mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-03 00:46:55 +02:00
[refactor] a few more cleanups
This commit is contained in:
@ -162,16 +162,17 @@ DLL_LINKAGE void FoWChange::applyGs( CGameState *gs )
|
|||||||
boost::unordered_set<int3, ShashInt3> tilesRevealed;
|
boost::unordered_set<int3, ShashInt3> tilesRevealed;
|
||||||
for (size_t i = 0; i < gs->map->objects.size(); i++)
|
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 Obj::HERO:
|
||||||
case 53://mine
|
case Obj::MINE:
|
||||||
case 98://town
|
case Obj::TOWN:
|
||||||
case 220:
|
case Obj::ABANDONED_MINE:
|
||||||
if(vstd::contains(team->players, gs->map->objects[i]->tempOwner)) //check owned observators
|
if(vstd::contains(team->players, o->tempOwner)) //check owned observators
|
||||||
gs->map->objects[i]->getSightTiles(tilesRevealed);
|
o->getSightTiles(tilesRevealed);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -523,10 +524,10 @@ DLL_LINKAGE void NewObject::applyGs( CGameState *gs )
|
|||||||
CGObjectInstance *o = NULL;
|
CGObjectInstance *o = NULL;
|
||||||
switch(ID)
|
switch(ID)
|
||||||
{
|
{
|
||||||
case 8:
|
case Obj::BOAT:
|
||||||
o = new CGBoat();
|
o = new CGBoat();
|
||||||
break;
|
break;
|
||||||
case 54: //probably more options will be needed
|
case Obj::MONSTER: //probably more options will be needed
|
||||||
o = new CGCreature();
|
o = new CGCreature();
|
||||||
{
|
{
|
||||||
//CStackInstance hlp;
|
//CStackInstance hlp;
|
||||||
@ -552,11 +553,11 @@ DLL_LINKAGE void NewObject::applyGs( CGameState *gs )
|
|||||||
|
|
||||||
switch(ID)
|
switch(ID)
|
||||||
{
|
{
|
||||||
case 54: //cfreature
|
case Obj::MONSTER:
|
||||||
o->defInfo = VLC->dobjinfo->gobjs[ID][subID];
|
o->defInfo = VLC->dobjinfo->gobjs[ID][subID];
|
||||||
assert(o->defInfo);
|
assert(o->defInfo);
|
||||||
break;
|
break;
|
||||||
case 124://hole
|
case Obj::HOLE:
|
||||||
const TerrainTile &t = gs->map->getTile(pos);
|
const TerrainTile &t = gs->map->getTile(pos);
|
||||||
o->defInfo = VLC->dobjinfo->gobjs[ID][t.terType];
|
o->defInfo = VLC->dobjinfo->gobjs[ID][t.terType];
|
||||||
assert(o->defInfo);
|
assert(o->defInfo);
|
||||||
@ -1403,11 +1404,11 @@ DLL_LINKAGE void ObstaclesRemoved::applyGs( CGameState *gs )
|
|||||||
{
|
{
|
||||||
if(gs->curB) //if there is a battle
|
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)
|
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);
|
gs->curB->obstacles.erase(gs->curB->obstacles.begin() + i);
|
||||||
break;
|
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
|
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] =
|
gs->curB->si.wallState[it.first.first] =
|
||||||
std::min( gs->curB->si.wallState[it->first.first] + it->second, 3 );
|
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)
|
if(!gs->curB)
|
||||||
return;
|
return;
|
||||||
|
BOOST_FOREACH(ui32 rem_stack, stackIDs)
|
||||||
for(std::set<ui32>::const_iterator it = stackIDs.begin(); it != stackIDs.end(); ++it) //for each removed stack
|
|
||||||
{
|
{
|
||||||
for(int b=0; b<gs->curB->stacks.size(); ++b) //find it in vector of stacks
|
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];
|
CStack *toRemove = gs->curB->stacks[b];
|
||||||
gs->curB->stacks.erase(gs->curB->stacks.begin() + b); //remove
|
gs->curB->stacks.erase(gs->curB->stacks.begin() + b); //remove
|
||||||
|
@ -4961,8 +4961,12 @@ bool CGameHandler::buildBoat( ui32 objid )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO use "real" cost via obj->getBoatCost
|
const TPlayerColor playerID = obj->o->tempOwner;
|
||||||
if(getResource(obj->o->tempOwner, Res::GOLD) < 1000 || getResource(obj->o->tempOwner, Res::WOOD) < 10)
|
TResources boatCost;
|
||||||
|
obj->getBoatCost(boatCost);
|
||||||
|
TResources aviable = gs->getPlayer(playerID)->resources;
|
||||||
|
|
||||||
|
if (!aviable.canAfford(boatCost))
|
||||||
{
|
{
|
||||||
complain("Not enough resources to build a boat!");
|
complain("Not enough resources to build a boat!");
|
||||||
return false;
|
return false;
|
||||||
@ -4977,15 +4981,13 @@ bool CGameHandler::buildBoat( ui32 objid )
|
|||||||
|
|
||||||
//take boat cost
|
//take boat cost
|
||||||
SetResources sr;
|
SetResources sr;
|
||||||
sr.player = obj->o->tempOwner;
|
sr.player = playerID;
|
||||||
sr.res = gs->getPlayer(obj->o->tempOwner)->resources;
|
sr.res = (aviable - boatCost);
|
||||||
sr.res[Res::WOOD] -= 10;
|
|
||||||
sr.res[Res::GOLD] -= 1000;
|
|
||||||
sendAndApply(&sr);
|
sendAndApply(&sr);
|
||||||
|
|
||||||
//create boat
|
//create boat
|
||||||
NewObject no;
|
NewObject no;
|
||||||
no.ID = 8;
|
no.ID = Obj::BOAT;
|
||||||
no.subID = obj->getBoatType();
|
no.subID = obj->getBoatType();
|
||||||
no.pos = tile + int3(1,0,0);
|
no.pos = tile + int3(1,0,0);
|
||||||
sendAndApply(&no);
|
sendAndApply(&no);
|
||||||
|
Reference in New Issue
Block a user