1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

[refactor] a few more cleanups

This commit is contained in:
alexvins
2013-01-12 18:08:33 +00:00
parent f4ee750d64
commit 055e922e4d
2 changed files with 51 additions and 49 deletions

View File

@ -162,16 +162,17 @@ DLL_LINKAGE void FoWChange::applyGs( CGameState *gs )
boost::unordered_set<int3, ShashInt3> tilesRevealed;
for (size_t i = 0; i < gs->map->objects.size(); i++)
{
if (gs->map->objects[i])
const CGObjectInstance *o = gs->map->objects[i];
if (o)
{
switch(gs->map->objects[i]->ID)
switch(o->ID)
{
case 34://hero
case 53://mine
case 98://town
case 220:
if(vstd::contains(team->players, gs->map->objects[i]->tempOwner)) //check owned observators
gs->map->objects[i]->getSightTiles(tilesRevealed);
case Obj::HERO:
case Obj::MINE:
case Obj::TOWN:
case Obj::ABANDONED_MINE:
if(vstd::contains(team->players, o->tempOwner)) //check owned observators
o->getSightTiles(tilesRevealed);
break;
}
}
@ -523,10 +524,10 @@ DLL_LINKAGE void NewObject::applyGs( CGameState *gs )
CGObjectInstance *o = NULL;
switch(ID)
{
case 8:
case Obj::BOAT:
o = new CGBoat();
break;
case 54: //probably more options will be needed
case Obj::MONSTER: //probably more options will be needed
o = new CGCreature();
{
//CStackInstance hlp;
@ -552,11 +553,11 @@ DLL_LINKAGE void NewObject::applyGs( CGameState *gs )
switch(ID)
{
case 54: //cfreature
case Obj::MONSTER:
o->defInfo = VLC->dobjinfo->gobjs[ID][subID];
assert(o->defInfo);
break;
case 124://hole
case Obj::HOLE:
const TerrainTile &t = gs->map->getTile(pos);
o->defInfo = VLC->dobjinfo->gobjs[ID][t.terType];
assert(o->defInfo);
@ -1403,11 +1404,11 @@ DLL_LINKAGE void ObstaclesRemoved::applyGs( CGameState *gs )
{
if(gs->curB) //if there is a battle
{
for(std::set<si32>::const_iterator it = obstacles.begin(); it != obstacles.end(); ++it)
BOOST_FOREACH(const si32 rem_obst,obstacles)
{
for(int i=0; i<gs->curB->obstacles.size(); ++i)
{
if(gs->curB->obstacles[i]->uniqueID == *it) //remove this obstacle
if(gs->curB->obstacles[i]->uniqueID == rem_obst) //remove this obstacle
{
gs->curB->obstacles.erase(gs->curB->obstacles.begin() + i);
break;
@ -1421,10 +1422,10 @@ DLL_LINKAGE void CatapultAttack::applyGs( CGameState *gs )
{
if(gs->curB && gs->curB->siege != 0) //if there is a battle and it's a siege
{
for(std::set< std::pair< std::pair< ui8, si16 >, ui8> >::const_iterator it = attackedParts.begin(); it != attackedParts.end(); ++it)
BOOST_FOREACH(const auto &it,attackedParts)
{
gs->curB->si.wallState[it->first.first] =
std::min( gs->curB->si.wallState[it->first.first] + it->second, 3 );
gs->curB->si.wallState[it.first.first] =
std::min( gs->curB->si.wallState[it.first.first] + it.second, 3 );
}
}
}
@ -1433,12 +1434,11 @@ DLL_LINKAGE void BattleStacksRemoved::applyGs( CGameState *gs )
{
if(!gs->curB)
return;
for(std::set<ui32>::const_iterator it = stackIDs.begin(); it != stackIDs.end(); ++it) //for each removed stack
BOOST_FOREACH(ui32 rem_stack, stackIDs)
{
for(int b=0; b<gs->curB->stacks.size(); ++b) //find it in vector of stacks
{
if(gs->curB->stacks[b]->ID == *it) //if found
if(gs->curB->stacks[b]->ID == rem_stack) //if found
{
CStack *toRemove = gs->curB->stacks[b];
gs->curB->stacks.erase(gs->curB->stacks.begin() + b); //remove

View File

@ -4961,8 +4961,12 @@ bool CGameHandler::buildBoat( ui32 objid )
return false;
}
//TODO use "real" cost via obj->getBoatCost
if(getResource(obj->o->tempOwner, Res::GOLD) < 1000 || getResource(obj->o->tempOwner, Res::WOOD) < 10)
const TPlayerColor playerID = obj->o->tempOwner;
TResources boatCost;
obj->getBoatCost(boatCost);
TResources aviable = gs->getPlayer(playerID)->resources;
if (!aviable.canAfford(boatCost))
{
complain("Not enough resources to build a boat!");
return false;
@ -4977,15 +4981,13 @@ bool CGameHandler::buildBoat( ui32 objid )
//take boat cost
SetResources sr;
sr.player = obj->o->tempOwner;
sr.res = gs->getPlayer(obj->o->tempOwner)->resources;
sr.res[Res::WOOD] -= 10;
sr.res[Res::GOLD] -= 1000;
sr.player = playerID;
sr.res = (aviable - boatCost);
sendAndApply(&sr);
//create boat
NewObject no;
no.ID = 8;
no.ID = Obj::BOAT;
no.subID = obj->getBoatType();
no.pos = tile + int3(1,0,0);
sendAndApply(&no);