From: Michael Andreen Date: Fri, 10 May 2002 12:33:31 +0000 (+0000) Subject: hbs now handles salvage.. not fully correctly yet though, need to fix X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=commitdiff_plain;h=924d4cd0f8c9c340c8ba6f2e5759fed8f0c83573 hbs now handles salvage.. not fully correctly yet though, need to fix the calculations when stolen ships is in.. --- diff --git a/bs/bsconf.cpp b/bs/bsconf.cpp index 478b8d4..816fd09 100644 --- a/bs/bsconf.cpp +++ b/bs/bsconf.cpp @@ -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; diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 3df0972..19bc386 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -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::calculateSide(std::vector fleets, int stays = vector fl; for (vector::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 cerr << "Lost " << lost << " " << unittype << " due to stealing ships worth: " << stealscore << endl; killFleet(unittype, lost, tick); } + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::distributeStolenShips(std::map > stolen, std::vector fleets, int tick = 0) +{ + for(map >::iterator i = stolen.begin(); i != stolen.end(); ++i) + { + int totalstealers = 0; + for (vector::iterator j = fleets.begin(); j != fleets.end(); ++j) + totalstealers += (*j)->fleet(i->first, tick - 1); + + for (map::iterator j = i->second.begin(); j != i->second.end(); ++j) + { + for (vector::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 res = s_Units[i->first].resources(); + + if (i->second.size() > 0) + cerr << endl << i->first << ": "; + + int tick = 0; + for (vector::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::iterator k = res.begin(); k != res.end(); ++k) + addResource(k->first, lostunits * k->second * 0.25, tick); + } + } +} diff --git a/bs/fleet.h b/bs/fleet.h index 3c690fd..6696151 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -266,6 +266,9 @@ public: void calculateLostStealships(std::string unittype, std::map stolen, int tick = 1); + void distributeStolenShips(std::map > stolen, std::vector fleets, int tick = 0); + + void calculateSalvage(); /** This function prints out all the ships in the fleet to stderr, * mainly used for debugging. */ diff --git a/bs/planet.cpp b/bs/planet.cpp index d62bf57..f1290ff 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -197,9 +197,11 @@ void Planet::runBattle(std::vector friendly, std::vector 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 friendly, std::vector hostile setRoids(i->first, roids(i->first, 1), tick);*/ } + for (vector::iterator i = friendly.begin(); i != friendly.end(); ++i) + (*i)->calculateSalvage(); + for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i) { for (vector::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; } diff --git a/bs/ui/infoview.ui b/bs/ui/infoview.ui index bb57b75..a8ed7ac 100644 --- a/bs/ui/infoview.ui +++ b/bs/ui/infoview.ui @@ -9,7 +9,7 @@ 0 - 4 + 0 267 221 @@ -235,7 +235,7 @@ StaySpin - 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 + 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> diff --git a/bs/ui/resourceview.ui b/bs/ui/resourceview.ui index 971f006..71eae5a 100644 --- a/bs/ui/resourceview.ui +++ b/bs/ui/resourceview.ui @@ -10,8 +10,8 @@ 0 0 - 551 - 105 + 549 + 110 @@ -25,14 +25,14 @@ 0 - 105 + 110 QGroupBoxForm - Resources and Score + Roids/Salvage and Score diff --git a/bs/unittype.cpp b/bs/unittype.cpp index 20c30a3..36bd4ed 100644 --- a/bs/unittype.cpp +++ b/bs/unittype.cpp @@ -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 res) +{ + m_Resources = res; +} + +////////////////////////////////////////////////////////////////////////// +// +std::map UnitType::resources() +{ + return m_Resources; } ////////////////////////////////////////////////////////////////////////// // int UnitType::totRes() const { - return m_iTotalResources; + int totres = 0; + for (map::const_iterator i = m_Resources.begin(); i != m_Resources.end(); ++i) + totres += i->second; + return totres; } ////////////////////////////////////////////////////////////////////////// diff --git a/bs/unittype.h b/bs/unittype.h index b01de80..ccff1d1 100644 --- a/bs/unittype.h +++ b/bs/unittype.h @@ -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 res); /** Returns the number of total resources this unittype cost. */ int totRes() const; + std::map 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 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 m_Resources; + std::string m_sType; //!< normal,emp,cloak,steal,pod + int m_iETA; + int m_iFuel; }; #endif