OpenClonk
C4ObjectRank.cpp
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 /* Logic for C4Object: Rank system */
19 
20 #include "C4Include.h"
22 #include "object/C4Object.h"
23 
24 #include "gui/C4GameMessage.h"
25 #include "object/C4Def.h"
26 #include "object/C4DefList.h"
27 #include "object/C4ObjectInfo.h"
28 #include "platform/C4SoundSystem.h"
29 #include "player/C4RankSystem.h"
30 
31 
32 void C4Object::DoExperience(int32_t change)
33 {
34  const int32_t MaxExperience = 100000000;
35 
36  if (!Info) return;
37 
38  Info->Experience=Clamp<int32_t>(Info->Experience+change,0,MaxExperience);
39 
40  // Promotion check
41  if (Info->Experience<MaxExperience)
43  Promote(Info->Rank+1, false, false);
44 }
45 
46 bool C4Object::Promote(int32_t torank, bool exception, bool fForceRankName)
47 {
48  if (!Info) return false;
49  // get rank system
50  C4Def *pUseDef = C4Id2Def(Info->id);
51  C4RankSystem *pRankSys;
52  if (pUseDef && pUseDef->pRankNames)
53  pRankSys = pUseDef->pRankNames;
54  else
55  pRankSys = &::DefaultRanks;
56  // always promote info
57  Info->Promote(torank,*pRankSys, fForceRankName);
58  // silent update?
59  if (!pRankSys->GetRankName(torank,false)) return false;
60  GameMsgObject(FormatString(LoadResStr("IDS_OBJ_PROMOTION"),GetName (),Info->sRankName.getData()).getData(),this);
61 
62  // call to object
64 
65  StartSoundEffect("UI::Trumpet",false,100,this);
66  return true;
67 }
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:84
void GameMsgObject(const char *szText, C4Object *pTarget)
#define PSF_Promotion
Definition: C4GameScript.h:147
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4RankSystem DefaultRanks
C4SoundInstance * StartSoundEffect(const char *szSndName, bool fLoop, int32_t iVolume, C4Object *pObj, int32_t iCustomFalloffDistance, int32_t iPitch, C4SoundModifier *modifier)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
Definition: C4Def.h:99
C4RankSystem * pRankNames
Definition: C4Def.h:188
C4ObjectInfo * Info
Definition: C4Object.h:143
void DoExperience(int32_t change)
bool Promote(int32_t torank, bool exception, bool fForceRankName)
void Promote(int32_t iRank, C4RankSystem &rRanks, bool fForceRankName)
Definition: C4InfoCore.cpp:252
StdStrBuf sRankName
Definition: C4InfoCore.h:40
int32_t Experience
Definition: C4InfoCore.h:43
virtual const char * GetName() const
Definition: C4PropList.cpp:618
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:114
StdStrBuf GetRankName(int iRank, bool fReturnLastIfOver)
int Experience(int iRank)
const char * getData() const
Definition: StdBuf.h:442