void UpkeepPhase::FinishGraveyard(CommitSession& session, const Player& player) { LiveGame& game = GetGame(); const Colour c = game.GetTeam(player).GetColour(); VERIFY_MODEL(GetCurrentCmd(c) == nullptr); bool bOK = m_finished.insert(c).second; VERIFY_MODEL(bOK); const Controller& controller = session.GetController(); UpdateClient(controller, &player); if (m_finished.size() == game.GetTeams().size()) { session.DoAndPushRecord(RecordPtr(new StartRoundRecord)); if (game.HasFinished()) game.StartScorePhase(); // Deletes this. else game.StartActionPhase(); // Deletes this. game.GetPhase().UpdateClient(controller, nullptr); } session.GetController().SendMessage(Output::UpdateCurrentPlayers(session.GetGame()), session.GetGame()); }
void Phase::UndoCmd(CommitSession& session, Player& player) { LiveGame& game = GetGame(); VERIFY_MODEL_MSG(player.GetName(), &game == player.GetCurrentLiveGame()); const Colour colour = game.GetTeam(player).GetColour(); const Cmd* pCmd = GetCurrentCmd(colour); const Controller& controller = session.GetController(); if (Cmd* pUndo = RemoveCmd(session, colour)) { while (pUndo->GetRecordCount()) { // Update review games before record gets popped. for (auto& g : game.GetReviewGames()) g->OnPreRecordPop(controller); pUndo->PopRecord(session); } if (pUndo->IsAutoProcess()) // Also undo the command start. RemoveCmd(session, colour); } UpdateClient(controller, &player); }
void Phase::StartCmd(CmdPtr pCmd, CommitSession& session) { Colour c = pCmd->GetColour(); GetCmdStack(c).StartCmd(std::move(pCmd)); Cmd* pStartedCmd = GetCurrentCmd(c); if (pStartedCmd->IsAutoProcess()) { const Player& player = Players::Get(pStartedCmd->GetTeam(session.GetGame()).GetPlayerID()); ProcessCmdMessage(Input::CmdMessage(), session, player); } else pStartedCmd->UpdateClient(session.GetController(), GetGame()); }
void Phase::ProcessCmdMessage(const Input::CmdMessage& msg, CommitSession& session, const Player& player) { LiveGame& game = GetGame(); VERIFY_MODEL_MSG(player.GetName(), &game == player.GetCurrentLiveGame()); const Colour colour = game.GetTeam(player).GetColour(); Cmd* pCmd = GetCurrentCmd(colour); VERIFY_MODEL_MSG("No current command", !!pCmd); Cmd::ProcessResult result = pCmd->Process(msg, session); // Might be null. CmdStack& cmdStack = GetCmdStack(colour); cmdStack.AddCmd(std::move(result.next), std::move(result.queue)); if (cmdStack.GetCurrentCmd() == nullptr) OnCmdFinished(*pCmd, session); // This phase might have finished, get potentially new phase. game.GetPhase().UpdateClient(session.GetController(), &player); }
void CCommandLineDisplay::AutoCompleteSearch (void) // AutocompleteSearch // // Searches the global symbol table for matches to the current command. { const CString sCurCmd = GetCurrentCmd(); CString sCommon; CString sHelp; ClearHint(); if (sCurCmd.IsBlank()) return; // Get the list of global symbols ICCItem *pGlobals = g_pUniverse->GetCC().GetGlobals(); int iMatches = 0; for (int i = 0; i < pGlobals->GetCount(); i++) { CString sGlobal = pGlobals->GetKey(i); // Partial match if (strStartsWith(sGlobal, sCurCmd)) { if (iMatches == 0) sCommon = sGlobal; // If we have multiple matching commands then find the longest common stem else { int iLen = min(sCommon.GetLength(), sGlobal.GetLength()); char *pPos1 = sCommon.GetPointer(); char *pPos2 = sGlobal.GetPointer(); int i; for (i = 0; i < iLen; i++) { if (CharLower((LPTSTR)(BYTE)(*pPos1)) != CharLower((LPTSTR)(BYTE)(*pPos2))) break; pPos1++; pPos2++; } sCommon.Truncate(i); m_sHint.Append(CONSTLIT(" ")); } // Append the command to the auto complete hint m_sHint.Append(sGlobal); iMatches++; } if (strEquals(sGlobal, sCurCmd)) { // Exact match - get help text ICCItem *pItem = pGlobals->GetElement(i); if (pItem->IsPrimitive()) sHelp = pItem->GetHelp(); } } // If the common stem is longer than the current command, then auto complete if (sCommon.GetLength() > sCurCmd.GetLength()) Input(strSubString(sCommon, sCurCmd.GetLength(), -1)); // If we only have one match then no need to show hint as we have either // auto completed or will show help text insead if (iMatches == 1) m_sHint = NULL_STR; if (!sHelp.IsBlank()) { if (!m_sHint.IsBlank()) m_sHint.Append(CONSTLIT("\n")); m_sHint.Append(sHelp); } }