void CPreGame::ReadDataFromDemo(const std::string& demoName) { logOutput.Print("Pre-scanning demo file for game data..."); CDemoReader scanner(demoName, 0); unsigned char demobuffer[netcode::NETWORK_BUFFER_SIZE]; unsigned length = 0; mapName = ""; modName = ""; scriptName = ""; while ( (length = scanner.GetData(demobuffer, netcode::NETWORK_BUFFER_SIZE, INT_MAX)) > 0 && (mapName.empty() || modName.empty() || scriptName.empty())) { if (demobuffer[0] == NETMSG_MAPNAME) { SelectMap((char*) (demobuffer + 6)); archiveScanner->CheckMap(mapName, *(unsigned*) (demobuffer + 2)); } else if (demobuffer[0] == NETMSG_MODNAME) { SelectMod((char*) (demobuffer + 6)); archiveScanner->CheckMod(modArchive, *(unsigned*) (demobuffer + 2)); } else if (demobuffer[0] == NETMSG_SCRIPT) { CScriptHandler::SelectScript((char*) (demobuffer+2)); SelectScript((char*) (demobuffer+2)); } if (scanner.ReachedEnd()) { logOutput.Print("End of demo reached and no data found"); } } }
void CChildView::OnSelectmap() { // TODO: Add your command handler code here //my SelectMap( false ); //end }
void CChildView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default //my unsigned char result=bm.PointAt(point); switch(result){ case BM_ERROR_PIONT_OUT: MessageBox( L"你搞笑吗?\r\n\r\n那里是墙外!", L"ERROR", MB_ICONEXCLAMATION | MB_ICONWARNING ); break; case BM_ERROR_POINT_MAN: break; case BM_ERROR_POINT_WALL: MessageBox( L"对不起,那里是墙.\r\n\r\n我不想撞墙自尽!", L"ERROR", MB_ICONEXCLAMATION | MB_ICONWARNING ); break; case BM_MAN_MOVED: break; case BM_BOX_MOVED: bm.m_TheShowStep = 0; break; case BM_MOVED_OK: SelectMap( true ); break; case BM_ERROR_CANNOT_MOVE_THERE: MessageBox( L"有东西挡着,\r\n\r\n不能移动到那里去!", L"ERROR", MB_ICONEXCLAMATION | MB_ICONWARNING ); break; case BM_MOVED_TO_BAD_POINT: MessageBox( L"这个地方不能推进去,\n进去就出不来了!", L"ERROR", MB_ICONASTERISK | MB_ICONINFORMATION ); break; } //end CWnd::OnLButtonUp(nFlags, point); }
void SelectRandom() { if(m_SourceCollection().empty()) return; uint32 selection = Random::IntRange(0, (int32)m_SourceCollection().size() - 1); auto it = m_SourceCollection().begin(); std::advance(it, selection); SelectMap(it->first); }
void MapGridCtrl::OnLeftUp(wxMouseEvent& event) { SetCursor(wxCursor(wxCURSOR_ARROW)); m_in_mouse_drag = false; if (wxPoint2DInt(event.GetPosition() - m_first_mouse_pos).GetVectorLength() <= 3) { SelectMap(m_mouseover_map); } }
void CChildView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default //my bool keydown = false; unsigned char result; switch( nChar ){ case VK_RIGHT: result=bm.MoveTowards( 1, 0 ); keydown = true; break; case VK_UP: result=bm.MoveTowards( 0, -1 ); keydown = true; break; case VK_LEFT: result=bm.MoveTowards( -1, 0 ); keydown = true; break; case VK_DOWN: result=bm.MoveTowards( 0, 1 ); keydown = true; break; /* case VK_CONTROL: if ( bm.m_CanUndo && !(bool)((nFlags>>14)&0x01) ) bm.Undo(); break; case VK_SPACE: bm.ThinkTheWay(); MessageBox( "Ok" ); */ } if ( keydown ){ switch (result){ case BM_MOVED_OK: SelectMap(true); break; case BM_BOX_MOVED: bm.m_TheShowStep=0; break; case BM_MOVED_TO_BAD_POINT: MessageBox( L"这个地方不能推进去,\n进去就出不来了!", L"PROMPT", MB_ICONASTERISK | MB_ICONINFORMATION ); break; } } //end CWnd::OnKeyDown(nChar, nRepCnt, nFlags); }
void MapGridCtrl::OnMouseMove(wxMouseEvent& event) { SetCursor(wxCursor(wxCURSOR_HAND)); if (m_in_mouse_drag) { // Fix for for not receiving LeftUp event when left button // is released outside the control (happens on Windows.) if (!event.LeftIsDown()) { OnLeftUp(event); return; } m_pos -= (event.GetPosition() - m_last_mouse_pos); m_last_mouse_pos = event.GetPosition(); CheckInBounds(); Refresh(); } else { const wxPoint pos_unscaled = event.GetPosition() + m_pos; const wxPoint pos = wxPoint2DInt(pos_unscaled) / (MINIMAP_SIZE + MINIMAP_MARGIN); const int idx = pos.y * m_size.x + pos.x; MapData* old_mouseover_map = m_mouseover_map; // use pos_unscaled for tests against 0 because negative values lower // than MINIMAP_SIZE get rounded up to 0 when diviving by MINIMAP_SIZE.. if (pos_unscaled.x >= 0 && pos.x < m_size.x && pos_unscaled.y >= 0 && pos.y <= m_size.y && idx < (int)m_grid.size()) { m_mouseover_map = m_grid[idx]; } else { m_mouseover_map = NULL; } if (m_mouseover_map != old_mouseover_map) { if (m_selection_follows_mouse && m_mouseover_map != NULL) { SelectMap(m_mouseover_map); } } } }
void AdvanceSelection(int32 offset) { auto& srcCollection = m_SourceCollection(); auto it = srcCollection.find(m_currentlySelectedId); if(it == srcCollection.end()) { if(srcCollection.empty()) { // Remove all elements, empty m_currentSelection.Release(); Clear(); m_guiElements.clear(); return; } it = srcCollection.begin(); } for(uint32 i = 0; i < (uint32)abs(offset); i++) { auto itn = it; if(offset < 0) { if(itn == srcCollection.begin()) break; itn--; } else itn++; if(itn == srcCollection.end()) break; it = itn; } if(it != srcCollection.end()) { SelectMap(it->first); } }
CPreGame::CPreGame(bool server, const string& demo): showList(0), server(server), state(UNKNOWN), saveAddress(true) { CommandDescription::Init(); infoConsole = SAFE_NEW CInfoConsole; pregame = this; // prevent crashes if Select* is called from ctor net = SAFE_NEW CNet; if (server) { assert(good_fpu_control_registers()); gameServer = SAFE_NEW CGameServer; assert(good_fpu_control_registers()); } //hpiHandler=SAFE_NEW CHpiHandler(); activeController=this; inbufpos=0; inbuflength=0; if(!gameSetup){ for(int a=0;a<gs->activeTeams;a++){ for(int b=0;b<4;++b) gs->Team(a)->color[b]=palette.teamColor[a][b]; } } if(server){ if(gameSetup){ CScriptHandler::SelectScript(gameSetup->scriptName); SelectMap(gameSetup->mapname); SelectMod(gameSetup->baseMod); state = ALL_READY; } else { ShowScriptList(); state = WAIT_ON_SCRIPT; } } else { if(gameSetup){ PrintLoadMsg("Connecting to server"); if(net->InitClient(gameSetup->hostip.c_str(),gameSetup->hostport,gameSetup->sourceport)==-1){ handleerror(0,"Client couldn't connect","PreGame error",0); exit(-1); } CScriptHandler::SelectScript(gameSetup->scriptName); SelectMap(gameSetup->mapname); SelectMod(gameSetup->baseMod); state = ALL_READY; } else { if (demo != "") { userInput = demo; state = WAIT_ON_ADDRESS; userWriting = false; saveAddress = false; } else { userInput=configHandler.GetString("address",""); userPrompt = "Enter server address: "; state = WAIT_ON_ADDRESS; userWriting = true; } } } assert(state != UNKNOWN); }
void CPreGame::UpdateClientNet() { int a; if((a=net->GetData(&inbuf[inbuflength],15000-inbuflength,0))==-1){ globalQuit=true; return; } inbuflength+=a; while(inbufpos<inbuflength){ switch (inbuf[inbufpos]){ case NETMSG_HELLO: inbufpos += 1; break; case NETMSG_SCRIPT: CScriptHandler::SelectScript((char*)(&inbuf[inbufpos+2])); if (mapName.empty()) state = WAIT_ON_MAP; else if (modName.empty()) state = WAIT_ON_MOD; else state = ALL_READY; inbufpos += inbuf[inbufpos+1]; break; case NETMSG_MAPNAME: SelectMap((char*)(&inbuf[inbufpos+6])); if (GetMapChecksum() != *(unsigned*)(&inbuf[inbufpos+2])) { char buf[256]; sprintf(buf, "Local map archive(s) are not binary equal to host map archive(s).\n" "Make sure you installed all map dependencies & consider redownloading the map." "\n\nLocal checksum = %u\nRemote checksum = %u", GetMapChecksum(), *(unsigned*)(&inbuf[inbufpos+2])); throw content_error(buf); } if (!CScriptHandler::Instance().chosenScript) state = WAIT_ON_SCRIPT; else if (modName.empty()) state = WAIT_ON_MOD; else state = ALL_READY; inbufpos += inbuf[inbufpos+1]; break; case NETMSG_MODNAME: SelectMod((char*)(&inbuf[inbufpos+6])); if (GetModChecksum() != *(unsigned*)(&inbuf[inbufpos+2])) { char buf[256]; sprintf(buf, "Local mod archive(s) are not binary equal to host mod archive(s).\n" "Make sure you installed all mod dependencies & consider redownloading the mod." "\n\nLocal checksum = %u\nRemote checksum = %u", GetModChecksum(), *(unsigned*)(&inbuf[inbufpos+2])); throw content_error(buf); } if (!CScriptHandler::Instance().chosenScript) state = WAIT_ON_SCRIPT; else if (mapName.empty()) state = WAIT_ON_MAP; else state = ALL_READY; inbufpos += inbuf[inbufpos+1]; case NETMSG_MAPDRAW: inbufpos += inbuf[inbufpos+1]; break; case NETMSG_SYSTEMMSG: case NETMSG_CHAT:{ int player=inbuf[inbufpos+2]; string s=(char*)(&inbuf[inbufpos+3]); logOutput.Print(s); inbufpos += inbuf[inbufpos+1]; break;} case NETMSG_STARTPOS:{ inbufpos += 15; break;} case NETMSG_SETPLAYERNUM: gu->myPlayerNum=inbuf[inbufpos+1]; logOutput.Print("Became player %i",gu->myPlayerNum); inbufpos += 2; break; case NETMSG_PLAYERNAME: gs->players[inbuf[inbufpos+2]]->playerName=(char*)(&inbuf[inbufpos+3]); gs->players[inbuf[inbufpos+2]]->readyToStart=true; gs->players[inbuf[inbufpos+2]]->active=true; inbufpos += inbuf[inbufpos+1]; break; case NETMSG_QUIT: net->connected=false; globalQuit=true; return; case NETMSG_USER_SPEED: case NETMSG_INTERNAL_SPEED: inbufpos += 5; break; default: char txt[200]; sprintf(txt,"Unknown net msg in client %d",(int)inbuf[inbufpos]); handleerror(0,txt,"Network error in CPreGame",0); inbufpos++; break; } } }
bool CPreGame::Update() { assert(good_fpu_control_registers("CPreGame::Update")); switch (state) { case UNKNOWN: logOutput.Print("Internal error in CPreGame"); return false; case WAIT_ON_ADDRESS: if (userWriting) break; if (saveAddress) configHandler.SetString("address",userInput); if(net->InitClient(userInput.c_str(),8452,0)==-1){ logOutput.Print("Client couldn't connect"); return false; } // State is never WAIT_ON_ADDRESS if gameSetup was true in our constructor, // so if it's true here, it means net->InitClient() just loaded a demo // with gameSetup. // If so, don't wait indefinitely on a script/map/mod name, but load // everything from gameSetup and switch to ALL_READY state. if(gameSetup) { CScriptHandler::SelectScript("Commanders"); SelectMap(gameSetup->mapname); SelectMod(gameSetup->baseMod); state = ALL_READY; break; } else { state = WAIT_ON_SCRIPT; // fall trough } case WAIT_ON_SCRIPT: if (showList || !server) break; mapName = CScriptHandler::Instance().chosenScript->GetMapName(); if (mapName == "") ShowMapList(); state = WAIT_ON_MAP; // fall through case WAIT_ON_MAP: if (showList || !server) break; modName = CScriptHandler::Instance().chosenScript->GetModName(); if (modName == "") ShowModList(); state = WAIT_ON_MOD; // fall through case WAIT_ON_MOD: if (showList || !server) break; state = ALL_READY; // fall through case ALL_READY: ENTER_MIXED; // Map all required archives depending on selected mod(s) vector<string> ars = archiveScanner->GetArchives(modName); if (ars.empty()) logOutput.Print("Warning: mod archive \"%s\" is missing?\n", modName.c_str()); for (vector<string>::iterator i = ars.begin(); i != ars.end(); ++i) if (!hpiHandler->AddArchive(*i, false)) logOutput.Print("Warning: Couldn't load archive '%s'.", i->c_str()); // Determine if the map is inside an archive, and possibly map needed archives CFileHandler* f = SAFE_NEW CFileHandler("maps/" + mapName); if (!f->FileExists()) { vector<string> ars = archiveScanner->GetArchivesForMap(mapName); if (ars.empty()) logOutput.Print("Warning: map archive \"%s\" is missing?\n", mapName.c_str()); for (vector<string>::iterator i = ars.begin(); i != ars.end(); ++i) { if (!hpiHandler->AddArchive(*i, false)) logOutput.Print("Warning: Couldn't load archive '%s'.", i->c_str()); } } delete f; // always load springcontent.sdz hpiHandler->AddArchive("base/springcontent.sdz", false); LoadStartPicture(); game = SAFE_NEW CGame(server, mapName, modName, infoConsole); infoConsole = 0; ENTER_UNSYNCED; pregame=0; delete this; return true; } if(!server && state != WAIT_ON_ADDRESS){ net->Update(); UpdateClientNet(); } return true; }
CPreGame::CPreGame(bool server, const string& demo, const std::string& save) : showList(0), server(server), state(UNKNOWN), saveAddress(true), hasDemo(!demo.empty()), hasSave(!save.empty()), savefile(NULL) { demoFile = gameSetup? gameSetup->demoName : demo; infoConsole = SAFE_NEW CInfoConsole; pregame = this; // prevent crashes if Select* is called from ctor net = SAFE_NEW CNetProtocol(); //hpiHandler=SAFE_NEW CHpiHandler(); activeController=this; if(!gameSetup) { for(int a=0; a<gs->activeTeams; a++) { for(int b=0; b<4; ++b) { gs->Team(a)->color[b]=palette.teamColor[a][b]; } } } if(server) { net->InitLocalClient(gameSetup ? gameSetup->myPlayerNum : 0); if(gameSetup) { CScriptHandler::SelectScript(gameSetup->scriptName); SelectScript(gameSetup->scriptName); if (!gameSetup->saveName.empty()) { savefile = new CLoadSaveHandler(); savefile->LoadGameStartInfo(savefile->FindSaveFile(gameSetup->saveName.c_str())); } SelectMap(gameSetup->mapName); SelectMod(gameSetup->baseMod); state = WAIT_CONNECTING; } else if (hasSave) { savefile = new CLoadSaveHandler(); savefile->LoadGameStartInfo(savefile->FindSaveFile(save.c_str())); CScriptHandler::SelectScript("Commanders"); SelectScript("Commanders"); SelectMap(savefile->mapName); SelectMod(savefile->modName); state = WAIT_CONNECTING; } else { ShowScriptList(); state = WAIT_ON_SCRIPT; } } else { if(gameSetup) { PrintLoadMsg("Connecting to server"); net->InitClient(gameSetup->hostip.c_str(),gameSetup->hostport,gameSetup->sourceport, gameSetup->myPlayerNum); CScriptHandler::SelectScript(gameSetup->scriptName); SelectScript(gameSetup->scriptName); SelectMap(gameSetup->mapName); SelectMod(gameSetup->baseMod); state = WAIT_CONNECTING; } else { if (hasDemo) { net->localDemoPlayback = true; state = WAIT_CONNECTING; ReadDataFromDemo(demoFile); net->InitLocalClient(0); if (gameSetup) { // we read a gameSetup from the demofiles logOutput.Print("Read GameSetup from Demofile"); SelectMap(gameSetup->mapName); SelectMod(gameSetup->baseMod); CScriptHandler::SelectScript(gameSetup->scriptName); SelectScript(gameSetup->scriptName); } else // we dont read a GameSetup from demofile (this code was copied from CDemoReader) { logOutput.Print("Demo file does not contain GameSetup data"); // Didn't get a CGameSetup script // FIXME: duplicated in Main.cpp const string luaGaiaStr = configHandler.GetString("LuaGaia", "1"); const string luaRulesStr = configHandler.GetString("LuaRules", "1"); gs->useLuaGaia = CLuaGaia::SetConfigString(luaGaiaStr); gs->useLuaRules = CLuaRules::SetConfigString(luaRulesStr); if (gs->useLuaGaia) { gs->gaiaTeamID = gs->activeTeams; gs->gaiaAllyTeamID = gs->activeAllyTeams; gs->activeTeams++; gs->activeAllyTeams++; CTeam* team = gs->Team(gs->gaiaTeamID); team->color[0] = 255; team->color[1] = 255; team->color[2] = 255; team->color[3] = 255; team->gaia = true; gs->SetAllyTeam(gs->gaiaTeamID, gs->gaiaAllyTeamID); } } /* We want to watch a demo local, so we dont know script, map and mod yet and we have to start a server which should send us the required data Default settings: spectating */ gu->spectating = true; gu->spectatingFullView = true; gu->spectatingFullSelect = true; } else { userInput=configHandler.GetString("address",""); writingPos = userInput.length(); userPrompt = "Enter server address: "; state = WAIT_ON_ADDRESS; userWriting = true; } } } assert(state != UNKNOWN); }
void CPreGame::UpdateClientNet() { if (!net->IsActiveConnection()) { logOutput.Print("Server not reachable"); globalQuit = true; return; } RawPacket* packet = 0; while ( (packet = net->GetData()) ) { const unsigned char* inbuf = packet->data; switch (inbuf[0]) { case NETMSG_SCRIPT: { if (!gameSetup) { CScriptHandler::SelectScript((char*) (inbuf+2)); SelectScript((char*) (inbuf+2)); } if (mapName.empty()) { state = WAIT_ON_MAP; } else if (modName.empty()) { state = WAIT_ON_MOD; } else { state = WAIT_CONNECTING; } } break; case NETMSG_MAPNAME: { if (!gameSetup) { SelectMap((char*) (inbuf + 6)); } archiveScanner->CheckMap(mapName, *(unsigned*) (inbuf + 2)); if (!CScriptHandler::Instance().chosenScript) { state = WAIT_ON_SCRIPT; } else if (modName.empty()) { state = WAIT_ON_MOD; } else { state = WAIT_CONNECTING; } } break; case NETMSG_MODNAME: { if (!gameSetup) { SelectMod((char*) (inbuf + 6)); } archiveScanner->CheckMod(modArchive, *(unsigned*) (inbuf + 2)); if (!CScriptHandler::Instance().chosenScript) { state = WAIT_ON_SCRIPT; } else if (mapName.empty()) { state = WAIT_ON_MAP; } else { state = WAIT_CONNECTING; } } break; case NETMSG_MAPDRAW: { } break; case NETMSG_SYSTEMMSG: case NETMSG_CHAT: { // int player = inbuf[inbufpos + 2]; string s = (char*) (inbuf + 3); logOutput.Print(s); } break; case NETMSG_STARTPOS: { // copied from CGame // unsigned player = inbuf[1]; int team = inbuf[2]; if(team>=gs->activeTeams || team<0 || !gameSetup) { logOutput.Print("Got invalid team num %i in startpos msg",team); } else { if(inbuf[3]!=2) gameSetup->readyTeams[team]=!!inbuf[3]; gs->Team(team)->startPos.x=*(float*)&inbuf[4]; gs->Team(team)->startPos.y=*(float*)&inbuf[8]; gs->Team(team)->startPos.z=*(float*)&inbuf[12]; } break; } case NETMSG_SETPLAYERNUM: { gu->myPlayerNum = inbuf[1]; logOutput.Print("Became player %i", gu->myPlayerNum); } break; case NETMSG_PLAYERNAME: { gs->players[inbuf[2]]->playerName = (char*) (inbuf + 3); gs->players[inbuf[2]]->readyToStart = true; gs->players[inbuf[2]]->active = true; if (net->GetDemoRecorder()) net->GetDemoRecorder()->SetMaxPlayerNum(inbuf[2]); } break; case NETMSG_QUIT: { globalQuit = true; break; } case NETMSG_USER_SPEED: { } break; case NETMSG_INTERNAL_SPEED: { } break; case NETMSG_SENDPLAYERSTAT: { } break; case NETMSG_PAUSE: { // these can get into the network stream here -- Kloot int playerNum = (int) inbuf[1]; bool paused = !!inbuf[2]; logOutput.Print(paused? "player %i paused the game": "player %i unpaused the game", playerNum); } break; case NETMSG_PLAYERINFO: break; default: { logOutput.Print("Unknown net-msg recieved from CPreGame: %i", int(inbuf[0])); break; } } delete packet; } }
bool CPreGame::Update() { good_fpu_control_registers("CPreGame::Update"); switch (state) { case UNKNOWN: logOutput.Print("Internal error in CPreGame"); return false; case WAIT_ON_ADDRESS: { if (userWriting) break; if (saveAddress) configHandler.SetString("address",userInput); net->InitClient(userInput.c_str(),8452,0, 0); state = WAIT_ON_SCRIPT; // fall trough } case WAIT_ON_SCRIPT: if (showList || !server) break; mapName = CScriptHandler::Instance().chosenScript->GetMapName(); if (mapName == "") ShowMapList(); else SelectMap(mapName); state = WAIT_ON_MAP; // fall through case WAIT_ON_MAP: if (showList || !server) break; modName = CScriptHandler::Instance().chosenScript->GetModName(); if (modName == "") ShowModList(); else SelectMod(modName); state = WAIT_ON_MOD; // fall through case WAIT_ON_MOD: if (showList || !server) break; state = WAIT_CONNECTING; // fall through case WAIT_CONNECTING: if ((server || hasDemo) && !gameServer) { good_fpu_control_registers("before CGameServer creation"); gameServer = new CGameServer(gameSetup? gameSetup->hostport : 8452, mapName, modArchive, scriptName, demoFile); gameServer->AddLocalClient(gameSetup? gameSetup->myPlayerNum : 0); good_fpu_control_registers("after CGameServer creation"); } if (net->Connected()) state = ALL_READY; // fall through else break; // abort case ALL_READY: { ENTER_MIXED; const int teamID = gs->players[gu->myPlayerNum]->team; const CTeam* team = gs->Team(teamID); if (net->localDemoPlayback) gs->players[gu->myPlayerNum]->spectator = true; LoadStartPicture(team->side); game = SAFE_NEW CGame(mapName, modArchive, infoConsole); if (savefile) { savefile->LoadGame(); } infoConsole = 0; ENTER_UNSYNCED; pregame=0; delete this; return true; } default: assert(false); break; } if(state > WAIT_ON_ADDRESS) { net->Update(); UpdateClientNet(); } return true; }