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
-3
View File
@@ -1010,9 +1010,6 @@ OBJECTTYPE* StackedObjectData::GetAttachmentAtIndex(UINT8 index)
if (iter != attachments.end()) {
OBJECTTYPE * attachment = &(*iter);
if (attachment->usItem > 0 && (attachment->ubNumberOfObjects != 1 || attachment->usItem > MAXITEMS || attachment->ubMission != 0) ) {
__debugbreak();
}
return attachment;
}
return 0;
+1 -53
View File
@@ -8282,11 +8282,6 @@ BOOLEAN OBJECTTYPE::RemoveAttachment( OBJECTTYPE * pAttachment, OBJECTTYPE * pNe
for (std::list<OBJECTTYPE>::iterator iter = (*this)[subObject]->attachments.begin();
iter != (*this)[subObject]->attachments.end(); ++iter){
// Bob: sanity check!
if (pAttachment != NULL && pAttachment->usItem > 0 && (pAttachment->ubNumberOfObjects != 1 || pAttachment->usItem > MAXITEMS || pAttachment->ubMission != 0)) {
__debugbreak();
}
//Compare the adress
if(&(*iter) == pAttachment)
{
@@ -8297,14 +8292,11 @@ BOOLEAN OBJECTTYPE::RemoveAttachment( OBJECTTYPE * pAttachment, OBJECTTYPE * pNe
break;
}
}
//It is possible that the previous loop did not find the EXACT attachment we wanted to delete, look if there is one that is at least equal in data.
if(!objDeleted){
for (std::list<OBJECTTYPE>::iterator iter = (*this)[subObject]->attachments.begin();
iter != (*this)[subObject]->attachments.end(); ++iter){
// Bob: sanity check!
if (pAttachment != NULL && pAttachment->usItem > 0 && (pAttachment->ubNumberOfObjects != 1 || pAttachment->usItem > MAXITEMS || pAttachment->ubMission != 0)) {
__debugbreak();
}
//This compares the internal data of the objects.
if(*iter == *pAttachment)
@@ -8318,19 +8310,9 @@ BOOLEAN OBJECTTYPE::RemoveAttachment( OBJECTTYPE * pAttachment, OBJECTTYPE * pNe
}
}
// Bob: sanity check!
if (pAttachment != NULL && pAttachment->usItem > 0 && (pAttachment->ubNumberOfObjects != 1 || pAttachment->usItem > MAXITEMS || pAttachment->ubMission != 0)) {
__debugbreak();
}
if(!objDeleted)
return( FALSE );
// Bob: this function tends to leave this pointer in a messed up state, leading to other code to deal with bogus item data
if (pAttachment != NULL) {
__debugbreak();
}
//After removing an attachment, the ammo capacity might have changed.
if ( Item[this->usItem].usItemClass == IC_GUN && (*this)[subObject]->data.gun.usGunAmmoItem != NONE && (*this)[subObject]->data.gun.ubGunShotsLeft > 0 && oldMagSize != GetMagSize(this, subObject) )
{
@@ -8423,28 +8405,9 @@ BOOLEAN OBJECTTYPE::RemoveAttachment( OBJECTTYPE * pAttachment, OBJECTTYPE * pNe
RemoveProhibitedAttachments(pSoldier, this, this->usItem);
}
// Bob: this function tends to leave this pointer in a messed up state, leading to other code to deal with bogus item data
if (pAttachment != NULL) {
__debugbreak();
}
if (pNewObj != NULL) {
*pNewObj = removedAttachment;
}
else {
*pAttachment = removedAttachment;
}
// Bob: this function tends to leave this pointer in a messed up state, leading to other code to deal with bogus item data
if (pAttachment != NULL) {
__debugbreak();
}
// Why is this here? By now, the object, pAttachment had been pointing to, has already been deconstructed via RemoveAttachmentAtIter.
// (Commenting out the following two lines)
//if(pAttachment->exists() && (pAttachment->usItem == 0 || pAttachment->usItem == removedAttachment.usItem ))
// *pAttachment = removedAttachment;
if (pNewObj->exists() && Item[pNewObj->usItem].grenadelauncher )//UNDER_GLAUNCHER)
{
@@ -8453,9 +8416,6 @@ BOOLEAN OBJECTTYPE::RemoveAttachment( OBJECTTYPE * pAttachment, OBJECTTYPE * pNe
OBJECTTYPE* pGrenade = FindAttachmentByClass( this, IC_GRENADE );
if (pGrenade->exists())
{
//ADB ubWeight has been removed, see comments in OBJECTTYPE
//pNewObj->ubWeight = CalculateObjectWeight( pNewObj );
// we might have to do it in this order, because if we attach first,
// the object is pretty much gone and RemoveAttachment won't work (returns right away)
OBJECTTYPE tmp;
@@ -8464,23 +8424,11 @@ BOOLEAN OBJECTTYPE::RemoveAttachment( OBJECTTYPE * pAttachment, OBJECTTYPE * pNe
}
}
// Bob: this function tends to leave this pointer in a messed up state, leading other code to deal with bogus item data
if (pAttachment != NULL) {
__debugbreak();
}
//Removing an attachment can alter slots, check them.
if(UsingNewAttachmentSystem()==true && fRemoveProhibited){
RemoveProhibitedAttachments(pSoldier, this, this->usItem);
}
// Bob: this function tends to leave this pointer in a messed up state, leading to other code to deal with bogus item data
if (pAttachment != NULL) {
__debugbreak();
}
//ADB ubWeight has been removed, see comments in OBJECTTYPE
//this->ubWeight = CalculateObjectWeight( this );
return( TRUE );
}
+1 -1
View File
@@ -273,7 +273,7 @@ public:
void initialize();
BOOLEAN Load(HWFILE hFile, int versionToLoad, bool loadChecksum);
BOOLEAN Load(INT8 **hBuffer, float dMajorMapVersion, UINT8 ubMinorMapVersion);
BOOLEAN Load(INT8 **hBuffer, FLOAT dMajorMapVersion, UINT8 ubMinorMapVersion);
BOOLEAN Save(HWFILE hFile, bool fSavingMap, FLOAT dMajorMapVersion=MAJOR_MAP_VERSION, UINT8 ubMinorMapVersion=MINOR_MAP_VERSION);//dnl ch42 250909
public:
+1 -1
View File
@@ -21,7 +21,7 @@ extern SOLDIERINITNODE *gSoldierInitTail;
//These serialization functions are assuming the passing of a valid file
//pointer to the beginning of the save/load area, at the correct part of the
//map file.
BOOLEAN LoadSoldiersFromMap( INT8 **hBuffer, float dMajorMapVersion, UINT8 ubMinorMapVersion );
BOOLEAN LoadSoldiersFromMap( INT8 **hBuffer, FLOAT dMajorMapVersion, UINT8 ubMinorMapVersion );
BOOLEAN SaveSoldiersToMap(HWFILE fp, FLOAT dMajorMapVersion, UINT8 ubMinorMapVersion);//dnl ch33 150909
//For the purpose of keeping track of which soldier belongs to which placement within the game,
+10 -1
View File
@@ -1655,7 +1655,8 @@ BOOLEAN DoesVehicleExistInSquad( INT8 bSquadValue )
void CheckSquadMovementGroups( void )
{
INT32 iSquad;
INT32 iSquad;
INT8 iSoldier;
GROUP * pGroup;
for( iSquad = 0; iSquad < NUMBER_OF_SQUADS; iSquad++ )
@@ -1671,5 +1672,13 @@ void CheckSquadMovementGroups( void )
Assert( pGroup );
pGroup->fPersistant = TRUE;
}
// Bob: propagate the group id to the squad members
for (INT8 iSoldier = 0; iSoldier < NUMBER_OF_SOLDIERS_PER_SQUAD; iSoldier++) {
if (Squad[iSquad][iSoldier] != NULL)
{
Squad[iSquad][iSoldier]->ubGroupID = pGroup->ubGroupID;
}
}
}
}