From 8886b95ff7438b889a1b3d949b014fc247cf53a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0imek?= Date: Fri, 26 Jul 2024 12:50:30 +0200 Subject: [PATCH] tile_num_in_direction can be called with either integer or pointer as the origin argument. Fixes #409 Both variants are used in the ecdogmet.ssl script: ``` tile_num_in_direction(self_tile, Random(0, 5), 1); tile_num_in_direction(dude_obj, Random(0, 5), Random(5, 10)); ``` --- src/interpreter_extra.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/interpreter_extra.cc b/src/interpreter_extra.cc index 124583b4..5c92326c 100644 --- a/src/interpreter_extra.cc +++ b/src/interpreter_extra.cc @@ -468,7 +468,7 @@ static void opGiveExpPoints(Program* program) int xp = programStackPopInteger(program); if (pcAddExperience(xp) != 0) { - scriptError("\nScript Error: %s: op_give_exp_points: stat_pc_set failed"); + scriptError("\nScript Error: %s: op_give_exp_points: stat_pc_set failed", program->name); } } @@ -1537,9 +1537,19 @@ static void opGetTileInDirection(Program* program) { int distance = programStackPopInteger(program); int rotation = programStackPopInteger(program); - int origin = programStackPopInteger(program); + ProgramValue originValue = programStackPopValue(program); int tile = -1; + int origin = -1; + + if (originValue.isInt()) { + origin = originValue.integerValue; + } else if (originValue.isPointer()) { + Object* object = static_cast(originValue.pointerValue); + origin = object->tile; + } else { + scriptError("Script Error: %s: invalid arg %d to tile_num_in_direction", program->name, 0); + } if (origin != -1) { if (rotation < ROTATION_COUNT) {