X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=blobdiff_plain;f=bs%2Fplanet.cpp;h=443b3b13695a31c2ba7d71854750acfcc2bd3241;hp=8fd1726b3979c4d287eb004597758315c762a28b;hb=8589e08e508806885b737682ed25b6f711d0fdee;hpb=9f0513b48fbafa876159812f638019c6b47eae33 diff --git a/bs/planet.cpp b/bs/planet.cpp index 8fd1726..443b3b1 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -65,6 +65,7 @@ int Planet::roids(std::string type, int tick = 0) const if( ticks == 0) return 0; + --ticks; if (ticks < tick) return roids->at(ticks); return roids->at(tick); @@ -72,13 +73,34 @@ int Planet::roids(std::string type, int tick = 0) const ////////////////////////////////////////////////////////////////////////// // -void Planet::setRoids(std::string type, int number) +void Planet::setRoids(std::string type, int number, int tick = 0) { - if (m_Roids[type].size() == 0) - m_Roids[type].push_back(number); - m_Roids[type][0] = number; + int ticks = m_Roids[type].size(); + int roids = 0; + if (m_Roids[type].size() > 0) + roids = m_Roids[type][m_Roids[type].size() - 1]; + + for (int i = ticks; i <= tick; ++i ) + m_Roids[type].push_back(roids); + m_Roids[type][tick] = number; } +////////////////////////////////////////////////////////////////////////// +// +void Planet::takeRoids(std::string type, int number, int tick = 0) +{ + int ticks = m_Roids[type].size(); + int roids = 0; + if (m_Roids[type].size() > 0) + roids = m_Roids[type][m_Roids[type].size() - 1]; + + for (int i = ticks; i <= tick; ++i ) + m_Roids[type].push_back(roids); + m_Roids[type][tick] -= number; +} + + + ////////////////////////////////////////////////////////////////////////// // void Planet::runBattle(std::vector friendly, std::vector hostile) @@ -103,26 +125,40 @@ void Planet::runBattle(std::vector friendly, std::vector hostile skipped = 0; Planet allFriends; - allFriends.addToThis(friends, tick); + allFriends.addToThis(friends, tick - 1); + + /*for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i) + allFriends.setRoids(i->first, roids(i->first, tick)); + + allFriends.setPlanetScore(m_iScore);*/ Fleet allHostiles; - allHostiles.addToThis(hostiles, tick); + allHostiles.addToThis(hostiles, tick - 1); map > stealfriendly; map > stealhostile; - calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile ); + calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile, tick ); //allFriends.printFleet(); allFriends.distributeLossesGains(friends, tick); allHostiles.distributeLossesGains(hostiles, tick); + + /* for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i) + setRoids(i->first, roids(i->first, 1), tick);*/ + } + + for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i) + { + for (vector::iterator j = i->second.begin(); j != i->second.end(); ++j) + cout << i->first << " roids : " << (*j) << endl; } } ////////////////////////////////////////////////////////////////////////// // -void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map >& stealfriendly, std::map >& stealhostile ) +void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map >& stealfriendly, std::map >& stealhostile, int tick = 0) { map unitsinit; // order units after their ininitiative for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) @@ -156,19 +192,38 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::mapm_iScore / hostile->score() / 10; - for (RoidList::iterator roids = m_Roids.begin(); roids != m_Roids.end(); ++roids) + if (m_iScore <= 0) break; + float capping = float(m_iScore) / hostile->score() / 10; + + cerr << "Capping is: " << capping << endl; + + if (capping > 0.15) + capping = 0.15; + if (capping <= 0) + break; + + for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid) { - int caproids = capping * roids->second[0]; + int caproids = capping * 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) + if (freepods <= 0) break; if (freepods < caproids) - caproids = caproids - freepods; + caproids = freepods; + + cerr << caproids << " roids stolen\n"; - roids->second.push_back(roids->second[0] - caproids); + takeRoids(roid->first, caproids, tick); + hostiletemp->killFleet(unittype, caproids, 1); + int totroids = caproids + hostiletemp->resource(roid->first, 0); + hostiletemp->setResource(roid->first, totroids, 1); + + cerr << totroids << " stolen " << roid->first << " roids\n"; } }