Compare commits

..
37 Commits
Author SHA1 Message Date
NovaRain ec4ba13a28 Fixed add_mult_objs_to_inven only adding 500 of an object when the value of "count" argument is over 99999. #129 2018-01-17 07:37:03 +08:00
NovaRain 14a6ef7fc6 Made sure the value of player's base EMP DR is set correctly. 2018-01-02 23:25:27 +08:00
NovaRain c3a74070ca Updated version number and the year.
Set the copyright string in the same way as 4.0 build.
2018-01-02 10:26:32 +08:00
NovaRain 302fd4bb51 Condensed the code in ApplyHeaveHoFix a bit. 2018-01-02 10:02:04 +08:00
NovaRain c7520c71cf Fixed player's base EMP DR isn't properly initialized when creating a new character and then starting the game. 2017-12-15 07:34:10 +08:00
NovaRain 45632d6887 Changed sneak_success to call is_pc_sneak_working_ engine function, which takes player's current sneaking status into account as well, instead of only returning the result of last sneak attempt. 2017-12-05 10:25:11 +08:00
NovaRain 866c9165c0 Replaced hex values with proper VAR_TYPE_* defines for code readability. 2017-12-03 23:29:28 +08:00
NovaRain 813abbf452 Added missing entry of block_combat script function in opcode list. 2017-12-03 02:40:36 +08:00
NovaRain c6864e01f6 Added the damage type offset of weapon proto to define_extra.h.
Fixed a typo in hookscripts.txt.
Added a new example mod gl_autodoors (by Mr.Stalin) to modderspack. #19
2017-11-28 00:30:29 +08:00
NovaRain 0eab48932a Tweaked the way DebugMode works, now only DebugMode=2 sends debug output to a debug.log file. Any other non-0 value sends debug output to the screen. #123 2017-11-07 10:44:57 +08:00
NovaRain 6c3efc5b84 Replaced some SafeWrite* usages in old code with corresponding HookCall/MakeCall/MakeJump for code readability.
Edited code style in Perks.cpp.
2017-11-06 15:21:08 +08:00
NovaRain cb8d7dc94a Enabled mouse scroll control in barter and loot screens when the cursor is hovering over other lists, also enabled scrolling through the display monitor (from Crafty) #120
Rearraged the code style in dinput.cpp.
Updated version number.
2017-10-25 11:40:46 +08:00
NovaRain 5786cfb267 Fix crash when calling partyMemberGetCurLevel_ on a critter that has no data in party.txt.
Updated version number.
2017-10-18 14:56:38 +08:00
NovaRain 78dfb530a9 Moved LoadHeroAppearance() from MainMenuHook to NewGame2. No reason to run it on the main menu where player appearance can't display. 2017-09-19 15:27:08 +08:00
NovaRain d588f2e691 Edited code style in HeroAppearance.cpp/h, also removed some redundant blank lines. 2017-09-19 10:43:31 +08:00
NovaRain daf7a82997 Added descriptions for the variables in Perks.ini.
(cherry picked from commit 848f29b468)
2017-09-12 15:39:39 +08:00
NovaRain 9ad2b19e1a Removed the redundant LoadHeroAppearance calling.
(now it's called during LoadGame_, which is earlier than LoadGame2_After)
2017-09-09 18:59:21 +08:00
NovaRain 4b66dd3682 Reverted LoadGame to previous revision, but also kept EndLoadHook and changed it to only call LoadHeroAppearance.
(attempted to fix issue #117 and #94)
2017-09-05 09:21:22 +08:00
NovaRain 4899aeece1 Changed new function names in the previous commit to PascalCase style. 2017-09-01 09:45:33 +08:00
NovaRainandGitHub 946266e367 Merge pull request #107 from FakelsHub/crafty_features/combat_proc
Added calls to unimplemented script procedures: combat_is_starting_p_proc/combat_is_over_p_proc (from Crafty)
2017-09-01 09:40:47 +08:00
NovaRain 438ea071fc Removed the backported new modes for get_game_mode in commit a93ad5a9ba. 2017-08-24 21:46:42 +08:00
NovaRain 89760235c7 Removed unimplemented HEROWIN game mode from header files.
Cleared some obsoleted/unused code from main.cpp & LoadGameHook.cpp.
2017-08-23 13:42:58 +08:00
NovaRain 321f1c6034 Fixed the double damage effect of Silent Death perk not being applied to critical hits (from Crafty) 2017-08-21 23:18:32 +08:00
NovaRain 513338f160 Fixed incorrect argument description for get/set_proto_data in sfall opcode list.txt.
Removed incorrect PROTO_CR_FLAGS value in define_extra.h (was actually critter's IN), and renamed PROTO_CR_ACTION_FLAGS to its correct name #112

(cherry picked from commit ad17773ace)
2017-08-21 11:33:37 +08:00
NovaRain 08b92542f4 Fixed the incorrect description in HOOK_COMBATDAMAGE.
(cherry picked from commit 85cdd8973e)
2017-08-19 08:49:56 +08:00
NovaRain 46013c94b0 Added SSL library files and define_lite.h (from 4.0 development branch) 2017-08-18 15:52:14 +08:00
NovaRain 7a4ab59089 Added missing description for set_car_current_town.
Removed trailing spaces in MetaruleOp.hpp.
2017-08-13 11:38:18 +08:00
NovaRain e505e204cb Two bug fixes from Crafty:
1. Fixed the displayed message when the attack randomly hits a target that is not a critter and has a script attached.
2. Fixed damage_p_proc being called for misses if the target is not a critter.
2017-08-07 13:24:11 +08:00
NovaRain 7343754d53 Fixed Bonus Move APs being replenished when you save and load the game in combat (from Crafty)
Replaced all usages of MakeCall with 3 arguments with either MakeJump or MakeCall (2 arguments) to improve code readability (ref. commit 96fa2668cc)
2017-07-26 23:13:40 +08:00
NovaRain ae1e17d359 Added a note for argnum in set_sfall_arg().
Fixed incorrect set_sfall_arg usage in the example.
Removed a redundant line in sfall opcode list.txt.
2017-07-25 23:14:50 +08:00
NovaRain 32dbe5581d Replaced hs_*.int scripts in example mods with normal global scripts with register_hook.
(cherry picked from commit e7e286013f)
2017-07-06 21:04:51 +08:00
NovaRain a93ad5a9ba Added new modes for get_game_mode to match Crafty's (backported from 4.0 development branch, commit c32dc7664e) 2017-06-22 09:41:05 +08:00
NovaRain 874b047ce1 Added Attack Type argument for HOOK_COMBATDAMAGE (from Crafty) #100 2017-06-14 12:45:13 +08:00
NovaRain afa590c5a8 Minor edits to ddraw.ini. 2017-06-02 11:49:02 +08:00
NovaRain b89c52fcec Added DontTurnOffSneakIfYouRun option to prevent the player from running while sneaking without Silent Running perk (from Crafty)
Added sfall log text for DisablePipboyAlarm.
2017-05-26 10:10:16 +08:00
NovaRain ec2d323f75 Changed LoadGame2_After to be called before LoadGame state is ended (backported from 4.0 development branch, commit c2e6d743a3)
Updated version number.
Minor edits to scripting documents.
2017-05-23 21:05:04 +08:00
Mr.Stalin 586679b07f Added scripting procedure handlers combat_is_starting_p_proc/combat_is_over_p_proc from Crafry. 2017-05-12 18:28:46 +03:00
75 changed files with 3969 additions and 1671 deletions
+29 -1
View File
@@ -7,6 +7,34 @@
; have an additional NoHardcode option in this file which can
; be used to remove their hardcoded effects, and add new stat/skill effects
;Name=The name of the perk
;Desc=The description of the perk
;Image=The line number (0-indexed) of the corresponding FRM in skilldex.lst
;Ranks=The number of perk levels
;Level=The minimum required level
;Type=If 0, the perk checks only Skill1 for skill requirements; if 1, it checks
; Skill1 or Skill2; if 2, it checks both Skill1 and Skill2
;Stat=The modified stat or -1 if you don't want to change any stats
;StatMag=The increased/decreased value to the modified stat
;Skill1=The first skill (or -1 for none) to check, but if you set a specific bit
; (67108864 or 0x4000000), it checks GVAR. For example, if Skill1=67108864, then
; the perk will check GVAR_PLAYER_REPUTATION (67108864 + 0) on Skill1Mag value
;Skill1Mag=Positive value is used as the minimum requirements of the first
; skill/GVAR, and a negative value is interpreted as the maximum requirement.
; For example, with Skill1=0 and Skill1Mag=100, if player has small guns skill
; >= 100 and meets all other requirements, the perk will be available in the
; selection window; with Skill1=1 and Skill1Mag=-120, the perk will not be
; available if player has big guns skill >= 120
;Skill2=The second skill/GVAR (or -1 for none) to check
;Skill2Mag=Same as Skill1Mag, but for Skill2
;STR-LCK=Positive values are used as minimum requirements of SPECIAL stats, and
; negative values are interpreted as maximum requirements. For some special
; perks processed by the engine (e.g. PERK_armor_powered and PERK_armor_combat),
; the values are not used as requirements but to add to corresponding SPECIAL
; stats
;If the value is set to -99999, the variable will be ignored (similar to comment out that line)
;This is a modification to perk 119
[119]
Name=Example
@@ -36,4 +64,4 @@ Name=Example
Desc=This is an example trait
Image=72
StatMod=0|-1 ;Subtract 1 from strength
SkillMod=0|20|1|-5 ;Add 20 to the players small guns skill and subtract 5 from big guns
SkillMod=0|20|1|-5 ;Add 20 to the player's small guns skill and subtract 5 from big guns
+7 -4
View File
@@ -1,5 +1,5 @@
;sfall configuration settings
;v3.8.4
;v3.8.8
[Main]
;Change to 1 if you want to use command line args to tell sfall to use another ini file.
@@ -72,7 +72,7 @@ Use32BitHeadGraphics=0
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[Input]
;Set to 1 to enable the mouse scroll wheel to scroll through your inventory
;Set to 1 to enable the mouse scroll wheel to scroll through inventory, barter, and loot screens
UseScrollWheel=1
;The mouse Z position is divided by this modifier to calculate the number of inventory
@@ -382,7 +382,7 @@ UseScrollingQuestsList=1
;PremadeFIDs=201,203,202
;Use this line to modify the list of cities and their associated global variables used for city reputations
;Syntax is 'city id : global id',with each city/global pair separated by a comma.
;Syntax is 'city id : global id', with each city/global pair separated by a comma.
;CityRepsCount=19
;CityRepsList=0:47,2:48,1:49,4:50,5:51,3:52,8:53,6:54,7:55,13:56,10:57,11:59,14:61,17:63,19:64,18:65,25:66,9:294,20:308
@@ -429,7 +429,7 @@ RemoveCriticalTimelimits=0
NPCStage6Fix=0
;Change the colour of the font used on the main menu for the Fallout/sfall version number
;It's the last byte ('3c' by default,) that picks the colour used. The first byte supplies additional flags
;It's the last byte ('3c' by default) that picks the colour used. The first byte supplies additional flags
;MainMenuFontColour=0x0600003c
;Two alternate fixes to the interaction between HtH attacks and the fast shot trait
@@ -556,6 +556,9 @@ DialogOptions9Lines=1
;Set to 1 to leave the music playing in dialogue with talking heads
EnableMusicInDialogue=0
;Set to 1 to prevent the player from running while sneaking without Silent Running perk
DontTurnOffSneakIfYouRun=0
;Set to 1 to fix the bug that unable to sell used geiger counters or stealth boys
CanSellUsedGeiger=1
Binary file not shown.
@@ -0,0 +1,77 @@
/*
Auto Doors mod for Fallout 2 by Mr.Stalin
-----------------------------------------
- allows the player to automatically open/walk through unlocked doors when not in combat
Requires sfall 3.7b or higher
NOTE: this script requires compiler from sfall modderspack with -s option
(short circuit evaluation)
*/
#include "..\headers\define.h"
#include "..\headers\command.h"
#include "..\headers\sfall\sfall.h"
#include "..\headers\sfall\define_extra.h"
procedure start;
procedure map_enter_p_proc;
procedure set_door_flag(variable state);
procedure combatturn_handler;
#define PORTAL (0)
#define DOOR_FLAGS (0x24)
variable only_once := 0;
procedure start begin
if game_loaded then begin
if (sfall_ver_major >= 4) then
register_hook_proc(HOOK_COMBATTURN, combatturn_handler);
else
set_global_script_repeat(60);
call map_enter_p_proc;
end else begin
if (only_once == 1 and combat_is_initialized) then begin
only_once := 2;
call set_door_flag(false);
end else if (only_once == 2 and not(combat_is_initialized)) then begin
only_once := 1;
if (sfall_ver_major >= 4) then
set_global_script_repeat(0);
call set_door_flag(FLAG_WALKTHRU);
end
end
end
procedure map_enter_p_proc begin
only_once := 1;
call set_door_flag(FLAG_WALKTHRU);
end
procedure set_door_flag(variable state) begin
variable objectMap, obj, objPid, arrayPid, i;
objectMap := list_as_array(LIST_SCENERY);
arrayPid := temp_array(1, 0);
foreach (obj in objectMap) begin
objPid := obj_pid(obj);
if (proto_data(objPid, sc_type) != PORTAL) or is_in_array(objPid, arrayPid) then
continue;
arrayPid[i] := objPid;
i++;
resize_array(arrayPid, i + 1);
set_proto_data(objPid, DOOR_FLAGS, state);
end
end
procedure combatturn_handler begin
if (only_once == 1) then
set_global_script_repeat(60);
end
@@ -0,0 +1,9 @@
Auto Doors mod for Fallout 2 by Mr.Stalin
-----------------------------------------
- allows the player to automatically open/walk through unlocked doors when not in combat
Requires sfall 3.7b or higher.
To use, copy gl_autodoors.int to your scripts folder.
Binary file not shown.
@@ -1,22 +1,24 @@
procedure start;
procedure start;
// adjust include paths if needed
#include "..\..\scripting_docs\headers\sfall.h"
#include "..\..\scripting_docs\headers\sfall.h"
#define RESULT_SUCCESS (1)
#define RESULT_FAIL (0)
procedure start begin
if not init_hook then begin
procedure start begin
if game_loaded then begin
register_hook(HOOK_STEAL);
end else begin
variable
thief := get_sfall_arg,
target := get_sfall_arg,
item := get_sfall_arg,
action := get_sfall_arg,
result := RESULT_SUCCESS;
if (thief == dude_obj) then begin
display_msg(sprintf(mstr_skill(570 + result + action*2), obj_name(item)));
set_sfall_return(result);
end
end
if (thief == dude_obj) then begin
display_msg(sprintf(mstr_skill(570 + result + action*2), obj_name(item)));
set_sfall_return(result);
end
end
end
Binary file not shown.
@@ -0,0 +1,20 @@
procedure start;
// adjust include paths if needed
#include "..\..\scripting_docs\headers\sfall.h"
#include "..\..\scripting_docs\headers\dik.h"
procedure start begin
if game_loaded then begin
register_hook(HOOK_KEYPRESS);
end else begin
variable
event := get_sfall_arg,
keyDX := get_sfall_arg;
if (event == 1) and (keyDX == DIK_SEMICOLON) then begin
tap_key(DIK_CAPITAL);
tap_key(DIK_A);
tap_key(DIK_CAPITAL);
end
end
end
Binary file not shown.
@@ -1,16 +0,0 @@
procedure start;
#include ".\HEADERS\dik.h"
procedure start begin
variable event, keyDX;
if not init_hook then begin
event := get_sfall_arg;
keyDX := get_sfall_arg;
if ((event == 1) and (keyDX == DIK_SEMICOLON)) then begin
tap_key(DIK_CAPITAL);
tap_key(DIK_A);
tap_key(DIK_CAPITAL);
end
end
end
@@ -2,8 +2,8 @@
----------------------------------------
- makes pressing the semicolon key send an uppercase A after a semicolon.
- the uppercase A (shift + A if Caps Lock is off) is the built-in hotkey for the TAKE ALL button on the loot screen.
- Note: the uppercase A (shift + A if Caps Lock is off) is the built-in hotkey for the TAKE ALL button on the loot screen.
To use, copy hs_keypress.int file to your scripts folder.
To use, copy *.int file to your scripts folder.
This mod is a simple example of how you can use HOOK_KEYPRESS hooks.
+3 -2
View File
@@ -83,11 +83,13 @@
#define PROTO_IT_SIZE (112)
#define PROTO_IT_WEIGHT (116)
#define PROTO_IT_COST (120)
#define PROTO_IT_INV_FID (124)
// weapons
#define PROTO_WP_ANIM (36)
#define PROTO_WP_DMG_MIN (40)
#define PROTO_WP_DMG_MAX (44)
#define PROTO_WP_DMG_TYPE (48)
#define PROTO_WP_RANGE_1 (52)
#define PROTO_WP_RANGE_2 (56)
#define PROTO_WP_PROJ_PID (60)
@@ -159,11 +161,10 @@
#define PROTO_DR_ADDICT_DELAY (100)
// critters
#define PROTO_CR_ACTION_FLAGS (32)
#define PROTO_CR_FLAGS (32)
#define PROTO_CR_HEAD_FID (40)
#define PROTO_CR_AI_PACKET (44)
#define PROTO_CR_TEAM_NUM (48)
#define PROTO_CR_FLAGS (52)
#define PROTO_CR_BODY_TYPE (388)
#define PROTO_CR_KILL_EXP (392)
#define PROTO_CR_KILL_TYPE (396)
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+162
View File
@@ -0,0 +1,162 @@
#ifndef LIB_INVEN_H
#define LIB_INVEN_H
#include "define_lite.h"
/**
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;
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;
end
// aliases:
#define add_item_pid(obj, pid) add_items_pid(obj, pid, 1)
#ifndef critter_wearing_armor
#define critter_wearing_armor(x) (obj_item_subtype(critter_inven_obj(x,INVEN_TYPE_WORN)) == item_type_armor)
#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
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
removed_qty := pid_qty;
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
call unwield_armor(who_obj);
end else if ((critter_inven_obj(who_obj, INVEN_TYPE_LEFT_HAND) == item) or (critter_inven_obj(who_obj, INVEN_TYPE_RIGHT_HAND) == item)) then begin
inven_unwield(who_obj);
end
end
tmp := rm_mult_objs_from_inven(who_obj, item, removed_qty);
destroy_object(item);
end
end
procedure remove_item_obj(variable who_obj, variable item) begin
if (obj_type(who_obj) == 1) then begin
if (critter_inven_obj(who_obj,INVEN_TYPE_WORN) == item) then begin
call unwield_armor(who_obj);
end else if ((critter_inven_obj(who_obj, INVEN_TYPE_LEFT_HAND) == item) or (critter_inven_obj(who_obj, INVEN_TYPE_RIGHT_HAND) == item)) then begin
inven_unwield(who_obj);
end
end
rm_obj_from_inven(who_obj, item);
destroy_object(item);
end
// aliases:
#define remove_item_pid(obj, pid) remove_items_pid(obj, pid, 1)
#define remove_all_items_pid(obj, pid) remove_items_pid(obj, pid, -1)
/**
Set item quantity in inventory, by item pid
*/
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
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
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
*/
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
procedure item_by_attack_type(variable critter, variable type) begin
variable slot;
if (type > 3 and type != ATKTYPE_LWEP_RELOAD and type != ATKTYPE_RWEP_RELOAD) then
return 0;
if (type < 2 or type == ATKTYPE_LWEP_RELOAD) then
slot := INVEN_TYPE_LEFT_HAND;
else
slot := INVEN_TYPE_RIGHT_HAND;
return critter_inven_obj(critter, slot);
end
#endif
+47
View File
@@ -0,0 +1,47 @@
#ifndef LIB_MATH_H
#define LIB_MATH_H
/**
Numbers...
*/
#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)
procedure max(variable x, variable y) begin
if (x > y) then return x;
return y;
end
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++;
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;
end
#endif
+85
View File
@@ -0,0 +1,85 @@
#ifndef LIB_MISC_H
#define LIB_MISC_H
/**
Some generic procedures
*/
/*
procedure round(variable val) begin
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;
end*/
// Parse keyboard shortcut definition
procedure parse_hotkey(variable string) begin
variable lst;
variable n;
lst := string_split(string, "+");
if (len_array(lst) == 0) then
return 0;
n := atoi(lst[0]);
if (len_array(lst) > 1) then
n += atoi(lst[1])*0x10000;
return n;
end
// Check if shortcut is pressed
procedure hotkey_pressed(variable n) begin
if (n < 0x10000) then
return key_pressed(n);
else
return key_pressed(n bwand 0xFFFF) and key_pressed((n bwand 0xFFFF0000) / 0x10000);
end
// same as above, but suited for hs_keypress hook when keycode is already known
procedure hotkey_pressed_now(variable n, variable key) begin
if (n < 0x10000) then
return key == n;
else begin
variable k1 := (n bwand 0xFFFF),
k2 := ((n bwand 0xFFFF0000) / 0x10000);
if (k1 == key) then begin
if (key_pressed(k2)) then return true;
end else if (k2 == key) then begin
if (key_pressed(k1)) then return true;
end
return false;
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++;
end
resize_array(arr, i);
list_end(list);
return arr;
end*/
#endif
+243
View File
@@ -0,0 +1,243 @@
/**
This library contains procedures to work with strings.
@author phobos2077
*/
#ifndef LIB_STRINGS_H
#define LIB_STRINGS_H
#define is_in_string(str, substr) (string_pos(str, substr) != -1)
#define string_starts_with(str, substr) (string_pos(str, substr) == 0)
/**
* Returns position of first occurance of substr in str, or -1 if not found
*/
procedure string_pos(variable str, variable subst) begin
variable lst, n;
lst := string_split(str, subst);
if (len_array(lst) < 2) then
return -1;
return strlen(lst[0]);
end
/**
* Join array of strings using delimeter
*/
procedure string_join(variable array, variable join) begin
variable str, i, len;
str := "";
len := len_array(array);
if (len > 0) then begin
str := array[0];
for (i:=1; i<len; i++) begin
str += join + array[i];
end
end
return str;
end
/**
* replaces all occurances of substring in a string with another substring
*/
#define string_replace(str, search, replace) (string_join(string_split(str, search), replace))
/**
* sprintf with two arguments
*/
procedure sprintf2(variable str, variable arg1, variable arg2) begin
variable split, len, i, j, arg;
split := string_split(str, "%");
len := len_array(split);
str := "";
if (len > 0) then begin
str := split[0];
j := 0;
for (i := 1; i < len; i++) begin
if (split[i] == "") then begin
if (i < len - 1) then begin
str += "%" + split[i+1];
i++;
end
end else begin
if (j == 0) then
arg := arg1;
else if (j == 1) then
arg := arg2;
else
arg := 0;
str += sprintf("%" + split[i], arg);
j++;
end
end
end
return str;
end
/**
* sprintf with unlimited number of arguments
*/
procedure sprintf_array(variable str, variable args) begin
variable split, len, i, j;
split := string_split(str, "%");
len := len_array(split);
str := "";
if (len > 0) then begin
str := split[0];
j := 0;
for (i := 1; i < len; i++) begin
if (split[i] == "") then begin
if (i < len - 1) then begin
str += "%" + split[i+1];
i++;
end
end else begin
str += sprintf("%" + split[i], args[j]);
j++;
end
end
end
return str;
end
/**
* Returns position of last occurance of substr in str, or -1 if not found
*/
/*procedure string_rpos(variable str, variable substr) begin
variable lst, n;
lst := string_split(str, substr);
n := len_array(lst);
if (n < 2) then
return -1;
return string_len(str) - (string_len(lst[n-1]) + string_len(substr));
end*/
/**
* Basically the same as string_split, but delim is of type char instead of string
*/
procedure string_get_tokens(variable str, variable delim) begin
variable lst, line, token, maxlen, len, count;
count := 1;
maxlen := 4;
token := tokenize(str, 0, delim);
//if (token != 0) then
//count := 1;
line := token;
while (line != str) do begin
count += 1;
len := strlen(token);
if (len > maxlen) then
maxlen := len;
token := tokenize(str, line, delim);
if (token != 0) then
line += delim + token;
end
//end
return count;
end
procedure string_repeat(variable str, variable count) begin
variable out := "", i := 0;
while (i < count) do begin
out += str;
i++;
end
return out;
end
/**
* Workaround for string_split bug in sfall 3.3
* DEPRECATED as of sfall 3.4 (bug fixed)
*/
procedure string_split_safe(variable str, variable split) begin
variable lst;
str += split;
lst := string_split(str, split);
resize_array(lst, len_array(lst) - 1);
return lst;
end
/**
* The same as sfall string_split, but returns array of integers instead
* 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;
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:
parse_str_2("Hello, %2%. I have only $%1% to spare.", money_amount, dude_name);
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
#define _TOKENIZE_END \
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
_TOKENIZE_BEGIN
n := atoi(token) - 1;
if (n >= 0 and n < len_array(list)) then result += list[n];
_TOKENIZE_END
end
procedure parse_str_2(variable str, variable x1, variable x2) begin
_TOKENIZE_BEGIN
n := atoi(token);
if (n == 1) then result += x1;
else if (n == 2) then result += x2;
_TOKENIZE_END
end
procedure parse_str_4(variable str, variable x1, variable x2, variable x3, variable x4) begin
_TOKENIZE_BEGIN
n := atoi(token);
if (n == 1) then result += x1;
else if (n == 2) then result += x2;
else if (n == 3) then result += x3;
else if (n == 4) then result += x4;
_TOKENIZE_END
end
#undef _TOKENIZE_BEGIN
#undef _TOKENIZE_END
#endif

Some files were not shown because too many files have changed in this diff Show More