OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Player.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Player data at runtime */
19 
20 #ifndef INC_C4Player
21 #define INC_C4Player
22 
23 #include "gui/C4MainMenu.h"
25 #include "object/C4InfoCore.h"
26 #include "object/C4ObjectList.h"
27 #include "object/C4ObjectPtr.h"
29 #include "script/C4Value.h"
30 #include <set>
31 #include <memory>
32 
33 const int32_t C4PVM_Cursor = 0,
36 
37 const int32_t C4P_Number_None = -5;
38 
39 const int32_t C4MaxPlayer = 5000; // ought to be enough for everybody (used to catch invalid player counts)
40 const int32_t C4MaxClient = 5000; // ought to be enough for everybody (used to catch invalid client counts)
41 
42 // view ranges in "CR-pixels" covered by viewport
43 static const int C4VP_DefViewRangeX = 300,
44  C4VP_DefMinViewRangeX = 150,
45  C4VP_DefMaxViewRangeX = 750;
46 
47 static const int C4FOW_DefLightRangeX = 300,
48  C4FOW_DefLightFadeoutRangeX = 80;
49 
51 {
52  class HostilitySet : public std::set<const C4Player*>
53  {
54  public:
55  void CompileFunc(StdCompiler *pComp);
56  };
57 
58 public:
59  // possible player controls used for statistics
61  {
62  PCID_None, // no control
63  PCID_Message, // chat
64  PCID_Special, // goalruleinfo, etc.
65  PCID_Command, // mouse control
66  PCID_DirectCom // menu or keyboard control
67  };
68  // possible status
70  {
71  PS_None=0, // player disabled
72  PS_Normal=1, // normal playing
73  PS_TeamSelection = 2, // team selection
74  PS_TeamSelectionPending = 3 // waiting for team selection packet to come through
75  };
76  friend class C4PlayerList;
77 
78 public:
79  C4Player();
80  ~C4Player();
81 public:
84  int32_t Status;
85  int32_t Eliminated;
86  int32_t Surrendered;
87  bool Evaluated;
88  int32_t Number;
89  int32_t ID; // unique player ID
90  int32_t Team; // team ID - may be 0 for no teams
91  uint32_t ColorDw;
94  int32_t MouseControl;
95  int32_t Position;
96  int32_t PlrStartIndex;
97  int32_t RetireDelay;
98  int32_t GameJoinTime; // Local-NoSave - set in Init; reset in LocalSync
99  int32_t AtClient;
101  bool LocalControl; // Local-NoSave //
102  bool LeagueEvaluated; // Local-NoSave //
103  bool NoEliminationCheck; // Local-NoSave. Always set in init and restore by info //
104  // Menu
105  C4MainMenu Menu; // Local-NoSave //
106  // View
107  int32_t ViewMode;
108  C4Real ViewX,ViewY; // FIXED because this is saved/synchronized
109  bool ViewLock; // if set, no scrolling is allowed
110  C4Object *ViewTarget; // NoSave //
112  int32_t FlashCom; // NoSave //
113  bool fFogOfWar;
114  int32_t ZoomLimitMinWdt,ZoomLimitMinHgt,ZoomLimitMaxWdt,ZoomLimitMaxHgt,ZoomWdt,ZoomHgt; // zoom limits and last zoom set by script
116  // Game
117  int32_t Wealth;
119  int32_t ObjectsOwned;
120  HostilitySet Hostility;
121  // Home Base
125  // Crew
127  C4ObjectList Crew; // Save new in 4.95.2 (for sync reasons)
128  // Knowledge
130  // Control
133  int32_t CursorFlash;
134  std::shared_ptr<class C4GamePadOpener> pGamepad;
135  // Message
136  int32_t MessageStatus;
137  char MessageBuf[256+1];
139  // BigIcon
141  // Sound
143  // Dynamic list
145 
146  // statistics
148  int32_t ControlCount; // controls issued since value was last recorded
149  int32_t ActionCount; // non-doubled controls since value was last recorded
150  ControlType LastControlType; int32_t LastControlID; // last control to capture perma-pressers in stats
151 
152 public:
153  const char *GetName() const { return Name.getData(); }
154  C4PlayerType GetType() const;
155 
156 public:
157  void Eliminate();
158  void ClearPointers(C4Object *tptr, bool fDeath);
159  void Execute();
160  void ExecuteControl();
161  void SetViewMode(int32_t iMode, C4Object *pTarget=nullptr, bool immediate_position=false);
162  void ResetCursorView(bool immediate_position = false); // reset view to cursor if any cursor exists
163  void Evaluate();
164  void Surrender();
165  void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt); // in landscape coordinates
166  void SetCursor(C4Object *pObj, bool fSelectArrow);
167  void RemoveCrewObjects();
168  int32_t FindNewOwner() const;
169  void NotifyOwnedObjects();
170  void DefaultRuntimeData();
171  void DrawHostility(C4Facet &cgo, int32_t iIndex);
172  void AdjustCursorCommand();
173 
174  bool DoScore(int32_t iChange);
175  bool Init(int32_t iNumber, int32_t iAtClient, const char *szAtClientName, const char *szFilename, bool fScenarioInit, class C4PlayerInfo *pInfo, C4ValueNumbers *);
176  bool ScenarioAndTeamInit(int32_t idTeam);
177  bool ScenarioInit();
178  bool FinalInit(bool fInitialScore);
179  bool Save();
180  bool Save(C4Group &hGroup, bool fSavegame, bool fStoreTiny);
181  bool MakeCrewMember(C4Object *pObj, bool fForceInfo=true, bool fDoCalls=true);
182  bool Load(const char *szFilename, bool fSavegame);
183  static bool Strip(const char *szFilename, bool fAggressive);
184  bool Message(const char *szMsg);
185  bool ObjectInCrew(C4Object *tobj);
186  bool DoWealth(int32_t change);
187  bool SetWealth(int32_t val);
188  bool SetKnowledge(C4ID id, bool fRemove);
189  bool SetHostility(int32_t iOpponent, int32_t iHostility, bool fSilent=false);
190  bool IsHostileTowards(const C4Player *opponent) const;
191  void CompileFunc(StdCompiler *pComp, C4ValueNumbers *);
192  void DenumeratePointers();
193  bool LoadRuntimeData(C4Group &hGroup, C4ValueNumbers *);
194  bool ActivateMenuMain();
195  bool ActivateMenuTeamSelection(bool fFromMain);
196  void DoTeamSelection(int32_t idTeam);
199  void SetFoW(bool fEnable);
200  int32_t ActiveCrewCount();
201  int32_t GetSelectedCrewCount();
202  bool LocalSync(); // sync InAction et. al. back o local player file
203  bool SetObjectCrewStatus(C4Object *pCrew, bool fNewStatus); // add/remove object from crew
204  bool IsChosingTeam() const { return Status==PS_TeamSelection || Status==PS_TeamSelectionPending; }
205  bool IsInvisible() const;
206  bool IsViewLocked() const { return ViewLock; } // return if view is fixed to cursor, so scrolling is not allowed
207  void SetViewLocked(bool to_val); // lock or unlock free scrolling for player
208  void SetSoundModifier(C4PropList *new_modifier); // set modifier to be applied to all new sounds being played in a player's viewport
209 
210 protected:
211  void ClearControl();
212  void InitControl();
213  void UpdateView();
214  void CheckElimination();
215  void ExecBaseProduction();
216  void PlaceReadyBase(int32_t &tx, int32_t &ty, C4Object **pFirstBase);
217  void PlaceReadyVehic(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase);
218  void PlaceReadyMaterial(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase);
219  void PlaceReadyCrew(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase);
220  void CheckCrewExPromotion();
221 
222 public:
223  void SetTeamHostility(); // if Team!=0: Set hostile to all players in other teams and allied to all others (both ways)
224 
225  void CloseMenu(); // close all player menus (keep sync object menus!)
226 
227  void EvaluateLeague(bool fDisconnected, bool fWon);
228 
229  // runtime statistics
230  void CreateGraphs();
231  void ClearGraphs();
232  void CountControl(ControlType eType, int32_t iID, int32_t iCntAdd=1);
233 
234  class C4PlayerInfo *GetInfo(); // search info by ID
235 
236 private:
237  // messageboard-calls for this player
238  class C4MessageBoardQuery *GetMessageboardQuery(C4Object *pForObj);
239  void ExecMsgBoardQueries();
240 public:
241  void ToggleMouseControl();
242  void CallMessageBoard(C4Object *pForObj, const StdStrBuf &sQueryString, bool fUppercase);
243  bool RemoveMessageBoardQuery(C4Object *pForObj);
245  bool HasMessageBoardQuery(); // return whether any object has a messageboard-query
246 
247  // callback by script execution of team selection: Restart team selection if the team turned out to be not available
248  void OnTeamSelectionFailed();
249 
250  // when the player changes team, his color changes. Relfect this in player objects
251  void SetPlayerColor(uint32_t dwNewClr);
252 
253  // zoom and zoom limit changes
254  void SetZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool direct, bool no_increase, bool no_decrease);
255  void SetMinZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease);
256  void SetMaxZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease);
257  void SetZoom(C4Fixed zoom, bool direct, bool no_increase, bool no_decrease);
258  void SetMinZoom(C4Fixed zoom, bool no_increase, bool no_decrease);
259  void SetMaxZoom(C4Fixed zoom, bool no_increase, bool no_decrease);
260  void ZoomToViewports(bool direct, bool no_increase=false, bool no_decrease=false);
261  void ZoomToViewport(C4Viewport* vp, bool direct, bool no_increase=false, bool no_decrease=false);
262  void ZoomLimitsToViewports();
264 
265 private:
266  bool AdjustZoomParameter(int32_t *range_par, int32_t new_val, bool no_increase, bool no_decrease);
267  bool AdjustZoomParameter(C4Fixed *zoom_par, C4Fixed new_val, bool no_increase, bool no_decrease);
268 
269  // Finds a new gamepad to use, returning true on success.
270  bool FindGamepad();
271 
272 public:
273  // custom scenario achievements
274  bool GainScenarioAchievement(const char *achievement_id, int32_t value, const char *scen_name_override=nullptr);
275 };
276 
277 #endif
bool IsHostileTowards(const C4Player *opponent) const
Definition: C4Player.cpp:864
const int32_t C4PVM_Scrolling
Definition: C4Player.h:35
const char * getData() const
Definition: StdBuf.h:450
class C4PlayerInfo * GetInfo()
Definition: C4Player.cpp:1555
void SetFoW(bool fEnable)
Definition: C4Player.cpp:727
void CloseMenu()
Definition: C4Player.cpp:1470
int32_t MouseControl
Definition: C4Player.h:94
const size_t C4MaxTitle
Definition: C4Constants.h:25
char AtClientName[C4MaxTitle+1]
Definition: C4Player.h:100
int32_t LastControlID
Definition: C4Player.h:150
int32_t Team
Definition: C4Player.h:90
C4ObjectPtr Cursor
Definition: C4Player.h:132
int32_t ProductionDelay
Definition: C4Player.h:124
bool MakeCrewMember(C4Object *pObj, bool fForceInfo=true, bool fDoCalls=true)
Definition: C4Player.cpp:1012
C4MainMenu Menu
Definition: C4Player.h:105
bool HasMessageBoardQuery()
Definition: C4Player.cpp:1701
void CheckCrewExPromotion()
Definition: C4Player.cpp:909
bool ViewLock
Definition: C4Player.h:109
int32_t ViewMode
Definition: C4Player.h:107
int32_t ControlCount
Definition: C4Player.h:148
int32_t Number
Definition: C4Player.h:88
int32_t FlashCom
Definition: C4Player.h:112
void ZoomLimitsToViewport(C4Viewport *vp)
Definition: C4Player.cpp:1862
C4Player()
Definition: C4Player.cpp:49
bool IsInvisible() const
Definition: C4Player.cpp:1737
int32_t ActiveCrewCount()
Definition: C4Player.cpp:1500
class C4TableGraph * pstatActions
Definition: C4Player.h:147
char Filename[_MAX_PATH+1]
Definition: C4Player.h:82
bool IsChosingTeam() const
Definition: C4Player.h:204
void Eliminate()
Definition: C4Player.cpp:1476
int32_t ObjectsOwned
Definition: C4Player.h:119
const int32_t C4MaxClient
Definition: C4Player.h:40
void ToggleMouseControl()
Definition: C4Player.cpp:1744
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *)
Definition: C4Player.cpp:1078
StatusTypes
Definition: C4Player.h:69
void ClearControl()
Definition: C4Player.cpp:1377
bool ShowStartup
Definition: C4Player.h:111
void UpdateView()
Definition: C4Player.cpp:1184
bool ScenarioAndTeamInit(int32_t idTeam)
Definition: C4Player.cpp:120
ControlType LastControlType
Definition: C4Player.h:150
bool Load(const char *szFilename, bool fSavegame)
Definition: C4Player.cpp:941
int32_t ZoomLimitMinHgt
Definition: C4Player.h:114
int32_t GetSelectedCrewCount()
Definition: C4Player.cpp:1512
C4PlayerControl Control
Definition: C4Player.h:131
int32_t PlrStartIndex
Definition: C4Player.h:96
bool IsViewLocked() const
Definition: C4Player.h:206
#define _MAX_PATH
int32_t Position
Definition: C4Player.h:95
void SetCursor(C4Object *pObj, bool fSelectArrow)
Definition: C4Player.cpp:1352
void SetZoom(C4Fixed zoom, bool direct, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1821
void ZoomLimitsToViewports()
Definition: C4Player.cpp:1855
int32_t ProductionUnit
Definition: C4Player.h:124
void DrawHostility(C4Facet &cgo, int32_t iIndex)
Definition: C4Player.cpp:999
StdStrBuf Name
Definition: C4Player.h:83
void ZoomToViewport(C4Viewport *vp, bool direct, bool no_increase=false, bool no_decrease=false)
Definition: C4Player.cpp:1846
int32_t ZoomLimitMaxWdt
Definition: C4Player.h:114
void ClearPointers(C4Object *tptr, bool fDeath)
Definition: C4Player.cpp:100
void DenumeratePointers()
Definition: C4Player.cpp:1262
char MessageBuf[256+1]
Definition: C4Player.h:137
bool ActivateMenuTeamSelection(bool fFromMain)
Definition: C4Player.cpp:1242
std::shared_ptr< class C4GamePadOpener > pGamepad
Definition: C4Player.h:134
Definition: C4Real.h:58
bool FinalInit(bool fInitialScore)
Definition: C4Player.cpp:703
uint32_t ColorDw
Definition: C4Player.h:91
int32_t CursorFlash
Definition: C4Player.h:133
void CallMessageBoard(C4Object *pForObj, const StdStrBuf &sQueryString, bool fUppercase)
Definition: C4Player.cpp:1667
int32_t ZoomWdt
Definition: C4Player.h:114
void OnTeamSelectionFailed()
Definition: C4Player.cpp:1707
const int32_t C4P_Number_None
Definition: C4Player.h:37
class C4PlayerControlAssignmentSet * ControlSet
Definition: C4Player.h:92
static bool Strip(const char *szFilename, bool fAggressive)
Definition: C4Player.cpp:961
~C4Player()
Definition: C4Player.cpp:78
bool LoadRuntimeData(C4Group &hGroup, C4ValueNumbers *)
Definition: C4Player.cpp:1136
bool Message(const char *szMsg)
Definition: C4Player.cpp:933
void NotifyOwnedObjects()
Definition: C4Player.cpp:1315
void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt)
Definition: C4Player.cpp:1368
int32_t Status
Definition: C4Player.h:84
C4Object * GetHiRankActiveCrew()
Definition: C4Player.cpp:890
ControlType
Definition: C4Player.h:60
void CreateGraphs()
Definition: C4Player.cpp:1591
C4IDList Knowledge
Definition: C4Player.h:129
void SetZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool direct, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1800
int32_t FindNewOwner() const
Definition: C4Player.cpp:1283
void SetViewMode(int32_t iMode, C4Object *pTarget=nullptr, bool immediate_position=false)
Definition: C4Player.cpp:771
void Execute()
Definition: C4Player.cpp:164
C4FacetSurface BigIcon
Definition: C4Player.h:140
class C4TableGraph * pstatControls
Definition: C4Player.h:147
void SetPlayerColor(uint32_t dwNewClr)
Definition: C4Player.cpp:1714
void SetMaxZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1814
bool SetObjectCrewStatus(C4Object *pCrew, bool fNewStatus)
Definition: C4Player.cpp:1560
bool DoWealth(int32_t change)
Definition: C4Player.cpp:733
C4Object * GetHiExpActiveCrew()
Definition: C4Player.cpp:871
int32_t MessageStatus
Definition: C4Player.h:136
void SetViewLocked(bool to_val)
Definition: C4Player.cpp:1901
bool SetKnowledge(C4ID id, bool fRemove)
Definition: C4Player.cpp:756
int32_t GameJoinTime
Definition: C4Player.h:98
bool Evaluated
Definition: C4Player.h:87
Definition: C4Id.h:28
C4PlayerType
Definition: C4Constants.h:152
int32_t Surrendered
Definition: C4Player.h:86
C4ObjectList Crew
Definition: C4Player.h:127
const int32_t C4MaxPlayer
Definition: C4Player.h:39
int32_t Eliminated
Definition: C4Player.h:85
C4Value SoundModifier
Definition: C4Player.h:142
void PlaceReadyCrew(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
Definition: C4Player.cpp:481
void PlaceReadyBase(int32_t &tx, int32_t &ty, C4Object **pFirstBase)
Definition: C4Player.cpp:531
int32_t CurrentScore
Definition: C4Player.h:118
void SetMinZoom(C4Fixed zoom, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1827
bool ActivateMenuMain()
Definition: C4Player.cpp:1764
bool ScenarioInit()
Definition: C4Player.cpp:605
int32_t Wealth
Definition: C4Player.h:117
void CheckElimination()
Definition: C4Player.cpp:1172
void Evaluate()
Definition: C4Player.cpp:791
void DoTeamSelection(int32_t idTeam)
Definition: C4Player.cpp:1254
int32_t ZoomLimitMinWdt
Definition: C4Player.h:114
int32_t AtClient
Definition: C4Player.h:99
bool NoEliminationCheck
Definition: C4Player.h:103
int32_t ID
Definition: C4Player.h:89
int32_t ZoomLimitMaxHgt
Definition: C4Player.h:114
const char * GetName() const
Definition: C4Player.h:153
C4Fixed ZoomLimitMinVal
Definition: C4Player.h:115
void EvaluateLeague(bool fDisconnected, bool fWon)
Definition: C4Player.cpp:1519
C4Real ViewY
Definition: C4Player.h:108
void CountControl(ControlType eType, int32_t iID, int32_t iCntAdd=1)
Definition: C4Player.cpp:1635
StdCopyStrBuf ControlSetName
Definition: C4Player.h:93
void SetTeamHostility()
Definition: C4Player.cpp:919
bool DoScore(int32_t iChange)
Definition: C4Player.cpp:1346
void ResetCursorView(bool immediate_position=false)
Definition: C4Player.cpp:784
bool LeagueEvaluated
Definition: C4Player.h:102
void ExecuteControl()
Definition: C4Player.cpp:1058
C4Player * Next
Definition: C4Player.h:144
void InitControl()
Definition: C4Player.cpp:1397
C4Fixed ZoomLimitMaxVal
Definition: C4Player.h:115
void Surrender()
Definition: C4Player.cpp:832
C4ObjectInfoList CrewInfoList
Definition: C4Player.h:126
int32_t InitialScore
Definition: C4Player.h:118
void ClearGraphs()
Definition: C4Player.cpp:1618
int32_t RetireDelay
Definition: C4Player.h:97
void AdjustCursorCommand()
Definition: C4Player.cpp:1063
const int32_t C4PVM_Target
Definition: C4Player.h:34
void PlaceReadyVehic(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
Definition: C4Player.cpp:556
C4Object * ViewTarget
Definition: C4Player.h:110
void SetMinZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1807
bool Save()
Definition: C4Player.cpp:417
const int32_t C4PVM_Cursor
Definition: C4Player.h:33
void RemoveCrewObjects()
Definition: C4Player.cpp:1275
bool SetWealth(int32_t val)
Definition: C4Player.cpp:745
int32_t ZoomHgt
Definition: C4Player.h:114
bool fFogOfWar
Definition: C4Player.h:113
C4ObjectPtr ViewCursor
Definition: C4Player.h:132
bool GainScenarioAchievement(const char *achievement_id, int32_t value, const char *scen_name_override=nullptr)
Definition: C4Player.cpp:1910
void DefaultRuntimeData()
Definition: C4Player.cpp:1210
C4IDList BaseMaterial
Definition: C4Player.h:122
bool ObjectInCrew(C4Object *tobj)
Definition: C4Player.cpp:92
C4Fixed ZoomVal
Definition: C4Player.h:115
class C4MessageBoardQuery * pMsgBoardQuery
Definition: C4Player.h:138
int32_t ActionCount
Definition: C4Player.h:149
bool Init(int32_t iNumber, int32_t iAtClient, const char *szAtClientName, const char *szFilename, bool fScenarioInit, class C4PlayerInfo *pInfo, C4ValueNumbers *)
Definition: C4Player.cpp:259
void ZoomToViewports(bool direct, bool no_increase=false, bool no_decrease=false)
Definition: C4Player.cpp:1839
void SetSoundModifier(C4PropList *new_modifier)
Definition: C4Player.cpp:1926
bool MarkMessageBoardQueryAnswered(C4Object *pForObj)
Definition: C4Player.cpp:1690
void PlaceReadyMaterial(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
Definition: C4Player.cpp:577
void SetMaxZoom(C4Fixed zoom, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1833
C4IDList BaseProduction
Definition: C4Player.h:123
bool SetHostility(int32_t iOpponent, int32_t iHostility, bool fSilent=false)
Definition: C4Player.cpp:842
bool LocalSync()
Definition: C4Player.cpp:1534
void ExecBaseProduction()
Definition: C4Player.cpp:1157
bool RemoveMessageBoardQuery(C4Object *pForObj)
Definition: C4Player.cpp:1677
bool LocalControl
Definition: C4Player.h:101
C4Real ViewX
Definition: C4Player.h:108
HostilitySet Hostility
Definition: C4Player.h:120
C4PlayerType GetType() const
Definition: C4Player.cpp:1730