J
JoeC
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();
}
}
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();
}
}