From 7311d423f454c500dbc60dd822007da3981b0d56 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Thu, 9 May 2002 17:22:01 +0000 Subject: [PATCH] added code so you lose ships if you steal.. --- bs/bsdoc.cpp | 1 + bs/bsview.cpp | 3 + bs/fleet.cpp | 36 ++++++++- bs/fleet.h | 22 ++++-- bs/planet.cpp | 6 ++ bs/ui/infoview.ui | 176 +++++++++++++++++++++++--------------------- bs/ui/infoview.ui.h | 13 +++- 7 files changed, 162 insertions(+), 95 deletions(-) diff --git a/bs/bsdoc.cpp b/bs/bsdoc.cpp index 11042b7..462dc75 100644 --- a/bs/bsdoc.cpp +++ b/bs/bsdoc.cpp @@ -69,6 +69,7 @@ int BSDoc::newBattle(QString name) m_Battles[name]["Friendly"]["Home Planet"]->setName("Home Planet"); m_Battles[name]["Friendly"]["Home Fleet"]->setName("Home Fleet"); m_Battles[name]["Friendly"]["Home Fleet"]->setRace("Terran"); + m_Battles[name]["Friendly"]["Home Fleet"]->setStays(-1); m_Battles[name]["Hostile"]["Evil guy"]->setName("Evil guy"); m_Battles[name]["Hostile"]["Evil guy"]->setETA(1); diff --git a/bs/bsview.cpp b/bs/bsview.cpp index 7adc6db..df3f558 100644 --- a/bs/bsview.cpp +++ b/bs/bsview.cpp @@ -278,6 +278,7 @@ void BSView::slotInfoApply() fl->setETA(m_InfoView->eta()); fl->setName(m_sFleet.latin1()); fl->setRace(m_InfoView->race().latin1()); + fl->setStays(m_InfoView->stays()); m_doc->newFleet(m_sBattle, m_sGroup, m_sFleet, fl); } @@ -317,6 +318,7 @@ void BSView::slotInfoNew() fl->setETA(m_InfoView->eta()); fl->setName(m_sFleet.latin1()); fl->setRace(m_InfoView->race().latin1()); + fl->setStays(m_InfoView->stays()); m_doc->newFleet(m_sBattle, m_sGroup, m_sFleet, fl); @@ -365,6 +367,7 @@ void BSView::updateInfoView() m_InfoView->setEta(fl->ETA()); m_InfoView->setGroup(m_sGroup); m_InfoView->setBattle(m_sBattle); + m_InfoView->setStays(fl->stays()); } ////////////////////////////////////////////////////////////////////////// diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 136ad22..3df0972 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -28,6 +28,7 @@ UnitList Fleet::s_Units; Fleet::Fleet() { m_iETA = 0; + m_iStays = 3; m_sRace = "Cathaar"; } @@ -332,12 +333,12 @@ std::vector Fleet::calculateSide(std::vector fleets, int stays = vector fl; for (vector::iterator i = fleets.begin(); i != fleets.end(); ++i) { - if (( tick - (*i)->ETA()) >= 0 && (tick - (*i)->ETA()) < stays) + if (( tick - (*i)->ETA()) >= 0 && (tick - (*i)->ETA()) < (*i)->stays()) { fl.push_back((*i)); cerr << "Using fleet " << (*i)->name() << " for tick " << tick << endl; } - else if ((*i)->name() == "Home Planet") + else if ((*i)->stays() < 0) fl.push_back((*i)); } return fl; @@ -712,9 +713,38 @@ void Fleet::distributeCappedRoids(std::vector fleets, int tick = 0) ////////////////////////////////////////////////////////////////////////// // - void Fleet::addFleet(std::map units, int tick = 0) { for (map::iterator i = units.begin(); i != units.end(); ++i) addFleet(i->first, i->second, tick); } + +////////////////////////////////////////////////////////////////////////// +// +int Fleet::stays() const +{ + return m_iStays; +} + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::setStays(int ticks) +{ + m_iStays = ticks; +} + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::calculateLostStealships(string unittype, std::map stolen, int tick = 1) +{ + int stealscore = 0; + for (map::iterator i = stolen.begin(); i != stolen.end(); ++i) + { + stealscore += stolen[i->first] * (s_Units[i->first].totRes() / 10.0); + } + + int lost = stealscore / (s_Units[unittype].totRes() / 10.0); + + cerr << "Lost " << lost << " " << unittype << " due to stealing ships worth: " << stealscore << endl; + killFleet(unittype, lost, tick); +} diff --git a/bs/fleet.h b/bs/fleet.h index 93bdee7..3c690fd 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -227,6 +227,13 @@ public: int resource(std::string type, int tick = 0)const; void resetResources(); + + /** This function tells how many ticks the fleet stays at it's target. + * \returns the number of ticks as an int. + */ + int stays() const; + void setStays(int ticks); + /** This is a little more advanced function. It makes a a number of units * of a specific unittype shoot at the current fleet and calculates the * losses. @@ -257,6 +264,8 @@ public: */ void takeEMP(std::string unittype, int number); + void calculateLostStealships(std::string unittype, std::map stolen, int tick = 1); + /** This function prints out all the ships in the fleet to stderr, * mainly used for debugging. */ @@ -288,13 +297,14 @@ public: protected: - std::string m_sName; - std::string m_sRace; - int m_iETA; - FleetList m_Fleet; - FleetList m_BlockedFleet; + std::string m_sName; + std::string m_sRace; + int m_iETA; + FleetList m_Fleet; + FleetList m_BlockedFleet; ResourceList m_Resources; - ArmorList m_Armor; + ArmorList m_Armor; + int m_iStays; diff --git a/bs/planet.cpp b/bs/planet.cpp index f57d208..d62bf57 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -23,6 +23,7 @@ using namespace std; Planet::Planet() { m_sRace = "Planet"; + m_iStays = -1; } Planet::~Planet(){ @@ -225,6 +226,7 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map pods; + //FIXME: Need to change this and allow multiple shiptypes with the same initiative. 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; @@ -247,6 +249,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 { @@ -257,6 +262,7 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map 0) diff --git a/bs/ui/infoview.ui b/bs/ui/infoview.ui index 33135f7..bb57b75 100644 --- a/bs/ui/infoview.ui +++ b/bs/ui/infoview.ui @@ -9,9 +9,9 @@ 0 - 0 + 4 267 - 198 + 221 @@ -25,7 +25,7 @@ 32767 - 200 + 221 @@ -36,10 +36,10 @@ unnamed - 3 + 0 - 2 + 0 @@ -89,72 +89,7 @@ NoInsertion - - - RaceLabel - - - &Race - - - RaceCombo - - - - - NameLine - - - - - NameLabel - - - Na&me - - - NameLine - - - - - RaceCombo - - - - - EtaLabel - - - E&ta - - - EtaSpin - - - - - EtaSpin - - - - - Spacer3 - - - Vertical - - - Expanding - - - - 20 - 20 - - - - + Layout13 @@ -185,7 +120,7 @@ - + Spacer1 @@ -194,12 +129,6 @@ Expanding - - - 20 - 20 - - @@ -225,8 +154,8 @@ - - + + Spacer4 @@ -235,13 +164,88 @@ Expanding - - - 20 - 20 - + + + + RaceLabel + + + &Race + + + RaceCombo + + + + + RaceCombo + + + + + Spacer3 + + + Vertical + + + Expanding + + + NameLabel + + + Na&me + + + NameLine + + + + + EtaLabel + + + E&ta + + + EtaSpin + + + + + NameLine + + + + + EtaSpin + + + + + StayLabel + + + Stays + + + StaySpin + + + Sets the number of ticks the fleet stays at the target, usually 3 for hostile and 6 for friendly. The fleet is disabled if stays is 0, and it stays the whole battle if it's -1 + + + + + StaySpin + + + -1 + + @@ -323,6 +327,8 @@ group() race() slotNameChanged( const QString & s ) + stays() + setStays( int ticks ) diff --git a/bs/ui/infoview.ui.h b/bs/ui/infoview.ui.h index a50bb95..1a7d70d 100644 --- a/bs/ui/infoview.ui.h +++ b/bs/ui/infoview.ui.h @@ -148,4 +148,15 @@ void InfoView::slotNameChanged( const QString & s ) ApplyButton->setEnabled(true); NewButton->setEnabled(false); } -} \ No newline at end of file +} + + +int InfoView::stays() +{ + return StaySpin->value(); +} + +void InfoView::setStays( int ticks ) +{ + StaySpin->setValue(ticks); +} -- 2.39.2