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 
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
202  bool IsChosingTeam() const { return Status==PS_TeamSelection || Status==PS_TeamSelectionPending; }
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
bool IsHostileTowards(const C4Player *opponent) const
Definition: C4Player.cpp:860
const int32_t C4PVM_Scrolling
Definition: C4Player.h:33
const char * getData() const
Definition: StdBuf.h:442
class C4PlayerInfo * GetInfo()
Definition: C4Player.cpp:1551
void SetFoW(bool fEnable)
Definition: C4Player.cpp:723
void CloseMenu()
Definition: C4Player.cpp:1466
int32_t MouseControl
Definition: C4Player.h:92
const size_t C4MaxTitle
Definition: C4Constants.h:25
char AtClientName[C4MaxTitle+1]
Definition: C4Player.h:98
int32_t LastControlID
Definition: C4Player.h:148
int32_t Team
Definition: C4Player.h:88
C4ObjectPtr Cursor
Definition: C4Player.h:130
int32_t ProductionDelay
Definition: C4Player.h:122
bool MakeCrewMember(C4Object *pObj, bool fForceInfo=true, bool fDoCalls=true)
Definition: C4Player.cpp:1008
C4MainMenu Menu
Definition: C4Player.h:103
bool HasMessageBoardQuery()
Definition: C4Player.cpp:1697
void CheckCrewExPromotion()
Definition: C4Player.cpp:905
bool ViewLock
Definition: C4Player.h:107
int32_t ViewMode
Definition: C4Player.h:105
int32_t ControlCount
Definition: C4Player.h:146
int32_t Number
Definition: C4Player.h:86
void SetMaxZoom(C4Real zoom, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1829
C4Real ZoomVal
Definition: C4Player.h:113
int32_t FlashCom
Definition: C4Player.h:110
void ZoomLimitsToViewport(C4Viewport *vp)
Definition: C4Player.cpp:1858
C4Player()
Definition: C4Player.cpp:47
bool IsInvisible() const
Definition: C4Player.cpp:1733
int32_t ActiveCrewCount()
Definition: C4Player.cpp:1496
class C4TableGraph * pstatActions
Definition: C4Player.h:145
char Filename[_MAX_PATH+1]
Definition: C4Player.h:80
bool IsChosingTeam() const
Definition: C4Player.h:202
void Eliminate()
Definition: C4Player.cpp:1472
int32_t ObjectsOwned
Definition: C4Player.h:117
const int32_t C4MaxClient
Definition: C4Player.h:38
void ToggleMouseControl()
Definition: C4Player.cpp:1740
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *)
Definition: C4Player.cpp:1074
StatusTypes
Definition: C4Player.h:67
void ClearControl()
Definition: C4Player.cpp:1373
bool ShowStartup
Definition: C4Player.h:109
void UpdateView()
Definition: C4Player.cpp:1180
bool ScenarioAndTeamInit(int32_t idTeam)
Definition: C4Player.cpp:118
ControlType LastControlType
Definition: C4Player.h:148
bool Load(const char *szFilename, bool fSavegame)
Definition: C4Player.cpp:937
int32_t ZoomLimitMinHgt
Definition: C4Player.h:112
int32_t GetSelectedCrewCount()
Definition: C4Player.cpp:1508
C4PlayerControl Control
Definition: C4Player.h:129
int32_t PlrStartIndex
Definition: C4Player.h:94
bool IsViewLocked() const
Definition: C4Player.h:204
#define _MAX_PATH
int32_t Position
Definition: C4Player.h:93
void SetCursor(C4Object *pObj, bool fSelectArrow)
Definition: C4Player.cpp:1348
void ZoomLimitsToViewports()
Definition: C4Player.cpp:1851
int32_t ProductionUnit
Definition: C4Player.h:122
void DrawHostility(C4Facet &cgo, int32_t iIndex)
Definition: C4Player.cpp:995
StdStrBuf Name
Definition: C4Player.h:81
void ZoomToViewport(C4Viewport *vp, bool direct, bool no_increase=false, bool no_decrease=false)
Definition: C4Player.cpp:1842
int32_t ZoomLimitMaxWdt
Definition: C4Player.h:112
void ClearPointers(C4Object *tptr, bool fDeath)
Definition: C4Player.cpp:98
void DenumeratePointers()
Definition: C4Player.cpp:1258
char MessageBuf[256+1]
Definition: C4Player.h:135
bool ActivateMenuTeamSelection(bool fFromMain)
Definition: C4Player.cpp:1238
std::shared_ptr< class C4GamePadOpener > pGamepad
Definition: C4Player.h:132
Definition: C4Real.h:58
bool FinalInit(bool fInitialScore)
Definition: C4Player.cpp:699
uint32_t ColorDw
Definition: C4Player.h:89
void SetZoom(C4Real zoom, bool direct, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1817
int32_t CursorFlash
Definition: C4Player.h:131
void CallMessageBoard(C4Object *pForObj, const StdStrBuf &sQueryString, bool fUppercase)
Definition: C4Player.cpp:1663
int32_t ZoomWdt
Definition: C4Player.h:112
void OnTeamSelectionFailed()
Definition: C4Player.cpp:1703
const int32_t C4P_Number_None
Definition: C4Player.h:35
class C4PlayerControlAssignmentSet * ControlSet
Definition: C4Player.h:90
static bool Strip(const char *szFilename, bool fAggressive)
Definition: C4Player.cpp:957
~C4Player()
Definition: C4Player.cpp:76
bool LoadRuntimeData(C4Group &hGroup, C4ValueNumbers *)
Definition: C4Player.cpp:1132
bool Message(const char *szMsg)
Definition: C4Player.cpp:929
void NotifyOwnedObjects()
Definition: C4Player.cpp:1311
void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt)
Definition: C4Player.cpp:1364
int32_t Status
Definition: C4Player.h:82
C4Object * GetHiRankActiveCrew()
Definition: C4Player.cpp:886
ControlType
Definition: C4Player.h:58
void CreateGraphs()
Definition: C4Player.cpp:1587
C4IDList Knowledge
Definition: C4Player.h:127
void SetZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool direct, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1796
int32_t FindNewOwner() const
Definition: C4Player.cpp:1279
void SetViewMode(int32_t iMode, C4Object *pTarget=nullptr, bool immediate_position=false)
Definition: C4Player.cpp:767
void Execute()
Definition: C4Player.cpp:162
C4FacetSurface BigIcon
Definition: C4Player.h:138
class C4TableGraph * pstatControls
Definition: C4Player.h:145
void SetMinZoom(C4Real zoom, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1823
void SetPlayerColor(uint32_t dwNewClr)
Definition: C4Player.cpp:1710
void SetMaxZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1810
bool SetObjectCrewStatus(C4Object *pCrew, bool fNewStatus)
Definition: C4Player.cpp:1556
bool DoWealth(int32_t change)
Definition: C4Player.cpp:729
C4Object * GetHiExpActiveCrew()
Definition: C4Player.cpp:867
int32_t MessageStatus
Definition: C4Player.h:134
void SetViewLocked(bool to_val)
Definition: C4Player.cpp:1897
bool SetKnowledge(C4ID id, bool fRemove)
Definition: C4Player.cpp:752
int32_t GameJoinTime
Definition: C4Player.h:96
bool Evaluated
Definition: C4Player.h:85
Definition: C4Id.h:25
C4PlayerType
Definition: C4Constants.h:152
int32_t Surrendered
Definition: C4Player.h:84
C4ObjectList Crew
Definition: C4Player.h:125
const int32_t C4MaxPlayer
Definition: C4Player.h:37
int32_t Eliminated
Definition: C4Player.h:83
C4Value SoundModifier
Definition: C4Player.h:140
void PlaceReadyCrew(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
Definition: C4Player.cpp:479
void PlaceReadyBase(int32_t &tx, int32_t &ty, C4Object **pFirstBase)
Definition: C4Player.cpp:527
int32_t CurrentScore
Definition: C4Player.h:116
bool ActivateMenuMain()
Definition: C4Player.cpp:1760
bool ScenarioInit()
Definition: C4Player.cpp:601
int32_t Wealth
Definition: C4Player.h:115
void CheckElimination()
Definition: C4Player.cpp:1168
void Evaluate()
Definition: C4Player.cpp:787
void DoTeamSelection(int32_t idTeam)
Definition: C4Player.cpp:1250
int32_t ZoomLimitMinWdt
Definition: C4Player.h:112
int32_t AtClient
Definition: C4Player.h:97
bool NoEliminationCheck
Definition: C4Player.h:101
int32_t ID
Definition: C4Player.h:87
int32_t ZoomLimitMaxHgt
Definition: C4Player.h:112
const char * GetName() const
Definition: C4Player.h:151
void EvaluateLeague(bool fDisconnected, bool fWon)
Definition: C4Player.cpp:1515
C4Real ViewY
Definition: C4Player.h:106
void CountControl(ControlType eType, int32_t iID, int32_t iCntAdd=1)
Definition: C4Player.cpp:1631
StdCopyStrBuf ControlSetName
Definition: C4Player.h:91
void SetTeamHostility()
Definition: C4Player.cpp:915
C4Real ZoomLimitMaxVal
Definition: C4Player.h:113
bool DoScore(int32_t iChange)
Definition: C4Player.cpp:1342
void ResetCursorView(bool immediate_position=false)
Definition: C4Player.cpp:780
bool LeagueEvaluated
Definition: C4Player.h:100
void ExecuteControl()
Definition: C4Player.cpp:1054
C4Player * Next
Definition: C4Player.h:142
void InitControl()
Definition: C4Player.cpp:1393
void Surrender()
Definition: C4Player.cpp:828
C4ObjectInfoList CrewInfoList
Definition: C4Player.h:124
int32_t InitialScore
Definition: C4Player.h:116
void ClearGraphs()
Definition: C4Player.cpp:1614
int32_t RetireDelay
Definition: C4Player.h:95
void AdjustCursorCommand()
Definition: C4Player.cpp:1059
const int32_t C4PVM_Target
Definition: C4Player.h:32
void PlaceReadyVehic(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
Definition: C4Player.cpp:552
C4Object * ViewTarget
Definition: C4Player.h:108
void SetMinZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease)
Definition: C4Player.cpp:1803
bool Save()
Definition: C4Player.cpp:415
const int32_t C4PVM_Cursor
Definition: C4Player.h:31
void RemoveCrewObjects()
Definition: C4Player.cpp:1271
bool SetWealth(int32_t val)
Definition: C4Player.cpp:741
int32_t ZoomHgt
Definition: C4Player.h:112
bool fFogOfWar
Definition: C4Player.h:111
C4ObjectPtr ViewCursor
Definition: C4Player.h:130
bool GainScenarioAchievement(const char *achievement_id, int32_t value, const char *scen_name_override=nullptr)
Definition: C4Player.cpp:1906
void DefaultRuntimeData()
Definition: C4Player.cpp:1206
C4IDList BaseMaterial
Definition: C4Player.h:120
bool ObjectInCrew(C4Object *tobj)
Definition: C4Player.cpp:90
class C4MessageBoardQuery * pMsgBoardQuery
Definition: C4Player.h:136
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
void ZoomToViewports(bool direct, bool no_increase=false, bool no_decrease=false)
Definition: C4Player.cpp:1835
void SetSoundModifier(C4PropList *new_modifier)
Definition: C4Player.cpp:1922
bool MarkMessageBoardQueryAnswered(C4Object *pForObj)
Definition: C4Player.cpp:1686
void PlaceReadyMaterial(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
Definition: C4Player.cpp:573
C4IDList BaseProduction
Definition: C4Player.h:121
bool SetHostility(int32_t iOpponent, int32_t iHostility, bool fSilent=false)
Definition: C4Player.cpp:838
bool LocalSync()
Definition: C4Player.cpp:1530
void ExecBaseProduction()
Definition: C4Player.cpp:1153
bool RemoveMessageBoardQuery(C4Object *pForObj)
Definition: C4Player.cpp:1673
bool LocalControl
Definition: C4Player.h:99
C4Real ViewX
Definition: C4Player.h:106
HostilitySet Hostility
Definition: C4Player.h:118
C4PlayerType GetType() const
Definition: C4Player.cpp:1726
C4Real ZoomLimitMinVal
Definition: C4Player.h:113