473,473 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why won't this work.

I am writing a game and I read units into a map manager and there they
are placed on a grind and if they are in the same space they will
fight. I have an attacker vector and defender fector and if they have
units they will fight. That all works but once they fight to combat
affects don't seem to take affect. I tested my program at earlier
states.

if(red){
for(int lp = 0; lp != rteam.size(); lp++){
m.atIn(rteam[lp]);} //reads in the attracking units to map
panager
for(int lp = 0; lp != yteam.size(); lp++){
m.dtIn(yteam[lp]);} //reads defender
} else { //same but for the other turn
for(int lp = 0; lp != rteam.size(); lp++){
m.atIn(yteam[lp]);}
for(int lp = 0; lp != yteam.size(); lp++){
m.dtIn(rteam[lp]);}
}
m.fight(); //directs units in the same space to fingt.
//rteam[1].tomark(); <-this works units are killed here
//yteam[1].disbersed(); <-this also works units are dispered
correctly
kill(rteam); //kills any red units
kill(yteam); //kills any purple units
m.clear(); //clears the map manager.
changeTurn(red, ppl); //changes red, purple turns

All my stuff works here in the main loop but once I send units rteam,
yteam to an object a refrences they don't get the combat affects:

Here is some sample code:

void mapmgt::atIn(unit& u){
int x = u.getXloc();
int y = u.getYloc();
h[y][x].at.push_back(u);

struct hold{
vector<unit>at; //holds the attackers
vector<unit>dt; //holds the defenders
float getAt(); //adds attacking factors
float getDt(); //addus up defending factors
void killA(); //attacker eliminated
void dispA(); //attacker disbersed
void dispD(); //defenders same as attackers
void killD();
};

void mapmgt::fight(){
float atk = 0;
float def = 0;
float odds = 0;
for(int lp1 = 0; lp1 != ylen; lp1++){
for(int lp2 = 0; lp2 != xlen; lp2++){
if(h[lp2][lp1].at.size() 0 && h[lp2][lp1].dt.size() 0){
atk = h[lp2][lp1].getAt();
def = h[lp2][lp1].getDt();
odds = atk/def;
int roll = (rand()%6)+1;
//int mod = t[b->GetSpace(lp2,lp1)].getDef(); <-this dosn't
work, seperat issue
//roll+=mod;
int res = tbl.result(roll, odds);
if(res == 0){h[lp2][lp1].killA();} //atk elim <-these don't
seem to be working
if(res == 1){h[lp2][lp1].dispA();} //atk disp imposing the
combat results
if(res == 2){h[lp2][lp1].dispD();} //def disp on the units
if(res == 3){h[lp2][lp1].killD();} //def elim

MessageBox(NULL, "There is fighting!", "simulation!", MB_OK);
}
}
}

}

Example of combat effects, works in the main loop but not here and this
is my main problem:

void hold::killA(){
MessageBox(NULL, "Atk elim!", "simulation!", MB_OK);
for(int lp = 0; lp != at.size(); lp++){
at[lp].tomark();
}
}

Sep 19 '06 #1
4 1518
JoeC wrote:
I am writing a game and I read units into a map manager and there they
are placed on a grind and if they are in the same space they will
fight. I have an attacker vector and defender fector and if they have
units they will fight. That all works but once they fight to combat
affects don't seem to take affect. I tested my program at earlier
states.

if(red){
for(int lp = 0; lp != rteam.size(); lp++){
[snip]

Problem #1: your index is going past the end of the vector. Use <
rteam.size(), not != rteam.size().

If there are more problems, post a complete but minimal sample that
demonstrates the problem (i.e., one that we can cut and paste unchanged
into our editors to see the problem). Also see these guidelines for
posting code that doesn't work:

http://parashift.com/c++-faq-lite/ho...t.html#faq-5.8

Cheers! --M

Sep 19 '06 #2

mlimber wrote:
JoeC wrote:
I am writing a game and I read units into a map manager and there they
are placed on a grind and if they are in the same space they will
fight. I have an attacker vector and defender fector and if they have
units they will fight. That all works but once they fight to combat
affects don't seem to take affect. I tested my program at earlier
states.

if(red){
for(int lp = 0; lp != rteam.size(); lp++){
[snip]

Problem #1: your index is going past the end of the vector. Use <
rteam.size(), not != rteam.size().

If there are more problems, post a complete but minimal sample that
demonstrates the problem (i.e., one that we can cut and paste unchanged
into our editors to see the problem). Also see these guidelines for
posting code that doesn't work:
OK that is an easy start.

Sep 19 '06 #3

mlimber wrote:
JoeC wrote:
I am writing a game and I read units into a map manager and there they
are placed on a grind and if they are in the same space they will
fight. I have an attacker vector and defender fector and if they have
units they will fight. That all works but once they fight to combat
affects don't seem to take affect. I tested my program at earlier
states.

if(red){
for(int lp = 0; lp != rteam.size(); lp++){
[snip]

Problem #1: your index is going past the end of the vector. Use <
rteam.size(), not != rteam.size().

If there are more problems, post a complete but minimal sample that
demonstrates the problem (i.e., one that we can cut and paste unchanged
into our editors to see the problem). Also see these guidelines for
posting code that doesn't work:
OK that is an easy start but didn't solve my problem.

Sep 19 '06 #4

JoeC wrote:
mlimber wrote:
JoeC wrote:
I am writing a game and I read units into a map manager and there they
are placed on a grind and if they are in the same space they will
fight. I have an attacker vector and defender fector and if they have
units they will fight. That all works but once they fight to combat
affects don't seem to take affect. I tested my program at earlier
states.
>
if(red){
for(int lp = 0; lp != rteam.size(); lp++){
[snip]

Problem #1: your index is going past the end of the vector. Use <
rteam.size(), not != rteam.size().

If there are more problems, post a complete but minimal sample that
demonstrates the problem (i.e., one that we can cut and paste unchanged
into our editors to see the problem). Also see these guidelines for
posting code that doesn't work:

OK that is an easy start but didn't solve my problem.
Then follow the instructions second part of my previous response.

Cheers! --M

Sep 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Kerry Neilson | last post by:
For the past couple of months, Idle won't start when I invoke it. I am at a complete loss for why this is. When this happens, they python command line still starts, and python works fine...
1
by: Jim | last post by:
Hey guys I DESPERATLY need some help with this small javascript i have on this website. All that it's supposed to do is change the button image once it's pressed but alas... I copy-pasted the code...
3
by: DFS | last post by:
I've been working around this for years (I believe), so I figured someone here might know: Why won't a crosstab query accept a value from a form reference? TRANSFORM...
7
by: simon | last post by:
I have simple html(aspx) page, but vertical height won't work. Even if i had set the height of a table=100%, the table is not 100% height. I spend a lot of time(my real page is more...
3
by: musosdev | last post by:
Hi guys Okay, I've setup my projects to open and compile fine in VS2005 using FPSE and remote web, but it's *really* slow. So I thought I'd have a go at doing it the normal way, by loading from...
11
by: John Ortt | last post by:
Hi everyone. I have a database which I have developed in Access 2000 which is working nicely. The problem is that my customer only has Access 97. I tried to convert the database but the main...
7
by: Eran.Yasso | last post by:
Hi, I have project that automate excel(using Excel COM) which works fine in my home. I took the project from my home to work and tried to build the project but it won't built. I get error "The...
2
by: scitrenbaum | last post by:
Here is the dilemma. I have a website where everything works perfectly in all browsers except for Safari. When you are in Safari and you go to this page... ...
2
tpgames
by: tpgames | last post by:
Two days ago, MS office Word would type JP fonts, I thought. I didn't think I was using Works. Now, it won't type in JP. Jasc Paint shop pro 8, should type JP fonts because I am using XP, according...
4
by: z55177 | last post by:
My domain: http://www.esthevision.cz/ This is the cause of my problem. The template is supposed to look somewhat like this: PINK STRIPE http://themebot.com/website-templates/ht... I created an...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.