From: Michael Andreen Date: Fri, 12 Apr 2002 10:19:35 +0000 (+0000) Subject: A few more bugs killed.. still a few left before 0.1 release.. X-Git-Tag: HBS_0_1_0~10 X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=commitdiff_plain;h=8589e08e508806885b737682ed25b6f711d0fdee A few more bugs killed.. still a few left before 0.1 release.. --- diff --git a/bs/bsview.cpp b/bs/bsview.cpp index 44ddfa4..ccf3341 100644 --- a/bs/bsview.cpp +++ b/bs/bsview.cpp @@ -405,6 +405,7 @@ void BSView::updateFleetView() connect(m_TickView, SIGNAL(ticksChanged(int,int)), m_FleetView, SLOT(slotViewTickRange(int,int))); m_FleetViews->addWidget(m_FleetView, 1); } + m_FleetViews->raiseWidget(2); m_FleetViews->raiseWidget(1); } } diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 95ae6d3..ed5efb9 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; } } } @@ -248,11 +251,15 @@ void Fleet::distributeLossesGains(std::vector fleets, int tick = 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); } } @@ -300,13 +307,16 @@ int Fleet::freeFleet(std:: string unittype, int tick = 0) void Fleet::takeShoot(std::string unittype, int number, std::map& hitunits) { - int guns = s_Units[unittype].guns() * number; + float guns = s_Units[unittype].guns() * number; + + cerr << number << " " << unittype << ": with " << guns << " guns\n"; + if (guns == 0) return; cerr << 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); @@ -345,15 +355,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; + 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(); double k = maxguns; - 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) { @@ -411,7 +421,7 @@ void Fleet::takeEMP(std::string unittype, int number) cerr << 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); @@ -486,10 +496,15 @@ void Fleet::takeEMP(std::string unittype, int number) // 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; } diff --git a/bs/fleetview.cpp b/bs/fleetview.cpp index 5cbed53..a261b93 100644 --- a/bs/fleetview.cpp +++ b/bs/fleetview.cpp @@ -91,7 +91,7 @@ void FleetView::viewFleet(const Fleet* fleet, bool friendly) { m_Fleet = new Fleet(*fleet); } - m_Fleet->printFleet(); + //m_Fleet->printFleet(); fillTable(); } @@ -235,4 +235,32 @@ void FleetView::slotViewTickRange(int min = -1, int max = -1) int after = m_Fleet->fleet(i->latin1(), m_iMaxTick); m_UnitsLostSurvivedView[(*i)]->setText(QString("%1").arg(after - before)); } + + Planet* pl; + if ((pl = dynamic_cast(m_Fleet))) + { + int lost; + int before; + int after; + + before = pl->roids(tr("metal").latin1(),m_iMinTick); + after = pl->roids(tr("metal").latin1(),m_iMaxTick); + lost = after - before; + m_RoidsEditView->slotSetLost(tr("metal"),lost); + + before = pl->roids(tr("crystal").latin1(),m_iMinTick); + after = pl->roids(tr("crystal").latin1(),m_iMaxTick); + lost = after - before; + m_RoidsEditView->slotSetLost(tr("crystal"),lost); + + before = pl->roids(tr("eonium").latin1(),m_iMinTick); + after = pl->roids(tr("eonium").latin1(),m_iMaxTick); + lost = after - before; + m_RoidsEditView->slotSetLost(tr("eonium"),lost); + + before = pl->roids(tr("uninit").latin1(),m_iMinTick); + after = pl->roids(tr("uninit").latin1(),m_iMaxTick); + lost = after - before; + m_RoidsEditView->slotSetLost(tr("uninit"),lost); + } } diff --git a/bs/planet.cpp b/bs/planet.cpp index 8fd1726..443b3b1 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -65,6 +65,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 +73,34 @@ 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 = 0) { - 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; } +////////////////////////////////////////////////////////////////////////// +// +void Planet::takeRoids(std::string type, int number, int tick = 0) +{ + 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::runBattle(std::vector friendly, std::vector hostile) @@ -103,26 +125,40 @@ void Planet::runBattle(std::vector friendly, std::vector hostile skipped = 0; Planet allFriends; - allFriends.addToThis(friends, tick); + 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, tick); + allHostiles.addToThis(hostiles, tick - 1); map > stealfriendly; map > stealhostile; - calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile ); + calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile, tick ); //allFriends.printFleet(); allFriends.distributeLossesGains(friends, tick); allHostiles.distributeLossesGains(hostiles, tick); + + /* for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i) + setRoids(i->first, roids(i->first, 1), tick);*/ + } + + 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 = 0) { map unitsinit; // order units after their ininitiative for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) @@ -156,19 +192,38 @@ 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) + if (m_iScore <= 0) break; + float capping = float(m_iScore) / hostile->score() / 10; + + cerr << "Capping is: " << capping << endl; + + if (capping > 0.15) + capping = 0.15; + if (capping <= 0) + break; + + for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid) { - int caproids = capping * roids->second[0]; + int caproids = capping * roids(roid->first, tick - 1); int freepods = hostiletemp->freeFleet(unittype, 1); + + cerr << "Possible to steal " << caproids << " " << roid->first << " roids\n"; + cerr << freepods << " free pods available\n"; - if (freepods == 0) + if (freepods <= 0) break; if (freepods < caproids) - caproids = caproids - freepods; + caproids = freepods; + + cerr << caproids << " roids stolen\n"; - roids->second.push_back(roids->second[0] - caproids); + takeRoids(roid->first, caproids, tick); + hostiletemp->killFleet(unittype, caproids, 1); + int totroids = caproids + hostiletemp->resource(roid->first, 0); + hostiletemp->setResource(roid->first, totroids, 1); + + cerr << totroids << " stolen " << roid->first << " roids\n"; } } diff --git a/bs/planet.h b/bs/planet.h index 2d51361..e5c173e 100644 --- a/bs/planet.h +++ b/bs/planet.h @@ -43,12 +43,13 @@ public: void setPlanetScore(unsigned i); int roids(std::string type, int tick = 0) const; - void setRoids(std::string type, int number); + void setRoids(std::string type, int number, int tick = 0); + void takeRoids(std::string type, int number, int tick = 0); void runBattle(std::vector friendly, std::vector hostile); protected: - void calcOneTick(Planet* friendly, Fleet* Hostile, std::map >& stealfriendly, std::map >& stealhostile ); + void calcOneTick(Planet* friendly, Fleet* Hostile, std::map >& stealfriendly, std::map >& stealhostile, int tick = 0); unsigned m_iScore; RoidList m_Roids; diff --git a/bs/ui/resourceview.ui b/bs/ui/resourceview.ui index 47043bf..9495a81 100644 --- a/bs/ui/resourceview.ui +++ b/bs/ui/resourceview.ui @@ -9,19 +9,25 @@ 0 - 0 - 198 - 89 + 11 + 222 + 105 5 - 5 + 4 0 0 + + + 0 + 105 + + QGroupBoxForm @@ -33,10 +39,10 @@ unnamed - 5 + 11 - 2 + 6 diff --git a/bs/ui/roidseditview.ui b/bs/ui/roidseditview.ui index bd0d949..caa5490 100644 --- a/bs/ui/roidseditview.ui +++ b/bs/ui/roidseditview.ui @@ -39,6 +39,9 @@ eoniumLabel + + MShape + Eonium @@ -215,7 +218,8 @@ init() setValue( const QString & type, unsigned value ) - slotValueChanged( const QString & s ) + slotValueChanged( const QString & s ) + slotSetLost( QString type, int i ) diff --git a/bs/ui/roidseditview.ui.h b/bs/ui/roidseditview.ui.h index e22a408..22a8230 100644 --- a/bs/ui/roidseditview.ui.h +++ b/bs/ui/roidseditview.ui.h @@ -43,4 +43,20 @@ void RoidsEditView::slotValueChanged( const QString & s ) type = tr("score"); test = type; emit changed(type, s.toInt()); +} + + +void RoidsEditView::slotSetLost( QString type, int i ) +{ + if (type == tr("metal")) + MetalLostEdit->setText(QString("%1").arg(i)); + else if (type == tr("crystal")) + CrystalLostEdit->setText(QString("%1").arg(i)); + else if (type == tr("eonium")) + EoniumLostEdit->setText(QString("%1").arg(i)); + else if (type == tr("uninit")) + UninitLostEdit->setText(QString("%1").arg(i)); + /*else if (type == tr("score")) + ScoreEdit->setText(QString("%1").arg(i)); + */ } \ No newline at end of file