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

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 ( )
default
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 357 of file C4RoundResults.cpp.

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

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 AppendChar(char cChar)
Definition: StdBuf.h:588
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
C4PlayerList Players
void AddCustomEvaluationString(const char *szCustomString)
size_t getLength() const
Definition: StdBuf.h:445

Here is the call graph for this function:

void C4RoundResults::Clear ( )

Definition at line 241 of file C4RoundResults.cpp.

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

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

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

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 }
Definition: StdAdaptors.h:762
bool IsMelee()
Definition: C4Scenario.cpp:510
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
C4PlayerList Players
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
C4SGame Game
Definition: C4Scenario.h:232

Here is the call graph for this function:

void C4RoundResults::EvaluateGame ( )

Definition at line 304 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().

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 }
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
C4Game Game
Definition: C4Globals.cpp:52
int32_t Number
Definition: C4Player.h:86
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
#define PSF_CollectStatistics
Definition: C4GameScript.h:105
static void EvaluateGoals(C4IDList &GoalList, C4IDList &FulfilledGoalList, int32_t iPlayerNumber)
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:278
C4PlayerList Players
int32_t Time
Definition: C4Game.h:131
C4Player * GetLocalByIndex(int iIndex) const
const int NO_OWNER
Definition: C4Constants.h:138
const C4Value C4VNull
Definition: C4Value.cpp:30
const char * what() const noexceptoverride
Definition: C4Value.h:69
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:110

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

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 }
C4Def * ID2Def(C4ID id)
void Clear()
Definition: stub-handle.cpp:64
#define PSF_IsFulfilled
Definition: C4GameScript.h:84
Definition: C4Id.h:25
C4ID GetListID(int32_t dwCategory, int Index) const
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:84
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:46
C4DefList Definitions
Definition: C4Globals.cpp:49
C4GameObjects Objects
Definition: C4Globals.cpp:48
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:110

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

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 }
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:73
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 326 of file C4RoundResults.cpp.

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

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

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 }
void Clear()
Definition: StdBuf.h:466
bool HasNetResult() const
void Copy()
Definition: StdBuf.h:467

Here is the call graph for this function:

Here is the caller graph for this function:

void C4RoundResults::EvaluatePlayer ( C4Player pPlr)

Definition at line 349 of file C4RoundResults.cpp.

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

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

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 }
void EvaluatePlayer(C4Player *pPlr)
C4PlayerList Players
int32_t ID
Definition: C4Player.h:87

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:442

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 397 of file C4RoundResults.cpp.

References C4RoundResultsPlayers::GetByID().

Referenced by C4Network2Reference::InitLocal().

398 {
399  if(!idPlayer)
400  return iLeaguePerformance;
401  else
402  if(C4RoundResultsPlayer *pPlr = Players.GetByID(idPlayer))
403  return pPlr->GetLeaguePerformance();
404  return 0;
405 }
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:442

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 373 of file C4RoundResults.cpp.

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

Definition at line 254 of file C4RoundResults.cpp.

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

Referenced by C4Game::InitGame().

255 {
256  if (Game.C4S.Game.IsMelee())
257  fHideSettlementScore=true;
258  else fHideSettlementScore=false;
259 }
bool IsMelee()
Definition: C4Scenario.cpp:510
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
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 407 of file C4RoundResults.cpp.

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

Referenced by C4Game::InitGame().

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 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
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 420 of file C4RoundResults.cpp.

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

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 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
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:445

Here is the call graph for this function:

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

Definition at line 383 of file C4RoundResults.cpp.

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

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)
C4PlayerList Players

Here is the call graph for this function:

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: