Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Version 1.9.0 (not released yet)
- Add `version` command
- Support autocompleting of level filenames and console commands from only 1 character
- Add support for `bluebeard.bty` (sound config file) in mods
- Add `spectate_mode_follow_killer` command (when player you are spectating dies, spectate their killer)
- Remove level editor popups that stop user from navigating between modes until rebuilding

[@is-this-c](https://github.com/is-this-c)
Expand Down
23 changes: 23 additions & 0 deletions game_patch/hud/multi_spectate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static rf::Player* g_spectate_mode_target;
static rf::Camera* g_old_target_camera = nullptr;
static bool g_spectate_mode_enabled = false;
static bool g_spawned_in_current_level = false;
static bool g_spectate_mode_follow_killer = false;

void player_fpgun_set_player(rf::Player* pp);

Expand Down Expand Up @@ -203,6 +204,18 @@ bool multi_spectate_execute_action(rf::ControlConfigAction action, bool was_pres
return false;
}

void multi_spectate_on_player_kill(rf::Player* victim, rf::Player* killer)
{
if (!g_spectate_mode_enabled) {
return;
}
if (g_spectate_mode_follow_killer && g_spectate_mode_target == victim && killer != rf::local_player) {
// spectate killer if we were spectating victim
// avoid spectating ourselves if we somehow managed to kill the victim
multi_spectate_set_target_player(killer);
}
}

void multi_spectate_on_destroy_player(rf::Player* player)
{
if (player != rf::local_player) {
Expand Down Expand Up @@ -272,6 +285,15 @@ static ConsoleCommand2 spectate_mode_minimal_ui_cmd{
"Toggles spectate mode minimal UI",
};

static ConsoleCommand2 spectate_mode_follow_killer_cmd{
"spectate_mode_follow_killer",
[]() {
g_spectate_mode_follow_killer = !g_spectate_mode_follow_killer;
rf::console::printf("Follow killer mode is %s", g_spectate_mode_follow_killer ? "enabled" : "disabled");
},
"When a player you're spectating dies, automatically spectate their killer",
};

#if SPECTATE_MODE_SHOW_WEAPON

static void player_render_new(rf::Player* player)
Expand Down Expand Up @@ -322,6 +344,7 @@ void multi_spectate_appy_patch()

spectate_cmd.register_cmd();
spectate_mode_minimal_ui_cmd.register_cmd();
spectate_mode_follow_killer_cmd.register_cmd();

// Note: HUD rendering doesn't make sense because life and armor isn't synced

Expand Down
1 change: 1 addition & 0 deletions game_patch/hud/multi_spectate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void multi_spectate_appy_patch();
void multi_spectate_after_full_game_init();
void multi_spectate_level_init();
void multi_spectate_render();
void multi_spectate_on_player_kill(rf::Player* player, rf::Player* killer);
void multi_spectate_on_destroy_player(rf::Player* player);
void multi_spectate_player_create_entity_post(rf::Player* player, rf::Entity* entity);
bool multi_spectate_is_spectating();
Expand Down
3 changes: 3 additions & 0 deletions game_patch/multi/kill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../rf/localize.h"
#include "../rf/multi.h"
#include "../rf/weapon.h"
#include "../hud/multi_spectate.h"
#include "server_internal.h"

bool kill_messages = true;
Expand Down Expand Up @@ -148,6 +149,8 @@ void on_player_kill(rf::Player* killed_player, rf::Player* killer_player)
}

multi_apply_kill_reward(killer_player);

multi_spectate_on_player_kill(killed_player, killer_player);
}
}

Expand Down