Commit graph

6437 commits

Author SHA1 Message Date
Kp c464ddeae1 Sanitize control center triggers on load
Descent 2: Vertigo level 10 has invalid data in its control center
triggers.  Sanitize invalid data at load to avoid problems in
memory-poisoning builds.
2022-09-24 17:47:52 +00:00
Kp ad7057be87 Add hack for case mismatch in Vertigo robot movies
PhysFS 3 is case-sensitive for movie filename lookup.  The consequence
of this was first reported in [1].  In [2], @icculus stated this was a
bug in PhysFS 3 that would be fixed in PhysFS 3.0.2.  However, [3] and
[4] assert that the fix was never included.  The existence of [5] seems
to support this.  The original problem was reported in 2019.  As of
2022, user @AlumiuN, running PhysFS 3.0.2, is affected.  Therefore, this
commit adds code to detect the relevant robot movies and adjust the case
in the Rebirth code.

[1]: https://github.com/dxx-rebirth/dxx-rebirth/issues/379
[2]: https://github.com/dxx-rebirth/dxx-rebirth/issues/379#issuecomment-389400528
[3]: https://github.com/dxx-rebirth/dxx-rebirth/issues/379#issuecomment-462083489
[4]: https://github.com/dxx-rebirth/dxx-rebirth/issues/379#issuecomment-477790175
[5]: https://github.com/dxx-rebirth/dxx-rebirth/issues/644
2022-09-24 17:47:52 +00:00
Kp 9fa97573c4 Move RoboFile to briefing scope 2022-09-24 17:47:52 +00:00
Kp af8efbf830 Clear GameSounds, SoundOffset in bulk 2022-09-24 17:47:52 +00:00
Kp 9cad6c0eaa Use std::span for sound_slot samples 2022-09-24 17:47:52 +00:00
Kp ceef174418 Cache strlen call result 2022-09-24 17:47:52 +00:00
Kp 5eb41816f3 Use std::span for CREDITS_FILE 2022-09-24 17:47:52 +00:00
Kp a79ed84112 Use std::span in location_wrapper 2022-09-24 17:47:52 +00:00
Kp e4e8259253 Reduce scope of callback_handler newpath
If select_file_recursive is not called again, then the handler returns
without reading newpath.  Skip defining it if it will not be read.
2022-09-24 17:47:52 +00:00
Kp a48e6ab56b Pass std::span to _g3_draw_tmap 2022-09-24 17:47:52 +00:00
Kp ad8325b63c Pass std::span to _g3_draw_tmap_2 2022-09-24 17:47:52 +00:00
Kp 491d23e2d9 Pass std::span to _g3_draw_poly 2022-09-24 17:47:52 +00:00
Kp 97f0c5a6d0 Pass std::span to decode_data 2022-09-24 17:47:52 +00:00
Kp 0b91da6d9c Use span methods to construct dxx_sendto input 2022-09-24 17:47:52 +00:00
Kp 9faa3d912d Pass std::span to pcx_encode_line 2022-09-24 17:47:52 +00:00
Kp e69f219539 Pass std::span to g3_validate_polygon_model 2022-09-24 17:47:52 +00:00
Kp 928834fdf8 Pass std::span to g3_init_polygon_model 2022-09-24 17:47:52 +00:00
Kp 76643ed432 Change trace_segs not to recompute children on every pass
`oldsegnum` is `const`, so the address computed from it cannot change.
Lift the computation of `auto &children` out of the loop.

Reduce the scope of `biggest_val`, since it does not need to outlive the
loop.
2022-09-24 17:47:52 +00:00
Kp d797072596 Make vector magnitude constant in more cases
Introduce a helper to obtain both the magnitude of a vector and the
corresponding normalized vector.  Use it to capture both values as const
when possible.
2022-09-24 17:47:52 +00:00
Kp f599ad90b4 Make create_omega_blobs::omega_delta_vector const 2022-09-24 17:47:52 +00:00
Kp 781ca0c97d Reorder endlevel exit_side initialization to fix -Wmaybe-uninitialized
gcc-11.3.0 issues a -Wmaybe-uninitialized warning for `exit_side`.
Reorder the code to eliminate this warning.  Also, fix a potential
out-of-bounds read if `matt_find_connect_side` returned `side_none`.
Before, this would lead to a read of `Side_opposite[side_none]` before
the test that `entry_side` is not `side_none`.  Now, if
`matt_find_connect_side` returns `side_none`, the read of
`Side_opposite` is skipped and logic goes directly to finding a proper
exit side.
2022-09-24 17:47:52 +00:00
Kp d1354911fc Reorder nm_string_inputbox to avoid -Wmaybe-uninitialized
gcc-11.3.0 with -Og may issue a -Wmaybe-uninitialized warning for `w1`
because it fails to prove that every path sets the variable.  Reorder
the logic to use a local lambda to ensure that every path assigns a
value.
2022-09-24 17:47:52 +00:00
Kp 2ecad00e90 Pass std::span to load_palette 2022-09-24 17:47:52 +00:00
Kp 805d71de6b Move Shareware_level_names,Registered_level_names to dumpmine.cpp
They are only used in this file, so move them there and make them
static.
2022-09-24 17:47:52 +00:00
Kp 8f1055ca6b Use std::span for poison helper functions 2022-09-24 17:47:51 +00:00
Kp 17a0452001 Use std::span for nm_item_input 2022-09-24 17:47:51 +00:00
Kp e0300e1e30 Pass std::span to dispatch_table::send_data 2022-09-24 17:47:51 +00:00
Kp 2d46e020e0 Return length change from copy_from_ntstring
Switch from passing length by-reference to instead passing it in by
value and returning the change.  This lets callers keep the length in a
register.
2022-09-24 17:47:51 +00:00
Kp 95bb58a2fe Convert PUT_INTEL_* uses to operator[]
Switch away from operator+(uint8_t *, std::size_t), since future work
will use a type that defines operator[] and not operator+.
2022-09-24 17:47:51 +00:00
Kp b8ed30235c Remove Multi_is_guided; handle setup directly
`Multi_is_guided` is only enabled in one place.  One code path set up
Guided_missile[] for the local player, and a different path handled
network players.  Remove `Multi_is_guided` and rearrange such that a
single site handles both local and network players.
2022-09-24 17:47:51 +00:00
JohnnyonFlame c90ac3e611 Fix OpenGL ES build on SDL2. 2022-09-18 21:35:55 -03:00
Kp ad46235b67 Avoid spinning in multiplayer when the game window is hidden
When the host exits the game, guests switch the game window to be
non-visible, and raise a dialog box stating `Host has left the game!`.
Prior to this change, the guests would then busy loop until the dialog
was dismissed.  With this change, the game will sleep for each idle
event, minimizing CPU use during the period waiting for the player to
acknowledge the dialog box.
2022-09-11 17:00:45 +00:00
Kp 45362ac37b Fix guest loading of multiplayer saved games
Using `sav_objnum` caused the player to be restored into the object slot
of the pre-load level, in the object table of the post-load level.  This
was harmless when the slots were the same, and wrong when they were not.
It became noticeably wrong when more player data was moved into the
object.  After those changes, the player's data was stored into the
correct post-load slot, but the ship was assigned to the pre-load slot.

Remove the incorrect slot switch, and add an assert that the object
being overwritten is a player ghost.  With the incorrect switch present,
this assert will catch most (but not all)[1] cases of the incorrect
restore.  With the incorrect switch removed, this assert succeeds.

[1] In the unlikely case that the post-load slot was a player start, but
for a different player, the assert could succeed despite the slot
mismatch bug.  In the common case, the post-load slot would not be a
start of a different player; it would either be the correct player slot,
in which case `sav_objnum` was harmless, or it would be some other
object, such as a robot.
2022-09-11 17:00:45 +00:00
Kp d9f30ba10c Avoid spinning in net_udp_request_poll
If the guest is slow to respond, the host would enter a busy loop
polling for the guests to be ready.  Mitigate the CPU load by sleeping
for 50ms when guests are not yet ready.
2022-09-11 17:00:45 +00:00
Kp 232c648024 Add Windows version resource for Windows build 2022-09-11 17:00:45 +00:00
Kp 11a400ab8f Move upid sizes to constexpr variable 2022-09-11 17:00:45 +00:00
Kp 70fd424599 Split net_udp_process_game_info to light/heavy variants
The two paths had nothing in common, so split them into separate
functions and call the appropriate version from each caller.
2022-09-11 17:00:44 +00:00
Kp 575bfe8a69 Use enum class for tracker_game_id 2022-09-11 17:00:44 +00:00
Kp 8f847c16bb Use std::span for csocket_data_buffer 2022-09-11 17:00:44 +00:00
Kp 763f1d4902 Use std::span for socket_data_buffer 2022-09-11 17:00:44 +00:00
Kp eb8a7d8186 Use std::span for multi::send_data_direct 2022-09-11 17:00:44 +00:00
Kp 53770489d8 Use std::span for net_udp_noloss_add_queue_pkt 2022-09-11 17:00:44 +00:00
Kp 2589ba9c60 Ignore invalid MULTI_START_TRIGGER messages 2022-09-11 17:00:44 +00:00
Kp 0512ea8d65 Use enum class for upid 2022-09-11 17:00:44 +00:00
Kp d32fc7acab Use enum class for kick_player_reason 2022-09-11 17:00:44 +00:00
Kp 4cf1eb328f Use std::array for prepare_kill_name storage 2022-09-11 17:00:44 +00:00
Kp 0a8bf6bfa8 Remove redundant test in multi_do_finish_game
This is only called from the dispatch switch which checked the type.
There is no need to check the type again.
2022-09-11 17:00:44 +00:00
Kp dac7b13f65 Pass optional parameters to multi_do_fire from caller
Remove the multi_do_fire branches that check the message type.  Delegate
those checks to the caller, so that multi_do_fire can work with the
common initial sequence of the three messages.
2022-09-11 17:00:44 +00:00
Kp 366b048879 Merge commit 'refs/pull/657/head' into master 2022-08-23 02:13:01 +00:00
Kp 0a1758f44f Ignore excess hostages during scoring
Descent 2 secret levels allow a player to rescue hostages that are not
counted in `total_hostages`, so a player can exit with more hostages
saved than were in the mine.  Change the scoring logic not to penalize a
player for saving these unaccounted hostages.
2022-08-22 01:24:49 +00:00
Kp cd09a742a0 Initialize aip->CURRENT_GUN in robot setup
In non-memory-poison builds, the zero initialization of the new object
will suffice to cover this.  In memory-poison builds, the new object
will be reset to a poison value, so the member must be given a
reasonable value here.
2022-08-22 01:24:49 +00:00
Kp c64a584bfd Use enum class for robot_gun_number
Validate gun numbers on loading object data.  Factor out and normalize
the logic for advancing to a robot's next gun.
2022-08-22 01:24:49 +00:00
Kp 4e66bff3f6 Fix SDL-only build of game.cpp
Fixes: 8be306efa7 ("Use enum class for cockpit_mode_t")
2022-08-22 01:24:49 +00:00
Kp 1fb55eebc2 Use enum class for robot_animation_state 2022-08-22 01:24:49 +00:00
Kp 3ea0cc7053 Store Pof_addr at local scope
Pass it to called functions as needed.
2022-08-22 01:24:49 +00:00
Kp 6b7ba83a00 Move anim_angs into local scope, since it is copied out later 2022-08-22 01:24:49 +00:00
Kp 99577c4296 Simplify pof_read_string
The resulting string is discarded, so change it to skip without copying.
2022-08-22 01:24:49 +00:00
Kp a41908dece Move Pof_file_end to local scope
Rely on the extent in std::span for called code that needs to know
bounds.
2022-08-22 01:24:49 +00:00
Kp 3e13dcdf19 Use std::span to bound read_model_guns valid bytes 2022-08-22 01:24:49 +00:00
Kp 15e8ceeaa4 Use std::span to bound read_model_file valid bytes 2022-08-22 01:24:49 +00:00
Kp 42caec7e58 Use std::span for pof reading functions 2022-08-22 01:24:49 +00:00
Kp c5c5e8ea39 Simplify pof_read_angs
The caller passes a length of 1, so inline that and simplify the
function.
2022-08-22 01:24:49 +00:00
Kp 69579df368 Simplify pof_read_short
Use the general little-endian helper.
2022-08-22 01:24:49 +00:00
Kp 87c79206e8 Simplify pof_cfread
All callers pass a value of 1 for one of the two length terms, so inline
that and eliminate the multiplication.
2022-08-22 01:24:49 +00:00
Kp bfb7ed7efc Simplify pof_read_vecs
All callers pass a count of 1, so inline that and eliminate the loop.
2022-08-22 01:24:49 +00:00
Tylor 6fee36638d Feat: Pitch unlocker 2022-08-21 16:16:40 -05:00
Kp 0d045ae3da Fix Windows net_udp build
Convert the RAIIsocket to a simple SOCKET before passing it to FD_SET.
Otherwise, the build fails with:

```
similar/main/net_udp.cpp: In function 'int {anonymous}::udp_general_packet_ready(dcx::{anonymous}::RAIIsocket&)':
similar/main/net_udp.cpp:969:2: error: use of deleted function 'bool dcx::{anonymous}::RAIIsocket::operator==(T) const [with T = long long unsigned int]'
  969 |  FD_SET(sock, &set);
      |  ^~~~~~
similar/main/net_udp.cpp:493:29: note: declared here
  493 |  template <typename T> bool operator==(T) const = delete;
      |                             ^~~~~~~~
```
2022-08-16 03:15:04 +00:00
raptor 5165efbc46 Use custom fixed-point audio resampler:
- Hopefully fixes issues with poor quality resampling when using SDL_AudioCVT
- Converts 11025 Hz or 22050 Hz samples to the default 44100 Hz outputs
- Uses high order brick wall filter like Sound Blaster 16
2022-08-09 22:10:13 -06:00
Kp fb75a7900c Pass std::span to multi_do_message 2022-07-30 17:42:59 +00:00
Kp 81ab68e0f6 Pass std::span to multi_do_player_inventory 2022-07-30 17:42:59 +00:00
Kp 31b8d98e22 Pass std::span to multi_do_kill_client 2022-07-30 17:42:59 +00:00
Kp e76cefd846 Pass std::span to multi_do_kill_host 2022-07-30 17:42:59 +00:00
Kp 43c86b94af Split multi_do_kill to multi_do_kill_host+multi_do_kill_client
The kill messages have different lengths and conditional processing
based on whether the message is MULTI_KILL_CLIENT or MULTI_KILL_HOST.
Split the two into separate functions to simplify the implementation of
each.
2022-07-30 17:42:59 +00:00
Kp 127a1f15e6 Pass std::span to multi_do_gmode_update 2022-07-30 17:42:59 +00:00
Kp b24d61cd0a Pass std::span to multi_do_msgsend_state 2022-07-30 17:42:59 +00:00
Kp c5eeaa48cd Pass std::span to multi_do_bounty 2022-07-30 17:42:59 +00:00
Kp da138757e6 Pass std::span to multi_do_kill_goal_counts 2022-07-30 17:42:59 +00:00
Kp 79683690bd Pass std::span to multi_do_heartbeat 2022-07-30 17:42:59 +00:00
Kp 4893196138 Pass std::span to multi_do_restore_game 2022-07-30 17:42:59 +00:00
Kp 4e42dacd23 Pass std::span to multi_do_save_game 2022-07-30 17:42:59 +00:00
Kp 96a260cea0 Pass std::span to multi_do_hostage_door_status 2022-07-30 17:42:59 +00:00
Kp 55bbc5f599 Pass std::span to multi_do_create_robot_powerups 2022-07-30 17:42:59 +00:00
Kp 4ce39a399e Pass std::span to multi_do_boss_create_robot 2022-07-30 17:42:59 +00:00
Kp c575283c5e Pass std::span to multi_do_boss_stop_gate 2022-07-30 17:42:59 +00:00
Kp b820098103 Pass std::span to multi_do_boss_start_gate 2022-07-30 17:42:59 +00:00
Kp 2b4dd444ca Pass std::span to multi_do_boss_cloak 2022-07-30 17:42:59 +00:00
Kp 6ab2068a82 Pass std::span to multi_do_boss_teleport 2022-07-30 17:42:59 +00:00
Kp 202e3309a7 Pass std::span to multi_recv_escort_goal 2022-07-30 17:42:59 +00:00
Kp cab6900f29 Pass std::span to multi_do_flags 2022-07-30 17:42:59 +00:00
Kp 53d5c296ff Pass std::span to multi_do_effect_blowup 2022-07-30 17:42:59 +00:00
Kp 2cb7de84b1 Pass std::span to multi_do_start_trigger 2022-07-30 17:42:59 +00:00
Kp 802b9bd37e Pass std::span to multi_do_trigger 2022-07-30 17:42:59 +00:00
Kp ff8e2090ab Pass std::span to multi_do_score 2022-07-30 17:42:59 +00:00
Kp 980b3080ce Pass std::span to multi_do_robot_fire 2022-07-30 17:42:59 +00:00
Kp fa0f7cef11 Pass std::span to multi_do_release_robot 2022-07-30 17:42:59 +00:00
Kp d4b047bb02 Pass std::span to multi_do_robot_position 2022-07-30 17:42:59 +00:00
Kp 0036b91084 Pass std::span to multi_do_claim_robot 2022-07-30 17:42:59 +00:00
Kp eb5880ac93 Pass std::span to multi_do_ranking 2022-07-30 17:42:59 +00:00
Kp 8cb20bb3ae Pass std::span to multi_do_finish_game 2022-07-30 17:42:59 +00:00
Kp 73361b9ae0 Pass std::span to multi_do_orb_bonus 2022-07-30 17:42:59 +00:00
Kp 575be1d1ee Pass std::span to multi_do_play_sound 2022-07-30 17:42:59 +00:00
Kp 47cb7d7801 Pass std::span to multi_do_create_powerup 2022-07-30 17:42:59 +00:00
Kp e5799fdabe Pass std::span to multi_do_controlcen_fire 2022-07-30 17:42:59 +00:00
Kp f0bae36bc7 Pass std::span to multi_do_door_open 2022-07-30 17:42:59 +00:00
Kp 7a8a2789e6 Pass std::span to multi_do_escape 2022-07-30 17:42:59 +00:00
Kp 81654ae8a9 Pass std::span to multi_do_light 2022-07-30 17:42:59 +00:00
Kp 784216d8ac Pass std::span to multi_do_seismic 2022-07-30 17:42:59 +00:00
Kp 1ea67e18e8 Pass std::span to multi_do_wall_status 2022-07-30 17:42:59 +00:00
Kp 3b43f040fd Pass std::span to multi_do_stolen_items 2022-07-30 17:42:59 +00:00
Kp dd374ef65e Pass std::span to multi_do_guided 2022-07-30 17:42:59 +00:00
Kp 74fd22a5a0 Pass std::span to multi_do_drop_flag 2022-07-30 17:42:59 +00:00
Kp a5c6a25cf2 Pass std::span to multi_do_drop_marker 2022-07-30 17:42:59 +00:00
Kp 652e3ceddd Pass std::span to multi_do_sound_function 2022-07-30 17:42:59 +00:00
Kp 84bb23e6d3 Pass std::span to multi_do_vulcan_weapon_ammo_adjust 2022-07-30 17:42:59 +00:00
Kp 4dd058d501 Pass std::span to multi_do_drop_weapon 2022-07-30 17:42:59 +00:00
Kp 5ac2a90121 Pass std::span to multi_do_controlcen_destroy 2022-07-30 17:42:59 +00:00
Kp 454bec9715 Pass std::span to multi_do_quit 2022-07-30 17:42:59 +00:00
Kp f923a5d710 Pass std::span to multi_do_player_deres 2022-07-30 17:42:59 +00:00
Kp aa95c6f804 Pass std::span to multi_do_remobj 2022-07-30 17:42:59 +00:00
Kp 7d464db18d Pass std::span to multi_do_reappear 2022-07-30 17:42:59 +00:00
Kp 74af38bba2 Pass std::span to multi_do_position 2022-07-30 17:42:59 +00:00
Kp 49f608010a Pass std::span to multi_do_robot_explode 2022-07-30 17:42:59 +00:00
Kp e1269dca35 Pass std::span to multi_do_create_robot 2022-07-30 17:42:59 +00:00
Kp 3bc110ec01 Fold robot kamikaze explode_object calls 2022-07-30 17:42:59 +00:00
Kp dc674eafe8 Replace various uses of std::enable_if with C++20 requires()
Compiler error messages are generally better when reporting a misuse
that fails a requires() versus reporting a misuse that fails a
std::enable_if.  In some cases, this also makes the code clearer, and
avoids the need for dummy template parameters as a place to invoke
std::enable_if.
2022-07-30 17:42:59 +00:00
Kp 58061b5f45 Use C++20 std::span for morph_data 2022-07-30 17:42:59 +00:00
Kp f92a978b4a Unify collide_player_and_materialization_center -> apply_damage_to_player
D2 changed the rule for the parameter `killer`.  Split that out to a
variable and combine the underlying call.  This does not change the game
semantics.
2022-07-23 20:58:10 +00:00
Kp d9d2bac092 Use enum class for apply_damage_to_player::possibly_friendly
Also, remove a redundant invulnerability check in one caller.
apply_damage_to_player already tests for invulnerability and returns if
appropriate.
2022-07-23 20:58:10 +00:00
Kp a44f80fd64 Flatten call chain to net_udp_send_data 2022-07-23 20:58:10 +00:00
Kp e6c510d467 Use vector read/write helpers in network messages 2022-07-23 20:58:10 +00:00
Kp 4141e04359 Pass thief stolen item storage to drop_stolen_items 2022-07-23 20:58:10 +00:00
Kp a3a2f7cc9a Pass context to drop_stolen_items
Pass the specific object fields needed, rather than the entire object.
2022-07-23 20:58:10 +00:00
Kp 801c76cbd2 Pass context to spit_powerup 2022-07-23 20:58:10 +00:00
Kp b61add4765 Pass context to drop_powerup 2022-07-23 20:58:10 +00:00
Kp 51219d3607 Use enum class for PlayMovie flag must_have 2022-07-23 20:58:10 +00:00
Kp 2536b6c1bc Pass player orientation matrix to multi_send_fire
The caller has the player object, and can provide the orientation matrix
from it.  Use that instead of letting multi_send_fire recompute the
object in order to get the matrix.
2022-07-23 20:58:10 +00:00
Kp c03b772ce7 Use caller supplied object for player_info in Flare_create
The caller supplies the local player, so use that instead of computing
it again.
2022-07-23 20:58:10 +00:00
Kp 68681d462c Fire flare from local player, not from ConsoleObject
The local player object was already computed above, and so is free to
reuse here.
2022-07-23 20:58:10 +00:00
Kp a0dc1b4283 Use union of multi_command<> for multi_send_fire message
Switch to a union of the possible multi_command<> types, and eliminate
the explicit length parameter passed to multi_send_data.
2022-07-23 20:58:10 +00:00
Kp 52aa9891b9 Simplify passing weapon to do_missile_firing
When the player fires a generic secondary, the choice of proximity bomb
versus super-mine is never read.  When the player specifically drops a
bomb, only that choice needs to be read.  Pass the chosen weapon as an
argument, and avoid computing the choice on the path where it is never
read.
2022-07-23 20:58:10 +00:00
Kp b4fcb9c305 Simplify do_missile_firing test for whether to autoselect
If `drop_bomb` is false, then `weapon == player_info.Secondary_weapon`.
If `drop_bomb` is true, then `weapon == bomb`.
2022-07-23 20:58:10 +00:00
Kp c0e12eee3f Push player object lookup from do_missile_firing to caller
The caller already needs the player object for other purposes, so let
the caller pass it down to do_missile_firing.
2022-07-23 20:58:10 +00:00
Kp 0dd5d6e0d5 Split guided missile release local/remote handling
Two paths are always local.  One path is always remote.  Split the
handler function to remove the locality test and rely on the caller's
knowledge of whether the affected player is local.
2022-07-23 20:58:10 +00:00
Kp 0cb0b5cdc0 Use playernum_t for guided missile player number 2022-07-23 20:58:10 +00:00
Kp 4886afdf93 Lift which_bomb from do_missile_firing to caller
Callers already have the player_info available, and will need the value
of bomb in a subsequent commit.  Lift it here.
2022-07-16 15:26:12 +00:00
Kp 3139445f02 Cache player object in do_missile_firing
Resolve the object to a vmobjptridx once, and use it as needed.  Replace
some uses of ConsoleObject with the local player, since those should be
the same, and local player is already computed.
2022-07-16 15:26:12 +00:00
Kp 1d65a83d73 Use primary_weapon_index_t for do_laser_firing weapon_id 2022-07-16 15:26:12 +00:00
Kp cbab79a56a Simplify multi_send_fire handling of is_bomb_objnum
Only one caller passes a value other than `object_none` for
`is_bomb_objnum`.  That one caller uses an equivalent predicate to the
one that `multi_send_fire` uses for deciding whether to use
`MULTI_FIRE_BOMB`.  Therefore, if `is_bomb_objnum != object_none` is
true, the weapon is guaranteed to be a proximity bomb or smart mine, and
`multi_send_fire` can use `MULTI_FIRE_BOMB` without retesting the object
id.
2022-07-16 15:26:12 +00:00
Kp f22b627949 Simplify do_missile_firing lookup of track_goal
Commit 81dd23b151 ("Only charge player for weapons that fire successfully")
added an early return when `objnum == object_none`, so if execution
reaches the call to `multi_send_fire`, then the object is guaranteed to
exist.  Access the track_goal without rechecking whether the object
exists.
2022-07-16 15:26:12 +00:00
Kp 9cf82a8eb5 Set multi_command code in constructor, not at send time
Rework multi_send_kill to handle the stricter construction requirements
this imposes.
2022-07-16 15:26:12 +00:00
Kp ea18bd074c Use multi_command for multi_send_message 2022-07-16 15:26:12 +00:00
Kp 2ea48475e3 Use multi_command for robot_fire_buf 2022-07-16 15:26:12 +00:00
Kp 2288f85d6a Use multi_command for multi_send_drop_marker 2022-07-16 15:26:12 +00:00
Kp efecd3507f Optimize removal of expired mdata records
Instead of sliding the entire queue down one element at a time, move the
non-expired elements in one step, and wipe all the trailing elements
in a single pass.
2022-07-16 15:26:12 +00:00
Kp 851edbbd3c Use enum class for player connected status 2022-07-16 15:26:12 +00:00
Kp 4cc1bc995b Pack player acknowledgement mask into a bitset
The only values for any given player are true/false, so use a bitset
instead of a byte per player.  Some implementations may use a uint64_t
internally, negating the space savings.  Even so, this version is
an improvement for requiring the use of playernum_t as an index.
2022-07-16 15:26:12 +00:00
Kp 1fa56d439c Skip dropping items when host quits
If the host quits, the game ends immediately afterward, so no dropped
items could be picked up.
2022-07-16 15:26:12 +00:00
Kp db4005fca6 Hold Network_laser_track const in multi_do_fire 2022-07-16 15:26:12 +00:00
Kp d3fdfd53b7 Update comment on do_laser_firing
Fixes: 5b29428643 ("Propagate nfires within do_laser_firing")
2022-07-16 15:26:12 +00:00
Kp 4cff6fd9d7 Simplify multi_send_robot_frame argument sent
The function had one caller, which always passed `0`.  Inline that.
Next, observe that `sent` is only ever modified `if (!(Game_mode &
GM_NETWORK))`.  As a multiplayer function, `multi_send_robot_frame`
should never be called in single-player, so this test should always be
false.  Delete it, and observe that `sent` is now `const`.

Remove unused return value of `multi_send_robot_frame`.
2022-07-16 15:26:12 +00:00
Kp 8af8124839 Lift multi_send_robot_position_sub priority parameter to callers
Instead of passing a truth value and letting
multi_send_robot_position_sub pick which of two priority values to use,
let the callers pass the priority directly.  There were two callers.
One used a fixed truth value, and the other can easily use a ternary.
2022-07-16 15:26:12 +00:00
Kp 450154452d Use enum class for multi_send_robot_position_priority
Increment all values by 1, to eliminate the increment inside
multi_send_robot_position.
2022-07-16 15:26:12 +00:00
Kp 47f622dbc4 Use std::bitset for robot_fired
This only ever tracks true/false, so use bitset to save space.
2022-07-16 15:26:12 +00:00
Kp dccebd9783 Flatten call chain to net_udp_send_mdata_direct 2022-07-16 15:26:12 +00:00
Kp 61d1ef9904 Remove obsolete and unused multi_send_data_direct
All callers now use the multi_command<C> form, so there is no need for
the form that allows a free pointer and length.
2022-07-16 15:26:12 +00:00
Kp b737524415 Use enum class for next_level_request_secret_flag
Instead of passing a bare `int` named `secret_flag`, define it as an
`enum class : uint8_t` to name the two special values.

Rework the passing of this value, to deal with some confusing
inconsistencies when reading the code.

Before this change:
In D1:
- Multiplayer will always go to the secret level, regardless of which
  exit door the player used.
In D2:
- Flying through a D1 secret exit in multiplayer shows the on-HUD error
  "Secret Level Teleporter disabled in multiplayer!", and does not exit
  the level.  This is at best confusing, and at worst dangerous, since
  D1 secret exits are only available during the countdown, so the player
  has little time to realize that the normal exit must be used instead.
- Like D1, multiplayer will request to go to the secret level regardless
  of the exit used.  Unlike D1, the caller ignores the flag and always
  advances to the next regular level.

After this change:
- No observable differences for the player in-game.  The questionable D2
  secret exit handling for D1 is retained.
- The code makes clearer that secret exits do not work in D2
  multiplayer, by way of `#if defined(DXX_BUILD_DESCENT_I)` guarding the
  existence of the parameter and all updates to it.
2022-07-16 15:26:12 +00:00
Kp f3d31a6d27 Use enum class for Difficulty_level_type 2022-07-16 15:26:12 +00:00
Kp 2eafb4a361 Simplify calling net_udp_request_game_info
All callers except one want the `lite` version of the request.  Switch
from a boolean that is selected inside the function to a reference that
is defaulted to `lite`.  Override that argument to the heavy version in
the one caller that needs it.
2022-07-09 13:39:29 +00:00
Kp 066b172963 Use enum class for Network_status 2022-07-09 13:39:29 +00:00
Kp 1cd9d18127 Compute game version rejection buffer at compile time
All the fields are constant.  Compute them at compile time.  Move the
sending function to dcx, since it is not game-specific.
2022-07-09 13:39:29 +00:00
Kp c354f9a606 Short-circuit network version mismatch tests
Once one component is known not to match, there is no reason to read the
other components from memory.
2022-07-09 13:39:29 +00:00
Kp 9af7159592 Compute game info request buffer at compile time
Its contents depend only on compile-time constants, so compute it once
and store it as a read-only variable to be sent as needed.
2022-07-09 13:39:29 +00:00
Kp a0c95c21a8 Flatten the indirection around udp socket functions
This reduces the noise from diagnostics when the function is misused,
and shrinks the code some.
2022-07-09 13:39:29 +00:00
Kp 5aaa095c14 Move Active_udp_games into netgame_list_game_menu 2022-07-09 13:39:29 +00:00
Kp c7bbc415f5 Remove obsolete MULTI_FIRE field nfires
As of 8f8989e049, this field is always
sent as `1`.  Remove it, and update position offsets.
2022-07-09 13:39:29 +00:00
Kp 6275353d97 Split UDP_sequence_packet into per-message types
Using `netplayer_info` in `UDP_sequence_packet` defined many unused
fields.  Replace this with per-message types that carry only the
required fields.  Make these fields `const` where possible.
2022-07-09 13:39:29 +00:00
Kp 2135328dab Use enum class for multiplayer_data_priority 2022-07-09 13:39:29 +00:00
Kp dd260f234b Use auto type for Viewer in more places 2022-07-09 13:39:29 +00:00
Kp a70188e7a5 Move various static functions into anonymous namespace 2022-07-09 13:39:29 +00:00
Kp 6215ef8e06 Pass LevelSharedRobotInfoState to various functions that need it 2022-07-09 13:39:29 +00:00
Kp 37132ab887 Pass LevelSharedRobotInfoState in fvi_query 2022-07-09 13:39:29 +00:00
Kp fac016c104 Split object_create_explosion_sub for with/without damage cases
Some callers create an explosion with damage forced to zero.  Others
create an explosion with damage non-zero.  Only the non-zero case needs
to examine nearby objects.  Split object_create_explosion_sub so that
the zero-damage case can skip that logic, and the arguments required to
implement it.
2022-07-09 13:39:29 +00:00
Kp d6c43f56af Use enum class for gun_num_t 2022-07-09 13:39:29 +00:00
Kp 0dfd462c64 Change fvi_query to pass LevelUniqueObjectState if checking objects
Remove the definition of FQ_CHECK_OBJS and all uses of it.  Add a new
fvi_query member d_level_unique_object_state *LevelUniqueObjectState.
If object checking is enabled, pass &LevelUniqueObjectState in that
member.  If object checking is disabled, pass nullptr in that member.

Change fvi_sub to use this member to decide whether to perform object
checking.
2022-07-09 13:39:29 +00:00
Kp 4bc901b0a9 fvi_sub: validate object once at start of FQ_CHECK_OBJS
If FQ_CHECK_OBJS is used, a valid object is required.  Copy the
icobjptridx_t from fvi_query into a local vcobjptridx_t to force a
validation, then use that validated copy for later work.
2022-07-09 13:39:29 +00:00
Kp 5d62df856d Pass fvi_query to fvi_sub
Many of the input parameters are available in fvi_query, so pass a
reference to that instead of copying the parameters to the stack
individually.
2022-07-09 13:39:29 +00:00
Kp 4ab619b7c2 Restructure use of fvi_query
- Make all members constant, and pass an anonymous temporary fvi_query
  to find_vector_intersection.
- Change `p0`/`p1` to `const vms_vector &`, since the positions are
  mandatory.  Callers can no longer pass `nullptr` or an uninitialized
  value here.
- Change `thisobjnum` to `icobjptridx_t`.  Calls to fvi_sub built an
  objptridx at need, so moving it to the caller allows it to be
  constructed once per find_vector_intersection call.
- Move `flags` and `rad` out of fvi_query, since calls to fvi_sub may
  use other values than the ones in fvi_query.  This prepares for
  passing fvi_query to fvi_sub.
2022-07-09 13:39:29 +00:00
Kp 4ef75b2aed Pass state to do_endlevel_flythrough 2022-07-09 13:39:29 +00:00
Kp a690374916 Pass state to place_object 2022-07-09 13:39:29 +00:00
Kp 8ba1390947 Pass state to explode_object 2022-07-09 13:39:29 +00:00
Kp 192c5de4f1 Add compile-time option to disable ship wiggling
Ship wiggle is normally enabled for compatibility with the original
game.  However, during development, it can become a nuisance, so add an
option to allow disabling it.
2022-07-02 18:10:45 +00:00
Kp e80c6fb05f Rename font underline to draw_full_width_as_fg_color
This started out as underline, but one of the special drawing modes uses
it to draw an underline-width block across the entire vertical height of
the character.
2022-07-02 18:10:45 +00:00
Kp 55af651200 Pass d_level_unique_object_state context to create_omega_blobs 2022-07-02 18:10:45 +00:00
Kp a40ab08bd0 Remove write-only field fcd_data::csd
This value was written when cache entries were created, but is never
read back.
2022-07-02 18:10:45 +00:00
Kp 3230b23bb9 Rework find_connected_distance cache
- Inline MAX_FCD_CACHE into the definition of Fcd_cache, then rely on
  Fcd_cache.size() later.
- Make Fcd_index unsigned.  As an index, a negative number is invalid.
- Change flush_fcd_cache to update Last_fcd_flush_time, rather than
  requiring callers to do it.  Most callers did not update this.
- Change add_to_fcd_cache to validate and reset Fcd_index before use,
  rather than resetting after increment.  This allows Fcd_index to
  become invalid after a write, but it will be reset to a valid value
  before it is used again.
- Fix original game bug in add_to_fcd_cache that caused the cache
  expiration path to clear the wrong cache entry.
2022-07-02 18:10:45 +00:00
Kp e25b476de7 Use enum for segnum_t
Add checked conversions for sites which load from external integers.
2022-07-02 18:10:45 +00:00
Kp fca59adb53 Split out creating OBJ_WEAPON objects 2022-07-02 18:10:45 +00:00
Kp e2509fc840 Move d_robot_info_array out of d_level_shared_robot_info_state
Embedding it in d_level_shared_robot_info_state is reasonable from a
relational perspective, but interferes with referencing
d_robot_info_array when only a forward declaration of
d_level_shared_robot_info_state is available.
2022-07-02 18:10:45 +00:00
Kp e51c11587b Change multi_do_kill to skip copying MULTI_KILL_CLIENT opcode
The opcode will be set to MULTI_KILL_HOST before sending, so do not set
it to MULTI_KILL_CLIENT initially.
2022-07-02 18:10:45 +00:00
Kp bdeca5687e Remove unused copy_diminish_palette
Fixes: f413017317 ("Delegate bald_guy_load PCX to SDL image")
2022-07-02 18:10:45 +00:00
Kp e45ff2da5e Use named enum types for netflag and netgrant 2022-07-02 18:10:45 +00:00
Kp d586fe91e4 Parenthesize gauge_key comma expression
C++20 deprecates `array_name[A,B]`.  For this use case, `A` is needed
for its side effects, but is not intended as an index operation.  Add
parentheses to satisfy the deprecation warning, without changing the
meaning of the code.
2022-07-02 18:10:45 +00:00
Kp 78fd6550ea Avoid unnecessary allocation in jukebox_play
If the song originates in an m3u playlist, no temporary buffer is
needed.  Avoid allocating and initializing one, and instead pass the
pointer directly from the CMLevelMusicPath field.
2022-07-02 18:10:45 +00:00
Kp 173d5559d7 Tighten TGA generation code
- Skip reading unused alpha channel in TGA screenshot path.  The alpha
  channel is discarded, so skip even retrieving it from OpenGL.
- Perform the red/blue swap in place, instead of copying into an
  additional buffer.
2022-07-02 18:10:45 +00:00
Kp d1ed53ebd9 Initialize IPv4/IPv6 broadcast addresses statically
These were computed by passing hardcoded inputs to a lookup function.
Initialize the structure at compile time instead.
2022-06-19 23:35:18 +00:00
Kp d1968fce82 Move num_active_udp_changed into netgame_list_game_menu 2022-06-19 23:35:18 +00:00
Kp 27f18be3ca Move num_active_udp_games into netgame_list_game_menu 2022-06-19 23:35:18 +00:00
Kp a1bdd81d41 Exclude unused code from D2 non-editor build
gamedata_read_tbl is only called if (D1 || (D2 && EDITOR)).  Exclude
defining it for (D2 && !EDITOR).  From there, also exclude defining or
reading the alias list, which is only written by a function
called by gamedata_read_tbl.

Reported-by: heftig <https://github.com/dxx-rebirth/dxx-rebirth/issues/642>
2022-06-11 15:00:02 +00:00
Kp 522c696af0 Remove unnecessary members in splitpath_t
splitpath_t is designed for MS-DOS paths, even though Rebirth now runs
on many platforms that never used DOS conventions.  Most of the members
of splitpath_t are unused on all platforms.  Remove them, and switch to
returning an initialized version of the structure.
2022-06-11 15:00:02 +00:00
Arne de Bruijn 0a5ecd77c6 Fix exit briefing animation speed
Undo change in e973dc0 which set the change animation direction delay
for every frame.
2022-06-06 10:15:27 +02:00
Kp 5545b32fee Do not reset_rear_view if dead when crossing exit trigger
Reported-by: ziplantil <https://github.com/dxx-rebirth/dxx-rebirth/issues/637>
Fixes: 8faed77f5f ("Properly record the event of reset_rear_view() while switching levels to make it work right when rewinding as well; Properly record Countdown seconds for each newdemo frame instead of second change to get display showing up right while playback and still preserving backwards compability; Suspend Game_wind when playing endlevel movie while demo playback")
2022-06-05 17:44:53 +00:00
Kp 346906ae9f Simplify UPID_QUIT_JOINING
The host only needs to check the source address.  Remove the check on
the callsign, and shrink the message accordingly.
2022-06-05 17:44:53 +00:00
Kp 68453cd86f Remove redundant net_udp_welcome_player checks
This loop is run once before the `if()` test, then again at the top of
both the true and false branches of the `if`.  Remove the runs inside
the conditional, since they should produce the same result as the run
that occurs before the conditional.
2022-06-05 17:44:53 +00:00
Kp 9816475706 Pass Object array to object_goto_next_viewer 2022-06-05 17:44:53 +00:00
Kp c5de47b51e Add const qualifiers to some net_udp functions 2022-06-05 17:44:53 +00:00
Kp 3d7cb4abc7 Remove force_dump_ai_objects_all
It rotted because it is only ever used when PARALLAX is defined.  No one
has reported it broken, so remove it.
2022-06-05 17:44:53 +00:00
Kp 0faa33d3df Harden bm_read_player_ship against invalid model numbers
Eliminate an unnecessary internal copy.  Terminate the search early if
an invalid model number is used.
2022-06-05 17:44:53 +00:00
Kp 504e950b75 Simplify bm_read_player_ship last_model_num handling
The existing handling always wrote to slot 0, but did so in a convoluted
way.  The variable names suggest this was not intended, but no one has
ever reported it as broken, and some otherwise valid data files may
depend on this quirk.
2022-06-05 17:44:53 +00:00
Kp 1b13274a5e Combine D1/D2 bm_read_player_ship call to load_polygon_model
D1 and D2 used logically equivalent code, but it was not the same text,
so the unification project split this with a `#ifdef`.  Since the code
does the same thing in both games, combine it into a non-guarded
statement.
2022-06-05 17:44:53 +00:00
Kp 5be32a05c6 Reorder check_line_to_line to eliminate useless copy
Instead of copying the input v1/v2 into det.uvec, pass a reference for
v1/v2 directly to calc_det_value.
2022-06-05 17:44:53 +00:00
Kp 9071675a0d Pass calc_det_value vectors separately
Pass 3 vectors rf/u instead of one vms_matrix.  This may make the code
slightly worse in the short term, but it makes a later change clearer.
2022-06-05 17:44:52 +00:00
Kp bfe7f2bb19 Reorder fvi_sub object type tests
Two tests in series examined the object for a type of OBJ_ROBOT.  Fold
the test together.

The next test also examines ->type.  Move that to an else since it
cannot be true if the first test was true.
2022-06-05 17:44:52 +00:00
Kp e180375f97 Pass GameBitmaps to draw_object_blob 2022-06-05 17:44:52 +00:00
Kp 6e2ed26659 Pass object to init_player_object 2022-06-05 17:44:52 +00:00
Kp 9f207daf95 Pass player object to reset_player_object 2022-06-05 17:44:52 +00:00
Kp 11a0aae9ee Pass GameBitmaps to piggy_bitmap_page_in 2022-06-05 17:44:52 +00:00
Kp f36a8e015e Disable collecting segment list in see_object
The segment list is written to `hit_data`, but `hit_data` goes out of
scope before the segment list is read back.  Skip collecting it, since
it was effectively write-only on this path.
2022-06-05 17:44:52 +00:00
Kp 33152640bc Remove fvi_info::hit_type
Its value is always readily available as the return value of
find_vector_intersection, so remove the structure member and rely on the
returned value.
2022-06-05 17:44:52 +00:00
Kp 8c4adbc262 Show repaircenters on automap 2022-06-05 17:44:52 +00:00
Kp 33923ab4ca Enable creating repaircenters in the editor
This is untested, but matches the logic used for
fuelcen_create_from_curseg.
2022-06-05 17:44:52 +00:00
Kp be7388a369 Enable repaircenter in D1
The code exists in D2, and the segment special is reserved for both
games.  Include the repaircenter code in D1, also.
2022-06-05 17:44:52 +00:00
Kp 885b0939d6 Defer charging for Omega cannon until blobs are created
If the creation of the Omega cannon blob fails, do not play the sound or
deplete the player's energy.
2022-06-05 17:44:52 +00:00
Kp 69d8dada1c Return next object from obj_detach_one
This allows obj_detach_all to avoid reloading the value from the parent
object each time.
2022-06-05 17:44:52 +00:00
Kp 6bd6a47612 Rework compress_segments to use segment iterators
This removes direct math on segnum_t, which will simplify later use of
`enum class segnum_t`.
2022-06-05 17:44:52 +00:00
Kp 86a32dd0ff Change enum sidenum_t to enum class sidenum_t 2022-06-05 17:44:52 +00:00
Kp 4fd412b2ea Precompute g3_draw_line GL color data 2022-06-05 17:44:52 +00:00
Kp e54338ce4e Combine canvas+color into g3_draw_line_context 2022-06-05 17:44:52 +00:00
Kp a44324abe1 Tighten net_udp player index check 2022-05-29 19:37:58 +00:00
Kp 0de494c2e0 Make thief explode when killed
Commit 1a9fba804d made an incorrect simplification.  It observed that
thief robots are not boss robots and vice versa, and from that changed:

```
	if (is_thief) { drop_stolen_items(); }
	if (is_boss) { start_boss_death_sequence(); }
	else if (death_roll) { start_robot_death_sequence(); }
	else { regular_death(); }
```

to

```
	if (is_thief) { drop_stolen_items(); }
	else if (is_boss) { start_boss_death_sequence(); }
	else if (death_roll) { start_robot_death_sequence(); }
	else { regular_death(); }
```

This was incorrect, because although a thief is not a boss, a thief does
need to proceed through the other non-boss if tests.  This error caused
a thief not to explode on death, and instead continue to fly around and
absorb weapon fire.

Fix the logic error by removing the incorrect `else`, so that a thief
can be tested for is_boss, get false, and then proceed through the
non-boss death logic.

Fixes: 1a9fba804d ("Avoid repeated valptridx dereferences in multibot.cpp")
2022-05-29 18:44:59 +00:00
Kp 092daecb61 Use static_cast<> to convert player_marker_num to game_marker_index
gcc-12 rejects the list initialization syntax.  Switch to static_cast<>,
which generates equivalent code.

Reported-by: dbermond <https://github.com/dxx-rebirth/dxx-rebirth/issues/638>
2022-05-28 21:04:37 +00:00
Kp 12cca97870 Remove unused piggy_new_pigfile local char tempname[20]
gcc-12 warns that the snprintf to initialize `tempname` may be
truncated.  The variable is never used after it is initialized, so
delete the initialization and declaration.
2022-05-28 21:04:37 +00:00
Kp a8e7f6ad59 Use enum class for find_vector_intersection result 2022-05-24 02:32:58 +00:00
Kp 62635ec285 Use enum class for vm_magnitude_squared 2022-05-24 02:32:58 +00:00
Kp cf51ac4ee0 Fix BUG on show-path cheat
Players are not robots, but the show-path cheat tried to pretend they
are, and triggered a BUG warning[1] when looking up robot information
from the player object.  Fix this by passing in the robot_info when the
caller is providing a robot, and a named `nullptr` value (as
`create_path_unused_robot_info`) when the caller is providing a
non-robot object.

[1] As below, but repeated many times
```
similar/main/ai.cpp:1905: BUG: object 0x555555858550 has type 4, expected 2
similar/main/ai.cpp:1974: BUG: object 0x555555858550 has type 4, expected 2
```
2022-05-21 19:51:18 +00:00
AlumiuN da0b746037 Set console output priority to highest given option rather than most recently specified 2022-05-16 20:03:34 +12:00
Kp e29cddd524 Cache Difficulty_level during aim-leading calculations 2022-05-11 03:17:23 +00:00
Kp edbdec361c Check return value of check_line_to_line 2022-05-10 01:58:55 +00:00
Kp 2b36332228 Use enum class for intersection_type in fvi 2022-05-10 01:58:55 +00:00
Kp 887851cb99 Make RAIIsocket::closesocket static
It exists as a wrapper for the Windows call of the same name.  Windows
does not require an object, so neither should this method.
2022-05-10 01:58:55 +00:00
Kp 464b5b302f Change RAIIaddrinfo to use using instead of forwarding functions 2022-05-10 01:58:55 +00:00
Kp 9e0431b861 digi_win32_play_midi_song: write hmp_open result directly to global
Commit 3b5b69cb97 changed the logic to store the result of hmp_open
into a local that was destroyed at the end of the function.  This was
incorrect, as destruction of the returned value will immediately halt
the music.  Revert to the previous behavior, where the result is written
to the global `cur_hmp` so that it persists past the end of the
function.

Reported-by: norbert79 <https://github.com/dxx-rebirth/dxx-rebirth/issues/634>
Analyzed-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/634#issuecomment-1110510761>
Proposed-fix-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/634#issuecomment-1110510761>
Fixes: 3b5b69cb97 ("Improve error reporting for hmp_open / hmp2mid")
2022-04-28 02:19:26 +00:00
Kp 504b38759c Use enum class for weapon_sound_flag
Pass the silent/audible flag as an enum:uint8_t to avoid type confusion
issues.
2022-04-24 20:42:01 +00:00
Kp 34793b5477 Use std::array for find_connected_distance depth array
Zero the entire array, rather than adjusting the loop to account for the
count of segments in the level.  The array may not need to be zeroed at
all, but this is cheap and guarantees consistent results.
2022-04-24 20:42:01 +00:00
Kp a610a7b32d Pass bare object & to thief stealing routines
Use `object &` instead of `vmobjptr_t`.  This should generate equivalent
code, but produce smaller debug information and may require less
inlining by the compiler.
2022-04-24 20:42:01 +00:00
Kp 1c2e1c6946 Tighten type info for d_strdup
The allocated block is part of the dmem subsystem, so return a type that
reflects that.
2022-04-24 20:42:01 +00:00
Kp 81dd23b151 Only charge player for weapons that fire successfully
If creating the weapon object fails, do not charge the player for the
shot that was not created.
2022-04-17 22:27:19 +00:00
Kp 5b29428643 Propagate nfires within do_laser_firing
Previous work made this a local constant.  Propagate that constant now
to eliminate dead conditional paths.
2022-04-17 22:27:19 +00:00
Kp 8f8989e049 Propagate do_laser_firing nfires as 1
Every caller passes `1`, so remove the parameter and always use `1`.
For backward compatibility with the previous network protocol, continue
to send a `1` in the network message.
2022-04-17 22:27:19 +00:00
Kp c4fb3fc30f Defer creating awareness event until weapon is created
If creation of the weapon object fails, do not tell robots that the
weapon was fired.
2022-04-17 22:27:19 +00:00
Kp dde3747ed4 Improve drop-secondary messages
- Write a more specific message on failure
- Defer writing a success message until `spit_powerup` succeeds
- Defer the sound too
- Rewrite the success message to tell how much ammo remains
2022-04-17 22:27:19 +00:00
Kp 834aeea23f Fix drop-primary/drop-secondary keys
Commit 8c8b7419b6 defined Shift-F5 and Shift-F6 to adjust the VR
handling.  However, Shift-F5 and Shift-F6 already had a meaning: drop
primary weapon / drop secondary weapon.  The ordering of the logic
causes the new VR handling to suppress the old drop handling, thus
preventing players from dropping weapons.  Disable the VR meaning for
these keys so that drop-weapon works again, since F1 documents those
keys as drop-weapon.

Fixes: 8c8b7419b6 ("Improved conditionals for stereo vs non-stereo modes.")
2022-04-17 22:27:19 +00:00
Kp f79baf722c Move static obj_* functions into anonymous namespace 2022-04-17 22:27:19 +00:00
Kp d0c32b8cf2 Pass LevelUniqueWallSubsystemState to wall_init 2022-04-17 22:27:19 +00:00
Kp 211dcede72 Inline trigger_init
It is used in only one place.  Move it inline.
2022-04-17 22:27:19 +00:00
Kp da85bd4cd1 Optimize check order in find_connected_distance
Checking for a previously visited segment is cheaper than checking
whether a doorway exists.  Reorder the logic to check first for a
previous visit.
2022-04-17 22:27:19 +00:00
Kp d6d7837aa7 Remove dead store of point_seg::segnum in find_connected_distance 2022-04-17 22:27:19 +00:00
Kp 06a0de1c90 Remove write-only legacy trigger field time
v29_trigger and v30_trigger define a field `time`.  v29_trigger never
initializes it.  v30_trigger initializes it from the uninitialized
v29_trigger in legacy mode, and from a file field otherwise.  No program
logic ever reads this member, so remove it.
2022-04-16 19:38:02 +00:00
Kp 87cc4c79c8 Fix off-by-one in mission string count
Commit 7f2df64649 converted `mission_menu` to inherit from `listbox`,
but introduced an off-by-one bug in the handling of subdirectories.
`listbox` must be told how many strings it is given.  Subdirectories
have one extra string, to represent the `listbox_go_up` element.  The
count passed to `listbox` incorrectly failed to adjust for the generated
go-up element, causing listbox not to show the last string in the list.
Change the logic to adjust the count to include the extra element.

Fixes: 7f2df64649 ("Make mission_menu inherit from listbox")
Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/629>
2022-04-12 03:01:48 +00:00
Kp 9cdf9152bc Always check return value of PHYSFSX_getRealPath
The contents of the output buffer are undefined if PHYSFSX_getRealPath
fails, so mark the function as [[nodiscard]] and modify all callers to
check that the function succeeded.
2022-03-19 22:55:58 +00:00
Kp 3b5b69cb97 Improve error reporting for hmp_open / hmp2mid
Rework the error paths to return path-specific status codes so that the
caller can report exactly which step caused an HMP file to be rejected.
On error, print this reason numerically and, if the reason was a PhysFS
error, also print the PhysFS error code numerically and symbolically.
2022-03-19 22:55:58 +00:00
Kp 61c4d53ae6 Pass canvas to con_draw 2022-03-19 22:55:58 +00:00
Kp b3f250f3b6 Fix openable_door_on_near_path for side WLEFT
openable_door_on_near_path should return 0 for no door and any non-zero
value for door-found.  Commit 9fdf6005df changed the logic to return 0
for no door, and the side number value for door-found.  This is wrong,
since WLEFT has integer value 0, so the caller will interpret a return
of door-found, side=WLEFT as no-door-found.

Fixes: 9fdf6005df ("Convert ai_static::GOALSIDE to sidenum_t")
2022-02-27 14:23:53 +00:00
Kp f51755c2e6 Use enum class for MBTN_* constants 2022-02-27 14:23:53 +00:00
Kp 6863dd3581 Reduce lifetime of joy_axis
It is only needed for the duration of kconfig_end_loop.  Move it from
the global Controls to local scope.
2022-02-27 14:23:53 +00:00
Kp 197a9cbd98 Move joystick interpretation to happen after the event loop
If two or more events are delivered in the same loop, the previous
implementation would count joystick motion multiple times.  Fix this by
moving the joystick interpretation to occur once, after all the events
have been processed.
2022-02-27 14:23:53 +00:00
Kp 9464bdf2e4 Use enumerated_array for indexing player input controls 2022-02-27 14:23:53 +00:00
Kp 165d5b892b Rename pitch -> pitch_ud for consistency
Other code uses pitch_ud.  Rename the kconfig pitch to match.
2022-02-27 14:23:53 +00:00
Kp 43bdfac56a Store copy_sensitivity values as std::integral_constant
Lists of these objects are unrolled by a template parameter pack
regardless of whether they are type compatible, so keeping the types
compatible does not improve code size.  Store more precise types in the
structure, and avoid needing to store the constant values into a
structure at runtime.
2022-02-27 14:23:53 +00:00
Kp e7fd31e3a6 Check return value of find_connect_side in more places 2022-02-19 14:52:17 +00:00
Kp 52403f104f Use symbolic sidenum values in Edge_to_sides 2022-02-19 14:52:17 +00:00
Kp 5611319962 Qualify references to sidenum_t members 2022-02-19 14:52:17 +00:00
Kp 68268e9a1f Use sidenum_t in more places 2022-02-19 14:52:17 +00:00
Kp 91c9055c90 Simplify do_endlevel_flythrough computation of next distance 2022-02-19 14:52:17 +00:00
Kp 2fe9a16613 Use dedicated type for mask of segment side numbers 2022-02-19 14:52:17 +00:00
Kp 8c037b7c26 Split player start generation
Move some of the logic to a separate function to enable use of `return`
instead of a `break` from a composite loop.
2022-02-19 14:52:17 +00:00
Kp f2832e6248 Simplify _sockaddr IPv4/IPv6 logic
- Use std::integral_constant instead of a static function that returns
  the value
- Remove unused protocol_family
- Replace the enum with a typedef for the one type that the enum was
  used to define
2022-02-12 18:57:12 +00:00
Kp 8be306efa7 Use enum class for cockpit_mode_t 2022-02-12 18:57:12 +00:00
Kp f9c876572f Use std::move to compact Netgame.players on quit-joining 2022-02-12 18:57:12 +00:00
Kp 8fa4e6aa46 Simplify net_udp_welcome_player test order
Move the test for closed up, to avoid re-testing it.
2022-02-06 16:12:31 +00:00
Kp fe19f78fcd Simplify some uses of Highest_object_index 2022-02-06 16:12:31 +00:00
Kp da49df78f7 Split drop_powerup to return either an object id or a success code
If exactly one object will always be needed, use an overload that
returns the object id.  Otherwise, use an overload that only returns
whether at least one object was created.  This simplifies callers that
always request exactly one object.
2022-02-06 16:12:31 +00:00
Kp 04f0507942 Fix memory corruption if spit_powerup fails to drop a weapon
If spit_powerup fails, it returns object_none.  object_none is not a
valid index for use by map_objnum_local_to_remote.
2022-02-06 16:12:31 +00:00
Kp d5e520bc7b Fix failure to send robot creation message if one creation fails
If at least two robots would be dropped, and a drop failed, then
object_create_robot_egg would report failure to the caller.  Callers
that check the return code treat any failure as total failure, but that
is not guaranteed to be true.  If the game successfully dropped one
robot and failed when dropping a second, then the caller would receive a
status of failure.

Fix this by returning a status of whether at least one object was
created.
2022-02-06 16:12:31 +00:00
Kp 4a85b55865 Factor out drop_player_eggs creation of vulcan/gauss weapons 2022-02-06 16:12:31 +00:00
Kp 1a9fba804d Avoid repeated valptridx dereferences in multibot.cpp 2022-02-05 13:30:56 +00:00
Kp 1ad3377a83 Pass context to start_boss_death_sequence 2022-02-05 13:30:56 +00:00
Kp 29d6072f60 Pass context to drop_stolen_items 2022-02-05 13:30:56 +00:00
Kp 60c5fc5dc4 Pass object& to multi_drop_robot_powerups 2022-02-05 13:30:56 +00:00
Kp 6cc788e1cd Pass object_base& to object_create_robot_egg 2022-02-05 13:30:56 +00:00
Kp a0be091cd0 Avoid repeated valptridx dereferences in player_is_visible_from_object 2022-02-05 13:30:56 +00:00