~ubuntu-branches/ubuntu/saucy/lordsawar/saucy

« back to all changes in this revision

Viewing changes to src/player.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2008-12-20 13:52:12 UTC
  • mfrom: (1.1.6 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081220135212-noeb2w3y98ebo7o9
Tags: 0.1.4-1
[ Barry deFreese ]
* New upstream release.
* Move 0.0.8-2.1 changelog entry to correct point in changelog.
* Make lordsawar-data suggest lordsawar.
* Update my e-mail address.
* Add build-depends on intltool, uuid-dev, and libboost-dev.
* Don't install locales since there are no translations currently.
* Add simple man page for new lordsawar-pbm binary.
* Drop gcc4.3 patches as they have been fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include "vector.h"
36
36
#include "fight.h"
37
37
#include "army.h"
38
 
#include "reward.h"
 
38
#include "defs.h"
39
39
 
40
40
class Stacklist;
41
41
class XML_Helper;
42
42
class Hero;
 
43
class HeroProto;
43
44
class Action;
44
45
class NetworkAction;
45
46
class History;
55
56
class Reward;
56
57
class Signpost;
57
58
class VectoredUnit;
 
59
class ArmyProto;
 
60
class Item;
 
61
class Triumphs;
58
62
 
59
63
//! The abstract player class.
60
64
/** 
112
116
class Player: public sigc::trackable
113
117
{
114
118
    public:
 
119
        //! The xml tag of this object in a saved-game file.
 
120
        static std::string d_tag; 
 
121
 
115
122
        //! The available player types.
116
123
        enum Type {
117
124
          //! Local human player.  See the RealPlayer class.
125
132
          //! Remote player.  See the NetworkPlayer class.
126
133
          NETWORKED = 8
127
134
        };
 
135
        static std::string playerTypeToString(const Player::Type type);
 
136
        static Player::Type playerTypeFromString(const std::string str);
128
137
 
129
138
        //! Every player has a diplomatic state with every other player.
130
139
        enum DiplomaticState {
148
157
          PROPOSE_WAR = 3 
149
158
        };
150
159
 
151
 
        //! Every player keeps a tally of frags.
152
 
        enum TriumphType {
153
 
          //! Kills we've made of an opponent's Hero army units.
154
 
          TALLY_HERO = 0, 
155
 
          //! Kills we've made of an opponent's awardable Army units.
156
 
          TALLY_SPECIAL = 1, 
157
 
          //! Kills we've made of an opponents other Army units.
158
 
          TALLY_NORMAL = 2, 
159
 
          //! Kills we've made of an opponent's Army units on the water.
160
 
          TALLY_SHIP = 3, 
161
 
          //! Kills we've made of opponent's Heroes who carry a standard Item.
162
 
          TALLY_FLAG = 4
163
 
        };
164
 
 
165
160
        /** 
166
161
         * Make a new player.  
167
162
         * @note AI_Fast, AI_Dummy, AI_Smart and RealPlayer use this 
416
411
        //! Returns the player's current score.
417
412
        Uint32 getScore();
418
413
 
419
 
        /**
420
 
         * The player's triumphs are tallied as opponent's armies die.
421
 
         * This method gets a tally for certain kind of triumph.  
422
 
         * See TriumphsDialog for a caller of this method.
423
 
         *
424
 
         * @param player      The player to obtain a tally for.
425
 
         * @param type        The kind of kills to tally (Player::TriumphType).
426
 
         *
427
 
         * @return Zero or more number of armies killed.
428
 
         */
429
 
        //! Returns a number of armies killed.
430
 
        Uint32 getTriumphTally(Player *player, TriumphType type) const
431
 
          {return d_triumph[player->getId()][type];}
432
 
 
433
414
        //! Returns the list of stacks (Stacklist) owned by the player.
434
415
        Stacklist* getStacklist() const {return d_stacklist;}
435
416
 
439
420
        //! Get the FogMap of the player.
440
421
        FogMap* getFogMap() const {return d_fogmap;}
441
422
 
 
423
        //! Get the Triumphs of the player.
 
424
        Triumphs* getTriumphs() const {return d_triumphs;}
 
425
 
442
426
        //! Get the fight order of the player.
443
427
        std::list<Uint32> getFightOrder() const {return d_fight_order;}
444
428
 
484
468
         */
485
469
        static Player* loadPlayer(XML_Helper* helper);
486
470
 
 
471
        void saveNetworkActions(XML_Helper *helper);
 
472
 
487
473
        /** 
488
474
         * This function is called when a player's turn starts. 
489
475
         * For AI players this function should start the algorithm.
495
481
        //! Callback to start a Player's turn.
496
482
        virtual bool startTurn() = 0;
497
483
 
 
484
        virtual void abortTurn() = 0;
 
485
 
498
486
        /** 
499
487
         * This function is called before a player's turn starts.
500
488
         * The idea here is that it happens before heroes are recruited,
530
518
         * 
531
519
         * @note Only change the name and gender attributes of the Hero.
532
520
         */
533
 
        void recruitHero(Hero* herotemplate, City *city, int cost, int alliesCount, const Army *ally);
 
521
        void recruitHero(HeroProto* hero, City *city, int cost, int alliesCount, const ArmyProto *ally);
534
522
 
535
523
        void rename (std::string name);
536
524
        /** 
1133
1121
        bool heroPlantStandard(Stack *stack);
1134
1122
 
1135
1123
        void cityTooPoorToProduce(City *city, int slot);
 
1124
 
 
1125
        bool isObservable() const {return d_observable;};
 
1126
        void setObservable(bool observable) {d_observable = observable;};
 
1127
 
1136
1128
        /**
1137
1129
         * @param city   The city being invaded.
1138
1130
         * @param loot   The gold looted.
1148
1140
         * @return True if we're accepting a hero, false if not.
1149
1141
         */
1150
1142
        //! Emitted whenever a hero is recruited.
1151
 
        sigc::signal<bool, Hero*, City *, int> srecruitingHero;
 
1143
        sigc::signal<bool, HeroProto*, City *, int> srecruitingHero;
1152
1144
 
1153
1145
        /**
1154
1146
         * @param army   The army that has gained a level.
1223
1215
        /**
1224
1216
         * Emitted when the player's treasury has been changed.
1225
1217
         */
1226
 
        //! Emitted whenever a player's status changes.
1227
 
        sigc::signal<void> schangingStatus;
 
1218
        //! Emitted whenever a player's stats changes.
 
1219
        sigc::signal<void> schangingStats;
 
1220
 
 
1221
        //! Emitted whenever a computer player does something of note.
 
1222
        sigc::signal<void, std::string> schangingStatus;
 
1223
 
 
1224
        //! Emitted whenever any player does anything at all.
 
1225
        sigc::signal<void> sbusy;
1228
1226
 
1229
1227
        /**
1230
1228
         * Emitted when the player's stack moves, is disbanded, gets blessed,
1284
1282
        //! Player would like to end the turn.
1285
1283
        sigc::signal<void> ending_turn;
1286
1284
 
 
1285
        //! Player has confirmed to abort the turn.
 
1286
        sigc::signal<void> aborted_turn;
 
1287
 
1287
1288
        sigc::signal<void, int> hero_arrives_with_allies;
1288
1289
 
1289
1290
        sigc::signal<void, NetworkAction *> acting;
1292
1293
        //! is it safe to vector from the given city?
1293
1294
        static bool safeFromAttack(City *c, Uint32 safe_mp, Uint32 min_defenders);
1294
1295
        void addHistory(History *history);
 
1296
        bool hasAlreadyInitializedTurn() const;
 
1297
        bool hasAlreadyEndedTurn() const;
 
1298
        void loadPbmGame();
 
1299
        //! Check the history to see if we ever conquered the given city.
 
1300
        bool conqueredCity(City *c);
 
1301
        std::list<Vector<int> > getStackTrack(Stack *s);
 
1302
        std::list<History *> getHistoryForHeroId(Uint32 id);
1295
1303
    protected:
1296
1304
        // do some fight cleaning up, setting
1297
1305
        void cleanupAfterFight(std::list<Stack*> &attackers,
1300
1308
        //! Move stack s one step forward on it's Path.
1301
1309
        bool stackMoveOneStep(Stack* s);
1302
1310
 
 
1311
        //! Move stack s one step forward on it's Path, over another stack.
 
1312
        bool stackMoveOneStepOverTooLargeFriendlyStacks(Stack *s);
 
1313
 
1303
1314
        void addAction(Action *action);
1304
1315
 
1305
1316
        // DATA
1342
1353
        //! What the player can see on the hidden map.
1343
1354
        FogMap* d_fogmap;
1344
1355
 
 
1356
        //! A tally of the kills that this player has made
 
1357
        Triumphs* d_triumphs;
 
1358
 
1345
1359
        //! The order in which this Player's army types fight in battle.
1346
1360
        /**
1347
1361
         * @note This value is related to the Player's ArmySet.
1348
1362
         */
1349
1363
        std::list<Uint32> d_fight_order; 
1350
1364
 
1351
 
        //! A set of statistics for this Player.
1352
 
        // 5 is max TriumphType + 1
1353
 
        Uint32 d_triumph[MAX_PLAYERS][5]; 
1354
 
 
1355
1365
        //! How many gold pieces the Player paid out in the last turn.
1356
1366
        Uint32 d_upkeep;
1357
1367
 
1373
1383
        //! A quantification of how much this Player likes every other Player.
1374
1384
        Uint32 d_diplomatic_score[MAX_PLAYERS];
1375
1385
 
 
1386
        //! Whether or not this player is observable by the user.
 
1387
        bool d_observable;
 
1388
 
1376
1389
        //! assists in scorekeeping for diplomacy
1377
1390
        void alterDiplomaticRelationshipScore (Player *player, int amount);
1378
1391
 
1390
1403
        void doCityChangeProduction(City *c, int slot);
1391
1404
        void doGiveReward(Stack *s, Reward *reward);
1392
1405
        void doHeroDropItem(Hero *hero, Item *item, Vector<int> pos);
 
1406
        bool doHeroDropAllItems(Hero *h, Vector<int> pos);
1393
1407
        void doHeroPickupItem(Hero *hero, Item *item, Vector<int> pos);
1394
1408
        void doLevelArmy(Army *army, Army::Stat stat);
1395
 
        void doStackDisband(Stack *stack);
 
1409
        bool doStackDisband(Stack *stack);
1396
1410
        void doSignpostChange(Signpost *signpost, std::string message);
1397
1411
        void doCityRename(City *c, std::string name);
1398
1412
        void doVectorFromCity(City * c, Vector<int> dest);
1402
1416
        void doDeclareDiplomacy (DiplomaticState state, Player *player);
1403
1417
        void doProposeDiplomacy (DiplomaticProposal proposal, Player *player);
1404
1418
        void doConquerCity(City *city, Stack *stack);
1405
 
        void doRecruitHero(Hero* herotemplate, City *city, int cost, int alliesCount, const Army *ally);
 
1419
        void doLootCity(Player *looted, Uint32 added, Uint32 subtracted);
 
1420
        Hero* doRecruitHero(HeroProto* hero, City *city, int cost, int alliesCount, const ArmyProto *ally);
1406
1421
        void doRename(std::string name);
1407
 
        void doCityProducesArmy(City *city);
1408
 
        void doVectoredUnitArrives(VectoredUnit *unit);
 
1422
        void doKill();
 
1423
        const Army *doCityProducesArmy(City *city);
 
1424
        Army *doVectoredUnitArrives(VectoredUnit *unit);
1409
1425
 
1410
1426
        void AI_maybeBuyScout();
1411
1427
 
1457
1473
 
1458
1474
        void pruneActionlist();
1459
1475
        static void pruneActionlist(std::list<Action*> actions);
 
1476
        std::list<History*> getHistoryForThisTurn() const;
1460
1477
            
1461
1478
    private:
1462
1479
        //! Loads the subdata of a player (actions and stacklist)
1503
1520
        void updateArmyValues(std::list<Stack*>& stacks, double xp_sum);
1504
1521
 
1505
1522
        void adjustDiplomacyFromConqueringCity(City *city);
1506
 
        // return how much gold we got out
1507
 
        int lootCity(City *city);
 
1523
 
 
1524
        void lootCity(City *city, Player *looted);
 
1525
        void calculateLoot(Player *looted, Uint32 &added, Uint32 &subtracted);
1508
1526
        void takeCityInPossession(City* c);
1509
 
        void tallyTriumph(Player *p, TriumphType type);
1510
1527
};
1511
1528
 
1512
1529
extern sigc::signal<void, Player::Type>  sendingTurn;