From 708705aa960baf21335cbed31108b9619687a87c Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Thu, 1 Nov 2018 23:31:23 +0300 Subject: [PATCH] CGLighthouse: workaround crash on map initialization. Fix issue 3020 Dirty hack here since proper fix would require to break saves --- lib/mapObjects/MiscObjects.cpp | 14 +++++++++++--- lib/mapObjects/MiscObjects.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 26e40609d..6ffd38f21 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -2161,7 +2161,8 @@ void CGLighthouse::initObj(CRandomGenerator & rand) { if(tempOwner < PlayerColor::PLAYER_LIMIT) { - giveBonusTo(tempOwner); + // FIXME: This is dirty hack + giveBonusTo(tempOwner, true); } } @@ -2171,7 +2172,7 @@ std::string CGLighthouse::getHoverText(PlayerColor player) const return getObjectName(); } -void CGLighthouse::giveBonusTo( PlayerColor player ) const +void CGLighthouse::giveBonusTo(PlayerColor player, bool onInit) const { GiveBonus gb(GiveBonus::PLAYER); gb.bonus.type = Bonus::SEA_MOVEMENT; @@ -2180,7 +2181,14 @@ void CGLighthouse::giveBonusTo( PlayerColor player ) const gb.bonus.duration = Bonus::PERMANENT; gb.bonus.source = Bonus::OBJECT; gb.bonus.sid = id.getNum(); - cb->sendAndApply(&gb); + + // FIXME: This is really dirty hack + // Proper fix would be to make CGLighthouse into bonus system node + // Unfortunately this will cause saves breakage + if(onInit) + gb.applyGs(cb->gameState()); + else + cb->sendAndApply(&gb); } void CGLighthouse::serializeJsonOptions(JsonSerializeFormat& handler) diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index 3cc222244..5a02b07f9 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -523,7 +523,7 @@ public: { h & static_cast(*this); } - void giveBonusTo( PlayerColor player ) const; + void giveBonusTo(PlayerColor player, bool onInit = false) const; protected: void serializeJsonOptions(JsonSerializeFormat & handler) override; };