X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=bs%2Fplanet.cpp;h=3c4404f800d4dee61ae9a968b6015f8eb27dde4a;hb=45577c33bdaab669fd787a0411996d506307708b;hp=0e4de71300db0651919b5b36549e5537dbf61dba;hpb=a61c6ecdc3dd55f06e06cc1a295b1b4fc2830314;p=hbs.git diff --git a/bs/planet.cpp b/bs/planet.cpp index 0e4de71..3c4404f 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -23,7 +23,6 @@ using namespace std; Planet::Planet() { m_sRace = "Planet"; - m_iScore = 0; } Planet::~Planet(){ @@ -31,18 +30,53 @@ Planet::~Planet(){ ////////////////////////////////////////////////////////////////////////// // -unsigned Planet::planetScore() const +unsigned Planet::planetScore(int tick = 0) const { - return m_iScore; + int ticks = m_Score.size(); + if (ticks == 0) + return 0; + + --ticks; + + if (ticks < tick) + return m_Score[ticks]; + + return m_Score[tick]; } ////////////////////////////////////////////////////////////////////////// // -void Planet::setPlanetScore(unsigned i) +void Planet::setPlanetScore(unsigned number, int tick = 0) { - m_iScore = i; + int earlier = 0; + int ticks = m_Score.size(); + + if (ticks != 0) + earlier = m_Score[ticks - 1]; + + for (int i = ticks; i <= tick; ++i) + { + m_Score.push_back(earlier); + } + m_Score[tick] = number; } +////////////////////////////////////////////////////////////////////////// +// +void Planet::addPlanetScore(unsigned number, int tick = 0) +{ + int earlier = 0; + int ticks = m_Score.size(); + + if (ticks != 0) + earlier = m_Score[ticks - 1]; + + for (int i = ticks; i <= tick; ++i) + { + m_Score.push_back(earlier); + } + m_Score[tick] += number; +} ////////////////////////////////////////////////////////////////////////// // int Planet::roids(std::string type, int tick = 0) const @@ -97,6 +131,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); } @@ -137,15 +174,26 @@ void Planet::runBattle(std::vector friendly, std::vector hostile map > stealfriendly; map > stealhostile; + + //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); + calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile, tick ); //allFriends.printFleet(); allFriends.distributeLossesGains(friends, tick); + + allHostiles.addPodsForLostRoids(); allHostiles.distributeLossesGains(hostiles, tick); allHostiles.distributeCappedRoids(hostiles, tick); + calculateScoreLoss(friends, tick); + /* for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i) setRoids(i->first, roids(i->first, 1), tick);*/ } @@ -159,7 +207,7 @@ 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) { map unitsinit; // order units after their ininitiative for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) @@ -172,7 +220,7 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::mapsecond; - cerr << "Initiative: " << s_Units[unittype].initiative() << " with unit: " << unittype << endl; + //cerr << "Initiative: " << s_Units[unittype].initiative() << " with unit: " << unittype << endl; if (s_Units[unittype].type() == "EMP") { @@ -193,19 +241,17 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map 0) + if (planetScore(tick - 1) > 0) { - float capping = float(m_iScore) / hostile->score() / 10; + setCapping(float(planetScore(tick - 1)) / hostile->score() / 10, tick); - cerr << "Capping is: " << capping << endl; + cerr << "Capping is: " << capping(tick) << endl; - if (capping > 0.15) - capping = 0.15; - if (capping > 0) + if (capping(tick) > 0) { for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid) { - int caproids = capping * roids(roid->first, tick - 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"; @@ -217,10 +263,10 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::mapfirst, caproids, tick); - //FIXME: Going to move this to the distribute roids section instead.. + //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); @@ -239,3 +285,47 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map friendly, int tick = 1) +{ + for (vector::iterator i = friendly.begin(); i != friendly.end(); ++i) + { + if ((*i)->name().find("Home") != string::npos) + { + int scorechange = (*i)->score(tick) - (*i)->score(tick - 1); + addPlanetScore(scorechange, tick); + } + } +} + +////////////////////////////////////////////////////////////////////////// +// +float Planet::capping(int tick = 0) +{ + int ticks = m_Capping.size(); + + --ticks; + + if (ticks < tick) + return 0; + + return m_Capping[tick]; +} + +////////////////////////////////////////////////////////////////////////// +// +void Planet::setCapping(float capping, int tick = 0) +{ + int ticks = m_Capping.size(); + + for (int i = ticks; i <= tick; ++i) + { + m_Capping.push_back(0); + } + + if (capping <= 0.15 && capping >= 0) + m_Capping[tick] = capping; + else + m_Capping[tick] = 0.15; +}