[kde-doc-english] KDE/kdegames/konquest

Jeffrey Kelling overlordapophis at gmail.com
Sat Oct 22 10:47:41 UTC 2011


SVN commit 1260171 by jkelling:

Implement standing orders

BUG: 87882
REVIEW: 6805
GUI: Add checkbox for standing orders to fleet setup area. While this
item is checked larger values than ships currently available can be
entered. Standing order will be executed whenever enough ships are
available.
GUI: If a planet has standing orders the number of ships needed for them
is displayed in the planets tooltip.
GUI: Standing orders are marked in the fleet dialog and can be removed
there at any time.

 M  +16 -8     dialogs/fleetdlg.cc  
 M  +3 -1      dialogs/fleetdlg.h  
 M  +9 -1      game.cpp  
 M  +1 -1      game.h  
 M  +28 -2     gameview.cc  
 M  +4 -2      gameview.h  
 M  +13 -2     map/mapitems.cc  
 M  +1 -0      planet.cc  
 M  +32 -2     players/player.cpp  
 M  +5 -0      players/player.h  


--- trunk/KDE/kdegames/konquest/dialogs/fleetdlg.cc #1260170:1260171
@@ -33,11 +33,11 @@
 
 #include "planet.h"
 
-
 FleetDlg::FleetDlg( QWidget *parent,
                     const AttackFleetList &fleets,
-                    const AttackFleetList &newFleets )
-    : KDialog(parent), m_newFleetList(newFleets), m_fleetList(fleets)
+                    const AttackFleetList &newFleets,
+                    const AttackFleetList &standingOrders)
+    : KDialog(parent), m_newFleetList(newFleets), m_standingOrders(standingOrders), m_fleetList(fleets)
 {
     setObjectName( QLatin1String( "FleetDlg" ) );
     setModal( true );
@@ -69,8 +69,9 @@
 FleetDlg::init()
 {
     AttackFleet *curFleet=0;
-    AttackFleetList fleets = m_newFleetList + m_fleetList;
-    int newFleets = m_newFleetList.count();
+    AttackFleetList fleets = m_standingOrders + m_newFleetList + m_fleetList;
+    const int standingOrders = m_standingOrders.count();
+    const int newFleets = standingOrders + m_newFleetList.count();
 
     m_fleetTable->setRowCount( fleets.count() );
     QTableWidgetItem *item;
@@ -82,6 +83,8 @@
         if( f < newFleets) {
           item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
           item->setCheckState(Qt::Checked);
+          if( f < standingOrders )
+              item->setText(i18n("Standing order"));
         } else {
           item->setFlags(Qt::ItemIsEnabled);
         }
@@ -120,11 +123,16 @@
         if( (item->flags() & Qt::ItemIsUserCheckable) &&
             (item->checkState() == Qt::Unchecked) ) {
 
-            int pos = m_fleetTable->item(f,1)->text().toInt();
-            if (pos > 0)
-                fleets->append( m_newFleetList.at(pos-1) );
+            const int pos = m_fleetTable->item(f,1)->text().toInt() - 1;
+            if (pos >= 0)
+            {
+                if(pos < m_standingOrders.count())
+                    fleets->append( m_standingOrders.at(pos) );
+                else
+                    fleets->append( m_newFleetList.at(pos - m_standingOrders.count()) );
         }
     }
+    }
 
     return fleets;
 }
--- trunk/KDE/kdegames/konquest/dialogs/fleetdlg.h #1260170:1260171
@@ -33,13 +33,15 @@
 public: 
     FleetDlg( QWidget *parent,
               const AttackFleetList &fleets,
-              const AttackFleetList &newFleets );
+              const AttackFleetList &newFleets,
+              const AttackFleetList &standingOrders );
     AttackFleetList *uncheckedFleets();
 
 private:
     void init();
 
     AttackFleetList  m_newFleetList;
+    AttackFleetList  m_standingOrders;
     AttackFleetList  m_fleetList;
     QTableWidget     *m_fleetTable;
 };
--- trunk/KDE/kdegames/konquest/game.cpp #1260170:1260171
@@ -67,9 +67,16 @@
     return 5 + random.getLong(10);
 }
 
-bool Game::attack(Planet *sourcePlanet, Planet *destPlanet, int shipCount)
+bool Game::attack(Planet *sourcePlanet, Planet *destPlanet, int shipCount, bool standingOrder)
 {
     int arrival = int(std::ceil(m_map->distance(sourcePlanet, destPlanet))) + m_turnCounter;
+    if(standingOrder)
+    {
+        m_currentPlayer->addStandingOrder(new AttackFleet(sourcePlanet, destPlanet, shipCount, arrival));
+        return true;
+    }
+    else
+    {
     AttackFleet *fleet = sourcePlanet->fleet().spawnAttackFleet(destPlanet, shipCount, arrival);
     if (fleet) {
         m_currentPlayer->addAttackFleet(fleet);
@@ -77,6 +84,7 @@
     }
     return false;
 }
+}
 
 void Game::setPlayers(const QList<Player *> &players)
 {
--- trunk/KDE/kdegames/konquest/game.h #1260170:1260171
@@ -58,7 +58,7 @@
 
     virtual void start() = 0;
 
-    bool attack( Planet *sourcePlanet, Planet *destPlanet, int shipCount);
+    bool attack( Planet *sourcePlanet, Planet *destPlanet, int shipCouna, bool standingOrder = false);
 
     static Coordinate generatePlanetCoordinates (int rows, int cols);
     static double generateKillPercentage();
--- trunk/KDE/kdegames/konquest/gameview.cc #1260170:1260171
@@ -4,6 +4,7 @@
     Copyright Dmitry Suzdalev <dimsuz at gmail.com>
     Copyright Inge Wallin <inge at lysator.liu.se>
     Copyright Pierre Ducroquet <pinaraf at gmail.com>
+    Copyright 2011 Jeffrey Kelling <overlordapophis at gmail.com>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -22,6 +23,7 @@
 
 #include "gameview.h"
 
+#include <QCheckBox>
 #include <QLabel>
 #include <QPushButton>
 #include <QLineEdit>
@@ -116,6 +118,11 @@
     m_shipCountEdit->setPalette( palette );
     m_shipCountEdit->setEchoMode( QLineEdit::Password );
 
+    m_standingOrder = new QCheckBox(i18n("Standing order"), this);
+    m_standingOrder->setEnabled(false);
+    m_standingOrder->setPalette( palette );
+    m_standingOrder->setCheckState(Qt::Unchecked);
+
     m_splashScreen = new QLabel( this );
     m_splashScreen->setPixmap(QPixmap(IMAGE_SPLASH));
     m_splashScreen->setScaledContents(true);
@@ -132,6 +139,7 @@
 
     topLineLayout->addSpacing( 5 );
     topLineLayout->addWidget( m_gameMessage, 10 );
+    topLineLayout->addWidget( m_standingOrder, 1 );
     topLineLayout->addWidget( m_shipCountEdit, 1 );
     topLineLayout->addWidget( m_endTurnBtn, 1 );
     
@@ -146,6 +154,8 @@
              this,            SLOT(planetSelected(Planet *)) );
     connect( m_shipCountEdit, SIGNAL(returnPressed()),
              this,            SLOT(newShipCount()) );
+    connect( m_standingOrder, SIGNAL(clicked()),
+             this,            SLOT(standingOrdersClicked()) );
     connect( m_endTurnBtn,    SIGNAL( clicked() ),
              this,            SLOT( nextPlayer() ) );
 
@@ -163,6 +173,14 @@
 //************************************************************************
 // Event handlers
 //************************************************************************
+void GameView::standingOrdersClicked() {
+    m_shipCountEdit->setFocus();
+    if(m_standingOrder->checkState() == Qt::Checked)
+        m_shipValidator->setTop(INT_MAX);
+    else
+        m_shipValidator->setTop(sourcePlanet->fleet().shipCount());
+}
+
 void
 GameView::resizeEvent ( QResizeEvent * ) {
     m_splashScreen->setGeometry( 0, 0, width(), height() );
@@ -239,6 +257,7 @@
         haveSourcePlanet = false;
         haveDestPlanet   = false;
         haveShipCount    = false;
+        standingOrder    = false;
         shipCount        = 0;
         m_mapScene->unselectPlanet();
 
@@ -257,6 +276,8 @@
         } else {
             m_shipCountEdit->setEnabled(false);
             m_shipCountEdit->setText( QString() );
+            m_standingOrder->setEnabled(false);
+            m_standingOrder->setCheckState(Qt::Unchecked);
             m_endTurnBtn->setEnabled( true );
             m_mapScene->unselectPlanet();
             m_gameMessage->setText( i18n("<qt>%1: Select source planet...</qt>", m_game->currentPlayer()->coloredName()) );
@@ -274,6 +295,7 @@
             turn();
         } else {
             m_shipCountEdit->setEnabled(false);
+            m_standingOrder->setEnabled(false);
             m_endTurnBtn->setEnabled( false );
             m_mapScene->selectPlanet(sourcePlanet);
             m_gameMessage->setText( i18n("<qt>%1: Select destination planet...</qt>", m_game->currentPlayer()->coloredName()) );
@@ -286,11 +308,12 @@
         // The user has selected, source, distance, ship count.
         if( haveShipCount ) {
             // We now have a complete fleet to send, so send it
-            if( !m_game->attack(sourcePlanet, destPlanet, shipCount) ) {
+            if( !m_game->attack(sourcePlanet, destPlanet, shipCount, standingOrder) ) {
                 KMessageBox::error( this, i18n("Not enough ships to send.") );
             }
 
             m_shipCountEdit->setEnabled(false);
+            m_standingOrder->setEnabled(false);
             m_endTurnBtn->setEnabled( true );
 
             m_guiState = NONE;
@@ -302,6 +325,7 @@
             m_gameMessage->setText( i18n("%1: How many ships?", m_game->currentPlayer()->coloredName()) );
 
             m_shipCountEdit->setEnabled(true);
+            m_standingOrder->setEnabled(true);
             m_shipCountEdit->setFocus();
 
             m_endTurnBtn->setEnabled( false );
@@ -601,9 +625,11 @@
     switch (m_guiState) {
     case SHIP_COUNT:
         shipCount = m_shipCountEdit->text().toInt(&ok);
+        standingOrder = m_standingOrder->checkState() == Qt::Checked;
         if (ok)
             haveShipCount = true;
         m_shipCountEdit->setText( QString() );
+        m_standingOrder->setCheckState(Qt::Unchecked);
         turn();
         break;
 
@@ -688,7 +714,7 @@
 {
     Player *current = m_game->currentPlayer();
     FleetDlg  *fleetDlg = new FleetDlg( this, current->attackList(),
-                                              current->newAttacks());
+                                        current->newAttacks(), current->standingOrders());
     if (fleetDlg->exec()) {
         AttackFleetList *deleteAttacks = fleetDlg->uncheckedFleets();
         foreach(AttackFleet *curFleet, *deleteAttacks) {
--- trunk/KDE/kdegames/konquest/gameview.h #1260170:1260171
@@ -35,7 +35,7 @@
 // forward declarations
 //************************************************************************
 
-
+class QCheckBox;
 class QLabel;
 class QPushButton;
 class QLineEdit;
@@ -86,6 +86,7 @@
     void  planetSelected( Planet * );
     void  newShipCount();
     void  nextPlayer();
+    void  standingOrdersClicked();
 
     //***************************************************************
     // Toolbar items
@@ -127,6 +128,7 @@
     QLabel        *m_gameMessage;
     QPushButton   *m_endTurnBtn;
     QLineEdit     *m_shipCountEdit;
+    QCheckBox     *m_standingOrder;
     QIntValidator *m_shipValidator;
     QLabel        *m_splashScreen;
     QTextEdit     *m_msgWidget;
@@ -149,7 +151,7 @@
     bool                haveDestPlanet;
     Planet             *destPlanet;
 
-    bool                haveShipCount;
+    bool                haveShipCount, standingOrder;
     int                 shipCount;
 
     //***************************************************************
--- trunk/KDE/kdegames/konquest/map/mapitems.cc #1260170:1260171
@@ -4,6 +4,7 @@
     Copyright 2008-2009 Dmitry Suzdalev <dimsuz at gmail.com>
     Copyright Inge Wallin <inge at lysator.liu.se>
     Copyright Pierre Ducroquet <pinaraf at gmail.com>
+    Copyright 2011 Jeffrey Kelling <overlordapophis at gmail.com>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -231,8 +232,18 @@
           + (m_game->options().NeutralsShowShips || !planet->player()->isNeutral() ?
              QString("<br />"
              + i18n("Ships: %1", planet->ships() )) :
-             QString())
-          + "<br />"
+             QString()));
+		if( m_game->currentPlayer() == planet->player() )
+        {
+            int shipsNeeded = 0; // determine hw many ships will be neede by standing orders
+            foreach(AttackFleet* fleet, planet->player()->standingOrders()) {
+                if(fleet->source == planet)
+                    shipsNeeded += fleet->shipCount();
+            }
+            if(shipsNeeded)
+                text += QString("<br />" + i18nc("regarding standing orders", "Ships due: %1", shipsNeeded));
+        }
+        text += QString("<br />"
           + i18n("Production: %1", planet->production() )
           + "<br />"
           + i18n("Kill percent: %1", planet->killPercentage() ));
--- trunk/KDE/kdegames/konquest/planet.cc #1260170:1260171
@@ -75,6 +75,7 @@
 void
 Planet::conquer( AttackFleet *conqueringFleet )
 {
+    m_owner->deleteStandingOrders(this);
     m_owner = conqueringFleet->owner;
     m_owner->statPlanetsConquered(1);
     m_homeFleet.become( conqueringFleet );
--- trunk/KDE/kdegames/konquest/players/player.cpp #1260170:1260171
@@ -1,5 +1,6 @@
 /*
     Copyright Pierre Ducroquet <pinaraf at pinaraf.info>
+    Copyright 2011 Jeffrey Kelling <overlordapophis at gmail.com>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -54,6 +55,13 @@
     Q_UNUSED(event);
     qDebug() << "Exiting state for player " << m_name;
     qDebug() << "We are moving our new attacks to our attacks";
+    for(AttackFleetList::iterator a = m_standingOrders.begin(); a != m_standingOrders.end(); ++a)
+    {
+        AttackFleet* fleet = (*a)->source->fleet().spawnAttackFleet((*a)->destination, (*a)->shipCount(), (*a)->arrivalTurn);
+        ++(*a)->arrivalTurn;
+        if(fleet)
+            m_newAttacks << fleet;
+    }
     m_attackList += m_newAttacks;
     statFleetsLaunched(m_newAttacks.size());
     m_newAttacks.clear();
@@ -94,11 +102,33 @@
     m_newAttacks << fleet;
 }
 
+void Player::addStandingOrder(AttackFleet *fleet)
+{
+    m_standingOrders << fleet;
+}
+
 void Player::cancelNewAttack(AttackFleet *fleet)
 {
-    if (!m_newAttacks.contains(fleet))
+    if (!m_newAttacks.removeAll(fleet))
+    {
+        if(!m_standingOrders.removeAll(fleet))
         return;
+    }
+    else
     fleet->source->fleet().absorb(fleet);
-    m_newAttacks.removeAll(fleet);
     fleet->deleteLater();
 }
+
+void Player::deleteStandingOrders(Planet *planet)
+{
+    for(AttackFleetList::iterator a = m_standingOrders.begin(); a != m_standingOrders.end(); )
+    {
+        if((*a)->source == planet)
+        {
+            (*a)->deleteLater();
+            a = m_standingOrders.erase(a);
+        }
+        else
+            ++a;
+    }
+}
--- trunk/KDE/kdegames/konquest/players/player.h #1260170:1260171
@@ -24,6 +24,7 @@
 #include "../fleet.h"
 
 class Game;
+class Planet;
 
 class Player : public QState
 {
@@ -60,10 +61,13 @@
 
     AttackFleetList attackList() { return m_attackList; }
     AttackFleetList newAttacks() { return m_newAttacks; }
+    AttackFleetList standingOrders() { return m_standingOrders; }
     void attackDone(AttackFleet *fleet);
 
     void addAttackFleet(AttackFleet *fleet);
+    void addStandingOrder(AttackFleet *fleet);
     void cancelNewAttack(AttackFleet *fleet);
+    void deleteStandingOrders(Planet *planet);
 protected:
     virtual void play() = 0;
     virtual void onEntry (QEvent *event);
@@ -82,6 +86,7 @@
     AttackFleetList m_attackList;
     // Fleets to send at the end of this turn
     AttackFleetList m_newAttacks;
+    AttackFleetList m_standingOrders;
 
     // Some fundamental properties.
     QString  m_name;


More information about the kde-doc-english mailing list