the calculations when stolen ships is in..
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;
//
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)
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;
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);
+ }
+ }
+}
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.
*/
//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);
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)
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;
}
<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 <p> <b>If you use -1 for an atttacker and it freeze, IT'S YOUR OWN FAULT! </b></string>
</property>
</widget>
<widget class="QSpinBox" row="5" column="1" rowspan="1" colspan="2">
<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">
//////////////////////////////////////////////////////////////////////////
//
-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;
}
//////////////////////////////////////////////////////////////////////////
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 */
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