1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

* compiles under MSVC (haven't I broken anything on gcc?)

* half-done support for battles
This commit is contained in:
Michał W. Urbańczyk
2008-08-04 15:56:36 +00:00
parent 038dd90517
commit a15ffb06e6
28 changed files with 899 additions and 308 deletions

View File

@@ -16,6 +16,7 @@
#include "../hch/CGeneralTextHandler.h"
#include "../hch/CArtHandler.h"
#include <boost/thread/shared_mutex.hpp>
#include "../lib/VCMI_Lib.h"
CSharedCond<std::set<IPack*> > mess(new std::set<IPack*>);
std::string toString(MetaString &ms)
@@ -208,6 +209,25 @@ void CClient::process(int what)
playerint[sr.player]->receivedResource(-1,-1);
break;
}
case 105:
{
SetPrimSkill sps;
*serv >> sps;
std::cout << "Changing hero primary skill"<<std::endl;
gs->apply(&sps);
playerint[gs->getHero(sps.id)->tempOwner]->heroPrimarySkillChanged(gs->getHero(sps.id),sps.which,sps.val);
break;
}
case 107:
{
ShowInInfobox sii;
*serv >> sii;
SComponent sc(sii.c);
sc.description = toString(sii.text);
if(playerint[sii.player]->human)
static_cast<CPlayerInterface*>(playerint[sii.player])->showComp(sc);
break;
}
case 500:
{
RemoveHero rh;
@@ -297,6 +317,59 @@ void CClient::process(int what)
gs->mx->lock();
gs->map->objects[shn.id]->hoverName = toString(shn.name);
gs->mx->unlock();
break;
}
case 3000:
{
BattleStart bs;
*serv >> bs; //uses new to allocate memory for battleInfo - must be deleted when battle is over
std::cout << "Starting battle!" <<std::endl;
gs->apply(&bs);
if(playerint.find(gs->curB->side1) != playerint.end())
playerint[gs->curB->side1]->battleStart(&gs->curB->army1, &gs->curB->army2, gs->curB->tile, gs->getHero(gs->curB->hero1), gs->getHero(gs->curB->hero2), 0);
if(playerint.find(gs->curB->side2) != playerint.end())
playerint[gs->curB->side2]->battleStart(&gs->curB->army1, &gs->curB->army2, gs->curB->tile, gs->getHero(gs->curB->hero1), gs->getHero(gs->curB->hero2), 1);
break;
}
case 3001:
{
BattleNextRound bnr;
*serv >> bnr;
std::cout << "Round nr " << bnr.round <<std::endl;
gs->apply(&bnr);
//tell players about next round
if(playerint.find(gs->curB->side1) != playerint.end())
playerint[gs->curB->side1]->battleNewRound(bnr.round);
if(playerint.find(gs->curB->side2) != playerint.end())
playerint[gs->curB->side2]->battleNewRound(bnr.round);
break;
}
case 3002:
{
BattleSetActiveStack sas;
*serv >> sas;
std::cout << "Active stack: " << sas.stack <<std::endl;
gs->apply(&sas);
boost::thread(boost::bind(&CClient::waitForMoveAndSend,this,gs->curB->stacks[sas.stack]->owner));
break;
}
case 3003:
{
BattleResult br;
*serv >> br;
std::cout << "Battle ends. Winner: " << (unsigned)br.winner<< ". Type of end: "<< (unsigned)br.result <<std::endl;
if(playerint.find(gs->curB->side1) != playerint.end())
playerint[gs->curB->side1]->battleEnd(&br);
if(playerint.find(gs->curB->side2) != playerint.end())
playerint[gs->curB->side2]->battleEnd(&br);
gs->apply(&br);
break;
}
case 9999:
@@ -310,6 +383,11 @@ void CClient::process(int what)
break;
}
}
void CClient::waitForMoveAndSend(int color)
{
BattleAction ba = playerint[color]->activeStack(gs->curB->activeStack);
*serv << ui16(3002) << ba;
}
void CClient::run()
{
try

View File

@@ -38,6 +38,8 @@ class CClient
CGameState *gs;
std::map<ui8,CGameInterface *> playerint;
CConnection *serv;
void waitForMoveAndSend(int color);
public:
CClient(void);
CClient(CConnection *con, StartInfo *si);

View File

@@ -15,6 +15,12 @@
#include "../hch/CLodHandler.h"
using namespace boost::assign;
using namespace CSDL_Ext;
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
Graphics * graphics = NULL;
SDL_Surface * Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
{