OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4RoundResults Class Reference

#include <C4RoundResults.h>

Public Types

enum  NetResult { NR_None =0, NR_LeagueOK, NR_LeagueError, NR_NetError }
 

Public Member Functions

 C4RoundResults ()
 
 ~C4RoundResults ()
 
void Clear ()
 
void Init ()
 
void CompileFunc (StdCompiler *pComp)
 
void EvaluateGame ()
 
void EvaluateLeague (const char *szResultMsg, bool fSuccess, const C4RoundResultsPlayers &rLeagueInfo)
 
void EvaluatePlayer (C4Player *pPlr)
 
void EvaluateNetwork (NetResult eResult, const char *szResultsString)
 
void AddCustomEvaluationString (const char *szCustomString, int32_t idPlayer)
 
void HideSettlementScore (bool fHide=true)
 
bool SettlementScoreIsHidden ()
 
void SetLeaguePerformance (int32_t iNewPerf, int32_t idPlayer=0)
 
int32_t GetLeaguePerformance (int32_t idPlayer=0) const
 
StdCopyStrBuf GetStatistics () const
 
const C4RoundResultsPlayersGetPlayers () const
 
const char * GetCustomEvaluationStrings () const
 
NetResult GetNetResult () const
 
const char * GetNetResultString () const
 
bool HasNetResult () const
 
bool Load (C4Group &hGroup, const char *szFilename=C4CFN_RoundResults)
 
bool Save (C4Group &hGroup, const char *szFilename=C4CFN_RoundResults)
 
const C4IDListGetGoals () const
 
const C4IDListGetFulfilledGoals () const
 

Static Public Member Functions

static void EvaluateGoals (C4IDList &GoalList, C4IDList &FulfilledGoalList, int32_t iPlayerNumber)
 

Detailed Description

Definition at line 124 of file C4RoundResults.h.

Member Enumeration Documentation

Enumerator
NR_None 
NR_LeagueOK 
NR_LeagueError 
NR_NetError 

Definition at line 127 of file C4RoundResults.h.

128  {
129  NR_None=0, // undefined
130  NR_LeagueOK, // league evaluated
131  NR_LeagueError, // league evaluation error
132  NR_NetError // network disconnect
133  };

Constructor & Destructor Documentation

C4RoundResults::C4RoundResults ( )
inline

Definition at line 155 of file C4RoundResults.h.

155 : iPlayingTime(0) {}
C4RoundResults::~C4RoundResults ( )
inline

Definition at line 156 of file C4RoundResults.h.

References Clear().

156 { Clear(); }

Here is the call graph for this function:

Member Function Documentation

void C4RoundResults::AddCustomEvaluationString ( const char *  szCustomString,
int32_t  idPlayer 
)

Definition at line 358 of file C4RoundResults.cpp.

References C4RoundResultsPlayer::AddCustomEvaluationString(), StdStrBuf::Append(), StdStrBuf::AppendChar(), C4RoundResultsPlayers::GetCreateByID(), and StdStrBuf::getLength().

359 {
360  // Set custom string to be shown in game over dialog
361  // idPlayer==0 for global strings
362  if (!idPlayer)
363  {
364  if (sCustomEvaluationStrings.getLength()) sCustomEvaluationStrings.AppendChar('|');
365  sCustomEvaluationStrings.Append(szCustomString);
366  }
367  else
368  {
369  C4RoundResultsPlayer *pOwnPlr = Players.GetCreateByID(idPlayer);
370  pOwnPlr->AddCustomEvaluationString(szCustomString);
371  }
372 }
void AppendChar(char cChar)
Definition: StdBuf.h:596
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:527
C4PlayerList Players
void AddCustomEvaluationString(const char *szCustomString)
size_t getLength() const
Definition: StdBuf.h:453

Here is the call graph for this function:

void C4RoundResults::Clear ( )

Definition at line 242 of file C4RoundResults.cpp.

References C4IDList::Clear(), C4RoundResultsPlayers::Clear(), StdStrBuf::Clear(), and NR_None.

Referenced by C4Game::Clear(), CompileFunc(), Load(), and ~C4RoundResults().

243 {
244  Players.Clear();
245  Goals.Clear();
246  iPlayingTime = 0;
247  sCustomEvaluationStrings.Clear();
248  iLeaguePerformance = 0;
249  sNetResult.Clear();
250  eNetResult = NR_None;
251  fHideSettlementScore=false;
252  Statistics.Clear();
253 }
void Clear()
Definition: stub-handle.cpp:64
void Clear()
Definition: StdBuf.h:474
C4PlayerList Players

Here is the call graph for this function:

Here is the caller graph for this function:

void C4RoundResults::CompileFunc ( StdCompiler pComp)

Definition at line 262 of file C4RoundResults.cpp.

References C4Game::C4S, Clear(), Game, C4Scenario::Game, StdCompiler::isDeserializer(), C4SGame::IsMelee(), mkNamingAdapt(), NR_LeagueError, NR_LeagueOK, NR_NetError, NR_None, and StdCompiler::Value().

263 {
264  bool deserializing = pComp->isDeserializer();
265  if (deserializing) Clear();
266  pComp->Value(mkNamingAdapt(Goals, "Goals", C4IDList()));
267  pComp->Value(mkNamingAdapt(iPlayingTime, "PlayingTime", 0u));
268  pComp->Value(mkNamingAdapt(fHideSettlementScore, "HideSettlementScore", Game.C4S.Game.IsMelee()));
269  pComp->Value(mkNamingAdapt(sCustomEvaluationStrings, "CustomEvaluationStrings", StdCopyStrBuf()));
270  pComp->Value(mkNamingAdapt(iLeaguePerformance, "LeaguePerformance", 0));
271  pComp->Value(mkNamingAdapt(Players, "PlayerInfos", C4RoundResultsPlayers()));
272  pComp->Value(mkNamingAdapt(sNetResult, "NetResult", StdCopyStrBuf()));
273  StdEnumEntry<NetResult> NetResultEntries[] =
274  {
275  { "", NR_None },
276  { "LeagueOK", NR_LeagueOK },
277  { "LeagueError", NR_LeagueError},
278  { "NetError", NR_NetError },
279  };
280  pComp->Value(mkNamingAdapt(mkEnumAdaptT<uint8_t>(eNetResult, NetResultEntries), "NetResult", NR_None));
281 }
Definition: StdAdaptors.h:763
bool IsMelee()
Definition: C4Scenario.cpp:510
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:76
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
C4PlayerList Players
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
C4SGame Game
Definition: C4Scenario.h:232

Here is the call graph for this function:

void C4RoundResults::EvaluateGame ( )

Definition at line 305 of file C4RoundResults.cpp.

References C4VNull, C4PropList::Call(), DebugLogF(), EvaluateGoals(), Game, C4AulScriptEngine::GetPropList(), NO_OWNER, C4Player::Number, PSF_CollectStatistics, ScriptEngine, C4Game::Time, and C4JSONSerializationError::what().

Referenced by C4Game::Evaluate().

306 {
307  // set game data
308  C4Player *pFirstLocalPlayer = ::Players.GetLocalByIndex(0);
309  int32_t iFirstLocalPlayer = pFirstLocalPlayer ? pFirstLocalPlayer->Number : NO_OWNER;
310  EvaluateGoals(Goals, FulfilledGoals, iFirstLocalPlayer);
311  iPlayingTime = Game.Time;
312 
313  // collect statistics
314  try
315  {
316  C4AulParSet Pars;
317  auto stats = ::ScriptEngine.GetPropList()->Call(PSF_CollectStatistics, &Pars);
318  if (stats != C4VNull)
319  Statistics = stats.ToJSON();
320  }
321  catch (C4JSONSerializationError& e)
322  {
323  DebugLogF("ERROR: cannot serialize CollectStatistics() result: %s", e.what());
324  }
325 }
C4PropListStatic * GetPropList()
Definition: C4Aul.h:153
C4Game Game
Definition: C4Globals.cpp:52
int32_t Number
Definition: C4Player.h:88
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
#define PSF_CollectStatistics
Definition: C4GameScript.h:105
static void EvaluateGoals(C4IDList &GoalList, C4IDList &FulfilledGoalList, int32_t iPlayerNumber)
virtual const char * what() const noexceptoverride
Definition: C4Value.h:69
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:281
C4PlayerList Players
int32_t Time
Definition: C4Game.h:133
C4Player * GetLocalByIndex(int iIndex) const
const int NO_OWNER
Definition: C4Constants.h:138
const C4Value C4VNull
Definition: C4Value.cpp:32
C4Value Call(C4PropertyName k, C4AulParSet *pPars=0, bool fPassErrors=false)
Definition: C4PropList.h:112

Here is the call graph for this function:

Here is the caller graph for this function:

void C4RoundResults::EvaluateGoals ( C4IDList GoalList,
C4IDList FulfilledGoalList,
int32_t  iPlayerNumber 
)
static

Definition at line 283 of file C4RoundResults.cpp.

References C4D_Goal, C4Id2Def(), C4PropList::Call(), C4IDList::Clear(), Definitions, C4ObjectList::Find(), C4ObjectList::GetListID(), C4DefList::ID2Def(), Objects, PSF_IsFulfilled, and C4IDList::SetIDCount().

Referenced by C4MainMenu::ActivateGoals(), and EvaluateGame().

284 {
285  // clear prev
286  GoalList.Clear(); FulfilledGoalList.Clear();
287  // Items
288  int32_t cnt; C4ID idGoal;
289  for (cnt=0; (idGoal=::Objects.GetListID(C4D_Goal,cnt)); cnt++)
290  {
291  // determine if the goal is fulfilled - do the calls even if the menu is not to be opened to ensure synchronization
292  bool fFulfilled = false;;
293  C4Object *pObj = C4Id2Def(idGoal) ? ::Objects.Find(::Definitions.ID2Def(idGoal)) : nullptr;
294  if (pObj)
295  {
296  // Check fulfilled per player, this enables the possibility of rivalry.
297  C4AulParSet pars(iPlayerNumber);
298  fFulfilled = !!pObj->Call(PSF_IsFulfilled, &pars);
299  }
300  GoalList.SetIDCount(idGoal, cnt, true);
301  if (fFulfilled) FulfilledGoalList.SetIDCount(idGoal, 1, true);
302  }
303 }
C4Def * ID2Def(C4ID id)
void Clear()
Definition: stub-handle.cpp:64
#define PSF_IsFulfilled
Definition: C4GameScript.h:84
Definition: C4Id.h:28
C4ID GetListID(int32_t dwCategory, int Index) const
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:80
C4Object * Find(C4Def *def, int iOwner=ANY_OWNER, DWORD dwOCF=OCF_All)
bool SetIDCount(C4ID c_id, int32_t iCount, bool fAddNewID=false)
Definition: stub-handle.cpp:68
const int32_t C4D_Goal
Definition: C4Def.h:48
C4DefList Definitions
Definition: C4Globals.cpp:49
C4Value Call(C4PropertyName k, C4AulParSet *pPars=0, bool fPassErrors=false)
Definition: C4PropList.h:112
C4GameObjects Objects
Definition: C4Globals.cpp:48

Here is the call graph for this function:

Here is the caller graph for this function:

void C4RoundResults::EvaluateLeague ( const char *  szResultMsg,
bool  fSuccess,
const C4RoundResultsPlayers rLeagueInfo 
)

Definition at line 337 of file C4RoundResults.cpp.

References C4RoundResultsPlayer::EvaluateLeague(), EvaluateNetwork(), Game, C4RoundResultsPlayers::GetByIndex(), C4RoundResultsPlayers::GetCreateByID(), C4RoundResultsPlayer::GetID(), NR_LeagueError, NR_LeagueOK, and C4Game::RoundResults.

Referenced by C4Network2Players::HandlePacket(), and C4Network2::LeagueEnd().

338 {
339  // League evaluation imples network evaluation
341  // Evaluation called by league: Sets new league scores and ranks
342  C4RoundResultsPlayer *pPlr, *pOwnPlr; int32_t i = 0;
343  while ((pPlr = rLeagueInfo.GetByIndex(i++)))
344  {
345  pOwnPlr = Players.GetCreateByID(pPlr->GetID());
346  pOwnPlr->EvaluateLeague(pPlr);
347  }
348 }
C4Game Game
Definition: C4Globals.cpp:52
void EvaluateNetwork(NetResult eResult, const char *szResultsString)
void EvaluateLeague(C4RoundResultsPlayer *pLeaguePlayer)
C4RoundResultsPlayer * GetByIndex(int32_t idx) const
C4PlayerList Players
C4RoundResults & RoundResults
Definition: C4Game.h:75
int32_t GetID() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4RoundResults::EvaluateNetwork ( C4RoundResults::NetResult  eNetResult,
const char *  szResultsString 
)

Definition at line 327 of file C4RoundResults.cpp.

References StdStrBuf::Clear(), StdStrBuf::Copy(), and HasNetResult().

Referenced by EvaluateLeague(), C4MainMenu::MenuCommand(), and C4Network2::OnClientDisconnect().

328 {
329  // take result only if there was no previous result (the previous one is usually more specific)
330  if (!HasNetResult())
331  {
332  this->eNetResult = eNetResult;
333  if (szResultMsg) sNetResult.Copy(szResultMsg); else sNetResult.Clear();
334  }
335 }
void Clear()
Definition: StdBuf.h:474
bool HasNetResult() const
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

void C4RoundResults::EvaluatePlayer ( C4Player pPlr)

Definition at line 350 of file C4RoundResults.cpp.

References C4RoundResultsPlayer::EvaluatePlayer(), C4RoundResultsPlayers::GetCreateByID(), and C4Player::ID.

Referenced by C4Player::Evaluate(), and C4PlayerList::Remove().

351 {
352  // Evaluation called by player when it's evaluated
353  assert(pPlr);
354  C4RoundResultsPlayer *pOwnPlr = Players.GetCreateByID(pPlr->ID);
355  pOwnPlr->EvaluatePlayer(pPlr);
356 }
void EvaluatePlayer(C4Player *pPlr)
C4PlayerList Players
int32_t ID
Definition: C4Player.h:89

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4RoundResults::GetCustomEvaluationStrings ( ) const
inline

Definition at line 197 of file C4RoundResults.h.

References StdStrBuf::getData().

Referenced by C4GameOverDlg::C4GameOverDlg().

197 { return sCustomEvaluationStrings.getData(); }
const char * getData() const
Definition: StdBuf.h:450

Here is the call graph for this function:

Here is the caller graph for this function:

const C4IDList& C4RoundResults::GetFulfilledGoals ( ) const
inline

Definition at line 206 of file C4RoundResults.h.

Referenced by C4GameOverDlg::C4GameOverDlg().

206 { return FulfilledGoals; }

Here is the caller graph for this function:

const C4IDList& C4RoundResults::GetGoals ( ) const
inline

Definition at line 205 of file C4RoundResults.h.

Referenced by C4GameOverDlg::C4GameOverDlg().

205 { return Goals; }

Here is the caller graph for this function:

int32_t C4RoundResults::GetLeaguePerformance ( int32_t  idPlayer = 0) const

Definition at line 398 of file C4RoundResults.cpp.

References C4RoundResultsPlayers::GetByID().

Referenced by C4Network2Reference::InitLocal().

399 {
400  if(!idPlayer)
401  return iLeaguePerformance;
402  else
403  if(C4RoundResultsPlayer *pPlr = Players.GetByID(idPlayer))
404  return pPlr->GetLeaguePerformance();
405  return 0;
406 }
C4PlayerList Players

Here is the call graph for this function:

Here is the caller graph for this function:

NetResult C4RoundResults::GetNetResult ( ) const
inline

Definition at line 198 of file C4RoundResults.h.

198 { return eNetResult; }
const char* C4RoundResults::GetNetResultString ( ) const
inline

Definition at line 199 of file C4RoundResults.h.

References StdStrBuf::getData().

Referenced by C4GameOverDlg::C4GameOverDlg().

199 { return sNetResult.getData(); }
const char * getData() const
Definition: StdBuf.h:450

Here is the call graph for this function:

Here is the caller graph for this function:

const C4RoundResultsPlayers& C4RoundResults::GetPlayers ( ) const
inline

Definition at line 196 of file C4RoundResults.h.

196 { return Players; }
C4PlayerList Players
StdCopyStrBuf C4RoundResults::GetStatistics ( ) const
inline

Definition at line 194 of file C4RoundResults.h.

Referenced by C4Network2Reference::InitLocal().

194 { return Statistics; }

Here is the caller graph for this function:

bool C4RoundResults::HasNetResult ( ) const
inline

Definition at line 200 of file C4RoundResults.h.

References NR_None.

Referenced by C4GameOverDlg::C4GameOverDlg(), and EvaluateNetwork().

200 { return eNetResult != NR_None; }

Here is the caller graph for this function:

void C4RoundResults::HideSettlementScore ( bool  fHide = true)

Definition at line 374 of file C4RoundResults.cpp.

375 {
376  fHideSettlementScore=fHide;
377 }
void C4RoundResults::Init ( )

Definition at line 255 of file C4RoundResults.cpp.

References C4Game::C4S, Game, C4Scenario::Game, and C4SGame::IsMelee().

Referenced by C4Game::InitGame().

256 {
257  if (Game.C4S.Game.IsMelee())
258  fHideSettlementScore=true;
259  else fHideSettlementScore=false;
260 }
bool IsMelee()
Definition: C4Scenario.cpp:510
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:76
C4SGame Game
Definition: C4Scenario.h:232

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4RoundResults::Load ( C4Group hGroup,
const char *  szFilename = C4CFN_RoundResults 
)

Definition at line 408 of file C4RoundResults.cpp.

References Clear(), C4Group::LoadEntryString(), and mkNamingAdapt().

Referenced by C4Game::InitGame().

409 {
410  // clear previous
411  Clear();
412  // load file contents
413  StdStrBuf Buf;
414  if (!hGroup.LoadEntryString(szFilename, &Buf)) return false;
415  // compile
416  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(*this, "RoundResults"), Buf, szFilename)) return false;
417  // done, success
418  return true;
419 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4RoundResults::Save ( C4Group hGroup,
const char *  szFilename = C4CFN_RoundResults 
)

Definition at line 421 of file C4RoundResults.cpp.

References C4Group::Add(), C4Group::DeleteEntry(), StdStrBuf::getLength(), and mkNamingAdapt().

422 {
423  // remove previous entry from group
424  hGroup.DeleteEntry(szFilename);
425  // decompile
426  try
427  {
428  StdStrBuf Buf = DecompileToBuf<StdCompilerINIWrite>(mkNamingAdapt(*this, "RoundResults"));
429  // save it, if not empty
430  if (Buf.getLength())
431  if (!hGroup.Add(szFilename, Buf, false, true))
432  return false;
433  }
434  catch (StdCompiler::Exception *)
435  { return false; }
436  // done, success
437  return true;
438 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
bool DeleteEntry(const char *szFilename, bool fRecycle=false)
Definition: C4Group.cpp:1384
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316
size_t getLength() const
Definition: StdBuf.h:453

Here is the call graph for this function:

void C4RoundResults::SetLeaguePerformance ( int32_t  iNewPerf,
int32_t  idPlayer = 0 
)

Definition at line 384 of file C4RoundResults.cpp.

References C4RoundResultsPlayers::GetCreateByID(), and C4RoundResultsPlayer::SetLeaguePerformance().

385 {
386  // Store to be sent later. idPlayer == 0 means global performance.
387  if(!idPlayer)
388  {
389  iLeaguePerformance = iNewPerf;
390  }
391  else
392  {
393  C4RoundResultsPlayer *pOwnPlr = Players.GetCreateByID(idPlayer);
394  pOwnPlr->SetLeaguePerformance(iNewPerf);
395  }
396  }
void SetLeaguePerformance(int32_t iNewPerf)
C4PlayerList Players

Here is the call graph for this function:

bool C4RoundResults::SettlementScoreIsHidden ( )

Definition at line 379 of file C4RoundResults.cpp.

380 {
381  return fHideSettlementScore;
382 }

The documentation for this class was generated from the following files: