]> ruin.nu Git - hbs.git/commitdiff
battle algorithms are getting closer.. ;)
authorMichael Andreen <harv@ruin.nu>
Tue, 9 Apr 2002 16:42:58 +0000 (16:42 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 9 Apr 2002 16:42:58 +0000 (16:42 +0000)
bs/fleet.cpp
bs/fleet.h
bs/planet.cpp
bs/planet.h

index f134f7bb1fa51b7c2d2f8e29d5d5dd6a16bafc7d..5f6b0155f01444431167c66f60abe72edbcb4c45 100644 (file)
@@ -228,3 +228,46 @@ std::vector<Fleet*> Fleet::calculateSide(std::vector<Fleet*> 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<std::string, int>& 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)
+{
+}
+
index f1d96affc4fb1264464f704c55db3262eb5b4646..3bdab65924c5f9db08ffd1f2decf47fbeac5da3a 100644 (file)
@@ -28,6 +28,7 @@
 typedef std::map<std::string, std::vector<int> > FleetList;
 typedef std::map<std::string, UnitType>        UnitList;
 typedef std::map<std::string, std::vector<int> > RaceList;
 typedef std::map<std::string, std::vector<int> > FleetList;
 typedef std::map<std::string, UnitType>        UnitList;
 typedef std::map<std::string, std::vector<int> > RaceList;
+typedef std::map<std::string, std::vector<int> > 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.
 //! 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);
 
        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);
        
        static void setRaces(RaceList& races);
        static void setUnits(UnitList& units);
@@ -102,7 +105,13 @@ public:
 
        std::vector<Fleet*> calculateSide(std::vector<Fleet*> fleets, int stays = 0, int tick = 0);
 
 
        std::vector<Fleet*> calculateSide(std::vector<Fleet*> fleets, int stays = 0, int tick = 0);
 
+       void takeShoot(std::string unittype, int number, std::map<std::string, int>& 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:
 
 
 protected:
 
 
@@ -110,6 +119,9 @@ protected:
        std::string     m_sRace;
        int         m_iETA;
        FleetList       m_Fleet;
        std::string     m_sRace;
        int         m_iETA;
        FleetList       m_Fleet;
+       FleetList       m_BlockedFleet;
+       ResourceList m_Resources;
+
 
        static UnitList s_Units;
        static RaceList s_Races;
 
        static UnitList s_Units;
        static RaceList s_Races;
index a5541cbebaee4b89dd68d5f79d9de96d6d94838a..4ae9c59e4d517e87b9047c7eb9b00dee837e3dad 100644 (file)
@@ -98,7 +98,10 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
                Fleet allHostiles;
                allHostiles.addToThis(hostiles);
 
                Fleet allHostiles;
                allHostiles.addToThis(hostiles);
 
-               calcOneTick(&allFriends, &allHostiles);
+               map<string, map<string, int> > stealfriendly;
+               map<string, map<string, int> > stealhostile;
+               
+               calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile );
 
                allFriends.distributeLossesGains(friends, tick);
                allHostiles.distributeLossesGains(friends, tick);
 
                allFriends.distributeLossesGains(friends, tick);
                allHostiles.distributeLossesGains(friends, tick);
@@ -107,7 +110,59 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
 
 //////////////////////////////////////////////////////////////////////////
 //
 
 //////////////////////////////////////////////////////////////////////////
 //
-void Planet::calcOneTick(Planet* friendly, Fleet* Hostile)
+void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string, std::map<std::string, int> >& stealfriendly, std::map<std::string, std::map<std::string, int> >&  stealhostile )
 {
 {
+       map<int, string> 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<int, string>::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<string, int> 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;
+       }
 }
 
 }
 
index a19a858c0e032ad4654a8939adf9f9dbd9b752fb..2d513618342c26c44253178712b3bea0cfabbcd7 100644 (file)
@@ -48,7 +48,7 @@ public:
        void runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile);
 
 protected:
        void runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile);
 
 protected:
-       void calcOneTick(Planet* friendly, Fleet* Hostile);
+       void calcOneTick(Planet* friendly, Fleet* Hostile, std::map<std::string, std::map<std::string, int> >& stealfriendly, std::map<std::string, std::map<std::string, int> >&  stealhostile );
 
        unsigned m_iScore;
        RoidList m_Roids;
 
        unsigned m_iScore;
        RoidList m_Roids;