mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Fixed crashes when VCAI cannot find hero to recruit.
Bumped format version.
This commit is contained in:
@@ -1882,9 +1882,8 @@ void VCAI::tryRealize(CGoal g)
|
|||||||
{
|
{
|
||||||
if(const CGTownInstance *t = findTownWithTavern())
|
if(const CGTownInstance *t = findTownWithTavern())
|
||||||
{
|
{
|
||||||
//TODO co jesli nie ma dostepnego bohatera?
|
recruitHero(t, true);
|
||||||
//TODO jezeli miasto jest zablokowane, sprobowac oczyscic wejscie
|
//TODO jezeli miasto jest zablokowane, sprobowac oczyscic wejscie
|
||||||
cb->recruitHero(t, cb->getAvailableHeroes(t)[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO karkolomna alternatywa - tawerna na mapie przygod lub wiezienie (nie wiem, czy warto?)
|
//TODO karkolomna alternatywa - tawerna na mapie przygod lub wiezienie (nie wiem, czy warto?)
|
||||||
@@ -2505,10 +2504,14 @@ void VCAI::checkHeroArmy (HeroPtr h)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCAI::recruitHero(const CGTownInstance * t)
|
void VCAI::recruitHero(const CGTownInstance * t, bool throwing)
|
||||||
{
|
{
|
||||||
BNLOG("Trying to recruit a hero in %s at %s", t->name % t->visitablePos())
|
BNLOG("Trying to recruit a hero in %s at %s", t->name % t->visitablePos())
|
||||||
cb->recruitHero(t, cb->getAvailableHeroes(t).front());
|
|
||||||
|
if(auto availableHero = frontOrNull(cb->getAvailableHeroes(t)))
|
||||||
|
cb->recruitHero(t, availableHero);
|
||||||
|
else if(throwing)
|
||||||
|
throw cannotFulfillGoalException("No available heroes in tavern in " + t->nodeName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCAI::finish()
|
void VCAI::finish()
|
||||||
|
@@ -359,7 +359,7 @@ public:
|
|||||||
bool fulfillsGoal (CGoal &goal, CGoal &mainGoal);
|
bool fulfillsGoal (CGoal &goal, CGoal &mainGoal);
|
||||||
bool fulfillsGoal (CGoal &goal, const CGoal &mainGoal); //TODO: something smarter
|
bool fulfillsGoal (CGoal &goal, const CGoal &mainGoal); //TODO: something smarter
|
||||||
|
|
||||||
void recruitHero(const CGTownInstance * t);
|
void recruitHero(const CGTownInstance * t, bool throwing = false);
|
||||||
std::vector<const CGObjectInstance *> getPossibleDestinations(HeroPtr h);
|
std::vector<const CGObjectInstance *> getPossibleDestinations(HeroPtr h);
|
||||||
void buildStructure(const CGTownInstance * t);
|
void buildStructure(const CGTownInstance * t);
|
||||||
//void recruitCreatures(const CGTownInstance * t);
|
//void recruitCreatures(const CGTownInstance * t);
|
||||||
|
@@ -251,6 +251,8 @@ void CCallback::setSelection(const CArmedInstance * obj)
|
|||||||
|
|
||||||
void CCallback::recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero)
|
void CCallback::recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero)
|
||||||
{
|
{
|
||||||
|
assert(townOrTavern);
|
||||||
|
assert(hero);
|
||||||
ui8 i=0;
|
ui8 i=0;
|
||||||
for(; i<gs->players[player].availableHeroes.size(); i++)
|
for(; i<gs->players[player].availableHeroes.size(); i++)
|
||||||
{
|
{
|
||||||
|
@@ -34,7 +34,7 @@
|
|||||||
#include "CObjectHandler.h" //for CArmedInstance
|
#include "CObjectHandler.h" //for CArmedInstance
|
||||||
#include "Mapping/CCampaignHandler.h" //for CCampaignState
|
#include "Mapping/CCampaignHandler.h" //for CCampaignState
|
||||||
|
|
||||||
const ui32 version = 735;
|
const ui32 version = 737;
|
||||||
const TSlot COMMANDER_SLOT_PLACEHOLDER = -2;
|
const TSlot COMMANDER_SLOT_PLACEHOLDER = -2;
|
||||||
|
|
||||||
class CConnection;
|
class CConnection;
|
||||||
|
Reference in New Issue
Block a user