Skip to content

Commit

Permalink
fix possible nameless character crash
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Sep 15, 2024
1 parent 59c0afb commit e95fadd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
4 changes: 3 additions & 1 deletion M2TWEOP Code/M2TWEOP library/types/army.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ bool armyStruct::canReceiveMerge(const armyStruct* other)
{
if (!other || !this) // NOLINT(clang-diagnostic-undefined-bool-conversion)
return false;
if (faction->factionID != other->faction->factionID)
return false;
if (settlement && settlement->siegeNum > 0)
return false;
if (faction->factionID != other->faction->factionID)
if (other->settlement && other->settlement->siegeNum > 0)
return false;
if (numOfUnits + other->numOfUnits > 20)
return false;
Expand Down
29 changes: 21 additions & 8 deletions M2TWEOP Code/M2TWEOP library/types/campaignAi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,12 @@ bool attackSettlementOrder::execute()
continue;
if (assignedArmy->resource->army->siege && globalEopAiConfig::getInstance()->isEndTurn)
continue;
const std::string logString2 = "General: " + string(assignedArmy->resource->army->gen->characterRecord->fullName);
gameHelpers::logStringGame(logString2);

if (assignedArmy->resource->army->gen->characterRecord->fullName)
{
const std::string logString2 = "General: " + string(assignedArmy->resource->army->gen->characterRecord->fullName);
gameHelpers::logStringGame(logString2);
}
const std::string logString = "Settlement: " + string(targetSettlement->settlement->name);
gameHelpers::logStringGame(logString);
if (targetSettlement->settlement->siegeNum > 0 && !assignedArmy->resource->army->siege)
Expand Down Expand Up @@ -1119,8 +1123,11 @@ bool attackArmyOrder::execute()
{
if (!assignedArmy->resource->validate() || !targetArmy->army || !targetArmy->army->gen || targetArmy->army->gen->markedForDeath)
continue;
const std::string logString2 = "General: " + string(assignedArmy->resource->army->gen->characterRecord->fullName);
gameHelpers::logStringGame(logString2);
if (assignedArmy->resource->army->gen->characterRecord->fullName)
{
const std::string logString2 = "General: " + string(assignedArmy->resource->army->gen->characterRecord->fullName);
gameHelpers::logStringGame(logString2);
}
if (assignedArmy->moveCost < assignedArmy->resource->army->gen->movePointsArmy && assignedArmy->turns < 2)
{
assignedArmy->resource->army->gen->hasEopOrders = true;
Expand Down Expand Up @@ -1169,8 +1176,11 @@ bool attackArmyOrder::execute()
continue;
assignedArmy->resource->army->gen->hasEopOrders = true;
assignedArmy->resource->used = true;
const std::string logString2 = "General: " + string(assignedArmy->resource->army->gen->characterRecord->fullName);
gameHelpers::logStringGame(logString2);
if (assignedArmy->resource->army->gen->characterRecord->fullName)
{
const std::string logString2 = "General: " + string(assignedArmy->resource->army->gen->characterRecord->fullName);
gameHelpers::logStringGame(logString2);
}
TURN_HAD_ACTION = true;
tileNums[tileIndex] += assignedArmy->resource->army->numOfUnits;
totalCommitted += assignedArmy->resource->army->totalStrength;
Expand Down Expand Up @@ -1246,7 +1256,8 @@ bool defendSettlementOrder::execute()
assignedArmy->resource->targets--;
continue;
}
gameHelpers::logStringGame("character: " + string(assignedArmy->resource->army->gen->characterRecord->fullName));
if (assignedArmy->resource->army->gen->characterRecord->fullName)
gameHelpers::logStringGame("character: " + string(assignedArmy->resource->army->gen->characterRecord->fullName));
assignedArmy->resource->army->gen->hasEopOrders = true;
assignedArmy->resource->used = true;
totalCommitted += assignedArmy->resource->army->totalStrength;
Expand Down Expand Up @@ -1523,8 +1534,10 @@ void globalEopAiConfig::characterTurnStart(character* currentChar)
if (xCoord == -1)
continue;
if (army->moveTactical(xCoord, yCoord, true))
{
gameHelpers::logStringGame("Character: " + string(currentChar->characterRecord->fullName) + " merged armies!");
break;
break;
}
}
}
}
Expand Down

0 comments on commit e95fadd

Please sign in to comment.