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 /* Structures for object and player info components */
19 
20 #ifndef INC_C4InfoCore
21 #define INC_C4InfoCore
22 
23 #include "lib/C4InputValidation.h"
24 #include "object/C4Id.h"
25 #include "player/C4ScenarioParameters.h"
26 #include "script/C4ValueMap.h"
27 
28 const int32_t C4MaxPhysical = 100000,
29                               C4MaxDeathMsg = 75;
30 
31 class C4ObjectInfoCore
32 {
33 public:
34 	C4ObjectInfoCore();
35 public:
36 	C4ID id;
37 	char Name[C4MaxName+1];
38 	int32_t  Participation;
39 	int32_t  Rank;
40 	StdStrBuf sRankName;
41 	StdStrBuf sNextRankName;
42 	int32_t NextRankExp; // EXP_NoPromotion for no more promotion; 0 if standard rank system is used
43 	int32_t  Experience,Rounds;
44 	int32_t  DeathCount;
45 	char TypeName[C4MaxName+1+1];
46 	int32_t  Birthday,TotalPlayingTime;
47 	int32_t  Age;
48 	char DeathMessage[C4MaxDeathMsg+1];
49 	C4ValueMapData ExtraData;
50 public:
51 	bool Save(C4Group &hGroup, class C4DefList *pDefs);
52 	bool Load(C4Group &hGroup);
53 	void Default(C4ID n_id=C4ID::None, class C4DefList *pDefs=nullptr, const char *cpNames=nullptr);
54 	void Promote(int32_t iRank, C4RankSystem &rRanks, bool fForceRankName);
55 	bool GetNextRankInfo(C4RankSystem &rDefaultRanks, int32_t *piNextRankExp, StdStrBuf *psNextRankName);
56 	void CompileFunc(StdCompiler *pComp);
57 protected:
58 	bool Compile(const char *szSource);
59 	bool Decompile(char **ppOutput, size_t *ipSize);
60 
61 	void UpdateCustomRanks(C4DefList *pDefs); // sets NextRankName and NextRankExp
62 };
63 
64 class C4RoundResult
65 {
66 public:
67 	StdCopyStrBuf Title;
68 	uint32_t Date = 0;
69 	int32_t Duration = 0;
70 	int32_t Won = 0;
71 	int32_t Score = 0, FinalScore = 0, TotalScore = 0;
72 	int32_t Bonus = 0;
73 	int32_t Level = 0;
74 public:
75 	void Default();
76 	void CompileFunc(StdCompiler *pComp);
77 };
78 
79 class C4PlayerInfoCore
80 {
81 public:
82 	C4PlayerInfoCore();
83 public:
84 	// Player Info
85 	char PrefName[C4MaxName+1];
86 	char Comment[C4MaxComment+1];
87 	int32_t  Rank;
88 	char RankName[C4MaxName+1];
89 	int32_t  TotalScore;
90 	int32_t  Rounds,RoundsWon,RoundsLost;
91 	int32_t  TotalPlayingTime;
92 	C4RoundResult LastRound;
93 	C4ValueMapData ExtraData;
94 	char LeagueName[C4MaxName+1];
95 	// Preferences
96 	StdCopyStrBuf PrefControl; // name of control set from definition file
97 	int32_t PrefMouse;
98 	int32_t PrefColor;
99 	uint32_t PrefColorDw, PrefColor2Dw;
100 	int32_t PrefClonkSkin;
101 	// Old control method - loaded for backwards compatilibity if PrefControl is unassigned
102 	// and stored back so you can use the same player file for CR and OC
103 	int32_t OldPrefControl;
104 	int32_t OldPrefControlStyle;
105 	int32_t OldPrefAutoContextMenu;
106 
107 	// achievements indexed by achievement name and scenario
108 	C4ScenarioParameters Achievements;
109 public:
110 	void Default(C4RankSystem *pRanks=nullptr);
111 	void Promote(int32_t iRank, C4RankSystem &rRanks);
112 	bool Load(C4Group &hGroup);
113 	bool Save(C4Group &hGroup);
114 	bool CheckPromotion(C4RankSystem &rRanks);
115 	static DWORD GetPrefColorValue(int32_t iPrefColor);
116 	void CompileFunc(StdCompiler *pComp);
117 };
118 
119 #endif
120