int CHighScoreList::AddEntry (const CGameRecord &NewEntry) // AddEntry // // Add another entry to the high score { int i, j; // Score of 0 doesn't count if (NewEntry.GetScore() == 0) return -1; // Modify the epitaph in the entry CGameRecord ModifiedEntry = NewEntry; if (strEquals(strWord(ModifiedEntry.GetEndGameEpitaph(), 0), CONSTLIT("was"))) ModifiedEntry.SetEndGameEpitaph(strSubString(ModifiedEntry.GetEndGameEpitaph(), 4, -1)); // Find a spot on the list for (i = 0; i < m_iCount; i++) { if (ModifiedEntry.GetScore() > m_List[i].GetScore()) break; } // If we are the end of the list, then we didn't make the // high score list. if (i == MAX_SCORES) return -1; // Otherwise, move all scores below us by one m_bModified = true; if (m_iCount < MAX_SCORES) m_iCount++; for (j = m_iCount-2; j >= i; j--) m_List[j+1] = m_List[j]; m_List[i] = ModifiedEntry; // Player name m_sMostRecentPlayerName = ModifiedEntry.GetPlayerName(); m_iMostRecentPlayerGenome = ModifiedEntry.GetPlayerGenome(); return i; }
void HexarcTest (CUniverse &Universe, CXMLElement *pCmdLine) { int i, j; CString sHostspec = pCmdLine->GetAttribute(OPTION_HOST); if (sHostspec.IsBlank()) sHostspec = HOSTSPEC_DEFAULT; CHTTPClientSession Session; if (!Connect(sHostspec, Session)) return; // Read the list of high scores for (j = 0; j < 5; j++) { CJSONValue Payload = CJSONValue(CJSONValue::typeObject); Payload.InsertHandoff(FIELD_MAX_GAMES, CJSONValue(100)); CJSONValue Result; if (!ServerCommand(Session, METHOD_OPTIONS, FUNC_HIGH_SCORE_GAMES, Payload, &Result)) { printf("%s\n", Result.AsString().GetASCIIZPointer()); return; } // For each adventure, print high score if (Result.GetCount() == 0) printf("No game records.\n"); else { for (i = 0; i < Result.GetCount(); i++) { const CJSONValue &Record = Result.GetElement(i); DWORD dwAdventure = (DWORD)Record.GetElement(FIELD_ADVENTURE).AsInt32(); if (dwAdventure == 0) continue; CGameRecord GameRecord; if (GameRecord.InitFromJSON(Record) != NOERROR) { printf("Unable to parse JSON record.\n"); continue; } DWORD dwAdventureUNID = GameRecord.GetAdventureUNID(); CString sUsername = GameRecord.GetUsername(); int iScore = GameRecord.GetScore(); printf("%x %s %d\n", dwAdventureUNID, sUsername.GetASCIIZPointer(), iScore); } } } }
void CAdventureDesc::FireOnGameEnd (const CGameRecord &Game, const SBasicGameStats &BasicStats) // FireOnGameEnd // // Fire OnGameEnd event { SEventHandlerDesc Event; if (FindEventHandler(ON_GAME_END_EVENT, &Event)) { CCodeChainCtx Ctx; // Initialize variables Ctx.DefineInteger(CONSTLIT("aScore"), Game.GetScore()); Ctx.DefineInteger(CONSTLIT("aResurrectCount"), Game.GetResurrectCount()); Ctx.DefineInteger(CONSTLIT("aSystemsVisited"), BasicStats.iSystemsVisited); Ctx.DefineInteger(CONSTLIT("aEnemiesDestroyed"), BasicStats.iEnemiesDestroyed); Ctx.DefineInteger(CONSTLIT("aBestEnemiesDestroyed"), BasicStats.iBestEnemyDestroyedCount); if (BasicStats.dwBestEnemyDestroyed) Ctx.DefineInteger(CONSTLIT("aBestEnemyClass"), BasicStats.dwBestEnemyDestroyed); else Ctx.DefineNil(CONSTLIT("aBestEnemyClass")); Ctx.DefineString(CONSTLIT("aEndGameReason"), Game.GetEndGameReason()); Ctx.DefineString(CONSTLIT("aEpitaph"), Game.GetEndGameEpitaph()); Ctx.DefineString(CONSTLIT("aEpitaphOriginal"), Game.GetEndGameEpitaph()); Ctx.DefineString(CONSTLIT("aTime"), Game.GetPlayTimeString()); // Invoke ICCItem *pResult = Ctx.Run(Event); if (pResult->IsError()) kernelDebugLogMessage("OnGameEnd error: %s", pResult->GetStringValue()); Ctx.Discard(pResult); } }
void CTranscendenceWnd::CreateScoreAnimation (const CGameRecord &Stats, IAnimatron **retpAnimatron) // CreateScoreAnimation // // Creates an animation of the given score { int i; int iDuration = 300; int x = m_rcIntroMain.left + RectWidth(m_rcIntroMain) / 2; int y = m_rcIntroMain.bottom - RectHeight(m_rcIntroMain) / 3; // Create sequencer to hold everything CAniSequencer *pSeq = new CAniSequencer; // Create the score CAniText *pCredit = new CAniText; pCredit->SetPropertyVector(CONSTLIT("position"), CVector((Metric)x, (Metric)y)); pCredit->SetPropertyColor(CONSTLIT("color"), m_Fonts.rgbTitleColor); pCredit->SetPropertyString(CONSTLIT("text"), strFromInt(Stats.GetScore())); pCredit->SetPropertyFont(CONSTLIT("font"), &m_Fonts.Title); pCredit->SetFontFlags(CG16bitFont::AlignCenter); pCredit->AnimateLinearFade(iDuration, 30, 30); pSeq->AddTrack(pCredit, 0); y += m_Fonts.Title.GetHeight(); // Player name CAniText *pName = new CAniText; pName->SetPropertyVector(CONSTLIT("position"), CVector((Metric)x, (Metric)y)); pName->SetPropertyColor(CONSTLIT("color"), m_Fonts.rgbTextColor); pName->SetPropertyString(CONSTLIT("text"), Stats.GetPlayerName()); pName->SetPropertyFont(CONSTLIT("font"), &m_Fonts.SubTitle); pName->SetFontFlags(CG16bitFont::AlignCenter); pName->AnimateLinearFade(iDuration, 30, 30); pSeq->AddTrack(pName, 5); y += m_Fonts.SubTitle.GetHeight(); // Epitaph TArray<CString> EpitaphLines; m_Fonts.Header.BreakText(strCapitalize(Stats.GetEndGameEpitaph()), 512, &EpitaphLines); for (i = 0; i < EpitaphLines.GetCount(); i++) { CAniText *pLine = new CAniText; pLine->SetPropertyVector(CONSTLIT("position"), CVector((Metric)x, (Metric)y)); pLine->SetPropertyColor(CONSTLIT("color"), m_Fonts.rgbTextColor); pLine->SetPropertyString(CONSTLIT("text"), EpitaphLines[i]); pLine->SetPropertyFont(CONSTLIT("font"), &m_Fonts.Header); pLine->SetFontFlags(CG16bitFont::AlignCenter); pLine->AnimateLinearFade(iDuration, 30, 30); pSeq->AddTrack(pLine, 5); y += m_Fonts.Header.GetHeight(); } // Done *retpAnimatron = pSeq; }