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

* refactorings and comment coverage improvements

This commit is contained in:
mateuszb 2009-05-07 17:20:41 +00:00
parent 4f30bde636
commit b5ae7d5cbe
34 changed files with 241 additions and 216 deletions

View File

@ -216,15 +216,15 @@ bool CCallback::verifyPath(CPath * path, bool blockSea) const
continue; continue;
if ( if (
((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].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype==TerrainTile::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!=TerrainTile::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].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype!=TerrainTile::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==TerrainTile::water))
|| ||
(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==rock) (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==TerrainTile::rock)
) )
return false; return false;
@ -597,14 +597,14 @@ void CCallback::getMarketOffer( int t1, int t2, int &give, int &rec, int mode/*=
if(mode) return; //TODO - support if(mode) return; //TODO - support
boost::shared_lock<boost::shared_mutex> lock(*gs->mx); boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
//if(gs->resVals[t1] >= gs->resVals[t2]) //if(gs->resVals[t1] >= gs->resVals[t2])
float r = gs->resVals[t1], float r = gs->resVals[t1], //price of given resource
g = gs->resVals[t2] / gs->getMarketEfficiency(player,mode); g = gs->resVals[t2] / gs->getMarketEfficiency(player,mode); //price of wanted resource
if(r>g) if(r>g) //if given resource is more expensive than wanted
{ {
rec = ceil(r / g); rec = ceil(r / g);
give = 1; give = 1;
} }
else else //if wanted resource is more expensive
{ {
give = ceil(g / r); give = ceil(g / r);
rec = 1; rec = 1;

View File

@ -81,7 +81,7 @@ public:
virtual const StartInfo * getStartInfo()const =0; virtual const StartInfo * getStartInfo()const =0;
virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)const =0; virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)const =0;
virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)const =0; virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)const =0;
virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)const =0; virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)const =0; //t1 - type of given resource, t2 - type of received resource; give is the amount of resource t1 that can be traded for amount rec of resource t2 (one of them is 1)
virtual std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const =0; virtual std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const =0;
virtual int3 getMapSize() const =0; //returns size of map - z is 1 for one - level map and 2 for two level map virtual int3 getMapSize() const =0; //returns size of map - z is 1 for one - level map and 2 for two level map
virtual std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const =0; //heroes that can be recruited virtual std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const =0; //heroes that can be recruited
@ -175,7 +175,7 @@ public:
const StartInfo * getStartInfo() const; const StartInfo * getStartInfo() const;
std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos) const; std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos) const;
std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos) const; std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos) const;
void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0) const; void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0) const; //t1 - type of given resource, t2 - type of received resource; give is the amount of resource t1 that can be traded for amount rec of resource t2 (one of them is 1)
std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const; std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const; //heroes that can be recruited std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const; //heroes that can be recruited

View File

@ -1599,6 +1599,7 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, i
bg2 = BitmapHandler::loadBitmap("TPSMITBK.bmp"); bg2 = BitmapHandler::loadBitmap("TPSMITBK.bmp");
blitAt(bg2,64,50,bmp); blitAt(bg2,64,50,bmp);
SDL_FreeSurface(bg2); SDL_FreeSurface(bg2);
CCreatureAnimation cra(CGI->creh->creatures[creMachineID].animDefName); CCreatureAnimation cra(CGI->creh->creatures[creMachineID].animDefName);
cra.nextFrameMiddle(bmp,170,120,true,0,false); cra.nextFrameMiddle(bmp,170,120,true,0,false);
char pom[75]; char pom[75];
@ -1607,16 +1608,20 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, i
printAtMiddle(CGI->generaltexth->jktexts[43],165,218,GEOR16,zwykly,bmp); //resource cost printAtMiddle(CGI->generaltexth->jktexts[43],165,218,GEOR16,zwykly,bmp); //resource cost
SDL_itoa(CGI->arth->artifacts[aid].price,pom,10); SDL_itoa(CGI->arth->artifacts[aid].price,pom,10);
printAtMiddle(pom,165,290,GEOR13,zwykly,bmp); printAtMiddle(pom,165,290,GEOR13,zwykly,bmp);
pos.w = bmp->w; pos.w = bmp->w;
pos.h = bmp->h; pos.h = bmp->h;
pos.x = screen->w/2 - pos.w/2; pos.x = screen->w/2 - pos.w/2;
pos.y = screen->h/2 - pos.h/2; pos.y = screen->h/2 - pos.h/2;
buy = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 42,pos.y + 312,"IBUY30.DEF",SDLK_RETURN); buy = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 42,pos.y + 312,"IBUY30.DEF",SDLK_RETURN);
cancel = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 224,pos.y + 312,"ICANCEL.DEF",SDLK_ESCAPE); cancel = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 224,pos.y + 312,"ICANCEL.DEF",SDLK_ESCAPE);
if(possible) if(possible)
buy->callback += boost::bind(&CCallback::buyArtifact,LOCPLINT->cb,LOCPLINT->cb->getHeroInfo(hid,2),aid); buy->callback += boost::bind(&CCallback::buyArtifact,LOCPLINT->cb,LOCPLINT->cb->getHeroInfo(hid,2),aid);
else else
buy->bitmapOffset = 2; buy->bitmapOffset = 2;
blitAt(graphics->resources32->ourImages[6].bitmap,148,244,bmp); blitAt(graphics->resources32->ourImages[6].bitmap,148,244,bmp);
} }

View File

@ -34,8 +34,8 @@ public:
CDefHandler* def; CDefHandler* def;
SDL_Surface* border; SDL_Surface* border;
SDL_Surface* area; SDL_Surface* area;
CBuildingRect(Structure *Str); CBuildingRect(Structure *Str); //c-tor
~CBuildingRect(); ~CBuildingRect(); //d-tor
void activate(); void activate();
void deactivate(); void deactivate();
bool operator<(const CBuildingRect & p2) const; bool operator<(const CBuildingRect & p2) const;
@ -58,8 +58,8 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h,CCastleInterface * Owner); CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h,CCastleInterface * Owner); //c-tor
~CHeroGSlot(); ~CHeroGSlot(); //d-tor
}; };
class CCastleInterface : public CWindowWithGarrison class CCastleInterface : public CWindowWithGarrison
@ -89,8 +89,8 @@ public:
std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling
CCastleInterface(const CGTownInstance * Town); CCastleInterface(const CGTownInstance * Town); //c-tor
~CCastleInterface(); ~CCastleInterface(); //d-tor
void townChange(); void townChange();
void show(SDL_Surface * to); void show(SDL_Surface * to);
void showAll(SDL_Surface * to); void showAll(SDL_Surface * to);
@ -124,9 +124,9 @@ public:
void show(SDL_Surface * to); void show(SDL_Surface * to);
void activate(); void activate();
void deactivate(); void deactivate();
CBuildingBox(int id); CBuildingBox(int id); //c-tor
CBuildingBox(int id, int x, int y); CBuildingBox(int id, int x, int y); //c-tor
~CBuildingBox(); ~CBuildingBox(); //d-tor
}; };
class CBuildWindow: public IShowActivable, public ClickableR class CBuildWindow: public IShowActivable, public ClickableR
@ -144,19 +144,19 @@ public:
void show(SDL_Surface * to); void show(SDL_Surface * to);
void Buy(); void Buy();
void close(); void close();
CBuildWindow(int Tid, int Bid, int State, bool Mode); CBuildWindow(int Tid, int Bid, int State, bool Mode); //c-tor
~CBuildWindow(); ~CBuildWindow(); //d-tor
}; };
std::vector< std::vector<CBuildingBox*> >boxes; std::vector< std::vector<CBuildingBox*> >boxes;
AdventureMapButton *exit; AdventureMapButton *exit;
SDL_Surface * bg; SDL_Surface * bg; //background
CHallInterface(CCastleInterface * owner); CHallInterface(CCastleInterface * owner); //c-tor
~CHallInterface(); ~CHallInterface(); //d-tor
void close(); void close();
void show(SDL_Surface * to); void show(SDL_Surface * to);
void activate(); void activate();
@ -217,8 +217,8 @@ public:
CMinorResDataBar resdatabar; CMinorResDataBar resdatabar;
CMageGuildScreen(CCastleInterface * owner); CMageGuildScreen(CCastleInterface * owner); //c-tor
~CMageGuildScreen(); ~CMageGuildScreen(); //d-tor
void close(); void close();
void show(SDL_Surface * to); void show(SDL_Surface * to);
void activate(); void activate();
@ -229,10 +229,10 @@ class CBlacksmithDialog : public IShowActivable, public CIntObject
{ {
public: public:
AdventureMapButton *buy, *cancel; AdventureMapButton *buy, *cancel;
SDL_Surface *bmp; SDL_Surface *bmp; //background
CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid); CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid); //c-tor
~CBlacksmithDialog(); ~CBlacksmithDialog(); //d-tor
void close(); void close();
void show(SDL_Surface * to); void show(SDL_Surface * to);
void activate(); void activate();

View File

@ -29,12 +29,12 @@ namespace boost
class DLL_EXPORT CConsoleHandler class DLL_EXPORT CConsoleHandler
{ {
public: public:
boost::function<void(const std::string &)> *cb; boost::function<void(const std::string &)> *cb; //function to be called when message is received
int curLvl; int curLvl; //logging level
int run(); int run();
void setColor(int level); void setColor(int level); //sets color of text appropriate for given logging level
CConsoleHandler(); CConsoleHandler(); //c-tor
~CConsoleHandler(); ~CConsoleHandler(); //d-tor
#ifndef _WIN32 #ifndef _WIN32
static void killConsole(pthread_t hThread); //for windows only, use native handle to the thread static void killConsole(pthread_t hThread); //for windows only, use native handle to the thread
#else #else

View File

@ -963,7 +963,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed)
/*********give starting hero****************************************/ /*********give starting hero****************************************/
for(int i=0;i<PLAYER_LIMIT;i++) for(int i=0;i<PLAYER_LIMIT;i++)
{ {
if((map->players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE)) if((map->players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==CMapHeader::RoE))
{ {
int3 hpos = map->players[i].posOfMainTown; int3 hpos = map->players[i].posOfMainTown;
hpos.x+=1;// hpos.y+=1; hpos.x+=1;// hpos.y+=1;
@ -1343,25 +1343,25 @@ int CGameState::battleGetBattlefieldType(int3 tile)
switch(map->terrain[tile.x][tile.y][tile.z].tertype) switch(map->terrain[tile.x][tile.y][tile.z].tertype)
{ {
case dirt: case TerrainTile::dirt:
return rand()%3+3; return rand()%3+3;
case sand: case TerrainTile::sand:
return 2; //TODO: coast support return 2; //TODO: coast support
case grass: case TerrainTile::grass:
return rand()%2+6; return rand()%2+6;
case snow: case TerrainTile::snow:
return rand()%2+10; return rand()%2+10;
case swamp: case TerrainTile::swamp:
return 13; return 13;
case rough: case TerrainTile::rough:
return 23; return 23;
case subterranean: case TerrainTile::subterranean:
return 12; return 12;
case lava: case TerrainTile::lava:
return 8; return 8;
case water: case TerrainTile::water:
return 25; return 25;
case rock: case TerrainTile::rock:
return 15; return 15;
default: default:
return -1; return -1;
@ -1564,7 +1564,7 @@ int CGameState::canBuildStructure( const CGTownInstance *t, int ID )
} }
else if(ID == 6) //shipyard else if(ID == 6) //shipyard
{ {
if(map->getTile(t->pos + int3(-1,3,0)).tertype != water && map->getTile(t->pos + int3(-3,3,0)).tertype != water) if(map->getTile(t->pos + int3(-1,3,0)).tertype != TerrainTile::water && map->getTile(t->pos + int3(-3,3,0)).tertype != TerrainTile::water)
ret = 1; //lack of water ret = 1; //lack of water
} }
@ -1598,7 +1598,7 @@ CPath * CGameState::getPath(int3 src, int3 dest, const CGHeroInstance * hero)
tribool blockLandSea; //true - blocks sea, false - blocks land, indeterminate - allows all tribool blockLandSea; //true - blocks sea, false - blocks land, indeterminate - allows all
if (!hero->canWalkOnSea()) if (!hero->canWalkOnSea())
blockLandSea = (map->getTile(hpos).tertype != water); //block land if hero is on water and vice versa blockLandSea = (map->getTile(hpos).tertype != TerrainTile::water); //block land if hero is on water and vice versa
else else
blockLandSea = boost::logic::indeterminate; blockLandSea = boost::logic::indeterminate;
@ -1625,9 +1625,9 @@ CPath * CGameState::getPath(int3 src, int3 dest, const CGHeroInstance * hero)
node.coord.y = j; node.coord.y = j;
node.coord.z = dest.z; node.coord.z = dest.z;
if ((tinfo->tertype == rock) //it's rock if ((tinfo->tertype == TerrainTile::rock) //it's rock
|| ((blockLandSea) && (tinfo->tertype == water)) //it's sea and we cannot walk on sea || ((blockLandSea) && (tinfo->tertype == TerrainTile::water)) //it's sea and we cannot walk on sea
|| ((!blockLandSea) && (tinfo->tertype != water)) //it's land and we cannot walk on land || ((!blockLandSea) && (tinfo->tertype != TerrainTile::water)) //it's land and we cannot walk on land
|| !getPlayer(hero->tempOwner)->fogOfWarMap[i][j][src.z] //tile is covered by the FoW || !getPlayer(hero->tempOwner)->fogOfWarMap[i][j][src.z] //tile is covered by the FoW
) )
{ {

View File

@ -245,7 +245,7 @@ public:
Mapa * map; Mapa * map;
std::map<ui8,PlayerState> players; //ID <-> player state std::map<ui8,PlayerState> players; //ID <-> player state
std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics
std::vector<ui32> resVals; std::vector<ui32> resVals; //default values of resources in gold
struct DLL_EXPORT HeroesPool struct DLL_EXPORT HeroesPool
{ {
@ -282,8 +282,8 @@ public:
bool checkForVisitableDir(const int3 & src, const int3 & dst) const; //check if dst tile is visitable from dst tile bool checkForVisitableDir(const int3 & src, const int3 & dst) const; //check if dst tile is visitable from dst tile
CPath * getPath(int3 src, int3 dest, const CGHeroInstance * hero); //calculates path between src and dest; returns pointer to newly allocated CPath or NULL if path does not exists CPath * getPath(int3 src, int3 dest, const CGHeroInstance * hero); //calculates path between src and dest; returns pointer to newly allocated CPath or NULL if path does not exists
CGameState(); CGameState(); //c-tor
~CGameState(); ~CGameState(); //d-tor
void getNeighbours(int3 tile, std::vector<int3> &vec, const boost::logic::tribool &onLand); void getNeighbours(int3 tile, std::vector<int3> &vec, const boost::logic::tribool &onLand);
int getMovementCost(const CGHeroInstance *h, int3 src, int3 dest, int remainingMovePoints=-1, bool checkLast=true); int getMovementCost(const CGHeroInstance *h, int3 src, int3 dest, int remainingMovePoints=-1, bool checkLast=true);
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 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

View File

@ -82,14 +82,14 @@ public:
bool clicked; bool clicked;
CHeroWindow * ourWindow; CHeroWindow * ourWindow;
const CArtifact * ourArt; const CArtifact * ourArt;
CArtPlace(const CArtifact * Art); CArtPlace(const CArtifact * Art); //c-tor
void clickLeft (tribool down); void clickLeft (tribool down);
void clickRight (tribool down); void clickRight (tribool down);
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
bool fitsHere(const CArtifact * art); //returns true if given artifact can be placed here bool fitsHere(const CArtifact * art); //returns true if given artifact can be placed here
~CArtPlace(); ~CArtPlace(); //d-tor
}; };
class CHeroWindow: public CWindowWithGarrison, public virtual CIntObject class CHeroWindow: public CWindowWithGarrison, public virtual CIntObject

View File

@ -38,9 +38,9 @@ struct ComponentResolved
SDL_Surface *img; SDL_Surface *img;
std::vector<std::vector<SDL_Surface*> > * txt; std::vector<std::vector<SDL_Surface*> > * txt;
ComponentResolved(); ComponentResolved(); //c-tor
ComponentResolved(SComponent *Comp); ComponentResolved(SComponent *Comp); //c-tor
~ComponentResolved(); ~ComponentResolved(); //d-tor
}; };
struct ComponentsToBlit struct ComponentsToBlit
@ -49,8 +49,8 @@ struct ComponentsToBlit
int w, h; int w, h;
void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret); void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret);
ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or); ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or); //c-tor
~ComponentsToBlit(); ~ComponentsToBlit(); //d-tor
}; };
class CMessage class CMessage

View File

@ -2609,8 +2609,8 @@ bool CPlayerInterface::moveHero( const CGHeroInstance *h, CPath path )
boost::unique_lock<boost::mutex> un(stillMoveHero.mx); boost::unique_lock<boost::mutex> un(stillMoveHero.mx);
stillMoveHero.data = CONTINUE_MOVE; stillMoveHero.data = CONTINUE_MOVE;
enum EterrainType currentTerrain = border; // not init yet enum TerrainTile::EterrainType currentTerrain = TerrainTile::border; // not init yet
enum EterrainType newTerrain; enum TerrainTile::EterrainType newTerrain;
int sh = -1; int sh = -1;
for(int i=path.nodes.size()-1; i>0 && stillMoveHero.data == CONTINUE_MOVE; i--) for(int i=path.nodes.size()-1; i>0 && stillMoveHero.data == CONTINUE_MOVE; i--)
@ -3464,6 +3464,7 @@ void CRecrutationWindow::activate()
slider->activate(); slider->activate();
LOCPLINT->statusbar = bar; LOCPLINT->statusbar = bar;
} }
void CRecrutationWindow::deactivate() void CRecrutationWindow::deactivate()
{ {
ClickableL::deactivate(); ClickableL::deactivate();
@ -3473,20 +3474,23 @@ void CRecrutationWindow::deactivate()
cancel->deactivate(); cancel->deactivate();
slider->deactivate(); slider->deactivate();
} }
void CRecrutationWindow::show(SDL_Surface * to) void CRecrutationWindow::show(SDL_Surface * to)
{ {
static char c=0; static char animCounter=0; //animation counter - for determining appropriate animation frame to be shown
blitAt(bitmap,pos.x,pos.y,to); blitAt(bitmap,pos.x,pos.y,to);
buy->show(to); buy->show(to);
max->show(to); max->show(to);
cancel->show(to); cancel->show(to);
slider->show(to); slider->show(to);
char pom[15]; char pom[15];
SDL_itoa(creatures[which].amount-slider->value,pom,10); //available SDL_itoa(creatures[which].amount-slider->value,pom,10); //available
printAtMiddle(pom,pos.x+205,pos.y+252,GEOR13,zwykly,to); printAtMiddle(pom,pos.x+205,pos.y+252,GEOR13,zwykly,to);
SDL_itoa(slider->value,pom,10); //recruit SDL_itoa(slider->value,pom,10); //recruit
printAtMiddle(pom,pos.x+279,pos.y+252,GEOR13,zwykly,to); printAtMiddle(pom,pos.x+279,pos.y+252,GEOR13,zwykly,to);
printAtMiddle(CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures[creatures[which].ID].namePl,pos.x+243,pos.y+32,GEOR16,tytulowy,to); //eg "Recruit Dragon flies" printAtMiddle(CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures[creatures[which].ID].namePl,pos.x+243,pos.y+32,GEOR16,tytulowy,to); //eg "Recruit Dragon flies"
int curx = pos.x+115-creatures[which].res.size()*16; int curx = pos.x+115-creatures[which].res.size()*16;
for(int i=0;i<creatures[which].res.size();i++) for(int i=0;i<creatures[which].res.size();i++)
{ {
@ -3500,18 +3504,19 @@ void CRecrutationWindow::show(SDL_Surface * to)
} }
curx = pos.x + 192 + 102 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2); curx = pos.x + 192 + 102 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
for(int i=0;i<creatures.size();i++) for(int i=0; i<creatures.size(); ++i)
{ {
creatures[i].pic->blitPic(to,curx-50,pos.y+130-65,!(c%4)); creatures[i].pic->blitPic(to, curx-50, pos.y+130-65, !(animCounter%4));
curx += 120; curx += 120;
} }
c++;
++animCounter;
bar->show(to); bar->show(to);
} }
CRecrutationWindow::CRecrutationWindow(const std::vector<std::pair<int,int> > &Creatures, const boost::function<void(int,int)> &Recruit) //creatures - pairs<creature_ID,amount> CRecrutationWindow::CRecrutationWindow(const std::vector<std::pair<int,int> > &Creatures, const boost::function<void(int,int)> &Recruit) //creatures - pairs<creature_ID,amount>
:recruit(Recruit) :recruit(Recruit), which(0)
{ {
which = 0;
creatures.resize(Creatures.size()); creatures.resize(Creatures.size());
amounts.resize(Creatures.size()); amounts.resize(Creatures.size());
for(int i=0;i<creatures.size();i++) for(int i=0;i<creatures.size();i++)
@ -3526,7 +3531,7 @@ CRecrutationWindow::CRecrutationWindow(const std::vector<std::pair<int,int> > &C
} }
SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp"); SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp");
graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID); graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo //it wouldn't work on 8bpp map
SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
SDL_FreeSurface(hhlp); SDL_FreeSurface(hhlp);
pos.x = screen->w/2 - bitmap->w/2; pos.x = screen->w/2 - bitmap->w/2;
@ -3573,6 +3578,7 @@ CRecrutationWindow::CRecrutationWindow(const std::vector<std::pair<int,int> > &C
} }
//buy->block(true); //not needed, will be blocked by initing slider on 0 //buy->block(true); //not needed, will be blocked by initing slider on 0
} }
CRecrutationWindow::~CRecrutationWindow() CRecrutationWindow::~CRecrutationWindow()
{ {
for(int i=0;i<creatures.size();i++) for(int i=0;i<creatures.size();i++)
@ -3614,7 +3620,8 @@ CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last, int
boost::algorithm::replace_first(title,"%s",CGI->creh->creatures[cid].namePl); boost::algorithm::replace_first(title,"%s",CGI->creh->creatures[cid].namePl);
printAtMiddle(title,150,34,GEOR16,tytulowy,bitmap); printAtMiddle(title,150,34,GEOR16,tytulowy,bitmap);
} }
CSplitWindow::~CSplitWindow()
CSplitWindow::~CSplitWindow() //d-tor
{ {
SDL_FreeSurface(bitmap); SDL_FreeSurface(bitmap);
delete ok; delete ok;
@ -3622,6 +3629,7 @@ CSplitWindow::~CSplitWindow()
delete slider; delete slider;
delete anim; delete anim;
} }
void CSplitWindow::activate() void CSplitWindow::activate()
{ {
ClickableL::activate(); ClickableL::activate();
@ -3630,6 +3638,7 @@ void CSplitWindow::activate()
cancel->activate(); cancel->activate();
slider->activate(); slider->activate();
} }
void CSplitWindow::deactivate() void CSplitWindow::deactivate()
{ {
ClickableL::deactivate(); ClickableL::deactivate();
@ -3638,15 +3647,18 @@ void CSplitWindow::deactivate()
cancel->deactivate(); cancel->deactivate();
slider->deactivate(); slider->deactivate();
} }
void CSplitWindow::split() void CSplitWindow::split()
{ {
gar->splitStacks(a2); gar->splitStacks(a2);
close(); close();
} }
void CSplitWindow::close() void CSplitWindow::close()
{ {
LOCPLINT->popIntTotally(this); LOCPLINT->popIntTotally(this);
} }
void CSplitWindow::sliderMoved(int to) void CSplitWindow::sliderMoved(int to)
{ {
int all = a1+a2; int all = a1+a2;
@ -3654,6 +3666,7 @@ void CSplitWindow::sliderMoved(int to)
if(slider) if(slider)
a1 = all - a2; a1 = all - a2;
} }
void CSplitWindow::show(SDL_Surface * to) void CSplitWindow::show(SDL_Surface * to)
{ {
blitAt(bitmap,pos.x,pos.y,to); blitAt(bitmap,pos.x,pos.y,to);
@ -3665,6 +3678,7 @@ void CSplitWindow::show(SDL_Surface * to)
anim->blitPic(to,pos.x+20,pos.y+54,false); anim->blitPic(to,pos.x+20,pos.y+54,false);
anim->blitPic(to,pos.x+177,pos.y+54,false); anim->blitPic(to,pos.x+177,pos.y+54,false);
} }
void CSplitWindow::keyPressed (const SDL_KeyboardEvent & key) void CSplitWindow::keyPressed (const SDL_KeyboardEvent & key)
{ {
if(key.state != SDL_PRESSED) if(key.state != SDL_PRESSED)
@ -3705,9 +3719,9 @@ void CSplitWindow::clickLeft( boost::logic::tribool down )
{ {
Point click(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y); Point click(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
click -= pos.topLeft(); click -= pos.topLeft();
if(Rect(19,216,105,40).isIn(click)) if(Rect(19,216,105,40).isIn(click)) //left picture
which = 0; which = 0;
else if(Rect(175,216,105,40).isIn(click)) else if(Rect(175,216,105,40).isIn(click)) //right picture
which = 1; which = 1;
} }
} }

View File

@ -214,7 +214,7 @@ public:
{ {
show(to); show(to);
} }
virtual ~IShowable(){}; virtual ~IShowable(){}; //d-tor
}; };
class IStatusBar class IStatusBar
@ -232,7 +232,7 @@ class IActivable
public: public:
virtual void activate()=0; virtual void activate()=0;
virtual void deactivate()=0; virtual void deactivate()=0;
virtual ~IActivable(){}; virtual ~IActivable(){}; //d-tor
}; };
class IShowActivable : public IShowable, public IActivable class IShowActivable : public IShowable, public IActivable
{ {
@ -240,7 +240,7 @@ public:
enum {WITH_GARRISON = 1}; enum {WITH_GARRISON = 1};
int type; //bin flags using etype int type; //bin flags using etype
IShowActivable(); IShowActivable();
virtual ~IShowActivable(){}; virtual ~IShowActivable(){}; //d-tor
}; };
class CWindowWithGarrison : public IShowActivable class CWindowWithGarrison : public IShowActivable
@ -270,7 +270,7 @@ public:
class CSimpleWindow : public IShowActivable, public virtual CIntObject class CSimpleWindow : public IShowActivable, public virtual CIntObject
{ {
public: public:
SDL_Surface * bitmap; SDL_Surface * bitmap; //background
CIntObject * owner; //who made this window CIntObject * owner; //who made this window
virtual void show(SDL_Surface * to); virtual void show(SDL_Surface * to);
CSimpleWindow():bitmap(NULL),owner(NULL){}; //c-tor CSimpleWindow():bitmap(NULL),owner(NULL){}; //c-tor
@ -301,7 +301,7 @@ class ClickableL : public virtual CIntObject //for left-clicks
public: public:
bool pressedL; //for determining if object is L-pressed bool pressedL; //for determining if object is L-pressed
ClickableL(); //c-tor ClickableL(); //c-tor
virtual ~ClickableL();//{}; virtual ~ClickableL();//{};//d-tor
virtual void clickLeft (boost::logic::tribool down)=0; virtual void clickLeft (boost::logic::tribool down)=0;
virtual void activate(); virtual void activate();
virtual void deactivate(); virtual void deactivate();
@ -311,7 +311,7 @@ class ClickableR : public virtual CIntObject //for right-clicks
public: public:
bool pressedR; //for determining if object is R-pressed bool pressedR; //for determining if object is R-pressed
ClickableR(); //c-tor ClickableR(); //c-tor
virtual ~ClickableR();//{}; virtual ~ClickableR();//{};//d-tor
virtual void clickRight (boost::logic::tribool down)=0; virtual void clickRight (boost::logic::tribool down)=0;
virtual void activate()=0; virtual void activate()=0;
virtual void deactivate()=0; virtual void deactivate()=0;
@ -331,12 +331,14 @@ class KeyInterested : public virtual CIntObject
public: public:
bool captureAllKeys; //if true, only this object should get info about pressed keys bool captureAllKeys; //if true, only this object should get info about pressed keys
KeyInterested(): captureAllKeys(false){} KeyInterested(): captureAllKeys(false){}
virtual ~KeyInterested();//{}; virtual ~KeyInterested();//{};//d-tor
virtual void keyPressed(const SDL_KeyboardEvent & key)=0; virtual void keyPressed(const SDL_KeyboardEvent & key)=0;
virtual void activate()=0; virtual void activate()=0;
virtual void deactivate()=0; virtual void deactivate()=0;
}; };
//class for binding keys to left mouse button clicks
//classes wanting use it should have it as one of their base classes
class KeyShortcut : public KeyInterested, public ClickableL class KeyShortcut : public KeyInterested, public ClickableL
{ {
public: public:
@ -352,7 +354,7 @@ class MotionInterested: public virtual CIntObject
public: public:
bool strongInterest; //if true - report all mouse movements, if not - only when hovered bool strongInterest; //if true - report all mouse movements, if not - only when hovered
MotionInterested(){strongInterest=false;}; MotionInterested(){strongInterest=false;};
virtual ~MotionInterested(){}; virtual ~MotionInterested(){};//d-tor
virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0;
virtual void activate()=0; virtual void activate()=0;
virtual void deactivate()=0; virtual void deactivate()=0;
@ -408,7 +410,7 @@ public:
bool delInner; bool delInner;
void show(SDL_Surface * to); void show(SDL_Surface * to);
CRClickPopupInt(IShowActivable *our, bool deleteInt); CRClickPopupInt(IShowActivable *our, bool deleteInt); //c-tor
virtual ~CRClickPopupInt(); //d-tor virtual ~CRClickPopupInt(); //d-tor
}; };
@ -498,7 +500,7 @@ public:
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0); CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0);
~CGarrisonSlot(); ~CGarrisonSlot(); //d-tor
}; };
class CGarrisonInt :public CIntObject class CGarrisonInt :public CIntObject
@ -514,8 +516,8 @@ public:
const CCreatureSet *set1; //top set of creatures const CCreatureSet *set1; //top set of creatures
const CCreatureSet *set2; //bottom set of creatures const CCreatureSet *set2; //bottom set of creatures
std::vector<CGarrisonSlot*> *sup, *sdown; //TODO: comment me std::vector<CGarrisonSlot*> *sup, *sdown; //slots of upper and lower garrison
const CArmedInstance *oup, *odown; //TODO: comment me const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
void activate(); void activate();
void deactivate(); void deactivate();
@ -581,7 +583,7 @@ public:
//overloaded funcs from CGameInterface //overloaded funcs from CGameInterface
void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished
void garrisonChanged(const CGObjectInstance * obj); void garrisonChanged(const CGObjectInstance * obj);
void heroArtifactSetChanged(const CGHeroInstance*hero); void heroArtifactSetChanged(const CGHeroInstance* hero);
void heroCreated(const CGHeroInstance* hero); void heroCreated(const CGHeroInstance* hero);
void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
void heroInGarrisonChange(const CGTownInstance *town); void heroInGarrisonChange(const CGTownInstance *town);
@ -597,8 +599,8 @@ public:
//void showYesNoDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID); //void showYesNoDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel); //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID. void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel); //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd); void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd);
void tileHidden(const std::set<int3> &pos); void tileHidden(const std::set<int3> &pos); //called when given tiles become hidden under fog of war
void tileRevealed(const std::set<int3> &pos); void tileRevealed(const std::set<int3> &pos); //called when fog of war disappears from given tiles
void yourTurn(); void yourTurn();
void availableCreaturesChanged(const CGTownInstance *town); void availableCreaturesChanged(const CGTownInstance *town);
void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it
@ -623,7 +625,7 @@ public:
//-------------// //-------------//
bool shiftPressed() const; bool shiftPressed() const; //determines if shift key is pressed (left or right or both)
void redrawHeroWin(const CGHeroInstance * hero); void redrawHeroWin(const CGHeroInstance * hero);
void updateWater(); void updateWater();
void showComp(SComponent comp); //TODO: comment me void showComp(SComponent comp); //TODO: comment me
@ -785,7 +787,7 @@ public:
AdventureMapButton *ok, *cancel; AdventureMapButton *ok, *cancel;
SDL_Surface *bitmap; //background SDL_Surface *bitmap; //background
int a1, a2, c; //TODO: comment me int a1, a2, c; //TODO: comment me
bool which; //TODO: comment me bool which; //which creature is selected
int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
@ -806,12 +808,12 @@ public:
//bool active; //TODO: comment me //bool active; //TODO: comment me
int type;//0 - rclick popup; 1 - normal window int type;//0 - rclick popup; 1 - normal window
SDL_Surface *bitmap; //background SDL_Surface *bitmap; //background
char anf; //TODO: comment me char anf; //animation counter
std::string count; //creature count in text format std::string count; //creature count in text format
boost::function<void()> dsm; //TODO: comment me boost::function<void()> dsm; //dismiss button callback
CCreaturePic *anim; CCreaturePic *anim; //related creature's animation
CCreature *c; CCreature *c; //related creature
std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty) std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
AdventureMapButton *dismiss, *upgrade, *ok; AdventureMapButton *dismiss, *upgrade, *ok;
@ -878,9 +880,9 @@ public:
CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight) CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
r1, r2; //TODO: comment me r1, r2; //suggested amounts of traded resources
AdventureMapButton *ok, *max, *deal; AdventureMapButton *ok, *max, *deal;
CSlider *slider; CSlider *slider; //for choosing amount to be exchanged
void activate(); void activate();
void deactivate(); void deactivate();
@ -936,7 +938,7 @@ public:
} h1, h2; //recruitable heroes } h1, h2; //recruitable heroes
SDL_Surface *bg; //background SDL_Surface *bg; //background
CStatusBar *bar; CStatusBar *bar; //tavern's internal status bar
int selected;//0 (left) or 1 (right) int selected;//0 (left) or 1 (right)
AdventureMapButton *thiefGuild, *cancel, *recruit; AdventureMapButton *thiefGuild, *cancel, *recruit;
@ -977,15 +979,15 @@ public:
class CGarrisonWindow : public CWindowWithGarrison, public CIntObject class CGarrisonWindow : public CWindowWithGarrison, public CIntObject
{ {
public: public:
SDL_Surface *bg; SDL_Surface *bg; //background surface
AdventureMapButton *split, *quit; AdventureMapButton *split, *quit;
void close(); void close();
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down); CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down); //c-tor
~CGarrisonWindow(); ~CGarrisonWindow(); //d-tor
}; };
extern CPlayerInterface * LOCPLINT; extern CPlayerInterface * LOCPLINT;

View File

@ -948,16 +948,16 @@ void MapSel::printMaps(int elemIdx)
int temp=-1; int temp=-1;
switch (curMap->version) switch (curMap->version)
{ {
case RoE: case CMapHeader::RoE:
temp=0; temp=0;
break; break;
case AB: case CMapHeader::AB:
temp=1; temp=1;
break; break;
case SoD: case CMapHeader::SoD:
temp=2; temp=2;
break; break;
case WoG: case CMapHeader::WoG:
temp=3; temp=3;
break; break;
default: default:
@ -1355,7 +1355,7 @@ void MapSel::select(int which, bool updateMapsList, bool forceSettingsUpdate)
} }
pset.heroPortrait=-1; pset.heroPortrait=-1;
if (! if (!
(((curVector()[which]->players[i].generateHeroAtMainTown || curVector()[which]->version==RoE) (((curVector()[which]->players[i].generateHeroAtMainTown || curVector()[which]->version==CMapHeader::RoE)
&& curVector()[which]->players[i].hasMainTown) && curVector()[which]->players[i].hasMainTown)
|| curVector()[which]->players[i].p8) || curVector()[which]->players[i].p8)
) )

View File

@ -42,8 +42,8 @@ public:
void convert(); void convert();
SDL_Surface * getSurface(); //for standard H3 PCX SDL_Surface * getSurface(); //for standard H3 PCX
//SDL_Surface * getSurfaceZ(); //for ZSoft PCX //SDL_Surface * getSurfaceZ(); //for ZSoft PCX
CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;}; CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;}; //c-tor
~CPCXConv(){if (pcxs) delete[] pcx; if(bmps) delete[] bmp;} ~CPCXConv(){if (pcxs) delete[] pcx; if(bmps) delete[] bmp;} //d-tor
}; };
namespace BitmapHandler namespace BitmapHandler
{ {

View File

@ -70,8 +70,8 @@ namespace config
std::map<std::pair<int,int>, GUIOptions > guiOptions; std::map<std::pair<int,int>, GUIOptions > guiOptions;
GUIOptions *go(); //return pointer to gui options appropriate for used screen resolution GUIOptions *go(); //return pointer to gui options appropriate for used screen resolution
void init(); void init();
CConfigHandler(void); CConfigHandler(void); //c-tor
~CConfigHandler(void); ~CConfigHandler(void); //d-tor
}; };
} }
extern config::CConfigHandler conf; extern config::CConfigHandler conf;

View File

@ -44,23 +44,16 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte)
*/ */
enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors 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}; captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255};
enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=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,
HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST};
enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
enum EAbilities {DOUBLE_WIDE, FLYING, SHOOTER, TWO_HEX_ATTACK, SIEGE_ABILITY, SIEGE_WEAPON, enum EAbilities {DOUBLE_WIDE, FLYING, SHOOTER, TWO_HEX_ATTACK, SIEGE_ABILITY, SIEGE_WEAPON,
KING1, KING2, KING3, MIND_IMMUNITY, NO_OBSTACLE_PENALTY, NO_CLOSE_COMBAT_PENALTY, KING1, KING2, KING3, MIND_IMMUNITY, NO_OBSTACLE_PENALTY, NO_CLOSE_COMBAT_PENALTY,
JOUSTING, FIRE_IMMUNITY, TWICE_ATTACK, NO_ENEMY_RETALIATION, NO_MORAL_PENALTY, JOUSTING, FIRE_IMMUNITY, TWICE_ATTACK, NO_ENEMY_RETALIATION, NO_MORAL_PENALTY,
UNDEAD, MULTI_HEAD_ATTACK, EXTENDED_RADIOUS_SHOOTER, GHOST, RAISES_MORALE, UNDEAD, MULTI_HEAD_ATTACK, EXTENDED_RADIOUS_SHOOTER, GHOST, RAISES_MORALE,
LOWERS_MORALE, DRAGON, STRIKE_AND_RETURN, FEARLESS, REBIRTH, NOT_ACTIVE}; //some flags are used only for battles LOWERS_MORALE, DRAGON, STRIKE_AND_RETURN, FEARLESS, REBIRTH, NOT_ACTIVE}; //some flags are used only for battles
enum ECombatInfo{ALIVE = NOT_ACTIVE+1, SUMMONED, CLONED, HAD_MORALE, WAITING, MOVED, DEFENDING}; enum ECombatInfo{ALIVE = NOT_ACTIVE+1, SUMMONED, CLONED, HAD_MORALE, WAITING, MOVED, DEFENDING};
class CGameInfo; class CGameInfo;
extern CGameInfo* CGI; extern CGameInfo* CGI;

View File

@ -42,8 +42,8 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
{ {
std::vector<ui16> slots; std::vector<ui16> slots;
slots += 17, 16, 15,14,13, 18, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0; slots += 17, 16, 15,14,13, 18, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0;
std::map<char,EartClass> classes = std::map<char, CArtifact::EartClass> classes =
map_list_of('S',ART_SPECIAL)('T',ART_TREASURE)('N',ART_MINOR)('J',ART_MAJOR)('R',ART_RELIC); map_list_of('S',CArtifact::ART_SPECIAL)('T',CArtifact::ART_TREASURE)('N',CArtifact::ART_MINOR)('J',CArtifact::ART_MAJOR)('R',CArtifact::ART_RELIC);
std::string buf = bitmaph->getTextFile("ARTRAITS.TXT"), dump, pom; std::string buf = bitmaph->getTextFile("ARTRAITS.TXT"), dump, pom;
int it=0; int it=0;
for(int i=0; i<2; ++i) for(int i=0; i<2; ++i)
@ -118,16 +118,16 @@ void CArtHandler::sortArts()
{ {
switch (artifacts[i].aClass) switch (artifacts[i].aClass)
{ {
case ART_TREASURE: case CArtifact::ART_TREASURE:
treasures.push_back(&(artifacts[i])); treasures.push_back(&(artifacts[i]));
break; break;
case ART_MINOR: case CArtifact::ART_MINOR:
minors.push_back(&(artifacts[i])); minors.push_back(&(artifacts[i]));
break; break;
case ART_MAJOR: case CArtifact::ART_MAJOR:
majors.push_back(&(artifacts[i])); majors.push_back(&(artifacts[i]));
break; break;
case ART_RELIC: case CArtifact::ART_RELIC:
relics.push_back(&(artifacts[i])); relics.push_back(&(artifacts[i]));
break; break;
} }

View File

@ -21,8 +21,9 @@ class DLL_EXPORT CArtifact //container for artifacts
{ {
std::string name, description; //set if custom std::string name, description; //set if custom
public: public:
const std::string &Name() const; enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
const std::string &Description() const; const std::string &Name() const; //getter
const std::string &Description() const; //getter
ui32 price; ui32 price;
std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed

View File

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

View File

@ -45,8 +45,8 @@ public:
bool alphaTransformed; bool alphaTransformed;
bool notFreeImgs; bool notFreeImgs;
CDefHandler(); CDefHandler(); //c-tor
~CDefHandler(); ~CDefHandler(); //d-tor
static void print (std::ostream & stream, int nr, int bytcon); static void print (std::ostream & stream, int nr, int bytcon);
int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false); int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false);
static unsigned char *writeNormalNr (int nr, int bytCon); static unsigned char *writeNormalNr (int nr, int bytCon);
@ -64,7 +64,7 @@ class CDefEssential //DefHandler with images only
{ {
public: public:
std::vector<Cimage> ourImages; std::vector<Cimage> ourImages;
~CDefEssential(); ~CDefEssential(); //d-tor
}; };

View File

@ -167,19 +167,19 @@ void CHeroHandler::loadHeroes()
int numberOfCurrentClassHeroes = 0; int numberOfCurrentClassHeroes = 0;
int currentClass = 0; int currentClass = 0;
int additHero = 0; int additHero = 0;
EHeroClasses addTab[12]; CHero::EHeroClasses addTab[12];
addTab[0] = HERO_KNIGHT; addTab[0] = CHero::KNIGHT;
addTab[1] = HERO_WITCH; addTab[1] = CHero::WITCH;
addTab[2] = HERO_KNIGHT; addTab[2] = CHero::KNIGHT;
addTab[3] = HERO_WIZARD; addTab[3] = CHero::WIZARD;
addTab[4] = HERO_RANGER; addTab[4] = CHero::RANGER;
addTab[5] = HERO_BARBARIAN; addTab[5] = CHero::BARBARIAN;
addTab[6] = HERO_DEATHKNIGHT; addTab[6] = CHero::DEATHKNIGHT;
addTab[7] = HERO_WARLOCK; addTab[7] = CHero::WARLOCK;
addTab[8] = HERO_KNIGHT; addTab[8] = CHero::KNIGHT;
addTab[9] = HERO_WARLOCK; addTab[9] = CHero::WARLOCK;
addTab[10] = HERO_BARBARIAN; addTab[10] = CHero::BARBARIAN;
addTab[11] = HERO_DEMONIAC; addTab[11] = CHero::DEMONIAC;
for (int i=0; i<HEROES_QUANTITY; i++) for (int i=0; i<HEROES_QUANTITY; i++)
@ -187,7 +187,7 @@ void CHeroHandler::loadHeroes()
CHero * nher = new CHero; CHero * nher = new CHero;
if(currentClass<18) if(currentClass<18)
{ {
nher->heroType = (EHeroClasses)currentClass; nher->heroType = static_cast<CHero::EHeroClasses>(currentClass);
++numberOfCurrentClassHeroes; ++numberOfCurrentClassHeroes;
if(numberOfCurrentClassHeroes==8) if(numberOfCurrentClassHeroes==8)
{ {

View File

@ -22,7 +22,11 @@ class CGHeroInstance;
class DLL_EXPORT CHero class DLL_EXPORT CHero
{ {
public: public:
std::string name; enum EHeroClasses {KNIGHT, CLERIC, RANGER, DRUID, ALCHEMIST, WIZARD,
DEMONIAC, HERETIC, DEATHKNIGHT, NECROMANCER, WARLOCK, OVERLORD,
BARBARIAN, BATTLEMAGE, BEASTMASTER, WITCH, PLANESWALKER, ELEMENTALIST};
std::string name; //name of hero
int ID; int ID;
int lowStack[3], highStack[3]; //amount of units; described below int lowStack[3], highStack[3]; //amount of units; described below
std::string refTypeStack[3]; //reference names of units appearing in hero's army if he is recruited in tavern std::string refTypeStack[3]; //reference names of units appearing in hero's army if he is recruited in tavern
@ -44,15 +48,15 @@ public:
ui32 skillLimit; //how many secondary skills can hero learn ui32 skillLimit; //how many secondary skills can hero learn
std::string name; std::string name;
float aggression; float aggression;
int initialAttack, initialDefence, initialPower, initialKnowledge; int initialAttack, initialDefence, initialPower, initialKnowledge; //initial values of primary skills
std::vector<std::pair<int,int> > primChance;//primChance[PRIMARY_SKILL_ID] - first is for levels 2 - 9, second for 10+;;; probability (%) of getting point of primary skill when getting new level std::vector<std::pair<int,int> > primChance;//primChance[PRIMARY_SKILL_ID] - first is for levels 2 - 9, second for 10+;;; probability (%) of getting point of primary skill when getting new level
std::vector<int> proSec; //probabilities of gaining secondary skills (out of 112), in id order std::vector<int> proSec; //probabilities of gaining secondary skills (out of 112), in id order
int selectionProbability[9]; //probability of selection in towns int selectionProbability[9]; //probability of selection in towns
std::vector<int> terrCosts; //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock; -1 means terrain is imapassable std::vector<int> terrCosts; //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock; -1 means terrain is imapassable
int chooseSecSkill(const std::set<int> & possibles) const; //picks secondary skill out from given possibilities int chooseSecSkill(const std::set<int> & possibles) const; //picks secondary skill out from given possibilities
CHeroClass(); CHeroClass(); //c-tor
~CHeroClass(); ~CHeroClass(); //d-tor
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
@ -83,7 +87,7 @@ struct DLL_EXPORT CObstacleInfo
class DLL_EXPORT CHeroHandler class DLL_EXPORT CHeroHandler
{ {
public: public:
std::vector<CHero*> heroes; //by³o nodrze std::vector<CHero*> heroes; //by³o nodrze //changed from nodrze
std::vector<CHeroClass *> heroClasses; std::vector<CHeroClass *> heroClasses;
std::vector<int> 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 std::vector<int> 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
@ -102,17 +106,17 @@ public:
std::map<int, CObstacleInfo> obstacles; //info about obstacles that may be placed on battlefield std::map<int, CObstacleInfo> obstacles; //info about obstacles that may be placed on battlefield
void loadObstacles(); void loadObstacles(); //loads info about obstacles
unsigned int level(unsigned int experience); unsigned int level(unsigned int experience); //calculates level corresponding to given experience amount
unsigned int reqExp(unsigned int level); unsigned int reqExp(unsigned int level); //calculates experience resuired for given level
void loadHeroes(); void loadHeroes();
void loadHeroClasses(); void loadHeroClasses();
void initHeroClasses(); void initHeroClasses();
void initTerrainCosts(); void initTerrainCosts();
CHeroHandler(); CHeroHandler(); //c-tor
~CHeroHandler(); ~CHeroHandler(); //d-tor
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {

View File

@ -277,13 +277,13 @@ unsigned int CGHeroInstance::getTileCost(const TerrainTile &dest, const TerrainT
int road = std::min(dest.malle,from.malle); //used road ID int road = std::min(dest.malle,from.malle); //used road ID
switch(road) switch(road)
{ {
case dirtRoad: case TerrainTile::dirtRoad:
ret = 75; ret = 75;
break; break;
case grazvelRoad: case TerrainTile::grazvelRoad:
ret = 65; ret = 65;
break; break;
case cobblestoneRoad: case TerrainTile::cobblestoneRoad:
ret = 50; ret = 50;
break; break;
default: default:
@ -867,18 +867,19 @@ int CGHeroInstance::valOfBonuses( HeroBonus::BonusType type, int subtype /*= -1*
bool CGHeroInstance::hasBonusOfType(HeroBonus::BonusType type, int subtype /*= -1*/) const bool CGHeroInstance::hasBonusOfType(HeroBonus::BonusType type, int subtype /*= -1*/) const
{ {
if(subtype == -1) if(subtype == -1) //any subtype
{ {
for(std::list<HeroBonus>::const_iterator i=bonuses.begin(); i != bonuses.end(); i++) for(std::list<HeroBonus>::const_iterator i=bonuses.begin(); i != bonuses.end(); i++)
if(i->type == type) if(i->type == type)
return true; return true;
} }
else else //given subtype
{ {
for(std::list<HeroBonus>::const_iterator i=bonuses.begin(); i != bonuses.end(); i++) for(std::list<HeroBonus>::const_iterator i=bonuses.begin(); i != bonuses.end(); i++)
if(i->type == type && i->subtype == subtype) if(i->type == type && i->subtype == subtype)
return true; return true;
} }
throw "CGHeroInstance::hasBonusOfType - we shouln't be here!";
} }
int CGTownInstance::getSightRadious() const //returns sight distance int CGTownInstance::getSightRadious() const //returns sight distance
@ -2884,7 +2885,7 @@ void CGOnceVisitable::initObj()
{ {
artOrRes = 1; artOrRes = 1;
std::vector<CArtifact*> arts; std::vector<CArtifact*> arts;
cb->getAllowed(arts, ART_TREASURE | ART_MINOR | ART_MAJOR); cb->getAllowed(arts, CArtifact::ART_TREASURE | CArtifact::ART_MINOR | CArtifact::ART_MAJOR);
bonusType = arts[ran() % arts.size()]->id; bonusType = arts[ran() % arts.size()]->id;
} }
else else
@ -2910,13 +2911,13 @@ void CGOnceVisitable::initObj()
int hlp = ran()%100; int hlp = ran()%100;
if(hlp < 30) if(hlp < 30)
cb->getAllowed(arts,ART_TREASURE); cb->getAllowed(arts,CArtifact::ART_TREASURE);
else if(hlp < 80) else if(hlp < 80)
cb->getAllowed(arts,ART_MINOR); cb->getAllowed(arts,CArtifact::ART_MINOR);
else if(hlp < 95) else if(hlp < 95)
cb->getAllowed(arts,ART_MAJOR); cb->getAllowed(arts,CArtifact::ART_MAJOR);
else else
cb->getAllowed(arts,ART_RELIC); cb->getAllowed(arts,CArtifact::ART_RELIC);
bonusType = arts[ran() % arts.size()]->id; bonusType = arts[ran() % arts.size()]->id;
} }
@ -2934,7 +2935,7 @@ void CGOnceVisitable::initObj()
{ {
artOrRes = 1; artOrRes = 1;
std::vector<CArtifact*> arts; std::vector<CArtifact*> arts;
cb->getAllowed(arts, ART_TREASURE | ART_MINOR); cb->getAllowed(arts, CArtifact::ART_TREASURE | CArtifact::ART_MINOR);
bonusType = arts[ran() % arts.size()]->id; bonusType = arts[ran() % arts.size()]->id;
} }
else //2 - 5 of non-gold resource else //2 - 5 of non-gold resource

View File

@ -150,7 +150,7 @@ public:
class DLL_EXPORT CPlayersVisited: public CGObjectInstance class DLL_EXPORT CPlayersVisited: public CGObjectInstance
{ {
public: public:
std::set<ui8> players; std::set<ui8> players; //players that visited this object
bool hasVisited(ui8 player) const; bool hasVisited(ui8 player) const;
void setPropertyDer(ui8 what, ui32 val);//synchr void setPropertyDer(ui8 what, ui32 val);//synchr
@ -342,7 +342,7 @@ public:
int creatureGrowth(const int & level) const; int creatureGrowth(const int & level) const;
bool hasFort() const; bool hasFort() const;
bool hasCapitol() const; bool hasCapitol() const;
int dailyIncome() const; int dailyIncome() const; //calculates daily income of this town
int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5) int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
CGTownInstance(); CGTownInstance();
@ -464,8 +464,8 @@ class DLL_EXPORT CGSeerHut : public CGObjectInstance, public CQuest
public: public:
ui8 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 ui8 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
si32 rID; si32 rID; //reward ID
si32 rVal; si32 rVal; //reward value
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {

View File

@ -45,8 +45,8 @@ private:
public: public:
std::vector<Entry> entries; std::vector<Entry> entries;
std::map<std::string, int> fimap; // map of wav file and index std::map<std::string, int> fimap; // map of wav file and index
~CSndHandler(); ~CSndHandler(); //d-tor
CSndHandler(std::string fname); CSndHandler(std::string fname); //c-tor
void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file
const char * extract (std::string srcfile, int & size); //return selecte file data, NULL if file doesn't exist const char * extract (std::string srcfile, int & size); //return selecte file data, NULL if file doesn't exist
void extract(int index, std::string dstfile); //saves selected file void extract(int index, std::string dstfile); //saves selected file
@ -67,8 +67,8 @@ protected:
bool opened; bool opened;
public: public:
std::vector<Entry> entries; std::vector<Entry> entries;
~CVidHandler(); ~CVidHandler(); //d-tor
CVidHandler(std::string fname); CVidHandler(std::string fname); //c-tor
std::ifstream & extract(std::string srcfile); std::ifstream & extract(std::string srcfile);
void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file
unsigned char * extract (std::string srcfile, int & size); //return selecte file, unsigned char * extract (std::string srcfile, int & size); //return selecte file,

View File

@ -67,8 +67,8 @@ public:
std::map<int,std::map<int, Structure*> > structures; // <town ID, <structure ID, structure>> std::map<int,std::map<int, Structure*> > structures; // <town ID, <structure ID, structure>>
std::map<int, std::map<int,std::set<int> > > requirements; //requirements[town_id][structure_id] -> set of required buildings std::map<int, std::map<int,std::set<int> > > requirements; //requirements[town_id][structure_id] -> set of required buildings
CTownHandler(); CTownHandler(); //c-tor
~CTownHandler(); ~CTownHandler(); //d-tor
void loadNames(); void loadNames();
void loadStructures(); void loadStructures();

View File

@ -123,7 +123,7 @@ public:
const char *GetLibExtension(); const char *GetLibExtension();
void *FindAddress234(const char *symbol); void *FindAddress234(const char *symbol);
virtual ~DLLHandler(); virtual ~DLLHandler(); //d-tor
}; };
class CBIKHandler class CBIKHandler

View File

@ -136,12 +136,12 @@ void IGameCallback::getAllowedArts(std::vector<CArtifact*> &out, std::vector<CAr
void IGameCallback::getAllowed(std::vector<CArtifact*> &out, int flags) void IGameCallback::getAllowed(std::vector<CArtifact*> &out, int flags)
{ {
if(flags & ART_TREASURE) if(flags & CArtifact::ART_TREASURE)
getAllowedArts(out,&CArtHandler::treasures); getAllowedArts(out,&CArtHandler::treasures);
if(flags & ART_MINOR) if(flags & CArtifact::ART_MINOR)
getAllowedArts(out,&CArtHandler::minors); getAllowedArts(out,&CArtHandler::minors);
if(flags & ART_MAJOR) if(flags & CArtifact::ART_MAJOR)
getAllowedArts(out,&CArtHandler::majors); getAllowedArts(out,&CArtHandler::majors);
if(flags & ART_RELIC) if(flags & CArtifact::ART_RELIC)
getAllowedArts(out,&CArtHandler::relics); getAllowedArts(out,&CArtHandler::relics);
} }

View File

@ -39,14 +39,14 @@ struct SharedMem
boost::interprocess::mapped_region *mr; boost::interprocess::mapped_region *mr;
ServerReady *sr; ServerReady *sr;
SharedMem() SharedMem() //c-tor
:smo(boost::interprocess::open_or_create,"vcmi_memory",boost::interprocess::read_write) :smo(boost::interprocess::open_or_create,"vcmi_memory",boost::interprocess::read_write)
{ {
smo.truncate(sizeof(ServerReady)); smo.truncate(sizeof(ServerReady));
mr = new boost::interprocess::mapped_region(smo,boost::interprocess::read_write); mr = new boost::interprocess::mapped_region(smo,boost::interprocess::read_write);
sr = new(mr->get_address())ServerReady(); sr = new(mr->get_address())ServerReady();
}; };
~SharedMem() ~SharedMem() //d-tor
{ {
delete mr; delete mr;
boost::interprocess::shared_memory_object::remove("vcmi_memory"); boost::interprocess::shared_memory_object::remove("vcmi_memory");

12
map.cpp
View File

@ -1238,11 +1238,11 @@ void Mapa::readTerrain( unsigned char * bufor, int &i)
{ {
for (int z=0; z<height; z++) for (int z=0; z<height; z++)
{ {
terrain[z][c][0].tertype = (EterrainType)(bufor[i++]); terrain[z][c][0].tertype = static_cast<TerrainTile::EterrainType>(bufor[i++]);
terrain[z][c][0].terview = bufor[i++]; terrain[z][c][0].terview = bufor[i++];
terrain[z][c][0].nuine = (Eriver)bufor[i++]; terrain[z][c][0].nuine = static_cast<TerrainTile::Eriver>(bufor[i++]);
terrain[z][c][0].rivDir = bufor[i++]; terrain[z][c][0].rivDir = bufor[i++];
terrain[z][c][0].malle = (Eroad)bufor[i++]; terrain[z][c][0].malle = static_cast<TerrainTile::Eroad>(bufor[i++]);
terrain[z][c][0].roadDir = bufor[i++]; terrain[z][c][0].roadDir = bufor[i++];
terrain[z][c][0].siodmyTajemniczyBajt = bufor[i++]; terrain[z][c][0].siodmyTajemniczyBajt = bufor[i++];
terrain[z][c][0].blocked = 0; terrain[z][c][0].blocked = 0;
@ -1255,11 +1255,11 @@ void Mapa::readTerrain( unsigned char * bufor, int &i)
{ {
for (int z=0; z<height; z++) for (int z=0; z<height; z++)
{ {
terrain[z][c][1].tertype = (EterrainType)(bufor[i++]); terrain[z][c][1].tertype = static_cast<TerrainTile::EterrainType>(bufor[i++]);
terrain[z][c][1].terview = bufor[i++]; terrain[z][c][1].terview = bufor[i++];
terrain[z][c][1].nuine = (Eriver)bufor[i++]; terrain[z][c][1].nuine = static_cast<TerrainTile::Eriver>(bufor[i++]);
terrain[z][c][1].rivDir = bufor[i++]; terrain[z][c][1].rivDir = bufor[i++];
terrain[z][c][1].malle = (Eroad)bufor[i++]; terrain[z][c][1].malle = static_cast<TerrainTile::Eroad>(bufor[i++]);
terrain[z][c][1].roadDir = bufor[i++]; terrain[z][c][1].roadDir = bufor[i++];
terrain[z][c][1].siodmyTajemniczyBajt = bufor[i++]; terrain[z][c][1].siodmyTajemniczyBajt = bufor[i++];
terrain[z][c][1].blocked = 0; terrain[z][c][1].blocked = 0;

5
map.h
View File

@ -66,6 +66,10 @@ public:
}; };
struct DLL_EXPORT TerrainTile struct DLL_EXPORT TerrainTile
{ {
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};
EterrainType tertype; // type of terrain EterrainType tertype; // type of terrain
unsigned char terview; // look of terrain unsigned char terview; // look of terrain
Eriver nuine; // type of Eriver (0 if there is no Eriver) Eriver nuine; // type of Eriver (0 if there is no Eriver)
@ -199,6 +203,7 @@ public:
class DLL_EXPORT CMapHeader class DLL_EXPORT CMapHeader
{ {
public: public:
enum Eformat { WoG=0x33, AB=0x15, RoE=0x0e, SoD=0x1c};
Eformat version; // version of map Eformat Eformat version; // version of map Eformat
ui8 areAnyPLayers; // if there are any playable players on map ui8 areAnyPLayers; // if there are any playable players on map
si32 height, width, twoLevel; //sizes si32 height, width, twoLevel; //sizes

View File

@ -30,59 +30,59 @@ extern SDL_Surface * screen;
std::string nameFromType (int typ) std::string nameFromType (int typ)
{ {
switch((EterrainType)typ) switch(static_cast<TerrainTile::EterrainType>(typ))
{ {
case dirt: case TerrainTile::dirt:
{ {
return std::string("DIRTTL.DEF"); return std::string("DIRTTL.DEF");
break; break;
} }
case sand: case TerrainTile::sand:
{ {
return std::string("SANDTL.DEF"); return std::string("SANDTL.DEF");
break; break;
} }
case grass: case TerrainTile::grass:
{ {
return std::string("GRASTL.DEF"); return std::string("GRASTL.DEF");
break; break;
} }
case snow: case TerrainTile::snow:
{ {
return std::string("SNOWTL.DEF"); return std::string("SNOWTL.DEF");
break; break;
} }
case swamp: case TerrainTile::swamp:
{ {
return std::string("SWMPTL.DEF"); return std::string("SWMPTL.DEF");
break; break;
} }
case rough: case TerrainTile::rough:
{ {
return std::string("ROUGTL.DEF"); return std::string("ROUGTL.DEF");
break; break;
} }
case subterranean: case TerrainTile::subterranean:
{ {
return std::string("SUBBTL.DEF"); return std::string("SUBBTL.DEF");
break; break;
} }
case lava: case TerrainTile::lava:
{ {
return std::string("LAVATL.DEF"); return std::string("LAVATL.DEF");
break; break;
} }
case water: case TerrainTile::water:
{ {
return std::string("WATRTL.DEF"); return std::string("WATRTL.DEF");
break; break;
} }
case rock: case TerrainTile::rock:
{ {
return std::string("ROCKTL.DEF"); return std::string("ROCKTL.DEF");
break; break;
} }
case border: case TerrainTile::border:
//TODO use me //TODO use me
break; break;
default: default:

View File

@ -80,12 +80,12 @@ public:
class CMapHandler class CMapHandler
{ {
public: public:
PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles; PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles; //informations about map tiles
int3 sizes; int3 sizes; //map size (x - width, y - height, z - number of levels)
Mapa * map; Mapa * map;
std::set<int> usedHeroes; std::set<int> usedHeroes;
CDefHandler * fullHide; CDefHandler * fullHide; //for Fog of War
CDefHandler * partialHide; CDefHandler * partialHide; //for For of War
std::vector<std::vector<SDL_Surface *> > terrainGraphics; // [terrain id] [view type] [rotation type] std::vector<std::vector<SDL_Surface *> > terrainGraphics; // [terrain id] [view type] [rotation type]
std::vector<CDefHandler *> roadDefs; std::vector<CDefHandler *> roadDefs;
@ -96,8 +96,8 @@ public:
std::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile std::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
CMapHandler(); CMapHandler(); //c-tor
~CMapHandler(); ~CMapHandler(); //d-tor
void loadDefs(); void loadDefs();
SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl); SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);

View File

@ -1139,8 +1139,8 @@ bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255*
tmh.movePoints = h->movement; tmh.movePoints = h->movement;
//check if destination tile is available //check if destination tile is available
if( t.tertype == rock if( t.tertype == TerrainTile::rock
|| (!h->canWalkOnSea() && t.tertype == water) || (!h->canWalkOnSea() && t.tertype == TerrainTile::water)
|| (t.blocked && !t.visitable) //tile is blocked andnot visitable || (t.blocked && !t.visitable) //tile is blocked andnot visitable
) )
{ {
@ -1934,8 +1934,8 @@ bool CGameHandler::buyArtifact( ui32 hid, si32 aid )
bool CGameHandler::tradeResources( ui32 val, ui8 player, ui32 id1, ui32 id2 ) bool CGameHandler::tradeResources( ui32 val, ui8 player, ui32 id1, ui32 id2 )
{ {
val = std::min(si32(val),gs->getPlayer(player)->resources[id1]); val = std::min(si32(val),gs->getPlayer(player)->resources[id1]);
double uzysk = (double)gs->resVals[id1] * val * gs->getMarketEfficiency(player); double yield = (double)gs->resVals[id1] * val * gs->getMarketEfficiency(player);
uzysk /= gs->resVals[id2]; yield /= gs->resVals[id2];
SetResource sr; SetResource sr;
sr.player = player; sr.player = player;
sr.resid = id1; sr.resid = id1;
@ -1943,7 +1943,7 @@ bool CGameHandler::tradeResources( ui32 val, ui8 player, ui32 id1, ui32 id2 )
sendAndApply(&sr); sendAndApply(&sr);
sr.resid = id2; sr.resid = id2;
sr.val = gs->getPlayer(player)->resources[id2] + (int)uzysk; sr.val = gs->getPlayer(player)->resources[id2] + (int)yield;
sendAndApply(&sr); sendAndApply(&sr);
return true; return true;

View File

@ -36,8 +36,8 @@ class CVCMIServer
std::map<int,CConnection*> connections; std::map<int,CConnection*> connections;
std::set<CConnection*> conns; std::set<CConnection*> conns;
public: public:
CVCMIServer(); CVCMIServer(); //c-tor
~CVCMIServer(); ~CVCMIServer(); //d-tor
void setUpConnection(CConnection *c, std::string mapname, si32 checksum); void setUpConnection(CConnection *c, std::string mapname, si32 checksum);
void newGame(CConnection *c); void newGame(CConnection *c);
void loadGame(CConnection *c); void loadGame(CConnection *c);