From d7249052acebc884bf69de7c2a4bbb16677c2596 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 24 Dec 2023 23:13:10 +0000 Subject: [PATCH] Fix Descent 1 robots-drop-robots logic Commit 7a183c18d909 ("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 7a183c18d909, 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 7a183c18d909 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 Bisected-by: InfernalCore Fixes: 7a183c18d909e6af5a39b95955afd856f2c2a02c ("Use enum class for robot_id") --- similar/main/fireball.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/similar/main/fireball.cpp b/similar/main/fireball.cpp index 977d4729e..b1cfd8dbf 100644 --- a/similar/main/fireball.cpp +++ b/similar/main/fireball.cpp @@ -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(ObjId[underlying_value(type)]); -#elif defined(DXX_BUILD_DESCENT_II) const auto rid = static_cast(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)