Cleaned up attachment removal code

Fixed rare issue with squads and movement groups not being defined at game start.
Fixed wrong type declarations in header files

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8407 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
TheBob
2017-06-12 17:09:25 +00:00
parent 5d6de52be9
commit 3c4da04532
10 changed files with 65 additions and 74 deletions
+35 -1
View File
@@ -4939,9 +4939,16 @@ BOOLEAN OKForSectorExit( INT8 bExitDirection, INT32 usAdditionalData, UINT32 *pu
// ATE: Dont's assume exit grids here...
if ( bExitDirection != -1 )
{
// Bob: make sure we have a valid movement group
UINT8 soldierGroupId = GetSoldierGroupId(pValidSoldier);
if (soldierGroupId == 0) {
soldierGroupId = tryToRecoverSquadsAndMovementGroups(pValidSoldier);
}
//Now, determine if this is a valid path.
pGroup = GetGroup( pValidSoldier->ubGroupID );
pGroup = GetGroup(soldierGroupId);
AssertMsg( pGroup, String( "%S is not in a valid group (pSoldier->ubGroupID is %d)", pValidSoldier->name, pValidSoldier->ubGroupID ) );
if ( !gbWorldSectorZ )
{
*puiTraverseTimeInMinutes = GetSectorMvtTimeForGroup( (UINT8)SECTOR( pGroup->ubSectorX, pGroup->ubSectorY ), bExitDirection, pGroup );
@@ -7862,3 +7869,30 @@ BOOLEAN CanRequestMilitiaReinforcements( INT16 sMapX, INT16 sMapY, INT16 sSrcMap
return FALSE;
}
// Bob: this function will check if the merc is in a valid squad and if there are other mercs assigned to that squad who lack a mvt group.
// Will attempt to fix this by assigning everyone to a proper squad and forcing squads to reevaluate movement groups.
// returns the movement group the character was reassigned to or zero if we failed.
UINT8 tryToRecoverSquadsAndMovementGroups(SOLDIERTYPE* pCharacter) {
// check if the char we're trying to move is in a valid squad!
if (SquadCharacterIsIn(pCharacter) == -1) {
if (pCharacter->bAssignment < ON_DUTY && SquadIsEmpty(pCharacter->bAssignment))
{ // assignment says we're in a squad but that squad is empty!
int squadWeThinkWeAreIn = pCharacter->bAssignment;
for (int i = 0; i < MAXMERCS; i++) {
if (Menptr[i].bActive && Menptr[i].bTeam == pCharacter->bTeam && Menptr[i].bAssignment == squadWeThinkWeAreIn)
{ // reassign everyone who's supposed to be in the bogus squad
AddCharacterToAnySquad(&Menptr[i]);
}
}
}
else
{ // that squad seems fine, it's just the merc that got confused
AddCharacterToAnySquad(pCharacter);
}
}
CheckSquadMovementGroups();
return GetSoldierGroupId(pCharacter);
}