From bd74fac6cc5d6f96dfc78153ab2c9226fa64a7b0 Mon Sep 17 00:00:00 2001 From: SpaceViking Date: Wed, 13 May 2009 22:32:44 +0000 Subject: [PATCH] Add checks around all use of bMercOpinion git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2854 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/Assignments.cpp | 6 ++++-- Strategic/Game Init.cpp | 3 ++- Strategic/Strategic Merc Handler.cpp | 14 +++++++++++--- Tactical/Morale.cpp | 2 +- Tactical/Soldier Control.cpp | 2 +- Tactical/opplist.cpp | 3 ++- Tactical/soldier profile type.h | 24 ++++++++++++++++++++++-- TacticalAI/NPC.cpp | 5 ++++- 8 files changed, 47 insertions(+), 12 deletions(-) diff --git a/Strategic/Assignments.cpp b/Strategic/Assignments.cpp index b9ffa23fc..a996a7033 100644 --- a/Strategic/Assignments.cpp +++ b/Strategic/Assignments.cpp @@ -3949,8 +3949,10 @@ INT16 GetBonusTrainingPtsDueToInstructor( SOLDIERTYPE *pInstructor, SOLDIERTYPE } // factor in their mutual relationship - bOpinionFactor = gMercProfiles[ pStudent->ubProfile ].bMercOpinion[ pInstructor->ubProfile ]; - bOpinionFactor += gMercProfiles[ pInstructor->ubProfile ].bMercOpinion[ pStudent->ubProfile ] / 2; + if (OKToCheckOpinion(pInstructor->ubProfile)) + bOpinionFactor = gMercProfiles[ pStudent->ubProfile ].bMercOpinion[ pInstructor->ubProfile ]; + if (OKToCheckOpinion(pStudent->ubProfile)) + bOpinionFactor += gMercProfiles[ pInstructor->ubProfile ].bMercOpinion[ pStudent->ubProfile ] / 2; } diff --git a/Strategic/Game Init.cpp b/Strategic/Game Init.cpp index fe4b599fd..70bad2693 100644 --- a/Strategic/Game Init.cpp +++ b/Strategic/Game Init.cpp @@ -697,7 +697,8 @@ void QuickSetupOfMercProfileItems( UINT32 uiCount, UINT8 ubProfileIndex ) // TEMP! // make carman's opinion of us high! - gMercProfiles[ 78 ].bMercOpinion[ ubProfileIndex ] = 25; + if (OKToCheckOpinion(ubProfileIndex)) + gMercProfiles[ 78 ].bMercOpinion[ ubProfileIndex ] = 25; } else if ( uiCount == 1 ) diff --git a/Strategic/Strategic Merc Handler.cpp b/Strategic/Strategic Merc Handler.cpp index 8f040ff61..82fedefd1 100644 --- a/Strategic/Strategic Merc Handler.cpp +++ b/Strategic/Strategic Merc Handler.cpp @@ -991,8 +991,10 @@ void UpdateBuddyAndHatedCounters( void ) else if (pProfile->bLearnToHateCount == 0) { // set as bHated[2]; + if (OKToCheckOpinion(ubOtherProfileID)) { pProfile->bHated[2] = pProfile->bLearnToHate; pProfile->bMercOpinion[ubOtherProfileID] = HATED_OPINION; + } if (pSoldier->ubWhatKindOfMercAmI == MERC_TYPE__MERC || (pSoldier->ubWhatKindOfMercAmI == MERC_TYPE__NPC && (pSoldier->ubProfile == DEVIN || pSoldier->ubProfile == SLAY || pSoldier->ubProfile == IGGY || pSoldier->ubProfile == CONRAD ) ) ) { @@ -1012,9 +1014,11 @@ void UpdateBuddyAndHatedCounters( void ) if (pProfile->bLearnToHateCount < pProfile->bLearnToHateTime / 2) { // gradual opinion drop + if (OKToCheckOpinion(ubOtherProfileID)) { pProfile->bMercOpinion[ubOtherProfileID] += (HATED_OPINION - pProfile->bMercOpinion[ubOtherProfileID]) / (pProfile->bLearnToHateCount + 1); } } + } else { if ( !fUpdatedTimeTillNextHatedComplaint ) @@ -1045,13 +1049,17 @@ void UpdateBuddyAndHatedCounters( void ) if (pProfile->bLearnToLikeCount == 0) { // add to liked! - pProfile->bBuddy[2] = pProfile->bLearnToLike; - pProfile->bMercOpinion[ubOtherProfileID] = BUDDY_OPINION; + if (OKToCheckOpinion(ubOtherProfileID)) { + pProfile->bBuddy[2] = pProfile->bLearnToLike; + pProfile->bMercOpinion[ubOtherProfileID] = BUDDY_OPINION; + } } else if (pProfile->bLearnToLikeCount < pProfile->bLearnToLikeTime / 2) { // increase opinion of them! - pProfile->bMercOpinion[ubOtherProfileID] += (BUDDY_OPINION - pProfile->bMercOpinion[ubOtherProfileID]) / (pProfile->bLearnToLikeCount + 1); + if (OKToCheckOpinion(ubOtherProfileID)) { + pProfile->bMercOpinion[ubOtherProfileID] += (BUDDY_OPINION - pProfile->bMercOpinion[ubOtherProfileID]) / (pProfile->bLearnToLikeCount + 1); + } break; } } diff --git a/Tactical/Morale.cpp b/Tactical/Morale.cpp index 36f08e5c3..1fd53eaad 100644 --- a/Tactical/Morale.cpp +++ b/Tactical/Morale.cpp @@ -829,7 +829,7 @@ void HourlyMoraleUpdate( void ) } // WANNE: Fix by Headrock: Morale and the ice-cream truck. - if (pOtherSoldier->ubProfile < 75) + if (OKToCheckOpinion(pOtherSoldier->ubProfile)) { bOpinion = pProfile->bMercOpinion[ pOtherSoldier->ubProfile ]; } diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index a6dc56392..b86d09fca 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -1216,7 +1216,7 @@ MERCPROFILESTRUCT& MERCPROFILESTRUCT::operator=(const OLD_MERCPROFILESTRUCT_101& memcpy( &(this->ubApproachVal), &(src.ubApproachVal), 4 * sizeof (UINT8)); memcpy( &(this->ubApproachMod), &(src.ubApproachMod), 3 * 4 * sizeof (UINT8)); - memcpy( &(this->bMercOpinion), &(src.bMercOpinion), 75 * sizeof (INT8)); + memcpy( &(this->bMercOpinion), &(src.bMercOpinion), DontUseMeDirectly::MaxIDToCheckForMorale * sizeof (INT8)); memcpy( &(this->usStatChangeChances), &(src.usStatChangeChances), 12 * sizeof (UINT16));// used strictly for balancing, never shown! memcpy( &(this->usStatChangeSuccesses), &(src.usStatChangeSuccesses), 12 * sizeof (UINT16));// used strictly for balancing, never shown! diff --git a/Tactical/opplist.cpp b/Tactical/opplist.cpp index f54fef430..fb286daca 100644 --- a/Tactical/opplist.cpp +++ b/Tactical/opplist.cpp @@ -4270,7 +4270,8 @@ void DebugSoldierPage3( ) SetFontShade(LARGEFONT1, FONT_SHADE_GREEN); gprintf( 0, LINE_HEIGHT * ubLine, L"NPC Opinion:"); SetFontShade(LARGEFONT1, FONT_SHADE_NEUTRAL); - gprintf( 150, LINE_HEIGHT * ubLine, L"%d", gMercProfiles[ pSoldier->ubProfile ].bMercOpinion[ MercPtrs[ gusSelectedSoldier ]->ubProfile ] ); + if (OKToCheckOpinion(MercPtrs[ gusSelectedSoldier ]->ubProfile)) + gprintf( 150, LINE_HEIGHT * ubLine, L"%d", gMercProfiles[ pSoldier->ubProfile ].bMercOpinion[ MercPtrs[ gusSelectedSoldier ]->ubProfile ] ); ubLine++; } diff --git a/Tactical/soldier profile type.h b/Tactical/soldier profile type.h index bc90fdb42..0332ea667 100644 --- a/Tactical/soldier profile type.h +++ b/Tactical/soldier profile type.h @@ -78,6 +78,20 @@ #define NEEDS_TRAINING_SKILL_VALUE 50 #define NO_CHANCE_IN_HELL_SKILL_VALUE 0 +// +// WDS 05/13/2009 +// This is a temporary fix and should be REALLY fixed someday. +// The bMercOpinion array in MERCPROFILESTRUCT below only contains 75 entries. That +// means profile ID#s of 75 and beyond are not valid to be used for checking morale. +// +namespace DontUseMeDirectly { + const static int MaxIDToCheckForMorale = 75; +} + +inline bool OKToCheckOpinion(int profileNumber) { + return (profileNumber < DontUseMeDirectly::MaxIDToCheckForMorale); +} + typedef enum { @@ -354,7 +368,10 @@ public: INT8 bTown; INT8 bTownAttachment; UINT16 usOptionalGearCost; - INT8 bMercOpinion[75]; + + // See above note near the definition of MaxIDToCheckForMorale + INT8 bMercOpinion[DontUseMeDirectly::MaxIDToCheckForMorale]; + INT8 bApproached; INT8 bMercStatus; //The status of the merc. If negative, see flags at the top of this file. Positive: The number of days the merc is away for. 0: Not hired but ready to be. INT8 bHatedTime[5]; @@ -589,7 +606,10 @@ public: INT8 bTown; INT8 bTownAttachment; UINT16 usOptionalGearCost; - INT8 bMercOpinion[75]; + + // See above note near the definition of MaxIDToCheckForMorale + INT8 bMercOpinion[DontUseMeDirectly::MaxIDToCheckForMorale]; + INT8 bApproached; INT8 bMercStatus; //The status of the merc. If negative, see flags at the top of this file. Positive: The number of days the merc is away for. 0: Not hired but ready to be. INT8 bHatedTime[5]; diff --git a/TacticalAI/NPC.cpp b/TacticalAI/NPC.cpp index 32f77373b..51818a2e5 100644 --- a/TacticalAI/NPC.cpp +++ b/TacticalAI/NPC.cpp @@ -575,7 +575,10 @@ UINT8 CalcDesireToTalk( UINT8 ubNPC, UINT8 ubMerc, INT8 bApproach ) pNPCProfile = &(gMercProfiles[ubNPC]); pMercProfile = &(gMercProfiles[ubMerc]); - iPersonalVal = 50 + pNPCProfile->bMercOpinion[ubMerc]; /* + pNPCProfile->bMercTownReputation[ pNPCProfile->bTown ] */; + iPersonalVal = 50; /* + pNPCProfile->bMercTownReputation[ pNPCProfile->bTown ] */; + if (OKToCheckOpinion(ubMerc)) { + iPersonalVal += pNPCProfile->bMercOpinion[ubMerc]; + } // ARM: NOTE - for towns which don't use loyalty (San Mona, Estoni, Tixa, Orta ) // loyalty will always remain 0 (this was OKed by Ian)