Skip to content

Commit

Permalink
Fixed issues with the car blockers:
Browse files Browse the repository at this point in the history
- when re-entering the same random encounter map right after exiting,
critters can walk "inside" the car due to missing blockers.

- when alternating between two maps multiple times, it's possible to
fail to destroy the car blockers. Adding a blocker destroy sequence to
the car script as a fail-safe.

- tweaked the sequence to remove one superfluous blocker.

- added a fix to remove all leftover blockers, as the two previously
created by car trunk could stack over a dozen on a map.
  • Loading branch information
NovaRain committed Sep 5, 2024
1 parent d381b94 commit 129ae56
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 22 deletions.
17 changes: 17 additions & 0 deletions scripts_src/generic/zsdrvcar.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ end

procedure map_enter_p_proc begin
if (global_var(GVAR_CAR_PLACED_TILE) != self_tile) then begin
// Warning: the following sequence must be identical to the "Dest_Car" macro!
Scenery_Creation_Hex:=self_tile;
Dest_Block_Cycle(1,2,self_elevation)
Dest_Block_Cycle(2,2,self_elevation)
Dest_Block_Cycle(3,2,self_elevation)
Dest_Block_Cycle(4,2,self_elevation)
Dest_Block_Cycle(5,1,self_elevation)
Dest_Block_Cycle(4,1,self_elevation)
Dest_Block_Cycle(5,1,self_elevation)
Dest_Block_Cycle(4,1,self_elevation)
Dest_Block_Cycle(5,3,self_elevation)
Dest_Block_Cycle(0,2,self_elevation)
Dest_Block_Cycle(1,1,self_elevation)
Dest_Block_Cycle(2,1,self_elevation)
Dest_Block_Cycle(1,1,self_elevation)
Dest_Block_Cycle(2,1,self_elevation)

destroy_object(self_obj);
end
end
Expand Down
61 changes: 39 additions & 22 deletions scripts_src/headers/scenepid.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,35 @@ variable Scenery_Creation_Ptr;
end


// This will clear the leftover blocking hexes (usually remain in old saves)
#define Dest_Leftover_Block(Hex_Num,Elevation) if (tile_contains_pid_obj(Hex_Num, Elevation, PID_DRIVABLE_CAR) == 0) then begin \
Scenery_Creation_Hex:=tile_num_in_direction(Hex_Num,5,1); \
Scenery_Creation_Ptr:=tile_contains_pid_obj(Scenery_Creation_Hex,Elevation,PID_BLOCKING_HEX); \
while (Scenery_Creation_Ptr != 0) do begin \
destroy_object(Scenery_Creation_Ptr); \
Scenery_Creation_Ptr:=tile_contains_pid_obj(Scenery_Creation_Hex,Elevation,PID_BLOCKING_HEX); \
end \
Scenery_Creation_Hex:=tile_num_in_direction(Hex_Num,5,2); \
Scenery_Creation_Ptr:=tile_contains_pid_obj(Scenery_Creation_Hex,Elevation,PID_BLOCKING_HEX); \
while (Scenery_Creation_Ptr != 0) do begin \
destroy_object(Scenery_Creation_Ptr); \
Scenery_Creation_Ptr:=tile_contains_pid_obj(Scenery_Creation_Hex,Elevation,PID_BLOCKING_HEX); \
end \
end \
Scenery_Creation_Hex:=tile_num_in_direction(tile_num_in_direction(Hex_Num,4,4),3,1); \
Scenery_Creation_Ptr:=tile_contains_pid_obj(Scenery_Creation_Hex,Elevation,PID_BLOCKING_HEX); \
if (Scenery_Creation_Ptr != 0) then begin \
destroy_object(Scenery_Creation_Ptr); \
end


// This will make the car that the player drives along the world map
#define Create_Car(Hex_Num,Elevation) ndebug("Place_Car(" + Hex_Num + "," + Elevation + ")"); \
ndebug(" GVAR_CAR_PLACED_TILE == " + global_var(GVAR_CAR_PLACED_TILE)); \
#define Create_Car(Hex_Num,Elevation) ndebug("Place_Car(" + Hex_Num + "," + Elevation + ")"); \
ndebug(" GVAR_CAR_PLACED_TILE == " + global_var(GVAR_CAR_PLACED_TILE)); \
ndebug(" Car_At_Loc == " + (tile_contains_pid_obj(Hex_Num, Elevation, PID_DRIVABLE_CAR) != 0)); \
if ((global_var(GVAR_CAR_PLACED_TILE) <= 0) or (Hex_Num == global_var(GVAR_CAR_PLACED_TILE))) then begin \
set_global_var(GVAR_CAR_PLACED_TILE, Hex_Num); \
if (not (tile_contains_pid_obj(Hex_Num, Elevation, PID_DRIVABLE_CAR) != 0)) then begin \
set_global_var(GVAR_CAR_PLACED_TILE, Hex_Num); \
if (tile_contains_pid_obj(Hex_Num, Elevation, PID_DRIVABLE_CAR) == 0) then begin \
Scenery_Creation:=create_object_sid(PID_DRIVABLE_CAR,Hex_Num,Elevation, SCRIPT_ZSDRVCAR); \
Scenery_Creation_Hex:=Hex_Num; \
Blocking_Cycle(1,2,Elevation) \
Expand All @@ -291,35 +313,32 @@ variable Scenery_Creation_Ptr;
Blocking_Cycle(4,1,Elevation) \
Blocking_Cycle(5,1,Elevation) \
Blocking_Cycle(4,1,Elevation) \
Blocking_Cycle(5,1,Elevation) \
Blocking_Cycle(4,1,Elevation) \
Blocking_Cycle(0,1,Elevation) \
Blocking_Cycle(5,1,Elevation) \
Blocking_Cycle(5,3,Elevation) \
Blocking_Cycle(0,2,Elevation) \
Blocking_Cycle(1,1,Elevation) \
Blocking_Cycle(2,1,Elevation) \
Blocking_Cycle(1,1,Elevation) \
Blocking_Cycle(2,1,Elevation) \
end \
end

#define Create_Trunk(Hex_Num,Elevation) if (not (tile_contains_pid_obj(tile_num_in_direction(tile_num_in_direction(Hex_Num, 5, 2), 4, 1), Elevation, PID_CAR_TRUNK) != 0)) then begin \
ndebug("placing trunk:"); \
#define Create_Trunk(Hex_Num,Elevation) if (tile_contains_pid_obj(tile_num_in_direction(tile_num_in_direction(Hex_Num, 5, 2), 4, 1), Elevation, PID_CAR_TRUNK) == 0) then begin \
ndebug("placing trunk:"); \
Scenery_Creation_Ptr := 0; \
if (Trunk_Ptr != 0) then begin \
Scenery_Creation_Ptr := Trunk_Ptr; \
end else if (dude_has_car == false) then begin \
Scenery_Creation_Ptr := create_object_sid(PID_CAR_TRUNK,0,0,SCRIPT_ZICRTRNK); \
Scenery_Creation_Ptr := create_object_sid(PID_CAR_TRUNK,0,0,SCRIPT_ZICRTRNK); \
end \
if (Scenery_Creation_Ptr != 0) then begin \
Scenery_Creation_Hex := tile_num_in_direction(tile_num_in_direction(Hex_Num, 5, 2), 4, 1); \
move_to(Scenery_Creation_Ptr, Scenery_Creation_Hex, Elevation); \
Blocking_Cycle(1,1,Elevation) \
Blocking_Cycle(2,1,Elevation) \
end else begin \
ndebug("WE HAD AN ERROR WITH THE TRUNK PTR, OHHH FUCK"); \
ndebug("WE HAD AN ERROR WITH THE TRUNK PTR, OHHH FUCK"); \
end \
end

#define Dest_Car(Hex_Num,Elevation) ndebug("Dest_Car_Loc(" + Hex_Num + "," + Elevation + ")"); \
#define Dest_Car(Hex_Num,Elevation) ndebug("Dest_Car_Loc(" + Hex_Num + "," + Elevation + ")"); \
Scenery_Creation_Ptr:=tile_contains_pid_obj(Hex_Num,Elevation,PID_DRIVABLE_CAR); \
if (Scenery_Creation_Ptr != 0) then begin \
destroy_object(Scenery_Creation_Ptr); \
Expand All @@ -332,10 +351,7 @@ variable Scenery_Creation_Ptr;
Dest_Block_Cycle(4,1,Elevation) \
Dest_Block_Cycle(5,1,Elevation) \
Dest_Block_Cycle(4,1,Elevation) \
Dest_Block_Cycle(5,1,Elevation) \
Dest_Block_Cycle(4,1,Elevation) \
Dest_Block_Cycle(0,1,Elevation) \
Dest_Block_Cycle(5,1,Elevation) \
Dest_Block_Cycle(5,3,Elevation) \
Dest_Block_Cycle(0,2,Elevation) \
Dest_Block_Cycle(1,1,Elevation) \
Dest_Block_Cycle(2,1,Elevation) \
Expand All @@ -352,7 +368,7 @@ variable Scenery_Creation_Ptr;
end

#define Check_Create_Car(Hex_Num, Elevation) \
ndebug("Check_Create_Car(" + Hex_Num + "," + Elevation + ")"); \
ndebug("Check_Create_Car(" + Hex_Num + "," + Elevation + ")"); \
if (not is_loading_game) then begin \
if (dude_has_car != false) then begin \
ndebug("car_current_town == " + car_current_town + " / map_get_load_area == " + map_get_load_area); \
Expand All @@ -364,11 +380,12 @@ variable Scenery_Creation_Ptr;
end else if (tile_contains_pid_obj(Hex_Num, Elevation, PID_DRIVABLE_CAR) != 0) then begin \
Dest_Car(Hex_Num, Elevation) \
end \
Dest_Leftover_Block(Hex_Num, Elevation) \
end else begin \
ndebug("the player hasn't gotten the car, can't place it"); \
ndebug("the player hasn't gotten the car, can't place it"); \
end \
end else begin \
ndebug("sorry, can't place the car, the game's loading"); \
ndebug("sorry, can't place the car, the game's loading"); \
end \

// This will make the East-West Caravans
Expand Down

0 comments on commit 129ae56

Please sign in to comment.