X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=bs%2Ffleet.cpp;h=2daa5cf052920866b68d158819a42e7a23c554d9;hb=d1b57a078d3edb148f8b6ec61944a0b852a4bf94;hp=432f16595efadab7d1e8c479fa8cb03678ac7292;hpb=e5701c8f3f1199264015c5d6e0f2a32515d5f6f8;p=hbs.git diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 432f165..2daa5cf 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -117,8 +117,8 @@ 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" @@ -139,6 +139,7 @@ void Fleet::setUnits(UnitList& units) << s_Units[(*i).first].ETA() << "\t" << s_Units[(*i).first].type() << endl; } + */ } @@ -183,10 +184,15 @@ unsigned Fleet::score(int tick = 0) const // void Fleet::setFleet(string unittype, int number, int tick = 0) { - if (m_Fleet[unittype].size() <= tick) + 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(number); - return; + m_Fleet[unittype].push_back(earlier); } m_Fleet[unittype][tick] = number; } @@ -202,7 +208,7 @@ int Fleet::fleet(string unittype, int tick = 0) --ticks; if (ticks < tick) - m_Fleet[unittype][ticks]; + return m_Fleet[unittype][ticks]; return m_Fleet[unittype][tick]; } @@ -218,7 +224,7 @@ void Fleet::addToThis(std::vector fleets, int tick = 0) for (vector::iterator j = fleets.begin(); j != fleets.end(); ++j) { - // FIXTHIS!! m_Fleet[i->first][0] += j->fleet(i->first, tick); + m_Fleet[i->first][0] += (*j)->fleet(i->first, tick); } } } @@ -227,6 +233,27 @@ void Fleet::addToThis(std::vector fleets, int tick = 0) // void Fleet::distributeLossesGains(std::vector fleets, int tick = 0) { + for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) + { + string unittype = i->first; + + cerr << "Distributing type: " << unittype << endl; + + if (m_Fleet[unittype].size() < 1) + continue; + if (m_Fleet[unittype][0] == 0) + continue; + + int totallost = m_Fleet[unittype][1] - m_Fleet[unittype][0]; + + + for (vector::iterator j = fleets.begin(); j != fleets.end(); ++j) + { + int lost = totallost * ( (*j)->fleet(unittype, tick - 1) / m_Fleet[unittype][0] ); + cerr << (*j)->name() << " gaining " << lost << " " << unittype << endl; + (*j)->setFleet(unittype, (*j)->fleet(unittype, tick - 1) + lost, tick); + } + } } ////////////////////////////////////////////////////////////////////////// @@ -237,7 +264,10 @@ std::vector Fleet::calculateSide(std::vector fleets, int stays = for (vector::iterator i = fleets.begin(); i != fleets.end(); ++i) { if (( tick - (*i)->ETA()) >= 0 && (tick - (*i)->ETA()) < stays) + { fl.push_back((*i)); + cerr << "Using fleet " << (*i)->name() << " for tick " << tick; + } else if ((*i)->name() == "Home Planet") fl.push_back((*i)); } @@ -248,12 +278,18 @@ std::vector Fleet::calculateSide(std::vector fleets, int stays = // int Fleet::freeFleet(std:: string unittype, int tick = 0) { - if (m_Fleet[unittype].size() == 0) - return 0; - if (m_BlockedFleet[unittype].size() < tick) - return m_Fleet[unittype][tick]; + int bticks = m_BlockedFleet[unittype].size(); + + --bticks; + + if (bticks < tick) + return fleet(unittype, tick); - return m_Fleet[unittype][tick] - m_BlockedFleet[unittype][tick]; + + int free = fleet(unittype,tick) - m_BlockedFleet[unittype][tick]; + if (free < 0) + return 0; + return free; } @@ -261,13 +297,19 @@ int Fleet::freeFleet(std:: string unittype, int tick = 0) // void Fleet::takeShoot(std::string unittype, int number, std::map& hitunits) { + + cerr << unittype << ": " << number << " in number\n"; int guns = s_Units[unittype].guns() * number; - int power = s_Units[unittype].power() * number; + if (guns == 0) + return; + + cerr << unittype << " with " << guns << " guns\n"; int gunsleft = guns; - for (vector::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i) + 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; while (gunsleft > 0) { @@ -275,16 +317,27 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst].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()) + //cerr << "Target is class: " << j->second.type() << endl; + + if (m_Fleet[j->first][1] > 0 && ( ta == j->second.unitClass() || ta == "All")) + { + + cerr << "Looking at target: " << j->first << endl; targets[j->first] = &m_Fleet[j->first][1]; + } + } + if (targets.size() == 0) + break; + int total = 0; for (map::iterator j = targets.begin(); j != targets.end(); ++j) total += (*j->second); @@ -292,11 +345,15 @@ void Fleet::takeShoot(std::string unittype, int number, std::map::iterator j = targets.begin(); j != targets.end(); ++j) { int maxguns = (*j->second)/total * guns; - + cerr << "Now shooting at target: " << j->first << endl; 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; + float k = maxguns; + + int blaha = 0; + cerr << "Targets agility: " << s_Units[j->first].agility() << endl; + cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl; while (k > 0) { @@ -308,6 +365,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst] = s_Units[j->first].armor(); (*j->second)--; + hitunits[j->first]++; //There is a chance that we're hitting a blocked ship. if (m_BlockedFleet[j->first].size() >= 1) @@ -323,7 +381,10 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst] << " units of type: " << j->first << "killed\n"; if (k <= 0) gunsleft -= maxguns; else @@ -390,3 +451,19 @@ int Fleet::resource(std::string type, int tick = 0) const return resource->at(tick); } +////////////////////////////////////////////////////////////////////////// +// +void Fleet::printFleet() +{ + for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) + { + for (int tick = 0; tick < 5 ;++tick) + { + int num = fleet(i->first, tick); + + if (num <= 0) + break; + cerr << num << " " << i->first << " during tick: " << tick << endl; + } + } +}