From: Michael Andreen Date: Tue, 9 Apr 2002 21:57:33 +0000 (+0000) Subject: takeShoot function might work now.. X-Git-Tag: HBS_0_1_0~14 X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=commitdiff_plain;h=e5701c8f3f1199264015c5d6e0f2a32515d5f6f8 takeShoot function might work now.. --- diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 3ce2b71..432f165 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -18,6 +18,7 @@ #include "fleet.h" #include +#include using namespace std; //Static variables @@ -260,12 +261,83 @@ int Fleet::freeFleet(std:: string unittype, int tick = 0) // void Fleet::takeShoot(std::string unittype, int number, std::map& hitunits) { + int guns = s_Units[unittype].guns() * number; + int power = s_Units[unittype].power() * number; + + int gunsleft = guns; + for (vector::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i) + { + + while (gunsleft > 0) + { + + map targets; + + for (UnitList::iterator j = s_Units.begin(); j != s_Units.end(); ++j) + { + if (m_Fleet[j->first].size() == 0) + break; + + if (m_Fleet[j->first].size() == 1) + m_Fleet[j->first].push_back(m_Fleet[j->first][0]); + + if (m_Fleet[j->first][1] > 0 && (*i) == j->second.type()) + targets[j->first] = &m_Fleet[j->first][1]; + } + + int total = 0; + for (map::iterator j = targets.begin(); j != targets.end(); ++j) + total += (*j->second); + + for (map::iterator j = targets.begin(); j != targets.end(); ++j) + { + int maxguns = (*j->second)/total * guns; + + + if (m_Armor[j->first] <= 0 || m_Armor[j->first] > s_Units[j->first].armor()) + m_Armor[j->first] = s_Units[j->first].armor(); + int k = maxguns; + while (k > 0) + { + + if (*(j->second) <= 0) + break; + k -= 100/(25+s_Units[unittype].weaponSpeed() - s_Units[j->first].agility()); + m_Armor[j->first] -= s_Units[unittype].power(); + if (m_Armor[j->first] <= 0) + { + m_Armor[j->first] = s_Units[j->first].armor(); + (*j->second)--; + + //There is a chance that we're hitting a blocked ship. + if (m_BlockedFleet[j->first].size() >= 1) + { + int test = rand() % m_BlockedFleet[j->first][0]; + if (test == 1 + && m_BlockedFleet[j->first][0] > 0) + { + if (m_BlockedFleet[j->first].size() == 1) + m_BlockedFleet[j->first].push_back(m_BlockedFleet[j->first][0] - 1); + else if (m_BlockedFleet[j->first][1] > 0) + m_BlockedFleet[j->first][1]--; + } + } + } + } + if (k <= 0) + gunsleft -= maxguns; + else + gunsleft -= maxguns - k; + } + } + } } ////////////////////////////////////////////////////////////////////////// // void Fleet::takeEMP(std::string unittype, int number) { + } ////////////////////////////////////////////////////////////////////////// diff --git a/bs/fleet.h b/bs/fleet.h index dfc5fdd..b706bbd 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -29,6 +29,7 @@ typedef std::map > FleetList; typedef std::map UnitList; typedef std::map > RaceList; typedef std::map > ResourceList; +typedef std::map ArmorList; //! An abstraction of a fleet and the engine for the battle simulation. /**This class and it's derivates is the engine for the whole battlesystem. * One of the few parts that I plan make fully portable. @@ -105,13 +106,13 @@ public: std::vector calculateSide(std::vector fleets, int stays = 0, int tick = 0); - void takeShoot(std::string unittype, int number, std::map& hitunits); - void takeEMP(std::string unittype, int number); void killFleet(std::string unittype, int number, int tick = 0); void setResource(std::string type, int number, int tick = 0); int resource(std::string type, int tick = 0)const; + void takeShoot(std::string unittype, int number, std::map& hitunits); + void takeEMP(std::string unittype, int number); protected: @@ -121,6 +122,8 @@ protected: FleetList m_Fleet; FleetList m_BlockedFleet; ResourceList m_Resources; + ArmorList m_Armor; + static UnitList s_Units;