X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=bs%2Fplanet.cpp;h=8fd1726b3979c4d287eb004597758315c762a28b;hb=9f0513b48fbafa876159812f638019c6b47eae33;hp=425861efbbf289afee2e6cd5518786bfd293f779;hpb=07acf9a898e295587b9034bee6b8682e11a97086;p=hbs.git diff --git a/bs/planet.cpp b/bs/planet.cpp index 425861e..8fd1726 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -17,9 +17,166 @@ #include "planet.h" +#include +using namespace std; + Planet::Planet() { m_sRace = "Planet"; + m_iScore = 0; } + Planet::~Planet(){ } + +////////////////////////////////////////////////////////////////////////// +// +unsigned Planet::planetScore() const +{ + return m_iScore; +} + +////////////////////////////////////////////////////////////////////////// +// +void Planet::setPlanetScore(unsigned i) +{ + m_iScore = i; +} + +////////////////////////////////////////////////////////////////////////// +// +int Planet::roids(std::string type, int tick = 0) const +{ + // const... I would like [] as for const types: int ticks = m_Roids[type].size(); + + vectorconst* roids = 0; + for (RoidList::const_iterator i = m_Roids.begin(); i != m_Roids.end(); ++i) + { + if (i->first == type) + { + roids = &i->second; + break; + } + } + if (roids == 0) + return 0; + + int ticks = roids->size(); + + if( ticks == 0) + return 0; + if (ticks < tick) + return roids->at(ticks); + return roids->at(tick); +} + +////////////////////////////////////////////////////////////////////////// +// +void Planet::setRoids(std::string type, int number) +{ + if (m_Roids[type].size() == 0) + m_Roids[type].push_back(number); + m_Roids[type][0] = number; +} + +////////////////////////////////////////////////////////////////////////// +// +void Planet::runBattle(std::vector friendly, std::vector hostile) +{ + 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 friends = calculateSide(friendly, 6, tick); + vector hostiles = calculateSide(hostile, 3, tick); + + // No idea to calculate anything if noone is there.. ;) + if (hostiles.size() == 0) + { + skipped++; + continue; + } + else + skipped = 0; + + Planet allFriends; + allFriends.addToThis(friends, tick); + + Fleet allHostiles; + allHostiles.addToThis(hostiles, tick); + + map > stealfriendly; + map > stealhostile; + + calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile ); + + //allFriends.printFleet(); + + allFriends.distributeLossesGains(friends, tick); + allHostiles.distributeLossesGains(hostiles, tick); + } +} + +////////////////////////////////////////////////////////////////////////// +// +void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map >& stealfriendly, std::map >& stealhostile ) +{ + map unitsinit; // order units after their ininitiative + for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) + unitsinit[i->second.initiative()] = i->first; + + for (map::iterator i = unitsinit.begin(); i != unitsinit.end(); ++i) + { + Fleet* hostiletemp = new Fleet(*hostile); + Planet* friendlytemp = new Planet(*friendly); + + 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)); + friendlytemp->takeEMP(unittype, hostile->freeFleet(unittype, 1)); + } + else if (s_Units[unittype].type() == "Steal") + { + hostiletemp->takeShoot(unittype, friendly->freeFleet(unittype, 1), stealfriendly[unittype]); + friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), stealhostile[unittype]); + } + else + { + map temp; + hostiletemp->takeShoot(unittype, friendly->freeFleet(unittype, 1), temp); + friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), temp); + } + + if (s_Units[unittype].type() == "Pod") + { + float capping = friendly->m_iScore / hostile->score() / 10; + for (RoidList::iterator roids = m_Roids.begin(); roids != m_Roids.end(); ++roids) + { + int caproids = capping * roids->second[0]; + int freepods = hostiletemp->freeFleet(unittype, 1); + + if (freepods == 0) + break; + if (freepods < caproids) + caproids = caproids - freepods; + + roids->second.push_back(roids->second[0] - caproids); + hostiletemp->killFleet(unittype, caproids, 1); + } + } + + //set the the objects so they point at the modified objects + *friendly = *friendlytemp; + delete friendlytemp; + *hostile = *hostiletemp; + delete hostiletemp; + } +} +