File indexing completed on 2024-11-03 03:47:51

0001 /*
0002     SPDX-FileCopyrightText: 2006 Pierre Ducroquet <pinaraf@pinaraf.info>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef PLAYER_H
0008 #define PLAYER_H
0009 
0010 #include <QColor>
0011 #include <QState>
0012 #include "../fleet.h"
0013 
0014 class Game;
0015 class Planet;
0016 
0017 class Player : public QState
0018 {
0019     Q_OBJECT
0020 public:
0021     explicit Player(Game *game, const QString &newName, const QColor &color);
0022 
0023     virtual bool isDead();
0024 
0025     virtual bool isNeutral();
0026     virtual bool isAiPlayer();
0027     virtual bool isSpectator();
0028 
0029     // Getters and Setters for some fundamental properties.
0030     QString name()        const { return m_name; }
0031     void setName(const QString &name) {  m_name = name; }
0032 
0033     QString coloredName() const;
0034     QColor& color()             { return m_color; }
0035 
0036     Game *game() const { return m_game; }
0037 
0038     // Statistics collection
0039     void statShipsBuilt( long long x )           { m_turnProduction += x; m_shipsBuilt += x; }
0040     void statPlanetsConquered( long long x )     { m_planetsConquered     += x; }
0041     void statFleetsLaunched( long long x )       { m_fleetsLaunched       += x; }
0042     void statEnemyFleetsDestroyed( long long x ) { m_enemyFleetsDestroyed += x; }
0043     void statEnemyShipsDestroyed( long long x )  { m_enemyShipsDestroyed  += x; }
0044 
0045     long long  shipsBuilt()           const { return m_shipsBuilt;           }
0046     long long  planetsConquered()     const { return m_planetsConquered;     }
0047     long long  fleetsLaunched()       const { return m_fleetsLaunched;       }
0048     long long  enemyFleetsDestroyed() const { return m_enemyFleetsDestroyed; }
0049     long long  enemyShipsDestroyed()  const { return m_enemyShipsDestroyed;  }
0050 
0051     void resetTurnStats();
0052     void statShipCount(long long x) { m_turnShips += x; }
0053 
0054     long long turnProduction() const { return m_turnProduction; }
0055     long long turnShips() const { return m_turnShips; }
0056 
0057     const AttackFleetList attackList() { return m_attackList; }
0058     const AttackFleetList newAttacks() { return m_newAttacks; }
0059     const AttackFleetList standingOrders() { return m_standingOrders; }
0060     void attackDone(AttackFleet *fleet);
0061 
0062     void addAttackFleet(AttackFleet *fleet);
0063     void addStandingOrder(AttackFleet *fleet);
0064     void cancelNewAttack(AttackFleet *fleet);
0065     void deleteStandingOrders(Planet *planet);
0066 
0067 protected:
0068     virtual void play() = 0;
0069     void onEntry (QEvent *event) override;
0070     void onExit (QEvent *event) override;
0071     Game *m_game;
0072 
0073 Q_SIGNALS:
0074     void donePlaying();
0075 
0076 private:
0077     // Attack fleets sent by this player that are still moving
0078     AttackFleetList m_attackList;
0079     // Fleets to send at the end of this turn
0080     AttackFleetList m_newAttacks;
0081     AttackFleetList m_standingOrders;
0082 
0083     // Some fundamental properties.
0084     QString  m_name;
0085     QColor   m_color;
0086 
0087     // statistics counters
0088     long long  m_shipsBuilt;
0089     long long  m_planetsConquered;
0090     long long  m_fleetsLaunched;
0091     long long  m_enemyFleetsDestroyed;
0092     long long  m_enemyShipsDestroyed;
0093 
0094     long long m_turnProduction; ///< number of ships produced in this turn
0095     long long m_turnShips; ///< number of all available player ships in this turn
0096 
0097     /**
0098      * @todo This is a bad GUI hack. The game selection grid is handled by just
0099      * a list of player instances. This property stores the GUI name of the class
0100      * used to create this player. For example a player of "AiDefaultWeak" class
0101      * will be created via "AiDefaultWeakGui" with the GUI name of "Default Weak".
0102      * That GUI name is stored here.
0103      */
0104 
0105     QString m_guiName;
0106 
0107 public:
0108     void setGuiName(const QString &guiName) {
0109         m_guiName = guiName;
0110     }
0111 
0112     QString guiName() const {
0113         return m_guiName;
0114     }
0115 };
0116 
0117 #endif // PLAYER_H