Skip to content

Commit

Permalink
Merge pull request #140 from BGforgeNet/critical-stat
Browse files Browse the repository at this point in the history
Fix is_critical checks for stats
  • Loading branch information
burner1024 authored Mar 31, 2024
2 parents 4c785a3 + 26823b9 commit 8b14148
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 29 deletions.
8 changes: 4 additions & 4 deletions scripts_src/generic/ziwoddor.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ procedure Look_Traps_And_Locks begin
variable Traps_Check;
variable Locks_Check;

Perception_Check:=do_check(dude_obj,STAT_pe,0);
Perception_Check = roll_vs_stat(dude_obj, STAT_pe, 0);
Traps_Check:=roll_vs_skill(dude_obj,SKILL_TRAPS,0);
Locks_Check:=roll_vs_skill(dude_obj,SKILL_LOCKPICK,0);

Expand Down Expand Up @@ -945,7 +945,7 @@ procedure Look_Traps begin
variable Perception_Check;
variable Traps_Check;

Perception_Check:=do_check(dude_obj,STAT_pe,0);
Perception_Check = roll_vs_stat(dude_obj, STAT_pe, 0);
Traps_Check:=roll_vs_skill(dude_obj,SKILL_TRAPS,0);

if (is_success(Perception_Check)) then begin
Expand Down Expand Up @@ -1042,7 +1042,7 @@ procedure Look_Locks begin
variable Perception_Check;
variable Locks_Check;

Perception_Check:=do_check(dude_obj,STAT_pe,0);
Perception_Check = roll_vs_stat(dude_obj, STAT_pe, 0);
Locks_Check:=roll_vs_skill(dude_obj,SKILL_LOCKPICK,0);

if (is_success(Perception_Check)) then begin
Expand Down Expand Up @@ -1536,7 +1536,7 @@ procedure Damage_Critter begin
set_local_var(LVAR_Trapped, STATE_INACTIVE);
end

// standard critical, used for stat checks - they can't crit on their own
// Unbiased critical, used for prying with Crowbar.
procedure roll_critical begin
variable rnd = random(1,20);
if rnd == 20 then return true;
Expand Down
27 changes: 27 additions & 0 deletions scripts_src/headers/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,33 @@ variable step_tile;
#define skill_success(x,y,z) (is_success(roll_vs_skill(x,y,z)))
#define stat_success(x,y,z) (is_success(do_check(x,y,z)))

/**
* Like `roll_vs_skill`, but for stat roll checks.
* Because `do_check` can't generate criticals.
* Returns one of the ROLL_* constants, can be used in `is_critical`.
* Average luck of 5 provides DnD-like 1/20 chance to upgrade success to critical.
* For failures, engine doesn't use mods, we follow suit.
* Maybe Jinxed should work here too.
* @arg {ObjPtr} who Critter
* @arg {int} stat STAT_*
* @arg {int} mod Difficulty mod
* @ret {int}
*/
procedure roll_vs_stat(variable who, variable stat, variable mod) begin
variable rnd = random(1,100);
variable stat_check = do_check(who, stat, mod);
// success
if stat_check then begin
// critical
if (rnd + (get_critter_stat(who, STAT_lu) - 5)) > 95 then return ROLL_CRITICAL_SUCCESS;
else return ROLL_SUCCESS;
end else begin // failure
// critical
if rnd > 95 then return ROLL_CRITICAL_FAILURE;
end
return ROLL_FAILURE;
end

#define self_can_see_dude obj_can_see_obj(self_obj,dude_obj)
#define self_can_hear_dude obj_can_hear_obj(self_obj,dude_obj)
#define self_distance_from_dude tile_distance(self_tile, dude_tile)
Expand Down
26 changes: 10 additions & 16 deletions scripts_src/headers/doors_containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,15 +603,13 @@ lockpick skill and perception to notice the lock.
#ifndef custom_Look_Locks
procedure Look_Locks begin
variable Perception_Check;
variable perception_critical;
variable Locks_Check;

Perception_Check:=do_check(dude_obj,STAT_pe,0);
perception_critical = roll_critical();
Perception_Check = roll_vs_stat(dude_obj, STAT_pe, 0);
Locks_Check:=roll_vs_skill(dude_obj,SKILL_LOCKPICK,0);

if (is_success(Perception_Check)) then begin
if perception_critical then begin
if is_critical(Perception_Check) then begin
if (is_success(Locks_Check)) then begin
if (is_critical(Locks_Check)) then begin
display_msg(my_mstr(114));
Expand Down Expand Up @@ -652,7 +650,7 @@ lockpick skill and perception to notice the lock.
end // Regular Success (Stat_pe)
end

else if perception_critical then begin
else if is_critical(Perception_Check) then begin
if (is_success(Locks_Check)) then begin
if (is_critical(Locks_Check)) then begin
display_msg(my_mstr(146));
Expand Down Expand Up @@ -701,15 +699,13 @@ traps skill and perception to notice the trap.
#ifndef custom_Look_Traps
procedure Look_Traps begin
variable Perception_Check;
variable perception_critical;
variable Traps_Check;

Perception_Check:=do_check(dude_obj,STAT_pe,0);
perception_critical = roll_critical();
Perception_Check = roll_vs_stat(dude_obj, STAT_pe, 0);
Traps_Check:=roll_vs_skill(dude_obj,SKILL_TRAPS,0);

if (is_success(Perception_Check)) then begin
if perception_critical then begin
if is_critical(Perception_Check) then begin
if (is_success(Traps_Check)) then begin
if (is_critical(Traps_Check)) then begin
display_msg(my_mstr(104));
Expand Down Expand Up @@ -750,7 +746,7 @@ traps skill and perception to notice the trap.
end // Regular Success (Stat_pe)
end

else if perception_critical then begin
else if is_critical(Perception_Check) then begin
if (is_success(Traps_Check)) then begin
if (is_critical(Traps_Check)) then begin
display_msg(my_mstr(136));
Expand Down Expand Up @@ -800,12 +796,10 @@ on your lockpick and traps skills and perception to notice things.
#ifndef custom_Look_Traps_And_Locks
procedure Look_Traps_And_Locks begin
variable Perception_Check;
variable perception_critical;
variable Traps_Check;
variable Locks_Check;

Perception_Check:=do_check(dude_obj,STAT_pe,0);
perception_critical = roll_critical();
Perception_Check = roll_vs_stat(dude_obj, STAT_pe, 0);
Traps_Check:=roll_vs_skill(dude_obj,SKILL_TRAPS,0);
Locks_Check:=roll_vs_skill(dude_obj,SKILL_LOCKPICK,0);

Expand All @@ -815,7 +809,7 @@ on your lockpick and traps skills and perception to notice things.

/* Critical Success of a Perception Check (Start)*/

if perception_critical then begin
if is_critical(Perception_Check) then begin

if (is_success(Traps_Check)) then begin
set_local_var(LVAR_Found_Trap,1); // player has found the trap
Expand Down Expand Up @@ -1019,7 +1013,7 @@ on your lockpick and traps skills and perception to notice things.

/* Critical Failure of a Perception Check (Start)*/

else if perception_critical then begin
else if is_critical(Perception_Check) then begin
if (is_success(Traps_Check)) then begin
set_local_var(LVAR_Found_Trap,1); // player has found the trap

Expand Down Expand Up @@ -1299,7 +1293,7 @@ and Repair can be added to this list to give more information about the door.
end
#endif

// standard critical, used for stat checks - they can't crit on their own
// Unbiased critical, used for prying with Crowbar.
procedure roll_critical begin
variable rnd = random(1,20);
if rnd == 20 then return true;
Expand Down
2 changes: 1 addition & 1 deletion scripts_src/klamath/kscorveg.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ procedure repair_it begin
end

procedure zamin_it begin
per_check:=do_check(dude_obj, STAT_pe, 0);
per_check = roll_vs_stat(dude_obj, STAT_pe, 0);
if (local_var(LVAR_Part_Given) == 0) then begin //added check by killap
if (is_success(per_check)) then begin
if (is_critical(per_check)) then
Expand Down
2 changes: 1 addition & 1 deletion scripts_src/navarro/cimine.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ procedure spatial_p_proc begin
if (Range_Mod > PERCEPTION_BONUS) then
Range_Mod:= PERCEPTION_BONUS;

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

if (is_success(Detection_Roll)) then begin

Expand Down
2 changes: 1 addition & 1 deletion scripts_src/raiders/iimine.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ procedure spatial_p_proc begin
if (Range_Mod > PERCEPTION_BONUS) then
Range_Mod:= PERCEPTION_BONUS;

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

if (is_success(Detection_Roll)) then begin

Expand Down
2 changes: 1 addition & 1 deletion scripts_src/raiders/iipit.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ procedure spatial_p_proc begin
if (Range_Mod > PERCEPTION_BONUS) then
Range_Mod:= PERCEPTION_BONUS;

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

if (is_success(Detection_Roll)) then begin

Expand Down
2 changes: 1 addition & 1 deletion scripts_src/redding/rtlndmin.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ procedure Trap_Detection begin
if (Range_Mod > PERCEPTION_BONUS) then
Range_Mod:= PERCEPTION_BONUS;

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

if (is_success(Detection_Roll)) then begin

Expand Down
2 changes: 1 addition & 1 deletion scripts_src/sierra/wtlndmin.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ procedure Trap_Detection begin
if (Range_Mod > PERCEPTION_BONUS) then
Range_Mod:= PERCEPTION_BONUS;

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

if (is_success(Detection_Roll)) then begin

Expand Down
2 changes: 1 addition & 1 deletion scripts_src/template/spear_trap.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ procedure spatial_p_proc begin
if (Range_Mod > PERCEPTION_BONUS) then
Range_Mod:= PERCEPTION_BONUS;

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

if (is_success(Detection_Roll)) then begin

Expand Down
2 changes: 1 addition & 1 deletion scripts_src/template/sprtrp0.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ procedure spatial_p_proc begin
if (Range_Mod > PERCEPTION_BONUS) then
Range_Mod:= PERCEPTION_BONUS;

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

if (is_success(Detection_Roll)) then begin

Expand Down
2 changes: 1 addition & 1 deletion scripts_src/template/wtpltrp.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ procedure spatial_p_proc begin
if (Range_Mod > PERCEPTION_BONUS) then
Range_Mod:= PERCEPTION_BONUS;

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

if (is_success(Detection_Roll)) then begin

Expand Down

0 comments on commit 8b14148

Please sign in to comment.