Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Fix Descent 1 robots-drop-robots logic
Browse files Browse the repository at this point in the history
Commit 7a183c1 ("Use enum class for robot_id") made an incorrect
change to the Descent 1 call to `robot_create`, causing the game to drop
the wrong type of robot.  Descent 2 was not affected.  This commit both
fixes the incorrect type, which is readily visible, and fixes the
created robot's radius, which Descent 1 has always done wrong and
Descent 2 has always done right.

The second argument to `robot_create` is the ID of the robot to create
(Hulk, Lifter, Spider, etc.).  Prior to 7a183c1, the second
argument was `id`, which came from the caller and was of type `int`.
Both games had a related variable `robot_id` used for lookup in the
`Robot_info` array.  In Descent 1, `robot_id` was set from a cast of
`ObjId[type]`.  In Descent 2, `robot_id` was set from a cast of `id`.

Based on the observation that `Robot_info[robot_id]` was used to read
`.model_num`, I believed that `robot_id` was suitable for use as the ID
of the robot to create.  For Descent 2, this was true.  For Descent 1,
it was not true.  Based on that belief, commit 7a183c1 changed the
second parameter from `id` to `robot_id` (which was also renamed to
`rid`).  For Descent 1, this caused the wrong robot to drop.  For
Descent 2, this was a no-op change.

Reported-by: JeodC <dxx-rebirth#742>
Bisected-by: InfernalCore <dxx-rebirth#742 (comment)>
Fixes: 7a183c1 ("Use enum class for robot_id")
  • Loading branch information
vLKp committed Dec 24, 2023
1 parent 68e1fe3 commit d724905
Showing 1 changed file with 0 additions and 7 deletions.
7 changes: 0 additions & 7 deletions similar/main/fireball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,14 +1197,7 @@ static bool drop_robot_egg(const d_robot_info_array &Robot_info, const contained
// new_pos.y += (d_rand()-16384)*7;
// new_pos.z += (d_rand()-16384)*6;

#if defined(DXX_BUILD_DESCENT_I)
/* ObjId appears to serve as both a polygon_model_index and as
* a robot index.
*/
const auto rid = static_cast<robot_id>(ObjId[underlying_value(type)]);
#elif defined(DXX_BUILD_DESCENT_II)
const auto rid = static_cast<robot_id>(id);
#endif
auto &robptr = Robot_info[rid];
const auto &&objp = robot_create(Robot_info, rid, segnum, new_pos, &vmd_identity_matrix, Polygon_models[robptr.model_num].rad, ai_behavior::AIB_NORMAL);
if (objp == object_none)
Expand Down

0 comments on commit d724905

Please sign in to comment.