]> ruin.nu Git - hbs.git/commitdiff
A few more bugs killed.. still a few left before 0.1 release..
authorMichael Andreen <harv@ruin.nu>
Fri, 12 Apr 2002 10:19:35 +0000 (10:19 +0000)
committerMichael Andreen <harv@ruin.nu>
Fri, 12 Apr 2002 10:19:35 +0000 (10:19 +0000)
bs/bsview.cpp
bs/fleet.cpp
bs/fleetview.cpp
bs/planet.cpp
bs/planet.h
bs/ui/resourceview.ui
bs/ui/roidseditview.ui
bs/ui/roidseditview.ui.h

index 44ddfa43acdc832f7b82681ee4a886e9b431ed08..ccf334158c714641a2eaac86a39c32794364ccc4 100644 (file)
@@ -405,6 +405,7 @@ void BSView::updateFleetView()
                        connect(m_TickView, SIGNAL(ticksChanged(int,int)), m_FleetView, SLOT(slotViewTickRange(int,int)));
                        m_FleetViews->addWidget(m_FleetView, 1);
                }
+               m_FleetViews->raiseWidget(2);
                m_FleetViews->raiseWidget(1);
        }
 }
index 95ae6d35789a4ca360c794e71d2670a2947e7f3f..ed5efb9fd16881f48f127302f9a92f1437c68f95 100644 (file)
@@ -224,7 +224,10 @@ void Fleet::addToThis(std::vector<Fleet*> fleets, int tick = 0)
 
                for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
                {
-                       m_Fleet[i->first][0] += (*j)->fleet(i->first, tick);
+                       int num = (*j)->fleet(i->first, tick);
+                       m_Fleet[i->first][0] += num;
+                       if (num > 0)
+                               cerr << (*j)->name() <<  " adding " << num << " units of type " << i->first << endl;
                }
        }
 }
@@ -248,11 +251,15 @@ void Fleet::distributeLossesGains(std::vector<Fleet*> fleets, int tick = 0)
 
 
                cerr << "Distributing type: " << unittype << " with a total loss of " << totallost << " units" << endl;
+
+               cerr << "Total number of units before: " << fleet(unittype, 0)  << " and after : " << fleet(unittype, 1) << endl;
                
                for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
                {
-                       int lost =  totallost * ( (*j)->fleet(unittype, tick - 1) / m_Fleet[unittype][0] );
-                       cerr << (*j)->name() << " gaining " << lost << " " << unittype << endl;
+                       int fl1 = (*j)->fleet(unittype, tick - 1);
+                       float part = float(fl1) / fleet(unittype, 0) ;
+                       int lost =  totallost * part;
+                       cerr << (*j)->name() << " gaining " << lost << " " << unittype  << " since it's " << part * 100 << "% of the whole fleet, and it had : " << fl1 << " units last tick.." <<  endl;
                        (*j)->setFleet(unittype, (*j)->fleet(unittype, tick - 1) + lost, tick);
                }
        }
@@ -300,13 +307,16 @@ int Fleet::freeFleet(std:: string unittype, int tick = 0)
 void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits)
 {
 
-       int guns = s_Units[unittype].guns() * number;
+       float guns = s_Units[unittype].guns() * number;
+
+       cerr << number << " " << unittype << ": with " << guns << " guns\n";
+       
        if (guns == 0)
                return;
 
        cerr << unittype << ": with " << guns << " guns\n";
 
-       int gunsleft = guns;
+       float gunsleft = guns;
        for (int count = 0; count < 3; ++count)//vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
        {
                string ta = s_Units[unittype].target(count);
@@ -345,15 +355,15 @@ void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, in
 
                        for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
                        {
-                               int maxguns = (*j->second)/total * guns;
-                               cerr << "Now shooting at target: " << j->first << endl;
+                               float maxguns = float((*j->second))/total * guns;
+                               //cerr << "Now shooting at target: " << j->first << endl;
 
                                if (m_Armor[j->first] <= 0 || m_Armor[j->first] > s_Units[j->first].armor())
                                        m_Armor[j->first] = s_Units[j->first].armor();
                                double k = maxguns;
 
-                               cerr << "Targets agility: " << s_Units[j->first].agility() << endl;
-                               cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl;
+                               //cerr << "Targets agility: " << s_Units[j->first].agility() << endl;
+                               //cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl;
                                while (k > 0)   
                                {
 
@@ -411,7 +421,7 @@ void Fleet::takeEMP(std::string unittype, int number)
 
        cerr << unittype << ": with " << guns << " guns\n";
 
-       int gunsleft = guns;
+       float gunsleft = guns;
        for (int count = 0; count < 3; ++count)//vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
        {
                string ta = s_Units[unittype].target(count);
@@ -486,10 +496,15 @@ void Fleet::takeEMP(std::string unittype, int number)
 //
 void Fleet::killFleet(std::string unittype, int number, int tick = 0)
 {
-       if (m_Fleet[unittype].size() <= tick)
+       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(m_Fleet[unittype][m_Fleet[unittype].size()] - number);
-               return;
+               m_Fleet[unittype].push_back(earlier);
        }
        m_Fleet[unittype][tick] -= number;
 }
index 5cbed5377caa4797c794f8a3bba2f167779298fe..a261b934b21d3433f18e8ac6e9fdd6da325a8d86 100644 (file)
@@ -91,7 +91,7 @@ void FleetView::viewFleet(const Fleet* fleet, bool friendly)
        {
                m_Fleet = new Fleet(*fleet);
        }
-       m_Fleet->printFleet();
+       //m_Fleet->printFleet();
        fillTable();
 }
 
@@ -235,4 +235,32 @@ void FleetView::slotViewTickRange(int min = -1, int max = -1)
                int after = m_Fleet->fleet(i->latin1(), m_iMaxTick);
                m_UnitsLostSurvivedView[(*i)]->setText(QString("%1").arg(after - before));
        }
+
+       Planet* pl;
+       if ((pl = dynamic_cast<Planet*>(m_Fleet)))
+       {
+               int lost;
+               int before;
+               int after;
+
+               before = pl->roids(tr("metal").latin1(),m_iMinTick);
+               after = pl->roids(tr("metal").latin1(),m_iMaxTick);
+               lost = after - before;
+               m_RoidsEditView->slotSetLost(tr("metal"),lost);
+
+               before = pl->roids(tr("crystal").latin1(),m_iMinTick);
+               after = pl->roids(tr("crystal").latin1(),m_iMaxTick);
+               lost = after - before;
+               m_RoidsEditView->slotSetLost(tr("crystal"),lost);
+
+               before = pl->roids(tr("eonium").latin1(),m_iMinTick);
+               after = pl->roids(tr("eonium").latin1(),m_iMaxTick);
+               lost = after - before;
+               m_RoidsEditView->slotSetLost(tr("eonium"),lost);
+
+               before = pl->roids(tr("uninit").latin1(),m_iMinTick);
+               after = pl->roids(tr("uninit").latin1(),m_iMaxTick);
+               lost = after - before;
+               m_RoidsEditView->slotSetLost(tr("uninit"),lost);
+       }
 }
index 8fd1726b3979c4d287eb004597758315c762a28b..443b3b13695a31c2ba7d71854750acfcc2bd3241 100644 (file)
@@ -65,6 +65,7 @@ int Planet::roids(std::string type, int tick = 0) const
 
        if( ticks == 0)
                return 0;
+       --ticks;
        if (ticks < tick)
                return roids->at(ticks);
        return roids->at(tick);
@@ -72,13 +73,34 @@ int Planet::roids(std::string type, int tick = 0) const
 
 //////////////////////////////////////////////////////////////////////////
 //
-void Planet::setRoids(std::string type, int number)
+void Planet::setRoids(std::string type, int number, int tick = 0)
 {
-       if (m_Roids[type].size() == 0)
-               m_Roids[type].push_back(number);
-       m_Roids[type][0] = number;
+       int ticks = m_Roids[type].size();
+       int roids = 0;
+       if (m_Roids[type].size() > 0)
+               roids = m_Roids[type][m_Roids[type].size() - 1];
+
+       for (int i = ticks; i <= tick; ++i )
+               m_Roids[type].push_back(roids);
+       m_Roids[type][tick] = number;
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+void Planet::takeRoids(std::string type, int number, int tick = 0)
+{
+       int ticks = m_Roids[type].size();
+       int roids = 0;
+       if (m_Roids[type].size() > 0)
+               roids = m_Roids[type][m_Roids[type].size() - 1];
+
+       for (int i = ticks; i <= tick; ++i )
+               m_Roids[type].push_back(roids);
+       m_Roids[type][tick] -= number;
+}
+
+
+
 //////////////////////////////////////////////////////////////////////////
 //
 void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile)
@@ -103,26 +125,40 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
                        skipped = 0;
 
                Planet allFriends;
-               allFriends.addToThis(friends, tick);
+               allFriends.addToThis(friends, tick - 1);
+
+               /*for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
+                       allFriends.setRoids(i->first, roids(i->first, tick));
+
+               allFriends.setPlanetScore(m_iScore);*/
                
                Fleet allHostiles;
-               allHostiles.addToThis(hostiles, tick);
+               allHostiles.addToThis(hostiles, tick - 1);
 
                map<string, map<string, int> > stealfriendly;
                map<string, map<string, int> > stealhostile;
                
-               calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile );
+               calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile, tick );
 
                //allFriends.printFleet();
 
                allFriends.distributeLossesGains(friends, tick);
                allHostiles.distributeLossesGains(hostiles, tick);
+
+       /*      for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
+                       setRoids(i->first, roids(i->first, 1), tick);*/
+       }
+
+       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)
+                       cout << i->first << " roids : " << (*j) << endl;
        }
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
-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 )
+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, int tick = 0)
 {
        map<int, string> unitsinit; // order units after their ininitiative
        for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
@@ -156,19 +192,38 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
 
                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)
+                       if (m_iScore <= 0) break;
+                       float capping = float(m_iScore) / hostile->score() /  10;
+                       
+                       cerr << "Capping is: " << capping << endl;
+
+                       if (capping > 0.15)
+                               capping = 0.15;
+                       if (capping <= 0)
+                               break;
+
+                       for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid)
                        {
-                               int caproids = capping * roids->second[0];
+                               int caproids = capping * 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)
+                               if (freepods <= 0)
                                        break;
                                if (freepods < caproids)
-                                       caproids = caproids - freepods;
+                                       caproids = freepods;
+
+                               cerr << caproids << " roids stolen\n";
                                        
-                               roids->second.push_back(roids->second[0] - caproids);
+                               takeRoids(roid->first, caproids, tick);
+
                                hostiletemp->killFleet(unittype, caproids, 1);
+                               int totroids = caproids + hostiletemp->resource(roid->first, 0);
+                               hostiletemp->setResource(roid->first, totroids, 1);
+                               
+                               cerr << totroids << " stolen " << roid->first << " roids\n";
                        }
                }
 
index 2d513618342c26c44253178712b3bea0cfabbcd7..e5c173e0cda880cf44b39c4e9134dcc6ddcbb39a 100644 (file)
@@ -43,12 +43,13 @@ public:
        void setPlanetScore(unsigned i);
 
        int roids(std::string type, int tick = 0) const;
-       void setRoids(std::string type, int number);
+       void setRoids(std::string type, int number, int tick = 0);
+       void takeRoids(std::string type, int number, int tick = 0);
 
        void runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile);
 
 protected:
-       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 );
+       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, int tick = 0);
 
        unsigned m_iScore;
        RoidList m_Roids;
index 47043bf9ba2f59ee978c62bb28e08cc07d00998c..9495a81b8a05b865ceec617af981aab9c9548e00 100644 (file)
@@ -9,19 +9,25 @@
     <property name="geometry">
         <rect>
             <x>0</x>
-            <y>0</y>
-            <width>198</width>
-            <height>89</height>
+            <y>11</y>
+            <width>222</width>
+            <height>105</height>
         </rect>
     </property>
     <property name="sizePolicy">
         <sizepolicy>
             <hsizetype>5</hsizetype>
-            <vsizetype>5</vsizetype>
+            <vsizetype>4</vsizetype>
             <horstretch>0</horstretch>
             <verstretch>0</verstretch>
         </sizepolicy>
     </property>
+    <property name="minimumSize">
+        <size>
+            <width>0</width>
+            <height>105</height>
+        </size>
+    </property>
     <property name="caption">
         <string>QGroupBoxForm</string>
     </property>
             <cstring>unnamed</cstring>
         </property>
         <property name="margin">
-            <number>5</number>
+            <number>11</number>
         </property>
         <property name="spacing">
-            <number>2</number>
+            <number>6</number>
         </property>
         <widget class="QLabel" row="0" column="1">
             <property name="name">
index bd0d94917974047e88b92386d243cbd9c71538ee..caa54900128e32731ad6e8f795e7bff180bbe531 100644 (file)
@@ -39,6 +39,9 @@
             <property name="name">
                 <cstring>eoniumLabel</cstring>
             </property>
+            <property name="frameShape">
+                <enum>MShape</enum>
+            </property>
             <property name="text">
                 <string>Eonium</string>
             </property>
 <slots>
     <slot>init()</slot>
     <slot>setValue( const QString &amp; type, unsigned value )</slot>
-    <slot access="protected">slotValueChanged( const QString &amp; s )</slot>
+    <slot>slotValueChanged( const QString &amp; s )</slot>
+    <slot>slotSetLost( QString type, int i )</slot>
 </slots>
 <pixmapinproject/>
 <layoutdefaults spacing="0" margin="2"/>
index e22a408540798be1dd3ca9bffb6025cec21bd9b1..22a8230ee24d3c7a401603ea661f9fa1f5cf0f0e 100644 (file)
@@ -43,4 +43,20 @@ void RoidsEditView::slotValueChanged( const QString & s )
                type = tr("score");
        test = type;
     emit changed(type, s.toInt());
+}
+
+
+void RoidsEditView::slotSetLost( QString type, int i )
+{ 
+    if (type == tr("metal"))
+       MetalLostEdit->setText(QString("%1").arg(i));
+    else if (type == tr("crystal"))
+       CrystalLostEdit->setText(QString("%1").arg(i));
+    else if (type == tr("eonium"))
+       EoniumLostEdit->setText(QString("%1").arg(i));
+    else if (type == tr("uninit"))
+       UninitLostEdit->setText(QString("%1").arg(i));
+    /*else if (type == tr("score"))
+       ScoreEdit->setText(QString("%1").arg(i));
+    */
 }
\ No newline at end of file