X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=bs%2Fplanet.cpp;h=d62bf579996a1f0d583a66302fce706531c9ac59;hb=7311d423f454c500dbc60dd822007da3981b0d56;hp=3e1f39ae65eab751585cde681e1cddc6789c67bd;hpb=b355aa1be760bf03c9be4bfa581f320e2e045eac;p=hbs.git diff --git a/bs/planet.cpp b/bs/planet.cpp index 3e1f39a..d62bf57 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -23,6 +23,7 @@ using namespace std; Planet::Planet() { m_sRace = "Planet"; + m_iStays = -1; } Planet::~Planet(){ @@ -131,6 +132,9 @@ void Planet::takeRoids(std::string type, int number, int tick = 0) for (int i = ticks; i <= tick; ++i ) m_Roids[type].push_back(roids); m_Roids[type][tick] -= number; + + if (type != "uninit") + addPlanetScore(-3000*number, tick); } @@ -143,6 +147,13 @@ void Planet::runBattle(std::vector friendly, std::vector hostile return; int skipped = 0; + + for (vector::iterator i = friendly.begin(); i != friendly.end(); ++i) + (*i)->resetResources(); + + for (vector::iterator i = hostile.begin(); i != hostile.end(); ++i) + (*i)->resetResources(); + for(int tick = 1; skipped < 20; ++tick) { //See who's in the battle at the current tick @@ -174,7 +185,9 @@ void Planet::runBattle(std::vector friendly, std::vector hostile //Reset roids for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid) + { setRoids(roid->first, roids(roid->first, tick-1), tick); + } setPlanetScore(planetScore(tick - 1), tick); @@ -184,6 +197,7 @@ void Planet::runBattle(std::vector friendly, std::vector hostile //allFriends.printFleet(); allFriends.distributeLossesGains(friends, tick); + allHostiles.distributeLossesGains(hostiles, tick); allHostiles.distributeCappedRoids(hostiles, tick); @@ -202,8 +216,17 @@ void Planet::runBattle(std::vector friendly, std::vector hostile ////////////////////////////////////////////////////////////////////////// // -void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map >& stealfriendly, std::map >& stealhostile, int tick = 0) +void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map >& stealfriendly, std::map >& stealhostile, int tick = 1) { + if (planetScore(tick - 1) > 0) + setCapping(float(planetScore(tick - 1)) / hostile->score() / 10, tick); + else + setCapping(0, tick); + + map pods; + + + //FIXME: Need to change this and allow multiple shiptypes with the same initiative. 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; @@ -226,6 +249,9 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::maptakeShoot(unittype, friendly->freeFleet(unittype, 1), stealfriendly[unittype]); friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), stealhostile[unittype]); + + friendlytemp->calculateLostStealships(unittype, stealfriendly[unittype], 1); + hostiletemp->calculateLostStealships(unittype, stealhostile[unittype], 1); } else { @@ -236,38 +262,35 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map 0) - { - setCapping(float(planetScore(tick - 1)) / hostile->score() / 10, tick); - - cerr << "Capping is: " << capping(tick) << endl; + //FIXME: Prolly need to recode the whole capping section for r7, due to multiple pods thingy + cerr << "Capping is: " << capping(tick) << endl; - if (capping(tick) > 0) + if (capping(tick) > 0) + { + for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid) { - for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid) - { - int caproids = capping(tick) * roids(roid->first, tick - 1); - int freepods = hostiletemp->freeFleet(unittype, 1); + int caproids = capping(tick) * roids(roid->first, tick - 1); + int freepods = hostiletemp->freeFleet(unittype, 1); - cerr << "Possible to steal " << caproids << " " << roid->first << " roids\n"; - cerr << freepods << " free pods available\n"; - - if (freepods <= 0) - break; - if (freepods < caproids) - caproids = freepods; + cerr << "Possible to steal " << caproids << " " << roid->first << " roids\n"; + cerr << freepods << " free pods available\n"; + + if (freepods <= 0) + break; + if (freepods < caproids) + caproids = freepods; - cerr << caproids << " roids stolen\n"; + cerr << caproids << " roids stolen\n"; - takeRoids(roid->first, caproids, tick); + takeRoids(roid->first, caproids, tick); - //FIXME: Going to move this to the distribute roids section instead.. Not really move, I'll keep this, but "regenerate" the pods in the distribute ships function. - hostiletemp->killFleet(unittype, caproids, 1); - //int totroids = caproids + hostiletemp->resource(roid->first, 0); - hostiletemp->addResource(roid->first, caproids, 1); + //FIXME: Going to move this to the distribute roids section instead.. Not really move, I'll keep this, but "regenerate" the pods in the distribute ships function. + hostiletemp->killFleet(unittype, caproids, 1); + pods[unittype] += caproids; + //int totroids = caproids + hostiletemp->resource(roid->first, 0); + hostiletemp->addResource(roid->first, caproids, 1); - cerr << caproids << " stolen " << roid->first << " roids\n"; - } + cerr << caproids << " stolen " << roid->first << " roids\n"; } } } @@ -278,6 +301,8 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::mapaddFleet(pods, 1); + } //////////////////////////////////////////////////////////////////////////