/** ******************************************************************************* @file /gui/contexts/Game.cpp @brief Obrazovka Game Makro SHOW_DBG_STATES aktivuje vypisovani informaci o stavu hry. @author Pavel @version 0.1 ******************************************************************************/ #include "gui/contexts/Game.h" #include "common/Log.h" #include "common/CommandLine.h" // #include "gui/contexts/FinalStatistic.h" #include "gui/common/ActiveObjects.h" #include "gui/common/colors.h" #include "gui/common/BasicFonts.h" #include "gui/common/Sounds.h" #include "gui/GUI.h" // #include "net/netinit.h" // #include "world/world_server.h" #include "world/plan/plan.h" #include "world/world_client.h" #include #include #include #ifdef _DEBUG static TLog glog(1); #endif #define GLOG //glog.LogMsg namespace gui{ using namespace World; /*utils***********************************************************************/ /// ziska data o typu jednotky World::UNIT* getUnitData(int unitid) { World::UNIT *u = NULL; rm::TRM_advxml_i* rmunit; //ziskej info o vsech jednotkach if( !(rmunit = (rm::TRM_advxml_i*)KSendGlobalMessage(MSG_GET_RM_UNIT_I, MOD_GUI, MOD_RM, NULL)) ) THROW(E_8K_GUI, "getUnitData(): failed to query rmunit interface\n"); rmunit->get(&u, unitid); delete rmunit; return u; } /// ziska data o typu budovy World::BUILDING* getBuildingData(int buildingid) { World::BUILDING *b = NULL; rm::TRM_building_i* rmbuilding; //ziskej info o vsech jednotkach if( !(rmbuilding = (rm::TRM_building_i*)KSendGlobalMessage(MSG_GET_RM_BUILDING_I, MOD_GUI, MOD_RM, NULL)) ) THROW(E_8K_GUI, "getBuildingData(): failed to query rmbuilding interface\n"); rmbuilding->get(&b, buildingid); delete rmbuilding; return b; } /// ziska data o typu bonusu World::UNIT_PROPERTY_BONUS* getBonusData(int bonusid) { World::UNIT_PROPERTY_BONUS *b = NULL; rm::TRM_advxml_i* rmbonus; //ziskej info o vsech jednotkach if( !(rmbonus = (rm::TRM_advxml_i*)KSendGlobalMessage(MSG_GET_RM_BONUS_I, MOD_GUI, MOD_RM, NULL)) ) THROW(E_8K_GUI, "getBonusData(): failed to query rmbonus interface\n"); rmbonus->get(&b, bonusid); delete rmbonus; return b; } /// ziska indexy mapu ve vektoru std::vector getIndexVector(std::map& m) { std::vector indx; // for(std::map::iterator it = m.begin(); it != m.end(); it++) { indx.push_back((*it).first); } return indx; } /// ziska map z vektoru std::map getMapFromVector(std::vector &v) { std::map m; for(std::vector::iterator it = v.begin(); it != v.end(); it++) m.insert(std::make_pair(*it,0)); return m; } /*game************************************************************************/ #define STATUS_X 0 #define STATUS_Y 0 #define STATUS_WIDTH SCREEN_WIDTH #define STATUS_HEIGHT 20 #define STATUS_TBMENU_X 10 #define STATUS_TBMENU_WIDTH 100 #define STATUS_IHEX_X (STATUS_WIDTH - 5*8-23) #define STATUS_LHEX_X (STATUS_WIDTH - 5*8) #define STATUS_IGOLD_X (STATUS_IHEX_X - 7*8-23) #define STATUS_LGOLD_X (STATUS_IHEX_X - 7*8) #define STATUS_IPLAYER_X (STATUS_IGOLD_X - 1*8-23) #define STATUS_LPLAYER_X (STATUS_IGOLD_X - 1*8) #define INFO_WIDTH SCREEN_WIDTH #define INFO_HEIGHT 200 #define INFO_X 0 #define INFO_Y (SCREEN_HEIGHT-INFO_HEIGHT) #define INFO_TEXT_LEN_1 22 #define INFO_TEXT_LEN_2 36 #define GUIMAP_X 0 #define GUIMAP_Y STATUS_HEIGHT #define GUIMAP_WIDTH SCREEN_WIDTH #define GUIMAP_HEIGHT (SCREEN_HEIGHT-INFO_HEIGHT-STATUS_HEIGHT) #define BORDER_WIDTH 6 #define BORDER_HEIGHT 6 #define NEXTTURN_BUTTON_WIDTH 40 #define NEXTTURN_BUTTON_HEIGHT (INFO_HEIGHT - 2*BORDER_WIDTH)/3 #define NEXTTURN_BUTTON_X (INFO_WIDTH - BORDER_WIDTH - NEXTTURN_BUTTON_WIDTH) #define NEXTTURN_BUTTON_Y BORDER_WIDTH #define NEXTUNIT_BUTTON_WIDTH 40 #define NEXTUNIT_BUTTON_HEIGHT (INFO_HEIGHT - 2*BORDER_WIDTH)/3 #define NEXTUNIT_BUTTON_X NEXTTURN_BUTTON_X #define NEXTUNIT_BUTTON_Y BORDER_WIDTH + NEXTTURN_BUTTON_HEIGHT #define PREVUNIT_BUTTON_WIDTH 40 #define PREVUNIT_BUTTON_HEIGHT (INFO_HEIGHT - 2*BORDER_WIDTH)/3 #define PREVUNIT_BUTTON_X NEXTTURN_BUTTON_X #define PREVUNIT_BUTTON_Y (BORDER_WIDTH + NEXTTURN_BUTTON_HEIGHT + NEXTUNIT_BUTTON_HEIGHT) #define MINIMAP_WIDTH (INFO_HEIGHT-2*BORDER_HEIGHT + MINIMAP_BORDER + MINIMAP_RADIO_HEIGHT) #define MINIMAP_HEIGHT (INFO_HEIGHT-2*BORDER_HEIGHT) #define MINIMAP_X BORDER_WIDTH #define MINIMAP_Y BORDER_HEIGHT #define ACTION_Y BORDER_HEIGHT #define ACTION_WIDTH (INFO_HEIGHT-2*BORDER_HEIGHT) #define ACTION_HEIGHT (INFO_HEIGHT-2*BORDER_HEIGHT) #define ACTION_X (INFO_WIDTH-2*BORDER_WIDTH-ACTION_WIDTH-NEXTTURN_BUTTON_WIDTH) #define SUB_ACTION_X BORDER_WIDTH #define SUB_ACTION_Y (ACTION_Y+ACTION_HEIGHT+BORDER_HEIGHT) #define SUB_ACTION_WIDTH (INFO_WIDTH-2*BORDER_WIDTH) #define SUB_ACTION_HEIGHT (INFO_HEIGHT-SUB_ACTION_Y-STATUS_HEIGHT-2) #define INFOPANEL_Y BORDER_HEIGHT #define INFOPANEL_WIDTH (INFO_WIDTH - 3*BORDER_WIDTH - (ACTION_WIDTH + BORDER_WIDTH) - NEXTTURN_BUTTON_WIDTH - (MINIMAP_WIDTH + BORDER_WIDTH) ) #define INFOPANEL_X (MINIMAP_WIDTH+2*BORDER_WIDTH) #define INFOPANEL_HEIGHT (INFO_HEIGHT-2*BORDER_HEIGHT) #define ACTION_BUTTON_WIDTH 49 #define ACTION_BUTTON_HEIGHT 63 #define INFOPANEL_PORTRAIT_BGCOLOR 0.57f, 0.73f, 0.95f #define INFOPANEL_PORTRAIT_BORDER_COLOR 0.2f, 0.2f, 0.2f #define INFOPANEL_PROPERTIES_X 125 #define INFOPANEL_BORDERS 5 #define INFOPANEL_LABEL_COLOR 0.6f, 0.6f, 0.6f, 1 #define INFOPANEL_VALUE_COLOR 0.9f, 0.9f, 0.9f, 1 #define INFOPANEL_HIGHLIGHT_COLOR 0.95f, 0.95f, 0.95f, 1 #define OSDCHAT_MSG_LENGTH 80 #define OSDCHAT_HEIGHT 20 /////////////////////////////////////////////////////////////////////////////// // inicializacne aktivacni kontextovej balast /////////////////////////////////////////////////////////////////////////////// TGame::TGame(TContextParameter contextparameter) { rmtxti = (rm::TRM_txt_i *)KSendGlobalMessage(MSG_GET_RM_TXT_I, MOD_GUI, MOD_RM, NULL); // hlavni mapa guiMap = new TguiMap(GUIMAP_X, GUIMAP_Y, GUIMAP_WIDTH, GUIMAP_HEIGHT); Add(guiMap); osd = new TOSD(GUIMAP_X, GUIMAP_Y, GUIMAP_WIDTH, GUIMAP_HEIGHT - OSDCHAT_HEIGHT); Add(osd); // chat osdchat = new TOSDChatBox(osd, GUIMAP_X, GUIMAP_Y + GUIMAP_HEIGHT - OSDCHAT_HEIGHT, OSDCHAT_MSG_LENGTH); Add(osdchat); eventswindow = new TEventsWindow(); Add(eventswindow); //infopanel infopanel = new TWindow(AO_UNMOVABLE,INFO_X,INFO_Y,INFO_WIDTH,INFO_HEIGHT); Add(infopanel); infopanel->setBgImage(RASTER_PANEL); //minimapa guiMiniMap = new TguiMiniMap(guiMap, MINIMAP_X, MINIMAP_Y, 3*MINIMAP_WIDTH/2, MINIMAP_HEIGHT); infopanel->Add(guiMiniMap); //infookno guiinfo = new TGroupBar(AO_NORMAL, INFOPANEL_X, INFOPANEL_Y, INFOPANEL_WIDTH, INFOPANEL_HEIGHT); infopanel->Add(guiinfo); //akce listOfActions = new TListBar(AO_NORMAL, ACTION_X, ACTION_Y, ACTION_WIDTH, ACTION_HEIGHT); infopanel->Add(listOfActions); rm::TSymbolData *sdNT = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 13); rm::TSymbolData *sdNU = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 13); rm::TSymbolData *sdPU = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 13); ibNextTurn = new TIconButton(AO_NORMAL, TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 20), NEXTTURN_BUTTON_X, NEXTTURN_BUTTON_Y, NEXTTURN_BUTTON_WIDTH, NEXTTURN_BUTTON_HEIGHT); infopanel->Add(ibNextTurn); ibNextUnit = new TIconButton(AO_NORMAL, TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 18), NEXTUNIT_BUTTON_X, NEXTUNIT_BUTTON_Y, NEXTUNIT_BUTTON_WIDTH, NEXTUNIT_BUTTON_HEIGHT); infopanel->Add(ibNextUnit); ibPrevUnit = new TIconButton(AO_NORMAL, TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 19), PREVUNIT_BUTTON_X, PREVUNIT_BUTTON_Y, PREVUNIT_BUTTON_WIDTH, PREVUNIT_BUTTON_HEIGHT); infopanel->Add(ibPrevUnit); ibNextTurn->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_ENDTURN)); ibNextTurn->setShortcutKey(SDLK_n, L"Ctrl+N", (SDLMod)KMOD_CTRL); ibNextUnit->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_NEXTUNIT)); ibNextUnit->setShortcutKey(SDLK_PAGEDOWN, L"PgDown"); ibPrevUnit->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_PREVUNIT)); ibPrevUnit->setShortcutKey(SDLK_PAGEUP, L"PgUp"); //alterentivni policko gbCanvas = new TGroupBar(AO_NORMAL, ACTION_X, ACTION_Y, (INFO_WIDTH - BORDER_WIDTH - ACTION_X), INFO_HEIGHT-2*BORDER_WIDTH); infopanel->Add(gbCanvas); statuspanel = new TWindow(AO_UNMOVABLE, STATUS_X, STATUS_Y, STATUS_WIDTH, STATUS_HEIGHT); Add(statuspanel); //butony nalevo statuspanel->setBgImage(RASTER_PANEL); tbmenu = new TSoundedTextButton(AO_TOOLBAR, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_MENU), STATUS_TBMENU_X, 2, STATUS_TBMENU_WIDTH, 16, SAMPLE_CLICK); statuspanel->Add(tbmenu); tdiplomacy = new TSoundedTextButton(AO_TOOLBAR, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_DIPLOMACY), STATUS_TBMENU_X + STATUS_TBMENU_WIDTH + 2, 2, STATUS_TBMENU_WIDTH, 16, SAMPLE_CLICK); statuspanel->Add(tdiplomacy); tinfo = new TSoundedTextButton(AO_TOOLBAR, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_INFO), STATUS_TBMENU_X + 2*(STATUS_TBMENU_WIDTH + 2), 2, STATUS_TBMENU_WIDTH, 16, SAMPLE_CLICK); statuspanel->Add(tinfo); //info napravo //hrac iplayer = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, ICON_BASIC_PLAYER), STATUS_IPLAYER_X, 2); statuspanel->Add(iplayer); lplayername = new TLabel(L"", STATUS_LPLAYER_X, 2); lplayername->setColor(ColorPlayer[1][0]/255.f,ColorPlayer[1][1]/255.f,ColorPlayer[1][2]/255.f,1); statuspanel->Add(lplayername); //prachy igold = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, ICON_BASIC_GOLD), STATUS_IGOLD_X, 2); statuspanel->Add(igold); lmoney = new TLabel(L"0", STATUS_LGOLD_X, 2); statuspanel->Add(lmoney); //hexindex ihex = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, ICON_BASIC_HEX), STATUS_IHEX_X, 2); statuspanel->Add(ihex); lhex = new TLabel(L"0", STATUS_LHEX_X, 2); statuspanel->Add(lhex); gamemenu = new TGameMenu(); Add(gamemenu); console_wnd = new TMyConsoleWindow(); Add(console_wnd); diplomacywindow = new TDiplomacyWindow(); Add(diplomacywindow); curtain = new TCurtain(); Add( curtain ); // nullStates(); // loading_thread = NULL; //dbg souboju b_dbg=0; FILE* f = fopen("battle", "r"); if(f){ fscanf(f, "%d %d %d %d %d %d %d", &b_kill, &b_loss, &b_dmgs, &b_ad, &b_dd, &b_bd, &b_dbg); fclose(f); } } TGame::~TGame() { delete rmtxti; // vypusti a odalokuje vsechny aktivni prvky v sobe (rekursivne) DelNFreeAll(); } TContext* TGame::createContext(...){ TGame* n = new TGame(TContextParameter()); strcpy(n->szName,"GAMECONTEXT"); return n; } void TGame::activateContext(TContextParameter contextparameter) { // kdyz je kurzor na kraji obrazovky tak se zmeni jeho obrazek na sipku TaoKernel::aoKernel->cursor->scrolling = true; //typ hry if( (contextparameter.iPrimary != context_localgame)&& (contextparameter.iPrimary != context_networkgame)) THROW(E_8K_GUI, "TGame::activateContext(): no gamemode selected\n"); //nastav hlasitost z profilu & prehrej "battle theme" if(TSoundInterface::si){ TSoundInterface::si->setSoundVolume(TGUI::gui_inst->profile->sfx_volume/(float)SOUND_VOLUME_LEVELS); TSoundInterface::si->setMusicVolume(TGUI::gui_inst->profile->music_volume/(float)MUSIC_VOLUME_LEVELS); TSoundInterface::si->playMusic(MUSIC_BATTLE_THEME); } //nastaveni rychlosti guiMap->getCM()->setSpeed( TGUI::gui_inst->profile->speed ); guiMap->initShadowMapping(); // iLocalGame = (contextparameter.iPrimary == context_localgame); updateVisibility(iGUIOwner); updateStatusBar(); updateActionsPanel(); updateInfoPanel(); //vytvor seznamy udalosti events.clear(); for(World::TPlayerContainer::iterator it = players->begin(); it != players->end(); it++) { int id = (*it).first; GLOG("creating event vector for player id=%d\n", id); events.insert( std::make_pair(id, new TEventVector()) ); } //chat if (!iLocalGame) { // najdu prvniho klienta na tomto pocitaci a to bude odesilatel zprav do chatboxu int i = 0, cid; while ((i < TGUI::gui_inst->clientsinfo.num) && (!TGUI::gui_inst->clientsinfo.cinfo[i].local)) i++; if (i >= TGUI::gui_inst->clientsinfo.num) cid = TO_SERVER; else cid = TGUI::gui_inst->clientsinfo.cinfo[i].clientid; osdchat->setClientColor(cid, ColorPlayer[iGUIOwner][0], ColorPlayer[iGUIOwner][1], ColorPlayer[iGUIOwner][2]); GLOG("CHAT:\n"); for (i = 0; i < TGUI::gui_inst->clientsinfo.num;i++) { GLOG("cid = %d, local = %d, name = %s\n", TGUI::gui_inst->clientsinfo.cinfo[i].clientid, TGUI::gui_inst->clientsinfo.cinfo[i].local, TGUI::gui_inst->clientsinfo.cinfo[i].profileName); } } //zaostri na jednotku focusUnit( nextUnit() ); //rozjasneni curtain->fadeOut(2000); } void TGame::deactivateContext(){ //zrus, pripadne na zvlastnim vlakne ukonci guiMap->done(); //zrus seznamy udalosti for(std::map::iterator it = events.begin(); it != events.end(); it++) { (it->second)->releaseEventsVector(); delete (it->second); } events.clear(); //zrus minimapu guiMiniMap->done(); } void TGame::nullStates(){ //nastaveni stavovejch informaci iLocalGame = -1; iGUIOwner = -1; iPlayerOnTurn = 0; selectable_hexes_map.clear(); selected_unit = NULL; selected_building = NULL; selected_hex_index = -1; preselected_hex_index = -1; dummy_building = NULL; actionsPanelState = apsBlank; infoPanelState = ipsBlank; selected_building_to_build = -1; selected_bonus_to_sell = -1; selected_unit_to_recruit = -1; //nuluj akcni buttony nullButtons(); //button jednotky v budove unitinside = NULL; //zamek pro uziv vstup inputLock = 0; actionLock = 0; } void TGame::nullButtons(){ //vynulluj pole buttonu int i; for(i = 0; i < UNIT_ACTION_COUNT; i++) unit_action_buttons[i] = NULL; for(i = 0; i < BUILDING_ACTION_COUNT; i++) building_action_buttons[i] = NULL; for(i = 0; i < MAX_UNITS_COUNT; i++) recruit_unit_buttons[i] = NULL; for(i = 0; i < MAX_BUILDINGS_COUNT; i++) construction_building_buttons[i] = NULL; for(i = 0; i < MAX_BONUS_COUNT; i++) bonus_buttons[i] = NULL; for(i = 0; i < COMMON_BUTTONS_COUNT; i++) common_buttons[i] = NULL; } /////////////////////////////////////////////////////////////////////////////// // vstup & vystup /////////////////////////////////////////////////////////////////////////////// void TGame::DbgInfo(){ static wchar_t buff[80]; snwprintf(buff,80,L"actionsPanelState = %d, infoPanelState = %d\n", actionsPanelState, infoPanelState); glDisable(GL_LIGHTING); DrawText(10,SCREEN_HEIGHT-46,buff); if(inputLock) DrawText(10,SCREEN_HEIGHT-62,L"Input Locked"); if(actionLock) DrawText(10,SCREEN_HEIGHT-82,L"Action Locked"); glEnable(GL_LIGHTING); } void TGame::drawContext(){ TFrame::drawObject(); #ifdef SHOW_DBG_STATES DbgInfo(); #endif } int TGame::workInput(INPUT *input) { //--- workinput predka --- int ret = TContext::workInput(input); //--- pumpnu zpravy z worldu --- TGUI::gui_inst->pumpGameMessage(); //--- blokovany vstup --- if(!inputLock) { // =========================================================================== // // --- ACTION TLACITKA --- // =========================================================================== // // =========================================================================== // // JEDNOTKY // // =========================================================================== // if( unit_action_buttons[UA_MOVE] && CLICKED(unit_action_buttons[UA_MOVE]) ) { actionSelected(gaMove); actionsPanelState = apsUnitMove; updateActionsPanel(); } if( actionsPanelState == apsUnitMove && common_buttons[0] && CLICKED(common_buttons[0]) ){ actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(1); } if( unit_action_buttons[UA_ATTACK] && CLICKED(unit_action_buttons[UA_ATTACK]) ) { actionSelected(gaAttack); actionsPanelState = apsUnitAttack; updateActionsPanel(); } if( actionsPanelState == apsUnitAttack && common_buttons[0] && CLICKED(common_buttons[0]) ){ actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(2); } if( actionsPanelState == apsUnitSuicideConfirmation ) { if( common_buttons[0] && CLICKED(common_buttons[0]) ){ actionSelected(gaUnitSuicide); updateActionsPanel(); } else if( common_buttons[1] && CLICKED(common_buttons[1]) ){ actionsPanelState = apsUnitSelection; updateActionsPanel(); } } if( unit_action_buttons[UA_SUICIDE] && CLICKED(unit_action_buttons[UA_SUICIDE]) ) { actionsPanelState = apsUnitSuicideConfirmation; updateActionsPanel(); } if( unit_action_buttons[UA_REPAIR_BUILDING] && CLICKED(unit_action_buttons[UA_REPAIR_BUILDING]) ){ actionSelected(gaRepair); actionsPanelState = apsUnitRepair; updateActionsPanel(); } if( actionsPanelState == apsUnitRepair && common_buttons[0] && CLICKED(common_buttons[0]) ){ actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(3); } if( unit_action_buttons[UA_START_BUILDING] && CLICKED(unit_action_buttons[UA_START_BUILDING]) ){ actionsPanelState = apsConstructionSelection; updateActionsPanel(); } if( actionsPanelState == apsConstructionSelection ) { int i = 0; while( construction_building_buttons[i] && (itag == -1 ) { actionsPanelState = apsUnitSelection; } else { actionsPanelState = apsConstructionPosition; selected_building_to_build = construction_building_buttons[i]->tag; actionSelected(gaBuild); } updateActionsPanel(); break; }//if i++; }//while } if(actionsPanelState == apsConstructionPosition && common_buttons[0] && CLICKED(common_buttons[0]) ){ //cancel building actionsPanelState = apsConstructionSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(3); } if(actionsPanelState == apsConstructionControl) { int hind = dummy_building->hexWhereIam->getIndex(); int allowed_orientations = selectable_hexes_map[hind]; if( common_buttons[0] && CLICKED(common_buttons[0]) ){ //rotate left dummy_building->changeOrientationBy(1, allowed_orientations); } if( common_buttons[1] && CLICKED(common_buttons[1]) ){ //rotate right dummy_building->changeOrientationBy(-1, allowed_orientations); } if( common_buttons[2] && CLICKED(common_buttons[2]) ){ //zrus dummy object TBuilding::uninstallDummyBuilding(guiMap, dummy_building); dummy_building = NULL; //cancel position -> constr selection actionSelected(gaBuild); actionsPanelState = apsConstructionPosition; updateActionsPanel(); } } if( unit_action_buttons[UA_STOP_BUILDING] && CLICKED(unit_action_buttons[UA_STOP_BUILDING]) ) { actionSelected(gaStopBuilding); updateActionsPanel(); } if( unit_action_buttons[UA_HEAL] && CLICKED(unit_action_buttons[UA_HEAL]) ) { actionSelected(gaHeal); updateActionsPanel(); } if( unit_action_buttons[UA_RECRUIT] && CLICKED(unit_action_buttons[UA_RECRUIT]) ) { actionSelected(gaRecruit); updateActionsPanel(); } if( unit_action_buttons[UA_RECRUIT_ELITE] && CLICKED(unit_action_buttons[UA_RECRUIT_ELITE]) ) { actionSelected(gaRecruitElite); updateActionsPanel(); } // =========================================================================== // // BUDOVY // // =========================================================================== // if(actionsPanelState == apsBuildingSuicideConfirmation) { if( common_buttons[0] && CLICKED(common_buttons[0]) ) { actionSelected(gaBuildingSuicide); //budova znicena updateActionsPanel(); } else if( common_buttons[1] && CLICKED(common_buttons[1]) ){ actionsPanelState = apsBuildingSelection; updateActionsPanel(); } } if( building_action_buttons[BA_SUICIDE] && CLICKED(building_action_buttons[BA_SUICIDE]) ) { actionsPanelState = apsBuildingSuicideConfirmation; updateActionsPanel(); } if( building_action_buttons[BA_RECRUIT_UNIT] && CLICKED(building_action_buttons[BA_RECRUIT_UNIT]) ){ actionsPanelState = apsRecruitUnitSelection; updateActionsPanel(); } if(actionsPanelState == apsRecruitUnitSelection) { int i = 0; while(recruit_unit_buttons[i] && (itag == -1 ) { actionsPanelState = apsBuildingSelection; } else { selected_unit_to_recruit = recruit_unit_buttons[i]->tag; actionSelected(gaRecruitUnit); } updateActionsPanel(); break; }//if i++; }//while } if( building_action_buttons[BA_SELL_BONUS] && CLICKED(building_action_buttons[BA_SELL_BONUS]) ) { actionsPanelState = apsSellBonusSelection; updateActionsPanel(); } if(actionsPanelState == apsSellBonusSelection) { int i = 0; while(bonus_buttons[i] && (itag == -1 ) { actionsPanelState = apsBuildingSelection; } else { selected_bonus_to_sell = bonus_buttons[i]->tag; actionSelected(gaSellBonus); } updateActionsPanel(); break; }//if i++; }//while } // =========================================================================== // // --- FUNKCNI TLACITKA --- // =========================================================================== // if CLICKED(ibNextTurn){ nextTurn(); } if CLICKED(ibNextUnit){ focusUnit( nextUnit() ); } if CLICKED(ibPrevUnit){ focusUnit( prevUnit() ); } // =========================================================================== // // --- INFOPANEL TLACITKA --- // =========================================================================== // if( unitinside && CLICKED(unitinside) ){ int uid = (*living_buildings)[ selected_building->guibiInfo.livingbuilding ]->unit(); // buildingUnselected(); unitSelected( guiMap->guimap_units[uid] ); } // =========================================================================== // // --- MENU TLACITKA --- // =========================================================================== // // VYPNUTI/ZAPNUTI MENU if CLICKED(tbmenu){ gamemenu->showModal(); } // ZAPNUTI/VYPNUTI DIPLOMACIE if CLICKED(tdiplomacy) { diplomacywindow->showModal(); } // ZAPNUTI/VYPNUTI INFOPANELU if CLICKED(tinfo) { eventswindow->showModal(); } }//if not inputLock // =========================================================================== // // KLAVESNICE // =========================================================================== // if ((input->type == INPUT_KEY_DOWN) && mayIUseKeyboardInput()){ // KONZOLE if (input->key.sym == SDLK_BACKQUOTE && TCommandLine::cl->iDevelopersConsole) { if (console_wnd->active == AO_PASIVE) console_wnd->showModal(); } // CHAT if (!iLocalGame) { if(input->key.sym == SDLK_c) osdchat->show(); else if (input->key.sym == SDLK_ESCAPE) osdchat->hide(); } } else if ((input->type == INPUT_KEY_DOWN) && (input->key.sym == SDLK_BACKQUOTE) && TCommandLine::cl->iDevelopersConsole && (console_wnd->active != AO_PASIVE)) console_wnd->hide(); return ret; } void TGame::updateActionsPanel(){ wchar_t wtemp2[20]; //ziskej manager na symboly rm::TSymbolData *rm_symbol; rm::TRM_symbol_i* rms = (rm::TRM_symbol_i*) KSendGlobalMessage(MSG_GET_RM_SYMBOL_I,MOD_GUI,MOD_RM,NULL); //smaz cely panel listOfActions->DelNFreeAll(); gbCanvas->DelNFreeAll(); //smaz seznam buttonu nullButtons(); //vytvor panel v skrolovatelnym okne TItem *subactionBar = new TItem(AO_UNSELECTABLE, ACTION_BUTTON_HEIGHT); //nasazej buttony podle typyu seznamu switch(actionsPanelState){ case apsBlank:{ }break; case apsUnitRepair: case apsConstructionPosition: case apsUnitMove: case apsUnitAttack:{ //ikona zpet rms->getSymbol(&rm_symbol, SYMBOLS_BUILDING_ICONS, ICON_BUILDING_RETURN); common_buttons[0] = new TIconButton(AO_TOOLBAR, rm_symbol, 0, 0, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); common_buttons[0]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BACK)); common_buttons[0]->setShortcutKey(SDLK_BACKSPACE, L"BckSpc"); subactionBar->Add(common_buttons[0]); //ukoncovac common_buttons[1] = NULL; }break; case apsUnitSuicideConfirmation: case apsBuildingSuicideConfirmation:{ //ikona ano rms->getSymbol(&rm_symbol, SYMBOLS_UNIT_ICONS, ICON_UNIT_YES); common_buttons[0] = new TIconButton(AO_TOOLBAR, rm_symbol, 0, 0, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); common_buttons[0]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_OK)); common_buttons[0]->setShortcutKey(SDLK_RETURN, L"Return"); subactionBar->Add(common_buttons[0]); rms->getSymbol(&rm_symbol, SYMBOLS_UNIT_ICONS, ICON_UNIT_NO); common_buttons[1] = new TIconButton(AO_TOOLBAR, rm_symbol, ACTION_BUTTON_WIDTH, 0, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); common_buttons[1]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BACK)); common_buttons[1]->setShortcutKey(SDLK_BACKSPACE, L"BckSpc"); subactionBar->Add(common_buttons[1]); //ukoncovac common_buttons[2] = NULL; }break; case apsConstructionControl:{ int bx = 0; //ikona otoc doleva rms->getSymbol(&rm_symbol, SYMBOLS_BUILDING_ICONS, ICON_BUILDING_LEFT); common_buttons[0] = new TIconButton(AO_TOOLBAR, rm_symbol, bx, 0, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); common_buttons[0]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_TURNLEFT)); common_buttons[0]->setShortcutKey(SDLK_l); subactionBar->Add(common_buttons[0]); //ikona otoc doprava rms->getSymbol(&rm_symbol, SYMBOLS_BUILDING_ICONS, ICON_BUILDING_RIGHT); common_buttons[1] = new TIconButton(AO_TOOLBAR, rm_symbol, bx+=ACTION_BUTTON_WIDTH, 0, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); common_buttons[1]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_TURNRIGHT)); common_buttons[1]->setShortcutKey(SDLK_r); subactionBar->Add(common_buttons[1]); //ikona zpet rms->getSymbol(&rm_symbol, SYMBOLS_BUILDING_ICONS, ICON_BUILDING_RETURN); common_buttons[2] = new TIconButton(AO_TOOLBAR, rm_symbol, bx+=ACTION_BUTTON_WIDTH, 0, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); common_buttons[2]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BACK)); common_buttons[2]->setShortcutKey(SDLK_BACKSPACE, L"BckSpc"); subactionBar->Add(common_buttons[2]); //ukoncovac common_buttons[3] = NULL; }break; case apsConstructionSelection:{ //zprava do worldu, zjisti postavitelne budovy PACKET_ACT_UNIT_CLICK msg; msg.player_id = iGUIOwner; msg.type = MSG_ACT_UNIT_CLICK; msg.unit_id = selected_unit->guiuiInfo.livingunit; TPacket_RCT_UNIT_CLICK *result; result = (TPacket_RCT_UNIT_CLICK *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //nacti vsechny jednotky int bx = 0; int by = 0; int i = 0; World::BUILDING *building_data; for(std::vector::iterator it = result->buildings.begin(); it != result->buildings.end(); it++) { int bid = *it; //vyber jednotku podle uid if( !(building_data = getBuildingData(bid)) ) THROW(E_8K_GUI, "TGame::updateActionsPanel(): failed to query building type\n"); //nacti symbol rms->getSymbol(&rm_symbol, building_data->symbolid, ICON_BUILDING_ICON); //pridej ikonu na seznam wchar_t cost[16]; snwprintf(cost, 16, L"%d", building_data->base_cost); construction_building_buttons[i] = new TIconTextButton(AO_TOOLBAR, rm_symbol, cost, bx, by, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); construction_building_buttons[i]->tag=bid; construction_building_buttons[i]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, building_data->nameid)); rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_CONSTRDURATION); snwprintf(wtemp2, 10, L": %d", building_data->construction_duration); wcsncat(wtemp, wtemp2, LABEL_MAX_LENGTH); construction_building_buttons[i]->addHelpLine(wtemp); rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_COST); snwprintf(wtemp2, 10, L": %d", building_data->base_cost); wcsncat(wtemp, wtemp2, LABEL_MAX_LENGTH); construction_building_buttons[i]->addHelpLine(wtemp); subactionBar->Add(construction_building_buttons[i]); //nastav souradnice bx+=ACTION_BUTTON_WIDTH; if( (bx+ACTION_BUTTON_WIDTH)>ACTION_WIDTH ){ bx = 0; by += ACTION_BUTTON_HEIGHT; //listOfActions->Add( subactionBar = new TItem(AO_UNSELECTABLE, ACTION_BUTTON_HEIGHT) ); } i++; }//for //ikona zpet rms->getSymbol(&rm_symbol, SYMBOLS_BUILDING_ICONS, ICON_BUILDING_RETURN); construction_building_buttons[i] = new TIconButton(AO_TOOLBAR, rm_symbol, bx, by, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); construction_building_buttons[i]->tag=-1; construction_building_buttons[i]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BACK)); construction_building_buttons[i]->setShortcutKey(SDLK_BACKSPACE, L"BckSpc"); subactionBar->Add(construction_building_buttons[i]); //ukoncovac construction_building_buttons[i+1] = NULL; }//if else GLOG("TPacket_SyncResult status: %d\n", result->status); delete result; }break; case apsRecruitUnitSelection:{ //zprava do worldu, zjisti postavitelne jednotky PACKET_ACT_BUILDING_CLICK msg; msg.type = MSG_ACT_BUILDING_CLICK; msg.player_id = selected_building->guibiInfo.player; msg.building_id = selected_building->guibiInfo.livingbuilding; TPacket_RCT_BUILDING_CLICK *result; result = (TPacket_RCT_BUILDING_CLICK *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //nacti vsechny jednotky int bx = 0; int by = 0; int i = 0; World::UNIT *unit_data; for(std::vector::iterator it = result->recruitment.begin(); it != result->recruitment.end(); it++) { int uid = *it; //vyber jednotku podle uid if( !(unit_data = getUnitData(uid)) ) THROW(E_8K_GUI, "TGame::updateActionsPanel(): failed to query unit type\n"); //nacti symbol rms->getSymbol(&rm_symbol, unit_data->symbolid, ICON_UNIT_ICON); //pridej ikonu na seznam wchar_t cost[16]; snwprintf(cost, 16, L"%d", unit_data->cost); recruit_unit_buttons[i] = new TIconTextButton(AO_TOOLBAR, rm_symbol, cost, bx, by, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); recruit_unit_buttons[i]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, unit_data->nameid)); rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_COST); snwprintf(wtemp2, 10, L": %d", unit_data->cost); wcsncat(wtemp, wtemp2, LABEL_MAX_LENGTH); recruit_unit_buttons[i]->addHelpLine(wtemp); rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_PAY); snwprintf(wtemp2, 10, L": %d", unit_data->pay); wcsncat(wtemp, wtemp2, LABEL_MAX_LENGTH); recruit_unit_buttons[i]->addHelpLine(wtemp); recruit_unit_buttons[i]->tag=uid; subactionBar->Add(recruit_unit_buttons[i]); //nastav souradnice bx+=ACTION_BUTTON_WIDTH; if( (bx+ACTION_BUTTON_WIDTH)>ACTION_WIDTH ){ bx = 0; by += ACTION_BUTTON_HEIGHT; //listOfActions->Add( subactionBar = new TItem(AO_UNSELECTABLE, ACTION_BUTTON_HEIGHT) ); } i++; }//for //ikona zpet rms->getSymbol(&rm_symbol, SYMBOLS_BUILDING_ICONS, ICON_BUILDING_RETURN); recruit_unit_buttons[i] = new TIconButton(AO_TOOLBAR, rm_symbol, bx, by, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); recruit_unit_buttons[i]->tag=-1; recruit_unit_buttons[i]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BACK)); recruit_unit_buttons[i]->setShortcutKey(SDLK_BACKSPACE, L"BckSpc"); subactionBar->Add(recruit_unit_buttons[i]); //ukoncovac recruit_unit_buttons[i+1] = NULL; }//if else GLOG("TPacket_SyncResult status: %d\n", result->status); delete result; }break; case apsBuildingSelection:{ //zprava do worldu, zjisti akce PACKET_ACT_BUILDING_CLICK msg; msg.type = MSG_ACT_BUILDING_CLICK; msg.player_id = selected_building->guibiInfo.player; msg.building_id = selected_building->guibiInfo.livingbuilding; TPacket_RCT_BUILDING_CLICK *result; result = (TPacket_RCT_BUILDING_CLICK *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ int bx = 0; int by = 0; int buttons[] = { ICON_BUILDING_RECRUIT_UNIT, ICON_BUILDING_SELL_BONUS, ICON_BUILDING_SUICIDE }; int actions[] = { BA_RECRUIT_UNIT, BA_SELL_BONUS, BA_SUICIDE}; int helps[] = {TEXT_BUILING_RECRUIT, TEXT_BUILING_SELLBONUS, TEXT_BUILING_SUICIDE}; SDLKey shortcut[] = {SDLK_r, SDLK_b, SDLK_d}; for(int i = 0; i < BUILDING_ACTION_COUNT; i++){ if( (bx+ACTION_BUTTON_WIDTH)>ACTION_WIDTH ){ bx = 0; by += ACTION_BUTTON_HEIGHT; //listOfActions->Add( subactionBar = new TItem(AO_UNSELECTABLE, ACTION_BUTTON_HEIGHT) ); } if(result->actions[ actions[i] ]){ rms->getSymbol(&rm_symbol, SYMBOLS_BUILDING_ICONS, buttons[i]); building_action_buttons[ actions[i] ] = new TIconButton(AO_TOOLBAR, rm_symbol, bx, by, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, helps[i]); building_action_buttons[ actions[i] ]->setHelp(wtemp); building_action_buttons[ actions[i] ]->setShortcutKey(shortcut[i]); subactionBar->Add(building_action_buttons[ actions[i] ]); bx+=ACTION_BUTTON_WIDTH; } else building_action_buttons[ actions[i] ] = NULL; }//for }//if else GLOG("TPacket_SyncResult status: %d\n", result->status); delete result; }break; case apsSellBonusSelection:{ //zprava do worldu, zjisti koupitelne bonusy PACKET_ACT_BUILDING_CLICK msg; msg.type = MSG_ACT_BUILDING_CLICK; msg.player_id = selected_building->guibiInfo.player; msg.building_id = selected_building->guibiInfo.livingbuilding; TPacket_RCT_BUILDING_CLICK *result; result = (TPacket_RCT_BUILDING_CLICK *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //nacti vsechny jednotky int bx = 0; int by = 0; int i = 0; for(std::vector::iterator it = result->bonuses.begin(); it != result->bonuses.end(); it++) { World::UNIT_PROPERTY_BONUS* bp = getBonusData(*it); //nacti symbol rms->getSymbol(&rm_symbol, SYMBOLS_BONUS_ICONS, bp->id); //pridej ikonu na seznam wchar_t cost[16]; snwprintf(cost, 16, L"%d", bp->cost); bonus_buttons[i] = new TIconTextButton(AO_TOOLBAR, rm_symbol, cost, bx, by, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); bonus_buttons[i]->setHelp( rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, bp->nameid) ); bonus_buttons[i]->tag=*it; subactionBar->Add(bonus_buttons[i]); //nastav souradnice bx+=ACTION_BUTTON_WIDTH; if( (bx+ACTION_BUTTON_WIDTH)>ACTION_WIDTH ){ bx = 0; by += ACTION_BUTTON_HEIGHT; //listOfActions->Add( subactionBar = new TItem(AO_UNSELECTABLE, ACTION_BUTTON_HEIGHT) ); } i++; }//for //ikona zpet rms->getSymbol(&rm_symbol, SYMBOLS_BUILDING_ICONS, ICON_BUILDING_RETURN); bonus_buttons[i] = new TIconButton(AO_TOOLBAR, rm_symbol, bx, by, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); bonus_buttons[i]->tag=-1; bonus_buttons[i]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BACK)); bonus_buttons[i]->setShortcutKey(SDLK_BACKSPACE, L"BckSpc"); subactionBar->Add(bonus_buttons[i]); //ukoncovak bonus_buttons[i+1]=NULL; }//if else GLOG("TPacket_SyncResult status: %d\n", result->status); delete result; }break; case apsUnitSelection:{ //zprava do worldu, zjisti akce PACKET_ACT_UNIT_CLICK msg; msg.player_id = iGUIOwner; msg.type = MSG_ACT_UNIT_CLICK; msg.unit_id = selected_unit->guiuiInfo.livingunit; TPacket_RCT_UNIT_CLICK *result; result = (TPacket_RCT_UNIT_CLICK *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); //world data World::TLivingUnit *lu = (*living_units)[ selected_unit->guiuiInfo.livingunit ]; World::LIVING_UNIT *lu_data = &( lu->data() ); World::UNIT *unit_data = getUnitData(selected_unit->guiuiInfo.uid); //unit data if( !unit_data ) THROW(E_8K_GUI, "TGame::updateInfoPanel(): failed to query unit type\n"); if(!result->status){ int bx = 0; int by = 0; //poradi zobrazovani int buttons[] = { ICON_UNIT_MOVE, ICON_UNIT_ATTACK, ICON_UNIT_HEAL, ICON_UNIT_RECRUIT, ICON_UNIT_RECRUIT_ELITE, ICON_UNIT_START_BUILDING, ICON_UNIT_STOP_BUILDING, ICON_UNIT_REPAIR_BUILDING, ICON_UNIT_SUICIDE}; int actions[] = { UA_MOVE, UA_ATTACK, UA_HEAL, UA_RECRUIT, UA_RECRUIT_ELITE, UA_START_BUILDING, UA_STOP_BUILDING, UA_REPAIR_BUILDING, UA_SUICIDE}; int helps[] = { TEXT_UNIT_MOVE, TEXT_UNIT_ATTACK, TEXT_UNIT_HEAL, TEXT_UNIT_RECRUIT, TEXT_UNIT_RECRUIT_ELITE, TEXT_UNIT_BUILD, TEXT_UNIT_STOPBUILDING, TEXT_UNIT_REPAIR, TEXT_UNIT_SUICIDE }; SDLKey shortcut[] = {SDLK_m, SDLK_a, SDLK_h, SDLK_u, SDLK_e, SDLK_b, SDLK_s, SDLK_r, SDLK_d}; for(int i = 0; i < UNIT_ACTION_COUNT; i++){ if( (bx+ACTION_BUTTON_WIDTH)>ACTION_WIDTH ){ bx = 0; by += ACTION_BUTTON_HEIGHT; } if(result->actions[ actions[i] ]){ rms->getSymbol(&rm_symbol, SYMBOLS_UNIT_ICONS, buttons[i]); //spec verze pro ceny doplneni if( actions[i] == UA_RECRUIT_ELITE || actions[i] == UA_RECRUIT){ int costval = 0; if(actions[i] == UA_RECRUIT_ELITE) costval = unit_data->cure_cost * lu_data->level * (unit_data->max_lives + lu->maxLivesBonus() - lu_data->lives); // wchar_t cost[16]; snwprintf(cost, 16, L"%d", costval); unit_action_buttons[ actions[i] ] = new TIconTextButton(AO_TOOLBAR, rm_symbol, cost, bx, by, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); } //obecna verze else{ unit_action_buttons[ actions[i] ] = new TIconButton(AO_TOOLBAR, rm_symbol, bx, by, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); } unit_action_buttons[ actions[i] ]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, helps[i])); unit_action_buttons[ actions[i] ]->setShortcutKey(shortcut[i]); subactionBar->Add(unit_action_buttons[ actions[i] ]); bx+=ACTION_BUTTON_WIDTH; } else unit_action_buttons[ actions[i] ] = NULL; }//for }//if else GLOG("TPacket_SyncResult status: %d\n", result->status); delete result; }break; } listOfActions->Add( subactionBar ); //podle toho jestli uzivatel na tahu, nebo ne if( iGUIOwner == iPlayerOnTurn /*&& !inputLock*/ ) { listOfActions->show(); ibNextTurn->show(); ibNextUnit->show(); ibPrevUnit->show(); gbCanvas->hide(); } else{ listOfActions->hide(); ibNextTurn->hide(); ibNextUnit->hide(); ibPrevUnit->hide(); gbCanvas->show(); TWallpaper* wp= new TWallpaper(RASTER_WAITING, 1, 1, (INFO_WIDTH - BORDER_WIDTH - ACTION_X)-2, INFO_HEIGHT-2*BORDER_WIDTH-2); gbCanvas->Add(wp); } delete rms; } void TGame::updateInfoPanel(){ //ziskej manager na symboly rm::TSymbolData *rm_symbol; rm::TRM_symbol_i* rms = (rm::TRM_symbol_i*) KSendGlobalMessage(MSG_GET_RM_SYMBOL_I,MOD_GUI,MOD_RM,NULL); TLabel *label; TIcon* ico; World::LIVING_UNIT *lu_data; World::TLivingUnit *lu; World::UNIT *unit_data; World::LIVING_BUILDING *lb_data; World::BUILDING *building_data; //smaz seznam akci guiinfo->DelNFreeAll(); unitinside = NULL; //informace podle typu switch(infoPanelState) { case ipsBlank: break; case ipsUnitInfo:{ GLOG("Filling InfoPanel infoPanelState==ipsUnitInfo\n"); //zprava do worldu, zjisti co o jednotce muzu zobrazit PACKET_ACT_UNIT_CLICK msg; msg.player_id = iGUIOwner; msg.type = MSG_ACT_UNIT_CLICK; msg.unit_id = selected_unit->guiuiInfo.livingunit; TPacket_RCT_UNIT_CLICK *result; result = (TPacket_RCT_UNIT_CLICK *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //livingunit lu = (*living_units)[ selected_unit->guiuiInfo.livingunit ]; lu_data = &( lu->data() ); //unit data if( !(unit_data = getUnitData(selected_unit->guiuiInfo.uid)) ) THROW(E_8K_GUI, "TGame::updateInfoPanel(): failed to query unit type\n"); // choulostive informace switch(result->knowledge){ case UK_MINE:{ GLOG("Filling InfoPanel knowledge==UK_MINE\n"); // obrazek rms->getSymbol(&rm_symbol, unit_data->symbolid, ICON_UNIT_PORTRAIT); portrait = new TIconExt(rm_symbol, INFOPANEL_BORDERS, INFOPANEL_BORDERS, INFOPANEL_PORTRAIT_BGCOLOR, 2, INFOPANEL_PORTRAIT_BORDER_COLOR); portrait->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, unit_data->nameid)); guiinfo->Add(portrait); // jmeno jednotky, pripoji za typ jednotky if(strlen(lu_data->name)){ wcsncat(wtemp, L" ", LABEL_MAX_LENGTH); UTF8toWideChar(lu_data->name, wtemp + wcslen(wtemp), INFO_TEXT_LEN_1); } label = new TLabel(wtemp, INFOPANEL_PROPERTIES_X + 10 , INFOPANEL_BORDERS, 160, 25, 1); label->setColor(INFOPANEL_VALUE_COLOR); guiinfo->Add(label); // zivoty ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 37), 126, 29); guiinfo->Add(ico); label = new TLabel(167, 41, L"%d/%d", lu_data->lives, unit_data->max_lives+lu->maxLivesBonus()); guiinfo->Add(label); // body pohybu ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 38), 220, 29); guiinfo->Add(ico); label = new TLabel(262, 41, L"%d/%d", lu_data->points_of_movement, unit_data->max_points_of_movement+lu->movementPointsBonus()); guiinfo->Add(label); //utok ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 39), 126, 72); guiinfo->Add(ico); if(unit_data->attack_range>1) label = new TLabel(167, 84, L"%d+%d(%d)", unit_data->attack, lu->attackBonus(), unit_data->attack_range+lu->attackRangeBonus()); else label = new TLabel(167, 84, L"%d+%d", unit_data->attack, lu->attackBonus()); guiinfo->Add(label); //obrana ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 40), 220, 72); guiinfo->Add(ico); label = new TLabel(262, 84, L"%d+%d", unit_data->defense, lu->defenseBonus()); guiinfo->Add(label); //uroven rm::TSymbolData *sdLevelStar = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 41); int level = lu_data->level; float sw = (float)sdLevelStar->width; if(level*sdLevelStar->width > 90) sw = 90.0f/level; // for(int i = 0; i < level; i++){ ico = new TIcon(sdLevelStar, 90 - (int)(sw*i), 93); guiinfo->Add(ico); }//for // int x, y; // muzstvo TGroupBar* men = new TGroupBar(AO_NORMAL, 156, 550-428, 147, 61); guiinfo->Add(men); rm::TSymbolData *sdGreenState = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 42); rm::TSymbolData *sdYellowState = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 43); rm::TSymbolData *sdRedState = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 44); for(int j = 0; j < lu_data->lives; j++){ x = 3+(j%6)*24; y = 2+(j/6)*20; if( lu_data->wounds[j] == UW_OK) ico = new TIcon(sdGreenState, x, y ); else if( lu_data->wounds[j] < UW_KO) ico = new TIcon(sdYellowState, x, y ); else ico = new TIcon(sdRedState, x, y ); men->Add(ico); } // bonusy TGroupBar* bonuses = new TGroupBar(AO_NORMAL, INFOPANEL_BORDERS, 122, 147, 61); guiinfo->Add(bonuses); x=4; for(int k = 0; k < lu_data->bonuses.length; k++) { UNIT_PROPERTY_BONUS_ID upbid = lu_data->bonuses.data[k]; UNIT_PROPERTY_BONUS* upb = getBonusData(upbid); // rm::TSymbolData *sdBonus = TaoKernel::getSymbol(SYMBOLS_BONUS_ICONS, upbid); y = ( bonuses->height - sdBonus->height )/2; ico = new TIcon(sdBonus, x, y ); ico->setHelp( rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, upb->nameid) ); bonuses->Add(ico); // x += sdBonus->width+8; } }break; case UK_ENEMY:{ GLOG("Filling InfoPanel knowledge==UK_ENEMY\n"); // obrazek rms->getSymbol(&rm_symbol, unit_data->symbolid, ICON_UNIT_PORTRAIT); portrait = new TIconExt(rm_symbol, INFOPANEL_BORDERS, INFOPANEL_BORDERS, INFOPANEL_PORTRAIT_BGCOLOR, 2, INFOPANEL_PORTRAIT_BORDER_COLOR); portrait->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, unit_data->nameid)); guiinfo->Add(portrait); // jmeno jednotky, pripoji se za typ jednotky if(strlen(lu_data->name)){ wcsncat(wtemp, L" ", LABEL_MAX_LENGTH); UTF8toWideChar(lu_data->name, wtemp + wcslen(wtemp), INFO_TEXT_LEN_1); } label = new TLabel(wtemp, INFOPANEL_PROPERTIES_X + 10 , INFOPANEL_BORDERS, 160, 25, 1); label->setColor(INFOPANEL_VALUE_COLOR); guiinfo->Add(label); // zivoty ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 37), 126, 29); guiinfo->Add(ico); label = new TLabel(167, 41, L"%d/%d", lu_data->lives, unit_data->max_lives+lu->maxLivesBonus()); guiinfo->Add(label); if((*players)[lu_data->player]){ UTF8toWideChar((*players)[lu_data->player]->data().game_data.name, wtemp, INFO_TEXT_LEN_1); label = new TLabel(wtemp, INFOPANEL_PROPERTIES_X + 10 , 114, 160, 16, 1); label->setColor(ColorPlayer[lu_data->player][0]/255.0f, ColorPlayer[lu_data->player][1]/255.0f, ColorPlayer[lu_data->player][2]/255.0f, 1); guiinfo->Add(label); ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 36), label->x-32, 102); ico->setColor(ColorPlayer[lu_data->player][0]/255.0f, ColorPlayer[lu_data->player][1]/255.0f, ColorPlayer[lu_data->player][2]/255.0f); guiinfo->Add(ico); } }break; case UK_NONE:{ //access denied GLOG("Filling InfoPanel knowledge==UK_NONE\n"); }break; }//switch }//if result else GLOG("TPacket_SyncResult status: %d\n", result->status); delete result; }break; case ipsBuildingInfo:{ GLOG("Filling InfoPanel infoPanelState==ipsBuildingInfo\n"); //zprava do worldu, zjisti akce PACKET_ACT_BUILDING_CLICK msg; msg.player_id = iGUIOwner; msg.type = MSG_ACT_BUILDING_CLICK; msg.building_id = selected_building->guibiInfo.livingbuilding; TPacket_RCT_BUILDING_CLICK *result; result = (TPacket_RCT_BUILDING_CLICK *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //info o typu budovy building_data = getBuildingData(selected_building->guibiInfo.bid); //info o instanci budovy lb_data = &( (*living_buildings)[ selected_building->guibiInfo.livingbuilding ]->data() ); switch(result->knowledge){ case BK_MINE:{ GLOG("Filling InfoPanel knowledge==BK_MINE\n"); // obrazek rms->getSymbol(&rm_symbol, building_data->symbolid, ICON_BUILDING_PORTRAIT); portrait = new TIconExt(rm_symbol, INFOPANEL_BORDERS, INFOPANEL_BORDERS, INFOPANEL_PORTRAIT_BGCOLOR, 2, INFOPANEL_PORTRAIT_BORDER_COLOR); portrait->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, building_data->nameid)); guiinfo->Add(portrait); // jmeno budovy, pripoji se za typ if(strlen(lb_data->name)){ wcsncat(wtemp, L" ", LABEL_MAX_LENGTH); UTF8toWideChar(lb_data->name, wtemp + wcslen(wtemp), INFO_TEXT_LEN_1); } label = new TLabel(wtemp, INFOPANEL_PROPERTIES_X + 10 , INFOPANEL_BORDERS, 160, 25, 1); label->setColor(INFOPANEL_VALUE_COLOR); guiinfo->Add(label); //budova se stavi if (lb_data->construction_duration != 0) { rmtxti->getWChar(wtemp, INFO_TEXT_LEN_1, TEXT_ISBUILDING); label = new TLabel(wtemp, INFOPANEL_PROPERTIES_X, 42); label->setColor(INFOPANEL_HIGHLIGHT_COLOR); guiinfo->Add(label); rmtxti->getWChar(wtemp, INFO_TEXT_LEN_1 - 1, TEXT_PROGRESS); label->setColor(INFOPANEL_VALUE_COLOR); label = new TLabel(INFOPANEL_PROPERTIES_X, 58, L"%ls: %d/%d()", wtemp, lb_data->lives, building_data->lives); guiinfo->Add(label); } else{ // zivoty ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 45), 126, 29); guiinfo->Add(ico); label = new TLabel(167, 41, L"%d/%d", lb_data->lives, building_data->lives); guiinfo->Add(label); //v budove je jednotka int uid = (*living_buildings)[ selected_building->guibiInfo.livingbuilding ]->unit(); if ( uid ){ //livingunit data lu_data = &( (*living_units)[ uid ]->data() ); //unit data if( !(unit_data = getUnitData(lu_data->type)) ) THROW(E_8K_GUI, "TGame::updateInfoPanel(): failed to query unit type\n"); // obrazek rms->getSymbol(&rm_symbol, unit_data->symbolid, ICON_UNIT_ICON); unitinside = new TIconButton(AO_TOOLBAR, rm_symbol, INFOPANEL_WIDTH-INFOPANEL_BORDERS-ACTION_BUTTON_WIDTH, INFOPANEL_HEIGHT-ACTION_BUTTON_HEIGHT-INFOPANEL_BORDERS, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT); // help rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, unit_data->nameid); if( strlen(lu_data->name) ){ wcsncat(wtemp, L" ", INFO_TEXT_LEN_1); int l = (int)wcslen(wtemp); UTF8toWideChar(lu_data->name, wtemp+l, INFO_TEXT_LEN_1-l); } unitinside->setHelp( wtemp ); guiinfo->Add(unitinside); } } }break; case BK_ENEMY:{ GLOG("Filling InfoPanel knowledge==BK_ENEMY\n"); // obrazek rms->getSymbol(&rm_symbol, building_data->symbolid, ICON_BUILDING_PORTRAIT); portrait = new TIconExt(rm_symbol, INFOPANEL_BORDERS, INFOPANEL_BORDERS, INFOPANEL_PORTRAIT_BGCOLOR, 2, INFOPANEL_PORTRAIT_BORDER_COLOR); portrait->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, building_data->nameid)); guiinfo->Add(portrait); // jmeno budovy, pripoji se za typ if(strlen(lb_data->name)){ wcsncat(wtemp, L" ", LABEL_MAX_LENGTH); UTF8toWideChar(lb_data->name, wtemp + wcslen(wtemp), INFO_TEXT_LEN_1); } label = new TLabel(wtemp, INFOPANEL_PROPERTIES_X + 10 , INFOPANEL_BORDERS, 160, 25, 1); label->setColor(INFOPANEL_VALUE_COLOR); guiinfo->Add(label); //budova se stavi if (lb_data->construction_duration != 0) { rmtxti->getWChar(wtemp, INFO_TEXT_LEN_1, TEXT_ISBUILDING); label = new TLabel(wtemp, INFOPANEL_PROPERTIES_X, 42); label->setColor(INFOPANEL_HIGHLIGHT_COLOR); guiinfo->Add(label); rmtxti->getWChar(wtemp, INFO_TEXT_LEN_1 - 1, TEXT_PROGRESS); label = new TLabel(INFOPANEL_PROPERTIES_X, 58, L"%ls: %d/%d()", wtemp, lb_data->lives, building_data->lives); label->setColor(INFOPANEL_VALUE_COLOR); guiinfo->Add(label); } else{ // zivoty ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 45), 126, 29); guiinfo->Add(ico); label = new TLabel(167, 41, L"%d/%d", lb_data->lives, building_data->lives); guiinfo->Add(label); } //vlastnik budovy if((*players)[lb_data->player]){ UTF8toWideChar((*players)[lb_data->player]->data().game_data.name, wtemp, INFO_TEXT_LEN_1); label = new TLabel(wtemp, INFOPANEL_PROPERTIES_X + 10 , 114, 160, 16, 1); label->setColor(ColorPlayer[lb_data->player][0]/255.0f, ColorPlayer[lb_data->player][1]/255.0f, ColorPlayer[lb_data->player][2]/255.0f, 1); guiinfo->Add(label); ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 36), label->x-32, 102); ico->setColor(ColorPlayer[lb_data->player][0]/255.0f, ColorPlayer[lb_data->player][1]/255.0f, ColorPlayer[lb_data->player][2]/255.0f); guiinfo->Add(ico); } }break; case BK_NONE:{ GLOG("Filling InfoPanel knowledge==BK_NONE\n"); }break; }//switch(knowledge) }//if result else GLOG("TPacket_SyncResult status: %d\n", result->status); delete result; }break; case ipsHexInfo:{ //nazev mesta if(map->hexes[selected_hex_index]->terrain == TT_TOWN){ getTerrainName(map->hexes[selected_hex_index]->terrain, wtemp, LABEL_MAX_LENGTH); wcsncat(wtemp, L" ", LABEL_MAX_LENGTH); int l = (int)wcslen(wtemp); getTownName(selected_hex_index, wtemp+l, LABEL_MAX_LENGTH-l); } //nazev terenu else{ getTerrainName(map->hexes[selected_hex_index]->terrain, wtemp, LABEL_MAX_LENGTH); } // label = new TLabel(wtemp, INFOPANEL_PROPERTIES_X + 10 , INFOPANEL_BORDERS, 160, 25, 1); label->setColor(INFOPANEL_VALUE_COLOR); guiinfo->Add(label); //obrazek terenu rms->getSymbol(&rm_symbol, SYMBOLS_TERRAINS, map->hexes[selected_hex_index]->terrain); portrait = new TIconExt(rm_symbol, INFOPANEL_BORDERS, INFOPANEL_BORDERS, INFOPANEL_PORTRAIT_BGCOLOR, 2, INFOPANEL_PORTRAIT_BORDER_COLOR); guiinfo->Add(portrait); //index ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 71), 126, 29); guiinfo->Add(ico); label = new TLabel(167, 41, L"%d", selected_hex_index); guiinfo->Add(label); //kralovstvi ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 72), 220, 29); guiinfo->Add(ico); label = new TLabel(262, 41, L"%d", map->hexes[selected_hex_index]->kingdom); guiinfo->Add(label); //vyska ico = new TIcon( TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 73), 126, 72); guiinfo->Add(ico); label = new TLabel(167, 84, L"%d", map->hexes[selected_hex_index]->elevation); guiinfo->Add(label); //zdroje TGroupBar* uoccurance = new TGroupBar(AO_NORMAL, INFOPANEL_BORDERS, 122, 298, 61); guiinfo->Add(uoccurance); int uol = map->hexes[selected_hex_index]->unit_occurrence.length; int x, y; x=4; for(int i = 0; i < uol; i++) { //unit data int unittype = map->hexes[selected_hex_index]->unit_occurrence.data[i]; if( !(unit_data = getUnitData(unittype)) ) THROW(E_8K_GUI, "TGame::updateInfoPanel(): failed to query unit type\n"); //unit icons rm::TSymbolData *sdUnitIcon = TaoKernel::getSymbol(unit_data->symbolid, ICON_UNIT_ICON); y = ( uoccurance->height - sdUnitIcon->height )/2; TIcon* ico = new TIcon(sdUnitIcon, x, y ); uoccurance->Add(ico); // x += sdUnitIcon->width+8; } }break; }//switch(infostate) delete rms; } void TGame::updateStatusBar(){ //vypis info o hraci, ktery vlastni gui do stavove radky //skryt diplomacii if( iGUIOwner == iPlayerOnTurn ) tdiplomacy->show(); else tdiplomacy->hide(); //skryt info if( iGUIOwner == iPlayerOnTurn ) tinfo->show(); else tinfo->hide(); //hrac UTF8toWideChar((*players)[ iGUIOwner ]->data().game_data.name, lplayername->text, LABEL_MAX_LENGTH); lplayername->setColor(ColorPlayer[iGUIOwner][0]/255.f, ColorPlayer[iGUIOwner][1]/255.f, ColorPlayer[iGUIOwner][2]/255.f,1); lplayername->x = STATUS_LPLAYER_X - (8 * ((int)wcslen(lplayername->text)+2)); iplayer->x = lplayername->x - 23; //jeho penize snwprintf(lmoney->text, LABEL_MAX_LENGTH, L"%d", (*players)[ iGUIOwner ]->data().game_data.money); //hexindex if(preselected_hex_index>=0) snwprintf(lhex->text, LABEL_MAX_LENGTH, L"%d", preselected_hex_index); else snwprintf(lhex->text, LABEL_MAX_LENGTH, L"-"); } void TGame::updateVisibility(int playerid) { guiMap->updateVisibility(playerid); guiMiniMap->refresh(playerid); } void TGame::updateVisibility(int playerid, TStep *stp) { guiMiniMap->refresh(playerid, stp); // guiMiniMap->updateVisibility(playerid, &(stp->shown), &(stp->hidden)); guiMap->updateVisibility(playerid, &(stp->shown), &(stp->hidden)); } void TGame::updateVisibility(int playerid, TIntContainer *shown, TIntContainer *hidden) { guiMiniMap->updateVisibility(playerid, shown, hidden); guiMap->updateVisibility(playerid, shown, hidden); } void TGame::lockInput(char* logmsg){ inputLock = 1; GLOG(logmsg); TaoKernel::aoKernel->cursor->setWait(); } void TGame::unlockInput(char* logmsg){ inputLock = 0; GLOG(logmsg); TaoKernel::aoKernel->cursor->setBasic(); } void TGame::lockActions(char* logmsg){ actionLock = 1; GLOG(logmsg); } void TGame::unlockActions(char* logmsg){ actionLock = 0; GLOG(logmsg); } TEventInfo* TGame::GAME_EVENT(int player, TEventInfoType eit, int loc, wchar_t* msg, ...) { // GLOG("GAME_EVENT: player=%d, type=%d, loc=%d, msg = %ls\n", player, eit, loc, msg); //zformatovani va_list args; wchar_t wbuff[MAX_EVENT_STRING_LEN]; va_start( args, msg ); vsnwprintf(wbuff, MAX_EVENT_STRING_LEN, msg, args); //nulty hrac neni if(player) { PLAYER_TYPE def_type = (*players)[player]->data().client_data.type; //soupni to i na obrazovku if( (player == iGUIOwner) && (iPlayerOnTurn == player) ){ GAME_MSG(wbuff); } //soupni to do fronty if( (iLocalGame && def_type == PT_HUMAN) || (player == iGUIOwner) ){ TEventInfo* ei = new TEventInfo(eit, wbuff, loc); (events[player])->push_back( ei ); return ei; }//if human }//if player return NULL; } void TGame::GAME_MSG(wchar_t* msg, float r, float g, float b) { osd->showMsgW(msg, r, g, b); } /////////////////////////////////////////////////////////////////////////////// // udalosti ze senzoru(dotazy do worldu) /////////////////////////////////////////////////////////////////////////////// bool TGame::isSelectable(int id) { if(selectable_hexes_map.find(id)!=selectable_hexes_map.end()) return true; return false; } void TGame::hexClicked(int indx){ // printf("TGame::hexClicked\n");//!!DBG!! if(inputLock) return; //pohyb if( selected_unit && (actionsPanelState == apsUnitMove) && isSelectable(indx)) { // printf("hexClicked:apsUnitMove\n");//!!DBG!! //gui if(TSoundInterface::si) TSoundInterface::si->playSample(selected_unit->guiuiInfo.soundsid[SOUND_COMMAND_ACKNOWLEDGE]); // lockInput("LOCK::hexclick+gaMove\n"); // actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(1); //zprava pro world PACKET_ACT_UNIT_MOVE msg_move; msg_move.type = MSG_ACT_UNIT_MOVE; msg_move.player_id = selected_unit->guiuiInfo.player; msg_move.unit_id = selected_unit->guiuiInfo.livingunit; msg_move.target = indx; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg_move); if(result->status)unlockInput("UNLOCK::result->status!=0\n"); delete result; } else if( selected_unit && (actionsPanelState == apsUnitAttack) && isSelectable(indx)){ //gui if(TSoundInterface::si) TSoundInterface::si->playSample(selected_unit->guiuiInfo.soundsid[SOUND_COMMAND_ACKNOWLEDGE]); // lockInput("LOCK::buildingclick+gaAttack\n"); // actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(2); //zprava pro world PACKET_ACT_UNIT_ATTACK msg_att; msg_att.attacker = selected_unit->guiuiInfo.livingunit; msg_att.player_id = selected_unit->guiuiInfo.player; msg_att.target = indx; msg_att.type = MSG_ACT_UNIT_ATTACK; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg_att); if(result->status)unlockInput("UNLOCK::result->status!=0\n"); delete result; } //poloha stavby else if( selected_unit && isSelectable(indx) && (actionsPanelState == apsConstructionPosition) ){ //highlituj jen vybrany guiMap->disableHexsHighlighting(3); // int allowed_orientations = selectable_hexes_map[indx]; selectable_hexes_map.clear(); selectable_hexes_map.insert(std::make_pair(indx, allowed_orientations)); std::vector v = getIndexVector(selectable_hexes_map); guiMap->highlightHexs(&v, 3); // selected_hex_index = indx; actionsPanelState = apsConstructionControl; updateActionsPanel(); //dummy objekt dummy_building = TBuilding::installDummyBuilding(guiMap, selected_building_to_build, indx, allowed_orientations); } //iniciace stavby else if( selected_unit && isSelectable(indx) && (actionsPanelState == apsConstructionControl) ){ //data int orientation = dummy_building->guibiInfo.orientation; //gui if(TSoundInterface::si) TSoundInterface::si->playSample(selected_unit->guiuiInfo.soundsid[SOUND_COMMAND_ACKNOWLEDGE]); // lockInput("LOCK::hexclick+gaBuild\n"); // actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(3); //zrus dummy objekt TBuilding::uninstallDummyBuilding(guiMap, dummy_building); dummy_building = NULL; //zprava pro world PACKET_ACT_START_BUILDING msg_build; msg_build.type = MSG_ACT_START_BUILDING; msg_build.player_id = selected_unit->guiuiInfo.player; msg_build.unit_id = selected_unit->guiuiInfo.livingunit; msg_build.building_type = selected_building_to_build; msg_build.orientation = orientation; msg_build.location = indx; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg_build); if(result->status)unlockInput("UNLOCK::result->status!=0\n"); delete result; } //oprava else if( selected_unit && (actionsPanelState == apsUnitRepair) && isSelectable(indx) ){ //gui if(TSoundInterface::si) TSoundInterface::si->playSample(selected_unit->guiuiInfo.soundsid[SOUND_COMMAND_ACKNOWLEDGE]); // lockInput("LOCK::hexclick+gaRepair\n"); // actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(3); //zjisti data TBuilding* build = (TBuilding*)( guiMap->hexy[indx]->getProxy(ptBuilding) ); assert(build); //zprava pro world PACKET_ACT_REPAIR_BUILDING msg; msg.unit_id = selected_unit->guiuiInfo.livingunit; msg.player_id = selected_unit->guiuiInfo.player; msg.building_id = build->guibiInfo.livingbuilding; msg.type = MSG_ACT_REPAIR_BUILDING; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(result->status)unlockInput("UNLOCK::result->status!=0\n"); delete result; } else if ( actionsPanelState==apsBlank || actionsPanelState==apsUnitSelection || actionsPanelState==apsBuildingSelection ) { TUnit* u = (TUnit*)guiMap->hexy[indx]->getProxy(ptDynamic); TBuilding* b = (TBuilding*)guiMap->hexy[indx]->getProxy(ptBuilding); // if( selected_unit ){ if( selected_unit == u ){ unitUnselected(); hexSelected(indx); } else{ unitUnselected(); if(b) buildingSelected(b); else if(u) unitSelected(u); else hexSelected(indx); } } else if( selected_building ){ if( selected_building == b ){ buildingUnselected(); if(u && iGUIOwner == u->guiuiInfo.player) unitSelected(u); else hexSelected(indx); } else{ buildingUnselected(); if(b) buildingSelected(b); else if(u) unitSelected(u); else hexSelected(indx); } } else if( selected_hex_index >0 ){ if( selected_hex_index == indx ){ hexUnselected(); if(b) buildingSelected(b); else if(u) unitSelected(u); } else{ hexUnselected(); if(b) buildingSelected(b); else if(u) unitSelected(u); else hexSelected(indx); } } else{ if(b) buildingSelected(b); else if(u) unitSelected(u); else hexSelected(indx); } } } void TGame::unitClicked(TUnit* unit){ if(inputLock) return; int indx = unit->hexWhereIam->getIndex(); //utok if(selected_unit && (actionsPanelState == apsUnitAttack) && isSelectable(indx)){ //gui if(TSoundInterface::si) TSoundInterface::si->playSample(selected_unit->guiuiInfo.soundsid[SOUND_COMMAND_ACKNOWLEDGE]); // lockInput("LOCK::unitclick+gaAttack\n"); // actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(2); //zprava pro world PACKET_ACT_UNIT_ATTACK msg_att; msg_att.attacker = selected_unit->guiuiInfo.livingunit; msg_att.player_id = selected_unit->guiuiInfo.player; msg_att.target = unit->hexWhereIam->getIndex(); msg_att.type = MSG_ACT_UNIT_ATTACK; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg_att); if(result->status)unlockInput("UNLOCK::result->status!=0\n"); delete result; } else if ( actionsPanelState==apsBlank || actionsPanelState==apsUnitSelection || actionsPanelState==apsBuildingSelection ) { if( selected_building ) buildingUnselected(); // if(selected_unit == unit) unitUnselected(); else{ if(selected_unit) unitUnselected(); unitSelected(unit); } } } void TGame::buildingClicked(TBuilding* build){ if(inputLock) return; int indx = build->hexWhereIam->getIndex(); //pohyb if( selected_unit && (actionsPanelState == apsUnitMove) && isSelectable(indx)){ //gui if(TSoundInterface::si) TSoundInterface::si->playSample(selected_unit->guiuiInfo.soundsid[SOUND_COMMAND_ACKNOWLEDGE]); // lockInput("LOCK::buildingclick+gaMove\n"); // actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(1); //zprava pro world PACKET_ACT_UNIT_MOVE msg_move; msg_move.type = MSG_ACT_UNIT_MOVE; msg_move.player_id = selected_unit->guiuiInfo.player; msg_move.unit_id = selected_unit->guiuiInfo.livingunit; msg_move.target = indx; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg_move); if(result->status)unlockInput("UNLOCK::result->status!=0\n"); delete result; } //utok else if( selected_unit && (actionsPanelState == apsUnitAttack) && isSelectable(indx)){ //gui if(TSoundInterface::si) TSoundInterface::si->playSample(selected_unit->guiuiInfo.soundsid[SOUND_COMMAND_ACKNOWLEDGE]); // lockInput("LOCK::buildingclick+gaAttack\n"); // actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(2); //zprava pro world PACKET_ACT_UNIT_ATTACK msg_att; msg_att.attacker = selected_unit->guiuiInfo.livingunit; msg_att.player_id = selected_unit->guiuiInfo.player; msg_att.target = indx; msg_att.type = MSG_ACT_UNIT_ATTACK; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg_att); if(result->status)unlockInput("UNLOCK::result->status!=0\n"); delete result; } //oprava else if( selected_unit && (actionsPanelState == apsUnitRepair) && isSelectable(indx) ){ //gui if(TSoundInterface::si) TSoundInterface::si->playSample(selected_unit->guiuiInfo.soundsid[SOUND_COMMAND_ACKNOWLEDGE]); // lockInput("LOCK::buildingclick+gaRepair\n"); // actionsPanelState = apsUnitSelection; updateActionsPanel(); guiMap->disableHexsHighlighting(3); //zprava pro world PACKET_ACT_REPAIR_BUILDING msg; msg.unit_id = selected_unit->guiuiInfo.livingunit; msg.player_id = selected_unit->guiuiInfo.player; msg.building_id = build->guibiInfo.livingbuilding; msg.type = MSG_ACT_REPAIR_BUILDING; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(result->status)unlockInput("UNLOCK::result->status!=0\n"); delete result; } else if ( actionsPanelState==apsBlank || actionsPanelState==apsUnitSelection || actionsPanelState==apsBuildingSelection ) { if( selected_unit ) unitUnselected(); // if(selected_building == build) buildingUnselected(); else{ if(selected_building)buildingUnselected(); buildingSelected(build); } } } void TGame::animationFinished() { unlockInput("UNLOCK::animationFinished\n"); unlockActions("ACTIONUNLOCK::animationFinished\n"); } void TGame::visibleEnemyMoved(int hid) { GLOG("visibleEnemyMoved on %d\n", hid); // focusHex(hid); } void TGame::enemyAppeared(int hid) { GLOG("enemyAppeared on %d\n", hid); P3F p3f; guiMap->hexCentre(&p3f, hid); guiMap->focus(p3f.x, p3f.y); // GAME_MSG(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_ENEMYAPPEARED)); } /////////////////////////////////////////////////////////////////////////////// // herni akce /////////////////////////////////////////////////////////////////////////////// /** herni akce = vyber hexu */ void TGame::hexSelected(int indx){ selected_hex_index = indx; // infoPanelState = ipsHexInfo; updateInfoPanel(); actionsPanelState = apsBlank; updateActionsPanel(); updateStatusBar(); } /** herni akce = odoznaceni hexu */ void TGame::hexUnselected(){ selected_hex_index = -1; // actionsPanelState = apsBlank; updateActionsPanel(); infoPanelState = ipsBlank; updateInfoPanel(); } /** herni akce = vyber jednotky */ void TGame::unitSelected(TUnit* unit){ TSelection::sel->select(unit); selected_unit = unit; // if(TSoundInterface::si){ if(selected_unit->guiuiInfo.player==iGUIOwner) TSoundInterface::si->playSample(selected_unit->guiuiInfo.soundsid[SOUND_COMMAND_SELECTED]); else ;//TSoundInterface::si->playSample(selected_unit->guiuiInfo.soundsid[SOUND_COMMAND_ENEMYSELECTED]); } // actionsPanelState = apsUnitSelection; updateActionsPanel(); infoPanelState = ipsUnitInfo; updateInfoPanel(); } /** herni akce = odznaceni jednotky */ void TGame::unitUnselected(){ TSelection::sel->unselect(selected_unit); guiMap->disableHexsHighlighting(1); selected_unit = NULL; // actionsPanelState = apsBlank; updateActionsPanel(); infoPanelState = ipsBlank; updateInfoPanel(); } /** herni akce = vyber budovy*/ void TGame::buildingSelected(TBuilding* build){ TSelection::sel->select(build); selected_building = build; // actionsPanelState = apsBuildingSelection; updateActionsPanel(); infoPanelState = ipsBuildingInfo; updateInfoPanel(); } /** herni akce = odznaceni budovy */ void TGame::buildingUnselected(){ TSelection::sel->unselect(selected_building); guiMap->disableHexsHighlighting(1); selected_building = NULL; // actionsPanelState = apsBlank; updateActionsPanel(); infoPanelState = ipsBlank; updateInfoPanel(); } void TGame::actionSelected( TGameAction ga ){ switch( ga ) { case gaAttack:{ if(!selected_unit)THROW(E_8K_GUI, "TGame::actionSelected(gaAttack): no unit selected\n"); //--- zprava pro world --- PACKET_GET_ATTACK_RANGE msg; msg.type = MSG_GET_ATTACK_RANGE; msg.unit_id = selected_unit->guiuiInfo.livingunit; msg.player_id = selected_unit->guiuiInfo.player; TPacket_RET_ATTACK_RANGE * result; result = (TPacket_RET_ATTACK_RANGE *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- vybrane hexy --- selectable_hexes_map = getMapFromVector(result->attack_range); guiMap->highlightHexs(&(result->attack_range), 2); } delete result; }break; case gaMove:{ if(!selected_unit)THROW(E_8K_GUI, "TGame::actionSelected(gaMove): no unit selected\n"); //--- zprava pro world --- PACKET_GET_RANGE msg; msg.type = MSG_GET_RANGE; msg.player_id = selected_unit->guiuiInfo.player; msg.unit_id = selected_unit->guiuiInfo.livingunit; TPacket_RET_RANGE * result; result = (TPacket_RET_RANGE *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- vybrane hexy --- selectable_hexes_map = getMapFromVector(result->range); guiMap->highlightHexs(&(result->range), 1); } delete result; }break; case gaBuild:{ if(!selected_unit)THROW(E_8K_GUI, "TGame::actionSelected(gaBuild): no unit selected\n"); //--- zprava pro world --- PACKET_GET_BUILDING_RANGE msg; msg.type = MSG_GET_BUILDING_RANGE; msg.player_id = selected_unit->guiuiInfo.player; msg.unit_id = selected_unit->guiuiInfo.livingunit; msg.building_type = selected_building_to_build; TPacket_RET_BUILDING_RANGE * result; result = (TPacket_RET_BUILDING_RANGE *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- vybrane hexy --- std::vector hl; selectable_hexes_map.clear(); for(std::vector::iterator i = result->locations.begin(); i != result->locations.end(); i++) { //vytvor masku orientace int allowed_orientations = 0; for(std::vector::iterator it = i->orientation.begin(); it != i->orientation.end(); it++) { allowed_orientations |= (1<<(*it)); } // selectable_hexes_map.insert(std::make_pair(i->position, allowed_orientations)); hl.push_back(i->position); } guiMap->highlightHexs(&hl, 3); } delete result; }break; case gaRepair:{ if(!selected_unit)THROW(E_8K_GUI, "TGame::actionSelected(gaRepair): no unit selected\n"); //--- zprava pro world --- PACKET_GET_REPAIR_RANGE msg; msg.type = MSG_GET_REPAIR_RANGE; msg.player_id = selected_unit->guiuiInfo.player; msg.unit_id = selected_unit->guiuiInfo.livingunit; TPacket_RET_REPAIR_RANGE * result; result = (TPacket_RET_REPAIR_RANGE *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- z budov vyrob hexy --- std::vector hl; selectable_hexes_map.clear(); for(std::vector::iterator it = result->buildings.begin(); it != result->buildings.end(); it++) { TBuilding* b = guiMap->guimap_buildings[ *it ]; int hindx = b->hexWhereIam->getIndex(); // hl.push_back(hindx); selectable_hexes_map.insert(std::make_pair(hindx, 0)); } //--- vybrane hexy --- guiMap->highlightHexs(&(hl), 3); //--- gui --- actionsPanelState = apsUnitRepair; } //--- neni co opravovat --- else{ //--- gui --- actionsPanelState = apsUnitSelection; } delete result; }break; case gaUnitSuicide:{ if(!selected_unit)THROW(E_8K_GUI, "TGame::actionSelected(gaUnitSuicide): no unit selected\n"); //--- zprava pro world --- PACKET_ACT_UNIT_SUICIDE msg; msg.type = MSG_ACT_UNIT_SUICIDE; msg.player_id = selected_unit->guiuiInfo.player; msg.unit_id = selected_unit->guiuiInfo.livingunit; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- gui --- lockInput("LOCK::actionSelected+gaUnitSuicide\n"); } else unlockInput("UNLOCK::result->status!=0\n"); delete result; }break; case gaBuildingSuicide:{ if(!selected_building)THROW(E_8K_GUI, "TGame::actionSelected(gaBuildingSuicide): no building selected\n"); //--- zprava pro world --- PACKET_ACT_BUILDING_SUICIDE msg; msg.type = MSG_ACT_BUILDING_SUICIDE; msg.player_id = selected_building->guibiInfo.player; msg.building_id = selected_building->guibiInfo.livingbuilding; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- gui --- lockInput("LOCK::actionSelected+gaBuildingSuicide\n"); } else unlockInput("UNLOCK::result->status!=0\n"); delete result; }break; case gaRecruitUnit:{ if(!selected_building)THROW(E_8K_GUI, "TGame::actionSelected(gaRecruitUnit): no building selected\n"); //--- zprava pro world --- PACKET_ACT_BUILDING_RECRUIT_UNIT msg; msg.type = MSG_ACT_BUILDING_RECRUIT_UNIT; msg.player_id = selected_building->guibiInfo.player; msg.building_id = selected_building->guibiInfo.livingbuilding; msg.unit_type = selected_unit_to_recruit; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- gui --- lockInput("LOCK::actionSelected+gaRecruitUnit\n"); } else unlockInput("UNLOCK::result->status!=0\n"); delete result; }break; case gaStopBuilding:{ if(!selected_unit)THROW(E_8K_GUI, "TGame::actionSelected(gaStopBuilding): no unit selected\n"); //--- zprava pro world --- PACKET_ACT_STOP_BUILDING msg; msg.type = MSG_ACT_STOP_BUILDING; msg.player_id = selected_unit->guiuiInfo.player; msg.unit_id = selected_unit->guiuiInfo.livingunit; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- gui --- lockInput("LOCK::actionSelected+gaStopBuilding\n"); } else unlockInput("UNLOCK::result->status!=0\n"); delete result; }break; case gaHeal:{ if(!selected_unit)THROW(E_8K_GUI, "TGame::actionSelected(gaHeal): no unit selected\n"); //--- zprava pro world --- PACKET_ACT_UNIT_HEAL msg; msg.type = MSG_ACT_UNIT_HEAL; msg.player_id = selected_unit->guiuiInfo.player; msg.unit_id = selected_unit->guiuiInfo.livingunit; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- gui --- lockInput("LOCK::actionSelected+gaHeal\n"); } else unlockInput("UNLOCK::result->status!=0\n"); delete result; }break; case gaRecruit:{ if(!selected_unit)THROW(E_8K_GUI, "TGame::actionSelected(gaRecruit): no unit selected\n"); //--- zprava pro world --- PACKET_ACT_UNIT_RECRUIT msg; msg.type = MSG_ACT_UNIT_RECRUIT; msg.player_id = selected_unit->guiuiInfo.player; msg.unit_id = selected_unit->guiuiInfo.livingunit; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- gui --- lockInput("LOCK::actionSelected+gaRecruit\n"); } else unlockInput("UNLOCK::result->status!=0\n"); delete result; }break; case gaRecruitElite:{ if(!selected_unit)THROW(E_8K_GUI, "TGame::actionSelected(gaRecruitElite): no unit selected\n"); //--- zprava pro world --- PACKET_ACT_UNIT_RECRUIT_ELITE msg; msg.type = MSG_ACT_UNIT_RECRUIT_ELITE; msg.player_id = selected_unit->guiuiInfo.player; msg.unit_id = selected_unit->guiuiInfo.livingunit; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- gui --- lockInput("LOCK::actionSelected+gaRecruitElite\n"); } else unlockInput("UNLOCK::result->status!=0\n"); delete result; }break; case gaSellBonus:{ if(!selected_building)THROW(E_8K_GUI, "TGame::actionSelected(gaSellBonus): no building selected\n"); //--- zprava pro world --- PACKET_ACT_SELL_BONUS msg; msg.type = MSG_ACT_SELL_BONUS; msg.player_id = selected_building->guibiInfo.player; msg.building_id = selected_building->guibiInfo.livingbuilding; msg.bonus_id = selected_bonus_to_sell; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(!result->status){ //--- gui --- lockInput("LOCK::actionSelected+gaSellBonus\n"); } else unlockInput("UNLOCK::result->status!=0\n"); delete result; }break; case gaNothing:{ }break; }//switch updateActionsPanel(); } void TGame::nextTurn(){ //odznac hexy if( actionsPanelState == apsUnitMove ) guiMap->disableHexsHighlighting(1); if( actionsPanelState == apsUnitAttack ) guiMap->disableHexsHighlighting(2); if( actionsPanelState == apsUnitRepair || actionsPanelState == apsConstructionPosition || actionsPanelState == apsConstructionControl) guiMap->disableHexsHighlighting(3); //zrus falesnou budovu // autosave at end turn if (TGUI::gui_inst->profile->autosave==1) { PACKET_SAVE_GAME msg; sprintf(msg.filename, "autosave.xml"); KSendGlobalMessage(MSG_SAVE_GAME, 0, MOD_WORLD_CLIENT, &msg); } if(dummy_building){ TBuilding::uninstallDummyBuilding(guiMap, dummy_building); dummy_building = NULL; } //odznacit budovy & jednotky if(selected_unit)unitUnselected(); if(selected_building)buildingUnselected(); int temp=TGUI::gui_inst->profile->autosave; // posli zpravu PACKET_WORLD_GUI msg_next; msg_next.player_id = iPlayerOnTurn; msg_next.type = MSG_ACT_NEXT_TURN; //smaz udalosti (events[iGUIOwner])->releaseEventsVector(); TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg_next); if(!result->status){ //zamknout gui lockInput("LOCK::nextTurn\n"); } else unlockInput("UNLOCK::result->status!=0\n"); } void TGame::focusUnit(TUnit* found_unit) { if(!found_unit)return; //odznac hexy if( actionsPanelState == apsUnitMove ) guiMap->disableHexsHighlighting(1); if( actionsPanelState == apsUnitAttack ) guiMap->disableHexsHighlighting(2); if( actionsPanelState == apsUnitRepair || actionsPanelState == apsConstructionPosition || actionsPanelState == apsConstructionControl) guiMap->disableHexsHighlighting(3); //zrus falesnou budovu if(dummy_building){ TBuilding::uninstallDummyBuilding(guiMap, dummy_building); dummy_building = NULL; } //odznacit budovy & jednotky if( selected_building )buildingUnselected(); if( selected_unit )unitUnselected(); //oznacit jednotku unitSelected(found_unit); //zaostreni guiMap->setFocus( found_unit->hexWhereIam->getIndex() ); } void TGame::focusHex(int indx) { guiMap->setFocus( indx ); } TUnit* TGame::nextUnit() { TUnit* found_unit = NULL; //pokud je zvolena jednotka, najdi nasledujici jednotku tohoto hrac if( selected_unit && (selected_unit->guiuiInfo.player == iGUIOwner) ) { int found = 0; for(std::map::iterator it = guiMap->guimap_units.begin(); it != guiMap->guimap_units.end(); it++) { World::TLivingUnit* wu = (*living_units)[it->first]; if( it->second == selected_unit ) found = 1; else if( (it->second->guiuiInfo.player == iGUIOwner) && (found == 1) && wu->isOperational()) { found = 2; found_unit = it->second; break; } } //prohledavej od zacatku if( found==1 ) for(std::map::iterator it = guiMap->guimap_units.begin(); it != guiMap->guimap_units.end(); it++) { World::TLivingUnit* wu = (*living_units)[it->first]; if( (it->second->guiuiInfo.player == iGUIOwner) && wu->isOperational()) { found = 2; found_unit = it->second; break; } }//for }//if //pokud neni zvolena, najdi prvni jednotku tohoto hrace else { for(std::map::iterator it = guiMap->guimap_units.begin(); it != guiMap->guimap_units.end(); it++) { World::TLivingUnit* wu = (*living_units)[it->first]; if( (it->second->guiuiInfo.player == iGUIOwner) && wu->isOperational() ) { found_unit = it->second; break; } }//for }//else return found_unit; } TUnit* TGame::prevUnit() { TUnit* found_unit = NULL; //pokud je zvolena jednotka, najdi nasledujici jednotku tohoto hrac if( selected_unit && (selected_unit->guiuiInfo.player == iGUIOwner) ) { int found = 0; for(std::map::reverse_iterator it = guiMap->guimap_units.rbegin(); it != guiMap->guimap_units.rend(); it++) { World::TLivingUnit* wu = (*living_units)[it->first]; if( (it->second)==selected_unit ) found = 1; else if( (it->second->guiuiInfo.player == iGUIOwner) && (found == 1) && wu->isOperational() ) { found = 2; found_unit = it->second; break; } } //prohledavej od zacatku if( found==1 ) for(std::map::reverse_iterator it = guiMap->guimap_units.rbegin(); it != guiMap->guimap_units.rend(); it++) { World::TLivingUnit* wu = (*living_units)[it->first]; if( (it->second->guiuiInfo.player == iGUIOwner) && wu->isOperational() ) { found_unit = it->second; break; } }//for }//if //pokud neni zvolena, najdi prvni jednotku tohoto hrace else { for(std::map::reverse_iterator it = guiMap->guimap_units.rbegin(); it != guiMap->guimap_units.rend(); it++) { World::TLivingUnit* wu = (*living_units)[it->first]; if( (it->second->guiuiInfo.player == iGUIOwner) && wu->isOperational() ) { found_unit = it->second; break; } }//for }//else return found_unit; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // herni udalosti z worldu(takove mapovani na gui animace/udalosti) /////////////////////////////////////////////////////////////////////////////// void mydumpvi(std::vector* ic){ for(std::vector::iterator it = (*ic).begin(); it != (*ic).end(); it++) printf("%d, ",*it); printf("\n"); } void TGame::attackUnit(TPacket_RCT_UNIT_ATTACK* rua){ //log GLOG("attackUnit:: dl:%d, al:%d, bl:%d, ak:%d, dk:%d, bd:%d\n", rua->defender_losses, rua->attacker_losses, rua->building_losses, rua->attacker_killed, rua->defender_killed, rua->building_destroyed ); //jak interperetovat boj? THex* hex = guiMap->hexy[rua->target]; TBuilding* b = (TBuilding*)hex->getProxy(ptBuilding); TUnit* u = (TUnit*)hex->getProxy(ptDynamic); TUnit* attacker = guiMap->guimap_units[ rua->attacker ]; // lockActions("ACTIONSLOCK: attackUnit\n"); lockInput("LOCK::attackUnit\n"); //dbg if(b_dbg){ attacker->attack(u, b, b_kill, b_loss, b_dmgs, b_ad, b_dd, b_bd, NULL, NULL); } else{ //utok attacker->attack(u, b, rua->defender_losses, rua->attacker_losses, rua->building_losses, rua->attacker_killed, rua->defender_killed, rua->building_destroyed, &(rua->attacker_hidden), &(rua->defender_hidden)); } //udalost int attacker_player = attacker->guiuiInfo.player; int defender_player = 0; if(u)defender_player = u->guiuiInfo.player; if(b)defender_player = b->guibiInfo.player; if(defender_player){ wchar_t attacker_playername[MAX_STRLEN+1]; UTF8toWideChar((*players)[attacker_player]->data().game_data.name, attacker_playername, MAX_STRLEN); // GAME_EVENT(defender_player, eitComment, rua->target, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_BATTLE), attacker_playername ); } //focusovani if(defender_player == iGUIOwner){ P3F p3f; guiMap->hexCentre(&p3f, rua->target); guiMap->focus(p3f.x, p3f.y); //utok na jednotku if(u) GAME_MSG(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNITUNDERATTACK)); //utok na budovu else GAME_MSG(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_BUILDINGUNDERATTACK)); } } void TGame::moveUnit(int luid, TPath *path){ //test na delku cesty if(path->size()>1){ // TUnit* unit = guiMap->guimap_units[luid]; if(!unit)THROW(E_8K_GUI, "TGame::moveUnit(): unit not exist\n") // lockActions("ACTIONSLOCK: moveUnit\n"); lockInput("LOCK::moveUnit\n"); // unit->gotoHex(path); } else{ // unlockActions("ACTIONSUNLOCK: moveUnit(pathsize==0)\n"); unlockInput("UNLOCK::moveUnit(pathsize==0)\n"); } //obnov informace o jednotce updateInfoPanel(); } void TGame::unitSuicide(TPacket_RCT_UNIT_SUICIDE* rus){ // lockActions("ACTIONSLOCK: unitSuicide\n"); lockInput("LOCK::unitSuicide\n"); // TUnit* unit = guiMap->guimap_units[rus->unit_id]; // unit->realeaseUnit(rus->hidden); //obnov gui if(selected_unit == unit)unitUnselected(); updateStatusBar(); } void TGame::buildingSuicide(TPacket_RCT_BUILDING_SUICIDE* rbs){ // lockActions("ACTIONSLOCK: buildingSuicide\n"); lockInput("LOCK::buildingSuicide\n"); // TBuilding* building = guiMap->guimap_buildings[rbs->building_id]; // building->demolishBuilding(rbs->hidden); //obnov gui if(selected_building == building)buildingUnselected(); updateStatusBar(); } void TGame::recruitUnit(TPacket_RCT_BUILDING_RECRUIT_UNIT* rbru){ //vytvor jednotku gui::TBuilding* b = guiMap->guimap_buildings[rbru->building_id]; b->recruitUnit( rbru->unit_id ); //obnov gui if(selected_building == b)actionsPanelState = apsBuildingSelection; if ( b->guibiInfo.player == iGUIOwner) { updateVisibility(b->guibiInfo.player, &(rbru->shown), NULL); } updateActionsPanel(); updateInfoPanel(); updateStatusBar(); //odemkni gui unlockInput("UNLOCK::recruitUnit\n"); /* * BUILDING_ID building_id; UNIT_TYPE_ID unit_type; * UNIT_ID unit_id; MONEY cost; * TIntContainer shown; */ } void TGame::startBuilding(TPacket_RCT_START_BUILDING* rsb){ // World::LIVING_BUILDING* lb = &( (*living_buildings)[ rsb->building_id ]->data() ); gui::TUnit* unit = guiMap->guimap_units[rsb->unit_id]; // lockActions("ACTIONSLOCK: startBuilding\n"); lockInput("LOCK::startBuilding\n"); // unit->build(rsb->location, rsb->building_id, lb); //obnov gui if(selected_unit == unit)actionsPanelState=apsUnitSelection; if ( unit->guiuiInfo.player == iGUIOwner) { updateVisibility(unit->guiuiInfo.player, &(rsb->shown), &(rsb->hidden)); } updateActionsPanel(); updateInfoPanel(); updateStatusBar(); /* * UNIT_ID unit_id; * BUILDING_TYPE_ID building_type; * HEX_ID location; * BUILDING_ID building_id; MONEY cost; * TIntContainer shown; * TIntContainer hidden; */ } void TGame::buildingOccupied(TPacket_BUILDING_OCCUPIED* bo){ //najdi budovu gui::TBuilding* b = guiMap->guimap_buildings[bo->building_id]; //prehrej obsazeni b->occupy(bo->new_player_id); //viditelnost if ( bo->new_player_id == iGUIOwner) updateVisibility(bo->new_player_id, &(bo->shown), NULL); if ( bo->former_player_id == iGUIOwner) updateVisibility(bo->former_player_id, NULL, &(bo->hidden)); //udalost if(bo->former_player_id){ wchar_t playername[MAX_STRLEN+1]; UTF8toWideChar((*players)[bo->former_player_id]->data().game_data.name, playername, MAX_STRLEN); // GAME_EVENT(bo->former_player_id, eitComment, b->hexWhereIam->getIndex(), rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_BUILDINGANNEXION), playername); } /* * int building_id; * int new_player_id; * int former_player_id; * TIntContainer hidden; * TIntContainer shown; */ } void TGame::townOccupied(TPacket_TOWN_OCCUPIED *to){ //prehrej obsazeni guiMap->townOccupy(to->town_id, to->new_player_id); guiMiniMap->refreshSpecial(iGUIOwner); //viditelnost if ( to->new_player_id == iGUIOwner) updateVisibility(to->new_player_id, &(to->shown), NULL); if ( to->former_player_id == iGUIOwner) updateVisibility(to->former_player_id, NULL, &(to->hidden)); //najit mesto TOWN* t = &( (*towns)[to->town_id]->data() ); int hpos = -1; if(t->citysize)hpos = t->position[0]; //udalost if(to->former_player_id){ wchar_t playername[MAX_STRLEN+1]; UTF8toWideChar((*players)[to->new_player_id]->data().game_data.name, playername, MAX_STRLEN); // GAME_EVENT(to->former_player_id, eitComment, hpos, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_TOWNANNEXED), playername); } GAME_EVENT(to->new_player_id, eitComment, hpos, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_ANNEXEDTOWN) ); /* * int town_id; * int new_player_id; * int former_player_id; * TIntContainer hidden; * TIntContainer shown; */ } void TGame::kingdomOccupied(TPacket_KINGDOM_OCCUPIED *ko){ //prebarvit hexy guiMap->kingdomOccupy(ko->kingdom_id, ko->new_player_id); guiMiniMap->refresh(iGUIOwner); //najit kralovstvi, jeho stred KINGDOM* k = &( (*kingdoms)[ko->kingdom_id]->data() ); int hpos = -1; hpos = guiMap->getHexIndex(k->centerx, k->centery); //udalost if(ko->former_player_id){ wchar_t playername[MAX_STRLEN+1]; UTF8toWideChar((*players)[ko->new_player_id]->data().game_data.name, playername, MAX_STRLEN); // GAME_EVENT(ko->former_player_id, eitComment, hpos, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_KINGDOMANNEXED), playername); GAME_EVENT(ko->new_player_id, eitComment, hpos, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_ANNEXEDKINGDOM)); } /* * int kingdom_id; * int new_player_id; * int former_player_id; */ } void TGame::unitRecruit(TPacket_RCT_UNIT_RECRUIT* ur){ gui::TUnit* unit = guiMap->guimap_units[ur->unit_id]; unit->recruit(ur->lives); //obnov gui updateActionsPanel(); updateInfoPanel(); updateStatusBar(); //odemkni gui unlockInput("UNLOCK::unitRecruit\n"); /* int level; int experience; * int unit_id; * int lives; */ } void TGame::unitRecruitElite(TPacket_RCT_UNIT_RECRUIT_ELITE* ure){ gui::TUnit* unit = guiMap->guimap_units[ure->unit_id]; unit->recruit(ure->lives); //obnov gui updateActionsPanel(); updateInfoPanel(); updateStatusBar(); //odemkni gui unlockInput("UNLOCK::unitRecruitElite\n"); /* * int unit_id; * int lives; */ } void TGame::unitHeal(TPacket_RCT_UNIT_HEAL* uh){ gui::TUnit* unit = guiMap->guimap_units[uh->unit_id]; unit->heal(); //obnov gui updateActionsPanel(); updateInfoPanel(); updateStatusBar(); //odemkni gui unlockInput("UNLOCK::unitHeal\n"); /* * int unit_id; int lives; */ } void TGame::repairBuilding(TPacket_RCT_REPAIR_BUILDING* rb){ GLOG("repairBuilding: unit_id=%d, building_id=%d\n", rb->unit_id, rb->building_id); TBuilding* b = guiMap->guimap_buildings[rb->building_id]; int bhex = b->hexWhereIam->getIndex(); TUnit* u = guiMap->guimap_units[rb->unit_id]; int uhex = u->hexWhereIam->getIndex(); //akce u->repair(bhex, b, rb->shown, rb->hidden); //obnov informace o jednotce updateActionsPanel(); updateInfoPanel(); //zamkni gui lockInput("LOCK::repairBuilding\n"); /* * UNIT_ID unit_id; * BUILDING_ID building_id; int lives; MONEY cost; * TIntContainer shown; * TIntContainer hidden; */ } void TGame::stopBuilding(TPacket_RCT_STOP_BUILDING* sb){ GLOG("stopBuilding: unit_id=%d\n", sb->unit_id); TUnit* u = guiMap->guimap_units[sb->unit_id]; u->stopBuilding(); //obnov informace o jednotce updateActionsPanel(); updateInfoPanel(); updateStatusBar(); // unlockInput("UNLOCK::stopBuilding\n"); //zprava na obrazovku if( u->guiuiInfo.player == iGUIOwner ) GAME_MSG(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_CONSTABORTED)); /* * UNIT_ID unit_id; */ } void TGame::sellBonus(TPacket_RCT_SELL_BONUS* sb){ GLOG("sellBonus: building_id=%d, bonus_id=%d\n", sb->building_id, sb->bonus_id); // TBuilding* b = guiMap->guimap_buildings[sb->building_id]; //obnov gui if(selected_building == b)actionsPanelState = apsBuildingSelection; updateActionsPanel(); updateInfoPanel(); updateStatusBar(); //odemkni gui unlockInput("UNLOCK::sellBonus\n"); /* * BUILDING_ID building_id; UNIT_PROPERTY_BONUS_ID bonus_id; MONEY cost; */ } void TGame::diplomacyChange(TPacket_DIPLOMACY_RELATION_CHANGE* drc){ GLOG("Diplomacy Change: target %d, oldrel %d, newrel %d, newoffer %d, oldoffer %d\n", drc->target_diplomat_world_id, drc->old_relationship, drc->new_relationship, drc->new_offered_relationship, drc->old_offered_relationship ); //jmeno hrace wchar_t source_playername[MAX_STRLEN+1]; wchar_t target_playername[MAX_STRLEN+1]; UTF8toWideChar((*players)[drc->source_diplomat_world_id]->data().game_data.name, source_playername, MAX_STRLEN); UTF8toWideChar((*players)[drc->target_diplomat_world_id]->data().game_data.name, target_playername, MAX_STRLEN); //zmena if(drc->old_relationship != drc->new_relationship){ switch( drc->new_relationship ){ case ai_ns::diplomacy_ns::RELATIONSHIP_WAR: GAME_EVENT(drc->target_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_TRG_RELBECOMEWAR), source_playername); GAME_EVENT(drc->source_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_SRC_RELBECOMEWAR), target_playername); break; case ai_ns::diplomacy_ns::RELATIONSHIP_ENEMY: GAME_EVENT(drc->target_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_TRG_RELBECOMEENEMY), source_playername); GAME_EVENT(drc->source_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_SRC_RELBECOMEENEMY), target_playername); break; case ai_ns::diplomacy_ns::RELATIONSHIP_TRUCE: GAME_EVENT(drc->target_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_TRG_RELBECOMENEUTRAL), source_playername); GAME_EVENT(drc->source_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_SRC_RELBECOMENEUTRAL), target_playername); break; case ai_ns::diplomacy_ns::RELATIONSHIP_ALLY: GAME_EVENT(drc->target_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_TRG_RELBECOMEALLY), source_playername); GAME_EVENT(drc->source_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_SRC_RELBECOMEALLY), target_playername); break; } } else if(drc->old_offered_relationship != drc->new_offered_relationship){ switch( drc->new_offered_relationship ){ case ai_ns::diplomacy_ns::RELATIONSHIP_WAR: GAME_EVENT(drc->target_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_TRG_RELOFFERWAR), source_playername); GAME_EVENT(drc->source_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_SRC_RELOFFERWAR), target_playername); break; case ai_ns::diplomacy_ns::RELATIONSHIP_ENEMY: GAME_EVENT(drc->target_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_TRG_RELOFFERENEMY), source_playername); GAME_EVENT(drc->source_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_SRC_RELOFFERENEMY), target_playername); break; case ai_ns::diplomacy_ns::RELATIONSHIP_TRUCE: GAME_EVENT(drc->target_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_TRG_RELOFFERNEUTRAL), source_playername); GAME_EVENT(drc->source_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_SRC_RELOFFERNEUTRAL), target_playername); break; case ai_ns::diplomacy_ns::RELATIONSHIP_ALLY: GAME_EVENT(drc->target_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_TRG_RELOFFERALLY), source_playername); GAME_EVENT(drc->source_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_SRC_RELOFFERALLY), target_playername); break; } } //pokuta if(drc->source_diplomat_penalty){ GAME_EVENT(drc->source_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_PENALTY), drc->source_diplomat_penalty); } if(drc->target_diplomat_penalty){ GAME_EVENT(drc->target_diplomat_world_id, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_PENALTY2), drc->target_diplomat_penalty); } // updateStatusBar(); /* * int source_diplomat_world_id; * int target_diplomat_world_id; * ai_ns::diplomacy_ns::TRelationship old_relationship; * ai_ns::diplomacy_ns::TRelationship old_offered_relationship; * ai_ns::diplomacy_ns::TRelationship new_relationship; * ai_ns::diplomacy_ns::TRelationship new_offered_relationship; * MONEY source_diplomat_penalty; * MONEY target_diplomat_penalty; */ } void TGame::playerChanged( TPacket_RCT_NEXT_TURN* rnt ){ //flag int showevent = 1; //hrac na tahu iPlayerOnTurn = rnt->player_id_on_turn; // GLOG("playerChanged: playerOnTurn=%d\n", iPlayerOnTurn); // TIntArray::iterator iait; TIntContainer::iterator icit; std::set unitOrdered; //pri lokalni hre se meni vlastnik if(iLocalGame){ //pokud je zmeneny hrac clovek, zmeni se vlastnik if( (*players)[iPlayerOnTurn]->data().client_data.type == PT_HUMAN ){ GLOG("switching gui from %d to player=%d\n", iGUIOwner, iPlayerOnTurn); iGUIOwner = iPlayerOnTurn; } } //---------------------------------------------------------------------------- //vytvor seznam udalosti //---------------------------------------------------------------------------- //smaz osd v lokalni hre, at se to neplete if(iLocalGame) osd->vMsgs.clear(); osd->iClosed = 1; ////novy kolo //if( iGUIOwner == player && rnt->newRound) // GAME_EVENT(player, eitComment, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_NEWROUND)); //zmena pocasi if( rnt->weatherState != World::WEATHER_STATE(guiMap->wc->state) ){ GLOG("weatherState: %d\n", rnt->weatherState); guiMap->wc->change( gui::TWeatherState(rnt->weatherState) ); if( iGUIOwner == iPlayerOnTurn ) GAME_EVENT(iPlayerOnTurn, eitComment, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_WEATHER)); } //penize if( iGUIOwner == iPlayerOnTurn) GAME_EVENT(iPlayerOnTurn, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_GOLDPROFIT), rnt->moneyGain); //nedostatek penez if( iGUIOwner == iPlayerOnTurn && rnt->moneyLack) GAME_EVENT(iPlayerOnTurn, eitWarning, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_LOWMONEY)); //---------------------------------------------------------------------------- //udalosti budov //---------------------------------------------------------------------------- for(iait = rnt->buildingLives.begin(); iait != rnt->buildingLives.end(); iait++) { //zjisti budovu TBuilding* b = (guiMap->guimap_buildings)[iait->first]; World::BUILDING* wb = getBuildingData(b->guibiInfo.bid); World::LIVING_BUILDING *lb = &( (*living_buildings)[ iait->first ]->data() ); int hex = b->hexWhereIam->getIndex(); //zpravicky if( iGUIOwner == iPlayerOnTurn) GAME_EVENT(iPlayerOnTurn, eitInfo, hex, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_BUILDINGHEAL), iait->second); //dostaveno & opraveno if( b->guibiInfo.underconstruction && lb->lives == wb->lives ){ if( iGUIOwner == iPlayerOnTurn) GAME_EVENT(iPlayerOnTurn, eitComment, hex, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_BUILDINGBUILT), iait->second); b->buildingCompleted(); } else if( !b->guibiInfo.underconstruction ){ if( iGUIOwner == iPlayerOnTurn && lb->lives == wb->lives ) GAME_EVENT(iPlayerOnTurn, eitComment, hex, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_BUILDINGREPAIRED), iait->second); // b->repairDamage(lb->lives-iait->second, lb->lives, wb->lives); } //dbg GLOG("budova: %d ziskala: %d\n", iait->first, iait->second); } //---------------------------------------------------------------------------- //udalosti jednotek //---------------------------------------------------------------------------- //rozprchle jednotky for(icit = rnt->unitsDeserted.begin(); icit != rnt->unitsDeserted.end(); icit++) { if( unitOrdered.find(*icit) != unitOrdered.end() )continue; else unitOrdered.insert(*icit); // GLOG("unitsDeserted: %d\n", *icit); TUnit* u = (guiMap->guimap_units)[*icit]; //urcene pro hrace if( iGUIOwner == iPlayerOnTurn ){ int hid = u->hexWhereIam->getIndex(); if(showevent){ TEventInfo* ei = GAME_EVENT(iPlayerOnTurn, eitUnitDeserted, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNITWASDISBANDED)); ei->data1 = (void*)u; } else{ u->desert(); GAME_EVENT(iPlayerOnTurn, eitInfo, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNITWASDISBANDED)); } } //neviditelne pro protivnika else{ u->desert(); } } //mrtve jednotky for(icit = rnt->unitsDied.begin(); icit != rnt->unitsDied.end(); icit++) { if( unitOrdered.find(*icit) != unitOrdered.end() )continue; else unitOrdered.insert(*icit); // GLOG("unitsDied: %d\n",*icit); TUnit* u = (guiMap->guimap_units)[*icit]; //pro hrace TIntContainer h; if( iGUIOwner == iPlayerOnTurn ){ int hid = u->hexWhereIam->getIndex(); if(showevent){ TEventInfo* ei = GAME_EVENT(iPlayerOnTurn, eitUnitDied, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNITDIED)); ei->data1 = (void*)u; } else{ u->realeaseUnit(h); GAME_EVENT(iPlayerOnTurn, eitInfo, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNITDIED)); } } else{ u->realeaseUnit(h); } } //neleceni panacci for(iait = rnt->menDied.begin(); iait != rnt->menDied.end(); iait++) { int uid = iait->first; int count = iait->second; // if( unitOrdered.find(uid) != unitOrdered.end() )continue; // GLOG("membersDied: %d - %d\n", uid, count); TUnit* u = (guiMap->guimap_units)[uid]; //pro hrace if( iGUIOwner == iPlayerOnTurn ){ int hid = u->hexWhereIam->getIndex(); if(showevent){ TEventInfo* ei = NULL; if(u->guiuiInfo.formation == ftIndividualFormation) ei = GAME_EVENT(iPlayerOnTurn, eitUnitMembersDied, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNHEALEDWOUNDS)); else ei = GAME_EVENT(iPlayerOnTurn, eitUnitMembersDied, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNHEALEDMEN)); ei->data1 = (void*)u; ei->data2 = *((void**)&count); } else{ u->membersDied(count); if(u->guiuiInfo.formation == ftIndividualFormation) GAME_EVENT(iPlayerOnTurn, eitInfo, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNHEALEDWOUNDS)); else GAME_EVENT(iPlayerOnTurn, eitInfo, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNHEALEDMEN)); } } else{ u->membersDied(count); } } //prerusene jednotky for(icit = rnt->unitsInterrupted.begin(); icit != rnt->unitsInterrupted.end(); icit++) { if( unitOrdered.find(*icit) != unitOrdered.end() )continue; GLOG("unitsInterrupted: %d\n",*icit); TUnit* u = (guiMap->guimap_units)[*icit]; //pro hrace if( iGUIOwner == iPlayerOnTurn ){ int hid = u->hexWhereIam->getIndex(); if(showevent){ TEventInfo* ei = GAME_EVENT(iPlayerOnTurn, eitUnitInterrupted, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNITINTERRPUTED)); ei->data1 = (void*)u; } else{ u->stopBuilding(); GAME_EVENT(iPlayerOnTurn, eitInfo, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_UNITINTERRPUTED)); } } else{ u->stopBuilding(); } } //jednotky pred umrenim for(icit = rnt->unitsWounded.begin(); icit != rnt->unitsWounded.end(); icit++) { if( unitOrdered.find(*icit) != unitOrdered.end() )continue; // GLOG("unitsWounded: %d\n",*icit); if( iGUIOwner == iPlayerOnTurn ){ TUnit* u = (guiMap->guimap_units)[*icit]; int hid = u->hexWhereIam->getIndex(); // GAME_EVENT(iPlayerOnTurn, eitWarning, hid, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_WILLDIE)); } } //viditelnost, neni potreba protoze se dela celkovy update // //if( iGUIOwner == player ){ // if(showevent) { // TEventInfo* ei = // GAME_EVENT(player, eitVisibilityUpdate, -1, L""); // // // TIntContainer* hidden = new TIntContainer; // TIntContainer* shown = new TIntContainer; // *shown = rnt->shown; // *hidden = rnt->hidden; // // // ei->data1 = shown; // ei->data2 = hidden; // } // else { // updateVisibility(player, &(rnt->shown), &(rnt->hidden)); // } //} //---------------------------------------------------------------------------- //update gui //---------------------------------------------------------------------------- osd->iClosed = 0; updateInfoPanel(); updateActionsPanel(); updateVisibility(iGUIOwner); if(!showevent) { updateStatusBar(); } //---------------------------------------------------------------------------- //insertuj udalosti do infookna //---------------------------------------------------------------------------- if( iGUIOwner == iPlayerOnTurn) { //smaz seznam udalosti eventswindow->clearList(); for( TEventVector::iterator evit = (events[iGUIOwner])->begin(); evit != (events[iGUIOwner])->end(); evit++) { eventswindow->addEvent(*evit); } //spust animace if(showevent) { GLOG("playerChanged - call showEvents\n"); guiMap->ep->showEvents( events[iGUIOwner] ); } //jen infookno else { focusUnit( nextUnit() ); #ifndef CLIENT_AUTOPLAY eventswindow->showModal(); #endif //odemkni unlockInput("UNLOCK::playerChanged\n"); } } else { eventswindow->hide(); //odemkni unlockInput("UNLOCK::playerChanged\n"); } } void TGame::playerDefeated(TPacket_PLAYER_DEFEATED* pd){ //prohral jsem v sitovy hre if(iGUIOwner == pd->defeated_player_id && !iLocalGame){ osd->iClosed = 1; //vysledek TGuiEndGame* end = new TGuiEndGame((World::ENDGAME_REASON)0, players, -1); (events[iGUIOwner])->releaseEventsVector(); GAME_EVENT(iGUIOwner, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_YOU_WERE_DEFEATED)); GAME_EVENT(iGUIOwner, eitEndGame, -1, L""); TEventInfo* ei = GAME_EVENT(iGUIOwner, eitExitGame, -1, L""); ei->data1 = end; // osd->iClosed = 0; guiMap->ep->showEvents( events[iGUIOwner] ); } //prohral protihrac v sitovy, nebo v lokalni else{ wchar_t wtemp2[255 + LABEL_MAX_LENGTH + MAX_STRLEN + 1]; wchar_t playername[MAX_STRLEN+1]; UTF8toWideChar((*players)[pd->defeated_player_id]->data().game_data.name, playername, MAX_STRLEN); rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_PLAYER_DEFEATED); snwprintf(wtemp2, 255 + LABEL_MAX_LENGTH, wtemp, playername); GAME_EVENT(iGUIOwner, eitInfo, -1, wtemp2); } /* * int defeated_player_id; */ } void TGame::endGame(TPacket_END_GAME* eg){ //data pro vyslednou obrazovku TGuiEndGame* end = new TGuiEndGame(eg->reason, players, eg->winner); //smaz udalosti (events[iGUIOwner])->releaseEventsVector(); osd->iClosed = 1; //vloz koncovou(=zprava->stmivacka->prepnuti) switch(eg->reason){ case ER_CANCEL: GAME_EVENT(iGUIOwner, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_GAME_WAS_CANCELED));break; case ER_SHUTDOWN: GAME_EVENT(iGUIOwner, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_SERVER_WAS_CLOSED));break; case ER_VICTORY_DESTROY: GAME_EVENT(iGUIOwner, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_WINNER_WON));break; case ER_VICTORY_CONQUER: GAME_EVENT(iGUIOwner, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_CITIES_CONQUERED));break; case ER_VICTORY_TIMEOUT: GAME_EVENT(iGUIOwner, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_AFTER_TIME_GAME_ENDS));break; case ER_DRAW: GAME_EVENT(iGUIOwner, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_DRAW_GAME));break; default: GAME_EVENT(iGUIOwner, eitInfo, -1, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_GAME_ABORTED));break; } GAME_EVENT(iGUIOwner, eitEndGame, -1, L""); TEventInfo* ei = GAME_EVENT(iGUIOwner, eitExitGame, -1, L""); ei->data1 = end; //let's play osd->iClosed = 0; guiMap->ep->showEvents( events[iGUIOwner] ); /* * World::ENDGAME_REASON reason; * PLAYER_ID winner; */ } void TGame::errorResult(TPacket_ErrorResult* er){ // switch(er->error){ case ERR_NotEnoughMoney: GAME_MSG(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_EVENT_LOWMONEY));break; case ERR_InvalidInput: GAME_MSG(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_ERROR));break; // default: GAME_MSG(L"Neni mozne splinit pozadavek.");break; } // updateActionsPanel(); updateInfoPanel(); updateStatusBar(); unlockInput("UNLOCK::errorResult\n"); } /** nahravaci vlakno */ int loadingMap_thread(void* data){ rm::TRM_txt_i *rmtxti = (rm::TRM_txt_i *)KSendGlobalMessage(MSG_GET_RM_TXT_I, MOD_GUI, MOD_RM, NULL); try{ TGame* game = (TGame*)data; wchar_t wtemp[LABEL_MAX_LENGTH]; //faze 2 KSendGlobalMsg(MSG_MAPLOADING_MSG, ANNONYMOUS, MOD_GUI, (PARAM)rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_ENTERPHASE2)); TGUI::gui_inst->enterResourcePhase(2); //vytvor guimapu! KSendGlobalMsg(MSG_MAPLOADING_MSG, ANNONYMOUS, MOD_GUI, (PARAM)rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_INITGUIMAP)); game->guiMap->init(); //napoji minimapu KSendGlobalMsg(MSG_MAPLOADING_MSG, ANNONYMOUS, MOD_GUI, (PARAM)rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_INITMINIMAP)); game->guiMiniMap->init(); //oznam vytoreni KSendGlobalMsg(MSG_MAPLOADING_MSG, ANNONYMOUS, MOD_GUI, (PARAM)rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_GAMEREADY)); KSendGlobalMsg(MSG_GUIMAP_READY, MOD_GUI, BROADCAST, NULL); // delete rmtxti; game->loading_thread = NULL; } catch(E_8K e){ GLOG(e.getDescription()); KSendMessage(RQUEUE,MSG_EXCEPTION_IN_THREAD,MOD_GUI, BROADCAST, &e); delete rmtxti; return -1; } return 0; } void TGame::loadGameMap(PACKET_LETS_GO* plg){ //hlaska KSendGlobalMsg(MSG_MAPLOADING_MSG, ANNONYMOUS, MOD_GUI, (PARAM)rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_GAMEREADY)); //zrus stavy nullStates(); //nastav pointery do worldu - DOCASNE RESENI map = plg->map; visibility_maps = plg->visibility_maps; living_units = plg->living_units; living_buildings = plg->living_buildings; players = plg->players; iGUIOwner = plg->human_player; iPlayerOnTurn = plg->player_on_turn; towns = plg->towns; kingdoms = plg->kingdoms; weather = plg->weather; //vlakno ktery vytvari guimapu loading_thread = SDL_CreateThread(&loadingMap_thread, this); /* World::TRules * rules; * World::MAP * map; * World::TVisibilityMapsContainer * visibility_maps; World::TWeather * weather; * World::TTownsContainer * towns; * World::TKingdomsContainer * kingdoms; * World::TLivingUnitsContainer * living_units; World::TLivingUnitsContainer * corpses; * World::TLivingBuildingsContainer * living_buildings; World::TLivingBuildingsContainer * ruins; * World::TPlayerContainer * players; int turn_id; * PLAYER_ID player_on_turn; * PLAYER_ID human_player; */ } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // dalsi udalosti /////////////////////////////////////////////////////////////////////////////// void TGame::chatMsg(TPackage *p) { if (!iLocalGame) if (osdchat) osdchat->receiveMsg(p); } void TGame::clientReconnected(int cid){ for(int i = 0; i < TGUI::gui_inst->clientsinfo.num; i++) { if(TGUI::gui_inst->clientsinfo.cinfo[i].clientid == cid){ wchar_t wtemp2[100 + LABEL_MAX_LENGTH]; // UTF8toWideChar(TGUI::gui_inst->clientsinfo.cinfo[i].profileName, wtemp2, 100); rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_HASCONNECTED); // snwprintf(wtemp2 + wcslen(wtemp2), LABEL_MAX_LENGTH, L" %ls", wtemp); GAME_MSG(wtemp2); } } } void TGame::clientDisconnected(int cid){ for(int i = 0; i < TGUI::gui_inst->clientsinfo.num; i++) { if(TGUI::gui_inst->clientsinfo.cinfo[i].clientid == cid){ wchar_t wtemp2[100 + LABEL_MAX_LENGTH]; // UTF8toWideChar(TGUI::gui_inst->clientsinfo.cinfo[i].profileName, wtemp2, 100); rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_HASDISCONNECTED); // snwprintf(wtemp2 + wcslen(wtemp2), LABEL_MAX_LENGTH, L" %ls", wtemp); GAME_MSG(wtemp2); } } } void TGame::gameEnding(){ GAME_MSG(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_GAME_ENDING)); } /////////////////////////////////////////////////////////////////////////////// // data z worldu /////////////////////////////////////////////////////////////////////////////// void TGame::getWorldData(World::MAP** m, World::TLivingUnitsContainer** lu, World::TLivingBuildingsContainer** lb){ if(m)(*m) = map; if(lu)(*lu) = living_units; if(lb)(*lb) = living_buildings; } void TGame::getWorldData(World::TTownsContainer** ts, World::TKingdomsContainer** k){ if(ts)(*ts) = towns; if(k)(*k) = kingdoms; } void TGame::getWorldPlayers(World::TPlayerContainer **pls) { if (players) (*pls) = players; } void TGame::getWorldVisibility(World::TVisibilityMapsContainer **vmaps) { if (vmaps) (*vmaps) = visibility_maps; } void TGame::getWorldWeather(World::TWeather **weat) { if (weat) (*weat) = weather; } /////////////////////////////////////////////////////////////////////////////// // zjistovaci /////////////////////////////////////////////////////////////////////////////// void TGame::getTownName(int si, wchar_t* w, int maxlen) { for(World::TTownsContainer::iterator tit = towns->begin(); tit != towns->end(); tit++){ TOWN* t = &((*tit).second->data()); //projdi hexy mesta. for(int i = 0; i < t->citysize; i++){ if( t->position[i] == si ){ UTF8toWideChar(t->name, w, maxlen); return; } }//for cityhexes } //nenalezeno nastav retezec mesto getTerrainName(TT_TOWN, w, maxlen); } int TGame::getTownHexOwner(int hid) { TOWN* t = NULL; // for(World::TTownsContainer::iterator it = towns->begin(); it != towns->end(); it++) { t = &((*it).second->data()); for(int i = 0; i < t->citysize; i++) { if( t->position[i] == hid ) { return t->owner; }//if }//for }//for return 0; } void TGame::getTerrainName(TERRAIN_TYPE tt, wchar_t* w, int maxlen) { switch(tt){ case TT_PLAIN: rmtxti->getWChar(w, maxlen, TEXT_TERRAIN_PLAIN); break; case TT_FOREST: rmtxti->getWChar(w, maxlen, TEXT_TERRAIN_FOREST); break; case TT_DEEP_FOREST: rmtxti->getWChar(w, maxlen, TEXT_TERRAIN_DEEP_FOREST); break; case TT_ROCKS: rmtxti->getWChar(w, maxlen, TEXT_TERRAIN_ROCKS); break; case TT_SWAMP: rmtxti->getWChar(w, maxlen, TEXT_TERRAIN_SWAMP); break; case TT_RIVER: rmtxti->getWChar(w, maxlen, TEXT_TERRAIN_RIVER); break; case TT_SEA: rmtxti->getWChar(w, maxlen, TEXT_TERRAIN_SEA); break; case TT_SHALLOW: rmtxti->getWChar(w, maxlen, TEXT_TERRAIN_SHALLOW); break; case TT_TOWN: rmtxti->getWChar(w, maxlen, TEXT_TERRAIN_TOWN); break; } } /*console*********************************************************************/ TMyConsoleWindow::TMyConsoleWindow(){ this->consoleOutput("Welcome to Developers Console!"); } void TMyConsoleWindow::consoleInput(char* str){ char str_copy[255]; static char last[255]; const int cmdmax = 30; TGame* g = (TGame*)(TGUI::gui_inst->game); strncpy(str_copy, str, 255); char *cmd = strtok(str," "); this->consoleOutput(str); if(!strnicmp(cmd, "volume", cmdmax)){ char *param = strtok(NULL," "); if(param){ int vol = atoi(param); float fv = float(vol)/MIX_MAX_VOLUME; if(TSoundInterface::si) TSoundInterface::si->setMusicVolume(fv); this->consoleOutput("setting volume: %f", fv); } else this->consoleOutput("use: volume /value/"); } else if(!strnicmp(cmd, "help", cmdmax)){ this->consoleOutput("help is not available!"); } else if(!strnicmp(cmd, "unittimeratio", cmdmax)){ char *param = strtok(NULL," "); if(param){ float tr = (float)atof(param); if(g->selected_unit){ g->selected_unit->setTimeRatio(tr); this->consoleOutput("setting unit timeratio: %f", tr); } else this->consoleOutput("unit not selected"); } else this->consoleOutput("use: unittimeratio /value/"); } else if(!strnicmp(cmd, "timeratio", cmdmax)){ char *param = strtok(NULL," "); if(param){ float tr = (float)atof(param); g->guiMap->getCM()->setTimeRatio(tr,1); this->consoleOutput("setting guimap timeratio: %f", tr); } else this->consoleOutput("use: unittimeratio /value/"); } else if(!strnicmp(cmd, "battle", cmdmax)){ g->b_kill = atoi(strtok(NULL," ")); g->b_loss = atoi(strtok(NULL," ")); g->b_dmgs = atoi(strtok(NULL," ")); g->b_ad = atoi(strtok(NULL," ")); g->b_dd = atoi(strtok(NULL," ")); g->b_bd = atoi(strtok(NULL," ")); g->b_dbg = 1; } else if(!strnicmp(cmd, "des2", cmdmax)){ P3F scpos; scpos.x = 2500; scpos.y = 2050; scpos.z = 180; TDestruction::installDestruction(&scpos, 10000, 200, KTime()); } else if(!strnicmp(cmd, "des", cmdmax)){ char *param1 = strtok(NULL," "); char *param2 = strtok(NULL," "); char *param3 = strtok(NULL," "); if(param1 && param2 && param3){ P3F scpos; scpos.x = (float)atof(param1); scpos.y = (float)atof(param2); scpos.z = (float)atof(param3); TDestruction::installDestruction(&scpos, 10000, 200, KTime()); } else this->consoleOutput("use: destruction /x/ /y/ /z/"); } else if(!strnicmp(cmd, "getpos", cmdmax)){ TCamera* cam = g->guiMap->getCam(); this->consoleOutput("maincam position %.1f %.1f %.1f", cam->p4fPos.x, cam->p4fPos.y, cam->p4fPos.z); this->consoleOutput("maincam direction %.1f %.1f %.1f", cam->p4fDir.x, cam->p4fDir.y, cam->p4fDir.z); } else if(!strnicmp(cmd, "last", cmdmax)){ consoleInput(last); return; } else if(!strnicmp(cmd, "kill", cmdmax)){ if(g->selected_building) g->selected_building->destroyBuilding(); } else if(!strnicmp(cmd, "fly", cmdmax)){ g->guiMap->freeFlight(); } else if(!strnicmp(cmd, "stopfly", cmdmax)){ g->guiMap->cancelFreeFlight(); } else if(!strnicmp(cmd, "winter", cmdmax)){ g->guiMap->wc->change(wsWinter); } else if(!strnicmp(cmd, "summer", cmdmax)){ g->guiMap->wc->change(wsSummer); } else if(!strnicmp(cmd, "autumn", cmdmax)){ g->guiMap->wc->change(wsAutumn); } else if(!strnicmp(cmd, "osd", cmdmax)){ char *param1 = strtok(NULL," "); g->osd->showMsg(param1); } else if(!strnicmp(cmd, "ctree", cmdmax)){ FILE* f=fopen("tree","w"); g->guiMap->getCM()->printSubtree(0,f); fclose(f); } else if(!strnicmp(cmd, "scriptdump", cmdmax)){ TSceneScript::report(); } else if(!strnicmp(cmd, "bye", cmdmax)){ exit(0); } else if(!strnicmp(cmd, "focus", cmdmax)){ P3F f; if(g->selected_unit){ g->selected_unit->hexWhereIam->getHexCenter(&f); g->guiMap->focus(f.x, f.y); } else if(g->selected_building){ g->selected_building->hexWhereIam->getHexCenter(&f); g->guiMap->focus(f.x, f.y); } } else if(!strnicmp(cmd, "set", cmdmax)){ char *param1 = strtok(NULL," "); char *param2 = strtok(NULL," "); float x = (float)atof(param1); float y = (float)atof(param2); // g->guiMap->focus(x, y); } else if(!strnicmp(cmd, "dump2d", cmdmax)){ g->guiMap->dump2DMap(); } else if(!strnicmp(cmd, "adump", cmdmax)){ if(g->selected_unit){ g->selected_unit->subselectedmember->umc->dumpActions(); } } else if(!strnicmp(cmd, "report", cmdmax)){ gui::TGUI::gui_inst->reportState(); } else if(!strnicmp(cmd, "sparkle", cmdmax)){ P3F f; if(g->selected_unit){ g->selected_unit->hexWhereIam->getHexCenter(&f); TSparkle::installSparkle(&f, 150, 50); } } else if(!strnicmp(cmd, "save", cmdmax)) { char * param = strtok(NULL, " "); if (param) { PACKET_SAVE_GAME msg; sprintf(msg.filename, "%s.xml", param); KSendGlobalMessage(MSG_SAVE_GAME, 0, MOD_WORLD_CLIENT, &msg); this->consoleOutput("game saved"); } else this->consoleOutput("use: save [filename]"); } else if(!strnicmp(cmd, "hearts", cmdmax)){ P3F f; if(g->selected_unit){ g->selected_unit->hexWhereIam->getHexCenter(&f); TSparkle::installHearts(&f, 150, 50); } } else if(!strnicmp(cmd, "mis", cmdmax)){ P3F a, b; g->guiMap->hexCentre(&a, 290); g->guiMap->hexCentre(&b, 306); a.z+=20; b.z+=20; TMagicMissileAttack::installMagicMissileAttack(&a, &b, KTime()); // TProjectileAttack::installSimpleProjectile(&a, &b, datMagicMissile, KTime()); // new TDistantAttack(&a, &b, datMagicMissile, KTime()); } else if(!strnicmp(cmd, "speed", cmdmax)){ char *param = strtok(NULL," "); if(param){ int spd = atoi(param); g->guiMap->getCM()->setSpeed( spd ); } } else if(!strnicmp(cmd, "recruit", cmdmax)){ char *param = strtok(NULL," "); if(param && g->selected_unit){ int c = atoi(param); g->selected_unit->recruit( c ); } } else if(!strnicmp(cmd, "heal", cmdmax)){ if(g->selected_unit){ g->selected_unit->heal(); } } else if(!strnicmp(cmd, "dumpq", cmdmax)){ TGUI::gui_inst->dumpGameMessages(); } else if(!strnicmp(cmd, "camsync", cmdmax)){ g->guiMap->syncDbgCam(); } else if(!strnicmp(cmd, "ktime", cmdmax)){ GLOG("ktime=%d\n", KTime()); } else if(!strnicmp(cmd, "find", cmdmax)){ TSceneObject* so; char *param1 = strtok(NULL," "); sscanf(param1,"%p",&so); g->guiMap->findSceneObject(so); } strncpy(last, str_copy, 255); } /*gamemenu********************************************************************/ #define GAME_MENU_BORDER 26 #define GAME_MENU_BUTTON_DELIMITER 4 #define GAME_MENU_BUTTON_HEIGHT 40 #define GAME_MENU_WIDTH 250 #define GAME_MENU_HEIGHT (3*GAME_MENU_BUTTON_DELIMITER+4*GAME_MENU_BUTTON_HEIGHT+2*GAME_MENU_BORDER) #define GAME_MENU_X ((SCREEN_WIDTH - GAME_MENU_WIDTH)/2) #define GAME_MENU_Y (GUIMAP_Y+(GUIMAP_HEIGHT - GAME_MENU_HEIGHT)/2) #define GAME_MENU_BUTTON_WIDTH (GAME_MENU_WIDTH - 2 * GAME_MENU_BORDER) TGameMenu::TGameMenu() : TWindow(AO_UNMOVABLE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) { wchar_t wtemp[LABEL_MAX_LENGTH]; active = AO_PASIVE; rm::TRM_txt_i *rmtxti = (rm::TRM_txt_i *)KSendGlobalMessage(MSG_GET_RM_TXT_I, MOD_GUI, MOD_RM, NULL); //dialog menu = new TWindow(AO_UNMOVABLE, GAME_MENU_X, GAME_MENU_Y, GAME_MENU_WIDTH, GAME_MENU_HEIGHT); menu->setBgImage(RASTER_PANEL); Add(menu); bsave = new TSoundedTextButton(AO_TOOLBAR, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_SAVE), GAME_MENU_BORDER, GAME_MENU_BORDER, GAME_MENU_BUTTON_WIDTH, GAME_MENU_BUTTON_HEIGHT, SAMPLE_CLICK); menu->Add(bsave); boptions = new TSoundedTextButton(AO_TOOLBAR, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_OPTIONS), GAME_MENU_BORDER, GAME_MENU_BUTTON_HEIGHT + GAME_MENU_BUTTON_DELIMITER + GAME_MENU_BORDER, GAME_MENU_BUTTON_WIDTH, GAME_MENU_BUTTON_HEIGHT, SAMPLE_CLICK); menu->Add(boptions); bresume = new TSoundedTextButton(AO_TOOLBAR, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_RESUME), GAME_MENU_BORDER, 2*(GAME_MENU_BUTTON_HEIGHT + GAME_MENU_BUTTON_DELIMITER) + GAME_MENU_BORDER, GAME_MENU_BUTTON_WIDTH, GAME_MENU_BUTTON_HEIGHT, SAMPLE_CLICK); menu->Add(bresume); bresume->setShortcutKey(SDLK_ESCAPE); bquit = new TSoundedTextButton(AO_TOOLBAR, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_QUIT), GAME_MENU_BORDER, 3*(GAME_MENU_BUTTON_HEIGHT + GAME_MENU_BUTTON_DELIMITER) + GAME_MENU_BORDER, GAME_MENU_BUTTON_WIDTH, GAME_MENU_BUTTON_HEIGHT, SAMPLE_CLICK); menu->Add(bquit); //dialog gamesetting = new TGameSetting(); Add(gamesetting); //dialog savegame = new TSaveGame(); Add(savegame); delete rmtxti; } void TGameMenu::show() { if( gui::TGUI::gui_inst->IMHost || ((TGame*)TGUI::gui_inst->game)->iLocalGame ) bsave->enabled = true; else bsave->enabled = false; menu->show(); TWindow::show(); } void TGameMenu::hide() { if (gamesetting) gamesetting->hide(); if (menu) menu->hide(); if (savegame) savegame->hide(); TWindow::hide(); } int TGameMenu::workInput(INPUT *input) { int ret = TWindow::workInput(input); // OBSLUHA MENU if (active == AO_ACTIVE) { if CLICKED(bsave) { menu->hide(); savegame->show(); } if CLICKED(boptions) { menu->hide(); gamesetting->show(); } if CLICKED(bresume) { hide(); } if ((gamesetting) && (CLICKED(gamesetting->bok) || CLICKED(gamesetting->bcancel)) ) { gamesetting->hide(); menu->show(); } if ((savegame) && (CLICKED(savegame->bback) || CLICKED(savegame->bsave)) ) { savegame->hide(); menu->show(); } if CLICKED(bquit) { //ukonceni podle typu hry PACKET_END_GAME_GUI egg; egg.player_id = ((TGame*)TGUI::gui_inst->game)->iGUIOwner; egg.type = MSG_END_GAME_GUI; if( ((TGame*)TGUI::gui_inst->game)->iLocalGame ) egg.final = true; else egg.final = false; TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &egg); if(result->status) GLOG("MSG_END_GAME_GUI: result->status!=0\n"); delete result; hide(); } // } return ret; } /*gamesetting*****************************************************************/ #define GAME_SET_WIDTH 370 #define GAME_SET_HEIGHT 200 #define GAME_SET_X ((SCREEN_WIDTH - GAME_SET_WIDTH)/2) #define GAME_SET_Y (GUIMAP_Y+(GUIMAP_HEIGHT - GAME_SET_HEIGHT)/2) #define GAME_SET_CAPTION_X 10 #define GAME_SET_LABEL_X 10 #define GAME_SET_OPT_Y 40 #define GAME_SET_OPT_HEIGHT 30 #define GAME_SET_SCROLL_X 170 #define GAME_SET_SCROLL_WIDTH 190 #define GAME_SET_SCROLL_HEIGHT 18 #define GAME_SET_BUTTON_WIDTH 100 #define GAME_SET_BUTTON_HEIGHT 35 #define GAME_SET_BUTTON_X ((GAME_SET_WIDTH - (10 + GAME_SET_BUTTON_WIDTH * 2))/2) #define GAME_SET_BUTTON_Y (GAME_SET_HEIGHT - (15 + GAME_SET_BUTTON_HEIGHT)) #define SPEED_RANGE 3 #define SOUND_RANGE SOUND_VOLUME_LEVELS #define MUSIC_RANGE MUSIC_VOLUME_LEVELS TGameSetting::TGameSetting() : TWindow(AO_UNMOVABLE, GAME_SET_X, GAME_SET_Y, GAME_SET_WIDTH, GAME_SET_HEIGHT) { wchar_t wtemp[LABEL_MAX_LENGTH]; active = AO_PASIVE; rm::TRM_txt_i *rmtxti = (rm::TRM_txt_i *)KSendGlobalMessage(MSG_GET_RM_TXT_I, MOD_GUI, MOD_RM, NULL); setBgImage(RASTER_PANEL); lsettingcaption = new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_OPTIONS), GAME_SET_CAPTION_X, 10); Add(lsettingcaption); //GAMEPLAY lspeedcaption = new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_SPEED), GAME_SET_LABEL_X, GAME_SET_OPT_Y); Add(lspeedcaption); sspeed = new TScrollBar(AO_HORIZONTAL, GAME_SET_SCROLL_X, GAME_SET_OPT_Y, GAME_SET_SCROLL_WIDTH, GAME_SET_SCROLL_HEIGHT); Add(sspeed); //autoscrool //showevents //SOUND musicvolumecaption = new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_MUSICVOLUME), GAME_SET_LABEL_X, GAME_SET_OPT_Y + GAME_SET_OPT_HEIGHT); Add(musicvolumecaption); smusicvolume = new TScrollBar(AO_HORIZONTAL, GAME_SET_SCROLL_X, GAME_SET_OPT_Y + GAME_SET_OPT_HEIGHT, GAME_SET_SCROLL_WIDTH, GAME_SET_SCROLL_HEIGHT); Add(smusicvolume); soundvolumecaption = new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_SOUNDVOLUME), GAME_SET_LABEL_X, GAME_SET_OPT_Y + GAME_SET_OPT_HEIGHT * 2); Add(soundvolumecaption); ssoundvolume = new TScrollBar(AO_HORIZONTAL, GAME_SET_SCROLL_X, GAME_SET_OPT_Y + GAME_SET_OPT_HEIGHT * 2, GAME_SET_SCROLL_WIDTH, GAME_SET_SCROLL_HEIGHT); Add(ssoundvolume); //BUTTONS bok = new TSoundedTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_OK), GAME_SET_BUTTON_X, GAME_SET_BUTTON_Y, GAME_SET_BUTTON_WIDTH, GAME_SET_BUTTON_HEIGHT, SAMPLE_CLICK); Add(bok); bok->setShortcutKey(SDLK_RETURN); bcancel = new TSoundedTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BACK), GAME_SET_BUTTON_X + 10 + GAME_SET_BUTTON_WIDTH, GAME_SET_BUTTON_Y, GAME_SET_BUTTON_WIDTH, GAME_SET_BUTTON_HEIGHT, SAMPLE_CLICK); Add(bcancel); bcancel->setShortcutKey(SDLK_ESCAPE); delete rmtxti; } int TGameSetting::workInput(INPUT *input) { int ret = TWindow::workInput(input); if (active == AO_PASIVE) return ret; // mozna urychlim, kdyz by to bylo pomale int newspeed = sspeed->pos(); float newmusic = smusicvolume->pos() / (float)(MUSIC_RANGE - 1); float newsound = ssoundvolume->pos() / (float)(SOUND_RANGE - 1); //rychlost TGame* g = (TGame*)(TGUI::gui_inst->game); g->guiMap->getCM()->setSpeed( newspeed+1 ); TGUI::gui_inst->profile->speed = newspeed+1; //zvuk if (TSoundInterface::si) { TSoundInterface::si->setMusicVolume(newmusic); TSoundInterface::si->setSoundVolume(newsound); } TGUI::gui_inst->profile->sfx_volume = ssoundvolume->pos(); TGUI::gui_inst->profile->music_volume = smusicvolume->pos(); if CLICKED(bok) { ok(); } if CLICKED(bcancel) { cancel(); } return ret; } void TGameSetting::show() { // zjisti puvodni hodnoty fspeed = ((TGame*)(TGUI::gui_inst->game))->guiMap->getCM()->getSpeed()-1; if (TSoundInterface::si) { fmusicvolume = TSoundInterface::si->getMusicVolume(); fsoundvolume = TSoundInterface::si->getSoundVolume(); } else { fsoundvolume = 0; fmusicvolume = 0; } // nastavim spravne scrolbary sspeed->ChangeTo(SPEED_RANGE, 1, ROUND(fspeed) ); smusicvolume->ChangeTo(MUSIC_RANGE, 1, ROUND((MUSIC_RANGE - 1) * fmusicvolume) ); ssoundvolume->ChangeTo(SOUND_RANGE, 1, ROUND((SOUND_RANGE - 1) * fsoundvolume) ); TWindow::show(); } void TGameSetting::cancel() { //restartovat rychlost TGame* g = (TGame*)(TGUI::gui_inst->game); g->guiMap->getCM()->setSpeed( ROUND(fspeed+1) ); TGUI::gui_inst->profile->speed = ROUND(fspeed+1); //restartovat zvuk if (TSoundInterface::si) { TSoundInterface::si->setMusicVolume(fmusicvolume); TSoundInterface::si->setSoundVolume(fsoundvolume); } TGUI::gui_inst->profile->sfx_volume = (int)fsoundvolume; TGUI::gui_inst->profile->music_volume = (int)fmusicvolume; } void TGameSetting::ok() { } /*savegame********************************************************************/ #define SAVE_WIDTH 320 #define SAVE_HEIGHT 330 #define SAVE_X ((SCREEN_WIDTH-SAVE_WIDTH)/2) #define SAVE_Y (GUIMAP_Y+(GUIMAP_HEIGHT - SAVE_HEIGHT)/2) #define SAVE_BORDER 10 #define SAVE_LIST_Y 30 #define SAVE_LIST_WIDTH 280 #define SAVE_LIST_HEIGHT 170 #define SAVE_LIST_X ((SAVE_WIDTH-SAVE_LIST_WIDTH)/2) #define SAVE_BUT_WIDTH 90 #define SAVE_BUT_HEIGHT 30 #define SAVE_BUT_X ((SAVE_WIDTH-3*SAVE_BUT_WIDTH-2*SAVE_BORDER)/2) #define SAVE_BUT_Y (SAVE_HEIGHT-SAVE_BUT_HEIGHT-SAVE_BORDER) #define SAVE_ITEM_BORDER 2 #define SAVE_ITEM_HEIGHT 20 #define LENGTH_OF_NAME_PART_DISPLAYED_IN_LIST (SAVE_LIST_WIDTH/8-1) #define SAVE_FILENAME_MAXLEN 40 TSaveGame::TSaveGame() : TWindow(AO_UNMOVABLE, SAVE_X, SAVE_Y, SAVE_WIDTH, SAVE_HEIGHT) { wchar_t wtemp[K8_MAX_FILE_NAME_LEN]; rmtxti = (rm::TRM_txt_i*)KSendGlobalMessage(MSG_GET_RM_TXT_I, MOD_GUI, MOD_RM, NULL); rmmapi = (rm::TRM_map_i*)KSendGlobalMessage(MSG_GET_RM_MAP_I, MOD_GUI, MOD_RM, NULL); active = AO_PASIVE; setBgImage(RASTER_PANEL); lsavedgames = new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_SAVEDGAMES), SAVE_LIST_X, SAVE_BORDER); Add(lsavedgames); listbar = new TListBar(AO_NORMAL, SAVE_LIST_X, SAVE_LIST_Y, SAVE_LIST_WIDTH, SAVE_LIST_HEIGHT); Add(listbar); bdelete = new TSoundedTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_DELETE), SAVE_LIST_X + SAVE_LIST_WIDTH - SAVE_BUT_WIDTH, SAVE_LIST_Y + SAVE_LIST_HEIGHT + 5, SAVE_BUT_WIDTH, SAVE_BUT_HEIGHT, SAMPLE_CLICK); Add(bdelete); lsaveas = new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_SAVEAS), SAVE_LIST_X, SAVE_LIST_Y + SAVE_LIST_HEIGHT + 5+30); Add(lsaveas); lfname = new TLineTextField(SAVE_LIST_X, SAVE_LIST_Y + SAVE_LIST_HEIGHT + 5+40+10, LENGTH_OF_NAME_PART_DISPLAYED_IN_LIST); Add(lfname); bsave = new TSoundedTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_SAVE), SAVE_LIST_X + SAVE_BORDER, SAVE_BUT_Y, SAVE_BUT_WIDTH, SAVE_BUT_HEIGHT, SAMPLE_CLICK); Add(bsave); bsave->setShortcutKey(SDLK_RETURN); bback = new TSoundedTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_BACK), SAVE_LIST_X + SAVE_LIST_WIDTH - SAVE_BUT_WIDTH - SAVE_BORDER, SAVE_BUT_Y, SAVE_BUT_WIDTH, SAVE_BUT_HEIGHT, SAMPLE_CLICK); Add(bback); bback->setShortcutKey(SDLK_ESCAPE); updateMapsList(); } TSaveGame::~TSaveGame() { delete rmtxti; delete rmmapi; } void TSaveGame::updateMapsList() { int i; TItem *item; TLabel *label; wchar_t wtemp[K8_MAX_FILE_NAME_LEN]; listbar->DelNFreeAll(); //naraj info o novych mapach DA* mapinfos = NULL; rmmapi->loadMapsInfo(MAP_TYPE_SAVE_GAME,0); rmmapi->getMapsInfo(&mapinfos, MAP_TYPE_SAVE_GAME); if (mapinfos) { //vypis mapy do okna for (i = (*mapinfos).getNext(-1); i != -1; i = (*mapinfos).getNext(i)) { item = new TItem(AO_NO, SAVE_ITEM_HEIGHT); listbar->Add(item); UTF8toWideChar((*mapinfos)[i]->file, wtemp, LENGTH_OF_NAME_PART_DISPLAYED_IN_LIST); label = new TLabel(wtemp, SAVE_ITEM_BORDER, SAVE_ITEM_BORDER); item->Add(label); } }//if } int TSaveGame::selectedMapID() { int sel = listbar->getSelection(), i; if (sel < 0) return -1; DA* mapinfos = NULL; rmmapi->getMapsInfo(&mapinfos, MAP_TYPE_SAVE_GAME); if (mapinfos) { for (i = (*mapinfos).getNext(-1); i != -1; i = (*mapinfos).getNext(i)) { if (sel == 0) return (*mapinfos)[i]->id; sel--; } } return -1; } int TSaveGame::workInput(INPUT *input) { if (active == AO_PASIVE) return 0; wchar_t wtemp[K8_MAX_FILE_NAME_LEN]; DA* mapinfos; int ret = TWindow::workInput(input); if CHANGED(lfname) listbar->deselectAll(); if CHANGED(listbar) { mapinfos = NULL; rmmapi->getMapsInfo(&mapinfos, MAP_TYPE_SAVE_GAME); if (mapinfos) { UTF8toWideChar((*mapinfos)[selectedMapID()]->file, wtemp, LENGTH_OF_NAME_PART_DISPLAYED_IN_LIST); lfname->setText(wtemp); } } if (CLICKED(bsave) && (wcslen(lfname->getText()) > 0)){ int i = -1; // zjistim, jestli mapa s takovym jmenem uz existuje rmmapi->getMapsInfo(&mapinfos, MAP_TYPE_SAVE_GAME); if (mapinfos) { for (i = (*mapinfos).getNext(-1); i != -1; i = (*mapinfos).getNext(i)) { UTF8toWideChar((*mapinfos)[i]->name, wtemp, LENGTH_OF_NAME_PART_DISPLAYED_IN_LIST); if (wcscpy(wtemp, lfname->getText()) == 0) break; } } //ukladam PACKET_SAVE_GAME msg; WideChartoUTF8(lfname->getText(), msg.filename, K8_MAX_FILE_NAME_LEN); //pripoji ".xml" pokud je potreba size_t len = strlen(msg.filename); if( len<4 || strnicmp(msg.filename + (len-4), ".xml", 4) ) strcat(msg.filename, ".xml"); //zprava TPacket_SyncResult * result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_SAVE_GAME, 0, MOD_WORLD_SERVER, &msg); if(result->status) GLOG("MSG_SAVE_GAME: result->status!=0\n"); delete result; } if CLICKED(bback) { } if CLICKED(bdelete) { int mi = selectedMapID(); if (mi >= 0) { /* Tady by se mela nejak smazat mapa s id = mi. Mozna bude stacit smazat soubor... */ lfname->setText(L""); updateMapsList(); } } return ret; } void TSaveGame::show() { // time_t tt = time(NULL); struct tm* st = gmtime(&tt); //vygeneruj nazev char temp[SAVE_FILENAME_MAXLEN]; snprintf(temp, SAVE_FILENAME_MAXLEN, "%02d%02d%02d_%02d%02d%02d_%s", st->tm_year>99?st->tm_year-100:st->tm_year, st->tm_mon+1, st->tm_mday, st->tm_hour, st->tm_min, st->tm_sec, TGUI::gui_inst->profile->name ); // wchar_t wtemp[SAVE_FILENAME_MAXLEN]; UTF8toWideChar(temp, wtemp, SAVE_FILENAME_MAXLEN); lfname->setText(wtemp); // updateMapsList(); // TWindow::show(); } /*diplomacywindow********************************************************************/ #define DIPL_BORDER 10 #define DIPL_BORDER2 6 #define DIPL_FRAME1_WIDTH 350 #define DIPL_FRAME2_WIDTH 350 #define DIPL_WIDTH 700 #define DIPL_HEIGHT 400 #define DIPL_X (STATUS_TBMENU_X + STATUS_TBMENU_WIDTH + 2) #define DIPL_Y 19 #define DIPL_SYMBOL_WIDTH 32 #define DIPL_SYMBOL_HEIGHT 32 #define DIPL_MAX_LEN 11 #define DIPL_REL_X 16 #define DIPL_REL_Y 16 #define DIPL_DIPL_REL_X 100 #define DIPL_DIPL_REL_Y 16 #define DIPL_CONTROL_HEIGHT 60 #define DIPL_BUT_WIDTH 100 #define DIPL_BUT_HEIGHT 35 #define DIPL_CAPTION_COL 1.0f, 1.0f, 1.0f TDiplomacyWindow::TDiplomacyWindow() : TWindow(AO_UNMOVABLE, DIPL_X, DIPL_Y, DIPL_WIDTH, DIPL_HEIGHT) { active = AO_PASIVE; wchar_t wtemp[LABEL_MAX_LENGTH]; rmtxti = (rm::TRM_txt_i *)KSendGlobalMessage(MSG_GET_RM_TXT_I, MOD_GUI, MOD_RM, NULL); setBgImage(RASTER_PANEL); relations_frame = new TGroupBar(AO_NORMAL, DIPL_BORDER, DIPL_BORDER, DIPL_FRAME1_WIDTH, DIPL_HEIGHT); Add(relations_frame); diplomat_frame = new TGroupBar(AO_NORMAL, DIPL_BORDER*2+DIPL_FRAME1_WIDTH, DIPL_BORDER, DIPL_FRAME2_WIDTH, DIPL_HEIGHT); Add(diplomat_frame); tbclose = new TTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_CLOSE) , 0, 0, DIPL_BUT_WIDTH, DIPL_BUT_HEIGHT); Add(tbclose); tbclose->setShortcutKey(SDLK_ESCAPE); playerscnt = 0; for(int i = 0; i < 8; i++) lastRelationOffer[i]=-1; relcount = 0; } TDiplomacyWindow::~TDiplomacyWindow() { delete rmtxti; } int TDiplomacyWindow::workInput(INPUT *input) { wchar_t wtemp[LABEL_MAX_LENGTH]; int ret = TWindow::workInput(input); //zmena vztahu for (int i = 0; i < playerscnt - 1; i++) { if( relation[i] && CLICKED(relation[i]) ) { //cykli vztahy int newrel = (relation[i]->tag+1)%4; //prepni button if( diplomat_frame->Del(relation[i]) ) delete relation[i]; int y = DIPL_DIPL_REL_Y + 3*DIPL_SYMBOL_HEIGHT + 8 + 8; int x = DIPL_DIPL_REL_X + DIPL_SYMBOL_WIDTH * i; rm::TSymbolData* ss = relIcon( (ai_ns::diplomacy_ns::TRelationship)newrel ); relation[i] = new TIconButton(AO_TOOLBAR, ss, x, y, DIPL_SYMBOL_WIDTH, DIPL_SYMBOL_HEIGHT); relation[i]->tag = newrel; relation[i]->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, relText((ai_ns::diplomacy_ns::TRelationship)newrel) )); diplomat_frame->Add(relation[i]); } } //zavrit a poslat zpravu if CLICKED(tbclose){ World::TPlayerContainer *players; ((TGame*)TGUI::gui_inst->game)->getWorldPlayers(&players); int pos = 0; World::TPlayerContainer::iterator it; int player = ((TGame*)TGUI::gui_inst->game)->iGUIOwner; //projdi hrace for(it = players->begin(); it != players->end(); it++) { int id = (*it).first; PLAYER* pl = &((*it).second->data()); //preskoc sebe a zabite hrace if(id != player && relation[pos] ){ //preskoc nabidky, kde se nic nezmenilo if( lastRelationOffer[id] != relation[pos]->tag ) { //odesli zpravu o zmene vztahu PACKET_ACT_OFFER_RELATION msg; msg.type = MSG_ACT_OFFER_RELATION; msg.player_id = ((TGame*)TGUI::gui_inst->game)->iGUIOwner; msg.source_diplomat_world_id = ((TGame*)TGUI::gui_inst->game)->iGUIOwner; msg.target_diplomat_world_id = id; msg.offered_relationship = (ai_ns::diplomacy_ns::TRelationship)relation[pos]->tag; TPacket_SyncResult* result; result = (TPacket_SyncResult *)KSendGlobalMessage(MSG_WORLD_GUI, 0, MOD_WORLD_CLIENT, &msg); if(result->status){ GLOG("MSG_ACT_OFFER_RELATION: result->status!=0\n"); } else{ // lastRelationOffer[id] = relation[pos]->tag; // GLOG("Relationship change: player %d ndplayer %d relation %d\n", ((TGame*)TGUI::gui_inst->game)->iGUIOwner, id, relation[pos]->tag); } delete result; }//if no change.. pos++; }//if not me.. }//for hide(); } return ret; } rm::TSymbolData* TDiplomacyWindow::relIcon(ai_ns::diplomacy_ns::TRelationship rs) { switch( rs ) { case ai_ns::diplomacy_ns::RELATIONSHIP_WAR: return TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 31); break; case ai_ns::diplomacy_ns::RELATIONSHIP_ENEMY: return TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 30); break; case ai_ns::diplomacy_ns::RELATIONSHIP_TRUCE: return TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 29); break; case ai_ns::diplomacy_ns::RELATIONSHIP_ALLY: return TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 28); break; } return NULL; } int TDiplomacyWindow::relText(ai_ns::diplomacy_ns::TRelationship rs) { switch( rs ) { case ai_ns::diplomacy_ns::RELATIONSHIP_WAR: return TEXT_RELWAR; case ai_ns::diplomacy_ns::RELATIONSHIP_ENEMY: return TEXT_RELENEMY; case ai_ns::diplomacy_ns::RELATIONSHIP_TRUCE: return TEXT_RELTRUCE; case ai_ns::diplomacy_ns::RELATIONSHIP_ALLY: return TEXT_RELALLY; } return 0; } void TDiplomacyWindow::show() { TLabel *label; TIcon *icon; wchar_t wtemp[LABEL_MAX_LENGTH]; World::TPlayerContainer *players; int x, y; //current player int player = ((TGame*)TGUI::gui_inst->game)->iGUIOwner; //hraci ((TGame*)TGUI::gui_inst->game)->getWorldPlayers(&players); //spocita hrace playerscnt = (int)players->size(); //RELATION FRAME relations_frame->DelNFreeAll(); relations_frame->Add( new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_RELATIONS), 1, 1, DIPL_CAPTION_COL) ); // jmena hracu int pos = 0; World::TPlayerContainer::iterator it; World::TPlayerContainer::iterator it2; for(it = players->begin(); it != players->end(); it++) { int id = (*it).first; PLAYER* pl = &((*it).second->data()); // vertikalni jmeno if (pos < playerscnt) { x = DIPL_REL_X + playerscnt * DIPL_SYMBOL_WIDTH + 8; y = DIPL_REL_Y + DIPL_SYMBOL_HEIGHT + (DIPL_SYMBOL_HEIGHT-8)/2 + pos * DIPL_SYMBOL_HEIGHT; // label = new TLabel(L"", x, y); UTF8toWideChar(pl->game_data.name, label->text, DIPL_MAX_LEN); label->setColor( ColorPlayer[id][0]/255.f, ColorPlayer[id][1]/255.f, ColorPlayer[id][2]/255.f,1); relations_frame->Add(label); } // horizontalni zahlavi - korunka/lebcicka if (pos < playerscnt) { x = DIPL_REL_X + pos * DIPL_SYMBOL_WIDTH; y = DIPL_REL_Y; //zahlavi rm::TSymbolData* ss = NULL; if(pl->game_data.state == PS_ACTIVE) ss = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 36); else ss = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 60); TIcon* ic = new TIcon(ss, x, y); ic->setColor( ColorPlayer[id][0]/255.f, ColorPlayer[id][1]/255.f, ColorPlayer[id][2]/255.f); relations_frame->Add( ic ); } pos++; } // vztahy relcount = (playerscnt * playerscnt); int i=0; for(it = players->begin(); it != players->end(); it++) { int j=-1; for(it2 = players->begin(); it2 != players->end(); it2++) { j++; if( (*it).first == (*it2).first )continue; x = DIPL_REL_X + DIPL_SYMBOL_WIDTH * j; y = DIPL_REL_Y + DIPL_SYMBOL_HEIGHT + DIPL_SYMBOL_HEIGHT * i; // ai_ns::diplomacy_ns::TRelationship rs = (*it).second->data().game_data.relations[(*it2).first]->rs; // rm::TSymbolData* ss = relIcon( rs ); if(ss) { TIcon* rel = new TIcon(ss, x, y); relations_frame->Add(rel); rel->setHelp( rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, relText(rs)) ); } } i++; } //DIPLOMAT FRAME diplomat_frame->DelNFreeAll(); diplomat_frame->Add( new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_DIPLOMAT), 1, 1, DIPL_CAPTION_COL) ); y = DIPL_DIPL_REL_Y; x = 10; y += DIPL_SYMBOL_HEIGHT + (DIPL_SYMBOL_HEIGHT-8)/2; diplomat_frame->Add( new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_ACTUAL), x, y ) ); y += 8 + DIPL_SYMBOL_HEIGHT; diplomat_frame->Add( new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_OFFERED), x, y ) ); y += 8 + DIPL_SYMBOL_HEIGHT; diplomat_frame->Add( new TLabel(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_POSSIBILITY), x, y ) ); //aktualni a nabizeny vztah pos = 0; for(it = players->begin(); it != players->end(); it++) { int id = (*it).first; PLAYER* pl = &((*it).second->data()); if( id != player) { y = DIPL_DIPL_REL_Y; x = DIPL_DIPL_REL_X + DIPL_SYMBOL_WIDTH * pos; rm::TSymbolData* ss; //zahlavi if(pl->game_data.state == PS_ACTIVE) ss = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 36); else ss = TaoKernel::getSymbol(SYMBOLS_BASIC_ICONS, 60); TIcon* ic = new TIcon(ss, x, y); ic->setColor( ColorPlayer[id][0]/255.f, ColorPlayer[id][1]/255.f, ColorPlayer[id][2]/255.f); diplomat_frame->Add( ic ); y += DIPL_SYMBOL_HEIGHT; //mrtvyho hrace preskocit if(pl->game_data.state == PS_DEFEATED){ relation[pos] = NULL; pos++; continue; } //aktualni ss = relIcon( (*players)[player]->data().game_data.relations[id]->rs ); icon = new TIcon(ss, x, y); diplomat_frame->Add( icon ); icon->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_RELWAR + (*players)[player]->data().game_data.relations[id]->rs) ); //nabizeny y += DIPL_SYMBOL_HEIGHT + 8; ss = relIcon( (*players)[id]->data().game_data.relations[player]->offeredrs ); icon = new TIcon(ss, x, y); diplomat_frame->Add( icon ); icon->setHelp(rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, relText((*players)[id]->data().game_data.relations[player]->offeredrs) )); //volby y += DIPL_SYMBOL_HEIGHT + 8; int rel = (*players)[player]->data().game_data.relations[id]->offeredrs; lastRelationOffer[id] = rel; // ss = relIcon( (ai_ns::diplomacy_ns::TRelationship)rel ); relation[pos] = new TIconButton(AO_TOOLBAR, ss, x, y, DIPL_SYMBOL_WIDTH, DIPL_SYMBOL_HEIGHT); relation[pos]->setHelp( rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, relText((ai_ns::diplomacy_ns::TRelationship)rel)) ); relation[pos]->tag = rel; diplomat_frame->Add( relation[pos] ); pos++; } } //RESIZE int h1 = DIPL_REL_Y + DIPL_SYMBOL_HEIGHT + DIPL_SYMBOL_HEIGHT * playerscnt + 8; int h2 = DIPL_DIPL_REL_Y + 4*DIPL_SYMBOL_HEIGHT + 8 + 8 + 8; relations_frame->width = DIPL_REL_X + playerscnt * DIPL_SYMBOL_WIDTH + 8 + DIPL_MAX_LEN*8 +8; relations_frame->height = MAX(h1, h2); diplomat_frame->width = DIPL_DIPL_REL_X + DIPL_SYMBOL_WIDTH * (playerscnt-1) + 8; diplomat_frame->height = MAX(h1, h2); diplomat_frame->x = relations_frame->width + 2*DIPL_BORDER; this->width = 3*DIPL_BORDER + relations_frame->width + diplomat_frame->width; this->height = MAX(h1, h2) + 2*DIPL_BORDER+DIPL_BORDER+DIPL_BUT_HEIGHT; // tbclose->move( (this->width-DIPL_BUT_WIDTH)/2, this->height-DIPL_BORDER-DIPL_BUT_HEIGHT ); // this->x = ((SCREEN_WIDTH - width)/2); this->y = (GUIMAP_Y+(GUIMAP_HEIGHT - height)/2); // TWindow::show(); } /*eventswindow***********************************************************************/ #define EVENTSWINDOW_WIDTH 500 #define EVENTSWINDOW_HEIGHT 350 #define EVENTSWINDOW_X ((SCREEN_WIDTH-EVENTSWINDOW_WIDTH)/2) #define EVENTSWINDOW_Y ((SCREEN_HEIGHT-EVENTSWINDOW_HEIGHT)/2) #define EVENTSWINDOW_BORDER 10 #define EVENTSWINDOW_BUTTON_WIDTH 80 #define EVENTSWINDOW_BUTTON_HEIGHT 40 #define EVENTSWINDOW_FILTERBUTTON_WIDTH 120 #define EVENTSWINDOW_BUTTONS_HEIGHT (EVENTSWINDOW_BUTTON_HEIGHT+EVENTSWINDOW_BORDER) #define EVENTSWINDOW_FONT_HEIGHT 16 #define EVENTSWINDOW_EVENTITEM_BORDER 5 #define EVENTSWINDOW_EVENTITEM_HEIGHT (EVENTSWINDOW_EVENTITEM_BORDER+EVENTSWINDOW_FONT_HEIGHT+EVENTSWINDOW_EVENTITEM_BORDER) #define EVENTSWINDOW_INFOCOLOR 1,1,1 #define EVENTSWINDOW_WARNCOLOR 1,0,0 #define EVENTSWINDOW_COMMENTCOLOR 0,1,0 TEventsWindow::TEventsWindow() : TWindow(AO_UNMOVABLE, EVENTSWINDOW_X, EVENTSWINDOW_Y, EVENTSWINDOW_WIDTH, EVENTSWINDOW_HEIGHT) { active = AO_PASIVE; rm::TRM_txt_i *rmtxti = (rm::TRM_txt_i *)KSendGlobalMessage(MSG_GET_RM_TXT_I, MOD_GUI, MOD_RM, NULL); wchar_t wtemp[LABEL_MAX_LENGTH]; setBgImage(RASTER_PANEL); lbenventslist = new TListBar(AO_NORMAL, EVENTSWINDOW_BORDER, EVENTSWINDOW_BORDER, EVENTSWINDOW_WIDTH-2*EVENTSWINDOW_BORDER, EVENTSWINDOW_HEIGHT-EVENTSWINDOW_BUTTONS_HEIGHT-2*EVENTSWINDOW_BORDER); Add(lbenventslist); tbClose = new TTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_CLOSE), EVENTSWINDOW_WIDTH - (EVENTSWINDOW_BUTTON_WIDTH+EVENTSWINDOW_BORDER), EVENTSWINDOW_HEIGHT - EVENTSWINDOW_BUTTONS_HEIGHT, EVENTSWINDOW_BUTTON_WIDTH, EVENTSWINDOW_BUTTON_HEIGHT); Add(tbClose); tbClose->setShortcutKey(SDLK_RETURN, L"Return"); tbCenter = new TTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_CENTER), EVENTSWINDOW_WIDTH - 2*(EVENTSWINDOW_BUTTON_WIDTH+EVENTSWINDOW_BORDER), EVENTSWINDOW_HEIGHT - EVENTSWINDOW_BUTTONS_HEIGHT, EVENTSWINDOW_BUTTON_WIDTH, EVENTSWINDOW_BUTTON_HEIGHT); Add(tbCenter); tbCenter->hide(); //filtracni tlacitka tbWarningsFilter = new TTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_WARNINGS), EVENTSWINDOW_BORDER, EVENTSWINDOW_HEIGHT - EVENTSWINDOW_BUTTONS_HEIGHT, EVENTSWINDOW_FILTERBUTTON_WIDTH, EVENTSWINDOW_BUTTON_HEIGHT); Add(tbWarningsFilter); tbInfosFilter = new TTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_INFOS), EVENTSWINDOW_BORDER + (EVENTSWINDOW_FILTERBUTTON_WIDTH+EVENTSWINDOW_BORDER), EVENTSWINDOW_HEIGHT - EVENTSWINDOW_BUTTONS_HEIGHT, EVENTSWINDOW_FILTERBUTTON_WIDTH, EVENTSWINDOW_BUTTON_HEIGHT); Add(tbInfosFilter); tbCommentsFilter = new TTextButton(AO_NORMAL, rmtxti->getWChar(wtemp, LABEL_MAX_LENGTH, TEXT_COMMENTS), EVENTSWINDOW_BORDER + 2*(EVENTSWINDOW_FILTERBUTTON_WIDTH+EVENTSWINDOW_BORDER), EVENTSWINDOW_HEIGHT - EVENTSWINDOW_BUTTONS_HEIGHT, EVENTSWINDOW_FILTERBUTTON_WIDTH, EVENTSWINDOW_BUTTON_HEIGHT); Add(tbCommentsFilter); // iShowWarnings = 1; iShowInfos = 1; iShowComments = 1; delete rmtxti; } int TEventsWindow::workInput(INPUT *input){ int ret = TWindow::workInput(input); if CLICKED(tbClose){ hide(); } if CLICKED(lbenventslist) { tbCenter->hide(); TActiveObject* ao = lbenventslist->getSelectedObject(); if(ao){ TEventInfo* ei = *((TEventInfo**)&(ao->tag)); if(ei->location>0)tbCenter->show(); } } if CLICKED(tbCenter){ TActiveObject* ao = lbenventslist->getSelectedObject(); if(ao){ TEventInfo* ei = *((TEventInfo**)&(ao->tag)); if(ei->location>0){ //zacentruj GLOG("focusing: %d\n", ei->location); ((TGame*)TGUI::gui_inst->game)->focusHex(ei->location); } }//if ao } if CLICKED(tbWarningsFilter){ iShowWarnings = !iShowWarnings; updateContent(); } if CLICKED(tbInfosFilter){ iShowInfos = !iShowInfos; updateContent(); } if CLICKED(tbCommentsFilter){ iShowComments = !iShowComments; updateContent(); } return ret; } void TEventsWindow::updateContent(){ //smaz seznam lbenventslist->DelNFreeAll(); // for(std::vector::iterator it = events.begin(); it != events.end(); it++) { // if( (iShowComments && (*it)->type == eitComment)|| (iShowInfos && ((*it)->type == eitInfo || (*it)->type == eitUnitInterrupted || (*it)->type == eitUnitDeserted))|| (iShowWarnings && ((*it)->type == eitWarning || (*it)->type == eitUnitDied || (*it)->type == eitUnitMembersDied)) ) addLine(*it); } //schovej button tbCenter->hide(); } void TEventsWindow::addLine(TEventInfo* ei){ // TMultiLabel* label = new TMultiLabel( 0, EVENTSWINDOW_EVENTITEM_BORDER, EVENTSWINDOW_EVENTITEM_BORDER, EVENTSWINDOW_WIDTH-2*EVENTSWINDOW_BORDER-lbenventslist->scroll->width, 20); label->setText( ei->msg, 1); //obarvi podle typu switch(ei->type){ case eitUnitMembersDied: case eitUnitDied: case eitWarning: label->setColor(EVENTSWINDOW_WARNCOLOR,1); break; case eitUnitDeserted: case eitUnitInterrupted: case eitInfo: label->setColor(EVENTSWINDOW_INFOCOLOR,1); break; case eitComment: label->setColor(EVENTSWINDOW_COMMENTCOLOR,1); break; } //umisti do seznamu TItem *item = new TItem(AO_NO, EVENTSWINDOW_EVENTITEM_HEIGHT); item->tag = *((int*)&ei); item->Add(label); // lbenventslist->Add(item); } void TEventsWindow::clearList(){ //smaz seznam lbenventslist->DelNFreeAll(); //smaz data events.clear(); } void TEventsWindow::addEvent(TEventInfo* ei){ // events.push_back(ei); // if( (iShowComments && ei->type == eitComment)|| (iShowInfos && (ei->type == eitInfo || ei->type == eitUnitDeserted || ei->type == eitUnitInterrupted))|| (iShowWarnings && (ei->type == eitWarning || ei->type == eitUnitMembersDied || ei->type == eitUnitDied)) ) addLine(ei); } }//namespace