From 2fe8b07f4f4f2dad80f2ad3fad8ff9c789da4547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 23 Dec 2010 00:33:48 +0000 Subject: [PATCH] Little more development for duel mode. --- AI/StupidAI/StupidAI.vcxproj | 38 ++++++++++++++++++++++++++++++++++-- client/CPlayerInterface.cpp | 11 +++++++++-- client/CPlayerInterface.h | 2 ++ client/Client.cpp | 37 ++++++++++++++++++++++++++++++++--- client/Client.h | 1 + client/NetPacksClient.cpp | 32 +++++------------------------- lib/CGameState.cpp | 23 ++++++++++++++++++++++ lib/CGameState.h | 1 + lib/NetPacksLib.cpp | 18 +---------------- 9 files changed, 112 insertions(+), 51 deletions(-) diff --git a/AI/StupidAI/StupidAI.vcxproj b/AI/StupidAI/StupidAI.vcxproj index eca22a321..30c6e2b4c 100644 --- a/AI/StupidAI/StupidAI.vcxproj +++ b/AI/StupidAI/StupidAI.vcxproj @@ -5,6 +5,10 @@ Debug Win32 + + RD + Win32 + Release Win32 @@ -26,6 +30,12 @@ true MultiByte + + DynamicLibrary + false + true + MultiByte + @@ -35,6 +45,9 @@ + + + @@ -48,7 +61,8 @@ true VCMI_lib.lib;%(AdditionalDependencies) - ../../libs; ../;E:\vcmi\rep - assembla\trunk;E:\C++\lua bin;E:\C++\boost_1_43_0\lib;E:\C++\SDL_mixer-1.2.7\lib;E:\C++\SDL_ttf-2.0.8\lib;E:\C++\zlib 1.2.3 binaries\lib;E:\C++\SDL-1.2.11\devlibs - visual\SDL-1.2.11\lib;E:\C++\SDL_Image 1.2.5\SDL_image-1.2.5\lib;%(AdditionalLibraryDirectories) + ../../../libs; ../../;E:\vcmi\rep - assembla\trunk;E:\C++\lua bin;E:\C++\boost_1_43_0\lib;E:\C++\SDL_mixer-1.2.7\lib;E:\C++\SDL_ttf-2.0.8\lib;E:\C++\zlib 1.2.3 binaries\lib;E:\C++\SDL-1.2.11\devlibs - visual\SDL-1.2.11\lib;E:\C++\SDL_Image 1.2.5\SDL_image-1.2.5\lib;%(AdditionalLibraryDirectories) + $(OutDir)StupidAI.dll @@ -66,7 +80,26 @@ true true VCMI_lib.lib;%(AdditionalDependencies) - E:\vcmi\rep - assembla\trunk;E:\C++\lua bin;E:\C++\boost_1_43_0\lib;E:\C++\SDL_mixer-1.2.7\lib;E:\C++\SDL_ttf-2.0.8\lib;E:\C++\zlib 1.2.3 binaries\lib;E:\C++\SDL-1.2.11\devlibs - visual\SDL-1.2.11\lib;E:\C++\SDL_Image 1.2.5\SDL_image-1.2.5\lib;%(AdditionalLibraryDirectories) + ../../../libs; ../../;E:\vcmi\rep - assembla\trunk;E:\C++\lua bin;E:\C++\boost_1_43_0\lib;E:\C++\SDL_mixer-1.2.7\lib;E:\C++\SDL_ttf-2.0.8\lib;E:\C++\zlib 1.2.3 binaries\lib;E:\C++\SDL-1.2.11\devlibs - visual\SDL-1.2.11\lib;E:\C++\SDL_Image 1.2.5\SDL_image-1.2.5\lib;%(AdditionalLibraryDirectories) + + + + + Level3 + MaxSpeed + true + true + E:\C++\Lua_includes;E:\vcmi\rep - assembla\trunk\lua src;E:\C++\boost_1_43_0;E:\C++\SDL_mixer-1.2.7\include;E:\C++\SDL_ttf-2.0.8\include;E:\C++\zlib 1.2.3 binaries\include;E:\C++\SDL-1.2.11\devlibs - visual\SDL-1.2.11\include;E:\C++\SDL_Image 1.2.5\SDL_image-1.2.5\include;%(AdditionalIncludeDirectories)options> + Use + stdafx.h + + + true + true + true + VCMI_lib.lib;%(AdditionalDependencies) + ../../../libs; ../../;E:\vcmi\rep - assembla\trunk;E:\C++\lua bin;E:\C++\boost_1_43_0\lib;E:\C++\SDL_mixer-1.2.7\lib;E:\C++\SDL_ttf-2.0.8\lib;E:\C++\zlib 1.2.3 binaries\lib;E:\C++\SDL-1.2.11\devlibs - visual\SDL-1.2.11\lib;E:\C++\SDL_Image 1.2.5\SDL_image-1.2.5\lib;%(AdditionalLibraryDirectories) + $(OutDir)StupidAI.dll @@ -74,6 +107,7 @@ Create Create + Create diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 2337dc831..e87fa2b47 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -95,6 +95,7 @@ struct OCM_HLP_CGIN CPlayerInterface::CPlayerInterface(int Player) { + observerInDuelMode = false; howManyPeople++; GH.defActionsDef = 0; LOCPLINT = this; @@ -140,6 +141,12 @@ CPlayerInterface::~CPlayerInterface() void CPlayerInterface::init(ICallback * CB) { cb = dynamic_cast(CB); + if(observerInDuelMode) + { + + return; + } + if(!adventureInt) adventureInt = new CAdvMapInt(); @@ -1318,13 +1325,13 @@ void CPlayerInterface::update() } //in some conditions we may receive calls before selection is initialized - we must ignore them - if(!adventureInt->selection && GH.topInt() == adventureInt) + if(adventureInt && !adventureInt->selection && GH.topInt() == adventureInt) return; GH.updateTime(); GH.handleEvents(); - if(!adventureInt->isActive() && adventureInt->scrollingDir) //player forces map scrolling though interface is disabled + if(adventureInt && !adventureInt->isActive() && adventureInt->scrollingDir) //player forces map scrolling though interface is disabled GH.totalRedraw(); else GH.simpleRedraw(); diff --git a/client/CPlayerInterface.h b/client/CPlayerInterface.h index 51982083d..939e5d30e 100644 --- a/client/CPlayerInterface.h +++ b/client/CPlayerInterface.h @@ -112,6 +112,8 @@ extern SystemOptions GDefaultOptions; //defined and inited in CMT.cpp, stores de class CPlayerInterface : public CGameInterface, public IUpdateable { public: + bool observerInDuelMode; + //minor interfaces CondSh *showingDialog; //indicates if dialog box is displayed diff --git a/client/Client.cpp b/client/Client.cpp index c7386658d..3b9053e43 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -33,6 +33,7 @@ #define NOT_LIB #include "../lib/RegisterTypes.cpp" +#include "CBattleInterface.h" extern std::string NAME; namespace intpr = boost::interprocess; @@ -369,7 +370,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) gs->init(si, sum, seed); tlog0 <<"Initializing GameState (together): "<map) + if(gs->map) { const_cast(CGI)->mh = new CMapHandler(); CGI->mh->map = gs->map; @@ -412,8 +413,14 @@ void CClient::newGame( CConnection *con, StartInfo *si ) } } - playerint[254] = new CPlayerInterface(-1); - playerint[254]->init(new CCallback(gs, -1, this)); + if(si->mode == StartInfo::DUEL) + { + CPlayerInterface *p = new CPlayerInterface(-1); + p->observerInDuelMode = true; + playerint[254] = p; + p->init(new CCallback(gs, -1, this)); + battleStarted(gs->curB); + } serv->addStdVecItems(const_cast(CGI)->state); hotSeat = (humanPlayers > 1); @@ -530,6 +537,30 @@ void CClient::stopConnection() } } +void CClient::battleStarted(const BattleInfo * info) +{ + CPlayerInterface * att, * def; + if(vstd::contains(playerint, info->side1) && playerint[info->side1]->human) + att = static_cast( playerint[info->side1] ); + else + att = NULL; + + if(vstd::contains(playerint, info->side2) && playerint[info->side2]->human) + def = static_cast( playerint[info->side2] ); + else + def = NULL; + + + new CBattleInterface(info->belligerents[0], info->belligerents[1], info->heroes[0], info->heroes[1], Rect((conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2, 800, 600), att, def); + + if(vstd::contains(playerint,info->side1)) + playerint[info->side1]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 0); + if(vstd::contains(playerint,info->side2)) + playerint[info->side2]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 1); + if(vstd::contains(playerint,254)) + playerint[254]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 1); +} + template void CClient::serialize( CISer &h, const int version ); template void CClient::serialize( COSer &h, const int version ); diff --git a/client/Client.h b/client/Client.h index 09d0faaef..333297172 100644 --- a/client/Client.h +++ b/client/Client.h @@ -148,6 +148,7 @@ public: void handlePack( CPack * pack ); //applies the given pack and deletes it void updatePaths(); + void battleStarted(const BattleInfo * info); ////////////////////////////////////////////////////////////////////////// diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index d28abcc18..42cdf7e54 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -481,41 +481,19 @@ void GarrisonDialog::applyCl(CClient *cl) void BattleStart::applyCl( CClient *cl ) { - CPlayerInterface * att, * def; - if(vstd::contains(cl->playerint, info->side1) && cl->playerint[info->side1]->human) - att = static_cast( cl->playerint[info->side1] ); - else - att = NULL; - - if(vstd::contains(cl->playerint, info->side2) && cl->playerint[info->side2]->human) - def = static_cast( cl->playerint[info->side2] ); - else - def = NULL; - - - new CBattleInterface(info->belligerents[0], info->belligerents[1], info->heroes[0], info->heroes[1], genRect(600, 800, (conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2), att, def); - - if(vstd::contains(cl->playerint,info->side1)) - cl->playerint[info->side1]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 0); - - if(vstd::contains(cl->playerint,info->side2)) - cl->playerint[info->side2]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 1); + cl->battleStarted(info); } void BattleNextRound::applyFirstCl(CClient *cl) { - if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end()) - cl->playerint[GS(cl)->curB->side1]->battleNewRoundFirst(round); - if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end()) - cl->playerint[GS(cl)->curB->side2]->battleNewRoundFirst(round); + INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleNewRoundFirst,round); + INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleNewRoundFirst,round); } void BattleNextRound::applyCl( CClient *cl ) { - if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end()) - cl->playerint[GS(cl)->curB->side1]->battleNewRound(round); - if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end()) - cl->playerint[GS(cl)->curB->side2]->battleNewRound(round); + INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleNewRound,round); + INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleNewRound,round); } void BattleSetActiveStack::applyCl( CClient *cl ) diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 29929c578..fb8a75d97 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1947,6 +1947,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) armies[1] = c; curB = ::setupBattle(tile, terrain, terType, armies, heroes, false, town); + curB->localInit(); return; } break; @@ -4795,6 +4796,28 @@ si8 BattleInfo::getDistance( int hex1, int hex2 ) return std::max(xDst, yDst) + std::min(xDst, yDst) - (yDst + 1)/2; } +void BattleInfo::localInit() +{ + belligerents[0]->battle = belligerents[1]->battle = this; + //TODO: attach battle to belligerents + + BOOST_FOREACH(CStack *s, stacks) + { + if(s->base) //stack originating from "real" stack in garrison -> attach to it + { + s->attachTo(const_cast(s->base)); + } + else //attach directly to obj to which stack belongs and creature type + { + CArmedInstance *army = belligerents[!s->attackerOwned]; + s->attachTo(army); + assert(s->type); + s->attachTo(const_cast(s->type)); + } + s->postInit(); + } +} + int3 CPath::startPos() const { return nodes[nodes.size()-1].coord; diff --git a/lib/CGameState.h b/lib/CGameState.h index 17f77f136..5d7e27631 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -259,6 +259,7 @@ struct DLL_EXPORT BattleInfo : public CBonusSystemNode si8 sameSideOfWall(int pos1, int pos2); //determines if given positions are on the same side of wall si8 hasWallPenalty(int stackID, int destHex); //determines if given stack has wall penalty shooting given pos si8 canTeleportTo(int stackID, int destHex, int telportLevel); //determines if given stack can teleport to given place + void localInit(); }; class DLL_EXPORT CStack : public CBonusSystemNode, public CStackBasicDescriptor diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 8ba5b7c0d..fb2cff9c2 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -825,23 +825,7 @@ DLL_EXPORT void HeroLevelUp::applyGs( CGameState *gs ) DLL_EXPORT void BattleStart::applyGs( CGameState *gs ) { gs->curB = info; - info->belligerents[0]->battle = info->belligerents[1]->battle = info; - - BOOST_FOREACH(CStack *s, info->stacks) - { - if(s->base) //stack originating from "real" stack in garrison -> attach to it - { - s->attachTo(const_cast(s->base)); - } - else //attach directly to obj to which stack belongs and creature type - { - CArmedInstance *army = info->belligerents[!s->attackerOwned]; - s->attachTo(army); - assert(s->type); - s->attachTo(const_cast(s->type)); - } - s->postInit(); - } + gs->curB->localInit(); } DLL_EXPORT void BattleNextRound::applyGs( CGameState *gs )