Skip to content

Commit

Permalink
CONCEAL_MAP_RECT script command still works when out of bounds (#3700)
Browse files Browse the repository at this point in the history
Co-authored-by: walter253 <[email protected]>
Co-authored-by: Loobinex <[email protected]>
  • Loading branch information
3 people authored Nov 20, 2024
1 parent 238f2b2 commit 339dc5d
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions src/lvl_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,7 @@ static void conceal_map_rect_check(const struct ScriptLine *scline)
{
conceal_all = 0;
}
else
if ((strcmp(scline->tp[5], "ALL") == 0) || (strcmp(scline->tp[5], "1") == 0))
else if ((strcmp(scline->tp[5], "ALL") == 0) || (strcmp(scline->tp[5], "1") == 0))
{
conceal_all = 1;
}
Expand All @@ -887,14 +886,52 @@ static void conceal_map_rect_check(const struct ScriptLine *scline)
MapSubtlCoord start_y = y - (height / 2);
MapSubtlCoord end_y = y + (height / 2) + (height & 1);

if ((start_x < 0) || (end_x > gameadd.map_subtiles_x) || (start_y < 0) || (end_y > gameadd.map_subtiles_y))
if (start_x < 0)
{
SCRPTWRNLOG("Starting X coordinate '%ld' (from %ld-%ld/2) is out of range, fixing it to '0'.", start_x,x,width);
start_x = 0;
}
else if (start_x > gameadd.map_subtiles_x)
{
SCRPTWRNLOG("Starting X coordinate '%ld' (from %ld-%ld/2) is out of range, fixing it to '%ld'.", start_x, x, width, gameadd.map_subtiles_x);
start_x = gameadd.map_subtiles_x;
}
if (end_x < 0)
{
SCRPTERRLOG("Conceal coordinates out of range, trying to conceal from (%ld,%ld) to (%ld,%ld) on map that's %ldx%ld subtiles",
start_x, start_y, end_x, end_y, gameadd.map_subtiles_x, gameadd.map_subtiles_y);
SCRPTWRNLOG("Ending X coordinate '%ld' (from %ld+%ld/2) is out of range, fixing it to '0'.", end_x, x, width);
end_x = 0;
}
else if (end_x > gameadd.map_subtiles_x)
{
SCRPTWRNLOG("Ending X coordinate '%ld' (from %ld+%ld/2) is out of range, fixing it to '%ld'.", end_x, x, width, gameadd.map_subtiles_x);
end_x = gameadd.map_subtiles_x;
}
if (start_y < 0)
{
SCRPTWRNLOG("Starting Y coordinate '%ld' (from %ld-%ld/2) is out of range, fixing it to '0'.", start_y, y, height);
start_y = 0;
}
else if (start_y > gameadd.map_subtiles_y)
{
SCRPTWRNLOG("Starting Y coordinate '%ld' (from %ld-%ld/2) is out of range, fixing it to '%ld'.", start_y, y, height, gameadd.map_subtiles_y);
start_y = gameadd.map_subtiles_y;
}
if (end_y < 0)
{
SCRPTWRNLOG("Ending Y coordinate '%ld' (from %ld+%ld/2) is out of range, fixing it to '0'.", end_y, y, height);
end_y = 0;
}
else if (end_y > gameadd.map_subtiles_y)
{
SCRPTWRNLOG("Ending Y coordinate '%ld' (from %ld+%ld/2) is out of range, fixing it to '%ld'.", end_y, y, height, gameadd.map_subtiles_y);
end_y = gameadd.map_subtiles_y;
}
if ((x < 0) || (x > gameadd.map_subtiles_x) || (y < 0) || (y > gameadd.map_subtiles_y))
{
SCRPTERRLOG("Conceal coordinates out of range, trying to set conceal center point to (%ld,%ld) on map that's %ldx%ld subtiles", x, y, gameadd.map_subtiles_x, gameadd.map_subtiles_y);
DEALLOCATE_SCRIPT_VALUE
return;
}

value->plyr_range = scline->np[0];
value->shorts[1] = start_x;
value->shorts[2] = end_x;
Expand All @@ -912,7 +949,6 @@ static void conceal_map_rect_process(struct ScriptContext *context)
MapSubtlCoord start_y = context->value->shorts[3];
MapSubtlCoord end_y = context->value->shorts[4];
TbBool conceal_all = context->value->shorts[5];

conceal_map_area(context->player_idx, start_x, end_x, start_y, end_y, conceal_all);
}

Expand Down

0 comments on commit 339dc5d

Please sign in to comment.