void MapSettingsControl::SetMapSettings(const AtObj& obj) { m_MapSettings = obj; m_MapSettings.NotifyObservers(); SendToEngine(); }
void OnEditSpin(wxSpinEvent& WXUNUSED(evt)) { if (!m_InGUIUpdate) { SendToEngine(); } }
void OnEdit(wxCommandEvent& WXUNUSED(evt)) { if (!m_InGUIUpdate) { SendToEngine(); } }
void OnNumPlayersSpin(wxSpinEvent& evt) { if (!m_InGUIUpdate) { wxASSERT(evt.GetInt() > 0); // When wxMessageBox pops up, wxSpinCtrl loses focus, which // forces another EVT_SPINCTRL event, which we don't want // to handle, so we check here for a change if (evt.GetInt() == (int)m_NumPlayers) { return; // No change } size_t oldNumPlayers = m_NumPlayers; m_NumPlayers = evt.GetInt(); if (m_NumPlayers < oldNumPlayers) { // Remove players, but check if they own any entities bool notified = false; for (size_t i = oldNumPlayers; i > m_NumPlayers; --i) { qGetPlayerObjects objectsQry(i); objectsQry.Post(); std::vector<AtlasMessage::ObjectID> ids = *objectsQry.ids; if (ids.size() > 0) { if (!notified) { // TODO: Add option to reassign objects? if (wxMessageBox(_("WARNING: All objects belonging to the removed players will be deleted. Continue anyway?"), _("Remove player confirmation"), wxICON_EXCLAMATION | wxYES_NO) != wxYES) { // Restore previous player count m_NumPlayers = oldNumPlayers; wxDynamicCast(FindWindow(ID_NumPlayers), wxSpinCtrl)->SetValue(m_NumPlayers); return; } notified = true; } // Delete objects // TODO: Merge multiple commands? POST_COMMAND(DeleteObjects, (ids)); } } } m_Players->ResizePlayers(m_NumPlayers); SendToEngine(); // Reload players, notify observers POST_MESSAGE(LoadPlayerSettings, (true)); m_MapSettings.NotifyObservers(); } }
void OnPlayerColour(wxCommandEvent& WXUNUSED(evt)) { if (!m_InGUIUpdate) { SendToEngine(); // Update player settings, to show new colour POST_MESSAGE(LoadPlayerSettings, (false)); } }
void Detach() { // Chatmode(""); // just leave chatmode.. otherwise that would could be serious disasters lol, oh and you could be getting messages lol Logged_in=0; attached=0; discovered=0; SendToEngine("KAI_CLIENT_DETACH;"); // Clean up global vars, free in-use pointers pthread_cancel(bcreceive); // cancel the thread... }
void Detach() { Chatmode(""); // just leave chatmode.. otherwise that would could be serious disasters lol, oh and you could be getting messages lol Logged_in=0; attached=0; discovered=0; EnterCriticalSection(&critical_section_network); SendToEngine("KAI_CLIENT_DETACH;"); LeaveCriticalSection(&critical_section_network); // TerminateThread(bcreceive,dw); // cancel the thread... }
/* * Solves a position given in an EPD file. */ void SolvePosition( char move[], const char position[] ) { char msg[BUF_SIZE]=""; char engineinput[BUF_SIZE]=""; int solved = 0; printf( "\nSolve position:\n\t%s\n", position ); /* Send position to adapter/engine. */ strcpy( msg, "setboard " ); strcat( msg, position ); msg[strlen(msg)-1] = '\0'; SendToEngine( msg ); /* Set adapter/engine to analyse. */ sprintf( msg, "st %d\ngo", (int)round( SearchTime ) ); SendToEngine( msg ); /* Read adapter/engine's answer (the move). */ while ( ( ! ReadFromEngine() ) || ( ! solved ) ) { if ( strlen( engineinputbuf ) > 0 ) { GetNextLineNoRemove( engineinputbuf, engineinput ); assert( strlen( engineinput ) > 0 ); if ( strncmp( engineinput, "move", 4 ) == 0 ) { solved = 1; break; } else { GetNextLine( engineinputbuf, engineinput ); printf( "%s\n", engineinput ); } } sleep( 0 ); } NextEngineCmd(); strcpy( move, SANmv ); }
/* * Extracts a command from the user input buffer. * * The command is removed from the buffer. * If the command must be sent to the engine, it is sent. * This function relies on parse_input(). */ void NextUserCmd( void ) { char userinput[BUF_SIZE]=""; if ( strlen( userinputbuf ) > 0 ) { printf("TimeLimit[0] = %g\n", TimeLimit[0]); printf("TimeLimit[1] = %g\n", TimeLimit[1]); if ( flags & XBOARD ) { fflush( stdout ); } if ( GetNextLine( userinputbuf, userinput ) > 0 ) { strcpy( inputstr, "" ); strcpy( inputstr, userinput ); dbg_printf( "USER >: %s\n", userinput ); parse_input(); /* Check if command/move must be sent to engine */ if ( GetDataToEngine( dataToEngine ) ) { dbg_printf( "> ENGINE: %s\n", dataToEngine ); SendToEngine( dataToEngine ); if ( GetAutoGo() && UserInputIsAValidMove() ) { strcpy( userinputbuf, "go\n" ); SetAutoGo( false ); } } showprompt = !AnswerFromEngineExpected(); /* Check if command was entered in manual mode */ if ( (flags & MANUAL) && UserInputIsAValidMove() ) { RealGameCnt = GameCnt; RealSide = board.side; showprompt = 1; } /* Check if the color must be changed, e.g. after an undo command. */ if ( changeColor ) { RealGameCnt = GameCnt; RealSide = board.side; } } } }
void OnEdit(wxCommandEvent& WXUNUSED(evt)) { SendToEngine(); }
void PlayerSettingsControl::ReadFromEngine() { AtlasMessage::qGetMapSettings qry; qry.Post(); if (!(*qry.settings).empty()) { // Prevent error if there's no map settings to parse m_MapSettings = AtlasObject::LoadFromJSON(*qry.settings); } else { // Use blank object, it will be created next m_MapSettings = AtObj(); } AtIter player = m_MapSettings["PlayerData"]["item"]; if (!m_MapSettings.defined() || !player.defined() || player.count() == 0) { // Player data missing - set number of players to max m_NumPlayers = MAX_NUM_PLAYERS; } else m_NumPlayers = player.count(); wxASSERT(m_NumPlayers <= MAX_NUM_PLAYERS && m_NumPlayers != 0); // To prevent recursion, don't handle GUI events right now m_InGUIUpdate = true; wxDynamicCast(FindWindow(ID_NumPlayers), wxSpinCtrl)->SetValue(m_NumPlayers); // Remove / add extra player pages as needed m_Players->ResizePlayers(m_NumPlayers); // Update player controls with player data AtIter playerDefs = m_PlayerDefaults["item"]; if (playerDefs.defined()) ++playerDefs; // skip gaia for (size_t i = 0; i < MAX_NUM_PLAYERS; ++i) { const PlayerPageControls& controls = m_PlayerControls[i]; // name wxString name(_("Unknown")); bool defined = player["Name"].defined(); if (defined) name = wxString(player["Name"]); else if (playerDefs["Name"].defined()) name = wxString(playerDefs["Name"]); controls.name->SetValue(name); wxDynamicCast(FindWindowById(ID_DefaultName, controls.page), DefaultCheckbox)->SetValue(defined); // civ wxChoice* choice = controls.civ; wxString civCode; defined = player["Civ"].defined(); if (defined) civCode = wxString(player["Civ"]); else civCode = wxString(playerDefs["Civ"]); for (size_t j = 0; j < choice->GetCount(); ++j) { wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(j)); if (str->GetData() == civCode) { choice->SetSelection(j); break; } } wxDynamicCast(FindWindowById(ID_DefaultCiv, controls.page), DefaultCheckbox)->SetValue(defined); // colour wxColour colour; AtObj clrObj = *player["Colour"]; defined = clrObj.defined(); if (!defined) clrObj = *playerDefs["Colour"]; colour = wxColor((*clrObj["r"]).getInt(), (*clrObj["g"]).getInt(), (*clrObj["b"]).getInt()); controls.colour->SetBackgroundColour(colour); wxDynamicCast(FindWindowById(ID_DefaultColour, controls.page), DefaultCheckbox)->SetValue(defined); // player type wxString aiID; defined = player["AI"].defined(); if (defined) aiID = wxString(player["AI"]); else aiID = wxString(playerDefs["AI"]); choice = controls.ai; if (!aiID.empty()) { // AI for (size_t j = 0; j < choice->GetCount(); ++j) { wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(j)); if (str->GetData() == aiID) { choice->SetSelection(j); break; } } } else // Human choice->SetSelection(0); wxDynamicCast(FindWindowById(ID_DefaultAI, controls.page), DefaultCheckbox)->SetValue(defined); // resources AtObj resObj = *player["Resources"]; defined = resObj.defined() && resObj["food"].defined(); if (defined) controls.food->SetValue(wxString(resObj["food"])); else controls.food->SetValue(0); wxDynamicCast(FindWindowById(ID_DefaultFood, controls.page), DefaultCheckbox)->SetValue(defined); defined = resObj.defined() && resObj["wood"].defined(); if (defined) controls.wood->SetValue(wxString(resObj["wood"])); else controls.wood->SetValue(0); wxDynamicCast(FindWindowById(ID_DefaultWood, controls.page), DefaultCheckbox)->SetValue(defined); defined = resObj.defined() && resObj["metal"].defined(); if (defined) controls.metal->SetValue(wxString(resObj["metal"])); else controls.metal->SetValue(0); wxDynamicCast(FindWindowById(ID_DefaultMetal, controls.page), DefaultCheckbox)->SetValue(defined); defined = resObj.defined() && resObj["stone"].defined(); if (defined) controls.stone->SetValue(wxString(resObj["stone"])); else controls.stone->SetValue(0); wxDynamicCast(FindWindowById(ID_DefaultStone, controls.page), DefaultCheckbox)->SetValue(defined); // population limit defined = player["PopulationLimit"].defined(); if (defined) controls.pop->SetValue(wxString(player["PopulationLimit"])); else controls.pop->SetValue(0); wxDynamicCast(FindWindowById(ID_DefaultPop, controls.page), DefaultCheckbox)->SetValue(defined); // team defined = player["Team"].defined(); if (defined) controls.team->SetSelection((*player["Team"]).getInt() + 1); else controls.team->SetSelection(0); wxDynamicCast(FindWindowById(ID_DefaultTeam, controls.page), DefaultCheckbox)->SetValue(defined); // camera if (player["StartingCamera"].defined()) { sCameraInfo info; // Don't use wxAtof because it depends on locales which // may cause problems with decimal points // see: http://www.wxwidgets.org/docs/faqgtk.htm#locale AtObj camPos = *player["StartingCamera"]["Position"]; info.pX = (float)(*camPos["x"]).getDouble(); info.pY = (float)(*camPos["y"]).getDouble(); info.pZ = (float)(*camPos["z"]).getDouble(); AtObj camRot = *player["StartingCamera"]["Rotation"]; info.rX = (float)(*camRot["x"]).getDouble(); info.rY = (float)(*camRot["y"]).getDouble(); info.rZ = (float)(*camRot["z"]).getDouble(); controls.page->SetCamera(info, true); } else controls.page->SetCamera(sCameraInfo(), false); // Only increment AtIters if they are defined if (player.defined()) ++player; if (playerDefs.defined()) ++playerDefs; } // Send default properties to engine, since they might not be set SendToEngine(); m_InGUIUpdate = false; }