$treeview $search $mathjax
Stratagus  2.2.7
$projectbrief
$projectbrief
$searchbox
-->
         _________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

CPlayer Class Reference

Diplomacy states for CommandDiplomacy. More...

#include <player.h>

List of all members.


Public Member Functions

void SetStartView (const Vec2i &pos)
 map tile start position
void void bool IsEnemy (const int index) const
player.cpp - The players.
void SetName (const std::string &name)
 Timer for the upgrades.
void Clear ()
 Clear turn related player data.
std::vector< CUnit * >
::const_iterator 
UnitBegin () const
std::vector< CUnit * >::iterator UnitBegin ()
std::vector< CUnit * >
::const_iterator 
UnitEnd () const
std::vector< CUnit * >::iterator UnitEnd ()
CUnitGetUnit (int index) const
int GetUnitCount () const
void AddUnit (CUnit &unit)
void RemoveUnit (CUnit &unit)
int GetResource (const int resource, const int type)
 Get a resource of the player.
void ChangeResource (const int resource, const int value, const bool store=false)
 Adds/subtracts some resources to/from the player store.
void SetResource (const int resource, const int value, const int type=STORE_OVERALL)
 Set a resource of the player.
bool CheckResource (const int resource, const int value)
 Check, if there enough resources for action.
int CheckLimits (const CUnitType &type) const
 Check if the unit-type didn't break any unit limits and supply/demand.
int CheckCosts (const int *costs) const
 Check if enough resources are available for costs.
int CheckUnitType (const CUnitType &type) const
 Check if enough resources are available for a new unit-type.
void AddCosts (const int *costs)
 Add costs to the resources.
void AddUnitType (const CUnitType &type)
 Add costs for an unit-type to the resources.
void AddCostsFactor (const int *costs, int factor)
 Add a factor of costs to the resources.
void SubCosts (const int *costs)
 Remove costs from the resources.
void SubUnitType (const CUnitType &type)
 Remove costs for an unit-type from the resources.
void SubCostsFactor (const int *costs, int factor)
 Remove a factor of costs from the resources.
int HaveUnitTypeByType (const CUnitType &type) const
 Does the player have units of that type.
int HaveUnitTypeByIdent (const std::string &ident) const
 Does the player have units of that type.
void Notify (int type, const Vec2i &pos, const char *fmt,...) const PRINTF_VAARG_ATTRIBUTE(4
 Notify player about a problem.
void void Notify (const char *fmt,...) const PRINTF_VAARG_ATTRIBUTE(2
 Notify player about a problem.
bool IsEnemy (const CPlayer &player) const
bool IsEnemy (const CUnit &unit) const
bool IsAllied (const CPlayer &player) const
bool IsAllied (const CUnit &unit) const
bool IsVisionSharing () const
bool IsSharedVision (const CPlayer &player) const
bool IsSharedVision (const CUnit &unit) const
bool IsBothSharedVision (const CPlayer &player) const
bool IsBothSharedVision (const CUnit &unit) const
bool IsTeamed (const CPlayer &player) const
bool IsTeamed (const CUnit &unit) const
void SetDiplomacyNeutralWith (const CPlayer &player)
void SetDiplomacyAlliedWith (const CPlayer &player)
void SetDiplomacyEnemyWith (const CPlayer &player)
void SetDiplomacyCrazyWith (const CPlayer &player)
void ShareVisionWith (const CPlayer &player)
void UnshareVisionWith (const CPlayer &player)
void Init (int type)
void Save (CFile &file) const
script_player.cpp - The player ccl functions.
void Load (lua_State *l)

Public Attributes

int Index
std::string Name
 player as number
int Type
 name of non computer
int Race
 type of player (human,computer,...)
std::string AiName
 race of player (orc,human,...)
int Team
 AI for computer.
Vec2i StartPos
 team of player
int Resources [MaxCosts]
int MaxResources [MaxCosts]
 resources in overall store
int StoredResources [MaxCosts]
 max resources can be stored
int LastResources [MaxCosts]
 resources in store buildings (can't exceed MaxResources)
int Incomes [MaxCosts]
 last values for revenue
int Revenue [MaxCosts]
 income of the resources
int SpeedResourcesHarvest [MaxCosts]
 income rate of the resources
int SpeedResourcesReturn [MaxCosts]
 speed factor for harvesting resources
int SpeedBuild
 speed factor for returning resources
int SpeedTrain
 speed factor for building
int SpeedUpgrade
 speed factor for training
int SpeedResearch
 speed factor for upgrading
int UnitTypesCount [UnitTypeMax]
 speed factor for researching
bool AiEnabled
 total units of unit-type
PlayerAiAi
 handle AI on local computer
int NumBuildings
 Ai structure pointer.
int Supply
 # buildings
int Demand
 supply available/produced
int UnitLimit
 demand of player
int BuildingLimit
 # food units allowed
int TotalUnitLimit
 # buildings allowed
int Score
 # total unit number allowed
int TotalUnits
 Points for killing ...
int TotalBuildings
int TotalResources [MaxCosts]
int TotalRazings
int TotalKills
Uint32 Color
 How many unit killed.
CUnitColors UnitColors
 color of units on minimap
CAllow Allow
 Unit colors for new units.
CUpgradeTimers UpgradeTimers
 Allowed for player.

Detailed Description

Diplomacy states for CommandDiplomacy.

Player structure

#include "player.h"

This structure contains all informations about a player in game.

The player structure members:

CPlayer::Player

This is the unique slot number. It is not possible that two players have the same slot number at the same time. The slot numbers are reused in the future. This means if a player is defeated, a new player can join using this slot. Currently PlayerMax (16) players are supported. This member is used to access bit fields. Slot PlayerNumNeutral (15) is reserved for the neutral units like gold-mines or critters.

Note:
Should call this member Slot?
CPlayer::Name

Name of the player used for displays and network game. It is restricted to 15 characters plus final zero.

CPlayer::Type

Type of the player. This field is setup from the level (map). We support currently PlayerNeutral, PlayerNobody, PlayerComputer, PlayerPerson, PlayerRescuePassive and PlayerRescueActive.

See also:
PlayerTypes.
CPlayer::RaceName

Name of the race to which the player belongs, used to select the user interface and the AI. We have 'orc', 'human', 'alliance' or 'mythical'. Should only be used during configuration and not during runtime.

CPlayer::Race

Race number of the player. This field is setup from the level map. This number is mapped with PlayerRaces to the symbolic name CPlayer::RaceName.

CPlayer::AiName

AI name for computer. This field is setup from the map. Used to select the AI for the computer player.

CPlayer::Team

Team of player. Selected during network game setup. All players of the same team are allied and enemy to all other teams.

Note:
It is planned to show the team on the map.
CPlayer::Enemy

A bit field which contains the enemies of this player. If CPlayer::Enemy & (1<<CPlayer::Player) != 0 its an enemy. Setup during startup using the CPlayer::Team, can later be changed with diplomacy. CPlayer::Enemy and CPlayer::Allied are combined, if none bit is set, the player is neutral.

Note:
You can be allied to a player, which sees you as enemy.
CPlayer::Allied

A bit field which contains the allies of this player. If CPlayer::Allied & (1<<CPlayer::Player) != 0 its an allied. Setup during startup using the Player:Team, can later be changed with diplomacy. CPlayer::Enemy and CPlayer::Allied are combined, if none bit is set, the player is neutral.

Note:
You can be allied to a player, which sees you as enemy.
CPlayer::SharedVision

A bit field which contains shared vision for this player. Shared vision only works when it's activated both ways. Really.

CPlayer::StartX CPlayer::StartY

The tile map coordinates of the player start position. 0,0 is the upper left on the map. This members are setup from the map and only important for the game start. Ignored if game starts with level settings. Used to place the initial workers if you play with 1 or 3 workers.

CPlayer::Resources[MaxCosts]

How many resources the player owns. Needed for building units and structures.

See also:
_costs_, TimeCost, GoldCost, WoodCost, OilCost, MaxCosts.
CPlayer::MaxResources[MaxCosts]

How many resources the player can store at the moment.

CPlayer::Incomes[MaxCosts]

Income of the resources, when they are delivered at a store.

See also:
_costs_, TimeCost, GoldCost, WoodCost, OilCost, MaxCosts.
CPlayer::LastResources[MaxCosts]

Keeps track of resources in time (used for calculating CPlayer::Revenue, see below)

CPlayer::Revenue[MaxCosts]

Production of resources per minute (or estimates) Used just as information (statistics) for the player...

CPlayer::UnitTypesCount[UnitTypeMax]

Total count for each different unit type. Used by the AI and for dependencies checks. The addition of all counts should be CPlayer::TotalNumUnits.

Note:
Should not use the maximum number of unit-types here, only the real number of unit-types used.
CPlayer::AiEnabled

If the player is controlled by the computer and this flag is true, than the player is handled by the AI on this local computer.

Note:
Currently the AI is calculated parallel on all computers in a network play. It is planned to change this.
CPlayer::Ai

AI structure pointer. Please look at PlayerAi for more informations.

CPlayer::Units

A table of all (CPlayer::TotalNumUnits) units of the player.

CPlayer::TotalNumUnits

Total number of units (incl. buildings) in the CPlayer::Units table.

CPlayer::Demand

Total unit demand, used to demand limit. A player can only build up to CPlayer::Food units and not more than CPlayer::FoodUnitLimit units.

Note:
that CPlayer::NumFoodUnits > CPlayer::Food, when enough farms are destroyed.
CPlayer::NumBuildings

Total number buildings, units that don't need food.

CPlayer::Food

Number of food available/produced. Player can't train more CPlayer::NumFoodUnits than this.

Note:
that all limits are always checked.
CPlayer::FoodUnitLimit

Number of food units allowed. Player can't train more CPlayer::NumFoodUnits than this.

Note:
that all limits are always checked.
CPlayer::BuildingLimit

Number of buildings allowed. Player can't build more CPlayer::NumBuildings than this.

Note:
that all limits are always checked.
CPlayer::TotalUnitLimit

Number of total units allowed. Player can't have more CPlayer::NumFoodUnits+CPlayerNumBuildings=CPlayerTotalNumUnits this.

Note:
that all limits are always checked.
CPlayer::Score

Total number of points. You can get points for killing units, destroying buildings ...

CPlayer::TotalUnits

Total number of units made.

CPlayer::TotalBuildings

Total number of buildings made.

CPlayer::TotalResources[MaxCosts]

Total number of resources collected.

See also:
_costs_, TimeCost, GoldCost, WoodCost, OilCost, MaxCosts.
CPlayer::TotalRazings

Total number of buildings destroyed.

CPlayer::TotalKills

Total number of kills.

CPlayer::Color

Color of units of this player on the minimap. Index number into the global palette.

CPlayer::UnitColors

Unit colors of this player. Contains the hardware dependent pixel values for the player colors (palette index #208-#211). Setup from the global palette.

Note:
Index #208-#211 are various SHADES of the team color (#208 is brightest shade, #211 is darkest shade) .... these numbers are NOT red=#208, blue=#209, etc
CPlayer::Allow

Contains which unit-types and upgrades are allowed for the player. Possible values are:

Timer for the upgrades. One timer for all possible upgrades. Initial 0 counted up by the upgrade action, until it reaches the upgrade time.
See also:
_upgrade_timers_
Note:
it is planned to combine research for faster upgrades.

Member Function Documentation

void CPlayer::SetStartView ( const Vec2i pos  )  [inline]

map tile start position

void CPlayer::SetName ( const std::string &  name  ) 

Timer for the upgrades.

Change player name

Change player name.

Parameters:
name New name.

void CPlayer::Clear (  ) 

Clear turn related player data.

Clear all player data excepts members which don't change.

The fields that are not cleared are UnitLimit, BuildingLimit, TotalUnitLimit and Allow.

std::vector< CUnit * >::const_iterator CPlayer::UnitBegin (  )  const

std::vector< CUnit * >::iterator CPlayer::UnitBegin (  ) 

std::vector< CUnit * >::const_iterator CPlayer::UnitEnd (  )  const

std::vector< CUnit * >::iterator CPlayer::UnitEnd (  ) 

CUnit & CPlayer::GetUnit ( int  index  )  const

int CPlayer::GetUnitCount (  )  const

void CPlayer::AddUnit ( CUnit unit  ) 

void CPlayer::RemoveUnit ( CUnit unit  ) 

int CPlayer::GetResource ( const int  resource,
const int  type 
)

Get a resource of the player.

Gets the player resource.

Parameters:
resource Resource to get.
type Storing type
Note:
Storing types: 0 - overall store, 1 - store buildings, 2 - both

void CPlayer::ChangeResource ( const int  resource,
const int  value,
const bool  store = false 
)

Adds/subtracts some resources to/from the player store.

Adds/subtracts some resources to/from the player store

Parameters:
resource Resource to add/subtract.
value How many of this resource (can be negative).
store If true, sets the building store resources, else the overall resources.

void CPlayer::SetResource ( const int  resource,
const int  value,
const int  type = STORE_OVERALL 
)

Set a resource of the player.

Change the player resource.

Parameters:
resource Resource to change.
value How many of this resource.
type Resource types: 0 - overall store, 1 - store buildings, 2 - both

bool CPlayer::CheckResource ( const int  resource,
const int  value 
)

Check, if there enough resources for action.

Check, if there enough resources for action.

Parameters:
resource Resource to change.
value How many of this resource.

int CPlayer::CheckLimits ( const CUnitType type  )  const

Check if the unit-type didn't break any unit limits and supply/demand.

Check if the unit-type didn't break any unit limits.

Parameters:
type Type of unit.
Returns:
True if enough, negative on problem.
Note:
The return values of the PlayerCheck functions are inconsistent.

int CPlayer::CheckCosts ( const int *  costs  )  const

Check if enough resources are available for costs.

Check if enough resources for are available.

Parameters:
costs How many costs.
Returns:
False if all enough, otherwise a bit mask.
Note:
The return values of the PlayerCheck functions are inconsistent.

int CPlayer::CheckUnitType ( const CUnitType type  )  const

Check if enough resources are available for a new unit-type.

Check if enough resources for new unit is available.

Parameters:
type Type of unit.
Returns:
False if all enough, otherwise a bit mask.

void CPlayer::AddCosts ( const int *  costs  ) 

Add costs to the resources.

Add costs to the resources

Parameters:
costs How many costs.

void CPlayer::AddUnitType ( const CUnitType type  ) 

Add costs for an unit-type to the resources.

Add the costs of an unit type to resources

Parameters:
type Type of unit.

void CPlayer::AddCostsFactor ( const int *  costs,
int  factor 
)

Add a factor of costs to the resources.

Add a factor of costs to the resources

Parameters:
costs How many costs.
factor Factor of the costs to apply.

void CPlayer::SubCosts ( const int *  costs  ) 

Remove costs from the resources.

Subtract costs from the resources

Parameters:
costs How many costs.

void CPlayer::SubUnitType ( const CUnitType type  ) 

Remove costs for an unit-type from the resources.

Substract the costs of new unit from resources

Parameters:
type Type of unit.

void CPlayer::SubCostsFactor ( const int *  costs,
int  factor 
)

Remove a factor of costs from the resources.

Substract a factor of costs from the resources

Parameters:
costs How many costs.
factor Factor of the costs to apply.

int CPlayer::HaveUnitTypeByType ( const CUnitType type  )  const

Does the player have units of that type.

Have unit of type.

Parameters:
type Type of unit.
Returns:
How many exists, false otherwise.

int CPlayer::HaveUnitTypeByIdent ( const std::string &  ident  )  const

Does the player have units of that type.

Have unit of type.

Parameters:
ident Identifier of unit-type that should be lookuped.
Returns:
How many exists, false otherwise.
Note:
This function should not be used during run time.

void CPlayer::Notify ( int  type,
const Vec2i pos,
const char *  fmt,
  ... 
) const

Notify player about a problem.

Notify player about a problem.

Parameters:
type Problem type
pos Map tile position
fmt Message format
... Message varargs
Todo:
FIXME: We must also notfiy allied players.

void CPlayer::Notify ( const char *  fmt,
  ... 
) const

Notify player about a problem.

Notify player about a problem.

Parameters:
type Problem type
pos Map tile position
fmt Message format
... Message varargs
Todo:
FIXME: We must also notfiy allied players.

void void bool CPlayer::IsEnemy ( const int  index  )  const [inline]

Check if the player index is an enemy

bool CPlayer::IsEnemy ( const CPlayer player  )  const

Check if the player is an enemy

bool CPlayer::IsEnemy ( const CUnit unit  )  const

Check if the unit is an enemy

bool CPlayer::IsAllied ( const CPlayer player  )  const

Check if the player is an ally

bool CPlayer::IsAllied ( const CUnit unit  )  const

Check if the unit is an ally

bool CPlayer::IsVisionSharing (  )  const

bool CPlayer::IsSharedVision ( const CPlayer player  )  const

Check if the player shares vision with the player

bool CPlayer::IsSharedVision ( const CUnit unit  )  const

Check if the player shares vision with the unit

bool CPlayer::IsBothSharedVision ( const CPlayer player  )  const

Check if the both players share vision

bool CPlayer::IsBothSharedVision ( const CUnit unit  )  const

Check if the player and the unit share vision

bool CPlayer::IsTeamed ( const CPlayer player  )  const

Check if the player is teamed

bool CPlayer::IsTeamed ( const CUnit unit  )  const

Check if the unit is teamed

void CPlayer::SetDiplomacyNeutralWith ( const CPlayer player  ) 

void CPlayer::SetDiplomacyAlliedWith ( const CPlayer player  ) 

void CPlayer::SetDiplomacyEnemyWith ( const CPlayer player  ) 

void CPlayer::SetDiplomacyCrazyWith ( const CPlayer player  ) 

void CPlayer::ShareVisionWith ( const CPlayer player  ) 

void CPlayer::UnshareVisionWith ( const CPlayer player  ) 

void CPlayer::Init ( int  type  ) 

void CPlayer::Save ( CFile file  )  const

void CPlayer::Load ( lua_State *  l  ) 


Member Data Documentation

std::string CPlayer::Name

player as number

name of non computer

type of player (human,computer,...)

std::string CPlayer::AiName

race of player (orc,human,...)

AI for computer.

team of player

int CPlayer::Resources[MaxCosts]

int CPlayer::MaxResources[MaxCosts]

resources in overall store

int CPlayer::StoredResources[MaxCosts]

max resources can be stored

int CPlayer::LastResources[MaxCosts]

resources in store buildings (can't exceed MaxResources)

int CPlayer::Incomes[MaxCosts]

last values for revenue

int CPlayer::Revenue[MaxCosts]

income of the resources

income rate of the resources

speed factor for harvesting resources

speed factor for returning resources

speed factor for building

speed factor for training

speed factor for upgrading

int CPlayer::UnitTypesCount[UnitTypeMax]

speed factor for researching

total units of unit-type

handle AI on local computer

Ai structure pointer.

# buildings

supply available/produced

demand of player

# food units allowed

# buildings allowed

# total unit number allowed

Points for killing ...

int CPlayer::TotalResources[MaxCosts]

How many unit killed.

color of units on minimap

Unit colors for new units.


The documentation for this class was generated from the following files:
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.