From 78d5839f4cc95fa53b587429a3121da148f5875a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Wed, 4 Jun 2008 13:05:57 +0000 Subject: [PATCH 01/47] New branch for me to experiment with network code From 608dc62ee8a71a009a38dce16fe83e24290b8432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Fri, 6 Jun 2008 12:35:23 +0000 Subject: [PATCH 02/47] * version set to 0.61 * Splitting: when moving slider to the right so that 0 is left in old slot the army is moved. --- CCallback.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CCallback.cpp b/CCallback.cpp index c2219b933..b03c2c612 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -644,7 +644,7 @@ int CCallback::splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2 if(!val) return -1; CCreatureSet *S1 = const_cast(getGarrison(s1)), *S2 = const_cast(getGarrison(s2)); - if ((S1->slots[p1].second<=val) && (true /*we are allowed to*/)) + if ((S1->slots[p1].secondslots[p2].first = S1->slots[p1].first; S2->slots[p2].second = val; S1->slots[p1].second -= val; + if(!S1->slots[p1].second) //if we've moved all creatures + S1->slots.erase(p1); if(s1->tempOwner Date: Sat, 7 Jun 2008 17:16:52 +0000 Subject: [PATCH 03/47] Code cleaning/refactoring --- CBattleInterface.cpp | 1 + CMT.cpp | 5 +- CMessage.cpp | 2 - CPathfinder.cpp | 2 +- CPlayerInterface.cpp | 1 + CPreGame.cpp | Bin 128302 -> 128496 bytes CPreGame.h | 2 - client/CCreatureAnimation.cpp | 373 ++++++++++++++++++++++++++++++ client/CCreatureAnimation.h | 45 ++++ hch/CAmbarCendamo.cpp | 286 +++++------------------ hch/CAmbarCendamo.h | 18 +- hch/CCastleHandler.h | 2 - hch/CCreatureHandler.cpp | 420 +--------------------------------- hch/CCreatureHandler.h | 48 +--- hch/CDefHandler.h | Bin 3534 -> 3384 bytes hch/CObjectHandler.h | 1 + hch/CSemiDefHandler.cpp | 148 ------------ hch/CSemiDefHandler.h | 31 --- hch/CSemiLodHandler.cpp | 12 - hch/CSemiLodHandler.h | 13 -- map.cpp | 9 - map.h | 31 +-- mapHandler.cpp | 93 +++++++- mapHandler.h | 3 +- 24 files changed, 579 insertions(+), 967 deletions(-) create mode 100644 client/CCreatureAnimation.cpp create mode 100644 client/CCreatureAnimation.h delete mode 100644 hch/CSemiDefHandler.cpp delete mode 100644 hch/CSemiDefHandler.h delete mode 100644 hch/CSemiLodHandler.cpp delete mode 100644 hch/CSemiLodHandler.h diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index e545adb94..9d2f6e8bc 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -9,6 +9,7 @@ #include "CCallback.h" #include "CGameState.h" #include "hch\CGeneralTextHandler.h" +#include "client/CCreatureAnimation.h" #include #include diff --git a/CMT.cpp b/CMT.cpp index 2802982b9..3ca7bfcaf 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -26,7 +26,6 @@ #include "hch\CObjectHandler.h" #include "CGameInfo.h" #include "hch\CMusicHandler.h" -#include "hch\CSemiLodHandler.h" #include "hch\CLodHandler.h" #include "hch\CDefHandler.h" #include "hch\CSndHandler.h" @@ -855,12 +854,12 @@ int _tmain(int argc, _TCHAR* argv[]) THC std::cout<<"Reading file: "<deh3m(); THC std::cout<<"Detecting file (together): "<loadDefs(); - THC std::cout<<"Reading terrain defs: "<mh = mh; mh->reader = ac; THC std::cout<<"Creating mapHandler: "<loadDefs(); + THC std::cout<<"Reading terrain defs: "<init(); THC std::cout<<"Initializing mapHandler (together): "< #include "CPlayerInterface.h" #include "hch\CDefHandler.h" -#include "hch\CSemiDefHandler.h" #include "CGameInfo.h" #include "SDL_Extensions.h" #include diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 9961c706a..148564e71 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -48,7 +48,7 @@ vector* CPathfinder::GetPath(const CGHeroInstance* hero) } else { - blockLandSea = indeterminate; + blockLandSea = boost::logic::indeterminate; } CalcG(&Start); diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index ddc8c8885..5f2ce2ceb 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -25,6 +25,7 @@ #include "CBattleInterface.h" #include "CLua.h" #include +#include "client/CCreatureAnimation.h" using namespace CSDL_Ext; extern TTF_Font * GEOR16; diff --git a/CPreGame.cpp b/CPreGame.cpp index 568a94547286954d47a89af2ac75cb783fef4bf9..fdcb629018b3ebea073ff674d9f2d502871ce018 100644 GIT binary patch delta 110 zcmZ4Yiv7cD_6=Sygf$p4!O(`ml)->OlR<%@dir{GMoHyxhD3%UhCHBT9z!~V6;L9X zAs;AG#8Apmz)-@F%8)X-@R2YlNJfdlhQVfX>?_&n4LXbxj0%$v_6jrBHru|~Zu^4q GBM$&g@g7eA delta 18 acmezHntk0X_6=Synt5Js=XuHaga-g(F9~@7 diff --git a/CPreGame.h b/CPreGame.h index 924653271..cce661198 100644 --- a/CPreGame.h +++ b/CPreGame.h @@ -4,8 +4,6 @@ #include #include "SDL.h" #include "StartInfo.h" -#include "hch\CSemiDefHandler.h" -#include "hch\CSemiLodHandler.h" #include "hch\CPreGameTextHandler.h" #include "CMessage.h" #include "map.h" diff --git a/client/CCreatureAnimation.cpp b/client/CCreatureAnimation.cpp new file mode 100644 index 000000000..0f81cce93 --- /dev/null +++ b/client/CCreatureAnimation.cpp @@ -0,0 +1,373 @@ +#include "CCreatureAnimation.h" +#include "../CGameInfo.h" +#include "../hch/CLodHandler.h" +int CCreatureAnimation::getType() const +{ + return type; +} + +void CCreatureAnimation::setType(int type) +{ + this->type = type; + curFrame = 0; + if(type!=-1) + { + if(SEntries[curFrame].group!=type) //rewind + { + int j=-1; //first frame in displayed group + for(int g=0; g=frames) + curFrame = 0; + } +} + +CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEntries(NULL) +{ + //load main file + std::string data2 = CGI->spriteh->getTextFile(name); + if(data2.size()==0) + throw new std::string("no such def!"); + FDef = new unsigned char[data2.size()]; + for(int g=0; g=amp/2) + { + ret = ret-amp; + } + return ret; +} +int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect) +{ + return nextFrame(dest,x-fullWidth/2,y-fullHeight/2,attacker,incrementFrame,yellowBorder,destRect); +} +int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect) +{ + if(dest->format->BytesPerPixel<3) + return -1; //not enough depth + + //increasing frame numer + int SIndex = -1; + if(incrementFrame) + { + SIndex = curFrame++; + if(type!=-1) + { + if(SEntries[curFrame].group!=type) //rewind + { + int j=-1; //first frame in displayed group + for(int g=0; g=frames) + curFrame = 0; + } + } + else + { + SIndex = curFrame; + } + //frame number increased + + long BaseOffset, + SpriteWidth, SpriteHeight, //sprite format + LeftMargin, RightMargin, TopMargin,BottomMargin, + i, add, FullHeight,FullWidth, + TotalRowLength, // length of read segment + RowAdd; + unsigned char SegmentType, SegmentLength; + + i=BaseOffset=SEntries[SIndex].offset; + int prSize=readNormalNr(i,4,FDef);i+=4; + int defType2 = readNormalNr(i,4,FDef);i+=4; + FullWidth = readNormalNr(i,4,FDef);i+=4; + FullHeight = readNormalNr(i,4,FDef);i+=4; + SpriteWidth = readNormalNr(i,4,FDef);i+=4; + SpriteHeight = readNormalNr(i,4,FDef);i+=4; + LeftMargin = readNormalNr(i,4,FDef);i+=4; + TopMargin = readNormalNr(i,4,FDef);i+=4; + RightMargin = FullWidth - SpriteWidth - LeftMargin; + BottomMargin = FullHeight - SpriteHeight - TopMargin; + + add = 4 - FullWidth%4; + + int BaseOffsetor = BaseOffset = i; + + int ftcp = 0; + + if (defType2==1) //as it should be allways in creature animations + { + if (TopMargin>0) + { + for (int i=0;i0) + { + ftcp+=LeftMargin; + } + TotalRowLength=0; + do + { + SegmentType=FDef[BaseOffset++]; + SegmentLength=FDef[BaseOffset++]; + if (SegmentType==0xFF) + { + for (int k=0;k<=SegmentLength;k++) + { + int xB = (attacker ? ftcp%(FullWidth+add) : (FullWidth+add) - ftcp%(FullWidth+add) - 1) + x; + int yB = ftcp/(FullWidth+add) + y; + if(xB>=0 && yB>=0 && xBw && yBh) + { + if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB)) + putPixel(dest, xB + yB*dest->w, palette[FDef[BaseOffset+k]], FDef[BaseOffset+k], yellowBorder); + } + ftcp++; //increment pos + if ((TotalRowLength+k+1)>=SpriteWidth) + break; + } + BaseOffset+=SegmentLength+1;//// + TotalRowLength+=SegmentLength+1; + } + else + { + for (int k=0;k=0 && yB>=0 && xBw && yBh) + { + if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB)) + putPixel(dest, xB + yB*dest->w, palette[SegmentType], SegmentType, yellowBorder); + } + ftcp++; //increment pos + } + TotalRowLength+=SegmentLength+1; + } + }while(TotalRowLength0) + { + ftcp+=RightMargin; + } + if (add>0) + { + ftcp+=add+RowAdd; + } + } + delete [] RLEntries; + RLEntries = NULL; + if (BottomMargin>0) + { + ftcp += BottomMargin * (FullWidth+add); + } + } + + //SDL_UpdateRect(dest, x, y, FullWidth+add, FullHeight); + + return 0; +} + +int CCreatureAnimation::framesInGroup(int group) const +{ + int ret = 0; //number of frames in given group + for(int g=0; gpixels + ftcp*3; + if(palc > 7) //normal color + { + p[0] = color.B; + p[1] = color.G; + p[2] = color.R; + } + else if(yellowBorder && (palc == 6 || palc == 7)) //dark yellow border + { + p[0] = 0; + p[1] = 0xff; + p[2] = 0xff; + } + else if(yellowBorder && (palc == 5)) //yellow border + { + p[0] = color.B; + p[1] = color.G; + p[2] = color.R; + } + else if(palc < 5) //shadow + { + Uint16 alpha; + switch(color.G) + { + case 0: + alpha = 128; + break; + case 50: + alpha = 50+32; + break; + case 100: + alpha = 100+64; + break; + case 125: + alpha = 125+64; + break; + case 128: + alpha = 128+64; + break; + case 150: + alpha = 150+64; + break; + default: + alpha = 255; + break; + } + //alpha counted + p[0] = (p[0] * alpha)>>8; + p[1] = (p[1] * alpha)>>8; + p[2] = (p[2] * alpha)>>8; + } + } +} diff --git a/client/CCreatureAnimation.h b/client/CCreatureAnimation.h new file mode 100644 index 000000000..98b56012f --- /dev/null +++ b/client/CCreatureAnimation.h @@ -0,0 +1,45 @@ +#pragma once +#include "../global.h" +#include "../CPlayerInterface.h" +#include "../hch/CDefHandler.h" + +class CCreatureAnimation : public CIntObject +{ +private: + int totalEntries, DEFType, totalBlocks; + bool allowRepaint; + int length; + BMPPalette palette[256]; + unsigned int * RWEntries; + int * RLEntries; + struct SEntry + { + std::string name; + int offset; + int group; + } ; + std::vector SEntries ; + char id[2]; + std::string defName, curDir; + int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false); + void putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const; + + //////////// + + unsigned char * FDef; //animation raw data + unsigned int curFrame; //number of currently displayed frame + unsigned int frames; //number of frames + int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1]) +public: + int fullWidth, fullHeight; //read-only, please! + CCreatureAnimation(std::string name); //c-tor + ~CCreatureAnimation(); //d-tor + + void setType(int type); //sets type of animation and cleares framecount + int getType() const; //returns type of animation + + int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next + int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next + + int framesInGroup(int group) const; //retirns number of fromes in given group +}; diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index 27b7f8fd8..8b735ab3c 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -1,20 +1,18 @@ #include "../stdafx.h" #include "CAmbarCendamo.h" -#include "CSemiDefHandler.h" #include "../CGameInfo.h" #include "CObjectHandler.h" #include "CCastleHandler.h" #include "CTownHandler.h" #include "CDefObjInfoHandler.h" #include "../SDL_Extensions.h" -#include "boost\filesystem.hpp" #include "../CGameState.h" #include "CLodHandler.h" #include #include #include -#include "../CLua.h" - +#include +std::string nameFromType (EterrainType typ); int readInt(unsigned char * bufor, int bytCon) { int ret=0; @@ -51,10 +49,10 @@ CAmbarCendamo::CAmbarCendamo (unsigned char * map) } CAmbarCendamo::CAmbarCendamo (const char * tie) { - is = new std::ifstream(); + std::ifstream * is = new std::ifstream(); is -> open(tie,std::ios::binary); is->seekg(0,std::ios::end); // na koniec - andame = is->tellg(); // read length + int andame = is->tellg(); // read length is->seekg(0,std::ios::beg); // wracamy na poczatek bufor = new unsigned char[andame]; // allocate memory is->read((char*)bufor, andame); // read map file to buffer @@ -66,20 +64,7 @@ CAmbarCendamo::~CAmbarCendamo () for (int ii=0;iiclose(); - // delete of; - //} + delete[] bufor; } std::set convertBuildings(const std::set h3m, int castleID) { @@ -153,8 +138,8 @@ void CAmbarCendamo::deh3m() for (int ii=0;ii defsToUnpack; + //////READING DEF INFO/////// + int defAmount = readNormalNr(i); i+=4; + map.defy.reserve(defAmount); + for (int idd = 0 ; iddname.reserve(nameLength); for (int cd=0;cdname += bufor[i++]; } - //for (int v=0; v<42; v++) // read info - //{ - // vinya->bytes[v] = bufor[i++]; - //} std::transform(vinya->name.begin(),vinya->name.end(),vinya->name.begin(),(int(*)(int))toupper); + + unsigned char bytes[12]; for (int v=0; v<12; v++) // read info { @@ -826,9 +812,9 @@ void CAmbarCendamo::deh3m() } i+=16; map.defy.push_back(vinya); // add this def to the vector - defsToUnpack.push_back(vinya->name); } - THC std::cout<<"\tReading defs: "<defInfo = map.defy[tempd]; nobj->ID = nobj->defInfo->id; nobj->subID = nobj->defInfo->subid; - //nobj->defInfo = readNormalNr(i, 4); i+=4; - //nobj->isHero = false; - //nobj->moveDir = 0; - //nobj->isStanding = true; - //nobj->state->owner = 254; //a lot of objs will never have an owner - //if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size()) - // std::cout << "Alarm!!! Obiekt "<map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size()) std::cout << "Alarm!!! Obiekt "<defInfo); int j = nobj->defInfo->id; int p = 99; - switch(uu) + switch(getDefType(nobj->defInfo)) { case EDefType::EVENTOBJ_DEF: //for event - objects { @@ -884,7 +863,7 @@ void CAmbarCendamo::deh3m() spec->areGuarders = bufor[i]; ++i; if(spec->areGuarders) { - spec->guarders = readCreatureSet(i); i+=( map.version == RoE ? 21 : 28); + spec->guarders = readCreatureSet(); } i+=4; } @@ -927,7 +906,7 @@ void CAmbarCendamo::deh3m() spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i; } int gcre = readNormalNr(i, 1); ++i; //number of gained creatures - spec->creatures = readCreatureSet(i, gcre); i+=3*gcre; + spec->creatures = readCreatureSet(gcre); if(map.version>RoE) i+=gcre; i+=8; @@ -996,7 +975,7 @@ void CAmbarCendamo::deh3m() spec->standardGarrison = standGarrison; if(standGarrison) { - spec->garrison = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28); //4 bytes per slot + spec->garrison = readCreatureSet(); } bool form = bufor[i]; ++i; //formation spec->garrison.formation = form; @@ -1726,7 +1705,7 @@ void CAmbarCendamo::deh3m() CGarrisonObjInfo * spec = new CGarrisonObjInfo; spec->player = bufor[i]; ++i; i+=3; - spec->units = readCreatureSet(i); i+= (map.version==RoE ? 21 : 28); + spec->units = readCreatureSet(); if(map.version > RoE) { spec->movableUnits = bufor[i]; ++i; @@ -1753,7 +1732,7 @@ void CAmbarCendamo::deh3m() if(areGuards) { spec->areGuards = true; - spec->guards = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28) ; + spec->guards = readCreatureSet(); } else spec->areGuards = false; @@ -1776,7 +1755,7 @@ void CAmbarCendamo::deh3m() spec->areGuards = bufor[i]; ++i; if(spec->areGuards) { - spec->guards = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28); + spec->guards = readCreatureSet(); } i+=4; } @@ -1820,7 +1799,7 @@ void CAmbarCendamo::deh3m() bool stGarr = bufor[i]; ++i; //true if garrison isn't empty if(stGarr) { - spec->garrison = readCreatureSet(i); i+=( map.version > RoE ? 28 : 21 ); + spec->garrison = readCreatureSet(); } spec->garrison.formation = bufor[i]; ++i; spec->unusualBuildins = bufor[i]; ++i; @@ -2021,7 +2000,7 @@ void CAmbarCendamo::deh3m() spec->areGuarders = bufor[i]; ++i; if(spec->areGuarders) { - spec->guarders = readCreatureSet(i); i+=( map.version == RoE ? 21 : 28 ); + spec->guarders = readCreatureSet(); } i+=4; } @@ -2044,7 +2023,7 @@ void CAmbarCendamo::deh3m() spec->areGuarders = bufor[i]; ++i; if(spec->areGuarders) { - spec->guarders = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28); + spec->guarders = readCreatureSet(); } i+=4; } @@ -2089,7 +2068,7 @@ void CAmbarCendamo::deh3m() spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i; } int gcre = readNormalNr(i, 1); ++i; //number of gained creatures - spec->creatures = readCreatureSet(i, gcre); i+=3*gcre; + spec->creatures = readCreatureSet(gcre); if(map.version > RoE) i+=gcre; i+=8; @@ -2376,23 +2355,18 @@ borderguardend: } } //end of main switch CGameInfo::mainObj->objh->objInstances.push_back(nobj); - //TODO - dokończyć, dużo do zrobienia - trzeba patrzeć, co def niesie - }//*/ //end of loading objects; commented to make application work until it will be finished - ////objects loaded - + }//end of loading objects THC std::cout<<"\tReading objects: "< dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack); - - THC std::cout<<"\tUnpacking defs: "<handler=dhandlers[i]; - CGDefInfo* pom = CGI->dobjinfo->gobjs[map.defy[i]->id][map.defy[i]->subid]; + map.defy[ir]->handler=CGI->spriteh->giveDef(map.defy[ir]->name); + CGDefInfo* pom = CGI->dobjinfo->gobjs[map.defy[ir]->id][map.defy[ir]->subid]; if(pom) - pom->handler=dhandlers[i]; + pom->handler=map.defy[ir]->handler; else - std::cout << "Lacking def info for " << map.defy[i]->id << " " << map.defy[i]->subid <<" " << map.defy[i]->name << std::endl; + std::cout << "Lacking def info for " << map.defy[ir]->id << " " << map.defy[ir]->subid <<" " << map.defy[ir]->name << std::endl; } for(int vv=0; vvhandler->ourImages.size(); ++yy) { map.defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap); - //SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap, CSDL_Ext::std32bppSurface); - //SDL_FreeSurface(map.defy[vv]->handler->ourImages[yy].bitmap); - //map.defy[vv]->handler->ourImages[yy].bitmap = bufs; map.defy[vv]->handler->alphaTransformed = true; } } + THC std::cout<<"\tUnpacking and handling defs: "<=amp/2) @@ -2464,29 +2438,6 @@ int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic) return ret; } -void CAmbarCendamo::loadDefs() -{ - std::set loadedTypes; - for (int i=0; ispriteh->giveDef(CSemiDefHandler::nameFromType(map.terrain[i][j].tertype).c_str()); - loadedTypes.insert(map.terrain[i][j].tertype); - defs.push_back(sdh); - } - if (map.twoLevel && loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end()) - { - CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.undergroungTerrain[i][j].tertype).c_str()); - loadedTypes.insert(map.undergroungTerrain[i][j].tertype); - defs.push_back(sdh); - } - } - } -} - EDefType CAmbarCendamo::getDefType(CGDefInfo * a) { switch(a->id) @@ -2544,161 +2495,42 @@ EDefType CAmbarCendamo::getDefType(CGDefInfo * a) } } -CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number) +CCreatureSet CAmbarCendamo::readCreatureSet(int number) { if(map.version>RoE) { CCreatureSet ret; std::pair ins; - if(number>0 && readNormalNr(pos, 2)!=0xffff) + for(int ir=0;ir32768) rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+2, 2); - std::pair > tt(0,ins); - ret.slots.insert(tt); - } - if(number>1 && readNormalNr(pos+4, 2)!=0xffff) - { - int rettt = readNormalNr(pos+4, 2); - if(rettt>32768) - rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+6, 2); - std::pair > tt(1,ins); - ret.slots.insert(tt); - } - if(number>2 && readNormalNr(pos+8, 2)!=0xffff) - { - int rettt = readNormalNr(pos+8, 2); - if(rettt>32768) - rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+10, 2); - std::pair > tt(2,ins); - ret.slots.insert(tt); - } - if(number>3 && readNormalNr(pos+12, 2)!=0xffff) - { - int rettt = readNormalNr(pos+12, 2); - if(rettt>32768) - rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+14, 2); - std::pair > tt(3,ins); - ret.slots.insert(tt); - } - if(number>4 && readNormalNr(pos+16, 2)!=0xffff) - { - int rettt = readNormalNr(pos+16, 2); - if(rettt>32768) - rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+18, 2); - std::pair > tt(4,ins); - ret.slots.insert(tt); - } - if(number>5 && readNormalNr(pos+20, 2)!=0xffff) - { - int rettt = readNormalNr(pos+20, 2); - if(rettt>32768) - rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+22, 2); - std::pair > tt(5,ins); - ret.slots.insert(tt); - } - if(number>6 && readNormalNr(pos+24, 2)!=0xffff) - { - int rettt = readNormalNr(pos+24, 2); - if(rettt>32768) - rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+26, 2); - std::pair > tt(6,ins); + ins.second = readNormalNr(i+ir*4+2, 2); + std::pair > tt(ir,ins); ret.slots.insert(tt); } + i+=number*4; return ret; } else { CCreatureSet ret; std::pair ins; - if(number>0 && readNormalNr(pos, 1)!=0xff) + for(int ir=0;ir220) rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16; ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+1, 2); - std::pair > tt(0,ins); - ret.slots.insert(tt); - } - if(number>1 && readNormalNr(pos+3, 1)!=0xff) - { - int rettt = readNormalNr(pos+3, 1); - if(rettt>220) - rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+4, 2); - std::pair > tt(1,ins); - ret.slots.insert(tt); - } - if(number>2 && readNormalNr(pos+6, 1)!=0xff) - { - int rettt = readNormalNr(pos+6, 1); - if(rettt>220) - rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+7, 2); - std::pair > tt(2,ins); - ret.slots.insert(tt); - } - if(number>3 && readNormalNr(pos+9, 1)!=0xff) - { - int rettt = readNormalNr(pos+9, 1); - if(rettt>220) - rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+10, 2); - std::pair > tt(3,ins); - ret.slots.insert(tt); - } - if(number>4 && readNormalNr(pos+12, 1)!=0xff) - { - int rettt = readNormalNr(pos+12, 1); - if(rettt>220) - rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+13, 2); - std::pair > tt(4,ins); - ret.slots.insert(tt); - } - if(number>5 && readNormalNr(pos+15, 1)!=0xff) - { - int rettt = readNormalNr(pos+15, 1); - if(rettt>220) - rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+16, 2); - std::pair > tt(5,ins); - ret.slots.insert(tt); - } - if(number>6 && readNormalNr(pos+18, 1)!=0xff) - { - int rettt = readNormalNr(pos+18, 1); - if(rettt>220) - rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); - ins.second = readNormalNr(pos+19, 2); - std::pair > tt(6,ins); + ins.second = readNormalNr(i+ir*3+1, 2); + std::pair > tt(ir,ins); ret.slots.insert(tt); } + i+=number*3; return ret; } -} - -void CAmbarCendamo::processMap(std::vector & defsToUnpack) -{} +} \ No newline at end of file diff --git a/hch/CAmbarCendamo.h b/hch/CAmbarCendamo.h index 2aab7a02f..b95f30359 100644 --- a/hch/CAmbarCendamo.h +++ b/hch/CAmbarCendamo.h @@ -1,13 +1,11 @@ #ifndef CAMBARCENDAMO_H #define CAMBARCENDAMO_H #include -#include #include #include #include "../global.h" #include "SDL.h" #include "../map.h" -#include "CSemiDefHandler.h" #include "CDefHandler.h" #include "CCreatureHandler.h" @@ -18,23 +16,17 @@ class CAmbarCendamo public: /////////////////member variables Mapa map; - std::ifstream * is; // stream used to read map file - int andame; // length of map file + + //map file unsigned char * bufor; // here we store map bytecode - std::vector defs; -/////////////////member functions + int i; //our pos in the file + CAmbarCendamo (const char * tie); // c-tor; tie is the path of the map file CAmbarCendamo (unsigned char * map); // c-tor; map is pointer to array containing map; it is not copied, so don't delete ~CAmbarCendamo (); // d-tor int readNormalNr (int pos, int bytCon=4, bool cyclic = false); //read number from bytCon bytes starting from pos position in buffer ; if cyclic is true, number is treated as it were signed number with bytCon bytes - void teceDef (); // create files with info about defs void deh3m(); // decode file, results are stored in map - void processMap(std::vector & defsToUnpack); //choose castles, creatures, resources, artifacts... - //// - std::vector resDefNames; - //// - void loadDefs(); EDefType getDefType(CGDefInfo * a); //returns type of object in def - CCreatureSet readCreatureSet(int pos, int number = 7); //reads creature set in most recently encountered format; reades number units (default is 7) + CCreatureSet readCreatureSet(int number = 7); //reads creature set in most recently encountered format; reades number units (default is 7) }; #endif //CAMBARCENDAMO_H \ No newline at end of file diff --git a/hch/CCastleHandler.h b/hch/CCastleHandler.h index e397357bd..b017b4712 100644 --- a/hch/CCastleHandler.h +++ b/hch/CCastleHandler.h @@ -31,8 +31,6 @@ public: bool unusualBuildins; //if true, intrepret bytes below unsigned char buildingSettings[12]; //raw format for two vectors above (greatly depends on town type) bool hasFort; //used only if unusualBuildings is false - CHero * visitingHero; - CHero * garnisonHero; unsigned char bytes[4]; //identifying bytes unsigned char player; //255 - nobody, players 0 - 7 diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index 30ee3afab..b3331433b 100644 --- a/hch/CCreatureHandler.cpp +++ b/hch/CCreatureHandler.cpp @@ -610,422 +610,4 @@ void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int break; } i+=2; -} - -void CCreatureHandler::loadUnitAnimations() -{ - //std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod - //inp.seekg(0,std::ios::end); // na koniec - //int andame = inp.tellg(); // read length - //inp.seekg(0,std::ios::beg); // wracamy na poczatek - //char * bufor = new char[andame]; // allocate memory - //inp.read((char*)bufor, andame); // read map file to buffer - //inp.close(); - //std::string buf = std::string(bufor); - //delete [andame] bufor; - - //int i = 0; //buf iterator - //int hmcr = 0; - //for(i; ispriteh->giveDef(defName); - // else - // creatures[s].battleAnimation = NULL; - // i+=2; - //} -} - -int CCreatureAnimation::getType() const -{ - return type; -} - -void CCreatureAnimation::setType(int type) -{ - this->type = type; - curFrame = 0; - if(type!=-1) - { - if(SEntries[curFrame].group!=type) //rewind - { - int j=-1; //first frame in displayed group - for(int g=0; g=frames) - curFrame = 0; - } -} - -CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEntries(NULL) -{ - //load main file - std::string data2 = CGI->spriteh->getTextFile(name); - if(data2.size()==0) - throw new std::string("no such def!"); - FDef = new unsigned char[data2.size()]; - for(int g=0; g=amp/2) - { - ret = ret-amp; - } - return ret; -} -int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect) -{ - return nextFrame(dest,x-fullWidth/2,y-fullHeight/2,attacker,incrementFrame,yellowBorder,destRect); -} -int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect) -{ - if(dest->format->BytesPerPixel<3) - return -1; //not enough depth - - //increasing frame numer - int SIndex = -1; - if(incrementFrame) - { - SIndex = curFrame++; - if(type!=-1) - { - if(SEntries[curFrame].group!=type) //rewind - { - int j=-1; //first frame in displayed group - for(int g=0; g=frames) - curFrame = 0; - } - } - else - { - SIndex = curFrame; - } - //frame number increased - - long BaseOffset, - SpriteWidth, SpriteHeight, //sprite format - LeftMargin, RightMargin, TopMargin,BottomMargin, - i, add, FullHeight,FullWidth, - TotalRowLength, // length of read segment - RowAdd; - unsigned char SegmentType, SegmentLength; - - i=BaseOffset=SEntries[SIndex].offset; - int prSize=readNormalNr(i,4,FDef);i+=4; - int defType2 = readNormalNr(i,4,FDef);i+=4; - FullWidth = readNormalNr(i,4,FDef);i+=4; - FullHeight = readNormalNr(i,4,FDef);i+=4; - SpriteWidth = readNormalNr(i,4,FDef);i+=4; - SpriteHeight = readNormalNr(i,4,FDef);i+=4; - LeftMargin = readNormalNr(i,4,FDef);i+=4; - TopMargin = readNormalNr(i,4,FDef);i+=4; - RightMargin = FullWidth - SpriteWidth - LeftMargin; - BottomMargin = FullHeight - SpriteHeight - TopMargin; - - add = 4 - FullWidth%4; - - int BaseOffsetor = BaseOffset = i; - - int ftcp = 0; - - if (defType2==1) //as it should be allways in creature animations - { - if (TopMargin>0) - { - for (int i=0;i0) - { - ftcp+=LeftMargin; - } - TotalRowLength=0; - do - { - SegmentType=FDef[BaseOffset++]; - SegmentLength=FDef[BaseOffset++]; - if (SegmentType==0xFF) - { - for (int k=0;k<=SegmentLength;k++) - { - int xB = (attacker ? ftcp%(FullWidth+add) : (FullWidth+add) - ftcp%(FullWidth+add) - 1) + x; - int yB = ftcp/(FullWidth+add) + y; - if(xB>=0 && yB>=0 && xBw && yBh) - { - if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB)) - putPixel(dest, xB + yB*dest->w, palette[FDef[BaseOffset+k]], FDef[BaseOffset+k], yellowBorder); - } - ftcp++; //increment pos - if ((TotalRowLength+k+1)>=SpriteWidth) - break; - } - BaseOffset+=SegmentLength+1;//// - TotalRowLength+=SegmentLength+1; - } - else - { - for (int k=0;k=0 && yB>=0 && xBw && yBh) - { - if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB)) - putPixel(dest, xB + yB*dest->w, palette[SegmentType], SegmentType, yellowBorder); - } - ftcp++; //increment pos - } - TotalRowLength+=SegmentLength+1; - } - }while(TotalRowLength0) - { - ftcp+=RightMargin; - } - if (add>0) - { - ftcp+=add+RowAdd; - } - } - delete [] RLEntries; - RLEntries = NULL; - if (BottomMargin>0) - { - ftcp += BottomMargin * (FullWidth+add); - } - } - - //SDL_UpdateRect(dest, x, y, FullWidth+add, FullHeight); - - return 0; -} - -int CCreatureAnimation::framesInGroup(int group) const -{ - int ret = 0; //number of frames in given group - for(int g=0; gpixels + ftcp*3; - if(palc > 7) //normal color - { - p[0] = color.B; - p[1] = color.G; - p[2] = color.R; - } - else if(yellowBorder && (palc == 6 || palc == 7)) //dark yellow border - { - p[0] = 0; - p[1] = 0xff; - p[2] = 0xff; - } - else if(yellowBorder && (palc == 5)) //yellow border - { - p[0] = color.B; - p[1] = color.G; - p[2] = color.R; - } - else if(palc < 5) //shadow - { - Uint16 alpha; - switch(color.G) - { - case 0: - alpha = 128; - break; - case 50: - alpha = 50+32; - break; - case 100: - alpha = 100+64; - break; - case 125: - alpha = 125+64; - break; - case 128: - alpha = 128+64; - break; - case 150: - alpha = 150+64; - break; - default: - alpha = 255; - break; - } - //alpha counted - p[0] = (p[0] * alpha)>>8; - p[1] = (p[1] * alpha)>>8; - p[2] = (p[2] * alpha)>>8; - } - } -} +} \ No newline at end of file diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index ea1c0e137..244eb6483 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -1,11 +1,10 @@ #ifndef CCREATUREHANDLER_H #define CCREATUREHANDLER_H -#include "../CPlayerInterface.h" #include #include #include -#include "CDefHandler.h" +#include class CDefHandler; struct SDL_Surface; @@ -51,8 +50,6 @@ class CCreatureSet //seven combined creatures { public: std::map > slots; - //CCreature * slot1, * slot2, * slot3, * slot4, * slot5, * slot6, * slot7; //types of creatures on each slot - //unsigned int s1, s2, s3, s4, s5, s6, s7; //amounts of units in slots bool formation; //false - wide, true - tight }; @@ -68,48 +65,5 @@ public: void loadCreatures(); void loadAnimationInfo(); void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i); - void loadUnitAnimations(); }; - -class CCreatureAnimation : public CIntObject -{ -private: - int totalEntries, DEFType, totalBlocks; - bool allowRepaint; - int length; - BMPPalette palette[256]; - unsigned int * RWEntries; - int * RLEntries; - struct SEntry - { - std::string name; - int offset; - int group; - } ; - std::vector SEntries ; - char id[2]; - std::string defName, curDir; - int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false); - void putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const; - - //////////// - - unsigned char * FDef; //animation raw data - unsigned int curFrame; //number of currently displayed frame - unsigned int frames; //number of frames - int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1]) -public: - int fullWidth, fullHeight; //read-only, please! - CCreatureAnimation(std::string name); //c-tor - ~CCreatureAnimation(); //d-tor - - void setType(int type); //sets type of animation and cleares framecount - int getType() const; //returns type of animation - - int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next - int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next - - int framesInGroup(int group) const; //retirns number of fromes in given group -}; - #endif //CCREATUREHANDLER_H \ No newline at end of file diff --git a/hch/CDefHandler.h b/hch/CDefHandler.h index e278fc62de7ac6dd5fcd8a7fc99de1c6677f8cc8..f97320602e0ea3bc2c243926c0e758e3e582e0ab 100644 GIT binary patch delta 171 zcmX>ny+dk3+vGA9iOC0egf_l;#yGi)S;*X(A(J7OA(0`SA(erbfs3IUOmYH6^B77P z6oBGI4EYSD3O%Gs8$~c^PqeMhH{`8B@7v0 q-5`@v87hGMRG^AtpiDkP-ehhrW$q-fDv%2bCf75|ZkA)&zzG0k^Cg!6 delta 250 zcmdlXbxwLh+r%UhPG^Q-hE#@JhRn$ynMF6&NHIz4GiWjJGH@{zGn6nCF_bbS18D^Y z7Y0`bw~1#J%}W?6847?}bbx~844DimK%lWaEFPzHCnI*_&1V9PmyCgp)G_5@lDvMUqF139!9%qs=T jW&?3P&<%MEhFHXm7_7l2)dFcP2K|W}WjFURui^v%cib@r diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 8fd582feb..e1f1242db 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -18,6 +18,7 @@ class CTown; class CHero; class CBuilding; class CSpell; +class CGTownInstance; class CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes { }; diff --git a/hch/CSemiDefHandler.cpp b/hch/CSemiDefHandler.cpp deleted file mode 100644 index 2d0b0d6ff..000000000 --- a/hch/CSemiDefHandler.cpp +++ /dev/null @@ -1,148 +0,0 @@ -#include "../stdafx.h" -#include "CSemiDefHandler.h" -#include -#include "SDL_image.h" -extern SDL_Surface * screen; -std::string CSemiDefHandler::nameFromType (EterrainType typ) -{ - switch(typ) - { - case dirt: - { - return std::string("DIRTTL.DEF"); - break; - } - case sand: - { - return std::string("SANDTL.DEF"); - break; - } - case grass: - { - return std::string("GRASTL.DEF"); - break; - } - case snow: - { - return std::string("SNOWTL.DEF"); - break; - } - case swamp: - { - return std::string("SWMPTL.DEF"); - break; - } - case rough: - { - return std::string("ROUGTL.DEF"); - break; - } - case subterranean: - { - return std::string("SUBBTL.DEF"); - break; - } - case lava: - { - return std::string("LAVATL.DEF"); - break; - } - case water: - { - return std::string("WATRTL.DEF"); - break; - } - case rock: - { - return std::string("ROCKTL.DEF"); - break; - } - } - return std::string(); -} -void CSemiDefHandler::openDef(std::string name, std::string lodName, int dist) -{ - std::ifstream * is = new std::ifstream(); - is -> open((lodName+"\\"+name).c_str(),std::ios::binary); - is->seekg(0,std::ios::end); // na koniec - int andame = is->tellg(); // read length - is->seekg(0,std::ios::beg); // wracamy na poczatek - buforD = new unsigned char[andame]; // allocate memory - is->read((char*)buforD, andame); // read map file to buffer - defName = name; - int gdzie = defName.find_last_of("\\"); - defName = defName.substr(gdzie+1, gdzie-defName.length()); - delete is; - - readFileList(dist); - loadImages(lodName); - -} -CSemiDefHandler::~CSemiDefHandler() -{ - for (int i=0;iw; - dest.h = image->h; - SDL_BlitSurface(image, NULL, ekran, &dest); - SDL_UpdateRects(ekran, 1, &dest); - SDL_FreeSurface(image); -} -void CSemiDefHandler::openImg(const char *name) -{ - SDL_Surface *image; - image=IMG_Load(name); - //SDL_DisplayBitmap(name,image, 0,0); - if(!image) - { - printf("IMG_Load: %s\n", IMG_GetError()); - return; - // handle error - } - Cimage vinya; - vinya.bitmap = image; - SDL_SetColorKey(vinya.bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(vinya.bitmap->format,0,255,255)); - vinya.imName = name; - ourImages.push_back(vinya); -} diff --git a/hch/CSemiDefHandler.h b/hch/CSemiDefHandler.h deleted file mode 100644 index 2abaca0cc..000000000 --- a/hch/CSemiDefHandler.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef SEMIDEF_H -#define SEMIDEF_H -#include "../global.h" -#include -#include "SDL.h" -//#include "SDL_image.h" -#include - -struct Cimage -{ - int groupNumber; - std::string imName; //name without extension - SDL_Surface * bitmap; -}; -class CSemiDefHandler -{ -public: - int howManyImgs; - std::string defName; - std::vector ourImages; - std::vector namesOfImgs; - unsigned char * buforD; - - static std::string nameFromType(EterrainType typ); - void openImg(const char *name); - void openDef(std::string name, std::string lodName, int dist=1); - void readFileList(int dist = 1); - void loadImages(std::string path); - ~CSemiDefHandler(); -}; -#endif // SEMIDEF_H \ No newline at end of file diff --git a/hch/CSemiLodHandler.cpp b/hch/CSemiLodHandler.cpp deleted file mode 100644 index 1043774d4..000000000 --- a/hch/CSemiLodHandler.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "../stdafx.h" -#include "CSemiLodHandler.h" -void CSemiLodHandler::openLod(std::string path) -{ - ourName = path; -}; -CSemiDefHandler * CSemiLodHandler::giveDef(std::string name, int dist) -{ - CSemiDefHandler * ret = new CSemiDefHandler(); - ret->openDef(name, ourName, dist); - return ret; -}; \ No newline at end of file diff --git a/hch/CSemiLodHandler.h b/hch/CSemiLodHandler.h deleted file mode 100644 index 9d8368757..000000000 --- a/hch/CSemiLodHandler.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef CSEMILODHANDLER_H -#define CSEMILODHANDLER_H - -#include "CSemiDefHandler.h" -class CSemiLodHandler -{ -public: - std::string ourName; // name of our lod - void openLod(std::string path); - CSemiDefHandler * giveDef(std::string name, int dist=1); //loads def from our lod -}; - -#endif //CSEMILODHANDLER_H \ No newline at end of file diff --git a/map.cpp b/map.cpp index ade921fc4..6de1bffc9 100644 --- a/map.cpp +++ b/map.cpp @@ -12,15 +12,6 @@ int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4) } return ret; } -bool DefInfo::isVisitable() -{ - for (int i=6; i<12; i++) - { - if (bytes[i]) - return true; - } - return false; -} CMapHeader::CMapHeader(unsigned char *map) { this->version = (Eformat)map[0]; //wersja mapy diff --git a/map.h b/map.h index 1125e5023..5c253cc6a 100644 --- a/map.h +++ b/map.h @@ -3,9 +3,8 @@ #pragma warning (disable : 4482) #include #include +#include #include "global.h" -#include "hch\CSemiDefHandler.h" -#include "hch\CDefHandler.h" class CGDefInfo; class CHeroObjInfo; enum ESortBy{name,playerAm,size,format, viccon,loscon}; @@ -25,24 +24,6 @@ struct TimeEvent bool areCompsAffected; int firstAfterNDays; //how many days after appears this event int nextAfterNDays; //how many days after the epperance before appaers this event -//bajty wydarzeń (59 + |teksty|) -//4 bajty na długość nazwy zdarzenia -//nazwa zdarzenia (bajty dodatkowe) -//4 bajty na długość wiadomości -//wiadomość (bajty dodatkowe) -//4 bajty na zwiększenie się ilosci drewna (zapis normalny) lub ff,ff,ff,ff - ilość drewna do odebrania (maksymalna ilość drewna, którą można dać/odebrać to 32767) -//4 bajty na zwiększenie się ilosci rtęci (zapis normalny) lub ff,ff,ff,ff - ilość rtęci do odebrania (maksymalna ilość rtęci, którą można dać/odebrać to 32767) -//4 bajty na zwiększenie się ilosci rudy (zapis normalny) lub ff,ff,ff,ff - ilość rudy do odebrania (maksymalna ilość rudy, którą można dać/odebrać to 32767) -//4 bajty na zwiększenie się ilosci siarki (zapis normalny) lub ff,ff,ff,ff - ilość siarki do odebrania (maksymalna ilość siarki, którą można dać/odebrać to 32767) -//4 bajty na zwiększenie się ilosci kryształu (zapis normalny) lub ff,ff,ff,ff - ilość kryształu do odebrania (maksymalna ilość kryształu, którą można dać/odebrać to 32767) -//4 bajty na zwiększenie się ilosci klejnotów (zapis normalny) lub ff,ff,ff,ff - ilość klejnotów do odebrania (maksymalna ilość klejnotów, którą można dać/odebrać to 32767) -//4 bajty na zwiększenie się ilosci złota (zapis normalny) lub ff,ff,ff,ff - ilość złota do odebrania (maksymalna ilość złota, którą można dać/odebrać to 32767) -//1 bajt - których graczy dotyczy zdarzenie (pole bitowe, +1 - pierwszy, +2 - drugi, +4 - trzeci, +8 - czwarty, +16 - piąty, +32 - szósty, +64 - siódmy, +128 - ósmy) -//1 bajt - czy zdarzenie odnosi się do graczy - ludzi (00 - nie, 01 - tak) -//1 bajt - czy zdarzenie odnosi się do graczy komputerowych (00 - nie, 01 - tak) -//2 bajty - opóźnienie pierwszego wystąpienia (w dniach, zapis normalny, maks 671) -//1 bajt - co ile dni występuje zdarzenie (maks 28, 00 oznacza zdarzenie jednorazowe) -//17 bajtów zerowych }; struct TerrainTile { @@ -54,16 +35,6 @@ struct TerrainTile unsigned char roadDir; // direction of Eroad unsigned char siodmyTajemniczyBajt; // mysterius byte // jak bedzie waidomo co to, to sie nazwie inaczej }; -struct DefInfo //information from def declaration -{ - std::string name; - int bytes [42]; - //CSemiDefHandler * handler; - CDefHandler * handler; - int printPriority; - bool isOnDefList; - bool isVisitable(); -}; struct SheroName //name of starting hero { int heroID; diff --git a/mapHandler.cpp b/mapHandler.cpp index cbe987776..b6f122d3b 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" #include "mapHandler.h" -#include "hch\CSemiDefHandler.h" #include "SDL_rotozoom.h" #include "SDL_Extensions.h" #include "CGameInfo.h" @@ -16,7 +15,63 @@ #include #include extern SDL_Surface * screen; - +std::string nameFromType (EterrainType typ) +{ + switch(typ) + { + case dirt: + { + return std::string("DIRTTL.DEF"); + break; + } + case sand: + { + return std::string("SANDTL.DEF"); + break; + } + case grass: + { + return std::string("GRASTL.DEF"); + break; + } + case snow: + { + return std::string("SNOWTL.DEF"); + break; + } + case swamp: + { + return std::string("SWMPTL.DEF"); + break; + } + case rough: + { + return std::string("ROUGTL.DEF"); + break; + } + case subterranean: + { + return std::string("SUBBTL.DEF"); + break; + } + case lava: + { + return std::string("LAVATL.DEF"); + break; + } + case water: + { + return std::string("WATRTL.DEF"); + break; + } + case rock: + { + return std::string("ROCKTL.DEF"); + break; + } + } + return std::string(); +} class OCM_HLP { public: @@ -616,14 +671,14 @@ void CMapHandler::borderAndTerrainBitmapInit() //TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff]; std::string name; if (k>0) - name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i][j].tertype); + name = nameFromType(reader->map.undergroungTerrain[i][j].tertype); else - name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype); - for (unsigned int m=0; mdefs.size(); m++) + name = nameFromType(reader->map.terrain[i][j].tertype); + for (unsigned int m=0; mdefs[m]->defName != name) + if (defs[m]->defName != name) continue; else { @@ -632,7 +687,7 @@ void CMapHandler::borderAndTerrainBitmapInit() ktora = reader->map.terrain[i][j].terview; else ktora = reader->map.undergroungTerrain[i][j].terview; - ttiles[i][j][k].terbitmap.push_back(reader->defs[m]->ourImages[ktora].bitmap); + ttiles[i][j][k].terbitmap.push_back(defs[m]->ourImages[ktora].bitmap); int zz; if (k==0) zz = (reader->map.terrain[i][j].siodmyTajemniczyBajt)%4; @@ -1732,3 +1787,27 @@ unsigned char CMapHandler::getDir(const int3 &a, const int3 &b) } return -2; //shouldn't happen } + + +void CMapHandler::loadDefs() +{ + std::set loadedTypes; + for (int i=0; imap.width; i++) + { + for (int j=0; jmap.width; j++) + { + if (loadedTypes.find(reader->map.terrain[i][j].tertype)==loadedTypes.end()) + { + CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(reader->map.terrain[i][j].tertype).c_str()); + loadedTypes.insert(reader->map.terrain[i][j].tertype); + defs.push_back(sdh); + } + if (reader->map.twoLevel && loadedTypes.find(reader->map.undergroungTerrain[i][j].tertype)==loadedTypes.end()) + { + CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(reader->map.undergroungTerrain[i][j].tertype).c_str()); + loadedTypes.insert(reader->map.undergroungTerrain[i][j].tertype); + defs.push_back(sdh); + } + } + } +} \ No newline at end of file diff --git a/mapHandler.h b/mapHandler.h index a83499c2d..c0aeb7547 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -2,7 +2,6 @@ #define MAPHANDLER_H #include "hch\CAmbarCendamo.h" -#include "hch\CSemiDefHandler.h" #include "CGameInfo.h" #include "hch\CDefHandler.h" #include @@ -70,6 +69,7 @@ public: //std::vector< std::vector > undVisibility; //true means that pointed place is visible std::vector roadDefs; std::vector staticRiverDefs; + std::vector defs; std::map loadedDefs; //pointers to loaded defs (key is filename, uppercase) std::map villages, forts, capitols; @@ -78,6 +78,7 @@ public: PseudoV< PseudoV< PseudoV > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile + void loadDefs(); char & visAccess(int x, int y); char & undVisAccess(int x, int y); SDL_Surface mirrorImage(SDL_Surface *src); //what is this?? From 798fd11f658d7701529d50e7b9d431948bf2a667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sun, 8 Jun 2008 00:58:29 +0000 Subject: [PATCH 04/47] radical cleanups --- CCallback.cpp | 8 +- CHeroWindow.cpp | 51 +-- CHeroWindow.h | 4 +- CLua.cpp | 1 + CMT.cpp | 4 +- CPlayerInterface.cpp | 1 + global.h | 1 + hch/CAmbarCendamo.cpp | 801 ++++++++++--------------------------- hch/CAmbarCendamo.h | 2 + hch/CDefObjInfoHandler.cpp | 17 +- hch/CDefObjInfoHandler.h | 12 - hch/CObjectHandler.cpp | 7 +- hch/CObjectHandler.h | 128 +++--- map.h | 7 +- mapHandler.cpp | 6 +- 15 files changed, 323 insertions(+), 727 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index b03c2c612..b7750ac06 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -991,20 +991,20 @@ void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos== { if(!h->artifacts[i]) { - h->artifacts[i] = &CGI->arth->artifacts[artid]; + h->artifacts[i] = artid; return; } } - h->artifacts.push_back(&CGI->arth->artifacts[artid]); + h->artifacts.push_back(artid); return; } else { if(h->artifWorn[position]) //slot is occupied { - giveHeroArtifact(h->artifWorn[position]->id,hid,-1); + giveHeroArtifact(h->artifWorn[position],hid,-1); } - h->artifWorn[position] = &CGI->arth->artifacts[artid]; + h->artifWorn[position] = artid; } } diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 162826565..2eac173e4 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -12,6 +12,8 @@ #include "hch\CObjectHandler.h" #include "CMessage.h" #include "CCallback.h" +#include "hch/CArtHandler.h" +#include "hch\CAbilityHandler.h" #include extern SDL_Surface * screen; @@ -181,8 +183,9 @@ void CHeroWindow::show(SDL_Surface *to) } } -void CHeroWindow::setHero(const CGHeroInstance *hero) +void CHeroWindow::setHero(const CGHeroInstance *Hero) { + CGHeroInstance *hero = const_cast(Hero); //but don't modify hero! - it's only for easy map reading if(!hero) //something strange... no hero? it shouldn't happen { return; @@ -259,7 +262,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[8]->pos.y = 295; artWorn[8]->pos.h = artWorn[8]->pos.w = 44; if(hero->artifWorn[8]) - artWorn[8]->text = hero->artifWorn[8]->description; + artWorn[8]->text = hero->getArt(8)->description; else artWorn[8]->text = std::string(); artWorn[8]->ourWindow = this; @@ -270,7 +273,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[0]->pos.y = 30; artWorn[0]->pos.h = artWorn[0]->pos.w = 44; if(hero->artifWorn[0]) - artWorn[0]->text = hero->artifWorn[0]->description; + artWorn[0]->text = hero->getArt(0)->description; else artWorn[0]->text = std::string(); artWorn[0]->ourWindow = this; @@ -281,7 +284,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[4]->pos.y = 183; artWorn[4]->pos.h = artWorn[4]->pos.w = 44; if(hero->artifWorn[4]) - artWorn[4]->text = hero->artifWorn[4]->description; + artWorn[4]->text = hero->getArt(4)->description; else artWorn[4]->text = std::string(); artWorn[4]->ourWindow = this; @@ -292,7 +295,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[7]->pos.y = 183; artWorn[7]->pos.h = artWorn[7]->pos.w = 44; if(hero->artifWorn[7]) - artWorn[7]->text = hero->artifWorn[7]->description; + artWorn[7]->text = hero->getArt(7)->description; else artWorn[7]->text = std::string(); artWorn[7]->ourWindow = this; @@ -303,7 +306,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[13]->pos.y = 30; artWorn[13]->pos.h = artWorn[13]->pos.w = 44; if(hero->artifWorn[13]) - artWorn[13]->text = hero->artifWorn[13]->description; + artWorn[13]->text = hero->getArt(13)->description; else artWorn[13]->text = std::string(); artWorn[13]->ourWindow = this; @@ -314,7 +317,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[14]->pos.y = 30; artWorn[14]->pos.h = artWorn[14]->pos.w = 44; if(hero->artifWorn[14]) - artWorn[14]->text = hero->artifWorn[14]->description; + artWorn[14]->text = hero->getArt(14)->description; else artWorn[14]->text = std::string(); artWorn[14]->ourWindow = this; @@ -325,7 +328,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[15]->pos.y = 76; artWorn[15]->pos.h = artWorn[15]->pos.w = 44; if(hero->artifWorn[15]) - artWorn[15]->text = hero->artifWorn[15]->description; + artWorn[15]->text = hero->getArt(15)->description; else artWorn[15]->text = std::string(); artWorn[15]->ourWindow = this; @@ -336,7 +339,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[16]->pos.y = 122; artWorn[16]->pos.h = artWorn[16]->pos.w = 44; if(hero->artifWorn[16]) - artWorn[16]->text = hero->artifWorn[16]->description; + artWorn[16]->text = hero->getArt(16)->description; else artWorn[16]->text = std::string(); artWorn[16]->ourWindow = this; @@ -347,7 +350,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[9]->pos.y = 143; artWorn[9]->pos.h = artWorn[9]->pos.w = 44; if(hero->artifWorn[9]) - artWorn[9]->text = hero->artifWorn[9]->description; + artWorn[9]->text = hero->getArt(9)->description; else artWorn[9]->text = std::string(); artWorn[9]->ourWindow = this; @@ -358,7 +361,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[10]->pos.y = 194; artWorn[10]->pos.h = artWorn[10]->pos.w = 44; if(hero->artifWorn[10]) - artWorn[10]->text = hero->artifWorn[10]->description; + artWorn[10]->text = hero->getArt(10)->description; else artWorn[10]->text = std::string(); artWorn[10]->ourWindow = this; @@ -369,7 +372,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[11]->pos.y = 245; artWorn[11]->pos.h = artWorn[11]->pos.w = 44; if(hero->artifWorn[11]) - artWorn[11]->text = hero->artifWorn[11]->description; + artWorn[11]->text = hero->getArt(11)->description; else artWorn[11]->text = std::string(); artWorn[11]->ourWindow = this; @@ -380,7 +383,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[12]->pos.y = 296; artWorn[12]->pos.h = artWorn[12]->pos.w = 44; if(hero->artifWorn[12]) - artWorn[12]->text = hero->artifWorn[12]->description; + artWorn[12]->text = hero->getArt(12)->description; else artWorn[12]->text = std::string(); artWorn[12]->ourWindow = this; @@ -391,7 +394,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[18]->pos.y = 296; artWorn[18]->pos.h = artWorn[18]->pos.w = 44; if(hero->artifWorn[18]) - artWorn[18]->text = hero->artifWorn[18]->description; + artWorn[18]->text = hero->getArt(18)->description; else artWorn[18]->text = std::string(); artWorn[18]->ourWindow = this; @@ -402,7 +405,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[2]->pos.y = 79; artWorn[2]->pos.h = artWorn[2]->pos.w = 44; if(hero->artifWorn[2]) - artWorn[2]->text = hero->artifWorn[2]->description; + artWorn[2]->text = hero->getArt(2)->description; else artWorn[2]->text = std::string(); artWorn[2]->ourWindow = this; @@ -413,7 +416,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[3]->pos.y = 68; artWorn[3]->pos.h = artWorn[3]->pos.w = 44; if(hero->artifWorn[3]) - artWorn[3]->text = hero->artifWorn[3]->description; + artWorn[3]->text = hero->getArt(3)->description; else artWorn[3]->text = std::string(); artWorn[3]->ourWindow = this; @@ -424,7 +427,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[6]->pos.y = 68; artWorn[6]->pos.h = artWorn[6]->pos.w = 44; if(hero->artifWorn[6]) - artWorn[6]->text = hero->artifWorn[6]->description; + artWorn[6]->text = hero->getArt(6)->description; else artWorn[6]->text = std::string(); artWorn[6]->ourWindow = this; @@ -435,7 +438,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[1]->pos.y = 240; artWorn[1]->pos.h = artWorn[1]->pos.w = 44; if(hero->artifWorn[1]) - artWorn[1]->text = hero->artifWorn[1]->description; + artWorn[1]->text = hero->getArt(1)->description; else artWorn[1]->text = std::string(); artWorn[1]->ourWindow = this; @@ -446,7 +449,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[17]->pos.y = 310; artWorn[17]->pos.h = artWorn[17]->pos.w = 44; if(hero->artifWorn[17]) - artWorn[17]->text = hero->artifWorn[17]->description; + artWorn[17]->text = hero->getArt(17)->description; else artWorn[17]->text = std::string(); artWorn[17]->ourWindow = this; @@ -457,7 +460,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) artWorn[5]->pos.y = 130; artWorn[5]->pos.h = artWorn[5]->pos.w = 44; if(hero->artifWorn[5]) - artWorn[5]->text = hero->artifWorn[5]->description; + artWorn[5]->text = hero->getArt(5)->description; else artWorn[5]->text = std::string(); artWorn[5]->ourWindow = this; @@ -484,7 +487,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero) add->pos.y = 365; add->pos.h = add->pos.w = 44; if(sartifacts.size() && hero->artifacts[s]) - add->text = hero->artifacts[s]->description; + add->text = hero->getArt(s)->description; else add->text = std::string(); add->ourWindow = this; @@ -674,7 +677,7 @@ void CHeroWindow::leftArtRoller() for(int s=0; s<5 && sartifacts.size(); ++s) //set new data { - backpack[s]->ourArt = curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]; + backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]]; if(backpack[s]->ourArt) backpack[s]->text = backpack[s]->ourArt->description; else @@ -691,7 +694,7 @@ void CHeroWindow::rightArtRoller() for(int s=0; s<5 && sartifacts.size(); ++s) //set new data { - backpack[s]->ourArt = curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]; + backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ] ]; if(backpack[s]->ourArt) backpack[s]->text = backpack[s]->ourArt->description; else @@ -873,7 +876,7 @@ void CHeroWindow::redrawCurBack() CSDL_Ext::printAt(manastr.str(), 212, 247, GEOR16, zwykly, curBack); } -CArtPlace::CArtPlace(const CArtifact * const & art): ourArt(art), active(false), clicked(false), +CArtPlace::CArtPlace(int Art): ourArt(&CGI->arth->artifacts[Art]), active(false), clicked(false), spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false), warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false), misc5(false), feet(false), lRing(false), rRing(false), torso(false), diff --git a/CHeroWindow.h b/CHeroWindow.h index 85ae0faec..2adb74b9b 100644 --- a/CHeroWindow.h +++ b/CHeroWindow.h @@ -70,7 +70,7 @@ public: bool clicked; CHeroWindow * ourWindow; const CArtifact * ourArt; - CArtPlace(const CArtifact * const & art); + CArtPlace(int Art); void clickLeft (tribool down); void clickRight (tribool down); void activate(); @@ -117,7 +117,7 @@ public: int player; CHeroWindow(int playerColor); //c-tor ~CHeroWindow(); //d-tor - void setHero(const CGHeroInstance * hero); //sets main displayed hero + void setHero(const CGHeroInstance * Hero); //sets main displayed hero void activate(); //activates hero window; void deactivate(); //activates hero window; virtual void show(SDL_Surface * to = NULL); //shows hero window diff --git a/CLua.cpp b/CLua.cpp index dc5a9dcc0..9092487e7 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -13,6 +13,7 @@ #include #include "hch/CObjectHandler.h" #include "hch/CTownHandler.h" +#include "hch/CArtHandler.h" #include "CCallback.h" #include "hch/CGeneralTextHandler.h" #include diff --git a/CMT.cpp b/CMT.cpp index 3ca7bfcaf..e4b1b33e7 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -163,11 +163,11 @@ void initGameState(CGameInfo * cgi) switch (pom) { case 145: //catapult - vhi->artifWorn[16] = &CGI->arth->artifacts[3]; + vhi->artifWorn[16] = 3; break; default: pom-=145; - vhi->artifWorn[13+pom] = &CGI->arth->artifacts[4+pom]; + vhi->artifWorn[13+pom] = 4+pom; break; } continue; diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 5f2ce2ceb..2a6a70dc2 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -12,6 +12,7 @@ #include "hch/CLodHandler.h" #include "CPathfinder.h" #include +#include "hch/CAbilityHandler.h" #include "hch/CHeroHandler.h" #include "hch/CTownHandler.h" #include "SDL_framerate.h" diff --git a/global.h b/global.h index a785e85c5..f14e8d8e4 100644 --- a/global.h +++ b/global.h @@ -53,6 +53,7 @@ const int SKILL_QUANTITY=28; const int SKILL_PER_HERO=8; const int ARTIFACTS_QUANTITY=171; const int HEROES_QUANTITY=156; +const int SPELLS_QUANTITY=70; const int RESOURCE_QUANTITY=8; const int TERRAIN_TYPES=10; const int PRIMARY_SKILLS=4; diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index 8b735ab3c..0316cc837 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -422,10 +422,14 @@ void CAmbarCendamo::deh3m() } } } - //allowed heroes have been read - unsigned char aaa1=bufor[i], aaa2=bufor[i+1], aaa3=bufor[i+2]; - i+=31; //omitting 0s - //reading allowed artifacts //18 bytes + + i+=31; //omitting NULLS + + map.allowedArtifact.resize(ARTIFACTS_QUANTITY); + for(int x=0;xarth->artifacts.size()) + if((i-ist)*8+yy < ARTIFACTS_QUANTITY) { - if(c != (c|((unsigned char)intPow(2, yy)))) - CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = true; - else - CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = false; + if(c == (c|((unsigned char)intPow(2, yy)))) + map.allowedArtifact[(i-ist)*8+yy] = false; } } }//allowed artifacts have been read } - //reading allowed spells (9 bytes) + + map.allowedSpell.resize(SPELLS_QUANTITY); + for(int x=0;x=SoD) { + //reading allowed spells (9 bytes) ist=i; //starting i for loop for(i; ispellh->spells.size()) - { - if(c != (c|((unsigned char)intPow(2, yy)))) - CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = true; - else - CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = false; - } - } + if((i-ist)*8+yy < SPELLS_QUANTITY) + if(c == (c|((unsigned char)intPow(2, yy)))) + map.allowedSpell[(i-ist)*8+yy] = false; } - //allowed spells have been read + + //allowed hero's abilities (4 bytes) ist=i; //starting i for loop for(i; iabilh->abilities.size()) + if((i-ist)*8+yy < SKILL_QUANTITY) { - if(c != (c|((unsigned char)intPow(2, yy)))) - CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = true; - else - CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = false; + if(c == (c|((unsigned char)intPow(2, yy)))) + map.allowedAbilities[(i-ist)*8+yy] = false; } } } } - //allowed hero's abilities have been read - THC std::cout<<"\tReading header: "<type = CGI->heroh->heroes[z]; - bool isExp = bufor[i]; ++i; //true if hore's experience is greater than 0 - if(isExp) - { - spec->experience = readNormalNr(i); i+=4; - } + CGHeroInstance * cgh = new CGHeroInstance; + cgh->ID = 34; + cgh->subID = z; + if(readChar())//true if hore's experience is greater than 0 + { cgh->exp = readNormalNr(i); i+=4; } else - { - spec->experience = 0; - } - bool nonstandardAbilities = bufor[i]; ++i; //true if hero has specified abilities - if(nonstandardAbilities) + cgh->exp = 0; + if(readChar())//true if hero has specified abilities { int howMany = readNormalNr(i); i+=4; + cgh->secSkills.resize(howMany); for(int yy=0; yyabilities.push_back(CGameInfo::mainObj->abilh->abilities[readNormalNr(i, 1)]); ++i; - spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i; + cgh->secSkills[yy].first = readNormalNr(i, 1); ++i; + cgh->secSkills[yy].second = readNormalNr(i, 1); ++i; } } bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts) int artmask = map.version == RoE ? 0xff : 0xffff; int artidlen = map.version == RoE ? 1 : 2; - spec->artifWorn.resize(19); if(artSet) { - //head art //1 - int id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[0] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[0] = NULL; - //shoulders art //2 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[1] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[1] = NULL; - //neck art //3 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[2] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[2] = NULL; - //right hand art //4 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[3] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[3] = NULL; - //left hand art //5 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[4] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[4] = NULL; - //torso art //6 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[5] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[5] = NULL; - //right hand ring //7 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[6] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[6] = NULL; - //left hand ring //8 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[7] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[7] = NULL; - //feet art //9 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[8] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[8] = NULL; - //misc1 art //10 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[9] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[9] = NULL; - //misc2 art //11 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[10] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[10] = NULL; - //misc3 art //12 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[11] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[11] = NULL; - //misc4 art //13 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[12] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[12] = NULL; - //machine1 art //14 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[13] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[13] = NULL; - //machine2 art //15 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[14] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[14] = NULL; - //machine3 art //16 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[15] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[15] = NULL; + for(int pom=0;pom<16;pom++) + { + int id = readNormalNr(i, artidlen); i+=artidlen; + if(id!=artmask) + cgh->artifWorn[pom] = id; + } //misc5 art //17 if(map.version>=SoD) { i+=2; - /*id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artMisc5 = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artMisc5 = NULL;*/ + //int id = readNormalNr(i, artidlen); i+=artidlen; + //if(id!=artmask) + // spec->artifWorn[16] = id; } //spellbook - id = readNormalNr(i, artidlen); i+=artidlen; + int id = readNormalNr(i, artidlen); i+=artidlen; if(id!=artmask) - spec->artifWorn[17] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[17] = NULL; + cgh->artifWorn[17] = id; //19 //???what is that? gap in file or what? - it's probably fifth slot.. if(map.version>RoE) { id = readNormalNr(i, artidlen); i+=artidlen; if(id!=artmask) - spec->artifWorn[18] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[18] = NULL; + cgh->artifWorn[18] = id; } else i+=1; @@ -664,46 +566,14 @@ void CAmbarCendamo::deh3m() { id = readNormalNr(i, artidlen); i+=artidlen; if(id!=artmask) - spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[id])); - else - spec->artifacts.push_back(NULL); + cgh->artifacts.push_back(id); } } } //artifacts - else - { - spec->artifWorn[8] = NULL; - spec->artifWorn[0] = NULL; - spec->artifWorn[4] = NULL; - spec->artifWorn[7] = NULL; - spec->artifWorn[13] = NULL; - spec->artifWorn[14] = NULL; - spec->artifWorn[15] = NULL; - spec->artifWorn[16] = NULL; - spec->artifWorn[9] = NULL; - spec->artifWorn[10] = NULL; - spec->artifWorn[11] = NULL; - spec->artifWorn[12] = NULL; - spec->artifWorn[18] = NULL; - spec->artifWorn[2] = NULL; - spec->artifWorn[3] = NULL; - spec->artifWorn[6] = NULL; - spec->artifWorn[1] = NULL; - spec->artifWorn[17] = NULL; - spec->artifWorn[5] = NULL; - } - for(int t=spec->artifacts.size(); t<10; ++t) //it does make sense, even it is not obvious ;] - spec->artifacts.push_back(NULL); - int customBio = bufor[i++]; - if(customBio) - { - int length = readNormalNr(i); i+=4; - for (int zz=0; zzbiography+=bufor[i++]; - } - int sex = bufor[i++]; // 0xFF is default, 00 male, 01 female - bool areSpells = bufor[i]; ++i; - if(areSpells) //TODO: sprawdzić //seems to be ok - tow + if(readChar())//customBio + cgh->biography = readString(); + int sex = bufor[i++]; // 0xFF is default, 00 male, 01 female + if(readChar())//are spells { int ist = i; for(i; ispellh->spells.size()) + if((i-ist)*8+yy < SPELLS_QUANTITY) { if(c == (c|((unsigned char)intPow(2, yy)))) - spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy])); + cgh->spells.insert((i-ist)*8+yy); } } } } - int customPrimSkills = bufor[i++]; - if(customPrimSkills) + if(readChar())//customPrimSkills { - spec->attack = bufor[i++]; - spec->defence = bufor[i++]; - spec->power = bufor[i++]; - spec->knowledge = bufor[i++]; + cgh->primSkills.resize(4); + for(int xx=0;xx<4;xx++) + cgh->primSkills[xx] = bufor[i++]; } - else - { - spec->attack = -1; - spec->defence = -1; - spec->power = -1; - spec->knowledge = -1; - } - map.predefinedHeroes.push_back(spec); + map.predefinedHeroes.push_back(cgh); } break; } @@ -892,18 +753,18 @@ void CAmbarCendamo::deh3m() gabn = readNormalNr(i, 1); ++i; for(int oo = 0; ooabilities.push_back((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)]); ++i; + spec->abilities.push_back(readNormalNr(i, 1)); ++i; spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i; } int gart = readNormalNr(i, 1); ++i; //number of gained artifacts for(int oo = 0; ooartifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, (map.version == RoE ? 1 : 2))])); i+=(map.version == RoE ? 1 : 2); + spec->artifacts.push_back(readNormalNr(i, (map.version == RoE ? 1 : 2))); i+=(map.version == RoE ? 1 : 2); } int gspel = readNormalNr(i, 1); ++i; //number of gained spells for(int oo = 0; oospells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i; + spec->spells.push_back(readNormalNr(i, 1)); ++i; } int gcre = readNormalNr(i, 1); ++i; //number of gained creatures spec->creatures = readCreatureSet(gcre); @@ -919,192 +780,81 @@ void CAmbarCendamo::deh3m() } case EDefType::HERO_DEF: { - CHeroObjInfo * spec = new CHeroObjInfo; + CGHeroInstance * nhi = new CGHeroInstance; + (*(static_cast(nhi))) = *nobj; + delete nobj; + nobj=nhi; if(map.version>RoE) { - spec->bytes[0] = bufor[i]; ++i; - spec->bytes[1] = bufor[i]; ++i; - spec->bytes[2] = bufor[i]; ++i; - spec->bytes[3] = bufor[i]; ++i; + nhi->identifier = readNormalNr(i, 4); i+=4; } - spec->player = bufor[i]; ++i; + nhi->setOwner(bufor[i]); ++i; int typeBuf = readNormalNr(i, 1); ++i; - if(typeBuf==0xff) - spec->type = NULL; - else - spec->type = CGameInfo::mainObj->heroh->heroes[typeBuf]; - bool isName = bufor[i]; ++i; //true if hero has nonstandard name - if(isName) - { - int length = readNormalNr(i, 4); i+=4; - for(int gg=0; ggname+=bufor[i]; ++i; - } - } - else - spec->name = std::string(""); + + //we should already know type from subID + //if(typeBuf==0xff) + // spec->type = NULL; + //else + // spec->type = CGameInfo::mainObj->heroh->heroes[typeBuf]; + + if(readChar())//true if hero has nonstandard name + nhi->name = readString(); if(map.version>AB) { - bool isExp = bufor[i]; ++i; //true if hore's experience is greater than 0 - if(isExp) - { - spec->experience = readNormalNr(i); i+=4; - } + if(readChar())//true if hore's experience is greater than 0 + { nhi->exp = readNormalNr(i); i+=4; } else - spec->experience = 0; + nhi->exp = -1; } else - { - spec->experience = readNormalNr(i); i+=4; - } + { nhi->exp = readNormalNr(i); i+=4; } + bool portrait=bufor[i]; ++i; if (portrait) i++; //TODO read portrait nr, save, open - bool nonstandardAbilities = bufor[i]; ++i; //true if hero has specified abilities - if(nonstandardAbilities) + + if(readChar())//true if hero has specified abilities { int howMany = readNormalNr(i); i+=4; + nhi->secSkills.resize(howMany); for(int yy=0; yyabilities.push_back(CGameInfo::mainObj->abilh->abilities[readNormalNr(i, 1)]); ++i; - spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i; + nhi->secSkills[yy].first = readNormalNr(i, 1); ++i; + nhi->secSkills[yy].second = readNormalNr(i, 1); ++i; } } - bool standGarrison = bufor[i]; ++i; //true if hero has nonstandard garrison - spec->standardGarrison = standGarrison; - if(standGarrison) - { - spec->garrison = readCreatureSet(); - } - bool form = bufor[i]; ++i; //formation - spec->garrison.formation = form; + if(readChar())//true if hero has nonstandard garrison + nhi->army = readCreatureSet(); + nhi->army.formation =bufor[i]; ++i; //formation bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts) int artmask = map.version == RoE ? 0xff : 0xffff; int artidlen = map.version == RoE ? 1 : 2; - spec->artifWorn.resize(19); if(artSet) { - //head art //1 - int id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[0] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[0] = NULL; - //shoulders art //2 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[1] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[1] = NULL; - //neck art //3 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[2] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[2] = NULL; - //right hand art //4 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[3] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[3] = NULL; - //left hand art //5 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[4] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[4] = NULL; - //torso art //6 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[5] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[5] = NULL; - //right hand ring //7 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[6] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[6] = NULL; - //left hand ring //8 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[7] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[7] = NULL; - //feet art //9 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[8] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[8] = NULL; - //misc1 art //10 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[9] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[9] = NULL; - //misc2 art //11 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[10] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[10] = NULL; - //misc3 art //12 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[11] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[11] = NULL; - //misc4 art //13 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[12] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[12] = NULL; - //machine1 art //14 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[13] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[13] = NULL; - //machine2 art //15 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[14] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[14] = NULL; - //machine3 art //16 - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artifWorn[15] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[15] = NULL; + for(int pom=0;pom<16;pom++) + { + int id = readNormalNr(i, artidlen); i+=artidlen; + if(id!=artmask) + nhi->artifWorn[pom] = id; + } //misc5 art //17 if(map.version>=SoD) { i+=2; - /*id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - spec->artMisc5 = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artMisc5 = NULL;*/ + //int id = readNormalNr(i, artidlen); i+=artidlen; + //if(id!=artmask) + // spec->artifWorn[16] = id; } //spellbook - id = readNormalNr(i, artidlen); i+=artidlen; + int id = readNormalNr(i, artidlen); i+=artidlen; if(id!=artmask) - spec->artifWorn[17] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[17] = NULL; + nhi->artifWorn[17] = id; //19 //???what is that? gap in file or what? - it's probably fifth slot.. if(map.version>RoE) { id = readNormalNr(i, artidlen); i+=artidlen; if(id!=artmask) - spec->artifWorn[18] = &(CGameInfo::mainObj->arth->artifacts[id]); - else - spec->artifWorn[18] = NULL; + nhi->artifWorn[18] = id; } else i+=1; @@ -1116,56 +866,28 @@ void CAmbarCendamo::deh3m() { id = readNormalNr(i, artidlen); i+=artidlen; if(id!=artmask) - spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[id])); - else - spec->artifacts.push_back(NULL); + nhi->artifacts.push_back(id); } } } //artifacts - else - { - spec->artifWorn[8] = NULL; - spec->artifWorn[0] = NULL; - spec->artifWorn[4] = NULL; - spec->artifWorn[7] = NULL; - spec->artifWorn[13] = NULL; - spec->artifWorn[14] = NULL; - spec->artifWorn[15] = NULL; - spec->artifWorn[16] = NULL; - spec->artifWorn[9] = NULL; - spec->artifWorn[10] = NULL; - spec->artifWorn[11] = NULL; - spec->artifWorn[12] = NULL; - spec->artifWorn[18] = NULL; - spec->artifWorn[2] = NULL; - spec->artifWorn[3] = NULL; - spec->artifWorn[6] = NULL; - spec->artifWorn[1] = NULL; - spec->artifWorn[17] = NULL; - spec->artifWorn[5] = NULL; - } - for(int t=spec->artifacts.size(); t<10; ++t) //it does make sense, even it is not obvious ;] - spec->artifacts.push_back(NULL); - spec->guardRange = readNormalNr(i, 1); ++i; - if(spec->guardRange == 0xff) - spec->isGuarding = false; - else - spec->isGuarding = true; + nhi->patrolRadious = readNormalNr(i, 1); ++i; + if(nhi->patrolRadious == 0xff) + nhi->patrolRadious = -1; + if(map.version>RoE) { - bool hasBiography = bufor[i]; ++i; //true if hero has nonstandard (mapmaker defined) biography - if(hasBiography) + if(readChar())//true if hero has nonstandard (mapmaker defined) biography { int length = readNormalNr(i); i+=4; int iStart = i; i+=length; for(int bb=0; bbbiography+=bufor[iStart+bb]; + nhi->biography+=bufor[iStart+bb]; } } - spec->sex = !(bufor[i]); ++i; + nhi->sex = !(bufor[i]); ++i; } //spells if(map.version>AB) @@ -1180,10 +902,10 @@ void CAmbarCendamo::deh3m() unsigned char c = bufor[i]; for(int yy=0; yy<8; ++yy) { - if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size()) + if((i-ist)*8+yy < SPELLS_QUANTITY) { if(c == (c|((unsigned char)intPow(2, yy)))) - spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy])); + nhi->spells.insert((i-ist)*8+yy); } } } @@ -1194,86 +916,25 @@ void CAmbarCendamo::deh3m() unsigned char buff = bufor[i]; ++i; if(buff!=254) { - spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[buff])); + nhi->spells.insert(buff); } } //spells loaded if(map.version>AB) { - spec->defaultMainStats = bufor[i]; ++i; - if(spec->defaultMainStats) + if(readChar())//customPrimSkills { - spec->attack = bufor[i]; ++i; - spec->defence = bufor[i]; ++i; - spec->power = bufor[i]; ++i; - spec->knowledge = bufor[i]; ++i; + nhi->primSkills.resize(4); + for(int xx=0;xx<4;xx++) + nhi->primSkills[xx] = bufor[i++]; } - else - { - spec->attack = -1; - spec->defence = -1; - spec->power = -1; - spec->knowledge = -1; - } - } - else - { - spec->attack = -1; - spec->defence = -1; - spec->power = -1; - spec->knowledge = -1; } i+=16; - nobj->info = spec; - //////creating CHeroInstance - CGHeroInstance * nhi = new CGHeroInstance; - (*(static_cast(nhi))) = *nobj; - delete nobj; - nobj=nhi; - spec->myInstance = nhi; - //nobj->isHero = true; - (static_cast(nobj))->moveDir = 4; + nhi->moveDir = 4; nhi->isStanding = true; - nhi->exp = spec->experience; - nhi->level = CGI->heroh->level(nhi->exp); - nhi->primSkills.resize(PRIMARY_SKILLS); - nhi->artifWorn.resize(19); - nhi->primSkills[0] = spec->attack; - nhi->primSkills[1] = spec->defence; - nhi->primSkills[2] = spec->power; - nhi->primSkills[3] = spec->knowledge; - nhi->mana = spec->knowledge * 10; + nhi->level = -1; + nhi->mana = -1; nhi->movement = -1; - nhi->name = spec->name; - nhi->setOwner(spec->player); - nhi->pos = nobj->pos; - nhi->type = spec->type; - nhi->army = spec->garrison; - nhi->portrait = -1; // TODO: przypisywac portret - nhi->artifWorn[8] = spec->artifWorn[8]; - nhi->artifWorn[0] = spec->artifWorn[0]; - nhi->artifacts = spec->artifacts; - nhi->artifWorn[4] = spec->artifWorn[4]; - nhi->artifWorn[7] = spec->artifWorn[7]; - nhi->artifWorn[13] = spec->artifWorn[13]; - nhi->artifWorn[14] = spec->artifWorn[14]; - nhi->artifWorn[15] = spec->artifWorn[15]; - nhi->artifWorn[16] = spec->artifWorn[16] = new CArtifact(CGI->arth->artifacts[3]); - nhi->artifWorn[9] = spec->artifWorn[9]; - nhi->artifWorn[10] = spec->artifWorn[10]; - nhi->artifWorn[11] = spec->artifWorn[11]; - nhi->artifWorn[12] = spec->artifWorn[12]; - nhi->artifWorn[18] = spec->artifWorn[18]; - nhi->artifWorn[2] = spec->artifWorn[2]; - nhi->artifWorn[3] = spec->artifWorn[3]; - nhi->artifWorn[6] = spec->artifWorn[6]; - nhi->artifWorn[1] = spec->artifWorn[1]; - nhi->artifWorn[17] = spec->artifWorn[17]; - nhi->artifWorn[5] = spec->artifWorn[5]; - for(int qq=0; qqabilities.size(); ++qq) - { - nhi->secSkills.push_back(std::make_pair(spec->abilities[qq]->idNumber, spec->abilityLevels[qq]-1)); - } if(nhi->ID==34) CGI->heroh->heroInstances.push_back(nhi); else @@ -1315,16 +976,16 @@ void CAmbarCendamo::deh3m() if(map.version==RoE) { if(artID!=0xff) - spec->gainedArtifact = &(CGameInfo::mainObj->arth->artifacts[artID]); + spec->gainedArtifact = artID; else - spec->gainedArtifact = NULL; + spec->gainedArtifact = -1; } else { if(artID!=0xffff) - spec->gainedArtifact = &(CGameInfo::mainObj->arth->artifacts[artID]); + spec->gainedArtifact = artID; else - spec->gainedArtifact = NULL; + spec->gainedArtifact = -1; } } spec->neverFlees = bufor[i]; ++i; @@ -1435,7 +1096,7 @@ void CAmbarCendamo::deh3m() for(int yy=0; yym5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid])); + spec->m5arts.push_back(artid); } int limit = readNormalNr(i); i+=4; if(limit == ((int)0xffffffff)) @@ -1553,7 +1214,7 @@ void CAmbarCendamo::deh3m() int artID = bufor[i]; ++i; if(artID!=255) //not none quest { - spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artID])); + spec->m5arts.push_back(artID); spec->missionType = 5; } else @@ -1604,35 +1265,30 @@ void CAmbarCendamo::deh3m() } case 7: { - int abid = bufor[i]; ++i; - spec->r7ability = CGameInfo::mainObj->abilh->abilities[abid]; + spec->r7ability = bufor[i]; ++i; spec->r7level = bufor[i]; ++i; break; } case 8: { - int artid = readNormalNr(i, (map.version == RoE ? 1 : 2)); i+=(map.version == RoE ? 1 : 2); - spec->r8art = &(CGameInfo::mainObj->arth->artifacts[artid]); + spec->r8art = readNormalNr(i, (map.version == RoE ? 1 : 2)); i+=(map.version == RoE ? 1 : 2); break; } case 9: { - int spellid = bufor[i]; ++i; - spec->r9spell = &(CGameInfo::mainObj->spellh->spells[spellid]); + spec->r9spell = bufor[i]; ++i; break; } case 10: { if(map.version>RoE) { - int creid = readNormalNr(i, 2); i+=2; - spec->r10creature = &(CGameInfo::mainObj->creh->creatures[creid]); + spec->r10creature = readNormalNr(i, 2); i+=2; spec->r10amount = readNormalNr(i, 2); i+=2; } else { - int creid = bufor[i]; ++i; - spec->r10creature = &(CGameInfo::mainObj->creh->creatures[creid]); + spec->r10creature = bufor[i]; ++i; spec->r10amount = readNormalNr(i, 2); i+=2; } break; @@ -1658,19 +1314,19 @@ void CAmbarCendamo::deh3m() unsigned char c = bufor[i]; for(int yy=0; yy<8; ++yy) { - if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size()) + if((i-ist)*8+yy < SKILL_QUANTITY) { if(c == (c|((unsigned char)intPow(2, yy)))) - spec->allowedAbilities.push_back(CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]); + spec->allowedAbilities.push_back((i-ist)*8+yy); } } } } else //(RoE map) { - for(int gg=0; ggabilh->abilities.size(); ++gg) + for(int gg=0; ggallowedAbilities.push_back(CGameInfo::mainObj->abilh->abilities[gg]); + spec->allowedAbilities.push_back(gg); } } @@ -1690,10 +1346,10 @@ void CAmbarCendamo::deh3m() spec->r0type = bufor[i]; ++i; break; case 1: - spec->r1 = CGameInfo::mainObj->abilh->abilities[bufor[i]]; ++i; + spec->r1 = bufor[i]; ++i; break; case 2: - spec->r2 = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i; + spec->r2 = bufor[i]; ++i; break; } i+=6; @@ -1770,49 +1426,52 @@ void CAmbarCendamo::deh3m() } case EDefType::TOWN_DEF: { - CCastleObjInfo * spec = new CCastleObjInfo; - if(map.version!=RoE) - { - spec->bytes[0] = bufor[i]; ++i; - spec->bytes[1] = bufor[i]; ++i; - spec->bytes[2] = bufor[i]; ++i; - spec->bytes[3] = bufor[i]; ++i; + CCastleObjInfo * spec = new CCastleObjInfo; + CGTownInstance * nt = new CGTownInstance(); + (*(static_cast(nt))) = *nobj; + delete nobj; + nobj = nt; + nt->identifier = 0; + if(map.version>RoE) + { + readNormalNr(i); i+=4; } - else + nt->tempOwner = bufor[i]; ++i; + if(readChar()) //has name + nt->name = readString(); + if(readChar())//true if garrison isn't empty + nt->army = readCreatureSet(); + nt->army.formation = bufor[i]; ++i; + if(readChar()) //unusualBuildings { - spec->bytes[0] = 0; - spec->bytes[1] = 0; - spec->bytes[2] = 0; - spec->bytes[3] = 0; - } - spec->player = bufor[i]; ++i; - - bool hasName = bufor[i]; ++i; - if(hasName) - { - int len = readNormalNr(i); i+=4; - for(int gg=0; ggname += bufor[i]; ++i; + for(int bit=0;bit<8;bit++) + if(bufor[i] & (1<h3mbuildings.insert(byte*8+bit); + i++; } - } - bool stGarr = bufor[i]; ++i; //true if garrison isn't empty - if(stGarr) - { - spec->garrison = readCreatureSet(); - } - spec->garrison.formation = bufor[i]; ++i; - spec->unusualBuildins = bufor[i]; ++i; - if(spec->unusualBuildins) - { - for(int ff=0; ff<12; ++ff) + //forbidden buildings + for(int byte=6;byte<12;byte++) { - spec->buildingSettings[ff] = bufor[i]; ++i; + for(int bit=0;bit<8;bit++) + if(bufor[i] & (1<forbiddenBuildings.insert(byte*8+bit); + i++; } + nt->builtBuildings = convertBuildings(nt->h3mbuildings,nt->subID); + nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings,nt->subID); } - else + else //standard buildings { - spec->hasFort = bufor[i]; ++i; + if(readChar()) //has fort + nt->builtBuildings.insert(7); + nt->builtBuildings.insert(10); + nt->builtBuildings.insert(5); + nt->builtBuildings.insert(30); + if(rand()%2) + nt->builtBuildings.insert(31); } int ist = i; @@ -1823,10 +1482,10 @@ void CAmbarCendamo::deh3m() unsigned char c = bufor[i]; for(int yy=0; yy<8; ++yy) { - if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size()) + if((i-ist)*8+yy < SPELLS_QUANTITY) { if(c == (c|((unsigned char)intPow(2, yy)))) - spec->obligatorySpells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy])); + nt->obligatorySpells.push_back((i-ist)*8+yy); } } } @@ -1838,10 +1497,10 @@ void CAmbarCendamo::deh3m() unsigned char c = bufor[i]; for(int yy=0; yy<8; ++yy) { - if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size()) + if((i-ist)*8+yy < SPELLS_QUANTITY) { if(c != (c|((unsigned char)intPow(2, yy)))) - spec->possibleSpells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy])); + nt->possibleSpells.push_back((i-ist)*8+yy); } } } @@ -1897,76 +1556,19 @@ void CAmbarCendamo::deh3m() } i+=4; spec->events.push_back(nce); - } - spec->x = nobj->pos.x; - spec->y = nobj->pos.y; - spec->z = nobj->pos.z; - - /////// castle events have been read /////////////////////////// + }//castle events have been read if(map.version > AB) { - spec->alignment = bufor[i]; ++i; + nt->alignment = bufor[i]; ++i; } else - spec->alignment = 0xff; + nt->alignment = 0xff; i+=3; - nobj->info = spec; - //////////// rewriting info to CTownInstance class ///////////////////// - CGTownInstance * nt = new CGTownInstance(); - (*(static_cast(nt))) = *nobj; - delete nobj; - nobj = nt; - nt->identifier = readInt(spec->bytes,4);; - if(spec->unusualBuildins) - { - for(int byte=0;byte<6;byte++) - { - for(int bit=0;bit<8;bit++) - { - if(spec->buildingSettings[byte] & (1<h3mbuildings.insert(byte*8+bit); - } - } - } - for(int byte=6;byte<12;byte++) - { - for(int bit=0;bit<8;bit++) - { - if(spec->buildingSettings[byte] & (1<forbiddenBuildings.insert(byte*8+bit); - } - } - } - nt->builtBuildings = convertBuildings(nt->h3mbuildings,nt->subID); - nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings,nt->subID); - } - else - { - if(spec->hasFort) - { - nt->builtBuildings.insert(7); - } - nt->builtBuildings.insert(10); - nt->builtBuildings.insert(5); - nt->builtBuildings.insert(30); - if(rand()%2) - nt->builtBuildings.insert(31); - } - nt->setOwner(spec->player); - nt->town = &CGI->townh->towns[nt->defInfo->subid]; nt->builded = 0; nt->destroyed = 0; - nt->name = spec->name; - nt->army = spec->garrison; - nt->garrisonHero = NULL;// spec->garnisonHero is not readed - TODO: readit - nt->pos = int3(spec->x, spec->y, spec->z); - nt->possibleSpells = spec->possibleSpells; - nt->obligatorySpells = spec->obligatorySpells; - nt->availableSpells = std::vector(); + nt->garrisonHero = NULL; CGI->townh->townInstances.push_back(nt); break; } @@ -2004,7 +1606,7 @@ void CAmbarCendamo::deh3m() } i+=4; } - spec->spell = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i; + spec->spell = bufor[i]; ++i; i+=3; nobj->info = spec; break; @@ -2047,7 +1649,7 @@ void CAmbarCendamo::deh3m() gabn = readNormalNr(i, 1); ++i; for(int oo = 0; ooabilities.push_back((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)]); ++i; + spec->abilities.push_back(readNormalNr(i, 1)); ++i; spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i; } int gart = readNormalNr(i, 1); ++i; //number of gained artifacts @@ -2055,17 +1657,17 @@ void CAmbarCendamo::deh3m() { if(map.version > RoE) { - spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2; + spec->artifacts.push_back(readNormalNr(i, 2)); i+=2; } else { - spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 1)])); i+=1; + spec->artifacts.push_back(readNormalNr(i, 1)); i+=1; } } int gspel = readNormalNr(i, 1); ++i; //number of gained spells for(int oo = 0; oospells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i; + spec->spells.push_back(readNormalNr(i, 1)); ++i; } int gcre = readNormalNr(i, 1); ++i; //number of gained creatures spec->creatures = readCreatureSet(gcre); @@ -2231,8 +1833,7 @@ void CAmbarCendamo::deh3m() int artNumber = bufor[i]; ++i; for(int yy=0; yym5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid])); + spec->m5arts.push_back(readNormalNr(i, 2)); i+=2; } int limit = readNormalNr(i); i+=4; if(limit == ((int)0xffffffff)) @@ -2533,4 +2134,18 @@ CCreatureSet CAmbarCendamo::readCreatureSet(int number) i+=number*3; return ret; } +} +char CAmbarCendamo::readChar() +{ + return bufor[i++]; +} +std::string CAmbarCendamo::readString() +{ + int len = readNormalNr(i); i+=4; + std::string ret; ret.reserve(len); + for(int gg=0; ggdefName == por; -} - void CDefObjInfoHandler::load() { nodrze ideki; @@ -72,14 +67,4 @@ void CDefObjInfoHandler::load() if(nobj->id==98) castles[nobj->subid]=nobj; } -} - -bool DefObjInfo::isVisitable() const -{ - for(int g=0; g<6; ++g) - { - if(visitMap[g]!=0) - return true; - } - return false; -} +} \ No newline at end of file diff --git a/hch/CDefObjInfoHandler.h b/hch/CDefObjInfoHandler.h index 55fdfd77c..5f40afd2a 100644 --- a/hch/CDefObjInfoHandler.h +++ b/hch/CDefObjInfoHandler.h @@ -27,18 +27,6 @@ public: } CGDefInfo(); }; -struct DefObjInfo -{ - std::string defName; - int priority; - int type, subtype; - int objType; - unsigned char visitMap[6]; - unsigned char blockMap[6]; - bool operator==(const std::string & por) const; - bool isVisitable() const; -}; - class CDefObjInfoHandler { public: diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 58cd952e1..030d38d42 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -10,6 +10,7 @@ #include "CHeroHandler.h" #include #include "CTownHandler.h" +#include "CArtHandler.h" void CObjectHandler::loadObjects() { int ID=0; @@ -239,7 +240,10 @@ int CGHeroInstance::getSecSkillLevel(const int & ID) const return secSkills[i].second; return -1; } - +const CArtifact * CGHeroInstance::getArt(int pos) +{ + return &CGI->arth->artifacts[artifWorn[pos]]; +} int CGTownInstance::getSightDistance() const //returns sight distance { @@ -326,7 +330,6 @@ CGTownInstance::CGTownInstance() garrisonHero=NULL; //state->owner=-1; town=NULL; - income = 500; visitingHero = NULL; } diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index e1f1242db..90073fb61 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -3,10 +3,8 @@ #include #include #include +#include #include "CCreatureHandler.h" -#include "CArtHandler.h" -#include "CAbilityHandler.h" -#include "CSpellHandler.h" //#include "CHeroHandler.h" using boost::logic::tribool; class CCPPObjectScript; @@ -19,6 +17,7 @@ class CHero; class CBuilding; class CSpell; class CGTownInstance; +class CArtifact; class CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes { }; @@ -39,40 +38,40 @@ public: unsigned int defence; //added defence points unsigned int power; //added power points unsigned int knowledge; //added knowledge points - std::vector abilities; //gained abilities + std::vector abilities; //gained abilities std::vector abilityLevels; //levels of gained abilities - std::vector artifacts; //gained artifacts - std::vector spells; //gained spells + std::vector artifacts; //gained artifacts + std::vector spells; //gained spells CCreatureSet creatures; //gained creatures unsigned char availableFor; //players whom this event is available for bool computerActivate; //true if computre player can activate this event bool humanActivate; //true if human player can activate this event }; -class CHeroObjInfo : public CSpecObjInfo -{ -public: - unsigned char bytes[4]; //mysterius bytes identifying hero in a strange way - int player; - CHero * type; - std::string name; //if nonstandard - bool standardGarrison; //true if hero has standard garrison - CCreatureSet garrison; //hero's army - std::vector artifacts; //hero's artifacts from bag - //CArtifact * artHead, * artLRing, * artRRing, * artLHand, * artRhand, * artFeet, * artSpellBook, * artMach1, * artMach2, * artMach3, * artMach4, * artMisc1, * artMisc2, * artMisc3, * artMisc4, * artMisc5, * artTorso, * artNeck, * artShoulders; //working artifactsstd::vector artifWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 - std::vector artifWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 - bool isGuarding; - int guardRange; //range of hero's guard - std::string biography; //if nonstandard - bool sex; //if true, reverse hero's sex - std::vector spells; //hero's spells - int attack, defence, power, knowledge; //main hero's attributes - unsigned int experience; //hero's experience points - std::vector abilities; //hero's abilities - std::vector abilityLevels; //hero ability levels - bool defaultMainStats; //if true attack, defence, power and knowledge are typical - CGHeroInstance * myInstance; //pointer to appropriate hero instance -}; +//class CHeroObjInfo : public CSpecObjInfo +//{ +//public: +// unsigned char bytes[4]; //mysterius bytes identifying hero in a strange way +// int player; +// CHero * type; +// std::string name; //if nonstandard +// bool standardGarrison; //true if hero has standard garrison +// CCreatureSet garrison; //hero's army +// std::vector artifacts; //hero's artifacts from bag +// //CArtifact * artHead, * artLRing, * artRRing, * artLHand, * artRhand, * artFeet, * artSpellBook, * artMach1, * artMach2, * artMach3, * artMach4, * artMisc1, * artMisc2, * artMisc3, * artMisc4, * artMisc5, * artTorso, * artNeck, * artShoulders; //working artifactsstd::vector artifWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 +// std::map artifWorn; // keys: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 +// bool isGuarding; +// int guardRange; //range of hero's guard +// std::string biography; //if nonstandard +// bool sex; //if true, reverse hero's sex +// std::vector spells; //hero's spells +// int attack, defence, power, knowledge; //main hero's attributes +// unsigned int experience; //hero's experience points +// std::vector abilities; //hero's abilities +// std::vector abilityLevels; //hero ability levels +// bool defaultMainStats; //if true attack, defence, power and knowledge are typical +// CGHeroInstance * myInstance; //pointer to appropriate hero instance +//}; class CCreatureObjInfo : public CSpecObjInfo { @@ -82,7 +81,7 @@ public: unsigned char character; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile) std::string message; //message printed for attacking hero int wood, mercury, ore, sulfur, crytal, gems, gold; //resources gained to hero that has won with monsters - CArtifact * gainedArtifact; //artifact gained to hero + int gainedArtifact; //ID of artifact gained to hero bool neverFlees; //if true, the troops will never flee bool notGrowingTeam; //if true, number of units won't grow }; @@ -99,25 +98,16 @@ public: unsigned char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player bool isDayLimit; //if true, there is a day limit int lastDay; //after this day (first day is 0) mission cannot be completed - //for mission 1 - int m1level; - //for mission 2 - int m2attack, m2defence, m2power, m2knowledge; - //for mission 3 - unsigned char m3bytes[4]; - //for mission 4 - unsigned char m4bytes[4]; - //for mission 5 - std::vector m5arts; - //for mission 6 - std::vector m6cre; + int m1level; //for mission 1 + int m2attack, m2defence, m2power, m2knowledge;//for mission 2 + unsigned char m3bytes[4];//for mission 3 + unsigned char m4bytes[4];//for mission 4 + std::vector m5arts;//for mission 5 - artifact ID + std::vector m6cre;//for mission 6 std::vector m6number; - //for mission 7 - int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; - //for mission 8 - CHero * m8hero; - //for mission 9 - int m9player; //number; from 0 to 7 + int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 7 + CHero * m8hero;//for mission 8 + int m9player; //for mission 9 - number; from 0 to 7 std::string firstVisitText, nextVisitText, completedText; @@ -137,21 +127,21 @@ public: unsigned char r6type; //0 - attack, 1 - defence, 2 - power, 3 - knowledge int r6amount; //for reward 7 - CAbility * r7ability; + int r7ability; //ability id unsigned char r7level; //1 - basic, 2 - advanced, 3 - expert //for reward 8 - CArtifact * r8art; + int r8art;//artifact id //for reward 9 - CSpell * r9spell; + int r9spell;//spell id //for reward 10 - CCreature * r10creature; + int r10creature; //creature id int r10amount; }; class CWitchHutObjInfo : public CSpecObjInfo { public: - std::vector allowedAbilities; + std::vector allowedAbilities; }; class CScholarObjInfo : public CSpecObjInfo @@ -160,8 +150,8 @@ public: unsigned char bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell unsigned char r0type; - CAbility * r1; - CSpell * r2; + int r1; //Ability ID + int r2; //Spell ID }; class CGarrisonObjInfo : public CSpecObjInfo @@ -206,7 +196,7 @@ class CSpellScrollObjinfo : public CSpecObjInfo { public: std::string message; - CSpell * spell; + int spell; bool areGuarders; CCreatureSet guarders; }; @@ -225,10 +215,10 @@ public: int luckDiff; int wood, mercury, ore, sulfur, crystal, gems, gold; int attack, defence, power, knowledge; - std::vector abilities; + std::vector abilities; std::vector abilityLevels; - std::vector artifacts; - std::vector spells; + std::vector artifacts; + std::vector spells; CCreatureSet creatures; }; @@ -279,7 +269,7 @@ public: //for mission 4 unsigned char m4bytes[4]; //for mission 5 - std::vector m5arts; + std::vector m5arts; //artifacts id //for mission 6 std::vector m6cre; std::vector m6number; @@ -352,12 +342,16 @@ public: std::vector primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge std::vector > secSkills; //first - ID of skill, second - level of skill (0 - basic, 1 - adv., 2 - expert) int movement; //remaining movement points + int identifier; //from the map file + int patrolRadious; //-1 - no patrol + bool sex; bool inTownGarrison; // if hero is in town garrison CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison - std::vector artifacts; //hero's artifacts from bag - std::vector artifWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 + std::vector artifacts; //hero's artifacts from bag + std::map artifWorn; //map; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 + std::set spells; //known spells (spell IDs) virtual bool isHero() const; unsigned int getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const; @@ -373,6 +367,7 @@ public: int getCurrentLuck() const; int getCurrentMorale() const; int getSecSkillLevel(const int & ID) const; //-1 - no skill + const CArtifact * getArt(int pos); CGHeroInstance(); virtual ~CGHeroInstance(); }; @@ -384,13 +379,12 @@ public: std::string name; // name of town int builded; //how many buildings has been built this turn int destroyed; //how many buildings has been destroyed this turn - int identifier; - int income; + int identifier; //special identifier from h3m (only > RoE maps) + int alignment; struct StrInfo { - public: std::map creatures; //level - available amount } strInfo; @@ -398,7 +392,7 @@ public: const CGHeroInstance * garrisonHero, *visitingHero; - std::vector possibleSpells, obligatorySpells, availableSpells; + std::vector possibleSpells, obligatorySpells, availableSpells; int getSightDistance() const; //returns sight distance diff --git a/map.h b/map.h index 5c253cc6a..ff9b07945 100644 --- a/map.h +++ b/map.h @@ -13,7 +13,7 @@ struct Sresource std::string resName; //name of this resource int amount; //it can be greater and lesser than 0 }; - +class CGHeroInstance; struct TimeEvent { std::string eventName; @@ -156,7 +156,7 @@ struct Mapa TerrainTile** undergroungTerrain; // used only if there is underground level std::vector rumors; std::vector disposedHeroes; - std::vector predefinedHeroes; + std::vector predefinedHeroes; std::vector defy; // list of .def files PlayerInfo players[8]; // info about players std::vector teams; // teams[i] = team of player no i @@ -164,6 +164,9 @@ struct Mapa EvictoryConditions victoryCondition; //victory conditions CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard int howManyTeams; + std::vector allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed + std::vector allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed + std::vector allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed std::vector events; }; class CMapHeader diff --git a/mapHandler.cpp b/mapHandler.cpp index b6f122d3b..8ed75b2ed 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -12,6 +12,7 @@ #include "hch\CCastleHandler.h" #include "hch\CHeroHandler.h" #include "hch\CTownHandler.h" +#include "hch\CArtHandler.h" #include #include extern SDL_Surface * screen; @@ -149,7 +150,7 @@ std::pair CMapHandler::pickObject(CGObjectInstance *obj) return std::pair(79,rand()%7); //now it's OH3 style, use %8 for mithril case 77: //random town { - int align = ((CCastleObjInfo*)obj->info)->alignment, + int align = ((CGTownInstance*)obj)->alignment, f; if(align>PLAYER_LIMIT-1)//same as owner / random { @@ -1484,9 +1485,8 @@ CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos, int ow nobj->defInfo->handler=NULL; nobj->defInfo->blockMap[5] = 253; nobj->defInfo->visitMap[5] = 2; - nobj->artifWorn.resize(20); nobj->artifacts.resize(20); - nobj->artifWorn[16] = &CGI->arth->artifacts[3]; + nobj->artifWorn[16] = 3; nobj->primSkills.resize(4); nobj->primSkills[0] = nobj->type->heroClass->initialAttack; nobj->primSkills[1] = nobj->type->heroClass->initialDefence; From dbca25df74e16ecbc64920962f455d2e1f904200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Wed, 11 Jun 2008 01:53:57 +0000 Subject: [PATCH 05/47] Cleanups/refactoring --- CCallback.h | 4 +- CConsoleHandler.cpp | 26 ++-- CGameState.h | 2 +- CHeroWindow.cpp | 80 ++++++------ CHeroWindow.h | 2 +- CLua.h | 21 ++-- CMT.cpp | 82 ++++++------ CPathfinder.cpp | 10 +- CPlayerInterface.cpp | 8 +- hch/CAmbarCendamo.cpp | 111 +++++----------- hch/CAmbarCendamo.h | 2 - hch/CCastleHandler.cpp | 2 - hch/CCastleHandler.h | 49 -------- hch/CHeroHandler.cpp | 2 +- hch/CHeroHandler.h | 1 - hch/CObjectHandler.cpp | 6 +- hch/CObjectHandler.h | 69 +++++----- hch/CTownHandler.h | 3 - map.h | 17 ++- mapHandler.cpp | 279 ++++++++++++++++++++++------------------- mapHandler.h | 2 +- 21 files changed, 353 insertions(+), 425 deletions(-) delete mode 100644 hch/CCastleHandler.cpp delete mode 100644 hch/CCastleHandler.h diff --git a/CCallback.h b/CCallback.h index 4d745ea62..23ebf3d9b 100644 --- a/CCallback.h +++ b/CCallback.h @@ -167,7 +167,7 @@ public: void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army //friends - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; class CLuaCallback : public CScriptCallback { @@ -179,6 +179,6 @@ private: static int getGnrlText(lua_State * L);//(int ID, int which, int val); static int getSelectedHero(lua_State * L);//() - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; #endif //CCALLBACK_H \ No newline at end of file diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index c1e403cdb..dac629a8b 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -64,20 +64,20 @@ int internalFunc(void * callback) vector* p; switch (*cn.c_str()) { - case 'P': - std::cout<<"Policzyc sciezke."<>src>>dst; - - p = CGI->pathf->GetPath(Coordinate(src),Coordinate(dst),CGI->heroh->heroInstances[0]); - LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->ConvertToOldFormat(p); + //case 'P': + // std::cout<<"Policzyc sciezke."<>src>>dst; + // + // p = CGI->pathf->GetPath(Coordinate(src),Coordinate(dst),CGI->heroh->heroInstances[0]); + // LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->ConvertToOldFormat(p); //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]); - break; + //break; case 'm': //number of heroes - std::cout<<"Number of heroes: "<heroh->heroInstances.size()<mh->map->heroes.size()<>heronum; - std::cout<<"Position of hero "<heroh->heroInstances[heronum]->getPosition(false)<mh->map->heroes[heronum]->getPosition(false)<objh->objInstances.size(); ++c) + for(int c=0; cmh->map->objects.size(); ++c) { - CGI->mh->hideObject(CGI->objh->objInstances[c]); + CGI->mh->hideObject(CGI->mh->map->objects[c]); } break; case 'R': //restora all objects after A has been pressed - for(int c=0; cobjh->objInstances.size(); ++c) + for(int c=0; cmh->map->objects.size(); ++c) { - CGI->mh->printObject(CGI->objh->objInstances[c]); + CGI->mh->printObject(CGI->mh->map->objects[c]); } break; } diff --git a/CGameState.h b/CGameState.h index 966909625..4ac7cb62a 100644 --- a/CGameState.h +++ b/CGameState.h @@ -98,7 +98,7 @@ public: friend CPathfinder;; friend CLuaCallback; friend int _tmain(int argc, _TCHAR* argv[]); - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); friend CScriptCallback; friend void handleCPPObjS(std::map * mapa, CCPPObjectScript * script); //CCallback * cb; //for communication between PlayerInterface/AI and GameState diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 2eac173e4..84bc77e18 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -257,209 +257,209 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero) } backpack.clear(); - artWorn[8] = new CArtPlace(hero->artifWorn[8]); + artWorn[8] = new CArtPlace(hero->getArt(8)); artWorn[8]->pos.x = 515; artWorn[8]->pos.y = 295; artWorn[8]->pos.h = artWorn[8]->pos.w = 44; - if(hero->artifWorn[8]) + if(hero->getArt(8)) artWorn[8]->text = hero->getArt(8)->description; else artWorn[8]->text = std::string(); artWorn[8]->ourWindow = this; artWorn[8]->feet = true; - artWorn[0] = new CArtPlace(hero->artifWorn[0]); + artWorn[0] = new CArtPlace(hero->getArt(0)); artWorn[0]->pos.x = 509; artWorn[0]->pos.y = 30; artWorn[0]->pos.h = artWorn[0]->pos.w = 44; - if(hero->artifWorn[0]) + if(hero->getArt(0)) artWorn[0]->text = hero->getArt(0)->description; else artWorn[0]->text = std::string(); artWorn[0]->ourWindow = this; artWorn[0]->head = true; - artWorn[4] = new CArtPlace(hero->artifWorn[4]); + artWorn[4] = new CArtPlace(hero->getArt(4)); artWorn[4]->pos.x = 564; artWorn[4]->pos.y = 183; artWorn[4]->pos.h = artWorn[4]->pos.w = 44; - if(hero->artifWorn[4]) + if(hero->getArt(4)) artWorn[4]->text = hero->getArt(4)->description; else artWorn[4]->text = std::string(); artWorn[4]->ourWindow = this; artWorn[4]->lHand = true; - artWorn[7] = new CArtPlace(hero->artifWorn[7]); + artWorn[7] = new CArtPlace(hero->getArt(7)); artWorn[7]->pos.x = 610; artWorn[7]->pos.y = 183; artWorn[7]->pos.h = artWorn[7]->pos.w = 44; - if(hero->artifWorn[7]) + if(hero->getArt(7)) artWorn[7]->text = hero->getArt(7)->description; else artWorn[7]->text = std::string(); artWorn[7]->ourWindow = this; artWorn[7]->lRing = true; - artWorn[13] = new CArtPlace(hero->artifWorn[13]); + artWorn[13] = new CArtPlace(hero->getArt(13)); artWorn[13]->pos.x = 564; artWorn[13]->pos.y = 30; artWorn[13]->pos.h = artWorn[13]->pos.w = 44; - if(hero->artifWorn[13]) + if(hero->getArt(13)) artWorn[13]->text = hero->getArt(13)->description; else artWorn[13]->text = std::string(); artWorn[13]->ourWindow = this; artWorn[13]->warMachine1 = true; - artWorn[14] = new CArtPlace(hero->artifWorn[14]); + artWorn[14] = new CArtPlace(hero->getArt(14)); artWorn[14]->pos.x = 610; artWorn[14]->pos.y = 30; artWorn[14]->pos.h = artWorn[14]->pos.w = 44; - if(hero->artifWorn[14]) + if(hero->getArt(14)) artWorn[14]->text = hero->getArt(14)->description; else artWorn[14]->text = std::string(); artWorn[14]->ourWindow = this; artWorn[14]->warMachine2 = true; - artWorn[15] = new CArtPlace(hero->artifWorn[15]); + artWorn[15] = new CArtPlace(hero->getArt(15)); artWorn[15]->pos.x = 610; artWorn[15]->pos.y = 76; artWorn[15]->pos.h = artWorn[15]->pos.w = 44; - if(hero->artifWorn[15]) + if(hero->getArt(15)) artWorn[15]->text = hero->getArt(15)->description; else artWorn[15]->text = std::string(); artWorn[15]->ourWindow = this; artWorn[15]->warMachine3 = true; - artWorn[16] = new CArtPlace(hero->artifWorn[16]); + artWorn[16] = new CArtPlace(hero->getArt(16)); artWorn[16]->pos.x = 610; artWorn[16]->pos.y = 122; artWorn[16]->pos.h = artWorn[16]->pos.w = 44; - if(hero->artifWorn[16]) + if(hero->getArt(16)) artWorn[16]->text = hero->getArt(16)->description; else artWorn[16]->text = std::string(); artWorn[16]->ourWindow = this; artWorn[16]->warMachine4 = true; - artWorn[9] = new CArtPlace(hero->artifWorn[9]); + artWorn[9] = new CArtPlace(hero->getArt(9)); artWorn[9]->pos.x = 383; artWorn[9]->pos.y = 143; artWorn[9]->pos.h = artWorn[9]->pos.w = 44; - if(hero->artifWorn[9]) + if(hero->getArt(9)) artWorn[9]->text = hero->getArt(9)->description; else artWorn[9]->text = std::string(); artWorn[9]->ourWindow = this; artWorn[9]->misc1 = true; - artWorn[10] = new CArtPlace(hero->artifWorn[10]); + artWorn[10] = new CArtPlace(hero->getArt(10)); artWorn[10]->pos.x = 399; artWorn[10]->pos.y = 194; artWorn[10]->pos.h = artWorn[10]->pos.w = 44; - if(hero->artifWorn[10]) + if(hero->getArt(10)) artWorn[10]->text = hero->getArt(10)->description; else artWorn[10]->text = std::string(); artWorn[10]->ourWindow = this; artWorn[10]->misc1 = true; - artWorn[11] = new CArtPlace(hero->artifWorn[11]); + artWorn[11] = new CArtPlace(hero->getArt(11)); artWorn[11]->pos.x = 415; artWorn[11]->pos.y = 245; artWorn[11]->pos.h = artWorn[11]->pos.w = 44; - if(hero->artifWorn[11]) + if(hero->getArt(11)) artWorn[11]->text = hero->getArt(11)->description; else artWorn[11]->text = std::string(); artWorn[11]->ourWindow = this; artWorn[11]->misc3 = true; - artWorn[12] = new CArtPlace(hero->artifWorn[12]); + artWorn[12] = new CArtPlace(hero->getArt(12)); artWorn[12]->pos.x = 431; artWorn[12]->pos.y = 296; artWorn[12]->pos.h = artWorn[12]->pos.w = 44; - if(hero->artifWorn[12]) + if(hero->getArt(12)) artWorn[12]->text = hero->getArt(12)->description; else artWorn[12]->text = std::string(); artWorn[12]->ourWindow = this; artWorn[12]->misc4 = true; - artWorn[18] = new CArtPlace(hero->artifWorn[18]); + artWorn[18] = new CArtPlace(hero->getArt(18)); artWorn[18]->pos.x = 381; artWorn[18]->pos.y = 296; artWorn[18]->pos.h = artWorn[18]->pos.w = 44; - if(hero->artifWorn[18]) + if(hero->getArt(18)) artWorn[18]->text = hero->getArt(18)->description; else artWorn[18]->text = std::string(); artWorn[18]->ourWindow = this; artWorn[18]->misc5 = true; - artWorn[2] = new CArtPlace(hero->artifWorn[2]); + artWorn[2] = new CArtPlace(hero->getArt(2)); artWorn[2]->pos.x = 508; artWorn[2]->pos.y = 79; artWorn[2]->pos.h = artWorn[2]->pos.w = 44; - if(hero->artifWorn[2]) + if(hero->getArt(2)) artWorn[2]->text = hero->getArt(2)->description; else artWorn[2]->text = std::string(); artWorn[2]->ourWindow = this; artWorn[2]->neck = true; - artWorn[3] = new CArtPlace(hero->artifWorn[3]); + artWorn[3] = new CArtPlace(hero->getArt(3)); artWorn[3]->pos.x = 383; artWorn[3]->pos.y = 68; artWorn[3]->pos.h = artWorn[3]->pos.w = 44; - if(hero->artifWorn[3]) + if(hero->getArt(3)) artWorn[3]->text = hero->getArt(3)->description; else artWorn[3]->text = std::string(); artWorn[3]->ourWindow = this; artWorn[3]->rHand = true; - artWorn[6] = new CArtPlace(hero->artifWorn[6]); + artWorn[6] = new CArtPlace(hero->getArt(6)); artWorn[6]->pos.x = 431; artWorn[6]->pos.y = 68; artWorn[6]->pos.h = artWorn[6]->pos.w = 44; - if(hero->artifWorn[6]) + if(hero->getArt(6)) artWorn[6]->text = hero->getArt(6)->description; else artWorn[6]->text = std::string(); artWorn[6]->ourWindow = this; artWorn[6]->rRing = true; - artWorn[1] = new CArtPlace(hero->artifWorn[1]); + artWorn[1] = new CArtPlace(hero->getArt(1)); artWorn[1]->pos.x = 567; artWorn[1]->pos.y = 240; artWorn[1]->pos.h = artWorn[1]->pos.w = 44; - if(hero->artifWorn[1]) + if(hero->getArt(1)) artWorn[1]->text = hero->getArt(1)->description; else artWorn[1]->text = std::string(); artWorn[1]->ourWindow = this; artWorn[1]->shoulders = true; - artWorn[17] = new CArtPlace(hero->artifWorn[17]); + artWorn[17] = new CArtPlace(hero->getArt(17)); artWorn[17]->pos.x = 610; artWorn[17]->pos.y = 310; artWorn[17]->pos.h = artWorn[17]->pos.w = 44; - if(hero->artifWorn[17]) + if(hero->getArt(17)) artWorn[17]->text = hero->getArt(17)->description; else artWorn[17]->text = std::string(); artWorn[17]->ourWindow = this; artWorn[17]->spellBook = true; - artWorn[5] = new CArtPlace(hero->artifWorn[5]); + artWorn[5] = new CArtPlace(hero->getArt(5)); artWorn[5]->pos.x = 509; artWorn[5]->pos.y = 130; artWorn[5]->pos.h = artWorn[5]->pos.w = 44; - if(hero->artifWorn[5]) + if(hero->getArt(5)) artWorn[5]->text = hero->getArt(5)->description; else artWorn[5]->text = std::string(); @@ -480,7 +480,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero) { CArtPlace * add; if( s < curHero->artifacts.size() ) - add = new CArtPlace(curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]); + add = new CArtPlace(&CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]]); else add = new CArtPlace(NULL); add->pos.x = 403 + 46*s; @@ -876,7 +876,7 @@ void CHeroWindow::redrawCurBack() CSDL_Ext::printAt(manastr.str(), 212, 247, GEOR16, zwykly, curBack); } -CArtPlace::CArtPlace(int Art): ourArt(&CGI->arth->artifacts[Art]), active(false), clicked(false), +CArtPlace::CArtPlace(const CArtifact* Art): ourArt(Art), active(false), clicked(false), spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false), warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false), misc5(false), feet(false), lRing(false), rRing(false), torso(false), diff --git a/CHeroWindow.h b/CHeroWindow.h index 2adb74b9b..473fad101 100644 --- a/CHeroWindow.h +++ b/CHeroWindow.h @@ -70,7 +70,7 @@ public: bool clicked; CHeroWindow * ourWindow; const CArtifact * ourArt; - CArtPlace(int Art); + CArtPlace(const CArtifact * Art); void clickLeft (tribool down); void clickRight (tribool down); void activate(); diff --git a/CLua.h b/CLua.h index 398206097..9309335cd 100644 --- a/CLua.h +++ b/CLua.h @@ -11,6 +11,7 @@ class CGHeroInstance; class CScriptCallback; class SComponent; class CSelectableComponent; +struct Mapa; enum ESLan{UNDEF=-1,CPP,ERM,LUA}; class CObjectScript { @@ -69,7 +70,7 @@ public: void findFS(std::string fname); - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; class CLuaObjectScript : public CLua, public CObjectScript @@ -84,7 +85,7 @@ public: void onHeroVisit(CGObjectInstance *os, int heroID); std::string hoverText(CGObjectInstance *os); - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; class CCPPObjectScript: public CObjectScript { @@ -106,7 +107,7 @@ class CVisitableOPH : public CCPPObjectScript //once per hero std::vector yourObjects(); //returns IDs of objects which are handled by script std::string hoverText(CGObjectInstance *os); - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; class CVisitableOPW : public CCPPObjectScript //once per week @@ -120,7 +121,7 @@ class CVisitableOPW : public CCPPObjectScript //once per week std::string hoverText(CGObjectInstance *os); void newTurn (); - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; class CMines : public CCPPObjectScript //flaggable, and giving resource at each day @@ -135,7 +136,7 @@ class CMines : public CCPPObjectScript //flaggable, and giving resource at each std::string hoverText(CGObjectInstance *os); void newTurn (); - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc @@ -150,7 +151,7 @@ class CPickable : public CCPPObjectScript, public IChosen //pickable - resource std::string hoverText(CGObjectInstance *os); std::vector yourObjects(); //returns IDs of objects which are handled by script - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, etc @@ -161,7 +162,7 @@ class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, std::string hoverText(CGObjectInstance *os); std::vector yourObjects(); //returns IDs of objects which are handled by script - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; class CHeroScript : public CCPPObjectScript @@ -173,7 +174,7 @@ class CHeroScript : public CCPPObjectScript std::vector yourObjects(); //returns IDs of objects which are handled by script std::string hoverText(CGObjectInstance *os); - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; class CMonsterS : public CCPPObjectScript @@ -185,7 +186,7 @@ class CMonsterS : public CCPPObjectScript void onHeroVisit(CGObjectInstance *os, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; class CCreatureGen : public CCPPObjectScript @@ -197,5 +198,5 @@ class CCreatureGen : public CCPPObjectScript void onHeroVisit(CGObjectInstance *os, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; \ No newline at end of file diff --git a/CMT.cpp b/CMT.cpp index e4b1b33e7..2daa4657f 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -61,7 +61,7 @@ CGameInfo* CGI; #endif #define CHUNK 16384 -const char * NAME = "VCMI 0.6"; +const char * NAME = "VCMI \"Altanatse\" 0.7"; SDL_Color playerColorPalette[256]; //palette to make interface colors good @@ -77,7 +77,7 @@ void handleCPPObjS(std::map * mapa, CCPPObjectScript * sc } CGI->state->cppscripts.insert(script); } -void initGameState(CGameInfo * cgi) +void initGameState(Mapa * map, CGameInfo * cgi) { cgi->state->day=0; /*********creating players entries in gs****************************************/ @@ -115,14 +115,14 @@ void initGameState(CGameInfo * cgi) } /*************************HEROES************************************************/ - for (int i=0; iheroh->heroInstances.size();i++) //heroes instances + for (int i=0; iheroes.size();i++) //heroes instances { - if (!cgi->heroh->heroInstances[i]->type || cgi->heroh->heroInstances[i]->getOwner()<0) + if (map->heroes[i]->getOwner()<0) continue; - //CGHeroInstance * vhi = new CGHeroInstance(); - //*vhi=*(cgi->heroh->heroInstances[i]); - CGHeroInstance * vhi = (cgi->heroh->heroInstances[i]); - vhi->subID = vhi->type->ID; + CGHeroInstance * vhi = (map->heroes[i]); + if(!vhi->type) + vhi->type = cgi->heroh->heroes[vhi->subID]; + //vhi->subID = vhi->type->ID; if (vhi->level<1) { vhi->exp=40+rand()%50; @@ -137,8 +137,8 @@ void initGameState(CGameInfo * cgi) vhi->primSkills[1] = vhi->type->heroClass->initialDefence; vhi->primSkills[2] = vhi->type->heroClass->initialPower; vhi->primSkills[3] = vhi->type->heroClass->initialKnowledge; - vhi->mana = vhi->primSkills[3]*10; } + vhi->mana = vhi->primSkills[3]*10; if (!vhi->name.length()) { vhi->name = vhi->type->name; @@ -186,21 +186,21 @@ void initGameState(CGameInfo * cgi) /*************************FOG**OF**WAR******************************************/ for(std::map::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k) { - k->second.fogOfWarMap.resize(cgi->ac->map.width, Woff); - for(int g=-Woff; gac->map.width+Woff; ++g) - k->second.fogOfWarMap[g].resize(cgi->ac->map.height, Hoff); + k->second.fogOfWarMap.resize(map->width, Woff); + for(int g=-Woff; gwidth+Woff; ++g) + k->second.fogOfWarMap[g].resize(map->height, Hoff); - for(int g=-Woff; gac->map.width+Woff; ++g) - for(int h=-Hoff; hac->map.height+Hoff; ++h) - k->second.fogOfWarMap[g][h].resize(cgi->ac->map.twoLevel+1, 0); + for(int g=-Woff; gwidth+Woff; ++g) + for(int h=-Hoff; hheight+Hoff; ++h) + k->second.fogOfWarMap[g][h].resize(map->twoLevel+1, 0); - for(int g=-Woff; gac->map.width+Woff; ++g) - for(int h=-Hoff; hac->map.height+Hoff; ++h) - for(int v=0; vac->map.twoLevel+1; ++v) + for(int g=-Woff; gwidth+Woff; ++g) + for(int h=-Hoff; hheight+Hoff; ++h) + for(int v=0; vtwoLevel+1; ++v) k->second.fogOfWarMap[g][h][v] = 0; - for(int xd=0; xdac->map.width; ++xd) //revealing part of map around heroes + for(int xd=0; xdwidth; ++xd) //revealing part of map around heroes { - for(int yd=0; ydac->map.height; ++yd) + for(int yd=0; ydheight; ++yd) { for(int ch=0; chsecond.heroes.size(); ++ch) { @@ -213,16 +213,20 @@ void initGameState(CGameInfo * cgi) } } /****************************TOWNS************************************************/ - for (int i=0;itownh->townInstances.size();i++) + for (int i=0;itowns.size();i++) { - //CGTownInstance * vti = new CGTownInstance(); - //(*vti)=*(cgi->townh->townInstances[i]); - CGTownInstance * vti =(cgi->townh->townInstances[i]); - //vti->creatureIncome.resize(CREATURES_PER_TOWN); - //vti->creaturesLeft.resize(CREATURES_PER_TOWN); + CGTownInstance * vti =(map->towns[i]); if (vti->name.length()==0) // if town hasn't name we draw it vti->name=vti->town->names[rand()%vti->town->names.size()]; - + if(vti->builtBuildings.find(-50)!=vti->builtBuildings.end()) //give standard set of buildings + { + vti->builtBuildings.erase(-50); + vti->builtBuildings.insert(10); + vti->builtBuildings.insert(5); + vti->builtBuildings.insert(30); + if(rand()%2) + vti->builtBuildings.insert(31); + } cgi->state->players[vti->getOwner()].towns.push_back(vti); } @@ -230,9 +234,9 @@ void initGameState(CGameInfo * cgi) { if(k->first==-1 || k->first==255) continue; - for(int xd=0; xdac->map.width; ++xd) //revealing part of map around towns + for(int xd=0; xdwidth; ++xd) //revealing part of map around towns { - for(int yd=0; ydac->map.height; ++yd) + for(int yd=0; ydheight; ++yd) { for(int ch=0; chsecond.towns.size(); ++ch) { @@ -300,22 +304,22 @@ void initGameState(CGameInfo * cgi) } /****************************INITIALIZING OBJECT SCRIPTS************************************************/ std::string temps("newObject"); - for (int i=0; iobjh->objInstances.size(); i++) + for (int i=0; iobjects.size(); i++) { //c++ scripts - if (scripts.find(CGI->objh->objInstances[i]->ID) != scripts.end()) + if (scripts.find(map->objects[i]->ID) != scripts.end()) { - CGI->objh->objInstances[i]->state = scripts[CGI->objh->objInstances[i]->ID]; - CGI->objh->objInstances[i]->state->newObject(CGI->objh->objInstances[i]); + map->objects[i]->state = scripts[map->objects[i]->ID]; + map->objects[i]->state->newObject(map->objects[i]); } else { - CGI->objh->objInstances[i]->state = NULL; + map->objects[i]->state = NULL; } // lua scripts - if(cgi->state->checkFunc(CGI->objh->objInstances[i]->ID,temps)) - (*skrypty)[CGI->objh->objInstances[i]->ID][temps]->newObject(CGI->objh->objInstances[i]); + if(cgi->state->checkFunc(map->objects[i]->ID,temps)) + (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); } delete lf; @@ -856,14 +860,14 @@ int _tmain(int argc, _TCHAR* argv[]) THC std::cout<<"Detecting file (together): "<mh = mh; - mh->reader = ac; + mh->map = &ac->map; THC std::cout<<"Creating mapHandler: "<loadDefs(); THC std::cout<<"Reading terrain defs: "<init(); THC std::cout<<"Initializing mapHandler (together): "<map,cgi); THC std::cout<<"Initializing GameState (together): "<w, mh = mm.map[0]->h, wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y; - for(int d=0; dmh->reader->map.twoLevel+1; ++d) + for(int d=0; dmh->map->twoLevel+1; ++d) { SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface); diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 148564e71..3510918a2 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -206,13 +206,13 @@ void CPathfinder::CalcH(Coordinate* node) int ret=-1; int x = node->x; int y = node->y; - if(node->x>=CGI->mh->reader->map.width) - x = CGI->mh->reader->map.width-1; - if(node->y>=CGI->mh->reader->map.height) - y = CGI->mh->reader->map.height-1; + if(node->x>=CGI->mh->map->width) + x = CGI->mh->map->width-1; + if(node->y>=CGI->mh->map->height) + y = CGI->mh->map->height-1; //Get the movement cost. - ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].terType, CGI->mh->reader->map.terrain[x][y].malle,CGI->mh->reader->map.terrain[x][y].nuine); + ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].terType, CGI->mh->map->terrain[x][y].malle,CGI->mh->map->terrain[x][y].nuine); node->h = ret; } diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 2a6a70dc2..609909e92 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -1897,10 +1897,10 @@ int3 CPlayerInterface::repairScreenPos(int3 pos) pos.x = -Woff+1; if(pos.y<=-Hoff) pos.y = -Hoff+1; - if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff) - pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff; - if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff) - pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff; + if(pos.x>CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff) + pos.x = CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff; + if(pos.y>CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff) + pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff; return pos; } void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index 0316cc837..d678b6737 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -2,12 +2,12 @@ #include "CAmbarCendamo.h" #include "../CGameInfo.h" #include "CObjectHandler.h" -#include "CCastleHandler.h" -#include "CTownHandler.h" #include "CDefObjInfoHandler.h" #include "../SDL_Extensions.h" #include "../CGameState.h" -#include "CLodHandler.h" +#include "SDL.h" +#include "CDefHandler.h" +#include "CCreatureHandler.h" #include #include #include @@ -383,19 +383,18 @@ void CAmbarCendamo::deh3m() int ist; ist=i; //starting i for loop + + map.allowedHeroes.resize(HEROES_QUANTITY); + for(int xx=0;xxheroh->heroes.size()) - { - if(c == (c|((unsigned char)intPow(2, yy)))) - CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy]->isAllowed = true; - else - CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy]->isAllowed = false; - } - } + if((i-ist)*8+yy < HEROES_QUANTITY) + if(c != (c|((unsigned char)intPow(2, yy)))) + map.allowedHeroes[(i-ist)*8+yy] = false; } if(map.version>RoE) //probably reserved for further heroes i+=4; @@ -682,7 +681,7 @@ void CAmbarCendamo::deh3m() { //std::cout << "object nr "<id = CGameInfo::mainObj->objh->objInstances.size(); + nobj->id = map.objects.size(); nobj->pos.x = bufor[i++]; nobj->pos.y = bufor[i++]; nobj->pos.z = bufor[i++]; @@ -789,14 +788,7 @@ void CAmbarCendamo::deh3m() nhi->identifier = readNormalNr(i, 4); i+=4; } nhi->setOwner(bufor[i]); ++i; - int typeBuf = readNormalNr(i, 1); ++i; - - //we should already know type from subID - //if(typeBuf==0xff) - // spec->type = NULL; - //else - // spec->type = CGameInfo::mainObj->heroh->heroes[typeBuf]; - + nhi->subID = readNormalNr(i, 1); ++i; if(readChar())//true if hero has nonstandard name nhi->name = readString(); if(map.version>AB) @@ -840,10 +832,9 @@ void CAmbarCendamo::deh3m() //misc5 art //17 if(map.version>=SoD) { - i+=2; - //int id = readNormalNr(i, artidlen); i+=artidlen; - //if(id!=artmask) - // spec->artifWorn[16] = id; + int id = readNormalNr(i, artidlen); i+=artidlen; + if(id!=artmask) + nhi->artifWorn[16] = id; } //spellbook int id = readNormalNr(i, artidlen); i+=artidlen; @@ -871,22 +862,16 @@ void CAmbarCendamo::deh3m() } } //artifacts - nhi->patrolRadious = readNormalNr(i, 1); ++i; - if(nhi->patrolRadious == 0xff) - nhi->patrolRadious = -1; + nhi->patrol.patrolRadious = readNormalNr(i, 1); ++i; + if(nhi->patrol.patrolRadious == 0xff) + nhi->patrol.patrolling = false; + else + nhi->patrol.patrolling = true; if(map.version>RoE) { if(readChar())//true if hero has nonstandard (mapmaker defined) biography - { - int length = readNormalNr(i); i+=4; - int iStart = i; - i+=length; - for(int bb=0; bbbiography+=bufor[iStart+bb]; - } - } + nhi->biography = readString(); nhi->sex = !(bufor[i]); ++i; } //spells @@ -936,9 +921,9 @@ void CAmbarCendamo::deh3m() nhi->mana = -1; nhi->movement = -1; if(nhi->ID==34) - CGI->heroh->heroInstances.push_back(nhi); - else - CGI->objh->objInstances.push_back(nhi); + map.heroes.push_back(nhi); + //else + // CGI->objh->objInstances.push_back(nhi); break; } @@ -1159,7 +1144,7 @@ void CAmbarCendamo::deh3m() case 8: { int heroType = bufor[i]; ++i; - spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType]; + spec->m8hero = heroType; int limit = readNormalNr(i); i+=4; if(limit == ((int)0xffffffff)) { @@ -1426,7 +1411,6 @@ void CAmbarCendamo::deh3m() } case EDefType::TOWN_DEF: { - CCastleObjInfo * spec = new CCastleObjInfo; CGTownInstance * nt = new CGTownInstance(); (*(static_cast(nt))) = *nobj; delete nobj; @@ -1449,7 +1433,7 @@ void CAmbarCendamo::deh3m() { for(int bit=0;bit<8;bit++) if(bufor[i] & (1<h3mbuildings.insert(byte*8+bit); + nt->builtBuildings.insert(byte*8+bit); i++; } //forbidden buildings @@ -1460,18 +1444,14 @@ void CAmbarCendamo::deh3m() nt->forbiddenBuildings.insert(byte*8+bit); i++; } - nt->builtBuildings = convertBuildings(nt->h3mbuildings,nt->subID); + nt->builtBuildings = convertBuildings(nt->builtBuildings,nt->subID); nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings,nt->subID); } else //standard buildings { if(readChar()) //has fort nt->builtBuildings.insert(7); - nt->builtBuildings.insert(10); - nt->builtBuildings.insert(5); - nt->builtBuildings.insert(30); - if(rand()%2) - nt->builtBuildings.insert(31); + nt->builtBuildings.insert(-50); //means that set of standard building should be included } int ist = i; @@ -1555,7 +1535,7 @@ void CAmbarCendamo::deh3m() nce.gen[vv] = readNormalNr(i, 2); i+=2; } i+=4; - spec->events.push_back(nce); + nt->events.insert(nce); }//castle events have been read if(map.version > AB) @@ -1569,7 +1549,7 @@ void CAmbarCendamo::deh3m() nt->builded = 0; nt->destroyed = 0; nt->garrisonHero = NULL; - CGI->townh->townInstances.push_back(nt); + map.towns.push_back(nt); break; } case EDefType::PLAYERONLY_DEF: @@ -1896,7 +1876,7 @@ void CAmbarCendamo::deh3m() case 8: { int heroType = bufor[i]; ++i; - spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType]; + spec->m8hero = heroType; int limit = readNormalNr(i); i+=4; if(limit == ((int)0xffffffff)) { @@ -1955,33 +1935,10 @@ borderguardend: break; } } //end of main switch - CGameInfo::mainObj->objh->objInstances.push_back(nobj); + map.objects.push_back(nobj); }//end of loading objects THC std::cout<<"\tReading objects: "<handler=CGI->spriteh->giveDef(map.defy[ir]->name); - CGDefInfo* pom = CGI->dobjinfo->gobjs[map.defy[ir]->id][map.defy[ir]->subid]; - if(pom) - pom->handler=map.defy[ir]->handler; - else - std::cout << "Lacking def info for " << map.defy[ir]->id << " " << map.defy[ir]->subid <<" " << map.defy[ir]->name << std::endl; - } - for(int vv=0; vvhandler->alphaTransformed) - continue; - for(int yy=0; yyhandler->ourImages.size(); ++yy) - { - map.defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap); - map.defy[vv]->handler->alphaTransformed = true; - } - } - THC std::cout<<"\tUnpacking and handling defs: "< #include #include "../global.h" -#include "SDL.h" #include "../map.h" -#include "CDefHandler.h" #include "CCreatureHandler.h" enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF, EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF, SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF, BORDERGUARD_DEF, HEROPLACEHOLDER_DEF}; diff --git a/hch/CCastleHandler.cpp b/hch/CCastleHandler.cpp deleted file mode 100644 index 8f24dbd55..000000000 --- a/hch/CCastleHandler.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "../stdafx.h" -#include "CCastleHandler.h" \ No newline at end of file diff --git a/hch/CCastleHandler.h b/hch/CCastleHandler.h deleted file mode 100644 index b017b4712..000000000 --- a/hch/CCastleHandler.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef CCASTLEHANDLER_H -#define CCASTLEHANDLER_H - -#include "CBuildingHandler.h" -#include "CHeroHandler.h" -#include "CObjectHandler.h" -#include "CCreatureHandler.h" - -class CCastleEvent -{ -public: - std::string name, message; - int wood, mercury, ore, sulfur, crystal, gems, gold; //gain / loss of resources - unsigned char players; //players for whom this event can be applied - bool forHuman, forComputer; - int firstShow; //postpone of first encounter time in days - int forEvery; //every n days this event will occure - - unsigned char bytes[6]; //build specific buildings (raw format, similar to town's) - - int gen[7]; //additional creatures in i-th level dwelling -}; - -class CCastleObjInfo : public CSpecObjInfo //castle class -{ -public: - int x, y, z; //posiotion - std::vector buildings; //buildings we can build in this castle - std::vector isBuild; //isBuild[i] is true, when building buildings[i] has been built - std::vector isLocked; //isLocked[i] is true, when building buildings[i] canot be built - bool unusualBuildins; //if true, intrepret bytes below - unsigned char buildingSettings[12]; //raw format for two vectors above (greatly depends on town type) - bool hasFort; //used only if unusualBuildings is false - - unsigned char bytes[4]; //identifying bytes - unsigned char player; //255 - nobody, players 0 - 7 - std::string name; //town name - CCreatureSet garrison; - - std::vector possibleSpells; - std::vector obligatorySpells; - std::vector availableSpells; - - std::vector events; - - unsigned char alignment; //255 - same as owner/random, 0 - same as red, 1 - same as blue, etc -}; - -#endif //CCASTLEHANDLER_H \ No newline at end of file diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index 585148f1a..3713e920d 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -9,7 +9,7 @@ #include "../SDL_Extensions.h" #include #include - +#include "CDefHandler.h" CHeroHandler::~CHeroHandler() { for (int j=0;j heroInstances; std::vector heroes; //było nodrze std::vector heroClasses; std::vector flags1, flags2, flags3, flags4; //flags blitted on heroes when , diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 030d38d42..0af46e127 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -242,7 +242,10 @@ int CGHeroInstance::getSecSkillLevel(const int & ID) const } const CArtifact * CGHeroInstance::getArt(int pos) { - return &CGI->arth->artifacts[artifWorn[pos]]; + if(artifWorn.find(pos)!=artifWorn.end()) + return &CGI->arth->artifacts[artifWorn[pos]]; + else + return NULL; } int CGTownInstance::getSightDistance() const //returns sight distance @@ -355,6 +358,7 @@ CGHeroInstance::CGHeroInstance() moveDir = 4; mana = 0; visitedTown = NULL; + type = NULL; } CGHeroInstance::~CGHeroInstance() diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 90073fb61..4f4abc3e9 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -48,30 +48,25 @@ public: bool humanActivate; //true if human player can activate this event }; -//class CHeroObjInfo : public CSpecObjInfo -//{ -//public: -// unsigned char bytes[4]; //mysterius bytes identifying hero in a strange way -// int player; -// CHero * type; -// std::string name; //if nonstandard -// bool standardGarrison; //true if hero has standard garrison -// CCreatureSet garrison; //hero's army -// std::vector artifacts; //hero's artifacts from bag -// //CArtifact * artHead, * artLRing, * artRRing, * artLHand, * artRhand, * artFeet, * artSpellBook, * artMach1, * artMach2, * artMach3, * artMach4, * artMisc1, * artMisc2, * artMisc3, * artMisc4, * artMisc5, * artTorso, * artNeck, * artShoulders; //working artifactsstd::vector artifWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 -// std::map artifWorn; // keys: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 -// bool isGuarding; -// int guardRange; //range of hero's guard -// std::string biography; //if nonstandard -// bool sex; //if true, reverse hero's sex -// std::vector spells; //hero's spells -// int attack, defence, power, knowledge; //main hero's attributes -// unsigned int experience; //hero's experience points -// std::vector abilities; //hero's abilities -// std::vector abilityLevels; //hero ability levels -// bool defaultMainStats; //if true attack, defence, power and knowledge are typical -// CGHeroInstance * myInstance; //pointer to appropriate hero instance -//}; +class CCastleEvent +{ +public: + std::string name, message; + int wood, mercury, ore, sulfur, crystal, gems, gold; //gain / loss of resources + unsigned char players; //players for whom this event can be applied + bool forHuman, forComputer; + int firstShow; //postpone of first encounter time in days + int forEvery; //every n days this event will occure + + unsigned char bytes[6]; //build specific buildings (raw format, similar to town's) + + int gen[7]; //additional creatures in i-th level dwelling + + bool operator<(const CCastleEvent &drugie) const + { + return firstShow m6cre;//for mission 6 std::vector m6number; int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 7 - CHero * m8hero;//for mission 8 + int m8hero;//for mission 8 - hero ID int m9player; //for mission 9 - number; from 0 to 7 std::string firstVisitText, nextVisitText, completedText; @@ -276,7 +271,7 @@ public: //for mission 7 int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 8 - CHero * m8hero; + int m8hero; //hero id //for mission 9 int m9player; //number; from 0 to 7 @@ -343,9 +338,16 @@ public: std::vector > secSkills; //first - ID of skill, second - level of skill (0 - basic, 1 - adv., 2 - expert) int movement; //remaining movement points int identifier; //from the map file - int patrolRadious; //-1 - no patrol bool sex; + struct Patrol + { + Patrol(){patrolling=false;patrolRadious=-1;}; + bool patrolling; + int patrolRadious; + } patrol; + + bool inTownGarrison; // if hero is in town garrison CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison @@ -379,29 +381,25 @@ public: std::string name; // name of town int builded; //how many buildings has been built this turn int destroyed; //how many buildings has been destroyed this turn - + const CGHeroInstance * garrisonHero, *visitingHero; int identifier; //special identifier from h3m (only > RoE maps) int alignment; + std::set forbiddenBuildings, builtBuildings; + std::vector possibleSpells, obligatorySpells, availableSpells; struct StrInfo { std::map creatures; //level - available amount } strInfo; - - std::set forbiddenBuildings, builtBuildings, h3mbuildings; + std::set events; - const CGHeroInstance * garrisonHero, *visitingHero; - - std::vector possibleSpells, obligatorySpells, availableSpells; int getSightDistance() const; //returns sight distance - int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol bool creatureDwelling(const int & level, bool upgraded=false) const; int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present int creatureGrowth(const int & level) const; - bool hasFort() const; bool hasCapitol() const; int dailyIncome() const; @@ -414,7 +412,6 @@ class CObjectHandler { public: std::vector objects; //vector of objects; i-th object in vector has subnumber i - std::vector objInstances; //vector with objects on map std::vector cregens; //type 17. dwelling subid -> creature ID void loadObjects(); diff --git a/hch/CTownHandler.h b/hch/CTownHandler.h index 64fcd5b27..58f5ebffc 100644 --- a/hch/CTownHandler.h +++ b/hch/CTownHandler.h @@ -53,9 +53,6 @@ public: std::map > structures; // > std::map > > requirements; //requirements[town_id][structure_id] -> set of required buildings - - std::vector townInstances; - }; #endif //CTOWNHANDLER_H \ No newline at end of file diff --git a/map.h b/map.h index ff9b07945..6a9e332d0 100644 --- a/map.h +++ b/map.h @@ -6,14 +6,15 @@ #include #include "global.h" class CGDefInfo; -class CHeroObjInfo; +class CGObjectInstance; +class CGHeroInstance; +class CGTownInstance; enum ESortBy{name,playerAm,size,format, viccon,loscon}; struct Sresource { std::string resName; //name of this resource int amount; //it can be greater and lesser than 0 }; -class CGHeroInstance; struct TimeEvent { std::string eventName; @@ -106,12 +107,6 @@ struct VicCon7 : public CspecificVictoryConidtions // defeat a specific monster { int3 locationOfMonster; }; -/*struct VicCon8 : public CspecificVictoryConidtions // flag all creature dwellings -{ -}; -struct VicCon9 : public CspecificVictoryConidtions // flag all mines -{ -};*/ struct VicCona : public CspecificVictoryConidtions //transport specific artifact { int artifactID; @@ -141,7 +136,6 @@ public: int firstOccurence; int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time; }; - struct Mapa { Eformat version; // version of map Eformat @@ -167,7 +161,12 @@ struct Mapa std::vector allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed std::vector allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed std::vector allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed + std::vector allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed std::vector events; + + std::vector objects; + std::vector heroes; + std::vector towns; }; class CMapHeader { diff --git a/mapHandler.cpp b/mapHandler.cpp index 8ed75b2ed..8164e9e04 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -9,7 +9,6 @@ #include #include "CGameState.h" #include "CLua.h" -#include "hch\CCastleHandler.h" #include "hch\CHeroHandler.h" #include "hch\CTownHandler.h" #include "hch\CArtHandler.h" @@ -178,17 +177,17 @@ std::pair CMapHandler::pickObject(CGObjectInstance *obj) CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info; if (info->asCastle) { - for(int i=0;iobjh->objInstances.size();i++) + for(int i=0;iobjects.size();i++) { - if(CGI->objh->objInstances[i]->ID==77 && dynamic_cast(CGI->objh->objInstances[i])->identifier == info->identifier) + if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) { - randomizeObject(CGI->objh->objInstances[i]); //we have to randomize the castle first - faction = CGI->objh->objInstances[i]->subID; + randomizeObject(map->objects[i]); //we have to randomize the castle first + faction = map->objects[i]->subID; break; } - else if(CGI->objh->objInstances[i]->ID==98 && dynamic_cast(CGI->objh->objInstances[i])->identifier == info->identifier) + else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) { - faction = CGI->objh->objInstances[i]->subID; + faction = map->objects[i]->subID; break; } } @@ -216,17 +215,17 @@ std::pair CMapHandler::pickObject(CGObjectInstance *obj) CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info; if (info->asCastle) { - for(int i=0;iobjh->objInstances.size();i++) + for(int i=0;iobjects.size();i++) { - if(CGI->objh->objInstances[i]->ID==77 && dynamic_cast(CGI->objh->objInstances[i])->identifier == info->identifier) + if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) { - randomizeObject(CGI->objh->objInstances[i]); //we have to randomize the castle first - faction = CGI->objh->objInstances[i]->subID; + randomizeObject(map->objects[i]); //we have to randomize the castle first + faction = map->objects[i]->subID; break; } - else if(CGI->objh->objInstances[i]->ID==98 && dynamic_cast(CGI->objh->objInstances[i])->identifier == info->identifier) + else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) { - faction = CGI->objh->objInstances[i]->subID; + faction = map->objects[i]->subID; break; } } @@ -290,8 +289,8 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur) cur->ID = ran.first; cur->subID = ran.second; h->type = CGI->heroh->heroes[ran.second]; - CGI->heroh->heroInstances.push_back(h); - CGI->objh->objInstances.erase(std::find(CGI->objh->objInstances.begin(),CGI->objh->objInstances.end(),h)); + map->heroes.push_back(h); + map->objects.erase(std::find(map->objects.begin(),map->objects.end(),h)); return; //TODO: maybe we should do something with definfo? } else if(ran.first==98)//special code for town @@ -330,11 +329,11 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur) void CMapHandler::randomizeObjects() { CGObjectInstance * cur; - for(int no=0; noobjh->objInstances.size(); ++no) + for(int no=0; noobjects.size(); ++no) { - randomizeObject(CGI->objh->objInstances[no]); - if(CGI->objh->objInstances[no]->ID==26) - CGI->objh->objInstances[no]->defInfo->handler=NULL; + randomizeObject(map->objects[no]); + if(map->objects[no]->ID==26) + map->objects[no]->defInfo->handler=NULL; } } void CMapHandler::prepareFOWDefs() @@ -385,11 +384,11 @@ void CMapHandler::prepareFOWDefs() { CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap); } - //visibility.resize(reader->map.width+2*Woff); - //for(int gg=0; ggmap.width+2*Woff; ++gg) + //visibility.resize(map->width+2*Woff); + //for(int gg=0; ggwidth+2*Woff; ++gg) //{ - // visibility[gg].resize(reader->map.height+2*Hoff); - // for(int jj=0; jjmap.height+2*Hoff; ++jj) + // visibility[gg].resize(map->height+2*Hoff); + // for(int jj=0; jjheight+2*Hoff; ++jj) // visibility[gg][jj] = true; //} @@ -458,9 +457,9 @@ void CMapHandler::roadsRiverTerrainInit() } } - //roadBitmaps = new SDL_Surface** [reader->map.width+2*Woff]; - //for (int ii=0;iimap.width+2*Woff;ii++) - // roadBitmaps[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory + //roadBitmaps = new SDL_Surface** [map->width+2*Woff]; + //for (int ii=0;iiwidth+2*Woff;ii++) + // roadBitmaps[ii] = new SDL_Surface*[map->height+2*Hoff]; // allocate memory sizes.x = CGI->ac->map.width; sizes.y = CGI->ac->map.height; sizes.z = CGI->ac->map.twoLevel+1; @@ -477,42 +476,42 @@ void CMapHandler::roadsRiverTerrainInit() - for (int i=0; imap.width; i++) //jest po szerokości + for (int i=0; iwidth; i++) //jest po szerokości { - for (int j=0; jmap.height;j++) //po wysokości + for (int j=0; jheight;j++) //po wysokości { - for (int k=0; k<=reader->map.twoLevel; ++k) + for (int k=0; k<=map->twoLevel; ++k) { - TerrainTile** pomm = reader->map.terrain; ; + TerrainTile** pomm = map->terrain; ; if (k==0) - pomm = reader->map.terrain; + pomm = map->terrain; else - pomm = reader->map.undergroungTerrain; + pomm = map->undergroungTerrain; if(pomm[i][j].malle) { int cDir; bool rotV, rotH; if(k==0) { - int roadpom = reader->map.terrain[i][j].malle-1, - impom = reader->map.terrain[i][j].roadDir; + int roadpom = map->terrain[i][j].malle-1, + impom = map->terrain[i][j].roadDir; SDL_Surface *pom1 = roadDefs[roadpom]->ourImages[impom].bitmap; ttiles[i][j][k].roadbitmap.push_back(pom1); - cDir = reader->map.terrain[i][j].roadDir; + cDir = map->terrain[i][j].roadDir; - rotH = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 5) & 1; - rotV = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 4) & 1; + rotH = (map->terrain[i][j].siodmyTajemniczyBajt >> 5) & 1; + rotV = (map->terrain[i][j].siodmyTajemniczyBajt >> 4) & 1; } else { - int pom111 = reader->map.undergroungTerrain[i][j].malle-1, - pom777 = reader->map.undergroungTerrain[i][j].roadDir; + int pom111 = map->undergroungTerrain[i][j].malle-1, + pom777 = map->undergroungTerrain[i][j].roadDir; SDL_Surface *pom1 = roadDefs[pom111]->ourImages[pom777].bitmap; ttiles[i][j][k].roadbitmap.push_back(pom1); - cDir = reader->map.undergroungTerrain[i][j].roadDir; + cDir = map->undergroungTerrain[i][j].roadDir; - rotH = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 5) & 1; - rotV = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 4) & 1; + rotH = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 5) & 1; + rotV = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 4) & 1; } if(rotH) { @@ -557,20 +556,20 @@ void CMapHandler::roadsRiverTerrainInit() } //simple values initialized - for (int i=0; imap.width; i++) //jest po szerokości + for (int i=0; iwidth; i++) //jest po szerokości { - for (int j=0; jmap.height;j++) //po wysokości + for (int j=0; jheight;j++) //po wysokości { - for(int k=0; k<=reader->map.twoLevel; ++k) + for(int k=0; k<=map->twoLevel; ++k) { - TerrainTile** pomm = reader->map.terrain; + TerrainTile** pomm = map->terrain; if(k==0) { - pomm = reader->map.terrain; + pomm = map->terrain; } else { - pomm = reader->map.undergroungTerrain; + pomm = map->undergroungTerrain; } if(pomm[i][j].nuine) { @@ -578,17 +577,17 @@ void CMapHandler::roadsRiverTerrainInit() bool rotH, rotV; if(k==0) { - ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[reader->map.terrain[i][j].nuine-1]->ourImages[reader->map.terrain[i][j].rivDir].bitmap); - cDir = reader->map.terrain[i][j].rivDir; - rotH = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 3) & 1; - rotV = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 2) & 1; + ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[map->terrain[i][j].nuine-1]->ourImages[map->terrain[i][j].rivDir].bitmap); + cDir = map->terrain[i][j].rivDir; + rotH = (map->terrain[i][j].siodmyTajemniczyBajt >> 3) & 1; + rotV = (map->terrain[i][j].siodmyTajemniczyBajt >> 2) & 1; } else { - ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[reader->map.undergroungTerrain[i][j].nuine-1]->ourImages[reader->map.undergroungTerrain[i][j].rivDir].bitmap); - cDir = reader->map.undergroungTerrain[i][j].rivDir; - rotH = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 3) & 1; - rotV = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 2) & 1; + ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[map->undergroungTerrain[i][j].nuine-1]->ourImages[map->undergroungTerrain[i][j].rivDir].bitmap); + cDir = map->undergroungTerrain[i][j].rivDir; + rotH = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 3) & 1; + rotV = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 2) & 1; } if(rotH) { @@ -609,56 +608,56 @@ void CMapHandler::roadsRiverTerrainInit() } void CMapHandler::borderAndTerrainBitmapInit() { - //terrainBitmap = new SDL_Surface **[reader->map.width+2*Woff]; - //for (int ii=0;iimap.width+2*Woff;ii++) - // terrainBitmap[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory + //terrainBitmap = new SDL_Surface **[map->width+2*Woff]; + //for (int ii=0;iiwidth+2*Woff;ii++) + // terrainBitmap[ii] = new SDL_Surface*[map->height+2*Hoff]; // allocate memory CDefHandler * bord = CGameInfo::mainObj->spriteh->giveDef("EDG.DEF"); bord->notFreeImgs = true; - for (int i=0-Woff; imap.width+Woff; i++) //jest po szerokości + for (int i=0-Woff; iwidth+Woff; i++) //jest po szerokości { - for (int j=0-Hoff; jmap.height+Hoff;j++) //po wysokości + for (int j=0-Hoff; jheight+Hoff;j++) //po wysokości { - for(int k=0; k<=reader->map.twoLevel; ++k) + for(int k=0; k<=map->twoLevel; ++k) { - if(i < 0 || i > (reader->map.width-1) || j < 0 || j > (reader->map.height-1)) + if(i < 0 || i > (map->width-1) || j < 0 || j > (map->height-1)) { if(i==-1 && j==-1) { ttiles[i][j][k].terbitmap.push_back(bord->ourImages[16].bitmap); continue; } - else if(i==-1 && j==(reader->map.height)) + else if(i==-1 && j==(map->height)) { ttiles[i][j][k].terbitmap.push_back(bord->ourImages[19].bitmap); continue; } - else if(i==(reader->map.width) && j==-1) + else if(i==(map->width) && j==-1) { ttiles[i][j][k].terbitmap.push_back(bord->ourImages[17].bitmap); continue; } - else if(i==(reader->map.width) && j==(reader->map.height)) + else if(i==(map->width) && j==(map->height)) { ttiles[i][j][k].terbitmap.push_back(bord->ourImages[18].bitmap); continue; } - else if(j == -1 && i > -1 && i < reader->map.height) + else if(j == -1 && i > -1 && i < map->height) { ttiles[i][j][k].terbitmap.push_back(bord->ourImages[22+rand()%2].bitmap); continue; } - else if(i == -1 && j > -1 && j < reader->map.height) + else if(i == -1 && j > -1 && j < map->height) { ttiles[i][j][k].terbitmap.push_back(bord->ourImages[33+rand()%2].bitmap); continue; } - else if(j == reader->map.height && i >-1 && i < reader->map.width) + else if(j == map->height && i >-1 && i < map->width) { ttiles[i][j][k].terbitmap.push_back(bord->ourImages[29+rand()%2].bitmap); continue; } - else if(i == reader->map.width && j > -1 && j < reader->map.height) + else if(i == map->width && j > -1 && j < map->height) { ttiles[i][j][k].terbitmap.push_back(bord->ourImages[25+rand()%2].bitmap); continue; @@ -669,12 +668,12 @@ void CMapHandler::borderAndTerrainBitmapInit() continue; } } - //TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff]; + //TerrainTile zz = map->terrain[i-Woff][j-Hoff]; std::string name; if (k>0) - name = nameFromType(reader->map.undergroungTerrain[i][j].tertype); + name = nameFromType(map->undergroungTerrain[i][j].tertype); else - name = nameFromType(reader->map.terrain[i][j].tertype); + name = nameFromType(map->terrain[i][j].tertype); for (unsigned int m=0; mmap.terrain[i][j].terview; + ktora = map->terrain[i][j].terview; else - ktora = reader->map.undergroungTerrain[i][j].terview; + ktora = map->undergroungTerrain[i][j].terview; ttiles[i][j][k].terbitmap.push_back(defs[m]->ourImages[ktora].bitmap); int zz; if (k==0) - zz = (reader->map.terrain[i][j].siodmyTajemniczyBajt)%4; + zz = (map->terrain[i][j].siodmyTajemniczyBajt)%4; else - zz = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt)%4; + zz = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt)%4; switch (zz) { case 1: @@ -729,15 +728,15 @@ void CMapHandler::borderAndTerrainBitmapInit() void CMapHandler::initObjectRects() { //initializing objects / rects - for(int f=0; fobjh->objInstances.size(); ++f) + for(int f=0; fobjects.size(); ++f) { - /*CGI->objh->objInstances[f]->pos.x+=1; - CGI->objh->objInstances[f]->pos.y+=1;*/ - if(!CGI->objh->objInstances[f]->defInfo) + /*map->objects[f]->pos.x+=1; + map->objects[f]->pos.y+=1;*/ + if(!map->objects[f]->defInfo) { continue; } - CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler; + CDefHandler * curd = map->objects[f]->defInfo->handler; if(curd) { for(int fx=0; fxourImages[0].bitmap->w>>5; ++fx) //curd->ourImages[0].bitmap->w/32 @@ -749,21 +748,21 @@ void CMapHandler::initObjectRects() cr.h = 32; cr.x = fx<<5; //fx*32 cr.y = fy<<5; //fy*32 - std::pair toAdd = std::make_pair(CGI->objh->objInstances[f],cr); + std::pair toAdd = std::make_pair(map->objects[f],cr); - if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32] - //[CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32] - //[CGI->objh->objInstances[f]->pos.z]; - ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd); + // [map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32] + //[map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32] + //[map->objects[f]->pos.z]; + ttiles[map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][map->objects[f]->pos.z].objects.push_back(toAdd); } } // for(int fy=0; fyourImages[0].bitmap->h/32; ++fy) } //for(int fx=0; fxourImages[0].bitmap->w/32; ++fx) }//if curd - } // for(int f=0; fobjh->objInstances.size(); ++f) + } // for(int f=0; fobjects.size(); ++f) for(int ix=0; ixobjh->objInstances.size(); ++f) //calculationg blocked / visitable positions + for(int f=0; fobjects.size(); ++f) //calculationg blocked / visitable positions { - if(!CGI->objh->objInstances[f]->defInfo) + if(!map->objects[f]->defInfo) continue; - CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler; + CDefHandler * curd = map->objects[f]->defInfo->handler; for(int fx=0; fx<8; ++fx) { for(int fy=0; fy<6; ++fy) { - int xVal = CGI->objh->objInstances[f]->pos.x + fx - 7; - int yVal = CGI->objh->objInstances[f]->pos.y + fy - 5; - int zVal = CGI->objh->objInstances[f]->pos.z; + int xVal = map->objects[f]->pos.x + fx - 7; + int yVal = map->objects[f]->pos.y + fy - 5; + int zVal = map->objects[f]->pos.z; if(xVal>=0 && xVal=0 && yValobjh->objInstances[f]->defInfo->visitMap[fy] >> (7 - fx)) & 1)) + if(((map->objects[f]->defInfo->visitMap[fy] >> (7 - fx)) & 1)) curt.visitable = true; - if(!((CGI->objh->objInstances[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1)) + if(!((map->objects[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1)) curt.blocked = true; } } @@ -803,6 +802,31 @@ void CMapHandler::calculateBlockedPos() } void CMapHandler::init() { + timeHandler th; + th.getDif(); + + ///loading defs from lod + for (int ir=0;irdefy.size();ir++) + { + map->defy[ir]->handler=CGI->spriteh->giveDef(map->defy[ir]->name); + CGDefInfo* pom = CGI->dobjinfo->gobjs[map->defy[ir]->id][map->defy[ir]->subid]; + if(pom) + pom->handler=map->defy[ir]->handler; + else + std::cout << "Lacking def info for " << map->defy[ir]->id << " " << map->defy[ir]->subid <<" " << map->defy[ir]->name << std::endl; + } + for(int vv=0; vvdefy.size(); ++vv) + { + if(map->defy[vv]->handler->alphaTransformed) + continue; + for(int yy=0; yydefy[vv]->handler->ourImages.size(); ++yy) + { + map->defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map->defy[vv]->handler->ourImages[yy].bitmap); + map->defy[vv]->handler->alphaTransformed = true; + } + } + THC std::cout<<"\tUnpacking and handling defs: "<map.players[CGI->scenarioOps.playerInfos[i].color].allowedFactions & 1<players[CGI->scenarioOps.playerInfos[i].color].allowedFactions & 1<scenarioOps.playerInfos[i].castle = f; } } for(int i=0;imap.players[i].heroesNames.size();j++) + for(int j=0; jplayers[i].heroesNames.size();j++) { - usedHeroes.insert(reader->map.players[i].heroesNames[j].heroID); + usedHeroes.insert(map->players[i].heroesNames[j].heroID); } } + std::cout<<"\tLoading town defs, picking random factions and heroes: "<map.defy.size(); ++h) //initializing loaded def handler's info + for(int h=0; hdefy.size(); ++h) //initializing loaded def handler's info { - //std::string hlp = reader->map.defy[h]->name; + //std::string hlp = map->defy[h]->name; //std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper); - CGI->mh->loadedDefs.insert(std::make_pair(reader->map.defy[h]->name, reader->map.defy[h]->handler)); + CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler)); } std::cout<<"\tCollecting loaded def's handlers: "<map.players[i].generateHeroAtMainTown && reader->map.players[i].hasMainTown) || (reader->map.players[i].hasMainTown && reader->map.version==RoE)) + if((map->players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE)) { - int3 hpos = reader->map.players[i].posOfMainTown; + int3 hpos = map->players[i].posOfMainTown; hpos.x+=1;// hpos.y+=1; int j; for(j=0;jscenarioOps.playerInfos.size();j++) @@ -877,8 +900,8 @@ void CMapHandler::init() h=pickHero(i); CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i); nnn->defInfo->handler = CGI->heroh->flags1[0]; - CGI->heroh->heroInstances.push_back(nnn); - CGI->objh->objInstances.push_back(nnn); + map->heroes.push_back(nnn); + map->objects.push_back(nnn); } } std::cout<<"\tGiving starting heroes: "<((reader->map.width+Woff)) || (dy+y)>((reader->map.height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) ) + if (((dx+x)>((map->width+Woff)) || (dy+y)>((map->height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) ) throw new std::string("terrainRect: out of range"); ////printing terrain for (int bx=0; bx=0 && by+y>=0 && bx+xmh->reader->map.width && by+ymh->reader->map.height && !visibilityMap[bx+x][by+y][level]) + if(bx+x>=0 && by+y>=0 && bx+xmh->map->width && by+ymh->map->height && !visibilityMap[bx+x][by+y][level]) { SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibilityMap, level); CSDL_Ext::blit8bppAlphaTo24bpp(hide, &genRect(sr.h, sr.w, 0, 0), su, &sr); @@ -1094,7 +1117,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, { for (int by=0; byreader->map.width+(-1) || by+y>reader->map.height+(-1)) + if(bx+x<0 || by+y<0 || bx+x>map->width+(-1) || by+y>map->height+(-1)) { SDL_Rect sr; sr.y=by*32; @@ -1412,12 +1435,12 @@ SDL_Surface * CMapHandler::getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV< int CMapHandler::getCost(int3 &a, int3 &b, const CGHeroInstance *hero) { int ret=-1; - if(a.x>=CGI->mh->reader->map.width && a.y>=CGI->mh->reader->map.height) - ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->reader->map.width-1][CGI->mh->reader->map.width-1][a.z].malle]; - else if(a.x>=CGI->mh->reader->map.width && a.ymh->reader->map.height) - ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->reader->map.width-1][a.y][a.z].malle]; - else if(a.xmh->reader->map.width && a.y>=CGI->mh->reader->map.height) - ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][CGI->mh->reader->map.width-1][a.z].malle]; + if(a.x>=CGI->mh->map->width && a.y>=CGI->mh->map->height) + ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][CGI->mh->map->width-1][a.z].malle]; + else if(a.x>=CGI->mh->map->width && a.ymh->map->height) + ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][a.y][a.z].malle]; + else if(a.xmh->map->width && a.y>=CGI->mh->map->height) + ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][CGI->mh->map->width-1][a.z].malle]; else ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].malle]; if(!(a.x==b.x || a.y==b.y)) @@ -1591,10 +1614,10 @@ std::string CMapHandler::getRandomizedDefName(CGDefInfo *di, CGObjectInstance * bool CMapHandler::removeObject(CGObjectInstance *obj) { hideObject(obj); - std::vector::iterator db = std::find(CGI->objh->objInstances.begin(), CGI->objh->objInstances.end(), obj); + std::vector::iterator db = std::find(map->objects.begin(), map->objects.end(), obj); recalculateHideVisPosUnderObj(*db); delete *db; - CGI->objh->objInstances.erase(db); + map->objects.erase(db); return true; } @@ -1792,20 +1815,20 @@ unsigned char CMapHandler::getDir(const int3 &a, const int3 &b) void CMapHandler::loadDefs() { std::set loadedTypes; - for (int i=0; imap.width; i++) + for (int i=0; iwidth; i++) { - for (int j=0; jmap.width; j++) + for (int j=0; jwidth; j++) { - if (loadedTypes.find(reader->map.terrain[i][j].tertype)==loadedTypes.end()) + if (loadedTypes.find(map->terrain[i][j].tertype)==loadedTypes.end()) { - CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(reader->map.terrain[i][j].tertype).c_str()); - loadedTypes.insert(reader->map.terrain[i][j].tertype); + CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(map->terrain[i][j].tertype).c_str()); + loadedTypes.insert(map->terrain[i][j].tertype); defs.push_back(sdh); } - if (reader->map.twoLevel && loadedTypes.find(reader->map.undergroungTerrain[i][j].tertype)==loadedTypes.end()) + if (map->twoLevel && loadedTypes.find(map->undergroungTerrain[i][j].tertype)==loadedTypes.end()) { - CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(reader->map.undergroungTerrain[i][j].tertype).c_str()); - loadedTypes.insert(reader->map.undergroungTerrain[i][j].tertype); + CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(map->undergroungTerrain[i][j].tertype).c_str()); + loadedTypes.insert(map->undergroungTerrain[i][j].tertype); defs.push_back(sdh); } } diff --git a/mapHandler.h b/mapHandler.h index c0aeb7547..013e9a700 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -60,7 +60,7 @@ class CMapHandler public: PseudoV< PseudoV< PseudoV > > ttiles; int3 sizes; - CAmbarCendamo * reader; + Mapa * map; std::set usedHeroes; CDefHandler * fullHide; CDefHandler * partialHide; From dd9b5062938d5093685679f691f1a04e294200e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Wed, 11 Jun 2008 01:58:18 +0000 Subject: [PATCH 06/47] Merged changes from trunk (since r452) --- CBattleInterface.cpp | 395 ++++++++++++++++++++++++++++++------------- CBattleInterface.h | 20 ++- CCallback.cpp | 13 +- CCallback.h | 2 + CGameInterface.h | 8 +- CGameState.cpp | 7 +- CPlayerInterface.cpp | 8 +- CPlayerInterface.h | 4 +- CPreGame.cpp | Bin 128496 -> 128500 bytes 9 files changed, 329 insertions(+), 128 deletions(-) diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 9d2f6e8bc..6c30061ce 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -19,7 +19,7 @@ extern SDL_Color zwykly; SDL_Surface * CBattleInterface::cellBorder, * CBattleInterface::cellShade; CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2) -: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL) +: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL) { //initializing armies this->army1 = army1; @@ -213,7 +213,10 @@ void CBattleInterface::show(SDL_Surface * to) } } //showing selected unit's range - showRange(to, activeStack); + if(creAnims[activeStack]->getType() != 0) //don't show if unit is moving + { + showRange(to, activeStack); + } //showing menu background and console blitAt(menu, 0, 556, to); @@ -244,25 +247,31 @@ void CBattleInterface::show(SDL_Surface * to) { stackByHex[j->second.position] = j->second.ID; } + + attackingShowHelper(); // handle attack animation + for(int b=0; b<187; ++b) { if(stackByHex[b]!=-1) { - creAnims[stackByHex[b]]->nextFrame(to, creAnims[stackByHex[b]]->pos.x, creAnims[stackByHex[b]]->pos.y, creDir[stackByHex[b]], animCount%2==0 || creAnims[stackByHex[b]]->getType()==0, stackByHex[b]==activeStack); //increment always when moving + creAnims[stackByHex[b]]->nextFrame(to, creAnims[stackByHex[b]]->pos.x, creAnims[stackByHex[b]]->pos.y, creDir[stackByHex[b]], (animCount%2==0 || creAnims[stackByHex[b]]->getType()!=2) && stacks[stackByHex[b]].alive, stackByHex[b]==activeStack); //increment always when moving, never if stack died //printing amount - if(stacks[stackByHex[b]].attackerOwned) + if(stacks[stackByHex[b]].amount > 0) //don't print if stack is not alive { - CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b]]->pos.x + 220, creAnims[stackByHex[b]]->pos.y + 260)); - std::stringstream ss; - ss<pos.x + 220 + 14, creAnims[stackByHex[b]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); - } - else - { - CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b]]->pos.x + 202, creAnims[stackByHex[b]]->pos.y + 260)); - std::stringstream ss; - ss<pos.x + 202 + 14, creAnims[stackByHex[b]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); + if(stacks[stackByHex[b]].attackerOwned) + { + CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b]]->pos.x + 220, creAnims[stackByHex[b]]->pos.y + 260)); + std::stringstream ss; + ss<pos.x + 220 + 14, creAnims[stackByHex[b]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); + } + else + { + CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b]]->pos.x + 202, creAnims[stackByHex[b]]->pos.y + 260)); + std::stringstream ss; + ss<pos.x + 202 + 14, creAnims[stackByHex[b]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); + } } } } @@ -362,8 +371,17 @@ void CBattleInterface::stackRemoved(CStack stack) creAnims.erase(stack.ID); } -void CBattleInterface::stackKilled(int ID) +void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby) { + creAnims[ID]->setType(5); //death + for(int i=0; iframesInGroup(5)-1; ++i) + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + } + + printConsoleAttacked(ID, dmg, killed, IDby); } void CBattleInterface::stackActivated(int number) @@ -548,8 +566,18 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo creAnims[number]->pos.y = coords.second; } -void CBattleInterface::stackIsAttacked(int ID) +void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby) { + creAnims[ID]->setType(3); //getting hit + for(int i=0; iframesInGroup(3); ++i) + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + } + creAnims[ID]->setType(2); + + printConsoleAttacked(ID, dmg, killed, IDby); } void CBattleInterface::stackAttacking(int ID, int dest) @@ -560,134 +588,97 @@ void CBattleInterface::stackAttacking(int ID, int dest) switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction { case 0: - //reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(10); - for(int i=0; iframesInGroup(10); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } //reverseCreature(ID, aStack.position, true); break; case 1: - creAnims[ID]->setType(10); - for(int i=0; iframesInGroup(10); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 2: - creAnims[ID]->setType(11); - for(int i=0; iframesInGroup(11); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 3: - creAnims[ID]->setType(12); - for(int i=0; iframesInGroup(12); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 4: - //reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(12); - for(int i=0; iframesInGroup(12); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } //reverseCreature(ID, aStack.position, true); break; case 5: - reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(11); - for(int i=0; iframesInGroup(11); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } reverseCreature(ID, aStack.position, true); break; } - creAnims[ID]->setType(2); } else //else for if(aStack.creature->isDoubleWide()) { switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction { case 0: - reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(10); - for(int i=0; iframesInGroup(10); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } reverseCreature(ID, aStack.position, true); break; case 1: - creAnims[ID]->setType(10); - for(int i=0; iframesInGroup(10); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 2: - creAnims[ID]->setType(11); - for(int i=0; iframesInGroup(11); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 3: - creAnims[ID]->setType(12); - for(int i=0; iframesInGroup(12); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } break; case 4: - reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(12); - for(int i=0; iframesInGroup(12); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } reverseCreature(ID, aStack.position, true); break; case 5: - reverseCreature(ID, aStack.position, true); - creAnims[ID]->setType(11); - for(int i=0; iframesInGroup(11); ++i) - { - show(); - CSDL_Ext::update(); - SDL_framerateDelay(LOCPLINT->mainFPSmng); - } reverseCreature(ID, aStack.position, true); break; } - creAnims[ID]->setType(2); + } + + attackingInfo = new CAttHelper; + attackingInfo->dest = dest; + attackingInfo->frame = 0; + attackingInfo->ID = ID; + attackingInfo->reversing = false; + + if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction + { + case 0: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); + break; + case 1: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); + break; + case 2: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + case 3: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 4: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 5: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction + { + case 0: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); + break; + case 1: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); + break; + case 2: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + case 3: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 4: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 5: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + } } } @@ -730,6 +721,144 @@ void CBattleInterface::showRange(SDL_Surface * to, int ID) } } + +void CBattleInterface::attackingShowHelper() +{ + if(attackingInfo && !attackingInfo->reversing) + { + if(attackingInfo->frame == 0) + { + CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack + if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + creAnims[attackingInfo->ID]->setType(10); + break; + case 1: + creAnims[attackingInfo->ID]->setType(10); + break; + case 2: + creAnims[attackingInfo->ID]->setType(11); + break; + case 3: + creAnims[attackingInfo->ID]->setType(12); + break; + case 4: + creAnims[attackingInfo->ID]->setType(12); + break; + case 5: + creAnims[attackingInfo->ID]->setType(11); + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + creAnims[attackingInfo->ID]->setType(10); + break; + case 1: + creAnims[attackingInfo->ID]->setType(10); + break; + case 2: + creAnims[attackingInfo->ID]->setType(11); + break; + case 3: + creAnims[attackingInfo->ID]->setType(12); + break; + case 4: + creAnims[attackingInfo->ID]->setType(12); + break; + case 5: + creAnims[attackingInfo->ID]->setType(11); + break; + } + } + } + else if(attackingInfo->frame == (attackingInfo->maxframe - 1)) + { + attackingInfo->reversing = true; + CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack + if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + //reverseCreature(ID, aStack.position, true); + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + //reverseCreature(ID, aStack.position, true); + break; + case 5: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + case 5: + reverseCreature(attackingInfo->ID, aStack.position, true); + break; + } + } + attackingInfo->reversing = false; + creAnims[attackingInfo->ID]->setType(2); + delete attackingInfo; + attackingInfo = NULL; + } + if(attackingInfo) + { + attackingInfo->frame++; + } + } +} + +void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby) +{ + char tabh[200]; + CStack attacker = LOCPLINT->cb->battleGetStackByID(IDby); + CStack defender = LOCPLINT->cb->battleGetStackByID(ID); + int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(), + (attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()), + dmg); + if(killed > 0) + { + if(killed > 1) + { + sprintf(tabh + end, CGI->generaltexth->allTexts[379].c_str(), killed, defender.creature->namePl.c_str()); + } + else //killed == 1 + { + sprintf(tabh + end, CGI->generaltexth->allTexts[378].c_str(), defender.creature->nameSing.c_str()); + } + } + + console->addText(std::string(tabh)); +} + void CBattleHero::show(SDL_Surface *to) { //animation of flag @@ -865,9 +994,14 @@ void CBattleHex::hover(bool on) { hovered = on; Hoverable::hover(on); + if(!on && setAlterText) + { + myInterface->console->alterTxt = std::string(); + setAlterText = false; + } } -CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strictHovered(false), myInterface(NULL) +CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strictHovered(false), myInterface(NULL), setAlterText(false) { } @@ -884,6 +1018,26 @@ void CBattleHex::mouseMoved(SDL_MouseMotionEvent &sEvent) strictHovered = true; } } + + if(hovered && strictHovered) //print attacked creature to console + { + if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 && + LOCPLINT->cb->battleGetStackByPos(myNumber).owner != LOCPLINT->playerID && + LOCPLINT->cb->battleGetStackByPos(myNumber).alive) + { + char tabh[160]; + CStack attackedStack = LOCPLINT->cb->battleGetStackByPos(myNumber); + std::string attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl; + sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); + myInterface->console->alterTxt = std::string(tabh); + setAlterText = true; + } + } + else if(setAlterText) + { + myInterface->console->alterTxt = std::string(); + setAlterText = false; + } } void CBattleHex::clickLeft(boost::logic::tribool down) @@ -919,7 +1073,7 @@ void CBattleHex::clickRight(boost::logic::tribool down) } } -CBattleConsole::CBattleConsole() : lastShown(-1) +CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt("") { } @@ -930,7 +1084,11 @@ CBattleConsole::~CBattleConsole() void CBattleConsole::show(SDL_Surface * to) { - if(texts.size()) + if(alterTxt.size()) + { + CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to); + } + else if(texts.size()) { if(texts.size()==1) { @@ -948,7 +1106,18 @@ bool CBattleConsole::addText(std::string text) { if(text.size()>70) return false; //text too long! - texts.push_back(text); + int firstInToken = 0; + for(int i=0; i texts; //a place where texts are stored - int lastShown; //las shown line of text + int lastShown; //last shown line of text public: + std::string alterTxt; //if it's not empty, this text is displayed CBattleConsole(); //c-tor ~CBattleConsole(); //d-tor void show(SDL_Surface * to = 0); @@ -81,6 +84,17 @@ private: int activeStack; //number of active stack; -1 - no one void showRange(SDL_Surface * to, int ID); //show helper funtion ot mark range of a unit + class CAttHelper + { + public: + int ID; //attacking stack + int dest; //atacked hex + int frame, maxframe; //frame of animation, number of frames of animation + bool reversing; + } * attackingInfo; + void attackingShowHelper(); + void printConsoleAttacked(int ID, int dmg, int killed, int IDby); + public: CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor ~CBattleInterface(); //d-tor @@ -112,10 +126,10 @@ public: //call-ins void newStack(CStack stack); //new stack appeared on battlefield void stackRemoved(CStack stack); //stack disappeared from batlefiled - void stackKilled(int ID); //stack has been killed (but corpses remain) + void stackKilled(int ID, int dmg, int killed, int IDby); //stack has been killed (but corpses remain) void stackActivated(int number); //active stack has been changed void stackMoved(int number, int destHex, bool startMoving, bool endMoving); //stack with id number moved to destHex - void stackIsAttacked(int ID); //called when stack id attacked + void stackIsAttacked(int ID, int dmg, int killed, int IDby); //called when stack id attacked by stack with id IDby void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest void newRound(int number); //caled when round is ended; number is the number of round void hexLclicked(int whichOne); //hex only call-in diff --git a/CCallback.cpp b/CCallback.cpp index b7750ac06..bb4cc43ac 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -765,7 +765,13 @@ int CCallback::battleGetStack(int pos) { for(int g=0; gstate->curB->stacks.size(); ++g) { - if(CGI->state->curB->stacks[g]->position == pos) + if(CGI->state->curB->stacks[g]->position == pos || + ( CGI->state->curB->stacks[g]->creature->isDoubleWide() && + ( (CGI->state->curB->stacks[g]->attackerOwned && CGI->state->curB->stacks[g]->position-1 == pos) || + (!CGI->state->curB->stacks[g]->attackerOwned && CGI->state->curB->stacks[g]->position+1 == pos) + ) + ) + ) return CGI->state->curB->stacks[g]->ID; } return -1; @@ -781,6 +787,11 @@ CStack CCallback::battleGetStackByID(int ID) return CStack(); } +CStack CCallback::battleGetStackByPos(int pos) +{ + return battleGetStackByID(battleGetStack(pos)); +} + int CCallback::battleGetPos(int stack) { for(int g=0; gstate->curB->stacks.size(); ++g) diff --git a/CCallback.h b/CCallback.h index 23ebf3d9b..07a8c6a69 100644 --- a/CCallback.h +++ b/CCallback.h @@ -60,6 +60,7 @@ public: virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile virtual CStack battleGetStackByID(int ID)=0; //returns stack info by given ID + virtual CStack battleGetStackByPos(int pos)=0; //returns stack info by given pos virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack //virtual int battleMakeAction(BattleAction* action)=0;//perform action with an active stack (or custom action) virtual std::map battleGetStacks()=0; //returns stacks on battlefield @@ -131,6 +132,7 @@ public: int battleGetObstaclesAtTile(int tile); //returns bitfield int battleGetStack(int pos); //returns ID of stack on the tile CStack battleGetStackByID(int ID); //returns stack info by given ID + CStack battleGetStackByPos(int pos); //returns stack info by given pos int battleGetPos(int stack); //returns position (tile ID) of stack //int battleMakeAction(BattleAction* action);//perform action with an active stack (or custom action) std::map battleGetStacks(); //returns stacks on battlefield diff --git a/CGameInterface.h b/CGameInterface.h index 52f44802e..c074caf50 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -72,8 +72,8 @@ public: virtual void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector capturedArtifacts, int expForWinner, bool winner){}; virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving)=0; virtual void battleStackAttacking(int ID, int dest)=0; - virtual void battleStackIsAttacked(int ID)=0; - virtual void battleStackKilled(int ID)=0; + virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby)=0; + virtual void battleStackKilled(int ID, int dmg, int killed, int IDby)=0; // }; @@ -91,8 +91,8 @@ public: virtual void heroCreated(const CGHeroInstance*){}; virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving){}; virtual void battleStackAttacking(int ID, int dest){}; - virtual void battleStackIsAttacked(int ID){}; - virtual void battleStackKilled(int ID){}; + virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby){}; + virtual void battleStackKilled(int ID, int dmg, int killed, int IDby){}; virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;}; }; #endif //CGAMEINTERFACE_H \ No newline at end of file diff --git a/CGameState.cpp b/CGameState.cpp index cef417b11..ca573cb26 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -474,12 +474,17 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) curB->stacks[numberOfStackAtEnd]->firstHPleft -= damageFirst; } + int cresInstackBefore = curB->stacks[numberOfStackAtEnd]->amount; curB->stacks[numberOfStackAtEnd]->amount -= cresKilled; if(curB->stacks[numberOfStackAtEnd]->amount<=0) //stack killed { curB->stacks[numberOfStackAtEnd]->amount = 0; + LOCPLINT->battleStackKilled(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore) , ID); curB->stacks[numberOfStackAtEnd]->alive = false; - LOCPLINT->battleStackKilled(curB->stacks[numberOfStackAtEnd]->ID); + } + else + { + LOCPLINT->battleStackIsAttacked(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID); } //damage applied diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 609909e92..8fa9afbc5 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2080,14 +2080,14 @@ void CPlayerInterface::battleStackAttacking(int ID, int dest) dynamic_cast(curint)->stackAttacking(ID, dest); } -void CPlayerInterface::battleStackIsAttacked(int ID) +void CPlayerInterface::battleStackIsAttacked(int ID, int dmg, int killed, int IDby) { - dynamic_cast(curint)->stackIsAttacked(ID); + dynamic_cast(curint)->stackIsAttacked(ID, dmg, killed, IDby); } -void CPlayerInterface::battleStackKilled(int ID) +void CPlayerInterface::battleStackKilled(int ID, int dmg, int killed, int IDby) { - dynamic_cast(curint)->stackKilled(ID); + dynamic_cast(curint)->stackKilled(ID, dmg, killed, IDby); } void CPlayerInterface::showComp(SComponent comp) diff --git a/CPlayerInterface.h b/CPlayerInterface.h index 19ecd3411..e02722f5e 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -341,8 +341,8 @@ public: void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector capturedArtifacts, int expForWinner, bool winner); void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving); void battleStackAttacking(int ID, int dest); - void battleStackIsAttacked(int ID); - void battleStackKilled(int ID); + void battleStackIsAttacked(int ID, int dmg, int killed, int IDby); + void battleStackKilled(int ID, int dmg, int killed, int IDby); //-------------// diff --git a/CPreGame.cpp b/CPreGame.cpp index fdcb629018b3ebea073ff674d9f2d502871ce018..074b7157d49bae9724aa12a118db1313948a2afb 100644 GIT binary patch delta 16 YcmezHn*Gab_J%EtAHK5iGH@{f08H`*{r~^~ delta 11 TcmezJn*GCT_J%EtAHD(rDl-P- From 4347996353a9319854ab1f9614fd9495f414f86f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 12 Jun 2008 06:45:51 +0000 Subject: [PATCH 07/47] Cleanups + started splitting --- AdventureMapButton.cpp | 6 +- CAdvmapInterface.cpp | 40 +-- CBattleInterface.cpp | 18 +- CCallback.cpp | 8 +- CCastleInterface.cpp | 32 +- CCursorHandler.cpp | 8 +- CGameInfo.h | 2 - CGameState.h | 2 - CHeroWindow.cpp | 12 +- CMT.cpp | 311 +------------------ CMessage.cpp | 8 +- CPlayerInterface.cpp | 154 ++++++---- CPlayerInterface.h | 49 +-- CPreGame.cpp | Bin 128500 -> 128430 bytes client/CBitmapHandler.cpp | 332 ++++++++++++++++++++ client/CBitmapHandler.h | 39 +++ client/CCreatureAnimation.cpp | 23 +- global.h | 14 +- hch/CAbilityHandler.cpp | 6 +- hch/CArtHandler.cpp | 2 - hch/CArtHandler.h | 1 - hch/CCreatureHandler.cpp | 37 +-- hch/CCreatureHandler.h | 16 +- hch/CDefHandler.cpp | Bin 27400 -> 27552 bytes hch/CDefHandler.h | Bin 3384 -> 3300 bytes hch/CHeroHandler.cpp | 300 +++++++++++++++++- hch/CHeroHandler.h | 1 + hch/CLodHandler.cpp | 551 ++-------------------------------- hch/CLodHandler.h | 51 +--- hch/CTownHandler.cpp | 4 +- mapHandler.cpp | 86 +++--- 31 files changed, 973 insertions(+), 1140 deletions(-) create mode 100644 client/CBitmapHandler.cpp create mode 100644 client/CBitmapHandler.h diff --git a/AdventureMapButton.cpp b/AdventureMapButton.cpp index 576a41484..d101ee468 100644 --- a/AdventureMapButton.cpp +++ b/AdventureMapButton.cpp @@ -31,7 +31,7 @@ AdventureMapButton::AdventureMapButton helpBox=HelpBox; colorChange = playerColoredButton; int est = LOCPLINT->playerID; - CDefHandler * temp = CGI->spriteh->giveDef(defName); + CDefHandler * temp = CDefHandler::giveDef(defName); temp->notFreeImgs = true; for (int i=0;iourImages.size();i++) { @@ -46,7 +46,7 @@ AdventureMapButton::AdventureMapButton imgs.resize(imgs.size()+add->size()); for (int i=0; isize();i++) { - temp = CGI->spriteh->giveDef((*add)[i]); + temp = CDefHandler::giveDef((*add)[i]); temp->notFreeImgs = true; for (int j=0;jourImages.size();j++) { @@ -245,7 +245,7 @@ CSlider::CSlider(int x, int y, int totalw, boost::function Moved, int { moving = false; strongInterest = true; - imgs = CGI->spriteh->giveDefEss("IGPCRDIV.DEF"); + imgs = CDefHandler::giveDefEss("IGPCRDIV.DEF"); left.pos.y = slider.pos.y = right.pos.y = pos.y = y; left.pos.x = pos.x = x; diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 177d9dd41..f5672a391 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "CAdvmapInterface.h" -#include "hch\CLodHandler.h" +#include "client/CBitmapHandler.h" #include "CPlayerInterface.h" #include "hch\CPreGameTextHandler.h" #include "hch\CGeneralTextHandler.h" @@ -62,7 +62,7 @@ CMinimap::CMinimap(bool draw) } SDL_SetColorKey(radar,SDL_SRCCOLORKEY,SDL_MapRGB(radar->format,0,255,255)); - //radar = CGI->spriteh->giveDef("RADAR.DEF"); + //radar = CDefHandler::giveDef("RADAR.DEF"); std::ifstream is("config/minimap.txt",std::ifstream::in); for (int i=0;ispriteh->giveDef("ADAG.DEF"); + arrows = CDefHandler::giveDef("ADAG.DEF"); for(int y=0; yourImages.size(); ++y) { arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap); @@ -592,7 +592,7 @@ void CResDataBar::deactivate() } CResDataBar::CResDataBar() { - bg = CGI->bitmaph->loadBitmap("ZRESBAR.bmp"); + bg = BitmapHandler::loadBitmap("ZRESBAR.bmp"); SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); //std::vector kolory; //SDL_Color p1={40,65,139,255}, p2={36,59,125,255}, p3={35,56,121,255}; @@ -637,11 +637,11 @@ CInfoBar::CInfoBar() pos.y=389; pos.w=194; pos.h=186; - day = CGI->spriteh->giveDef("NEWDAY.DEF"); - week1 = CGI->spriteh->giveDef("NEWWEEK1.DEF"); - week2 = CGI->spriteh->giveDef("NEWWEEK2.DEF"); - week3 = CGI->spriteh->giveDef("NEWWEEK3.DEF"); - week4 = CGI->spriteh->giveDef("NEWWEEK4.DEF"); + day = CDefHandler::giveDef("NEWDAY.DEF"); + week1 = CDefHandler::giveDef("NEWWEEK1.DEF"); + week2 = CDefHandler::giveDef("NEWWEEK2.DEF"); + week3 = CDefHandler::giveDef("NEWWEEK3.DEF"); + week4 = CDefHandler::giveDef("NEWWEEK4.DEF"); } CInfoBar::~CInfoBar() { @@ -679,14 +679,14 @@ void CInfoBar::draw(const CGObjectInstance * specific) if(specific->ID == 34) //hero { - if(LOCPLINT->heroWins.find(specific->subID)!=LOCPLINT->heroWins.end()) - blitAt(LOCPLINT->heroWins[specific->subID],pos.x,pos.y); + if(LOCPLINT->graphics.heroWins.find(specific->subID)!=LOCPLINT->graphics.heroWins.end()) + blitAt(LOCPLINT->graphics.heroWins[specific->subID],pos.x,pos.y); } else if (specific->ID == 98) { const CGTownInstance * t = static_cast(specific); - if(LOCPLINT->townWins.find(t->identifier)!=LOCPLINT->townWins.end()) - blitAt(LOCPLINT->townWins[t->identifier],pos.x,pos.y); + if(LOCPLINT->graphics.townWins.find(t->identifier)!=LOCPLINT->graphics.townWins.end()) + blitAt(LOCPLINT->graphics.townWins[t->identifier],pos.x,pos.y); } //SDL_Surface * todr = LOCPLINT->infoWin(specific); @@ -774,7 +774,7 @@ void CInfoBar::newDay(int Day) void CInfoBar::showComp(SComponent * comp, int time) { - SDL_Surface * b = CGI->bitmaph->loadBitmap("ADSTATOT.bmp"); + SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp"); blitAt(b,pos.x+8,pos.y+11); blitAt(comp->getImg(),pos.x+52,pos.y+54); printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly); @@ -848,7 +848,7 @@ townList(5,&genRect(192,48,747,196),747,196,747,372) { townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this); LOCPLINT->adventureInt=this; - bg = CGI->bitmaph->loadBitmap("ADVMAP.bmp"); + bg = BitmapHandler::loadBitmap("ADVMAP.bmp"); blueToPlayersAdv(bg,player); scrollingLeft = false; scrollingRight = false; @@ -867,10 +867,10 @@ townList(5,&genRect(192,48,747,196),747,196,747,372) heroWindow = new CHeroWindow(this->player); - gems.push_back(CGI->spriteh->giveDef("agemLL.def")); - gems.push_back(CGI->spriteh->giveDef("agemLR.def")); - gems.push_back(CGI->spriteh->giveDef("agemUL.def")); - gems.push_back(CGI->spriteh->giveDef("agemUR.def")); + gems.push_back(CDefHandler::giveDef("agemLL.def")); + gems.push_back(CDefHandler::giveDef("agemLR.def")); + gems.push_back(CDefHandler::giveDef("agemUL.def")); + gems.push_back(CDefHandler::giveDef("agemUR.def")); } void CAdvMapInt::fshowOverview() @@ -878,7 +878,7 @@ void CAdvMapInt::fshowOverview() } void CAdvMapInt::fswitchLevel() { - if(!CGI->ac->map.twoLevel) + if(!CGI->mh->map->twoLevel) return; if (position.z) { diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 6c30061ce..b615e4ead 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -35,13 +35,13 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C } //preparing menu background and terrain std::vector< std::string > & backref = CGI->mh->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; - background = CGI->bitmaph->loadBitmap(backref[ rand() % backref.size()] ); - menu = CGI->bitmaph->loadBitmap("CBAR.BMP"); + background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] ); + menu = BitmapHandler::loadBitmap("CBAR.BMP"); CSDL_Ext::blueToPlayersAdv(menu, hero1->tempOwner); //preparing graphics for displaying amounts of creatures - amountBasic = CGI->bitmaph->loadBitmap("CMNUMWIN.BMP"); - amountNormal = CGI->bitmaph->loadBitmap("CMNUMWIN.BMP"); + amountBasic = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); + amountNormal = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); CSDL_Ext::alphaTransform(amountNormal); for(int g=0; gformat->palette->ncolors; ++g) { @@ -98,9 +98,9 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C } //preparing cells and hexes - cellBorder = CGI->bitmaph->loadBitmap("CCELLGRD.BMP"); + cellBorder = BitmapHandler::loadBitmap("CCELLGRD.BMP"); CSDL_Ext::alphaTransform(cellBorder); - cellShade = CGI->bitmaph->loadBitmap("CCELLSHD.BMP"); + cellShade = BitmapHandler::loadBitmap("CCELLSHD.BMP"); CSDL_Ext::alphaTransform(cellShade); for(int h=0; h<187; ++h) { @@ -896,7 +896,7 @@ void CBattleHero::show(SDL_Surface *to) CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG, unsigned char player): phase(phaseG), image(imageG), flip(flipG), flagAnim(0) { - dh = CGI->spriteh->giveDef( defName ); + dh = CDefHandler::giveDef( defName ); for(int i=0; iourImages.size(); ++i) //transforming images { if(flip) @@ -910,9 +910,9 @@ CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG dh->alphaTransformed = true; if(flip) - flag = CGI->spriteh->giveDef("CMFLAGR.DEF"); + flag = CDefHandler::giveDef("CMFLAGR.DEF"); else - flag = CGI->spriteh->giveDef("CMFLAGL.DEF"); + flag = CDefHandler::giveDef("CMFLAGL.DEF"); //coloring flag and adding transparency for(int i=0; iourImages.size(); ++i) diff --git a/CCallback.cpp b/CCallback.cpp index bb4cc43ac..7f5f0b248 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -163,14 +163,14 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) if(xbeg < 0) xbeg = 0; int xend = stpos.x + heroSight + 2; - if(xend >= CGI->ac->map.width) - xend = CGI->ac->map.width; + if(xend >= CGI->mh->map->width) + xend = CGI->mh->map->width; int ybeg = stpos.y - heroSight - 2; if(ybeg < 0) ybeg = 0; int yend = stpos.y + heroSight + 2; - if(yend >= CGI->ac->map.height) - yend = CGI->ac->map.height; + if(yend >= CGI->mh->map->height) + yend = CGI->mh->map->height; for(int xd=xbeg; xdspriteh->giveDef(Str->defName); + def = CDefHandler::giveDef(Str->defName); max = def->ourImages.size(); if(str->ID == 33 && str->townID == 4) //little 'hack' for estate in necropolis - background color is not always the first color in the palette @@ -36,11 +36,11 @@ CBuildingRect::CBuildingRect(Structure *Str) area = border = NULL; return; } - if (border = CGI->bitmaph->loadBitmap(str->borderName)) + if (border = BitmapHandler::loadBitmap(str->borderName)) SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255)); else std::cout << "Warning: no border for "<ID<bitmaph->loadBitmap(str->areaName)) + if (area = BitmapHandler::loadBitmap(str->areaName)) ;//SDL_SetColorKey(area,SDL_SRCCOLORKEY,SDL_MapRGB(area->format,0,255,255)); else std::cout << "Warning: no area for "<ID<bitmaph->loadBitmap("TOWNSCRN.bmp"); - cityBg = CGI->bitmaph->loadBitmap(getBgName(Town->subID)); - hall = CGI->spriteh->giveDef("ITMTL.DEF"); - fort = CGI->spriteh->giveDef("ITMCL.DEF"); - flag = CGI->spriteh->giveDef("CREST58.DEF"); + townInt = BitmapHandler::loadBitmap("TOWNSCRN.bmp"); + cityBg = BitmapHandler::loadBitmap(getBgName(Town->subID)); + hall = CDefHandler::giveDef("ITMTL.DEF"); + fort = CDefHandler::giveDef("ITMCL.DEF"); + flag = CDefHandler::giveDef("CREST58.DEF"); hBuild = NULL; count=0; town = Town; @@ -283,7 +283,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) default: throw new std::exception("Bad town subID"); } - bicons = CGI->spriteh->giveDefEss(defname); + bicons = CDefHandler::giveDefEss(defname); //blit buildings on bg //for(int i=0;i3)?(i-4):i)); pomy = (i>3)?(507):(459); - blitAt(CGI->creh->smallImgs[cid],pomx,pomy,to); + blitAt(LOCPLINT->graphics.smallImgs[cid],pomx,pomy,to); std::ostringstream oss; oss << '+' << town->creatureGrowth(i); CSDL_Ext::printAtMiddle(oss.str(),pomx+16,pomy+37,GEOR13,zwykly,to); @@ -433,7 +433,7 @@ void CCastleInterface::showAll(SDL_Surface * to) pom += F_NUMBER*2; if(town->builded >= MAX_BUILDING_PER_TURN) pom++; - blitAt(LOCPLINT->bigTownPic->ourImages[pom].bitmap,15,387,to); + blitAt(LOCPLINT->graphics.bigTownPic->ourImages[pom].bitmap,15,387,to); //flag if(town->getOwner()bitmaph->loadBitmap("Z2ESBAR.bmp"); + bg = BitmapHandler::loadBitmap("Z2ESBAR.bmp"); SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); CSDL_Ext::blueToPlayersAdv(bg,LOCPLINT->playerID); pos.x = 7; @@ -768,10 +768,10 @@ CHallInterface::CBuildingBox::CBuildingBox(int id, int x, int y) CHallInterface::CHallInterface(CCastleInterface * owner) { - bg = CGI->bitmaph->loadBitmap(CGI->buildh->hall[owner->town->subID].first); + bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first); CSDL_Ext::blueToPlayersAdv(bg,LOCPLINT->playerID); - bars = CGI->spriteh->giveDefEss("TPTHBAR.DEF"); - status = CGI->spriteh->giveDefEss("TPTHCHK.DEF"); + bars = CDefHandler::giveDefEss("TPTHBAR.DEF"); + status = CDefHandler::giveDefEss("TPTHCHK.DEF"); exit = new AdventureMapButton (CGI->townh->tcommands[8],"",boost::bind(&CHallInterface::close,this),748,556,"TPMAGE1.DEF",false,NULL,false); @@ -1007,7 +1007,7 @@ std::string CHallInterface::CBuildWindow::getTextForState(int state) CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mode) :tid(Tid),bid(Bid),mode(Mode), state(State) { - SDL_Surface *hhlp = CGI->bitmaph->loadBitmap("TPUBUILD.bmp"); + SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPUBUILD.bmp"); bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo SDL_SetColorKey(hhlp,SDL_SRCCOLORKEY,SDL_MapRGB(hhlp->format,0,255,255)); SDL_FreeSurface(hhlp); diff --git a/CCursorHandler.cpp b/CCursorHandler.cpp index b057b7f69..a46a2a4c4 100644 --- a/CCursorHandler.cpp +++ b/CCursorHandler.cpp @@ -195,10 +195,10 @@ void CCursorHandler::initCursor() // xpos = ypos = 0; // behindCur = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, rmask, gmask, bmask, amask); // xbef = ybef = 0; -// adventure = CGI->spriteh->giveDef("CRADVNTR.DEF"); -// combat = CGI->spriteh->giveDef("CRCOMBAT.DEF"); -// deflt = CGI->spriteh->giveDef("CRDEFLT.DEF"); -// spell = CGI->spriteh->giveDef("CRSPELL.DEF"); +// adventure = CDefHandler::giveDef("CRADVNTR.DEF"); +// combat = CDefHandler::giveDef("CRCOMBAT.DEF"); +// deflt = CDefHandler::giveDef("CRDEFLT.DEF"); +// spell = CDefHandler::giveDef("CRSPELL.DEF"); // //SDL_SetCursor(init_system_cursor(arrow)); // //SDL_Thread * myth = SDL_CreateThread(&cursorHandlerFunc, this); } diff --git a/CGameInfo.h b/CGameInfo.h index ea40b2c7d..e278d7587 100644 --- a/CGameInfo.h +++ b/CGameInfo.h @@ -47,7 +47,6 @@ public: CAbilityHandler * abilh; CSpellHandler * spellh; CMapHandler * mh; - CAmbarCendamo * ac; CPreGameTextHandler * preth; CBuildingHandler * buildh; CObjectHandler * objh; @@ -65,7 +64,6 @@ public: int localPlayer; std::vector playerint; std::vector playerColors; - std::vector playerColorInfo; //gems from adventure map interface SDL_Color neutralColor; StartInfo scenarioOps; }; diff --git a/CGameState.h b/CGameState.h index 4ac7cb62a..c5a7100a2 100644 --- a/CGameState.h +++ b/CGameState.h @@ -101,8 +101,6 @@ public: friend void initGameState(Mapa * map, CGameInfo * cgi); friend CScriptCallback; friend void handleCPPObjS(std::map * mapa, CCPPObjectScript * script); - //CCallback * cb; //for communication between PlayerInterface/AI and GameState - friend SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect); //todo: wywalic koniecznie, tylko do flag obecnie!!!! }; diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 84bc77e18..beb0dd81b 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -23,7 +23,7 @@ CHeroWindow::CHeroWindow(int playerColor): backpackPos(0), player(playerColor) { artWorn.resize(19); - background = CGI->bitmaph->loadBitmap("HEROSCR4.bmp"); + background = BitmapHandler::loadBitmap("HEROSCR4.bmp"); CSDL_Ext::blueToPlayersAdv(background, playerColor); pos.x = 65; pos.y = 8; @@ -60,8 +60,8 @@ CHeroWindow::CHeroWindow(int playerColor): heroListMi[g]->id = g; } - skillpics = CGI->spriteh->giveDef("pskil42.def"); - flags = CGI->spriteh->giveDef("CREST58.DEF"); + skillpics = CDefHandler::giveDef("pskil42.def"); + flags = CDefHandler::giveDef("CREST58.DEF"); //areas portraitArea = new LRClickableAreaWText(); portraitArea->pos.x = 83; @@ -788,8 +788,8 @@ void CHeroWindow::redrawCurBack() primarySkill4<primSkills[3]; CSDL_Ext::printAtMiddle(primarySkill4.str(), 263, 165, TNRB16, zwykly, curBack); - blitAt(LOCPLINT->luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack); - blitAt(LOCPLINT->morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack); + blitAt(LOCPLINT->graphics.luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack); + blitAt(LOCPLINT->graphics.morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack); blitAt(flags->ourImages[player].bitmap, 606, 8, curBack); @@ -979,7 +979,7 @@ void CArtPlace::show(SDL_Surface *to) { if(ourArt) { - blitAt(CGI->arth->artDefs->ourImages[ourArt->id].bitmap, pos.x, pos.y, to); + blitAt(LOCPLINT->graphics.artDefs->ourImages[ourArt->id].bitmap, pos.x, pos.y, to); } if(clicked && active) { diff --git a/CMT.cpp b/CMT.cpp index 2daa4657f..7d1b3668a 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -391,9 +391,9 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->curh = new CCursorHandler; THC std::cout<<"Initializing screen, fonts and sound handling: "<spriteh = new CLodHandler; + CDefHandler::Spriteh = cgi->spriteh = new CLodHandler; cgi->spriteh->init(std::string("Data\\H3sprite.lod")); - cgi->bitmaph = new CLodHandler; + BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler; cgi->bitmaph->init(std::string("Data\\H3bitmap.lod")); THC std::cout<<"Loading .lod files: "<generaltexth = new CGeneralTextHandler; cgi->generaltexth->load(); THC std::cout<<"Preparing more handlers: "<heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01L.DEF")); //red - cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01G.DEF")); //blue - cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01R.DEF")); //tan - cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01D.DEF")); //green - cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01B.DEF")); //orange - cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01P.DEF")); //purple - cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01W.DEF")); //teal - cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01K.DEF")); //pink - - for(int q=0; q<8; ++q) - { - for(int o=0; oheroh->flags1[q]->ourImages.size(); ++o) - { - if(cgi->heroh->flags1[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags1[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - cgi->heroh->flags1[q]->ourImages.push_back(nci); - } - o+=8; - } - if(cgi->heroh->flags1[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags1[q]->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - cgi->heroh->flags1[q]->ourImages.push_back(nci); - } - o+=8; - } - if(cgi->heroh->flags1[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags1[q]->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - cgi->heroh->flags1[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffheroh->flags1[q]->ourImages.size(); ++ff) - { - SDL_SetColorKey(cgi->heroh->flags1[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(cgi->heroh->flags1[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - cgi->heroh->flags1[q]->alphaTransformed = true; - } - - cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02L.DEF")); //red - cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02G.DEF")); //blue - cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02R.DEF")); //tan - cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02D.DEF")); //green - cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02B.DEF")); //orange - cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02P.DEF")); //purple - cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02W.DEF")); //teal - cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02K.DEF")); //pink - - for(int q=0; q<8; ++q) - { - for(int o=0; oheroh->flags2[q]->ourImages.size(); ++o) - { - if(cgi->heroh->flags2[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags2[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - cgi->heroh->flags2[q]->ourImages.push_back(nci); - } - o+=8; - } - if(cgi->heroh->flags2[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags2[q]->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - cgi->heroh->flags2[q]->ourImages.push_back(nci); - } - o+=8; - } - if(cgi->heroh->flags2[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags2[q]->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - cgi->heroh->flags2[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffheroh->flags2[q]->ourImages.size(); ++ff) - { - SDL_SetColorKey(cgi->heroh->flags2[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(cgi->heroh->flags2[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - cgi->heroh->flags2[q]->alphaTransformed = true; - } - - cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03L.DEF")); //red - cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03G.DEF")); //blue - cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03R.DEF")); //tan - cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03D.DEF")); //green - cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03B.DEF")); //orange - cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03P.DEF")); //purple - cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03W.DEF")); //teal - cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03K.DEF")); //pink - - for(int q=0; q<8; ++q) - { - for(int o=0; oheroh->flags3[q]->ourImages.size(); ++o) - { - if(cgi->heroh->flags3[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags3[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - cgi->heroh->flags3[q]->ourImages.push_back(nci); - } - o+=8; - } - if(cgi->heroh->flags3[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags3[q]->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - cgi->heroh->flags3[q]->ourImages.push_back(nci); - } - o+=8; - } - if(cgi->heroh->flags3[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags3[q]->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - cgi->heroh->flags3[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffheroh->flags3[q]->ourImages.size(); ++ff) - { - SDL_SetColorKey(cgi->heroh->flags3[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(cgi->heroh->flags3[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - cgi->heroh->flags3[q]->alphaTransformed = true; - } - - cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF00.DEF")); //red - cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF01.DEF")); //blue - cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF02.DEF")); //tan - cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF03.DEF")); //green - cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF04.DEF")); //orange - cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF05.DEF")); //purple - cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF06.DEF")); //teal - cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF07.DEF")); //pink - - - for(int q=0; q<8; ++q) - { - for(int o=0; oheroh->flags4[q]->ourImages.size(); ++o) - { - if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - cgi->heroh->flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 11; - nci.imName = std::string(); - cgi->heroh->flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 12; - nci.imName = std::string(); - cgi->heroh->flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int o=0; oheroh->flags4[q]->ourImages.size(); ++o) - { - if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==1) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 13; - nci.imName = std::string(); - cgi->heroh->flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==2) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 14; - nci.imName = std::string(); - cgi->heroh->flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==3) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 15; - nci.imName = std::string(); - cgi->heroh->flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffheroh->flags4[q]->ourImages.size(); ++ff) - { - SDL_SetColorKey(cgi->heroh->flags4[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(cgi->heroh->flags4[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - cgi->heroh->flags4[q]->alphaTransformed = true; - } - - //hero flags initialized - + cgi->heroh->loadHeroFlags(); THC std::cout<<"Initializing colours and flags: "<arth = arth; THC std::cout<<"\tArtifact handler: "<bitmaph); creh->loadCreatures(); cgi->creh = creh; THC std::cout<<"\tCreature handler: "<ourScenSel->mapsel.selected==0) - // CPG->ourScenSel->mapsel.selected = 1; //only for tests - if (CPG) - mapname = CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].filename; - else - { - std::cout<<"Critical error: CPG==NULL"<ourScenSel->mapsel.ourMaps[cpg->ourScenSel->mapsel.selected].filename; std::cout<<"Opening map file: "< mapstr; int pom; @@ -853,8 +555,7 @@ int _tmain(int argc, _TCHAR* argv[]) } std::cout<<"done."<ac = ac; + CAmbarCendamo * ac = new CAmbarCendamo(initTable); THC std::cout<<"Reading file: "<deh3m(); THC std::cout<<"Detecting file (together): "<spriteh->giveDef("DIALGBOX.DEF"); + CDefHandler * bluePieces = CDefHandler::giveDef("DIALGBOX.DEF"); std::vector n; piecesOfBox.push_back(n); if (i==1) @@ -65,11 +65,11 @@ void CMessage::init() piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap); } } - NMessage::background = CGI->bitmaph->loadBitmap("DIBOXBCK.BMP"); + NMessage::background = BitmapHandler::loadBitmap("DIBOXBCK.BMP"); SDL_SetColorKey(background,SDL_SRCCOLORKEY,SDL_MapRGB(background->format,0,255,255)); } - ok = CGI->spriteh->giveDef("IOKAY.DEF"); - cancel = CGI->spriteh->giveDef("ICANCEL.DEF"); + ok = CDefHandler::giveDef("IOKAY.DEF"); + cancel = CDefHandler::giveDef("ICANCEL.DEF"); } diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 8fa9afbc5..79d05b0ec 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -229,10 +229,10 @@ void CGarrisonSlot::show() { char* buf = new char[15]; itoa(count,buf,10); - blitAt(CGI->creh->bigImgs[creature->idNumber],pos); + blitAt(LOCPLINT->graphics.bigImgs[creature->idNumber],pos); printTo(buf,pos.x+56,pos.y+62,GEOR16,zwykly); if(owner->highlighted==this) - blitAt(CGI->creh->bigImgs[-1],pos); + blitAt(LOCPLINT->graphics.bigImgs[-1],pos); if(owner->update) updateRect(&pos,screen); delete [] buf; @@ -242,7 +242,7 @@ void CGarrisonSlot::show() SDL_Rect jakis1 = genRect(pos.h,pos.w,owner->offx+ID*(pos.w+owner->interx),owner->offy+upg*(pos.h+owner->intery)), jakis2 = pos; SDL_BlitSurface(owner->sur,&jakis1,screen,&jakis2); if(owner->splitting) - blitAt(CGI->creh->bigImgs[-1],pos); + blitAt(LOCPLINT->graphics.bigImgs[-1],pos); if(owner->update) SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h); } @@ -887,15 +887,12 @@ void TimeInterested::deactivate() LOCPLINT-> timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this)); } -CPlayerInterface::CPlayerInterface(int Player, int serial) +CPlayerInterface::Graphics::Graphics() { - playerID=Player; - serialID=serial; - CGI->localPlayer = playerID; - human=true; - hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp"); + artDefs = CDefHandler::giveDef("ARTIFACT.DEF"); + hInfo = BitmapHandler::loadBitmap("HEROQVBK.bmp"); SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255)); - tInfo = CGI->bitmaph->loadBitmap("TOWNQVBK.bmp"); + tInfo = BitmapHandler::loadBitmap("TOWNQVBK.bmp"); SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->format,0,255,255)); slotsPos.push_back(std::pair(44,82)); slotsPos.push_back(std::pair(80,82)); @@ -905,18 +902,51 @@ CPlayerInterface::CPlayerInterface(int Player, int serial) slotsPos.push_back(std::pair(98,131)); slotsPos.push_back(std::pair(134,131)); - luck22 = CGI->spriteh->giveDefEss("ILCK22.DEF"); - luck30 = CGI->spriteh->giveDefEss("ILCK30.DEF"); - luck42 = CGI->spriteh->giveDefEss("ILCK42.DEF"); - luck82 = CGI->spriteh->giveDefEss("ILCK82.DEF"); - morale22 = CGI->spriteh->giveDefEss("IMRL22.DEF"); - morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF"); - morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF"); - morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF"); - halls = CGI->spriteh->giveDefEss("ITMTLS.DEF"); - forts = CGI->spriteh->giveDefEss("ITMCLS.DEF"); - bigTownPic = CGI->spriteh->giveDefEss("ITPT.DEF"); + luck22 = CDefHandler::giveDefEss("ILCK22.DEF"); + luck30 = CDefHandler::giveDefEss("ILCK30.DEF"); + luck42 = CDefHandler::giveDefEss("ILCK42.DEF"); + luck82 = CDefHandler::giveDefEss("ILCK82.DEF"); + morale22 = CDefHandler::giveDefEss("IMRL22.DEF"); + morale30 = CDefHandler::giveDefEss("IMRL30.DEF"); + morale42 = CDefHandler::giveDefEss("IMRL42.DEF"); + morale82 = CDefHandler::giveDefEss("IMRL82.DEF"); + halls = CDefHandler::giveDefEss("ITMTLS.DEF"); + forts = CDefHandler::giveDefEss("ITMCLS.DEF"); + bigTownPic = CDefHandler::giveDefEss("ITPT.DEF"); + std::ifstream ifs; + ifs.open("config/cr_bgs.txt"); + while(!ifs.eof()) + { + int id; + std::string name; + ifs >> id >> name; + backgrounds[id]=BitmapHandler::loadBitmap(name); + } + ifs.close(); + ifs.clear(); + //loading 32x32px imgs + CDefHandler *smi = CDefHandler::giveDef("CPRSMALL.DEF"); + smi->notFreeImgs = true; + for (int i=0; iourImages.size(); i++) + { + smallImgs[i-2] = smi->ourImages[i].bitmap; + } + delete smi; + smi = CDefHandler::giveDef("TWCRPORT.DEF"); + smi->notFreeImgs = true; + for (int i=0; iourImages.size(); i++) + { + bigImgs[i-2] = smi->ourImages[i].bitmap; + } + delete smi; +} +CPlayerInterface::CPlayerInterface(int Player, int serial) +{ + playerID=Player; + serialID=serial; + CGI->localPlayer = playerID; + human=true; } void CPlayerInterface::init(ICallback * CB) { @@ -928,13 +958,13 @@ void CPlayerInterface::init(ICallback * CB) for(int i=0;i(hh[i]->subID,pom)); + graphics.heroWins.insert(std::pair(hh[i]->subID,pom)); } std::vector tt = cb->getTownsInfo(false); for(int i=0;i(tt[i]->identifier,pom)); + graphics.townWins.insert(std::pair(tt[i]->identifier,pom)); } } void CPlayerInterface::yourTurn() @@ -1022,7 +1052,7 @@ void CPlayerInterface::yourTurn() } if(LOCPLINT->adventureInt->scrollingRight) { - if(LOCPLINT->adventureInt->position.xac->map.width-19+4) + if(LOCPLINT->adventureInt->position.xmh->map->width-19+4) { LOCPLINT->adventureInt->position.x++; LOCPLINT->adventureInt->updateScreen = true; @@ -1040,7 +1070,7 @@ void CPlayerInterface::yourTurn() } if(LOCPLINT->adventureInt->scrollingDown) { - if(LOCPLINT->adventureInt->position.yac->map.height-18+4) + if(LOCPLINT->adventureInt->position.ymh->map->height-18+4) { LOCPLINT->adventureInt->position.y++; LOCPLINT->adventureInt->updateScreen = true; @@ -1554,15 +1584,15 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } void CPlayerInterface::heroKilled(const CGHeroInstance* hero) { - heroWins.erase(hero->ID); + graphics.heroWins.erase(hero->ID); } void CPlayerInterface::heroCreated(const CGHeroInstance * hero) { - if(heroWins.find(hero->subID)==heroWins.end()) - heroWins.insert(std::pair(hero->subID,infoWin(hero))); + if(graphics.heroWins.find(hero->subID)==graphics.heroWins.end()) + graphics.heroWins.insert(std::pair(hero->subID,infoWin(hero))); } -SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to) +SDL_Surface * CPlayerInterface::Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to) { char * buf = new char[10]; for (int i=from;itempOwner,1); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); printAt(curh->name,75,15,GEOR13,zwykly,ret); drawPrimarySkill(curh, ret); for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) { - blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); + blitAt(LOCPLINT->graphics.smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); itoa((*i).second.second,buf,10); printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret); } @@ -1597,10 +1627,10 @@ SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh) return ret; } -SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh) +SDL_Surface * CPlayerInterface::Graphics::drawTownInfoWin(const CGTownInstance * curh) { char * buf = new char[10]; - blueToPlayersAdv(tInfo,playerID,1); + blueToPlayersAdv(tInfo,curh->tempOwner,1); SDL_Surface * ret = SDL_DisplayFormat(tInfo); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); printAt(curh->name,75,15,GEOR13,zwykly,ret); @@ -1615,7 +1645,7 @@ SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh) { if(!i->second.first) continue; - blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); + blitAt(LOCPLINT->graphics.smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); itoa((*i).second.second,buf,10); printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret); } @@ -1647,10 +1677,10 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe switch (specific->ID) { case 34: - return drawHeroInfoWin(dynamic_cast(specific)); + return graphics.drawHeroInfoWin(dynamic_cast(specific)); break; case 98: - return drawTownInfoWin(dynamic_cast(specific)); + return graphics.drawTownInfoWin(dynamic_cast(specific)); break; default: return NULL; @@ -1664,11 +1694,11 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe case HEROI_TYPE: { const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected; - return drawHeroInfoWin(curh); + return graphics.drawHeroInfoWin(curh); } case TOWNI_TYPE: { - return drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected); + return graphics.drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected); } default: return NULL; @@ -1905,8 +1935,8 @@ int3 CPlayerInterface::repairScreenPos(int3 pos) } void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) { - SDL_FreeSurface(heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia - heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki. + SDL_FreeSurface(graphics.heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia + graphics.heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki. if (adventureInt->selection.selected == hero) adventureInt->infoBar.draw(); return; @@ -1947,8 +1977,8 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj) const CGHeroInstance * hh; if(hh = dynamic_cast(obj)) { - SDL_FreeSurface(heroWins[hh->subID]); - heroWins[hh->subID] = infoWin(hh); + SDL_FreeSurface(graphics.heroWins[hh->subID]); + graphics.heroWins[hh->subID] = infoWin(hh); } CHeroWindow * hw = dynamic_cast(curint); if(hw) @@ -1968,8 +1998,8 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj) const CGTownInstance * tt; if(tt = dynamic_cast(obj)) { - SDL_FreeSurface(townWins[tt->identifier]); - townWins[tt->identifier] = infoWin(tt); + SDL_FreeSurface(graphics.townWins[tt->identifier]); + graphics.townWins[tt->identifier] = infoWin(tt); } const CCastleInterface *ci = dynamic_cast(curint); @@ -2135,7 +2165,7 @@ void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero) } CStatusBar::CStatusBar(int x, int y, std::string name, int maxw) { - bg=CGI->bitmaph->loadBitmap(name); + bg=BitmapHandler::loadBitmap(name); SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); pos.x=x; pos.y=y; @@ -2212,12 +2242,12 @@ CHeroList::CHeroList(int Size) posmanx = 666; posmany = 213; - arrup = CGI->spriteh->giveDef("IAM012.DEF"); - arrdo = CGI->spriteh->giveDef("IAM013.DEF"); - mobile = CGI->spriteh->giveDef("IMOBIL.DEF"); - mana = CGI->spriteh->giveDef("IMANA.DEF"); - empty = CGI->bitmaph->loadBitmap("HPSXXX.bmp"); - selection = CGI->bitmaph->loadBitmap("HPSYYY.bmp"); + arrup = CDefHandler::giveDef("IAM012.DEF"); + arrdo = CDefHandler::giveDef("IAM013.DEF"); + mobile = CDefHandler::giveDef("IMOBIL.DEF"); + mana = CDefHandler::giveDef("IMANA.DEF"); + empty = BitmapHandler::loadBitmap("HPSXXX.bmp"); + selection = BitmapHandler::loadBitmap("HPSYYY.bmp"); SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255)); from = 0; pressed = indeterminate; @@ -2376,7 +2406,7 @@ void CHeroList::clickRight(tribool down) } //show popup - CInfoPopup * ip = new CInfoPopup(LOCPLINT->heroWins[items[from+ny].first->subID],LOCPLINT->current->motion.x-LOCPLINT->heroWins[items[from+ny].first->subID]->w,LOCPLINT->current->motion.y-LOCPLINT->heroWins[items[from+ny].first->subID]->h,false); + CInfoPopup * ip = new CInfoPopup(LOCPLINT->graphics.heroWins[items[from+ny].first->subID],LOCPLINT->current->motion.x-LOCPLINT->graphics.heroWins[items[from+ny].first->subID]->w,LOCPLINT->current->motion.y-LOCPLINT->graphics.heroWins[items[from+ny].first->subID]->h,false); ip->activate(); } else @@ -2460,8 +2490,8 @@ CTownList::CTownList(int Size, SDL_Rect * Pos, int arupx, int arupy, int ardox, :CList(Size) { pos = *Pos; - arrup = CGI->spriteh->giveDef("IAM014.DEF"); - arrdo = CGI->spriteh->giveDef("IAM015.DEF"); + arrup = CDefHandler::giveDef("IAM014.DEF"); + arrdo = CDefHandler::giveDef("IAM015.DEF"); arrupp.x=arupx; arrupp.y=arupy; @@ -2616,7 +2646,7 @@ void CTownList::clickRight(tribool down) } //show popup - CInfoPopup * ip = new CInfoPopup(LOCPLINT->townWins[items[from+ny]->identifier],LOCPLINT->current->motion.x-LOCPLINT->townWins[items[from+ny]->identifier]->w,LOCPLINT->current->motion.y-LOCPLINT->townWins[items[from+ny]->identifier]->h,false); + CInfoPopup * ip = new CInfoPopup(LOCPLINT->graphics.townWins[items[from+ny]->identifier],LOCPLINT->current->motion.x-LOCPLINT->graphics.townWins[items[from+ny]->identifier]->w,LOCPLINT->current->motion.y-LOCPLINT->graphics.townWins[items[from+ny]->identifier]->h,false); ip->activate(); } else @@ -2675,7 +2705,7 @@ CCreaturePic::~CCreaturePic() } int CCreaturePic::blitPic(SDL_Surface *to, int x, int y, bool nextFrame) { - blitAt(CGI->creh->backgrounds[c->faction],x,y);//curx-50,pos.y+130-65); + blitAt(LOCPLINT->graphics.backgrounds[c->faction],x,y);//curx-50,pos.y+130-65); SDL_Rect dst = genRect(130,100,x,y); if(c->isDoubleWide()) x-=15; @@ -2807,7 +2837,7 @@ CRecrutationWindow::CRecrutationWindow(const std::vector > &C creatures[i].pic = new CCreaturePic(&CGI->creh->creatures[Creatures[i].first]); amounts[i] = CGI->creh->creatures[Creatures[i].first].maxAmount(LOCPLINT->cb->getResourceAmount()); } - SDL_Surface *hhlp = CGI->bitmaph->loadBitmap("TPRCRT.bmp"); + SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp"); blueToPlayersAdv(hhlp,LOCPLINT->playerID); bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); @@ -2870,7 +2900,7 @@ CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner) c=cid; slider = NULL; gar = Owner; - bitmap = CGI->bitmaph->loadBitmap("GPUCRDIV.bmp"); + bitmap = BitmapHandler::loadBitmap("GPUCRDIV.bmp"); SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); pos.x = screen->w/2 - bitmap->w/2; pos.y = screen->h/2 - bitmap->h/2; @@ -2970,7 +3000,7 @@ CCreInfoWindow::CCreInfoWindow :ok(0),dismiss(0),upgrade(0),type(Type),dsm(Dsm) { c = &CGI->creh->creatures[Cid]; - bitmap = CGI->bitmaph->loadBitmap("CRSTKPU.bmp"); + bitmap = BitmapHandler::loadBitmap("CRSTKPU.bmp"); pos.x = screen->w/2 - bitmap->w/2; pos.y = screen->h/2 - bitmap->h/2; pos.w = bitmap->w; @@ -3039,8 +3069,8 @@ CCreInfoWindow::CCreInfoWindow //luck and morale - blitAt(LOCPLINT->morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap); - blitAt(LOCPLINT->luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap); + blitAt(LOCPLINT->graphics.morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap); + blitAt(LOCPLINT->graphics.luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap); //print abilities text - if r-click popup if(type) diff --git a/CPlayerInterface.h b/CPlayerInterface.h index e02722f5e..5d6998a51 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -290,17 +290,19 @@ public: class CPlayerInterface : public CGameInterface { public: + //minor interfaces bool makingTurn; - SDL_Event * current; + SDL_Event * current; IActivable *curint; CAdvMapInt * adventureInt; CCastleInterface * castleInt; FPSmanager * mainFPSmng; IStatusBar *statusbar; - //TODO: town interace, battle interface, other interfaces + //to commucate with engine CCallback * cb; + //GUI elements std::vector lclickable; std::vector rclickable; std::vector hoverable; @@ -309,15 +311,32 @@ public: std::vector timeinterested; std::vector objsToBlit; - SDL_Surface * hInfo, *tInfo; - std::vector > slotsPos; - CDefEssential *luck22, *luck30, *luck42, *luck82, - *morale22, *morale30, *morale42, *morale82, - *halls, *forts, *bigTownPic; - std::map heroWins; - std::map townWins; + //various graphics + class Graphics + { + public: + //various graphics + SDL_Surface * hInfo, *tInfo; //hero and town infobox bgs + std::vector > slotsPos; //creature slot positions in infoboxes + CDefEssential *luck22, *luck30, *luck42, *luck82, + *morale22, *morale30, *morale42, *morale82, + *halls, *forts, *bigTownPic; + std::map heroWins; //hero_ID => infobox + std::map townWins; //town_ID => infobox + CDefHandler * artDefs; //artifacts + //creatures + std::map smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border + std::map bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border + std::map backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral + + //functions + Graphics(); + SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh); + SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS); + SDL_Surface * drawTownInfoWin(const CGTownInstance * curh); + } graphics; - //overloaded funcs from Interface + //overloaded funcs from CGameInterface void yourTurn(); void heroMoved(const HeroMoveDetails & details); void tileRevealed(int3 pos); @@ -330,8 +349,7 @@ public: void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town); void garrisonChanged(const CGObjectInstance * obj); void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished - - //battles + //for battles void battleStart(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, boost::logic::tribool side); //called by engine when battle starts; side=0 - left, side=1 - right void battlefieldPrepared(int battlefieldType, std::vector obstacles); //called when battlefield is prepared, prior the battle beginning void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn @@ -348,7 +366,6 @@ public: //-------------// void showComp(SComponent comp); - void openTownWindow(const CGTownInstance * town); //shows townscreen void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void* @@ -360,12 +377,8 @@ public: int3 repairScreenPos(int3 pos); void showInfoDialog(std::string text, std::vector & components); void removeObjToBlit(IShowable* obj); - SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh); - SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS); - SDL_Surface * drawTownInfoWin(const CGTownInstance * curh); - - CPlayerInterface(int Player, int serial); + CPlayerInterface(int Player, int serial);//c-tor }; class CStatusBar : public CIntObject, public IStatusBar diff --git a/CPreGame.cpp b/CPreGame.cpp index 074b7157d49bae9724aa12a118db1313948a2afb..4c684ece6b844ea1aebac458280c1aa42796a974 100644 GIT binary patch delta 2840 zcma)-PiPZC6vp?}+7=HXhlH5eWUG`S5;TcY>uMzpL5kEuiv*Msn^22|D2b-=)J-%o z@t{GR!d$!*N|7R^btQX~;z1;qR7FEkgk+JR)T4Ov;A-*ayqV+j{oeQf?3EKN?#W~E z7tq?;3RtX6(uDzmc{U0mA*zc+?z_ z{8i>r(UjK{fC4W!rf}e5jpNYToWvb6Z|8R*HON}%Ly_sAHS718qItu*wZ*Ln2FP0A zBOA~bKB4xqHvM^{4XNHi;temV|9t@(hf$`dIgjeOW)EpMY%E6e8%NJ^H^oVFH^4%d zj=-oW+wTKafc@%&MFDKx4XA%Eie%dhz+~<`VgHT~P>1(H<#N0o9YzW4fDm7zMx;G4cF89=APwUZ6*|0GrB*<(Nm4b?qbNFD_vblPa z)rrnaj2b>j4>7x=+d~g~5?MnHN<>Sxy}E~po}!2D22nly&e_9#`h32>`}>_g_rBh( z`>|V>o;M#nPcD$-W2FFCr_kJOLOSJQTFUry!W}n4# z37kE7fXBidR^YHetVgg6R|H(9zBxD7c{wMp;g0ibJdR)GzGEpSQ^!Mojf%4%c2vuw zl2`CDiMHj|k-fL7t`9@l)wQbc^P@QQuX2)`Ye76Y{_*J^tRb4*Hmc6gaWq{O${V+N z!hUsrbC4$(Rr3}usLAapKkfUPH=q;r6dVYXX{ykQGD9(eFb^#h8xba{wvzp#=nSyF z2{5tQ6X37SY;=MmG*_IkAe2%kp#@>10Es~Tf<2A5X-7vtubwG<|?|?FP`u>#@UEt8NUdZreO|Lv< z7VLn;E)T;cp`;%o+p}x1gN|Yh!T<_mK^R2g-Vg*(sD!|W!tWu#?wiDtQE;KjpHXPm y@*~iDpq9x?Xr1**sAt0wPLEaNO9cFa8k5k+Gx~Y3o&} +int readNormalNr (int pos, int bytCon, unsigned char * str); +CLodHandler * BitmapHandler::bitmaph = NULL; +void BMPHeader::print(std::ostream & out) +{ + CDefHandler::print(out,fullSize,4); + CDefHandler::print(out,_h1,4); + CDefHandler::print(out,_c1,4); + CDefHandler::print(out,_c2,4); + CDefHandler::print(out,x,4); + CDefHandler::print(out,y,4); + CDefHandler::print(out,_c3,2); + CDefHandler::print(out,_c4,2); + CDefHandler::print(out,_h2,4); + CDefHandler::print(out,_h3,4); + CDefHandler::print(out,dataSize1,4); + CDefHandler::print(out,dataSize2,4); + for (int i=0;i<8;i++) + out << _c5[i]; + out.flush(); +} +void CPCXConv::openPCX(char * PCX, int len) +{ + pcxs=len; + pcx=(unsigned char*)PCX; +} +void CPCXConv::fromFile(std::string path) +{ + std::ifstream * is = new std::ifstream(); + is -> open(path.c_str(),std::ios::binary); + is->seekg(0,std::ios::end); // to the end + pcxs = is->tellg(); // read length + is->seekg(0,std::ios::beg); // wracamy na poczatek + pcx = new unsigned char[pcxs]; // allocate memory + is->read((char*)pcx, pcxs); // read map file to buffer + is->close(); + delete is; +} +void CPCXConv::saveBMP(std::string path) +{ + std::ofstream os; + os.open(path.c_str(), std::ios::binary); + os.write((char*)bmp,bmps); + os.close(); +} +void CPCXConv::convert() +{ + BMPHeader bh; + BMPPalette pal[256]; + Epcxformat format; + int fSize,i,y; + bool check1, check2; + unsigned char add; + int it=0; + + std::stringstream out; + + fSize = readNormalNr(it,4,pcx);it+=4; + bh.x = readNormalNr(it,4,pcx);it+=4; + bh.y = readNormalNr(it,4,pcx);it+=4; + if (fSize==bh.x*bh.y*3) + check1=true; + else + check1=false; + if (fSize==bh.x*bh.y) + check2=true; + else + check2=false; + if (check1) + format=PCX24B; + else if (check2) + format=PCX8B; + else + return; + add = 4 - bh.x%4; + if (add==4) + add=0; + bh._h3=bh.x*bh.y; + if (format==PCX8B) + { + bh._c1=0x436; + bh._c2=0x28; + bh._c3=1; + bh._c4=8; + //bh.dataSize2=bh.dataSize1=maxx*maxy; + bh.dataSize1=bh.x; + bh.dataSize2=bh.y; + bh.fullSize = bh.dataSize1+436; + } + else + { + bh._c1=0x36; + bh._c2=0x28; + bh._c3=1; + bh._c4=0x18; + //bh.dataSize2=bh.dataSize1=0xB12; + bh.dataSize1=bh.x; + bh.dataSize2=bh.y; + bh.fullSize=(bh.x+add)*bh.y*3+36+18; + bh._h3*=3; + } + if (format==PCX8B) + { + it = pcxs-256*3; + for (int i=0;i<256;i++) + { + pal[i].R=pcx[it++]; + pal[i].G=pcx[it++]; + pal[i].B=pcx[it++]; + pal[i].F='\0'; + } + } + out<<"BM"; + bh.print(out); + if (format==PCX8B) + { + for (int i=0;i<256;i++) + { + out<0;y--) + { + it=0xC+(y-1)*bh.x; + for (int j=0;j0) + { + for (int j=0;j0; y--) + { + it=0xC+(y-1)*bh.x*3; + for (int j=0;j0) + { + for (int j=0;jformat->palette->colors+i) = tp; + } + for (y=bh.y;y>0;y--) + { + it=0xC+(y-1)*bh.x; + for (int j=0;jpixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * j) = pcx[it+j]; + } + if (add>0) + { + for (int j=0;jpixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * (j+bh.x)) = 0; + } + } + } + } + else + { + for (y=bh.y; y>0; y--) + { + it=0xC+(y-1)*bh.x*3; + for (int j=0;jpixels + ret->pitch * (y-1) + j) = pcx[it+j]; + } + if (add>0) + { + for (int j=0;jpixels + ret->pitch * (y-1) + (j+bh.x*3)) = 0; + } + } + } + } + return ret; +} + +SDL_Surface * BitmapHandler::loadBitmap(std::string fname) +{ + if(!fname.size()) + return NULL; + unsigned char * pcx; + std::transform(fname.begin(),fname.end(),fname.begin(),toupper); + fname.replace(fname.find_first_of('.'),fname.find_first_of('.')+4,".PCX"); + Entry *e = bitmaph->entries.znajdz(fname); + if(!e) + { + std::cout<<"File "<offset<0) + { + fname.replace(fname.find_first_of('.'),fname.find_first_of('.')+4,".BMP"); + fname = "Data/"+fname; + FILE * f = fopen(fname.c_str(),"r"); + if(f) + { + fclose(f); + return SDL_LoadBMP(fname.c_str()); + } + else //file .bmp not present, check .pcx + { + char sign[3]; + fname.replace(fname.find_first_of('.'),fname.find_first_of('.')+4,".PCX"); + f = fopen(fname.c_str(),"r"); + if(!f) + return NULL; + fread(sign,1,3,f); + if(sign[0]=='B' && sign[1]=='M') //BMP named as PCX - people (eg. Kulex) sometimes use such files + { + fclose(f); + return SDL_LoadBMP(fname.c_str()); + } + else //PCX - but we don't know which + { + if((sign[0]==10) && (sign[1]<6) && (sign[2]==1)) //ZSoft PCX + { + fclose(f); + return IMG_Load(fname.c_str()); + } + else //H3-style PCX + { + CPCXConv cp; + pcx = new unsigned char[e->realSize]; + memcpy(pcx,sign,3); + int res = fread((char*)pcx+3, 1, e->realSize-3, f); + fclose(f); + cp.openPCX((char*)pcx,e->realSize); + return cp.getSurface(); + } + } + } + } + fseek(bitmaph->FLOD, e->offset, 0); + if (e->size==0) //file is not compressed + { + pcx = new unsigned char[e->realSize]; + fread((char*)pcx, 1, e->realSize, bitmaph->FLOD); + } + else + { + unsigned char * pcd = new unsigned char[e->size]; + fread((char*)pcd, 1, e->size, bitmaph->FLOD); + int res=bitmaph->infs2(pcd,e->size,e->realSize,pcx); + if(res!=0) + { + std::cout<<"an error "<realSize); + return cp.getSurface(); +} \ No newline at end of file diff --git a/client/CBitmapHandler.h b/client/CBitmapHandler.h new file mode 100644 index 000000000..368679ae6 --- /dev/null +++ b/client/CBitmapHandler.h @@ -0,0 +1,39 @@ +#pragma once +#include "../global.h" +struct SDL_Surface; +class CLodHandler; + +enum Epcxformat {PCX8B, PCX24B}; + +struct BMPPalette +{ + unsigned char R,G,B,F; +}; +struct BMPHeader +{ + int fullSize, _h1, _h2, _h3, _c1, _c2, _c3, _c4, x, y, + dataSize1, dataSize2; //DataSize=X*Y+2*Y + unsigned char _c5[8]; + void print(std::ostream & out); + BMPHeader(){_h1=_h2=0;for(int i=0;i<8;i++)_c5[i]=0;}; +}; +class CPCXConv +{ +public: + unsigned char * pcx, *bmp; + int pcxs, bmps; + void fromFile(std::string path); + void saveBMP(std::string path); + void openPCX(char * PCX, int len); + void openPCX(); + void convert(); + SDL_Surface * getSurface(); //for standard H3 PCX + //SDL_Surface * getSurfaceZ(); //for ZSoft PCX + CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;}; + ~CPCXConv(){if (pcxs) delete[] pcx; if(bmps) delete[] bmp;} +}; +namespace BitmapHandler +{ + extern CLodHandler *bitmaph; + SDL_Surface * loadBitmap(std::string fname); +}; \ No newline at end of file diff --git a/client/CCreatureAnimation.cpp b/client/CCreatureAnimation.cpp index 0f81cce93..e1916cda4 100644 --- a/client/CCreatureAnimation.cpp +++ b/client/CCreatureAnimation.cpp @@ -1,5 +1,4 @@ #include "CCreatureAnimation.h" -#include "../CGameInfo.h" #include "../hch/CLodHandler.h" int CCreatureAnimation::getType() const { @@ -36,21 +35,12 @@ void CCreatureAnimation::setType(int type) CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEntries(NULL) { - //load main file - std::string data2 = CGI->spriteh->getTextFile(name); - if(data2.size()==0) - throw new std::string("no such def!"); - FDef = new unsigned char[data2.size()]; - for(int g=0; ggiveFile(name); //load main file //init anim data int i,j, totalInBlock; char Buffer[13]; defName=name; - int andame = data2.size(); i = 0; DEFType = readNormalNr(i,4); i+=4; fullWidth = readNormalNr(i,4); i+=4; @@ -98,17 +88,6 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEn { SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4); } - //pictures don't have to be readed here - //for(int i=0; i= 4 + #define DLL_EXPORT __attribute__ ((visibility("default"))) + #else + #define DLL_EXPORT + #endif +#endif #define HANDLE_EXCEPTION \ catch (const std::exception& e) { \ diff --git a/hch/CAbilityHandler.cpp b/hch/CAbilityHandler.cpp index 2c40e676f..5986b3899 100644 --- a/hch/CAbilityHandler.cpp +++ b/hch/CAbilityHandler.cpp @@ -24,9 +24,9 @@ void CAbilityHandler::loadAbilities() nab->idNumber = abilities.size(); abilities.push_back(nab); } - abils32 = CGI->spriteh->giveDef("SECSK32.DEF"); - abils44 = CGI->spriteh->giveDef("SECSKILL.DEF"); - abils82 = CGI->spriteh->giveDef("SECSK82.DEF"); + abils32 = CDefHandler::giveDef("SECSK32.DEF"); + abils44 = CDefHandler::giveDef("SECSKILL.DEF"); + abils82 = CDefHandler::giveDef("SECSK82.DEF"); buf = CGameInfo::mainObj->bitmaph->getTextFile("SKILLLEV.TXT"); it=0; diff --git a/hch/CArtHandler.cpp b/hch/CArtHandler.cpp index 06b02a19f..f1910ae8c 100644 --- a/hch/CArtHandler.cpp +++ b/hch/CArtHandler.cpp @@ -6,8 +6,6 @@ void CArtHandler::loadArtifacts() { - artDefs = CGI->spriteh->giveDef("ARTIFACT.DEF"); - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("ARTRAITS.TXT"); int it=0; std::string dump; diff --git a/hch/CArtHandler.h b/hch/CArtHandler.h index 32a5a3646..e8f06ca93 100644 --- a/hch/CArtHandler.h +++ b/hch/CArtHandler.h @@ -24,7 +24,6 @@ public: class CArtHandler //handles artifacts { public: - CDefHandler * artDefs; std::vector treasures, minors, majors, relics; std::vector artifacts; void loadArtifacts(); diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index b3331433b..847bd4972 100644 --- a/hch/CCreatureHandler.cpp +++ b/hch/CCreatureHandler.cpp @@ -1,6 +1,4 @@ #include "../stdafx.h" -#include "../CGameInfo.h" -#include "CDefHandler.h" #include "CCreatureHandler.h" #include "CLodHandler.h" #include @@ -8,7 +6,6 @@ #include #include #include -#include "../SDL_Extensions.h" int CCreature::getQuantityID(int quantity) { @@ -54,7 +51,7 @@ int CCreature::maxAmount(const std::vector &res) const //how many creatures void CCreatureHandler::loadCreatures() { - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("ZCRTRAIT.TXT"); + std::string buf = bitmaph->getTextFile("ZCRTRAIT.TXT"); int andame = buf.size(); int i=0; //buf iterator int hmcr=0; @@ -346,19 +343,6 @@ void CCreatureHandler::loadCreatures() ifs.close(); ifs.clear(); - - ifs.open("config/cr_bgs.txt"); - while(!ifs.eof()) - { - int id; - std::string name; - ifs >> id >> name; - backgrounds[id]=CGI->bitmaph->loadBitmap(name); - } - ifs.close(); - ifs.clear(); - - ifs.open("config/cr_factions.txt"); while(!ifs.eof()) { @@ -378,23 +362,6 @@ void CCreatureHandler::loadCreatures() } ifs.close(); ifs.clear(); - - //loading 32x32px imgs - CDefHandler *smi = CGI->spriteh->giveDef("CPRSMALL.DEF"); - smi->notFreeImgs = true; - for (int i=0; iourImages.size(); i++) - { - boost::assign::insert(smallImgs)(i-2,smi->ourImages[i].bitmap); - } - delete smi; - smi = CGI->spriteh->giveDef("TWCRPORT.DEF"); - smi->notFreeImgs = true; - for (int i=0; iourImages.size(); i++) - { - boost::assign::insert(bigImgs)(i-2,smi->ourImages[i].bitmap); - } - delete smi; - // //loading unit animation def names std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod @@ -441,7 +408,7 @@ void CCreatureHandler::loadCreatures() void CCreatureHandler::loadAnimationInfo() { - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("CRANIM.TXT"); + std::string buf = bitmaph->getTextFile("CRANIM.TXT"); int andame = buf.size(); int i=0; //buf iterator int hmcr=0; diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index 244eb6483..f6f0550c0 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -6,8 +6,7 @@ #include #include -class CDefHandler; -struct SDL_Surface; +class CLodHandler; class CCreature { @@ -36,14 +35,14 @@ public: bool isDefinite; //if the creature type is wotn dependent, it should be true int indefLevel; //only if indefinite bool indefUpgraded; //onlu if inddefinite - //end - //CDefHandler * battleAnimation; - //TODO - zdolności - na typie wyliczeniowym czy czymś - static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion + //TODO - zdolności (abilities) - na typie wyliczeniowym czy czymś - albo lepiej secie czegoś + bool isDoubleWide(); //returns true if unit is double wide on battlefield bool isFlying(); //returns true if it is a flying unit int maxAmount(const std::vector &res) const; //how many creatures can be bought + + static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion }; class CCreatureSet //seven combined creatures @@ -55,15 +54,14 @@ public: class CCreatureHandler { + CLodHandler * bitmaph; public: - std::map smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border - std::map bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border - std::map backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral std::vector creatures; //creature ID -> creature info std::map > levelCreatures; //level -> list of creatures std::map nameToID; void loadCreatures(); void loadAnimationInfo(); void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i); + CCreatureHandler(CLodHandler * Bitmaph):bitmaph(Bitmaph){}; }; #endif //CCREATUREHANDLER_H \ No newline at end of file diff --git a/hch/CDefHandler.cpp b/hch/CDefHandler.cpp index becc28e6a11de1e61148f79a5c01655f6c0132ec..ed9261e361f9ed877dfbd25c3a7b4235db4cb83c 100644 GIT binary patch delta 701 zcmbu7KTpC?6va;swYCNas+M91g+v2HT^xxzh{PC_5FAWgBq<1le*xlWa5C1rIyktR zm@pexR~KE3CVl}&SMP(8P#hha-rRS4&ON`^i&yFPO}fg+1*DO6PQp%l-zf*w7Xdxu|>(5imJnvnw&aUGw3Ebr^nen1wS;X%&8)j z=sp-Jj@(2%kIvtD-l@(ZEBroUu7Y=$0kyamfNXc;@?fsZoq-=oilMkJ^jR}x;hv(O znPmZ7AEikTGVHQqmm=EIf8f)jWRRu?W``6ytlXpgRD@2~=W|}a33hzRo@*RqFi>$5 ZivOv>Bm_gL7N%$aqT=>AVZtXU{{jIvlI#Eg delta 597 zcmZ2*ow4H@;{>;fSss%u7#~cQ(&CbLV(?`MVDMl_Wk_U50g^=wRzO$)q%#@v7)mC4 zYALejGn4{ZjcMYO&t&jTQe&BHr^O|!!2lL!&|ydeO6LG!Fi=Ys&rRzLk}87+)BZgGH6b|FD^TIgC`fG#pH{g!sd_&QDCqELIs9+hGYg) zhG<}<#4=bj@G@{Qa6+R@4;W=Rz(^|w#)k&bl=n>Pn~j*VgoVLT4%Au2!<-4@mgRj3V=p~9G1$EFj6CLy0BLJf A9smFU delta 593 zcmZuuO-lk%6g_?vjA?sYSwU(>r4N@7$T7&68&N)i7;^8Q6zH~oQr zK%0I+LEE5ZQ0KjwCa}1?_b&IId(S=hy~H1;?#`1jL@)~zmoQ+VjVfwLU}ezA@6q()CN{{eGoGQPS>w)Qavry`=kfJ|&_z1%n*8tEN>py~I~-a~$>@r` uP+Urk9de`FJO!Su;aA`>I1G<{gkwq=MYc%Z5${?{+()B>=Q;5<@%as53}xs5 diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index 3713e920d..677a89302 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -28,7 +28,7 @@ void CHeroHandler::loadPortraits() of>>ID; std::string path; of>>path; - heroes[ID]->portraitSmall=CGI->bitmaph->loadBitmap(path); + heroes[ID]->portraitSmall=BitmapHandler::loadBitmap(path); if (!heroes[ID]->portraitSmall) std::cout<<"Can't read small portrait for "<portraitLarge=CGI->bitmaph->loadBitmap(path); + heroes[ID]->portraitLarge=BitmapHandler::loadBitmap(path); if (!heroes[ID]->portraitLarge) std::cout<<"Can't read large portrait for "<portraitLarge,SDL_SRCCOLORKEY,SDL_MapRGB(heroes[ID]->portraitLarge->format,0,255,255)); } of.close(); - pskillsb = CGI->spriteh->giveDef("PSKILL.DEF"); - resources = CGI->spriteh->giveDef("RESOUR82.DEF"); - un44 = CGI->spriteh->giveDef("UN44.DEF"); + pskillsb = CDefHandler::giveDef("PSKILL.DEF"); + resources = CDefHandler::giveDef("RESOUR82.DEF"); + un44 = CDefHandler::giveDef("UN44.DEF"); std::string strs = CGI->bitmaph->getTextFile("PRISKILL.TXT"); int itr=0; @@ -59,6 +59,294 @@ void CHeroHandler::loadPortraits() pskillsn.push_back(tmp); } } +void CHeroHandler::loadHeroFlags() +{ + flags1.push_back(CDefHandler::giveDef("ABF01L.DEF")); //red + flags1.push_back(CDefHandler::giveDef("ABF01G.DEF")); //blue + flags1.push_back(CDefHandler::giveDef("ABF01R.DEF")); //tan + flags1.push_back(CDefHandler::giveDef("ABF01D.DEF")); //green + flags1.push_back(CDefHandler::giveDef("ABF01B.DEF")); //orange + flags1.push_back(CDefHandler::giveDef("ABF01P.DEF")); //purple + flags1.push_back(CDefHandler::giveDef("ABF01W.DEF")); //teal + flags1.push_back(CDefHandler::giveDef("ABF01K.DEF")); //pink + + for(int q=0; q<8; ++q) + { + for(int o=0; oourImages.size(); ++o) + { + if(flags1[q]->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + flags1[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags1[q]->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); + nci.groupNumber = 11; + nci.imName = std::string(); + flags1[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags1[q]->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); + nci.groupNumber = 12; + nci.imName = std::string(); + flags1[q]->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int ff=0; ffourImages.size(); ++ff) + { + SDL_SetColorKey(flags1[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, + SDL_MapRGB(flags1[q]->ourImages[ff].bitmap->format, 0, 255, 255) + ); + } + flags1[q]->alphaTransformed = true; + } + + flags2.push_back(CDefHandler::giveDef("ABF02L.DEF")); //red + flags2.push_back(CDefHandler::giveDef("ABF02G.DEF")); //blue + flags2.push_back(CDefHandler::giveDef("ABF02R.DEF")); //tan + flags2.push_back(CDefHandler::giveDef("ABF02D.DEF")); //green + flags2.push_back(CDefHandler::giveDef("ABF02B.DEF")); //orange + flags2.push_back(CDefHandler::giveDef("ABF02P.DEF")); //purple + flags2.push_back(CDefHandler::giveDef("ABF02W.DEF")); //teal + flags2.push_back(CDefHandler::giveDef("ABF02K.DEF")); //pink + + for(int q=0; q<8; ++q) + { + for(int o=0; oourImages.size(); ++o) + { + if(flags2[q]->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + flags2[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags2[q]->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); + nci.groupNumber = 11; + nci.imName = std::string(); + flags2[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags2[q]->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); + nci.groupNumber = 12; + nci.imName = std::string(); + flags2[q]->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int ff=0; ffourImages.size(); ++ff) + { + SDL_SetColorKey(flags2[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, + SDL_MapRGB(flags2[q]->ourImages[ff].bitmap->format, 0, 255, 255) + ); + } + flags2[q]->alphaTransformed = true; + } + + flags3.push_back(CDefHandler::giveDef("ABF03L.DEF")); //red + flags3.push_back(CDefHandler::giveDef("ABF03G.DEF")); //blue + flags3.push_back(CDefHandler::giveDef("ABF03R.DEF")); //tan + flags3.push_back(CDefHandler::giveDef("ABF03D.DEF")); //green + flags3.push_back(CDefHandler::giveDef("ABF03B.DEF")); //orange + flags3.push_back(CDefHandler::giveDef("ABF03P.DEF")); //purple + flags3.push_back(CDefHandler::giveDef("ABF03W.DEF")); //teal + flags3.push_back(CDefHandler::giveDef("ABF03K.DEF")); //pink + + for(int q=0; q<8; ++q) + { + for(int o=0; oourImages.size(); ++o) + { + if(flags3[q]->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + flags3[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags3[q]->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); + nci.groupNumber = 11; + nci.imName = std::string(); + flags3[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags3[q]->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); + nci.groupNumber = 12; + nci.imName = std::string(); + flags3[q]->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int ff=0; ffourImages.size(); ++ff) + { + SDL_SetColorKey(flags3[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, + SDL_MapRGB(flags3[q]->ourImages[ff].bitmap->format, 0, 255, 255) + ); + } + flags3[q]->alphaTransformed = true; + } + + flags4.push_back(CDefHandler::giveDef("AF00.DEF")); //red + flags4.push_back(CDefHandler::giveDef("AF01.DEF")); //blue + flags4.push_back(CDefHandler::giveDef("AF02.DEF")); //tan + flags4.push_back(CDefHandler::giveDef("AF03.DEF")); //green + flags4.push_back(CDefHandler::giveDef("AF04.DEF")); //orange + flags4.push_back(CDefHandler::giveDef("AF05.DEF")); //purple + flags4.push_back(CDefHandler::giveDef("AF06.DEF")); //teal + flags4.push_back(CDefHandler::giveDef("AF07.DEF")); //pink + + + for(int q=0; q<8; ++q) + { + for(int o=0; oourImages.size(); ++o) + { + if(flags4[q]->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags4[q]->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.groupNumber = 11; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags4[q]->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.groupNumber = 12; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int o=0; oourImages.size(); ++o) + { + if(flags4[q]->ourImages[o].groupNumber==1) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.groupNumber = 13; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags4[q]->ourImages[o].groupNumber==2) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.groupNumber = 14; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags4[q]->ourImages[o].groupNumber==3) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.groupNumber = 15; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int ff=0; ffourImages.size(); ++ff) + { + SDL_SetColorKey(flags4[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, + SDL_MapRGB(flags4[q]->ourImages[ff].bitmap->format, 0, 255, 255) + ); + } + flags4[q]->alphaTransformed = true; + } +} void CHeroHandler::loadHeroes() { int ID=0; @@ -304,7 +592,7 @@ void CHeroHandler::loadHeroClasses() nm<moveAnim = CGI->spriteh->giveDef(nm.str()); + hc->moveAnim = CDefHandler::giveDef(nm.str()); for(int o=0; omoveAnim->ourImages.size(); ++o) { diff --git a/hch/CHeroHandler.h b/hch/CHeroHandler.h index 94245325e..43faa4e26 100644 --- a/hch/CHeroHandler.h +++ b/hch/CHeroHandler.h @@ -60,6 +60,7 @@ public: void loadBiographies(); void loadHeroClasses(); void loadPortraits(); //loads also imgs and names of primary skills + void loadHeroFlags(); void initHeroClasses(); ~CHeroHandler(); void initTerrainCosts(); diff --git a/hch/CLodHandler.cpp b/hch/CLodHandler.cpp index 9d9632877..eb2d7c7c9 100644 --- a/hch/CLodHandler.cpp +++ b/hch/CLodHandler.cpp @@ -1,14 +1,12 @@ +#define VCMI_DLL #include "../stdafx.h" +#include "zlib.h" #include "CLodHandler.h" -#include "../SDL_Extensions.h" -#include "CDefHandler.h" #include #include #include #include -#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations -#include "SDL_image.h" -int readNormalNr (int pos, int bytCon, unsigned char * str) +DLL_EXPORT int readNormalNr (int pos, int bytCon, unsigned char * str) { int ret=0; int amp=1; @@ -23,431 +21,35 @@ int readNormalNr (int pos, int bytCon, unsigned char * str) else return -1; return ret; } -void CPCXConv::openPCX(char * PCX, int len) -{ - pcxs=len; - pcx=(unsigned char*)PCX; - /*pcx = new unsigned char[len]; - for (int i=0;i open(path.c_str(),std::ios::binary); - is->seekg(0,std::ios::end); // to the end - pcxs = is->tellg(); // read length - is->seekg(0,std::ios::beg); // wracamy na poczatek - pcx = new unsigned char[pcxs]; // allocate memory - is->read((char*)pcx, pcxs); // read map file to buffer - is->close(); - delete is; -} -void CPCXConv::saveBMP(std::string path) -{ - std::ofstream os; - os.open(path.c_str(), std::ios::binary); - os.write((char*)bmp,bmps); - os.close(); -} -void CPCXConv::convert() -{ - BMPHeader bh; - BMPPalette pal[256]; - Epcxformat format; - int fSize,i,y; - bool check1, check2; - unsigned char add; - int it=0; - - std::stringstream out; - - fSize = readNormalNr(it,4,pcx);it+=4; - bh.x = readNormalNr(it,4,pcx);it+=4; - bh.y = readNormalNr(it,4,pcx);it+=4; - if (fSize==bh.x*bh.y*3) - check1=true; - else - check1=false; - if (fSize==bh.x*bh.y) - check2=true; - else - check2=false; - if (check1) - format=PCX24B; - else if (check2) - format=PCX8B; - else - return; - add = 4 - bh.x%4; - if (add==4) - add=0; - bh._h3=bh.x*bh.y; - if (format==PCX8B) - { - bh._c1=0x436; - bh._c2=0x28; - bh._c3=1; - bh._c4=8; - //bh.dataSize2=bh.dataSize1=maxx*maxy; - bh.dataSize1=bh.x; - bh.dataSize2=bh.y; - bh.fullSize = bh.dataSize1+436; - } - else - { - bh._c1=0x36; - bh._c2=0x28; - bh._c3=1; - bh._c4=0x18; - //bh.dataSize2=bh.dataSize1=0xB12; - bh.dataSize1=bh.x; - bh.dataSize2=bh.y; - bh.fullSize=(bh.x+add)*bh.y*3+36+18; - bh._h3*=3; - } - if (format==PCX8B) - { - it = pcxs-256*3; - for (int i=0;i<256;i++) - { - pal[i].R=pcx[it++]; - pal[i].G=pcx[it++]; - pal[i].B=pcx[it++]; - pal[i].F='\0'; - } - } - out<<"BM"; - bh.print(out); - if (format==PCX8B) - { - for (int i=0;i<256;i++) - { - out<0;y--) - { - it=0xC+(y-1)*bh.x; - for (int j=0;j0) - { - for (int j=0;j0; y--) - { - it=0xC+(y-1)*bh.x*3; - for (int j=0;j0) - { - for (int j=0;jformat->palette->colors+i) = tp; - } - for (y=bh.y;y>0;y--) - { - it=0xC+(y-1)*bh.x; - for (int j=0;jpixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * j) = pcx[it+j]; - } - if (add>0) - { - for (int j=0;jpixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * (j+bh.x)) = 0; - } - } - } - } - else - { - for (y=bh.y; y>0; y--) - { - it=0xC+(y-1)*bh.x*3; - for (int j=0;jpixels + ret->pitch * (y-1) + j) = pcx[it+j]; - } - if (add>0) - { - for (int j=0;jpixels + ret->pitch * (y-1) + (j+bh.x*3)) = 0; - } - } - } - } - return ret; -} - -SDL_Surface * CLodHandler::loadBitmap(std::string fname) -{ - if(!fname.size()) - return NULL; - unsigned char * pcx; - std::transform(fname.begin(),fname.end(),fname.begin(),toupper); - fname.replace(fname.find_first_of('.'),fname.find_first_of('.')+4,".PCX"); - Entry *e = entries.znajdz(fname); - if(!e) - { - std::cout<<"File "<offset<0) - { - fname.replace(fname.find_first_of('.'),fname.find_first_of('.')+4,".BMP"); - fname = "Data/"+fname; - FILE * f = fopen(fname.c_str(),"r"); - if(f) - { - fclose(f); - return SDL_LoadBMP(fname.c_str()); - } - else //file .bmp not present, check .pcx - { - char sign[3]; - fname.replace(fname.find_first_of('.'),fname.find_first_of('.')+4,".PCX"); - f = fopen(fname.c_str(),"r"); - if(!f) - return NULL; - fread(sign,1,3,f); - if(sign[0]=='B' && sign[1]=='M') //BMP named as PCX - people (eg. Kulex) sometimes use such files - { - fclose(f); - return SDL_LoadBMP(fname.c_str()); - } - else //PCX - but we don't know which - { - if((sign[0]==10) && (sign[1]<6) && (sign[2]==1)) //ZSoft PCX - { - fclose(f); - return IMG_Load(fname.c_str()); - } - else //H3-style PCX - { - CPCXConv cp; - pcx = new unsigned char[e->realSize]; - memcpy(pcx,sign,3); - int res = fread((char*)pcx+3, 1, e->realSize-3, f); - fclose(f); - cp.openPCX((char*)pcx,e->realSize); - return cp.getSurface(); - } - } - } - } - fseek(FLOD, e->offset, 0); - if (e->size==0) //file is not compressed - { - pcx = new unsigned char[e->realSize]; - fread((char*)pcx, 1, e->realSize, FLOD); - } - else - { - unsigned char * pcd = new unsigned char[e->size]; - fread((char*)pcd, 1, e->size, FLOD); - int res=infs2(pcd,e->size,e->realSize,pcx); - if(res!=0) - { - std::cout<<"an error "<realSize); - return cp.getSurface(); -} - -int CLodHandler::decompress (unsigned char * source, int size, int realSize, std::string & dest) -{ - std::ofstream lb; - lb.open("lodbuf\\buf.gz", std::ios::out|std::ios::binary); - for(int i=0; irealSize; fseek(FLOD, ourEntry->offset, 0); unsigned char * outp; - if (ourEntry->offset<0) //file in the sprites/ folder + if (ourEntry->offset<0) //file is in the sprites/ folder; no compression { - char * outp = new char[ourEntry->realSize]; - char name[120];for(int i=0;i<120;i++) name[i]='\0'; + unsigned char * outp = new unsigned char[ourEntry->realSize]; + char name[30];memset(name,0,30); strcat(name,"Sprites/"); strcat(name,(char*)ourEntry->name); FILE * f = fopen(name,"rb"); int result = fread(outp,1,ourEntry->realSize,f); if(result<0) {std::cout<<"Error in file reading: "<openFromMemory((unsigned char*)outp, ourEntry->realSize, std::string((char*)ourEntry->name)); - nh->alphaTransformed = false; - ret = nh; - delete[] outp; + else + return outp; } else if (ourEntry->size==0) //file is not compressed { outp = new unsigned char[ourEntry->realSize]; fread((char*)outp, 1, ourEntry->realSize, FLOD); - CDefHandler * nh = new CDefHandler(); - nh->openFromMemory(outp, ourEntry->realSize, std::string((char*)ourEntry->name)); - nh->alphaTransformed = false; - ret = nh; - delete[] outp; + return outp; } else //we will decompress file { @@ -456,62 +58,12 @@ CDefHandler * CLodHandler::giveDef(std::string defName) fseek(FLOD, 0, 0); unsigned char * decomp = NULL; int decRes = infs2(outp, ourEntry->size, ourEntry->realSize, decomp); - CDefHandler * nh = new CDefHandler(); - nh->openFromMemory(decomp, ourEntry->realSize, std::string((char*)ourEntry->name)); - nh->alphaTransformed = false; - ret = nh; - delete[] decomp; delete[] outp; + return decomp; } - return ret; + return NULL; } -CDefEssential * CLodHandler::giveDefEss(std::string defName) -{ - CDefEssential * ret; - CDefHandler * temp = giveDef(defName); - ret = temp->essentialize(); - delete temp; - return ret; -} -std::vector CLodHandler::extractManyFiles(std::vector defNamesIn) -{ - std::vector ret(defNamesIn.size()); - for(int hh=0; hhoffset, 0); - unsigned char * outp; - if (e->size==0) //file is not compressed - { - outp = new unsigned char[e->realSize]; - fread((char*)outp, 1, e->realSize, FLOD); - CDefHandler * nh = new CDefHandler; - nh->openFromMemory(outp, e->realSize, std::string((char*)e->name)); - nh->alphaTransformed = false; - ret[hh] = nh; - } - else //we will decompressing file - { - outp = new unsigned char[e->size]; - fread((char*)outp, 1, e->size, FLOD); - fseek(FLOD, 0, 0); - unsigned char * decomp = NULL; - int decRes = infs2(outp, e->size, e->realSize, decomp); - CDefHandler * nh = new CDefHandler; - nh->openFromMemory(decomp, e->realSize, std::string((char*)e->name)); - nh->alphaTransformed = false; - delete [] decomp; - ret[hh] = nh; - } - delete[] outp; - } - return ret; -} -int CLodHandler::infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits) +DLL_EXPORT int CLodHandler::infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits) { int ret; unsigned have; @@ -587,7 +139,7 @@ int CLodHandler::infs(unsigned char * in, int size, int realSize, std::ofstream return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; } -int CLodHandler::infs2(unsigned char * in, int size, int realSize, unsigned char *& out, int wBits) +DLL_EXPORT int CLodHandler::infs2(unsigned char * in, int size, int realSize, unsigned char *& out, int wBits) { int ret; unsigned have; @@ -670,13 +222,9 @@ int CLodHandler::infs2(unsigned char * in, int size, int realSize, unsigned char return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; } -void CLodHandler::extract(std::string FName) +DLL_EXPORT void CLodHandler::extract(std::string FName) { - std::ofstream FOut; - int i; - - //std::cout<<" done\n"; for (int i=0;ioffset<0) - { - char * outp = new char[e->realSize]; - char name[120];for(int i=0;i<120;i++) name[i]='\0'; - strcat(name,"Data/"); - strcat(name,(char*)e->name); - FILE * f = fopen(name,"rb"); - int result = fread(outp,1,e->realSize,f); - if(result<0) {std::cout<<"Error in file reading: "<realSize;itr++) - ret0+= *(outp+itr); - delete[] outp; - return ret0; - } - fseek(FLOD, e->offset, 0); - unsigned char * outp; - if (e->size==0) //file is not compressed - { - outp = new unsigned char[e->realSize]; - fread((char*)outp, 1, e->realSize, FLOD); - std::string ret = std::string((char*)outp); - delete[] outp; - return ret; - } - else //we will decompressing file - { - outp = new unsigned char[e->size]; - fread((char*)outp, 1, e->size, FLOD); - fseek(FLOD, 0, 0); - unsigned char * decomp = NULL; - int decRes = infs2(outp, e->size, e->realSize, decomp); - std::string ret; - for (int itr=0;itrrealSize;itr++) - ret+= *((char*)decomp+itr); - delete[] outp; - delete[] decomp; - return ret; - } - return ret0; + int length=-1; + unsigned char* data = giveFile(name,&length); + std::string ret; + ret.reserve(length); + for(int i=0;i +#include "../global.h" #include #include #include -#include "zlib.h" #include "../nodrze.h" -#include "SDL.h" - +struct SDL_Surface; class CDefHandler; class CDefEssential; -enum Epcxformat {PCX8B, PCX24B}; - namespace NLoadHandlerHelp { const int dmHelp=0, dmNoExtractingMask=1; @@ -43,43 +38,21 @@ struct Entry //Entry(unsigned char ): nameStr(con){}; Entry(){}; }; -class CPCXConv -{ -public: - unsigned char * pcx, *bmp; - int pcxs, bmps; - void fromFile(std::string path); - void saveBMP(std::string path); - void openPCX(char * PCX, int len); - void openPCX(); - void convert(); - SDL_Surface * getSurface(); //for standard H3 PCX - //SDL_Surface * getSurfaceZ(); //for ZSoft PCX - CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;}; - ~CPCXConv(){if (pcxs) delete[] pcx; if(bmps) delete[] bmp;} -}; -class CLodHandler + class CLodHandler { -private: - FILE* FLOD; public: + FILE* FLOD; nodrze entries; unsigned int totalFiles; - int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper - int decompress (unsigned char * source, int size, int realSize, std::ofstream & dest); //main decompression function - int decompress (unsigned char * source, int size, int realSize, std::string & dest); //main decompression function - int infm(FILE *source, FILE *dest, int wBits = 15); //zlib handler - int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler - int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler - std::vector extractManyFiles(std::vector defNamesIn); //extrats given files (defs only) - CDefHandler * giveDef(std::string defName); - CDefEssential * giveDefEss(std::string defName); - std::string getTextFile(std::string name); //extracts one file - void extract(std::string FName); - void extractFile(std::string FName, std::string name); //extracts a specific file - void init(std::string lodFile); - SDL_Surface * loadBitmap(std::string fname); + DLL_EXPORT int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper + DLL_EXPORT int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler + DLL_EXPORT int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler + DLL_EXPORT unsigned char * giveFile(std::string defName, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed! + DLL_EXPORT std::string getTextFile(std::string name); //extracts one file + DLL_EXPORT void extract(std::string FName); + DLL_EXPORT void extractFile(std::string FName, std::string name); //extracts a specific file + DLL_EXPORT void init(std::string lodFile); }; #endif //CLODHANDLER_H \ No newline at end of file diff --git a/hch/CTownHandler.cpp b/hch/CTownHandler.cpp index 80fda64c0..197d52722 100644 --- a/hch/CTownHandler.cpp +++ b/hch/CTownHandler.cpp @@ -6,8 +6,8 @@ #include "CGeneralTextHandler.h" CTownHandler::CTownHandler() { - smallIcons = CGI->spriteh->giveDef("ITPA.DEF"); - resources = CGI->spriteh->giveDef("RESOURCE.DEF"); + smallIcons = CDefHandler::giveDef("ITPA.DEF"); + resources = CDefHandler::giveDef("RESOURCE.DEF"); } CTownHandler::~CTownHandler() { diff --git a/mapHandler.cpp b/mapHandler.cpp index 8164e9e04..f70d4b031 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -276,7 +276,7 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur) t->defInfo = villages[t->subID]; if(!t->defInfo->handler) { - t->defInfo->handler = CGI->spriteh->giveDef(t->defInfo->name); + t->defInfo->handler = CDefHandler::giveDef(t->defInfo->name); alphaTransformDef(t->defInfo); } } @@ -308,7 +308,7 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur) t->defInfo = villages[t->subID]; if(!t->defInfo->handler) { - t->defInfo->handler = CGI->spriteh->giveDef(t->defInfo->name); + t->defInfo->handler = CDefHandler::giveDef(t->defInfo->name); alphaTransformDef(t->defInfo); } //CGI->townh->townInstances.push_back(t); @@ -321,7 +321,7 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur) if(!cur->defInfo){std::cout<<"Missing def declaration for "<ID<<" "<subID<defInfo->handler) //if we have to load def { - cur->defInfo->handler = CGI->spriteh->giveDef(cur->defInfo->name); + cur->defInfo->handler = CDefHandler::giveDef(cur->defInfo->name); alphaTransformDef(cur->defInfo); } @@ -338,8 +338,8 @@ void CMapHandler::randomizeObjects() } void CMapHandler::prepareFOWDefs() { - fullHide = CGameInfo::mainObj->spriteh->giveDef("TSHRC.DEF"); - partialHide = CGameInfo::mainObj->spriteh->giveDef("TSHRE.DEF"); + fullHide = CDefHandler::giveDef("TSHRC.DEF"); + partialHide = CDefHandler::giveDef("TSHRE.DEF"); //adding necessary rotations Cimage nw = partialHide->ourImages[22]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap); @@ -392,32 +392,32 @@ void CMapHandler::prepareFOWDefs() // visibility[gg][jj] = true; //} - visibility.resize(CGI->ac->map.width, Woff); + visibility.resize(CGI->mh->map->width, Woff); for (int i=0-Woff;iac->map.height,Hoff); + visibility[i].resize(CGI->mh->map->height,Hoff); } for (int i=0-Woff; iac->map.height+Hoff; ++j) + for (int j=0-Hoff; jmh->map->height+Hoff; ++j) { - visibility[i][j].resize(CGI->ac->map.twoLevel+1,0); - for(int k=0; kac->map.twoLevel+1; ++k) + visibility[i][j].resize(CGI->mh->map->twoLevel+1,0); + for(int k=0; kmh->map->twoLevel+1; ++k) visibility[i][j][k]=true; } } - hideBitmap.resize(CGI->ac->map.width, Woff); + hideBitmap.resize(CGI->mh->map->width, Woff); for (int i=0-Woff;iac->map.height,Hoff); + hideBitmap[i].resize(CGI->mh->map->height,Hoff); } for (int i=0-Woff; iac->map.height+Hoff; ++j) + for (int j=0-Hoff; jmh->map->height+Hoff; ++j) { - hideBitmap[i][j].resize(CGI->ac->map.twoLevel+1,0); - for(int k=0; kac->map.twoLevel+1; ++k) + hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1,0); + for(int k=0; kmh->map->twoLevel+1; ++k) hideBitmap[i][j][k] = rand()%fullHide->ourImages.size(); } } @@ -435,13 +435,13 @@ void CMapHandler::roadsRiverTerrainInit() { //initializing road's and river's DefHandlers - roadDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("dirtrd.def")); - roadDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("gravrd.def")); - roadDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("cobbrd.def")); - staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("clrrvr.def")); - staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("icyrvr.def")); - staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("mudrvr.def")); - staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("lavrvr.def")); + roadDefs.push_back(CDefHandler::giveDef("dirtrd.def")); + roadDefs.push_back(CDefHandler::giveDef("gravrd.def")); + roadDefs.push_back(CDefHandler::giveDef("cobbrd.def")); + staticRiverDefs.push_back(CDefHandler::giveDef("clrrvr.def")); + staticRiverDefs.push_back(CDefHandler::giveDef("icyrvr.def")); + staticRiverDefs.push_back(CDefHandler::giveDef("mudrvr.def")); + staticRiverDefs.push_back(CDefHandler::giveDef("lavrvr.def")); for(int g=0; gourImages.size(); ++h) @@ -460,18 +460,18 @@ void CMapHandler::roadsRiverTerrainInit() //roadBitmaps = new SDL_Surface** [map->width+2*Woff]; //for (int ii=0;iiwidth+2*Woff;ii++) // roadBitmaps[ii] = new SDL_Surface*[map->height+2*Hoff]; // allocate memory - sizes.x = CGI->ac->map.width; - sizes.y = CGI->ac->map.height; - sizes.z = CGI->ac->map.twoLevel+1; - ttiles.resize(CGI->ac->map.width,Woff); + sizes.x = CGI->mh->map->width; + sizes.y = CGI->mh->map->height; + sizes.z = CGI->mh->map->twoLevel+1; + ttiles.resize(CGI->mh->map->width,Woff); for (int i=0-Woff;iac->map.height,Hoff); + ttiles[i].resize(CGI->mh->map->height,Hoff); } for (int i=0-Woff;iac->map.height+Hoff;j++) - ttiles[i][j].resize(CGI->ac->map.twoLevel+1,0); + for (int j=0-Hoff;jmh->map->height+Hoff;j++) + ttiles[i][j].resize(CGI->mh->map->twoLevel+1,0); } @@ -531,25 +531,25 @@ void CMapHandler::roadsRiverTerrainInit() } //initializing simple values - for (int i=0; iac->map.width; i++) //jest po szerokości + for (int i=0; imh->map->width; i++) //jest po szerokości { - for (int j=0; jac->map.height;j++) //po wysokości + for (int j=0; jmh->map->height;j++) //po wysokości { for(int k=0; k=CGI->ac->map.width || j>=CGI->ac->map.height) + if(i<0 || j<0 || i>=CGI->mh->map->width || j>=CGI->mh->map->height) { ttiles[i][j][k].blocked = true; continue; } - ttiles[i][j][k].terType = (k==0 ? CGI->ac->map.terrain[i][j].tertype : CGI->ac->map.undergroungTerrain[i][j].tertype); - ttiles[i][j][k].malle = (k==0 ? CGI->ac->map.terrain[i][j].malle : CGI->ac->map.undergroungTerrain[i][j].malle); - ttiles[i][j][k].nuine = (k==0 ? CGI->ac->map.terrain[i][j].nuine : CGI->ac->map.undergroungTerrain[i][j].nuine); - ttiles[i][j][k].rivdir = (k==0 ? CGI->ac->map.terrain[i][j].rivDir : CGI->ac->map.undergroungTerrain[i][j].rivDir); - ttiles[i][j][k].roaddir = (k==0 ? CGI->ac->map.terrain[i][j].roadDir : CGI->ac->map.undergroungTerrain[i][j].roadDir); + ttiles[i][j][k].terType = (k==0 ? CGI->mh->map->terrain[i][j].tertype : CGI->mh->map->undergroungTerrain[i][j].tertype); + ttiles[i][j][k].malle = (k==0 ? CGI->mh->map->terrain[i][j].malle : CGI->mh->map->undergroungTerrain[i][j].malle); + ttiles[i][j][k].nuine = (k==0 ? CGI->mh->map->terrain[i][j].nuine : CGI->mh->map->undergroungTerrain[i][j].nuine); + ttiles[i][j][k].rivdir = (k==0 ? CGI->mh->map->terrain[i][j].rivDir : CGI->mh->map->undergroungTerrain[i][j].rivDir); + ttiles[i][j][k].roaddir = (k==0 ? CGI->mh->map->terrain[i][j].roadDir : CGI->mh->map->undergroungTerrain[i][j].roadDir); } } @@ -612,7 +612,7 @@ void CMapHandler::borderAndTerrainBitmapInit() //for (int ii=0;iiwidth+2*Woff;ii++) // terrainBitmap[ii] = new SDL_Surface*[map->height+2*Hoff]; // allocate memory - CDefHandler * bord = CGameInfo::mainObj->spriteh->giveDef("EDG.DEF"); + CDefHandler * bord = CDefHandler::giveDef("EDG.DEF"); bord->notFreeImgs = true; for (int i=0-Woff; iwidth+Woff; i++) //jest po szerokości { @@ -808,7 +808,7 @@ void CMapHandler::init() ///loading defs from lod for (int ir=0;irdefy.size();ir++) { - map->defy[ir]->handler=CGI->spriteh->giveDef(map->defy[ir]->name); + map->defy[ir]->handler=CDefHandler::giveDef(map->defy[ir]->name); CGDefInfo* pom = CGI->dobjinfo->gobjs[map->defy[ir]->id][map->defy[ir]->subid]; if(pom) pom->handler=map->defy[ir]->handler; @@ -835,7 +835,7 @@ void CMapHandler::init() { CGDefInfo * n = new CGDefInfo(*CGI->dobjinfo->castles[i%ccc]); ifs >> n->name; - if (!(n->handler = CGI->spriteh->giveDef(n->name))) + if (!(n->handler = CDefHandler::giveDef(n->name))) std::cout << "Cannot open "<name<defInfo = CGI->dobjinfo->gobjs[id][subid]; if(!nobj->defInfo->handler) - nobj->defInfo->handler = CGI->spriteh->giveDef(nobj->defInfo->name); + nobj->defInfo->handler = CDefHandler::giveDef(nobj->defInfo->name); return nobj; } @@ -1821,13 +1821,13 @@ void CMapHandler::loadDefs() { if (loadedTypes.find(map->terrain[i][j].tertype)==loadedTypes.end()) { - CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(map->terrain[i][j].tertype).c_str()); + CDefHandler *sdh = CDefHandler::giveDef(nameFromType(map->terrain[i][j].tertype).c_str()); loadedTypes.insert(map->terrain[i][j].tertype); defs.push_back(sdh); } if (map->twoLevel && loadedTypes.find(map->undergroungTerrain[i][j].tertype)==loadedTypes.end()) { - CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(map->undergroungTerrain[i][j].tertype).c_str()); + CDefHandler *sdh = CDefHandler::giveDef(nameFromType(map->undergroungTerrain[i][j].tertype).c_str()); loadedTypes.insert(map->undergroungTerrain[i][j].tertype); defs.push_back(sdh); } From 7df624d9191a8e7fe34a37eee16c3b51339d73de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 12 Jun 2008 21:08:04 +0000 Subject: [PATCH 08/47] More changes for splitting --- CAdvmapInterface.cpp | 2 +- CGameInfo.cpp | 2 +- CGameInfo.h | 1 - CMT.cpp | 12 ++++-------- SDL_Extensions.cpp | 34 +++++++++++++++++----------------- global.h | 8 ++------ hch/CAbilityHandler.cpp | 4 ++-- hch/CAmbarCendamo.cpp | 12 ++++++------ hch/CArtHandler.cpp | 2 +- hch/CBuildingHandler.cpp | 8 ++++---- hch/CCreatureHandler.cpp | 3 ++- hch/CCreatureHandler.h | 9 ++++----- hch/CDefObjInfoHandler.cpp | 5 +++-- hch/CDefObjInfoHandler.h | 6 ++++-- hch/CGeneralTextHandler.cpp | 2 +- hch/CHeroHandler.cpp | 10 +++++----- hch/CLodHandler.cpp | 12 ++++++------ hch/CLodHandler.h | 18 +++++++++--------- hch/CObjectHandler.cpp | 14 +++++++------- hch/CPreGameTextHandler.cpp | 6 +++--- hch/CSpellHandler.cpp | 2 +- 21 files changed, 83 insertions(+), 89 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index f5672a391..12ae46952 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -127,7 +127,7 @@ void CMinimap::draw() } void CMinimap::redraw(int level)// (level==-1) => redraw all levels { - (CGameInfo::mainObj); + (CGI); for (int i=0; imh->sizes.z; i++) { SDL_Surface * pom ; diff --git a/CGameInfo.cpp b/CGameInfo.cpp index bc942a234..ed0467ec5 100644 --- a/CGameInfo.cpp +++ b/CGameInfo.cpp @@ -1,4 +1,4 @@ #include "stdafx.h" #include "CGameInfo.h" -CGameInfo * CGameInfo::mainObj; \ No newline at end of file +CGameInfo * CGI; \ No newline at end of file diff --git a/CGameInfo.h b/CGameInfo.h index e278d7587..0e0570427 100644 --- a/CGameInfo.h +++ b/CGameInfo.h @@ -39,7 +39,6 @@ class CDefHandler; class CGameInfo { public: - static CGameInfo * mainObj; //pointer to main CGameInfo object CGameState * state; CArtHandler * arth; CHeroHandler * heroh; diff --git a/CMT.cpp b/CMT.cpp index 7d1b3668a..fc41df789 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -58,11 +58,10 @@ # define SET_BINARY_MODE(file) #endif #ifdef _DEBUG -CGameInfo* CGI; #endif #define CHUNK 16384 const char * NAME = "VCMI \"Altanatse\" 0.7"; - +DLL_EXPORT void initDLL(CLodHandler *b); SDL_Color playerColorPalette[256]; //palette to make interface colors good SDL_Surface * screen, * screen2; @@ -381,11 +380,7 @@ int _tmain(int argc, _TCHAR* argv[]) //screen = SDL_ConvertSurface(screen2, screen2->format, SDL_SWSURFACE); SDL_WM_SetCaption(NAME,""); //set window title - CGameInfo * cgi = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.) - CGameInfo::mainObj = cgi; - #ifdef _DEBUG - CGI = cgi; - #endif + CGameInfo * cgi = CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.) cgi->consoleh = new CConsoleHandler; cgi->mush = mush; cgi->curh = new CCursorHandler; @@ -395,6 +390,7 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->spriteh->init(std::string("Data\\H3sprite.lod")); BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler; cgi->bitmaph->init(std::string("Data\\H3bitmap.lod")); + initDLL(cgi->bitmaph); THC std::cout<<"Loading .lod files: "<arth = arth; THC std::cout<<"\tArtifact handler: "<bitmaph); + CCreatureHandler * creh = new CCreatureHandler(); creh->loadCreatures(); cgi->creh = creh; THC std::cout<<"\tCreature handler: "<format->palette->colors+i; if(cc->r==0 && cc->g==0 && cc->b==255) { - cc->r = CGameInfo::mainObj->playerColors[player].r; - cc->g = CGameInfo::mainObj->playerColors[player].g; - cc->b = CGameInfo::mainObj->playerColors[player].b; + cc->r = CGI->playerColors[player].r; + cc->g = CGI->playerColors[player].g; + cc->b = CGI->playerColors[player].b; } } } @@ -759,9 +759,9 @@ void CSDL_Ext::blueToPlayers(SDL_Surface * sur, int player) { if(cp[0]==0 && cp[1]==0 && cp[2]==255) { - cp[0] = CGameInfo::mainObj->playerColors[player].r; - cp[1] = CGameInfo::mainObj->playerColors[player].g; - cp[2] = CGameInfo::mainObj->playerColors[player].b; + cp[0] = CGI->playerColors[player].r; + cp[1] = CGI->playerColors[player].g; + cp[2] = CGI->playerColors[player].b; } } else @@ -769,9 +769,9 @@ void CSDL_Ext::blueToPlayers(SDL_Surface * sur, int player) if(cp[0]==255 && cp[1]==0 && cp[2]==0) { - cp[0] = CGameInfo::mainObj->playerColors[player].b; - cp[1] = CGameInfo::mainObj->playerColors[player].g; - cp[2] = CGameInfo::mainObj->playerColors[player].r; + cp[0] = CGI->playerColors[player].b; + cp[1] = CGI->playerColors[player].g; + cp[2] = CGI->playerColors[player].r; } } } @@ -806,9 +806,9 @@ void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player, int mode, void* a sort1.push_back(cp[1]); sort1.push_back(cp[2]); std::vector< std::pair > sort2; - sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].r, &(cp[0]))); - sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].g, &(cp[1]))); - sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].b, &(cp[2]))); + sort2.push_back(std::make_pair(CGI->playerColors[player].r, &(cp[0]))); + sort2.push_back(std::make_pair(CGI->playerColors[player].g, &(cp[1]))); + sort2.push_back(std::make_pair(CGI->playerColors[player].b, &(cp[2]))); std::sort(sort1.begin(), sort1.end()); if(sort2[0].first>sort2[1].first) std::swap(sort2[0], sort2[1]); @@ -834,9 +834,9 @@ void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player, int mode, void* a sort1.push_back(cp[1]); sort1.push_back(cp[0]); std::vector< std::pair > sort2; - sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].r, &(cp[2]))); - sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].g, &(cp[1]))); - sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].b, &(cp[0]))); + sort2.push_back(std::make_pair(CGI->playerColors[player].r, &(cp[2]))); + sort2.push_back(std::make_pair(CGI->playerColors[player].g, &(cp[1]))); + sort2.push_back(std::make_pair(CGI->playerColors[player].b, &(cp[0]))); std::sort(sort1.begin(), sort1.end()); if(sort2[0].first>sort2[1].first) std::swap(sort2[0], sort2[1]); @@ -874,9 +874,9 @@ void CSDL_Ext::setPlayerColor(SDL_Surface * sur, unsigned char player) if(sur->format->BitsPerPixel==8) { if(player != 255) - *(sur->format->palette->colors+5) = CGameInfo::mainObj->playerColors[player]; + *(sur->format->palette->colors+5) = CGI->playerColors[player]; else - *(sur->format->palette->colors+5) = CGameInfo::mainObj->neutralColor; + *(sur->format->palette->colors+5) = CGI->neutralColor; } } int readNormalNr (std::istream &in, int bytCon) diff --git a/global.h b/global.h index bf8057dc0..17a8f6549 100644 --- a/global.h +++ b/global.h @@ -21,14 +21,10 @@ enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255}; enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHEMIST, HERO_WIZARD, HERO_DEMONIAC, HERO_HERETIC, HERO_DEATHKNIGHT, HERO_NECROMANCER, HERO_WARLOCK, HERO_OVERLORD, HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST}; -#ifdef _DEBUG class CGameInfo; extern CGameInfo* CGI; -#else -#define CGI (CGameInfo::mainObj) -#endif -#define CURPLINT (((CPlayerInterface*)((CGameInfo::mainObj)->playerint[(CGameInfo::mainObj)->state->currentPlayer]))) -#define LOCPLINT (((CPlayerInterface*)((CGameInfo::mainObj)->playerint[(CGameInfo::mainObj)->localPlayer]))) +#define CURPLINT (((CPlayerInterface*)((CGI)->playerint[(CGI)->state->currentPlayer]))) +#define LOCPLINT (((CPlayerInterface*)((CGI)->playerint[(CGI)->localPlayer]))) //CURPLINT gives pointer to the interface of human player which is currently making turn, //LOCPLINT gives pointer to the interface which is currently showed (on this machine) diff --git a/hch/CAbilityHandler.cpp b/hch/CAbilityHandler.cpp index 5986b3899..b09aac533 100644 --- a/hch/CAbilityHandler.cpp +++ b/hch/CAbilityHandler.cpp @@ -7,7 +7,7 @@ void CAbilityHandler::loadAbilities() { - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("SSTRAITS.TXT"); + std::string buf = CGI->bitmaph->getTextFile("SSTRAITS.TXT"); int it=0; std::string dump; for(int i=0; i<2; ++i) @@ -28,7 +28,7 @@ void CAbilityHandler::loadAbilities() abils44 = CDefHandler::giveDef("SECSKILL.DEF"); abils82 = CDefHandler::giveDef("SECSK82.DEF"); - buf = CGameInfo::mainObj->bitmaph->getTextFile("SKILLLEV.TXT"); + buf = CGI->bitmaph->getTextFile("SKILLLEV.TXT"); it=0; for(int i=0; i<6; ++i) { diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index d678b6737..9336674d4 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -1103,7 +1103,7 @@ void CAmbarCendamo::deh3m() { int creType = readNormalNr(i, 2); i+=2; int creNumb = readNormalNr(i, 2); i+=2; - spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType])); + spec->m6cre.push_back(&(CGI->creh->creatures[creType])); spec->m6number.push_back(creNumb); } int limit = readNormalNr(i); i+=4; @@ -1835,7 +1835,7 @@ void CAmbarCendamo::deh3m() { int creType = readNormalNr(i, 2); i+=2; int creNumb = readNormalNr(i, 2); i+=2; - spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType])); + spec->m6cre.push_back(&(CGI->creh->creatures[creType])); spec->m6number.push_back(creNumb); } int limit = readNormalNr(i); i+=4; @@ -2064,8 +2064,8 @@ CCreatureSet CAmbarCendamo::readCreatureSet(int number) int rettt = readNormalNr(i+ir*4, 2); if(rettt==0xffff) continue; if(rettt>32768) - rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); + rettt = 65536-rettt+CGI->creh->creatures.size()-16; + ins.first = &(CGI->creh->creatures[rettt]); ins.second = readNormalNr(i+ir*4+2, 2); std::pair > tt(ir,ins); ret.slots.insert(tt); @@ -2082,8 +2082,8 @@ CCreatureSet CAmbarCendamo::readCreatureSet(int number) int rettt = readNormalNr(i+ir*3, 1); if(rettt==0xff) continue; if(rettt>220) - rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16; - ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); + rettt = 256-rettt+CGI->creh->creatures.size()-16; + ins.first = &(CGI->creh->creatures[rettt]); ins.second = readNormalNr(i+ir*3+1, 2); std::pair > tt(ir,ins); ret.slots.insert(tt); diff --git a/hch/CArtHandler.cpp b/hch/CArtHandler.cpp index f1910ae8c..1faa64fd6 100644 --- a/hch/CArtHandler.cpp +++ b/hch/CArtHandler.cpp @@ -6,7 +6,7 @@ void CArtHandler::loadArtifacts() { - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("ARTRAITS.TXT"); + std::string buf = CGI->bitmaph->getTextFile("ARTRAITS.TXT"); int it=0; std::string dump; for(int i=0; i<2; ++i) diff --git a/hch/CBuildingHandler.cpp b/hch/CBuildingHandler.cpp index d5e26f869..1fc627408 100644 --- a/hch/CBuildingHandler.cpp +++ b/hch/CBuildingHandler.cpp @@ -34,7 +34,7 @@ CBuilding * readBg(std::string &buf, unsigned int& it) } void CBuildingHandler::loadBuildings() { - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("BUILDING.TXT"), temp; + std::string buf = CGI->bitmaph->getTextFile("BUILDING.TXT"), temp; unsigned int andame = buf.size(), it=0; //buf iterator temp = readTo(buf,it,'\n');temp = readTo(buf,it,'\n');//read 2 lines of file info @@ -75,7 +75,7 @@ void CBuildingHandler::loadBuildings() } /////done reading BUILDING.TXT***************************** - buf = CGameInfo::mainObj->bitmaph->getTextFile("BLDGNEUT.TXT"); + buf = CGI->bitmaph->getTextFile("BLDGNEUT.TXT"); andame = buf.size(), it=0; for(int b=0;b<15;b++) @@ -105,7 +105,7 @@ void CBuildingHandler::loadBuildings() } /////done reading "BLDGNEUT.TXT"****************************** - buf = CGameInfo::mainObj->bitmaph->getTextFile("BLDGSPEC.TXT"); + buf = CGI->bitmaph->getTextFile("BLDGSPEC.TXT"); andame = buf.size(), it=0; for(int f=0;fbitmaph->getTextFile("DWELLING.TXT"); + buf = CGI->bitmaph->getTextFile("DWELLING.TXT"); andame = buf.size(), it=0; for(int f=0;f #include #include - +extern CLodHandler * bitmaph; int CCreature::getQuantityID(int quantity) { if (quantity<5) diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index f6f0550c0..c1e99afc0 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -1,6 +1,6 @@ #ifndef CCREATUREHANDLER_H #define CCREATUREHANDLER_H - +#include "../global.h" #include #include #include @@ -8,7 +8,7 @@ class CLodHandler; -class CCreature +class DLL_EXPORT CCreature { public: std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name @@ -52,9 +52,8 @@ public: bool formation; //false - wide, true - tight }; -class CCreatureHandler +class DLL_EXPORT CCreatureHandler { - CLodHandler * bitmaph; public: std::vector creatures; //creature ID -> creature info std::map > levelCreatures; //level -> list of creatures @@ -62,6 +61,6 @@ public: void loadCreatures(); void loadAnimationInfo(); void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i); - CCreatureHandler(CLodHandler * Bitmaph):bitmaph(Bitmaph){}; + CCreatureHandler(){}; }; #endif //CCREATUREHANDLER_H \ No newline at end of file diff --git a/hch/CDefObjInfoHandler.cpp b/hch/CDefObjInfoHandler.cpp index 4a7569ebe..9474b1b27 100644 --- a/hch/CDefObjInfoHandler.cpp +++ b/hch/CDefObjInfoHandler.cpp @@ -1,9 +1,10 @@ +#define VCMI_DLL #include "../stdafx.h" #include "CDefObjInfoHandler.h" #include "../CGameInfo.h" #include "CLodHandler.h" #include - +extern CLodHandler * bitmaph; bool CGDefInfo::isVisitable() { for (int i=0; i<6; i++) @@ -20,7 +21,7 @@ CGDefInfo::CGDefInfo() void CDefObjInfoHandler::load() { nodrze ideki; - std::istringstream inp(CGameInfo::mainObj->bitmaph->getTextFile("ZOBJCTS.TXT")); + std::istringstream inp(bitmaph->getTextFile("ZOBJCTS.TXT")); int objNumber; inp>>objNumber; for(int hh=0; hh #include +#include "../global.h" class CDefHandler; -class CGDefInfo +class CLodHandler; +class DLL_EXPORT CGDefInfo { public: std::string name; @@ -27,7 +29,7 @@ public: } CGDefInfo(); }; -class CDefObjInfoHandler +class DLL_EXPORT CDefObjInfoHandler { public: std::map > gobjs; diff --git a/hch/CGeneralTextHandler.cpp b/hch/CGeneralTextHandler.cpp index 6b6c9e84c..58cd563d6 100644 --- a/hch/CGeneralTextHandler.cpp +++ b/hch/CGeneralTextHandler.cpp @@ -6,7 +6,7 @@ void CGeneralTextHandler::load() { - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("GENRLTXT.TXT"); + std::string buf = CGI->bitmaph->getTextFile("GENRLTXT.TXT"); int andame = buf.size(); int i=0; //buf iterator for(i; ibitmaph->getTextFile("HOTRAITS.TXT"); + std::string buf = CGI->bitmaph->getTextFile("HOTRAITS.TXT"); int it=0; std::string dump; for(int i=0; i<2; ++i) @@ -436,7 +436,7 @@ void CHeroHandler::loadHeroes() } void CHeroHandler::loadSpecialAbilities() { - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("HEROSPEC.TXT"); + std::string buf = CGI->bitmaph->getTextFile("HEROSPEC.TXT"); int it=0; std::string dump; for(int i=0; i<2; ++i) @@ -453,7 +453,7 @@ void CHeroHandler::loadSpecialAbilities() void CHeroHandler::loadBiographies() { - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("HEROBIOS.TXT"); + std::string buf = CGI->bitmaph->getTextFile("HEROBIOS.TXT"); int it=0; for (int i=0;ibitmaph->getTextFile("HCTRAITS.TXT"); + std::string buf = CGI->bitmaph->getTextFile("HCTRAITS.TXT"); int andame = buf.size(); for(int y=0; yabilh->abilities.size(); ++dd) + for(int dd=0; ddabilh->abilities.size(); ++dd) { befi=i; for(i; i entries; unsigned int totalFiles; - DLL_EXPORT int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper - DLL_EXPORT int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler - DLL_EXPORT int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler - DLL_EXPORT unsigned char * giveFile(std::string defName, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed! - DLL_EXPORT std::string getTextFile(std::string name); //extracts one file - DLL_EXPORT void extract(std::string FName); - DLL_EXPORT void extractFile(std::string FName, std::string name); //extracts a specific file - DLL_EXPORT void init(std::string lodFile); + int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper + int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler + int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler + unsigned char * giveFile(std::string defName, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed! + std::string getTextFile(std::string name); //extracts one file + void extract(std::string FName); + void extractFile(std::string FName, std::string name); //extracts a specific file + void init(std::string lodFile); }; #endif //CLODHANDLER_H \ No newline at end of file diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 0af46e127..478d279a9 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -14,7 +14,7 @@ void CObjectHandler::loadObjects() { int ID=0; - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("OBJNAMES.TXT"); + std::string buf = CGI->bitmaph->getTextFile("OBJNAMES.TXT"); int it=0; while (itbitmaph->getTextFile("ADVEVENT.TXT"); + buf = CGI->bitmaph->getTextFile("ADVEVENT.TXT"); it=0; std::string temp; while (itbitmaph->getTextFile("XTRAINFO.TXT"); + buf = CGI->bitmaph->getTextFile("XTRAINFO.TXT"); it=0; while (itbitmaph->getTextFile("MINENAME.TXT"); + buf = CGI->bitmaph->getTextFile("MINENAME.TXT"); it=0; while (it(temp,"")); } - buf = CGameInfo::mainObj->bitmaph->getTextFile("MINEEVNT.TXT"); + buf = CGI->bitmaph->getTextFile("MINEEVNT.TXT"); it=0; int i=0; while (itbitmaph->getTextFile("RESTYPES.TXT"); + buf = CGI->bitmaph->getTextFile("RESTYPES.TXT"); it=0; while (itbitmaph->getTextFile("ZCRGN1.TXT"); + buf = CGI->bitmaph->getTextFile("ZCRGN1.TXT"); it=0; while (itbitmaph->getTextFile("ZELP.TXT"); + std::string buf1 = CGI->bitmaph->getTextFile("ZELP.TXT"); int itr=0, eol=-1, eolnext=-1, pom; eolnext = buf1.find_first_of('\r',itr); while(itrbitmaph->getTextFile("VCDESC.TXT"); + std::string buf = CGI->bitmaph->getTextFile("VCDESC.TXT"); int andame = buf.size(); int i=0; //buf iterator for(int gg=0; gg<14; ++gg) @@ -62,7 +62,7 @@ void CPreGameTextHandler::loadTexts() victoryConditions[gg] = buf.substr(befi, i-befi); i+=2; } - buf = CGameInfo::mainObj->bitmaph->getTextFile("LCDESC.TXT"); + buf = CGI->bitmaph->getTextFile("LCDESC.TXT"); andame = buf.size(); i=0; //buf iterator for(int gg=0; gg<4; ++gg) diff --git a/hch/CSpellHandler.cpp b/hch/CSpellHandler.cpp index 0b2d1bae8..d31dc73b2 100644 --- a/hch/CSpellHandler.cpp +++ b/hch/CSpellHandler.cpp @@ -5,7 +5,7 @@ void CSpellHandler::loadSpells() { - std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("SPTRAITS.TXT"); + std::string buf = CGI->bitmaph->getTextFile("SPTRAITS.TXT"); int andame = buf.size(); int i=0; //buf iterator int hmcr=0; From 6ad729148e3a85d59b1064d031a06bada246e872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Fri, 13 Jun 2008 08:16:51 +0000 Subject: [PATCH 09/47] Continuation of splitting. (don't try to compile this revision) --- CAdvmapInterface.cpp | 9 +- CCastleInterface.cpp | 9 +- CHeroWindow.cpp | 20 +- CMT.cpp | 19 +- CPlayerInterface.cpp | 189 +++------------ CPlayerInterface.h | 25 -- CPreGame.cpp | Bin 128430 -> 128724 bytes client/Graphics.cpp | 469 ++++++++++++++++++++++++++++++++++++ client/Graphics.h | 40 +++ hch/CAbilityHandler.cpp | 12 +- hch/CArtHandler.cpp | 150 ++---------- hch/CArtHandler.h | 6 +- hch/CGeneralTextHandler.cpp | 119 +-------- hch/CGeneralTextHandler.h | 19 +- hch/CHeroHandler.cpp | 367 ++-------------------------- hch/CHeroHandler.h | 23 +- hch/CObjectHandler.cpp | 35 ++- hch/CTownHandler.cpp | 57 +---- hch/CTownHandler.h | 23 +- mapHandler.cpp | 7 +- stdafx.h | 1 + 21 files changed, 669 insertions(+), 930 deletions(-) create mode 100644 client/Graphics.cpp create mode 100644 client/Graphics.h diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 12ae46952..995720d9d 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -19,6 +19,7 @@ #include #include "AdventureMapButton.h" #include "CHeroWindow.h" +#include "client/Graphics.h" #pragma warning (disable : 4355) extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts @@ -679,14 +680,14 @@ void CInfoBar::draw(const CGObjectInstance * specific) if(specific->ID == 34) //hero { - if(LOCPLINT->graphics.heroWins.find(specific->subID)!=LOCPLINT->graphics.heroWins.end()) - blitAt(LOCPLINT->graphics.heroWins[specific->subID],pos.x,pos.y); + if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end()) + blitAt(graphics->heroWins[specific->subID],pos.x,pos.y); } else if (specific->ID == 98) { const CGTownInstance * t = static_cast(specific); - if(LOCPLINT->graphics.townWins.find(t->identifier)!=LOCPLINT->graphics.townWins.end()) - blitAt(LOCPLINT->graphics.townWins[t->identifier],pos.x,pos.y); + if(graphics->townWins.find(t->identifier)!=graphics->townWins.end()) + blitAt(graphics->townWins[t->identifier],pos.x,pos.y); } //SDL_Surface * todr = LOCPLINT->infoWin(specific); diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index 8dc296fe0..6484595ea 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -12,6 +12,7 @@ #include "CMessage.h" #include "hch/CGeneralTextHandler.h" #include "CCallback.h" +#include "client/Graphics.h" extern TTF_Font * GEOR16; CBuildingRect::CBuildingRect(Structure *Str) :str(Str), moi(false), offset(0) @@ -414,7 +415,7 @@ void CCastleInterface::showAll(SDL_Surface * to) int pomx, pomy; pomx = 22 + (55*((i>3)?(i-4):i)); pomy = (i>3)?(507):(459); - blitAt(LOCPLINT->graphics.smallImgs[cid],pomx,pomy,to); + blitAt(graphics->smallImgs[cid],pomx,pomy,to); std::ostringstream oss; oss << '+' << town->creatureGrowth(i); CSDL_Ext::printAtMiddle(oss.str(),pomx+16,pomy+37,GEOR13,zwykly,to); @@ -433,7 +434,7 @@ void CCastleInterface::showAll(SDL_Surface * to) pom += F_NUMBER*2; if(town->builded >= MAX_BUILDING_PER_TURN) pom++; - blitAt(LOCPLINT->graphics.bigTownPic->ourImages[pom].bitmap,15,387,to); + blitAt(graphics->bigTownPic->ourImages[pom].bitmap,15,387,to); //flag if(town->getOwner()w/2-row1w/2)+77*it+16,ah+42,GEOR16,zwykly,bitmap); - blitAt(CGI->townh->resources->ourImages[cn].bitmap,(bitmap->w/2-row1w/2)+77*it++,ah,bitmap); + blitAt(graphics->resources32->ourImages[cn].bitmap,(bitmap->w/2-row1w/2)+77*it++,ah,bitmap); } else { CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row2w/2)+77*it+16-308,ah+42,GEOR16,zwykly,bitmap); - blitAt(CGI->townh->resources->ourImages[cn].bitmap,(bitmap->w/2-row2w/2)+77*it++ - 308,ah,bitmap); + blitAt(graphics->resources32->ourImages[cn].bitmap,(bitmap->w/2-row2w/2)+77*it++ - 308,ah,bitmap); } if(it==4) ah+=75; diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index beb0dd81b..e67978534 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -15,7 +15,7 @@ #include "hch/CArtHandler.h" #include "hch\CAbilityHandler.h" #include - +#include "client/Graphics.h" extern SDL_Surface * screen; extern TTF_Font * GEOR16; @@ -732,7 +732,7 @@ void CHeroWindow::redrawCurBack() blitAt(skillpics->ourImages[4].bitmap, 20, 230, curBack); blitAt(skillpics->ourImages[3].bitmap, 162, 230, curBack); - blitAt(curHero->type->portraitLarge, 19, 19, curBack); + blitAt(graphics->portraitLarge[curHero->subID], 19, 19, curBack); CSDL_Ext::printAtMiddle(curHero->name, 190, 40, GEORXX, tytulowy, curBack); @@ -788,8 +788,8 @@ void CHeroWindow::redrawCurBack() primarySkill4<primSkills[3]; CSDL_Ext::printAtMiddle(primarySkill4.str(), 263, 165, TNRB16, zwykly, curBack); - blitAt(LOCPLINT->graphics.luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack); - blitAt(LOCPLINT->graphics.morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack); + blitAt(graphics->luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack); + blitAt(graphics->morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack); blitAt(flags->ourImages[player].bitmap, 606, 8, curBack); @@ -797,14 +797,14 @@ void CHeroWindow::redrawCurBack() for(int g=0; gcb->howManyHeroes(); ++g) { const CGHeroInstance * cur = LOCPLINT->cb->getHeroInfo(player, g, false); - blitAt(cur->type->portraitSmall, 611, 87+g*54, curBack); + blitAt(graphics->portraitSmall[cur->subID], 611, 87+g*54, curBack); //printing yellow border if(cur->name == curHero->name) { - for(int f=0; ftype->portraitSmall->w; ++f) + for(int f=0; fportraitSmall[cur->subID]->w; ++f) { - for(int h=0; htype->portraitSmall->h; ++h) - if(f==0 || h==0 || f==cur->type->portraitSmall->w-1 || h==cur->type->portraitSmall->h-1) + for(int h=0; hportraitSmall[cur->subID]->h; ++h) + if(f==0 || h==0 || f==graphics->portraitSmall[cur->subID]->w-1 || h==graphics->portraitSmall[cur->subID]->h-1) { CSDL_Ext::SDL_PutPixel(curBack, 611+f, 87+g*54+h, 240, 220, 120); } @@ -863,7 +863,7 @@ void CHeroWindow::redrawCurBack() } //printing special ability - blitAt(CGI->heroh->un44->ourImages[curHero->subID].bitmap, 18, 180, curBack); + blitAt(graphics->un44->ourImages[curHero->subID].bitmap, 18, 180, curBack); //printing necessery texts CSDL_Ext::printAt(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 231, GEOR13, tytulowy, curBack); @@ -979,7 +979,7 @@ void CArtPlace::show(SDL_Surface *to) { if(ourArt) { - blitAt(LOCPLINT->graphics.artDefs->ourImages[ourArt->id].bitmap, pos.x, pos.y, to); + blitAt(graphics->artDefs->ourImages[ourArt->id].bitmap, pos.x, pos.y, to); } if(clicked && active) { diff --git a/CMT.cpp b/CMT.cpp index fc41df789..3ec091365 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -50,6 +50,7 @@ #include "boost/filesystem/operations.hpp" #include #include +#include "client\Graphics.h" #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) # include # include @@ -370,11 +371,7 @@ int _tmain(int argc, _TCHAR* argv[]) CMusicHandler * mush = new CMusicHandler; //initializing audio mush->initMusics(); //audio initialized - /*if(Mix_PlayMusic(mush->mainMenuWoG, -1)==-1) //uncomment this fragment to have music - { - printf("Mix_PlayMusic: %s\n", Mix_GetError()); - // well, there's no music, but most games don't break without music... - }*/ + //screen2 = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //screen = SDL_ConvertSurface(screen2, screen2->format, SDL_SWSURFACE); @@ -390,8 +387,11 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->spriteh->init(std::string("Data\\H3sprite.lod")); BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler; cgi->bitmaph->init(std::string("Data\\H3bitmap.lod")); - initDLL(cgi->bitmaph); THC std::cout<<"Loading .lod files: "<bitmaph); + THC std::cout<<"Initializing VCMI_Lib: "<generaltexth = new CGeneralTextHandler; cgi->generaltexth->load(); THC std::cout<<"Preparing more handlers: "<heroh->loadHeroFlags(); - THC std::cout<<"Initializing colours and flags: "<mush = mush; @@ -566,11 +564,6 @@ int _tmain(int argc, _TCHAR* argv[]) initGameState(&ac->map,cgi); THC std::cout<<"Initializing GameState (together): "<playerint.push_back(NULL); - }*/ for (int i=0; iscenarioOps.playerInfos.size();i++) //initializing interfaces { diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 79d05b0ec..74b5b35a9 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -27,6 +27,7 @@ #include "CLua.h" #include #include "client/CCreatureAnimation.h" +#include "client/Graphics.h" using namespace CSDL_Ext; extern TTF_Font * GEOR16; @@ -229,10 +230,10 @@ void CGarrisonSlot::show() { char* buf = new char[15]; itoa(count,buf,10); - blitAt(LOCPLINT->graphics.bigImgs[creature->idNumber],pos); + blitAt(graphics->bigImgs[creature->idNumber],pos); printTo(buf,pos.x+56,pos.y+62,GEOR16,zwykly); if(owner->highlighted==this) - blitAt(LOCPLINT->graphics.bigImgs[-1],pos); + blitAt(graphics->bigImgs[-1],pos); if(owner->update) updateRect(&pos,screen); delete [] buf; @@ -242,7 +243,7 @@ void CGarrisonSlot::show() SDL_Rect jakis1 = genRect(pos.h,pos.w,owner->offx+ID*(pos.w+owner->interx),owner->offy+upg*(pos.h+owner->intery)), jakis2 = pos; SDL_BlitSurface(owner->sur,&jakis1,screen,&jakis2); if(owner->splitting) - blitAt(LOCPLINT->graphics.bigImgs[-1],pos); + blitAt(graphics->bigImgs[-1],pos); if(owner->update) SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h); } @@ -552,16 +553,16 @@ SDL_Surface * SComponent::getImg() switch (type) { case primskill: - return CGI->heroh->pskillsb->ourImages[subtype].bitmap; + return graphics->pskillsb->ourImages[subtype].bitmap; break; case secskill: return CGI->abilh->abils82->ourImages[subtype*3 + 3 + val].bitmap; break; case resource: - return CGI->heroh->resources->ourImages[subtype].bitmap; + return graphics->resources->ourImages[subtype].bitmap; break; case experience: - return CGI->heroh->pskillsb->ourImages[4].bitmap; + return graphics->pskillsb->ourImages[4].bitmap; break; } return NULL; @@ -887,60 +888,6 @@ void TimeInterested::deactivate() LOCPLINT-> timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this)); } -CPlayerInterface::Graphics::Graphics() -{ - artDefs = CDefHandler::giveDef("ARTIFACT.DEF"); - hInfo = BitmapHandler::loadBitmap("HEROQVBK.bmp"); - SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255)); - tInfo = BitmapHandler::loadBitmap("TOWNQVBK.bmp"); - SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->format,0,255,255)); - slotsPos.push_back(std::pair(44,82)); - slotsPos.push_back(std::pair(80,82)); - slotsPos.push_back(std::pair(116,82)); - slotsPos.push_back(std::pair(26,131)); - slotsPos.push_back(std::pair(62,131)); - slotsPos.push_back(std::pair(98,131)); - slotsPos.push_back(std::pair(134,131)); - - luck22 = CDefHandler::giveDefEss("ILCK22.DEF"); - luck30 = CDefHandler::giveDefEss("ILCK30.DEF"); - luck42 = CDefHandler::giveDefEss("ILCK42.DEF"); - luck82 = CDefHandler::giveDefEss("ILCK82.DEF"); - morale22 = CDefHandler::giveDefEss("IMRL22.DEF"); - morale30 = CDefHandler::giveDefEss("IMRL30.DEF"); - morale42 = CDefHandler::giveDefEss("IMRL42.DEF"); - morale82 = CDefHandler::giveDefEss("IMRL82.DEF"); - halls = CDefHandler::giveDefEss("ITMTLS.DEF"); - forts = CDefHandler::giveDefEss("ITMCLS.DEF"); - bigTownPic = CDefHandler::giveDefEss("ITPT.DEF"); - std::ifstream ifs; - ifs.open("config/cr_bgs.txt"); - while(!ifs.eof()) - { - int id; - std::string name; - ifs >> id >> name; - backgrounds[id]=BitmapHandler::loadBitmap(name); - } - ifs.close(); - ifs.clear(); - - //loading 32x32px imgs - CDefHandler *smi = CDefHandler::giveDef("CPRSMALL.DEF"); - smi->notFreeImgs = true; - for (int i=0; iourImages.size(); i++) - { - smallImgs[i-2] = smi->ourImages[i].bitmap; - } - delete smi; - smi = CDefHandler::giveDef("TWCRPORT.DEF"); - smi->notFreeImgs = true; - for (int i=0; iourImages.size(); i++) - { - bigImgs[i-2] = smi->ourImages[i].bitmap; - } - delete smi; -} CPlayerInterface::CPlayerInterface(int Player, int serial) { playerID=Player; @@ -958,13 +905,13 @@ void CPlayerInterface::init(ICallback * CB) for(int i=0;i(hh[i]->subID,pom)); + graphics->heroWins.insert(std::pair(hh[i]->subID,pom)); } std::vector tt = cb->getTownsInfo(false); for(int i=0;i(tt[i]->identifier,pom)); + graphics->townWins.insert(std::pair(tt[i]->identifier,pom)); } } void CPlayerInterface::yourTurn() @@ -1584,83 +1531,13 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } void CPlayerInterface::heroKilled(const CGHeroInstance* hero) { - graphics.heroWins.erase(hero->ID); + graphics->heroWins.erase(hero->ID); } void CPlayerInterface::heroCreated(const CGHeroInstance * hero) { - if(graphics.heroWins.find(hero->subID)==graphics.heroWins.end()) - graphics.heroWins.insert(std::pair(hero->subID,infoWin(hero))); + if(graphics->heroWins.find(hero->subID)==graphics->heroWins.end()) + graphics->heroWins.insert(std::pair(hero->subID,infoWin(hero))); } - -SDL_Surface * CPlayerInterface::Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to) -{ - char * buf = new char[10]; - for (int i=from;iprimSkills[i],buf,10); - printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret); - } - delete[] buf; - return ret; -} -SDL_Surface * CPlayerInterface::Graphics::drawHeroInfoWin(const CGHeroInstance * curh) -{ - char * buf = new char[10]; - SDL_Surface * ret = SDL_DisplayFormat(hInfo); - blueToPlayersAdv(hInfo,curh->tempOwner,1); - SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); - printAt(curh->name,75,15,GEOR13,zwykly,ret); - drawPrimarySkill(curh, ret); - for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) - { - blitAt(LOCPLINT->graphics.smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); - itoa((*i).second.second,buf,10); - printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret); - } - blitAt(curh->type->portraitLarge,11,12,ret); - 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); - blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret); - //SDL_SaveBMP(ret,"inf1.bmp"); - return ret; -} - -SDL_Surface * CPlayerInterface::Graphics::drawTownInfoWin(const CGTownInstance * curh) -{ - char * buf = new char[10]; - blueToPlayersAdv(tInfo,curh->tempOwner,1); - SDL_Surface * ret = SDL_DisplayFormat(tInfo); - SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); - printAt(curh->name,75,15,GEOR13,zwykly,ret); - - int pom = curh->fortLevel() - 1; if(pom<0) pom = 3; - 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); - printAtMiddle(buf,167,70,GEORM,zwykly,ret); - for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) - { - if(!i->second.first) - continue; - blitAt(LOCPLINT->graphics.smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); - itoa((*i).second.second,buf,10); - printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret); - } - - //blit town icon - pom = curh->subID*2; - if (!curh->hasFort()) - pom += F_NUMBER*2; - if(curh->builded >= MAX_BUILDING_PER_TURN) - pom++; - blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret); - delete[] buf; - return ret; -} - void CPlayerInterface::openTownWindow(const CGTownInstance * town) { adventureInt->hide(); @@ -1677,10 +1554,10 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe switch (specific->ID) { case 34: - return graphics.drawHeroInfoWin(dynamic_cast(specific)); + return graphics->drawHeroInfoWin(dynamic_cast(specific)); break; case 98: - return graphics.drawTownInfoWin(dynamic_cast(specific)); + return graphics->drawTownInfoWin(dynamic_cast(specific)); break; default: return NULL; @@ -1694,11 +1571,11 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe case HEROI_TYPE: { const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected; - return graphics.drawHeroInfoWin(curh); + return graphics->drawHeroInfoWin(curh); } case TOWNI_TYPE: { - return graphics.drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected); + return graphics->drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected); } default: return NULL; @@ -1935,8 +1812,8 @@ int3 CPlayerInterface::repairScreenPos(int3 pos) } void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) { - SDL_FreeSurface(graphics.heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia - graphics.heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki. + SDL_FreeSurface(graphics->heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia + graphics->heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki. if (adventureInt->selection.selected == hero) adventureInt->infoBar.draw(); return; @@ -1977,8 +1854,8 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj) const CGHeroInstance * hh; if(hh = dynamic_cast(obj)) { - SDL_FreeSurface(graphics.heroWins[hh->subID]); - graphics.heroWins[hh->subID] = infoWin(hh); + SDL_FreeSurface(graphics->heroWins[hh->subID]); + graphics->heroWins[hh->subID] = infoWin(hh); } CHeroWindow * hw = dynamic_cast(curint); if(hw) @@ -1998,8 +1875,8 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj) const CGTownInstance * tt; if(tt = dynamic_cast(obj)) { - SDL_FreeSurface(graphics.townWins[tt->identifier]); - graphics.townWins[tt->identifier] = infoWin(tt); + SDL_FreeSurface(graphics->townWins[tt->identifier]); + graphics->townWins[tt->identifier] = infoWin(tt); } const CCastleInterface *ci = dynamic_cast(curint); @@ -2406,7 +2283,7 @@ void CHeroList::clickRight(tribool down) } //show popup - CInfoPopup * ip = new CInfoPopup(LOCPLINT->graphics.heroWins[items[from+ny].first->subID],LOCPLINT->current->motion.x-LOCPLINT->graphics.heroWins[items[from+ny].first->subID]->w,LOCPLINT->current->motion.y-LOCPLINT->graphics.heroWins[items[from+ny].first->subID]->h,false); + CInfoPopup * ip = new CInfoPopup(graphics->heroWins[items[from+ny].first->subID],LOCPLINT->current->motion.x-graphics->heroWins[items[from+ny].first->subID]->w,LOCPLINT->current->motion.y-graphics->heroWins[items[from+ny].first->subID]->h,false); ip->activate(); } else @@ -2459,7 +2336,7 @@ void CHeroList::draw() if (pom>25) pom=25; if (pom<0) pom=0; blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana - SDL_Surface * temp = LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->type->portraitSmall; + SDL_Surface * temp = graphics->portraitSmall[LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->subID]; blitAt(temp,posporx,pospory+i*32); if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE)) { @@ -2646,7 +2523,7 @@ void CTownList::clickRight(tribool down) } //show popup - CInfoPopup * ip = new CInfoPopup(LOCPLINT->graphics.townWins[items[from+ny]->identifier],LOCPLINT->current->motion.x-LOCPLINT->graphics.townWins[items[from+ny]->identifier]->w,LOCPLINT->current->motion.y-LOCPLINT->graphics.townWins[items[from+ny]->identifier]->h,false); + CInfoPopup * ip = new CInfoPopup(graphics->townWins[items[from+ny]->identifier],LOCPLINT->current->motion.x-graphics->townWins[items[from+ny]->identifier]->w,LOCPLINT->current->motion.y-graphics->townWins[items[from+ny]->identifier]->h,false); ip->activate(); } else @@ -2671,15 +2548,15 @@ void CTownList::draw() int i = iT-from; if (iT>=items.size()) { - blitAt(CGI->townh->getPic(-1),posporx,pospory+i*32); + blitAt(graphics->getPic(-1),posporx,pospory+i*32); continue; } - blitAt(CGI->townh->getPic(items[iT]->subID,items[iT]->hasFort(),items[iT]->builded),posporx,pospory+i*32); + blitAt(graphics->getPic(items[iT]->subID,items[iT]->hasFort(),items[iT]->builded),posporx,pospory+i*32); if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE)) { - blitAt(CGI->townh->getPic(-2),posporx,pospory+i*32); + blitAt(graphics->getPic(-2),posporx,pospory+i*32); } } if (from>0) @@ -2705,7 +2582,7 @@ CCreaturePic::~CCreaturePic() } int CCreaturePic::blitPic(SDL_Surface *to, int x, int y, bool nextFrame) { - blitAt(LOCPLINT->graphics.backgrounds[c->faction],x,y);//curx-50,pos.y+130-65); + blitAt(graphics->backgrounds[c->faction],x,y);//curx-50,pos.y+130-65); SDL_Rect dst = genRect(130,100,x,y); if(c->isDoubleWide()) x-=15; @@ -2804,8 +2681,8 @@ void CRecrutationWindow::show(SDL_Surface * to) int curx = pos.x+115-creatures[which].res.size()*16; for(int i=0;itownh->resources->ourImages[creatures[which].res[i].first].bitmap,curx,pos.y+243,screen); - blitAt(CGI->townh->resources->ourImages[creatures[which].res[i].first].bitmap,curx+258,pos.y+243,screen); + blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx,pos.y+243,screen); + blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx+258,pos.y+243,screen); itoa(creatures[which].res[i].second,pom,10); printAtMiddle(pom,curx+12,pos.y+286,GEOR13,zwykly,screen); itoa(creatures[which].res[i].second * slider->value,pom,10); @@ -3069,8 +2946,8 @@ CCreInfoWindow::CCreInfoWindow //luck and morale - blitAt(LOCPLINT->graphics.morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap); - blitAt(LOCPLINT->graphics.luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap); + blitAt(graphics->morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap); + blitAt(graphics->luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap); //print abilities text - if r-click popup if(type) diff --git a/CPlayerInterface.h b/CPlayerInterface.h index 5d6998a51..8097dd505 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -311,31 +311,6 @@ public: std::vector timeinterested; std::vector objsToBlit; - //various graphics - class Graphics - { - public: - //various graphics - SDL_Surface * hInfo, *tInfo; //hero and town infobox bgs - std::vector > slotsPos; //creature slot positions in infoboxes - CDefEssential *luck22, *luck30, *luck42, *luck82, - *morale22, *morale30, *morale42, *morale82, - *halls, *forts, *bigTownPic; - std::map heroWins; //hero_ID => infobox - std::map townWins; //town_ID => infobox - CDefHandler * artDefs; //artifacts - //creatures - std::map smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border - std::map bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border - std::map backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral - - //functions - Graphics(); - SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh); - SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS); - SDL_Surface * drawTownInfoWin(const CGTownInstance * curh); - } graphics; - //overloaded funcs from CGameInterface void yourTurn(); void heroMoved(const HeroMoveDetails & details); diff --git a/CPreGame.cpp b/CPreGame.cpp index 4c684ece6b844ea1aebac458280c1aa42796a974..e1445c26124dd9740b43f960fd5ad5d8643dce7c 100644 GIT binary patch delta 300 zcmZ4Yn*GXK_6d3H84Sq`84UW9C(4RXj$@YFn0JkNvKW()suEBqDVEIfS&C9^WzzK&yb0@zowcNa< W#EUVKHkJTQZGKz2{cS1Z!Fm8>d_c_r delta 60 zcmV-C0K@;(?FX*w2as-)jsga;u+RguxCBCMlS*|8lT3LIvkr021Cz>g6thfqZUK{? SaukzHbtHpKcehM;0f>Jrv>9Xo diff --git a/client/Graphics.cpp b/client/Graphics.cpp new file mode 100644 index 000000000..6bb2940ac --- /dev/null +++ b/client/Graphics.cpp @@ -0,0 +1,469 @@ +#include "../stdafx.h" +#include "Graphics.h" +#include "../hch/CDefHandler.h" +#include "../hch/CObjectHandler.h" +#include "../SDL_Extensions.h" +using namespace CSDL_Ext; +Graphics * graphics = NULL; +SDL_Surface * Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to) +{ + char * buf = new char[10]; + for (int i=from;iprimSkills[i],buf,10); + printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret); + } + delete[] buf; + return ret; +} +SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh) +{ + char * buf = new char[10]; + SDL_Surface * ret = SDL_DisplayFormat(hInfo); + blueToPlayersAdv(hInfo,curh->tempOwner,1); + SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); + printAt(curh->name,75,15,GEOR13,zwykly,ret); + drawPrimarySkill(curh, ret); + for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) + { + blitAt(graphics->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); + 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->subID],11,12,ret); + 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); + blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret); + //SDL_SaveBMP(ret,"inf1.bmp"); + return ret; +} +SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh) +{ + char * buf = new char[10]; + blueToPlayersAdv(tInfo,curh->tempOwner,1); + SDL_Surface * ret = SDL_DisplayFormat(tInfo); + SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); + printAt(curh->name,75,15,GEOR13,zwykly,ret); + + int pom = curh->fortLevel() - 1; if(pom<0) pom = 3; + 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); + printAtMiddle(buf,167,70,GEORM,zwykly,ret); + for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) + { + if(!i->second.first) + continue; + blitAt(graphics->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); + itoa((*i).second.second,buf,10); + printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret); + } + + //blit town icon + pom = curh->subID*2; + if (!curh->hasFort()) + pom += F_NUMBER*2; + if(curh->builded >= MAX_BUILDING_PER_TURN) + pom++; + blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret); + delete[] buf; + return ret; +} +Graphics::Graphics() +{ + artDefs = CDefHandler::giveDef("ARTIFACT.DEF"); + hInfo = BitmapHandler::loadBitmap("HEROQVBK.bmp"); + SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255)); + tInfo = BitmapHandler::loadBitmap("TOWNQVBK.bmp"); + SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->format,0,255,255)); + slotsPos.push_back(std::pair(44,82)); + slotsPos.push_back(std::pair(80,82)); + slotsPos.push_back(std::pair(116,82)); + slotsPos.push_back(std::pair(26,131)); + slotsPos.push_back(std::pair(62,131)); + slotsPos.push_back(std::pair(98,131)); + slotsPos.push_back(std::pair(134,131)); + + luck22 = CDefHandler::giveDefEss("ILCK22.DEF"); + luck30 = CDefHandler::giveDefEss("ILCK30.DEF"); + luck42 = CDefHandler::giveDefEss("ILCK42.DEF"); + luck82 = CDefHandler::giveDefEss("ILCK82.DEF"); + morale22 = CDefHandler::giveDefEss("IMRL22.DEF"); + morale30 = CDefHandler::giveDefEss("IMRL30.DEF"); + morale42 = CDefHandler::giveDefEss("IMRL42.DEF"); + morale82 = CDefHandler::giveDefEss("IMRL82.DEF"); + halls = CDefHandler::giveDefEss("ITMTLS.DEF"); + forts = CDefHandler::giveDefEss("ITMCLS.DEF"); + bigTownPic = CDefHandler::giveDefEss("ITPT.DEF"); + std::ifstream ifs; + ifs.open("config/cr_bgs.txt"); + while(!ifs.eof()) + { + int id; + std::string name; + ifs >> id >> name; + backgrounds[id]=BitmapHandler::loadBitmap(name); + } + ifs.close(); + ifs.clear(); + + //loading 32x32px imgs + CDefHandler *smi = CDefHandler::giveDef("CPRSMALL.DEF"); + smi->notFreeImgs = true; + for (int i=0; iourImages.size(); i++) + { + smallImgs[i-2] = smi->ourImages[i].bitmap; + } + delete smi; + smi = CDefHandler::giveDef("TWCRPORT.DEF"); + smi->notFreeImgs = true; + for (int i=0; iourImages.size(); i++) + { + bigImgs[i-2] = smi->ourImages[i].bitmap; + } + delete smi; + + std::ifstream of("config/portrety.txt"); + for (int j=0;j>ID; + std::string path; + of>>path; + portraitSmall.push_back(BitmapHandler::loadBitmap(path)); + //if (!heroes[ID]->portraitSmall) + // std::cout<<"Can't read small portrait for "<portraitLarge) + // std::cout<<"Can't read large portrait for "<format,0,255,255)); + + } + of.close(); + pskillsb = CDefHandler::giveDef("PSKILL.DEF"); + resources = CDefHandler::giveDef("RESOUR82.DEF"); + un44 = CDefHandler::giveDef("UN44.DEF"); + smallIcons = CDefHandler::giveDef("ITPA.DEF"); + resources32 = CDefHandler::giveDef("RESOURCE.DEF"); + loadHeroFlags(); +} +void Graphics::loadHeroFlags() +{ + flags1.push_back(CDefHandler::giveDef("ABF01L.DEF")); //red + flags1.push_back(CDefHandler::giveDef("ABF01G.DEF")); //blue + flags1.push_back(CDefHandler::giveDef("ABF01R.DEF")); //tan + flags1.push_back(CDefHandler::giveDef("ABF01D.DEF")); //green + flags1.push_back(CDefHandler::giveDef("ABF01B.DEF")); //orange + flags1.push_back(CDefHandler::giveDef("ABF01P.DEF")); //purple + flags1.push_back(CDefHandler::giveDef("ABF01W.DEF")); //teal + flags1.push_back(CDefHandler::giveDef("ABF01K.DEF")); //pink + + for(int q=0; q<8; ++q) + { + for(int o=0; oourImages.size(); ++o) + { + if(flags1[q]->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + flags1[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags1[q]->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); + nci.groupNumber = 11; + nci.imName = std::string(); + flags1[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags1[q]->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); + nci.groupNumber = 12; + nci.imName = std::string(); + flags1[q]->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int ff=0; ffourImages.size(); ++ff) + { + SDL_SetColorKey(flags1[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, + SDL_MapRGB(flags1[q]->ourImages[ff].bitmap->format, 0, 255, 255) + ); + } + flags1[q]->alphaTransformed = true; + } + + flags2.push_back(CDefHandler::giveDef("ABF02L.DEF")); //red + flags2.push_back(CDefHandler::giveDef("ABF02G.DEF")); //blue + flags2.push_back(CDefHandler::giveDef("ABF02R.DEF")); //tan + flags2.push_back(CDefHandler::giveDef("ABF02D.DEF")); //green + flags2.push_back(CDefHandler::giveDef("ABF02B.DEF")); //orange + flags2.push_back(CDefHandler::giveDef("ABF02P.DEF")); //purple + flags2.push_back(CDefHandler::giveDef("ABF02W.DEF")); //teal + flags2.push_back(CDefHandler::giveDef("ABF02K.DEF")); //pink + + for(int q=0; q<8; ++q) + { + for(int o=0; oourImages.size(); ++o) + { + if(flags2[q]->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + flags2[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags2[q]->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); + nci.groupNumber = 11; + nci.imName = std::string(); + flags2[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags2[q]->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); + nci.groupNumber = 12; + nci.imName = std::string(); + flags2[q]->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int ff=0; ffourImages.size(); ++ff) + { + SDL_SetColorKey(flags2[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, + SDL_MapRGB(flags2[q]->ourImages[ff].bitmap->format, 0, 255, 255) + ); + } + flags2[q]->alphaTransformed = true; + } + + flags3.push_back(CDefHandler::giveDef("ABF03L.DEF")); //red + flags3.push_back(CDefHandler::giveDef("ABF03G.DEF")); //blue + flags3.push_back(CDefHandler::giveDef("ABF03R.DEF")); //tan + flags3.push_back(CDefHandler::giveDef("ABF03D.DEF")); //green + flags3.push_back(CDefHandler::giveDef("ABF03B.DEF")); //orange + flags3.push_back(CDefHandler::giveDef("ABF03P.DEF")); //purple + flags3.push_back(CDefHandler::giveDef("ABF03W.DEF")); //teal + flags3.push_back(CDefHandler::giveDef("ABF03K.DEF")); //pink + + for(int q=0; q<8; ++q) + { + for(int o=0; oourImages.size(); ++o) + { + if(flags3[q]->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + flags3[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags3[q]->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); + nci.groupNumber = 11; + nci.imName = std::string(); + flags3[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags3[q]->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); + nci.groupNumber = 12; + nci.imName = std::string(); + flags3[q]->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int ff=0; ffourImages.size(); ++ff) + { + SDL_SetColorKey(flags3[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, + SDL_MapRGB(flags3[q]->ourImages[ff].bitmap->format, 0, 255, 255) + ); + } + flags3[q]->alphaTransformed = true; + } + + flags4.push_back(CDefHandler::giveDef("AF00.DEF")); //red + flags4.push_back(CDefHandler::giveDef("AF01.DEF")); //blue + flags4.push_back(CDefHandler::giveDef("AF02.DEF")); //tan + flags4.push_back(CDefHandler::giveDef("AF03.DEF")); //green + flags4.push_back(CDefHandler::giveDef("AF04.DEF")); //orange + flags4.push_back(CDefHandler::giveDef("AF05.DEF")); //purple + flags4.push_back(CDefHandler::giveDef("AF06.DEF")); //teal + flags4.push_back(CDefHandler::giveDef("AF07.DEF")); //pink + + + for(int q=0; q<8; ++q) + { + for(int o=0; oourImages.size(); ++o) + { + if(flags4[q]->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags4[q]->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.groupNumber = 11; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags4[q]->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.groupNumber = 12; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int o=0; oourImages.size(); ++o) + { + if(flags4[q]->ourImages[o].groupNumber==1) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.groupNumber = 13; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags4[q]->ourImages[o].groupNumber==2) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.groupNumber = 14; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags4[q]->ourImages[o].groupNumber==3) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.groupNumber = 15; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + } + + for(int ff=0; ffourImages.size(); ++ff) + { + SDL_SetColorKey(flags4[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, + SDL_MapRGB(flags4[q]->ourImages[ff].bitmap->format, 0, 255, 255) + ); + } + flags4[q]->alphaTransformed = true; + } +} +SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded) +{ + if (ID==-1) + return smallIcons->ourImages[0].bitmap; + else if (ID==-2) + return smallIcons->ourImages[1].bitmap; + else if (ID==-3) + return smallIcons->ourImages[2+F_NUMBER*4].bitmap; + else if (ID>F_NUMBER || ID<-3) + throw new std::exception("Invalid ID"); + else + { + int pom = 3; + if(!fort) + pom+=F_NUMBER*2; + pom += ID*2; + if (!builded) + pom--; + return smallIcons->ourImages[pom].bitmap; + } +} \ No newline at end of file diff --git a/client/Graphics.h b/client/Graphics.h new file mode 100644 index 000000000..eddc7b293 --- /dev/null +++ b/client/Graphics.h @@ -0,0 +1,40 @@ +#pragma once +#include "../global.h" +class CDefEssential; +struct SDL_Surface; +class CGHeroInstance; +class CGTownInstance; +class CDefHandler; +class Graphics +{ +public: + //various graphics + SDL_Surface * hInfo, *tInfo; //hero and town infobox bgs + std::vector > slotsPos; //creature slot positions in infoboxes + CDefEssential *luck22, *luck30, *luck42, *luck82, + *morale22, *morale30, *morale42, *morale82, + *halls, *forts, *bigTownPic; + std::map heroWins; //hero_ID => infobox + std::map townWins; //town_ID => infobox + CDefHandler * artDefs; //artifacts + std::vector portraitSmall; //48x32 px portraits of heroes + std::vector portraitLarge; //58x64 px portraits of heroes + std::vector flags1, flags2, flags3, flags4; //flags blitted on heroes when , + CDefHandler * pskillsb, *resources; //82x93 + CDefHandler * un44; //many things + CDefHandler * smallIcons, *resources32; //resources 32x32 + //creatures + std::map smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border + std::map bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border + std::map backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral + + //functions + Graphics(); + void loadHeroFlags(); + SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh); + SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS); + SDL_Surface * drawTownInfoWin(const CGTownInstance * curh); + SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //returns small picture of town: ID=-1 - blank; -2 - border; -3 - random +}; + +extern Graphics * graphics; \ No newline at end of file diff --git a/hch/CAbilityHandler.cpp b/hch/CAbilityHandler.cpp index b09aac533..2269c5a8c 100644 --- a/hch/CAbilityHandler.cpp +++ b/hch/CAbilityHandler.cpp @@ -12,15 +12,15 @@ void CAbilityHandler::loadAbilities() std::string dump; for(int i=0; i<2; ++i) { - CGeneralTextHandler::loadToIt(dump,buf,it,3); + loadToIt(dump,buf,it,3); } for (int i=0; iname,buf,it,4); - CGeneralTextHandler::loadToIt(nab->basicText,buf,it,4); - CGeneralTextHandler::loadToIt(nab->advText,buf,it,4); - CGeneralTextHandler::loadToIt(nab->expText,buf,it,3); + loadToIt(nab->name,buf,it,4); + loadToIt(nab->basicText,buf,it,4); + loadToIt(nab->advText,buf,it,4); + loadToIt(nab->expText,buf,it,3); nab->idNumber = abilities.size(); abilities.push_back(nab); } @@ -33,7 +33,7 @@ void CAbilityHandler::loadAbilities() for(int i=0; i<6; ++i) { std::string buffo; - CGeneralTextHandler::loadToIt(buffo,buf,it,3); + loadToIt(buffo,buf,it,3); levels.push_back(buffo); } } \ No newline at end of file diff --git a/hch/CArtHandler.cpp b/hch/CArtHandler.cpp index 1faa64fd6..23ed7e69c 100644 --- a/hch/CArtHandler.cpp +++ b/hch/CArtHandler.cpp @@ -1,144 +1,42 @@ +#define VCMI_DLL #include "../stdafx.h" #include "CArtHandler.h" -#include "../CGameInfo.h" -#include "CGeneralTextHandler.h" #include "CLodHandler.h" - +#include +#include +void loadToIt(std::string &dest, std::string &src, int &iter, int mode); +extern CLodHandler *bitmaph; +using namespace boost::assign; void CArtHandler::loadArtifacts() { - std::string buf = CGI->bitmaph->getTextFile("ARTRAITS.TXT"); + std::vector slots; + slots += &CArtifact::spellBook, &CArtifact::warMachine4, &CArtifact::warMachine3, &CArtifact::warMachine2, + &CArtifact::warMachine1, &CArtifact::misc5, &CArtifact::misc4, &CArtifact::misc3, &CArtifact::misc2, + &CArtifact::misc1, &CArtifact::feet, &CArtifact::lRing, &CArtifact::rRing, &CArtifact::torso, + &CArtifact::lHand, &CArtifact::rHand, &CArtifact::neck, &CArtifact::shoulders, &CArtifact::head; + std::map classes = + map_list_of('S',SartClass)('T',TartClass)('N',NartClass)('J',JartClass)('R',RartClass); + std::string buf = bitmaph->getTextFile("ARTRAITS.TXT"), dump, pom; int it=0; - std::string dump; for(int i=0; i<2; ++i) { - CGeneralTextHandler::loadToIt(dump,buf,it,3); + loadToIt(dump,buf,it,3); } for (int i=0; i #include enum EartClass {SartClass=0, TartClass, NartClass, JartClass, RartClass}; //artifact class (relict, treasure, strong, weak etc.) class CDefHandler; -class CArtifact //container for artifacts +class DLL_EXPORT CArtifact //container for artifacts { public: bool isAllowed; //true if we can use this artifact (map information) @@ -21,7 +21,7 @@ public: int id; }; -class CArtHandler //handles artifacts +class DLL_EXPORT CArtHandler //handles artifacts { public: std::vector treasures, minors, majors, relics; diff --git a/hch/CGeneralTextHandler.cpp b/hch/CGeneralTextHandler.cpp index 58cd563d6..71a68249c 100644 --- a/hch/CGeneralTextHandler.cpp +++ b/hch/CGeneralTextHandler.cpp @@ -28,7 +28,7 @@ void CGeneralTextHandler::load() while(itr #include - +DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode); class CGeneralTextHandler //Handles general texts { public: @@ -13,21 +13,6 @@ public: std::vector primarySkillNames; std::vector jktexts; std::vector heroscrn; - /*std::string cantAddManager, experienceLimitScenarioReached, heroExperienceInfo, perDay, or, somethingVanquished, lastTownLostInfo, heroesAbandonedYou, heroesAbandonedHim; - std::string couldNotSaveGame, errorOpeningFile, newgameUppercase, sureToDismissArmy, playersTurn, errorReceivingDataKeepTrying, somethingTheSomething, recruit, noRoomInGarrision, numberOFAdventuringHeroes, heroWithoutCreatures; - std::string videoQuality, itemCantBeTraded, sureDismissHero, selectSpellTarget, invalidTeleportDestination, teleportHere, castSomething, castSomethingOnSomething, sureRetreat, notEnoughGold, capturedEnemyArtifact, none; - std::string surrenderProposal, highMoraleNextAttack, lowMoraleFreeze, makeRoomInArmyForSomething, attackSomethingSomethingDamage, shootSomethingOneShootLeftSomethingDamage; - std::string campaignDescription, somethingIsActive, sessionName, userName, creature, creatures, badLuckOnSomething, goodLuckOnSomething, treasure, somethingSomethingsUnderAttack, town, hero, townScreen, cannotBuildBoat, requires, systemUppercase; - std::string worldMapHelp, sureEndTurnHeroMayMove, diggingArtifactWholeDay, noRoomForArtifact, heroUncoveredThe, diggingNothing, tryLookingOnLand, unchartedTerritory; - std::string month, week, day, enemyViewTip, pingInfo, sureToRestart, sureToStartNewGame, sureQuit, dimensionDoorFiled, chooseBonus, ping, pingSomething, pingEveryone, score, autosaveUppercase; - std::string startingHeroB, heroSpecialityB, associatedCreaturesB, townAlignmentB, errorSendingDataKeepTrying, tooFewPalyersForMultiGame, artifactBonusB, goldBonusB, resourceBonusB, randomBonusB; - std::string fiveHundredToOneThousand, armageddonDamages, woodOreBonus, randomlyChoosenArtifact, disruptingRayReducesDefence, goldStartingBonus, woodOreStartingBonus, randomStartingBonus; - std::string youEliminatedFormGame, scoreToHallOfFame, trySearchingOnClearGround, sendingData, receivingData, chaosMp2, randomHeroB, randomStartingHeroInfo, randomTownB, randomStartingTownInfo, somethingSurrendersInfo; - std::string heroesCDNotFound, autosaving, playerexitUppercase, statusWindowTip, border, somethingAbsorbsMana, somethingsAbsorbMana, unableChangeHeroesDirectory, unableFindHeoresDataFiles, victoryAchievementText; - std::string somethingsRiseFromDeath, somethingRisesFormDeath, somethingDiesUnderGaze, somethingsDieUnderGaze, somethingTakesDefensiveStance, somethingsTakeDefensiveStance, somethingExp, nearestTownOccupied, noAvailableTown, heroTooTiredSpell, townGateCannotBeUsed, youHaveNoHeroes, heroHasCastSpell; - std::string doYouWishToSaveSomethingsArmy, problemsWithInputDevices, problemsWithSound, problemsWithMouse, problemsWithWindows, abandonedShipyard, spellFailed, somethingPauses, somethingsPause, somethingLevelSomething, somethingStudiedMagic, learnsSpeced, andSpaced, fromSomethingSpaced;*/ - - static void loadToIt(std::string & dest, std::string & src, int & iter, int mode = 0); //mode 0 - dump to tab, dest to tab, dump to eol //mode 1 - dump to tab, src to eol //mode 2 - copy to tab, dump to eol //mode 3 - copy to eol //mode 4 - copy to tab void load(); }; diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index 6c4eac7f2..b1c9edce3 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -1,361 +1,34 @@ #include "../stdafx.h" #include "CHeroHandler.h" -#include "../CGameInfo.h" #include -#include "../CGameInfo.h" -#include "CGeneralTextHandler.h" #include "CLodHandler.h" -#include "CAbilityHandler.h" -#include "../SDL_Extensions.h" #include #include #include "CDefHandler.h" +extern CLodHandler * bitmaph; +void loadToIt(std::string &dest, std::string &src, int &iter, int mode); CHeroHandler::~CHeroHandler() -{ - for (int j=0;jportraitSmall) - SDL_FreeSurface(heroes[j]->portraitSmall); - delete heroes[j]; - } -} +{} void CHeroHandler::loadPortraits() { - std::ifstream of("config/portrety.txt"); - for (int j=0;j>ID; - std::string path; - of>>path; - heroes[ID]->portraitSmall=BitmapHandler::loadBitmap(path); - if (!heroes[ID]->portraitSmall) - std::cout<<"Can't read small portrait for "<portraitLarge=BitmapHandler::loadBitmap(path); - if (!heroes[ID]->portraitLarge) - std::cout<<"Can't read large portrait for "<portraitLarge,SDL_SRCCOLORKEY,SDL_MapRGB(heroes[ID]->portraitLarge->format,0,255,255)); - - } - of.close(); - pskillsb = CDefHandler::giveDef("PSKILL.DEF"); - resources = CDefHandler::giveDef("RESOUR82.DEF"); - un44 = CDefHandler::giveDef("UN44.DEF"); - - std::string strs = CGI->bitmaph->getTextFile("PRISKILL.TXT"); + std::string strs = bitmaph->getTextFile("PRISKILL.TXT"); int itr=0; for (int i=0; iourImages.size(); ++o) - { - if(flags1[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - flags1[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags1[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - flags1[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags1[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - flags1[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffourImages.size(); ++ff) - { - SDL_SetColorKey(flags1[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(flags1[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - flags1[q]->alphaTransformed = true; - } - - flags2.push_back(CDefHandler::giveDef("ABF02L.DEF")); //red - flags2.push_back(CDefHandler::giveDef("ABF02G.DEF")); //blue - flags2.push_back(CDefHandler::giveDef("ABF02R.DEF")); //tan - flags2.push_back(CDefHandler::giveDef("ABF02D.DEF")); //green - flags2.push_back(CDefHandler::giveDef("ABF02B.DEF")); //orange - flags2.push_back(CDefHandler::giveDef("ABF02P.DEF")); //purple - flags2.push_back(CDefHandler::giveDef("ABF02W.DEF")); //teal - flags2.push_back(CDefHandler::giveDef("ABF02K.DEF")); //pink - - for(int q=0; q<8; ++q) - { - for(int o=0; oourImages.size(); ++o) - { - if(flags2[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - flags2[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags2[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - flags2[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags2[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - flags2[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffourImages.size(); ++ff) - { - SDL_SetColorKey(flags2[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(flags2[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - flags2[q]->alphaTransformed = true; - } - - flags3.push_back(CDefHandler::giveDef("ABF03L.DEF")); //red - flags3.push_back(CDefHandler::giveDef("ABF03G.DEF")); //blue - flags3.push_back(CDefHandler::giveDef("ABF03R.DEF")); //tan - flags3.push_back(CDefHandler::giveDef("ABF03D.DEF")); //green - flags3.push_back(CDefHandler::giveDef("ABF03B.DEF")); //orange - flags3.push_back(CDefHandler::giveDef("ABF03P.DEF")); //purple - flags3.push_back(CDefHandler::giveDef("ABF03W.DEF")); //teal - flags3.push_back(CDefHandler::giveDef("ABF03K.DEF")); //pink - - for(int q=0; q<8; ++q) - { - for(int o=0; oourImages.size(); ++o) - { - if(flags3[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - flags3[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags3[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - flags3[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags3[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - flags3[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffourImages.size(); ++ff) - { - SDL_SetColorKey(flags3[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(flags3[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - flags3[q]->alphaTransformed = true; - } - - flags4.push_back(CDefHandler::giveDef("AF00.DEF")); //red - flags4.push_back(CDefHandler::giveDef("AF01.DEF")); //blue - flags4.push_back(CDefHandler::giveDef("AF02.DEF")); //tan - flags4.push_back(CDefHandler::giveDef("AF03.DEF")); //green - flags4.push_back(CDefHandler::giveDef("AF04.DEF")); //orange - flags4.push_back(CDefHandler::giveDef("AF05.DEF")); //purple - flags4.push_back(CDefHandler::giveDef("AF06.DEF")); //teal - flags4.push_back(CDefHandler::giveDef("AF07.DEF")); //pink - - - for(int q=0; q<8; ++q) - { - for(int o=0; oourImages.size(); ++o) - { - if(flags4[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags4[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 11; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags4[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 12; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int o=0; oourImages.size(); ++o) - { - if(flags4[q]->ourImages[o].groupNumber==1) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 13; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags4[q]->ourImages[o].groupNumber==2) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 14; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags4[q]->ourImages[o].groupNumber==3) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 15; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffourImages.size(); ++ff) - { - SDL_SetColorKey(flags4[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(flags4[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - flags4[q]->alphaTransformed = true; - } -} void CHeroHandler::loadHeroes() { int ID=0; - std::string buf = CGI->bitmaph->getTextFile("HOTRAITS.TXT"); + std::string buf = bitmaph->getTextFile("HOTRAITS.TXT"); int it=0; std::string dump; for(int i=0; i<2; ++i) { - CGeneralTextHandler::loadToIt(dump,buf,it,3); + loadToIt(dump,buf,it,3); } int numberOfCurrentClassHeroes = 0; @@ -395,15 +68,15 @@ void CHeroHandler::loadHeroes() } std::string pom ; - CGeneralTextHandler::loadToIt(nher->name,buf,it,4); + loadToIt(nher->name,buf,it,4); for(int x=0;x<3;x++) { - CGeneralTextHandler::loadToIt(pom,buf,it,4); + loadToIt(pom,buf,it,4); nher->lowStack[x] = atoi(pom.c_str()); - CGeneralTextHandler::loadToIt(pom,buf,it,4); + loadToIt(pom,buf,it,4); nher->highStack[x] = atoi(pom.c_str()); - CGeneralTextHandler::loadToIt(nher->refTypeStack[x],buf,it,(x==2) ? (3) : (4)); + loadToIt(nher->refTypeStack[x],buf,it,(x==2) ? (3) : (4)); int hlp = nher->refTypeStack[x].find_first_of(' ',0); if(hlp>=0) nher->refTypeStack[x].replace(hlp,1,""); @@ -436,34 +109,34 @@ void CHeroHandler::loadHeroes() } void CHeroHandler::loadSpecialAbilities() { - std::string buf = CGI->bitmaph->getTextFile("HEROSPEC.TXT"); + std::string buf = bitmaph->getTextFile("HEROSPEC.TXT"); int it=0; std::string dump; for(int i=0; i<2; ++i) { - CGeneralTextHandler::loadToIt(dump,buf,it,3); + loadToIt(dump,buf,it,3); } for (int i=0;ibonusName,buf,it,4); - CGeneralTextHandler::loadToIt(heroes[i]->shortBonus,buf,it,4); - CGeneralTextHandler::loadToIt(heroes[i]->longBonus,buf,it,3); + loadToIt(heroes[i]->bonusName,buf,it,4); + loadToIt(heroes[i]->shortBonus,buf,it,4); + loadToIt(heroes[i]->longBonus,buf,it,3); } } void CHeroHandler::loadBiographies() { - std::string buf = CGI->bitmaph->getTextFile("HEROBIOS.TXT"); + std::string buf = bitmaph->getTextFile("HEROBIOS.TXT"); int it=0; for (int i=0;ibiography,buf,it,3); + loadToIt(heroes[i]->biography,buf,it,3); } } void CHeroHandler::loadHeroClasses() { - std::string buf = CGI->bitmaph->getTextFile("HCTRAITS.TXT"); + std::string buf = bitmaph->getTextFile("HCTRAITS.TXT"); int andame = buf.size(); for(int y=0; yabilh->abilities.size(); ++dd) + for(int dd=0; dd #include -#include "CCreatureHandler.h" -#include "SDL.h" -#include "../int3.h" -#include "CAmbarCendamo.h" -#include "../CGameInterface.h" class CHeroClass; class CDefHandler; @@ -26,8 +21,6 @@ public: CHeroClass * heroClass; EHeroClasses heroType; //hero class //bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;} - SDL_Surface * portraitSmall; //48x32 px - SDL_Surface * portraitLarge; //58x64 px }; class CHeroClass @@ -48,9 +41,6 @@ class CHeroHandler public: std::vector heroes; //było nodrze std::vector heroClasses; - std::vector flags1, flags2, flags3, flags4; //flags blitted on heroes when , - CDefHandler * pskillsb, *resources; //82x93 - CDefHandler * un44; //many things std::vector pskillsn; std::vector expPerLevel; //expPerLEvel[i] is amount of exp needed to reach level i; if it is not in this vector, multiplicate last value by 1,2 to get next value unsigned int level(unsigned int experience); @@ -59,18 +49,9 @@ public: void loadSpecialAbilities(); void loadBiographies(); void loadHeroClasses(); - void loadPortraits(); //loads also imgs and names of primary skills - void loadHeroFlags(); + void loadPortraits(); //loads names of primary skills void initHeroClasses(); ~CHeroHandler(); void initTerrainCosts(); - - friend void CAmbarCendamo::deh3m(); - friend void initGameState(CGameInfo * cgi); - //friend class CConsoleHandler; - - //friend void CPlayerInterface::heroMoved(const HeroMoveDetails & details); //TODO: wywalic, wstretne!!! }; - - #endif //CHEROHANDLER_H \ No newline at end of file diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 478d279a9..b6d8b3115 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -1,16 +1,15 @@ #include "../stdafx.h" #include "CObjectHandler.h" -#include "../CGameInfo.h" -#include "CGeneralTextHandler.h" -#include "CLodHandler.h" -#include "CAmbarCendamo.h" -#include "../mapHandler.h" #include "CDefObjInfoHandler.h" -#include "../CLua.h" +#include "CDefHandler.h" +#include "../CGameInfo.h" +#include "CLodHandler.h" +#include "CDefObjInfoHandler.h" #include "CHeroHandler.h" #include #include "CTownHandler.h" #include "CArtHandler.h" +DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode); void CObjectHandler::loadObjects() { int ID=0; @@ -19,7 +18,7 @@ void CObjectHandler::loadObjects() while (it(temp,"")); } @@ -58,7 +57,7 @@ void CObjectHandler::loadObjects() int i=0; while (itisVisitable() && defInfo->isVisitable()) return false; - //if(defInfo->isOnDefList && !(cmp.defInfo->isOnDefList)) - // return true; - //if(cmp.defInfo->isOnDefList && !(defInfo->isOnDefList)) - // return false; if(this->pos.xheroClass->terrCosts[ttype]; switch(rdtype) { - case Eroad::dirtRoad: + case dirtRoad: ret*=0.75; break; - case Eroad::grazvelRoad: + case grazvelRoad: ret*=0.667; break; - case Eroad::cobblestoneRoad: + case cobblestoneRoad: ret*=0.5; break; } diff --git a/hch/CTownHandler.cpp b/hch/CTownHandler.cpp index 197d52722..91943cd43 100644 --- a/hch/CTownHandler.cpp +++ b/hch/CTownHandler.cpp @@ -1,24 +1,19 @@ +#define VCMI_DLL #include "../stdafx.h" #include "CTownHandler.h" -#include "../CGameInfo.h" #include "CLodHandler.h" #include -#include "CGeneralTextHandler.h" +extern CLodHandler * bitmaph; +void loadToIt(std::string &dest, std::string &src, int &iter, int mode); CTownHandler::CTownHandler() -{ - smallIcons = CDefHandler::giveDef("ITPA.DEF"); - resources = CDefHandler::giveDef("RESOURCE.DEF"); -} +{} CTownHandler::~CTownHandler() -{ - delete smallIcons; - //todo - delete structures info -} +{} void CTownHandler::loadNames() { std::istringstream ins, names; - ins.str(CGI->bitmaph->getTextFile("TOWNTYPE.TXT")); - names.str(CGI->bitmaph->getTextFile("TOWNNAME.TXT")); + ins.str(bitmaph->getTextFile("TOWNTYPE.TXT")); + names.str(bitmaph->getTextFile("TOWNNAME.TXT")); int si=0; char bufname[75]; while (!ins.eof()) @@ -40,21 +35,21 @@ void CTownHandler::loadNames() towns.push_back(town); } - std::string strs = CGI->bitmaph->getTextFile("TCOMMAND.TXT"); + std::string strs = bitmaph->getTextFile("TCOMMAND.TXT"); int itr=0; while(itrbitmaph->getTextFile("HALLINFO.TXT"); + strs = bitmaph->getTextFile("HALLINFO.TXT"); itr=0; while(itrourImages[0].bitmap; - else if (ID==-2) - return smallIcons->ourImages[1].bitmap; - else if (ID==-3) - return smallIcons->ourImages[2+F_NUMBER*4].bitmap; - else if (ID>F_NUMBER || ID<-3) - throw new std::exception("Invalid ID"); - else - { - int pom = 3; - if(!fort) - pom+=F_NUMBER*2; - pom += ID*2; - if (!builded) - pom--; - return smallIcons->ourImages[pom].bitmap; - } -} - -int CTownHandler::getTypeByDefName(std::string name) -{ - //TODO - return 0; -} - +} \ No newline at end of file diff --git a/hch/CTownHandler.h b/hch/CTownHandler.h index 58f5ebffc..7a9e675a5 100644 --- a/hch/CTownHandler.h +++ b/hch/CTownHandler.h @@ -1,12 +1,6 @@ #ifndef CTOWNHANDLER_H #define CTOWNHANDLER_H - -#include "CDefHandler.h" -#include "CCreatureHandler.h" -#include "SDL.h" -#include "../int3.h" -#include -#include +#include "../global.h" #include class CBuilding; class CSpell; @@ -24,7 +18,7 @@ public: int typeID; }; -struct Structure +struct DLL_EXPORT Structure { int ID; int3 pos; @@ -39,20 +33,17 @@ struct Structure } }; -class CTownHandler +class DLL_EXPORT CTownHandler { public: - CDefHandler * smallIcons, *resources; //resources 32x32 - CTownHandler(); - ~CTownHandler(); std::vector towns; std::vector tcommands, hcommands; - void loadNames(); - SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //ID=-1 - blank; -2 - border; -3 - random - static int getTypeByDefName(std::string name); - std::map > structures; // > std::map > > requirements; //requirements[town_id][structure_id] -> set of required buildings + + CTownHandler(); + ~CTownHandler(); + void loadNames(); }; #endif //CTOWNHANDLER_H \ No newline at end of file diff --git a/mapHandler.cpp b/mapHandler.cpp index f70d4b031..465fbfd1d 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -12,6 +12,7 @@ #include "hch\CHeroHandler.h" #include "hch\CTownHandler.h" #include "hch\CArtHandler.h" +#include "client\Graphics.h" #include #include extern SDL_Surface * screen; @@ -899,7 +900,7 @@ void CMapHandler::init() //if(h<0) h=pickHero(i); CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i); - nnn->defInfo->handler = CGI->heroh->flags1[0]; + nnn->defInfo->handler = graphics->flags1[0]; map->heroes.push_back(nnn); map->objects.push_back(nnn); } @@ -1045,7 +1046,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,su,&sr); pp.y+=imgVal*2-32; sr.y-=16; - SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr); + SDL_BlitSurface(graphics->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr); } else if(themp && themp->moveDir && themp->isStanding && themp->ID!=62) //last condition - this is not prison) { @@ -1074,7 +1075,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, bufr.h = 64; bufr.w = 96; if(bufr.x-extRect->x>-64) - SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+(heroAnim/4)%imgVal].bitmap, NULL, su, &bufr); + SDL_BlitSurface(graphics->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+(heroAnim/4)%imgVal].bitmap, NULL, su, &bufr); themp->flagPrinted = true; } } diff --git a/stdafx.h b/stdafx.h index 0f0b88fd8..c8c475414 100644 --- a/stdafx.h +++ b/stdafx.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include "global.h" From 300d540663d00ce14415aa6a9e08cac5a3597774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 14 Jun 2008 10:20:18 +0000 Subject: [PATCH 10/47] More changes / project files. --- CConsoleHandler.cpp | 2 +- CMT.cpp | 89 ++--- CPreGame.cpp | Bin 128724 -> 128732 bytes client/Graphics.cpp | 86 +++++ client/VCMI_client.vcproj | 715 ++++++++++++++++++++++++++++++++++++++ hch/CAmbarCendamo.cpp | 2 - hch/CHeroHandler.cpp | 87 +---- hch/CHeroHandler.h | 2 +- hch/CLodHandler.cpp | 26 +- hch/CLodHandler.h | 2 +- lib/VCMI_Lib.cpp | 120 +++++++ lib/VCMI_Lib.h | 58 ++++ lib/VCMI_lib.vcproj | 404 +++++++++++++++++++++ timeHandler.h | 2 +- 14 files changed, 1437 insertions(+), 158 deletions(-) create mode 100644 client/VCMI_client.vcproj create mode 100644 lib/VCMI_Lib.cpp create mode 100644 lib/VCMI_Lib.h create mode 100644 lib/VCMI_lib.vcproj diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index dac629a8b..a5b201b4b 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -41,7 +41,7 @@ int internalFunc(void * callback) boost::filesystem::create_directory("Extracted_txts"); std::cout<<"Command accepted. Opening .lod file...\t"; CLodHandler * txth = new CLodHandler; - txth->init(std::string("Data\\H3bitmap.lod")); + txth->init(std::string("Data\\H3bitmap.lod"),"Data"); std::cout<<"done.\nScanning .lod file\n"; int curp=0; std::string pattern = ".TXT"; diff --git a/CMT.cpp b/CMT.cpp index 3ec091365..944ab8d33 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -47,9 +47,6 @@ #include "CLua.h" #include "CAdvmapInterface.h" #include "CCastleInterface.h" -#include "boost/filesystem/operations.hpp" -#include -#include #include "client\Graphics.h" #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) # include @@ -333,9 +330,7 @@ int _tmain(int argc, _TCHAR* argv[]) //CBIKHandler cb; //cb.open("CSECRET.BIK"); - THC timeHandler tmh; - THC tmh.getDif(); - timeHandler pomtime;pomtime.getDif(); + THC timeHandler tmh, total, pomtime; int xx=0, yy=0, zz=0; srand ( time(NULL) ); std::vector Sprites; @@ -361,9 +356,7 @@ int _tmain(int argc, _TCHAR* argv[]) TTF_Init(); atexit(TTF_Quit); atexit(SDL_Quit); - //TNRB = TTF_OpenFont("Fonts\\tnrb.ttf",16); TNRB16 = TTF_OpenFont("Fonts\\tnrb.ttf",16); - //TNR = TTF_OpenFont("Fonts\\tnr.ttf",10); GEOR13 = TTF_OpenFont("Fonts\\georgia.ttf",13); GEOR16 = TTF_OpenFont("Fonts\\georgia.ttf",16); GEORXX = TTF_OpenFont("Fonts\\tnrb.ttf",22); @@ -383,60 +376,35 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->curh = new CCursorHandler; THC std::cout<<"Initializing screen, fonts and sound handling: "<spriteh = new CLodHandler; - cgi->spriteh->init(std::string("Data\\H3sprite.lod")); + CDefHandler::Spriteh = cgi->spriteh = new CLodHandler(); + cgi->spriteh->init("Data\\H3sprite.lod","Sprites"); BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler; - cgi->bitmaph->init(std::string("Data\\H3bitmap.lod")); + cgi->bitmaph->init("Data\\H3bitmap.lod","Data"); THC std::cout<<"Loading .lod files: "<bitmaph); THC std::cout<<"Initializing VCMI_Lib: "<status())) - { - std::string name = dir->path().leaf(); - std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper); - boost::algorithm::replace_all(name,".BMP",".PCX"); - Entry * e = cgi->bitmaph->entries.znajdz(name); - if(e) - { - e->offset = -1; - e->realSize = e->size = boost::filesystem::file_size(dir->path()); - } - } - } - if(boost::filesystem::exists("Sprites")) - { - for (boost::filesystem::directory_iterator dir("Sprites");dir!=enddir;dir++) - { - if(boost::filesystem::is_regular(dir->status())) - { - std::string name = dir->path().leaf(); - std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper); - boost::algorithm::replace_all(name,".BMP",".PCX"); - Entry * e = cgi->spriteh->entries.znajdz(name); - if(e) - { - e->offset = -1; - e->realSize = e->size = boost::filesystem::file_size(dir->path()); - } - } - } - } - else - std::cout<<"Warning: No sprites/ folder!"<curh->initCursor(); - cgi->curh->showGraphicCursor(); + //cgi->curh->initCursor(); + //cgi->curh->showGraphicCursor(); + pomtime.getDif(); cgi->screenh = new CScreenHandler; cgi->screenh->initScreen(); - + THC std::cout<<"\tScreen handler: "<townh = new CTownHandler; + cgi->townh->loadNames(); + THC std::cout<<"\tTown handler: "<loadAbilities(); + cgi->abilh = abilh; + THC std::cout<<"\tAbility handler: "<loadHeroes(); + heroh->loadPortraits(); + cgi->heroh = heroh; + THC std::cout<<"\tHero handler: "<townh = new CTownHandler; - cgi->townh->loadNames(); - CAbilityHandler * abilh = new CAbilityHandler; - abilh->loadAbilities(); - cgi->abilh = abilh; - CHeroHandler * heroh = new CHeroHandler; - heroh->loadHeroes(); - heroh->loadPortraits(); - cgi->heroh = heroh; cgi->generaltexth = new CGeneralTextHandler; cgi->generaltexth->load(); THC std::cout<<"Preparing more handlers: "<mush = mush; cgi->scenarioOps = cpg->runLoop(); - THC tmh.getDif(); - + THC tmh.getDif();pomtime.getDif(); CArtHandler * arth = new CArtHandler; arth->loadArtifacts(); cgi->arth = arth; diff --git a/CPreGame.cpp b/CPreGame.cpp index e1445c26124dd9740b43f960fd5ad5d8643dce7c..98676ebb7cf7bb02e47f5ef47d02903673900451 100644 GIT binary patch delta 27 jcmccemi^9K_6=n(rzdDLvM|Rmlr)#V++O;UF`gFyxl0TM delta 18 acmccfmi@|G_6=n(o9kX~uY1WD#|r>y`U)HX diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 6bb2940ac..41389a4d5 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -157,6 +157,92 @@ Graphics::Graphics() smallIcons = CDefHandler::giveDef("ITPA.DEF"); resources32 = CDefHandler::giveDef("RESOURCE.DEF"); loadHeroFlags(); + + + + //std::stringstream nm; + //nm<<"AH"; + //nm<moveAnim = CDefHandler::giveDef(nm.str()); + + //for(int o=0; omoveAnim->ourImages.size(); ++o) + //{ + // if(hc->moveAnim->ourImages[o].groupNumber==6) + // { + // for(int e=0; e<8; ++e) + // { + // Cimage nci; + // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); + // nci.groupNumber = 10; + // nci.imName = std::string(); + // hc->moveAnim->ourImages.push_back(nci); + // } + // o+=8; + // } + // if(hc->moveAnim->ourImages[o].groupNumber==7) + // { + // for(int e=0; e<8; ++e) + // { + // Cimage nci; + // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); + // nci.groupNumber = 11; + // nci.imName = std::string(); + // hc->moveAnim->ourImages.push_back(nci); + // } + // o+=8; + // } + // if(hc->moveAnim->ourImages[o].groupNumber==8) + // { + // for(int e=0; e<8; ++e) + // { + // Cimage nci; + // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); + // nci.groupNumber = 12; + // nci.imName = std::string(); + // hc->moveAnim->ourImages.push_back(nci); + // } + // o+=8; + // } + //} + //for(int o=0; omoveAnim->ourImages.size(); ++o) + //{ + // if(hc->moveAnim->ourImages[o].groupNumber==1) + // { + // Cimage nci; + // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o].bitmap); + // nci.groupNumber = 13; + // nci.imName = std::string(); + // hc->moveAnim->ourImages.push_back(nci); + // //o+=1; + // } + // if(hc->moveAnim->ourImages[o].groupNumber==2) + // { + // Cimage nci; + // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o].bitmap); + // nci.groupNumber = 14; + // nci.imName = std::string(); + // hc->moveAnim->ourImages.push_back(nci); + // //o+=1; + // } + // if(hc->moveAnim->ourImages[o].groupNumber==3) + // { + // Cimage nci; + // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o].bitmap); + // nci.groupNumber = 15; + // nci.imName = std::string(); + // hc->moveAnim->ourImages.push_back(nci); + // //o+=1; + // } + //} + + //for(int ff=0; ffmoveAnim->ourImages.size(); ++ff) + //{ + // CSDL_Ext::alphaTransform(hc->moveAnim->ourImages[ff].bitmap); + //} + //hc->moveAnim->alphaTransformed = true; } void Graphics::loadHeroFlags() { diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj new file mode 100644 index 000000000..b6dc3076f --- /dev/null +++ b/client/VCMI_client.vcproj @@ -0,0 +1,715 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index 9336674d4..6a2330dc3 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -3,10 +3,8 @@ #include "../CGameInfo.h" #include "CObjectHandler.h" #include "CDefObjInfoHandler.h" -#include "../SDL_Extensions.h" #include "../CGameState.h" #include "SDL.h" -#include "CDefHandler.h" #include "CCreatureHandler.h" #include #include diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index b1c9edce3..dd5e65572 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -1,10 +1,8 @@ +#define VCMI_DLL #include "../stdafx.h" #include "CHeroHandler.h" #include #include "CLodHandler.h" -#include -#include -#include "CDefHandler.h" extern CLodHandler * bitmaph; void loadToIt(std::string &dest, std::string &src, int &iter, int mode); CHeroHandler::~CHeroHandler() @@ -259,89 +257,6 @@ void CHeroHandler::loadHeroClasses() ++i; } ++i; - std::stringstream nm; - nm<<"AH"; - nm<moveAnim = CDefHandler::giveDef(nm.str()); - - for(int o=0; omoveAnim->ourImages.size(); ++o) - { - if(hc->moveAnim->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - hc->moveAnim->ourImages.push_back(nci); - } - o+=8; - } - if(hc->moveAnim->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - hc->moveAnim->ourImages.push_back(nci); - } - o+=8; - } - if(hc->moveAnim->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - hc->moveAnim->ourImages.push_back(nci); - } - o+=8; - } - } - for(int o=0; omoveAnim->ourImages.size(); ++o) - { - if(hc->moveAnim->ourImages[o].groupNumber==1) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o].bitmap); - nci.groupNumber = 13; - nci.imName = std::string(); - hc->moveAnim->ourImages.push_back(nci); - //o+=1; - } - if(hc->moveAnim->ourImages[o].groupNumber==2) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o].bitmap); - nci.groupNumber = 14; - nci.imName = std::string(); - hc->moveAnim->ourImages.push_back(nci); - //o+=1; - } - if(hc->moveAnim->ourImages[o].groupNumber==3) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o].bitmap); - nci.groupNumber = 15; - nci.imName = std::string(); - hc->moveAnim->ourImages.push_back(nci); - //o+=1; - } - } - - for(int ff=0; ffmoveAnim->ourImages.size(); ++ff) - { - CSDL_Ext::alphaTransform(hc->moveAnim->ourImages[ff].bitmap); - } - hc->moveAnim->alphaTransformed = true; heroClasses.push_back(hc); } } diff --git a/hch/CHeroHandler.h b/hch/CHeroHandler.h index 4084b44a9..fd353c5d7 100644 --- a/hch/CHeroHandler.h +++ b/hch/CHeroHandler.h @@ -36,7 +36,7 @@ public: CDefHandler * moveAnim; //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing }; -class CHeroHandler +class DLL_EXPORT CHeroHandler { public: std::vector heroes; //było nodrze diff --git a/hch/CLodHandler.cpp b/hch/CLodHandler.cpp index 3c000742e..89d105e0b 100644 --- a/hch/CLodHandler.cpp +++ b/hch/CLodHandler.cpp @@ -6,6 +6,9 @@ #include #include #include +#include "boost/filesystem/operations.hpp" +#include +#include DLL_EXPORT int readNormalNr (int pos, int bytCon, unsigned char * str) { int ret=0; @@ -335,7 +338,7 @@ int CLodHandler::readNormalNr (unsigned char* bufor, int bytCon, bool cyclic) return ret; } -void CLodHandler::init(std::string lodFile) +void CLodHandler::init(std::string lodFile, std::string dirName) { std::string Ts; FLOD = fopen(lodFile.c_str(), "rb"); @@ -380,6 +383,27 @@ void CLodHandler::init(std::string lodFile) } entries.push_back(entry); } + boost::filesystem::directory_iterator enddir; + if(boost::filesystem::exists(dirName)) + { + for (boost::filesystem::directory_iterator dir(dirName);dir!=enddir;dir++) + { + if(boost::filesystem::is_regular(dir->status())) + { + std::string name = dir->path().leaf(); + std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper); + boost::algorithm::replace_all(name,".BMP",".PCX"); + Entry * e = entries.znajdz(name); + if(e) + { + e->offset = -1; + e->realSize = e->size = boost::filesystem::file_size(dir->path()); + } + } + } + } + else + std::cout<<"Warning: No "+dirName+"/ folder!"< playerint; + //std::vector playerColors; + //SDL_Color neutralColor; + //StartInfo scenarioOps; +}; + +extern LibClasses * VLC; \ No newline at end of file diff --git a/lib/VCMI_lib.vcproj b/lib/VCMI_lib.vcproj new file mode 100644 index 000000000..63ab651e6 --- /dev/null +++ b/lib/VCMI_lib.vcproj @@ -0,0 +1,404 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/timeHandler.h b/timeHandler.h index 2331ac82d..74f4ee81f 100644 --- a/timeHandler.h +++ b/timeHandler.h @@ -6,7 +6,7 @@ class timeHandler { public: clock_t start, last, mem; - timeHandler():start(clock()){last=0;mem=0;}; + timeHandler():start(clock()){last=clock();mem=0;}; long getDif(){long ret=clock()-last;last=clock();return ret;}; void update(){last=clock();}; void remember(){mem=clock();}; From d5b0bdcf9efb6f372781a6978916f894cda8faf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 16 Jun 2008 10:51:14 +0000 Subject: [PATCH 11/47] A little threading and minor changes. --- CMT.cpp | 56 ++-- CPreGame.cpp | Bin 128732 -> 129722 bytes CPreGame.h | 1 + client/Graphics.cpp | 589 ++++++++++++++------------------------ client/Graphics.h | 3 + client/VCMI_client.vcproj | 2 +- hch/CLodHandler.cpp | 7 +- hch/CLodHandler.h | 4 +- hch/CObjectHandler.cpp | 3 +- lib/VCMI_lib.vcproj | 6 +- 10 files changed, 263 insertions(+), 408 deletions(-) diff --git a/CMT.cpp b/CMT.cpp index 944ab8d33..452590147 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -48,6 +48,7 @@ #include "CAdvmapInterface.h" #include "CCastleInterface.h" #include "client\Graphics.h" +#include #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) # include # include @@ -324,57 +325,43 @@ void initGameState(Mapa * map, CGameInfo * cgi) int _tmain(int argc, _TCHAR* argv[]) { - //std::ios_base::sync_with_stdio(0); + srand ( time(NULL) ); + CPG=NULL; + atexit(SDL_Quit); + CGameInfo * cgi = CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.) //CLuaHandler luatest; //luatest.test(); - //CBIKHandler cb; //cb.open("CSECRET.BIK"); + std::cout << "Starting... " << std::endl; THC timeHandler tmh, total, pomtime; - int xx=0, yy=0, zz=0; - srand ( time(NULL) ); - std::vector Sprites; if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO/*|SDL_INIT_EVENTTHREAD*/)==0) { - screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); - - //initializing important global surface -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - int rmask = 0xff000000; - int gmask = 0x00ff0000; - int bmask = 0x0000ff00; - int amask = 0x000000ff; -#else - int rmask = 0x000000ff; - int gmask = 0x0000ff00; - int bmask = 0x00ff0000; - int amask = 0xff000000; -#endif + screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface + THC std::cout<<"\tInitializing screen: "<initMusics(); //audio initialized - - - //screen2 = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); - //screen = SDL_ConvertSurface(screen2, screen2->format, SDL_SWSURFACE); - - SDL_WM_SetCaption(NAME,""); //set window title - CGameInfo * cgi = CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.) cgi->consoleh = new CConsoleHandler; cgi->mush = mush; cgi->curh = new CCursorHandler; - + THC std::cout<<"\tInitializing sound and cursor: "<spriteh = new CLodHandler(); cgi->spriteh->init("Data\\H3sprite.lod","Sprites"); @@ -403,7 +390,14 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->heroh = heroh; THC std::cout<<"\tHero handler: "< animacje; + for(std::vector::iterator i = cgi->heroh->heroClasses.begin();i!=cgi->heroh->heroClasses.end();i++) + animacje.push_back(&((*i)->*(&CHeroClass::moveAnim))); + graphics->loadHeroAnim(animacje); + THC std::cout<<"\tHero animations: "<1M zh-kQr=hFUwf|5l+bXVMT??yKwG?qk41^1r!CP}AOxeV{k%>6j$+n2XDJUWQi)=C7HE;ul%zR|;$DDFmCMG!1UcPiDMJsPE|pD}^=aV1WsJrsM@z_; zrWFd{zCz=&*APSAJf-ll2)l+d1)Qeb>lASj?8xrXl%tTKm4nL>Ki79IwHJUV z$5u7O9ko-P0Xl~~N{=F2wXnycQEfB4T#dU+pu9wB{&s%QlL1$&~uiUx@&B%?2@K=8A`h;<@q4!lFng;^alnj~tao0c6@TQ23w*CB-QHxZLnJY>ue?eU{~7SRbapsSfXh^wO52DN}z=zo7P zFKS=y9)-~TCgm5aS1Px+yM6smCijtEwIG3@EXmHp0J_6>VjHtVqJ9GmW7%*Zu)!WV(bCoV}$W~p=7Y;=Q9V)KJbD$LW5IWsCv zeso%F^0hO3(>KU4N=;sN)`c;1^82%z)3bgua!sGZ!zePj=$sL!HiI@pCJ0UrG*=V^ zvFsR37!1HrlR;s6;yOn0$=}XpF>5o}PWC=0J-P3Ej;ua|K2TvAg93vFLopae12x1l z*f1C|SWLcqK~}hmA%~$7D4)iV&rrmW%aF)WGWp~AnT(m6`!5(XPL?<)#j6FD&IBq< zWiXm-drq6Nc=}sqMsdd2$?^TNlN0{(Km;Tw&qxuF=L8xBRm%{~kOj2N7H&0=H(CCY zKEE@AFVLa_22X}Okj0Z1UY8V(2I`7s&_U9zIl1tXyfDHvYX)8hE(T79+UCR$+Y>)9 HMsfiF{5)%n diff --git a/CPreGame.h b/CPreGame.h index cce661198..26c865edb 100644 --- a/CPreGame.h +++ b/CPreGame.h @@ -203,6 +203,7 @@ public: void moveByOne(bool up); void printSelectedInfo(); void printFlags(); + void processMaps(std::vector &pliczkiTemp, int &index); MapSel(); ~MapSel(); }; diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 41389a4d5..8389644a4 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -2,7 +2,13 @@ #include "Graphics.h" #include "../hch/CDefHandler.h" #include "../hch/CObjectHandler.h" +//#include "../hch/CHeroHandler.h" #include "../SDL_Extensions.h" +#include +#include +#include +#include +#include using namespace CSDL_Ext; Graphics * graphics = NULL; SDL_Surface * Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to) @@ -157,380 +163,221 @@ Graphics::Graphics() smallIcons = CDefHandler::giveDef("ITPA.DEF"); resources32 = CDefHandler::giveDef("RESOURCE.DEF"); loadHeroFlags(); - - - - //std::stringstream nm; - //nm<<"AH"; - //nm<moveAnim = CDefHandler::giveDef(nm.str()); - - //for(int o=0; omoveAnim->ourImages.size(); ++o) - //{ - // if(hc->moveAnim->ourImages[o].groupNumber==6) - // { - // for(int e=0; e<8; ++e) - // { - // Cimage nci; - // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); - // nci.groupNumber = 10; - // nci.imName = std::string(); - // hc->moveAnim->ourImages.push_back(nci); - // } - // o+=8; - // } - // if(hc->moveAnim->ourImages[o].groupNumber==7) - // { - // for(int e=0; e<8; ++e) - // { - // Cimage nci; - // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); - // nci.groupNumber = 11; - // nci.imName = std::string(); - // hc->moveAnim->ourImages.push_back(nci); - // } - // o+=8; - // } - // if(hc->moveAnim->ourImages[o].groupNumber==8) - // { - // for(int e=0; e<8; ++e) - // { - // Cimage nci; - // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap); - // nci.groupNumber = 12; - // nci.imName = std::string(); - // hc->moveAnim->ourImages.push_back(nci); - // } - // o+=8; - // } - //} - //for(int o=0; omoveAnim->ourImages.size(); ++o) - //{ - // if(hc->moveAnim->ourImages[o].groupNumber==1) - // { - // Cimage nci; - // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o].bitmap); - // nci.groupNumber = 13; - // nci.imName = std::string(); - // hc->moveAnim->ourImages.push_back(nci); - // //o+=1; - // } - // if(hc->moveAnim->ourImages[o].groupNumber==2) - // { - // Cimage nci; - // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o].bitmap); - // nci.groupNumber = 14; - // nci.imName = std::string(); - // hc->moveAnim->ourImages.push_back(nci); - // //o+=1; - // } - // if(hc->moveAnim->ourImages[o].groupNumber==3) - // { - // Cimage nci; - // nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o].bitmap); - // nci.groupNumber = 15; - // nci.imName = std::string(); - // hc->moveAnim->ourImages.push_back(nci); - // //o+=1; - // } - //} - - //for(int ff=0; ffmoveAnim->ourImages.size(); ++ff) - //{ - // CSDL_Ext::alphaTransform(hc->moveAnim->ourImages[ff].bitmap); - //} - //hc->moveAnim->alphaTransformed = true; } +void Graphics::loadHeroAnim(std::vector & anims) +{ + for(int i=0; iourImages.size(); ++o) + { + if((*anims[i])->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + (*anims[i])->ourImages.push_back(nci); + } + o+=8; + } + if((*anims[i])->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o+e].bitmap); + nci.groupNumber = 11; + nci.imName = std::string(); + (*anims[i])->ourImages.push_back(nci); + } + o+=8; + } + if((*anims[i])->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o+e].bitmap); + nci.groupNumber = 12; + nci.imName = std::string(); + (*anims[i])->ourImages.push_back(nci); + } + o+=8; + } + } + for(int o=0; o<(*anims[i])->ourImages.size(); ++o) + { + if((*anims[i])->ourImages[o].groupNumber==1) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o].bitmap); + nci.groupNumber = 13; + nci.imName = std::string(); + (*anims[i])->ourImages.push_back(nci); + //o+=1; + } + if((*anims[i])->ourImages[o].groupNumber==2) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o].bitmap); + nci.groupNumber = 14; + nci.imName = std::string(); + (*anims[i])->ourImages.push_back(nci); + //o+=1; + } + if((*anims[i])->ourImages[o].groupNumber==3) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o].bitmap); + nci.groupNumber = 15; + nci.imName = std::string(); + (*anims[i])->ourImages.push_back(nci); + //o+=1; + } + } + + for(int ff=0; ff<(*anims[i])->ourImages.size(); ++ff) + { + CSDL_Ext::alphaTransform((*anims[i])->ourImages[ff].bitmap); + } + (*anims[i])->alphaTransformed = true; + } +} + +void Graphics::loadHeroFlags(std::pair Graphics::*, std::vector > &pr, bool mode) +{ + for(int i=0;i<8;i++) + (this->*pr.first).push_back(CDefHandler::giveDef(pr.second[i])); + + for(int q=0; q<8; ++q) + { + for(int o=0; o<(this->*pr.first)[q]->ourImages.size(); ++o) + { + if((this->*pr.first)[q]->ourImages[o].groupNumber==6) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((this->*pr.first)[q]->ourImages[o+e].bitmap); + nci.groupNumber = 10; + nci.imName = std::string(); + (this->*pr.first)[q]->ourImages.push_back(nci); + } + o+=8; + } + if((this->*pr.first)[q]->ourImages[o].groupNumber==7) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((this->*pr.first)[q]->ourImages[o+e].bitmap); + nci.groupNumber = 11; + nci.imName = std::string(); + (this->*pr.first)[q]->ourImages.push_back(nci); + } + o+=8; + } + if((this->*pr.first)[q]->ourImages[o].groupNumber==8) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((this->*pr.first)[q]->ourImages[o+e].bitmap); + nci.groupNumber = 12; + nci.imName = std::string(); + (this->*pr.first)[q]->ourImages.push_back(nci); + } + o+=8; + } + } + if (mode) + { + for(int o=0; oourImages.size(); ++o) + { + if(flags4[q]->ourImages[o].groupNumber==1) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 13; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags4[q]->ourImages[o].groupNumber==2) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 14; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + if(flags4[q]->ourImages[o].groupNumber==3) + { + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); + nci.groupNumber = 15; + nci.imName = std::string(); + flags4[q]->ourImages.push_back(nci); + } + o+=8; + } + } + } + for(int ff=0; ff<(this->*pr.first)[q]->ourImages.size(); ++ff) + { + SDL_SetColorKey((this->*pr.first)[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, + SDL_MapRGB((this->*pr.first)[q]->ourImages[ff].bitmap->format, 0, 255, 255) + ); + } + (this->*pr.first)[q]->alphaTransformed = true; + } +} + void Graphics::loadHeroFlags() { - flags1.push_back(CDefHandler::giveDef("ABF01L.DEF")); //red - flags1.push_back(CDefHandler::giveDef("ABF01G.DEF")); //blue - flags1.push_back(CDefHandler::giveDef("ABF01R.DEF")); //tan - flags1.push_back(CDefHandler::giveDef("ABF01D.DEF")); //green - flags1.push_back(CDefHandler::giveDef("ABF01B.DEF")); //orange - flags1.push_back(CDefHandler::giveDef("ABF01P.DEF")); //purple - flags1.push_back(CDefHandler::giveDef("ABF01W.DEF")); //teal - flags1.push_back(CDefHandler::giveDef("ABF01K.DEF")); //pink - - for(int q=0; q<8; ++q) - { - for(int o=0; oourImages.size(); ++o) - { - if(flags1[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - flags1[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags1[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - flags1[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags1[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - flags1[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffourImages.size(); ++ff) - { - SDL_SetColorKey(flags1[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(flags1[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - flags1[q]->alphaTransformed = true; - } - - flags2.push_back(CDefHandler::giveDef("ABF02L.DEF")); //red - flags2.push_back(CDefHandler::giveDef("ABF02G.DEF")); //blue - flags2.push_back(CDefHandler::giveDef("ABF02R.DEF")); //tan - flags2.push_back(CDefHandler::giveDef("ABF02D.DEF")); //green - flags2.push_back(CDefHandler::giveDef("ABF02B.DEF")); //orange - flags2.push_back(CDefHandler::giveDef("ABF02P.DEF")); //purple - flags2.push_back(CDefHandler::giveDef("ABF02W.DEF")); //teal - flags2.push_back(CDefHandler::giveDef("ABF02K.DEF")); //pink - - for(int q=0; q<8; ++q) - { - for(int o=0; oourImages.size(); ++o) - { - if(flags2[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - flags2[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags2[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - flags2[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags2[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - flags2[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffourImages.size(); ++ff) - { - SDL_SetColorKey(flags2[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(flags2[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - flags2[q]->alphaTransformed = true; - } - - flags3.push_back(CDefHandler::giveDef("ABF03L.DEF")); //red - flags3.push_back(CDefHandler::giveDef("ABF03G.DEF")); //blue - flags3.push_back(CDefHandler::giveDef("ABF03R.DEF")); //tan - flags3.push_back(CDefHandler::giveDef("ABF03D.DEF")); //green - flags3.push_back(CDefHandler::giveDef("ABF03B.DEF")); //orange - flags3.push_back(CDefHandler::giveDef("ABF03P.DEF")); //purple - flags3.push_back(CDefHandler::giveDef("ABF03W.DEF")); //teal - flags3.push_back(CDefHandler::giveDef("ABF03K.DEF")); //pink - - for(int q=0; q<8; ++q) - { - for(int o=0; oourImages.size(); ++o) - { - if(flags3[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - flags3[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags3[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - flags3[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags3[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - flags3[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffourImages.size(); ++ff) - { - SDL_SetColorKey(flags3[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(flags3[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - flags3[q]->alphaTransformed = true; - } - - flags4.push_back(CDefHandler::giveDef("AF00.DEF")); //red - flags4.push_back(CDefHandler::giveDef("AF01.DEF")); //blue - flags4.push_back(CDefHandler::giveDef("AF02.DEF")); //tan - flags4.push_back(CDefHandler::giveDef("AF03.DEF")); //green - flags4.push_back(CDefHandler::giveDef("AF04.DEF")); //orange - flags4.push_back(CDefHandler::giveDef("AF05.DEF")); //purple - flags4.push_back(CDefHandler::giveDef("AF06.DEF")); //teal - flags4.push_back(CDefHandler::giveDef("AF07.DEF")); //pink - - - for(int q=0; q<8; ++q) - { - for(int o=0; oourImages.size(); ++o) - { - if(flags4[q]->ourImages[o].groupNumber==6) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags4[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 11; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags4[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 12; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int o=0; oourImages.size(); ++o) - { - if(flags4[q]->ourImages[o].groupNumber==1) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 13; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags4[q]->ourImages[o].groupNumber==2) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 14; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - if(flags4[q]->ourImages[o].groupNumber==3) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.groupNumber = 15; - nci.imName = std::string(); - flags4[q]->ourImages.push_back(nci); - } - o+=8; - } - } - - for(int ff=0; ffourImages.size(); ++ff) - { - SDL_SetColorKey(flags4[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY, - SDL_MapRGB(flags4[q]->ourImages[ff].bitmap->format, 0, 255, 255) - ); - } - flags4[q]->alphaTransformed = true; - } + using namespace boost::assign; + timeHandler th; + std::vector Graphics::*point; + std::pair Graphics::*, std::vector > pr[4]; + pr[0].first = &Graphics::flags1; + pr[0].second+=("ABF01L.DEF"),("ABF01G.DEF"),("ABF01R.DEF"),("ABF01D.DEF"),("ABF01B.DEF"), + ("ABF01P.DEF"),("ABF01W.DEF"),("ABF01K.DEF"); + pr[1].first = &Graphics::flags2; + pr[1].second+=("ABF02L.DEF"),("ABF02G.DEF"),("ABF02R.DEF"),("ABF02D.DEF"),("ABF02B.DEF"), + ("ABF02P.DEF"),("ABF02W.DEF"),("ABF02K.DEF"); + pr[2].first = &Graphics::flags3; + pr[2].second+=("ABF03L.DEF"),("ABF03G.DEF"),("ABF03R.DEF"),("ABF03D.DEF"),("ABF03B.DEF"), + ("ABF03P.DEF"),("ABF03W.DEF"),("ABF03K.DEF"); + pr[3].first = &Graphics::flags4; + pr[3].second+=("AF00.DEF"),("AF01.DEF"),("AF02.DEF"),("AF03.DEF"),("AF04.DEF"), + ("AF05.DEF"),("AF06.DEF"),("AF07.DEF"); + boost::thread_group grupa; + grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[3]),true)); + grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[2]),false)); + grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[1]),false)); + grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[0]),false)); + grupa.join_all(); + std::cout << "Flagi: "< Graphics::*, std::vector > &pr, bool mode); + void loadHeroAnim(std::vector & anims); SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh); SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS); SDL_Surface * drawTownInfoWin(const CGTownInstance * curh); diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index b6dc3076f..c2250a898 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -121,7 +121,7 @@ AdditionalIncludeDirectories="G:\vcmt\repa\include" StringPooling="true" BasicRuntimeChecks="0" - RuntimeLibrary="3" + RuntimeLibrary="2" EnableFunctionLevelLinking="false" WarningLevel="3" DebugInformationFormat="3" diff --git a/hch/CLodHandler.cpp b/hch/CLodHandler.cpp index 89d105e0b..7335484b0 100644 --- a/hch/CLodHandler.cpp +++ b/hch/CLodHandler.cpp @@ -9,6 +9,7 @@ #include "boost/filesystem/operations.hpp" #include #include +#include DLL_EXPORT int readNormalNr (int pos, int bytCon, unsigned char * str) { int ret=0; @@ -34,6 +35,7 @@ unsigned char * CLodHandler::giveFile(std::string defName, int * length) return NULL; } if(length) *length = ourEntry->realSize; + mutex->lock(); fseek(FLOD, ourEntry->offset, 0); unsigned char * outp; if (ourEntry->offset<0) //file is in the sprites/ folder; no compression @@ -44,6 +46,7 @@ unsigned char * CLodHandler::giveFile(std::string defName, int * length) strcat(name,(char*)ourEntry->name); FILE * f = fopen(name,"rb"); int result = fread(outp,1,ourEntry->realSize,f); + mutex->unlock(); if(result<0) {std::cout<<"Error in file reading: "<realSize]; fread((char*)outp, 1, ourEntry->realSize, FLOD); + mutex->unlock(); return outp; } else //we will decompress file { outp = new unsigned char[ourEntry->size]; fread((char*)outp, 1, ourEntry->size, FLOD); - fseek(FLOD, 0, 0); + mutex->unlock(); unsigned char * decomp = NULL; int decRes = infs2(outp, ourEntry->size, ourEntry->realSize, decomp); delete[] outp; @@ -340,6 +344,7 @@ int CLodHandler::readNormalNr (unsigned char* bufor, int bytCon, bool cyclic) void CLodHandler::init(std::string lodFile, std::string dirName) { + mutex = new boost::mutex; std::string Ts; FLOD = fopen(lodFile.c_str(), "rb"); fseek(FLOD, 8, 0); diff --git a/hch/CLodHandler.h b/hch/CLodHandler.h index c61d334b5..e84645e4a 100644 --- a/hch/CLodHandler.h +++ b/hch/CLodHandler.h @@ -9,7 +9,8 @@ struct SDL_Surface; class CDefHandler; class CDefEssential; - +namespace boost +{class mutex;}; namespace NLoadHandlerHelp { const int dmHelp=0, dmNoExtractingMask=1; @@ -44,6 +45,7 @@ public: FILE* FLOD; nodrze entries; unsigned int totalFiles; + boost::mutex *mutex; int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index b6d8b3115..18e4733dc 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -326,7 +326,6 @@ CGTownInstance::CGTownInstance() builded=-1; destroyed=-1; garrisonHero=NULL; - //state->owner=-1; town=NULL; visitingHero = NULL; } @@ -335,7 +334,7 @@ CGObjectInstance::CGObjectInstance(): animPhaseShift(rand()%0xff) { //std::cout << "Tworze obiekt "< + + From 39887673297c87ea460d16fed152065ff1a134c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 16 Jun 2008 14:56:48 +0000 Subject: [PATCH 12/47] * BitmapHandler thread-safe * multi-threaded loading main graphics --- CThreadHelper.cpp | 35 +++++++++++++++ CThreadHelper.h | 38 +++++++++++++++++ client/CBitmapHandler.cpp | 12 +++++- client/CBitmapHandler.h | 2 +- client/Graphics.cpp | 89 +++++++++++++++++++++------------------ client/Graphics.h | 1 + client/VCMI_client.vcproj | 24 +++++++++++ hch/CLodHandler.cpp | 17 -------- 8 files changed, 156 insertions(+), 62 deletions(-) create mode 100644 CThreadHelper.cpp create mode 100644 CThreadHelper.h diff --git a/CThreadHelper.cpp b/CThreadHelper.cpp new file mode 100644 index 000000000..448f99c37 --- /dev/null +++ b/CThreadHelper.cpp @@ -0,0 +1,35 @@ +#include "CThreadHelper.h" +#include +#include +CThreadHelper::CThreadHelper(std::vector > *Tasks, int Threads) +{ + currentTask = 0; amount = Tasks->size(); + tasks = Tasks; + threads = Threads; +} +void CThreadHelper::run() +{ + boost::thread_group grupa; + for(int i=0;i= amount) + { + rtinm.unlock(); + break; + } + else + { + ++currentTask; + rtinm.unlock(); + (*tasks)[pom](); + } + } +} \ No newline at end of file diff --git a/CThreadHelper.h b/CThreadHelper.h new file mode 100644 index 000000000..61cd9e462 --- /dev/null +++ b/CThreadHelper.h @@ -0,0 +1,38 @@ +#include "global.h" +#include +#include +typedef boost::function Task; + +class CThreadHelper +{ + boost::mutex rtinm; + int currentTask, amount, threads; + std::vector *tasks; + + + void processTasks(); +public: + CThreadHelper(std::vector > *Tasks, int Threads); + void run(); +}; + +template inline void setData(T * data, boost::function func) +{ + *data = func(); +} + + +#define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \ + (boost::bind(&setData,&DESTINATION,FUNCTION_TO_GET)) +#define GET_SURFACE(SUR_DESTINATION, SUR_NAME) \ + (GET_DATA \ + (SDL_Surface*,SUR_DESTINATION,\ + boost::function(boost::bind(&BitmapHandler::loadBitmap,SUR_NAME,true)))) +#define GET_DEF(DESTINATION, DEF_NAME) \ + (GET_DATA \ + (CDefHandler*,DESTINATION,\ + boost::function(boost::bind(CDefHandler::giveDef,DEF_NAME,(CLodHandler*)NULL)))) +#define GET_DEF_ESS(DESTINATION, DEF_NAME) \ + (GET_DATA \ + (CDefEssential*,DESTINATION,\ + boost::function(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL)))) \ No newline at end of file diff --git a/client/CBitmapHandler.cpp b/client/CBitmapHandler.cpp index da5658106..b7b600729 100644 --- a/client/CBitmapHandler.cpp +++ b/client/CBitmapHandler.cpp @@ -5,6 +5,8 @@ #include "../hch/CDefHandler.h" #include "../hch/CLodHandler.h" #include +#include +boost::mutex bitmap_handler_mx; int readNormalNr (int pos, int bytCon, unsigned char * str); CLodHandler * BitmapHandler::bitmaph = NULL; void BMPHeader::print(std::ostream & out) @@ -253,7 +255,7 @@ SDL_Surface * CPCXConv::getSurface() return ret; } -SDL_Surface * BitmapHandler::loadBitmap(std::string fname) +SDL_Surface * BitmapHandler::loadBitmap(std::string fname, bool setKey) { if(!fname.size()) return NULL; @@ -309,16 +311,19 @@ SDL_Surface * BitmapHandler::loadBitmap(std::string fname) } } } + bitmap_handler_mx.lock(); fseek(bitmaph->FLOD, e->offset, 0); if (e->size==0) //file is not compressed { pcx = new unsigned char[e->realSize]; fread((char*)pcx, 1, e->realSize, bitmaph->FLOD); + bitmap_handler_mx.unlock(); } else { unsigned char * pcd = new unsigned char[e->size]; fread((char*)pcd, 1, e->size, bitmaph->FLOD); + bitmap_handler_mx.unlock(); int res=bitmaph->infs2(pcd,e->size,e->realSize,pcx); if(res!=0) { @@ -328,5 +333,8 @@ SDL_Surface * BitmapHandler::loadBitmap(std::string fname) } CPCXConv cp; cp.openPCX((char*)pcx,e->realSize); - return cp.getSurface(); + SDL_Surface * ret = cp.getSurface(); + if(setKey) + SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); + return ret; } \ No newline at end of file diff --git a/client/CBitmapHandler.h b/client/CBitmapHandler.h index 368679ae6..53114c138 100644 --- a/client/CBitmapHandler.h +++ b/client/CBitmapHandler.h @@ -35,5 +35,5 @@ public: namespace BitmapHandler { extern CLodHandler *bitmaph; - SDL_Surface * loadBitmap(std::string fname); + SDL_Surface * loadBitmap(std::string fname, bool setKey=false); }; \ No newline at end of file diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 8389644a4..1f491c6ad 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -8,7 +8,11 @@ #include #include #include +#include #include +#include +#include "../CThreadHelper.h" +using namespace boost::assign; using namespace CSDL_Ext; Graphics * graphics = NULL; SDL_Surface * Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to) @@ -80,11 +84,6 @@ SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh) } Graphics::Graphics() { - artDefs = CDefHandler::giveDef("ARTIFACT.DEF"); - hInfo = BitmapHandler::loadBitmap("HEROQVBK.bmp"); - SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255)); - tInfo = BitmapHandler::loadBitmap("TOWNQVBK.bmp"); - SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->format,0,255,255)); slotsPos.push_back(std::pair(44,82)); slotsPos.push_back(std::pair(80,82)); slotsPos.push_back(std::pair(116,82)); @@ -93,45 +92,61 @@ Graphics::Graphics() slotsPos.push_back(std::pair(98,131)); slotsPos.push_back(std::pair(134,131)); - luck22 = CDefHandler::giveDefEss("ILCK22.DEF"); - luck30 = CDefHandler::giveDefEss("ILCK30.DEF"); - luck42 = CDefHandler::giveDefEss("ILCK42.DEF"); - luck82 = CDefHandler::giveDefEss("ILCK82.DEF"); - morale22 = CDefHandler::giveDefEss("IMRL22.DEF"); - morale30 = CDefHandler::giveDefEss("IMRL30.DEF"); - morale42 = CDefHandler::giveDefEss("IMRL42.DEF"); - morale82 = CDefHandler::giveDefEss("IMRL82.DEF"); - halls = CDefHandler::giveDefEss("ITMTLS.DEF"); - forts = CDefHandler::giveDefEss("ITMCLS.DEF"); - bigTownPic = CDefHandler::giveDefEss("ITPT.DEF"); - std::ifstream ifs; - ifs.open("config/cr_bgs.txt"); + CDefHandler *smi, *smi2; + + std::vector tasks; //preparing list of graphics to load + tasks += boost::bind(&Graphics::loadHeroFlags,this); + tasks += boost::bind(&Graphics::loadHeroPortraits,this); + tasks += GET_SURFACE(hInfo,"HEROQVBK.bmp"); + tasks += GET_SURFACE(tInfo,"TOWNQVBK.bmp"); + tasks += GET_DEF(artDefs,"ARTIFACT.DEF"); + tasks += GET_DEF_ESS(forts,"ITMCLS.DEF"); + tasks += GET_DEF_ESS(luck22,"ILCK22.DEF"); + tasks += GET_DEF_ESS(luck30,"ILCK30.DEF"); + tasks += GET_DEF_ESS(luck42,"ILCK42.DEF"); + tasks += GET_DEF_ESS(luck82,"ILCK82.DEF"); + tasks += GET_DEF_ESS(morale22,"IMRL22.DEF"); + tasks += GET_DEF_ESS(morale30,"IMRL30.DEF"); + tasks += GET_DEF_ESS(morale42,"IMRL42.DEF"); + tasks += GET_DEF_ESS(morale82,"IMRL82.DEF"); + tasks += GET_DEF_ESS(halls,"ITMTLS.DEF"); + tasks += GET_DEF_ESS(bigTownPic,"ITPT.DEF"); + tasks += GET_DEF(pskillsb,"PSKILL.DEF"); + tasks += GET_DEF(resources,"RESOUR82.DEF"); + tasks += GET_DEF(un44,"UN44.DEF"); + tasks += GET_DEF(smallIcons,"ITPA.DEF"); + tasks += GET_DEF(resources32,"RESOURCE.DEF"); + tasks += GET_DEF(smi,"CPRSMALL.DEF"); + tasks += GET_DEF(smi2,"TWCRPORT.DEF"); + + std::ifstream ifs("config/cr_bgs.txt"); + int id; + std::string name; while(!ifs.eof()) { - int id; - std::string name; ifs >> id >> name; - backgrounds[id]=BitmapHandler::loadBitmap(name); + tasks += GET_SURFACE(backgrounds[id],name); } - ifs.close(); - ifs.clear(); - //loading 32x32px imgs - CDefHandler *smi = CDefHandler::giveDef("CPRSMALL.DEF"); + CThreadHelper th(&tasks,max(1,boost::thread::hardware_concurrency())); + th.run(); + + //handling 32x32px imgs smi->notFreeImgs = true; for (int i=0; iourImages.size(); i++) { smallImgs[i-2] = smi->ourImages[i].bitmap; } delete smi; - smi = CDefHandler::giveDef("TWCRPORT.DEF"); - smi->notFreeImgs = true; - for (int i=0; iourImages.size(); i++) + smi2->notFreeImgs = true; + for (int i=0; iourImages.size(); i++) { - bigImgs[i-2] = smi->ourImages[i].bitmap; + bigImgs[i-2] = smi2->ourImages[i].bitmap; } - delete smi; - + delete smi2; +} +void Graphics::loadHeroPortraits() +{ std::ifstream of("config/portrety.txt"); for (int j=0;j>path; portraitSmall.push_back(BitmapHandler::loadBitmap(path)); - //if (!heroes[ID]->portraitSmall) - // std::cout<<"Can't read small portrait for "<portraitLarge) - // std::cout<<"Can't read large portrait for "<format,0,255,255)); } of.close(); - pskillsb = CDefHandler::giveDef("PSKILL.DEF"); - resources = CDefHandler::giveDef("RESOUR82.DEF"); - un44 = CDefHandler::giveDef("UN44.DEF"); - smallIcons = CDefHandler::giveDef("ITPA.DEF"); - resources32 = CDefHandler::giveDef("RESOURCE.DEF"); - loadHeroFlags(); } void Graphics::loadHeroAnim(std::vector & anims) { @@ -377,7 +382,7 @@ void Graphics::loadHeroFlags() grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[1]),false)); grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[0]),false)); grupa.join_all(); - std::cout << "Flagi: "< Graphics::*, std::vector > &pr, bool mode); void loadHeroAnim(std::vector & anims); + void loadHeroPortraits(); SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh); SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS); SDL_Surface * drawTownInfoWin(const CGTownInstance * curh); diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index c2250a898..ac047bde2 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -376,6 +376,10 @@ RelativePath="..\hch\CSpellHandler.cpp" > + + @@ -558,6 +562,10 @@ RelativePath="..\hch\CAmbarCendamo.h" > + + @@ -586,6 +594,10 @@ RelativePath=".\CCreatureAnimation.h" > + + @@ -610,6 +622,10 @@ RelativePath="..\hch\CGeneralTextHandler.h" > + + @@ -630,6 +646,10 @@ RelativePath="..\hch\CMusicHandler.h" > + + @@ -658,6 +678,10 @@ RelativePath="..\hch\CSpellHandler.h" > + + diff --git a/hch/CLodHandler.cpp b/hch/CLodHandler.cpp index 7335484b0..4fed56801 100644 --- a/hch/CLodHandler.cpp +++ b/hch/CLodHandler.cpp @@ -176,12 +176,6 @@ DLL_EXPORT int CLodHandler::infs2(unsigned char * in, int size, int realSize, un } ++chunkNumber; strm.avail_in = readBytes; - //strm.avail_in = fread(inx, 1, NLoadHandlerHelp::fCHUNK, source); - /*if (in.bad()) - { - (void)inflateEnd(&strm); - return Z_ERRNO; - }*/ if (strm.avail_in == 0) break; strm.next_in = inx; @@ -203,22 +197,11 @@ DLL_EXPORT int CLodHandler::infs2(unsigned char * in, int size, int realSize, un return ret; } have = NLoadHandlerHelp::fCHUNK - strm.avail_out; - /*if (fwrite(out, 1, have, dest) != have || ferror(dest)) - { - (void)inflateEnd(&strm); - return Z_ERRNO; - }*/ - //out.write((char*)outx, have); for(int oo=0; oo Date: Tue, 17 Jun 2008 17:48:32 +0000 Subject: [PATCH 13/47] Moved objecthandler / minor --- CMT.cpp | 13 +--- client/Graphics.cpp | 135 +++++++++++--------------------------- client/VCMI_client.vcproj | 4 -- hch/CAmbarCendamo.cpp | 3 - hch/CArtHandler.cpp | 5 ++ hch/CArtHandler.h | 1 + hch/CCreatureHandler.cpp | 5 ++ hch/CCreatureHandler.h | 2 +- hch/CDefObjInfoHandler.h | 1 + hch/CHeroHandler.h | 4 +- hch/CMusicHandler.cpp | 84 ++++++++++++------------ hch/CObjectHandler.cpp | 33 +++++----- hch/CObjectHandler.h | 59 +++++++++-------- hch/CTownHandler.h | 2 +- lib/VCMI_Lib.h | 4 +- lib/VCMI_lib.vcproj | 8 +++ mapHandler.cpp | 21 ++++++ 17 files changed, 175 insertions(+), 209 deletions(-) diff --git a/CMT.cpp b/CMT.cpp index 452590147..5ad67663e 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -48,17 +48,6 @@ #include "CAdvmapInterface.h" #include "CCastleInterface.h" #include "client\Graphics.h" -#include -#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) -# include -# include -# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) -#else -# define SET_BINARY_MODE(file) -#endif -#ifdef _DEBUG -#endif -#define CHUNK 16384 const char * NAME = "VCMI \"Altanatse\" 0.7"; DLL_EXPORT void initDLL(CLodHandler *b); SDL_Color playerColorPalette[256]; //palette to make interface colors good @@ -214,6 +203,8 @@ void initGameState(Mapa * map, CGameInfo * cgi) for (int i=0;itowns.size();i++) { CGTownInstance * vti =(map->towns[i]); + if(!vti->town) + vti->town = &CGI->townh->towns[vti->subID]; if (vti->name.length()==0) // if town hasn't name we draw it vti->name=vti->town->names[rand()%vti->town->names.size()]; if(vti->builtBuildings.find(-50)!=vti->builtBuildings.end()) //give standard set of buildings diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 1f491c6ad..d628e65e3 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -171,6 +171,9 @@ void Graphics::loadHeroPortraits() } void Graphics::loadHeroAnim(std::vector & anims) { + std::vector > 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(int i=0; i & anims) nm<<"_.DEF"; std::string name = nm.str(); (*anims[i]) = CDefHandler::giveDef(name); - //(CDefHandler*)(((void*)hc)+((void*)moveAnim)) = CDefHandler::giveDef(name); - for(int o=0; o<(*anims[i])->ourImages.size(); ++o) + int pom = 0; //how many groups has been rotated + for(int o=7; pom<6; ++o) { - if((*anims[i])->ourImages[o].groupNumber==6) + for(int p=0;p<6;p++) { - for(int e=0; e<8; ++e) + if((*anims[i])->ourImages[o].groupNumber==rotations[p].first) { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - (*anims[i])->ourImages.push_back(nci); + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o+e].bitmap); + nci.groupNumber = rotations[p].second; + nci.imName = std::string(); + (*anims[i])->ourImages.push_back(nci); + if(pom>2) //we need only one frame for groups 13/14/15 + break; + } + if(pom<3) //there are eight frames of animtion of groups 6/7/8 so for speed we'll skip them + o+=8; + else //there is only one frame of 1/2/3 + o+=1; + ++pom; + if(p==2 && pom<4) //group1 starts at index 1 + o = 1; } - o+=8; - } - if((*anims[i])->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - (*anims[i])->ourImages.push_back(nci); - } - o+=8; - } - if((*anims[i])->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - (*anims[i])->ourImages.push_back(nci); - } - o+=8; } } - for(int o=0; o<(*anims[i])->ourImages.size(); ++o) - { - if((*anims[i])->ourImages[o].groupNumber==1) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o].bitmap); - nci.groupNumber = 13; - nci.imName = std::string(); - (*anims[i])->ourImages.push_back(nci); - //o+=1; - } - if((*anims[i])->ourImages[o].groupNumber==2) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o].bitmap); - nci.groupNumber = 14; - nci.imName = std::string(); - (*anims[i])->ourImages.push_back(nci); - //o+=1; - } - if((*anims[i])->ourImages[o].groupNumber==3) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01((*anims[i])->ourImages[o].bitmap); - nci.groupNumber = 15; - nci.imName = std::string(); - (*anims[i])->ourImages.push_back(nci); - //o+=1; - } - } - for(int ff=0; ff<(*anims[i])->ourImages.size(); ++ff) { CSDL_Ext::alphaTransform((*anims[i])->ourImages[ff].bitmap); @@ -264,46 +223,26 @@ void Graphics::loadHeroFlags(std::pair Graphics::*, s { for(int i=0;i<8;i++) (this->*pr.first).push_back(CDefHandler::giveDef(pr.second[i])); - + std::vector > 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); for(int q=0; q<8; ++q) { for(int o=0; o<(this->*pr.first)[q]->ourImages.size(); ++o) { - if((this->*pr.first)[q]->ourImages[o].groupNumber==6) + for(int p=0;p*pr.first)[q]->ourImages[o].groupNumber==rotations[p].first) { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01((this->*pr.first)[q]->ourImages[o+e].bitmap); - nci.groupNumber = 10; - nci.imName = std::string(); - (this->*pr.first)[q]->ourImages.push_back(nci); + for(int e=0; e<8; ++e) + { + Cimage nci; + nci.bitmap = CSDL_Ext::rotate01((this->*pr.first)[q]->ourImages[o+e].bitmap); + nci.groupNumber = rotations[p].second; + nci.imName = std::string(); + (this->*pr.first)[q]->ourImages.push_back(nci); + } + o+=8; } - o+=8; - } - if((this->*pr.first)[q]->ourImages[o].groupNumber==7) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01((this->*pr.first)[q]->ourImages[o+e].bitmap); - nci.groupNumber = 11; - nci.imName = std::string(); - (this->*pr.first)[q]->ourImages.push_back(nci); - } - o+=8; - } - if((this->*pr.first)[q]->ourImages[o].groupNumber==8) - { - for(int e=0; e<8; ++e) - { - Cimage nci; - nci.bitmap = CSDL_Ext::rotate01((this->*pr.first)[q]->ourImages[o+e].bitmap); - nci.groupNumber = 12; - nci.imName = std::string(); - (this->*pr.first)[q]->ourImages.push_back(nci); - } - o+=8; } } if (mode) diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index ac047bde2..a202c5dd7 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -344,10 +344,6 @@ RelativePath="..\hch\CMusicHandler.cpp" > - - diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index 6a2330dc3..baadf3500 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -3,9 +3,6 @@ #include "../CGameInfo.h" #include "CObjectHandler.h" #include "CDefObjInfoHandler.h" -#include "../CGameState.h" -#include "SDL.h" -#include "CCreatureHandler.h" #include #include #include diff --git a/hch/CArtHandler.cpp b/hch/CArtHandler.cpp index 23ed7e69c..06c989ed2 100644 --- a/hch/CArtHandler.cpp +++ b/hch/CArtHandler.cpp @@ -4,9 +4,14 @@ #include "CLodHandler.h" #include #include +#include "../lib/VCMI_Lib.h" void loadToIt(std::string &dest, std::string &src, int &iter, int mode); extern CLodHandler *bitmaph; using namespace boost::assign; +CArtHandler::CArtHandler() +{ + VLC->arth = this; +} void CArtHandler::loadArtifacts() { std::vector slots; diff --git a/hch/CArtHandler.h b/hch/CArtHandler.h index 30ae6d483..862e55d24 100644 --- a/hch/CArtHandler.h +++ b/hch/CArtHandler.h @@ -28,6 +28,7 @@ public: std::vector artifacts; void loadArtifacts(); bool loadArtEvents(); + CArtHandler(); }; #endif // CARTHANDLER_H \ No newline at end of file diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index e62f71e7a..2a45a811a 100644 --- a/hch/CCreatureHandler.cpp +++ b/hch/CCreatureHandler.cpp @@ -7,7 +7,12 @@ #include #include #include +#include "../lib/VCMI_Lib.h" extern CLodHandler * bitmaph; +CCreatureHandler::CCreatureHandler() +{ + VLC->creh = this; +} int CCreature::getQuantityID(int quantity) { if (quantity<5) diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index c1e99afc0..82fbbf0c0 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -61,6 +61,6 @@ public: void loadCreatures(); void loadAnimationInfo(); void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i); - CCreatureHandler(){}; + CCreatureHandler(); }; #endif //CCREATUREHANDLER_H \ No newline at end of file diff --git a/hch/CDefObjInfoHandler.h b/hch/CDefObjInfoHandler.h index bdca4bcfd..e45ccab21 100644 --- a/hch/CDefObjInfoHandler.h +++ b/hch/CDefObjInfoHandler.h @@ -16,6 +16,7 @@ public: int id, subid; //of object described by this defInfo int terrainAllowed, //on which terrain it is possible to place object terrainMenu; //in which menus in map editor object will be showed + int width, height; //tiles int type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources) CDefHandler * handler; int printPriority; diff --git a/hch/CHeroHandler.h b/hch/CHeroHandler.h index fd353c5d7..ff6ffb873 100644 --- a/hch/CHeroHandler.h +++ b/hch/CHeroHandler.h @@ -8,7 +8,7 @@ class CHeroClass; class CDefHandler; class CGameInfo; class CGHeroInstance; -class CHero +class DLL_EXPORT CHero { public: std::string name; @@ -23,7 +23,7 @@ public: //bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;} }; -class CHeroClass +class DLL_EXPORT CHeroClass { public: std::string name; diff --git a/hch/CMusicHandler.cpp b/hch/CMusicHandler.cpp index 16a45f0d6..03dbfdf2a 100644 --- a/hch/CMusicHandler.cpp +++ b/hch/CMusicHandler.cpp @@ -12,48 +12,48 @@ void CMusicHandler::initMusics() } atexit(Mix_CloseAudio); - AITheme0 = Mix_LoadMUS("MP3\\AITheme0.mp3"); - AITheme1 = Mix_LoadMUS("MP3\\AITHEME1.mp3"); - AITheme2 = Mix_LoadMUS("MP3\\AITHEME2.mp3"); - buildTown = Mix_LoadWAV("MP3\\BUILDTWN.wav"); - combat1 = Mix_LoadMUS("MP3\\COMBAT01.mp3"); - combat2 = Mix_LoadMUS("MP3\\COMBAT02.mp3"); - combat3 = Mix_LoadMUS("MP3\\COMBAT03.mp3"); - combat4 = Mix_LoadMUS("MP3\\COMBAT04.mp3"); - castleTown = Mix_LoadMUS("MP3\\CstleTown.mp3"); - defendCastle = Mix_LoadMUS("MP3\\Defend Castle.mp3"); - dirt = Mix_LoadMUS("MP3\\DIRT.mp3"); - dungeon = Mix_LoadMUS("MP3\\DUNGEON.mp3"); - elemTown = Mix_LoadMUS("MP3\\ElemTown.mp3"); - evilTheme = Mix_LoadMUS("MP3\\EvilTheme.mp3"); - fortressTown = Mix_LoadMUS("MP3\\FortressTown.mp3"); - goodTheme = Mix_LoadMUS("MP3\\GoodTheme.mp3"); - grass = Mix_LoadMUS("MP3\\GRASS.mp3"); - infernoTown = Mix_LoadMUS("MP3\\InfernoTown.mp3"); - lava = Mix_LoadMUS("MP3\\LAVA.mp3"); - loopLepr = Mix_LoadMUS("MP3\\LoopLepr.mp3"); - loseCampain = Mix_LoadMUS("MP3\\Lose Campain.mp3"); - loseCastle = Mix_LoadMUS("MP3\\LoseCastle.mp3"); - loseCombat = Mix_LoadMUS("MP3\\LoseCombat.mp3"); - mainMenu = Mix_LoadMUS("MP3\\MAINMENU.mp3"); - mainMenuWoG = Mix_LoadMUS("MP3\\MainMenuWoG.mp3"); - necroTown = Mix_LoadMUS("MP3\\necroTown.mp3"); - neutralTheme = Mix_LoadMUS("MP3\\NeutralTheme.mp3"); - rampart = Mix_LoadMUS("MP3\\RAMPART.mp3"); - retreatBattle = Mix_LoadMUS("MP3\\Retreat Battle.mp3"); - rough = Mix_LoadMUS("MP3\\ROUGH.mp3"); - sand = Mix_LoadMUS("MP3\\SAND.mp3"); - secretTheme = Mix_LoadMUS("MP3\\SecretTheme.mp3"); - snow = Mix_LoadMUS("MP3\\SNOW.mp3"); - stronghold = Mix_LoadMUS("MP3\\StrongHold.mp3"); - surrenderBattle = Mix_LoadMUS("MP3\\Surrender Battle.mp3"); - swamp = Mix_LoadMUS("MP3\\SWAMP.mp3"); - towerTown = Mix_LoadMUS("MP3\\TowerTown.mp3"); - ultimateLose = Mix_LoadMUS("MP3\\UltimateLose.mp3"); - underground = Mix_LoadMUS("MP3\\Underground.mp3"); - water = Mix_LoadMUS("MP3\\WATER.mp3"); - winBattle = Mix_LoadMUS("MP3\\Win Battle.mp3"); - winScenario = Mix_LoadMUS("MP3\\Win Scenario.mp3"); + //AITheme0 = Mix_LoadMUS("MP3\\AITheme0.mp3"); + //AITheme1 = Mix_LoadMUS("MP3\\AITHEME1.mp3"); + //AITheme2 = Mix_LoadMUS("MP3\\AITHEME2.mp3"); + //buildTown = Mix_LoadWAV("MP3\\BUILDTWN.wav"); + //combat1 = Mix_LoadMUS("MP3\\COMBAT01.mp3"); + //combat2 = Mix_LoadMUS("MP3\\COMBAT02.mp3"); + //combat3 = Mix_LoadMUS("MP3\\COMBAT03.mp3"); + //combat4 = Mix_LoadMUS("MP3\\COMBAT04.mp3"); + //castleTown = Mix_LoadMUS("MP3\\CstleTown.mp3"); + //defendCastle = Mix_LoadMUS("MP3\\Defend Castle.mp3"); + //dirt = Mix_LoadMUS("MP3\\DIRT.mp3"); + //dungeon = Mix_LoadMUS("MP3\\DUNGEON.mp3"); + //elemTown = Mix_LoadMUS("MP3\\ElemTown.mp3"); + //evilTheme = Mix_LoadMUS("MP3\\EvilTheme.mp3"); + //fortressTown = Mix_LoadMUS("MP3\\FortressTown.mp3"); + //goodTheme = Mix_LoadMUS("MP3\\GoodTheme.mp3"); + //grass = Mix_LoadMUS("MP3\\GRASS.mp3"); + //infernoTown = Mix_LoadMUS("MP3\\InfernoTown.mp3"); + //lava = Mix_LoadMUS("MP3\\LAVA.mp3"); + //loopLepr = Mix_LoadMUS("MP3\\LoopLepr.mp3"); + //loseCampain = Mix_LoadMUS("MP3\\Lose Campain.mp3"); + //loseCastle = Mix_LoadMUS("MP3\\LoseCastle.mp3"); + //loseCombat = Mix_LoadMUS("MP3\\LoseCombat.mp3"); + //mainMenu = Mix_LoadMUS("MP3\\MAINMENU.mp3"); + //mainMenuWoG = Mix_LoadMUS("MP3\\MainMenuWoG.mp3"); + //necroTown = Mix_LoadMUS("MP3\\necroTown.mp3"); + //neutralTheme = Mix_LoadMUS("MP3\\NeutralTheme.mp3"); + //rampart = Mix_LoadMUS("MP3\\RAMPART.mp3"); + //retreatBattle = Mix_LoadMUS("MP3\\Retreat Battle.mp3"); + //rough = Mix_LoadMUS("MP3\\ROUGH.mp3"); + //sand = Mix_LoadMUS("MP3\\SAND.mp3"); + //secretTheme = Mix_LoadMUS("MP3\\SecretTheme.mp3"); + //snow = Mix_LoadMUS("MP3\\SNOW.mp3"); + //stronghold = Mix_LoadMUS("MP3\\StrongHold.mp3"); + //surrenderBattle = Mix_LoadMUS("MP3\\Surrender Battle.mp3"); + //swamp = Mix_LoadMUS("MP3\\SWAMP.mp3"); + //towerTown = Mix_LoadMUS("MP3\\TowerTown.mp3"); + //ultimateLose = Mix_LoadMUS("MP3\\UltimateLose.mp3"); + //underground = Mix_LoadMUS("MP3\\Underground.mp3"); + //water = Mix_LoadMUS("MP3\\WATER.mp3"); + //winBattle = Mix_LoadMUS("MP3\\Win Battle.mp3"); + //winScenario = Mix_LoadMUS("MP3\\Win Scenario.mp3"); click = Mix_LoadWAV("MP3\\snd1.wav"); click->volume = 30; diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 18e4733dc..c1b29519c 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -1,19 +1,20 @@ +#define VCMI_DLL #include "../stdafx.h" #include "CObjectHandler.h" #include "CDefObjInfoHandler.h" -#include "CDefHandler.h" -#include "../CGameInfo.h" #include "CLodHandler.h" #include "CDefObjInfoHandler.h" #include "CHeroHandler.h" #include #include "CTownHandler.h" #include "CArtHandler.h" +#include "../lib/VCMI_Lib.h" DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode); +extern CLodHandler * bitmaph; void CObjectHandler::loadObjects() { int ID=0; - std::string buf = CGI->bitmaph->getTextFile("OBJNAMES.TXT"); + std::string buf = bitmaph->getTextFile("OBJNAMES.TXT"); int it=0; while (itbitmaph->getTextFile("ADVEVENT.TXT"); + buf = bitmaph->getTextFile("ADVEVENT.TXT"); it=0; std::string temp; while (itbitmaph->getTextFile("XTRAINFO.TXT"); + buf = bitmaph->getTextFile("XTRAINFO.TXT"); it=0; while (itbitmaph->getTextFile("MINENAME.TXT"); + buf = bitmaph->getTextFile("MINENAME.TXT"); it=0; while (it(temp,"")); } - buf = CGI->bitmaph->getTextFile("MINEEVNT.TXT"); + buf = bitmaph->getTextFile("MINEEVNT.TXT"); it=0; int i=0; while (itbitmaph->getTextFile("RESTYPES.TXT"); + buf = bitmaph->getTextFile("RESTYPES.TXT"); it=0; while (itbitmaph->getTextFile("ZCRGN1.TXT"); + buf = bitmaph->getTextFile("ZCRGN1.TXT"); it=0; while (ithandler->ourImages[0].bitmap->w/32; + return defInfo->width; } int CGObjectInstance::getHeight() const //returns height of object graphic in tiles { - return defInfo->handler->ourImages[0].bitmap->h/32; + return defInfo->width; } bool CGObjectInstance::visitableAt(int x, int y) const //returns true if ibject is visitable at location (x, y) form left top tile of image (x, y in tiles) { @@ -238,7 +239,7 @@ int CGHeroInstance::getSecSkillLevel(const int & ID) const const CArtifact * CGHeroInstance::getArt(int pos) { if(artifWorn.find(pos)!=artifWorn.end()) - return &CGI->arth->artifacts[artifWorn[pos]]; + return &VLC->arth->artifacts[artifWorn[pos]]; else return NULL; } @@ -279,7 +280,7 @@ int CGTownInstance::getHordeLevel(const int & HID) const//HID - 0 or 1; returns } int CGTownInstance::creatureGrowth(const int & level) const { - int ret = CGI->creh->creatures[town->basicCreatures[level]].growth; + int ret = VLC->creh->creatures[town->basicCreatures[level]].growth; switch(fortLevel()) { case 3: @@ -288,13 +289,13 @@ int CGTownInstance::creatureGrowth(const int & level) const ret*=(1.5); break; } if(builtBuildings.find(26)!=builtBuildings.end()) //grail - ret+=CGI->creh->creatures[town->basicCreatures[level]].growth; + ret+=VLC->creh->creatures[town->basicCreatures[level]].growth; if(getHordeLevel(0)==level) if((builtBuildings.find(18)!=builtBuildings.end()) || (builtBuildings.find(19)!=builtBuildings.end())) - ret+=CGI->creh->creatures[town->basicCreatures[level]].hordeGrowth; + ret+=VLC->creh->creatures[town->basicCreatures[level]].hordeGrowth; if(getHordeLevel(1)==level) if((builtBuildings.find(24)!=builtBuildings.end()) || (builtBuildings.find(25)!=builtBuildings.end())) - ret+=CGI->creh->creatures[town->basicCreatures[level]].hordeGrowth; + ret+=VLC->creh->creatures[town->basicCreatures[level]].hordeGrowth; return ret; } int CGTownInstance::dailyIncome() const diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 4f4abc3e9..571aefe04 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -1,11 +1,12 @@ #ifndef COBJECTHANDLER_H #define COBJECTHANDLER_H +#include "../global.h" #include #include #include #include #include "CCreatureHandler.h" -//#include "CHeroHandler.h" + using boost::logic::tribool; class CCPPObjectScript; class CGObjectInstance; @@ -18,11 +19,11 @@ class CBuilding; class CSpell; class CGTownInstance; class CArtifact; -class CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes +class DLL_EXPORT CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes { }; -class CEventObjInfo : public CSpecObjInfo +class DLL_EXPORT CEventObjInfo : public CSpecObjInfo { public: bool areGuarders; //true if there are @@ -48,7 +49,7 @@ public: bool humanActivate; //true if human player can activate this event }; -class CCastleEvent +class DLL_EXPORT CCastleEvent { public: std::string name, message; @@ -68,7 +69,7 @@ public: } }; -class CCreatureObjInfo : public CSpecObjInfo +class DLL_EXPORT CCreatureObjInfo : public CSpecObjInfo { public: unsigned char bytes[4]; //mysterious bytes identifying creature @@ -81,13 +82,13 @@ public: bool notGrowingTeam; //if true, number of units won't grow }; -class CSignObjInfo : public CSpecObjInfo +class DLL_EXPORT CSignObjInfo : public CSpecObjInfo { public: std::string message; //message }; -class CSeerHutObjInfo : public CSpecObjInfo +class DLL_EXPORT CSeerHutObjInfo : public CSpecObjInfo { public: unsigned char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player @@ -133,13 +134,13 @@ public: int r10amount; }; -class CWitchHutObjInfo : public CSpecObjInfo +class DLL_EXPORT CWitchHutObjInfo : public CSpecObjInfo { public: std::vector allowedAbilities; }; -class CScholarObjInfo : public CSpecObjInfo +class DLL_EXPORT CScholarObjInfo : public CSpecObjInfo { public: unsigned char bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell @@ -149,7 +150,7 @@ public: int r2; //Spell ID }; -class CGarrisonObjInfo : public CSpecObjInfo +class DLL_EXPORT CGarrisonObjInfo : public CSpecObjInfo { public: unsigned char player; //255 - nobody; 0 - 7 - players @@ -157,7 +158,7 @@ public: bool movableUnits; //if true, units can be moved }; -class CArtifactObjInfo : public CSpecObjInfo +class DLL_EXPORT CArtifactObjInfo : public CSpecObjInfo { public: bool areGuards; @@ -165,7 +166,7 @@ public: CCreatureSet guards; }; -class CResourceObjInfo : public CSpecObjInfo +class DLL_EXPORT CResourceObjInfo : public CSpecObjInfo { public: bool randomAmount; @@ -175,19 +176,19 @@ public: std::string message; }; -class CPlayerOnlyObjInfo : public CSpecObjInfo +class DLL_EXPORT CPlayerOnlyObjInfo : public CSpecObjInfo { public: unsigned char player; //FF - nobody, 0 - 7 }; -class CShrineObjInfo : public CSpecObjInfo +class DLL_EXPORT CShrineObjInfo : public CSpecObjInfo { public: unsigned char spell; //number of spell or 255 }; -class CSpellScrollObjinfo : public CSpecObjInfo +class DLL_EXPORT CSpellScrollObjinfo : public CSpecObjInfo { public: std::string message; @@ -196,7 +197,7 @@ public: CCreatureSet guarders; }; -class CPandorasBoxObjInfo : public CSpecObjInfo +class DLL_EXPORT CPandorasBoxObjInfo : public CSpecObjInfo { public: std::string message; @@ -217,13 +218,13 @@ public: CCreatureSet creatures; }; -class CGrailObjInfo : public CSpecObjInfo +class DLL_EXPORT CGrailObjInfo : public CSpecObjInfo { public: int radius; //place grail at the distance lesser or equal radius from this place }; -class CCreGenObjInfo : public CSpecObjInfo +class DLL_EXPORT CCreGenObjInfo : public CSpecObjInfo { public: unsigned char player; //owner @@ -232,7 +233,7 @@ public: unsigned char castles[2]; //allowed castles }; -class CCreGen2ObjInfo : public CSpecObjInfo +class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo { public: unsigned char player; //owner @@ -242,14 +243,14 @@ public: unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> }; -class CCreGen3ObjInfo : public CSpecObjInfo +class DLL_EXPORT CCreGen3ObjInfo : public CSpecObjInfo { public: unsigned char player; //owner unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> }; -class CBorderGuardObjInfo : public CSpecObjInfo //copied form seer huts, seems to be similar +class DLL_EXPORT CBorderGuardObjInfo : public CSpecObjInfo //copied form seer huts, seems to be similar { public: char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player @@ -278,15 +279,15 @@ public: std::string firstVisitText, nextVisitText, completedText; }; -class CObject //typical object that can be encountered on a map +class DLL_EXPORT CObject //typical object that can be encountered on a map { public: std::string name; //object's name }; -class CGDefInfo; +class DLL_EXPORT CGDefInfo; -class CGObjectInstance +class DLL_EXPORT CGObjectInstance { public: int3 pos; //h3m pos @@ -313,13 +314,13 @@ public: CGObjectInstance& operator=(const CGObjectInstance & right); }; -class CArmedInstance: public CGObjectInstance +class DLL_EXPORT CArmedInstance: public CGObjectInstance { public: CCreatureSet army; //army }; -class CGHeroInstance : public CArmedInstance +class DLL_EXPORT CGHeroInstance : public CArmedInstance { public: int moveDir; //format: 123 @@ -340,7 +341,7 @@ public: int identifier; //from the map file bool sex; - struct Patrol + struct DLL_EXPORT Patrol { Patrol(){patrolling=false;patrolRadious=-1;}; bool patrolling; @@ -374,7 +375,7 @@ public: virtual ~CGHeroInstance(); }; -class CGTownInstance : public CArmedInstance +class DLL_EXPORT CGTownInstance : public CArmedInstance { public: CTown * town; @@ -408,7 +409,7 @@ public: virtual ~CGTownInstance(); }; -class CObjectHandler +class DLL_EXPORT CObjectHandler { public: std::vector objects; //vector of objects; i-th object in vector has subnumber i diff --git a/hch/CTownHandler.h b/hch/CTownHandler.h index 7a9e675a5..927828866 100644 --- a/hch/CTownHandler.h +++ b/hch/CTownHandler.h @@ -6,7 +6,7 @@ class CBuilding; class CSpell; class CHero; class CGTownInstance; -class CTown +class DLL_EXPORT CTown { public: std::string name; //name of type diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index f93fb251b..2bbcdafa2 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -2,7 +2,7 @@ //class CMapHandler; -//class CArtHandler; +class CArtHandler; //class CHeroHandler; class CCreatureHandler; //class CAbilityHandler; @@ -30,7 +30,7 @@ class LibClasses { public: //CGameState * state; - //CArtHandler * arth; + CArtHandler * arth; //CHeroHandler * heroh; CCreatureHandler * creh; //CAbilityHandler * abilh; diff --git a/lib/VCMI_lib.vcproj b/lib/VCMI_lib.vcproj index 85b869182..05b1118a0 100644 --- a/lib/VCMI_lib.vcproj +++ b/lib/VCMI_lib.vcproj @@ -349,6 +349,10 @@ RelativePath="..\hch\CLodHandler.cpp" > + + @@ -387,6 +391,10 @@ RelativePath="..\hch\CLodHandler.h" > + + diff --git a/mapHandler.cpp b/mapHandler.cpp index 465fbfd1d..ae9164a8f 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -278,6 +278,8 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur) if(!t->defInfo->handler) { t->defInfo->handler = CDefHandler::giveDef(t->defInfo->name); + t->defInfo->width = t->defInfo->handler->ourImages[0].bitmap->w/32; + t->defInfo->height = t->defInfo->handler->ourImages[0].bitmap->h/32; alphaTransformDef(t->defInfo); } } @@ -310,6 +312,8 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur) if(!t->defInfo->handler) { t->defInfo->handler = CDefHandler::giveDef(t->defInfo->name); + t->defInfo->width = t->defInfo->handler->ourImages[0].bitmap->w/32; + t->defInfo->height = t->defInfo->handler->ourImages[0].bitmap->h/32; alphaTransformDef(t->defInfo); } //CGI->townh->townInstances.push_back(t); @@ -323,6 +327,8 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur) if(!cur->defInfo->handler) //if we have to load def { cur->defInfo->handler = CDefHandler::giveDef(cur->defInfo->name); + cur->defInfo->width = cur->defInfo->handler->ourImages[0].bitmap->w/32; + cur->defInfo->height = cur->defInfo->handler->ourImages[0].bitmap->h/32; alphaTransformDef(cur->defInfo); } @@ -810,9 +816,15 @@ void CMapHandler::init() for (int ir=0;irdefy.size();ir++) { map->defy[ir]->handler=CDefHandler::giveDef(map->defy[ir]->name); + map->defy[ir]->width = map->defy[ir]->handler->ourImages[0].bitmap->w/32; + map->defy[ir]->height = map->defy[ir]->handler->ourImages[0].bitmap->h/32; CGDefInfo* pom = CGI->dobjinfo->gobjs[map->defy[ir]->id][map->defy[ir]->subid]; if(pom) + { pom->handler=map->defy[ir]->handler; + pom->width = pom->handler->ourImages[0].bitmap->w/32; + pom->height = pom->handler->ourImages[0].bitmap->h/32; + } else std::cout << "Lacking def info for " << map->defy[ir]->id << " " << map->defy[ir]->subid <<" " << map->defy[ir]->name << std::endl; } @@ -838,6 +850,11 @@ void CMapHandler::init() ifs >> n->name; if (!(n->handler = CDefHandler::giveDef(n->name))) std::cout << "Cannot open "<name<width = n->handler->ourImages[0].bitmap->w/32; + n->height = n->handler->ourImages[0].bitmap->h/32; + } if(idefInfo = CGI->dobjinfo->gobjs[id][subid]; if(!nobj->defInfo->handler) + { nobj->defInfo->handler = CDefHandler::giveDef(nobj->defInfo->name); + nobj->defInfo->width = nobj->defInfo->handler->ourImages[0].bitmap->w/32; + nobj->defInfo->height = nobj->defInfo->handler->ourImages[0].bitmap->h/32; + } return nobj; } From c7dde147c311777653f5d5ecc48f3a410c86ecc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 19 Jun 2008 06:08:05 +0000 Subject: [PATCH 14/47] More moving / minor changes --- client/Graphics.cpp | 6 +- client/VCMI_client.vcproj | 12 -- hch/CAmbarCendamo.cpp | 44 +++--- hch/CAmbarCendamo.h | 2 +- hch/CBuildingHandler.cpp | 11 +- hch/CBuildingHandler.h | 4 +- hch/CCreatureHandler.h | 6 - hch/CObjectHandler.h | 243 +--------------------------------- int3.h | 8 ++ lib/VCMI_lib.vcproj | 30 ++++- map.cpp | 1 + map.h | 272 ++++++++++++++++++++++++++++++++++---- 12 files changed, 311 insertions(+), 328 deletions(-) diff --git a/client/Graphics.cpp b/client/Graphics.cpp index d628e65e3..02da2ebe8 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -177,11 +177,7 @@ void Graphics::loadHeroAnim(std::vector & anims) for(int i=0; i - - @@ -276,10 +272,6 @@ RelativePath=".\CBitmapHandler.cpp" > - - @@ -380,10 +372,6 @@ RelativePath=".\Graphics.cpp" > - - diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index baadf3500..49418cda9 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -1,12 +1,12 @@ +#define VCMI_DLL #include "../stdafx.h" #include "CAmbarCendamo.h" -#include "../CGameInfo.h" #include "CObjectHandler.h" #include "CDefObjInfoHandler.h" #include -#include #include #include +#include "../lib/VCMI_Lib.h" std::string nameFromType (EterrainType typ); int readInt(unsigned char * bufor, int bytCon) { @@ -120,10 +120,11 @@ void CAmbarCendamo::deh3m() { THC timeHandler th; th.getDif(); - map.version = (Eformat)bufor[0]; //wersja mapy - map.areAnyPLayers = bufor[4]; //invalid on some maps - map.height = map.width = bufor[5]; // wymiary mapy - map.twoLevel = bufor[9]; //czy sa lochy + i=0; + map.version = (Eformat)(readNormalNr(i)); i+=4; //map version + map.areAnyPLayers = readChar(); //invalid on some maps + map.height = map.width = (readNormalNr(i)); i+=4; // wymiary mapy + map.twoLevel = readChar(); //czy sa lochy map.terrain = new TerrainTile*[map.width]; // allocate memory for (int ii=0;iim6cre.push_back(&(CGI->creh->creatures[creType])); + spec->m6cre.push_back(&(VLC->creh->creatures[creType])); spec->m6number.push_back(creNumb); } int limit = readNormalNr(i); i+=4; @@ -1830,7 +1822,7 @@ void CAmbarCendamo::deh3m() { int creType = readNormalNr(i, 2); i+=2; int creNumb = readNormalNr(i, 2); i+=2; - spec->m6cre.push_back(&(CGI->creh->creatures[creType])); + spec->m6cre.push_back(&(VLC->creh->creatures[creType])); spec->m6number.push_back(creNumb); } int limit = readNormalNr(i); i+=4; @@ -2059,8 +2051,8 @@ CCreatureSet CAmbarCendamo::readCreatureSet(int number) int rettt = readNormalNr(i+ir*4, 2); if(rettt==0xffff) continue; if(rettt>32768) - rettt = 65536-rettt+CGI->creh->creatures.size()-16; - ins.first = &(CGI->creh->creatures[rettt]); + rettt = 65536-rettt+VLC->creh->creatures.size()-16; + ins.first = &(VLC->creh->creatures[rettt]); ins.second = readNormalNr(i+ir*4+2, 2); std::pair > tt(ir,ins); ret.slots.insert(tt); @@ -2077,8 +2069,8 @@ CCreatureSet CAmbarCendamo::readCreatureSet(int number) int rettt = readNormalNr(i+ir*3, 1); if(rettt==0xff) continue; if(rettt>220) - rettt = 256-rettt+CGI->creh->creatures.size()-16; - ins.first = &(CGI->creh->creatures[rettt]); + rettt = 256-rettt+VLC->creh->creatures.size()-16; + ins.first = &(VLC->creh->creatures[rettt]); ins.second = readNormalNr(i+ir*3+1, 2); std::pair > tt(ir,ins); ret.slots.insert(tt); diff --git a/hch/CAmbarCendamo.h b/hch/CAmbarCendamo.h index 4bcdd120d..ebbbe6283 100644 --- a/hch/CAmbarCendamo.h +++ b/hch/CAmbarCendamo.h @@ -9,7 +9,7 @@ enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF, EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF, SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF, BORDERGUARD_DEF, HEROPLACEHOLDER_DEF}; -class CAmbarCendamo +class DLL_EXPORT CAmbarCendamo { public: /////////////////member variables diff --git a/hch/CBuildingHandler.cpp b/hch/CBuildingHandler.cpp index 1fc627408..3d74bedf4 100644 --- a/hch/CBuildingHandler.cpp +++ b/hch/CBuildingHandler.cpp @@ -1,9 +1,10 @@ +#define VCMI_DLL #include "../stdafx.h" -#include "../CGameInfo.h" #include "CBuildingHandler.h" #include "CLodHandler.h" #include #include +extern CLodHandler * bitmaph; std::string readTo(std::string &in, unsigned int &it, char end) { int pom = it; @@ -34,7 +35,7 @@ CBuilding * readBg(std::string &buf, unsigned int& it) } void CBuildingHandler::loadBuildings() { - std::string buf = CGI->bitmaph->getTextFile("BUILDING.TXT"), temp; + std::string buf = bitmaph->getTextFile("BUILDING.TXT"), temp; unsigned int andame = buf.size(), it=0; //buf iterator temp = readTo(buf,it,'\n');temp = readTo(buf,it,'\n');//read 2 lines of file info @@ -75,7 +76,7 @@ void CBuildingHandler::loadBuildings() } /////done reading BUILDING.TXT***************************** - buf = CGI->bitmaph->getTextFile("BLDGNEUT.TXT"); + buf = bitmaph->getTextFile("BLDGNEUT.TXT"); andame = buf.size(), it=0; for(int b=0;b<15;b++) @@ -105,7 +106,7 @@ void CBuildingHandler::loadBuildings() } /////done reading "BLDGNEUT.TXT"****************************** - buf = CGI->bitmaph->getTextFile("BLDGSPEC.TXT"); + buf = bitmaph->getTextFile("BLDGSPEC.TXT"); andame = buf.size(), it=0; for(int f=0;fbitmaph->getTextFile("DWELLING.TXT"); + buf = bitmaph->getTextFile("DWELLING.TXT"); andame = buf.size(), it=0; for(int f=0;f //enum EbuildingType {NEUTRAL=-1, CASTLE, RAMPART, TOWER, INFERNO, NECROPOLIS, DUNGEON, STRONGHOLD, FORTRESS, CONFLUX}; -class CBuilding //a typical building encountered in every castle ;] +class DLL_EXPORT CBuilding //a typical building encountered in every castle ;] { public: std::string name; @@ -14,7 +14,7 @@ public: //bool isDwelling; //true, if this building is a dwelling }; -class CBuildingHandler +class DLL_EXPORT CBuildingHandler { public: std::map > buildings; ///< first int is the castle ID, second the building ID (in ERM-U format) diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index 82fbbf0c0..dd74a27d4 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -45,12 +45,6 @@ public: static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion }; -class CCreatureSet //seven combined creatures -{ -public: - std::map > slots; - bool formation; //false - wide, true - tight -}; class DLL_EXPORT CCreatureHandler { diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 571aefe04..4219a24cf 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -19,35 +19,8 @@ class CBuilding; class CSpell; class CGTownInstance; class CArtifact; -class DLL_EXPORT CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes -{ -}; - -class DLL_EXPORT CEventObjInfo : public CSpecObjInfo -{ -public: - bool areGuarders; //true if there are - CCreatureSet guarders; - bool isMessage; //true if there is a message - std::string message; - unsigned int gainedExp; - int manaDiff; //amount of gained / lost mana - int moraleDiff; //morale modifier - int luckDiff; //luck modifier - int wood, mercury, ore, sulfur, crystal, gems, gold; //gained / lost resources - unsigned int attack; //added attack points - unsigned int defence; //added defence points - unsigned int power; //added power points - unsigned int knowledge; //added knowledge points - std::vector abilities; //gained abilities - std::vector abilityLevels; //levels of gained abilities - std::vector artifacts; //gained artifacts - std::vector spells; //gained spells - CCreatureSet creatures; //gained creatures - unsigned char availableFor; //players whom this event is available for - bool computerActivate; //true if computre player can activate this event - bool humanActivate; //true if human player can activate this event -}; +class CGDefInfo; +class CSpecObjInfo; class DLL_EXPORT CCastleEvent { @@ -69,224 +42,12 @@ public: } }; -class DLL_EXPORT CCreatureObjInfo : public CSpecObjInfo -{ -public: - unsigned char bytes[4]; //mysterious bytes identifying creature - unsigned int number; //number of units (0 - random) - unsigned char character; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile) - std::string message; //message printed for attacking hero - int wood, mercury, ore, sulfur, crytal, gems, gold; //resources gained to hero that has won with monsters - int gainedArtifact; //ID of artifact gained to hero - bool neverFlees; //if true, the troops will never flee - bool notGrowingTeam; //if true, number of units won't grow -}; - -class DLL_EXPORT CSignObjInfo : public CSpecObjInfo -{ -public: - std::string message; //message -}; - -class DLL_EXPORT CSeerHutObjInfo : public CSpecObjInfo -{ -public: - unsigned char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player - bool isDayLimit; //if true, there is a day limit - int lastDay; //after this day (first day is 0) mission cannot be completed - int m1level; //for mission 1 - int m2attack, m2defence, m2power, m2knowledge;//for mission 2 - unsigned char m3bytes[4];//for mission 3 - unsigned char m4bytes[4];//for mission 4 - std::vector m5arts;//for mission 5 - artifact ID - std::vector m6cre;//for mission 6 - std::vector m6number; - int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 7 - int m8hero;//for mission 8 - hero ID - int m9player; //for mission 9 - number; from 0 to 7 - - std::string firstVisitText, nextVisitText, completedText; - - char rewardType; //type of reward: 0 - no reward; 1 - experience; 2 - mana points; 3 - morale bonus; 4 - luck bonus; 5 - resources; 6 - main ability bonus (attak, defence etd.); 7 - secondary ability gain; 8 - artifact; 9 - spell; 10 - creature - //for reward 1 - int r1exp; - //for reward 2 - int r2mana; - //for reward 3 - int r3morale; - //for reward 4 - int r4luck; - //for reward 5 - unsigned char r5type; //0 - wood, 1 - mercury, 2 - ore, 3 - sulfur, 4 - crystal, 5 - gems, 6 - gold - int r5amount; - //for reward 6 - unsigned char r6type; //0 - attack, 1 - defence, 2 - power, 3 - knowledge - int r6amount; - //for reward 7 - int r7ability; //ability id - unsigned char r7level; //1 - basic, 2 - advanced, 3 - expert - //for reward 8 - int r8art;//artifact id - //for reward 9 - int r9spell;//spell id - //for reward 10 - int r10creature; //creature id - int r10amount; -}; - -class DLL_EXPORT CWitchHutObjInfo : public CSpecObjInfo -{ -public: - std::vector allowedAbilities; -}; - -class DLL_EXPORT CScholarObjInfo : public CSpecObjInfo -{ -public: - unsigned char bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell - - unsigned char r0type; - int r1; //Ability ID - int r2; //Spell ID -}; - -class DLL_EXPORT CGarrisonObjInfo : public CSpecObjInfo -{ -public: - unsigned char player; //255 - nobody; 0 - 7 - players - CCreatureSet units; - bool movableUnits; //if true, units can be moved -}; - -class DLL_EXPORT CArtifactObjInfo : public CSpecObjInfo -{ -public: - bool areGuards; - std::string message; - CCreatureSet guards; -}; - -class DLL_EXPORT CResourceObjInfo : public CSpecObjInfo -{ -public: - bool randomAmount; - int amount; //if not random - bool areGuards; - CCreatureSet guards; - std::string message; -}; - -class DLL_EXPORT CPlayerOnlyObjInfo : public CSpecObjInfo -{ -public: - unsigned char player; //FF - nobody, 0 - 7 -}; - -class DLL_EXPORT CShrineObjInfo : public CSpecObjInfo -{ -public: - unsigned char spell; //number of spell or 255 -}; - -class DLL_EXPORT CSpellScrollObjinfo : public CSpecObjInfo -{ -public: - std::string message; - int spell; - bool areGuarders; - CCreatureSet guarders; -}; - -class DLL_EXPORT CPandorasBoxObjInfo : public CSpecObjInfo -{ -public: - std::string message; - bool areGuarders; - CCreatureSet guarders; - - //gained things: - unsigned int gainedExp; - int manaDiff; - int moraleDiff; - int luckDiff; - int wood, mercury, ore, sulfur, crystal, gems, gold; - int attack, defence, power, knowledge; - std::vector abilities; - std::vector abilityLevels; - std::vector artifacts; - std::vector spells; - CCreatureSet creatures; -}; - -class DLL_EXPORT CGrailObjInfo : public CSpecObjInfo -{ -public: - int radius; //place grail at the distance lesser or equal radius from this place -}; - -class DLL_EXPORT CCreGenObjInfo : public CSpecObjInfo -{ -public: - unsigned char player; //owner - bool asCastle; - int identifier; - unsigned char castles[2]; //allowed castles -}; - -class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo -{ -public: - unsigned char player; //owner - bool asCastle; - int identifier; - unsigned char castles[2]; //allowed castles - unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> -}; - -class DLL_EXPORT CCreGen3ObjInfo : public CSpecObjInfo -{ -public: - unsigned char player; //owner - unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> -}; - -class DLL_EXPORT CBorderGuardObjInfo : public CSpecObjInfo //copied form seer huts, seems to be similar -{ -public: - char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player - bool isDayLimit; //if true, there is a day limit - int lastDay; //after this day (first day is 0) mission cannot be completed - //for mission 1 - int m1level; - //for mission 2 - int m2attack, m2defence, m2power, m2knowledge; - //for mission 3 - unsigned char m3bytes[4]; - //for mission 4 - unsigned char m4bytes[4]; - //for mission 5 - std::vector m5arts; //artifacts id - //for mission 6 - std::vector m6cre; - std::vector m6number; - //for mission 7 - int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; - //for mission 8 - int m8hero; //hero id - //for mission 9 - int m9player; //number; from 0 to 7 - - std::string firstVisitText, nextVisitText, completedText; -}; - class DLL_EXPORT CObject //typical object that can be encountered on a map { public: std::string name; //object's name }; -class DLL_EXPORT CGDefInfo; - class DLL_EXPORT CGObjectInstance { public: diff --git a/int3.h b/int3.h index 6d6ff2b9a..d8af5f5e4 100644 --- a/int3.h +++ b/int3.h @@ -1,5 +1,13 @@ #ifndef INT3_H #define INT3_H +#include +class CCreature; +class CCreatureSet //seven combined creatures +{ +public: + std::map > slots; + bool formation; //false - wide, true - tight +}; class int3 { diff --git a/lib/VCMI_lib.vcproj b/lib/VCMI_lib.vcproj index 05b1118a0..0d46c51af 100644 --- a/lib/VCMI_lib.vcproj +++ b/lib/VCMI_lib.vcproj @@ -329,10 +329,18 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + + + + @@ -357,6 +365,10 @@ RelativePath="..\hch\CTownHandler.cpp" > + + @@ -371,10 +383,18 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + + + @@ -399,17 +419,15 @@ RelativePath="..\hch\CTownHandler.h" > + + - - diff --git a/map.cpp b/map.cpp index 6de1bffc9..01f310f32 100644 --- a/map.cpp +++ b/map.cpp @@ -1,3 +1,4 @@ +#define VCMI_DLL #include "stdafx.h" #include "map.h" diff --git a/map.h b/map.h index 6a9e332d0..06d369fd3 100644 --- a/map.h +++ b/map.h @@ -10,12 +10,236 @@ class CGObjectInstance; class CGHeroInstance; class CGTownInstance; enum ESortBy{name,playerAm,size,format, viccon,loscon}; -struct Sresource + +class DLL_EXPORT CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes +{ +}; +class DLL_EXPORT CEventObjInfo : public CSpecObjInfo +{ +public: + bool areGuarders; //true if there are + CCreatureSet guarders; + bool isMessage; //true if there is a message + std::string message; + unsigned int gainedExp; + int manaDiff; //amount of gained / lost mana + int moraleDiff; //morale modifier + int luckDiff; //luck modifier + int wood, mercury, ore, sulfur, crystal, gems, gold; //gained / lost resources + unsigned int attack; //added attack points + unsigned int defence; //added defence points + unsigned int power; //added power points + unsigned int knowledge; //added knowledge points + std::vector abilities; //gained abilities + std::vector abilityLevels; //levels of gained abilities + std::vector artifacts; //gained artifacts + std::vector spells; //gained spells + CCreatureSet creatures; //gained creatures + unsigned char availableFor; //players whom this event is available for + bool computerActivate; //true if computre player can activate this event + bool humanActivate; //true if human player can activate this event +}; +class DLL_EXPORT CCreatureObjInfo : public CSpecObjInfo +{ +public: + unsigned char bytes[4]; //mysterious bytes identifying creature + unsigned int number; //number of units (0 - random) + unsigned char character; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile) + std::string message; //message printed for attacking hero + int wood, mercury, ore, sulfur, crytal, gems, gold; //resources gained to hero that has won with monsters + int gainedArtifact; //ID of artifact gained to hero + bool neverFlees; //if true, the troops will never flee + bool notGrowingTeam; //if true, number of units won't grow +}; +class DLL_EXPORT CSignObjInfo : public CSpecObjInfo +{ +public: + std::string message; //message +}; +class DLL_EXPORT CSeerHutObjInfo : public CSpecObjInfo +{ +public: + unsigned char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player + bool isDayLimit; //if true, there is a day limit + int lastDay; //after this day (first day is 0) mission cannot be completed + int m1level; //for mission 1 + int m2attack, m2defence, m2power, m2knowledge;//for mission 2 + unsigned char m3bytes[4];//for mission 3 + unsigned char m4bytes[4];//for mission 4 + std::vector m5arts;//for mission 5 - artifact ID + std::vector m6cre;//for mission 6 + std::vector m6number; + int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 7 + int m8hero;//for mission 8 - hero ID + int m9player; //for mission 9 - number; from 0 to 7 + + std::string firstVisitText, nextVisitText, completedText; + + char rewardType; //type of reward: 0 - no reward; 1 - experience; 2 - mana points; 3 - morale bonus; 4 - luck bonus; 5 - resources; 6 - main ability bonus (attak, defence etd.); 7 - secondary ability gain; 8 - artifact; 9 - spell; 10 - creature + //for reward 1 + int r1exp; + //for reward 2 + int r2mana; + //for reward 3 + int r3morale; + //for reward 4 + int r4luck; + //for reward 5 + unsigned char r5type; //0 - wood, 1 - mercury, 2 - ore, 3 - sulfur, 4 - crystal, 5 - gems, 6 - gold + int r5amount; + //for reward 6 + unsigned char r6type; //0 - attack, 1 - defence, 2 - power, 3 - knowledge + int r6amount; + //for reward 7 + int r7ability; //ability id + unsigned char r7level; //1 - basic, 2 - advanced, 3 - expert + //for reward 8 + int r8art;//artifact id + //for reward 9 + int r9spell;//spell id + //for reward 10 + int r10creature; //creature id + int r10amount; +}; +class DLL_EXPORT CWitchHutObjInfo : public CSpecObjInfo +{ +public: + std::vector allowedAbilities; +}; +class DLL_EXPORT CScholarObjInfo : public CSpecObjInfo +{ +public: + unsigned char bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell + + unsigned char r0type; + int r1; //Ability ID + int r2; //Spell ID +}; +class DLL_EXPORT CGarrisonObjInfo : public CSpecObjInfo +{ +public: + unsigned char player; //255 - nobody; 0 - 7 - players + CCreatureSet units; + bool movableUnits; //if true, units can be moved +}; +class DLL_EXPORT CArtifactObjInfo : public CSpecObjInfo +{ +public: + bool areGuards; + std::string message; + CCreatureSet guards; +}; +class DLL_EXPORT CResourceObjInfo : public CSpecObjInfo +{ +public: + bool randomAmount; + int amount; //if not random + bool areGuards; + CCreatureSet guards; + std::string message; +}; +class DLL_EXPORT CPlayerOnlyObjInfo : public CSpecObjInfo +{ +public: + unsigned char player; //FF - nobody, 0 - 7 +}; +class DLL_EXPORT CShrineObjInfo : public CSpecObjInfo +{ +public: + unsigned char spell; //number of spell or 255 +}; +class DLL_EXPORT CSpellScrollObjinfo : public CSpecObjInfo +{ +public: + std::string message; + int spell; + bool areGuarders; + CCreatureSet guarders; +}; +class DLL_EXPORT CPandorasBoxObjInfo : public CSpecObjInfo +{ +public: + std::string message; + bool areGuarders; + CCreatureSet guarders; + + //gained things: + unsigned int gainedExp; + int manaDiff; + int moraleDiff; + int luckDiff; + int wood, mercury, ore, sulfur, crystal, gems, gold; + int attack, defence, power, knowledge; + std::vector abilities; + std::vector abilityLevels; + std::vector artifacts; + std::vector spells; + CCreatureSet creatures; +}; + +class DLL_EXPORT CGrailObjInfo : public CSpecObjInfo +{ +public: + int radius; //place grail at the distance lesser or equal radius from this place +}; +class DLL_EXPORT CCreGenObjInfo : public CSpecObjInfo +{ +public: + unsigned char player; //owner + bool asCastle; + int identifier; + unsigned char castles[2]; //allowed castles +}; +class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo +{ +public: + unsigned char player; //owner + bool asCastle; + int identifier; + unsigned char castles[2]; //allowed castles + unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> +}; +class DLL_EXPORT CCreGen3ObjInfo : public CSpecObjInfo +{ +public: + unsigned char player; //owner + unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6> +}; +class DLL_EXPORT CBorderGuardObjInfo : public CSpecObjInfo //copied form seer huts, seems to be similar +{ +public: + char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player + bool isDayLimit; //if true, there is a day limit + int lastDay; //after this day (first day is 0) mission cannot be completed + //for mission 1 + int m1level; + //for mission 2 + int m2attack, m2defence, m2power, m2knowledge; + //for mission 3 + unsigned char m3bytes[4]; + //for mission 4 + unsigned char m4bytes[4]; + //for mission 5 + std::vector m5arts; //artifacts id + //for mission 6 + std::vector m6cre; + std::vector m6number; + //for mission 7 + int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; + //for mission 8 + int m8hero; //hero id + //for mission 9 + int m9player; //number; from 0 to 7 + + std::string firstVisitText, nextVisitText, completedText; +}; + +struct DLL_EXPORT Sresource { std::string resName; //name of this resource int amount; //it can be greater and lesser than 0 }; -struct TimeEvent +struct DLL_EXPORT TimeEvent { std::string eventName; std::string message; @@ -26,7 +250,7 @@ struct TimeEvent int firstAfterNDays; //how many days after appears this event int nextAfterNDays; //how many days after the epperance before appaers this event }; -struct TerrainTile +struct DLL_EXPORT TerrainTile { EterrainType tertype; // type of terrain unsigned char terview; // look of terrain @@ -34,14 +258,14 @@ struct TerrainTile unsigned char rivDir; // direction of Eriver Eroad malle; // type of Eroad (0 if there is no Eriver) unsigned char roadDir; // direction of Eroad - unsigned char siodmyTajemniczyBajt; // mysterius byte // jak bedzie waidomo co to, to sie nazwie inaczej + unsigned char siodmyTajemniczyBajt; //bitfield, info whether this tile is coastal and how to rotate tile graphics }; -struct SheroName //name of starting hero +struct DLL_EXPORT SheroName //name of starting hero { int heroID; std::string heroName; }; -struct PlayerInfo +struct DLL_EXPORT PlayerInfo { int p7, p8, p9; bool canHumanPlay; @@ -58,66 +282,66 @@ struct PlayerInfo int team; bool generateHero; }; -struct LossCondition +struct DLL_EXPORT LossCondition { ElossCon typeOfLossCon; int3 castlePos; int3 heroPos; int timeLimit; // in days }; -struct CspecificVictoryConidtions +struct DLL_EXPORT CspecificVictoryConidtions { bool allowNormalVictory; bool appliesToAI; }; -struct VicCon0 : public CspecificVictoryConidtions //acquire artifact +struct DLL_EXPORT VicCon0 : public CspecificVictoryConidtions //acquire artifact { int ArtifactID; }; -struct VicCon1 : public CspecificVictoryConidtions //accumulate creatures +struct DLL_EXPORT VicCon1 : public CspecificVictoryConidtions //accumulate creatures { int monsterID; int neededQuantity; }; -struct VicCon2 : public CspecificVictoryConidtions // accumulate resources +struct DLL_EXPORT VicCon2 : public CspecificVictoryConidtions // accumulate resources { int resourceID; int neededQuantity; }; -struct VicCon3 : public CspecificVictoryConidtions // upgrade specific town +struct DLL_EXPORT VicCon3 : public CspecificVictoryConidtions // upgrade specific town { int3 posOfCity; int councilNeededLevel; //0 - town; 1 - city; 2 - capitol int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle }; -struct VicCon4 : public CspecificVictoryConidtions // build grail structure +struct DLL_EXPORT VicCon4 : public CspecificVictoryConidtions // build grail structure { bool anyLocation; int3 whereBuildGrail; }; -struct VicCon5 : public CspecificVictoryConidtions // defeat a specific hero +struct DLL_EXPORT VicCon5 : public CspecificVictoryConidtions // defeat a specific hero { int3 locationOfHero; }; -struct VicCon6 : public CspecificVictoryConidtions // capture a specific town +struct DLL_EXPORT VicCon6 : public CspecificVictoryConidtions // capture a specific town { int3 locationOfTown; }; -struct VicCon7 : public CspecificVictoryConidtions // defeat a specific monster +struct DLL_EXPORT VicCon7 : public CspecificVictoryConidtions // defeat a specific monster { int3 locationOfMonster; }; -struct VicCona : public CspecificVictoryConidtions //transport specific artifact +struct DLL_EXPORT VicCona : public CspecificVictoryConidtions //transport specific artifact { int artifactID; int3 destinationPlace; }; -struct Rumor +struct DLL_EXPORT Rumor { std::string name, text; }; -struct DisposedHero +struct DLL_EXPORT DisposedHero { int ID; int portrait; //0xFF - default @@ -125,7 +349,7 @@ struct DisposedHero bool players[8]; //who can hire this hero }; -class CMapEvent +class DLL_EXPORT CMapEvent { public: std::string name, message; @@ -136,7 +360,7 @@ public: int firstOccurence; int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time; }; -struct Mapa +struct DLL_EXPORT Mapa { Eformat version; // version of map Eformat int twoLevel; // if map has underground level @@ -168,7 +392,7 @@ struct Mapa std::vector heroes; std::vector towns; }; -class CMapHeader +class DLL_EXPORT CMapHeader { public: Eformat version; // version of map Eformat @@ -187,7 +411,7 @@ public: int howManyTeams; CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked) }; -class CMapInfo : public CMapHeader +class DLL_EXPORT CMapInfo : public CMapHeader { public: std::string filename; @@ -204,7 +428,7 @@ public: }; -class mapSorter +class DLL_EXPORT mapSorter { public: ESortBy sortBy; From c351496a477c71fe77bc2e488d8ca49b11df0b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 21 Jun 2008 13:27:52 +0000 Subject: [PATCH 15/47] * moved map reading to the map.cpp * merged changes from trunk (since r461) --- CAdvmapInterface.cpp | 1 + CBattleInterface.cpp | 66 +- CBattleInterface.h | 2 +- CCallback.cpp | 5 +- CConsoleHandler.cpp | 211 ++-- CGameState.cpp | 60 +- CGameState.h | 10 +- CHeroWindow.cpp | 5 +- CMT.cpp | 11 +- CPathfinder.cpp | 36 +- CPlayerInterface.cpp | 2 + hch/CAmbarCendamo.cpp | 2138 +---------------------------------------- hch/CAmbarCendamo.h | 19 +- map.cpp | 2048 ++++++++++++++++++++++++++++++++++++++- map.h | 7 +- 15 files changed, 2346 insertions(+), 2275 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 995720d9d..c87e5b403 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -316,6 +316,7 @@ void CTerrainRect::clickLeft(tribool down) //Convert to old format. currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->ConvertToOldFormat(p); + delete p; //currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1); } } diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index b615e4ead..43c9464e7 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -213,7 +213,7 @@ void CBattleInterface::show(SDL_Surface * to) } } //showing selected unit's range - if(creAnims[activeStack]->getType() != 0) //don't show if unit is moving + if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //don't show if unit is moving { showRange(to, activeStack); } @@ -240,37 +240,68 @@ void CBattleInterface::show(SDL_Surface * to) defendingHero->show(to); //showing units //a lot of work... - int stackByHex[187]; - for(int b=0; b<187; ++b) - stackByHex[b] = -1; + std::vector stackAliveByHex[187]; + //double loop because dead stacks should be printed first for(std::map::iterator j=stacks.begin(); j!=stacks.end(); ++j) { - stackByHex[j->second.position] = j->second.ID; + if(j->second.alive) + stackAliveByHex[j->second.position].push_back(j->second.ID); + } + std::vector stackDeadByHex[187]; + for(std::map::iterator j=stacks.begin(); j!=stacks.end(); ++j) + { + if(!j->second.alive) + stackDeadByHex[j->second.position].push_back(j->second.ID); } attackingShowHelper(); // handle attack animation - for(int b=0; b<187; ++b) + for(int b=0; b<187; ++b) //showing dead stacks { - if(stackByHex[b]!=-1) + for(int v=0; vnextFrame(to, creAnims[stackByHex[b]]->pos.x, creAnims[stackByHex[b]]->pos.y, creDir[stackByHex[b]], (animCount%2==0 || creAnims[stackByHex[b]]->getType()!=2) && stacks[stackByHex[b]].alive, stackByHex[b]==activeStack); //increment always when moving, never if stack died + creAnims[stackDeadByHex[b][v]]->nextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x, creAnims[stackDeadByHex[b][v]]->pos.y, creDir[stackDeadByHex[b][v]], (animCount%2==0 || creAnims[stackDeadByHex[b][v]]->getType()!=2) && stacks[stackDeadByHex[b][v]].alive, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died //printing amount - if(stacks[stackByHex[b]].amount > 0) //don't print if stack is not alive + if(stacks[stackDeadByHex[b][v]].amount > 0) //don't print if stack is not alive { - if(stacks[stackByHex[b]].attackerOwned) + if(stacks[stackDeadByHex[b][v]].attackerOwned) { - CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b]]->pos.x + 220, creAnims[stackByHex[b]]->pos.y + 260)); + CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackDeadByHex[b][v]]->pos.x + 220, creAnims[stackDeadByHex[b][v]]->pos.y + 260)); std::stringstream ss; - ss<pos.x + 220 + 14, creAnims[stackByHex[b]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); + ss<pos.x + 220 + 14, creAnims[stackDeadByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); } else { - CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b]]->pos.x + 202, creAnims[stackByHex[b]]->pos.y + 260)); + CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackDeadByHex[b][v]]->pos.x + 202, creAnims[stackDeadByHex[b][v]]->pos.y + 260)); std::stringstream ss; - ss<pos.x + 202 + 14, creAnims[stackByHex[b]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); + ss<pos.x + 202 + 14, creAnims[stackDeadByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); + } + } + } + } + for(int b=0; b<187; ++b) //showing alive stacks + { + for(int v=0; vnextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], (animCount%2==0 || creAnims[stackAliveByHex[b][v]]->getType()!=2) && stacks[stackAliveByHex[b][v]].alive, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died + //printing amount + if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive + { + if(stacks[stackAliveByHex[b][v]].attackerOwned) + { + CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + 220, creAnims[stackAliveByHex[b][v]]->pos.y + 260)); + std::stringstream ss; + ss<pos.x + 220 + 14, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); + } + else + { + CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + 202, creAnims[stackAliveByHex[b][v]]->pos.y + 260)); + std::stringstream ss; + ss<pos.x + 202 + 14, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to); } } } @@ -1113,12 +1144,11 @@ bool CBattleConsole::addText(std::string text) { texts.push_back( text.substr(firstInToken, i-firstInToken) ); firstInToken = i+1; - lastShown++; } } texts.push_back( text.substr(firstInToken, text.size()) ); - lastShown++; + lastShown = texts.size()-1; return true; } diff --git a/CBattleInterface.h b/CBattleInterface.h index 56fe34a1b..534b83e6a 100644 --- a/CBattleInterface.h +++ b/CBattleInterface.h @@ -35,7 +35,7 @@ public: bool hovered, strictHovered; CBattleInterface * myInterface; //interface that owns me static std::pair getXYUnitAnim(int hexNum, bool attacker, CCreature * creature); //returns (x, y) of left top corner of animation - static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left) + static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left) //for user interactions void hover (bool on); void activate(); diff --git a/CCallback.cpp b/CCallback.cpp index 7f5f0b248..86ab8b2c5 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -132,9 +132,10 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) { hero->pos = endpos; }*/ - if((hero->movement>=CGI->mh->getCost(int3(stpos.x-1, stpos.y, stpos.z), int3(endpos.x-1, endpos.y, endpos.z), hero)) || player==-1) + if(hero->movement >= (ourPath->nodes.size()>=2 ? (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist || player==-1) { //performing move - hero->movement-=CGI->mh->getCost(int3(stpos.x-1, stpos.y, stpos.z), int3(endpos.x-1, endpos.y, endpos.z), hero); + hero->movement -= (ourPath->nodes.size()>=2 ? (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist; + ourPath->nodes.pop_back(); std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.dst,false)); bool blockvis = false; diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index a5b201b4b..f532e872b 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -16,6 +16,13 @@ #include "hch/CLodHandler.h" #include "boost/filesystem/operations.hpp" #include +#ifdef WIN32 +#include +#else +#endif + +bool continueReadingConsole = true; + int internalFunc(void * callback) { CCallback * cb = (CCallback*)callback; @@ -23,119 +30,127 @@ int internalFunc(void * callback) std::string readed; while(true) { - std::cin.getline(usersMessage, 500); - std::istringstream readed; - std::string pom(usersMessage); - readed.str(pom); - std::string cn; //command name - readed >> cn; - int3 src, dst; - - int heronum; - int3 dest; - - if(pom==std::string("die, fool")) - exit(0); - else if(pom==std::string("get txt")) +#ifdef WIN32 + if(continueReadingConsole && kbhit()) +#else +#endif { - boost::filesystem::create_directory("Extracted_txts"); - std::cout<<"Command accepted. Opening .lod file...\t"; - CLodHandler * txth = new CLodHandler; - txth->init(std::string("Data\\H3bitmap.lod"),"Data"); - std::cout<<"done.\nScanning .lod file\n"; - int curp=0; - std::string pattern = ".TXT"; - for(int i=0;ientries.size(); i++) + std::cin.getline(usersMessage, 500); + std::istringstream readed; + std::string pom(usersMessage); + readed.str(pom); + std::string cn; //command name + readed >> cn; + int3 src, dst; + + int heronum; + int3 dest; + + if(pom==std::string("die, fool")) + exit(0); + else if(pom==std::string("get txt")) { - std::string pom = txth->entries[i].nameStr; - if(boost::algorithm::find_last(pom,pattern)) + boost::filesystem::create_directory("Extracted_txts"); + std::cout<<"Command accepted. Opening .lod file...\t"; + CLodHandler * txth = new CLodHandler; + txth->init(std::string("Data\\H3bitmap.lod"),"data"); + std::cout<<"done.\nScanning .lod file\n"; + int curp=0; + std::string pattern = ".TXT"; + for(int i=0;ientries.size(); i++) { - txth->extractFile(std::string("Extracted_txts\\")+pom,pom); - } - int p2 = ((float)i/(float)txth->entries.size())*(float)100; - if(p2!=curp) - { - curp = p2; - std::cout<<"\r"<entries[i].nameStr; + if(boost::algorithm::find_last(pom,pattern)) + { + txth->extractFile(std::string("Extracted_txts\\")+pom,pom); + } + int p2 = ((float)i/(float)txth->entries.size())*(float)100; + if(p2!=curp) + { + curp = p2; + std::cout<<"\r"<* p; - switch (*cn.c_str()) - { - //case 'P': - // std::cout<<"Policzyc sciezke."<>src>>dst; - // - // p = CGI->pathf->GetPath(Coordinate(src),Coordinate(dst),CGI->heroh->heroInstances[0]); - // LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->ConvertToOldFormat(p); - //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]); - //break; - case 'm': //number of heroes - std::cout<<"Number of heroes: "<mh->map->heroes.size()<>heronum; - std::cout<<"Position of hero "<mh->map->heroes[heronum]->getPosition(false)<* p; + switch (*cn.c_str()) { - readed>>heronum>>dest; - const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0); - p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero); - cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0); - //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]); + //case 'P': + // std::cout<<"Policzyc sciezke."<>src>>dst; + // + // p = CGI->pathf->GetPath(Coordinate(src),Coordinate(dst),CGI->heroh->heroInstances[0]); + // LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->ConvertToOldFormat(p); + // //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]); + // break; + //case 'm': //number of heroes + // std::cout<<"Number of heroes: "<heroh->heroInstances.size()<>heronum; + // std::cout<<"Position of hero "<heroh->heroInstances[heronum]->getPosition(false)<>heronum>>dest; + const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0); + p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero); + cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0); + //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]); + break; + } + case 'D': //pos description + readed>>src; + CGI->mh->getObjDescriptions(src); break; - } - case 'D': //pos description - readed>>src; - CGI->mh->getObjDescriptions(src); - break; - case 'I': - { - SDL_Surface * temp = LOCPLINT->infoWin(NULL); - blitAtWR(temp,605,389); - SDL_FreeSurface(temp); - break; - } - case 'T': //test rect - readed>>src; - for(int g=0; g<8; ++g) - { - for(int v=0; v<8; ++v) + case 'I': { - int3 csrc = src; - csrc.y+=g; - csrc.x+=v; - if(CGI->mh->getObjDescriptions(csrc).size()) - std::cout<<'x'; - else - std::cout<<'o'; + SDL_Surface * temp = LOCPLINT->infoWin(NULL); + blitAtWR(temp,605,389); + SDL_FreeSurface(temp); + break; } - std::cout<>src; + for(int g=0; g<8; ++g) + { + for(int v=0; v<8; ++v) + { + int3 csrc = src; + csrc.y+=g; + csrc.x+=v; + if(CGI->mh->getObjDescriptions(csrc).size()) + std::cout<<'x'; + else + std::cout<<'o'; + } + std::cout<objh->objInstances.size(); ++c) + // { + // CGI->mh->hideObject(CGI->objh->objInstances[c]); + // } + // break; + //case 'R': //restora all objects after A has been pressed + // for(int c=0; cobjh->objInstances.size(); ++c) + // { + // CGI->mh->printObject(CGI->objh->objInstances[c]); + // } + // break; } - break; - case 'A': //hide everything from map - for(int c=0; cmh->map->objects.size(); ++c) - { - CGI->mh->hideObject(CGI->mh->map->objects[c]); - } - break; - case 'R': //restora all objects after A has been pressed - for(int c=0; cmh->map->objects.size(); ++c) - { - CGI->mh->printObject(CGI->mh->map->objects[c]); - } - break; + //SDL_Delay(100); + delete p; } - //SDL_Delay(100); - delete p; } return -1; } +SDL_Thread * consoleReadingThread; + void CConsoleHandler::runConsole() { - SDL_Thread * myth = SDL_CreateThread(&internalFunc, cb); + consoleReadingThread = SDL_CreateThread(&internalFunc, cb); } diff --git a/CGameState.cpp b/CGameState.cpp index ca573cb26..9488b39f4 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -4,6 +4,7 @@ #include #include "SDL_Thread.h" #include "SDL_Extensions.h" +#include "CBattleInterface.h" //for CBattleHex #include @@ -161,7 +162,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C else if(j->first == curB->side2) //player is defender side = true; else - return; //no witnesses + continue; //no witnesses if(CGI->playerint[j->second.serial]->human) { ((CPlayerInterface*)( CGI->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); @@ -283,9 +284,12 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) || (curB->stacks[g]->creature->isDoubleWide() && curB->stacks[g]->attackerOwned && curB->stacks[g]->position-1 == dest) || (curB->stacks[g]->creature->isDoubleWide() && !curB->stacks[g]->attackerOwned && curB->stacks[g]->position+1 == dest)) { - stackAtEnd = true; - numberOfStackAtEnd = g; - break; + if(curB->stacks[g]->alive) + { + stackAtEnd = true; + numberOfStackAtEnd = g; + break; + } } } @@ -307,7 +311,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) accessibility[k] = true; for(int g=0; gstacks.size(); ++g) { - if(curB->stacks[g]->ID != ID) //we don't want to lock enemy's positions and this units' position + if(curB->stacks[g]->ID != ID && curB->stacks[g]->alive) //we don't want to lock enemy's positions and this units' position { accessibility[curB->stacks[g]->position] = false; if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature @@ -402,7 +406,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) } } //following the Path - if(dists[dest] > curStack->creature->speed) + if(dists[dest] > curStack->creature->speed && !(stackAtEnd && dists[dest] == curStack->creature->speed+1)) //we can attack a stack if we can go to adjacent hex return false; std::vector path; int curElem = dest; @@ -544,7 +548,7 @@ std::vector CGameState::battleGetRange(int ID) accessibility[k] = true; for(int g=0; gstacks.size(); ++g) { - if(curB->stacks[g]->ID != ID) //we don't want to lock current unit's position + if(curB->stacks[g]->ID != ID && curB->stacks[g]->alive) //we don't want to lock current unit's position { accessibility[curB->stacks[g]->position] = false; if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature @@ -637,6 +641,46 @@ std::vector CGameState::battleGetRange(int ID) ret.push_back(i); } } - return ret; + + std::vector additionals; + + //adding enemies' positions + for(int c=0; cstacks.size(); ++c) + { + if(curB->stacks[c]->alive && curB->stacks[c]->owner != owner) + { + for(int g=0; gstacks[c]->position) != -1) + { + additionals.push_back(curB->stacks[c]->position); + } + if(curB->stacks[c]->creature->isDoubleWide() && curB->stacks[c]->attackerOwned && CBattleHex::mutualPosition(ret[g], curB->stacks[c]->position-1) != -1) + { + additionals.push_back(curB->stacks[c]->position-1); + } + if(curB->stacks[c]->creature->isDoubleWide() && !curB->stacks[c]->attackerOwned && CBattleHex::mutualPosition(ret[g], curB->stacks[c]->position+1) != -1) + { + additionals.push_back(curB->stacks[c]->position+1); + } + } + } + } + for(int g=0; g::iterator nend = std::unique(ret.begin(), ret.end()); + + std::vector ret2; + + for(std::vector::iterator it = ret.begin(); it != nend; ++it) + { + ret2.push_back(*it); + } + + return ret2; } diff --git a/CGameState.h b/CGameState.h index c5a7100a2..e4e891e43 100644 --- a/CGameState.h +++ b/CGameState.h @@ -13,6 +13,7 @@ class CCreatureSet; class CStack; class CGHeroInstance; class CArmedInstance; +struct Mapa; struct PlayerState { @@ -56,12 +57,13 @@ public: class CGameState { private: - int currentPlayer; + int currentPlayer; //ID of player currently having turn BattleInfo *curB; //current battle int day; //total number of days in game - std::map players; //color <-> playerstate - std::set cppscripts; - std::map > objscr; //custom user scripts (as for now only Lua) + Mapa * map; + std::map players; //ID <-> playerstate + std::set cppscripts; //C++ scripts + std::map > objscr; //non-C++ scripts bool checkFunc(int obid, std::string name) diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index e67978534..defd056d8 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -43,8 +43,9 @@ CHeroWindow::CHeroWindow(int playerColor): gar1button = new AdventureMapButton(CGI->generaltexth->heroscrn[23], CGI->generaltexth->heroscrn[29], boost::bind(&CHeroWindow::gar1,this), 546, 491, "hsbtns6.def", false, NULL, false); gar2button = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::gar2,this), 604, 491, "hsbtns8.def", false, NULL, false); gar3button = new AdventureMapButton(CGI->generaltexth->heroscrn[24], CGI->generaltexth->heroscrn[30], boost::bind(&CHeroWindow::gar3,this), 546, 527, "hsbtns7.def", false, NULL, false); - gar4button = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[32], boost::bind(&CGarrisonInt::splitClick,garInt), 604, 527, "hsbtns9.def", false, NULL, false); + gar4button = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[32], boost::function(), 604, 527, "hsbtns9.def", false, NULL, false); + //boost::bind(&CGarrisonInt::splitClick,garInt) leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::leftArtRoller,this), 379, 364, "hsbtns3.def", false, NULL, false); rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::rightArtRoller,this), 632, 364, "hsbtns5.def", false, NULL, false); @@ -207,6 +208,8 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero) delete garInt; /*gar4button->owner = */garInt = new CGarrisonInt(80, 493, 8, 0, curBack, 13, 482, curHero); garInt->update = false; + gar4button->callback = boost::bind(&CGarrisonInt::splitClick,garInt);//actualization of callback function + for(int g=0; gbonus = hero->primSkills[g]; diff --git a/CMT.cpp b/CMT.cpp index 5ad67663e..8bee31431 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -492,21 +492,18 @@ int _tmain(int argc, _TCHAR* argv[]) initTable[ss] = mapstr[ss]; } std::cout<<"done."<deh3m(); - THC std::cout<<"Detecting file (together): "<mh = mh; - mh->map = &ac->map; + mh->map = mapa; THC std::cout<<"Creating mapHandler: "<loadDefs(); THC std::cout<<"Reading terrain defs: "<init(); THC std::cout<<"Initializing mapHandler (together): "<map,cgi); + initGameState(mapa,cgi); THC std::cout<<"Initializing GameState (together): "<scenarioOps.playerInfos.size();i++) //initializing interfaces { diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 3510918a2..4fca779c7 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -149,33 +149,33 @@ void CPathfinder::AddNeighbors(vector* branch) // 6 7 8 Coordinate node = branch->back(); - Coordinate* c; + Coordinate c; for(int i = node.x-1; i 0 && j > 0 && i < CGI->mh->sizes.x-1 && j < CGI->mh->sizes.y-1) + if(i >= 0 && j >= 0 && i < CGI->mh->sizes.x && j < CGI->mh->sizes.y) { - c = new Coordinate(i,j,node.z); + c = Coordinate(i,j,node.z); //Calculate the distance from the end node - CalcG(c); + CalcG(&c); //Calculate the movement cost - CalcH(c); + CalcH(&c); - if(c->g != -1 && c->h != -1) + if(c.g != -1 && c.h != -1) { vector toAdd = *branch; - toAdd.push_back(*c); + toAdd.push_back(c); Open.push(toAdd); } + //delete c; } } } - delete c; } /* @@ -238,6 +238,8 @@ CPath* CPathfinder::ConvertToOldFormat(vector* p) CPath* path = new CPath(); + std::vector costs; //vector with costs of tiles + for(int i = 0; i < p->size(); i++) { CPathNode temp; @@ -256,19 +258,16 @@ CPath* CPathfinder::ConvertToOldFormat(vector* p) } //set diagonality float diagonal = 1.0f; //by default - if(i+1size()) + if(i>0) { - if(p->at(i+1).x != temp.coord.x && p->at(i+1).y != temp.coord.y) + if(p->at(i-1).x != temp.coord.x && p->at(i-1).y != temp.coord.y) { diagonal = sqrt(2.0f); } } //Set distance - if(i == 0) - temp.dist = p->at(i).h * diagonal; - else - temp.dist = p->at(i).h * diagonal + path->nodes.back().dist; + costs.push_back( i==0 ? 0 : p->at(i - 1).h * diagonal ); //theNodeBefore is never used outside of pathfinding? @@ -278,13 +277,10 @@ CPath* CPathfinder::ConvertToOldFormat(vector* p) path->nodes.push_back(temp); } - //YOU ARE ALL BACKWARDS!! =P - //Flip the distances. - for(int i = 0; i < path->nodes.size()/2;i++) + costs.push_back(0); + for(int i=path->nodes.size()-1; i>=0; --i) { - int t = path->nodes[i].dist; - path->nodes[i].dist = path->nodes[path->nodes.size()-i-1].dist; - path->nodes[path->nodes.size()-i-1].dist = t; + path->nodes[i].dist = costs[i+1] + ((i == path->nodes.size()-1) ? 0 : path->nodes[i+1].dist); } return path; diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 74b5b35a9..5288fd250 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -31,6 +31,7 @@ using namespace CSDL_Ext; extern TTF_Font * GEOR16; +extern bool continueReadingConsole; class OCM_HLP_CGIN { @@ -1705,6 +1706,7 @@ void CPlayerInterface::handleKeyDown(SDL_Event *sEvent) } case (SDLK_q): { + continueReadingConsole = false; exit(0); break; } diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index 49418cda9..91539b02c 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -1,2095 +1,43 @@ -#define VCMI_DLL -#include "../stdafx.h" -#include "CAmbarCendamo.h" -#include "CObjectHandler.h" -#include "CDefObjInfoHandler.h" -#include -#include -#include -#include "../lib/VCMI_Lib.h" -std::string nameFromType (EterrainType typ); -int readInt(unsigned char * bufor, int bytCon) -{ - int ret=0; - int amp=1; - for (int i=0; i>i) - { - ret |= (128>>i); - } - } - return ret; -} -CAmbarCendamo::CAmbarCendamo (unsigned char * map) -{ - bufor=map; -} -CAmbarCendamo::CAmbarCendamo (const char * tie) -{ - std::ifstream * is = new std::ifstream(); - is -> open(tie,std::ios::binary); - is->seekg(0,std::ios::end); // na koniec - int andame = is->tellg(); // read length - is->seekg(0,std::ios::beg); // wracamy na poczatek - bufor = new unsigned char[andame]; // allocate memory - is->read((char*)bufor, andame); // read map file to buffer - is->close(); - delete is; -} -CAmbarCendamo::~CAmbarCendamo () -{// free memory - for (int ii=0;ii convertBuildings(const std::set h3m, int castleID) -{ - std::map mapa; - std::set ret; - std::ifstream b5("config/buildings5.txt"); - while(!b5.eof()) - { - int a, b; - b5 >> a >> b; - if(castleID==8 && b==17) //magic university ID 17 (h3m) => 21 (vcmi) - b=21; - mapa[a]=b; - } - - for(std::set::const_iterator i=h3m.begin();i!=h3m.end();i++) - { - if(mapa[*i]>=0) - ret.insert(mapa[*i]); - else if(mapa[*i] >= (-CREATURES_PER_TOWN)) // horde buildings - { - int level = (-mapa[*i]); - if(h3m.find(20+(level*3)) != h3m.end()) //upgraded creature horde building - { - if(((castleID==1) || (castleID==3)) && ((level==3) || (level==5))) - ret.insert(25); - else - ret.insert(19); - } - else - { - if(((castleID==1) || (castleID==3)) && ((level==3) || (level==5))) - ret.insert(24); - else - ret.insert(18); - } - } - else - { - std::cout<<"Conversion warning: unknown building "<<*i<<" in castle "<ArtifactID = bufor[i+2]; - nr=(map.version==RoE ? 1 : 2); - break; - } - case gatherTroop: - { - map.vicConDetails = new VicCon1(); - int temp1 = bufor[i+2]; - int temp2 = bufor[i+3]; - ((VicCon1*)map.vicConDetails)->monsterID = bufor[i+2]; - ((VicCon1*)map.vicConDetails)->neededQuantity=readNormalNr(i+(map.version==RoE ? 3 : 4)); - nr=(map.version==RoE ? 5 : 6); - break; - } - case gatherResource: - { - map.vicConDetails = new VicCon2(); - ((VicCon2*)map.vicConDetails)->resourceID = bufor[i+2]; - ((VicCon2*)map.vicConDetails)->neededQuantity=readNormalNr(i+3); - nr=5; - break; - } - case buildCity: - { - map.vicConDetails = new VicCon3(); - ((VicCon3*)map.vicConDetails)->posOfCity.x = bufor[i+2]; - ((VicCon3*)map.vicConDetails)->posOfCity.y = bufor[i+3]; - ((VicCon3*)map.vicConDetails)->posOfCity.z = bufor[i+4]; - ((VicCon3*)map.vicConDetails)->councilNeededLevel = bufor[i+5]; - ((VicCon3*)map.vicConDetails)->fortNeededLevel = bufor[i+6]; - nr=5; - break; - } - case buildGrail: - { - map.vicConDetails = new VicCon4(); - if (bufor[i+4]>2) - ((VicCon4*)map.vicConDetails)->anyLocation = true; - else - { - ((VicCon4*)map.vicConDetails)->whereBuildGrail.x = bufor[i+2]; - ((VicCon4*)map.vicConDetails)->whereBuildGrail.y = bufor[i+3]; - ((VicCon4*)map.vicConDetails)->whereBuildGrail.z = bufor[i+4]; - } - nr=3; - break; - } - case beatHero: - { - map.vicConDetails = new VicCon5(); - ((VicCon5*)map.vicConDetails)->locationOfHero.x = bufor[i+2]; - ((VicCon5*)map.vicConDetails)->locationOfHero.y = bufor[i+3]; - ((VicCon5*)map.vicConDetails)->locationOfHero.z = bufor[i+4]; - nr=3; - break; - } - case captureCity: - { - map.vicConDetails = new VicCon6(); - ((VicCon6*)map.vicConDetails)->locationOfTown.x = bufor[i+2]; - ((VicCon6*)map.vicConDetails)->locationOfTown.y = bufor[i+3]; - ((VicCon6*)map.vicConDetails)->locationOfTown.z = bufor[i+4]; - nr=3; - break; - } - case beatMonster: - { - map.vicConDetails = new VicCon7(); - ((VicCon7*)map.vicConDetails)->locationOfMonster.x = bufor[i+2]; - ((VicCon7*)map.vicConDetails)->locationOfMonster.y = bufor[i+3]; - ((VicCon7*)map.vicConDetails)->locationOfMonster.z = bufor[i+4]; - nr=3; - break; - } - case takeDwellings: - { - map.vicConDetails = new CspecificVictoryConidtions(); - nr=0; - break; - } - case takeMines: - { - map.vicConDetails = new CspecificVictoryConidtions(); - nr=0; - break; - } - case transportItem: - { - map.vicConDetails = new VicCona(); - ((VicCona*)map.vicConDetails)->artifactID = bufor[i+2]; - ((VicCona*)map.vicConDetails)->destinationPlace.x = bufor[i+3]; - ((VicCona*)map.vicConDetails)->destinationPlace.y = bufor[i+4]; - ((VicCona*)map.vicConDetails)->destinationPlace.z = bufor[i+5]; - nr=4; - break; - } - } - map.vicConDetails->allowNormalVictory = bufor[i++]; - map.vicConDetails->appliesToAI = bufor[i++]; - i+=nr; - } - map.lossCondition.typeOfLossCon = (ElossCon)bufor[i++]; - switch (map.lossCondition.typeOfLossCon) //read loss conditions - { - case lossCastle: - { - map.lossCondition.castlePos.x=bufor[i++]; - map.lossCondition.castlePos.y=bufor[i++]; - map.lossCondition.castlePos.z=bufor[i++]; - break; - } - case lossHero: - { - map.lossCondition.heroPos.x=bufor[i++]; - map.lossCondition.heroPos.y=bufor[i++]; - map.lossCondition.heroPos.z=bufor[i++]; - break; - } - case timeExpires: - { - map.lossCondition.timeLimit = readNormalNr(i++,2); - i++; - break; - } - } - map.howManyTeams=bufor[i++]; //read number of teams - if(map.howManyTeams>0) //read team numbers - { - for(int rr=0; rr<8; ++rr) - { - map.players[rr].team=bufor[i++]; - } - } - //reading allowed heroes (20 bytes) - int ist; - - ist=i; //starting i for loop - - map.allowedHeroes.resize(HEROES_QUANTITY); - for(int xx=0;xxRoE) //probably reserved for further heroes - i+=4; - unsigned char disp = 0; - if(map.version>=SoD) - { - disp = bufor[i++]; - map.disposedHeroes.resize(disp); - for(int g=0; g=SoD) - { - //reading allowed spells (9 bytes) - ist=i; //starting i for loop - for(i; iID = 34; - cgh->subID = z; - if(readChar())//true if hore's experience is greater than 0 - { cgh->exp = readNormalNr(i); i+=4; } - else - cgh->exp = 0; - if(readChar())//true if hero has specified abilities - { - int howMany = readNormalNr(i); i+=4; - cgh->secSkills.resize(howMany); - for(int yy=0; yysecSkills[yy].first = readNormalNr(i, 1); ++i; - cgh->secSkills[yy].second = readNormalNr(i, 1); ++i; - } - } - bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts) - int artmask = map.version == RoE ? 0xff : 0xffff; - int artidlen = map.version == RoE ? 1 : 2; - if(artSet) - { - for(int pom=0;pom<16;pom++) - { - int id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - cgh->artifWorn[pom] = id; - } - //misc5 art //17 - if(map.version>=SoD) - { - i+=2; - //int id = readNormalNr(i, artidlen); i+=artidlen; - //if(id!=artmask) - // spec->artifWorn[16] = id; - } - //spellbook - int id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - cgh->artifWorn[17] = id; - //19 //???what is that? gap in file or what? - it's probably fifth slot.. - if(map.version>RoE) - { - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - cgh->artifWorn[18] = id; - } - else - i+=1; - //bag artifacts //20 - int amount = readNormalNr(i, 2); i+=2; //number of artifacts in hero's bag - if(amount>0) - { - for(int ss=0; ssartifacts.push_back(id); - } - } - } //artifacts - if(readChar())//customBio - cgh->biography = readString(); - int sex = bufor[i++]; // 0xFF is default, 00 male, 01 female - if(readChar())//are spells - { - int ist = i; - for(i; ispells.insert((i-ist)*8+yy); - } - } - } - } - if(readChar())//customPrimSkills - { - cgh->primSkills.resize(4); - for(int xx=0;xx<4;xx++) - cgh->primSkills[xx] = bufor[i++]; - } - map.predefinedHeroes.push_back(cgh); - } - break; - } - case RoE: - i+=0; - break; - } - for (int c=0; cname.reserve(nameLength); - for (int cd=0;cdname += bufor[i++]; - } - std::transform(vinya->name.begin(),vinya->name.end(),vinya->name.begin(),(int(*)(int))toupper); - - - unsigned char bytes[12]; - for (int v=0; v<12; v++) // read info - { - bytes[v] = bufor[i++]; - } - vinya->terrainAllowed = readNormalNr(i,2);i+=2; - vinya->terrainMenu = readNormalNr(i,2);i+=2; - vinya->id = readNormalNr(i,4);i+=4; - vinya->subid = readNormalNr(i,4);i+=4; - vinya->type = bufor[i++]; - vinya->printPriority = bufor[i++]; - for (int zi=0; zi<6; zi++) - { - vinya->blockMap[zi] = reverse(bytes[zi]); - } - for (int zi=0; zi<6; zi++) - { - vinya->visitMap[zi] = reverse(bytes[6+zi]); - } - i+=16; - map.defy.push_back(vinya); // add this def to the vector - } - THC std::cout<<"\tReading defs info: "<defInfo->id; - int p = 99; - switch(getDefType(nobj->defInfo)) - { - case EDefType::EVENTOBJ_DEF: //for event - objects - { - CEventObjInfo * spec = new CEventObjInfo; - bool guardMess; - guardMess = bufor[i]; ++i; - if(guardMess) - { - int messLong = readNormalNr(i, 4); i+=4; - if(messLong>0) - { - spec->isMessage = true; - for(int yy=0; yymessage +=bufor[i+yy]; - } - i+=messLong; - } - spec->areGuarders = bufor[i]; ++i; - if(spec->areGuarders) - { - spec->guarders = readCreatureSet(); - } - i+=4; - } - else - { - spec->isMessage = false; - spec->areGuarders = false; - spec->message = std::string(""); - } - spec->gainedExp = readNormalNr(i, 4); i+=4; - spec->manaDiff = readNormalNr(i, 4); i+=4; - spec->moraleDiff = readNormalNr(i, 1, true); ++i; - spec->luckDiff = readNormalNr(i, 1, true); ++i; - spec->wood = readNormalNr(i); i+=4; - spec->mercury = readNormalNr(i); i+=4; - spec->ore = readNormalNr(i); i+=4; - spec->sulfur = readNormalNr(i); i+=4; - spec->crystal = readNormalNr(i); i+=4; - spec->gems = readNormalNr(i); i+=4; - spec->gold = readNormalNr(i); i+=4; - spec->attack = readNormalNr(i, 1); ++i; - spec->defence = readNormalNr(i, 1); ++i; - spec->power = readNormalNr(i, 1); ++i; - spec->knowledge = readNormalNr(i, 1); ++i; - int gabn; //number of gained abilities - gabn = readNormalNr(i, 1); ++i; - for(int oo = 0; ooabilities.push_back(readNormalNr(i, 1)); ++i; - spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i; - } - int gart = readNormalNr(i, 1); ++i; //number of gained artifacts - for(int oo = 0; ooartifacts.push_back(readNormalNr(i, (map.version == RoE ? 1 : 2))); i+=(map.version == RoE ? 1 : 2); - } - int gspel = readNormalNr(i, 1); ++i; //number of gained spells - for(int oo = 0; oospells.push_back(readNormalNr(i, 1)); ++i; - } - int gcre = readNormalNr(i, 1); ++i; //number of gained creatures - spec->creatures = readCreatureSet(gcre); - if(map.version>RoE) - i+=gcre; - i+=8; - spec->availableFor = readNormalNr(i, 1); ++i; - spec->computerActivate = readNormalNr(i, 1); ++i; - spec->humanActivate = readNormalNr(i, 1); ++i; - i+=4; - nobj->info = spec; - break; - } - case EDefType::HERO_DEF: - { - CGHeroInstance * nhi = new CGHeroInstance; - (*(static_cast(nhi))) = *nobj; - delete nobj; - nobj=nhi; - if(map.version>RoE) - { - nhi->identifier = readNormalNr(i, 4); i+=4; - } - nhi->setOwner(bufor[i]); ++i; - nhi->subID = readNormalNr(i, 1); ++i; - if(readChar())//true if hero has nonstandard name - nhi->name = readString(); - if(map.version>AB) - { - if(readChar())//true if hore's experience is greater than 0 - { nhi->exp = readNormalNr(i); i+=4; } - else - nhi->exp = -1; - } - else - { nhi->exp = readNormalNr(i); i+=4; } - - bool portrait=bufor[i]; ++i; - if (portrait) - i++; //TODO read portrait nr, save, open - - if(readChar())//true if hero has specified abilities - { - int howMany = readNormalNr(i); i+=4; - nhi->secSkills.resize(howMany); - for(int yy=0; yysecSkills[yy].first = readNormalNr(i, 1); ++i; - nhi->secSkills[yy].second = readNormalNr(i, 1); ++i; - } - } - if(readChar())//true if hero has nonstandard garrison - nhi->army = readCreatureSet(); - nhi->army.formation =bufor[i]; ++i; //formation - bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts) - int artmask = map.version == RoE ? 0xff : 0xffff; - int artidlen = map.version == RoE ? 1 : 2; - if(artSet) - { - for(int pom=0;pom<16;pom++) - { - int id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - nhi->artifWorn[pom] = id; - } - //misc5 art //17 - if(map.version>=SoD) - { - int id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - nhi->artifWorn[16] = id; - } - //spellbook - int id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - nhi->artifWorn[17] = id; - //19 //???what is that? gap in file or what? - it's probably fifth slot.. - if(map.version>RoE) - { - id = readNormalNr(i, artidlen); i+=artidlen; - if(id!=artmask) - nhi->artifWorn[18] = id; - } - else - i+=1; - //bag artifacts //20 - int amount = readNormalNr(i, 2); i+=2; //number of artifacts in hero's bag - if(amount>0) - { - for(int ss=0; ssartifacts.push_back(id); - } - } - } //artifacts - - nhi->patrol.patrolRadious = readNormalNr(i, 1); ++i; - if(nhi->patrol.patrolRadious == 0xff) - nhi->patrol.patrolling = false; - else - nhi->patrol.patrolling = true; - - if(map.version>RoE) - { - if(readChar())//true if hero has nonstandard (mapmaker defined) biography - nhi->biography = readString(); - nhi->sex = !(bufor[i]); ++i; - } - //spells - if(map.version>AB) - { - bool areSpells = bufor[i]; ++i; - - if(areSpells) //TODO: sprawdzić //seems to be ok - tow - { - int ist = i; - for(i; ispells.insert((i-ist)*8+yy); - } - } - } - } - } - else if(map.version==AB) //we can read one spell - { - unsigned char buff = bufor[i]; ++i; - if(buff!=254) - { - nhi->spells.insert(buff); - } - } - //spells loaded - if(map.version>AB) - { - if(readChar())//customPrimSkills - { - nhi->primSkills.resize(4); - for(int xx=0;xx<4;xx++) - nhi->primSkills[xx] = bufor[i++]; - } - } - i+=16; - nhi->moveDir = 4; - nhi->isStanding = true; - nhi->level = -1; - nhi->mana = -1; - nhi->movement = -1; - if(nhi->ID==34) - map.heroes.push_back(nhi); - //else - // CGI->objh->objInstances.push_back(nhi); - - break; - } - case CREATURES_DEF: - { - CCreatureObjInfo * spec = new CCreatureObjInfo; - if(map.version>RoE) - { - spec->bytes[0] = bufor[i]; ++i; - spec->bytes[1] = bufor[i]; ++i; - spec->bytes[2] = bufor[i]; ++i; - spec->bytes[3] = bufor[i]; ++i; - } - spec->number = readNormalNr(i, 2); i+=2; - spec->character = bufor[i]; ++i; - bool isMesTre = bufor[i]; ++i; //true if there is message or treasury - if(isMesTre) - { - int messLength = readNormalNr(i); i+=4; - if(messLength>0) - { - for(int tt=0; ttmessage += bufor[i]; ++i; - } - } - spec->wood = readNormalNr(i); i+=4; - spec->mercury = readNormalNr(i); i+=4; - spec->ore = readNormalNr(i); i+=4; - spec->sulfur = readNormalNr(i); i+=4; - spec->crytal = readNormalNr(i); i+=4; - spec->gems = readNormalNr(i); i+=4; - spec->gold = readNormalNr(i); i+=4; - int artID = readNormalNr(i, (map.version == RoE ? 1 : 2)); i+=(map.version == RoE ? 1 : 2); - if(map.version==RoE) - { - if(artID!=0xff) - spec->gainedArtifact = artID; - else - spec->gainedArtifact = -1; - } - else - { - if(artID!=0xffff) - spec->gainedArtifact = artID; - else - spec->gainedArtifact = -1; - } - } - spec->neverFlees = bufor[i]; ++i; - spec->notGrowingTeam = bufor[i]; ++i; - i+=2; - nobj->info = spec; - break; - } - case EDefType::SIGN_DEF: - { - CSignObjInfo * spec = new CSignObjInfo; - int length = readNormalNr(i); i+=4; - for(int rr=0; rrmessage += bufor[i]; ++i; - } - i+=4; - nobj->info = spec; - break; - } - case EDefType::SEERHUT_DEF: - { - CSeerHutObjInfo * spec = new CSeerHutObjInfo; - if(map.version>RoE) - { - spec->missionType = bufor[i]; ++i; - switch(spec->missionType) - { - case 0: - i+=3; - continue; - case 1: - { - spec->m1level = readNormalNr(i); i+=4; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 2: - { - spec->m2attack = bufor[i]; ++i; - spec->m2defence = bufor[i]; ++i; - spec->m2power = bufor[i]; ++i; - spec->m2knowledge = bufor[i]; ++i; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 3: - { - spec->m3bytes[0] = bufor[i]; ++i; - spec->m3bytes[1] = bufor[i]; ++i; - spec->m3bytes[2] = bufor[i]; ++i; - spec->m3bytes[3] = bufor[i]; ++i; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 4: - { - spec->m4bytes[0] = bufor[i]; ++i; - spec->m4bytes[1] = bufor[i]; ++i; - spec->m4bytes[2] = bufor[i]; ++i; - spec->m4bytes[3] = bufor[i]; ++i; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 5: - { - int artNumber = bufor[i]; ++i; - for(int yy=0; yym5arts.push_back(artid); - } - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 6: - { - int typeNumber = bufor[i]; ++i; - for(int hh=0; hhm6cre.push_back(&(VLC->creh->creatures[creType])); - spec->m6number.push_back(creNumb); - } - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 7: - { - spec->m7wood = readNormalNr(i); i+=4; - spec->m7mercury = readNormalNr(i); i+=4; - spec->m7ore = readNormalNr(i); i+=4; - spec->m7sulfur = readNormalNr(i); i+=4; - spec->m7crystal = readNormalNr(i); i+=4; - spec->m7gems = readNormalNr(i); i+=4; - spec->m7gold = readNormalNr(i); i+=4; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 8: - { - int heroType = bufor[i]; ++i; - spec->m8hero = heroType; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 9: - { - spec->m9player = bufor[i]; ++i; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - }//internal switch end (seer huts) - - int len1 = readNormalNr(i); i+=4; - for(int ee=0; eefirstVisitText += bufor[i]; ++i; - } - - int len2 = readNormalNr(i); i+=4; - for(int ee=0; eenextVisitText += bufor[i]; ++i; - } - - int len3 = readNormalNr(i); i+=4; - for(int ee=0; eecompletedText += bufor[i]; ++i; - } - } - else //RoE - { - int artID = bufor[i]; ++i; - if(artID!=255) //not none quest - { - spec->m5arts.push_back(artID); - spec->missionType = 5; - } - else - { - spec->missionType = 255; - } - } - - if(spec->missionType!=255) - { - unsigned char rewardType = bufor[i]; ++i; - spec->rewardType = rewardType; - - switch(rewardType) - { - case 1: - { - spec->r1exp = readNormalNr(i); i+=4; - break; - } - case 2: - { - spec->r2mana = readNormalNr(i); i+=4; - break; - } - case 3: - { - spec->r3morale = bufor[i]; ++i; - break; - } - case 4: - { - spec->r4luck = bufor[i]; ++i; - break; - } - case 5: - { - spec->r5type = bufor[i]; ++i; - spec->r5amount = readNormalNr(i, 3); i+=3; - i+=1; - break; - } - case 6: - { - spec->r6type = bufor[i]; ++i; - spec->r6amount = bufor[i]; ++i; - break; - } - case 7: - { - spec->r7ability = bufor[i]; ++i; - spec->r7level = bufor[i]; ++i; - break; - } - case 8: - { - spec->r8art = readNormalNr(i, (map.version == RoE ? 1 : 2)); i+=(map.version == RoE ? 1 : 2); - break; - } - case 9: - { - spec->r9spell = bufor[i]; ++i; - break; - } - case 10: - { - if(map.version>RoE) - { - spec->r10creature = readNormalNr(i, 2); i+=2; - spec->r10amount = readNormalNr(i, 2); i+=2; - } - else - { - spec->r10creature = bufor[i]; ++i; - spec->r10amount = readNormalNr(i, 2); i+=2; - } - break; - } - }// end of internal switch - i+=2; - } - else //missionType==255 - { - i+=3; - } - nobj->info = spec; - break; - } - case EDefType::WITCHHUT_DEF: - { - CWitchHutObjInfo * spec = new CWitchHutObjInfo; - if(map.version>RoE) //in reo we cannot specify it - all are allowed (I hope) - { - ist=i; //starting i for loop - for(i; iallowedAbilities.push_back((i-ist)*8+yy); - } - } - } - } - else //(RoE map) - { - for(int gg=0; ggallowedAbilities.push_back(gg); - } - } - - nobj->info = spec; - break; - } - case EDefType::SCHOLAR_DEF: - { - CScholarObjInfo * spec = new CScholarObjInfo; - spec->bonusType = bufor[i]; ++i; - switch(spec->bonusType) - { - case 0xff: - ++i; - break; - case 0: - spec->r0type = bufor[i]; ++i; - break; - case 1: - spec->r1 = bufor[i]; ++i; - break; - case 2: - spec->r2 = bufor[i]; ++i; - break; - } - i+=6; - nobj->info = spec; - break; - } - case EDefType::GARRISON_DEF: - { - CGarrisonObjInfo * spec = new CGarrisonObjInfo; - spec->player = bufor[i]; ++i; - i+=3; - spec->units = readCreatureSet(); - if(map.version > RoE) - { - spec->movableUnits = bufor[i]; ++i; - } - else - spec->movableUnits = true; - i+=8; - nobj->setOwner(spec->player); - nobj->info = spec; - break; - } - case EDefType::ARTIFACT_DEF: - { - CArtifactObjInfo * spec = new CArtifactObjInfo; - bool areSettings = bufor[i]; ++i; - if(areSettings) - { - int messLength = readNormalNr(i, 4); i+=4; - for(int hh=0; hhmessage += bufor[i]; ++i; - } - bool areGuards = bufor[i]; ++i; - if(areGuards) - { - spec->areGuards = true; - spec->guards = readCreatureSet(); - } - else - spec->areGuards = false; - i+=4; - } - nobj->info = spec; - break; - } - case EDefType::RESOURCE_DEF: - { - CResourceObjInfo * spec = new CResourceObjInfo; - bool isMessGuard = bufor[i]; ++i; - if(isMessGuard) - { - int messLength = readNormalNr(i); i+=4; - for(int mm=0; mmmessage+=bufor[i]; ++i; - } - spec->areGuards = bufor[i]; ++i; - if(spec->areGuards) - { - spec->guards = readCreatureSet(); - } - i+=4; - } - else - { - spec->areGuards = false; - } - spec->amount = readNormalNr(i); i+=4; - i+=4; - nobj->info = spec; - break; - } - case EDefType::TOWN_DEF: - { - CGTownInstance * nt = new CGTownInstance(); - (*(static_cast(nt))) = *nobj; - delete nobj; - nobj = nt; - nt->identifier = 0; - if(map.version>RoE) - { - readNormalNr(i); i+=4; - } - nt->tempOwner = bufor[i]; ++i; - if(readChar()) //has name - nt->name = readString(); - if(readChar())//true if garrison isn't empty - nt->army = readCreatureSet(); - nt->army.formation = bufor[i]; ++i; - if(readChar()) //unusualBuildings - { - //built buildings - for(int byte=0;byte<6;byte++) - { - for(int bit=0;bit<8;bit++) - if(bufor[i] & (1<builtBuildings.insert(byte*8+bit); - i++; - } - //forbidden buildings - for(int byte=6;byte<12;byte++) - { - for(int bit=0;bit<8;bit++) - if(bufor[i] & (1<forbiddenBuildings.insert(byte*8+bit); - i++; - } - nt->builtBuildings = convertBuildings(nt->builtBuildings,nt->subID); - nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings,nt->subID); - } - else //standard buildings - { - if(readChar()) //has fort - nt->builtBuildings.insert(7); - nt->builtBuildings.insert(-50); //means that set of standard building should be included - } - - int ist = i; - if(map.version>RoE) - { - for(i; iobligatorySpells.push_back((i-ist)*8+yy); - } - } - } - } - - ist = i; - for(i; ipossibleSpells.push_back((i-ist)*8+yy); - } - } - } - - /////// reading castle events ////////////////////////////////// - - int numberOfEvent = readNormalNr(i); i+=4; - - for(int gh = 0; gh AB) - { - nce.forHuman = bufor[i]; ++i; - } - else - nce.forHuman = true; - nce.forComputer = bufor[i]; ++i; - nce.firstShow = readNormalNr(i, 2); i+=2; - nce.forEvery = bufor[i]; ++i; - - i+=17; - - for(int kk=0; kk<6; ++kk) - { - nce.bytes[kk] = bufor[i]; ++i; - } - - for(int vv=0; vv<7; ++vv) - { - nce.gen[vv] = readNormalNr(i, 2); i+=2; - } - i+=4; - nt->events.insert(nce); - }//castle events have been read - - if(map.version > AB) - { - nt->alignment = bufor[i]; ++i; - } - else - nt->alignment = 0xff; - i+=3; - - nt->builded = 0; - nt->destroyed = 0; - nt->garrisonHero = NULL; - map.towns.push_back(nt); - break; - } - case EDefType::PLAYERONLY_DEF: - { - CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo; - spec->player = bufor[i]; ++i; - i+=3; - nobj->setOwner(spec->player); - nobj->info = spec; - break; - } - case EDefType::SHRINE_DEF: - { - CShrineObjInfo * spec = new CShrineObjInfo; - spec->spell = bufor[i]; i+=4; - nobj->info = spec; - break; - } - case EDefType::SPELLSCROLL_DEF: - { - CSpellScrollObjinfo * spec = new CSpellScrollObjinfo; - bool messg = bufor[i]; ++i; - if(messg) - { - int mLength = readNormalNr(i); i+=4; - for(int vv=0; vvmessage += bufor[i]; ++i; - } - spec->areGuarders = bufor[i]; ++i; - if(spec->areGuarders) - { - spec->guarders = readCreatureSet(); - } - i+=4; - } - spec->spell = bufor[i]; ++i; - i+=3; - nobj->info = spec; - break; - } - case EDefType::PANDORA_DEF: - { - CPandorasBoxObjInfo * spec = new CPandorasBoxObjInfo; - bool messg = bufor[i]; ++i; - if(messg) - { - int mLength = readNormalNr(i); i+=4; - for(int vv=0; vvmessage += bufor[i]; ++i; - } - spec->areGuarders = bufor[i]; ++i; - if(spec->areGuarders) - { - spec->guarders = readCreatureSet(); - } - i+=4; - } - ////// copied form event handling (seems to be similar) - spec->gainedExp = readNormalNr(i, 4); i+=4; - spec->manaDiff = readNormalNr(i, 4); i+=4; - spec->moraleDiff = readNormalNr(i, 1, true); ++i; - spec->luckDiff = readNormalNr(i, 1, true); ++i; - spec->wood = readNormalNr(i); i+=4; - spec->mercury = readNormalNr(i); i+=4; - spec->ore = readNormalNr(i); i+=4; - spec->sulfur = readNormalNr(i); i+=4; - spec->crystal = readNormalNr(i); i+=4; - spec->gems = readNormalNr(i); i+=4; - spec->gold = readNormalNr(i); i+=4; - spec->attack = readNormalNr(i, 1); ++i; - spec->defence = readNormalNr(i, 1); ++i; - spec->power = readNormalNr(i, 1); ++i; - spec->knowledge = readNormalNr(i, 1); ++i; - int gabn; //number of gained abilities - gabn = readNormalNr(i, 1); ++i; - for(int oo = 0; ooabilities.push_back(readNormalNr(i, 1)); ++i; - spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i; - } - int gart = readNormalNr(i, 1); ++i; //number of gained artifacts - for(int oo = 0; oo RoE) - { - spec->artifacts.push_back(readNormalNr(i, 2)); i+=2; - } - else - { - spec->artifacts.push_back(readNormalNr(i, 1)); i+=1; - } - } - int gspel = readNormalNr(i, 1); ++i; //number of gained spells - for(int oo = 0; oospells.push_back(readNormalNr(i, 1)); ++i; - } - int gcre = readNormalNr(i, 1); ++i; //number of gained creatures - spec->creatures = readCreatureSet(gcre); - if(map.version > RoE) - i+=gcre; - i+=8; - nobj->info = spec; - ///////end of copied fragment - break; - } - case EDefType::GRAIL_DEF: - { - CGrailObjInfo * spec = new CGrailObjInfo; - spec->radius = readNormalNr(i); i+=4; - nobj->info = spec; - break; - } - case EDefType::CREGEN_DEF: - { - CCreGenObjInfo * spec = new CCreGenObjInfo; - spec->player = readNormalNr(i); i+=4; - spec->identifier = readNormalNr(i); i+=4; - if(!spec->identifier) - { - spec->asCastle = false; - spec->castles[0] = bufor[i]; ++i; - spec->castles[1] = bufor[i]; ++i; - } - else - { - spec->asCastle = true; - } - nobj->setOwner(spec->player); - nobj->info = spec; - break; - } - case EDefType::CREGEN2_DEF: - { - CCreGen2ObjInfo * spec = new CCreGen2ObjInfo; - spec->player = readNormalNr(i); i+=4; - spec->identifier = readNormalNr(i); i+=4; - if(!spec->identifier) - { - spec->asCastle = false; - spec->castles[0] = bufor[i]; ++i; - spec->castles[1] = bufor[i]; ++i; - } - else - { - spec->asCastle = true; - } - spec->minLevel = bufor[i]; ++i; - spec->maxLevel = bufor[i]; ++i; - //if(spec->maxLevel>7) - // spec->maxLevel = 7; - //if(spec->minLevel<1) - // spec->minLevel = 1; - nobj->setOwner(spec->player); - nobj->info = spec; - break; - } - case EDefType::CREGEN3_DEF: - { - CCreGen3ObjInfo * spec = new CCreGen3ObjInfo; - spec->player = bufor[i]; ++i; - i+=3; - spec->minLevel = bufor[i]; ++i; - spec->maxLevel = bufor[i]; ++i; - if(spec->maxLevel>7) - spec->maxLevel = 7; - if(spec->minLevel<1) - spec->minLevel = 1; - nobj->setOwner(spec->player); - nobj->info = spec; - break; - } - case EDefType::BORDERGUARD_DEF: - { - CBorderGuardObjInfo * spec = new CBorderGuardObjInfo; - spec->missionType = bufor[i]; ++i; - switch(spec->missionType) - { - case 0: - { - goto borderguardend; - break; - } - case 1: - { - spec->m1level = readNormalNr(i); i+=4; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 2: - { - spec->m2attack = bufor[i]; ++i; - spec->m2defence = bufor[i]; ++i; - spec->m2power = bufor[i]; ++i; - spec->m2knowledge = bufor[i]; ++i; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 3: - { - spec->m3bytes[0] = bufor[i]; ++i; - spec->m3bytes[1] = bufor[i]; ++i; - spec->m3bytes[2] = bufor[i]; ++i; - spec->m3bytes[3] = bufor[i]; ++i; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 4: - { - spec->m4bytes[0] = bufor[i]; ++i; - spec->m4bytes[1] = bufor[i]; ++i; - spec->m4bytes[2] = bufor[i]; ++i; - spec->m4bytes[3] = bufor[i]; ++i; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 5: - { - int artNumber = bufor[i]; ++i; - for(int yy=0; yym5arts.push_back(readNormalNr(i, 2)); i+=2; - } - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 6: - { - int typeNumber = bufor[i]; ++i; - for(int hh=0; hhm6cre.push_back(&(VLC->creh->creatures[creType])); - spec->m6number.push_back(creNumb); - } - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 7: - { - spec->m7wood = readNormalNr(i); i+=4; - spec->m7mercury = readNormalNr(i); i+=4; - spec->m7ore = readNormalNr(i); i+=4; - spec->m7sulfur = readNormalNr(i); i+=4; - spec->m7crystal = readNormalNr(i); i+=4; - spec->m7gems = readNormalNr(i); i+=4; - spec->m7gold = readNormalNr(i); i+=4; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 8: - { - int heroType = bufor[i]; ++i; - spec->m8hero = heroType; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - case 9: - { - spec->m9player = bufor[i]; ++i; - int limit = readNormalNr(i); i+=4; - if(limit == ((int)0xffffffff)) - { - spec->isDayLimit = false; - spec->lastDay = -1; - } - else - { - spec->isDayLimit = true; - spec->lastDay = limit; - } - break; - } - }//internal switch end (seer huts) - - int len1 = readNormalNr(i); i+=4; - for(int ee=0; eefirstVisitText += bufor[i]; ++i; - } - - int len2 = readNormalNr(i); i+=4; - for(int ee=0; eenextVisitText += bufor[i]; ++i; - } - - int len3 = readNormalNr(i); i+=4; - for(int ee=0; eecompletedText += bufor[i]; ++i; - } - nobj->info = spec; -borderguardend: - break; - } - case EDefType::HEROPLACEHOLDER_DEF: - { - i+=3; //TODO: handle it more properly - break; - } - } //end of main switch - map.objects.push_back(nobj); - }//end of loading objects - THC std::cout<<"\tReading objects: "<AB) - { - ne.humanAffected = bufor[i]; ++i; - } - else - ne.humanAffected = true; - ne.computerAffected = bufor[i]; ++i; - ne.firstOccurence = bufor[i]; ++i; - ne.nextOccurence = bufor[i]; ++i; - i+=18; - map.events.push_back(ne); - } - - //map readed, bufor no longer needed - delete[] bufor; bufor=NULL; -} -int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic) -{ - int ret=0; - int amp=1; - for (int ir=0; ir=amp/2) - { - ret = ret-amp; - } - return ret; -} - -EDefType CAmbarCendamo::getDefType(CGDefInfo * a) -{ - switch(a->id) - { - case 5: case 65: case 66: case 67: case 68: case 69: - return EDefType::ARTIFACT_DEF; //handled - case 6: - return EDefType::PANDORA_DEF; //hanled - case 26: - return EDefType::EVENTOBJ_DEF; //handled - case 33: - return EDefType::GARRISON_DEF; //handled - case 34: case 70: case 62: //70 - random hero //62 - prison - return EDefType::HERO_DEF; //handled - case 36: - return EDefType::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 - case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164: - return EDefType::CREATURES_DEF; //handled - case 59: - return EDefType::SIGN_DEF; //handled - case 77: - return EDefType::TOWN_DEF; //can be problematic, but handled - case 79: case 76: - return EDefType::RESOURCE_DEF; //handled - case 81: - return EDefType::SCHOLAR_DEF; //handled - case 83: - return EDefType::SEERHUT_DEF; //handled - case 91: - return EDefType::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 - case 113: - return EDefType::WITCHHUT_DEF; //handled - case 214: - return EDefType::HEROPLACEHOLDER_DEF; //partially handled - case 215: - return EDefType::BORDERGUARD_DEF; //handled by analogy to seer huts ;] - case 216: - return EDefType::CREGEN2_DEF; //handled - case 217: - return EDefType::CREGEN_DEF; //handled - case 218: - return EDefType::CREGEN3_DEF; //handled - case 219: - return EDefType::GARRISON_DEF; //handled - default: - return EDefType::TERRAINOBJ_DEF; // nothing to be handled - } -} - -CCreatureSet CAmbarCendamo::readCreatureSet(int number) -{ - if(map.version>RoE) - { - CCreatureSet ret; - std::pair ins; - for(int ir=0;ir32768) - rettt = 65536-rettt+VLC->creh->creatures.size()-16; - ins.first = &(VLC->creh->creatures[rettt]); - ins.second = readNormalNr(i+ir*4+2, 2); - std::pair > tt(ir,ins); - ret.slots.insert(tt); - } - i+=number*4; - return ret; - } - else - { - CCreatureSet ret; - std::pair ins; - for(int ir=0;ir220) - rettt = 256-rettt+VLC->creh->creatures.size()-16; - ins.first = &(VLC->creh->creatures[rettt]); - ins.second = readNormalNr(i+ir*3+1, 2); - std::pair > tt(ir,ins); - ret.slots.insert(tt); - } - i+=number*3; - return ret; - } -} -char CAmbarCendamo::readChar() -{ - return bufor[i++]; -} -std::string CAmbarCendamo::readString() -{ - int len = readNormalNr(i); i+=4; - std::string ret; ret.reserve(len); - for(int gg=0; gg +//#include +//#include +//#include "../lib/VCMI_Lib.h" +//std::string nameFromType (EterrainType typ); +//int readInt(unsigned char * bufor, int bytCon) +//{ +// int ret=0; +// int amp=1; +// for (int i=0; i open(tie,std::ios::binary); +//// is->seekg(0,std::ios::end); // na koniec +//// int andame = is->tellg(); // read length +//// is->seekg(0,std::ios::beg); // wracamy na poczatek +//// bufor = new unsigned char[andame]; // allocate memory +//// is->read((char*)bufor, andame); // read map file to buffer +//// is->close(); +//// delete is; +////} +//CAmbarCendamo::~CAmbarCendamo () +//{// free memory +// for (int ii=0;ii convertBuildings(const std::set h3m, int castleID) +{ + std::map mapa; + std::set ret; + std::ifstream b5("config/buildings5.txt"); + while(!b5.eof()) + { + int a, b; + b5 >> a >> b; + if(castleID==8 && b==17) //magic university ID 17 (h3m) => 21 (vcmi) + b=21; + mapa[a]=b; + } -int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4) + for(std::set::const_iterator i=h3m.begin();i!=h3m.end();i++) + { + if(mapa[*i]>=0) + ret.insert(mapa[*i]); + else if(mapa[*i] >= (-CREATURES_PER_TOWN)) // horde buildings + { + int level = (-mapa[*i]); + if(h3m.find(20+(level*3)) != h3m.end()) //upgraded creature horde building + { + if(((castleID==1) || (castleID==3)) && ((level==3) || (level==5))) + ret.insert(25); + else + ret.insert(19); + } + else + { + if(((castleID==1) || (castleID==3)) && ((level==3) || (level==5))) + ret.insert(24); + else + ret.insert(18); + } + } + else + { + std::cout<<"Conversion warning: unknown building "<<*i<<" in castle "<>i) + { + ret |= (128>>i); + } + } + return ret; +} +EDefType getDefType(CGDefInfo * a) +{ + switch(a->id) + { + case 5: case 65: case 66: case 67: case 68: case 69: + return EDefType::ARTIFACT_DEF; //handled + case 6: + return EDefType::PANDORA_DEF; //hanled + case 26: + return EDefType::EVENTOBJ_DEF; //handled + case 33: + return EDefType::GARRISON_DEF; //handled + case 34: case 70: case 62: //70 - random hero //62 - prison + return EDefType::HERO_DEF; //handled + case 36: + return EDefType::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 + case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164: + return EDefType::CREATURES_DEF; //handled + case 59: + return EDefType::SIGN_DEF; //handled + case 77: + return EDefType::TOWN_DEF; //can be problematic, but handled + case 79: case 76: + return EDefType::RESOURCE_DEF; //handled + case 81: + return EDefType::SCHOLAR_DEF; //handled + case 83: + return EDefType::SEERHUT_DEF; //handled + case 91: + return EDefType::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 + case 113: + return EDefType::WITCHHUT_DEF; //handled + case 214: + return EDefType::HEROPLACEHOLDER_DEF; //partially handled + case 215: + return EDefType::BORDERGUARD_DEF; //handled by analogy to seer huts ;] + case 216: + return EDefType::CREGEN2_DEF; //handled + case 217: + return EDefType::CREGEN_DEF; //handled + case 218: + return EDefType::CREGEN3_DEF; //handled + case 219: + return EDefType::GARRISON_DEF; //handled + default: + return EDefType::TERRAINOBJ_DEF; // nothing to be handled + } +} +int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4, bool cyclic = false) { int ret=0; int amp=1; - for (int i=0; i=amp/2) + { + ret = ret-amp; } return ret; } +char readChar(unsigned char * bufor, int &i) +{ + return bufor[i++]; +} +std::string readString(unsigned char * bufor, int &i) +{ + int len = readNormalNr(bufor,i); i+=4; + std::string ret; ret.reserve(len); + for(int gg=0; ggRoE maps +{ + if(version) + { + CCreatureSet ret; + std::pair ins; + for(int ir=0;ir32768) + rettt = 65536-rettt+VLC->creh->creatures.size()-16; + ins.first = &(VLC->creh->creatures[rettt]); + ins.second = readNormalNr(bufor,i+ir*4+2, 2); + std::pair > tt(ir,ins); + ret.slots.insert(tt); + } + i+=number*4; + return ret; + } + else + { + CCreatureSet ret; + std::pair ins; + for(int ir=0;ir220) + rettt = 256-rettt+VLC->creh->creatures.size()-16; + ins.first = &(VLC->creh->creatures[rettt]); + ins.second = readNormalNr(bufor,i+ir*3+1, 2); + std::pair > tt(ir,ins); + ret.slots.insert(tt); + } + i+=number*3; + return ret; + } +} CMapHeader::CMapHeader(unsigned char *map) { this->version = (Eformat)map[0]; //wersja mapy @@ -250,4 +439,1855 @@ CMapHeader::CMapHeader(unsigned char *map) this->players[rr].team=map[i++]; } } +} +Mapa::Mapa(unsigned char * bufor) +{ + THC timeHandler th; + th.getDif(); + int i=0; + version = (Eformat)(readNormalNr(bufor,i)); i+=4; //map version + areAnyPLayers = readChar(bufor,i); //invalid on some maps + height = width = (readNormalNr(bufor,i)); i+=4; // wymiary mapy + twoLevel = readChar(bufor,i); //czy sa lochy + terrain = new TerrainTile*[width]; // allocate memory + for (int ii=0;iiArtifactID = bufor[i+2]; + nr=(version==RoE ? 1 : 2); + break; + } + case gatherTroop: + { + vicConDetails = new VicCon1(); + int temp1 = bufor[i+2]; + int temp2 = bufor[i+3]; + ((VicCon1*)vicConDetails)->monsterID = bufor[i+2]; + ((VicCon1*)vicConDetails)->neededQuantity=readNormalNr(bufor,i+(version==RoE ? 3 : 4)); + nr=(version==RoE ? 5 : 6); + break; + } + case gatherResource: + { + vicConDetails = new VicCon2(); + ((VicCon2*)vicConDetails)->resourceID = bufor[i+2]; + ((VicCon2*)vicConDetails)->neededQuantity=readNormalNr(bufor,i+3); + nr=5; + break; + } + case buildCity: + { + vicConDetails = new VicCon3(); + ((VicCon3*)vicConDetails)->posOfCity.x = bufor[i+2]; + ((VicCon3*)vicConDetails)->posOfCity.y = bufor[i+3]; + ((VicCon3*)vicConDetails)->posOfCity.z = bufor[i+4]; + ((VicCon3*)vicConDetails)->councilNeededLevel = bufor[i+5]; + ((VicCon3*)vicConDetails)->fortNeededLevel = bufor[i+6]; + nr=5; + break; + } + case buildGrail: + { + vicConDetails = new VicCon4(); + if (bufor[i+4]>2) + ((VicCon4*)vicConDetails)->anyLocation = true; + else + { + ((VicCon4*)vicConDetails)->whereBuildGrail.x = bufor[i+2]; + ((VicCon4*)vicConDetails)->whereBuildGrail.y = bufor[i+3]; + ((VicCon4*)vicConDetails)->whereBuildGrail.z = bufor[i+4]; + } + nr=3; + break; + } + case beatHero: + { + vicConDetails = new VicCon5(); + ((VicCon5*)vicConDetails)->locationOfHero.x = bufor[i+2]; + ((VicCon5*)vicConDetails)->locationOfHero.y = bufor[i+3]; + ((VicCon5*)vicConDetails)->locationOfHero.z = bufor[i+4]; + nr=3; + break; + } + case captureCity: + { + vicConDetails = new VicCon6(); + ((VicCon6*)vicConDetails)->locationOfTown.x = bufor[i+2]; + ((VicCon6*)vicConDetails)->locationOfTown.y = bufor[i+3]; + ((VicCon6*)vicConDetails)->locationOfTown.z = bufor[i+4]; + nr=3; + break; + } + case beatMonster: + { + vicConDetails = new VicCon7(); + ((VicCon7*)vicConDetails)->locationOfMonster.x = bufor[i+2]; + ((VicCon7*)vicConDetails)->locationOfMonster.y = bufor[i+3]; + ((VicCon7*)vicConDetails)->locationOfMonster.z = bufor[i+4]; + nr=3; + break; + } + case takeDwellings: + { + vicConDetails = new CspecificVictoryConidtions(); + nr=0; + break; + } + case takeMines: + { + vicConDetails = new CspecificVictoryConidtions(); + nr=0; + break; + } + case transportItem: + { + vicConDetails = new VicCona(); + ((VicCona*)vicConDetails)->artifactID = bufor[i+2]; + ((VicCona*)vicConDetails)->destinationPlace.x = bufor[i+3]; + ((VicCona*)vicConDetails)->destinationPlace.y = bufor[i+4]; + ((VicCona*)vicConDetails)->destinationPlace.z = bufor[i+5]; + nr=4; + break; + } + } + vicConDetails->allowNormalVictory = bufor[i++]; + vicConDetails->appliesToAI = bufor[i++]; + i+=nr; + } + lossCondition.typeOfLossCon = (ElossCon)bufor[i++]; + switch (lossCondition.typeOfLossCon) //read loss conditions + { + case lossCastle: + { + lossCondition.castlePos.x=bufor[i++]; + lossCondition.castlePos.y=bufor[i++]; + lossCondition.castlePos.z=bufor[i++]; + break; + } + case lossHero: + { + lossCondition.heroPos.x=bufor[i++]; + lossCondition.heroPos.y=bufor[i++]; + lossCondition.heroPos.z=bufor[i++]; + break; + } + case timeExpires: + { + lossCondition.timeLimit = readNormalNr(bufor,i++,2); + i++; + break; + } + } + howManyTeams=bufor[i++]; //read number of teams + if(howManyTeams>0) //read team numbers + { + for(int rr=0; rr<8; ++rr) + { + players[rr].team=bufor[i++]; + } + } + //reading allowed heroes (20 bytes) + int ist; + + ist=i; //starting i for loop + + allowedHeroes.resize(HEROES_QUANTITY); + for(int xx=0;xxRoE) //probably reserved for further heroes + i+=4; + unsigned char disp = 0; + if(version>=SoD) + { + disp = bufor[i++]; + disposedHeroes.resize(disp); + for(int g=0; g=SoD) + { + //reading allowed spells (9 bytes) + ist=i; //starting i for loop + for(i; iID = 34; + cgh->subID = z; + if(readChar(bufor,i))//true if hore's experience is greater than 0 + { cgh->exp = readNormalNr(bufor,i); i+=4; } + else + cgh->exp = 0; + if(readChar(bufor,i))//true if hero has specified abilities + { + int howMany = readNormalNr(bufor,i); i+=4; + cgh->secSkills.resize(howMany); + for(int yy=0; yysecSkills[yy].first = readNormalNr(bufor,i, 1); ++i; + cgh->secSkills[yy].second = readNormalNr(bufor,i, 1); ++i; + } + } + bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts) + int artmask = version == RoE ? 0xff : 0xffff; + int artidlen = version == RoE ? 1 : 2; + if(artSet) + { + for(int pom=0;pom<16;pom++) + { + int id = readNormalNr(bufor,i, artidlen); i+=artidlen; + if(id!=artmask) + cgh->artifWorn[pom] = id; + } + //misc5 art //17 + if(version>=SoD) + { + i+=2; + //int id = readNormalNr(bufor,i, artidlen); i+=artidlen; + //if(id!=artmask) + // spec->artifWorn[16] = id; + } + //spellbook + int id = readNormalNr(bufor,i, artidlen); i+=artidlen; + if(id!=artmask) + cgh->artifWorn[17] = id; + //19 //???what is that? gap in file or what? - it's probably fifth slot.. + if(version>RoE) + { + id = readNormalNr(bufor,i, artidlen); i+=artidlen; + if(id!=artmask) + cgh->artifWorn[18] = id; + } + else + i+=1; + //bag artifacts //20 + int amount = readNormalNr(bufor,i, 2); i+=2; //number of artifacts in hero's bag + if(amount>0) + { + for(int ss=0; ssartifacts.push_back(id); + } + } + } //artifacts + if(readChar(bufor,i))//customBio + cgh->biography = readString(bufor,i); + int sex = bufor[i++]; // 0xFF is default, 00 male, 01 female + if(readChar(bufor,i))//are spells + { + int ist = i; + for(i; ispells.insert((i-ist)*8+yy); + } + } + } + } + if(readChar(bufor,i))//customPrimSkills + { + cgh->primSkills.resize(4); + for(int xx=0;xx<4;xx++) + cgh->primSkills[xx] = bufor[i++]; + } + predefinedHeroes.push_back(cgh); + } + break; + } + case RoE: + i+=0; + break; + } + for (int c=0; cname.reserve(nameLength); + for (int cd=0;cdname += bufor[i++]; + } + std::transform(vinya->name.begin(),vinya->name.end(),vinya->name.begin(),(int(*)(int))toupper); + + + unsigned char bytes[12]; + for (int v=0; v<12; v++) // read info + { + bytes[v] = bufor[i++]; + } + vinya->terrainAllowed = readNormalNr(bufor,i,2);i+=2; + vinya->terrainMenu = readNormalNr(bufor,i,2);i+=2; + vinya->id = readNormalNr(bufor,i,4);i+=4; + vinya->subid = readNormalNr(bufor,i,4);i+=4; + vinya->type = bufor[i++]; + vinya->printPriority = bufor[i++]; + for (int zi=0; zi<6; zi++) + { + vinya->blockMap[zi] = reverse(bytes[zi]); + } + for (int zi=0; zi<6; zi++) + { + vinya->visitMap[zi] = reverse(bytes[6+zi]); + } + i+=16; + defy.push_back(vinya); // add this def to the vector + } + THC std::cout<<"\tReading defs info: "<defInfo->id; + int p = 99; + switch(getDefType(nobj->defInfo)) + { + case EDefType::EVENTOBJ_DEF: //for event - objects + { + CEventObjInfo * spec = new CEventObjInfo; + bool guardMess; + guardMess = bufor[i]; ++i; + if(guardMess) + { + int messLong = readNormalNr(bufor,i, 4); i+=4; + if(messLong>0) + { + spec->isMessage = true; + for(int yy=0; yymessage +=bufor[i+yy]; + } + i+=messLong; + } + spec->areGuarders = bufor[i]; ++i; + if(spec->areGuarders) + { + spec->guarders = readCreatureSet(bufor,i,7,(version>RoE)); + } + i+=4; + } + else + { + spec->isMessage = false; + spec->areGuarders = false; + spec->message = std::string(""); + } + spec->gainedExp = readNormalNr(bufor,i, 4); i+=4; + spec->manaDiff = readNormalNr(bufor,i, 4); i+=4; + spec->moraleDiff = readNormalNr(bufor,i, 1, true); ++i; + spec->luckDiff = readNormalNr(bufor,i, 1, true); ++i; + spec->wood = readNormalNr(bufor,i); i+=4; + spec->mercury = readNormalNr(bufor,i); i+=4; + spec->ore = readNormalNr(bufor,i); i+=4; + spec->sulfur = readNormalNr(bufor,i); i+=4; + spec->crystal = readNormalNr(bufor,i); i+=4; + spec->gems = readNormalNr(bufor,i); i+=4; + spec->gold = readNormalNr(bufor,i); i+=4; + spec->attack = readNormalNr(bufor,i, 1); ++i; + spec->defence = readNormalNr(bufor,i, 1); ++i; + spec->power = readNormalNr(bufor,i, 1); ++i; + spec->knowledge = readNormalNr(bufor,i, 1); ++i; + int gabn; //number of gained abilities + gabn = readNormalNr(bufor,i, 1); ++i; + for(int oo = 0; ooabilities.push_back(readNormalNr(bufor,i, 1)); ++i; + spec->abilityLevels.push_back(readNormalNr(bufor,i, 1)); ++i; + } + int gart = readNormalNr(bufor,i, 1); ++i; //number of gained artifacts + for(int oo = 0; ooartifacts.push_back(readNormalNr(bufor,i, (version == RoE ? 1 : 2))); i+=(version == RoE ? 1 : 2); + } + int gspel = readNormalNr(bufor,i, 1); ++i; //number of gained spells + for(int oo = 0; oospells.push_back(readNormalNr(bufor,i, 1)); ++i; + } + int gcre = readNormalNr(bufor,i, 1); ++i; //number of gained creatures + spec->creatures = readCreatureSet(bufor,i,gcre,(version>RoE)); + if(version>RoE) + i+=gcre; + i+=8; + spec->availableFor = readNormalNr(bufor,i, 1); ++i; + spec->computerActivate = readNormalNr(bufor,i, 1); ++i; + spec->humanActivate = readNormalNr(bufor,i, 1); ++i; + i+=4; + nobj->info = spec; + break; + } + case EDefType::HERO_DEF: + { + CGHeroInstance * nhi = new CGHeroInstance; + (*(static_cast(nhi))) = *nobj; + delete nobj; + nobj=nhi; + if(version>RoE) + { + nhi->identifier = readNormalNr(bufor,i, 4); i+=4; + } + nhi->setOwner(bufor[i]); ++i; + nhi->subID = readNormalNr(bufor,i, 1); ++i; + if(readChar(bufor,i))//true if hero has nonstandard name + nhi->name = readString(bufor,i); + if(version>AB) + { + if(readChar(bufor,i))//true if hore's experience is greater than 0 + { nhi->exp = readNormalNr(bufor,i); i+=4; } + else + nhi->exp = -1; + } + else + { nhi->exp = readNormalNr(bufor,i); i+=4; } + + bool portrait=bufor[i]; ++i; + if (portrait) + i++; //TODO read portrait nr, save, open + + if(readChar(bufor,i))//true if hero has specified abilities + { + int howMany = readNormalNr(bufor,i); i+=4; + nhi->secSkills.resize(howMany); + for(int yy=0; yysecSkills[yy].first = readNormalNr(bufor,i, 1); ++i; + nhi->secSkills[yy].second = readNormalNr(bufor,i, 1); ++i; + } + } + if(readChar(bufor,i))//true if hero has nonstandard garrison + nhi->army = readCreatureSet(bufor,i,7,(version>RoE)); + nhi->army.formation =bufor[i]; ++i; //formation + bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts) + int artmask = version == RoE ? 0xff : 0xffff; + int artidlen = version == RoE ? 1 : 2; + if(artSet) + { + for(int pom=0;pom<16;pom++) + { + int id = readNormalNr(bufor,i, artidlen); i+=artidlen; + if(id!=artmask) + nhi->artifWorn[pom] = id; + } + //misc5 art //17 + if(version>=SoD) + { + int id = readNormalNr(bufor,i, artidlen); i+=artidlen; + if(id!=artmask) + nhi->artifWorn[16] = id; + } + //spellbook + int id = readNormalNr(bufor,i, artidlen); i+=artidlen; + if(id!=artmask) + nhi->artifWorn[17] = id; + //19 //???what is that? gap in file or what? - it's probably fifth slot.. + if(version>RoE) + { + id = readNormalNr(bufor,i, artidlen); i+=artidlen; + if(id!=artmask) + nhi->artifWorn[18] = id; + } + else + i+=1; + //bag artifacts //20 + int amount = readNormalNr(bufor,i, 2); i+=2; //number of artifacts in hero's bag + if(amount>0) + { + for(int ss=0; ssartifacts.push_back(id); + } + } + } //artifacts + + nhi->patrol.patrolRadious = readNormalNr(bufor,i, 1); ++i; + if(nhi->patrol.patrolRadious == 0xff) + nhi->patrol.patrolling = false; + else + nhi->patrol.patrolling = true; + + if(version>RoE) + { + if(readChar(bufor,i))//true if hero has nonstandard (mapmaker defined) biography + nhi->biography = readString(bufor,i); + nhi->sex = !(bufor[i]); ++i; + } + //spells + if(version>AB) + { + bool areSpells = bufor[i]; ++i; + + if(areSpells) //TODO: sprawdzić //seems to be ok - tow + { + int ist = i; + for(i; ispells.insert((i-ist)*8+yy); + } + } + } + } + } + else if(version==AB) //we can read one spell + { + unsigned char buff = bufor[i]; ++i; + if(buff!=254) + { + nhi->spells.insert(buff); + } + } + //spells loaded + if(version>AB) + { + if(readChar(bufor,i))//customPrimSkills + { + nhi->primSkills.resize(4); + for(int xx=0;xx<4;xx++) + nhi->primSkills[xx] = bufor[i++]; + } + } + i+=16; + nhi->moveDir = 4; + nhi->isStanding = true; + nhi->level = -1; + nhi->mana = -1; + nhi->movement = -1; + if(nhi->ID==34) + heroes.push_back(nhi); + //else + // CGI->objh->objInstances.push_back(nhi); + + break; + } + case CREATURES_DEF: + { + CCreatureObjInfo * spec = new CCreatureObjInfo; + if(version>RoE) + { + spec->bytes[0] = bufor[i]; ++i; + spec->bytes[1] = bufor[i]; ++i; + spec->bytes[2] = bufor[i]; ++i; + spec->bytes[3] = bufor[i]; ++i; + } + spec->number = readNormalNr(bufor,i, 2); i+=2; + spec->character = bufor[i]; ++i; + bool isMesTre = bufor[i]; ++i; //true if there is message or treasury + if(isMesTre) + { + int messLength = readNormalNr(bufor,i); i+=4; + if(messLength>0) + { + for(int tt=0; ttmessage += bufor[i]; ++i; + } + } + spec->wood = readNormalNr(bufor,i); i+=4; + spec->mercury = readNormalNr(bufor,i); i+=4; + spec->ore = readNormalNr(bufor,i); i+=4; + spec->sulfur = readNormalNr(bufor,i); i+=4; + spec->crytal = readNormalNr(bufor,i); i+=4; + spec->gems = readNormalNr(bufor,i); i+=4; + spec->gold = readNormalNr(bufor,i); i+=4; + int artID = readNormalNr(bufor,i, (version == RoE ? 1 : 2)); i+=(version == RoE ? 1 : 2); + if(version==RoE) + { + if(artID!=0xff) + spec->gainedArtifact = artID; + else + spec->gainedArtifact = -1; + } + else + { + if(artID!=0xffff) + spec->gainedArtifact = artID; + else + spec->gainedArtifact = -1; + } + } + spec->neverFlees = bufor[i]; ++i; + spec->notGrowingTeam = bufor[i]; ++i; + i+=2; + nobj->info = spec; + break; + } + case EDefType::SIGN_DEF: + { + CSignObjInfo * spec = new CSignObjInfo; + int length = readNormalNr(bufor,i); i+=4; + for(int rr=0; rrmessage += bufor[i]; ++i; + } + i+=4; + nobj->info = spec; + break; + } + case EDefType::SEERHUT_DEF: + { + CSeerHutObjInfo * spec = new CSeerHutObjInfo; + if(version>RoE) + { + spec->missionType = bufor[i]; ++i; + switch(spec->missionType) + { + case 0: + i+=3; + continue; + case 1: + { + spec->m1level = readNormalNr(bufor,i); i+=4; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 2: + { + spec->m2attack = bufor[i]; ++i; + spec->m2defence = bufor[i]; ++i; + spec->m2power = bufor[i]; ++i; + spec->m2knowledge = bufor[i]; ++i; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 3: + { + spec->m3bytes[0] = bufor[i]; ++i; + spec->m3bytes[1] = bufor[i]; ++i; + spec->m3bytes[2] = bufor[i]; ++i; + spec->m3bytes[3] = bufor[i]; ++i; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 4: + { + spec->m4bytes[0] = bufor[i]; ++i; + spec->m4bytes[1] = bufor[i]; ++i; + spec->m4bytes[2] = bufor[i]; ++i; + spec->m4bytes[3] = bufor[i]; ++i; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 5: + { + int artNumber = bufor[i]; ++i; + for(int yy=0; yym5arts.push_back(artid); + } + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 6: + { + int typeNumber = bufor[i]; ++i; + for(int hh=0; hhm6cre.push_back(&(VLC->creh->creatures[creType])); + spec->m6number.push_back(creNumb); + } + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 7: + { + spec->m7wood = readNormalNr(bufor,i); i+=4; + spec->m7mercury = readNormalNr(bufor,i); i+=4; + spec->m7ore = readNormalNr(bufor,i); i+=4; + spec->m7sulfur = readNormalNr(bufor,i); i+=4; + spec->m7crystal = readNormalNr(bufor,i); i+=4; + spec->m7gems = readNormalNr(bufor,i); i+=4; + spec->m7gold = readNormalNr(bufor,i); i+=4; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 8: + { + int heroType = bufor[i]; ++i; + spec->m8hero = heroType; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 9: + { + spec->m9player = bufor[i]; ++i; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + }//internal switch end (seer huts) + + int len1 = readNormalNr(bufor,i); i+=4; + for(int ee=0; eefirstVisitText += bufor[i]; ++i; + } + + int len2 = readNormalNr(bufor,i); i+=4; + for(int ee=0; eenextVisitText += bufor[i]; ++i; + } + + int len3 = readNormalNr(bufor,i); i+=4; + for(int ee=0; eecompletedText += bufor[i]; ++i; + } + } + else //RoE + { + int artID = bufor[i]; ++i; + if(artID!=255) //not none quest + { + spec->m5arts.push_back(artID); + spec->missionType = 5; + } + else + { + spec->missionType = 255; + } + } + + if(spec->missionType!=255) + { + unsigned char rewardType = bufor[i]; ++i; + spec->rewardType = rewardType; + + switch(rewardType) + { + case 1: + { + spec->r1exp = readNormalNr(bufor,i); i+=4; + break; + } + case 2: + { + spec->r2mana = readNormalNr(bufor,i); i+=4; + break; + } + case 3: + { + spec->r3morale = bufor[i]; ++i; + break; + } + case 4: + { + spec->r4luck = bufor[i]; ++i; + break; + } + case 5: + { + spec->r5type = bufor[i]; ++i; + spec->r5amount = readNormalNr(bufor,i, 3); i+=3; + i+=1; + break; + } + case 6: + { + spec->r6type = bufor[i]; ++i; + spec->r6amount = bufor[i]; ++i; + break; + } + case 7: + { + spec->r7ability = bufor[i]; ++i; + spec->r7level = bufor[i]; ++i; + break; + } + case 8: + { + spec->r8art = readNormalNr(bufor,i, (version == RoE ? 1 : 2)); i+=(version == RoE ? 1 : 2); + break; + } + case 9: + { + spec->r9spell = bufor[i]; ++i; + break; + } + case 10: + { + if(version>RoE) + { + spec->r10creature = readNormalNr(bufor,i, 2); i+=2; + spec->r10amount = readNormalNr(bufor,i, 2); i+=2; + } + else + { + spec->r10creature = bufor[i]; ++i; + spec->r10amount = readNormalNr(bufor,i, 2); i+=2; + } + break; + } + }// end of internal switch + i+=2; + } + else //missionType==255 + { + i+=3; + } + nobj->info = spec; + break; + } + case EDefType::WITCHHUT_DEF: + { + CWitchHutObjInfo * spec = new CWitchHutObjInfo; + if(version>RoE) //in reo we cannot specify it - all are allowed (I hope) + { + ist=i; //starting i for loop + for(i; iallowedAbilities.push_back((i-ist)*8+yy); + } + } + } + } + else //(RoE map) + { + for(int gg=0; ggallowedAbilities.push_back(gg); + } + } + + nobj->info = spec; + break; + } + case EDefType::SCHOLAR_DEF: + { + CScholarObjInfo * spec = new CScholarObjInfo; + spec->bonusType = bufor[i]; ++i; + switch(spec->bonusType) + { + case 0xff: + ++i; + break; + case 0: + spec->r0type = bufor[i]; ++i; + break; + case 1: + spec->r1 = bufor[i]; ++i; + break; + case 2: + spec->r2 = bufor[i]; ++i; + break; + } + i+=6; + nobj->info = spec; + break; + } + case EDefType::GARRISON_DEF: + { + CGarrisonObjInfo * spec = new CGarrisonObjInfo; + spec->player = bufor[i]; ++i; + i+=3; + spec->units = readCreatureSet(bufor,i,7,(version>RoE)); + if(version > RoE) + { + spec->movableUnits = bufor[i]; ++i; + } + else + spec->movableUnits = true; + i+=8; + nobj->setOwner(spec->player); + nobj->info = spec; + break; + } + case EDefType::ARTIFACT_DEF: + { + CArtifactObjInfo * spec = new CArtifactObjInfo; + bool areSettings = bufor[i]; ++i; + if(areSettings) + { + int messLength = readNormalNr(bufor,i, 4); i+=4; + for(int hh=0; hhmessage += bufor[i]; ++i; + } + bool areGuards = bufor[i]; ++i; + if(areGuards) + { + spec->areGuards = true; + spec->guards = readCreatureSet(bufor,i,7,(version>RoE)); + } + else + spec->areGuards = false; + i+=4; + } + nobj->info = spec; + break; + } + case EDefType::RESOURCE_DEF: + { + CResourceObjInfo * spec = new CResourceObjInfo; + bool isMessGuard = bufor[i]; ++i; + if(isMessGuard) + { + int messLength = readNormalNr(bufor,i); i+=4; + for(int mm=0; mmmessage+=bufor[i]; ++i; + } + spec->areGuards = bufor[i]; ++i; + if(spec->areGuards) + { + spec->guards = readCreatureSet(bufor,i,7,(version>RoE)); + } + i+=4; + } + else + { + spec->areGuards = false; + } + spec->amount = readNormalNr(bufor,i); i+=4; + i+=4; + nobj->info = spec; + break; + } + case EDefType::TOWN_DEF: + { + CGTownInstance * nt = new CGTownInstance(); + (*(static_cast(nt))) = *nobj; + delete nobj; + nobj = nt; + nt->identifier = 0; + if(version>RoE) + { + readNormalNr(bufor,i); i+=4; + } + nt->tempOwner = bufor[i]; ++i; + if(readChar(bufor,i)) //has name + nt->name = readString(bufor,i); + if(readChar(bufor,i))//true if garrison isn't empty + nt->army = readCreatureSet(bufor,i,7,(version>RoE)); + nt->army.formation = bufor[i]; ++i; + if(readChar(bufor,i)) //unusualBuildings + { + //built buildings + for(int byte=0;byte<6;byte++) + { + for(int bit=0;bit<8;bit++) + if(bufor[i] & (1<builtBuildings.insert(byte*8+bit); + i++; + } + //forbidden buildings + for(int byte=6;byte<12;byte++) + { + for(int bit=0;bit<8;bit++) + if(bufor[i] & (1<forbiddenBuildings.insert(byte*8+bit); + i++; + } + nt->builtBuildings = convertBuildings(nt->builtBuildings,nt->subID); + nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings,nt->subID); + } + else //standard buildings + { + if(readChar(bufor,i)) //has fort + nt->builtBuildings.insert(7); + nt->builtBuildings.insert(-50); //means that set of standard building should be included + } + + int ist = i; + if(version>RoE) + { + for(i; iobligatorySpells.push_back((i-ist)*8+yy); + } + } + } + } + + ist = i; + for(i; ipossibleSpells.push_back((i-ist)*8+yy); + } + } + } + + /////// reading castle events ////////////////////////////////// + + int numberOfEvent = readNormalNr(bufor,i); i+=4; + + for(int gh = 0; gh AB) + { + nce.forHuman = bufor[i]; ++i; + } + else + nce.forHuman = true; + nce.forComputer = bufor[i]; ++i; + nce.firstShow = readNormalNr(bufor,i, 2); i+=2; + nce.forEvery = bufor[i]; ++i; + + i+=17; + + for(int kk=0; kk<6; ++kk) + { + nce.bytes[kk] = bufor[i]; ++i; + } + + for(int vv=0; vv<7; ++vv) + { + nce.gen[vv] = readNormalNr(bufor,i, 2); i+=2; + } + i+=4; + nt->events.insert(nce); + }//castle events have been read + + if(version > AB) + { + nt->alignment = bufor[i]; ++i; + } + else + nt->alignment = 0xff; + i+=3; + + nt->builded = 0; + nt->destroyed = 0; + nt->garrisonHero = NULL; + towns.push_back(nt); + break; + } + case EDefType::PLAYERONLY_DEF: + { + CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo; + spec->player = bufor[i]; ++i; + i+=3; + nobj->setOwner(spec->player); + nobj->info = spec; + break; + } + case EDefType::SHRINE_DEF: + { + CShrineObjInfo * spec = new CShrineObjInfo; + spec->spell = bufor[i]; i+=4; + nobj->info = spec; + break; + } + case EDefType::SPELLSCROLL_DEF: + { + CSpellScrollObjinfo * spec = new CSpellScrollObjinfo; + bool messg = bufor[i]; ++i; + if(messg) + { + int mLength = readNormalNr(bufor,i); i+=4; + for(int vv=0; vvmessage += bufor[i]; ++i; + } + spec->areGuarders = bufor[i]; ++i; + if(spec->areGuarders) + { + spec->guarders = readCreatureSet(bufor,i,7,(version>RoE)); + } + i+=4; + } + spec->spell = bufor[i]; ++i; + i+=3; + nobj->info = spec; + break; + } + case EDefType::PANDORA_DEF: + { + CPandorasBoxObjInfo * spec = new CPandorasBoxObjInfo; + bool messg = bufor[i]; ++i; + if(messg) + { + int mLength = readNormalNr(bufor,i); i+=4; + for(int vv=0; vvmessage += bufor[i]; ++i; + } + spec->areGuarders = bufor[i]; ++i; + if(spec->areGuarders) + { + spec->guarders = readCreatureSet(bufor,i,7,(version>RoE)); + } + i+=4; + } + ////// copied form event handling (seems to be similar) + spec->gainedExp = readNormalNr(bufor,i, 4); i+=4; + spec->manaDiff = readNormalNr(bufor,i, 4); i+=4; + spec->moraleDiff = readNormalNr(bufor,i, 1, true); ++i; + spec->luckDiff = readNormalNr(bufor,i, 1, true); ++i; + spec->wood = readNormalNr(bufor,i); i+=4; + spec->mercury = readNormalNr(bufor,i); i+=4; + spec->ore = readNormalNr(bufor,i); i+=4; + spec->sulfur = readNormalNr(bufor,i); i+=4; + spec->crystal = readNormalNr(bufor,i); i+=4; + spec->gems = readNormalNr(bufor,i); i+=4; + spec->gold = readNormalNr(bufor,i); i+=4; + spec->attack = readNormalNr(bufor,i, 1); ++i; + spec->defence = readNormalNr(bufor,i, 1); ++i; + spec->power = readNormalNr(bufor,i, 1); ++i; + spec->knowledge = readNormalNr(bufor,i, 1); ++i; + int gabn; //number of gained abilities + gabn = readNormalNr(bufor,i, 1); ++i; + for(int oo = 0; ooabilities.push_back(readNormalNr(bufor,i, 1)); ++i; + spec->abilityLevels.push_back(readNormalNr(bufor,i, 1)); ++i; + } + int gart = readNormalNr(bufor,i, 1); ++i; //number of gained artifacts + for(int oo = 0; oo RoE) + { + spec->artifacts.push_back(readNormalNr(bufor,i, 2)); i+=2; + } + else + { + spec->artifacts.push_back(readNormalNr(bufor,i, 1)); i+=1; + } + } + int gspel = readNormalNr(bufor,i, 1); ++i; //number of gained spells + for(int oo = 0; oospells.push_back(readNormalNr(bufor,i, 1)); ++i; + } + int gcre = readNormalNr(bufor,i, 1); ++i; //number of gained creatures + spec->creatures = readCreatureSet(bufor,i,gcre,(version>RoE)); + if(version > RoE) + i+=gcre; + i+=8; + nobj->info = spec; + ///////end of copied fragment + break; + } + case EDefType::GRAIL_DEF: + { + CGrailObjInfo * spec = new CGrailObjInfo; + spec->radius = readNormalNr(bufor,i); i+=4; + nobj->info = spec; + break; + } + case EDefType::CREGEN_DEF: + { + CCreGenObjInfo * spec = new CCreGenObjInfo; + spec->player = readNormalNr(bufor,i); i+=4; + spec->identifier = readNormalNr(bufor,i); i+=4; + if(!spec->identifier) + { + spec->asCastle = false; + spec->castles[0] = bufor[i]; ++i; + spec->castles[1] = bufor[i]; ++i; + } + else + { + spec->asCastle = true; + } + nobj->setOwner(spec->player); + nobj->info = spec; + break; + } + case EDefType::CREGEN2_DEF: + { + CCreGen2ObjInfo * spec = new CCreGen2ObjInfo; + spec->player = readNormalNr(bufor,i); i+=4; + spec->identifier = readNormalNr(bufor,i); i+=4; + if(!spec->identifier) + { + spec->asCastle = false; + spec->castles[0] = bufor[i]; ++i; + spec->castles[1] = bufor[i]; ++i; + } + else + { + spec->asCastle = true; + } + spec->minLevel = bufor[i]; ++i; + spec->maxLevel = bufor[i]; ++i; + //if(spec->maxLevel>7) + // spec->maxLevel = 7; + //if(spec->minLevel<1) + // spec->minLevel = 1; + nobj->setOwner(spec->player); + nobj->info = spec; + break; + } + case EDefType::CREGEN3_DEF: + { + CCreGen3ObjInfo * spec = new CCreGen3ObjInfo; + spec->player = bufor[i]; ++i; + i+=3; + spec->minLevel = bufor[i]; ++i; + spec->maxLevel = bufor[i]; ++i; + if(spec->maxLevel>7) + spec->maxLevel = 7; + if(spec->minLevel<1) + spec->minLevel = 1; + nobj->setOwner(spec->player); + nobj->info = spec; + break; + } + case EDefType::BORDERGUARD_DEF: + { + CBorderGuardObjInfo * spec = new CBorderGuardObjInfo; + spec->missionType = bufor[i]; ++i; + switch(spec->missionType) + { + case 0: + { + goto borderguardend; + break; + } + case 1: + { + spec->m1level = readNormalNr(bufor,i); i+=4; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 2: + { + spec->m2attack = bufor[i]; ++i; + spec->m2defence = bufor[i]; ++i; + spec->m2power = bufor[i]; ++i; + spec->m2knowledge = bufor[i]; ++i; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 3: + { + spec->m3bytes[0] = bufor[i]; ++i; + spec->m3bytes[1] = bufor[i]; ++i; + spec->m3bytes[2] = bufor[i]; ++i; + spec->m3bytes[3] = bufor[i]; ++i; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 4: + { + spec->m4bytes[0] = bufor[i]; ++i; + spec->m4bytes[1] = bufor[i]; ++i; + spec->m4bytes[2] = bufor[i]; ++i; + spec->m4bytes[3] = bufor[i]; ++i; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 5: + { + int artNumber = bufor[i]; ++i; + for(int yy=0; yym5arts.push_back(readNormalNr(bufor,i, 2)); i+=2; + } + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 6: + { + int typeNumber = bufor[i]; ++i; + for(int hh=0; hhm6cre.push_back(&(VLC->creh->creatures[creType])); + spec->m6number.push_back(creNumb); + } + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 7: + { + spec->m7wood = readNormalNr(bufor,i); i+=4; + spec->m7mercury = readNormalNr(bufor,i); i+=4; + spec->m7ore = readNormalNr(bufor,i); i+=4; + spec->m7sulfur = readNormalNr(bufor,i); i+=4; + spec->m7crystal = readNormalNr(bufor,i); i+=4; + spec->m7gems = readNormalNr(bufor,i); i+=4; + spec->m7gold = readNormalNr(bufor,i); i+=4; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 8: + { + int heroType = bufor[i]; ++i; + spec->m8hero = heroType; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + case 9: + { + spec->m9player = bufor[i]; ++i; + int limit = readNormalNr(bufor,i); i+=4; + if(limit == ((int)0xffffffff)) + { + spec->isDayLimit = false; + spec->lastDay = -1; + } + else + { + spec->isDayLimit = true; + spec->lastDay = limit; + } + break; + } + }//internal switch end (seer huts) + + int len1 = readNormalNr(bufor,i); i+=4; + for(int ee=0; eefirstVisitText += bufor[i]; ++i; + } + + int len2 = readNormalNr(bufor,i); i+=4; + for(int ee=0; eenextVisitText += bufor[i]; ++i; + } + + int len3 = readNormalNr(bufor,i); i+=4; + for(int ee=0; eecompletedText += bufor[i]; ++i; + } + nobj->info = spec; +borderguardend: + break; + } + case EDefType::HEROPLACEHOLDER_DEF: + { + i+=3; //TODO: handle it more properly + break; + } + } //end of main switch + objects.push_back(nobj); + }//end of loading objects + THC std::cout<<"\tReading objects: "<AB) + { + ne.humanAffected = bufor[i]; ++i; + } + else + ne.humanAffected = true; + ne.computerAffected = bufor[i]; ++i; + ne.firstOccurence = bufor[i]; ++i; + ne.nextOccurence = bufor[i]; ++i; + i+=18; + events.push_back(ne); + } + + //map readed, bufor no longer needed + delete[] bufor; bufor=NULL; } \ No newline at end of file diff --git a/map.h b/map.h index 06d369fd3..5c0f24b5f 100644 --- a/map.h +++ b/map.h @@ -10,7 +10,10 @@ class CGObjectInstance; class CGHeroInstance; class CGTownInstance; enum ESortBy{name,playerAm,size,format, viccon,loscon}; - +enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF, + EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF, + SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF, + BORDERGUARD_DEF, HEROPLACEHOLDER_DEF}; class DLL_EXPORT CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes { }; @@ -391,6 +394,8 @@ struct DLL_EXPORT Mapa std::vector objects; std::vector heroes; std::vector towns; + + Mapa(unsigned char * bufor); //creates map from decompressed .h3m data }; class DLL_EXPORT CMapHeader { From b26024e6075299b8d75ddc327dde7453994bc98a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 30 Jun 2008 00:05:48 +0000 Subject: [PATCH 16/47] First part of commit --- client/Graphics.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/Graphics.h b/client/Graphics.h index d01addf80..5dd17272f 100644 --- a/client/Graphics.h +++ b/client/Graphics.h @@ -6,10 +6,14 @@ class CGHeroInstance; class CGTownInstance; class CDefHandler; class CHeroClass; +struct SDL_Color; class Graphics { public: //various graphics + SDL_Color * playerColors; //array [8] + SDL_Color * neutralColor; + SDL_Color * playerColorPalette; //palette to make interface colors good - array of size [256] SDL_Surface * hInfo, *tInfo; //hero and town infobox bgs std::vector > slotsPos; //creature slot positions in infoboxes CDefEssential *luck22, *luck30, *luck42, *luck82, @@ -31,6 +35,7 @@ public: //functions Graphics(); + void loadPaletteAndColors(); void loadHeroFlags(); void loadHeroFlags(std::pair Graphics::*, std::vector > &pr, bool mode); void loadHeroAnim(std::vector & anims); @@ -39,6 +44,7 @@ public: SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS); SDL_Surface * drawTownInfoWin(const CGTownInstance * curh); SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //returns small picture of town: ID=-1 - blank; -2 - border; -3 - random + void blueToPlayersAdv(SDL_Surface * sur, int player); //replaces blue interface colour with a color of player }; extern Graphics * graphics; \ No newline at end of file From ea8562a6b155b21dcdb6f15c36ac9aa0805615af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 30 Jun 2008 00:06:41 +0000 Subject: [PATCH 17/47] Rest of commit: broken battles, starting hero, town displaying and linker errors. Further changes for netcode. --- AdventureMapButton.cpp | 5 +- CAdvmapInterface.cpp | 6 +- CBattleInterface.cpp | 5 +- CCallback.cpp | 23 +- CCallback.h | 10 +- CCastleInterface.cpp | 8 +- CConsoleHandler.cpp | 2 +- CGameInfo.h | 3 - CGameState.cpp | 563 ++++++++++++++++- CGameState.h | 50 +- CHeroWindow.cpp | 2 +- CLua.h | 21 +- CMT.cpp | 368 ++--------- CMessage.cpp | 3 +- CPlayerInterface.cpp | 4 +- SDL_Extensions.cpp | 184 +----- SDL_Extensions.h | 6 - SDL_rotozoom.cpp | 1231 ------------------------------------ SDL_rotozoom.h | 117 ---- client/Graphics.cpp | 113 +++- client/VCMI_client.vcproj | 17 +- global.h | 2 + hch/CDefObjInfoHandler.cpp | 6 +- hch/CHeroHandler.cpp | 2 + hch/CObjectHandler.cpp | 1 + hch/CSpellHandler.cpp | 2 +- hch/CTownHandler.cpp | 5 +- lib/VCMI_Lib.h | 12 +- lib/VCMI_lib.vcproj | 10 +- map.cpp | 16 +- map.h | 71 ++- mapHandler.cpp | 588 +++++------------ mapHandler.h | 21 +- 33 files changed, 1027 insertions(+), 2450 deletions(-) delete mode 100644 SDL_rotozoom.cpp delete mode 100644 SDL_rotozoom.h diff --git a/AdventureMapButton.cpp b/AdventureMapButton.cpp index d101ee468..745e68046 100644 --- a/AdventureMapButton.cpp +++ b/AdventureMapButton.cpp @@ -7,6 +7,7 @@ #include "hch/CTownHandler.h" #include "CLua.h" #include "CCallback.h" +#include "client/Graphics.h" AdventureMapButton::AdventureMapButton () { type=2; @@ -38,7 +39,7 @@ AdventureMapButton::AdventureMapButton imgs.resize(1); imgs[0].push_back(temp->ourImages[i].bitmap); if(playerColoredButton) - CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID); + graphics->blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID); } delete temp; if (add) @@ -52,7 +53,7 @@ AdventureMapButton::AdventureMapButton { imgs[i+1].push_back(temp->ourImages[j].bitmap); if(playerColoredButton) - CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID); + graphics->blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID); } delete temp; } diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index c87e5b403..e11e9db64 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -113,7 +113,7 @@ void CMinimap::draw() { for (int jj=0; jjplayerColors[hh[i]->getOwner()].r,CGI->playerColors[hh[i]->getOwner()].g,CGI->playerColors[hh[i]->getOwner()].b); + SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[hh[i]->getOwner()].r,graphics->playerColors[hh[i]->getOwner()].g,graphics->playerColors[hh[i]->getOwner()].b); } } } @@ -600,7 +600,7 @@ CResDataBar::CResDataBar() //SDL_Color p1={40,65,139,255}, p2={36,59,125,255}, p3={35,56,121,255}; //kolory+=p1,p2,p3; //blueToPlayersAdv(bg,LOCPLINT->playerID,2,&kolory); - blueToPlayersAdv(bg,LOCPLINT->playerID,2); + graphics->blueToPlayersAdv(bg,LOCPLINT->playerID); pos = genRect(bg->h,bg->w,3,575); txtpos += (std::pair(35,577)),(std::pair(120,577)),(std::pair(205,577)), @@ -851,7 +851,7 @@ townList(5,&genRect(192,48,747,196),747,196,747,372) townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this); LOCPLINT->adventureInt=this; bg = BitmapHandler::loadBitmap("ADVMAP.bmp"); - blueToPlayersAdv(bg,player); + graphics->blueToPlayersAdv(bg,player); scrollingLeft = false; scrollingRight = false; scrollingUp = false ; diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 43c9464e7..fba75b2b4 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -10,6 +10,7 @@ #include "CGameState.h" #include "hch\CGeneralTextHandler.h" #include "client/CCreatureAnimation.h" +#include "client/Graphics.h" #include #include @@ -37,7 +38,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C std::vector< std::string > & backref = CGI->mh->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] ); menu = BitmapHandler::loadBitmap("CBAR.BMP"); - CSDL_Ext::blueToPlayersAdv(menu, hero1->tempOwner); + graphics->blueToPlayersAdv(menu, hero1->tempOwner); //preparing graphics for displaying amounts of creatures amountBasic = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); @@ -949,7 +950,7 @@ CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG for(int i=0; iourImages.size(); ++i) { flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap); - CSDL_Ext::blueToPlayersAdv(flag->ourImages[i].bitmap, player); + graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player); } } diff --git a/CCallback.cpp b/CCallback.cpp index 86ab8b2c5..4a6213278 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -364,6 +364,11 @@ UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos) return ret; } +const StartInfo * CCallback::getStartInfo() +{ + return gs->scenarioOps; +} + int CCallback::howManyTowns() { return gs->players[gs->currentPlayer].towns.size(); @@ -484,7 +489,7 @@ std::vector < std::string > CCallback::getObjDescriptions(int3 pos) else return std::vector< std::string > (); } -PseudoV< PseudoV< PseudoV > > & CCallback::getVisibilityMap() +std::vector< std::vector< std::vector > > & CCallback::getVisibilityMap() { return gs->players[player].fogOfWarMap; } @@ -844,7 +849,7 @@ int3 CScriptCallback::getPos(CGObjectInstance * ob) } void CScriptCallback::changePrimSkill(int ID, int which, int val) { - CGHeroInstance * hero = CGI->state->getHero(ID,0); + CGHeroInstance * hero = CGI->state->map->getHero(ID,0); if (whichprimSkills[which]+=val; @@ -884,7 +889,7 @@ void CScriptCallback::changePrimSkill(int ID, int which, int val) int CScriptCallback::getHeroOwner(int heroID) { - CGHeroInstance * hero = CGI->state->getHero(heroID,0); + CGHeroInstance * hero = CGI->state->map->getHero(heroID,0); return hero->getOwner(); } void CScriptCallback::showInfoDialog(int player, std::string text, std::vector * components) @@ -966,13 +971,13 @@ void CScriptCallback::heroVisitCastle(CGObjectInstance * ob, int heroID) CGTownInstance * n; if(n = dynamic_cast(ob)) { - n->visitingHero = CGI->state->getHero(heroID,0); - CGI->state->getHero(heroID,0)->visitedTown = n; + n->visitingHero = CGI->state->map->getHero(heroID,0); + CGI->state->map->getHero(heroID,0)->visitedTown = n; for(int b=0; bplayerint.size(); ++b) { if(CGI->playerint[b]->playerID == getHeroOwner(heroID)) { - CGI->playerint[b]->heroVisitsTown(CGI->state->getHero(heroID,0),n); + CGI->playerint[b]->heroVisitsTown(CGI->state->map->getHero(heroID,0),n); break; } } @@ -986,7 +991,7 @@ void CScriptCallback::stopHeroVisitCastle(CGObjectInstance * ob, int heroID) CGTownInstance * n; if(n = dynamic_cast(ob)) { - CGI->state->getHero(heroID,0)->visitedTown = NULL; + CGI->state->map->getHero(heroID,0)->visitedTown = NULL; if(n->visitingHero && n->visitingHero->type->ID == heroID) n->visitingHero = NULL; return; @@ -996,7 +1001,7 @@ void CScriptCallback::stopHeroVisitCastle(CGObjectInstance * ob, int heroID) } void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos==-1 - first free slot in backpack { - CGHeroInstance* h = gs->getHero(hid,0); + CGHeroInstance* h = gs->map->getHero(hid,0); if(position<0) { for(int i=0;iartifacts.size();i++) @@ -1026,7 +1031,7 @@ void CScriptCallback::startBattle(CCreatureSet * army1, CCreatureSet * army2, in } void CScriptCallback::startBattle(int heroID, CCreatureSet * army, int3 tile) //for hero<=>neutral army { - CGHeroInstance* h = gs->getHero(heroID,0); + CGHeroInstance* h = gs->map->getHero(heroID,0); gs->battle(&h->army,army,tile,h,NULL); } void CLuaCallback::registerFuncs(lua_State * L) diff --git a/CCallback.h b/CCallback.h index 07a8c6a69..be5f7ac6d 100644 --- a/CCallback.h +++ b/CCallback.h @@ -40,7 +40,7 @@ public: //get info virtual bool verifyPath(CPath * path, bool blockSea)=0; virtual int getDate(int mode=0)=0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month - virtual PseudoV< PseudoV< PseudoV > > & getVisibilityMap()=0; //returns visibility map (TODO: make it const) + virtual std::vector< std::vector< std::vector > > & getVisibilityMap()=0; //returns visibility map (TODO: make it const) virtual const CGHeroInstance * getHeroInfo(int player, int val, bool mode)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID virtual int getResourceAmount(int type)=0; virtual int howManyHeroes()=0; @@ -54,6 +54,7 @@ public: virtual int getHeroSerial(const CGHeroInstance * hero)=0; virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)=0; virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)=0; + virtual const StartInfo * getStartInfo()=0; //battle virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship @@ -110,7 +111,7 @@ public: //get info bool verifyPath(CPath * path, bool blockSea); int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month - PseudoV< PseudoV< PseudoV > > & getVisibilityMap(); //returns visibility map (TODO: make it const) + std::vector< std::vector< std::vector > > & getVisibilityMap(); //returns visibility map (TODO: make it const) const CGHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID int getResourceAmount(int type); std::vector getResourceAmount(); @@ -126,6 +127,7 @@ public: int getMySerial(); const CCreatureSet* getGarrison(const CGObjectInstance *obj); UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos); + virtual const StartInfo * getStartInfo(); //battle int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship @@ -169,7 +171,7 @@ public: void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army //friends - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CLuaCallback : public CScriptCallback { @@ -181,6 +183,6 @@ private: static int getGnrlText(lua_State * L);//(int ID, int which, int val); static int getSelectedHero(lua_State * L);//() - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; #endif //CCALLBACK_H \ No newline at end of file diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index 6484595ea..3478adc20 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -235,7 +235,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) if((townlist->selected+1) > townlist->SIZE) townlist->from = townlist->selected - townlist->SIZE + 2; - CSDL_Ext::blueToPlayersAdv(townInt,LOCPLINT->playerID); + graphics->blueToPlayersAdv(townInt,LOCPLINT->playerID); exit->bitmapOffset = 4; @@ -660,7 +660,7 @@ CHallInterface::CResDataBar::CResDataBar() { bg = BitmapHandler::loadBitmap("Z2ESBAR.bmp"); SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); - CSDL_Ext::blueToPlayersAdv(bg,LOCPLINT->playerID); + graphics->blueToPlayersAdv(bg,LOCPLINT->playerID); pos.x = 7; pos.y = 575; pos.w = bg->w; @@ -770,7 +770,7 @@ CHallInterface::CBuildingBox::CBuildingBox(int id, int x, int y) CHallInterface::CHallInterface(CCastleInterface * owner) { bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first); - CSDL_Ext::blueToPlayersAdv(bg,LOCPLINT->playerID); + graphics->blueToPlayersAdv(bg,LOCPLINT->playerID); bars = CDefHandler::giveDefEss("TPTHBAR.DEF"); status = CDefHandler::giveDefEss("TPTHCHK.DEF"); exit = new AdventureMapButton @@ -1014,7 +1014,7 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod SDL_FreeSurface(hhlp); pos.x = screen->w/2 - bitmap->w/2; pos.y = screen->h/2 - bitmap->h/2; - CSDL_Ext::blueToPlayersAdv(bitmap,LOCPLINT->playerID); + graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID); blitAt(LOCPLINT->castleInt->bicons->ourImages[bid].bitmap,125,50,bitmap); std::vector pom; pom.push_back(CGI->buildh->buildings[tid][bid]->name); CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->description,197,168,GEOR16,40,zwykly,bitmap); diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index f532e872b..14292e4be 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -142,7 +142,7 @@ int internalFunc(void * callback) // break; } //SDL_Delay(100); - delete p; + //delete p; } } return -1; diff --git a/CGameInfo.h b/CGameInfo.h index 0e0570427..d8bd87704 100644 --- a/CGameInfo.h +++ b/CGameInfo.h @@ -62,9 +62,6 @@ public: CScreenHandler * screenh; int localPlayer; std::vector playerint; - std::vector playerColors; - SDL_Color neutralColor; - StartInfo scenarioOps; }; #endif //CGAMEINFO_H \ No newline at end of file diff --git a/CGameState.cpp b/CGameState.cpp index 9488b39f4..e50a069a3 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -1,13 +1,28 @@ +#define VCMI_DLL +#include +#include +#include #include "CGameState.h" #include "CGameInterface.h" #include "CPlayerInterface.h" -#include -#include "SDL_Thread.h" #include "SDL_Extensions.h" #include "CBattleInterface.h" //for CBattleHex -#include +#include +#include "hch/CDefObjInfoHandler.h" +#include "hch/CArtHandler.h" +#include "hch/CTownHandler.h" +#include "hch/CHeroHandler.h" +#include "hch/CObjectHandler.h" +#include "hch/CCreatureHandler.h" +#include "lib/VCMI_Lib.h" +#include "map.h" +#include "StartInfo.h" +#include "CLua.h" +#include "CCallback.h" +#include "CLuaHandler.h" +boost::rand48 ran; class CMP_stack { public: @@ -17,8 +32,509 @@ public: } } cmpst ; -void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2) +CStack::CStack(CCreature * C, int A, int O, int I, bool AO) + :creature(C),amount(A),owner(O), alive(true), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints) { +} +int CGameState::pickHero(int owner) +{ + int h=-1; + if(map->getHero(h = scenarioOps->getIthPlayersSettings(owner).hero,0) && h>=0) //we haven't used selected hero + return h; + int f = scenarioOps->getIthPlayersSettings(owner).castle; + int i=0; + do //try to find free hero of our faction + { + i++; + h = scenarioOps->getIthPlayersSettings(owner).castle*HEROES_PER_TYPE*2+(ran()%(HEROES_PER_TYPE*2));//->scenarioOps->playerInfos[pru].hero = VLC-> + } while( map->getHero(h) && i<175); + if(i>174) //probably no free heroes - there's no point in further search, we'll take first free + { + std::cout << "Warning: cannot find free hero - trying to get first available..."<getHero(j)) + h=j; + } + return h; +} +std::pair CGameState::pickObject(CGObjectInstance *obj) +{ + switch(obj->ID) + { + case 65: //random artifact + return std::pair(5,(ran()%136)+7); //tylko sensowny zakres - na poczatku sa katapulty itp, na koncu specjalne i blanki + case 66: //random treasure artifact + return std::pair(5,VLC->arth->treasures[ran()%VLC->arth->treasures.size()]->id); + case 67: //random minor artifact + return std::pair(5,VLC->arth->minors[ran()%VLC->arth->minors.size()]->id); + case 68: //random major artifact + return std::pair(5,VLC->arth->majors[ran()%VLC->arth->majors.size()]->id); + case 69: //random relic artifact + return std::pair(5,VLC->arth->relics[ran()%VLC->arth->relics.size()]->id); + case 70: //random hero + { + return std::pair(34,pickHero(obj->tempOwner)); + } + case 71: //random monster + return std::pair(54,ran()%(VLC->creh->creatures.size())); + case 72: //random monster lvl1 + return std::pair(54,VLC->creh->levelCreatures[1][ran()%VLC->creh->levelCreatures[1].size()]->idNumber); + case 73: //random monster lvl2 + return std::pair(54,VLC->creh->levelCreatures[2][ran()%VLC->creh->levelCreatures[2].size()]->idNumber); + case 74: //random monster lvl3 + return std::pair(54,VLC->creh->levelCreatures[3][ran()%VLC->creh->levelCreatures[3].size()]->idNumber); + case 75: //random monster lvl4 + return std::pair(54,VLC->creh->levelCreatures[4][ran()%VLC->creh->levelCreatures[4].size()]->idNumber); + case 76: //random resource + return std::pair(79,ran()%7); //now it's OH3 style, use %8 for mithril + case 77: //random town + { + int align = ((CGTownInstance*)obj)->alignment, + f; + if(align>PLAYER_LIMIT-1)//same as owner / random + { + if(obj->tempOwner > PLAYER_LIMIT-1) + f = -1; //random + else + f = scenarioOps->getIthPlayersSettings(obj->tempOwner).castle; + } + else + { + f = scenarioOps->getIthPlayersSettings(align).castle; + } + if(f<0) f = ran()%VLC->townh->towns.size(); + return std::pair(98,f); + } + case 162: //random monster lvl5 + return std::pair(54,VLC->creh->levelCreatures[5][ran()%VLC->creh->levelCreatures[5].size()]->idNumber); + case 163: //random monster lvl6 + return std::pair(54,VLC->creh->levelCreatures[6][ran()%VLC->creh->levelCreatures[6].size()]->idNumber); + case 164: //random monster lvl7 + return std::pair(54,VLC->creh->levelCreatures[7][ran()%VLC->creh->levelCreatures[7].size()]->idNumber); + case 216: //random dwelling + { + int faction = ran()%F_NUMBER; + CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info; + if (info->asCastle) + { + for(int i=0;iobjects.size();i++) + { + if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) + { + randomizeObject(map->objects[i]); //we have to randomize the castle first + faction = map->objects[i]->subID; + break; + } + else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) + { + faction = map->objects[i]->subID; + break; + } + } + } + else + { + while((!(info->castles[0]&(1<7) && (info->castles[1]&(1<<(faction-8)))) + break; + faction = ran()%F_NUMBER; + } + } + int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel)); + int cid = VLC->townh->towns[faction].basicCreatures[level]; + for(int i=0;iobjh->cregens.size();i++) + if(VLC->objh->cregens[i]==cid) + return std::pair(17,i); + std::cout << "Cannot find a dwelling for creature "<(17,0); + } + case 217: + { + int faction = ran()%F_NUMBER; + CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info; + if (info->asCastle) + { + for(int i=0;iobjects.size();i++) + { + if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) + { + randomizeObject(map->objects[i]); //we have to randomize the castle first + faction = map->objects[i]->subID; + break; + } + else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) + { + faction = map->objects[i]->subID; + break; + } + } + } + else + { + while((!(info->castles[0]&(1<7) && (info->castles[1]&(1<<(faction-8)))) + break; + faction = ran()%F_NUMBER; + } + } + int cid = VLC->townh->towns[faction].basicCreatures[obj->subID]; + for(int i=0;iobjh->cregens.size();i++) + if(VLC->objh->cregens[i]==cid) + return std::pair(17,i); + std::cout << "Cannot find a dwelling for creature "<(17,0); + } + case 218: + { + CCreGen3ObjInfo* info =(CCreGen3ObjInfo*)obj->info; + int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel)); + int cid = VLC->townh->towns[obj->subID].basicCreatures[level]; + for(int i=0;iobjh->cregens.size();i++) + if(VLC->objh->cregens[i]==cid) + return std::pair(17,i); + std::cout << "Cannot find a dwelling for creature "<(17,0); + } + } + return std::pair(-1,-1); +} +void CGameState::randomizeObject(CGObjectInstance *cur) +{ + std::pair ran = pickObject(cur); + if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything + { + if(cur->ID==98) //town - set def + { + CGTownInstance *t = dynamic_cast(cur); + if(t->hasCapitol()) + t->defInfo = capitols[t->subID]; + else if(t->hasFort()) + t->defInfo = forts[t->subID]; + else + t->defInfo = villages[t->subID]; + } + return; + } + else if(ran.first==34)//special code for hero + { + CGHeroInstance *h = dynamic_cast(cur); + if(!h) {std::cout<<"Wrong random hero at "<pos<ID = ran.first; + cur->subID = ran.second; + h->type = VLC->heroh->heroes[ran.second]; + map->heroes.push_back(h); + return; //TODO: maybe we should do something with definfo? + } + else if(ran.first==98)//special code for town + { + CGTownInstance *t = dynamic_cast(cur); + if(!t) {std::cout<<"Wrong random town at "<pos<ID = ran.first; + cur->subID = ran.second; + t->town = &VLC->townh->towns[ran.second]; + if(t->hasCapitol()) + t->defInfo = capitols[t->subID]; + else if(t->hasFort()) + t->defInfo = forts[t->subID]; + else + t->defInfo = villages[t->subID]; + map->towns.push_back(t); + return; + } + //we have to replace normal random object + cur->ID = ran.first; + cur->subID = ran.second; + map->defs.insert(cur->defInfo = VLC->dobjinfo->gobjs[ran.first][ran.second]); + if(!cur->defInfo){std::cout<<"Missing def declaration for "<ID<<" "<subID<map = map; + + for(int i=0;idobjinfo->castles[i]); + forts[i] = VLC->dobjinfo->castles[i]; + capitols[i] = new CGDefInfo(*VLC->dobjinfo->castles[i]); + } + + //picking random factions for players + for(int i=0;iplayerInfos.size();i++) + { + if(scenarioOps->playerInfos[i].castle==-1) + { + int f; + do + { + f = ran()%F_NUMBER; + }while(!(map->players[scenarioOps->playerInfos[i].color].allowedFactions & 1<playerInfos[i].castle = f; + } + } + //randomizing objects + for(int no=0; noobjects.size(); ++no) + { + randomizeObject(map->objects[no]); + if(map->objects[no]->ID==26) + map->objects[no]->defInfo->handler=NULL; + } + //std::cout<<"\tRandomizing objects: "<playerInfos.size();i++) + { + std::pair ins(scenarioOps->playerInfos[i].color,PlayerState()); + ins.second.color=ins.first; + ins.second.serial=i; + players.insert(ins); + } + /******************RESOURCES****************************************************/ + //TODO: zeby komputer dostawal inaczej niz gracz + std::vector startres; + std::ifstream tis("config/startres.txt"); + int k; + for (int j=0;jdifficulty;j++) + { + tis >> k; + for (int z=0;z>k; + } + tis >> k; + for (int i=0;i> k; + startres.push_back(k); + } + tis.close(); + for (std::map::iterator i = players.begin(); i!=players.end(); i++) + { + (*i).second.resources.resize(RESOURCE_QUANTITY); + for (int x=0;xheroes.size();i++) //heroes instances + { + if (map->heroes[i]->getOwner()<0) + continue; + CGHeroInstance * vhi = (map->heroes[i]); + if(!vhi->type) + vhi->type = VLC->heroh->heroes[vhi->subID]; + //vhi->subID = vhi->type->ID; + if (vhi->level<1) + { + vhi->exp=40+ran()%50; + vhi->level = 1; + } + if (vhi->level>1) ;//TODO dodac um dr, ale potrzebne los + if ((!vhi->primSkills.size()) || (vhi->primSkills[0]<0)) + { + if (vhi->primSkills.size()primSkills.resize(PRIMARY_SKILLS); + vhi->primSkills[0] = vhi->type->heroClass->initialAttack; + vhi->primSkills[1] = vhi->type->heroClass->initialDefence; + vhi->primSkills[2] = vhi->type->heroClass->initialPower; + vhi->primSkills[3] = vhi->type->heroClass->initialKnowledge; + } + vhi->mana = vhi->primSkills[3]*10; + if (!vhi->name.length()) + { + vhi->name = vhi->type->name; + } + if (!vhi->biography.length()) + { + vhi->biography = vhi->type->biography; + } + if (vhi->portrait < 0) + vhi->portrait = vhi->type->ID; + + //initial army + if (!vhi->army.slots.size()) //standard army + { + int pom, pom2=0; + for(int x=0;x<3;x++) + { + pom = (VLC->creh->nameToID[vhi->type->refTypeStack[x]]); + if(pom>=145 && pom<=149) //war machine + { + pom2++; + switch (pom) + { + case 145: //catapult + vhi->artifWorn[16] = 3; + break; + default: + pom-=145; + vhi->artifWorn[13+pom] = 4+pom; + break; + } + continue; + } + vhi->army.slots[x-pom2].first = &(VLC->creh->creatures[pom]); + if((pom = (vhi->type->highStack[x]-vhi->type->lowStack[x])) > 0) + vhi->army.slots[x-pom2].second = (ran()%pom)+vhi->type->lowStack[x]; + else + vhi->army.slots[x-pom2].second = +vhi->type->lowStack[x]; + } + } + + players[vhi->getOwner()].heroes.push_back(vhi); + + } + /*************************FOG**OF**WAR******************************************/ + for(std::map::iterator k=players.begin(); k!=players.end(); ++k) + { + k->second.fogOfWarMap.resize(map->width); + for(int g=0; gwidth; ++g) + k->second.fogOfWarMap[g].resize(map->height); + + for(int g=-0; gwidth; ++g) + for(int h=0; hheight; ++h) + k->second.fogOfWarMap[g][h].resize(map->twoLevel+1, 0); + + for(int g=0; gwidth; ++g) + for(int h=0; hheight; ++h) + for(int v=0; vtwoLevel+1; ++v) + k->second.fogOfWarMap[g][h][v] = 0; + for(int xd=0; xdwidth; ++xd) //revealing part of map around heroes + { + for(int yd=0; ydheight; ++yd) + { + for(int ch=0; chsecond.heroes.size(); ++ch) + { + int deltaX = (k->second.heroes[ch]->getPosition(false).x-xd)*(k->second.heroes[ch]->getPosition(false).x-xd); + int deltaY = (k->second.heroes[ch]->getPosition(false).y-yd)*(k->second.heroes[ch]->getPosition(false).y-yd); + if(deltaX+deltaYsecond.heroes[ch]->getSightDistance()*k->second.heroes[ch]->getSightDistance()) + k->second.fogOfWarMap[xd][yd][k->second.heroes[ch]->getPosition(false).z] = 1; + } + } + } + } + /****************************TOWNS************************************************/ + for (int i=0;itowns.size();i++) + { + CGTownInstance * vti =(map->towns[i]); + if(!vti->town) + vti->town = &VLC->townh->towns[vti->subID]; + if (vti->name.length()==0) // if town hasn't name we draw it + vti->name=vti->town->names[ran()%vti->town->names.size()]; + if(vti->builtBuildings.find(-50)!=vti->builtBuildings.end()) //give standard set of buildings + { + vti->builtBuildings.erase(-50); + vti->builtBuildings.insert(10); + vti->builtBuildings.insert(5); + vti->builtBuildings.insert(30); + if(ran()%2) + vti->builtBuildings.insert(31); + } + players[vti->getOwner()].towns.push_back(vti); + } + + for(std::map::iterator k=players.begin(); k!=players.end(); ++k) + { + if(k->first==-1 || k->first==255) + continue; + for(int xd=0; xdwidth; ++xd) //revealing part of map around towns + { + for(int yd=0; ydheight; ++yd) + { + for(int ch=0; chsecond.towns.size(); ++ch) + { + int deltaX = (k->second.towns[ch]->pos.x-xd)*(k->second.towns[ch]->pos.x-xd); + int deltaY = (k->second.towns[ch]->pos.y-yd)*(k->second.towns[ch]->pos.y-yd); + if(deltaX+deltaYsecond.towns[ch]->getSightDistance()*k->second.towns[ch]->getSightDistance()) + k->second.fogOfWarMap[xd][yd][k->second.towns[ch]->pos.z] = 1; + } + } + } + + //init visiting heroes + for(int l=0; lsecond.heroes.size();l++) + { + for(int m=0; msecond.towns.size();m++) + { + int3 vistile = k->second.towns[m]->pos; vistile.x--; //tile next to the entrance + if(vistile == k->second.heroes[l]->pos) + { + k->second.towns[m]->visitingHero = k->second.heroes[l]; + break; + } + } + } + } + + /****************************SCRIPTS************************************************/ + std::map > * skrypty = &objscr; //alias for easier access + /****************************C++ OBJECT SCRIPTS************************************************/ + std::map scripts; + CScriptCallback * csc = new CScriptCallback(); + csc->gs = this; + handleCPPObjS(&scripts,new CVisitableOPH(csc)); + handleCPPObjS(&scripts,new CVisitableOPW(csc)); + handleCPPObjS(&scripts,new CPickable(csc)); + handleCPPObjS(&scripts,new CMines(csc)); + handleCPPObjS(&scripts,new CTownScript(csc)); + handleCPPObjS(&scripts,new CHeroScript(csc)); + handleCPPObjS(&scripts,new CMonsterS(csc)); + handleCPPObjS(&scripts,new CCreatureGen(csc)); + //created map + + /****************************LUA OBJECT SCRIPTS************************************************/ + std::vector * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files + for (int i=0; isize(); i++) + { + try + { + std::vector * temp = CLuaHandler::functionList((*lf)[i]); + CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]); + CLuaCallback::registerFuncs(objs->is); + //objs + for (int j=0; jsize(); j++) + { + int obid ; //obj ID + int dspos = (*temp)[j].find_first_of('_'); + obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str()); + std::string fname = (*temp)[j].substr(0,dspos); + if (skrypty->find(obid)==skrypty->end()) + skrypty->insert(std::pair >(obid,std::map())); + (*skrypty)[obid].insert(std::pair(fname,objs)); + } + delete temp; + }HANDLE_EXCEPTION + } + /****************************INITIALIZING OBJECT SCRIPTS************************************************/ + std::string temps("newObject"); + for (int i=0; iobjects.size(); i++) + { + //c++ scripts + if (scripts.find(map->objects[i]->ID) != scripts.end()) + { + map->objects[i]->state = scripts[map->objects[i]->ID]; + map->objects[i]->state->newObject(map->objects[i]); + } + else + { + map->objects[i]->state = NULL; + } + + // lua scripts + if(checkFunc(map->objects[i]->ID,temps)) + (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); + } + + delete lf; +} +void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2) +{/* curB = new BattleInfo(); std::vector & stacks = (curB->stacks); @@ -150,7 +666,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C std::stable_sort(stacks.begin(),stacks.end(),cmpst); //for start inform players about battle - for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing + for(std::map::iterator j=players.begin(); j!=players.end(); ++j)//->players.size(); ++j) //for testing { if (j->first > PLAYER_LIMIT) break; @@ -163,13 +679,13 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C side = true; else continue; //no witnesses - if(CGI->playerint[j->second.serial]->human) + if(VLC->playerint[j->second.serial]->human) { - ((CPlayerInterface*)( CGI->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); + ((CPlayerInterface*)( VLC->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); } else { - //CGI->playerint[j->second.serial]->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); + //VLC->playerint[j->second.serial]->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); } } } @@ -188,8 +704,8 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C { bool battleEnd = false; //tell players about next round - for(int v=0; vplayerint.size(); ++v) - CGI->playerint[v]->battleNewRound(curB->round); + for(int v=0; vplayerint.size(); ++v) + VLC->playerint[v]->battleNewRound(curB->round); //stack loop for(int i=0;iowner)?(hero2 ? hero2->tempOwner : 255):(hero1->tempOwner); unsigned char serialOwner = -1; - for(int g=0; gplayerint.size(); ++g) + for(int g=0; gplayerint.size(); ++g) { - if(CGI->playerint[g]->playerID == owner) + if(VLC->playerint[g]->playerID == owner) { serialOwner = g; break; @@ -211,9 +727,9 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C if(serialOwner==255) //neutral unit { } - else if(CGI->playerint[serialOwner]->human) + else if(VLC->playerint[serialOwner]->human) { - BattleAction ba = ((CPlayerInterface*)CGI->playerint[serialOwner])->activeStack(stacks[i]->ID); + BattleAction ba = ((CPlayerInterface*)VLC->playerint[serialOwner])->activeStack(stacks[i]->ID); switch(ba.actionType) { case 2: //walk @@ -226,8 +742,8 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C } case 4: //retreat/flee { - for(int v=0; vplayerint.size(); ++v) //tell about the end of this battle to interfaces - CGI->playerint[v]->battleEnd(army1, army2, hero1, hero2, std::vector(), 0, false); + for(int v=0; vplayerint.size(); ++v) //tell about the end of this battle to interfaces + VLC->playerint[v]->battleEnd(army1, army2, hero1, hero2, std::vector(), 0, false); battleEnd = true; break; } @@ -241,7 +757,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C } else { - //CGI->playerint[serialOwner]->activeStack(stacks[i]->ID); + //VLC->playerint[serialOwner]->activeStack(stacks[i]->ID); } } if(battleEnd) @@ -257,11 +773,11 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C for(int i=0;istackActionPerformed) //because unit cannot be moved more than once return false; @@ -435,7 +951,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) } else { - damageBase = rand()%(curStack->creature->damageMax - curStack->creature->damageMin) + curStack->creature->damageMin + 1; + damageBase = ran()%(curStack->creature->damageMax - curStack->creature->damageMin) + curStack->creature->damageMin + 1; } float dmgBonusMultiplier = 1.0; @@ -495,7 +1011,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) } } curB->stackActionPerformed = true; - LOCPLINT->actionFinished(BattleAction()); + LOCPLINT->actionFinished(BattleAction());*/ return true; } @@ -517,7 +1033,7 @@ bool CGameState::battleAttackCreatureStack(int ID, int dest) } std::vector CGameState::battleGetRange(int ID) -{ +{/* int initialPlace=-1; //position of unit int radius=-1; //range of unit unsigned char owner = -1; //owner of unit @@ -681,6 +1197,7 @@ std::vector CGameState::battleGetRange(int ID) ret2.push_back(*it); } - return ret2; + return ret2;*/ + return std::vector(); } diff --git a/CGameState.h b/CGameState.h index e4e891e43..b1e6457a5 100644 --- a/CGameState.h +++ b/CGameState.h @@ -1,8 +1,8 @@ #ifndef CGAMESTATE_H #define CGAMESTATE_H - -#include "mapHandler.h" +#include "global.h" #include +#include #include class CScriptCallback; @@ -12,22 +12,30 @@ class CCPPObjectScript; class CCreatureSet; class CStack; class CGHeroInstance; +class CGTownInstance; class CArmedInstance; +class CGDefInfo; +class CObjectScript; +class CGObjectInstance; +class CCreature; struct Mapa; +struct StartInfo; +struct SDL_Surface; +class CMapHandler; +class CPathfinder; -struct PlayerState +struct DLL_EXPORT PlayerState { public: int color, serial; - //std::vector > > fogOfWarMap; //true - visible, false - hidden - PseudoV< PseudoV< PseudoV > > fogOfWarMap; //true - visible, false - hidden + std::vector > > fogOfWarMap; //true - visible, false - hidden std::vector resources; std::vector heroes; std::vector towns; PlayerState():color(-1){}; }; -struct BattleInfo +struct DLL_EXPORT BattleInfo { int side1, side2; int round, activeStack; @@ -39,7 +47,7 @@ struct BattleInfo bool stackActionPerformed; //true if current stack has been moved }; -class CStack +class DLL_EXPORT CStack { public: int ID; //unique ID of stack @@ -50,13 +58,14 @@ public: bool attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle) int position; //position on battlefield bool alive; //true if it is alive - CStack(CCreature * C, int A, int O, int I, bool AO):creature(C),amount(A),owner(O), alive(true), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints){}; + CStack(CCreature * C, int A, int O, int I, bool AO); CStack() : creature(NULL),amount(-1),owner(255), alive(true), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1){}; }; -class CGameState +class DLL_EXPORT CGameState { private: + StartInfo* scenarioOps; int currentPlayer; //ID of player currently having turn BattleInfo *curB; //current battle int day; //total number of days in game @@ -65,6 +74,7 @@ private: std::set cppscripts; //C++ scripts std::map > objscr; //non-C++ scripts + std::map villages, forts, capitols; //def-info for town graphics bool checkFunc(int obid, std::string name) { @@ -77,20 +87,12 @@ private: } return false; } - CGHeroInstance * getHero(int ID, int mode) - { - if (mode != 0) - throw new std::exception("gs->getHero: This mode is not supported!"); - for ( std::map::iterator i=players.begin() ; i!=players.end();i++) - { - for (int j=0;j<(*i).second.heroes.size();j++) - { - if (i->second.heroes[j]->subID == ID) - return i->second.heroes[j]; - } - } - return NULL; - } + + void init(StartInfo * si, Mapa * map, int seed); + void randomizeObject(CGObjectInstance *cur); + std::pair pickObject(CGObjectInstance *obj); + int pickHero(int owner); + void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2); bool battleMoveCreatureStack(int ID, int dest); bool battleAttackCreatureStack(int ID, int dest); @@ -103,7 +105,7 @@ public: friend void initGameState(Mapa * map, CGameInfo * cgi); friend CScriptCallback; friend void handleCPPObjS(std::map * mapa, CCPPObjectScript * script); - friend SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect); //todo: wywalic koniecznie, tylko do flag obecnie!!!! + friend CMapHandler; }; #endif //CGAMESTATE_H diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index defd056d8..e4a980691 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -24,7 +24,7 @@ CHeroWindow::CHeroWindow(int playerColor): { artWorn.resize(19); background = BitmapHandler::loadBitmap("HEROSCR4.bmp"); - CSDL_Ext::blueToPlayersAdv(background, playerColor); + graphics->blueToPlayersAdv(background, playerColor); pos.x = 65; pos.y = 8; pos.h = background->h; diff --git a/CLua.h b/CLua.h index 9309335cd..2d697fe4d 100644 --- a/CLua.h +++ b/CLua.h @@ -11,6 +11,7 @@ class CGHeroInstance; class CScriptCallback; class SComponent; class CSelectableComponent; +class CGameState; struct Mapa; enum ESLan{UNDEF=-1,CPP,ERM,LUA}; class CObjectScript @@ -70,7 +71,7 @@ public: void findFS(std::string fname); - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CLuaObjectScript : public CLua, public CObjectScript @@ -85,7 +86,7 @@ public: void onHeroVisit(CGObjectInstance *os, int heroID); std::string hoverText(CGObjectInstance *os); - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CCPPObjectScript: public CObjectScript { @@ -107,7 +108,7 @@ class CVisitableOPH : public CCPPObjectScript //once per hero std::vector yourObjects(); //returns IDs of objects which are handled by script std::string hoverText(CGObjectInstance *os); - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CVisitableOPW : public CCPPObjectScript //once per week @@ -121,7 +122,7 @@ class CVisitableOPW : public CCPPObjectScript //once per week std::string hoverText(CGObjectInstance *os); void newTurn (); - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CMines : public CCPPObjectScript //flaggable, and giving resource at each day @@ -136,7 +137,7 @@ class CMines : public CCPPObjectScript //flaggable, and giving resource at each std::string hoverText(CGObjectInstance *os); void newTurn (); - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc @@ -151,7 +152,7 @@ class CPickable : public CCPPObjectScript, public IChosen //pickable - resource std::string hoverText(CGObjectInstance *os); std::vector yourObjects(); //returns IDs of objects which are handled by script - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, etc @@ -162,7 +163,7 @@ class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, std::string hoverText(CGObjectInstance *os); std::vector yourObjects(); //returns IDs of objects which are handled by script - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CHeroScript : public CCPPObjectScript @@ -174,7 +175,7 @@ class CHeroScript : public CCPPObjectScript std::vector yourObjects(); //returns IDs of objects which are handled by script std::string hoverText(CGObjectInstance *os); - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CMonsterS : public CCPPObjectScript @@ -186,7 +187,7 @@ class CMonsterS : public CCPPObjectScript void onHeroVisit(CGObjectInstance *os, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CCreatureGen : public CCPPObjectScript @@ -198,5 +199,5 @@ class CCreatureGen : public CCPPObjectScript void onHeroVisit(CGObjectInstance *os, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; \ No newline at end of file diff --git a/CMT.cpp b/CMT.cpp index 8bee31431..a2e91aa01 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -9,14 +9,10 @@ #include "SDL_Extensions.h" #include "SDL_framerate.h" #include -#include -#include #include -#include #include #include "zlib.h" #include -#include #include "hch\CArtHandler.h" #include "hch\CHeroHandler.h" #include "hch\CCreatureHandler.h" @@ -28,7 +24,6 @@ #include "hch\CMusicHandler.h" #include "hch\CLodHandler.h" #include "hch\CDefHandler.h" -#include "hch\CSndHandler.h" #include "hch\CTownHandler.h" #include "hch\CDefObjInfoHandler.h" #include "hch\CAmbarCendamo.h" @@ -46,12 +41,11 @@ #include "CLuaHandler.h" #include "CLua.h" #include "CAdvmapInterface.h" -#include "CCastleInterface.h" #include "client\Graphics.h" -const char * NAME = "VCMI \"Altanatse\" 0.7"; +#include +std::string NAME = NAME_VER + std::string(" (client)"); DLL_EXPORT void initDLL(CLodHandler *b); -SDL_Color playerColorPalette[256]; //palette to make interface colors good - +using boost::asio::ip::tcp; SDL_Surface * screen, * screen2; extern SDL_Surface * CSDL_Ext::std32bppSurface; TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; @@ -64,258 +58,30 @@ void handleCPPObjS(std::map * mapa, CCPPObjectScript * sc } CGI->state->cppscripts.insert(script); } -void initGameState(Mapa * map, CGameInfo * cgi) -{ - cgi->state->day=0; - /*********creating players entries in gs****************************************/ - for (int i=0; iscenarioOps.playerInfos.size();i++) - { - std::pair ins(cgi->scenarioOps.playerInfos[i].color,PlayerState()); - ins.second.color=ins.first; - ins.second.serial=i; - cgi->state->players.insert(ins); - } - /******************RESOURCES****************************************************/ - //TODO: zeby komputer dostawal inaczej niz gracz - std::vector startres; - std::ifstream tis("config/startres.txt"); - int k; - for (int j=0;jscenarioOps.difficulty;j++) - { - tis >> k; - for (int z=0;z>k; - } - tis >> k; - for (int i=0;i> k; - startres.push_back(k); - } - tis.close(); - for (std::map::iterator i = cgi->state->players.begin(); i!=cgi->state->players.end(); i++) - { - (*i).second.resources.resize(RESOURCE_QUANTITY); - for (int x=0;xheroes.size();i++) //heroes instances - { - if (map->heroes[i]->getOwner()<0) - continue; - CGHeroInstance * vhi = (map->heroes[i]); - if(!vhi->type) - vhi->type = cgi->heroh->heroes[vhi->subID]; - //vhi->subID = vhi->type->ID; - if (vhi->level<1) - { - vhi->exp=40+rand()%50; - vhi->level = 1; - } - if (vhi->level>1) ;//TODO dodac um dr, ale potrzebne los - if ((!vhi->primSkills.size()) || (vhi->primSkills[0]<0)) - { - if (vhi->primSkills.size()primSkills.resize(PRIMARY_SKILLS); - vhi->primSkills[0] = vhi->type->heroClass->initialAttack; - vhi->primSkills[1] = vhi->type->heroClass->initialDefence; - vhi->primSkills[2] = vhi->type->heroClass->initialPower; - vhi->primSkills[3] = vhi->type->heroClass->initialKnowledge; - } - vhi->mana = vhi->primSkills[3]*10; - if (!vhi->name.length()) - { - vhi->name = vhi->type->name; - } - if (!vhi->biography.length()) - { - vhi->biography = vhi->type->biography; - } - if (vhi->portrait < 0) - vhi->portrait = vhi->type->ID; - - //initial army - if (!vhi->army.slots.size()) //standard army - { - int pom, pom2=0; - for(int x=0;x<3;x++) - { - pom = (cgi->creh->nameToID[vhi->type->refTypeStack[x]]); - if(pom>=145 && pom<=149) //war machine - { - pom2++; - switch (pom) - { - case 145: //catapult - vhi->artifWorn[16] = 3; - break; - default: - pom-=145; - vhi->artifWorn[13+pom] = 4+pom; - break; - } - continue; - } - vhi->army.slots[x-pom2].first = &(cgi->creh->creatures[pom]); - if((pom = (vhi->type->highStack[x]-vhi->type->lowStack[x])) > 0) - vhi->army.slots[x-pom2].second = (rand()%pom)+vhi->type->lowStack[x]; - else - vhi->army.slots[x-pom2].second = +vhi->type->lowStack[x]; - } - } - - cgi->state->players[vhi->getOwner()].heroes.push_back(vhi); - - } - /*************************FOG**OF**WAR******************************************/ - for(std::map::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k) - { - k->second.fogOfWarMap.resize(map->width, Woff); - for(int g=-Woff; gwidth+Woff; ++g) - k->second.fogOfWarMap[g].resize(map->height, Hoff); - - for(int g=-Woff; gwidth+Woff; ++g) - for(int h=-Hoff; hheight+Hoff; ++h) - k->second.fogOfWarMap[g][h].resize(map->twoLevel+1, 0); - - for(int g=-Woff; gwidth+Woff; ++g) - for(int h=-Hoff; hheight+Hoff; ++h) - for(int v=0; vtwoLevel+1; ++v) - k->second.fogOfWarMap[g][h][v] = 0; - for(int xd=0; xdwidth; ++xd) //revealing part of map around heroes - { - for(int yd=0; ydheight; ++yd) - { - for(int ch=0; chsecond.heroes.size(); ++ch) - { - int deltaX = (k->second.heroes[ch]->getPosition(false).x-xd)*(k->second.heroes[ch]->getPosition(false).x-xd); - int deltaY = (k->second.heroes[ch]->getPosition(false).y-yd)*(k->second.heroes[ch]->getPosition(false).y-yd); - if(deltaX+deltaYsecond.heroes[ch]->getSightDistance()*k->second.heroes[ch]->getSightDistance()) - k->second.fogOfWarMap[xd][yd][k->second.heroes[ch]->getPosition(false).z] = 1; - } - } - } - } - /****************************TOWNS************************************************/ - for (int i=0;itowns.size();i++) - { - CGTownInstance * vti =(map->towns[i]); - if(!vti->town) - vti->town = &CGI->townh->towns[vti->subID]; - if (vti->name.length()==0) // if town hasn't name we draw it - vti->name=vti->town->names[rand()%vti->town->names.size()]; - if(vti->builtBuildings.find(-50)!=vti->builtBuildings.end()) //give standard set of buildings - { - vti->builtBuildings.erase(-50); - vti->builtBuildings.insert(10); - vti->builtBuildings.insert(5); - vti->builtBuildings.insert(30); - if(rand()%2) - vti->builtBuildings.insert(31); - } - cgi->state->players[vti->getOwner()].towns.push_back(vti); - } - - for(std::map::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k) - { - if(k->first==-1 || k->first==255) - continue; - for(int xd=0; xdwidth; ++xd) //revealing part of map around towns - { - for(int yd=0; ydheight; ++yd) - { - for(int ch=0; chsecond.towns.size(); ++ch) - { - int deltaX = (k->second.towns[ch]->pos.x-xd)*(k->second.towns[ch]->pos.x-xd); - int deltaY = (k->second.towns[ch]->pos.y-yd)*(k->second.towns[ch]->pos.y-yd); - if(deltaX+deltaYsecond.towns[ch]->getSightDistance()*k->second.towns[ch]->getSightDistance()) - k->second.fogOfWarMap[xd][yd][k->second.towns[ch]->pos.z] = 1; - } - } - } - - //init visiting heroes - for(int l=0; lsecond.heroes.size();l++) - { - for(int m=0; msecond.towns.size();m++) - { - int3 vistile = k->second.towns[m]->pos; vistile.x--; //tile next to the entrance - if(vistile == k->second.heroes[l]->pos) - { - k->second.towns[m]->visitingHero = k->second.heroes[l]; - break; - } - } - } - } - - /****************************SCRIPTS************************************************/ - std::map > * skrypty = &cgi->state->objscr; //alias for easier access - /****************************C++ OBJECT SCRIPTS************************************************/ - std::map scripts; - CScriptCallback * csc = new CScriptCallback(); - csc->gs = cgi->state; - handleCPPObjS(&scripts,new CVisitableOPH(csc)); - handleCPPObjS(&scripts,new CVisitableOPW(csc)); - handleCPPObjS(&scripts,new CPickable(csc)); - handleCPPObjS(&scripts,new CMines(csc)); - handleCPPObjS(&scripts,new CTownScript(csc)); - handleCPPObjS(&scripts,new CHeroScript(csc)); - handleCPPObjS(&scripts,new CMonsterS(csc)); - handleCPPObjS(&scripts,new CCreatureGen(csc)); - //created map - - /****************************LUA OBJECT SCRIPTS************************************************/ - std::vector * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files - for (int i=0; isize(); i++) - { - try - { - std::vector * temp = CLuaHandler::functionList((*lf)[i]); - CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]); - CLuaCallback::registerFuncs(objs->is); - //objs - for (int j=0; jsize(); j++) - { - int obid ; //obj ID - int dspos = (*temp)[j].find_first_of('_'); - obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str()); - std::string fname = (*temp)[j].substr(0,dspos); - if (skrypty->find(obid)==skrypty->end()) - skrypty->insert(std::pair >(obid,std::map())); - (*skrypty)[obid].insert(std::pair(fname,objs)); - } - delete temp; - }HANDLE_EXCEPTION - } - /****************************INITIALIZING OBJECT SCRIPTS************************************************/ - std::string temps("newObject"); - for (int i=0; iobjects.size(); i++) - { - //c++ scripts - if (scripts.find(map->objects[i]->ID) != scripts.end()) - { - map->objects[i]->state = scripts[map->objects[i]->ID]; - map->objects[i]->state->newObject(map->objects[i]); - } - else - { - map->objects[i]->state = NULL; - } - - // lua scripts - if(cgi->state->checkFunc(map->objects[i]->ID,temps)) - (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); - } - - delete lf; -} - int _tmain(int argc, _TCHAR* argv[]) -{ +{ /* + boost::asio::io_service io_service; + boost::system::error_code error = boost::asio::error::host_not_found; + tcp::socket socket(io_service); + tcp::resolver resolver(io_service); + tcp::resolver::query query("127.0.0.1", "3030"); + tcp::resolver::iterator endpoint_iterator = resolver.resolve(tcp::resolver::query("127.0.0.1", "3030")); + socket.connect(*endpoint_iterator, error); + + boost::array buf; + + size_t len = socket.read_some(boost::asio::buffer(buf), error); + + if (error == boost::asio::error::eof) + ; // Connection closed cleanly by peer. + else if (error) + throw boost::system::system_error(error); // Some other error. + + std::cout.write(buf.data(), len); + len = socket.read_some(boost::asio::buffer(buf), error); + std::cout.write(buf.data(), len);*/ + + srand ( time(NULL) ); CPG=NULL; atexit(SDL_Quit); @@ -330,7 +96,7 @@ int _tmain(int argc, _TCHAR* argv[]) { screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface THC std::cout<<"\tInitializing screen: "<loadHeroAnim(animacje); THC std::cout<<"\tHero animations: "<playerColors.push_back(p); //red - p.r = 0x31; p.g = 0x52; p.b = 0xff; //blue - cgi->playerColors.push_back(p); //blue - p.r = 0x9c; p.g = 0x73; p.b = 0x52;//tan - cgi->playerColors.push_back(p);//tan - p.r = 0x42; p.g = 0x94; p.b = 0x29; //green - cgi->playerColors.push_back(p); //green - p.r = 0xff; p.g = 0x84; p.b = 0x0; //orange - cgi->playerColors.push_back(p); //orange - p.r = 0x8c; p.g = 0x29; p.b = 0xa5; //purple - cgi->playerColors.push_back(p); //purple - p.r = 0x09; p.g = 0x9c; p.b = 0xa5;//teal - cgi->playerColors.push_back(p);//teal - p.r = 0xc6; p.g = 0x7b; p.b = 0x8c;//pink - cgi->playerColors.push_back(p);//pink - p.r = 0x84; p.g = 0x84; p.b = 0x84;//gray - cgi->neutralColor = p;//gray - //colors initialized - //palette initialization - std::string pals = cgi->bitmaph->getTextFile("PLAYERS.PAL"); - int startPoint = 24; //beginning byte; used to read - for(int i=0; i<256; ++i) - { - SDL_Color col; - col.r = pals[startPoint++]; - col.g = pals[startPoint++]; - col.b = pals[startPoint++]; - col.unused = pals[startPoint++]; - playerColorPalette[i] = col; - } - //palette initialized - THC std::cout<<"Preparing players' colours: "<generaltexth = new CGeneralTextHandler; cgi->generaltexth->load(); @@ -435,8 +164,17 @@ int _tmain(int argc, _TCHAR* argv[]) THC std::cout<<"Initialization CPreGame (together): "<mush = mush; - cgi->scenarioOps = cpg->runLoop(); - THC tmh.getDif();pomtime.getDif(); + StartInfo *options = new StartInfo(cpg->runLoop()); + + cgi->dobjinfo = new CDefObjInfoHandler; + cgi->dobjinfo->load(); + THC std::cout<<"\tDef information handler: "<state = new CGameState(); + cgi->state->scenarioOps = options; + THC std::cout<<"\tGamestate: "<loadArtifacts(); cgi->arth = arth; @@ -462,20 +200,13 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->objh = objh; THC std::cout<<"\tObject handler: "<dobjinfo = new CDefObjInfoHandler; - cgi->dobjinfo->load(); - THC std::cout<<"\tDef information handler: "<state = new CGameState(); - cgi->state->players = std::map(); - THC std::cout<<"\tGamestate: "<pathf = new CPathfinder(); THC std::cout<<"\tPathfinder: "<consoleh->cb = new CCallback(cgi->state,-1); cgi->consoleh->runConsole(); THC std::cout<<"\tCallback and console: "<ourScenSel->mapsel.ourMaps[cpg->ourScenSel->mapsel.selected].filename; std::cout<<"Opening map file: "<mh = mh; + + cgi->state->init(options,mapa,8); + + CMapHandler * mh = cgi->mh = new CMapHandler(); + THC std::cout<<"Initializing GameState (together): "<map = mapa; THC std::cout<<"Creating mapHandler: "<loadDefs(); @@ -503,18 +237,16 @@ int _tmain(int argc, _TCHAR* argv[]) mh->init(); THC std::cout<<"Initializing mapHandler (together): "<scenarioOps.playerInfos.size();i++) //initializing interfaces + for (int i=0; istate->scenarioOps->playerInfos.size();i++) //initializing interfaces { - if(!cgi->scenarioOps.playerInfos[i].human) - cgi->playerint.push_back(static_cast(CAIHandler::getNewAI(new CCallback(cgi->state,cgi->scenarioOps.playerInfos[i].color),"EmptyAI.dll"))); + if(!cgi->state->scenarioOps->playerInfos[i].human) + cgi->playerint.push_back(static_cast(CAIHandler::getNewAI(new CCallback(cgi->state,cgi->state->scenarioOps->playerInfos[i].color),"EmptyAI.dll"))); else { - cgi->state->currentPlayer=cgi->scenarioOps.playerInfos[i].color; - cgi->playerint.push_back(new CPlayerInterface(cgi->scenarioOps.playerInfos[i].color,i)); - ((CPlayerInterface*)(cgi->playerint[i]))->init(new CCallback(cgi->state,cgi->scenarioOps.playerInfos[i].color)); + cgi->state->currentPlayer=cgi->state->scenarioOps->playerInfos[i].color; + cgi->playerint.push_back(new CPlayerInterface(cgi->state->scenarioOps->playerInfos[i].color,i)); + ((CPlayerInterface*)(cgi->playerint[i]))->init(new CCallback(cgi->state,cgi->state->scenarioOps->playerInfos[i].color)); } } ///claculating FoWs for minimap diff --git a/CMessage.cpp b/CMessage.cpp index 0b0ccaf1e..e226c60e4 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -14,6 +14,7 @@ #include #include "CLua.h" #include "hch/CGeneralTextHandler.h" +#include "client/Graphics.h" SDL_Color tytulowy, tlo, zwykly ; SDL_Rect genRect(int hh, int ww, int xx, int yy); @@ -61,7 +62,7 @@ void CMessage::init() } for (int j=0;jourImages.size();j++) { - CSDL_Ext::blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i); + graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i); piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap); } } diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 5288fd250..081930a09 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2717,7 +2717,7 @@ CRecrutationWindow::CRecrutationWindow(const std::vector > &C amounts[i] = CGI->creh->creatures[Creatures[i].first].maxAmount(LOCPLINT->cb->getResourceAmount()); } SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp"); - blueToPlayersAdv(hhlp,LOCPLINT->playerID); + graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID); bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); SDL_FreeSurface(hhlp); @@ -2884,7 +2884,7 @@ CCreInfoWindow::CCreInfoWindow pos.y = screen->h/2 - bitmap->h/2; pos.w = bitmap->w; pos.h = bitmap->h; - blueToPlayersAdv(bitmap,LOCPLINT->playerID); + graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID); SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); anim = new CCreaturePic(c); if(!type) anim->anim->setType(1); diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index d9f474935..94558ca8e 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -9,8 +9,7 @@ #include #include "hch\CDefHandler.h" #include - -extern SDL_Color playerColorPalette[256]; +#include "client\Graphics.h" SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given { @@ -403,45 +402,6 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot) } return ret; } - //converts surface to cursor -SDL_Cursor * CSDL_Ext::SurfaceToCursor(SDL_Surface *image, int hx, int hy) -{ - int w, x, y; - Uint8 *data, *mask, *d, *m, r, g, b; - Uint32 color; - SDL_Cursor *cursor; - - w = (image->w + 7) / 8; - data = (Uint8 *)alloca(w * image->h * 2); - if (data == NULL) - return NULL; - memset(data, 0, w * image->h * 2); - mask = data + w * image->h; - if (SDL_MUSTLOCK(image)) - SDL_LockSurface(image); - for (y = 0; y < image->h; y++) - { - d = data + y * w; - m = mask + y * w; - for (x = 0; x < image->w; x++) - { - color = CSDL_Ext::SDL_GetPixel(image, x, y); - if ((image->flags & SDL_SRCCOLORKEY) == 0 || color != image->format->colorkey) - { - SDL_GetRGB(color, image->format, &r, &g, &b); - color = (r + g + b) / 3; - m[x / 8] |= 128 >> (x & 7); - if (color < 128) - d[x / 8] |= 128 >> (x & 7); - } - } - } - if (SDL_MUSTLOCK(image)) - SDL_UnlockSurface(image); - cursor = SDL_CreateCursor(data, mask, w, image->h, hx, hy); - return cursor; -} - Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte) { int bpp = surface->format->BytesPerPixel; @@ -471,7 +431,7 @@ Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y return *(Uint32 *)p; default: - return 0; /* shouldn't happen, but avoids warnings */ + return 0; // shouldn't happen, but avoids warnings } } @@ -530,11 +490,6 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src) return src; } -SDL_Surface * CSDL_Ext::secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha) -{ - return copySurface(src); -} - int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect) { static std::map st; @@ -732,128 +687,6 @@ void CSDL_Ext::update(SDL_Surface * what) if(what) SDL_UpdateRect(what, 0, 0, what->w, what->h); } - -void CSDL_Ext::blueToPlayers(SDL_Surface * sur, int player) -{ - if(sur->format->BitsPerPixel == 8) - { - for(int i=0; iformat->palette->ncolors; ++i) - { - SDL_Color * cc = sur->format->palette->colors+i; - if(cc->r==0 && cc->g==0 && cc->b==255) - { - cc->r = CGI->playerColors[player].r; - cc->g = CGI->playerColors[player].g; - cc->b = CGI->playerColors[player].b; - } - } - } - else if(sur->format->BitsPerPixel == 24) - { - for(int y=0; yh; ++y) - { - for(int x=0; xw; ++x) - { - Uint8* cp = (Uint8*)sur->pixels + y+sur->pitch + x*3; - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - if(cp[0]==0 && cp[1]==0 && cp[2]==255) - { - cp[0] = CGI->playerColors[player].r; - cp[1] = CGI->playerColors[player].g; - cp[2] = CGI->playerColors[player].b; - } - } - else - { - - if(cp[0]==255 && cp[1]==0 && cp[2]==0) - { - cp[0] = CGI->playerColors[player].b; - cp[1] = CGI->playerColors[player].g; - cp[2] = CGI->playerColors[player].r; - } - } - } - } - } -} - -void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player, int mode, void* additionalInfo) -{ - if(player==1) //it is actually blue... - return; - if(sur->format->BitsPerPixel == 8) - { - for(int i=0; i<32; ++i) - { - sur->format->palette->colors[224+i] = playerColorPalette[32*player+i]; - } - } - else if(sur->format->BitsPerPixel == 24) //should never happen in general - { - for(int y=0; yh; ++y) - { - for(int x=0; xw; ++x) - { - Uint8* cp = (Uint8*)sur->pixels + y*sur->pitch + x*3; - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - if(cp[2]>cp[1] && cp[2]>cp[0]) - { - std::vector sort1; - sort1.push_back(cp[0]); - sort1.push_back(cp[1]); - sort1.push_back(cp[2]); - std::vector< std::pair > sort2; - sort2.push_back(std::make_pair(CGI->playerColors[player].r, &(cp[0]))); - sort2.push_back(std::make_pair(CGI->playerColors[player].g, &(cp[1]))); - sort2.push_back(std::make_pair(CGI->playerColors[player].b, &(cp[2]))); - std::sort(sort1.begin(), sort1.end()); - if(sort2[0].first>sort2[1].first) - std::swap(sort2[0], sort2[1]); - if(sort2[1].first>sort2[2].first) - std::swap(sort2[1], sort2[2]); - if(sort2[0].first>sort2[1].first) - std::swap(sort2[0], sort2[1]); - for(int hh=0; hh<3; ++hh) - { - (*sort2[hh].second) = (sort1[hh] + sort2[hh].first)/2.2; - } - } - } - else - { - if( - ((mode==0) && (cp[0]>cp[1]) && (cp[0]>cp[2])) || - ((mode==1) && (cp[2]<45) && (cp[0]>80) && (cp[1]<70) && ((cp[0]-cp[1])>40)) - ) - { - std::vector sort1; - sort1.push_back(cp[2]); - sort1.push_back(cp[1]); - sort1.push_back(cp[0]); - std::vector< std::pair > sort2; - sort2.push_back(std::make_pair(CGI->playerColors[player].r, &(cp[2]))); - sort2.push_back(std::make_pair(CGI->playerColors[player].g, &(cp[1]))); - sort2.push_back(std::make_pair(CGI->playerColors[player].b, &(cp[0]))); - std::sort(sort1.begin(), sort1.end()); - if(sort2[0].first>sort2[1].first) - std::swap(sort2[0], sort2[1]); - if(sort2[1].first>sort2[2].first) - std::swap(sort2[1], sort2[2]); - if(sort2[0].first>sort2[1].first) - std::swap(sort2[0], sort2[1]); - for(int hh=0; hh<3; ++hh) - { - (*sort2[hh].second) = (sort1[hh]*0.8 + sort2[hh].first)/2; - } - } - } - } - } - } -} void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color) { for(int i=0;iformat->BitsPerPixel==8) { if(player != 255) - *(sur->format->palette->colors+5) = CGI->playerColors[player]; + *(sur->format->palette->colors+5) = graphics->playerColors[player]; else - *(sur->format->palette->colors+5) = CGI->neutralColor; + *(sur->format->palette->colors+5) = *graphics->neutralColor; } } int readNormalNr (std::istream &in, int bytCon) @@ -897,15 +730,6 @@ int readNormalNr (std::istream &in, int bytCon) return ret; } -//void CSDL_Ext::fullAlphaTransform(SDL_Surface *& src) -//{ -// src = alphaTransform(src); -// //SDL_Surface * hlp2; -// //hlp2 = secondAlphaTransform(src, std32bppSurface); -// //SDL_FreeSurface(src); -// //src = hlp2; -//} - std::string CSDL_Ext::processStr(std::string str, std::vector & tor) { for (int i=0;(i & tor); //replaces %s in string diff --git a/SDL_rotozoom.cpp b/SDL_rotozoom.cpp deleted file mode 100644 index 2e36db595..000000000 --- a/SDL_rotozoom.cpp +++ /dev/null @@ -1,1231 +0,0 @@ -/* - - SDL_rotozoom.c - rotozoomer for 32bit or 8bit surfaces - - LGPL (c) A. Schiffler - -*/ -#include "stdafx.h" -#ifdef WIN32 -#include -#endif - -#include -#include - -#include "SDL_rotozoom.h" - -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) - - -/* - - 32bit integer-factor averaging Shrinker - - Shrinks 32bit RGBA/ABGR 'src' surface to 'dst' surface. - -*/ - -int shrinkSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory) -{ - int x, y, dx, dy, sgap, dgap, ra, ga, ba, aa; - int n_average; - tColorRGBA *sp, *osp, *oosp; - tColorRGBA *dp; - - /* - * Averaging integer shrink - */ - - /* Precalculate division factor */ - n_average = factorx*factory; - - /* - * Scan destination - */ - sp = (tColorRGBA *) src->pixels; - sgap = src->pitch - src->w * 4; - - dp = (tColorRGBA *) dst->pixels; - dgap = dst->pitch - dst->w * 4; - - for (y = 0; y < dst->h; y++) { - - osp=sp; - for (x = 0; x < dst->w; x++) { - - /* Trace out source box and accumulate */ - oosp=sp; - ra=ga=ba=aa=0; - for (dy=0; dy < factory; dy++) { - for (dx=0; dx < factorx; dx++) { - ra += sp->r; - ga += sp->g; - ba += sp->b; - aa += sp->a; - - sp++; - } // src dx loop - sp = (tColorRGBA *)((Uint8*)sp + (src->pitch - 4*factorx)); // next y - } // src dy loop - - // next box-x - sp = (tColorRGBA *)((Uint8*)oosp + 4*factorx); - - /* Store result in destination */ - dp->r = ra/n_average; - dp->g = ga/n_average; - dp->b = ba/n_average; - dp->a = aa/n_average; - - /* - * Advance destination pointer - */ - dp++; - } // dst x loop - - // next box-y - sp = (tColorRGBA *)((Uint8*)osp + src->pitch*factory); - - /* - * Advance destination pointers - */ - dp = (tColorRGBA *) ((Uint8 *) dp + dgap); - } // dst y loop - - return (0); -} - -/* - - 8bit integer-factor averaging Shrinker - - Shrinks 8bit Y 'src' surface to 'dst' surface. - -*/ - -int shrinkSurfaceY(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory) -{ - int x, y, dx, dy, sgap, dgap, a; - int n_average; - Uint8 *sp, *osp, *oosp; - Uint8 *dp; - - /* - * Averaging integer shrink - */ - - /* Precalculate division factor */ - n_average = factorx*factory; - - /* - * Scan destination - */ - sp = (Uint8 *) src->pixels; - sgap = src->pitch - src->w; - - dp = (Uint8 *) dst->pixels; - dgap = dst->pitch - dst->w; - - for (y = 0; y < dst->h; y++) { - - osp=sp; - for (x = 0; x < dst->w; x++) { - - /* Trace out source box and accumulate */ - oosp=sp; - a=0; - for (dy=0; dy < factory; dy++) { - for (dx=0; dx < factorx; dx++) { - a += (*sp); - sp++; // next x - } // src dx loop - sp = (Uint8 *)((Uint8*)sp + (src->pitch - factorx)); // next y - } // src dy loop - - // next box-x - sp = (Uint8 *)((Uint8*)oosp + factorx); - - /* Store result in destination */ - *dp = a/n_average; - - /* - * Advance destination pointer - */ - dp++; - } // dst x loop - - // next box-y - sp = (Uint8 *)((Uint8*)osp + src->pitch*factory); - - /* - * Advance destination pointers - */ - dp = (Uint8 *)((Uint8 *)dp + dgap); - } // dst y loop - - return (0); -} - -/* - - 32bit Zoomer with optional anti-aliasing by bilinear interpolation. - - Zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface. - -*/ - -int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy, int smooth) -{ - int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy, ex, ey, t1, t2, sstep; - tColorRGBA *c00, *c01, *c10, *c11; - tColorRGBA *sp, *csp, *dp; - int dgap; - - /* - * Variable setup - */ - if (smooth) { - /* - * For interpolation: assume source dimension is one pixel - */ - /* - * smaller to avoid overflow on right and bottom edge. - */ - sx = (int) (65536.0 * (float) (src->w - 1) / (float) dst->w); - sy = (int) (65536.0 * (float) (src->h - 1) / (float) dst->h); - } else { - sx = (int) (65536.0 * (float) src->w / (float) dst->w); - sy = (int) (65536.0 * (float) src->h / (float) dst->h); - } - - /* - * Allocate memory for row increments - */ - if ((sax = (int *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) { - return (-1); - } - if ((say = (int *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL) { - free(sax); - return (-1); - } - - /* - * Precalculate row increments - */ - sp = csp = (tColorRGBA *) src->pixels; - dp = (tColorRGBA *) dst->pixels; - - if (flipx) csp += (src->w-1); - if (flipy) csp = (tColorRGBA*)( (Uint8*)csp + src->pitch*(src->h-1) ); - - csx = 0; - csax = sax; - for (x = 0; x <= dst->w; x++) { - *csax = csx; - csax++; - csx &= 0xffff; - csx += sx; - } - csy = 0; - csay = say; - for (y = 0; y <= dst->h; y++) { - *csay = csy; - csay++; - csy &= 0xffff; - csy += sy; - } - - dgap = dst->pitch - dst->w * 4; - - /* - * Switch between interpolating and non-interpolating code - */ - if (smooth) { - - /* - * Interpolating Zoom - */ - - /* - * Scan destination - */ - csay = say; - for (y = 0; y < dst->h; y++) { - /* - * Setup color source pointers - */ - c00 = csp; - c01 = csp; - c01++; - c10 = (tColorRGBA *) ((Uint8 *) csp + src->pitch); - c11 = c10; - c11++; - csax = sax; - for (x = 0; x < dst->w; x++) { - - /* - * Interpolate colors - */ - ex = (*csax & 0xffff); - ey = (*csay & 0xffff); - t1 = ((((c01->r - c00->r) * ex) >> 16) + c00->r) & 0xff; - t2 = ((((c11->r - c10->r) * ex) >> 16) + c10->r) & 0xff; - dp->r = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01->g - c00->g) * ex) >> 16) + c00->g) & 0xff; - t2 = ((((c11->g - c10->g) * ex) >> 16) + c10->g) & 0xff; - dp->g = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01->b - c00->b) * ex) >> 16) + c00->b) & 0xff; - t2 = ((((c11->b - c10->b) * ex) >> 16) + c10->b) & 0xff; - dp->b = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01->a - c00->a) * ex) >> 16) + c00->a) & 0xff; - t2 = ((((c11->a - c10->a) * ex) >> 16) + c10->a) & 0xff; - dp->a = (((t2 - t1) * ey) >> 16) + t1; - - /* - * Advance source pointers - */ - csax++; - sstep = (*csax >> 16); - c00 += sstep; - c01 += sstep; - c10 += sstep; - c11 += sstep; - /* - * Advance destination pointer - */ - dp++; - } - /* - * Advance source pointer - */ - csay++; - csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch); - /* - * Advance destination pointers - */ - dp = (tColorRGBA *) ((Uint8 *) dp + dgap); - } - - } else { - - /* - * Non-Interpolating Zoom - */ - - csay = say; - for (y = 0; y < dst->h; y++) { - sp = csp; - csax = sax; - for (x = 0; x < dst->w; x++) { - /* - * Draw - */ - *dp = *sp; - /* - * Advance source pointers - */ - csax++; - sstep = (*csax >> 16); - if (flipx) sstep = -sstep; - sp += sstep; - /* - * Advance destination pointer - */ - dp++; - } - /* - * Advance source pointer - */ - csay++; - sstep = (*csay >> 16) * src->pitch; - if (flipy) sstep = -sstep; - csp = (tColorRGBA *) ((Uint8 *) csp + sstep); - - /* - * Advance destination pointers - */ - dp = (tColorRGBA *) ((Uint8 *) dp + dgap); - } - - } - - /* - * Remove temp arrays - */ - free(sax); - free(say); - - return (0); -} - -/* - - 8bit Zoomer without smoothing. - - Zoomes 8bit palette/Y 'src' surface to 'dst' surface. - -*/ - -int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy) -{ - Uint32 x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy; - Uint8 *sp, *dp, *csp; - int dgap; - - /* - * Variable setup - */ - sx = (Uint32) (65536.0 * (float) src->w / (float) dst->w); - sy = (Uint32) (65536.0 * (float) src->h / (float) dst->h); - - /* - * Allocate memory for row increments - */ - if ((sax = (Uint32 *) malloc(dst->w * sizeof(Uint32))) == NULL) { - return (-1); - } - if ((say = (Uint32 *) malloc(dst->h * sizeof(Uint32))) == NULL) { - if (sax != NULL) { - free(sax); - } - return (-1); - } - - /* - * Precalculate row increments - */ - csx = 0; - csax = sax; - for (x = 0; x < dst->w; x++) { - csx += sx; - *csax = (csx >> 16); - csx &= 0xffff; - csax++; - } - csy = 0; - csay = say; - for (y = 0; y < dst->h; y++) { - csy += sy; - *csay = (csy >> 16); - csy &= 0xffff; - csay++; - } - - csx = 0; - csax = sax; - for (x = 0; x < dst->w; x++) { - csx += (*csax); - csax++; - } - csy = 0; - csay = say; - for (y = 0; y < dst->h; y++) { - csy += (*csay); - csay++; - } - - /* - * Pointer setup - */ - sp = csp = (Uint8 *) src->pixels; - dp = (Uint8 *) dst->pixels; - dgap = dst->pitch - dst->w; - - /* - * Draw - */ - csay = say; - for (y = 0; y < dst->h; y++) { - csax = sax; - sp = csp; - for (x = 0; x < dst->w; x++) { - /* - * Draw - */ - *dp = *sp; - /* - * Advance source pointers - */ - sp += (*csax); - csax++; - /* - * Advance destination pointer - */ - dp++; - } - /* - * Advance source pointer (for row) - */ - csp += ((*csay) * src->pitch); - csay++; - /* - * Advance destination pointers - */ - dp += dgap; - } - - /* - * Remove temp arrays - */ - free(sax); - free(say); - - return (0); -} - -/* - - 32bit Rotozoomer with optional anti-aliasing by bilinear interpolation. - - Rotates and zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface. - -*/ - -void transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth) -{ - int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh; - tColorRGBA c00, c01, c10, c11; - tColorRGBA *pc, *sp; - int gap; - - /* - * Variable setup - */ - xd = ((src->w - dst->w) << 15); - yd = ((src->h - dst->h) << 15); - ax = (cx << 16) - (icos * cx); - ay = (cy << 16) - (isin * cx); - sw = src->w - 1; - sh = src->h - 1; - pc = (tColorRGBA*)dst->pixels; - gap = dst->pitch - dst->w * 4; - - /* - * Switch between interpolating and non-interpolating code - */ - if (smooth) { - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (sdx >> 16); - dy = (sdy >> 16); - if ((dx >= -1) && (dy >= -1) && (dx < src->w) && (dy < src->h)) { - if ((dx >= 0) && (dy >= 0) && (dx < sw) && (dy < sh)) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - c00 = *sp; - sp += 1; - c01 = *sp; - sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch); - sp -= 1; - c10 = *sp; - sp += 1; - c11 = *sp; - } else if ((dx == sw) && (dy == sh)) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - c00 = *sp; - c01 = *sp; - c10 = *sp; - c11 = *sp; - } else if ((dx == -1) && (dy == -1)) { - sp = (tColorRGBA *) (src->pixels); - c00 = *sp; - c01 = *sp; - c10 = *sp; - c11 = *sp; - } else if ((dx == -1) && (dy == sh)) { - sp = (tColorRGBA *) (src->pixels); - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - c00 = *sp; - c01 = *sp; - c10 = *sp; - c11 = *sp; - } else if ((dx == sw) && (dy == -1)) { - sp = (tColorRGBA *) (src->pixels); - sp += dx; - c00 = *sp; - c01 = *sp; - c10 = *sp; - c11 = *sp; - } else if (dx == -1) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - c00 = *sp; - c01 = *sp; - c10 = *sp; - sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch); - c11 = *sp; - } else if (dy == -1) { - sp = (tColorRGBA *) (src->pixels); - sp += dx; - c00 = *sp; - c01 = *sp; - c10 = *sp; - sp += 1; - c11 = *sp; - } else if (dx == sw) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - c00 = *sp; - c01 = *sp; - sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch); - c10 = *sp; - c11 = *sp; - } else if (dy == sh) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - c00 = *sp; - sp += 1; - c01 = *sp; - c10 = *sp; - c11 = *sp; - } - /* - * Interpolate colors - */ - ex = (sdx & 0xffff); - ey = (sdy & 0xffff); - t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff; - t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff; - pc->r = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff; - t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff; - pc->g = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff; - t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff; - pc->b = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff; - t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff; - pc->a = (((t2 - t1) * ey) >> 16) + t1; - } - sdx += icos; - sdy += isin; - pc++; - } - pc = (tColorRGBA *) ((Uint8 *) pc + gap); - } - } else { - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (short) (sdx >> 16); - dy = (short) (sdy >> 16); - if (flipx) dx = (src->w-1)-dx; - if (flipy) dy = (src->h-1)-dy; - if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - *pc = *sp; - } - sdx += icos; - sdy += isin; - pc++; - } - pc = (tColorRGBA *) ((Uint8 *) pc + gap); - } - } -} - -/* - - 8bit Rotozoomer without smoothing - - Rotates and zoomes 8bit palette/Y 'src' surface to 'dst' surface. - -*/ - -void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos) -{ - int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay, sw, sh; - tColorY *pc, *sp; - int gap; - - /* - * Variable setup - */ - xd = ((src->w - dst->w) << 15); - yd = ((src->h - dst->h) << 15); - ax = (cx << 16) - (icos * cx); - ay = (cy << 16) - (isin * cx); - sw = src->w - 1; - sh = src->h - 1; - pc = (tColorY*)dst->pixels; - gap = dst->pitch - dst->w; - /* - * Clear surface to colorkey - */ - memset(pc, (unsigned char) (src->format->colorkey & 0xff), dst->pitch * dst->h); - /* - * Iterate through destination surface - */ - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (short) (sdx >> 16); - dy = (short) (sdy >> 16); - if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) { - sp = (tColorY *) (src->pixels); - sp += (src->pitch * dy + dx); - *pc = *sp; - } - sdx += icos; - sdy += isin; - pc++; - } - pc += gap; - } -} - -/* - - rotozoomSurface() - - Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. - 'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1 - then the destination 32bit surface is anti-aliased. If the surface is not 8bit - or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. - -*/ - -#define VALUE_LIMIT 0.001 - - -/* Local rotozoom-size function with trig result return */ - -void rotozoomSurfaceSizeTrig(int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight, - double *canglezoom, double *sanglezoom) -{ - double x, y, cx, cy, sx, sy; - double radangle; - int dstwidthhalf, dstheighthalf; - - /* - * Determine destination width and height by rotating a centered source box - */ - radangle = angle * (M_PI / 180.0); - *sanglezoom = sin(radangle); - *canglezoom = cos(radangle); - *sanglezoom *= zoomx; - *canglezoom *= zoomx; - x = width / 2; - y = height / 2; - cx = *canglezoom * x; - cy = *canglezoom * y; - sx = *sanglezoom * x; - sy = *sanglezoom * y; - - dstwidthhalf = MAX((int) - ceil(MAX(MAX(MAX(fabs(cx + sy), fabs(cx - sy)), fabs(-cx + sy)), fabs(-cx - sy))), 1); - dstheighthalf = MAX((int) - ceil(MAX(MAX(MAX(fabs(sx + cy), fabs(sx - cy)), fabs(-sx + cy)), fabs(-sx - cy))), 1); - *dstwidth = 2 * dstwidthhalf; - *dstheight = 2 * dstheighthalf; -} - - -/* Publically available rotozoom-size function */ - -void rotozoomSurfaceSizeXY(int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight) -{ - double dummy_sanglezoom, dummy_canglezoom; - - rotozoomSurfaceSizeTrig(width, height, angle, zoomx, zoomy, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom); -} - -/* Publically available rotozoom-size function */ - -void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, int *dstheight) -{ - double dummy_sanglezoom, dummy_canglezoom; - - rotozoomSurfaceSizeTrig(width, height, angle, zoom, zoom, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom); -} - -/* Publically available rotozoom function */ - -SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth) -{ - return rotozoomSurfaceXY(src, angle, zoom, zoom, smooth); -} - -/* Publically available rotozoom function */ - -SDL_Surface *rotozoomSurfaceXY(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth) -{ - SDL_Surface *rz_src; - SDL_Surface *rz_dst; - double zoominv; - double sanglezoom, canglezoom, sanglezoominv, canglezoominv; - int dstwidthhalf, dstwidth, dstheighthalf, dstheight; - int is32bit; - int i, src_converted; - int flipx,flipy; - - /* - * Sanity check - */ - if (src == NULL) - return (NULL); - - /* - * Determine if source surface is 32bit or 8bit - */ - is32bit = (src->format->BitsPerPixel == 32); - if ((is32bit) || (src->format->BitsPerPixel == 8)) { - /* - * Use source surface 'as is' - */ - rz_src = src; - src_converted = 0; - } else { - /* - * New source surface is 32bit with a defined RGBA ordering - */ - rz_src = - SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(src, NULL, rz_src, NULL); - src_converted = 1; - is32bit = 1; - } - - /* - * Sanity check zoom factor - */ - flipx = (zoomx<0); - if (flipx) zoomx=-zoomx; - flipy = (zoomy<0); - if (flipy) zoomy=-zoomy; - if (zoomx < VALUE_LIMIT) zoomx = VALUE_LIMIT; - if (zoomy < VALUE_LIMIT) zoomy = VALUE_LIMIT; - zoominv = 65536.0 / (zoomx * zoomx); - - /* - * Check if we have a rotozoom or just a zoom - */ - if (fabs(angle) > VALUE_LIMIT) { - - /* - * Angle!=0: full rotozoom - */ - /* - * ----------------------- - */ - - /* Determine target size */ - rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, zoomx, zoomy, &dstwidth, &dstheight, &canglezoom, &sanglezoom); - - /* - * Calculate target factors from sin/cos and zoom - */ - sanglezoominv = sanglezoom; - canglezoominv = canglezoom; - sanglezoominv *= zoominv; - canglezoominv *= zoominv; - - /* Calculate half size */ - dstwidthhalf = dstwidth / 2; - dstheighthalf = dstheight / 2; - - /* - * Alloc space to completely contain the rotated surface - */ - rz_dst = NULL; - if (is32bit) { - /* - * Target surface is 32bit with source RGBA/ABGR ordering - */ - rz_dst = - SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32, - rz_src->format->Rmask, rz_src->format->Gmask, - rz_src->format->Bmask, rz_src->format->Amask); - } else { - /* - * Target surface is 8bit - */ - rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0); - } - - /* - * Lock source surface - */ - SDL_LockSurface(rz_src); - /* - * Check which kind of surface we have - */ - if (is32bit) { - /* - * Call the 32bit transformation routine to do the rotation (using alpha) - */ - transformSurfaceRGBA(rz_src, rz_dst, dstwidthhalf, dstheighthalf, - (int) (sanglezoominv), (int) (canglezoominv), - flipx, flipy, - smooth); - /* - * Turn on source-alpha support - */ - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); - } else { - /* - * Copy palette and colorkey info - */ - for (i = 0; i < rz_src->format->palette->ncolors; i++) { - rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i]; - } - rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; - /* - * Call the 8bit transformation routine to do the rotation - */ - transformSurfaceY(rz_src, rz_dst, dstwidthhalf, dstheighthalf, - (int) (sanglezoominv), (int) (canglezoominv)); - SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey); - } - /* - * Unlock source surface - */ - SDL_UnlockSurface(rz_src); - - } else { - - /* - * Angle=0: Just a zoom - */ - /* - * -------------------- - */ - - /* - * Calculate target size - */ - zoomSurfaceSize(rz_src->w, rz_src->h, zoomx, zoomy, &dstwidth, &dstheight); - - /* - * Alloc space to completely contain the zoomed surface - */ - rz_dst = NULL; - if (is32bit) { - /* - * Target surface is 32bit with source RGBA/ABGR ordering - */ - rz_dst = - SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32, - rz_src->format->Rmask, rz_src->format->Gmask, - rz_src->format->Bmask, rz_src->format->Amask); - } else { - /* - * Target surface is 8bit - */ - rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0); - } - - /* - * Lock source surface - */ - SDL_LockSurface(rz_src); - /* - * Check which kind of surface we have - */ - if (is32bit) { - /* - * Call the 32bit transformation routine to do the zooming (using alpha) - */ - zoomSurfaceRGBA(rz_src, rz_dst, flipx, flipy, smooth); - /* - * Turn on source-alpha support - */ - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); - } else { - /* - * Copy palette and colorkey info - */ - for (i = 0; i < rz_src->format->palette->ncolors; i++) { - rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i]; - } - rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; - /* - * Call the 8bit transformation routine to do the zooming - */ - zoomSurfaceY(rz_src, rz_dst, flipx, flipy); - SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey); - } - /* - * Unlock source surface - */ - SDL_UnlockSurface(rz_src); - } - - /* - * Cleanup temp surface - */ - if (src_converted) { - SDL_FreeSurface(rz_src); - } - - /* - * Return destination surface - */ - return (rz_dst); -} - -/* - - zoomSurface() - - Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. - 'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1 - then the destination 32bit surface is anti-aliased. If the surface is not 8bit - or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. - -*/ - -#define VALUE_LIMIT 0.001 - -void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight) -{ - /* - * Sanity check zoom factors - */ - if (zoomx < VALUE_LIMIT) { - zoomx = VALUE_LIMIT; - } - if (zoomy < VALUE_LIMIT) { - zoomy = VALUE_LIMIT; - } - - /* - * Calculate target size - */ - *dstwidth = (int) ((double) width * zoomx); - *dstheight = (int) ((double) height * zoomy); - if (*dstwidth < 1) { - *dstwidth = 1; - } - if (*dstheight < 1) { - *dstheight = 1; - } -} - -SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth) -{ - SDL_Surface *rz_src; - SDL_Surface *rz_dst; - int dstwidth, dstheight; - int is32bit; - int i, src_converted; - int flipx, flipy; - - /* - * Sanity check - */ - if (src == NULL) - return (NULL); - - /* - * Determine if source surface is 32bit or 8bit - */ - is32bit = (src->format->BitsPerPixel == 32); - if ((is32bit) || (src->format->BitsPerPixel == 8)) { - /* - * Use source surface 'as is' - */ - rz_src = src; - src_converted = 0; - } else { - /* - * New source surface is 32bit with a defined RGBA ordering - */ - rz_src = - SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(src, NULL, rz_src, NULL); - src_converted = 1; - is32bit = 1; - } - - flipx = (zoomx<0); - if (flipx) zoomx = -zoomx; - flipy = (zoomy<0); - if (flipy) zoomy = -zoomy; - - /* Get size if target */ - zoomSurfaceSize(rz_src->w, rz_src->h, zoomx, zoomy, &dstwidth, &dstheight); - - /* - * Alloc space to completely contain the zoomed surface - */ - rz_dst = NULL; - if (is32bit) { - /* - * Target surface is 32bit with source RGBA/ABGR ordering - */ - rz_dst = - SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32, - rz_src->format->Rmask, rz_src->format->Gmask, - rz_src->format->Bmask, rz_src->format->Amask); - } else { - /* - * Target surface is 8bit - */ - rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0); - } - - /* - * Lock source surface - */ - SDL_LockSurface(rz_src); - /* - * Check which kind of surface we have - */ - if (is32bit) { - /* - * Call the 32bit transformation routine to do the zooming (using alpha) - */ - zoomSurfaceRGBA(rz_src, rz_dst, flipx, flipy, smooth); - /* - * Turn on source-alpha support - */ - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); - } else { - /* - * Copy palette and colorkey info - */ - for (i = 0; i < rz_src->format->palette->ncolors; i++) { - rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i]; - } - rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; - /* - * Call the 8bit transformation routine to do the zooming - */ - zoomSurfaceY(rz_src, rz_dst, flipx, flipy); - SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey); - } - /* - * Unlock source surface - */ - SDL_UnlockSurface(rz_src); - - /* - * Cleanup temp surface - */ - if (src_converted) { - SDL_FreeSurface(rz_src); - } - - /* - * Return destination surface - */ - return (rz_dst); -} - -SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory) -{ - SDL_Surface *rz_src; - SDL_Surface *rz_dst; - int dstwidth, dstheight; - int is32bit; - int i, src_converted; - - /* - * Sanity check - */ - if (src == NULL) - return (NULL); - - /* - * Determine if source surface is 32bit or 8bit - */ - is32bit = (src->format->BitsPerPixel == 32); - if ((is32bit) || (src->format->BitsPerPixel == 8)) { - /* - * Use source surface 'as is' - */ - rz_src = src; - src_converted = 0; - } else { - /* - * New source surface is 32bit with a defined RGBA ordering - */ - rz_src = - SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(src, NULL, rz_src, NULL); - src_converted = 1; - is32bit = 1; - } - - /* Get size for target */ - dstwidth=rz_src->w/factorx; - while (dstwidth*factorx>rz_src->w) { dstwidth--; } - dstheight=rz_src->h/factory; - while (dstheight*factory>rz_src->h) { dstheight--; } - - /* - * Alloc space to completely contain the shrunken surface - */ - rz_dst = NULL; - if (is32bit) { - /* - * Target surface is 32bit with source RGBA/ABGR ordering - */ - rz_dst = - SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32, - rz_src->format->Rmask, rz_src->format->Gmask, - rz_src->format->Bmask, rz_src->format->Amask); - } else { - /* - * Target surface is 8bit - */ - rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0); - } - - /* - * Lock source surface - */ - SDL_LockSurface(rz_src); - /* - * Check which kind of surface we have - */ - if (is32bit) { - /* - * Call the 32bit transformation routine to do the shrinking (using alpha) - */ - shrinkSurfaceRGBA(rz_src, rz_dst, factorx, factory); - /* - * Turn on source-alpha support - */ - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); - } else { - /* - * Copy palette and colorkey info - */ - for (i = 0; i < rz_src->format->palette->ncolors; i++) { - rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i]; - } - rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; - /* - * Call the 8bit transformation routine to do the shrinking - */ - shrinkSurfaceY(rz_src, rz_dst, factorx, factory); - SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey); - } - /* - * Unlock source surface - */ - SDL_UnlockSurface(rz_src); - - /* - * Cleanup temp surface - */ - if (src_converted) { - SDL_FreeSurface(rz_src); - } - - /* - * Return destination surface - */ - return (rz_dst); -} diff --git a/SDL_rotozoom.h b/SDL_rotozoom.h deleted file mode 100644 index cc3b7720b..000000000 --- a/SDL_rotozoom.h +++ /dev/null @@ -1,117 +0,0 @@ - -/* - - SDL_rotozoom - rotozoomer - - LGPL (c) A. Schiffler - -*/ - -#ifndef _SDL_rotozoom_h -#define _SDL_rotozoom_h - -#include - -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef M_PI -#define M_PI 3.141592654 -#endif - -#include "SDL.h" - -/* ---- Defines */ - -#define SMOOTHING_OFF 0 -#define SMOOTHING_ON 1 - -/* ---- Structures */ - - typedef struct tColorRGBA { - Uint8 r; - Uint8 g; - Uint8 b; - Uint8 a; - } tColorRGBA; - - typedef struct tColorY { - Uint8 y; - } tColorY; - - -/* ---- Prototypes */ - -#ifdef WIN32 -#ifdef BUILD_DLL -#define DLLINTERFACE __declspec(dllexport) -#else -#define DLLINTERFACE __declspec(dllimport) -#endif -#else -#define DLLINTERFACE -#endif - -/* - - rotozoomSurface() - - Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. - 'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1 - then the destination 32bit surface is anti-aliased. If the surface is not 8bit - or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. - -*/ - - SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth); - - SDL_Surface *rotozoomSurfaceXY - (SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth); - -/* Returns the size of the target surface for a rotozoomSurface() call */ - - void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, - int *dstheight); - - void rotozoomSurfaceSizeXY - (int width, int height, double angle, double zoomx, double zoomy, - int *dstwidth, int *dstheight); - -/* - - zoomSurface() - - Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. - 'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1 - then the destination 32bit surface is anti-aliased. If the surface is not 8bit - or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. - -*/ - - SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth); - -/* Returns the size of the target surface for a zoomSurface() call */ - - void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight); - - -/* - shrinkSurface() - - Shrinks a 32bit or 8bit 'src' surface ti a newly created 'dst' surface. - 'factorx' and 'factory' are the shrinking ratios (i.e. 2=1/2 the size, - 3=1/3 the size, etc.) The destination surface is antialiased by averaging - the source box RGBA or Y information. If the surface is not 8bit - or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. -*/ - - SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory); - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif - -#endif /* _SDL_rotozoom_h */ diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 02da2ebe8..db65b451b 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -2,7 +2,6 @@ #include "Graphics.h" #include "../hch/CDefHandler.h" #include "../hch/CObjectHandler.h" -//#include "../hch/CHeroHandler.h" #include "../SDL_Extensions.h" #include #include @@ -12,6 +11,8 @@ #include #include #include "../CThreadHelper.h" +#include "../CGameInfo.h" +#include "../hch/CLodHandler.h" using namespace boost::assign; using namespace CSDL_Ext; Graphics * graphics = NULL; @@ -30,7 +31,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh) { char * buf = new char[10]; SDL_Surface * ret = SDL_DisplayFormat(hInfo); - blueToPlayersAdv(hInfo,curh->tempOwner,1); + blueToPlayersAdv(hInfo,curh->tempOwner); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); printAt(curh->name,75,15,GEOR13,zwykly,ret); drawPrimarySkill(curh, ret); @@ -52,7 +53,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh) SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh) { char * buf = new char[10]; - blueToPlayersAdv(tInfo,curh->tempOwner,1); + blueToPlayersAdv(tInfo,curh->tempOwner); SDL_Surface * ret = SDL_DisplayFormat(tInfo); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); printAt(curh->name,75,15,GEOR13,zwykly,ret); @@ -82,6 +83,35 @@ SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh) delete[] buf; return ret; } + +void Graphics::loadPaletteAndColors() +{ + std::string pals = CGI->bitmaph->getTextFile("PLAYERS.PAL"); + playerColorPalette = new SDL_Color[256]; + neutralColor = new SDL_Color; + playerColors = new SDL_Color[PLAYER_LIMIT]; + int startPoint = 24; //beginning byte; used to read + for(int i=0; i<256; ++i) + { + SDL_Color col; + col.r = pals[startPoint++]; + col.g = pals[startPoint++]; + col.b = pals[startPoint++]; + col.unused = pals[startPoint++]; + playerColorPalette[i] = col; + } + //colors initialization + int3 kolory[] = {int3(0xff,0,0),int3(0x31,0x52,0xff),int3(0x9c,0x73,0x52),int3(0x42,0x94,0x29), + int3(0xff,0x84,0x0),int3(0x8c,0x29,0xa5),int3(0x09,0x9c,0xa5),int3(0xc6,0x7b,0x8c)}; + for(int i=0;i<8;i++) + { + playerColors[i].r = kolory[i].x; + playerColors[i].g = kolory[i].y; + playerColors[i].b = kolory[i].z; + playerColors[i].unused = 0; + } + neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84;//gray +} Graphics::Graphics() { slotsPos.push_back(std::pair(44,82)); @@ -95,6 +125,7 @@ Graphics::Graphics() CDefHandler *smi, *smi2; std::vector tasks; //preparing list of graphics to load + tasks += boost::bind(&Graphics::loadPaletteAndColors,this); tasks += boost::bind(&Graphics::loadHeroFlags,this); tasks += boost::bind(&Graphics::loadHeroPortraits,this); tasks += GET_SURFACE(hInfo,"HEROQVBK.bmp"); @@ -339,4 +370,80 @@ SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded) pom--; return smallIcons->ourImages[pom].bitmap; } +} + +void Graphics::blueToPlayersAdv(SDL_Surface * sur, int player) +{ + if(player==1) //it is actually blue... + return; + if(sur->format->BitsPerPixel == 8) + { + for(int i=0; i<32; ++i) + { + sur->format->palette->colors[224+i] = playerColorPalette[32*player+i]; + } + } + else if(sur->format->BitsPerPixel == 24) //should never happen in general + { + for(int y=0; yh; ++y) + { + for(int x=0; xw; ++x) + { + Uint8* cp = (Uint8*)sur->pixels + y*sur->pitch + x*3; + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + if(cp[2]>cp[1] && cp[2]>cp[0]) + { + std::vector sort1; + sort1.push_back(cp[0]); + sort1.push_back(cp[1]); + sort1.push_back(cp[2]); + std::vector< std::pair > sort2; + sort2.push_back(std::make_pair(graphics->playerColors[player].r, &(cp[0]))); + sort2.push_back(std::make_pair(graphics->playerColors[player].g, &(cp[1]))); + sort2.push_back(std::make_pair(graphics->playerColors[player].b, &(cp[2]))); + std::sort(sort1.begin(), sort1.end()); + if(sort2[0].first>sort2[1].first) + std::swap(sort2[0], sort2[1]); + if(sort2[1].first>sort2[2].first) + std::swap(sort2[1], sort2[2]); + if(sort2[0].first>sort2[1].first) + std::swap(sort2[0], sort2[1]); + for(int hh=0; hh<3; ++hh) + { + (*sort2[hh].second) = (sort1[hh] + sort2[hh].first)/2.2; + } + } + } + else + { + if( + (/*(mode==0) && (cp[0]>cp[1]) && (cp[0]>cp[2])) || + ((mode==1) &&*/ (cp[2]<45) && (cp[0]>80) && (cp[1]<70) && ((cp[0]-cp[1])>40)) + ) + { + std::vector sort1; + sort1.push_back(cp[2]); + sort1.push_back(cp[1]); + sort1.push_back(cp[0]); + std::vector< std::pair > sort2; + sort2.push_back(std::make_pair(graphics->playerColors[player].r, &(cp[2]))); + sort2.push_back(std::make_pair(graphics->playerColors[player].g, &(cp[1]))); + sort2.push_back(std::make_pair(graphics->playerColors[player].b, &(cp[0]))); + std::sort(sort1.begin(), sort1.end()); + if(sort2[0].first>sort2[1].first) + std::swap(sort2[0], sort2[1]); + if(sort2[1].first>sort2[2].first) + std::swap(sort2[1], sort2[2]); + if(sort2[0].first>sort2[1].first) + std::swap(sort2[0], sort2[1]); + for(int hh=0; hh<3; ++hh) + { + (*sort2[hh].second) = (sort1[hh]*0.8 + sort2[hh].first)/2; + } + } + } + } + } + } } \ No newline at end of file diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index 7239c57ed..a5ee95d9b 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -41,6 +41,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="G:\vcmt\repa\include" + GeneratePreprocessedFile="0" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -304,10 +305,6 @@ RelativePath="..\CGameInterface.cpp" > - - @@ -384,10 +381,6 @@ RelativePath="..\SDL_framerate.cpp" > - - @@ -598,10 +591,6 @@ RelativePath="..\CGameInterface.h" > - - @@ -694,10 +683,6 @@ RelativePath="..\SDL_framerate.h" > - - diff --git a/global.h b/global.h index 17a8f6549..f49cddd6e 100644 --- a/global.h +++ b/global.h @@ -41,6 +41,8 @@ extern CGameInfo* CGI; #define LOGE(x) ; #endif +#define NAME_VER ("VCMI \"Altanatse\" 0.7") + const int F_NUMBER = 9; //factions (town types) quantity const int PLAYER_LIMIT = 8; //player limit per map const int HEROES_PER_TYPE=8; //amount of heroes of each type diff --git a/hch/CDefObjInfoHandler.cpp b/hch/CDefObjInfoHandler.cpp index 9474b1b27..fb51a6987 100644 --- a/hch/CDefObjInfoHandler.cpp +++ b/hch/CDefObjInfoHandler.cpp @@ -4,6 +4,7 @@ #include "../CGameInfo.h" #include "CLodHandler.h" #include +#include "../lib/VCMI_Lib.h" extern CLodHandler * bitmaph; bool CGDefInfo::isVisitable() { @@ -20,6 +21,7 @@ CGDefInfo::CGDefInfo() } void CDefObjInfoHandler::load() { + VLC->dobjinfo = this; nodrze ideki; std::istringstream inp(bitmaph->getTextFile("ZOBJCTS.TXT")); int objNumber; @@ -58,8 +60,8 @@ void CDefObjInfoHandler::load() } } - for(int yy=0; yy<2; ++yy) - inp>>dump; + for(int yy=0; yy<2; ++yy) //first - on which types of terrain object can be placed; + inp>>dump; //second -in which terrains' menus object in the editor will be available (?) inp>>nobj->id; inp>>nobj->subid; inp>>nobj->type; diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index dd5e65572..1a5550c02 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -3,6 +3,7 @@ #include "CHeroHandler.h" #include #include "CLodHandler.h" +#include "../lib/VCMI_Lib.h" extern CLodHandler * bitmaph; void loadToIt(std::string &dest, std::string &src, int &iter, int mode); CHeroHandler::~CHeroHandler() @@ -20,6 +21,7 @@ void CHeroHandler::loadPortraits() } void CHeroHandler::loadHeroes() { + VLC->heroh = this; int ID=0; std::string buf = bitmaph->getTextFile("HOTRAITS.TXT"); int it=0; diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index c1b29519c..1c4e63549 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -13,6 +13,7 @@ DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mod extern CLodHandler * bitmaph; void CObjectHandler::loadObjects() { + VLC->objh = this; int ID=0; std::string buf = bitmaph->getTextFile("OBJNAMES.TXT"); int it=0; diff --git a/hch/CSpellHandler.cpp b/hch/CSpellHandler.cpp index d31dc73b2..244969e48 100644 --- a/hch/CSpellHandler.cpp +++ b/hch/CSpellHandler.cpp @@ -1,4 +1,4 @@ -#include "../stdafx.h" + #include "../stdafx.h" #include "CSpellHandler.h" #include "../CGameInfo.h" #include "CLodHandler.h" diff --git a/hch/CTownHandler.cpp b/hch/CTownHandler.cpp index 91943cd43..a2648587f 100644 --- a/hch/CTownHandler.cpp +++ b/hch/CTownHandler.cpp @@ -3,10 +3,13 @@ #include "CTownHandler.h" #include "CLodHandler.h" #include +#include "../lib/VCMI_Lib.h" extern CLodHandler * bitmaph; void loadToIt(std::string &dest, std::string &src, int &iter, int mode); CTownHandler::CTownHandler() -{} +{ + VLC->townh = this; +} CTownHandler::~CTownHandler() {} void CTownHandler::loadNames() diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index 2bbcdafa2..b569b6e7a 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -3,18 +3,18 @@ //class CMapHandler; class CArtHandler; -//class CHeroHandler; +class CHeroHandler; class CCreatureHandler; //class CAbilityHandler; //class CSpellHandler; //class CAmbarCendamo; //class CPreGameTextHandler; //class CBuildingHandler; -//class CObjectHandler; +class CObjectHandler; //class CMusicHandler; //class CSemiLodHandler; class CDefObjInfoHandler; -//class CTownHandler; +class CTownHandler; //class CGeneralTextHandler; //class CConsoleHandler; //class CPathfinder; @@ -31,18 +31,18 @@ class LibClasses public: //CGameState * state; CArtHandler * arth; - //CHeroHandler * heroh; + CHeroHandler * heroh; CCreatureHandler * creh; //CAbilityHandler * abilh; //CSpellHandler * spellh; //CMapHandler * mh; //CPreGameTextHandler * preth; //CBuildingHandler * buildh; - //CObjectHandler * objh; + CObjectHandler * objh; //CMusicHandler * mush; //CSemiLodHandler * sspriteh; CDefObjInfoHandler * dobjinfo; - //CTownHandler * townh; + CTownHandler * townh; //CGeneralTextHandler * generaltexth; //CConsoleHandler * consoleh; //CPathfinder * pathf; diff --git a/lib/VCMI_lib.vcproj b/lib/VCMI_lib.vcproj index 0d46c51af..0d1c12fb8 100644 --- a/lib/VCMI_lib.vcproj +++ b/lib/VCMI_lib.vcproj @@ -326,8 +326,6 @@ + + @@ -403,6 +405,10 @@ RelativePath="..\hch\CDefObjInfoHandler.h" > + + diff --git a/map.cpp b/map.cpp index 11a1f0e26..461867fcc 100644 --- a/map.cpp +++ b/map.cpp @@ -947,7 +947,6 @@ Mapa::Mapa(unsigned char * bufor) //////READING DEF INFO/////// int defAmount = readNormalNr(bufor,i); i+=4; defy.reserve(defAmount); - for (int idd = 0 ; iddmovement = -1; if(nhi->ID==34) heroes.push_back(nhi); - //else - // CGI->objh->objInstances.push_back(nhi); - break; } case CREATURES_DEF: @@ -1860,7 +1856,8 @@ Mapa::Mapa(unsigned char * bufor) nt->builded = 0; nt->destroyed = 0; nt->garrisonHero = NULL; - towns.push_back(nt); + if(nt->ID=98) + towns.push_back(nt); break; } case EDefType::PLAYERONLY_DEF: @@ -2290,4 +2287,13 @@ borderguardend: //map readed, bufor no longer needed delete[] bufor; bufor=NULL; +} +CGHeroInstance * Mapa::getHero(int ID, int mode) +{ + if (mode != 0) + throw new std::exception("gs->getHero: This mode is not supported!"); + for(int i=0; isubID == ID) + return heroes[i]; + return NULL; } \ No newline at end of file diff --git a/map.h b/map.h index 5c0f24b5f..3de6a6900 100644 --- a/map.h +++ b/map.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "global.h" class CGDefInfo; class CGObjectInstance; @@ -363,40 +364,6 @@ public: int firstOccurence; int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time; }; -struct DLL_EXPORT Mapa -{ - Eformat version; // version of map Eformat - int twoLevel; // if map has underground level - int difficulty; // 0 easy - 4 impossible - int levelLimit; - bool areAnyPLayers; // if there are any playable players on map - std::string name; //name of map - std::string description; //and description - int height, width; - TerrainTile** terrain; - TerrainTile** undergroungTerrain; // used only if there is underground level - std::vector rumors; - std::vector disposedHeroes; - std::vector predefinedHeroes; - std::vector defy; // list of .def files - PlayerInfo players[8]; // info about players - std::vector teams; // teams[i] = team of player no i - LossCondition lossCondition; - EvictoryConditions victoryCondition; //victory conditions - CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard - int howManyTeams; - std::vector allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed - std::vector allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed - std::vector allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed - std::vector allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed - std::vector events; - - std::vector objects; - std::vector heroes; - std::vector towns; - - Mapa(unsigned char * bufor); //creates map from decompressed .h3m data -}; class DLL_EXPORT CMapHeader { public: @@ -478,4 +445,40 @@ public: }; mapSorter(ESortBy es):sortBy(es){}; }; +struct DLL_EXPORT Mapa +{ + Eformat version; // version of map Eformat + int twoLevel; // if map has underground level + int difficulty; // 0 easy - 4 impossible + int levelLimit; + bool areAnyPLayers; // if there are any playable players on map + std::string name; //name of map + std::string description; //and description + int height, width; + TerrainTile** terrain; + TerrainTile** undergroungTerrain; // used only if there is underground level + std::vector rumors; + std::vector disposedHeroes; + std::vector predefinedHeroes; + std::vector defy; // list of .def files with definitions from .h3m (may be custom) + std::set defs; // other defInfos - for randomized objects, objects added or modified by script + PlayerInfo players[8]; // info about players + std::vector teams; // teams[i] = team of player no i + LossCondition lossCondition; + EvictoryConditions victoryCondition; //victory conditions + CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard + int howManyTeams; + std::vector allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed + std::vector allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed + std::vector allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed + std::vector allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed + std::vector events; + + std::vector objects; + std::vector heroes; + std::vector towns; + + Mapa(unsigned char * bufor); //creates map from decompressed .h3m data + CGHeroInstance * getHero(int ID, int mode=0); +}; #endif //MAPD_H diff --git a/mapHandler.cpp b/mapHandler.cpp index ae9164a8f..fb8a40ca5 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -1,9 +1,8 @@ #include "stdafx.h" #include "mapHandler.h" -#include "SDL_rotozoom.h" #include "SDL_Extensions.h" #include "CGameInfo.h" -#include "stdlib.h" +#include #include "hch\CLodHandler.h" #include "hch\CDefObjInfoHandler.h" #include @@ -11,7 +10,6 @@ #include "CLua.h" #include "hch\CHeroHandler.h" #include "hch\CTownHandler.h" -#include "hch\CArtHandler.h" #include "client\Graphics.h" #include #include @@ -87,262 +85,10 @@ void alphaTransformDef(CGDefInfo * defInfo) for(int yy=0;yyhandler->ourImages.size();yy++) { defInfo->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(defInfo->handler->ourImages[yy].bitmap); - //SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(defInfo->handler->ourImages[yy].bitmap, alphaTransSurf); - //SDL_FreeSurface(defInfo->handler->ourImages[yy].bitmap); - //defInfo->handler->ourImages[yy].bitmap = bufs; defInfo->handler->alphaTransformed = true; } SDL_FreeSurface(alphaTransSurf); } -int CMapHandler::pickHero(int owner) -{ - int h; - if(usedHeroes.find(h = CGI->scenarioOps.getIthPlayersSettings(owner).hero)==usedHeroes.end() && h>=0) //we haven't used selected hero - { - usedHeroes.insert(h); - return h; - } - int f = CGI->scenarioOps.getIthPlayersSettings(owner).castle; - int i=0; - do //try to find free hero of our faction - { - i++; - h = CGI->scenarioOps.getIthPlayersSettings(owner).castle*HEROES_PER_TYPE*2+(rand()%(HEROES_PER_TYPE*2));//cgi->scenarioOps.playerInfos[pru].hero = cgi-> - } while((usedHeroes.find(h)!=usedHeroes.end()) && i<175); - if(i>174) //probably no free heroes - there's no point in further search, we'll take first free - { - for(int j=0; j CMapHandler::pickObject(CGObjectInstance *obj) -{ - switch(obj->ID) - { - case 65: //random artifact - return std::pair(5,(rand()%136)+7); //tylko sensowny zakres - na poczatku sa katapulty itp, na koncu specjalne i blanki - case 66: //random treasure artifact - return std::pair(5,CGI->arth->treasures[rand()%CGI->arth->treasures.size()]->id); - case 67: //random minor artifact - return std::pair(5,CGI->arth->minors[rand()%CGI->arth->minors.size()]->id); - case 68: //random major artifact - return std::pair(5,CGI->arth->majors[rand()%CGI->arth->majors.size()]->id); - case 69: //random relic artifact - return std::pair(5,CGI->arth->relics[rand()%CGI->arth->relics.size()]->id); - case 70: //random hero - { - return std::pair(34,pickHero(obj->tempOwner)); - } - case 71: //random monster - return std::pair(54,rand()%(CGI->creh->creatures.size())); - case 72: //random monster lvl1 - return std::pair(54,CGI->creh->levelCreatures[1][rand()%CGI->creh->levelCreatures[1].size()]->idNumber); - case 73: //random monster lvl2 - return std::pair(54,CGI->creh->levelCreatures[2][rand()%CGI->creh->levelCreatures[2].size()]->idNumber); - case 74: //random monster lvl3 - return std::pair(54,CGI->creh->levelCreatures[3][rand()%CGI->creh->levelCreatures[3].size()]->idNumber); - case 75: //random monster lvl4 - return std::pair(54,CGI->creh->levelCreatures[4][rand()%CGI->creh->levelCreatures[4].size()]->idNumber); - case 76: //random resource - return std::pair(79,rand()%7); //now it's OH3 style, use %8 for mithril - case 77: //random town - { - int align = ((CGTownInstance*)obj)->alignment, - f; - if(align>PLAYER_LIMIT-1)//same as owner / random - { - if(obj->tempOwner > PLAYER_LIMIT-1) - f = -1; //random - else - f = CGI->scenarioOps.getIthPlayersSettings(obj->tempOwner).castle; - } - else - { - f = CGI->scenarioOps.getIthPlayersSettings(align).castle; - } - if(f<0) f = rand()%CGI->townh->towns.size(); - return std::pair(98,f); - } - case 162: //random monster lvl5 - return std::pair(54,CGI->creh->levelCreatures[5][rand()%CGI->creh->levelCreatures[5].size()]->idNumber); - case 163: //random monster lvl6 - return std::pair(54,CGI->creh->levelCreatures[6][rand()%CGI->creh->levelCreatures[6].size()]->idNumber); - case 164: //random monster lvl7 - return std::pair(54,CGI->creh->levelCreatures[7][rand()%CGI->creh->levelCreatures[7].size()]->idNumber); - case 216: //random dwelling - { - int faction = rand()%F_NUMBER; - CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info; - if (info->asCastle) - { - for(int i=0;iobjects.size();i++) - { - if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) - { - randomizeObject(map->objects[i]); //we have to randomize the castle first - faction = map->objects[i]->subID; - break; - } - else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) - { - faction = map->objects[i]->subID; - break; - } - } - } - else - { - while((!(info->castles[0]&(1<7) && (info->castles[1]&(1<<(faction-8)))) - break; - faction = rand()%F_NUMBER; - } - } - int level = ((info->maxLevel-info->minLevel) ? (rand()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel)); - int cid = CGI->townh->towns[faction].basicCreatures[level]; - for(int i=0;iobjh->cregens.size();i++) - if(CGI->objh->cregens[i]==cid) - return std::pair(17,i); - std::cout << "Cannot find a dwelling for creature "<(17,0); - } - case 217: - { - int faction = rand()%F_NUMBER; - CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info; - if (info->asCastle) - { - for(int i=0;iobjects.size();i++) - { - if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) - { - randomizeObject(map->objects[i]); //we have to randomize the castle first - faction = map->objects[i]->subID; - break; - } - else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) - { - faction = map->objects[i]->subID; - break; - } - } - } - else - { - while((!(info->castles[0]&(1<7) && (info->castles[1]&(1<<(faction-8)))) - break; - faction = rand()%F_NUMBER; - } - } - int cid = CGI->townh->towns[faction].basicCreatures[obj->subID]; - for(int i=0;iobjh->cregens.size();i++) - if(CGI->objh->cregens[i]==cid) - return std::pair(17,i); - std::cout << "Cannot find a dwelling for creature "<(17,0); - } - case 218: - { - CCreGen3ObjInfo* info =(CCreGen3ObjInfo*)obj->info; - int level = ((info->maxLevel-info->minLevel) ? (rand()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel)); - int cid = CGI->townh->towns[obj->subID].basicCreatures[level]; - for(int i=0;iobjh->cregens.size();i++) - if(CGI->objh->cregens[i]==cid) - return std::pair(17,i); - std::cout << "Cannot find a dwelling for creature "<(17,0); - } - } - return std::pair(-1,-1); -} -void CMapHandler::randomizeObject(CGObjectInstance *cur) -{ - std::pair ran = pickObject(cur); - if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything - { - if(cur->ID==98) //town - set def - { - CGTownInstance *t = dynamic_cast(cur); - if(t->hasCapitol()) - t->defInfo = capitols[t->subID]; - else if(t->hasFort()) - t->defInfo = CGI->dobjinfo->castles[t->subID]; - else - t->defInfo = villages[t->subID]; - if(!t->defInfo->handler) - { - t->defInfo->handler = CDefHandler::giveDef(t->defInfo->name); - t->defInfo->width = t->defInfo->handler->ourImages[0].bitmap->w/32; - t->defInfo->height = t->defInfo->handler->ourImages[0].bitmap->h/32; - alphaTransformDef(t->defInfo); - } - } - return; - } - else if(ran.first==34)//special code for hero - { - CGHeroInstance *h = dynamic_cast(cur); - if(!h) {std::cout<<"Wrong random hero at "<pos<ID = ran.first; - cur->subID = ran.second; - h->type = CGI->heroh->heroes[ran.second]; - map->heroes.push_back(h); - map->objects.erase(std::find(map->objects.begin(),map->objects.end(),h)); - return; //TODO: maybe we should do something with definfo? - } - else if(ran.first==98)//special code for town - { - CGTownInstance *t = dynamic_cast(cur); - if(!t) {std::cout<<"Wrong random town at "<pos<ID = ran.first; - cur->subID = ran.second; - t->town = &CGI->townh->towns[ran.second]; - if(t->hasCapitol()) - t->defInfo = capitols[t->subID]; - else if(t->hasFort()) - t->defInfo = CGI->dobjinfo->castles[t->subID]; - else - t->defInfo = villages[t->subID]; - if(!t->defInfo->handler) - { - t->defInfo->handler = CDefHandler::giveDef(t->defInfo->name); - t->defInfo->width = t->defInfo->handler->ourImages[0].bitmap->w/32; - t->defInfo->height = t->defInfo->handler->ourImages[0].bitmap->h/32; - alphaTransformDef(t->defInfo); - } - //CGI->townh->townInstances.push_back(t); - return; - } - //we have to replace normal random object - cur->ID = ran.first; - cur->subID = ran.second; - cur->defInfo = CGI->dobjinfo->gobjs[ran.first][ran.second]; - if(!cur->defInfo){std::cout<<"Missing def declaration for "<ID<<" "<subID<defInfo->handler) //if we have to load def - { - cur->defInfo->handler = CDefHandler::giveDef(cur->defInfo->name); - cur->defInfo->width = cur->defInfo->handler->ourImages[0].bitmap->w/32; - cur->defInfo->height = cur->defInfo->handler->ourImages[0].bitmap->h/32; - alphaTransformDef(cur->defInfo); - } - -} -void CMapHandler::randomizeObjects() -{ - CGObjectInstance * cur; - for(int no=0; noobjects.size(); ++no) - { - randomizeObject(map->objects[no]); - if(map->objects[no]->ID==26) - map->objects[no]->defInfo->handler=NULL; - } -} void CMapHandler::prepareFOWDefs() { fullHide = CDefHandler::giveDef("TSHRC.DEF"); @@ -399,43 +145,35 @@ void CMapHandler::prepareFOWDefs() // visibility[gg][jj] = true; //} - visibility.resize(CGI->mh->map->width, Woff); - for (int i=0-Woff;imh->map->height,Hoff); - } - for (int i=0-Woff; imh->map->height+Hoff; ++j) - { - visibility[i][j].resize(CGI->mh->map->twoLevel+1,0); - for(int k=0; kmh->map->twoLevel+1; ++k) - visibility[i][j][k]=true; - } - } + //visibility.resize(CGI->mh->map->width, Woff); + //for (int i=0-Woff;imh->map->height,Hoff); + //} + //for (int i=0-Woff; imh->map->height+Hoff; ++j) + // { + // visibility[i][j].resize(CGI->mh->map->twoLevel+1,0); + // for(int k=0; kmh->map->twoLevel+1; ++k) + // visibility[i][j][k]=true; + // } + //} - hideBitmap.resize(CGI->mh->map->width, Woff); - for (int i=0-Woff;imh->map->width); + for (int i=0;imh->map->height,Hoff); + hideBitmap[i].resize(CGI->mh->map->height); } - for (int i=0-Woff; imh->map->height+Hoff; ++j) + for (int j=0; jmh->map->height; ++j) { - hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1,0); + hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1); for(int k=0; kmh->map->twoLevel+1; ++k) hideBitmap[i][j][k] = rand()%fullHide->ourImages.size(); } } - - //visibility[6][7][1] = false; - //visibility[7][7][1] = false; - //visibility[6][8][1] = false; - //visibility[6][6][1] = false; - //visibility[5][8][1] = false; - //visibility[7][6][1] = false; - //visibility[6][9][1] = false; } void CMapHandler::roadsRiverTerrainInit() @@ -464,9 +202,6 @@ void CMapHandler::roadsRiverTerrainInit() } } - //roadBitmaps = new SDL_Surface** [map->width+2*Woff]; - //for (int ii=0;iiwidth+2*Woff;ii++) - // roadBitmaps[ii] = new SDL_Surface*[map->height+2*Hoff]; // allocate memory sizes.x = CGI->mh->map->width; sizes.y = CGI->mh->map->height; sizes.z = CGI->mh->map->twoLevel+1; @@ -615,10 +350,6 @@ void CMapHandler::roadsRiverTerrainInit() } void CMapHandler::borderAndTerrainBitmapInit() { - //terrainBitmap = new SDL_Surface **[map->width+2*Woff]; - //for (int ii=0;iiwidth+2*Woff;ii++) - // terrainBitmap[ii] = new SDL_Surface*[map->height+2*Hoff]; // allocate memory - CDefHandler * bord = CDefHandler::giveDef("EDG.DEF"); bord->notFreeImgs = true; for (int i=0-Woff; iwidth+Woff; i++) //jest po szerokości @@ -807,73 +538,59 @@ void CMapHandler::calculateBlockedPos() } } } +void processDef (CGDefInfo* def) +{ + def->handler=CDefHandler::giveDef(def->name); + 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]; + if(pom) + { + pom->handler = def->handler; + pom->width = pom->handler->ourImages[0].bitmap->w/32; + pom->height = pom->handler->ourImages[0].bitmap->h/32; + } + else + std::cout << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl; + if(!def->handler->alphaTransformed) + { + for(int yy=0; yyhandler->ourImages.size(); ++yy) + { + def->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(def->handler->ourImages[yy].bitmap); + def->handler->alphaTransformed = true; + } + } +} void CMapHandler::init() { timeHandler th; th.getDif(); - - ///loading defs from lod - for (int ir=0;irdefy.size();ir++) - { - map->defy[ir]->handler=CDefHandler::giveDef(map->defy[ir]->name); - map->defy[ir]->width = map->defy[ir]->handler->ourImages[0].bitmap->w/32; - map->defy[ir]->height = map->defy[ir]->handler->ourImages[0].bitmap->h/32; - CGDefInfo* pom = CGI->dobjinfo->gobjs[map->defy[ir]->id][map->defy[ir]->subid]; - if(pom) - { - pom->handler=map->defy[ir]->handler; - pom->width = pom->handler->ourImages[0].bitmap->w/32; - pom->height = pom->handler->ourImages[0].bitmap->h/32; - } - else - std::cout << "Lacking def info for " << map->defy[ir]->id << " " << map->defy[ir]->subid <<" " << map->defy[ir]->name << std::endl; - } - for(int vv=0; vvdefy.size(); ++vv) - { - if(map->defy[vv]->handler->alphaTransformed) - continue; - for(int yy=0; yydefy[vv]->handler->ourImages.size(); ++yy) - { - map->defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map->defy[vv]->handler->ourImages[yy].bitmap); - map->defy[vv]->handler->alphaTransformed = true; - } - } + std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs + std::for_each(map->defs.begin(),map->defs.end(),processDef); //and non-h3m defs THC std::cout<<"\tUnpacking and handling defs: "<>ccc; - for(int i=0;idobjinfo->castles[i%ccc]); - ifs >> n->name; - if (!(n->handler = CDefHandler::giveDef(n->name))) - std::cout << "Cannot open "<name<width = n->handler->ourImages[0].bitmap->w/32; - n->height = n->handler->ourImages[0].bitmap->h/32; - } - if(i>ccc; + //for(int i=0;idobjinfo->castles[i%ccc]); + // ifs >> n->name; + // if (!(n->handler = CDefHandler::giveDef(n->name))) + // std::cout << "Cannot open "<name<width = n->handler->ourImages[0].bitmap->w/32; + // n->height = n->handler->ourImages[0].bitmap->h/32; + // } + // if(iscenarioOps.playerInfos.size();i++) - { - if(CGI->scenarioOps.playerInfos[i].castle==-1) - { - int f; - do - { - f = rand()%F_NUMBER; - }while(!(map->players[CGI->scenarioOps.playerInfos[i].color].allowedFactions & 1<scenarioOps.playerInfos[i].castle = f; - } - } for(int i=0;iplayers[i].heroesNames.size();j++) @@ -884,15 +601,9 @@ void CMapHandler::init() std::cout<<"\tLoading town defs, picking random factions and heroes: "<defy.size(); ++h) //initializing loaded def handler's info - { - //std::string hlp = map->defy[h]->name; - //std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper); + for(int h=0; hdefy.size(); ++h) //initializing loaded def handler's info { CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler)); - } std::cout<<"\tCollecting loaded def's handlers: "<players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE)) - { - int3 hpos = map->players[i].posOfMainTown; - hpos.x+=1;// hpos.y+=1; - int j; - for(j=0;jscenarioOps.playerInfos.size();j++) - if(CGI->scenarioOps.playerInfos[j].color==i) - break; - if(j==CGI->scenarioOps.playerInfos.size()) - continue; - int h; //= CGI->scenarioOps.playerInfos[j].hero; - //if(h<0) - h=pickHero(i); - CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i); - nnn->defInfo->handler = graphics->flags1[0]; - map->heroes.push_back(nnn); - map->objects.push_back(nnn); - } - } + //for(int i=0;iplayers[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE)) + // { + // int3 hpos = map->players[i].posOfMainTown; + // hpos.x+=1;// hpos.y+=1; + // int j; + // for(j=0;jstate->scenarioOps->playerInfos.size();j++) + // if(CGI->state->scenarioOps->playerInfos[j].color==i) + // break; + // if(j==CGI->state->scenarioOps->playerInfos.size()) + // continue; + // int h=pickHero(i); + // CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i); + // nnn->defInfo->handler = graphics->flags1[0]; + // map->heroes.push_back(nnn); + // map->objects.push_back(nnn); + // } + //} std::cout<<"\tGiving starting heroes: "< > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect) +SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect) { if(!otherHeroAnim) heroAnim = anim; //the same, as it should be @@ -1200,250 +909,261 @@ SDL_Surface * CMapHandler::undTerrBitmap(int x, int y) return ttiles[x+Woff][y+Hoff][0].terbitmap[1]; } -SDL_Surface * CMapHandler::getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV > > & visibilityMap, int lvl) +SDL_Surface * CMapHandler::getVisBitmap(int x, int y, std::vector< std::vector< std::vector > > & visibilityMap, int lvl) { - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + int size = visibilityMap.size()-1; //is tile visible. arrangement: (like num keyboard) + bool d7 = (x>0 && y>0) ? visibilityMap[x-1][y-1][lvl] : 0, //789 + d8 = (y>0) ? visibilityMap[x][y-1][lvl] : 0, //456 + d9 = (y>0 && x0) ? visibilityMap[x-1][y][lvl] : 0, + d5 = visibilityMap[x][y][lvl], + d6 = (x0 && yourImages[hideBitmap[x][y][lvl]].bitmap; //fully hidden } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && !d1) { return partialHide->ourImages[22].bitmap; //visible right bottom corner } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && !d4 && !d8 && !d7 && !d3 && d9 && !d1) { return partialHide->ourImages[15].bitmap; //visible right top corner } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && !d4 && !d8 && !d7 && !d3 && !d9 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[22].bitmap); //visible left bottom corner return partialHide->ourImages[34].bitmap; //visible left bottom corner } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && !d9 && !d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[15].bitmap); //visible left top corner return partialHide->ourImages[35].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && !d4 && d8 && d7 && !d3 && d9 && !d1) { //return partialHide->ourImages[rand()%2].bitmap; //visible top return partialHide->ourImages[0].bitmap; //visible top } - else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + else if(d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && d1) { //return partialHide->ourImages[4+rand()%2].bitmap; //visble bottom return partialHide->ourImages[4].bitmap; //visble bottom } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && d4 && !d8 && d7 && !d3 && !d9 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[2+rand()%2].bitmap); //visible left //return CSDL_Ext::rotate01(partialHide->ourImages[2].bitmap); //visible left return partialHide->ourImages[36].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && d6 && !d4 && !d8 && !d7 && d3 && d9 && !d1) { //return partialHide->ourImages[2+rand()%2].bitmap; //visible right return partialHide->ourImages[2].bitmap; //visible right } - else if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl]) + else if(d2 && d6 && !d4 && !d8 && !d7) { //return partialHide->ourImages[12+2*(rand()%2)].bitmap; //visible bottom, right - bottom, right; left top corner hidden return partialHide->ourImages[12].bitmap; //visible bottom, right - bottom, right; left top corner hidden } - else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && d6 && !d4 && d8 && !d1) { return partialHide->ourImages[13].bitmap; //visible right, right - top; left bottom corner hidden } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl]) + else if(!d2 && !d6 && d4 && d8 && !d3) { //return CSDL_Ext::rotate01(partialHide->ourImages[13].bitmap); //visible top, top - left, left; right bottom corner hidden return partialHide->ourImages[37].bitmap; } - else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y-1][lvl]) + else if(d2 && !d6 && d4 && !d8 && !d9) { //return CSDL_Ext::rotate01(partialHide->ourImages[12+2*(rand()%2)].bitmap); //visible left, left - bottom, bottom; right top corner hidden //return CSDL_Ext::rotate01(partialHide->ourImages[12].bitmap); //visible left, left - bottom, bottom; right top corner hidden return partialHide->ourImages[38].bitmap; } - else if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) + else if(d2 && d6 && d4 && d8) { return partialHide->ourImages[10].bitmap; //visible left, right, bottom and top } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && d9 && !d1) { return partialHide->ourImages[16].bitmap; //visible right corners } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && d9 && !d1) { return partialHide->ourImages[18].bitmap; //visible top corners } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && !d9 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[16].bitmap); //visible left corners return partialHide->ourImages[39].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && d1) { //return CSDL_Ext::hFlip(partialHide->ourImages[18].bitmap); //visible bottom corners return partialHide->ourImages[40].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && !d7 && !d3 && d9 && d1) { return partialHide->ourImages[17].bitmap; //visible right - top and bottom - left corners } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && !d9 && !d1) { //return CSDL_Ext::hFlip(partialHide->ourImages[17].bitmap); //visible top - left and bottom - right corners return partialHide->ourImages[41].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && d9 && d1) { return partialHide->ourImages[19].bitmap; //visible corners without left top } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && d9 && !d1) { return partialHide->ourImages[20].bitmap; //visible corners without left bottom } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && d9 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[20].bitmap); //visible corners without right bottom return partialHide->ourImages[42].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && !d9 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[19].bitmap); //visible corners without right top return partialHide->ourImages[43].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && d9 && d1) { return partialHide->ourImages[21].bitmap; //visible all corners only } - if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl]) + if(d2 && d6 && d4 && !d8) { return partialHide->ourImages[6].bitmap; //hidden top } - if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) + if(d2 && !d6 && d4 && d8) { return partialHide->ourImages[7].bitmap; //hidden right } - if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) + if(!d2 && d6 && d4 && d8) { return partialHide->ourImages[8].bitmap; //hidden bottom } - if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) + if(d2 && d6 && !d4 && d8) { //return CSDL_Ext::rotate01(partialHide->ourImages[7].bitmap); //hidden left return partialHide->ourImages[44].bitmap; } - if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl]) + if(!d2 && d6 && d4 && !d8) { return partialHide->ourImages[9].bitmap; //hidden top and bottom } - if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) + if(d2 && !d6 && !d4 && d8) { return partialHide->ourImages[29].bitmap; //hidden left and right } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && d8 && d3 && !d1) { return partialHide->ourImages[24].bitmap; //visible top and right bottom corner } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && d8 && !d3 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[24].bitmap); //visible top and left bottom corner return partialHide->ourImages[45].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && d8 && d3 && d1) { return partialHide->ourImages[33].bitmap; //visible top and bottom corners } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl]) + if(!d2 && !d6 && d4 && !d8 && !d3 && d9) { //return CSDL_Ext::rotate01(partialHide->ourImages[26].bitmap); //visible left and right top corner return partialHide->ourImages[46].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl]) + if(!d2 && !d6 && d4 && !d8 && d3 && !d9) { //return CSDL_Ext::rotate01(partialHide->ourImages[25].bitmap); //visible left and right bottom corner return partialHide->ourImages[47].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl]) + if(!d2 && !d6 && d4 && !d8 && d3 && d9) { return partialHide->ourImages[32].bitmap; //visible left and right corners } - if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y-1][lvl]) + if(d2 && !d6 && !d4 && !d8 && d7 && !d9) { //return CSDL_Ext::rotate01(partialHide->ourImages[30].bitmap); //visible bottom and left top corner return partialHide->ourImages[48].bitmap; } - if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y-1][lvl]) + if(d2 && !d6 && !d4 && !d8 && !d7 && d9) { return partialHide->ourImages[30].bitmap; //visible bottom and right top corner } - if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y-1][lvl]) + if(d2 && !d6 && !d4 && !d8 && d7 && d9) { return partialHide->ourImages[31].bitmap; //visible bottom and top corners } - if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && d6 && !d4 && !d8 && !d7 && d1) { return partialHide->ourImages[25].bitmap; //visible right and left bottom corner } - if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && d6 && !d4 && !d8 && d7 && !d1) { return partialHide->ourImages[26].bitmap; //visible right and left top corner } - if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && d6 && !d4 && !d8 && d7 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[32].bitmap); //visible right and left cornres return partialHide->ourImages[49].bitmap; } - if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl]) + if(d2 && d6 && !d4 && !d8 && d7) { return partialHide->ourImages[28].bitmap; //visible bottom, right - bottom, right; left top corner visible } - else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + else if(!d2 && d6 && !d4 && d8 && d1) { return partialHide->ourImages[27].bitmap; //visible right, right - top; left bottom corner visible } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl]) + else if(!d2 && !d6 && d4 && d8 && d3) { //return CSDL_Ext::rotate01(partialHide->ourImages[27].bitmap); //visible top, top - left, left; right bottom corner visible return partialHide->ourImages[50].bitmap; } - else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y-1][lvl]) + else if(d2 && !d6 && d4 && !d8 && d9) { //return CSDL_Ext::rotate01(partialHide->ourImages[28].bitmap); //visible left, left - bottom, bottom; right top corner visible return partialHide->ourImages[51].bitmap; } //newly added - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible t and tr + else if(!d2 && !d6 && !d4 && d8 && !d7 && !d3 && d9 && !d1) //visible t and tr { return partialHide->ourImages[0].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible t and tl + else if(!d2 && !d6 && !d4 && d8 && d7 && !d3 && !d9 && !d1) //visible t and tl { return partialHide->ourImages[1].bitmap; } - else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible b and br + else if(d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && !d1) //visible b and br { return partialHide->ourImages[4].bitmap; } - else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) //visible b and bl + else if(d2 && !d6 && !d4 && !d8 && !d7 && !d3 && !d9 && d1) //visible b and bl { return partialHide->ourImages[5].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible l and tl + else if(!d2 && !d6 && d4 && !d8 && d7 && !d3 && !d9 && !d1) //visible l and tl { return partialHide->ourImages[36].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) //visible l and bl + else if(!d2 && !d6 && d4 && !d8 && !d7 && !d3 && !d9 && d1) //visible l and bl { return partialHide->ourImages[36].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible r and tr + else if(!d2 && d6 && !d4 && !d8 && !d7 && !d3 && d9 && !d1) //visible r and tr { return partialHide->ourImages[2].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible r and br + else if(!d2 && d6 && !d4 && !d8 && !d7 && d3 && !d9 && !d1) //visible r and br { return partialHide->ourImages[3].bitmap; } diff --git a/mapHandler.h b/mapHandler.h index 013e9a700..6fb8145ff 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -41,6 +41,18 @@ template class PseudoV public: int offset; std::vector inver; + PseudoV(){}; + PseudoV(std::vector &src, int offset, const T& fill) + { + inver.resize(Offset*2+rest); + offset=Offset; + for(int i=0; i > > visibility; //true means that pointed place is visible //not used now + std::vector< std::vector< std::vector > > visibility; //true means that pointed place is visible //not used now //std::vector< std::vector > undVisibility; //true means that pointed place is visible std::vector roadDefs; std::vector staticRiverDefs; std::vector defs; std::map loadedDefs; //pointers to loaded defs (key is filename, uppercase) - std::map villages, forts, capitols; std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle - PseudoV< PseudoV< PseudoV > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile + std::vector > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile void loadDefs(); char & visAccess(int x, int y); char & undVisAccess(int x, int y); SDL_Surface mirrorImage(SDL_Surface *src); //what is this?? - SDL_Surface * getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV > > & visibilityMap, int lvl); + SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector< std::vector > > & visibilityMap, int lvl); int getCost(int3 & a, int3 & b, const CGHeroInstance * hero); std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position @@ -105,7 +116,7 @@ public: void prepareFOWDefs(); void randomizeObjects(); - SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, PseudoV< PseudoV< PseudoV > > & visibilityMap = CGI->mh->visibility, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it + SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector > > & visibilityMap = CGI->mh->visibility, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it SDL_Surface * terrBitmap(int x, int y); SDL_Surface * undTerrBitmap(int x, int y); std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns From b0002ff50b83f60dfa3171a4c780257134aaf97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Tue, 1 Jul 2008 08:01:02 +0000 Subject: [PATCH 18/47] * added files for future server * make code compiling * broken objects scripts --- AdventureMapButton.cpp | 6 +- CAdvmapInterface.cpp | 6 +- CBattleInterface.cpp | 8 +- CCallback.cpp | 6 +- CCursorHandler.cpp | 2 +- CGameState.cpp | 114 +++++++++++----------- CHeroWindow.cpp | 10 +- CMT.cpp | 39 ++++---- CMessage.cpp | 6 +- CPathfinder.cpp | 2 +- CPlayerInterface.cpp | 2 +- CPreGame.cpp | Bin 129722 -> 129722 bytes CPreGame.h | 4 +- CScreenHandler.cpp | 2 +- SDL_Extensions.cpp | 2 +- client/VCMI_client.vcproj | 4 - mapHandler.cpp | 8 +- mapHandler.h | 6 +- server/CGameHandler.cpp | 9 ++ server/CGameHandler.h | 8 ++ server/VCMI_server.vcproj | 192 ++++++++++++++++++++++++++++++++++++++ server/server_main.cpp | 81 ++++++++++++++++ 22 files changed, 403 insertions(+), 114 deletions(-) create mode 100644 server/CGameHandler.cpp create mode 100644 server/CGameHandler.h create mode 100644 server/VCMI_server.vcproj create mode 100644 server/server_main.cpp diff --git a/AdventureMapButton.cpp b/AdventureMapButton.cpp index 745e68046..da87fa196 100644 --- a/AdventureMapButton.cpp +++ b/AdventureMapButton.cpp @@ -1,9 +1,9 @@ #include "CAdvmapInterface.h" #include "SDL_Extensions.h" -#include "hch\CDefHandler.h" +#include "hch/CDefHandler.h" #include "CGameInfo.h" -#include "hch\CLodHandler.h" -#include "hch\CPreGameTextHandler.h" +#include "hch/CLodHandler.h" +#include "hch/CPreGameTextHandler.h" #include "hch/CTownHandler.h" #include "CLua.h" #include "CCallback.h" diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index e11e9db64..d6959f493 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -2,9 +2,9 @@ #include "CAdvmapInterface.h" #include "client/CBitmapHandler.h" #include "CPlayerInterface.h" -#include "hch\CPreGameTextHandler.h" -#include "hch\CGeneralTextHandler.h" -#include "hch\CTownHandler.h" +#include "hch/CPreGameTextHandler.h" +#include "hch/CGeneralTextHandler.h" +#include "hch/CTownHandler.h" #include "CPathfinder.h" #include "CGameInfo.h" #include "SDL_Extensions.h" diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index fba75b2b4..11506f6d9 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -1,14 +1,14 @@ #include "CBattleInterface.h" #include "CGameInfo.h" -#include "hch\CLodHandler.h" +#include "hch/CLodHandler.h" #include "SDL_Extensions.h" #include "CAdvmapInterface.h" #include "AdventureMapButton.h" -#include "hch\CHeroHandler.h" -#include "hch\CDefHandler.h" +#include "hch/CHeroHandler.h" +#include "hch/CDefHandler.h" #include "CCallback.h" #include "CGameState.h" -#include "hch\CGeneralTextHandler.h" +#include "hch/CGeneralTextHandler.h" #include "client/CCreatureAnimation.h" #include "client/Graphics.h" #include diff --git a/CCallback.cpp b/CCallback.cpp index 4a6213278..c833ddc3b 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -1,10 +1,10 @@ #include "stdafx.h" #include "CCallback.h" #include "CPathfinder.h" -#include "hch\CHeroHandler.h" -#include "hch\CTownHandler.h" +#include "hch/CHeroHandler.h" +#include "hch/CTownHandler.h" #include "CGameInfo.h" -#include "hch\CAmbarCendamo.h" +#include "hch/CAmbarCendamo.h" #include "mapHandler.h" #include "CGameState.h" #include "CPlayerInterface.h" diff --git a/CCursorHandler.cpp b/CCursorHandler.cpp index a46a2a4c4..53a39708b 100644 --- a/CCursorHandler.cpp +++ b/CCursorHandler.cpp @@ -4,7 +4,7 @@ #include "SDL_thread.h" #include "CGameInfo.h" #include "SDL_framerate.h" -#include "hch\CLodHandler.h" +#include "hch/CLodHandler.h" extern SDL_Surface * screen; diff --git a/CGameState.cpp b/CGameState.cpp index e50a069a3..7a44877b9 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -472,66 +472,66 @@ void CGameState::init(StartInfo * si, Mapa * map, int seed) } } - /****************************SCRIPTS************************************************/ - std::map > * skrypty = &objscr; //alias for easier access - /****************************C++ OBJECT SCRIPTS************************************************/ - std::map scripts; - CScriptCallback * csc = new CScriptCallback(); - csc->gs = this; - handleCPPObjS(&scripts,new CVisitableOPH(csc)); - handleCPPObjS(&scripts,new CVisitableOPW(csc)); - handleCPPObjS(&scripts,new CPickable(csc)); - handleCPPObjS(&scripts,new CMines(csc)); - handleCPPObjS(&scripts,new CTownScript(csc)); - handleCPPObjS(&scripts,new CHeroScript(csc)); - handleCPPObjS(&scripts,new CMonsterS(csc)); - handleCPPObjS(&scripts,new CCreatureGen(csc)); - //created map + ///****************************SCRIPTS************************************************/ + //std::map > * skrypty = &objscr; //alias for easier access + ///****************************C++ OBJECT SCRIPTS************************************************/ + //std::map scripts; + //CScriptCallback * csc = new CScriptCallback(); + //csc->gs = this; + //handleCPPObjS(&scripts,new CVisitableOPH(csc)); + //handleCPPObjS(&scripts,new CVisitableOPW(csc)); + //handleCPPObjS(&scripts,new CPickable(csc)); + //handleCPPObjS(&scripts,new CMines(csc)); + //handleCPPObjS(&scripts,new CTownScript(csc)); + //handleCPPObjS(&scripts,new CHeroScript(csc)); + //handleCPPObjS(&scripts,new CMonsterS(csc)); + //handleCPPObjS(&scripts,new CCreatureGen(csc)); + ////created map - /****************************LUA OBJECT SCRIPTS************************************************/ - std::vector * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files - for (int i=0; isize(); i++) - { - try - { - std::vector * temp = CLuaHandler::functionList((*lf)[i]); - CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]); - CLuaCallback::registerFuncs(objs->is); - //objs - for (int j=0; jsize(); j++) - { - int obid ; //obj ID - int dspos = (*temp)[j].find_first_of('_'); - obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str()); - std::string fname = (*temp)[j].substr(0,dspos); - if (skrypty->find(obid)==skrypty->end()) - skrypty->insert(std::pair >(obid,std::map())); - (*skrypty)[obid].insert(std::pair(fname,objs)); - } - delete temp; - }HANDLE_EXCEPTION - } - /****************************INITIALIZING OBJECT SCRIPTS************************************************/ - std::string temps("newObject"); - for (int i=0; iobjects.size(); i++) - { - //c++ scripts - if (scripts.find(map->objects[i]->ID) != scripts.end()) - { - map->objects[i]->state = scripts[map->objects[i]->ID]; - map->objects[i]->state->newObject(map->objects[i]); - } - else - { - map->objects[i]->state = NULL; - } + ///****************************LUA OBJECT SCRIPTS************************************************/ + //std::vector * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files + //for (int i=0; isize(); i++) + //{ + // try + // { + // std::vector * temp = CLuaHandler::functionList((*lf)[i]); + // CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]); + // CLuaCallback::registerFuncs(objs->is); + // //objs + // for (int j=0; jsize(); j++) + // { + // int obid ; //obj ID + // int dspos = (*temp)[j].find_first_of('_'); + // obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str()); + // std::string fname = (*temp)[j].substr(0,dspos); + // if (skrypty->find(obid)==skrypty->end()) + // skrypty->insert(std::pair >(obid,std::map())); + // (*skrypty)[obid].insert(std::pair(fname,objs)); + // } + // delete temp; + // }HANDLE_EXCEPTION + //} + ///****************************INITIALIZING OBJECT SCRIPTS************************************************/ + //std::string temps("newObject"); + //for (int i=0; iobjects.size(); i++) + //{ + // //c++ scripts + // if (scripts.find(map->objects[i]->ID) != scripts.end()) + // { + // map->objects[i]->state = scripts[map->objects[i]->ID]; + // map->objects[i]->state->newObject(map->objects[i]); + // } + // else + // { + // map->objects[i]->state = NULL; + // } - // lua scripts - if(checkFunc(map->objects[i]->ID,temps)) - (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); - } + // // lua scripts + // if(checkFunc(map->objects[i]->ID,temps)) + // (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); + //} - delete lf; + //delete lf; } void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2) {/* diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index e4a980691..4ed35f25e 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -2,18 +2,18 @@ #include "global.h" #include "CHeroWindow.h" #include "CGameInfo.h" -#include "hch\CHeroHandler.h" -#include "hch\CGeneralTextHandler.h" +#include "hch/CHeroHandler.h" +#include "hch/CGeneralTextHandler.h" #include "SDL.h" #include "SDL_Extensions.h" #include "CAdvmapInterface.h" -#include "hch\CLodHandler.h" +#include "hch/CLodHandler.h" #include "AdventureMapButton.h" -#include "hch\CObjectHandler.h" +#include "hch/CObjectHandler.h" #include "CMessage.h" #include "CCallback.h" #include "hch/CArtHandler.h" -#include "hch\CAbilityHandler.h" +#include "hch/CAbilityHandler.h" #include #include "client/Graphics.h" extern SDL_Surface * screen; diff --git a/CMT.cpp b/CMT.cpp index a2e91aa01..46fe471d4 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -3,9 +3,9 @@ #include "stdafx.h" #include "SDL.h" #include "SDL_TTF.h" -#include "hch\CVideoHandler.h" +#include "hch/CVideoHandler.h" #include "SDL_mixer.h" -#include "hch\CBuildingHandler.h" +#include "hch/CBuildingHandler.h" #include "SDL_Extensions.h" #include "SDL_framerate.h" #include @@ -13,24 +13,24 @@ #include #include "zlib.h" #include -#include "hch\CArtHandler.h" -#include "hch\CHeroHandler.h" -#include "hch\CCreatureHandler.h" -#include "hch\CAbilityHandler.h" -#include "hch\CSpellHandler.h" -#include "hch\CBuildingHandler.h" -#include "hch\CObjectHandler.h" +#include "hch/CArtHandler.h" +#include "hch/CHeroHandler.h" +#include "hch/CCreatureHandler.h" +#include "hch/CAbilityHandler.h" +#include "hch/CSpellHandler.h" +#include "hch/CBuildingHandler.h" +#include "hch/CObjectHandler.h" #include "CGameInfo.h" -#include "hch\CMusicHandler.h" -#include "hch\CLodHandler.h" -#include "hch\CDefHandler.h" -#include "hch\CTownHandler.h" -#include "hch\CDefObjInfoHandler.h" -#include "hch\CAmbarCendamo.h" +#include "hch/CMusicHandler.h" +#include "hch/CLodHandler.h" +#include "hch/CDefHandler.h" +#include "hch/CTownHandler.h" +#include "hch/CDefObjInfoHandler.h" +#include "hch/CAmbarCendamo.h" #include "mapHandler.h" #include "global.h" #include "CPreGame.h" -#include "hch\CGeneralTextHandler.h" +#include "hch/CGeneralTextHandler.h" #include "CConsoleHandler.h" #include "CCursorHandler.h" #include "CScreenHandler.h" @@ -41,8 +41,9 @@ #include "CLuaHandler.h" #include "CLua.h" #include "CAdvmapInterface.h" -#include "client\Graphics.h" +#include "client/Graphics.h" #include +#include std::string NAME = NAME_VER + std::string(" (client)"); DLL_EXPORT void initDLL(CLodHandler *b); using boost::asio::ip::tcp; @@ -59,7 +60,9 @@ void handleCPPObjS(std::map * mapa, CCPPObjectScript * sc CGI->state->cppscripts.insert(script); } int _tmain(int argc, _TCHAR* argv[]) -{ /* +{ + boost::thread servthr(boost::bind(system,"Debug\\VCMI_server.exe")); + /* boost::asio::io_service io_service; boost::system::error_code error = boost::asio::error::host_not_found; tcp::socket socket(io_service); diff --git a/CMessage.cpp b/CMessage.cpp index e226c60e4..82b5e43c2 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -1,14 +1,14 @@ #include "stdafx.h" #include "CMessage.h" #include "SDL_TTF.h" -#include "hch\CDefHandler.h" +#include "hch/CDefHandler.h" #include "CGameInfo.h" #include "SDL_Extensions.h" -#include "hch\CLodHandler.h" +#include "hch/CLodHandler.h" #include #include #include "CPlayerInterface.h" -#include "hch\CDefHandler.h" +#include "hch/CDefHandler.h" #include "CGameInfo.h" #include "SDL_Extensions.h" #include diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 4fca779c7..d59501bdc 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -2,7 +2,7 @@ #include "global.h" #include "CPathfinder.h" #include "CGameInfo.h" -#include "hch\CAmbarCendamo.h" +#include "hch/CAmbarCendamo.h" #include "mapHandler.h" #include "CGameState.h" diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 081930a09..8f88fceb4 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -22,7 +22,7 @@ #include "timeHandler.h" #include #include -#include "hch\CPreGameTextHandler.h" +#include "hch/CPreGameTextHandler.h" #include "CBattleInterface.h" #include "CLua.h" #include diff --git a/CPreGame.cpp b/CPreGame.cpp index 10ff9dfee6620ebc06011be0828e2620dbdab589..afad3fd17ee050570477b834108e49712dc97fa0 100644 GIT binary patch delta 38 scmdn>m3`M&_6`4-81*OrXW9=W_cL1q$=}SjjQY)%EZZ$v7#qI<06={Xx&QzG delta 38 scmdn>m3`M&_6`4-7-J^?XW9=W_cL1q$=}Sjj4{oYEZZ$v7#qI<08QBsZU6uP diff --git a/CPreGame.h b/CPreGame.h index 26c865edb..133bf6006 100644 --- a/CPreGame.h +++ b/CPreGame.h @@ -4,10 +4,10 @@ #include #include "SDL.h" #include "StartInfo.h" -#include "hch\CPreGameTextHandler.h" +#include "hch/CPreGameTextHandler.h" #include "CMessage.h" #include "map.h" -#include "hch\CMusicHandler.h" +#include "hch/CMusicHandler.h" class CPreGame; extern CPreGame * CPG; diff --git a/CScreenHandler.cpp b/CScreenHandler.cpp index eb26a8938..0a9c0c719 100644 --- a/CScreenHandler.cpp +++ b/CScreenHandler.cpp @@ -6,7 +6,7 @@ #include "SDL_Extensions.h" #include "CCursorHandler.h" #include "CGameInfo.h" -#include "hch\CDefHandler.h" +#include "hch/CDefHandler.h" extern SDL_Surface * screen, * screen2; diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 94558ca8e..a4ac056fc 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -7,7 +7,7 @@ #include #include "CMessage.h" #include -#include "hch\CDefHandler.h" +#include "hch/CDefHandler.h" #include #include "client\Graphics.h" diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index a5ee95d9b..86a03d6fa 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -603,10 +603,6 @@ RelativePath="..\CHeroWindow.h" > - - diff --git a/mapHandler.cpp b/mapHandler.cpp index fb8a40ca5..383128ac0 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -3,13 +3,13 @@ #include "SDL_Extensions.h" #include "CGameInfo.h" #include -#include "hch\CLodHandler.h" -#include "hch\CDefObjInfoHandler.h" +#include "hch/CLodHandler.h" +#include "hch/CDefObjInfoHandler.h" #include #include "CGameState.h" #include "CLua.h" -#include "hch\CHeroHandler.h" -#include "hch\CTownHandler.h" +#include "hch/CHeroHandler.h" +#include "hch/CTownHandler.h" #include "client\Graphics.h" #include #include diff --git a/mapHandler.h b/mapHandler.h index 6fb8145ff..97378e513 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -1,11 +1,11 @@ #ifndef MAPHANDLER_H #define MAPHANDLER_H -#include "hch\CAmbarCendamo.h" +#include "hch/CAmbarCendamo.h" #include "CGameInfo.h" -#include "hch\CDefHandler.h" +#include "hch/CDefHandler.h" #include -#include "hch\CObjectHandler.h" +#include "hch/CObjectHandler.h" #include const int Woff = 12; //width of map's frame const int Hoff = 8; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp new file mode 100644 index 000000000..a8c49efc0 --- /dev/null +++ b/server/CGameHandler.cpp @@ -0,0 +1,9 @@ +#include "CGameHandler.h" + +CGameHandler::CGameHandler(void) +{ +} + +CGameHandler::~CGameHandler(void) +{ +} diff --git a/server/CGameHandler.h b/server/CGameHandler.h new file mode 100644 index 000000000..5d4cdde7e --- /dev/null +++ b/server/CGameHandler.h @@ -0,0 +1,8 @@ +#pragma once + +class CGameHandler +{ +public: + CGameHandler(void); + ~CGameHandler(void); +}; diff --git a/server/VCMI_server.vcproj b/server/VCMI_server.vcproj new file mode 100644 index 000000000..03c722b93 --- /dev/null +++ b/server/VCMI_server.vcproj @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/server_main.cpp b/server/server_main.cpp new file mode 100644 index 000000000..4157a6bb5 --- /dev/null +++ b/server/server_main.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include "../global.h" +std::string NAME = NAME_VER + std::string(" (server)"); +//using boost::asio::ip::tcp; +//using namespace boost; +//using namespace boost::asio; +// +//class CConnection +//{ +//public: +// int ID; +// tcp::socket socket; +// void witaj() +// { +// char message[50]; strcpy_s(message,50,NAME.c_str());message[NAME.size()]='\n'; +// write(socket,buffer("Aiya!\n")); +// write(socket,buffer(message,NAME.size()+1)); +// } +// CConnection(io_service& io_service, int id=-1) +// : socket(io_service), ID(id) +// { +// } +//}; +// +//class CVCMIServer +//{ +// tcp::acceptor acceptor; +// std::vector connections; +//public: +// CVCMIServer(io_service& io_service) +// : acceptor(io_service, tcp::endpoint(tcp::v4(), 3030)) +// { +// start_accept(); +// } +// +//private: +// void start_accept() +// { +// std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl; +// CConnection * new_connection = new CConnection(acceptor.io_service()); +// acceptor.accept(new_connection->socket); +// new_connection->witaj(); +// acceptor.async_accept(new_connection->socket, +// boost::bind(&CVCMIServer::gotConnection, this, new_connection, +// placeholders::error)); +// } +// +// void gotConnection(CConnection * connection,const system::error_code& error) +// { +// if (!error) +// { +// std::cout<<"Got connection!" << std::endl; +// connection->witaj(); +// start_accept(); +// } +// else +// { +// std::cout<<"Got connection but there is an error " << std::endl; +// } +// } +// +//}; +// +int main() +{ +// try +// { +// io_service io_service; +// CVCMIServer server(io_service); +// io_service.run(); +// } +// catch (std::exception& e) +// { +// std::cerr << e.what() << std::endl; +// } +// + return 0; +} \ No newline at end of file From 1b73678b7cc9232a9450380ef863481943713ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Wed, 2 Jul 2008 08:39:56 +0000 Subject: [PATCH 19/47] Fighting with includes. --- CAdvmapInterface.cpp | 4 +- CBattleInterface.cpp | 33 ++++----- CCallback.cpp | 9 +-- CCallback.h | 21 +++--- CCastleInterface.cpp | 1 + CConsoleHandler.cpp | 18 ++--- CGameInfo.h | 4 +- CGameState.h | 2 +- CHeroWindow.cpp | 2 + CLua.cpp | 2 + CMT.cpp | 2 +- CPathfinder.cpp | 1 + CPlayerInterface.cpp | 3 + client/Graphics.cpp | 26 +++++++ client/Graphics.h | 7 +- mapHandler.cpp | 32 ++------- mapHandler.h | 17 ++--- server/VCMI_server.vcproj | 2 +- server/server_main.cpp | 143 +++++++++++++++++++------------------- 19 files changed, 175 insertions(+), 154 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index d6959f493..baba2a7c5 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -20,6 +20,8 @@ #include "AdventureMapButton.h" #include "CHeroWindow.h" #include "client/Graphics.h" +#include "hch/CObjectHandler.h" +#include "map.h" #pragma warning (disable : 4355) extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts @@ -558,7 +560,7 @@ void CTerrainRect::show() SDL_Surface * teren = CGI->mh->terrainRect (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y, tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim, - LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim, + &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim, screen,&genRect(547,594,7,6) ); //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6)); diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 11506f6d9..78db60923 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -4,6 +4,7 @@ #include "SDL_Extensions.h" #include "CAdvmapInterface.h" #include "AdventureMapButton.h" +#include "hch/CObjectHandler.h" #include "hch/CHeroHandler.h" #include "hch/CDefHandler.h" #include "CCallback.h" @@ -35,7 +36,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner; } //preparing menu background and terrain - std::vector< std::string > & backref = CGI->mh->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; + std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] ); menu = BitmapHandler::loadBitmap("CBAR.BMP"); graphics->blueToPlayersAdv(menu, hero1->tempOwner); @@ -81,7 +82,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C //loading hero animations if(hero1) // attacking hero { - attackingHero = new CBattleHero(CGI->mh->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner); + attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner); attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0); } else @@ -90,7 +91,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C } if(hero2) // defending hero { - defendingHero = new CBattleHero(CGI->mh->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner); + defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner); defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0); } else @@ -323,7 +324,7 @@ bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick) } creDir[number] = !creDir[number]; - CStack curs = LOCPLINT->cb->battleGetStackByID(number); + CStack curs = *LOCPLINT->cb->battleGetStackByID(number); std::pair coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature); creAnims[number]->pos.x = coords.first; //creAnims[number]->pos.y = coords.second; @@ -504,7 +505,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo CSDL_Ext::update(); SDL_framerateDelay(LOCPLINT->mainFPSmng); } - if( (LOCPLINT->cb->battleGetStackByID(number).owner == attackingHeroInstance->tempOwner ) != creDir[number]) + if( (LOCPLINT->cb->battleGetStackByID(number)->owner == attackingHeroInstance->tempOwner ) != creDir[number]) { reverseCreature(number, curStackPos, true); } @@ -585,7 +586,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo } creAnims[number]->setType(2); //resetting to default - CStack curs = LOCPLINT->cb->battleGetStackByID(number); + CStack curs = *LOCPLINT->cb->battleGetStackByID(number); if(endMoving) //resetting to default { if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner)) @@ -614,7 +615,7 @@ void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby) void CBattleInterface::stackAttacking(int ID, int dest) { - CStack aStack = LOCPLINT->cb->battleGetStackByID(ID); //attacking stack + CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack if(aStack.creature->isDoubleWide()) { switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction @@ -733,7 +734,7 @@ void CBattleInterface::hexLclicked(int whichOne) ba->stackNumber = activeStack; givenCommand = ba; } - else if(LOCPLINT->cb->battleGetStackByID(atCre).owner != attackingHeroInstance->tempOwner) //attacking + else if(LOCPLINT->cb->battleGetStackByID(atCre)->owner != attackingHeroInstance->tempOwner) //attacking { BattleAction * ba = new BattleAction(); //to be deleted by engine ba->actionType = 6; @@ -760,7 +761,7 @@ void CBattleInterface::attackingShowHelper() { if(attackingInfo->frame == 0) { - CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack + CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack if(aStack.creature->isDoubleWide()) { switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction @@ -813,7 +814,7 @@ void CBattleInterface::attackingShowHelper() else if(attackingInfo->frame == (attackingInfo->maxframe - 1)) { attackingInfo->reversing = true; - CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack + CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack if(aStack.creature->isDoubleWide()) { switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction @@ -871,8 +872,8 @@ void CBattleInterface::attackingShowHelper() void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby) { char tabh[200]; - CStack attacker = LOCPLINT->cb->battleGetStackByID(IDby); - CStack defender = LOCPLINT->cb->battleGetStackByID(ID); + CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby); + CStack defender = *LOCPLINT->cb->battleGetStackByID(ID); int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(), (attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()), dmg); @@ -1054,11 +1055,11 @@ void CBattleHex::mouseMoved(SDL_MouseMotionEvent &sEvent) if(hovered && strictHovered) //print attacked creature to console { if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 && - LOCPLINT->cb->battleGetStackByPos(myNumber).owner != LOCPLINT->playerID && - LOCPLINT->cb->battleGetStackByPos(myNumber).alive) + LOCPLINT->cb->battleGetStackByPos(myNumber)->owner != LOCPLINT->playerID && + LOCPLINT->cb->battleGetStackByPos(myNumber)->alive) { char tabh[160]; - CStack attackedStack = LOCPLINT->cb->battleGetStackByPos(myNumber); + CStack attackedStack = *LOCPLINT->cb->battleGetStackByPos(myNumber); std::string attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl; sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); myInterface->console->alterTxt = std::string(tabh); @@ -1085,7 +1086,7 @@ void CBattleHex::clickRight(boost::logic::tribool down) int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile if(hovered && strictHovered && stID!=-1) { - CStack myst = LOCPLINT->cb->battleGetStackByID(stID); //stack info + CStack myst = *LOCPLINT->cb->battleGetStackByID(stID); //stack info StackState *pom = NULL; if(down) { diff --git a/CCallback.cpp b/CCallback.cpp index c833ddc3b..72c4767d7 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -13,6 +13,7 @@ #include "CAdvmapInterface.h" #include "CPlayerInterface.h" #include "hch/CBuildingHandler.h" +#include "hch/CObjectHandler.h" LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); int CCallback::lowestSpeed(CGHeroInstance * chi) @@ -783,17 +784,17 @@ int CCallback::battleGetStack(int pos) return -1; } -CStack CCallback::battleGetStackByID(int ID) +CStack* CCallback::battleGetStackByID(int ID) { for(int g=0; gstate->curB->stacks.size(); ++g) { if(CGI->state->curB->stacks[g]->ID == ID) - return *(CGI->state->curB->stacks[g]); + return CGI->state->curB->stacks[g]; } - return CStack(); + return NULL; } -CStack CCallback::battleGetStackByPos(int pos) +CStack* CCallback::battleGetStackByPos(int pos) { return battleGetStackByID(battleGetStack(pos)); } diff --git a/CCallback.h b/CCallback.h index be5f7ac6d..215039f6d 100644 --- a/CCallback.h +++ b/CCallback.h @@ -1,19 +1,22 @@ #ifndef CCALLBACK_H #define CCALLBACK_H -#include "mapHandler.h" +#include "global.h" #include "tchar.h" -#include "CGameState.h" - +#include +class CGHeroInstance; class CGameState; struct CPath; class CGObjectInstance; +class CArmedInstance; class SComponent; class IChosen; class CSelectableComponent; struct BattleAction; -typedef struct lua_State lua_State; - +class CGTownInstance; +struct StartInfo; +class CStack; +struct lua_State; //structure gathering info about upgrade possibilites struct UpgradeInfo { @@ -60,8 +63,8 @@ public: virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile - virtual CStack battleGetStackByID(int ID)=0; //returns stack info by given ID - virtual CStack battleGetStackByPos(int pos)=0; //returns stack info by given pos + virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID + virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack //virtual int battleMakeAction(BattleAction* action)=0;//perform action with an active stack (or custom action) virtual std::map battleGetStacks()=0; //returns stacks on battlefield @@ -133,8 +136,8 @@ public: int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship int battleGetObstaclesAtTile(int tile); //returns bitfield int battleGetStack(int pos); //returns ID of stack on the tile - CStack battleGetStackByID(int ID); //returns stack info by given ID - CStack battleGetStackByPos(int pos); //returns stack info by given pos + CStack * battleGetStackByID(int ID); //returns stack info by given ID + CStack * battleGetStackByPos(int pos); //returns stack info by given pos int battleGetPos(int stack); //returns position (tile ID) of stack //int battleMakeAction(BattleAction* action);//perform action with an active stack (or custom action) std::map battleGetStacks(); //returns stacks on battlefield diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index 3478adc20..f404293fc 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -8,6 +8,7 @@ #include "hch/CTownHandler.h" #include "AdventureMapButton.h" #include "hch/CBuildingHandler.h" +#include "hch/CDefHandler.h" #include #include "CMessage.h" #include "hch/CGeneralTextHandler.h" diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index 14292e4be..6093e7961 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -91,15 +91,15 @@ int internalFunc(void * callback) // readed>>heronum; // std::cout<<"Position of hero "<heroh->heroInstances[heronum]->getPosition(false)<>heronum>>dest; - const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0); - p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero); - cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0); - //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]); - break; - } + //case 'M': //move heroa + // { + // readed>>heronum>>dest; + // const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0); + // p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero); + // cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0); + // //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]); + // break; + // } case 'D': //pos description readed>>src; CGI->mh->getObjDescriptions(src); diff --git a/CGameInfo.h b/CGameInfo.h index d8bd87704..412e47c8b 100644 --- a/CGameInfo.h +++ b/CGameInfo.h @@ -1,8 +1,6 @@ #ifndef CGAMEINFO_H #define CGAMEINFO_H - -#include "StartInfo.h" -#include "SDL.h" +#include "global.h" #include diff --git a/CGameState.h b/CGameState.h index b1e6457a5..14f5dd982 100644 --- a/CGameState.h +++ b/CGameState.h @@ -105,7 +105,7 @@ public: friend void initGameState(Mapa * map, CGameInfo * cgi); friend CScriptCallback; friend void handleCPPObjS(std::map * mapa, CCPPObjectScript * script); - friend CMapHandler; + friend class CMapHandler; }; #endif //CGAMESTATE_H diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 4ed35f25e..c2c672a3a 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -14,6 +14,8 @@ #include "CCallback.h" #include "hch/CArtHandler.h" #include "hch/CAbilityHandler.h" +#include "hch/CDefHandler.h" +#include "client/CBitmapHandler.h" #include #include "client/Graphics.h" extern SDL_Surface * screen; diff --git a/CLua.cpp b/CLua.cpp index 9092487e7..7fb5210b2 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -21,6 +21,8 @@ #include #include #include "hch/CDefObjInfoHandler.h" +#include "map.h" +#include "maphandler.h" #pragma warning (disable : 4311) bool getGlobalFunc(lua_State * L, std::string fname) { diff --git a/CMT.cpp b/CMT.cpp index 46fe471d4..475f09b6a 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -61,7 +61,7 @@ void handleCPPObjS(std::map * mapa, CCPPObjectScript * sc } int _tmain(int argc, _TCHAR* argv[]) { - boost::thread servthr(boost::bind(system,"Debug\\VCMI_server.exe")); + boost::thread servthr(boost::bind(system,"VCMI_server.exe")); /* boost::asio::io_service io_service; boost::system::error_code error = boost::asio::error::host_not_found; diff --git a/CPathfinder.cpp b/CPathfinder.cpp index d59501bdc..70a7e8727 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -5,6 +5,7 @@ #include "hch/CAmbarCendamo.h" #include "mapHandler.h" #include "CGameState.h" +#include "hch/CObjectHandler.h" using namespace std; diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 8f88fceb4..c94cb6ab7 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -23,11 +23,14 @@ #include #include #include "hch/CPreGameTextHandler.h" +#include "hch/CObjectHandler.h" #include "CBattleInterface.h" +#include "CGameInfo.h" #include "CLua.h" #include #include "client/CCreatureAnimation.h" #include "client/Graphics.h" +#include "map.h" using namespace CSDL_Ext; extern TTF_Font * GEOR16; diff --git a/client/Graphics.cpp b/client/Graphics.cpp index db65b451b..353f3c158 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -111,6 +111,31 @@ void Graphics::loadPaletteAndColors() playerColors[i].unused = 0; } neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84;//gray +} +void Graphics::initializeBattleGraphics() +{ + std::ifstream bback("config/battleBack.txt"); + battleBacks.resize(9); + for(int i=0; i<9; ++i) //9 - number of terrains battle can be fought on + { + int am; + bback>>am; + battleBacks[i].resize(am); + for(int f=0; f>battleBacks[i][f]; + } + } + + //initializing battle hero animation + std::ifstream bher("config/battleHeroes.txt"); + int numberofh; + bher>>numberofh; + battleHeroes.resize(numberofh); + for(int i=0; i>battleHeroes[i]; + } } Graphics::Graphics() { @@ -128,6 +153,7 @@ Graphics::Graphics() tasks += boost::bind(&Graphics::loadPaletteAndColors,this); tasks += boost::bind(&Graphics::loadHeroFlags,this); tasks += boost::bind(&Graphics::loadHeroPortraits,this); + tasks += boost::bind(&Graphics::initializeBattleGraphics,this); tasks += GET_SURFACE(hInfo,"HEROQVBK.bmp"); tasks += GET_SURFACE(tInfo,"TOWNQVBK.bmp"); tasks += GET_DEF(artDefs,"ARTIFACT.DEF"); diff --git a/client/Graphics.h b/client/Graphics.h index 5dd17272f..007f55ee1 100644 --- a/client/Graphics.h +++ b/client/Graphics.h @@ -32,9 +32,12 @@ public: std::map smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border std::map bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border std::map backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral - + //for battles + std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type + std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle //functions - Graphics(); + Graphics(); + void initializeBattleGraphics(); void loadPaletteAndColors(); void loadHeroFlags(); void loadHeroFlags(std::pair Graphics::*, std::vector > &pr, bool mode); diff --git a/mapHandler.cpp b/mapHandler.cpp index 383128ac0..e04d89f6d 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -13,6 +13,8 @@ #include "client\Graphics.h" #include #include +#include "hch/CObjectHandler.h" +#include "map.h" extern SDL_Surface * screen; std::string nameFromType (EterrainType typ) { @@ -637,33 +639,9 @@ void CMapHandler::init() std::cout<<"\tMaking object rects: "<>am; - battleBacks[i].resize(am); - for(int f=0; f>battleBacks[i][f]; - } - } - - //initializing battle hero animation - std::ifstream bher("config/battleHeroes.txt"); - int numberofh; - bher>>numberofh; - battleHeroes.resize(numberofh); - for(int i=0; i>battleHeroes[i]; - } } -SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect) +SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect) { if(!otherHeroAnim) heroAnim = anim; //the same, as it should be @@ -831,9 +809,9 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, sr.h=sr.w=32; validateRectTerr(&sr, extRect); - if(bx+x>=0 && by+y>=0 && bx+xmh->map->width && by+ymh->map->height && !visibilityMap[bx+x][by+y][level]) + if(bx+x>=0 && by+y>=0 && bx+xmh->map->width && by+ymh->map->height && !(*visibilityMap)[bx+x][by+y][level]) { - SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibilityMap, level); + SDL_Surface * hide = getVisBitmap(bx+x, by+y, *visibilityMap, level); CSDL_Ext::blit8bppAlphaTo24bpp(hide, &genRect(sr.h, sr.w, 0, 0), su, &sr); } } diff --git a/mapHandler.h b/mapHandler.h index 97378e513..ccb68d1a3 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -1,15 +1,19 @@ #ifndef MAPHANDLER_H #define MAPHANDLER_H - -#include "hch/CAmbarCendamo.h" -#include "CGameInfo.h" +#include "global.h" +#include #include "hch/CDefHandler.h" #include -#include "hch/CObjectHandler.h" #include +#include const int Woff = 12; //width of map's frame const int Hoff = 8; +class CGObjectInstance; +class CGHeroInstance; +struct Mapa; +class CGDefInfo; + struct TerrainTile2 { int3 pos; //this tile's position @@ -84,15 +88,12 @@ public: std::vector defs; std::map loadedDefs; //pointers to loaded defs (key is filename, uppercase) - std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type - std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle std::vector > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile void loadDefs(); char & visAccess(int x, int y); char & undVisAccess(int x, int y); - SDL_Surface mirrorImage(SDL_Surface *src); //what is this?? SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector< std::vector > > & visibilityMap, int lvl); int getCost(int3 & a, int3 & b, const CGHeroInstance * hero); @@ -116,7 +117,7 @@ public: void prepareFOWDefs(); void randomizeObjects(); - SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector > > & visibilityMap = CGI->mh->visibility, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it + SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector > > * visibilityMap = NULL, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it SDL_Surface * terrBitmap(int x, int y); SDL_Surface * undTerrBitmap(int x, int y); std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns diff --git a/server/VCMI_server.vcproj b/server/VCMI_server.vcproj index 03c722b93..0303b1bc8 100644 --- a/server/VCMI_server.vcproj +++ b/server/VCMI_server.vcproj @@ -17,7 +17,7 @@ #include "../global.h" std::string NAME = NAME_VER + std::string(" (server)"); -//using boost::asio::ip::tcp; -//using namespace boost; -//using namespace boost::asio; -// -//class CConnection -//{ -//public: -// int ID; -// tcp::socket socket; -// void witaj() -// { -// char message[50]; strcpy_s(message,50,NAME.c_str());message[NAME.size()]='\n'; -// write(socket,buffer("Aiya!\n")); -// write(socket,buffer(message,NAME.size()+1)); -// } -// CConnection(io_service& io_service, int id=-1) -// : socket(io_service), ID(id) -// { -// } -//}; -// -//class CVCMIServer -//{ -// tcp::acceptor acceptor; -// std::vector connections; -//public: -// CVCMIServer(io_service& io_service) -// : acceptor(io_service, tcp::endpoint(tcp::v4(), 3030)) -// { -// start_accept(); -// } -// -//private: -// void start_accept() -// { -// std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl; -// CConnection * new_connection = new CConnection(acceptor.io_service()); -// acceptor.accept(new_connection->socket); -// new_connection->witaj(); -// acceptor.async_accept(new_connection->socket, -// boost::bind(&CVCMIServer::gotConnection, this, new_connection, -// placeholders::error)); -// } -// -// void gotConnection(CConnection * connection,const system::error_code& error) -// { -// if (!error) -// { -// std::cout<<"Got connection!" << std::endl; -// connection->witaj(); -// start_accept(); -// } -// else -// { -// std::cout<<"Got connection but there is an error " << std::endl; -// } -// } -// -//}; -// +using boost::asio::ip::tcp; +using namespace boost; +using namespace boost::asio; + +class CConnection +{ +public: + int ID; + tcp::socket socket; + void witaj() + { + char message[50]; strcpy(message,NAME.c_str());message[NAME.size()]='\n'; + write(socket,buffer("Aiya!\n")); + write(socket,buffer(message,NAME.size()+1)); + } + CConnection(io_service& io_service, int id=-1) + : socket(io_service), ID(id) + { + } +}; + +class CVCMIServer +{ + tcp::acceptor acceptor; + std::vector connections; +public: + CVCMIServer(io_service& io_service) + : acceptor(io_service, tcp::endpoint(tcp::v4(), 3030)) + { + start_accept(); + } +private: + void start_accept() + { + std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl; + CConnection * new_connection = new CConnection(acceptor.io_service()); + acceptor.accept(new_connection->socket); + new_connection->witaj(); + acceptor.async_accept(new_connection->socket, + boost::bind(&CVCMIServer::gotConnection, this, new_connection, + placeholders::error)); + } + + void gotConnection(CConnection * connection,const boost::system::error_code& error) + { + if (!error) + { + std::cout<<"Got connection!" << std::endl; + connection->witaj(); + start_accept(); + } + else + { + std::cout<<"Got connection but there is an error " << std::endl; + } + } + +}; + int main() { -// try -// { -// io_service io_service; -// CVCMIServer server(io_service); -// io_service.run(); -// } -// catch (std::exception& e) -// { -// std::cerr << e.what() << std::endl; -// } -// + try + { + io_service io_service; + CVCMIServer server(io_service); + io_service.run(); + } + catch (std::exception& e) + { + std::cerr << e.what() << std::endl; + } + return 0; -} \ No newline at end of file +} From 9422b0d9ca9a333f3f7a0541767a5deb5e99edfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 3 Jul 2008 15:03:32 +0000 Subject: [PATCH 20/47] Experimantal parts of netcode --- CAdvmapInterface.cpp | 1 - CMT.cpp | 32 ++++----------- CPlayerInterface.cpp | 1 - client/VCMI_client.vcproj | 2 +- global.h | 17 ++------ lib/Connection.cpp | 72 +++++++++++++++++++++++++++++++++ lib/Connection.h | 84 +++++++++++++++++++++++++++++++++++++++ lib/VCMI_lib.vcproj | 10 ++++- server/VCMI_server.vcproj | 4 ++ server/server_main.cpp | 45 ++++++++------------- 10 files changed, 196 insertions(+), 72 deletions(-) create mode 100644 lib/Connection.cpp create mode 100644 lib/Connection.h diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index baba2a7c5..4e708bd3b 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -262,7 +262,6 @@ void CTerrainRect::deactivate() }; void CTerrainRect::clickLeft(tribool down) { - LOGE("Left mouse button down2"); if ((down==false) || indeterminate(down)) return; if (LOCPLINT->adventureInt->selection.type != HEROI_TYPE) diff --git a/CMT.cpp b/CMT.cpp index 475f09b6a..db4b48dd8 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -42,11 +42,10 @@ #include "CLua.h" #include "CAdvmapInterface.h" #include "client/Graphics.h" -#include #include +#include "lib/Connection.h" std::string NAME = NAME_VER + std::string(" (client)"); DLL_EXPORT void initDLL(CLodHandler *b); -using boost::asio::ip::tcp; SDL_Surface * screen, * screen2; extern SDL_Surface * CSDL_Ext::std32bppSurface; TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; @@ -61,30 +60,13 @@ void handleCPPObjS(std::map * mapa, CCPPObjectScript * sc } int _tmain(int argc, _TCHAR* argv[]) { - boost::thread servthr(boost::bind(system,"VCMI_server.exe")); - /* - boost::asio::io_service io_service; - boost::system::error_code error = boost::asio::error::host_not_found; - tcp::socket socket(io_service); - tcp::resolver resolver(io_service); - tcp::resolver::query query("127.0.0.1", "3030"); - tcp::resolver::iterator endpoint_iterator = resolver.resolve(tcp::resolver::query("127.0.0.1", "3030")); - socket.connect(*endpoint_iterator, error); - - boost::array buf; - - size_t len = socket.read_some(boost::asio::buffer(buf), error); - - if (error == boost::asio::error::eof) - ; // Connection closed cleanly by peer. - else if (error) - throw boost::system::system_error(error); // Some other error. - - std::cout.write(buf.data(), len); - len = socket.read_some(boost::asio::buffer(buf), error); - std::cout.write(buf.data(), len);*/ - + //boost::thread servthr(boost::bind(system,"VCMI_server.exe")); //runs server executable; + //TODO: add versions for other platforms + CConnection c("localhost","3030",NAME,std::cout); + int r; + c >> r; + std::cout << NAME << std::endl; srand ( time(NULL) ); CPG=NULL; atexit(SDL_Quit); diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index c94cb6ab7..1141aa50c 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -1756,7 +1756,6 @@ void CPlayerInterface::handleEvent(SDL_Event *sEvent) else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT)) { - LOGE("Left mouse button down1"); for(int i=0; ipos,sEvent->motion.x,sEvent->motion.y)) diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index 86a03d6fa..cbeb50a17 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -17,7 +17,7 @@ #include "int3.h" #define THC -#else -#define THC // #endif + +#define NAME_VER ("VCMI \"Altanatse\" 0.7") + enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors enum EterrainType {border=-1, dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock}; enum Eriver {noRiver=0, clearRiver, icyRiver, muddyRiver, lavaRiver}; @@ -31,18 +32,6 @@ extern CGameInfo* CGI; #define HEROI_TYPE (0) #define TOWNI_TYPE (1) -//#define LOGUJ - -#ifdef LOGUJ -#define LOG(x) std::cout< +using namespace boost; +using namespace boost::asio::ip; + +#define LOG(a) \ + if(logging)\ + out << a +#if defined(__hppa__) || \ + defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ + (defined(__MIPS__) && defined(__MISPEB__)) || \ + defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \ + defined(__sparc__) +#define BIG_ENDIAN +#else +#define LIL_ENDIAN +#endif + + +CConnection::CConnection(std::string host, std::string port, std::string Name, std::ostream & Out) +:io_service(new asio::io_service), name(Name), out(Out) +{ +#ifdef LIL_ENDIAN + myEndianess = true; +#else + myEndianess = false; +#endif + 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)); + socket->connect(*endpoint_iterator, error); + if(error) + { + connected = false; + return; + } + std::string pom; + //we got connection + (*this) << std::string("Aiya!\n") << name << myEndianess; //identify ourselves + (*this) >> pom >> pom >> contactEndianess; +} +CConnection::CConnection( + boost::asio::basic_stream_socket > * Socket, + boost::asio::io_service *Io_service, + std::string Name, + std::ostream & Out ) +:socket(Socket),io_service(Io_service), out(Out), name(Name) +{ + std::string pom; + //we start with just connected socket + (*this) << std::string("Aiya!\n") << name << myEndianess; //identify ourselves + (*this) >> pom >> pom >> contactEndianess; +} +int CConnection::write(const void * data, unsigned size) +{ + LOG("wysylam dane o rozmiarze " << size << std::endl); + int ret; + ret = asio::write(*socket,asio::const_buffers_1(asio::const_buffer(data,size))); + return ret; +} +int CConnection::read(void * data, unsigned size) +{ + int ret = asio::read(*socket,asio::mutable_buffers_1(asio::mutable_buffer(data,size))); + return ret; +} +CConnection::~CConnection(void) +{ + delete io_service; + delete socket; +} diff --git a/lib/Connection.h b/lib/Connection.h new file mode 100644 index 000000000..9e262ca6a --- /dev/null +++ b/lib/Connection.h @@ -0,0 +1,84 @@ +#pragma once +#include "../global.h" +#include +#include +namespace boost +{ + namespace asio + { + namespace ip + { + class tcp; + } + class io_service; + + template class stream_socket_service; + template + class basic_stream_socket; + } +}; + +class DLL_EXPORT CConnection +{ + std::ostream &out; + CConnection(void); +public: + boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > * socket; + bool logging; + bool connected; + bool myEndianess, contactEndianess; //true if little endian, if ednianess is different we'll have to revert recieved multi-byte vars + boost::asio::io_service *io_service; + std::string name; //who uses this connection + + CConnection(std::string host, std::string port, std::string Name, std::ostream & Out); + CConnection(boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > * Socket, boost::asio::io_service *Io_service, std::string Name, std::ostream & Out); //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); + ~CConnection(void); +}; + + +template CConnection & operator<<(CConnection &c, const T &data); +template CConnection & operator>>(CConnection &c, T &data); +CConnection & operator<<(CConnection &c, const std::string &data) +{ + boost::uint32_t length = data.size(); + c << length; + c.write(data.c_str(),length); + return c; +} +CConnection & operator>>(CConnection &c, std::string &data) +{ + boost::uint32_t length; + c >> length; + data.reserve(length); + c.read((void*)data.c_str(),length); + return c; +} +CConnection & operator<<(CConnection &c, const char * &data) +{ + boost::uint32_t length = strlen(data); + c << length; + c.write(data,length); + return c; +} +CConnection & operator>>(CConnection &c, char * &data) +{ + boost::uint32_t length; + c >> length; + data = new char[length]; + c.read(data,length); + return c; +} +template CConnection & operator<<(CConnection &c, const T &data) +{ + c.write(&data,sizeof(data)); + return c; +} +template CConnection & operator>>(CConnection &c, T &data) +{ + c.read(&data,sizeof(data)); + return c; +} \ No newline at end of file diff --git a/lib/VCMI_lib.vcproj b/lib/VCMI_lib.vcproj index 0d1c12fb8..c85598afc 100644 --- a/lib/VCMI_lib.vcproj +++ b/lib/VCMI_lib.vcproj @@ -17,7 +17,7 @@ + + @@ -421,6 +425,10 @@ RelativePath="..\hch\CObjectHandler.h" > + + diff --git a/server/VCMI_server.vcproj b/server/VCMI_server.vcproj index 0303b1bc8..f05aa6e97 100644 --- a/server/VCMI_server.vcproj +++ b/server/VCMI_server.vcproj @@ -57,6 +57,8 @@ /> @@ -125,6 +127,8 @@ /> #include #include "../global.h" +#include "../lib/Connection.h" std::string NAME = NAME_VER + std::string(" (server)"); using boost::asio::ip::tcp; using namespace boost; using namespace boost::asio; - -class CConnection -{ -public: - int ID; - tcp::socket socket; - void witaj() - { - char message[50]; strcpy(message,NAME.c_str());message[NAME.size()]='\n'; - write(socket,buffer("Aiya!\n")); - write(socket,buffer(message,NAME.size()+1)); - } - CConnection(io_service& io_service, int id=-1) - : socket(io_service), ID(id) - { - } -}; +using namespace boost::asio::ip; class CVCMIServer { @@ -38,27 +23,29 @@ public: private: void start_accept() { + boost::system::error_code error; std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl; - CConnection * new_connection = new CConnection(acceptor.io_service()); - acceptor.accept(new_connection->socket); - new_connection->witaj(); - acceptor.async_accept(new_connection->socket, - boost::bind(&CVCMIServer::gotConnection, this, new_connection, - placeholders::error)); - } - - void gotConnection(CConnection * connection,const boost::system::error_code& error) - { + tcp::socket s(acceptor.io_service()); + acceptor.accept(s,error); if (!error) { + CConnection *connection = new CConnection(&s,&s.io_service(),NAME,std::cout); std::cout<<"Got connection!" << std::endl; - connection->witaj(); - start_accept(); } else { std::cout<<"Got connection but there is an error " << std::endl; } + + //asio::write(s,asio::buffer("570")); + //new_connection->witaj(); + //acceptor.async_accept(s, + // boost::bind(&CVCMIServer::gotConnection, this, &s, + // placeholders::error)); + } + + void gotConnection(tcp::socket *s,const boost::system::error_code& error) + { } }; From 358ab062ebbbbf8abe71af885c80a5b21f618302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Wed, 9 Jul 2008 17:22:28 +0000 Subject: [PATCH 21/47] Base for netcode --- CAdvmapInterface.cpp | 2 +- CGameState.h | 1 + CMT.cpp | 79 +++++++++++++---------- CPreGame.cpp | Bin 129722 -> 129816 bytes StartInfo.h | 37 ++++++++--- global.h | 13 +++- lib/Connection.cpp | 46 ++++++++------ lib/Connection.h | 126 +++++++++++++++++++++++++++++++++++-- server/VCMI_server.vcproj | 7 ++- server/server_main.cpp | 129 +++++++++++++++++++++++++++++++------- 10 files changed, 345 insertions(+), 95 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 4e708bd3b..9486af337 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -119,7 +119,7 @@ void CMinimap::draw() } } } - blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps); + //blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps); //draw radar int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)CGI->mh->sizes.x)))*pos.w, diff --git a/CGameState.h b/CGameState.h index 14f5dd982..c62181219 100644 --- a/CGameState.h +++ b/CGameState.h @@ -106,6 +106,7 @@ public: friend CScriptCallback; friend void handleCPPObjS(std::map * mapa, CCPPObjectScript * script); friend class CMapHandler; + friend class CVCMIServer; }; #endif //CGAMESTATE_H diff --git a/CMT.cpp b/CMT.cpp index db4b48dd8..7cfefd511 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -1,7 +1,6 @@ // CMT.cpp : Defines the entry point for the console application. // #include "stdafx.h" -#include "SDL.h" #include "SDL_TTF.h" #include "hch/CVideoHandler.h" #include "SDL_mixer.h" @@ -44,6 +43,7 @@ #include "client/Graphics.h" #include #include "lib/Connection.h" +#include std::string NAME = NAME_VER + std::string(" (client)"); DLL_EXPORT void initDLL(CLodHandler *b); SDL_Surface * screen, * screen2; @@ -62,9 +62,6 @@ int _tmain(int argc, _TCHAR* argv[]) { //boost::thread servthr(boost::bind(system,"VCMI_server.exe")); //runs server executable; //TODO: add versions for other platforms - CConnection c("localhost","3030",NAME,std::cout); - int r; - c >> r; std::cout << NAME << std::endl; srand ( time(NULL) ); @@ -150,7 +147,7 @@ int _tmain(int argc, _TCHAR* argv[]) THC std::cout<<"Initialization of VCMI (togeter): "<mush = mush; StartInfo *options = new StartInfo(cpg->runLoop()); - +/////////////////////////////////////////////////////////////////////////////////////// cgi->dobjinfo = new CDefObjInfoHandler; cgi->dobjinfo->load(); THC std::cout<<"\tDef information handler: "<consoleh->runConsole(); THC std::cout<<"\tCallback and console: "<ourScenSel->mapsel.ourMaps[cpg->ourScenSel->mapsel.selected].filename; std::cout<<"Opening map file: "<> pom8; + if(pom8) throw "Server cannot open the map!"; + c < *options; + c << ui8(options->playerInfos.size()); + for(int i=0;iplayerInfos.size();i++) + c << ui8(options->playerInfos[i].color); + boost::crc_32_type result; + result.process_bytes(initTable,mapstr.size()); + std::cout << "\tMap checksum: "<state->init(options,mapa,8); CMapHandler * mh = cgi->mh = new CMapHandler(); @@ -236,36 +251,36 @@ int _tmain(int argc, _TCHAR* argv[]) } ///claculating FoWs for minimap /****************************Minimaps' FoW******************************************/ - for(int g=0; gplayerint.size(); ++g) - { - if(!cgi->playerint[g]->human) - continue; - CMinimap & mm = ((CPlayerInterface*)cgi->playerint[g])->adventureInt->minimap; + //for(int g=0; gplayerint.size(); ++g) + //{ + // if(!cgi->playerint[g]->human) + // continue; + // CMinimap & mm = ((CPlayerInterface*)cgi->playerint[g])->adventureInt->minimap; - int mw = mm.map[0]->w, mh = mm.map[0]->h, - wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y; + // int mw = mm.map[0]->w, mh = mm.map[0]->h, + // wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y; - for(int d=0; dmh->map->twoLevel+1; ++d) - { - SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface); + // for(int d=0; dmh->map->twoLevel+1; ++d) + // { + // SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface); - for (int i=0; imh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d ); + // for (int i=0; imh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d ); - if ( !((CPlayerInterface*)cgi->playerint[g])->cb->isVisible(pp) ) - { - CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0); - } - } - } - CSDL_Ext::update(pt); - mm.FoW.push_back(pt); - } + // if ( !((CPlayerInterface*)cgi->playerint[g])->cb->isVisible(pp) ) + // { + // CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0); + // } + // } + // } + // CSDL_Ext::update(pt); + // mm.FoW.push_back(pt); + // } - } + //} while(1) //main game loop, one execution per turn { diff --git a/CPreGame.cpp b/CPreGame.cpp index afad3fd17ee050570477b834108e49712dc97fa0..a3c904c31753eca114269c40320eaeeadf2dd70f 100644 GIT binary patch delta 62 zcmdn>m3_uH_6!0Tp8a delta 27 jcmbR7jeXZw_6 void serialize(Handler &h, const int version) + { + h && castle; + h && hero; + h && heroPortrait; + h && heroName; + h && bonus; + h && color; + h && serial; + h && handicap; + h && name; + h && human; + } }; - int difficulty; //0=easy; 4=impossible + si32 difficulty; //0=easy; 4=impossible std::vector playerInfos; - int turnTime; //in minutes, 0=unlimited + ui8 turnTime; //in minutes, 0=unlimited + std::string mapname; PlayerSettings & getIthPlayersSettings(int no) { - for(int i=0; i void serialize(Handler &h, const int version) + { + h && difficulty; + h & playerInfos; + h && turnTime; + h && mapname; + } }; #endif \ No newline at end of file diff --git a/global.h b/global.h index 8fa7d111a..0634bbd50 100644 --- a/global.h +++ b/global.h @@ -1,11 +1,18 @@ #ifndef GLOBAL_H #define GLOBAL_H +#include +#include +#include +typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) +typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes) +typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte) +typedef boost::int32_t si32; //signed int 32 bits (4 bytes) +typedef boost::int16_t si16; //signed int 16 bits (2 bytes) +typedef boost::int8_t si8; //signed int 8 bits (1 byte) +#include "int3.h" #define CHECKTIME 1 #if CHECKTIME #include "timeHandler.h" -#include -#include -#include "int3.h" #define THC #endif diff --git a/lib/Connection.cpp b/lib/Connection.cpp index b79557d11..6ae1d2c52 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -1,4 +1,5 @@ #define VCMI_DLL +#pragma warning(disable:4355) #include "Connection.h" #include using namespace boost; @@ -17,41 +18,48 @@ using namespace boost::asio::ip; #define LIL_ENDIAN #endif - -CConnection::CConnection(std::string host, std::string port, std::string Name, std::ostream & Out) -:io_service(new asio::io_service), name(Name), out(Out) +void CConnection::init() { #ifdef LIL_ENDIAN myEndianess = true; #else myEndianess = false; #endif + connected = true; + std::string pom; + //we got connection + (*this) << std::string("Aiya!\n") << name << myEndianess; //identify ourselves + (*this) >> pom >> pom >> contactEndianess; + out << "Established connection with "<connect(*endpoint_iterator, error); - if(error) - { - connected = false; - return; - } - std::string pom; - //we got connection - (*this) << std::string("Aiya!\n") << name << myEndianess; //identify ourselves - (*this) >> pom >> pom >> contactEndianess; + if (error){ delete socket; throw "Can't establish connection :("; } + init(); } CConnection::CConnection( boost::asio::basic_stream_socket > * Socket, - boost::asio::io_service *Io_service, std::string Name, std::ostream & Out ) -:socket(Socket),io_service(Io_service), out(Out), name(Name) + :socket(Socket),io_service(Socket->io_service()), out(Out), name(Name), send(this), rec(this) { - std::string pom; - //we start with just connected socket - (*this) << std::string("Aiya!\n") << name << myEndianess; //identify ourselves - (*this) >> pom >> pom >> contactEndianess; + init(); +} +CConnection::CConnection(boost::asio::basic_socket_acceptor > * 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; + socket = new tcp::socket(*io_service); + acceptor->accept(*socket,error); + if (error){ delete socket; throw "Can't establish connection :("; } + init(); } int CConnection::write(const void * data, unsigned size) { @@ -68,5 +76,7 @@ int CConnection::read(void * data, unsigned size) CConnection::~CConnection(void) { delete io_service; + if(socket) + socket->close(); delete socket; } diff --git a/lib/Connection.h b/lib/Connection.h index 9e262ca6a..0a1a4f68b 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -1,7 +1,11 @@ #pragma once #include "../global.h" -#include #include +#include +#include +const int version = 63; +class CConnection; + namespace boost { namespace asio @@ -13,17 +17,55 @@ namespace boost class io_service; template class stream_socket_service; - template + template class basic_stream_socket; + + template class socket_acceptor_service; + template + class basic_socket_acceptor; } }; +class CSender +{ +public: + CConnection* c; + CSender(CConnection* C):c(C){}; + template CSender & operator&&(T &data) //send built-in type + { + *c << data; + return *this; + } + template CSender & operator&(T &data) //send serializable type + { + *c < data; + return *this; + } +}; +class CReceiver +{ +public: + CConnection *c; + CReceiver(CConnection* C):c(C){}; + template CReceiver & operator&&(T &data) //get built-in type + { + *c >> data; + return *this; + } + template CReceiver & operator&(T &data) //get serializable type + { + *c > data; + return *this; + } +}; class DLL_EXPORT CConnection { std::ostream &out; CConnection(void); + void init(); public: + CSender send; + CReceiver rec; boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > * socket; bool logging; bool connected; @@ -31,8 +73,14 @@ public: boost::asio::io_service *io_service; std::string name; //who uses this connection - CConnection(std::string host, std::string port, std::string Name, std::ostream & Out); - CConnection(boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > * Socket, boost::asio::io_service *Io_service, std::string Name, std::ostream & Out); //use immediately after accepting connection into socket + CConnection + (std::string host, std::string port, std::string Name, std::ostream & Out); + CConnection + (boost::asio::basic_socket_acceptor > * acceptor, + boost::asio::io_service *Io_service, std::string Name, std::ostream & Out); + CConnection + (boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > * Socket, + std::string Name, std::ostream & Out); //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); @@ -53,7 +101,7 @@ CConnection & operator>>(CConnection &c, std::string &data) { boost::uint32_t length; c >> length; - data.reserve(length); + data.resize(length); c.read((void*)data.c_str(),length); return c; } @@ -68,10 +116,49 @@ CConnection & operator>>(CConnection &c, char * &data) { boost::uint32_t length; c >> length; + std::cout <<"Alokujemy " < CConnection & operator<<(CConnection &c, std::vector &data) +{ + boost::uint32_t length = data.size(); + c << length; + for(ui32 i=0;i CConnection & operator>>(CConnection &c, std::vector &data) +{ + boost::uint32_t length; + c >> length; + data.resize(length); + for(ui32 i=0;i> data[i]; + return c; +} +//template CConnection & operator<<(CConnection &c, std::set &data) +//{ +// boost::uint32_t length = data.size(); +// c << length; +// for(std::set::iterator i=data.begin();i!=data.end();i++) +// c << *i; +// return c; +//} +//template CConnection & operator>>(CConnection &c, std::set &data) +//{ +// boost::uint32_t length; +// c >> length; +// data.resize(length); +// T pom; +// for(int i=0;i> pom; +// data.insert(pom); +// } +// return c; +//} template CConnection & operator<<(CConnection &c, const T &data) { c.write(&data,sizeof(data)); @@ -81,4 +168,31 @@ template CConnection & operator>>(CConnection &c, T &data) { c.read(&data,sizeof(data)); return c; +} +template CConnection & operator<(CConnection &c, std::vector &data) +{ + boost::uint32_t length = data.size(); + c << length; + for(ui32 i=0;i CConnection & operator>(CConnection &c, std::vector &data) +{ + boost::uint32_t length; + c >> length; + data.resize(length); + for(ui32 i=0;i CConnection & operator<(CConnection &c, T &data) +{ + data.serialize(c.send,version); + return c; +} +template CConnection & operator>(CConnection &c, T &data) +{ + data.serialize(c.rec,version); + return c; } \ No newline at end of file diff --git a/server/VCMI_server.vcproj b/server/VCMI_server.vcproj index f05aa6e97..616074d21 100644 --- a/server/VCMI_server.vcproj +++ b/server/VCMI_server.vcproj @@ -20,7 +20,7 @@ OutputDirectory="$(SolutionDir)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="1" - CharacterSet="2" + CharacterSet="1" > #include "../global.h" #include "../lib/Connection.h" +#include "../CGameState.h" +#include "zlib.h" +#include +#include +#include +#include "../StartInfo.h" std::string NAME = NAME_VER + std::string(" (server)"); using boost::asio::ip::tcp; using namespace boost; using namespace boost::asio; using namespace boost::asio::ip; - +mutex smx1; class CVCMIServer { + CGameState *gs; tcp::acceptor acceptor; - std::vector connections; + std::map connections; + std::set conns; + ui32 seed; public: CVCMIServer(io_service& io_service) : acceptor(io_service, tcp::endpoint(tcp::v4(), 3030)) { - start_accept(); + start(); } -private: - void start_accept() + void setUpConnection(CConnection *c, std::string mapname, si32 checksum) + { + ui8 quantity, pom; + (*c) << mapname << checksum << seed; + (*c) >> quantity; + for(int i=0;i> pom; + smx1.lock(); + connections[pom] = c; + conns.insert(c); + smx1.unlock(); + } + } + void newGame(CConnection &c) { boost::system::error_code error; - std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl; - tcp::socket s(acceptor.io_service()); - acceptor.accept(s,error); - if (!error) + StartInfo *si = new StartInfo; + ui8 clients; + std::string mapname; + c >> clients; + c >> mapname; + //getting map + gzFile map = gzopen(mapname.c_str(),"rb"); + if(!map){ c << int8_t(1); return; } + std::vector mapstr; int pom; + while((pom=gzgetc(map))>=0) { - CConnection *connection = new CConnection(&s,&s.io_service(),NAME,std::cout); - std::cout<<"Got connection!" << std::endl; + mapstr.push_back(pom); } - else + gzclose(map); + //map is decompressed + c << int8_t(0); //OK! + gs = new CGameState(); + gs->scenarioOps = si; + c > *si; //get start options + boost::crc_32_type result; + result.process_bytes(&(*mapstr.begin()),mapstr.size()); + int checksum = result.checksum(); + std::cout << "Checksum:" << checksum << std::endl; + CConnection* cc; tcp::socket * ss; + for(int i=0; i> mode; + switch (mode) + { + case 0: + connection.socket->close(); + exit(0); + break; + case 1: + connection.socket->close(); + return; + break; + case 2: + newGame(connection); + break; + } } - - //asio::write(s,asio::buffer("570")); - //new_connection->witaj(); - //acceptor.async_accept(s, - // boost::bind(&CVCMIServer::gotConnection, this, &s, - // placeholders::error)); } - - void gotConnection(tcp::socket *s,const boost::system::error_code& error) - { - } - }; -int main() +int _tmain(int argc, _TCHAR* argv[]) { try { io_service io_service; CVCMIServer server(io_service); + while(1) + server.start(); io_service.run(); } catch (std::exception& e) From 0c139e72f5201f4a1e81212b1cd6a6c5cf8781be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Fri, 25 Jul 2008 17:28:28 +0000 Subject: [PATCH 22/47] More changes for netcode/serialization Removed not needed stuff --- CAdvmapInterface.cpp | 1 + CCallback.cpp | 191 ++----- CCallback.h | 11 +- CConsoleHandler.h | 2 +- CGameState.cpp | 37 +- CGameState.h | 23 +- CLua.cpp | 133 ++--- CLua.h | 3 +- CLuaHandler.cpp | 54 +- CMT.cpp | 150 ++--- CPreGame.cpp | Bin 129816 -> 129830 bytes DefSorter.exe | Bin 32768 -> 0 bytes Projekt.dia | Bin 3265 -> 0 bytes SDL_Extensions.cpp | 2 +- StartInfo.h | 30 +- client/Client.cpp | 110 ++++ client/Client.h | 19 + client/VCMI_client.vcproj | 152 +---- int3.h | 2 +- lib/Connection.cpp | 41 +- lib/Connection.h | 430 +++++++++++---- lib/VCMI_Lib.cpp | 36 ++ lib/VCMI_Lib.h | 7 +- lib/VCMI_lib.vcproj | 8 +- map.cpp | 27 +- map.h | 4 +- mapHandler.cpp | 22 +- mapHandler.h | 16 +- server/CGameHandler.cpp | 145 +++++ server/CGameHandler.h | 17 +- server/VCMI_server.vcproj | 15 +- server/server_main.cpp | 219 ++++---- tools/Defopruj/AssemblyInfo.cpp | 38 -- tools/Defopruj/CDefHandler.cpp | Bin 26988 -> 0 bytes tools/Defopruj/CDefHandler.h | Bin 3846 -> 0 bytes tools/Defopruj/Oknopruj.cpp | 62 --- tools/Defopruj/Oknopruj.h | 235 -------- tools/Defopruj/wyprujdef.vcproj | 260 --------- tools/Defsorter/Form1.Designer.cs | 99 ---- tools/Defsorter/Form1.cs | 242 -------- tools/Defsorter/Form2.Designer.cs | 517 ----------------- tools/Defsorter/Form2.cs | 28 - tools/Defsorter/Form3.Designer.cs | 101 ---- tools/Defsorter/Form3.cs | 23 - tools/Defsorter/Program.cs | 20 - tools/Obwodziciel/BNAMES.txt | 44 -- tools/Obwodziciel/Form1.h | 791 --------------------------- tools/Obwodziciel/Form1.resx | 126 ----- tools/Obwodziciel/Obwodziciel.cpp | 17 - tools/Obwodziciel/Obwodziciel.vcproj | 236 -------- tools/Obwodziciel/TOWNTYPE.TXT | 9 - tools/Obwodziciel/buildings.txt | 37 -- tools/Wpasujbud/AssemblyInfo.cpp | 38 -- tools/Wpasujbud/Wpasujbud.cpp | 361 ------------ tools/Wpasujbud/Wpasujbud.h | 649 ---------------------- tools/Wpasujbud/config/BNAMES.txt | 44 -- tools/Wpasujbud/config/TOWNTYPE.TXT | 9 - tools/Wpasujbud/data.h | 12 - tools/Wpasujbud/dataEditor.cpp | 2 - tools/Wpasujbud/dataEditor.h | 209 ------- tools/Wpasujbud/obrazek.cpp | 2 - tools/Wpasujbud/obrazek.h | 121 ---- 62 files changed, 1102 insertions(+), 5137 deletions(-) delete mode 100644 DefSorter.exe delete mode 100644 Projekt.dia create mode 100644 client/Client.cpp create mode 100644 client/Client.h delete mode 100644 tools/Defopruj/AssemblyInfo.cpp delete mode 100644 tools/Defopruj/CDefHandler.cpp delete mode 100644 tools/Defopruj/CDefHandler.h delete mode 100644 tools/Defopruj/Oknopruj.cpp delete mode 100644 tools/Defopruj/Oknopruj.h delete mode 100644 tools/Defopruj/wyprujdef.vcproj delete mode 100644 tools/Defsorter/Form1.Designer.cs delete mode 100644 tools/Defsorter/Form1.cs delete mode 100644 tools/Defsorter/Form2.Designer.cs delete mode 100644 tools/Defsorter/Form2.cs delete mode 100644 tools/Defsorter/Form3.Designer.cs delete mode 100644 tools/Defsorter/Form3.cs delete mode 100644 tools/Defsorter/Program.cs delete mode 100644 tools/Obwodziciel/BNAMES.txt delete mode 100644 tools/Obwodziciel/Form1.h delete mode 100644 tools/Obwodziciel/Form1.resx delete mode 100644 tools/Obwodziciel/Obwodziciel.cpp delete mode 100644 tools/Obwodziciel/Obwodziciel.vcproj delete mode 100644 tools/Obwodziciel/TOWNTYPE.TXT delete mode 100644 tools/Obwodziciel/buildings.txt delete mode 100644 tools/Wpasujbud/AssemblyInfo.cpp delete mode 100644 tools/Wpasujbud/Wpasujbud.cpp delete mode 100644 tools/Wpasujbud/Wpasujbud.h delete mode 100644 tools/Wpasujbud/config/BNAMES.txt delete mode 100644 tools/Wpasujbud/config/TOWNTYPE.TXT delete mode 100644 tools/Wpasujbud/data.h delete mode 100644 tools/Wpasujbud/dataEditor.cpp delete mode 100644 tools/Wpasujbud/dataEditor.h delete mode 100644 tools/Wpasujbud/obrazek.cpp delete mode 100644 tools/Wpasujbud/obrazek.h diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 9486af337..7fc291a09 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -4,6 +4,7 @@ #include "CPlayerInterface.h" #include "hch/CPreGameTextHandler.h" #include "hch/CGeneralTextHandler.h" +#include "hch/CDefHandler.h" #include "hch/CTownHandler.h" #include "CPathfinder.h" #include "CGameInfo.h" diff --git a/CCallback.cpp b/CCallback.cpp index 72c4767d7..9673576c0 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -14,63 +14,8 @@ #include "CPlayerInterface.h" #include "hch/CBuildingHandler.h" #include "hch/CObjectHandler.h" -LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); +//LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); -int CCallback::lowestSpeed(CGHeroInstance * chi) -{ - int min = 150; - for ( std::map >::iterator i = chi->army.slots.begin(); - i!=chi->army.slots.end(); i++ ) - { - if (min>(*i).second.first->speed) - min = (*i).second.first->speed; - } - return min; -} -int CCallback::valMovePoints(CGHeroInstance * chi) -{ - int ret = 1270+70*lowestSpeed(chi); - if (ret>2000) - ret=2000; - - //TODO: additional bonuses (but they aren't currently stored in chi) - - return ret; -} -void CCallback::newTurn() -{ - //std::map::iterator i = gs->players.begin() ; - gs->day++; - for (std::set::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++) - { - (*i)->newTurn(); - } - for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) - { - //handle heroes///////////////////////////// - for (int j=0;j<(*i).second.heroes.size();j++) - { - (*i).second.heroes[j]->movement = valMovePoints((*i).second.heroes[j]); - } - - - //handle towns///////////////////////////// - for(int j=0;jsecond.towns.size();j++) - { - i->second.towns[j]->builded=0; - if(getDate(1)==1) //first day of week - { - for(int k=0;ksecond.towns[j]->creatureDwelling(k))//there is dwelling - i->second.towns[j]->strInfo.creatures[k]+=i->second.towns[j]->creatureGrowth(k); - } - } - if((gs->day>1) && i->firstsecond.resources[6]+=i->second.towns[j]->dailyIncome(); - } - } -} bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) { CGHeroInstance * hero = NULL; @@ -93,7 +38,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) else //idtype==1; player<0 { - for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j) + for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j) { for (int i=0; i<(*j).second.heroes.size();i++) { @@ -193,7 +138,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) //notify interfacesabout move int nn=0; //number of interfece of currently browsed player - for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing + for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing { if (j->first > PLAYER_LIMIT) break; @@ -425,30 +370,7 @@ std::vector CCallback::getResourceAmount() } int CCallback::getDate(int mode) { - int temp; - switch (mode) - { - case 0: - return gs->day; - break; - case 1: - temp = (gs->day)%7; - if (temp) - return temp; - else return 7; - break; - case 2: - temp = ((gs->day-1)/7)+1; - if (!(temp%4)) - return 4; - else - return (temp%4); - break; - case 3: - return ((gs->day-1)/28)+1; - break; - } - return 0; + return gs->getDate(mode); } bool CCallback::verifyPath(CPath * path, bool blockSea) { @@ -504,7 +426,7 @@ bool CCallback::isVisible(int3 pos, int Player) std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) { std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>(); - for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) { for (int j=0;j<(*i).second.towns.size();j++) { @@ -519,7 +441,7 @@ std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur) { std::vector < const CGHeroInstance *> ret = std::vector < const CGHeroInstance *>(); - for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) { for (int j=0;j<(*i).second.heroes.size();j++) { @@ -1037,77 +959,68 @@ void CScriptCallback::startBattle(int heroID, CCreatureSet * army, int3 tile) // } void CLuaCallback::registerFuncs(lua_State * L) { - lua_newtable(L); - -#define REGISTER_C_FUNC(x) \ - lua_pushstring(L, #x); \ - lua_pushcfunction(L, x); \ - lua_rawset(L, -3) - - REGISTER_C_FUNC(getPos); - REGISTER_C_FUNC(changePrimSkill); - REGISTER_C_FUNC(getGnrlText); - REGISTER_C_FUNC(getSelectedHero); - - /* - REGISTER_C_FUNC(changePrimSkill); - REGISTER_C_FUNC(getGnrlText); - REGISTER_C_FUNC(changePrimSkill); - REGISTER_C_FUNC(getGnrlText); - REGISTER_C_FUNC(changePrimSkill); - REGISTER_C_FUNC(getGnrlText);*/ - - - lua_setglobal(L, "vcmi"); - #undef REGISTER_C_FUNC +// lua_newtable(L); +// +//#define REGISTER_C_FUNC(x) \ +// lua_pushstring(L, #x); \ +// lua_pushcfunction(L, x); \ +// lua_rawset(L, -3) +// +// REGISTER_C_FUNC(getPos); +// REGISTER_C_FUNC(changePrimSkill); +// REGISTER_C_FUNC(getGnrlText); +// REGISTER_C_FUNC(getSelectedHero); +// +// lua_setglobal(L, "vcmi"); +// #undef REGISTER_C_FUNC } int CLuaCallback::getPos(lua_State * L)//(CGObjectInstance * object); { - const int args = lua_gettop(L); // number of arguments - if ((args < 1) || !lua_isnumber(L, 1) ) - luaL_error(L, - "Incorrect arguments to getPos([Object address])"); - CGObjectInstance * object = (CGObjectInstance *)(lua_tointeger(L, 1)); - lua_pushinteger(L,object->pos.x); - lua_pushinteger(L,object->pos.y); - lua_pushinteger(L,object->pos.z); + //const int args = lua_gettop(L); // number of arguments + //if ((args < 1) || !lua_isnumber(L, 1) ) + // luaL_error(L, + // "Incorrect arguments to getPos([Object address])"); + //CGObjectInstance * object = (CGObjectInstance *)(lua_tointeger(L, 1)); + //lua_pushinteger(L,object->pos.x); + //lua_pushinteger(L,object->pos.y); + //lua_pushinteger(L,object->pos.z); return 3; } int CLuaCallback::changePrimSkill(lua_State * L)//(int ID, int which, int val); { - const int args = lua_gettop(L); // number of arguments - if ((args < 1) || !lua_isnumber(L, 1) || - ((args >= 2) && !lua_isnumber(L, 2)) || - ((args >= 3) && !lua_isnumber(L, 3)) ) - { - luaL_error(L, - "Incorrect arguments to changePrimSkill([Hero ID], [Which Primary skill], [Change by])"); - } - int ID = lua_tointeger(L, 1), - which = lua_tointeger(L, 2), - val = lua_tointeger(L, 3); + //const int args = lua_gettop(L); // number of arguments + //if ((args < 1) || !lua_isnumber(L, 1) || + // ((args >= 2) && !lua_isnumber(L, 2)) || + // ((args >= 3) && !lua_isnumber(L, 3)) ) + //{ + // luaL_error(L, + // "Incorrect arguments to changePrimSkill([Hero ID], [Which Primary skill], [Change by])"); + //} + //int ID = lua_tointeger(L, 1), + // which = lua_tointeger(L, 2), + // val = lua_tointeger(L, 3); - CScriptCallback::changePrimSkill(ID,which,val); + //CScriptCallback::changePrimSkill(ID,which,val); return 0; } int CLuaCallback::getGnrlText(lua_State * L) //(int which),returns string { - const int args = lua_gettop(L); // number of arguments - if ((args < 1) || !lua_isnumber(L, 1) ) - luaL_error(L, - "Incorrect arguments to getGnrlText([Text ID])"); - int which = lua_tointeger(L,1); - lua_pushstring(L,CGI->generaltexth->allTexts[which].c_str()); + //const int args = lua_gettop(L); // number of arguments + //if ((args < 1) || !lua_isnumber(L, 1) ) + // luaL_error(L, + // "Incorrect arguments to getGnrlText([Text ID])"); + //int which = lua_tointeger(L,1); + //lua_pushstring(L,CGI->generaltexth->allTexts[which].c_str()); return 1; } int CLuaCallback::getSelectedHero(lua_State * L) //(),returns int (ID of hero, -1 if no hero is seleceted) { - int ret; - if (LOCPLINT->adventureInt->selection.type == HEROI_TYPE) - ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->subID; - else - ret = -1; - lua_pushinteger(L,ret); + //int ret; + //if (LOCPLINT->adventureInt->selection.type == HEROI_TYPE) + // ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->subID; + //else + // ret = -1; + //lua_pushinteger(L,ret); return 1; } diff --git a/CCallback.h b/CCallback.h index 215039f6d..34bf91854 100644 --- a/CCallback.h +++ b/CCallback.h @@ -85,11 +85,8 @@ struct HeroMoveDetails class CCallback : public ICallback { private: - void newTurn(); CCallback(CGameState * GS, int Player):gs(GS),player(Player){}; CGameState * gs; - int lowestSpeed(CGHeroInstance * chi); //speed of the slowest stack - int valMovePoints(CGHeroInstance * chi); bool isVisible(int3 pos, int Player); protected: @@ -148,7 +145,7 @@ public: //friends - friend int _tmain(int argc, _TCHAR* argv[]); + friend class CClient; }; class CScriptCallback { @@ -174,7 +171,8 @@ public: void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army //friends - friend CGameState; + friend class CGameState; + friend class CClient; }; class CLuaCallback : public CScriptCallback { @@ -186,6 +184,7 @@ private: static int getGnrlText(lua_State * L);//(int ID, int which, int val); static int getSelectedHero(lua_State * L);//() - friend CGameState; + friend class CGameState; + friend class CClient; }; #endif //CCALLBACK_H \ No newline at end of file diff --git a/CConsoleHandler.h b/CConsoleHandler.h index bbf6c7b60..9c9584aa4 100644 --- a/CConsoleHandler.h +++ b/CConsoleHandler.h @@ -7,7 +7,7 @@ class CConsoleHandler public: void runConsole(); - friend int _tmain(int argc, _TCHAR* argv[]); + friend class CClient; }; #endif //CCONSOLEHANDLER_H \ No newline at end of file diff --git a/CGameState.cpp b/CGameState.cpp index 7a44877b9..5dc48b13c 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -249,8 +249,37 @@ void CGameState::randomizeObject(CGObjectInstance *cur) map->defs.insert(cur->defInfo = VLC->dobjinfo->gobjs[ran.first][ran.second]); if(!cur->defInfo){std::cout<<"Missing def declaration for "<ID<<" "<subID<map = map; @@ -313,7 +342,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int seed) startres.push_back(k); } tis.close(); - for (std::map::iterator i = players.begin(); i!=players.end(); i++) + for (std::map::iterator i = players.begin(); i!=players.end(); i++) { (*i).second.resources.resize(RESOURCE_QUANTITY); for (int x=0;x::iterator k=players.begin(); k!=players.end(); ++k) + for(std::map::iterator k=players.begin(); k!=players.end(); ++k) { k->second.fogOfWarMap.resize(map->width); for(int g=0; gwidth; ++g) @@ -439,7 +468,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int seed) players[vti->getOwner()].towns.push_back(vti); } - for(std::map::iterator k=players.begin(); k!=players.end(); ++k) + for(std::map::iterator k=players.begin(); k!=players.end(); ++k) { if(k->first==-1 || k->first==255) continue; diff --git a/CGameState.h b/CGameState.h index c62181219..725146fbf 100644 --- a/CGameState.h +++ b/CGameState.h @@ -66,11 +66,12 @@ class DLL_EXPORT CGameState { private: StartInfo* scenarioOps; - int currentPlayer; //ID of player currently having turn + ui32 seed; + ui8 currentPlayer; //ID of player currently having turn BattleInfo *curB; //current battle - int day; //total number of days in game + ui32 day; //total number of days in game Mapa * map; - std::map players; //ID <-> playerstate + std::map players; //ID <-> playerstate std::set cppscripts; //C++ scripts std::map > objscr; //non-C++ scripts @@ -88,7 +89,7 @@ private: return false; } - void init(StartInfo * si, Mapa * map, int seed); + void init(StartInfo * si, Mapa * map, int Seed); void randomizeObject(CGObjectInstance *cur); std::pair pickObject(CGObjectInstance *obj); int pickHero(int owner); @@ -98,15 +99,17 @@ private: bool battleAttackCreatureStack(int ID, int dest); std::vector battleGetRange(int ID); //called by std::vector CCallback::battleGetAvailableHexes(int ID); public: - friend CCallback; - friend CPathfinder;; - friend CLuaCallback; - friend int _tmain(int argc, _TCHAR* argv[]); + 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 + + friend class CCallback; + friend class CPathfinder;; + friend class CLuaCallback; + friend class CClient; friend void initGameState(Mapa * map, CGameInfo * cgi); - friend CScriptCallback; + friend class CScriptCallback; friend void handleCPPObjS(std::map * mapa, CCPPObjectScript * script); friend class CMapHandler; - friend class CVCMIServer; + friend class CGameHandler; }; #endif //CGAMESTATE_H diff --git a/CLua.cpp b/CLua.cpp index 7fb5210b2..57d341d3e 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -2,12 +2,12 @@ #include "CLua.h" #include "CLuaHandler.h" #include "hch/CHeroHandler.h" -#include "lua.h" -#include "lualib.h" -#include "lauxlib.h" -#include "lobject.h" -#include "lgc.h" -#include "lapi.h" +//#include "lua.h" +//#include "lualib.h" +//#include "lauxlib.h" +//#include "lobject.h" +//#include "lgc.h" +//#include "lapi.h" #include "CGameInfo.h" #include "CGameState.h" #include @@ -26,10 +26,11 @@ #pragma warning (disable : 4311) bool getGlobalFunc(lua_State * L, std::string fname) { - unsigned int hash = lua_calchash(fname.c_str(), fname.size()); - lua_pushhstring(L, hash, fname.c_str(), fname.size()); - lua_gettable(L, LUA_GLOBALSINDEX); - return lua_isfunction(L, -1); + //unsigned int hash = lua_calchash(fname.c_str(), fname.size()); + //lua_pushhstring(L, hash, fname.c_str(), fname.size()); + //lua_gettable(L, LUA_GLOBALSINDEX); + //return lua_isfunction(L, -1); + return false; } CObjectScript::CObjectScript() @@ -65,20 +66,20 @@ CLua::CLua() } void CLua::open(std::string initpath) { - LST = lua_open(); - opened = true; - LUA_OPEN_LIB(LST, luaopen_base); - LUA_OPEN_LIB(LST, luaopen_io); - if ((luaL_loadfile (LST, initpath.c_str())) == 0) - { - lua_pcall (LST, 0, LUA_MULTRET, 0); - } - else - { - std::string temp = "Cannot open script "; - temp += initpath; - throw std::exception(temp.c_str()); - } + //LST = lua_open(); + //opened = true; + //LUA_OPEN_LIB(LST, luaopen_base); + //LUA_OPEN_LIB(LST, luaopen_io); + //if ((luaL_loadfile (LST, initpath.c_str())) == 0) + //{ + // lua_pcall (LST, 0, LUA_MULTRET, 0); + //} + //else + //{ + // std::string temp = "Cannot open script "; + // temp += initpath; + // throw std::exception(temp.c_str()); + //} } void CLua::registerCLuaCallback() { @@ -86,31 +87,31 @@ void CLua::registerCLuaCallback() CLua::~CLua() { - //std::cout << "Usuwam obiekt clua "<ID)); - lua_pushinteger(is, (int)os); - if (lua_pcall (is, 1, 0, 0)) - { - lua_settop(is, 0); - throw new std::exception(("Failed to call "+genFN("newObject",os->ID)+" function in lua script.").c_str()); - } - lua_settop(is, 0); + //findF(genFN("newObject",os->ID)); + //lua_pushinteger(is, (int)os); + //if (lua_pcall (is, 1, 0, 0)) + //{ + // lua_settop(is, 0); + // throw new std::exception(("Failed to call "+genFN("newObject",os->ID)+" function in lua script.").c_str()); + //} + //lua_settop(is, 0); return; } void CLuaObjectScript::onHeroVisit(CGObjectInstance *os, int heroID) { - findF(genFN("heroVisit",os->ID)); - lua_pushinteger(is, (int)os); - lua_pushinteger(is, heroID); - if (lua_pcall (is, 2, 0, 0)) - { - lua_settop(is, 0); - throw new std::exception(("Failed to call "+genFN("heroVisit",os->ID)+" function in lua script.").c_str()); - } - lua_settop(is, 0); + //findF(genFN("heroVisit",os->ID)); + //lua_pushinteger(is, (int)os); + //lua_pushinteger(is, heroID); + //if (lua_pcall (is, 2, 0, 0)) + //{ + // lua_settop(is, 0); + // throw new std::exception(("Failed to call "+genFN("heroVisit",os->ID)+" function in lua script.").c_str()); + //} + //lua_settop(is, 0); } std::string CLuaObjectScript::hoverText(CGObjectInstance *os) { - findF(genFN("hoverText",os->ID)); - lua_pushinteger(is, (int)os); - if (lua_pcall (is, 1, 1, 0)) - { - lua_settop(is, 0); - throw new std::exception(("Failed to call "+genFN("hoverText",os->ID)+" function in lua script.").c_str()); - } - std::string ret = lua_tostring(is,1); - lua_settop(is, 0); - return ret; + //findF(genFN("hoverText",os->ID)); + //lua_pushinteger(is, (int)os); + //if (lua_pcall (is, 1, 1, 0)) + //{ + // lua_settop(is, 0); + // throw new std::exception(("Failed to call "+genFN("hoverText",os->ID)+" function in lua script.").c_str()); + //} + //std::string ret = lua_tostring(is,1); + //lua_settop(is, 0); + return ""; } std::string CCPPObjectScript::hoverText(CGObjectInstance *os) diff --git a/CLua.h b/CLua.h index 2d697fe4d..6dc166f8a 100644 --- a/CLua.h +++ b/CLua.h @@ -1,6 +1,6 @@ #pragma once #include "global.h" -#include "lstate.h" +//#include "lstate.h" #include #include class CLua; @@ -13,6 +13,7 @@ class SComponent; class CSelectableComponent; class CGameState; struct Mapa; +struct lua_State; enum ESLan{UNDEF=-1,CPP,ERM,LUA}; class CObjectScript { diff --git a/CLuaHandler.cpp b/CLuaHandler.cpp index 30706baaf..93e1f82f7 100644 --- a/CLuaHandler.cpp +++ b/CLuaHandler.cpp @@ -23,45 +23,21 @@ CLuaHandler::~CLuaHandler() } void CLuaHandler::test() { - int iErr = 0; - lua_State *lua = lua_open (); // Open Lua - LUA_OPEN_LIB(lua, luaopen_base); - LUA_OPEN_LIB(lua, luaopen_io); - - //luabind::open(lua); - //luabind::module(lua) - //[ - // luabind::class_("int3") - // //.def(luabind::constructor<>()) - // //.def(luabind::constructor()) - // .def_readwrite("x", &int3::x) - // .def_readwrite("y", &int3::y) - // .def_readwrite("z", &int3::z) - //]; - //luabind::module(lua) - //[ - // luabind::def("powitanie",&piszpowitanie2) - //]; - - - if ((iErr = luaL_loadfile (lua, "scripts/lua/objects/0023_marletto_tower.lua")) == 0) - { - // Call main... - if ((iErr = lua_pcall (lua, 0, LUA_MULTRET, 0)) == 0) - { - - //int ret = luabind::call_function(lua, "helloWorld2"); - //lua_pushstring (lua, "helloWorld2"); - //lua_gettable (lua, LUA_GLOBALSINDEX); - //lua_pcall (lua, 0, 0, 0); - - // Push the function name onto the stack - lua_pushstring (lua, "rightText"); - lua_gettable (lua, LUA_GLOBALSINDEX); - lua_pcall (lua, 0, 0, 0); - } - } - lua_close (lua); + //int iErr = 0; + //lua_State *lua = lua_open (); // Open Lua + //LUA_OPEN_LIB(lua, luaopen_base); + //LUA_OPEN_LIB(lua, luaopen_io); + //if ((iErr = luaL_loadfile (lua, "scripts/lua/objects/0023_marletto_tower.lua")) == 0) + //{ + // // Call main... + // if ((iErr = lua_pcall (lua, 0, LUA_MULTRET, 0)) == 0) + // { + // lua_pushstring (lua, "rightText"); + // lua_gettable (lua, LUA_GLOBALSINDEX); + // lua_pcall (lua, 0, 0, 0); + // } + //} + //lua_close (lua); } diff --git a/CMT.cpp b/CMT.cpp index 7cfefd511..6c3df98cf 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -1,35 +1,19 @@ // CMT.cpp : Defines the entry point for the console application. // #include "stdafx.h" -#include "SDL_TTF.h" -#include "hch/CVideoHandler.h" -#include "SDL_mixer.h" -#include "hch/CBuildingHandler.h" -#include "SDL_Extensions.h" -#include "SDL_framerate.h" #include #include #include -#include "zlib.h" #include -#include "hch/CArtHandler.h" -#include "hch/CHeroHandler.h" -#include "hch/CCreatureHandler.h" -#include "hch/CAbilityHandler.h" -#include "hch/CSpellHandler.h" -#include "hch/CBuildingHandler.h" -#include "hch/CObjectHandler.h" +#include +#include "SDL_TTF.h" +#include "SDL_mixer.h" +#include "SDL_Extensions.h" +#include "SDL_framerate.h" #include "CGameInfo.h" -#include "hch/CMusicHandler.h" -#include "hch/CLodHandler.h" -#include "hch/CDefHandler.h" -#include "hch/CTownHandler.h" -#include "hch/CDefObjInfoHandler.h" -#include "hch/CAmbarCendamo.h" #include "mapHandler.h" #include "global.h" #include "CPreGame.h" -#include "hch/CGeneralTextHandler.h" #include "CConsoleHandler.h" #include "CCursorHandler.h" #include "CScreenHandler.h" @@ -40,10 +24,22 @@ #include "CLuaHandler.h" #include "CLua.h" #include "CAdvmapInterface.h" +#include "hch/CBuildingHandler.h" +#include "hch/CVideoHandler.h" +#include "hch/CAbilityHandler.h" +#include "hch/CHeroHandler.h" +#include "hch/CCreatureHandler.h" +#include "hch/CSpellHandler.h" +#include "hch/CBuildingHandler.h" +#include "hch/CMusicHandler.h" +#include "hch/CLodHandler.h" +#include "hch/CDefHandler.h" +#include "hch/CAmbarCendamo.h" +#include "hch/CGeneralTextHandler.h" #include "client/Graphics.h" -#include +#include "Client/Client.h" #include "lib/Connection.h" -#include +#include "lib/VCMI_Lib.h" std::string NAME = NAME_VER + std::string(" (client)"); DLL_EXPORT void initDLL(CLodHandler *b); SDL_Surface * screen, * screen2; @@ -108,6 +104,13 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->bitmaph->init("Data\\H3bitmap.lod","Data"); THC std::cout<<"Loading .lod files: "<bitmaph); + + CGI->arth = VLC->arth; + CGI->townh = VLC->townh; + CGI->heroh = VLC->heroh; + CGI->objh = VLC->objh; + CGI->dobjinfo = VLC->dobjinfo; + THC std::cout<<"Initializing VCMI_Lib: "<curh->initCursor(); @@ -116,18 +119,12 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->screenh = new CScreenHandler; cgi->screenh->initScreen(); THC std::cout<<"\tScreen handler: "<townh = new CTownHandler; - cgi->townh->loadNames(); - THC std::cout<<"\tTown handler: "<loadAbilities(); cgi->abilh = abilh; THC std::cout<<"\tAbility handler: "<loadHeroes(); - heroh->loadPortraits(); - cgi->heroh = heroh; - THC std::cout<<"\tHero handler: "<mush = mush; StartInfo *options = new StartInfo(cpg->runLoop()); /////////////////////////////////////////////////////////////////////////////////////// - cgi->dobjinfo = new CDefObjInfoHandler; - cgi->dobjinfo->load(); - THC std::cout<<"\tDef information handler: "<state = new CGameState(); - cgi->state->scenarioOps = options; THC std::cout<<"\tGamestate: "<loadArtifacts(); - cgi->arth = arth; - THC std::cout<<"\tArtifact handler: "<loadCreatures(); - cgi->creh = creh; - THC std::cout<<"\tCreature handler: "<loadSpells(); @@ -177,78 +162,21 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->buildh = buildh; THC std::cout<<"\tBuilding handler: "<loadObjects(); - cgi->objh = objh; - THC std::cout<<"\tObject handler: "<pathf = new CPathfinder(); THC std::cout<<"\tPathfinder: "<consoleh->cb = new CCallback(cgi->state,-1); cgi->consoleh->runConsole(); THC std::cout<<"\tCallback and console: "<ourScenSel->mapsel.ourMaps[cpg->ourScenSel->mapsel.selected].filename; - std::cout<<"Opening map file: "< mapstr; int pom; - while((pom=gzgetc(map))>=0) - { - mapstr.push_back(pom); - } - gzclose(map); - unsigned char *initTable = new unsigned char[mapstr.size()]; - for(int ss=0; ss> pom8; - if(pom8) throw "Server cannot open the map!"; - c < *options; - c << ui8(options->playerInfos.size()); - for(int i=0;iplayerInfos.size();i++) - c << ui8(options->playerInfos[i].color); - boost::crc_32_type result; - result.process_bytes(initTable,mapstr.size()); - std::cout << "\tMap checksum: "<state->init(options,mapa,8); - - CMapHandler * mh = cgi->mh = new CMapHandler(); - THC std::cout<<"Initializing GameState (together): "<map = mapa; - THC std::cout<<"Creating mapHandler: "<loadDefs(); - THC std::cout<<"Reading terrain defs: "<init(); - THC std::cout<<"Initializing mapHandler (together): "<state->scenarioOps->playerInfos.size();i++) //initializing interfaces - { - - if(!cgi->state->scenarioOps->playerInfos[i].human) - cgi->playerint.push_back(static_cast(CAIHandler::getNewAI(new CCallback(cgi->state,cgi->state->scenarioOps->playerInfos[i].color),"EmptyAI.dll"))); - else - { - cgi->state->currentPlayer=cgi->state->scenarioOps->playerInfos[i].color; - cgi->playerint.push_back(new CPlayerInterface(cgi->state->scenarioOps->playerInfos[i].color,i)); - ((CPlayerInterface*)(cgi->playerint[i]))->init(new CCallback(cgi->state,cgi->state->scenarioOps->playerInfos[i].color)); - } - } ///claculating FoWs for minimap /****************************Minimaps' FoW******************************************/ //for(int g=0; gplayerint.size(); ++g) @@ -281,19 +209,7 @@ int _tmain(int argc, _TCHAR* argv[]) // } //} - - while(1) //main game loop, one execution per turn - { - cgi->consoleh->cb->newTurn(); - for (int i=0;iplayerint.size();i++) - { - cgi->state->currentPlayer=cgi->playerint[i]->playerID; - try - { - cgi->playerint[i]->yourTurn(); - }HANDLE_EXCEPTION - } - } + cl.run(); } else { diff --git a/CPreGame.cpp b/CPreGame.cpp index a3c904c31753eca114269c40320eaeeadf2dd70f..da782cdd47c096a453ca6cf786b56ba64d3578fe 100644 GIT binary patch delta 31 ncmbR7jeXfS_6=;`rZ-41im<0KWHRJ1q&5qG+b;Z#k(Cty$-E0E delta 26 icmZ4XjeW*9_6=;`rY>OQo6MFb&}{T=yU{nsFDwA1>I=I7 diff --git a/DefSorter.exe b/DefSorter.exe deleted file mode 100644 index 8da32bc65c4b791badf42129b3213d4b6d02e8ae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeHPYm{77mEO0y>(Q@DstdZ)3D6ZoLMJ3`zmjwUf%GGfCTSAVod+5o)m1m0N~-HN zx2i*$n9#vN7mk3D8Acp&0AGv2QGASm3Ni?@29}_RjxsJ7@G*)@bWp*ivxNEfzW3C9 zRHrm6|FkO9zWeO6&pzMY_ndvtIk)KHcYJ`Vh^QLhx85Rp5Lf=J7h0aopgP+6{OuQAmvG33Do!$m9}(+eQ)-Mp|!gXsA8cHobiV z(N?XBp4E?SRK2}KQLRpk5N(GfVM#B_+58Nb*IV+r7H*a>e)&8K3ORoQB1S>V>RPN8 zou5q*jW9Pu6yZSlKX(z;L)Htuv;1}C$_dzW)kjd?>?*ex^uq;|2QLLdo%m|wMoB&i zqO04@yqQ8tu+4yBovZP6ebyr&?WUeJpvYM1E__*U5?|M6JyE}_SYay>s6?O=fl34_ z5vW9<5`jttDiNqepb~*f1pbO5kl=kaKD;*#P>|+r!*=u>A`Rs;i9)?wiC)4+`p^Ab zSG7DIID*#I%j>MGft_e=psFo~%QC9!sHR(Odx3l-WJh_M9>~X;#Rgol*w8CB$ZXpg zY~~0nx7N4T=K-$PXe!E@jpib6qWei>Ua{P4v=sS7Jt`B=!kzql2#p2BnkEDLd-T8< z78qw2`PTZxPg&j7A*+}GtUBRx>z3ALw@H>YyG)vkSRawKyJ$9Ag=aq#Posm9Ubx15 zyVDDo{k^bE^&4ndjvd8EI~_K8@Du%15%re3G?P6x~8_JVs;tmvQ>e$^QDBwp=I;ima}mFu@Fox z+m**9)P}oJTR>-l8Ihh7XzO4lYtVa{FHN2=21m@QVajzFK!D{LKn%XwSScu&S1>zfgUJe*yESf@(&%^Gr!`+i$82qM zV`P~cUZNk=ic^V0rT{SS0BA0a6DuS>$T9F>kammNriFpatvy~0ESqOfXVLF=Fz~&a z-#X-Wi$&%-$0U~%PjSz2w`VMFv8>|Wo_unAn_DJJX9lQ@kdR=S(PGo4){!mIx~IAKAeRQI2C; zvdLyKY4H|qS{y&aSO=BZ8OBAps5%KGl4)(*dJv zxfw&L=;xZtSgXFR9}VLTu?Ay+nJAb+HdWuc*Vw?4IkEcKoaQ~TdSfHY=Um==xv_~W z=EkD&=2&y<`pY)}3n2&6TloGSH{v(QC9fh2y@EXW6I8s6Wb^{E&hxmpz5ju`V}6Pq z-wZP=>MVW;{1V`M02Q&hZI__fwgp6P#@wdZTFGhv?o=2MZ)R%U7DxO;wPt)^OfG&mMcs_e4KF|LP zL*HEI@?3c3`A(nbHO+e(O1nH2&n=6m>G@)SE`{NEK6@uV&tJmCHw~BP!Yj|QsP^1* zJK>&u9=HAJnQqxUP2ZOSb~)c?@5JZ(kCFJyn_a#OuYAAT?|Tprn_y|Dr*hvdo2Tjf z3cxOf;oSGxJMsDcGbDcV0hjN>E8m~=`;G)350!R$D!yAbPt*5Kz%GU1_&$3lKHqHA8+E`{OvK6@uV-~Sg6esfNhE5|dhd_Nxr zcaD!C$;Tt5ot}#Cmd(@jeGM-hOVWQyY)R;_-R0dGp#EV)GVUa02Ff-_OC61>$ySyjZp5MSIoc6lM9~6xZ>L zbBdB|oucF)rzlg>Dawd-igM$MMcHD%NY_xmR>tnS?&hu>~AZlZg=IkvXTFRn;N3@JZRUXm#EUNa1 zma{165v^cR$RlcJQP?BGxj}Vf#3SlpQH@80jem9EU3{w@aX@bUiWp#H!(VM)kHK!; z;aX#aBT{RO;671O%RlXtf7X_N#V3EnmOtf_{~SI;cJN4pJMMVGU8k;Z79%vU376axESJoq-vq4uC@T>CPNz z^63s=J*PY97w0?Qz)>WB>_eTo(6ZT>!!|lBPG*z>dQ&XU7!?b9ip9yMVsSvB*cOMy zNv4wW46r-qk#Dm+;%$~ky3L;NuspJDDUWEI<&kW&Jc4bON3PA{^i;7pJXI{tP8Eyu zPQ~H~P_YSzUFfiHbJ#@=d#=MS78a4KJ-Wn^;t);Ql?h~>s_|q|=VyE~)EN=;>WpaC zvou!lA5uvp*C7>`6TBO5jk!;ASgg*{q{-LSWDOkQQJ^p|Uls!^0K{bAnFAIPb0N_eD0BLlG13+|qV}NA}farh90l+y$0bsr?09F71!woUQk zolCqCV3`6S`cF6jIFl&=%$Ehg3V8W4gL&r0AnktOU=X#9UJNW#7(^dOW$NV%r%;7~ z`LY;T0T@pBFi5*UIv7OFHxyZ>Fo=F#u!wa#-YQE#%8M%O#IM5n`xi)HFWU-Y|iLTDd9^P^J%V7@E>RsaA`vXn-*Isin+ z2Y_V?fatpb@B>=`V7@E>RsaA`vXn;u;$fcdfjSOEY$$B}!Fo?bj1FrxT2Ik9R zUl_SR_G4g~!XWxC47|Ni7?>}MffXza zp7bc~h8+xC_G4g~!XWxC47{&V7?>}MffXzao(w7Nu5d7L*^hx`3WMmoFz|*-VPL*2 z23D{zc#@>Fn{Y62*^hx`3WMmoFeFf?Ffd;h11neEhru!hL-buRc-yXEFkco1D_Ai6Ia8WG?7-l% z9|p@54AFPN;3ESCgL$lBU+{U#V)JRI3oa)D8aDS0?#(@m=i5I3ktQ#26U<30z4VzSY#t3x`W^v4i97;+JbDED%=QR) zA>k45t?~$Xx#JP=8q6c$g`r2lt5uJHm(U&oFX}x4-e!0Nyz%h}cq`@+@aE7X-~sOu z@V3??;Jvm-zy|;x0iQ~E1bkHD5%A%SN5IEP9zonMX!HwWe!<+Lz`O(F)Bg3>CyGPW z^Xsp7wC%<0ZECv$G+&F%({?2|L=c}Z;`_`~zj_1%mrmfD9huG-^ojNzdfu2aQ+mG0 z?a-5H-CUlS$fpc5n;Bc4*rl8KjFDT{)!xDXmL~?LvV|#AUzgLT3T869Jh6RhESpJf z(Wgg^gL-b=*y`2Em8q4hI@fgf=pDUl7L|53l`CW>bk+NaUI+k``fTqTlN-;o#(qrB z$HS2A9HHe%ewcW)Xw%N2L0m6H`NtTai~6(17%St0qPF|Yd$by!P=C<63HgB8_4vXJ zA=C5k@dXQJq3~6>qMf|wtHzb}`O05RR2zMWrYVimhv`O&(pTsh`0vwW6rx%!4Y~j{ zO6#>_;NK;Z4~XO$?O`oSZ)raVovKPzMd^b=pQ^eK{P%_aLL|Xzu1yHNKASt8t-!Ta&7)rBBs7 zh6q0j8l~?-&L6%rO!?njnn&kg1j*>q=29DVQVp=PWG-!#y0HB1fVs34bq)AeFLk@5 zZVt3&&~7hE4b+2?pwW-eV~85HX3)233qY3%?E;O_9&L%Oqe-nsH)uVO+$8iPS}*u} zwF{y7qINN8U0|T7@7BB`z^&3k4+=GfP79q8`d*>82)$kCM}>Y;=x2m}N$4X&|6S-a zLjP0fi$ecL=r4s@9=!oRL~jZWRWTnG+9dQGp-Y6e3tc7jB2bMs3V*54U7*_&d_Nwi zU*aC&)K^N!=?#iwKGk7`MD(6{Yc(#lNa;9TqP3!wkkaju{n|3jvUM)aYC2C!C*~ar zCsDUSN>&fml$Mg!Ly!_!*r^_Z^l>R2r_Z8?Abqum>)tKBhv{)C-4Hc!x% zRY{b1#Eu4;HX;Qf7NE09?ym9cc=eOCR?{gX^ctblpiw$5{7phn2)#q--9qmb`Z=Kw z3H>+F1N1EDBs~urrZbRTFP?E+muDbQ}Iy?|~5|4!la^kwiP!fz3pl2!+)KQKhk1^NRi%4^@F z6dlyQfzim4j|u-V=zW7ehT0dky8=G|f3@}{ZB?KOqdkamPgKyb8KGyi-JqKSdm#(r zsT;r?;rb}%pGI?dPR{U5aDUE0fi0*H@~5y~ne~+L%06GBH$^j;jn;>IS%@{qgSaw( z3HV7c%%{P(!5H($z{}^tVIw`2)i0t!ecy;-7Id>+KdjS6!<^`LWQ3J-LDn#i+IG{J z)XhRh&x>{^sa3XB?jk7gAN(PERlYluOB>hb+u5|GV%I2z0VB6BGd^V|3)lrv-{d6L z`ogQu`;&Q{)P8}sjUCWa1*h@Eq>}xl*rwWEi8xEn%J`;;OORwvy z0iZreX?;kG>j3b z0>4Awm&JIMp`Fj`6Jy!wjhU=&Z+iO**dt&F>C|UemQ<*_ZEb1WhjN&!#^i`@9?D=} zO`E1NX~zo2^{z}lgHhwilx6#7l~#Ono9GBcALs?y5QOu_Aw9hAXLay)0`3z-xqxjr^EKA!ZrZpo0qI6LHv zx5N%51I4W{i?Or>GDUXi+2mp2@(!3CRzq>HkQvKlGXn4dv4MVWhug))>c}<}AdvN(7t)?Zj8?aA#h}P?}0+M+(zfy+4^c zIACN|>f4;mr4czwrqe1Zq5qBIt)yS&Hh0%IRWL?U$*ewzGnpKp_2j82<2xguN+n3C z$g<*(Z4L<3WRjF*#TM4mX?Ym+8zv5y1hClTXO3IOF__Tpd$3(M_o3b{<#BW15GJDY z0HO_tGX?l$4Uv++`Da#xSSRdtqS8G!Z+GjMEP0 zfE-HDhFm(oJ5$(?XJP@Fan!Koe821rqHH@sN1#nJIlVQLx8UqbW~Z#1H=N03CZ;Cj z;UR+wH|!8r2{3GRz;=g|hee5j5EJyNW1+AO6NASwW8*UO{nN;a16h7*Z%yX$K*d1b zwomMD)pO$jJ~B0yw|zMbK>U=q10avJ0hlUa#HpYF5M~x`=HxVPYf6_qBld>zti@xK zM)n)mS~CN=B&(x;9%Gh|J15hyCMwj2Y<`GKR(8?NON|^Ri|M`BqtlZ**$IPrYsT=s z;nGIan6M=(Jxg!J!XXLmhI9sZwBN+~$(z`G6(a>fH`+J4A8xw_=!P7(bIoH60E`aK z&`4leo$u8S8Tm*p6)~63yB)o>KMvd_ONwOYJLNBjBpyr zOi+%%T1YgPHhiwxL)JfPnG_`BpqQ2T*AJ_v#7ubw>x(Swi6R=t$evAuj-roiVY8hE zX#-B5n6q$F-7+dl=k!nq{G1fTIQxuw%Xm+KcEixvQsg!fHTM7ux8gg)_t`>1EwjsE z<;))H!fucKNlM(9V>_i%XhYsjeZYH&w!xnR&`qHg+n-I277aZ(G20A1zJmm>oDyo| zJ+u-L;aVP38QfJy_K7QWTkkLSd96Zbv|eDDYOW|O1Ef*$Ji zL~NfRnc!AupS%t&VRH=-@k|+$*cH8m&Dm?vD!3NsCbZ7FFC%Epqm}({#~&o+81Wrv zSq9fUq&wtli0AA}o@jUkGb)8|i}p?}3(adqJAt;&4B%15v&4Xn1ns7A(1U^#Sy%ea zpw(K^d?RbEXRct5o@DHJ^>9!&>zMIs;ppomBgLz?$~RKHwRj;g%NX(M^vc-sjt{TK znv;$S=*@9w3%n;SGZOsTnExle|9)NM7Ee!zwx^7!ddi5Or_6D3BSmC9WkkVKhR?2Y z7cz{u4D6nI;A^mQ6KBeH(mb_Zv|X6l-qv2UU6`%jdN0~8%tLRz7j3r>Z8v9K7oKip zEYhuc#d-ERnG5`6$x7axk|!F^A8YRLvrdN|KLHG6G@d)wJW8X6pE>(cvk%g&cKASf-wcX1#T!DT7F{C`U~E@iR;uSPVKp|_ODiYlCKvDs)4 zB&IVPiQIqjRoBP9Te~(0^O16rgdU5hYLB4_1jCUBtqm9I4_a+iu9UYkQ zQH^SfD_=m<>_6Il4!@ln4K(e>h77Cy;{E~4Z7j{jBo+T=IgVQCHhf1X@WqcMc8m;; z^nK~}J36aZ^gr_AZ$EvVG3PAYMjBYVchE>-KbkA#6WC8D)Nt90VYNT`#0`6gjRSfj zZ5$Mx>Alt%ON8(oU>5a>qm{CT+gS8rNxD(p!m zPZXkyrPlf_gQ~Gb*hO%QU3emyu*3T_ob=-f$WKT9oQwCbn2D&h_GP>#;T0@DC9Ti> z)pLPW1EvDBc%45!i=|(nV+~%be?3@PBL;LK-lF22vfVR3410$yQr zE8ZPUV)emD$FX)OK&MoepnH)V5?H^m-^h{ZgE4Hg+i|qmn)07Ze;P}V#LU`Lq_KP8 zeVXINY<>_{a2zXd8-K+7@#>W}eTZoue)C?)T5tWSc5t)usYIX>fl34_5vW9<5`jtt zDiNqepb~*f1pcxkaJBXS6s*7KFWb$Eca;cKB2bAyB?6TQR3cD`KqUf|2vj0ai9jU+ Ll?ePbN8tYf`K`d0 diff --git a/Projekt.dia b/Projekt.dia deleted file mode 100644 index c61a45a6700fa0a6fc23cc42cad1ac47ead04724..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3265 zcmZ{l=Q|sU0>+J+2c3QCwPXl=3G$OXHUk2&|WE|Gcihy}49m zvS2*fy&HOL3vkF6&{YO39Ey(x-bo;rqFwHX@2(|tK%JS& z_K9$}Y}Ryzj8A00*q zGmH2}puwHuT|>Cw;c56lHzpWGXkN6PRLwN(6~l;X?=tsD=yW(+t|r$+r}$M!F3Y-L z`RFx3IyE+S0w(tv>f&>=uCi1d*vT_Es;e74tH07*SML@3DiRZ`|9z4F&HUBa=nu0* z!n*yzFyamaPk{YzL{5X$d13CNZ<5YpYrd2*m@T8oaQ?2^-G++b%N;~Y6i;@Z%wVIf zpjvi@HNNckDb|9>UUzQ4W(O~i?hD^X9Vc0a*gmQP*Oye!;_~SgMmdG(&rXPz4QxA5 zm9hFG7UyU^9w6~>erqn!cADXSio0K6%RR)F=UR`7&Vteqw&E+my;f5)%st?I3mDy+|$&=m`#4p(^DtqN0mT*a?N|c-4_D0ze=2R9XAGh#E!;VsnHw3D$D%@2^Xlk8gJ^3 zM$06*K^BgE3ij<;YXR4?c&v`o4CT(6L*KfXDPF2;Y*+2brg67?_4${q&mHz2({F0B zN@!^8bs=?;bipdXI^YuhfWL;n#D$PF5lNYcmxz3$fU`dcxfOZk7!Z6<*zEHy-BQGe zy;=*iLAEw0kNU~}0nC8gVkiKxrTi;HE#Cn^Sv(^Vt6sk6^`UcIe@?oDS=LkVOhP}q zyJyn#!NZAHc=kJ+M)GUxs}J4a?=qjZ1TW=I#F;-DZZW|7lTFX0C$?RTGx8YrdbgB= z^HrS|gUOab!7a?&Z6!IQ_2FHQI)Y$CR=mf+W0jQCdgH1MW-2a)N}MG0?5%_DbTTxC znq(H7#>S3@BnYQ3qHaabE{(9*=L~<6K&3{@S`LzW8Ku&>;2^7qLHU&1KV`>Fh)=9H zl%~hkKgrT855Vel~&YpNvS zf~e%7-1KbVi4KR&$}HT-S+>?1;&|JnZ`+2=+q|a4{%KXV2;Ak^t8|)Kteq51PDXW&ff~pt^N+}X(H>ezlc4^P0l+2> z%oP7>^l}mKpc}ou;1$zZljPOQ)Mv7^hu+{B#|6E<;r8Wy#GZ42rHKdDg{l}B0mooj ze5B0nI5axX`g%GhT$<`!Y?cTup^)xtt$5 z-S@vQUyzqshQvi@Fp73PAegM}&h<@OhB4pvc+kd|Q|Awv5x4RX{t$UE8c2maOpv;_ zR~|nlVT4QiGLC=1+5D(gL=-P6gojVUceFKfg}q^|^)VKjLO!#`m42sT6Nu}$M7ljQ zb)Pb1MYg{8dxN!;OyO3Z{sn>C`XLk%8w%mQs=Tvfw>1HZ31pJA6a0Eb|As34BCO!L z&&r*Qk~hP5oum5gdE-4WdrNTpHj9*d?~ zD)pmAxH`zeGsyh{xDk7gM5>?g7zB z4IP-6S99NHeK>5kUaqTLNM!E(exAJUY47lo(a%PirfRfcu!45mdA2Ud^i+oX{8bMZ zX%EY-r&ikN`xO5I7xI*|PxMFhEB$7Wr{})%F3oP73xYRq|87@%*)>qwKA?st9+`{d z7#vJT+Cyz~FntaOB$4}=zE-Ji=w^%SM1f>LLuJByh z(+Z%%zLN}+W|KdpvS%0pzLiz<{9EAh<&q!@C0wWkaR-=61;(3LZ)hDzA z=kpU%lsECGoC^Wwu*NjYJeW>L-h?WFLGRBVnGR~1AiNTU;x9FC$R#NkM(&x+$G*^o z+0;6Dg1LjbzQe!NrM?39ed;;8#KvG>M3++6EN9uMDO(!%fjLUPEr=ovH) zd!BZ5zlI+T%}H!q8H3vrqtT8ijl=`}xYK2|2z~4{C7lDdFzS&~M~h$R-Q*Hc$QXGSVA`Fflee2#`Blb?t;z zzu2CxP|sJWKA7H@U6bD8%XQL!Jn>yPHfHA8@994TRysIYDVxOmBA*Y2gxSoIZ$oa-9??@Z!R>e%*nAa-6f<&k;j;I4p^ZPntVYR( zW^YCaQy>Mph@h+e1yx3agrD(={mL22c7?8X9k4!aKT9F+cjqgT98j6g!3cG+JTp=5GEvc~s*B zwFmnn(;dQS_3BBn1OLRKFZ#O_ZC-p>?e{(#@7!V?H7y+mfi9#%NYfmQ-`HxrjGTL zLlcS1&MUHn>E0>)sN#_Ft+H07YBq4hWU6<0+P$A}oE!b-#}?}qRlr8TJUtyL$$tRvHe^o# diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index a4ac056fc..52debd736 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -9,7 +9,7 @@ #include #include "hch/CDefHandler.h" #include -#include "client\Graphics.h" +#include "client/Graphics.h" SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given { diff --git a/StartInfo.h b/StartInfo.h index 344b4dad6..012f6784a 100644 --- a/StartInfo.h +++ b/StartInfo.h @@ -21,16 +21,16 @@ struct StartInfo bool human; template void serialize(Handler &h, const int version) { - h && castle; - h && hero; - h && heroPortrait; - h && heroName; - h && bonus; - h && color; - h && serial; - h && handicap; - h && name; - h && human; + h & castle; + h & hero; + h & heroPortrait; + h & heroName; + h & bonus; + h & color; + h & serial; + h & handicap; + h & name; + h & human; } }; si32 difficulty; //0=easy; 4=impossible @@ -44,13 +44,13 @@ struct StartInfo return playerInfos[i]; throw new std::exception("Cannot find info about player"); } - template void serialize(Handler &h, const int version) + template void serialize(Handler &h, const int version) { - h && difficulty; + h & difficulty; h & playerInfos; - h && turnTime; - h && mapname; + h & turnTime; + h & mapname; } }; -#endif \ No newline at end of file +#endif diff --git a/client/Client.cpp b/client/Client.cpp new file mode 100644 index 000000000..b132077a5 --- /dev/null +++ b/client/Client.cpp @@ -0,0 +1,110 @@ +#include "Client.h" +#include "../lib/Connection.h" +#include "../StartInfo.h" +#include "../map.h" +#include "../CGameState.h" +#include "../CGameInfo.h" +#include "../mapHandler.h" +#include "../CCallback.h" +#include "../CPlayerInterface.h" +#include "../CConsoleHandler.h" + +CClient::CClient(void) +{ +} +CClient::CClient(CConnection *con, StartInfo *si) + :serv(con) +{ + timeHandler tmh, pomtime; + CConnection &c(*con); +//////////////////////////////////////////////////// + ui8 pom8; + c << ui8(2) << ui8(1); + c << *si; + c >> pom8; + if(pom8) throw "Server cannot open the map!"; + c << ui8(si->playerInfos.size()); + for(int i=0;iplayerInfos.size();i++) + c << ui8(si->playerInfos[i].color); + + ui32 seed, sum; + std::string mapname; + c >> mapname >> sum >> seed; + THC std::cout<<"\tSending/Getting info to/from the server: "<checksum << std::endl; + + if(mapa->checksum != sum) + exit(-1); + std::cout << "\tUsing random seed: "<state; + gs->scenarioOps = si; + gs->init(si,mapa,seed); + + CGI->mh = new CMapHandler(); + THC std::cout<<"Initializing GameState (together): "<mh->map = mapa; + THC std::cout<<"Creating mapHandler: "<mh->init(); + THC std::cout<<"Initializing mapHandler (together): "<state->scenarioOps->playerInfos.size();i++) //initializing interfaces + { + + if(!CGI->state->scenarioOps->playerInfos[i].human) + CGI->playerint.push_back(static_cast(CAIHandler::getNewAI(new CCallback(CGI->state,CGI->state->scenarioOps->playerInfos[i].color),"EmptyAI.dll"))); + else + { + CGI->state->currentPlayer=CGI->state->scenarioOps->playerInfos[i].color; + CGI->playerint.push_back(new CPlayerInterface(CGI->state->scenarioOps->playerInfos[i].color,i)); + ((CPlayerInterface*)(CGI->playerint[i]))->init(new CCallback(CGI->state,CGI->state->scenarioOps->playerInfos[i].color)); + } + } + CGI->consoleh->cb = new CCallback(CGI->state,-1); +} +CClient::~CClient(void) +{ +} +void CClient::process(int what) +{ + switch (what) + { + case 100: //one of our interaces has turn + ui8 player; + *serv >> player;//who? + CGI->playerint[gs->players[player].serial]->yourTurn(); + *serv << ui16(100); //report that we ended turn + break; + default: + throw std::exception("Not supported server message!"); + break; + } +} +void CClient::run() +{ + try + { + ui16 typ; + while(1) + { + *serv >> typ; + process(typ); + } + } HANDLE_EXCEPTION + //while(1) //main game loop, one execution per turn + //{ + // CGI->consoleh->cb->newTurn(); + // for (int i=0;iplayerint.size();i++) + // { + // CGI->state->currentPlayer=CGI->playerint[i]->playerID; + // try + // { + // CGI->playerint[i]->yourTurn(); + // }HANDLE_EXCEPTION + // } + //} +} \ No newline at end of file diff --git a/client/Client.h b/client/Client.h new file mode 100644 index 000000000..962f77207 --- /dev/null +++ b/client/Client.h @@ -0,0 +1,19 @@ +#pragma once +#include "../global.h" +struct StartInfo; +class CGameState; +class CGameInterface; +class CConnection; +class CClient +{ + CGameState *gs; + std::map playerint; + CConnection *serv; +public: + CClient(void); + CClient(CConnection *con, StartInfo *si); + ~CClient(void); + + void process(int what); + void run(); +}; diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index cbeb50a17..44ac9a49c 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -124,8 +124,9 @@ BasicRuntimeChecks="0" RuntimeLibrary="2" EnableFunctionLevelLinking="false" + EnableEnhancedInstructionSet="0" WarningLevel="3" - DebugInformationFormat="3" + DebugInformationFormat="0" /> + + @@ -381,138 +387,6 @@ RelativePath="..\SDL_framerate.cpp" > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -692,12 +570,6 @@ > - - diff --git a/int3.h b/int3.h index d8af5f5e4..722546aea 100644 --- a/int3.h +++ b/int3.h @@ -76,7 +76,7 @@ inline std::istream & operator>>(std::istream & str, int3 & dest) str>>dest.x>>dest.y>>dest.z; return str; } -inline std::ostream & operator<<(std::ostream & str, int3 & sth) +inline std::ostream & operator<<(std::ostream & str, const int3 & sth) { return str<>(CConnection &c, std::string &data) +//{ +// boost::uint32_t length; +// c >> length; +// data.resize(length); +// c.read((void*)data.c_str(),length); +// return c; +//} +//CConnection & operator<<(CConnection &c, const char * &data) +//{ +// boost::uint32_t length = strlen(data); +// c << length; +// c.write(data,length); +// return c; +//} +//CConnection & operator>>(CConnection &c, char * &data) +//{ +// boost::uint32_t length; +// c >> length; +// std::cout <<"Alokujemy " < > * Socket, std::string Name, std::ostream & Out ) - :socket(Socket),io_service(Socket->io_service()), out(Out), name(Name), send(this), rec(this) + :socket(Socket),io_service(&Socket->io_service()), out(Out), name(Name)//, send(this), rec(this) { init(); } CConnection::CConnection(boost::asio::basic_socket_acceptor > * acceptor, boost::asio::io_service *Io_service, std::string Name, std::ostream & Out) -: out(Out), name(Name), send(this), rec(this) +: out(Out), name(Name)//, send(this), rec(this) { system::error_code error = asio::error::host_not_found; socket = new tcp::socket(*io_service); @@ -70,13 +102,14 @@ int CConnection::write(const void * data, unsigned size) } int CConnection::read(void * data, unsigned size) { + LOG("odbieram dane o rozmiarze " << size << std::endl); int ret = asio::read(*socket,asio::mutable_buffers_1(asio::mutable_buffer(data,size))); return ret; } CConnection::~CConnection(void) { - delete io_service; if(socket) socket->close(); delete socket; + delete io_service; } diff --git a/lib/Connection.h b/lib/Connection.h index 0a1a4f68b..849caef85 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -3,9 +3,32 @@ #include #include #include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + const int version = 63; class CConnection; +namespace mpl = boost::mpl; + namespace boost { namespace asio @@ -24,48 +47,248 @@ namespace boost template class basic_socket_acceptor; } + class mutex; }; -class CSender +enum SerializationLvl +{ + Wrong=0, + Primitive, + Serializable +}; + +template +struct SerializationLevel +{ + typedef mpl::integral_c_tag tag; + typedef + typename mpl::eval_if< + boost::is_fundamental, + mpl::int_, + //else + typename mpl::eval_if< + boost::is_class, + mpl::int_, + //else + typename mpl::eval_if< + boost::is_array, + mpl::int_, + //else + typename mpl::eval_if< + boost::is_enum, + mpl::int_, + //else + mpl::int_ + > + > + > + >::type type; + static const int value = SerializationLevel::type::value; +}; + +template class DLL_EXPORT COSer { public: - CConnection* c; - CSender(CConnection* C):c(C){}; - template CSender & operator&&(T &data) //send built-in type + COSer(){}; + Serializer * This() { - *c << data; - return *this; + return static_cast(this); } - template CSender & operator&(T &data) //send serializable type + + template + Serializer & operator<<(const T &t) { - *c < data; - return *this; + this->This()->save(t); + return * this->This(); + } + + template + Serializer & operator&(T & t){ + return * this->This() << t; } }; -class CReceiver +template class DLL_EXPORT CISer { public: - CConnection *c; - CReceiver(CConnection* C):c(C){}; - template CReceiver & operator&&(T &data) //get built-in type + CISer(){}; + Serializer * This() { - *c >> data; - return *this; + return static_cast(this); } - template CReceiver & operator&(T &data) //get serializable type + + template + Serializer & operator>>(T &t) { - *c > data; - return *this; + this->This()->load(t); + return * this->This(); + } + + template + Serializer & operator&(T & t){ + return * this->This() >> t; } }; + +template +struct SavePrimitive +{ + static void invoke(Ser &s, const T &data) + { + s.savePrimitive(data); + } +}; +template +struct SaveSerializable +{ + static void invoke(Ser &s, const T &data) + { + s.saveSerializable(data); + } +}; +template +struct LoadPrimitive +{ + static void invoke(Ser &s, T &data) + { + s.loadPrimitive(data); + } +}; +template +struct LoadSerializable +{ + static void invoke(Ser &s, T &data) + { + s.loadSerializable(data); + } +}; + +template +struct SaveWrong +{ + static void invoke(Ser &s, const T &data) + { + throw std::exception("Wrong save serialization call!"); + } +}; +template +struct LoadWrong +{ + static void invoke(Ser &s, const T &data) + { + throw std::exception("Wrong load serialization call!"); + } +}; + + class DLL_EXPORT CConnection + :public CISer, public COSer { + + std::ostream &out; CConnection(void); void init(); + boost::mutex *mx; public: - CSender send; - CReceiver rec; + + template + void savePrimitive(const T &data) + { + write(&data,sizeof(data)); + } + template + void loadPrimitive(T &data) + { + read(&data,sizeof(data)); + } + + template + void saveSerializable(const T &data) + { + const_cast(data).serialize(*static_cast(this),version); + } + template + void loadSerializable(T &data) + { + data.serialize(*static_cast(this),version); + } + template <> + void saveSerializable(const std::string &data) + { + *this << ui32(data.size()); + write(data.c_str(),data.size()); + } + template <> + void loadSerializable(std::string &data) + { + ui32 l; + *this >> l; + data.resize(l); + read((void*)data.c_str(),l); + } + template + void saveSerializable(const std::vector &data) + { + boost::uint32_t length = data.size(); + *this << length; + for(ui32 i=0;i + void loadSerializable(std::vector &data) + { + boost::uint32_t length; + *this >> length; + data.resize(length); + for(ui32 i=0;i> data[i]; + } + //template + //void saveSerializable(T &data) + //{ + // data.serialize(*static_cast(this),version); + //} + //template + //void loadSerializable(T &data) + //{ + // data.serialize(*static_cast(this),version); + //} + + template + void save(const T &data) + { + typedef + //if + typename mpl::eval_if< mpl::equal_to,mpl::int_ >, + mpl::identity >, + //else if + typename mpl::eval_if,mpl::int_ >, + mpl::identity >, + //else + mpl::identity > + > + >::type typex; + typex::invoke(*this, data); + } + template + void load(T &data) + { + typedef + //if + typename mpl::eval_if< mpl::equal_to,mpl::int_ >, + mpl::identity >, + //else if + typename mpl::eval_if,mpl::int_ >, + mpl::identity >, + //else + mpl::identity > + > + >::type typex; + typex::invoke(*this, data); + } + + //CSender send; + //CReceiver rec; boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > * socket; bool logging; bool connected; @@ -88,56 +311,28 @@ public: }; -template CConnection & operator<<(CConnection &c, const T &data); -template CConnection & operator>>(CConnection &c, T &data); -CConnection & operator<<(CConnection &c, const std::string &data) -{ - boost::uint32_t length = data.size(); - c << length; - c.write(data.c_str(),length); - return c; -} -CConnection & operator>>(CConnection &c, std::string &data) -{ - boost::uint32_t length; - c >> length; - data.resize(length); - c.read((void*)data.c_str(),length); - return c; -} -CConnection & operator<<(CConnection &c, const char * &data) -{ - boost::uint32_t length = strlen(data); - c << length; - c.write(data,length); - return c; -} -CConnection & operator>>(CConnection &c, char * &data) -{ - boost::uint32_t length; - c >> length; - std::cout <<"Alokujemy " < CConnection & operator<<(CConnection &c, std::vector &data) -{ - boost::uint32_t length = data.size(); - c << length; - for(ui32 i=0;i CConnection & operator>>(CConnection &c, std::vector &data) -{ - boost::uint32_t length; - c >> length; - data.resize(length); - for(ui32 i=0;i> data[i]; - return c; -} +//DLL_EXPORT CConnection & operator<<(CConnection &c, const std::string &data); +//DLL_EXPORT CConnection & operator>>(CConnection &c, std::string &data); +//DLL_EXPORT CConnection & operator<<(CConnection &c, const char * &data); +//DLL_EXPORT CConnection & operator>>(CConnection &c, char * &data); +// +//template CConnection & operator<<(CConnection &c, std::vector &data) +//{ +// boost::uint32_t length = data.size(); +// c << length; +// for(ui32 i=0;i CConnection & operator>>(CConnection &c, std::vector &data) +//{ +// boost::uint32_t length; +// c >> length; +// data.resize(length); +// for(ui32 i=0;i> data[i]; +// return c; +//} //template CConnection & operator<<(CConnection &c, std::set &data) //{ // boost::uint32_t length = data.size(); @@ -159,40 +354,61 @@ template CConnection & operator>>(CConnection &c, std::vector & // } // return c; //} -template CConnection & operator<<(CConnection &c, const T &data) -{ - c.write(&data,sizeof(data)); - return c; -} -template CConnection & operator>>(CConnection &c, T &data) -{ - c.read(&data,sizeof(data)); - return c; -} -template CConnection & operator<(CConnection &c, std::vector &data) -{ - boost::uint32_t length = data.size(); - c << length; - for(ui32 i=0;i CConnection & operator>(CConnection &c, std::vector &data) -{ - boost::uint32_t length; - c >> length; - data.resize(length); - for(ui32 i=0;i CConnection & operator<(CConnection &c, T &data) -{ - data.serialize(c.send,version); - return c; -} -template CConnection & operator>(CConnection &c, T &data) -{ - data.serialize(c.rec,version); - return c; -} \ No newline at end of file +//template CConnection & operator<<(CConnection &c, const T &data) +//{ +// c.write(&data,sizeof(data)); +// return c; +//} +//template CConnection & operator>>(CConnection &c, T &data) +//{ +// c.read(&data,sizeof(data)); +// return c; +//} +//template CConnection & operator<(CConnection &c, std::vector &data) +//{ +// boost::uint32_t length = data.size(); +// c << length; +// for(ui32 i=0;i CConnection & operator>(CConnection &c, std::vector &data) +//{ +// boost::uint32_t length; +// c >> length; +// data.resize(length); +// for(ui32 i=0;i CConnection & operator<(CConnection &c, std::set &data) +//{ +// boost::uint32_t length = data.size(); +// c << length; +// for(std::set::iterator i=data.begin();i!=data.end();i++) +// i->serialize(c.send,version); +// return c; +//} +//template CConnection & operator>(CConnection &c, std::set &data) +//{ +// boost::uint32_t length; +// c >> length; +// data.resize(length); +// T pom; +// for(int i=0;i CConnection & operator<(CConnection &c, T &data) +//{ +// data.serialize(c.send,version); +// return c; +//} +//template CConnection & operator>(CConnection &c, T &data) +//{ +// data.serialize(c.rec,version); +// return c; +//} diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index 3f125b32b..f1f7bb40e 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -1,14 +1,50 @@ #define VCMI_DLL #include "../global.h" #include "VCMI_Lib.h" +#include "../hch/CArtHandler.h" +#include "../hch/CCreatureHandler.h" +#include "../hch/CDefObjInfoHandler.h" +#include "../hch/CHeroHandler.h" +#include "../hch/CObjectHandler.h" +#include "../hch/CTownHandler.h" class CLodHandler; LibClasses * VLC = NULL; CLodHandler * bitmaph=NULL; DLL_EXPORT void initDLL(CLodHandler *b) { + timeHandler pomtime; bitmaph=b; VLC = new LibClasses; + + CHeroHandler * heroh = new CHeroHandler; + heroh->loadHeroes(); + heroh->loadPortraits(); + VLC->heroh = heroh; + THC std::cout<<"\tHero handler: "<loadArtifacts(); + VLC->arth = arth; + THC std::cout<<"\tArtifact handler: "<loadCreatures(); + VLC->creh = creh; + THC std::cout<<"\tCreature handler: "<townh = new CTownHandler; + VLC->townh->loadNames(); + THC std::cout<<"\tTown handler: "<loadObjects(); + VLC->objh = objh; + THC std::cout<<"\tObject handler: "<dobjinfo = new CDefObjInfoHandler; + VLC->dobjinfo->load(); + THC std::cout<<"\tDef information handler: "< + + diff --git a/map.cpp b/map.cpp index 461867fcc..2b5b3fb72 100644 --- a/map.cpp +++ b/map.cpp @@ -4,6 +4,8 @@ #include "hch/CObjectHandler.h" #include "hch/CDefObjInfoHandler.h" #include "lib/VCMI_Lib.h" +#include +#include std::set convertBuildings(const std::set h3m, int castleID) { std::map mapa; @@ -440,7 +442,7 @@ CMapHeader::CMapHeader(unsigned char *map) } } } -Mapa::Mapa(unsigned char * bufor) +void Mapa::initFromBytes(unsigned char * bufor) { THC timeHandler th; th.getDif(); @@ -2288,6 +2290,29 @@ borderguardend: //map readed, bufor no longer needed delete[] bufor; bufor=NULL; } + +Mapa::Mapa(std::string filename) +{ + std::cout<<"Opening map file: "< mapstr; int pom; + while((pom=gzgetc(map))>=0) + { + mapstr.push_back(pom); + } + gzclose(map); + unsigned char *initTable = new unsigned char[mapstr.size()]; + for(int ss=0; ss heroes; std::vector towns; - Mapa(unsigned char * bufor); //creates map from decompressed .h3m data + void initFromBytes(unsigned char * bufor); //creates map from decompressed .h3m data + Mapa(std::string filename); //creates map structure from .h3m file CGHeroInstance * getHero(int ID, int mode=0); }; #endif //MAPD_H diff --git a/mapHandler.cpp b/mapHandler.cpp index e04d89f6d..9df769597 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -10,11 +10,12 @@ #include "CLua.h" #include "hch/CHeroHandler.h" #include "hch/CTownHandler.h" -#include "client\Graphics.h" +#include "client/Graphics.h" #include #include #include "hch/CObjectHandler.h" #include "map.h" +#include "hch/CDefHandler.h" extern SDL_Surface * screen; std::string nameFromType (EterrainType typ) { @@ -567,6 +568,8 @@ void CMapHandler::init() { timeHandler th; th.getDif(); + loadDefs(); + THC std::cout<<"Reading terrain defs: "<defy.begin(),map->defy.end(),processDef); //load h3m defs std::for_each(map->defs.begin(),map->defs.end(),processDef); //and non-h3m defs THC std::cout<<"\tUnpacking and handling defs: "< > > & visibilityMap, int lvl) { int size = visibilityMap.size()-1; //is tile visible. arrangement: (like num keyboard) @@ -1325,12 +1317,6 @@ bool CMapHandler::hideObject(CGObjectInstance *obj) } //for(int fx=0; fxourImages[0].bitmap->w/32; ++fx) return true; } - -std::string CMapHandler::getRandomizedDefName(CGDefInfo *di, CGObjectInstance * obj) -{ - return std::string(); -} - bool CMapHandler::removeObject(CGObjectInstance *obj) { hideObject(obj); diff --git a/mapHandler.h b/mapHandler.h index ccb68d1a3..699daf1f9 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -2,8 +2,6 @@ #define MAPHANDLER_H #include "global.h" #include -#include "hch/CDefHandler.h" -#include #include #include const int Woff = 12; //width of map's frame @@ -13,7 +11,8 @@ class CGObjectInstance; class CGHeroInstance; struct Mapa; class CGDefInfo; - +class CGObjectInstance; +class CDefHandler; struct TerrainTile2 { int3 pos; //this tile's position @@ -81,8 +80,6 @@ public: CDefHandler * fullHide; CDefHandler * partialHide; - std::vector< std::vector< std::vector > > visibility; //true means that pointed place is visible //not used now - //std::vector< std::vector > undVisibility; //true means that pointed place is visible std::vector roadDefs; std::vector staticRiverDefs; std::vector defs; @@ -92,8 +89,6 @@ public: std::vector > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile void loadDefs(); - char & visAccess(int x, int y); - char & undVisAccess(int x, int y); SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector< std::vector > > & visibilityMap, int lvl); int getCost(int3 & a, int3 & b, const CGHeroInstance * hero); @@ -107,20 +102,13 @@ public: bool recalculateHideVisPos(int3& pos); //recalculates position for hidden / visitable positions bool recalculateHideVisPosUnderObj(CGObjectInstance * obj, bool withBorder = false); //recalculates position for hidden / visitable positions under given object void init(); - int pickHero(int owner); - std::pair pickObject(CGObjectInstance *obj); - void randomizeObject(CGObjectInstance *cur); void calculateBlockedPos(); void initObjectRects(); void borderAndTerrainBitmapInit(); void roadsRiverTerrainInit(); void prepareFOWDefs(); - void randomizeObjects(); SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector > > * visibilityMap = NULL, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it - SDL_Surface * terrBitmap(int x, int y); - SDL_Surface * undTerrBitmap(int x, int y); - std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper static unsigned char getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b] diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index a8c49efc0..acfd0a4a4 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1,9 +1,154 @@ +#include +#include +#include +#include #include "CGameHandler.h" +#include "../CGameState.h" +#include "../StartInfo.h" +#include "../map.h" +#include "../lib/NetPacks.h" +#include "../lib/Connection.h" +#include "../CLua.h" +#include "../hch/CObjectHandler.h" +#include "../hch/CTownHandler.h" +#include "../hch/CHeroHandler.h" + +bool makingTurn; +boost::condition_variable cTurn; +boost::mutex mTurn; +boost::shared_mutex gsm; + +void CGameHandler::handleConnection(std::set players, CConnection &c) +{ + ui16 pom; + while(1) + { + c >> pom; + switch(pom) + { + case 100: //my interface end its turn + mTurn.lock(); + makingTurn = false; + mTurn.unlock(); + cTurn.notify_all(); + break; + default: + throw std::exception("Not supported client message!"); + break; + } + } +} CGameHandler::CGameHandler(void) { + gs = NULL; } CGameHandler::~CGameHandler(void) { + delete gs; } +void CGameHandler::init(StartInfo *si, int Seed) +{ + + Mapa *map = new Mapa(si->mapname); + gs = new CGameState(); + gs->init(si,map,Seed); +} +int lowestSpeed(CGHeroInstance * chi) +{ + std::map >::iterator i = chi->army.slots.begin(); + int ret = (*i++).second.first->speed; + for (;i!=chi->army.slots.end();i++) + { + ret = min(ret,(*i).second.first->speed); + } + return ret; +} +int valMovePoints(CGHeroInstance * chi) +{ + int ret = 1270+70*lowestSpeed(chi); + if (ret>2000) + ret=2000; + + //TODO: additional bonuses (but they aren't currently stored in chi) + + return ret; +} +void CGameHandler::newTurn() +{ + //std::map::iterator i = gs->players.begin() ; + gs->day++; + for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + { + //handle heroes///////////////////////////// + for (unsigned j=0;j<(*i).second.heroes.size();j++) + { + (*i).second.heroes[j]->movement = valMovePoints((*i).second.heroes[j]); + } + + + //handle towns///////////////////////////// + for(unsigned j=0;jsecond.towns.size();j++) + { + i->second.towns[j]->builded=0; + if(gs->getDate(1)==1) //first day of week + { + for(int k=0;ksecond.towns[j]->creatureDwelling(k))//there is dwelling (k-level) + i->second.towns[j]->strInfo.creatures[k]+=i->second.towns[j]->creatureGrowth(k); + } + } + if((gs->day>1) && i->firstsecond.resources[6]+=i->second.towns[j]->dailyIncome(); + } + } + for (std::set::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++) + { + (*i)->newTurn(); + } +} +void CGameHandler::run() +{ + BOOST_FOREACH(CConnection *cc, conns) + {//init conn. + ui8 quantity, pom; + //ui32 seed; + (*cc) << gs->scenarioOps->mapname;// << gs->map->checksum << seed; + (*cc) >> quantity; + for(int i=0;i> pom; + gsm.lock(); + connections[pom] = cc; + gsm.unlock(); + } + } + + for(std::set::iterator i = conns.begin(); i!=conns.end();i++) + { + std::set pom; + for(std::map::iterator j = connections.begin(); j!=connections.end();j++) + if(j->second == *i) + pom.insert(j->first); + + boost::thread(boost::bind(&CGameHandler::handleConnection,this,pom,boost::ref(**i))); + } + while (1) + { + for(std::map::iterator i = gs->players.begin(); i != gs->players.end(); i++) + { + if((i->second.towns.size()==0 && i->second.heroes.size()==0) || i->second.color<0) continue; //players has not towns/castle - loser + makingTurn = true; + *connections[i->first] << ui16(100) << i->first; + //wait till turn is done + boost::unique_lock lock(mTurn); + while(makingTurn) + { + cTurn.wait(lock); + } + + } + } +} \ No newline at end of file diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 5d4cdde7e..726d369c0 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -1,8 +1,23 @@ #pragma once - +#include "../global.h" +#include +class CVCMIServer; +class CGameState; +class CConnection; +struct StartInfo; class CGameHandler { + CGameState *gs; + CVCMIServer *s; + std::map connections; + std::set conns; public: CGameHandler(void); ~CGameHandler(void); + void init(StartInfo *si, int Seed); + void handleConnection(std::set players, CConnection &c); + void run(); + void newTurn(); + + friend class CVCMIServer; }; diff --git a/server/VCMI_server.vcproj b/server/VCMI_server.vcproj index 616074d21..dc7b5025f 100644 --- a/server/VCMI_server.vcproj +++ b/server/VCMI_server.vcproj @@ -112,10 +112,15 @@ Name="VCCLCompilerTool" Optimization="2" EnableIntrinsicFunctions="true" + FavorSizeOrSpeed="1" + OmitFramePointers="true" + EnableFiberSafeOptimizations="true" + StringPooling="true" RuntimeLibrary="2" - EnableFunctionLevelLinking="true" + EnableFunctionLevelLinking="false" WarningLevel="3" - DebugInformationFormat="3" + DebugInformationFormat="0" + DisableSpecificWarnings="4251" /> + + #include -#include #include #include "../global.h" #include "../lib/Connection.h" -#include "../CGameState.h" #include "zlib.h" -#include +#include +#include "CVCMIServer.h" #include #include #include "../StartInfo.h" +#include "../map.h" +#include "../hch/CLodHandler.h" +#include "../lib/VCMI_Lib.h" +#include "CGameHandler.h" std::string NAME = NAME_VER + std::string(" (server)"); using boost::asio::ip::tcp; using namespace boost; using namespace boost::asio; using namespace boost::asio::ip; -mutex smx1; -class CVCMIServer + + +CVCMIServer::CVCMIServer() +: io(new io_service()), acceptor(new tcp::acceptor(*io, tcp::endpoint(tcp::v4(), 3030))) { - CGameState *gs; - tcp::acceptor acceptor; - std::map connections; - std::set conns; - ui32 seed; -public: - CVCMIServer(io_service& io_service) - : acceptor(io_service, tcp::endpoint(tcp::v4(), 3030)) +} +CVCMIServer::~CVCMIServer() +{ + delete io; + delete acceptor; +} + +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 + int problem; +#ifdef _MSC_VER + FILE *f; + problem = fopen_s(&f,si->mapname.c_str(),"r"); +#else + FILE * f = fopen(si->mapname.c_str(),"r"); + problem = !f; +#endif + if(problem) { - start(); + c << ui8(problem); //WRONG! + return; } - void setUpConnection(CConnection *c, std::string mapname, si32 checksum) + else { - ui8 quantity, pom; - (*c) << mapname << checksum << seed; - (*c) >> quantity; - for(int i=0;i> pom; - smx1.lock(); - connections[pom] = c; - conns.insert(c); - smx1.unlock(); - } + fclose(f); + c << ui8(0); //OK! } - void newGame(CConnection &c) + + gh.init(si,rand()); + + CConnection* cc; //tcp::socket * ss; + for(int i=0; i> clients; - c >> mapname; - //getting map - gzFile map = gzopen(mapname.c_str(),"rb"); - if(!map){ c << int8_t(1); return; } - std::vector mapstr; int pom; - while((pom=gzgetc(map))>=0) + if(!i) { - mapstr.push_back(pom); + cc=&c; } - gzclose(map); - //map is decompressed - c << int8_t(0); //OK! - gs = new CGameState(); - gs->scenarioOps = si; - c > *si; //get start options - boost::crc_32_type result; - result.process_bytes(&(*mapstr.begin()),mapstr.size()); - int checksum = result.checksum(); - std::cout << "Checksum:" << checksum << std::endl; - CConnection* cc; tcp::socket * ss; - for(int i=0; iio_service()); + acceptor->accept(*s,error); + if(error) //retry { - cc=&c; + std::cout<<"Cannot establish connection - retrying..." << std::endl; + i--; + continue; } - else - { - tcp::socket * s = new tcp::socket(acceptor.io_service()); - acceptor.accept(*s,error); - if(error) //retry - { - std::cout<<"Cannot establish connection - retrying..." << std::endl; - i--; - continue; - } - cc = new CConnection(s,NAME,std::cout); - } - setUpConnection(cc,mapname,checksum); - } - //TODO: wait for other connections + cc = new CConnection(s,NAME,std::cout); + } + gh.conns.insert(cc); } - void start() + + gh.run(); +} +void CVCMIServer::start() +{ + boost::system::error_code error; + std::cout<<"Listening for connections at port " << acceptor->local_endpoint().port() << std::endl; + tcp::socket * s = new tcp::socket(acceptor->io_service()); + acceptor->accept(*s,error); + if (error) { - srand ( time(NULL) ); - seed = rand(); - boost::system::error_code error; - std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl; - tcp::socket * s = new tcp::socket(acceptor.io_service()); - acceptor.accept(*s,error); - if (error) + std::cout<<"Got connection but there is an error " << std::endl; + return; + } + CConnection connection(s,NAME,std::cout); + std::cout<<"Got connection!" << std::endl; + while(1) + { + uint8_t mode; + connection >> mode; + switch (mode) { - std::cout<<"Got connection but there is an error " << std::endl; + case 0: + connection.socket->close(); + exit(0); + break; + case 1: + connection.socket->close(); return; - } - CConnection connection(s,NAME,std::cout); - std::cout<<"Got connection!" << std::endl; - while(1) - { - uint8_t mode; - connection >> mode; - switch (mode) - { - case 0: - connection.socket->close(); - exit(0); - break; - case 1: - connection.socket->close(); - return; - break; - case 2: - newGame(connection); - break; - } + break; + case 2: + newGame(connection); + break; } } -}; +} int _tmain(int argc, _TCHAR* argv[]) { - try - { - io_service io_service; - CVCMIServer server(io_service); - while(1) - server.start(); - io_service.run(); - } - catch (std::exception& e) - { - std::cerr << e.what() << std::endl; - } - + CLodHandler h3bmp; + h3bmp.init("Data\\H3bitmap.lod","Data"); + initDLL(&h3bmp); + srand ( (unsigned int)time(NULL) ); + try + { + io_service io_service; + CVCMIServer server; + while(1) + server.start(); + io_service.run(); + } + catch (std::exception& e) + { + std::cerr << e.what() << std::endl; + } + catch(...) + { + ; + } return 0; } diff --git a/tools/Defopruj/AssemblyInfo.cpp b/tools/Defopruj/AssemblyInfo.cpp deleted file mode 100644 index 0557e2815..000000000 --- a/tools/Defopruj/AssemblyInfo.cpp +++ /dev/null @@ -1,38 +0,0 @@ -using namespace System; -using namespace System::Reflection; -using namespace System::Runtime::CompilerServices; -using namespace System::Runtime::InteropServices; -using namespace System::Security::Permissions; - -// -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -// -[assembly:AssemblyTitleAttribute("wyprujdef")]; -[assembly:AssemblyDescriptionAttribute("Cudowne narzędzie pozwalające w szybkimczasie wypruć defy.")]; -[assembly:AssemblyConfigurationAttribute("")]; -[assembly:AssemblyCompanyAttribute("VCMI Team")]; -[assembly:AssemblyProductAttribute("wyprujdef")]; -[assembly:AssemblyCopyrightAttribute("Copyright (c) 2008")]; -[assembly:AssemblyTrademarkAttribute("")]; -[assembly:AssemblyCultureAttribute("")]; - -// -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the value or you can default the Revision and Build Numbers -// by using the '*' as shown below: - -[assembly:AssemblyVersionAttribute("1.0.*")]; - -[assembly:ComVisible(false)]; - -[assembly:CLSCompliantAttribute(true)]; - -[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/tools/Defopruj/CDefHandler.cpp b/tools/Defopruj/CDefHandler.cpp deleted file mode 100644 index bf1376c190dadb3f5022608bc99b352eff75f63b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 26988 zcmeHQYi}FJ6`ijv(Eq?RXf0WmoLEVl){+6smQo{*8%PO)Kn)D*Y09!BNOUaQNPl|U zbN2G^&dkm(DUq&Ylpti1yEAv@z8`a!{?ETZ4ZUy@cEfRa752h@=!QRp2jL+;9fZG! zXSlbAd;8%$EQRN|_xtd>P@1!aIgi6rKzoT#O*CHoW&5c=swA5Yi%ETBQ>@7qzgFw~0z7)4XE&^cZ^L(> zFR>@p&%@vFI>WnRGFMS&uey4gP^ugLg!!kyp`YPe=2{NdX5Io_UIC}$u!R-hVh6Xv z7l0>vTn*M!Q0VgsA?!{8!kvlsa5>TJHxtc%3JF>UggX=PU>6*m48n7)KdBrLi|b3$ z9`vD)KS||eQk6r?u{(esokN@E23kiuvKl^v7WBeO_^Nte2nz!}qqdv&ba8hD^T@R? z!!}0$Jk%T;u>}31MZJJ#%nf;JR-jq8%6B-QmQglsV_==lPCW@f!0tXCuD=<64C|FO zq%GOU4w}Y29&6kQaPEf<&}kp9N3hk0LzuMRuW;3@#whIm)!TPl4Y)bjIW<_PrLP&?hq@IRRcTG17P@Iwi{oC0Ne0@%aJ9av>yOVTXS`|y3vXj zfjqRh$Ko^_DOz&x7C}%m;%KXjn1ym7+i-%FUgJvh47Xuilk*l4voQ`a%FPXTw**X| z4p!r=TM1OgGNd>qi_|<1Z!ktXCS=0Bz<%~YuS3Z2XAKa@uf1w+H{8a{xYNZf#*ego zy8}s&X=Aof>(Guc2I4y0MHerFWpODZHQF0;zYm^?=Hu^j2eS{8UA_j+)DH6M&2ZO@ zaCf1#^nS$LR+5FYU5iVvupjF9A>Q{vgDz&8JZ)n>sbX?KpCo)JizbD(LbsCRmsph? z=w_G+`#I1>ux|nj?T0cRuVl2#DQ9-03)xfjOub-??lPZJlvxNRM7GQBrdFT4b9ph! z&|}-!hwy0|;d|gjxwN~&=1GMucXbS{ItOmlSc_H6O0MFYASpin5u^4h?oR_6BYtx3 zIUr5~&*GFza7X)fo8$II`h6V=h%=0bE@7FR#wDNBAI436c%?gtivEn9(R-AA&soI< zdUDD;{Y@X1Zz*gJs3J+@9YXNfVkHqvS!IY6heYG>#8phyHVRdMAUqI`9)SJrgyZ@nYBb6BW8y|9f$YZV?b0DQ& zX=m?-&|-M<-7f~5eF3P90PbR!rZub+xUJmA^`9{|)eT{9OM z`>N|c@j4n}PR-ndZMcCoZ(x55 zNkt>aT6(P7fn{d-?#kHr3fMou`l_Kas^z!Ch)cSX=4VC|)?NF+(JG1bt(3Xg!uf2% zRd&%tQC2pb?k)ii#pUS{`+A99BJn)RZD@W=_oPcB%*@t~@L2<~7fwO!g=tzqS0aGxQ_It8uam;du4T z!lQy*TUf;qTtZeP=>S%POY) zTb>YVO6luH`?BzH_MrXFG9v29JMhV=l*f~!^S8+}qLNI0F`@J*dhS$}R<{MStV)#8 z`z)(sCO^xnK4exk>daN~x%uw&M9wp^_I#?_a4yVqBA%A8HoT8am32k0-p8l*C%6;m zVmqk+_W_kBLFri?D>?EqJiTTm+5c#bm|yZ#8F$KiO=1P-E>0Yb-qC{RaTCh?0@+{x#Or}$(fOd>)yRd>h zQSIU1)Cy|X#!-`0-@q%_l#HMvAVR{riZ5&T`{ZzxdGB_f>6L(nf9^*0N3S&n`T^A9Y8@ML;kFoXvMtqBF=cw0H#t2~( zpR8jezw?|9CSaE##9ivuJxB~;?rw* zwtei?dX$877tq;(dWaDh@BrNkYxV`Q&xr9ceKNa~*poxLA42{Khu!O1=?Sh};z~^6 zoIkdQ`xQRY1J`ESs#LN!Fp`wk*f!1FO7^9`9^#nZ$tj>XfnI!^b!Y*;$6B-i4+pz5 z*&$7IGDNBvWgI`ljk3ZM9`+s?6s_uW=nqRWUhk6F26m4C(X@*vaB(e1kYxj@6L*3?L>a+Ettk3(Oc0ewfFk4>k{prW^$;p_DlnAEb*>`(}q0l zU6*XwH1=G#bkl%ZwyXxZBrS`T-j}=p^PX;H2XhN9ZE3R0>1ruI^7ZO>>vXa8%u3Xs z@?o5@GqgzjyafB2?!l!^d$)1y(`0TZ%EY@#N7kQvu$cxYzpL{c?S?1Z+}E3Ip9cd! zC0o-DlRXp5RTrSq!eH`Ap=DrU-*SkH$qbuE|4r+_K3B_Z%|^{5;$aPjJ*sIY&z#-l zfp>g#{w>b_MN_9ev+#HX`$Xp|)vZoEPpYgDn?6?wUu(8qK1&H!GVW2=J3+QCiB-fW?IFbJFmw>_o5Zz3iv2|>yYZWr|?P; zb*jM=jkoc!!;Md8huLercIeP9$8;~OcS@`<$a|5@k(pS`sH0+PRDWqOil9oE7;+@^_Au6EJC+%qQpA;X zRZ!!nwo0_Gd#4-{sj3?Pb)bnmP5UE`mxy>ah8EFqO|k0~qSUxsleO#^|9IE_T$|I5 zYve2B9#WdK-Jm!21Y8Q!y}QMvO`KgowSYZ6^N7~DcegYid&ol=J?!6l_lfSheX}cN zZnx2i`?)*xCn;WSQc4TbOnrkILrZrWS0{u^&Y8L;ig`b3ZBjb^EfrfOUnA#!3RU`K z^og+{H2UB)CcF{;3Aw(J#OWNF;@+w9mS!2bK3#vs>D+U8jbms#i!JH7fDrJuj9%?6TEu#l-u$;+z*?Ni~gciDI+NL#b~_ANM3hO zGXmKp&8gQhuFHoyq>qmSjQY#JPo=28UMv03c|gg7x5dgm)Ct)w%wHNP#S^!Y8^*u$ zMt@YNipAHa>sQS;_&aBcn!J`Bd%Y4)wpQtma)6w3+wiULI}4*vFYW0%yN#b1CDo;) zj8gM+<5WwpX4y*crtM4GW0nt-vD9@}{cG$-J+00bjc?_sj@1-aPVQv!S{vM7P;X(M zlYZ@oS{G*^iWsfqm%qfq)8PgD`LBOc7EBuWdq=iUTKT_>l?(alN&K4*D>!x4&eTO8 z|AK?98GB*7lE$yn;-=gueNxpR$jglUR*1#Od1&VeqlX%(*vmX{viuvpTbw`RZp_(n3j1DP~?C+DW%(8b6DfQ;U9e z4wRxpljm8?yk2!EogBHQU!mgTR@QRpnLopv1VvYgj~uM*e#v(X;?ijz%s+mx5FH){8A zP4Ma-?rPPN|9xMUXy1%4J0ZPeEcNHj-H>&7*R6NQT(KT^RZ`e5>OF{O*ykl;A9fa7 zRm1PuZrGp9=Q!^n*5FfLjFY~@zvuW@bL~k$X8c_10M!&ekLD+!>XTFDgueyA&+MD@ z=$6qJ=Qs0{zoeLU&509wFZGl1X*%nqv=y5%Z12EKtCc@sx9o0bwTZtPzF$2pZBI@U zFYScS{GFjb%WmZRz^=SHdx(9X?03zt?9{Ft)~>`|sb06$PFUBnU$wBF(r>CgYe!tq zM{c4g`T@G}A6Fgu-=IJGr)sqrPhY`sDnI9Mc7+ucJt?{l3A(`Aq+YM8agBPC)SfVi xXZZh6K**BzQ7hO!)7+en@wzj-#^|9+u$%2Xtl{{;ZS{FeX# diff --git a/tools/Defopruj/CDefHandler.h b/tools/Defopruj/CDefHandler.h deleted file mode 100644 index c084827cfd98962aae62495c7320a2742f8747a2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3846 zcmbVP`)kus6h6OJ@P7ynWSin+>J(iC=bRICjBTPKGP*Qf>)NKI>7MAHu72M=_v9vP z%tS(aliYL9<2%p%{B(5Sl3vfD_5J z)Ov!nu?%JA&PH-e_8i}P(#Jh%>gm>?St?V>C4;PvjO68CDNjHVgE9r}->G^v+$dXR z%p3a6SfAB+K|6Iv&(~;*HkREQ#fbe3fVN&12M(6ZmD|=q8}i=vV}z=KpH!Msgc`)W1sw zk9lktWeE|d$hFHWYJ4vMCtp1tU<3Ac)o*c31?K-0d!RgivzCrVKMEk z`q*;5*~ht@BevAHjMy%0?K|)E@pgbX@8bHC)lNx&z+{BUa=}NTZYJYW;$av@kprO z_e*{a)ay8rB9@Llt!4P9is$Vu>w`sr)xswGd#G14#B|Tu!pwSr%RJt~Zi;IN-%)dF za*95bApSa#Lpw~0)n%f>TFaQUy(SGs&uIoM4XN+TrjnsKy3giNwVK-#4o%{iN>^@Yw za`#`$(Tk(fv&LQE5b7&y$yZck^S@=m1Tk_5?+*}%7S}AL=0)wjoKJ?hXIBlqY=S+l&2~z8zIHq*dp^fP^f1d**ETqR#LW8M z=@)R1p&=_O(P+a*)PYeSw5{TGoiv-Esy^b>cM8k2+ceo*kDyu`bkaGwe%j-7nj^Qg z_OtGn@!Ugf=}dp-Y}9%40(MWJ-4tkkcPEa41Eb{FJ*D758ctGUAU4AD7_^M$%uRL7 zGE&{b8TJtN>s;<3M@QhS(|ma{O7WIeS?A4iys5wFZRW03DB2$RdKTs@PQ$GGv}mz0 z61L&@Cf{)eTldj%J>708K7ux86SFvl-5+4#2zMC}Yu1i&%B*BX(<#cLom0L|%|xcD ziih~HD4d_;^^1TWVw5v$b-q_Ap_bTW#mZARany0 -#include -using namespace System; -using namespace wyprujdef; -std::string Oknopruj::ToString(System::String^ src) -{ - std::string dest; - using namespace System::Runtime::InteropServices; - const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(src)).ToPointer(); - dest = chars; - Marshal::FreeHGlobal(IntPtr((void*)chars)); - return dest; -} -void Oknopruj::wyprujDefyZPlikow(array ^pliki) -{ - progressBar1->Maximum = pliki->Length; - progressBar1->Value = 0; - CDefHandler * defik; - for each(String ^ plik in pliki) - { - progressBar1->Value++; - if(!((plik->EndsWith(".def")||(plik->EndsWith(".DEF"))))) - continue; - defik = new CDefHandler(); - defik->openDef(ToString(plik)); - - int to=1; - std::string bmpname; - if (rall->Checked) - { - to = defik->ourImages.size(); - } - - for (int i=0;iSubstring(0,plik->Length-4)) << '_' << i << "_.bmp"; - SDL_SaveBMP(defik->ourImages[i].bitmap,oss.str().c_str()); - } - - - delete defik; - } -} -[STAThreadAttribute] -int WinMain() -{ - String^ folder = (System::IO::Directory::GetCurrentDirectory()); - array^ pliki = IO::Directory::GetFiles(folder); - Oknopruj ^ okno = gcnew Oknopruj(); - Application::Run(okno); - exit(0); -} - -void Oknopruj::runSearch() -{ - wyprujDefyZPlikow(IO::Directory::GetFiles(pathBox->Text)); -}// wyprujdef.cpp : main project file. diff --git a/tools/Defopruj/Oknopruj.h b/tools/Defopruj/Oknopruj.h deleted file mode 100644 index a4bd45b1c..000000000 --- a/tools/Defopruj/Oknopruj.h +++ /dev/null @@ -1,235 +0,0 @@ -#pragma once -#include -using namespace System; -using namespace System::ComponentModel; -using namespace System::Collections; -using namespace System::Windows::Forms; -using namespace System::Data; -using namespace System::Drawing; - - -namespace wyprujdef { - - /// - /// Summary for Oknopruj - /// - /// WARNING: If you change the name of this class, you will need to change the - /// 'Resource File Name' property for the managed resource compiler tool - /// associated with all .resx files this class depends on. Otherwise, - /// the designers will not be able to interact properly with localized - /// resources associated with this form. - /// - public ref class Oknopruj : public System::Windows::Forms::Form - { - public: - - static std::string ToString(System::String^ src); - void runSearch(); - void wyprujDefyZPlikow(array ^pliki); - - Oknopruj(void) - { - InitializeComponent(); - } - - protected: - /// - /// Clean up any resources being used. - /// - ~Oknopruj() - { - if (components) - { - delete components; - } - } - private: System::Windows::Forms::MenuStrip^ menuStrip1; - protected: - private: System::Windows::Forms::ToolStripMenuItem^ rUNToolStripMenuItem; - private: System::Windows::Forms::ToolStripMenuItem^ getProgramDirToolStripMenuItem; - private: System::Windows::Forms::ToolStripMenuItem^ browseToolStripMenuItem; - - private: System::Windows::Forms::ToolStripMenuItem^ vCMIHomepageToolStripMenuItem; - private: System::Windows::Forms::ProgressBar^ progressBar1; - private: System::Windows::Forms::TextBox^ pathBox; - - private: System::Windows::Forms::Label^ label1; - private: System::DirectoryServices::DirectorySearcher^ directorySearcher1; - private: System::Windows::Forms::FolderBrowserDialog^ folderBrowserDialog1; - private: System::Windows::Forms::RadioButton^ rfirst; - private: System::Windows::Forms::RadioButton^ rall; - - - - - - private: - /// - /// Required designer variable. - /// - System::ComponentModel::Container ^components; - -#pragma region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - void InitializeComponent(void) - { - this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip()); - this->rUNToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); - this->getProgramDirToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); - this->browseToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); - this->vCMIHomepageToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem()); - this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar()); - this->pathBox = (gcnew System::Windows::Forms::TextBox()); - this->label1 = (gcnew System::Windows::Forms::Label()); - this->directorySearcher1 = (gcnew System::DirectoryServices::DirectorySearcher()); - this->folderBrowserDialog1 = (gcnew System::Windows::Forms::FolderBrowserDialog()); - this->rfirst = (gcnew System::Windows::Forms::RadioButton()); - this->rall = (gcnew System::Windows::Forms::RadioButton()); - this->menuStrip1->SuspendLayout(); - this->SuspendLayout(); - // - // menuStrip1 - // - this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->rUNToolStripMenuItem, - this->getProgramDirToolStripMenuItem, this->browseToolStripMenuItem, this->vCMIHomepageToolStripMenuItem}); - this->menuStrip1->Location = System::Drawing::Point(0, 0); - this->menuStrip1->Name = L"menuStrip1"; - this->menuStrip1->Size = System::Drawing::Size(308, 24); - this->menuStrip1->TabIndex = 0; - this->menuStrip1->Text = L"menuStrip1"; - // - // rUNToolStripMenuItem - // - this->rUNToolStripMenuItem->Name = L"rUNToolStripMenuItem"; - this->rUNToolStripMenuItem->Size = System::Drawing::Size(44, 20); - this->rUNToolStripMenuItem->Text = L"RUN!"; - this->rUNToolStripMenuItem->Click += gcnew System::EventHandler(this, &Oknopruj::rUNToolStripMenuItem_Click); - // - // getProgramDirToolStripMenuItem - // - this->getProgramDirToolStripMenuItem->Name = L"getProgramDirToolStripMenuItem"; - this->getProgramDirToolStripMenuItem->Size = System::Drawing::Size(94, 20); - this->getProgramDirToolStripMenuItem->Text = L"Get program dir"; - this->getProgramDirToolStripMenuItem->Click += gcnew System::EventHandler(this, &Oknopruj::getProgramDirToolStripMenuItem_Click); - // - // browseToolStripMenuItem - // - this->browseToolStripMenuItem->Name = L"browseToolStripMenuItem"; - this->browseToolStripMenuItem->Size = System::Drawing::Size(66, 20); - this->browseToolStripMenuItem->Text = L"Browse..."; - this->browseToolStripMenuItem->Click += gcnew System::EventHandler(this, &Oknopruj::browseToolStripMenuItem_Click); - // - // vCMIHomepageToolStripMenuItem - // - this->vCMIHomepageToolStripMenuItem->Name = L"vCMIHomepageToolStripMenuItem"; - this->vCMIHomepageToolStripMenuItem->Size = System::Drawing::Size(97, 20); - this->vCMIHomepageToolStripMenuItem->Text = L"VCMI homepage"; - this->vCMIHomepageToolStripMenuItem->Click += gcnew System::EventHandler(this, &Oknopruj::vCMIHomepageToolStripMenuItem_Click); - // - // progressBar1 - // - this->progressBar1->Location = System::Drawing::Point(12, 96); - this->progressBar1->Name = L"progressBar1"; - this->progressBar1->Size = System::Drawing::Size(284, 14); - this->progressBar1->TabIndex = 1; - // - // pathBox - // - this->pathBox->Location = System::Drawing::Point(12, 50); - this->pathBox->Name = L"pathBox"; - this->pathBox->Size = System::Drawing::Size(276, 20); - this->pathBox->TabIndex = 2; - // - // label1 - // - this->label1->AutoSize = true; - this->label1->Location = System::Drawing::Point(137, 34); - this->label1->Name = L"label1"; - this->label1->Size = System::Drawing::Size(32, 13); - this->label1->TabIndex = 3; - this->label1->Text = L"Path:"; - // - // directorySearcher1 - // - this->directorySearcher1->ClientTimeout = System::TimeSpan::Parse(L"-00:00:01"); - this->directorySearcher1->ServerPageTimeLimit = System::TimeSpan::Parse(L"-00:00:01"); - this->directorySearcher1->ServerTimeLimit = System::TimeSpan::Parse(L"-00:00:01"); - // - // rfirst - // - this->rfirst->AutoSize = true; - this->rfirst->Checked = true; - this->rfirst->Location = System::Drawing::Point(12, 73); - this->rfirst->Name = L"rfirst"; - this->rfirst->Size = System::Drawing::Size(128, 17); - this->rfirst->TabIndex = 4; - this->rfirst->TabStop = true; - this->rfirst->Text = L"Extract only first frame"; - this->rfirst->UseVisualStyleBackColor = true; - // - // rall - // - this->rall->AutoSize = true; - this->rall->Location = System::Drawing::Point(183, 73); - this->rall->Name = L"rall"; - this->rall->Size = System::Drawing::Size(105, 17); - this->rall->TabIndex = 4; - this->rall->Text = L"Extract all frames"; - this->rall->UseVisualStyleBackColor = true; - // - // Oknopruj - // - this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); - this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; - this->ClientSize = System::Drawing::Size(308, 120); - this->Controls->Add(this->rall); - this->Controls->Add(this->rfirst); - this->Controls->Add(this->label1); - this->Controls->Add(this->pathBox); - this->Controls->Add(this->progressBar1); - this->Controls->Add(this->menuStrip1); - this->MainMenuStrip = this->menuStrip1; - this->MaximizeBox = false; - this->Name = L"Oknopruj"; - this->ShowIcon = false; - this->Text = L"Defopruj 1.0"; - this->Load += gcnew System::EventHandler(this, &Oknopruj::Oknopruj_Load); - this->menuStrip1->ResumeLayout(false); - this->menuStrip1->PerformLayout(); - this->ResumeLayout(false); - this->PerformLayout(); - - } -#pragma endregion -private: System::Void rUNToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) - { - runSearch(); - } -private: System::Void Oknopruj_Load(System::Object^ sender, System::EventArgs^ e) - { - pathBox->Text = IO::Directory::GetCurrentDirectory(); - } -private: System::Void getProgramDirToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) - { - pathBox->Text = IO::Directory::GetCurrentDirectory(); - } -private: System::Void browseToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) - { - if (folderBrowserDialog1->ShowDialog()==System::Windows::Forms::DialogResult::OK) - { - pathBox->Text = folderBrowserDialog1->SelectedPath; - } - } -private: System::Void aboutToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) - { - - } -private: System::Void vCMIHomepageToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) - { - Diagnostics::Process::Start(gcnew String("http://antypika.aplus.pl/vcmi")); - } -}; -} diff --git a/tools/Defopruj/wyprujdef.vcproj b/tools/Defopruj/wyprujdef.vcproj deleted file mode 100644 index 04c7e480c..000000000 --- a/tools/Defopruj/wyprujdef.vcproj +++ /dev/null @@ -1,260 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tools/Defsorter/Form1.Designer.cs b/tools/Defsorter/Form1.Designer.cs deleted file mode 100644 index 3fc634049..000000000 --- a/tools/Defsorter/Form1.Designer.cs +++ /dev/null @@ -1,99 +0,0 @@ -namespace DefSorter -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.button1 = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.progressBar1 = new System.Windows.Forms.ProgressBar(); - this.SuspendLayout(); - // - // button1 - // - this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.button1.Location = new System.Drawing.Point(41, 35); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(138, 27); - this.button1.TabIndex = 0; - this.button1.Text = "Posortuj defy!"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label1.Location = new System.Drawing.Point(12, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(114, 18); - this.label1.TabIndex = 1; - this.label1.Text = "DefĂłw wykryto: "; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label2.Location = new System.Drawing.Point(146, 9); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(52, 18); - this.label2.TabIndex = 2; - this.label2.Text = "XXXX"; - // - // progressBar1 - // - this.progressBar1.Location = new System.Drawing.Point(4, 73); - this.progressBar1.Name = "progressBar1"; - this.progressBar1.Size = new System.Drawing.Size(202, 19); - this.progressBar1.TabIndex = 3; - // - // Form1 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(210, 97); - this.Controls.Add(this.progressBar1); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.Controls.Add(this.button1); - this.Name = "Form1"; - this.Text = "Def sorter by Tow"; - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Button button1; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.ProgressBar progressBar1; - } -} - diff --git a/tools/Defsorter/Form1.cs b/tools/Defsorter/Form1.cs deleted file mode 100644 index 529a3f06f..000000000 --- a/tools/Defsorter/Form1.cs +++ /dev/null @@ -1,242 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; -using System.IO; -using System.Collections; -namespace DefSorter -{ - public partial class Form1 : Form - { - int bledy; - public Form1() - { - InitializeComponent(); - int ile = 0; - bledy = 0; - string[] pliczki = Directory.GetFiles(Directory.GetCurrentDirectory()); - foreach (string ss in pliczki) - { - if ((!(ss.EndsWith(".DEF")))&&(!(ss.EndsWith(".def")))) - continue; - else ile++; - } - label2.Text = ile.ToString(); - progressBar1.Visible = false; - } - - private void button1_Click(object sender, EventArgs e) - { - int s12 = 0, s13 = 0, s14 = 0, s15 = 0, s16 = 0, s17 = 0, s18 = 0, - s19 = 0, s20 = 0, s21 = 0; - Form2 pozegnanie = new Form2(); - ArrayList defy = new ArrayList(); - string[] pliczki = Directory.GetFiles(Directory.GetCurrentDirectory(),"*.DEF"); - progressBar1.Visible = true; - progressBar1.Minimum = progressBar1.Value = 0; - progressBar1.Maximum = Convert.ToInt32(label2.Text); - foreach (string ss in pliczki) - { - if ((!(ss.EndsWith(".DEF"))) && (!(ss.EndsWith(".def")))) - continue; - FileStream czytacz = File.OpenRead(ss); - int coTo = czytacz.ReadByte(); - czytacz.Close(); - int poczP = ss.LastIndexOf('\\'); - string nazwa = ss.Substring(poczP + 1, ss.Length - poczP - 1); - try - { - switch (coTo) - { - case 64: - if (!Directory.Exists("40Spell")) - Directory.CreateDirectory("40Spell"); - File.Copy(ss, "40Spell\\" + nazwa); - s12++; - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSK")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSK", "40Spell\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSK"); - } - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSG")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSG", "40Spell\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSG"); - } - break; - case 65: - if (!Directory.Exists("41SpriteDef")) - Directory.CreateDirectory("41SpriteDef"); - File.Copy(ss, "41SpriteDef\\" + nazwa); - s13++; - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSK")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSK", "41SpriteDef\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSK"); - } - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSG")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSG", "41SpriteDef\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSG"); - } - break; - case 66: - if (!Directory.Exists("42Creature")) - Directory.CreateDirectory("42Creature"); - File.Copy(ss, "42Creature\\" + nazwa); - s14++; - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSK")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSK", "42Creature\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSK"); - } - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSG")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSG", "42Creature\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSG"); - } - break; - case 67: - if (!Directory.Exists("43AdvObject")) - Directory.CreateDirectory("43AdvObject"); - File.Copy(ss, "43AdvObject\\" + nazwa); - s15++; - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSK")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSK", "43AdvObject\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSK"); - } - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSG")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSG", "43AdvObject\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSG"); - } - break; - case 68: - if (!Directory.Exists("44Hero")) - Directory.CreateDirectory("44Hero"); - File.Copy(ss, "44Hero\\" + nazwa); - s16++; - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSK")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSK", "44Hero\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSK"); - } - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSG")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSG", "44Hero\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSG"); - } - break; - case 69: - if (!Directory.Exists("45Terrain")) - Directory.CreateDirectory("45Terrain"); - File.Copy(ss, "45Terrain\\" + nazwa); - s17++; - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4)+".MSK")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4)+".MSK","45Terrain\\"+nazwa.Substring(0, nazwa.Length - 4)+".MSK"); - } - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4)+".MSG")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4)+".MSG","45Terrain\\"+nazwa.Substring(0, nazwa.Length - 4)+".MSG"); - } - break; - case 70: - if (!Directory.Exists("46Cursor")) - Directory.CreateDirectory("46Cursor"); - File.Copy(ss, "46Cursor\\" + nazwa); - s18++; - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSK")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSK", "46Cursor\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSK"); - } - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSG")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSG", "46Cursor\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSG"); - } - break; - case 71: - if (!Directory.Exists("47Interface")) - Directory.CreateDirectory("47Interface"); - File.Copy(ss, "47Interface\\" + nazwa); - s19++; - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSK")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSK", "47Interface\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSK"); - } - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSG")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSG", "47Interface\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSG"); - } - break; - case 72: - if (!Directory.Exists("48Spriteframe")) - Directory.CreateDirectory("48Spriteframe"); - File.Copy(ss, "48Spriteframe\\" + nazwa); - s20++; - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSK")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSK", "48Spriteframe\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSK"); - } - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSG")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSG", "48Spriteframe\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSG"); - } - break; - case 73: - if (!Directory.Exists("49CombatHero")) - Directory.CreateDirectory("49CombatHero"); - File.Copy(ss, "49CombatHero\\" + nazwa); - s21++; - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSK")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSK", "49CombatHero\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSK"); - } - if (File.Exists(nazwa.Substring(0, nazwa.Length - 4) + ".MSG")) - { - File.Copy(nazwa.Substring(0, nazwa.Length - 4) + ".MSG", "49CombatHero\\" + nazwa.Substring(0, nazwa.Length - 4) + ".MSG"); - } - break; - } - } - catch (Exception ee) - { - bledy++; - Form3 niedobrze = new Form3(); - niedobrze.textBox1.Text += ee.Message; - DialogResult res = niedobrze.ShowDialog(); - switch (res) - { - case DialogResult.Ignore: - break; - case DialogResult.Cancel: - try { Directory.Delete("40Spell"); }catch(Exception){}; - try { Directory.Delete("41SpriteDef"); }catch(Exception){}; - try { Directory.Delete("42Creature"); }catch(Exception){}; - try { Directory.Delete("43AdvObject"); }catch(Exception){}; - try { Directory.Delete("45Terrain"); }catch(Exception){}; - try { Directory.Delete("46Cursor"); }catch(Exception){}; - try { Directory.Delete("47Interface"); }catch(Exception){}; - try { Directory.Delete("48Spriteframe"); }catch(Exception){}; - try { Directory.Delete("49CombatHero"); }catch(Exception){}; - Application.Exit(); - break; - } - } - progressBar1.Value++; - if (progressBar1.Value % 100 == 5) - this.Update(); - } - progressBar1.Visible = false; - pozegnanie.label12.Text = s12.ToString(); - pozegnanie.label13.Text = s13.ToString(); - pozegnanie.label14.Text = s14.ToString(); - pozegnanie.label15.Text = s15.ToString(); - pozegnanie.label16.Text = s16.ToString(); - pozegnanie.label17.Text = s17.ToString(); - pozegnanie.label18.Text = s18.ToString(); - pozegnanie.label19.Text = s19.ToString(); - pozegnanie.label20.Text = s20.ToString(); - pozegnanie.label21.Text = s21.ToString(); - pozegnanie.label34.Text = bledy.ToString(); - if (bledy == 0) - pozegnanie.label35.Text = ":)"; - pozegnanie.Show(); - pozegnanie.Activate(); - } - } -} \ No newline at end of file diff --git a/tools/Defsorter/Form2.Designer.cs b/tools/Defsorter/Form2.Designer.cs deleted file mode 100644 index bc700e17f..000000000 --- a/tools/Defsorter/Form2.Designer.cs +++ /dev/null @@ -1,517 +0,0 @@ -namespace DefSorter -{ - partial class Form2 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.label5 = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); - this.label7 = new System.Windows.Forms.Label(); - this.label8 = new System.Windows.Forms.Label(); - this.label9 = new System.Windows.Forms.Label(); - this.label10 = new System.Windows.Forms.Label(); - this.label11 = new System.Windows.Forms.Label(); - this.label12 = new System.Windows.Forms.Label(); - this.label13 = new System.Windows.Forms.Label(); - this.label14 = new System.Windows.Forms.Label(); - this.label15 = new System.Windows.Forms.Label(); - this.label16 = new System.Windows.Forms.Label(); - this.label17 = new System.Windows.Forms.Label(); - this.label18 = new System.Windows.Forms.Label(); - this.label19 = new System.Windows.Forms.Label(); - this.label20 = new System.Windows.Forms.Label(); - this.label21 = new System.Windows.Forms.Label(); - this.label22 = new System.Windows.Forms.Label(); - this.label23 = new System.Windows.Forms.Label(); - this.label24 = new System.Windows.Forms.Label(); - this.label25 = new System.Windows.Forms.Label(); - this.label26 = new System.Windows.Forms.Label(); - this.label27 = new System.Windows.Forms.Label(); - this.label28 = new System.Windows.Forms.Label(); - this.label29 = new System.Windows.Forms.Label(); - this.label30 = new System.Windows.Forms.Label(); - this.label31 = new System.Windows.Forms.Label(); - this.label32 = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); - this.label33 = new System.Windows.Forms.Label(); - this.label34 = new System.Windows.Forms.Label(); - this.label35 = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label1.Location = new System.Drawing.Point(12, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(255, 17); - this.label1.TabIndex = 0; - this.label1.Text = "Szczęśliwie posortowano. Wg kategorii:"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label2.Location = new System.Drawing.Point(12, 26); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(59, 17); - this.label2.TabIndex = 1; - this.label2.Text = "40Spell:"; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label3.Location = new System.Drawing.Point(12, 43); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(87, 17); - this.label3.TabIndex = 1; - this.label3.Text = "41SpriteDef:"; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label4.Location = new System.Drawing.Point(12, 60); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(83, 17); - this.label4.TabIndex = 1; - this.label4.Text = "42Creature:"; - // - // label5 - // - this.label5.AutoSize = true; - this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label5.Location = new System.Drawing.Point(12, 77); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(93, 17); - this.label5.TabIndex = 1; - this.label5.Text = "43AdvObject:"; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label6.Location = new System.Drawing.Point(12, 94); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(59, 17); - this.label6.TabIndex = 1; - this.label6.Text = "44Hero:"; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label7.Location = new System.Drawing.Point(12, 111); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(74, 17); - this.label7.TabIndex = 1; - this.label7.Text = "45Terrain:"; - // - // label8 - // - this.label8.AutoSize = true; - this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label8.Location = new System.Drawing.Point(12, 128); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(70, 17); - this.label8.TabIndex = 1; - this.label8.Text = "46Cursor:"; - // - // label9 - // - this.label9.AutoSize = true; - this.label9.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label9.Location = new System.Drawing.Point(12, 145); - this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(83, 17); - this.label9.TabIndex = 1; - this.label9.Text = "47Interface:"; - // - // label10 - // - this.label10.AutoSize = true; - this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label10.Location = new System.Drawing.Point(12, 162); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(101, 17); - this.label10.TabIndex = 1; - this.label10.Text = "48Spriteframe:"; - // - // label11 - // - this.label11.AutoSize = true; - this.label11.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label11.Location = new System.Drawing.Point(12, 179); - this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(107, 17); - this.label11.TabIndex = 1; - this.label11.Text = "49CombatHero:"; - this.label11.Click += new System.EventHandler(this.label11_Click); - // - // label12 - // - this.label12.AutoSize = true; - this.label12.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label12.Location = new System.Drawing.Point(125, 26); - this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(48, 17); - this.label12.TabIndex = 2; - this.label12.Text = "XXXX"; - // - // label13 - // - this.label13.AutoSize = true; - this.label13.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label13.Location = new System.Drawing.Point(125, 43); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(48, 17); - this.label13.TabIndex = 2; - this.label13.Text = "XXXX"; - // - // label14 - // - this.label14.AutoSize = true; - this.label14.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label14.Location = new System.Drawing.Point(125, 60); - this.label14.Name = "label14"; - this.label14.Size = new System.Drawing.Size(48, 17); - this.label14.TabIndex = 2; - this.label14.Text = "XXXX"; - // - // label15 - // - this.label15.AutoSize = true; - this.label15.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label15.Location = new System.Drawing.Point(125, 77); - this.label15.Name = "label15"; - this.label15.Size = new System.Drawing.Size(48, 17); - this.label15.TabIndex = 2; - this.label15.Text = "XXXX"; - // - // label16 - // - this.label16.AutoSize = true; - this.label16.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label16.Location = new System.Drawing.Point(125, 94); - this.label16.Name = "label16"; - this.label16.Size = new System.Drawing.Size(48, 17); - this.label16.TabIndex = 2; - this.label16.Text = "XXXX"; - // - // label17 - // - this.label17.AutoSize = true; - this.label17.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label17.Location = new System.Drawing.Point(125, 111); - this.label17.Name = "label17"; - this.label17.Size = new System.Drawing.Size(48, 17); - this.label17.TabIndex = 2; - this.label17.Text = "XXXX"; - // - // label18 - // - this.label18.AutoSize = true; - this.label18.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label18.Location = new System.Drawing.Point(125, 128); - this.label18.Name = "label18"; - this.label18.Size = new System.Drawing.Size(48, 17); - this.label18.TabIndex = 2; - this.label18.Text = "XXXX"; - // - // label19 - // - this.label19.AutoSize = true; - this.label19.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label19.Location = new System.Drawing.Point(125, 145); - this.label19.Name = "label19"; - this.label19.Size = new System.Drawing.Size(48, 17); - this.label19.TabIndex = 2; - this.label19.Text = "XXXX"; - // - // label20 - // - this.label20.AutoSize = true; - this.label20.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label20.Location = new System.Drawing.Point(125, 162); - this.label20.Name = "label20"; - this.label20.Size = new System.Drawing.Size(48, 17); - this.label20.TabIndex = 2; - this.label20.Text = "XXXX"; - // - // label21 - // - this.label21.AutoSize = true; - this.label21.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label21.Location = new System.Drawing.Point(125, 179); - this.label21.Name = "label21"; - this.label21.Size = new System.Drawing.Size(48, 17); - this.label21.TabIndex = 2; - this.label21.Text = "XXXX"; - // - // label22 - // - this.label22.AutoSize = true; - this.label22.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label22.Location = new System.Drawing.Point(179, 26); - this.label22.Name = "label22"; - this.label22.Size = new System.Drawing.Size(49, 17); - this.label22.TabIndex = 3; - this.label22.Text = "defĂłw."; - // - // label23 - // - this.label23.AutoSize = true; - this.label23.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label23.Location = new System.Drawing.Point(179, 43); - this.label23.Name = "label23"; - this.label23.Size = new System.Drawing.Size(49, 17); - this.label23.TabIndex = 3; - this.label23.Text = "defĂłw."; - // - // label24 - // - this.label24.AutoSize = true; - this.label24.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label24.Location = new System.Drawing.Point(179, 60); - this.label24.Name = "label24"; - this.label24.Size = new System.Drawing.Size(49, 17); - this.label24.TabIndex = 3; - this.label24.Text = "defĂłw."; - // - // label25 - // - this.label25.AutoSize = true; - this.label25.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label25.Location = new System.Drawing.Point(179, 77); - this.label25.Name = "label25"; - this.label25.Size = new System.Drawing.Size(49, 17); - this.label25.TabIndex = 3; - this.label25.Text = "defĂłw."; - // - // label26 - // - this.label26.AutoSize = true; - this.label26.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label26.Location = new System.Drawing.Point(179, 94); - this.label26.Name = "label26"; - this.label26.Size = new System.Drawing.Size(49, 17); - this.label26.TabIndex = 3; - this.label26.Text = "defĂłw."; - // - // label27 - // - this.label27.AutoSize = true; - this.label27.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label27.Location = new System.Drawing.Point(179, 111); - this.label27.Name = "label27"; - this.label27.Size = new System.Drawing.Size(49, 17); - this.label27.TabIndex = 3; - this.label27.Text = "defĂłw."; - // - // label28 - // - this.label28.AutoSize = true; - this.label28.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label28.Location = new System.Drawing.Point(179, 128); - this.label28.Name = "label28"; - this.label28.Size = new System.Drawing.Size(49, 17); - this.label28.TabIndex = 3; - this.label28.Text = "defĂłw."; - // - // label29 - // - this.label29.AutoSize = true; - this.label29.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label29.Location = new System.Drawing.Point(179, 145); - this.label29.Name = "label29"; - this.label29.Size = new System.Drawing.Size(49, 17); - this.label29.TabIndex = 3; - this.label29.Text = "defĂłw."; - // - // label30 - // - this.label30.AutoSize = true; - this.label30.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label30.Location = new System.Drawing.Point(179, 162); - this.label30.Name = "label30"; - this.label30.Size = new System.Drawing.Size(49, 17); - this.label30.TabIndex = 3; - this.label30.Text = "defĂłw."; - // - // label31 - // - this.label31.AutoSize = true; - this.label31.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label31.Location = new System.Drawing.Point(179, 179); - this.label31.Name = "label31"; - this.label31.Size = new System.Drawing.Size(49, 17); - this.label31.TabIndex = 3; - this.label31.Text = "defĂłw."; - // - // label32 - // - this.label32.AutoSize = true; - this.label32.Location = new System.Drawing.Point(12, 221); - this.label32.Name = "label32"; - this.label32.Size = new System.Drawing.Size(258, 13); - this.label32.TabIndex = 4; - this.label32.Text = "Defy zostaly umieszczone w odpowiednich folderach."; - // - // button1 - // - this.button1.Location = new System.Drawing.Point(98, 237); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); - this.button1.TabIndex = 5; - this.button1.Text = "Koniec!"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); - // - // label33 - // - this.label33.AutoSize = true; - this.label33.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label33.Location = new System.Drawing.Point(12, 196); - this.label33.Name = "label33"; - this.label33.Size = new System.Drawing.Size(57, 17); - this.label33.TabIndex = 1; - this.label33.Text = "BĹ‚Ä™dĂłw:"; - this.label33.Click += new System.EventHandler(this.label11_Click); - // - // label34 - // - this.label34.AutoSize = true; - this.label34.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label34.Location = new System.Drawing.Point(125, 196); - this.label34.Name = "label34"; - this.label34.Size = new System.Drawing.Size(48, 17); - this.label34.TabIndex = 2; - this.label34.Text = "XXXX"; - // - // label35 - // - this.label35.AutoSize = true; - this.label35.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label35.Location = new System.Drawing.Point(179, 196); - this.label35.Name = "label35"; - this.label35.Size = new System.Drawing.Size(17, 17); - this.label35.TabIndex = 3; - this.label35.Text = ":("; - // - // Form2 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(276, 272); - this.Controls.Add(this.button1); - this.Controls.Add(this.label32); - this.Controls.Add(this.label35); - this.Controls.Add(this.label31); - this.Controls.Add(this.label29); - this.Controls.Add(this.label30); - this.Controls.Add(this.label27); - this.Controls.Add(this.label28); - this.Controls.Add(this.label26); - this.Controls.Add(this.label25); - this.Controls.Add(this.label24); - this.Controls.Add(this.label23); - this.Controls.Add(this.label22); - this.Controls.Add(this.label34); - this.Controls.Add(this.label21); - this.Controls.Add(this.label20); - this.Controls.Add(this.label19); - this.Controls.Add(this.label18); - this.Controls.Add(this.label17); - this.Controls.Add(this.label16); - this.Controls.Add(this.label15); - this.Controls.Add(this.label14); - this.Controls.Add(this.label13); - this.Controls.Add(this.label12); - this.Controls.Add(this.label33); - this.Controls.Add(this.label11); - this.Controls.Add(this.label10); - this.Controls.Add(this.label9); - this.Controls.Add(this.label8); - this.Controls.Add(this.label7); - this.Controls.Add(this.label6); - this.Controls.Add(this.label5); - this.Controls.Add(this.label4); - this.Controls.Add(this.label3); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.Name = "Form2"; - this.Text = "UdaĹ‚o siÄ™! :)"; - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.Label label8; - private System.Windows.Forms.Label label9; - private System.Windows.Forms.Label label10; - private System.Windows.Forms.Label label11; - private System.Windows.Forms.Label label22; - private System.Windows.Forms.Label label23; - private System.Windows.Forms.Label label24; - private System.Windows.Forms.Label label25; - private System.Windows.Forms.Label label26; - private System.Windows.Forms.Label label27; - private System.Windows.Forms.Label label28; - private System.Windows.Forms.Label label29; - private System.Windows.Forms.Label label30; - private System.Windows.Forms.Label label31; - private System.Windows.Forms.Label label32; - private System.Windows.Forms.Button button1; - public System.Windows.Forms.Label label12; - public System.Windows.Forms.Label label13; - public System.Windows.Forms.Label label14; - public System.Windows.Forms.Label label15; - public System.Windows.Forms.Label label16; - public System.Windows.Forms.Label label17; - public System.Windows.Forms.Label label18; - public System.Windows.Forms.Label label19; - public System.Windows.Forms.Label label20; - public System.Windows.Forms.Label label21; - private System.Windows.Forms.Label label33; - public System.Windows.Forms.Label label34; - public System.Windows.Forms.Label label35; - } -} \ No newline at end of file diff --git a/tools/Defsorter/Form2.cs b/tools/Defsorter/Form2.cs deleted file mode 100644 index fd6ba816f..000000000 --- a/tools/Defsorter/Form2.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace DefSorter -{ - public partial class Form2 : Form - { - public Form2() - { - InitializeComponent(); - } - - private void button1_Click(object sender, EventArgs e) - { - Application.Exit(); - } - - private void label11_Click(object sender, EventArgs e) - { - - } - } -} \ No newline at end of file diff --git a/tools/Defsorter/Form3.Designer.cs b/tools/Defsorter/Form3.Designer.cs deleted file mode 100644 index bee160a5b..000000000 --- a/tools/Defsorter/Form3.Designer.cs +++ /dev/null @@ -1,101 +0,0 @@ -namespace DefSorter -{ - partial class Form3 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.textBox1 = new System.Windows.Forms.TextBox(); - this.button1 = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); - this.button3 = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // textBox1 - // - this.textBox1.Location = new System.Drawing.Point(12, 12); - this.textBox1.Multiline = true; - this.textBox1.Name = "textBox1"; - this.textBox1.ReadOnly = true; - this.textBox1.Size = new System.Drawing.Size(268, 209); - this.textBox1.TabIndex = 0; - // - // button1 - // - this.button1.DialogResult = System.Windows.Forms.DialogResult.Ignore; - this.button1.Location = new System.Drawing.Point(12, 231); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); - this.button1.TabIndex = 1; - this.button1.Text = "PomiĹ„"; - this.button1.UseVisualStyleBackColor = true; - // - // button2 - // - this.button2.Location = new System.Drawing.Point(205, 231); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(75, 23); - this.button2.TabIndex = 1; - this.button2.Text = "Harakiri"; - this.button2.UseVisualStyleBackColor = true; - this.button2.Click += new System.EventHandler(this.button2_Click); - // - // button3 - // - this.button3.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.button3.Location = new System.Drawing.Point(93, 231); - this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(106, 23); - this.button3.TabIndex = 1; - this.button3.Text = "Anuluj wszystko"; - this.button3.UseVisualStyleBackColor = true; - // - // Form3 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(292, 266); - this.Controls.Add(this.button3); - this.Controls.Add(this.button2); - this.Controls.Add(this.button1); - this.Controls.Add(this.textBox1); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Name = "Form3"; - this.Text = "Nastapil blad :("; - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - public System.Windows.Forms.TextBox textBox1; - public System.Windows.Forms.Button button1; - public System.Windows.Forms.Button button2; - public System.Windows.Forms.Button button3; - - } -} \ No newline at end of file diff --git a/tools/Defsorter/Form3.cs b/tools/Defsorter/Form3.cs deleted file mode 100644 index 0419b3921..000000000 --- a/tools/Defsorter/Form3.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; -using System.Windows.Forms; - -namespace DefSorter -{ - public partial class Form3 : Form - { - public Form3() - { - InitializeComponent(); - } - - private void button2_Click(object sender, EventArgs e) - { - Application.Exit(); - } - } -} \ No newline at end of file diff --git a/tools/Defsorter/Program.cs b/tools/Defsorter/Program.cs deleted file mode 100644 index bcf07661f..000000000 --- a/tools/Defsorter/Program.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Windows.Forms; - -namespace DefSorter -{ - static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); - } - } -} \ No newline at end of file diff --git a/tools/Obwodziciel/BNAMES.txt b/tools/Obwodziciel/BNAMES.txt deleted file mode 100644 index 82caf4c15..000000000 --- a/tools/Obwodziciel/BNAMES.txt +++ /dev/null @@ -1,44 +0,0 @@ -0 Mage guild 1 -1 Mage guild 2 -2 Mage guild 3 -3 Mage guild 4 -4 Mage guild 5 -5 tavern -6 shipyard when it's present:)) -7 fort -8 citadel -9 castle -10 village hall -11 town hall -12 city hall -13 capitol -14 marketplace -15 resource silo -16 blacksmith -17 lighthouse(0) mystic pond(1) artifact merchants(2,5,8) veil of darkness(4) escape tunnel(6) cage of warlords(7) -18 horde buildings for non-upgraded creatures: Griffins, dwarves, stone gargoyles, imps, skeletons, troglodytes, goblins, gnolls, pixies. -19 horde buildings for upgraded creatures Royal griffins, battle dwarves, obsidian gargoyles, familiars, skeleton warriors, infernal troglodytes, hobgoblins, gnoll marauders, sprites -20 Ship at the Shipyard -21 stables(0) fountain of fortune(1) lookout tower(2) brimstone clouds(3) necromancy amplifier(4) mana vortex(5) freelancer's guild(6) glyphs of fear(7) magic university(8) -22 brotherhood of sword(0) dwarven treasury(1) library(2) castle gates(3) skeleton transformer(4) portal of summoning(5) ballista yard(6) blood obelisk(7) -23 wall of Knowledge.(2) order of fire(3) academy of battle scholars(5) hall of valhalla(6) -24 horde buildings for non-upgraded creatures: dendroid guards, hell hounds -25 horde buildings for upgraded creatures: Dendroid soldiers, Cerberi -26 Grail -27 Houses near city hall -28 Houses near municipal -29 Houses near Capitol -30 dwelling 1 -31 dwelling 2 -32 dwelling 3 -33 dwelling 4 -34 dwelling 5 -35 dwelling 6 -36 dwelling 7 -37 upgraded dwelling 1 -38 upgraded dwelling 2 -39 upgraded dwelling 3 -40 upgraded dwelling 4 -41 upgraded dwelling 5 -42 upgraded dwelling 6 -43 upgraded dwelling 7 diff --git a/tools/Obwodziciel/Form1.h b/tools/Obwodziciel/Form1.h deleted file mode 100644 index 3cae61c21..000000000 --- a/tools/Obwodziciel/Form1.h +++ /dev/null @@ -1,791 +0,0 @@ -#pragma once -#include -#include - -namespace Obwodziciel { - - using namespace System; - using namespace System::ComponentModel; - using namespace System::Collections; - using namespace System::Windows::Forms; - using namespace System::Data; - using namespace System::Drawing; - -std::string ToString(System::String^ src) -{ - std::string dest; - using namespace System::Runtime::InteropServices; - const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(src)).ToPointer(); - dest = chars; - Marshal::FreeHGlobal(IntPtr((void*)chars)); - return dest; -} - /// - /// Summary for Form1 - /// - /// WARNING: If you change the name of this class, you will need to change the - /// 'Resource File Name' property for the managed resource compiler tool - /// associated with all .resx files this class depends on. Otherwise, - /// the designers will not be able to interact properly with localized - /// resources associated with this form. - /// - public ref class Form1 : public System::Windows::Forms::Form - { - public: - value struct BuildingEntry - { - int townID, ID; - String^ defname; - }; - Form1(void) - { - InitializeComponent(); - source1->Text = IO::Directory::GetCurrentDirectory(); - source2->Text = IO::Directory::GetCurrentDirectory(); - - IO::StreamReader ^sr = gcnew IO::StreamReader(IO::Directory::GetCurrentDirectory()+L"\\BNAMES.TXT"); - int i=0; - while(!sr->EndOfStream) - { - String ^ n = sr->ReadLine(); - //n = (i.ToString()) + L". " + n; - buildingTypes->Items->Add(n); - i++; - } - buildingTypes->SelectedIndex=0; - sr->Close(); - delete sr; - - sr = gcnew IO::StreamReader(IO::Directory::GetCurrentDirectory()+L"\\TOWNTYPE.TXT"); - while(!sr->EndOfStream) - { - String ^ n = sr->ReadLine(); - castleType->Items->Add(n); - } - castleType->SelectedIndex = 0; - - std::ifstream bb("buildings.txt"); - std::string pom; - while(!bb.eof()) - { - BuildingEntry be; - bb >> be.townID >> be.ID >> pom >> i >> i; - be.defname = gcnew String(pom.c_str()); - lista.Add(be); - } - bb.close(); - bb.clear(); - - out = gcnew IO::StreamWriter("wynik.txt"); - } - - protected: - /// - /// Clean up any resources being used. - /// - ~Form1() - { - if (components) - { - delete components; - } - out->Close(); - } - private: System::Windows::Forms::PictureBox^ pictureBox1; - protected: - private: System::Windows::Forms::PictureBox^ pictureBox2; - private: System::Windows::Forms::ListBox^ listBox1; - private: System::Windows::Forms::ListBox^ listBox2; - private: System::Windows::Forms::TextBox^ searchpat1; - private: System::Windows::Forms::Label^ label1; - private: System::Windows::Forms::TextBox^ searchpat2; - private: System::Windows::Forms::Label^ label2; - private: System::Windows::Forms::Button^ search1; - private: System::Windows::Forms::Button^ search2; - private: System::Windows::Forms::Label^ label3; - private: System::Windows::Forms::Label^ label4; - private: System::Windows::Forms::Button^ prev1; - private: System::Windows::Forms::Button^ next1; - private: System::Windows::Forms::Button^ prev2; - private: System::Windows::Forms::Button^ next2; - private: System::Windows::Forms::Button^ assign1; - private: System::Windows::Forms::Button^ assign2; - private: System::Windows::Forms::ListBox^ possibilites1; - private: System::Windows::Forms::ListBox^ possibilites2; - private: System::Windows::Forms::Button^ confirm1; - private: System::Windows::Forms::Button^ confirm2; - private: System::Windows::Forms::TextBox^ source1; - private: System::Windows::Forms::Label^ label5; - private: System::Windows::Forms::TextBox^ source2; - private: System::Windows::Forms::Label^ label6; - private: System::Windows::Forms::Button^ browse1; - private: System::Windows::Forms::Button^ button1; - private: System::Windows::Forms::Button^ browse2; - private: System::Windows::Forms::Label^ label7; - private: System::Windows::Forms::Label^ label8; - private: System::Windows::Forms::Label^ label9; - - - - private: System::Windows::Forms::Label^ label10; - private: System::Windows::Forms::FolderBrowserDialog^ folderBrowserDialog1; - - - private: - /// - /// Required designer variable. - /// - - int b1, b2; - IO::StreamWriter ^out; - System::Collections::Generic::List lista; - private: System::Windows::Forms::ComboBox^ buildingTypes; -private: System::Windows::Forms::ComboBox^ castleType; - - System::ComponentModel::Container ^components; - -#pragma region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - void InitializeComponent(void) - { - this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); - this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox()); - this->listBox1 = (gcnew System::Windows::Forms::ListBox()); - this->listBox2 = (gcnew System::Windows::Forms::ListBox()); - this->searchpat1 = (gcnew System::Windows::Forms::TextBox()); - this->label1 = (gcnew System::Windows::Forms::Label()); - this->searchpat2 = (gcnew System::Windows::Forms::TextBox()); - this->label2 = (gcnew System::Windows::Forms::Label()); - this->search1 = (gcnew System::Windows::Forms::Button()); - this->search2 = (gcnew System::Windows::Forms::Button()); - this->label3 = (gcnew System::Windows::Forms::Label()); - this->label4 = (gcnew System::Windows::Forms::Label()); - this->prev1 = (gcnew System::Windows::Forms::Button()); - this->next1 = (gcnew System::Windows::Forms::Button()); - this->prev2 = (gcnew System::Windows::Forms::Button()); - this->next2 = (gcnew System::Windows::Forms::Button()); - this->assign1 = (gcnew System::Windows::Forms::Button()); - this->assign2 = (gcnew System::Windows::Forms::Button()); - this->possibilites1 = (gcnew System::Windows::Forms::ListBox()); - this->possibilites2 = (gcnew System::Windows::Forms::ListBox()); - this->confirm1 = (gcnew System::Windows::Forms::Button()); - this->confirm2 = (gcnew System::Windows::Forms::Button()); - this->source1 = (gcnew System::Windows::Forms::TextBox()); - this->label5 = (gcnew System::Windows::Forms::Label()); - this->source2 = (gcnew System::Windows::Forms::TextBox()); - this->label6 = (gcnew System::Windows::Forms::Label()); - this->browse1 = (gcnew System::Windows::Forms::Button()); - this->button1 = (gcnew System::Windows::Forms::Button()); - this->browse2 = (gcnew System::Windows::Forms::Button()); - this->label7 = (gcnew System::Windows::Forms::Label()); - this->label8 = (gcnew System::Windows::Forms::Label()); - this->label9 = (gcnew System::Windows::Forms::Label()); - this->label10 = (gcnew System::Windows::Forms::Label()); - this->folderBrowserDialog1 = (gcnew System::Windows::Forms::FolderBrowserDialog()); - this->buildingTypes = (gcnew System::Windows::Forms::ComboBox()); - this->castleType = (gcnew System::Windows::Forms::ComboBox()); - (cli::safe_cast(this->pictureBox1))->BeginInit(); - (cli::safe_cast(this->pictureBox2))->BeginInit(); - this->SuspendLayout(); - // - // pictureBox1 - // - this->pictureBox1->Location = System::Drawing::Point(12, 38); - this->pictureBox1->Name = L"pictureBox1"; - this->pictureBox1->Size = System::Drawing::Size(450, 298); - this->pictureBox1->TabIndex = 0; - this->pictureBox1->TabStop = false; - // - // pictureBox2 - // - this->pictureBox2->Location = System::Drawing::Point(522, 38); - this->pictureBox2->Name = L"pictureBox2"; - this->pictureBox2->Size = System::Drawing::Size(450, 298); - this->pictureBox2->TabIndex = 0; - this->pictureBox2->TabStop = false; - // - // listBox1 - // - this->listBox1->FormattingEnabled = true; - this->listBox1->HorizontalScrollbar = true; - this->listBox1->Location = System::Drawing::Point(12, 342); - this->listBox1->Name = L"listBox1"; - this->listBox1->Size = System::Drawing::Size(167, 186); - this->listBox1->TabIndex = 1; - this->listBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::listBox1_SelectedIndexChanged); - // - // listBox2 - // - this->listBox2->FormattingEnabled = true; - this->listBox2->HorizontalScrollbar = true; - this->listBox2->Location = System::Drawing::Point(805, 342); - this->listBox2->Name = L"listBox2"; - this->listBox2->Size = System::Drawing::Size(167, 186); - this->listBox2->TabIndex = 1; - this->listBox2->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::listBox2_SelectedIndexChanged); - // - // searchpat1 - // - this->searchpat1->Location = System::Drawing::Point(185, 363); - this->searchpat1->Name = L"searchpat1"; - this->searchpat1->Size = System::Drawing::Size(173, 20); - this->searchpat1->TabIndex = 2; - this->searchpat1->Text = L"TOCS*.bmp"; - // - // label1 - // - this->label1->AutoSize = true; - this->label1->Location = System::Drawing::Point(243, 345); - this->label1->Name = L"label1"; - this->label1->Size = System::Drawing::Size(77, 13); - this->label1->TabIndex = 3; - this->label1->Text = L"Search pattern"; - // - // searchpat2 - // - this->searchpat2->Location = System::Drawing::Point(626, 361); - this->searchpat2->Name = L"searchpat2"; - this->searchpat2->Size = System::Drawing::Size(173, 20); - this->searchpat2->TabIndex = 2; - this->searchpat2->Text = L"TBCS*.bmp"; - // - // label2 - // - this->label2->AutoSize = true; - this->label2->Location = System::Drawing::Point(664, 345); - this->label2->Name = L"label2"; - this->label2->Size = System::Drawing::Size(77, 13); - this->label2->TabIndex = 3; - this->label2->Text = L"Search pattern"; - // - // search1 - // - this->search1->Location = System::Drawing::Point(185, 393); - this->search1->Name = L"search1"; - this->search1->Size = System::Drawing::Size(103, 21); - this->search1->TabIndex = 4; - this->search1->Text = L"Search"; - this->search1->UseVisualStyleBackColor = true; - this->search1->Click += gcnew System::EventHandler(this, &Form1::search1_Click); - // - // search2 - // - this->search2->Location = System::Drawing::Point(696, 391); - this->search2->Name = L"search2"; - this->search2->Size = System::Drawing::Size(103, 21); - this->search2->TabIndex = 4; - this->search2->Text = L"Search"; - this->search2->UseVisualStyleBackColor = true; - this->search2->Click += gcnew System::EventHandler(this, &Form1::search2_Click); - // - // label3 - // - this->label3->AutoSize = true; - this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, - static_cast(238))); - this->label3->Location = System::Drawing::Point(160, 6); - this->label3->Name = L"label3"; - this->label3->Size = System::Drawing::Size(81, 29); - this->label3->TabIndex = 5; - this->label3->Text = L"POLE"; - // - // label4 - // - this->label4->AutoSize = true; - this->label4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, - static_cast(238))); - this->label4->Location = System::Drawing::Point(743, 6); - this->label4->Name = L"label4"; - this->label4->Size = System::Drawing::Size(93, 29); - this->label4->TabIndex = 5; - this->label4->Text = L"IMAGE"; - // - // prev1 - // - this->prev1->Enabled = false; - this->prev1->Location = System::Drawing::Point(294, 393); - this->prev1->Name = L"prev1"; - this->prev1->Size = System::Drawing::Size(64, 21); - this->prev1->TabIndex = 6; - this->prev1->Text = L"<-"; - this->prev1->UseVisualStyleBackColor = true; - this->prev1->Click += gcnew System::EventHandler(this, &Form1::prev1_Click); - // - // next1 - // - this->next1->Enabled = false; - this->next1->Location = System::Drawing::Point(364, 393); - this->next1->Name = L"next1"; - this->next1->Size = System::Drawing::Size(64, 21); - this->next1->TabIndex = 6; - this->next1->Text = L"->"; - this->next1->UseVisualStyleBackColor = true; - this->next1->Click += gcnew System::EventHandler(this, &Form1::next1_Click); - // - // prev2 - // - this->prev2->Enabled = false; - this->prev2->Location = System::Drawing::Point(556, 391); - this->prev2->Name = L"prev2"; - this->prev2->Size = System::Drawing::Size(64, 21); - this->prev2->TabIndex = 6; - this->prev2->Text = L"<-"; - this->prev2->UseVisualStyleBackColor = true; - this->prev2->Click += gcnew System::EventHandler(this, &Form1::prev2_Click); - // - // next2 - // - this->next2->Enabled = false; - this->next2->Location = System::Drawing::Point(626, 391); - this->next2->Name = L"next2"; - this->next2->Size = System::Drawing::Size(64, 21); - this->next2->TabIndex = 6; - this->next2->Text = L"->"; - this->next2->UseVisualStyleBackColor = true; - this->next2->Click += gcnew System::EventHandler(this, &Form1::next2_Click); - // - // assign1 - // - this->assign1->Location = System::Drawing::Point(434, 391); - this->assign1->Name = L"assign1"; - this->assign1->Size = System::Drawing::Size(116, 22); - this->assign1->TabIndex = 7; - this->assign1->Text = L"Assign there >"; - this->assign1->UseVisualStyleBackColor = true; - this->assign1->Click += gcnew System::EventHandler(this, &Form1::assign1_Click); - // - // assign2 - // - this->assign2->Location = System::Drawing::Point(434, 414); - this->assign2->Name = L"assign2"; - this->assign2->Size = System::Drawing::Size(116, 22); - this->assign2->TabIndex = 7; - this->assign2->Text = L"< Assign there"; - this->assign2->UseVisualStyleBackColor = true; - this->assign2->Click += gcnew System::EventHandler(this, &Form1::assign2_Click); - // - // possibilites1 - // - this->possibilites1->FormattingEnabled = true; - this->possibilites1->HorizontalScrollbar = true; - this->possibilites1->Location = System::Drawing::Point(185, 422); - this->possibilites1->Name = L"possibilites1"; - this->possibilites1->Size = System::Drawing::Size(120, 108); - this->possibilites1->TabIndex = 8; - this->possibilites1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::possibilites1_SelectedIndexChanged); - // - // possibilites2 - // - this->possibilites2->FormattingEnabled = true; - this->possibilites2->HorizontalScrollbar = true; - this->possibilites2->Location = System::Drawing::Point(679, 422); - this->possibilites2->Name = L"possibilites2"; - this->possibilites2->Size = System::Drawing::Size(120, 108); - this->possibilites2->TabIndex = 8; - this->possibilites2->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::possibilites2_SelectedIndexChanged); - // - // confirm1 - // - this->confirm1->Location = System::Drawing::Point(312, 422); - this->confirm1->Name = L"confirm1"; - this->confirm1->Size = System::Drawing::Size(116, 25); - this->confirm1->TabIndex = 9; - this->confirm1->Text = L"Confirm"; - this->confirm1->UseVisualStyleBackColor = true; - this->confirm1->Click += gcnew System::EventHandler(this, &Form1::confirm1_Click); - // - // confirm2 - // - this->confirm2->Location = System::Drawing::Point(557, 422); - this->confirm2->Name = L"confirm2"; - this->confirm2->Size = System::Drawing::Size(116, 25); - this->confirm2->TabIndex = 9; - this->confirm2->Text = L"Confirm"; - this->confirm2->UseVisualStyleBackColor = true; - this->confirm2->Click += gcnew System::EventHandler(this, &Form1::confirm2_Click); - // - // source1 - // - this->source1->Location = System::Drawing::Point(312, 468); - this->source1->Name = L"source1"; - this->source1->Size = System::Drawing::Size(116, 20); - this->source1->TabIndex = 10; - // - // label5 - // - this->label5->AutoSize = true; - this->label5->Location = System::Drawing::Point(335, 452); - this->label5->Name = L"label5"; - this->label5->Size = System::Drawing::Size(73, 13); - this->label5->TabIndex = 11; - this->label5->Text = L"Source folder:"; - // - // source2 - // - this->source2->Location = System::Drawing::Point(556, 468); - this->source2->Name = L"source2"; - this->source2->Size = System::Drawing::Size(116, 20); - this->source2->TabIndex = 10; - // - // label6 - // - this->label6->AutoSize = true; - this->label6->Location = System::Drawing::Point(579, 452); - this->label6->Name = L"label6"; - this->label6->Size = System::Drawing::Size(73, 13); - this->label6->TabIndex = 11; - this->label6->Text = L"Source folder:"; - // - // browse1 - // - this->browse1->Location = System::Drawing::Point(312, 494); - this->browse1->Name = L"browse1"; - this->browse1->Size = System::Drawing::Size(116, 23); - this->browse1->TabIndex = 12; - this->browse1->Text = L"Browse"; - this->browse1->UseVisualStyleBackColor = true; - this->browse1->Click += gcnew System::EventHandler(this, &Form1::browse1_Click); - // - // button1 - // - this->button1->Location = System::Drawing::Point(557, 494); - this->button1->Name = L"button1"; - this->button1->Size = System::Drawing::Size(116, 23); - this->button1->TabIndex = 12; - this->button1->Text = L"Browse"; - this->button1->UseVisualStyleBackColor = true; - // - // browse2 - // - this->browse2->Location = System::Drawing::Point(556, 494); - this->browse2->Name = L"browse2"; - this->browse2->Size = System::Drawing::Size(116, 23); - this->browse2->TabIndex = 12; - this->browse2->Text = L"Browse"; - this->browse2->UseVisualStyleBackColor = true; - this->browse2->Click += gcnew System::EventHandler(this, &Form1::browse2_Click); - // - // label7 - // - this->label7->AutoSize = true; - this->label7->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, - static_cast(238))); - this->label7->Location = System::Drawing::Point(440, 472); - this->label7->Name = L"label7"; - this->label7->Size = System::Drawing::Size(104, 20); - this->label7->TabIndex = 13; - this->label7->Text = L"Obwodziciel"; - // - // label8 - // - this->label8->AutoSize = true; - this->label8->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, - static_cast(238))); - this->label8->Location = System::Drawing::Point(442, 492); - this->label8->Name = L"label8"; - this->label8->Size = System::Drawing::Size(102, 20); - this->label8->TabIndex = 13; - this->label8->Text = L"VCMI Team"; - // - // label9 - // - this->label9->AutoSize = true; - this->label9->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, - static_cast(238))); - this->label9->Location = System::Drawing::Point(459, 512); - this->label9->Name = L"label9"; - this->label9->Size = System::Drawing::Size(66, 20); - this->label9->TabIndex = 13; - this->label9->Text = L"© 2008"; - // - // label10 - // - this->label10->AutoSize = true; - this->label10->Location = System::Drawing::Point(463, 344); - this->label10->Name = L"label10"; - this->label10->Size = System::Drawing::Size(58, 13); - this->label10->TabIndex = 16; - this->label10->Text = L"Building ID"; - // - // buildingTypes - // - this->buildingTypes->FormattingEnabled = true; - this->buildingTypes->Location = System::Drawing::Point(365, 364); - this->buildingTypes->Name = L"buildingTypes"; - this->buildingTypes->Size = System::Drawing::Size(255, 21); - this->buildingTypes->TabIndex = 17; - // - // castleType - // - this->castleType->FormattingEnabled = true; - this->castleType->Location = System::Drawing::Point(434, 445); - this->castleType->Name = L"castleType"; - this->castleType->Size = System::Drawing::Size(116, 21); - this->castleType->TabIndex = 18; - // - // Form1 - // - this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); - this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; - this->ClientSize = System::Drawing::Size(984, 535); - this->Controls->Add(this->castleType); - this->Controls->Add(this->buildingTypes); - this->Controls->Add(this->label10); - this->Controls->Add(this->label9); - this->Controls->Add(this->label8); - this->Controls->Add(this->label7); - this->Controls->Add(this->browse2); - this->Controls->Add(this->button1); - this->Controls->Add(this->browse1); - this->Controls->Add(this->label6); - this->Controls->Add(this->label5); - this->Controls->Add(this->source2); - this->Controls->Add(this->source1); - this->Controls->Add(this->confirm2); - this->Controls->Add(this->confirm1); - this->Controls->Add(this->possibilites2); - this->Controls->Add(this->possibilites1); - this->Controls->Add(this->assign2); - this->Controls->Add(this->assign1); - this->Controls->Add(this->next2); - this->Controls->Add(this->next1); - this->Controls->Add(this->prev2); - this->Controls->Add(this->prev1); - this->Controls->Add(this->label4); - this->Controls->Add(this->label3); - this->Controls->Add(this->search2); - this->Controls->Add(this->search1); - this->Controls->Add(this->label2); - this->Controls->Add(this->label1); - this->Controls->Add(this->searchpat2); - this->Controls->Add(this->searchpat1); - this->Controls->Add(this->listBox2); - this->Controls->Add(this->listBox1); - this->Controls->Add(this->pictureBox2); - this->Controls->Add(this->pictureBox1); - this->Name = L"Form1"; - this->Text = L"Obwodziciel 1.00"; - (cli::safe_cast(this->pictureBox1))->EndInit(); - (cli::safe_cast(this->pictureBox2))->EndInit(); - this->ResumeLayout(false); - this->PerformLayout(); - - } -#pragma endregion - private: System::Void browse1_Click(System::Object^ sender, System::EventArgs^ e) { - folderBrowserDialog1->ShowDialog(); - source1->Text = folderBrowserDialog1->SelectedPath; - } -private: System::Void browse2_Click(System::Object^ sender, System::EventArgs^ e) { - folderBrowserDialog1->ShowDialog(); - source2->Text = folderBrowserDialog1->SelectedPath; - } -private: System::Void search1_Click(System::Object^ sender, System::EventArgs^ e) { - listBox1->Items->Clear(); - array^ pliki = IO::Directory::GetFiles(source1->Text,searchpat1->Text); - for each(String^ plik in pliki) - { - listBox1->Items->Add(plik); - } - if(listBox1->Items->Count>0) - listBox1->SelectedIndex=0; - } -private: System::Void search2_Click(System::Object^ sender, System::EventArgs^ e) { - listBox2->Items->Clear(); - array^ pliki = IO::Directory::GetFiles(source2->Text,searchpat2->Text); - for each(String^ plik in pliki) - { - listBox2->Items->Add(plik); - } - if(listBox2->Items->Count>0) - listBox2->SelectedIndex=0; - } -private: System::Void listBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) { - if(listBox1->SelectedIndex<0) - return; - pictureBox1->Image = gcnew Drawing::Bitmap(dynamic_cast(listBox1->SelectedItem)); - } -private: System::Void listBox2_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) { - if(listBox2->SelectedIndex<0) - return; - String^ s = dynamic_cast(listBox2->SelectedItem); - pictureBox2->Image = gcnew Drawing::Bitmap(s); - s = s->Substring(s->LastIndexOf(L"\\")+1); - s = s->Replace(L"_0_",L""); - s = s->Replace(L".bmp",L".def"); - s = s->Replace(L".BMP",L".def"); - for each(BuildingEntry b in lista) - { - if(b.defname == s) - buildingTypes->SelectedIndex = b.ID; - } - } -private: System::Void assign2_Click(System::Object^ sender, System::EventArgs^ e) { - possibilites1->Items->Clear(); - for each(Object^ item in listBox1->Items) - { - String^ path = dynamic_cast(item); - Bitmap ^b = gcnew Bitmap(path); - if( (b->Width == pictureBox2->Image->Width) && (b->Height == pictureBox2->Image->Height) ) - possibilites1->Items->Add(path); - delete b; - } - if (possibilites1->Items->Count>0) - { - possibilites1->SelectedIndex=0; - } - } -private: System::Void assign1_Click(System::Object^ sender, System::EventArgs^ e) { - possibilites2->Items->Clear(); - for each(Object^ item in listBox2->Items) - { - String^ path = dynamic_cast(item); - Bitmap ^b = gcnew Bitmap(path); - if( (b->Width == pictureBox1->Image->Width) && (b->Height == pictureBox1->Image->Height) ) - possibilites2->Items->Add(path); - delete b; - } - if (possibilites2->Items->Count>0) - { - possibilites2->SelectedIndex=0; - } - } -private: System::Void possibilites1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) { - if(possibilites1->SelectedIndex<0) - return; - String^ s = dynamic_cast(possibilites1->SelectedItem); - pictureBox1->Image = gcnew Drawing::Bitmap(s); - s = s->Substring(s->LastIndexOf(L"\\")+1); - s = s->Replace(L"_0_",L""); - s = s->Replace(L".bmp",L".def"); - s = s->Replace(L".BMP",L".def"); - for each(BuildingEntry b in lista) - { - if(b.defname == s) - buildingTypes->SelectedIndex = b.ID; - } - } -private: System::Void possibilites2_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) { - if(possibilites2->SelectedIndex<0) - return; - String^ s = dynamic_cast(possibilites2->SelectedItem); - pictureBox2->Image = gcnew Drawing::Bitmap(s); - s = s->Substring(s->LastIndexOf(L"\\")+1); - s = s->Replace(L"_0_",L""); - s = s->Replace(L".bmp",L".def"); - s = s->Replace(L".BMP",L".def"); - for each(BuildingEntry b in lista) - { - if(b.defname == s) - buildingTypes->SelectedIndex = b.ID; - } - } - void confirm(bool first) - { - try - { - //out format: - // townId ID defname bordername areaname - - String^ s, ^s2, ^s3; - if(first) - { - s = dynamic_cast(possibilites2->SelectedItem); - } - else - { - s = dynamic_cast(listBox2->SelectedItem); - } - s = s->Substring(s->LastIndexOf(L"\\")+1); - s = s->Replace(L"_0_",L""); - s = s->Replace(L".bmp",L".def"); - s = s->Replace(L".BMP",L".def"); - - if(!first) - { - s2 = dynamic_cast(possibilites1->SelectedItem); - } - else - { - s2 = dynamic_cast(listBox1->SelectedItem); - } - s2 = s2->Substring(s2->LastIndexOf(L"\\")+1); - - s3 = L"TZ" + s2->Substring(2); - - String^ toOut; - toOut = castleType->SelectedIndex.ToString() + L"\t" - + buildingTypes->SelectedIndex + (L"\t") - + s + L"\t" - + s2 + L"\t" - + s3; - out->WriteLine(toOut); - out->Flush(); - - if(first) - { - for each(Object^ obj in listBox2->Items) - { - String^ str = dynamic_cast(obj), - ^usw = dynamic_cast(possibilites2->SelectedItem); - if(str==usw) - { - listBox2->Items->Remove(obj); - if(listBox2->Items->Count>0) - listBox2->SelectedIndex = 0; - break; - } - } - listBox1->Items->Remove(listBox1->SelectedItem); - if(listBox1->Items->Count>0) - listBox1->SelectedIndex++; - } - else - { - for each(Object^ obj in listBox1->Items) - { - String^ str = dynamic_cast(obj), - ^usw = dynamic_cast(possibilites1->SelectedItem); - if(str==usw) - { - listBox1->Items->Remove(obj); - if(listBox1->Items->Count>0) - listBox1->SelectedIndex = 0; - break; - } - } - int tempp = listBox2->SelectedIndex; - listBox2->Items->Remove(listBox2->SelectedItem); - if(listBox2->Items->Count>tempp) - listBox2->SelectedIndex=tempp; - } - - possibilites1->Items->Clear(); - possibilites2->Items->Clear(); - } - catch(...) - { - possibilites1->Items->Clear(); - possibilites2->Items->Clear(); - } - } -private: System::Void confirm1_Click(System::Object^ sender, System::EventArgs^ e) { - confirm(true); - } -private: System::Void confirm2_Click(System::Object^ sender, System::EventArgs^ e) { - confirm(false); - } -private: System::Void prev1_Click(System::Object^ sender, System::EventArgs^ e) { - } -private: System::Void next1_Click(System::Object^ sender, System::EventArgs^ e) { - } -private: System::Void prev2_Click(System::Object^ sender, System::EventArgs^ e) { - } -private: System::Void next2_Click(System::Object^ sender, System::EventArgs^ e) { - } -}; -} - diff --git a/tools/Obwodziciel/Form1.resx b/tools/Obwodziciel/Form1.resx deleted file mode 100644 index f28ce5858..000000000 --- a/tools/Obwodziciel/Form1.resx +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 17, 17 - - - 42 - - \ No newline at end of file diff --git a/tools/Obwodziciel/Obwodziciel.cpp b/tools/Obwodziciel/Obwodziciel.cpp deleted file mode 100644 index d1a5858a6..000000000 --- a/tools/Obwodziciel/Obwodziciel.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Obwodziciel.cpp : main project file. - -#include "Form1.h" - -using namespace Obwodziciel; - -[STAThreadAttribute] -int main(array ^args) -{ - // Enabling Windows XP visual effects before any controls are created - Application::EnableVisualStyles(); - Application::SetCompatibleTextRenderingDefault(false); - - // Create the main window and run it - Application::Run(gcnew Form1()); - return 0; -} diff --git a/tools/Obwodziciel/Obwodziciel.vcproj b/tools/Obwodziciel/Obwodziciel.vcproj deleted file mode 100644 index 7df6c12e7..000000000 --- a/tools/Obwodziciel/Obwodziciel.vcproj +++ /dev/null @@ -1,236 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tools/Obwodziciel/TOWNTYPE.TXT b/tools/Obwodziciel/TOWNTYPE.TXT deleted file mode 100644 index f2e154580..000000000 --- a/tools/Obwodziciel/TOWNTYPE.TXT +++ /dev/null @@ -1,9 +0,0 @@ -Castle -Rampart -Tower -Inferno -Necropolis -Dungeon -Stronghold -Fortress -Conflux diff --git a/tools/Obwodziciel/buildings.txt b/tools/Obwodziciel/buildings.txt deleted file mode 100644 index ec31cfc0e..000000000 --- a/tools/Obwodziciel/buildings.txt +++ /dev/null @@ -1,37 +0,0 @@ -0 16 TBCSBLAK.def 213 251 -0 8 TBCSCAS2.def 478 66 -0 9 TBCSCAS3.def 478 37 -0 7 TBCSCSTL.def 595 66 -0 6 TBCSDOCK.def 478 134 -0 30 TBCSDW_0.def 304 92 -0 31 TBCSDW_1.def 360 130 -0 32 TBCSDW_2.def 76 57 -0 33 TBCSDW_3.def 176 101 -0 34 TBCSDW_4.def 563 211 -0 35 TBCSDW_5.def 174 190 -0 36 TBCSDW_6.def 303 0 -0 21 TBCSEXT0.def 384 193 -0 22 TBCSEXT1.def 0 198 -0 11 TBCSHAL2.def 0 176 -0 12 TBCSHAL3.def 0 164 -0 13 TBCSHAL4.def 0 154 -0 10 TBCSHALL.def 0 209 -0 26 TBCSHOLY.def 456 109 -0 18 TBCSHRD1.def 76 53 -0 19 TBCSHRD2.def 76 35 -0 1 TBCSMAG2.def 706 135 -0 2 TBCSMAG3.def 704 107 -0 3 TBCSMAG4.def 704 76 -0 0 TBCSMAGE.def 707 166 -0 14 TBCSMARK.def 413 264 -0 15 TBCSSILO.def 488 228 -0 17 TBCSSPEC.def 533 71 -0 5 TBCSTVRN.def 0 230 -0 37 TBCSUP_0.def 304 65 -0 38 TBCSUP_1.def 360 115 -0 39 TBCSUP_2.def 76 35 -0 40 TBCSUP_3.def 176 85 -0 41 TBCSUP_4.def 563 173 -0 42 TBCSUP_5.def 160 190 -0 43 TBCSUP_6.def 303 0 -0 20 TBCSBOAT.def 478 134 \ No newline at end of file diff --git a/tools/Wpasujbud/AssemblyInfo.cpp b/tools/Wpasujbud/AssemblyInfo.cpp deleted file mode 100644 index a64855d4a..000000000 --- a/tools/Wpasujbud/AssemblyInfo.cpp +++ /dev/null @@ -1,38 +0,0 @@ -using namespace System; -using namespace System::Reflection; -using namespace System::Runtime::CompilerServices; -using namespace System::Runtime::InteropServices; -using namespace System::Security::Permissions; - -// -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -// -[assembly:AssemblyTitleAttribute("Wpasujbud 1.0")]; -[assembly:AssemblyDescriptionAttribute("Cudowne narzedzie, ktore wpasuje budynki za mnie")]; -[assembly:AssemblyConfigurationAttribute("")]; -[assembly:AssemblyCompanyAttribute("VCMI Team")]; -[assembly:AssemblyProductAttribute("ret")]; -[assembly:AssemblyCopyrightAttribute("Copyright (c) 2008")]; -[assembly:AssemblyTrademarkAttribute("")]; -[assembly:AssemblyCultureAttribute("")]; - -// -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the value or you can default the Revision and Build Numbers -// by using the '*' as shown below: - -[assembly:AssemblyVersionAttribute("1.0.*")]; - -[assembly:ComVisible(false)]; - -[assembly:CLSCompliantAttribute(true)]; - -[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/tools/Wpasujbud/Wpasujbud.cpp b/tools/Wpasujbud/Wpasujbud.cpp deleted file mode 100644 index 7fa0e50a9..000000000 --- a/tools/Wpasujbud/Wpasujbud.cpp +++ /dev/null @@ -1,361 +0,0 @@ -// Wpasujbud.cpp : main project file. -//#include -#include "SDL.h" -#include "Wpasujbud.h" -#include "tchar.h" -#include "obrazek.h" -#include "dataEditor.h" -using namespace Wpasuj; - -int Inaccuracy=5; -int zgodnosc(Bitmap^ bg, Bitmap^ st, int x, int y); -int zgodnosc(SDL_Surface * bg, SDL_Surface * st, int x, int y); - -std::string Wpasujbud::ToString(System::String^ src) -{ - std::string dest; - using namespace System::Runtime::InteropServices; - const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(src)).ToPointer(); - dest = chars; - Marshal::FreeHGlobal(IntPtr((void*)chars)); - return dest; -} - -[STAThreadAttribute] -int __stdcall WinMain() -{ - // Enabling Windows XP visual effects before any controls are created - Application::EnableVisualStyles(); - Application::SetCompatibleTextRenderingDefault(false); - - Application::Run(gcnew Wpasujbud()); - exit(0); - return 0; -} - -Wpasujbud::Wpasujbud(void) -{ - InitializeComponent(); - openFileDialog1->InitialDirectory = IO::Directory::GetCurrentDirectory(); - IO::StreamReader ^sr = gcnew IO::StreamReader(L"config/TOWNTYPE.TXT"); - Int32 i=0; - while(!sr->EndOfStream) - { - String ^ n = sr->ReadLine(); - n = (i.ToString()) + L". " + n; - townID->Items->Add(n); - i++; - } - townID->SelectedIndex=0; - sr->Close(); - i++; - - - sr = gcnew IO::StreamReader(L"config/BNAMES.TXT"); - i=0; - while(!sr->EndOfStream) - { - String ^ n = sr->ReadLine(); - //n = (i.ToString()) + L". " + n; - buildingType->Items->Add(n); - i++; - } - buildingType->SelectedIndex=0; - sr->Close(); - i++; - - bitmapsFolder->Text = openFileDialog1->InitialDirectory; - -} - -System::Void Wpasujbud::searchBitmaps_Click(System::Object^ sender, System::EventArgs^ e) -{ - bitmapList->Items->Clear(); - array^ pliki = IO::Directory::GetFiles(bitmapsFolder->Text,bmpPattern->Text); - for each(String ^ plik in pliki) - { - //if(plik->EndsWith(L".bmp") || plik->EndsWith(L".BMP")) - bitmapList->Items->Add(plik->Substring(plik->LastIndexOf('\\')+1)); - } - if(bitmapList->Items->Count>0) - bitmapList->SelectedIndex=0; -} -System::Void Wpasujbud::startLocating_Click(System::Object^ sender, System::EventArgs^ e) -{ - searchPicturePos(); -} -System::Void Wpasujbud::setBackground_Click(System::Object^ sender, System::EventArgs^ e) -{ - if(townBgPath->Text->Length==0) - return; - Bitmap ^ bg = gcnew Bitmap(townBgPath->Text); - townBg->Image = dynamic_cast(bg); - sbg = SDL_LoadBMP(ToString(townBgPath->Text).c_str()); -} -System::Void Wpasujbud::openFileDialog1_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) -{ - townBgPath->Text = (dynamic_cast(sender))->FileName; -} -System::Void Wpasujbud::browseForBg_Click(System::Object^ sender, System::EventArgs^ e) -{ - openFileDialog1->ShowDialog(); -} -System::Void Wpasujbud::browseForbmpfol_Click(System::Object^ sender, System::EventArgs^ e) -{ - folderBrowserDialog1->ShowDialog(); - bitmapsFolder->Text = folderBrowserDialog1->SelectedPath; -} -System::Void Wpasujbud::bitmapList_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) -{ - int nsel = bitmapList->SelectedIndex; - if (nsel<0) - return; - String ^ bmpname = bitmapsFolder->Text + "\\" + dynamic_cast(bitmapList->SelectedItem); - Bitmap ^building = gcnew Bitmap(bmpname); - buildingImg->Image = dynamic_cast(building); -} -System::Void Wpasujbud::townBg_Click(System::Object^ sender, System::EventArgs^ e) -{ - //Int32 tx, ty, ux, uy; - //tx = townBg->Location.X; - //ty = townBg->Location.Y; - //ux = Location.X; - //uy = Location.Y; - mx = MousePosition.X - townBg->Location.X - Location.X - 4; - my = MousePosition.Y - townBg->Location.Y - Location.Y - 30; - koordy->Text = mx.ToString() + L", " + my.ToString(); -} -System::Void Wpasujbud::button1_Click(System::Object^ sender, System::EventArgs^ e) //skip -{ - nextPicture(); -} - -Uint32 SDL_GetPixel(SDL_Surface *surface, int x, int y) -{ - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel; - - switch(surface->format->BytesPerPixel) - { - case 1: - { - SDL_Color * color = surface->format->palette->colors+(*p); - return color->r<<16 | color->g<<8 | color->b; - } - case 3: - return p[0] | p[1] << 8 | p[2] << 16; - } -} -int zgodnosc(SDL_Surface * bg, SDL_Surface * st, int x, int y) -{ - int ret=0; - for(int i=0;iw;i+=Inaccuracy) - { - for(int j=0;jh;j+=Inaccuracy) - { - int c1 = SDL_GetPixel(bg,i+x,j+y); - int c2 = SDL_GetPixel(st,i,j); - if((i+x)>=bg->w) - break; - if((j+y)>=bg->h) - break; - if(SDL_GetPixel(bg,i+x,j+y) == SDL_GetPixel(st,i,j)) - { - ret++; - } - } - } - return ret*(Inaccuracy*Inaccuracy); -} -int zgodnosc(Bitmap^ bg, Bitmap^ st, int x, int y) -{ - int ret=0; - for(int i=0;iWidth;i++) - { - for(int j=0;jHeight;j++) - { - //Color c1 = bg->GetPixel(i+x,j+y); - //Color c2 = st->GetPixel(i,j); - if((i+x)>=bg->Width) - break; - if((j+y)>=bg->Height) - break; - if(bg->GetPixel(i+x,j+y) == st->GetPixel(i,j)) - { - ret++; - } - } - } - return ret; -} -void Wpasujbud::searchPicturePos() -{ - //Bitmap^ b = gcnew Bitmap((townBg->Image)->Width,(townBg->Image)->Height,Imaging::PixelFormat::Format24bppRgb); - //Bitmap^ s = dynamic_cast(buildingImg->Image); - //Graphics ^ g = Graphics::FromImage(b); - //g->DrawImage(townBg->Image,0,0); - //townBg->Image = b; - String^ sss = bitmapsFolder->Text; - if(!(sss->EndsWith(L"/")||sss->EndsWith(L"\\"))) - sss+=L"\\"; - sss+=dynamic_cast(bitmapList->SelectedItem); - SDL_Surface *str = SDL_LoadBMP(ToString(sss).c_str()); - Int32 colorPxs = 0; - - int aq = 0x00ffff; - for (int x=0;xw;x++) - { - for(int y=0;yh;y++) - { - if(SDL_GetPixel(str,x,y) != aq) - colorPxs++; - } - } - int zgoda=0, retx, rety; - int px=mx, py=my, maxr = Convert::ToInt32(radious->Text); - if (radioButton2->Checked) - { - px-=str->w/2; - py-=str->h/2; - } - else if (radioButton3->Checked) - { - px-=str->w; - py-=str->h; - } - px-=maxr/2; - py-=maxr/2; - for(int i=0;izgoda) - { - zgoda = pom; - retx = px+i; - rety = py+j; - } - } - } - //for(int r=0;rzgoda) - // { - // zgoda = pom; - // retx = px+i; - // rety = py; - // } - // pom = zgodnosc(sbg,str,px+i,py+r); - // if (pom>zgoda) - // { - // zgoda = pom; - // retx = px+i; - // rety = py+r; - // } - // pom = zgodnosc(sbg,str,px,py+i); - // if (pom>zgoda) - // { - // zgoda = pom; - // retx = px; - // rety = py+i; - // } - // pom = zgodnosc(sbg,str,px+r,py+i); - // if (pom>zgoda) - // { - // zgoda = pom; - // retx = px+r; - // rety = py+i; - // } - // float per = zgoda/colorPxs; - // - // } - // px--; - // py--; - //} - accordanceBox->Text = zgoda.ToString() + L"/" + colorPxs.ToString(); - curx = retx; - cury = rety; - foundedCoords->Text = retx.ToString() + L", " + rety.ToString(); - //townBg->Refresh(); -} - -System::Void Wpasujbud::inaccuracy_TextChanged(System::Object^ sender, System::EventArgs^ e) -{ - int ni = Convert::ToUInt32(inaccuracy->Text); - if(ni==0) - { - inaccuracy->Text == L"1"; - Inaccuracy = 1; - } - else - { - Inaccuracy = ni; - } -} - -void Wpasujbud::nextPicture() -{ - if(bitmapList->SelectedIndex<(bitmapList->Items->Count-1)) - bitmapList->SelectedIndex++; -} -void Wpasujbud::previousPicture() -{ - if(bitmapList->SelectedIndex>0) - bitmapList->SelectedIndex--; -} - -System::Void Wpasujbud::confirm_Click(System::Object^ sender, System::EventArgs^ e) -{ - CBuildingData ^cbd = gcnew CBuildingData(); - //cbd->defname = bitmapsFolder->Text; - //if(!(cbd->defname->EndsWith(L"/")||cbd->defname->EndsWith(L"\\"))) - // cbd->defname+=L"\\"; - cbd->defname+=dynamic_cast(bitmapList->SelectedItem); - cbd->defname = (cbd->defname)->Substring(0,cbd->defname->Length-7)+".def"; - cbd->ID = buildingType->SelectedIndex; - cbd->townID = townID->SelectedIndex; - cbd->x = curx; - cbd->y = cury; - - //int curind = bitmapList->SelectedIndex; - bitmapList->Items->RemoveAt(bitmapList->SelectedIndex); - - nextPicture(); - nextPicture(); - data.push_back(cbd); - -} - //System::String^ defname; - //System::Int32 ID, x, y; - //System::Int32 townID; -System::Void Wpasujbud::save_Click(System::Object^ sender, System::EventArgs^ e) -{ - String ^n = DateTime::Now.ToString()+".txt"; - n = n->Replace(L" ",L"___")->Replace(':','_'); - IO::StreamWriter sr(IO::Directory::GetCurrentDirectory() + L"\\" + n); - for each (CBuildingData ^Data in data) - { - String ^temp = Data->ToString(); - sr.Write(temp); - } - sr.Close(); -} - -System::Void Wpasujbud::buildingImg_Click(System::Object^ sender, System::EventArgs^ e) -{ - if (!buildingImg->Image) - return; - obrazek ^ob = gcnew obrazek(buildingImg->Image); - ob->Show(); -} -System::Void Wpasujbud::dataview_Click(System::Object^ sender, System::EventArgs^ e) -{ - if (data.size()<=0) - return; - dataEditor ^ de = gcnew dataEditor(%data); - de->Show(); -} \ No newline at end of file diff --git a/tools/Wpasujbud/Wpasujbud.h b/tools/Wpasujbud/Wpasujbud.h deleted file mode 100644 index 0ab671c47..000000000 --- a/tools/Wpasujbud/Wpasujbud.h +++ /dev/null @@ -1,649 +0,0 @@ -#pragma once -#include -#include "data.h" -#include "obrazek.h" -#include "dataEditor.h" -#include -namespace Wpasuj { - - using namespace System; - using namespace System::ComponentModel; - using namespace System::Collections; - using namespace System::Windows::Forms; - using namespace System::Data; - using namespace System::Drawing; - - - /// - /// Summary for Wpasujbud - /// - /// WARNING: If you change the name of this class, you will need to change the - /// 'Resource File Name' property for the managed resource compiler tool - /// associated with all .resx files this class depends on. Otherwise, - /// the designers will not be able to interact properly with localized - /// resources associated with this form. - /// - public ref class Wpasujbud : public System::Windows::Forms::Form - { - public: - cliext::vector data; - - Int32 mx, my, curx, cury; - SDL_Surface * sbg; - private: System::Windows::Forms::TextBox^ foundedCoords; - public: - - public: - - public: - - public: - private: System::Windows::Forms::Label^ label11; - private: System::Windows::Forms::Button^ confirm; - - private: System::Windows::Forms::Label^ label12; - private: System::Windows::Forms::Button^ button3; - private: System::Windows::Forms::TextBox^ accordanceBox; - private: System::Windows::Forms::Button^ button4; - private: System::Windows::Forms::TextBox^ inaccuracy; - private: System::Windows::Forms::Label^ label13; - private: System::Windows::Forms::Button^ save; - - private: System::Windows::Forms::RadioButton^ radioButton3; - private: System::Windows::Forms::Button^ dataview; - private: System::Windows::Forms::Label^ label9; - private: System::Windows::Forms::Label^ label14; - - private: System::Windows::Forms::Button^ button1; - public: - - void searchPicturePos(); - void nextPicture(); - void previousPicture(); - std::string ToString(System::String^ src); - - - obrazek ^curob; - dataEditor ^cured; - - Wpasujbud(void); - - protected: - /// - /// Clean up any resources being used. - /// - ~Wpasujbud() - { - if (components) - { - delete components; - } - } - private: System::Windows::Forms::PictureBox^ townBg; - private: System::Windows::Forms::PictureBox^ buildingImg; - - private: System::Windows::Forms::Label^ label1; - private: System::Windows::Forms::RadioButton^ radioButton1; - private: System::Windows::Forms::RadioButton^ radioButton2; - private: System::Windows::Forms::TextBox^ koordy; - private: System::Windows::Forms::Label^ label2; - private: System::Windows::Forms::ComboBox^ buildingType; - - private: System::Windows::Forms::Label^ label3; - private: System::Windows::Forms::Label^ label4; - private: System::Windows::Forms::ComboBox^ townID; - private: System::Windows::Forms::TextBox^ bmpPattern; - private: System::Windows::Forms::Label^ label5; - private: System::Windows::Forms::ListBox^ bitmapList; - private: System::Windows::Forms::Label^ label6; - private: System::Windows::Forms::Button^ searchBitmaps; - private: System::Windows::Forms::Button^ startLocating; - - private: System::Windows::Forms::TextBox^ townBgPath; - private: System::Windows::Forms::Label^ label7; - private: System::Windows::Forms::Button^ setBackground; - - private: System::Windows::Forms::TextBox^ radious; - private: System::Windows::Forms::Label^ label8; - - - private: System::Windows::Forms::OpenFileDialog^ openFileDialog1; - private: System::Windows::Forms::Button^ browseForBg; - private: System::Windows::Forms::TextBox^ bitmapsFolder; - private: System::Windows::Forms::Label^ label10; - private: System::Windows::Forms::Button^ browseForbmpfol; - - private: System::Windows::Forms::FolderBrowserDialog^ folderBrowserDialog1; - - - protected: - - protected: - - private: - /// - /// Required designer variable. - /// - System::ComponentModel::Container ^components; - -#pragma region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - void InitializeComponent(void) - { - this->townBg = (gcnew System::Windows::Forms::PictureBox()); - this->buildingImg = (gcnew System::Windows::Forms::PictureBox()); - this->label1 = (gcnew System::Windows::Forms::Label()); - this->radioButton1 = (gcnew System::Windows::Forms::RadioButton()); - this->radioButton2 = (gcnew System::Windows::Forms::RadioButton()); - this->koordy = (gcnew System::Windows::Forms::TextBox()); - this->label2 = (gcnew System::Windows::Forms::Label()); - this->buildingType = (gcnew System::Windows::Forms::ComboBox()); - this->label3 = (gcnew System::Windows::Forms::Label()); - this->label4 = (gcnew System::Windows::Forms::Label()); - this->townID = (gcnew System::Windows::Forms::ComboBox()); - this->bmpPattern = (gcnew System::Windows::Forms::TextBox()); - this->label5 = (gcnew System::Windows::Forms::Label()); - this->bitmapList = (gcnew System::Windows::Forms::ListBox()); - this->label6 = (gcnew System::Windows::Forms::Label()); - this->searchBitmaps = (gcnew System::Windows::Forms::Button()); - this->startLocating = (gcnew System::Windows::Forms::Button()); - this->townBgPath = (gcnew System::Windows::Forms::TextBox()); - this->label7 = (gcnew System::Windows::Forms::Label()); - this->setBackground = (gcnew System::Windows::Forms::Button()); - this->radious = (gcnew System::Windows::Forms::TextBox()); - this->label8 = (gcnew System::Windows::Forms::Label()); - this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog()); - this->browseForBg = (gcnew System::Windows::Forms::Button()); - this->bitmapsFolder = (gcnew System::Windows::Forms::TextBox()); - this->label10 = (gcnew System::Windows::Forms::Label()); - this->browseForbmpfol = (gcnew System::Windows::Forms::Button()); - this->folderBrowserDialog1 = (gcnew System::Windows::Forms::FolderBrowserDialog()); - this->button1 = (gcnew System::Windows::Forms::Button()); - this->foundedCoords = (gcnew System::Windows::Forms::TextBox()); - this->label11 = (gcnew System::Windows::Forms::Label()); - this->confirm = (gcnew System::Windows::Forms::Button()); - this->label12 = (gcnew System::Windows::Forms::Label()); - this->button3 = (gcnew System::Windows::Forms::Button()); - this->accordanceBox = (gcnew System::Windows::Forms::TextBox()); - this->button4 = (gcnew System::Windows::Forms::Button()); - this->inaccuracy = (gcnew System::Windows::Forms::TextBox()); - this->label13 = (gcnew System::Windows::Forms::Label()); - this->save = (gcnew System::Windows::Forms::Button()); - this->radioButton3 = (gcnew System::Windows::Forms::RadioButton()); - this->dataview = (gcnew System::Windows::Forms::Button()); - this->label9 = (gcnew System::Windows::Forms::Label()); - this->label14 = (gcnew System::Windows::Forms::Label()); - (cli::safe_cast(this->townBg))->BeginInit(); - (cli::safe_cast(this->buildingImg))->BeginInit(); - this->SuspendLayout(); - // - // townBg - // - this->townBg->Location = System::Drawing::Point(12, 6); - this->townBg->Name = L"townBg"; - this->townBg->Size = System::Drawing::Size(800, 374); - this->townBg->TabIndex = 0; - this->townBg->TabStop = false; - this->townBg->Click += gcnew System::EventHandler(this, &Wpasujbud::townBg_Click); - // - // buildingImg - // - this->buildingImg->Location = System::Drawing::Point(12, 401); - this->buildingImg->Name = L"buildingImg"; - this->buildingImg->Size = System::Drawing::Size(163, 137); - this->buildingImg->TabIndex = 1; - this->buildingImg->TabStop = false; - this->buildingImg->Click += gcnew System::EventHandler(this, &Wpasujbud::buildingImg_Click); - // - // label1 - // - this->label1->AutoSize = true; - this->label1->Location = System::Drawing::Point(12, 385); - this->label1->Name = L"label1"; - this->label1->Size = System::Drawing::Size(166, 13); - this->label1->TabIndex = 2; - this->label1->Text = L"Current building (click for full size):"; - // - // radioButton1 - // - this->radioButton1->AutoSize = true; - this->radioButton1->Checked = true; - this->radioButton1->Location = System::Drawing::Point(185, 491); - this->radioButton1->Name = L"radioButton1"; - this->radioButton1->Size = System::Drawing::Size(94, 17); - this->radioButton1->TabIndex = 3; - this->radioButton1->TabStop = true; - this->radioButton1->Text = L"Top left corner"; - this->radioButton1->UseVisualStyleBackColor = true; - // - // radioButton2 - // - this->radioButton2->AutoSize = true; - this->radioButton2->Location = System::Drawing::Point(185, 512); - this->radioButton2->Name = L"radioButton2"; - this->radioButton2->Size = System::Drawing::Size(85, 17); - this->radioButton2->TabIndex = 3; - this->radioButton2->Text = L"Middle of pic"; - this->radioButton2->UseVisualStyleBackColor = true; - // - // koordy - // - this->koordy->Location = System::Drawing::Point(185, 470); - this->koordy->Name = L"koordy"; - this->koordy->Size = System::Drawing::Size(121, 20); - this->koordy->TabIndex = 4; - // - // label2 - // - this->label2->AutoSize = true; - this->label2->Location = System::Drawing::Point(214, 456); - this->label2->Name = L"label2"; - this->label2->Size = System::Drawing::Size(67, 13); - this->label2->TabIndex = 5; - this->label2->Text = L"Your coords:"; - // - // buildingType - // - this->buildingType->FormattingEnabled = true; - this->buildingType->Location = System::Drawing::Point(185, 400); - this->buildingType->Name = L"buildingType"; - this->buildingType->Size = System::Drawing::Size(121, 21); - this->buildingType->TabIndex = 6; - // - // label3 - // - this->label3->AutoSize = true; - this->label3->Location = System::Drawing::Point(214, 385); - this->label3->Name = L"label3"; - this->label3->Size = System::Drawing::Size(67, 13); - this->label3->TabIndex = 7; - this->label3->Text = L"Building type"; - // - // label4 - // - this->label4->AutoSize = true; - this->label4->Location = System::Drawing::Point(224, 422); - this->label4->Name = L"label4"; - this->label4->Size = System::Drawing::Size(48, 13); - this->label4->TabIndex = 7; - this->label4->Text = L"Town ID"; - // - // townID - // - this->townID->FormattingEnabled = true; - this->townID->Location = System::Drawing::Point(185, 435); - this->townID->Name = L"townID"; - this->townID->Size = System::Drawing::Size(121, 21); - this->townID->TabIndex = 6; - // - // bmpPattern - // - this->bmpPattern->Location = System::Drawing::Point(317, 467); - this->bmpPattern->Name = L"bmpPattern"; - this->bmpPattern->Size = System::Drawing::Size(121, 20); - this->bmpPattern->TabIndex = 4; - this->bmpPattern->Text = L"*.bmp"; - // - // label5 - // - this->label5->AutoSize = true; - this->label5->Location = System::Drawing::Point(332, 452); - this->label5->Name = L"label5"; - this->label5->Size = System::Drawing::Size(103, 13); - this->label5->TabIndex = 5; - this->label5->Text = L"Search bmp pattern:"; - // - // bitmapList - // - this->bitmapList->Enabled = false; - this->bitmapList->FormattingEnabled = true; - this->bitmapList->Location = System::Drawing::Point(449, 400); - this->bitmapList->Name = L"bitmapList"; - this->bitmapList->Size = System::Drawing::Size(133, 95); - this->bitmapList->TabIndex = 8; - this->bitmapList->SelectedIndexChanged += gcnew System::EventHandler(this, &Wpasujbud::bitmapList_SelectedIndexChanged); - // - // label6 - // - this->label6->AutoSize = true; - this->label6->Location = System::Drawing::Point(485, 384); - this->label6->Name = L"label6"; - this->label6->Size = System::Drawing::Size(57, 13); - this->label6->TabIndex = 9; - this->label6->Text = L"Bitmap list:"; - // - // searchBitmaps - // - this->searchBitmaps->Location = System::Drawing::Point(449, 501); - this->searchBitmaps->Name = L"searchBitmaps"; - this->searchBitmaps->Size = System::Drawing::Size(133, 23); - this->searchBitmaps->TabIndex = 10; - this->searchBitmaps->Text = L"Search bitmaps"; - this->searchBitmaps->UseVisualStyleBackColor = true; - this->searchBitmaps->Click += gcnew System::EventHandler(this, &Wpasujbud::searchBitmaps_Click); - // - // startLocating - // - this->startLocating->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 10, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, - static_cast(238))); - this->startLocating->Location = System::Drawing::Point(696, 464); - this->startLocating->Name = L"startLocating"; - this->startLocating->Size = System::Drawing::Size(120, 29); - this->startLocating->TabIndex = 11; - this->startLocating->Text = L"Search pos!"; - this->startLocating->UseVisualStyleBackColor = true; - this->startLocating->Click += gcnew System::EventHandler(this, &Wpasujbud::startLocating_Click); - // - // townBgPath - // - this->townBgPath->Location = System::Drawing::Point(317, 403); - this->townBgPath->Name = L"townBgPath"; - this->townBgPath->Size = System::Drawing::Size(121, 20); - this->townBgPath->TabIndex = 4; - // - // label7 - // - this->label7->AutoSize = true; - this->label7->Location = System::Drawing::Point(332, 386); - this->label7->Name = L"label7"; - this->label7->Size = System::Drawing::Size(94, 13); - this->label7->TabIndex = 5; - this->label7->Text = L"Town background"; - // - // setBackground - // - this->setBackground->Location = System::Drawing::Point(317, 427); - this->setBackground->Name = L"setBackground"; - this->setBackground->Size = System::Drawing::Size(52, 23); - this->setBackground->TabIndex = 12; - this->setBackground->Text = L"Set bg"; - this->setBackground->UseVisualStyleBackColor = true; - this->setBackground->Click += gcnew System::EventHandler(this, &Wpasujbud::setBackground_Click); - // - // radious - // - this->radious->Location = System::Drawing::Point(591, 441); - this->radious->Name = L"radious"; - this->radious->Size = System::Drawing::Size(98, 20); - this->radious->TabIndex = 13; - this->radious->Text = L"100"; - // - // label8 - // - this->label8->AutoSize = true; - this->label8->Location = System::Drawing::Point(597, 426); - this->label8->Name = L"label8"; - this->label8->Size = System::Drawing::Size(62, 13); - this->label8->TabIndex = 5; - this->label8->Text = L"Search rad:"; - // - // openFileDialog1 - // - this->openFileDialog1->FileName = L"openFileDialog1"; - this->openFileDialog1->Filter = L"BMP Files (*.bmp)|*.bmp|All files (*.*)|*.*"; - this->openFileDialog1->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &Wpasujbud::openFileDialog1_FileOk); - // - // browseForBg - // - this->browseForBg->Location = System::Drawing::Point(373, 427); - this->browseForBg->Name = L"browseForBg"; - this->browseForBg->Size = System::Drawing::Size(65, 23); - this->browseForBg->TabIndex = 14; - this->browseForBg->Text = L"Browse"; - this->browseForBg->UseVisualStyleBackColor = true; - this->browseForBg->Click += gcnew System::EventHandler(this, &Wpasujbud::browseForBg_Click); - // - // bitmapsFolder - // - this->bitmapsFolder->Location = System::Drawing::Point(317, 505); - this->bitmapsFolder->Name = L"bitmapsFolder"; - this->bitmapsFolder->Size = System::Drawing::Size(121, 20); - this->bitmapsFolder->TabIndex = 4; - // - // label10 - // - this->label10->AutoSize = true; - this->label10->Location = System::Drawing::Point(334, 490); - this->label10->Name = L"label10"; - this->label10->Size = System::Drawing::Size(97, 13); - this->label10->TabIndex = 5; - this->label10->Text = L"Folder with bitmaps"; - // - // browseForbmpfol - // - this->browseForbmpfol->Location = System::Drawing::Point(321, 528); - this->browseForbmpfol->Name = L"browseForbmpfol"; - this->browseForbmpfol->Size = System::Drawing::Size(111, 19); - this->browseForbmpfol->TabIndex = 15; - this->browseForbmpfol->Text = L"Browse"; - this->browseForbmpfol->UseVisualStyleBackColor = true; - this->browseForbmpfol->Click += gcnew System::EventHandler(this, &Wpasujbud::browseForbmpfol_Click); - // - // button1 - // - this->button1->Location = System::Drawing::Point(592, 466); - this->button1->Name = L"button1"; - this->button1->Size = System::Drawing::Size(97, 23); - this->button1->TabIndex = 16; - this->button1->Text = L"Next pic"; - this->button1->UseVisualStyleBackColor = true; - this->button1->Click += gcnew System::EventHandler(this, &Wpasujbud::button1_Click); - // - // foundedCoords - // - this->foundedCoords->Location = System::Drawing::Point(696, 441); - this->foundedCoords->Name = L"foundedCoords"; - this->foundedCoords->Size = System::Drawing::Size(120, 20); - this->foundedCoords->TabIndex = 17; - this->foundedCoords->Text = L"0, 0"; - // - // label11 - // - this->label11->AutoSize = true; - this->label11->Location = System::Drawing::Point(722, 425); - this->label11->Name = L"label11"; - this->label11->Size = System::Drawing::Size(87, 13); - this->label11->TabIndex = 18; - this->label11->Text = L"Founded coords:"; - // - // confirm - // - this->confirm->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, - static_cast(238))); - this->confirm->Location = System::Drawing::Point(590, 525); - this->confirm->Name = L"confirm"; - this->confirm->Size = System::Drawing::Size(120, 23); - this->confirm->TabIndex = 19; - this->confirm->Text = L"Confirm"; - this->confirm->UseVisualStyleBackColor = true; - this->confirm->Click += gcnew System::EventHandler(this, &Wpasujbud::confirm_Click); - // - // label12 - // - this->label12->AutoSize = true; - this->label12->Location = System::Drawing::Point(722, 385); - this->label12->Name = L"label12"; - this->label12->Size = System::Drawing::Size(68, 13); - this->label12->TabIndex = 21; - this->label12->Text = L"Accordance:"; - // - // button3 - // - this->button3->Location = System::Drawing::Point(736, 496); - this->button3->Name = L"button3"; - this->button3->Size = System::Drawing::Size(83, 23); - this->button3->TabIndex = 22; - this->button3->Text = L"Check pos"; - this->button3->UseVisualStyleBackColor = true; - // - // accordanceBox - // - this->accordanceBox->Enabled = false; - this->accordanceBox->Location = System::Drawing::Point(696, 401); - this->accordanceBox->Name = L"accordanceBox"; - this->accordanceBox->Size = System::Drawing::Size(115, 20); - this->accordanceBox->TabIndex = 20; - this->accordanceBox->Text = L"0/0"; - // - // button4 - // - this->button4->Location = System::Drawing::Point(592, 496); - this->button4->Name = L"button4"; - this->button4->Size = System::Drawing::Size(83, 23); - this->button4->TabIndex = 23; - this->button4->Text = L"Previous pic"; - this->button4->UseVisualStyleBackColor = true; - this->button4->Click += gcnew System::EventHandler(this, &Wpasujbud::button4_Click); - // - // inaccuracy - // - this->inaccuracy->Location = System::Drawing::Point(592, 401); - this->inaccuracy->Name = L"inaccuracy"; - this->inaccuracy->Size = System::Drawing::Size(98, 20); - this->inaccuracy->TabIndex = 20; - this->inaccuracy->Text = L"5"; - this->inaccuracy->TextChanged += gcnew System::EventHandler(this, &Wpasujbud::inaccuracy_TextChanged); - // - // label13 - // - this->label13->AutoSize = true; - this->label13->Location = System::Drawing::Point(587, 385); - this->label13->Name = L"label13"; - this->label13->Size = System::Drawing::Size(88, 13); - this->label13->TabIndex = 21; - this->label13->Text = L"Inaccuracy level:"; - // - // save - // - this->save->Location = System::Drawing::Point(681, 497); - this->save->Name = L"save"; - this->save->Size = System::Drawing::Size(48, 23); - this->save->TabIndex = 24; - this->save->Text = L"Save"; - this->save->UseVisualStyleBackColor = true; - this->save->Click += gcnew System::EventHandler(this, &Wpasujbud::save_Click); - // - // radioButton3 - // - this->radioButton3->AutoSize = true; - this->radioButton3->Location = System::Drawing::Point(185, 531); - this->radioButton3->Name = L"radioButton3"; - this->radioButton3->Size = System::Drawing::Size(114, 17); - this->radioButton3->TabIndex = 3; - this->radioButton3->Text = L"Bottom right corner"; - this->radioButton3->UseVisualStyleBackColor = true; - // - // dataview - // - this->dataview->Location = System::Drawing::Point(449, 528); - this->dataview->Name = L"dataview"; - this->dataview->Size = System::Drawing::Size(135, 21); - this->dataview->TabIndex = 25; - this->dataview->Text = L"Data view/edition"; - this->dataview->UseVisualStyleBackColor = true; - this->dataview->Click += gcnew System::EventHandler(this, &Wpasujbud::dataview_Click); - // - // label9 - // - this->label9->AutoSize = true; - this->label9->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, - static_cast(238))); - this->label9->Location = System::Drawing::Point(722, 523); - this->label9->Name = L"label9"; - this->label9->Size = System::Drawing::Size(99, 15); - this->label9->TabIndex = 26; - this->label9->Text = L"By VCMI Team"; - // - // label14 - // - this->label14->AutoSize = true; - this->label14->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, - static_cast(238))); - this->label14->Location = System::Drawing::Point(742, 538); - this->label14->Name = L"label14"; - this->label14->Size = System::Drawing::Size(53, 15); - this->label14->TabIndex = 27; - this->label14->Text = L"© 2008"; - // - // Wpasujbud - // - this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); - this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; - this->ClientSize = System::Drawing::Size(823, 554); - this->Controls->Add(this->label14); - this->Controls->Add(this->label9); - this->Controls->Add(this->dataview); - this->Controls->Add(this->save); - this->Controls->Add(this->button4); - this->Controls->Add(this->button3); - this->Controls->Add(this->label13); - this->Controls->Add(this->label12); - this->Controls->Add(this->inaccuracy); - this->Controls->Add(this->accordanceBox); - this->Controls->Add(this->confirm); - this->Controls->Add(this->label11); - this->Controls->Add(this->foundedCoords); - this->Controls->Add(this->button1); - this->Controls->Add(this->browseForbmpfol); - this->Controls->Add(this->browseForBg); - this->Controls->Add(this->radious); - this->Controls->Add(this->setBackground); - this->Controls->Add(this->startLocating); - this->Controls->Add(this->searchBitmaps); - this->Controls->Add(this->label6); - this->Controls->Add(this->bitmapList); - this->Controls->Add(this->label4); - this->Controls->Add(this->label3); - this->Controls->Add(this->townID); - this->Controls->Add(this->buildingType); - this->Controls->Add(this->label8); - this->Controls->Add(this->label7); - this->Controls->Add(this->label10); - this->Controls->Add(this->label5); - this->Controls->Add(this->label2); - this->Controls->Add(this->bitmapsFolder); - this->Controls->Add(this->townBgPath); - this->Controls->Add(this->bmpPattern); - this->Controls->Add(this->koordy); - this->Controls->Add(this->radioButton3); - this->Controls->Add(this->radioButton2); - this->Controls->Add(this->radioButton1); - this->Controls->Add(this->label1); - this->Controls->Add(this->buildingImg); - this->Controls->Add(this->townBg); - this->MaximizeBox = false; - this->Name = L"Wpasujbud"; - this->Text = L"Cudowny wpasowywacz 1.00"; - (cli::safe_cast(this->townBg))->EndInit(); - (cli::safe_cast(this->buildingImg))->EndInit(); - this->ResumeLayout(false); - this->PerformLayout(); - - } -#pragma endregion - private: - System::Void searchBitmaps_Click(System::Object^ sender, System::EventArgs^ e); - System::Void startLocating_Click(System::Object^ sender, System::EventArgs^ e); - System::Void setBackground_Click(System::Object^ sender, System::EventArgs^ e); - System::Void openFileDialog1_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) ; - System::Void browseForBg_Click(System::Object^ sender, System::EventArgs^ e); - System::Void browseForbmpfol_Click(System::Object^ sender, System::EventArgs^ e); - System::Void bitmapList_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e); - System::Void townBg_Click(System::Object^ sender, System::EventArgs^ e); - System::Void button1_Click(System::Object^ sender, System::EventArgs^ e); - System::Void inaccuracy_TextChanged(System::Object^ sender, System::EventArgs^ e); - System::Void confirm_Click(System::Object^ sender, System::EventArgs^ e); - System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) { - previousPicture(); - } - System::Void save_Click(System::Object^ sender, System::EventArgs^ e); - System::Void buildingImg_Click(System::Object^ sender, System::EventArgs^ e); - System::Void dataview_Click(System::Object^ sender, System::EventArgs^ e); - -}; - -} - diff --git a/tools/Wpasujbud/config/BNAMES.txt b/tools/Wpasujbud/config/BNAMES.txt deleted file mode 100644 index 82caf4c15..000000000 --- a/tools/Wpasujbud/config/BNAMES.txt +++ /dev/null @@ -1,44 +0,0 @@ -0 Mage guild 1 -1 Mage guild 2 -2 Mage guild 3 -3 Mage guild 4 -4 Mage guild 5 -5 tavern -6 shipyard when it's present:)) -7 fort -8 citadel -9 castle -10 village hall -11 town hall -12 city hall -13 capitol -14 marketplace -15 resource silo -16 blacksmith -17 lighthouse(0) mystic pond(1) artifact merchants(2,5,8) veil of darkness(4) escape tunnel(6) cage of warlords(7) -18 horde buildings for non-upgraded creatures: Griffins, dwarves, stone gargoyles, imps, skeletons, troglodytes, goblins, gnolls, pixies. -19 horde buildings for upgraded creatures Royal griffins, battle dwarves, obsidian gargoyles, familiars, skeleton warriors, infernal troglodytes, hobgoblins, gnoll marauders, sprites -20 Ship at the Shipyard -21 stables(0) fountain of fortune(1) lookout tower(2) brimstone clouds(3) necromancy amplifier(4) mana vortex(5) freelancer's guild(6) glyphs of fear(7) magic university(8) -22 brotherhood of sword(0) dwarven treasury(1) library(2) castle gates(3) skeleton transformer(4) portal of summoning(5) ballista yard(6) blood obelisk(7) -23 wall of Knowledge.(2) order of fire(3) academy of battle scholars(5) hall of valhalla(6) -24 horde buildings for non-upgraded creatures: dendroid guards, hell hounds -25 horde buildings for upgraded creatures: Dendroid soldiers, Cerberi -26 Grail -27 Houses near city hall -28 Houses near municipal -29 Houses near Capitol -30 dwelling 1 -31 dwelling 2 -32 dwelling 3 -33 dwelling 4 -34 dwelling 5 -35 dwelling 6 -36 dwelling 7 -37 upgraded dwelling 1 -38 upgraded dwelling 2 -39 upgraded dwelling 3 -40 upgraded dwelling 4 -41 upgraded dwelling 5 -42 upgraded dwelling 6 -43 upgraded dwelling 7 diff --git a/tools/Wpasujbud/config/TOWNTYPE.TXT b/tools/Wpasujbud/config/TOWNTYPE.TXT deleted file mode 100644 index f2e154580..000000000 --- a/tools/Wpasujbud/config/TOWNTYPE.TXT +++ /dev/null @@ -1,9 +0,0 @@ -Castle -Rampart -Tower -Inferno -Necropolis -Dungeon -Stronghold -Fortress -Conflux diff --git a/tools/Wpasujbud/data.h b/tools/Wpasujbud/data.h deleted file mode 100644 index 6ec54ad59..000000000 --- a/tools/Wpasujbud/data.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -public ref class CBuildingData -{ -public: - System::String^ defname; - System::Int32 ID, x, y; - System::Int32 townID; - virtual System::String^ ToString()override - { - return townID.ToString() + L" " + ID.ToString() + L" " + defname + L" " + x.ToString() + L" " + y.ToString() + L"\n"; - } -}; \ No newline at end of file diff --git a/tools/Wpasujbud/dataEditor.cpp b/tools/Wpasujbud/dataEditor.cpp deleted file mode 100644 index 5bd79ee72..000000000 --- a/tools/Wpasujbud/dataEditor.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "dataEditor.h" - diff --git a/tools/Wpasujbud/dataEditor.h b/tools/Wpasujbud/dataEditor.h deleted file mode 100644 index 1ff83d23c..000000000 --- a/tools/Wpasujbud/dataEditor.h +++ /dev/null @@ -1,209 +0,0 @@ -#pragma once -#include "data.h" -#include -using namespace System; -using namespace System::ComponentModel; -using namespace System::Collections; -using namespace System::Windows::Forms; -using namespace System::Data; -using namespace System::Drawing; - - -namespace Wpasuj { - - /// - /// Summary for dataEditor - /// - /// WARNING: If you change the name of this class, you will need to change the - /// 'Resource File Name' property for the managed resource compiler tool - /// associated with all .resx files this class depends on. Otherwise, - /// the designers will not be able to interact properly with localized - /// resources associated with this form. - /// - public ref class dataEditor : public System::Windows::Forms::Form - { - public: - dataEditor(cliext::vector ^Data) - { - data = Data; - InitializeComponent(); - dataGridView1->Rows->Add(data->size()); - for (int i=0;isize();i++) - { - dataGridView1->Rows[i]->Cells[0]->Value = data->at(i)->townID; - dataGridView1->Rows[i]->Cells[1]->Value = data->at(i)->ID; - dataGridView1->Rows[i]->Cells[2]->Value = data->at(i)->defname; - dataGridView1->Rows[i]->Cells[3]->Value = data->at(i)->x; - dataGridView1->Rows[i]->Cells[4]->Value = data->at(i)->y; - } - } - private: System::Windows::Forms::DataGridViewTextBoxColumn^ townid; - public: - private: System::Windows::Forms::DataGridViewTextBoxColumn^ buildingID; - private: System::Windows::Forms::DataGridViewTextBoxColumn^ defname; - private: System::Windows::Forms::DataGridViewTextBoxColumn^ x; - private: System::Windows::Forms::DataGridViewTextBoxColumn^ y; - private: System::Windows::Forms::Button^ save; - private: System::Windows::Forms::Button^ clear; - private: System::Windows::Forms::Button^ close; - private: - - cliext::vector ^data; - protected: - /// - /// Clean up any resources being used. - /// - ~dataEditor() - { - if (components) - { - delete components; - } - } - private: System::Windows::Forms::DataGridView^ dataGridView1; - - - - - - protected: - - protected: - - private: - /// - /// Required designer variable. - /// - System::ComponentModel::Container ^components; - -#pragma region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - void InitializeComponent(void) - { - this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView()); - this->townid = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn()); - this->buildingID = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn()); - this->defname = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn()); - this->x = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn()); - this->y = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn()); - this->save = (gcnew System::Windows::Forms::Button()); - this->clear = (gcnew System::Windows::Forms::Button()); - this->close = (gcnew System::Windows::Forms::Button()); - (cli::safe_cast(this->dataGridView1))->BeginInit(); - this->SuspendLayout(); - // - // dataGridView1 - // - this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize; - this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^ >(5) {this->townid, - this->buildingID, this->defname, this->x, this->y}); - this->dataGridView1->Location = System::Drawing::Point(12, 12); - this->dataGridView1->Name = L"dataGridView1"; - this->dataGridView1->Size = System::Drawing::Size(334, 276); - this->dataGridView1->TabIndex = 0; - // - // townid - // - this->townid->HeaderText = L"Town ID"; - this->townid->Name = L"townid"; - this->townid->Width = 50; - // - // buildingID - // - this->buildingID->HeaderText = L"Building ID"; - this->buildingID->Name = L"buildingID"; - this->buildingID->Width = 60; - // - // defname - // - this->defname->HeaderText = L"Def name"; - this->defname->Name = L"defname"; - this->defname->Width = 120; - // - // x - // - this->x->HeaderText = L"X"; - this->x->Name = L"x"; - this->x->Width = 30; - // - // y - // - this->y->HeaderText = L"Y"; - this->y->Name = L"y"; - this->y->Width = 30; - // - // save - // - this->save->Location = System::Drawing::Point(12, 294); - this->save->Name = L"save"; - this->save->Size = System::Drawing::Size(105, 23); - this->save->TabIndex = 1; - this->save->Text = L"Save changes"; - this->save->UseVisualStyleBackColor = true; - this->save->Click += gcnew System::EventHandler(this, &dataEditor::save_Click); - // - // clear - // - this->clear->Location = System::Drawing::Point(248, 294); - this->clear->Name = L"clear"; - this->clear->Size = System::Drawing::Size(96, 23); - this->clear->TabIndex = 2; - this->clear->Text = L"Clear changes"; - this->clear->UseVisualStyleBackColor = true; - this->clear->Click += gcnew System::EventHandler(this, &dataEditor::clear_Click); - // - // close - // - this->close->Location = System::Drawing::Point(123, 294); - this->close->Name = L"close"; - this->close->Size = System::Drawing::Size(119, 23); - this->close->TabIndex = 3; - this->close->Text = L"Close"; - this->close->UseVisualStyleBackColor = true; - this->close->Click += gcnew System::EventHandler(this, &dataEditor::close_Click); - // - // dataEditor - // - this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); - this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; - this->ClientSize = System::Drawing::Size(356, 328); - this->Controls->Add(this->close); - this->Controls->Add(this->clear); - this->Controls->Add(this->save); - this->Controls->Add(this->dataGridView1); - this->Name = L"dataEditor"; - this->Text = L"dataEditor"; - (cli::safe_cast(this->dataGridView1))->EndInit(); - this->ResumeLayout(false); - - } -#pragma endregion - - private: System::Void clear_Click(System::Object^ sender, System::EventArgs^ e) { - for (int i=0;isize();i++) - { - dataGridView1->Rows[i]->Cells[0]->Value = data->at(i)->townID; - dataGridView1->Rows[i]->Cells[1]->Value = data->at(i)->ID; - dataGridView1->Rows[i]->Cells[2]->Value = data->at(i)->defname; - dataGridView1->Rows[i]->Cells[3]->Value = data->at(i)->x; - dataGridView1->Rows[i]->Cells[4]->Value = data->at(i)->y; - } - } -private: System::Void close_Click(System::Object^ sender, System::EventArgs^ e) { - Close(); - } -private: System::Void save_Click(System::Object^ sender, System::EventArgs^ e) { - for (int i=0;isize();i++) - { - data->at(i)->townID = Convert::ToInt32( static_cast(dataGridView1->Rows[i]->Cells[0]->Value)); - data->at(i)->ID = Convert::ToInt32( static_cast(dataGridView1->Rows[i]->Cells[1]->Value)); - data->at(i)->defname = static_cast(dataGridView1->Rows[i]->Cells[2]->Value); - data->at(i)->x = Convert::ToInt32( static_cast(dataGridView1->Rows[i]->Cells[3]->Value)); - data->at(i)->y = Convert::ToInt32( static_cast(dataGridView1->Rows[i]->Cells[4]->Value)); - } - } -}; -} diff --git a/tools/Wpasujbud/obrazek.cpp b/tools/Wpasujbud/obrazek.cpp deleted file mode 100644 index f4a63a41b..000000000 --- a/tools/Wpasujbud/obrazek.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "obrazek.h" - diff --git a/tools/Wpasujbud/obrazek.h b/tools/Wpasujbud/obrazek.h deleted file mode 100644 index c5b7c50d9..000000000 --- a/tools/Wpasujbud/obrazek.h +++ /dev/null @@ -1,121 +0,0 @@ -#pragma once - -using namespace System; -using namespace System::ComponentModel; -using namespace System::Collections; -using namespace System::Windows::Forms; -using namespace System::Data; -using namespace System::Drawing; - - -namespace Wpasuj { - - /// - /// Summary for obrazek - /// - /// WARNING: If you change the name of this class, you will need to change the - /// 'Resource File Name' property for the managed resource compiler tool - /// associated with all .resx files this class depends on. Otherwise, - /// the designers will not be able to interact properly with localized - /// resources associated with this form. - /// - public ref class obrazek : public System::Windows::Forms::Form - { - public: - obrazek(System::Drawing::Image^ img) - { - InitializeComponent(img); - } - - protected: - /// - /// Clean up any resources being used. - /// - ~obrazek() - { - if (components) - { - delete components; - } - } - private: System::Windows::Forms::PictureBox^ pictureBox1; - private: System::Windows::Forms::TrackBar^ trackBar1; - private: System::Windows::Forms::Label^ Transparency; - protected: - - private: - /// - /// Required designer variable. - /// - System::ComponentModel::Container ^components; - -#pragma region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - void InitializeComponent(System::Drawing::Image^ img) - { - this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); - (cli::safe_cast(this->pictureBox1))->BeginInit(); - this->SuspendLayout(); - // - // pictureBox1 - // - this->pictureBox1->Location = System::Drawing::Point(12, 12); - this->pictureBox1->Name = L"pictureBox1"; - this->pictureBox1->Size = System::Drawing::Size(img->Width,img->Height);//(268, 242); - this->pictureBox1->TabIndex = 0; - this->pictureBox1->TabStop = false; - this->pictureBox1->Image = img; - this->pictureBox1->Click += gcnew System::EventHandler(this,&obrazek::obrazek_Click); - - - - this->Transparency = (gcnew System::Windows::Forms::Label()); - this->Transparency->AutoSize = true; - this->Transparency->Location = System::Drawing::Point(12, img->Height+70); - this->Transparency->Name = L"label13"; - this->Transparency->Size = System::Drawing::Size(110, 13); - this->Transparency->TabIndex = 21; - this->Transparency->Text = L"Window transparency"; - - - this->trackBar1 = (gcnew System::Windows::Forms::TrackBar()); - this->trackBar1->Location = System::Drawing::Point(12, img->Height+24); - this->trackBar1->Name = L"trackBar1"; - this->trackBar1->Size = System::Drawing::Size(img->Width, 45); - this->trackBar1->TabIndex = 26; - this->trackBar1->Minimum = 0; - this->trackBar1->Maximum = 255; - this->trackBar1->Value = 255; - this->trackBar1->TickFrequency=1; - this->trackBar1->ValueChanged += gcnew System::EventHandler(this,&obrazek::suwakiemRuszono); - - // - // obrazek - // - this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); - this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; - this->ClientSize = System::Drawing::Size(img->Width+24,img->Height+94);//(292, 266); - this->Controls->Add(this->pictureBox1); - this->Controls->Add(this->trackBar1); - this->Controls->Add(this->Transparency); - this->Click += gcnew System::EventHandler(this,&obrazek::obrazek_Click); - this->Name = L"obrazek"; - this->Text = L"Picture window"; - (cli::safe_cast(this->pictureBox1))->EndInit(); - this->ResumeLayout(false); - - - } -#pragma endregion - - private: System::Void obrazek_Click(System::Object^ sender, System::EventArgs^ e) { - Close(); - } - private: System::Void suwakiemRuszono(System::Object^ sender, System::EventArgs^ e) { - Opacity = trackBar1->Value/((double)255); - } - }; -} From b72d0652659c0cb65ce348fbc128f252bd2230b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 26 Jul 2008 06:39:44 +0000 Subject: [PATCH 23/47] Minor changes/cleanups. Adventure map is shown :) --- client/Client.cpp | 4 +- lib/Connection.cpp | 32 ----- lib/Connection.h | 149 +++----------------- lib/NetPacks.h | 32 +++++ server/CGameHandler.cpp | 3 +- server/{server_main.cpp => CVCMIServer.cpp} | 0 server/VCMI_server.vcproj | 2 +- 7 files changed, 59 insertions(+), 163 deletions(-) create mode 100644 lib/NetPacks.h rename server/{server_main.cpp => CVCMIServer.cpp} (100%) diff --git a/client/Client.cpp b/client/Client.cpp index b132077a5..124bbf0aa 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -15,11 +15,11 @@ CClient::CClient(void) CClient::CClient(CConnection *con, StartInfo *si) :serv(con) { - timeHandler tmh, pomtime; + timeHandler tmh; CConnection &c(*con); //////////////////////////////////////////////////// ui8 pom8; - c << ui8(2) << ui8(1); + c << ui8(2) << ui8(1); //new game; one client c << *si; c >> pom8; if(pom8) throw "Server cannot open the map!"; diff --git a/lib/Connection.cpp b/lib/Connection.cpp index e0bd9b7cb..bc54c3c32 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -18,38 +18,6 @@ using namespace boost::asio::ip; #define LIL_ENDIAN #endif -//CConnection & operator<<(CConnection &c, const std::string &data) -//{ -// boost::uint32_t length = data.size(); -// c << length; -// c.write(data.c_str(),length); -// return c; -//} -//CConnection & operator>>(CConnection &c, std::string &data) -//{ -// boost::uint32_t length; -// c >> length; -// data.resize(length); -// c.read((void*)data.c_str(),length); -// return c; -//} -//CConnection & operator<<(CConnection &c, const char * &data) -//{ -// boost::uint32_t length = strlen(data); -// c << length; -// c.write(data,length); -// return c; -//} -//CConnection & operator>>(CConnection &c, char * &data) -//{ -// boost::uint32_t length; -// c >> length; -// std::cout <<"Alokujemy " < #include -#include #include #include -#include -#include -#include -#include -#include #include -#include -#include -#include #include #include #include -#include -#include -#include const int version = 63; class CConnection; @@ -243,16 +231,27 @@ public: for(ui32 i=0;i> data[i]; } - //template - //void saveSerializable(T &data) - //{ - // data.serialize(*static_cast(this),version); - //} - //template - //void loadSerializable(T &data) - //{ - // data.serialize(*static_cast(this),version); - //} + template + void saveSerializable(const std::set &data) + { + boost::uint32_t length = data.size(); + *this << length; + for(std::set::iterator i=data.begin();i!=data.end();i++) + *this << *i; + } + template + void loadSerializable(std::set &data) + { + boost::uint32_t length; + *this >> length; + data.resize(length); + T ins; + for(ui32 i=0;i> ins; + data.insert(ins); + } + } template void save(const T &data) @@ -270,6 +269,7 @@ public: >::type typex; typex::invoke(*this, data); } + template void load(T &data) { @@ -308,107 +308,4 @@ public: int read(void * data, unsigned size); int readLine(void * data, unsigned maxSize); ~CConnection(void); -}; - - -//DLL_EXPORT CConnection & operator<<(CConnection &c, const std::string &data); -//DLL_EXPORT CConnection & operator>>(CConnection &c, std::string &data); -//DLL_EXPORT CConnection & operator<<(CConnection &c, const char * &data); -//DLL_EXPORT CConnection & operator>>(CConnection &c, char * &data); -// -//template CConnection & operator<<(CConnection &c, std::vector &data) -//{ -// boost::uint32_t length = data.size(); -// c << length; -// for(ui32 i=0;i CConnection & operator>>(CConnection &c, std::vector &data) -//{ -// boost::uint32_t length; -// c >> length; -// data.resize(length); -// for(ui32 i=0;i> data[i]; -// return c; -//} -//template CConnection & operator<<(CConnection &c, std::set &data) -//{ -// boost::uint32_t length = data.size(); -// c << length; -// for(std::set::iterator i=data.begin();i!=data.end();i++) -// c << *i; -// return c; -//} -//template CConnection & operator>>(CConnection &c, std::set &data) -//{ -// boost::uint32_t length; -// c >> length; -// data.resize(length); -// T pom; -// for(int i=0;i> pom; -// data.insert(pom); -// } -// return c; -//} -//template CConnection & operator<<(CConnection &c, const T &data) -//{ -// c.write(&data,sizeof(data)); -// return c; -//} -//template CConnection & operator>>(CConnection &c, T &data) -//{ -// c.read(&data,sizeof(data)); -// return c; -//} -//template CConnection & operator<(CConnection &c, std::vector &data) -//{ -// boost::uint32_t length = data.size(); -// c << length; -// for(ui32 i=0;i CConnection & operator>(CConnection &c, std::vector &data) -//{ -// boost::uint32_t length; -// c >> length; -// data.resize(length); -// for(ui32 i=0;i CConnection & operator<(CConnection &c, std::set &data) -//{ -// boost::uint32_t length = data.size(); -// c << length; -// for(std::set::iterator i=data.begin();i!=data.end();i++) -// i->serialize(c.send,version); -// return c; -//} -//template CConnection & operator>(CConnection &c, std::set &data) -//{ -// boost::uint32_t length; -// c >> length; -// data.resize(length); -// T pom; -// for(int i=0;i CConnection & operator<(CConnection &c, T &data) -//{ -// data.serialize(c.send,version); -// return c; -//} -//template CConnection & operator>(CConnection &c, T &data) -//{ -// data.serialize(c.rec,version); -// return c; -//} +}; \ No newline at end of file diff --git a/lib/NetPacks.h b/lib/NetPacks.h new file mode 100644 index 000000000..34fbae454 --- /dev/null +++ b/lib/NetPacks.h @@ -0,0 +1,32 @@ +#include "../global.h" + +struct NewTurn +{ + struct Hero + { + ui32 id, move, mana; //id is a general serial id + template void serialize(Handler &h, const int version) + { + h -= id -= move -= mana; + } + }; + struct Resources + { + ui8 player; + si32 resources[RESOURCE_QUANTITY]; + template void serialize(Handler &h, const int version) + { + h -= resources; + } + }; + + std::set heroes; + std::set res; + + + + template void serialize(Handler &h, const int version) + { + h += heroes += res; + } +}; \ No newline at end of file diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index acfd0a4a4..d82e3b4ef 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -50,7 +50,6 @@ CGameHandler::~CGameHandler(void) } void CGameHandler::init(StartInfo *si, int Seed) { - Mapa *map = new Mapa(si->mapname); gs = new CGameState(); gs->init(si,map,Seed); @@ -115,7 +114,7 @@ void CGameHandler::run() {//init conn. ui8 quantity, pom; //ui32 seed; - (*cc) << gs->scenarioOps->mapname;// << gs->map->checksum << seed; + (*cc) << gs->scenarioOps->mapname << gs->map->checksum << gs->seed; (*cc) >> quantity; for(int i=0;i From 88c9d8d72d40b25ed17a286bf2b6bf3508f1f431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 26 Jul 2008 06:42:12 +0000 Subject: [PATCH 24/47] Forgot to add this file --- server/CVCMIServer.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 server/CVCMIServer.h diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h new file mode 100644 index 000000000..ad1a26af1 --- /dev/null +++ b/server/CVCMIServer.h @@ -0,0 +1,31 @@ +#pragma once +#include "../global.h" +#include +namespace boost +{ + namespace asio + { + class io_service; + namespace ip + { + class tcp; + } + template class socket_acceptor_service; + template + class basic_socket_acceptor; + } +}; + +class CVCMIServer +{ + boost::asio::io_service *io; + boost::asio::basic_socket_acceptor > * acceptor; + std::map connections; + std::set conns; +public: + CVCMIServer(); + ~CVCMIServer(); + void setUpConnection(CConnection *c, std::string mapname, si32 checksum); + void newGame(CConnection &c); + void start(); +}; \ No newline at end of file From b3c5f19c0d0fd8cdae69a68d7ad87c319f83a34e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 26 Jul 2008 13:57:32 +0000 Subject: [PATCH 25/47] Proper initialization of the first turn. --- CGameState.cpp | 28 ++++++++++++++++++- CGameState.h | 2 ++ client/Client.cpp | 24 ++++++++++++---- lib/Connection.cpp | 9 ++++-- lib/Connection.h | 16 +++++------ lib/NetPacks.h | 30 ++++++++++++++------ server/CGameHandler.cpp | 62 +++++++++++++++++++++++++---------------- server/CGameHandler.h | 3 ++ 8 files changed, 125 insertions(+), 49 deletions(-) diff --git a/CGameState.cpp b/CGameState.cpp index 5dc48b13c..38274bc59 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -20,7 +20,8 @@ #include "CLua.h" #include "CCallback.h" #include "CLuaHandler.h" - +#include "lib/NetPacks.h" +#include boost::rand48 ran; class CMP_stack @@ -36,6 +37,30 @@ CStack::CStack(CCreature * C, int A, int O, int I, bool AO) :creature(C),amount(A),owner(O), alive(true), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints) { } +void CGameState::apply(IPack * pack) +{ + switch(pack->getType()) + { + case 101://NewTurn + { + NewTurn * n = static_cast(pack); + day = n->day; + BOOST_FOREACH(NewTurn::Hero h, n->heroes) //give mana/movement point + { + static_cast(map->objects[h.id])->movement = h.move; + static_cast(map->objects[h.id])->mana = h.mana; + } + BOOST_FOREACH(NewTurn::Resources h, n->res) //give resources + { + for(int i=0;iresetBuilded) //reset amount of structures set in this turn in towns + BOOST_FOREACH(CGTownInstance* t, map->towns) + t->builded = 0; + } + } +} int CGameState::pickHero(int owner) { int h=-1; @@ -279,6 +304,7 @@ int CGameState::getDate(int mode) const } void CGameState::init(StartInfo * si, Mapa * map, int Seed) { + day = 0; seed = Seed; ran.seed((long)seed); scenarioOps = si; diff --git a/CGameState.h b/CGameState.h index 725146fbf..71945e00c 100644 --- a/CGameState.h +++ b/CGameState.h @@ -23,6 +23,7 @@ struct StartInfo; struct SDL_Surface; class CMapHandler; class CPathfinder; +struct IPack; struct DLL_EXPORT PlayerState { @@ -90,6 +91,7 @@ private: } void init(StartInfo * si, Mapa * map, int Seed); + void apply(IPack * pack); void randomizeObject(CGObjectInstance *cur); std::pair pickObject(CGObjectInstance *obj); int pickHero(int owner); diff --git a/client/Client.cpp b/client/Client.cpp index 124bbf0aa..8c83ab03a 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -8,6 +8,7 @@ #include "../CCallback.h" #include "../CPlayerInterface.h" #include "../CConsoleHandler.h" +#include "../lib/NetPacks.h" CClient::CClient(void) { @@ -74,11 +75,24 @@ void CClient::process(int what) switch (what) { case 100: //one of our interaces has turn - ui8 player; - *serv >> player;//who? - CGI->playerint[gs->players[player].serial]->yourTurn(); - *serv << ui16(100); //report that we ended turn - break; + { + ui8 player; + *serv >> player;//who? + std::cout << "It's turn of "<<(unsigned)player<<" player."<playerint[gs->players[player].serial]->yourTurn(); + *serv << ui16(100); //report that we ended turn + std::cout << "Player "<<(unsigned)player<<" end his turn."<> n; + std::cout << "New day: "<<(unsigned)n.day<<". Applying changes... "; + gs->apply(&n); + std::cout << "done!"< +#include using namespace boost; using namespace boost::asio::ip; @@ -31,6 +32,8 @@ void CConnection::init() (*this) << std::string("Aiya!\n") << name << myEndianess; //identify ourselves (*this) >> pom >> pom >> contactEndianess; out << "Established connection with "<close(); delete socket; delete io_service; + delete wmx; + delete rmx; } diff --git a/lib/Connection.h b/lib/Connection.h index cb945439f..21bedabd1 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -60,7 +60,7 @@ struct SerializationLevel //else typename mpl::eval_if< boost::is_array, - mpl::int_, + mpl::int_, //else typename mpl::eval_if< boost::is_enum, @@ -91,7 +91,7 @@ public: } template - Serializer & operator&(T & t){ + COSer & operator&(T & t){ return * this->This() << t; } }; @@ -112,7 +112,7 @@ public: } template - Serializer & operator&(T & t){ + CISer & operator&(T & t){ return * this->This() >> t; } }; @@ -176,7 +176,7 @@ class DLL_EXPORT CConnection std::ostream &out; CConnection(void); void init(); - boost::mutex *mx; + boost::mutex *rmx, *wmx; // read/write mutexes public: template @@ -234,9 +234,10 @@ public: template void saveSerializable(const std::set &data) { - boost::uint32_t length = data.size(); + std::set &d = const_cast &>(data); + boost::uint32_t length = d.size(); *this << length; - for(std::set::iterator i=data.begin();i!=data.end();i++) + for(std::set::iterator i=d.begin();i!=d.end();i++) *this << *i; } template @@ -244,7 +245,6 @@ public: { boost::uint32_t length; *this >> length; - data.resize(length); T ins; for(ui32 i=0;i > * socket; bool logging; bool connected; diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 34fbae454..c8dc2edea 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -1,14 +1,25 @@ #include "../global.h" - -struct NewTurn +struct IPack +{ + virtual ui16 getType()=0; +}; +template struct CPack + :public IPack +{ + ui16 type; + ui16 getType(){return type;} + T* This(){return static_cast(this);}; +}; +struct NewTurn : public CPack //101 { struct Hero { ui32 id, move, mana; //id is a general serial id template void serialize(Handler &h, const int version) { - h -= id -= move -= mana; + h & id & move & mana; } + bool operator<(const Hero&h)const{return id < h.id;} }; struct Resources { @@ -16,17 +27,20 @@ struct NewTurn si32 resources[RESOURCE_QUANTITY]; template void serialize(Handler &h, const int version) { - h -= resources; + h & player & resources; } + bool operator<(const Resources&h)const{return player < h.player;} }; - std::set heroes; - std::set res; - + std::set heroes; //updates movement and mana points + std::set res;//resource list + ui32 day; + bool resetBuilded; + NewTurn(){type = 101;}; template void serialize(Handler &h, const int version) { - h += heroes += res; + h & heroes & res & day & resetBuilded; } }; \ No newline at end of file diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index d82e3b4ef..92c49ebcd 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -38,7 +38,11 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) } } } - +template void CGameHandler::sendToAllClients(CPack * info) +{ + BOOST_FOREACH(CConnection* c, conns) + *c << info->getType() << *info->This(); +} CGameHandler::CGameHandler(void) { gs = NULL; @@ -76,37 +80,46 @@ int valMovePoints(CGHeroInstance * chi) } void CGameHandler::newTurn() { - //std::map::iterator i = gs->players.begin() ; - gs->day++; + NewTurn n; + n.day = gs->day + 1; + for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) { - //handle heroes///////////////////////////// - for (unsigned j=0;j<(*i).second.heroes.size();j++) + if(i->first>=PLAYER_LIMIT) continue; + NewTurn::Resources r; + r.player = i->first; + for(int j=0;jsecond.resources[j]; + + for (unsigned j=0;j<(*i).second.heroes.size();j++) //handle heroes { - (*i).second.heroes[j]->movement = valMovePoints((*i).second.heroes[j]); + NewTurn::Hero h; + h.id = (*i).second.heroes[j]->id; + h.move = valMovePoints((*i).second.heroes[j]); + h.mana = (*i).second.heroes[j]->mana; + n.heroes.insert(h); } - - - //handle towns///////////////////////////// - for(unsigned j=0;jsecond.towns.size();j++) + for(unsigned j=0;jsecond.towns.size();j++)//handle towns { i->second.towns[j]->builded=0; - if(gs->getDate(1)==1) //first day of week - { - for(int k=0;ksecond.towns[j]->creatureDwelling(k))//there is dwelling (k-level) - i->second.towns[j]->strInfo.creatures[k]+=i->second.towns[j]->creatureGrowth(k); - } - } - if((gs->day>1) && i->firstsecond.resources[6]+=i->second.towns[j]->dailyIncome(); + //if(gs->getDate(1)==1) //first day of week + //{ + // for(int k=0;ksecond.towns[j]->creatureDwelling(k))//there is dwelling (k-level) + // i->second.towns[j]->strInfo.creatures[k]+=i->second.towns[j]->creatureGrowth(k); + // } + //} + if((gs->day>1) && i->firstsecond.towns[j]->dailyIncome(); } + n.res.insert(r); } - for (std::set::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++) - { - (*i)->newTurn(); - } + sendToAllClients(&n); + //for (std::set::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++) + //{ + // (*i)->newTurn(); + //} } void CGameHandler::run() { @@ -136,6 +149,7 @@ void CGameHandler::run() } while (1) { + newTurn(); for(std::map::iterator i = gs->players.begin(); i != gs->players.end(); i++) { if((i->second.towns.size()==0 && i->second.heroes.size()==0) || i->second.color<0) continue; //players has not towns/castle - loser diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 726d369c0..d29bce860 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -5,6 +5,8 @@ class CVCMIServer; class CGameState; class CConnection; struct StartInfo; +template struct CPack; + class CGameHandler { CGameState *gs; @@ -16,6 +18,7 @@ public: ~CGameHandler(void); void init(StartInfo *si, int Seed); void handleConnection(std::set players, CConnection &c); + template void sendToAllClients(CPack * info); void run(); void newTurn(); From 62b0365e7080666524961b1b95efa4a6dbf913b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sun, 27 Jul 2008 17:07:37 +0000 Subject: [PATCH 26/47] Improvements for netcode. AI is working. Townlist won't crash. Moving hero is wrong but won't crash. Giving starting hero is working properly. Town defs are wrong but displayed. --- AI/EmptyAI/CEmptyAI.cpp | 1 + AI/EmptyAI/exp_funcs.cpp | 12 ++-- AI_Base.h | 12 +--- CAdvmapInterface.cpp | 24 +++---- CCallback.cpp | 12 +++- CCallback.h | 7 +- CGameState.cpp | 115 +++++++++++++++++++++++++++++- CGameState.h | 20 +++--- CMT.cpp | 31 ++++++--- CPlayerInterface.cpp | 23 ++++-- CPlayerInterface.h | 2 + client/Client.cpp | 31 +++------ client/Client.h | 3 + global.h | 4 -- lib/Connection.h | 2 +- map.h | 2 +- mapHandler.cpp | 146 +++++++++------------------------------ server/CGameHandler.cpp | 58 +++++++++++----- server/CVCMIServer.cpp | 19 ++--- 19 files changed, 290 insertions(+), 234 deletions(-) diff --git a/AI/EmptyAI/CEmptyAI.cpp b/AI/EmptyAI/CEmptyAI.cpp index 345659259..658b947e0 100644 --- a/AI/EmptyAI/CEmptyAI.cpp +++ b/AI/EmptyAI/CEmptyAI.cpp @@ -10,6 +10,7 @@ void CEmptyAI::init(ICallback * CB) } void CEmptyAI::yourTurn() { + cb->endTurn(); } void CEmptyAI::heroKilled(const CGHeroInstance *) { diff --git a/AI/EmptyAI/exp_funcs.cpp b/AI/EmptyAI/exp_funcs.cpp index 769885432..1c700fe5d 100644 --- a/AI/EmptyAI/exp_funcs.cpp +++ b/AI/EmptyAI/exp_funcs.cpp @@ -1,30 +1,30 @@ +#define VCMI_DLL #include "../../AI_Base.h" #include "CEmptyAI.h" #include #include std::set ais; - -DLL_EXPORT int GetGlobalAiVersion() +extern "C" DLL_EXPORT int GetGlobalAiVersion() { return AI_INTERFACE_VER; } -DLL_EXPORT void GetAiName(char* name) +extern "C" DLL_EXPORT void GetAiName(char* name) { strcpy(name,NAME); } -DLL_EXPORT char * GetAiNameS() +extern "C" DLL_EXPORT char * GetAiNameS() { char * ret = new char[50]; strcpy(ret,NAME); return ret; } -DLL_EXPORT CGlobalAI * GetNewAI() +extern "C" DLL_EXPORT CGlobalAI * GetNewAI() { return new CEmptyAI(); // return } -DLL_EXPORT void ReleaseAI(CGlobalAI * i) +extern "C" DLL_EXPORT void ReleaseAI(CGlobalAI * i) { delete (CEmptyAI*)i; ais.erase(i); diff --git a/AI_Base.h b/AI_Base.h index 2a4247d5e..90be85824 100644 --- a/AI_Base.h +++ b/AI_Base.h @@ -1,16 +1,6 @@ #pragma once #include #include -#include "int3.h" #include "CGameInterface.h" -#define AI_INTERFACE_VER 1 -#ifdef _WIN32 - #define DLL_EXPORT extern "C" __declspec(dllexport) - #define VCMI_API -#elif __GNUC__ >= 4 - #define DLL_EXPORT extern "C" __attribute__ ((visibility("default"))) - #define VCMI_API __attribute__ ((visibility("default"))) -#else - #define VCMI_EXPORT extern "C" -#endif \ No newline at end of file +#define AI_INTERFACE_VER 1 \ No newline at end of file diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 7fc291a09..25f3dea3a 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -216,17 +216,17 @@ void CMinimap::deactivate() } void CMinimap::showTile(int3 pos) { - int mw = map[0]->w, mh = map[0]->h; - double wo = ((double)mw)/CGI->mh->sizes.x, ho = ((double)mh)/CGI->mh->sizes.y; - for (int ii=0; iipos.w) && (pos.y*ho+jjpos.h)) - CSDL_Ext::SDL_PutPixel(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0,0); + //int mw = map[0]->w, mh = map[0]->h; + //double wo = ((double)mw)/CGI->mh->sizes.x, ho = ((double)mh)/CGI->mh->sizes.y; + //for (int ii=0; iipos.w) && (pos.y*ho+jjpos.h)) + // CSDL_Ext::SDL_PutPixel(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0,0); - } - } + // } + //} } void CMinimap::hideTile(int3 pos) { @@ -598,10 +598,6 @@ CResDataBar::CResDataBar() { bg = BitmapHandler::loadBitmap("ZRESBAR.bmp"); SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); - //std::vector kolory; - //SDL_Color p1={40,65,139,255}, p2={36,59,125,255}, p3={35,56,121,255}; - //kolory+=p1,p2,p3; - //blueToPlayersAdv(bg,LOCPLINT->playerID,2,&kolory); graphics->blueToPlayersAdv(bg,LOCPLINT->playerID); pos = genRect(bg->h,bg->w,3,575); diff --git a/CCallback.cpp b/CCallback.cpp index 9673576c0..fb8f4552a 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -14,6 +14,9 @@ #include "CPlayerInterface.h" #include "hch/CBuildingHandler.h" #include "hch/CObjectHandler.h" +#include "lib/Connection.h" +#include "client/Client.h" +#include //LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) @@ -205,7 +208,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 = std::min(amount,av->second); //reduce recruited amount up to available amount + amount = min(amount,av->second); //reduce recruited amount up to available amount ser = av->first; break; } @@ -272,6 +275,13 @@ bool CCallback::upgradeCreature(const CArmedInstance *obj, int stackPos, int new //TODO: write return false; } +void CCallback::endTurn() +{ + std::cout << "Player "<<(unsigned)player<<" end his turn."<serv->wmx->lock(); + *cl->serv << ui16(100); //report that we ended turn + cl->serv->wmx->unlock(); +} UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos) { UpgradeInfo ret; diff --git a/CCallback.h b/CCallback.h index 34bf91854..9b3f5cd71 100644 --- a/CCallback.h +++ b/CCallback.h @@ -17,6 +17,7 @@ class CGTownInstance; struct StartInfo; class CStack; struct lua_State; +class CClient; //structure gathering info about upgrade possibilites struct UpgradeInfo { @@ -39,6 +40,7 @@ public: virtual void recruitCreatures(const CGObjectInstance *obj, int ID, int amount)=0; virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0; virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1)=0; //if newID==-1 then best possible upgrade will be made + virtual void endTurn()=0; //get info virtual bool verifyPath(CPath * path, bool blockSea)=0; @@ -85,8 +87,9 @@ struct HeroMoveDetails class CCallback : public ICallback { private: - CCallback(CGameState * GS, int Player):gs(GS),player(Player){}; + CCallback(CGameState * GS, int Player, CClient *C):gs(GS),player(Player),cl(C){}; CGameState * gs; + CClient *cl; bool isVisible(int3 pos, int Player); protected: @@ -106,7 +109,7 @@ public: void recruitCreatures(const CGObjectInstance *obj, int ID, int amount); bool dismissCreature(const CArmedInstance *obj, int stackPos); bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1); - + void endTurn(); //get info bool verifyPath(CPath * path, bool blockSea); diff --git a/CGameState.cpp b/CGameState.cpp index 38274bc59..c1d7118f6 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -22,6 +22,8 @@ #include "CLuaHandler.h" #include "lib/NetPacks.h" #include +#include +#include boost::rand48 ran; class CMP_stack @@ -33,12 +35,80 @@ public: } } cmpst ; +CGObjectInstance * createObject(int id, int subid, int3 pos, int owner) +{ + CGObjectInstance * nobj; + switch(id) + { + case 34: //hero + { + CGHeroInstance * nobj; + nobj = new CGHeroInstance(); + nobj->pos = pos; + nobj->tempOwner = owner; + nobj->defInfo = new CGDefInfo(); + nobj->defInfo->id = 34; + nobj->defInfo->subid = subid; + nobj->defInfo->printPriority = 0; + nobj->type = VLC->heroh->heroes[subid]; + for(int i=0;i<6;i++) + { + nobj->defInfo->blockMap[i]=255; + nobj->defInfo->visitMap[i]=0; + } + nobj->ID = id; + nobj->subID = subid; + nobj->defInfo->handler=NULL; + nobj->defInfo->blockMap[5] = 253; + nobj->defInfo->visitMap[5] = 2; + nobj->artifacts.resize(20); + nobj->artifWorn[16] = 3; + nobj->primSkills.resize(4); + nobj->primSkills[0] = nobj->type->heroClass->initialAttack; + nobj->primSkills[1] = nobj->type->heroClass->initialDefence; + nobj->primSkills[2] = nobj->type->heroClass->initialPower; + nobj->primSkills[3] = nobj->type->heroClass->initialKnowledge; + nobj->mana = 10 * nobj->primSkills[3]; + return nobj; + } + case 98: //town + nobj = new CGTownInstance; + break; + default: //rest of objects + nobj = new CGObjectInstance; + nobj->defInfo = VLC->dobjinfo->gobjs[id][subid]; + break; + } + nobj->ID = id; + nobj->subID = subid; + if(!nobj->defInfo) + std::cout <<"No def declaration for " <pos = pos; + //nobj->state = NULL;//new CLuaObjectScript(); + nobj->tempOwner = owner; + nobj->info = NULL; + nobj->defInfo->id = id; + nobj->defInfo->subid = subid; + + //assigning defhandler + if(nobj->ID==34 || nobj->ID==98) + return nobj; + nobj->defInfo = VLC->dobjinfo->gobjs[id][subid]; + //if(!nobj->defInfo->handler) + //{ + // nobj->defInfo->handler = CDefHandler::giveDef(nobj->defInfo->name); + // nobj->defInfo->width = nobj->defInfo->handler->ourImages[0].bitmap->w/32; + // nobj->defInfo->height = nobj->defInfo->handler->ourImages[0].bitmap->h/32; + //} + return nobj; +} CStack::CStack(CCreature * C, int A, int O, int I, bool AO) :creature(C),amount(A),owner(O), alive(true), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints) { } void CGameState::apply(IPack * pack) { + mx->lock(); switch(pack->getType()) { case 101://NewTurn @@ -60,6 +130,7 @@ void CGameState::apply(IPack * pack) t->builded = 0; } } + mx->unlock(); } int CGameState::pickHero(int owner) { @@ -302,6 +373,26 @@ int CGameState::getDate(int mode) const } return 0; } +CGameState::CGameState() +{ + mx = new boost::shared_mutex(); +} +CGameState::~CGameState() +{ + delete mx; +} +bool CGameState::checkFunc(int obid, std::string name) +{ + if (objscr.find(obid)!=objscr.end()) + { + if(objscr[obid].find(name)!=objscr[obid].end()) + { + return true; + } + } + return false; +} + void CGameState::init(StartInfo * si, Mapa * map, int Seed) { day = 0; @@ -339,9 +430,29 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed) } //std::cout<<"\tRandomizing objects: "<players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE)) + { + int3 hpos = map->players[i].posOfMainTown; + hpos.x+=1;// hpos.y+=1; + int j; + for(j=0; jplayerInfos.size(); j++) + if(scenarioOps->playerInfos[j].color == i) + break; + if(j == scenarioOps->playerInfos.size()) + continue; + int h=pickHero(i); + CGHeroInstance * nnn = static_cast(createObject(34,h,hpos,i)); + nnn->id = map->objects.size(); + //nnn->defInfo->handler = graphics->flags1[0]; + map->heroes.push_back(nnn); + map->objects.push_back(nnn); + } + } + //std::cout<<"\tGiving starting heroes: "<playerInfos.size();i++) { diff --git a/CGameState.h b/CGameState.h index 71945e00c..5c551e1a5 100644 --- a/CGameState.h +++ b/CGameState.h @@ -25,6 +25,11 @@ class CMapHandler; class CPathfinder; struct IPack; +namespace boost +{ + class shared_mutex; +} + struct DLL_EXPORT PlayerState { public: @@ -78,18 +83,11 @@ private: std::map villages, forts, capitols; //def-info for town graphics - bool checkFunc(int obid, std::string name) - { - if (objscr.find(obid)!=objscr.end()) - { - if(objscr[obid].find(name)!=objscr[obid].end()) - { - return true; - } - } - return false; - } + boost::shared_mutex *mx; + CGameState(); + ~CGameState(); + bool checkFunc(int obid, std::string name); void init(StartInfo * si, Mapa * map, int Seed); void apply(IPack * pack); void randomizeObject(CGObjectInstance *cur); diff --git a/CMT.cpp b/CMT.cpp index 6c3df98cf..12b45bcf1 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include "SDL_TTF.h" @@ -44,6 +45,10 @@ std::string NAME = NAME_VER + std::string(" (client)"); DLL_EXPORT void initDLL(CLodHandler *b); SDL_Surface * screen, * screen2; extern SDL_Surface * CSDL_Ext::std32bppSurface; + +std::queue events; +boost::mutex eventsM; + TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; void handleCPPObjS(std::map * mapa, CCPPObjectScript * script) { @@ -56,9 +61,7 @@ void handleCPPObjS(std::map * mapa, CCPPObjectScript * sc } int _tmain(int argc, _TCHAR* argv[]) { - //boost::thread servthr(boost::bind(system,"VCMI_server.exe")); //runs server executable; - //TODO: add versions for other platforms - + std::cout.flags(ios::unitbuf); std::cout << NAME << std::endl; srand ( time(NULL) ); CPG=NULL; @@ -146,9 +149,8 @@ int _tmain(int argc, _TCHAR* argv[]) StartInfo *options = new StartInfo(cpg->runLoop()); /////////////////////////////////////////////////////////////////////////////////////// - cgi->state = new CGameState(); - THC std::cout<<"\tGamestate: "< server_log.txt")); //runs server executable; + //TODO: will it work on non-windows platforms? THC tmh.getDif();pomtime.getDif();//reset timers @@ -173,9 +175,23 @@ int _tmain(int argc, _TCHAR* argv[]) std::ofstream lll("client_log.txt"); CConnection c("localhost","3030",NAME,lll); THC std::cout<<"\tConnecting to the server: "< #include "CPlayerInterface.h" #include "CAdvmapInterface.h" #include "CMessage.h" @@ -20,6 +21,7 @@ #include "CCastleInterface.h" #include "CHeroWindow.h" #include "timeHandler.h" +#include #include #include #include "hch/CPreGameTextHandler.h" @@ -35,6 +37,9 @@ using namespace CSDL_Ext; extern TTF_Font * GEOR16; extern bool continueReadingConsole; +CPlayerInterface * LOCPLINT; +extern std::queue events; +extern boost::mutex eventsM; class OCM_HLP_CGIN { @@ -894,6 +899,7 @@ void TimeInterested::deactivate() } CPlayerInterface::CPlayerInterface(int Player, int serial) { + LOCPLINT = this; playerID=Player; serialID=serial; CGI->localPlayer = playerID; @@ -920,6 +926,7 @@ void CPlayerInterface::init(ICallback * CB) } void CPlayerInterface::yourTurn() { + LOCPLINT = this; makingTurn = true; CGI->localPlayer = serialID; unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling @@ -977,10 +984,13 @@ void CPlayerInterface::yourTurn() timeinterested[i]->tick(); } LOCPLINT->adventureInt->updateScreen = false; - while (SDL_PollEvent(&sEvent)) //wait for event... + eventsM.lock(); + while(!events.empty()) { - handleEvent(&sEvent); + handleEvent(&events.front()); + events.pop(); } + eventsM.unlock(); if (!castleInt) //stuff for advMapInt { ++LOCPLINT->adventureInt->animValHitCount; //for animations @@ -1047,6 +1057,7 @@ void CPlayerInterface::yourTurn() SDL_framerateDelay(mainFPSmng); } adventureInt->hide(); + cb->endTurn(); } inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid) @@ -2051,7 +2062,7 @@ CStatusBar::CStatusBar(int x, int y, std::string name, int maxw) pos.x=x; pos.y=y; if(maxw >= 0) - pos.w = std::min(bg->w,maxw); + pos.w = min(bg->w,maxw); else pos.w=bg->w; pos.h=bg->h; @@ -2437,7 +2448,7 @@ void CTownList::mouseMoved (SDL_MouseMotionEvent & sEvent) LOCPLINT->statusbar->clear(); return; }; - LOCPLINT->statusbar->print(items[from+ny]->state->hoverText(const_cast(items[from+ny]))); + LOCPLINT->statusbar->print(items[from+ny]->name); } void CTownList::clickLeft(tribool down) @@ -2630,7 +2641,7 @@ void CRecrutationWindow::clickLeft(tribool down) if(isItIn(&genRect(132,102,pos.x+curx,pos.y+64),LOCPLINT->current->motion.x,LOCPLINT->current->motion.y)) { which = i; - int newAmount = std::min(amounts[i],creatures[i].amount); + int newAmount = min(amounts[i],creatures[i].amount); slider->amount = newAmount; if(slider->value > newAmount) slider->moveTo(newAmount); @@ -2727,7 +2738,7 @@ CRecrutationWindow::CRecrutationWindow(const std::vector > &C pos.y = screen->h/2 - bitmap->h/2; pos.w = bitmap->w; pos.h = bitmap->h; - slider = new CSlider(pos.x+176,pos.y+279,135,boost::bind(&CRecrutationWindow::sliderMoved,this, _1),1,std::min(amounts[0],creatures[0].amount),0,true); + slider = new CSlider(pos.x+176,pos.y+279,135,boost::bind(&CRecrutationWindow::sliderMoved,this, _1),1,min(amounts[0],creatures[0].amount),0,true); std::string pom; printAtMiddle(CGI->generaltexth->allTexts[346],113,231,GEOR13,zwykly,bitmap); //cost per troop t printAtMiddle(CGI->generaltexth->allTexts[465],205,231,GEOR13,zwykly,bitmap); //available t diff --git a/CPlayerInterface.h b/CPlayerInterface.h index 8097dd505..d3efc047a 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -524,4 +524,6 @@ public: void show(SDL_Surface * to = NULL); }; +extern CPlayerInterface * LOCPLINT; + #endif //CPLAYERINTERFACE_H \ No newline at end of file diff --git a/client/Client.cpp b/client/Client.cpp index 8c83ab03a..d4c75e38b 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -9,14 +9,17 @@ #include "../CPlayerInterface.h" #include "../CConsoleHandler.h" #include "../lib/NetPacks.h" - +#include +#include CClient::CClient(void) { } CClient::CClient(CConnection *con, StartInfo *si) :serv(con) -{ +{ timeHandler tmh; + CGI->state = new CGameState(); + THC std::cout<<"\tGamestate: "<state->scenarioOps->playerInfos.size();i++) //initializing interfaces { - + CCallback *cb = new CCallback(CGI->state,CGI->state->scenarioOps->playerInfos[i].color,this); if(!CGI->state->scenarioOps->playerInfos[i].human) - CGI->playerint.push_back(static_cast(CAIHandler::getNewAI(new CCallback(CGI->state,CGI->state->scenarioOps->playerInfos[i].color),"EmptyAI.dll"))); + CGI->playerint.push_back(static_cast(CAIHandler::getNewAI(cb,"EmptyAI.dll"))); else { CGI->state->currentPlayer=CGI->state->scenarioOps->playerInfos[i].color; CGI->playerint.push_back(new CPlayerInterface(CGI->state->scenarioOps->playerInfos[i].color,i)); - ((CPlayerInterface*)(CGI->playerint[i]))->init(new CCallback(CGI->state,CGI->state->scenarioOps->playerInfos[i].color)); + ((CPlayerInterface*)(CGI->playerint[i]))->init(cb); } } - CGI->consoleh->cb = new CCallback(CGI->state,-1); + CGI->consoleh->cb = new CCallback(CGI->state,-1,this); } CClient::~CClient(void) { @@ -79,9 +82,7 @@ void CClient::process(int what) ui8 player; *serv >> player;//who? std::cout << "It's turn of "<<(unsigned)player<<" player."<playerint[gs->players[player].serial]->yourTurn(); - *serv << ui16(100); //report that we ended turn - std::cout << "Player "<<(unsigned)player<<" end his turn."<playerint[gs->players[player].serial])); break; } case 101: @@ -109,16 +110,4 @@ void CClient::run() process(typ); } } HANDLE_EXCEPTION - //while(1) //main game loop, one execution per turn - //{ - // CGI->consoleh->cb->newTurn(); - // for (int i=0;iplayerint.size();i++) - // { - // CGI->state->currentPlayer=CGI->playerint[i]->playerID; - // try - // { - // CGI->playerint[i]->yourTurn(); - // }HANDLE_EXCEPTION - // } - //} } \ No newline at end of file diff --git a/client/Client.h b/client/Client.h index 962f77207..893dd3532 100644 --- a/client/Client.h +++ b/client/Client.h @@ -4,6 +4,7 @@ struct StartInfo; class CGameState; class CGameInterface; class CConnection; +class CCallback; class CClient { CGameState *gs; @@ -16,4 +17,6 @@ public: void process(int what); void run(); + + friend class CCallback; }; diff --git a/global.h b/global.h index 0634bbd50..51d66a917 100644 --- a/global.h +++ b/global.h @@ -31,10 +31,6 @@ enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHE HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST}; class CGameInfo; extern CGameInfo* CGI; -#define CURPLINT (((CPlayerInterface*)((CGI)->playerint[(CGI)->state->currentPlayer]))) -#define LOCPLINT (((CPlayerInterface*)((CGI)->playerint[(CGI)->localPlayer]))) -//CURPLINT gives pointer to the interface of human player which is currently making turn, -//LOCPLINT gives pointer to the interface which is currently showed (on this machine) #define HEROI_TYPE (0) #define TOWNI_TYPE (1) diff --git a/lib/Connection.h b/lib/Connection.h index 21bedabd1..69621b2e0 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -176,8 +176,8 @@ class DLL_EXPORT CConnection std::ostream &out; CConnection(void); void init(); - boost::mutex *rmx, *wmx; // read/write mutexes public: + boost::mutex *rmx, *wmx; // read/write mutexes template void savePrimitive(const T &data) diff --git a/map.h b/map.h index 16c822380..d73d1ddc9 100644 --- a/map.h +++ b/map.h @@ -462,7 +462,7 @@ struct DLL_EXPORT Mapa std::vector disposedHeroes; std::vector predefinedHeroes; std::vector defy; // list of .def files with definitions from .h3m (may be custom) - std::set defs; // other defInfos - for randomized objects, objects added or modified by script + std::set defs; // other defInfos - for randomized objects, objects added or modified by scripts PlayerInfo players[8]; // info about players std::vector teams; // teams[i] = team of player no i LossCondition lossCondition; diff --git a/mapHandler.cpp b/mapHandler.cpp index 9df769597..30e859301 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -568,34 +568,41 @@ void CMapHandler::init() { timeHandler th; th.getDif(); - loadDefs(); + loadDefs(); //loading castles' defs THC std::cout<<"Reading terrain defs: "<>ccc; + for(int i=0;istate->villages[i]; + map->defs.insert(CGI->state->forts[i]); + } + else + n = CGI->state->capitols[i%ccc]; + ifs >> n->name; + map->defs.insert(n); + } + std::cout<<"\tLoading town def info: "<heroes.size();i++) + { + if(!map->heroes[i]->defInfo->handler) + { + map->heroes[i]->defInfo->handler = graphics->flags1[0]; + map->heroes[i]->defInfo->width = map->heroes[i]->defInfo->handler->ourImages[0].bitmap->w/32; + map->heroes[i]->defInfo->height = map->heroes[i]->defInfo->handler->ourImages[0].bitmap->h/32; + } + } + std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs std::for_each(map->defs.begin(),map->defs.end(),processDef); //and non-h3m defs THC std::cout<<"\tUnpacking and handling defs: "<>ccc; - //for(int i=0;idobjinfo->castles[i%ccc]); - // ifs >> n->name; - // if (!(n->handler = CDefHandler::giveDef(n->name))) - // std::cout << "Cannot open "<name<width = n->handler->ourImages[0].bitmap->w/32; - // n->height = n->handler->ourImages[0].bitmap->h/32; - // } - // if(iplayers[i].heroesNames.size();j++) @@ -603,7 +610,7 @@ void CMapHandler::init() usedHeroes.insert(map->players[i].heroesNames[j].heroID); } } - std::cout<<"\tLoading town defs, picking random factions and heroes: "<players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE)) - // { - // int3 hpos = map->players[i].posOfMainTown; - // hpos.x+=1;// hpos.y+=1; - // int j; - // for(j=0;jstate->scenarioOps->playerInfos.size();j++) - // if(CGI->state->scenarioOps->playerInfos[j].color==i) - // break; - // if(j==CGI->state->scenarioOps->playerInfos.size()) - // continue; - // int h=pickHero(i); - // CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i); - // nnn->defInfo->handler = graphics->flags1[0]; - // map->heroes.push_back(nnn); - // map->objects.push_back(nnn); - // } - //} - std::cout<<"\tGiving starting heroes: "< CMapHandler::getVisitableObjs(int3 pos) return ret; } -CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos, int owner) -{ - CGObjectInstance * nobj; - switch(id) - { - case 34: //hero - { - CGHeroInstance * nobj; - nobj = new CGHeroInstance(); - nobj->pos = pos; - nobj->tempOwner = owner; - nobj->defInfo = new CGDefInfo(); - nobj->defInfo->id = 34; - nobj->defInfo->subid = subid; - nobj->defInfo->printPriority = 0; - nobj->type = CGI->heroh->heroes[subid]; - for(int i=0;i<6;i++) - { - nobj->defInfo->blockMap[i]=255; - nobj->defInfo->visitMap[i]=0; - } - nobj->ID = id; - nobj->subID = subid; - nobj->defInfo->handler=NULL; - nobj->defInfo->blockMap[5] = 253; - nobj->defInfo->visitMap[5] = 2; - nobj->artifacts.resize(20); - nobj->artifWorn[16] = 3; - nobj->primSkills.resize(4); - nobj->primSkills[0] = nobj->type->heroClass->initialAttack; - nobj->primSkills[1] = nobj->type->heroClass->initialDefence; - nobj->primSkills[2] = nobj->type->heroClass->initialPower; - nobj->primSkills[3] = nobj->type->heroClass->initialKnowledge; - nobj->mana = 10 * nobj->primSkills[3]; - return nobj; - } - case 98: //town - nobj = new CGTownInstance; - break; - default: //rest of objects - nobj = new CGObjectInstance; - nobj->defInfo = CGI->dobjinfo->gobjs[id][subid]; - break; - } - nobj->ID = id; - nobj->subID = subid; - if(!nobj->defInfo) - std::cout <<"No def declaration for " <pos = pos; - //nobj->state = NULL;//new CLuaObjectScript(); - nobj->tempOwner = owner; - nobj->info = NULL; - nobj->defInfo->id = id; - nobj->defInfo->subid = subid; - - //assigning defhandler - if(nobj->ID==34 || nobj->ID==98) - return nobj; - nobj->defInfo = CGI->dobjinfo->gobjs[id][subid]; - if(!nobj->defInfo->handler) - { - nobj->defInfo->handler = CDefHandler::giveDef(nobj->defInfo->name); - nobj->defInfo->width = nobj->defInfo->handler->ourImages[0].bitmap->w/32; - nobj->defInfo->height = nobj->defInfo->handler->ourImages[0].bitmap->h/32; - } - return nobj; -} - std::string CMapHandler::getDefName(int id, int subid) { CGDefInfo* temp = CGI->dobjinfo->gobjs[id][subid]; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 92c49ebcd..498ee2042 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -12,7 +12,8 @@ #include "../hch/CObjectHandler.h" #include "../hch/CTownHandler.h" #include "../hch/CHeroHandler.h" - +#include "boost/date_time/posix_time/posix_time_types.hpp" //no i/o just types +extern bool end; bool makingTurn; boost::condition_variable cTurn; boost::mutex mTurn; @@ -20,23 +21,41 @@ boost::shared_mutex gsm; void CGameHandler::handleConnection(std::set players, CConnection &c) { - ui16 pom; - while(1) + try { - c >> pom; - switch(pom) + ui16 pom; + while(!end) { - case 100: //my interface end its turn - mTurn.lock(); - makingTurn = false; - mTurn.unlock(); - cTurn.notify_all(); - break; - default: - throw std::exception("Not supported client message!"); - break; + c >> pom; + switch(pom) + { + case 100: //my interface end its turn + mTurn.lock(); + makingTurn = false; + mTurn.unlock(); + cTurn.notify_all(); + break; + default: + throw std::exception("Not supported client message!"); + break; + } } } + catch (const std::exception& e) + { + std::cerr << e.what() << std::endl; + end = true; + } + catch (const std::exception * e) + { + std::cerr << e->what()<< std::endl; + end = true; + delete e; + } + catch(...) + { + end = true; + } } template void CGameHandler::sendToAllClients(CPack * info) { @@ -110,11 +129,12 @@ void CGameHandler::newTurn() // i->second.towns[j]->strInfo.creatures[k]+=i->second.towns[j]->creatureGrowth(k); // } //} - if((gs->day>1) && i->firstday) && i->firstsecond.towns[j]->dailyIncome(); } n.res.insert(r); } + gs->apply(&n); sendToAllClients(&n); //for (std::set::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++) //{ @@ -147,7 +167,7 @@ void CGameHandler::run() boost::thread(boost::bind(&CGameHandler::handleConnection,this,pom,boost::ref(**i))); } - while (1) + while (!end) { newTurn(); for(std::map::iterator i = gs->players.begin(); i != gs->players.end(); i++) @@ -157,9 +177,11 @@ void CGameHandler::run() *connections[i->first] << ui16(100) << i->first; //wait till turn is done boost::unique_lock lock(mTurn); - while(makingTurn) + while(makingTurn && !end) { - cTurn.wait(lock); + boost::posix_time::time_duration p; + p= boost::posix_time::seconds(1); + cTurn.timed_wait(lock,p); } } diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 38614cac8..919123807 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -19,6 +19,7 @@ using namespace boost; using namespace boost::asio; using namespace boost::asio::ip; +bool end = false; CVCMIServer::CVCMIServer() : io(new io_service()), acceptor(new tcp::acceptor(*io, tcp::endpoint(tcp::v4(), 3030))) @@ -26,8 +27,8 @@ CVCMIServer::CVCMIServer() } CVCMIServer::~CVCMIServer() { - delete io; - delete acceptor; + //delete io; + //delete acceptor; } void CVCMIServer::newGame(CConnection &c) @@ -96,7 +97,7 @@ void CVCMIServer::start() } CConnection connection(s,NAME,std::cout); std::cout<<"Got connection!" << std::endl; - while(1) + while(!end) { uint8_t mode; connection >> mode; @@ -127,17 +128,9 @@ int _tmain(int argc, _TCHAR* argv[]) { io_service io_service; CVCMIServer server; - while(1) + while(!end) server.start(); io_service.run(); - } - catch (std::exception& e) - { - std::cerr << e.what() << std::endl; - } - catch(...) - { - ; - } + } HANDLE_EXCEPTION return 0; } From 001868652a9d6ef9f63b938c0cdc8fd3f7823bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sun, 27 Jul 2008 20:00:41 +0000 Subject: [PATCH 27/47] Two minor fixes --- CMT.cpp | 1 + map.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMT.cpp b/CMT.cpp index 12b45bcf1..a09b61561 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -109,6 +109,7 @@ int _tmain(int argc, _TCHAR* argv[]) initDLL(cgi->bitmaph); CGI->arth = VLC->arth; + CGI->creh = VLC->creh; CGI->townh = VLC->townh; CGI->heroh = VLC->heroh; CGI->objh = VLC->objh; diff --git a/map.cpp b/map.cpp index 2b5b3fb72..6529e3179 100644 --- a/map.cpp +++ b/map.cpp @@ -1858,7 +1858,7 @@ void Mapa::initFromBytes(unsigned char * bufor) nt->builded = 0; nt->destroyed = 0; nt->garrisonHero = NULL; - if(nt->ID=98) + if(nt->ID==98) towns.push_back(nt); break; } From 3247a9a4dd24d9c4e0e0e136f36427ff9df795dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 28 Jul 2008 12:44:08 +0000 Subject: [PATCH 28/47] Rewrote hero moving code. Seems to be working. --- CCallback.cpp | 337 +++++++++++++++++----------------------- CCallback.h | 6 +- CGameInfo.h | 2 - CGameState.cpp | 14 ++ CPlayerInterface.cpp | 7 +- client/Client.cpp | 56 ++++++- client/Client.h | 30 +++- client/Graphics.cpp | 4 +- hch/CObjectHandler.h | 2 +- int3.h | 20 ++- lib/NetPacks.h | 33 +++- map.cpp | 32 ++++ map.h | 5 + mapHandler.cpp | 4 +- server/CGameHandler.cpp | 135 +++++++++++++++- 15 files changed, 454 insertions(+), 233 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index fb8f4552a..327e38cbe 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -17,8 +17,16 @@ #include "lib/Connection.h" #include "client/Client.h" #include +#include +#include "lib/NetPacks.h" //LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); +extern CSharedCond > mess; +HeroMoveDetails::HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho) + :src(Src),dst(Dst),ho(Ho) +{ + owner = ho->getOwner(); +}; bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) { CGHeroInstance * hero = NULL; @@ -69,120 +77,123 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) return false; for(int i=ourPath->nodes.size()-1; i>0; i--) { - int3 stpos, endpos; - stpos = int3(ourPath->nodes[i].coord.x, ourPath->nodes[i].coord.y, hero->pos.z); - endpos = int3(ourPath->nodes[i-1].coord.x, ourPath->nodes[i-1].coord.y, hero->pos.z); - HeroMoveDetails curd; - curd.src = stpos; - curd.dst = endpos; - curd.ho = hero; - curd.owner = hero->getOwner(); - /*if(player!=-1) - { - hero->pos = endpos; - }*/ - if(hero->movement >= (ourPath->nodes.size()>=2 ? (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist || player==-1) - { //performing move - hero->movement -= (ourPath->nodes.size()>=2 ? (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist; - ourPath->nodes.pop_back(); - - std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.dst,false)); - bool blockvis = false; - for (int pit = 0; pitblockVisit) - blockvis = true; + int3 stpos(ourPath->nodes[i].coord.x, ourPath->nodes[i].coord.y, hero->pos.z), + endpos(ourPath->nodes[i-1].coord.x, ourPath->nodes[i-1].coord.y, hero->pos.z); + HeroMoveDetails curd(stpos,endpos,hero); - if (!blockvis) - { - curd.successful = true; - hero->pos = curd.dst; - - //inform leaved objects - std::vector< CGObjectInstance * > leave = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.src,false)); - for (int iii=0; iiistate) //hard-coded function - leave[iii]->state->onHeroLeave(leave[iii],curd.ho->subID); - } - - - //reveal fog of war - int heroSight = hero->getSightDistance(); - int xbeg = stpos.x - heroSight - 2; - if(xbeg < 0) - xbeg = 0; - int xend = stpos.x + heroSight + 2; - if(xend >= CGI->mh->map->width) - xend = CGI->mh->map->width; - int ybeg = stpos.y - heroSight - 2; - if(ybeg < 0) - ybeg = 0; - int yend = stpos.y + heroSight + 2; - if(yend >= CGI->mh->map->height) - yend = CGI->mh->map->height; - for(int xd=xbeg; xdgetPosition(false).x-xd)*(hero->getPosition(false).x-xd); - int deltaY = (hero->getPosition(false).y-yd)*(hero->getPosition(false).y-yd); - if(deltaX+deltaYgetSightDistance()*hero->getSightDistance()) - { - if(gs->players[player].fogOfWarMap[xd][yd][hero->getPosition(false).z] == 0) - { - CGI->playerint[gs->players[player].serial]->tileRevealed(int3(xd, yd, hero->getPosition(false).z)); - } - gs->players[player].fogOfWarMap[xd][yd][hero->getPosition(false).z] = 1; - } - } - } - - - //notify interfacesabout move - int nn=0; //number of interfece of currently browsed player - for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing - { - if (j->first > PLAYER_LIMIT) - break; - if(j->second.fogOfWarMap[stpos.x-1][stpos.y][stpos.z] || j->second.fogOfWarMap[endpos.x-1][endpos.y][endpos.z]) - { //player should be notified - CGI->playerint[j->second.serial]->heroMoved(curd); - } - ++nn; - } - - - //call objects if they arevisited - for (int iii=0; iiicheckFunc(vis[iii]->ID,"heroVisit")) //script function - gs->objscr[vis[iii]->ID]["heroVisit"]->onHeroVisit(vis[iii],curd.ho->subID); - if(vis[iii]->state) //hard-coded function - vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID); - } - } - else //interaction with blocking object (like resources) - { - curd.successful = false; - CGI->playerint[gs->players[hero->getOwner()].serial]->heroMoved(curd); - for (int iii=0; iiiblockVisit) - { - if(gs->checkFunc(vis[iii]->ID,"heroVisit")) //script function - gs->objscr[vis[iii]->ID]["heroVisit"]->onHeroVisit(vis[iii],curd.ho->subID); - if(vis[iii]->state) //hard-coded function - vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID); - } - } + *cl->serv << ui16(501) << hero->id << stpos << endpos; + {//wait till there is server answer + boost::unique_lock lock(*mess.mx); + while(std::find_if(mess.res->begin(),mess.res->end(),IPack::isType<501>) == mess.res->end()) + mess.cv->wait(lock); + std::set::iterator itr = std::find_if(mess.res->begin(),mess.res->end(),IPack::isType<501>); + TryMoveHero tmh = *static_cast(*itr); + mess.res->erase(itr); + if(!tmh.result) return false; - } - } - else - return true; //move ended - no more movement points } + + // if(hero->movement >= (ourPath->nodes.size()>=2 ? (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist || player==-1) + // { //performing move + // hero->movement -= (ourPath->nodes.size()>=2 ? (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist; + // ourPath->nodes.pop_back(); + // + // std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.dst,false)); + // bool blockvis = false; + // for (int pit = 0; pitblockVisit) + // blockvis = true; + + // if (!blockvis) + // { + // curd.successful = true; + // hero->pos = curd.dst; + + // //inform leaved objects + // std::vector< CGObjectInstance * > leave = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.src,false)); + // for (int iii=0; iiistate) //hard-coded function + // leave[iii]->state->onHeroLeave(leave[iii],curd.ho->subID); + // } + + + // //reveal fog of war + // int heroSight = hero->getSightDistance(); + // int xbeg = stpos.x - heroSight - 2; + // if(xbeg < 0) + // xbeg = 0; + // int xend = stpos.x + heroSight + 2; + // if(xend >= CGI->mh->map->width) + // xend = CGI->mh->map->width; + // int ybeg = stpos.y - heroSight - 2; + // if(ybeg < 0) + // ybeg = 0; + // int yend = stpos.y + heroSight + 2; + // if(yend >= CGI->mh->map->height) + // yend = CGI->mh->map->height; + // for(int xd=xbeg; xdgetPosition(false).x-xd)*(hero->getPosition(false).x-xd); + // int deltaY = (hero->getPosition(false).y-yd)*(hero->getPosition(false).y-yd); + // if(deltaX+deltaYgetSightDistance()*hero->getSightDistance()) + // { + // if(gs->players[player].fogOfWarMap[xd][yd][hero->getPosition(false).z] == 0) + // { + // cl->playerint[player]->tileRevealed(int3(xd, yd, hero->getPosition(false).z)); + // } + // gs->players[player].fogOfWarMap[xd][yd][hero->getPosition(false).z] = 1; + // } + // } + // } + + + // //notify interfacesabout move + // int nn=0; //number of interfece of currently browsed player + // for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing + // { + // if (j->first > PLAYER_LIMIT) + // break; + // if(j->second.fogOfWarMap[stpos.x-1][stpos.y][stpos.z] || j->second.fogOfWarMap[endpos.x-1][endpos.y][endpos.z]) + // { //player should be notified + // cl->playerint[j->second.color]->heroMoved(curd); + // } + // ++nn; + // } + + + // //call objects if they arevisited + // for (int iii=0; iiicheckFunc(vis[iii]->ID,"heroVisit")) //script function + // gs->objscr[vis[iii]->ID]["heroVisit"]->onHeroVisit(vis[iii],curd.ho->subID); + // if(vis[iii]->state) //hard-coded function + // vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID); + // } + // } + // else //interaction with blocking object (like resources) + // { + // curd.successful = false; + // cl->playerint[gs->players[hero->getOwner()].color]->heroMoved(curd); + // for (int iii=0; iiiblockVisit) + // { + // if(gs->checkFunc(vis[iii]->ID,"heroVisit")) //script function + // gs->objscr[vis[iii]->ID]["heroVisit"]->onHeroVisit(vis[iii],curd.ho->subID); + // if(vis[iii]->state) //hard-coded function + // vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID); + // } + // } + // return false; + // } + + // } + //} return true; } @@ -254,7 +265,7 @@ void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount t->army.slots[slot].first = &CGI->creh->creatures[ID]; t->army.slots[slot].second = amount; } - CGI->playerint[gs->players[player].serial]->garrisonChanged(obj); + cl->playerint[player]->garrisonChanged(obj); } //TODO: recruit from dwellings on the adventure map @@ -267,7 +278,7 @@ bool CCallback::dismissCreature(const CArmedInstance *obj, int stackPos) return false; CArmedInstance *ob = const_cast(obj); ob->army.slots.erase(stackPos); - CGI->playerint[gs->players[player].serial]->garrisonChanged(obj); + cl->playerint[player]->garrisonChanged(obj); return true; } bool CCallback::upgradeCreature(const CArmedInstance *obj, int stackPos, int newID) @@ -515,27 +526,9 @@ int CCallback::swapCreatures(const CGObjectInstance *s1, const CGObjectInstance S2->slots.erase(p2); if(s1->tempOwnerplayerint.size(); ++b) - { - if(CGI->playerint[b]->playerID == s1->tempOwner) - { - CGI->playerint[b]->garrisonChanged(s1); - break; - } - } - } + cl->playerint[s1->tempOwner]->garrisonChanged(s1); if((s2->tempOwnerplayerint.size(); ++b) - { - if(CGI->playerint[b]->playerID == s2->tempOwner) - { - CGI->playerint[b]->garrisonChanged(s2); - break; - } - } - } + cl->playerint[s2->tempOwner]->garrisonChanged(s2); return 0; } @@ -555,27 +548,10 @@ int CCallback::mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s S1->slots.erase(p1); if(s1->tempOwnerplayerint.size(); ++b) - { - if(CGI->playerint[b]->playerID == s1->tempOwner) - { - CGI->playerint[b]->garrisonChanged(s1); - break; - } - } - } + cl->playerint[s1->tempOwner]->garrisonChanged(s1); + if((s2->tempOwnerplayerint.size(); ++b) - { - if(CGI->playerint[b]->playerID == s2->tempOwner) - { - CGI->playerint[b]->garrisonChanged(s2); - break; - } - } - } + cl->playerint[s2->tempOwner]->garrisonChanged(s2); return 0; } int CCallback::splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val) @@ -597,25 +573,11 @@ int CCallback::splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2 if(s1->tempOwnerplayerint.size(); ++b) - { - if(CGI->playerint[b]->playerID == s1->tempOwner) - { - CGI->playerint[b]->garrisonChanged(s1); - break; - } - } + cl->playerint[s1->tempOwner]->garrisonChanged(s1); } if((s2->tempOwnerplayerint.size(); ++b) - { - if(CGI->playerint[b]->playerID == s2->tempOwner) - { - CGI->playerint[b]->garrisonChanged(s2); - break; - } - } + cl->playerint[s2->tempOwner]->garrisonChanged(s2); } return 0; } @@ -686,7 +648,7 @@ bool CCallback::buildBuilding(const CGTownInstance *town, int buildingID) for(int i=0;i<7;i++) gs->players[player].resources[i]-=b->resources[i]; t->builded++; - CGI->playerint[CGI->state->players[player].serial]->buildChanged(town,buildingID,1); + cl->playerint[player]->buildChanged(town,buildingID,1); return true; } @@ -782,18 +744,11 @@ int3 CScriptCallback::getPos(CGObjectInstance * ob) } void CScriptCallback::changePrimSkill(int ID, int which, int val) { - CGHeroInstance * hero = CGI->state->map->getHero(ID,0); + CGHeroInstance * hero = gs->map->getHero(ID,0); if (whichprimSkills[which]+=val; - for (int i=0; iplayerint.size(); i++) - { - if (CGI->playerint[i]->playerID == hero->getOwner()) - { - CGI->playerint[i]->heroPrimarySkillChanged(hero, which, val); - break; - } - } + cl->playerint[hero->getOwner()]->heroPrimarySkillChanged(hero, which, val); } else if (which==4) { @@ -830,24 +785,25 @@ void CScriptCallback::showInfoDialog(int player, std::string text, std::vector=0) { - CGameInterface * temp = CGI->playerint[CGI->state->players[player].serial]; + CGameInterface * temp = cl->playerint[player]; if (temp->human) ((CPlayerInterface*)(temp))->showInfoDialog(text,*components); return; } else { - for (int i=0; iplayerint.size();i++) + typedef std::pair intf; + BOOST_FOREACH(intf & i, cl->playerint) { - if (CGI->playerint[i]->human) - ((CPlayerInterface*)(CGI->playerint[i]))->showInfoDialog(text,*components); + if (i.second->human) + ((CPlayerInterface*)(i.second))->showInfoDialog(text,*components); } } } void CScriptCallback::showSelDialog(int player, std::string text, std::vector*components, IChosen * asker) { - CGameInterface * temp = CGI->playerint[CGI->state->players[player].serial]; + CGameInterface * temp = cl->playerint[player]; if (temp->human) ((CPlayerInterface*)(temp))->showSelDialog(text,*components,(int)asker); return; @@ -891,11 +847,11 @@ int CScriptCallback::getDate(int mode) void CScriptCallback::giveResource(int player, int which, int val) { gs->players[player].resources[which]+=val; - CGI->playerint[gs->players[player].serial]->receivedResource(which,val); + cl->playerint[player]->receivedResource(which,val); } void CScriptCallback::showCompInfo(int player, SComponent * comp) { - CPlayerInterface * i = dynamic_cast(CGI->playerint[gs->players[player].serial]); + CPlayerInterface * i = dynamic_cast(cl->playerint[player]); if(i) i->showComp(*comp); } @@ -905,15 +861,8 @@ void CScriptCallback::heroVisitCastle(CGObjectInstance * ob, int heroID) if(n = dynamic_cast(ob)) { n->visitingHero = CGI->state->map->getHero(heroID,0); - CGI->state->map->getHero(heroID,0)->visitedTown = n; - for(int b=0; bplayerint.size(); ++b) - { - if(CGI->playerint[b]->playerID == getHeroOwner(heroID)) - { - CGI->playerint[b]->heroVisitsTown(CGI->state->map->getHero(heroID,0),n); - break; - } - } + gs->map->getHero(heroID,0)->visitedTown = n; + cl->playerint[getHeroOwner(heroID)]->heroVisitsTown(CGI->state->map->getHero(heroID,0),n); } else return; diff --git a/CCallback.h b/CCallback.h index 9b3f5cd71..66d0ef3e2 100644 --- a/CCallback.h +++ b/CCallback.h @@ -78,6 +78,8 @@ public: struct HeroMoveDetails { + HeroMoveDetails(){}; + HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho); int3 src, dst; //source and destination points CGHeroInstance * ho; //object instance of this hero int owner; @@ -152,8 +154,10 @@ public: }; class CScriptCallback { + CScriptCallback(){}; public: CGameState * gs; + CClient *cl; //get info static int3 getPos(CGObjectInstance * ob); @@ -162,7 +166,7 @@ public: int getDate(int mode=0); //do sth - static void changePrimSkill(int ID, int which, int val); + void changePrimSkill(int ID, int which, int val); void showInfoDialog(int player, std::string text, std::vector * components); //TODO: obslugiwac nulle void showSelDialog(int player, std::string text, std::vector*components, IChosen * asker); void giveResource(int player, int which, int val); diff --git a/CGameInfo.h b/CGameInfo.h index 412e47c8b..f0109414a 100644 --- a/CGameInfo.h +++ b/CGameInfo.h @@ -58,8 +58,6 @@ public: CPathfinder * pathf; CCursorHandler * curh; CScreenHandler * screenh; - int localPlayer; - std::vector playerint; }; #endif //CGAMEINFO_H \ No newline at end of file diff --git a/CGameState.cpp b/CGameState.cpp index c1d7118f6..45908b9a3 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -128,6 +128,20 @@ void CGameState::apply(IPack * pack) if(n->resetBuilded) //reset amount of structures set in this turn in towns BOOST_FOREACH(CGTownInstance* t, map->towns) t->builded = 0; + break; + } + case 501://hero try-move + { + TryMoveHero * n = static_cast(pack); + CGHeroInstance *h = static_cast(map->objects[n->id]); + h->movement = n->movePoints; + if(n->result) + h->pos = n->end; + else + h->pos = n->start; + BOOST_FOREACH(int3 t, n->fowRevealed) + players[h->getOwner()].fogOfWarMap[t.x][t.y][t.z] = 1; + break; } } mx->unlock(); diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index f0cc6d4a6..8c8b783a6 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -340,7 +340,7 @@ void CGarrisonInt::createSlots() { sup = new std::vector(7,(CGarrisonSlot *)(NULL)); for - (std::map >::const_iterator i=set1->slots.begin(); + (std::map >::const_iterator i=set1->slots.begin(); i!=set1->slots.end(); i++) { (*sup)[i->first] = @@ -354,7 +354,7 @@ void CGarrisonInt::createSlots() { sdown = new std::vector(7,(CGarrisonSlot *)(NULL)); for - (std::map >::const_iterator i=set2->slots.begin(); + (std::map >::const_iterator i=set2->slots.begin(); i!=set2->slots.end(); i++) { (*sdown)[i->first] = @@ -902,13 +902,11 @@ CPlayerInterface::CPlayerInterface(int Player, int serial) LOCPLINT = this; playerID=Player; serialID=serial; - CGI->localPlayer = playerID; human=true; } void CPlayerInterface::init(ICallback * CB) { cb = dynamic_cast(CB); - CGI->localPlayer = serialID; adventureInt = new CAdvMapInt(playerID); castleInt = NULL; std::vector hh = cb->getHeroesInfo(false); @@ -928,7 +926,6 @@ void CPlayerInterface::yourTurn() { LOCPLINT = this; makingTurn = true; - CGI->localPlayer = serialID; unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling unsigned char & heroAnimVal = LOCPLINT->adventureInt->heroAnim; adventureInt->infoBar.newDay(cb->getDate(1)); diff --git a/client/Client.cpp b/client/Client.cpp index d4c75e38b..3e8bc885f 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -11,6 +11,9 @@ #include "../lib/NetPacks.h" #include #include +#include "../hch/CObjectHandler.h" +CSharedCond > mess(new std::set); + CClient::CClient(void) { } @@ -58,17 +61,18 @@ CClient::CClient(CConnection *con, StartInfo *si) for (int i=0; istate->scenarioOps->playerInfos.size();i++) //initializing interfaces { - CCallback *cb = new CCallback(CGI->state,CGI->state->scenarioOps->playerInfos[i].color,this); - if(!CGI->state->scenarioOps->playerInfos[i].human) - CGI->playerint.push_back(static_cast(CAIHandler::getNewAI(cb,"EmptyAI.dll"))); + ui8 color = gs->scenarioOps->playerInfos[i].color; + CCallback *cb = new CCallback(gs,color,this); + if(!gs->scenarioOps->playerInfos[i].human) + playerint[color] = static_cast(CAIHandler::getNewAI(cb,"EmptyAI.dll")); else { - CGI->state->currentPlayer=CGI->state->scenarioOps->playerInfos[i].color; - CGI->playerint.push_back(new CPlayerInterface(CGI->state->scenarioOps->playerInfos[i].color,i)); - ((CPlayerInterface*)(CGI->playerint[i]))->init(cb); + gs->currentPlayer = color; + playerint[color] = new CPlayerInterface(color,i); + playerint[color]->init(cb); } } - CGI->consoleh->cb = new CCallback(CGI->state,-1,this); + CGI->consoleh->cb = new CCallback(gs,-1,this); } CClient::~CClient(void) { @@ -82,7 +86,7 @@ void CClient::process(int what) ui8 player; *serv >> player;//who? std::cout << "It's turn of "<<(unsigned)player<<" player."<playerint[gs->players[player].serial])); + boost::thread(boost::bind(&CGameInterface::yourTurn,playerint[player])); break; } case 101: @@ -94,6 +98,42 @@ void CClient::process(int what) std::cout << "done!"<> *th; + std::cout << "HeroMove: id="<id<<"\tResult: "<<(unsigned)th->result<<"\tPosition "<end<apply(th); + int player = gs->map->objects[th->id]->getOwner(); + + if(playerint[player]) + { + for(std::set::iterator i=th->fowRevealed.begin(); i != th->fowRevealed.end(); i++) + playerint[player]->tileRevealed(*i); + //boost::function tr = boost::bind(&CGameInterface::tileRevealed,playerint[player]); + //std::for_each(th->fowRevealed.begin(),th->fowRevealed.end(),tr); + } + + //notify interfacesabout move + int nn=0; //number of interfece of currently browsed player + for(std::map::iterator i=playerint.begin();i!=playerint.end();i++) + { + if(gs->players[i->first].fogOfWarMap[th->start.x-1][th->start.y][th->start.z] || gs->players[i->first].fogOfWarMap[th->end.x-1][th->end.y][th->end.z]) + { + HeroMoveDetails hmd(th->start,th->end,static_cast(gs->map->objects[th->id])); + hmd.successful = th->result; + i->second->heroMoved(hmd); + } + } + + //add info for callback + mess.mx->lock(); + mess.res->insert(th); + mess.mx->unlock(); + mess.cv->notify_all(); + break; + } default: throw std::exception("Not supported server message!"); break; diff --git a/client/Client.h b/client/Client.h index 893dd3532..a6e0bcef4 100644 --- a/client/Client.h +++ b/client/Client.h @@ -5,10 +5,37 @@ class CGameState; class CGameInterface; class CConnection; class CCallback; + +namespace boost +{ + class mutex; + class condition_variable; +} + +template +struct CSharedCond +{ + boost::mutex *mx; + boost::condition_variable *cv; + T *res; + CSharedCond(T*R) + { + res = R; + mx = new boost::mutex; + cv = new boost::condition_variable; + } + ~CSharedCond() + { + delete res; + delete mx; + delete cv; + } +}; + class CClient { CGameState *gs; - std::map playerint; + std::map playerint; CConnection *serv; public: CClient(void); @@ -19,4 +46,5 @@ public: void run(); friend class CCallback; + friend class CScriptCallback; }; diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 353f3c158..35609d1f1 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -35,7 +35,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh) SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); printAt(curh->name,75,15,GEOR13,zwykly,ret); drawPrimarySkill(curh, ret); - for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) + for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) { blitAt(graphics->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); itoa((*i).second.second,buf,10); @@ -64,7 +64,7 @@ SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh) blitAt(halls->ourImages[pom].bitmap,77,42,ret); itoa(curh->dailyIncome(),buf,10); printAtMiddle(buf,167,70,GEORM,zwykly,ret); - for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) + for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) { if(!i->second.first) continue; diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 4219a24cf..6b3421a2d 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -53,7 +53,7 @@ class DLL_EXPORT CGObjectInstance public: int3 pos; //h3m pos int ID, subID; //normal ID (this one from OH3 maps ;]) - eg. town=98; hero=34 - int id;//number of object in CObjectHandler's vector + si32 id;//number of object in CObjectHandler's vector CGDefInfo * defInfo; CCPPObjectScript * state; CSpecObjInfo * info; diff --git a/int3.h b/int3.h index 722546aea..31469933b 100644 --- a/int3.h +++ b/int3.h @@ -5,26 +5,26 @@ class CCreature; class CCreatureSet //seven combined creatures { public: - std::map > slots; + std::map > slots; bool formation; //false - wide, true - tight }; class int3 { public: - int x,y,z; + si32 x,y,z; inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0 - inline int3(const int & X, const int & Y, const int & Z):x(X),y(Y),z(Z){}; //c-tor + inline int3(const si32 & X, const si32 & Y, const si32 & Z):x(X),y(Y),z(Z){}; //c-tor inline ~int3(){} // d-tor - does nothing inline int3 operator+(const int3 & i) const {return int3(x+i.x,y+i.y,z+i.z);} - inline int3 operator+(const int i) const //increases all components by int + inline int3 operator+(const si32 i) const //increases all components by si32 {return int3(x+i,y+i,z+i);} inline int3 operator-(const int3 & i) const {return int3(x-i.x,y-i.y,z-i.z);} - inline int3 operator-(const int i) const + inline int3 operator-(const si32 i) const {return int3(x-i,y-i,z-i);} - inline int3 operator-() const //increases all components by int + inline int3 operator-() const //increases all components by si32 {return int3(-x,-y,-z);} inline void operator+=(const int3 & i) { @@ -32,7 +32,7 @@ public: y+=i.y; z+=i.z; } - inline void operator+=(const int & i) + inline void operator+=(const si32 & i) { x+=i; y+=i; @@ -44,7 +44,7 @@ public: y-=i.y; z-=i.z; } - inline void operator-=(const int & i) + inline void operator-=(const si32 & i) { x+=i; y+=i; @@ -70,6 +70,10 @@ public: return false; return false; } + template void serialize(Handler &h, const int version) + { + h & x & y & z; + } }; inline std::istream & operator>>(std::istream & str, int3 & dest) { diff --git a/lib/NetPacks.h b/lib/NetPacks.h index c8dc2edea..2e63aaf03 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -1,13 +1,28 @@ #include "../global.h" struct IPack { - virtual ui16 getType()=0; + virtual ui16 getType()const = 0 ; + //template + //static bool isType(const IPack * ip) + //{ + // return Type == ip->getType(); + //} + template + static bool isType(IPack * ip) + { + return Type == ip->getType(); + } + //template + //static bool isType(const IPack & ip) + //{ + // return Type == ip.getType(); + //} }; template struct CPack :public IPack { ui16 type; - ui16 getType(){return type;} + ui16 getType() const{return type;} T* This(){return static_cast(this);}; }; struct NewTurn : public CPack //101 @@ -43,4 +58,18 @@ struct NewTurn : public CPack //101 { h & heroes & res & day & resetBuilded; } +}; +struct TryMoveHero : public CPack //501 +{ + TryMoveHero(){type = 501;}; + + ui32 id, movePoints; + ui8 result; + int3 start, end; + std::set fowRevealed; //revealed tiles + + template void serialize(Handler &h, const int version) + { + h & id & result & start & end & movePoints & fowRevealed; + } }; \ No newline at end of file diff --git a/map.cpp b/map.cpp index 6529e3179..bfd6d4daf 100644 --- a/map.cpp +++ b/map.cpp @@ -926,6 +926,8 @@ void Mapa::initFromBytes(unsigned char * bufor) terrain[z][c].malle = (Eroad)bufor[i++]; terrain[z][c].roadDir = bufor[i++]; terrain[z][c].siodmyTajemniczyBajt = bufor[i++]; + terrain[z][c].blocked = 0; + terrain[z][c].visitable = 0; } } if (twoLevel) // read underground terrain @@ -941,6 +943,8 @@ void Mapa::initFromBytes(unsigned char * bufor) undergroungTerrain[z][c].malle = (Eroad)bufor[i++]; undergroungTerrain[z][c].roadDir = bufor[i++]; undergroungTerrain[z][c].siodmyTajemniczyBajt = bufor[i++]; + undergroungTerrain[z][c].blocked = 0; + undergroungTerrain[z][c].visitable = 0; } } } @@ -2289,6 +2293,34 @@ borderguardend: //map readed, bufor no longer needed delete[] bufor; bufor=NULL; + + + for(int f=0; fdefInfo) + continue; + CDefHandler * curd = objects[f]->defInfo->handler; + for(int fx=0; fx<8; ++fx) + { + for(int fy=0; fy<6; ++fy) + { + int xVal = objects[f]->pos.x + fx - 7; + int yVal = objects[f]->pos.y + fy - 5; + int zVal = objects[f]->pos.z; + if(xVal>=0 && xVal=0 && yValdefInfo->visitMap[fy] >> (7 - fx)) & 1)) + { + curt.visitableObjects.push_back(objects[f]); + curt.visitable = true; + } + if(!((objects[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1)) + curt.blocked = true; + } + } + } + } } Mapa::Mapa(std::string filename) diff --git a/map.h b/map.h index d73d1ddc9..bdd81bda0 100644 --- a/map.h +++ b/map.h @@ -263,6 +263,11 @@ struct DLL_EXPORT TerrainTile Eroad malle; // type of Eroad (0 if there is no Eriver) unsigned char roadDir; // direction of Eroad unsigned char siodmyTajemniczyBajt; //bitfield, info whether this tile is coastal and how to rotate tile graphics + + bool visitable; //false = not visitable; true = visitable + bool blocked; //false = free; true = blocked; + + std::vector visitableObjects; //pointers to objects hero can visit while being on this tile }; struct DLL_EXPORT SheroName //name of starting hero { diff --git a/mapHandler.cpp b/mapHandler.cpp index 30e859301..405e40aa6 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -1325,7 +1325,7 @@ unsigned char CMapHandler::getHeroFrameNum(const unsigned char &dir, const bool case 8: return 11; default: - return -1; //should never happen + throw std::exception("Something very wrong1."); } } else //if(isMoving) @@ -1349,7 +1349,7 @@ unsigned char CMapHandler::getHeroFrameNum(const unsigned char &dir, const bool case 8: return 14; default: - return -1; //should never happen + throw std::exception("Something very wrong2."); } } } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 498ee2042..994653a3d 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -3,6 +3,7 @@ #include #include #include "CGameHandler.h" +#include "../CLua.h" #include "../CGameState.h" #include "../StartInfo.h" #include "../map.h" @@ -19,6 +20,11 @@ boost::condition_variable cTurn; boost::mutex mTurn; boost::shared_mutex gsm; +double neighbours(int3 a, int3 b) +{ + return std::sqrt( (double)(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ); +} + void CGameHandler::handleConnection(std::set players, CConnection &c) { try @@ -29,12 +35,126 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) c >> pom; switch(pom) { - case 100: //my interface end its turn - mTurn.lock(); - makingTurn = false; - mTurn.unlock(); - cTurn.notify_all(); - break; + case 100: //my interface ended its turn + { + mTurn.lock(); + makingTurn = false; + mTurn.unlock(); + cTurn.notify_all(); + break; + } + case 501://interface wants to move hero + { + int3 start, end; + si32 id; + c >> id >> start >> end; + int3 hmpos = end + int3(-1,0,0); + TerrainTile t = (hmpos.z) ? (gs->map->undergroungTerrain[hmpos.x][hmpos.y]) : (gs->map->terrain[hmpos.x][hmpos.y]); + CGHeroInstance *h = static_cast(gs->map->objects[id]); + int cost = (double)h->getTileCost(t.tertype,t.malle,t.nuine) * neighbours(start,end); + + TryMoveHero tmh; + tmh.id = id; + tmh.start = tmh.end = start; + tmh.end = end; + tmh.result = 0; + tmh.movePoints = h->movement; + + if((h->getOwner() != gs->currentPlayer) || //not turn of that hero + (neighbours(start,end)>=1.5) || //tiles are not neighouring + (h->movement < cost) || //lack of movement points + (t.tertype == rock) || //rock + (!h->canWalkOnSea() && t.tertype == water) || + (t.blocked && !t.visitable) ) //tile is blocked andnot visitable + goto fail; + + //we start moving + bool blockvis = false; + tmh.movePoints = h->movement = (h->movement-cost); //take move points + BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects) + { + if(obj->blockVisit) + { + blockvis = true; + break; + } + } + + if(blockvis)//interaction with blocking object (like resources) + { + gs->apply(&tmh); + sendToAllClients(&tmh); + BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects) + { + if (obj->blockVisit) + { + if(gs->checkFunc(obj->ID,"heroVisit")) //script function + gs->objscr[obj->ID]["heroVisit"]->onHeroVisit(obj,h->subID); + if(obj->state) //hard-coded function + obj->state->onHeroVisit(obj,h->subID); + } + } + break; + } + else //normal move + { + tmh.result = 1; + + BOOST_FOREACH(CGObjectInstance *obj, ((start.z) ? (gs->map->undergroungTerrain[start.x][start.y]) : (gs->map->terrain[start.x][start.y])).visitableObjects) + { + //TODO: allow to handle this in script-languages + if(obj->state) //hard-coded function + obj->state->onHeroLeave(obj,h->subID); + } + + //reveal fog of war + int heroSight = h->getSightDistance(); + int xbeg = start.x - heroSight - 2; + if(xbeg < 0) + xbeg = 0; + int xend = start.x + heroSight + 2; + if(xend >= gs->map->width) + xend = gs->map->width; + int ybeg = start.y - heroSight - 2; + if(ybeg < 0) + ybeg = 0; + int yend = start.y + heroSight + 2; + if(yend >= gs->map->height) + yend = gs->map->height; + for(int xd=xbeg; xdgetSightDistance()*h->getSightDistance()) + { + if(gs->players[h->getOwner()].fogOfWarMap[xd][yd][hmpos.z] == 0) + { + tmh.fowRevealed.insert(int3(xd,yd,hmpos.z)); + } + } + } + } + + gs->apply(&tmh); + sendToAllClients(&tmh); + + //call objects if they arevisited + BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects) + { + if(gs->checkFunc(obj->ID,"heroVisit")) //script function + gs->objscr[obj->ID]["heroVisit"]->onHeroVisit(obj,h->subID); + if(obj->state) //hard-coded function + obj->state->onHeroVisit(obj,h->subID); + } + } + break; + fail: + gs->apply(&tmh); + sendToAllClients(&tmh); + break; + } default: throw std::exception("Not supported client message!"); break; @@ -79,7 +199,7 @@ void CGameHandler::init(StartInfo *si, int Seed) } int lowestSpeed(CGHeroInstance * chi) { - std::map >::iterator i = chi->army.slots.begin(); + std::map >::iterator i = chi->army.slots.begin(); int ret = (*i++).second.first->speed; for (;i!=chi->army.slots.end();i++) { @@ -174,6 +294,7 @@ void CGameHandler::run() { if((i->second.towns.size()==0 && i->second.heroes.size()==0) || i->second.color<0) continue; //players has not towns/castle - loser makingTurn = true; + gs->currentPlayer = i->first; *connections[i->first] << ui16(100) << i->first; //wait till turn is done boost::unique_lock lock(mTurn); From 08b67965452863b60cbf7ed8cccc15b0b6259b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Tue, 29 Jul 2008 09:53:27 +0000 Subject: [PATCH 29/47] Mainly refactoring --- CAdvmapInterface.cpp | 6 +- CCallback.cpp | 142 ++++----------------- CConsoleHandler.cpp | 56 ++++----- CPathfinder.cpp | 12 +- CPlayerInterface.cpp | 2 +- hch/CObjectHandler.h | 1 - map.cpp | 3 + map.h | 1 + mapHandler.cpp | 269 ++++++++++++++++------------------------ mapHandler.h | 22 +--- server/CGameHandler.cpp | 15 ++- 11 files changed, 187 insertions(+), 342 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 25f3dea3a..10f6ba0b8 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -146,9 +146,9 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels { int mx=(CGI->mh->sizes.x*x)/pos.w; int my=(CGI->mh->sizes.y*y)/pos.h; - if (CGI->mh->ttiles[mx][my][i].blocked && (!CGI->mh->ttiles[mx][my][i].visitable)) - SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].b); - else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].terType].r,colors[CGI->mh->ttiles[mx][my][i].terType].g,colors[CGI->mh->ttiles[mx][my][i].terType].b); + if (CGI->mh->ttiles[mx][my][i].tileInfo->blocked && (!CGI->mh->ttiles[mx][my][i].tileInfo->visitable)) + SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b); + else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b); } } map.push_back(pom); diff --git a/CCallback.cpp b/CCallback.cpp index 327e38cbe..70d9f51e6 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -93,107 +93,6 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) return false; } } - - // if(hero->movement >= (ourPath->nodes.size()>=2 ? (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist || player==-1) - // { //performing move - // hero->movement -= (ourPath->nodes.size()>=2 ? (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist; - // ourPath->nodes.pop_back(); - // - // std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.dst,false)); - // bool blockvis = false; - // for (int pit = 0; pitblockVisit) - // blockvis = true; - - // if (!blockvis) - // { - // curd.successful = true; - // hero->pos = curd.dst; - - // //inform leaved objects - // std::vector< CGObjectInstance * > leave = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.src,false)); - // for (int iii=0; iiistate) //hard-coded function - // leave[iii]->state->onHeroLeave(leave[iii],curd.ho->subID); - // } - - - // //reveal fog of war - // int heroSight = hero->getSightDistance(); - // int xbeg = stpos.x - heroSight - 2; - // if(xbeg < 0) - // xbeg = 0; - // int xend = stpos.x + heroSight + 2; - // if(xend >= CGI->mh->map->width) - // xend = CGI->mh->map->width; - // int ybeg = stpos.y - heroSight - 2; - // if(ybeg < 0) - // ybeg = 0; - // int yend = stpos.y + heroSight + 2; - // if(yend >= CGI->mh->map->height) - // yend = CGI->mh->map->height; - // for(int xd=xbeg; xdgetPosition(false).x-xd)*(hero->getPosition(false).x-xd); - // int deltaY = (hero->getPosition(false).y-yd)*(hero->getPosition(false).y-yd); - // if(deltaX+deltaYgetSightDistance()*hero->getSightDistance()) - // { - // if(gs->players[player].fogOfWarMap[xd][yd][hero->getPosition(false).z] == 0) - // { - // cl->playerint[player]->tileRevealed(int3(xd, yd, hero->getPosition(false).z)); - // } - // gs->players[player].fogOfWarMap[xd][yd][hero->getPosition(false).z] = 1; - // } - // } - // } - - - // //notify interfacesabout move - // int nn=0; //number of interfece of currently browsed player - // for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing - // { - // if (j->first > PLAYER_LIMIT) - // break; - // if(j->second.fogOfWarMap[stpos.x-1][stpos.y][stpos.z] || j->second.fogOfWarMap[endpos.x-1][endpos.y][endpos.z]) - // { //player should be notified - // cl->playerint[j->second.color]->heroMoved(curd); - // } - // ++nn; - // } - - - // //call objects if they arevisited - // for (int iii=0; iiicheckFunc(vis[iii]->ID,"heroVisit")) //script function - // gs->objscr[vis[iii]->ID]["heroVisit"]->onHeroVisit(vis[iii],curd.ho->subID); - // if(vis[iii]->state) //hard-coded function - // vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID); - // } - // } - // else //interaction with blocking object (like resources) - // { - // curd.successful = false; - // cl->playerint[gs->players[hero->getOwner()].color]->heroMoved(curd); - // for (int iii=0; iiiblockVisit) - // { - // if(gs->checkFunc(vis[iii]->ID,"heroVisit")) //script function - // gs->objscr[vis[iii]->ID]["heroVisit"]->onHeroVisit(vis[iii],curd.ho->subID); - // if(vis[iii]->state) //hard-coded function - // vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID); - // } - // } - // return false; - // } - - // } - //} return true; } @@ -393,12 +292,30 @@ int CCallback::getDate(int mode) { return gs->getDate(mode); } +std::vector < std::string > CCallback::getObjDescriptions(int3 pos) +{ + std::vector ret; + //BOOST_FOREACH(const CGObjectInstance * obj, gs->map->terrain[i][j] + //{ + // if( (5-(objs[g].first->pos.y-pos.y)) >= 0 && (5-(objs[g].first->pos.y-pos.y)) < 6 && (objs[g].first->pos.x-pos.x) >= 0 && (objs[g].first->pos.x-pos.x)<7 && objs[g].first->defInfo && + // (((objs[g].first->defInfo->blockMap[5-(objs[g].first->pos.y-pos.y)])>>((objs[g].first->pos.x-pos.x)))&1)==0 + // ) //checking position blocking + // { + // //unsigned char * blm = objs[g].first->defInfo->blockMap; + // if (objs[g].first->state) + // ret.push_back(objs[g].first->state->hoverText(objs[g].first)); + // else + // ret.push_back(CGI->objh->objects[objs[g].first->ID].name); + // } + //} + return ret; +} bool CCallback::verifyPath(CPath * path, bool blockSea) { for (int i=0;inodes.size();i++) { - if ( CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].blocked - && (! (CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].visitable))) + if ( CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->blocked + && (! (CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->visitable))) return false; //path is wrong - one of the tiles is blocked if (blockSea) @@ -407,15 +324,15 @@ bool CCallback::verifyPath(CPath * path, bool blockSea) continue; if ( - ((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].terType==EterrainType::water) + ((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype==EterrainType::water) && - (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].terType!=EterrainType::water)) + (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype!=EterrainType::water)) || - ((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].terType!=EterrainType::water) + ((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype!=EterrainType::water) && - (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].terType==EterrainType::water)) + (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==EterrainType::water)) || - (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].terType==EterrainType::rock) + (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==EterrainType::rock) ) return false; @@ -426,13 +343,6 @@ bool CCallback::verifyPath(CPath * path, bool blockSea) return true; } -std::vector < std::string > CCallback::getObjDescriptions(int3 pos) -{ - if(gs->players[player].fogOfWarMap[pos.x][pos.y][pos.z]) - return CGI->mh->getObjDescriptions(pos); - else return std::vector< std::string > (); -} - std::vector< std::vector< std::vector > > & CCallback::getVisibilityMap() { return gs->players[player].fogOfWarMap; @@ -654,7 +564,7 @@ bool CCallback::buildBuilding(const CGTownInstance *town, int buildingID) int CCallback::battleGetBattlefieldType() { - return CGI->mh->ttiles[CGI->state->curB->tile.x][CGI->state->curB->tile.y][CGI->state->curB->tile.z].terType; + return CGI->mh->ttiles[CGI->state->curB->tile.x][CGI->state->curB->tile.y][CGI->state->curB->tile.z].tileInfo->tertype; } int CCallback::battleGetObstaclesAtTile(int tile) //returns bitfield diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index 6093e7961..cfd6acab4 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -100,34 +100,34 @@ int internalFunc(void * callback) // //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]); // break; // } - case 'D': //pos description - readed>>src; - CGI->mh->getObjDescriptions(src); - break; - case 'I': - { - SDL_Surface * temp = LOCPLINT->infoWin(NULL); - blitAtWR(temp,605,389); - SDL_FreeSurface(temp); - break; - } - case 'T': //test rect - readed>>src; - for(int g=0; g<8; ++g) - { - for(int v=0; v<8; ++v) - { - int3 csrc = src; - csrc.y+=g; - csrc.x+=v; - if(CGI->mh->getObjDescriptions(csrc).size()) - std::cout<<'x'; - else - std::cout<<'o'; - } - std::cout<>src; + // CGI->mh->getObjDescriptions(src); + // break; + //case 'I': + // { + // SDL_Surface * temp = LOCPLINT->infoWin(NULL); + // blitAtWR(temp,605,389); + // SDL_FreeSurface(temp); + // break; + // } + //case 'T': //test rect + // readed>>src; + // for(int g=0; g<8; ++g) + // { + // for(int v=0; v<8; ++v) + // { + // int3 csrc = src; + // csrc.y+=g; + // csrc.x+=v; + // if(CGI->mh->getObjDescriptions(csrc).size()) + // std::cout<<'x'; + // else + // std::cout<<'o'; + // } + // std::cout<objh->objInstances.size(); ++c) // { diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 70a7e8727..29459a979 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -42,7 +42,7 @@ vector* CPathfinder::GetPath(const CGHeroInstance* hero) int3 hpos = Hero->getPosition(false); if (!Hero->canWalkOnSea()) { - if (CGI->mh->ttiles[hpos.x][hpos.y][hpos.z].terType==EterrainType::water) + if (CGI->mh->ttiles[hpos.x][hpos.y][hpos.z].tileInfo->tertype==EterrainType::water) blockLandSea=false; else blockLandSea=true; @@ -192,11 +192,11 @@ void CPathfinder::CalcH(Coordinate* node) * If there is fog of war on the node. * => Impossible to move there. */ - if( (CGI->mh->ttiles[node->x][node->y][node->z].blocked && !(node->x==End.x && node->y==End.y && CGI->mh->ttiles[node->x][node->y][node->z].visitable)) || - (CGI->mh->ttiles[node->x][node->y][node->z].terType==EterrainType::rock) || - ((blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].terType==EterrainType::water)) || + if( (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->blocked && !(node->x==End.x && node->y==End.y && CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->visitable)) || + (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==EterrainType::rock) || + ((blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==EterrainType::water)) || (!CGI->state->players[Hero->tempOwner].fogOfWarMap[node->x][node->y][node->z]) || - ((!blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].terType!=EterrainType::water))) + ((!blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype!=EterrainType::water))) { //Impossible. @@ -213,7 +213,7 @@ void CPathfinder::CalcH(Coordinate* node) y = CGI->mh->map->height-1; //Get the movement cost. - ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].terType, CGI->mh->map->terrain[x][y].malle,CGI->mh->map->terrain[x][y].nuine); + ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].tileInfo->tertype, CGI->mh->map->terrain[x][y].malle,CGI->mh->map->terrain[x][y].nuine); node->h = ret; } diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 8c8b783a6..45e368bf0 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -44,7 +44,7 @@ extern boost::mutex eventsM; class OCM_HLP_CGIN { public: - bool operator ()(const std::pair & a, const std::pair & b) const + bool operator ()(const std::pair & a, const std::pair & b) const { return (*a.first)<(*b.first); } diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 6b3421a2d..6a3673647 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -88,7 +88,6 @@ public: // 8 4 // 765 bool isStanding; - bool flagPrinted; CHero * type; int exp; //experience point int level; //current level of hero diff --git a/map.cpp b/map.cpp index bfd6d4daf..39e6eae64 100644 --- a/map.cpp +++ b/map.cpp @@ -2316,7 +2316,10 @@ borderguardend: curt.visitable = true; } if(!((objects[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1)) + { + curt.blockingObjects.push_back(objects[f]); curt.blocked = true; + } } } } diff --git a/map.h b/map.h index bdd81bda0..f8522991d 100644 --- a/map.h +++ b/map.h @@ -268,6 +268,7 @@ struct DLL_EXPORT TerrainTile bool blocked; //false = free; true = blocked; std::vector visitableObjects; //pointers to objects hero can visit while being on this tile + std::vector blockingObjects; //pointers to objects that are blocking this tile }; struct DLL_EXPORT SheroName //name of starting hero { diff --git a/mapHandler.cpp b/mapHandler.cpp index 405e40aa6..95665b137 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -77,7 +77,7 @@ std::string nameFromType (EterrainType typ) class OCM_HLP { public: - bool operator ()(const std::pair & a, const std::pair & b) + bool operator ()(const std::pair & a, const std::pair & b) { return (*a.first)<(*b.first); } @@ -227,37 +227,23 @@ void CMapHandler::roadsRiverTerrainInit() { for (int k=0; k<=map->twoLevel; ++k) { - TerrainTile** pomm = map->terrain; ; - if (k==0) - pomm = map->terrain; - else - pomm = map->undergroungTerrain; - if(pomm[i][j].malle) + TerrainTile2 &pom(ttiles[i][j][k]); + pom.pos = int3(i, j, k); + pom.tileInfo = &( k ? map->undergroungTerrain[i][j] : map->terrain[i][j] ); + if(pom.tileInfo->malle) { int cDir; bool rotV, rotH; - if(k==0) - { - int roadpom = map->terrain[i][j].malle-1, - impom = map->terrain[i][j].roadDir; - SDL_Surface *pom1 = roadDefs[roadpom]->ourImages[impom].bitmap; - ttiles[i][j][k].roadbitmap.push_back(pom1); - cDir = map->terrain[i][j].roadDir; - rotH = (map->terrain[i][j].siodmyTajemniczyBajt >> 5) & 1; - rotV = (map->terrain[i][j].siodmyTajemniczyBajt >> 4) & 1; - } - else - { - int pom111 = map->undergroungTerrain[i][j].malle-1, - pom777 = map->undergroungTerrain[i][j].roadDir; - SDL_Surface *pom1 = roadDefs[pom111]->ourImages[pom777].bitmap; - ttiles[i][j][k].roadbitmap.push_back(pom1); - cDir = map->undergroungTerrain[i][j].roadDir; + int roadpom = pom.tileInfo->malle-1, + impom = pom.tileInfo->roadDir; + SDL_Surface *pom1 = roadDefs[roadpom]->ourImages[impom].bitmap; + ttiles[i][j][k].roadbitmap.push_back(pom1); + cDir = pom.tileInfo->roadDir; + + rotH = (pom.tileInfo->siodmyTajemniczyBajt >> 5) & 1; + rotV = (pom.tileInfo->siodmyTajemniczyBajt >> 4) & 1; - rotH = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 5) & 1; - rotV = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 4) & 1; - } if(rotH) { ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].roadbitmap[0]); @@ -275,32 +261,6 @@ void CMapHandler::roadsRiverTerrainInit() } } - //initializing simple values - for (int i=0; imh->map->width; i++) //jest po szerokości - { - for (int j=0; jmh->map->height;j++) //po wysokości - { - for(int k=0; k=CGI->mh->map->width || j>=CGI->mh->map->height) - { - ttiles[i][j][k].blocked = true; - continue; - } - ttiles[i][j][k].terType = (k==0 ? CGI->mh->map->terrain[i][j].tertype : CGI->mh->map->undergroungTerrain[i][j].tertype); - ttiles[i][j][k].malle = (k==0 ? CGI->mh->map->terrain[i][j].malle : CGI->mh->map->undergroungTerrain[i][j].malle); - ttiles[i][j][k].nuine = (k==0 ? CGI->mh->map->terrain[i][j].nuine : CGI->mh->map->undergroungTerrain[i][j].nuine); - ttiles[i][j][k].rivdir = (k==0 ? CGI->mh->map->terrain[i][j].rivDir : CGI->mh->map->undergroungTerrain[i][j].rivDir); - ttiles[i][j][k].roaddir = (k==0 ? CGI->mh->map->terrain[i][j].roadDir : CGI->mh->map->undergroungTerrain[i][j].roadDir); - - } - } - } - //simple values initialized - for (int i=0; iwidth; i++) //jest po szerokości { for (int j=0; jheight;j++) //po wysokości @@ -517,29 +477,29 @@ void CMapHandler::initObjectRects() } void CMapHandler::calculateBlockedPos() { - for(int f=0; fobjects.size(); ++f) //calculationg blocked / visitable positions - { - if(!map->objects[f]->defInfo) - continue; - CDefHandler * curd = map->objects[f]->defInfo->handler; - for(int fx=0; fx<8; ++fx) - { - for(int fy=0; fy<6; ++fy) - { - int xVal = map->objects[f]->pos.x + fx - 7; - int yVal = map->objects[f]->pos.y + fy - 5; - int zVal = map->objects[f]->pos.z; - if(xVal>=0 && xVal=0 && yValobjects[f]->defInfo->visitMap[fy] >> (7 - fx)) & 1)) - curt.visitable = true; - if(!((map->objects[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1)) - curt.blocked = true; - } - } - } - } + //for(int f=0; fobjects.size(); ++f) //calculationg blocked / visitable positions + //{ + // if(!map->objects[f]->defInfo) + // continue; + // CDefHandler * curd = map->objects[f]->defInfo->handler; + // for(int fx=0; fx<8; ++fx) + // { + // for(int fy=0; fy<6; ++fy) + // { + // int xVal = map->objects[f]->pos.x + fx - 7; + // int yVal = map->objects[f]->pos.y + fy - 5; + // int zVal = map->objects[f]->pos.z; + // if(xVal>=0 && xVal=0 && yValobjects[f]->defInfo->visitMap[fy] >> (7 - fx)) & 1)) + // curt.tileInfo->visitable = true; + // if(!((map->objects[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1)) + // curt.tileInfo->blocked = true; + // } + // } + // } + //} } void processDef (CGDefInfo* def) { @@ -714,7 +674,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, SDL_Rect pp = ttiles[x+bx][y+by][level].objects[h].second; pp.h = sr.h; pp.w = sr.w; - CGHeroInstance * themp = (dynamic_cast(ttiles[x+bx][y+by][level].objects[h].first)); + const CGHeroInstance * themp = (dynamic_cast(ttiles[x+bx][y+by][level].objects[h].first)); if(themp && themp->moveDir && !themp->isStanding && themp->ID!=62) //last condition - this is not prison { @@ -767,7 +727,6 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, bufr.w = 96; if(bufr.x-extRect->x>-64) SDL_BlitSurface(graphics->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+(heroAnim/4)%imgVal].bitmap, NULL, su, &bufr); - themp->flagPrinted = true; } } else @@ -821,7 +780,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, } else { - if(MARK_BLOCKED_POSITIONS && ttiles[x+bx][y+by][level].blocked) //temporary hiding blocked positions + if(MARK_BLOCKED_POSITIONS && ttiles[x+bx][y+by][level].tileInfo->blocked) //temporary hiding blocked positions { SDL_Rect sr; sr.y=by*32; @@ -839,7 +798,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, SDL_FreeSurface(ns); } - if(MARK_VISITABLE_POSITIONS && ttiles[x+bx][y+by][level].visitable) //temporary hiding visitable positions + if(MARK_VISITABLE_POSITIONS && ttiles[x+bx][y+by][level].tileInfo->visitable) //temporary hiding visitable positions { SDL_Rect sr; sr.y=by*32; @@ -1128,13 +1087,13 @@ int CMapHandler::getCost(int3 &a, int3 &b, const CGHeroInstance *hero) { int ret=-1; if(a.x>=CGI->mh->map->width && a.y>=CGI->mh->map->height) - ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][CGI->mh->map->width-1][a.z].malle]; + ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][CGI->mh->map->width-1][a.z].tileInfo->malle]; else if(a.x>=CGI->mh->map->width && a.ymh->map->height) - ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][a.y][a.z].malle]; + ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][a.y][a.z].tileInfo->malle]; else if(a.xmh->map->width && a.y>=CGI->mh->map->height) - ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][CGI->mh->map->width-1][a.z].malle]; + ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][CGI->mh->map->width-1][a.z].tileInfo->malle]; else - ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].malle]; + ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].tileInfo->malle]; if(!(a.x==b.x || a.y==b.y)) ret*=1.41421; @@ -1142,37 +1101,17 @@ int CMapHandler::getCost(int3 &a, int3 &b, const CGHeroInstance *hero) return ret; } -std::vector < std::string > CMapHandler::getObjDescriptions(int3 pos) -{ - std::vector < std::pair > objs = ttiles[pos.x][pos.y][pos.z].objects; - std::vector ret; - for(int g=0; gpos.y-pos.y)) >= 0 && (5-(objs[g].first->pos.y-pos.y)) < 6 && (objs[g].first->pos.x-pos.x) >= 0 && (objs[g].first->pos.x-pos.x)<7 && objs[g].first->defInfo && - (((objs[g].first->defInfo->blockMap[5-(objs[g].first->pos.y-pos.y)])>>((objs[g].first->pos.x-pos.x)))&1)==0 - ) //checking position blocking - { - //unsigned char * blm = objs[g].first->defInfo->blockMap; - if (objs[g].first->state) - ret.push_back(objs[g].first->state->hoverText(objs[g].first)); - else - ret.push_back(CGI->objh->objects[objs[g].first->ID].name); - } - } - return ret; -} - -std::vector < CGObjectInstance * > CMapHandler::getVisitableObjs(int3 pos) -{ - std::vector < CGObjectInstance * > ret; - for(int h=0; hvisitableAt(- curi->pos.x + pos.x + curi->getWidth() - 1, -curi->pos.y + pos.y + curi->getHeight() - 1)) - ret.push_back(curi); - } - return ret; -} +//std::vector < CGObjectInstance * > CMapHandler::getVisitableObjs(int3 pos) +//{ +// std::vector < CGObjectInstance * > ret; +// for(int h=0; hvisitableAt(- curi->pos.x + pos.x + curi->getWidth() - 1, -curi->pos.y + pos.y + curi->getHeight() - 1)) +// ret.push_back(curi); +// } +// return ret; +//} std::string CMapHandler::getDefName(int id, int subid) { @@ -1221,7 +1160,7 @@ bool CMapHandler::hideObject(CGObjectInstance *obj) { if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1) > & ctile = ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects; + std::vector < std::pair > & ctile = ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects; for(int dd=0; ddid==obj->id) @@ -1245,60 +1184,60 @@ bool CMapHandler::removeObject(CGObjectInstance *obj) bool CMapHandler::recalculateHideVisPos(int3 &pos) { - ttiles[pos.x][pos.y][pos.z].visitable = false; - ttiles[pos.x][pos.y][pos.z].blocked = false; - for(int i=0; idefInfo->handler; - for(int fx=0; fx<8; ++fx) - { - for(int fy=0; fy<6; ++fy) - { - int xVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.x + fx - 7; - int yVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.y + fy - 5; - int zVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.z; - if(xVal>=0 && xVal=0 && yValdefInfo->visitMap[fy] >> (7 - fx)) & 1)) - curt.visitable = true; - if(!((ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->blockMap[fy] >> (7 - fx)) & 1)) - curt.blocked = true; - } - } - } - } + //ttiles[pos.x][pos.y][pos.z].tileInfo->visitable = false; + //ttiles[pos.x][pos.y][pos.z].tileInfo->blocked = false; + //for(int i=0; idefInfo->handler; + // for(int fx=0; fx<8; ++fx) + // { + // for(int fy=0; fy<6; ++fy) + // { + // int xVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.x + fx - 7; + // int yVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.y + fy - 5; + // int zVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.z; + // if(xVal>=0 && xVal=0 && yValdefInfo->visitMap[fy] >> (7 - fx)) & 1)) + // curt.tileInfo->visitable = true; + // if(!((ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->blockMap[fy] >> (7 - fx)) & 1)) + // curt.tileInfo->blocked = true; + // } + // } + // } + //} return true; } bool CMapHandler::recalculateHideVisPosUnderObj(CGObjectInstance *obj, bool withBorder) { - if(withBorder) - { - for(int fx=-1; fx<=obj->defInfo->handler->ourImages[0].bitmap->w/32; ++fx) - { - for(int fy=-1; fy<=obj->defInfo->handler->ourImages[0].bitmap->h/32; ++fy) - { - if((obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32 +1, obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32 + 1, obj->pos.z)); - } - } - } - } - else - { - for(int fx=0; fxdefInfo->handler->ourImages[0].bitmap->w/32; ++fx) - { - for(int fy=0; fydefInfo->handler->ourImages[0].bitmap->h/32; ++fy) - { - if((obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32 +1, obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32 + 1, obj->pos.z)); - } - } - } - } + //if(withBorder) + //{ + // for(int fx=-1; fx<=obj->defInfo->handler->ourImages[0].bitmap->w/32; ++fx) + // { + // for(int fy=-1; fy<=obj->defInfo->handler->ourImages[0].bitmap->h/32; ++fy) + // { + // if((obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32 +1, obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32 + 1, obj->pos.z)); + // } + // } + // } + //} + //else + //{ + // for(int fx=0; fxdefInfo->handler->ourImages[0].bitmap->w/32; ++fx) + // { + // for(int fy=0; fydefInfo->handler->ourImages[0].bitmap->h/32; ++fy) + // { + // if((obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32 +1, obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32 + 1, obj->pos.z)); + // } + // } + // } + //} return true; } diff --git a/mapHandler.h b/mapHandler.h index 699daf1f9..60b972750 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -13,27 +13,17 @@ struct Mapa; class CGDefInfo; class CGObjectInstance; class CDefHandler; +struct TerrainTile; + struct TerrainTile2 { - int3 pos; //this tile's position - EterrainType terType; //type of terrain tile - - Eroad malle; //type of road - unsigned char roaddir; //type of road tile - - Eriver nuine; //type of river - unsigned char rivdir; //type of river tile - + int3 pos; + const TerrainTile *tileInfo; std::vector terbitmap; //frames of terrain animation std::vector rivbitmap; //frames of river animation std::vector roadbitmap; //frames of road animation - bool visitable; //false = not visitable; true = visitable - bool blocked; //false = free; true = blocked; - - std::vector < std::pair > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen - std::vector visitableObjects; //pointers to objects hero is visiting being on this tile - + std::vector < std::pair > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen }; //pathfinder @@ -93,7 +83,7 @@ public: int getCost(int3 & a, int3 & b, const CGHeroInstance * hero); std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position - std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position + //std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid std::string getDefName(int id, int subid); //returns name of def for object with given id and subid bool printObject(CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 994653a3d..5451b3703 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -20,7 +20,7 @@ boost::condition_variable cTurn; boost::mutex mTurn; boost::shared_mutex gsm; -double neighbours(int3 a, int3 b) +double distance(int3 a, int3 b) { return std::sqrt( (double)(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ); } @@ -51,24 +51,25 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) int3 hmpos = end + int3(-1,0,0); TerrainTile t = (hmpos.z) ? (gs->map->undergroungTerrain[hmpos.x][hmpos.y]) : (gs->map->terrain[hmpos.x][hmpos.y]); CGHeroInstance *h = static_cast(gs->map->objects[id]); - int cost = (double)h->getTileCost(t.tertype,t.malle,t.nuine) * neighbours(start,end); + int cost = (double)h->getTileCost(t.tertype,t.malle,t.nuine) * distance(start,end); TryMoveHero tmh; tmh.id = id; - tmh.start = tmh.end = start; + tmh.start = start; tmh.end = end; tmh.result = 0; tmh.movePoints = h->movement; if((h->getOwner() != gs->currentPlayer) || //not turn of that hero - (neighbours(start,end)>=1.5) || //tiles are not neighouring + (distance(start,end)>=1.5) || //tiles are not neighouring (h->movement < cost) || //lack of movement points (t.tertype == rock) || //rock (!h->canWalkOnSea() && t.tertype == water) || (t.blocked && !t.visitable) ) //tile is blocked andnot visitable goto fail; - //we start moving + + //check if there is blocking visitable object bool blockvis = false; tmh.movePoints = h->movement = (h->movement-cost); //take move points BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects) @@ -80,10 +81,12 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) } } + + //we start moving if(blockvis)//interaction with blocking object (like resources) { gs->apply(&tmh); - sendToAllClients(&tmh); + sendToAllClients(&tmh); //failed to move to that tile but we visit object BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects) { if (obj->blockVisit) From add34b26edcc9917da3deb95b1ea78359c11dc94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Tue, 29 Jul 2008 19:10:28 +0000 Subject: [PATCH 30/47] Further refactoring: merged terrain and undergroundTerrain in Mapa. --- CPathfinder.cpp | 2 +- map.cpp | 48 +++++++++++++++++----------------- map.h | 3 +-- mapHandler.cpp | 57 +++++++++++++++-------------------------- server/CGameHandler.cpp | 4 +-- 5 files changed, 47 insertions(+), 67 deletions(-) diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 29459a979..01e477b38 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -213,7 +213,7 @@ void CPathfinder::CalcH(Coordinate* node) y = CGI->mh->map->height-1; //Get the movement cost. - ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].tileInfo->tertype, CGI->mh->map->terrain[x][y].malle,CGI->mh->map->terrain[x][y].nuine); + ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].tileInfo->tertype, CGI->mh->map->terrain[x][y][0].malle,CGI->mh->map->terrain[x][y][0].nuine); node->h = ret; } diff --git a/map.cpp b/map.cpp index 39e6eae64..bfb654573 100644 --- a/map.cpp +++ b/map.cpp @@ -451,14 +451,12 @@ void Mapa::initFromBytes(unsigned char * bufor) areAnyPLayers = readChar(bufor,i); //invalid on some maps height = width = (readNormalNr(bufor,i)); i+=4; // wymiary mapy twoLevel = readChar(bufor,i); //czy sa lochy - terrain = new TerrainTile*[width]; // allocate memory + terrain = new TerrainTile**[width]; // allocate memory for (int ii=0;iipos.z; if(xVal>=0 && xVal=0 && yValdefInfo->visitMap[fy] >> (7 - fx)) & 1)) { curt.visitableObjects.push_back(objects[f]); diff --git a/map.h b/map.h index f8522991d..5e78d807a 100644 --- a/map.h +++ b/map.h @@ -462,8 +462,7 @@ struct DLL_EXPORT Mapa std::string name; //name of map std::string description; //and description int height, width; - TerrainTile** terrain; - TerrainTile** undergroungTerrain; // used only if there is underground level + TerrainTile*** terrain; std::vector rumors; std::vector disposedHeroes; std::vector predefinedHeroes; diff --git a/mapHandler.cpp b/mapHandler.cpp index 95665b137..03e830685 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -229,7 +229,7 @@ void CMapHandler::roadsRiverTerrainInit() { TerrainTile2 &pom(ttiles[i][j][k]); pom.pos = int3(i, j, k); - pom.tileInfo = &( k ? map->undergroungTerrain[i][j] : map->terrain[i][j] ); + pom.tileInfo = &(map->terrain[i][j][k]); if(pom.tileInfo->malle) { int cDir; @@ -267,33 +267,16 @@ void CMapHandler::roadsRiverTerrainInit() { for(int k=0; k<=map->twoLevel; ++k) { - TerrainTile** pomm = map->terrain; - if(k==0) - { - pomm = map->terrain; - } - else - { - pomm = map->undergroungTerrain; - } - if(pomm[i][j].nuine) + if(map->terrain[i][j][k].nuine) { int cDir; bool rotH, rotV; - if(k==0) - { - ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[map->terrain[i][j].nuine-1]->ourImages[map->terrain[i][j].rivDir].bitmap); - cDir = map->terrain[i][j].rivDir; - rotH = (map->terrain[i][j].siodmyTajemniczyBajt >> 3) & 1; - rotV = (map->terrain[i][j].siodmyTajemniczyBajt >> 2) & 1; - } - else - { - ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[map->undergroungTerrain[i][j].nuine-1]->ourImages[map->undergroungTerrain[i][j].rivDir].bitmap); - cDir = map->undergroungTerrain[i][j].rivDir; - rotH = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 3) & 1; - rotV = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 2) & 1; - } + + ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[map->terrain[i][j][k].nuine-1]->ourImages[map->terrain[i][j][k].rivDir].bitmap); + cDir = map->terrain[i][j][k].rivDir; + rotH = (map->terrain[i][j][k].siodmyTajemniczyBajt >> 3) & 1; + rotV = (map->terrain[i][j][k].siodmyTajemniczyBajt >> 2) & 1; + if(rotH) { ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].rivbitmap[0]); @@ -372,9 +355,9 @@ void CMapHandler::borderAndTerrainBitmapInit() //TerrainTile zz = map->terrain[i-Woff][j-Hoff]; std::string name; if (k>0) - name = nameFromType(map->undergroungTerrain[i][j].tertype); + name = nameFromType(map->terrain[i][j][1].tertype); else - name = nameFromType(map->terrain[i][j].tertype); + name = nameFromType(map->terrain[i][j][0].tertype); for (unsigned int m=0; mterrain[i][j].terview; + ktora = map->terrain[i][j][0].terview; else - ktora = map->undergroungTerrain[i][j].terview; + ktora = map->terrain[i][j][1].terview; ttiles[i][j][k].terbitmap.push_back(defs[m]->ourImages[ktora].bitmap); int zz; if (k==0) - zz = (map->terrain[i][j].siodmyTajemniczyBajt)%4; + zz = (map->terrain[i][j][0].siodmyTajemniczyBajt)%4; else - zz = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt)%4; + zz = (map->terrain[i][j][1].siodmyTajemniczyBajt)%4; switch (zz) { case 1: @@ -1380,16 +1363,16 @@ void CMapHandler::loadDefs() { for (int j=0; jwidth; j++) { - if (loadedTypes.find(map->terrain[i][j].tertype)==loadedTypes.end()) + if (loadedTypes.find(map->terrain[i][j][0].tertype)==loadedTypes.end()) { - CDefHandler *sdh = CDefHandler::giveDef(nameFromType(map->terrain[i][j].tertype).c_str()); - loadedTypes.insert(map->terrain[i][j].tertype); + CDefHandler *sdh = CDefHandler::giveDef(nameFromType(map->terrain[i][j][0].tertype).c_str()); + loadedTypes.insert(map->terrain[i][j][0].tertype); defs.push_back(sdh); } - if (map->twoLevel && loadedTypes.find(map->undergroungTerrain[i][j].tertype)==loadedTypes.end()) + if (map->twoLevel && loadedTypes.find(map->terrain[i][j][1].tertype)==loadedTypes.end()) { - CDefHandler *sdh = CDefHandler::giveDef(nameFromType(map->undergroungTerrain[i][j].tertype).c_str()); - loadedTypes.insert(map->undergroungTerrain[i][j].tertype); + CDefHandler *sdh = CDefHandler::giveDef(nameFromType(map->terrain[i][j][1].tertype).c_str()); + loadedTypes.insert(map->terrain[i][j][1].tertype); defs.push_back(sdh); } } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 5451b3703..3047c1617 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -49,7 +49,7 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) si32 id; c >> id >> start >> end; int3 hmpos = end + int3(-1,0,0); - TerrainTile t = (hmpos.z) ? (gs->map->undergroungTerrain[hmpos.x][hmpos.y]) : (gs->map->terrain[hmpos.x][hmpos.y]); + TerrainTile t = gs->map->terrain[hmpos.x][hmpos.y][hmpos.z]; CGHeroInstance *h = static_cast(gs->map->objects[id]); int cost = (double)h->getTileCost(t.tertype,t.malle,t.nuine) * distance(start,end); @@ -103,7 +103,7 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) { tmh.result = 1; - BOOST_FOREACH(CGObjectInstance *obj, ((start.z) ? (gs->map->undergroungTerrain[start.x][start.y]) : (gs->map->terrain[start.x][start.y])).visitableObjects) + BOOST_FOREACH(CGObjectInstance *obj, gs->map->terrain[start.x][start.y][start.z].visitableObjects) { //TODO: allow to handle this in script-languages if(obj->state) //hard-coded function From b4f383f1961f9e5b78b6d66f7a6dc3149e8bbe3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Wed, 30 Jul 2008 17:51:19 +0000 Subject: [PATCH 31/47] Slowly recovering object scripts. --- CCallback.cpp | 268 +------------- CCallback.h | 42 --- CGameState.cpp | 104 ++---- CGameState.h | 3 - CLua.cpp | 707 ++++++++++++++++++------------------- CLua.h | 99 ++---- CMT.cpp | 10 +- CPathfinder.cpp | 2 +- client/Client.cpp | 83 ++++- client/VCMI_client.vcproj | 4 - hch/CObjectHandler.cpp | 10 +- hch/CObjectHandler.h | 11 +- lib/Connection.h | 11 +- lib/NetPacks.h | 55 ++- server/CGameHandler.cpp | 121 +++++-- server/CGameHandler.h | 25 +- server/CScriptCallback.cpp | 292 +++++++++++++++ server/CScriptCallback.h | 62 ++++ server/CVCMIServer.h | 1 + server/VCMI_server.vcproj | 16 + 20 files changed, 1068 insertions(+), 858 deletions(-) create mode 100644 server/CScriptCallback.cpp create mode 100644 server/CScriptCallback.h diff --git a/CCallback.cpp b/CCallback.cpp index 70d9f51e6..a6e4c15d1 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -8,7 +8,6 @@ #include "mapHandler.h" #include "CGameState.h" #include "CPlayerInterface.h" -#include "CLua.h" #include "hch/CGeneralTextHandler.h" #include "CAdvmapInterface.h" #include "CPlayerInterface.h" @@ -99,8 +98,8 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) void CCallback::selectionMade(int selection, int asker) { //todo - jak bedzie multiplayer po sieci, to moze wymagac przerobek zaleznych od obranego modelu - IChosen * ask = (IChosen *)asker; - ask->chosen(selection); + //IChosen * ask = (IChosen *)asker; + //ask->chosen(selection); } void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount) { @@ -295,19 +294,8 @@ int CCallback::getDate(int mode) std::vector < std::string > CCallback::getObjDescriptions(int3 pos) { std::vector ret; - //BOOST_FOREACH(const CGObjectInstance * obj, gs->map->terrain[i][j] - //{ - // if( (5-(objs[g].first->pos.y-pos.y)) >= 0 && (5-(objs[g].first->pos.y-pos.y)) < 6 && (objs[g].first->pos.x-pos.x) >= 0 && (objs[g].first->pos.x-pos.x)<7 && objs[g].first->defInfo && - // (((objs[g].first->defInfo->blockMap[5-(objs[g].first->pos.y-pos.y)])>>((objs[g].first->pos.x-pos.x)))&1)==0 - // ) //checking position blocking - // { - // //unsigned char * blm = objs[g].first->defInfo->blockMap; - // if (objs[g].first->state) - // ret.push_back(objs[g].first->state->hoverText(objs[g].first)); - // else - // ret.push_back(CGI->objh->objects[objs[g].first->ID].name); - // } - //} + BOOST_FOREACH(const CGObjectInstance * obj, gs->map->terrain[pos.x][pos.y][pos.z].blockingObjects) + ret.push_back(obj->hoverName); return ret; } bool CCallback::verifyPath(CPath * path, bool blockSea) @@ -646,250 +634,4 @@ bool CCallback::battleIsStackMine(int ID) return CGI->state->curB->stacks[h]->owner == player; } return false; -} - -int3 CScriptCallback::getPos(CGObjectInstance * ob) -{ - return ob->pos; -} -void CScriptCallback::changePrimSkill(int ID, int which, int val) -{ - CGHeroInstance * hero = gs->map->getHero(ID,0); - if (whichprimSkills[which]+=val; - cl->playerint[hero->getOwner()]->heroPrimarySkillChanged(hero, which, val); - } - else if (which==4) - { - hero->exp+=val; - if(hero->exp >= CGI->heroh->reqExp(hero->level+1)) //new level - { - hero->level++; - std::cout << hero->name <<" got level "<level<::*g = (hero->level>9) ? (&std::pair::second) : (&std::pair::first); - for(;xtype->heroClass->primChance[x].*g; - if(rprimSkills[x]++; - - //TODO: dac dwie umiejetnosci 2-rzedne to wyboru - - } - //TODO - powiadomic interfejsy, sprawdzic czy nie ma awansu itp - } -} - -int CScriptCallback::getHeroOwner(int heroID) -{ - CGHeroInstance * hero = CGI->state->map->getHero(heroID,0); - return hero->getOwner(); -} -void CScriptCallback::showInfoDialog(int player, std::string text, std::vector * components) -{ - //TODO: upewniac sie ze mozemy to zrzutowac (przy customowych interfejsach cos moze sie kopnac) - if (player>=0) - { - CGameInterface * temp = cl->playerint[player]; - if (temp->human) - ((CPlayerInterface*)(temp))->showInfoDialog(text,*components); - return; - } - else - { - typedef std::pair intf; - BOOST_FOREACH(intf & i, cl->playerint) - { - if (i.second->human) - ((CPlayerInterface*)(i.second))->showInfoDialog(text,*components); - } - } -} - -void CScriptCallback::showSelDialog(int player, std::string text, std::vector*components, IChosen * asker) -{ - CGameInterface * temp = cl->playerint[player]; - if (temp->human) - ((CPlayerInterface*)(temp))->showSelDialog(text,*components,(int)asker); - return; -} -int CScriptCallback::getSelectedHero() -{ - int ret; - if (LOCPLINT->adventureInt->selection.type == HEROI_TYPE) - ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->subID; - else - ret = -1;; - return ret; -} -int CScriptCallback::getDate(int mode) -{ - int temp; - switch (mode) - { - case 0: - return gs->day; - break; - case 1: - temp = (gs->day)%7; - if (temp) - return temp; - else return 7; - break; - case 2: - temp = ((gs->day-1)/7)+1; - if (!(temp%4)) - return 4; - else - return (temp%4); - break; - case 3: - return ((gs->day-1)/28)+1; - break; - } - return 0; -} -void CScriptCallback::giveResource(int player, int which, int val) -{ - gs->players[player].resources[which]+=val; - cl->playerint[player]->receivedResource(which,val); -} -void CScriptCallback::showCompInfo(int player, SComponent * comp) -{ - CPlayerInterface * i = dynamic_cast(cl->playerint[player]); - if(i) - i->showComp(*comp); -} -void CScriptCallback::heroVisitCastle(CGObjectInstance * ob, int heroID) -{ - CGTownInstance * n; - if(n = dynamic_cast(ob)) - { - n->visitingHero = CGI->state->map->getHero(heroID,0); - gs->map->getHero(heroID,0)->visitedTown = n; - cl->playerint[getHeroOwner(heroID)]->heroVisitsTown(CGI->state->map->getHero(heroID,0),n); - } - else - return; -} - -void CScriptCallback::stopHeroVisitCastle(CGObjectInstance * ob, int heroID) -{ - CGTownInstance * n; - if(n = dynamic_cast(ob)) - { - CGI->state->map->getHero(heroID,0)->visitedTown = NULL; - if(n->visitingHero && n->visitingHero->type->ID == heroID) - n->visitingHero = NULL; - return; - } - else - return; -} -void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos==-1 - first free slot in backpack -{ - CGHeroInstance* h = gs->map->getHero(hid,0); - if(position<0) - { - for(int i=0;iartifacts.size();i++) - { - if(!h->artifacts[i]) - { - h->artifacts[i] = artid; - return; - } - } - h->artifacts.push_back(artid); - return; - } - else - { - if(h->artifWorn[position]) //slot is occupied - { - giveHeroArtifact(h->artifWorn[position],hid,-1); - } - h->artifWorn[position] = artid; - } -} - -void CScriptCallback::startBattle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2) //use hero=NULL for no hero -{ - gs->battle(army1,army2,tile,hero1,hero2); -} -void CScriptCallback::startBattle(int heroID, CCreatureSet * army, int3 tile) //for hero<=>neutral army -{ - CGHeroInstance* h = gs->map->getHero(heroID,0); - gs->battle(&h->army,army,tile,h,NULL); -} -void CLuaCallback::registerFuncs(lua_State * L) -{ -// lua_newtable(L); -// -//#define REGISTER_C_FUNC(x) \ -// lua_pushstring(L, #x); \ -// lua_pushcfunction(L, x); \ -// lua_rawset(L, -3) -// -// REGISTER_C_FUNC(getPos); -// REGISTER_C_FUNC(changePrimSkill); -// REGISTER_C_FUNC(getGnrlText); -// REGISTER_C_FUNC(getSelectedHero); -// -// lua_setglobal(L, "vcmi"); -// #undef REGISTER_C_FUNC -} -int CLuaCallback::getPos(lua_State * L)//(CGObjectInstance * object); -{ - //const int args = lua_gettop(L); // number of arguments - //if ((args < 1) || !lua_isnumber(L, 1) ) - // luaL_error(L, - // "Incorrect arguments to getPos([Object address])"); - //CGObjectInstance * object = (CGObjectInstance *)(lua_tointeger(L, 1)); - //lua_pushinteger(L,object->pos.x); - //lua_pushinteger(L,object->pos.y); - //lua_pushinteger(L,object->pos.z); - return 3; -} -int CLuaCallback::changePrimSkill(lua_State * L)//(int ID, int which, int val); -{ - //const int args = lua_gettop(L); // number of arguments - //if ((args < 1) || !lua_isnumber(L, 1) || - // ((args >= 2) && !lua_isnumber(L, 2)) || - // ((args >= 3) && !lua_isnumber(L, 3)) ) - //{ - // luaL_error(L, - // "Incorrect arguments to changePrimSkill([Hero ID], [Which Primary skill], [Change by])"); - //} - //int ID = lua_tointeger(L, 1), - // which = lua_tointeger(L, 2), - // val = lua_tointeger(L, 3); - - //CScriptCallback::changePrimSkill(ID,which,val); - - return 0; -} -int CLuaCallback::getGnrlText(lua_State * L) //(int which),returns string -{ - //const int args = lua_gettop(L); // number of arguments - //if ((args < 1) || !lua_isnumber(L, 1) ) - // luaL_error(L, - // "Incorrect arguments to getGnrlText([Text ID])"); - //int which = lua_tointeger(L,1); - //lua_pushstring(L,CGI->generaltexth->allTexts[which].c_str()); - return 1; -} -int CLuaCallback::getSelectedHero(lua_State * L) //(),returns int (ID of hero, -1 if no hero is seleceted) -{ - //int ret; - //if (LOCPLINT->adventureInt->selection.type == HEROI_TYPE) - // ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->subID; - //else - // ret = -1; - //lua_pushinteger(L,ret); - return 1; -} +} \ No newline at end of file diff --git a/CCallback.h b/CCallback.h index 66d0ef3e2..c755ccb1e 100644 --- a/CCallback.h +++ b/CCallback.h @@ -152,46 +152,4 @@ public: //friends friend class CClient; }; -class CScriptCallback -{ - CScriptCallback(){}; -public: - CGameState * gs; - CClient *cl; - - //get info - static int3 getPos(CGObjectInstance * ob); - int getHeroOwner(int heroID); - int getSelectedHero(); - int getDate(int mode=0); - - //do sth - void changePrimSkill(int ID, int which, int val); - void showInfoDialog(int player, std::string text, std::vector * components); //TODO: obslugiwac nulle - void showSelDialog(int player, std::string text, std::vector*components, IChosen * asker); - void giveResource(int player, int which, int val); - void showCompInfo(int player, SComponent * comp); - void heroVisitCastle(CGObjectInstance * ob, int heroID); - void stopHeroVisitCastle(CGObjectInstance * ob, int heroID); - void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack - void startBattle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2); //use hero=NULL for no hero - void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army - - //friends - friend class CGameState; - friend class CClient; -}; -class CLuaCallback : public CScriptCallback -{ -private: - - static void registerFuncs(lua_State * L); - static int getPos(lua_State * L);//(CGObjectInstance * object); - static int changePrimSkill(lua_State * L);//(int ID, int which, int val); - static int getGnrlText(lua_State * L);//(int ID, int which, int val); - static int getSelectedHero(lua_State * L);//() - - friend class CGameState; - friend class CClient; -}; #endif //CCALLBACK_H \ No newline at end of file diff --git a/CGameState.cpp b/CGameState.cpp index 45908b9a3..636f913e7 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -3,10 +3,6 @@ #include #include #include "CGameState.h" -#include "CGameInterface.h" -#include "CPlayerInterface.h" -#include "SDL_Extensions.h" -#include "CBattleInterface.h" //for CBattleHex #include #include "hch/CDefObjInfoHandler.h" #include "hch/CArtHandler.h" @@ -17,14 +13,10 @@ #include "lib/VCMI_Lib.h" #include "map.h" #include "StartInfo.h" -#include "CLua.h" -#include "CCallback.h" -#include "CLuaHandler.h" #include "lib/NetPacks.h" #include #include #include - boost::rand48 ran; class CMP_stack { @@ -143,6 +135,28 @@ void CGameState::apply(IPack * pack) players[h->getOwner()].fogOfWarMap[t.x][t.y][t.z] = 1; break; } + case 1001://set object property + { + SetObjectProperty *p = static_cast(pack); + int CGObjectInstance::*point; + switch(p->what) + { + case 1: + point = &CGObjectInstance::tempOwner; + break; + case 2: + point = &CGObjectInstance::blockVisit; + break; + } + map->objects[p->id]->*point = p->val; + break; + } + //case 1002://set hover name + // { + // SetHoverName * shn = static_cast(pack); + // map->objects[shn->id]->hoverName = toString(shn->name); + // break; + // } } mx->unlock(); } @@ -395,18 +409,6 @@ CGameState::~CGameState() { delete mx; } -bool CGameState::checkFunc(int obid, std::string name) -{ - if (objscr.find(obid)!=objscr.end()) - { - if(objscr[obid].find(name)!=objscr[obid].end()) - { - return true; - } - } - return false; -} - void CGameState::init(StartInfo * si, Mapa * map, int Seed) { day = 0; @@ -441,6 +443,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed) randomizeObject(map->objects[no]); if(map->objects[no]->ID==26) map->objects[no]->defInfo->handler=NULL; + map->objects[no]->hoverName = VLC->objh->names[map->objects[no]->ID]; } //std::cout<<"\tRandomizing objects: "< > * skrypty = &objscr; //alias for easier access - ///****************************C++ OBJECT SCRIPTS************************************************/ - //std::map scripts; - //CScriptCallback * csc = new CScriptCallback(); - //csc->gs = this; - //handleCPPObjS(&scripts,new CVisitableOPH(csc)); - //handleCPPObjS(&scripts,new CVisitableOPW(csc)); - //handleCPPObjS(&scripts,new CPickable(csc)); - //handleCPPObjS(&scripts,new CMines(csc)); - //handleCPPObjS(&scripts,new CTownScript(csc)); - //handleCPPObjS(&scripts,new CHeroScript(csc)); - //handleCPPObjS(&scripts,new CMonsterS(csc)); - //handleCPPObjS(&scripts,new CCreatureGen(csc)); - ////created map - - ///****************************LUA OBJECT SCRIPTS************************************************/ - //std::vector * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files - //for (int i=0; isize(); i++) - //{ - // try - // { - // std::vector * temp = CLuaHandler::functionList((*lf)[i]); - // CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]); - // CLuaCallback::registerFuncs(objs->is); - // //objs - // for (int j=0; jsize(); j++) - // { - // int obid ; //obj ID - // int dspos = (*temp)[j].find_first_of('_'); - // obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str()); - // std::string fname = (*temp)[j].substr(0,dspos); - // if (skrypty->find(obid)==skrypty->end()) - // skrypty->insert(std::pair >(obid,std::map())); - // (*skrypty)[obid].insert(std::pair(fname,objs)); - // } - // delete temp; - // }HANDLE_EXCEPTION - //} - ///****************************INITIALIZING OBJECT SCRIPTS************************************************/ - //std::string temps("newObject"); - //for (int i=0; iobjects.size(); i++) - //{ - // //c++ scripts - // if (scripts.find(map->objects[i]->ID) != scripts.end()) - // { - // map->objects[i]->state = scripts[map->objects[i]->ID]; - // map->objects[i]->state->newObject(map->objects[i]); - // } - // else - // { - // map->objects[i]->state = NULL; - // } - - // // lua scripts - // if(checkFunc(map->objects[i]->ID,temps)) - // (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); - //} - - //delete lf; } void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2) {/* diff --git a/CGameState.h b/CGameState.h index 5c551e1a5..68f317186 100644 --- a/CGameState.h +++ b/CGameState.h @@ -78,8 +78,6 @@ private: ui32 day; //total number of days in game Mapa * map; std::map players; //ID <-> playerstate - std::set cppscripts; //C++ scripts - std::map > objscr; //non-C++ scripts std::map villages, forts, capitols; //def-info for town graphics @@ -87,7 +85,6 @@ private: CGameState(); ~CGameState(); - bool checkFunc(int obid, std::string name); void init(StartInfo * si, Mapa * map, int Seed); void apply(IPack * pack); void randomizeObject(CGObjectInstance *cur); diff --git a/CLua.cpp b/CLua.cpp index 57d341d3e..ed58fc320 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -1,29 +1,26 @@ #include "stdafx.h" -#include "CLua.h" -#include "CLuaHandler.h" +#include +#include +#include #include "hch/CHeroHandler.h" +#include "hch/CObjectHandler.h" +#include "hch/CTownHandler.h" +#include "hch/CArtHandler.h" +#include "hch/CDefObjInfoHandler.h" //#include "lua.h" //#include "lualib.h" //#include "lauxlib.h" //#include "lobject.h" //#include "lgc.h" //#include "lapi.h" -#include "CGameInfo.h" +#include "CLua.h" #include "CGameState.h" -#include -#include "hch/CObjectHandler.h" -#include "hch/CTownHandler.h" -#include "hch/CArtHandler.h" -#include "CCallback.h" -#include "hch/CGeneralTextHandler.h" -#include -#include "CPlayerInterface.h" -#include -#include -#include "hch/CDefObjInfoHandler.h" +#include "lib/VCMI_Lib.h" #include "map.h" -#include "maphandler.h" +#include "server/CScriptCallback.h" +#include "lib/NetPacks.h" #pragma warning (disable : 4311) +#define DEFOS const CGObjectInstance *os = cb->getObj(objid) bool getGlobalFunc(lua_State * L, std::string fname) { //unsigned int hash = lua_calchash(fname.c_str(), fname.size()); @@ -138,7 +135,7 @@ std::string CLuaObjectScript::genFN(std::string base, int ID) return sts.str(); } -void CLuaObjectScript::newObject(CGObjectInstance *os) +void CLuaObjectScript::newObject(int objid) { //findF(genFN("newObject",os->ID)); //lua_pushinteger(is, (int)os); @@ -150,7 +147,7 @@ void CLuaObjectScript::newObject(CGObjectInstance *os) //lua_settop(is, 0); return; } -void CLuaObjectScript::onHeroVisit(CGObjectInstance *os, int heroID) +void CLuaObjectScript::onHeroVisit(int objid, int heroID) { //findF(genFN("heroVisit",os->ID)); //lua_pushinteger(is, (int)os); @@ -162,43 +159,75 @@ void CLuaObjectScript::onHeroVisit(CGObjectInstance *os, int heroID) //} //lua_settop(is, 0); } -std::string CLuaObjectScript::hoverText(CGObjectInstance *os) -{ - //findF(genFN("hoverText",os->ID)); - //lua_pushinteger(is, (int)os); - //if (lua_pcall (is, 1, 1, 0)) - //{ - // lua_settop(is, 0); - // throw new std::exception(("Failed to call "+genFN("hoverText",os->ID)+" function in lua script.").c_str()); - //} - //std::string ret = lua_tostring(is,1); - //lua_settop(is, 0); - return ""; -} +//std::string CLuaObjectScript::hoverText(int objid) +//{ +// //findF(genFN("hoverText",os->ID)); +// //lua_pushinteger(is, (int)os); +// //if (lua_pcall (is, 1, 1, 0)) +// //{ +// // lua_settop(is, 0); +// // throw new std::exception(("Failed to call "+genFN("hoverText",os->ID)+" function in lua script.").c_str()); +// //} +// //std::string ret = lua_tostring(is,1); +// //lua_settop(is, 0); +// return ""; +//} -std::string CCPPObjectScript::hoverText(CGObjectInstance *os) -{ - return CGI->objh->objects[os->defInfo->id].name; -} - -void CVisitableOPH::newObject(CGObjectInstance *os) +void CVisitableOPH::newObject(int objid) { visitors.insert - (std::pair >(os,std::set())); + (std::pair >(objid,std::set())); + + DEFOS; + MetaString hovername; + int pom; + switch(os->ID) + { + case 51: + pom = 8; + break; + case 23: + pom = 7; + break; + case 61: + pom = 11; + break; + case 32: + pom = 4; + break; + case 100: + pom = 5; + break; + default: + throw new std::exception("Unsupported ID in CVisitableOPH::hoverText"); + } + + hovername << std::pair(3,os->ID) << " " << std::pair(2,pom); + cb->setHoverName(objid,&hovername); + + //int heroID = cb->getSelectedHero(); + //if (heroID>=0) + //{ + //add += ( (visitors[os].find(heroID) == visitors[os].end()) + // ? + // (VLC->generaltexth->allTexts[353]) //not visited + // : + // ( VLC->generaltexth->allTexts[352]) ); //visited + //} }; -void CVisitableOPH::onHeroVisit(CGObjectInstance *os, int heroID) +void CVisitableOPH::onHeroVisit(int objid, int heroID) { - if (visitors.find(os)!=visitors.end()) + if (visitors.find(objid)!=visitors.end()) { - if(visitors[os].find(heroID)==visitors[os].end()) + if(visitors[objid].find(heroID)==visitors[objid].end()) { - onNAHeroVisit(os,heroID, false); - visitors[os].insert(heroID); + onNAHeroVisit(objid,heroID, false); + visitors[objid].insert(heroID); } else { - onNAHeroVisit(os,heroID, true); + onNAHeroVisit(objid,heroID, true); } } else @@ -206,8 +235,9 @@ void CVisitableOPH::onHeroVisit(CGObjectInstance *os, int heroID) throw new std::exception("Skrypt nie zainicjalizowal instancji tego obiektu. :("); } }; -void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited) +void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited) { + const CGObjectInstance *os = cb->getObj(objid); int w=0, ot=0, vvv=1; switch(os->ID) { @@ -242,30 +272,26 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already case 61: case 32: { - cb->changePrimSkill(heroID,w,vvv); - std::vector weko; - weko.push_back(new SComponent(SComponent::primskill,w,vvv)); - cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko); - //for (int ii=0; iichangePrimSkill(heroID,w,vvv); + //std::vector weko; + //weko.push_back(new SComponent(SComponent::primskill,w,vvv)); + //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&weko); + //break; } case 100: { - cb->changePrimSkill(heroID,w,vvv); - std::vector weko; - weko.push_back(new SComponent(SComponent::experience,0,vvv)); - cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko); - //for (int ii=0; iichangePrimSkill(heroID,w,vvv); + //std::vector weko; + //weko.push_back(new SComponent(SComponent::experience,0,vvv)); + //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&weko); + //break; } } } else { ot++; - cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&std::vector()); + cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&std::vector()); } } @@ -280,126 +306,93 @@ std::vector CVisitableOPH::yourObjects() return ret; } -std::string CVisitableOPH::hoverText(CGObjectInstance *os) +void CVisitableOPW::onNAHeroVisit(int objid, int heroID, bool alreadyVisited) { - std::string add; - int pom; - switch(os->ID) - { - case 51: - pom = 8; - break; - case 23: - pom = 7; - break; - case 61: - pom = 11; - break; - case 32: - pom = 4; - break; - case 100: - pom = 5; - break; - default: - throw new std::exception("Unsupported ID in CVisitableOPH::hoverText"); - } - add = " " + CGI->objh->xtrainfo[pom] + " "; - int heroID = cb->getSelectedHero(); - if (heroID>=0) - { - add += ( (visitors[os].find(heroID) == visitors[os].end()) - ? - (CGI->generaltexth->allTexts[353]) //not visited - : - ( CGI->generaltexth->allTexts[352]) ); //visited - } - return CGI->objh->objects[os->defInfo->id].name + add; -} - -void CVisitableOPW::onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited) -{ - int mid; - switch (os->ID) - { - case 55: - mid = 92; - break; - case 112: - mid = 170; - break; - case 109: - mid = 164; - break; - } - if (alreadyVisited) - { - if (os->ID!=112) - mid++; - else - mid--; - cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[mid],&std::vector()); //TODO: maybe we have memory leak with these windows - } - else - { - int type, sub, val; - type = SComponent::resource; - switch (os->ID) - { - case 55: - if (rand()%2) - { - sub = 5; - val = 5; - } - else - { - sub = 6; - val = 500; - } - break; - case 112: - mid = 170; - sub = (rand() % 5) + 1; - val = (rand() % 4) + 3; - break; - case 109: - mid = 164; - sub = 6; - if(cb->getDate(2)<2) - val = 500; - else - val = 1000; - } - SComponent * com = new SComponent((SComponent::Etype)type,sub,val); - std::vector weko; - weko.push_back(com); - cb->giveResource(cb->getHeroOwner(heroID),sub,val); - cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[mid],&weko); - visited[os] = true; - } + //int mid; + //switch (os->ID) + //{ + //case 55: + // mid = 92; + // break; + //case 112: + // mid = 170; + // break; + //case 109: + // mid = 164; + // break; + //} + //if (alreadyVisited) + //{ + // if (os->ID!=112) + // mid++; + // else + // mid--; + // cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[mid],&std::vector()); //TODO: maybe we have memory leak with these windows + //} + //else + //{ + // int type, sub, val; + // type = SComponent::resource; + // switch (os->ID) + // { + // case 55: + // if (rand()%2) + // { + // sub = 5; + // val = 5; + // } + // else + // { + // sub = 6; + // val = 500; + // } + // break; + // case 112: + // mid = 170; + // sub = (rand() % 5) + 1; + // val = (rand() % 4) + 3; + // break; + // case 109: + // mid = 164; + // sub = 6; + // if(cb->getDate(2)<2) + // val = 500; + // else + // val = 1000; + // } + // SComponent * com = new SComponent((SComponent::Etype)type,sub,val); + // std::vector weko; + // weko.push_back(com); + // cb->giveResource(cb->getHeroOwner(heroID),sub,val); + // cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[mid],&weko); + // visited[os] = true; + //} } void CVisitableOPW::newTurn () { if (cb->getDate(1)==1) { - for (std::map::iterator i = visited.begin(); i != visited.end(); i++) + for (std::map::iterator i = visited.begin(); i != visited.end(); i++) { (*i).second = false; } } } -void CVisitableOPW::newObject(CGObjectInstance *os) +void CVisitableOPW::newObject(int objid) { - visited.insert(std::pair(os,false)); + visited.insert(std::pair(objid,false)); + DEFOS; + MetaString ms; + ms << std::pair(3,os->ID) << " " << std::pair(1,visited[objid] ? 352 : 353); + cb->setHoverName(objid,&ms); } -void CVisitableOPW::onHeroVisit(CGObjectInstance *os, int heroID) +void CVisitableOPW::onHeroVisit(int objid, int heroID) { - if(visited[os]) - onNAHeroVisit(os,heroID,true); + if(visited[objid]) + onNAHeroVisit(objid,heroID,true); else - onNAHeroVisit(os,heroID,false); + onNAHeroVisit(objid,heroID,false); } std::vector CVisitableOPW::yourObjects() //returns IDs of objects which are handled by script @@ -411,38 +404,43 @@ std::vector CVisitableOPW::yourObjects() //returns IDs of objects which are return ret; } -std::string CVisitableOPW::hoverText(CGObjectInstance *os) +void CMines::newObject(int objid) { - return CGI->objh->objects[os->defInfo->id].name + " " + ( (visited[os]) ? (CGI->generaltexth->allTexts[352]) : (CGI->generaltexth->allTexts[353])) ; + ourObjs.push_back(objid); + cb->setOwner(objid,NEUTRAL_PLAYER); + DEFOS; + MetaString ms; + ms << std::pair(3,os->ID); + cb->setHoverName(objid,&ms); } - -void CMines::newObject(CGObjectInstance *os) +void CMines::onHeroVisit(int objid, int heroID) { - ourObjs.push_back(os); - os->tempOwner = NEUTRAL_PLAYER; -} -void CMines::onHeroVisit(CGObjectInstance *os, int heroID) -{ - int vv = 1; - if (os->subID==0 || os->subID==2) - vv++; - else if (os->subID==6) - vv = 1000; - if (os->tempOwner == cb->getHeroOwner(heroID)) - { - //TODO: garrison - } - else - { - if (os->subID==7) - return; //TODO: support for abandoned mine - os->tempOwner = cb->getHeroOwner(heroID); - SComponent * com = new SComponent(SComponent::Etype::resource,os->subID,vv); - com->subtitle+=CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2); - std::vector weko; - weko.push_back(com); - cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->mines[os->subID].second,&weko); - } + DEFOS; + const CGHeroInstance *h = cb->getHero(heroID); + cb->setOwner(objid,h->tempOwner); + MetaString ms; + ms << std::pair(9,os->subID) << " " << std::pair(6,23+h->tempOwner); + cb->setHoverName(objid,&ms); + //int vv = 1; + //if (os->subID==0 || os->subID==2) + // vv++; + //else if (os->subID==6) + // vv = 1000; + //if (os->tempOwner == cb->getHeroOwner(heroID)) + //{ + // //TODO: garrison + //} + //else + //{ + // if (os->subID==7) + // return; //TODO: support for abandoned mine + // os->tempOwner = cb->getHeroOwner(heroID); + // SComponent * com = new SComponent(SComponent::Etype::resource,os->subID,vv); + // com->subtitle+=VLC->generaltexth->allTexts[3].substr(2,VLC->generaltexth->allTexts[3].length()-2); + // std::vector weko; + // weko.push_back(com); + // cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->mines[os->subID].second,&weko); + //} } std::vector CMines::yourObjects() { @@ -450,36 +448,48 @@ std::vector CMines::yourObjects() ret.push_back(53); return ret; } -std::string CMines::hoverText(CGObjectInstance *os) -{ - if (os->tempOwner == NEUTRAL_PLAYER) - return CGI->objh->mines[os->subID].first; - else - return CGI->objh->mines[os->subID].first + " " + CGI->generaltexth->arraytxt[23+os->tempOwner]; - -} void CMines::newTurn () { - for (int i=0;itempOwner == NEUTRAL_PLAYER) + obj = cb->getObj(ourObjs[i]); + if (obj->tempOwner == NEUTRAL_PLAYER) continue; int vv = 1; - if (ourObjs[i]->subID==0 || ourObjs[i]->subID==2) + if (obj->subID==0 || obj->subID==2) vv++; - else if (ourObjs[i]->subID==6) + else if (obj->subID==6) vv = 1000; - cb->giveResource(ourObjs[i]->tempOwner,ourObjs[i]->subID,vv); + cb->giveResource(obj->tempOwner,obj->subID,vv); } } -void CPickable::newObject(CGObjectInstance *os) +void CPickable::newObject(int objid) { - os->blockVisit = true; + cb->setBlockVis(objid,true); + + MetaString ms; + DEFOS; + switch (os->ID) + { + case 79: + ms << std::pair(4,os->ID); + break; + case 5: + ms << std::pair(5,os->ID); + break; + default: + ms << std::pair(3,os->ID); + break; + } + + cb->setHoverName(objid,&ms); } -void CPickable::onHeroVisit(CGObjectInstance *os, int heroID) +void CPickable::onHeroVisit(int objid, int heroID) { + DEFOS; switch(os->ID) { case 5: @@ -489,109 +499,93 @@ void CPickable::onHeroVisit(CGObjectInstance *os, int heroID) } case 79: { - //TODO: handle guards (when battles are finished) - CResourceObjInfo * t2 = static_cast(os->info); - int val; - if(t2->amount) - val = t2->amount; - else - { - switch(os->subID) - { - case 6: - val = 500 + (rand()%6)*100; - break; - case 0: case 2: - val = 6 + (rand()%5); - break; - default: - val = 3 + (rand()%3); - break; - } - } - if(t2->message.length()) - cb->showInfoDialog(cb->getHeroOwner(heroID),t2->message,&std::vector()); - SComponent ccc(SComponent::resource,os->subID,val); - ccc.description = CGI->objh->advobtxt[113]; - boost::algorithm::replace_first(ccc.description,"%s",CGI->objh->restypes[os->subID]); - cb->giveResource(cb->getHeroOwner(heroID),os->subID,val); - cb->showCompInfo(cb->getHeroOwner(heroID),&ccc); + ////TODO: handle guards (when battles are finished) + //CResourceObjInfo * t2 = static_cast(os->info); + //int val; + //if(t2->amount) + // val = t2->amount; + //else + //{ + // switch(os->subID) + // { + // case 6: + // val = 500 + (rand()%6)*100; + // break; + // case 0: case 2: + // val = 6 + (rand()%5); + // break; + // default: + // val = 3 + (rand()%3); + // break; + // } + //} + //if(t2->message.length()) + // cb->showInfoDialog(cb->getHeroOwner(heroID),t2->message,&std::vector()); + //SComponent ccc(SComponent::resource,os->subID,val); + //ccc.description = VLC->objh->advobtxt[113]; + //boost::algorithm::replace_first(ccc.description,"%s",VLC->objh->restypes[os->subID]); + //cb->giveResource(cb->getHeroOwner(heroID),os->subID,val); + //cb->showCompInfo(cb->getHeroOwner(heroID),&ccc); break; } case 101: { - if (os->subID) - break; //not OH3 treasure chest - int wyn = rand()%100; - if (wyn<32) - { - tempStore.push_back(new CSelectableComponent(SComponent::resource,6,1000)); - tempStore.push_back(new CSelectableComponent(SComponent::experience,0,500)); - }//1k/0.5k - else if(wyn<64) - { - tempStore.push_back(new CSelectableComponent(SComponent::resource,6,1500)); - tempStore.push_back(new CSelectableComponent(SComponent::experience,0,1000)); - }//1.5k/1k - else if(wyn<95) - { - tempStore.push_back(new CSelectableComponent(SComponent::resource,6,2000)); - tempStore.push_back(new CSelectableComponent(SComponent::experience,0,1500)); - }//2k/1.5k - else - { - if (1/*TODO: backpack is full*/) - { - tempStore.push_back(new CSelectableComponent(SComponent::resource,6,1000)); - tempStore.push_back(new CSelectableComponent(SComponent::experience,0,500)); - } - else - { - //TODO: give treasure artifact - break; - } - }//random treasure artifact, or (if backapack is full) 1k/0.5k - tempStore[1]->ID = heroID; - player = cb->getHeroOwner(heroID); - cb->showSelDialog(player,CGI->objh->advobtxt[146],&tempStore,this); + //if (os->subID) + // break; //not OH3 treasure chest + //int wyn = rand()%100; + //if (wyn<32) + //{ + // tempStore.push_back(new CSelectableComponent(SComponent::resource,6,1000)); + // tempStore.push_back(new CSelectableComponent(SComponent::experience,0,500)); + //}//1k/0.5k + //else if(wyn<64) + //{ + // tempStore.push_back(new CSelectableComponent(SComponent::resource,6,1500)); + // tempStore.push_back(new CSelectableComponent(SComponent::experience,0,1000)); + //}//1.5k/1k + //else if(wyn<95) + //{ + // tempStore.push_back(new CSelectableComponent(SComponent::resource,6,2000)); + // tempStore.push_back(new CSelectableComponent(SComponent::experience,0,1500)); + //}//2k/1.5k + //else + //{ + // if (1/*TODO: backpack is full*/) + // { + // tempStore.push_back(new CSelectableComponent(SComponent::resource,6,1000)); + // tempStore.push_back(new CSelectableComponent(SComponent::experience,0,500)); + // } + // else + // { + // //TODO: give treasure artifact + // break; + // } + //}//random treasure artifact, or (if backapack is full) 1k/0.5k + //tempStore[1]->ID = heroID; + //player = cb->getHeroOwner(heroID); + //cb->showSelDialog(player,VLC->objh->advobtxt[146],&tempStore,this); break; } } - CGI->mh->removeObject(os); + //VLC->mh->removeObject(os); } void CPickable::chosen(int which) { - switch(tempStore[which]->type) - { - case SComponent::resource: - cb->giveResource(player,tempStore[which]->subtype,tempStore[which]->val); - break; - case SComponent::experience: - cb->changePrimSkill(tempStore[which]->ID,4,tempStore[which]->val); - break; - default: - throw new std::exception("Unhandled choice"); - - } - for (int i=0;iID) - { - case 79: - return CGI->objh->restypes[os->subID]; - break; - case 5: - return CGI->arth->artifacts[os->subID].name; - break; - default: - return CGI->objh->objects[os->defInfo->id].name; - break; - } + //switch(tempStore[which]->type) + //{ + //case SComponent::resource: + // cb->giveResource(player,tempStore[which]->subtype,tempStore[which]->val); + // break; + //case SComponent::experience: + // cb->changePrimSkill(tempStore[which]->ID,4,tempStore[which]->val); + // break; + //default: + // throw new std::exception("Unhandled choice"); + // + //} + //for (int i=0;i CPickable::yourObjects() //returns IDs of objects which are handled by script @@ -603,20 +597,22 @@ std::vector CPickable::yourObjects() //returns IDs of objects which are han return ret; } -void CTownScript::onHeroVisit(CGObjectInstance *os, int heroID) +void CTownScript::onHeroVisit(int objid, int heroID) { - cb->heroVisitCastle(os,heroID); + cb->heroVisitCastle(objid,heroID); } -void CTownScript::onHeroLeave(CGObjectInstance *os, int heroID) + +void CTownScript::newObject(int objid) { - cb->stopHeroVisitCastle(os,heroID); + MetaString ms; + const CGTownInstance * n = cb->getTown(objid); + ms << n->name << ", " << n->town->name; + cb->setHoverName(objid,&ms); } -std::string CTownScript::hoverText(CGObjectInstance *os) + +void CTownScript::onHeroLeave(int objid, int heroID) { - CGTownInstance * n; - if(n = dynamic_cast(os)) - return n->name + ", " + n->town->name; - else return ""; + cb->stopHeroVisitCastle(objid,heroID); } std::vector CTownScript::yourObjects() //returns IDs of objects which are handled by script @@ -626,27 +622,28 @@ std::vector CTownScript::yourObjects() //returns IDs of objects which are h return ret; } -void CHeroScript::newObject(CGObjectInstance *os) +void CHeroScript::newObject(int objid) { - os->blockVisit = true; - heroes.insert(std::pair(os->subID,os)); + cb->setBlockVis(objid,true); } -void CHeroScript::onHeroVisit(CGObjectInstance *os, int heroID) +void CHeroScript::onHeroVisit(int objid, int heroID) { //TODO: check for allies - if(static_cast(heroes[heroID])->tempOwner == static_cast(os)->tempOwner) //one of allied cases + const CGHeroInstance *my = cb->getHero(objid), + *vis = cb->getHero(objid); + if(my->tempOwner == vis->tempOwner) //one of allied cases { //exchange } else { cb->startBattle( - &(static_cast(heroes[heroID]))->army, - &(static_cast(os))->army, - os->pos, - static_cast(heroes[heroID]), - static_cast(os)); + &my->army, + &vis->army, + my->pos, + my, + vis); } } std::vector CHeroScript::yourObjects() //returns IDs of objects which are handled by script @@ -655,64 +652,66 @@ std::vector CHeroScript::yourObjects() //returns IDs of objects which are h ret.push_back(34); //hero return ret; } -std::string CHeroScript::hoverText(CGObjectInstance *os) -{ - CGHeroInstance* h = static_cast(os); - std::string ret = CGI->generaltexth->allTexts[15]; - boost::algorithm::replace_first(ret,"%s",h->name); - boost::algorithm::replace_first(ret,"%s",h->type->heroClass->name); - return ret; -} -void CMonsterS::newObject(CGObjectInstance *os) +//std::string CHeroScript::hoverText(int objid) +//{ +// //CGHeroInstance* h = static_cast(os); +// //std::string ret = VLC->generaltexth->allTexts[15]; +// //boost::algorithm::replace_first(ret,"%s",h->name); +// //boost::algorithm::replace_first(ret,"%s",h->type->heroClass->name); +// //return ret; +// return ""; +//} +void CMonsterS::newObject(int objid) { //os->blockVisit = true; - switch(CGI->creh->creatures[os->subID].level) + DEFOS; + switch(VLC->creh->creatures[os->subID].level) { case 1: - ((CCreatureObjInfo*)os->info)->number = rand()%31+20; + amounts[objid] = rand()%31+20; break; case 2: - ((CCreatureObjInfo*)os->info)->number = rand()%16+15; + amounts[objid] = rand()%16+15; break; case 3: - ((CCreatureObjInfo*)os->info)->number = rand()%16+10; + amounts[objid] = rand()%16+10; break; case 4: - ((CCreatureObjInfo*)os->info)->number = rand()%11+10; + amounts[objid] = rand()%11+10; break; case 5: - ((CCreatureObjInfo*)os->info)->number = rand()%9+8; + amounts[objid] = rand()%9+8; break; case 6: - ((CCreatureObjInfo*)os->info)->number = rand()%8+5; + amounts[objid] = rand()%8+5; break; case 7: - ((CCreatureObjInfo*)os->info)->number = rand()%7+3; + amounts[objid] = rand()%7+3; break; case 8: - ((CCreatureObjInfo*)os->info)->number = rand()%4+2; + amounts[objid] = rand()%4+2; break; case 9: - ((CCreatureObjInfo*)os->info)->number = rand()%3+2; + amounts[objid] = rand()%3+2; break; case 10: - ((CCreatureObjInfo*)os->info)->number = rand()%3+1; + amounts[objid] = rand()%3+1; break; } -} -std::string CMonsterS::hoverText(CGObjectInstance *os) -{ - int pom = CCreature::getQuantityID(((CCreatureObjInfo*)os->info)->number); + MetaString ms; + int pom = CCreature::getQuantityID(amounts[objid]); pom = 174 + 3*pom + 1; - return CGI->generaltexth->arraytxt[pom] + " " + CGI->creh->creatures[os->subID].namePl; + ms << std::pair(6,pom) << " " << std::pair(7,os->subID); + cb->setHoverName(objid,&ms); } -void CMonsterS::onHeroVisit(CGObjectInstance *os, int heroID) +void CMonsterS::onHeroVisit(int objid, int heroID) { + DEFOS; CCreatureSet set; //TODO: zrobic secik w sposob wyrafinowany - set.slots[0] = std::pair(&CGI->creh->creatures[os->subID],((CCreatureObjInfo*)os->info)->number); + set.slots[0] = std::pair(&VLC->creh->creatures[os->subID],((CCreatureObjInfo*)os->info)->number); cb->startBattle(heroID,&set,os->pos); } std::vector CMonsterS::yourObjects() //returns IDs of objects which are handled by script @@ -723,15 +722,15 @@ std::vector CMonsterS::yourObjects() //returns IDs of objects which are han } -void CCreatureGen::newObject(CGObjectInstance *os) +void CCreatureGen::newObject(int objid) { - amount[os] = CGI->creh->creatures[CGI->objh->cregens[os->subID]].growth; + DEFOS; + amount[objid] = VLC->creh->creatures[VLC->objh->cregens[os->subID]].growth; + MetaString ms; + ms << std::pair(8,os->subID); + cb->setHoverName(objid,&ms); } -std::string CCreatureGen::hoverText(CGObjectInstance *os) -{ - return CGI->objh->creGens[os->subID]; -} -void CCreatureGen::onHeroVisit(CGObjectInstance *os, int heroID) +void CCreatureGen::onHeroVisit(int objid, int heroID) { } std::vector CCreatureGen::yourObjects() //returns IDs of objects which are handled by script diff --git a/CLua.h b/CLua.h index 6dc166f8a..15d4429d2 100644 --- a/CLua.h +++ b/CLua.h @@ -28,10 +28,10 @@ public: //functions to be called in script //virtual void init(){}; - virtual void newObject(CGObjectInstance *os){}; - virtual void onHeroVisit(CGObjectInstance *os, int heroID){}; - virtual void onHeroLeave(CGObjectInstance *os, int heroID){}; - virtual std::string hoverText(CGObjectInstance *os){return "";}; + virtual void newObject(int objid){}; + virtual void onHeroVisit(int objid, int heroID){}; + virtual void onHeroLeave(int objid, int heroID){}; + virtual std::string hoverText(int objid){return "";}; virtual void newTurn (){}; @@ -83,122 +83,101 @@ public: static std::string genFN(std::string base, int ID); void init(); - void newObject(CGObjectInstance *os); - void onHeroVisit(CGObjectInstance *os, int heroID); - std::string hoverText(CGObjectInstance *os); - - friend CGameState; + void newObject(int objid); + void onHeroVisit(int objid, int heroID); }; class CCPPObjectScript: public CObjectScript { -protected: +public: CScriptCallback * cb; CCPPObjectScript(CScriptCallback * CB){cb=CB;}; -public: virtual std::vector yourObjects()=0; //returns IDs of objects which are handled by script - virtual std::string hoverText(CGObjectInstance *os); }; class CVisitableOPH : public CCPPObjectScript //once per hero { +public: CVisitableOPH(CScriptCallback * CB):CCPPObjectScript(CB){}; - std::map > visitors; + std::map > visitors; - void onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited); - void newObject(CGObjectInstance *os); - void onHeroVisit(CGObjectInstance *os, int heroID); + void onNAHeroVisit(int objid, int heroID, bool alreadyVisited); + void newObject(int objid); + void onHeroVisit(int objid, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - std::string hoverText(CGObjectInstance *os); - - friend CGameState; }; class CVisitableOPW : public CCPPObjectScript //once per week { +public: CVisitableOPW(CScriptCallback * CB):CCPPObjectScript(CB){}; - std::map visited; - void onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited); - void newObject(CGObjectInstance *os); - void onHeroVisit(CGObjectInstance *os, int heroID); + std::map visited; + void onNAHeroVisit(int objid, int heroID, bool alreadyVisited); + void newObject(int objid); + void onHeroVisit(int objid, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - std::string hoverText(CGObjectInstance *os); void newTurn (); - - friend CGameState; }; class CMines : public CCPPObjectScript //flaggable, and giving resource at each day { +public: CMines(CScriptCallback * CB):CCPPObjectScript(CB){}; - std::vector ourObjs; + std::vector ourObjs; - void newObject(CGObjectInstance *os); - void onHeroVisit(CGObjectInstance *os, int heroID); + void newObject(int objid); + void onHeroVisit(int objid, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - std::string hoverText(CGObjectInstance *os); void newTurn (); - - friend CGameState; }; class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc { +public: std::vector tempStore; int player; CPickable(CScriptCallback * CB):CCPPObjectScript(CB){}; void chosen(int which); - void newObject(CGObjectInstance *os); - void onHeroVisit(CGObjectInstance *os, int heroID); - std::string hoverText(CGObjectInstance *os); + void newObject(int objid); + void onHeroVisit(int objid, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - - friend CGameState; }; class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, etc { +public: CTownScript(CScriptCallback * CB):CCPPObjectScript(CB){}; - void onHeroVisit(CGObjectInstance *os, int heroID); - void onHeroLeave(CGObjectInstance *os, int heroID); - std::string hoverText(CGObjectInstance *os); + void onHeroVisit(int objid, int heroID); + void onHeroLeave(int objid, int heroID); + void newObject(int objid); std::vector yourObjects(); //returns IDs of objects which are handled by script - - friend CGameState; }; class CHeroScript : public CCPPObjectScript { - std::map heroes; +public: CHeroScript(CScriptCallback * CB):CCPPObjectScript(CB){}; - void newObject(CGObjectInstance *os); - void onHeroVisit(CGObjectInstance *os, int heroID); + void newObject(int objid); + void onHeroVisit(int objid, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - std::string hoverText(CGObjectInstance *os); - - friend CGameState; }; class CMonsterS : public CCPPObjectScript { - std::map heroes; +public: + std::map amounts; //monster id -> stack quantity CMonsterS(CScriptCallback * CB):CCPPObjectScript(CB){}; - void newObject(CGObjectInstance *os); - std::string hoverText(CGObjectInstance *os); - void onHeroVisit(CGObjectInstance *os, int heroID); + void newObject(int objid); + void onHeroVisit(int objid, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - - friend CGameState; }; class CCreatureGen : public CCPPObjectScript { - std::map amount; //amount of creatures in each dwelling +public: + std::map amount; //amount of creatures in each dwelling CCreatureGen(CScriptCallback * CB):CCPPObjectScript(CB){}; - void newObject(CGObjectInstance *os); - std::string hoverText(CGObjectInstance *os); - void onHeroVisit(CGObjectInstance *os, int heroID); + void newObject(int objid); + void onHeroVisit(int objid, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - - friend CGameState; }; \ No newline at end of file diff --git a/CMT.cpp b/CMT.cpp index a09b61561..9c637e9fa 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -50,15 +50,7 @@ std::queue events; boost::mutex eventsM; TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; -void handleCPPObjS(std::map * mapa, CCPPObjectScript * script) -{ - std::vector tempv = script->yourObjects(); - for (int i=0;istate->cppscripts.insert(script); -} + int _tmain(int argc, _TCHAR* argv[]) { std::cout.flags(ios::unitbuf); diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 01e477b38..4d812052f 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -213,7 +213,7 @@ void CPathfinder::CalcH(Coordinate* node) y = CGI->mh->map->height-1; //Get the movement cost. - ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].tileInfo->tertype, CGI->mh->map->terrain[x][y][0].malle,CGI->mh->map->terrain[x][y][0].nuine); + ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].tileInfo->tertype, CGI->mh->map->terrain[x][y][node->z].malle,CGI->mh->map->terrain[x][y][node->z].nuine); node->h = ret; } diff --git a/client/Client.cpp b/client/Client.cpp index 3e8bc885f..70ef92b11 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -12,8 +12,69 @@ #include #include #include "../hch/CObjectHandler.h" +#include "../hch/CGeneralTextHandler.h" +#include "../hch/CArtHandler.h" +#include CSharedCond > mess(new std::set); +std::string toString(MetaString &ms) +{ + std::string ret; + for(int i=0;i0) + { + ret += ms.strings[ms.message[i]-1]; + } + else + { + std::vector *vec; + int type = ms.texts[-ms.message[i]-1].first; + if(type == 5) + { + ret += CGI->arth->artifacts[ms.texts[-ms.message[i]-1].second].name; + continue; + } + else if(type == 7) + { + ret += CGI->creh->creatures[ms.texts[-ms.message[i]-1].second].namePl; + continue; + } + else if(type == 9) + { + ret += CGI->objh->mines[ms.texts[-ms.message[i]-1].second].first; + continue; + } + else + { + switch(type) + { + case 1: + vec = &CGI->generaltexth->allTexts; + break; + case 2: + vec = &CGI->objh->xtrainfo; + break; + case 3: + vec = &CGI->objh->names; + break; + case 4: + vec = &CGI->objh->restypes; + break; + case 6: + vec = &CGI->generaltexth->arraytxt; + break; + case 8: + vec = &CGI->objh->creGens; + break; + } + ret += (*vec)[ms.texts[-ms.message[i]-1].second]; + } + } + } + return ret; +} + CClient::CClient(void) { } @@ -100,7 +161,7 @@ void CClient::process(int what) } case 501: //hero movement response - we have to notify interfaces and callback { - TryMoveHero *th = new TryMoveHero; + TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing *serv >> *th; std::cout << "HeroMove: id="<id<<"\tResult: "<<(unsigned)th->result<<"\tPosition "<end<notify_all(); break; } + case 1001: + { + SetObjectProperty sop; + *serv >> sop; + std::cout << "Setting " << (unsigned)sop.what << " property of " << sop.id <<" object to "<apply(&sop); + break; + } + case 1002: + { + SetHoverName shn; + *serv >> shn; + std::cout << "Setting a name of " << shn.id <<" object to "<< toString(shn.name) <mx->lock(); + gs->map->objects[shn.id]->hoverName = toString(shn.name); + gs->mx->unlock(); + break; + } + case 9999: + break; default: throw std::exception("Not supported server message!"); break; diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index 44ac9a49c..de8d21572 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -319,10 +319,6 @@ RelativePath=".\Client.cpp" > - - diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 1c4e63549..2aa8f0956 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -19,11 +19,11 @@ void CObjectHandler::loadObjects() int it=0; while (itgetTextFile("ADVEVENT.TXT"); diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 6a3673647..3e2929587 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -42,12 +42,6 @@ public: } }; -class DLL_EXPORT CObject //typical object that can be encountered on a map -{ -public: - std::string name; //object's name -}; - class DLL_EXPORT CGObjectInstance { public: @@ -58,9 +52,10 @@ public: CCPPObjectScript * state; CSpecObjInfo * info; unsigned char animPhaseShift; + std::string hoverName; int tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna - bool blockVisit; + int blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile virtual bool isHero() const; int getOwner() const; @@ -172,7 +167,7 @@ public: class DLL_EXPORT CObjectHandler { public: - std::vector objects; //vector of objects; i-th object in vector has subnumber i + std::vector names; //vector of objects; i-th object in vector has subnumber i std::vector cregens; //type 17. dwelling subid -> creature ID void loadObjects(); diff --git a/lib/Connection.h b/lib/Connection.h index 69621b2e0..6f7cd88ad 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -252,7 +252,16 @@ public: data.insert(ins); } } - + template + void saveSerializable(const std::pair &data) + { + *this << data.first << data.second; + } + template + void loadSerializable(std::pair &data) + { + *this >> data.first >> data.second; + } template void save(const T &data) { diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 2e63aaf03..a04d1507f 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -72,4 +72,57 @@ struct TryMoveHero : public CPack //501 { h & id & result & start & end & movePoints & fowRevealed; } -}; \ No newline at end of file +}; +struct MetaString : public CPack //2001 helper for object scrips +{ + std::vector strings; + std::vector > texts; //pairs; types: 1 - generaltexthandler->all; 2 - objh->xtrainfo; 3 - objh->names; 4 - objh->restypes; 5 - arth->artifacts[id].name; 6 - generaltexth->arraytxt; 7 - creh->creatures[os->subID].namePl; 8 - objh->creGens; 9 - objh->mines[ID].first + std::vector message; + + template void serialize(Handler &h, const int version) + { + h & strings & texts & message; + } + + MetaString& operator<<(const std::pair &txt) + { + message.push_back(-((si32)texts.size())-1); + texts.push_back(txt); + return *this; + } + MetaString& operator<<(const std::string &txt) + { + message.push_back(strings.size()+1); + strings.push_back(txt); + return *this; + } + + MetaString(){type = 2001;}; +}; + +struct SetObjectProperty : public CPack//1001 +{ + ui32 id; + ui8 what; //1 - owner; 2 - blockvis + ui32 val; + SetObjectProperty(){type = 1001;}; + SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;}; + + template void serialize(Handler &h, const int version) + { + h & id & what & val; + } +}; + +struct SetHoverName : public CPack//1002 +{ + ui32 id; + MetaString name; + SetHoverName(){type = 1002;}; + SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;}; + + template void serialize(Handler &h, const int version) + { + h & id & name; + } +}; \ No newline at end of file diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 3047c1617..981f4e5c8 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -3,6 +3,7 @@ #include #include #include "CGameHandler.h" +#include "CScriptCallback.h" #include "../CLua.h" #include "../CGameState.h" #include "../StartInfo.h" @@ -24,6 +25,27 @@ double distance(int3 a, int3 b) { return std::sqrt( (double)(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ); } +//bool CGameState::checkFunc(int obid, std::string name) +//{ +// if (objscr.find(obid)!=objscr.end()) +// { +// if(objscr[obid].find(name)!=objscr[obid].end()) +// { +// return true; +// } +// } +// return false; +//} + +void CGameHandler::handleCPPObjS(std::map * mapa, CCPPObjectScript * script) +{ + std::vector tempv = script->yourObjects(); + for (unsigned i=0;i players, CConnection &c) { @@ -51,7 +73,7 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) int3 hmpos = end + int3(-1,0,0); TerrainTile t = gs->map->terrain[hmpos.x][hmpos.y][hmpos.z]; CGHeroInstance *h = static_cast(gs->map->objects[id]); - int cost = (double)h->getTileCost(t.tertype,t.malle,t.nuine) * distance(start,end); + int cost = (int)((double)h->getTileCost(t.tertype,t.malle,t.nuine) * distance(start,end)); TryMoveHero tmh; tmh.id = id; @@ -85,16 +107,15 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) //we start moving if(blockvis)//interaction with blocking object (like resources) { - gs->apply(&tmh); - sendToAllClients(&tmh); //failed to move to that tile but we visit object + sendAndApply(&tmh); //failed to move to that tile but we visit object BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects) { if (obj->blockVisit) { - if(gs->checkFunc(obj->ID,"heroVisit")) //script function - gs->objscr[obj->ID]["heroVisit"]->onHeroVisit(obj,h->subID); + //if(gs->checkFunc(obj->ID,"heroVisit")) //script function + // gs->objscr[obj->ID]["heroVisit"]->onHeroVisit(obj,h->subID); if(obj->state) //hard-coded function - obj->state->onHeroVisit(obj,h->subID); + obj->state->onHeroVisit(obj->id,h->subID); } } break; @@ -107,7 +128,7 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) { //TODO: allow to handle this in script-languages if(obj->state) //hard-coded function - obj->state->onHeroLeave(obj,h->subID); + obj->state->onHeroLeave(obj->id,h->subID); } //reveal fog of war @@ -140,22 +161,19 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) } } - gs->apply(&tmh); - sendToAllClients(&tmh); + sendAndApply(&tmh); - //call objects if they arevisited - BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects) + BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects)//call objects if they are visited { - if(gs->checkFunc(obj->ID,"heroVisit")) //script function - gs->objscr[obj->ID]["heroVisit"]->onHeroVisit(obj,h->subID); + //if(gs->checkFunc(obj->ID,"heroVisit")) //script function + // gs->objscr[obj->ID]["heroVisit"]->onHeroVisit(obj,h->subID); if(obj->state) //hard-coded function - obj->state->onHeroVisit(obj,h->subID); + obj->state->onHeroVisit(obj->id,h->id); } } break; fail: - gs->apply(&tmh); - sendToAllClients(&tmh); + sendAndApply(&tmh); break; } default: @@ -180,11 +198,6 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) end = true; } } -template void CGameHandler::sendToAllClients(CPack * info) -{ - BOOST_FOREACH(CConnection* c, conns) - *c << info->getType() << *info->This(); -} CGameHandler::CGameHandler(void) { gs = NULL; @@ -198,7 +211,68 @@ void CGameHandler::init(StartInfo *si, int Seed) { Mapa *map = new Mapa(si->mapname); gs = new CGameState(); - gs->init(si,map,Seed); + gs->init(si,map,Seed); + + /****************************SCRIPTS************************************************/ + //std::map > * skrypty = &objscr; //alias for easier access + /****************************C++ OBJECT SCRIPTS************************************************/ + std::map scripts; + CScriptCallback * csc = new CScriptCallback(); + csc->gh = this; + handleCPPObjS(&scripts,new CVisitableOPH(csc)); + handleCPPObjS(&scripts,new CVisitableOPW(csc)); + handleCPPObjS(&scripts,new CPickable(csc)); + handleCPPObjS(&scripts,new CMines(csc)); + handleCPPObjS(&scripts,new CTownScript(csc)); + handleCPPObjS(&scripts,new CHeroScript(csc)); + handleCPPObjS(&scripts,new CMonsterS(csc)); + handleCPPObjS(&scripts,new CCreatureGen(csc)); + //created map + + /****************************LUA OBJECT SCRIPTS************************************************/ + //std::vector * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files + //for (int i=0; isize(); i++) + //{ + // try + // { + // std::vector * temp = CLuaHandler::functionList((*lf)[i]); + // CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]); + // CLuaCallback::registerFuncs(objs->is); + // //objs + // for (int j=0; jsize(); j++) + // { + // int obid ; //obj ID + // int dspos = (*temp)[j].find_first_of('_'); + // obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str()); + // std::string fname = (*temp)[j].substr(0,dspos); + // if (skrypty->find(obid)==skrypty->end()) + // skrypty->insert(std::pair >(obid,std::map())); + // (*skrypty)[obid].insert(std::pair(fname,objs)); + // } + // delete temp; + // }HANDLE_EXCEPTION + //} + /****************************INITIALIZING OBJECT SCRIPTS************************************************/ + //std::string temps("newObject"); + for (unsigned i=0; iobjects.size(); i++) + { + //c++ scripts + if (scripts.find(map->objects[i]->ID) != scripts.end()) + { + map->objects[i]->state = scripts[map->objects[i]->ID]; + map->objects[i]->state->newObject(map->objects[i]->id); + } + else + { + map->objects[i]->state = NULL; + } + + //// lua scripts + //if(checkFunc(map->objects[i]->ID,temps)) + // (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); + } + + //delete lf; } int lowestSpeed(CGHeroInstance * chi) { @@ -257,8 +331,7 @@ void CGameHandler::newTurn() } n.res.insert(r); } - gs->apply(&n); - sendToAllClients(&n); + sendAndApply(&n); //for (std::set::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++) //{ // (*i)->newTurn(); diff --git a/server/CGameHandler.h b/server/CGameHandler.h index d29bce860..54043d3e4 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -5,22 +5,45 @@ class CVCMIServer; class CGameState; class CConnection; struct StartInfo; +class CCPPObjectScript; +class CScriptCallback; template struct CPack; class CGameHandler { + CGameState *gs; + std::set cppscripts; //C++ scripts + //std::map > objscr; //non-C++ scripts + CVCMIServer *s; std::map connections; std::set conns; + + void handleCPPObjS(std::map * mapa, CCPPObjectScript * script); + public: CGameHandler(void); ~CGameHandler(void); void init(StartInfo *si, int Seed); void handleConnection(std::set players, CConnection &c); - template void sendToAllClients(CPack * info); + template void sendToAllClients(CPack * info) + { + for(std::set::iterator i=conns.begin(); i!=conns.end();i++) + { + (*i)->rmx->lock(); + **i << info->getType() << *info->This(); + (*i)->rmx->unlock(); + } + } + template void sendAndApply(CPack * info) + { + gs->apply(info); + sendToAllClients(info); + } void run(); void newTurn(); friend class CVCMIServer; + friend class CScriptCallback; }; diff --git a/server/CScriptCallback.cpp b/server/CScriptCallback.cpp new file mode 100644 index 000000000..8651f19f7 --- /dev/null +++ b/server/CScriptCallback.cpp @@ -0,0 +1,292 @@ +#include "CScriptCallback.h" +#include "../lib/Connection.h" +#include "CVCMIServer.h" +#include "CGameHandler.h" +#include "../CGameState.h" +#include "../map.h" +#include "../hch/CObjectHandler.h" +#include "../hch/CTownHandler.h" +#include "../hch/CHeroHandler.h" +#include "../lib/NetPacks.h" +#include +#include +CScriptCallback::CScriptCallback(void) +{ +} + +CScriptCallback::~CScriptCallback(void) +{ +} +void CScriptCallback::setBlockVis(int objid, bool bv) +{ + SetObjectProperty sop(objid,2,bv); + gh->sendAndApply(&sop); +} +void CScriptCallback::setOwner(int objid, ui8 owner) +{ + SetObjectProperty sop(objid,1,owner); + gh->sendAndApply(&sop); +} +const CGObjectInstance* CScriptCallback::getObj(int objid) +{ + return gh->gs->map->objects[objid]; +} +const CGHeroInstance* CScriptCallback::getHero(int objid) +{ + return static_cast(gh->gs->map->objects[objid]); +} +const CGTownInstance* CScriptCallback::getTown(int objid) +{ + return static_cast(gh->gs->map->objects[objid]); +} +void CScriptCallback::setHoverName(int objid, MetaString* name) +{ + SetHoverName shn(objid, *name); + gh->sendAndApply(&shn); +} +int3 CScriptCallback::getPos(CGObjectInstance * ob) +{ + return ob->pos; +} +void CScriptCallback::changePrimSkill(int ID, int which, int val) +{ + //CGHeroInstance * hero = gh->gs->map->getHero(ID,0); + //if (whichprimSkills[which]+=val; + // sv->playerint[hero->getOwner()]->heroPrimarySkillChanged(hero, which, val); + //} + //else if (which==4) + //{ + // hero->exp+=val; + // if(hero->exp >= CGI->heroh->reqExp(hero->level+1)) //new level + // { + // hero->level++; + // std::cout << hero->name <<" got level "<level<::*g = (hero->level>9) ? (&std::pair::second) : (&std::pair::first); + // for(;xtype->heroClass->primChance[x].*g; + // if(rprimSkills[x]++; + + // //TODO: dac dwie umiejetnosci 2-rzedne to wyboru + + // } + // //TODO - powiadomic interfejsy, sprawdzic czy nie ma awansu itp + //} +} + +int CScriptCallback::getHeroOwner(int heroID) +{ + //CGHeroInstance * hero = CGI->state->map->getHero(heroID,0); + //return hero->getOwner(); + return -1; +} +void CScriptCallback::showInfoDialog(int player, std::string text, std::vector * components) +{ + //TODO: upewniac sie ze mozemy to zrzutowac (przy customowych interfejsach cos moze sie kopnac) + //if (player>=0) + //{ + // CGameInterface * temp = sv->playerint[player]; + // if (temp->human) + // ((CPlayerInterface*)(temp))->showInfoDialog(text,*components); + // return; + //} + //else + //{ + // typedef std::pair intf; + // BOOST_FOREACH(intf & i, sv->playerint) + // { + // if (i.second->human) + // ((CPlayerInterface*)(i.second))->showInfoDialog(text,*components); + // } + //} +} + +void CScriptCallback::showSelDialog(int player, std::string text, std::vector*components, IChosen * asker) +{ + //CGameInterface * temp = sv->playerint[player]; + //if (temp->human) + // ((CPlayerInterface*)(temp))->showSelDialog(text,*components,(int)asker); + return; +} +int CScriptCallback::getSelectedHero() +{ + int ret; + //if (LOCPLINT->adventureInt->selection.type == HEROI_TYPE) + // ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->subID; + //else + // ret = -1;; + return ret; +} +int CScriptCallback::getDate(int mode) +{ + int temp; + switch (mode) + { + case 0: + return gh->gs->day; + break; + case 1: + temp = (gh->gs->day)%7; + if (temp) + return temp; + else return 7; + break; + case 2: + temp = ((gh->gs->day-1)/7)+1; + if (!(temp%4)) + return 4; + else + return (temp%4); + break; + case 3: + return ((gh->gs->day-1)/28)+1; + break; + } + return 0; +} +void CScriptCallback::giveResource(int player, int which, int val) +{ + //gh->gs->players[player].resources[which]+=val; + //sv->playerint[player]->receivedResource(which,val); +} +void CScriptCallback::showCompInfo(int player, SComponent * comp) +{ + //CPlayerInterface * i = dynamic_cast(sv->playerint[player]); + //if(i) + // i->showComp(*comp); +} +void CScriptCallback::heroVisitCastle(int obj, int heroID) +{ + //CGTownInstance * n; + //if(n = dynamic_cast(ob)) + //{ + // n->visitingHero = CGI->state->map->getHero(heroID,0); + // gh->gs->map->getHero(heroID,0)->visitedTown = n; + // sv->playerint[getHeroOwner(heroID)]->heroVisitsTown(CGI->state->map->getHero(heroID,0),n); + //} + //else + // return; +} + +void CScriptCallback::stopHeroVisitCastle(int obj, int heroID) +{ + //CGTownInstance * n; + //if(n = dynamic_cast(ob)) + //{ + // CGI->state->map->getHero(heroID,0)->visitedTown = NULL; + // if(n->visitingHero && n->visitingHero->type->ID == heroID) + // n->visitingHero = NULL; + // return; + //} + //else + // return; +} +void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos==-1 - first free slot in backpack +{ + CGHeroInstance* h = gh->gs->map->getHero(hid,0); + if(position<0) + { + for(unsigned i=0;iartifacts.size();i++) + { + if(!h->artifacts[i]) + { + h->artifacts[i] = artid; + return; + } + } + h->artifacts.push_back(artid); + return; + } + else + { + if(h->artifWorn[position]) //slot is occupied + { + giveHeroArtifact(h->artifWorn[position],hid,-1); + } + h->artifWorn[position] = artid; + } +} + +void CScriptCallback::startBattle(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2) //use hero=NULL for no hero +{ + //gh->gs->battle(army1,army2,tile,hero1,hero2); +} +void CScriptCallback::startBattle(int heroID, CCreatureSet * army, int3 tile) //for hero<=>neutral army +{ + //CGHeroInstance* h = gh->gs->map->getHero(heroID,0); + //gh->gs->battle(&h->army,army,tile,h,NULL); +} +void CLuaCallback::registerFuncs(lua_State * L) +{ +// lua_newtable(L); +// +//#define REGISTER_C_FUNC(x) \ +// lua_pushstring(L, #x); \ +// lua_pushcfunction(L, x); \ +// lua_rawset(L, -3) +// +// REGISTER_C_FUNC(getPos); +// REGISTER_C_FUNC(changePrimSkill); +// REGISTER_C_FUNC(getGnrlText); +// REGISTER_C_FUNC(getSelectedHero); +// +// lua_setglobal(L, "vcmi"); +// #undef REGISTER_C_FUNC +} +int CLuaCallback::getPos(lua_State * L)//(CGObjectInstance * object); +{ + //const int args = lua_gettop(L); // number of arguments + //if ((args < 1) || !lua_isnumber(L, 1) ) + // luaL_error(L, + // "Incorrect arguments to getPos([Object address])"); + //CGObjectInstance * object = (CGObjectInstance *)(lua_tointeger(L, 1)); + //lua_pushinteger(L,object->pos.x); + //lua_pushinteger(L,object->pos.y); + //lua_pushinteger(L,object->pos.z); + return 3; +} +int CLuaCallback::changePrimSkill(lua_State * L)//(int ID, int which, int val); +{ + //const int args = lua_gettop(L); // number of arguments + //if ((args < 1) || !lua_isnumber(L, 1) || + // ((args >= 2) && !lua_isnumber(L, 2)) || + // ((args >= 3) && !lua_isnumber(L, 3)) ) + //{ + // luaL_error(L, + // "Incorrect arguments to changePrimSkill([Hero ID], [Which Primary skill], [Change by])"); + //} + //int ID = lua_tointeger(L, 1), + // which = lua_tointeger(L, 2), + // val = lua_tointeger(L, 3); + + //CScriptCallback::changePrimSkill(ID,which,val); + + return 0; +} +int CLuaCallback::getGnrlText(lua_State * L) //(int which),returns string +{ + //const int args = lua_gettop(L); // number of arguments + //if ((args < 1) || !lua_isnumber(L, 1) ) + // luaL_error(L, + // "Incorrect arguments to getGnrlText([Text ID])"); + //int which = lua_tointeger(L,1); + //lua_pushstring(L,CGI->generaltexth->allTexts[which].c_str()); + return 1; +} +int CLuaCallback::getSelectedHero(lua_State * L) //(),returns int (ID of hero, -1 if no hero is seleceted) +{ + //int ret; + //if (LOCPLINT->adventureInt->selection.type == HEROI_TYPE) + // ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->subID; + //else + // ret = -1; + //lua_pushinteger(L,ret); + return 1; +} diff --git a/server/CScriptCallback.h b/server/CScriptCallback.h new file mode 100644 index 000000000..4b4e9ef21 --- /dev/null +++ b/server/CScriptCallback.h @@ -0,0 +1,62 @@ +#pragma once +#include "../global.h" +#include +class CVCMIServer; +class CGameHandler; +class SComponent; +class CSelectableComponent; +class IChosen; +class CCreatureSet; +class CGHeroInstance; +class CGObjectInstance; +class CGHeroInstance; +class CGTownInstance; +class CGameState; +struct lua_State; +struct MetaString; +class CScriptCallback +{ + CScriptCallback(void); +public: + ~CScriptCallback(void); + CGameHandler *gh; + + //get info + static int3 getPos(CGObjectInstance * ob); + int getHeroOwner(int heroID); + int getSelectedHero(); + int getDate(int mode=0); + const CGObjectInstance* getObj(int objid); + const CGHeroInstance* getHero(int objid); + const CGTownInstance* getTown(int objid); + + //do sth + void setBlockVis(int objid, bool bv); + void setOwner(int objid, ui8 owner); + void setHoverName(int objid, MetaString * name); + void changePrimSkill(int ID, int which, int val); + void showInfoDialog(int player, std::string text, std::vector * components); //TODO: obslugiwac nulle + void showSelDialog(int player, std::string text, std::vector*components, IChosen * asker); + void giveResource(int player, int which, int val); + void showCompInfo(int player, SComponent * comp); + void heroVisitCastle(int obj, int heroID); + void stopHeroVisitCastle(int obj, int heroID); + void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack + void startBattle(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2); //use hero=NULL for no hero + void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army + + //friends + friend class CGameHandler; +}; +class CLuaCallback : public CScriptCallback +{ +private: + + static void registerFuncs(lua_State * L); + static int getPos(lua_State * L);//(CGObjectInstance * object); + static int changePrimSkill(lua_State * L);//(int ID, int which, int val); + static int getGnrlText(lua_State * L);//(int ID, int which, int val); + static int getSelectedHero(lua_State * L);//() + + friend class CGameHandler; +}; \ No newline at end of file diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h index ad1a26af1..c78af3c63 100644 --- a/server/CVCMIServer.h +++ b/server/CVCMIServer.h @@ -1,6 +1,7 @@ #pragma once #include "../global.h" #include +class CConnection; namespace boost { namespace asio diff --git a/server/VCMI_server.vcproj b/server/VCMI_server.vcproj index 23217f874..8c2ceb0e8 100644 --- a/server/VCMI_server.vcproj +++ b/server/VCMI_server.vcproj @@ -175,6 +175,14 @@ RelativePath=".\CGameHandler.cpp" > + + + + @@ -189,6 +197,14 @@ RelativePath=".\CGameHandler.h" > + + + + From 03287540c75bcf93c3cd4ca48caffe5fba32ce7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Wed, 30 Jul 2008 21:27:15 +0000 Subject: [PATCH 32/47] Further code for objects (mines) - not finished. --- CGameInterface.h | 2 ++ CGameState.h | 1 - CHeroWindow.cpp | 16 ++++----- CLua.cpp | 40 ++++++++++----------- CPlayerInterface.cpp | 27 +++++++++++++++ CPlayerInterface.h | 5 +-- client/Client.cpp | 32 ++++++++++++++--- lib/NetPacks.h | 46 +++++++++++++++++++++++- server/CGameHandler.cpp | 71 +++++++++++++++++++------------------- server/CScriptCallback.cpp | 8 ++++- server/CScriptCallback.h | 3 +- 11 files changed, 175 insertions(+), 76 deletions(-) diff --git a/CGameInterface.h b/CGameInterface.h index c074caf50..c8a3bba4b 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -10,6 +10,7 @@ class CCallback; class ICallback; class CGlobalAI; class CGHeroInstance; +class Component; class CSelectableComponent; struct HeroMoveDetails; class CGHeroInstance; @@ -59,6 +60,7 @@ 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 &components)=0{}; virtual void showSelDialog(std::string text, std::vector & 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 diff --git a/CGameState.h b/CGameState.h index 68f317186..0d01d6db2 100644 --- a/CGameState.h +++ b/CGameState.h @@ -104,7 +104,6 @@ public: friend class CClient; friend void initGameState(Mapa * map, CGameInfo * cgi); friend class CScriptCallback; - friend void handleCPPObjS(std::map * mapa, CCPPObjectScript * script); friend class CMapHandler; friend class CGameHandler; }; diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index c2c672a3a..93358842b 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -1034,10 +1034,10 @@ void LClickableArea::deactivate() } void LClickableArea::clickLeft(boost::logic::tribool down) { - if(!down) - { - LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector()); - } + //if(!down) + //{ + // LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector()); + //} } void RClickableArea::activate() @@ -1050,10 +1050,10 @@ void RClickableArea::deactivate() } void RClickableArea::clickRight(boost::logic::tribool down) { - if(!down) - { - LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector()); - } + //if(!down) + //{ + // LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector()); + //} } void LRClickableAreaWText::clickLeft(boost::logic::tribool down) diff --git a/CLua.cpp b/CLua.cpp index ed58fc320..e1f9f7894 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -291,7 +291,7 @@ void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited) else { ot++; - cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&std::vector()); + //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&std::vector()); } } @@ -415,36 +415,32 @@ void CMines::newObject(int objid) } void CMines::onHeroVisit(int objid, int heroID) { + //TODO: this is code for standard mines, no support for abandoned mine (subId==7) DEFOS; const CGHeroInstance *h = cb->getHero(heroID); cb->setOwner(objid,h->tempOwner); MetaString ms; ms << std::pair(9,os->subID) << " " << std::pair(6,23+h->tempOwner); cb->setHoverName(objid,&ms); - //int vv = 1; - //if (os->subID==0 || os->subID==2) - // vv++; - //else if (os->subID==6) - // vv = 1000; - //if (os->tempOwner == cb->getHeroOwner(heroID)) - //{ - // //TODO: garrison - //} - //else - //{ - // if (os->subID==7) - // return; //TODO: support for abandoned mine - // os->tempOwner = cb->getHeroOwner(heroID); - // SComponent * com = new SComponent(SComponent::Etype::resource,os->subID,vv); - // com->subtitle+=VLC->generaltexth->allTexts[3].substr(2,VLC->generaltexth->allTexts[3].length()-2); - // std::vector weko; - // weko.push_back(com); - // cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->mines[os->subID].second,&weko); - //} + ms.clear(); + + int vv=1; //amount of resource per turn + if (os->subID==0 || os->subID==2) + vv++; + else if (os->subID==6) + vv = 1000; + + InfoWindow iw; + iw.text << std::pair(10,os->subID); + iw.player = h->tempOwner; + iw.components.push_back(Component(2,os->subID,vv,-1)); + cb->showInfoDialog(&iw); + //TODO: leaving garrison + } std::vector CMines::yourObjects() { - std::vector ret(1); + std::vector ret; ret.push_back(53); return ret; } diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 45e368bf0..24b0ec727 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -33,6 +33,7 @@ #include "client/CCreatureAnimation.h" #include "client/Graphics.h" #include "map.h" +#include "lib/NetPacks.h" using namespace CSDL_Ext; extern TTF_Font * GEOR16; @@ -41,6 +42,14 @@ CPlayerInterface * LOCPLINT; extern std::queue events; extern boost::mutex eventsM; +SComponent toSComponent(const Component *c) +{ + SComponent ret((SComponent::Etype)c->type,c->subtype,c->val); + if(c->type == 2) + ret.subtitle+=CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2); + return ret; +} + class OCM_HLP_CGIN { public: @@ -2014,6 +2023,24 @@ void CPlayerInterface::showComp(SComponent comp) adventureInt->infoBar.showComp(&comp,4000); } +void CPlayerInterface::showInfoDialog(std::string text, std::vector &components) +{ + curint->deactivate(); //dezaktywacja starego interfejsu + std::vector intComps; + CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,intComps); + LOCPLINT->objsToBlit.push_back(temp); + temp->pos.x=300-(temp->pos.w/2); + temp->pos.y=300-(temp->pos.h/2); + temp->okb.pos.x = temp->okb.posr.x + temp->pos.x; + temp->okb.pos.y = temp->okb.posr.y + temp->pos.y; + temp->okb.activate(); + for (int i=0;icomponents.size();i++) + { + temp->components[i]->activate(); + temp->components[i]->pos.x += temp->pos.x; + temp->components[i]->pos.y += temp->pos.y; + } +} void CPlayerInterface::showInfoDialog(std::string text, std::vector & components) { curint->deactivate(); //dezaktywacja starego interfejsu diff --git a/CPlayerInterface.h b/CPlayerInterface.h index d3efc047a..69e098019 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -154,7 +154,7 @@ public: }; class CInfoWindow : public CSimpleWindow //text + comp. + ok button -{ //okno usuwa swoje komponenty w chwili zamkniecia +{ //window deletes its components when closed public: CSCButton okb; std::vector components; @@ -320,6 +320,7 @@ public: void heroCreated(const CGHeroInstance* hero); void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val); void receivedResource(int type, int val); + void showInfoDialog(std::string text, std::vector &components); void showSelDialog(std::string text, std::vector & components, int askID); void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town); void garrisonChanged(const CGObjectInstance * obj); @@ -350,8 +351,8 @@ public: void handleMouseMotion(SDL_Event *sEvent); void init(ICallback * CB); int3 repairScreenPos(int3 pos); + void removeObjToBlit(IShowable* obj); void showInfoDialog(std::string text, std::vector & components); - void removeObjToBlit(IShowable* obj); CPlayerInterface(int Player, int serial);//c-tor }; diff --git a/client/Client.cpp b/client/Client.cpp index 70ef92b11..85e74684f 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -29,20 +29,26 @@ std::string toString(MetaString &ms) else { std::vector *vec; - int type = ms.texts[-ms.message[i]-1].first; + int type = ms.texts[-ms.message[i]-1].first, + ser = ms.texts[-ms.message[i]-1].second; if(type == 5) { - ret += CGI->arth->artifacts[ms.texts[-ms.message[i]-1].second].name; + ret += CGI->arth->artifacts[ser].name; continue; } else if(type == 7) { - ret += CGI->creh->creatures[ms.texts[-ms.message[i]-1].second].namePl; + ret += CGI->creh->creatures[ser].namePl; continue; } else if(type == 9) { - ret += CGI->objh->mines[ms.texts[-ms.message[i]-1].second].first; + ret += CGI->objh->mines[ser].first; + continue; + } + else if(type == 10) + { + ret += CGI->objh->mines[ser].second; continue; } else @@ -68,7 +74,7 @@ std::string toString(MetaString &ms) vec = &CGI->objh->creGens; break; } - ret += (*vec)[ms.texts[-ms.message[i]-1].second]; + ret += (*vec)[ser]; } } } @@ -159,6 +165,22 @@ void CClient::process(int what) std::cout << "done!"<> sr; + std::cout << "Set amount of "<objh->restypes[sr.resid] + << " of player "<<(unsigned)sr.player <<" to "<apply(&sr); + playerint[sr.player]->receivedResource(sr.resid,sr.val); + break; + } + case 103: //show info dialog + { + InfoWindow iw; + *serv >> iw; + + } case 501: //hero movement response - we have to notify interfaces and callback { TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing diff --git a/lib/NetPacks.h b/lib/NetPacks.h index a04d1507f..07a535d49 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -59,6 +59,18 @@ struct NewTurn : public CPack //101 h & heroes & res & day & resetBuilded; } }; +struct SetResource : public CPack //102 +{ + SetResource(){type = 102;}; + + ui8 player, resid; + si32 val; + + template void serialize(Handler &h, const int version) + { + h & player & resid & val; + } +}; struct TryMoveHero : public CPack //501 { TryMoveHero(){type = 501;}; @@ -76,7 +88,7 @@ struct TryMoveHero : public CPack //501 struct MetaString : public CPack //2001 helper for object scrips { std::vector strings; - std::vector > texts; //pairs; types: 1 - generaltexthandler->all; 2 - objh->xtrainfo; 3 - objh->names; 4 - objh->restypes; 5 - arth->artifacts[id].name; 6 - generaltexth->arraytxt; 7 - creh->creatures[os->subID].namePl; 8 - objh->creGens; 9 - objh->mines[ID].first + std::vector > texts; //pairs; types: 1 - generaltexthandler->all; 2 - objh->xtrainfo; 3 - objh->names; 4 - objh->restypes; 5 - arth->artifacts[id].name; 6 - generaltexth->arraytxt; 7 - creh->creatures[os->subID].namePl; 8 - objh->creGens; 9 - objh->mines[ID].first; 10 - objh->mines[ID].second std::vector message; template void serialize(Handler &h, const int version) @@ -96,8 +108,40 @@ struct MetaString : public CPack //2001 helper for object scrips strings.push_back(txt); return *this; } + void clear() + { + strings.clear(); + texts.clear(); + message.clear(); + } MetaString(){type = 2001;}; +}; +struct Component : public CPack //2002 helper for object scrips informations +{ + ui16 type, subtype; //types: 0 - primskill; 1 - secskill; 2 - resource; 3 - creature; 4 - artifact; 5 - experience + si32 val; // + give; - take + si16 when; // 0 - now; +x - within x days; -x - per x days + + template void serialize(Handler &h, const int version) + { + h & type & subtype & val & when; + } + Component(){type = 2002;}; + Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):type(Type),subtype(Subtype),val(Val),when(When){type = 2002;}; +}; + +struct InfoWindow : public CPack //103 - displays simple info window +{ + MetaString text; + std::vector components; + ui8 player; + + template void serialize(Handler &h, const int version) + { + h & text & components & player; + } + InfoWindow(){type = 103;}; }; struct SetObjectProperty : public CPack//1001 diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 981f4e5c8..9c4b4a812 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -213,22 +213,6 @@ void CGameHandler::init(StartInfo *si, int Seed) gs = new CGameState(); gs->init(si,map,Seed); - /****************************SCRIPTS************************************************/ - //std::map > * skrypty = &objscr; //alias for easier access - /****************************C++ OBJECT SCRIPTS************************************************/ - std::map scripts; - CScriptCallback * csc = new CScriptCallback(); - csc->gh = this; - handleCPPObjS(&scripts,new CVisitableOPH(csc)); - handleCPPObjS(&scripts,new CVisitableOPW(csc)); - handleCPPObjS(&scripts,new CPickable(csc)); - handleCPPObjS(&scripts,new CMines(csc)); - handleCPPObjS(&scripts,new CTownScript(csc)); - handleCPPObjS(&scripts,new CHeroScript(csc)); - handleCPPObjS(&scripts,new CMonsterS(csc)); - handleCPPObjS(&scripts,new CCreatureGen(csc)); - //created map - /****************************LUA OBJECT SCRIPTS************************************************/ //std::vector * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files //for (int i=0; isize(); i++) @@ -252,25 +236,6 @@ void CGameHandler::init(StartInfo *si, int Seed) // delete temp; // }HANDLE_EXCEPTION //} - /****************************INITIALIZING OBJECT SCRIPTS************************************************/ - //std::string temps("newObject"); - for (unsigned i=0; iobjects.size(); i++) - { - //c++ scripts - if (scripts.find(map->objects[i]->ID) != scripts.end()) - { - map->objects[i]->state = scripts[map->objects[i]->ID]; - map->objects[i]->state->newObject(map->objects[i]->id); - } - else - { - map->objects[i]->state = NULL; - } - - //// lua scripts - //if(checkFunc(map->objects[i]->ID,temps)) - // (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); - } //delete lf; } @@ -363,6 +328,42 @@ void CGameHandler::run() boost::thread(boost::bind(&CGameHandler::handleConnection,this,pom,boost::ref(**i))); } + + /****************************SCRIPTS************************************************/ + //std::map > * skrypty = &objscr; //alias for easier access + /****************************C++ OBJECT SCRIPTS************************************************/ + std::map scripts; + CScriptCallback * csc = new CScriptCallback(); + csc->gh = this; + handleCPPObjS(&scripts,new CVisitableOPH(csc)); + handleCPPObjS(&scripts,new CVisitableOPW(csc)); + handleCPPObjS(&scripts,new CPickable(csc)); + handleCPPObjS(&scripts,new CMines(csc)); + handleCPPObjS(&scripts,new CTownScript(csc)); + handleCPPObjS(&scripts,new CHeroScript(csc)); + handleCPPObjS(&scripts,new CMonsterS(csc)); + handleCPPObjS(&scripts,new CCreatureGen(csc)); + + /****************************INITIALIZING OBJECT SCRIPTS************************************************/ + //std::string temps("newObject"); + for (unsigned i=0; imap->objects.size(); i++) + { + //c++ scripts + if (scripts.find(gs->map->objects[i]->ID) != scripts.end()) + { + gs->map->objects[i]->state = scripts[gs->map->objects[i]->ID]; + gs->map->objects[i]->state->newObject(gs->map->objects[i]->id); + } + else + { + gs->map->objects[i]->state = NULL; + } + + //// lua scripts + //if(checkFunc(map->objects[i]->ID,temps)) + // (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); + } + while (!end) { newTurn(); diff --git a/server/CScriptCallback.cpp b/server/CScriptCallback.cpp index 8651f19f7..21cc08650 100644 --- a/server/CScriptCallback.cpp +++ b/server/CScriptCallback.cpp @@ -87,8 +87,9 @@ int CScriptCallback::getHeroOwner(int heroID) //return hero->getOwner(); return -1; } -void CScriptCallback::showInfoDialog(int player, std::string text, std::vector * components) +void CScriptCallback::showInfoDialog(InfoWindow *iw) { + gh->sendToAllClients(iw); //TODO: upewniac sie ze mozemy to zrzutowac (przy customowych interfejsach cos moze sie kopnac) //if (player>=0) //{ @@ -153,6 +154,11 @@ int CScriptCallback::getDate(int mode) } void CScriptCallback::giveResource(int player, int which, int val) { + SetResource sr; + sr.player = player; + sr.resid = which; + sr.val = (gh->gs->players[player].resources[which]+val); + gh->sendAndApply(&sr); //gh->gs->players[player].resources[which]+=val; //sv->playerint[player]->receivedResource(which,val); } diff --git a/server/CScriptCallback.h b/server/CScriptCallback.h index 4b4e9ef21..e90135a72 100644 --- a/server/CScriptCallback.h +++ b/server/CScriptCallback.h @@ -14,6 +14,7 @@ class CGTownInstance; class CGameState; struct lua_State; struct MetaString; +struct InfoWindow; class CScriptCallback { CScriptCallback(void); @@ -35,7 +36,7 @@ public: void setOwner(int objid, ui8 owner); void setHoverName(int objid, MetaString * name); void changePrimSkill(int ID, int which, int val); - void showInfoDialog(int player, std::string text, std::vector * components); //TODO: obslugiwac nulle + void showInfoDialog(InfoWindow *iw); void showSelDialog(int player, std::string text, std::vector*components, IChosen * asker); void giveResource(int player, int which, int val); void showCompInfo(int player, SComponent * comp); From 28d5c184a9f9b11a8a64da0a82de971f91170ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 31 Jul 2008 10:35:22 +0000 Subject: [PATCH 33/47] Mines and object visitable once per week working. --- CGameState.cpp | 6 ++ CLua.cpp | 143 ++++++++++++++++++++----------------- CPlayerInterface.cpp | 26 ++++--- CPlayerInterface.h | 3 +- client/Client.cpp | 8 ++- lib/NetPacks.h | 8 +-- server/CGameHandler.cpp | 8 +-- server/CScriptCallback.cpp | 31 +------- 8 files changed, 121 insertions(+), 112 deletions(-) diff --git a/CGameState.cpp b/CGameState.cpp index 636f913e7..22b2d2e41 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -122,6 +122,12 @@ void CGameState::apply(IPack * pack) t->builded = 0; break; } + case 102: //set resource amount + { + SetResource *sr = static_cast(pack); + players[sr->player].resources[sr->resid] = sr->val; + break; + } case 501://hero try-move { TryMoveHero * n = static_cast(pack); diff --git a/CLua.cpp b/CLua.cpp index e1f9f7894..f7800a593 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -201,7 +201,6 @@ void CVisitableOPH::newObject(int objid) default: throw new std::exception("Unsupported ID in CVisitableOPH::hoverText"); } - hovername << std::pair(3,os->ID) << " " << std::pair(2,pom); cb->setHoverName(objid,&hovername); @@ -308,74 +307,88 @@ std::vector CVisitableOPH::yourObjects() void CVisitableOPW::onNAHeroVisit(int objid, int heroID, bool alreadyVisited) { - //int mid; - //switch (os->ID) - //{ - //case 55: - // mid = 92; - // break; - //case 112: - // mid = 170; - // break; - //case 109: - // mid = 164; - // break; - //} - //if (alreadyVisited) - //{ - // if (os->ID!=112) - // mid++; - // else - // mid--; - // cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[mid],&std::vector()); //TODO: maybe we have memory leak with these windows - //} - //else - //{ - // int type, sub, val; - // type = SComponent::resource; - // switch (os->ID) - // { - // case 55: - // if (rand()%2) - // { - // sub = 5; - // val = 5; - // } - // else - // { - // sub = 6; - // val = 500; - // } - // break; - // case 112: - // mid = 170; - // sub = (rand() % 5) + 1; - // val = (rand() % 4) + 3; - // break; - // case 109: - // mid = 164; - // sub = 6; - // if(cb->getDate(2)<2) - // val = 500; - // else - // val = 1000; - // } - // SComponent * com = new SComponent((SComponent::Etype)type,sub,val); - // std::vector weko; - // weko.push_back(com); - // cb->giveResource(cb->getHeroOwner(heroID),sub,val); - // cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[mid],&weko); - // visited[os] = true; - //} + DEFOS; + int mid; + switch (os->ID) + { + case 55: + mid = 92; + break; + case 112: + mid = 170; + break; + case 109: + mid = 164; + break; + } + if (alreadyVisited) + { + if (os->ID!=112) + mid++; + else + mid--; + + InfoWindow iw; + iw.player = cb->getHero(heroID)->tempOwner; + iw.text << std::pair(11,mid); + cb->showInfoDialog(&iw); + } + else + { + int type, sub, val; + type = 2; + switch (os->ID) + { + case 55: + if (rand()%2) + { + sub = 5; + val = 5; + } + else + { + sub = 6; + val = 500; + } + break; + case 112: + mid = 170; + sub = (rand() % 5) + 1; + val = (rand() % 4) + 3; + break; + case 109: + mid = 164; + sub = 6; + if(cb->getDate(2)<2) + val = 500; + else + val = 1000; + } + int player = cb->getHeroOwner(heroID); + cb->giveResource(player,sub,val); + InfoWindow iw; + iw.player = player; + iw.components.push_back(Component(type,sub,val,0)); + iw.text << std::pair(11,mid); + cb->showInfoDialog(&iw); + visited[objid] = true; + MetaString ms; //set text to "visited" + ms << std::pair(3,os->ID) << " " << std::pair(1,352); + cb->setHoverName(objid,&ms); + } } void CVisitableOPW::newTurn () { - if (cb->getDate(1)==1) + if (cb->getDate(1)==1) //first day of week { for (std::map::iterator i = visited.begin(); i != visited.end(); i++) { (*i).second = false; + MetaString ms; //set text to "not visited" + ms << std::pair(3,cb->getObj(i->first)->ID) << " " << std::pair(1,353); + cb->setHoverName(i->first,&ms); } + } } void CVisitableOPW::newObject(int objid) @@ -418,6 +431,8 @@ void CMines::onHeroVisit(int objid, int heroID) //TODO: this is code for standard mines, no support for abandoned mine (subId==7) DEFOS; const CGHeroInstance *h = cb->getHero(heroID); + if(h->tempOwner == os->tempOwner) + return; //TODO: leaving garrison cb->setOwner(objid,h->tempOwner); MetaString ms; ms << std::pair(9,os->subID) << " " << std::pair(6,23+h->tempOwner); @@ -435,8 +450,6 @@ void CMines::onHeroVisit(int objid, int heroID) iw.player = h->tempOwner; iw.components.push_back(Component(2,os->subID,vv,-1)); cb->showInfoDialog(&iw); - //TODO: leaving garrison - } std::vector CMines::yourObjects() { @@ -471,10 +484,10 @@ void CPickable::newObject(int objid) switch (os->ID) { case 79: - ms << std::pair(4,os->ID); + ms << std::pair(4,os->subID); break; case 5: - ms << std::pair(5,os->ID); + ms << std::pair(5,os->subID); break; default: ms << std::pair(3,os->ID); diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 24b0ec727..8ca30f9a3 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -42,13 +42,6 @@ CPlayerInterface * LOCPLINT; extern std::queue events; extern boost::mutex eventsM; -SComponent toSComponent(const Component *c) -{ - SComponent ret((SComponent::Etype)c->type,c->subtype,c->val); - if(c->type == 2) - ret.subtitle+=CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2); - return ret; -} class OCM_HLP_CGIN { @@ -537,7 +530,7 @@ void CInfoPopup::show(SDL_Surface * to) blitAt(bitmap,pos.x,pos.y,(to)?(to):(screen)); } -SComponent::SComponent(Etype Type, int Subtype, int Val) +void SComponent::init(Etype Type, int Subtype, int Val) { std::ostringstream oss; switch (Type) @@ -565,7 +558,22 @@ SComponent::SComponent(Etype Type, int Subtype, int Val) pos.w = temp->w; pos.h = temp->h; } +SComponent::SComponent(Etype Type, int Subtype, int Val) +{ + init(Type,Subtype,Val); +} +SComponent::SComponent(const Component &c) +{ + init((Etype)c.id,c.subtype,c.val); + switch(c.id) + { + case resource: + if(c.when==1) + subtitle += CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2); + break; + } +} SDL_Surface * SComponent::getImg() { switch (type) @@ -2027,6 +2035,8 @@ void CPlayerInterface::showInfoDialog(std::string text, std::vector { curint->deactivate(); //dezaktywacja starego interfejsu std::vector intComps; + for(int i=0;iplayerID,32,intComps); LOCPLINT->objsToBlit.push_back(temp); temp->pos.x=300-(temp->pos.w/2); diff --git a/CPlayerInterface.h b/CPlayerInterface.h index 69e098019..b529faeaf 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -207,8 +207,9 @@ public: std::string description; //r-click std::string subtitle; + void init(Etype Type, int Subtype, int Val); SComponent(Etype Type, int Subtype, int Val); - //SComponent(const & SComponent r); + SComponent(const Component &c); void clickRight (boost::logic::tribool down); virtual SDL_Surface * getImg(); diff --git a/client/Client.cpp b/client/Client.cpp index 85e74684f..769c7daff 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -73,6 +73,8 @@ std::string toString(MetaString &ms) case 8: vec = &CGI->objh->creGens; break; + case 11: + vec = &CGI->objh->advobtxt; } ret += (*vec)[ser]; } @@ -179,7 +181,11 @@ void CClient::process(int what) { InfoWindow iw; *serv >> iw; - + std::vector comps; + for(int i=0;ishowInfoDialog(toString(iw.text),comps); + break; } case 501: //hero movement response - we have to notify interfaces and callback { diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 07a535d49..ed08054fa 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -88,7 +88,7 @@ struct TryMoveHero : public CPack //501 struct MetaString : public CPack //2001 helper for object scrips { std::vector strings; - std::vector > texts; //pairs; types: 1 - generaltexthandler->all; 2 - objh->xtrainfo; 3 - objh->names; 4 - objh->restypes; 5 - arth->artifacts[id].name; 6 - generaltexth->arraytxt; 7 - creh->creatures[os->subID].namePl; 8 - objh->creGens; 9 - objh->mines[ID].first; 10 - objh->mines[ID].second + std::vector > texts; //pairs; types: 1 - generaltexthandler->all; 2 - objh->xtrainfo; 3 - objh->names; 4 - objh->restypes; 5 - arth->artifacts[id].name; 6 - generaltexth->arraytxt; 7 - creh->creatures[os->subID].namePl; 8 - objh->creGens; 9 - objh->mines[ID].first; 10 - objh->mines[ID].second; 11 - objh->advobtxt std::vector message; template void serialize(Handler &h, const int version) @@ -119,16 +119,16 @@ struct MetaString : public CPack //2001 helper for object scrips }; struct Component : public CPack //2002 helper for object scrips informations { - ui16 type, subtype; //types: 0 - primskill; 1 - secskill; 2 - resource; 3 - creature; 4 - artifact; 5 - experience + ui16 id, subtype; //ids: 0 - primskill; 1 - secskill; 2 - resource; 3 - creature; 4 - artifact; 5 - experience si32 val; // + give; - take si16 when; // 0 - now; +x - within x days; -x - per x days template void serialize(Handler &h, const int version) { - h & type & subtype & val & when; + h & id & subtype & val & when; } Component(){type = 2002;}; - Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):type(Type),subtype(Subtype),val(Val),when(When){type = 2002;}; + Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):id(Type),subtype(Subtype),val(Val),when(When){type = 2002;}; }; struct InfoWindow : public CPack //103 - displays simple info window diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 9c4b4a812..a36b344fa 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -297,10 +297,10 @@ void CGameHandler::newTurn() n.res.insert(r); } sendAndApply(&n); - //for (std::set::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++) - //{ - // (*i)->newTurn(); - //} + for (std::set::iterator i=cppscripts.begin();i!=cppscripts.end();i++) + { + (*i)->newTurn(); + } } void CGameHandler::run() { diff --git a/server/CScriptCallback.cpp b/server/CScriptCallback.cpp index 21cc08650..69581f6fd 100644 --- a/server/CScriptCallback.cpp +++ b/server/CScriptCallback.cpp @@ -83,9 +83,7 @@ void CScriptCallback::changePrimSkill(int ID, int which, int val) int CScriptCallback::getHeroOwner(int heroID) { - //CGHeroInstance * hero = CGI->state->map->getHero(heroID,0); - //return hero->getOwner(); - return -1; + return gh->gs->map->objects[heroID]->tempOwner; } void CScriptCallback::showInfoDialog(InfoWindow *iw) { @@ -127,30 +125,7 @@ int CScriptCallback::getSelectedHero() } int CScriptCallback::getDate(int mode) { - int temp; - switch (mode) - { - case 0: - return gh->gs->day; - break; - case 1: - temp = (gh->gs->day)%7; - if (temp) - return temp; - else return 7; - break; - case 2: - temp = ((gh->gs->day-1)/7)+1; - if (!(temp%4)) - return 4; - else - return (temp%4); - break; - case 3: - return ((gh->gs->day-1)/28)+1; - break; - } - return 0; + return gh->gs->getDate(mode); } void CScriptCallback::giveResource(int player, int which, int val) { @@ -159,8 +134,6 @@ void CScriptCallback::giveResource(int player, int which, int val) sr.resid = which; sr.val = (gh->gs->players[player].resources[which]+val); gh->sendAndApply(&sr); - //gh->gs->players[player].resources[which]+=val; - //sv->playerint[player]->receivedResource(which,val); } void CScriptCallback::showCompInfo(int player, SComponent * comp) { From 5c5c80933b9aa271ead43d06664243c787b57677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 31 Jul 2008 13:21:42 +0000 Subject: [PATCH 34/47] Made CreatureSet serializable and using creature id. Stack moving, swapping, merging, splitting. --- CCallback.cpp | 70 +++++------------------------ CGameState.cpp | 13 ++++-- CLua.cpp | 2 +- CPlayerInterface.cpp | 8 ++-- client/Client.cpp | 12 +++++ client/Graphics.cpp | 8 ++-- client/VCMI_client.vcproj | 12 +++-- hch/CObjectHandler.cpp | 4 +- int3.h | 8 +++- lib/Connection.h | 19 ++++++++ lib/NetPacks.h | 10 +++++ lib/VCMI_lib.vcproj | 92 +++++---------------------------------- map.cpp | 15 ++++--- server/CGameHandler.cpp | 55 +++++++++++++++++++++-- server/VCMI_server.vcproj | 77 ++++++++++++++++++++++++++++++++ 15 files changed, 235 insertions(+), 170 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index a6e4c15d1..650eb4b19 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -136,11 +136,11 @@ void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount //recruit int slot = -1; //slot ID - std::pair > parb; + std::pair > parb; for(int i=0;i<7;i++) //TODO: if there is already stack of same creatures it should be used always { - if((!t->army.slots[i].first) || (t->army.slots[i].first->idNumber == ID)) //slot is free or there is saem creature + if(((!t->army.slots[i].first) && (!t->army.slots[i].second)) || (t->army.slots[i].first == ID)) //slot is free or there is saem creature { slot = i; break; @@ -160,7 +160,7 @@ void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount } else //create new stack in the garrison { - t->army.slots[slot].first = &CGI->creh->creatures[ID]; + t->army.slots[slot].first = ID; t->army.slots[slot].second = amount; } cl->playerint[player]->garrisonChanged(obj); @@ -194,7 +194,7 @@ void CCallback::endTurn() UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos) { UpgradeInfo ret; - CCreature *base = ((CArmedInstance*)obj)->army.slots[stackPos].first; + CCreature *base = &CGI->creh->creatures[((CArmedInstance *)obj)->army.slots[stackPos].first]; if((obj->ID == 98) || ((obj->ID == 34) && static_cast(obj)->visitedTown)) { CGTownInstance * t; @@ -404,79 +404,29 @@ const CCreatureSet* CCallback::getGarrison(const CGObjectInstance *obj) int CCallback::swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2) { - CCreatureSet *S1 = const_cast(getGarrison(s1)), *S2 = const_cast(getGarrison(s2)); - if (false) - { - //TODO: check if we are allowed to swap these creatures + if(s1->tempOwner != player || s2->tempOwner != player) return -1; - } - CCreature * pom = S2->slots[p2].first; - S2->slots[p2].first = S1->slots[p1].first; - S1->slots[p1].first = pom; - int pom2 = S2->slots[p2].second; - S2->slots[p2].second = S1->slots[p1].second; - S1->slots[p1].second = pom2; - - if(!S1->slots[p1].first) - S1->slots.erase(p1); - if(!S2->slots[p2].first) - S2->slots.erase(p2); - - if(s1->tempOwnerplayerint[s1->tempOwner]->garrisonChanged(s1); - if((s2->tempOwnerplayerint[s2->tempOwner]->garrisonChanged(s2); + *cl->serv << ui16(502) << ui8(1) << s1->id << ui8(p1) << s2->id << ui8(p2); return 0; } int CCallback::mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2) { - CCreatureSet *S1 = const_cast(getGarrison(s1)), *S2 = const_cast(getGarrison(s2)); - if ((S1->slots[p1].first != S2->slots[p2].first) && (true /*we are allowed to*/)) + if ((s1->tempOwner!= player || s2->tempOwner!=player)) { return -1; } - - - S2->slots[p2].second += S1->slots[p1].second; - S1->slots[p1].first = NULL; - S1->slots[p1].second = 0; - - S1->slots.erase(p1); - - if(s1->tempOwnerplayerint[s1->tempOwner]->garrisonChanged(s1); - - if((s2->tempOwnerplayerint[s2->tempOwner]->garrisonChanged(s2); + *cl->serv << ui16(502) << ui8(2) << s1->id << ui8(p1) << s2->id << ui8(p2); return 0; } int CCallback::splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val) { - if(!val) - return -1; - CCreatureSet *S1 = const_cast(getGarrison(s1)), *S2 = const_cast(getGarrison(s2)); - if ((S1->slots[p1].secondtempOwner!= player || s2->tempOwner!=player || (!val)) { return -1; } - - S2->slots[p2].first = S1->slots[p1].first; - S2->slots[p2].second = val; - S1->slots[p1].second -= val; - if(!S1->slots[p1].second) //if we've moved all creatures - S1->slots.erase(p1); - - - if(s1->tempOwnerplayerint[s1->tempOwner]->garrisonChanged(s1); - } - if((s2->tempOwnerplayerint[s2->tempOwner]->garrisonChanged(s2); - } + *cl->serv << ui16(502) << ui8(3) << s1->id << ui8(p1) << s2->id << ui8(p2) << si32(val); return 0; } diff --git a/CGameState.cpp b/CGameState.cpp index 22b2d2e41..882eeff47 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -141,6 +141,13 @@ void CGameState::apply(IPack * pack) players[h->getOwner()].fogOfWarMap[t.x][t.y][t.z] = 1; break; } + case 502: + { + SetGarrisons * n = static_cast(pack); + for(std::map::iterator i = n->garrs.begin(); i!=n->garrs.end(); i++) + static_cast(map->objects[i->first])->army = i->second; + break; + } case 1001://set object property { SetObjectProperty *p = static_cast(pack); @@ -568,7 +575,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed) } continue; } - vhi->army.slots[x-pom2].first = &(VLC->creh->creatures[pom]); + vhi->army.slots[x-pom2].first = pom; if((pom = (vhi->type->highStack[x]-vhi->type->lowStack[x])) > 0) vhi->army.slots[x-pom2].second = (ran()%pom)+vhi->type->lowStack[x]; else @@ -674,7 +681,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C curB->side2=(hero2)?(hero2->tempOwner):(-1); curB->round = -2; curB->stackActionPerformed = false; - for(std::map >::iterator i = army1->slots.begin(); i!=army1->slots.end(); i++) + for(std::map >::iterator i = army1->slots.begin(); i!=army1->slots.end(); i++) { stacks.push_back(new CStack(i->second.first,i->second.second,0, stacks.size(), true)); stacks[stacks.size()-1]->ID = stacks.size()-1; @@ -729,7 +736,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C default: //fault break; } - for(std::map >::iterator i = army2->slots.begin(); i!=army2->slots.end(); i++) + for(std::map >::iterator i = army2->slots.begin(); i!=army2->slots.end(); i++) stacks.push_back(new CStack(i->second.first,i->second.second,1, stacks.size(), false)); switch(army2->slots.size()) //for defender { diff --git a/CLua.cpp b/CLua.cpp index f7800a593..85a006661 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -720,7 +720,7 @@ void CMonsterS::onHeroVisit(int objid, int heroID) DEFOS; CCreatureSet set; //TODO: zrobic secik w sposob wyrafinowany - set.slots[0] = std::pair(&VLC->creh->creatures[os->subID],((CCreatureObjInfo*)os->info)->number); + set.slots[0] = std::pair(os->subID,((CCreatureObjInfo*)os->info)->number); cb->startBattle(heroID,&set,os->pos); } std::vector CMonsterS::yourObjects() //returns IDs of objects which are handled by script diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 8ca30f9a3..cdb9652f2 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -342,11 +342,11 @@ void CGarrisonInt::createSlots() { sup = new std::vector(7,(CGarrisonSlot *)(NULL)); for - (std::map >::const_iterator i=set1->slots.begin(); + (std::map >::const_iterator i=set1->slots.begin(); i!=set1->slots.end(); i++) { (*sup)[i->first] = - new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y,i->first, 0, i->second.first,i->second.second); + new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y,i->first, 0, &CGI->creh->creatures[i->second.first],i->second.second); } for(int i=0; isize(); i++) if((*sup)[i] == NULL) @@ -356,11 +356,11 @@ void CGarrisonInt::createSlots() { sdown = new std::vector(7,(CGarrisonSlot *)(NULL)); for - (std::map >::const_iterator i=set2->slots.begin(); + (std::map >::const_iterator i=set2->slots.begin(); i!=set2->slots.end(); i++) { (*sdown)[i->first] = - new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y + 64 + intery,i->first,1, i->second.first,i->second.second); + new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y + 64 + intery,i->first,1, &CGI->creh->creatures[i->second.first],i->second.second); } for(int i=0; isize(); i++) if((*sdown)[i] == NULL) diff --git a/client/Client.cpp b/client/Client.cpp index 769c7daff..88bbc236d 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -114,7 +114,10 @@ CClient::CClient(CConnection *con, StartInfo *si) std::cout << "\tOur checksum for the map: "<< mapa->checksum << std::endl; if(mapa->checksum != sum) + { + throw std::exception("Wrong checksum"); exit(-1); + } std::cout << "\tUsing random seed: "<state; @@ -223,6 +226,15 @@ void CClient::process(int what) mess.cv->notify_all(); break; } + case 502: + { + SetGarrisons sg; + *serv >> sg; + gs->apply(&sg); + for(std::map::iterator i = sg.garrs.begin(); i!=sg.garrs.end(); i++) + playerint[gs->map->objects[i->first]->tempOwner]->garrisonChanged(gs->map->objects[i->first]); + break; + } case 1001: { SetObjectProperty sop; diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 35609d1f1..e8e5c7875 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -35,9 +35,9 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh) SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); printAt(curh->name,75,15,GEOR13,zwykly,ret); drawPrimarySkill(curh, ret); - for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) + for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) { - blitAt(graphics->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); + blitAt(graphics->smallImgs[(*i).second.first],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); itoa((*i).second.second,buf,10); printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret); } @@ -64,11 +64,11 @@ SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh) blitAt(halls->ourImages[pom].bitmap,77,42,ret); itoa(curh->dailyIncome(),buf,10); printAtMiddle(buf,167,70,GEORM,zwykly,ret); - for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) + for (std::map >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++) { if(!i->second.first) continue; - blitAt(graphics->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); + blitAt(graphics->smallImgs[(*i).second.first],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); itoa((*i).second.second,buf,10); printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret); } diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index de8d21572..114c4b714 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -171,7 +171,7 @@ /> @@ -220,8 +224,10 @@ AdditionalDependencies="SDL.lib zdll.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib lua5.1.lib VCMI_lib.lib" AdditionalLibraryDirectories="G:\vcmt\repa\libs" GenerateDebugInformation="true" + Driver="0" OptimizeReferences="2" EnableCOMDATFolding="2" + LinkTimeCodeGeneration="0" TargetMachine="1" /> speedspeed; + if(VLC->creh->creatures[army.slots[h].first].speedcreh->creatures[army.slots[h].first].speed; } return sl; } diff --git a/int3.h b/int3.h index 31469933b..c6fd05b66 100644 --- a/int3.h +++ b/int3.h @@ -5,8 +5,12 @@ class CCreature; class CCreatureSet //seven combined creatures { public: - std::map > slots; - bool formation; //false - wide, true - tight + std::map > slots; //slots[slot_id]=> pair(creature_id,creature_quantity) + bool formation; //false - wide, true - tight + template void serialize(Handler &h, const int version) + { + h & slots & formation; + } }; class int3 diff --git a/lib/Connection.h b/lib/Connection.h index 6f7cd88ad..67a7fa14d 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -262,6 +262,25 @@ public: { *this >> data.first >> data.second; } + template + void saveSerializable(const std::map &data) + { + *this << ui32(data.size()); + for(std::map::const_iterator i=data.begin();i!=data.end();i++) + *this << i->first << i->second; + } + template + void loadSerializable(std::map &data) + { + ui32 length; + *this >> length; + T1 t; + for(int i=0;i> t; + *this >> data[t]; + } + } template void save(const T &data) { diff --git a/lib/NetPacks.h b/lib/NetPacks.h index ed08054fa..21a0a0d34 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -85,6 +85,16 @@ struct TryMoveHero : public CPack //501 h & id & result & start & end & movePoints & fowRevealed; } }; +struct SetGarrisons : public CPack //502 +{ + SetGarrisons(){type = 502;}; + std::map garrs; + + template void serialize(Handler &h, const int version) + { + h & garrs; + } +}; struct MetaString : public CPack //2001 helper for object scrips { std::vector strings; diff --git a/lib/VCMI_lib.vcproj b/lib/VCMI_lib.vcproj index 09f44210c..d9df4651c 100644 --- a/lib/VCMI_lib.vcproj +++ b/lib/VCMI_lib.vcproj @@ -169,11 +169,11 @@ /> - - - - - - - - - - - - - - - - - - - ins; + std::pair ins; for(int ir=0;ir32768) rettt = 65536-rettt+VLC->creh->creatures.size()-16; - ins.first = &(VLC->creh->creatures[rettt]); + ins.first = rettt; ins.second = readNormalNr(bufor,i+ir*4+2, 2); - std::pair > tt(ir,ins); + std::pair > tt(ir,ins); ret.slots.insert(tt); } i+=number*4; @@ -188,16 +188,16 @@ CCreatureSet readCreatureSet(unsigned char * bufor, int &i, int number, bool ver else { CCreatureSet ret; - std::pair ins; + std::pair ins; for(int ir=0;ir220) rettt = 256-rettt+VLC->creh->creatures.size()-16; - ins.first = &(VLC->creh->creatures[rettt]); + ins.first = rettt; ins.second = readNormalNr(bufor,i+ir*3+1, 2); - std::pair > tt(ir,ins); + std::pair > tt(ir,ins); ret.slots.insert(tt); } i+=number*3; @@ -455,7 +455,7 @@ void Mapa::initFromBytes(unsigned char * bufor) for (int ii=0;ii players, CConnection &c) sendAndApply(&tmh); break; } + case 502: //swap creatures in garrison + { + ui8 what, p1, p2; si32 id1, id2; + c >> what >> id1 >> p1 >> id2 >> p2; + CArmedInstance *s1 = static_cast(gs->map->objects[id1]), + *s2 = static_cast(gs->map->objects[id2]); + CCreatureSet *S1 = &s1->army, *S2 = &s2->army; + + if(what==1) //swap + { + int pom = S2->slots[p2].first; + S2->slots[p2].first = S1->slots[p1].first; + S1->slots[p1].first = pom; + int pom2 = S2->slots[p2].second; + S2->slots[p2].second = S1->slots[p1].second; + S1->slots[p1].second = pom2; + + if(!S1->slots[p1].first) + S1->slots.erase(p1); + if(!S2->slots[p2].first) + S2->slots.erase(p2); + } + else if(what==2)//merge + { + if(S1->slots[p1].first != S2->slots[p2].first) break; //not same creature + S2->slots[p2].second += S1->slots[p1].second; + S1->slots[p1].first = NULL; + S1->slots[p1].second = 0; + S1->slots.erase(p1); + } + else if(what==3) //split + { + si32 val; + c >> val; + if(S2->slots.find(p2) != S2->slots.end()) break; //slot not free + S2->slots[p2].first = S1->slots[p1].first; + S2->slots[p2].second = val; + S1->slots[p1].second -= val; + if(!S1->slots[p1].second) //if we've moved all creatures + S1->slots.erase(p1); + } + SetGarrisons sg; + sg.garrs[id1] = *S1; + if(s1 != s2) + sg.garrs[id2] = *S2; + sendAndApply(&sg); + break; + } default: throw std::exception("Not supported client message!"); break; @@ -241,11 +290,11 @@ void CGameHandler::init(StartInfo *si, int Seed) } int lowestSpeed(CGHeroInstance * chi) { - std::map >::iterator i = chi->army.slots.begin(); - int ret = (*i++).second.first->speed; + std::map >::iterator i = chi->army.slots.begin(); + int ret = VLC->creh->creatures[(*i++).second.first].speed; for (;i!=chi->army.slots.end();i++) { - ret = min(ret,(*i).second.first->speed); + ret = min(ret,VLC->creh->creatures[(*i).second.first].speed); } return ret; } diff --git a/server/VCMI_server.vcproj b/server/VCMI_server.vcproj index 8c2ceb0e8..34dd0ad1d 100644 --- a/server/VCMI_server.vcproj +++ b/server/VCMI_server.vcproj @@ -162,6 +162,83 @@ Name="VCPostBuildEventTool" /> + + + + + + + + + + + + + + + + + + + From e5a064f36b7694dec1123b254d2373e41bec224a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Fri, 1 Aug 2008 11:21:15 +0000 Subject: [PATCH 35/47] Improved threa-safety, almost finished building structures in towns. --- CCallback.cpp | 40 +++++++++------------------ CCallback.h | 4 +-- CCastleInterface.cpp | 2 +- CGameState.cpp | 22 +++++++++++++++ CGameState.h | 6 ++-- CMT.cpp | 8 +----- CPlayerInterface.cpp | 12 ++++++++ CPlayerInterface.h | 7 +++++ client/Client.cpp | 27 ++++++++++++++++++ hch/CBuildingHandler.cpp | 1 + hch/CBuildingHandler.h | 3 +- hch/CCreatureHandler.cpp | 4 +-- hch/CCreatureHandler.h | 2 +- hch/CObjectHandler.h | 9 ++++-- lib/NetPacks.h | 34 +++++++++++++++++++++++ lib/VCMI_Lib.cpp | 5 ++++ lib/VCMI_Lib.h | 4 +-- map.cpp | 6 ++-- server/CGameHandler.cpp | 56 ++++++++++++++++++++++++++++++++++++++ server/CScriptCallback.cpp | 2 +- 20 files changed, 202 insertions(+), 52 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index 650eb4b19..bddd033b7 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -112,7 +112,7 @@ void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount //verify bool found = false; typedef std::pair Parka; - for(std::map::iterator av=t->strInfo.creatures.begin();av!=t->strInfo.creatures.end();av++) + for(std::map::iterator av=t->strInfo.creatures.begin();av!=t->strInfo.creatures.end();av++) { 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 @@ -172,11 +172,9 @@ void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount bool CCallback::dismissCreature(const CArmedInstance *obj, int stackPos) { - if((player>=0) && obj->tempOwner != player) + if(((player>=0) && obj->tempOwner != player) || obj->army.slots.size()<2) return false; - CArmedInstance *ob = const_cast(obj); - ob->army.slots.erase(stackPos); - cl->playerint[player]->garrisonChanged(obj); + *cl->serv << ui16(503) << obj->id << ui8(stackPos); return true; } bool CCallback::upgradeCreature(const CArmedInstance *obj, int stackPos, int newID) @@ -202,7 +200,7 @@ UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos) t = static_cast(const_cast(obj)); else t = static_cast(obj)->visitedTown; - for(std::set::iterator i=t->builtBuildings.begin(); i!=t->builtBuildings.end(); i++) + for(std::set::iterator i=t->builtBuildings.begin(); i!=t->builtBuildings.end(); i++) { if( (*i) >= 37 && (*i) < 44 ) //upgraded creature dwelling { @@ -283,7 +281,7 @@ int CCallback::getResourceAmount(int type) { return gs->players[player].resources[type]; } -std::vector CCallback::getResourceAmount() +std::vector CCallback::getResourceAmount() { return gs->players[player].resources; } @@ -472,31 +470,19 @@ bool CCallback::swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, return true; } -bool CCallback::buildBuilding(const CGTownInstance *town, int buildingID) +bool CCallback::buildBuilding(const CGTownInstance *town, si32 buildingID) { CGTownInstance * t = const_cast(town); - CBuilding *b = CGI->buildh->buildings[t->subID][buildingID]; - if(0/*not allowed*/)//TODO: check if we are allowed to build + if(town->tempOwner!=player) return false; - - if(buildingID>36) //upg dwelling - { - if(t->getHordeLevel(0) == (buildingID-37)) - t->builtBuildings.insert(19); - else if(t->getHordeLevel(1) == (buildingID-37)) - t->builtBuildings.insert(25); - } - else if(buildingID >= 30) //bas. dwelling - { - t->strInfo.creatures[buildingID-30] = CGI->creh->creatures[t->town->basicCreatures[buildingID-30]].growth; - } - - t->builtBuildings.insert(buildingID); + CBuilding *b = CGI->buildh->buildings[t->subID][buildingID]; for(int i=0;i<7;i++) - gs->players[player].resources[i]-=b->resources[i]; - t->builded++; - cl->playerint[player]->buildChanged(town,buildingID,1); + if(b->resources[i] > gs->players[player].resources[i]) + return false; //lack of resources + + *cl->serv << ui16(504) << town->id << buildingID; +//TODO: check if we are allowed to build return true; } diff --git a/CCallback.h b/CCallback.h index c755ccb1e..19c1df86a 100644 --- a/CCallback.h +++ b/CCallback.h @@ -107,7 +107,7 @@ public: int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val); bool dismissHero(const CGHeroInstance * hero); bool swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, const CGHeroInstance * hero2, bool worn2, int pos2); - bool buildBuilding(const CGTownInstance *town, int buildingID); + bool buildBuilding(const CGTownInstance *town, si32 buildingID); void recruitCreatures(const CGObjectInstance *obj, int ID, int amount); bool dismissCreature(const CArmedInstance *obj, int stackPos); bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1); @@ -119,7 +119,7 @@ public: std::vector< std::vector< std::vector > > & getVisibilityMap(); //returns visibility map (TODO: make it const) const CGHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID int getResourceAmount(int type); - std::vector getResourceAmount(); + std::vector getResourceAmount(); int howManyHeroes(); const CGTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true); diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index f404293fc..aba56f1d0 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -533,7 +533,7 @@ void CCastleInterface::recreateBuildings() std::set< std::pair > s; //group - id - for (std::set::const_iterator i=town->builtBuildings.begin();i!=town->builtBuildings.end();i++) + for (std::set::const_iterator i=town->builtBuildings.begin();i!=town->builtBuildings.end();i++) { if(CGI->townh->structures.find(town->subID) != CGI->townh->structures.end()) //we have info about structures in this town { diff --git a/CGameState.cpp b/CGameState.cpp index 882eeff47..6f269d7be 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -128,6 +128,13 @@ void CGameState::apply(IPack * pack) players[sr->player].resources[sr->resid] = sr->val; break; } + case 104: + { + SetResources *sr = static_cast(pack); + for(int i=0;sr->res.size();i++) + players[sr->player].resources[i] = sr->res[i]; + break; + } case 501://hero try-move { TryMoveHero * n = static_cast(pack); @@ -148,6 +155,21 @@ void CGameState::apply(IPack * pack) static_cast(map->objects[i->first])->army = i->second; break; } + case 503: + { + SetStrInfo *ssi = static_cast(pack); + static_cast(map->objects[ssi->tid])->strInfo.creatures = ssi->cres; + break; + } + case 504: + { + NewStructures *ns = static_cast(pack); + CGTownInstance*t = static_cast(map->objects[ns->tid]); + BOOST_FOREACH(si32 bid,ns->bid) + t->builtBuildings.insert(bid); + t->builded = ns->builded; + break; + } case 1001://set object property { SetObjectProperty *p = static_cast(pack); diff --git a/CGameState.h b/CGameState.h index 0d01d6db2..73ccd8c32 100644 --- a/CGameState.h +++ b/CGameState.h @@ -33,9 +33,9 @@ namespace boost struct DLL_EXPORT PlayerState { public: - int color, serial; - std::vector > > fogOfWarMap; //true - visible, false - hidden - std::vector resources; + ui8 color, serial; + std::vector > > fogOfWarMap; //true - visible, false - hidden + std::vector resources; std::vector heroes; std::vector towns; PlayerState():color(-1){}; diff --git a/CMT.cpp b/CMT.cpp index 9c637e9fa..a59361428 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -31,7 +31,6 @@ #include "hch/CHeroHandler.h" #include "hch/CCreatureHandler.h" #include "hch/CSpellHandler.h" -#include "hch/CBuildingHandler.h" #include "hch/CMusicHandler.h" #include "hch/CLodHandler.h" #include "hch/CDefHandler.h" @@ -106,6 +105,7 @@ int _tmain(int argc, _TCHAR* argv[]) CGI->heroh = VLC->heroh; CGI->objh = VLC->objh; CGI->dobjinfo = VLC->dobjinfo; + CGI->buildh = VLC->buildh; THC std::cout<<"Initializing VCMI_Lib: "<spellh = spellh; THC std::cout<<"\tSpell handler: "<loadBuildings(); - cgi->buildh = buildh; - THC std::cout<<"\tBuilding handler: "<pathf = new CPathfinder(); THC std::cout<<"\tPathfinder: "<screenh->updateScreen(); + + pim->lock(); + int tv = th.getDif(); for (int i=0;ishow(); + pim->unlock(); //SDL_Flip(screen); CSDL_Ext::update(screen); SDL_Delay(5); //give time for other apps @@ -1137,6 +1146,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) //initializing objects and performing first step of move CGHeroInstance * ho = details.ho; //object representing this hero int3 hp = details.src; + boost::unique_lock un(*pim); if (!details.successful) { ho->moveDir = getDir(details.src,details.dst); @@ -1878,6 +1888,7 @@ void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownIn } void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj) { + boost::unique_lock un(*pim); if(obj->ID == 34) //hero { const CGHeroInstance * hh; @@ -1922,6 +1933,7 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, return; if(castleInt->town!=town) return; + boost::unique_lock un(*pim); switch(what) { case 1: diff --git a/CPlayerInterface.h b/CPlayerInterface.h index b529faeaf..9ec210c0b 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -25,6 +25,11 @@ class CCreatureSet; class CGObjectInstance; class CSlider; +namespace boost +{ + class mutex; +}; + class IShowable { public: @@ -292,6 +297,7 @@ class CPlayerInterface : public CGameInterface { public: //minor interfaces + boost::mutex *pim; bool makingTurn; SDL_Event * current; IActivable *curint; @@ -356,6 +362,7 @@ public: void showInfoDialog(std::string text, std::vector & components); CPlayerInterface(int Player, int serial);//c-tor + ~CPlayerInterface();//d-tor }; class CStatusBar : public CIntObject, public IStatusBar diff --git a/client/Client.cpp b/client/Client.cpp index 88bbc236d..b2642cd2e 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -11,6 +11,7 @@ #include "../lib/NetPacks.h" #include #include +#include #include "../hch/CObjectHandler.h" #include "../hch/CGeneralTextHandler.h" #include "../hch/CArtHandler.h" @@ -190,6 +191,15 @@ void CClient::process(int what) playerint[iw.player]->showInfoDialog(toString(iw.text),comps); break; } + case 104: + { + SetResources sr; + *serv >> sr; + std::cout << "Set amount of resources of player "<<(unsigned)sr.player<apply(&sr); + playerint[sr.player]->receivedResource(-1,-1); + break; + } case 501: //hero movement response - we have to notify interfaces and callback { TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing @@ -235,6 +245,23 @@ void CClient::process(int what) playerint[gs->map->objects[i->first]->tempOwner]->garrisonChanged(gs->map->objects[i->first]); break; } + case 503: + { + SetStrInfo ssi; + *serv >> ssi; + gs->apply(&ssi); + //TODO: notify interfaces + break; + } + case 504: + { + NewStructures ns; + *serv >> ns; + gs->apply(&ns); + BOOST_FOREACH(si32 bid, ns.bid) + playerint[gs->map->objects[ns.tid]->tempOwner]->buildChanged(static_cast(gs->map->objects[ns.tid]),bid,1); + break; + } case 1001: { SetObjectProperty sop; diff --git a/hch/CBuildingHandler.cpp b/hch/CBuildingHandler.cpp index 3d74bedf4..50c020d27 100644 --- a/hch/CBuildingHandler.cpp +++ b/hch/CBuildingHandler.cpp @@ -28,6 +28,7 @@ unsigned int readNr(std::string &in, unsigned int &it) CBuilding * readBg(std::string &buf, unsigned int& it) { CBuilding * nb = new CBuilding(); + nb->resources.resize(RESOURCE_QUANTITY); for(int res=0;res<7;res++) nb->resources[res] = readNr(buf,it); nb->refName = readTo(buf,it,'\n'); diff --git a/hch/CBuildingHandler.h b/hch/CBuildingHandler.h index e28fd9898..00941d42c 100644 --- a/hch/CBuildingHandler.h +++ b/hch/CBuildingHandler.h @@ -2,13 +2,14 @@ #define CBUILDINGHANDLER_H #include "../global.h" #include +#include //enum EbuildingType {NEUTRAL=-1, CASTLE, RAMPART, TOWER, INFERNO, NECROPOLIS, DUNGEON, STRONGHOLD, FORTRESS, CONFLUX}; class DLL_EXPORT CBuilding //a typical building encountered in every castle ;] { public: std::string name; std::string refName; //reference name, for identification - int resources[7]; + std::vector resources; std::string description; //EbuildingType type; //type of building (occures in many castles or is specific for one castle) //bool isDwelling; //true, if this building is a dwelling diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index 2a45a811a..02b418d38 100644 --- a/hch/CCreatureHandler.cpp +++ b/hch/CCreatureHandler.cpp @@ -45,13 +45,13 @@ bool CCreature::isFlying() { return boost::algorithm::find_first(abilityRefs, "FLYING_ARMY"); } -int CCreature::maxAmount(const std::vector &res) const //how many creatures can be bought +si32 CCreature::maxAmount(const std::vector &res) const //how many creatures can be bought { int ret = 2147483645; int resAmnt = std::min(res.size(),cost.size()); for(int i=0;i &res) const; //how many creatures can be bought + si32 maxAmount(const std::vector &res) const; //how many creatures can be bought static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion }; diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 3e2929587..578e5ece3 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -140,12 +140,17 @@ public: const CGHeroInstance * garrisonHero, *visitingHero; int identifier; //special identifier from h3m (only > RoE maps) int alignment; - std::set forbiddenBuildings, builtBuildings; + std::set forbiddenBuildings, builtBuildings; std::vector possibleSpells, obligatorySpells, availableSpells; struct StrInfo { - std::map creatures; //level - available amount + std::map creatures; //level - available amount + + template void serialize(Handler &h, const int version) + { + h & creatures; + } } strInfo; std::set events; diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 21a0a0d34..257d20b9d 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -71,6 +71,17 @@ struct SetResource : public CPack //102 h & player & resid & val; } }; +struct SetResources : public CPack //104 +{ + SetResources(){type = 104;}; + ui8 player; + std::vector res; //res[resid] => res amount + + template void serialize(Handler &h, const int version) + { + h & player & res; + } +}; struct TryMoveHero : public CPack //501 { TryMoveHero(){type = 501;}; @@ -95,6 +106,29 @@ struct SetGarrisons : public CPack //502 h & garrs; } }; +struct SetStrInfo : public CPack //503 +{ + SetStrInfo(){type = 503;}; + si32 tid; + std::map cres; + + template void serialize(Handler &h, const int version) + { + h & tid & cres; + } +}; +struct NewStructures : public CPack //504 +{ + NewStructures(){type = 504;}; + si32 tid; + std::set bid; + si16 builded; + + template void serialize(Handler &h, const int version) + { + h & tid & bid & builded; + } +}; struct MetaString : public CPack //2001 helper for object scrips { std::vector strings; diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index f1f7bb40e..c6e208609 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -7,6 +7,7 @@ #include "../hch/CHeroHandler.h" #include "../hch/CObjectHandler.h" #include "../hch/CTownHandler.h" +#include "../hch/CBuildingHandler.h" class CLodHandler; LibClasses * VLC = NULL; CLodHandler * bitmaph=NULL; @@ -45,6 +46,10 @@ DLL_EXPORT void initDLL(CLodHandler *b) VLC->dobjinfo = new CDefObjInfoHandler; VLC->dobjinfo->load(); THC std::cout<<"\tDef information handler: "<buildh = new CBuildingHandler; + VLC->buildh->loadBuildings(); + THC std::cout<<"\tBuilding handler: "< #include -std::set convertBuildings(const std::set h3m, int castleID) +std::set convertBuildings(const std::set h3m, int castleID) { std::map mapa; - std::set ret; + std::set ret; std::ifstream b5("config/buildings5.txt"); while(!b5.eof()) { @@ -20,7 +20,7 @@ std::set convertBuildings(const std::set h3m, int castleID) mapa[a]=b; } - for(std::set::const_iterator i=h3m.begin();i!=h3m.end();i++) + for(std::set::const_iterator i=h3m.begin();i!=h3m.end();i++) { if(mapa[*i]>=0) ret.insert(mapa[*i]); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 506068df9..b2c132669 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -13,6 +13,7 @@ #include "../CLua.h" #include "../hch/CObjectHandler.h" #include "../hch/CTownHandler.h" +#include "../hch/CBuildingHandler.h" #include "../hch/CHeroHandler.h" #include "boost/date_time/posix_time/posix_time_types.hpp" //no i/o just types #include "../lib/VCMI_Lib.h" @@ -223,6 +224,61 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) if(s1 != s2) sg.garrs[id2] = *S2; sendAndApply(&sg); + break; + } + case 503: + { + si32 id; + ui8 pos; + c >> id >> pos; + CArmedInstance *s1 = static_cast(gs->map->objects[id]); + s1->army.slots.erase(pos); + SetGarrisons sg; + sg.garrs[id] = s1->army; + sendAndApply(&sg); + break; + } + case 504: + { + si32 tid, bid; + c >> tid >> bid; + CGTownInstance * t = static_cast(gs->map->objects[tid]); + CBuilding * b = VLC->buildh->buildings[t->subID][bid]; + for(int i=0;iresources[i] > gs->players[t->tempOwner].resources[i]) + break; //no res + //TODO: check requirements + //TODO: check if building isn't forbidden + + NewStructures ns; + ns.tid = tid; + if(bid>36) //upg dwelling + { + if(t->getHordeLevel(0) == (bid-37)) + ns.bid.insert(19); + else if(t->getHordeLevel(1) == (bid-37)) + ns.bid.insert(25); + } + else if(bid >= 30) //bas. dwelling + { + SetStrInfo ssi; + ssi.tid = tid; + ssi.cres = t->strInfo.creatures; + ssi.cres[bid-30] = VLC->creh->creatures[t->town->basicCreatures[bid-30]].growth; + sendAndApply(&ssi); + } + + ns.bid.insert(bid); + ns.builded = t->builded + 1; + sendAndApply(&ns); + + SetResources sr; + sr.player = t->tempOwner; + sr.res = gs->players[t->tempOwner].resources; + for(int i=0;i<7;i++) + sr.res[i]-=b->resources[i]; + sendAndApply(&sr); + break; } default: diff --git a/server/CScriptCallback.cpp b/server/CScriptCallback.cpp index 69581f6fd..483c5ff5c 100644 --- a/server/CScriptCallback.cpp +++ b/server/CScriptCallback.cpp @@ -121,7 +121,7 @@ int CScriptCallback::getSelectedHero() // ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->subID; //else // ret = -1;; - return ret; + return -1; } int CScriptCallback::getDate(int mode) { From bfad10a8e4696239ac609190dc1db2b902916ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Fri, 1 Aug 2008 18:13:33 +0000 Subject: [PATCH 36/47] * added fast graphical cursor :) * building structures should work --- CCastleInterface.cpp | 8 +- CCursorHandler.cpp | 244 +++++--------------------------------- CCursorHandler.h | 18 ++- CGameState.cpp | 2 +- CMT.cpp | 9 +- CPlayerInterface.cpp | 13 +- CPreGame.cpp | Bin 129830 -> 129838 bytes CScreenHandler.cpp | 45 ------- CScreenHandler.h | 17 --- client/VCMI_client.vcproj | 8 -- server/CGameHandler.cpp | 2 +- 11 files changed, 54 insertions(+), 312 deletions(-) delete mode 100644 CScreenHandler.cpp delete mode 100644 CScreenHandler.h diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index aba56f1d0..ce46f7cab 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -510,7 +510,9 @@ void CCastleInterface::deactivate() void CCastleInterface::addBuilding(int bid) { //TODO: lepiej by bylo tylko dodawac co trzeba pamietajac o grupach + deactivate(); recreateBuildings(); + activate(); } void CCastleInterface::removeBuilding(int bid) @@ -916,12 +918,12 @@ void CHallInterface::CBuildWindow::deactivate() } void CHallInterface::CBuildWindow::Buy() { - LOCPLINT->cb->buildBuilding(LOCPLINT->castleInt->town,bid); deactivate(); - delete this; - delete LOCPLINT->castleInt->hallInt; LOCPLINT->castleInt->hallInt = NULL; LOCPLINT->castleInt->activate(); + LOCPLINT->cb->buildBuilding(LOCPLINT->castleInt->town,bid); + delete this; + delete LOCPLINT->castleInt->hallInt; LOCPLINT->castleInt->showAll(); } void CHallInterface::CBuildWindow::close() diff --git a/CCursorHandler.cpp b/CCursorHandler.cpp index 53a39708b..af3476d5b 100644 --- a/CCursorHandler.cpp +++ b/CCursorHandler.cpp @@ -1,237 +1,51 @@ #include "stdafx.h" #include "CCursorHandler.h" #include "SDL.h" -#include "SDL_thread.h" +#include "SDL_Extensions.h" #include "CGameInfo.h" -#include "SDL_framerate.h" -#include "hch/CLodHandler.h" +#include "hch/CDefHandler.h" extern SDL_Surface * screen; -/* Creates a new mouse cursor from an XPM */ - - -/* XPM */ -static const char *arrow[] = { //no cursor mode - /* width height num_colors chars_per_pixel */ - " 32 32 3 1", - /* colors */ - "X c #000000", - ". c #ffffff", - " c None", - /* pixels */ - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - "0,0" -}; - -/* XPM */ -static const char *arrow2[] = { //normal cursor - /* width height num_colors chars_per_pixel */ - " 32 32 3 1", - /* colors */ - "X c #000000", - ". c #ffffff", - " c None", - /* pixels */ - "X ", - "XX ", - "X.X ", - "X..X ", - "X...X ", - "X....X ", - "X.....X ", - "X......X ", - "X.......X ", - "X........X ", - "X.....XXXXX ", - "X..X..X ", - "X.X X..X ", - "XX X..X ", - "X X..X ", - " X..X ", - " X..X ", - " X..X ", - " XX ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - "0,0" -}; - -static SDL_Cursor *init_system_cursor(const char *image[]) -{ - int i, row, col; - Uint8 data[4*32]; - Uint8 mask[4*32]; - int hot_x, hot_y; - - i = -1; - for ( row=0; row<32; ++row ) { - for ( col=0; col<32; ++col ) { - if ( col % 8 ) { - data[i] <<= 1; - mask[i] <<= 1; - } else { - ++i; - data[i] = mask[i] = 0; - } - switch (image[4+row][col]) { - case 'X': - data[i] |= 0x01; - //k[i] |= 0x01; - break; - case '.': - mask[i] |= 0x01; - break; - case ' ': - break; - } - } - } - sscanf(image[4+row], "%d,%d", &hot_x, &hot_y); - return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y); -} - -//int cursorHandlerFunc(void * cursorHandler) -//{ -// FPSmanager * cursorFramerateKeeper = new FPSmanager; -// SDL_initFramerate(cursorFramerateKeeper); -// SDL_setFramerate(cursorFramerateKeeper, 200); -// -// CCursorHandler * ch = (CCursorHandler *) cursorHandler; -// while(true) -// { -// if(ch->xbef!=-1 && ch->ybef!=-1) //restore surface under cursor -// { -// blitAtWR(ch->behindCur, ch->xbef, ch->ybef); -// } -// ch->xbef = ch->xpos; -// ch->ybef = ch->ypos; -// //prepare part of surface to restore -// SDL_BlitSurface(screen, &genRect(32, 32, ch->xpos, ch->ypos), ch->behindCur, NULL); -// CSDL_Ext::update(ch->behindCur); -// -// //blit cursor -// if(ch->curVisible) -// { -// switch(ch->mode) -// { -// case 0: -// { -// break; -// } -// case 1: -// { -// break; -// } -// case 2: -// { -// blitAtWR(ch->deflt->ourImages[ch->number].bitmap, ch->xpos, ch->ypos); -// break; -// } -// } -// } -// SDL_framerateDelay(cursorFramerateKeeper); -// //SDL_Delay(5); //to avoid great usage of CPU -// } -// return 0; -//} - void CCursorHandler::initCursor() { -//#if SDL_BYTEORDER == SDL_BIG_ENDIAN -// int rmask = 0xff000000; -// int gmask = 0x00ff0000; -// int bmask = 0x0000ff00; -// int amask = 0x000000ff; -//#else -// int rmask = 0x000000ff; -// int gmask = 0x0000ff00; -// int bmask = 0x00ff0000; -// int amask = 0xff000000; -//#endif -// curVisible = true; -// xpos = ypos = 0; -// behindCur = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, rmask, gmask, bmask, amask); -// xbef = ybef = 0; -// adventure = CDefHandler::giveDef("CRADVNTR.DEF"); -// combat = CDefHandler::giveDef("CRCOMBAT.DEF"); -// deflt = CDefHandler::giveDef("CRDEFLT.DEF"); -// spell = CDefHandler::giveDef("CRSPELL.DEF"); -// //SDL_SetCursor(init_system_cursor(arrow)); -// //SDL_Thread * myth = SDL_CreateThread(&cursorHandlerFunc, this); +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + int rmask = 0xff000000; + int gmask = 0x00ff0000; + int bmask = 0x0000ff00; + int amask = 0x000000ff; +#else + int rmask = 0x000000ff; + int gmask = 0x0000ff00; + int bmask = 0x00ff0000; + int amask = 0xff000000; +#endif + mode = number = xpos = ypos = 0; + help = CSDL_Ext::newSurface(32,32); + cursors.push_back(CDefHandler::giveDef("CRADVNTR.DEF")); + cursors.push_back(CDefHandler::giveDef("CRCOMBAT.DEF")); + cursors.push_back(CDefHandler::giveDef("CRDEFLT.DEF")); + cursors.push_back(CDefHandler::giveDef("CRSPELL.DEF")); + SDL_ShowCursor(SDL_DISABLE); } void CCursorHandler::changeGraphic(int type, int no) { - //mode = type; - //number = no; + mode = type; + number = no; } void CCursorHandler::cursorMove(int x, int y) { - //xbef = xpos; - //ybef = ypos; - //xpos = x; - //ypos = y; + xpos = x; + ypos = y; } - -void CCursorHandler::hardwareCursor() +void CCursorHandler::draw1() { - //curVisible = false; - //SDL_SetCursor(init_system_cursor(arrow2)); + SDL_BlitSurface(screen,&genRect(32,32,xpos,ypos),help,&genRect(32,32,0,0)); + blitAt(cursors[mode]->ourImages[number].bitmap,xpos,ypos); } - -void CCursorHandler::hideCursor() +void CCursorHandler::draw2() { - //curVisible = false; - //SDL_SetCursor(init_system_cursor(arrow)); -} - -void CCursorHandler::showGraphicCursor() -{ - //curVisible = true; - //SDL_SetCursor(init_system_cursor(arrow)); - //changeGraphic(0, 0); + blitAt(help,xpos,ypos); } \ No newline at end of file diff --git a/CCursorHandler.h b/CCursorHandler.h index 7373cfa65..80d9b7126 100644 --- a/CCursorHandler.h +++ b/CCursorHandler.h @@ -1,6 +1,7 @@ #ifndef CCURSORHANDLER_H #define CCURSORHANDLER_H - +#include "global.h" +#include struct SDL_Thread; class CDefHandler; struct SDL_Surface; @@ -8,21 +9,16 @@ struct SDL_Surface; class CCursorHandler //handles cursor { public: - SDL_Thread * myThread; //thread that updates cursor - bool curVisible; //true if cursor is visible int mode, number; - SDL_Surface * behindCur; - int xbef, ybef; //position of cursor after last move (to restore background) + SDL_Surface * help; - CDefHandler * adventure, * combat, * deflt, * spell; //read - only - int xpos, ypos; //position of cursor - read only + std::vector cursors; + int xpos, ypos; //position of cursor void initCursor(); //inits cursorHandler - void showGraphicCursor(); //shows default graphic cursor void cursorMove(int x, int y); //change cursor's positions to (x, y) void changeGraphic(int type, int no); //changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame no (not used for type 3) - void hideCursor(); //no cursor will be visible - void hardwareCursor(); // returns to hardware cursor mode - friend int cursorHandlerFunc(void * cursorHandler); + void draw1(); + void draw2(); }; diff --git a/CGameState.cpp b/CGameState.cpp index 6f269d7be..efcef9ad7 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -131,7 +131,7 @@ void CGameState::apply(IPack * pack) case 104: { SetResources *sr = static_cast(pack); - for(int i=0;sr->res.size();i++) + for(int i=0;ires.size();i++) players[sr->player].resources[i] = sr->res[i]; break; } diff --git a/CMT.cpp b/CMT.cpp index a59361428..31a5f3e5f 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -89,8 +89,7 @@ int _tmain(int argc, _TCHAR* argv[]) //audio initialized cgi->consoleh = new CConsoleHandler; cgi->mush = mush; - cgi->curh = new CCursorHandler; - THC std::cout<<"\tInitializing sound and cursor: "<spriteh = new CLodHandler(); cgi->spriteh->init("Data\\H3sprite.lod","Sprites"); @@ -112,8 +111,10 @@ int _tmain(int argc, _TCHAR* argv[]) //cgi->curh->initCursor(); //cgi->curh->showGraphicCursor(); pomtime.getDif(); - cgi->screenh = new CScreenHandler; - cgi->screenh->initScreen(); + cgi->curh = new CCursorHandler; + cgi->curh->initCursor(); + //cgi->screenh = new CScreenHandler; + //cgi->screenh->initScreen(); THC std::cout<<"\tScreen handler: "<screenh->updateScreen(); + //CGI->screenh->updateScreen(); pim->lock(); @@ -1016,7 +1016,7 @@ void CPlayerInterface::yourTurn() if (!castleInt) //stuff for advMapInt { ++LOCPLINT->adventureInt->animValHitCount; //for animations - if(LOCPLINT->adventureInt->animValHitCount == 4) + if(LOCPLINT->adventureInt->animValHitCount == 8) { LOCPLINT->adventureInt->animValHitCount = 0; ++animVal; @@ -1074,9 +1074,9 @@ void CPlayerInterface::yourTurn() for(int i=0;ishow(); pim->unlock(); - //SDL_Flip(screen); + CGI->curh->draw1(); CSDL_Ext::update(screen); - SDL_Delay(5); //give time for other apps + CGI->curh->draw2(); SDL_framerateDelay(mainFPSmng); } adventureInt->hide(); @@ -1146,7 +1146,6 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) //initializing objects and performing first step of move CGHeroInstance * ho = details.ho; //object representing this hero int3 hp = details.src; - boost::unique_lock un(*pim); if (!details.successful) { ho->moveDir = getDir(details.src,details.dst); @@ -1486,7 +1485,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } LOCPLINT->adventureInt->update(); //updating screen CSDL_Ext::update(screen); - CGI->screenh->updateScreen(); + //CGI->screenh->updateScreen(); ++LOCPLINT->adventureInt->animValHitCount; //for animations if(LOCPLINT->adventureInt->animValHitCount == 4) diff --git a/CPreGame.cpp b/CPreGame.cpp index da782cdd47c096a453ca6cf786b56ba64d3578fe..3ace59cc3286ed815ac5459817c7693ef4066e3a 100644 GIT binary patch delta 133 zcmZ4XjeXrW_6>E+6Z5#54>4~)#LO7BX?xT*#uzhIP6kc}X9jl$PX=8EJBDP2QidXi z3@|$d$Vy}=XE0>Yn7nYE=;T?el@#%-G=iw)cVS3n$N}oDWYAzRVldc#`3++*9{{-a BA{77t delta 109 zcmZ4YjeXfS_6>E+yv_{449N^d45>hv*Br>aJ&>8Pcaxcurh->mode) - { - case 0: - { - blitAt(CGI->curh->adventure->ourImages[CGI->curh->number].bitmap, CGI->curh->xpos, CGI->curh->ypos, screen2); - break; - } - case 1: - { - blitAt(CGI->curh->combat->ourImages[CGI->curh->number].bitmap, CGI->curh->xpos, CGI->curh->ypos, screen2); - break; - } - case 2: - { - blitAt(CGI->curh->deflt->ourImages[CGI->curh->number].bitmap, CGI->curh->xpos, CGI->curh->ypos, screen2); - break; - } - case 3: - { - blitAt(CGI->curh->spell->ourImages[CGI->curh->number].bitmap, CGI->curh->xpos, CGI->curh->ypos, screen2); - break; - } - } - CSDL_Ext::update(screen2);*/ -} \ No newline at end of file diff --git a/CScreenHandler.h b/CScreenHandler.h deleted file mode 100644 index cb1ad1e54..000000000 --- a/CScreenHandler.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef CSCREENHANDLER_H -#define CSCREENHANDLER_H - -struct SDL_Thread; - -class CScreenHandler -{ -private: - SDL_Thread * myth; -public: - void initScreen(); - void updateScreen(); -}; - - - -#endif //CSCREENHANDLER_H \ No newline at end of file diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index 114c4b714..c1e2da63a 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -357,10 +357,6 @@ RelativePath="..\hch\CPreGameTextHandler.cpp" > - - @@ -515,10 +511,6 @@ RelativePath="..\hch\CPreGameTextHandler.h" > - - diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index b2c132669..312ba1792 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -474,7 +474,7 @@ void CGameHandler::run() newTurn(); for(std::map::iterator i = gs->players.begin(); i != gs->players.end(); i++) { - if((i->second.towns.size()==0 && i->second.heroes.size()==0) || i->second.color<0) continue; //players has not towns/castle - loser + 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 makingTurn = true; gs->currentPlayer = i->first; *connections[i->first] << ui16(100) << i->first; From 1f4b4364df5321b07a06a99b3bd07b739643fbb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Fri, 1 Aug 2008 21:41:38 +0000 Subject: [PATCH 37/47] Dismissing heroes / minor. --- CCallback.cpp | 23 +++++++++-------------- CCursorHandler.cpp | 11 ----------- CGameState.cpp | 12 ++++++++++++ CPlayerInterface.cpp | 4 +++- client/Client.cpp | 11 +++++++++++ lib/NetPacks.h | 11 +++++++++++ mapHandler.cpp | 5 +---- server/CGameHandler.cpp | 8 ++++++++ 8 files changed, 55 insertions(+), 30 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index bddd033b7..ec6b77f11 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -357,17 +357,15 @@ std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) } std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur) { - std::vector < const CGHeroInstance *> ret = std::vector < const CGHeroInstance *>(); - for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + std::vector < const CGHeroInstance *> ret; + for(int i=0;imap->heroes.size();i++) { - for (int j=0;j<(*i).second.heroes.size();j++) + if( (gs->map->heroes[i]->tempOwner==player) || + (isVisible(gs->map->heroes[i]->getPosition(false),player) && !onlyOur) ) { - if ( ( isVisible((*i).second.heroes[j]->getPosition(false),player) ) || (*i).first==player) - { - ret.push_back((*i).second.heroes[j]); - } + ret.push_back(gs->map->heroes[i]); } - } // for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + } return ret; } @@ -430,12 +428,9 @@ int CCallback::splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2 bool CCallback::dismissHero(const CGHeroInstance *hero) { - CGHeroInstance * Vhero = const_cast(hero); - CGI->mh->removeObject(Vhero); - std::vector::iterator nitr = find(CGI->state->players[player].heroes.begin(), CGI->state->players[player].heroes.end(), Vhero); - CGI->state->players[player].heroes.erase(nitr); - LOCPLINT->adventureInt->heroList.updateHList(); - return false; + if(player!=hero->tempOwner) return false; + *cl->serv << ui16(500) << hero->id; + return true; } int CCallback::getMySerial() diff --git a/CCursorHandler.cpp b/CCursorHandler.cpp index af3476d5b..5c17dc95d 100644 --- a/CCursorHandler.cpp +++ b/CCursorHandler.cpp @@ -9,17 +9,6 @@ extern SDL_Surface * screen; void CCursorHandler::initCursor() { -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - int rmask = 0xff000000; - int gmask = 0x00ff0000; - int bmask = 0x0000ff00; - int amask = 0x000000ff; -#else - int rmask = 0x000000ff; - int gmask = 0x0000ff00; - int bmask = 0x00ff0000; - int amask = 0xff000000; -#endif mode = number = xpos = ypos = 0; help = CSDL_Ext::newSurface(32,32); cursors.push_back(CDefHandler::giveDef("CRADVNTR.DEF")); diff --git a/CGameState.cpp b/CGameState.cpp index efcef9ad7..25e57b8d3 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -135,6 +135,18 @@ void CGameState::apply(IPack * pack) players[sr->player].resources[i] = sr->res[i]; break; } + case 500: + { + RemoveHero *rh = static_cast(pack); + CGHeroInstance *h = static_cast(map->objects[rh->id]); + std::vector::iterator nitr = std::find(map->heroes.begin(), map->heroes.end(),h); + map->heroes.erase(nitr); + int player = h->tempOwner; + nitr = std::find(players[player].heroes.begin(), players[player].heroes.end(), h); + players[player].heroes.erase(nitr); + map->objects[h->id] = NULL; + break; + } case 501://hero try-move { TryMoveHero * n = static_cast(pack); diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 6adcb350b..b5bf15f42 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -6,7 +6,6 @@ #include "mapHandler.h" #include "SDL_Extensions.h" #include "SDL_framerate.h" -#include "CScreenHandler.h" #include "CCursorHandler.h" #include "CCallback.h" #include "SDL_Extensions.h" @@ -1569,7 +1568,9 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) } void CPlayerInterface::heroKilled(const CGHeroInstance* hero) { + boost::unique_lock un(*pim); graphics->heroWins.erase(hero->ID); + adventureInt->heroList.updateHList(); } void CPlayerInterface::heroCreated(const CGHeroInstance * hero) { @@ -1850,6 +1851,7 @@ int3 CPlayerInterface::repairScreenPos(int3 pos) } void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) { + boost::unique_lock un(*pim); SDL_FreeSurface(graphics->heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia graphics->heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki. if (adventureInt->selection.selected == hero) diff --git a/client/Client.cpp b/client/Client.cpp index b2642cd2e..d68db84ec 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -200,6 +200,17 @@ void CClient::process(int what) playerint[sr.player]->receivedResource(-1,-1); break; } + case 500: + { + RemoveHero rh; + *serv >> rh; + CGHeroInstance *h = static_cast(gs->map->objects[rh.id]); + std::cout << "Removing hero with id = "<<(unsigned)rh.id<mh->removeObject(h); + gs->apply(&rh); + playerint[h->tempOwner]->heroKilled(h); + break; + } case 501: //hero movement response - we have to notify interfaces and callback { TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 257d20b9d..9b3a2c410 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -82,6 +82,17 @@ struct SetResources : public CPack //104 h & player & res; } }; +struct RemoveHero : public CPack //500 +{ + RemoveHero(){type = 500;}; + RemoveHero(si32 ID){id = ID;type = 500;}; + si32 id; + + template void serialize(Handler &h, const int version) + { + h & id; + } +}; struct TryMoveHero : public CPack //501 { TryMoveHero(){type = 501;}; diff --git a/mapHandler.cpp b/mapHandler.cpp index 03e830685..8bc13b20d 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -1158,10 +1158,7 @@ bool CMapHandler::hideObject(CGObjectInstance *obj) bool CMapHandler::removeObject(CGObjectInstance *obj) { hideObject(obj); - std::vector::iterator db = std::find(map->objects.begin(), map->objects.end(), obj); - recalculateHideVisPosUnderObj(*db); - delete *db; - map->objects.erase(db); + recalculateHideVisPosUnderObj(obj); return true; } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 312ba1792..602c5acb3 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -67,6 +67,14 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) cTurn.notify_all(); break; } + case 500: + { + si32 id; + c >> id; + RemoveHero rh(id); + sendAndApply(&rh); + break; + } case 501://interface wants to move hero { int3 start, end; From dc82232e70b6a360974ec926469389ed9c06bf86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 2 Aug 2008 10:25:58 +0000 Subject: [PATCH 38/47] Hover text for heroes. --- CLua.cpp | 14 +++++--------- CPlayerInterface.cpp | 2 +- client/Client.cpp | 4 ++++ lib/NetPacks.h | 3 ++- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CLua.cpp b/CLua.cpp index 85a006661..36937fd1e 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -634,6 +634,11 @@ std::vector CTownScript::yourObjects() //returns IDs of objects which are h void CHeroScript::newObject(int objid) { cb->setBlockVis(objid,true); + MetaString ms; + ms << std::pair(1,15); + ms.replacements.push_back(cb->getHero(objid)->name); + ms.replacements.push_back(cb->getHero(objid)->type->heroClass->name); + cb->setHoverName(objid,&ms); } void CHeroScript::onHeroVisit(int objid, int heroID) @@ -661,15 +666,6 @@ std::vector CHeroScript::yourObjects() //returns IDs of objects which are h ret.push_back(34); //hero return ret; } -//std::string CHeroScript::hoverText(int objid) -//{ -// //CGHeroInstance* h = static_cast(os); -// //std::string ret = VLC->generaltexth->allTexts[15]; -// //boost::algorithm::replace_first(ret,"%s",h->name); -// //boost::algorithm::replace_first(ret,"%s",h->type->heroClass->name); -// //return ret; -// return ""; -//} void CMonsterS::newObject(int objid) { //os->blockVisit = true; diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index b5bf15f42..7d9503dd2 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -568,7 +568,7 @@ SComponent::SComponent(const Component &c) switch(c.id) { case resource: - if(c.when==1) + if(c.when == -1) subtitle += CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2); break; } diff --git a/client/Client.cpp b/client/Client.cpp index d68db84ec..23d60ad6c 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -81,6 +81,10 @@ std::string toString(MetaString &ms) } } } + for(int i=0;i //2001 helper for object scrips std::vector strings; std::vector > texts; //pairs; types: 1 - generaltexthandler->all; 2 - objh->xtrainfo; 3 - objh->names; 4 - objh->restypes; 5 - arth->artifacts[id].name; 6 - generaltexth->arraytxt; 7 - creh->creatures[os->subID].namePl; 8 - objh->creGens; 9 - objh->mines[ID].first; 10 - objh->mines[ID].second; 11 - objh->advobtxt std::vector message; + std::vector replacements; template void serialize(Handler &h, const int version) { - h & strings & texts & message; + h & strings & texts & message & replacements; } MetaString& operator<<(const std::pair &txt) From cc7be20b07fd47a0cf64abb6f26cff9290a05992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 2 Aug 2008 15:08:03 +0000 Subject: [PATCH 39/47] Merged most of the changes from trunk. Because of really huge amount of modifications here I've probably missed some minor stuff. I doubt if it's still compatible with gcc - some changes should be reapplied. --- AI_Base.h | 11 +- AdventureMapButton.cpp | 4 +- CAdvmapInterface.cpp | 42 ++-- CAdvmapInterface.h | 28 +-- CBattleInterface.cpp | 401 +++++++++++++++++++++++++++--------- CBattleInterface.h | 26 ++- CCallback.cpp | 62 ++++-- CCallback.h | 29 ++- CCastleInterface.cpp | 76 ++++--- CCastleInterface.h | 4 +- CConsoleHandler.cpp | 6 +- CConsoleHandler.h | 8 +- CCursorHandler.cpp | 2 +- CCursorHandler.h | 2 +- CGameInfo.cpp | 2 +- CGameInfo.h | 6 +- CGameInterface.cpp | 11 +- CGameInterface.h | 32 +-- CGameState.cpp | 168 +++++++++++---- CGameState.h | 8 +- CHeroWindow.cpp | 39 ++-- CHeroWindow.h | 2 +- CLua.cpp | 79 ++++++- CLua.h | 17 +- CLuaHandler.cpp | 37 +++- CLuaHandler.h | 2 +- CMT.cpp | 85 +++----- CMessage.cpp | 62 +++--- CMessage.h | 16 +- CPathfinder.cpp | 24 +-- CPathfinder.h | 12 +- CPlayerInterface.cpp | 126 +++++------ CPlayerInterface.h | 35 ++-- CPreGame.cpp | Bin 129838 -> 64834 bytes CPreGame.h | 43 ++-- SDL_Extensions.cpp | 63 +++--- SDL_Extensions.h | 2 +- StartInfo.h | 4 + client/CBitmapHandler.cpp | 12 ++ client/Graphics.cpp | 6 +- config/cr_shots.txt | 40 ++++ config/portrety.txt | 8 + global.h | 19 +- hch/CAbilityHandler.h | 2 +- hch/CAmbarCendamo.cpp | 2 +- hch/CAmbarCendamo.h | 2 +- hch/CArtHandler.h | 2 +- hch/CBuildingHandler.cpp | 16 +- hch/CBuildingHandler.h | 2 +- hch/CCreatureHandler.cpp | 43 +++- hch/CCreatureHandler.h | 6 +- hch/CDefHandler.h | Bin 3300 -> 3272 bytes hch/CDefObjInfoHandler.h | 4 +- hch/CGeneralTextHandler.cpp | 3 +- hch/CGeneralTextHandler.h | 2 +- hch/CHeroHandler.h | 2 +- hch/CLodHandler.cpp | 4 +- hch/CLodHandler.h | 2 +- hch/CMusicHandler.cpp | 96 ++++----- hch/CMusicHandler.h | 2 +- hch/CObjectHandler.cpp | 6 +- hch/CObjectHandler.h | 8 +- hch/CPreGameTextHandler.h | 2 +- hch/CSndHandler.cpp | 16 +- hch/CSndHandler.h | 2 +- hch/CSpellHandler.h | 2 +- hch/CTownHandler.cpp | 12 +- hch/CTownHandler.h | 2 +- hch/CVideoHandler.cpp | 28 ++- hch/CVideoHandler.h | 28 ++- int3.h | 10 +- map.cpp | 60 +++--- map.h | 24 +-- mapHandler.cpp | 4 +- mapHandler.h | 4 +- nodrze.h | 53 ++--- stdafx.h | 4 + tchar_amigaos4.h | 238 +++++++++++++++++++++ timeHandler.h | 2 +- 79 files changed, 1635 insertions(+), 721 deletions(-) create mode 100644 config/cr_shots.txt create mode 100644 tchar_amigaos4.h diff --git a/AI_Base.h b/AI_Base.h index 90be85824..cf1ecd3d0 100644 --- a/AI_Base.h +++ b/AI_Base.h @@ -3,4 +3,13 @@ #include #include "CGameInterface.h" -#define AI_INTERFACE_VER 1 \ No newline at end of file +#define AI_INTERFACE_VER 1 + + + + + + + + + diff --git a/AdventureMapButton.cpp b/AdventureMapButton.cpp index da87fa196..6bda0df31 100644 --- a/AdventureMapButton.cpp +++ b/AdventureMapButton.cpp @@ -74,7 +74,7 @@ void AdventureMapButton::clickLeft (tribool down) { state=1; } - else + else { state=0; } @@ -264,4 +264,4 @@ CSlider::CSlider(int x, int y, int totalw, boost::function Moved, int slider.actOnDown = true; moveTo(value); -} \ No newline at end of file +} diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 10f6ba0b8..b498b2eda 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -36,7 +36,7 @@ CAdvMapInt::~CAdvMapInt() } CMinimap::CMinimap(bool draw) { - statusbarTxt = CGI->preth->zelp[291].first; + statusbarTxt = CGI->preth->zelp[291].first; rcText = CGI->preth->zelp[291].second; pos.x=630; pos.y=26; @@ -64,7 +64,7 @@ CMinimap::CMinimap(bool draw) SDL_PutPixel(radar,radar->w-1,i,255,75,125); } } - SDL_SetColorKey(radar,SDL_SRCCOLORKEY,SDL_MapRGB(radar->format,0,255,255)); + SDL_SetColorKey(radar,SDL_SRCCOLORKEY,SDL_MapRGB(radar->format,0,255,255)); //radar = CDefHandler::giveDef("RADAR.DEF"); std::ifstream is("config/minimap.txt",std::ifstream::in); @@ -86,7 +86,7 @@ CMinimap::CMinimap(bool draw) is >> pom; vinya2.second.g=pom; is >> pom; - vinya2.second.b=pom; + vinya2.second.b=pom; vinya.second.unused=vinya2.second.unused=255; colors.insert(vinya); colorsBlocked.insert(vinya2); @@ -121,9 +121,9 @@ void CMinimap::draw() } } //blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps); - + //draw radar - int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)CGI->mh->sizes.x)))*pos.w, + int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)CGI->mh->sizes.x)))*pos.w, by = (((float)LOCPLINT->adventureInt->position.y)/(((float)CGI->mh->sizes.y)))*pos.h; blitAt(radar,bx,by,temps); blitAt(temps,pos.x,pos.y); @@ -173,7 +173,7 @@ void CMinimap::clickLeft (tribool down) ClickableL::clickLeft(down); if (!((bool)down)) return; - + float dx=((float)(LOCPLINT->current->motion.x-pos.x))/((float)pos.w), dy=((float)(LOCPLINT->current->motion.y-pos.y))/((float)pos.h); @@ -252,7 +252,7 @@ void CTerrainRect::activate() Hoverable::activate(); KeyInterested::activate(); MotionInterested::activate(); -}; +}; void CTerrainRect::deactivate() { ClickableL::deactivate(); @@ -260,7 +260,7 @@ void CTerrainRect::deactivate() Hoverable::deactivate(); KeyInterested::deactivate(); MotionInterested::deactivate(); -}; +}; void CTerrainRect::clickLeft(tribool down) { if ((down==false) || indeterminate(down)) @@ -307,7 +307,7 @@ void CTerrainRect::clickLeft(tribool down) } const CGHeroInstance * currentHero = (LOCPLINT->adventureInt->heroList.items.size())?(LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first):(NULL); if(!currentHero) - return; + return; int3 bufpos = currentHero->getPosition(false); //bufpos.x-=1; if (mres) @@ -330,7 +330,7 @@ void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent) int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y)); if (pom!=curHoveredTile) curHoveredTile=pom; - else + else return; std::vector temp = LOCPLINT->cb->getObjDescriptions(pom); if (temp.size()) @@ -618,13 +618,13 @@ void CResDataBar::draw() char * buf = new char[15]; for (int i=0;i<7;i++) { - itoa(LOCPLINT->cb->getResourceAmount(i),buf,10); + SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10); printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly); } std::vector temp; - itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf); - itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf); - itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf); + SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf); + SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf); + SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf); printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly); temp.clear(); //updateRect(&pos,screen); @@ -671,7 +671,7 @@ void CInfoBar::draw(const CGObjectInstance * specific) draw((const CGObjectInstance *)LOCPLINT->adventureInt->selection.selected); } if (!specific) - specific = (const CGObjectInstance *)LOCPLINT->adventureInt->selection.selected; + specific = (const CGObjectInstance *)LOCPLINT->adventureInt->selection.selected; //TODO: to rzutowanie wyglada groznie, ale dziala. Ale nie powinno wygladac groznie. if(!specific) @@ -744,7 +744,7 @@ void CInfoBar::newDay(int Day) { mode = 0; //showing day } - else + else { switch(LOCPLINT->cb->getDate(2)) { @@ -866,7 +866,7 @@ townList(5,&genRect(192,48,747,196),747,196,747,372) townList.genList(); heroWindow = new CHeroWindow(this->player); - + gems.push_back(CDefHandler::giveDef("agemLL.def")); gems.push_back(CDefHandler::giveDef("agemLR.def")); gems.push_back(CDefHandler::giveDef("agemUL.def")); @@ -886,7 +886,7 @@ void CAdvMapInt::fswitchLevel() underground.curimg=0; underground.show(); } - else + else { underground.curimg=1; position.z++; @@ -930,7 +930,7 @@ void CAdvMapInt::fendTurn() void CAdvMapInt::activate() { LOCPLINT->curint = this; - LOCPLINT->statusbar = &statusbar; + LOCPLINT->statusbar = &statusbar; kingOverview.activate(); underground.activate(); questlog.activate(); @@ -1049,7 +1049,7 @@ CAdvMapInt::CurrentSelection::CurrentSelection() selected=NULL; } void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client) -{ +{ if (down) { boost::algorithm::erase_all(text,"\""); @@ -1090,4 +1090,4 @@ int3 CAdvMapInt::verifyPos(int3 ver) if (ver.z>=CGI->mh->sizes.z) ver.z=CGI->mh->sizes.z-1; return ver; -} \ No newline at end of file +} diff --git a/CAdvmapInterface.h b/CAdvmapInterface.h index ce7293f59..11d13bbe8 100644 --- a/CAdvmapInterface.h +++ b/CAdvmapInterface.h @@ -8,7 +8,7 @@ #include "AdventureMapButton.h" class CDefHandler; class CCallback; -struct CPath; +struct CPath; class CAdvMapInt; class CGHeroInstance; class CGTownInstance; @@ -18,7 +18,7 @@ class CMinimap : public ClickableL, public ClickableR, public Hoverable, public MotionInterested, public virtual CIntObject { public: - SDL_Surface * radar; + SDL_Surface * radar; SDL_Surface * temps; std::map colors; std::map colorsBlocked; @@ -26,7 +26,7 @@ public: //TODO flagged buildings std::string statusbarTxt, rcText; - CMinimap(bool draw=true); + CMinimap(bool draw=true); void draw(); void redraw(int level=-1);// (level==-1) => redraw all levels void updateRadar(); @@ -51,7 +51,7 @@ public: CDefHandler * arrows; CTerrainRect(); CPath * currentPath; - void activate(); + void activate(); void deactivate(); void clickLeft(tribool down); void clickRight(tribool down); @@ -60,7 +60,7 @@ public: void keyPressed (SDL_KeyboardEvent & key); void show(); void showPath(); - int3 whichTileIsIt(int x, int y); //x,y are cursor position + int3 whichTileIsIt(int x, int y); //x,y are cursor position int3 whichTileIsIt(); //uses current cursor pos }; class CResDataBar @@ -72,7 +72,7 @@ public: std::string datetext; void clickRight (tribool down); - void activate(); + void activate(); void deactivate(); CResDataBar(); ~CResDataBar(); @@ -108,7 +108,7 @@ public: int player; std::vector gems; - + bool scrollingLeft ; bool scrollingRight ; bool scrollingUp ; @@ -128,7 +128,7 @@ public: moveHero, //- move hero spellbook,//- spellbook advOptions, //- adventure options - sysOptions,//- system options + sysOptions,//- system options nextHero, //- next hero endTurn;//- end turn //CHeroList herolist; @@ -137,13 +137,13 @@ public: CStatusBar statusbar; CResDataBar resdatabar; - + CHeroList heroList; - CTownList townList; + CTownList townList; CInfoBar infoBar; CHeroWindow * heroWindow; - + struct CurrentSelection { int type; //0 - hero, 1 - town @@ -153,8 +153,8 @@ public: //fuctions binded to buttons void fshowOverview(); - void fswitchLevel(); - void fshowQuestlog(); + void fswitchLevel(); + void fshowQuestlog(); void fsleepWake(); void fmoveHero(); void fshowSpellbok(); @@ -177,4 +177,4 @@ public: }; -#endif //CADVENTUREMAPINTERFACE_H \ No newline at end of file +#endif //CADVENTUREMAPINTERFACE_H diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 78db60923..d5ea7ff24 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -15,13 +15,15 @@ #include #include +const double M_PI = 3.14159265358979323846; + extern SDL_Surface * screen; extern TTF_Font * GEOR13; extern SDL_Color zwykly; SDL_Surface * CBattleInterface::cellBorder, * CBattleInterface::cellShade; -CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2) -: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL) +CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2) +: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL), myTurn(false) { //initializing armies this->army1 = army1; @@ -61,7 +63,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C blitAt(background, 0, 0); blitAt(menu, 0, 556); CSDL_Ext::update(); - + //preparing buttons and console bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3, 561, "icm003.def", false, NULL, false); bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54, 561, "icm001.def", false, NULL, false); @@ -78,7 +80,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C console->pos.y = 560; console->pos.w = 406; console->pos.h = 38; - + //loading hero animations if(hero1) // attacking hero { @@ -107,7 +109,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C for(int h=0; h<187; ++h) { bfield[h].myNumber = h; - + int x = 14 + ((h/17)%2==0 ? 22 : 0) + 44*(h%17); int y = 86 + 42 * (h/17); bfield[h].pos = genRect(cellShade->h, cellShade->w, x, y); @@ -119,7 +121,31 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C { bfield[it->second.position].accesible = false; } - + + //loading projectiles for units + for(std::map::iterator g = stacks.begin(); g != stacks.end(); ++g) + { + if(g->second.creature->isShooting() && CGI->creh->idToProjectile[g->second.creature->idNumber] != std::string()) + { + idToProjectile[g->second.creature->idNumber] = CDefHandler::giveDef(CGI->creh->idToProjectile[g->second.creature->idNumber]); + + if(idToProjectile[g->second.creature->idNumber]->ourImages.size() > 2) //add symmetric images + { + for(int k = idToProjectile[g->second.creature->idNumber]->ourImages.size()-2; k > 1; --k) + { + Cimage ci; + ci.bitmap = CSDL_Ext::rotate01(idToProjectile[g->second.creature->idNumber]->ourImages[k].bitmap); + ci.groupNumber = 0; + ci.imName = std::string(); + idToProjectile[g->second.creature->idNumber]->ourImages.push_back(ci); + } + } + for(int s=0; ssecond.creature->idNumber]->ourImages.size(); ++s) //alpha transforming + { + CSDL_Ext::alphaTransform(idToProjectile[g->second.creature->idNumber]->ourImages[s].bitmap); + } + } + } } CBattleInterface::~CBattleInterface() @@ -147,6 +173,9 @@ CBattleInterface::~CBattleInterface() for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g) delete g->second; + + for(std::map< int, CDefHandler * >::iterator g=idToProjectile.begin(); g!=idToProjectile.end(); ++g) + delete g->second; } void CBattleInterface::activate() @@ -241,7 +270,7 @@ void CBattleInterface::show(SDL_Surface * to) if(defendingHero) defendingHero->show(to); - //showing units //a lot of work... + ////showing units //a lot of work... std::vector stackAliveByHex[187]; //double loop because dead stacks should be printed first for(std::map::iterator j=stacks.begin(); j!=stacks.end(); ++j) @@ -309,6 +338,7 @@ void CBattleInterface::show(SDL_Surface * to) } } //units shown + projectileShowHelper(to);//showing projectiles } bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick) @@ -404,8 +434,36 @@ void CBattleInterface::stackRemoved(CStack stack) creAnims.erase(stack.ID); } -void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby) +void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting) { + if(creAnims[ID]->getType() != 2) + { + return; //something went wrong + } + if(byShooting) //delay hit animation + { + CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby); + while(true) + { + bool found = false; + for(std::list::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it) + { + if(it->creID == attacker.creature->idNumber) + { + found = true; + break; + } + } + if(!found) + break; + else + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + } + } + } creAnims[ID]->setType(5); //death for(int i=0; iframesInGroup(5)-1; ++i) { @@ -413,7 +471,7 @@ void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby) CSDL_Ext::update(); SDL_framerateDelay(LOCPLINT->mainFPSmng); } - + printConsoleAttacked(ID, dmg, killed, IDby); } @@ -421,6 +479,8 @@ void CBattleInterface::stackActivated(int number) { givenCommand = NULL; activeStack = number; + shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(number); + myTurn = true; } void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, bool endMoving) @@ -442,7 +502,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo int mutPos = CBattleHex::mutualPosition(curStackPos, destHex); - if(LOCPLINT->cb->battleGetCreature(number).isDoubleWide() && + if(LOCPLINT->cb->battleGetCreature(number).isDoubleWide() && ((creDir[number] && mutPos == 5) || (creDir[number] && mutPos == 0) || (creDir[number] && mutPos == 4))) //for special cases { switch(CBattleHex::mutualPosition(curStackPos, destHex)) //reverse unit if necessary @@ -593,14 +653,42 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo reverseCreature(number, destHex); //creDir[number] = (curs.owner == attackingHeroInstance->tempOwner); } - + std::pair coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature); creAnims[number]->pos.x = coords.first; creAnims[number]->pos.y = coords.second; } -void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby) +void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting) { + if(creAnims[ID]->getType() != 2) + { + return; //something went wrong + } + if(byShooting) //delay hit animation + { + CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby); + while(true) + { + bool found = false; + for(std::list::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it) + { + if(it->creID == attacker.creature->idNumber) + { + found = true; + break; + } + } + if(!found) + break; + else + { + show(); + CSDL_Ext::update(); + SDL_framerateDelay(LOCPLINT->mainFPSmng); + } + } + } creAnims[ID]->setType(3); //getting hit for(int i=0; iframesInGroup(3); ++i) { @@ -615,6 +703,10 @@ void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby) void CBattleInterface::stackAttacking(int ID, int dest) { + if(attackingInfo != NULL) + { + return; //something went wrong + } CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack if(aStack.creature->isDoubleWide()) { @@ -664,54 +756,28 @@ void CBattleInterface::stackAttacking(int ID, int dest) attackingInfo->frame = 0; attackingInfo->ID = ID; attackingInfo->reversing = false; + attackingInfo->shooting = false; - if(aStack.creature->isDoubleWide()) + switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction { - switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction - { - case 0: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); - break; - case 1: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); - break; - case 2: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); - break; - case 3: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); - break; - case 4: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); - break; - case 5: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); - break; - } - } - else //else for if(aStack.creature->isDoubleWide()) - { - switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction - { - case 0: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); - break; - case 1: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); - break; - case 2: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); - break; - case 3: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); - break; - case 4: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); - break; - case 5: - attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); - break; - } + case 0: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); + break; + case 1: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(10); + break; + case 2: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; + case 3: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 4: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(12); + break; + case 5: + attackingInfo->maxframe = creAnims[ID]->framesInGroup(11); + break; } } @@ -724,6 +790,9 @@ void CBattleInterface::hexLclicked(int whichOne) { if((whichOne%17)!=0 && (whichOne%17)!=16) //if player is trying to attack enemey unit or move creature stack { + if(!myTurn) + return; //we are not permit to do anything + int atCre = LOCPLINT->cb->battleGetStack(whichOne); //creature at destination tile; -1 if there is no one //LOCPLINT->cb->battleGetCreature(); if(atCre==-1) //normal move action @@ -734,6 +803,15 @@ void CBattleInterface::hexLclicked(int whichOne) ba->stackNumber = activeStack; givenCommand = ba; } + else if(LOCPLINT->cb->battleGetStackByID(atCre)->owner != attackingHeroInstance->tempOwner + && LOCPLINT->cb->battleCanShoot(activeStack, whichOne)) //shooting + { + BattleAction * ba = new BattleAction(); //to be deleted by engine + ba->actionType = 7; + ba->destinationTile = whichOne; + ba->stackNumber = activeStack; + givenCommand = ba; + } else if(LOCPLINT->cb->battleGetStackByID(atCre)->owner != attackingHeroInstance->tempOwner) //attacking { BattleAction * ba = new BattleAction(); //to be deleted by engine @@ -745,9 +823,80 @@ void CBattleInterface::hexLclicked(int whichOne) } } +void CBattleInterface::stackIsShooting(int ID, int dest) +{ + if(attackingInfo != NULL) + { + return; //something went wrong + } + //projectile + float projectileAngle; //in radians; if positive, projectiles goes up + float straightAngle = 0.2f; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value) + int fromHex = LOCPLINT->cb->battleGetPos(ID); + projectileAngle = atan2(float(abs(dest - fromHex)/17), float(abs(dest - fromHex)%17)); + if(fromHex < dest) + projectileAngle = -projectileAngle; + + SProjectileInfo spi; + spi.creID = LOCPLINT->cb->battleGetStackByID(ID)->creature->idNumber; + + spi.step = 0; + spi.frameNum = 0; + spi.spin = CGI->creh->idToProjectileSpin[spi.creID]; + + std::pair xycoord = CBattleHex::getXYUnitAnim(LOCPLINT->cb->battleGetPos(ID), true, &LOCPLINT->cb->battleGetCreature(ID)); + std::pair destcoord = CBattleHex::getXYUnitAnim(dest, false, &LOCPLINT->cb->battleGetCreature(ID)); + destcoord.first += 250; destcoord.second += 210; //TODO: find a better place to shoot + + if(projectileAngle > straightAngle) //upper shot + { + spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetX; + spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetY; + } + else if(projectileAngle < -straightAngle) //lower shot + { + spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetX; + spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetY; + } + else //straight shot + { + spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetX; + spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetY; + } + spi.lastStep = sqrt((float)((destcoord.first - spi.x)*(destcoord.first - spi.x) + (destcoord.second - spi.y) * (destcoord.second - spi.y))) / 40; + spi.dx = (destcoord.first - spi.x) / spi.lastStep; + spi.dy = (destcoord.second - spi.y) / spi.lastStep; + //set starting frame + if(spi.spin) + { + spi.frameNum = 0; + } + else + { + spi.frameNum = ((M_PI/2.0f - projectileAngle) / (2.0f *M_PI) + 1/((float)(2*(idToProjectile[spi.creID]->ourImages.size()-1)))) * (idToProjectile[spi.creID]->ourImages.size()-1); + } + //set delay + spi.animStartDelay = CGI->creh->creatures[spi.creID].attackClimaxFrame; + projectiles.push_back(spi); + + //attack aniamtion + attackingInfo = new CAttHelper; + attackingInfo->dest = dest; + attackingInfo->frame = 0; + attackingInfo->ID = ID; + attackingInfo->reversing = false; + attackingInfo->shooting = true; + if(projectileAngle > straightAngle) //upper shot + attackingInfo->shootingGroup = 14; + else if(projectileAngle < -straightAngle) //lower shot + attackingInfo->shootingGroup = 15; + else //straight shot + attackingInfo->shootingGroup = 16; + attackingInfo->maxframe = creAnims[ID]->framesInGroup(attackingInfo->shootingGroup); +} + void CBattleInterface::showRange(SDL_Surface * to, int ID) { - std::vector shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(ID); for(int i=0; iframe == 0) { CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack - if(aStack.creature->isDoubleWide()) + if(attackingInfo->shooting) { - switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction - { - case 0: - creAnims[attackingInfo->ID]->setType(10); - break; - case 1: - creAnims[attackingInfo->ID]->setType(10); - break; - case 2: - creAnims[attackingInfo->ID]->setType(11); - break; - case 3: - creAnims[attackingInfo->ID]->setType(12); - break; - case 4: - creAnims[attackingInfo->ID]->setType(12); - break; - case 5: - creAnims[attackingInfo->ID]->setType(11); - break; - } + creAnims[attackingInfo->ID]->setType(attackingInfo->shootingGroup); } - else //else for if(aStack.creature->isDoubleWide()) + else { - switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + if(aStack.creature->isDoubleWide()) { - case 0: - creAnims[attackingInfo->ID]->setType(10); - break; - case 1: - creAnims[attackingInfo->ID]->setType(10); - break; - case 2: - creAnims[attackingInfo->ID]->setType(11); - break; - case 3: - creAnims[attackingInfo->ID]->setType(12); - break; - case 4: - creAnims[attackingInfo->ID]->setType(12); - break; - case 5: - creAnims[attackingInfo->ID]->setType(11); - break; + switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + creAnims[attackingInfo->ID]->setType(10); + break; + case 1: + creAnims[attackingInfo->ID]->setType(10); + break; + case 2: + creAnims[attackingInfo->ID]->setType(11); + break; + case 3: + creAnims[attackingInfo->ID]->setType(12); + break; + case 4: + creAnims[attackingInfo->ID]->setType(12); + break; + case 5: + creAnims[attackingInfo->ID]->setType(11); + break; + } + } + else //else for if(aStack.creature->isDoubleWide()) + { + switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction + { + case 0: + creAnims[attackingInfo->ID]->setType(10); + break; + case 1: + creAnims[attackingInfo->ID]->setType(10); + break; + case 2: + creAnims[attackingInfo->ID]->setType(11); + break; + case 3: + creAnims[attackingInfo->ID]->setType(12); + break; + case 4: + creAnims[attackingInfo->ID]->setType(12); + break; + case 5: + creAnims[attackingInfo->ID]->setType(11); + break; + } } } } @@ -892,6 +1048,47 @@ void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDb console->addText(std::string(tabh)); } +void CBattleInterface::projectileShowHelper(SDL_Surface * to) +{ + if(to == NULL) + to = screen; + std::list< std::list::iterator > toBeDeleted; + for(std::list::iterator it=projectiles.begin(); it!=projectiles.end(); ++it) + { + if(it->animStartDelay>0) + { + --(it->animStartDelay); + continue; + } + SDL_Rect dst; + dst.h = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->h; + dst.w = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->w; + dst.x = it->x; + dst.y = it->y; + CSDL_Ext::blit8bppAlphaTo24bpp(idToProjectile[it->creID]->ourImages[it->frameNum].bitmap, NULL, to, &dst); + //actualizing projectile + ++it->step; + if(it->step == it->lastStep) + { + toBeDeleted.insert(toBeDeleted.end(), it); + } + else + { + it->x += it->dx; + it->y += it->dy; + if(it->spin) + { + ++(it->frameNum); + it->frameNum %= idToProjectile[it->creID]->ourImages.size(); + } + } + } + for(std::list< std::list::iterator >::iterator it = toBeDeleted.begin(); it!= toBeDeleted.end(); ++it) + { + projectiles.erase(*it); + } +} + void CBattleHero::show(SDL_Surface *to) { //animation of flag @@ -935,7 +1132,7 @@ CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG if(flip) { SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap); - SDL_FreeSurface(dh->ourImages[i].bitmap); + SDL_FreeSurface(dh->ourImages[i].bitmap); dh->ourImages[i].bitmap = hlp; } dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap); diff --git a/CBattleInterface.h b/CBattleInterface.h index 534b83e6a..196f8ade9 100644 --- a/CBattleInterface.h +++ b/CBattleInterface.h @@ -1,6 +1,7 @@ #pragma once #include "global.h" #include "CPlayerInterface.h" +#include class CCreatureSet; class CGHeroInstance; @@ -79,9 +80,11 @@ private: CCreatureSet * army1, * army2; //fighting armies CGHeroInstance * attackingHeroInstance, * defendingHeroInstance; std::map< int, CCreatureAnimation * > creAnims; //animations of creatures from fighting armies (order by BattleInfo's stacks' ID) + std::map< int, CDefHandler * > idToProjectile; //projectiles of creaures (creatureID, defhandler) std::map< int, bool > creDir; // unsigned char animCount; int activeStack; //number of active stack; -1 - no one + std::vector shadedHexes; //hexes available for active stack void showRange(SDL_Surface * to, int ID); //show helper funtion ot mark range of a unit class CAttHelper @@ -91,10 +94,25 @@ private: int dest; //atacked hex int frame, maxframe; //frame of animation, number of frames of animation bool reversing; + bool shooting; + int shootingGroup; //if shooting is true, print this animation group } * attackingInfo; void attackingShowHelper(); void printConsoleAttacked(int ID, int dmg, int killed, int IDby); + struct SProjectileInfo + { + int x, y; //position on the screen + int dx, dy; //change in position in one step + int step, lastStep; //to know when finish showing this projectile + int creID; //ID of creature that shot this projectile + int frameNum; //frame to display form projectile animation + bool spin; //if true, frameNum will be increased + int animStartDelay; //how many times projectile must be attempted to be shown till it's really show (decremented after hit) + }; + std::list projectiles; + void projectileShowHelper(SDL_Surface * to=NULL); //prints projectiles present on the battlefield + public: CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor ~CBattleInterface(); //d-tor @@ -105,6 +123,7 @@ public: std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield static SDL_Surface * cellBorder, * cellShade; BattleAction * givenCommand; //true if we have i.e. moved current unit + bool myTurn; //if true, interface is active (commands can be ordered //button handle funcs: void bOptionsf(); @@ -126,13 +145,14 @@ public: //call-ins void newStack(CStack stack); //new stack appeared on battlefield void stackRemoved(CStack stack); //stack disappeared from batlefiled - void stackKilled(int ID, int dmg, int killed, int IDby); //stack has been killed (but corpses remain) + void stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting); //stack has been killed (but corpses remain) void stackActivated(int number); //active stack has been changed void stackMoved(int number, int destHex, bool startMoving, bool endMoving); //stack with id number moved to destHex - void stackIsAttacked(int ID, int dmg, int killed, int IDby); //called when stack id attacked by stack with id IDby + void stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting); //called when stack id attacked by stack with id IDby void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest void newRound(int number); //caled when round is ended; number is the number of round void hexLclicked(int whichOne); //hex only call-in + void stackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest - friend CBattleHex; + friend class CBattleHex; }; diff --git a/CCallback.cpp b/CCallback.cpp index ec6b77f11..b7543f7ff 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -18,7 +18,6 @@ #include #include #include "lib/NetPacks.h" -//LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); extern CSharedCond > mess; HeroMoveDetails::HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho) @@ -79,7 +78,6 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) int3 stpos(ourPath->nodes[i].coord.x, ourPath->nodes[i].coord.y, hero->pos.z), endpos(ourPath->nodes[i-1].coord.x, ourPath->nodes[i-1].coord.y, hero->pos.z); HeroMoveDetails curd(stpos,endpos,hero); - *cl->serv << ui16(501) << hero->id << stpos << endpos; {//wait till there is server answer boost::unique_lock lock(*mess.mx); @@ -288,6 +286,29 @@ std::vector CCallback::getResourceAmount() int CCallback::getDate(int mode) { return gs->getDate(mode); + + + + + + + + + + + + + + + + + + + + + + + } std::vector < std::string > CCallback::getObjDescriptions(int3 pos) { @@ -310,15 +331,15 @@ bool CCallback::verifyPath(CPath * path, bool blockSea) continue; if ( - ((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype==EterrainType::water) + ((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype==water) && - (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype!=EterrainType::water)) + (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype!=water)) || - ((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype!=EterrainType::water) + ((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype!=water) && - (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==EterrainType::water)) + (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==water)) || - (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==EterrainType::rock) + (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==rock) ) return false; @@ -401,6 +422,9 @@ const CCreatureSet* CCallback::getGarrison(const CGObjectInstance *obj) int CCallback::swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2) { if(s1->tempOwner != player || s2->tempOwner != player) + + + return -1; *cl->serv << ui16(502) << ui8(1) << s1->id << ui8(p1) << s2->id << ui8(p2); @@ -493,18 +517,7 @@ int CCallback::battleGetObstaclesAtTile(int tile) //returns bitfield } int CCallback::battleGetStack(int pos) { - for(int g=0; gstate->curB->stacks.size(); ++g) - { - if(CGI->state->curB->stacks[g]->position == pos || - ( CGI->state->curB->stacks[g]->creature->isDoubleWide() && - ( (CGI->state->curB->stacks[g]->attackerOwned && CGI->state->curB->stacks[g]->position-1 == pos) || - (!CGI->state->curB->stacks[g]->attackerOwned && CGI->state->curB->stacks[g]->position+1 == pos) - ) - ) - ) - return CGI->state->curB->stacks[g]->ID; - } - return -1; + return CGI->state->battleGetStack(pos); } CStack* CCallback::battleGetStackByID(int ID) @@ -565,4 +578,13 @@ bool CCallback::battleIsStackMine(int ID) return CGI->state->curB->stacks[h]->owner == player; } return false; -} \ No newline at end of file +} +bool CCallback::battleCanShoot(int ID, int dest) //TODO: finish +{ + if(battleGetStackByID(ID)->creature->isShooting() + && battleGetStack(dest) != -1 + && battleGetStackByPos(dest)->owner != battleGetStackByID(ID)->owner + && battleGetStackByPos(dest)->alive) + return true; + return false; +} diff --git a/CCallback.h b/CCallback.h index 19c1df86a..8cb7ce1ae 100644 --- a/CCallback.h +++ b/CCallback.h @@ -2,8 +2,13 @@ #define CCALLBACK_H #include "global.h" +#ifdef _WIN32 #include "tchar.h" -#include +#else +#include "tchar_amigaos4.h" +#endif +#include "CGameState.h" + class CGHeroInstance; class CGameState; struct CPath; @@ -28,9 +33,9 @@ struct UpgradeInfo }; class ICallback -{ +{ public: - virtual bool moveHero(int ID, CPath * path, int idtype, int pathType=0)=0;//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero + virtual bool moveHero(int ID, CPath * path, int idtype, int pathType=0)=0;//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos virtual int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)=0;//swaps creatures between two posiibly different garrisons // TODO: AI-unsafe code - fix it! virtual int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)=0;//joins first stack tothe second (creatures must be same type) @@ -63,7 +68,7 @@ public: //battle virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship - virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield + virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos @@ -74,6 +79,7 @@ public: //virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible virtual std::vector battleGetAvailableHexes(int ID)=0; //reutrns numbers of hexes reachable by creature with id ID virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller + virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest }; struct HeroMoveDetails @@ -99,7 +105,7 @@ protected: public: //commands - bool moveHero(int ID, CPath * path, int idtype, int pathType=0);//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero + bool moveHero(int ID, CPath * path, int idtype, int pathType=0);//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos void selectionMade(int selection, int asker); int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); @@ -136,7 +142,7 @@ public: //battle int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship - int battleGetObstaclesAtTile(int tile); //returns bitfield + int battleGetObstaclesAtTile(int tile); //returns bitfield int battleGetStack(int pos); //returns ID of stack on the tile CStack * battleGetStackByID(int ID); //returns stack info by given ID CStack * battleGetStackByPos(int pos); //returns stack info by given pos @@ -147,9 +153,16 @@ public: //bool battleMoveCreature(int ID, int dest); //moves creature with id ID to dest if possible std::vector battleGetAvailableHexes(int ID); //reutrns numbers of hexes reachable by creature with id ID bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller - + bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest + + //friends friend class CClient; +#ifndef __GNUC__ + friend int _tmain(int argc, _TCHAR* argv[]); +#else + friend int main(int argc, _TCHAR* argv[]); +#endif }; -#endif //CCALLBACK_H \ No newline at end of file +#endif //CCALLBACK_H diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index ce46f7cab..bda748917 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -17,7 +17,7 @@ extern TTF_Font * GEOR16; CBuildingRect::CBuildingRect(Structure *Str) :str(Str), moi(false), offset(0) -{ +{ def = CDefHandler::giveDef(Str->defName); max = def->ourImages.size(); @@ -88,7 +88,7 @@ void CBuildingRect::hover(bool on) MotionInterested::activate(); moi = true; } - else + else { if(moi) MotionInterested::deactivate(); @@ -102,7 +102,7 @@ void CBuildingRect::hover(bool on) } void CBuildingRect::clickLeft (tribool down) { - + if(area && (LOCPLINT->castleInt->hBuild==this) && !(indeterminate(down)) && (CSDL_Ext::SDL_GetPixel(area,LOCPLINT->current->motion.x-pos.x,LOCPLINT->current->motion.y-pos.y) != 0)) //na polu { if(pressedL && !down) @@ -110,7 +110,7 @@ void CBuildingRect::clickLeft (tribool down) ClickableL::clickLeft(down); } - + //todo - handle } void CBuildingRect::clickRight (tribool down) @@ -123,8 +123,8 @@ void CBuildingRect::clickRight (tribool down) vinya->free = true; vinya->bitmap = CMessage::drawBoxTextBitmapSub (LOCPLINT->playerID, - CGI->buildh->buildings[str->townID][str->ID]->description, - LOCPLINT->castleInt->bicons->ourImages[str->ID].bitmap, + CGI->buildh->buildings[str->townID][str->ID]->description, + LOCPLINT->castleInt->bicons->ourImages[str->ID].bitmap, CGI->buildh->buildings[str->townID][str->ID]->name); vinya->pos.x = screen->w/2 - vinya->bitmap->w/2; vinya->pos.y = screen->h/2 - vinya->bitmap->h/2; @@ -194,7 +194,11 @@ std::string getBgName(int type) //TODO - co z tym zrobi case 8: return "TBELBACK.bmp"; default: +#ifndef __GNUC__ throw new std::exception("std::string getBgName(int type): invalid type"); +#else + throw new std::exception(); +#endif } } class SORTHELP @@ -209,7 +213,7 @@ public: } srthlp ; CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) -{ +{ hall = NULL; townInt = BitmapHandler::loadBitmap("TOWNSCRN.bmp"); cityBg = BitmapHandler::loadBitmap(getBgName(Town->subID)); @@ -283,7 +287,11 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) defname = "HALLELEM.DEF"; break; default: +#ifndef __GNUC__ throw new std::exception("Bad town subID"); +#else + throw new std::exception(); +#endif } bicons = CDefHandler::giveDefEss(defname); //blit buildings on bg @@ -368,7 +376,7 @@ void CCastleInterface::enterHall() hallInt->show(); } void CCastleInterface::showAll(SDL_Surface * to) -{ +{ if (!to) to=screen; blitAt(cityBg,0,0,to); @@ -377,7 +385,7 @@ void CCastleInterface::showAll(SDL_Surface * to) townlist->draw(); statusbar->show(); - garr->show(); + garr->show(); int pom; //draw fort icon @@ -426,7 +434,7 @@ void CCastleInterface::showAll(SDL_Surface * to) //print name and income CSDL_Ext::printAt(town->name,85,389,GEOR13,zwykly,to); char temp[10]; - itoa(town->dailyIncome(),temp,10); + SDL_itoa(town->dailyIncome(),temp,10); CSDL_Ext::printAtMiddle(temp,195,442,GEOR13,zwykly,to); //blit town icon @@ -476,13 +484,13 @@ void CCastleInterface::show(SDL_Surface * to) blitAt(buildings[i]->def->ourImages[0].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to); blitAt(buildings[i]->def->ourImages[frame].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to); } - else + else blitAt(buildings[i]->def->ourImages[frame].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to); if(hBuild==buildings[i] && hBuild->border) //if this this higlighted structure and has border we'll blit it blitAt(hBuild->border,hBuild->pos,to); } - + } void CCastleInterface::activate() { @@ -553,7 +561,7 @@ void CCastleInterface::recreateBuildings() { if(seti->first == st->group) { - obecny = seti; + obecny = seti; break; } } @@ -567,7 +575,11 @@ void CCastleInterface::recreateBuildings() { delete buildings[itpb]; buildings.erase(buildings.begin() + itpb); + #ifndef __GNUC__ obecny->second = st->ID; + #else + *(const_cast(&(obecny->second))) = st->ID; + #endif buildings.push_back(new CBuildingRect(st)); } } @@ -588,7 +600,7 @@ void CCastleInterface::recreateBuildings() std::sort(buildings.begin(),buildings.end(),srthlp); //code for Mana Vortex (there are two sets of animation frames - one without mage guild and one with - if((town->subID == 5) && (town->builtBuildings.find(21)!=town->builtBuildings.end())) + if((town->subID == 5) && (town->builtBuildings.find(21)!=town->builtBuildings.end())) { CBuildingRect *vortex = NULL; for(int i=0;isubID == 0) && (town->builtBuildings.find(6)!=town->builtBuildings.end())) + else if((town->subID == 0) && (town->builtBuildings.find(6)!=town->builtBuildings.end())) { CBuildingRect *shipyard = NULL; for(int i=0;icb->getResourceAmount(i),buf,10); + SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10); CSDL_Ext::printAtMiddle(buf,pos.x + 50 + 76*i,pos.y+pos.h/2,GEOR13,zwykly); } std::vector temp; - itoa(LOCPLINT->cb->getDate(3),buf,10); temp.push_back(std::string(buf)); - itoa(LOCPLINT->cb->getDate(2),buf,10); temp.push_back(buf); - itoa(LOCPLINT->cb->getDate(1),buf,10); temp.push_back(buf); + SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp.push_back(std::string(buf)); + SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp.push_back(buf); + SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp.push_back(buf); CSDL_Ext::printAtMiddle(CSDL_Ext::processStr( CGI->generaltexth->allTexts[62] - +": %s, " - + CGI->generaltexth->allTexts[63] - + ": %s, " - + CGI->generaltexth->allTexts[64] + +": %s, " + + CGI->generaltexth->allTexts[63] + + ": %s, " + + CGI->generaltexth->allTexts[64] + ": %s",temp) ,pos.x+545+(pos.w-545)/2,pos.y+pos.h/2,GEOR13,zwykly); temp.clear(); @@ -715,7 +727,7 @@ void CHallInterface::CBuildingBox::show(SDL_Surface * to) int pom, pom2=-1; switch (state) { - case 4: + case 4: pom = 0; pom2 = 0; break; @@ -790,7 +802,7 @@ CHallInterface::CHallInterface(CCastleInterface * owner) { if( (owner->town->builtBuildings.find(CGI->buildh->hall[owner->town->subID].second[i][j][k])) - == + == (owner->town->builtBuildings.end()) ) { int x = 34 + 194*j, @@ -828,7 +840,7 @@ CHallInterface::CHallInterface(CCastleInterface * owner) } //TODO: check if capital is already built, check if there is water for shipyard - + @@ -967,9 +979,9 @@ std::string CHallInterface::CBuildWindow::getTextForState(int state) std::set used; used.insert(bid); std::set reqs; - + for(std::set::iterator i=CGI->townh->requirements[tid][bid].begin();i!=CGI->townh->requirements[tid][bid].end();i++) - if (LOCPLINT->castleInt->town->builtBuildings.find(*i) == LOCPLINT->castleInt->town->builtBuildings.end()) + if (LOCPLINT->castleInt->town->builtBuildings.find(*i) == LOCPLINT->castleInt->town->builtBuildings.end()) reqs.insert(*i); while(true) { @@ -986,7 +998,7 @@ std::string CHallInterface::CBuildWindow::getTextForState(int state) ) { if(LOCPLINT->castleInt->town->builtBuildings.find(*j) == //this building is not built - LOCPLINT->castleInt->town->builtBuildings.end()) + LOCPLINT->castleInt->town->builtBuildings.end()) reqs.insert(*j); } } @@ -1012,12 +1024,12 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod :tid(Tid),bid(Bid),mode(Mode), state(State) { SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPUBUILD.bmp"); + graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID); bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo SDL_SetColorKey(hhlp,SDL_SRCCOLORKEY,SDL_MapRGB(hhlp->format,0,255,255)); SDL_FreeSurface(hhlp); pos.x = screen->w/2 - bitmap->w/2; pos.y = screen->h/2 - bitmap->h/2; - graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID); blitAt(LOCPLINT->castleInt->bicons->ourImages[bid].bitmap,125,50,bitmap); std::vector pom; pom.push_back(CGI->buildh->buildings[tid][bid]->name); CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->description,197,168,GEOR16,40,zwykly,bitmap); @@ -1033,7 +1045,7 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod { if(!CGI->buildh->buildings[tid][bid]->resources[cn]) continue; - itoa(CGI->buildh->buildings[tid][bid]->resources[cn],buf,10); + SDL_itoa(CGI->buildh->buildings[tid][bid]->resources[cn],buf,10); if(it<4) { CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row1w/2)+77*it+16,ah+42,GEOR16,zwykly,bitmap); @@ -1066,4 +1078,4 @@ CHallInterface::CBuildWindow::~CBuildWindow() delete buy; delete cancel; } -} \ No newline at end of file +} diff --git a/CCastleInterface.h b/CCastleInterface.h index 356a6681c..4e1ec91f7 100644 --- a/CCastleInterface.h +++ b/CCastleInterface.h @@ -97,7 +97,7 @@ public: class CBuildWindow: public IShowable, public ClickableR { - public: + public: int tid, bid, state; //town id, building id, state bool mode; // 0 - normal (with buttons), 1 - r-click popup SDL_Surface * bitmap; //main window bitmap, with blitted res/text, without buttons/subtitle in "statusbar" @@ -129,4 +129,4 @@ public: void show(SDL_Surface * to=NULL); void activate(); void deactivate(); -}; \ No newline at end of file +}; diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index cfd6acab4..d08d59d2b 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -53,7 +53,7 @@ int internalFunc(void * callback) boost::filesystem::create_directory("Extracted_txts"); std::cout<<"Command accepted. Opening .lod file...\t"; CLodHandler * txth = new CLodHandler; - txth->init(std::string("Data\\H3bitmap.lod"),"data"); + txth->init(std::string(DATA_DIR "Data" PATHSEPARATOR "H3bitmap.lod"),"data"); std::cout<<"done.\nScanning .lod file\n"; int curp=0; std::string pattern = ".TXT"; @@ -74,6 +74,9 @@ int internalFunc(void * callback) std::cout<<"\rExtracting done :)\n"; } vector* p; + int heroX; + int heroY; + int heroZ; switch (*cn.c_str()) { //case 'P': @@ -144,6 +147,7 @@ int internalFunc(void * callback) //SDL_Delay(100); //delete p; } + SDL_Delay(10); } return -1; } diff --git a/CConsoleHandler.h b/CConsoleHandler.h index 9c9584aa4..e84579b8c 100644 --- a/CConsoleHandler.h +++ b/CConsoleHandler.h @@ -8,6 +8,12 @@ public: void runConsole(); friend class CClient; + +#ifndef __GNUC__ + friend int _tmain(int argc, _TCHAR* argv[]); +#else + friend int main(int argc, _TCHAR* argv[]); +#endif }; -#endif //CCONSOLEHANDLER_H \ No newline at end of file +#endif //CCONSOLEHANDLER_H diff --git a/CCursorHandler.cpp b/CCursorHandler.cpp index 5c17dc95d..5d532d670 100644 --- a/CCursorHandler.cpp +++ b/CCursorHandler.cpp @@ -37,4 +37,4 @@ void CCursorHandler::draw1() void CCursorHandler::draw2() { blitAt(help,xpos,ypos); -} \ No newline at end of file +} diff --git a/CCursorHandler.h b/CCursorHandler.h index 80d9b7126..313e96d03 100644 --- a/CCursorHandler.h +++ b/CCursorHandler.h @@ -22,4 +22,4 @@ public: }; -#endif //CCURSORHANDLER_H \ No newline at end of file +#endif //CCURSORHANDLER_H diff --git a/CGameInfo.cpp b/CGameInfo.cpp index ed0467ec5..e677d0c4e 100644 --- a/CGameInfo.cpp +++ b/CGameInfo.cpp @@ -1,4 +1,4 @@ #include "stdafx.h" #include "CGameInfo.h" -CGameInfo * CGI; \ No newline at end of file +CGameInfo * CGI; diff --git a/CGameInfo.h b/CGameInfo.h index f0109414a..e10c0f3be 100644 --- a/CGameInfo.h +++ b/CGameInfo.h @@ -2,6 +2,10 @@ #define CGAMEINFO_H #include "global.h" + + + + #include @@ -60,4 +64,4 @@ public: CScreenHandler * screenh; }; -#endif //CGAMEINFO_H \ No newline at end of file +#endif //CGAMEINFO_H diff --git a/CGameInterface.cpp b/CGameInterface.cpp index f77e63997..0a847d999 100644 --- a/CGameInterface.cpp +++ b/CGameInterface.cpp @@ -1,11 +1,10 @@ #include "stdafx.h" #include "CGameInterface.h" -#include "CAdvMapInterface.h" +#include "CAdvmapInterface.h" #include "CMessage.h" #include "mapHandler.h" #include "SDL_Extensions.h" #include "SDL_framerate.h" -#include "CScreenHandler.h" #include "CCursorHandler.h" #include "CCallback.h" #include "SDL_Extensions.h" @@ -14,6 +13,7 @@ #include #include "hch/CHeroHandler.h" #include "SDL_framerate.h" +#include "AI/EmptyAI/CEmptyAI.h" #ifdef _WIN32 #include //for .dll libs @@ -28,6 +28,7 @@ CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname) CGlobalAI * ret=NULL; CGlobalAI*(*getAI)(); void(*getName)(char*); + #ifdef _WIN32 HINSTANCE dll = LoadLibraryA(dllname.c_str()); if (!dll) @@ -42,11 +43,17 @@ CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname) ; //TODO: handle AI library on Linux #endif char * temp = new char[50]; +#if !defined(__amigaos4__) && !defined(__unix__) getName(temp); +#endif std::cout << "Loaded .dll with AI named " << temp << std::endl; delete temp; +#if !defined(__amigaos4__) && !defined(__unix__) ret = getAI(); ret->init(cb); +#else + //ret = new CEmptyAI(); +#endif return ret; } //CGlobalAI::CGlobalAI() diff --git a/CGameInterface.h b/CGameInterface.h index c8a3bba4b..826c14447 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -28,9 +28,9 @@ class CObstacle struct BattleAction { bool side; //who made this action: false - left, true - right player - int stackNumber;//stack ID, -1 left hero, -2 right hero, - int actionType; // 0 = Cancel BattleAction 1 = Hero cast a spell 2 = Walk 3 = Defend 4 = Retreat from the battle 5 = Surrender 6 = Walk and Attack 7 = Shoot 8 = Wait 9 = Catapult 10 = Monster casts a spell (i.e. Faerie Dragons) - int destinationTile; + int stackNumber;//stack ID, -1 left hero, -2 right hero, + int actionType; // 0 = Cancel BattleAction 1 = Hero cast a spell 2 = Walk 3 = Defend 4 = Retreat from the battle 5 = Surrender 6 = Walk and Attack 7 = Shoot 8 = Wait 9 = Catapult 10 = Monster casts a spell (i.e. Faerie Dragons) + int destinationTile; int additionalInfo; // e.g. spell number if type is 1 || 10 }; @@ -40,7 +40,7 @@ struct StackState int attackBonus, defenseBonus, healthBonus, speedBonus; int currentHealth; int shotsLeft; - std::set effects; + std::set effects; int morale, luck; }; @@ -50,12 +50,12 @@ public: bool human; int playerID, serialID; - virtual void init(ICallback * CB)=0{}; - virtual void yourTurn()=0{}; - virtual void heroKilled(const CGHeroInstance*)=0{}; - virtual void heroCreated(const CGHeroInstance*)=0{}; - virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)=0{}; - virtual void heroMoved(const HeroMoveDetails & details)=0{}; + virtual void init(ICallback * CB){}; + virtual void yourTurn(){}; + virtual void heroKilled(const CGHeroInstance*){}; + virtual void heroCreated(const CGHeroInstance*){}; + virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val){}; + virtual void heroMoved(const HeroMoveDetails & details){}; virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){}; virtual void tileRevealed(int3 pos){}; virtual void tileHidden(int3 pos){}; @@ -64,7 +64,7 @@ public: virtual void showSelDialog(std::string text, std::vector & 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 + //battle call-ins virtual void battleStart(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles){}; //called when battlefield is prepared, prior the battle beginning virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn @@ -74,8 +74,8 @@ public: virtual void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector capturedArtifacts, int expForWinner, bool winner){}; virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving)=0; virtual void battleStackAttacking(int ID, int dest)=0; - virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby)=0; - virtual void battleStackKilled(int ID, int dmg, int killed, int IDby)=0; + virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting)=0; + virtual void battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting)=0; // }; @@ -93,8 +93,8 @@ public: virtual void heroCreated(const CGHeroInstance*){}; virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving){}; virtual void battleStackAttacking(int ID, int dest){}; - virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby){}; - virtual void battleStackKilled(int ID, int dmg, int killed, int IDby){}; + virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting){}; + virtual void battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting){}; virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;}; }; -#endif //CGAMEINTERFACE_H \ No newline at end of file +#endif //CGAMEINTERFACE_H diff --git a/CGameState.cpp b/CGameState.cpp index 25e57b8d3..1e2babdc3 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -922,6 +922,11 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C battleAttackCreatureStack(ba.stackNumber, ba.destinationTile); break; } + case 7: //shoot + { + battleShootCreatureStack(ba.stackNumber, ba.destinationTile); + break; + } } } else @@ -1030,7 +1035,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) if(curStack->attackerOwned ? (v%17)==1 : (v%17)==15) accessibility[v] = false; } - if(!accessibility[dest]) + if(!stackAtEnd && !accessibility[dest]) return false; int predecessor[187]; //for getting the Path for(int b=0; b<187; ++b) @@ -1111,43 +1116,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) { LOCPLINT->battleStackAttacking(ID, path[v]); //counting dealt damage - int numberOfCres = curStack->amount; //number of attacking creatures - int attackDefenseBonus = curStack->creature->attack - curB->stacks[numberOfStackAtEnd]->creature->defence; - int damageBase = 0; - if(curStack->creature->damageMax == curStack->creature->damageMin) //constant damage - { - damageBase = curStack->creature->damageMin; - } - else - { - damageBase = ran()%(curStack->creature->damageMax - curStack->creature->damageMin) + curStack->creature->damageMin + 1; - } - - float dmgBonusMultiplier = 1.0; - if(attackDefenseBonus < 0) //decreasing dmg - { - if(0.02f * (-attackDefenseBonus) > 0.3f) - { - dmgBonusMultiplier += -0.3f; - } - else - { - dmgBonusMultiplier += 0.02f * attackDefenseBonus; - } - } - else //increasing dmg - { - if(0.05f * attackDefenseBonus > 4.0f) - { - dmgBonusMultiplier += 4.0f; - } - else - { - dmgBonusMultiplier += 0.05f * attackDefenseBonus; - } - } - - int finalDmg = (float)damageBase * (float)curStack->amount * dmgBonusMultiplier; + int finalDmg = calculateDmg(curStack, curB->stacks[numberOfStackAtEnd]); //applying damages int cresKilled = finalDmg / curB->stacks[numberOfStackAtEnd]->creature->hitPoints; @@ -1168,12 +1137,12 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) if(curB->stacks[numberOfStackAtEnd]->amount<=0) //stack killed { curB->stacks[numberOfStackAtEnd]->amount = 0; - LOCPLINT->battleStackKilled(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore) , ID); + LOCPLINT->battleStackKilled(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore) , ID, false); curB->stacks[numberOfStackAtEnd]->alive = false; } else { - LOCPLINT->battleStackIsAttacked(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID); + LOCPLINT->battleStackIsAttacked(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID, false); } //damage applied @@ -1201,6 +1170,125 @@ bool CGameState::battleAttackCreatureStack(int ID, int dest) return true; } +bool CGameState::battleShootCreatureStack(int ID, int dest) +{/* + CStack * curStack = NULL; + for(int y=0; ystacks.size(); ++y) + { + if(curB->stacks[y]->ID == ID) + { + curStack = curB->stacks[y]; + break; + } + } + if(!curStack) + return false; + int IDOfStackAtEnd = battleGetStack(dest); + int numberOfStackAtEnd = -1; + for(int v=0; vstacks.size(); ++v) + { + if(curB->stacks[v]->ID == IDOfStackAtEnd) + { + numberOfStackAtEnd = v; + break; + } + } + + if(IDOfStackAtEnd == -1 || curB->stacks[numberOfStackAtEnd]->owner == curStack->owner || !curB->stacks[numberOfStackAtEnd]->alive) + return false; + + LOCPLINT->battleStackIsShooting(ID, dest); + + //counting dealt damage + int finalDmg = calculateDmg(curStack, curB->stacks[numberOfStackAtEnd]); + + //applying damages + int cresKilled = finalDmg / curB->stacks[ID]->creature->hitPoints; + int damageFirst = finalDmg % curB->stacks[ID]->creature->hitPoints; + + if( curB->stacks[numberOfStackAtEnd]->firstHPleft <= damageFirst ) + { + curB->stacks[numberOfStackAtEnd]->amount -= 1; + curB->stacks[numberOfStackAtEnd]->firstHPleft += curB->stacks[numberOfStackAtEnd]->creature->hitPoints - damageFirst; + } + else + { + curB->stacks[numberOfStackAtEnd]->firstHPleft -= damageFirst; + } + + int cresInstackBefore = curB->stacks[numberOfStackAtEnd]->amount; + curB->stacks[numberOfStackAtEnd]->amount -= cresKilled; + if(curB->stacks[numberOfStackAtEnd]->amount<=0) //stack killed + { + curB->stacks[numberOfStackAtEnd]->amount = 0; + LOCPLINT->battleStackKilled(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID, true); + curB->stacks[numberOfStackAtEnd]->alive = false; + } + else + { + LOCPLINT->battleStackIsAttacked(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID, true); + } + + //damage applied*/ + return true; +} + +int CGameState::battleGetStack(int pos) +{ + for(int g=0; gstacks.size(); ++g) + { + if(curB->stacks[g]->position == pos || + ( curB->stacks[g]->creature->isDoubleWide() && + ( (curB->stacks[g]->attackerOwned && curB->stacks[g]->position-1 == pos) || + (!curB->stacks[g]->attackerOwned && curB->stacks[g]->position+1 == pos) + ) + ) + ) + return curB->stacks[g]->ID; + } + return -1; +} + +int CGameState::calculateDmg(const CStack* attacker, const CStack* defender) +{ + int attackDefenseBonus = attacker->creature->attack - defender->creature->defence; + int damageBase = 0; + if(attacker->creature->damageMax == attacker->creature->damageMin) //constant damage + { + damageBase = attacker->creature->damageMin; + } + else + { + damageBase = rand()%(attacker->creature->damageMax - attacker->creature->damageMin) + attacker->creature->damageMin + 1; + } + + float dmgBonusMultiplier = 1.0; + if(attackDefenseBonus < 0) //decreasing dmg + { + if(0.02f * (-attackDefenseBonus) > 0.3f) + { + dmgBonusMultiplier += -0.3f; + } + else + { + dmgBonusMultiplier += 0.02f * attackDefenseBonus; + } + } + else //increasing dmg + { + if(0.05f * attackDefenseBonus > 4.0f) + { + dmgBonusMultiplier += 4.0f; + } + else + { + dmgBonusMultiplier += 0.05f * attackDefenseBonus; + } + } + + return (float)damageBase * (float)attacker->amount * dmgBonusMultiplier; +} + std::vector CGameState::battleGetRange(int ID) {/* int initialPlace=-1; //position of unit diff --git a/CGameState.h b/CGameState.h index 73ccd8c32..11e65d6e2 100644 --- a/CGameState.h +++ b/CGameState.h @@ -3,7 +3,11 @@ #include "global.h" #include #include +#ifdef _WIN32 #include +#else +#include "tchar_amigaos4.h" +#endif class CScriptCallback; class CCallback; @@ -78,7 +82,6 @@ private: ui32 day; //total number of days in game Mapa * map; std::map players; //ID <-> playerstate - std::map villages, forts, capitols; //def-info for town graphics boost::shared_mutex *mx; @@ -94,6 +97,9 @@ private: void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2); bool battleMoveCreatureStack(int ID, int dest); bool battleAttackCreatureStack(int ID, int dest); + bool battleShootCreatureStack(int ID, int dest); + int battleGetStack(int pos); //returns ID of stack at given tile + static int calculateDmg(const CStack* attacker, const CStack* defender); //TODO: add additional conditions and require necessary data std::vector battleGetRange(int ID); //called by std::vector CCallback::battleGetAvailableHexes(int ID); public: 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 diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 93358842b..5337d1e75 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -47,7 +47,6 @@ CHeroWindow::CHeroWindow(int playerColor): gar3button = new AdventureMapButton(CGI->generaltexth->heroscrn[24], CGI->generaltexth->heroscrn[30], boost::bind(&CHeroWindow::gar3,this), 546, 527, "hsbtns7.def", false, NULL, false); gar4button = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[32], boost::function(), 604, 527, "hsbtns9.def", false, NULL, false); - //boost::bind(&CGarrisonInt::splitClick,garInt) leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::leftArtRoller,this), 379, 364, "hsbtns3.def", false, NULL, false); rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::rightArtRoller,this), 632, 364, "hsbtns5.def", false, NULL, false); @@ -191,7 +190,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero) CGHeroInstance *hero = const_cast(Hero); //but don't modify hero! - it's only for easy map reading if(!hero) //something strange... no hero? it shouldn't happen { - return; + return; } curHero = hero; @@ -236,7 +235,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero) secSkillAreas[g]->text = hlp.substr(1, hlp.size()-2); break; } - + char * hlpp = new char[200]; sprintf(hlpp, CGI->generaltexth->heroscrn[21].c_str(), CGI->abilh->levels[hero->secSkills[g].second].c_str(), CGI->abilh->abilities[hero->secSkills[g].first]->name.c_str()); secSkillAreas[g]->hoverText = std::string(hlpp); @@ -632,12 +631,12 @@ void CHeroWindow::deactivate() } for(int f=0; fdeactivate(); } for(int f=0; fdeactivate(); } @@ -737,7 +736,7 @@ void CHeroWindow::redrawCurBack() blitAt(skillpics->ourImages[4].bitmap, 20, 230, curBack); blitAt(skillpics->ourImages[3].bitmap, 162, 230, curBack); - blitAt(graphics->portraitLarge[curHero->subID], 19, 19, curBack); + blitAt(graphics->portraitLarge[curHero->portrait], 19, 19, curBack); CSDL_Ext::printAtMiddle(curHero->name, 190, 40, GEORXX, tytulowy, curBack); @@ -802,14 +801,14 @@ void CHeroWindow::redrawCurBack() for(int g=0; gcb->howManyHeroes(); ++g) { const CGHeroInstance * cur = LOCPLINT->cb->getHeroInfo(player, g, false); - blitAt(graphics->portraitSmall[cur->subID], 611, 87+g*54, curBack); + blitAt(graphics->portraitSmall[cur->portrait], 611, 87+g*54, curBack); //printing yellow border if(cur->name == curHero->name) { - for(int f=0; fportraitSmall[cur->subID]->w; ++f) + for(int f=0; fportraitSmall[cur->portrait]->w; ++f) { - for(int h=0; hportraitSmall[cur->subID]->h; ++h) - if(f==0 || h==0 || f==graphics->portraitSmall[cur->subID]->w-1 || h==graphics->portraitSmall[cur->subID]->h-1) + for(int h=0; hportraitSmall[cur->portrait]->h; ++h) + if(f==0 || h==0 || f==graphics->portraitSmall[cur->portrait]->w-1 || h==graphics->portraitSmall[cur->portrait]->h-1) { CSDL_Ext::SDL_PutPixel(curBack, 611+f, 87+g*54+h, 240, 220, 120); } @@ -914,7 +913,7 @@ void CArtPlace::clickLeft(boost::logic::tribool down) if(this->fitsHere(ourWindow->activeArtPlace->ourArt) && ourWindow->activeArtPlace->fitsHere(this->ourArt)) { //swap artifacts - + LOCPLINT->cb->swapArifacts( ourWindow->curHero, this->myNumber>=0, @@ -936,7 +935,7 @@ void CArtPlace::clickLeft(boost::logic::tribool down) text = ourArt->description; else text = std::string(); - + ourWindow->activeArtPlace->clicked = false; ourWindow->activeArtPlace = NULL; } @@ -1038,6 +1037,10 @@ void LClickableArea::clickLeft(boost::logic::tribool down) //{ // LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector()); //} + + + + } void RClickableArea::activate() @@ -1054,13 +1057,21 @@ void RClickableArea::clickRight(boost::logic::tribool down) //{ // LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector()); //} + + + + } void LRClickableAreaWText::clickLeft(boost::logic::tribool down) { if(!down) { + #ifndef __amigaos4__ LOCPLINT->showInfoDialog(text, std::vector()); + #else + #warning error here! + #endif } } void LRClickableAreaWText::clickRight(boost::logic::tribool down) @@ -1104,7 +1115,11 @@ void LRClickableAreaWTextComp::clickLeft(boost::logic::tribool down) { if((!down) && pressedL) { +#ifndef __amigaos4__ LOCPLINT->showInfoDialog(text, std::vector(1, new SComponent(SComponent::Etype(baseType), type, bonus))); +#else +#warning error here! +#endif } ClickableL::clickLeft(down); } diff --git a/CHeroWindow.h b/CHeroWindow.h index 473fad101..b0566a79f 100644 --- a/CHeroWindow.h +++ b/CHeroWindow.h @@ -135,5 +135,5 @@ public: //friends friend void CArtPlace::clickLeft(tribool down); - friend CPlayerInterface; + friend class CPlayerInterface; }; diff --git a/CLua.cpp b/CLua.cpp index 36937fd1e..c4696b3e3 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -32,7 +32,7 @@ bool getGlobalFunc(lua_State * L, std::string fname) CObjectScript::CObjectScript() { - language = ESLan::UNDEF; + language = UNDEF; //std::cout << "Tworze obiekt objectscript "<ID)+" function in lua script.").c_str()); //} //lua_settop(is, 0); + + + + return; } void CLuaObjectScript::onHeroVisit(int objid, int heroID) @@ -158,6 +170,10 @@ void CLuaObjectScript::onHeroVisit(int objid, int heroID) // throw new std::exception(("Failed to call "+genFN("heroVisit",os->ID)+" function in lua script.").c_str()); //} //lua_settop(is, 0); + + + + } //std::string CLuaObjectScript::hoverText(int objid) //{ @@ -276,6 +292,8 @@ void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited) //weko.push_back(new SComponent(SComponent::primskill,w,vvv)); //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&weko); //break; + + } case 100: { @@ -284,6 +302,8 @@ void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited) //weko.push_back(new SComponent(SComponent::experience,0,vvv)); //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&weko); //break; + + } } } @@ -308,6 +328,46 @@ std::vector CVisitableOPH::yourObjects() void CVisitableOPW::onNAHeroVisit(int objid, int heroID, bool alreadyVisited) { DEFOS; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + int mid; switch (os->ID) { @@ -450,6 +510,15 @@ void CMines::onHeroVisit(int objid, int heroID) iw.player = h->tempOwner; iw.components.push_back(Component(2,os->subID,vv,-1)); cb->showInfoDialog(&iw); + + + + + + + + + } std::vector CMines::yourObjects() { @@ -595,6 +664,10 @@ void CPickable::chosen(int which) //for (int i=0;i CPickable::yourObjects() //returns IDs of objects which are handled by script @@ -743,4 +816,4 @@ std::vector CCreatureGen::yourObjects() //returns IDs of objects which are std::vector ret(1); ret.push_back(17); //cregen1 return ret; -} \ No newline at end of file +} diff --git a/CLua.h b/CLua.h index 15d4429d2..8c6b342d6 100644 --- a/CLua.h +++ b/CLua.h @@ -1,6 +1,11 @@ #pragma once #include "global.h" //#include "lstate.h" + +#ifndef _MSC_VER +} +#endif + #include #include class CLua; @@ -32,7 +37,7 @@ public: virtual void onHeroVisit(int objid, int heroID){}; virtual void onHeroLeave(int objid, int heroID){}; virtual std::string hoverText(int objid){return "";}; - virtual void newTurn (){}; + virtual void newTurn (){}; //TODO: implement functions below: @@ -71,7 +76,7 @@ public: void findF2(std::string fname); void findFS(std::string fname); - + friend CGameState; }; @@ -98,7 +103,7 @@ class CVisitableOPH : public CCPPObjectScript //once per hero public: CVisitableOPH(CScriptCallback * CB):CCPPObjectScript(CB){}; std::map > visitors; - + void onNAHeroVisit(int objid, int heroID, bool alreadyVisited); void newObject(int objid); void onHeroVisit(int objid, int heroID); @@ -114,7 +119,7 @@ public: void newObject(int objid); void onHeroVisit(int objid, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - void newTurn (); + void newTurn (); }; class CMines : public CCPPObjectScript //flaggable, and giving resource at each day @@ -127,7 +132,7 @@ public: void newObject(int objid); void onHeroVisit(int objid, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script - void newTurn (); + void newTurn (); }; class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc @@ -180,4 +185,4 @@ public: void newObject(int objid); void onHeroVisit(int objid, int heroID); std::vector yourObjects(); //returns IDs of objects which are handled by script -}; \ No newline at end of file +}; diff --git a/CLuaHandler.cpp b/CLuaHandler.cpp index 93e1f82f7..40e0a81ff 100644 --- a/CLuaHandler.cpp +++ b/CLuaHandler.cpp @@ -1,8 +1,17 @@ #include "stdafx.h" +#ifndef _MSC_VER +extern "C" { +#endif + #include "lua.h" #include "lualib.h" -#include "lauxlib.h" +#include "lauxlib.h" + +#ifndef _MSC_VER +} +#endif + //#include //#include //#include @@ -38,6 +47,30 @@ void CLuaHandler::test() // } //} //lua_close (lua); + + + + + + + + + + + + + + + + + + + + + + + + } @@ -89,4 +122,4 @@ std::vector * CLuaHandler::functionList(std::string file) } is.close(); return ret; -} \ No newline at end of file +} diff --git a/CLuaHandler.h b/CLuaHandler.h index 1c8f44010..698af5c6c 100644 --- a/CLuaHandler.h +++ b/CLuaHandler.h @@ -20,4 +20,4 @@ public: void test(); }; -#endif //CLUAHANDLER_H \ No newline at end of file +#endif //CLUAHANDLER_H diff --git a/CMT.cpp b/CMT.cpp index 31a5f3e5f..399c38d06 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -1,6 +1,6 @@ // CMT.cpp : Defines the entry point for the console application. // -#include "stdafx.h" +#include "stdafx.h" #include #include #include @@ -10,14 +10,13 @@ #include "SDL_TTF.h" #include "SDL_mixer.h" #include "SDL_Extensions.h" -#include "SDL_framerate.h" -#include "CGameInfo.h" +#include "SDL_framerate.h" +#include "CGameInfo.h" #include "mapHandler.h" #include "global.h" -#include "CPreGame.h" +#include "CPreGame.h" #include "CConsoleHandler.h" #include "CCursorHandler.h" -#include "CScreenHandler.h" #include "CPathfinder.h" #include "CGameState.h" #include "CCallback.h" @@ -43,13 +42,10 @@ std::string NAME = NAME_VER + std::string(" (client)"); DLL_EXPORT void initDLL(CLodHandler *b); SDL_Surface * screen, * screen2; -extern SDL_Surface * CSDL_Ext::std32bppSurface; - +extern SDL_Surface * CSDL_Ext::std32bppSurface; std::queue events; -boost::mutex eventsM; - -TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; - +boost::mutex eventsM; +TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; int _tmain(int argc, _TCHAR* argv[]) { std::cout.flags(ios::unitbuf); @@ -59,7 +55,7 @@ int _tmain(int argc, _TCHAR* argv[]) atexit(SDL_Quit); CGameInfo * cgi = CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.) //CLuaHandler luatest; - //luatest.test(); + //luatest.test(); //CBIKHandler cb; //cb.open("CSECRET.BIK"); std::cout << "Starting... " << std::endl; @@ -73,7 +69,7 @@ int _tmain(int argc, _TCHAR* argv[]) int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff; #else int rmask = 0x000000ff; int gmask = 0x0000ff00; int bmask = 0x00ff0000; int amask = 0xff000000; - #endif + #endif CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask); THC std::cout<<"\tInitializing minors: "<initMusics(); - //audio initialized + //audio initialized cgi->consoleh = new CConsoleHandler; cgi->mush = mush; - THC std::cout<<"\tInitializing sound: "<spriteh = new CLodHandler(); cgi->spriteh->init("Data\\H3sprite.lod","Sprites"); BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler; cgi->bitmaph->init("Data\\H3bitmap.lod","Data"); THC std::cout<<"Loading .lod files: "<bitmaph); - + initDLL(cgi->bitmaph); CGI->arth = VLC->arth; CGI->creh = VLC->creh; CGI->townh = VLC->townh; CGI->heroh = VLC->heroh; CGI->objh = VLC->objh; CGI->dobjinfo = VLC->dobjinfo; - CGI->buildh = VLC->buildh; - - THC std::cout<<"Initializing VCMI_Lib: "<buildh = VLC->buildh; + THC std::cout<<"Initializing VCMI_Lib: "<curh->initCursor(); //cgi->curh->showGraphicCursor(); pomtime.getDif(); @@ -115,13 +108,11 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->curh->initCursor(); //cgi->screenh = new CScreenHandler; //cgi->screenh->initScreen(); - THC std::cout<<"\tScreen handler: "<loadAbilities(); cgi->abilh = abilh; - THC std::cout<<"\tAbility handler: "<generaltexth = new CGeneralTextHandler; cgi->generaltexth->load(); - THC std::cout<<"Preparing more handlers: "<mush = mush; StartInfo *options = new StartInfo(cpg->runLoop()); -/////////////////////////////////////////////////////////////////////////////////////// - +/////////////////////////////////////////////////////////////////////////////////////// boost::thread servthr(boost::bind(system,"VCMI_server.exe > server_log.txt")); //runs server executable; //TODO: will it work on non-windows platforms? - THC tmh.getDif();pomtime.getDif();//reset timers - - + THC tmh.getDif();pomtime.getDif();//reset timers CSpellHandler * spellh = new CSpellHandler; spellh->loadSpells(); cgi->spellh = spellh; - THC std::cout<<"\tSpell handler: "<pathf = new CPathfinder(); THC std::cout<<"\tPathfinder: "<consoleh->runConsole(); THC std::cout<<"\tCallback and console: "<playerint.size(); ++g) //{ // if(!cgi->playerint[g]->human) // continue; - // CMinimap & mm = ((CPlayerInterface*)cgi->playerint[g])->adventureInt->minimap; - + // CMinimap & mm = ((CPlayerInterface*)cgi->playerint[g])->adventureInt->minimap; // int mw = mm.map[0]->w, mh = mm.map[0]->h, - // wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y; - + // wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y; // for(int d=0; dmh->map->twoLevel+1; ++d) // { - // SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface); - + // SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface); // for (int i=0; imh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d ); - + // int3 pp( ((i*CGI->mh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d ); // if ( !((CPlayerInterface*)cgi->playerint[g])->cb->isVisible(pp) ) // { // CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0); @@ -210,8 +188,7 @@ int _tmain(int argc, _TCHAR* argv[]) // } // CSDL_Ext::update(pt); // mm.FoW.push_back(pt); - // } - + // } //} } else diff --git a/CMessage.cpp b/CMessage.cpp index 82b5e43c2..9ae2c6b75 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "CMessage.h" -#include "SDL_TTF.h" +#include "SDL_ttf.h" #include "hch/CDefHandler.h" #include "CGameInfo.h" #include "SDL_Extensions.h" @@ -133,7 +133,7 @@ std::vector * CMessage::breakText(std::string text, int line, bool { int whereCut = -1, braces=0; bool pom = true, opened=false; - for (int i=0; i * CMessage::breakText(std::string text, int line, bool { if (text[i]=='{') opened=true; - else + else opened=false; braces++; } @@ -172,7 +172,7 @@ std::vector * CMessage::breakText(std::string text, int line, bool } } for (int i=0;ipush_back(text.substr(0,i)); @@ -211,7 +211,7 @@ std::pair CMessage::getMaxSizes(std::vector< std::vector CMessage::getMaxSizes(std::vector > * txtg) { - std::pair ret; + std::pair ret; ret.first = -1; ret.second=0; for (int i=0; isize();i++) //szukamy najszerszej linii i lacznej wysokosci @@ -239,7 +239,7 @@ SDL_Surface * CMessage::blitTextOnSur(std::vector > * int tw = pw; for (int j=0;j<(*txtg)[i].size();j++) //blit text - { + { blitAt((*txtg)[i][j],tw,curh+i*19,ret); tw+=(*txtg)[i][j]->w; SDL_FreeSurface((*txtg)[i][j]); @@ -253,7 +253,7 @@ SDL_Surface * CMessage::blitCompsOnSur(std::vector & comps, int max std::vector * brdtext; if (comps.size()) brdtext = breakText(comps[0]->subtitle,12,true,true); - else + else brdtext = NULL; curh += 30; comps[0]->pos.x = (ret->w/2) - ((comps[0]->getImg()->w)/2); @@ -269,7 +269,7 @@ SDL_Surface * CMessage::blitCompsOnSur(std::vector & comps, int max } return ret; } -SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * or, std::vector< std::vector > * komp, int inter, int &curh, SDL_Surface *ret) +SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * _or, std::vector< std::vector > * komp, int inter, int &curh, SDL_Surface *ret) { for (int i=0;isize();i++) { @@ -280,7 +280,7 @@ SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * or, std::vector< std::vector if(maxh<(*komp)[i][j]->getImg()->h) maxh=(*komp)[i][j]->getImg()->h; } - totalw += (inter*2+or->w) * ((*komp)[i].size() - 1); + totalw += (inter*2+_or->w) * ((*komp)[i].size() - 1); curh+=maxh/2; int curw = (ret->w/2)-(totalw/2); for(int j=0;j<(*komp)[i].size();j++) @@ -293,8 +293,8 @@ SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * or, std::vector< std::vector if(j<((*komp)[i].size()-1)) { curw+=inter; - blitAt(or,curw,curh-(or->h/2),ret); - curw+=or->w; + blitAt(_or,curw,curh-(_or->h/2),ret); + curw+=_or->w; curw+=inter; } } @@ -336,7 +336,7 @@ std::vector > * CMessage::drawText(std::vectorsize();i++) + } //ends for(int i=0; isize();i++) return txtg; } CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int Rmar, int Tmar, int Bmar) @@ -345,7 +345,7 @@ CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int std::vector * brtext = breakText(text,32,true,true); std::vector > * txtg = drawText(brtext); std::pair txts = getMaxSizes(txtg); - ret->bitmap = drawBox1(txts.first+Lmar+Rmar,txts.second+Tmar+Bmar,0); + ret->bitmap = drawBox1(txts.first+Lmar+Rmar,txts.second+Tmar+Bmar,0); ret->pos.h=ret->bitmap->h; ret->pos.w=ret->bitmap->w; for (int i=0; isize();i++) @@ -364,7 +364,7 @@ CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int //std::stringstream n; //n <<"temp_"<bitmap); - //SDL_SaveBMP(ret->bitmap,n.str().c_str()); + //SDL_SaveBMP(ret->bitmap,n.str().c_str()); tw+=(*txtg)[i][j]->w; SDL_FreeSurface((*txtg)[i][j]); } @@ -390,7 +390,7 @@ CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline + comps[0]->getImg()->h + 5 //img <-> subtitle + 20; //subtitle //!!!!!!!!!!!!!!!!!!!! - ret->bitmap = drawBox1(txts.first+70,txts.second+70,0); + ret->bitmap = drawBox1(txts.first+70,txts.second+70,0); ret->pos.h=ret->bitmap->h; ret->pos.w=ret->bitmap->w; int curh = 30; //gorny margines @@ -406,21 +406,21 @@ CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline curh+=ret->okb.imgs[0][0]->h; return ret; } -std::vector< std::vector > * CMessage::breakComps(std::vector & comps,int maxw, SDL_Surface* or) +std::vector< std::vector > * CMessage::breakComps(std::vector & comps,int maxw, SDL_Surface* _or) { std::vector< std::vector > * ret = new std::vector< std::vector >(); ret->resize(1); bool wywalicOr=false; - if (!or) + if (!_or) { - or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly); + _or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly); wywalicOr=true; } int rvi = 0; int curw = 0; for(int i=0;igetImg()->w + 12 + or->w); + curw += (comps[i]->getImg()->w + 12 + _or->w); if (curw > maxw) { curw = 0; @@ -431,7 +431,7 @@ std::vector< std::vector > * CMessage::breakComps(std::ve } if (wywalicOr) { - SDL_FreeSurface(or); + SDL_FreeSurface(_or); } return ret; } @@ -444,7 +444,7 @@ SDL_Surface * CMessage::drawBoxTextBitmapSub(int player, std::string text, SDL_S std::pair txts = getMaxSizes(txtg), boxs; boxs.first = std::max(txts.first,bitmap->w) // text/bitmap max width + 50; //side margins - boxs.second = + boxs.second = (curh=45) //top margin + txts.second //text total height + 55 //text <=> img @@ -474,8 +474,8 @@ CSelWindow * CMessage::genSelWindow(std::string text, int player, int charperlin std::pair txts = getMaxSizes(txtg); txts.first+=45; //side margins int curh = 50; //top margin - SDL_Surface * or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly); - std::vector< std::vector > * komp = breakComps(comps,500,or); + SDL_Surface * _or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly); + std::vector< std::vector > * komp = breakComps(comps,500,_or); std::pair txts2 = getMaxSizes(komp); ret->pos.h = txts.second //wys. tekstu + txts2.second //wys komponentow @@ -489,13 +489,13 @@ CSelWindow * CMessage::genSelWindow(std::string text, int player, int charperlin ret->bitmap = drawBox1(ret->pos.w,ret->pos.h,player); blitTextOnSur(txtg,curh,ret->bitmap); curh += 50; - blitCompsOnSur(or,komp,10,curh,ret->bitmap); + blitCompsOnSur(_or,komp,10,curh,ret->bitmap); curh += 30; //to buttton ret->okb.posr.x = (ret->bitmap->w/2) - (ret->okb.imgs[0][0]->w/2); ret->okb.posr.y = curh; ret->okb.show(); curh+=ret->okb.imgs[0][0]->h; - SDL_FreeSurface(or); + SDL_FreeSurface(_or); delete komp; delete tekst; return ret; @@ -521,17 +521,17 @@ SDL_Surface * CMessage::genMessage else hh=60+(21*tekst->size()); if (type==yesOrNO) //make place for buttons { - if (ww<200) ww=200; + if (ww<200) ww=200; hh+=70; } SDL_Surface * ret = drawBox1(ww,hh,0); //prepare title text - + if (title.length()) { - //SDL_Surface * titleText = TTF_RenderText_Shaded(TNRB16,title.c_str(),tytulowy,tlo); - SDL_Surface * titleText = TTF_RenderText_Blended(TNRB16,title.c_str(),tytulowy); + //SDL_Surface * titleText = TTF_RenderText_Shaded(TNRB16,title.c_str(),tytulowy,tlo); + SDL_Surface * titleText = TTF_RenderText_Blended(TNRB16,title.c_str(),tytulowy); //draw title SDL_Rect tytul = genRect(titleText->h,titleText->w,((ret->w/2)-(titleText->w/2)),37); @@ -539,7 +539,7 @@ SDL_Surface * CMessage::genMessage SDL_FreeSurface(titleText); } //draw text - for (int i=0; isize(); i++) + for (int i=0; isize(); i++) { int by = 37+i*21; if (title.length()) by+=40; @@ -565,4 +565,4 @@ SDL_Surface * CMessage::genMessage } delete tekst; return ret; -} \ No newline at end of file +} diff --git a/CMessage.h b/CMessage.h index 6ec362a3a..69c9c1ab4 100644 --- a/CMessage.h +++ b/CMessage.h @@ -2,8 +2,10 @@ #define CMESSAGE_H #include "global.h" -#include "SDL_TTF.h" +#include #include "SDL.h" +#include "CPreGame.h" + enum EWindowType {infoOnly, infoOK, yesOrNO}; class CPreGame; class MapSel; @@ -23,18 +25,18 @@ namespace NMessage class CMessage { public: - + static std::pair getMaxSizes(std::vector > * txtg); static std::pair getMaxSizes(std::vector< std::vector > * komp); static std::vector > * drawText(std::vector * brtext); static SDL_Surface * blitTextOnSur(std::vector > * txtg, int & curh, SDL_Surface * ret); static SDL_Surface * blitCompsOnSur(std::vector & comps, int maxw, int inter, int & curh, SDL_Surface * ret); - static SDL_Surface* blitCompsOnSur(SDL_Surface * or, std::vector< std::vector > * komp, int inter, int &curh, SDL_Surface *ret); - static CInfoWindow * genIWindow(std::string text, int player, int charperline, std::vector & comps); - static std::vector< std::vector > * breakComps(std::vector & comps,int maxw, SDL_Surface* or=NULL); + static SDL_Surface * blitCompsOnSur(SDL_Surface *_or, std::vector< std::vector > *komp, int inter, int &curh, SDL_Surface *ret); + static CInfoWindow * genIWindow(std::string text, int player, int charperline, std::vector &comps); + static std::vector< std::vector > * breakComps(std::vector &comps, int maxw, SDL_Surface* _or=NULL); static CSelWindow * genSelWindow(std::string text, int player, int charperline, std::vector & comps, int owner); static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins - static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly, + static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly, std::vector *addPics=NULL, void * cb=NULL); static SDL_Surface * drawBox1(int w, int h, int playerColor=1); static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30); @@ -46,4 +48,4 @@ public: // -#endif //CMESSAGE_H \ No newline at end of file +#endif //CMESSAGE_H diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 4d812052f..d3b36d04a 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -35,14 +35,14 @@ vector* CPathfinder::GetPath(const CGHeroInstance* hero) Hero = hero; //Reset the queues - Open = priority_queue < vector, vector>, Compare>(); + Open = priority_queue < vector, vector >, Compare>(); Closed.clear(); //Determine if the hero can move on water int3 hpos = Hero->getPosition(false); if (!Hero->canWalkOnSea()) { - if (CGI->mh->ttiles[hpos.x][hpos.y][hpos.z].tileInfo->tertype==EterrainType::water) + if (CGI->mh->ttiles[hpos.x][hpos.y][hpos.z].tileInfo->tertype==water) blockLandSea=false; else blockLandSea=true; @@ -138,14 +138,14 @@ bool CPathfinder::ExistsInClosed(Coordinate node) } /* - * Adds the neighbors of the current node to the open cue so they can be considered in the + * Adds the neighbors of the current node to the open cue so they can be considered in the * path creation. If the node has a cost (f = g + h) less than zero, it isn't added to Open. */ void CPathfinder::AddNeighbors(vector* branch) { //8 possible Nodes to add - // - // 1 2 3 + // + // 1 2 3 // 4 X 5 // 6 7 8 @@ -193,13 +193,13 @@ void CPathfinder::CalcH(Coordinate* node) * => Impossible to move there. */ if( (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->blocked && !(node->x==End.x && node->y==End.y && CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->visitable)) || - (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==EterrainType::rock) || - ((blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==EterrainType::water)) || + (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==rock) || + ((blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==water)) || (!CGI->state->players[Hero->tempOwner].fogOfWarMap[node->x][node->y][node->z]) || - ((!blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype!=EterrainType::water))) + ((!blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype!=water))) { //Impossible. - + node->h = -1; return; } @@ -214,7 +214,7 @@ void CPathfinder::CalcH(Coordinate* node) //Get the movement cost. ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].tileInfo->tertype, CGI->mh->map->terrain[x][y][node->z].malle,CGI->mh->map->terrain[x][y][node->z].nuine); - + node->h = ret; } @@ -247,7 +247,7 @@ CPath* CPathfinder::ConvertToOldFormat(vector* p) //Set coord temp.coord = int3(p->at(i).x,p->at(i).y,p->at(i).z); - + //Set accesible if(p->at(i).h == -1) { @@ -334,4 +334,4 @@ void Coordinate::operator =(const Coordinate &other) this->z = other.z; this->g = other.g; this->h = other.h; -} \ No newline at end of file +} diff --git a/CPathfinder.h b/CPathfinder.h index 8624148a0..25480737b 100644 --- a/CPathfinder.h +++ b/CPathfinder.h @@ -6,7 +6,7 @@ #include class CGHeroInstance; -using namespace std; +using namespace std; class Coordinate { @@ -54,7 +54,7 @@ class CPathfinder { private: boost::logic::tribool blockLandSea; //true - blocks sea, false - blocks land, indeterminate - allows all - + /* * Does the actual path calculation. Don't call this directly, call GetPath instead. */ @@ -67,7 +67,7 @@ private: bool ExistsInClosed(Coordinate node); /* - * Adds the neighbors of the current node to the open cue so they can be considered in the + * Adds the neighbors of the current node to the open cue so they can be considered in the * path creation. If the node has a cost (f = g + h) less than zero, it isn't added to Open. */ void AddNeighbors(vector* node); @@ -84,7 +84,7 @@ private: public: //Contains nodes to be searched - priority_queue < vector, vector>, Compare> Open; + priority_queue < vector, vector >, Compare > Open; //History of nodes you have been to before vector Closed; @@ -97,7 +97,7 @@ public: //A reference to the Hero. const CGHeroInstance* Hero; - + /* * Does basic input checking and setup for the path calculation. */ @@ -111,4 +111,4 @@ public: }; -#endif //CPATHFINDER_H \ No newline at end of file +#endif //CPATHFINDER_H diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 7d9503dd2..8fe38b6f3 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -239,7 +239,7 @@ void CGarrisonSlot::show() if(creature) { char* buf = new char[15]; - itoa(count,buf,10); + SDL_itoa(count,buf,10); blitAt(graphics->bigImgs[creature->idNumber],pos); printTo(buf,pos.x+56,pos.y+62,GEOR16,zwykly); if(owner->highlighted==this) @@ -344,7 +344,7 @@ void CGarrisonInt::createSlots() (std::map >::const_iterator i=set1->slots.begin(); i!=set1->slots.end(); i++) { - (*sup)[i->first] = + (*sup)[i->first] = new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y,i->first, 0, &CGI->creh->creatures[i->second.first],i->second.second); } for(int i=0; isize(); i++) @@ -352,13 +352,13 @@ void CGarrisonInt::createSlots() (*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y,i,0,NULL, 0); } if(set2) - { + { sdown = new std::vector(7,(CGarrisonSlot *)(NULL)); for (std::map >::const_iterator i=set2->slots.begin(); i!=set2->slots.end(); i++) { - (*sdown)[i->first] = + (*sdown)[i->first] = new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y + 64 + intery,i->first,1, &CGI->creh->creatures[i->second.first],i->second.second); } for(int i=0; isize(); i++) @@ -618,7 +618,7 @@ CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWin { SDL_Surface * symb = SComponent::getImg(); myBitmap = CSDL_Ext::newSurface(symb->w+2,symb->h+2,screen); - SDL_SetColorKey(myBitmap,SDL_SRCCOLORKEY,SDL_MapRGB(myBitmap->format,0,255,255)); + SDL_SetColorKey(myBitmap,SDL_SRCCOLORKEY,SDL_MapRGB(myBitmap->format,0,255,255)); blitAt(symb,1,1,myBitmap); if (Border) //use custom border { @@ -640,7 +640,7 @@ CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWin SDL_PutPixel(border,0,i,239,215,123); SDL_PutPixel(border,(border->w)-1,i,239,215,123); } - SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255)); + SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255)); } selected = false; } @@ -677,7 +677,7 @@ void CSelectableComponent::select(bool on) selected = on; return; } - else + else { return; } @@ -732,7 +732,7 @@ void CSelWindow::close() ret = i; } components[i]->deactivate(); - } + } components.clear(); okb.deactivate(); SDL_FreeSurface(bitmap); @@ -763,7 +763,7 @@ template void CSCButton::clickLeft (tribool down) { state=1; } - else + else { state=0; } @@ -772,16 +772,16 @@ template void CSCButton::clickLeft (tribool down) if (delg) (delg->*func)(down); } -template void CSCButton::activate() +template void CSCButton::activate() { ClickableL::activate(); } -template void CSCButton::deactivate() +template void CSCButton::deactivate() { ClickableL::deactivate(); } -template void CSCButton::show(SDL_Surface * to) +template void CSCButton::show(SDL_Surface * to) { if (delg) //we blit on our owner's bitmap { @@ -819,7 +819,7 @@ void CButtonBase::show(SDL_Surface * to) if (abs) { blitAt(imgs[curimg] - [( (state+bitmapOffset) < (imgs[curimg].size()) ) ? + [( (state+bitmapOffset) < (imgs[curimg].size()) ) ? (state+bitmapOffset) : (imgs[curimg].size()-1) ] ,pos.x,pos.y,to); @@ -828,11 +828,11 @@ void CButtonBase::show(SDL_Surface * to) else { blitAt(imgs[curimg] - [( (state+bitmapOffset) < (imgs[curimg].size()) ) ? + [( (state+bitmapOffset) < (imgs[curimg].size()) ) ? (state+bitmapOffset) : (imgs[curimg].size()-1) ],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to); //updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to); - + } } ClickableL::ClickableL() @@ -988,7 +988,7 @@ void CPlayerInterface::yourTurn() // CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + i] = tab[i]; // } // //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t2.bmp"); - // CSDL_Ext::update(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap); + // CSDL_Ext::update(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap); // } //} //water tiles updated @@ -1082,7 +1082,7 @@ void CPlayerInterface::yourTurn() cb->endTurn(); } -inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid) +inline void subRect(const int & x, const int & y, const int & z, const SDL_Rect & r, const int & hid) { TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z]; for(int h=0; hcurh->cursorMove(sEvent->motion.x, sEvent->motion.y); } - if(sEvent->type==SDL_QUIT) + if(sEvent->type==SDL_QUIT) exit(0); else if (sEvent->type==SDL_KEYDOWN) { handleKeyDown(sEvent); } //keydown end - else if(sEvent->type==SDL_KEYUP) + else if(sEvent->type==SDL_KEYUP) { handleKeyUp(sEvent); }//keyup end @@ -1904,12 +1904,12 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj) hw->garInt->recreateSlots(); hw->garInt->show(); } - else if(castleInt == curint) //opened town window - redraw town garrsion slots (change is within hero garr) + else if(castleInt == curint) //opened town window - redraw town garrsion slots (change is within hero garr) { castleInt->garr->highlighted = NULL; castleInt->garr->recreateSlots(); } - + } else if (obj->ID == 98) //town { @@ -1919,7 +1919,7 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj) SDL_FreeSurface(graphics->townWins[tt->identifier]); graphics->townWins[tt->identifier] = infoWin(tt); } - + const CCastleInterface *ci = dynamic_cast(curint); if(ci) { @@ -1989,7 +1989,7 @@ BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn objsToBlit[i]->show(); //SDL_Flip(screen); CSDL_Ext::update(screen); - + /*timeHandler th; th.getDif(); int tv = th.getDif(); @@ -2007,6 +2007,7 @@ BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn BattleAction ret = *(dynamic_cast(curint)->givenCommand); delete dynamic_cast(curint)->givenCommand; dynamic_cast(curint)->givenCommand = NULL; + dynamic_cast(curint)->myTurn = false; return ret; } @@ -2029,14 +2030,19 @@ void CPlayerInterface::battleStackAttacking(int ID, int dest) dynamic_cast(curint)->stackAttacking(ID, dest); } -void CPlayerInterface::battleStackIsAttacked(int ID, int dmg, int killed, int IDby) +void CPlayerInterface::battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting) { - dynamic_cast(curint)->stackIsAttacked(ID, dmg, killed, IDby); + dynamic_cast(curint)->stackIsAttacked(ID, dmg, killed, IDby, byShooting); } -void CPlayerInterface::battleStackKilled(int ID, int dmg, int killed, int IDby) +void CPlayerInterface::battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting) { - dynamic_cast(curint)->stackKilled(ID, dmg, killed, IDby); + dynamic_cast(curint)->stackKilled(ID, dmg, killed, IDby, byShooting); +} + +void CPlayerInterface::battleStackIsShooting(int ID, int dest) +{ + dynamic_cast(curint)->stackIsShooting(ID, dest); } void CPlayerInterface::showComp(SComponent comp) @@ -2150,7 +2156,7 @@ void CList::activate() Hoverable::activate(); KeyInterested::activate(); MotionInterested::activate(); -}; +}; void CList::deactivate() { ClickableL::deactivate(); @@ -2158,7 +2164,7 @@ void CList::deactivate() Hoverable::deactivate(); KeyInterested::deactivate(); MotionInterested::deactivate(); -}; +}; void CList::clickLeft(tribool down) { }; @@ -2170,7 +2176,7 @@ CHeroList::CHeroList(int Size) :CList(Size) { pos = genRect(192,64,609,196); - + arrupp = genRect(16,64,609,196); arrdop = genRect(16,64,609,372); //32px per hero @@ -2180,7 +2186,7 @@ CHeroList::CHeroList(int Size) pospory = 212; posmanx = 666; posmany = 213; - + arrup = CDefHandler::giveDef("IAM012.DEF"); arrdo = CDefHandler::giveDef("IAM013.DEF"); mobile = CDefHandler::giveDef("IMOBIL.DEF"); @@ -2214,7 +2220,7 @@ void CHeroList::select(int which) draw(); LOCPLINT->adventureInt->infoBar.draw(NULL); } - if (which>=items.size()) + if (which>=items.size()) return; selected = which; LOCPLINT->adventureInt->centerOn(items[which].first->pos); @@ -2223,7 +2229,7 @@ void CHeroList::select(int which) LOCPLINT->adventureInt->terrain.currentPath = items[which].second; draw(); LOCPLINT->adventureInt->townList.draw(); - + LOCPLINT->adventureInt->infoBar.draw(NULL); } void CHeroList::clickLeft(tribool down) @@ -2379,7 +2385,7 @@ void CHeroList::updateMove(const CGHeroInstance* which) //draws move points bar blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+ser*32); //move point } void CHeroList::draw() -{ +{ for (int iT=0+from;iT<5+from;iT++) { int i = iT-from; @@ -2398,7 +2404,7 @@ void CHeroList::draw() if (pom>25) pom=25; if (pom<0) pom=0; blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana - SDL_Surface * temp = graphics->portraitSmall[LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->subID]; + SDL_Surface * temp = graphics->portraitSmall[LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->portrait]; blitAt(temp,posporx,pospory+i*32); if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE)) { @@ -2446,7 +2452,7 @@ CTownList::CTownList(int Size, SDL_Rect * Pos, int arupx, int arupy, int ardox, pressed = indeterminate; from = 0; - + } void CTownList::genList() @@ -2460,7 +2466,7 @@ void CTownList::genList() void CTownList::select(int which) { - if (which>=items.size()) + if (which>=items.size()) return; selected = which; if(!fun.empty()) @@ -2562,7 +2568,7 @@ void CTownList::clickLeft(tribool down) } void CTownList::clickRight(tribool down) -{ +{ if (down) { /***************************ARROWS*****************************************/ @@ -2604,7 +2610,7 @@ void CTownList::keyPressed (SDL_KeyboardEvent & key) } void CTownList::draw() -{ +{ for (int iT=0+from;iTcurrent->motion.x,LOCPLINT->current->motion.y)) { - which = i; + which = i; int newAmount = min(amounts[i],creatures[i].amount); slider->amount = newAmount; if(slider->value > newAmount) @@ -2735,9 +2741,9 @@ void CRecrutationWindow::show(SDL_Surface * to) cancel->show(); slider->show(); char pom[15]; - itoa(creatures[which].amount,pom,10); //available + SDL_itoa(creatures[which].amount,pom,10); //available printAtMiddle(pom,pos.x+205,pos.y+252,GEOR13,zwykly,screen); - itoa(slider->value,pom,10); //recruit + SDL_itoa(slider->value,pom,10); //recruit printAtMiddle(pom,pos.x+279,pos.y+252,GEOR13,zwykly,screen); printAtMiddle(CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures[creatures[which].ID].namePl,pos.x+243,pos.y+32,GEOR16,tytulowy,screen); //eg "Recruit Dragon flies" int curx = pos.x+115-creatures[which].res.size()*16; @@ -2745,9 +2751,9 @@ void CRecrutationWindow::show(SDL_Surface * to) { blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx,pos.y+243,screen); blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx+258,pos.y+243,screen); - itoa(creatures[which].res[i].second,pom,10); + SDL_itoa(creatures[which].res[i].second,pom,10); printAtMiddle(pom,curx+12,pos.y+286,GEOR13,zwykly,screen); - itoa(creatures[which].res[i].second * slider->value,pom,10); + SDL_itoa(creatures[which].res[i].second * slider->value,pom,10); printAtMiddle(pom,curx+12+258,pos.y+286,GEOR13,zwykly,screen); curx+=32; } @@ -2818,7 +2824,7 @@ CRecrutationWindow::CRecrutationWindow(const std::vector > &C buy = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Buy,this),pos.x+212,pos.y+313,"IBY6432.DEF"); cancel = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Cancel,this),pos.x+290,pos.y+313,"ICN6432.DEF"); LOCPLINT->curint->deactivate(); - //AdventureMapButton( std::string Name, std::string HelpBox, void(T::*Function)(), + //AdventureMapButton( std::string Name, std::string HelpBox, void(T::*Function)(), //int x, int y, std::string defName, T* Owner, bool activ=false, std::vector * add = NULL, bool playerColoredButton = true );//c-tor }//(int x, int y, int totalw, T*Owner,void(T::*Moved)(int to), int Capacity, int Amount, int Value, bool Horizontal) CRecrutationWindow::~CRecrutationWindow() @@ -2891,7 +2897,7 @@ void CSplitWindow::close() deactivate(); delete this; LOCPLINT->curint->activate(); - + CCastleInterface *c = dynamic_cast(LOCPLINT->curint); if(c) c->showAll(); } @@ -2908,16 +2914,16 @@ void CSplitWindow::show(SDL_Surface * to) ok->show(); cancel->show(); slider->show(); - itoa(a1,pom,10); + SDL_itoa(a1,pom,10); printAtMiddle(pom,pos.x+70,pos.y+237,GEOR16,zwykly,screen); - itoa(a2,pom,10); + SDL_itoa(a2,pom,10); printAtMiddle(pom,pos.x+233,pos.y+237,GEOR16,zwykly,screen); anim->blitPic(screen,pos.x+20,pos.y+54,false); anim->blitPic(screen,pos.x+177,pos.y+54,false); } void CSplitWindow::keyPressed (SDL_KeyboardEvent & key) { - //TODO: make manual typing possible + //TODO: make manual typing possible } void CCreInfoWindow::show(SDL_Surface * to) @@ -2954,12 +2960,12 @@ CCreInfoWindow::CCreInfoWindow //atttack printAt(CGI->preth->zelp[435].first,155,48,GEOR13,zwykly,bitmap); - itoa(c->attack,pom,10); + SDL_itoa(c->attack,pom,10); if(State && State->attackBonus) { int hlp = log10f(c->attack)+2; pom[hlp-1] = ' '; pom[hlp] = '('; - itoa(c->attack+State->attackBonus,pom+hlp+1,10); + SDL_itoa(c->attack+State->attackBonus,pom+hlp+1,10); hlp += 2+(int)log10f(State->attackBonus+c->attack); pom[hlp] = ')'; pom[hlp+1] = '\0'; } @@ -2967,12 +2973,12 @@ CCreInfoWindow::CCreInfoWindow //defense printAt(CGI->preth->zelp[436].first,155,67,GEOR13,zwykly,bitmap); - itoa(c->defence,pom,10); + SDL_itoa(c->defence,pom,10); if(State && State->defenseBonus) { int hlp = log10f(c->defence)+2; pom[hlp-1] = ' '; pom[hlp] = '('; - itoa(c->defence+State->defenseBonus,pom+hlp+1,10); + SDL_itoa(c->defence+State->defenseBonus,pom+hlp+1,10); pom[hlp+2+(int)log10f(State->defenseBonus+c->defence)] = ')'; } printToWR(pom,276,80,GEOR13,zwykly,bitmap); @@ -2981,21 +2987,21 @@ CCreInfoWindow::CCreInfoWindow if(c->shots) { printAt(CGI->generaltexth->allTexts[198],155,86,GEOR13,zwykly,bitmap); - itoa(c->shots,pom,10); + SDL_itoa(c->shots,pom,10); printToWR(pom,276,99,GEOR13,zwykly,bitmap); } //damage printAt(CGI->generaltexth->allTexts[199],155,105,GEOR13,zwykly,bitmap); - itoa(c->damageMin,pom,10); + SDL_itoa(c->damageMin,pom,10); hlp=log10f(c->damageMin)+2; pom[hlp-1]=' '; pom[hlp]='-'; pom[hlp+1]=' '; - itoa(c->damageMax,pom+hlp+2,10); + SDL_itoa(c->damageMax,pom+hlp+2,10); printToWR(pom,276,118,GEOR13,zwykly,bitmap); //health printAt(CGI->preth->zelp[439].first,155,124,GEOR13,zwykly,bitmap); - itoa(c->hitPoints,pom,10); + SDL_itoa(c->hitPoints,pom,10); printToWR(pom,276,137,GEOR13,zwykly,bitmap); //remaining health - TODO: show during the battles @@ -3003,7 +3009,7 @@ CCreInfoWindow::CCreInfoWindow //speed printAt(CGI->preth->zelp[441].first,155,162,GEOR13,zwykly,bitmap); - itoa(c->speed,pom,10); + SDL_itoa(c->speed,pom,10); printToWR(pom,276,175,GEOR13,zwykly,bitmap); @@ -3074,7 +3080,7 @@ void CCreInfoWindow::keyPressed (SDL_KeyboardEvent & key) void CCreInfoWindow::deactivate() { if(!type) - ClickableR::deactivate(); + ClickableR::deactivate(); LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this)); if(ok) ok->deactivate(); diff --git a/CPlayerInterface.h b/CPlayerInterface.h index 9ec210c0b..eed2971ea 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -206,16 +206,16 @@ public: { primskill, secskill, resource, creature, artifact, experience } type; - int subtype; + int subtype; int val; std::string description; //r-click - std::string subtitle; + std::string subtitle; void init(Etype Type, int Subtype, int Val); SComponent(Etype Type, int Subtype, int Val); SComponent(const Component &c); - + void clickRight (boost::logic::tribool down); virtual SDL_Surface * getImg(); virtual void activate(); @@ -249,7 +249,7 @@ public: int count; int upg; //0 - up garrison, 1 - down garrison bool active; - + virtual void hover (bool on); const CArmedInstance * getObj(); void clickRight (boost::logic::tribool down); @@ -342,8 +342,9 @@ public: void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector capturedArtifacts, int expForWinner, bool winner); void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving); void battleStackAttacking(int ID, int dest); - void battleStackIsAttacked(int ID, int dmg, int killed, int IDby); - void battleStackKilled(int ID, int dmg, int killed, int IDby); + void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting); + void battleStackKilled(int ID, int dmg, int killed, int IDby, bool byShooting); + void battleStackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest //-------------// @@ -380,30 +381,30 @@ public: std::string getCurrent(); }; -class CList +class CList : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested { public: SDL_Surface * bg; CDefHandler *arrup, *arrdo; - SDL_Surface *empty, *selection; + SDL_Surface *empty, *selection; SDL_Rect arrupp, arrdop; //positions of arrows int posw, posh; //position width/height int selected, //id of selected position, <0 if none - from; + from; const int SIZE; boost::logic::tribool pressed; //true=up; false=down; indeterminate=none CList(int Size = 5); void clickLeft(boost::logic::tribool down); - void activate(); + void activate(); void deactivate(); virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0; virtual void genList()=0; virtual void select(int which)=0; virtual void draw()=0; }; -class CHeroList +class CHeroList : public CList { public: @@ -426,10 +427,10 @@ public: void init(); }; -class CTownList +class CTownList : public CList { -public: +public: boost::function fun; std::vector items; int posporx,pospory; @@ -481,7 +482,7 @@ public: void Cancel(); void sliderMoved(int to); void clickLeft(boost::logic::tribool down); - void activate(); + void activate(); void deactivate(); void show(SDL_Surface * to = NULL); CRecrutationWindow(const std::vector > & Creatures, const boost::function & Recruit); //creatures - pairs @@ -501,7 +502,7 @@ public: CSplitWindow(int cid, int max, CGarrisonInt *Owner); ~CSplitWindow(); - void activate(); + void activate(); void split(); void close(); void deactivate(); @@ -524,7 +525,7 @@ public: AdventureMapButton *dismiss, *upgrade, *ok; CCreInfoWindow(int Cid, int Type, StackState *State, boost::function Upg, boost::function Dsm); ~CCreInfoWindow(); - void activate(); + void activate(); void close(); void clickRight(boost::logic::tribool down); void dismissF(); @@ -535,4 +536,4 @@ public: extern CPlayerInterface * LOCPLINT; -#endif //CPLAYERINTERFACE_H \ No newline at end of file +#endif //CPLAYERINTERFACE_H diff --git a/CPreGame.cpp b/CPreGame.cpp index 3ace59cc3286ed815ac5459817c7693ef4066e3a..ba9645a5ecf90ac0af4c0f0125bdd8a43720b421 100644 GIT binary patch literal 64834 zcmeHw`Enb{(dXZshOWsZr4Ebb?+Ow!&7hL&Xds;%GM*RP%EGKFy*b;DfhHb-bAY<9PNJV5cq{(T(wMucGs)Gjgb zpm*I*y=NxA347tN**OpImggyGV5&=THU4>A_!QGwwdw(zgK0M5z z5>*kDsLq=mt}>JoH}cP={L^eKQH90DFa4+$3?P{Cc3i4PuZfWla;+z$4@u z^i-Kc(%@&}M8k0+$-CAlZV3OVRWokEkKNNZc!A#O1kvaqKIm1hAfqt@X5wdqA!tt` zLNI>*sRzLw4XAIfM?oXt9^Tk+!x)8J5h}4uIPKrZT$|~B8{M>bZsWM$1KI8VU1jFy zpT7P4)6``rB6dXGo6-DM|8{uLZQg{V52LslhaVR%qqy4~R0sXh!ae`Zyq~%qwD6gG z>N&mH0np=>6ZIgO6LY=ATI;imbfZJRngAOPOHlfx=qu_iiU=q&4cqq);Jm1>b$fe>B(RHsC zUI!N!Z;s#ZUR)?S&xoGj`E$j;Q3K6WQ?rA9)N6bWA3)3>!d@%7##_HjqzUE)ih!9J zR<`?J!lAITZy5>xJ!_+9JNOefFFWB3WGKEJ(%79!u$k*jeIsNHua~LNl&v1N8u9Qp zq?c%)I|2VBYH(j9YFszbSEkBu(o02sP;YkcO)cW?lRg0u-Bj=~P9Ar@T6ZC`Bh z)`}=I^4}q}JYXYYS zqY;biRQ9VWSK%HfPEO^N3K)jU1FHm8yJwxK6%IExFm+vh-op@KeeKjObNce@O^0QW zz~@zbKX`1l?h%H~*h;=k7!|+>ZyNm#Eg(vd2r;_zy3=pQ!5|!7LFHB|{5W&h4u|3P zF#I)~Sv2pUBO|t%w!6J}{;CO89>tavc6sn%h&Y&4*mP^n~le!0#{{LWYCs6JEW8FI=@1|z0@Aw4H7 zStU!*?yJPs8DJ;Epp_Vda1$p8E_v zMH8S=Et`c>)P+2<{F}KDUG79?6YR^A6zbm!42b!y+3VZhOl5A))nWGg!U^;}Emw{T zMpP~$TT846{5I$3$F`XovqbC8!$~g`MS43RR6Q2aSPF;!7?U@t@k;ZU+Ja4tA2E_f2bxtn!(eqLbC3wGGM28 zf^P&m|Ij>L5wtfpW@johTNP6cm89NWd!7c_b5qR7K-F8iZEV~`kc{xUGJUoS%X#m3 zVQ>HS^i0*$x6t{IYB$y7`$1WQ?@zN0j<|y!*C^`~w!%uNJ3GuYmR1wVE&wCjPwxWm z0QBGEy5QY;21!_wkK;zF$?`5Ze4TCZ@m)Y_5Trh_3m}_Vxr0b+*||~QAp0+&TEtq; z4C5A7_i^+EmbK9?th+FfF*m~R&|1J+dlbqd>>7(v(KFun%kU=ZRc5N0dMG{N}Bd?H*OHx=mK1zqLo$Oew6P=mS zpug<@jWs7geZa9!DqV z2Pen5bAd5^S*^(OY;J9Zf83jO8f=rKmMWbo$oTK7BBbBgoseNHS`k|lZd4olpP6pd zVmD7MvfiVWvr&7r>Cq5nxbi|EP60Obi7x8_X3_k%IPeHTF;bWKC!sI#ObU};muk!$ z{O;!&KU&ac@S}zDZ;Br=`E%SK65D|M1j>|4KWlhuk%jvk|2^eiH@Ki8pH;CWgA*xQ zlv|u-ciV5JY(>@j1Cw=3*mA>}oL_d>>eu%s;^XQHF%Nm&+_t|RGD2}(seOZkTx*CMb)Y_R;%;1 znJPB)=>^-E*K(7B$tq6~a~m2Ti|4)*nxrLpiG_Mpum z4@Y|6qW(4y_2nfnXAEO})CIU;o`AlSgZDE0DC2-TygjC0_ItMoqfnmj#O`C&iXZ7zX2pWMI@oIn`tF%~*n4E0 z+%t=>_n7)DU};v6W<;W0Gxk}UagPGWK1(z1G4)wKpc#yK_7U50c-8E^ABE@G=%RoN z9*75f7-9h+_tuCE(ixa*;gQLd%Q!X&#FtZ^VhE5_#4lUXH)VANidRQi zi+*6hIp57V_^7gOl*z#!w?<-z-lpXfsmPh&PeBFqQm_$JYHSpeX+budAFp5*(su}I zYLnpck3ij#7>DE^{gd`7uYu=l8z`oe+!Y+6HzA3D_9AfT?>1>8M;JA~B_)X+*1|{k znD>pwe4U!@_06<4AJA_L*GQTGuq%)xbU*>2i;F|JXZzitu@ziLLj>I+zyzz;FU_b! z);6OccygS^fQov|dVO*H{%B|aoiYvkvj7<|3@jHIB7>k&6jWZJ`c`9!oI&`tX)4p} zxdx45DXZEGD?De9L+ zDpX%sx}KR^T3Dk0)vgWQ2AE7~aE{jIl?^fsxnl@pDX#8+^bqTKt*1 zOwrHC18YMrl`9U?=lGlJGt)3upEZ&#(m;~&*U~Y`#g$j4EKi)aJ@Z!VBt*-}NK}>> zg{Jx$VJ%p(96&59OI4#V{XJLbq|4T*<<}6>oN&-HG*1{Tk+x!^!s!$tB`Y*WFqBjW zO~;d8LktJ2ytswOsV;@^1jR)&J`|T>x@g$hxBKr-_RlU(_upNd|Lt^twmw%|ovEs* zVA`Feig6wo&`cIW8)^GY-jQ0G-%49G0AD3zW~oY=Pr6;Y#EPpj)i+5h~M+IY63gI-9q`~*;Iy2o`ACXrmRA7@Vh!QEF*r zoT(G6z^*v5yTSiRH(I?*y^#l<7jC!RW{>9f$}__f>l%KtJzdloBlmFuviO#oB?ihm zNLC?aCjwV8m9a61?Gic$@DQ{aMOl7V1K5lxBkxcM%)5+Qt*{415>G#QJpEM4(@(lY zD_Yfl!m5^9PBF8HHo>S7m^kFzat0>m5bGfHqxoTo;!|!_EV3z1o&=`sdr@_?Tv}bf zqq-Wy6ma2(t#hL?>}Bq{gcqg=6Y1#cbF-&bds%(?vI<`v_RsiyM*7nlTtD@fa}hZR zdETSu-@8zKt)<0Qmu4dZSbJ&9J`Gh+{Zv#xO^oU%4^`QB2j%Zq>FB`#pts!$$HCSrUG+7O54W41DLA^m6 zr2)!wcuX+A74)EZpp-60{myNSrNcMUIMA#FjF;bdrgu{Y3wRBxXqnn1_PF;;`L7eD zX^tX&*2GC5Ii)~tJtJVIo#tiHVDAl8uBBbt3hr@KDM3|Bl2K(4@<~?XW?F(bD{pM4 z=OYHfT*xa;^9xHyqtVlKyi}MPg^h@DORTpEJL?1cF6R+Da-2`585^dd!$WjDM;$2g zU@}x*YVjt>5zCFGBcfvc6TU4YpWwuhsX}R#(@DR+tK8^WxB0D`Fg}g0QXpmLL*g5% zwRLjbFU>*2jZE+avqcP@EJEzEA-);shHW;Zu!p<6qw=IS>iMK)+USjK!&)WW(_kH~ zEs22q?x1m*?F@SR7|P$$=&r9~l9`OR3O`9T3CyjEBuAw*78;z&hh$+aeet z3|hnH9R;RREy$Ww<35{0S=V824zL}GGHv+>N7?e)<9&01an^;F%B9PAuI#eWBIlaR zEJoiJaY>;$LG%UAY&}dsZ8@ABpq&ol0E;Bdx zTd%N|YB;W?Ska-y!?1S~^Fb(mNqYy>Vfx6seBQHm72bg1Nh^jJY&p)%wjsKg6y3hV z2V3>P^~MGca<$}DWqNz>FDIwxJHISkb_dgzFl@W95%){@P`SLR5{J&-?e3l&p1eaq zAU|WngbpHK-pp^IKX7UrE~xtID*X|AoX8<_!yVZ7PJL|eotz%N-j)*pL?lyNTKwI) zS6rD*;Z$N7JW=avojp%;AY1B=ze0uT&eH zoW46fJ{0ldRv%S&=R4~D?K|qe`Hs3LUftla%sTZdKeq1qcho&g)Xhu?w4k&T0+uB7 zj2T#+W(6>w1wQEK_s$H?-iEh&BZCVDA}>ELx3s!seF{0V+twA@jzd*#q9PcaBsoW@*4k zaRYJ!%RTFftGS3}9IegI6J2b!f}7$ngMngBa9yFvp#=REIZvjyTVI;JD@4wy4K!V) zV6){_c9#70uiR2mWwz(w`=YEYl%NA<9Sn8K&ocV3TCaTssFmvK%8EK(WP_Z%q2Vwf zeI4xGN}?LzPIi?zVn%2E*Uh2zZ~B3^r-$2r!+zD_!O_9_D|HrIzCWvUM+-20IVb`@ zv+)nKPH*;h``rON8$&{bJi?E!r9mx;jdCj`ZE|-9?PzlXxNXet;pmuBhZt!>O?B8# zdGSI~4;!EHBm{aOKeRPs3GqiPCw2gkQCg*0w*F$yXFB=%xa6QOL6V*VrdeA0&RENS z&1xj}6YPAc`N8~9!scsO^z?=ezfz*9+zR4WsqFK=Gtu}88g<5+WP;Kflr~{;jd+{1 z^y7eQwB3ZjHRexLCKKw^gqt*xU8STqm{-!@PpHh)J+(G-^2wFIt7+!*Q=1mHYi(L! z?BB<I*uxzns=wJj)za*Q?&1frK;>D?nI& ze_8Nj;I4Ua2_Q|l#>rd?d_2lNXn0e2f|OZsZjQz_&+UcSm(IeqHJXKM)wN}_`+?Q2 z$Dm@SFj&NR(X0-K?s)_UO~rrtHS7#N)K}L&Vy4AZ*h1vQ685U_NB3@OD=Zb?-^5GT zM4iIPy(VP7`tByykT}IqQD4W>^EYUs=9*YuMf`WB34ej>&cl-cSmQ#@ADIDdYzAX7 z&}_hQQuFm{p8Ue+RV6Hm24DVq22z`Rq$hF_qI!`tGjWj8V2py?I(g)b)wCz-(Z3s5zVaDD?tr!8v&v1O+ z7RocjIpPS-JH;u>M?y(ZXD6h=ohKS7Xu><%eYvb#>;lx06Ucoy1ghu^p4VUAVj^`+N+dF?}}8V7whe zF14<^fm-S)zf^7MMFQAiL9vyUM6thS%OUw^^R^QwitT2g@o>uUP*-z|Y8AmlNQ|p? zZ7v%%!-Sc#5?za=2bApCsWE28yZ*jIOr}deOoYp9?|4NtsNan>E^^l2^U6r~rTPAA z|BY9Mb7A^TF$2^&v_~0H5?iap0lT-lwqC8P2#NfVc6erI>IB&o)V0vz4MQAulTn__ zA1a7}JpH~$zgp5kMIBNI0eeOi_)ykMglum8FVPj{Q`p5ahO^Q%8i-^-Xil%y97;xk zDPlvTCVjwG2EUjH8jl6TUo_=s@l9~I{sLQ(8TRJ3(dmyy7F|vrb#i?u@93-{ea^vO zx_%7$C7=_OP`N@#E$7U-;+KY5a_&IUxL%PNoNx9;q(Hp?T4a-K09nar}J z#i7!$W3aKoA<(c~=^aOIeM9Y(G3OaCl=?yY;wS?>mzx8#oJouU`ArN;apk);rn*b=$D|adAt144!Q~BptA6!2 zI7t`!KI+OelwWX$UL8#%(4x9#qM~IyWs5^mQr7=waE2vMa~So5xX=4Q({Nx@@Jv-M z5#ahr;04IumL?B+&%G>z*L%TZ$9tB+YD1@VgA(!p}Oq z3%}E-rH`N;A&ita{%?=DZiVJTWb&)TGZA9o&V4 z@t7_A%0sd6tB$b3?>cbsojJ$L7F=ne5=Oi5c<-Duu)bdqC3q>rEa4ty5IpHmp5hZz zBK$fdY~FOS7knRd?*TqB9tXqz6>dhra2d&x?hD32f4J!_n6`rF10+lT`Z+p>aVQ?6 z=SYSo zZejP-Hm4?tTU1b`+n!e~Wf$1Z3T}Y{GNFwau371)0gxpzb@LT2xsX@Bl#bx$Ykv^- zDjp)(xJB&c)rBlKr-zpkkvDbQ8$~xgL>Azn;t&}PM!3B}g1r)7KGbj=ntiEkdPR{Q z7eiJu;tadm2oJ%UtRWQHLQKUHqAJ{4h%0|(1hHFj6;#Nuz83zmbMY$$FjJ_E0W}4L zJ^9-4sQe*h3G#v6R3w8gFh+|0DiK{A+Uv zPtpxCm-L6j+W{g=DLo0Y1a!iUV0v>i&CgAdGvo=u@eIr{aw4Bw<`oy=zVdO#eWFv4 zQ3#*`;_$D&KKzN`Hv_!889v-KJG~}Ke7gO=q`p5#Ve8?42cP@!BOng9`G3OhJaU5I z%jMS=LNZV?zQtkg4hnXIL34EbDO^}sAl~gllsQ91H_FIB6-Wu+lHzM@W~Y3*ku8^y zSn)J}_(-zy3eACD{FfS-e%$EdB0Af0as-znLMc#@*`GIHJw8(d*CXuS;_jXxj=~CZ z2jY>yBkR)zz1}q6x3GX+oL&S=N7Di0PG4}Aly$tJ#V zqAp}K!r=$X!ttzOD+Y6P7&fq~fV!LU8eI&-n_J9QbcPj&;*s(57DtW5jPZtt>NNly zUBD~Rmf}QCWd_Uf<~5u`o)W7}FSM7t(`JE=?MJ6#T#u32Fj}0R%K@eckZf{i@kj)x z4tg!|YA8Z--OwJ631kP_%#}>K6UVW{)D(*%p4TZqhqu4BqY8H+m;%F~HgjPyYp)ZqU zc;E}^7+>bDT3>o$2+`shO2nQWLkL2S{oar|Njl_Rk_-pCkczQIKm@FQ?F}iNp+Rl% zF+}|JFhPV?N>ZUOlVo_{3+WhN=B~QDR5yfZ@eC!jco;**c9IOLk)(m%BndE33$Y(l z0I09vl(38lDw~V9?2b?(qK1;^y^)^tUZ^~JZ)B)>FKj@oeBtw)T8)1TO#Z12@^3`_PuTF;`jdEjo?Ullzr}g?PfkY2*<-by3{J666ir~?2I(W3WxWoDEaRG{1uvBR_ zreVy!T`x3GV7Om;n0~hrL!x;;%206nNkZX&7IIR5%hQ z$e7UL+zawsC{cIE1eB~gO0-gv5`CGZ!~ zdjt(EILmHenPItqxa;`72k<3@kKg^}VAnH4_kco~)q4Ey@Z?Mn1pyzp*!D=ba1}b{ zG3rokqJJmT(dpUWJ#=j8+~a(7+%8#R#34?F6dattd40J3#=}UK7@yFg7ns+?T_bBN zu+eNaE|@(L%=5(B1uV_527?5gp%iY65M0<^p4wSXudqitd zl(3N-a{h$36HPHJUkMv;+su5)?4D7O7d$yjoFwoYD*2mQ?B#fTL>RlnJja(}Ou)H? z#F?3tM-1ymLR})KBDxtM>GPo#t`Nf;a_j~WuBS5Pr+KWEXsIe$mn5c4YEgeuES~b6 zd!Yq~&lye&*+im9-&Qevq%{7VeUq{ovGW&u1PfwCkZZ=oO*P=}5**ou506trnkOP{ zJxC!b2Ygf6LQYch_=l~JNM4KGdzn+n2bsYavC0(rP83vx5$+}dlFcP2okY9j?%Nfo z0N|ymv@Q>eoKKV&U@3mpyXL4D4{#@h%|+x(9c|X;9TzfU07-UX3yx%Ikri-Cd`Rh%C!PB zx<%g^7ew~K2_%E3I3o!zKH;<8=y&|moF~b{Ir2q%8a<<3F2hP6%qU|Rd?ebWl#^lt zo6oEx+biDLF=^P(@^2!hOkeR4fm1ru1+}8GAq0J60D>8bbE7O`er0*(BPHk}Na4_{ znNEBKJ;8D+jF*T<_|t`kDJPtE*=5qKlDcHLkHc&2#m85Ri{{uw4r0lMh;7O`tBWaV z*e9FX<(0_{rbB|g3e9l6J0o@Uge``|SJ4ilfP z({5seND9tq=GcOggBM02SQJINfx49lkx@cl&}PD*DT@Wai`EI@W5~6OwaSPWfutgy zn$HsB!&26wZRrXEU|2d45L0-j(V*lCBCn1<^SKn(KogHh2Mga2l7*{x2QrE15KPa1 z&TUO~cn;*K7=pty)|pOmG+naMmWa$p528S225ALkCamC60SzddEPenL7m&P+q;Jd1IG>4VyX9;yIrDi1(QfsZGRZ%_5yUiN z35;oaWo13vhJ0PYMFlIX%M&(nNfeD1XswpJn34-GO=i3d8?-tWXxwFEDZ12ys84Uu z0GPbVcbxn5=`Ct~)1XFg(BWy?w#vjj<{Y@P$B1x`1jk=UR4TKqpnky-?Uk1}97aHD zdfdCV{3Iyr0)>JXzXO*S0%aLjkvtj7^2;TGva+;h;y}v|y9s*>*t7f+C)ig(R4y>| z7TL74{p;y4qcJ`%U?rT0D4pZ!jixrLvQ@|Gf_{h|^S0x3n_Nr_C^oEc)1XEls3vcj z8+iUKmB3-Q-`fjgWVFYK2zFS>jYe~byhXJ6oaE!w6Mxw@Wsg29VSoS? zQLio|8b|}A9n0AQDdZ6?|AC-{+$LjK%h@Gf1J2zjEHaQd4ZdSf3AXFG*qU&vRtPP{ zN2k%xg`3G#3Y|Z@dxSud=1quwMLGvT2@vd*?RtY@Mhq13WhUqPs6;BVG)E;+ zDXdSbE0`T>t97KybV1KP=f$2g?FUF4&nAjpM+RGV&1Ygsc$$_40~r7$UB>hgvV)a*T+hs~~Brh?MBv%6XRrab^37h=?<23WC4br~lqUC%Ys3m0+g zW==-}j9E2*188zk=IG@FPASOj&!Pm!f?%Tokg_HdfGYUNttc*VUkvgv_26A{n!f7w zeYGvS5y0>Iey;IEKseGt>@(|myEOh$c!oZn;g71hfd^ROweZnN%Dd>lmkl|!3*A&F&k`WU!G~AJsXAQb8 zECt*2MdI#b3cEi8JnwSY#CJu@olPL#sDh@BopO!(_sw!bcx_)MchtjwPSnjWLqHo> zpmyjQRA6Gl6CG^(YKWa{a}7ltbwf=R8^qoAEBskNXfWhXnv5UfTR5p77KV*_{pBnB zc+;rYR^8)eqgG#bkGIH13>-K|vMjBr{_5&0eL!vZaOpqTnlP7cE@>Yj?(|W4ZS58P zxM?5~ihiJy{IC^Jl$Rl}J7^c!@P-zZN+1n3U8zt~T>2tc4otc9JPj^DCC}gP20U7A zG`az~foQ5`i?m-12pop)v&|1d2ORAHUFzCSxD4BfrQOB8bU3mvDTbQ-;zwccR`_3r z1^Jx=greW#Gy=z7M_-}#`n_=&QR(CGZn8$e%NuflKe3&J{FV_j!eHcMQdjMMbcG$b zN0X#Z$?<%%O=*(1N47=dc=AqaMI$mWNm^`wjq4y7IOaNO&1yw^5RK_m-diK3pH*nY zFUtX$lA*rzjgATXo#fkno!_F$%(r~Fwi7K}eWP&gcZI9ZxVhPBM!U;KT9$5Ls?7Ws z)^om!y~MsP1%@F0y(DYx-%k&A=@5%cip)!fCj)W`poJ+Gd1!(WX))ELsjnm1dnm*7 z4MNvXPfkq(vVc3JblgX$mFf1ftN?Iesr8S4q{^lmBYt5*D{Bn7tdF)&{nXw*M^w_w z0F2KK?gLcv%aVoX6fepiF0488@{p%1(>(o{#;ANzYh(@<$iPYfC>i)-U&O1YzB_zB*hYfVOFszv9gLA25BT#^N(u0IXgu_tcH}zl_`Gn zj>4*Vko}LB;@dC7U>RPSi7?Qx&{7QKe$oU6Z*f?stbKUhCu?7WIZNA@z|lne`}YIn z$t}TP4TlCM!(dI~2um@L{jvlG2VLy#jUoi|lwq+<+p3dD!ukYQaGJ%`$hq91;2~V1 zpz-xdL41L<%*)7c<;4k-HK4{+foM{=oFFW>N!mzGH_2g< zWsU873GdVN(ey@vpoOiyz$I)c`lt>o;Igr&@u}JU8Kfdi^fY6T-U&9_H-R~XmRUQN z?m4dFC@fCs%tck~>m;406#Gd{Lbc3q73{PlYE33%cGFJNVlLP=w=>%l{G;hKGvD#9 zb{RKoOIdOGvFsEaelS1RS0?0Ve(U7sGz?AiOpVYormZf)=aP~^tyUoRqW&iqK?U}M znYOw_soN(I!h+^~u3`DBVwlb|FM9~y3c;6ebv5|*e8xdW8cPR+aU9T@*swt_X$eL{ zowQWiZRR)RZ1qHN3eC{00m|x*&<=&|@N{mXTFiv+H=+gUxMc2Y93ObOhARoU#m6a( zm6t0N@vvT9!PIWzCctx8*#Vp%*Bdm}9}BXMxQ7%-^rP%A;Iy)_$sP^4UPF+_8bwqj zkrgi|qiWKb@U%rCF=ZXV23K16KiK1`$&T?kFBMG?PH7WjQ$48>tvXRNWH>#k5w18< z6Ji@ZsS&L@Q8Uf}dQwwf^@*BetK&&6NzKU`fid;8HmIU$!dweSdv~h13TJXB#5sil zaN$0oN?hpNf^5R&w^cC9xyHy$qp6rm=>6gOL4Ix8fju*6 zd5T)!-99=!&aaQ8JBaEnKHK~E^Yi!TC*DPuKI;Fxjf(H!{QJ4{L6O4llb0(W!-JDw zw)Lt-Dv8^1u5jO4Vd>rNV?OLfw90GSsYbw6D*hK(sBn!Ya6KEqS zhYLpjCT4?$ljOq~I9WzmIN-z@-%6a|ll_e3Bz4}{UtGLub_Y%5s!Nmh){cTy7rWsx zF?k-WB!OdLWl8j4QFohN4s;~#g=4$YEAY^$FLRV9<#fY|1f(`glesH{HASNi;fV<} zP?FS@L&=h6pyZ3O`HGw~tK79%qd>E!3Hmb>NQxTLDHD^z^^Ia^no$nEcpQ^?jbDwJpFGSo^{ zQVD#cdd4;|MkSOq;RgQLM#@HJNeemz$AT{$FeR{Q1Tf&I8>ku&mK_b`N;ad(3WT9qlAr364*(^R@aRDhjXDtN7X&{C9+g_c9B2MyFB5VZ_@7?P`OX~JF>gE3QD z=Y}+)T6}UU4V)B-<#2N7GjKrM>Ux$q^O>wk&NQ&NNSY->7EMcOnyBF91TlmZH6;*o zNMQ(|B2Cx=WqYo!a+#t_fTOT2SIsE2BD=*aS*Co-S}>Ynd=q2FYFQ(0$c}HOY`m1U zq2pqF10+njgP;sLNhE`Qw2_xJ>a4&@6cC@O;JhZ1i=VID`o?ljZZ>uxA`!i=Y+ym? zFVC}RoY@S;oRaX)qW~JtrlrMO;oyREndN<^^m`_TB*_(9Cn1{YYq_{-abAyUI&Z2Q z-*!T1a~l``_n5}>C3<}GDRIt4K%D4f5Xh1B@vZxUp4;>)pRyj)bb1twZ`Tfibfb{) z$2;e#B;@X@P1-gk zfEYAgz7ZOSJ2>eqM^T79yjF1^m4eirC>cGKVD5}lT z1z+|jl8vLAL%zw2hoIa7naEh~6}CU`sx)Zz1Ti2k)@SCSDwrO5tlE$5Btig9;77PS(xXTsx z{PU8c>?<>K5z_{Ml7rXgwcNn5V`UaUuB}WZFhanfNlkInt$0 z7LxM{N+4R!7hbO7Cffnn&(%eeh+}-Jl+=#FDOaT4pXO0Gfk2rKW3#O{B(JokPkWUS zA`EiAY2vzc6}jFjY&2>fdvmJ8CZp4>6^=_%jhIu+Xe||_fA=6rD1C{;qI+G8)Y;LM zjYUh&7t(Vz7RBsHnZcRLTe)N$l3a<~5wbbWRw{)hVXup*aVEpBba@_6F&e`tV}fu; zlJ>7(Ew+^6&eXdO>~z*Z%7NaHaI^FXzB0p^F#^mgI3NkJ!KE*_$3P3u0DI(WwHPI| zL%}#PIbf3^qKU#1$##YTHUVTPH%^>2+V1w^gdi(SWKihE7-fcSc}TjX9kMn-SFqla zzv*XUPReyj6!{2U0tEvNB)hwhkHkrv{!;7O(#^;nukVuR6|2;XC+{^F^>%s zLv70Y?imcezAhPS=7^jl<(U;73)mYd$XG7dAS&sVA2>Y;ZT2z+^qR#0N9PqSm3px% zewv)+FfGEvDKGhqY4H7Ig6V^Ot{y5oAzU416fWE`~87$3G>{d1_Yr2?T?!> zQIN(cb2A=35R>>fbO>8Dr~OWcYvS$@v211nY&PFDv6)J}6q41W*F0*?Dc`bFdk+1a zwCsct)JjH}|NQF`alhl2Exs?16*y=>;zr914GbZ6G$aWSF7H&x7jijt!B3| zjieg{?YK~YxrHq`DvEmUfaS*m!V|>9%s>{L84{CDz9N*#nN8l=saPKUhK(R3uy@uF zSFlVF10DCOI;BemtT5nrYKVB>yzM83>anJPezT$UAIE_D(;1*gK$ru5KjaF)TS%XT z&i}`;VEO4R(332au|W6L{^RIhc{=^F6FA`*p#8o7IO12ILj1p=nT^lR>Nu-ftZh3* zA92O6RG3%`KU% zC&TLr>ZK4fWCk6BnWWI34710M`a-mjTzd>!9H~bAJV8f3YA_b!v^o|iK6K;Zls2Qx zIw05m_B4+!S~CcDv2BS}KN9Qh;{Nu}&a5k0e_MyI2ZyaKGaBq_c5=6`530=hi*geG zAAVM%QE7{9bVVGpPbSlm96#8!z&mN9Z;{`FK> zsf}qkW7W%}?LE_B&c9&Qm*mr85-fbHLoxuW@+&e(Gx+X1|mA8i&^J zp}xl9^j+%fDZ2-dV>1^1{W|J#?s1peod&1D+H>h;HzBCtV-%b{A^QKbf*UujTLtI3 z$0|Z|=3vI{TKv29;5hVuKRq}Ov)@S%jzjDB(1YV}vU)I2203suD}cY9sVDwV^C@(i#L@ZiT2X;Er=M?}B?IQ4mrw>bH;m|V%0*X?IX(vqtE!hO!G{nCD3=F`im z+BMOE)OhN%A3U1#nFaz)3ck|{{cp2eUEa7moa@WDR~N3#)wSws-UZ9{`-|$TxnbG& zTbV?%dF4p=13jnj=>SAuW)J+0E9ip$h;>STw7H3ro14?YQPjJQ!;##zApgr~cXe&q=9C5HL_I6eqRP0nvlDeAT-!69Qy@&Onp~czFHmHRJ=s5_j0YU;B5Ud)lW>z~U6XGeJM>B(vcJ@!d zJO8BDx7;H#GApaPx?y%?ZP3+~84(`-4i68H|M!3Y*X+UU$?V73quF0(w`X@|+p}Y{ z{n-oq{KM?-?C06Z*?s%wf6o5Lto7!_*^SwAYxSkQ{n&nwzkT1vxj%b%c5(K(y?b|d z*;+lZksjG!&zH2_vo=?kymM>z)P8{eUF-cp*YE!9Rrk#ugAeGQ+0QYXB|q=l&vrHc zef#DIYx&52KQXxObXd7z23-|ZN|^7hv}_9HGX>B@%Q}^S|SGzI@}_S zUv~I?W_>BD2JIvJ_uSgNFm3a~`r_}G_IbDaj=%WyOZVMFd-}@$ zYV~>3IPi*vJ$8~Qw9xV<#HZqHB6&di_cn?KI} zSbcMCJ}NpybN||A_+vNLy>71hd#A%6Fx?s^tHYf}Ub11@-@HN%JY+?y323EhCePe#!Rl{l4zq>uW zt&U%)_}H+If5zwS8J3K{z$lXbnf)J}wP)|(e`U`4w0jHw8m9$P|J*p>PLC>1gSQq` z*tVJduEH{OaIW2&ZJCCLyP)T}*+c8`)dK%Ryq{qUYCC0}-(r?SeIPx5wb7mzyoPj@ z@+7W$%Vf|c5&1$QksPEA9Bg--i)F;_ipPd|)W_ML%dBK~tH+CH7JY3s#>aOLN@!Ha zK<03yZ)-L@N^tz}DEJO8G4(iqKT@))gtR4Nm~(;_B@a#ELFWj^ty6F_(4ynuQ7m89 zsx3};@29U(#jUlb4DS5zqD{k!xV6Nu=hHKjaMxqtB0eMU@eWoNZ|Irf`&?&jq~${P zq)+PpX`5+$mozx!6F3D8mdNw;ow(AO~5ZR@dj%#uplWyjIf(_lsl9F9^`geOpX zw0p*%__pX`ERV0Oel%O~xsAxmZ^xcHZ?-(x@Dy&@3gn*kmgUf4m^$J&M!Ulv?eXlI z%?sOe@R3TtDr53f<0r70y)-?qea5?nv!_OJd}ny~xzWJA+#Q24o*p-9-0z;>vDF8@ z+PC)axUEm>_uOB^n^b(`y!j^3@Ez;>2O9;Cn&;W0jFGnO?N>III7m|C7Mot_<!`JLJOvyZKhx9x5Bbzj+MR-qbqYvG}LMC_5RL#0b=|4pktJy)NM zb7pordC{yc^|bV^ee~n@Jl20mUg_2ECy6;}xES|B-)nfGd315%@j1@3#Frzf)hm;* zx|J|idmpv$F`Ygy8}#}4Q0NoXV9b(M8Zq91V-K4?HFnFy{qgA>?y1_sIcm!|(BlGFuM?)F{$l#&xPAM!{j|mj zzRq*kY|x30SLfhZLFkRveBEA5pX+CxTrZo!JH~|vpTW4z6U8o=p1p3E!y1Jp1w+C| zYySB=@#=OjN|qxnWrU5$isDPM?QR!n6L7e`FY#O3fOGS8oTS3FREwM3rfF=wU)v*p z%fHn-;@=EUUQzj&-m%-kcJ==yB$w$dt@m{Pgk5C`s<4GJm8rl08e{J8P`j`=&p zZ$pB8q&(i+ou%U&^w#fsy@?YfySoGXSB!kmtPMEu{jD9_Y1*^5J$n1O{XS_=E?IQ< zST|PNi-flvQ-?F(@mV6V>(1~Si$hMC;eMjmVa_zXg@`J(_a2wgZm-*WTt>TPwtY+r zoFkEiqnCn^0GGeRl!C7%1186JfcxCDr*M=J%cH?dy#=K3u3o$N-- zinF)l&!>1AtczJIvF7=!eIhDUuiwHCa$Ab0LL8lU*&pO@qQJD|Ti-8Y&w~BK>_@fR z-?ElyepcdW*X84Rzr3qhz;SD-S#LG=1hS2jSGjE7iaah~o4IBxy>=wQA9Px zl-o};U$@`D^9tCo-9#1gdQrI8GF<9S-vg@G?8EKY6T|my)9jh~!_4h_^QOS#LxUh_ zu_`6*TOZ0~xnlj`laQ}ME(896M`!laU!~6`|B2Z|i<8zeciGdYln=ztoREXjDMvOa=+i(Ebv%vTF(x1_Ui<9x!3r+ zh2N$%7rQxmUg!qJK70pl>^VN6#?GUMf5!*yyq6 z!w_qXgF{=&+2KNs#Ma}rXRu`}7ovAa-MtiPl$7gB z(Px-rYy9-7cv%7rZxO}nE2T=w=ltHyyHxPRWPBL)lp-j<=Z&zz&vqR zpJ8hyJ{ASeG;EFGlxjT*&&uhBE>ebq{EJe14o8t%{kQb4cq4Ye#DBGYnr`b@XC9rM z6DJ4U+5b^~i1xE&eP5SF3@^sxegSJl09$kly|81RfqQ;a=O&wm<{Gz)>)XwGUOwj3 zIRzH-9kr+oBLDpIbB8q=6#FLqSwegCg-T^(X&`i&a+v_&?YzAf449|tdZ3jJ-Lti z2lK353;aIeDb`)S6T4^Q<9qMf|Bt%00C}s=y1pLSh>rO?=0``2H}ZA@W9%d#pY9bklMRS$l|PL4Qd}tp)37tZY1S zFMWP#`x779&SQLo2T<-h`5sdVFEiT2n!?wMzQY>SMnC#0j(ycfi4V34U(rt;lO;RB`ghHf?`zlE;*IOl9B(;V z-!`u$hHPd;R*05L*OxS#))tR6dK=23QXW;`dPiH&>{L8E_(8NmC;N$v*nK6x8J+UL zcI9swFFi3o0I%bLWkq?+_^j!;2i^X7dzM31O}%|*t^eHl8Ln$L=?jnE|NH#$ zStu`JyE>bD(|o~OUCv|P(*Xy+&SgjZ7wf1WEf(;+lR|u7?;&*K_naHIKz==T*4A7tf|nH7RaHw(cw!cq66!#@4?G-c>a6v=XLV| zv`*Xa`0<9VQGPHllzrG$o`!A5=5g+iHA&8@^3y)vv-tM+wx>wO|6PNkpC5F(TX~+c zh_h!Uu@2>Avnb5yadkp04vcQy|HZ(3t}BF zx^Fm%j`R_oa$R+?o28$w8HfF}Wz>GK0ocK+kGE?W1HWLQhCkj~HiOHHxh{kMeZ%kJ z;GW#!KIT1h`>9c+#`@*SSU+PhJLepXV*;Ng)-&Ys4kvWs{}$|=&6~pOXAEvm7as<% zw>h0G#wTW9yy8O1=NDGM_(!vkHUM{Ev&49YJ>Kyg%pvI6SNy@GrqAK%j9t?(WV@f5 zYZ`cFecht5IIWts-JflQ{C8<*f-8u5hxWZOif6S7~h5Kk=nP1~EDhqZ6j z8(jXwA~N@q=Gd8=W?zX=|K7A5v3bs7JnUAz#3)0H5Vutw6s!-v+IA|hh`@KYTA zy+_sELixHo;K-})@a=qESJT%kcl1}~^_m<%HAivAd-Ihh=UE&_?9>HzSWTAe%nN=w@c)VH1#j35(>G_*I<2&soqW>Zam``LV%2MjQ%hs}09U}J; zEhX)HCS&-3UONNMV%!@YSNmFG&v=$xI%I_U5ne$f`~SX^^1GA^x=c%8~nSRAL;f``Jw+Z z*E*8Z*a?Qmv8~wJawW$&Xf}30UCL_><9K*#_-6&^n8+N(N;3B;Zbj1w2V?JJi{3HM zQ~Lc$$3?kE*UI|74{xp0G6d3KSOllXa#*0E~eIx8;`0tE)Rb( zK4!+p7w2mq+vnp3hf~Kj2b_i037_H%``dHsS)-LF<{7z$M0+-_w`)%Iz30aZeJ1$Z zxeNYO7E+ewy@j_WTzgz& z+|yd_pVT^}q;m_p(%J;qm3m50wtX=@JzPIbqc{vl-6s6CP?qtp^m_a{91c+2HO9>-Ah z#-ZP}S$M1l36&R^4pg%h!5_|iFYB0YQ9vl{AucSC&Or}oh_EnKzE zqqMBtrfFHvI$Mt^yobHm?a7ItWbdFo-^?2=Ev4t7L1Vod_GY>c4ZhOark;89ioS7} zsFaLeBs;tGLB?9swrv4J3Z!=(F0}Y`xT5dXU?O@M^U0DLaE;Atr?B;8K@GqCc9Y9B z>$;uzMb>62E@ao9_{uXo&U#mH}*2Pc{L2R<~JQX zL(-NpG^S(p-g3*>_f8`cH_e0evBo0GIfnX$QJwwSqlqSaWQMp{K7Z$t10qD^qXv$~ zqr`Q->SlJvSQD^XeQpq*>sAQ=bcV=%T47hCcvwx31 zYQ5^r0*}PNT{B)bO9$jn7W)Tzm&mD&Eu<>0_T5;YDAo+$cueY%z2$ZA$=AQX=$DuP z{Omgu?B{uG(&>}m^PZgZsAYZIe%OU{4J|(XX@F0EIsl*kWIlV|TLZRLc5r{{YV^fi z#yN9Ux<$Y4%PUJuc42ydHJsjG#^f^{NeN?ZbtxD<|W8L=kdS+ZBeK+$t zuRnU(-bZ&lXeLpYf?6RjY+Z=NxPL)zY0NZR>Ky;L)$P*dy{%=la-3#~rYcf>e(luk z6Z6DB>Hha@J65H+lF71GAI@`uPFo-BR4cDAR-c;vHzwyg=km45tye5A$0~ax+vtS# zDF}hK-!IuSM}<|V^-*K>r$fN%PXkzO)vIBL!L{poM|Q%A3rU zXZ|){Q>^2W4%bh2tM}{NUSBpoYUMWM_QZNc^W{Er?T54WkXL|5PIaxEFZ9Itn!j09 z;X$(YyJgx>>qWI;N1TWTzGY-L)ABw0PU}hj=ABrh@y%)b#`h-ikG%h=UroR46$43l zO27a-?BM%uyKp9-Rgh_AEPq1pZCMZC@ug*Apsk3QdrZdXta*xiTJICToBlQto%Y*W zM~M=Q4Q7a}YkbY?tpx?#r;GW}YE@YQ9`|ImKG1l~SCwdZOWzAtMLve1$gQ@_mb=dy z{HE0sRNdVADDV-h`;h!;8aS*M+`~M?J^kn_SmI_C;m4z{{k0U|3wQBJ-@Lwjq{u;P zWzV1wGU7A~RVRd47iG(x)R? z6!=Kk?{95)g3NB>BXOe{aNr%juyr0;Mg1sV9xtB+iPZtV<0-S{%EKow+=-?KGRTyu}`(-^LVm>d9>tP^a}Z4 z?^2MjA|0}qQzS$09v00n8}D)MWY_HU2lJJTpJ&(%--ohg^bE&d7l|UzYdXEc8aedRHF-{%dwHuhJ9+VW23db_f90yY zRKg|+D>Y)kSwaaFHc#Dy(AKTt<|vo(F-;>)v)5Vg)LucRF5DZwe3rFLiO`3ozW@~- zBh-y4Yrza<21Q?4x8|NcndFH@KN%yrpO07U=X95+61*65aqFVu1eF#ofk81 z1;+T%;q(9VIRHN^{9p5|Kk1J81hqV%w>rHHY@Cr{Me5$YV(m_gW$O-)8!p>*QH1V` zZj3v<_@ttb#2&(nTQ+u_>{~WIQGB9F%$2-p-`#>vj3}O%0%btA>}_s3c744{n~P?D zv7w%mJQcFA4b#Ue{kUjX;!3qeuG(C%;_SKzs`5=B=EQjWX`J$FKQE=q-*FBfixA;i zz`=bU_wV8Ch=pimxXoAk7rNFio0kpqs!;9sh_T1Vt;+c=Zmc+OXHWjkr0j;-#|yJR z*iP0hlW%TK4=jp1_6#d8%wtx3;1BlqD}xspc1;ev2KJtbrj+FyrWis&i(s2m@RXqYX5ngYuxdm zzJs>w_s*>c?cPhySbYTDFS6H-@b$n9B&!GEi_3;3D0#lCHh!wf7v(B&bEA>7+~>m3 z3!5A1!-0{q=Gxq7A2dg6X(b<%9Kx3--Ky4$2Ie+^9g_=A!6P4j8vc_`QnW+R&g^ZC z?EGEf}|?ea$J$Dl5ckFnp7;*8VE@u$(su{lX*^{ZMjv zXn?SKn;q|hQ7Cl6;g9#HBOdR|BOdSi5s!D{h{r2$w>f-%*=x?vWzhZ3wmf93-?x)v zz5&+qYy0<=No3Z_G1tQz_rhx$m)!H$G2bs=)40&MHDBc_9v+2n42*o(9DVaOjk`B8 z?(!9ab}9QS1m6eHb6*3uR=}lwk7{LVNzd|x-A~8oe`G$$@9f`Wv+M4e)RFb^{d4u0 zBZXQuoH0L!tbV<-yk}wrU7yk9O@eQ6ft6-0Lxh7OL zK+cNUHwk!Zo-+CS{aoXm&7s|O_@1@zc{^RjsVi=Kx?&khS8RMTlXKQ)aGLo2Eu$$K z;G~TTjIJM;y?+bWL47jSpc(PP5?-quF1c^`a;%e`3uZS1ul9qGs;>-Bj}15d8c9B8rWexNt~>8%e^AE0E%0(n)S8pX}g7-JIEu;Idi%)CZkXG4YF=%d%#*ti_5@AsZ*#9 z-yU<<=$qqD9?#EXQjM*KBG;N`x5M{($RMFYLVKj)Sxp}yXRL7ADE>Zf^Vq})7Y%xk zk76_33TJ(P5d4%C;WpiSS^aIZkmtIQo5#zAL&W(7<4M*19D=;%ZL}gierNi6vJre0 z7CieL;m2%#Ake|#6!~(+?EqsUf$bgyc74_E}N&pPE9`L={8L9-63ss zG+IGWWPC;@=_WBc7 zuQtSUIY&`^fq!~X_zwm#Gi^aE2(`uy==Ee>$TxxKA*ek+rR_zsE|3P$tk%K(`m158 zOKUYut~>lyYb@X0ZBb-BdZFa4EweESkH_gNGOavk$%EBq%qfcm7Mi^ZK5r?ZzjZjb%!(AJ?IB)etYMjSUdsC`WLo^!Jfga1Z6EcxD7YKj*3LQ%9v|imFo#?q6J&W(&v=>4 zFB`k=&vCgbG*?Z2*wvz!&)B;iNtW!eK^_n8seR5+s1$4DX5w&t( zV|oO>jGm9rRyrhB9g^QK3|qc0!C6SJG)tYxvUkVENz<3;COjf`qu80^M4{{X+|$%} zI2?*+BpufBI2|vp%k`eiSFKBHyyN*ecKr!wZH4W-_KbZ4&P3`vvZwRko3~fl~=JEgNQc1Ayt)gEzEIAE2%L~>pbe~q4(GhNUVzd<_K_+sg4bh^$1+C zFYENmE7{;`TIr2VoSak!DqN?E5nel8dIEZC4_kUI;yu1gP*Tg3fXiIpQO8=zlvBldWm0{EJNkKlkFG{!SXC{$4Zk`pGUq)MeKD$4!Ek%MW%0TUOo&pY`D?*bQuD zIM7ILld&?fhaS?qwa_h`0eEHq{?ch3qP}Mr`5|GKrHRfJF|T+t^X=F35jo5Fz&_(q z0FCEB=;=-;X`K3zHuP2NX^ZZ-oVYBOJEd=u+{>1;LMHQ|w&i%AUZ;s0Oz{h7fw#zK zIDnf4^o(`l^7rxV;W5t6ll`IA+ot`g&t3B0cZI$Q4ndl7boRVK;-~7pmt&@fj#+Q3 z_UW~-SPR@RZcZqUi((5KMGC0P2%BTHsFmi_BX$t)#;q|?b6DQv7*?~6Qg5My*za&Z_l(UaPH+>Y5ESPO^LzF$ zplP4Qi@rXxxeoVrZKb}5;C(#O+tn3&BWr0Gwm+IBT|QG*U3gz;s23x>U7XNY*r%4| zEIF~0+Tf&JVa{Gq2YNoURQ`gKO7HJ; z!}KfDuH;z}XLOBRo`4lEp@*rZ7-wKV>~_NNN{75Jc_HM_P1p9?7e3kf13ImUW-Zs~ ztM}-({h0a1PwdAt%x)KwxT>VB4g<3IiD|)u$)qqleSGeHAwLlrdu6`3@9RKMmrlH} zOWo}-V{iG{WGu%M)BM~X#_kY#nCuZrV}y+$4>-$IcxmD*RmGX6PsZmEcBtlapZ)4Q zPDY-e#9Yqh(`mt)dEb8eR5)okb&0%g`tWM;o;>ACo%b8<(Ut0P8cnjsI2c7V?rJj` zrjz+RCqAzW$YWKc!mbvVKe6V(u?1t;%;qFoij3bV0Go zy4c$y!Q3XZ#{{aSB?+1<3H55Ao^3v%6N28dk`4&%eAG*g==%$jF-k73(+d zSM?pXHv=a5RBr|}T6w$~(70#paojfpBKHCN5bc{bz*gZ4VX=m@402A!kEUOrclHT? z$FoX&9jN^gMc(?gjB8t&&t$Z0rJj41%PN*qEwRF~s>G?~trCg9H(y`rJC8u}J(219 zEU7%h*x@T9M&!r({HU_w(zt*dA3dMH{4dV zpS8S>_Q{TzNydLa8Z}`)Ss!?KiTfYrip_PwF|ZgYOa}>+~RetR=rcU`-Z!Q&D5j~BY#-^})G*p>wp(&&eo;QQ}v@rr`F2c$oaFy$Kj$M z4c=_UJ!-+;w_v3vZ+mv=fXG1BC}o_$M9+p?8ui>#FvU4zQ_KH;fvh|GMd{M@pDsNf%8W@weNfaes|5ocy8K1SL@>( z_>&HY_v|-bm~MDvU;l*tgD+LdL+7H0+kDsgBHUmd)g_^)N6sGDC*_k1o0(_eXzp!q z(^2si?**Q~@8O61rq+&DjQoqeAq@KIh#&2norGcOFd|5_^C~I7nCHyi86ybdk^{(c z=ZEY`exUuI=c5hdX~*bXju<=;9M_&zya~5ZMFahV%mu&XzL^Ws#LuVQ?k2PO)!Imx zuyP>lfQ*1+v;VM9{QI_(Vc&D-Mm#tJPXZcoX4kpJEg-c;$uYgty?3nZX&HYqTEO6u zr$?qSeH=IjzJVXkrW+7M8KP{C_xBCo%*fY2xs}(?ULEvJNxdTVFj-dh&gTW!|cL8p?lx4w)}IC z{g#b*+j?Pi@00i=P&1PENX7`T?Aw!{tjCkxkNEE5Tq|F(k%$#DqX!f80I_m@GEaSEo_^gHG{i`VLSlnNA5Iqhf8+s(~d#nPX+yhj_Thp-u`s)hT2oPk>~=s zI`4M8ON@xToxr<#^; zF+3;ee$l&VLC?Oo{)1tNzmO?uPd>>LV--(DlQTv!>?}W$U+hYohuT$06m8h=cz~=q z#~bq=hKvzK*}5i^Ljn)78g$K#HlbE<)KM=n1TTYs>H&Y>X-D(}(uJn<&l*oXyPY6M z!mTbN{cP})l{?%!(sRF~@a;~EGV1qpt)632KbqckT5DY2IdhMZnIU;TBR+lF^+9js zs__jrI_MJf;N*_a71{aT-i^7Fb(}qYGCRQBj(OhK4C-g|=#A@umRHZsF6*KqDdG3PO3de?B}Fm+D|Mw4pylu z>odP*^Zv%xQMt;iI4+NK*W^Lx1R_G}G|2C+A~JbUid?lQ_b^5BIAiq4?~PF-zqdXu z4&IAX!YdJ!l*oNAr$dhM9+VQ~*bY;o9BGUe<(p&FDBoP49-HU~ig23<8B8Tb%HEgL zq}H12X{z(1)X*4XbkI9v6wo{Cobhcr!}wkpjBkEtHot%NR(3YS^3ZVi%CN`j zgR|x_5TWo~nUfY@@MoMRI9p&>PyB4a*$VgZlwAL_3-3bTYt_K&`-1sFFYJdrS#BQi zyI1jPbykE}wEL`@6W?eDgwI-~^EvNO@OR#E(ERH?oP+99*QGbj|7m%B{n5r`x&QW< zRQKOrU%ofhms>o}=8%6KzF@z9@xvusG5Bud1>;3u3kCf-iR6@X@3`cJP0{XjlXmr3 zW0b4k9ivOfku3rj%rKGc;n4wk2ON${2Oxtuea9TkBKg zpnX7#Pr9{KNsH)rmbl%KNqVH)N4GL8Da1UMnK zdam*niIVF{XwdjhQkvh(oRPoJ(B$tGLq1{N4v}5uPT|dr`9DtaKE(Py;MF$)t-dK? z)wd<2`gZ94E%&{yb@6DO%ywTZpIlsTb?dRzX)Y&l| z2(95N(Nr?VE)#R$WHY#wl!azk#>?eM;#A^bdj=yqe9!(7uVSpwo6tVP0=JXP5Ri~-^q=-a-a}*?vnNYE!W{3qVm-t4b=5@9 zH9~`o$5OsrYs8qscYi$BkJ5kMuGC%M_2xrm0_Dc2rAB~Hb_!ay@$1>}!NR=7uQMzLyI5 z759jKf<8W&K@V#^vTr`xoM`YOZB|J+`Hx^-MJmbzS4txTvcs`y_?fVGS+(&1S7v;~f zQBRF7#FEJYe7N`ey=C@%yVEU5jZO)p0U6El#e3d9@PhPkn)!^4 zmvOvj5Ry6d!hCGkNJM6DbXa(0Jw9*fLbA=6S@1L2Oa2`kq&kM@Y(AIL-^UHAb{pDC zrd?+8Hy4Xm<&)Z$1supE_}w?jx@36MU(64C>(w^Gqk`Ycc_7JN>zxW;syP$SkpD5mmi72)Zasc7>+ywUr;%$!juN-?oi%+`X0?@e13%I& zhu1g64?1r0OujPTU{C*I5`+Fb-mQavvfsxo0#frmlBpeAwAC>8`(CDQ-Tb1{xYDO& zBWKK&)C*{X^SwHiOR946a}VIG{dQfs&+#jK47G7>P(nF2#!rR*D)}|@Zj9%?(NmK^ zUne8KWbO9h6|7kOdNuu>QBXeeFfFo! z)_n?ArL1|}qYp}k9bC2|Y@Msn{9ma;-Z+KnneP4k6MshU&bdCuaHMJ)%+X)eFTP+iL@U-cpaah?4LT|BGbA3NbEl3K z>e^hyXpO3ngDgU3gzkJ?tBgmB2@7v0jssg92&%CzRDb&N9iPx<3y=Gru zldr?A8(t|3US!?Unn!NS9M~g$-((Lg1RoxJ7PpLseiE2?$m;u9QJ=d%r{&yGj*jP( zPeg5EcI6GRuVaQa1cx!puTAR_oyQA)9dj(luV;vdju(r@V2$o;A)Wb}QiUVdRp=~i zps%FzeP8{%nUEN=w2^+QAFf{oB*xD^+mva zUReJ^siTJld&B9CfCWg%ugkEsZys#l1`u`?Pd?vPw;J~VncqoI?igG%9WwWQ@OdS3 ztdHCNAzo$nF<7zqzPF!JY}Hxiz6SYaS_vW9jPhA0b*wM+P4>s~USyonBZ|h4Ll~B$ zl=o#&5$)8Nan`+tZ)hzwj0fTiPrChOVs@OV_DaLCn*Pe(@T$*`Y}Xt=RJa2VKDW2c zFWv4=j&fr3ZTokSdFIpnQ*@}q01uHLj(_D9ik5RZyyW~O+)n2s&y?8jA~aYiY=B2^ zPui!U8nFlAuH{@*!z75>+_N5TKk8|-wgz#$mKKt8+4#xS#S?7)UdYbW^U> zaINco-}o49q?oMVj&akzAx_y}Ww&HQeG@+pNXc|%jUw&P-eFb+RrOKU3}L^yjGRrO zg8HKBgX{BC^A!Xf|F(U5!g#)4LB4f^spDIkqrdyeO%2=KJY(On#u4}XAn|2npqy!r zp}1$`dk(7R7E!mdm-halBGF@UjVYL1WvpyBIiVl%q0o0VlBBHzK1KsZTB9MLNeB$eEcFl;iv5WMc z&B~u`En1#4Skz12r7mq;_G#G@fL~&NDdeh^yAb1_+Q|4HtUZ3dA479qeg3T*d_}|Y z`JdUy{PCC9!+*YmWBvK#Bd;>PqEWKbWz>2duFut`hj_ibStZ8SIV2*#{XCoC)$%r# zXdfQtczZu374jB6Xypx^9`DtvSg)s`t-qY|bQQ&p+RsP|wrHS$&RL zO_QPSv-Ew_zgB+gwAt4F;4~j~6&wT?)fmv&2f@LIwpxYKj)O-X4xHzf+uHKR9ce0G zC6EzByps5 z$vK<;LDm*`Te|tq)D);dBhus@wfjqYNZ!V-=k}<`Tx^Euh%P#i+r0c`)Da*UD z-uLuXSKjSsRg>45aq=(n0MH`HFuP*n>+sm}=+o~;h%uM#xhU(?>0f&OqDuI|4o$t= z9Pjy?(^fFUcp8VsA;%N2m1gC~cy!Bm{K;VbO~ z{Jd*%)O?1*_h@-Stm0@PV$LrY+y^AGj(iq3%9g%)_(UJH@yU}n3!j168n2m4(P4R= zvZ_oV2f?vf)hmn(j7rbjL z4bLQCg@tEKwUsG*`MEW|y5FnnnKbUVyH(5n?bn72_7FJlSZ7E~?Qe*q*qOMsu(a){ zfU*MiI?Ics)a%60jUL3qq`}2iv98ZCFdvhfRyoP_zwNhpW!c(3uj_%EKD@^8^j>l_ zDj;DkvkELZrj&bOMKB$fGR~kGu}{6c7s=JC>pF*)*uZ-o4^Lm!ttO|g3Go~K#9W-R zh#R}J?E31c&ufoO-aYGzs(G1Iz*VbZ$awhp5AJ6}9QKJ5?rU2vKv(do}zge4754Eo3*n+$N7PYZC zxn7?J!lIA`TAueMcJqEh3)>jKP-;hvghS3?k5d{XN-}FatOBg#M9`n#S;hJx58ui$(EGa0< z61~97Kt;V=wei}-dN(qBq80ZWxCa9_IAk|%tc&I!g>C(@lj~fky@rx1?HXM>QZG8V zsXt9d09DtAxNWE+yTemTK)JWumjupTAzSRkU+iSwTlC-L9pa#9Tt4$29GIniU0k5A z=#!Y4_sXd$AJ0!0lH2MYA9)uC#gY2{%0?s3wz-)&U*0oVnaNSlXITHPOPPJM1Yn1A zX=G_|#t&=4o~NIUJA5jY`I4L9xBjfSuS1y?2sa^ls44JoLkXp2>kOKbBOp}p8gb1QgrC^K;LUD-zn`x`7HC0dz|HS ztb<05cUOV8FNuA4%Xdn6%Vz<@u+P`_8T%*N_gadGquCt;6fhK?sCh)_pIGw{`0J5B4{=APhlRQh#?rr9IpKxoAJvyLw1p+q^H$ z{$vp*jpI1|+URp(a_{Igj};=ZFRVA^!IMXVnQPXam)6q(`DSOP{#Tuw@VM%{ zN}k^ItjgYxYEGq;Yqlzb*^m8x*qAM`%=dz>+=78M<%D$VYoc5UGg_(I1G zQSO%6oXFl^7YAo7vh8^@o5Dd^d31dooSK9Ktn_o^wRPw38Sk7f*wp;Xs-El5KUc{f z=7CEVk>M6czm<0#Iba{atJQ4|2On-o4mdZuTn}97d~;4=l9NM@inPwEI^jc;V4Ydr z6hC~lAzZw_z{R-Dxn;UY6^Y=7x|aS<7a4wH-kbL7LL+|M&7SkRoR{Z>Z$B!?>28nJ zmyxMmd-rqe^KN6EHC&1Ef_cq;BUI?kDKx)eBYE9Nm;C9o)Vbtkvy94;>(1jCaV)p>#$Do-^1Cb!~Vc3Ggt0SUKztyP&cD&+tV^?%8iiAIP+_3Ph5o)+w005F_kIWMex0e+?nyP?Bx3E z<c!SDE_|hc4r@GSay&ry-l3>oRV~%F*5=Em%VKW^)?Y_H*Bx(uAwceu&pv z+VFO#51(`zkhMcOlIua|(V;zrA&=Z6&Az6EUcU1bt9g&l)Ax85nS3m1L0{L>4{d*) zYijm$iIZ{D6_u>@7tuU{QfG7g1g_z^=OsDnhE0Dj(2}@S(r@IV4 z>M*j3&;ACm5FORczuSw*&hHm?{;;7u-9gDIX7Uh+pmh1ndvbB|HOI{)kK$WazAuc= z`{!^YE5bQ})$x>imZwdBd3_J6G@dc!65v({ZcJYqhl<>&p5Zx1wuW<;&Y#1&Y!eUynBght`1Wz>#@=JOtyrf+;GPr|AMEfo!6}x`7Glt`}T=F z!%HCF_rBGX);fW+AjAAFk0yL)PFAejTek6==~1?JGreVdx0xPWwq`RuhmPA!e_6L| zrpHoGY^KkU`Azlb@~hrlqJ}f%hIYgAUjA_Fa!;7ZW9+T(m{f75fU4}$MBHxV5ncAo zuG<@4quC>FLs2tdha(xpf@yilq8ZWWkhGVvkrFocpdt@Y5P~gX%=3a;dkO3$gw7~; z1M0niUl;v_p7F>L>wnqLmljV^kMVSM4NRZq>F|E98uR`J$BfK>PD1v_ykgM+I4ak= z@yJx1Ux#y`k>fw`whnbyZ$mE15JxblO`ZSCR;+yna7@}{y{1SSbRaJFgXO4(ti+hP z_SM*!*~V>R+E^~aBxZ%7y3*EFe!oytAq zo}4M=k)D ze4c&=C(hnnF}hKQwmjeEFqiFt`IhBAobNn$&+v%M=xmjrchS*D#%G>Q9dCJ#`&VYS zzqP3GdCOfcv$0+050CCXP0qB}9$k#F3M4t(p8Tmgw;kOH|7o{=7&6BTH^X^7G3v#V z-89^yKNoo)TP7LEfG`Nn{iKSY#o~6YylxuDnp0er0vunfWX$}#Ai}bqnDtSmLY< zXCN+`MrrdVa)h068S)H0?dWNTa$J5MS^u1b6c=-!j4I{zHDoDm=uDRmEW6hbrus)e zg2kKRJr7G%4GSxVp|=kLOROG-dhg?f3U41++=uhjtK!tF$1Q7jx1t5r1;#Q36-#gr zM!mxmk4;LrkpSN!YP>Cj`l{g?n>LLXYW=r)Zs@}^#t#RBX9`F3;c=c|UsKp0=BIvZ zxB@#G>qTgX&fruWnPvA(dn}{c2Qp3@`6-*HN{l~7kM+i%LWvmPY4EXe zy*PeY`$a3ah15!2*6Qv|t(IBBYn`@?$`tB(oR-oztbuZ68R_FyR>`HFs8_5yd0kfM z@Y*`>+D!yhS{vTa$r0WY#;J-VtX8W>@k%O{;wj=E#_F8dhpkN(7|UQInMU@u&L1U0S-Qsb*<=nlql`u!J%K>=Bx*|tU^GH z{g(6|RZLa;ey+8q*a}5AYim_o3%8>6TdqM}*G!9W);$dANbh;QDh*{#k2=cekv>sI zl0U5i#dyzd+1HOGws2GG@zrBN|85cAOSXpp#{QLO)MVM(l!Y#}7Cy-6S63drr9lq@ z!DW-i;iz5<_oe1L$k-Q0BZ{rDrMC_;>c3hHw>{&(*Qla2%{}w=yrNl-%X<|&Vil^h zl6~zKmTS)?ub*1)m(n=hp7UlMYi#x3hbPukt@jTCPra^c_1}j_Yh0~Iw6{8~wMUnx zv|Tms_?4{Hrg3f&CNziDV4B7+ zeVCkM&h%E~ZLIa%JJ00yP*v7}orc(NS}yM`A9Q}nm7P1t#Z7+yA+xZ3tk4lu^MT@+HQ)h1nEZQ;h z(b+fB-NZRRT2ILY7siLQcL@)CF->=ZiT?RE?Zx!ZQ1{1qRAtEor+8L=KO5ZXn`fP~ zvkx}wsrq&k^B&f;(`TM@#1A%eNyHQ#y@}ahHfds)HjlRs?Q^#J!7wmQuWw@RLmGWL z-9NCbW!F0SY{oirzRVVEV!nMVuxzH1@i)U-DEs|lr{UeV=ZqD;^zANxoKN{qdg7=* z6gGnFe|&1{FM4jJtOGaExK(hSOYUv?X0{5_%xjYIxHydAQ9%bufM$S}Cr*+Pdw@p;XN zb1Yt~#PLwhaHs1bW(Ty?mMQ1Vx7ccj$Ls3^BpT^!gNPg0m=6^(9g?~tPP^y+w?H9T zEKhJajPF{E=D1OyJp+Hb+i{a?AgJW?7;Aao{3!bE&u+-ZXPi*A(&xTw>$5g}!snYl zMv0y1p`=KR-tYMvgUh+-PO83H!miVRocY)1SLrhp(f9Wo7~&2ycw?Ny0=Cj?DJ7_s z+?vC7=5Rz`+_{Bhk&z?mJlpZl6u(uPC`TElXd+}+XLWYWE4^zm!{f$t)W0mhho|_y ztf5tFr1f-H=*z#_?2$k+DL*x>(5i`g!erUULF@ct8JRztv=d!6nu15USI%Q-*=3OQdnzI5&kzmJsuS?k<{ywxZ^s%zXBVQq;3_5I&9f%(FXyn( zFI3iiX*TMW;pa|geP7w{eLK0qO*PkzquoxG9K*LI-2w|k8t^v@g^m5qLb-L9to(Pk zP}qlBQgjN)Z#$Q5jR^Nxn^)Zp>1y+85fyK@p*kkje7JpBZI+GWZHC6tT-tS4q`7na z$L~aF!{>Ek+b4OnmfAH9_0aTCoYO`7L{y~o+cpcIR~Mz8OzW%>emEY8uMn{Q*)B|l zc-V*8>Ut0Vrf;9z*QwtV4xHlt4pKM8Co1QJH&psAlG`D_cu4yXd#_{uU|1E6+tL^9 z^#at$vBJ{R#3R7tUG@&1@UnOCke9uaJ!jTk&y9zD4a3UmfypP?DAVhTM07^^^P+lG z5Am8C>}o5PTMKlC%3e3$4c4X;sFDTc|`Hbff(PTY8 zKyeAtc4#Fr#8WX!Ig>G3XkKIQxThiwqZUI@)S3N0tCqfaY>B_1Y`s6ACR2kY?#QXV+H(r=MAm1nc zE_I|=FU!wQS{wJU;VsrU;`wXlV}E0RU9wox_3o_ub+c_X?TB}MX?r1PE$0l6Liy+Y zPM=(}|ACLFNkDeeB34gr^au9;lg<~wdXBx3EBOWPkm9@6a;Mk7X2!hwv+`StZra?w zvUTZoTXiryZf63AHLN*{61@_&4r;vRe!sU9;Fs(!^_$jnA9L$z+y0#nk|Wn>jtf@M z$mSKpEnY&YLw(grOpJ)lI8DZ$LlMo3(K95iT1)r|9vf{};Gz%D&e)styq}VGc-7W# zZQSYI=5oSdDd#B-K)=p0<)`4BQmgqHuj%Kzrt-}zlM>Dj6P0mJ8|SlE7BwLQi73YQ zBKpW2;%5rK{%qrNr?^I4#@|2NxMyr!_h9A4Wa_d)_sFX59P7(pmJ&|dzO$G+YfYee zdyv{_{%6LUMA4`=#18K5PRp=A>gV0gcii-?{gvrF#6NY9Q9o$-zQ?jn?96^^a!t(7 z`9DU_T1ouIILrgNJ*b}g#;n6s8fNUTucIy`O~-mEB6Uv;`>OM>Oj-j&!od)gLPH?s z(#F%?MoWa3f%GD0E$*G(U%<1I)_LLIA&1j?tGzK=ibuAr?{z%yzaLv5x|jOdDHf8b z8+n3iuII*E4cn68QL}GwYQbmdu$trhR)t+2?q>aq>A)INU}2@Y-@S9f`dg<@kIjeF zfCXvXUo1xM>i}T|{g`ik632Th`2(MsJkYjpNm{k|qAj*UBl!vr$wDsB0Fu!14e*mO zoY#5u{Odw0`D?4g5uVD6IrgP#z(d(H{)V`QyQ)e_q^}`qEOq%Zi{h)^jLCI+&Q;&` z<~D3IFna`r{o4mN<0r-e=gpr6gTp$x!~kak;NTbL`C`r1#Uz~Iym@VIv&%gXr*LSx zto8J*e)nx<>3wFN>U;F#>lEn%q?3%4$O*&JgdAtyRGZqHZubFSI$bvFRc{%FW3`*L zg76i5nxUtnZELQ;$!%z?$=J=0_+`xl?e?yH>NPEN79I1a^(@<1ty)p#tx7leyy_XZ zZ3^5E@58y&0nS*Z{~desCa$0|-E@|D8rAA5zIn#O92OMaGAz}eY^j^u_%EdkE@`z| z#*Ko*fBXM?MnCFd_$n7ZYsXKh^!&th+*A9ZYNyM(Bt?28R>5TyLU?lT-?L@BN9hdp zv}KSyw>5#JF~0X0MZ{}v7$npkjWJoHXI+P#+qNGvqh8u9(e&F3FY(SI-gDAcM<*8} z)|PcBu2-&hU7pMDh#mB6aJnvc`N+_ow6{Hqlw&RbYVo5hUF@S=yJo!5;~k54GryMI zC^>U`t_ejGhey2Oe~s%Kw^Vh#l+u5yb&qC^z9?HpL_6130e9uPzLwC?U?tYYQ9fdg zr`os7V@5p}e5OpBdh8NgeVNW}+jRYd@$H{d%uM_a)HTeSY1!*T!{aOCTmQ|y<&V2n zKEH#5{$MvJ{GVi*9V`7Y_o^`d!Yv z?z`1{#Ijv)fg{BjBl;{%wR+&0OK{11rNpDl>zr-&Yd`B^QJLZ~);j%_`!CTKRsyf5 ztPmd0OD^X7z>M@PxcS;N(3ciDCjvViKlGM&=%(T3ZHs4>no00(W-cE6nLdkksZ5lT zh~uWHOyn=`vI#5v-VA0Uem@;M>(H3ogH6%6&%w(2D|eb&E3?0u_IkIVPubf#T77)K z$7xn;_oLqXaeqh_o{C{aiCLu}{g2E;Vo!-%cXU^Scul&#ldrC69g9lucKWq#EBd~QdLGx6?RH@m^XVz|$nPO+Os9W+!s#~-=*LY; z4xkEu&P>kq;B%?X)>;9>TC zp#B_63yu%Ru4dndn~IO}7DJcB+V0Db4Qx-r*5UhOtK$og=b-qCisjN?L2(xM8f+G4hi&Uu#}?M~pxBD)_M64l;aSGj@r3O;D4yc}hBlr`x$JAPa)+Y5 z%MkIXoKYK*K4qTNeciJ7&kOtUtm6FFs#$P8w;IFT(nF+<=z#9&xoEK`Vo(pe-Nmy- zWNvG*Yqw+Xu!n>;Uw*2hpWD@jXV{YV_gN1oI{~{-q%5K_K)R#9TZ#tDBjmW@$~wA_5n4`~v1{;X zaYOP^#8Ow8`}-5-UdsO_t-#?#7qSJ=o>93bsH5lE>#wDVbqzItys}z<)sV3hpW_qx zm@jONcHi`?pWO3$Fg`prQECsyiKpx)wBfmk2lcz;^S0Ivi{q`vE7_@XYOZTe59ojKto)Voony2A zm>sis$Uoe+S{J~!ZI%Zwi}Tu?*2~{;X4-Qt$OPG5+`RWMT|dW)U4KZ}TxHE#vKCGwQBkb2o@;n69x(dG$%UIX2++DL5ywBU69p9bjJ?vRez~wa{ zropCJUogz)^}*EEXg6g=Fs+q|y4! zo_2p)7dZA>{=T$6d1A3P z@z0!Qe{8mhXTfd!^{M@MpL{xI?_BFN5m7nnWgbiKUtH8Ojhl2rf1bA%w7qRVUaN%u zSq%UUR%+L9 struct Button: public HighButton T fun; virtual void hover(bool on=true); virtual void select(bool on=true); -}; +}; template struct SetrButton: public Button { int key, * poin; virtual void press(bool down=true); - SetrButton(){type=1;selectable=selected=false;state=0;highlightable=false;} + SetrButton(){int type=1;bool selectable=false;bool selected=false;int state=0;bool highlightable=false;} }; template class Slider { // @@ -55,7 +56,7 @@ public: bool vertical; // false means horizontal SDL_Rect pos; // position Button up, down, //or left/right - slider; + slider; int positionsAmnt, capacity;// capacity - amount of positions dispplayed at once int whereAreWe; // first displayed thing bool moving; @@ -78,7 +79,7 @@ template struct IntBut: public Button public: int key; int * what; - IntBut(){type=2;fun=NULL;highlightable=false;}; + IntBut(){int type=2;int fun=NULL;bool highlightable=false;}; void set(){*what=key;}; }; template struct IntSelBut: public Button @@ -88,8 +89,14 @@ public: int key; IntSelBut(){}; IntSelBut( SDL_Rect Pos, T Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup* gr=NULL, int My=-1) - : Button(Pos,Fun,Imgs,Sel,gr),key(My){ourPoinGroup=gr;}; - void select(bool on=true) {(*this).Button::select(on);ourPoinGroup->setYour(this);CPG->printRating();} + : Button(Pos,Fun,Imgs,Sel,gr),key(My){ourPoinGroup=gr;}; + void select(bool on=true) {(*this).Button::select(on);ourPoinGroup->setYour(this); + #if !defined(__amigaos4__) && !defined(__unix__) + CPG->printRating(); + #else + #warning not compile here + #endif + } }; template class CPoinGroup :public CGroup { @@ -181,7 +188,7 @@ public: ESortBy sortBy; SDL_Surface * bg; int selected; //selected map - CDefHandler * Dtypes, * Dvic; + CDefHandler * Dtypes, * Dvic; CDefHandler *Dsizes, * Dloss, * sFlags; std::vector scenList; @@ -228,7 +235,7 @@ public: } ; class CPreGame { -public: +public: std::string playerName; int playerColor; HighButton * highlighted; @@ -240,13 +247,13 @@ public: CMusicHandler * mush; std::vector btns; CPreGameTextHandler * preth ; - SDL_Rect * currentMessage; + SDL_Rect * currentMessage; SDL_Surface * behindCurMes; CDefHandler *ok, *cancel; enum EState { //where are we? mainMenu, newGame, loadGame, ScenarioList } state; - struct menuItems { + struct menuItems { SDL_Surface * background, *bgAd; CDefHandler *newGame, *loadGame, *highScores,*credits, *quit; SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit; @@ -263,15 +270,15 @@ public: void scenHandleEv(SDL_Event& sEvent); void begin(){run=false;ret.difficulty=ourScenSel->selectedDiff;}; void quitAskBox(); - void quit(){exit(0);}; - void initScenSel(); - void showScenSel(); - void showScenList(); + void quit(){exit(0);}; + void initScenSel(); + void showScenSel(); + void showScenList(); void initOptions(); - void showOptions(); - void initNewMenu(); - void showNewMenu(); - void showMainMenu(); + void showOptions(); + void initNewMenu(); + void showNewMenu(); + void showMainMenu(); StartInfo runLoop(); // runs mainloop of PreGame void initMainMenu(); //loads components for main menu void highlightButton(int which, int on); //highlights one from 5 main menu buttons diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 52debd736..609a51513 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "SDL_Extensions.h" -#include "SDL_TTF.h" +#include "SDL_ttf.h" #include "CGameInfo.h" #include #include @@ -234,34 +234,38 @@ void CSDL_Ext::printToWR(std::string text, int x, int y, TTF_Font * font, SDL_Co void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A) { Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC; +/* #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) p[0] = R; p[1] = G; p[2] = B; #else +*/ p[0] = B; p[1] = G; p[2] = R; if(ekran->format->BytesPerPixel==4) p[3] = A; -#endif +//#endif SDL_UpdateRect(ekran, x, y, 1, 1); } void CSDL_Ext::SDL_PutPixelWithoutRefresh(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A) { Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC; +/* #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) p[0] = B; p[1] = G; p[2] = R; #else +*/ p[0] = R; p[1] = G; p[2] = B; if(ekran->format->BytesPerPixel==4) p[3] = A; -#endif +//#endif } ///**************/ @@ -279,11 +283,14 @@ SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot, int myC) { { Uint8 *p = (Uint8 *)toRot->pixels + j * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel; +/* + #if(SDL_BYTEORDER == SDL_BIG_ENDIAN) CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], myC); #else +*/ CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], myC); -#endif +//#endif } } } @@ -316,11 +323,13 @@ SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot) { Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j -1) * toRot->pitch + i * toRot->format->BytesPerPixel; //int k=2; +/* #if(SDL_BYTEORDER == SDL_BIG_ENDIAN) CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2]); #else +*/ CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0]); -#endif +//#endif } } } @@ -354,11 +363,13 @@ SDL_Surface * CSDL_Ext::rotate02(SDL_Surface * toRot) { { Uint8 *p = (Uint8 *)toRot->pixels + i * toRot->pitch + j * toRot->format->BytesPerPixel; +/* #if(SDL_BYTEORDER == SDL_BIG_ENDIAN) SDL_PutPixel(ret, i, j, p[0], p[1], p[2]); #else +*/ SDL_PutPixel(ret, i, j, p[2], p[1], p[0]); -#endif +//#endif } } } @@ -380,11 +391,13 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot) { { Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j - 1) * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel+2; +/* #if(SDL_BYTEORDER == SDL_BIG_ENDIAN) SDL_PutPixel(ret, i, j, p[0], p[1], p[2], 2); #else +*/ SDL_PutPixel(ret, i, j, p[2], p[1], p[0], 2); -#endif +//#endif } } } @@ -421,11 +434,13 @@ Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y return *(Uint16 *)p; case 3: +/* #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) return p[0] << 16 | p[1] << 8 | p[2]; #else +*/ return p[0] | p[1] << 8 | p[2] << 16; -#endif +//#endif case 4: return *(Uint32 *)p; @@ -440,11 +455,11 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src) Uint32 trans = SDL_MapRGBA(src->format, 0, 255, 255, 255); SDL_SetColorKey(src, 0, trans); src->flags|=SDL_SRCALPHA; - + SDL_Color transp; transp.b = transp.g = transp.r = 0; transp.unused = 255; - + if(src->format->BitsPerPixel == 8) { for(int yy=0; yyformat->palette->ncolors; ++yy) @@ -517,7 +532,7 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su /* clip the source rectangle to the source surface */ if(srcRect) { int maxw, maxh; - + srcx = srcRect->x; w = srcRect->w; if(srcx < 0) { @@ -539,7 +554,7 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su maxh = src->h - srcy; if(maxh < h) h = maxh; - + } else { srcx = srcy = 0; w = src->w; @@ -589,11 +604,11 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su SDL_Color tbc = src->format->palette->colors[*((Uint8*)src->pixels + (y+sr.y)*src->pitch + x + sr.x)]; //color to blit Uint8 * p = (Uint8*)dst->pixels + (y+dstRect->y)*dst->pitch + (x+dstRect->x)*dst->format->BytesPerPixel; //place to blit at - // According analyze, the values of tbc.unused are fixed, + // According analyze, the values of tbc.unused are fixed, // and the approximate ratios are as following: // // tbc.unused numbers - // 192 2679 + // 192 2679 // 164 326907 // 82 705590 // 214 1292625 @@ -603,7 +618,7 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su // // By making use of such characteristic, we may implement a // very fast algorithm for heroes3 without loose much quality. - switch ((Uint32)tbc.unused) + switch ((Uint32)tbc.unused) { case 255: break; @@ -621,9 +636,9 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su p[0] = ((((Uint32)p[0]-(Uint32)tbc.r)*(Uint32)tbc.unused) >> 8 + (Uint32)tbc.r) & 0xFF; p[1] = ((((Uint32)p[1]-(Uint32)tbc.g)*(Uint32)tbc.unused) >> 8 + (Uint32)tbc.g) & 0xFF; p[2] = ((((Uint32)p[2]-(Uint32)tbc.b)*(Uint32)tbc.unused) >> 8 + (Uint32)tbc.b) & 0xFF; - //p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red - //p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green - //p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue + //p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red + //p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green + //p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue break; } } @@ -637,8 +652,8 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su { SDL_Color tbc = src->format->palette->colors[*((Uint8*)src->pixels + (y+sr.y)*src->pitch + x + sr.x)]; //color to blit Uint8 * p = (Uint8*)dst->pixels + (y+dstRect->y)*dst->pitch + (x+dstRect->x)*dst->format->BytesPerPixel; //place to blit at - - switch ((Uint32)tbc.unused) + + switch ((Uint32)tbc.unused) { case 255: break; @@ -656,9 +671,9 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su p[2] = ((((Uint32)p[2]-(Uint32)tbc.r)*(Uint32)tbc.unused) >> 8 + (Uint32)tbc.r) & 0xFF; p[1] = ((((Uint32)p[1]-(Uint32)tbc.g)*(Uint32)tbc.unused) >> 8 + (Uint32)tbc.g) & 0xFF; p[0] = ((((Uint32)p[0]-(Uint32)tbc.b)*(Uint32)tbc.unused) >> 8 + (Uint32)tbc.b) & 0xFF; - //p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red - //p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green - //p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue + //p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red + //p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green + //p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue break; } } @@ -706,7 +721,7 @@ void CSDL_Ext::setPlayerColor(SDL_Surface * sur, unsigned char player) return; if(sur->format->BitsPerPixel==8) { - if(player != 255) + if(player != 255) *(sur->format->palette->colors+5) = graphics->playerColors[player]; else *(sur->format->palette->colors+5) = *graphics->neutralColor; diff --git a/SDL_Extensions.h b/SDL_Extensions.h index 09c73df6a..c88d70b97 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -50,4 +50,4 @@ namespace CSDL_Ext SDL_Surface * copySurface(SDL_Surface * mod); //returns copy of given surface }; -#endif // SDL_EXTENSIONS_H \ No newline at end of file +#endif // SDL_EXTENSIONS_H diff --git a/StartInfo.h b/StartInfo.h index 012f6784a..86a79ecb9 100644 --- a/StartInfo.h +++ b/StartInfo.h @@ -42,7 +42,11 @@ struct StartInfo for(unsigned int i=0; i void serialize(Handler &h, const int version) { diff --git a/client/CBitmapHandler.cpp b/client/CBitmapHandler.cpp index b7b600729..1bbb67caa 100644 --- a/client/CBitmapHandler.cpp +++ b/client/CBitmapHandler.cpp @@ -201,9 +201,15 @@ SDL_Surface * CPCXConv::getSurface() } else { +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + int bmask = 0xff0000; + int gmask = 0x00ff00; + int rmask = 0x0000ff; +#else int bmask = 0x0000ff; int gmask = 0x00ff00; int rmask = 0xff0000; +#endif ret = SDL_CreateRGBSurface(SDL_SWSURFACE, bh.x+add, bh.y, 24, rmask, gmask, bmask, 0); } if (format==PCX8B) @@ -212,9 +218,15 @@ SDL_Surface * CPCXConv::getSurface() for (int i=0;i<256;i++) { SDL_Color tp; +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + tp.b = pcx[it++]; + tp.g = pcx[it++]; + tp.r = pcx[it++]; +#else tp.r = pcx[it++]; tp.g = pcx[it++]; tp.b = pcx[it++]; +#endif tp.unused = 0; *(ret->format->palette->colors+i) = tp; } diff --git a/client/Graphics.cpp b/client/Graphics.cpp index e8e5c7875..4a7e3059a 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -41,7 +41,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh) 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->subID],11,12,ret); + blitAt(graphics->portraitLarge[curh->portrait],11,12,ret); itoa(curh->mana,buf,10); printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points delete[] buf; @@ -205,7 +205,9 @@ Graphics::Graphics() void Graphics::loadHeroPortraits() { std::ifstream of("config/portrety.txt"); - for (int j=0;j>numberOfPortraits; + for (int j=0; j>ID; diff --git a/config/cr_shots.txt b/config/cr_shots.txt new file mode 100644 index 000000000..7c0b4b5e1 --- /dev/null +++ b/config/cr_shots.txt @@ -0,0 +1,40 @@ +//here are defs with things shot by different units - don't delete this line; format: unit_ID def_name spin_projectile +2 PLCBOWX.DEF 0 +3 PLCBOWX.DEF 0 +8 SMBALX.DEF 1 +9 SMBALX.DEF 1 +18 PELFX.DEF 0 +19 PELFX.DEF 0 +29 CPGRE.DEF 1 +34 PMAGX.DEF 1 +35 PMAGX.DEF 1 +41 SMBALX.DEF 0 +44 CPRGOGX.DEF 1 +45 CPRGOGX.DEF 1 +64 PLICH.DEF 0 +65 PLICH.DEF 0 +74 SMBALX.DEF 0 +75 SMBALX.DEF 0 +76 PMEDUSX.DEF 0 +77 PMEDUSX.DEF 0 +88 PORCHX.DEF 1 +89 PORCHX.DEF 1 +94 PCYCLBX.DEF 1 +95 PCYCLBX.DEF 1 +100 PPLIZAX.DEF 0 +101 PPLIZAX.DEF 0 +123 PICEE.DEF 0 +127 SMBALX.DEF 0 +136 SMBALX.DEF 0 +137 PLCBOWX.DEF 0 +138 PHALF.DEF 1 +145 SMBALX.DEF 0 +146 SMBALX.DEF 0 +152 SMBALX.DEF 0 +169 SMBALX.DEF 0 +170 PLCBOWX.DEF 0 +171 PLCBOWX.DEF 0 +173 CPGRE.DEF 1 +193 SMBALX.DEF 0 +196 SMBALX.DEF 0 +-1 \ No newline at end of file diff --git a/config/portrety.txt b/config/portrety.txt index 638dceda6..811127226 100644 --- a/config/portrety.txt +++ b/config/portrety.txt @@ -1,3 +1,4 @@ +163 0 HPS000KN.bmp 1 HPS001KN.bmp 2 HPS002KN.bmp @@ -154,3 +155,10 @@ 153 HPS008SH.bmp 154 HPS001SH.bmp 155 HPS131DM.bmp +156 HPS129MK.bmp +157 HPS002SH.bmp +158 HPS132Wl.bmp +159 HPS133Nc.bmp +160 HPS134Nc.bmp +161 HPS135Wi.bmp +162 HPS136Wi.bmp \ No newline at end of file diff --git a/global.h b/global.h index 51d66a917..c28537ef4 100644 --- a/global.h +++ b/global.h @@ -18,16 +18,25 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte) #define NAME_VER ("VCMI \"Altanatse\" 0.7") + +#ifdef _WIN32 +#define PATHSEPARATOR "\\" +#define DATA_DIR "" +#else +#define PATHSEPARATOR "/" +#define DATA_DIR "/progdir/" +#endif + enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors enum EterrainType {border=-1, dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock}; enum Eriver {noRiver=0, clearRiver, icyRiver, muddyRiver, lavaRiver}; enum Eroad {dirtRoad=1, grazvelRoad, cobblestoneRoad}; enum Eformat { WoG=0x33, AB=0x15, RoE=0x0e, SoD=0x1c}; -enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero, +enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero, captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255}; enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255}; -enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHEMIST, HERO_WIZARD, - HERO_DEMONIAC, HERO_HERETIC, HERO_DEATHKNIGHT, HERO_NECROMANCER, HERO_WARLOCK, HERO_OVERLORD, +enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHEMIST, HERO_WIZARD, + HERO_DEMONIAC, HERO_HERETIC, HERO_DEATHKNIGHT, HERO_NECROMANCER, HERO_WARLOCK, HERO_OVERLORD, HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST}; class CGameInfo; extern CGameInfo* CGI; @@ -78,6 +87,6 @@ const int MAX_BUILDING_PER_TURN = 1; { \ std::cerr << e->what()<< std::endl; \ delete e; \ - } + } -#endif //GLOBAL_H \ No newline at end of file +#endif //GLOBAL_H diff --git a/hch/CAbilityHandler.h b/hch/CAbilityHandler.h index be8921634..9b9ca9815 100644 --- a/hch/CAbilityHandler.h +++ b/hch/CAbilityHandler.h @@ -26,4 +26,4 @@ public: void loadAbilities(); }; -#endif CABILITYHANDLER_H \ No newline at end of file +#endif //CABILITYHANDLER_H diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index 91539b02c..0bbe244a1 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -40,4 +40,4 @@ // delete map.terrain[ii] ; // delete map.terrain; // delete[] bufor; -//} \ No newline at end of file +//} diff --git a/hch/CAmbarCendamo.h b/hch/CAmbarCendamo.h index d629b7058..e9d4d4dbd 100644 --- a/hch/CAmbarCendamo.h +++ b/hch/CAmbarCendamo.h @@ -16,4 +16,4 @@ public: //CAmbarCendamo (unsigned char * data); // c-tor; data is pointer to decompressed h3m data //~CAmbarCendamo (); // d-tor }; -#endif //CAMBARCENDAMO_H \ No newline at end of file +#endif //CAMBARCENDAMO_H diff --git a/hch/CArtHandler.h b/hch/CArtHandler.h index 862e55d24..c1d8352c8 100644 --- a/hch/CArtHandler.h +++ b/hch/CArtHandler.h @@ -31,4 +31,4 @@ public: CArtHandler(); }; -#endif // CARTHANDLER_H \ No newline at end of file +#endif // CARTHANDLER_H diff --git a/hch/CBuildingHandler.cpp b/hch/CBuildingHandler.cpp index 50c020d27..b9a8b3ae1 100644 --- a/hch/CBuildingHandler.cpp +++ b/hch/CBuildingHandler.cpp @@ -19,7 +19,11 @@ unsigned int readNr(std::string &in, unsigned 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 std::stringstream ss(in.substr(it,last-it)); it+=(1+last-it); ss >> last; @@ -63,7 +67,7 @@ void CBuildingHandler::loadBuildings() delete nb; } - //reading 14 per faction dwellings + //reading 14 per faction dwellings temp = readTo(buf,it,'\n');temp = readTo(buf,it,'\n');//dwellings - skip 2 lines for(int i=0;idescription = readTo(buf,it,'\n'); } /////done reading "BLDGNEUT.TXT"****************************** - + buf = bitmaph->getTextFile("BLDGSPEC.TXT"); andame = buf.size(), it=0; for(int f=0;f>castles; @@ -170,12 +174,12 @@ void CBuildingHandler::loadBuildings() (hall[tid].second)[j][box].push_back(last); areboxes = it; //wyzeruje jak nie znajdzie kolejnej spacji = koniec linii if(!it) - it = seppos+1; + it = seppos+1; } box++; it+=2; } } } - -} \ No newline at end of file + +} diff --git a/hch/CBuildingHandler.h b/hch/CBuildingHandler.h index 00941d42c..576effb66 100644 --- a/hch/CBuildingHandler.h +++ b/hch/CBuildingHandler.h @@ -23,4 +23,4 @@ public: void loadBuildings(); //main loader }; -#endif //CBUILDINGHANDLER_H \ No newline at end of file +#endif //CBUILDINGHANDLER_H diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index 02b418d38..5f22ff6a3 100644 --- a/hch/CCreatureHandler.cpp +++ b/hch/CCreatureHandler.cpp @@ -45,6 +45,10 @@ bool CCreature::isFlying() { return boost::algorithm::find_first(abilityRefs, "FLYING_ARMY"); } +bool CCreature::isShooting() +{ + return boost::algorithm::find_first(abilityRefs, "SHOOTING_ARMY"); +} si32 CCreature::maxAmount(const std::vector &res) const //how many creatures can be bought { int ret = 2147483645; @@ -318,7 +322,7 @@ void CCreatureHandler::loadCreatures() } //loading reference names - std::ifstream ifs("config/crerefnam.txt"); + std::ifstream ifs("config/crerefnam.txt"); int tempi; std::string temps; for (;;) @@ -333,7 +337,7 @@ void CCreatureHandler::loadCreatures() ifs.clear(); for(int i=1;i<=10;i++) levelCreatures.insert(std::pair >(i,std::vector())); - ifs.open("config/monsters.txt"); + ifs.open("config/monsters.txt"); { while(!ifs.eof()) { @@ -349,7 +353,7 @@ void CCreatureHandler::loadCreatures() ifs.close(); ifs.clear(); - ifs.open("config/cr_factions.txt"); + ifs.open("config/cr_factions.txt"); while(!ifs.eof()) { int id, fact; @@ -359,7 +363,7 @@ void CCreatureHandler::loadCreatures() ifs.close(); ifs.clear(); - ifs.open("config/cr_upgrade_list.txt"); + ifs.open("config/cr_upgrade_list.txt"); while(!ifs.eof()) { int id, up; @@ -368,17 +372,21 @@ void CCreatureHandler::loadCreatures() } ifs.close(); ifs.clear(); - + //loading unit animation def names std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod inp.seekg(0,std::ios::end); // na koniec int andame2 = inp.tellg(); // read length inp.seekg(0,std::ios::beg); // wracamy na poczatek - char * bufor = new char[andame2]; // allocate memory + char * bufor = new char[andame2]; // allocate memory inp.read((char*)bufor, andame2); // read map file to buffer inp.close(); buf = std::string(bufor); +#ifndef __GNUC__ delete [andame2] bufor; +#else + delete [] bufor; +#endif i = 0; //buf iterator hmcr = 0; @@ -410,6 +418,27 @@ void CCreatureHandler::loadCreatures() creatures[s].animDefName = defName; } loadAnimationInfo(); + + //loading id to projectile mapping + + std::ifstream inp2("config/cr_shots.TXT", std::ios::in | std::ios::binary); //this file is not in lod + char dump [200]; + inp2.getline(dump, 200); + while(true) + { + int id; + std::string name; + bool spin; + + inp2>>id; + if(id == -1) + break; + inp2>>name; + idToProjectile[id] = name; + inp2>>spin; + idToProjectileSpin[id] = spin; + } + inp2.close(); } void CCreatureHandler::loadAnimationInfo() @@ -583,4 +612,4 @@ void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int break; } i+=2; -} \ No newline at end of file +} diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index 31f5c9358..c4feac8f1 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -40,8 +40,8 @@ public: bool isDoubleWide(); //returns true if unit is double wide on battlefield bool isFlying(); //returns true if it is a flying unit + bool isShooting(); //returns true if unit can shoot si32 maxAmount(const std::vector &res) const; //how many creatures can be bought - static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion }; @@ -52,9 +52,11 @@ public: std::vector creatures; //creature ID -> creature info std::map > levelCreatures; //level -> list of creatures std::map nameToID; + std::map idToProjectile; + std::map idToProjectileSpin; //if true, appropriate projectile is spinning during flight void loadCreatures(); void loadAnimationInfo(); void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i); CCreatureHandler(); }; -#endif //CCREATUREHANDLER_H \ No newline at end of file +#endif //CCREATUREHANDLER_H diff --git a/hch/CDefHandler.h b/hch/CDefHandler.h index e112648a6f7a237ca87cb5cd1bae23093a835ee4..952da36e25ae30054f47877095fbbcbf2950adb5 100644 GIT binary patch delta 27 jcmaDNc|vl-4c5)KSXVG^p2wcYxS5ah8Z!$o0~Z4TqtOX0 delta 45 ycmX>h`9yNV4OVte23`g(2F}ThY|5M18WwSI}0ZO diff --git a/hch/CDefObjInfoHandler.h b/hch/CDefObjInfoHandler.h index e45ccab21..df3d047b5 100644 --- a/hch/CDefObjInfoHandler.h +++ b/hch/CDefObjInfoHandler.h @@ -8,7 +8,7 @@ class CLodHandler; class DLL_EXPORT CGDefInfo { public: - std::string name; + std::string name; unsigned char visitMap[6]; unsigned char blockMap[6]; @@ -39,4 +39,4 @@ public: void load(); }; -#endif //COBJINFOECTHANDLER_H \ No newline at end of file +#endif //COBJINFOECTHANDLER_H diff --git a/hch/CGeneralTextHandler.cpp b/hch/CGeneralTextHandler.cpp index 71a68249c..60c888a46 100644 --- a/hch/CGeneralTextHandler.cpp +++ b/hch/CGeneralTextHandler.cpp @@ -14,6 +14,7 @@ void CGeneralTextHandler::load() if(buf[i]=='\r') break; } + i+=2; for(int jj=0; jj<764; ++jj) { @@ -22,8 +23,8 @@ void CGeneralTextHandler::load() allTexts.push_back(buflet); } - std::string strs = CGI->bitmaph->getTextFile("ARRAYTXT.TXT"); + int itr=0; while(itrvolume = 30; - this->sndh = new CSndHandler(std::string("Data\\Heroes3.snd")); + this->sndh = new CSndHandler(std::string(DATA_DIR "Data" PATHSEPARATOR "Heroes3.snd")); } void CMusicHandler::playClick() @@ -86,12 +86,12 @@ void CMusicHandler::playLodSnd(std::string sndname) ops = SDL_RWFromConstMem(data, size); chunk = Mix_LoadWAV_RW(ops, 1); - + channel = Mix_PlayChannel(-1, chunk, 0); if(channel == -1) { - fprintf(stderr, "Unable to play WAV file(Data\\Heroes3.wav::%s): %s\n", + fprintf(stderr, "Unable to play WAV file("DATA_DIR "Data" PATHSEPARATOR "Heroes3.wav::%s): %s\n", sndname.c_str(),Mix_GetError()); } ops->close(ops); -} \ No newline at end of file +} diff --git a/hch/CMusicHandler.h b/hch/CMusicHandler.h index f095d983a..2120ccfb7 100644 --- a/hch/CMusicHandler.h +++ b/hch/CMusicHandler.h @@ -17,4 +17,4 @@ public: }; -#endif //CMUSICHANDLER_H \ No newline at end of file +#endif //CMUSICHANDLER_H diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 3d238beee..fb92cb7d3 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -102,7 +102,7 @@ int CGObjectInstance::getOwner() const { //if (state) // return state->owner; - //else + //else return tempOwner; //won't have owner } @@ -152,7 +152,7 @@ bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const //screen p return false; } - + bool CGHeroInstance::isHero() const { return true; @@ -390,4 +390,4 @@ CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right) //*state = *right.state; tempOwner = right.tempOwner; return *this; -} \ No newline at end of file +} diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 578e5ece3..97b044929 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -56,10 +56,10 @@ public: int tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna int blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile - + virtual bool isHero() const; - int getOwner() const; - void setOwner(int ow); + int getOwner() const; + void setOwner(int ow); int getWidth() const; //returns width of object graphic in tiles int getHeight() const; //returns height of object graphic in tiles bool visitableAt(int x, int y) const; //returns true if ibject is visitable at location (x, y) form left top tile of image (x, y in tiles) @@ -184,4 +184,4 @@ public: }; -#endif //COBJECTHANDLER_H \ No newline at end of file +#endif //COBJECTHANDLER_H diff --git a/hch/CPreGameTextHandler.h b/hch/CPreGameTextHandler.h index b497d647d..25f3e0f4b 100644 --- a/hch/CPreGameTextHandler.h +++ b/hch/CPreGameTextHandler.h @@ -18,4 +18,4 @@ public: }; -#endif //CPREGAMETEXTHANDLER_H \ No newline at end of file +#endif //CPREGAMETEXTHANDLER_H diff --git a/hch/CSndHandler.cpp b/hch/CSndHandler.cpp index 15b6a21ab..ae1a0c193 100644 --- a/hch/CSndHandler.cpp +++ b/hch/CSndHandler.cpp @@ -12,7 +12,11 @@ CSndHandler::CSndHandler(std::string fname):CHUNK(65535) { file.open(fname.c_str(),std::ios::binary); if (!file.is_open()) +#ifndef __GNUC__ throw new std::exception((std::string("Cannot open ")+fname).c_str()); +#else + throw new std::exception(); +#endif int nr = readNormalNr(0,4); char tempc; for (int i=0;i +#include #include "../lib/VCMI_Lib.h" extern CLodHandler * bitmaph; void loadToIt(std::string &dest, std::string &src, int &iter, int mode); @@ -33,7 +33,7 @@ void CTownHandler::loadNames() } town.typeID=si++; town.bonus=towns.size(); - if (town.bonus==8) town.bonus=3; + if (town.bonus==8) town.bonus=3; if (town.name.length()) towns.push_back(town); } @@ -122,7 +122,7 @@ void CTownHandler::loadNames() { i2->second->borderName = border; i2->second->areaName = area; - } + } else std::cout << "Warning2: No building "<second.begin(); i2!=i->second.end(); i2++) + for(i2=i->second.begin(); i2!=i->second.end(); i2++) { if(i2->first == buildingID) { @@ -247,7 +247,7 @@ void CTownHandler::loadNames() } of.close(); of.clear(); - + of.open("config/requirements.txt"); while(!of.eof()) { @@ -274,4 +274,4 @@ void CTownHandler::loadNames() of.close(); of.clear(); } -} \ No newline at end of file +} diff --git a/hch/CTownHandler.h b/hch/CTownHandler.h index 927828866..2cf895980 100644 --- a/hch/CTownHandler.h +++ b/hch/CTownHandler.h @@ -46,4 +46,4 @@ public: void loadNames(); }; -#endif //CTOWNHANDLER_H \ No newline at end of file +#endif //CTOWNHANDLER_H diff --git a/hch/CVideoHandler.cpp b/hch/CVideoHandler.cpp index 77bb97c6b..4281e3c60 100644 --- a/hch/CVideoHandler.cpp +++ b/hch/CVideoHandler.cpp @@ -2,9 +2,14 @@ #include #include "CVideoHandler.h" #include "SDL.h" + void DLLHandler::Instantiate(const char *filename) { +#ifdef WIN32 dll = LoadLibraryA(filename); +#else + dll = dlopen(filename,RTLD_LOCAL | RTLD_LAZY); +#endif } const char *DLLHandler::GetLibExtension() { @@ -21,14 +26,22 @@ const char *DLLHandler::GetLibExtension() void *DLLHandler::FindAddress234(const char *symbol) { +#ifdef WIN32 if ((int)symbol == 0x00001758) return NULL; std::cout<<"co ja tu robie"< +#ifdef WIN32 #include +#else +#include +#endif + // #define BINKNOTHREADEDIO 0x00800000 // @@ -75,14 +80,14 @@ //end; typedef struct { - int width; - int height; - int frameCount; - int currentFrame; + int width; + int height; + int frameCount; + int currentFrame; int lastFrame; - int FPSMul; + int FPSMul; int FPSDiv; - int unknown0; + int unknown0; unsigned char flags; unsigned char unknown1[260]; int CurPlane; // current plane @@ -109,8 +114,11 @@ struct SMKStruct class DLLHandler { public: +#if !defined(__amigaos4__) && !defined(__unix__) HINSTANCE dll; - +#else + void *dll; +#endif void Instantiate(const char *filename); const char *GetLibExtension(); void *FindAddress234(const char *symbol); @@ -123,7 +131,11 @@ class CBIKHandler public: DLLHandler ourLib; int newmode; +#if !defined(__amigaos4__) && !defined(__unix__) HANDLE hBinkFile; +#else + void *hBinkFile; +#endif HBINK hBink; BINK_STRUCT data; unsigned char * buffer; @@ -135,4 +147,4 @@ public: void open(std::string name); void close(); }; -#endif //CVIDEOHANDLEER_H \ No newline at end of file +#endif //CVIDEOHANDLEER_H diff --git a/int3.h b/int3.h index c6fd05b66..2b28a2885 100644 --- a/int3.h +++ b/int3.h @@ -35,7 +35,7 @@ public: x+=i.x; y+=i.y; z+=i.z; - } + } inline void operator+=(const si32 & i) { x+=i; @@ -47,15 +47,15 @@ public: x-=i.x; y-=i.y; z-=i.z; - } + } inline void operator-=(const si32 & i) { x+=i; y+=i; z+=i; - } + } inline bool operator==(const int3 & i) const - {return (x==i.x) && (y==i.y) && (z==i.z);} + {return (x==i.x) && (y==i.y) && (z==i.z);} inline bool operator!=(const int3 & i) const {return !(*this==i);} inline bool operator<(const int3 & i) const @@ -88,4 +88,4 @@ inline std::ostream & operator<<(std::ostream & str, const int3 & sth) { return str<areAnyPLayers = map[4]; //seems to be invalid this->height = this->width = map[5]; // wymiary mapy this->twoLevel = map[9]; //czy sa lochy - + int length = map[10]; //name length - int i=14, pom; + int i=14, pom; while (i-14name+=map[i++]; length = map[i] + map[i+1]*256; //description length @@ -220,7 +220,7 @@ CMapHeader::CMapHeader(unsigned char *map) for (pom=0;pomdescription+=map[i++]; this->difficulty = map[i++]; // reading map difficulty - if(version!=Eformat::RoE) + if(version!=RoE) { this->levelLimit = map[i++]; // hero level limit } @@ -236,13 +236,13 @@ CMapHeader::CMapHeader(unsigned char *map) { switch(version) { - case Eformat::SoD: case Eformat::WoG: + case SoD: case WoG: i+=13; break; - case Eformat::AB: + case AB: i+=12; break; - case Eformat::RoE: + case RoE: i+=6; break; } @@ -251,39 +251,39 @@ CMapHeader::CMapHeader(unsigned char *map) this->players[pom].AITactic = map[i++]; - if(version == Eformat::SoD || version == Eformat::WoG) + if(version == SoD || version == WoG) i++; this->players[pom].allowedFactions = 0; this->players[pom].allowedFactions += map[i++]; - if(version != Eformat::RoE) + if(version != RoE) this->players[pom].allowedFactions += (map[i++])*256; this->players[pom].isFactionRandom = map[i++]; this->players[pom].hasMainTown = map[i++]; if (this->players[pom].hasMainTown) { - if(version != Eformat::RoE) + if(version != RoE) { this->players[pom].generateHeroAtMainTown = map[i++]; this->players[pom].generateHero = map[i++]; } this->players[pom].posOfMainTown.x = map[i++]; this->players[pom].posOfMainTown.y = map[i++]; - this->players[pom].posOfMainTown.z = map[i++]; + this->players[pom].posOfMainTown.z = map[i++]; } players[pom].p8= map[i++]; - players[pom].p9= map[i++]; + players[pom].p9= map[i++]; if(players[pom].p9!=0xff) { players[pom].mainHeroPortrait = map[i++]; int nameLength = map[i++]; - i+=3; + i+=3; for (int pp=0;ppvicConDetails = new VicCon5(); ((VicCon5*)this->vicConDetails)->locationOfHero.x = map[i+2]; ((VicCon5*)this->vicConDetails)->locationOfHero.y = map[i+3]; - ((VicCon5*)this->vicConDetails)->locationOfHero.z = map[i+4]; + ((VicCon5*)this->vicConDetails)->locationOfHero.z = map[i+4]; nr=3; break; } @@ -372,7 +372,7 @@ CMapHeader::CMapHeader(unsigned char *map) this->vicConDetails = new VicCon6(); ((VicCon6*)this->vicConDetails)->locationOfTown.x = map[i+2]; ((VicCon6*)this->vicConDetails)->locationOfTown.y = map[i+3]; - ((VicCon6*)this->vicConDetails)->locationOfTown.z = map[i+4]; + ((VicCon6*)this->vicConDetails)->locationOfTown.z = map[i+4]; nr=3; break; } @@ -381,19 +381,19 @@ CMapHeader::CMapHeader(unsigned char *map) this->vicConDetails = new VicCon7(); ((VicCon7*)this->vicConDetails)->locationOfMonster.x = map[i+2]; ((VicCon7*)this->vicConDetails)->locationOfMonster.y = map[i+3]; - ((VicCon7*)this->vicConDetails)->locationOfMonster.z = map[i+4]; + ((VicCon7*)this->vicConDetails)->locationOfMonster.z = map[i+4]; nr=3; break; } case takeDwellings: - { + { this->vicConDetails = new CspecificVictoryConidtions(); nr=3; break; } case takeMines: - { - this->vicConDetails = new CspecificVictoryConidtions(); + { + this->vicConDetails = new CspecificVictoryConidtions(); nr=3; break; } @@ -403,7 +403,7 @@ CMapHeader::CMapHeader(unsigned char *map) ((VicCona*)this->vicConDetails)->artifactID = map[i+2]; ((VicCona*)this->vicConDetails)->destinationPlace.x = map[i+3]; ((VicCona*)this->vicConDetails)->destinationPlace.y = map[i+4]; - ((VicCona*)this->vicConDetails)->destinationPlace.z = map[i+5]; + ((VicCona*)this->vicConDetails)->destinationPlace.z = map[i+5]; nr=4; break; } @@ -462,7 +462,7 @@ void Mapa::initFromBytes(unsigned char * bufor) name = readString(bufor,i); description= readString(bufor,i); difficulty = readChar(bufor,i); // reading map difficulty - if(version != Eformat::RoE) + if(version != RoE) levelLimit = readChar(bufor,i); // hero level limit else levelLimit = 0; @@ -474,13 +474,13 @@ void Mapa::initFromBytes(unsigned char * bufor) { switch(version) { - case Eformat::SoD: case Eformat::WoG: + case SoD: case WoG: i+=13; break; - case Eformat::AB: + case AB: i+=12; break; - case Eformat::RoE: + case RoE: i+=6; break; } @@ -489,19 +489,19 @@ void Mapa::initFromBytes(unsigned char * bufor) players[pom].AITactic = bufor[i++]; - if(version == Eformat::SoD || version == Eformat::WoG) + if(version == SoD || version == WoG) players[pom].p7= bufor[i++]; players[pom].allowedFactions = 0; players[pom].allowedFactions += bufor[i++]; - if(version != Eformat::RoE) + if(version != RoE) players[pom].allowedFactions += (bufor[i++])*256; players[pom].isFactionRandom = bufor[i++]; players[pom].hasMainTown = bufor[i++]; if (players[pom].hasMainTown) { - if(version != Eformat::RoE) + if(version != RoE) { players[pom].generateHeroAtMainTown = bufor[i++]; players[pom].generateHero = bufor[i++]; @@ -529,7 +529,7 @@ void Mapa::initFromBytes(unsigned char * bufor) players[pom].mainHeroName+=bufor[i++]; } - if(version != Eformat::RoE) + if(version != RoE) { i++; ////unknown byte int heroCount = bufor[i++]; @@ -699,7 +699,7 @@ void Mapa::initFromBytes(unsigned char * bufor) for(int xx=0;xxsubID == ID) return heroes[i]; return NULL; -} \ No newline at end of file +} diff --git a/map.h b/map.h index 5e78d807a..f258ee1b1 100644 --- a/map.h +++ b/map.h @@ -1,6 +1,6 @@ #ifndef MAPD_H #define MAPD_H -#pragma warning (disable : 4482) +#pragma warning (disable : 4482) #include #include #include @@ -10,7 +10,7 @@ class CGDefInfo; class CGObjectInstance; class CGHeroInstance; class CGTownInstance; -enum ESortBy{name,playerAm,size,format, viccon,loscon}; +enum ESortBy{_name, _playerAm, _size, _format, _viccon, _loscon}; enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF, EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF, SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF, @@ -282,7 +282,7 @@ struct DLL_EXPORT PlayerInfo bool canComputerPlay; unsigned int AITactic; //(00 - random, 01 - warrior, 02 - builder, 03 - explorer) unsigned int allowedFactions; //(01 - castle; 02 - rampart; 04 - tower; 08 - inferno; 16 - necropolis; 32 - dungeon; 64 - stronghold; 128 - fortress; 256 - conflux); - bool isFactionRandom; + bool isFactionRandom; unsigned int mainHeroPortrait; //it's ID of hero with choosen portrait; 255 if standard std::string mainHeroName; std::vector heroesNames; @@ -375,7 +375,7 @@ class DLL_EXPORT CMapHeader public: Eformat version; // version of map Eformat bool areAnyPLayers; // if there are any playable players on map - int height, width; + int height, width; bool twoLevel; // if map has underground level std::string name; //name of map std::string description; //and description @@ -385,7 +385,7 @@ public: EvictoryConditions victoryCondition; //victory conditions CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard PlayerInfo players[8]; // info about players - std::vector teams; // teams[i] = team of player no i + std::vector teams; // teams[i] = team of player no i int howManyTeams; CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked) }; @@ -410,17 +410,17 @@ class DLL_EXPORT mapSorter { public: ESortBy sortBy; - bool operator()(CMapHeader & a, CMapHeader& b) + bool operator()(const CMapHeader & a, const CMapHeader& b) { switch (sortBy) { - case ESortBy::format: + case _format: return (a.version toAdd = std::make_pair(obj, cr); if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)pos.x + fx - curd->ourImages[0].bitmap->w/32] [obj->pos.y + fy - curd->ourImages[0].bitmap->h/32] @@ -1374,4 +1374,4 @@ void CMapHandler::loadDefs() } } } -} \ No newline at end of file +} diff --git a/mapHandler.h b/mapHandler.h index 60b972750..f8e145678 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -5,7 +5,7 @@ #include #include const int Woff = 12; //width of map's frame -const int Hoff = 8; +const int Hoff = 8; class CGObjectInstance; class CGHeroInstance; @@ -105,4 +105,4 @@ public: }; -#endif //MAPHANDLER_H \ No newline at end of file +#endif //MAPHANDLER_H diff --git a/nodrze.h b/nodrze.h index 15f7c8667..c9bf38f77 100644 --- a/nodrze.h +++ b/nodrze.h @@ -6,9 +6,12 @@ //ignore comment above, it is simply TowDragon's envy. Everything (without removing) is working fine #include +#include #include #include +#define CLOG(x) + const bool CZERWONY=true, CZARNY=false; template class wezel { @@ -82,7 +85,7 @@ public: ktory=0; }; T * begin () {return minimumimum();}; //first element (=minimum) - T * end () {return NIL;}; // + T * end () {return NIL;}; // void clear(); // czysci az do korzenia wlacznie // removes all elements, including root void usun (T co); // usuwa element z drzewa @@ -140,7 +143,7 @@ template void nodrze::wypisuj(wezel * w, std::ostream & strum if (w==NIL) return; wypisuj(w->lewy, strum); - strum << "Informacje o wezle: "<ojciec!=NIL) strum <<"\n\tOjciec: "<<(w->ojciec)<<" - "<<*(w->ojciec->zawart); else strum <<"\n\tOjciec: NIL"; @@ -159,7 +162,7 @@ template void nodrze::wypisujPre(wezel * w, std::ostream & st { if (w==NIL) return; - strum << "Informacje o wezle: "<ojciec!=NIL) strum <<"\n\tOjciec: "<<(w->ojciec)<<" - "<<*(w->ojciec->zawart); else strum <<"\n\tOjciec: NIL"; @@ -179,14 +182,16 @@ template void nodrze::wypiszObficie(std::ostream & strum) { strum << "Nodrze " < T* operator%(nodrze & drzewko, X co) { CLOG ("Szukam " <gl->loguj); +#endif wezel * w = drzewko.korzen; while (w!=drzewko.NIL && (*w->zawart)!=co) { @@ -494,10 +499,10 @@ template void nodrze::naprawUsun (wezel * x) wezel *w; while ( (x != korzen) && (x->kolor == CZARNY) ) { - CLOG("6... "<ojciec->lewy) { - CLOG("7... "<ojciec->prawy; if (w->kolor == CZERWONY) { @@ -506,38 +511,38 @@ template void nodrze::naprawUsun (wezel * x) rotacjaLewa(x->ojciec); w = x->ojciec->prawy; } - CLOG("8... "<lewy->kolor == CZARNY) && (w->prawy->kolor == CZARNY) ) { - CLOG("8,1... "<kolor = CZERWONY; x = x->ojciec; } else { - CLOG("9... "<prawy->kolor == CZARNY) { - CLOG("9,1... "<lewy->kolor = CZARNY; w->kolor = CZERWONY; rotacjaPrawa(w); w = x->ojciec->prawy; - CLOG("9,2... "<kolor = x->ojciec->kolor; x->ojciec->kolor = CZARNY; w->prawy->kolor = CZARNY; rotacjaLewa(x->ojciec); x=korzen; - CLOG("9,4... "<ojciec->lewy; if (w->kolor == CZERWONY) { @@ -546,7 +551,7 @@ template void nodrze::naprawUsun (wezel * x) rotacjaPrawa(x->ojciec); w = x->ojciec->lewy; } - CLOG("11... "<lewy->kolor == CZARNY) && (w->prawy->kolor == CZARNY) ) { w->kolor = CZERWONY; @@ -566,12 +571,12 @@ template void nodrze::naprawUsun (wezel * x) w->lewy->kolor = CZARNY; rotacjaPrawa(x->ojciec); x=korzen; - CLOG("12... "<kolor = CZARNY; - CLOG("13... "< wezel * nodrze::usunRBT (wezel * nowy) { @@ -597,27 +602,27 @@ template wezel * nodrze::usunRBT (wezel * nowy) } CLOG(*ostatnio->zawart< *y, *x; if ( (nowy->lewy == NIL) || (nowy->prawy == NIL) ) y=nowy; else y = nastepnik(nowy); - CLOG("2... "<lewy != NIL) x = y->lewy; else x = y->prawy; x->ojciec = y->ojciec; - CLOG("3... "<ojciec == NIL) korzen = x; else if (y == y->ojciec->lewy) y->ojciec->lewy = x; else y->ojciec->prawy = x; - CLOG("4... "<kolor == CZARNY) naprawUsun(x); CLOG ("koniec usuwania"< void nodrze::pre(std::ostream & strum, wezel * wsk) if (wsk->prawy != NIL) pre(strum,wsk->prawy); }; -#endif //_NODRZE_H \ No newline at end of file +#endif //_NODRZE_H diff --git a/stdafx.h b/stdafx.h index c8c475414..b6ef3cd8a 100644 --- a/stdafx.h +++ b/stdafx.h @@ -7,7 +7,11 @@ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include +#ifdef _WIN32 #include +#else +#include "tchar_amigaos4.h" +#endif #include #include #include diff --git a/tchar_amigaos4.h b/tchar_amigaos4.h new file mode 100644 index 000000000..a150fe866 --- /dev/null +++ b/tchar_amigaos4.h @@ -0,0 +1,238 @@ +/* + * tchar.h + * + * Unicode mapping layer for the standard C library. By including this + * file and using the 't' names for string functions + * (eg. _tprintf) you can make code which can be easily adapted to both + * Unicode and non-unicode environments. In a unicode enabled compile define + * _UNICODE before including tchar.h, otherwise the standard non-unicode + * library functions will be used. + * + * Note that you still need to include string.h or stdlib.h etc. to define + * the appropriate functions. Also note that there are several defines + * included for non-ANSI functions which are commonly available (but using + * the convention of prepending an underscore to non-ANSI library function + * names). + * + * This file is part of the Mingw32 package. + * + * Contributors: + * Created by Colin Peters + * + * THIS SOFTWARE IS NOT COPYRIGHTED + * + * This source code is offered for use in the public domain. You may + * use, modify or distribute it freely. + * + * This code is distributed in the hope that it will be useful but + * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY + * DISCLAMED. This includes but is not limited to warranties of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * $Revision: 1.1.1.1 $ + * $Author: brandon6684 $ + * $Date: 2001/12/18 22:54:08 $ + * + */ + +#ifndef _TCHAR_H_ +#define _TCHAR_H_ + +/* + * NOTE: This tests _UNICODE, which is different from the UNICODE define + * used to differentiate Win32 API calls. + */ +#ifdef __unix__ +#define _TCHAR char* +#endif +#ifdef _UNICODE + + +/* + * Use TCHAR instead of char or wchar_t. It will be appropriately translated + * if _UNICODE is correctly defined (or not). + */ +#ifndef _TCHAR_DEFINED +#ifndef RC_INVOKED +typedef wchar_t TCHAR; +#endif /* Not RC_INVOKED */ +#define _TCHAR_DEFINED +#endif + + +/* + * Enclose constant strings and literal characters in the _TEXT and _T macro to make + * them unicode constant strings when _UNICODE is defined. + */ +#define _TEXT(x) L ## x +#define _T(x) L ## x + +/* + * Unicode functions + */ + +#define _tprintf wprintf +#define _ftprintf fwprintf +#define _stprintf swprintf +#define _sntprintf _snwprintf +#define _vtprintf vwprintf +#define _vftprintf vfwprintf +#define _vstprintf vswprintf +#define _vsntprintf _vsnwprintf +#define _tscanf wscanf +#define _ftscanf fwscanf +#define _stscanf swscanf +#define _fgettc fgetwc +#define _fgettchar _fgetwchar +#define _fgetts fgetws +#define _fputtc fputwc +#define _fputtchar _fputwchar +#define _fputts fputws +#define _gettc getwc +#define _getts getws +#define _puttc putwc +#define _putts putws +#define _ungettc ungetwc +#define _tcstod wcstod +#define _tcstol wcstol +#define _tcstoul wcstoul +#define _tcscat wcscat +#define _tcschr wcschr +#define _tcscmp wcscmp +#define _tcscpy wcscpy +#define _tcscspn wcscspn +#define _tcslen wcslen +#define _tcsncat wcsncat +#define _tcsncmp wcsncmp +#define _tcsncpy wcsncpy +#define _tcspbrk wcspbrk +#define _tcsrchr wcsrchr +#define _tcsspn wcsspn +#define _tcsstr wcsstr +#define _tcstok wcstok +#define _tcsdup _wcsdup +#define _tcsicmp _wcsicmp +#define _tcsnicmp _wcsnicmp +#define _tcsnset _wcsnset +#define _tcsrev _wcsrev +#define _tcsset _wcsset +#define _tcslwr _wcslwr +#define _tcsupr _wcsupr +#define _tcsxfrm wcsxfrm +#define _tcscoll wcscoll +#define _tcsicoll _wcsicoll +#define _istalpha iswalpha +#define _istupper iswupper +#define _istlower iswlower +#define _istdigit iswdigit +#define _istxdigit iswxdigit +#define _istspace iswspace +#define _istpunct iswpunct +#define _istalnum iswalnum +#define _istprint iswprint +#define _istgraph iswgraph +#define _istcntrl iswcntrl +#define _istascii iswascii +#define _totupper towupper +#define _totlower towlower +#define _ttoi _wtoi +#define _tcsftime wcsftime + +#else /* Not _UNICODE */ + +/* + * TCHAR, the type you should use instead of char. + */ +#ifndef _TCHAR_DEFINED +#ifndef RC_INVOKED +typedef char TCHAR; +#endif +#define _TCHAR_DEFINED +#endif + +/* + * Enclose constant strings and characters in the _TEXT and _T macro. + */ +#define _TEXT(x) x +#define _T(x) x + + +/* + * Non-unicode (standard) functions + */ + +#define _tprintf printf +#define _ftprintf fprintf +#define _stprintf sprintf +#define _sntprintf _snprintf +#define _vtprintf vprintf +#define _vftprintf vfprintf +#define _vstprintf vsprintf +#define _vsntprintf _vsnprintf +#define _tscanf scanf +#define _ftscanf fscanf +#define _stscanf sscanf +#define _fgettc fgetc +#define _fgettchar _fgetchar +#define _fgetts fgets +#define _fputtc fputc +#define _fputtchar _fputchar +#define _fputts fputs +#define _gettc getc +#define _getts gets +#define _puttc putc +#define _putts puts +#define _ungettc ungetc +#define _tcstod strtod +#define _tcstol strtol +#define _tcstoul strtoul +#define _tcscat strcat +#define _tcschr strchr +#define _tcscmp strcmp +#define _tcscpy strcpy +#define _tcscspn strcspn +#define _tcslen strlen +#define _tcsncat strncat +#define _tcsncmp strncmp +#define _tcsncpy strncpy +#define _tcspbrk strpbrk +#define _tcsrchr strrchr +#define _tcsspn strspn +#define _tcsstr strstr +#define _tcstok strtok +#define _tcsdup _strdup +#define _tcsicmp _stricmp +#define _tcsnicmp _strnicmp +#define _tcsnset _strnset +#define _tcsrev _strrev +#define _tcsset _strset +#define _tcslwr _strlwr +#define _tcsupr _strupr +#define _tcsxfrm strxfrm +#define _tcscoll strcoll +#define _tcsicoll _stricoll +#define _istalpha isalpha +#define _istupper isupper +#define _istlower islower +#define _istdigit isdigit +#define _istxdigit isxdigit +#define _istspace isspace +#define _istpunct ispunct +#define _istalnum isalnum +#define _istprint isprint +#define _istgraph isgraph +#define _istcntrl iscntrl +#define _istascii isascii +#define _totupper toupper +#define _totlower tolower +#define _ttoi atoi +#define _tcsftime strftime + +#ifdef __amigaos4__ +#define _TCHAR wchar_t +#endif + +#endif /* Not _UNICODE */ + +#endif /* Not _TCHAR_H_ */ + diff --git a/timeHandler.h b/timeHandler.h index 74f4ee81f..e6656ac9f 100644 --- a/timeHandler.h +++ b/timeHandler.h @@ -13,4 +13,4 @@ public: long memDif(){return mem-clock();}; }; -#endif //TIMEHANDLER_H \ No newline at end of file +#endif //TIMEHANDLER_H From 6e737bbf3c996b5967b0d49318c335288dd01a20 Mon Sep 17 00:00:00 2001 From: Vadim Glazunov Date: Mon, 4 Aug 2008 09:05:52 +0000 Subject: [PATCH 40/47] Now netcode branch may be compiled with gcc. Sorry can't check build with MSVC --- CBattleInterface.cpp | 5 ++ CCallback.cpp | 10 +++- CGameInterface.h | 4 +- CGameState.cpp | 2 +- CHeroWindow.cpp | 4 +- CLua.cpp | 8 ++++ CLua.h | 7 ++- CLuaHandler.cpp | 4 ++ CMT.cpp | 12 +++-- CPreGame.cpp | 4 +- client/Client.cpp | 11 ++++- client/Client.h | 1 + client/Graphics.cpp | 18 +++++--- hch/CDefHandler.cpp | Bin 27552 -> 13775 bytes hch/CDefHandler.h | Bin 3272 -> 1635 bytes lib/Connection.cpp | 20 +++++++- lib/Connection.h | 39 ++++++++-------- map.cpp | 98 +++++++++++++++++++++------------------- mapHandler.cpp | 12 +++++ mapHandler.h | 2 +- server/CGameHandler.cpp | 31 ++++++++----- server/CGameHandler.h | 4 +- server/CVCMIServer.cpp | 32 +++++++------ server/CVCMIServer.h | 4 +- 24 files changed, 216 insertions(+), 116 deletions(-) diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index d5ea7ff24..82e25f4d4 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -15,7 +15,12 @@ #include #include +#ifndef __GNUC__ const double M_PI = 3.14159265358979323846; +#else +#define _USE_MATH_DEFINES +#include +#endif extern SDL_Surface * screen; extern TTF_Font * GEOR13; diff --git a/CCallback.cpp b/CCallback.cpp index b7543f7ff..0bedcbbee 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -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 CCallback::battleGetAvailableHexes(int ID) diff --git a/CGameInterface.h b/CGameInterface.h index 826c14447..0c968f1ea 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -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 &components)=0{}; - virtual void showSelDialog(std::string text, std::vector & components, int askID)=0{}; + virtual void showInfoDialog(std::string text, std::vector &components)=0; + virtual void showSelDialog(std::string text, std::vector & 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 diff --git a/CGameState.cpp b/CGameState.cpp index 1e2babdc3..5a811c9e6 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -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; diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 5337d1e75..63abf480e 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -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()); #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(1, new SComponent(SComponent::Etype(baseType), type, bonus))); #else #warning error here! diff --git a/CLua.cpp b/CLua.cpp index c4696b3e3..c18781346 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -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(3,os->ID) << " " << std::pair(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) diff --git a/CLua.h b/CLua.h index 8c6b342d6..707ed0ba4 100644 --- a/CLua.h +++ b/CLua.h @@ -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 diff --git a/CLuaHandler.cpp b/CLuaHandler.cpp index 40e0a81ff..68eabcf80 100644 --- a/CLuaHandler.cpp +++ b/CLuaHandler.cpp @@ -79,7 +79,11 @@ std::vector * CLuaHandler::searchForScripts(std::string fol) std::vector * ret = new std::vector (); 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 ( diff --git a/CMT.cpp b/CMT.cpp index 399c38d06..acb16861f 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -7,7 +7,7 @@ #include #include #include -#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 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: "< &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;tichecksum != sum) { +#ifndef __GNUC__ throw std::exception("Wrong checksum"); +#else + throw std::exception(); +#endif exit(-1); } std::cout << "\tUsing random seed: "< struct StartInfo; class CGameState; class CGameInterface; diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 4a7e3059a..bc03213db 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -21,7 +21,7 @@ SDL_Surface * Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface char * buf = new char[10]; for (int i=from;iprimSkills[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 >::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 >::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) } } } -} \ No newline at end of file +} diff --git a/hch/CDefHandler.cpp b/hch/CDefHandler.cpp index ed9261e361f9ed877dfbd25c3a7b4235db4cb83c..df5e44f9525c134a33dc981b98d0cf9036b7c382 100644 GIT binary patch literal 13775 zcmeHOdvDuD691b4@*TDP$D!i%f>|p1c0!EFHPf&U0Njs16S=7g2>_Q`i(yQiwtA`LlP=pLx+(_@51GB9p~3OT;c#dJH@Ss*s*;rco?~-)hkk&kO6p zkcRaF0{Qj%vkEWHgRjYSI;Rl4k<8t(vxj3zTAXH5zMfAAava9FTto4{ zYe|x9M3(vPbVf3kg%tfOL4za%0a!*Ds)VuQ7SM3F3TVa+pu;kQDoxSsIL(Al+K+;r zBN27eW%ha=PGsKBqkHMsFxF_$ns@lm+*yczbk!b2#XMXvP6qJcUO$s|E|=Lj97=y3 zG|~0EH8X*B6wibG=)X4Ot2~!U5ry&LA*|c1RYMpOdK!AW101L_pfMZB**7i z8PIY(>($tS>e*uw(O7LhQ5O;USt4&lWdgRLmAPp31Tp6my7usAEc0tk1)AoEhl3~y zvpWsk>g7_-CjO2CAd?Zy-046ZF-wz34uMy31G-V(>J>7MC*%tRg@`Z`u}mh#la3t%VV`q(w>uAV#l?US>|PtKlV zmKmbmP3-L}{#Y^{XTcz8(?q3vic0rgM|M0qj2rcP?zRJ&4eId}h3nu_leN+ATG7(O z4HxZ^xK@-s&n{am^Xbona5(dM=+3XPH+kUeYZAoJffO3E2@Mw6I|3^uo+6B)T)U$HV&*(-hyInEpKiJWA7LGE35% zWEaFA#Pt=;cpDSJg9V&xe#cBu3b41802CXv#QR$<&;opTiZPb`bLSXsKuQ{1b!%N6 zY^5vCfPW<;8@?$I{tn5=vC+rOMx1O`a!K_RcS9`+Q^%`=Z<6Wu!(DNbCi*zn>5x{6 zER6YYLC2!eJx-t@+-$G@&&KY~PV1mP;5C%>I-OOzIAa5rj%}5hzFNbTb!7qvJ+;If zf{ksiRiSd-1ZB}B)PidItk;HoRPuM5LeWxXK{WOO{u!UKxs>t-h^Bl-rCs5) zW9C#tQH#bO$7xv9a9n6AOs!qU#SurjjTuL}?4h2DS}j|=um)vbP}obdjvvk!iW9Jb z-a$~%oGNQF(F%lbfNFJs@&tZ&0y?dLL1GdssU?J87{S29W4gRu;QUwBh&XRnHT|VH zK5JIZA~1HLjemRwj{S2C?cBcFsfk`sd_^1_)6qx`@180KNJgj8b9m?`DCJ*^Grm+~_4dZC2xggXK6iNkYdVn$lZiZ2h2#c(u9dp1zqOP(D6)@bnQLP)& zT_eD_$1PrH1bjO6V@2O~>pr>Y`@0!_;eJaYs%4s-d2&v#8e1*!uE zcQ$ao;f}5cJ4BP;q>rRz*RnAKN?VE4^Q})w!6=Pj0rz zF3~{^+<@RTj?CeLAV+dcl-HJrY&$rP>M~iiu=lU+NV%YoA4IBX9V2f>>^i|_=+YlH z!&(>F4C=TRfJ?Qsw2!J*TuYSX$t1A3)W}SVsyePw?9vJ&2GSP6ITXe+^g(ieE zSCfsvAzxiV4b9~wz7vQF2nNex5v57H-4<`(ynJ(rs33o%V>wDiRGu^C?`%N+gj3Nk7=JkPIF8Q1Em*xTx9YOUUoSV3m5 z)dIy2XAd}x@J)aT0(O{pgonnhllPP(@x*HGvOqR{>4KsJqyqK2YjU+EE;EV^mSW&7?dxC_d!}E}XT&BZ~g*Tmi1CibL0ncPajS z0$zM!?qRW!=^%(O*>_!8U9W8K>lPm!pDKk#=}Pu$svOeA!~5>65`k0oq*=q|Lhaj+ zz6YxXq0TzqD5bz=T+*rO)a6MjkKJxwrPg~Kj0AM?;qL16l#`$(SH=Z(gA-Ix^KA}u zS1#BT7gu8h+Hx8LhY3V)w<>PT8oRY#;6x+MA2ebQ`uME80KXk|RC#Ue9(C|X(^{eO z091j|9>pIzGpbK2I6t`8swf47=#onlGAlNz#jykU)QeGjt&g}3C%u%izmHJA^4lgW z+IFKp7bl*lP8Y5LT2(UTUfDXrJAh7Z*`%SBgv#E6T(L2kH1q-K!%}y7BV+>wOKzVK z3{8uRS#uN1pDzKeNk3&Dg5rX$kDlV)0)4#936FGMXsYxfKQs@Op`)4^qWWIlcOp<{ zf6r_V!wNDN?EhHq+S9L9(5~i?Qc}XI@`19D#kljnX|&TRF+Gkp(&6^gO>Wg5$1uff zfw;adTOFb!_EiJcTj_`V62?mcc9R}DW&67|oMX8MiC|9+JKzk0e>}{D>MkFNSxmc( zjE+v~1|KW84fU%TP`{4?3_9ODm3Dp`7Dz%BxL1i*gL@-TVsbwERcx6v$hVvr|8#_Q z06)cKVD_s@2IdJ)_Gu@BeR6(wXfh`CM09(^_DBBgXKfovVT(^RO>BRJ`YZDD3yptx zo863W3nX66KzI9lc}IwFMMrm{7bhog&fZ*n z|LWgOO_LV@zLsc)UoPP9JE*t$>6X=90Gv8GR%WP_VZGSbBmreV z)2#Ew3ryjrhr?QxMZ=-~R?RAZljs)-b}C;yKtrEi?`#U^+c#L3b1Rz4Y$`|)d_FTH zW=gjwro>zIcu*Iku%NeF^paMO2%qA$dAdFzYOG!7{uu-ldflCB24`5kPoGR%J^EIH z^O7gwZ_;I_MMgkjyqJb>voOi&MuYD>%vWm6OZoVE46W7LCgUa~0E+*LH6BqM?D+n= tTSW|u5qU>UP}A=L7y}uj7@cc=$?mv@YW1p)MzgwALem=9@mz9?{{fguVut_# literal 27552 zcmeHQ`%hfQ6`o(WQvZidtJdpaaAGHY#Nf(cJBi}B5+sT$8byEsFJM4`V;d{|)7yUE zJ^SsMxik0fGsblhTG+jJ=FFV;W6oXv^Y7n>emD+0;V8Te&%$o#hTnxH{M-)b;R08- z!d`fd&(CrFx8XOTG=3vI3{OUkS;LrJ!1@Xhj{)}xpUzt6EMo`U!x=_yg%{y|~;+t#AutN$m^#-3~V^C~vFZ9bDhT)n53hy3?(&z5q|oFuof;9jw`jAn)KhceORV z_X<1hSCl2BMf_-$PUv9V#~8me98J3V3WD-WwV!6Xl<)Lv*xZKvJRWeoM7vH{4?l!Q z6)i~RU2wW-+>^1!9fR^0Sd&=ohOZ$n`$L#}!2JlHb_ckR!tq}Xa#6xkd=s|DRnnU@ zphi*BDMj6|8GgiXjWj88&gT?ySS2|5_#9%LcB3HH$JZg2sq9c=nbO=naOMnn_lC0H zha7$aUQipBahFm~j%|Twl!PU``r#7qNpTyu5Ece9)(LM1I^(p-E!6b~dX0P-b?j9gGWG_>%YI%~`2g6wWl+)ZbK6AAv5EVp@=XCDXK2 zF0J|fy2KhUa!!oLhdy}VT$nfI4A-AQyFT=$%{HIFHj@hGQF@>WJr!wT{(?4^cKH}I zdV!H9pOP9`;6Ci}L1mLKu;xWY&#y6OwX(50;c#dvcVJhyDj8mdZ0zBOzH1X!`7UHk ze5a1?fupwO%5ZhNPv1#-HS2Fa&_-&$V?mn|d%i9#H+4le@)#?Z*BkC`2~z&kU^ULVl|VhgC(@N#L~5ReHyEQGb4P?rncM}v_MxwzG(aG~o>gM?f@LuRrH0m)+`jJ8wN3SCg~1lKO{o_jhRtn?ChX}R|Ccej#ZmmG3Xmfx@v7n^5o0zRo`azaTH zzVv5|EVwW8EtK;YxIzwfYnY2VJp5+plrcT-_hne$KgBRM7g!Q!scm(Eq8SUtvds5 z)acLf5?<~*R&ZS~_po15?+1*3R>{eH;eLgkQU;y__Ix0lzkChe2?w`WZmnb;W}}Zd zNDuuQ7S4H5^5Yi+Pfj1Z9PWhA!=JE6eu_QC+W|K_;3B!jc!*LGc7n#5vv} z1h=lubHAKn?&=J49}ng_h2*=%ue%BToM(@q)y!)w?zLFR=$_N~au_RJg2E0X<~!}e zWdp@Y$5{G15scK^%|}){un&s&4zTh@Eqc#myMqL;lr{^EyCu#C3C@h3^3_hE?dQJ{Gs8drs+C+L>!W3{TO(;ef}7paf%zd)TGv zPZ!Zh9B~{%BUXm?&9sEqxTZ-EsbDx5B){rdo7`bPA z)6yu$Ve;LcU>A&=XkDg}Wv5iGGtz9!>Rb!!bX$pNT9*pJH(GfN{v6V&e2DL3Ew97q zR&v2no^!>rH9pmt8|}jeF;k&eXC>h>lKM`yQWK`R42VL)j=Jx1P~TT>1t{+aL#!O9 z`piv?;@%~jw)0V=xZX=x0E?RN6s9=J64eq6Smg7Pmwd*)2-@O+L#%rogFV3gZ*t?W37H)*_CuE8kou>GZVK7&K; zog_D9CF%rte+#@7m-n#mW5{4rhQJ(jyNZt(k$ZM$QcKx--?Ccz8l#yvpuIxS+i!(2u81v#)qT*VH#i8qb!d~z6K>c6DmdC^T`QH9Jn(_4k&I& zd3<+{E2JFo$ZQf?dQ=ui{M!4ZS&U1~bsoc055~WYY^TX%oR%K{SSDDK+|TAHSBkQ( zGb76(JaQFf^!GY5VqX4!XGUc`Qf~2~N9-a z#>s)!k!Es*QTQ^dQWa^ObDDS^uUSvBN}6-Zzj~GE0N%kXDvXZ|PsTh}J1JF9Vm#Wi zPo4(xEJ>$IJwPYFV!UF{(nn>a2kwwcA7NkGy;r3=m}{}ApQFkWdQXhMW4%FjD0R{F zunI@;jO*s$bm3OAr$y}3_vJB;B#71~#)0E4ySzW3W*?HWIFP}(FF+6|+04Hc?NO3% z19#i6uiY6?gRu;2v_4OA*Ma1+0ND)~ZOqWwisg8sq;Wu9LiWjK z+lX;07P~m-;kk^}x!Pp*DP*GU{vUzYDtaj>Iits|52*fjP`Tzz)8roHsT&B5XHbvu z`zGGsuTHQ(A6CCs(L-e8Px~v_R39$bo))Q4=;%*P| ziE*XvixnEfYZDSg3N2L9pUW}3$*KuaarPZ1>3w9h=}XC+@J0=%a6`Cj%h_AzN> z(TAl&{nE#Y_N_@QUW%w{%H;U70$tK(>@YqIqW#9tV z#>SgYIJIr$Y?i|+%a&opT{x5k@7pv@j;~M)B**2*U~&UH1$R1ml>Gn6Cjja5MIT)j@h zxeMs*<=)4Lb4VY1mCg_=v%l)HiiYXw+2zFE9nyUtT0=PO1=dPWapg6x#1yXc$M*1` z!YAfzo1ShY>#47Ydr$AwF;i4QpC7M9n_rTjyzgKWE4aMZ>nzfKStZhJ1N_pVF!VIF(Vt;jr} zmaUdS7GGo9FIKwema%@XguS$-$>yc2rTnO`m*36l5^Fr|xx*ja zb66VoD0LAv(88<7@>ylAS!b~>0CuLI4e)5D#&VT8$)=YvC7vZpipK`MELG#eFVEHr zwmpAzS0dmC$x^;KR|`+QR3@eyP6|_F1pWnmz~u0---;a z+AeGqH?j+Rv|k}ycFD3ExXo9yCKN-icZ%P{{a7=#o031ajzDTu>8{bbpFp$N&Ff!j zcBdTDYG0+!8S!Hcn!{L=l^0q$Ngex1`TQBLb6V+?&aqcH(sGtGOAe4PF}857>Yigd$7mDG_4-N zQ0Ls9z8&hG#^;v&el$L=wsi)3j`I_7oOxFcDbK!AcqNFcpt5?J+m?laCAo)6Yns=Q z#-wuEJs(s26f}Abp0R2{T5bX#voM6jdf<)lPvCwd;eS73 zM8;|Fk@0}HcVzUO7O12?slp;si{Jk<~ki%kdtA=R>wE3 z#;Il%KY3E(Pww5=eHT|4NhwtR1T@I^QmQUU+ z<6R0r-nBoQqfE2B!mJ*4R2*SX{iJ*FXrk9D2@BQpMf4UtPl|1i=cn={hMoP+PxN(H z-btU!($Pj&_HEp&YA39pqYW5tGTvsI?D^xkP=9S*0c2 zh4jJb8RJI&kiL_|xTJ6?dm*fpn(g*y7Eb+wTG(^=wjcv6Qrxmx*1JVwpj1d_q62EpYuGwXOW@$ zpnRmL)|9cNbd2pn?xW&}u?b!tG1h&14)^`9i^$H1nx*Wg)DNNYdCoE|-E&AECdHe- zp-I_KUOT?(e5e$4wB-za)J@qn%Idvma2^BQ#di{hu`Nx`R5rBE5JW z$$O_*MY6R@*eVyQf49~q;^JRB8)aNk+S4?8$`s7Jyx6+`PlbzNxr=L-SXZMOAQ#0fIQIW0nl=1sD*cr+* zU;l zTTAAeZaMN#<7YeX6BWe6REpX$ZPO;^Au%^SKl%l7G~YZ!cB>r6&tkdC5U<8|3CsVV z%%JXHT{iP?Wi%Ukof+JOJ+|HoJCmNziK*6&$~LUxsLgb?(DyuHs+_7=vDISnx>W=o$3&pwJ zTBUB@XGV(t%9&Rh0ZvwhDnq=^<@od>yI1FvDbRzg7$>p=uYRf3jX~d!(fe{-$TAz zJ&or`N(xVd$5M*N}k}g9=<^z+drz+Vmy5XqiFeQV6*$IlIcm){QnG$dJ>i2p>U4f zT8zU=s{elnLY7vHTEX^dQlN9F<~j0ME-(4FNgAyDy5{ox)|&pW2%m9|qqR0F63du| zUqPz)^es=F`3wS|U=}9nJ$^?4pGy51BOl_$=#tM9mHy*_RX_CYos@|3|Gu&H&ZAQ= zRkOtji+n!9N`5lNG3j%(tdYlAcuO zWvUs5$B3BA(vs4+7sU>o!yV{y#U1c~x~3aDF%-T93+d>%};!=Ll0 z|CgGwztXyr&s65PqTR80OthI?V?}?HIGg`2w5dPdi{=?D2NJB`VuzhIP!tzpDNJB|F`k{=X*k?zpEE!2|o0RUi?@o4J zoWK|%k$pPdJ@?$B%ZW^Mj0p^eqwAX=li_$YeZFZnPRJ%T9+;($R1qT_ce}kvNz}eK z=u4l8{6^?lq3te?n+@k}5qX#m$Ir9ECL+R%W+PIPFh1y!jCawaIZ4+Q1 zGm&Dm@zHD?N$nxErpPBnHb+ZtN6yFR=aft86l69L8D2oIr)h;Z=@+K(fbSl)lSY&K z4jgF1JfNm9pCRKGU4VD9?z@%-gu!#nlhs605SHk%&`N(+*c-gA!|}7^(bS% zC?9W7rVGz#=f)@yN}0DQ=7P#$BUhzRr+&e2{k!{nq0oDTyj-8ozJB|~TLo2-YK(zT zv|;*K!B__&(|E_U?f{#Xbo_(9HNKc7J{u62Bykw5P%`CokqoM$DS?!pjH-+x`;x8PV!7RJ_|lk{tK215sgza@*l5bt#4` zFonHkSvba4k(w{WgB98(#%36AHnj2A7V$Pq*_qr~eN}&3r|kCUz)~T8H8KXmNo=mOHh~x0n05tB^DvYn1(G)crZOnX=Tv9ppS2X|I_#jK5`K+ literal 3272 zcmb`K-D?w35XI*;g8#!}L8^#?pbvh5t%^bo(kecPNRr*Ot7$eQ+g2_5r>nnnCpS0S zY?D4nNcQ8-%sq4F+_^V@|7=-lLmOLe1=q}W?S;LxSN7VTTbKJip7!kv&)4mmZO!dU zJc=t=%WhyJI|+W7-LSiS?uBYv}-${sO{K#Hese-z%yceiuDm*ntO)Dlt=@v znH>adU$~y|c8Jda`^UjjGxo5b%@HcIm*LrGEEyfO+U{8e(k23rxr$&H%tCy~yc#_Z zza8ExtBm(kqMeXYm)~RShkQI*CuEb`BR-y&ybkeF%q~%nLpB-g++)O_Gdl}B9fi1> zqpr)F#f z_hLl01vu}3!8P{Ye!xx<-X!ZCJSuQ}o7)ayZ^Y*#{yA}uf_;4Z8vhdJju?sD_VKUq z$inQ3c7}!v=IUW9EYUL7N?H^DiXO*y?5(}yqYMg0lw%fRq~}j|-yYaQ`@HZvA&zQs z$h82kD(ZR=_xohgWFyYjw9=|u<}6xWTm#YS$DI4~`So&rMJ>gMNv{>FWC(WUx;mQF z9LIiy7eu54Y!e`j0XV*fCFo5|UKH@7k@ftam-t?WIgFdw=i66D5 zd8IzRQ}1e9zpnZN{G~uuG1WNXc4k!ttwQgHaUDvr17@G1+mhc+Sub}6WvwnSwKt1y zFV#c#o|*;EZaBMRkI_#beB9O{bnRUWDj}_&7H4)d{^^y|1}`x9!#<+V3ma zG&w$HR#iwVL43Nlx0yLApbGawrLL9PO}@^qzY&|!Z%mBk=RO^whHG`Qgfd!t%$)w{ zyl7>1iICa$BI1NG?=jKKWA28Snrn51ChcjBI@YH|{(zqL0=`tI0SMJ2rMRbXD-2pQ z32l?F^|PG?4yDO;IkmIo8KrsKcSKje_NbcGm)5{CX9uXqPXOOTw(BuxXzm5^h9PI) zp?<={1WsnK`<1bb?yWtz=BlTPuWWL@V;Gb!#@I^RQ$}Qy2df+SXqQmGt=awi*i7ap zfDU_2RA0s0f*6iuS$|$XRbMMP_PfMWilN<8dxCP`UaN~PysTqI8sC{~WwYJ>l3Eg) zn2}a=Mb>Z0@0hzOe62?()v6DwJNj-a4%$u^t8D1J*M2^7<){|Yx7N9zo61nH)J444 zG*us?Hakz$qRtG(#>%bs;C20dMkP~!Ppdc8y&d7|xv&kTTV1ZQ|BH3gd8`ey&WT>h zi=4+Zqn|DPysDG2dh7^oseb2cci6U_{px#M+GAF6ClxK{ycP78qc{B{QD&R|m;3|g C2NNs+ diff --git a/lib/Connection.cpp b/lib/Connection.cpp index 3e84ea82f..ee5234704 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -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 > * 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(const std::string &data) +{ + *this << ui32(data.size()); + write(data.c_str(),data.size()); +} + +template <> +void CConnection::loadSerializable(std::string &data) +{ + ui32 l; + *this >> l; + data.resize(l); + read((void*)data.c_str(),l); +} diff --git a/lib/Connection.h b/lib/Connection.h index 67a7fa14d..360df35b9 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -12,6 +12,8 @@ #include #include +#include + const int version = 63; class CConnection; @@ -190,30 +192,19 @@ public: read(&data,sizeof(data)); } + + template void saveSerializable(const T &data) { - const_cast(data).serialize(*static_cast(this),version); + const_cast(data).serialize(*static_cast*>(this),version); } template void loadSerializable(T &data) { - data.serialize(*static_cast(this),version); - } - template <> - void saveSerializable(const std::string &data) - { - *this << ui32(data.size()); - write(data.c_str(),data.size()); - } - template <> - void loadSerializable(std::string &data) - { - ui32 l; - *this >> l; - data.resize(l); - read((void*)data.c_str(),l); + data.serialize(*static_cast*>(this),version); } + template void saveSerializable(const std::vector &data) { @@ -231,13 +222,14 @@ public: for(ui32 i=0;i> data[i]; } + template void saveSerializable(const std::set &data) { std::set &d = const_cast &>(data); boost::uint32_t length = d.size(); *this << length; - for(std::set::iterator i=d.begin();i!=d.end();i++) + for(typename std::set::iterator i=d.begin();i!=d.end();i++) *this << *i; } template @@ -252,6 +244,7 @@ public: data.insert(ins); } } + template void saveSerializable(const std::pair &data) { @@ -262,11 +255,12 @@ public: { *this >> data.first >> data.second; } + template void saveSerializable(const std::map &data) { *this << ui32(data.size()); - for(std::map::const_iterator i=data.begin();i!=data.end();i++) + for(typename std::map::const_iterator i=data.begin();i!=data.end();i++) *this << i->first << i->second; } template @@ -334,4 +328,11 @@ public: int read(void * data, unsigned size); int readLine(void * data, unsigned maxSize); ~CConnection(void); -}; \ No newline at end of file +}; + +template<> +void CConnection::saveSerializable(const std::string &data); +template <> +void CConnection::loadSerializable(std::string &data); + + diff --git a/map.cpp b/map.cpp index f1c50a1b8..fa25e279e 100644 --- a/map.cpp +++ b/map.cpp @@ -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(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(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; eefirstVisitText += bufor[i]; ++i; } - int len2 = readNormalNr(bufor,i); i+=4; + len2 = readNormalNr(bufor,i); i+=4; for(int ee=0; eenextVisitText += bufor[i]; ++i; } - int len3 = readNormalNr(bufor,i); i+=4; + len3 = readNormalNr(bufor,i); i+=4; for(int ee=0; eecompletedText += 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; isubID == ID) return heroes[i]; diff --git a/mapHandler.cpp b/mapHandler.cpp index 340dcf3ba..f23d428b9 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -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 } } } diff --git a/mapHandler.h b/mapHandler.h index f8e145678..5b1d4f664 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -35,7 +35,7 @@ public: int offset; std::vector inver; PseudoV(){}; - PseudoV(std::vector &src, int offset, const T& fill) + PseudoV(std::vector &src, int rest, int Offset, const T& fill) { inver.resize(Offset*2+rest); offset=Offset; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 602c5acb3..f5314bfec 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -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 +#include +extern bool end2; bool makingTurn; boost::condition_variable cTurn; boost::mutex mTurn; @@ -54,9 +56,10 @@ void CGameHandler::handleConnection(std::set 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 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 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 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::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 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(p.total_seconds()); + cTurn.timed_wait(lock,time); } } } -} \ No newline at end of file +} diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 54043d3e4..8641d0a7f 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -1,9 +1,11 @@ #pragma once #include "../global.h" #include +#include "../CGameState.h" +#include "../lib/Connection.h" class CVCMIServer; class CGameState; -class CConnection; +//class CConnection; struct StartInfo; class CCPPObjectScript; class CScriptCallback; diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 919123807..f69159bbe 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -4,7 +4,9 @@ #include "../global.h" #include "../lib/Connection.h" #include "zlib.h" +#ifndef __GNUC__ #include +#endif #include "CVCMIServer.h" #include #include @@ -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 diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h index c78af3c63..9263988ab 100644 --- a/server/CVCMIServer.h +++ b/server/CVCMIServer.h @@ -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(); -}; \ No newline at end of file +}; From 038dd90517f67fcad2e9beeff99d95e436e88f89 Mon Sep 17 00:00:00 2001 From: Vadim Glazunov Date: Mon, 4 Aug 2008 09:33:08 +0000 Subject: [PATCH 41/47] Autoconf/automake scripts to easy building. --- AUTHORS | 0 ChangeLog | 0 Makefile.am | 48 ++ NEWS | 0 README | 0 aclocal.m4 | 854 ++++++++++++++++++++++++++++++ aclocal/m4/ax_boost_base.m4 | 198 +++++++ aclocal/m4/ax_boost_filesystem.m4 | 108 ++++ aclocal/m4/ax_boost_system.m4 | 118 +++++ aclocal/m4/ax_boost_thread.m4 | 147 +++++ client/Makefile.am | 83 +++ config.h.in | 190 +++++++ configure.ac | 78 +++ lib/Makefile.am | 32 ++ server/Makefile.am | 16 + 15 files changed, 1872 insertions(+) create mode 100644 AUTHORS create mode 100644 ChangeLog create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100644 aclocal.m4 create mode 100644 aclocal/m4/ax_boost_base.m4 create mode 100644 aclocal/m4/ax_boost_filesystem.m4 create mode 100644 aclocal/m4/ax_boost_system.m4 create mode 100644 aclocal/m4/ax_boost_thread.m4 create mode 100644 client/Makefile.am create mode 100644 config.h.in create mode 100644 configure.ac create mode 100644 lib/Makefile.am create mode 100644 server/Makefile.am diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 000000000..e69de29bb diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 000000000..e69de29bb diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 000000000..6d07a0bed --- /dev/null +++ b/Makefile.am @@ -0,0 +1,48 @@ +ACLOCAL_AMFLAGS = -I aclocal/m4 +EXTRA_DIST = aclocal/m4 +#bin_PROGRAMS = vcmi +#vcmi_LDADD = $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_THREAD_LIB) +AM_CXXFLAGS = $(BOOST_CPPFLAGS) +SUBDIRS = lib client server +#vcmi_SOURCES = \ +# AdventureMapButton.cpp CGameState.cpp \ +# AdventureMapButton.h CGameState.h global.h \ +# AI_Base.h CHeroWindow.cpp int3.h \ +# CAdvmapInterface.cpp CHeroWindow.h map.cpp \ +# CAdvmapInterface.h CLua.cpp map.h \ +# CBattleInterface.cpp CLua.h mapHandler.cpp \ +# CBattleInterface.h CLuaHandler.cpp mapHandler.h \ +# CCallback.cpp CLuaHandler.h nodrze.h \ +# CCallback.h CMessage.cpp SDL_Extensions.cpp \ +# CCastleInterface.cpp CMessage.h SDL_Extensions.h \ +# CCastleInterface.h CMT.cpp SDL_framerate.cpp \ +# CConsoleHandler.cpp SDL_framerate.h \ +# CConsoleHandler.h CPathfinder.cpp \ +# CCursorHandler.cpp CPathfinder.h \ +# CCursorHandler.h CPlayerInterface.cpp StartInfo.h \ +# CGameInfo.cpp CPlayerInterface.h stdafx.cpp \ +# CGameInfo.h CPreGame.cpp stdafx.h \ +# CGameInterface.cpp CPreGame.h tchar_amigaos4.h \ +# CGameInterface.h timeHandler.h \ +# hch/CAbilityHandler.cpp hch/CDefObjInfoHandler.cpp \ +# hch/CAbilityHandler.h hch/CDefObjInfoHandler.h \ +# hch/CAmbarCendamo.cpp hch/CGeneralTextHandler.cpp \ +# hch/CAmbarCendamo.h hch/CGeneralTextHandler.h \ +# hch/CArtHandler.cpp hch/CHeroHandler.cpp hch/CSndHandler.cpp \ +# hch/CArtHandler.h hch/CHeroHandler.h hch/CSndHandler.h \ +# hch/CBuildingHandler.cpp hch/CLodHandler.cpp hch/CSpellHandler.cpp \ +# hch/CBuildingHandler.h hch/CLodHandler.h hch/CSpellHandler.h \ +# hch/CMusicHandler.cpp hch/CTownHandler.cpp \ +# hch/CMusicHandler.h hch/CTownHandler.h \ +# hch/CCreatureHandler.cpp hch/CObjectHandler.cpp hch/CVideoHandler.cpp \ +# hch/CCreatureHandler.h hch/CObjectHandler.h hch/CVideoHandler.h \ +# hch/CDefHandler.cpp hch/CPreGameTextHandler.cpp \ +# hch/CDefHandler.h hch/CPreGameTextHandler.h \ +#client/CBitmapHandler.cpp client/CCreatureAnimation.cpp client/Client.cpp client/Graphics.cpp \ +#client/CBitmapHandler.h client/CCreatureAnimation.h client/Client.h client/Graphics.h \ +#lib/VCMI_Lib.h lib/VCMI_Lib.cpp \ +# server/CScriptCallback.h server/CScriptCallback.cpp \ +# lib/Connection.cpp lib/Connection.h \ +# CThreadHelper.cpp CThreadHelper.h +# +# diff --git a/NEWS b/NEWS new file mode 100644 index 000000000..e69de29bb diff --git a/README b/README new file mode 100644 index 000000000..e69de29bb diff --git a/aclocal.m4 b/aclocal.m4 new file mode 100644 index 000000000..ab2ad391e --- /dev/null +++ b/aclocal.m4 @@ -0,0 +1,854 @@ +# generated automatically by aclocal 1.9.6 -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +# Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_AUTOMAKE_VERSION(VERSION) +# ---------------------------- +# Automake X.Y traces this macro to ensure aclocal.m4 has been +# generated from the m4 files accompanying Automake X.Y. +AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version="1.9"]) + +# AM_SET_CURRENT_AUTOMAKE_VERSION +# ------------------------------- +# Call AM_AUTOMAKE_VERSION so it can be traced. +# This function is AC_REQUIREd by AC_INIT_AUTOMAKE. +AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], + [AM_AUTOMAKE_VERSION([1.9.6])]) + +# AM_AUX_DIR_EXPAND -*- Autoconf -*- + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets +# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to +# `$srcdir', `$srcdir/..', or `$srcdir/../..'. +# +# Of course, Automake must honor this variable whenever it calls a +# tool from the auxiliary directory. The problem is that $srcdir (and +# therefore $ac_aux_dir as well) can be either absolute or relative, +# depending on how configure is run. This is pretty annoying, since +# it makes $ac_aux_dir quite unusable in subdirectories: in the top +# source directory, any form will work fine, but in subdirectories a +# relative path needs to be adjusted first. +# +# $ac_aux_dir/missing +# fails when called from a subdirectory if $ac_aux_dir is relative +# $top_srcdir/$ac_aux_dir/missing +# fails if $ac_aux_dir is absolute, +# fails when called from a subdirectory in a VPATH build with +# a relative $ac_aux_dir +# +# The reason of the latter failure is that $top_srcdir and $ac_aux_dir +# are both prefixed by $srcdir. In an in-source build this is usually +# harmless because $srcdir is `.', but things will broke when you +# start a VPATH build or use an absolute $srcdir. +# +# So we could use something similar to $top_srcdir/$ac_aux_dir/missing, +# iff we strip the leading $srcdir from $ac_aux_dir. That would be: +# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` +# and then we would define $MISSING as +# MISSING="\${SHELL} $am_aux_dir/missing" +# This will work as long as MISSING is not called from configure, because +# unfortunately $(top_srcdir) has no meaning in configure. +# However there are other variables, like CC, which are often used in +# configure, and could therefore not use this "fixed" $ac_aux_dir. +# +# Another solution, used here, is to always expand $ac_aux_dir to an +# absolute PATH. The drawback is that using absolute paths prevent a +# configured tree to be moved without reconfiguration. + +AC_DEFUN([AM_AUX_DIR_EXPAND], +[dnl Rely on autoconf to set up CDPATH properly. +AC_PREREQ([2.50])dnl +# expand $ac_aux_dir to an absolute path +am_aux_dir=`cd $ac_aux_dir && pwd` +]) + +# AM_CONDITIONAL -*- Autoconf -*- + +# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 7 + +# AM_CONDITIONAL(NAME, SHELL-CONDITION) +# ------------------------------------- +# Define a conditional. +AC_DEFUN([AM_CONDITIONAL], +[AC_PREREQ(2.52)dnl + ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], + [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl +AC_SUBST([$1_TRUE]) +AC_SUBST([$1_FALSE]) +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi +AC_CONFIG_COMMANDS_PRE( +[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then + AC_MSG_ERROR([[conditional "$1" was never defined. +Usually this means the macro was only invoked conditionally.]]) +fi])]) + + +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 8 + +# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be +# written in clear, in which case automake, when reading aclocal.m4, +# will think it sees a *use*, and therefore will trigger all it's +# C support machinery. Also note that it means that autoscan, seeing +# CC etc. in the Makefile, will ask for an AC_PROG_CC use... + + +# _AM_DEPENDENCIES(NAME) +# ---------------------- +# See how the compiler implements dependency checking. +# NAME is "CC", "CXX", "GCJ", or "OBJC". +# We try a few techniques and use that to set a single cache variable. +# +# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was +# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular +# dependency, and given that the user is not expected to run this macro, +# just rely on AC_PROG_CC. +AC_DEFUN([_AM_DEPENDENCIES], +[AC_REQUIRE([AM_SET_DEPDIR])dnl +AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl +AC_REQUIRE([AM_MAKE_INCLUDE])dnl +AC_REQUIRE([AM_DEP_TRACK])dnl + +ifelse([$1], CC, [depcc="$CC" am_compiler_list=], + [$1], CXX, [depcc="$CXX" am_compiler_list=], + [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], + [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], + [depcc="$$1" am_compiler_list=]) + +AC_CACHE_CHECK([dependency style of $depcc], + [am_cv_$1_dependencies_compiler_type], +[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_$1_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` + fi + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + case $depmode in + nosideeffect) + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + none) break ;; + esac + # We check with `-c' and `-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle `-M -o', and we need to detect this. + if depmode=$depmode \ + source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_$1_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_$1_dependencies_compiler_type=none +fi +]) +AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) +AM_CONDITIONAL([am__fastdep$1], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) +]) + + +# AM_SET_DEPDIR +# ------------- +# Choose a directory name for dependency files. +# This macro is AC_REQUIREd in _AM_DEPENDENCIES +AC_DEFUN([AM_SET_DEPDIR], +[AC_REQUIRE([AM_SET_LEADING_DOT])dnl +AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl +]) + + +# AM_DEP_TRACK +# ------------ +AC_DEFUN([AM_DEP_TRACK], +[AC_ARG_ENABLE(dependency-tracking, +[ --disable-dependency-tracking speeds up one-time build + --enable-dependency-tracking do not reject slow dependency extractors]) +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' +fi +AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) +AC_SUBST([AMDEPBACKSLASH]) +]) + +# Generate code to set up dependency tracking. -*- Autoconf -*- + +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +#serial 3 + +# _AM_OUTPUT_DEPENDENCY_COMMANDS +# ------------------------------ +AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], +[for mf in $CONFIG_FILES; do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named `Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # So let's grep whole file. + if grep '^#.*generated by automake' $mf > /dev/null 2>&1; then + dirpart=`AS_DIRNAME("$mf")` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running `make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # When using ansi2knr, U may be empty or an underscore; expand it + U=`sed -n 's/^U = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`AS_DIRNAME(["$file"])` + AS_MKDIR_P([$dirpart/$fdir]) + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done +done +])# _AM_OUTPUT_DEPENDENCY_COMMANDS + + +# AM_OUTPUT_DEPENDENCY_COMMANDS +# ----------------------------- +# This macro should only be invoked once -- use via AC_REQUIRE. +# +# This code is only required when automatic dependency tracking +# is enabled. FIXME. This creates each `.P' file that we will +# need in order to bootstrap the dependency handling code. +AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], +[AC_CONFIG_COMMANDS([depfiles], + [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], + [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) +]) + +# Do all the work for Automake. -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 12 + +# This macro actually does too much. Some checks are only needed if +# your package does certain things. But this isn't really a big deal. + +# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) +# AM_INIT_AUTOMAKE([OPTIONS]) +# ----------------------------------------------- +# The call with PACKAGE and VERSION arguments is the old style +# call (pre autoconf-2.50), which is being phased out. PACKAGE +# and VERSION should now be passed to AC_INIT and removed from +# the call to AM_INIT_AUTOMAKE. +# We support both call styles for the transition. After +# the next Automake release, Autoconf can make the AC_INIT +# arguments mandatory, and then we can depend on a new Autoconf +# release and drop the old call support. +AC_DEFUN([AM_INIT_AUTOMAKE], +[AC_PREREQ([2.58])dnl +dnl Autoconf wants to disallow AM_ names. We explicitly allow +dnl the ones we care about. +m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl +AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl +AC_REQUIRE([AC_PROG_INSTALL])dnl +# test to see if srcdir already configured +if test "`cd $srcdir && pwd`" != "`pwd`" && + test -f $srcdir/config.status; then + AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi +AC_SUBST([CYGPATH_W]) + +# Define the identity of the package. +dnl Distinguish between old-style and new-style calls. +m4_ifval([$2], +[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl + AC_SUBST([PACKAGE], [$1])dnl + AC_SUBST([VERSION], [$2])], +[_AM_SET_OPTIONS([$1])dnl + AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl + AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl + +_AM_IF_OPTION([no-define],, +[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) + AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl + +# Some tools Automake needs. +AC_REQUIRE([AM_SANITY_CHECK])dnl +AC_REQUIRE([AC_ARG_PROGRAM])dnl +AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) +AM_MISSING_PROG(AUTOCONF, autoconf) +AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) +AM_MISSING_PROG(AUTOHEADER, autoheader) +AM_MISSING_PROG(MAKEINFO, makeinfo) +AM_PROG_INSTALL_SH +AM_PROG_INSTALL_STRIP +AC_REQUIRE([AM_PROG_MKDIR_P])dnl +# We need awk for the "check" target. The system "awk" is bad on +# some platforms. +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([AC_PROG_MAKE_SET])dnl +AC_REQUIRE([AM_SET_LEADING_DOT])dnl +_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], + [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], + [_AM_PROG_TAR([v7])])]) +_AM_IF_OPTION([no-dependencies],, +[AC_PROVIDE_IFELSE([AC_PROG_CC], + [_AM_DEPENDENCIES(CC)], + [define([AC_PROG_CC], + defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [_AM_DEPENDENCIES(CXX)], + [define([AC_PROG_CXX], + defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl +]) +]) + + +# When config.status generates a header, we must update the stamp-h file. +# This file resides in the same directory as the config header +# that is generated. The stamp files are numbered to have different names. + +# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the +# loop where config.status creates the headers, so we can generate +# our stamp files there. +AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], +[# Compute $1's index in $config_headers. +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $1 | $1:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count]) + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_SH +# ------------------ +# Define $install_sh. +AC_DEFUN([AM_PROG_INSTALL_SH], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +install_sh=${install_sh-"$am_aux_dir/install-sh"} +AC_SUBST(install_sh)]) + +# Copyright (C) 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# Check whether the underlying file-system supports filenames +# with a leading dot. For instance MS-DOS doesn't. +AC_DEFUN([AM_SET_LEADING_DOT], +[rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null +AC_SUBST([am__leading_dot])]) + +# Check to see how 'make' treats includes. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 3 + +# AM_MAKE_INCLUDE() +# ----------------- +# Check to see how make treats includes. +AC_DEFUN([AM_MAKE_INCLUDE], +[am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo done +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +AC_MSG_CHECKING([for style of include used by $am_make]) +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# We grep out `Entering directory' and `Leaving directory' +# messages which can occur if `w' ends up in MAKEFLAGS. +# In particular we don't look at `^make:' because GNU make might +# be invoked under some other name (usually "gmake"), in which +# case it prints its new name instead of `make'. +if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then + am__include=include + am__quote= + _am_result=GNU +fi +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then + am__include=.include + am__quote="\"" + _am_result=BSD + fi +fi +AC_SUBST([am__include]) +AC_SUBST([am__quote]) +AC_MSG_RESULT([$_am_result]) +rm -f confinc confmf +]) + +# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- + +# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 4 + +# AM_MISSING_PROG(NAME, PROGRAM) +# ------------------------------ +AC_DEFUN([AM_MISSING_PROG], +[AC_REQUIRE([AM_MISSING_HAS_RUN]) +$1=${$1-"${am_missing_run}$2"} +AC_SUBST($1)]) + + +# AM_MISSING_HAS_RUN +# ------------------ +# Define MISSING if not defined so far and test if it supports --run. +# If it does, set am_missing_run to use it, otherwise, to nothing. +AC_DEFUN([AM_MISSING_HAS_RUN], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing" +# Use eval to expand $SHELL +if eval "$MISSING --run true"; then + am_missing_run="$MISSING --run " +else + am_missing_run= + AC_MSG_WARN([`missing' script is too old or missing]) +fi +]) + +# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_MKDIR_P +# --------------- +# Check whether `mkdir -p' is supported, fallback to mkinstalldirs otherwise. +# +# Automake 1.8 used `mkdir -m 0755 -p --' to ensure that directories +# created by `make install' are always world readable, even if the +# installer happens to have an overly restrictive umask (e.g. 077). +# This was a mistake. There are at least two reasons why we must not +# use `-m 0755': +# - it causes special bits like SGID to be ignored, +# - it may be too restrictive (some setups expect 775 directories). +# +# Do not use -m 0755 and let people choose whatever they expect by +# setting umask. +# +# We cannot accept any implementation of `mkdir' that recognizes `-p'. +# Some implementations (such as Solaris 8's) are not thread-safe: if a +# parallel make tries to run `mkdir -p a/b' and `mkdir -p a/c' +# concurrently, both version can detect that a/ is missing, but only +# one can create it and the other will error out. Consequently we +# restrict ourselves to GNU make (using the --version option ensures +# this.) +AC_DEFUN([AM_PROG_MKDIR_P], +[if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then + # We used to keeping the `.' as first argument, in order to + # allow $(mkdir_p) to be used without argument. As in + # $(mkdir_p) $(somedir) + # where $(somedir) is conditionally defined. However this is wrong + # for two reasons: + # 1. if the package is installed by a user who cannot write `.' + # make install will fail, + # 2. the above comment should most certainly read + # $(mkdir_p) $(DESTDIR)$(somedir) + # so it does not work when $(somedir) is undefined and + # $(DESTDIR) is not. + # To support the latter case, we have to write + # test -z "$(somedir)" || $(mkdir_p) $(DESTDIR)$(somedir), + # so the `.' trick is pointless. + mkdir_p='mkdir -p --' +else + # On NextStep and OpenStep, the `mkdir' command does not + # recognize any option. It will interpret all options as + # directories to create, and then abort because `.' already + # exists. + for d in ./-p ./--version; + do + test -d $d && rmdir $d + done + # $(mkinstalldirs) is defined by Automake if mkinstalldirs exists. + if test -f "$ac_aux_dir/mkinstalldirs"; then + mkdir_p='$(mkinstalldirs)' + else + mkdir_p='$(install_sh) -d' + fi +fi +AC_SUBST([mkdir_p])]) + +# Helper functions for option handling. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 3 + +# _AM_MANGLE_OPTION(NAME) +# ----------------------- +AC_DEFUN([_AM_MANGLE_OPTION], +[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) + +# _AM_SET_OPTION(NAME) +# ------------------------------ +# Set option NAME. Presently that only means defining a flag for this option. +AC_DEFUN([_AM_SET_OPTION], +[m4_define(_AM_MANGLE_OPTION([$1]), 1)]) + +# _AM_SET_OPTIONS(OPTIONS) +# ---------------------------------- +# OPTIONS is a space-separated list of Automake options. +AC_DEFUN([_AM_SET_OPTIONS], +[AC_FOREACH([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) + +# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) +# ------------------------------------------- +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +AC_DEFUN([_AM_IF_OPTION], +[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) + +# Check to make sure that the build environment is sane. -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 4 + +# AM_SANITY_CHECK +# --------------- +AC_DEFUN([AM_SANITY_CHECK], +[AC_MSG_CHECKING([whether build environment is sane]) +# Just in case +sleep 1 +echo timestamp > conftest.file +# Do `set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t $srcdir/configure conftest.file` + fi + rm -f conftest.file + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken +alias in your environment]) + fi + + test "$[2]" = conftest.file + ) +then + # Ok. + : +else + AC_MSG_ERROR([newly created file is older than distributed files! +Check your system clock]) +fi +AC_MSG_RESULT(yes)]) + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_STRIP +# --------------------- +# One issue with vendor `install' (even GNU) is that you can't +# specify the program used to strip binaries. This is especially +# annoying in cross-compiling environments, where the build's strip +# is unlikely to handle the host's binaries. +# Fortunately install-sh will honor a STRIPPROG variable, so we +# always use install-sh in `make install-strip', and initialize +# STRIPPROG with the value of the STRIP variable (set by the user). +AC_DEFUN([AM_PROG_INSTALL_STRIP], +[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +# Installed binaries are usually stripped using `strip' when the user +# run `make install-strip'. However `strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the `STRIP' environment variable to overrule this program. +dnl Don't test for $cross_compiling = yes, because it might be `maybe'. +if test "$cross_compiling" != no; then + AC_CHECK_TOOL([STRIP], [strip], :) +fi +INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s" +AC_SUBST([INSTALL_STRIP_PROGRAM])]) + +# Check how to create a tarball. -*- Autoconf -*- + +# Copyright (C) 2004, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# _AM_PROG_TAR(FORMAT) +# -------------------- +# Check how to create a tarball in format FORMAT. +# FORMAT should be one of `v7', `ustar', or `pax'. +# +# Substitute a variable $(am__tar) that is a command +# writing to stdout a FORMAT-tarball containing the directory +# $tardir. +# tardir=directory && $(am__tar) > result.tar +# +# Substitute a variable $(am__untar) that extract such +# a tarball read from stdin. +# $(am__untar) < result.tar +AC_DEFUN([_AM_PROG_TAR], +[# Always define AMTAR for backward compatibility. +AM_MISSING_PROG([AMTAR], [tar]) +m4_if([$1], [v7], + [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'], + [m4_case([$1], [ustar],, [pax],, + [m4_fatal([Unknown tar format])]) +AC_MSG_CHECKING([how to create a $1 tar archive]) +# Loop over all known methods to create a tar archive until one works. +_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' +_am_tools=${am_cv_prog_tar_$1-$_am_tools} +# Do not fold the above two line into one, because Tru64 sh and +# Solaris sh will not grok spaces in the rhs of `-'. +for _am_tool in $_am_tools +do + case $_am_tool in + gnutar) + for _am_tar in tar gnutar gtar; + do + AM_RUN_LOG([$_am_tar --version]) && break + done + am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' + am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' + am__untar="$_am_tar -xf -" + ;; + plaintar) + # Must skip GNU tar: if it does not support --format= it doesn't create + # ustar tarball either. + (tar --version) >/dev/null 2>&1 && continue + am__tar='tar chf - "$$tardir"' + am__tar_='tar chf - "$tardir"' + am__untar='tar xf -' + ;; + pax) + am__tar='pax -L -x $1 -w "$$tardir"' + am__tar_='pax -L -x $1 -w "$tardir"' + am__untar='pax -r' + ;; + cpio) + am__tar='find "$$tardir" -print | cpio -o -H $1 -L' + am__tar_='find "$tardir" -print | cpio -o -H $1 -L' + am__untar='cpio -i -H $1 -d' + ;; + none) + am__tar=false + am__tar_=false + am__untar=false + ;; + esac + + # If the value was cached, stop now. We just wanted to have am__tar + # and am__untar set. + test -n "${am_cv_prog_tar_$1}" && break + + # tar/untar a dummy directory, and stop if the command works + rm -rf conftest.dir + mkdir conftest.dir + echo GrepMe > conftest.dir/file + AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) + rm -rf conftest.dir + if test -s conftest.tar; then + AM_RUN_LOG([$am__untar /dev/null 2>&1 && break + fi +done +rm -rf conftest.dir + +AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) +AC_MSG_RESULT([$am_cv_prog_tar_$1])]) +AC_SUBST([am__tar]) +AC_SUBST([am__untar]) +]) # _AM_PROG_TAR + +m4_include([aclocal/m4/ax_boost_base.m4]) +m4_include([aclocal/m4/ax_boost_filesystem.m4]) +m4_include([aclocal/m4/ax_boost_system.m4]) +m4_include([aclocal/m4/ax_boost_thread.m4]) diff --git a/aclocal/m4/ax_boost_base.m4 b/aclocal/m4/ax_boost_base.m4 new file mode 100644 index 000000000..1d2537ee2 --- /dev/null +++ b/aclocal/m4/ax_boost_base.m4 @@ -0,0 +1,198 @@ +##### http://autoconf-archive.cryp.to/ax_boost_base.html +# +# SYNOPSIS +# +# AX_BOOST_BASE([MINIMUM-VERSION]) +# +# DESCRIPTION +# +# Test for the Boost C++ libraries of a particular version (or newer) +# +# If no path to the installed boost library is given the macro +# searchs under /usr, /usr/local, and /opt, and evaluates the +# $BOOST_ROOT environment variable. Further documentation is +# available at . +# +# This macro calls: +# +# AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS) +# +# And sets: +# +# HAVE_BOOST +# +# LAST MODIFICATION +# +# 2007-03-15 +# +# COPYLEFT +# +# Copyright (c) 2007 Thomas Porschberg +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +AC_DEFUN([AX_BOOST_BASE], +[ +AC_ARG_WITH([boost], + AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is yes) - it is possible to specify the root directory for boost (optional)]), + [ + if test "$withval" = "no"; then + want_boost="no" + elif test "$withval" = "yes"; then + want_boost="yes" + ac_boost_path="" + else + want_boost="yes" + ac_boost_path="$withval" + fi + ], + [want_boost="yes"]) + +if test "x$want_boost" = "xyes"; then + boost_lib_version_req=ifelse([$1], ,1.20.0,$1) + boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'` + boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'` + boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'` + boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` + if test "x$boost_lib_version_req_sub_minor" = "x" ; then + boost_lib_version_req_sub_minor="0" + fi + WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor` + AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req) + succeeded=no + + dnl first we check the system location for boost libraries + dnl this location ist chosen if boost libraries are installed with the --layout=system option + dnl or if you install boost with RPM + if test "$ac_boost_path" != ""; then + BOOST_LDFLAGS="-L$ac_boost_path/lib" + BOOST_CPPFLAGS="-I$ac_boost_path/include" + else + for ac_boost_path_tmp in /usr /usr/local /opt ; do + if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then + BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib" + BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include" + break; + fi + done + fi + + CPPFLAGS_SAVED="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + + LDFLAGS_SAVED="$LDFLAGS" + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_LANG_PUSH(C++) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + @%:@include + ]], [[ + #if BOOST_VERSION >= $WANT_BOOST_VERSION + // Everything is okay + #else + # error Boost version is too old + #endif + ]])],[ + AC_MSG_RESULT(yes) + succeeded=yes + found_system=yes + ],[ + ]) + AC_LANG_POP([C++]) + + + + dnl if we found no boost with system layout we search for boost libraries + dnl built and installed without the --layout=system option or for a staged(not installed) version + if test "x$succeeded" != "xyes"; then + _version=0 + if test "$ac_boost_path" != ""; then + BOOST_LDFLAGS="-L$ac_boost_path/lib" + if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then + for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do + _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` + V_CHECK=`expr $_version_tmp \> $_version` + if test "$V_CHECK" = "1" ; then + _version=$_version_tmp + fi + VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` + BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE" + done + fi + else + for ac_boost_path in /usr /usr/local /opt ; do + if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then + for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do + _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` + V_CHECK=`expr $_version_tmp \> $_version` + if test "$V_CHECK" = "1" ; then + _version=$_version_tmp + best_path=$ac_boost_path + fi + done + fi + done + + VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` + BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE" + BOOST_LDFLAGS="-L$best_path/lib" + + if test "x$BOOST_ROOT" != "x"; then + if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then + version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'` + stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'` + stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'` + V_CHECK=`expr $stage_version_shorten \>\= $_version` + if test "$V_CHECK" = "1" ; then + AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT) + BOOST_CPPFLAGS="-I$BOOST_ROOT" + BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib" + fi + fi + fi + fi + + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_LANG_PUSH(C++) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + @%:@include + ]], [[ + #if BOOST_VERSION >= $WANT_BOOST_VERSION + // Everything is okay + #else + # error Boost version is too old + #endif + ]])],[ + AC_MSG_RESULT(yes) + succeeded=yes + found_system=yes + ],[ + ]) + AC_LANG_POP([C++]) + fi + + if test "$succeeded" != "yes" ; then + if test "$_version" = "0" ; then + AC_MSG_ERROR([[We could not detect the boost libraries (version $boost_lib_version_req_shorten or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in . See http://randspringer.de/boost for more documentation.]]) + else + AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).]) + fi + else + AC_SUBST(BOOST_CPPFLAGS) + AC_SUBST(BOOST_LDFLAGS) + AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available]) + fi + + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" +fi + +]) diff --git a/aclocal/m4/ax_boost_filesystem.m4 b/aclocal/m4/ax_boost_filesystem.m4 new file mode 100644 index 000000000..44c89346e --- /dev/null +++ b/aclocal/m4/ax_boost_filesystem.m4 @@ -0,0 +1,108 @@ +##### http://autoconf-archive.cryp.to/ax_boost_filesystem.html +# +# SYNOPSIS +# +# AX_BOOST_FILESYSTEM +# +# DESCRIPTION +# +# Test for Filesystem library from the Boost C++ libraries. The macro +# requires a preceding call to AX_BOOST_BASE. Further documentation +# is available at . +# +# This macro calls: +# +# AC_SUBST(BOOST_FILESYSTEM_LIB) +# +# And sets: +# +# HAVE_BOOST_FILESYSTEM +# +# LAST MODIFICATION +# +# 2007-07-26 +# +# COPYLEFT +# +# Copyright (c) 2007 Thomas Porschberg +# Copyright (c) 2007 Michael Tindal +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +AC_DEFUN([AX_BOOST_FILESYSTEM], +[ + AC_ARG_WITH([boost-filesystem], + AS_HELP_STRING([--with-boost-filesystem@<:@=special-lib@:>@], + [use the Filesystem library from boost - it is possible to specify a certain library for the linker + e.g. --with-boost-filesystem=boost_filesystem-gcc-mt ]), + [ + if test "$withval" = "no"; then + want_boost="no" + elif test "$withval" = "yes"; then + want_boost="yes" + ax_boost_user_filesystem_lib="" + else + want_boost="yes" + ax_boost_user_filesystem_lib="$withval" + fi + ], + [want_boost="yes"] + ) + + if test "x$want_boost" = "xyes"; then + AC_REQUIRE([AC_PROG_CC]) + CPPFLAGS_SAVED="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + + LDFLAGS_SAVED="$LDFLAGS" + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_CACHE_CHECK(whether the Boost::Filesystem library is available, + ax_cv_boost_filesystem, + [AC_LANG_PUSH([C++]) + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include ]], + [[using namespace boost::filesystem; + path my_path( "foo/bar/data.txt" ); + return 0;]]), + ax_cv_boost_filesystem=yes, ax_cv_boost_filesystem=no) + AC_LANG_POP([C++]) + ]) + if test "x$ax_cv_boost_filesystem" = "xyes"; then + AC_DEFINE(HAVE_BOOST_FILESYSTEM,,[define if the Boost::Filesystem library is available]) + BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` + if test "x$ax_boost_user_filesystem_lib" = "x"; then + for libextension in `ls $BOOSTLIBDIR/libboost_filesystem*.{so,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_filesystem.*\)\.so.*$;\1;' -e 's;^lib\(boost_filesystem.*\)\.a*$;\1;'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], + [link_filesystem="no"]) + done + if test "x$link_program_options" != "xyes"; then + for libextension in `ls $BOOSTLIBDIR/boost_filesystem*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_filesystem.*\)\.dll.*$;\1;' -e 's;^\(boost_filesystem.*\)\.a*$;\1;'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], + [link_filesystem="no"]) + done + fi + else + for ax_lib in $ax_boost_user_filesystem_lib boost_filesystem-$ax_boost_user_filesystem_lib; do + AC_CHECK_LIB($ax_lib, exit, + [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], + [link_filesystem="no"]) + done + + fi + if test "x$link_filesystem" != "xyes"; then + AC_MSG_ERROR(Could not link against $ax_lib !) + fi + fi + + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" + fi +]) diff --git a/aclocal/m4/ax_boost_system.m4 b/aclocal/m4/ax_boost_system.m4 new file mode 100644 index 000000000..618860325 --- /dev/null +++ b/aclocal/m4/ax_boost_system.m4 @@ -0,0 +1,118 @@ +# =========================================================================== +# http://autoconf-archive.cryp.to/ax_boost_system.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_BOOST_SYSTEM +# +# DESCRIPTION +# +# Test for System library from the Boost C++ libraries. The macro requires +# a preceding call to AX_BOOST_BASE. Further documentation is available at +# . +# +# This macro calls: +# +# AC_SUBST(BOOST_SYSTEM_LIB) +# +# And sets: +# +# HAVE_BOOST_SYSTEM +# +# LAST MODIFICATION +# +# 2008-04-12 +# +# COPYLEFT +# +# Copyright (c) 2008 Thomas Porschberg +# Copyright (c) 2008 Michael Tindal +# Copyright (c) 2008 Daniel Casimiro +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AX_BOOST_SYSTEM], +[ + AC_ARG_WITH([boost-system], + AS_HELP_STRING([--with-boost-system@<:@=special-lib@:>@], + [use the System library from boost - it is possible to specify a certain library for the linker + e.g. --with-boost-system=boost_system-gcc-mt ]), + [ + if test "$withval" = "no"; then + want_boost="no" + elif test "$withval" = "yes"; then + want_boost="yes" + ax_boost_user_system_lib="" + else + want_boost="yes" + ax_boost_user_system_lib="$withval" + fi + ], + [want_boost="yes"] + ) + + if test "x$want_boost" = "xyes"; then + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_BUILD]) + CPPFLAGS_SAVED="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + + LDFLAGS_SAVED="$LDFLAGS" + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_CACHE_CHECK(whether the Boost::System library is available, + ax_cv_boost_system, + [AC_LANG_PUSH([C++]) + CXXFLAGS_SAVE=$CXXFLAGS + + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include ]], + [[boost::system::system_category]]), + ax_cv_boost_system=yes, ax_cv_boost_system=no) + CXXFLAGS=$CXXFLAGS_SAVE + AC_LANG_POP([C++]) + ]) + if test "x$ax_cv_boost_system" = "xyes"; then + AC_SUBST(BOOST_CPPFLAGS) + + AC_DEFINE(HAVE_BOOST_SYSTEM,,[define if the Boost::System library is available]) + BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` + + LDFLAGS_SAVE=$LDFLAGS + if test "x$ax_boost_user_system_lib" = "x"; then + for libextension in `ls $BOOSTLIBDIR/libboost_system*.{so,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_system.*\)\.so.*$;\1;' -e 's;^lib\(boost_system.*\)\.a*$;\1;'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], + [link_system="no"]) + done + if test "x$link_system" != "xyes"; then + for libextension in `ls $BOOSTLIBDIR/boost_system*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_system.*\)\.dll.*$;\1;' -e 's;^\(boost_system.*\)\.a*$;\1;'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], + [link_system="no"]) + done + fi + + else + for ax_lib in $ax_boost_user_system_lib boost_system-$ax_boost_user_system_lib; do + AC_CHECK_LIB($ax_lib, exit, + [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break], + [link_system="no"]) + done + + fi + if test "x$link_system" = "xno"; then + AC_MSG_ERROR(Could not link against $ax_lib !) + fi + fi + + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" + fi +]) diff --git a/aclocal/m4/ax_boost_thread.m4 b/aclocal/m4/ax_boost_thread.m4 new file mode 100644 index 000000000..94ab82e11 --- /dev/null +++ b/aclocal/m4/ax_boost_thread.m4 @@ -0,0 +1,147 @@ +# =========================================================================== +# http://autoconf-archive.cryp.to/ax_boost_thread.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_BOOST_THREAD +# +# DESCRIPTION +# +# Test for Thread library from the Boost C++ libraries. The macro requires +# a preceding call to AX_BOOST_BASE. Further documentation is available at +# . +# +# This macro calls: +# +# AC_SUBST(BOOST_THREAD_LIB) +# +# And sets: +# +# HAVE_BOOST_THREAD +# +# LAST MODIFICATION +# +# 2008-04-12 +# +# COPYLEFT +# +# Copyright (c) 2008 Thomas Porschberg +# Copyright (c) 2008 Michael Tindal +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AX_BOOST_THREAD], +[ + AC_ARG_WITH([boost-thread], + AS_HELP_STRING([--with-boost-thread@<:@=special-lib@:>@], + [use the Thread library from boost - it is possible to specify a certain library for the linker + e.g. --with-boost-thread=boost_thread-gcc-mt ]), + [ + if test "$withval" = "no"; then + want_boost="no" + elif test "$withval" = "yes"; then + want_boost="yes" + ax_boost_user_thread_lib="" + else + want_boost="yes" + ax_boost_user_thread_lib="$withval" + fi + ], + [want_boost="yes"] + ) + + if test "x$want_boost" = "xyes"; then + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_BUILD]) + CPPFLAGS_SAVED="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + + LDFLAGS_SAVED="$LDFLAGS" + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_CACHE_CHECK(whether the Boost::Thread library is available, + ax_cv_boost_thread, + [AC_LANG_PUSH([C++]) + CXXFLAGS_SAVE=$CXXFLAGS + + if test "x$build_os" = "xsolaris" ; then + CXXFLAGS="-pthreads $CXXFLAGS" + elif test "x$build_os" = "xming32" ; then + CXXFLAGS="-mthreads $CXXFLAGS" + else + CXXFLAGS="-pthread $CXXFLAGS" + fi + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include ]], + [[boost::thread_group thrds; + return 0;]]), + ax_cv_boost_thread=yes, ax_cv_boost_thread=no) + CXXFLAGS=$CXXFLAGS_SAVE + AC_LANG_POP([C++]) + ]) + if test "x$ax_cv_boost_thread" = "xyes"; then + if test "x$build_os" = "xsolaris" ; then + BOOST_CPPFLAGS="-pthreads $BOOST_CPPFLAGS" + elif test "x$build_os" = "xming32" ; then + BOOST_CPPFLAGS="-mthreads $BOOST_CPPFLAGS" + else + BOOST_CPPFLAGS="-pthread $BOOST_CPPFLAGS" + fi + + AC_SUBST(BOOST_CPPFLAGS) + + AC_DEFINE(HAVE_BOOST_THREAD,,[define if the Boost::Thread library is available]) + BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` + + LDFLAGS_SAVE=$LDFLAGS + case "x$build_os" in + *bsd* ) + LDFLAGS="-pthread $LDFLAGS" + break; + ;; + esac + if test "x$ax_boost_user_thread_lib" = "x"; then + for libextension in `ls $BOOSTLIBDIR/libboost_thread*.{so,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_thread.*\)\.so.*$;\1;' -e 's;^lib\(boost_thread.*\)\.a*$;\1;'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break], + [link_thread="no"]) + done + if test "x$link_thread" != "xyes"; then + for libextension in `ls $BOOSTLIBDIR/boost_thread*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_thread.*\)\.dll.*$;\1;' -e 's;^\(boost_thread.*\)\.a*$;\1;'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break], + [link_thread="no"]) + done + fi + + else + for ax_lib in $ax_boost_user_thread_lib boost_thread-$ax_boost_user_thread_lib; do + AC_CHECK_LIB($ax_lib, exit, + [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break], + [link_thread="no"]) + done + + fi + if test "x$link_thread" = "xno"; then + AC_MSG_ERROR(Could not link against $ax_lib !) + else + case "x$build_os" in + *bsd* ) + BOOST_LDFLAGS="-pthread $BOOST_LDFLAGS" + break; + ;; + esac + + fi + fi + + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" + fi +]) diff --git a/client/Makefile.am b/client/Makefile.am new file mode 100644 index 000000000..3607a6104 --- /dev/null +++ b/client/Makefile.am @@ -0,0 +1,83 @@ +AUTOMAKE_OPTIONS=foreign +bin_PROGRAMS = vcmiclient +#vcmi_LDADD = $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_THREAD_LIB) +#AM_CXXFLAGS = $(BOOST_CPPFLAGS) +vcmiclient_LDADD = $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_THREAD_LIB) +#vcmiclient_LDADD = $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_THREAD_LIB) +vcmiclient_LDFLAGS = -L$(top_builddir)/lib +vcmiclient_LDADD += -lvcmi +vcmiclient_SOURCES = \ +../AdventureMapButton.cpp \ +../hch/CAbilityHandler.cpp \ +../CAdvmapInterface.cpp \ +../CBattleInterface.cpp \ +./CBitmapHandler.cpp \ +../CCallback.cpp \ +../CCastleInterface.cpp \ +../CConsoleHandler.cpp \ +./CCreatureAnimation.cpp \ +../CCursorHandler.cpp \ +../hch/CDefHandler.cpp \ +../CGameInfo.cpp \ +../CGameInterface.cpp \ +../hch/CGeneralTextHandler.cpp \ +../CHeroWindow.cpp \ +./Client.cpp \ +../CLuaHandler.cpp \ +../CMessage.cpp \ +../CMT.cpp \ +../hch/CMusicHandler.cpp \ +../CPathfinder.cpp \ +../CPlayerInterface.cpp \ +../CPreGame.cpp \ +../hch/CPreGameTextHandler.cpp \ +../hch/CSndHandler.cpp \ +../hch/CSpellHandler.cpp \ +../CThreadHelper.cpp \ +./Graphics.cpp \ +../mapHandler.cpp \ +../SDL_Extensions.cpp \ +../SDL_framerate.cpp \ +../AdventureMapButton.h \ +../AI_Base.h \ +../hch/CAbilityHandler.h \ +../CAdvmapInterface.h \ +../hch/CAmbarCendamo.h \ +../hch/CArtHandler.h \ +../CBattleInterface.h \ +./CBitmapHandler.h \ +../hch/CBuildingHandler.h \ +../CCallback.h \ +../CCastleInterface.h \ +../CConsoleHandler.h \ +./CCreatureAnimation.h \ +../hch/CCreatureHandler.h \ +../CCursorHandler.h \ +../hch/CDefHandler.h \ +../CGameInfo.h \ +../CGameInterface.h \ +../hch/CGeneralTextHandler.h \ +../hch/CHeroHandler.h \ +../CHeroWindow.h \ +./Client.h \ +../CLuaHandler.h \ +../CMessage.h \ +../hch/CMusicHandler.h \ +../hch/CObjectHandler.h \ +../CPathfinder.h \ +../CPlayerInterface.h \ +../CPreGame.h \ +../hch/CPreGameTextHandler.h \ +../hch/CSndHandler.h \ +../hch/CSpellHandler.h \ +../CThreadHelper.h \ +../global.h \ +./Graphics.h \ +../int3.h \ +../map.h \ +../mapHandler.h \ +../nodrze.h \ +../SDL_framerate.h \ +../StartInfo.h \ +../stdafx.h \ +../timeHandler.h diff --git a/config.h.in b/config.h.in new file mode 100644 index 000000000..e67fd55fa --- /dev/null +++ b/config.h.in @@ -0,0 +1,190 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP + systems. This function is required for `alloca.c' support on those systems. + */ +#undef CRAY_STACKSEG_END + +/* Define to 1 if using `alloca.c'. */ +#undef C_ALLOCA + +/* Define to 1 if you have `alloca', as a function or macro. */ +#undef HAVE_ALLOCA + +/* Define to 1 if you have and it should be used (not on Ultrix). + */ +#undef HAVE_ALLOCA_H + +/* Define to 1 if you have the `atexit' function. */ +#undef HAVE_ATEXIT + +/* define if the Boost library is available */ +#undef HAVE_BOOST + +/* Define to 1 if you have the header file. + */ +#undef HAVE_BOOST_ALGORITHM_STRING_FIND_HPP + +/* Define to 1 if you have the header file. */ +#undef HAVE_BOOST_ALGORITHM_STRING_HPP + +/* Define to 1 if you have the header + file. */ +#undef HAVE_BOOST_ALGORITHM_STRING_REPLACE_HPP + +/* Define to 1 if you have the header file. */ +#undef HAVE_BOOST_ASSIGN_STD_VECTOR_HPP + +/* Define to 1 if you have the header file. */ +#undef HAVE_BOOST_BIND_HPP + +/* define if the Boost::Filesystem library is available */ +#undef HAVE_BOOST_FILESYSTEM + +/* Define to 1 if you have the header file. */ +#undef HAVE_BOOST_FILESYSTEM_HPP + +/* Define to 1 if you have the header file. + */ +#undef HAVE_BOOST_FILESYSTEM_OPERATIONS_HPP + +/* Define to 1 if you have the header file. */ +#undef HAVE_BOOST_FUNCTION_HPP + +/* define if the Boost::System library is available */ +#undef HAVE_BOOST_SYSTEM + +/* define if the Boost::Thread library is available */ +#undef HAVE_BOOST_THREAD + +/* Define to 1 if you have the header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `lua' library (-llua). */ +#undef HAVE_LIBLUA + +/* Define to 1 if you have the `SDL_image' library (-lSDL_image). */ +#undef HAVE_LIBSDL_IMAGE + +/* Define to 1 if you have the `SDL_mixer' library (-lSDL_mixer). */ +#undef HAVE_LIBSDL_MIXER + +/* Define to 1 if you have the `SDL_ttf' library (-lSDL_ttf). */ +#undef HAVE_LIBSDL_TTF + +/* Define to 1 if you have the `stdc++' library (-lstdc++). */ +#undef HAVE_LIBSTDC__ + +/* Define to 1 if you have the `lua_calchash' function. */ +#undef HAVE_LUA_CALCHASH + +/* Define to 1 if you have the `lua_pushhstring' function. */ +#undef HAVE_LUA_PUSHHSTRING + +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ +#undef HAVE_MALLOC + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `memset' function. */ +#undef HAVE_MEMSET + +/* Define to 1 if you have the `pow' function. */ +#undef HAVE_POW + +/* Define to 1 if you have the `select' function. */ +#undef HAVE_SELECT + +/* Define to 1 if you have the `sqrt' function. */ +#undef HAVE_SQRT + +/* Define to 1 if stdbool.h conforms to C99. */ +#undef HAVE_STDBOOL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SELECT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKET_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if the system has the type `_Bool'. */ +#undef HAVE__BOOL + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to the type of arg 1 for `select'. */ +#undef SELECT_TYPE_ARG1 + +/* Define to the type of args 2, 3 and 4 for `select'. */ +#undef SELECT_TYPE_ARG234 + +/* Define to the type of arg 5 for `select'. */ +#undef SELECT_TYPE_ARG5 + +/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at runtime. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ +#undef STACK_DIRECTION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + +/* Define to rpl_malloc if the replacement function should be used. */ +#undef malloc diff --git a/configure.ac b/configure.ac new file mode 100644 index 000000000..60fd85e67 --- /dev/null +++ b/configure.ac @@ -0,0 +1,78 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.60) +AC_INIT(vcmi, VERSION) +AM_INIT_AUTOMAKE +AC_CONFIG_HEADER([config.h]) + +# Checks for programs. +AC_PROG_CXX +AX_BOOST_BASE([1.33]) +AX_BOOST_SYSTEM +AX_BOOST_FILESYSTEM +AX_BOOST_THREAD +AC_PROG_CC +AC_PROG_CPP +AC_PROG_RANLIB + +CFLAGS="-g" +CXXFLAGS="-g" +AC_CHECK_LIB([stdc++], [main]) +if test "x$GCC" = "xyes"; then + stdcxx_name=`$CXX -print-file-name=libstdc++.so` + stdcxx_path=`dirname $stdcxx_name` +LIBS="-L$stdcxx_path $LIBS" +fi +AC_CHECK_PROG(HAVE_SDL_CONFIG, sdl-config, yes, no) + +AC_ARG_WITH(lua-includes,AC_HELP_STRING([--with-lua-includes=INCLUDE_PATH],[Use Lua library headers installed at specified + path(default=check)]),LUA_INCLUDES="$with_lua_includes") +if test "$LUA_INCLUDES" != ""; then +AC_SUBST([CPPFLAGS],["$CPPFLAGS -I$LUA_INCLUDES"]) +fi + +AC_ARG_WITH(lua-libs,AC_HELP_STRING([--with-lua-libs=INCLUDE_PATH],[Use Lua library installed at specified + path(default=check)]),LUA_LIBS="$with_lua_libs") +if test "$LUA_LIBS" != ""; then +AC_SUBST([LIBS],["$LIBS -L$LUA_LIBS"]) +fi + +# Checks for libraries. +if test "$HAVE_SDL_CONFIG" = no; then +AC_MSG_ERROR(sdl-config doesn't exist. Try to check the PATH enviroment.) + else +AC_CHECK_LIB(SDL, SDL_Init,SDL_CFLAGS=`sdl-config --cflags` + SDL_LIBS=`sdl-config --libs`) +fi + +LIBS="$LIBS $SDL_LIBS" +CPPFLAGS="$CPPFLAGS $SDL_CFLAGS" + +AC_CHECK_LIB(SDL_mixer,main,,AC_MSG_ERROR([SDL_mixer library not found. Please install it.])) +AC_CHECK_LIB(SDL_image,IMG_Load,,AC_MSG_ERROR([SDL_image library not found. Please install it.])) +AC_CHECK_LIB(SDL_ttf,main,,AC_MSG_ERROR([SDL_ttf library not found. Please install it.])) +AC_CHECK_LIB(lua,main,,AC_MSG_ERROR([lua library not found. Please install it.])) + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([fcntl.h stdlib.h string.h]) +AC_CHECK_HEADER(lstate.h,,AC_MSG_ERROR([lstate.h header not found. Please install it.])) +AC_LANG_PUSH(C++) +CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" +AC_CHECK_HEADERS([boost/filesystem.hpp boost/algorithm/string.hpp boost/algorithm/string/replace.hpp boost/filesystem/operations.hpp boost/assign/std/vector.hpp boost/algorithm/string/find.hpp boost/function.hpp boost/bind.hpp],,AC_MSG_ERROR([Required boost headers not found. Please install it.])) +AC_LANG_POP(C++) + +# Checks for typedefs, structures, and compiler characteristics. +AC_HEADER_STDBOOL +AC_C_CONST +AC_C_INLINE + +# Checks for library functions. +AC_FUNC_ALLOCA +AC_FUNC_MALLOC +AC_FUNC_SELECT_ARGTYPES +AC_CHECK_FUNCS([lua_pushhstring lua_calchash],, AC_MSG_ERROR([Lua required fuctions not found])) +AC_CHECK_FUNCS([atexit memset pow select sqrt]) + +AC_OUTPUT(Makefile lib/Makefile client/Makefile server/Makefile) diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 000000000..f03134e15 --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,32 @@ +noinst_LIBRARIES = libvcmi.a +#vcmi_LDADD = $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_THREAD_LIB) +#AM_CXXFLAGS = $(BOOST_CPPFLAGS) +libvcmi_a_SOURCES = \ + ../hch/CAmbarCendamo.cpp \ +../hch/CArtHandler.cpp \ +../hch/CBuildingHandler.cpp \ +../hch/CCreatureHandler.cpp \ +../hch/CDefObjInfoHandler.cpp \ +../CGameState.cpp \ +../hch/CHeroHandler.cpp \ +../hch/CLodHandler.cpp \ +../hch/CObjectHandler.cpp \ +./Connection.cpp \ +../hch/CTownHandler.cpp \ +../map.cpp \ +../stdafx.cpp \ +./VCMI_Lib.cpp \ +../hch/CAmbarCendamo.h \ +../hch/CArtHandler.h \ +../hch/CBuildingHandler.h \ +../hch/CCreatureHandler.h \ +../hch/CDefObjInfoHandler.h \ +../CGameState.h \ +../hch/CHeroHandler.h \ +../hch/CLodHandler.h \ +../hch/CObjectHandler.h \ +./Connection.h \ +../hch/CTownHandler.h \ +../map.h \ +./NetPacks.h \ +./VCMI_Lib.h diff --git a/server/Makefile.am b/server/Makefile.am new file mode 100644 index 000000000..464f9b0ac --- /dev/null +++ b/server/Makefile.am @@ -0,0 +1,16 @@ +AUTOMAKE_OPTIONS=foreign +bin_PROGRAMS = vcmiserver +vcmiserver_LDADD = $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_THREAD_LIB) +#vcmi_LDADD = $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_THREAD_LIB) +#AM_CXXFLAGS = $(BOOST_CPPFLAGS) +vcmiserver_LDFLAGS = -L$(top_builddir)/lib +vcmiserver_LDADD += -lvcmi +vcmiserver_SOURCES = \ +./CGameHandler.cpp \ +../CLua.cpp \ +./CScriptCallback.cpp \ +./CVCMIServer.cpp \ +./CGameHandler.h \ +../CLua.h \ +./CScriptCallback.h \ +./CVCMIServer.h From a15ffb06e6ec55c65cd9822769d28060d3f6b80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 4 Aug 2008 15:56:36 +0000 Subject: [PATCH 42/47] * compiles under MSVC (haven't I broken anything on gcc?) * half-done support for battles --- CAdvmapInterface.cpp | 3 + CBattleInterface.cpp | 43 +++-- CBattleInterface.h | 5 +- CCallback.cpp | 6 + CGameInterface.h | 15 +- CGameState.cpp | 65 ++++++- CGameState.h | 52 ++++-- CLua.cpp | 171 +++++++------------ CMT.cpp | 66 ++++---- CPlayerInterface.cpp | 61 +++---- CPlayerInterface.h | 4 +- CPreGame.cpp | 7 +- client/Client.cpp | 78 +++++++++ client/Client.h | 2 + client/Graphics.cpp | 6 + hch/CCreatureHandler.h | 2 +- hch/CHeroHandler.cpp | 26 +++ hch/CHeroHandler.h | 6 +- hch/CObjectHandler.h | 2 +- lib/BattleAction.h | 13 ++ lib/CondSh.h | 13 ++ lib/Connection.h | 58 ++++++- lib/NetPacks.h | 89 +++++++++- lib/VCMI_lib.vcproj | 8 + server/CGameHandler.cpp | 336 ++++++++++++++++++++++++++++++++++++- server/CGameHandler.h | 12 +- server/CScriptCallback.cpp | 51 ++---- server/CScriptCallback.h | 7 +- 28 files changed, 899 insertions(+), 308 deletions(-) create mode 100644 lib/BattleAction.h create mode 100644 lib/CondSh.h diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index b498b2eda..4e1f130b6 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -22,6 +22,7 @@ #include "CHeroWindow.h" #include "client/Graphics.h" #include "hch/CObjectHandler.h" +#include #include "map.h" #pragma warning (disable : 4355) extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts @@ -283,7 +284,9 @@ void CTerrainRect::clickLeft(tribool down) if ( (currentPath->endPos()) == mp) { //move CPath sended(*currentPath); //temporary path - engine will operate on it + LOCPLINT->pim->unlock(); mres = LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0); + LOCPLINT->pim->lock(); if(!mres) { delete currentPath; diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 82e25f4d4..39c5475ee 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -14,7 +14,7 @@ #include "client/Graphics.h" #include #include - +#include "lib/CondSh.h" #ifndef __GNUC__ const double M_PI = 3.14159265358979323846; #else @@ -30,6 +30,7 @@ SDL_Surface * CBattleInterface::cellBorder, * CBattleInterface::cellShade; CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2) : printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL), myTurn(false) { + givenCommand = new CondSh(NULL); //initializing armies this->army1 = army1; this->army2 = army2; @@ -169,6 +170,7 @@ CBattleInterface::~CBattleInterface() delete bConsoleUp; delete bConsoleDown; delete console; + delete givenCommand; delete attackingHero; delete defendingHero; @@ -391,9 +393,7 @@ void CBattleInterface::bSurrenderf() void CBattleInterface::bFleef() { - BattleAction * ba = new BattleAction; - ba->actionType = 4; - givenCommand = ba; + giveCommand(4,0,0); } void CBattleInterface::bAutofightf() @@ -410,10 +410,7 @@ void CBattleInterface::bWaitf() void CBattleInterface::bDefencef() { - BattleAction * ba = new BattleAction; - ba->actionType = 3; - ba->stackNumber = activeStack; - givenCommand = ba; + giveCommand(3,0,activeStack); } void CBattleInterface::bConsoleUpf() @@ -482,7 +479,7 @@ void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool b void CBattleInterface::stackActivated(int number) { - givenCommand = NULL; + //givenCommand = NULL; activeStack = number; shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(number); myTurn = true; @@ -791,6 +788,16 @@ void CBattleInterface::newRound(int number) console->addText(CGI->generaltexth->allTexts[412]); } +void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack) +{ + BattleAction * ba = new BattleAction(); //to be deleted by engine + ba->actionType = action; + ba->destinationTile = tile; + ba->stackNumber = stack; + givenCommand->setn(ba); + myTurn = false; +} + void CBattleInterface::hexLclicked(int whichOne) { if((whichOne%17)!=0 && (whichOne%17)!=16) //if player is trying to attack enemey unit or move creature stack @@ -802,28 +809,16 @@ void CBattleInterface::hexLclicked(int whichOne) //LOCPLINT->cb->battleGetCreature(); if(atCre==-1) //normal move action { - BattleAction * ba = new BattleAction(); //to be deleted by engine - ba->actionType = 2; - ba->destinationTile = whichOne; - ba->stackNumber = activeStack; - givenCommand = ba; + giveCommand(2,whichOne,activeStack); } else if(LOCPLINT->cb->battleGetStackByID(atCre)->owner != attackingHeroInstance->tempOwner && LOCPLINT->cb->battleCanShoot(activeStack, whichOne)) //shooting { - BattleAction * ba = new BattleAction(); //to be deleted by engine - ba->actionType = 7; - ba->destinationTile = whichOne; - ba->stackNumber = activeStack; - givenCommand = ba; + giveCommand(7,whichOne,activeStack); } else if(LOCPLINT->cb->battleGetStackByID(atCre)->owner != attackingHeroInstance->tempOwner) //attacking { - BattleAction * ba = new BattleAction(); //to be deleted by engine - ba->actionType = 6; - ba->destinationTile = whichOne; - ba->stackNumber = activeStack; - givenCommand = ba; + giveCommand(6,whichOne,activeStack); } } } diff --git a/CBattleInterface.h b/CBattleInterface.h index 196f8ade9..f4f3ca400 100644 --- a/CBattleInterface.h +++ b/CBattleInterface.h @@ -9,6 +9,7 @@ class CDefHandler; class CStack; class CCallback; class AdventureMapButton; +template struct CondSh; class CBattleHero : public IShowable, public CIntObject { @@ -112,7 +113,7 @@ private: }; std::list projectiles; void projectileShowHelper(SDL_Surface * to=NULL); //prints projectiles present on the battlefield - + void giveCommand(ui8 action, ui16 tile, ui32 stack); public: CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor ~CBattleInterface(); //d-tor @@ -122,7 +123,7 @@ public: CBattleHex bfield[187]; //11 lines, 17 hexes on each std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield static SDL_Surface * cellBorder, * cellShade; - BattleAction * givenCommand; //true if we have i.e. moved current unit + CondSh *givenCommand; //data != NULL if we have i.e. moved current unit bool myTurn; //if true, interface is active (commands can be ordered //button handle funcs: diff --git a/CCallback.cpp b/CCallback.cpp index 0bedcbbee..d304b808b 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -18,6 +18,12 @@ #include #include #include "lib/NetPacks.h" +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif extern CSharedCond > mess; HeroMoveDetails::HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho) diff --git a/CGameInterface.h b/CGameInterface.h index 0c968f1ea..5a0d8ac51 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -3,6 +3,7 @@ #include "global.h" #include #include +#include "lib/BattleAction.h" BOOST_TRIBOOL_THIRD_STATE(outOfRange) using namespace boost::logic; @@ -18,21 +19,13 @@ class CGTownInstance; class CGObjectInstance; class CCreatureSet; class CArmedInstance; - +struct BattleResult; class CObstacle { int ID; int position; //TODO: add some kind of the blockmap }; -struct BattleAction -{ - bool side; //who made this action: false - left, true - right player - int stackNumber;//stack ID, -1 left hero, -2 right hero, - int actionType; // 0 = Cancel BattleAction 1 = Hero cast a spell 2 = Walk 3 = Defend 4 = Retreat from the battle 5 = Surrender 6 = Walk and Attack 7 = Shoot 8 = Wait 9 = Catapult 10 = Monster casts a spell (i.e. Faerie Dragons) - int destinationTile; - int additionalInfo; // e.g. spell number if type is 1 || 10 -}; struct StackState { @@ -65,13 +58,13 @@ public: virtual void garrisonChanged(const CGObjectInstance * obj){}; virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished //battle call-ins - virtual void battleStart(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right + virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles){}; //called when battlefield is prepared, prior the battle beginning virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn virtual void actionStarted(BattleAction action){};//occurs BEFORE every action taken by any stack or by the hero virtual void actionFinished(BattleAction action){};//occurs AFTER every action taken by any stack or by the hero virtual BattleAction activeStack(int stackID)=0; //called when it's turn of that stack - virtual void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector capturedArtifacts, int expForWinner, bool winner){}; + virtual void battleEnd(BattleResult *br){}; virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving)=0; virtual void battleStackAttacking(int ID, int dest)=0; virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting)=0; diff --git a/CGameState.cpp b/CGameState.cpp index 5a811c9e6..fbff5897a 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -18,14 +18,6 @@ #include #include boost::rand48 ran; -class CMP_stack -{ -public: - bool operator ()(const CStack* a, const CStack* b) - { - return (a->creature->speed)>(b->creature->speed); - } -} cmpst ; CGObjectInstance * createObject(int id, int subid, int3 pos, int owner) { @@ -135,6 +127,26 @@ void CGameState::apply(IPack * pack) players[sr->player].resources[i] = sr->res[i]; break; } + case 105: + { + SetPrimSkill *sr = static_cast(pack); + CGHeroInstance *hero = getHero(sr->id); + if(sr->which <4) + { + if(sr->abs) + hero->primSkills[sr->which] = sr->val; + else + hero->primSkills[sr->which] += sr->val; + } + else if(sr->which == 4) //XP + { + if(sr->abs) + hero->exp = sr->val; + else + hero->exp += sr->val; + } + break; + } case 500: { RemoveHero *rh = static_cast(pack); @@ -198,6 +210,35 @@ void CGameState::apply(IPack * pack) map->objects[p->id]->*point = p->val; break; } + case 3000: + { + BattleStart * bs = static_cast(pack); + curB = bs->info; + break; + } + case 3001: + { + BattleNextRound *ns = static_cast(pack); + curB->round = ns->round; + break; + } + case 3002: + { + BattleSetActiveStack *ns = static_cast(pack); + curB->activeStack = ns->stack; + break; + } + case 3003: + { + BattleResult *br = static_cast(pack); + + //TODO: give exp, artifacts to winner, decrease armies (casualties) + + for(unsigned i=0;istacks.size();i++) + delete curB->stacks[i]; + delete curB; + curB = NULL; + } //case 1002://set hover name // { // SetHoverName * shn = static_cast(pack); @@ -228,6 +269,12 @@ int CGameState::pickHero(int owner) } return h; } +CGHeroInstance *CGameState::getHero(int objid) +{ + if(objid<0 || objid>=map->objects.size()) + return NULL; + return static_cast(map->objects[objid]); +} std::pair CGameState::pickObject(CGObjectInstance *obj) { switch(obj->ID) @@ -460,7 +507,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed) { day = 0; seed = Seed; - ran.seed((int32_t)seed); + ran.seed((boost::int32_t)seed); scenarioOps = si; this->map = map; diff --git a/CGameState.h b/CGameState.h index 11e65d6e2..4c8b79ce8 100644 --- a/CGameState.h +++ b/CGameState.h @@ -47,29 +47,53 @@ public: struct DLL_EXPORT BattleInfo { - int side1, side2; - int round, activeStack; - int siege; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle + ui8 side1, side2; + si32 round, activeStack; + ui8 siege; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle int3 tile; //for background and bonuses - CGHeroInstance *hero1, *hero2; - CCreatureSet * army1, * army2; + si32 hero1, hero2; + CCreatureSet army1, army2; std::vector stacks; - bool stackActionPerformed; //true if current stack has been moved + + template void serialize(Handler &h, const int version) + { + h & side1 & side2 & round & activeStack & siege & tile & stacks & army1 & army2 & hero1 & hero2; + } }; class DLL_EXPORT CStack { public: - int ID; //unique ID of stack + ui32 ID; //unique ID of stack CCreature * creature; - int amount; - int firstHPleft; //HP of first creature in stack - int owner; - bool attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle) - int position; //position on battlefield - bool alive; //true if it is alive + ui32 amount; + ui32 firstHPleft; //HP of first creature in stack + ui8 owner; + ui8 attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle) + ui16 position; //position on battlefield + ui8 alive; //true if it is alive + CStack(CCreature * C, int A, int O, int I, bool AO); CStack() : creature(NULL),amount(-1),owner(255), alive(true), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1){}; + + template void save(Handler &h, const int version) + { + h & creature->idNumber; + } + template void load(Handler &h, const int version) + { + ui32 id; + h & id; + creature = &VLC->creh->creatures[id]; + } + template void serialize(Handler &h, const int version) + { + h & ID & amount & firstHPleft & owner & attackerOwned & position & alive; + if(h.saving) + save(h,version); + else + load(h,version); + } }; class DLL_EXPORT CGameState @@ -94,6 +118,8 @@ private: std::pair pickObject(CGObjectInstance *obj); int pickHero(int owner); + CGHeroInstance *getHero(int objid); + void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2); bool battleMoveCreatureStack(int ID, int dest); bool battleAttackCreatureStack(int ID, int dest); diff --git a/CLua.cpp b/CLua.cpp index c18781346..8e7b9b93f 100644 --- a/CLua.cpp +++ b/CLua.cpp @@ -77,10 +77,6 @@ void CLua::open(std::string initpath) // temp += initpath; // throw std::exception(temp.c_str()); //} - - - - } void CLua::registerCLuaCallback() { @@ -113,10 +109,6 @@ void CLua::findFS(std::string fname) // lua_settop(is, 0); // throw new std::exception((fname + ": function not defined").c_str()); // the call is not defined //} - - - - } #undef LST @@ -153,10 +145,6 @@ void CLuaObjectScript::newObject(int objid) // throw new std::exception(("Failed to call "+genFN("newObject",os->ID)+" function in lua script.").c_str()); //} //lua_settop(is, 0); - - - - return; } void CLuaObjectScript::onHeroVisit(int objid, int heroID) @@ -170,10 +158,6 @@ void CLuaObjectScript::onHeroVisit(int objid, int heroID) // throw new std::exception(("Failed to call "+genFN("heroVisit",os->ID)+" function in lua script.").c_str()); //} //lua_settop(is, 0); - - - - } //std::string CLuaObjectScript::hoverText(int objid) //{ @@ -295,30 +279,33 @@ void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited) case 61: case 32: { - //cb->changePrimSkill(heroID,w,vvv); - //std::vector weko; - //weko.push_back(new SComponent(SComponent::primskill,w,vvv)); - //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&weko); - //break; - - + cb->changePrimSkill(heroID,w,vvv); + InfoWindow iw; + iw.components.push_back(Component(0,w,vvv,0)); + iw.text << std::pair(11,ot); + iw.player = cb->getHeroOwner(heroID); + cb->showInfoDialog(&iw); + break; } - case 100: + case 100: //give 1000 exp { - //cb->changePrimSkill(heroID,w,vvv); - //std::vector weko; - //weko.push_back(new SComponent(SComponent::experience,0,vvv)); - //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&weko); - //break; - - + cb->changePrimSkill(heroID,w,vvv); + InfoWindow iw; + iw.components.push_back(Component(0,4,vvv,0)); + iw.player = cb->getHeroOwner(heroID); + iw.text << std::pair(11,ot); + cb->showInfoDialog(&iw); + break; } } } else { ot++; - //cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&std::vector()); + InfoWindow iw; + iw.player = cb->getHeroOwner(heroID); + iw.text << std::pair(11,ot); + cb->showInfoDialog(&iw); } } @@ -336,46 +323,6 @@ std::vector CVisitableOPH::yourObjects() void CVisitableOPW::onNAHeroVisit(int objid, int heroID, bool alreadyVisited) { DEFOS; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int mid; switch (os->ID) { @@ -518,15 +465,6 @@ void CMines::onHeroVisit(int objid, int heroID) iw.player = h->tempOwner; iw.components.push_back(Component(2,os->subID,vv,-1)); cb->showInfoDialog(&iw); - - - - - - - - - } std::vector CMines::yourObjects() { @@ -585,33 +523,42 @@ void CPickable::onHeroVisit(int objid, int heroID) } case 79: { - ////TODO: handle guards (when battles are finished) - //CResourceObjInfo * t2 = static_cast(os->info); - //int val; - //if(t2->amount) - // val = t2->amount; - //else - //{ - // switch(os->subID) - // { - // case 6: - // val = 500 + (rand()%6)*100; - // break; - // case 0: case 2: - // val = 6 + (rand()%5); - // break; - // default: - // val = 3 + (rand()%3); - // break; - // } - //} - //if(t2->message.length()) - // cb->showInfoDialog(cb->getHeroOwner(heroID),t2->message,&std::vector()); - //SComponent ccc(SComponent::resource,os->subID,val); - //ccc.description = VLC->objh->advobtxt[113]; - //boost::algorithm::replace_first(ccc.description,"%s",VLC->objh->restypes[os->subID]); - //cb->giveResource(cb->getHeroOwner(heroID),os->subID,val); - //cb->showCompInfo(cb->getHeroOwner(heroID),&ccc); + //TODO: handle guards (when battles are finished) + CResourceObjInfo * t2 = static_cast(os->info); + int val; + if(t2->amount) + val = t2->amount; + else + { + switch(os->subID) + { + case 6: + val = 500 + (rand()%6)*100; + break; + case 0: case 2: + val = 6 + (rand()%5); + break; + default: + val = 3 + (rand()%3); + break; + } + } + if(t2->message.length()) + { + InfoWindow iw; + iw.player = cb->getHero(heroID)->tempOwner; + iw.text << t2->message; + cb->showInfoDialog(&iw); + } + + cb->giveResource(cb->getHeroOwner(heroID),os->subID,val); + + ShowInInfobox sii; + sii.player = cb->getHeroOwner(heroID); + sii.c = Component(2,os->subID,val,0); + sii.text << std::pair(11,113); + sii.text.replacements.push_back(VLC->objh->restypes[os->subID]); + cb->showCompInfo(&sii); break; } case 101: @@ -672,10 +619,6 @@ void CPickable::chosen(int which) //for (int i=0;i CPickable::yourObjects() //returns IDs of objects which are handled by script @@ -797,8 +740,8 @@ void CMonsterS::onHeroVisit(int objid, int heroID) DEFOS; CCreatureSet set; //TODO: zrobic secik w sposob wyrafinowany - set.slots[0] = std::pair(os->subID,((CCreatureObjInfo*)os->info)->number); - cb->startBattle(heroID,&set,os->pos); + set.slots[0] = std::pair(os->subID,amounts[objid]); + cb->startBattle(heroID,set,os->pos); } std::vector CMonsterS::yourObjects() //returns IDs of objects which are handled by script { diff --git a/CMT.cpp b/CMT.cpp index acb16861f..61326f606 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -1,6 +1,6 @@ // CMT.cpp : Defines the entry point for the console application. // -#include "stdafx.h" +#include "stdafx.h" #include #include #include @@ -10,11 +10,11 @@ #include "SDL_ttf.h" #include "SDL_mixer.h" #include "SDL_Extensions.h" -#include "SDL_framerate.h" -#include "CGameInfo.h" +#include "SDL_framerate.h" +#include "CGameInfo.h" #include "mapHandler.h" #include "global.h" -#include "CPreGame.h" +#include "CPreGame.h" #include "CConsoleHandler.h" #include "CCursorHandler.h" #include "CPathfinder.h" @@ -42,15 +42,15 @@ std::string NAME = NAME_VER + std::string(" (client)"); DLL_EXPORT void initDLL(CLodHandler *b); SDL_Surface * screen, * screen2; -extern SDL_Surface * CSDL_Ext::std32bppSurface; +extern SDL_Surface * CSDL_Ext::std32bppSurface; std::queue events; -boost::mutex eventsM; -TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; +boost::mutex eventsM; +TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; #ifndef __GNUC__ int _tmain(int argc, _TCHAR* argv[]) -#else +#else int main(int argc, _TCHAR* argv[]) -#endif +#endif { std::cout.flags(ios::unitbuf); std::cout << NAME << std::endl; @@ -59,7 +59,7 @@ int main(int argc, _TCHAR* argv[]) atexit(SDL_Quit); CGameInfo * cgi = CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.) //CLuaHandler luatest; - //luatest.test(); + //luatest.test(); //CBIKHandler cb; //cb.open("CSECRET.BIK"); std::cout << "Starting... " << std::endl; @@ -73,7 +73,7 @@ int main(int argc, _TCHAR* argv[]) int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff; #else int rmask = 0x000000ff; int gmask = 0x0000ff00; int bmask = 0x00ff0000; int amask = 0xff000000; - #endif + #endif CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask); THC std::cout<<"\tInitializing minors: "<initMusics(); - //audio initialized + //audio initialized cgi->consoleh = new CConsoleHandler; cgi->mush = mush; - THC std::cout<<"\tInitializing sound: "<spriteh = new CLodHandler(); cgi->spriteh->init("Data\\H3sprite.lod","Sprites"); BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler; cgi->bitmaph->init("Data\\H3bitmap.lod","Data"); THC std::cout<<"Loading .lod files: "<bitmaph); + initDLL(cgi->bitmaph); CGI->arth = VLC->arth; CGI->creh = VLC->creh; CGI->townh = VLC->townh; CGI->heroh = VLC->heroh; CGI->objh = VLC->objh; CGI->dobjinfo = VLC->dobjinfo; - CGI->buildh = VLC->buildh; - THC std::cout<<"Initializing VCMI_Lib: "<buildh = VLC->buildh; + THC std::cout<<"Initializing VCMI_Lib: "<curh->initCursor(); //cgi->curh->showGraphicCursor(); pomtime.getDif(); @@ -112,11 +112,11 @@ int main(int argc, _TCHAR* argv[]) cgi->curh->initCursor(); //cgi->screenh = new CScreenHandler; //cgi->screenh->initScreen(); - THC std::cout<<"\tScreen handler: "<loadAbilities(); cgi->abilh = abilh; - THC std::cout<<"\tAbility handler: "<generaltexth = new CGeneralTextHandler; cgi->generaltexth->load(); - THC std::cout<<"Preparing more handlers: "<mush = mush; StartInfo *options = new StartInfo(cpg->runLoop()); -/////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////// boost::thread servthr(boost::bind(system,"VCMI_server.exe > server_log.txt")); //runs server executable; //TODO: will it work on non-windows platforms? - THC tmh.getDif();pomtime.getDif();//reset timers + THC tmh.getDif();pomtime.getDif();//reset timers CSpellHandler * spellh = new CSpellHandler; spellh->loadSpells(); cgi->spellh = spellh; - THC std::cout<<"\tSpell handler: "<pathf = new CPathfinder(); THC std::cout<<"\tPathfinder: "<consoleh->runConsole(); THC std::cout<<"\tCallback and console: "<playerint.size(); ++g) //{ // if(!cgi->playerint[g]->human) // continue; - // CMinimap & mm = ((CPlayerInterface*)cgi->playerint[g])->adventureInt->minimap; + // CMinimap & mm = ((CPlayerInterface*)cgi->playerint[g])->adventureInt->minimap; // int mw = mm.map[0]->w, mh = mm.map[0]->h, - // wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y; + // wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y; // for(int d=0; dmh->map->twoLevel+1; ++d) // { - // SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface); + // SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface); // for (int i=0; imh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d ); + // int3 pp( ((i*CGI->mh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d ); // if ( !((CPlayerInterface*)cgi->playerint[g])->cb->isVisible(pp) ) // { // CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0); @@ -192,7 +192,7 @@ int main(int argc, _TCHAR* argv[]) // } // CSDL_Ext::update(pt); // mm.FoW.push_back(pt); - // } + // } //} } else diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 8fe38b6f3..91f4fdca5 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -33,6 +33,7 @@ #include "client/Graphics.h" #include "map.h" #include "lib/NetPacks.h" +#include "lib/CondSh.h" using namespace CSDL_Ext; extern TTF_Font * GEOR16; @@ -564,7 +565,10 @@ SComponent::SComponent(Etype Type, int Subtype, int Val) SComponent::SComponent(const Component &c) { - init((Etype)c.id,c.subtype,c.val); + if(c.id==0 && c.subtype==4) + init(experience,0,c.val); + else + init((Etype)c.id,c.subtype,c.val); switch(c.id) { case resource: @@ -1142,6 +1146,7 @@ int getDir(int3 src, int3 dst) } void CPlayerInterface::heroMoved(const HeroMoveDetails & details) { + boost::unique_lock un(*pim); //initializing objects and performing first step of move CGHeroInstance * ho = details.ho; //object representing this hero int3 hp = details.src; @@ -1487,7 +1492,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details) //CGI->screenh->updateScreen(); ++LOCPLINT->adventureInt->animValHitCount; //for animations - if(LOCPLINT->adventureInt->animValHitCount == 4) + if(LOCPLINT->adventureInt->animValHitCount == 8) { LOCPLINT->adventureInt->animValHitCount = 0; ++LOCPLINT->adventureInt->anim; @@ -1946,8 +1951,9 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, } } -void CPlayerInterface::battleStart(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, tribool side) //called by engine when battle starts; side=0 - left, side=1 - right +void CPlayerInterface::battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side) //called by engine when battle starts; side=0 - left, side=1 - right { + boost::unique_lock un(*pim); curint->deactivate(); curint = new CBattleInterface(army1,army2,hero1,hero2); curint->activate(); @@ -1974,45 +1980,27 @@ void CPlayerInterface::actionFinished(BattleAction action)//occurs AFTER every a BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack { - unsigned char showCount = 0; - dynamic_cast(curint)->stackActivated(stackID); - while(!dynamic_cast(curint)->givenCommand) //while current unit can perform an action + CBattleInterface *b = dynamic_cast(curint); { - ++showCount; - SDL_Event sEvent; - while (SDL_PollEvent(&sEvent)) //wait for event... - { - LOCPLINT->handleEvent(&sEvent); - } - if(showCount%2==0) - for(int i=0;ishow(); - //SDL_Flip(screen); - CSDL_Ext::update(screen); - - /*timeHandler th; - th.getDif(); - int tv = th.getDif(); - for (int i=0;i<((CBattleInterface*)this->curint)->timeinterested.size();i++) - { - if (timeinterested[i]->toNextTick>=0) - timeinterested[i]->toNextTick-=tv; - if (timeinterested[i]->toNextTick<0) - timeinterested[i]->tick(); - }*/ - - SDL_Delay(1); //give time for other apps - SDL_framerateDelay(mainFPSmng); + boost::unique_lock un(*pim); + b->stackActivated(stackID); } - BattleAction ret = *(dynamic_cast(curint)->givenCommand); - delete dynamic_cast(curint)->givenCommand; - dynamic_cast(curint)->givenCommand = NULL; - dynamic_cast(curint)->myTurn = false; + //wait till BattleInterface sets its command + boost::unique_lock lock(b->givenCommand->mx); + while(!b->givenCommand->data) + b->givenCommand->cond.wait(lock); + + //tidy up + BattleAction ret = *(b->givenCommand->data); + delete b->givenCommand->data; + + //return command return ret; } -void CPlayerInterface::battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector capturedArtifacts, int expForWinner, bool winner) +void CPlayerInterface::battleEnd(BattleResult *br) { + boost::unique_lock un(*pim); dynamic_cast(curint)->deactivate(); LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),dynamic_cast(curint))); delete dynamic_cast(curint); @@ -2047,6 +2035,7 @@ void CPlayerInterface::battleStackIsShooting(int ID, int dest) void CPlayerInterface::showComp(SComponent comp) { + boost::unique_lock un(*pim); adventureInt->infoBar.showComp(&comp,4000); } diff --git a/CPlayerInterface.h b/CPlayerInterface.h index eed2971ea..1da22d45b 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -333,13 +333,13 @@ public: void garrisonChanged(const CGObjectInstance * obj); void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished //for battles - void battleStart(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, boost::logic::tribool side); //called by engine when battle starts; side=0 - left, side=1 - right + void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right void battlefieldPrepared(int battlefieldType, std::vector obstacles); //called when battlefield is prepared, prior the battle beginning void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn void actionStarted(BattleAction action);//occurs BEFORE every action taken by any stack or by the hero void actionFinished(BattleAction action);//occurs AFTER every action taken by any stack or by the hero BattleAction activeStack(int stackID); //called when it's turn of that stack - void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector capturedArtifacts, int expForWinner, bool winner); + void battleEnd(BattleResult *br); void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving); void battleStackAttacking(int ID, int dest); void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting); diff --git a/CPreGame.cpp b/CPreGame.cpp index c5b4dba37..6e9d61536 100644 --- a/CPreGame.cpp +++ b/CPreGame.cpp @@ -22,7 +22,12 @@ extern SDL_Surface * screen; extern SDL_Color tytulowy, tlo, zwykly ; extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM; - +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif SDL_Rect genRect(int hh, int ww, int xx, int yy); SDL_Color genRGB(int r, int g, int b, int a=0); //void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen); diff --git a/client/Client.cpp b/client/Client.cpp index ae2c0ff73..9208c7b32 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -16,6 +16,7 @@ #include "../hch/CGeneralTextHandler.h" #include "../hch/CArtHandler.h" #include +#include "../lib/VCMI_Lib.h" CSharedCond > mess(new std::set); std::string toString(MetaString &ms) @@ -208,6 +209,25 @@ void CClient::process(int what) playerint[sr.player]->receivedResource(-1,-1); break; } + case 105: + { + SetPrimSkill sps; + *serv >> sps; + std::cout << "Changing hero primary skill"<apply(&sps); + playerint[gs->getHero(sps.id)->tempOwner]->heroPrimarySkillChanged(gs->getHero(sps.id),sps.which,sps.val); + break; + } + case 107: + { + ShowInInfobox sii; + *serv >> sii; + SComponent sc(sii.c); + sc.description = toString(sii.text); + if(playerint[sii.player]->human) + static_cast(playerint[sii.player])->showComp(sc); + break; + } case 500: { RemoveHero rh; @@ -297,6 +317,59 @@ void CClient::process(int what) gs->mx->lock(); gs->map->objects[shn.id]->hoverName = toString(shn.name); gs->mx->unlock(); + break; + } + case 3000: + { + BattleStart bs; + *serv >> bs; //uses new to allocate memory for battleInfo - must be deleted when battle is over + std::cout << "Starting battle!" <apply(&bs); + + if(playerint.find(gs->curB->side1) != playerint.end()) + playerint[gs->curB->side1]->battleStart(&gs->curB->army1, &gs->curB->army2, gs->curB->tile, gs->getHero(gs->curB->hero1), gs->getHero(gs->curB->hero2), 0); + if(playerint.find(gs->curB->side2) != playerint.end()) + playerint[gs->curB->side2]->battleStart(&gs->curB->army1, &gs->curB->army2, gs->curB->tile, gs->getHero(gs->curB->hero1), gs->getHero(gs->curB->hero2), 1); + + break; + } + case 3001: + { + BattleNextRound bnr; + *serv >> bnr; + std::cout << "Round nr " << bnr.round <apply(&bnr); + + //tell players about next round + if(playerint.find(gs->curB->side1) != playerint.end()) + playerint[gs->curB->side1]->battleNewRound(bnr.round); + if(playerint.find(gs->curB->side2) != playerint.end()) + playerint[gs->curB->side2]->battleNewRound(bnr.round); + break; + } + case 3002: + { + BattleSetActiveStack sas; + *serv >> sas; + std::cout << "Active stack: " << sas.stack <apply(&sas); + boost::thread(boost::bind(&CClient::waitForMoveAndSend,this,gs->curB->stacks[sas.stack]->owner)); + break; + } + case 3003: + { + BattleResult br; + *serv >> br; + std::cout << "Battle ends. Winner: " << (unsigned)br.winner<< ". Type of end: "<< (unsigned)br.result <curB->side1) != playerint.end()) + playerint[gs->curB->side1]->battleEnd(&br); + if(playerint.find(gs->curB->side2) != playerint.end()) + playerint[gs->curB->side2]->battleEnd(&br); + + gs->apply(&br); + + break; } case 9999: @@ -310,6 +383,11 @@ void CClient::process(int what) break; } } +void CClient::waitForMoveAndSend(int color) +{ + BattleAction ba = playerint[color]->activeStack(gs->curB->activeStack); + *serv << ui16(3002) << ba; +} void CClient::run() { try diff --git a/client/Client.h b/client/Client.h index 8b9c2699a..7778e6692 100644 --- a/client/Client.h +++ b/client/Client.h @@ -38,6 +38,8 @@ class CClient CGameState *gs; std::map playerint; CConnection *serv; + + void waitForMoveAndSend(int color); public: CClient(void); CClient(CConnection *con, StartInfo *si); diff --git a/client/Graphics.cpp b/client/Graphics.cpp index bc03213db..99b17e3ad 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -15,6 +15,12 @@ #include "../hch/CLodHandler.h" using namespace boost::assign; using namespace CSDL_Ext; +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif Graphics * graphics = NULL; SDL_Surface * Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to) { diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index c4feac8f1..de2d9524d 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -21,7 +21,7 @@ public: std::string abilityText; //description of abilities std::string abilityRefs; //references to abilities, in textformat std::string animDefName; - int idNumber; + ui32 idNumber; int faction; //-1 = neutral ///animation info diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index 1a5550c02..b9db4e17c 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -6,6 +6,32 @@ #include "../lib/VCMI_Lib.h" extern CLodHandler * bitmaph; void loadToIt(std::string &dest, std::string &src, int &iter, int mode); + +CHeroClass::CHeroClass() +{ + skillLimit = 8; +} +CHeroClass::~CHeroClass() +{ +} +int CHeroClass::chooseSecSkill(std::set possibles) //picks secondary skill out from given possibilities +{ + if(possibles.size()==1) + return *possibles.begin(); + int totalProb = 0; + for(std::set::iterator i=possibles.begin(); i!=possibles.end(); i++) + { + totalProb += proSec[*i]; + } + int ran = rand()%totalProb; + for(std::set::iterator i=possibles.begin(); i!=possibles.end(); i++) + { + ran -= proSec[*i]; + if(ran<0) + return *i; + } +} + CHeroHandler::~CHeroHandler() {} void CHeroHandler::loadPortraits() diff --git a/hch/CHeroHandler.h b/hch/CHeroHandler.h index 13299e619..34bf77c8c 100644 --- a/hch/CHeroHandler.h +++ b/hch/CHeroHandler.h @@ -3,7 +3,7 @@ #include "../global.h" #include #include - +#include class CHeroClass; class CDefHandler; class CGameInfo; @@ -26,6 +26,7 @@ public: class DLL_EXPORT CHeroClass { public: + ui32 skillLimit; //how many secondary skills can hero learn std::string name; float aggression; int initialAttack, initialDefence, initialPower, initialKnowledge; @@ -34,6 +35,9 @@ public: int selectionProbability[9]; //probability of selection in towns std::vector terrCosts; //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterrain, 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(std::set possibles); //picks secondary skill out from given possibilities + CHeroClass(); + ~CHeroClass(); }; class DLL_EXPORT CHeroHandler diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 97b044929..234b310d8 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -84,7 +84,7 @@ public: // 765 bool isStanding; CHero * type; - int exp; //experience point + ui32 exp; //experience point int level; //current level of hero std::string name; //may be custom std::string biography; //may be custom diff --git a/lib/BattleAction.h b/lib/BattleAction.h new file mode 100644 index 000000000..60a23ea29 --- /dev/null +++ b/lib/BattleAction.h @@ -0,0 +1,13 @@ +#pragma once +struct BattleAction +{ + ui8 side; //who made this action: false - left, true - right player + ui32 stackNumber;//stack ID, -1 left hero, -2 right hero, + ui8 actionType; // 0 = Cancel BattleAction 1 = Hero cast a spell 2 = Walk 3 = Defend 4 = Retreat from the battle 5 = Surrender 6 = Walk and Attack 7 = Shoot 8 = Wait 9 = Catapult 10 = Monster casts a spell (i.e. Faerie Dragons) + ui16 destinationTile; + ui16 additionalInfo; // e.g. spell number if type is 1 || 10 + template void serialize(Handler &h, const int version) + { + h & side & stackNumber & actionType & destinationTile & additionalInfo; + } +}; \ No newline at end of file diff --git a/lib/CondSh.h b/lib/CondSh.h new file mode 100644 index 000000000..0cc44f23b --- /dev/null +++ b/lib/CondSh.h @@ -0,0 +1,13 @@ +#pragma once +#include +template struct CondSh +{ + T data; + boost::condition_variable cond; + boost::mutex mx; + CondSh(){}; + CondSh(T t){data = t;}; + void set(T t){mx.lock();data=t;mx.unlock();}; //set data + void setn(T t){mx.lock();data=t;mx.unlock();cond.notify_all();}; //set data and notify + T get(){boost::unique_lock lock(mx); return data;}; +}; \ No newline at end of file diff --git a/lib/Connection.h b/lib/Connection.h index 360df35b9..925fa8c00 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -6,14 +6,14 @@ #include #include +#include +#include #include #include #include #include -#include - const int version = 63; class CConnection; @@ -44,6 +44,7 @@ enum SerializationLvl { Wrong=0, Primitive, + Pointer, Serializable }; @@ -64,6 +65,10 @@ struct SerializationLevel boost::is_array, mpl::int_, //else + typename mpl::eval_if< + boost::is_pointer, + mpl::int_, + //else typename mpl::eval_if< boost::is_enum, mpl::int_, @@ -72,6 +77,7 @@ struct SerializationLevel > > > + > >::type type; static const int value = SerializationLevel::type::value; }; @@ -79,7 +85,8 @@ struct SerializationLevel template class DLL_EXPORT COSer { public: - COSer(){}; + bool saving; + COSer(){saving=true;}; Serializer * This() { return static_cast(this); @@ -100,7 +107,8 @@ public: template class DLL_EXPORT CISer { public: - CISer(){}; + bool saving; + CISer(){saving = false;}; Serializer * This() { return static_cast(this); @@ -144,6 +152,22 @@ struct LoadPrimitive } }; template +struct SavePointer +{ + static void invoke(Ser &s, const T &data) + { + s.savePointer(data); + } +}; +template +struct LoadPointer +{ + static void invoke(Ser &s, T &data) + { + s.loadPointer(data); + } +}; +template struct LoadSerializable { static void invoke(Ser &s, T &data) @@ -203,8 +227,20 @@ public: void loadSerializable(T &data) { data.serialize(*static_cast*>(this),version); + } + template + void savePointer(const T &data) + { + *this << *data; + } + template + void loadPointer(T &data) + { + std::cout<<"Allocating memory for pointer!"<::type npT; + data = new npT; + *this >> *data; } - template void saveSerializable(const std::vector &data) { @@ -283,11 +319,15 @@ public: typename mpl::eval_if< mpl::equal_to,mpl::int_ >, mpl::identity >, //else if + typename mpl::eval_if,mpl::int_ >, + mpl::identity >, + //else if typename mpl::eval_if,mpl::int_ >, mpl::identity >, //else mpl::identity > > + > >::type typex; typex::invoke(*this, data); } @@ -300,11 +340,15 @@ public: typename mpl::eval_if< mpl::equal_to,mpl::int_ >, mpl::identity >, //else if + typename mpl::eval_if,mpl::int_ >, + mpl::identity >, + //else if typename mpl::eval_if,mpl::int_ >, mpl::identity >, //else mpl::identity > > + > >::type typex; typex::invoke(*this, data); } @@ -330,9 +374,9 @@ public: ~CConnection(void); }; -template<> +template<> DLL_EXPORT void CConnection::saveSerializable(const std::string &data); -template <> +template <>DLL_EXPORT void CConnection::loadSerializable(std::string &data); diff --git a/lib/NetPacks.h b/lib/NetPacks.h index bd79ad21a..3f9823441 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -82,6 +82,18 @@ struct SetResources : public CPack //104 h & player & res; } }; +struct SetPrimSkill : public CPack //105 +{ + SetPrimSkill(){type = 105;}; + ui8 abs; //0 - changes by value; 1 - sets to value + si32 id; + ui16 which, val; + + template void serialize(Handler &h, const int version) + { + h & abs & id & which & val; + } +}; struct RemoveHero : public CPack //500 { RemoveHero(){type = 500;}; @@ -225,4 +237,79 @@ struct SetHoverName : public CPack//1002 { h & id & name; } -}; \ No newline at end of file +}; +struct HeroLevelUp : public CPack//2000 +{ + si32 id; + ui8 primskill, level; + std::set skills; + + HeroLevelUp(){type = 2000;}; + + template void serialize(Handler &h, const int version) + { + h & id & primskill & level & skills; + } +}; +struct BattleInfo; +struct BattleStart : public CPack//3000 +{ + BattleInfo * info; + + BattleStart(){type = 3000;}; + + template void serialize(Handler &h, const int version) + { + h & info; + } +}; +struct BattleNextRound : public CPack//3001 +{ + si32 round; + + BattleNextRound(){type = 3001;}; + + template void serialize(Handler &h, const int version) + { + h & round; + } +}; +struct BattleSetActiveStack : public CPack//3002 +{ + ui32 stack; + + BattleSetActiveStack(){type = 3002;}; + template void serialize(Handler &h, const int version) + { + h & stack; + } +}; +struct BattleResult : public CPack//3003 +{ + ui8 result; //0 - normal victory; 1 - escape; 2 - surrender + ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)] + std::set > s1, s2; //first => casualties of attackers - set of pairs crid<>number + ui32 exp[2]; //exp for attacker and defender + std::set artifacts; //artifacts taken from loser to winner + + + + BattleResult(){type = 3003;}; + template void serialize(Handler &h, const int version) + { + h & result & winner & s1 & s2 & exp & artifacts; + } +}; + +struct ShowInInfobox : public CPack //107 +{ + ShowInInfobox(){type = 107;}; + ui8 player; + Component c; + MetaString text; + + template void serialize(Handler &h, const int version) + { + h & player & c & text; + } +}; \ No newline at end of file diff --git a/lib/VCMI_lib.vcproj b/lib/VCMI_lib.vcproj index d9df4651c..41ebcd03a 100644 --- a/lib/VCMI_lib.vcproj +++ b/lib/VCMI_lib.vcproj @@ -319,6 +319,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + @@ -355,6 +359,10 @@ RelativePath="..\hch\CObjectHandler.h" > + + diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index f5314bfec..173bf54f6 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -17,14 +17,36 @@ #include "../hch/CHeroHandler.h" #include "boost/date_time/posix_time/posix_time_types.hpp" //no i/o just types #include "../lib/VCMI_Lib.h" -#include +#include "../lib/CondSh.h" #include extern bool end2; -bool makingTurn; +#include "../lib/BattleAction.h" +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif +#define NEW_ROUND BattleNextRound bnr;\ + bnr.round = gs->curB->round + 1;\ + sendAndApply(&bnr); boost::condition_variable cTurn; boost::mutex mTurn; boost::shared_mutex gsm; + +CondSh battleMadeAction; +CondSh battleResult(NULL); + +class CMP_stack +{ +public: + bool operator ()(const CStack* a, const CStack* b) + { + return (a->creature->speed)>(b->creature->speed); + } +} cmpst ; + double distance(int3 a, int3 b) { return std::sqrt( (double)(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ); @@ -51,6 +73,268 @@ void CGameHandler::handleCPPObjS(std::map * mapa, CCPPObj cppscripts.insert(script); } +void CGameHandler::changePrimSkill(int ID, int which, int val, bool abs) +{ + SetPrimSkill sps; + sps.id = ID; + sps.which = which; + sps.abs = abs; + sps.val = val; + sendAndApply(&sps); + if(which==4) + { + CGHeroInstance *hero = static_cast(gs->map->objects[ID]); + if(hero->exp >= VLC->heroh->reqExp(hero->level+1)) //new level + { + //hero->level++; + + //give prim skill + std::cout << hero->name <<" got level "<level<::*g = (hero->level>9) ? (&std::pair::second) : (&std::pair::first); + for(;xtype->heroClass->primChance[x].*g; + if(rprimSkills[x]++; + + std::set choice; + + std::set basicAndAdv, expert, none; + for(int i=0;isecSkills.size();i++) + { + if(hero->secSkills[i].second < 2) + basicAndAdv.insert(hero->secSkills[i].first); + else + expert.insert(hero->secSkills[i].first); + none.erase(hero->secSkills[i].first); + } + if(hero->secSkills.size() < hero->type->heroClass->skillLimit) //free skill slot + { + choice.insert(hero->type->heroClass->chooseSecSkill(none)); //new skill + } + else + { + int s = hero->type->heroClass->chooseSecSkill(basicAndAdv); + choice.insert(s); + basicAndAdv.erase(s); + } + if(basicAndAdv.size()) + { + choice.insert(hero->type->heroClass->chooseSecSkill(basicAndAdv)); //new skill + } + else if(hero->secSkills.size() < hero->type->heroClass->skillLimit) + { + choice.insert(hero->type->heroClass->chooseSecSkill(none)); //new skill + } + + } + //TODO - powiadomic interfejsy, sprawdzic czy nie ma awansu itp + } +} + +void CGameHandler::startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2) +{ + + BattleInfo *curB = new BattleInfo; + //battle start + { + battleResult.set(NULL); + std::vector & stacks = (curB->stacks); + + curB->army1=army1; + curB->army2=army2; + curB->hero1=(hero1)?(hero1->id):(-1); + curB->hero2=(hero1)?(hero1->id):(-1); + curB->side1=(hero1)?(hero1->tempOwner):(-1); + curB->side2=(hero2)?(hero2->tempOwner):(-1); + curB->round = -2; + curB->activeStack = -1; + for(std::map >::iterator i = army1.slots.begin(); i!=army1.slots.end(); i++) + { + stacks.push_back(new CStack(&VLC->creh->creatures[i->second.first],i->second.second,hero1->tempOwner, stacks.size(), true)); + stacks[stacks.size()-1]->ID = stacks.size()-1; + } + //initialization of positions + switch(army1.slots.size()) //for attacker + { + case 0: + break; + case 1: + stacks[0]->position = 86; //6 + break; + case 2: + stacks[0]->position = 35; //3 + stacks[1]->position = 137; //9 + break; + case 3: + stacks[0]->position = 35; //3 + stacks[1]->position = 86; //6 + stacks[2]->position = 137; //9 + break; + case 4: + stacks[0]->position = 1; //1 + stacks[1]->position = 69; //5 + stacks[2]->position = 103; //7 + stacks[3]->position = 171; //11 + break; + case 5: + stacks[0]->position = 1; //1 + stacks[1]->position = 35; //3 + stacks[2]->position = 86; //6 + stacks[3]->position = 137; //9 + stacks[4]->position = 171; //11 + break; + case 6: + stacks[0]->position = 1; //1 + stacks[1]->position = 35; //3 + stacks[2]->position = 69; //5 + stacks[3]->position = 103; //7 + stacks[4]->position = 137; //9 + stacks[5]->position = 171; //11 + break; + case 7: + stacks[0]->position = 1; //1 + stacks[1]->position = 35; //3 + stacks[2]->position = 69; //5 + stacks[3]->position = 86; //6 + stacks[4]->position = 103; //7 + stacks[5]->position = 137; //9 + stacks[6]->position = 171; //11 + break; + default: //fault + break; + } + for(std::map >::iterator i = army2.slots.begin(); i!=army2.slots.end(); i++) + stacks.push_back(new CStack(&VLC->creh->creatures[i->second.first],i->second.second,hero2 ? hero2->tempOwner : 255, stacks.size(), false)); + switch(army2.slots.size()) //for defender + { + case 0: + break; + case 1: + stacks[0+army1.slots.size()]->position = 100; //6 + break; + case 2: + stacks[0+army1.slots.size()]->position = 49; //3 + stacks[1+army1.slots.size()]->position = 151; //9 + break; + case 3: + stacks[0+army1.slots.size()]->position = 49; //3 + stacks[1+army1.slots.size()]->position = 100; //6 + stacks[2+army1.slots.size()]->position = 151; //9 + break; + case 4: + stacks[0+army1.slots.size()]->position = 15; //1 + stacks[1+army1.slots.size()]->position = 83; //5 + stacks[2+army1.slots.size()]->position = 117; //7 + stacks[3+army1.slots.size()]->position = 185; //11 + break; + case 5: + stacks[0+army1.slots.size()]->position = 15; //1 + stacks[1+army1.slots.size()]->position = 49; //3 + stacks[2+army1.slots.size()]->position = 100; //6 + stacks[3+army1.slots.size()]->position = 151; //9 + stacks[4+army1.slots.size()]->position = 185; //11 + break; + case 6: + stacks[0+army1.slots.size()]->position = 15; //1 + stacks[1+army1.slots.size()]->position = 49; //3 + stacks[2+army1.slots.size()]->position = 83; //5 + stacks[3+army1.slots.size()]->position = 117; //7 + stacks[4+army1.slots.size()]->position = 151; //9 + stacks[5+army1.slots.size()]->position = 185; //11 + break; + case 7: + stacks[0+army1.slots.size()]->position = 15; //1 + stacks[1+army1.slots.size()]->position = 49; //3 + stacks[2+army1.slots.size()]->position = 83; //5 + stacks[3+army1.slots.size()]->position = 100; //6 + stacks[4+army1.slots.size()]->position = 117; //7 + stacks[5+army1.slots.size()]->position = 151; //9 + stacks[6+army1.slots.size()]->position = 185; //11 + break; + default: //fault + break; + } + for(unsigned g=0; gposition%17)==1 && stacks[g]->creature->isDoubleWide()) + { + stacks[g]->position += 1; + } + else if((stacks[g]->position%17)==15 && stacks[g]->creature->isDoubleWide()) + { + stacks[g]->position -= 1; + } + } + std::stable_sort(stacks.begin(),stacks.end(),cmpst); + + //block engaged players + if(hero1->tempOwnertempOwner] += 10; + if(hero2 && hero2->tempOwnertempOwner] += 10; + + //send info about battles + BattleStart bs; + bs.info = curB; + sendAndApply(&bs); + + NEW_ROUND; + } + + //tactic round + { + NEW_ROUND; + if( (hero1 && hero1->getSecSkillLevel(19)>=0) || + ( hero2 && hero2->getSecSkillLevel(19)>=0) )//someone has tactics + { + //TODO: tactic round (round -1) + } + } + + //main loop + while(!battleResult.get()) //till the end of the battle ;] + { + NEW_ROUND; + std::vector & stacks = (gs->curB->stacks); + const BattleInfo & curB = *gs->curB; + + //stack loop + for(unsigned i=0;ialive) continue;//indicates imposiibility of making action for this dead unit + BattleSetActiveStack sas; + sas.stack = i; + sendAndApply(&sas); + + //wait for response about battle action + + boost::unique_lock lock(battleMadeAction.mx); + while(!battleMadeAction.data) + battleMadeAction.cond.wait(lock); + } + } + + //end battle, remove all info, free memory + sendAndApply(battleResult.data); + delete battleResult.data; + //for(int i=0;i players, CConnection &c) { try @@ -65,7 +349,7 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) case 100: //my interface ended its turn { mTurn.lock(); - makingTurn = false; + states[gs->currentPlayer] = 0; mTurn.unlock(); cTurn.notify_all(); break; @@ -290,6 +574,47 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) sr.res[i]-=b->resources[i]; sendAndApply(&sr); + break; + } + case 3002: + { + BattleAction ba; + c >> ba; + switch(ba.actionType) + { + case 2: //walk + { + //battleMoveCreatureStack(ba.stackNumber, ba.destinationTile); + break; + } + case 3: //defend + { + break; + } + case 4: //retreat/flee + { + //TODO: check if fleeing is possible (e.g. enemy may have Shackles of War) + //TODO: calculate casualties + //TODO: remove retreating hero from map and place it in recrutation list + BattleResult *br = new BattleResult; + br->result = 1; + battleResult.set(br); + break; + } + case 6: //walk or attack + { + //battleMoveCreatureStack(ba.stackNumber, ba.destinationTile); + //battleAttackCreatureStack(ba.stackNumber, ba.destinationTile); + break; + } + case 7: //shoot + { + //battleShootCreatureStack(ba.stackNumber, ba.destinationTile); + break; + } + } + battleMadeAction.setn(true); + //sprawdzic czy po tej akcji ktoras strona nie wygrala bitwy break; } default: @@ -490,12 +815,12 @@ void CGameHandler::run() for(std::map::iterator i = gs->players.begin(); i != gs->players.end(); i++) { 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 - makingTurn = true; + states[i->first] = 1; gs->currentPlayer = i->first; *connections[i->first] << ui16(100) << i->first; //wait till turn is done boost::unique_lock lock(mTurn); - while(makingTurn && !end2) + while(states[i->first] && !end2) { boost::posix_time::time_duration p; p= boost::posix_time::seconds(1); @@ -503,7 +828,6 @@ void CGameHandler::run() time.sec = static_cast(p.total_seconds()); cTurn.timed_wait(lock,time); } - } } } diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 8641d0a7f..b1c68ea2b 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -10,7 +10,7 @@ struct StartInfo; class CCPPObjectScript; class CScriptCallback; template struct CPack; - +class CGHeroInstance; class CGameHandler { @@ -19,10 +19,14 @@ class CGameHandler //std::map > objscr; //non-C++ scripts CVCMIServer *s; - std::map connections; + std::map connections; //player color -> connection to clinet with interface of that player + std::map states; //player color -> player state std::set conns; void handleCPPObjS(std::map * mapa, CCPPObjectScript * script); + void changePrimSkill(int ID, int which, int val, bool abs=false); + void startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2); //use hero=NULL for no hero + public: CGameHandler(void); @@ -33,9 +37,9 @@ public: { for(std::set::iterator i=conns.begin(); i!=conns.end();i++) { - (*i)->rmx->lock(); + (*i)->wmx->lock(); **i << info->getType() << *info->This(); - (*i)->rmx->unlock(); + (*i)->wmx->unlock(); } } template void sendAndApply(CPack * info) diff --git a/server/CScriptCallback.cpp b/server/CScriptCallback.cpp index 483c5ff5c..0c9abd64a 100644 --- a/server/CScriptCallback.cpp +++ b/server/CScriptCallback.cpp @@ -8,6 +8,8 @@ #include "../hch/CTownHandler.h" #include "../hch/CHeroHandler.h" #include "../lib/NetPacks.h" +#include "../lib/VCMI_Lib.h" +#include #include #include CScriptCallback::CScriptCallback(void) @@ -48,37 +50,9 @@ int3 CScriptCallback::getPos(CGObjectInstance * ob) { return ob->pos; } -void CScriptCallback::changePrimSkill(int ID, int which, int val) -{ - //CGHeroInstance * hero = gh->gs->map->getHero(ID,0); - //if (whichprimSkills[which]+=val; - // sv->playerint[hero->getOwner()]->heroPrimarySkillChanged(hero, which, val); - //} - //else if (which==4) - //{ - // hero->exp+=val; - // if(hero->exp >= CGI->heroh->reqExp(hero->level+1)) //new level - // { - // hero->level++; - // std::cout << hero->name <<" got level "<level<::*g = (hero->level>9) ? (&std::pair::second) : (&std::pair::first); - // for(;xtype->heroClass->primChance[x].*g; - // if(rprimSkills[x]++; - - // //TODO: dac dwie umiejetnosci 2-rzedne to wyboru - - // } - // //TODO - powiadomic interfejsy, sprawdzic czy nie ma awansu itp - //} +void CScriptCallback::changePrimSkill(int ID, int which, int val, bool abs) +{ + gh->changePrimSkill(ID, which, val, abs); } int CScriptCallback::getHeroOwner(int heroID) @@ -116,7 +90,7 @@ void CScriptCallback::showSelDialog(int player, std::string text, std::vectoradventureInt->selection.type == HEROI_TYPE) // ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->subID; //else @@ -135,11 +109,9 @@ void CScriptCallback::giveResource(int player, int which, int val) sr.val = (gh->gs->players[player].resources[which]+val); gh->sendAndApply(&sr); } -void CScriptCallback::showCompInfo(int player, SComponent * comp) +void CScriptCallback::showCompInfo(ShowInInfobox * comp) { - //CPlayerInterface * i = dynamic_cast(sv->playerint[player]); - //if(i) - // i->showComp(*comp); + gh->sendToAllClients(comp); } void CScriptCallback::heroVisitCastle(int obj, int heroID) { @@ -195,11 +167,12 @@ void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos== void CScriptCallback::startBattle(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2) //use hero=NULL for no hero { - //gh->gs->battle(army1,army2,tile,hero1,hero2); + boost::thread(boost::bind(&CGameHandler::startBattle,gh,*(CCreatureSet *)army1,*(CCreatureSet *)army2,tile,(CGHeroInstance *)hero1,(CGHeroInstance *)hero2)); } -void CScriptCallback::startBattle(int heroID, CCreatureSet * army, int3 tile) //for hero<=>neutral army +void CScriptCallback::startBattle(int heroID, CCreatureSet army, int3 tile) //for hero<=>neutral army { - //CGHeroInstance* h = gh->gs->map->getHero(heroID,0); + CGHeroInstance* h = const_cast(getHero(heroID)); + startBattle(&h->army,&army,tile,h,NULL); //gh->gs->battle(&h->army,army,tile,h,NULL); } void CLuaCallback::registerFuncs(lua_State * L) diff --git a/server/CScriptCallback.h b/server/CScriptCallback.h index e90135a72..a4ee7794f 100644 --- a/server/CScriptCallback.h +++ b/server/CScriptCallback.h @@ -15,6 +15,7 @@ class CGameState; struct lua_State; struct MetaString; struct InfoWindow; +struct ShowInInfobox; class CScriptCallback { CScriptCallback(void); @@ -35,16 +36,16 @@ public: void setBlockVis(int objid, bool bv); void setOwner(int objid, ui8 owner); void setHoverName(int objid, MetaString * name); - void changePrimSkill(int ID, int which, int val); + void changePrimSkill(int ID, int which, int val, bool abs=false); void showInfoDialog(InfoWindow *iw); void showSelDialog(int player, std::string text, std::vector*components, IChosen * asker); void giveResource(int player, int which, int val); - void showCompInfo(int player, SComponent * comp); + void showCompInfo(ShowInInfobox * comp); void heroVisitCastle(int obj, int heroID); void stopHeroVisitCastle(int obj, int heroID); void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack void startBattle(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2); //use hero=NULL for no hero - void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army + void startBattle(int heroID, CCreatureSet army, int3 tile); //for hero<=>neutral army //friends friend class CGameHandler; From 1bd3a677fe7ff953dac4942693bc16ff0cefa53f Mon Sep 17 00:00:00 2001 From: Vadim Glazunov Date: Mon, 4 Aug 2008 20:27:47 +0000 Subject: [PATCH 43/47] Little changes to fix broken gcc compilation, hope MSVC still compile --- CGameState.h | 2 ++ lib/Connection.h | 2 +- lib/VCMI_Lib.h | 10 +++++++++- server/CGameHandler.h | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CGameState.h b/CGameState.h index 4c8b79ce8..c13b88b59 100644 --- a/CGameState.h +++ b/CGameState.h @@ -1,6 +1,8 @@ #ifndef CGAMESTATE_H #define CGAMESTATE_H #include "global.h" +#include "../hch/CCreatureHandler.h" +#include "lib/VCMI_Lib.h" #include #include #ifdef _WIN32 diff --git a/lib/Connection.h b/lib/Connection.h index 925fa8c00..a071f7dd0 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -237,7 +237,7 @@ public: void loadPointer(T &data) { std::cout<<"Allocating memory for pointer!"<::type npT; + typedef typename boost::remove_pointer::type npT; data = new npT; *this >> *data; } diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index fa37692f3..b2fd10281 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -1,3 +1,5 @@ +#ifndef VCMI_LIB_H +#define VCMI_LIB_H #include "../global.h" class CLodHandler; @@ -55,7 +57,13 @@ public: //StartInfo scenarioOps; }; +#ifndef __GNUC__ +DLL_EXPORT LibClasses * VLC; +#else extern DLL_EXPORT LibClasses * VLC; +#endif -DLL_EXPORT void initDLL(CLodHandler *b); \ No newline at end of file +DLL_EXPORT void initDLL(CLodHandler *b); + +#endif //VCMI_LIB_H diff --git a/server/CGameHandler.h b/server/CGameHandler.h index b1c68ea2b..1b0bf5d53 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -3,6 +3,7 @@ #include #include "../CGameState.h" #include "../lib/Connection.h" +#include class CVCMIServer; class CGameState; //class CConnection; From a5354271e226cfb5b12426f53ba95b2f5599109c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 4 Aug 2008 23:04:15 +0000 Subject: [PATCH 44/47] * improvements in battle support - moving creatures work though there are small graphic glitches * @neweagle - I've replaced in VCMI_Lib.h your #ifndef with #ifdef since you modification affected (and broke) compilation only on MSVC. Is it ok now? --- CCallback.cpp | 86 ++++----- CGameState.cpp | 389 +++++++++++++++------------------------- CGameState.h | 8 +- CPlayerInterface.cpp | 2 + client/Client.cpp | 16 +- lib/NetPacks.h | 22 +++ lib/VCMI_Lib.h | 2 +- server/CGameHandler.cpp | 78 +++++++- server/CGameHandler.h | 2 + 9 files changed, 303 insertions(+), 302 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index d304b808b..eb60d1705 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -18,6 +18,7 @@ #include #include #include "lib/NetPacks.h" +#include #ifdef min #undef min #endif @@ -53,7 +54,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) else //idtype==1; player<0 { - for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j) + for(std::map::iterator j=gs->players.begin(); j!=gs->players.end(); ++j) { for (int i=0; i<(*j).second.heroes.size();i++) { @@ -264,10 +265,12 @@ const CGTownInstance * CCallback::getTownInfo(int val, bool mode) //mode = 0 -> } int CCallback::howManyHeroes() { + boost::shared_lock lock(*gs->mx); return gs->players[player].heroes.size(); } const CGHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) //mode = 0 -> val = serial; mode = 1 -> val = ID { + boost::shared_lock lock(*gs->mx); if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info return NULL; if (!mode) @@ -287,41 +290,22 @@ const CGHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) // int CCallback::getResourceAmount(int type) { + boost::shared_lock lock(*gs->mx); return gs->players[player].resources[type]; } std::vector CCallback::getResourceAmount() { + boost::shared_lock lock(*gs->mx); return gs->players[player].resources; } int CCallback::getDate(int mode) { + boost::shared_lock lock(*gs->mx); return gs->getDate(mode); - - - - - - - - - - - - - - - - - - - - - - - } std::vector < std::string > CCallback::getObjDescriptions(int3 pos) { + boost::shared_lock lock(*gs->mx); std::vector ret; BOOST_FOREACH(const CGObjectInstance * obj, gs->map->terrain[pos.x][pos.y][pos.z].blockingObjects) ret.push_back(obj->hoverName); @@ -362,17 +346,20 @@ bool CCallback::verifyPath(CPath * path, bool blockSea) std::vector< std::vector< std::vector > > & CCallback::getVisibilityMap() { + boost::shared_lock lock(*gs->mx); return gs->players[player].fogOfWarMap; } bool CCallback::isVisible(int3 pos, int Player) { + boost::shared_lock lock(*gs->mx); return gs->players[Player].fogOfWarMap[pos.x][pos.y][pos.z]; } std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) { + boost::shared_lock lock(*gs->mx); std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>(); for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) { @@ -388,6 +375,7 @@ std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) } std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur) { + boost::shared_lock lock(*gs->mx); std::vector < const CGHeroInstance *> ret; for(int i=0;imap->heroes.size();i++) { @@ -411,6 +399,7 @@ int CCallback::getMyColor() } int CCallback::getHeroSerial(const CGHeroInstance * hero) { + boost::shared_lock lock(*gs->mx); for (int i=0; iplayers[player].heroes.size();i++) { if (gs->players[player].heroes[i]==hero) @@ -432,9 +421,6 @@ const CCreatureSet* CCallback::getGarrison(const CGObjectInstance *obj) int CCallback::swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2) { if(s1->tempOwner != player || s2->tempOwner != player) - - - return -1; *cl->serv << ui16(502) << ui8(1) << s1->id << ui8(p1) << s2->id << ui8(p2); @@ -469,6 +455,7 @@ bool CCallback::dismissHero(const CGHeroInstance *hero) int CCallback::getMySerial() { + boost::shared_lock lock(*gs->mx); return gs->players[player].serial; } @@ -517,7 +504,8 @@ bool CCallback::buildBuilding(const CGTownInstance *town, si32 buildingID) int CCallback::battleGetBattlefieldType() { - return CGI->mh->ttiles[CGI->state->curB->tile.x][CGI->state->curB->tile.y][CGI->state->curB->tile.z].tileInfo->tertype; + boost::shared_lock lock(*gs->mx); + return CGI->mh->ttiles[gs->curB->tile.x][gs->curB->tile.y][gs->curB->tile.z].tileInfo->tertype; } int CCallback::battleGetObstaclesAtTile(int tile) //returns bitfield @@ -527,17 +515,15 @@ int CCallback::battleGetObstaclesAtTile(int tile) //returns bitfield } int CCallback::battleGetStack(int pos) { - return CGI->state->battleGetStack(pos); + boost::shared_lock lock(*gs->mx); + return gs->battleGetStack(pos); } CStack* CCallback::battleGetStackByID(int ID) { - for(int g=0; gstate->curB->stacks.size(); ++g) - { - if(CGI->state->curB->stacks[g]->ID == ID) - return CGI->state->curB->stacks[g]; - } - return NULL; + boost::shared_lock lock(*gs->mx); + if(!gs->curB) return NULL; + return gs->curB->getStack(ID); } CStack* CCallback::battleGetStackByPos(int pos) @@ -547,30 +533,33 @@ CStack* CCallback::battleGetStackByPos(int pos) int CCallback::battleGetPos(int stack) { - for(int g=0; gstate->curB->stacks.size(); ++g) + boost::shared_lock lock(*gs->mx); + for(int g=0; gcurB->stacks.size(); ++g) { - if(CGI->state->curB->stacks[g]->ID == stack) - return CGI->state->curB->stacks[g]->position; + if(gs->curB->stacks[g]->ID == stack) + return gs->curB->stacks[g]->position; } return -1; } std::map CCallback::battleGetStacks() { + boost::shared_lock lock(*gs->mx); std::map ret; - for(int g=0; gstate->curB->stacks.size(); ++g) + for(int g=0; gcurB->stacks.size(); ++g) { - ret[CGI->state->curB->stacks[g]->ID] = *(CGI->state->curB->stacks[g]); + ret[gs->curB->stacks[g]->ID] = *(gs->curB->stacks[g]); } return ret; } CCreature CCallback::battleGetCreature(int number) { - for(int h=0; hstate->curB->stacks.size(); ++h) + boost::shared_lock lock(*gs->mx); + for(int h=0; hcurB->stacks.size(); ++h) { - if(CGI->state->curB->stacks[h]->ID == number) //creature found - return *(CGI->state->curB->stacks[h]->creature); + if(gs->curB->stacks[h]->ID == number) //creature found + return *(gs->curB->stacks[h]->creature); } #ifndef __GNUC__ throw new std::exception("Cannot find the creature"); @@ -581,20 +570,23 @@ CCreature CCallback::battleGetCreature(int number) std::vector CCallback::battleGetAvailableHexes(int ID) { - return CGI->state->battleGetRange(ID); + boost::shared_lock lock(*gs->mx); + return gs->battleGetRange(ID); } bool CCallback::battleIsStackMine(int ID) { - for(int h=0; hstate->curB->stacks.size(); ++h) + boost::shared_lock lock(*gs->mx); + for(int h=0; hcurB->stacks.size(); ++h) { - if(CGI->state->curB->stacks[h]->ID == ID) //creature found - return CGI->state->curB->stacks[h]->owner == player; + if(gs->curB->stacks[h]->ID == ID) //creature found + return gs->curB->stacks[h]->owner == player; } return false; } bool CCallback::battleCanShoot(int ID, int dest) //TODO: finish { + boost::shared_lock lock(*gs->mx); if(battleGetStackByID(ID)->creature->isShooting() && battleGetStack(dest) != -1 && battleGetStackByPos(dest)->owner != battleGetStackByID(ID)->owner diff --git a/CGameState.cpp b/CGameState.cpp index fbff5897a..6c945371c 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -86,6 +86,140 @@ CGObjectInstance * createObject(int id, int subid, int3 pos, int owner) //} return nobj; } +CStack * BattleInfo::getStack(int stackID) +{ + for(int g=0; gID == stackID) + return stacks[g]; + } + return NULL; +} +CStack * BattleInfo::getStackT(int tileID) +{ + for(int g=0; gposition == tileID + || (stacks[g]->creature->isDoubleWide() && stacks[g]->attackerOwned && stacks[g]->position-1 == tileID) + || (stacks[g]->creature->isDoubleWide() && !stacks[g]->attackerOwned && stacks[g]->position+1 == tileID)) + { + if(stacks[g]->alive) + { + return stacks[g]; + } + } + } + return NULL; +} +void BattleInfo::getAccessibilityMap(bool *accessibility) +{ + memset(accessibility,1,187); //initialize array with trues + for(int g=0; galive) //we don't want to lock enemy's positions and this units' position + continue; + + accessibility[stacks[g]->position] = false; + if(stacks[g]->creature->isDoubleWide()) //if it's a double hex creature + { + if(stacks[g]->attackerOwned) + accessibility[stacks[g]->position-1] = false; + else + accessibility[stacks[g]->position+1] = false; + } + } +} +void BattleInfo::getAccessibilityMapForTwoHex(bool *accessibility, bool atackerSide) //send pointer to at least 187 allocated bytes +{ + bool mac[187]; + getAccessibilityMap(mac); + memcpy(accessibility,mac,187); + + for(int b=0; b<187; ++b) + { + if( mac[b] && !(atackerSide ? mac[b-1] : mac[b+1])) + { + accessibility[b] = false; + } + } + //removing accessibility for side hexes + for(int v=0; v<187; ++v) + if(atackerSide ? (v%17)==1 : (v%17)==15) + accessibility[v] = false; +} + +std::vector BattleInfo::getPath(int start, int dest, bool*accessibility) +{ + int predecessor[187]; //for getting the Path + for(int b=0; b<187; ++b) + predecessor[b] = -1; + //bfsing + int dists[187]; //calculated distances + std::queue hexq; //bfs queue + hexq.push(start); + for(int g=0; g<187; ++g) + dists[g] = 100000000; + dists[hexq.front()] = 0; + int curNext = -1; //for bfs loop only (helper var) + while(!hexq.empty()) //bfs loop + { + int curHex = hexq.front(); + hexq.pop(); + curNext = curHex - ( (curHex/17)%2 ? 18 : 17 ); + if((curNext > 0) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top left + { + hexq.push(curNext); + dists[curNext] = dists[curHex] + 1; + predecessor[curNext] = curHex; + } + curNext = curHex - ( (curHex/17)%2 ? 17 : 16 ); + if((curNext > 0) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top right + { + hexq.push(curNext); + dists[curNext] = dists[curHex] + 1; + predecessor[curNext] = curHex; + } + curNext = curHex - 1; + if((curNext > 0) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //left + { + hexq.push(curNext); + dists[curNext] = dists[curHex] + 1; + predecessor[curNext] = curHex; + } + curNext = curHex + 1; + if((curNext < 187) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //right + { + hexq.push(curNext); + dists[curNext] = dists[curHex] + 1; + predecessor[curNext] = curHex; + } + curNext = curHex + ( (curHex/17)%2 ? 16 : 17 ); + if((curNext < 187) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom left + { + hexq.push(curNext); + dists[curNext] = dists[curHex] + 1; + predecessor[curNext] = curHex; + } + curNext = curHex + ( (curHex/17)%2 ? 17 : 18 ); + if((curNext < 187) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom right + { + hexq.push(curNext); + dists[curNext] = dists[curHex] + 1; + predecessor[curNext] = curHex; + } + } + + //following the Path + std::vector path; + int curElem = dest; + while(curElem != start) + { + path.push_back(curElem); + curElem = predecessor[curElem]; + } + return path; +} + CStack::CStack(CCreature * C, int A, int O, int I, bool AO) :creature(C),amount(A),owner(O), alive(true), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints) { @@ -238,6 +372,13 @@ void CGameState::apply(IPack * pack) delete curB->stacks[i]; delete curB; curB = NULL; + break; + } + case 3004: + { + BattleStackMoved *br = static_cast(pack); + curB->getStack(br->stack)->position = br->tile; + break; } //case 1002://set hover name // { @@ -749,254 +890,6 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed) } } } -void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2) -{/* - curB = new BattleInfo(); - std::vector & stacks = (curB->stacks); - - curB->army1=army1; - curB->army2=army2; - curB->hero1=dynamic_cast(hero1); - curB->hero2=dynamic_cast(hero2); - curB->side1=(hero1)?(hero1->tempOwner):(-1); - curB->side2=(hero2)?(hero2->tempOwner):(-1); - curB->round = -2; - curB->stackActionPerformed = false; - for(std::map >::iterator i = army1->slots.begin(); i!=army1->slots.end(); i++) - { - stacks.push_back(new CStack(i->second.first,i->second.second,0, stacks.size(), true)); - stacks[stacks.size()-1]->ID = stacks.size()-1; - } - //initialization of positions - switch(army1->slots.size()) //for attacker - { - case 0: - break; - case 1: - stacks[0]->position = 86; //6 - break; - case 2: - stacks[0]->position = 35; //3 - stacks[1]->position = 137; //9 - break; - case 3: - stacks[0]->position = 35; //3 - stacks[1]->position = 86; //6 - stacks[2]->position = 137; //9 - break; - case 4: - stacks[0]->position = 1; //1 - stacks[1]->position = 69; //5 - stacks[2]->position = 103; //7 - stacks[3]->position = 171; //11 - break; - case 5: - stacks[0]->position = 1; //1 - stacks[1]->position = 35; //3 - stacks[2]->position = 86; //6 - stacks[3]->position = 137; //9 - stacks[4]->position = 171; //11 - break; - case 6: - stacks[0]->position = 1; //1 - stacks[1]->position = 35; //3 - stacks[2]->position = 69; //5 - stacks[3]->position = 103; //7 - stacks[4]->position = 137; //9 - stacks[5]->position = 171; //11 - break; - case 7: - stacks[0]->position = 1; //1 - stacks[1]->position = 35; //3 - stacks[2]->position = 69; //5 - stacks[3]->position = 86; //6 - stacks[4]->position = 103; //7 - stacks[5]->position = 137; //9 - stacks[6]->position = 171; //11 - break; - default: //fault - break; - } - for(std::map >::iterator i = army2->slots.begin(); i!=army2->slots.end(); i++) - stacks.push_back(new CStack(i->second.first,i->second.second,1, stacks.size(), false)); - switch(army2->slots.size()) //for defender - { - case 0: - break; - case 1: - stacks[0+army1->slots.size()]->position = 100; //6 - break; - case 2: - stacks[0+army1->slots.size()]->position = 49; //3 - stacks[1+army1->slots.size()]->position = 151; //9 - break; - case 3: - stacks[0+army1->slots.size()]->position = 49; //3 - stacks[1+army1->slots.size()]->position = 100; //6 - stacks[2+army1->slots.size()]->position = 151; //9 - break; - case 4: - stacks[0+army1->slots.size()]->position = 15; //1 - stacks[1+army1->slots.size()]->position = 83; //5 - stacks[2+army1->slots.size()]->position = 117; //7 - stacks[3+army1->slots.size()]->position = 185; //11 - break; - case 5: - stacks[0+army1->slots.size()]->position = 15; //1 - stacks[1+army1->slots.size()]->position = 49; //3 - stacks[2+army1->slots.size()]->position = 100; //6 - stacks[3+army1->slots.size()]->position = 151; //9 - stacks[4+army1->slots.size()]->position = 185; //11 - break; - case 6: - stacks[0+army1->slots.size()]->position = 15; //1 - stacks[1+army1->slots.size()]->position = 49; //3 - stacks[2+army1->slots.size()]->position = 83; //5 - stacks[3+army1->slots.size()]->position = 117; //7 - stacks[4+army1->slots.size()]->position = 151; //9 - stacks[5+army1->slots.size()]->position = 185; //11 - break; - case 7: - stacks[0+army1->slots.size()]->position = 15; //1 - stacks[1+army1->slots.size()]->position = 49; //3 - stacks[2+army1->slots.size()]->position = 83; //5 - stacks[3+army1->slots.size()]->position = 100; //6 - stacks[4+army1->slots.size()]->position = 117; //7 - stacks[5+army1->slots.size()]->position = 151; //9 - stacks[6+army1->slots.size()]->position = 185; //11 - break; - default: //fault - break; - } - for(int g=0; gposition%17)==1 && stacks[g]->creature->isDoubleWide()) - { - stacks[g]->position += 1; - } - else if((stacks[g]->position%17)==15 && stacks[g]->creature->isDoubleWide()) - { - stacks[g]->position -= 1; - } - } - std::stable_sort(stacks.begin(),stacks.end(),cmpst); - - //for start inform players about battle - for(std::map::iterator j=players.begin(); j!=players.end(); ++j)//->players.size(); ++j) //for testing - { - if (j->first > PLAYER_LIMIT) - break; - if(j->second.fogOfWarMap[tile.x][tile.y][tile.z]) - { //player should be notified - tribool side = tribool::indeterminate_value; - if(j->first == curB->side1) //player is attacker - side = false; - else if(j->first == curB->side2) //player is defender - side = true; - else - continue; //no witnesses - if(VLC->playerint[j->second.serial]->human) - { - ((CPlayerInterface*)( VLC->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); - } - else - { - //VLC->playerint[j->second.serial]->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); - } - } - } - - curB->round++; - if( (curB->hero1 && curB->hero1->getSecSkillLevel(19)>=0) || ( curB->hero2 && curB->hero2->getSecSkillLevel(19)>=0) )//someone has tactics - { - //TODO: wywolania dla rundy -1, ograniczenie pola ruchu, etc - } - - curB->round++; - - //SDL_Thread * eventh = SDL_CreateThread(battleEventThread, NULL); - - while(true) //till the end of the battle ;] - { - bool battleEnd = false; - //tell players about next round - for(int v=0; vplayerint.size(); ++v) - VLC->playerint[v]->battleNewRound(curB->round); - - //stack loop - for(int i=0;iactiveStack = i; - curB->stackActionPerformed = false; - if(stacks[i]->alive) //indicate posiibility of making action for this unit - { - unsigned char owner = (stacks[i]->owner)?(hero2 ? hero2->tempOwner : 255):(hero1->tempOwner); - unsigned char serialOwner = -1; - for(int g=0; gplayerint.size(); ++g) - { - if(VLC->playerint[g]->playerID == owner) - { - serialOwner = g; - break; - } - } - if(serialOwner==255) //neutral unit - { - } - else if(VLC->playerint[serialOwner]->human) - { - BattleAction ba = ((CPlayerInterface*)VLC->playerint[serialOwner])->activeStack(stacks[i]->ID); - switch(ba.actionType) - { - case 2: //walk - { - battleMoveCreatureStack(ba.stackNumber, ba.destinationTile); - } - case 3: //defend - { - break; - } - case 4: //retreat/flee - { - for(int v=0; vplayerint.size(); ++v) //tell about the end of this battle to interfaces - VLC->playerint[v]->battleEnd(army1, army2, hero1, hero2, std::vector(), 0, false); - battleEnd = true; - break; - } - case 6: //walk or attack - { - battleMoveCreatureStack(ba.stackNumber, ba.destinationTile); - battleAttackCreatureStack(ba.stackNumber, ba.destinationTile); - break; - } - case 7: //shoot - { - battleShootCreatureStack(ba.stackNumber, ba.destinationTile); - break; - } - } - } - else - { - //VLC->playerint[serialOwner]->activeStack(stacks[i]->ID); - } - } - if(battleEnd) - break; - //sprawdzic czy po tej akcji ktoras strona nie wygrala bitwy - } - if(battleEnd) - break; - curB->round++; - SDL_Delay(50); - } - - for(int i=0;i #include #ifdef _WIN32 @@ -61,6 +63,11 @@ struct DLL_EXPORT BattleInfo { h & side1 & side2 & round & activeStack & siege & tile & stacks & army1 & army2 & hero1 & hero2; } + CStack * getStack(int stackID); + CStack * getStackT(int tileID); + void getAccessibilityMap(bool *accessibility); //send pointer to at least 187 allocated bytes + void getAccessibilityMapForTwoHex(bool *accessibility, bool atackerSide); //send pointer to at least 187 allocated bytes + std::vector getPath(int start, int dest, bool*accessibility); }; class DLL_EXPORT CStack @@ -122,7 +129,6 @@ private: CGHeroInstance *getHero(int objid); - void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2); bool battleMoveCreatureStack(int ID, int dest); bool battleAttackCreatureStack(int ID, int dest); bool battleShootCreatureStack(int ID, int dest); diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 91f4fdca5..f77d3302a 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -1993,6 +1993,7 @@ BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn //tidy up BattleAction ret = *(b->givenCommand->data); delete b->givenCommand->data; + b->givenCommand->data = NULL; //return command return ret; @@ -2010,6 +2011,7 @@ void CPlayerInterface::battleEnd(BattleResult *br) void CPlayerInterface::battleStackMoved(int ID, int dest, bool startMoving, bool endMoving) { + boost::unique_lock un(*pim); dynamic_cast(curint)->stackMoved(ID, dest, startMoving, endMoving); } diff --git a/client/Client.cpp b/client/Client.cpp index 9208c7b32..c4bfaec6c 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -353,7 +353,7 @@ void CClient::process(int what) *serv >> sas; std::cout << "Active stack: " << sas.stack <apply(&sas); - boost::thread(boost::bind(&CClient::waitForMoveAndSend,this,gs->curB->stacks[sas.stack]->owner)); + boost::thread(boost::bind(&CClient::waitForMoveAndSend,this,gs->curB->getStack(sas.stack)->owner)); break; } case 3003: @@ -368,8 +368,18 @@ void CClient::process(int what) playerint[gs->curB->side2]->battleEnd(&br); gs->apply(&br); - - + break; + } + case 3004: + { + BattleStackMoved br; + *serv >> br; + std::cout << "Stack "<curB->side1) != playerint.end()) + playerint[gs->curB->side1]->battleStackMoved(br.stack,br.tile,br.flags&1,br.flags&2); + if(playerint.find(gs->curB->side2) != playerint.end()) + playerint[gs->curB->side2]->battleStackMoved(br.stack,br.tile,br.flags&1,br.flags&2); + gs->apply(&br); break; } case 9999: diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 3f9823441..a53fa5ad9 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -301,6 +301,28 @@ struct BattleResult : public CPack//3003 } }; +struct BattleStackMoved : public CPack//3004 +{ + ui32 stack, tile; + ui8 flags; + + + + BattleStackMoved(){flags = 0; type = 3004;}; + bool startMoving() + { + return flags & 1; + } + bool endMoving() + { + return flags & 2; + } + template void serialize(Handler &h, const int version) + { + h & stack & tile & flags; + } +}; + struct ShowInInfobox : public CPack //107 { ShowInInfobox(){type = 107;}; diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index b2fd10281..69a45014b 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -57,7 +57,7 @@ public: //StartInfo scenarioOps; }; -#ifndef __GNUC__ +#ifdef __GNUC__ DLL_EXPORT LibClasses * VLC; #else extern DLL_EXPORT LibClasses * VLC; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 173bf54f6..15807ad34 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -315,7 +315,7 @@ void CGameHandler::startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile { if(!stacks[i]->alive) continue;//indicates imposiibility of making action for this dead unit BattleSetActiveStack sas; - sas.stack = i; + sas.stack = stacks[i]->ID; sendAndApply(&sas); //wait for response about battle action @@ -323,6 +323,7 @@ void CGameHandler::startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile boost::unique_lock lock(battleMadeAction.mx); while(!battleMadeAction.data) battleMadeAction.cond.wait(lock); + battleMadeAction.data = false; } } @@ -584,7 +585,80 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) { case 2: //walk { - //battleMoveCreatureStack(ba.stackNumber, ba.destinationTile); + CStack *curStack = gs->curB->getStack(ba.stackNumber), + *stackAtEnd = gs->curB->getStackT(ba.destinationTile); + + //initing necessary tables + bool accessibility[187]; + if(curStack->creature->isDoubleWide()) + { + gs->curB->getAccessibilityMapForTwoHex(accessibility,curStack->attackerOwned); + accessibility[curStack->attackerOwned ? curStack->position+1 : curStack->position-1]=true;//OUR second tile is for US accessible + } + else + gs->curB->getAccessibilityMap(accessibility); + accessibility[curStack->position] = true; //OUR tile is for US accessible + + //if(!stackAtEnd && !accessibility[dest]) + // return false; + + //if(dists[dest] > curStack->creature->speed && !(stackAtEnd && dists[dest] == curStack->creature->speed+1)) //we can attack a stack if we can go to adjacent hex + // return false; + + std::vector path = gs->curB->getPath(curStack->position,ba.destinationTile,accessibility); + + for(int v=path.size()-1; v>=0; --v) + { + if(v!=0 || !stackAtEnd) //it's not the last step or the last tile is free + { + //inform clients about move + BattleStackMoved sm; + sm.stack = curStack->ID; + sm.tile = path[v]; + if(v==path.size()-1)//move start - set flag + sm.flags |= 1; + if(v==0 || (stackAtEnd && v==1)) //move end - set flag + sm.flags |= 2; + sendAndApply(&sm); + } + else //if it's last step and we should attack unit at the end + { + //LOCPLINT->battleStackAttacking(ID, path[v]); + ////counting dealt damage + //int finalDmg = calculateDmg(curStack, curB->stacks[numberOfStackAtEnd]); + + ////applying damages + //int cresKilled = finalDmg / curB->stacks[numberOfStackAtEnd]->creature->hitPoints; + //int damageFirst = finalDmg % curB->stacks[numberOfStackAtEnd]->creature->hitPoints; + + //if( curB->stacks[numberOfStackAtEnd]->firstHPleft <= damageFirst ) + //{ + // curB->stacks[numberOfStackAtEnd]->amount -= 1; + // curB->stacks[numberOfStackAtEnd]->firstHPleft += curB->stacks[numberOfStackAtEnd]->creature->hitPoints - damageFirst; + //} + //else + //{ + // curB->stacks[numberOfStackAtEnd]->firstHPleft -= damageFirst; + //} + + //int cresInstackBefore = curB->stacks[numberOfStackAtEnd]->amount; + //curB->stacks[numberOfStackAtEnd]->amount -= cresKilled; + //if(curB->stacks[numberOfStackAtEnd]->amount<=0) //stack killed + //{ + // curB->stacks[numberOfStackAtEnd]->amount = 0; + // LOCPLINT->battleStackKilled(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore) , ID, false); + // curB->stacks[numberOfStackAtEnd]->alive = false; + //} + //else + //{ + // LOCPLINT->battleStackIsAttacked(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID, false); + //} + + //damage applied + } + } + //curB->stackActionPerformed = true; + //LOCPLINT->actionFinished(BattleAction()); break; } case 3: //defend diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 1b0bf5d53..47683243b 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -3,7 +3,9 @@ #include #include "../CGameState.h" #include "../lib/Connection.h" +#ifndef _MSC_VER #include +#endif class CVCMIServer; class CGameState; //class CConnection; From ba59b28be8cb7893375b2157254b006a3ab14811 Mon Sep 17 00:00:00 2001 From: Vadim Glazunov Date: Mon, 4 Aug 2008 23:19:19 +0000 Subject: [PATCH 45/47] Now MSVC and gcc must be happy :) --- lib/VCMI_Lib.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index 69a45014b..a8797ba86 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -57,11 +57,7 @@ public: //StartInfo scenarioOps; }; -#ifdef __GNUC__ -DLL_EXPORT LibClasses * VLC; -#else extern DLL_EXPORT LibClasses * VLC; -#endif DLL_EXPORT void initDLL(CLodHandler *b); From c7bb04235c395cb59407a857161c951454349342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Tue, 5 Aug 2008 22:11:32 +0000 Subject: [PATCH 46/47] * merged changes in pregame * portrait initialziaton * minor --- CGameInterface.h | 2 +- CGameState.cpp | 9 ++- CPreGame.cpp | 168 +++++++++++++++++++++++++++-------------- CPreGame.h | 111 +++++++++++++-------------- client/Client.cpp | 5 +- client/Graphics.cpp | 3 +- hch/CObjectHandler.cpp | 2 +- map.cpp | 2 + 8 files changed, 180 insertions(+), 122 deletions(-) diff --git a/CGameInterface.h b/CGameInterface.h index 5a0d8ac51..9f4752236 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -53,7 +53,7 @@ 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 &components)=0; + virtual void showInfoDialog(std::string text, std::vector &components){}; virtual void showSelDialog(std::string text, std::vector & 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 diff --git a/CGameState.cpp b/CGameState.cpp index 6c945371c..69705d9a8 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -47,6 +47,7 @@ CGObjectInstance * createObject(int id, int subid, int3 pos, int owner) nobj->defInfo->visitMap[5] = 2; nobj->artifacts.resize(20); nobj->artifWorn[16] = 3; + nobj->portrait = subid; nobj->primSkills.resize(4); nobj->primSkills[0] = nobj->type->heroClass->initialAttack; nobj->primSkills[1] = nobj->type->heroClass->initialDefence; @@ -581,7 +582,7 @@ void CGameState::randomizeObject(CGObjectInstance *cur) CGHeroInstance *h = dynamic_cast(cur); if(!h) {std::cout<<"Wrong random hero at "<pos<ID = ran.first; - cur->subID = ran.second; + h->portrait = cur->subID = ran.second; h->type = VLC->heroh->heroes[ran.second]; map->heroes.push_back(h); return; //TODO: maybe we should do something with definfo? @@ -606,7 +607,11 @@ void CGameState::randomizeObject(CGObjectInstance *cur) cur->ID = ran.first; cur->subID = ran.second; map->defs.insert(cur->defInfo = VLC->dobjinfo->gobjs[ran.first][ran.second]); - if(!cur->defInfo){std::cout<<"Missing def declaration for "<ID<<" "<subID<defInfo) + { + std::cout<<"Missing def declaration for "<ID<<" "<subID<ourImages[state].bitmap,pos.x,pos.y); @@ -51,8 +66,25 @@ void HighButton::press(bool down) SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,screen,&pos); updateRect(&pos); } +Button::Button( SDL_Rect Pos, boost::function Fun,CDefHandler* Imgs, bool Sel, CGroup* gr, int id) + :HighButton(Pos,Imgs,Sel,id),ourGroup(gr),fun(Fun) +{ + type=1; +}; +Button::Button() +{ + ourGroup=NULL;type=1; +}; -template void SetrButton::press(bool down) +SetrButton::SetrButton() +{ + type=1; + selectable=false; + selected=false; + state=0; + highlightable=false; +} +void SetrButton::press(bool down) { #ifndef __GNUC__ if (!down && state==1) @@ -77,11 +109,11 @@ void HighButton::hover(bool on) SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,screen,&pos); updateRect(&pos); } -template void Button::hover(bool on) +void Button::hover(bool on) { HighButton::hover(on); } -template void Button::select(bool on) +void Button::select(bool on) { int i; if (on) state=i=3; @@ -96,11 +128,7 @@ template void Button::select(bool on) } } -//void Slider::clickDown(int x, int y, bool bzgl=true); -//void Slider::clickUp(int x, int y, bool bzgl=true); -//void Slider::mMove(int x, int y, bool bzgl=true); - -template <> void Slider::updateSlid() +void Slider::updateSlid() { float perc = ((float)whereAreWe)/((float)positionsAmnt-capacity); float myh; @@ -121,20 +149,19 @@ template <> void Slider::updateSlid() updateRect(&pos); } -template<> void Slider::moveDown() +void Slider::moveDown() { if (whereAreWe*fun)(++whereAreWe); + fun(++whereAreWe); updateSlid(); } -template<> void Slider::moveUp() +void Slider::moveUp() { if (whereAreWe>0) - (CPG->*fun)(--whereAreWe); + fun(--whereAreWe); updateSlid(); } -//void Slider::moveByOne(bool up); -template<> Slider::Slider(int x, int y, int h, int amnt, int cap, bool ver) +Slider::Slider(int x, int y, int h, int amnt, int cap, bool ver) { vertical=ver; positionsAmnt = amnt; @@ -142,26 +169,26 @@ template<> Slider::Slider(int x, int y, int h, int amnt, int cap, bool if (ver) { pos = genRect(h,16,x,y); - down = Button(genRect(16,16,x,y+h-16),&Slider::moveDown,CDefHandler::giveDef("SCNRBDN.DEF"),false); - up = Button(genRect(16,16,x,y),&Slider::moveUp,CDefHandler::giveDef("SCNRBUP.DEF"),false); - slider = Button(genRect(16,16,x,y+16),NULL,CDefHandler::giveDef("SCNRBSL.DEF"),false); + down = Button(genRect(16,16,x,y+h-16),boost::bind(&Slider::moveDown,this),CDefHandler::giveDef("SCNRBDN.DEF"),false); + up = Button(genRect(16,16,x,y),boost::bind(&Slider::moveUp,this),CDefHandler::giveDef("SCNRBUP.DEF"),false); + slider = Button(genRect(16,16,x,y+16),boost::function(),CDefHandler::giveDef("SCNRBSL.DEF"),false); } else { pos = genRect(16,h,x,y); - down = Button(genRect(16,16,x+h-16,y),&Slider::moveDown,CDefHandler::giveDef("SCNRBRT.DEF"),false); - up = Button(genRect(16,16,x,y),&Slider::moveUp,CDefHandler::giveDef("SCNRBLF.DEF"),false); - slider = Button(genRect(16,16,x+16,y),NULL,CDefHandler::giveDef("SCNRBSL.DEF"),false); + down = Button(genRect(16,16,x+h-16,y),boost::bind(&Slider::moveDown,this),CDefHandler::giveDef("SCNRBRT.DEF"),false); + up = Button(genRect(16,16,x,y),boost::bind(&Slider::moveUp,this),CDefHandler::giveDef("SCNRBLF.DEF"),false); + slider = Button(genRect(16,16,x+16,y),boost::function(),CDefHandler::giveDef("SCNRBSL.DEF"),false); } moving = false; whereAreWe=0; } -template<>void Slider::deactivate() +void Slider::deactivate() { CPG->interested.erase(std::find(CPG->interested.begin(),CPG->interested.end(),this)); } -template<>void Slider::activate() +void Slider::activate() { SDL_FillRect(screen,&pos,0); up.show(); @@ -172,7 +199,7 @@ template<>void Slider::activate() CPG->interested.push_back(this); } -template<>void Slider::handleIt(SDL_Event sEvent) +void Slider::handleIt(SDL_Event sEvent) { if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT)) { @@ -210,7 +237,7 @@ template<>void Slider::handleIt(SDL_Event sEvent) whereAreWe = pe*(positionsAmnt-capacity); if (whereAreWe<0)whereAreWe=0; updateSlid(); - (CPG->*fun)(whereAreWe); + fun(whereAreWe); } } else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT)) @@ -218,11 +245,11 @@ template<>void Slider::handleIt(SDL_Event sEvent) if ((down.state==1) && isItIn(&down.pos,sEvent.motion.x,sEvent.motion.y)) { - (this->*down.fun)(); + this->down.fun(); } if ((up.state==1) && isItIn(&up.pos,sEvent.motion.x,sEvent.motion.y)) { - (this->*up.fun)(); + this->up.fun(); } if (down.state==1) down.press(false); if (up.state==1) up.press(false); @@ -273,7 +300,7 @@ template<>void Slider::handleIt(SDL_Event sEvent) whereAreWe=ktory; updateSlid(); } - (CPG->*fun)(whereAreWe); + fun(whereAreWe); } } @@ -312,6 +339,31 @@ template<>void Slider::handleIt(SDL_Event sEvent) }*/ } +IntBut::IntBut() +{ + type=2; + fun=NULL; + highlightable=false; +} +void IntBut::set() +{ + *what=key; +} +void CPoinGroup::setYour(IntSelBut * your) +{ + *gdzie=your->key; +}; +IntSelBut::IntSelBut( SDL_Rect Pos, boost::function Fun,CDefHandler* Imgs, bool Sel, CPoinGroup* gr, int My) + : Button(Pos,Fun,Imgs,Sel,gr),key(My) +{ + ourPoinGroup=gr; +}; +void IntSelBut::select(bool on) +{ + Button::select(on); + ourPoinGroup->setYour(this); + CPG->printRating(); +} /********************************************************************************************/ void PreGameTab::show() { @@ -630,8 +682,8 @@ void Options::init() rCastle = BitmapHandler::loadBitmap("HPSRAND0.bmp"); nHero = BitmapHandler::loadBitmap("HPSRAND6.bmp"); nCastle = BitmapHandler::loadBitmap("HPSRAND5.bmp"); - turnLength = new Slider<>(57,557,195,11,1,false); - turnLength->fun=&CPreGame::setTurnLength; + turnLength = new Slider(57,557,195,11,1,false); + turnLength->fun=boost::bind(&CPreGame::setTurnLength,CPG,_1); flags.push_back(CDefHandler::giveDef("AOFLGBR.DEF")); flags.push_back(CDefHandler::giveDef("AOFLGBB.DEF")); @@ -1047,7 +1099,7 @@ void MapSel::init() loscon.key=_loscon; nrplayer.poin=mapsize.poin=type.poin=name.poin=viccon.poin=loscon.poin=(int*)(&sortBy); - nrplayer.fun=mapsize.fun=type.fun=name.fun=viccon.fun=loscon.fun=&CPreGame::sortMaps; + nrplayer.fun=mapsize.fun=type.fun=name.fun=viccon.fun=loscon.fun=boost::bind(&CPreGame::sortMaps,CPG); Dtypes = CDefHandler::giveDef("SCSELC.DEF"); Dvic = CDefHandler::giveDef("SCNRVICT.DEF"); @@ -1057,8 +1109,8 @@ void MapSel::init() sFlags = CDefHandler::giveDef("ITGFLAGS.DEF"); group.join_all(); std::sort(ourMaps.begin(),ourMaps.end(),mapSorter(_name)); - slid = new Slider<>(375,92,480,ourMaps.size(),18,true); - slid->fun = &CPreGame::printMapsFrom; + slid = new Slider(375,92,480,ourMaps.size(),18,true); + slid->fun = boost::bind(&CPreGame::printMapsFrom,CPG,_1); } void MapSel::moveByOne(bool up) { @@ -1083,9 +1135,9 @@ void MapSel::moveByOne(bool up) select(help); slid->updateSlid(); } -void MapSel::select(int which, bool updateMapsList) +void MapSel::select(int which, bool updateMapsList, bool forceSettingsUpdate) { - bool dontSaveSettings = ((selected!=which) || (CPG->ret.playerInfos.size()==0)); + bool dontSaveSettings = ((selected!=which) || (CPG->ret.playerInfos.size()==0) || forceSettingsUpdate); selected = which; CPG->ret.mapname = ourMaps[selected].filename; if(updateMapsList) @@ -1381,26 +1433,26 @@ void CPreGame::initScenSel() SDL_SetColorKey(ourScenSel->randMap,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->randMap->format,0,255,255)); SDL_SetColorKey(ourScenSel->options,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->options->format,0,255,255)); - ourScenSel->difficulty = new CPoinGroup<>(); + ourScenSel->difficulty = new CPoinGroup(); ourScenSel->difficulty->type=1; ourScenSel->selectedDiff=-77; ourScenSel->difficulty->gdzie = &ourScenSel->selectedDiff; - ourScenSel->bEasy = IntSelBut<>(genRect(0,0,506,456),NULL,CDefHandler::giveDef("GSPBUT3.DEF"),true,ourScenSel->difficulty,0); - ourScenSel->bNormal = IntSelBut<>(genRect(0,0,538,456),NULL,CDefHandler::giveDef("GSPBUT4.DEF"),true,ourScenSel->difficulty,1); - ourScenSel->bHard = IntSelBut<>(genRect(0,0,570,456),NULL,CDefHandler::giveDef("GSPBUT5.DEF"),true,ourScenSel->difficulty,2); - ourScenSel->bExpert = IntSelBut<>(genRect(0,0,602,456),NULL,CDefHandler::giveDef("GSPBUT6.DEF"),true,ourScenSel->difficulty,3); - ourScenSel->bImpossible = IntSelBut<>(genRect(0,0,634,456),NULL,CDefHandler::giveDef("GSPBUT7.DEF"),true,ourScenSel->difficulty,4); + ourScenSel->bEasy = IntSelBut(genRect(0,0,506,456),NULL,CDefHandler::giveDef("GSPBUT3.DEF"),true,ourScenSel->difficulty,0); + ourScenSel->bNormal = IntSelBut(genRect(0,0,538,456),NULL,CDefHandler::giveDef("GSPBUT4.DEF"),true,ourScenSel->difficulty,1); + ourScenSel->bHard = IntSelBut(genRect(0,0,570,456),NULL,CDefHandler::giveDef("GSPBUT5.DEF"),true,ourScenSel->difficulty,2); + ourScenSel->bExpert = IntSelBut(genRect(0,0,602,456),NULL,CDefHandler::giveDef("GSPBUT6.DEF"),true,ourScenSel->difficulty,3); + ourScenSel->bImpossible = IntSelBut(genRect(0,0,634,456),NULL,CDefHandler::giveDef("GSPBUT7.DEF"),true,ourScenSel->difficulty,4); - ourScenSel->bBack = Button<>(genRect(0,0,584,535),&CPreGame::showNewMenu,CDefHandler::giveDef("SCNRBACK.DEF")); - ourScenSel->bBegin = Button<>(genRect(0,0,414,535),&CPreGame::begin,CDefHandler::giveDef("SCNRBEG.DEF")); + ourScenSel->bBack = Button(genRect(0,0,584,535),boost::bind(&CPreGame::showNewMenu,this),CDefHandler::giveDef("SCNRBACK.DEF")); + ourScenSel->bBegin = Button(genRect(0,0,414,535),boost::bind(&CPreGame::begin,this),CDefHandler::giveDef("SCNRBEG.DEF")); + ourScenSel->bScens = Button(genRect(0,0,414,81),boost::bind(&CPreGame::showScenList,this),CDefHandler::giveDef("GSPBUTT.DEF")); - ourScenSel->bScens = Button<>(genRect(0,0,414,81),&CPreGame::showScenList,CDefHandler::giveDef("GSPBUTT.DEF")); for (int i=0; ibScens.imgs->ourImages.size(); i++) CSDL_Ext::printAt(CGI->generaltexth->allTexts[500],25+i,2+i,GEOR13,zwykly,ourScenSel->bScens.imgs->ourImages[i].bitmap); //"Show Available Scenarios" - ourScenSel->bRandom = Button<>(genRect(0,0,414,105),&CPreGame::showScenList,CDefHandler::giveDef("GSPBUTT.DEF")); + ourScenSel->bRandom = Button(genRect(0,0,414,105),boost::bind(&CPreGame::showScenList,this),CDefHandler::giveDef("GSPBUTT.DEF")); for (int i=0; ibRandom.imgs->ourImages.size(); i++) CSDL_Ext::printAt(CGI->generaltexth->allTexts[740],25+i,2+i,GEOR13,zwykly,ourScenSel->bRandom.imgs->ourImages[i].bitmap); - ourScenSel->bOptions = Button<>(genRect(0,0,414,509),&CPreGame::showOptions,CDefHandler::giveDef("GSPBUTT.DEF")); + ourScenSel->bOptions = Button(genRect(0,0,414,509),boost::bind(&CPreGame::showOptions,this),CDefHandler::giveDef("GSPBUTT.DEF")); for (int i=0; ibOptions.imgs->ourImages.size(); i++) CSDL_Ext::printAt(CGI->generaltexth->allTexts[501],25+i,2+i,GEOR13,zwykly,ourScenSel->bOptions.imgs->ourImages[i].bitmap); //"Show Advanced Options" @@ -1675,8 +1727,8 @@ void CPreGame::showAskBox (std::string data, void(*f1)(),void(*f2)()) (*btnspos)[0].y+=pos.y; (*btnspos)[1].x+=pos.x; (*btnspos)[1].y+=pos.y; - btns.push_back(new Button<>((*btnspos)[0],&CPreGame::quit,ok,false, NULL,2)); - btns.push_back(new Button<>((*btnspos)[1],(&CPreGame::hideBox),cancel,false, NULL,2)); + btns.push_back(new Button((*btnspos)[0],boost::bind(&CPreGame::quit,this),ok,false, NULL,2)); + btns.push_back(new Button((*btnspos)[1],boost::bind(&CPreGame::hideBox,this),cancel,false, NULL,2)); delete cmh; delete przyciski; delete btnspos; @@ -1728,7 +1780,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent) if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y)) { btns[i]->press(true); - ourScenSel->pressed=(Button<>*)btns[i]; + ourScenSel->pressed=(Button*)btns[i]; } } if ((currentTab==&ourScenSel->mapsel) && (sEvent.button.y>121) &&(sEvent.button.y<570) @@ -1741,7 +1793,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent) } else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT)) { - Button<> * prnr=ourScenSel->pressed; + Button * prnr=ourScenSel->pressed; if (ourScenSel->pressed && ourScenSel->pressed->state==1) { ourScenSel->pressed->press(false); @@ -1753,17 +1805,19 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent) { if (btns[i]->selectable) btns[i]->select(true); - if (btns[i]->type==1 && ((Button<>*)btns[i])->fun) - (this->*(((Button<>*)btns[i])->fun))(); + if (btns[i]->type==1 && ((Button*)btns[i])->fun) + ((Button*)btns[i])->fun(); int zz = btns.size(); if (i>=zz) break; if (btns[i]==prnr && btns[i]->type==2) { - ((IntBut<> *)(btns[i]))->set(); + ((IntBut*)(btns[i]))->set(); ourScenSel->mapsel.slid->whereAreWe=0; ourScenSel->mapsel.slid->updateSlid(); ourScenSel->mapsel.slid->positionsAmnt=ourScenSel->mapsel.countWL(); + ourScenSel->mapsel.select(ourScenSel->mapsel.whichWL(0)); + ourScenSel->mapsel.printMaps(0); } } @@ -1988,7 +2042,7 @@ StartInfo CPreGame::runLoop() for (int i=0;ipos,sEvent.motion.x,sEvent.motion.y)) - (this->*(((Button<>*)btns[i])->fun))(); + ((Button*)btns[i])->fun(); else { btns[i]->press(false); @@ -2106,8 +2160,12 @@ void CPreGame::quitAskBox() } void CPreGame::sortMaps() { - std::sort(ourScenSel->mapsel.ourMaps.begin(),ourScenSel->mapsel.ourMaps.end(),mapSorter(ourScenSel->mapsel.sortBy)); - ourScenSel->mapsel.select(0); + std::sort(ourScenSel->mapsel.ourMaps.begin(),ourScenSel->mapsel.ourMaps.end(),mapSorter(_name)); + if(ourScenSel->mapsel.sortBy != _name) + std::stable_sort(ourScenSel->mapsel.ourMaps.begin(),ourScenSel->mapsel.ourMaps.end(),mapSorter(ourScenSel->mapsel.sortBy)); + ourScenSel->mapsel.select(ourScenSel->mapsel.whichWL(0),false,true); + ourScenSel->mapsel.slid->whereAreWe=0; + ourScenSel->mapsel.slid->updateSlid(); printMapsFrom(0); } void CPreGame::setTurnLength(int on) diff --git a/CPreGame.h b/CPreGame.h index d83662856..cabd9fc20 100644 --- a/CPreGame.h +++ b/CPreGame.h @@ -8,14 +8,16 @@ #include "CMessage.h" #include "map.h" #include "hch/CMusicHandler.h" +#include +#include class CPreGame; class CDefHandler; extern CPreGame * CPG; typedef void(CPreGame::*ttt)(); -template class CGroup; -template class CPoinGroup ; - +class CGroup; +class CPoinGroup ; +class IntSelBut; struct HighButton { @@ -24,9 +26,8 @@ struct HighButton SDL_Rect pos; CDefHandler* imgs; int state; - HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1) - {type=0;imgs=Imgs;selectable=Sel;selected=false;state=0;pos=Pos;ID=id;highlightable=false;}; - HighButton(){state=0;} + HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1); + HighButton(); bool selectable, selected; bool highlightable, highlighted; virtual void show(); @@ -34,33 +35,33 @@ struct HighButton virtual void hover(bool on=true)=0; virtual void select(bool on=true)=0; }; -template struct Button: public HighButton +struct Button: public HighButton { - CGroup * ourGroup; - Button( SDL_Rect Pos, T Fun,CDefHandler* Imgs, bool Sel=false, CGroup* gr=NULL, int id=-1) - :HighButton(Pos,Imgs,Sel,id),ourGroup(gr),fun(Fun){type=1;}; - Button(){ourGroup=NULL;type=1;}; - T fun; + CGroup *ourGroup; + Button( SDL_Rect Pos, boost::function Fun,CDefHandler* Imgs, bool Sel=false, CGroup* gr=NULL, int id=-1); + Button(); + boost::function fun; virtual void hover(bool on=true); virtual void select(bool on=true); }; -template struct SetrButton: public Button +struct SetrButton: public Button { int key, * poin; virtual void press(bool down=true); - SetrButton(){int type=1;bool selectable=false;bool selected=false;int state=0;bool highlightable=false;} + SetrButton(); }; -template class Slider -{ // + +class Slider +{ public: bool vertical; // false means horizontal SDL_Rect pos; // position - Button up, down, //or left/right + Button up, down, //or left/right slider; int positionsAmnt, capacity;// capacity - amount of positions dispplayed at once int whereAreWe; // first displayed thing bool moving; - void(T::*fun)(int); + boost::function fun; void clickDown(int x, int y, bool bzgl=true); void clickUp(int x, int y, bool bzgl=true); void mMove(int x, int y, bool bzgl=true); @@ -71,47 +72,39 @@ public: Slider(int x, int y, int h, int amnt, int cap, bool ver); void updateSlid(); void handleIt(SDL_Event sev); - }; -//template -template struct IntBut: public Button + +struct IntBut: public Button { public: int key; int * what; - IntBut(){int type=2;int fun=NULL;bool highlightable=false;}; - void set(){*what=key;}; + IntBut(); + void set(); }; -template struct IntSelBut: public Button +class CGroup { public: - CPoinGroup * ourPoinGroup; - int key; - IntSelBut(){}; - IntSelBut( SDL_Rect Pos, T Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup* gr=NULL, int My=-1) - : Button(Pos,Fun,Imgs,Sel,gr),key(My){ourPoinGroup=gr;}; - void select(bool on=true) {(*this).Button::select(on);ourPoinGroup->setYour(this); - #if !defined(__amigaos4__) && !defined(__unix__) - CPG->printRating(); - #else - #warning not compile here - #endif - } -}; -template class CPoinGroup :public CGroup -{ -public: - int * gdzie; //where (po polsku, bo by było słowo kluczowe :/) - void setYour(IntSelBut * your){*gdzie=your->key;}; -}; -template class CGroup -{ -public: - Button * selected; + Button * selected; int type; // 1=sinsel CGroup():selected(NULL),type(0){}; }; +class CPoinGroup :public CGroup +{ +public: + int * gdzie; //where (po polsku, bo by było słowo kluczowe :/) + void setYour(IntSelBut * your); +}; +struct IntSelBut: public Button +{ +public: + CPoinGroup * ourPoinGroup; + int key; + IntSelBut(){}; + IntSelBut( SDL_Rect Pos, boost::function Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup* gr=NULL, int My=-1); + void select(bool on=true); +}; class PreGameTab { public: @@ -123,9 +116,9 @@ public: }; class RanSel : public PreGameTab { - Button<> horcpl[9], horcte[9], conpl[9], conte[8], water[4], monster[4], //last is random + Button horcpl[9], horcte[9], conpl[9], conte[8], water[4], monster[4], //last is random size[4], twoLevel, showRand; - CGroup<> *Ghorcpl, *Ghorcte, *Gconpl, *Gconte, *Gwater, *Gmonster, *Gsize; + CGroup *Ghorcpl, *Ghorcte, *Gconpl, *Gconte, *Gwater, *Gmonster, *Gsize; }; class Options : public PreGameTab { @@ -164,7 +157,7 @@ class Options : public PreGameTab }; public: std::set usedHeroes; - Slider<> * turnLength; + Slider * turnLength; SDL_Surface * bg, * rHero, * rCastle, * nHero, * nCastle; std::vector bgs; @@ -195,9 +188,9 @@ public: std::vector scenImgs; //int current; std::vector ourMaps; - IntBut<> small, medium, large, xlarge, all; - SetrButton<> nrplayer, mapsize, type, name, viccon, loscon; - Slider<> *slid, *descslid; + IntBut small, medium, large, xlarge, all; + SetrButton nrplayer, mapsize, type, name, viccon, loscon; + Slider *slid, *descslid; int sizeFilter; int whichWL(int nr); int countWL(); @@ -206,7 +199,7 @@ public: void init(); std::string gdiff(std::string ss); void printMaps(int from,int to=18, int at=0, bool abs=false); - void select(int which, bool updateMapsList=true); + void select(int which, bool updateMapsList=true, bool forceSettingsUpdate=false); void moveByOne(bool up); void printSelectedInfo(); void printFlags(); @@ -221,10 +214,10 @@ public: //RanSel ransel; MapSel mapsel; SDL_Surface * background, *scenInf, *scenList, *randMap, *options ; - Button<> bScens, bOptions, bRandom, bBegin, bBack; - IntSelBut<> bEasy, bNormal, bHard, bExpert, bImpossible; - Button<> * pressed; - CPoinGroup<> * difficulty; + Button bScens, bOptions, bRandom, bBegin, bBack; + IntSelBut bEasy, bNormal, bHard, bExpert, bImpossible; + Button * pressed; + CPoinGroup * difficulty; std::vector maps; int selectedDiff; void initRanSel(); @@ -243,7 +236,7 @@ public: StartInfo ret; bool run; bool first; //hasn't we showed the scensel - std::vector *> interested; + std::vector interested; CMusicHandler * mush; std::vector btns; CPreGameTextHandler * preth ; diff --git a/client/Client.cpp b/client/Client.cpp index c4bfaec6c..6b77a7ea9 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -146,7 +146,9 @@ CClient::CClient(CConnection *con, StartInfo *si) ui8 color = gs->scenarioOps->playerInfos[i].color; CCallback *cb = new CCallback(gs,color,this); if(!gs->scenarioOps->playerInfos[i].human) + { playerint[color] = static_cast(CAIHandler::getNewAI(cb,"EmptyAI.dll")); + } else { gs->currentPlayer = color; @@ -252,8 +254,7 @@ void CClient::process(int what) { for(std::set::iterator i=th->fowRevealed.begin(); i != th->fowRevealed.end(); i++) playerint[player]->tileRevealed(*i); - //boost::function tr = boost::bind(&CGameInterface::tileRevealed,playerint[player]); - //std::for_each(th->fowRevealed.begin(),th->fowRevealed.end(),tr); + //std::for_each(th->fowRevealed.begin(),th->fowRevealed.end(),boost::bind(&CGameInterface::tileRevealed,playerint[player],_1)); } //notify interfacesabout move diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 99b17e3ad..54fe23859 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -36,8 +36,8 @@ SDL_Surface * Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh) { char * buf = new char[10]; - SDL_Surface * ret = SDL_DisplayFormat(hInfo); blueToPlayersAdv(hInfo,curh->tempOwner); + SDL_Surface * ret = SDL_DisplayFormat(hInfo); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); printAt(curh->name,75,15,GEOR13,zwykly,ret); drawPrimarySkill(curh, ret); @@ -53,7 +53,6 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh) delete[] buf; blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret); blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret); - //SDL_SaveBMP(ret,"inf1.bmp"); return ret; } SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh) diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index fb92cb7d3..6b943ce1a 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -349,7 +349,7 @@ CGObjectInstance::~CGObjectInstance() } CGHeroInstance::CGHeroInstance() { - level = exp = -1; + portrait = level = exp = -1; isStanding = true; moveDir = 4; mana = 0; diff --git a/map.cpp b/map.cpp index fa25e279e..531d1d77e 100644 --- a/map.cpp +++ b/map.cpp @@ -1118,6 +1118,8 @@ void Mapa::initFromBytes(unsigned char * bufor) bool portrait=bufor[i]; ++i; if (portrait) i++; //TODO read portrait nr, save, open + else + nhi->portrait = nhi->subID; if(readChar(bufor,i))//true if hero has specified abilities { From d8eb861117e706a5538647f0a76cb1f34f7765d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Tue, 5 Aug 2008 23:33:08 +0000 Subject: [PATCH 47/47] Battles: * showing ranges * improvements in moving * workaround for neutrals --- CCallback.cpp | 3 +- CGameState.cpp | 400 +++++----------------------------------- CGameState.h | 2 + client/Client.cpp | 13 +- lib/BattleAction.h | 2 +- server/CGameHandler.cpp | 4 +- 6 files changed, 61 insertions(+), 363 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index eb60d1705..e5c47b7b4 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -571,7 +571,8 @@ CCreature CCallback::battleGetCreature(int number) std::vector CCallback::battleGetAvailableHexes(int ID) { boost::shared_lock lock(*gs->mx); - return gs->battleGetRange(ID); + return gs->curB->getAccessibility(ID); + //return gs->battleGetRange(ID); } bool CCallback::battleIsStackMine(int ID) diff --git a/CGameState.cpp b/CGameState.cpp index 69705d9a8..0dbca2669 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -129,6 +129,7 @@ void BattleInfo::getAccessibilityMap(bool *accessibility) accessibility[stacks[g]->position+1] = false; } } + //TODO: obstacles } void BattleInfo::getAccessibilityMapForTwoHex(bool *accessibility, bool atackerSide) //send pointer to at least 187 allocated bytes { @@ -143,23 +144,22 @@ void BattleInfo::getAccessibilityMapForTwoHex(bool *accessibility, bool atackerS accessibility[b] = false; } } + //removing accessibility for side hexes for(int v=0; v<187; ++v) if(atackerSide ? (v%17)==1 : (v%17)==15) accessibility[v] = false; } - -std::vector BattleInfo::getPath(int start, int dest, bool*accessibility) -{ - int predecessor[187]; //for getting the Path +void BattleInfo::makeBFS(int start, bool*accessibility, int *predecessor, int *dists) //both pointers must point to the at least 187-elements int arrays +{ + //inits for(int b=0; b<187; ++b) predecessor[b] = -1; - //bfsing - int dists[187]; //calculated distances + for(int g=0; g<187; ++g) + dists[g] = 100000000; + std::queue hexq; //bfs queue hexq.push(start); - for(int g=0; g<187; ++g) - dists[g] = 100000000; dists[hexq.front()] = 0; int curNext = -1; //for bfs loop only (helper var) while(!hexq.empty()) //bfs loop @@ -167,50 +167,77 @@ std::vector BattleInfo::getPath(int start, int dest, bool*accessibility) int curHex = hexq.front(); hexq.pop(); curNext = curHex - ( (curHex/17)%2 ? 18 : 17 ); - if((curNext > 0) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top left + if((curNext > 0) && (accessibility[curNext]) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top left { hexq.push(curNext); dists[curNext] = dists[curHex] + 1; predecessor[curNext] = curHex; } curNext = curHex - ( (curHex/17)%2 ? 17 : 16 ); - if((curNext > 0) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top right + if((curNext > 0) && (accessibility[curNext]) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top right { hexq.push(curNext); dists[curNext] = dists[curHex] + 1; predecessor[curNext] = curHex; } curNext = curHex - 1; - if((curNext > 0) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //left + if((curNext > 0) && (accessibility[curNext]) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //left { hexq.push(curNext); dists[curNext] = dists[curHex] + 1; predecessor[curNext] = curHex; } curNext = curHex + 1; - if((curNext < 187) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //right + if((curNext < 187) && (accessibility[curNext]) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //right { hexq.push(curNext); dists[curNext] = dists[curHex] + 1; predecessor[curNext] = curHex; } curNext = curHex + ( (curHex/17)%2 ? 16 : 17 ); - if((curNext < 187) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom left + if((curNext < 187) && (accessibility[curNext]) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom left { hexq.push(curNext); dists[curNext] = dists[curHex] + 1; predecessor[curNext] = curHex; } curNext = curHex + ( (curHex/17)%2 ? 17 : 18 ); - if((curNext < 187) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom right + if((curNext < 187) && (accessibility[curNext]) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom right { hexq.push(curNext); dists[curNext] = dists[curHex] + 1; predecessor[curNext] = curHex; } } +}; - //following the Path +std::vector BattleInfo::getAccessibility(int stackID) +{ + std::vector ret; + bool ac[187]; + CStack *s = getStack(stackID); + if(s->creature->isDoubleWide()) + getAccessibilityMapForTwoHex(ac,s->attackerOwned); + else + getAccessibilityMap(ac); + + int pr[187], dist[187]; + makeBFS(s->position,ac,pr,dist); + + for(int i=0;i<187;i++) + if(dist[i] <= s->creature->speed) + ret.push_back(i); + + return ret; +} +std::vector BattleInfo::getPath(int start, int dest, bool*accessibility) +{ + int predecessor[187]; //for getting the Path + int dist[187]; //calculated distances + + makeBFS(start,accessibility,predecessor,dist); + + //making the Path std::vector path; int curElem = dest; while(curElem != start) @@ -895,225 +922,6 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed) } } } -bool CGameState::battleMoveCreatureStack(int ID, int dest) -{/* - //first checks - if(curB->stackActionPerformed) //because unit cannot be moved more than once - return false; - - unsigned char owner = -1; //owner moved of unit - for(int g=0; gstacks.size(); ++g) - { - if(curB->stacks[g]->ID == ID) - { - owner = curB->stacks[g]->owner; - break; - } - } - - bool stackAtEnd = false; //true if there is a stack at the end of the path (we should attack it) - int numberOfStackAtEnd = -1; - for(int g=0; gstacks.size(); ++g) - { - if(curB->stacks[g]->position == dest - || (curB->stacks[g]->creature->isDoubleWide() && curB->stacks[g]->attackerOwned && curB->stacks[g]->position-1 == dest) - || (curB->stacks[g]->creature->isDoubleWide() && !curB->stacks[g]->attackerOwned && curB->stacks[g]->position+1 == dest)) - { - if(curB->stacks[g]->alive) - { - stackAtEnd = true; - numberOfStackAtEnd = g; - break; - } - } - } - - //selecting moved stack - CStack * curStack = NULL; - for(int y=0; ystacks.size(); ++y) - { - if(curB->stacks[y]->ID == ID) - { - curStack = curB->stacks[y]; - break; - } - } - if(!curStack) - return false; - //initing necessary tables - bool accessibility[187]; //accesibility of hexes - for(int k=0; k<187; k++) - accessibility[k] = true; - for(int g=0; gstacks.size(); ++g) - { - if(curB->stacks[g]->ID != ID && curB->stacks[g]->alive) //we don't want to lock enemy's positions and this units' position - { - accessibility[curB->stacks[g]->position] = false; - if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature - { - if(curB->stacks[g]->attackerOwned) - accessibility[curB->stacks[g]->position-1] = false; - else - accessibility[curB->stacks[g]->position+1] = false; - } - } - } - accessibility[dest] = true; - if(curStack->creature->isDoubleWide()) //locking positions unreachable by two-hex creatures - { - bool mac[187]; - for(int b=0; b<187; ++b) - { - // - // && ( ? (curStack->attackerOwned ? accessibility[curNext-1] : accessibility[curNext+1]) : true ) - mac[b] = accessibility[b]; - if( accessibility[b] && !(curStack->attackerOwned ? accessibility[b-1] : accessibility[b+1])) - { - mac[b] = false; - } - } - mac[curStack->attackerOwned ? curStack->position+1 : curStack->position-1]=true; - for(int v=0; v<187; ++v) - accessibility[v] = mac[v]; - //removing accessibility for side hexes - for(int v=0; v<187; ++v) - if(curStack->attackerOwned ? (v%17)==1 : (v%17)==15) - accessibility[v] = false; - } - if(!stackAtEnd && !accessibility[dest]) - return false; - int predecessor[187]; //for getting the Path - for(int b=0; b<187; ++b) - predecessor[b] = -1; - //bfsing - int dists[187]; //calculated distances - std::queue hexq; //bfs queue - hexq.push(curStack->position); - for(int g=0; g<187; ++g) - dists[g] = 100000000; - dists[hexq.front()] = 0; - int curNext = -1; //for bfs loop only (helper var) - while(!hexq.empty()) //bfs loop - { - int curHex = hexq.front(); - hexq.pop(); - curNext = curHex - ( (curHex/17)%2 ? 18 : 17 ); - if((curNext > 0) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top left - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - predecessor[curNext] = curHex; - } - curNext = curHex - ( (curHex/17)%2 ? 17 : 16 ); - if((curNext > 0) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top right - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - predecessor[curNext] = curHex; - } - curNext = curHex - 1; - if((curNext > 0) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //left - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - predecessor[curNext] = curHex; - } - curNext = curHex + 1; - if((curNext < 187) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //right - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - predecessor[curNext] = curHex; - } - curNext = curHex + ( (curHex/17)%2 ? 16 : 17 ); - if((curNext < 187) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom left - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - predecessor[curNext] = curHex; - } - curNext = curHex + ( (curHex/17)%2 ? 17 : 18 ); - if((curNext < 187) && (accessibility[curNext] || curNext==dest) && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom right - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - predecessor[curNext] = curHex; - } - } - //following the Path - if(dists[dest] > curStack->creature->speed && !(stackAtEnd && dists[dest] == curStack->creature->speed+1)) //we can attack a stack if we can go to adjacent hex - return false; - std::vector path; - int curElem = dest; - while(curElem!=curStack->position) - { - path.push_back(curElem); - curElem = predecessor[curElem]; - } - for(int v=path.size()-1; v>=0; --v) - { - if(v!=0 || !stackAtEnd) //it's not the last step - { - LOCPLINT->battleStackMoved(ID, path[v], v==path.size()-1, v==0 || (stackAtEnd && v==1) ); - curStack->position = path[v]; - } - else //if it's last step and we should attack unit at the end - { - LOCPLINT->battleStackAttacking(ID, path[v]); - //counting dealt damage - int finalDmg = calculateDmg(curStack, curB->stacks[numberOfStackAtEnd]); - - //applying damages - int cresKilled = finalDmg / curB->stacks[numberOfStackAtEnd]->creature->hitPoints; - int damageFirst = finalDmg % curB->stacks[numberOfStackAtEnd]->creature->hitPoints; - - if( curB->stacks[numberOfStackAtEnd]->firstHPleft <= damageFirst ) - { - curB->stacks[numberOfStackAtEnd]->amount -= 1; - curB->stacks[numberOfStackAtEnd]->firstHPleft += curB->stacks[numberOfStackAtEnd]->creature->hitPoints - damageFirst; - } - else - { - curB->stacks[numberOfStackAtEnd]->firstHPleft -= damageFirst; - } - - int cresInstackBefore = curB->stacks[numberOfStackAtEnd]->amount; - curB->stacks[numberOfStackAtEnd]->amount -= cresKilled; - if(curB->stacks[numberOfStackAtEnd]->amount<=0) //stack killed - { - curB->stacks[numberOfStackAtEnd]->amount = 0; - LOCPLINT->battleStackKilled(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore) , ID, false); - curB->stacks[numberOfStackAtEnd]->alive = false; - } - else - { - LOCPLINT->battleStackIsAttacked(curB->stacks[numberOfStackAtEnd]->ID, finalDmg, std::min(cresKilled, cresInstackBefore), ID, false); - } - - //damage applied - } - } - curB->stackActionPerformed = true; - LOCPLINT->actionFinished(BattleAction());*/ - return true; -} - -bool CGameState::battleAttackCreatureStack(int ID, int dest) -{ - int attackedCreaure = -1; //-1 - there is no attacked creature - for(int b=0; bstacks.size(); ++b) //TODO: make upgrades for two-hex cres. - { - if(curB->stacks[b]->position == dest) - { - attackedCreaure = curB->stacks[b]->ID; - break; - } - } - if(attackedCreaure == -1) - return false; - //LOCPLINT->cb-> - return true; -} bool CGameState::battleShootCreatureStack(int ID, int dest) {/* @@ -1236,130 +1044,6 @@ int CGameState::calculateDmg(const CStack* attacker, const CStack* defender) std::vector CGameState::battleGetRange(int ID) {/* - int initialPlace=-1; //position of unit - int radius=-1; //range of unit - unsigned char owner = -1; //owner of unit - //selecting stack - CStack * curStack = NULL; - for(int y=0; ystacks.size(); ++y) - { - if(curB->stacks[y]->ID == ID) - { - curStack = curB->stacks[y]; - break; - } - } - - for(int g=0; gstacks.size(); ++g) - { - if(curB->stacks[g]->ID == ID) - { - initialPlace = curB->stacks[g]->position; - radius = curB->stacks[g]->creature->speed; - owner = curB->stacks[g]->owner; - break; - } - } - - bool accessibility[187]; //accesibility of hexes - for(int k=0; k<187; k++) - accessibility[k] = true; - for(int g=0; gstacks.size(); ++g) - { - if(curB->stacks[g]->ID != ID && curB->stacks[g]->alive) //we don't want to lock current unit's position - { - accessibility[curB->stacks[g]->position] = false; - if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature - { - if(curB->stacks[g]->attackerOwned) - accessibility[curB->stacks[g]->position-1] = false; - else - accessibility[curB->stacks[g]->position+1] = false; - } - } - } - - if(curStack->creature->isDoubleWide()) //locking positions unreachable by two-hex creatures - { - bool mac[187]; - for(int b=0; b<187; ++b) - { - // - // && ( ? (curStack->attackerOwned ? accessibility[curNext-1] : accessibility[curNext+1]) : true ) - mac[b] = accessibility[b]; - if( accessibility[b] && !(curStack->attackerOwned ? accessibility[b-1] : accessibility[b+1])) - { - mac[b] = false; - } - } - mac[curStack->attackerOwned ? curStack->position+1 : curStack->position-1]=true; - for(int v=0; v<187; ++v) - accessibility[v] = mac[v]; - //removing accessibility for side hexes - for(int v=0; v<187; ++v) - if(curStack->attackerOwned ? (v%17)==1 : (v%17)==15) - accessibility[v] = false; - } - - int dists[187]; //calculated distances - std::queue hexq; //bfs queue - hexq.push(initialPlace); - for(int g=0; g<187; ++g) - dists[g] = 100000000; - dists[initialPlace] = 0; - int curNext = -1; //for bfs loop only (helper var) - while(!hexq.empty()) //bfs loop - { - int curHex = hexq.front(); - hexq.pop(); - curNext = curHex - ( (curHex/17)%2 ? 18 : 17 ); - if((curNext > 0) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top left - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - } - curNext = curHex - ( (curHex/17)%2 ? 17 : 16 ); - if((curNext > 0) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top right - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - } - curNext = curHex - 1; - if((curNext > 0) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //left - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - } - curNext = curHex + 1; - if((curNext < 187) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //right - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - } - curNext = curHex + ( (curHex/17)%2 ? 16 : 17 ); - if((curNext < 187) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom left - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - } - curNext = curHex + ( (curHex/17)%2 ? 17 : 18 ); - if((curNext < 187) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom right - { - hexq.push(curNext); - dists[curNext] = dists[curHex] + 1; - } - } - - std::vector ret; - - for(int i=0; i<187; ++i) - { - if(dists[i]<=radius) - { - ret.push_back(i); - } - } - std::vector additionals; //adding enemies' positions diff --git a/CGameState.h b/CGameState.h index 601d3d59f..8c22cc605 100644 --- a/CGameState.h +++ b/CGameState.h @@ -67,7 +67,9 @@ struct DLL_EXPORT BattleInfo CStack * getStackT(int tileID); void getAccessibilityMap(bool *accessibility); //send pointer to at least 187 allocated bytes void getAccessibilityMapForTwoHex(bool *accessibility, bool atackerSide); //send pointer to at least 187 allocated bytes + void makeBFS(int start, bool*accessibility, int *predecessor, int *dists); //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result std::vector getPath(int start, int dest, bool*accessibility); + std::vector getAccessibility(int stackID); //returns vector of accessible tiles (taking into account the creature range) }; class DLL_EXPORT CStack diff --git a/client/Client.cpp b/client/Client.cpp index 6b77a7ea9..9b00bb45e 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -354,7 +354,18 @@ void CClient::process(int what) *serv >> sas; std::cout << "Active stack: " << sas.stack <apply(&sas); - boost::thread(boost::bind(&CClient::waitForMoveAndSend,this,gs->curB->getStack(sas.stack)->owner)); + int owner = gs->curB->getStack(sas.stack)->owner; + if(owner >= PLAYER_LIMIT) //ugly workaround to skip neutral creatures - should be replaced with AI + { + BattleAction ba; + ba.stackNumber = sas.stack; + ba.actionType = 3; + *serv << ui16(3002) << ba; + } + else + { + boost::thread(boost::bind(&CClient::waitForMoveAndSend,this,owner)); + } break; } case 3003: diff --git a/lib/BattleAction.h b/lib/BattleAction.h index 60a23ea29..08f509f04 100644 --- a/lib/BattleAction.h +++ b/lib/BattleAction.h @@ -5,7 +5,7 @@ struct BattleAction ui32 stackNumber;//stack ID, -1 left hero, -2 right hero, ui8 actionType; // 0 = Cancel BattleAction 1 = Hero cast a spell 2 = Walk 3 = Defend 4 = Retreat from the battle 5 = Surrender 6 = Walk and Attack 7 = Shoot 8 = Wait 9 = Catapult 10 = Monster casts a spell (i.e. Faerie Dragons) ui16 destinationTile; - ui16 additionalInfo; // e.g. spell number if type is 1 || 10 + si32 additionalInfo; // e.g. spell number if type is 1 || 10 template void serialize(Handler &h, const int version) { h & side & stackNumber & actionType & destinationTile & additionalInfo; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 15807ad34..0e3c4c6e2 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -606,8 +606,8 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) // return false; std::vector path = gs->curB->getPath(curStack->position,ba.destinationTile,accessibility); - - for(int v=path.size()-1; v>=0; --v) + int tilesToMove = std::max((int)path.size()-curStack->creature->speed, 0); + for(int v=path.size()-1; v>=tilesToMove; --v) { if(v!=0 || !stackAtEnd) //it's not the last step or the last tile is free {