X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=blobdiff_plain;f=bs%2Fplanet.cpp;h=1f904f82685ff101d4d392c644a6f269801089c4;hp=c374a99ff9cc7f726fd18392cad21aeb0890a5b2;hb=bb4169deef42f91b6afa4c4561f9339fba040f01;hpb=3f7ef4493164c1570a0dd6aa3c91de433b29d1d0 diff --git a/bs/planet.cpp b/bs/planet.cpp index c374a99..1f904f8 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 @@ -146,6 +180,8 @@ void Planet::runBattle(std::vector friendly, std::vector hostile 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);*/ } @@ -193,9 +229,9 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map 0) + if (planetScore(tick - 1) > 0) { - float capping = float(m_iScore) / hostile->score() / 10; + float capping = float(planetScore(tick - 1)) / hostile->score() / 10; cerr << "Capping is: " << capping << endl; @@ -220,7 +256,7 @@ 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 +275,15 @@ 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); + } + } +} +