]> ruin.nu Git - hbs.git/commitdiff
added code so you lose ships if you steal..
authorMichael Andreen <harv@ruin.nu>
Thu, 9 May 2002 17:22:01 +0000 (17:22 +0000)
committerMichael Andreen <harv@ruin.nu>
Thu, 9 May 2002 17:22:01 +0000 (17:22 +0000)
bs/bsdoc.cpp
bs/bsview.cpp
bs/fleet.cpp
bs/fleet.h
bs/planet.cpp
bs/ui/infoview.ui
bs/ui/infoview.ui.h

index 11042b73cccf8eca3f063286fc74db110935b539..462dc75e89177eef3aed62488869e6f1da80a9c3 100644 (file)
@@ -69,6 +69,7 @@ int BSDoc::newBattle(QString name)
        m_Battles[name]["Friendly"]["Home Planet"]->setName("Home Planet");
        m_Battles[name]["Friendly"]["Home Fleet"]->setName("Home Fleet");
        m_Battles[name]["Friendly"]["Home Fleet"]->setRace("Terran");
+       m_Battles[name]["Friendly"]["Home Fleet"]->setStays(-1);
        m_Battles[name]["Hostile"]["Evil guy"]->setName("Evil guy");
        m_Battles[name]["Hostile"]["Evil guy"]->setETA(1);
 
index 7adc6db02ad18be3c2fbc297375a1480d57abb72..df3f558d97de534a8a5d37512581b9c1de3c2a4f 100644 (file)
@@ -278,6 +278,7 @@ void BSView::slotInfoApply()
        fl->setETA(m_InfoView->eta());
        fl->setName(m_sFleet.latin1());
        fl->setRace(m_InfoView->race().latin1());
+       fl->setStays(m_InfoView->stays());
        
        m_doc->newFleet(m_sBattle, m_sGroup, m_sFleet, fl);
 }
@@ -317,6 +318,7 @@ void BSView::slotInfoNew()
        fl->setETA(m_InfoView->eta());
        fl->setName(m_sFleet.latin1());
        fl->setRace(m_InfoView->race().latin1());
+       fl->setStays(m_InfoView->stays());
 
        m_doc->newFleet(m_sBattle, m_sGroup, m_sFleet, fl);
 
@@ -365,6 +367,7 @@ void BSView::updateInfoView()
        m_InfoView->setEta(fl->ETA());
        m_InfoView->setGroup(m_sGroup);
        m_InfoView->setBattle(m_sBattle);
+       m_InfoView->setStays(fl->stays());
 }
 
 //////////////////////////////////////////////////////////////////////////
index 136ad22ac8a77860265672eae5db422a012eb978..3df0972e0584f0b3d4e541b0de0b9964237b0b19 100644 (file)
@@ -28,6 +28,7 @@ UnitList Fleet::s_Units;
 Fleet::Fleet()
 {
        m_iETA = 0;
+       m_iStays = 3;
        m_sRace = "Cathaar";
 }
 
@@ -332,12 +333,12 @@ 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()) < stays)
+               if (( tick - (*i)->ETA()) >= 0 && (tick - (*i)->ETA()) < (*i)->stays())
                {
                        fl.push_back((*i));
                        cerr << "Using fleet " << (*i)->name() << " for tick " << tick << endl;
                }
-               else if ((*i)->name() == "Home Planet")
+               else if ((*i)->stays() < 0)
                        fl.push_back((*i));
        }
        return fl;
@@ -712,9 +713,38 @@ void Fleet::distributeCappedRoids(std::vector<Fleet*> fleets, int tick = 0)
 
 //////////////////////////////////////////////////////////////////////////
 //
-
 void Fleet::addFleet(std::map<string, int> units, int tick = 0)
 {
        for (map<string, int>::iterator i = units.begin(); i != units.end(); ++i)
                addFleet(i->first, i->second, tick);
 }
+
+//////////////////////////////////////////////////////////////////////////
+//
+int Fleet::stays() const
+{
+       return m_iStays;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::setStays(int ticks)
+{
+       m_iStays = ticks;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::calculateLostStealships(string unittype, std::map<std::string, int> stolen, int tick = 1)
+{
+       int stealscore = 0;
+       for (map<string, int>::iterator i = stolen.begin(); i != stolen.end(); ++i)
+       {
+               stealscore += stolen[i->first] * (s_Units[i->first].totRes() / 10.0);   
+       }
+
+       int lost = stealscore / (s_Units[unittype].totRes() / 10.0);
+
+       cerr << "Lost " << lost << " " << unittype << " due to stealing ships worth: " << stealscore << endl; 
+       killFleet(unittype, lost, tick);
+}
index 93bdee74a247d04ad4c75db9b173a515ce8707aa..3c690fddb775886c08d5c4f4d4fee78d01677b16 100644 (file)
@@ -227,6 +227,13 @@ public:
        int resource(std::string type, int tick = 0)const;
        
        void resetResources();
+
+       /** This function tells how many ticks the fleet stays at it's target.
+        * \returns the number of ticks as an int.
+        */
+       int stays() const;
+       void setStays(int ticks);
+
        /** 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.
@@ -257,6 +264,8 @@ public:
         */
        void takeEMP(std::string unittype, int number);
 
+       void calculateLostStealships(std::string unittype, std::map<std::string, int> stolen, int tick = 1);
+
        /** This function prints out all the ships in the fleet to stderr,
         * mainly used for debugging.
         */
@@ -288,13 +297,14 @@ public:
 protected:
 
 
-       std::string     m_sName;
-       std::string     m_sRace;
-       int         m_iETA;
-       FleetList       m_Fleet;
-       FleetList       m_BlockedFleet;
+       std::string  m_sName;
+       std::string      m_sRace;
+       int          m_iETA;
+       FleetList    m_Fleet;
+       FleetList    m_BlockedFleet;
        ResourceList m_Resources;
-       ArmorList       m_Armor;
+       ArmorList        m_Armor;
+       int          m_iStays;
        
 
 
index f57d20877ed5455f262c495271204c4daa1f6795..d62bf579996a1f0d583a66302fce706531c9ac59 100644 (file)
@@ -23,6 +23,7 @@ using namespace std;
 Planet::Planet()
 {
        m_sRace = "Planet";
+       m_iStays = -1;
 }
 
 Planet::~Planet(){
@@ -225,6 +226,7 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
        map<string, int> pods;
 
 
+       //FIXME: Need to change this and allow multiple shiptypes with the same initiative.
        map<int, string> unitsinit; // order units after their ininitiative
        for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
                unitsinit[i->second.initiative()] = i->first;
@@ -247,6 +249,9 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
                {
                        hostiletemp->takeShoot(unittype, friendly->freeFleet(unittype, 1), stealfriendly[unittype]);
                        friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), stealhostile[unittype]);
+
+                       friendlytemp->calculateLostStealships(unittype, stealfriendly[unittype], 1);
+                       hostiletemp->calculateLostStealships(unittype, stealhostile[unittype], 1);
                }
                else
                {
@@ -257,6 +262,7 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
 
                if (s_Units[unittype].type() == "Pod")
                {
+                       //FIXME: Prolly need to recode the whole capping section for r7, due to multiple pods thingy
                        cerr << "Capping is: " << capping(tick) << endl;
        
                        if (capping(tick) > 0)
index 33135f7ef3f7373ad4e9a29aa764735cb634b850..bb57b75002469dc7b26c71ed8fcc2639fcdc425e 100644 (file)
@@ -9,9 +9,9 @@
     <property name="geometry">
         <rect>
             <x>0</x>
-            <y>0</y>
+            <y>4</y>
             <width>267</width>
-            <height>198</height>
+            <height>221</height>
         </rect>
     </property>
     <property name="sizePolicy">
@@ -25,7 +25,7 @@
     <property name="maximumSize">
         <size>
             <width>32767</width>
-            <height>200</height>
+            <height>221</height>
         </size>
     </property>
     <property name="caption">
             <cstring>unnamed</cstring>
         </property>
         <property name="margin">
-            <number>3</number>
+            <number>0</number>
         </property>
         <property name="spacing">
-            <number>2</number>
+            <number>0</number>
         </property>
         <widget class="QLabel" row="1" column="0">
             <property name="name">
                 <enum>NoInsertion</enum>
             </property>
         </widget>
-        <widget class="QLabel" row="5" column="0">
-            <property name="name">
-                <cstring>RaceLabel</cstring>
-            </property>
-            <property name="text">
-                <string>&amp;Race</string>
-            </property>
-            <property name="buddy" stdset="0">
-                <cstring>RaceCombo</cstring>
-            </property>
-        </widget>
-        <widget class="QLineEdit" row="3" column="1" rowspan="1" colspan="2">
-            <property name="name">
-                <cstring>NameLine</cstring>
-            </property>
-        </widget>
-        <widget class="QLabel" row="3" column="0">
-            <property name="name">
-                <cstring>NameLabel</cstring>
-            </property>
-            <property name="text">
-                <string>Na&amp;me</string>
-            </property>
-            <property name="buddy" stdset="0">
-                <cstring>NameLine</cstring>
-            </property>
-        </widget>
-        <widget class="QComboBox" row="5" column="1" rowspan="1" colspan="2">
-            <property name="name">
-                <cstring>RaceCombo</cstring>
-            </property>
-        </widget>
-        <widget class="QLabel" row="4" column="0">
-            <property name="name">
-                <cstring>EtaLabel</cstring>
-            </property>
-            <property name="text">
-                <string>E&amp;ta</string>
-            </property>
-            <property name="buddy" stdset="0">
-                <cstring>EtaSpin</cstring>
-            </property>
-        </widget>
-        <widget class="QSpinBox" row="4" column="1" rowspan="1" colspan="2">
-            <property name="name">
-                <cstring>EtaSpin</cstring>
-            </property>
-        </widget>
-        <spacer row="2" column="2">
-            <property name="name" stdset="0">
-                <cstring>Spacer3</cstring>
-            </property>
-            <property name="orientation">
-                <enum>Vertical</enum>
-            </property>
-            <property name="sizeType">
-                <enum>Expanding</enum>
-            </property>
-            <property name="sizeHint">
-                <size>
-                    <width>20</width>
-                    <height>20</height>
-                </size>
-            </property>
-        </spacer>
-        <widget class="QLayoutWidget" row="7" column="0" rowspan="1" colspan="3">
+        <widget class="QLayoutWidget" row="8" column="0" rowspan="1" colspan="3">
             <property name="name">
                 <cstring>Layout13</cstring>
             </property>
                     </property>
                 </widget>
                 <spacer>
-                    <property name="name" stdset="0">
+                    <property name="name">
                         <cstring>Spacer1</cstring>
                     </property>
                     <property name="orientation">
                     <property name="sizeType">
                         <enum>Expanding</enum>
                     </property>
-                    <property name="sizeHint">
-                        <size>
-                            <width>20</width>
-                            <height>20</height>
-                        </size>
-                    </property>
                 </spacer>
                 <widget class="QPushButton">
                     <property name="name">
                 </widget>
             </hbox>
         </widget>
-        <spacer row="6" column="1">
-            <property name="name" stdset="0">
+        <spacer row="7" column="1">
+            <property name="name">
                 <cstring>Spacer4</cstring>
             </property>
             <property name="orientation">
             <property name="sizeType">
                 <enum>Expanding</enum>
             </property>
-            <property name="sizeHint">
-                <size>
-                    <width>20</width>
-                    <height>20</height>
-                </size>
+        </spacer>
+        <widget class="QLabel" row="6" column="0">
+            <property name="name">
+                <cstring>RaceLabel</cstring>
+            </property>
+            <property name="text">
+                <string>&amp;Race</string>
+            </property>
+            <property name="buddy" stdset="0">
+                <cstring>RaceCombo</cstring>
+            </property>
+        </widget>
+        <widget class="QComboBox" row="6" column="1" rowspan="1" colspan="2">
+            <property name="name">
+                <cstring>RaceCombo</cstring>
+            </property>
+        </widget>
+        <spacer row="2" column="2">
+            <property name="name">
+                <cstring>Spacer3</cstring>
+            </property>
+            <property name="orientation">
+                <enum>Vertical</enum>
+            </property>
+            <property name="sizeType">
+                <enum>Expanding</enum>
             </property>
         </spacer>
+        <widget class="QLabel" row="3" column="0">
+            <property name="name">
+                <cstring>NameLabel</cstring>
+            </property>
+            <property name="text">
+                <string>Na&amp;me</string>
+            </property>
+            <property name="buddy" stdset="0">
+                <cstring>NameLine</cstring>
+            </property>
+        </widget>
+        <widget class="QLabel" row="4" column="0">
+            <property name="name">
+                <cstring>EtaLabel</cstring>
+            </property>
+            <property name="text">
+                <string>E&amp;ta</string>
+            </property>
+            <property name="buddy" stdset="0">
+                <cstring>EtaSpin</cstring>
+            </property>
+        </widget>
+        <widget class="QLineEdit" row="3" column="1" rowspan="1" colspan="2">
+            <property name="name">
+                <cstring>NameLine</cstring>
+            </property>
+        </widget>
+        <widget class="QSpinBox" row="4" column="1" rowspan="1" colspan="2">
+            <property name="name">
+                <cstring>EtaSpin</cstring>
+            </property>
+        </widget>
+        <widget class="QLabel" row="5" column="0">
+            <property name="name">
+                <cstring>StayLabel</cstring>
+            </property>
+            <property name="text">
+                <string>Stays</string>
+            </property>
+            <property name="buddy" stdset="0">
+                <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>
+            </property>
+        </widget>
+        <widget class="QSpinBox" row="5" column="1" rowspan="1" colspan="2">
+            <property name="name">
+                <cstring>StaySpin</cstring>
+            </property>
+            <property name="minValue">
+                <number>-1</number>
+            </property>
+        </widget>
     </grid>
 </widget>
 <connections>
     <slot returnType="QString">group()</slot>
     <slot returnType="QString">race()</slot>
     <slot>slotNameChanged( const QString &amp; s )</slot>
+    <slot returnType="int">stays()</slot>
+    <slot>setStays( int ticks )</slot>
 </slots>
 <layoutdefaults spacing="0" margin="0"/>
 </UI>
index a50bb950a2749e12be7666902e979f4bfe250321..1a7d70d4d473669b41ba6d2f24d71c550b490adc 100644 (file)
@@ -148,4 +148,15 @@ void InfoView::slotNameChanged( const QString & s )
        ApplyButton->setEnabled(true);
        NewButton->setEnabled(false);
     }
-}
\ No newline at end of file
+}
+
+
+int InfoView::stays()
+{
+    return StaySpin->value();
+}
+
+void InfoView::setStays( int ticks )
+{
+    StaySpin->setValue(ticks);
+}