]> ruin.nu Git - hbs.git/commitdiff
hbs now handles salvage.. not fully correctly yet though, need to fix
authorMichael Andreen <harv@ruin.nu>
Fri, 10 May 2002 12:33:31 +0000 (12:33 +0000)
committerMichael Andreen <harv@ruin.nu>
Fri, 10 May 2002 12:33:31 +0000 (12:33 +0000)
the calculations when stolen ships is in..

bs/bsconf.cpp
bs/fleet.cpp
bs/fleet.h
bs/planet.cpp
bs/ui/infoview.ui
bs/ui/resourceview.ui
bs/unittype.cpp
bs/unittype.h

index 478b8d456bb64621effb19fe78ae09fbd235bb91..816fd09865f86a8cf362202f9b22441e3056f887 100644 (file)
@@ -112,7 +112,10 @@ bool BSConf::loadStats()
                                t1 >> metal;
                                t1 >> crystal;
                                t1 >> eonium;
-                               units[race].setTotalResources(metal.toInt() + crystal.toInt() + eonium.toInt());
+                               units[race].setResources(tr("metal").latin1(), metal.toInt());
+                               units[race].setResources(tr("crystal").latin1(), crystal.toInt());
+                               units[race].setResources(tr("eonium").latin1(), eonium.toInt());
+                               //units[race].setTotalResources(metal.toInt() + crystal.toInt() + eonium.toInt());
                                t1 >> temp;
                                units[race].setFuel(temp.toInt());
                                t1 >> temp;
index 3df0972e0584f0b3d4e541b0de0b9964237b0b19..19bc3860ef51af974aee0f3c60b14542f58ecb42 100644 (file)
@@ -223,10 +223,14 @@ void Fleet::addFleet(std::string unittype, int number, int tick = 0)
 //
 int     Fleet::fleet(string unittype, int tick = 0)
 {
+
        int ticks = m_Fleet[unittype].size();
        if (ticks == 0)
                return 0;
 
+       if (tick < 0)
+               return m_Fleet[unittype][0];
+
        --ticks;
 
        if (ticks < tick)
@@ -333,7 +337,9 @@ std::vector<Fleet*> Fleet::calculateSide(std::vector<Fleet*> fleets, int stays =
        vector<Fleet*> fl;
        for (vector<Fleet*>::iterator i = fleets.begin(); i != fleets.end(); ++i)
        {
-               if (( tick - (*i)->ETA()) >= 0 && (tick - (*i)->ETA()) < (*i)->stays())
+               if ((*i)->stays() == 0)
+                       continue;
+               else if (( tick - (*i)->ETA()) >= 0 && (tick - (*i)->ETA()) < (*i)->stays())
                {
                        fl.push_back((*i));
                        cerr << "Using fleet " << (*i)->name() << " for tick " << tick << endl;
@@ -748,3 +754,50 @@ void Fleet::calculateLostStealships(string unittype, std::map<std::string, int>
        cerr << "Lost " << lost << " " << unittype << " due to stealing ships worth: " << stealscore << endl; 
        killFleet(unittype, lost, tick);
 }
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::distributeStolenShips(std::map<std::string, std::map<std::string, int> > stolen, std::vector<Fleet*> fleets, int tick = 0)
+{
+       for(map<string, map<string, int> >::iterator i = stolen.begin(); i != stolen.end(); ++i)
+       {
+               int totalstealers = 0;
+               for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
+                       totalstealers += (*j)->fleet(i->first, tick - 1);
+
+               for (map<string, int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
+               {
+                       for (vector<Fleet*>::iterator k = fleets.begin(); k != fleets.end(); ++k)
+                       {
+                               int stolen = float ((*k)->fleet(i->first, tick - 1)) / totalstealers * j->second;
+                               (*k)->addFleet(j->first, stolen, tick);
+                       }
+               }
+       }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::calculateSalvage()
+{
+       for (FleetList::iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
+       {
+               
+               map<string, int> res = s_Units[i->first].resources();
+
+               if (i->second.size() > 0)
+                       cerr << endl << i->first << ": ";
+
+               int tick = 0;
+               for (vector<int>::iterator j = i->second.begin(); j != i->second.end(); ++j, ++tick)
+               {
+                       int lostunits = fleet(i->first, tick - 1) - fleet(i->first, tick);
+
+                       if (lostunits <= 0)
+                               continue;
+                       cerr << "(" << tick << ":" << fleet(i->first, tick) << ") ";
+                       for (map<string, int>::iterator k = res.begin(); k != res.end(); ++k)
+                               addResource(k->first, lostunits * k->second * 0.25, tick);
+               }
+       }
+}
index 3c690fddb775886c08d5c4f4d4fee78d01677b16..6696151a51303f0b4f070d05d11d5c422ed07fe4 100644 (file)
@@ -266,6 +266,9 @@ public:
 
        void calculateLostStealships(std::string unittype, std::map<std::string, int> stolen, int tick = 1);
 
+       void distributeStolenShips(std::map<std::string, std::map<std::string, int> > stolen, std::vector<Fleet*> fleets, int tick = 0);
+
+       void calculateSalvage();
        /** This function prints out all the ships in the fleet to stderr,
         * mainly used for debugging.
         */
index d62bf579996a1f0d583a66302fce706531c9ac59..f1290ff76502e560ffbcd037037d4f2480e14251 100644 (file)
@@ -197,9 +197,11 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
                //allFriends.printFleet();
 
                allFriends.distributeLossesGains(friends, tick);
+               allFriends.distributeStolenShips(stealfriendly, friends, tick);
 
                allHostiles.distributeLossesGains(hostiles, tick);
                allHostiles.distributeCappedRoids(hostiles, tick);
+               allHostiles.distributeStolenShips(stealhostile, hostiles, tick);
 
                calculateScoreLoss(friends, tick);
 
@@ -207,6 +209,9 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
                        setRoids(i->first, roids(i->first, 1), tick);*/
        }
 
+       for (vector<Fleet*>::iterator i = friendly.begin(); i != friendly.end(); ++i)
+               (*i)->calculateSalvage();
+
        for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
        {
                for (vector<int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
@@ -346,6 +351,8 @@ void Planet::setCapping(float capping, int tick = 0)
 
        if (capping <= 0.15 && capping >= 0)
                m_Capping[tick] = capping;
-       else
+       else if (capping >= 0.15)
                m_Capping[tick] = 0.15;
+       else
+               m_Capping[tick] = 0;
 }
index bb57b75002469dc7b26c71ed8fcc2639fcdc425e..a8ed7ac42fcdcf35736b07b593c115cd4785b7cd 100644 (file)
@@ -9,7 +9,7 @@
     <property name="geometry">
         <rect>
             <x>0</x>
-            <y>4</y>
+            <y>0</y>
             <width>267</width>
             <height>221</height>
         </rect>
                 <cstring>StaySpin</cstring>
             </property>
             <property name="toolTip" stdset="0">
-                <string>Sets the number of ticks the fleet stays at the target, usually 3 for hostile and 6 for friendly. The fleet is disabled if stays is 0, and it stays the whole battle if it's -1</string>
+                <string>Sets the number of ticks the fleet stays at the target, usually 3 for hostile and 6 for friendly. The fleet is disabled if stays is 0, and it stays the whole battle if it's -1 &lt;p&gt; &lt;b&gt;If you use -1 for an atttacker and it freeze, IT'S YOUR OWN FAULT! &lt;/b&gt;</string>
             </property>
         </widget>
         <widget class="QSpinBox" row="5" column="1" rowspan="1" colspan="2">
index 971f0060790e94e82ff40b0363a221907f253e09..71eae5afe5018a663b5a27753828db9eac7754b7 100644 (file)
@@ -10,8 +10,8 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>551</width>
-            <height>105</height>
+            <width>549</width>
+            <height>110</height>
         </rect>
     </property>
     <property name="sizePolicy">
     <property name="minimumSize">
         <size>
             <width>0</width>
-            <height>105</height>
+            <height>110</height>
         </size>
     </property>
     <property name="caption">
         <string>QGroupBoxForm</string>
     </property>
     <property name="title">
-        <string>Resources and Score</string>
+        <string>Roids/Salvage and Score</string>
     </property>
     <grid>
         <property name="name">
index 20c30a39e7e87660cb8810ff6391dbac5e1687aa..36bd4ed7c333c80bc063a8384980222f06b1a431 100644 (file)
@@ -224,16 +224,33 @@ int  UnitType::EMP() const
 
 //////////////////////////////////////////////////////////////////////////
 //
-void UnitType::setTotalResources(int iTR)
+void UnitType::setResources(std::string type, int i)
 {
-       m_iTotalResources = iTR;
+       m_Resources[type] = i;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void UnitType::setResources(map<std::string, int> res)
+{
+       m_Resources = res;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+std::map<std::string, int> UnitType::resources()
+{
+       return m_Resources;
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
 int UnitType::totRes() const
 {
-       return m_iTotalResources;
+       int totres = 0;
+       for (map<string, int>::const_iterator i = m_Resources.begin(); i != m_Resources.end(); ++i)
+               totres += i->second;
+       return totres;
 }
 
 //////////////////////////////////////////////////////////////////////////
index b01de80ef3c247107bfd3fb6b7c601aeef1a3f6f..ccff1d1a958a34a7162ca2df70b6f2a31c0b39b5 100644 (file)
@@ -134,10 +134,13 @@ public:
        int  EMP() const;
 
        /** Sets the resource cost for this unittype. Used for example for score calculation and so on. */
-       void setTotalResources(int iTR);
+       void setResources(std::string type, int i);
+       void setResources(std::map<std::string, int> res);
        /** Returns the number of total resources this unittype cost. */
        int totRes() const;
 
+       std::map<std::string, int> resources();
+
        /** Sets the fuelcost for this unittype */
        void setFuel(int iFuel);
        /** Returns the fuelcost */
@@ -158,17 +161,17 @@ protected:
        int                     m_iRace;            //!< Not really the race, but an indiaction on what race can use it.. 
        std::string     m_sClass;
        std::vector<std::string>        m_vTarget;
-       int                     m_iInitiative;
-       int                     m_iAgility;
-       int                     m_iWeaponSpeed;
-       int                     m_iGuns;
-       int                     m_iPower;
-       int                     m_iArmor;
-       int                     m_iEMP;
-       int                     m_iTotalResources;
-       std::string     m_sType;            //!< normal,emp,cloak,steal,pod
-       int                     m_iETA;
-       int                     m_iFuel;
+       int                       m_iInitiative;
+       int                       m_iAgility;
+       int                       m_iWeaponSpeed;
+       int                       m_iGuns;
+       int                       m_iPower;
+       int                       m_iArmor;
+       int                   m_iEMP;
+       std::map<std::string, int> m_Resources;
+       std::string   m_sType;            //!< normal,emp,cloak,steal,pod
+       int                       m_iETA;
+       int                       m_iFuel;
 };
 
 #endif