1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Fourth part of sailing code.

Support for Shipyard (both for town and adventure map versions). Improved boat displaying code. Minor changes.
This commit is contained in:
Michał W. Urbańczyk
2009-07-26 03:33:13 +00:00
parent 7853a19b54
commit 9fd4b5bb62
23 changed files with 527 additions and 52 deletions

View File

@@ -662,7 +662,7 @@ void CGameHandler::newTurn()
{
NewTurn::Hero hth;
hth.id = h->id;
hth.move = h->maxMovePoints(true); //TODO: check if hero is really on the land
hth.move = h->maxMovePoints(gs->map->getTile(h->getPosition(false)).tertype != TerrainTile::water);
if(h->visitedTown && vstd::contains(h->visitedTown->builtBuildings,0)) //if hero starts turn in town with mage guild
hth.mana = h->manaLimit(); //restore all mana
@@ -2872,3 +2872,49 @@ void CGameHandler::objectVisited( const CGObjectInstance * obj, const CGHeroInst
{
obj->onHeroVisit(h);
}
bool CGameHandler::buildBoat( ui32 objid )
{
const IShipyard *obj = IShipyard::castFrom(getObj(objid));
if(obj->state())
{
complain("Cannot build boat in this shipyard!");
return false;
}
else if(obj->o->ID == TOWNI_TYPE
&& !vstd::contains((static_cast<const CGTownInstance*>(obj))->builtBuildings,6))
{
complain("Cannot build boat in the town - no shipyard!");
return false;
}
//TODO use "real" cost via obj->getBoatCost
if(getResource(obj->o->tempOwner, 6) < 1000 || getResource(obj->o->tempOwner, 0) < 10)
{
complain("Not enough resources to build a boat!");
return false;
}
int3 tile = obj->bestLocation();
if(!gs->map->isInTheMap(tile))
{
complain("Cannot find appropriate tile for a boat!");
return false;
}
//take boat cost
SetResources sr;
sr.player = obj->o->tempOwner;
sr.res = gs->getPlayer(obj->o->tempOwner)->resources;
sr.res[0] -= 10;
sr.res[6] -= 1000;
sendAndApply(&sr);
//create boat
NewObject no;
no.ID = 8;
no.subID = 1;
no.pos = tile + int3(1,0,0);
sendAndApply(&no);
}