X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=blobdiff_plain;f=bs%2Ffleet.cpp;h=85304bb2bfcb6e642826764749ca1bad9a2ea4be;hp=136ad22ac8a77860265672eae5db422a012eb978;hb=b308a9445cfe1883ea8068d3f4d1a04bfcff9aa8;hpb=217cda78005f993fd6b2e575d4abd97c93cec655 diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 136ad22..85304bb 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -28,6 +28,7 @@ UnitList Fleet::s_Units; Fleet::Fleet() { m_iETA = 0; + m_iStays = 3; m_sRace = "Cathaar"; } @@ -222,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) @@ -332,12 +337,14 @@ 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()) < 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; } - else if ((*i)->name() == "Home Planet") + else if ((*i)->stays() < 0) fl.push_back((*i)); } return fl; @@ -712,9 +719,103 @@ void Fleet::distributeCappedRoids(std::vector fleets, int tick = 0) ////////////////////////////////////////////////////////////////////////// // - void Fleet::addFleet(std::map units, int tick = 0) { for (map::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 stolen, int tick = 1) +{ + int stealscore = 0; + for (map::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); +} + +////////////////////////////////////////////////////////////////////////// +// +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); + } + } +} + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::resetTicks() +{ + for (FleetList::iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i) + { + if ( i->second.size() < 2) + continue; + + int temp = i->second[0]; + i->second.clear(); + + if (temp > 0) + i->second.push_back(temp); + } + resetResources(); +}