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
|
||||
#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 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 dude_tile (tile_num(dude_obj))
|
||||
#define dude_elevation (elevation(dude_obj))
|
||||
#define dude_skill(x) (has_skill(dude_obj, x))
|
||||
|
||||
|
||||
// some commands
|
||||
@@ -913,5 +908,3 @@
|
||||
#define g_mstr(x) message_str(SCRIPT_GENERIC,x)
|
||||
|
||||
#endif // DEFINE_H
|
||||
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
This library contains procedures which should ease working with sfall arrays.
|
||||
sfall v3.4 or higher is required
|
||||
|
||||
|
||||
WARNING!!!
|
||||
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.
|
||||
|
||||
|
||||
@author phobos2077
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#ifndef LIB_ARRAYS_H
|
||||
@@ -66,7 +66,7 @@ procedure array_sum(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
|
||||
* count - number of items to fill (use -1 to fill to the end of the array)
|
||||
* 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)
|
||||
Recommended use case:
|
||||
Recommended use case:
|
||||
1) create a block for each "object"
|
||||
2) define macros like (example):
|
||||
2) define macros like (example):
|
||||
#define TRAP_OFSET_TILE (5)
|
||||
#define trap_tile(array, index) (array[index + TRAP_OFSET_TILE])
|
||||
#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
|
||||
5) 0 offset is always equal to object "ID" (starting index of block)
|
||||
|
||||
|
||||
DEPRECATED, use collections instead
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
procedure get_empty_array_index(variable array) begin
|
||||
variable zero := false;
|
||||
variable i := 0;
|
||||
while i < len_array(array) and not(zero) do begin
|
||||
if (array[i] == 0) then begin
|
||||
zero := true; // break
|
||||
end else begin
|
||||
i++;
|
||||
end
|
||||
end
|
||||
return i;
|
||||
variable zero := false;
|
||||
variable i := 0;
|
||||
while i < len_array(array) and not(zero) do begin
|
||||
if (array[i] == 0) then begin
|
||||
zero := true; // break
|
||||
end else begin
|
||||
i++;
|
||||
end
|
||||
end
|
||||
return i;
|
||||
end
|
||||
|
||||
// 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
|
||||
i := scan_array(arr1, v);
|
||||
if (i != -1) then begin
|
||||
if (isMap) then
|
||||
if (isMap) then
|
||||
unset_array(arr1, i);
|
||||
else
|
||||
call array_cut(arr1, i, 1);
|
||||
end
|
||||
end
|
||||
end
|
||||
return arr1;
|
||||
end
|
||||
@@ -282,8 +282,8 @@ procedure clone_array(variable array) begin
|
||||
new := temp_array_list(len_array(array));
|
||||
foreach k: v in array begin
|
||||
new[k] := v;
|
||||
end
|
||||
return new;
|
||||
end
|
||||
return new;
|
||||
end
|
||||
|
||||
procedure arrays_equal(variable arr1, variable arr2) begin
|
||||
@@ -344,48 +344,48 @@ end
|
||||
|
||||
|
||||
procedure add_array_set(variable array, variable item) begin
|
||||
variable i := 0;
|
||||
variable len;
|
||||
variable exist := false;
|
||||
variable zero := false;
|
||||
len := len_array(array);
|
||||
|
||||
// search for first empty space and also check if item exists
|
||||
while i < len and not(zero) do begin
|
||||
if (array[i] == 0) then begin
|
||||
zero := true; // break
|
||||
i--;
|
||||
end else if (array[i] == item) then exist := true;
|
||||
i++;
|
||||
end
|
||||
if not(exist) then begin
|
||||
// if no empty space, resize array
|
||||
if (i == len) then begin
|
||||
resize_array(array, len + ARRAY_SET_BLOCK_SIZE);
|
||||
end
|
||||
set_array(array, i, item);
|
||||
end
|
||||
variable i := 0;
|
||||
variable len;
|
||||
variable exist := false;
|
||||
variable zero := false;
|
||||
len := len_array(array);
|
||||
|
||||
// search for first empty space and also check if item exists
|
||||
while i < len and not(zero) do begin
|
||||
if (array[i] == 0) then begin
|
||||
zero := true; // break
|
||||
i--;
|
||||
end else if (array[i] == item) then exist := true;
|
||||
i++;
|
||||
end
|
||||
if not(exist) then begin
|
||||
// if no empty space, resize array
|
||||
if (i == len) then begin
|
||||
resize_array(array, len + ARRAY_SET_BLOCK_SIZE);
|
||||
end
|
||||
set_array(array, i, item);
|
||||
end
|
||||
end
|
||||
|
||||
procedure remove_array_set(variable array, variable item) begin
|
||||
variable i := 0;
|
||||
variable len;
|
||||
variable found_at := -1;
|
||||
variable zero := false;
|
||||
variable i := 0;
|
||||
variable len;
|
||||
variable found_at := -1;
|
||||
variable zero := false;
|
||||
|
||||
len := len_array(array);
|
||||
// search for first empty space and also check if item exists
|
||||
while (i < len and not(zero)) do begin
|
||||
if (array[i] == 0) then begin
|
||||
zero := true; // break
|
||||
i--;
|
||||
end else if (array[i] == item) then found_at := i;
|
||||
i++;
|
||||
end
|
||||
if (found_at != -1) then begin
|
||||
array[found_at] := array[i - 1];
|
||||
array[i - 1] := 0;
|
||||
end
|
||||
len := len_array(array);
|
||||
// search for first empty space and also check if item exists
|
||||
while (i < len and not(zero)) do begin
|
||||
if (array[i] == 0) then begin
|
||||
zero := true; // break
|
||||
i--;
|
||||
end else if (array[i] == item) then found_at := i;
|
||||
i++;
|
||||
end
|
||||
if (found_at != -1) then begin
|
||||
array[found_at] := array[i - 1];
|
||||
array[i - 1] := 0;
|
||||
end
|
||||
end
|
||||
|
||||
// use callback on each array element
|
||||
@@ -404,27 +404,27 @@ end
|
||||
* DEPRECATED, use collections instead
|
||||
*/
|
||||
procedure add_array_block(variable arr, variable blocksize) begin
|
||||
variable begin
|
||||
index := 0;
|
||||
zero := false;
|
||||
tile;
|
||||
elev;
|
||||
end
|
||||
// find empty array index
|
||||
index := 0;
|
||||
while index < len_array(arr) and not(zero) do begin
|
||||
if (get_array(arr, index) == ARRAY_EMPTY_INDEX) then begin
|
||||
// this index is empty, place struct here
|
||||
zero := true; // break
|
||||
end else begin
|
||||
index += blocksize;
|
||||
end
|
||||
end
|
||||
if (index == len_array(arr)) then begin
|
||||
resize_array(arr, index + blocksize);
|
||||
end
|
||||
set_array(arr, index, index);
|
||||
return index;
|
||||
variable begin
|
||||
index := 0;
|
||||
zero := false;
|
||||
tile;
|
||||
elev;
|
||||
end
|
||||
// find empty array index
|
||||
index := 0;
|
||||
while index < len_array(arr) and not(zero) do begin
|
||||
if (get_array(arr, index) == ARRAY_EMPTY_INDEX) then begin
|
||||
// this index is empty, place struct here
|
||||
zero := true; // break
|
||||
end else begin
|
||||
index += blocksize;
|
||||
end
|
||||
end
|
||||
if (index == len_array(arr)) then begin
|
||||
resize_array(arr, index + blocksize);
|
||||
end
|
||||
set_array(arr, index, index);
|
||||
return index;
|
||||
end
|
||||
|
||||
/**
|
||||
@@ -433,25 +433,25 @@ end
|
||||
* DEPRECATED, use collections instead
|
||||
*/
|
||||
procedure remove_array_block(variable arr, variable blocksize, variable index) begin
|
||||
variable len;
|
||||
len := len_array(arr);
|
||||
if (index + blocksize == len) then begin
|
||||
// if this is last block, reduce the array
|
||||
resize_array(arr, len - blocksize);
|
||||
end else begin
|
||||
// mark block as empty
|
||||
set_array(arr, index, ARRAY_EMPTY_INDEX);
|
||||
// null other part of block - just in case...
|
||||
call array_fill(arr, index + 1, blocksize - 1, 0);
|
||||
end
|
||||
variable len;
|
||||
len := len_array(arr);
|
||||
if (index + blocksize == len) then begin
|
||||
// if this is last block, reduce the array
|
||||
resize_array(arr, len - blocksize);
|
||||
end else begin
|
||||
// mark block as empty
|
||||
set_array(arr, index, ARRAY_EMPTY_INDEX);
|
||||
// null other part of block - just in case...
|
||||
call array_fill(arr, index + 1, blocksize - 1, 0);
|
||||
end
|
||||
end
|
||||
|
||||
procedure array_fill(variable arr, variable pos, variable count, variable value) begin
|
||||
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
|
||||
while (i < count) do begin
|
||||
arr[pos + i] := value;
|
||||
i++;
|
||||
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
|
||||
while (i < count) do begin
|
||||
arr[pos + i] := value;
|
||||
i++;
|
||||
end
|
||||
return arr;
|
||||
end
|
||||
@@ -462,7 +462,7 @@ procedure array_append(variable arr1, variable arr2) begin
|
||||
variable k, v;
|
||||
foreach (k: v in arr2) begin
|
||||
arr1[k] := v;
|
||||
end
|
||||
end
|
||||
end else begin
|
||||
arr1_len := len_array(arr1);
|
||||
resize_array(arr1, arr1_len + len_array(arr2));
|
||||
@@ -484,7 +484,7 @@ end
|
||||
procedure get_saved_array_new(variable name, variable size) begin
|
||||
variable arr;
|
||||
arr := load_array(name);
|
||||
if (arr) then
|
||||
if (arr) then
|
||||
free_array(arr);
|
||||
arr := create_array(size, 0);
|
||||
save_array(name, arr);
|
||||
@@ -525,45 +525,45 @@ end
|
||||
|
||||
/* NOT SAFE
|
||||
procedure sfall_global_array(variable global, variable size) begin
|
||||
variable ar;
|
||||
ar := get_sfall_global_int(global);
|
||||
if (ar == 0) then begin
|
||||
ar := create_array(size, 0); // persistent array, but not saved
|
||||
set_sfall_global(global, ar);
|
||||
end
|
||||
return ar;
|
||||
variable ar;
|
||||
ar := get_sfall_global_int(global);
|
||||
if (ar == 0) then begin
|
||||
ar := create_array(size, 0); // persistent array, but not saved
|
||||
set_sfall_global(global, ar);
|
||||
end
|
||||
return ar;
|
||||
end*/
|
||||
|
||||
/*
|
||||
/*
|
||||
DEPRECATED code, just for reference, don't use
|
||||
|
||||
procedure get_sfall_global_array(variable global_id, variable elemcount, variable elemsize) begin
|
||||
variable ar;
|
||||
ar := get_sfall_global_int(global_id);
|
||||
if (ar == 0) then begin
|
||||
ar := create_array(elemcount, elemsize);
|
||||
set_sfall_global(global_id, ar);
|
||||
end
|
||||
return ar;
|
||||
variable ar;
|
||||
ar := get_sfall_global_int(global_id);
|
||||
if (ar == 0) then begin
|
||||
ar := create_array(elemcount, elemsize);
|
||||
set_sfall_global(global_id, ar);
|
||||
end
|
||||
return ar;
|
||||
end
|
||||
|
||||
procedure get_sfall_global_array_new(variable global_id, variable elemcount, variable elemsize) begin
|
||||
variable ar;
|
||||
variable i;
|
||||
variable it;
|
||||
ar := get_sfall_global_int(global_id);
|
||||
if (ar == 0) then begin
|
||||
ar := create_array(elemcount, elemsize);
|
||||
set_sfall_global(global_id, ar);
|
||||
end else begin
|
||||
i := 0;
|
||||
resize_array(ar, elemcount);
|
||||
while (i < len_array(ar)) do begin
|
||||
ar[i] := 0;
|
||||
i++;
|
||||
end
|
||||
end
|
||||
return ar;
|
||||
variable ar;
|
||||
variable i;
|
||||
variable it;
|
||||
ar := get_sfall_global_int(global_id);
|
||||
if (ar == 0) then begin
|
||||
ar := create_array(elemcount, elemsize);
|
||||
set_sfall_global(global_id, ar);
|
||||
end else begin
|
||||
i := 0;
|
||||
resize_array(ar, elemcount);
|
||||
while (i < len_array(ar)) do begin
|
||||
ar[i] := 0;
|
||||
i++;
|
||||
end
|
||||
end
|
||||
return ar;
|
||||
end
|
||||
*/
|
||||
|
||||
|
||||
@@ -8,24 +8,24 @@
|
||||
Inventory contents as temp array to be used in foreach
|
||||
*/
|
||||
procedure inven_as_array(variable critter) begin
|
||||
variable i:=0, list;
|
||||
list := temp_array(100, 4);
|
||||
while (inven_ptr(critter, i)) do begin
|
||||
if (i>=len_array(list)) then
|
||||
resize_array(list, len_array(list) + 100);
|
||||
list[i] := inven_ptr(critter, i);
|
||||
i++;
|
||||
end
|
||||
resize_array(list, i);
|
||||
return list;
|
||||
variable i:=0, list;
|
||||
list := temp_array(100, 4);
|
||||
while (inven_ptr(critter, i)) do begin
|
||||
if (i>=len_array(list)) then
|
||||
resize_array(list, len_array(list) + 100);
|
||||
list[i] := inven_ptr(critter, i);
|
||||
i++;
|
||||
end
|
||||
resize_array(list, i);
|
||||
return list;
|
||||
end
|
||||
|
||||
|
||||
procedure add_items_pid(variable who_obj, variable the_pid, variable pid_qty) begin
|
||||
variable item;
|
||||
item := create_object(the_pid,0,0);
|
||||
add_mult_objs_to_inven(who_obj, item, (pid_qty));
|
||||
return item;
|
||||
variable item;
|
||||
item := create_object(the_pid,0,0);
|
||||
add_mult_objs_to_inven(who_obj, item, (pid_qty));
|
||||
return item;
|
||||
end
|
||||
|
||||
// aliases:
|
||||
@@ -36,27 +36,27 @@ end
|
||||
#endif
|
||||
|
||||
procedure unwield_armor(variable who_obj) begin
|
||||
variable armor;
|
||||
if (not(who_obj)) then return;
|
||||
if (critter_wearing_armor(who_obj)) then begin
|
||||
armor := critter_inven_obj(who_obj,INVEN_TYPE_WORN);
|
||||
rm_obj_from_inven(who_obj, armor);
|
||||
add_obj_to_inven(who_obj, armor);
|
||||
end
|
||||
variable armor;
|
||||
if (not(who_obj)) then return;
|
||||
if (critter_wearing_armor(who_obj)) then begin
|
||||
armor := critter_inven_obj(who_obj,INVEN_TYPE_WORN);
|
||||
rm_obj_from_inven(who_obj, armor);
|
||||
add_obj_to_inven(who_obj, armor);
|
||||
end
|
||||
end
|
||||
|
||||
procedure remove_items_pid(variable who_obj, variable the_pid, variable pid_qty) begin
|
||||
variable begin
|
||||
item;
|
||||
removed_qty;
|
||||
tmp;
|
||||
end
|
||||
if (not(who_obj)) then return;
|
||||
removed_qty := obj_is_carrying_obj_pid(who_obj,the_pid);
|
||||
if (pid_qty < removed_qty and pid_qty != -1) then begin
|
||||
variable begin
|
||||
item;
|
||||
removed_qty;
|
||||
tmp;
|
||||
end
|
||||
if (not(who_obj)) then return;
|
||||
removed_qty := obj_is_carrying_obj_pid(who_obj,the_pid);
|
||||
if (pid_qty < removed_qty and pid_qty != -1) then begin
|
||||
removed_qty := pid_qty;
|
||||
end
|
||||
if (removed_qty > 0) then begin
|
||||
end
|
||||
if (removed_qty > 0) then begin
|
||||
item := obj_carrying_pid_obj(who_obj, the_pid);
|
||||
if (obj_type(who_obj) == 1) 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
|
||||
tmp := rm_mult_objs_from_inven(who_obj, item, removed_qty);
|
||||
destroy_object(item);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
begin
|
||||
variable begin
|
||||
count;
|
||||
obj;
|
||||
end
|
||||
count := obj_is_carrying_obj_pid(invenobj, itempid);
|
||||
if (newcount > count) then begin
|
||||
obj := create_object_sid(itempid, 0, 0, -1);
|
||||
add_mult_objs_to_inven(invenobj, obj, newcount - count);
|
||||
end else if (newcount < count) then begin
|
||||
call remove_items_pid(invenobj, itempid, count - newcount);
|
||||
end
|
||||
variable begin
|
||||
count;
|
||||
obj;
|
||||
end
|
||||
count := obj_is_carrying_obj_pid(invenobj, itempid);
|
||||
if (newcount > count) then begin
|
||||
obj := create_object_sid(itempid, 0, 0, -1);
|
||||
add_mult_objs_to_inven(invenobj, obj, newcount - count);
|
||||
end else if (newcount < count) then begin
|
||||
call remove_items_pid(invenobj, itempid, count - newcount);
|
||||
end
|
||||
end
|
||||
|
||||
/*
|
||||
|
||||
procedure check_restock_item(the_item, min_amt, max_amt, res_perc)
|
||||
restock_amt := random(min_amt, max_amt);
|
||||
if (obj_is_carrying_obj_pid(self_obj, the_item) < restock_amt) then begin
|
||||
if (res_perc >= random(1,100)) then begin
|
||||
stock_pid_qty(self_obj, the_item, restock_amt)
|
||||
end
|
||||
end else begin
|
||||
stock_pid_qty(self_obj, the_item, restock_amt)
|
||||
end
|
||||
restock_amt := random(min_amt, max_amt);
|
||||
if (obj_is_carrying_obj_pid(self_obj, the_item) < restock_amt) then begin
|
||||
if (res_perc >= random(1,100)) then begin
|
||||
stock_pid_qty(self_obj, the_item, restock_amt)
|
||||
end
|
||||
end else begin
|
||||
stock_pid_qty(self_obj, the_item, restock_amt)
|
||||
end
|
||||
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
|
||||
check_restock_item(the_item, min_amt, max_amt, res_perc)
|
||||
end
|
||||
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)
|
||||
end
|
||||
*/
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ procedure reduce_merchant_loot(variable critter, variable moneyPercent, variable
|
||||
//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);
|
||||
it := obj_item_subtype(item);
|
||||
if (it == item_type_armor) then
|
||||
prob := probArmor;
|
||||
else if (it == item_type_drug) then
|
||||
|
||||
@@ -20,26 +20,26 @@ procedure min(variable x, variable y) begin
|
||||
end
|
||||
|
||||
/*procedure round(variable val) begin
|
||||
variable intp;
|
||||
intp := floor(val);
|
||||
if ((val-intp) >= 0.5) then intp++;
|
||||
return intp;
|
||||
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++;
|
||||
end
|
||||
return intp;
|
||||
variable intp;
|
||||
intp := floor(val);
|
||||
if (abs(val-intp) > 0.0) then begin
|
||||
intp++;
|
||||
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 (num > max) then num := max;
|
||||
else if (num < min) then num := min;
|
||||
return num;
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -6,20 +6,20 @@
|
||||
*/
|
||||
/*
|
||||
procedure round(variable val) begin
|
||||
variable intp;
|
||||
intp := floor(val);
|
||||
if ((val-intp) >= 0.5) then intp++;
|
||||
return intp;
|
||||
variable intp;
|
||||
intp := floor(val);
|
||||
if ((val-intp) >= 0.5) then intp++;
|
||||
return intp;
|
||||
end*/
|
||||
|
||||
// this fixes strange behavior when using negative float values
|
||||
// looks like the only way to create correct negative float is to use atof()
|
||||
// DEPRECATED as of sfall 3.4 (engine bug fixed)
|
||||
/*procedure itof_safe(variable var) begin
|
||||
if (var < 0) then begin
|
||||
var := atof("-"+(-var));
|
||||
end
|
||||
return var;
|
||||
if (var < 0) then begin
|
||||
var := atof("-"+(-var));
|
||||
end
|
||||
return var;
|
||||
end*/
|
||||
|
||||
// Parse keyboard shortcut definition
|
||||
@@ -65,20 +65,20 @@ 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++;
|
||||
end
|
||||
resize_array(arr, i);
|
||||
list_end(list);
|
||||
return arr;
|
||||
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++;
|
||||
end
|
||||
resize_array(arr, i);
|
||||
list_end(list);
|
||||
return arr;
|
||||
end*/
|
||||
|
||||
|
||||
|
||||
@@ -63,12 +63,12 @@ procedure sprintf2(variable str, variable arg1, variable arg2) begin
|
||||
end
|
||||
end else begin
|
||||
if (j == 0) then
|
||||
arg := arg1;
|
||||
else if (j == 1) then
|
||||
arg := arg1;
|
||||
else if (j == 1) then
|
||||
arg := arg2;
|
||||
else
|
||||
arg := 0;
|
||||
|
||||
|
||||
str += sprintf("%" + split[i], arg);
|
||||
j++;
|
||||
end
|
||||
@@ -136,7 +136,7 @@ procedure string_get_tokens(variable str, variable delim) begin
|
||||
line += delim + token;
|
||||
end
|
||||
//end
|
||||
|
||||
|
||||
return count;
|
||||
end
|
||||
|
||||
@@ -166,14 +166,14 @@ end
|
||||
* Useful in cunjunction with is_in_array()
|
||||
*/
|
||||
procedure string_split_ints(variable str, variable split) begin
|
||||
variable i := 0;
|
||||
variable list;
|
||||
list := string_split(str, split);
|
||||
while (i < len_array(list)) do begin
|
||||
list[i] := atoi(list[i]);
|
||||
i++;
|
||||
end
|
||||
return list;
|
||||
variable i := 0;
|
||||
variable list;
|
||||
list := string_split(str, split);
|
||||
while (i < len_array(list)) do begin
|
||||
list[i] := atoi(list[i]);
|
||||
i++;
|
||||
end
|
||||
return list;
|
||||
end
|
||||
|
||||
|
||||
@@ -181,34 +181,34 @@ end
|
||||
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).
|
||||
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);
|
||||
Will return:
|
||||
Will return:
|
||||
Hello, Killiano. I have only $1200 to spare.
|
||||
|
||||
|
||||
The *_list function takes a temp_array as second parameter.
|
||||
*/
|
||||
*/
|
||||
|
||||
#define _TOKENIZE_BEGIN \
|
||||
variable token, rest, line, result, n; \
|
||||
line := tokenize(str, 0, '%'); \
|
||||
result := line; \
|
||||
while line != str do begin \
|
||||
token := tokenize(str, line, '%'); \
|
||||
line += "%" + token; \
|
||||
if token == "" then result += "%"; \
|
||||
else begin
|
||||
|
||||
variable token, rest, line, result, n; \
|
||||
line := tokenize(str, 0, '%'); \
|
||||
result := line; \
|
||||
while line != str do begin \
|
||||
token := tokenize(str, line, '%'); \
|
||||
line += "%" + token; \
|
||||
if token == "" then result += "%"; \
|
||||
else begin
|
||||
|
||||
#define _TOKENIZE_END \
|
||||
end \
|
||||
rest := tokenize(str, line, '%'); \
|
||||
if (rest != 0) then begin \
|
||||
line += "%" + rest; \
|
||||
result += rest; \
|
||||
end \
|
||||
end \
|
||||
return result;
|
||||
end \
|
||||
rest := tokenize(str, line, '%'); \
|
||||
if (rest != 0) then begin \
|
||||
line += "%" + rest; \
|
||||
result += rest; \
|
||||
end \
|
||||
end \
|
||||
return result;
|
||||
|
||||
|
||||
procedure parse_str_list(variable str, variable list) begin
|
||||
|
||||
Reference in New Issue
Block a user