mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-21 17:17:06 +02:00
Fix crash on rearranging troops on non-owned hero
This commit is contained in:
parent
56ee307b3a
commit
c82db9d574
@ -274,12 +274,12 @@ bool CGarrisonSlot::mustForceReselection() const
|
||||
if (!LOCPLINT->makingTurn)
|
||||
return true;
|
||||
|
||||
if (!creature || !selection->creature)
|
||||
return false;
|
||||
|
||||
// Attempt to take creatures from ally (select theirs first)
|
||||
if (!selection->our())
|
||||
return true;
|
||||
|
||||
if (!creature || !selection->creature)
|
||||
return false;
|
||||
|
||||
// Attempt to swap creatures with ally (select ours first)
|
||||
if (selection->creature != creature && withAlly)
|
||||
|
@ -199,10 +199,11 @@ void CHeroWindow::update()
|
||||
OBJECT_CONSTRUCTION;
|
||||
if(!garr)
|
||||
{
|
||||
bool removableTroops = curHero->getOwner() == LOCPLINT->playerID;
|
||||
std::string helpBox = heroscrn[32];
|
||||
boost::algorithm::replace_first(helpBox, "%s", CGI->generaltexth->allTexts[43]);
|
||||
|
||||
garr = std::make_shared<CGarrisonInt>(Point(15, 485), 8, Point(), curHero);
|
||||
garr = std::make_shared<CGarrisonInt>(Point(15, 485), 8, Point(), curHero, nullptr, removableTroops);
|
||||
auto split = std::make_shared<CButton>(Point(539, 519), AnimationPath::builtin("hsbtns9.def"), CButton::tooltip(CGI->generaltexth->allTexts[256], helpBox), [this](){ garr->splitClick(); }, EShortcut::HERO_ARMY_SPLIT);
|
||||
garr->addSplitBtn(split);
|
||||
}
|
||||
|
@ -957,12 +957,12 @@ void CGameInfoCallback::calculatePaths( const CGHeroInstance *hero, CPathsInfo &
|
||||
|
||||
const CArtifactInstance * CGameInfoCallback::getArtInstance( ArtifactInstanceID aid ) const
|
||||
{
|
||||
return gs->map->artInstances[aid.num];
|
||||
return gs->map->artInstances.at(aid.num);
|
||||
}
|
||||
|
||||
const CGObjectInstance * CGameInfoCallback::getObjInstance( ObjectInstanceID oid ) const
|
||||
{
|
||||
return gs->map->objects[oid.num];
|
||||
return gs->map->objects.at(oid.num);
|
||||
}
|
||||
|
||||
const CArtifactSet * CGameInfoCallback::getArtSet(const ArtifactLocation & loc) const
|
||||
|
@ -1861,12 +1861,8 @@ bool CGameHandler::bulkSmartSplitStack(SlotID slotSrc, ObjectInstanceID srcOwner
|
||||
|
||||
bool CGameHandler::arrangeStacks(ObjectInstanceID id1, ObjectInstanceID id2, ui8 what, SlotID p1, SlotID p2, si32 val, PlayerColor player)
|
||||
{
|
||||
const CArmedInstance * s1 = static_cast<const CArmedInstance *>(getObjInstance(id1));
|
||||
const CArmedInstance * s2 = static_cast<const CArmedInstance *>(getObjInstance(id2));
|
||||
const CCreatureSet & S1 = *s1;
|
||||
const CCreatureSet & S2 = *s2;
|
||||
StackLocation sl1(s1, p1);
|
||||
StackLocation sl2(s2, p2);
|
||||
const CArmedInstance * s1 = static_cast<const CArmedInstance *>(getObj(id1));
|
||||
const CArmedInstance * s2 = static_cast<const CArmedInstance *>(getObj(id2));
|
||||
|
||||
if (s1 == nullptr || s2 == nullptr)
|
||||
{
|
||||
@ -1874,6 +1870,11 @@ bool CGameHandler::arrangeStacks(ObjectInstanceID id1, ObjectInstanceID id2, ui8
|
||||
return false;
|
||||
}
|
||||
|
||||
const CCreatureSet & S1 = *s1;
|
||||
const CCreatureSet & S2 = *s2;
|
||||
StackLocation sl1(s1, p1);
|
||||
StackLocation sl2(s2, p2);
|
||||
|
||||
if (!sl1.slot.validSlot() || !sl2.slot.validSlot())
|
||||
{
|
||||
complain(complainInvalidSlot);
|
||||
|
Loading…
Reference in New Issue
Block a user