From 253db894600de5aea9a1ddd915402f20625c2a98 Mon Sep 17 00:00:00 2001 From: Flugente Date: Thu, 24 Jan 2019 21:38:08 +0000 Subject: [PATCH] - Drug effects on first aid kits can be applied during bandaging - Drug consumption opinion event, Larry personality change and increase of 'drugs taken' counter only occur if a drug if genuine drug effects were applied. As a result purely disease-causing items no longer cause these events. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8649 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Drugs And Alcohol.cpp | 50 ++++++++++++++++++++-------------- Tactical/Soldier Control.cpp | 4 +++ Tactical/UI Cursors.cpp | 3 +- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/Tactical/Drugs And Alcohol.cpp b/Tactical/Drugs And Alcohol.cpp index 3fa3df900..11237d161 100644 --- a/Tactical/Drugs And Alcohol.cpp +++ b/Tactical/Drugs And Alcohol.cpp @@ -42,6 +42,9 @@ BOOLEAN ApplyDrugs_New( SOLDIERTYPE *pSoldier, UINT16 usItem, UINT16 uStatusUsed UINT32 drugused = Item[usItem].drugtype; + // to stop Larry from getting stoned via unsanitary bandages etc., note whether this is a 'real' drug + BOOL complainworthyeffects = FALSE; + // we might not use up the entire item, so reduce effects accordingly FLOAT effectivepercentage = uStatusUsed / 100.0; @@ -93,6 +96,8 @@ BOOLEAN ApplyDrugs_New( SOLDIERTYPE *pSoldier, UINT16 usItem, UINT16 uStatusUsed pSoldier->newdrugs.duration[(*drug_effects_it).effect] = (*drug_effects_it).duration; pSoldier->newdrugs.size[(*drug_effects_it).effect] = (*drug_effects_it).size * effectivepercentage; } + + complainworthyeffects = TRUE; } } @@ -147,28 +152,31 @@ BOOLEAN ApplyDrugs_New( SOLDIERTYPE *pSoldier, UINT16 usItem, UINT16 uStatusUsed } } } - - // do switch for Larry!! - if ( pSoldier->ubProfile == LARRY_NORMAL ) - { - SwapToProfile( pSoldier, LARRY_DRUNK ); - - gMercProfiles[LARRY_NORMAL].bNPCData = LARRY_FALLS_OFF_WAGON; - } - else if ( pSoldier->ubProfile == LARRY_DRUNK ) - { - // NB store all drunkenness info in LARRY_NORMAL profile (to use same values) - // so long as he keeps consuming, keep number above level at which he cracked - gMercProfiles[LARRY_NORMAL].bNPCData += (INT8)Random( 5 ); - - // allow value to keep going up to 24 (about 2 days since we subtract Random( 2 ) when he has no access ) - gMercProfiles[LARRY_NORMAL].bNPCData = __min( gMercProfiles[LARRY_NORMAL].bNPCData, 24 ); - gMercProfiles[LARRY_NORMAL].bNPCData = __max( gMercProfiles[LARRY_NORMAL].bNPCData, LARRY_FALLS_OFF_WAGON ); - } - if ( NewDrug[drugused].opinionevent ) + if ( complainworthyeffects ) { - HandleDynamicOpinionChange( pSoldier, OPINIONEVENT_ADDICT, TRUE, TRUE ); + // do switch for Larry!! + if ( pSoldier->ubProfile == LARRY_NORMAL ) + { + SwapToProfile( pSoldier, LARRY_DRUNK ); + + gMercProfiles[LARRY_NORMAL].bNPCData = LARRY_FALLS_OFF_WAGON; + } + else if ( pSoldier->ubProfile == LARRY_DRUNK ) + { + // NB store all drunkenness info in LARRY_NORMAL profile (to use same values) + // so long as he keeps consuming, keep number above level at which he cracked + gMercProfiles[LARRY_NORMAL].bNPCData += (INT8)Random( 5 ); + + // allow value to keep going up to 24 (about 2 days since we subtract Random( 2 ) when he has no access ) + gMercProfiles[LARRY_NORMAL].bNPCData = __min( gMercProfiles[LARRY_NORMAL].bNPCData, 24 ); + gMercProfiles[LARRY_NORMAL].bNPCData = __max( gMercProfiles[LARRY_NORMAL].bNPCData, LARRY_FALLS_OFF_WAGON ); + } + + if ( NewDrug[drugused].opinionevent ) + { + HandleDynamicOpinionChange( pSoldier, OPINIONEVENT_ADDICT, TRUE, TRUE ); + } } if ( Item[usItem].alcohol > 0.0f ) @@ -193,7 +201,7 @@ BOOLEAN ApplyDrugs_New( SOLDIERTYPE *pSoldier, UINT16 usItem, UINT16 uStatusUsed // set flag: we are on non-alcoholic drugs pSoldier->usSoldierFlagMask |= SOLDIER_DRUGGED; - if ( gMercProfiles[pSoldier->ubProfile].ubNumTimesDrugUseInLifetime != 255 ) + if ( complainworthyeffects && gMercProfiles[pSoldier->ubProfile].ubNumTimesDrugUseInLifetime != 255 ) { gMercProfiles[pSoldier->ubProfile].ubNumTimesDrugUseInLifetime++; } diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index b5e53b48b..11b9ecca6 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -13044,6 +13044,10 @@ void SOLDIERTYPE::EVENT_SoldierBeginFirstAid( INT32 sGridNo, UINT8 ubDirection ) // Flugente: additional dialogue AdditionalTacticalCharacterDialogue_CallsLua( this, ADE_BANDAGE_PERFORM_BEGIN, pTSoldier->ubProfile ); AdditionalTacticalCharacterDialogue_CallsLua( pTSoldier, ADE_BANDAGE_RECEIVE_BEGIN, this->ubProfile ); + + // Flugente: if the medkit we use has drug effects set, apply them + // as a kit is used up over time, applying it several times would screw with chance effects, so just apply once + ApplyDrugs_New( pTSoldier, this->inv[HANDPOS].usItem, ( ( this->inv[HANDPOS] ) )[0]->data.objectStatus ); } } diff --git a/Tactical/UI Cursors.cpp b/Tactical/UI Cursors.cpp index 85476b052..bbe4a3dd2 100644 --- a/Tactical/UI Cursors.cpp +++ b/Tactical/UI Cursors.cpp @@ -2884,7 +2884,8 @@ UINT8 GetActionModeCursor( SOLDIERTYPE *pSoldier ) } // Flugente: apply misc items to other soldiers - if ( ItemCanBeAppliedToOthers( usInHand ) ) + // exception: not for medical items (medkists can have drug effects that are applied during bandaging) + if ( ubCursor != AIDCURS && ItemCanBeAppliedToOthers( usInHand ) ) { // if item is a bomb, only allow apply if hovering over a soldier (otherwise we cannot mine anymore) if ( Item[ usInHand ].usItemClass & IC_BOMB )