1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// Copyright 2005 by Anthony Liekens anthony@liekens.net
#ifndef PLAYERS_H
#define PLAYERS_H
#include <vector>
#include <list>
#include "actions.h"
class Ships;
class Universe;
class Planet;
class Selection;
class Game;
class Player {
public:
enum PlayerTypes { HUMAN, COMPUTER, NEUTRAL };
enum PlayerStates { ALIVE, DEAD };
protected:
Universe* universe;
Ships* ships;
PlayerTypes playerType;
PlayerStates playerState;
Uint32 color;
std::vector< int > stats;
std::list< Planet * > occupiedPlanets;
bool visible;
int team;
public:
Player(Universe *, Uint32, int);
virtual ~Player() {}
void addShip(Uint32, Planet * const);
void removeDeadShips();
void render();
void setVisible(bool vis) { visible = vis; };
void updateStats( double maximumPoints );
bool renderStats( int height );
void renderStatsLog( );
virtual void update(Game *game) = 0;
PlayerTypes getPlayerType();
void setColor( const Uint32& );
Uint32 getColor();
Universe* getUniverse() { return universe; }
double getPoints();
void addPlanet(Planet *);
void removePlanet(Planet *);
int getTeam() const { return team; }
};
class HumanPlayer : public Player {
private:
int fleetStrength;
public:
HumanPlayer( Universe* universe, Uint32 color, int team );
void update(Game *game);
void selectAllPlanets();
void setFleetStrength(int);
int getFleetStrength() const { return fleetStrength; }
void selectPlanetAt(int, int);
void selectNearestPlanet(int, int);
void moveToNearestPlanet(Uint32, int, int);
};
class ComputerPlayer : public Player {
private:
// strategy related
double proportionResidents; // proportion of all ships to reside on planets
double moonPriority, enemyPriority, preferredPriority, neutralPriority, weakerEnemyPriority, strongerEnemyPriority;
std::list< Planet* > preferredPlanets;
public:
ComputerPlayer( Universe* universe, Uint32 color, int team );
void update(Game *);
void action( const Uint32& time );
bool isAPreferredPlanet( Planet* );
Planet* getRandomNearbyPlanet( Planet* );
void printStats();
};
class NeutralPlayer : public Player {
public:
NeutralPlayer( Universe* universe, Uint32 color);
void update(Game *);
};
class Players : public std::list< Player* > {
protected:
Universe* universe;
Player* bestPlayer;
public:
Players( Universe* universe );
void render( );
double getSumOfScores();
void updateStats( int time );
void renderStats( );
void update(Game *);
};
class ComputerPlayerAction : public Action {
private:
ComputerPlayer* player;
public:
ComputerPlayerAction();
ComputerPlayerAction( ComputerPlayer* player );
void execute( const Uint32& time );
};
class UpdatePlayersStatsAction : public Action {
private:
Players* players;
public:
UpdatePlayersStatsAction();
UpdatePlayersStatsAction( Players* players );
void execute( const Uint32& time );
};
#endif
|