From d5268f3fbc69a29734a932d286a5d6553cb05cec Mon Sep 17 00:00:00 2001 From: phobos2077 Date: Thu, 25 May 2023 02:37:51 +0200 Subject: [PATCH] Small update to headers --- artifacts/scripting/headers/command_lite.h | 1 + artifacts/scripting/headers/define_extra.h | 3 ++ artifacts/scripting/headers/lib.arrays.h | 8 ++-- artifacts/scripting/headers/lib.inven.h | 1 + artifacts/scripting/headers/lib.math.h | 50 ++++++++-------------- artifacts/scripting/headers/lib.misc.h | 30 +++++-------- 6 files changed, 39 insertions(+), 54 deletions(-) diff --git a/artifacts/scripting/headers/command_lite.h b/artifacts/scripting/headers/command_lite.h index 015df3b7..26e7497a 100644 --- a/artifacts/scripting/headers/command_lite.h +++ b/artifacts/scripting/headers/command_lite.h @@ -82,6 +82,7 @@ (critter_state(dude_obj) bwand DAM_CRIP_ARM_LEFT) orElse \ (critter_state(dude_obj) bwand DAM_CRIP_ARM_RIGHT)) +#define get_cur_rot(cr) has_trait(TRAIT_OBJECT,cr,OBJECT_CUR_ROT) #define dude_cur_rot (has_trait(TRAIT_OBJECT,dude_obj,OBJECT_CUR_ROT)) #define dude_inv_rot ((dude_cur_rot + 3)%6) #define dude_tile (tile_num(dude_obj)) diff --git a/artifacts/scripting/headers/define_extra.h b/artifacts/scripting/headers/define_extra.h index 273a9c10..cde2e6b1 100644 --- a/artifacts/scripting/headers/define_extra.h +++ b/artifacts/scripting/headers/define_extra.h @@ -277,6 +277,8 @@ // critters #define PROTO_CR_FLAGS (32) // Critter Flags +#define PROTO_CR_BASE_STATS (36) // 35 stats, see STAT_* +#define PROTO_CR_BONUS_STATS (176) // 35 stats, see STAT_* #define PROTO_CR_BONUS_SRENGTH (176) #define PROTO_CR_BONUS_PRCEPTION (180) #define PROTO_CR_BONUS_ENDURANCE (184) @@ -294,6 +296,7 @@ #define PROTO_CR_BONUS_HEALING_RATE (232) #define PROTO_CR_BONUS_CRITICAL_CHANCE (236) #define PROTO_CR_BONUS_BETTER_CRITICALS (240) +#define PROTO_CR_SKILLS (316) // 18 skills, see SKILL_* #define PROTO_CR_BODY_TYPE (388) #define PROTO_CR_KILL_EXP (392) #define PROTO_CR_KILL_TYPE (396) diff --git a/artifacts/scripting/headers/lib.arrays.h b/artifacts/scripting/headers/lib.arrays.h index 8bee30d8..75bd1594 100644 --- a/artifacts/scripting/headers/lib.arrays.h +++ b/artifacts/scripting/headers/lib.arrays.h @@ -284,7 +284,9 @@ procedure copy_array(variable src, variable srcPos, variable dest, variable dstP end end -// create exact copy of the array as a new temp array +/** + * Creates a shallow copy of the array as a new temp array. + */ procedure clone_array(variable array) begin variable new, k, v; if (array_is_map(array)) then @@ -399,9 +401,9 @@ procedure remove_array_set(variable array, variable item) begin end end -// use callback on each array element +// Transform every value in array using given callback procedure array_map_func(variable arr, variable callback) begin - variable k, v, i; + variable k, v; foreach (k: v in arr) arr[k] := callback(v); return arr; diff --git a/artifacts/scripting/headers/lib.inven.h b/artifacts/scripting/headers/lib.inven.h index 8d66ff09..bde7de04 100644 --- a/artifacts/scripting/headers/lib.inven.h +++ b/artifacts/scripting/headers/lib.inven.h @@ -3,6 +3,7 @@ #define LIB_INVEN_H #include "define_lite.h" +#include "define_extra.h" #define PID_BOTTLE_CAPS (41) /** diff --git a/artifacts/scripting/headers/lib.math.h b/artifacts/scripting/headers/lib.math.h index f649c4fd..a854741c 100644 --- a/artifacts/scripting/headers/lib.math.h +++ b/artifacts/scripting/headers/lib.math.h @@ -16,42 +16,30 @@ pure procedure unsigned_comp(variable a, variable b) begin return 1 if ((b == 0) orElse a div b) else -1; end -#define MAX(x, y) ((x > y) * x + (x <= y) * y) -#define MIN(x, y) ((x < y) * x + (x >= y) * y) -#define in_range(x, from, to) (x >= from and x <= to) +#define MAX(x, y) ((x > y) * x + (x <= y) * y) +#define MIN(x, y) ((x < y) * x + (x >= y) * y) -procedure max(variable x, variable y) begin - if (x > y) then return x; - return y; -end +#define math_max(x, y) (x if x > y else y) +#define math_min(x, y) (x if x < y else y) +#define in_range(x, from, to) (x >= from and x <= to) -procedure min(variable x, variable y) begin - if (x < y) then return x; - return y; -end -/*procedure round(variable val) begin - variable intp; - intp := floor(val); - if ((val-intp) >= 0.5) then intp++; - return intp; -end*/ - -/*procedure ceil(variable val) begin - variable intp; - intp := floor(val); - if (abs(val-intp) > 0.0) then begin - intp++; +procedure get_clamped(variable val, variable a, variable b) begin + variable min, max; + if (a < b) then begin + min := a; + max := b; + end else begin + min := b; + max := a; end - return intp; -end*/ - -procedure cap_number(variable num, variable min, variable max) begin - if (num > max) then num := max; - else if (num < min) then num := min; - return num; + if (val < min) then + return min; + else if (val > max) then + return max; + else + return val; end - #endif diff --git a/artifacts/scripting/headers/lib.misc.h b/artifacts/scripting/headers/lib.misc.h index b730931b..c683e671 100644 --- a/artifacts/scripting/headers/lib.misc.h +++ b/artifacts/scripting/headers/lib.misc.h @@ -59,27 +59,17 @@ procedure hotkey_pressed_now(variable n, variable key) begin end end - - -/** - Attempt to make list_as_array safe -*/ -/*procedure list_as_array_safe(variable type) begin - variable list, item, arr, i; - list := list_begin(type); - arr := temp_array(100, 4); - i := 0; - item := list_next(list); - while (item) do begin - if (len_array(arr) == i) then resize_array(arr, len_array(arr) + 100); - arr[i] := item; - item := list_next(list); - i++; +// Loads ini section as map of keys and values parsed as integers (0 values will be skipped!) +procedure get_ini_section_int_to_int(variable file, variable section, variable fixArray := false) begin + variable ar, ar2 := temp_array_map, k, v; + ar := get_ini_section(file, section); + foreach k: v in ar begin + ar2[atoi(k)] := atoi(v); end - resize_array(arr, i); - list_end(list); - return arr; -end*/ + if (fixArray) then + fix_array(ar2); + return ar2; +end #endif