#include "planet.h"
+#include <iostream>
using namespace std;
Planet::Planet()
//
void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile)
{
- for(int tick = 1; ; ++tick)
+ if (hostile.size() == 0)
+ return;
+
+ int skipped = 0;
+ for(int tick = 1; skipped < 20; ++tick)
{
//See who's in the battle at the current tick
vector<Fleet*> friends = calculateSide(friendly, 6, tick);
// No idea to calculate anything if noone is there.. ;)
if (hostiles.size() == 0)
- break;
+ {
+ skipped++;
+ continue;
+ }
+ else
+ skipped = 0;
Planet allFriends;
allFriends.addToThis(friends);
calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile );
allFriends.distributeLossesGains(friends, tick);
- allHostiles.distributeLossesGains(friends, tick);
+ allHostiles.distributeLossesGains(hostiles, tick);
}
}
{
map<int, string> unitsinit; // order units after their ininitiative
for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
- unitsinit[i->second.ETA()] = i->first;
+ unitsinit[i->second.initiative()] = i->first;
for (map<int, string>::iterator i = unitsinit.begin(); i != unitsinit.end(); ++i)
{
string unittype = i->second;
+ cerr << "Initiative: " << s_Units[unittype].initiative() << " with unit: " << unittype << endl;
+
if (s_Units[unittype].type() == "EMP")
{
hostiletemp->takeEMP(unittype, friendly->freeFleet(unittype, 1));
}
//set the the objects so they point at the modified objects
- delete friendly;
- friendly = friendlytemp;
- delete hostile;
- hostile = hostiletemp;
+ *friendly = *friendlytemp;
+ delete friendlytemp;
+ *hostile = *hostiletemp;
+ delete hostiletemp;
}
}