From d482f0e610215cac1e97dca655c88c24f2180396 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sun, 14 Aug 2022 12:42:18 +0300 Subject: [PATCH] Add healing items improvements (#29) --- src/combat_ai.cc | 6 ++---- src/item.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++ src/item.h | 8 +++++++ src/sfall_config.h | 1 + 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/combat_ai.cc b/src/combat_ai.cc index d76a1ab..da67e41 100644 --- a/src/combat_ai.cc +++ b/src/combat_ai.cc @@ -988,8 +988,7 @@ static int _ai_check_drugs(Object* critter) } int drugPid = drug->pid; - if ((drugPid == PROTO_ID_STIMPACK || drugPid == PROTO_ID_SUPER_STIMPACK || drugPid == PROTO_ID_HEALING_POWDER) - && itemRemove(critter, drug, 1) == 0) { + if (itemIsHealing(drugPid) && itemRemove(critter, drug, 1) == 0) { if (_item_d_take_drug(critter, drug) == -1) { itemAdd(critter, drug, 1); } else { @@ -1027,8 +1026,7 @@ static int _ai_check_drugs(Object* critter) } if (index < AI_PACKET_CHEM_PRIMARY_DESIRE_COUNT) { - if (drugPid != PROTO_ID_STIMPACK && drugPid != PROTO_ID_SUPER_STIMPACK && drugPid != 273 - && itemRemove(critter, drug, 1) == 0) { + if (!itemIsHealing(drugPid) && itemRemove(critter, drug, 1) == 0) { if (_item_d_take_drug(critter, drug) == -1) { itemAdd(critter, drug, 1); } else { diff --git a/src/item.cc b/src/item.cc index c688f2e..2415b95 100644 --- a/src/item.cc +++ b/src/item.cc @@ -67,6 +67,10 @@ static void explosionsInit(); static void explosionsReset(); static void explosionsExit(); +static void healingItemsInit(); +static void healingItemsInitVanilla(); +static void healingItemsInitCustom(); + typedef struct DrugDescription { int drugPid; int gvar; @@ -179,6 +183,7 @@ static int gExplosionFrm; static int gExplosionRadius; static int gExplosionDamageType; static int gExplosionMaxTargets; +static int gHealingItemPids[HEALING_ITEM_COUNT]; // 0x4770E0 int itemsInit() @@ -197,6 +202,7 @@ int itemsInit() // SFALL booksInit(); explosionsInit(); + healingItemsInit(); return 0; } @@ -3584,3 +3590,51 @@ void explosionSetMaxTargets(int maxTargets) { gExplosionMaxTargets = maxTargets; } + +static void healingItemsInit() +{ + healingItemsInitVanilla(); + healingItemsInitCustom(); +} + +static void healingItemsInitVanilla() +{ + gHealingItemPids[HEALING_ITEM_STIMPACK] = PROTO_ID_STIMPACK; + gHealingItemPids[HEALING_ITEM_SUPER_STIMPACK] = PROTO_ID_SUPER_STIMPACK; + gHealingItemPids[HEALING_ITEM_HEALING_POWDER] = PROTO_ID_HEALING_POWDER; +} + +static void healingItemsInitCustom() +{ + char* tweaksFilePath = NULL; + configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_TWEAKS_FILE_KEY, &tweaksFilePath); + if (tweaksFilePath != NULL && *tweaksFilePath == '\0') { + tweaksFilePath = NULL; + } + + if (tweaksFilePath == NULL) { + return; + } + + Config tweaksConfig; + if (configInit(&tweaksConfig)) { + if (configRead(&tweaksConfig, tweaksFilePath, false)) { + configGetInt(&gSfallConfig, "Items", "STIMPAK", &(gHealingItemPids[HEALING_ITEM_STIMPACK])); + configGetInt(&gSfallConfig, "Items", "SUPER_STIMPAK", &(gHealingItemPids[HEALING_ITEM_SUPER_STIMPACK])); + configGetInt(&gSfallConfig, "Items", "HEALING_POWDER", &(gHealingItemPids[HEALING_ITEM_HEALING_POWDER])); + } + + configFree(&tweaksConfig); + } +} + +bool itemIsHealing(int pid) +{ + for (int index = 0; index < HEALING_ITEM_COUNT; index++) { + if (gHealingItemPids[index] == pid) { + return true; + } + } + + return false; +} diff --git a/src/item.h b/src/item.h index 2bd2189..012590d 100644 --- a/src/item.h +++ b/src/item.h @@ -13,6 +13,13 @@ typedef enum _WeaponClass { ATTACK_TYPE_COUNT, } WeaponClass; +typedef enum HealingItem { + HEALING_ITEM_STIMPACK, + HEALING_ITEM_SUPER_STIMPACK, + HEALING_ITEM_HEALING_POWDER, + HEALING_ITEM_COUNT, +} HealingItem; + int itemsInit(); void itemsReset(); void itemsExit(); @@ -143,5 +150,6 @@ int explosionGetDamageType(); void explosionSetDamageType(int damageType); int explosionGetMaxTargets(); void explosionSetMaxTargets(int maxTargets); +bool itemIsHealing(int pid); #endif /* ITEM_H */ diff --git a/src/sfall_config.h b/src/sfall_config.h index c852932..0956e23 100644 --- a/src/sfall_config.h +++ b/src/sfall_config.h @@ -54,6 +54,7 @@ #define SFALL_CONFIG_USE_REPAIR_FRM_KEY "Repair" #define SFALL_CONFIG_SCIENCE_REPAIR_TARGET_TYPE_KEY "ScienceOnCritters" #define SFALL_CONFIG_GAME_DIALOG_FIX_KEY "DialogueFix" +#define SFALL_CONFIG_TWEAKS_FILE_KEY "TweaksFile" #define SFALL_CONFIG_BURST_MOD_DEFAULT_CENTER_MULTIPLIER 1 #define SFALL_CONFIG_BURST_MOD_DEFAULT_CENTER_DIVISOR 3