1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Little more development for duel mode.

This commit is contained in:
Michał W. Urbańczyk 2010-12-23 00:33:48 +00:00
parent cde0e8933f
commit 2fe8b07f4f
9 changed files with 112 additions and 51 deletions

View File

@ -5,6 +5,10 @@
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="RD|Win32">
<Configuration>RD</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
@ -26,6 +30,12 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RD|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
@ -35,6 +45,9 @@
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='RD|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -48,7 +61,8 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>VCMI_lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<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)</AdditionalLibraryDirectories>
<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)</AdditionalLibraryDirectories>
<OutputFile>$(OutDir)StupidAI.dll</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -66,7 +80,26 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>VCMI_lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>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)</AdditionalLibraryDirectories>
<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)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='RD|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>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&gt;</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>VCMI_lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<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)</AdditionalLibraryDirectories>
<OutputFile>$(OutDir)StupidAI.dll</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
@ -74,6 +107,7 @@
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='RD|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="StupidAI.cpp" />
</ItemGroup>

View File

@ -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<CCallback*>(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();

View File

@ -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<bool> *showingDialog; //indicates if dialog box is displayed

View File

@ -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): "<<tmh.getDif()<<std::endl;
if(!gs->map)
if(gs->map)
{
const_cast<CGameInfo*>(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<CGameInfo*>(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<CPlayerInterface*>( playerint[info->side1] );
else
att = NULL;
if(vstd::contains(playerint, info->side2) && playerint[info->side2]->human)
def = static_cast<CPlayerInterface*>( 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<CLoadFile> &h, const int version );
template void CClient::serialize( COSer<CSaveFile> &h, const int version );

View File

@ -148,6 +148,7 @@ public:
void handlePack( CPack * pack ); //applies the given pack and deletes it
void updatePaths();
void battleStarted(const BattleInfo * info);
//////////////////////////////////////////////////////////////////////////

View File

@ -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<CPlayerInterface*>( cl->playerint[info->side1] );
else
att = NULL;
if(vstd::contains(cl->playerint, info->side2) && cl->playerint[info->side2]->human)
def = static_cast<CPlayerInterface*>( 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 )

View File

@ -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<CStackInstance*>(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<CCreature*>(s->type));
}
s->postInit();
}
}
int3 CPath::startPos() const
{
return nodes[nodes.size()-1].coord;

View File

@ -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

View File

@ -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<CStackInstance*>(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<CCreature*>(s->type));
}
s->postInit();
}
gs->curB->localInit();
}
DLL_EXPORT void BattleNextRound::applyGs( CGameState *gs )