OpenClonk
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 
24 #include "gui/C4MainMenu.h"
25 #include "object/C4InfoCore.h"
27 #include "object/C4ObjectList.h"
28 #include "object/C4ObjectPtr.h"
29 #include "script/C4Value.h"
30 
31 const int32_t C4PVM_Cursor = 0,
34 
35 const int32_t C4P_Number_None = -5;
36 
37 const int32_t C4MaxPlayer = 5000; // ought to be enough for everybody (used to catch invalid player counts)
38 const int32_t C4MaxClient = 5000; // ought to be enough for everybody (used to catch invalid client counts)
39 
40 // view ranges in "CR-pixels" covered by viewport
41 static const int C4VP_DefViewRangeX = 300,
42  C4VP_DefMinViewRangeX = 150,
43  C4VP_DefMaxViewRangeX = 750;
44 
45 static const int C4FOW_DefLightRangeX = 300,
46  C4FOW_DefLightFadeoutRangeX = 80;
47 
49 {
50  class HostilitySet : public std::set<const C4Player*>
51  {
52  public:
53  void CompileFunc(StdCompiler *pComp);
54  };
55 
56 public:
57  // possible player controls used for statistics
59  {
60  PCID_None, // no control
61  PCID_Message, // chat
62  PCID_Special, // goalruleinfo, etc.
63  PCID_Command, // mouse control
64  PCID_DirectCom // menu or keyboard control
65  };
66  // possible status
68  {
69  PS_None=0, // player disabled
70  PS_Normal=1, // normal playing
71  PS_TeamSelection = 2, // team selection
72  PS_TeamSelectionPending = 3 // waiting for team selection packet to come through
73  };
74  friend class C4PlayerList;
75 
76 public:
77  C4Player();
78  ~C4Player();
79 public:
82  int32_t Status;
83  int32_t Eliminated;
84  int32_t Surrendered;
85  bool Evaluated;
86  int32_t Number;
87  int32_t ID; // unique player ID
88  int32_t Team; // team ID - may be 0 for no teams
89  uint32_t ColorDw;
92  int32_t MouseControl;
93  int32_t Position;
94  int32_t PlrStartIndex;
95  int32_t RetireDelay;
96  int32_t GameJoinTime; // Local-NoSave - set in Init; reset in LocalSync
97  int32_t AtClient;
99  bool LocalControl; // Local-NoSave //
100  bool LeagueEvaluated; // Local-NoSave //
101  bool NoEliminationCheck; // Local-NoSave. Always set in init and restore by info //
102  // Menu
103  C4MainMenu Menu; // Local-NoSave //
104  // View
105  int32_t ViewMode;
106  C4Real ViewX,ViewY; // FIXED because this is saved/synchronized
107  bool ViewLock; // if set, no scrolling is allowed
108  C4Object *ViewTarget; // NoSave //
110  int32_t FlashCom; // NoSave //
111  bool fFogOfWar;
112  int32_t ZoomLimitMinWdt,ZoomLimitMinHgt,ZoomLimitMaxWdt,ZoomLimitMaxHgt,ZoomWdt,ZoomHgt; // zoom limits and last zoom set by script
114  // Game
115  int32_t Wealth;
117  int32_t ObjectsOwned;
118  HostilitySet Hostility;
119  // Home Base
123  // Crew
125  C4ObjectList Crew; // Save new in 4.95.2 (for sync reasons)
126  // Knowledge
128  // Control
131  int32_t CursorFlash;
132  std::shared_ptr<class C4GamePadOpener> pGamepad;
133  // Message
134  int32_t MessageStatus;
135  char MessageBuf[256+1];
137  // BigIcon
139  // Sound
141  // Dynamic list
143 
144  // statistics
146  int32_t ControlCount; // controls issued since value was last recorded
147  int32_t ActionCount; // non-doubled controls since value was last recorded
148  ControlType LastControlType; int32_t LastControlID; // last control to capture perma-pressers in stats
149 
150 public:
151  const char *GetName() const { return Name.getData(); }
152  C4PlayerType GetType() const;
153 
154 public:
155  void Eliminate();
156  void ClearPointers(C4Object *tptr, bool fDeath);
157  void Execute();
158  void ExecuteControl();
159  void SetViewMode(int32_t iMode, C4Object *pTarget=nullptr, bool immediate_position=false);
160  void ResetCursorView(bool immediate_position = false); // reset view to cursor if any cursor exists
161  void Evaluate();
162  void Surrender();
163  void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt); // in landscape coordinates
164  void SetCursor(C4Object *pObj, bool fSelectArrow);
165  void RemoveCrewObjects();
166  int32_t FindNewOwner() const;
167  void NotifyOwnedObjects();
168  void DefaultRuntimeData();
169  void DrawHostility(C4Facet &cgo, int32_t iIndex);
170  void AdjustCursorCommand();
171 
172  bool DoScore(int32_t iChange);
173  bool Init(int32_t iNumber, int32_t iAtClient, const char *szAtClientName, const char *szFilename, bool fScenarioInit, class C4PlayerInfo *pInfo, C4ValueNumbers *);
174  bool ScenarioAndTeamInit(int32_t idTeam);
175  bool ScenarioInit();
176  bool FinalInit(bool fInitialScore);
177  bool Save();
178  bool Save(C4Group &hGroup, bool fSavegame, bool fStoreTiny);
179  bool MakeCrewMember(C4Object *pObj, bool fForceInfo=true, bool fDoCalls=true);
180  bool Load(const char *szFilename, bool fSavegame);
181  static bool Strip(const char *szFilename, bool fAggressive);
182  bool Message(const char *szMsg);
183  bool ObjectInCrew(C4Object *tobj);
184  bool DoWealth(int32_t change);
185  bool SetWealth(int32_t val);
186  bool SetKnowledge(C4ID id, bool fRemove);
187  bool SetHostility(int32_t iOpponent, int32_t iHostility, bool fSilent=false);
188  bool IsHostileTowards(const C4Player *opponent) const;
189  void CompileFunc(StdCompiler *pComp, C4ValueNumbers *);
190  void DenumeratePointers();
191  bool LoadRuntimeData(C4Group &hGroup, C4ValueNumbers *);
192  bool ActivateMenuMain();
193  bool ActivateMenuTeamSelection(bool fFromMain);
194  void DoTeamSelection(int32_t idTeam);
197  void SetFoW(bool fEnable);
198  int32_t ActiveCrewCount();
199  int32_t GetSelectedCrewCount();
200  bool LocalSync(); // sync InAction et. al. back o local player file
201  bool SetObjectCrewStatus(C4Object *pCrew, bool fNewStatus); // add/remove object from crew
203  bool IsInvisible() const;
204  bool IsViewLocked() const { return ViewLock; } // return if view is fixed to cursor, so scrolling is not allowed
205  void SetViewLocked(bool to_val); // lock or unlock free scrolling for player
206  void SetSoundModifier(C4PropList *new_modifier); // set modifier to be applied to all new sounds being played in a player's viewport
207 
208 protected:
209  void ClearControl();
210  void InitControl();
211  void UpdateView();
212  void CheckElimination();
213  void ExecBaseProduction();
214  void PlaceReadyBase(int32_t &tx, int32_t &ty, C4Object **pFirstBase);
215  void PlaceReadyVehic(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase);
216  void PlaceReadyMaterial(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase);
217  void PlaceReadyCrew(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase);
218  void CheckCrewExPromotion();
219 
220 public:
221  void SetTeamHostility(); // if Team!=0: Set hostile to all players in other teams and allied to all others (both ways)
222 
223  void CloseMenu(); // close all player menus (keep sync object menus!)
224 
225  void EvaluateLeague(bool fDisconnected, bool fWon);
226 
227  // runtime statistics
228  void CreateGraphs();
229  void ClearGraphs();
230  void CountControl(ControlType eType, int32_t iID, int32_t iCntAdd=1);
231 
232  class C4PlayerInfo *GetInfo(); // search info by ID
233 
234 private:
235  // messageboard-calls for this player
236  class C4MessageBoardQuery *GetMessageboardQuery(C4Object *pForObj);
237  void ExecMsgBoardQueries();
238 public:
239  void ToggleMouseControl();
240  void CallMessageBoard(C4Object *pForObj, const StdStrBuf &sQueryString, bool fUppercase);
241  bool RemoveMessageBoardQuery(C4Object *pForObj);
243  bool HasMessageBoardQuery(); // return whether any object has a messageboard-query
244 
245  // callback by script execution of team selection: Restart team selection if the team turned out to be not available
246  void OnTeamSelectionFailed();
247 
248  // when the player changes team, his color changes. Relfect this in player objects
249  void SetPlayerColor(uint32_t dwNewClr);
250 
251  // zoom and zoom limit changes
252  void SetZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool direct, bool no_increase, bool no_decrease);
253  void SetMinZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease);
254  void SetMaxZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease);
255  void SetZoom(C4Real zoom, bool direct, bool no_increase, bool no_decrease);
256  void SetMinZoom(C4Real zoom, bool no_increase, bool no_decrease);
257  void SetMaxZoom(C4Real zoom, bool no_increase, bool no_decrease);
258  void ZoomToViewports(bool direct, bool no_increase=false, bool no_decrease=false);
259  void ZoomToViewport(C4Viewport* vp, bool direct, bool no_increase=false, bool no_decrease=false);
260  void ZoomLimitsToViewports();
262 
263 private:
264  bool AdjustZoomParameter(int32_t *range_par, int32_t new_val, bool no_increase, bool no_decrease);
265  bool AdjustZoomParameter(C4Real *zoom_par, C4Real new_val, bool no_increase, bool no_decrease);
266 
267  // Finds a new gamepad to use, returning true on success.
268  bool FindGamepad();
269 
270 public:
271  // custom scenario achievements
272  bool GainScenarioAchievement(const char *achievement_id, int32_t value, const char *scen_name_override=nullptr);
273 };
274 
275 #endif
const size_t C4MaxTitle
Definition: C4Constants.h:25
C4PlayerType
Definition: C4Constants.h:152
const int32_t C4PVM_Scrolling
Definition: C4Player.h:33
const int32_t C4PVM_Cursor
Definition: C4Player.h:31
const int32_t C4MaxPlayer
Definition: C4Player.h:37
const int32_t C4P_Number_None
Definition: C4Player.h:35
const int32_t C4PVM_Target
Definition: C4Player.h:32
const int32_t C4MaxClient
Definition: C4Player.h:38
#define _MAX_PATH_LEN
Definition: C4Real.h:59
Definition: C4Id.h:26
C4ObjectPtr Cursor
Definition: C4Player.h:130
int32_t CurrentScore
Definition: C4Player.h:116
void PlaceReadyBase(int32_t &tx, int32_t &ty, C4Object **pFirstBase)
Definition: C4Player.cpp:527
void SetFoW(bool fEnable)
Definition: C4Player.cpp:723
void PlaceReadyMaterial(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
Definition: C4Player.cpp:573
C4MainMenu Menu
Definition: C4Player.h:103
C4IDList BaseProduction
Definition: C4Player.h:121
void DoTeamSelection(int32_t idTeam)
Definition: C4Player.cpp:1250
int32_t ZoomLimitMinWdt
Definition: C4Player.h:112
void CountControl(ControlType eType, int32_t iID, int32_t iCntAdd=1)
Definition: C4Player.cpp:1632
C4Value SoundModifier
Definition: C4Player.h:140
bool fFogOfWar
Definition: C4Player.h:111
void ZoomLimitsToViewport(C4Viewport *vp)
Definition: C4Player.cpp:1859
bool Message(const char *szMsg)
Definition: C4Player.cpp:929
C4ObjectInfoList CrewInfoList
Definition: C4Player.h:124
void SetPlayerColor(uint32_t dwNewClr)
Definition: C4Player.cpp:1711
int32_t ObjectsOwned
Definition: C4Player.h:117
bool HasMessageBoardQuery()
Definition: C4Player.cpp:1698
int32_t InitialScore
Definition: C4Player.h:116
int32_t Eliminated
Definition: C4Player.h:83
int32_t ZoomHgt
Definition: C4Player.h:112
int32_t FlashCom
Definition: C4Player.h:110
int32_t ViewMode
Definition: C4Player.h:105
void ZoomLimitsToViewports()
Definition: C4Player.cpp:1852
int32_t Status
Definition: C4Player.h:82
uint32_t ColorDw
Definition: C4Player.h:89
void InitControl()
Definition: C4Player.cpp:1393
HostilitySet Hostility
Definition: C4Player.h:118
void ClearControl()
Definition: C4Player.cpp:1373
C4Object * ViewTarget
Definition: C4Player.h:108
bool ShowStartup
Definition: C4Player.h:109
void SetMaxZoom(C4Real zoom, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1830
int32_t Position
Definition: C4Player.h:93
C4IDList BaseMaterial
Definition: C4Player.h:120
bool LocalControl
Definition: C4Player.h:99
C4Player * Next
Definition: C4Player.h:142
void EvaluateLeague(bool fDisconnected, bool fWon)
Definition: C4Player.cpp:1515
bool SetKnowledge(C4ID id, bool fRemove)
Definition: C4Player.cpp:752
bool LocalSync()
Definition: C4Player.cpp:1531
bool SetHostility(int32_t iOpponent, int32_t iHostility, bool fSilent=false)
Definition: C4Player.cpp:838
bool LeagueEvaluated
Definition: C4Player.h:100
C4Player()
Definition: C4Player.cpp:47
C4ObjectPtr ViewCursor
Definition: C4Player.h:130
void SetTeamHostility()
Definition: C4Player.cpp:915
int32_t Wealth
Definition: C4Player.h:115
static bool Strip(const char *szFilename, bool fAggressive)
Definition: C4Player.cpp:957
bool GainScenarioAchievement(const char *achievement_id, int32_t value, const char *scen_name_override=nullptr)
Definition: C4Player.cpp:1907
bool IsInvisible() const
Definition: C4Player.cpp:1734
void PlaceReadyCrew(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
Definition: C4Player.cpp:479
int32_t FindNewOwner() const
Definition: C4Player.cpp:1279
bool DoWealth(int32_t change)
Definition: C4Player.cpp:729
void ExecBaseProduction()
Definition: C4Player.cpp:1153
int32_t RetireDelay
Definition: C4Player.h:95
void Surrender()
Definition: C4Player.cpp:828
int32_t ActiveCrewCount()
Definition: C4Player.cpp:1496
void Evaluate()
Definition: C4Player.cpp:787
const char * GetName() const
Definition: C4Player.h:151
bool LoadRuntimeData(C4Group &hGroup, C4ValueNumbers *)
Definition: C4Player.cpp:1132
ControlType
Definition: C4Player.h:59
@ PCID_DirectCom
Definition: C4Player.h:64
@ PCID_Command
Definition: C4Player.h:63
@ PCID_Message
Definition: C4Player.h:61
@ PCID_Special
Definition: C4Player.h:62
@ PCID_None
Definition: C4Player.h:60
bool SetWealth(int32_t val)
Definition: C4Player.cpp:741
int32_t ZoomLimitMaxHgt
Definition: C4Player.h:112
void CallMessageBoard(C4Object *pForObj, const StdStrBuf &sQueryString, bool fUppercase)
Definition: C4Player.cpp:1664
bool ScenarioInit()
Definition: C4Player.cpp:601
int32_t GameJoinTime
Definition: C4Player.h:96
void RemoveCrewObjects()
Definition: C4Player.cpp:1271
bool Load(const char *szFilename, bool fSavegame)
Definition: C4Player.cpp:937
int32_t ZoomLimitMinHgt
Definition: C4Player.h:112
void PlaceReadyVehic(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
Definition: C4Player.cpp:552
void SetCursor(C4Object *pObj, bool fSelectArrow)
Definition: C4Player.cpp:1348
int32_t CursorFlash
Definition: C4Player.h:131
C4Real ZoomVal
Definition: C4Player.h:113
int32_t ActionCount
Definition: C4Player.h:147
bool Init(int32_t iNumber, int32_t iAtClient, const char *szAtClientName, const char *szFilename, bool fScenarioInit, class C4PlayerInfo *pInfo, C4ValueNumbers *)
Definition: C4Player.cpp:257
bool ScenarioAndTeamInit(int32_t idTeam)
Definition: C4Player.cpp:118
bool ObjectInCrew(C4Object *tobj)
Definition: C4Player.cpp:90
C4Real ZoomLimitMaxVal
Definition: C4Player.h:113
C4PlayerType GetType() const
Definition: C4Player.cpp:1727
void NotifyOwnedObjects()
Definition: C4Player.cpp:1311
bool IsHostileTowards(const C4Player *opponent) const
Definition: C4Player.cpp:860
bool FinalInit(bool fInitialScore)
Definition: C4Player.cpp:699
void SetZoom(C4Real zoom, bool direct, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1818
int32_t PlrStartIndex
Definition: C4Player.h:94
void AdjustCursorCommand()
Definition: C4Player.cpp:1059
void SetMinZoom(C4Real zoom, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1824
C4PlayerControl Control
Definition: C4Player.h:129
int32_t ControlCount
Definition: C4Player.h:146
void ZoomToViewport(C4Viewport *vp, bool direct, bool no_increase=false, bool no_decrease=false)
Definition: C4Player.cpp:1843
char MessageBuf[256+1]
Definition: C4Player.h:135
void DrawHostility(C4Facet &cgo, int32_t iIndex)
Definition: C4Player.cpp:995
C4Real ViewY
Definition: C4Player.h:106
int32_t Team
Definition: C4Player.h:88
int32_t ID
Definition: C4Player.h:87
void DefaultRuntimeData()
Definition: C4Player.cpp:1206
C4Object * GetHiExpActiveCrew()
Definition: C4Player.cpp:867
int32_t Surrendered
Definition: C4Player.h:84
void ToggleMouseControl()
Definition: C4Player.cpp:1741
C4ObjectList Crew
Definition: C4Player.h:125
void ZoomToViewports(bool direct, bool no_increase=false, bool no_decrease=false)
Definition: C4Player.cpp:1836
class C4TableGraph * pstatControls
Definition: C4Player.h:145
void SetViewMode(int32_t iMode, C4Object *pTarget=nullptr, bool immediate_position=false)
Definition: C4Player.cpp:767
int32_t MessageStatus
Definition: C4Player.h:134
void OnTeamSelectionFailed()
Definition: C4Player.cpp:1704
bool NoEliminationCheck
Definition: C4Player.h:101
StatusTypes
Definition: C4Player.h:68
@ PS_TeamSelectionPending
Definition: C4Player.h:72
@ PS_None
Definition: C4Player.h:69
@ PS_Normal
Definition: C4Player.h:70
@ PS_TeamSelection
Definition: C4Player.h:71
class C4PlayerControlAssignmentSet * ControlSet
Definition: C4Player.h:90
bool MakeCrewMember(C4Object *pObj, bool fForceInfo=true, bool fDoCalls=true)
Definition: C4Player.cpp:1008
int32_t ZoomWdt
Definition: C4Player.h:112
bool Save()
Definition: C4Player.cpp:415
bool IsChosingTeam() const
Definition: C4Player.h:202
bool ActivateMenuMain()
Definition: C4Player.cpp:1761
void CloseMenu()
Definition: C4Player.cpp:1466
int32_t ZoomLimitMaxWdt
Definition: C4Player.h:112
void Eliminate()
Definition: C4Player.cpp:1472
C4FacetSurface BigIcon
Definition: C4Player.h:138
void CheckCrewExPromotion()
Definition: C4Player.cpp:905
class C4MessageBoardQuery * pMsgBoardQuery
Definition: C4Player.h:136
bool Evaluated
Definition: C4Player.h:85
void SetMaxZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1811
void CreateGraphs()
Definition: C4Player.cpp:1588
int32_t Number
Definition: C4Player.h:86
void SetMinZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1804
void ExecuteControl()
Definition: C4Player.cpp:1054
ControlType LastControlType
Definition: C4Player.h:148
void ResetCursorView(bool immediate_position=false)
Definition: C4Player.cpp:780
char AtClientName[C4MaxTitle+1]
Definition: C4Player.h:98
C4Object * GetHiRankActiveCrew()
Definition: C4Player.cpp:886
void SetViewLocked(bool to_val)
Definition: C4Player.cpp:1898
int32_t LastControlID
Definition: C4Player.h:148
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *)
Definition: C4Player.cpp:1074
void SetZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool direct, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1797
int32_t ProductionUnit
Definition: C4Player.h:122
StdStrBuf Name
Definition: C4Player.h:81
void ClearGraphs()
Definition: C4Player.cpp:1615
C4Real ZoomLimitMinVal
Definition: C4Player.h:113
C4Real ViewX
Definition: C4Player.h:106
int32_t GetSelectedCrewCount()
Definition: C4Player.cpp:1508
std::shared_ptr< class C4GamePadOpener > pGamepad
Definition: C4Player.h:132
C4IDList Knowledge
Definition: C4Player.h:127
~C4Player()
Definition: C4Player.cpp:76
void DenumeratePointers()
Definition: C4Player.cpp:1258
bool SetObjectCrewStatus(C4Object *pCrew, bool fNewStatus)
Definition: C4Player.cpp:1557
class C4TableGraph * pstatActions
Definition: C4Player.h:145
void SetSoundModifier(C4PropList *new_modifier)
Definition: C4Player.cpp:1923
void UpdateView()
Definition: C4Player.cpp:1180
void Execute()
Definition: C4Player.cpp:162
int32_t ProductionDelay
Definition: C4Player.h:122
bool IsViewLocked() const
Definition: C4Player.h:204
bool RemoveMessageBoardQuery(C4Object *pForObj)
Definition: C4Player.cpp:1674
int32_t MouseControl
Definition: C4Player.h:92
StdCopyStrBuf ControlSetName
Definition: C4Player.h:91
bool MarkMessageBoardQueryAnswered(C4Object *pForObj)
Definition: C4Player.cpp:1687
class C4PlayerInfo * GetInfo()
Definition: C4Player.cpp:1552
int32_t AtClient
Definition: C4Player.h:97
char Filename[_MAX_PATH_LEN]
Definition: C4Player.h:80
void ClearPointers(C4Object *tptr, bool fDeath)
Definition: C4Player.cpp:98
bool ViewLock
Definition: C4Player.h:107
void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt)
Definition: C4Player.cpp:1364
void CheckElimination()
Definition: C4Player.cpp:1168
bool ActivateMenuTeamSelection(bool fFromMain)
Definition: C4Player.cpp:1238
bool DoScore(int32_t iChange)
Definition: C4Player.cpp:1342
const char * getData() const
Definition: StdBuf.h:442