Commit 0af7f515 authored by Alexander Schuch's avatar Alexander Schuch
Browse files

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:
parent 7038c263
......@@ -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();
......
......@@ -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());
}
......
......@@ -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:
......
......@@ -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);
......
......@@ -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
......
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment