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

* Added comments to map.h * Refactoring(renamed attributes, some steps towards coding guidelines, ..)

This commit is contained in:
beegee1 2012-10-26 17:51:05 +00:00
parent 8604234f8d
commit 720deba838
16 changed files with 1364 additions and 804 deletions

View File

@ -2737,7 +2737,7 @@ TSubgoal CGoal::whatToDoToAchieve()
{
case WIN:
{
const CVictoryCondition &vc = cb->getMapHeader()->victoryCondition;
const VictoryCondition &vc = cb->getMapHeader()->victoryCondition;
EVictoryConditionType::EVictoryConditionType cond = vc.condition;
if(!vc.appliesToAI)

View File

@ -1385,7 +1385,7 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
{
if(pnode->land)
{
if(LOCPLINT->cb->getTile(h->getPosition(false))->tertype != TerrainTile::water)
if(LOCPLINT->cb->getTile(h->getPosition(false))->tertype != ETerrainType::WATER)
CCS->curh->changeGraphic(0, 4 + turns*6);
else
CCS->curh->changeGraphic(0, 7 + turns*6); //anchor

View File

@ -44,7 +44,7 @@ public:
};
extern CClientState * CCS;
struct Mapa;
struct CMap;
/// CGameInfo class
/// for allowing different functions for accessing game informations
@ -67,7 +67,7 @@ public:
void setFromLib();
friend class CClient;
friend void initVillagesCapitols(Mapa * map);
friend void initVillagesCapitols(CMap * map);
CGameInfo();
};

View File

@ -87,7 +87,7 @@ CSoundHandler::CSoundHandler():
pickupSounds += soundBase::pickup01, soundBase::pickup02, soundBase::pickup03,
soundBase::pickup04, soundBase::pickup05, soundBase::pickup06, soundBase::pickup07;
horseSounds += // must be the same order as terrains (see EterrainType);
horseSounds += // must be the same order as terrains (see ETerrainType);
soundBase::horseDirt, soundBase::horseSand, soundBase::horseGrass,
soundBase::horseSnow, soundBase::horseSwamp, soundBase::horseRough,
soundBase::horseSubterranean, soundBase::horseLava,

View File

@ -1223,8 +1223,8 @@ bool CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
boost::unique_lock<boost::mutex> un(stillMoveHero.mx);
stillMoveHero.data = CONTINUE_MOVE;
enum TerrainTile::EterrainType currentTerrain = TerrainTile::border; // not init yet
enum TerrainTile::EterrainType newTerrain;
enum ETerrainType::ETerrainType currentTerrain = ETerrainType::BORDER; // not init yet
enum ETerrainType::ETerrainType newTerrain;
int sh = -1;
const TerrainTile * curTile = cb->getTile(CGHeroInstance::convertPosition(h->pos, false));

View File

@ -1048,7 +1048,7 @@ void SelectionTab::parseMaps(const std::vector<ResourceID> &files, int start, in
{
try
{
TInputStreamPtr stream(Mapa::getMapStream(files[start].getName()));
TInputStreamPtr stream(CMap::getMapStream(files[start].getName()));
int read = stream->read(mapBuffer, 1500);
if(read < 50 || !mapBuffer[4])
@ -1360,16 +1360,16 @@ void SelectionTab::printMaps(SDL_Surface *to)
int temp=-1;
switch (currentItem->mapHeader->version)
{
case CMapHeader::RoE:
case EMapFormat::ROE:
temp=0;
break;
case CMapHeader::AB:
case EMapFormat::AB:
temp=1;
break;
case CMapHeader::SoD:
case EMapFormat::SOD:
temp=2;
break;
case CMapHeader::WoG:
case EMapFormat::WOG:
temp=3;
break;
default:

View File

@ -34,39 +34,39 @@ extern SDL_Surface * screen;
std::string nameFromType (int typ)
{
switch(static_cast<TerrainTile::EterrainType>(typ))
switch(static_cast<ETerrainType::ETerrainType>(typ))
{
case TerrainTile::dirt:
case ETerrainType::DIRT:
return std::string("DIRTTL.DEF");
case TerrainTile::sand:
case ETerrainType::SAND:
return std::string("SANDTL.DEF");
case TerrainTile::grass:
case ETerrainType::GRASS:
return std::string("GRASTL.DEF");
case TerrainTile::snow:
case ETerrainType::SNOW:
return std::string("SNOWTL.DEF");
case TerrainTile::swamp:
case ETerrainType::SWAMP:
return std::string("SWMPTL.DEF");
case TerrainTile::rough:
case ETerrainType::ROUGH:
return std::string("ROUGTL.DEF");
case TerrainTile::subterranean:
case ETerrainType::SUBTERRANEAN:
return std::string("SUBBTL.DEF");
case TerrainTile::lava:
case ETerrainType::LAVA:
return std::string("LAVATL.DEF");
case TerrainTile::water:
case ETerrainType::WATER:
return std::string("WATRTL.DEF");
case TerrainTile::rock:
case ETerrainType::ROCK:
return std::string("ROCKTL.DEF");
case TerrainTile::border:
case ETerrainType::BORDER:
//TODO use me
break;
default:
@ -378,7 +378,7 @@ void CMapHandler::init()
}
}
std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs
std::for_each(map->customDefs.begin(),map->customDefs.end(),processDef); //load h3m defs
tlog0<<"\tUnpacking and handling defs: "<<th.getDiff()<<std::endl;
//it seems to be completely unnecessary and useless
@ -504,27 +504,27 @@ void CMapHandler::terrainRect( int3 top_tile, ui8 anim, const std::vector< std::
}
else //use default terrain graphic
{
blitterWithRotation(terrainGraphics[tinfo.tertype][tinfo.terview],rtile, extSurf, sr, tinfo.siodmyTajemniczyBajt%4);
blitterWithRotation(terrainGraphics[tinfo.tertype][tinfo.terview],rtile, extSurf, sr, tinfo.extTileFlags%4);
}
if(tinfo.nuine) //print river if present
if(tinfo.riverType) //print river if present
{
blitterWithRotationAndAlpha(staticRiverDefs[tinfo.nuine-1]->ourImages[tinfo.rivDir].bitmap,rtile, extSurf, sr, (tinfo.siodmyTajemniczyBajt>>2)%4);
blitterWithRotationAndAlpha(staticRiverDefs[tinfo.riverType-1]->ourImages[tinfo.riverDir].bitmap,rtile, extSurf, sr, (tinfo.extTileFlags>>2)%4);
}
//Roads are shifted by 16 pixels to bottom. We have to draw both parts separately
if (pos.y > 0 && map->terrain[pos.x][pos.y-1][pos.z].malle)
if (pos.y > 0 && map->terrain[pos.x][pos.y-1][pos.z].roadType)
{ //part from top tile
const TerrainTile &topTile = map->terrain[pos.x][pos.y-1][pos.z];
Rect source(0, 16, 32, 16);
Rect dest(sr.x, sr.y, sr.w, sr.h/2);
blitterWithRotationAndAlpha(roadDefs[topTile.malle-1]->ourImages[topTile.roadDir].bitmap, source, extSurf, dest, (topTile.siodmyTajemniczyBajt>>4)%4);
blitterWithRotationAndAlpha(roadDefs[topTile.roadType-1]->ourImages[topTile.roadDir].bitmap, source, extSurf, dest, (topTile.extTileFlags>>4)%4);
}
if(tinfo.malle) //print road from this tile
if(tinfo.roadType) //print road from this tile
{
Rect source(0, 0, 32, 32);
Rect dest(sr.x, sr.y+16, sr.w, sr.h/2);
blitterWithRotationAndAlpha(roadDefs[tinfo.malle-1]->ourImages[tinfo.roadDir].bitmap, source, extSurf, dest, (tinfo.siodmyTajemniczyBajt>>4)%4);
blitterWithRotationAndAlpha(roadDefs[tinfo.roadType-1]->ourImages[tinfo.roadDir].bitmap, source, extSurf, dest, (tinfo.extTileFlags>>4)%4);
}
//blit objects

View File

@ -15,7 +15,7 @@
class CGObjectInstance;
class CGHeroInstance;
struct Mapa;
struct CMap;
class CGDefInfo;
class CGObjectInstance;
class CDefHandler;
@ -73,7 +73,7 @@ class CMapHandler
public:
PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles; //informations about map tiles
int3 sizes; //map size (x = width, y = height, z = number of levels)
const Mapa * map;
const CMap * map;
// Max number of tiles that will fit in the map screen. Tiles
// can be partial on each edges.

View File

@ -465,7 +465,7 @@ int CGameState::pickHero(int owner)
{
int h=-1;
const PlayerSettings &ps = scenarioOps->getIthPlayersSettings(owner);
if(!map->getHero(h = ps.hero,0) && h>=0) //we haven't used selected hero
if(!map->getHero(h = ps.hero) && h>=0) //we haven't used selected hero
return h;
if(scenarioOps->mode == StartInfo::CAMPAIGN)
@ -699,7 +699,7 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
cur->ID = ran.first;
cur->subID = ran.second;
map->removeBlockVisTiles(cur); //recalculate blockvis tiles - picked object might have different than random placeholder
map->defy.push_back(cur->defInfo = VLC->dobjinfo->gobjs[ran.first][ran.second]);
map->customDefs.push_back(cur->defInfo = VLC->dobjinfo->gobjs[ran.first][ran.second]);
if(!cur->defInfo)
{
tlog1<<"*BIG* WARNING: Missing def declaration for "<<cur->ID<<" "<<cur->subID<<std::endl;
@ -771,7 +771,7 @@ BattleInfo * CGameState::setupBattle(int3 tile, const CArmedInstance *armies[2],
const TerrainTile &t = map->getTile(tile);
int terrain = t.tertype;
if(t.isCoastal() && !t.isWater())
terrain = TerrainTile::sand;
terrain = ETerrainType::SAND;
int terType = battleGetBattlefieldType(tile);
return BattleInfo::setupBattle(tile, terrain, terType, armies, heroes, creatureBank, town);
@ -865,7 +865,7 @@ void CGameState::init(StartInfo * si)
switch(scenarioOps->mode)
{
case StartInfo::NEW_GAME:
map = new Mapa(scenarioOps->mapname);
map = new CMap(scenarioOps->mapname);
break;
case StartInfo::CAMPAIGN:
{
@ -873,7 +873,7 @@ void CGameState::init(StartInfo * si)
assert(vstd::contains(campaign->camp->mapPieces, scenarioOps->campState->currentMap));
std::string &mapContent = campaign->camp->mapPieces[scenarioOps->campState->currentMap];
map = new Mapa();
map = new CMap();
map->initFromBytes((const ui8*)mapContent.c_str(), mapContent.size());
}
break;
@ -926,8 +926,8 @@ void CGameState::init(StartInfo * si)
const TerrainTile &t = map->terrain[i][j][k];
if(!t.blocked
&& !t.visitable
&& t.tertype != TerrainTile::water
&& t.tertype != TerrainTile::rock
&& t.tertype != ETerrainType::WATER
&& t.tertype != ETerrainType::ROCK
&& map->grailPos.dist2d(int3(i,j,k)) <= map->grailRadious)
allowedPos.push_back(int3(i,j,k));
}
@ -974,7 +974,7 @@ void CGameState::init(StartInfo * si)
{
int3 pos = obj->pos - int3(i,j,0);
if(map->isInTheMap(pos))
map->getTile(pos).siodmyTajemniczyBajt |= 128;
map->getTile(pos).extTileFlags |= 128;
}
}
//std::cout<<"\tRandomizing objects: "<<th.getDif()<<std::endl;
@ -1669,25 +1669,25 @@ int CGameState::battleGetBattlefieldType(int3 tile) const
switch(t.tertype)
{
case TerrainTile::dirt:
case ETerrainType::DIRT:
return rand()%3+3;
case TerrainTile::sand:
case ETerrainType::SAND:
return 2; //TODO: coast support
case TerrainTile::grass:
case ETerrainType::GRASS:
return rand()%2+6;
case TerrainTile::snow:
case ETerrainType::SNOW:
return rand()%2+10;
case TerrainTile::swamp:
case ETerrainType::SWAMP:
return 13;
case TerrainTile::rough:
case ETerrainType::ROUGH:
return 23;
case TerrainTile::subterranean:
case ETerrainType::SUBTERRANEAN:
return 12;
case TerrainTile::lava:
case ETerrainType::LAVA:
return 8;
case TerrainTile::water:
case ETerrainType::WATER:
return 25;
case TerrainTile::rock:
case ETerrainType::ROCK:
return 15;
default:
return -1;
@ -1794,9 +1794,9 @@ void CGameState::loadTownDInfos()
capitols[town.first] = new CGDefInfo(*townInfos[town.first]);
capitols[town.first]->name = town.second.clientInfo.advMapCapitol;
map->defy.push_back(villages[town.first]);
map->defy.push_back(forts[town.first]);
map->defy.push_back(capitols[town.first]);
map->customDefs.push_back(villages[town.first]);
map->customDefs.push_back(forts[town.first]);
map->customDefs.push_back(capitols[town.first]);
}
}
@ -1819,19 +1819,19 @@ void CGameState::getNeighbours(const TerrainTile &srct, int3 tile, std::vector<i
// continue;
// }
if(srct.tertype == TerrainTile::water && limitCoastSailing && hlpt.tertype == TerrainTile::water && dirs[i].x && dirs[i].y) //diagonal move through water
if(srct.tertype == ETerrainType::WATER && limitCoastSailing && hlpt.tertype == ETerrainType::WATER && dirs[i].x && dirs[i].y) //diagonal move through water
{
int3 hlp1 = tile,
hlp2 = tile;
hlp1.x += dirs[i].x;
hlp2.y += dirs[i].y;
if(map->getTile(hlp1).tertype != TerrainTile::water || map->getTile(hlp2).tertype != TerrainTile::water)
if(map->getTile(hlp1).tertype != ETerrainType::WATER || map->getTile(hlp2).tertype != ETerrainType::WATER)
continue;
}
if((indeterminate(onLand) || onLand == (hlpt.tertype!=TerrainTile::water) )
&& hlpt.tertype != TerrainTile::rock)
if((indeterminate(onLand) || onLand == (hlpt.tertype!=ETerrainType::WATER) )
&& hlpt.tertype != ETerrainType::ROCK)
{
vec.push_back(hlp);
}
@ -1858,7 +1858,7 @@ int CGameState::getMovementCost(const CGHeroInstance *h, const int3 &src, const
ret *= 1.4; //40% penalty for movement over blocked tile
}
}
else if (d.tertype == TerrainTile::water)
else if (d.tertype == ETerrainType::WATER)
{
if(h->boat && s.hasFavourableWinds() && d.hasFavourableWinds()) //Favourable Winds
ret *= 0.666;
@ -1882,7 +1882,7 @@ int CGameState::getMovementCost(const CGHeroInstance *h, const int3 &src, const
if(checkLast && left > 0 && remainingMovePoints-ret < 250) //it might be the last tile - if no further move possible we take all move points
{
std::vector<int3> vec;
getNeighbours(d, dest, vec, s.tertype != TerrainTile::water, true);
getNeighbours(d, dest, vec, s.tertype != ETerrainType::WATER, true);
for(size_t i=0; i < vec.size(); i++)
{
int fcost = getMovementCost(h,dest,vec[i],left,false);
@ -1952,7 +1952,7 @@ int3 CGameState::guardingCreaturePosition (int3 pos) const
if (map->isInTheMap(pos))
{
TerrainTile &tile = map->terrain[pos.x][pos.y][pos.z];
if (tile.visitable && (tile.tertype == TerrainTile::water) == (posTile.tertype == TerrainTile::water))
if (tile.visitable && (tile.tertype == ETerrainType::WATER) == (posTile.tertype == ETerrainType::WATER))
{
BOOST_FOREACH (CGObjectInstance* obj, tile.visitableObjects)
{
@ -2809,7 +2809,7 @@ DuelParameters::SideSettings::SideSettings()
DuelParameters::DuelParameters()
{
terType = TerrainTile::dirt;
terType = ETerrainType::DIRT;
bfieldType = 15;
}
@ -2928,7 +2928,7 @@ void CPathfinder::initializeGraph()
node.coord.x = i;
node.coord.y = j;
node.coord.z = k;
node.land = tinfo->tertype != TerrainTile::water;
node.land = tinfo->tertype != ETerrainType::WATER;
node.theNodeBefore = NULL;
}
}
@ -3101,7 +3101,7 @@ CGPathNode::EAccessibility CPathfinder::evaluateAccessibility(const TerrainTile
CGPathNode::EAccessibility ret = (tinfo->blocked ? CGPathNode::BLOCKED : CGPathNode::ACCESSIBLE);
if(tinfo->tertype == TerrainTile::rock || !FoW[curPos.x][curPos.y][curPos.z])
if(tinfo->tertype == ETerrainType::ROCK || !FoW[curPos.x][curPos.y][curPos.z])
return CGPathNode::BLOCKED;
if(tinfo->visitable)

View File

@ -44,7 +44,7 @@ class CGDefInfo;
class CObjectScript;
class CGObjectInstance;
class CCreature;
struct Mapa;
struct CMap;
struct StartInfo;
struct SDL_Surface;
class CMapHandler;
@ -386,7 +386,7 @@ public:
ui8 currentPlayer; //ID of player currently having turn
ConstTransitivePtr<BattleInfo> curB; //current battle
ui32 day; //total number of days in game
ConstTransitivePtr<Mapa> map;
ConstTransitivePtr<CMap> map;
bmap<TPlayerColor, PlayerState> players;
bmap<TPlayerColor, TeamState> teams;
bmap<TPlayerColor, ConstTransitivePtr<CGDefInfo> > villages, forts, capitols; //def-info for town graphics
@ -461,7 +461,7 @@ public:
friend class CCallback;
friend class CLuaCallback;
friend class CClient;
friend void initGameState(Mapa * map, CGameInfo * cgi);
friend void initGameState(CMap * map, CGameInfo * cgi);
friend class IGameCallback;
friend class CMapHandler;
friend class CGameHandler;

View File

@ -38,7 +38,7 @@ void CMapInfo::mapInit(const std::string &fname, const ui8 *map )
fileURI = fname;
int i = 0;
mapHeader = new CMapHeader();
mapHeader->version = CMapHeader::invalid;
mapHeader->version = EMapFormat::INVALID;
try
{

View File

@ -530,18 +530,18 @@ ui32 CGHeroInstance::getTileCost(const TerrainTile &dest, const TerrainTile &fro
unsigned ret = 100;
//if there is road both on dest and src tiles - use road movement cost
if(dest.malle && from.malle)
if(dest.roadType && from.roadType)
{
int road = std::min(dest.malle,from.malle); //used road ID
int road = std::min(dest.roadType,from.roadType); //used road ID
switch(road)
{
case TerrainTile::dirtRoad:
case ERoadType::DIRT_ROAD:
ret = 75;
break;
case TerrainTile::grazvelRoad:
case ERoadType::GRAVEL_ROAD:
ret = 65;
break;
case TerrainTile::cobblestoneRoad:
case ERoadType::COBBLESTONE_ROAD:
ret = 50;
break;
default:
@ -1502,7 +1502,7 @@ CGHeroInstance::ECanDig CGHeroInstance::diggingStatus() const
{
if(movement < maxMovePoints(true))
return LACK_OF_MOVEMENT;
else if(cb->getTile(getPosition(false))->tertype == TerrainTile::water)
else if(cb->getTile(getPosition(false))->tertype == ETerrainType::WATER)
return WRONG_TERRAIN;
else
{
@ -6530,7 +6530,7 @@ int3 IBoatGenerator::bestLocation() const
{
if (const TerrainTile *tile = IObjectInterface::cb->getTile(o->pos + offsets[i], false)) //tile is in the map
{
if (tile->tertype == TerrainTile::water && (!tile->blocked || tile->blockingObjects.front()->ID == 8)) //and is water and is not blocked or is blocked by boat
if (tile->tertype == ETerrainType::WATER && (!tile->blocked || tile->blockingObjects.front()->ID == 8)) //and is water and is not blocked or is blocked by boat
return o->pos + offsets[i];
}
}

View File

@ -430,9 +430,9 @@ bool CGameInfoCallback::verifyPath(CPath * path, bool blockSea) const
continue;
const TerrainTile *prev = getTile(path->nodes[i-1].coord); //tile of previous node on the path
if (( t->tertype == TerrainTile::water && prev->tertype != TerrainTile::water)
|| (t->tertype != TerrainTile::water && prev->tertype == TerrainTile::water)
|| prev->tertype == TerrainTile::rock
if (( t->tertype == ETerrainType::WATER && prev->tertype != ETerrainType::WATER)
|| (t->tertype != ETerrainType::WATER && prev->tertype == ETerrainType::WATER)
|| prev->tertype == ETerrainType::ROCK
)
return false;
}
@ -594,7 +594,7 @@ int CGameInfoCallback::canBuildStructure( const CGTownInstance *t, int ID )
{
const TerrainTile *tile = getTile(t->bestLocation(), false);
if(!tile || tile->tertype != TerrainTile::water )
if(!tile || tile->tertype != ETerrainType::WATER)
return EBuildingState::NO_WATER; //lack of water
}

File diff suppressed because it is too large Load Diff

1036
lib/map.h

File diff suppressed because it is too large Load Diff

View File

@ -1229,7 +1229,7 @@ void CGameHandler::newTurn()
NewTurn::Hero hth;
hth.id = h->id;
hth.move = h->maxMovePoints(gs->map->getTile(h->getPosition(false)).tertype != TerrainTile::water);
hth.move = h->maxMovePoints(gs->map->getTile(h->getPosition(false)).tertype != ETerrainType::WATER);
if(h->visitedTown && h->visitedTown->hasBuilt(EBuilding::MAGES_GUILD_1)) //if hero starts turn in town with mage guild
hth.mana = std::max(h->mana, h->manaLimit()); //restore all mana
@ -1671,11 +1671,11 @@ bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255*
//it's a rock or blocked and not visitable tile
//OR hero is on land and dest is water and (there is not present only one object - boat)
if(((t.tertype == TerrainTile::rock || (t.blocked && !t.visitable && !h->hasBonusOfType(Bonus::FLYING_MOVEMENT) ))
if(((t.tertype == ETerrainType::ROCK || (t.blocked && !t.visitable && !h->hasBonusOfType(Bonus::FLYING_MOVEMENT) ))
&& complain("Cannot move hero, destination tile is blocked!"))
|| ((!h->boat && !h->canWalkOnSea() && t.tertype == TerrainTile::water && (t.visitableObjects.size() < 1 || (t.visitableObjects.back()->ID != 8 && t.visitableObjects.back()->ID != Obj::HERO))) //hero is not on boat/water walking and dst water tile doesn't contain boat/hero (objs visitable from land) -> we test back cause boat may be on top of another object (#276)
|| ((!h->boat && !h->canWalkOnSea() && t.tertype == ETerrainType::WATER && (t.visitableObjects.size() < 1 || (t.visitableObjects.back()->ID != 8 && t.visitableObjects.back()->ID != Obj::HERO))) //hero is not on boat/water walking and dst water tile doesn't contain boat/hero (objs visitable from land) -> we test back cause boat may be on top of another object (#276)
&& complain("Cannot move hero, destination tile is on water!"))
|| ((h->boat && t.tertype != TerrainTile::water && t.blocked)
|| ((h->boat && t.tertype != ETerrainType::WATER && t.blocked)
&& complain("Cannot disembark hero, tile is blocked!"))
|| ((h->movement < cost && dst != h->pos && !instant)
&& complain("Hero doesn't have any movement points left!"))
@ -1697,7 +1697,7 @@ bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255*
return true;
}
//hero leaves the boat
else if(h->boat && t.tertype != TerrainTile::water && !t.blocked)
else if(h->boat && t.tertype != ETerrainType::WATER && !t.blocked)
{
//TODO? code similarity with the block above
tmh.result = TryMoveHero::DISEMBARK;