1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

- fixed some crashes on staring a map/campaign

This commit is contained in:
Ivan Savenko 2014-02-08 21:05:24 +00:00
parent 562dc02b3b
commit e6f433795b
3 changed files with 24 additions and 9 deletions

View File

@ -3595,6 +3595,7 @@ void CBonusSelection::updateBonusSelection()
void CBonusSelection::updateCampaignState() void CBonusSelection::updateCampaignState()
{ {
ourCampaign->currentMap = selectedMap; ourCampaign->currentMap = selectedMap;
if (selectedBonus)
ourCampaign->chosenCampaignBonuses[selectedMap] = *selectedBonus; ourCampaign->chosenCampaignBonuses[selectedMap] = *selectedBonus;
} }

View File

@ -645,7 +645,7 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
{ {
if(cur->ID==Obj::TOWN) //town - set def if(cur->ID==Obj::TOWN) //town - set def
{ {
const TerrainTile &tile = map->getTile(cur->pos); const TerrainTile &tile = map->getTile(cur->visitablePos());
CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur); CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
t->town = VLC->townh->factions[t->subID]->town; t->town = VLC->townh->factions[t->subID]->town;
t->appearance = VLC->dobjinfo->pickCandidates(Obj::TOWN, t->subID, tile.terType).front(); t->appearance = VLC->dobjinfo->pickCandidates(Obj::TOWN, t->subID, tile.terType).front();
@ -667,7 +667,7 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
} }
else if(ran.first==Obj::TOWN)//special code for town else if(ran.first==Obj::TOWN)//special code for town
{ {
const TerrainTile &tile = map->getTile(cur->pos); const TerrainTile &tile = map->getTile(cur->visitablePos());
CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur); CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
if(!t) {logGlobal->warnStream()<<"Wrong random town at "<<cur->pos; return;} if(!t) {logGlobal->warnStream()<<"Wrong random town at "<<cur->pos; return;}
cur->ID = ran.first; cur->ID = ran.first;
@ -686,7 +686,7 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
if (ran.first != cur->appearance.id || if (ran.first != cur->appearance.id ||
ran.second != cur->appearance.subid) ran.second != cur->appearance.subid)
{ {
const TerrainTile &tile = map->getTile(cur->pos); const TerrainTile &tile = map->getTile(cur->visitablePos());
cur->appearance = VLC->dobjinfo->pickCandidates(Obj(ran.first),ran.second, tile.terType).front(); cur->appearance = VLC->dobjinfo->pickCandidates(Obj(ran.first),ran.second, tile.terType).front();
} }
} }
@ -1199,7 +1199,7 @@ CGameState::CrossoverHeroesList CGameState::getCrossoverHeroesFromPreviousScenar
auto campaignState = scenarioOps->campState; auto campaignState = scenarioOps->campState;
auto bonus = campaignState->getBonusForCurrentMap(); auto bonus = campaignState->getBonusForCurrentMap();
if (bonus->type == CScenarioTravel::STravelBonus::HEROES_FROM_PREVIOUS_SCENARIO) if (bonus && bonus->type == CScenarioTravel::STravelBonus::HEROES_FROM_PREVIOUS_SCENARIO)
{ {
crossoverHeroes.heroesFromAnyPreviousScenarios = crossoverHeroes.heroesFromPreviousScenario = campaignState->camp->scenarios[bonus->info2].crossoverHeroes; crossoverHeroes.heroesFromAnyPreviousScenarios = crossoverHeroes.heroesFromPreviousScenario = campaignState->camp->scenarios[bonus->info2].crossoverHeroes;
} }
@ -2349,10 +2349,22 @@ bool CGameState::checkForVictory( PlayerColor player, const EventCondition & con
return p->resources[condition.objectType] >= condition.value; return p->resources[condition.objectType] >= condition.value;
} }
case EventCondition::HAVE_BUILDING: case EventCondition::HAVE_BUILDING:
{
if (condition.object) // specific town
{ {
const CGTownInstance *t = static_cast<const CGTownInstance *>(condition.object); const CGTownInstance *t = static_cast<const CGTownInstance *>(condition.object);
return (t->tempOwner == player && t->hasBuilt(BuildingID(condition.objectType))); return (t->tempOwner == player && t->hasBuilt(BuildingID(condition.objectType)));
} }
else // any town
{
for (const CGTownInstance * t : p->towns)
{
if (t->hasBuilt(BuildingID(condition.objectType)))
return true;
}
return false;
}
}
case EventCondition::DESTROY: case EventCondition::DESTROY:
{ {
if (condition.object) // mode A - destroy specific object of this type if (condition.object) // mode A - destroy specific object of this type

View File

@ -384,8 +384,10 @@ boost::optional<CScenarioTravel::STravelBonus> CCampaignState::getBonusForCurren
auto bonuses = getCurrentScenario().travelOptions.bonusesToChoose; auto bonuses = getCurrentScenario().travelOptions.bonusesToChoose;
assert(chosenCampaignBonuses.count(*currentMap) || bonuses.size() == 0); assert(chosenCampaignBonuses.count(*currentMap) || bonuses.size() == 0);
if(bonuses.empty()) return boost::optional<CScenarioTravel::STravelBonus>(); if(bonuses.empty())
else return bonuses[currentBonusID()]; return boost::optional<CScenarioTravel::STravelBonus>();
else
return bonuses[currentBonusID()];
} }
const CCampaignScenario & CCampaignState::getCurrentScenario() const const CCampaignScenario & CCampaignState::getCurrentScenario() const