Release 4.3

This commit is contained in:
NovaRain
2021-06-01 12:00:50 +08:00
201 changed files with 11822 additions and 4200 deletions
+34
View File
@@ -0,0 +1,34 @@
name: github pages
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
sudo apt -y -qq install bundler python3-pip
pip3 install ruamel.yaml --user
- name: Build
run: ./docs/generate.sh
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_site
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
+8
View File
@@ -55,8 +55,10 @@ nb-configuration.xml
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Dd]evXP
[Rr]elease/
[Rr]eleases/
[Rr]eleaseXP/
x64/
x86/
build/
@@ -222,3 +224,9 @@ FakesAssemblies/
# Visual Studio 6 workspace options file
*.opt
sfall/postbuild.cmd
# jekyll build files
docs/_site
docs/.sass-cache
docs/.jekyll-metadata
docs/pages/*.md
+1
View File
@@ -1,4 +1,5 @@
# sfall
[![github pages](https://github.com/phobos2077/sfall/actions/workflows/gh-pages.yml/badge.svg)](https://github.com/phobos2077/sfall/actions/workflows/gh-pages.yml)
A set of engine modifications for the classic game Fallout 2 in form of a DLL, which modifies executable in memory without changing anything in EXE file itself.
+46 -30
View File
@@ -1,27 +1,27 @@
;sfall configuration settings
;v4.2.9
;v4.3
[Main]
;Change to 1 if you want to use command line args to tell sfall to use another ini file.
UseCommandLine=0
;Uncomment and point to a file to get alternate translations for some sfall messages
;This file can be placed in text\<language>\ for sfall to get the translations depending on the game language
;TranslationsINI=sfall\Translations.ini
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[ExtraPatches]
;This section allows you to set multiple paths to folders containing mods or patches that will be loaded by the game
;The priority of read files will be higher than the files in patchXXX.dat
;If DataLoadOrderPatch is enabled, the data load order will be:
;master_patches > critter_patches > PatchFile99 - PatchFile0 > patchXXX.dat > ...
;Paths to folders and Fallout .dat files are supported. The available range for PatchFile option names is from 0 to 99
;The greater numbers take precedence over lesser numbers
;If DataLoadOrderPatch is enabled, the data load order is:
;master_patches > critter_patches > PatchFile99..PatchFile0 > patchXXX.dat > critter_dat > f2_res_patches > f2_res_dat > master_dat
;Paths to folders and Fallout .dat files are supported
;The PatchFile## options are available from 0 to 99. Larger numbers take precedence over smaller numbers (same as patchXXX.dat)
;PatchFile0=mods\RP_data
;Path to the folder in which the game will automatically search and load custom files (by *.dat mask, including folders)
;The data load order of the files in the folder will be in reverse alphabetical order of the filenames
;The files placed in this folder will have higher priority than the PatchFileXX options
;This option has no effect in v4.2.6 or later. The default path is <GameRoot>\mods\
;The files placed in this folder will have higher priority than the PatchFile## options
;This option has no effect in 4.2.6 or later. The path is fixed to <GameRoot>\mods\
;AutoSearchPath=mods
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@@ -149,7 +149,7 @@ OverrideMusicDir=1
UseScrollWheel=1
;The mouse Z position is divided by this modifier to calculate the number of inventory
;slots to scroll. My mouse moves 120 pixel in the z direction for one click of the mouse
;slots to scroll. My mouse moves 120 pixels in the z direction for one click of the mouse
;wheel, but this may vary depending on your mouse manufacturer and windows settings.
;Set to 0 to only ever scroll 1 click
ScrollMod=0
@@ -159,9 +159,9 @@ ScrollMod=0
MouseSensitivity=100
;DX scancode of a key to press when the middle mouse button is clicked
;The default of 0x30 toggles between your two weapons
;The default of 48 ('B' key) toggles between your active items
;Set to 0 to disable
MiddleMouse=0x30
MiddleMouse=48
;Set to 1 to reverse the left and right mouse buttons
ReverseMouseButtons=0
@@ -240,6 +240,7 @@ WorldMapTimeMod=100
WorldMapFPSPatch=1
;Controls the world map speed if WorldMapFPSPatch is 1. Higher values cause slower movement
;Default is 66 milliseconds
WorldMapDelay2=66
;Set to 1 to enable Ray's patch to make world map encounter rate independent of your travel speed
@@ -272,7 +273,8 @@ UseFileSystemOverride=0
;Set to 1 to use the modified data load order for the engine to find game data
;Original: patchXXX.dat > critter_patches > critter_dat > f2_res_patches > f2_res_dat > master_patches > master_dat
;Modified: master_patches > critter_patches > patchXXX.dat > critter_dat > f2_res_patches > f2_res_dat > master_dat
DataLoadOrderPatch=1
;This option is always enabled in 4.3/3.8.30 or later. The information is left for reference only
;DataLoadOrderPatch=1
;Set to 1 to load alternative dialog msg files from text\<language>\dialog_female\ for female PC
;Set to 2 to also load subtitle files from text\<language>\cuts_female\ for female PC
@@ -369,7 +371,7 @@ SingleCore=1
OverrideArtCacheSize=0
;Prevents you from saving in combat except at the start of your turn to avoid a few bugs
;Note that even with this option enabled, it is still not advisable to save in combat at all (obsolete information)
;Note that even with this option enabled, it is still not advisable to save in combat
;Set to 2 to block all saving in combat
SaveInCombatFix=1
@@ -419,7 +421,7 @@ CorpseDeleteTime=6
;Set a number of milliseconds to idle each input loop
;Set to -1 to disable
;Set to 0 to idle only if other processes are waiting for processor time (WinXP/2000: if processes have equal priority)
;Set to 1 (or some higher number if needed) to prevent 100% CPU use. The maximum is 127
;Set to 1 (or some higher number if needed) to prevent 100% CPU use. The maximum is 30
ProcessorIdle=-1
;Set to 1 if using the hero appearance mod
@@ -436,17 +438,19 @@ SkipOpeningMovies=0
;Set to 0 to disable
NPCsTryToSpendExtraAP=0
;Set to 1 to fix NPCs not checking weapon perks properly when choosing the best weapon in combat
;Set to 2 to change the priority multiplier for having weapon perk to 3x (the original is 5x)
;Note that enabling this option can significantly affect the weapon of choice for some NPCs
AIBestWeaponFix=0
;Set to 1 to fix the priority score calculation for choosing the best weapon for NPCs
;Note that enabling this option can affect the weapon of choice for some NPCs
AIBestWeaponFix=1
;Set to 1 to fix NPCs not taking chem_primary_desire in AI.txt as drug use preference when using drugs in their inventory
;Set to 2 to allow NPCs to use only the drugs listed in chem_primary_desire and healing drugs (stimpaks and healing powder)
;Note: chem_primary_desire w/o fixes prevents the specified item PID from being consumed if all three values in the list are the same PID
;chem_primary_desire also works as a priority list of drug items the NPC will try to pick up in combat when they are on the ground
AIDrugUsePerfFix=0
;Allows the use of tiles over 80x36 in size. sfall will just split and resave them at startup
;Set to 1 to check all tiles on started (slow)
;Set to 2 if you provide a XLtiles.lst file in art\tiles\ containing a list of the tile ids that need checking
;Allows the use of tiles over 80x36 in size. sfall will just split and resave them to art\tiles\zzz####.frm at startup
;Set to 1 to check all tiles on started (slow, but can also be useful for checking the correct size of your new tiles)
;Set to 2 if you provide a XLtiles.lst file in art\tiles\ containing a list of the tile indexes that need checking
AllowLargeTiles=0
;Set to 1 to boost the maximum number of tile FRMs from 4096 to 16383
@@ -541,11 +545,11 @@ RemoveCriticalTimelimits=0
;MainMenuBigFontColour=0x3C
;Alternative behaviors to the Fast Shot trait
;0 - Fallout 2 original behavior: -1 AP cost for ranged weapons; aimed attacks are disabled
;1 - Haenlomal's fix: aimed attacks are enabled for melee/unarmed weapons and HtH attacks
;0 - Fallout 2 original behavior: -1 AP cost for ranged weapons. Aimed attacks are disabled
;1 - Haenlomal's tweak: aimed attacks are enabled for melee/unarmed weapons and HtH attacks
;2 - Alternative behavior: apply -1 AP cost to melee/unarmed weapons and HtH attacks
;3 - Fallout 1 original behavior: -1 AP cost for all weapons; aimed attacks are disabled
FastShotFix=1
;3 - Fallout 1 original behavior: -1 AP cost for all weapons. Aimed attacks are disabled
FastShotFix=0
;Set to 1 to fix the carry weight penalty of the Small Frame trait not being applied to bonus Strength points
SmallFrameFix=0
@@ -595,7 +599,7 @@ ObjCanSeeObj_ShootThru_Fix=0
;Set to 1 to fix the broken obj_can_hear_obj script function
ObjCanHearObjFix=0
;Set to 1 to enable the mood argument of start_gdialog script function to be available for talking heads
;Set to 1 to enable the 'mood' argument of start_gdialog script function for talking heads
;If the argument value is -1, the mood will be determined by the local variable 0 of the script (vanilla behavior)
StartGDialogFix=0
@@ -605,6 +609,11 @@ StartGDialogFix=0
;num_attacks - the number of free action points on the first turn only
AttackComplexFix=0
;Set to 1 to make the create_object_sid script function run the 'start' procedure of attached script upon object creation
;By default, the 'start' procedure of attached script is executed after the current script procedure is finished
;Note that enabling this option may cause unexpected results with some existing game scripts
CreateObjectSidFix=0
;Set to 1 to fix the issue with the division operator treating negative integers as unsigned
;Note: To perform the unsigned integer division, use the new 'div' operator
DivisionOperatorFix=1
@@ -642,7 +651,7 @@ ExplosionsEmitLight=0
;Set to 0 for backward compatibility with pre-3.4 scripts
arraysBehavior=1
;Set to 1 to add proper checks if there is enough ammo to use weapons that use multiple ammo per shot
;Set to 1 to add proper checks to see if there is enough ammo to attack with weapons that use multiple ammo per shot
CheckWeaponAmmoCost=0
;Controls the speed of combat panel animations (lower - faster; valid range: 0..65535)
@@ -738,9 +747,14 @@ SkipLoadingGameSettings=0
SpecialDeathGVAR=491
;Set to 1 to disable the special handling of map IDs 19 and 37 in the engine when entering the maps
;Note that enabling this option can break the map changes in Modoc and Vault 15
;Note that enabling this option will break the map changes in Modoc and Vault 15 in Fallout 2
DisableSpecialMapIDs=0
;Set to 1 to disable the special handling of city areas 45 and 46 in the engine when visiting Area 45:
;Area 45 automatically disappears from the world map, and Area 46 appears on the world map
;Note that enabling this option will break the location change of the 'Fake Vault 13' in Fallout 2
DisableSpecialAreas=0
;Changes the base value of the duration of the knockout effect (valid range: 35..100; default is 35)
;The formula for the duration in ticks is: 10 * (value - 3 * EN)
KnockoutTime=35
@@ -851,10 +865,12 @@ Test_ForceFloats=0
;These options control what output is saved in the debug log (sfall-log.txt)
;Prints messages duing sfall initialization
Init=0
Init=1
;Prints messages relating to hook scripts
Hook=0
;Prints messages relating to scripting
Script=0
;Prints messages relating to the critical table
Criticals=0
Criticals=1
;Prints messages relating to engine fixes
Fixes=1
@@ -13,8 +13,10 @@ Requires sfall 4.2.2/3.8.29 or higher
#include "..\headers\sfall\define_extra.h"
procedure start;
procedure close;
variable lootObject;
variable closeObject;
procedure start begin
if (game_loaded) then begin
@@ -26,8 +28,14 @@ procedure start begin
lootObject := loot_obj;
if (obj_type(lootObject) != OBJ_TYPE_ITEM) then lootObject = 0;
end else if (lootObject andAlso get_sfall_arg_at(1) == INTFACELOOT) then begin
obj_close(lootObject);
lootObject = 0;
if (get_object_data(lootObject, OBJ_DATA_CUR_FRM) > 1) then begin
closeObject = lootObject;
call close in 0;
end
end
end
end
procedure close begin
obj_close(closeObject);
end
Binary file not shown.
Binary file not shown.
+14 -1
View File
@@ -9,7 +9,7 @@
NOTE: this script requires compiler from sfall modderspack with -s option
(short circuit evaluation)
version 1.1
version 1.2
*/
@@ -21,6 +21,7 @@
#define FID_OBJ_CRITTER (0x01000000)
procedure update_armor_apperance;
procedure canuseweapon_handler;
variable
modIni := "npcarmor.ini",
@@ -203,6 +204,7 @@ procedure start begin
register_hook_proc(HOOK_INVENWIELD, invenwield_handler);
register_hook_proc(HOOK_ADJUSTFID, adjustfid_handler);
register_hook_proc(HOOK_INVENTORYMOVE, inventorymove_handler);
register_hook_proc_spec(HOOK_CANUSEWEAPON, canuseweapon_handler);
debug_msg("NPC armor appearance mod: Done.");
end
@@ -220,3 +222,14 @@ procedure update_armor_apperance begin
end
end
end
procedure canuseweapon_handler begin
variable critter, canWield;
critter := get_sfall_arg;
//if (critter) then begin
canWield := check_weapon_change(critter, get_sfall_arg, true);
// override result
set_sfall_arg(3, canWield);
set_sfall_return(canWield);
//end
end
+1 -1
View File
@@ -137,7 +137,7 @@ end
procedure start begin
if (game_loaded and sfall_ver_major >= 4) then begin
variable configSection := "CombatControl";
//variable configSection := "CombatControl";
set_perk_ranks(PERK_gecko_skinning_perk, 1);
set_perk_level(PERK_gecko_skinning_perk, 999); // prevent it from appearing in the perk selection window
+4 -4
View File
@@ -25,7 +25,7 @@ end
// Gets the string value from the specified ini
procedure GetIniConfigStr(variable section, variable key, variable def, variable inifile) begin
variable val := get_ini_string(inifile + "|" + section + "|" + key);
if val == -1 or val == "" then val := def;
if val == -1 orElse val == "" then val := def;
return val;
end
@@ -39,14 +39,14 @@ end
// Gets the string value from sfall-mods.ini
procedure GetConfigStr(variable section, variable key, variable def) begin
variable val := get_ini_string(ini + "|" + section + "|" + key);
if val == -1 or val == "" then val := def;
if val == -1 orElse val == "" then val := def;
return val;
end
// Gets the value from sfall-mods.ini as a temp array of strings
procedure GetConfigList(variable section, variable key) begin
variable val := get_ini_string(ini + "|" + section + "|" + key);
if val == -1 or val == "" then return [];
if val == -1 orElse val == "" then return [];
return string_split(val, ",");
end
@@ -65,7 +65,7 @@ end
// Translates given string using Translations.ini
procedure Translate(variable id, variable def) begin
variable str := get_ini_string(translationIni + "|Sfall|" + id);
if not str or (strlen(str) == 0) then begin
if (str == 0 orElse (strlen(str) == 0)) then begin
str := def;
end
return str;
+25
View File
@@ -0,0 +1,25 @@
This folder contains documentation about sfall scripting extensions.
headers\ - folder contains sfall headers that you should #include in your scripts
sfall.h - main sfall header, always include it
define_extra.h - some additional preprocessor constants for vanilla engine stuff (proto offsets, etc.)
define_lite.h - a lite version of official define.h
command_lite.h - a lite version of official command.h
dik.h - DX scancodes constants for use with key_pressed function and HOOK_KEYPRESS
lib.arrays.h - procedures that will help you use arrays in their full:
- use them as stacks, sets
- easily compare, copy, slice, cut, add arrays
- display array contents (for debugging)
- save/load two-dimensional arrays to savegame in one command (e.g. arrays of objects)
lib.inven.h - fallout items manipulation functions
lib.math.h - a few simple functions for calculations
lib.strings.h - search in strings, join, repeat, etc.
lib.misc.h - misc stuff
sfall function notes.md - incomplete reference for new opcodes
sfall opcode list.md - list of all sfall opcodes (w/o descriptions)
hookscripts.md - detailed manual for using hook scripts to modify engine behavior
arrays.md - manual for sfall arrays
If you are/will be using sfall Script Editor, don't forget to check out new compiler documentation in **.\compiler\sslc_readme.txt**.
There are numerious new syntax features and extensions to SSL (Star-Trek Scripting language).
+7 -7
View File
@@ -4,12 +4,13 @@ This folder contains documentation about sfall scripting extensions.
sfall.h - main sfall header, always include it
define_extra.h - some additional preprocessor constants for vanilla engine stuff (proto offsets, etc.)
define_lite.h - a lite version of official define.h
command_lite.h - a lite version of official command.h
dik.h - DX scancodes constants for use with key_pressed function and HOOK_KEYPRESS
lib.arrays.h - procedures that will help you use arrays in their full:
- use them as stacks, sets
- easily compare, copy, slice, cut, add arrays
- display array contents (for debugging)
- save/load two-dimensional arrays to savegame in one command (e.g. arrays of objects)
- use them as stacks, sets
- easily compare, copy, slice, cut, add arrays
- display array contents (for debugging)
- save/load two-dimensional arrays to savegame in one command (e.g. arrays of objects)
lib.inven.h - fallout items manipulation functions
lib.math.h - a few simple functions for calculations
lib.strings.h - search in strings, join, repeat, etc.
@@ -20,6 +21,5 @@ This folder contains documentation about sfall scripting extensions.
hookscripts.txt - detailed manual for using hook scripts to modify engine behavior
arrays.txt - manual for sfall arrays
If you are/will be using sfall Script Editor, don't forget to check out new compiler documentation in ScriptEditor\docs\sslc_readme.txt,
there are numerious new syntax features and extensions to SSL (Star-Trek Scripting language).
If you are/will be using sfall Script Editor, don't forget to check out new compiler documentation in .\compiler\sslc_readme.txt.
There are numerious new syntax features and extensions to SSL (Star-Trek Scripting language).
+244
View File
@@ -0,0 +1,244 @@
ARRAYS
------
sfall introduces new method of storing variables - arrays.
Array is basically a container which can store variable number of values (elements). Each element in array can be of any type.
Arrays can be extremely useful for some more advanced scripting, in conjunction with loops.
***
### ARRAYS CONCEPT
Arrays are created and manipulated with the array functions. An array must first be created with `create_array` or `temp_array`, specifying how many data elements the array can hold. You can store any of ints, floats and strings in an array, and can mix all 3 in a single array. The ID returned by `create_array` or `temp_array` can then be used with the other array functions. Arrays are shared between all scripts (i.e. you can call `create_array` from one script, and then use the returned ID from another script). They are also saved across savegames.
Arrays created with `temp_array` will be automatically freed at the end of the frame. These functions are safe, in that supplying a bad ID or trying to access out of range elements will not crash the script. `create_array` is the only function that returns a permanent array, all other functions which return arrays (`string_split`, `list_as_array`, etc,) all return temporary arrays. You can use `fix_array` to make a temporary array permanent.
Array elements are accessed by index or key. For example:
```js
// this code puts some string in array "list" at index 5:
list[5] := "Value";
```
There are 2 different types of arrays currently available:
* **Lists** - a set of values with specific size (number of elements), where all elements have numeric indexes starting from zero (0) up to array length minus one.
For example:
```js
// this creates list with 3 elements. Element "A" has index 0, element "B" has index 1, element "C" - 2
list := ["A", "B", "C"];
```
Limitations:
- all indexes are numeric, starting from 0;
- to assign value to a specific index, you must first resize array to contain this index
(for example, if list is of size 3 (indexes from 0 to 2), you can't assign value to index 4 unless you change list size to 5 first).
* **Maps** (or associative arrays) - a set of key=>value pairs, where all elements (values) are accessed by corresponding keys.
Differences from list:
- maps don't have specific size (to assign values, you don't need to resize array first);
- keys, just like values, can be of any type (but avoid using -1 as array keys or you won't be able to use some functions reliably).
Both array types have their pros and cons and are suited for different tasks.
___
### ARRAYS SYNTAX
Basically arrays are implemented using number of new operators (scripting functions). But for ease of use, there are some new syntax elements:
* Accessing elements. Use square brackets:
```js
display_msg(arr[5]);
mymap["price"] := 515.23;
```
* Alternative accessing for maps. Use dot:
```js
display_msg(mymap.name);
mymap.price := 232.23;
```
* Array expressions. Create and fill arrays with just one expression:
```js
// create list with 5 values
[5, 777, 0, 3.14, "Cool Value"]
// create map:
{5: "Five", "health": 50, "speed": 0.252}
```
__NOTES:__
Make sure to call `fix_array` if you want new array to be available in the next frame or `save_array` if you want to use it for a longer period (see next section for details).
* Iterating in loop. Use `foreach` key word like this:
```js
foreach (item in myarray) begin
// this block is executed for each array element, where "item" contains current value on each step
end
// alternative syntax:
foreach (key: item in myarray) begin
// "key" will contain current key (or numeric index, for lists)
end
```
See **sslc_readme.txt** file for full information on new SSL syntax features.
___
### STORING ARRAYS
Apart from lists/maps, arrays are divided by how they are stored.
There a 3 types of arrays:
* **Temporary**. They are created using `temp_array` function or when using array expressions.
Arrays of this type are auto-deleted at the end of the frame. So, for example, if you have a global script which runs at regular intervals, where you create a temporary array, it will not be available next time your global script is executed.
* **Permanent**. They are created using `create_array` function or `fix_array` (from pre-existing temporary array).
This type of arrays are always available (by their ID) until you start a new game or load a saved game (at which point they are deleted).
* **Saved**. If you want your array to really stay for a while, use function `save_array` to make any array "saved". However, they are, like permanent arrays, "deleted" from memory when loading game. In order to use them properly, you must load them from the savegame using `load_array` whenever you want to use them.
Example:
```js
variable savedArray;
procedure start begin
if game_loaded then begin
savedArray := load_array("traps");
end else begin
foreach trap in traps begin
....
end
end
end
```
___
### PRACTICAL EXAMPLES
**Use arrays to implement variable-argument procedures:**
```js
// define it
procedure give_item(variable critter, variable pidList) begin
foreach (pid: qty in pidList) begin
give_pid_qty(critter, pid, qty);
end
end
// call it:
call give_item(dude_obj, {PID_SHOTGUN: 1, PID_SHOTGUN_SHELLS: 4, PID_STIMPAK: 3});
```
**Create arrays of objects (maps) for advanced scripting:**
```js
variable traps;
procedure init_traps begin
// just a quick example, there is a better way of doing it...
traps := load_array("traps");
if (traps == 0) then begin
traps := [];
save_array("traps", traps);
end
foreach k: v in traps begin
traps[k] := load_array("trap_"+k); // each object is stored separately
end
end
procedure add_trap(variable trapArray) begin
variable index;
index := len_array(traps);
save_array("trap_"+k, trapArray);
array_push(traps, trapArray);
end
// use them:
foreach trap in traps begin
if (self_elevation == trap["elev"] and tile_distance(self_tile, trap["tile"]) < trap["radius"]) then
// kaboom!!!
end
end
```
___
### ARRAY OPERATORS REFERENCE
_*mixed means any type_
#### `int create_array(int size, int flags)`
- creates permanent array (but not "saved")
- if `size >= 0`, creates list with given size
- if `size == -1`, creates map (associative array)
- if `size == -1` and `flags == 2`, creates a "lookup" map (associative array) in which the values of existing keys are read-only and can't be updated. This type of array allows you to store a zero (0) key value
* NOTE: in earlier versions (up to 4.1.3/3.8.13) the second argument is not used, just use 0
- returns array ID (valid until array is deleted)
#### `int temp_array(int size, int flags)`
- works exactly like `create_array`, only created array becomes "temporary"
#### `void fix_array(int arrayID)`
- changes "temporary" array into "permanent" ("permanent" arrays are not automatically saved into savegames)
#### `void set_array(int arrayID, mixed key, mixed value)`
- sets array value
- if used on list, "key" must be numeric and within valid index range (0..size-1)
- if used on map, key can be of any type
- to "unset" a value from map, just set it to zero (0)
* NOTE: to add a value of 0 for the key, use the float value of 0.0
- this works exactly like statement: `arrayID[key] := value;`
#### `mixed get_array(int arrayID, mixed key)`
- returns array value by key or index
- if key doesn't exist or index is not in valid range, returns 0
- works exactly like expression: `(arrayID[key])`
#### `void resize_array(int arrayID, int size)`
- changes array size
- applicable to maps too, but only to reduce elements
- there are number of special negative values of "size" which perform various operations on the array, use macros `sort_array`, `sort_array_reverse`, `reverse_array`, `shuffle_array` from **sfall.h** header
#### `void free_array(int arrayID)`
- deletes any array
- if array was "saved", it will be removed from a savegame
#### `mixed scan_array(int arrayID, mixed value)`
- searches for a first occurence of given value inside given array
- if value is found, returns it's index (for lists) or key (for maps)
- if value is not found, returns -1 (be careful, as -1 can be a valid key for a map)
#### `int len_array(int arrayID)`
- returns number of elements or key=>value pairs in a given array
- if array is not found, returns -1 (can be used to check if given array exist)
#### `mixed array_key(int arrayID, int index)`
- don't use it directly; it is generated by the compiler in foreach loops
- for lists, returns index back (no change)
- for maps, returns a key at the specified numeric index (don't rely on the order in which keys are stored though)
- can be checked if given array is associative or not, by using index (-1): 0 - array is list, 1 - array is map
#### `int arrayexpr(mixed key, mixed value)`
- don't use it directly; it is used by compiler to create array expressions
- assigns value to a given key in an array, created by last `create_array` or `temp_array` call
- always returns 0
#### `void save_array(mixed key, int arrayID)`
- makes the array saveable; it will be saved in **sfallgv.sav** file when saving the game
- array ID is associated with given "key"
- array becomes permanent (if it was temporary) and "saved"
- key can be of any type (int, float or string)
- if you specify 0 as the key for the array ID, it will make the array "unsaved"
#### `int load_array(mixed key)`
- loads array from savegame data by the same key provided in `save_array`
- returns array ID or zero (0) if none found
___
### BACKWARD COMPATIBILITY NOTES
For those who used arrays in their mods before sfall 3.4:
* There is an INI parameter **arraysBehavior** in **Misc** section of ddraw.ini. If set to 0, all scripts which used sfall arrays before should work. This basically changes that `create_array` will create permanent arrays which are "saved" by default and their ID is also permanent. It is 1 by default.
* How savegame compatibility is handled?<br>
Saved arrays are stored in **sfallgv.sav** file (in savegame) in new (more flexible) format, just after the old arrays. So basically, when you load older savegame, sfall will load arrays from old format and save them to new format on next game save. If you load savegame made with sfall 3.4 using sfall 3.3 (for example), game shouldn't crash, but all arrays will be lost.
* Previously you had to specify size in bytes for array elements. This parameter is now ignored and you can store strings of arbitrary length in arrays.
-234
View File
@@ -1,234 +0,0 @@
>>> ARRAYS CONCEPT <<<
Sfall introduces new method of storing variables - arrays.
Array is basically a container which can store variable number of values (elements). Each element in array can be of any type.
Arrays can be extremely useful for some more advanced scripting, in conjunction with loops.
Array elements are accessed by index or key. For example:
// this code puts some string in array "list" at index 5:
list[5] := "Value";
There are 2 different types of arrays currently available:
1) Lists - a set of values with specific size (number of elements), where all elements have numeric indexes starting from zero (0) up to array length minus one.
For example:
// this creates list with 3 elements. Element "A" has index 0, element "B" has index 1, element "C" - 2
list := ["A", "B", "C"];
Limitations:
- all indexes are numeric, starting from 0;
- to assign value to a specific index, you must first resize array to contain this index
(for example, if list is of size 3 (indexes from 0 to 2), you can't assign value to index 4 unless you change list size to 5 first).
2) Maps (or associative arrays) - a set of key=>value pairs, where all elements (values) are accessed by corresponding keys.
Differences from list:
- maps don't have specific size (to assign values, you don't need to resize array first);
- keys, just like values, can be of any type (but avoid using -1 as array keys or you won't be able to use some functions reliably).
Both array types have their pros and cons and are suited for different tasks.
>>> ARRAYS SYNTAX <<<
Basically arrays are implemented using number of new operators (scripting functions). But for ease of use, there are some new syntax elements:
1) Accessing elements. Use square brackets:
display_msg(arr[5]);
mymap["price"] := 515.23;
2) Alternative accessing for maps. Use dot:
display_msg(mymap.name);
mymap.price := 232.23;
3) Array expressions. Create and fill arrays with just one expression:
// create list with 5 values
[5, 777, 0, 3.14, "Cool Value"]
// create map:
{5: "Five", "health": 50, "speed": 0.252}
NOTES:
- make sure to call "fix_array" if you want new array to be available in the next frame or "save_array" if you want to use it for a longer period
(see next section for details)
4) Iterating in loop. Use "foreach" key word like this:
foreach (item in myarray) begin
// this block is executed for each array element, where "item" contains current value on each step
end
// alternative syntax:
foreach (key: item in myarray) begin
// "key" will contain current key (or numeric index, for lists)
end
See "Script editor\docs\sslc readme.txt" file for full information on new SSL syntax features.
>>> STORING ARRAYS <<<
Apart from lists/maps arrays are divided by how they are stored.
There a 3 types of arrays:
1) Temporary. They are created using temp_array function or when using array expressions.
Arrays of this type are auto-deleted at the end of the frame. So, for example, if you have a global script which runs at regular intervals,
where you create temp_array, it will not be available next time your global script is executed.
2) Permanent. They are created using "create_array" function or "fix_array" (from pre-existing temporary array).
This type of arrays are always available (by their ID) until you start a new game or load a saved game (at which point they are deleted).
3) Saved. If you want your array to really stay for a while, use function "save_array" to make any array "saved". However, they are, like permanent arrays,
"deleted" from memory when loading game. In order to use them properly, you must load them from the savegame using "load_array" whenever you want to use them.
Example:
variable savedArray;
procedure start begin
if game_loaded then begin
savedArray := load_array("traps");
end else begin
foreach trap in traps begin
....
end
end
end
>>> PRACTICAL EXAMPLES <<<
> Use arrays to implement variable-argument procedures:
// define it
procedure give_item(variable critter, variable pidList) begin
foreach (pid: qty in pidList) begin
give_pid_qty(critter, pid, qty);
end
end
// call it:
call give_item(dude_obj, {PID_SHOTGUN: 1, PID_SHOTGUN_SHELLS: 4, PID_STIMPAK: 3});
> Create arrays of objects (maps) for advanced scripting:
variable traps;
procedure init_traps begin
// just a quick example, there is a better way of doing it...
traps := load_array("traps");
if (traps == 0) then begin
traps := [];
save_array("traps", traps);
end
foreach k: v in traps begin
traps[k] := load_array("trap_"+k); // each object is stored separately
end
end
procedure add_trap(variable trapArray) begin
variable index;
index := len_array(traps);
save_array("trap_"+k, trapArray);
array_push(traps, trapArray);
end
// use them:
foreach trap in traps begin
if (self_elevation == trap["elev"] and tile_distance(self_tile, trap["tile"]) < trap["radius"]) then
// kaboom!!!
end
end
>>> ARRAY OPERATORS REFERENCE <<<
*mixed means any type
> int create_array(int size, int flags):
- creates permanent array (but not "saved")
- if size is >= 0, creates list with given size
- if size == -1, creates map (associative array)
- if size == -1 and flags == 2, creates a "lookup" map (associative array) in which the values of existing keys are read-only and can't be updated.
This type of array allows you to store a zero (0) key value
- NOTE: in earlier versions (up to 4.1.3/3.8.13) the second argument is not used, just use 0
- returns arrayID (valid until array is deleted)
> int temp_array(int size, int flags):
- works exactly like "create_array", only created array becomes "temporary"
> void fix_array(int arrayID):
- changes "temporary" array into "permanent" ("permanent" arrays are not automatically saved into savegames)
> void set_array(int arrayID, mixed key, mixed value):
- sets array value
- if used on list, "key" must be numeric and within valid index range (0..size-1)
- if used on map, key can be of any type
- to "unset" a value from map, just set it to zero (0)
- NOTE: to add a value of 0 for the key, use the float value of 0.0
- this works exactly like statement:
arrayID[key] := value;
> mixed get_array(int arrayID, mixed key):
- returns array value by key or index
- if key doesn't exist or index is not in valid range, returns 0
- works exactly like expression:
(arrayID[key])
> void resize_array(int arrayID, int size):
- changes array size
- applicable to maps too, but only to reduce elements
- there are number of special negative values of "size" which perform various operations on the array,
use macros sort_array, sort_array_reverse, reverse_array, shuffle_array from sfall.h header
> void free_array(int arrayID):
- deletes any array
- if array was "saved", it will be removed from a savegame
> mixed scan_array(int arrayID, mixed value):
- searches for a first occurence of given value inside given array
- if value is found, returns it's index (for lists) or key (for maps)
- if value is not found, returns -1 (be careful, as -1 can be a valid key for a map)
> int len_array(int arrayID):
- returns number of elements or key=>value pairs in a given array
- if array is not found, returns -1 (can be used to check if given array exist)
> mixed array_key(int arrayID, int index):
- don't use it directly; it is generated by the compiler in foreach loops
- for lists, returns index back (no change)
- for maps, returns a key at the specified numeric index (don't rely on the order in which keys are stored though)
- can be checked if given array is associative or not, by using index (-1): 0 - array is list, 1 - array is map
> int arrayexpr(mixed key, mixed value):
- don't use it directly; it is used by compiler to create array expressions
- assigns value to a given key in an array, created by last "create_array" or "temp_array" call
- always returns 0
> void save_array(mixed key, int arrayID):
- makes the array saveable; it will be saved in sfallgv.sav file when saving the game
- arrayID is associated with given "key"
- array becomes permanent (if it was temporary) and "saved"
- key can be of any type (int, float or string)
- if you specify 0 as the key for the array ID, it will make the array "unsaved"
> int load_array(mixed key):
- load array from savegame data by the same key provided in "save_array"
- arrayID is returned or zero (0) if none found
>>> BACKWARD COMPATIBILITY NOTES <<<
For those who used arrays in their mods before sfall 3.4:
1) There is an INI parameter "arraysBehavior" in "Misc" section of ddraw.ini. If set to 0, all scripts which used sfall arrays before should work. This basically changes that "create_array" will create permanent arrays which are "saved" by default and their ID is also permanent. It is 1 by default.
2) How savegame compatibility is handled?
Saved arrays are stored in sfallgv.sav file (in savegame) in new (more flexible) format, just after the old arrays. So basically, when you load older savegame, sfall will load arrays from old format and save them to new format on next game save. If you load savegame made with sfall 3.4 using sfall 3.3 (for example), game shouldn't crash, but all arrays will be lost.
3) Previously you had to specify size in bytes for array elements. This parameter is now ignored and you can store strings of arbitrary length in arrays.
+1 -1
View File
@@ -90,7 +90,7 @@ old:
x := 5;
> Multiple variable decleration: Multiple variables can be declared on one line, seperated by commas. This is an alterative to the ugly begin/end block, or the bulky single variable per line style.
> Multiple variable declaration: Multiple variables can be declared on one line, seperated by commas. This is an alterative to the ugly begin/end block, or the bulky single variable per line style.
new:
variable a, b, c;
File diff suppressed because it is too large Load Diff
+5
View File
@@ -72,6 +72,8 @@
#define HOOK_ADJUSTPOISON (44)
#define HOOK_ADJUSTRADS (45)
#define HOOK_ROLLCHECK (46)
#define HOOK_BESTWEAPON (47)
#define HOOK_CANUSEWEAPON (48)
//Valid arguments to list_begin
#define LIST_CRITTERS (0)
@@ -288,6 +290,8 @@
// clears the keyboard input buffer, use it in the HOOK_KEYPRESS hook to clear keyboard events before calling functions that are waiting for keyboard input
#define clear_keyboard_buffer metarule3(201, 0, 0, 0)
// checks if the specified PID number exists in the list of registered protos
#define check_pid(pid) (get_proto_data(pid, 0) != -1)
/* sfall_funcX macros */
#define add_extra_msg_file(name) sfall_func1("add_extra_msg_file", name)
@@ -377,6 +381,7 @@
#define set_map_enter_position(tile, elev, rot) sfall_func3("set_map_enter_position", tile, elev, rot)
#define set_object_data(obj, offset, value) sfall_func3("set_object_data", obj, offset, value)
#define set_outline(obj, color) sfall_func2("set_outline", obj, color)
#define set_quest_failure_value(gvar, threshold) sfall_func2("set_quest_failure_value", gvar, threshold)
#define set_rest_heal_time(time) sfall_func1("set_rest_heal_time", time)
#define set_rest_mode(mode) sfall_func1("set_rest_mode", mode)
#define set_terrain_name(x, y, name) sfall_func3("set_terrain_name", x, y, name)
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff

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