From 5607d57385764744eee09165813b5b0ca5d71466 Mon Sep 17 00:00:00 2001 From: Sevenfm Date: Tue, 11 May 2021 04:56:58 +0000 Subject: [PATCH] If refilling canteen makes merc to automatically drink, drinking should make merc to automatically refill canteen - which gives player a way how to refill empty canteen while in battle (by Shadooow). https://discord.com/channels/348449397308391426/821085354009952307/841090805435072522 git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9017 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Food.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Tactical/Food.cpp b/Tactical/Food.cpp index 8aafdccae..2c7650f07 100644 --- a/Tactical/Food.cpp +++ b/Tactical/Food.cpp @@ -1142,13 +1142,44 @@ void DrinkFromWaterTap( SOLDIERTYPE* pSoldier ) } } - if ( GetWaterQuality( gWorldSectorX, gWorldSectorY, gbWorldSectorZ ) == WATER_POISONOUS ) + UINT8 waterquality = GetWaterQuality(gWorldSectorX, gWorldSectorY, gbWorldSectorZ); + if ( waterquality == WATER_POISONOUS ) HandlePossibleInfection( pSoldier, NULL, INFECTION_TYPE_BADWATER ); INT32 bpadded = 100 * min( 20, 100 - pSoldier->bBreath ); DeductPoints( pSoldier, 20, -bpadded ); + if (waterquality == WATER_DRINKABLE)//todo possibly allow refill with poisonous water + { + // the temperature of the water in this sector (temperature reflects the quality) + FLOAT addtemperature = OVERHEATING_MAX_TEMPERATURE; + + // first step: fill all canteens in inventories + INT8 invsize = (INT8)pSoldier->inv.size(); // remember inventorysize, so we don't call size() repeatedly + for (INT8 bLoop = 0; bLoop < invsize; ++bLoop) // ... for all items in our inventory ... + { + // ... if Item exists and is canteen (that can have drink points) ... + if (pSoldier->inv[bLoop].exists() == true && Item[pSoldier->inv[bLoop].usItem].canteen && Food[Item[pSoldier->inv[bLoop].usItem].foodtype].bDrinkPoints > 0) + { + OBJECTTYPE* pObj = &(pSoldier->inv[bLoop]); // ... get pointer for this item ... + + if (pObj != NULL) // ... if pointer is not obviously useless ... + { + for (INT16 i = 0; i < pObj->ubNumberOfObjects; ++i) // ... there might be multiple items here (item stack), so for each one ... + { + UINT16 status = (*pObj)[i]->data.objectStatus; + UINT16 statusmmissing = max(0, 100 - status); + FLOAT temperature = (*pObj)[i]->data.bTemperature; + + (*pObj)[i]->data.objectStatus = 100; // refill canteen + (*pObj)[i]->data.bTemperature = (status * temperature + statusmmissing * addtemperature) / 100; + } + } + } + } + } + // play water sound if ( pSoldier->bTeam == gbPlayerNum && gGameExternalOptions.fFoodEatingSounds ) {