Przeglądaj źródła

- Set fixed boat type for Tavern / Prison
- Move magical boat offset to static function

Tomasz Zieliński 2 lat temu
rodzic
commit
adec58f5bf

+ 0 - 11
lib/CHeroHandler.cpp

@@ -102,17 +102,6 @@ std::string CHero::getSpecialtyTooltipTextID() const
 	return TextIdentifier("hero", modScope, identifier, "specialty", "tooltip").get();
 }
 
-BoatId CHero::getBoatType() const
-{
-	switch(heroClass->getAlignment())
-	{
-		case EAlignment::EVIL : return EBoatId::BOAT_EVIL;
-		case EAlignment::GOOD : return EBoatId::BOAT_GOOD;
-		case EAlignment::NEUTRAL : return EBoatId::BOAT_NEUTRAL;
-		default: return EBoatId::NONE;
-	}
-}
-
 void CHero::registerIcons(const IconRegistar & cb) const
 {
 	cb(getIconIndex(), 0, "UN32", iconSpecSmall);

+ 0 - 2
lib/CHeroHandler.h

@@ -99,8 +99,6 @@ public:
 	std::string getSpecialtyDescriptionTextID() const override;
 	std::string getSpecialtyTooltipTextID() const override;
 
-	BoatId getBoatType() const;
-
 	void updateFrom(const JsonNode & data);
 	void serializeJson(JsonSerializeFormat & handler);
 

+ 1 - 1
lib/NetPacksLib.cpp

@@ -1497,7 +1497,7 @@ void NewObject::applyGs(CGameState *gs)
 		testObject.pos = pos;
 		testObject.appearance = VLC->objtypeh->getHandlerFor(ID, subID)->getTemplates(ETerrainId::WATER).front();
 
-		[[maybe_unused]] const int3 previousXAxisTile = int3(pos.x - 1, pos.y, pos.z);
+		[[maybe_unused]] const int3 previousXAxisTile = CGBoat::translatePos(pos, true);
 		assert(gs->isInTheMap(previousXAxisTile) && (testObject.visitablePos() == previousXAxisTile));
 	}
 	else

+ 12 - 6
lib/mapObjects/CGHeroInstance.cpp

@@ -446,19 +446,19 @@ void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
 			cb->setManaPoints (id, manaLimit());		
 			
 			ObjectInstanceID boatId;
-			if (cb->gameState()->map->getTile(pos).isWater())
+			const auto boatPos = visitablePos();
+			if (cb->gameState()->map->getTile(boatPos).isWater())
 			{
 				smp.val = maxMovePoints(false);
 				//Create a new boat for hero
 				NewObject no;
 				no.ID = Obj::BOAT;
-				no.subID = getBoatType().getNum();
-				no.pos = pos + int3(1,0,0); //FIXME: handle this magic offset somehow
+				no.subID = BoatId(EBoatId::BOAT_NEUTRAL);
+				no.pos = CGBoat::translatePos(boatPos);
 				
 				cb->sendAndApply(&no);
 
-				cb->getVisitableObjs(pos);
-				boatId = cb->getTopObj(pos)->id;
+				boatId = cb->getTopObj(boatPos)->id;
 			}
 			else
 			{
@@ -954,7 +954,13 @@ si32 CGHeroInstance::getManaNewTurn() const
 
 BoatId CGHeroInstance::getBoatType() const
 {
-	return type->getBoatType();
+	switch (type->heroClass->getAlignment())
+	{
+		case EAlignment::EVIL: return EBoatId::BOAT_EVIL;
+		case EAlignment::GOOD: return EBoatId::BOAT_GOOD;
+		case EAlignment::NEUTRAL: return EBoatId::BOAT_NEUTRAL;
+		default: return EBoatId::NONE;
+	}
 }
 
 void CGHeroInstance::getOutOffsets(std::vector<int3> &offsets) const

+ 16 - 0
lib/mapObjects/MiscObjects.cpp

@@ -1858,6 +1858,22 @@ void CGBoat::initObj(CRandomGenerator & rand)
 	hero = nullptr;
 }
 
+int3 CGBoat::translatePos(const int3& pos, bool reverse /* = false */)
+{
+	//pos - offset we want to place the boat at the map
+	//returned value - actual position as seen by game mechanics
+
+	//If reverse = true, then it's the opposite.
+	if (!reverse)
+	{
+		return pos + int3(1, 0, 0);
+	}
+	else
+	{
+		return pos - int3(1, 0, 0);
+	}
+}
+
 void CGSirens::initObj(CRandomGenerator & rand)
 {
 	blockVisit = true;

+ 1 - 0
lib/mapObjects/MiscObjects.h

@@ -430,6 +430,7 @@ public:
 	std::array<std::string, PlayerColor::PLAYER_LIMIT_I> flagAnimations;
 
 	void initObj(CRandomGenerator & rand) override;
+	static int3 translatePos(const int3 &pos, bool reverse = false);
 
 	CGBoat()
 	{

+ 3 - 3
lib/spells/AdventureSpellMechanics.cpp

@@ -201,7 +201,7 @@ ESpellCastResult SummonBoatMechanics::applyAdventureEffects(SpellCastEnvironment
 	{
 		ChangeObjPos cop;
 		cop.objid = nearest->id;
-		cop.nPos = summonPos + int3(1,0,0);
+		cop.nPos = CGBoat::translatePos(summonPos);
 		env->apply(&cop);
 	}
 	else if(schoolLevel < 2) //none or basic level -> cannot create boat :(
@@ -215,8 +215,8 @@ ESpellCastResult SummonBoatMechanics::applyAdventureEffects(SpellCastEnvironment
 	{
 		NewObject no;
 		no.ID = Obj::BOAT;
-		no.subID = parameters.caster->getHeroCaster()->getBoatType().getNum();
-		no.pos = summonPos + int3(1,0,0);
+		no.subID = BoatId(EBoatId::BOAT_EVIL);
+		no.pos = CGBoat::translatePos(summonPos);
 		env->apply(&no);
 	}
 	return ESpellCastResult::OK;

+ 1 - 1
server/CGameHandler.cpp

@@ -4421,7 +4421,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl
 		//Create a new boat for hero
 		NewObject no;
 		no.ID = Obj::BOAT;
-		no.subID = VLC->heroh->objects[nh->subID]->getBoatType().getNum();
+		no.subID = BoatId(EBoatId::BOAT_NEUTRAL);
 		no.pos = hr.tile + int3(1,0,0);
 		sendAndApply(&no);