____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
A futuristic real-time strategy game.
This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project.
Distributed under the "GNU General Public License"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <algorithm>
#include "stratagus.h"
#include "video.h"
#include "sound.h"
#include "unitsound.h"
#include "unittype.h"
#include "player.h"
#include "unit.h"
#include "map.h"
#include "ai.h"
#include "network.h"
#include "netconnect.h"
#include "interface.h"
#include "iolib.h"
#include "ui.h"
Go to the source code of this file.
Functions | |
| void | InitPlayers (void) |
| < Init players | |
| void | CleanPlayers (void) |
| Save players. | |
| void | CalculateRequestedAmount (CUnitType *utype, int bcosts[MaxCosts], int costs[MaxCosts]) |
| Output debug informations for players. | |
| static int | AvailableResourcesRate (int type, CPlayer *p) |
| static int | SpecificEfficiency (int type, CPlayer *p) |
| static int | BaseEfficiency (CPlayer *p) |
| static int | ExtraProduction (int type, CPlayer *p, int be) |
| static int | UniqueNeeds (int type, CPlayer *p) |
| static int | UniqueEfficiency (int type, CPlayer *p) |
| static int | MaxRate (CUnit *unit, int res) |
| static void | CalculateCosts (CUnit *unit, int costs[MaxCosts]) |
| void | SavePlayers (CFile *file) |
| Create a new player. | |
| void | CreatePlayer (int type) |
| Initialize the computer opponent AI. | |
| void | PlayersInitAi (void) |
| Called each game cycle for player handlers (AI). | |
| void | PlayersEachCycle (void) |
| Called each second for a given player handler (AI). | |
| void | PlayersEachSecond (int player) |
| Change current color set to new player of the sprite. | |
| void | GraphicPlayerPixels (CPlayer *player, const CGraphic *sprite) |
| Calculate how many resources the unit needs to request. | |
| void | SetPlayersPalette (void) |
| The SDL screen. | |
| void | DebugPlayers (void) |
| register ccl features | |
Variables | |
| int | NumPlayers |
| How many player slots used. | |
| CPlayer | Players [PlayerMax] |
| All players in play. | |
| CPlayer * | ThisPlayer |
| Player on this computer. | |
| int | NoRescueCheck |
| Disable rescue check. | |
| SDL_Color * | PlayerColorsRGB [PlayerMax] |
| Player colors. | |
| Uint32 * | PlayerColors [PlayerMax] |
| Player colors. | |
| std::string | PlayerColorNames [PlayerMax] |
| Player color names. | |
| int | PlayerColorIndexStart |
| int | PlayerColorIndexCount |
Definition in file player.cpp.
| static int AvailableResourcesRate | ( | int | type, | |
| CPlayer * | p | |||
| ) | [static] |
Definition at line 271 of file player.cpp.
References CPlayer::ProductionRate, and CPlayer::StoredResources.
Referenced by ExtraProduction(), and SpecificEfficiency().
| static int BaseEfficiency | ( | CPlayer * | p | ) | [static] |
Definition at line 289 of file player.cpp.
References EnergyCost, MagmaCost, and SpecificEfficiency().
Referenced by CalculateCosts(), and UniqueEfficiency().
| static void CalculateCosts | ( | CUnit * | unit, | |
| int | costs[MaxCosts] | |||
| ) | [static] |
Definition at line 330 of file player.cpp.
References Assert, BaseEfficiency(), MaxRate(), CUnit::Player, UniqueEfficiency(), and CPlayer::UnitsConsumingResourcesRequested.
Referenced by PlayersEachCycle().
| void CalculateRequestedAmount | ( | CUnitType * | utype, | |
| int | bcosts[MaxCosts], | |||
| int | costs[MaxCosts] | |||
| ) |
Output debug informations for players.
Calculate how many resources the unit needs to request
| utype | builder unit type | |
| bcosts | costs of unit type being built or harvested | |
| costs | returns the resource amount |
Definition at line 192 of file player.cpp.
References EnergyCost, MagmaCost, and CUnitType::MaxUtilizationRate.
Referenced by GatherResource(), HandleActionTrain(), MoveToLocation(), CPlayer::RebuildUnitsConsumingResourcesList(), and StartBuilding().
| void CleanPlayers | ( | void | ) |
Save players.
Clean up players.
Definition at line 105 of file player.cpp.
References CPlayer::Clear(), NoRescueCheck, NumPlayers, and PlayerMax.
Referenced by CleanModules(), StartEditor(), StartMap(), StartReplay(), and StartSavedGame().
| void CreatePlayer | ( | int | type | ) |
Initialize the computer opponent AI.
Create a new player.
| type | Player type (Computer,Human,...). |
Definition at line 490 of file player.cpp.
References _C_, CPlayer::AiEnabled, CPlayer::AiName, CPlayer::Allied, CPlayer::Color, DebugPrint, CPlayer::Enemy, CPlayer::Index, CPlayer::Name, NetLocalPlayerNumber, NetPlayers, CPlayer::NumBuildings, NumPlayers, PlayerColors, PlayerComputer, PlayerMax, PlayerNeutral, PlayerNobody, PlayerPerson, PlayerRescueActive, PlayerRescuePassive, CPlayer::Score, CPlayer::SetName(), CPlayer::Team, CPlayer::TotalNumUnits, CPlayer::Type, CPlayer::Units, and CPlayer::UnitTypesCount.
Referenced by CreateGame(), and CEditor::Init().
| void DebugPlayers | ( | void | ) |
register ccl features
Output debug informations for players.
Definition at line 865 of file player.cpp.
References _C_, CPlayer::AiEnabled, CPlayer::AiName, DebugPrint, CPlayer::Name, PlayerColorNames, PlayerMax, PlayerNobody, and CPlayer::Type.
Referenced by CreateGame().
| static int ExtraProduction | ( | int | type, | |
| CPlayer * | p, | |||
| int | be | |||
| ) | [static] |
Definition at line 295 of file player.cpp.
References AvailableResourcesRate(), and CPlayer::RequestedUtilizationRate.
Referenced by UniqueEfficiency().
Calculate how many resources the unit needs to request.
Change current color set to new player.
FIXME: use function pointer here.
| player | Pointer to player. | |
| sprite | The sprite in which the colors should be changed. |
Definition at line 833 of file player.cpp.
References Assert, CUnitColors::Colors, PlayerColorIndexCount, PlayerColorIndexStart, CGraphic::Surface, CGraphic::SurfaceFlip, and CPlayer::UnitColors.
Referenced by CPlayerColorGraphic::DrawPlayerColorFrameClip(), and CPlayerColorGraphic::DrawPlayerColorFrameClipX().
| void InitPlayers | ( | void | ) |
< Init players
Init players.
Definition at line 87 of file player.cpp.
References CPlayer::Index, CVideo::MapRGB(), PlayerColorIndexCount, PlayerColors, PlayerColorsRGB, PlayerMax, PlayerNobody, TheScreen, CPlayer::Type, CUnit::Type, and Video.
Referenced by CreateGame(), CEditor::Init(), InitModules(), and LoadStratagusMap().
| static int MaxRate | ( | CUnit * | unit, | |
| int | res | |||
| ) | [static] |
Definition at line 324 of file player.cpp.
References CUnit::Player, and CPlayer::UnitsConsumingResourcesRequested.
Referenced by CalculateCosts().
| void PlayersEachCycle | ( | void | ) |
Called each second for a given player handler (AI).
Handle AI of all players each game cycle.
Definition at line 772 of file player.cpp.
References CPlayer::ActualUtilizationRate, AiEachCycle(), CPlayer::AiEnabled, CalculateCosts(), MaxCosts, NumPlayers, CPlayer::ProductionRate, CPlayer::StorageCapacity, CPlayer::StoredResources, CPlayer::TotalResources, CPlayer::UnitsConsumingResourcesActual, and CPlayer::UpdateUnitsConsumingResources().
Referenced by GameMainLoop().
| void PlayersEachSecond | ( | int | player | ) |
Change current color set to new player of the sprite.
Handle AI of a player each second.
| player | the player to update AI |
Definition at line 818 of file player.cpp.
References AiEachSecond(), and CPlayer::AiEnabled.
Referenced by GameMainLoop().
| void PlayersInitAi | ( | void | ) |
Called each game cycle for player handlers (AI).
Initialize the Ai for all players.
Definition at line 760 of file player.cpp.
References CPlayer::AiEnabled, AiInit(), and NumPlayers.
Referenced by CreateGame().
| void SavePlayers | ( | CFile * | file | ) |
Create a new player.
Save state of players to file.
| file | Output file. |
Definition at line 368 of file player.cpp.
References CPlayer::AiEnabled, CPlayer::AiName, CPlayer::Allied, CPlayer::BuildingLimit, CPlayer::Color, DebugPrint, DefaultResourceNames, CPlayer::Enemy, CPlayer::Index, MaxCosts, CPlayer::Name, NumPlayers, PlayerComputer, PlayerMax, PlayerNeutral, PlayerNobody, PlayerPerson, PlayerRescueActive, PlayerRescuePassive, CFile::printf(), CPlayer::ProductionRate, CPlayer::Score, CPlayer::SharedVision, CPlayer::StartX, CPlayer::StartY, CPlayer::StorageCapacity, CPlayer::StoredResources, CPlayer::Team, TheScreen, CPlayer::TotalBuildings, CPlayer::TotalKills, CPlayer::TotalRazings, CPlayer::TotalResources, CPlayer::TotalUnitLimit, CPlayer::TotalUnits, CPlayer::Type, and CPlayer::UnitLimit.
Referenced by SaveGame().
| void SetPlayersPalette | ( | void | ) |
The SDL screen.
Setup the player colors for the current palette.
Definition at line 852 of file player.cpp.
References CUnitColors::Colors, PlayerColorIndexCount, PlayerColorsRGB, PlayerMax, and CPlayer::UnitColors.
Referenced by CclNewPlayerColors(), CreateGame(), and LoadModules().
| static int SpecificEfficiency | ( | int | type, | |
| CPlayer * | p | |||
| ) | [static] |
Definition at line 279 of file player.cpp.
References AvailableResourcesRate(), and CPlayer::RequestedUtilizationRate.
Referenced by BaseEfficiency().
| static int UniqueEfficiency | ( | int | type, | |
| CPlayer * | p | |||
| ) | [static] |
Definition at line 318 of file player.cpp.
References BaseEfficiency(), ExtraProduction(), and UniqueNeeds().
Referenced by CalculateCosts().
| static int UniqueNeeds | ( | int | type, | |
| CPlayer * | p | |||
| ) | [static] |
Definition at line 301 of file player.cpp.
References EnergyCost, MagmaCost, and CPlayer::UnitsConsumingResourcesRequested.
Referenced by UniqueEfficiency().
| int NoRescueCheck |
Disable rescue check.
Definition at line 64 of file player.cpp.
Referenced by CleanPlayers(), and RescueUnits().
| int NumPlayers |
How many player slots used.
Definition at line 60 of file player.cpp.
Referenced by CclAiDebugPlayer(), CclPlayer(), CleanPlayers(), CommandQuit(), CreatePlayer(), GameMainLoop(), LoadGame(), main1(), NetworkEvent(), NetworkExecCommands(), PlayersEachCycle(), PlayersInitAi(), RescueUnits(), and SavePlayers().
Definition at line 78 of file player.cpp.
Referenced by CclDefinePlayerColorIndex(), CclDefinePlayerColors(), GraphicPlayerPixels(), InitPlayers(), MakeTextures2(), and SetPlayersPalette().
Which indexes to replace with player color
Definition at line 77 of file player.cpp.
Referenced by CclDefinePlayerColorIndex(), GraphicPlayerPixels(), and MakeTextures2().
| std::string PlayerColorNames[PlayerMax] |
Player color names.
Definition at line 72 of file player.cpp.
Referenced by CclDefinePlayerColors(), DebugPlayers(), and InputKey().
| Uint32* PlayerColors[PlayerMax] |
Player colors.
Definition at line 70 of file player.cpp.
Referenced by CclDefinePlayerColorIndex(), CreatePlayer(), and InitPlayers().
| SDL_Color* PlayerColorsRGB[PlayerMax] |
Player colors.
Colors used for minimap.
Definition at line 69 of file player.cpp.
Referenced by CclDefinePlayerColorIndex(), CclDefinePlayerColors(), InitPlayers(), and SetPlayersPalette().
All players in play.
All players.
Definition at line 61 of file player.cpp.
Referenced by Polymorph::Cast(), SpawnPortal::Cast(), CclAiDebugPlayer(), CclChangeUnitsOwner(), CclCreateUnit(), CclDefineAiPlayer(), CclDefineAllow(), CclDefineUnitAllow(), CclGetUnits(), CclKillUnit(), CclPlayer(), CclSetAllPlayersBuildingLimit(), CclSetAllPlayersTotalUnitLimit(), CclSetAllPlayersUnitLimit(), CclUnit(), CleanAi(), CommandDiplomacy(), CommandQuit(), CommandSharedVision(), DrawEditorPanel(), DrawInfoPanelNoneSelected(), CPlayerColorGraphic::DrawPlayerColorFrameClip(), CPlayerColorGraphic::DrawPlayerColorFrameClipX(), DrawPlayers(), DrawStartLocations(), DrawUnitIcons(), DrawUnitSelection(), EditorActionPlaceUnit(), EditorCallbackButtonDown(), EditorCallbackKeyDown(), EditorCallbackMouse(), GameTypeLeftVsRight(), GameTypeManTeamVsMachine(), GameTypeManVsMachine(), GameTypeTopVsBottom(), GetNumOpponents(), CEditor::Init(), InputKey(), IsTileRadarVisible(), CMap::IsTileVisible(), CUnit::IsVisible(), LoadGame(), MakePlayerColorTexture(), NetworkConnectSetupGame(), NetworkEvent(), NetworkProcessSelection(), NetworkSendSelection(), ReplayEachCycle(), RescueUnits(), CMap::Reveal(), SaveAiPlayers(), SaveUpgrades(), StartReplay(), tolua_get_stratagus_Players(), tolua_set_stratagus_Players(), UnitCountSeen(), UnitLost(), UnitsOnTileMarkSeen(), UnitsOnTileUnmarkSeen(), and WriteMapSetup().
Player on this computer.
Player on local computer.
Definition at line 62 of file player.cpp.
Referenced by AddToGroup(), AiRemoveFromBuilt(), CclAiDebugPlayer(), CclDiplomacy(), CclSharedVision(), CommandCancelTraining(), CommandLog(), CreateGame(), DoActionMove(), CButtonPanel::DoClicked(), DoNextReplay(), DoRightButton(), CUnit::Draw(), DrawBuildingCursor(), DrawDecoration(), DrawInfoPanelMultipleSelected(), DrawInfoPanelNoneSelected(), DrawInformations(), CViewport::DrawMapFogOfWar(), DrawResources(), DrawUnitInfo(), DrawUnitOn(), DrawUnitSelection(), EditorCallbackButtonDown(), HandleActionBuilt(), HandleActionTrain(), HandleCheats(), HitUnit(), CEditor::Init(), InputKey(), CUnit::IsVisibleInViewport(), CUnit::IsVisibleOnMinimap(), LoadStratagusMap(), main1(), MissileVisibleInViewport(), NetworkChatMessage(), NetworkConnectSetupGame(), NetworkEvent(), NetworkQuit(), NetworkSendCommands(), NetworkSendSelection(), SaveReplay(), SelectUnitsInRectangle(), SendRepair(), StartReplay(), tolua_get_ThisPlayer_ptr(), tolua_set_ThisPlayer_ptr(), TriggerGetPlayer(), UiFindIdleWorker(), UIHandleButtonDown(), UIHandleButtonUp(), UIHandleMouseMove(), UnitActions(), UnitGoesUnderFog(), UnitOnScreen(), UnitShowAnimationScaled(), CMinimap::Update(), and CButtonPanel::Update().
1.5.6