From 217cda78005f993fd6b2e575d4abd97c93cec655 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Thu, 25 Apr 2002 19:41:17 +0000 Subject: [PATCH] a couple of bugs solved.. --- bs/fleet.cpp | 46 +++++++++++++++++++++++------- bs/fleet.h | 8 ++++-- bs/planet.cpp | 66 ++++++++++++++++++++++++++----------------- bs/ui/resourceview.ui | 4 +-- 4 files changed, 84 insertions(+), 40 deletions(-) diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 13bafb7..136ad22 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -201,6 +201,23 @@ void Fleet::setFleet(string unittype, int number, int tick = 0) m_Fleet[unittype][tick] = number; } +////////////////////////////////////////////////////////////////////////// +// +void Fleet::addFleet(std::string unittype, int number, int tick = 0) +{ + int earlier = 0; + int ticks = m_Fleet[unittype].size(); + + if (ticks != 0) + earlier = m_Fleet[unittype][ticks - 1]; + + for (int i = ticks; i <= tick; ++i) + { + m_Fleet[unittype].push_back(earlier); + } + m_Fleet[unittype][tick] += number; +} + ////////////////////////////////////////////////////////////////////////// // int Fleet::fleet(string unittype, int tick = 0) @@ -572,10 +589,7 @@ void Fleet::addResource(std::string type, int number, int tick = 0) { int ticks = m_Resources[type].size(); - int latest = 0; - - if (ticks > 0) - latest = m_Resources[type][ticks - 1]; + int latest = resource(type, tick - 1); for (int i = ticks; i <= tick; ++i) m_Resources[type].push_back(latest); @@ -586,6 +600,9 @@ void Fleet::addResource(std::string type, int number, int tick = 0) // int Fleet::resource(std::string type, int tick = 0) const { + if (tick < 0) + return 0; + vectorconst* resource = 0; for (ResourceList::const_iterator i = m_Resources.begin(); i != m_Resources.end(); ++i) { @@ -610,6 +627,13 @@ int Fleet::resource(std::string type, int tick = 0) const return resource->at(tick); } +////////////////////////////////////////////////////////////////////////// +// +void Fleet::resetResources() +{ + m_Resources.clear() ; +} + ////////////////////////////////////////////////////////////////////////// // void Fleet::printFleet() @@ -654,6 +678,7 @@ void Fleet::distributeCappedRoids(std::vector fleets, int tick = 0) { string res = i->first; + cerr << "Distributing type: " << res << endl; for (vector::iterator j = i->second.begin(); j != i->second.end(); ++j) cout << (*j) << endl; @@ -678,17 +703,18 @@ void Fleet::distributeCappedRoids(std::vector fleets, int tick = 0) int lost = totcapped * part; cerr << (*j)->name() << " gaining " << lost << " " << res << " since it's " << part * 100 << "% of the whole score, and it had : " << fl1 << " score last tick.. compared to fleet total of: " << score(0) << endl; - (*j)->setResource(res, (*j)->resource(res,tick-1) + lost, tick); + + //(*j)->setResource(res, (*j)->resource(res,tick-1) + lost, tick); + (*j)->addResource(res,lost, tick); } } } ////////////////////////////////////////////////////////////////////////// // -void Fleet::addPodsForLostRoids(int tick = 1) + +void Fleet::addFleet(std::map units, int tick = 0) { - for (ResourceList::iterator i = m_Resources.begin(); i != m_Resources.end(); ++i) - { - setFleet("Astro Pod", fleet("Astro Pod", tick) + (resource(i->first, tick) - resource(i->first, tick - 1)), tick); - } + for (map::iterator i = units.begin(); i != units.end(); ++i) + addFleet(i->first, i->second, tick); } diff --git a/bs/fleet.h b/bs/fleet.h index 448d4de..93bdee7 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -106,6 +106,11 @@ public: * other is hardly used other than inside the engine. */ void setFleet(std::string unittype, int number, int tick = 0); + + void addFleet(std::string unittype, int number, int tick = 0); + + void addFleet(std::map units, int tick = 0); + /**Returns the numbers of units fo a specific type at a specific tick. * \param unittype The shipname, as a std string * \param tick The tick you want to look at, tick 0 (before battle) is default @@ -164,8 +169,6 @@ public: */ void distributeCappedRoids(std::vector fleets, int tick = 0); - void addPodsForLostRoids(int tick = 1); - /** Checks through the vector with fleets to see who's in time for the * specified tick and staying long enough so they're not too early. * \param fleets a vector with Fleet pointers to use for the calculations @@ -223,6 +226,7 @@ public: */ int resource(std::string type, int tick = 0)const; + void resetResources(); /** This is a little more advanced function. It makes a a number of units * of a specific unittype shoot at the current fleet and calculates the * losses. diff --git a/bs/planet.cpp b/bs/planet.cpp index 3c4404f..f57d208 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -146,6 +146,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 @@ -177,7 +184,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); @@ -188,7 +197,6 @@ void Planet::runBattle(std::vector friendly, std::vector hostile allFriends.distributeLossesGains(friends, tick); - allHostiles.addPodsForLostRoids(); allHostiles.distributeLossesGains(hostiles, tick); allHostiles.distributeCappedRoids(hostiles, tick); @@ -209,6 +217,14 @@ void Planet::runBattle(std::vector friendly, std::vector hostile // 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; + + 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; @@ -241,38 +257,34 @@ 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; + 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"; } } } @@ -283,6 +295,8 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::mapaddFleet(pods, 1); + } ////////////////////////////////////////////////////////////////////////// diff --git a/bs/ui/resourceview.ui b/bs/ui/resourceview.ui index 376a60a..971f006 100644 --- a/bs/ui/resourceview.ui +++ b/bs/ui/resourceview.ui @@ -62,7 +62,7 @@ - EoniumEdit + UninitEdit NoFocus @@ -92,7 +92,7 @@ - UninitEdit + EoniumEdit NoFocus -- 2.39.2