| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi, comp.games.development.programming is probably more appropiate for this question. -- Regards, Ron AF Greve http://moonlit.xs4all.nl "JoeC" <enki034@yahoo.com> wrote in message news:1157330894.182338.159730@p79g2000cwp.googlegr oups.com... >I am writing a game and I am having a challenge with my combat > function. All I want to do is find out how to group pieces that are in > the same space. There are two sides and all the units that are in the > same space fight. I want to add up the attack factors and defending > factors in the same space then figure out the odds so I can roll > against an odds table. Basically each piece holds its own x and y loc. > > > Here is what I have right now: > > void fight(vector<unit>& at, vector<unit>& dt, > board * b , terrain * trn ){ > > vector<fightclass> fighting; > > /* adds attacking units to the fightclass vector if units are in the > same space they are to grouped in the same fight class elemet of > the > vector. */ > > for(int atu = 0; atu != at.size(); atu++){ > if(fighting.size() == 0){ > fightclass ft; > ft.addAu(at[atu]); > fighting.push_back(ft); > } else { > for(int lp = 0; lp != fighting.size(); lp++){ > if(at[atu].getXloc() != fighting[lp].getX() && > at[atu].getYloc() != fighting[lp].getY()){ > fightclass ft; > ft.addAu(at[atu]); > fighting.push_back(ft); > } else { > fighting[lp].addAu(at[atu]); > } > } > } > } > /* Adds defending units to the fightclass array. If x and y locs are > the same as attacking locations (are in the same space) they are > added to array for combat */ > > for(int dtu = 0; dtu != dt.size(); dtu++){ > for(int lp = 0; lp != fighting.size(); lp++){ > if(dt[dtu].getXloc() == fighting[lp].getX() && > dt[dtu].getYloc() == fighting[lp].getY()){ > fighting[lp].addDu(dt[dtu]); > } > } > } > > // Combat routine > > for(int lp = 0; lp != fighting.size(); lp++){ //handles combat > if(fighting[lp].canfight()){ > int df = b->GetSpace(fighting[lp].getX(), fighting[lp].getY()); > float odds = > fighting[lp].getAtk()/fighting[lp].getDef(); > //gets the defense bonus for the terrain in the space where > //combat takes place > int roll = rand() - trn[df].defend(); > //get the die roll modified for terrain > odds = fighting[lp].getAtk() / fighting[lp].getDef(); > //gets the attack to defence ratio. > if(odds < .5){ > MessageBox(NULL, "Fighting! 1:3", "Info!", MB_OK); > return; > } > if(odds < 1){ > MessageBox(NULL, "Fighting! 1:2", "Info!", MB_OK); > return; > } > if(odds < 2){ > MessageBox(NULL, "Fighting! 1:1", "Info!", MB_OK); > return; > } > if(odds < 3){ > MessageBox(NULL, "Fighting! 2:1", "Info!", MB_OK); > return; > } > if(odds < 4){ > MessageBox(NULL, "Fighting! 3:1", "Info!", MB_OK); > return; > } > if(odds < 5){ > MessageBox(NULL, "Fighting! 4:1", "Info!", MB_OK); > return; > } > if(odds < 6){ > MessageBox(NULL, "Fighting! 5:1", "Info!", MB_OK); > return; > } > > } > } > for(int lp = 0; lp != fighting.size(); lp++){ > fighting[lp].done(); > } > fighting.clear(); > } > > class fightclass{ > /* Fightclass holds two arrays of units. The two arrays represent > units > in the same space elgible for combat. Array at represents the > attacking > forces and dt represents the defending units */ > > > int xl; > int yl; > > bool sides2; /* indicates if there are units in both attack and > defend > if there are units in both attack and defend then > combat > is to take place between the opposing sides. */ > > vector<unit>at; //attack units > vector<unit>dt; //defending units > > public: > fightclass(); > void addAu(unit au); //adds an addacking unit > void addDu(unit du); //adds a defending unit > int getX(){return xl;} //return the x coord > int getY(){return yl;} //returns the y coord > float getAtk(); //returns the total attack factors for one space > float getDef(); //returns the total defending factors for one space > bool canfight(); //if there are both attacking and defending units > void done(); //clears vectores after the turn > > }; > > fightclass::fightclass(){ > xl = 0; > yl = 0; > } > > void fightclass::addAu(unit u){ > at.push_back(u); > xl = u.getXloc(); > yl = u.getYloc(); > > } > > void fightclass::addDu(unit u){ > > dt.push_back(u); > > } > > bool fightclass::canfight(){ > if(at.size() && dt.size()){ > return true; > }else {return false;} > } > > float fightclass::getAtk(){ > float total; > for(int lp = 0; lp != at.size(); lp++){ > total +=at[lp].getAttack(); > } > return total; > } > > I know the logic is not the best but it is the best I can do. This is > tricky and I am pretty confused. I would like to find some way of > making the logic steps easier. There may be some simple error that I > overlooked or it can be totally screwed up. > |
|
#2
| |||
| |||
| Thanks, I didn't know about that group. I will ask the question there. Still it is programming and I am trying to learn programming by programming games. |
|
#3
| |||
| |||
| Moonlit wrote: > comp.games.development.programming is probably more appropiate for this > question. Why? His question was more or less about program logic, using mostly standard C++ (save for one function). That's more on-topic than many other posts here. Regards, Bart. |
|
#4
| |||
| |||
| Bart wrote: > Moonlit wrote: >> comp.games.development.programming is probably more appropiate for this >> question. > > Why? His question was more or less about program logic, using mostly > standard C++ (save for one function). That's more on-topic than many > other posts here. Only the OP should guess which group will provide the best answer. -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!! |
|
#5
| |||
| |||
| In article <BUkLg.1693$MF1.562@newssvr25.news.prodigy.net>, Phlip <phlipcpp@yahoo.com> wrote: >Only the OP should guess which group will provide the best answer. Posters are entitled to guess, true. But, correcting guesses is the job of newsgroup regulars, and prefectly reasonable. Nathan Mates -- <*> Nathan Mates - personal webpage http://www.visi.com/~nathan/ # Programmer at Pandemic Studios -- http://www.pandemicstudios.com/ # NOT speaking for Pandemic Studios. "Care not what the neighbors # think. What are the facts, and to how many decimal places?" -R.A. Heinlein |
|
#6
| |||
| |||
| Nathan Mates wrote: >>Only the OP should guess which group will provide the best answer. > > Posters are entitled to guess, true. But, correcting guesses is the > job of newsgroup regulars, and prefectly reasonable. The only topicality criteria relevant to a questioner is what newsgroup will provide the best question. Once we suggestion one, we can no longer declare whether an equally topical question belongs here or there. That was the context. When you offer another newsgroup, always reinforce that topicality is in the poster's best interests. The answer "your question is off topic here go away" doesn't increase the odds of useful participation. -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!! |
|
#7
| |||
| |||
| Phlip wrote: > The only topicality criteria relevant to a questioner is what newsgroup > will provide the best question. answer. you know... -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!! |
|
#8
| |||
| |||
| Phlip wrote: > Bart wrote: > > > Moonlit wrote: > > >> comp.games.development.programming is probably more appropiate for this > >> question. > > > > Why? His question was more or less about program logic, using mostly > > standard C++ (save for one function). That's more on-topic than many > > other posts here. > > Only the OP should guess which group will provide the best answer. > > -- > Phlip > http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!! I think MY code works. It is a bit more complex and cumbersom than I would like but I am pushing ahead on next part of the game. |
|
#9
| |||
| |||
| Thanks Nathan :-) -- Regards, Ron AF Greve http://moonlit.xs4all.nl "Nathan Mates" <nathan@visi.com> wrote in message news:12frp1vb3ndj6d7@corp.supernews.com... > In article <BUkLg.1693$MF1.562@newssvr25.news.prodigy.net>, > Phlip <phlipcpp@yahoo.com> wrote: >>Only the OP should guess which group will provide the best answer. > > Posters are entitled to guess, true. But, correcting guesses is the > job of newsgroup regulars, and prefectly reasonable. > > Nathan Mates > -- > <*> Nathan Mates - personal webpage http://www.visi.com/~nathan/ > # Programmer at Pandemic Studios -- http://www.pandemicstudios.com/ > # NOT speaking for Pandemic Studios. "Care not what the neighbors > # think. What are the facts, and to how many decimal places?" -R.A. > Heinlein |
|
#10
| |||
| |||
| Moonlit wrote: > Thanks Nathan :-) You correctly indicated a good newsgroup. Nobody doubted that. Except Bart, who claimed you shouldn't have bounced. I defended you, by saying you didn't bounce, you suggested. Then Nathan attempted to refute my defense, which he didn't understand. So I think your thanks are due me, not Nathan. ;-) -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!! |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.