1
0
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:
nordsoft
2023-04-19 01:11:51 +04:00
parent d1dacd45e2
commit 22da7a931d
6 changed files with 18 additions and 5 deletions

View File

@@ -1176,6 +1176,7 @@ void RemoveObject::applyGs(CGameState *gs)
//If hero on Boat is removed, the Boat disappears
if(beatenHero->boat)
{
beatenHero->detachFrom(const_cast<CGBoat&>(*beatenHero->boat));
gs->map->instanceNames.erase(beatenHero->boat->instanceName);
gs->map->objects[beatenHero->boat->id.getNum()].dellNull();
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
h->boat = boat;
h->attachTo(*boat);
boat->hero = h;
}
else if(result == DISEMBARK) //hero leaves boat to destination tile
@@ -1300,6 +1302,7 @@ void TryMoveHero::applyGs(CGameState *gs)
b->pos = start;
b->hero = nullptr;
gs->map->addBlockVisTiles(b);
h->detachFrom(*b);
h->boat = nullptr;
}

View File

@@ -268,6 +268,7 @@ void BoatInstanceConstructor::initTypeData(const JsonNode & input)
overlayAnimation = input["overlayAnimation"].String();
for(int i = 0; i < flagAnimations.size() && i < input["flagAnimations"].Vector().size(); ++i)
flagAnimations[i] = input["flagAnimations"].Vector()[i].String();
bonuses = JsonRandom::loadBonuses(input["bonuses"]);
}
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->overlayAnimation = overlayAnimation;
boat->flagAnimations = flagAnimations;
for(auto & b : bonuses)
boat->addNewBonus(std::make_shared<Bonus>(b));
return boat;
}

View File

@@ -145,7 +145,9 @@ class BoatInstanceConstructor : public CDefaultObjectTypeHandler<CGBoat>
protected:
void initTypeData(const JsonNode & config) override;
std::vector<Bonus> bonuses;
EPathfindingLayer layer;
std::string actualAnimation; //for OH3 boats those have actual animations
std::string overlayAnimation; //waves animations
std::array<std::string, PlayerColor::PLAYER_LIMIT_I> flagAnimations;

View File

@@ -312,8 +312,8 @@ namespace JsonRandom
std::vector<Bonus> ret;
for (const JsonNode & entry : value.Vector())
{
auto bonus = JsonUtils::parseBonus(entry);
ret.push_back(*bonus);
if(auto bonus = JsonUtils::parseBonus(entry))
ret.push_back(*bonus);
}
return ret;
}

View File

@@ -414,7 +414,7 @@ public:
}
};
class DLL_LINKAGE CGBoat : public CGObjectInstance
class DLL_LINKAGE CGBoat : public CGObjectInstance, public CBonusSystemNode
{
public:
ui8 direction;
@@ -438,9 +438,13 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CGObjectInstance&>(*this);
h & static_cast<CBonusSystemNode&>(*this);
h & direction;
h & hero;
h & layer;
h & actualAnimation;
h & overlayAnimation;
h & flagAnimations;
}
};

View File

@@ -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 disembarking = h->boat
&& t.terType->isLand()
&& (h->boat->layer == EPathfindingLayer::SAIL || dst == h->pos)
&& !t.blocked;
&& (dst == h->pos
|| (h->boat->layer == EPathfindingLayer::SAIL && !t.blocked));
//result structure for start - movement failed, no move points used
TryMoveHero tmh;