1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Now netcode branch may be compiled with gcc. Sorry can't check build with MSVC

This commit is contained in:
Vadim Glazunov 2008-08-04 09:05:52 +00:00
parent cc7be20b07
commit 6e737bbf3c
24 changed files with 216 additions and 116 deletions

View File

@ -15,7 +15,12 @@
#include <queue>
#include <sstream>
#ifndef __GNUC__
const double M_PI = 3.14159265358979323846;
#else
#define _USE_MATH_DEFINES
#include <cmath>
#endif
extern SDL_Surface * screen;
extern TTF_Font * GEOR13;

View File

@ -68,7 +68,11 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
if (pathType==0)
CPathfinder::convertPath(path,pathType);
if (pathType>1)
#ifndef __GNUC__
throw std::exception("Unknown path format");
#else
throw std::exception();
#endif
CPath * ourPath = path;
if(!ourPath)
@ -115,7 +119,7 @@ void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount
if( ( found = (ID == t->town->basicCreatures[av->first]) ) //creature is available among basic cretures
|| (found = (ID == t->town->upgradedCreatures[av->first])) )//creature is available among upgraded cretures
{
amount = min(amount,av->second); //reduce recruited amount up to available amount
amount = std::min(amount,(int)av->second); //reduce recruited amount up to available amount
ser = av->first;
break;
}
@ -562,7 +566,11 @@ CCreature CCallback::battleGetCreature(int number)
if(CGI->state->curB->stacks[h]->ID == number) //creature found
return *(CGI->state->curB->stacks[h]->creature);
}
#ifndef __GNUC__
throw new std::exception("Cannot find the creature");
#else
throw new std::exception();
#endif
}
std::vector<int> CCallback::battleGetAvailableHexes(int ID)

View File

@ -60,8 +60,8 @@ public:
virtual void tileRevealed(int3 pos){};
virtual void tileHidden(int3 pos){};
virtual void receivedResource(int type, int val){};
virtual void showInfoDialog(std::string text, std::vector<Component*> &components)=0{};
virtual void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)=0{};
virtual void showInfoDialog(std::string text, std::vector<Component*> &components)=0;
virtual void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)=0;
virtual void garrisonChanged(const CGObjectInstance * obj){};
virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished
//battle call-ins

View File

@ -460,7 +460,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed)
{
day = 0;
seed = Seed;
ran.seed((long)seed);
ran.seed((int32_t)seed);
scenarioOps = si;
this->map = map;

View File

@ -1067,7 +1067,7 @@ void LRClickableAreaWText::clickLeft(boost::logic::tribool down)
{
if(!down)
{
#ifndef __amigaos4__
#if !defined(__amigaos4__) && !defined(__unix__)
LOCPLINT->showInfoDialog(text, std::vector<SComponent*>());
#else
#warning error here!
@ -1115,7 +1115,7 @@ void LRClickableAreaWTextComp::clickLeft(boost::logic::tribool down)
{
if((!down) && pressedL)
{
#ifndef __amigaos4__
#if !defined(__amigaos4__) && !defined(__unix__)
LOCPLINT->showInfoDialog(text, std::vector<SComponent*>(1, new SComponent(SComponent::Etype(baseType), type, bonus)));
#else
#warning error here!

View File

@ -215,7 +215,11 @@ void CVisitableOPH::newObject(int objid)
pom = 5;
break;
default:
#ifndef __GNUC__
throw new std::exception("Unsupported ID in CVisitableOPH::hoverText");
#else
throw new std::exception();
#endif
}
hovername << std::pair<ui8,ui32>(3,os->ID) << " " << std::pair<ui8,ui32>(2,pom);
cb->setHoverName(objid,&hovername);
@ -247,7 +251,11 @@ void CVisitableOPH::onHeroVisit(int objid, int heroID)
}
else
{
#ifndef __GNUC__
throw new std::exception("Skrypt nie zainicjalizowal instancji tego obiektu. :(");
#else
throw new std::exception();
#endif
}
};
void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited)

7
CLua.h
View File

@ -1,5 +1,10 @@
#pragma once
#include "global.h"
#ifndef _MSC_VER
extern "C" {
#endif
//#include "lstate.h"
#ifndef _MSC_VER
@ -77,7 +82,7 @@ public:
void findFS(std::string fname);
friend CGameState;
friend class CGameState;
};
class CLuaObjectScript : public CLua, public CObjectScript

View File

@ -79,7 +79,11 @@ std::vector<std::string> * CLuaHandler::searchForScripts(std::string fol)
std::vector<std::string> * ret = new std::vector<std::string> ();
boost::filesystem::path folder(fol);
if (!boost::filesystem::exists(folder))
#ifndef __GNUC__
throw new std::exception("No such folder!");
#else
throw new std::exception();
#endif
boost::filesystem::directory_iterator end_itr;
for
(

12
CMT.cpp
View File

@ -7,7 +7,7 @@
#include <queue>
#include <cmath>
#include <boost/thread.hpp>
#include "SDL_TTF.h"
#include "SDL_ttf.h"
#include "SDL_mixer.h"
#include "SDL_Extensions.h"
#include "SDL_framerate.h"
@ -36,7 +36,7 @@
#include "hch/CAmbarCendamo.h"
#include "hch/CGeneralTextHandler.h"
#include "client/Graphics.h"
#include "Client/Client.h"
#include "client/Client.h"
#include "lib/Connection.h"
#include "lib/VCMI_Lib.h"
std::string NAME = NAME_VER + std::string(" (client)");
@ -46,7 +46,11 @@ extern SDL_Surface * CSDL_Ext::std32bppSurface;
std::queue<SDL_Event> events;
boost::mutex eventsM;
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
#ifndef __GNUC__
int _tmain(int argc, _TCHAR* argv[])
#else
int main(int argc, _TCHAR* argv[])
#endif
{
std::cout.flags(ios::unitbuf);
std::cout << NAME << std::endl;
@ -146,9 +150,9 @@ int _tmain(int argc, _TCHAR* argv[])
THC std::cout<<"\tCallback and console: "<<pomtime.getDif()<<std::endl;
THC std::cout<<"Handlers initialization (together): "<<tmh.getDif()<<std::endl;
std::ofstream lll("client_log.txt");
CConnection c("localhost","3030",NAME,lll);
CConnection *c = new CConnection("localhost","3030",NAME,lll);
THC std::cout<<"\tConnecting to the server: "<<tmh.getDif()<<std::endl;
CClient cl(&c,options);
CClient cl(c,options);
boost::thread t(boost::bind(&CClient::run,&cl));
SDL_Event ev;
while(1) //main SDL events loop

View File

@ -949,7 +949,7 @@ void MapSel::processMaps(std::vector<std::string> &pliczkiTemp, int &index)
int z = gzgetc (tempf);
if (z>=0)
{
sss[iii++] = unsigned char(z);
sss[iii++] = (unsigned char)z;
}
else break;
}
@ -981,7 +981,7 @@ void MapSel::init()
int mapInd=0;
boost::thread_group group;
int cores = max(1,boost::thread::hardware_concurrency());
int cores = std::max((unsigned int)1,boost::thread::hardware_concurrency());
for(int ti=0;ti<cores;ti++)
group.create_thread(boost::bind(&MapSel::processMaps,this,boost::ref(pliczkiTemp),boost::ref(mapInd)));

View File

@ -120,7 +120,11 @@ CClient::CClient(CConnection *con, StartInfo *si)
if(mapa->checksum != sum)
{
#ifndef __GNUC__
throw std::exception("Wrong checksum");
#else
throw std::exception();
#endif
exit(-1);
}
std::cout << "\tUsing random seed: "<<seed << std::endl;
@ -298,7 +302,11 @@ void CClient::process(int what)
case 9999:
break;
default:
#ifndef __GNUC__
throw std::exception("Not supported server message!");
#else
throw std::exception();
#endif
break;
}
}
@ -313,4 +321,5 @@ void CClient::run()
process(typ);
}
} HANDLE_EXCEPTION
}
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "../global.h"
#include <boost/thread.hpp>
struct StartInfo;
class CGameState;
class CGameInterface;

View File

@ -21,7 +21,7 @@ SDL_Surface * Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface
char * buf = new char[10];
for (int i=from;i<to;i++)
{
itoa(curh->primSkills[i],buf,10);
SDL_itoa(curh->primSkills[i],buf,10);
printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
}
delete[] buf;
@ -38,11 +38,11 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh)
for (std::map<si32,std::pair<ui32,si32> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
{
blitAt(graphics->smallImgs[(*i).second.first],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
itoa((*i).second.second,buf,10);
SDL_itoa((*i).second.second,buf,10);
printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
}
blitAt(graphics->portraitLarge[curh->portrait],11,12,ret);
itoa(curh->mana,buf,10);
SDL_itoa(curh->mana,buf,10);
printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
delete[] buf;
blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
@ -62,14 +62,14 @@ SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh)
blitAt(forts->ourImages[pom].bitmap,115,42,ret);
if((pom=curh->hallLevel())>=0)
blitAt(halls->ourImages[pom].bitmap,77,42,ret);
itoa(curh->dailyIncome(),buf,10);
SDL_itoa(curh->dailyIncome(),buf,10);
printAtMiddle(buf,167,70,GEORM,zwykly,ret);
for (std::map<si32,std::pair<ui32,si32> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
{
if(!i->second.first)
continue;
blitAt(graphics->smallImgs[(*i).second.first],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
itoa((*i).second.second,buf,10);
SDL_itoa((*i).second.second,buf,10);
printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
}
@ -185,7 +185,7 @@ Graphics::Graphics()
tasks += GET_SURFACE(backgrounds[id],name);
}
CThreadHelper th(&tasks,max(1,boost::thread::hardware_concurrency()));
CThreadHelper th(&tasks,std::max((unsigned int)1,boost::thread::hardware_concurrency()));
th.run();
//handling 32x32px imgs
@ -387,7 +387,11 @@ SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded)
else if (ID==-3)
return smallIcons->ourImages[2+F_NUMBER*4].bitmap;
else if (ID>F_NUMBER || ID<-3)
#ifndef __GNUC__
throw new std::exception("Invalid ID");
#else
throw new std::exception();
#endif
else
{
int pom = 3;
@ -474,4 +478,4 @@ void Graphics::blueToPlayersAdv(SDL_Surface * sur, int player)
}
}
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -39,7 +39,7 @@ void CConnection::init()
CConnection::CConnection(std::string host, std::string port, std::string Name, std::ostream & Out)
:io_service(new asio::io_service), name(Name), out(Out)//, send(this), rec(this)
{
system::error_code error = asio::error::host_not_found;
boost::system::error_code error = asio::error::host_not_found;
socket = new tcp::socket(*io_service);
tcp::resolver resolver(*io_service);
tcp::resolver::iterator endpoint_iterator = resolver.resolve(tcp::resolver::query(host,port));
@ -58,7 +58,7 @@ CConnection::CConnection(
CConnection::CConnection(boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptor_service<boost::asio::ip::tcp> > * acceptor, boost::asio::io_service *Io_service, std::string Name, std::ostream & Out)
: out(Out), name(Name)//, send(this), rec(this)
{
system::error_code error = asio::error::host_not_found;
boost::system::error_code error = asio::error::host_not_found;
socket = new tcp::socket(*io_service);
acceptor->accept(*socket,error);
if (error){ delete socket; throw "Can't establish connection :("; }
@ -86,3 +86,19 @@ CConnection::~CConnection(void)
delete wmx;
delete rmx;
}
template <>
void CConnection::saveSerializable<std::string>(const std::string &data)
{
*this << ui32(data.size());
write(data.c_str(),data.size());
}
template <>
void CConnection::loadSerializable<std::string>(std::string &data)
{
ui32 l;
*this >> l;
data.resize(l);
read((void*)data.c_str(),l);
}

View File

@ -12,6 +12,8 @@
#include <boost/mpl/int.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/thread.hpp>
const int version = 63;
class CConnection;
@ -190,30 +192,19 @@ public:
read(&data,sizeof(data));
}
template <typename T>
void saveSerializable(const T &data)
{
const_cast<T&>(data).serialize(*static_cast<COSer*>(this),version);
const_cast<T&>(data).serialize(*static_cast<COSer<CConnection>*>(this),version);
}
template <typename T>
void loadSerializable(T &data)
{
data.serialize(*static_cast<CISer*>(this),version);
}
template <>
void saveSerializable<std::string>(const std::string &data)
{
*this << ui32(data.size());
write(data.c_str(),data.size());
}
template <>
void loadSerializable<std::string>(std::string &data)
{
ui32 l;
*this >> l;
data.resize(l);
read((void*)data.c_str(),l);
data.serialize(*static_cast<CISer<CConnection>*>(this),version);
}
template <typename T>
void saveSerializable(const std::vector<T> &data)
{
@ -231,13 +222,14 @@ public:
for(ui32 i=0;i<length;i++)
*this >> data[i];
}
template <typename T>
void saveSerializable(const std::set<T> &data)
{
std::set<T> &d = const_cast<std::set<T> &>(data);
boost::uint32_t length = d.size();
*this << length;
for(std::set<T>::iterator i=d.begin();i!=d.end();i++)
for(typename std::set<T>::iterator i=d.begin();i!=d.end();i++)
*this << *i;
}
template <typename T>
@ -252,6 +244,7 @@ public:
data.insert(ins);
}
}
template <typename T1, typename T2>
void saveSerializable(const std::pair<T1,T2> &data)
{
@ -262,11 +255,12 @@ public:
{
*this >> data.first >> data.second;
}
template <typename T1, typename T2>
void saveSerializable(const std::map<T1,T2> &data)
{
*this << ui32(data.size());
for(std::map<T1,T2>::const_iterator i=data.begin();i!=data.end();i++)
for(typename std::map<T1,T2>::const_iterator i=data.begin();i!=data.end();i++)
*this << i->first << i->second;
}
template <typename T1, typename T2>
@ -334,4 +328,11 @@ public:
int read(void * data, unsigned size);
int readLine(void * data, unsigned maxSize);
~CConnection(void);
};
};
template<>
void CConnection::saveSerializable<std::string>(const std::string &data);
template <>
void CConnection::loadSerializable<std::string>(std::string &data);

98
map.cpp
View File

@ -85,55 +85,55 @@ EDefType getDefType(CGDefInfo * a)
switch(a->id)
{
case 5: case 65: case 66: case 67: case 68: case 69:
return EDefType::ARTIFACT_DEF; //handled
return ARTIFACT_DEF; //handled
case 6:
return EDefType::PANDORA_DEF; //hanled
return PANDORA_DEF; //hanled
case 26:
return EDefType::EVENTOBJ_DEF; //handled
return EVENTOBJ_DEF; //handled
case 33:
return EDefType::GARRISON_DEF; //handled
return GARRISON_DEF; //handled
case 34: case 70: case 62: //70 - random hero //62 - prison
return EDefType::HERO_DEF; //handled
return HERO_DEF; //handled
case 36:
return EDefType::GRAIL_DEF; //hanled
return GRAIL_DEF; //hanled
case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests
return EDefType::PLAYERONLY_DEF; //handled
return PLAYERONLY_DEF; //handled
case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164:
return EDefType::CREATURES_DEF; //handled
return CREATURES_DEF; //handled
case 59:
return EDefType::SIGN_DEF; //handled
return SIGN_DEF; //handled
case 77:
return EDefType::TOWN_DEF; //can be problematic, but handled
return TOWN_DEF; //can be problematic, but handled
case 79: case 76:
return EDefType::RESOURCE_DEF; //handled
return RESOURCE_DEF; //handled
case 81:
return EDefType::SCHOLAR_DEF; //handled
return SCHOLAR_DEF; //handled
case 83:
return EDefType::SEERHUT_DEF; //handled
return SEERHUT_DEF; //handled
case 91:
return EDefType::SIGN_DEF; //handled
return SIGN_DEF; //handled
case 88: case 89: case 90:
return SHRINE_DEF; //handled
case 93:
return SPELLSCROLL_DEF; //handled
case 98:
return EDefType::TOWN_DEF; //handled
return TOWN_DEF; //handled
case 113:
return EDefType::WITCHHUT_DEF; //handled
return WITCHHUT_DEF; //handled
case 214:
return EDefType::HEROPLACEHOLDER_DEF; //partially handled
return HEROPLACEHOLDER_DEF; //partially handled
case 215:
return EDefType::BORDERGUARD_DEF; //handled by analogy to seer huts ;]
return BORDERGUARD_DEF; //handled by analogy to seer huts ;]
case 216:
return EDefType::CREGEN2_DEF; //handled
return CREGEN2_DEF; //handled
case 217:
return EDefType::CREGEN_DEF; //handled
return CREGEN_DEF; //handled
case 218:
return EDefType::CREGEN3_DEF; //handled
return CREGEN3_DEF; //handled
case 219:
return EDefType::GARRISON_DEF; //handled
return GARRISON_DEF; //handled
default:
return EDefType::TERRAINOBJ_DEF; // nothing to be handled
return TERRAINOBJ_DEF; // nothing to be handled
}
}
int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4, bool cyclic = false)
@ -1017,7 +1017,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
int p = 99;
switch(getDefType(nobj->defInfo))
{
case EDefType::EVENTOBJ_DEF: //for event - objects
case EVENTOBJ_DEF: //for event - objects
{
CEventObjInfo * spec = new CEventObjInfo;
bool guardMess;
@ -1091,7 +1091,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::HERO_DEF:
case HERO_DEF:
{
CGHeroInstance * nhi = new CGHeroInstance;
(*(static_cast<CGObjectInstance*>(nhi))) = *nobj;
@ -1290,7 +1290,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::SIGN_DEF:
case SIGN_DEF:
{
CSignObjInfo * spec = new CSignObjInfo;
int length = readNormalNr(bufor,i); i+=4;
@ -1302,7 +1302,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::SEERHUT_DEF:
case SEERHUT_DEF:
{
CSeerHutObjInfo * spec = new CSeerHutObjInfo;
if(version>RoE)
@ -1599,7 +1599,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::WITCHHUT_DEF:
case WITCHHUT_DEF:
{
CWitchHutObjInfo * spec = new CWitchHutObjInfo;
if(version>RoE) //in reo we cannot specify it - all are allowed (I hope)
@ -1629,7 +1629,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::SCHOLAR_DEF:
case SCHOLAR_DEF:
{
CScholarObjInfo * spec = new CScholarObjInfo;
spec->bonusType = bufor[i]; ++i;
@ -1652,7 +1652,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::GARRISON_DEF:
case GARRISON_DEF:
{
CGarrisonObjInfo * spec = new CGarrisonObjInfo;
spec->player = bufor[i]; ++i;
@ -1669,7 +1669,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::ARTIFACT_DEF:
case ARTIFACT_DEF:
{
CArtifactObjInfo * spec = new CArtifactObjInfo;
bool areSettings = bufor[i]; ++i;
@ -1693,7 +1693,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::RESOURCE_DEF:
case RESOURCE_DEF:
{
CResourceObjInfo * spec = new CResourceObjInfo;
bool isMessGuard = bufor[i]; ++i;
@ -1720,7 +1720,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::TOWN_DEF:
case TOWN_DEF:
{
CGTownInstance * nt = new CGTownInstance();
(*(static_cast<CGObjectInstance*>(nt))) = *nobj;
@ -1864,7 +1864,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
towns.push_back(nt);
break;
}
case EDefType::PLAYERONLY_DEF:
case PLAYERONLY_DEF:
{
CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo;
spec->player = bufor[i]; ++i;
@ -1873,14 +1873,14 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::SHRINE_DEF:
case SHRINE_DEF:
{
CShrineObjInfo * spec = new CShrineObjInfo;
spec->spell = bufor[i]; i+=4;
nobj->info = spec;
break;
}
case EDefType::SPELLSCROLL_DEF:
case SPELLSCROLL_DEF:
{
CSpellScrollObjinfo * spec = new CSpellScrollObjinfo;
bool messg = bufor[i]; ++i;
@ -1903,7 +1903,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::PANDORA_DEF:
case PANDORA_DEF:
{
CPandorasBoxObjInfo * spec = new CPandorasBoxObjInfo;
bool messg = bufor[i]; ++i;
@ -1970,14 +1970,14 @@ void Mapa::initFromBytes(unsigned char * bufor)
///////end of copied fragment
break;
}
case EDefType::GRAIL_DEF:
case GRAIL_DEF:
{
CGrailObjInfo * spec = new CGrailObjInfo;
spec->radius = readNormalNr(bufor,i); i+=4;
nobj->info = spec;
break;
}
case EDefType::CREGEN_DEF:
case CREGEN_DEF:
{
CCreGenObjInfo * spec = new CCreGenObjInfo;
spec->player = readNormalNr(bufor,i); i+=4;
@ -1996,7 +1996,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::CREGEN2_DEF:
case CREGEN2_DEF:
{
CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
spec->player = readNormalNr(bufor,i); i+=4;
@ -2021,7 +2021,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::CREGEN3_DEF:
case CREGEN3_DEF:
{
CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
spec->player = bufor[i]; ++i;
@ -2036,10 +2036,11 @@ void Mapa::initFromBytes(unsigned char * bufor)
nobj->info = spec;
break;
}
case EDefType::BORDERGUARD_DEF:
case BORDERGUARD_DEF:
{
CBorderGuardObjInfo * spec = new CBorderGuardObjInfo;
spec->missionType = bufor[i]; ++i;
int len1, len2, len3;
switch(spec->missionType)
{
case 0:
@ -2220,19 +2221,19 @@ void Mapa::initFromBytes(unsigned char * bufor)
}
}//internal switch end (seer huts)
int len1 = readNormalNr(bufor,i); i+=4;
len1 = readNormalNr(bufor,i); i+=4;
for(int ee=0; ee<len1; ++ee)
{
spec->firstVisitText += bufor[i]; ++i;
}
int len2 = readNormalNr(bufor,i); i+=4;
len2 = readNormalNr(bufor,i); i+=4;
for(int ee=0; ee<len2; ++ee)
{
spec->nextVisitText += bufor[i]; ++i;
}
int len3 = readNormalNr(bufor,i); i+=4;
len3 = readNormalNr(bufor,i); i+=4;
for(int ee=0; ee<len3; ++ee)
{
spec->completedText += bufor[i]; ++i;
@ -2241,7 +2242,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
borderguardend:
break;
}
case EDefType::HEROPLACEHOLDER_DEF:
case HEROPLACEHOLDER_DEF:
{
i+=3; //TODO: handle it more properly
break;
@ -2350,7 +2351,12 @@ Mapa::Mapa(std::string filename)
CGHeroInstance * Mapa::getHero(int ID, int mode)
{
if (mode != 0)
#ifndef __GNUC__
throw new std::exception("gs->getHero: This mode is not supported!");
#else
throw new std::exception();
#endif
for(int i=0; i<heroes.size();i++)
if(heroes[i]->subID == ID)
return heroes[i];

View File

@ -1101,7 +1101,11 @@ std::string CMapHandler::getDefName(int id, int subid)
CGDefInfo* temp = CGI->dobjinfo->gobjs[id][subid];
if(temp)
return temp->name;
#ifndef __GNUC__
throw new std::exception("Def not found.");
#else
throw new std::exception();
#endif
}
bool CMapHandler::printObject(CGObjectInstance *obj)
@ -1244,7 +1248,11 @@ unsigned char CMapHandler::getHeroFrameNum(const unsigned char &dir, const bool
case 8:
return 11;
default:
#ifndef __GNUC__
throw std::exception("Something very wrong1.");
#else
throw std::exception();
#endif
}
}
else //if(isMoving)
@ -1268,7 +1276,11 @@ unsigned char CMapHandler::getHeroFrameNum(const unsigned char &dir, const bool
case 8:
return 14;
default:
#ifndef __GNUC__
throw std::exception("Something very wrong2.");
#else
throw std::exception();
#endif
}
}
}

View File

@ -35,7 +35,7 @@ public:
int offset;
std::vector<T> inver;
PseudoV(){};
PseudoV(std::vector<T> &src, int offset, const T& fill)
PseudoV(std::vector<T> &src, int rest, int Offset, const T& fill)
{
inver.resize(Offset*2+rest);
offset=Offset;

View File

@ -17,7 +17,9 @@
#include "../hch/CHeroHandler.h"
#include "boost/date_time/posix_time/posix_time_types.hpp" //no i/o just types
#include "../lib/VCMI_Lib.h"
extern bool end;
#include <boost/thread.hpp>
#include <boost/thread/xtime.hpp>
extern bool end2;
bool makingTurn;
boost::condition_variable cTurn;
boost::mutex mTurn;
@ -54,9 +56,10 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
try
{
ui16 pom;
while(!end)
while(!end2)
{
c >> pom;
bool blockvis = false;
switch(pom)
{
case 100: //my interface ended its turn
@ -102,7 +105,7 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
//check if there is blocking visitable object
bool blockvis = false;
blockvis = false;
tmh.movePoints = h->movement = (h->movement-cost); //take move points
BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects)
{
@ -290,7 +293,11 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
break;
}
default:
#ifndef __GNUC__
throw std::exception("Not supported client message!");
#else
throw std::exception();
#endif
break;
}
}
@ -298,17 +305,17 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
end = true;
end2 = true;
}
catch (const std::exception * e)
{
std::cerr << e->what()<< std::endl;
end = true;
end2 = true;
delete e;
}
catch(...)
{
end = true;
end2 = true;
}
}
CGameHandler::CGameHandler(void)
@ -358,7 +365,7 @@ int lowestSpeed(CGHeroInstance * chi)
int ret = VLC->creh->creatures[(*i++).second.first].speed;
for (;i!=chi->army.slots.end();i++)
{
ret = min(ret,VLC->creh->creatures[(*i).second.first].speed);
ret = std::min(ret,VLC->creh->creatures[(*i).second.first].speed);
}
return ret;
}
@ -477,7 +484,7 @@ void CGameHandler::run()
// (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
}
while (!end)
while (!end2)
{
newTurn();
for(std::map<ui8,PlayerState>::iterator i = gs->players.begin(); i != gs->players.end(); i++)
@ -488,13 +495,15 @@ void CGameHandler::run()
*connections[i->first] << ui16(100) << i->first;
//wait till turn is done
boost::unique_lock<boost::mutex> lock(mTurn);
while(makingTurn && !end)
while(makingTurn && !end2)
{
boost::posix_time::time_duration p;
p= boost::posix_time::seconds(1);
cTurn.timed_wait(lock,p);
boost::xtime time={0,0};
time.sec = static_cast<boost::xtime::xtime_sec_t>(p.total_seconds());
cTurn.timed_wait(lock,time);
}
}
}
}
}

View File

@ -1,9 +1,11 @@
#pragma once
#include "../global.h"
#include <set>
#include "../CGameState.h"
#include "../lib/Connection.h"
class CVCMIServer;
class CGameState;
class CConnection;
//class CConnection;
struct StartInfo;
class CCPPObjectScript;
class CScriptCallback;

View File

@ -4,7 +4,9 @@
#include "../global.h"
#include "../lib/Connection.h"
#include "zlib.h"
#ifndef __GNUC__
#include <tchar.h>
#endif
#include "CVCMIServer.h"
#include <boost/crc.hpp>
#include <boost/serialization/split_member.hpp>
@ -19,7 +21,7 @@ using namespace boost;
using namespace boost::asio;
using namespace boost::asio::ip;
bool end = false;
bool end2 = false;
CVCMIServer::CVCMIServer()
: io(new io_service()), acceptor(new tcp::acceptor(*io, tcp::endpoint(tcp::v4(), 3030)))
@ -31,14 +33,14 @@ CVCMIServer::~CVCMIServer()
//delete acceptor;
}
void CVCMIServer::newGame(CConnection &c)
void CVCMIServer::newGame(CConnection *c)
{
CGameHandler gh;
boost::system::error_code error;
StartInfo *si = new StartInfo;
ui8 clients;
c >> clients; //how many clients should be connected - TODO: support more than one
c >> *si; //get start options
*c >> clients; //how many clients should be connected - TODO: support more than one
*c >> *si; //get start options
int problem;
#ifdef _MSC_VER
FILE *f;
@ -49,13 +51,13 @@ void CVCMIServer::newGame(CConnection &c)
#endif
if(problem)
{
c << ui8(problem); //WRONG!
*c << ui8(problem); //WRONG!
return;
}
else
{
fclose(f);
c << ui8(0); //OK!
*c << ui8(0); //OK!
}
gh.init(si,rand());
@ -65,7 +67,7 @@ void CVCMIServer::newGame(CConnection &c)
{
if(!i)
{
cc=&c;
cc=c;
}
else
{
@ -95,20 +97,20 @@ void CVCMIServer::start()
std::cout<<"Got connection but there is an error " << std::endl;
return;
}
CConnection connection(s,NAME,std::cout);
CConnection *connection = new CConnection(s,NAME,std::cout);
std::cout<<"Got connection!" << std::endl;
while(!end)
while(!end2)
{
uint8_t mode;
connection >> mode;
*connection >> mode;
switch (mode)
{
case 0:
connection.socket->close();
connection->socket->close();
exit(0);
break;
case 1:
connection.socket->close();
connection->socket->close();
return;
break;
case 2:
@ -118,7 +120,11 @@ void CVCMIServer::start()
}
}
#ifndef __GNUC__
int _tmain(int argc, _TCHAR* argv[])
#else
int main(int argc, _TCHAR* argv[])
#endif
{
CLodHandler h3bmp;
h3bmp.init("Data\\H3bitmap.lod","Data");
@ -128,7 +134,7 @@ int _tmain(int argc, _TCHAR* argv[])
{
io_service io_service;
CVCMIServer server;
while(!end)
while(!end2)
server.start();
io_service.run();
} HANDLE_EXCEPTION

View File

@ -27,6 +27,6 @@ public:
CVCMIServer();
~CVCMIServer();
void setUpConnection(CConnection *c, std::string mapname, si32 checksum);
void newGame(CConnection &c);
void newGame(CConnection *c);
void start();
};
};