Skip to content

Commit

Permalink
Merge pull request #139 from BGforgeNet/traps-refactor
Browse files Browse the repository at this point in the history
Traps refactor
  • Loading branch information
burner1024 authored Mar 31, 2024
2 parents ba53ce5 + 8a4c396 commit 4c785a3
Show file tree
Hide file tree
Showing 38 changed files with 817 additions and 10,542 deletions.
295 changes: 7 additions & 288 deletions scripts_src/arroyo/atsrtrp0.ssl
Original file line number Diff line number Diff line change
@@ -1,292 +1,11 @@
/*
Copyright 1998-2003 Interplay Entertainment Corp. All rights reserved.
*/

/******************************************************************
Filename: SprTrp0.ssl

Purpose: This script is a spatial/scenery script for a spear
trap. Basically, trap will be hidden until the player
makes a successful stat roll (vs. Perception). Once
Found, the trap will become visible and the player
will have to try to disarm it.

Created: December 18, 1997 RWH2

Updated:
******************************************************************/


/* Include Files */
#define SCRIPT_REALNAME "atsrtrp0"
#define SCRIPT_REALNAME "atsrtrp0"
#define NAME SCRIPT_SPRTRP0
#include "../headers/define.h"

#define NAME SCRIPT_SPRTRP0
#define CUR_SCRIPT SCRIPT_ATSRTRP0

#include "../headers/command.h"
#include "../headers/arcaves.h"

#define TRAP_BONUS (0)
#define PERCEPTION_BONUS (0)
#define AGILITY_BONUS (0)
#define DIST_BONUS (2)
#define TRAP_EXP EXP_TRAPS_NORMAL
#define TRAP_TIME (0) // In Seconds
#define MIN_DMG (1)
#define MAX_DMG (4)
#define INITIAL_TILE (28492) // Tile num spear is fired from
#define PROJECTILE_ROF (500)
#define TRAP_MVAR MVAR_Arroyo_Trial_Spear04

procedure start;
procedure spatial_p_proc;
procedure use_skill_on_p_proc;
procedure look_at_p_proc;
procedure description_p_proc;
procedure timed_event_p_proc;

procedure Missile_Fired;
procedure Check_Hit;

#define LVAR_Trap_Found (0)
#define LVAR_Trap_Exploded (1)
#define LVAR_Gave_Exp (2)
#define LVAR_Got_Perception_Roll (3)
#define LVAR_Extended_Look (4)

variable Projectile;
variable Final_Hex;
variable Projectile_Dir;

procedure start begin
end

procedure spatial_p_proc begin
variable Range;
variable Range_Mod;
variable Detection_Roll;
variable Trap;

if (obj_type(source_obj) == 1) then begin

Range:=get_perception(source_obj) + PERCEPTION_BONUS;
Range_Mod:=Range - (tile_distance_objs(self_obj,source_obj)*DIST_BONUS);

if ((tile_distance_objs(self_obj,source_obj) <= Range) and
(local_var(LVAR_Trap_Found) == 0) and (local_var(LVAR_Trap_Exploded) == 0)) then begin

if (Range_Mod > PERCEPTION_BONUS) then
Range_Mod:= PERCEPTION_BONUS;

Detection_Roll:=do_check(source_obj,STAT_pe,Range_Mod);

if (is_success(Detection_Roll)) then begin

if (not(dude_is_running)) then begin
set_local_var(LVAR_Trap_Found,1);
reg_anim_clear(source_obj);
Trap:=create_object_sid(PID_CAVE_FLOOR_TRAP_VISIBLE,self_tile,self_elevation,CUR_SCRIPT);
end

if (is_critical(Detection_Roll)) then begin
if (source_obj == dude_obj) then
display_msg(mstr(100));
else if ((proto_data(obj_pid(source_obj),cr_body_type) == CR_BODY_BIPED) and (obj_can_see_obj(source_obj,dude_obj))) then
display_msg(obj_name(source_obj)+mstr(101));
end

else begin
if (source_obj == dude_obj) then
display_msg(mstr(102));
else if ((proto_data(obj_pid(source_obj),cr_body_type) == CR_BODY_BIPED) and (obj_can_see_obj(source_obj,dude_obj))) then
display_msg(obj_name(source_obj)+mstr(103));
end
end
end

if ((tile_distance_objs(self_obj,source_obj) == 0) and
(local_var(LVAR_Trap_Exploded) == 0) and (map_var(TRAP_MVAR) == 0)) then begin

//game_ui_disable;

ndebug("Set off the Trap!");
Projectile:=create_object(PID_FLYING_SPEAR,INITIAL_TILE,self_elevation);
Face_Critter(source_obj,Projectile);
if (tile_contains_obj_pid(self_tile,self_elevation,PID_CAVE_FLOOR_TRAP_VISIBLE)) then begin
ndebug("Destroying Visible Trap");
destroy_object(tile_contains_pid_obj(self_tile,self_elevation,PID_CAVE_FLOOR_TRAP_VISIBLE));
ndebug("Destroyed Visible Trap");
end
Trap:=create_object(PID_CAVE_FLOOR_TRAP_DEPRESSED,self_tile,self_elevation);

//added by killap
if ((source_obj == dude_obj) and (dude_perk(PERK_light_step_perk)) and (random(0,1) == 1)) then
ndebug("Used Light Step.");
else begin
call Check_Hit;
end
//end added by killap

set_local_var(LVAR_Trap_Exploded,1);
set_map_var(TRAP_MVAR,1);

end
end

end

procedure use_skill_on_p_proc begin
variable Traps_Roll;
variable Trap;

if ((local_var(LVAR_Trap_Exploded) == 0) and (map_var(TRAP_MVAR) == 0) and (action_being_used == SKILL_TRAPS)) then begin
script_overrides;
Traps_Roll:=roll_vs_skill(source_obj,SKILL_TRAPS,TRAP_BONUS);
if (source_obj == dude_obj) then begin
if (is_success(Traps_Roll)) then begin
//Trap:=create_object_sid(PID_CAVE_FLOOR_TRAP_DISARMED,tile_num(self_obj),elevation(self_obj),CUR_SCRIPT);
Trap:=create_object(PID_CAVE_FLOOR_TRAP_DISARMED,self_tile,self_elevation); // edit by killap
set_local_var(LVAR_Trap_Exploded,1);
set_map_var(TRAP_MVAR,1);
display_msg(g_mstr(102));
if (local_var(LVAR_Gave_Exp) == 0) then begin
set_local_var(LVAR_Gave_Exp,1);
give_xp(TRAP_EXP);
end
end
else if (is_critical(Traps_Roll)) then begin
set_local_var(LVAR_Trap_Exploded,1);
set_map_var(TRAP_MVAR,1);
display_msg(g_mstr(104));
//for some reason this code segment causes issues - killap
/*if (tile_contains_obj_pid(self_tile,self_elevation,PID_CAVE_FLOOR_TRAP_VISIBLE)) then begin
ndebug("Destroying Visible Trap");
destroy_object(tile_contains_pid_obj(self_tile,self_elevation,PID_CAVE_FLOOR_TRAP_VISIBLE));
ndebug("Destroyed Visible Trap");
end*/
//Trap:=create_object_sid(PID_CAVE_FLOOR_TRAP_DEPRESSED,tile_num(self_obj),elevation(self_obj),CUR_SCRIPT);
Trap:=create_object(PID_CAVE_FLOOR_TRAP_DEPRESSED,self_tile,self_elevation); // edit by killap
call Check_Hit;
end
else begin
display_msg(g_mstr(103));
end
end
else begin
if (is_success(Traps_Roll)) then begin
//Trap:=create_object_sid(PID_CAVE_FLOOR_TRAP_DISARMED,tile_num(self_obj),elevation(self_obj),CUR_SCRIPT);
Trap:=create_object(PID_CAVE_FLOOR_TRAP_DISARMED,self_tile,self_elevation); // edit by killap
set_map_var(TRAP_MVAR,1);
display_msg(obj_name(source_obj)+g_mstr(105));
if (local_var(LVAR_Gave_Exp) == 0) then begin
set_local_var(LVAR_Gave_Exp,1);
give_xp(TRAP_EXP);
end
end
else if (is_critical(Traps_Roll)) then begin
set_local_var(LVAR_Trap_Exploded,1);
set_map_var(TRAP_MVAR,1);
display_msg(obj_name(source_obj)+g_mstr(107));
//for some reason this code segment causes issues - killap
/*if (tile_contains_obj_pid(self_tile,self_elevation,PID_CAVE_FLOOR_TRAP_VISIBLE)) then begin
ndebug("Destroying Visible Trap");
destroy_object(tile_contains_pid_obj(self_tile,self_elevation,PID_CAVE_FLOOR_TRAP_VISIBLE));
ndebug("Destroyed Visible Trap");
end*/
//Trap:=create_object_sid(PID_CAVE_FLOOR_TRAP_DEPRESSED,tile_num(self_obj),elevation(self_obj),CUR_SCRIPT);
Trap:=create_object(PID_CAVE_FLOOR_TRAP_DEPRESSED,self_tile,self_elevation); // edit by killap
call Check_Hit;
end
else begin
display_msg(obj_name(source_obj)+g_mstr(106));
end
end
end
end

procedure look_at_p_proc begin
script_overrides;
display_msg(mstr(102));
ndebug("Looking At the Trap");
end

procedure description_p_proc begin
variable Perception_Roll;

script_overrides;

if (local_var(LVAR_Got_Perception_Roll) == 0) then begin
set_local_var(LVAR_Got_Perception_Roll,1);
Perception_Roll:=do_check(dude_obj,STAT_pe,PERCEPTION_BONUS);
set_local_var(LVAR_Extended_Look,Perception_Roll);
end

if (is_critical(local_var(LVAR_Extended_Look))) then begin
if (is_success(local_var(LVAR_Extended_Look))) then
display_msg(mstr(100));
else
display_msg(mstr(106));
end
else begin
display_msg(mstr(102));
end
end

procedure timed_event_p_proc begin
if (fixed_param == 1) then begin
destroy_object(Projectile);
Projectile:=create_object(PID_SHARPENED_POLE,Final_Hex,self_elevation);
// Face_Critter(source_obj,Projectile);
// anim(Projectile,ANIMATE_ROTATION,Projectile_Dir);
obj_rotate(Projectile,rotation_to_tile(INITIAL_TILE,Final_Hex));
game_ui_enable;
end
end

procedure Check_Hit begin
variable Agility_Roll;

Agility_Roll:=do_check(source_obj,STAT_ag,AGILITY_BONUS);

if (is_success(Agility_Roll)) then begin
if (source_obj == dude_obj) then
display_msg(mstr(104));
else
display_msg(obj_name(source_obj)+mstr(105));

Final_Hex:=tile_num_in_direction(source_tile,rotation_to_tile(INITIAL_TILE,source_tile),3);
call Missile_Fired;
end
else begin
critter_dmg(source_obj,random(MIN_DMG,MAX_DMG),(DMG_normal_dam BWOR DMG_BYPASS_ARMOR BWOR DMG_NOANIMATE));
Final_Hex:=source_tile;
call Missile_Fired;
end

add_timer_event(self_obj,game_ticks(TRAP_TIME),1);
end

procedure Missile_Fired begin
variable Cur_Tile_Num;
variable Counter:=0;

set_map_var(TRAP_MVAR,1);

play_sfx("sprtrap");
#include "../headers/arcaves.h"
#define INITIAL_TILE 28492
#define TRAP_MVAR MVAR_Arroyo_Trial_Spear04
#define CUR_SCRIPT SCRIPT_ATSRTRP0

while ((Counter < 10) and tile_num(Projectile) != Final_Hex) do begin //edit by killap - not sure what this code is for, but apparently it gets stuck on occasion. Added counter check to exit if it takes too long
if ((Counter % PROJECTILE_ROF) == 0) then begin
Cur_Tile_Num:=tile_num_in_direction(tile_num(Projectile),rotation_to_tile(tile_num(Projectile),Final_Hex),1);
move_to(Projectile,Cur_Tile_Num,self_elevation);
if (Final_Hex == source_tile) then begin
anim(source_obj,ANIM_hit_from_back,ANIMATE_FORWARD);
end
else begin
anim(source_obj,ANIM_dodge_anim,ANIMATE_FORWARD);
end
ndebug("Projectile == "+tile_num(Projectile)+". Final_Hex == "+Final_Hex);
end
Counter+=1;
end
end
#include "../template/spear_trap.ssl"
Loading

0 comments on commit 4c785a3

Please sign in to comment.