mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Unified the indent style (3 spaces) in SSL library and removed trailing spaces.
This commit is contained in:
@@ -895,16 +895,11 @@
|
|||||||
|
|
||||||
//Misc commands
|
//Misc commands
|
||||||
#define obj_get_rot(obj) (has_trait(TRAIT_OBJECT, obj, OBJECT_CUR_ROT))
|
#define obj_get_rot(obj) (has_trait(TRAIT_OBJECT, obj, OBJECT_CUR_ROT))
|
||||||
|
#define obj_in_party(x) (party_member_obj(obj_pid(x)) != 0)
|
||||||
|
|
||||||
|
#define dude_tile (tile_num(dude_obj))
|
||||||
|
#define dude_elevation (elevation(dude_obj))
|
||||||
|
#define dude_skill(x) (has_skill(dude_obj, x))
|
||||||
#define obj_in_party(x) (party_member_obj(obj_pid(x)) != 0)
|
|
||||||
|
|
||||||
#define dude_tile (tile_num(dude_obj))
|
|
||||||
#define dude_elevation (elevation(dude_obj))
|
|
||||||
|
|
||||||
#define dude_skill(x) (has_skill(dude_obj, x))
|
|
||||||
|
|
||||||
|
|
||||||
// some commands
|
// some commands
|
||||||
@@ -913,5 +908,3 @@
|
|||||||
#define g_mstr(x) message_str(SCRIPT_GENERIC,x)
|
#define g_mstr(x) message_str(SCRIPT_GENERIC,x)
|
||||||
|
|
||||||
#endif // DEFINE_H
|
#endif // DEFINE_H
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
This library contains procedures which should ease working with sfall arrays.
|
This library contains procedures which should ease working with sfall arrays.
|
||||||
sfall v3.4 or higher is required
|
sfall v3.4 or higher is required
|
||||||
|
|
||||||
WARNING!!!
|
WARNING!!!
|
||||||
1. This library may contain bugs, so test each method before you use it.
|
1. This library may contain bugs, so test each method before you use it.
|
||||||
2. Author is not responsible for any damage to your mod or your savegames when using this library.
|
2. Author is not responsible for any damage to your mod or your savegames when using this library.
|
||||||
It is provided AS IS.
|
It is provided AS IS.
|
||||||
|
|
||||||
@author phobos2077
|
@author phobos2077
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIB_ARRAYS_H
|
#ifndef LIB_ARRAYS_H
|
||||||
@@ -66,7 +66,7 @@ procedure array_sum(variable arr);
|
|||||||
procedure array_random_value(variable arr);
|
procedure array_random_value(variable arr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill array (or it's part) with the same value.
|
* Fill array (or it's part) with the same value.
|
||||||
* pos - starting position
|
* pos - starting position
|
||||||
* count - number of items to fill (use -1 to fill to the end of the array)
|
* count - number of items to fill (use -1 to fill to the end of the array)
|
||||||
* value - value to set
|
* value - value to set
|
||||||
@@ -92,21 +92,21 @@ procedure remove_array_set(variable array, variable item);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Array of blocks functions (allows to use arrays as arrays of "objects", where "object" properties are bound to
|
Array of blocks functions (allows to use arrays as arrays of "objects", where "object" properties are bound to
|
||||||
relative offsets in one array)
|
relative offsets in one array)
|
||||||
Recommended use case:
|
Recommended use case:
|
||||||
1) create a block for each "object"
|
1) create a block for each "object"
|
||||||
2) define macros like (example):
|
2) define macros like (example):
|
||||||
#define TRAP_OFSET_TILE (5)
|
#define TRAP_OFSET_TILE (5)
|
||||||
#define trap_tile(array, index) (array[index + TRAP_OFSET_TILE])
|
#define trap_tile(array, index) (array[index + TRAP_OFSET_TILE])
|
||||||
#define trap_tile_set(array, index, value) (array[index + TRAP_OFSET_TILE] := value)
|
#define trap_tile_set(array, index, value) (array[index + TRAP_OFSET_TILE] := value)
|
||||||
3) use them to read and write object properties;
|
3) use them to read and write object properties;
|
||||||
4) use while loop with step equal to blocksize to iterate over all objects
|
4) use while loop with step equal to blocksize to iterate over all objects
|
||||||
5) 0 offset is always equal to object "ID" (starting index of block)
|
5) 0 offset is always equal to object "ID" (starting index of block)
|
||||||
|
|
||||||
DEPRECATED, use collections instead
|
DEPRECATED, use collections instead
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds new empty place for a new block into array. Returns index of new block that was "created".
|
* Adds new empty place for a new block into array. Returns index of new block that was "created".
|
||||||
*/
|
*/
|
||||||
@@ -155,16 +155,16 @@ procedure load_collection(variable name);
|
|||||||
* Returns first index of zero value
|
* Returns first index of zero value
|
||||||
*/
|
*/
|
||||||
procedure get_empty_array_index(variable array) begin
|
procedure get_empty_array_index(variable array) begin
|
||||||
variable zero := false;
|
variable zero := false;
|
||||||
variable i := 0;
|
variable i := 0;
|
||||||
while i < len_array(array) and not(zero) do begin
|
while i < len_array(array) and not(zero) do begin
|
||||||
if (array[i] == 0) then begin
|
if (array[i] == 0) then begin
|
||||||
zero := true; // break
|
zero := true; // break
|
||||||
end else begin
|
end else begin
|
||||||
i++;
|
i++;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return i;
|
return i;
|
||||||
end
|
end
|
||||||
|
|
||||||
// push new item at the end of array
|
// push new item at the end of array
|
||||||
@@ -252,11 +252,11 @@ procedure array_diff(variable arr1, variable arr2) begin
|
|||||||
foreach (v in arr2) begin
|
foreach (v in arr2) begin
|
||||||
i := scan_array(arr1, v);
|
i := scan_array(arr1, v);
|
||||||
if (i != -1) then begin
|
if (i != -1) then begin
|
||||||
if (isMap) then
|
if (isMap) then
|
||||||
unset_array(arr1, i);
|
unset_array(arr1, i);
|
||||||
else
|
else
|
||||||
call array_cut(arr1, i, 1);
|
call array_cut(arr1, i, 1);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return arr1;
|
return arr1;
|
||||||
end
|
end
|
||||||
@@ -282,8 +282,8 @@ procedure clone_array(variable array) begin
|
|||||||
new := temp_array_list(len_array(array));
|
new := temp_array_list(len_array(array));
|
||||||
foreach k: v in array begin
|
foreach k: v in array begin
|
||||||
new[k] := v;
|
new[k] := v;
|
||||||
end
|
end
|
||||||
return new;
|
return new;
|
||||||
end
|
end
|
||||||
|
|
||||||
procedure arrays_equal(variable arr1, variable arr2) begin
|
procedure arrays_equal(variable arr1, variable arr2) begin
|
||||||
@@ -344,48 +344,48 @@ end
|
|||||||
|
|
||||||
|
|
||||||
procedure add_array_set(variable array, variable item) begin
|
procedure add_array_set(variable array, variable item) begin
|
||||||
variable i := 0;
|
variable i := 0;
|
||||||
variable len;
|
variable len;
|
||||||
variable exist := false;
|
variable exist := false;
|
||||||
variable zero := false;
|
variable zero := false;
|
||||||
len := len_array(array);
|
len := len_array(array);
|
||||||
|
|
||||||
// search for first empty space and also check if item exists
|
// search for first empty space and also check if item exists
|
||||||
while i < len and not(zero) do begin
|
while i < len and not(zero) do begin
|
||||||
if (array[i] == 0) then begin
|
if (array[i] == 0) then begin
|
||||||
zero := true; // break
|
zero := true; // break
|
||||||
i--;
|
i--;
|
||||||
end else if (array[i] == item) then exist := true;
|
end else if (array[i] == item) then exist := true;
|
||||||
i++;
|
i++;
|
||||||
end
|
end
|
||||||
if not(exist) then begin
|
if not(exist) then begin
|
||||||
// if no empty space, resize array
|
// if no empty space, resize array
|
||||||
if (i == len) then begin
|
if (i == len) then begin
|
||||||
resize_array(array, len + ARRAY_SET_BLOCK_SIZE);
|
resize_array(array, len + ARRAY_SET_BLOCK_SIZE);
|
||||||
end
|
end
|
||||||
set_array(array, i, item);
|
set_array(array, i, item);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
procedure remove_array_set(variable array, variable item) begin
|
procedure remove_array_set(variable array, variable item) begin
|
||||||
variable i := 0;
|
variable i := 0;
|
||||||
variable len;
|
variable len;
|
||||||
variable found_at := -1;
|
variable found_at := -1;
|
||||||
variable zero := false;
|
variable zero := false;
|
||||||
|
|
||||||
len := len_array(array);
|
len := len_array(array);
|
||||||
// search for first empty space and also check if item exists
|
// search for first empty space and also check if item exists
|
||||||
while (i < len and not(zero)) do begin
|
while (i < len and not(zero)) do begin
|
||||||
if (array[i] == 0) then begin
|
if (array[i] == 0) then begin
|
||||||
zero := true; // break
|
zero := true; // break
|
||||||
i--;
|
i--;
|
||||||
end else if (array[i] == item) then found_at := i;
|
end else if (array[i] == item) then found_at := i;
|
||||||
i++;
|
i++;
|
||||||
end
|
end
|
||||||
if (found_at != -1) then begin
|
if (found_at != -1) then begin
|
||||||
array[found_at] := array[i - 1];
|
array[found_at] := array[i - 1];
|
||||||
array[i - 1] := 0;
|
array[i - 1] := 0;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
// use callback on each array element
|
// use callback on each array element
|
||||||
@@ -404,27 +404,27 @@ end
|
|||||||
* DEPRECATED, use collections instead
|
* DEPRECATED, use collections instead
|
||||||
*/
|
*/
|
||||||
procedure add_array_block(variable arr, variable blocksize) begin
|
procedure add_array_block(variable arr, variable blocksize) begin
|
||||||
variable begin
|
variable begin
|
||||||
index := 0;
|
index := 0;
|
||||||
zero := false;
|
zero := false;
|
||||||
tile;
|
tile;
|
||||||
elev;
|
elev;
|
||||||
end
|
end
|
||||||
// find empty array index
|
// find empty array index
|
||||||
index := 0;
|
index := 0;
|
||||||
while index < len_array(arr) and not(zero) do begin
|
while index < len_array(arr) and not(zero) do begin
|
||||||
if (get_array(arr, index) == ARRAY_EMPTY_INDEX) then begin
|
if (get_array(arr, index) == ARRAY_EMPTY_INDEX) then begin
|
||||||
// this index is empty, place struct here
|
// this index is empty, place struct here
|
||||||
zero := true; // break
|
zero := true; // break
|
||||||
end else begin
|
end else begin
|
||||||
index += blocksize;
|
index += blocksize;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (index == len_array(arr)) then begin
|
if (index == len_array(arr)) then begin
|
||||||
resize_array(arr, index + blocksize);
|
resize_array(arr, index + blocksize);
|
||||||
end
|
end
|
||||||
set_array(arr, index, index);
|
set_array(arr, index, index);
|
||||||
return index;
|
return index;
|
||||||
end
|
end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -433,25 +433,25 @@ end
|
|||||||
* DEPRECATED, use collections instead
|
* DEPRECATED, use collections instead
|
||||||
*/
|
*/
|
||||||
procedure remove_array_block(variable arr, variable blocksize, variable index) begin
|
procedure remove_array_block(variable arr, variable blocksize, variable index) begin
|
||||||
variable len;
|
variable len;
|
||||||
len := len_array(arr);
|
len := len_array(arr);
|
||||||
if (index + blocksize == len) then begin
|
if (index + blocksize == len) then begin
|
||||||
// if this is last block, reduce the array
|
// if this is last block, reduce the array
|
||||||
resize_array(arr, len - blocksize);
|
resize_array(arr, len - blocksize);
|
||||||
end else begin
|
end else begin
|
||||||
// mark block as empty
|
// mark block as empty
|
||||||
set_array(arr, index, ARRAY_EMPTY_INDEX);
|
set_array(arr, index, ARRAY_EMPTY_INDEX);
|
||||||
// null other part of block - just in case...
|
// null other part of block - just in case...
|
||||||
call array_fill(arr, index + 1, blocksize - 1, 0);
|
call array_fill(arr, index + 1, blocksize - 1, 0);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
procedure array_fill(variable arr, variable pos, variable count, variable value) begin
|
procedure array_fill(variable arr, variable pos, variable count, variable value) begin
|
||||||
variable i := 0;
|
variable i := 0;
|
||||||
if (count == -1 or (pos + count > len_array(arr))) then count := len_array(arr) - pos; // this should prevent write to illegal offsets
|
if (count == -1 or (pos + count > len_array(arr))) then count := len_array(arr) - pos; // this should prevent write to illegal offsets
|
||||||
while (i < count) do begin
|
while (i < count) do begin
|
||||||
arr[pos + i] := value;
|
arr[pos + i] := value;
|
||||||
i++;
|
i++;
|
||||||
end
|
end
|
||||||
return arr;
|
return arr;
|
||||||
end
|
end
|
||||||
@@ -462,7 +462,7 @@ procedure array_append(variable arr1, variable arr2) begin
|
|||||||
variable k, v;
|
variable k, v;
|
||||||
foreach (k: v in arr2) begin
|
foreach (k: v in arr2) begin
|
||||||
arr1[k] := v;
|
arr1[k] := v;
|
||||||
end
|
end
|
||||||
end else begin
|
end else begin
|
||||||
arr1_len := len_array(arr1);
|
arr1_len := len_array(arr1);
|
||||||
resize_array(arr1, arr1_len + len_array(arr2));
|
resize_array(arr1, arr1_len + len_array(arr2));
|
||||||
@@ -484,7 +484,7 @@ end
|
|||||||
procedure get_saved_array_new(variable name, variable size) begin
|
procedure get_saved_array_new(variable name, variable size) begin
|
||||||
variable arr;
|
variable arr;
|
||||||
arr := load_array(name);
|
arr := load_array(name);
|
||||||
if (arr) then
|
if (arr) then
|
||||||
free_array(arr);
|
free_array(arr);
|
||||||
arr := create_array(size, 0);
|
arr := create_array(size, 0);
|
||||||
save_array(name, arr);
|
save_array(name, arr);
|
||||||
@@ -525,45 +525,45 @@ end
|
|||||||
|
|
||||||
/* NOT SAFE
|
/* NOT SAFE
|
||||||
procedure sfall_global_array(variable global, variable size) begin
|
procedure sfall_global_array(variable global, variable size) begin
|
||||||
variable ar;
|
variable ar;
|
||||||
ar := get_sfall_global_int(global);
|
ar := get_sfall_global_int(global);
|
||||||
if (ar == 0) then begin
|
if (ar == 0) then begin
|
||||||
ar := create_array(size, 0); // persistent array, but not saved
|
ar := create_array(size, 0); // persistent array, but not saved
|
||||||
set_sfall_global(global, ar);
|
set_sfall_global(global, ar);
|
||||||
end
|
end
|
||||||
return ar;
|
return ar;
|
||||||
end*/
|
end*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
DEPRECATED code, just for reference, don't use
|
DEPRECATED code, just for reference, don't use
|
||||||
|
|
||||||
procedure get_sfall_global_array(variable global_id, variable elemcount, variable elemsize) begin
|
procedure get_sfall_global_array(variable global_id, variable elemcount, variable elemsize) begin
|
||||||
variable ar;
|
variable ar;
|
||||||
ar := get_sfall_global_int(global_id);
|
ar := get_sfall_global_int(global_id);
|
||||||
if (ar == 0) then begin
|
if (ar == 0) then begin
|
||||||
ar := create_array(elemcount, elemsize);
|
ar := create_array(elemcount, elemsize);
|
||||||
set_sfall_global(global_id, ar);
|
set_sfall_global(global_id, ar);
|
||||||
end
|
end
|
||||||
return ar;
|
return ar;
|
||||||
end
|
end
|
||||||
|
|
||||||
procedure get_sfall_global_array_new(variable global_id, variable elemcount, variable elemsize) begin
|
procedure get_sfall_global_array_new(variable global_id, variable elemcount, variable elemsize) begin
|
||||||
variable ar;
|
variable ar;
|
||||||
variable i;
|
variable i;
|
||||||
variable it;
|
variable it;
|
||||||
ar := get_sfall_global_int(global_id);
|
ar := get_sfall_global_int(global_id);
|
||||||
if (ar == 0) then begin
|
if (ar == 0) then begin
|
||||||
ar := create_array(elemcount, elemsize);
|
ar := create_array(elemcount, elemsize);
|
||||||
set_sfall_global(global_id, ar);
|
set_sfall_global(global_id, ar);
|
||||||
end else begin
|
end else begin
|
||||||
i := 0;
|
i := 0;
|
||||||
resize_array(ar, elemcount);
|
resize_array(ar, elemcount);
|
||||||
while (i < len_array(ar)) do begin
|
while (i < len_array(ar)) do begin
|
||||||
ar[i] := 0;
|
ar[i] := 0;
|
||||||
i++;
|
i++;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ar;
|
return ar;
|
||||||
end
|
end
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -8,24 +8,24 @@
|
|||||||
Inventory contents as temp array to be used in foreach
|
Inventory contents as temp array to be used in foreach
|
||||||
*/
|
*/
|
||||||
procedure inven_as_array(variable critter) begin
|
procedure inven_as_array(variable critter) begin
|
||||||
variable i:=0, list;
|
variable i:=0, list;
|
||||||
list := temp_array(100, 4);
|
list := temp_array(100, 4);
|
||||||
while (inven_ptr(critter, i)) do begin
|
while (inven_ptr(critter, i)) do begin
|
||||||
if (i>=len_array(list)) then
|
if (i>=len_array(list)) then
|
||||||
resize_array(list, len_array(list) + 100);
|
resize_array(list, len_array(list) + 100);
|
||||||
list[i] := inven_ptr(critter, i);
|
list[i] := inven_ptr(critter, i);
|
||||||
i++;
|
i++;
|
||||||
end
|
end
|
||||||
resize_array(list, i);
|
resize_array(list, i);
|
||||||
return list;
|
return list;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
procedure add_items_pid(variable who_obj, variable the_pid, variable pid_qty) begin
|
procedure add_items_pid(variable who_obj, variable the_pid, variable pid_qty) begin
|
||||||
variable item;
|
variable item;
|
||||||
item := create_object(the_pid,0,0);
|
item := create_object(the_pid,0,0);
|
||||||
add_mult_objs_to_inven(who_obj, item, (pid_qty));
|
add_mult_objs_to_inven(who_obj, item, (pid_qty));
|
||||||
return item;
|
return item;
|
||||||
end
|
end
|
||||||
|
|
||||||
// aliases:
|
// aliases:
|
||||||
@@ -36,27 +36,27 @@ end
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
procedure unwield_armor(variable who_obj) begin
|
procedure unwield_armor(variable who_obj) begin
|
||||||
variable armor;
|
variable armor;
|
||||||
if (not(who_obj)) then return;
|
if (not(who_obj)) then return;
|
||||||
if (critter_wearing_armor(who_obj)) then begin
|
if (critter_wearing_armor(who_obj)) then begin
|
||||||
armor := critter_inven_obj(who_obj,INVEN_TYPE_WORN);
|
armor := critter_inven_obj(who_obj,INVEN_TYPE_WORN);
|
||||||
rm_obj_from_inven(who_obj, armor);
|
rm_obj_from_inven(who_obj, armor);
|
||||||
add_obj_to_inven(who_obj, armor);
|
add_obj_to_inven(who_obj, armor);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
procedure remove_items_pid(variable who_obj, variable the_pid, variable pid_qty) begin
|
procedure remove_items_pid(variable who_obj, variable the_pid, variable pid_qty) begin
|
||||||
variable begin
|
variable begin
|
||||||
item;
|
item;
|
||||||
removed_qty;
|
removed_qty;
|
||||||
tmp;
|
tmp;
|
||||||
end
|
end
|
||||||
if (not(who_obj)) then return;
|
if (not(who_obj)) then return;
|
||||||
removed_qty := obj_is_carrying_obj_pid(who_obj,the_pid);
|
removed_qty := obj_is_carrying_obj_pid(who_obj,the_pid);
|
||||||
if (pid_qty < removed_qty and pid_qty != -1) then begin
|
if (pid_qty < removed_qty and pid_qty != -1) then begin
|
||||||
removed_qty := pid_qty;
|
removed_qty := pid_qty;
|
||||||
end
|
end
|
||||||
if (removed_qty > 0) then begin
|
if (removed_qty > 0) then begin
|
||||||
item := obj_carrying_pid_obj(who_obj, the_pid);
|
item := obj_carrying_pid_obj(who_obj, the_pid);
|
||||||
if (obj_type(who_obj) == 1) then begin
|
if (obj_type(who_obj) == 1) then begin
|
||||||
if (critter_inven_obj(who_obj,INVEN_TYPE_WORN) == item) then begin
|
if (critter_inven_obj(who_obj,INVEN_TYPE_WORN) == item) then begin
|
||||||
@@ -67,7 +67,7 @@ procedure remove_items_pid(variable who_obj, variable the_pid, variable pid_qty)
|
|||||||
end
|
end
|
||||||
tmp := rm_mult_objs_from_inven(who_obj, item, removed_qty);
|
tmp := rm_mult_objs_from_inven(who_obj, item, removed_qty);
|
||||||
destroy_object(item);
|
destroy_object(item);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
procedure remove_item_obj(variable who_obj, variable item) begin
|
procedure remove_item_obj(variable who_obj, variable item) begin
|
||||||
@@ -91,34 +91,34 @@ end
|
|||||||
*/
|
*/
|
||||||
procedure set_items_qty_pid(variable invenobj, variable itempid, variable newcount)
|
procedure set_items_qty_pid(variable invenobj, variable itempid, variable newcount)
|
||||||
begin
|
begin
|
||||||
variable begin
|
variable begin
|
||||||
count;
|
count;
|
||||||
obj;
|
obj;
|
||||||
end
|
end
|
||||||
count := obj_is_carrying_obj_pid(invenobj, itempid);
|
count := obj_is_carrying_obj_pid(invenobj, itempid);
|
||||||
if (newcount > count) then begin
|
if (newcount > count) then begin
|
||||||
obj := create_object_sid(itempid, 0, 0, -1);
|
obj := create_object_sid(itempid, 0, 0, -1);
|
||||||
add_mult_objs_to_inven(invenobj, obj, newcount - count);
|
add_mult_objs_to_inven(invenobj, obj, newcount - count);
|
||||||
end else if (newcount < count) then begin
|
end else if (newcount < count) then begin
|
||||||
call remove_items_pid(invenobj, itempid, count - newcount);
|
call remove_items_pid(invenobj, itempid, count - newcount);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
procedure check_restock_item(the_item, min_amt, max_amt, res_perc)
|
procedure check_restock_item(the_item, min_amt, max_amt, res_perc)
|
||||||
restock_amt := random(min_amt, max_amt);
|
restock_amt := random(min_amt, max_amt);
|
||||||
if (obj_is_carrying_obj_pid(self_obj, the_item) < restock_amt) then begin
|
if (obj_is_carrying_obj_pid(self_obj, the_item) < restock_amt) then begin
|
||||||
if (res_perc >= random(1,100)) then begin
|
if (res_perc >= random(1,100)) then begin
|
||||||
stock_pid_qty(self_obj, the_item, restock_amt)
|
stock_pid_qty(self_obj, the_item, restock_amt)
|
||||||
end
|
end
|
||||||
end else begin
|
end else begin
|
||||||
stock_pid_qty(self_obj, the_item, restock_amt)
|
stock_pid_qty(self_obj, the_item, restock_amt)
|
||||||
end
|
end
|
||||||
procedure check_restock_item_min_limit(the_item, min_amt, max_amt, res_perc)
|
procedure check_restock_item_min_limit(the_item, min_amt, max_amt, res_perc)
|
||||||
if (obj_is_carrying_obj_pid(self_obj, the_item) < min_amt) then begin
|
if (obj_is_carrying_obj_pid(self_obj, the_item) < min_amt) then begin
|
||||||
check_restock_item(the_item, min_amt, max_amt, res_perc)
|
check_restock_item(the_item, min_amt, max_amt, res_perc)
|
||||||
end
|
end
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ procedure reduce_merchant_loot(variable critter, variable moneyPercent, variable
|
|||||||
//display_msg("total items "+len_array(inv));
|
//display_msg("total items "+len_array(inv));
|
||||||
foreach item in inv begin
|
foreach item in inv begin
|
||||||
if (obj_pid(item) != PID_BOTTLE_CAPS) then begin
|
if (obj_pid(item) != PID_BOTTLE_CAPS) then begin
|
||||||
it := obj_item_subtype(item);
|
it := obj_item_subtype(item);
|
||||||
if (it == item_type_armor) then
|
if (it == item_type_armor) then
|
||||||
prob := probArmor;
|
prob := probArmor;
|
||||||
else if (it == item_type_drug) then
|
else if (it == item_type_drug) then
|
||||||
|
|||||||
@@ -20,26 +20,26 @@ procedure min(variable x, variable y) begin
|
|||||||
end
|
end
|
||||||
|
|
||||||
/*procedure round(variable val) begin
|
/*procedure round(variable val) begin
|
||||||
variable intp;
|
variable intp;
|
||||||
intp := floor(val);
|
intp := floor(val);
|
||||||
if ((val-intp) >= 0.5) then intp++;
|
if ((val-intp) >= 0.5) then intp++;
|
||||||
return intp;
|
return intp;
|
||||||
end*/
|
end*/
|
||||||
|
|
||||||
procedure ceil(variable val) begin
|
procedure ceil(variable val) begin
|
||||||
variable intp;
|
variable intp;
|
||||||
intp := floor(val);
|
intp := floor(val);
|
||||||
if (abs(val-intp) > 0.0) then begin
|
if (abs(val-intp) > 0.0) then begin
|
||||||
intp++;
|
intp++;
|
||||||
end
|
end
|
||||||
return intp;
|
return intp;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
procedure cap_number(variable num, variable min, variable max) begin
|
procedure cap_number(variable num, variable min, variable max) begin
|
||||||
if (num > max) then num := max;
|
if (num > max) then num := max;
|
||||||
else if (num < min) then num := min;
|
else if (num < min) then num := min;
|
||||||
return num;
|
return num;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,20 +6,20 @@
|
|||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
procedure round(variable val) begin
|
procedure round(variable val) begin
|
||||||
variable intp;
|
variable intp;
|
||||||
intp := floor(val);
|
intp := floor(val);
|
||||||
if ((val-intp) >= 0.5) then intp++;
|
if ((val-intp) >= 0.5) then intp++;
|
||||||
return intp;
|
return intp;
|
||||||
end*/
|
end*/
|
||||||
|
|
||||||
// this fixes strange behavior when using negative float values
|
// this fixes strange behavior when using negative float values
|
||||||
// looks like the only way to create correct negative float is to use atof()
|
// looks like the only way to create correct negative float is to use atof()
|
||||||
// DEPRECATED as of sfall 3.4 (engine bug fixed)
|
// DEPRECATED as of sfall 3.4 (engine bug fixed)
|
||||||
/*procedure itof_safe(variable var) begin
|
/*procedure itof_safe(variable var) begin
|
||||||
if (var < 0) then begin
|
if (var < 0) then begin
|
||||||
var := atof("-"+(-var));
|
var := atof("-"+(-var));
|
||||||
end
|
end
|
||||||
return var;
|
return var;
|
||||||
end*/
|
end*/
|
||||||
|
|
||||||
// Parse keyboard shortcut definition
|
// Parse keyboard shortcut definition
|
||||||
@@ -65,20 +65,20 @@ end
|
|||||||
Attempt to make list_as_array safe
|
Attempt to make list_as_array safe
|
||||||
*/
|
*/
|
||||||
/*procedure list_as_array_safe(variable type) begin
|
/*procedure list_as_array_safe(variable type) begin
|
||||||
variable list, item, arr, i;
|
variable list, item, arr, i;
|
||||||
list := list_begin(type);
|
list := list_begin(type);
|
||||||
arr := temp_array(100, 4);
|
arr := temp_array(100, 4);
|
||||||
i := 0;
|
i := 0;
|
||||||
item := list_next(list);
|
item := list_next(list);
|
||||||
while (item) do begin
|
while (item) do begin
|
||||||
if (len_array(arr) == i) then resize_array(arr, len_array(arr) + 100);
|
if (len_array(arr) == i) then resize_array(arr, len_array(arr) + 100);
|
||||||
arr[i] := item;
|
arr[i] := item;
|
||||||
item := list_next(list);
|
item := list_next(list);
|
||||||
i++;
|
i++;
|
||||||
end
|
end
|
||||||
resize_array(arr, i);
|
resize_array(arr, i);
|
||||||
list_end(list);
|
list_end(list);
|
||||||
return arr;
|
return arr;
|
||||||
end*/
|
end*/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -63,12 +63,12 @@ procedure sprintf2(variable str, variable arg1, variable arg2) begin
|
|||||||
end
|
end
|
||||||
end else begin
|
end else begin
|
||||||
if (j == 0) then
|
if (j == 0) then
|
||||||
arg := arg1;
|
arg := arg1;
|
||||||
else if (j == 1) then
|
else if (j == 1) then
|
||||||
arg := arg2;
|
arg := arg2;
|
||||||
else
|
else
|
||||||
arg := 0;
|
arg := 0;
|
||||||
|
|
||||||
str += sprintf("%" + split[i], arg);
|
str += sprintf("%" + split[i], arg);
|
||||||
j++;
|
j++;
|
||||||
end
|
end
|
||||||
@@ -136,7 +136,7 @@ procedure string_get_tokens(variable str, variable delim) begin
|
|||||||
line += delim + token;
|
line += delim + token;
|
||||||
end
|
end
|
||||||
//end
|
//end
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -166,14 +166,14 @@ end
|
|||||||
* Useful in cunjunction with is_in_array()
|
* Useful in cunjunction with is_in_array()
|
||||||
*/
|
*/
|
||||||
procedure string_split_ints(variable str, variable split) begin
|
procedure string_split_ints(variable str, variable split) begin
|
||||||
variable i := 0;
|
variable i := 0;
|
||||||
variable list;
|
variable list;
|
||||||
list := string_split(str, split);
|
list := string_split(str, split);
|
||||||
while (i < len_array(list)) do begin
|
while (i < len_array(list)) do begin
|
||||||
list[i] := atoi(list[i]);
|
list[i] := atoi(list[i]);
|
||||||
i++;
|
i++;
|
||||||
end
|
end
|
||||||
return list;
|
return list;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -181,34 +181,34 @@ end
|
|||||||
String parse functions. Idea taken from KLIMaka on TeamX forums.
|
String parse functions. Idea taken from KLIMaka on TeamX forums.
|
||||||
Placeholders in format %d% are replaced from string. d refers to variable index (starting from 1).
|
Placeholders in format %d% are replaced from string. d refers to variable index (starting from 1).
|
||||||
You can repeat one placeholder multiple times, or use placeholders in any order.
|
You can repeat one placeholder multiple times, or use placeholders in any order.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
parse_str_2("Hello, %2%. I have only $%1% to spare.", money_amount, dude_name);
|
parse_str_2("Hello, %2%. I have only $%1% to spare.", money_amount, dude_name);
|
||||||
Will return:
|
Will return:
|
||||||
Hello, Killiano. I have only $1200 to spare.
|
Hello, Killiano. I have only $1200 to spare.
|
||||||
|
|
||||||
The *_list function takes a temp_array as second parameter.
|
The *_list function takes a temp_array as second parameter.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _TOKENIZE_BEGIN \
|
#define _TOKENIZE_BEGIN \
|
||||||
variable token, rest, line, result, n; \
|
variable token, rest, line, result, n; \
|
||||||
line := tokenize(str, 0, '%'); \
|
line := tokenize(str, 0, '%'); \
|
||||||
result := line; \
|
result := line; \
|
||||||
while line != str do begin \
|
while line != str do begin \
|
||||||
token := tokenize(str, line, '%'); \
|
token := tokenize(str, line, '%'); \
|
||||||
line += "%" + token; \
|
line += "%" + token; \
|
||||||
if token == "" then result += "%"; \
|
if token == "" then result += "%"; \
|
||||||
else begin
|
else begin
|
||||||
|
|
||||||
#define _TOKENIZE_END \
|
#define _TOKENIZE_END \
|
||||||
end \
|
end \
|
||||||
rest := tokenize(str, line, '%'); \
|
rest := tokenize(str, line, '%'); \
|
||||||
if (rest != 0) then begin \
|
if (rest != 0) then begin \
|
||||||
line += "%" + rest; \
|
line += "%" + rest; \
|
||||||
result += rest; \
|
result += rest; \
|
||||||
end \
|
end \
|
||||||
end \
|
end \
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|
||||||
procedure parse_str_list(variable str, variable list) begin
|
procedure parse_str_list(variable str, variable list) begin
|
||||||
|
|||||||
Reference in New Issue
Block a user