[kde-doc-english] [konquest] /: Add production and fleet size to standings.
Alexander Schuch
aschuch247 at gmail.com
Mon Dec 23 15:20:05 UTC 2013
Git commit 0af7f515370d157c4331b75a3f6129d5beb274a5 by Alexander Schuch.
Committed on 17/11/2013 at 19:34.
Pushed by aschuch into branch 'master'.
Add production and fleet size to standings.
The standings overview now contains the current production and the overall
fleet size (planet defence plus attacking fleets) of each player.
This is implemented in Konquest 2.3.
FEATURE: 301140
FIXED-IN: 4.13
REVIEW: 113914
GUI:
M +11 -6 planet.cc
M +14 -7 players/neutralplayer.cpp
M +8 -1 players/neutralplayer.h
M +16 -1 players/player.cpp
M +11 -1 players/player.h
M +15 -2 view/standingswidget.cpp
http://commits.kde.org/konquest/0af7f515370d157c4331b75a3f6129d5beb274a5
diff --git a/planet.cc b/planet.cc
index 3079a91..e6f20d6 100644
--- a/planet.cc
+++ b/planet.cc
@@ -89,15 +89,20 @@ Planet::turn(const GameOptions &options)
kDebug() << "Planet::turn...";
if (options.ProductionAfterConquere || !m_justconquered) {
- if (m_owner->isNeutral() )
- m_homeFleet.addShips( options.NeutralsProduction );
+ if (m_owner->isNeutral()) {
+ m_homeFleet.addShips(options.NeutralsProduction);
+ m_owner->statShipsBuilt(options.NeutralsProduction);
+ }
else {
- m_homeFleet.addShips( m_productionRate );
- m_owner->statShipsBuilt( m_productionRate );
+ m_homeFleet.addShips(m_productionRate);
+ m_owner->statShipsBuilt(m_productionRate);
}
-
- if (options.CumulativeProduction)
+
+ m_owner->statShipCount(m_homeFleet.shipCount());
+
+ if (options.CumulativeProduction) {
m_productionRate++;
+ }
}
m_oldShips = m_homeFleet.shipCount();
diff --git a/players/neutralplayer.cpp b/players/neutralplayer.cpp
index 8fa3668..6317c2d 100644
--- a/players/neutralplayer.cpp
+++ b/players/neutralplayer.cpp
@@ -41,21 +41,28 @@ bool NeutralPlayer::isDead()
void NeutralPlayer::play()
{
kDebug() << "NeutralPlayer::play";
+
// Go on each attack...
foreach (Player *player, m_game->players()) {
+ player->resetTurnStats();
+
foreach (AttackFleet *fleet, player->attackList()) {
- if( m_game->turnCounter() == fleet->arrivalTurn ) {
- if (m_game->doFleetArrival(fleet)) {
- player->attackDone(fleet);
- fleet->deleteLater();
- }
+ if (m_game->doFleetArrival(fleet)) {
+ player->attackDone(fleet);
+ fleet->deleteLater();
+ }
+ else {
+
+ // Only add the number of ships of the fleet to the player's
+ // total fleet size if the fleet does not arrive this turn.
+
+ player->statShipCount(fleet->shipCount());
}
}
}
// Go over each planet, adding its ships
- foreach (Planet *planet, m_game->map()->planets())
- {
+ foreach (Planet *planet, m_game->map()->planets()) {
kDebug() << "Turn for planet " << planet->name();
planet->turn(m_game->options());
}
diff --git a/players/neutralplayer.h b/players/neutralplayer.h
index 5c81375..fa25b56 100644
--- a/players/neutralplayer.h
+++ b/players/neutralplayer.h
@@ -25,6 +25,13 @@
#include "player.h"
+
+/**
+ * The neutral player is the owner of neutral planets. From a game mechanics
+ * point of view, a neutral player's turn starts a new game turn. Attacks and
+ * production are handled here.
+ */
+
class NeutralPlayer : public Player
{
Q_OBJECT
@@ -32,7 +39,7 @@ public:
explicit NeutralPlayer(Game *game);
virtual bool isDead();
-
+
virtual bool isNeutral();
protected:
diff --git a/players/player.cpp b/players/player.cpp
index 2bf1306..20df24f 100644
--- a/players/player.cpp
+++ b/players/player.cpp
@@ -31,7 +31,9 @@ Player::Player(Game *game, const QString &newName, const QColor &color) :
m_planetsConquered(0),
m_fleetsLaunched(0),
m_enemyFleetsDestroyed(0),
- m_enemyShipsDestroyed(0)
+ m_enemyShipsDestroyed(0),
+ m_turnProduction(0),
+ m_turnShips(0)
{
}
@@ -97,6 +99,19 @@ QString Player::coloredName() const
return QString("<font color=\"%1\">%2</font>").arg(m_color.name(), m_name);
}
+
+/**
+ * Reset the turn statistics.
+ */
+
+void
+Player::resetTurnStats()
+{
+ m_turnProduction = 0;
+ m_turnShips = 0;
+}
+
+
void Player::attackDone(AttackFleet *fleet)
{
m_attackList.removeAll(fleet);
diff --git a/players/player.h b/players/player.h
index 278b740..acf92ff 100644
--- a/players/player.h
+++ b/players/player.h
@@ -48,7 +48,7 @@ public:
Game *game() const { return m_game; }
// Statistics collection
- void statShipsBuilt( int x ) { m_shipsBuilt += x; }
+ void statShipsBuilt( int x ) { m_turnProduction += x; m_shipsBuilt += x; }
void statPlanetsConquered( int x ) { m_planetsConquered += x; }
void statFleetsLaunched( int x ) { m_fleetsLaunched += x; }
void statEnemyFleetsDestroyed( int x ) { m_enemyFleetsDestroyed += x; }
@@ -60,6 +60,12 @@ public:
int enemyFleetsDestroyed() const { return m_enemyFleetsDestroyed; }
int enemyShipsDestroyed() const { return m_enemyShipsDestroyed; }
+ void resetTurnStats();
+ void statShipCount(int x) { m_turnShips += x; }
+
+ int turnProduction() const { return m_turnProduction; }
+ int turnShips() const { return m_turnShips; }
+
AttackFleetList attackList() { return m_attackList; }
AttackFleetList newAttacks() { return m_newAttacks; }
AttackFleetList standingOrders() { return m_standingOrders; }
@@ -69,6 +75,7 @@ public:
void addStandingOrder(AttackFleet *fleet);
void cancelNewAttack(AttackFleet *fleet);
void deleteStandingOrders(Planet *planet);
+
protected:
virtual void play() = 0;
virtual void onEntry (QEvent *event);
@@ -100,6 +107,9 @@ private:
int m_enemyFleetsDestroyed;
int m_enemyShipsDestroyed;
+ int m_turnProduction; ///< number of ships produced in this turn
+ int m_turnShips; ///< number of all available player ships in this turn
+
/**
* @todo This is a bad GUI hack. The game selection grid is handled by just
* a list of player instances. This property stores the GUI name of the class
diff --git a/view/standingswidget.cpp b/view/standingswidget.cpp
index a72e06c..fceca22 100644
--- a/view/standingswidget.cpp
+++ b/view/standingswidget.cpp
@@ -124,6 +124,16 @@ StandingsWidget::update(const QList<Player *> players )
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 5, item);
+ item = new QTableWidgetItem();
+ item->setData(Qt::DisplayRole, curPlayer->turnProduction());
+ item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ m_scoreTable->setItem(row, 6, item);
+
+ item = new QTableWidgetItem();
+ item->setData(Qt::DisplayRole, curPlayer->turnShips());
+ item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ m_scoreTable->setItem(row, 7, item);
+
++row;
}
@@ -140,7 +150,7 @@ StandingsWidget::setupTable()
QVBoxLayout *main = new QVBoxLayout(this);
m_scoreTable = new QTableWidget();
- m_scoreTable->setColumnCount(6);
+ m_scoreTable->setColumnCount(8);
m_scoreTable->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
m_scoreTable->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
m_scoreTable->setSelectionMode(QAbstractItemView::NoSelection);
@@ -152,7 +162,10 @@ StandingsWidget::setupTable()
<< i18n("Planets\nConquered")
<< i18n("Fleets\nLaunched")
<< i18n("Fleets\nDestroyed")
- << i18n("Ships\nDestroyed");
+ << i18n("Ships\nDestroyed")
+ << i18n("Current\nProduction")
+ << i18n("Current\nFleet Size");
+
m_scoreTable->setHorizontalHeaderLabels(headerLabels);
m_scoreTable->verticalHeader()->hide();
More information about the kde-doc-english
mailing list