mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Boat as bonus system node
This commit is contained in:
@@ -1176,6 +1176,7 @@ void RemoveObject::applyGs(CGameState *gs)
|
|||||||
//If hero on Boat is removed, the Boat disappears
|
//If hero on Boat is removed, the Boat disappears
|
||||||
if(beatenHero->boat)
|
if(beatenHero->boat)
|
||||||
{
|
{
|
||||||
|
beatenHero->detachFrom(const_cast<CGBoat&>(*beatenHero->boat));
|
||||||
gs->map->instanceNames.erase(beatenHero->boat->instanceName);
|
gs->map->instanceNames.erase(beatenHero->boat->instanceName);
|
||||||
gs->map->objects[beatenHero->boat->id.getNum()].dellNull();
|
gs->map->objects[beatenHero->boat->id.getNum()].dellNull();
|
||||||
beatenHero->boat = nullptr;
|
beatenHero->boat = nullptr;
|
||||||
@@ -1291,6 +1292,7 @@ void TryMoveHero::applyGs(CGameState *gs)
|
|||||||
|
|
||||||
gs->map->removeBlockVisTiles(boat); //hero blockvis mask will be used, we don't need to duplicate it with boat
|
gs->map->removeBlockVisTiles(boat); //hero blockvis mask will be used, we don't need to duplicate it with boat
|
||||||
h->boat = boat;
|
h->boat = boat;
|
||||||
|
h->attachTo(*boat);
|
||||||
boat->hero = h;
|
boat->hero = h;
|
||||||
}
|
}
|
||||||
else if(result == DISEMBARK) //hero leaves boat to destination tile
|
else if(result == DISEMBARK) //hero leaves boat to destination tile
|
||||||
@@ -1300,6 +1302,7 @@ void TryMoveHero::applyGs(CGameState *gs)
|
|||||||
b->pos = start;
|
b->pos = start;
|
||||||
b->hero = nullptr;
|
b->hero = nullptr;
|
||||||
gs->map->addBlockVisTiles(b);
|
gs->map->addBlockVisTiles(b);
|
||||||
|
h->detachFrom(*b);
|
||||||
h->boat = nullptr;
|
h->boat = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -268,6 +268,7 @@ void BoatInstanceConstructor::initTypeData(const JsonNode & input)
|
|||||||
overlayAnimation = input["overlayAnimation"].String();
|
overlayAnimation = input["overlayAnimation"].String();
|
||||||
for(int i = 0; i < flagAnimations.size() && i < input["flagAnimations"].Vector().size(); ++i)
|
for(int i = 0; i < flagAnimations.size() && i < input["flagAnimations"].Vector().size(); ++i)
|
||||||
flagAnimations[i] = input["flagAnimations"].Vector()[i].String();
|
flagAnimations[i] = input["flagAnimations"].Vector()[i].String();
|
||||||
|
bonuses = JsonRandom::loadBonuses(input["bonuses"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGObjectInstance * BoatInstanceConstructor::create(std::shared_ptr<const ObjectTemplate> tmpl) const
|
CGObjectInstance * BoatInstanceConstructor::create(std::shared_ptr<const ObjectTemplate> tmpl) const
|
||||||
@@ -277,6 +278,9 @@ CGObjectInstance * BoatInstanceConstructor::create(std::shared_ptr<const ObjectT
|
|||||||
boat->actualAnimation = actualAnimation;
|
boat->actualAnimation = actualAnimation;
|
||||||
boat->overlayAnimation = overlayAnimation;
|
boat->overlayAnimation = overlayAnimation;
|
||||||
boat->flagAnimations = flagAnimations;
|
boat->flagAnimations = flagAnimations;
|
||||||
|
for(auto & b : bonuses)
|
||||||
|
boat->addNewBonus(std::make_shared<Bonus>(b));
|
||||||
|
|
||||||
return boat;
|
return boat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,9 @@ class BoatInstanceConstructor : public CDefaultObjectTypeHandler<CGBoat>
|
|||||||
protected:
|
protected:
|
||||||
void initTypeData(const JsonNode & config) override;
|
void initTypeData(const JsonNode & config) override;
|
||||||
|
|
||||||
|
std::vector<Bonus> bonuses;
|
||||||
EPathfindingLayer layer;
|
EPathfindingLayer layer;
|
||||||
|
|
||||||
std::string actualAnimation; //for OH3 boats those have actual animations
|
std::string actualAnimation; //for OH3 boats those have actual animations
|
||||||
std::string overlayAnimation; //waves animations
|
std::string overlayAnimation; //waves animations
|
||||||
std::array<std::string, PlayerColor::PLAYER_LIMIT_I> flagAnimations;
|
std::array<std::string, PlayerColor::PLAYER_LIMIT_I> flagAnimations;
|
||||||
|
|||||||
@@ -312,8 +312,8 @@ namespace JsonRandom
|
|||||||
std::vector<Bonus> ret;
|
std::vector<Bonus> ret;
|
||||||
for (const JsonNode & entry : value.Vector())
|
for (const JsonNode & entry : value.Vector())
|
||||||
{
|
{
|
||||||
auto bonus = JsonUtils::parseBonus(entry);
|
if(auto bonus = JsonUtils::parseBonus(entry))
|
||||||
ret.push_back(*bonus);
|
ret.push_back(*bonus);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -414,7 +414,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class DLL_LINKAGE CGBoat : public CGObjectInstance
|
class DLL_LINKAGE CGBoat : public CGObjectInstance, public CBonusSystemNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ui8 direction;
|
ui8 direction;
|
||||||
@@ -438,9 +438,13 @@ public:
|
|||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
h & static_cast<CGObjectInstance&>(*this);
|
h & static_cast<CGObjectInstance&>(*this);
|
||||||
|
h & static_cast<CBonusSystemNode&>(*this);
|
||||||
h & direction;
|
h & direction;
|
||||||
h & hero;
|
h & hero;
|
||||||
h & layer;
|
h & layer;
|
||||||
|
h & actualAnimation;
|
||||||
|
h & overlayAnimation;
|
||||||
|
h & flagAnimations;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2266,8 +2266,8 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
|
|||||||
const bool embarking = !h->boat && !t.visitableObjects.empty() && t.visitableObjects.back()->ID == Obj::TRANSPORT;
|
const bool embarking = !h->boat && !t.visitableObjects.empty() && t.visitableObjects.back()->ID == Obj::TRANSPORT;
|
||||||
const bool disembarking = h->boat
|
const bool disembarking = h->boat
|
||||||
&& t.terType->isLand()
|
&& t.terType->isLand()
|
||||||
&& (h->boat->layer == EPathfindingLayer::SAIL || dst == h->pos)
|
&& (dst == h->pos
|
||||||
&& !t.blocked;
|
|| (h->boat->layer == EPathfindingLayer::SAIL && !t.blocked));
|
||||||
|
|
||||||
//result structure for start - movement failed, no move points used
|
//result structure for start - movement failed, no move points used
|
||||||
TryMoveHero tmh;
|
TryMoveHero tmh;
|
||||||
|
|||||||
Reference in New Issue
Block a user