From 87eca4898a359b788467af8890c25e8eb9f67f28 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 18 Jul 2024 08:36:30 +0800 Subject: [PATCH] Scripting headers: add material-related constants, minor lib extensions --- artifacts/scripting/headers/define_extra.h | 16 +++++ artifacts/scripting/headers/lib.arrays.h | 16 +++-- artifacts/scripting/headers/lib.inven.h | 72 ++++++---------------- 3 files changed, 48 insertions(+), 56 deletions(-) diff --git a/artifacts/scripting/headers/define_extra.h b/artifacts/scripting/headers/define_extra.h index 722f2b3c..2c2c74f6 100644 --- a/artifacts/scripting/headers/define_extra.h +++ b/artifacts/scripting/headers/define_extra.h @@ -306,6 +306,22 @@ #define PROTO_CR_AI_PACKET (408) #define PROTO_CR_TEAM_NUM (412) +// scenery +#define PROTO_SC_MATERIAL (44) + +// walls +#define PROTO_WL_MATERIAL (32) + +// material types +#define MATERIAL_TYPE_GLASS (0) +#define MATERIAL_TYPE_METAL (1) +#define MATERIAL_TYPE_PLASTIC (2) +#define MATERIAL_TYPE_WOOD (3) +#define MATERIAL_TYPE_DIRT (4) +#define MATERIAL_TYPE_STONE (5) +#define MATERIAL_TYPE_CEMENT (6) +#define MATERIAL_TYPE_LEATHER (7) + // weapon calibers #define CALIBER_NONE (0) #define CALIBER_ROCKET (1) diff --git a/artifacts/scripting/headers/lib.arrays.h b/artifacts/scripting/headers/lib.arrays.h index 37e0a58a..e99e14f9 100644 --- a/artifacts/scripting/headers/lib.arrays.h +++ b/artifacts/scripting/headers/lib.arrays.h @@ -554,14 +554,14 @@ procedure array_transform_kv(variable arr, variable keyFunc, variable valueFunc) end /** - * Converts given array into a new map where keys are array values and all values are 1. + * Converts given array into a new map where keys are array values and all values are set to specified value. * @arg {array} arr * @ret {array} */ -procedure array_to_set(variable arr) begin +procedure array_to_set(variable arr, variable value := 1) begin variable v, retArr := temp_array_map; foreach (v in arr) begin - retArr[v] := 1; + retArr[v] := value; end return retArr; end @@ -641,7 +641,7 @@ procedure array_fill(variable arr, variable pos, variable count, variable value) end /** - * Adds all the values of the second array to the first array. + * Adds all the values of the second array to the first array. If arr1 is a map then for values with same keys, values from arr2 will take priority. * @arg {array} arr1 * @arg {array} arr2 * @ret {array} - the first array after modification @@ -661,6 +661,14 @@ procedure array_append(variable arr1, variable arr2) begin return arr1; end +/** + * Creates a new temp array with all values from arr1 and arr2. If arr1 is a map then for values with same keys, values from arr2 will take priority. + * @arg {array} arr1 + * @arg {array} arr2 + * @ret {array} - the created temp array + */ +#define array_concat(arr1, arr2) array_append(clone_array(arr1), arr2) + /** * Loads a "saved" array. If it doesn't exist, creates it (with a given size). * @arg {string} name - saved array name/key diff --git a/artifacts/scripting/headers/lib.inven.h b/artifacts/scripting/headers/lib.inven.h index 23a58552..cdffd7d2 100644 --- a/artifacts/scripting/headers/lib.inven.h +++ b/artifacts/scripting/headers/lib.inven.h @@ -65,6 +65,21 @@ procedure unwield_armor(variable critter) begin end end +/** + * Makes critter put away given item if it's in armor or any item/weapon slot. + * @arg {ObjectPtr} critter + * @arg {ObjectPtr} item + */ +procedure inven_unwield_item(variable critter, variable item) begin + if (obj_type(critter) != OBJ_TYPE_CRITTER) then return; + + if (critter_inven_obj(critter, INVEN_TYPE_WORN) == item) then begin + call unwield_armor(critter); + end else if ((critter_inven_obj(critter, INVEN_TYPE_LEFT_HAND) == item) or (critter_inven_obj(critter, INVEN_TYPE_RIGHT_HAND) == item)) then begin + inven_unwield(critter); + end +end + /** * Removes items of given pid from given object's inventory. Returns number of actually removed items. * @arg {ObjectPtr} invenObj - obj to remove items from @@ -86,13 +101,7 @@ procedure remove_items_pid(variable invenObj, variable itemPid, variable quantit toRemoveQty := quantity; while (quantity > 0) do begin item := obj_carrying_pid_obj(invenObj, itemPid); - if (obj_type(invenObj) == OBJ_TYPE_CRITTER) then begin - if (critter_inven_obj(invenObj, INVEN_TYPE_WORN) == item) then begin - call unwield_armor(invenObj); - end else if ((critter_inven_obj(invenObj, INVEN_TYPE_LEFT_HAND) == item) or (critter_inven_obj(invenObj, INVEN_TYPE_RIGHT_HAND) == item)) then begin - inven_unwield(invenObj); - end - end + call inven_unwield_item(invenObj, item); quantity -= rm_mult_objs_from_inven(invenObj, item, quantity); destroy_object(item); end @@ -100,19 +109,14 @@ procedure remove_items_pid(variable invenObj, variable itemPid, variable quantit end /** - * Remove the whole stack of a given *item* object from *invenObj* inventory. + * Remove one item from a given *item* stack object from *invenObj* inventory. * For a critter, this will correctly remove item from armor/hand slot, if it is equipped. + * Note that *item* pointer will be invalid after this. * @arg {ObjectPtr} invenObj - obj to remove from * @arg {ObjectPtr} item - item (stack) object to remove */ procedure remove_item_obj(variable invenObj, variable item) begin - if (obj_type(invenObj) == OBJ_TYPE_CRITTER) then begin - if (critter_inven_obj(invenObj,INVEN_TYPE_WORN) == item) then begin - call unwield_armor(invenObj); - end else if ((critter_inven_obj(invenObj, INVEN_TYPE_LEFT_HAND) == item) or (critter_inven_obj(invenObj, INVEN_TYPE_RIGHT_HAND) == item)) then begin - inven_unwield(invenObj); - end - end + call inven_unwield_item(invenObj, item); rm_obj_from_inven(invenObj, item); destroy_object(item); end @@ -136,7 +140,7 @@ end /** * Ensures a given *quantity* of *itemPid* in *invenObj* inventory, adding or removing items as necessary. * @arg {ObjectPtr} invenObj - obj to add/remove items to/from - * @arg {int} itemPid - PID of item to remove + * @arg {int} itemPid - PID of item to add/remove * @arg {int} quantity */ procedure set_items_qty_pid(variable invenObj, variable itemPid, variable quantity) @@ -154,42 +158,6 @@ begin end end -/** - * Removes money and items from a *critter*'s inventory, using provided probabilities (applied to whole stacks, not individual items). - * Useful for reducing loot of merchants after death. - * @arg {ObjectPtr} critter - * @arg {int} moneyPercent - Percent of money to remove. - * @arg {int} probArmor - % probability to remove armor. - * @arg {int} probDrugs - % probability to remove drugs. - * @arg {int} probWeapons - % probability to remove weapons. - * @arg {int} probAmmo - % probability to remove ammo. - * @arg {int} probMisc - % probability to remove misc item. - */ -procedure reduce_merchant_loot(variable critter, variable moneyPercent, variable probArmor, variable probDrugs, variable probWeapons, variable probAmmo, variable probMisc) begin - variable inv, item, it, prob, tmp; - inv := inven_as_array(critter); - item_caps_adjust(critter, -(item_caps_total(critter) * moneyPercent / 100)); - //display_msg("total items "+len_array(inv)); - foreach item in inv begin - if (obj_pid(item) != PID_BOTTLE_CAPS) then begin - it := obj_item_subtype(item); - if (it == item_type_armor) then - prob := probArmor; - else if (it == item_type_drug) then - prob := probDrugs; - else if (it == item_type_weapon) then - prob := probWeapons; - else if (it == item_type_ammo) then - prob := probAmmo; - else - prob := probMisc; - if (random(0, 99) < prob) then begin - //display_msg("remove "+obj_name(item)); - call remove_all_items_pid(critter, obj_pid(item)); - end - end - end -end /** * Returns item in one of *critter*'s hand slots using given attack type.