X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=blobdiff_plain;f=bs%2Ffleet.cpp;h=136ad22ac8a77860265672eae5db422a012eb978;hp=13bafb7aa071ace95640bb0e84dca2840aeb3cef;hb=217cda78005f993fd6b2e575d4abd97c93cec655;hpb=45577c33bdaab669fd787a0411996d506307708b diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 13bafb7..136ad22 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -201,6 +201,23 @@ void Fleet::setFleet(string unittype, int number, int tick = 0) m_Fleet[unittype][tick] = number; } +////////////////////////////////////////////////////////////////////////// +// +void Fleet::addFleet(std::string unittype, int number, int tick = 0) +{ + 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(earlier); + } + m_Fleet[unittype][tick] += number; +} + ////////////////////////////////////////////////////////////////////////// // int Fleet::fleet(string unittype, int tick = 0) @@ -572,10 +589,7 @@ void Fleet::addResource(std::string type, int number, int tick = 0) { int ticks = m_Resources[type].size(); - int latest = 0; - - if (ticks > 0) - latest = m_Resources[type][ticks - 1]; + int latest = resource(type, tick - 1); for (int i = ticks; i <= tick; ++i) m_Resources[type].push_back(latest); @@ -586,6 +600,9 @@ void Fleet::addResource(std::string type, int number, int tick = 0) // int Fleet::resource(std::string type, int tick = 0) const { + if (tick < 0) + return 0; + vectorconst* resource = 0; for (ResourceList::const_iterator i = m_Resources.begin(); i != m_Resources.end(); ++i) { @@ -610,6 +627,13 @@ int Fleet::resource(std::string type, int tick = 0) const return resource->at(tick); } +////////////////////////////////////////////////////////////////////////// +// +void Fleet::resetResources() +{ + m_Resources.clear() ; +} + ////////////////////////////////////////////////////////////////////////// // void Fleet::printFleet() @@ -654,6 +678,7 @@ void Fleet::distributeCappedRoids(std::vector fleets, int tick = 0) { string res = i->first; + cerr << "Distributing type: " << res << endl; for (vector::iterator j = i->second.begin(); j != i->second.end(); ++j) cout << (*j) << endl; @@ -678,17 +703,18 @@ void Fleet::distributeCappedRoids(std::vector fleets, int tick = 0) int lost = totcapped * part; cerr << (*j)->name() << " gaining " << lost << " " << res << " since it's " << part * 100 << "% of the whole score, and it had : " << fl1 << " score last tick.. compared to fleet total of: " << score(0) << endl; - (*j)->setResource(res, (*j)->resource(res,tick-1) + lost, tick); + + //(*j)->setResource(res, (*j)->resource(res,tick-1) + lost, tick); + (*j)->addResource(res,lost, tick); } } } ////////////////////////////////////////////////////////////////////////// // -void Fleet::addPodsForLostRoids(int tick = 1) + +void Fleet::addFleet(std::map units, int tick = 0) { - for (ResourceList::iterator i = m_Resources.begin(); i != m_Resources.end(); ++i) - { - setFleet("Astro Pod", fleet("Astro Pod", tick) + (resource(i->first, tick) - resource(i->first, tick - 1)), tick); - } + for (map::iterator i = units.begin(); i != units.end(); ++i) + addFleet(i->first, i->second, tick); }