mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Removed hardcoded constants in hero placement code for more robust
solution
This commit is contained in:
@@ -1873,17 +1873,24 @@ void CGameState::initVisitingAndGarrisonedHeroes()
|
|||||||
{
|
{
|
||||||
for(CGTownInstance *t : k->second.towns)
|
for(CGTownInstance *t : k->second.towns)
|
||||||
{
|
{
|
||||||
int3 vistile = t->visitablePos(); vistile.x++; //tile next to the entrance
|
bool heroOnTownBlockableTile = t->blockingAt(h->visitablePos().x, h->visitablePos().y);
|
||||||
if(vistile == h->pos || h->pos==t->visitablePos())
|
bool heroOnTownVisitableTile = t->visitableAt(h->visitablePos().x, h->visitablePos().y);
|
||||||
|
|
||||||
|
// current hero position is at one of blocking tiles of current town
|
||||||
|
// assume that this hero should be visiting the town (H3M format quirk) and move hero to correct position
|
||||||
|
if (heroOnTownBlockableTile)
|
||||||
{
|
{
|
||||||
t->setVisitingHero(h);
|
int3 townVisitablePos = t->visitablePos();
|
||||||
if(h->pos == t->pos) //visiting hero placed in the editor has same pos as the town - we need to correct it
|
int3 correctedPos = townVisitablePos + h->getVisitableOffset();
|
||||||
{
|
h->pos = correctedPos;
|
||||||
map->removeBlockVisTiles(h);
|
|
||||||
h->pos.x -= 1;
|
assert(t->visitableAt(h->visitablePos().x, h->visitablePos().y));
|
||||||
map->addBlockVisTiles(h);
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
if (heroOnTownBlockableTile || heroOnTownVisitableTile)
|
||||||
|
{
|
||||||
|
assert(t->visitingHero == nullptr);
|
||||||
|
t->setVisitingHero(h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user