Skip to content

Commit 352a41e

Browse files
is-this-cGooberRFrafalh
authored
Add a spawned player count to the scoreboard (#316)
* Add player count to scoreboard in all gamemodes * replace "WITH" with pipe * Add spawned players to the scoreboard * Update CHANGELOG.md * Update gr_font.cpp * Update multi_scoreboard.cpp * Update multi.h * Update multi_scoreboard.cpp * Update multi.h * Update multi.{cpp,h} * Update multi_scoreboard.cpp * Update multi.{cpp,h} * Inline closure * Update multi.h * Update multi_scoreboard.cpp * Update multi.cpp * Update multi.{cpp,h} * Update multi_scoreboard.cpp * Update multi.cpp --------- Co-authored-by: Goober <[email protected]> Co-authored-by: Rafał Harabień <[email protected]>
1 parent 8b892d8 commit 352a41e

File tree

6 files changed

+42
-11
lines changed

6 files changed

+42
-11
lines changed

docs/CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Version 1.9.0 (not released yet)
5454
[@GooberRF](https://github.com/GooberRF)
5555
- Fix crash when `verify_level` command is run without a level being loaded
5656
- Fix cockpit not rendering for any jeeps after the first one entered each level load
57+
- Add current server player count to scoreboard
5758
- Add `server_password` command
5859
- Add `$DF CTF Flag Return Time` option in dedicated server config
5960
- Add mod name to main menu
@@ -65,10 +66,11 @@ Version 1.9.0 (not released yet)
6566
- Remove level editor popups that stop user from navigating between modes until rebuilding
6667

6768
[@is-this-c](https://github.com/is-this-c)
68-
- Support `©` in TrueType fonts
69+
- Support `©` and `` in TrueType fonts
6970
- Improve frag message format
7071
- Search command descriptions in `.` command
7172
- Improve PF network protocol compatibility
73+
- Add a spawned player count to the scoreboard
7274

7375
[@Mystyle-48](https://github.com/Mystyle-48)
7476
- Simplify installation detection in setup and launcher

game_patch/graphics/gr_font.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ GrNewFont::GrNewFont(std::string_view name) :
250250
static std::pair<int, int> win_1252_char_ranges[]{
251251
{0x20, 0x7E},
252252
{0x8C, 0x8C},
253+
{0x95, 0x95},
253254
{0x99, 0x99},
254255
{0x9C, 0x9C},
255256
{0x9F, 0x9F},

game_patch/hud/multi_scoreboard.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,13 @@ int draw_scoreboard_header(int x, int y, int w, rf::NetGameType game_type, bool
5353

5454
// Draw Game Type name
5555
if (!dry_run) {
56-
const char* game_type_name;
57-
if (game_type == rf::NG_TYPE_DM)
58-
game_type_name = rf::strings::deathmatch;
59-
else if (game_type == rf::NG_TYPE_CTF)
60-
game_type_name = rf::strings::capture_the_flag;
61-
else
62-
game_type_name = rf::strings::team_deathmatch;
63-
rf::gr::string_aligned(rf::gr::ALIGN_CENTER, x_center, cur_y, game_type_name);
56+
const std::string game_info = std::format(
57+
"{} \x95 {}/{} PLAYING",
58+
multi_game_type_name(game_type),
59+
multi_num_alive_players(),
60+
rf::multi_num_players()
61+
);
62+
rf::gr::string_aligned(rf::gr::ALIGN_CENTER, x_center, cur_y, game_info.c_str());
6463
}
6564
int font_h = rf::gr::get_font_height(-1);
6665
cur_y += font_h + 8;

game_patch/multi/multi.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
#include <algorithm>
12
#include <regex>
23
#include <xlog/xlog.h>
34
#include <winsock2.h>
5+
#include <common/utils/list-utils.h>
46
#include <patch_common/FunHook.h>
57
#include <patch_common/CodeInjection.h>
68
#include <patch_common/AsmWriter.h>
@@ -14,6 +16,8 @@
1416
#include "../rf/os/console.h"
1517
#include "../rf/weapon.h"
1618
#include "../rf/entity.h"
19+
#include "../rf/player/player.h"
20+
#include "../rf/localize.h"
1721
#include "../rf/ai.h"
1822
#include "../rf/item.h"
1923

@@ -332,6 +336,28 @@ void multi_init_player(rf::Player* player)
332336
multi_kill_init_player(player);
333337
}
334338

339+
std::string_view multi_game_type_name(const rf::NetGameType game_type) {
340+
if (game_type == rf::NG_TYPE_DM) {
341+
return std::string_view{rf::strings::deathmatch};
342+
} else if (game_type == rf::NG_TYPE_CTF) {
343+
return std::string_view{rf::strings::capture_the_flag};
344+
} else {
345+
if (game_type != rf::NG_TYPE_TEAMDM) {
346+
xlog::warn(
347+
"`multi_game_type_name`: {} is an invalid `NetGameType`",
348+
static_cast<int>(game_type)
349+
);
350+
}
351+
return std::string_view{rf::strings::team_deathmatch};
352+
}
353+
};
354+
355+
int multi_num_alive_players() {
356+
return std::ranges::count_if(SinglyLinkedList{rf::player_list}, [] (const auto& p) {
357+
return !rf::player_is_dead(&p) && !rf::player_is_dying(&p);
358+
});
359+
}
360+
335361
void multi_do_patch()
336362
{
337363
multi_limbo_init.install();

game_patch/multi/multi.h

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <optional>
44
#include "../rf/player/player.h"
5+
#include "../rf/multi.h"
56

67
struct PlayerStatsNew : rf::PlayerLevelStats
78
{
@@ -90,3 +91,5 @@ void multi_level_download_do_frame();
9091
void multi_level_download_abort();
9192
void multi_ban_apply_patch();
9293
std::optional<std::string> multi_ban_unban_last();
94+
std::string_view multi_game_type_name(rf::NetGameType game_type);
95+
[[nodiscard]] int multi_num_alive_players();

game_patch/rf/player/player.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ namespace rf
163163
static auto& local_player = addr_as_ref<Player*>(0x007C75D4);
164164

165165
static auto& player_from_entity_handle = addr_as_ref<Player*(int entity_handle)>(0x004A3740);
166-
static auto& player_is_dead = addr_as_ref<bool(Player *player)>(0x004A4920);
167-
static auto& player_is_dying = addr_as_ref<bool(Player *player)>(0x004A4940);
166+
static auto& player_is_dead = addr_as_ref<bool(const Player *player)>(0x004A4920);
167+
static auto& player_is_dying = addr_as_ref<bool(const Player *player)>(0x004A4940);
168168
static auto& player_add_score = addr_as_ref<void(Player *player, int delta)>(0x004A7460);
169169
static auto& player_get_ai = addr_as_ref<AiInfo*(Player *player)>(0x004A3260);
170170
static auto& player_get_weapon_total_ammo = addr_as_ref<int(Player *player, int weapon_type)>(0x004A3280);

0 commit comments

Comments
 (0)