X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=bs%2Ffleet.cpp;h=97be5aaf867286b7e24d8d178dac634eb9667396;hb=3ae63f013b2ac281d17acec43bc054a132861d35;hp=c2bf40ed4b634e5399f2f08e03bc7b1a8669ac64;hpb=f1e79e13d76a63700e6345503e338afaa93c102d;p=hbs.git diff --git a/bs/fleet.cpp b/bs/fleet.cpp index c2bf40e..97be5aa 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -17,16 +17,19 @@ #include "fleet.h" +#include using namespace std; //Static variables map > Fleet::s_Races; -map Fleet::s_Units; +UnitList Fleet::s_Units; Fleet::Fleet() { m_iETA = 0; + m_sRace = "Cathaar"; } + Fleet::~Fleet(){ } @@ -39,7 +42,7 @@ void Fleet::setName(string sName) ////////////////////////////////////////////////////////////////////////// // -string Fleet::Name() +string Fleet::name() const { return m_sName; } @@ -50,7 +53,7 @@ string Fleet::Name() * s_Races and checks if it finds the race it returns true, if it reaches * the end without finding it it returns false. */ -bool Fleet::setRace(std::string sRace) +bool Fleet::setRace(string sRace) { m_sRace = sRace; for (map >::iterator i = s_Races.begin(); i != s_Races.end(); i++) @@ -63,7 +66,7 @@ bool Fleet::setRace(std::string sRace) ////////////////////////////////////////////////////////////////////////// // -string Fleet::Race() +string Fleet::race() const { return m_sRace; } @@ -73,13 +76,14 @@ string Fleet::Race() /** This function iterates through m_Fleet and adds all numbers together to * produce a total. */ -int Fleet::NumberOfShips() +int Fleet::numberOfShips() const { int total = 0; - for (map >::iterator i = m_Fleet.begin(); i != m_Fleet.end(); i++) + for (map >::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i) { - total += m_Fleet[(*i).first][0]; + if (i->second.size() != 0) + total += i->second[0]; } return total; @@ -94,9 +98,127 @@ void Fleet::setETA(int eta) ////////////////////////////////////////////////////////////////////////// // -int Fleet::ETA() +int Fleet::ETA() const { return m_iETA; } +////////////////////////////////////////////////////////////////////////// +// +void Fleet::setRaces(map >& races) +{ + s_Races = races; +} + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::setUnits(UnitList& units) +{ + s_Units = units; + + /* + + for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); i++) + { + cerr << s_Units[(*i).first].Name() << "\t\t" + << s_Units[(*i).first].race() <<"\t" + << s_Units[(*i).first].unitClass() << "\t" + << s_Units[(*i).first].target(0) << "\t" + << s_Units[(*i).first].target(1) << "\t" + << s_Units[(*i).first].target(2) << "\t" + << s_Units[(*i).first].initiative() << "\t" + << s_Units[(*i).first].agility() << "\t" + << s_Units[(*i).first].weaponSpeed() << "\t" + << s_Units[(*i).first].guns() << "\t" + << s_Units[(*i).first].power() << "\t" + << s_Units[(*i).first].armor() << "\t" + << s_Units[(*i).first].EMP() << "\t" + << s_Units[(*i).first].totRes() << "\t" + << s_Units[(*i).first].fuel() << "\t" + << s_Units[(*i).first].ETA() << "\t" + << s_Units[(*i).first].type() << endl; + } + */ +} + +////////////////////////////////////////////////////////////////////////// +// +const map >& Fleet::Races() +{ + return s_Races; +} + +////////////////////////////////////////////////////////////////////////// +// +const UnitList& Fleet::Units() +{ + return s_Units; +} + +////////////////////////////////////////////////////////////////////////// +// +vector Fleet::RacesAllowed() const +{ + return s_Races[m_sRace]; +} + +////////////////////////////////////////////////////////////////////////// +// +unsigned Fleet::score(int tick = 0) const +{ + unsigned tot_score = 0; + + for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i) + { + if (i->second.size() >= tick) + break; + tot_score += i->second[tick] * s_Units[i->first].totRes() / 10; + } + + return tot_score; +} + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::setFleet(string unittype, int number) +{ + if (m_Fleet[unittype].size() == 0) + { + m_Fleet[unittype].push_back(number); + return; + } + m_Fleet[unittype][0] = number; +} + +////////////////////////////////////////////////////////////////////////// +// +int Fleet::fleet(string unittype, int tick = 0) +{ + if (m_Fleet[unittype].size() == 0) + return 0; + + return m_Fleet[unittype][tick]; +} + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::addToThis(std::vector fleets, int tick = 0) +{ + for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) + { + if (m_Fleet[i->first].size() == 0) + m_Fleet[i->first].push_back(0); + + for (vector::iterator j = fleets.begin(); j != fleets.end(); ++j) + { + // FIXTHIS!! m_Fleet[i->first][0] += j->fleet(i->first, tick); + } + } +} + +////////////////////////////////////////////////////////////////////////// +// +void distributeLossesGains(std::vector fleets, int tick = 0) +{ +}