OpenClonk
C4RoundResults Class Reference

#include <C4RoundResults.h>

Public Types

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

Public Member Functions

 C4RoundResults ()=default
 
 ~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

◆ NetResult

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::C4RoundResults ( )
default

◆ ~C4RoundResults()

C4RoundResults::~C4RoundResults ( )
inline

Definition at line 156 of file C4RoundResults.h.

156 { Clear(); }

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ AddCustomEvaluationString()

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

Definition at line 357 of file C4RoundResults.cpp.

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

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

Here is the call graph for this function:

◆ Clear()

void C4RoundResults::Clear ( )

Definition at line 241 of file C4RoundResults.cpp.

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

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileFunc()

void C4RoundResults::CompileFunc ( StdCompiler pComp)

Definition at line 261 of file C4RoundResults.cpp.

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

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

Here is the call graph for this function:

◆ EvaluateGame()

void C4RoundResults::EvaluateGame ( )

Definition at line 304 of file C4RoundResults.cpp.

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

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EvaluateGoals()

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

Definition at line 282 of file C4RoundResults.cpp.

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

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EvaluateLeague()

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

Definition at line 336 of file C4RoundResults.cpp.

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

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EvaluateNetwork()

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

Definition at line 326 of file C4RoundResults.cpp.

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

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EvaluatePlayer()

void C4RoundResults::EvaluatePlayer ( C4Player pPlr)

Definition at line 349 of file C4RoundResults.cpp.

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

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCustomEvaluationStrings()

const char* C4RoundResults::GetCustomEvaluationStrings ( ) const
inline

Definition at line 197 of file C4RoundResults.h.

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

References StdStrBuf::getData().

Referenced by C4GameOverDlg::C4GameOverDlg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFulfilledGoals()

const C4IDList& C4RoundResults::GetFulfilledGoals ( ) const
inline

Definition at line 206 of file C4RoundResults.h.

206 { return FulfilledGoals; }

Referenced by C4GameOverDlg::C4GameOverDlg().

Here is the caller graph for this function:

◆ GetGoals()

const C4IDList& C4RoundResults::GetGoals ( ) const
inline

Definition at line 205 of file C4RoundResults.h.

205 { return Goals; }

Referenced by C4GameOverDlg::C4GameOverDlg().

Here is the caller graph for this function:

◆ GetLeaguePerformance()

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

Definition at line 397 of file C4RoundResults.cpp.

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

References C4RoundResultsPlayers::GetByID().

Here is the call graph for this function:

◆ GetNetResult()

NetResult C4RoundResults::GetNetResult ( ) const
inline

Definition at line 198 of file C4RoundResults.h.

198 { return eNetResult; }

◆ GetNetResultString()

const char* C4RoundResults::GetNetResultString ( ) const
inline

Definition at line 199 of file C4RoundResults.h.

199 { return sNetResult.getData(); }

References StdStrBuf::getData().

Referenced by C4GameOverDlg::C4GameOverDlg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPlayers()

const C4RoundResultsPlayers& C4RoundResults::GetPlayers ( ) const
inline

Definition at line 196 of file C4RoundResults.h.

196 { return Players; }

References Players.

◆ GetStatistics()

StdCopyStrBuf C4RoundResults::GetStatistics ( ) const
inline

Definition at line 194 of file C4RoundResults.h.

194 { return Statistics; }

◆ HasNetResult()

bool C4RoundResults::HasNetResult ( ) const
inline

Definition at line 200 of file C4RoundResults.h.

200 { return eNetResult != NR_None; }

References NR_None.

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

Here is the caller graph for this function:

◆ HideSettlementScore()

void C4RoundResults::HideSettlementScore ( bool  fHide = true)

Definition at line 373 of file C4RoundResults.cpp.

374 {
375  fHideSettlementScore=fHide;
376 }

◆ Init()

void C4RoundResults::Init ( )

Definition at line 254 of file C4RoundResults.cpp.

255 {
256  if (Game.C4S.Game.IsMelee())
257  fHideSettlementScore=true;
258  else fHideSettlementScore=false;
259 }

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

Here is the call graph for this function:

◆ Load()

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

Definition at line 407 of file C4RoundResults.cpp.

408 {
409  // clear previous
410  Clear();
411  // load file contents
412  StdStrBuf Buf;
413  if (!hGroup.LoadEntryString(szFilename, &Buf)) return false;
414  // compile
415  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(*this, "RoundResults"), Buf, szFilename)) return false;
416  // done, success
417  return true;
418 }
bool LoadEntryString(const char *entry_name, StdStrBuf *buffer)
Definition: C4Group.cpp:2430

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

Here is the call graph for this function:

◆ Save()

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

Definition at line 420 of file C4RoundResults.cpp.

421 {
422  // remove previous entry from group
423  hGroup.DeleteEntry(szFilename);
424  // decompile
425  try
426  {
427  StdStrBuf Buf = DecompileToBuf<StdCompilerINIWrite>(mkNamingAdapt(*this, "RoundResults"));
428  // save it, if not empty
429  if (Buf.getLength())
430  if (!hGroup.Add(szFilename, Buf, false, true))
431  return false;
432  }
433  catch (StdCompiler::Exception *)
434  { return false; }
435  // done, success
436  return true;
437 }
bool DeleteEntry(const char *filename, bool do_recycle=false)
Definition: C4Group.cpp:1695
bool Add(const char *filename, const char *entry_name)
Definition: C4Group.cpp:1621

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

Here is the call graph for this function:

◆ SetLeaguePerformance()

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

Definition at line 383 of file C4RoundResults.cpp.

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

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

Here is the call graph for this function:

◆ SettlementScoreIsHidden()

bool C4RoundResults::SettlementScoreIsHidden ( )

Definition at line 378 of file C4RoundResults.cpp.

379 {
380  return fHideSettlementScore;
381 }

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