X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=bs%2Ffleet.cpp;h=b4e4335a4c71486f7db35b461765b8ba31566f16;hb=515395613c36c35c3797bc085f6d54a8ac7725d9;hp=2daa5cf052920866b68d158819a42e7a23c554d9;hpb=d1b57a078d3edb148f8b6ec61944a0b852a4bf94;p=hbs.git diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 2daa5cf..b4e4335 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -224,7 +224,10 @@ void Fleet::addToThis(std::vector fleets, int tick = 0) for (vector::iterator j = fleets.begin(); j != fleets.end(); ++j) { - m_Fleet[i->first][0] += (*j)->fleet(i->first, tick); + int num = (*j)->fleet(i->first, tick); + m_Fleet[i->first][0] += num; + if (num > 0) + cerr << (*j)->name() << " adding " << num << " units of type " << i->first << endl; } } } @@ -237,20 +240,26 @@ void Fleet::distributeLossesGains(std::vector fleets, int tick = 0) { 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]; + + int totallost = fleet(unittype,1) - fleet(unittype, 0); + + cerr << "Distributing type: " << unittype << " with a total loss of " << totallost << " units" << endl; + + cerr << "Total number of units before: " << fleet(unittype, 0) << " and after : " << fleet(unittype, 1) << endl; 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; + int fl1 = (*j)->fleet(unittype, tick - 1); + float part = float(fl1) / fleet(unittype, 0) ; + int lost = totallost * part; + cerr << (*j)->name() << " gaining " << lost << " " << unittype << " since it's " << part * 100 << "% of the whole fleet, and it had : " << fl1 << " units last tick.." << endl; (*j)->setFleet(unittype, (*j)->fleet(unittype, tick - 1) + lost, tick); } } @@ -266,7 +275,7 @@ std::vector Fleet::calculateSide(std::vector fleets, int stays = if (( tick - (*i)->ETA()) >= 0 && (tick - (*i)->ETA()) < stays) { fl.push_back((*i)); - cerr << "Using fleet " << (*i)->name() << " for tick " << tick; + cerr << "Using fleet " << (*i)->name() << " for tick " << tick << endl; } else if ((*i)->name() == "Home Planet") fl.push_back((*i)); @@ -298,18 +307,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; + float guns = s_Units[unittype].guns() * number; + + if (guns == 0) return; - cerr << unittype << " with " << guns << " guns\n"; + cerr << number << " " << unittype << ": with " << guns << " guns\n"; - int gunsleft = guns; + 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) { @@ -319,7 +329,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst].size() == 0) - break; + continue; if (m_Fleet[j->first].size() == 1) m_Fleet[j->first].push_back(m_Fleet[j->first][0]); @@ -329,7 +339,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst][1] > 0 && ( ta == j->second.unitClass() || ta == "All")) { - cerr << "Looking at target: " << j->first << endl; + // cerr << "Looking at target: " << j->first << endl; targets[j->first] = &m_Fleet[j->first][1]; } @@ -344,22 +354,28 @@ 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; + float maxguns = float((*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(); - float k = maxguns; + double k = maxguns; - int blaha = 0; - cerr << "Targets agility: " << s_Units[j->first].agility() << endl; - cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl; + //cerr << "Targets agility: " << s_Units[j->first].agility() << endl; + //cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl; while (k > 0) { if (*(j->second) <= 0) break; - k -= 100/(25+s_Units[unittype].weaponSpeed() - s_Units[j->first].agility()); + + int wpsp = s_Units[unittype].weaponSpeed(); + int agil = s_Units[j->first].agility(); + + k -= float(100)/(25 + wpsp - agil); + //cout << "Used " << blaha << " guns to hit with one shot.\n"; + //cout << "WPSP: " << wpsp << "\nAgil: " << agil << endl; + m_Armor[j->first] -= s_Units[unittype].power(); if (m_Armor[j->first] <= 0) { @@ -398,17 +414,96 @@ 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; + while (gunsleft > 0) + { + + map targets; + + for (UnitList::iterator j = s_Units.begin(); j != s_Units.end(); ++j) + { + if (j->second.type() == "PDS") + continue; + + if (m_Fleet[j->first].size() == 0) + continue; + + if (m_Fleet[j->first].size() == 1) + m_Fleet[j->first].push_back(m_Fleet[j->first][0]); + + //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); + + for (map::iterator j = targets.begin(); j != targets.end(); ++j) + { + int maxguns = (*j->second)/total * guns; + cerr << "Now shooting at target: " << j->first << endl; + + double k = maxguns; + + int hits = 0; + + while (k > 0) + { + + if (*(j->second) <= 0) + break; + + int eres = s_Units[j->first].EMP(); + k -= float(100)/(100-eres); + hits++; + blockFleet(j->first, 1); + } + + cerr << hits << " units of type: " << j->first << " blocked\n"; + if (k <= 0) + gunsleft -= maxguns; + else + gunsleft -= maxguns - k; + } + } + } } ////////////////////////////////////////////////////////////////////////// // void Fleet::killFleet(std::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(m_Fleet[unittype][m_Fleet[unittype].size()] - number); - return; + m_Fleet[unittype].push_back(earlier); } m_Fleet[unittype][tick] -= number; } @@ -467,3 +562,22 @@ void Fleet::printFleet() } } } + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::blockFleet(std::string unittype, int number, int tick = 0) +{ + if (m_BlockedFleet[unittype].size() >= 1) + { + m_BlockedFleet[unittype][0] += number; + if (m_BlockedFleet[unittype].size() > 1) + m_BlockedFleet[unittype][1] += number; + else + m_BlockedFleet[unittype].push_back(m_BlockedFleet[unittype][0]); + } + else + { + m_BlockedFleet[unittype].push_back(number); + m_BlockedFleet[unittype].push_back(number); + } +}