1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* save/load partially working

* Arena and Witch Hut support
* improved support for Resources
* minor fixes and changes
This commit is contained in:
Michał W. Urbańczyk 2009-01-10 22:08:18 +00:00
parent 645ed84978
commit 3474fdaf05
44 changed files with 1103 additions and 538 deletions

View File

@ -1089,7 +1089,7 @@ void CHallInterface::close()
delete this;
LOCPLINT->castleInt->activate();
}
void CHallInterface::show(SDL_Surface * to) //TODO use me
void CHallInterface::show(SDL_Surface * to)
{
blitAt(bg,pos);
resdatabar.show();
@ -1460,7 +1460,7 @@ void CFortScreen::RecArea::clickLeft (tribool down)
if(!down && pressedL)
{
LOCPLINT->curint->deactivate();
//CRecrutationWindow *rw = LOCPLINT->castleInt->showRecruitmentWindow(bid); //TODO use me
CRecrutationWindow *rw = LOCPLINT->castleInt->showRecruitmentWindow(bid); //do not touch me
}
ClickableL::clickLeft(down);
}
@ -1530,7 +1530,7 @@ void CMageGuildScreen::close()
LOCPLINT->castleInt->subInt = NULL;
LOCPLINT->castleInt->activate();
}
void CMageGuildScreen::show(SDL_Surface * to) //TODO use me
void CMageGuildScreen::show(SDL_Surface * to)
{
blitAt(bg,pos);
resdatabar.show();

View File

@ -1,4 +1,24 @@
#include "stdafx.h"
#include "CGameInfo.h"
#include "lib/VCMI_Lib.h"
CGameInfo * CGI;
CGameInfo::CGameInfo()
{
mh = NULL;
state = NULL;
}
void CGameInfo::setFromLib()
{
generaltexth = VLC->generaltexth;
arth = VLC->arth;
creh = VLC->creh;
townh = VLC->townh;
heroh = VLC->heroh;
objh = VLC->objh;
spellh = VLC->spellh;
dobjinfo = VLC->dobjinfo;
buildh = VLC->buildh;
}

View File

@ -61,6 +61,9 @@ public:
CPathfinder * pathf;
CCursorHandler * curh;
CScreenHandler * screenh;
CGameInfo();
void setFromLib();
};

View File

@ -1122,10 +1122,16 @@ int CGameState::getDate(int mode) const
CGameState::CGameState()
{
mx = new boost::shared_mutex();
map = NULL;
curB = NULL;
scenarioOps = NULL;
}
CGameState::~CGameState()
{
delete mx;
delete map;
delete curB;
delete scenarioOps;
}
void CGameState::init(StartInfo * si, Mapa * map, int Seed)
{

View File

@ -59,7 +59,6 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & color & serial & currentSelection & fogOfWarMap & resources;
//TODO: vectors of heroes/towns
}
};
@ -187,8 +186,6 @@ private:
boost::shared_mutex *mx;
CGameState();
~CGameState();
void init(StartInfo * si, Mapa * map, int Seed);
void loadTownDInfos();
void applyNL(IPack * pack);
@ -210,6 +207,8 @@ private:
float getMarketEfficiency(int player, int mode=0);
std::set<int3> tilesToReveal(int3 pos, int radious, int player) const; //if player==-1 => adds all tiles in radious
public:
CGameState();
~CGameState();
int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
template <typename Handler> void serialize(Handler &h, const int version)
{
@ -217,6 +216,14 @@ public:
if(!h.saving)
{
loadTownDInfos();
//recreating towns/heroes vectors in players entries
for(int i=0; i<map->towns.size(); i++)
if(map->towns[i]->tempOwner < PLAYER_LIMIT)
players[map->towns[i]->tempOwner].towns.push_back(map->towns[i]);
for(int i=0; i<map->heroes.size(); i++)
if(map->heroes[i]->tempOwner < PLAYER_LIMIT)
players[map->heroes[i]->tempOwner].heroes.push_back(map->heroes[i]);
}
}

View File

@ -237,10 +237,10 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
{
secSkillAreas[g]->type = hero->secSkills[g].first;
secSkillAreas[g]->bonus = hero->secSkills[g].second;
std::string hlp = CGI->abilh->abilities[ hero->secSkills[g].first ]->infoTexts[hero->secSkills[g].second-1];
std::string hlp = CGI->generaltexth->skillInfoTexts[ hero->secSkills[g].first ][hero->secSkills[g].second-1];
secSkillAreas[g]->text = hlp.substr(1, hlp.size()-2);
sprintf(bufor, CGI->generaltexth->heroscrn[21].c_str(), CGI->abilh->levels[hero->secSkills[g].second-1].c_str(), CGI->abilh->abilities[hero->secSkills[g].first]->name.c_str());
sprintf(bufor, CGI->generaltexth->heroscrn[21].c_str(), CGI->generaltexth->levels[hero->secSkills[g].second-1].c_str(), CGI->generaltexth->skillName[hero->secSkills[g].first].c_str());
secSkillAreas[g]->hoverText = std::string(bufor);
}
@ -615,50 +615,50 @@ void CHeroWindow::redrawCurBack()
if(curHero->secSkills.size()>=1)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[0].first*3+3+curHero->secSkills[0].second-1].bitmap, 18, 276, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[0].second-1], 69, 279, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[0].first]->name, 69, 299, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[0].second-1], 69, 279, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[0].first], 69, 299, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=2)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[1].first*3+3+curHero->secSkills[1].second-1].bitmap, 161, 276, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[1].second-1], 213, 279, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[1].first]->name, 213, 299, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[1].second-1], 213, 279, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[1].first], 213, 299, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=3)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[2].first*3+3+curHero->secSkills[2].second-1].bitmap, 18, 324, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[2].second-1], 69, 327, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[2].first]->name, 69, 347, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[2].second-1], 69, 327, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[2].first], 69, 347, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=4)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[3].first*3+3+curHero->secSkills[3].second-1].bitmap, 161, 324, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[3].second-1], 213, 327, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[3].first]->name, 213, 347, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[3].second-1], 213, 327, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[3].first], 213, 347, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=5)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[4].first*3+3+curHero->secSkills[4].second-1].bitmap, 18, 372, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[4].second-1], 69, 375, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[4].first]->name, 69, 395, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[4].second-1], 69, 375, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[4].first], 69, 395, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=6)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[5].first*3+3+curHero->secSkills[5].second-1].bitmap, 161, 372, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[5].second-1], 213, 375, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[5].first]->name, 213, 395, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[5].second-1], 213, 375, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[5].first], 213, 395, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=7)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[6].first*3+3+curHero->secSkills[6].second-1].bitmap, 18, 420, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[6].second-1], 69, 423, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[6].first]->name, 69, 443, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[6].second-1], 69, 423, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[6].first], 69, 443, GEOR13, zwykly, curBack);
}
if(curHero->secSkills.size()>=8)
{
blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[7].first*3+3+curHero->secSkills[7].second-1].bitmap, 161, 420, curBack);
CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[7].second-1], 213, 423, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[7].first]->name, 213, 443, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->levels[curHero->secSkills[7].second-1], 213, 423, GEOR13, zwykly, curBack);
CSDL_Ext::printAt(CGI->generaltexth->skillName[curHero->secSkills[7].first], 213, 443, GEOR13, zwykly, curBack);
}
//printing special ability

72
CMT.cpp
View File

@ -8,8 +8,6 @@
#include <cmath>
#include <boost/algorithm/string.hpp>
#include "boost/filesystem/operations.hpp"
#include <boost/interprocess/mapped_region.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/thread.hpp>
#include <SDL_ttf.h>
#include <SDL_mixer.h>
@ -43,7 +41,6 @@
#include "client/Client.h"
#include "client/CConfigHandler.h"
#include "lib/Connection.h"
#include "lib/Interprocess.h"
#include "lib/VCMI_Lib.h"
#include <cstdlib>
@ -54,7 +51,6 @@ extern SDL_Surface * CSDL_Ext::std32bppSurface;
std::queue<SDL_Event> events;
boost::mutex eventsM;
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
namespace intpr = boost::interprocess;
void processCommand(const std::string &message, CClient *&client);
#ifndef __GNUC__
int _tmain(int argc, _TCHAR* argv[])
@ -115,15 +111,7 @@ int main(int argc, char** argv)
cgi->bitmaph->init("Data" PATHSEPARATOR "H3bitmap.lod","Data");
tlog0<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
initDLL(cgi->bitmaph,::console,logfile);
CGI->generaltexth = VLC->generaltexth;
CGI->arth = VLC->arth;
CGI->creh = VLC->creh;
CGI->townh = VLC->townh;
CGI->heroh = VLC->heroh;
CGI->objh = VLC->objh;
CGI->spellh = VLC->spellh;
CGI->dobjinfo = VLC->dobjinfo;
CGI->buildh = VLC->buildh;
CGI->setFromLib();
tlog0<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
pomtime.getDif();
cgi->curh = new CCursorHandler;
@ -134,15 +122,13 @@ int main(int argc, char** argv)
abilh->loadAbilities();
cgi->abilh = abilh;
tlog0<<"\tAbility handler: "<<pomtime.getDif()<<std::endl;
cgi->pathf = new CPathfinder();
tlog0<<"\tPathfinder: "<<pomtime.getDif()<<std::endl;
tlog0<<"Preparing first handlers: "<<tmh.getDif()<<std::endl;
pomtime.getDif();
graphics = new Graphics();
graphics->loadHeroAnim();
tlog0<<"\tMain graphics: "<<tmh.getDif()<<std::endl;
std::vector<CDefHandler **> animacje;
for(std::vector<CHeroClass *>::iterator i = cgi->heroh->heroClasses.begin();i!=cgi->heroh->heroClasses.end();i++)
animacje.push_back(&((*i)->*(&CHeroClass::moveAnim)));
graphics->loadHeroAnim(animacje);
tlog0<<"\tHero animations: "<<tmh.getDif()<<std::endl;
tlog0<<"Initializing game graphics: "<<tmh.getDif()<<std::endl;
CMessage::init();
tlog0<<"Message handler: "<<tmh.getDif()<<std::endl;
@ -152,41 +138,29 @@ int main(int argc, char** argv)
cpg->mush = mush;
StartInfo *options = new StartInfo(cpg->runLoop());
CClient cl;
if(options->mode == 0) //new game
{
tmh.getDif();
////////////////////////SERVER STARTING/////////////////////////////////////////////////
char portc[10]; SDL_itoa(conf.cc.port,portc,10);
intpr::shared_memory_object smo(intpr::open_or_create,"vcmi_memory",intpr::read_write);
smo.truncate(sizeof(ServerReady));
intpr::mapped_region mr(smo,intpr::read_write);
ServerReady *sr = new(mr.get_address())ServerReady();
std::string comm = std::string(SERVER_NAME) + " " + portc + " > server_log.txt";
boost::thread servthr(boost::bind(system,comm.c_str())); //runs server executable; //TODO: will it work on non-windows platforms?
char portc[10];
SDL_itoa(conf.cc.port,portc,10);
CClient::runServer(portc);
tlog0<<"Preparing shared memory and starting server: "<<tmh.getDif()<<std::endl;
///////////////////////////////////////////////////////////////////////////////////////
tmh.getDif();pomtime.getDif();//reset timers
cgi->pathf = new CPathfinder();
tlog0<<"\tPathfinder: "<<pomtime.getDif()<<std::endl;
tlog0<<"Handlers initialization (together): "<<tmh.getDif()<<std::endl;
std::ofstream logs("client_log.txt");
CConnection *c=NULL;
//wait until server is ready
tlog0<<"Waiting for server... ";
{
intpr::scoped_lock<intpr::interprocess_mutex> slock(sr->mutex);
while(!sr->ready)
{
sr->cond.wait(slock);
}
}
intpr::shared_memory_object::remove("vcmi_memory");
CClient::waitForServer();
tlog0 << tmh.getDif()<<std::endl;
while(!c)
{
try
{
tlog0 << "Establishing connection...\n";
c = new CConnection(conf.cc.server,portc,NAME,logs);
c = new CConnection(conf.cc.server,portc,NAME);
}
catch(...)
{
@ -195,9 +169,19 @@ int main(int argc, char** argv)
}
}
THC tlog0<<"\tConnecting to the server: "<<tmh.getDif()<<std::endl;
CClient cl(c,options);
cl.newGame(c,options);
client = &cl;
boost::thread t(boost::bind(&CClient::run,&cl));
}
else //load game
{
std::string fname = options->mapname;
boost::algorithm::erase_last(fname,".vlgm1");
cl.load(fname);
client = &cl;
boost::thread t(boost::bind(&CClient::run,&cl));
}
SDL_Event ev;
while(1) //main SDL events loop
{
@ -275,6 +259,12 @@ void processCommand(const std::string &message, CClient *&client)
readed >> fname;
client->save(fname);
}
else if(cn=="load")
{
std::string fname;
readed >> fname;
client->load(fname);
}
else if(message=="get txt")
{
boost::filesystem::create_directory("Extracted_txts");

View File

@ -646,9 +646,9 @@ void SComponent::init(Etype Type, int Subtype, int Val)
oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->generaltexth->primarySkillNames[Subtype];
subtitle = oss.str();
break;
case secskill44:
subtitle += CGI->abilh->levels[Val-1] + " " + CGI->abilh->abilities[Subtype]->name;
description = CGI->abilh->abilities[Subtype]->infoTexts[Val-1];
case secskill44: case secskill:
subtitle += CGI->generaltexth->levels[Val-1] + " " + CGI->generaltexth->skillName[Subtype];
description = CGI->generaltexth->skillInfoTexts[Subtype][Val-1];
break;
case resource:
description = CGI->generaltexth->allTexts[242];

View File

@ -20,6 +20,7 @@
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <cstdlib>
#include "lib/Connection.h"
extern SDL_Surface * screen;
extern SDL_Color tytulowy, tlo, zwykly ;
@ -811,12 +812,10 @@ void Options::hide()
MapSel::~MapSel()
{
SDL_FreeSurface(bg);
for (size_t i=0; i < scenImgs.size(); ++i) {
for (size_t i=0; i < scenImgs.size(); ++i)
{
SDL_FreeSurface(scenImgs[i]);
}
for (size_t i=0; i < scenList.size(); ++i) {
delete scenList[i];
}
delete sFlags;
}
int MapSel::countWL()
@ -838,9 +837,9 @@ void MapSel::printMaps(int from, int to, int at, bool abs)
if (true)//
{
int help=-1;
for (size_t i=0; i < ourMaps.size(); ++i)
for (size_t i=0; i < curVector().size(); ++i)
{
if (sizeFilter && ((ourMaps[i].width) != sizeFilter)) {
if (sizeFilter && ((curVector()[i].width) != sizeFilter)) {
continue;
}
else {
@ -857,7 +856,7 @@ void MapSel::printMaps(int from, int to, int at, bool abs)
SDL_Color nasz;
for (int i=at;i<to;i++)
{
if ((i-at+from) > ourMaps.size()-1)
if ((i-at+from) > curVector().size()-1)
{
SDL_Surface * scenin = CSDL_Ext::newSurface(351,25);
SDL_BlitSurface(bg,&genRect(25,351,22,(i-at)*25+115),scenin,NULL);
@ -867,12 +866,12 @@ void MapSel::printMaps(int from, int to, int at, bool abs)
SDL_FreeSurface(scenin);
continue;
}
if (sizeFilter && ((ourMaps[(i-at)+from].width) != sizeFilter))
if (sizeFilter && ((curVector()[(i-at)+from].width) != sizeFilter))
{
to++;
at++;
from++;
if (((i-at)+from)>ourMaps.size()-1) break;
if (((i-at)+from)>curVector().size()-1) break;
else continue;
}
if ((i-at+from) == selected)
@ -881,10 +880,10 @@ void MapSel::printMaps(int from, int to, int at, bool abs)
//SDL_Rect pier = genRect(25,351,24,126+(i*25));
SDL_BlitSurface(bg,&genRect(25,351,22,(i-at)*25+115),scenin,NULL);
int temp=-1;
std::ostringstream ostr(std::ostringstream::out); ostr << ourMaps[(i-at)+from].playerAmnt << "/" << ourMaps[(i-at)+from].humenPlayers;
std::ostringstream ostr(std::ostringstream::out); ostr << curVector()[(i-at)+from].playerAmnt << "/" << curVector()[(i-at)+from].humenPlayers;
CSDL_Ext::printAt(ostr.str(),6,4,GEOR13,nasz,scenin, 2);
std::string temp2;
switch (ourMaps[(i-at)+from].width)
switch (curVector()[(i-at)+from].width)
{
case 36:
temp2="S";
@ -903,7 +902,7 @@ void MapSel::printMaps(int from, int to, int at, bool abs)
break;
}
CSDL_Ext::printAtMiddle(temp2,50,13,GEOR13,nasz,scenin, 2);
switch (ourMaps[(i-at)+from].version)
switch (curVector()[(i-at)+from].version)
{
case RoE:
temp=0;
@ -918,21 +917,32 @@ void MapSel::printMaps(int from, int to, int at, bool abs)
temp=3;
break;
}
if (temp >= 0)
blitAt(Dtypes->ourImages[temp].bitmap,67,2,scenin);
if (!(ourMaps[(i-at)+from].name.length()))
ourMaps[(i-at)+from].name = "Unnamed";
CSDL_Ext::printAtMiddle(ourMaps[(i-at)+from].name,192,13,GEOR13,nasz,scenin, 2);
if (ourMaps[(i-at)+from].victoryCondition.condition == winStandard)
else
tlog2 << "Warning: " << curVector()[(i-at)+from].filename << " has wrong version!\n";
if(CPG->fromnewgame)
{
if (!(curVector()[(i-at)+from].name.length()))
curVector()[(i-at)+from].name = "Unnamed";
CSDL_Ext::printAtMiddle(curVector()[(i-at)+from].name,192,13,GEOR13,nasz,scenin, 2);
}
else
{
CSDL_Ext::printAtMiddle(curVector()[(i-at)+from].filename,192,13,GEOR13,nasz,scenin, 2);
}
if (curVector()[(i-at)+from].victoryCondition.condition == winStandard)
temp=11;
else
temp=ourMaps[(i-at)+from].victoryCondition.condition;
temp=curVector()[(i-at)+from].victoryCondition.condition;
blitAt(Dvic->ourImages[temp].bitmap,285,2,scenin);
if (ourMaps[(i-at)+from].lossCondition.typeOfLossCon == lossStandard)
if (curVector()[(i-at)+from].lossCondition.typeOfLossCon == lossStandard)
temp=3;
else
temp=ourMaps[(i-at)+from].lossCondition.typeOfLossCon;
temp=curVector()[(i-at)+from].lossCondition.typeOfLossCon;
blitAt(Dloss->ourImages[temp].bitmap,318,2,scenin);
@ -944,9 +954,9 @@ void MapSel::printMaps(int from, int to, int at, bool abs)
int MapSel::whichWL(int nr)
{
int help=-1;
for (int i=0;i<ourMaps.size();i++)
for (int i=0;i<curVector().size();i++)
{
if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
if (sizeFilter && ((curVector()[i].width) != sizeFilter))
continue;
else help++;
if (help==nr)
@ -1055,6 +1065,19 @@ void MapSel::processMaps(std::vector<std::string> &pliczkiTemp, int &index)
}
}
void MapSel::processGames( std::vector<std::string> &pliczkiTemp, int &index )
{
ourGames.resize(pliczkiTemp.size());
for(int i=0; i<pliczkiTemp.size(); i++)
{
CLoadFile lf(pliczkiTemp[i]);
ui8 sign[8];
lf >> sign >> static_cast<CMapHeader&>(ourGames[i]);
ourGames[i].filename = pliczkiTemp[i];
ourGames[i].countPlayers();
}
}
void MapSel::init()
{
//get map files names
@ -1146,16 +1169,29 @@ void MapSel::init()
std::sort(ourMaps.begin(),ourMaps.end(),mapSorter(_name));
slid = new Slider(375,92,480,ourMaps.size(),18,true);
slid->fun = boost::bind(&CPreGame::printMapsFrom,CPG,_1);
group.join_all();
pliczkiTemp.clear();
tie = fs::path( (fs::initial_path<fs::path>())/"/Games" );
for ( fs::directory_iterator dir (tie); dir!=end_iter; ++dir )
{
if (fs::is_regular_file(dir->status()));
{
if (boost::ends_with(dir->path().filename(),".vlgm1"))
pliczkiTemp.push_back("Games/"+(dir->path().leaf()));
}
}
processGames(pliczkiTemp,mapInd);
}
void MapSel::moveByOne(bool up)
{
int help=selected;
if (up) selected--;
else selected ++;
for (int i=selected;i<ourMaps.size() && i>=0;)
for (int i=selected;i<curVector().size() && i>=0;)
{
help=i;
if (!(sizeFilter && ((ourMaps[i].width) != sizeFilter)))
if (!(sizeFilter && ((curVector()[i].width) != sizeFilter)))
break;
if (up)
{
@ -1172,9 +1208,11 @@ void MapSel::moveByOne(bool up)
}
void MapSel::select(int which, bool updateMapsList, bool forceSettingsUpdate)
{
if(which < 0)
return;
bool dontSaveSettings = ((selected!=which) || (CPG->ret.playerInfos.size()==0) || forceSettingsUpdate);
selected = which;
CPG->ret.mapname = ourMaps[selected].filename;
CPG->ret.mapname = curVector()[selected].filename;
if(updateMapsList)
printMaps(slid->whereAreWe,18,0,true);
int serialC=0;
@ -1184,7 +1222,9 @@ void MapSel::select(int which, bool updateMapsList, bool forceSettingsUpdate)
bool wasntpl = true;
for (int i=0;i<PLAYER_LIMIT;i++)
{
if (!(ourMaps[selected].players[i].canComputerPlay || ourMaps[selected].players[i].canComputerPlay))
if (!(curVector()[selected].players[i].canComputerPlay
|| curVector()[selected].players[i].canComputerPlay)
)
continue; // this caused some serious problems becouse of lack of simple bijection between two sets of player's numbers (one is returned by CPreGame, second is used in h3m)
StartInfo::PlayerSettings pset;
pset.color=(Ecolor)i;
@ -1193,7 +1233,7 @@ void MapSel::select(int which, bool updateMapsList, bool forceSettingsUpdate)
pset.bonus=brandom;
pset.castle=-2;
if (ourMaps[which].players[i].canHumanPlay && wasntpl)
if (curVector()[which].players[i].canHumanPlay && wasntpl)
{
pset.name=CGI->generaltexth->allTexts[434]; //Player
pset.human = true;
@ -1211,7 +1251,7 @@ void MapSel::select(int which, bool updateMapsList, bool forceSettingsUpdate)
for (int j=0;j<F_NUMBER;j++)
{
if (((int)pow((double)2,j))&ourMaps[selected].players[i].allowedFactions)
if (((int)pow((double)2,j))&curVector()[selected].players[i].allowedFactions)
{
if (pset.castle>=0)
pset.castle=-1;
@ -1220,16 +1260,20 @@ void MapSel::select(int which, bool updateMapsList, bool forceSettingsUpdate)
}
}
pset.heroPortrait=-1;
if (!((ourMaps[which].players[i].generateHeroAtMainTown && ourMaps[which].players[i].hasMainTown) || ourMaps[which].players[i].p8))
if (!
((curVector()[which].players[i].generateHeroAtMainTown
&& curVector()[which].players[i].hasMainTown)
|| curVector()[which].players[i].p8)
)
pset.hero=-2;
else
pset.hero=-1;
if(ourMaps[which].players[i].mainHeroName.length())
if(curVector()[which].players[i].mainHeroName.length())
{
pset.heroName = ourMaps[which].players[i].mainHeroName;
if((pset.heroPortrait = ourMaps[which].players[i].mainHeroPortrait)==255)
pset.heroPortrait = ourMaps[which].players[i].p9;
pset.heroName = curVector()[which].players[i].mainHeroName;
if((pset.heroPortrait = curVector()[which].players[i].mainHeroPortrait)==255)
pset.heroPortrait = curVector()[which].players[i].p9;
}
pset.handicap=0;
CPG->ret.playerInfos.push_back(pset);
@ -1245,9 +1289,12 @@ void MapSel::printSelectedInfo()
{
SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(399,337,17,23),screen,&genRect(399,337,413,29));
SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(50,91,18,447),screen,&genRect(50,91,414,453));
if(CPG->fromnewgame)
{
SDL_BlitSurface(CPG->ourScenSel->bScens.imgs->ourImages[0].bitmap,NULL,screen,&CPG->ourScenSel->bScens.pos);
SDL_BlitSurface(CPG->ourScenSel->bOptions.imgs->ourImages[0].bitmap,NULL,screen,&CPG->ourScenSel->bOptions.pos);
SDL_BlitSurface(CPG->ourScenSel->bRandom.imgs->ourImages[0].bitmap,NULL,screen,&CPG->ourScenSel->bRandom.pos);
}
//blit texts
CSDL_Ext::printAt(CGI->generaltexth->zelp[21].second,420,25,GEOR13);
CSDL_Ext::printAt(CGI->generaltexth->allTexts[496],420,135,GEOR13);
@ -1256,30 +1303,32 @@ void MapSel::printSelectedInfo()
CSDL_Ext::printAt(CGI->generaltexth->allTexts[390],420,406,GEOR13,zwykly);
CSDL_Ext::printAt(CGI->generaltexth->allTexts[391],585,406,GEOR13,zwykly);
int temp = ourMaps[selected].victoryCondition.condition+1;
CMapInfo &selMap = selectedMap();
int temp = selMap.victoryCondition.condition+1;
if (temp>20) temp=0;
std::string sss = CGI->generaltexth->victoryConditions[temp];
if (temp && ourMaps[selected].victoryCondition.allowNormalVictory) sss+= "/" + CGI->generaltexth->victoryConditions[0];
if (temp && selMap.victoryCondition.allowNormalVictory) sss+= "/" + CGI->generaltexth->victoryConditions[0];
CSDL_Ext::printAt(sss,452,310,GEOR13,zwykly);
temp = ourMaps[selected].lossCondition.typeOfLossCon+1;
temp = selMap.lossCondition.typeOfLossCon+1;
if (temp>20) temp=0;
sss = CGI->generaltexth->lossCondtions[temp];
CSDL_Ext::printAt(sss,452,370,GEOR13,zwykly);
//blit descrption
std::vector<std::string> desc = *CMessage::breakText(ourMaps[selected].description,50);
std::vector<std::string> desc = *CMessage::breakText(selMap.description,50);
for (int i=0;i<desc.size();i++)
CSDL_Ext::printAt(desc[i],417,152+i*13,GEOR13,zwykly);
if ((selected < 0) || (selected >= ourMaps.size()))
return;
if (ourMaps[selected].name.length())
CSDL_Ext::printAt(ourMaps[selected].name,420,41,GEORXX);
if (selMap.name.length())
CSDL_Ext::printAt(selMap.name,420,41,GEORXX);
else CSDL_Ext::printAt("Unnamed",420,41,GEORXX);
std::string diff;
switch (ourMaps[selected].difficulty)
switch (selMap.difficulty)
{
case 0:
diff=gdiff(CGI->generaltexth->zelp[24].second);
@ -1298,7 +1347,7 @@ void MapSel::printSelectedInfo()
break;
}
temp=-1;
switch (ourMaps[selected].width)
switch (selMap.width)
{
case 36:
temp=0;
@ -1317,10 +1366,10 @@ void MapSel::printSelectedInfo()
break;
}
blitAt(Dsizes->ourImages[temp].bitmap,714,28);
temp = ourMaps[selected].victoryCondition.condition;
temp = selMap.victoryCondition.condition;
if (temp>12) temp=11;
blitAt(Dvic->ourImages[temp].bitmap,420,308); //v
temp=ourMaps[selected].lossCondition.typeOfLossCon;
temp=selMap.lossCondition.typeOfLossCon;
if (temp>12) temp=3;
blitAt(Dloss->ourImages[temp].bitmap,420,366); //l
@ -1331,15 +1380,16 @@ void MapSel::printSelectedInfo()
}
void MapSel::printFlags()
{
CMapInfo &selMap = selectedMap();
int hy=405, fx=460, ex=640, myT;
if (ourMaps[selected].howManyTeams)
myT = ourMaps[selected].players[CPG->playerColor].team;
if (selMap.howManyTeams)
myT = selMap.players[CPG->playerColor].team;
else myT = -1;
for (int i=0;i<CPG->ret.playerInfos.size();i++)
{
if (myT>=0)
{
if(ourMaps[selected].players[CPG->ret.playerInfos[i].color].team==myT)
if(selMap.players[CPG->ret.playerInfos[i].color].team==myT)
{
blitAtWR(sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap,fx,hy);
fx+=sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap->w;
@ -1376,6 +1426,23 @@ std::string MapSel::gdiff(std::string ss)
}
return ret;
}
CMapInfo & MapSel::selectedMap()
{
if(CPG->fromnewgame)
return ourMaps[selected];
else
return ourGames[selected];
}
std::vector<CMapInfo> & MapSel::curVector()
{
if (CPG->fromnewgame)
return ourMaps;
else
return ourGames;
}
void CPreGame::printRating()
{
SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(47,83,271,449),screen,&genRect(47,83,666,455));
@ -1460,6 +1527,7 @@ void CPreGame::initScenSel()
void CPreGame::showScenSel()
{
state=ScenarioList;
ourScenSel->mapsel.slid->positionsAmnt = ourScenSel->mapsel.curVector().size();
SDL_BlitSurface(ourScenSel->background,NULL,screen,NULL);
SDL_BlitSurface(ourScenSel->scenInf,NULL,screen,&genRect(ourScenSel->scenInf->h,ourScenSel->scenInf->w,396,6));
CSDL_Ext::printAt(CGI->generaltexth->allTexts[494],427,438,GEOR13);//"Map Diff:"
@ -1481,6 +1549,8 @@ void CPreGame::showScenSel()
//add buttons info
if(first)
{
if(fromnewgame)
{
btns.push_back(&ourScenSel->bEasy);
btns.push_back(&ourScenSel->bNormal);
@ -1490,6 +1560,9 @@ void CPreGame::showScenSel()
btns.push_back(&ourScenSel->bScens);
btns.push_back(&ourScenSel->bRandom);
btns.push_back(&ourScenSel->bOptions);
}
else
ourScenSel->mapsel.show();
btns.push_back(&ourScenSel->bBegin);
btns.push_back(&ourScenSel->bBack);
@ -1583,12 +1656,18 @@ void CPreGame::initNewMenu()
}
void CPreGame::showNewMenu()
{
if(state == ScenarioList && !fromnewgame)
{
showLoadMenu();
return;
}
if (currentTab/*==&ourScenSel->mapsel*/)
currentTab->hide();
btns.clear();
interested.clear();
handleOther=NULL;
state = newGame;
fromnewgame = true;
SDL_BlitSurface(ourNewMenu->background,NULL,screen,NULL);
SDL_BlitSurface(ourNewMenu->newGame->ourImages[0].bitmap,NULL,screen,&ourNewMenu->lNewGame);
SDL_BlitSurface(ourNewMenu->loadGame->ourImages[0].bitmap,NULL,screen,&ourNewMenu->lLoadGame);
@ -2120,6 +2199,7 @@ StartInfo CPreGame::runLoop()
CGI->curh->draw2();
SDL_Delay(20); //give time for other apps
}
ret.mode = !fromnewgame;
return ret;
}
std::string CPreGame::buttonText(int which)
@ -2233,6 +2313,7 @@ void CPreGame::showLoadMenu()
interested.clear();
handleOther=NULL;
state = loadGame;
fromnewgame = false;
SDL_BlitSurface(ourLoadMenu->background,NULL,screen,NULL);
SDL_BlitSurface(ourLoadMenu->newGame->ourImages[0].bitmap,NULL,screen,&ourLoadMenu->lNewGame);
SDL_BlitSurface(ourLoadMenu->loadGame->ourImages[0].bitmap,NULL,screen,&ourLoadMenu->lLoadGame);

View File

@ -187,7 +187,6 @@ public:
CDefHandler * Dtypes, * Dvic;
CDefHandler *Dsizes, * Dloss,
* sFlags;
std::vector<Mapa*> scenList;
std::vector<SDL_Surface*> scenImgs;
//int current;
std::vector<CMapInfo> ourMaps;
@ -208,6 +207,9 @@ public:
void printSelectedInfo();
void printFlags();
void processMaps(std::vector<std::string> &pliczkiTemp, int &index);
void processGames(std::vector<std::string> &pliczkiTemp, int &index);
CMapInfo &selectedMap();
std::vector<CMapInfo> &curVector();
MapSel();
~MapSel();
};
@ -241,6 +243,7 @@ public:
StartInfo ret;
bool run;
bool first; //hasn't we showed the scensel
bool fromnewgame;
std::vector<Slider *> interested;
CMusicHandler * mush;
std::vector<HighButton *> btns;

View File

@ -1,4 +1,4 @@
0.64 -> 0.next (???) [as for r672]
0.64 -> 0.next (???) [as for r679]
GENERAL:
* move some settings to the config/settings.txt file
* partial support for new screen resolutions
@ -7,6 +7,7 @@ GENERAL:
* support for non-standard screen resolutions
ADVENTURE INTERFACE:
* smooth map scrolling on hero movement
* added water animation
* speed of scrolling map and hero movement can be adjusted in the System Options Window
@ -44,6 +45,11 @@ BATTLES
AI PLAYER:
* Genius AI (first VCMI AI) will control computer creatures during the combat.
OBJECTS:
* Guardians property for resources is handled
* support for Witch Hut
* support for Arena
And a lot of minor fixes
0.63 -> 0.64 (Nov 01 2008)

View File

@ -18,7 +18,7 @@ struct StartInfo
ui8 serial;
ui8 handicap;//0-no, 1-mild, 2-severe
std::string name;
bool human;
ui8 human;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & castle;
@ -33,6 +33,7 @@ struct StartInfo
h & human;
}
};
ui8 mode; //0 - new game; 1 - load game
si32 difficulty; //0=easy; 4=impossible
std::vector<PlayerSettings> playerInfos;
ui8 turnTime; //in minutes, 0=unlimited
@ -48,6 +49,7 @@ struct StartInfo
}
template <typename Handler> void serialize(Handler &h, const int version)
{
h & mode;
h & difficulty;
h & playerInfos;
h & turnTime;

View File

@ -5,9 +5,15 @@
#include "../CPlayerInterface.h"
#include "../StartInfo.h"
#include "../hch/CArtHandler.h"
#include "../hch/CDefObjInfoHandler.h"
#include "../hch/CGeneralTextHandler.h"
#include "../hch/CHeroHandler.h"
#include "../hch/CTownHandler.h"
#include "../hch/CObjectHandler.h"
#include "../hch/CBuildingHandler.h"
#include "../hch/CSpellHandler.h"
#include "../lib/Connection.h"
#include "../lib/Interprocess.h"
#include "../lib/NetPacks.h"
#include "../lib/VCMI_Lib.h"
#include "../map.h"
@ -20,75 +26,19 @@
#include <boost/thread/shared_mutex.hpp>
#include <sstream>
CSharedCond<std::set<IPack*> > mess(new std::set<IPack*>);
extern std::string NAME;
namespace intpr = boost::interprocess;
SharedMem sm;
CClient::CClient(void)
{
serv = NULL;
gs = NULL;
cb = NULL;
}
CClient::CClient(CConnection *con, StartInfo *si)
:serv(con)
{
timeHandler tmh;
IObjectInterface::cb = this;
CGI->state = new CGameState();
tlog0 <<"\tGamestate: "<<tmh.getDif()<<std::endl;
CConnection &c(*con);
////////////////////////////////////////////////////
ui8 pom8;
c << ui8(2) << ui8(1); //new game; one client
c << *si;
c >> pom8;
if(pom8) throw "Server cannot open the map!";
c << ui8(si->playerInfos.size()+1); //number of players + neutral
for(size_t i=0;i<si->playerInfos.size();i++) {
c << ui8(si->playerInfos[i].color); //players
}
c << ui8(255); // neutrals
ui32 seed, sum;
std::string mapname;
c >> mapname >> sum >> seed;
tlog0 <<"\tSending/Getting info to/from the server: "<<tmh.getDif()<<std::endl;
Mapa * mapa = new Mapa(mapname);
tlog0 <<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl;
tlog0 << "\tServer checksum for "<<mapname <<": "<<sum << std::endl;
tlog0 << "\tOur checksum for the map: "<< mapa->checksum << std::endl;
if(mapa->checksum != sum)
{
tlog1 << "Wrong map checksum!!!" << std::endl;
throw std::string("Wrong checksum");
}
tlog0 << "\tUsing random seed: "<<seed << std::endl;
gs = CGI->state;
gs->scenarioOps = si;
gs->init(si,mapa,seed);
CGI->mh = new CMapHandler();
tlog0 <<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
CGI->mh->map = mapa;
tlog0 <<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
CGI->mh->init();
tlog0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
for (size_t i=0; i<CGI->state->scenarioOps->playerInfos.size();++i) //initializing interfaces for players
{
ui8 color = gs->scenarioOps->playerInfos[i].color;
CCallback *cb = new CCallback(gs,color,this);
if(!gs->scenarioOps->playerInfos[i].human) {
playerint[color] = static_cast<CGameInterface*>(CAIHandler::getNewAI(cb,conf.cc.defaultAI));
}
else {
playerint[color] = new CPlayerInterface(color,i);
}
gs->currentPlayer = color;
playerint[color]->init(cb);
}
playerint[255] = CAIHandler::getNewAI(cb,conf.cc.defaultAI);
playerint[255]->init(new CCallback(gs,255,this));
newGame(con,si);
}
CClient::~CClient(void)
{
@ -634,10 +584,13 @@ void CClient::run()
void CClient::close()
{
if(!serv)
return;
tlog3 << "Connection has been requested to be closed.\n";
boost::unique_lock<boost::mutex>(*serv->wmx);
*serv << ui16(99);
tlog3 << "Sended closing signal to the server\n";
tlog3 << "Sent closing signal to the server\n";
serv->close();
tlog3 << "Our socket has been closed.\n";
}
@ -647,6 +600,96 @@ void CClient::save(const std::string & fname)
*serv << ui16(98) << fname;
}
void CClient::load( const std::string & fname )
{
tlog0 <<"\n\nLoading procedure started!\n\n";
timeHandler tmh;
close(); //kill server
tlog0 <<"Sent kill signal to the server: "<<tmh.getDif()<<std::endl;
VLC->clear(); //delete old handlers
delete CGI->mh;
delete CGI->state;
//TODO: del callbacks
for(std::map<ui8,CGameInterface *>::iterator i = playerint.begin(); i!=playerint.end(); i++)
{
delete i->second; //delete player interfaces
}
tlog0 <<"Deleting old data: "<<tmh.getDif()<<std::endl;
char portc[10];
SDL_itoa(conf.cc.port,portc,10);
runServer(portc); //create new server
tlog0 <<"Restarting server: "<<tmh.getDif()<<std::endl;
{
char sig[8];
CMapHeader dum;
CGI->mh = new CMapHandler();
CLoadFile lf(fname + ".vlgm1");
lf >> sig >> dum;
tlog0 <<"Reading save signature: "<<tmh.getDif()<<std::endl;
lf >> *VLC;
CGI->setFromLib();
tlog0 <<"Reading handlers: "<<tmh.getDif()<<std::endl;
lf >> gs;
tlog0 <<"Reading gamestate: "<<tmh.getDif()<<std::endl;
CGI->state = gs;
CGI->mh->map = gs->map;
CGI->mh->init();
tlog0 <<"Initing maphandler: "<<tmh.getDif()<<std::endl;
}
waitForServer();
tlog0 <<"Waiting for server: "<<tmh.getDif()<<std::endl;
serv = new CConnection(conf.cc.server,portc,NAME);
tlog0 <<"Setting up connection: "<<tmh.getDif()<<std::endl;
ui8 pom8;
*serv << ui8(3) << ui8(1); //load game; one client
*serv << fname;
*serv >> pom8;
if(pom8)
throw "Server cannot open the savegame!";
else
tlog0 << "Server opened savegame properly.\n";
*serv << ui8(gs->scenarioOps->playerInfos.size()+1); //number of players + neutral
for(size_t i=0;i<gs->scenarioOps->playerInfos.size();i++)
{
*serv << ui8(gs->scenarioOps->playerInfos[i].color); //players
}
*serv << ui8(255); // neutrals
tlog0 <<"Sent info to server: "<<tmh.getDif()<<std::endl;
for (size_t i=0; i<gs->scenarioOps->playerInfos.size();++i) //initializing interfaces for players
{
ui8 color = gs->scenarioOps->playerInfos[i].color;
CCallback *cb = new CCallback(gs,color,this);
if(!gs->scenarioOps->playerInfos[i].human) {
playerint[color] = static_cast<CGameInterface*>(CAIHandler::getNewAI(cb,conf.cc.defaultAI));
}
else {
playerint[color] = new CPlayerInterface(color,i);
}
gs->currentPlayer = color;
playerint[color]->init(cb);
tlog0 <<"Setting up interface for player "<< (int)color <<": "<<tmh.getDif()<<std::endl;
}
playerint[255] = CAIHandler::getNewAI(cb,conf.cc.defaultAI);
playerint[255]->init(new CCallback(gs,255,this));
tlog0 <<"Setting up interface for neutral \"player\"" << tmh.getDif() << std::endl;
}
int CClient::getCurrentPlayer()
{
return gs->currentPlayer;
@ -656,3 +699,91 @@ int CClient::getSelectedHero()
{
return IGameCallback::getSelectedHero(getCurrentPlayer())->id;
}
void CClient::newGame( CConnection *con, StartInfo *si )
{
timeHandler tmh;
IObjectInterface::cb = this;
CGI->state = new CGameState();
tlog0 <<"\tGamestate: "<<tmh.getDif()<<std::endl;
serv = con;
CConnection &c(*con);
////////////////////////////////////////////////////
ui8 pom8;
c << ui8(2) << ui8(1); //new game; one client
c << *si;
c >> pom8;
if(pom8)
throw "Server cannot open the map!";
else
tlog0 << "Server opened map properly.\n";
c << ui8(si->playerInfos.size()+1); //number of players + neutral
for(size_t i=0;i<si->playerInfos.size();i++)
{
c << ui8(si->playerInfos[i].color); //players
}
c << ui8(255); // neutrals
ui32 seed, sum;
std::string mapname;
c >> mapname >> sum >> seed;
tlog0 <<"\tSending/Getting info to/from the server: "<<tmh.getDif()<<std::endl;
Mapa * mapa = new Mapa(mapname);
tlog0 <<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl;
tlog0 << "\tServer checksum for "<<mapname <<": "<<sum << std::endl;
tlog0 << "\tOur checksum for the map: "<< mapa->checksum << std::endl;
if(mapa->checksum != sum)
{
tlog1 << "Wrong map checksum!!!" << std::endl;
throw std::string("Wrong checksum");
}
tlog0 << "\tUsing random seed: "<<seed << std::endl;
gs = CGI->state;
gs->scenarioOps = si;
gs->init(si,mapa,seed);
CGI->mh = new CMapHandler();
tlog0 <<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
CGI->mh->map = mapa;
tlog0 <<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
CGI->mh->init();
tlog0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
for (size_t i=0; i<CGI->state->scenarioOps->playerInfos.size();++i) //initializing interfaces for players
{
ui8 color = gs->scenarioOps->playerInfos[i].color;
CCallback *cb = new CCallback(gs,color,this);
if(!gs->scenarioOps->playerInfos[i].human) {
playerint[color] = static_cast<CGameInterface*>(CAIHandler::getNewAI(cb,conf.cc.defaultAI));
}
else {
playerint[color] = new CPlayerInterface(color,i);
}
gs->currentPlayer = color;
playerint[color]->init(cb);
}
playerint[255] = CAIHandler::getNewAI(cb,conf.cc.defaultAI);
playerint[255]->init(new CCallback(gs,255,this));
}
void CClient::runServer(const char * portc)
{
static std::string comm = std::string(SERVER_NAME) + " " + portc + " > server_log.txt"; //needs to be static, if not - will be probably destroyed before new thread reads it
boost::thread servthr(boost::bind(system,comm.c_str())); //runs server executable; //TODO: will it work on non-windows platforms?
}
void CClient::waitForServer()
{
{
intpr::scoped_lock<intpr::interprocess_mutex> slock(sm.sr->mutex);
while(!sm.sr->ready)
{
sm.sr->cond.wait(slock);
}
}
intpr::shared_memory_object::remove("vcmi_memory");
}

View File

@ -51,7 +51,9 @@ public:
~CClient(void);
void close();
void newGame(CConnection *con, StartInfo *si); //con - connection to server
void save(const std::string & fname);
void load(const std::string & fname);
void process(int what);
void run();
//////////////////////////////////////////////////////////////////////////
@ -67,6 +69,7 @@ public:
void setHoverName(int objid, MetaString * name){};
void setObjProperty(int objid, int prop, int val){};
void changePrimSkill(int ID, int which, int val, bool abs=false){};
void changeSecSkill(int ID, int which, int val, bool abs=false){};
void showInfoDialog(InfoWindow *iw){};
void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback){};
void showSelectionDialog(SelectionDialog *iw, const CFunctionList<void(ui32)> &callback){}; //returns question id
@ -82,6 +85,10 @@ public:
//////////////////////////////////////////////////////////////////////////
friend class CCallback; //handling players actions
friend void processCommand(const std::string &message, CClient *&client); //handling console
static void runServer(const char * portc);
static void waitForServer();
};
#endif // __CLIENT_H__

View File

@ -275,31 +275,32 @@ void Graphics::loadHeroPortraits()
}
of.close();
}
void Graphics::loadHeroAnim(std::vector<CDefHandler **> & anims)
void Graphics::loadHeroAnim()
{
heroAnims.resize(F_NUMBER * 2);
std::vector<std::pair<int,int> > rotations; //first - group number to be rotated1, second - group number after rotation1
rotations += std::make_pair(6,10), std::make_pair(7,11), std::make_pair(8,12), std::make_pair(1,13),
std::make_pair(2,14), std::make_pair(3,15);
for(size_t i=0; i<anims.size(); ++i)
for(size_t i=0; i<heroAnims.size(); ++i)
{
std::stringstream nm;
nm << "AH" << std::setw(2) << std::setfill('0') << i << "_.DEF";
std::string name = nm.str();
(*anims[i]) = CDefHandler::giveDef(name);
heroAnims[i] = CDefHandler::giveDef(name);
int pom = 0; //how many groups has been rotated
for(int o=7; pom<6; ++o)
{
for(int p=0;p<6;p++)
{
if((*anims[i])->ourImages[o].groupNumber==rotations[p].first)
if(heroAnims[i]->ourImages[o].groupNumber==rotations[p].first)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o+e].bitmap);
nci.bitmap = CSDL_Ext::rotate01(heroAnims[i]->ourImages[o+e].bitmap);
nci.groupNumber = rotations[p].second;
nci.imName = std::string();
(*anims[i])->ourImages.push_back(nci);
heroAnims[i]->ourImages.push_back(nci);
if(pom>2) //we need only one frame for groups 13/14/15
break;
}
@ -313,11 +314,11 @@ void Graphics::loadHeroAnim(std::vector<CDefHandler **> & anims)
}
}
}
for(size_t ff=0; ff<(*anims[i])->ourImages.size(); ++ff)
for(size_t ff=0; ff<heroAnims[i]->ourImages.size(); ++ff)
{
CSDL_Ext::alphaTransform((*anims[i])->ourImages[ff].bitmap);
CSDL_Ext::alphaTransform(heroAnims[i]->ourImages[ff].bitmap);
}
(*anims[i])->alphaTransformed = true;
heroAnims[i]->alphaTransformed = true;
}
}

View File

@ -36,6 +36,7 @@ public:
CDefHandler * un44; //many things
CDefHandler * smallIcons, *resources32; //resources 32x32
CDefHandler * flags;
std::vector<CDefHandler *> heroAnims; // [class id: 0 - 17] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
//creatures
std::map<int,SDL_Surface*> smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border
std::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border
@ -53,7 +54,7 @@ public:
void loadPaletteAndColors();
void loadHeroFlags();
void loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, std::vector<const char *> > &pr, bool mode);
void loadHeroAnim(std::vector<CDefHandler **> & anims);
void loadHeroAnim();
void loadHeroPortraits();
SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh);
SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS);

View File

@ -7,34 +7,8 @@
void CAbilityHandler::loadAbilities()
{
std::string buf = CGI->bitmaph->getTextFile("SSTRAITS.TXT");
int it=0;
std::string dump;
for(int i=0; i<2; ++i)
{
loadToIt(dump,buf,it,3);
}
for (int i=0; i<SKILL_QUANTITY; i++)
{
CAbility * nab = new CAbility; //new skill, that will be read
nab->infoTexts.resize(3);
loadToIt(nab->name,buf,it,4);
loadToIt(nab->infoTexts[0],buf,it,4);
loadToIt(nab->infoTexts[1],buf,it,4);
loadToIt(nab->infoTexts[2],buf,it,3);
nab->idNumber = abilities.size();
abilities.push_back(nab);
}
abils32 = CDefHandler::giveDef("SECSK32.DEF");
abils44 = CDefHandler::giveDef("SECSKILL.DEF");
abils82 = CDefHandler::giveDef("SECSK82.DEF");
buf = CGI->bitmaph->getTextFile("SKILLLEV.TXT");
it=0;
for(int i=0; i<6; ++i)
{
std::string buffo;
loadToIt(buffo,buf,it,3);
levels.push_back(buffo);
}
}

View File

@ -9,8 +9,6 @@ class CDefHandler;
class CAbility
{
public:
std::string name;
std::vector <std::string> infoTexts; //0 - basic; 2 - advanced
int idNumber;
bool isAllowed; //true if we can use this hero's ability (map information)
};
@ -20,7 +18,6 @@ class CAbilityHandler
public:
std::vector<CAbility *> abilities;
CDefHandler * abils32, * abils44, * abils82;
std::vector<std::string> levels;
void loadAbilities();
};

View File

@ -14,11 +14,8 @@ unsigned int readNr(std::string &in, int &it)
if(in[last]=='\t' || in[last]=='\n' || in[last]==' ' || in[last]=='\r' || in[last]=='\n')
break;
if(last==in.size())
#ifndef __GNUC__
throw new std::exception("Cannot read number...");
#else
throw new std::exception();
#endif
throw std::string("Cannot read number...");
std::stringstream ss(in.substr(it,last-it));
it+=(1+last-it);
ss >> last;
@ -131,6 +128,12 @@ void CBuildingHandler::loadBuildings()
}
CBuildingHandler::~CBuildingHandler()
{
for(std::map<int, std::map<int, CBuilding*> >::iterator i=buildings.begin(); i!=buildings.end(); i++)
for(std::map<int, CBuilding*>::iterator j=i->second.begin(); j!=i->second.end(); j++)
delete j->second;
}
const std::string & CBuilding::Name()
{
if(name.length())

View File

@ -28,6 +28,7 @@ public:
std::map<int, std::pair<std::string,std::vector< std::vector< std::vector<int> > > > > hall; //map<castle ID, pair<hall bg name, std::vector< std::vector<building id> >[5]> - external vector is the vector of buildings in the row, internal is the list of buildings for the specific slot
void loadBuildings(); //main loader
~CBuildingHandler();
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -629,3 +629,7 @@ void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int
}
i+=2;
}
CCreatureHandler::~CCreatureHandler()
{
}

View File

@ -67,6 +67,7 @@ public:
void loadAnimationInfo();
void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
CCreatureHandler();
~CCreatureHandler();
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -18,6 +18,7 @@ bool CGDefInfo::isVisitable()
}
CGDefInfo::CGDefInfo()
{
handler = NULL;
serial = -1;
visitDir = (8|16|32|64|128); //4,5,6,7,8 - any not-from-up direction
}
@ -77,3 +78,10 @@ void CDefObjInfoHandler::load()
castles[nobj->subid]=nobj;
}
}
CDefObjInfoHandler::~CDefObjInfoHandler()
{
for(std::map<int,std::map<int,CGDefInfo*> >::iterator i=gobjs.begin(); i!=gobjs.end(); i++)
for(std::map<int,CGDefInfo*>::iterator j=i->second.begin(); j!=i->second.end(); j++)
delete j->second;
}

View File

@ -41,8 +41,9 @@ class DLL_EXPORT CDefObjInfoHandler
public:
std::map<int,std::map<int,CGDefInfo*> > gobjs;
std::map<int,CGDefInfo*> castles;
void load();
void load();
~CDefObjInfoHandler();
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -16,88 +16,6 @@ std::string readTo(std::string &in, int &it, char end)
return in.substr(pom,last-pom);
}
void CGeneralTextHandler::load()
{
std::string buf = bitmaph->getTextFile("GENRLTXT.TXT"), tmp;
int andame = buf.size();
int i=0; //buf iterator
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
break;
}
i+=2;
std::string buflet;
for(int jj=0; jj<764; ++jj)
{
loadToIt(buflet, buf, i, 2);
if(buflet[0] == '"' && buflet[buflet.size()-1] == '"')
buflet = buflet.substr(1,buflet.size()-2);
allTexts.push_back(buflet);
}
std::string strs = bitmaph->getTextFile("ARRAYTXT.TXT");
int itr=0;
while(itr<strs.length()-1)
{
loadToIt(tmp, strs, itr, 3);
arraytxt.push_back(tmp);
}
itr = 0;
std::string strin = bitmaph->getTextFile("PRISKILL.TXT");
for(int hh=0; hh<4; ++hh)
{
loadToIt(tmp, strin, itr, 3);
primarySkillNames.push_back(tmp);
}
itr = 0;
std::string strin2 = bitmaph->getTextFile("JKTEXT.TXT");
for(int hh=0; hh<45; ++hh)
{
loadToIt(tmp, strin2, itr, 3);
jktexts.push_back(tmp);
}
itr = 0;
std::string strin3 = bitmaph->getTextFile("HEROSCRN.TXT");
for(int hh=0; hh<33; ++hh)
{
loadToIt(tmp, strin3, itr, 3);
heroscrn.push_back(tmp);
}
strin3 = bitmaph->getTextFile("ARTEVENT.TXT");
for(itr = 0; itr<strin3.size();itr++)
{
loadToIt(tmp, strin3, itr, 3);
artifEvents.push_back(tmp);
}
}
std::string CGeneralTextHandler::getTitle(std::string text)
{
std::string ret;
int i=0;
while ((text[i++]!='{'));
while ((text[i]!='}') && (i<text.length()))
ret+=text[i++];
return ret;
}
std::string CGeneralTextHandler::getDescr(std::string text)
{
std::string ret;
int i=0;
while ((text[i++]!='}'));
i+=2;
while ((text[i]!='"') && (i<text.length()))
ret+=text[i++];
return ret;
}
void CGeneralTextHandler::loadTexts()
{
std::string buf1 = bitmaph->getTextFile("ZELP.TXT");
int itr=0, eol=-1, eolnext=-1, pom;
@ -344,4 +262,115 @@ void CGeneralTextHandler::loadTexts()
loadToIt(temp,buf,it,3);
creGens.push_back(temp);
}
buf = bitmaph->getTextFile("GENRLTXT.TXT");
std::string tmp;
andame = buf.size();
i=0; //buf iterator
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
break;
}
i+=2;
std::string buflet;
for(int jj=0; jj<764; ++jj)
{
loadToIt(buflet, buf, i, 2);
if(buflet[0] == '"' && buflet[buflet.size()-1] == '"')
buflet = buflet.substr(1,buflet.size()-2);
allTexts.push_back(buflet);
}
std::string strs = bitmaph->getTextFile("ARRAYTXT.TXT");
itr=0;
while(itr<strs.length()-1)
{
loadToIt(tmp, strs, itr, 3);
arraytxt.push_back(tmp);
}
itr = 0;
std::string strin = bitmaph->getTextFile("PRISKILL.TXT");
for(int hh=0; hh<4; ++hh)
{
loadToIt(tmp, strin, itr, 3);
primarySkillNames.push_back(tmp);
}
itr = 0;
std::string strin2 = bitmaph->getTextFile("JKTEXT.TXT");
for(int hh=0; hh<45; ++hh)
{
loadToIt(tmp, strin2, itr, 3);
jktexts.push_back(tmp);
}
itr = 0;
std::string strin3 = bitmaph->getTextFile("HEROSCRN.TXT");
for(int hh=0; hh<33; ++hh)
{
loadToIt(tmp, strin3, itr, 3);
heroscrn.push_back(tmp);
}
strin3 = bitmaph->getTextFile("ARTEVENT.TXT");
for(itr = 0; itr<strin3.size();itr++)
{
loadToIt(tmp, strin3, itr, 3);
artifEvents.push_back(tmp);
}
buf = bitmaph->getTextFile("SSTRAITS.TXT");
it=0;
for(int i=0; i<2; ++i)
loadToIt(dump,buf,it,3);
skillName.resize(SKILL_QUANTITY);
skillInfoTexts.resize(SKILL_QUANTITY);
for (int i=0; i<SKILL_QUANTITY; i++)
{
skillInfoTexts[i].resize(3);
loadToIt(skillName[i],buf,it,4);
loadToIt(skillInfoTexts[i][0],buf,it,4);
loadToIt(skillInfoTexts[i][1],buf,it,4);
loadToIt(skillInfoTexts[i][2],buf,it,3);
}
buf = bitmaph->getTextFile("SKILLLEV.TXT");
it=0;
for(int i=0; i<6; ++i)
{
std::string buffo;
loadToIt(buffo,buf,it,3);
levels.push_back(buffo);
}
}
std::string CGeneralTextHandler::getTitle(std::string text)
{
std::string ret;
int i=0;
while ((text[i++]!='{'));
while ((text[i]!='}') && (i<text.length()))
ret+=text[i++];
return ret;
}
std::string CGeneralTextHandler::getDescr(std::string text)
{
std::string ret;
int i=0;
while ((text[i++]!='}'));
i+=2;
while ((text[i]!='"') && (i<text.length()))
ret+=text[i++];
return ret;
}
CGeneralTextHandler::CGeneralTextHandler()
{
}

View File

@ -46,12 +46,17 @@ public:
std::vector<std::string> restypes;
std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event description
//sec skills
std::vector <std::string> skillName;
std::vector <std::vector <std::string> > skillInfoTexts; //[id][level] : level 0 - basic; 2 - advanced
std::vector<std::string> levels;
std::string getTitle(std::string text);
std::string getDescr(std::string text);
void loadTexts();
void load();
CGeneralTextHandler();
};

View File

@ -10,7 +10,6 @@ void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
CHeroClass::CHeroClass()
{
skillLimit = 8;
moveAnim = NULL;
}
CHeroClass::~CHeroClass()
{
@ -35,7 +34,17 @@ int CHeroClass::chooseSecSkill(const std::set<int> & possibles) const //picks se
}
CHeroHandler::~CHeroHandler()
{
for (int i = 0; i < heroes.size(); i++)
delete heroes[i];
for (int i = 0; i < heroClasses.size(); i++)
delete heroClasses[i];
}
CHeroHandler::CHeroHandler()
{}
void CHeroHandler::loadHeroes()
{
VLC->heroh = this;

View File

@ -38,7 +38,6 @@ public:
std::vector<int> proSec; //probabilities of gaining secondary skills (out of 112), in id order
int selectionProbability[9]; //probability of selection in towns
std::vector<int> terrCosts; //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock; -1 means terrain is imapassable
CDefHandler * moveAnim; //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
int chooseSecSkill(const std::set<int> & possibles) const; //picks secondary skill out from given possibilities
CHeroClass();
@ -60,11 +59,13 @@ public:
unsigned int level(unsigned int experience);
unsigned int reqExp(unsigned int level);
void loadHeroes();
void loadHeroClasses();
void initHeroClasses();
~CHeroHandler();
void initTerrainCosts();
CHeroHandler();
~CHeroHandler();
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -743,7 +743,7 @@ void CGVisitableOPH::onHeroVisit( const CGHeroInstance * h ) const
if(visitors.find(h->id)==visitors.end())
{
onNAHeroVisit(h->id, false);
if(ID != 102) //not tree
if(ID != 102 && ID!=4) //not tree nor arena
cb->setObjProperty(id,4,h->id); //add to the visitors
}
else
@ -774,6 +774,9 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
int id=0, subid=0, ot=0, val=1;
switch(ID)
{
case 4:
ot = 0;
break;
case 51:
subid=0;
ot=80;
@ -806,6 +809,16 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
{
switch (ID)
{
case 4: //arena
{
SelectionDialog sd;
sd.text << std::pair<ui8,ui32>(11,ot);
sd.components.push_back(Component(0,0,2,0));
sd.components.push_back(Component(0,1,2,0));
sd.player = cb->getOwner(heroID);
cb->showSelectionDialog(&sd,boost::bind(&CGVisitableOPH::arenaSelected,this,heroID,_1));
return;
}
case 51:
case 23:
case 61:
@ -835,7 +848,7 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
val = VLC->heroh->reqExp(h->level+val) - VLC->heroh->reqExp(h->level);
if(!ttype)
{
cb->setObjProperty(id,4,heroID); //add to the visitors
cb->setObjProperty(this->id,4,heroID); //add to the visitors
InfoWindow iw;
iw.components.push_back(Component(id,subid,1,0));
iw.player = cb->getOwner(heroID);
@ -892,9 +905,12 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
const std::string & CGVisitableOPH::getHoverText() const
{
int pom;
int pom = -1;
switch(ID)
{
case 4:
pom = -1;
break;
case 51:
pom = 8;
break;
@ -914,9 +930,11 @@ const std::string & CGVisitableOPH::getHoverText() const
pom = 18;
break;
default:
throw "Wrong CGVisitableOPH object ID!\n";
throw std::string("Wrong CGVisitableOPH object ID!\n");
}
hoverName = VLC->generaltexth->names[ID] + " " + VLC->generaltexth->xtrainfo[pom];
hoverName = VLC->generaltexth->names[ID];
if(pom >= 0)
hoverName += (" " + VLC->generaltexth->xtrainfo[pom]);
const CGHeroInstance *h = cb->getSelectedHero(cb->getCurrentPlayer());
if(h)
{
@ -928,6 +946,12 @@ const std::string & CGVisitableOPH::getHoverText() const
return hoverName;
}
void CGVisitableOPH::arenaSelected( int heroID, int primSkill ) const
{
cb->setObjProperty(id,4,heroID); //add to the visitors
cb->changePrimSkill(heroID,primSkill,2);
}
bool CArmedInstance::needsLastStack() const
{
return false;
@ -1053,7 +1077,22 @@ void CGResource::initObj()
void CGResource::onHeroVisit( const CGHeroInstance * h ) const
{
//TODO: handle guards (when battles are finished)
if(army.slots.size())
{
if(message.size())
{
YesNoDialog ynd;
ynd.player = h->getOwner();
ynd.text << message;
cb->showYesNoDialog(&ynd,boost::bind(&CGResource::fightForRes,this,_1,h));
}
else
{
fightForRes(1,h);
}
}
else
{
if(message.length())
{
InfoWindow iw;
@ -1061,11 +1100,15 @@ void CGResource::onHeroVisit( const CGHeroInstance * h ) const
iw.text << message;
cb->showInfoDialog(&iw);
}
collectRes(h->getOwner());
}
}
cb->giveResource(h->tempOwner,subID,amount);
void CGResource::collectRes( int player ) const
{
cb->giveResource(player,subID,amount);
ShowInInfobox sii;
sii.player = h->tempOwner;
sii.player = player;
sii.c = Component(2,subID,amount,0);
sii.text << std::pair<ui8,ui32>(11,113);
sii.text.replacements.push_back(VLC->generaltexth->restypes[subID]);
@ -1073,6 +1116,20 @@ void CGResource::onHeroVisit( const CGHeroInstance * h ) const
cb->removeObject(id);
}
void CGResource::fightForRes(ui32 wantToFight, const CGHeroInstance *h) const
{
if(wantToFight)
return;
cb->startBattleI(h->id,army,pos,boost::bind(&CGResource::endBattle,this,_1,h));
}
void CGResource::endBattle( BattleResult *result, const CGHeroInstance *h ) const
{
if(result->winner == 0) //attacker won
collectRes(h->getOwner());
}
void CGVisitableOPW::newTurn() const
{
if (cb->getDate(1)==1) //first day of week
@ -1330,4 +1387,36 @@ void CGPickable::chosen( int which, int heroID ) const
default:
throw std::string("Unhandled treasure choice");
}
cb->removeObject(id);
}
void CGWitchHut::initObj()
{
ability = allowedAbilities[ran()%allowedAbilities.size()];
}
void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const
{
InfoWindow iw;
iw.player = h->getOwner();
if(h->getSecSkillLevel(ability)) //you alredy know this skill
{
iw.text << std::pair<ui8,ui32>(11,172);
iw.text.replacements.push_back(VLC->generaltexth->skillName[ability]);
}
else if(h->secSkills.size() >= SKILL_PER_HERO) //already all skills slots used
{
iw.text << std::pair<ui8,ui32>(11,173);
iw.text.replacements.push_back(VLC->generaltexth->skillName[ability]);
}
else //give sec skill
{
iw.components.push_back(Component(1, ability, 1, 0));
iw.text << std::pair<ui8,ui32>(11,171);
iw.text.replacements.push_back(VLC->generaltexth->skillName[ability]);
cb->changeSecSkill(h->id,ability,1,true);
}
cb->showInfoDialog(&iw);
}

View File

@ -306,6 +306,7 @@ public:
void onNAHeroVisit(int heroID, bool alreadyVisited) const;
void initObj();
void treeSelected(int heroID, int resType, int resVal, int expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog
void arenaSelected(int heroID, int primSkill) const;
template <typename Handler> void serialize(Handler &h, const int version)
{
@ -399,10 +400,14 @@ class DLL_EXPORT CGWitchHut : public CGObjectInstance
public:
std::vector<si32> allowedAbilities;
ui32 ability;
void onHeroVisit(const CGHeroInstance * h) const;
void initObj();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CGObjectInstance&>(*this);
h & allowedAbilities;
h & allowedAbilities & ability;
}
};
@ -457,7 +462,10 @@ public:
std::string message;
void onHeroVisit(const CGHeroInstance * h) const;
void collectRes(int player) const;
void initObj();
void fightForRes(ui32 wantToFight, const CGHeroInstance *h) const;
void endBattle(BattleResult *result, const CGHeroInstance *h) const;
template <typename Handler> void serialize(Handler &h, const int version)
{
@ -572,8 +580,13 @@ public:
class DLL_EXPORT CObjectHandler
{
public:
std::vector<int> cregens; //type 17. dwelling subid -> creature ID
std::vector<si32> cregens; //type 17. dwelling subid -> creature ID
void loadObjects();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & cregens;
}
};

View File

@ -32,13 +32,13 @@ void CConnection::init()
//we got connection
(*this) << std::string("Aiya!\n") << name << myEndianess; //identify ourselves
(*this) >> pom >> pom >> contactEndianess;
out << "Established connection with "<<pom<<std::endl;
tlog0 << "Established connection with "<<pom<<std::endl;
wmx = new boost::mutex;
rmx = new boost::mutex;
}
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)
CConnection::CConnection(std::string host, std::string port, std::string Name)
:io_service(new asio::io_service), name(Name)
{
int i;
boost::system::error_code error = asio::error::host_not_found;
@ -94,14 +94,14 @@ connerror1:
}
CConnection::CConnection(
boost::asio::basic_stream_socket<boost::asio::ip::tcp , boost::asio::stream_socket_service<boost::asio::ip::tcp> > * Socket,
std::string Name,
std::ostream & Out )
:socket(Socket),io_service(&Socket->io_service()), out(Out), name(Name)//, send(this), rec(this)
std::string Name )
:socket(Socket),io_service(&Socket->io_service()), name(Name)//, send(this), rec(this)
{
init();
}
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)
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)
: name(Name)//, send(this), rec(this)
{
boost::system::error_code error = asio::error::host_not_found;
socket = new tcp::socket(*io_service);

View File

@ -401,7 +401,6 @@ public:
class DLL_EXPORT CConnection
:public CISer<CConnection>, public COSer<CConnection>
{
std::ostream &out;
CConnection(void);
void init();
public:
@ -414,13 +413,13 @@ public:
std::string name; //who uses this connection
CConnection
(std::string host, std::string port, std::string Name, std::ostream & Out);
(std::string host, std::string port, std::string Name);
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);
boost::asio::io_service *Io_service, std::string Name);
CConnection
(boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service<boost::asio::ip::tcp> > * Socket,
std::string Name, std::ostream & Out); //use immediately after accepting connection into socket
std::string Name); //use immediately after accepting connection into socket
int write(const void * data, unsigned size);
int read(void * data, unsigned size);
int readLine(void * data, unsigned maxSize);

View File

@ -42,6 +42,7 @@ public:
virtual void setHoverName(int objid, MetaString * name)=0;
virtual void setObjProperty(int objid, int prop, int val)=0;
virtual void changePrimSkill(int ID, int which, int val, bool abs=false)=0;
virtual void changeSecSkill(int ID, int which, int val, bool abs=false)=0;
virtual void showInfoDialog(InfoWindow *iw)=0;
virtual void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback)=0;
virtual void showSelectionDialog(SelectionDialog *iw, const CFunctionList<void(ui32)> &callback)=0; //returns question id

View File

@ -1,5 +1,7 @@
#include <boost/interprocess/sync/interprocess_mutex.hpp>
#include <boost/interprocess/sync/interprocess_condition.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
struct ServerReady
{
@ -20,3 +22,18 @@ struct ServerReady
cond.notify_all();
}
};
struct SharedMem
{
boost::interprocess::shared_memory_object smo;
boost::interprocess::mapped_region mr;
ServerReady *sr;
SharedMem()
:smo(boost::interprocess::open_or_create,"vcmi_memory",boost::interprocess::read_write),
mr(smo,boost::interprocess::read_write)
{
smo.truncate(sizeof(ServerReady));
sr = new(mr.get_address())ServerReady();
};
};

View File

@ -20,56 +20,15 @@ DLL_EXPORT CLogger<3> tlog3;
DLL_EXPORT CLogger<4> tlog4;
DLL_EXPORT CLogger<5> tlog5;
DLL_EXPORT CConsoleHandler *console = NULL;
DLL_EXPORT std::ostream *logfile = NULL;
DLL_EXPORT std::ostream *logfile = NULL
;
DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *Logfile)
{
console = Console;
logfile = Logfile;
timeHandler pomtime;
bitmaph=b;
VLC = new LibClasses;
VLC->generaltexth = new CGeneralTextHandler;
VLC->generaltexth->loadTexts();
VLC->generaltexth->load();
tlog0<<"\tGeneral text handler: "<<pomtime.getDif()<<std::endl;
CHeroHandler * heroh = new CHeroHandler;
heroh->loadHeroes();
VLC->heroh = heroh;
tlog0 <<"\tHero handler: "<<pomtime.getDif()<<std::endl;
CArtHandler * arth = new CArtHandler;
arth->loadArtifacts();
VLC->arth = arth;
tlog0<<"\tArtifact handler: "<<pomtime.getDif()<<std::endl;
CCreatureHandler * creh = new CCreatureHandler();
creh->loadCreatures();
VLC->creh = creh;
tlog0<<"\tCreature handler: "<<pomtime.getDif()<<std::endl;
VLC->townh = new CTownHandler;
VLC->townh->loadNames();
tlog0<<"\tTown handler: "<<pomtime.getDif()<<std::endl;
CObjectHandler * objh = new CObjectHandler;
objh->loadObjects();
VLC->objh = objh;
tlog0<<"\tObject handler: "<<pomtime.getDif()<<std::endl;
VLC->dobjinfo = new CDefObjInfoHandler;
VLC->dobjinfo->load();
tlog0<<"\tDef information handler: "<<pomtime.getDif()<<std::endl;
VLC->buildh = new CBuildingHandler;
VLC->buildh->loadBuildings();
tlog0<<"\tBuilding handler: "<<pomtime.getDif()<<std::endl;
CSpellHandler * spellh = new CSpellHandler;
spellh->loadSpells();
VLC->spellh = spellh;
tlog0<<"\tSpell handler: "<<pomtime.getDif()<<std::endl;
VLC->init();
}
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode)
@ -186,3 +145,65 @@ DLL_EXPORT void loadToIt(si32 &dest, std::string &src, int &iter, int mode)
loadToIt(pom,src,iter,mode);
dest = atol(pom.c_str());
}
void LibClasses::init()
{
timeHandler pomtime;
generaltexth = new CGeneralTextHandler;
generaltexth->load();
tlog0<<"\tGeneral text handler: "<<pomtime.getDif()<<std::endl;
heroh = new CHeroHandler;
heroh->loadHeroes();
tlog0 <<"\tHero handler: "<<pomtime.getDif()<<std::endl;
arth = new CArtHandler;
arth->loadArtifacts();
tlog0<<"\tArtifact handler: "<<pomtime.getDif()<<std::endl;
creh = new CCreatureHandler();
creh->loadCreatures();
tlog0<<"\tCreature handler: "<<pomtime.getDif()<<std::endl;
townh = new CTownHandler;
townh->loadNames();
tlog0<<"\tTown handler: "<<pomtime.getDif()<<std::endl;
objh = new CObjectHandler;
objh->loadObjects();
tlog0<<"\tObject handler: "<<pomtime.getDif()<<std::endl;
dobjinfo = new CDefObjInfoHandler;
dobjinfo->load();
tlog0<<"\tDef information handler: "<<pomtime.getDif()<<std::endl;
buildh = new CBuildingHandler;
buildh->loadBuildings();
tlog0<<"\tBuilding handler: "<<pomtime.getDif()<<std::endl;
spellh = new CSpellHandler;
spellh->loadSpells();
tlog0<<"\tSpell handler: "<<pomtime.getDif()<<std::endl;
}
void LibClasses::clear()
{
delete generaltexth;
delete heroh;
delete arth;
delete creh;
delete townh;
delete objh;
delete dobjinfo;
delete buildh;
delete spellh;
generaltexth = NULL;
heroh = NULL;
arth = NULL;
creh = NULL;
townh = NULL;
objh = NULL;
dobjinfo = NULL;
buildh = NULL;
spellh = NULL;
}

View File

@ -20,7 +20,7 @@ class CGeneralTextHandler;
//class CPathfinder;
//class CGameState;
class LibClasses
class DLL_EXPORT LibClasses
{
public:
CArtHandler * arth;
@ -33,6 +33,19 @@ public:
CTownHandler * townh;
CGeneralTextHandler * generaltexth;
//CPathfinder * pathf;
void init(); //uses standard config file
void clear(); //deletes all handlers and its data
template <typename Handler> void serialize(Handler &h, const int version)
{
if(!h.saving)
{
generaltexth = new CGeneralTextHandler;
generaltexth->load();
}
h & heroh & arth & creh & townh & objh & dobjinfo & buildh & spellh;
}
};
extern DLL_EXPORT LibClasses * VLC;

37
map.cpp
View File

@ -244,6 +244,7 @@ void CMapHeader::initFromMemory( unsigned char *bufor, int &i )
}
void CMapHeader::loadPlayerInfo( int &pom, unsigned char * bufor, int &i )
{
players.resize(8);
for (pom=0;pom<8;pom++)
{
players[pom].canHumanPlay = bufor[i++];
@ -468,9 +469,6 @@ void Mapa::initFromBytes(unsigned char * bufor)
tlog0<<"\tReading events: "<<th.getDif()<<std::endl;
//map readed, bufor no longer needed
delete[] bufor; bufor=NULL;
for(int f=0; f<objects.size(); ++f) //calculationg blocked / visitable positions
{
if(!objects[f]->defInfo)
@ -552,12 +550,28 @@ Mapa::Mapa(std::string filename)
checksum = result.checksum();
tlog0 << "\tOur map checksum: "<<result.checksum() << std::endl;
initFromBytes(initTable);
delete [] initTable;
}
Mapa::Mapa()
{
terrain = NULL;
}
Mapa::~Mapa()
{
if(terrain)
{
for (int ii=0;ii<width;ii++)
{
for(int jj=0;jj<height;jj++)
delete [] terrain[ii][jj];
delete [] terrain[ii];
}
delete [] terrain;
}
}
CGHeroInstance * Mapa::getHero(int ID, int mode)
{
if (mode != 0)
@ -1397,6 +1411,7 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
loadHero(nobj, bufor, i);
break;
}
case 4: //arena
case 51: //Mercenary Camp
case 23: //Marletto Tower
case 61: // Star Axis
@ -1904,3 +1919,19 @@ void Mapa::loadQuest(CQuest * guard, unsigned char * bufor, int & i)
guard->nextVisitText = readString(bufor,i);
guard->completedText = readString(bufor,i);
}
void CMapInfo::countPlayers()
{
playerAmnt=humenPlayers=0;
for (int i=0;i<PLAYER_LIMIT;i++)
{
if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
else if (players[i].canComputerPlay) {playerAmnt++;}
}
}
CMapInfo::CMapInfo( std::string fname, unsigned char *map )
:CMapHeader(map),filename(fname)
{
countPlayers();
}

28
map.h
View File

@ -205,7 +205,7 @@ public:
ui8 levelLimit;
LossCondition lossCondition;
CVictoryCondition victoryCondition; //victory conditions
PlayerInfo players[8]; // info about players
std::vector<PlayerInfo> players; // info about players - size 8
std::vector<ui8> teams; // teams[i] = team of player no i
ui8 howManyTeams;
void initFromMemory(unsigned char *bufor, int &i);
@ -213,6 +213,13 @@ public:
void loadPlayerInfo( int &pom, unsigned char * bufor, int &i);
CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked)
CMapHeader();
template <typename Handler> void serialize(Handler &h, const int Version)
{
h & version & name & description & width & height & twoLevel & difficulty & levelLimit & areAnyPLayers;
h & players & teams & lossCondition & victoryCondition & howManyTeams;
}
};
class DLL_EXPORT CMapInfo : public CMapHeader
@ -220,15 +227,9 @@ class DLL_EXPORT CMapInfo : public CMapHeader
public:
std::string filename;
int playerAmnt, humenPlayers;
CMapInfo(std::string fname, unsigned char *map):CMapHeader(map),filename(fname)
{
playerAmnt=humenPlayers=0;
for (int i=0;i<PLAYER_LIMIT;i++)
{
if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
else if (players[i].canComputerPlay) {playerAmnt++;}
}
};
CMapInfo(){};
void countPlayers();
CMapInfo(std::string fname, unsigned char *map);
};
@ -317,6 +318,7 @@ struct DLL_EXPORT Mapa : public CMapHeader
void removeBlockVisTiles(CGObjectInstance * obj);
Mapa(std::string filename); //creates map structure from .h3m file
Mapa();
~Mapa();
CGHeroInstance * getHero(int ID, int mode=0);
bool isInTheMap(int3 pos);
template <typename TObject, typename Handler> void serializeObj(Handler &h, const int version, TObject ** obj)
@ -325,10 +327,8 @@ struct DLL_EXPORT Mapa : public CMapHeader
}
template <typename Handler> void serialize(Handler &h, const int formatVersion)
{
h & version & name & description & width & height & twoLevel & difficulty & levelLimit & areAnyPLayers & rumors;
h & players & teams & lossCondition & victoryCondition & howManyTeams & allowedSpell
& allowedAbilities & allowedArtifact & allowedHeroes & events & grailPos;
h & static_cast<CMapHeader&>(*this);
h & rumors & allowedSpell & allowedAbilities & allowedArtifact & allowedHeroes & events & grailPos;
//TODO: viccondetails
if(h.saving)

View File

@ -404,7 +404,16 @@ void processDef (CGDefInfo* def)
{
if(def->id == 26)
return;
if(def->name.size())
{
def->handler = CDefHandler::giveDef(def->name);
}
else
{
tlog2 << "No def name for " << def->id << " " << def->subid << std::endl;
def->handler = NULL;
return;
}
def->width = def->handler->ourImages[0].bitmap->w/32;
def->height = def->handler->ourImages[0].bitmap->h/32;
CGDefInfo* pom = CGI->dobjinfo->gobjs[def->id][def->subid];
@ -518,7 +527,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
if(extRect) SDL_SetClipRect(su, extRect); //preventing blitting outside of that rect
if (((dx+x)>((map->width+Woff)) || (dy+y)>((map->height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) )
throw new std::string("terrainRect: out of range");
throw std::string("terrainRect: out of range");
////printing terrain
for (int bx=0; bx<dx; bx++)
{
@ -622,7 +631,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
if(themp->type==NULL)
continue;
std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
std::vector<Cimage> & iv = graphics->heroAnims[themp->type->heroType]->ourImages;
size_t gg;
for(gg=0; gg<iv.size(); ++gg)
@ -645,7 +654,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
if(themp->type==NULL)
continue;
std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
std::vector<Cimage> & iv = graphics->heroAnims[themp->type->heroType]->ourImages;
size_t gg;
for(gg=0; gg < iv.size(); ++gg)
@ -785,7 +794,7 @@ SDL_Surface * CMapHandler::terrainRectSmooth(int x, int y, int dx, int dy, int l
if(extRect) SDL_SetClipRect(su, extRect); //preventing blitting outside of that rect
if (((dx+x)>((map->width+Woff)) || (dy+y)>((map->height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) )
throw new std::string("terrainRect: out of range");
throw std::string("terrainRect: out of range");
////printing terrain
for (int bx= (moveX <= 0 ? 0 : -1); bx<dx+1; bx++)
{
@ -889,7 +898,7 @@ SDL_Surface * CMapHandler::terrainRectSmooth(int x, int y, int dx, int dy, int l
if(themp->type==NULL)
continue;
std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
std::vector<Cimage> & iv = graphics->heroAnims[themp->type->heroType]->ourImages;
size_t gg;
for(gg=0; gg<iv.size(); ++gg)
@ -912,7 +921,7 @@ SDL_Surface * CMapHandler::terrainRectSmooth(int x, int y, int dx, int dy, int l
if(themp->type==NULL)
continue;
std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
std::vector<Cimage> & iv = graphics->heroAnims[themp->type->heroType]->ourImages;
size_t gg;
for(gg=0; gg < iv.size(); ++gg)
@ -1328,11 +1337,7 @@ 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
throw std::string("Def not found.");
}
bool CMapHandler::printObject(const CGObjectInstance *obj)
@ -1415,11 +1420,7 @@ 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
throw std::string("Something very wrong1.");
}
}
else //if(isMoving)
@ -1443,11 +1444,7 @@ 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
throw std::string("Something very wrong2.");
}
}
}
@ -1549,6 +1546,18 @@ void CMapHandler::updateWater() //shift colors in palettes of water tiles
}
}
CMapHandler::~CMapHandler()
{
delete fullHide;
delete partialHide;
}
CMapHandler::CMapHandler()
{
fullHide = NULL;
partialHide = NULL;
}
TerrainTile2::TerrainTile2()
:terbitmap(0),tileInfo(0)
{}

View File

@ -85,6 +85,9 @@ public:
std::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
CMapHandler();
~CMapHandler();
void loadDefs();
SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);

View File

@ -1,12 +1,13 @@
#include "../CGameState.h"
#include "../StartInfo.h"
#include "../hch/CArtHandler.h"
#include "../hch/CBuildingHandler.h"
#include "../hch/CDefObjInfoHandler.h"
#include "../hch/CGeneralTextHandler.h"
#include "../hch/CHeroHandler.h"
#include "../hch/CObjectHandler.h"
#include "../hch/CSpellHandler.h"
#include "../hch/CTownHandler.h"
#include "../CGameState.h"
#include "../lib/CondSh.h"
#include "../lib/Connection.h"
#include "../lib/NetPacks.h"
@ -183,15 +184,16 @@ void callWith(std::vector<T> args, boost::function<void(T)> fun, ui32 which)
fun(args[which]);
}
void CGameHandler::changeSecSkill(int ID, ui16 which, int val, bool abs)
void CGameHandler::changeSecSkill( int ID, int which, int val, bool abs/*=false*/ )
{
SetSecSkill sps;
sps.id = ID;
sps.which = which;
sps.abs = abs;
sps.val = val;
sendAndApply(&sps);
SetSecSkill sss;
sss.id = ID;
sss.which = which;
sss.val = val;
sss.abs = abs;
sendAndApply(&sss);
}
void CGameHandler::changePrimSkill(int ID, int which, int val, bool abs)
{
SetPrimSkill sps;
@ -413,18 +415,16 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
c >> fname;
{
CSaveFile save(fname);
save << gs->map;
CSaveFile save(std::string("Games") + PATHSEPARATOR + fname + ".vlgm1");
char hlp[8] = "VCMISVG";
save << hlp << static_cast<CMapHeader&>(*gs->map) << *VLC << gs;
}
{
CLoadFile load(fname);
load >> mapa;
CSaveFile save(std::string("Games") + PATHSEPARATOR + fname + ".vsgm1");
save << *this;
}
//save << VLC->arth << VLC->buildh << VLC->creh << VLC->dobjinfo << VLC->heroh
// << VLC->spellh << VLC->townh << this;
//save << this;
break;
}
case 99: //end!
@ -1553,6 +1553,9 @@ void CGameHandler::init(StartInfo *si, int Seed)
//}
//delete lf;
for(std::map<ui8,PlayerState>::iterator i = gs->players.begin(); i != gs->players.end(); i++)
states.addPlayer(i->first);
}
void CGameHandler::newTurn()
@ -1638,13 +1641,15 @@ void CGameHandler::newTurn()
if(gs->map->objects[i])
gs->map->objects[i]->newTurn();
}
void CGameHandler::run()
void CGameHandler::run(bool resume)
{
BOOST_FOREACH(CConnection *cc, conns)
{//init conn.
ui8 quantity, pom;
//ui32 seed;
if(!resume)
(*cc) << gs->scenarioOps->mapname << gs->map->checksum << gs->seed;
(*cc) >> quantity; //how many players will be handled at that client
for(int i=0;i<quantity;i++)
{
@ -1700,14 +1705,23 @@ void CGameHandler::run()
//if(checkFunc(map->objects[i]->ID,temps))
// (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
//}
for(std::map<ui8,PlayerState>::iterator i = gs->players.begin(); i != gs->players.end(); i++)
states.addPlayer(i->first);
while (!end2)
{
newTurn();
for(std::map<ui8,PlayerState>::iterator i = gs->players.begin(); i != gs->players.end(); i++)
std::map<ui8,PlayerState>::iterator i;
if(!resume)
i = gs->players.begin();
else
i = gs->players.find(gs->currentPlayer);
for(; i != gs->players.end(); i++)
{
if(!resume)
newTurn();
else
resume = false;
if((i->second.towns.size()==0 && i->second.heroes.size()==0) || i->second.color<0 || i->first>=PLAYER_LIMIT ) continue; //players has not towns/castle - loser
states.setFlag(i->first,&PlayerStatus::makingTurn,true);
gs->currentPlayer = i->first;

View File

@ -57,15 +57,11 @@ public:
class CGameHandler : public IGameCallback
{
static ui32 QID;
//std::set<CCPPObjectScript *> cppscripts; //C++ scripts
//std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts
CVCMIServer *s;
std::map<int,CConnection*> connections; //player color -> connection to clinet with interface of that player
PlayerStatuses states; //player color -> player state
std::set<CConnection*> conns;
void changeSecSkill(int ID, ui16 which, int val, bool abs=false);
void giveSpells(const CGTownInstance *t, const CGHeroInstance *h);
void moveStack(int stack, int dest);
void startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb); //use hero=NULL for no hero
@ -93,6 +89,7 @@ public:
void setHoverName(int objid, MetaString * name);
void setObjProperty(int objid, int prop, int val);
void changePrimSkill(int ID, int which, int val, bool abs=false);
void changeSecSkill(int ID, int which, int val, bool abs=false);
void showInfoDialog(InfoWindow *iw);
void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback);
void showSelectionDialog(SelectionDialog *iw, const CFunctionList<void(ui32)> &callback); //returns question id
@ -111,7 +108,7 @@ public:
void handleConnection(std::set<int> players, CConnection &c);
template <typename Handler> void serialize(Handler &h, const int version)
{
h & QID & gs & states;
h & QID & states;
}
template <typename T> void applyAndAsk(Query<T> * sel, ui8 player, boost::function<void(ui32)> &callback)
{
@ -157,7 +154,7 @@ public:
gs->apply(info);
sendToAllClients(info);
}
void run();
void run(bool resume);
void newTurn();
friend class CVCMIServer;

View File

@ -3,6 +3,14 @@
#include <boost/asio.hpp>
#include "../global.h"
#include "../lib/Connection.h"
#include "../hch/CArtHandler.h"
#include "../hch/CDefObjInfoHandler.h"
#include "../hch/CGeneralTextHandler.h"
#include "../hch/CHeroHandler.h"
#include "../hch/CTownHandler.h"
#include "../hch/CObjectHandler.h"
#include "../hch/CBuildingHandler.h"
#include "../hch/CSpellHandler.h"
#include "zlib.h"
#ifndef __GNUC__
#include <tchar.h>
@ -87,12 +95,12 @@ void CVCMIServer::newGame(CConnection *c)
i--;
continue;
}
cc = new CConnection(s,NAME,std::cout);
cc = new CConnection(s,NAME);
}
gh.conns.insert(cc);
}
gh.run();
gh.run(false);
}
void CVCMIServer::start()
{
@ -125,7 +133,7 @@ void CVCMIServer::start()
return;
}
tlog0<<"We've accepted someone... " << std::endl;
CConnection *connection = new CConnection(s,NAME,std::cout);
CConnection *connection = new CConnection(s,NAME);
tlog0<<"Got connection!" << std::endl;
while(!end2)
{
@ -144,10 +152,68 @@ void CVCMIServer::start()
case 2:
newGame(connection);
break;
case 3:
loadGame(connection);
break;
}
}
}
void CVCMIServer::loadGame( CConnection *c )
{
std::string fname;
CGameHandler gh;
boost::system::error_code error;
ui8 clients;
*c >> clients >> fname; //how many clients should be connected - TODO: support more than one
{
char sig[8];
CMapHeader dum;
CLoadFile lf(fname + ".vlgm1");
lf >> sig >> dum;
tlog0 <<"Reading save signature"<<std::endl;
lf >> *VLC;
tlog0 <<"Reading handlers"<<std::endl;
lf >> (gh.gs);
tlog0 <<"Reading gamestate"<<std::endl;
}
{
CLoadFile lf(fname + ".vsgm1");
lf >> gh;
}
*c << ui8(0);
CConnection* cc; //tcp::socket * ss;
for(int i=0; i<clients; i++)
{
if(!i)
{
cc=c;
}
else
{
tcp::socket * s = new tcp::socket(acceptor->io_service());
acceptor->accept(*s,error);
if(error) //retry
{
tlog3<<"Cannot establish connection - retrying..." << std::endl;
i--;
continue;
}
cc = new CConnection(s,NAME);
}
gh.conns.insert(cc);
}
gh.run(true);
}
#ifndef __GNUC__
int _tmain(int argc, _TCHAR* argv[])
#else

View File

@ -29,6 +29,7 @@ public:
~CVCMIServer();
void setUpConnection(CConnection *c, std::string mapname, si32 checksum);
void newGame(CConnection *c);
void loadGame(CConnection *c);
void start();
};
#endif // __CVCMISERVER_H__