Debian Codegraph @

netgames/dmfc/dmfcstats.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/Dmfc/dmfcstats.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003/08/26 03:57:21 $
23 * $Author: kevinb $
24 *
25 * Functions for in-game stats system
26 *
27 * $Log: dmfcstats.cpp,v $
28 * Revision 1.1.1.1 2003/08/26 03:57:21 kevinb
29 * initial 1.5 import
30 *
31 *
32 * 34 10/26/99 10:32a Jeff
33 * fixed COM interface bug
34 *
35 * 33 9/03/99 5:48p Jeff
36 * fixed crash if the stats is brought up before all player records are
37 * recieved
38 *
39 * 32 7/14/99 11:48a Jeff
40 * localized text for patch fixes
41 *
42 * 31 7/11/99 6:09p Jeff
43 * for team games (or where the divide up by teams flag is set), process
44 * everyone in the game and display them, before the disconnected people,
45 * so everyone is displayed.
46 *
47 * 30 7/09/99 6:17p Jeff
48 * fixed bugs when scrolling down in a dedicated server game
49 *
50 * 29 7/06/99 11:47p Jeff
51 * selected pilot when stats are enabled is yourself, not server
52 *
53 * 28 5/23/99 3:04a Jason
54 * fixed bug with player rankings not being updated correctly
55 *
56 * 27 5/22/99 1:12a Jeff
57 * correctly handle Viewer_object
58 *
59 * 26 5/19/99 5:26p Jeff
60 * fixed crash trying to view stats before getting player records from
61 * server
62 *
63 * 25 5/13/99 4:55p Ardussi
64 * changes for compiling on the Mac
65 *
66 * 24 5/03/99 12:07p Jeff
67 * safety precautions
68 *
69 * 23 3/29/99 7:20p Jeff
70 * added vis stuff for coop stat views
71 *
72 * 22 3/27/99 4:53p Jeff
73 * player rankings in multiplayer games implemented. Fixed join message
74 * so it doesn't get cut off
75 *
76 * 21 3/17/99 12:25p Jeff
77 * converted DMFC to be COM interface
78 *
79 * 20 3/05/99 1:30p Jeff
80 * fixed 99% of the high res issues
81 *
82 * 19 2/11/99 12:51a Jeff
83 * changed names of exported variables
84 *
85 * 18 2/08/99 7:49p Jeff
86 * removed calls to get frame parameters (function is dead..pending
87 * removal)
88 *
89 * 17 2/08/99 5:22p Jeff
90 * exported rend_SetZBuffer...fixed up small view of stats
91 *
92 * 16 2/08/99 12:06a Jeff
93 * some new flags for more configuration. Added an option to see from a
94 * player's view
95 *
96 * 15 2/06/99 6:59p Jeff
97 * created RenderHUDGetTextLineWidth and RenderHUDGetTextHeight
98 *
99 * 14 1/31/99 7:26p Matt
100 * Renamed a bunch of functions to have HUD capitalized
101 *
102 * 13 1/24/99 8:31p Jeff
103 * updated stat manager to show team information
104 *
105 * 12 1/20/99 8:07p Jeff
106 * disconnected players in color mode team show up as grey
107 *
108 * 11 1/19/99 3:55a Jeff
109 * all strings localized out
110 *
111 * 10 1/16/99 2:55p Jeff
112 * possibly fixed some stat manager bugs...needs testing
113 *
114 * 9 1/13/99 4:36p Jeff
115 * fixed scroll bug
116 *
117 * 8 1/07/99 5:01p Jeff
118 * added Int3's and updated all net games to use stats manager...correctly
119 * too
120 *
121 * 7 1/04/99 12:21p Jeff
122 * added support for hosts.allow/deny and updates stats manager a little
123 *
124 * 6 12/08/98 4:47p Jeff
125 * umm, various changes, fixed pilot pics so that they work for everyone
126 * now
127 *
128 * 5 12/08/98 3:29p Jeff
129 * updated the team control dialog so the server can determine if they
130 * want to make the clients wait
131 *
132 * 4 12/08/98 12:17p Jeff
133 * various changes that include an improved Team Control dialog (doesn't
134 * switch teams until exit..) and spew/respawn players that change teams
135 *
136 * 3 12/04/98 7:04p Jeff
137 * almost finished up dmfc stat manager
138 *
139 * 2 12/03/98 7:05p Jeff
140 * updated new stats
141 *
142 * $NoKeywords: $
143 */
144
145 #include "gamedll_header.h"
146 #include "DMFC.h"
147 #include "dmfcinternal.h"
148
149
150 #include <algorithm>
151
152 extern DMFCBase *basethis;
153 extern player_record Player_records[MAX_PLAYER_RECORDS];
154
155 #define ROW_PIXEL_GAP 2
156 #define PAGE_DISP_TIME 2.0f
157 #define ALPHA_IN_TIME 0.4f
158
159 #define PLIST_WIN_W 400
160 #define PLIST_WIN_H 440
161 #define PLIST_WIN_X 10
162 #define PLIST_WIN_Y 20
163 #define DLIST_WIN_W 210
164 #define DLIST_WIN_H 440
165 #define DLIST_WIN_X PLIST_WIN_W + PLIST_WIN_X + 10
166 #define DLIST_WIN_Y 20
167
168 // constructor
169 CDmfcStats::CDmfcStats() {
170 m_cPtrs = 0;
171 m_init = false;
172 m_flags = 0;
173 m_SortedPRecs = NULL;
174 m_pMaxNumberDisplayed = NULL;
175 m_MaxCount = 0;
176 m_iPLColCount = 0;
177 m_iDColCount = 0;
178 m_PLColInfo = NULL;
179 m_DColInfo = NULL;
180 m_PLColCallback = NULL;
181 m_DColCallback = NULL;
182 m_PLColCallbackBMP = NULL;
183 m_DColCallbackBMP = NULL;
184 m_TeamCallback = NULL;
185 m_GameName = NULL;
186 m_top_index = 0;
187 m_selected_index = 0;
188 m_bottom_index = -1;
189 m_enabled = false;
190 m_font_height = 0;
191 m_y_start_plist = 0;
192 m_y_start_detail = 0;
193 m_x_start_plist = 0;
194 m_x_start_detail = 0;
195 m_selected_prec = 0;
196 m_highlight_bmp = BAD_BITMAP_HANDLE;
197 m_background_bmp = BAD_BITMAP_HANDLE;
198 m_page_index = 0;
199 m_can_fit_count = -1;
200 m_page_display_time = 0;
201 m_has_multiple_pages = false;
202 m_alpha = 0;
203 alpha_in_time = 0;
204 }
205
206 // destructor
207 CDmfcStats::~CDmfcStats() {
208 if (m_GameName) {
209 free(m_GameName);
210 }
211 if (m_PLColInfo) {
212 free(m_PLColInfo);
213 }
214 if (m_DColInfo) {
215 free(m_DColInfo);
216 }
217
218 if (m_highlight_bmp > BAD_BITMAP_HANDLE)
219 DLLbm_FreeBitmap(m_highlight_bmp);
220
221 if (m_background_bmp > BAD_BITMAP_HANDLE)
222 DLLbm_FreeBitmap(m_background_bmp);
223 }
224
225 // initialization member function
226 bool CDmfcStats::Initialize(tDmfcStatsInit *init_info) {
227 m_font_height = DLLgrfont_GetHeight(basethis->Game_fonts[HUD_FONT_INDEX]);
228 // m_font_height = DLLRenderHUDGetTextHeight("X");
229 m_flags = init_info->flags;
230 m_SortedPRecs = init_info->SortedPlayerRecords;
231 if (!m_SortedPRecs)
232 goto error_init;
233 m_pMaxNumberDisplayed = init_info->MaxNumberDisplayed;
234 if ((m_flags & DSIF_ONLY_X_PLAYERS_SHOWN) && (!m_pMaxNumberDisplayed))
235 goto error_init;
236
237 m_PLColCallback = init_info->clbPlayerColumn;
238 m_DColCallback = init_info->clbDetailedColumn;
239 m_PLColCallbackBMP = init_info->clbPlayerColumnBMP;
240 m_DColCallbackBMP = init_info->clbDetailedColumnBMP;
241 m_TeamCallback = init_info->clTeamLine;
242
243 m_iPLColCount = init_info->cColumnCountPlayerList;
244 m_iDColCount = init_info->cColumnCountDetailed;
245
246 if (m_iPLColCount > 0 && !init_info->PlayerListColumns)
247 goto error_init;
248
249 if (m_iDColCount > 0 && !init_info->DetailedColumns)
250 goto error_init;
251
252 if (m_iPLColCount > 0) {
253 m_PLColInfo = (tDmfcStatsColumnInfo *)malloc(sizeof(tDmfcStatsColumnInfo) * m_iPLColCount);
254 if (!m_PLColInfo)
255 goto error_init;
256 memcpy(m_PLColInfo, init_info->PlayerListColumns, sizeof(tDmfcStatsColumnInfo) * m_iPLColCount);
257 }
258
259 if (m_iDColCount > 0) {
260 m_DColInfo = (tDmfcStatsColumnInfo *)malloc(sizeof(tDmfcStatsColumnInfo) * m_iDColCount);
261 if (!m_DColInfo) {
262 goto error_init;
263 }
264 memcpy(m_DColInfo, init_info->DetailedColumns, sizeof(tDmfcStatsColumnInfo) * m_iDColCount);
265 }
266
267 if (init_info->GameName) {
268 m_GameName = strdup(init_info->GameName);
269 }
270
271 m_y_start_plist = PLIST_WIN_Y + 2 * (m_font_height + ROW_PIXEL_GAP);
272 m_y_start_detail = DLIST_WIN_Y + (m_font_height + ROW_PIXEL_GAP);
273 m_x_start_plist = PLIST_WIN_X;
274 m_x_start_detail = DLIST_WIN_X;
275
276 m_highlight_bmp = DLLbm_AllocBitmap(32, 32, 0);
277 m_background_bmp = DLLbm_AllocBitmap(32, 32, 0);
278 uint16_t *data;
279
280 if (m_highlight_bmp == -1)
281 m_highlight_bmp = BAD_BITMAP_HANDLE;
282 if (m_background_bmp == -1)
283 m_background_bmp = BAD_BITMAP_HANDLE;
284
285 if (m_highlight_bmp > BAD_BITMAP_HANDLE) {
286 data = DLLbm_data(m_highlight_bmp, 0);
287 for (int x = 0; x < 32 * 32; x++) {
288 data[x] = GR_RGB16(50, 50, 50) | OPAQUE_FLAG;
289 }
290 }
291
292 if (m_background_bmp > BAD_BITMAP_HANDLE) {
293 data = DLLbm_data(m_background_bmp, 0);
294 for (int x = 0; x < 32 * 32; x++) {
295 data[x] = GR_RGB16(0, 0, 0) | OPAQUE_FLAG;
296 }
297 }
298
299 m_init = true;
300 return true;
301
302 error_init:
303 if (m_GameName) {
304 free(m_GameName);
305 }
306 if (m_PLColInfo) {
307 free(m_PLColInfo);
308 }
309 if (m_DColInfo) {
310 free(m_DColInfo);
311 }
312 return false;
313 }
314
315 //=================================
316
317 // enables/disables the displaying of the stats screen
318 void CDmfcStats::Enable(bool enable) {
319 m_enabled = enable;
320 if (enable) {
321 player_record *pr = PRec_GetPRecordByPnum(basethis->GetPlayerNum());
322 if (pr && pr->state != STATE_EMPTY) {
323 m_selected_prec = pr - Player_records;
324 } else {
325 m_selected_prec = 0;
326 }
327 alpha_in_time = 0;
328 m_alpha = 0;
329 m_page_index = 0;
330 m_can_fit_count = -1;
331 m_page_display_time = 0;
332 m_has_multiple_pages = false;
333
334 basethis->Players[basethis->GetPlayerNum()].small_dll_obj = -1;
335 if (m_flags & DSIF_SHOWPLAYERVIEW) {
336 player_record *pr = basethis->GetPlayerRecord(m_selected_prec);
337 if (pr && pr->state == STATE_INGAME) {
338 basethis->Players[basethis->GetPlayerNum()].small_dll_obj = basethis->Players[pr->pnum].objnum;
339 }
340 }
341 } else {
342 basethis->Players[basethis->GetPlayerNum()].small_dll_obj = -1;
343 }
344 }
345
346 // returns the state of the stats manager
347 bool CDmfcStats::IsEnabled() { return m_enabled; }
348
349 // scrolls the player list down one
350 void CDmfcStats::ScrollDown() {
351 if (CanScrollDown()) {
352
353 if (m_flags & DSIF_SEPERATE_BY_TEAM) {
354 // we need to handle team stats a bit different
355 // we must state on connected people until no more
356 // connected people exist, then go through the list
357 // through disconnected people
358 player_record *pr = basethis->GetPlayerRecord(m_selected_prec);
359 if (!pr || pr->state == STATE_EMPTY) {
360 m_selected_index++;
361 m_selected_prec = m_translate[m_selected_index];
362 } else {
363 bool isingame = (pr->state == STATE_INGAME) ? true : false;
364
365 while (1) {
366 m_selected_index++;
367 if (m_selected_index == (m_MaxCount - 1)) {
368 // we hit the bottom
369 m_selected_prec = m_translate[m_selected_index];
370
371 if (!isingame)
372 break; // we have gotten to the bottom of everyone
373
374 pr = basethis->GetPlayerRecord(m_selected_prec);
375
376 // check to see if we want this player
377 if (pr->state == STATE_INGAME)
378 break;
379
380 // now go through the disconnected folk
381 isingame = false;
382 m_selected_index = -1; // set to -1, since it will be incremented right away
383 continue;
384 }
385
386 m_selected_prec = m_translate[m_selected_index];
387 pr = basethis->GetPlayerRecord(m_selected_prec);
388
389 if (!pr || pr->state == STATE_EMPTY)
390 continue;
391
392 // should we use this player?
393 if (isingame) {
394 if (pr->state != STATE_INGAME)
395 continue; // move to the next
396 } else {
397 if (pr->state != STATE_DISCONNECTED)
398 continue; // move to the next
399 }
400
401 // all matches up if we haven't continue by here
402 break;
403 }
404 }
405 } else {
406 m_selected_index++;
407 m_selected_prec = m_translate[m_selected_index];
408 }
409
410 m_page_index = 0;
411 m_can_fit_count = -1;
412 m_page_display_time = 0;
413 m_has_multiple_pages = false;
414
415 basethis->Players[basethis->GetPlayerNum()].small_dll_obj = -1;
416 if (m_flags & DSIF_SHOWPLAYERVIEW) {
417 player_record *pr = basethis->GetPlayerRecord(m_selected_prec);
418 if (pr && pr->state == STATE_INGAME) {
419 basethis->Players[basethis->GetPlayerNum()].small_dll_obj = basethis->Players[pr->pnum].objnum;
420 }
421 }
422 }
423 }
424
425 // scrolls the player list up one
426 void CDmfcStats::ScrollUp() {
427 if (CanScrollUp()) {
428 if (m_flags & DSIF_SEPERATE_BY_TEAM) {
429 // we need to handle team stats a bit different
430 // we must state on connected people until no more
431 // connected people exist, then go through the list
432 // through disconnected people
433 player_record *pr = basethis->GetPlayerRecord(m_selected_prec);
434 if (!pr || pr->state == STATE_EMPTY) {
435 m_selected_index--;
436 m_selected_prec = m_translate[m_selected_index];
437 } else {
438 bool isingame = (pr->state == STATE_INGAME) ? true : false;
439
440 while (1) {
441 m_selected_index--;
442 if (m_selected_index == 0) {
443 // we hit the top
444 m_selected_prec = m_translate[m_selected_index];
445
446 if (isingame)
447 break; // we have gotten to the top of everyone
448
449 pr = basethis->GetPlayerRecord(m_selected_prec);
450
451 // check to see if we want this player
452 if (pr->state == STATE_DISCONNECTED)
453 break;
454
455 // now go through the connected folk
456 isingame = true;
457 m_selected_index = m_MaxCount; // set to m_MaxCount, since it will be incremented right away
458 continue;
459 }
460
461 m_selected_prec = m_translate[m_selected_index];
462 pr = basethis->GetPlayerRecord(m_selected_prec);
463
464 if (!pr || pr->state == STATE_EMPTY)
465 continue;
466
467 // should we use this player?
468 if (isingame) {
469 if (pr->state != STATE_INGAME)
470 continue; // move to the next
471 } else {
472 if (pr->state != STATE_DISCONNECTED)
473 continue; // move to the next
474 }
475
476 // all matches up if we haven't continue by here
477 break;
478 }
479 }
480 } else {
481 m_selected_index--;
482 m_selected_prec = m_translate[m_selected_index];
483 }
484
485 m_page_index = 0;
486 m_can_fit_count = -1;
487 m_page_display_time = 0;
488 m_has_multiple_pages = false;
489
490 basethis->Players[basethis->GetPlayerNum()].small_dll_obj = -1;
491 if (m_flags & DSIF_SHOWPLAYERVIEW) {
492 player_record *pr = basethis->GetPlayerRecord(m_selected_prec);
493 if (pr && pr->state == STATE_INGAME) {
494 basethis->Players[basethis->GetPlayerNum()].small_dll_obj = basethis->Players[pr->pnum].objnum;
495 }
496 }
497 }
498 }
499
500 // returns true if the player list can scroll down any more
501 bool CDmfcStats::CanScrollDown() { return (m_selected_index < (m_MaxCount - 1)) ? true : false; }
502
503 // returns true if the player list can scroll up any more
504 bool CDmfcStats::CanScrollUp() { return (bool)(m_selected_index > 0); }
505
506 void drawline(int lx, int rx, int y, float perc) {
507 int width = ((float)(rx - lx)) * perc;
508 int center = lx + (rx - lx) / 2;
509
510 width = width / 2;
511 lx = center - width;
512 rx = center + width;
513
514 /*
515 rx = lx + width;
516 */
517
518 int ny = y;
519 basethis->ConvertHUDCoord(lx, y, &lx, &y);
520 basethis->ConvertHUDCoord(rx, ny, &rx, &ny);
521 DLLrend_DrawLine(lx, y, rx, ny);
522 }
523
524 // renders the stats screen
525 void CDmfcStats::Render() {
526 int i, c, curr_x, curr_y;
527 player_record *pr;
528 char buffer[256];
529 DLLrend_SetFlatColor(GR_WHITE);
530 float perc_done = (alpha_in_time < ALPHA_IN_TIME) ? (alpha_in_time / ALPHA_IN_TIME) : 1.0f;
531 bool need_to_display_observer_icon;
532 bool is_dedicated_server;
533 int last_team = -1;
534 int teams_displayed = 0;
535 bool team_disp[DLLMAX_TEAMS];
536
537 for (i = 0; i < DLLMAX_TEAMS; i++) {
538 team_disp[i] = false;
539 }
540
541 // render all the player list columns
542 curr_x = m_x_start_plist;
543 curr_y = PLIST_WIN_Y + 1;
544
545 // render window and headings
546 DLLRenderHUDQuad(PLIST_WIN_X, PLIST_WIN_Y, PLIST_WIN_W, PLIST_WIN_H, 0, 0, 1, 1, m_background_bmp, perc_done * 200.0f,
547 0);
548
549 DLLgrtext_SetFont(basethis->Game_fonts[HUD_FONT_INDEX]);
550 int l_width = DLLRenderHUDGetTextLineWidth(m_GameName);
551 DLLRenderHUDText(GR_WHITE, m_alpha, 0, (PLIST_WIN_W / 2) - (l_width / 2), curr_y, m_GameName);
552 curr_y += (m_font_height + ROW_PIXEL_GAP);
553 for (c = 0; c < m_iPLColCount; c++) {
554 strcpy(buffer, m_PLColInfo[c].title);
555 basethis->ClipString(m_PLColInfo[c].width, buffer, false);
556 DLLRenderHUDText(GR_WHITE, m_alpha, 0, curr_x, curr_y, buffer);
557 curr_x += m_PLColInfo[c].width;
558 }
559 curr_y += (m_font_height + (ROW_PIXEL_GAP) / 2);
560 if (m_iPLColCount > 0)
561 drawline(PLIST_WIN_X, PLIST_WIN_X + PLIST_WIN_W - 1, curr_y, perc_done);
562
563 curr_x = m_x_start_plist;
564 curr_y = m_y_start_plist + 4;
565
566 bool displaying_in_game_players = true;
567 bool not_overflowing = true;
568 bool update_bottom_index = true;
569
570 redisplay_list:
571
572 for (i = m_top_index; i < m_MaxCount; i++) {
573 pr = PRec_GetPRecord(m_translate[i]);
574
575 if (!pr || pr->state == STATE_EMPTY)
576 continue;
577
578 if (m_flags & DSIF_SEPERATE_BY_TEAM) {
579 // for team games we seperate disconnected and ingame people
580 if (displaying_in_game_players) {
581 // filter out non-ingame players
582 if (pr->state != STATE_INGAME)
583 continue;
584 } else {
585 // filter out non-disconnected players
586 if (pr->state != STATE_DISCONNECTED)
587 continue;
588 }
589 }
590
591 is_dedicated_server = basethis->IsPlayerDedicatedServer(pr);
592
593 if ((m_flags & DSIF_SEPERATE_BY_TEAM) && (last_team != pr->team) && !is_dedicated_server) {
594 i--; // this line doesn't count
595 last_team = pr->team;
596 buffer[0] = '\0';
597
598 if (!team_disp[last_team]) {
599 teams_displayed++;
600 team_disp[last_team] = true;
601 }
602
603 if (m_TeamCallback) {
604 snprintf(buffer, sizeof(buffer), DTXT_TEAMLABEL, basethis->GetTeamString(pr->team));
605 int length = strlen(buffer);
606 buffer[length] = ' '; // lose the \0
607
608 (*m_TeamCallback)(pr->team, &buffer[length], sizeof(buffer) - length - 1);
609 buffer[sizeof(buffer) - 1] = '\0';
610
611 int width = (PLIST_WIN_X + PLIST_WIN_W - curr_x - 5);
612 float ratio = DEFAULT_HUD_WIDTH / ((float)*basethis->Game_window_w);
613
614 // clip the string to the width
615 basethis->ClipString(width, buffer, false);
616
617 int l = ratio * ((float)DLLRenderHUDGetTextLineWidth(buffer));
618 int x = (width / 2) - (l / 2);
619
620 DLLRenderHUDText(basethis->GetTeamColor(pr->team), m_alpha, 0, x, curr_y, buffer);
621 }
622
623 goto skip_line; // don't process this line
624 }
625
626 // draw the highlight bar if selected bitmap
627 if (m_selected_index == i) {
628 DLLRenderHUDQuad(m_x_start_plist, curr_y, PLIST_WIN_W, m_font_height, 0, 0, 1, 1, m_highlight_bmp,
629 perc_done * 128.0f, 0);
630 }
631
632 need_to_display_observer_icon =
633 (pr->state == STATE_INGAME) ? (basethis->IsPlayerObserver(pr->pnum) ? true : false) : false;
634
635 for (c = 0; c < m_iPLColCount; c++) {
636 buffer[0] = '\0';
637
638 if (!is_dedicated_server || m_PLColInfo[c].type == DSCOL_PILOT_NAME || m_PLColInfo[c].type == DSCOL_BLANK) {
639 switch (m_PLColInfo[c].type) {
640 case DSCOL_BMP:
641 break;
642 case DSCOL_KILLS_LEVEL:
643 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.kills[DSTAT_LEVEL]);
644 break;
645 case DSCOL_KILLS_OVERALL:
646 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.kills[DSTAT_OVERALL]);
647 break;
648 case DSCOL_KILLS_BOTH:
649 snprintf(buffer, sizeof(buffer), "%d[%d]", pr->dstats.kills[DSTAT_LEVEL], pr->dstats.kills[DSTAT_OVERALL]);
650 break;
651 case DSCOL_DEATHS_LEVEL:
652 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.deaths[DSTAT_LEVEL]);
653 break;
654 case DSCOL_DEATHS_OVERALL:
655 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.deaths[DSTAT_OVERALL]);
656 break;
657 case DSCOL_DEATHS_BOTH:
658 snprintf(buffer, sizeof(buffer), "%d[%d]", pr->dstats.deaths[DSTAT_LEVEL], pr->dstats.deaths[DSTAT_OVERALL]);
659 break;
660 case DSCOL_SUICIDES_LEVEL:
661 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.suicides[DSTAT_LEVEL]);
662 break;
663 case DSCOL_SUICIDES_OVERALL:
664 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.suicides[DSTAT_OVERALL]);
665 break;
666 case DSCOL_SUICIDES_BOTH:
667 snprintf(buffer, sizeof(buffer), "%d[%d]", pr->dstats.suicides[DSTAT_LEVEL],
668 pr->dstats.suicides[DSTAT_OVERALL]);
669 break;
670 case DSCOL_PILOT_NAME:
671 strcpy(buffer, pr->callsign);
672 break;
673 case DSCOL_PILOT_TEAM:
674 snprintf(buffer, sizeof(buffer), "%s", basethis->GetTeamString(pr->team));
675 break;
676 case DSCOL_PING:
677 if (pr->state == STATE_INGAME)
678 snprintf(buffer, sizeof(buffer), "%.0f", basethis->NetPlayers[pr->pnum].ping_time * 1000.0f);
679 else
680 strcpy(buffer, "N/A");
681 break;
682 case DSCOL_CUSTOM:
683 if (m_PLColCallback)
684 (*m_PLColCallback)(m_translate[i], c, buffer, sizeof(buffer));
685 break;
686 case DSCOL_BLANK:
687 buffer[0] = '\0';
688 break;
689 }
690 } else {
691 strcpy(buffer, "N/A");
692 }
693
694 int width_to_use = m_PLColInfo[c].width;
695
696 if (m_PLColInfo[c].type != DSCOL_BMP) {
697
698 if (need_to_display_observer_icon) {
699 if (m_flags & DSIF_SHOW_OBSERVERICON && m_PLColInfo[c].type == DSCOL_PILOT_NAME) {
700 need_to_display_observer_icon = false;
701 DLLRenderHUDQuad(curr_x, curr_y, m_font_height, m_font_height, 0, 0, 1, 1, basethis->hBitmapObserver,
702 m_alpha, 0);
703 curr_x += m_font_height + 1;
704 width_to_use -= (m_font_height + 1);
705 }
706 }
707
708 // clip the string to the width
709 basethis->ClipString(std::min(width_to_use, (PLIST_WIN_X + PLIST_WIN_W - curr_x - 5)), buffer, false);
710
711 // print out string
712 ddgr_color color;
713 switch (m_PLColInfo[c].color_type) {
714 case DSCOLOR_NORMAL:
715 color = (pr->state == STATE_INGAME) ? GR_GREEN : GR_GREY;
716 break;
717 case DSCOLOR_TEAM:
718 color = (m_PLColInfo[c].type == DSCOL_PILOT_NAME)
719 ? (basethis->GetTeamColor(pr->team))
720 : ((pr->state == STATE_INGAME) ? (basethis->GetTeamColor(pr->team)) : (GR_GREY));
721 break;
722 case DSCOLOR_SHIPCOLOR:
723 color = (pr->state == STATE_INGAME) ? basethis->Player_colors[pr->pnum] : GR_GREY;
724 break;
725 case DSCOLOR_CUSTOM:
726 color = m_PLColInfo[c].color;
727 break;
728 default:
729 color = (pr->state == STATE_INGAME) ? GR_GREEN : GR_GREY;
730 break;
731 };
732
733 DLLRenderHUDText(color, m_alpha, 0, curr_x, curr_y, buffer);
734 } else {
735
736 // we need to draw a custom bitmap
737 (*m_PLColCallbackBMP)(m_translate[i], c, curr_x, curr_y, m_PLColInfo[c].width, m_font_height + ROW_PIXEL_GAP,
738 m_alpha);
739 }
740
741 curr_x += width_to_use;
742
743 if (curr_x > PLIST_WIN_W + PLIST_WIN_X)
744 break; // we can't fit anymore columns
745 }
746
747 // update the bottom index
748 if (update_bottom_index || i > m_bottom_index) {
749 m_bottom_index = i;
750 update_bottom_index = false; // we force an update the first time through
751 }
752 skip_line:
753 curr_x = m_x_start_plist;
754 curr_y += (m_font_height + ROW_PIXEL_GAP);
755
756 if ((curr_y + m_font_height + ROW_PIXEL_GAP) > PLIST_WIN_H + PLIST_WIN_Y) {
757 not_overflowing = false;
758 break; // we are done here
759 }
760 }
761
762 if ((m_flags & DSIF_SEPERATE_BY_TEAM) && displaying_in_game_players && not_overflowing) {
763 // we can continue displaying, but just the disconnected people now
764 last_team = -1; // so we redraw the team names
765 displaying_in_game_players = false;
766
767 // display the disconnected people
768 goto redisplay_list;
769 }
770
771 // Display the remaining teams
772 if ((m_flags & DSIF_SEPERATE_BY_TEAM) && (teams_displayed < DLLMAX_TEAMS) &&
773 ((curr_y + m_font_height + ROW_PIXEL_GAP) < PLIST_WIN_H + PLIST_WIN_Y)) {
774 int tcount = basethis->GetNumTeams();
775 for (i = 0; i < tcount; i++) {
776 if (team_disp[i])
777 continue;
778
779 team_disp[i] = true;
780 last_team = i;
781 buffer[0] = '\0';
782 teams_displayed++;
783
784 if (m_TeamCallback) {
785 snprintf(buffer, sizeof(buffer), DTXT_TEAMLABEL, basethis->GetTeamString(i));
786 int length = strlen(buffer);
787 buffer[length] = ' '; // lose the \0
788
789 (*m_TeamCallback)(i, &buffer[length], sizeof(buffer) - length - 1);
790 buffer[sizeof(buffer) - 1] = '\0';
791
792 int width = (PLIST_WIN_X + PLIST_WIN_W - curr_x - 5);
793 float ratio = DEFAULT_HUD_WIDTH / ((float)*basethis->Game_window_w);
794
795 // clip the string to the width
796 basethis->ClipString(width, buffer, false);
797
798 int l = ratio * ((float)DLLRenderHUDGetTextLineWidth(buffer));
799 int x = (width / 2) - (l / 2);
800
801 DLLRenderHUDText(basethis->GetTeamColor(i), m_alpha, 0, x, curr_y, buffer);
802 }
803
804 curr_y += (m_font_height + ROW_PIXEL_GAP);
805
806 if ((curr_y + m_font_height + ROW_PIXEL_GAP) > PLIST_WIN_H + PLIST_WIN_Y) {
807 break; // we are done here
808 }
809 }
810 }
811
812 // render the detailed menu
813 curr_x = m_x_start_detail;
814 curr_y = DLIST_WIN_Y + 1;
815
816 DLLRenderHUDQuad(DLIST_WIN_X, DLIST_WIN_Y, DLIST_WIN_W, DLIST_WIN_H, 0, 0, 1, 1, m_background_bmp, perc_done * 200.0f,
817 0);
818 pr = PRec_GetPRecord(m_selected_prec);
819 if (!pr || pr->state == STATE_EMPTY || pr->pinfo == NULL)
820 return;
821
822 is_dedicated_server = basethis->IsPlayerDedicatedServer(pr);
823
824 // display the heading for the player
825 strcpy(buffer, pr->callsign);
826 basethis->ClipString(DLIST_WIN_W, buffer, false);
827 l_width = DLLRenderHUDGetTextLineWidth(buffer);
828 DLLRenderHUDText(GR_WHITE, m_alpha, 0, DLIST_WIN_X + (DLIST_WIN_W / 2) - (l_width / 2), curr_y, buffer);
829 curr_y += (m_font_height + ROW_PIXEL_GAP);
830
831 if (m_flags & DSIF_SHOW_PIC && pr->state == STATE_INGAME && !is_dedicated_server) {
832
833 if (basethis->PilotPicBmpHandles[pr->pnum] > BAD_BITMAP_HANDLE) {
834 // display the pilot picture
835 DLLRenderHUDQuad(DLIST_WIN_X + (DLIST_WIN_W / 2) - 32, curr_y, 64, 64, 0, 0, 1, 1,
836 basethis->PilotPicBmpHandles[pr->pnum], m_alpha, 0);
837 curr_y += 70;
838 } else if (basethis->AreLogosEnabled()) { // only show logo's if enabled
839 bool animated;
840 int bmp_to_disp = BAD_BITMAP_HANDLE;
841 int logo_handle = basethis->GetPlayerLogoBmp(pr->pnum, &animated);
842 if (logo_handle != -1) {
843 if (animated) {
844 // display a vclip
845
846 vclip *vc = &basethis->GameVClips[logo_handle];
847 float interval = 1.0f / 10.0f;
848 int frames_elapsed = (int)(alpha_in_time / interval);
849
850 int frame = frames_elapsed % vc->num_frames;
851 bmp_to_disp = vc->frames[frame];
852
853 } else {
854 bmp_to_disp = logo_handle;
855 }
856 DLLRenderHUDQuad(DLIST_WIN_X + (DLIST_WIN_W / 2) - 32, curr_y, 64, 64, 0, 0, 1, 1, bmp_to_disp, m_alpha, 0);
857 curr_y += 70;
858 }
859 }
860 }
861
862 int old_y = curr_y;
863 int max_w = 0;
864 int x_to_use = curr_x + 5;
865 PInfo *pi;
866 tPExtraInfo *ei;
867 pi = (PInfo *)pr->pinfo;
868 ei = pi->GetExtraInfo();
869
870 // drawline(DLIST_WIN_X,DLIST_WIN_X+DLIST_WIN_W-1,curr_y,perc_done); curr_y += 3;
871
872 // game status
873 strcpy(buffer, DTXT_STAT_STATUS);
874 // l_width = (DLLgrtext_GetTextLineWidth(buffer)*(*basethis->Hud_aspect_x));
875 l_width = DLLRenderHUDGetTextLineWidth(buffer);
876 max_w = l_width;
877 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
878 curr_y += (m_font_height + ROW_PIXEL_GAP);
879
880 // ranking (if available)
881 int player_rank;
882 char player_rank_buffer[64];
883 player_rank =
884 (pr->state == STATE_INGAME && !is_dedicated_server) ? GetPlayerRankIndex(pr->pnum, player_rank_buffer) : -1;
885
886 if (player_rank != -1) {
887 strcpy(buffer, DTXT_RANK);
888 l_width = DLLRenderHUDGetTextLineWidth(buffer);
889 if (l_width > max_w)
890 max_w = l_width;
891 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
892 curr_y += (m_font_height + ROW_PIXEL_GAP);
893 }
894
895 // team (if available)
896 if (basethis->GetNumTeams() > 1 && !is_dedicated_server) {
897 strcpy(buffer, DTXT_STAT_TEAM);
898 l_width = DLLRenderHUDGetTextLineWidth(buffer);
899 if (l_width > max_w)
900 max_w = l_width;
901 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
902 curr_y += (m_font_height + ROW_PIXEL_GAP);
903 }
904
905 // time in game
906 strcpy(buffer, DTXT_STAT_PLAYTIME);
907 l_width = DLLRenderHUDGetTextLineWidth(buffer);
908 if (l_width > max_w)
909 max_w = l_width;
910 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
911 curr_y += (m_font_height + ROW_PIXEL_GAP);
912
913 uint8_t streak_type = 0;
914
915 if (!is_dedicated_server) {
916 // none of this should be displayed for a dedicated server
917
918 if (ei->kills_in_a_row)
919 streak_type = 1;
920 else if (ei->deaths_in_a_row)
921 streak_type = 2;
922
923 // kills/deaths in a row
924 if (streak_type > 0) {
925 strcpy(buffer, DTXT_STAT_STREAK);
926 l_width = DLLRenderHUDGetTextLineWidth(buffer);
927 if (l_width > max_w)
928 max_w = l_width;
929 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
930 curr_y += (m_font_height + ROW_PIXEL_GAP);
931 }
932
933 // last player you killed
934 if (!(m_flags & DSIF_NOLASTVICTIM)) {
935 strcpy(buffer, DTXT_STAT_LASTVICTIM);
936 l_width = DLLRenderHUDGetTextLineWidth(buffer);
937 if (l_width > max_w)
938 max_w = l_width;
939 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
940 curr_y += (m_font_height + ROW_PIXEL_GAP);
941 }
942
943 // last player to kill you
944 if (!(m_flags & DSIF_NOLASTKILLER)) {
945 strcpy(buffer, DTXT_STAT_LASTKILLER);
946 l_width = DLLRenderHUDGetTextLineWidth(buffer);
947 if (l_width > max_w)
948 max_w = l_width;
949 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
950 curr_y += (m_font_height + ROW_PIXEL_GAP);
951 }
952 }
953
954 curr_y = old_y;
955 x_to_use += (max_w + 5);
956 int width_to_clip;
957
958 width_to_clip = DLIST_WIN_X + DLIST_WIN_W - x_to_use - 5;
959
960 // game status
961 if (pr->state == STATE_INGAME) {
962 if (basethis->IsPlayerDedicatedServer(pr)) {
963 strcpy(buffer, DTXT_STAT_SERVER);
964 } else {
965 if (basethis->IsPlayerObserver(pr->pnum)) {
966 strcpy(buffer, DTXT_STAT_OBSERVER);
967 } else {
968 strcpy(buffer, DTXT_STAT_PLAYING);
969 }
970 }
971 } else {
972 strcpy(buffer, DTXT_STAT_DISCONNECTED);
973 }
974 basethis->ClipString(width_to_clip, buffer, false);
975 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
976 curr_y += (m_font_height + ROW_PIXEL_GAP);
977
978 // player ranking (if available)
979 if (player_rank != -1) {
980 basethis->ClipString(width_to_clip, player_rank_buffer, false);
981 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, player_rank_buffer);
982 curr_y += (m_font_height + ROW_PIXEL_GAP);
983 }
984
985 // team (if available)
986 if (basethis->GetNumTeams() > 1 && !is_dedicated_server) {
987 strcpy(buffer, basethis->GetTeamString(pr->team));
988 basethis->ClipString(width_to_clip, buffer, false);
989 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
990 curr_y += (m_font_height + ROW_PIXEL_GAP);
991 }
992
993 // time in game
994 strcpy(buffer, basethis->GetTimeString(basethis->GetTimeInGame(m_selected_prec)));
995 basethis->ClipString(width_to_clip, buffer, false);
996 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
997 curr_y += (m_font_height + ROW_PIXEL_GAP);
998
999 if (!is_dedicated_server) {
1000 switch (streak_type) {
1001 case 1: // kills in a row
1002 snprintf(buffer, sizeof(buffer), "%d %s", ei->kills_in_a_row,
1003 (ei->kills_in_a_row == 1) ? DTXT_STAT_KILL : DTXT_STAT_KILLS);
1004 basethis->ClipString(width_to_clip, buffer, false);
1005 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
1006 curr_y += (m_font_height + ROW_PIXEL_GAP);
1007 break;
1008 case 2: // deaths in a row
1009 snprintf(buffer, sizeof(buffer), "%d %s", ei->deaths_in_a_row,
1010 (ei->deaths_in_a_row == 1) ? DTXT_STAT_DEATH : DTXT_STAT_DEATHS);
1011 basethis->ClipString(width_to_clip, buffer, false);
1012 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
1013 curr_y += (m_font_height + ROW_PIXEL_GAP);
1014 break;
1015 default:
1016 break;
1017 }
1018
1019 player_record *tpr;
1020 // last player you killed
1021 if (ei->last_kill_num != -1) {
1022 tpr = PRec_GetPRecord(ei->last_kill_num);
1023 if (tpr && tpr->state != STATE_EMPTY) {
1024 strcpy(buffer, tpr->callsign);
1025 } else {
1026 buffer[0] = '\0';
1027 }
1028 } else {
1029 buffer[0] = '\0';
1030 }
1031 if (!(m_flags & DSIF_NOLASTVICTIM)) {
1032 basethis->ClipString(width_to_clip, buffer, false);
1033 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
1034 curr_y += (m_font_height + ROW_PIXEL_GAP);
1035 }
1036
1037 // last player to kill you
1038 if (ei->last_death_num != -1) {
1039 tpr = PRec_GetPRecord(ei->last_death_num);
1040 if (tpr && tpr->state != STATE_EMPTY) {
1041 strcpy(buffer, tpr->callsign);
1042 } else {
1043 buffer[0] = '\0';
1044 }
1045 } else {
1046 buffer[0] = '\0';
1047 }
1048 if (!(m_flags & DSIF_NOLASTKILLER)) {
1049 basethis->ClipString(width_to_clip, buffer, false);
1050 DLLRenderHUDText(GR_WHITE, m_alpha, 0, x_to_use, curr_y, buffer);
1051 curr_y += (m_font_height + ROW_PIXEL_GAP);
1052 }
1053 }
1054
1055 // drawline(DLIST_WIN_X,DLIST_WIN_X+DLIST_WIN_W-1,curr_y,perc_done); curr_y += 10;
1056
1057 curr_x = m_x_start_detail;
1058
1059 // now do the detail columns (if any for this player)
1060 for (c = 0; c < m_iDColCount; c++) {
1061 strcpy(buffer, m_DColInfo[c].title);
1062 basethis->ClipString(m_DColInfo[c].width, buffer, false);
1063 DLLRenderHUDText(GR_WHITE, m_alpha, 0, curr_x, curr_y, buffer);
1064 curr_x += m_DColInfo[c].width;
1065 }
1066
1067 if (m_iDColCount > 0)
1068 curr_y += (m_font_height + ROW_PIXEL_GAP);
1069 curr_x = m_x_start_detail;
1070
1071 if (m_iDColCount > 0)
1072 drawline(DLIST_WIN_X, DLIST_WIN_X + DLIST_WIN_W - 1, curr_y, perc_done);
1073 curr_y += 3;
1074
1075 for (c = 0; c < m_iDColCount; c++) {
1076 buffer[0] = '\0';
1077 if (!is_dedicated_server || m_DColInfo[c].type == DSCOL_PILOT_NAME || m_DColInfo[c].type == DSCOL_BLANK) {
1078 switch (m_DColInfo[c].type) {
1079 case DSCOL_BMP:
1080 break;
1081 case DSCOL_KILLS_LEVEL:
1082 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.kills[DSTAT_LEVEL]);
1083 break;
1084 case DSCOL_KILLS_OVERALL:
1085 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.kills[DSTAT_OVERALL]);
1086 break;
1087 case DSCOL_KILLS_BOTH:
1088 snprintf(buffer, sizeof(buffer), "%d[%d]", pr->dstats.kills[DSTAT_LEVEL], pr->dstats.kills[DSTAT_OVERALL]);
1089 break;
1090 case DSCOL_DEATHS_LEVEL:
1091 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.deaths[DSTAT_LEVEL]);
1092 break;
1093 case DSCOL_DEATHS_OVERALL:
1094 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.deaths[DSTAT_OVERALL]);
1095 break;
1096 case DSCOL_DEATHS_BOTH:
1097 snprintf(buffer, sizeof(buffer), "%d[%d]", pr->dstats.deaths[DSTAT_LEVEL], pr->dstats.deaths[DSTAT_OVERALL]);
1098 break;
1099 case DSCOL_SUICIDES_LEVEL:
1100 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.suicides[DSTAT_LEVEL]);
1101 break;
1102 case DSCOL_SUICIDES_OVERALL:
1103 snprintf(buffer, sizeof(buffer), "%d", pr->dstats.suicides[DSTAT_OVERALL]);
1104 break;
1105 case DSCOL_SUICIDES_BOTH:
1106 snprintf(buffer, sizeof(buffer), "%d[%d]", pr->dstats.suicides[DSTAT_LEVEL],
1107 pr->dstats.suicides[DSTAT_OVERALL]);
1108 break;
1109 case DSCOL_PILOT_NAME:
1110 strcpy(buffer, pr->callsign);
1111 break;
1112 case DSCOL_PILOT_TEAM:
1113 snprintf(buffer, sizeof(buffer), "%s", basethis->GetTeamString(pr->team));
1114 break;
1115 case DSCOL_PING:
1116 if (pr->state == STATE_INGAME)
1117 snprintf(buffer, sizeof(buffer), "%.0f", basethis->NetPlayers[pr->pnum].ping_time * 1000.0f);
1118 else
1119 strcpy(buffer, "---");
1120 break;
1121 case DSCOL_CUSTOM:
1122 if (m_DColCallback)
1123 (*m_DColCallback)(m_selected_prec, c, buffer, sizeof(buffer));
1124 break;
1125 case DSCOL_BLANK:
1126 buffer[0] = '\0';
1127 break;
1128 }
1129 } else {
1130 strcpy(buffer, "N/A");
1131 }
1132
1133 if (m_DColInfo[c].type != DSCOL_BMP) {
1134
1135 // clip the string to the width
1136 basethis->ClipString(std::min(m_DColInfo[c].width, (DLIST_WIN_X + DLIST_WIN_W - curr_x - 5)), buffer, false);
1137
1138 // print out string
1139 ddgr_color color;
1140 switch (m_DColInfo[c].color_type) {
1141 case DSCOLOR_NORMAL:
1142 color = (pr->state == STATE_INGAME) ? GR_GREEN : GR_GREY;
1143 break;
1144 case DSCOLOR_TEAM:
1145 color = basethis->GetTeamColor(pr->team);
1146 break;
1147 case DSCOLOR_SHIPCOLOR:
1148 color = (pr->state == STATE_INGAME) ? basethis->Player_colors[pr->pnum] : GR_GREY;
1149 break;
1150 case DSCOLOR_CUSTOM:
1151 color = m_DColInfo[c].color;
1152 break;
1153 default:
1154 color = (pr->state == STATE_INGAME) ? GR_GREEN : GR_GREY;
1155 break;
1156 };
1157
1158 DLLRenderHUDText(color, m_alpha, 0, curr_x, curr_y, buffer);
1159
1160 } else {
1161 // we need to draw a custom bitmap
1162 (*m_DColCallbackBMP)(m_selected_prec, c, curr_x, curr_y, m_DColInfo[c].width, m_font_height + ROW_PIXEL_GAP,
1163 m_alpha);
1164 }
1165
1166 curr_x += m_DColInfo[c].width;
1167
1168 if (curr_x > DLIST_WIN_W + DLIST_WIN_X)
1169 break; // we can't fit anymore columns
1170 }
1171 curr_y += (m_font_height + ROW_PIXEL_GAP);
1172
1173 // finally do the who-killed-who stats for the player
1174 int col_callsign, col_kills, col_deaths;
1175 col_callsign = m_x_start_detail + 5;
1176 col_kills = col_callsign + 100;
1177 col_deaths = col_kills + 50;
1178 int colw_callsign, colw_kills, colw_deaths;
1179 colw_callsign = col_kills - col_callsign;
1180 colw_kills = col_deaths - col_kills;
1181 colw_deaths = DLIST_WIN_X + DLIST_WIN_W - col_deaths;
1182
1183 if (!(m_flags & DSIF_NODETAILEDINFO)) {
1184
1185 DLLRenderHUDText(GR_WHITE, m_alpha, 0, col_callsign, curr_y, DTXT_STAT_PILOTNAMELABEL);
1186 DLLRenderHUDText(GR_WHITE, m_alpha, 0, col_kills, curr_y, DTXT_STAT_KILLS);
1187 DLLRenderHUDText(GR_WHITE, m_alpha, 0, col_deaths, curr_y, DTXT_STAT_DEATHS);
1188 curr_y += (m_font_height + ROW_PIXEL_GAP);
1189 drawline(DLIST_WIN_X, DLIST_WIN_X + DLIST_WIN_W - 1, curr_y, perc_done);
1190 curr_y += 3;
1191
1192 if (m_can_fit_count == -1) {
1193 // we need to recalculate the how-many-items-can-fit-on-this-page value
1194 int count = 0;
1195 int y = curr_y;
1196
1197 while (y + (m_font_height + ROW_PIXEL_GAP) < DLIST_WIN_H + DLIST_WIN_Y) {
1198 count++;
1199 y += (m_font_height + ROW_PIXEL_GAP);
1200 }
1201 m_can_fit_count = count;
1202 }
1203
1204 tPInfoStat stat;
1205 player_record *dpr;
1206 int stats_displayed = 0;
1207 bool clean_exit = true;
1208 int start_index = (m_page_index * m_can_fit_count);
1209 bool team_game = (basethis->GetNumTeams() > 1) ? true : false;
1210
1211 if (basethis->FindPInfoStatFirst(m_selected_prec, &stat)) {
1212 if (stat.slot != m_selected_prec) {
1213 dpr = basethis->GetPlayerRecord(stat.slot);
1214 stats_displayed++;
1215
1216 ASSERT(dpr != NULL);
1217 if (dpr && start_index < stats_displayed) {
1218 ddgr_color color;
1219 color = (dpr->state == STATE_INGAME)
1220 ? ((team_game) ? basethis->GetTeamColor(dpr->team) : basethis->Player_colors[dpr->pnum])
1221 : GR_GREY;
1222
1223 strcpy(buffer, dpr->callsign);
1224 basethis->ClipString(colw_callsign - 5, buffer, false);
1225 DLLRenderHUDText(color, m_alpha, 0, col_callsign, curr_y, buffer);
1226
1227 snprintf(buffer, sizeof(buffer), "%d", stat.kills);
1228 basethis->ClipString(colw_kills - 5, buffer, false);
1229 DLLRenderHUDText(color, m_alpha, 0, col_kills, curr_y, buffer);
1230
1231 snprintf(buffer, sizeof(buffer), "%d", stat.deaths);
1232 basethis->ClipString(colw_deaths - 5, buffer, false);
1233 DLLRenderHUDText(color, m_alpha, 0, col_deaths, curr_y, buffer);
1234
1235 curr_y += (m_font_height + ROW_PIXEL_GAP);
1236 }
1237 }
1238
1239 while (basethis->FindPInfoStatNext(&stat)) {
1240 if (stat.slot != m_selected_prec) {
1241 dpr = basethis->GetPlayerRecord(stat.slot);
1242 stats_displayed++;
1243
1244 ASSERT(dpr != NULL);
1245 if (dpr && start_index < stats_displayed) {
1246 ddgr_color color;
1247 color = (dpr->state == STATE_INGAME)
1248 ? ((team_game) ? basethis->GetTeamColor(dpr->team) : basethis->Player_colors[dpr->pnum])
1249 : GR_GREY;
1250
1251 strcpy(buffer, dpr->callsign);
1252 basethis->ClipString(colw_callsign - 5, buffer, false);
1253 DLLRenderHUDText(color, m_alpha, 0, col_callsign, curr_y, buffer);
1254
1255 snprintf(buffer, sizeof(buffer), "%d", stat.kills);
1256 basethis->ClipString(colw_kills - 5, buffer, false);
1257 DLLRenderHUDText(color, m_alpha, 0, col_kills, curr_y, buffer);
1258
1259 snprintf(buffer, sizeof(buffer), "%d", stat.deaths);
1260 basethis->ClipString(colw_deaths - 5, buffer, false);
1261 DLLRenderHUDText(color, m_alpha, 0, col_deaths, curr_y, buffer);
1262
1263 curr_y += (m_font_height + ROW_PIXEL_GAP);
1264 }
1265 }
1266
1267 if (curr_y + (m_font_height + ROW_PIXEL_GAP) > DLIST_WIN_H + DLIST_WIN_Y) {
1268
1269 if (basethis->FindPInfoStatNext(&stat)) {
1270 clean_exit = false; // there are more stats
1271 m_has_multiple_pages = true;
1272 }
1273
1274 break; // can't fit anymore
1275 }
1276 }
1277 }
1278 basethis->FindPInfoStatClose();
1279
1280 m_page_display_time += *basethis->Frametime;
1281 if ((m_page_display_time >= PAGE_DISP_TIME) && m_has_multiple_pages) {
1282 if (!clean_exit)
1283 m_page_index++;
1284 else
1285 m_page_index = 0; // if there was a clean exit, that means we were on the last page,
1286 // go back to the beginning
1287 m_page_display_time = 0;
1288 }
1289 }
1290
1291 if (m_flags & DSIF_SHOWPLAYERVIEW && m_flags & DSIF_NODETAILEDINFO && pr->state == STATE_INGAME) {
1292 DLLgrtext_Flush();
1293
1294 float x, y, w, h;
1295 x = (float)DLIST_WIN_X + 2;
1296 y = (float)curr_y;
1297 h = w = (float)std::min(DLIST_WIN_W - 4, (DLIST_WIN_Y + DLIST_WIN_H - curr_y) - 4);
1298 object *obj_view = &basethis->Objects[basethis->Players[pr->pnum].objnum];
1299
1300 x *= *basethis->Hud_aspect_x;
1301 y *= *basethis->Hud_aspect_y;
1302 w *= *basethis->Hud_aspect_x;
1303 h *= *basethis->Hud_aspect_y;
1304 x += *basethis->Game_window_x;
1305 y += *basethis->Game_window_y;
1306
1307 if (obj_view->type == OBJ_PLAYER) {
1308 DisplayPlayerView((int)x, (int)y, (int)w, (int)h, obj_view);
1309 }
1310 }
1311
1312 alpha_in_time += *basethis->Frametime;
1313 m_alpha = (perc_done * 255.0f);
1314 }
1315
1316 // validates all the variables
1317 void CDmfcStats::ValidateInfo() {
1318 // change index to match the last selected prec num so it doesn't move around
1319 int new_idx = -1;
1320 for (int p = 0; p < m_MaxCount; p++) {
1321 if (m_translate[p] == m_selected_prec) {
1322 // found it, update the index
1323 new_idx = p;
1324 break;
1325 }
1326 }
1327
1328 if (new_idx == -1) {
1329 // the old prec wasn't found
1330 m_selected_index = 0;
1331 } else {
1332 m_selected_index = new_idx;
1333 }
1334
1335 // make sure selected index is in view
1336 while (m_selected_index < m_top_index) {
1337 m_top_index--;
1338 }
1339 if (m_bottom_index != -1) { // make sure it has been set in a frame
1340 while (m_selected_index > m_bottom_index) {
1341 m_top_index++;
1342 m_bottom_index++;
1343 }
1344 }
1345 }
1346
1347 // the do-it-all function, call once per frame
1348 void CDmfcStats::DoFrame() {
1349 if (!m_enabled)
1350 return;
1351
1352 int high_count;
1353 int count;
1354 int index;
1355 static slot_state last_state = STATE_EMPTY;
1356 player_record *pr;
1357
1358 if (m_flags & DSIF_ONLY_X_PLAYERS_SHOWN)
1359 high_count = *m_pMaxNumberDisplayed;
1360 else
1361 high_count = MAX_PLAYER_RECORDS;
1362
1363 // count the number of players in the game/disconnected
1364 // build translation table
1365 count = 0;
1366 index = 0;
1367
1368 if (m_SortedPRecs[0] != 0) {
1369 count = 0;
1370 index = 0;
1371 }
1372
1373 for (int p = 0; p < MAX_PLAYER_RECORDS; p++) {
1374
1375 // increase count to see how many at most there are to display
1376 pr = PRec_GetPRecord(p);
1377 if (pr && pr->state != STATE_EMPTY && !basethis->IsPlayerDedicatedServer(pr))
1378 count++;
1379
1380 // update translation table
1381 pr = PRec_GetPRecord(m_SortedPRecs[p]);
1382 if (pr && pr->state != STATE_EMPTY && !basethis->IsPlayerDedicatedServer(pr)) {
1383 m_translate[index] = m_SortedPRecs[p];
1384 index++;
1385 }
1386 }
1387
1388 if (m_flags & DSIF_SEPERATE_BY_TEAM) {
1389 // Seperate by teams
1390 int team_index;
1391 int real_index = 0;
1392 int num_teams = basethis->GetNumTeams();
1393 int temp_array[MAX_PLAYER_RECORDS];
1394 int prec, p;
1395
1396 bool getting_ingame_people = true;
1397
1398 get_disconnected_people:
1399
1400 for (team_index = 0; team_index < num_teams; team_index++) {
1401 for (p = 0; p < index; p++) {
1402 prec = m_translate[p];
1403 pr = PRec_GetPRecord(prec);
1404 if (pr->state != STATE_EMPTY && pr->team == team_index) {
1405
1406 // we must make sure to move all disconnected people to the
1407 // bottom
1408 if ((getting_ingame_people && pr->state == STATE_INGAME) ||
1409 (!getting_ingame_people && pr->state == STATE_DISCONNECTED)) {
1410 temp_array[real_index] = prec;
1411 real_index++;
1412 }
1413 }
1414 }
1415 // next team
1416 }
1417
1418 if (getting_ingame_people) {
1419 getting_ingame_people = false;
1420 goto get_disconnected_people;
1421 }
1422
1423 memcpy(m_translate, temp_array, sizeof(int) * MAX_PLAYER_RECORDS);
1424 }
1425
1426 m_MaxCount = std::min({high_count, count, index});
1427
1428 pr = PRec_GetPRecord(m_selected_prec);
1429 if (!pr || pr->state != last_state) {
1430 m_can_fit_count = -1; // we need to recalc this
1431 m_page_index = 0;
1432 m_has_multiple_pages = false;
1433 if (pr)
1434 last_state = pr->state;
1435 }
1436
1437 ValidateInfo();
1438
1439 Render();
1440
1441 // save the last selected prec num for the next frame
1442 m_selected_prec = m_translate[m_selected_index];
1443 }
1444
1445 void CDmfcStats::DisplayPlayerView(int x, int y, int w, int h, object *viewer) {
1446 object *save_viewer_object = *basethis->Viewer_object;
1447
1448 DLLrend_SetZBufferState(1);
1449
1450 // Set up for rendering
1451 DLLStartFrame(x, y, x + w, y + h, true);
1452
1453 // Reset facings for mine stuff
1454 DLLResetFacings();
1455
1456 // Set the viewer for this render
1457 *basethis->Viewer_object = viewer;
1458
1459 // Render the world
1460 DLLGameRenderWorld(viewer, &viewer->pos, viewer->roomnum, &viewer->orient, *basethis->Render_zoom, false);
1461
1462 // Restore the viewre
1463 *basethis->Viewer_object = save_viewer_object;
1464
1465 // Done rendering
1466 DLLEndFrame();
1467 }