X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=bs%2Ffleet.cpp;h=01ceb2b930e0cc70c3c6e24077822b18f892bd00;hb=935b6de2d1428854d76acc20b1727eb4a30f9273;hp=4072788a4af0d142607e8302e2dffb89b4010d83;hpb=20b89dab5346f13dc17b368b92de89eebf00ac11;p=hbs.git diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 4072788..01ceb2b 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -119,28 +119,28 @@ 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; + 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; } - */ + */ } ////////////////////////////////////////////////////////////////////////// @@ -316,12 +316,12 @@ void Fleet::distributeLossesGains(std::vector fleets, int tick) { int fl1 = (*j)->fleet(unittype, tick - 1); float part = float(fl1) / fleet(unittype, 0) ; - int lost = totallost * part; + int lost = int(totallost * part); (*j)->setFleet(unittype, (*j)->fleet(unittype, tick - 1) + lost, tick); cerr << (*j)->name() << " gaining " << lost << " " << unittype << " since it's " << part * 100 << "% of the whole fleet, and it had : " << fl1 << " units last tick.." << endl; - lost = part * blockedFleet(unittype, 0); + lost = int(part * blockedFleet(unittype, 0)); cerr << (*j)->name() << " got " << lost << " blocked " << unittype << ", the total number of blocked ships was: " << blockedFleet(unittype, 0) << endl; @@ -332,7 +332,7 @@ void Fleet::distributeLossesGains(std::vector fleets, int tick) ////////////////////////////////////////////////////////////////////////// // -std::vector Fleet::calculateSide(std::vector fleets, int stays, int tick) +std::vector Fleet::calculateSide(std::vector fleets, int tick) { vector fl; for (vector::iterator i = fleets.begin(); i != fleets.end(); ++i) @@ -380,13 +380,13 @@ void Fleet::takeShoot(std::string unittype, int number, std::map::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i) { string ta = s_Units[unittype].target(count); - cerr << "Shooting at target class: " << ta << endl; + //cerr << "Shooting at target class: " << ta << endl; while (gunsleft > 0) { @@ -450,6 +450,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst]++; //There is a chance that we're hitting a blocked ship. + /*Not anymore.. if (m_BlockedFleet[j->first].size() >= 1) { int test = rand() % m_BlockedFleet[j->first][0]; @@ -462,11 +463,12 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst][1]--; } } + */ } } - cerr << hitunits[j->first] << " units of type: " << j->first << "killed\n"; + //cerr << hitunits[j->first] << " units of type: " << j->first << "killed\n"; if (k <= 0) gunsleft -= maxguns; else @@ -478,19 +480,19 @@ void Fleet::takeShoot(std::string unittype, int number, std::map& hitunits) { int guns = s_Units[unittype].guns() * number; if (guns == 0) return; - cerr << unittype << ": with " << guns << " guns\n"; + //cerr << unittype << ": with " << guns << " guns\n"; float gunsleft = guns; for (int count = 0; count < 3; ++count)//vector::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i) { string ta = s_Units[unittype].target(count); - cerr << "Shooting at target class: " << ta << endl; + //cerr << "Shooting at target class: " << ta << endl; while (gunsleft > 0) { @@ -531,7 +533,7 @@ void Fleet::takeEMP(std::string unittype, int number) for (map::iterator j = targets.begin(); j != targets.end(); ++j) { float maxguns = float((*j->second))/total * guns; - cerr << "Now shooting at target: " << j->first << endl; + //cerr << "Now shooting at target: " << j->first << endl; double k = maxguns; @@ -547,10 +549,11 @@ void Fleet::takeEMP(std::string unittype, int number) k -= float(100)/(100-eres); hits++; + hitunits[j->first]++; blockFleet(j->first, 1); } - cerr << hits << " units of type: " << j->first << " blocked\n"; + //cerr << hits << " units of type: " << j->first << " blocked\n"; if (k <= 0) gunsleft -= maxguns; else @@ -705,7 +708,7 @@ void Fleet::distributeCappedRoids(std::vector fleets, int tick) { unsigned fl1 = (*j)->score(tick - 1); float part = float(fl1) / score(0) ; - int lost = totcapped * part; + int lost = int(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; @@ -744,10 +747,10 @@ void Fleet::calculateLostStealships(string unittype, std::map int stealscore = 0; for (map::iterator i = stolen.begin(); i != stolen.end(); ++i) { - stealscore += stolen[i->first] * (s_Units[i->first].totRes() / 10.0); + stealscore += int(stolen[i->first] * (s_Units[i->first].totRes() / 10.0)); } - int lost = stealscore / (s_Units[unittype].totRes() / 10.0); + int lost = int(stealscore / (s_Units[unittype].totRes() / 10.0)); cerr << "Lost " << lost << " " << unittype << " due to stealing ships worth: " << stealscore << endl; killFleet(unittype, lost, tick); @@ -767,7 +770,7 @@ void Fleet::distributeStolenShips(std::map::iterator k = fleets.begin(); k != fleets.end(); ++k) { - int stolen = float ((*k)->fleet(i->first, tick - 1)) / totalstealers * j->second; + int stolen = int(float ((*k)->fleet(i->first, tick - 1)) / totalstealers * j->second); (*k)->addFleet(j->first, stolen, tick); } } @@ -795,7 +798,7 @@ void Fleet::calculateSalvage() 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); + addResource(k->first, int(lostunits * k->second * 0.25), tick); } } } @@ -817,3 +820,53 @@ void Fleet::resetTicks() } resetResources(); } + +////////////////////////////////////////////////////////////////////////// +// +int Fleet::freePodGuns(int tick) +{ + int guns = 0; + for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i) + { + if (s_Units[i->first].type() == "Pod") + { + guns += freeFleet(i->first, tick) * s_Units[i->first].guns(); + } + } + guns -= usedPodGuns(tick); + return guns; +} + +////////////////////////////////////////////////////////////////////////// +// +int Fleet::usedPodGuns(int tick) const +{ + int ticks = m_UsedPodGuns.size(); + + if (ticks == 0) + return 0; + + if (tick < 0) + return m_UsedPodGuns[0]; + + --ticks; + + if (ticks < tick) + return m_UsedPodGuns[ticks]; + + return m_UsedPodGuns[tick]; + +} + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::usePodGuns(int tick, int guns) +{ + int ticks = m_UsedPodGuns.size(); + + for (int i = ticks; i <= tick; ++i) + { + m_UsedPodGuns.push_back(0); + } + m_UsedPodGuns[tick] += guns; +}