mirror of
https://github.com/1dot13/source.git
synced 2026-08-19 14:20:30 +02:00
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:
@@ -5108,7 +5108,7 @@ void SortSectorInventoryEmptyLBE() {
|
||||
void SortSectorInventorySeparateAttachments()
|
||||
{
|
||||
// attachment ref and pointer
|
||||
OBJECTTYPE gTempObject;
|
||||
//OBJECTTYPE gTempObject;
|
||||
OBJECTTYPE * gpTempObject = NULL;
|
||||
|
||||
// current item
|
||||
@@ -5143,15 +5143,7 @@ void SortSectorInventorySeparateAttachments()
|
||||
//WarmSteel - This actually still works with NAS, be it by accident
|
||||
if (gpTempObject != NULL && pInventoryItem->object.RemoveAttachment(gpTempObject, pNewObj, x))
|
||||
{
|
||||
// Bob: sanity check! I think RemoveAttachment shouldn't be used like it was here.
|
||||
if (gpTempObject->usItem > 0 && (gpTempObject->ubNumberOfObjects != 1 || gpTempObject->usItem > MAXITEMS || gpTempObject->ubMission != 0)) {
|
||||
gpTempObject = pNewObj;
|
||||
}
|
||||
|
||||
// Bob: not sure why was this a ref instead of a pointer,
|
||||
// I'll leave it here so it gets cleaned up when going out of scope
|
||||
// since DeleteObj() doesn't free all the memory
|
||||
gTempObject = *gpTempObject;
|
||||
gpTempObject = pNewObj;
|
||||
|
||||
AutoPlaceObjectToWorld(pSoldier, gpTempObject, true);
|
||||
if (gpTempObject != NULL)
|
||||
|
||||
@@ -1754,14 +1754,18 @@ void PlotATemporaryPathForCharacter( SOLDIERTYPE *pCharacter, INT16 sX, INT16 sY
|
||||
return;
|
||||
}
|
||||
|
||||
// Bob: make sure we have a valid movement group
|
||||
UINT8 soldierGroupId = GetSoldierGroupId(pCharacter);
|
||||
if (soldierGroupId == 0) {
|
||||
soldierGroupId = tryToRecoverSquadsAndMovementGroups(pCharacter);
|
||||
}
|
||||
|
||||
// build path
|
||||
pTempCharacterPath = BuildAStrategicPath( pTempCharacterPath, GetLastSectorIdInCharactersPath( pCharacter ) , ( INT16 )( sX + sY*( MAP_WORLD_X ) ), GetSoldierGroupId( pCharacter ), FALSE /*, TRUE */ );
|
||||
pTempCharacterPath = BuildAStrategicPath( pTempCharacterPath, GetLastSectorIdInCharactersPath( pCharacter ) , ( INT16 )( sX + sY*( MAP_WORLD_X ) ), soldierGroupId, FALSE /*, TRUE */ );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// clear out character path list, after and including this sector
|
||||
UINT32 ClearPathAfterThisSectorForCharacter( SOLDIERTYPE *pCharacter, INT16 sX, INT16 sY )
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -225,4 +225,7 @@ void HandleEmailBeingSentWhenEnteringSector( INT16 sMapX, INT16 sMapY, INT8 bMap
|
||||
// Flugente: militia movement: can we order militia reinforcements from( sSrcMapX, sSrcMapY ) to( sMapX, sMapY ) ?
|
||||
BOOLEAN CanRequestMilitiaReinforcements( INT16 sMapX, INT16 sMapY, INT16 sSrcMapX, INT16 sSrcMapY );
|
||||
|
||||
// Bob: check and try to fix issues with squad and group assignment
|
||||
UINT8 tryToRecoverSquadsAndMovementGroups(SOLDIERTYPE* pCharacter);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user