From: Michael Andreen Date: Tue, 9 Apr 2002 16:42:58 +0000 (+0000) Subject: battle algorithms are getting closer.. ;) X-Git-Tag: HBS_0_1_0~17 X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=commitdiff_plain;h=a2ce63f561d091d9c3af49987d74849f9450c16b battle algorithms are getting closer.. ;) --- diff --git a/bs/fleet.cpp b/bs/fleet.cpp index f134f7b..5f6b015 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -228,3 +228,46 @@ std::vector Fleet::calculateSide(std::vector fleets, int stays = { } +////////////////////////////////////////////////////////////////////////// +// +int Fleet::freeFleet(std:: string unittype, int tick = 0) +{ + if (m_Fleet[unittype].size() == 0) + return 0; + if (m_BlockedFleet[unittype].size() < tick) + return m_Fleet[unittype][tick]; + + return m_Fleet[unittype][tick] - m_BlockedFleet[unittype][tick]; +} + + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::takeShoot(std::string unittype, int number, std::map& hitunits) +{ +} + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::takeEMP(std::string unittype, int number) +{ +} + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::killFleet(std::string unittype, int number, int tick = 0) +{ +} + +////////////////////////////////////////////////////////////////////////// +// +void setResource(std::string type, int number, int tick = 0) +{ +} + +////////////////////////////////////////////////////////////////////////// +// +int resource(std::string type, int tick = 0) +{ +} + diff --git a/bs/fleet.h b/bs/fleet.h index f1d96af..3bdab65 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -28,6 +28,7 @@ typedef std::map > FleetList; typedef std::map UnitList; typedef std::map > RaceList; +typedef std::map > ResourceList; //! An abstraction of a fleet and the engine for the battle simulation. /**This class and it's derivates is the engine for the whole battlesystem. * One of the few parts that I plan make fully portable. @@ -89,6 +90,8 @@ public: void setFleet(std::string unittype, int number); int fleet(std::string unittype, int tick = 0); + + int freeFleet(std:: string unittype, int tick = 0); static void setRaces(RaceList& races); static void setUnits(UnitList& units); @@ -102,7 +105,13 @@ public: std::vector calculateSide(std::vector fleets, int stays = 0, int tick = 0); + void takeShoot(std::string unittype, int number, std::map& hitunits); + void takeEMP(std::string unittype, int number); + void killFleet(std::string unittype, int number, int tick = 0); + void setResource(std::string type, int number, int tick = 0); + int resource(std::string type, int tick = 0); + protected: @@ -110,6 +119,9 @@ protected: std::string m_sRace; int m_iETA; FleetList m_Fleet; + FleetList m_BlockedFleet; + ResourceList m_Resources; + static UnitList s_Units; static RaceList s_Races; diff --git a/bs/planet.cpp b/bs/planet.cpp index a5541cb..4ae9c59 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -98,7 +98,10 @@ void Planet::runBattle(std::vector friendly, std::vector hostile Fleet allHostiles; allHostiles.addToThis(hostiles); - calcOneTick(&allFriends, &allHostiles); + map > stealfriendly; + map > stealhostile; + + calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile ); allFriends.distributeLossesGains(friends, tick); allHostiles.distributeLossesGains(friends, tick); @@ -107,7 +110,59 @@ void Planet::runBattle(std::vector friendly, std::vector hostile ////////////////////////////////////////////////////////////////////////// // -void Planet::calcOneTick(Planet* friendly, Fleet* Hostile) +void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map >& stealfriendly, std::map >& stealhostile ) { + map unitsinit; // order units after their ininitiative + for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) + unitsinit[i->second.ETA()] = i->first; + + for (map::iterator i = unitsinit.begin(); i != unitsinit.end(); ++i) + { + Fleet* hostiletemp = new Fleet(*hostile); + Planet* friendlytemp = new Planet(*friendly); + + string unittype = i->second; + + if (s_Units[unittype].type() == "EMP") + { + hostiletemp->takeEMP(unittype, friendly->freeFleet(unittype, 1)); + friendlytemp->takeEMP(unittype, hostile->freeFleet(unittype, 1)); + } + else if (s_Units[unittype].type() == "Steal") + { + hostiletemp->takeShoot(unittype, friendly->freeFleet(unittype, 1), stealfriendly[unittype]); + friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), stealhostile[unittype]); + } + else + { + map temp; + hostiletemp->takeShoot(unittype, friendly->freeFleet(unittype, 1), temp); + friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), temp); + } + + if (s_Units[unittype].type() == "Pod") + { + float capping = friendly->m_iScore / hostile->score() / 10; + for (RoidList::iterator roids = m_Roids.begin(); roids != m_Roids.end(); ++roids) + { + int caproids = capping * roids->second[0]; + int freepods = hostiletemp->freeFleet(unittype, 1); + + if (freepods == 0) + break; + if (freepods < caproids) + caproids = caproids - freepods; + + roids->second.push_back(roids->second[0] - caproids); + hostiletemp->killFleet(unittype, caproids, 1); + } + } + + //set the the objects so they point at the modified objects + delete friendly; + friendly = friendlytemp; + delete hostile; + hostile = hostiletemp; + } } diff --git a/bs/planet.h b/bs/planet.h index a19a858..2d51361 100644 --- a/bs/planet.h +++ b/bs/planet.h @@ -48,7 +48,7 @@ public: void runBattle(std::vector friendly, std::vector hostile); protected: - void calcOneTick(Planet* friendly, Fleet* Hostile); + void calcOneTick(Planet* friendly, Fleet* Hostile, std::map >& stealfriendly, std::map >& stealhostile ); unsigned m_iScore; RoidList m_Roids;