mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
PlayerState now stores all objects owned by player
This commit is contained in:
@@ -1171,7 +1171,7 @@ void RemoveObject::applyGs(CGameState *gs)
|
||||
assert(beatenHero);
|
||||
PlayerState * p = gs->getPlayerState(beatenHero->tempOwner);
|
||||
gs->map->heroesOnMap -= beatenHero;
|
||||
p->heroes -= beatenHero;
|
||||
p->removeOwnedObject(beatenHero);
|
||||
|
||||
|
||||
auto * siegeNode = beatenHero->whereShouldBeAttachedOnSiege(gs);
|
||||
@@ -1417,7 +1417,7 @@ void HeroRecruited::applyGs(CGameState *gs)
|
||||
gs->map->objects[h->id.getNum()] = h;
|
||||
|
||||
gs->map->heroesOnMap.emplace_back(h);
|
||||
p->heroes.emplace_back(h);
|
||||
p->addOwnedObject(h);
|
||||
h->attachTo(*p);
|
||||
gs->map->addBlockVisTiles(h);
|
||||
|
||||
@@ -1452,7 +1452,7 @@ void GiveHero::applyGs(CGameState *gs)
|
||||
h->setMovementPoints(h->movementPointsLimit(true));
|
||||
h->pos = h->convertFromVisitablePos(oldVisitablePos);
|
||||
gs->map->heroesOnMap.emplace_back(h);
|
||||
gs->getPlayerState(h->getOwner())->heroes.emplace_back(h);
|
||||
gs->getPlayerState(h->getOwner())->addOwnedObject(h);
|
||||
|
||||
gs->map->addBlockVisTiles(h);
|
||||
h->inTownGarrison = false;
|
||||
@@ -1942,6 +1942,18 @@ void SetObjectProperty::applyGs(CGameState *gs)
|
||||
}
|
||||
|
||||
auto * cai = dynamic_cast<CArmedInstance *>(obj);
|
||||
|
||||
if(what == ObjProperty::OWNER)
|
||||
{
|
||||
PlayerColor oldOwner = obj->getOwner();
|
||||
PlayerColor newOwner = identifier.as<PlayerColor>();
|
||||
if(oldOwner.isValidPlayer())
|
||||
gs->getPlayerState(oldOwner)->removeOwnedObject(obj);;
|
||||
|
||||
if(newOwner.isValidPlayer())
|
||||
gs->getPlayerState(newOwner)->addOwnedObject(obj);;
|
||||
}
|
||||
|
||||
if(what == ObjProperty::OWNER && cai)
|
||||
{
|
||||
if(obj->ID == Obj::TOWN)
|
||||
@@ -1953,17 +1965,13 @@ void SetObjectProperty::applyGs(CGameState *gs)
|
||||
if(oldOwner.isValidPlayer())
|
||||
{
|
||||
auto * state = gs->getPlayerState(oldOwner);
|
||||
state->towns -= t;
|
||||
|
||||
if(state->towns.empty())
|
||||
if(state->getTowns().empty())
|
||||
state->daysWithoutCastle = 0;
|
||||
}
|
||||
if(identifier.as<PlayerColor>().isValidPlayer())
|
||||
{
|
||||
PlayerState * p = gs->getPlayerState(identifier.as<PlayerColor>());
|
||||
p->towns.emplace_back(t);
|
||||
|
||||
//reset counter before NewTurn to avoid no town message if game loaded at turn when one already captured
|
||||
PlayerState * p = gs->getPlayerState(identifier.as<PlayerColor>());
|
||||
if(p->daysWithoutCastle)
|
||||
p->daysWithoutCastle = std::nullopt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user