mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Replaced most of accesses to CGObjectInstance::pos with anchorPoint()
This commit is contained in:
@@ -33,7 +33,7 @@ std::string CGCreature::getHoverText(PlayerColor player) const
|
||||
if(stacks.empty())
|
||||
{
|
||||
//should not happen...
|
||||
logGlobal->error("Invalid stack at tile %s: subID=%d; id=%d", pos.toString(), getCreature(), id.getNum());
|
||||
logGlobal->error("Invalid stack at tile %s: subID=%d; id=%d", anchorPos().toString(), getCreature(), id.getNum());
|
||||
return "INVALID_STACK";
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ bool CGCreature::containsUpgradedStack() const
|
||||
float c = 5325.181015f;
|
||||
float d = 32788.727920f;
|
||||
|
||||
int val = static_cast<int>(std::floor(a * pos.x + b * pos.y + c * pos.z + d));
|
||||
int val = static_cast<int>(std::floor(a * visitablePos().x + b * visitablePos().y + c * visitablePos().z + d));
|
||||
return ((val % 32768) % 100) < 50;
|
||||
}
|
||||
|
||||
@@ -591,7 +591,7 @@ int CGCreature::getNumberOfStacks(const CGHeroInstance *hero) const
|
||||
ui32 c = 1943276003u;
|
||||
ui32 d = 3174620878u;
|
||||
|
||||
ui32 R1 = a * static_cast<ui32>(pos.x) + b * static_cast<ui32>(pos.y) + c * static_cast<ui32>(pos.z) + d;
|
||||
ui32 R1 = a * static_cast<ui32>(visitablePos().x) + b * static_cast<ui32>(visitablePos().y) + c * static_cast<ui32>(visitablePos().z) + d;
|
||||
ui32 R2 = (R1 >> 16) & 0x7fff;
|
||||
|
||||
int R4 = R2 % 100 + 1;
|
||||
|
||||
@@ -1514,11 +1514,11 @@ bool CGHeroInstance::hasVisions(const CGObjectInstance * target, BonusSubtypeID
|
||||
if (visionsMultiplier > 0)
|
||||
vstd::amax(visionsRange, 3); //minimum range is 3 tiles, but only if VISIONS bonus present
|
||||
|
||||
const int distance = static_cast<int>(target->pos.dist2d(visitablePos()));
|
||||
const int distance = static_cast<int>(target->anchorPos().dist2d(visitablePos()));
|
||||
|
||||
//logGlobal->debug(boost::str(boost::format("Visions: dist %d, mult %d, range %d") % distance % visionsMultiplier % visionsRange));
|
||||
|
||||
return (distance < visionsRange) && (target->pos.z == pos.z);
|
||||
return (distance < visionsRange) && (target->anchorPos().z == anchorPos().z);
|
||||
}
|
||||
|
||||
std::string CGHeroInstance::getHeroTypeName() const
|
||||
|
||||
@@ -54,14 +54,14 @@ MapObjectSubID CGObjectInstance::getObjTypeIndex() const
|
||||
return subID;
|
||||
}
|
||||
|
||||
int3 CGObjectInstance::getPosition() const
|
||||
int3 CGObjectInstance::anchorPos() const
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
int3 CGObjectInstance::getTopVisiblePos() const
|
||||
{
|
||||
return pos - appearance->getTopVisibleOffset();
|
||||
return anchorPos() - appearance->getTopVisibleOffset();
|
||||
}
|
||||
|
||||
void CGObjectInstance::setOwner(const PlayerColor & ow)
|
||||
@@ -69,6 +69,11 @@ void CGObjectInstance::setOwner(const PlayerColor & ow)
|
||||
tempOwner = ow;
|
||||
}
|
||||
|
||||
void CGObjectInstance::setAnchorPos(int3 newPos)
|
||||
{
|
||||
pos = newPos;
|
||||
}
|
||||
|
||||
int CGObjectInstance::getWidth() const
|
||||
{
|
||||
return appearance->getWidth();
|
||||
@@ -79,32 +84,19 @@ int CGObjectInstance::getHeight() const
|
||||
return appearance->getHeight();
|
||||
}
|
||||
|
||||
bool CGObjectInstance::visitableAt(int x, int y) const
|
||||
{
|
||||
return appearance->isVisitableAt(pos.x - x, pos.y - y);
|
||||
}
|
||||
bool CGObjectInstance::blockingAt(int x, int y) const
|
||||
{
|
||||
return appearance->isBlockedAt(pos.x - x, pos.y - y);
|
||||
}
|
||||
|
||||
bool CGObjectInstance::coveringAt(int x, int y) const
|
||||
{
|
||||
return appearance->isVisibleAt(pos.x - x, pos.y - y);
|
||||
}
|
||||
|
||||
bool CGObjectInstance::visitableAt(const int3 & testPos) const
|
||||
{
|
||||
return pos.z == testPos.z && appearance->isVisitableAt(pos.x - testPos.x, pos.y - testPos.y);
|
||||
return anchorPos().z == testPos.z && appearance->isVisitableAt(anchorPos().x - testPos.x, anchorPos().y - testPos.y);
|
||||
}
|
||||
|
||||
bool CGObjectInstance::blockingAt(const int3 & testPos) const
|
||||
{
|
||||
return pos.z == testPos.z && appearance->isBlockedAt(pos.x - testPos.x, pos.y - testPos.y);
|
||||
return anchorPos().z == testPos.z && appearance->isBlockedAt(anchorPos().x - testPos.x, anchorPos().y - testPos.y);
|
||||
}
|
||||
|
||||
bool CGObjectInstance::coveringAt(const int3 & testPos) const
|
||||
{
|
||||
return pos.z == testPos.z && appearance->isVisibleAt(pos.x - testPos.x, pos.y - testPos.y);
|
||||
return anchorPos().z == testPos.z && appearance->isVisibleAt(anchorPos().x - testPos.x, anchorPos().y - testPos.y);
|
||||
}
|
||||
|
||||
std::set<int3> CGObjectInstance::getBlockedPos() const
|
||||
@@ -115,7 +107,7 @@ std::set<int3> CGObjectInstance::getBlockedPos() const
|
||||
for(int h=0; h<getHeight(); ++h)
|
||||
{
|
||||
if(appearance->isBlockedAt(w, h))
|
||||
ret.insert(int3(pos.x - w, pos.y - h, pos.z));
|
||||
ret.insert(int3(anchorPos().x - w, anchorPos().y - h, anchorPos().z));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@@ -215,6 +207,8 @@ int CGObjectInstance::getSightRadius() const
|
||||
|
||||
int3 CGObjectInstance::getVisitableOffset() const
|
||||
{
|
||||
if (!isVisitable())
|
||||
throw std::runtime_error("Attempt to access visitable offset of a non-visitable object!");
|
||||
return appearance->getVisitableOffset();
|
||||
}
|
||||
|
||||
@@ -313,6 +307,9 @@ void CGObjectInstance::onHeroVisit( const CGHeroInstance * h ) const
|
||||
|
||||
int3 CGObjectInstance::visitablePos() const
|
||||
{
|
||||
if (!isVisitable())
|
||||
throw std::runtime_error("Attempt to access visitable position on a non-visitable object!");
|
||||
|
||||
return pos - getVisitableOffset();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@ using TObjectTypeHandler = std::shared_ptr<AObjectTypeHandler>;
|
||||
class DLL_LINKAGE CGObjectInstance : public IObjectInterface
|
||||
{
|
||||
public:
|
||||
/// Position of bottom-right corner of object on map
|
||||
int3 pos;
|
||||
/// Type of object, e.g. town, hero, creature.
|
||||
MapObjectID ID;
|
||||
/// Subtype of object, depends on type
|
||||
@@ -41,6 +39,9 @@ public:
|
||||
/// Defines appearance of object on map (animation, blocked tiles, blit order, etc)
|
||||
std::shared_ptr<const ObjectTemplate> appearance;
|
||||
|
||||
/// Position of bottom-right corner of object on map
|
||||
int3 pos;
|
||||
|
||||
std::string instanceName;
|
||||
std::string typeName;
|
||||
std::string subTypeName;
|
||||
@@ -62,21 +63,19 @@ public:
|
||||
return this->tempOwner;
|
||||
}
|
||||
void setOwner(const PlayerColor & ow);
|
||||
void setAnchorPos(int3 pos);
|
||||
|
||||
/** APPEARANCE ACCESSORS **/
|
||||
|
||||
int getWidth() const; //returns width of object graphic in tiles
|
||||
int getHeight() const; //returns height of object graphic in tiles
|
||||
int3 visitablePos() const override;
|
||||
int3 getPosition() const override;
|
||||
int3 anchorPos() const override;
|
||||
int3 getTopVisiblePos() const;
|
||||
bool visitableAt(int x, int y) const; //returns true if object is visitable at location (x, y) (h3m pos)
|
||||
bool blockingAt(int x, int y) const; //returns true if object is blocking location (x, y) (h3m pos)
|
||||
bool coveringAt(int x, int y) const; //returns true if object covers with picture location (x, y) (h3m pos)
|
||||
|
||||
bool visitableAt(const int3 & pos) const; //returns true if object is visitable at location (x, y) (h3m pos)
|
||||
bool blockingAt (const int3 & pos) const; //returns true if object is blocking location (x, y) (h3m pos)
|
||||
bool coveringAt (const int3 & pos) const; //returns true if object covers with picture location (x, y) (h3m pos)
|
||||
bool visitableAt(const int3 & pos) const; //returns true if object is visitable at location
|
||||
bool blockingAt (const int3 & pos) const; //returns true if object is blocking location
|
||||
bool coveringAt (const int3 & pos) const; //returns true if object covers with picture location
|
||||
|
||||
std::set<int3> getBlockedPos() const; //returns set of positions blocked by this object
|
||||
const std::set<int3> & getBlockedOffsets() const; //returns set of relative positions blocked by this object
|
||||
|
||||
@@ -954,7 +954,7 @@ TResources CGTownInstance::getBuildingCost(const BuildingID & buildingID) const
|
||||
return town->buildings.at(buildingID)->resources;
|
||||
else
|
||||
{
|
||||
logGlobal->error("Town %s at %s has no possible building %d!", getNameTranslated(), pos.toString(), buildingID.toEnum());
|
||||
logGlobal->error("Town %s at %s has no possible building %d!", getNameTranslated(), anchorPos().toString(), buildingID.toEnum());
|
||||
return TResources();
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,6 @@ class DLL_LINKAGE CGTownInstance : public CGDwelling, public IShipyard, public I
|
||||
std::set<BuildingID> builtBuildings;
|
||||
|
||||
public:
|
||||
using CGDwelling::getPosition;
|
||||
|
||||
enum EFortLevel {NONE = 0, FORT = 1, CITADEL = 2, CASTLE = 3};
|
||||
|
||||
CTownAndVisitingHero townAndVis;
|
||||
|
||||
@@ -614,7 +614,7 @@ void CGSeerHut::onHeroVisit(const CGHeroInstance * h) const
|
||||
|
||||
int CGSeerHut::checkDirection() const
|
||||
{
|
||||
int3 cord = getCreatureToKill(false)->pos;
|
||||
int3 cord = getCreatureToKill(false)->visitablePos();
|
||||
if(static_cast<double>(cord.x) / static_cast<double>(cb->getMapSize().x) < 0.34) //north
|
||||
{
|
||||
if(static_cast<double>(cord.y) / static_cast<double>(cb->getMapSize().y) < 0.34) //northwest
|
||||
|
||||
@@ -145,7 +145,7 @@ void IBoatGenerator::getProblemText(MetaString &out, const CGHeroInstance *visit
|
||||
out.appendLocalString(EMetaText::ADVOB_TXT, 189);
|
||||
break;
|
||||
case NO_WATER:
|
||||
logGlobal->error("Shipyard without water at tile %s! ", getObject()->getPosition().toString());
|
||||
logGlobal->error("Shipyard without water at tile %s! ", getObject()->anchorPos().toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
virtual PlayerColor getOwner() const = 0;
|
||||
virtual int3 visitablePos() const = 0;
|
||||
virtual int3 getPosition() const = 0;
|
||||
virtual int3 anchorPos() const = 0;
|
||||
|
||||
virtual void onHeroVisit(const CGHeroInstance * h) const;
|
||||
virtual void onHeroLeave(const CGHeroInstance * h) const;
|
||||
|
||||
@@ -111,7 +111,7 @@ void CGMine::initObj(vstd::RNG & rand)
|
||||
}
|
||||
else
|
||||
{
|
||||
logGlobal->error("Abandoned mine at (%s) has no valid resource candidates!", pos.toString());
|
||||
logGlobal->error("Abandoned mine at (%s) has no valid resource candidates!", anchorPos().toString());
|
||||
producedResource = GameResID::GOLD;
|
||||
}
|
||||
}
|
||||
@@ -510,11 +510,11 @@ void CGMonolith::onHeroVisit( const CGHeroInstance * h ) const
|
||||
|
||||
if(cb->isTeleportChannelImpassable(channel))
|
||||
{
|
||||
logGlobal->debug("Cannot find corresponding exit monolith for %d at %s", id.getNum(), pos.toString());
|
||||
logGlobal->debug("Cannot find corresponding exit monolith for %d at %s", id.getNum(), anchorPos().toString());
|
||||
td.impassable = true;
|
||||
}
|
||||
else if(getRandomExit(h) == ObjectInstanceID())
|
||||
logGlobal->debug("All exits blocked for monolith %d at %s", id.getNum(), pos.toString());
|
||||
logGlobal->debug("All exits blocked for monolith %d at %s", id.getNum(), anchorPos().toString());
|
||||
}
|
||||
else
|
||||
h->showInfoDialog(70);
|
||||
@@ -574,7 +574,7 @@ void CGSubterraneanGate::onHeroVisit( const CGHeroInstance * h ) const
|
||||
if(cb->isTeleportChannelImpassable(channel))
|
||||
{
|
||||
h->showInfoDialog(153);//Just inside the entrance you find a large pile of rubble blocking the tunnel. You leave discouraged.
|
||||
logGlobal->debug("Cannot find exit subterranean gate for %d at %s", id.getNum(), pos.toString());
|
||||
logGlobal->debug("Cannot find exit subterranean gate for %d at %s", id.getNum(), anchorPos().toString());
|
||||
td.impassable = true;
|
||||
}
|
||||
else
|
||||
@@ -602,13 +602,13 @@ void CGSubterraneanGate::postInit(IGameCallback * cb) //matches subterranean gat
|
||||
|
||||
auto * hlp = dynamic_cast<CGSubterraneanGate *>(cb->gameState()->getObjInstance(obj->id));
|
||||
if(hlp)
|
||||
gatesSplit[hlp->pos.z].push_back(hlp);
|
||||
gatesSplit[hlp->visitablePos().z].push_back(hlp);
|
||||
}
|
||||
|
||||
//sort by position
|
||||
std::sort(gatesSplit[0].begin(), gatesSplit[0].end(), [](const CGObjectInstance * a, const CGObjectInstance * b)
|
||||
{
|
||||
return a->pos < b->pos;
|
||||
return a->visitablePos() < b->visitablePos();
|
||||
});
|
||||
|
||||
auto assignToChannel = [&](CGSubterraneanGate * obj)
|
||||
@@ -631,7 +631,7 @@ void CGSubterraneanGate::postInit(IGameCallback * cb) //matches subterranean gat
|
||||
CGSubterraneanGate *checked = gatesSplit[1][j];
|
||||
if(checked->channel != TeleportChannelID())
|
||||
continue;
|
||||
si32 hlp = checked->pos.dist2dSQ(objCurrent->pos);
|
||||
si32 hlp = checked->visitablePos().dist2dSQ(objCurrent->visitablePos());
|
||||
if(hlp < best.second)
|
||||
{
|
||||
best.first = j;
|
||||
@@ -657,11 +657,11 @@ void CGWhirlpool::onHeroVisit( const CGHeroInstance * h ) const
|
||||
TeleportDialog td(h->id, channel);
|
||||
if(cb->isTeleportChannelImpassable(channel))
|
||||
{
|
||||
logGlobal->debug("Cannot find exit whirlpool for %d at %s", id.getNum(), pos.toString());
|
||||
logGlobal->debug("Cannot find exit whirlpool for %d at %s", id.getNum(), anchorPos().toString());
|
||||
td.impassable = true;
|
||||
}
|
||||
else if(getRandomExit(h) == ObjectInstanceID())
|
||||
logGlobal->debug("All exits are blocked for whirlpool %d at %s", id.getNum(), pos.toString());
|
||||
logGlobal->debug("All exits are blocked for whirlpool %d at %s", id.getNum(), anchorPos().toString());
|
||||
|
||||
if(!isProtected(h))
|
||||
{
|
||||
@@ -1086,9 +1086,9 @@ void CGMagi::onHeroVisit(const CGHeroInstance * h) const
|
||||
|
||||
for(const auto & eye : eyes)
|
||||
{
|
||||
cb->getTilesInRange (fw.tiles, eye->pos, 10, ETileVisibility::HIDDEN, h->tempOwner);
|
||||
cb->getTilesInRange (fw.tiles, eye->visitablePos(), 10, ETileVisibility::HIDDEN, h->tempOwner);
|
||||
cb->sendAndApply(fw);
|
||||
cv.pos = eye->pos;
|
||||
cv.pos = eye->visitablePos();
|
||||
|
||||
cb->sendAndApply(cv);
|
||||
}
|
||||
|
||||
@@ -56,9 +56,9 @@ int3 TownBuildingInstance::visitablePos() const
|
||||
return town->visitablePos();
|
||||
}
|
||||
|
||||
int3 TownBuildingInstance::getPosition() const
|
||||
int3 TownBuildingInstance::anchorPos() const
|
||||
{
|
||||
return town->getPosition();
|
||||
return town->anchorPos();
|
||||
}
|
||||
|
||||
TownRewardableBuildingInstance::TownRewardableBuildingInstance(IGameCallback *cb)
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
const IOwnableObject * asOwnable() const override;
|
||||
|
||||
int3 visitablePos() const override;
|
||||
int3 getPosition() const override;
|
||||
int3 anchorPos() const override;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user