Fixed the functions of the engine op_obj_can_see_obj_/op_obj_can_hear_obj_ (#189)

Added one additional argument for the hook HOOK_WITHINPERCEPTION.
This commit is contained in:
Mr.Stalin
2018-08-18 23:56:03 +08:00
committed by NovaRain
parent a7c66685b9
commit 032e1d13f3
4 changed files with 134 additions and 14 deletions
@@ -0,0 +1,58 @@
/*
Example engine algorithm.
* The AllowUnsafeScripting option must be enabled.
*/
#include "define_lite.h"
#include "command.h"
#include "sfall.h"
#include "define_extra.h"
#define can_see_(source, target) call_offset_r2(0x412BEC, source, target)
#define obj_dist_(target, source) call_offset_r2(0x48BBD4, target, source)
procedure start;
procedure start begin
if not(init_hook) then begin
variable source := get_sfall_arg,
target := get_sfall_arg,
original := get_sfall_arg,
type := get_sfall_arg, /* new arg */
result := 0,
distance;
if target then begin
distance := get_critter_stat(source, STAT_pe);
if can_see_(source, target) then begin
distance *= 5;
if (get_flags(target) bwand FLAG_TRANSGLASS) then distance /= 2;
end
else if combat_is_initialized then distance *= 2;
if target == dude_obj then begin
if sneak_success then begin
distance /= 4;
if has_skill(target, SKILL_SNEAK) > 120 then distance -= 1;
end
else if dude_is_sneaking then distance := distance * 2 / 3;
end
if obj_dist_(target, source) <= distance then result := 1;
// example
if (result) then begin
display_msg("hs_withinperception: " + obj_name(source) + " does he see > " + obj_name(target) + " [original: " + original + " script: " + result + "]");
end else begin
display_msg("hs_withinperception: " + obj_name(source) + " he does not see > " + obj_name(target) + " [original: " + original + " script: " + result + "]");
end
end
//set_sfall_return(result);
end
end