X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=bs%2Fplanet.cpp;h=c819323d76bde827bde8414b7b8c3b620ef2355c;hb=e0be1e6e8f7a246acf49e1f315c8d5bc5a65bfa3;hp=41d92ac51eb2ed6004bab3b01c8009a46b8fdefb;hpb=2fd4fff0f5eef1d64527b202924f16f2242691dc;p=hbs.git diff --git a/bs/planet.cpp b/bs/planet.cpp index 41d92ac..c819323 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -23,7 +23,7 @@ using namespace std; Planet::Planet() { m_sRace = "Planet"; - m_iScore = 0; + m_iStays = -1; } Planet::~Planet(){ @@ -31,21 +31,56 @@ Planet::~Planet(){ ////////////////////////////////////////////////////////////////////////// // -unsigned Planet::planetScore() const +unsigned Planet::planetScore(int tick) const { - return m_iScore; + int ticks = m_Score.size(); + if (ticks == 0) + return 0; + + --ticks; + + if (ticks < tick) + return m_Score[ticks]; + + return m_Score[tick]; } ////////////////////////////////////////////////////////////////////////// // -void Planet::setPlanetScore(unsigned i) +void Planet::setPlanetScore(unsigned number, int tick) { - m_iScore = i; + int earlier = 0; + int ticks = m_Score.size(); + + if (ticks != 0) + earlier = m_Score[ticks - 1]; + + for (int i = ticks; i <= tick; ++i) + { + m_Score.push_back(earlier); + } + m_Score[tick] = number; } ////////////////////////////////////////////////////////////////////////// // -int Planet::roids(std::string type, int tick = 0) const +void Planet::addPlanetScore(unsigned number, int tick) +{ + int earlier = 0; + int ticks = m_Score.size(); + + if (ticks != 0) + earlier = m_Score[ticks - 1]; + + for (int i = ticks; i <= tick; ++i) + { + m_Score.push_back(earlier); + } + m_Score[tick] += number; +} +////////////////////////////////////////////////////////////////////////// +// +int Planet::roids(std::string type, int tick) const { // const... I would like [] as for const types: int ticks = m_Roids[type].size(); @@ -65,6 +100,7 @@ int Planet::roids(std::string type, int tick = 0) const if( ticks == 0) return 0; + --ticks; if (ticks < tick) return roids->at(ticks); return roids->at(tick); @@ -72,13 +108,37 @@ int Planet::roids(std::string type, int tick = 0) const ////////////////////////////////////////////////////////////////////////// // -void Planet::setRoids(std::string type, int number) +void Planet::setRoids(std::string type, int number, int tick) +{ + int ticks = m_Roids[type].size(); + int roids = 0; + if (m_Roids[type].size() > 0) + roids = m_Roids[type][m_Roids[type].size() - 1]; + + for (int i = ticks; i <= tick; ++i ) + m_Roids[type].push_back(roids); + m_Roids[type][tick] = number; +} + +////////////////////////////////////////////////////////////////////////// +// +void Planet::takeRoids(std::string type, int number, int tick) { - if (m_Roids[type].size() == 0) - m_Roids[type].push_back(number); - m_Roids[type][0] = number; + int ticks = m_Roids[type].size(); + int roids = 0; + if (m_Roids[type].size() > 0) + roids = m_Roids[type][m_Roids[type].size() - 1]; + + for (int i = ticks; i <= tick; ++i ) + m_Roids[type].push_back(roids); + m_Roids[type][tick] -= number; + + if (type != "uninit") + addPlanetScore(-1000*number, tick); } + + ////////////////////////////////////////////////////////////////////////// // void Planet::runBattle(std::vector friendly, std::vector hostile) @@ -87,6 +147,13 @@ void Planet::runBattle(std::vector friendly, std::vector hostile return; int skipped = 0; + + for (vector::iterator i = friendly.begin(); i != friendly.end(); ++i) + (*i)->resetTicks(); + + for (vector::iterator i = hostile.begin(); i != hostile.end(); ++i) + (*i)->resetTicks(); + for(int tick = 1; skipped < 20; ++tick) { //See who's in the battle at the current tick @@ -103,25 +170,69 @@ void Planet::runBattle(std::vector friendly, std::vector hostile skipped = 0; Planet allFriends; - allFriends.addToThis(friends); + allFriends.addToThis(friends, tick - 1); + + /*for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i) + allFriends.setRoids(i->first, roids(i->first, tick)); + + allFriends.setPlanetScore(m_iScore);*/ Fleet allHostiles; - allHostiles.addToThis(hostiles); + allHostiles.addToThis(hostiles, tick - 1); map > stealfriendly; map > stealhostile; + + //Reset roids + for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid) + { + setRoids(roid->first, roids(roid->first, tick-1), tick); + } + + setPlanetScore(planetScore(tick - 1), tick); + - calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile ); + calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile, tick ); + + //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); + + /* for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i) + 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) + cout << i->first << " roids : " << (*j) << endl; } } ////////////////////////////////////////////////////////////////////////// // -void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map >& stealfriendly, std::map >& stealhostile ) +void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map >& stealfriendly, std::map >& stealhostile, int tick) { + if (planetScore(tick - 1) > 0) + setCapping(float(planetScore(tick - 1)) / hostile->score() / 10, tick); + else + setCapping(0, tick); + + //FIXME: remove this line later.. map pods; + + + //FIXME: Need to change this and allow multiple shiptypes with the same initiative. + //FIXME: Looks like I don't have to.. map unitsinit; // order units after their ininitiative for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) unitsinit[i->second.initiative()] = i->first; @@ -133,7 +244,7 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::mapsecond; - cerr << "Initiative: " << s_Units[unittype].initiative() << " with unit: " << unittype << endl; + //cerr << "Initiative: " << s_Units[unittype].initiative() << " with unit: " << unittype << endl; if (s_Units[unittype].type() == "EMP") { @@ -144,6 +255,9 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::maptakeShoot(unittype, friendly->freeFleet(unittype, 1), stealfriendly[unittype]); friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), stealhostile[unittype]); + + friendlytemp->calculateLostStealships(unittype, stealfriendly[unittype], 1); + hostiletemp->calculateLostStealships(unittype, stealhostile[unittype], 1); } else { @@ -154,20 +268,47 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::mapm_iScore / hostile->score() / 10; - for (RoidList::iterator roids = m_Roids.begin(); roids != m_Roids.end(); ++roids) + //FIXME: Prolly need to recode the whole capping section for r7, due to multiple pods thingy + cerr << "Capping is: " << capping(tick) << endl; + + if (capping(tick) > 0) { - int caproids = capping * roids->second[0]; - int freepods = hostiletemp->freeFleet(unittype, 1); + for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid) + { + int caproids = capping(tick) * roids(roid->first, tick - 1); + //int freepods = hostiletemp->freeFleet(unittype, 1); + + cerr << "Possible to steal " << caproids << " " << roid->first << " roids\n"; + cerr << hostiletemp->freePodGuns(1) << " free pod guns available\n"; - if (freepods == 0) - break; - if (freepods < caproids) - caproids = caproids - freepods; - - roids->second.push_back(roids->second[0] - caproids); - hostiletemp->killFleet(unittype, caproids, 1); + if (hostiletemp->freePodGuns(1) <= 0) + break; + if (hostiletemp->freePodGuns(1) < caproids) + caproids = hostiletemp->freePodGuns(1); + + cerr << caproids << " roids stolen\n"; + + takeRoids(roid->first, caproids, tick); + + /*FIXME: REMOVE THIS BLOCK LATER + //FIXME: Going to move this to the distribute roids section instead.. Not really move, I'll keep this, but "regenerate" the pods in the distribute ships function. + hostiletemp->killFleet(unittype, caproids, 1); + pods[unittype] += caproids; + //int totroids = caproids + hostiletemp->resource(roid->first, 0); + */ + hostiletemp->addResource(roid->first, caproids, 1); + hostiletemp->usePodGuns(1, caproids); + cerr << caproids << " stolen " << roid->first << " roids\n"; + } } + + //FIXME: This is ugly and I want to change this, but as long as pods shoot last it works.. + *friendly = *friendlytemp; + delete friendlytemp; + *hostile = *hostiletemp; + delete hostiletemp; + + return; } //set the the objects so they point at the modified objects @@ -176,5 +317,53 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::mapaddFleet(pods, 1); + +} + +////////////////////////////////////////////////////////////////////////// +// +void Planet::calculateScoreLoss(std::vector friendly, int tick) +{ + for (vector::iterator i = friendly.begin(); i != friendly.end(); ++i) + { + if ((*i)->name().find("Home") != string::npos) + { + int scorechange = (*i)->score(tick) - (*i)->score(tick - 1); + addPlanetScore(scorechange, tick); + } + } } +////////////////////////////////////////////////////////////////////////// +// +float Planet::capping(int tick) +{ + int ticks = m_Capping.size(); + + --ticks; + + if (ticks < tick) + return 0; + + return m_Capping[tick]; +} + +////////////////////////////////////////////////////////////////////////// +// +void Planet::setCapping(float capping, int tick) +{ + int ticks = m_Capping.size(); + + for (int i = ticks; i <= tick; ++i) + { + m_Capping.push_back(0); + } + + if (capping <= 0.15 && capping >= 0) + m_Capping[tick] = capping; + else if (capping >= 0.15) + m_Capping[tick] = 0.15; + else + m_Capping[tick] = 0; +}