Skip to content

Commit

Permalink
Traps: use config for all settings, nothing is hard coded now
Browse files Browse the repository at this point in the history
  • Loading branch information
phobos2077 committed Jul 5, 2023
1 parent 1dacdfc commit 3115b1b
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 267 deletions.
59 changes: 50 additions & 9 deletions root/data/config/traps.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,76 @@ other=0
613=0


; TODO: this is not implemented yet
[Trap_0] ; Spike
name_msg=10
; Values for grenades default to proto data
; Values for explosives default to explosives data
[Armament_25] ; Frag Grenade
skill_mod=-10
;radius=2
;dmg_type=6
;dmg_min=30
;dmg_max=60

[Armament_26] ; Plasma Grenade
skill_mod=-30

[Armament_27] ; Pulse Grenade
skill_mod=-30

[Armament_51] ; Dynamite
skill_mod=-50
radius=3

[Armament_85] ; Plastic explosive
skill_mod=-50
radius=3

[Armament_159] ; Molotov
skill_mod=-20
dmg_type=2 ; Fire
sound_sfx=WHO1XXX2

[Armament_613] ; Home-made grenade
skill_mod=0


[Trap_1] ; Spike
item_pid=618
trap_pid=2335 ; 33556767
radius=1
stop=1
dmg_min=8
dmg_max=16
skill_mod=-10

[Trap_1] ; Bear
name_msg=13
[Trap_2] ; Bear
item_pid=645
trap_pid=2336
radius=0
stop=3
dmg_min=12
dmg_max=24
skill_mod=-40

[Trap_2] ; Mine
name_msg=11
[Trap_3] ; Mine
item_pid=616
trap_pid=2337
radius=0
armaments=25,26,27,51,85,159,613
skill_mod=-10

[Trap_3] ; Sensor
name_msg=12
[Trap_4] ; Sensor
item_pid=619
trap_pid=2339
radius=1
armaments=25,26,27,51,85,159,613
skill_mod=-30

[Trap_5] ; RESERVED
;name_msg=10
;item_pid=618
trap_pid=2338

[Trap_6] ; RESERVED
;name_msg=10
;item_pid=618
trap_pid=2340
Binary file modified root/data/scripts/gl_pbs_traps.int
Binary file not shown.
Binary file modified root/data/scripts/test2.int
Binary file not shown.
8 changes: 4 additions & 4 deletions root/data/text/english/dialog/test2.msg
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 0 - 5000 reserved for traps
# trap types
{10}{}{spike trap}
{11}{}{pressure plate trap}
{12}{}{proximity sensor trap}
{13}{}{bear trap}
{11}{}{spike trap}
{12}{}{bear trap}
{13}{}{mine trap}
{14}{}{proximity sensor trap}

# traps look at
{50}{}{You see a %s.}
Expand Down
8 changes: 4 additions & 4 deletions root/data/text/russian/dialog/test2.msg
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# phobos2077 crafting. Translated by Pyran. Corrected and added by Drobovik.
# 0 - 5000 reserved for traps
# trap types
{10}{}{������� � ������}
{11}{}{����-�������}
{12}{}{������� � ��������� �����������}
{13}{}{�������-������}
{11}{}{������� � ������}
{12}{}{�������-������}
{13}{}{����-�������}
{14}{}{������� � ��������� �����������}

# traps look at
{50}{}{�� ������ %s.}
Expand Down
62 changes: 0 additions & 62 deletions root/mods/ecco/traps.ini

This file was deleted.

143 changes: 42 additions & 101 deletions scripts_src/_pbs_headers/traps.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef PBS_TRAPS_H
#define PBS_TRAPS_H


#include "../sfall/sfall.h"
#include "../sfall/lib.arrays.h"
#include "../sfall/lib.strings.h"
Expand All @@ -23,27 +22,8 @@

#define SCRIPT_PBS_TRAPS SCRIPT_TEST2

#define is_explosive_pid(pid) (pid == PID_FRAG_GRENADE or pid == PID_PBS_HOMEMADE_GRENADE \
or pid == PID_DYNAMITE or pid == PID_PLASTIC_EXPLOSIVES \
or pid == PID_PULSE_GRENADE or pid == PID_PLASMA_GRENADE or pid == PID_MOLOTOV_COCKTAIL)

#define TRAPINFO_SIZE (10)

#define TRAPINFO_OFS_INDEX (0) // trap record start index in SGVAR_TRAPS_BY_DUDE array
#define TRAPINFO_OFS_TILE (1) // trap tile
#define TRAPINFO_OFS_ELEV (2) // elevation
#define TRAPINFO_OFS_MAP (3) // map index
#define TRAPINFO_OFS_TYPE (4) // trap type
#define TRAPINFO_OFS_ARMPID (5) // trap armament item PID
#define TRAPINFO_OFS_STATE (6) // see below
#define TRAPINFO_OFS_OBJPID (7) // pid of visual object (eg. floor plate)
#define TRAPINFO_OFS_CHARGES (8) // number of uses left
#define TRAPINFO_OFS_FLAGS (9) // flags, see below
// reserved up to (9)

#define TRAP_STATE_ACTIVE (0)
#define TRAP_STATE_SETOFF (1)
#define TRAP_STATE_DISARMED (2)
#define TRAP_STATE_DISARMED (0)
#define TRAP_STATE_ACTIVE (1)

#define TRAP_FRAME_DEFAULT (0)
#define TRAP_FRAME_ACTIVE (1)
Expand All @@ -53,48 +33,6 @@
#define TRAP_TYPE_SENSOR (2)
#define TRAP_TYPE_BEAR (3)

//#define TRAP_OBJECT_PID PID_METAL_FLOOR_TRAP_VISIBLE
//#define TRAP_OBJECT_PID_DISARMED PID_METAL_FLOOR_TRAP_DISARMED

#define is_trap_kit_pid(pid) (pid == PID_PBS_TRAP_KIT_MINE or pid == PID_PBS_TRAP_KIT_SPIKE or pid == PID_PBS_TRAP_KIT_SENSOR or pid == PID_PBS_TRAP_KIT_BEAR)

pure procedure tile_contains_any_trap(variable tile, variable elev) begin
variable pids, pid;
pids := [PID_METAL_FLOOR_TRAP_VISIBLE, PID_METAL_FLOOR_TRAP_DISARMED, PID_METAL_FLOOR_TRAP_DEPRESSED,
PID_CAVE_FLOOR_TRAP_VISIBLE, PID_CAVE_FLOOR_TRAP_DISARMED, PID_CAVE_FLOOR_TRAP_DEPRESSED,
PID_PBS_SPIKE_TRAP, PID_PBS_MINE_TRAP, PID_PBS_SENSOR_MINE, PID_PBS_BEAR_TRAP,
PID_PBS_TRAP_RESERVED_4, PID_PBS_TRAP_RESERVED_6];
foreach (pid in pids) begin
if (tile_contains_obj_pid(tile, elev, pid)) then return true;
end
return false;
end

/*#define tile_contains_any_trap(tile, elev) (tile_contains_obj_pid(tile, elev, PID_METAL_FLOOR_TRAP_VISIBLE) \
or tile_contains_obj_pid(tile, elev, PID_METAL_FLOOR_TRAP_DISARMED) \
or tile_contains_obj_pid(tile, elev, PID_METAL_FLOOR_TRAP_DEPRESSED) \
or tile_contains_obj_pid(tile, elev, PID_CAVE_FLOOR_TRAP_VISIBLE) \
or tile_contains_obj_pid(tile, elev, PID_CAVE_FLOOR_TRAP_DISARMED) \
or tile_contains_obj_pid(tile, elev, PID_CAVE_FLOOR_TRAP_DEPRESSED))*/

#define trap_index(x,y) get_array(x, y + TRAPINFO_OFS_INDEX)
#define trap_tile(x,y) get_array(x, y + TRAPINFO_OFS_TILE)
#define trap_elev(x,y) get_array(x, y + TRAPINFO_OFS_ELEV)
#define trap_map(x,y) get_array(x, y + TRAPINFO_OFS_MAP)
#define trap_type(x,y) get_array(x, y + TRAPINFO_OFS_TYPE)
#define trap_armpid(x,y) get_array(x, y + TRAPINFO_OFS_ARMPID)
#define trap_state(x,y) get_array(x, y + TRAPINFO_OFS_STATE)
#define trap_objpid(x,y) get_array(x, y + TRAPINFO_OFS_OBJPID)
#define trap_charges(x,y) get_array(x, y + TRAPINFO_OFS_CHARGES)
#define trap_flags(x,y) get_array(x, y + TRAPINFO_OFS_FLAGS)
#define trap_object(x,y) tile_contains_pid_obj(trap_tile(x,y), trap_elev(x,y), trap_objpid(x,y))

// TODO: use config?
#define is_trap_customizable_type(type) (type == TRAP_TYPE_MINE or type == TRAP_TYPE_SENSOR)

// TODO: 100% or config?
#define TRAP_SENSOR_CHANCE (70)

// custom timed_event's
#define TRAP_EVENT_INIT (0)
#define TRAP_EVENT_DESTROY (1)
Expand All @@ -111,24 +49,11 @@ end

#define make_critter_angry(obj) add_array_set(load_create_array(ARR_ANGRY_TEAMS, 0), obj_team(obj))

// TODO: better solution? arrays? based on config data?
#define trapkit_pid_by_trap_type(type) ((type == TRAP_TYPE_SPIKE)*PID_PBS_TRAP_KIT_SPIKE \
+(type == TRAP_TYPE_MINE)*PID_PBS_TRAP_KIT_MINE \
+(type == TRAP_TYPE_SENSOR)*PID_PBS_TRAP_KIT_SENSOR \
+(type == TRAP_TYPE_BEAR)*PID_PBS_TRAP_KIT_BEAR)

#define trap_type_by_trapkit_pid(pid) ((pid == PID_PBS_TRAP_KIT_SPIKE)*TRAP_TYPE_SPIKE \
+(pid == PID_PBS_TRAP_KIT_MINE)*TRAP_TYPE_MINE \
+(pid == PID_PBS_TRAP_KIT_SENSOR)*TRAP_TYPE_SENSOR \
+(pid == PID_PBS_TRAP_KIT_BEAR)*TRAP_TYPE_BEAR)

#define trapkit_pid_by_trap_type(type) (pbs_trap_config.types[type].item_pid)
#define trap_type_by_trapkit_pid(pid) (pbs_trap_config.item_to_type[pid])
#define is_trap_kit_pid(pid) (trap_type_by_trapkit_pid(pid) != 0)

procedure create_trap_object(variable trapType, variable tile, variable elev, variable charges);

procedure react_hostile_action;

procedure trap_setoff_explosion(variable trapObj, variable mainTarget, variable dmgMin, variable dmgMax, variable radius, variable dmgType, variable isCritical, variable pid, variable sfx);
procedure trap_setoff_melee(variable critter, variable dmgMin, variable dmgMax, variable dmgType, variable isCritical, variable stopTurns);

#define send_trap_init_event(obj, type, charges) add_timer_event(obj, 0, TRAP_EVENT_INIT + 0x100 * (type bwand 0xFF) + 0x10000 * (charges bwand 0xFF))

Expand All @@ -146,36 +71,52 @@ end
#define _EXPORT_VAR(name, value) import variable name;
#endif

_EXPORT_VAR(pbs_trap_config, 0)
_EXPORT_VAR(pbs_trap_victims, 0) // maps trap object to it's victim, used to "send" object from spatial script
_EXPORT_VAR(pbs_ini_trap_is_crime, 1)
_EXPORT_VAR(pbs_ini_trap_reveals_dude, 1)
_EXPORT_VAR(pbs_ini_trap_friendfoe, 1)
_EXPORT_VAR(pbs_trap_last_target, 0)
_EXPORT_VAR(pbs_trap_last_target_dead, 0)
_EXPORT_VAR(pbs_trap_hold_critters, 0)

#undef _EXPORT_VAR


procedure create_trap_object(variable trapType, variable tile, variable elev, variable charges);
procedure react_hostile_action;
procedure trap_setoff_explosion(variable trapObj, variable mainTarget, variable dmgMin, variable dmgMax, variable radius, variable dmgType, variable isCritical, variable pid, variable sfx);
procedure trap_setoff_melee(variable critter, variable dmgMin, variable dmgMax, variable dmgType, variable isCritical, variable stopTurns);

variable trap_object_pid_set;

pure procedure tile_contains_any_trap(variable tile, variable elev) begin
if not trap_object_pid_set then begin
trap_object_pid_set := array_fixed(array_to_set(array_keys(pbs_trap_config.pid_to_type)));
call array_append(trap_object_pid_set, array_to_set([
PID_METAL_FLOOR_TRAP_VISIBLE, PID_METAL_FLOOR_TRAP_DISARMED, PID_METAL_FLOOR_TRAP_DEPRESSED,
PID_CAVE_FLOOR_TRAP_VISIBLE, PID_CAVE_FLOOR_TRAP_DISARMED, PID_CAVE_FLOOR_TRAP_DEPRESSED]));
debug_log("trap_object_pid_set: "+debug_array_str(trap_object_pid_set));
end
variable obj, objs := tile_get_objs(tile, elev);
foreach (obj in objs) begin
if (trap_object_pid_set[obj_pid(obj)]) then return true;
end
return false;
end

pure procedure is_suitable_armament(variable pid, variable type) begin
variable arms := pbs_trap_config.types[type].armaments;
debug_log("arms="+debug_array_str(arms));
return is_in_array(pid, arms) if arms else false;
end


/**
Create new trap object with correct PID, and init properly. Used when creating and transforming trap.
@param type - type of trap
*/
// TODO: remove state
procedure create_trap_object(variable type, variable tile, variable elev, variable charges) begin
variable begin
newPid := 0;
newObj;
end
// TODO: use one PID and just change FID instead?
if (type == TRAP_TYPE_SPIKE) then begin
newPid := PID_PBS_SPIKE_TRAP;
end else if (type == TRAP_TYPE_MINE) then begin
newPid := PID_PBS_MINE_TRAP;
end else if (type == TRAP_TYPE_SENSOR) then begin
newPid := PID_PBS_SENSOR_MINE;
end else if (type == TRAP_TYPE_BEAR) then begin
newPid := PID_PBS_BEAR_TRAP;
end else begin
variable newPid := 0, newObj;
newPid := 0x02000000 + pbs_trap_config.types[type].trap_pid;
if (newPid == 0) then begin
debug_err("Invalid trap type: "+type);
return 0;
end
Expand Down Expand Up @@ -293,7 +234,7 @@ procedure trap_damage_critter(variable critter, variable dmgMin, variable dmgMax
pbs_trap_hold_critters[critter] := array_fixed([stop, tile_num(critter)]);
debug_log("Stopping critter: "+debug_array_str(pbs_trap_hold_critters));
end
if (pbs_ini_trap_reveals_dude) then begin
if (pbs_trap_config.reveal_dude) then begin
debug_log("Making angry!");
call make_critter_angry(critter);
end
Expand Down Expand Up @@ -363,7 +304,7 @@ procedure trap_setoff_melee(variable critter, variable dmgMin, variable dmgMax,
end
end

procedure get_suitable_armament_in_inventory(variable critter) begin
procedure get_suitable_armament_in_inventory(variable critter, variable trapType) begin
variable item, lastPid, list;
lastPid := get_sfall_global_int(SGVAR_TRAPS_LAST_ARMAMENT);
// first search for last used item PID
Expand All @@ -374,7 +315,7 @@ procedure get_suitable_armament_in_inventory(variable critter) begin
// if none, then search for any suitable armament
list := inven_as_array(critter);
foreach item in list begin
if is_explosive_pid(obj_pid(item)) then return item;
if is_suitable_armament(obj_pid(item), trapType) then return item;
end
return 0;
end
Expand Down
Loading

0 comments on commit 3115b1b

Please sign in to comment.