| 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/anarchy/anarchy.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003/08/26 03:56:37 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * <insert description of file here> |
| 26 | * |
| 27 | * $Log: anarchy.cpp,v $ |
| 28 | * Revision 1.1.1.1 2003/08/26 03:56:37 kevinb |
| 29 | * initial 1.5 import |
| 30 | * |
| 31 | * |
| 32 | * 84 11/08/99 11:42p Jeff |
| 33 | * SourceSafe Test...ignore |
| 34 | * |
| 35 | * 83 10/21/99 9:27p Jeff |
| 36 | * B.A. Macintosh code merge |
| 37 | * |
| 38 | * 82 7/12/99 1:22p Jeff |
| 39 | * updated for new netflags |
| 40 | * |
| 41 | * 81 7/11/99 6:43p Jeff |
| 42 | * cleaner plr if the list is too long |
| 43 | * |
| 44 | * 80 5/23/99 3:04a Jason |
| 45 | * fixed bug with player rankings not being updated correctly |
| 46 | * |
| 47 | * 79 5/12/99 11:28a Jeff |
| 48 | * added sourcesafe comment block |
| 49 | * |
| 50 | * $NoKeywords: $ |
| 51 | */ |
| 52 | |
| 53 | #include <string.h> |
| 54 | #include <stdio.h> |
| 55 | #include <stdlib.h> |
| 56 | #include "idmfc.h" |
| 57 | #include "Anarchy.h" |
| 58 | #include "anarchystr.h" |
| 59 | |
| 60 | #include <algorithm> |
| 61 | |
| 62 | IDMFC *DMFCBase = NULL; |
| 63 | static IDmfcStats *dstat = NULL; |
| 64 | |
| 65 | static int SortedPlayers[MAX_PLAYER_RECORDS]; // sorted player nums |
| 66 | static bool DisplayScoreScreen; |
| 67 | static int Highlight_bmp = -1; |
| 68 | |
| 69 | #define AHD_NONE 0 |
| 70 | #define AHD_SCORE 1 |
| 71 | #define AHD_EFFICIENCY 2 |
| 72 | #define ACM_PLAYERCOLOR 0 |
| 73 | #define ACM_NORMAL 1 |
| 74 | static uint8_t Anarchy_hud_display = AHD_SCORE; |
| 75 | static uint8_t HUD_color_model = ACM_PLAYERCOLOR; |
| 76 | static bool display_my_welcome = false; |
| 77 | |
| 78 | static void DisplayHUDScores(struct tHUDItem *hitem); |
| 79 | static void DisplayScores(void); |
| 80 | static void DisplayWelcomeMessage(int player_num); |
| 81 | static void SaveStatsToFile(char *filename); |
| 82 | static void SwitchHUDColor(int i); |
| 83 | static void SwitchAnarchyScores(int i); |
| 84 | static const char *GetString(int d); |
| 85 | static void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size); |
| 86 | |
| 87 | /////////////////////////////////////////////// |
| 88 | // localization info |
| 89 | static char **StringTable; |
| 90 | static int StringTableSize = 0; |
| 91 | static const char *_ErrorString = "Missing String"; |
| 92 | const char *GetString(int d) { |
| 93 | if ((d < 0) || (d >= StringTableSize)) |
| 94 | return _ErrorString; |
| 95 | else |
| 96 | return StringTable[d]; |
| 97 | } |
| 98 | /////////////////////////////////////////////// |
| 99 | |
| 100 | void SwitchAnarchyScores(int i) { |
| 101 | if (i < 0) |
| 102 | i = 0; |
| 103 | if (i > 2) |
| 104 | i = 2; |
| 105 | |
| 106 | Anarchy_hud_display = i; |
| 107 | |
| 108 | switch (i) { |
| 109 | case AHD_NONE: |
| 110 | DLLAddHUDMessage(TXT_HUDD_NONE); |
| 111 | break; |
| 112 | case AHD_SCORE: |
| 113 | DLLAddHUDMessage(TXT_HUDD_SCORES); |
| 114 | break; |
| 115 | case AHD_EFFICIENCY: |
| 116 | DLLAddHUDMessage(TXT_HUDD_EFFIC); |
| 117 | break; |
| 118 | }; |
| 119 | } |
| 120 | |
| 121 | // This function gets called by the game when it wants to learn some info about the game |
| 122 | void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options) { |
| 123 | options->flags = DOF_MAXTEAMS; |
| 124 | options->max_teams = 1; |
| 125 | strcpy(options->game_name, "Anarchy"); |
| 126 | strcpy(options->requirements, ""); |
| 127 | } |
| 128 | |
| 129 | // Initializes the game function pointers |
| 130 | void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_use) { |
| 131 | *all_ok = 1; |
| 132 | DMFCBase = CreateDMFC(); |
| 133 | if (!DMFCBase) { |
| 134 | *all_ok = 0; |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | dstat = CreateDmfcStats(); |
| 139 | if (!dstat) { |
| 140 | *all_ok = 0; |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | DMFCBase->LoadFunctions(api_func); |
| 145 | |
| 146 | // Setup the event handlers that we handle |
| 147 | DMFCBase->Set_OnKeypress(OnKeypress); |
| 148 | DMFCBase->Set_OnHUDInterval(OnHUDInterval); |
| 149 | DMFCBase->Set_OnInterval(OnInterval); |
| 150 | DMFCBase->Set_OnClientPlayerKilled(OnClientPlayerKilled); |
| 151 | DMFCBase->Set_OnClientPlayerEntersGame(OnClientPlayerEntersGame); |
| 152 | DMFCBase->Set_OnClientLevelStart(OnClientLevelStart); |
| 153 | DMFCBase->Set_OnClientLevelEnd(OnClientLevelEnd); |
| 154 | DMFCBase->Set_OnServerGameCreated(OnServerGameCreated); |
| 155 | DMFCBase->Set_OnPLRInterval(OnPLRInterval); |
| 156 | DMFCBase->Set_OnPLRInit(OnPLRInit); |
| 157 | DMFCBase->Set_OnSaveStatsToFile(OnSaveStatsToFile); |
| 158 | DMFCBase->Set_OnLevelEndSaveStatsToFile(OnLevelEndSaveStatsToFile); |
| 159 | DMFCBase->Set_OnDisconnectSaveStatsToFile(OnDisconnectSaveStatsToFile); |
| 160 | DMFCBase->Set_OnPrintScores(OnPrintScores); |
| 161 | |
| 162 | DLLCreateStringTable("Anarchy.str", &StringTable, &StringTableSize); |
| 163 | mprintf(0, "%d strings loaded from string table\n", StringTableSize); |
| 164 | if (!StringTableSize) { |
| 165 | *all_ok = 0; |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | AnarchyGameInit(1); |
| 170 | |
| 171 | // add the death and suicide messages |
| 172 | DMFCBase->AddDeathMessage(TXT_DEATH1, true); |
| 173 | DMFCBase->AddDeathMessage(TXT_DEATH2, true); |
| 174 | DMFCBase->AddDeathMessage(TXT_DEATH3, false); |
| 175 | DMFCBase->AddDeathMessage(TXT_DEATH4, false); |
| 176 | DMFCBase->AddDeathMessage(TXT_DEATH5, true); |
| 177 | DMFCBase->AddDeathMessage(TXT_DEATH6, true); |
| 178 | DMFCBase->AddDeathMessage(TXT_DEATH7, false); |
| 179 | DMFCBase->AddDeathMessage(TXT_DEATH8, true); |
| 180 | DMFCBase->AddDeathMessage(TXT_DEATH9, true); |
| 181 | DMFCBase->AddDeathMessage(TXT_DEATH10, true); |
| 182 | |
| 183 | DMFCBase->AddSuicideMessage(TXT_SUICIDE1); |
| 184 | DMFCBase->AddSuicideMessage(TXT_SUICIDE2); |
| 185 | DMFCBase->AddSuicideMessage(TXT_SUICIDE3); |
| 186 | DMFCBase->AddSuicideMessage(TXT_SUICIDE4); |
| 187 | DMFCBase->AddSuicideMessage(TXT_SUICIDE5); |
| 188 | DMFCBase->AddSuicideMessage(TXT_SUICIDE6); |
| 189 | |
| 190 | DMFCBase->SetNumberOfTeams(1); |
| 191 | |
| 192 | netgame_info *Netgame = DMFCBase->GetNetgameInfo(); |
| 193 | Netgame->flags |= (NF_DAMAGE_FRIENDLY | NF_TRACK_RANK); |
| 194 | |
| 195 | Highlight_bmp = DLLbm_AllocBitmap(32, 32, 0); |
| 196 | if (Highlight_bmp > BAD_BITMAP_HANDLE) { |
| 197 | uint16_t *data = DLLbm_data(Highlight_bmp, 0); |
| 198 | if (!data) { |
| 199 | // bail on out of here |
| 200 | *all_ok = 0; |
| 201 | return; |
| 202 | } |
| 203 | for (int x = 0; x < 32 * 32; x++) { |
| 204 | data[x] = GR_RGB16(50, 50, 50) | OPAQUE_FLAG; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | DMFCBase->AddHUDItemCallback(HI_TEXT, DisplayHUDScores); |
| 209 | |
| 210 | DisplayScoreScreen = false; |
| 211 | } |
| 212 | // Called when the DLL is shutdown |
| 213 | void DLLFUNCCALL DLLGameClose() { |
| 214 | if (Highlight_bmp > BAD_BITMAP_HANDLE) |
| 215 | DLLbm_FreeBitmap(Highlight_bmp); |
| 216 | |
| 217 | DLLDestroyStringTable(StringTable, StringTableSize); |
| 218 | |
| 219 | if (dstat) { |
| 220 | dstat->DestroyPointer(); |
| 221 | dstat = NULL; |
| 222 | } |
| 223 | |
| 224 | if (DMFCBase) { |
| 225 | AnarchyGameClose(); |
| 226 | DMFCBase->GameClose(); |
| 227 | DMFCBase->DestroyPointer(); |
| 228 | DMFCBase = NULL; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size) { |
| 233 | player_record *pr = DMFCBase->GetPlayerRecord(precord_num); |
| 234 | if (!pr || pr->state == STATE_EMPTY) { |
| 235 | buffer[0] = '\0'; |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | snprintf(buffer, buffer_size, "%d", pr->dstats.kills[DSTAT_LEVEL] - pr->dstats.suicides[DSTAT_LEVEL]); |
| 240 | } |
| 241 | |
| 242 | void AnarchyGameClose(void) {} |
| 243 | |
| 244 | // DMFCApp::GameInit |
| 245 | // |
| 246 | // Sets up all the DLL functions and pointers and preps the class for use. This ABSOLUTLY must be |
| 247 | // called, so if you override DMFCApp::GameInit, make sure that you put a call to this somewhere in |
| 248 | // the override. |
| 249 | void AnarchyGameInit(int teams) { |
| 250 | // add the anarchy menu/submenus |
| 251 | IMenuItem *lev1, *lev2; |
| 252 | |
| 253 | lev1 = CreateMenuItemWArgs("Anarchy", MIT_NORMAL, 0, NULL); |
| 254 | |
| 255 | lev2 = CreateMenuItemWArgs(TXT_MNU_HUDSTYLE, MIT_STATE, 0, SwitchAnarchyScores); |
| 256 | lev2->SetStateItemList(3, TXT_NONE, TXT_SCOREHD, TXT_EFFICIENCY); |
| 257 | lev2->SetState(1); |
| 258 | lev1->AddSubMenu(lev2); |
| 259 | |
| 260 | lev2 = CreateMenuItemWArgs(TXT_MNU_HUDCOLOR, MIT_STATE, 0, SwitchHUDColor); |
| 261 | lev2->SetStateItemList(2, TXT_PLAYERCOLORS, TXT_NORMAL); |
| 262 | lev2->SetState(HUD_color_model); |
| 263 | lev1->AddSubMenu(lev2); |
| 264 | |
| 265 | lev2 = DMFCBase->GetOnScreenMenu(); |
| 266 | lev2->AddSubMenu(lev1); |
| 267 | |
| 268 | DMFCBase->GameInit(teams); |
| 269 | |
| 270 | // Initialize the Stats Manager |
| 271 | // ---------------------------- |
| 272 | |
| 273 | tDmfcStatsInit tsi; |
| 274 | tDmfcStatsColumnInfo pl_col[6]; |
| 275 | char gname[20]; |
| 276 | strcpy(gname, "Anarchy"); |
| 277 | |
| 278 | tsi.flags = DSIF_SHOW_PIC | DSIF_SHOW_OBSERVERICON; |
| 279 | tsi.cColumnCountDetailed = 0; |
| 280 | tsi.cColumnCountPlayerList = 6; |
| 281 | tsi.clbDetailedColumn = NULL; |
| 282 | tsi.clbDetailedColumnBMP = NULL; |
| 283 | tsi.clbPlayerColumn = DetermineScore; |
| 284 | tsi.clbPlayerColumnBMP = NULL; |
| 285 | tsi.DetailedColumns = NULL; |
| 286 | tsi.GameName = gname; |
| 287 | tsi.MaxNumberDisplayed = NULL; |
| 288 | tsi.PlayerListColumns = pl_col; |
| 289 | tsi.SortedPlayerRecords = SortedPlayers; |
| 290 | |
| 291 | pl_col[0].color_type = DSCOLOR_SHIPCOLOR; |
| 292 | strcpy(pl_col[0].title, TXT_PILOT); |
| 293 | pl_col[0].type = DSCOL_PILOT_NAME; |
| 294 | pl_col[0].width = 120; |
| 295 | |
| 296 | pl_col[1].color_type = DSCOLOR_SHIPCOLOR; |
| 297 | strcpy(pl_col[1].title, TXT_SCORE); |
| 298 | pl_col[1].type = DSCOL_CUSTOM; |
| 299 | pl_col[1].width = 50; |
| 300 | |
| 301 | pl_col[2].color_type = DSCOLOR_SHIPCOLOR; |
| 302 | strcpy(pl_col[2].title, TXT_KILLS_SHORT); |
| 303 | pl_col[2].type = DSCOL_KILLS_LEVEL; |
| 304 | pl_col[2].width = 50; |
| 305 | |
| 306 | pl_col[3].color_type = DSCOLOR_SHIPCOLOR; |
| 307 | strcpy(pl_col[3].title, TXT_DEATHS_SHORT); |
| 308 | pl_col[3].type = DSCOL_DEATHS_LEVEL; |
| 309 | pl_col[3].width = 60; |
| 310 | |
| 311 | pl_col[4].color_type = DSCOLOR_SHIPCOLOR; |
| 312 | strcpy(pl_col[4].title, TXT_SUICIDES_SHORT); |
| 313 | pl_col[4].type = DSCOL_SUICIDES_LEVEL; |
| 314 | pl_col[4].width = 65; |
| 315 | |
| 316 | pl_col[5].color_type = DSCOLOR_SHIPCOLOR; |
| 317 | strcpy(pl_col[5].title, TXT_PING); |
| 318 | pl_col[5].type = DSCOL_PING; |
| 319 | pl_col[5].width = 40; |
| 320 | |
| 321 | dstat->Initialize(&tsi); |
| 322 | } |
| 323 | |
| 324 | void OnHUDInterval(void) { |
| 325 | dstat->DoFrame(); |
| 326 | DMFCBase->DisplayOutrageLogo(); |
| 327 | DMFCBase->OnHUDInterval(); |
| 328 | } |
| 329 | |
| 330 | void OnInterval(void) { |
| 331 | DMFCBase->GetSortedPlayerSlots(SortedPlayers, MAX_PLAYER_RECORDS); |
| 332 | DMFCBase->OnInterval(); |
| 333 | } |
| 334 | |
| 335 | void OnKeypress(int key) { |
| 336 | dllinfo *Data = DMFCBase->GetDLLInfoCallData(); |
| 337 | |
| 338 | switch (key) { |
| 339 | case K_F7: |
| 340 | DisplayScoreScreen = !DisplayScoreScreen; |
| 341 | DMFCBase->EnableOnScreenMenu(false); |
| 342 | dstat->Enable(DisplayScoreScreen); |
| 343 | break; |
| 344 | case K_PAGEDOWN: |
| 345 | if (DisplayScoreScreen) { |
| 346 | dstat->ScrollDown(); |
| 347 | Data->iRet = 1; |
| 348 | } |
| 349 | break; |
| 350 | case K_PAGEUP: |
| 351 | if (DisplayScoreScreen) { |
| 352 | dstat->ScrollUp(); |
| 353 | Data->iRet = 1; |
| 354 | } |
| 355 | break; |
| 356 | case K_F6: |
| 357 | DisplayScoreScreen = false; |
| 358 | dstat->Enable(false); |
| 359 | break; |
| 360 | case K_ESC: |
| 361 | if (DisplayScoreScreen) { |
| 362 | dstat->Enable(false); |
| 363 | DisplayScoreScreen = false; |
| 364 | Data->iRet = 1; |
| 365 | } |
| 366 | break; |
| 367 | } |
| 368 | |
| 369 | DMFCBase->OnKeypress(key); |
| 370 | } |
| 371 | |
| 372 | // The server has just started, so clear out all the stats and game info |
| 373 | void OnServerGameCreated(void) { DMFCBase->OnServerGameCreated(); } |
| 374 | |
| 375 | // The server has started a new level, so clear out any scores needed to be reset |
| 376 | void OnClientLevelStart(void) { |
| 377 | for (int i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 378 | SortedPlayers[i] = -1; |
| 379 | } |
| 380 | |
| 381 | DMFCBase->OnClientLevelStart(); |
| 382 | } |
| 383 | |
| 384 | void OnClientLevelEnd(void) { DMFCBase->OnClientLevelEnd(); } |
| 385 | |
| 386 | // A new player has entered the game, zero their stats out |
| 387 | void OnClientPlayerEntersGame(int player_num) { |
| 388 | DMFCBase->OnClientPlayerEntersGame(player_num); |
| 389 | |
| 390 | if (player_num != DMFCBase->GetPlayerNum()) |
| 391 | DisplayWelcomeMessage(player_num); |
| 392 | else |
| 393 | display_my_welcome = true; |
| 394 | } |
| 395 | |
| 396 | // We need to adjust the scores |
| 397 | void OnClientPlayerKilled(object *killer_obj, int victim_pnum) { |
| 398 | DMFCBase->OnClientPlayerKilled(killer_obj, victim_pnum); |
| 399 | player_record *kpr; |
| 400 | |
| 401 | int kpnum; |
| 402 | |
| 403 | if (killer_obj) { |
| 404 | if ((killer_obj->type == OBJ_PLAYER) || (killer_obj->type == OBJ_GHOST)) |
| 405 | kpnum = killer_obj->id; |
| 406 | else if (killer_obj->type == OBJ_ROBOT || killer_obj->type == OBJ_BUILDING) { |
| 407 | // countermeasure kill |
| 408 | kpnum = DMFCBase->GetCounterMeasureOwner(killer_obj); |
| 409 | } else { |
| 410 | kpnum = -1; |
| 411 | } |
| 412 | } else { |
| 413 | kpnum = -1; |
| 414 | } |
| 415 | |
| 416 | kpr = DMFCBase->GetPlayerRecordByPnum(kpnum); |
| 417 | if (kpr) { |
| 418 | int goal; |
| 419 | if (DMFCBase->GetScoreLimit(&goal)) { |
| 420 | int score = kpr->dstats.kills[DSTAT_LEVEL] - kpr->dstats.suicides[DSTAT_LEVEL]; |
| 421 | if (score >= goal) { |
| 422 | DMFCBase->EndLevel(); |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | bool compare_slots(int a, int b) { |
| 429 | int ascore, bscore; |
| 430 | player_record *apr, *bpr; |
| 431 | apr = DMFCBase->GetPlayerRecord(a); |
| 432 | bpr = DMFCBase->GetPlayerRecord(b); |
| 433 | if (!apr) |
| 434 | return true; |
| 435 | if (!bpr) |
| 436 | return false; |
| 437 | if (apr->state == STATE_EMPTY) |
| 438 | return true; |
| 439 | if (bpr->state == STATE_EMPTY) |
| 440 | return false; |
| 441 | if ((apr->state == STATE_INGAME) && (bpr->state == STATE_INGAME)) { |
| 442 | // both players were in the game |
| 443 | ascore = apr->dstats.kills[DSTAT_LEVEL] - apr->dstats.suicides[DSTAT_LEVEL]; |
| 444 | bscore = bpr->dstats.kills[DSTAT_LEVEL] - bpr->dstats.suicides[DSTAT_LEVEL]; |
| 445 | return (ascore < bscore); |
| 446 | } |
| 447 | if ((apr->state == STATE_INGAME) && (bpr->state == STATE_DISCONNECTED)) { |
| 448 | // apr gets priority since he was in the game on exit |
| 449 | return false; |
| 450 | } |
| 451 | if ((apr->state == STATE_DISCONNECTED) && (bpr->state == STATE_INGAME)) { |
| 452 | // bpr gets priority since he was in the game on exit |
| 453 | return true; |
| 454 | } |
| 455 | // if we got here then both players were disconnected |
| 456 | ascore = apr->dstats.kills[DSTAT_LEVEL] - apr->dstats.suicides[DSTAT_LEVEL]; |
| 457 | bscore = bpr->dstats.kills[DSTAT_LEVEL] - bpr->dstats.suicides[DSTAT_LEVEL]; |
| 458 | return (ascore < bscore); |
| 459 | } |
| 460 | |
| 461 | void OnPLRInit(void) { |
| 462 | int tempsort[MAX_PLAYER_RECORDS]; |
| 463 | int i, t, j; |
| 464 | |
| 465 | for (i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 466 | tempsort[i] = i; |
| 467 | } |
| 468 | |
| 469 | for (i = 1; i <= MAX_PLAYER_RECORDS - 1; i++) { |
| 470 | t = tempsort[i]; |
| 471 | // Shift elements down until |
| 472 | // insertion point found. |
| 473 | for (j = i - 1; j >= 0 && compare_slots(tempsort[j], t); j--) { |
| 474 | tempsort[j + 1] = tempsort[j]; |
| 475 | } |
| 476 | // insert |
| 477 | tempsort[j + 1] = t; |
| 478 | } |
| 479 | |
| 480 | // copy the array over |
| 481 | memcpy(SortedPlayers, tempsort, DLLMAX_PLAYERS * sizeof(int)); |
| 482 | |
| 483 | DMFCBase->OnPLRInit(); |
| 484 | } |
| 485 | |
| 486 | void OnPLRInterval(void) { |
| 487 | #define PLAYERS_COL 130 |
| 488 | #define SCORE_COL 280 |
| 489 | #define DEATHS_COL 330 |
| 490 | #define SUICIDES_COL 390 |
| 491 | #define TOTAL_COL 460 |
| 492 | |
| 493 | DMFCBase->OnPLRInterval(); |
| 494 | |
| 495 | int y = 40; |
| 496 | |
| 497 | int height = DLLgrfont_GetHeight((DMFCBase->GetGameFontTranslateArray())[SMALL_UI_FONT_INDEX]) + 1; |
| 498 | DLLgrtext_SetFont((DMFCBase->GetGameFontTranslateArray())[SMALL_UI_FONT_INDEX]); |
| 499 | |
| 500 | // print out header |
| 501 | DLLgrtext_SetColor(GR_RGB(255, 255, 150)); |
| 502 | DLLgrtext_Printf(PLAYERS_COL, y, TXT_PILOT); |
| 503 | DLLgrtext_Printf(SCORE_COL, y, TXT_KILLS_SHORT); |
| 504 | DLLgrtext_Printf(DEATHS_COL, y, TXT_DEATHS_SHORT); |
| 505 | DLLgrtext_Printf(SUICIDES_COL, y, TXT_SUICIDES_SHORT); |
| 506 | DLLgrtext_Printf(TOTAL_COL, y, TXT_SCORE); |
| 507 | y += height; |
| 508 | |
| 509 | // print out player stats |
| 510 | int rank = 1; |
| 511 | int slot, pnum; |
| 512 | player_record *pr; |
| 513 | |
| 514 | for (int i = 0; i < DLLMAX_PLAYERS; i++) { |
| 515 | slot = SortedPlayers[i]; |
| 516 | pr = DMFCBase->GetPlayerRecord(slot); |
| 517 | if ((pr) && (pr->state != STATE_EMPTY)) { |
| 518 | |
| 519 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 520 | continue; // skip a dedicated server |
| 521 | |
| 522 | pnum = DMFCBase->WasPlayerInGameAtLevelEnd(slot); |
| 523 | if (pnum != -1) { |
| 524 | DLLgrtext_SetColor((DMFCBase->GetPlayerColors())[pnum]); |
| 525 | } else { |
| 526 | DLLgrtext_SetColor(GR_RGB(128, 128, 128)); |
| 527 | } |
| 528 | |
| 529 | char temp[100]; |
| 530 | snprintf(temp, sizeof(temp), "%d)%s", rank, pr->callsign); |
| 531 | DMFCBase->ClipString(SCORE_COL - PLAYERS_COL - 10, temp, true); |
| 532 | DLLgrtext_Printf(PLAYERS_COL, y, "%s", temp); |
| 533 | |
| 534 | DLLgrtext_Printf(SCORE_COL, y, "%d", pr->dstats.kills[DSTAT_LEVEL]); |
| 535 | DLLgrtext_Printf(DEATHS_COL, y, "%d", pr->dstats.deaths[DSTAT_LEVEL]); |
| 536 | DLLgrtext_Printf(SUICIDES_COL, y, "%d", pr->dstats.suicides[DSTAT_LEVEL]); |
| 537 | DLLgrtext_Printf(TOTAL_COL, y, "%d", pr->dstats.kills[DSTAT_LEVEL] - pr->dstats.suicides[DSTAT_LEVEL]); |
| 538 | y += height; |
| 539 | rank++; |
| 540 | |
| 541 | if (y >= 440) |
| 542 | goto quick_exit; |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | quick_exit:; |
| 547 | } |
| 548 | |
| 549 | void SaveStatsToFile(char *filename) { |
| 550 | CFILE *file; |
| 551 | DLLOpenCFILE(&file, filename, "wt"); |
| 552 | if (!file) { |
| 553 | mprintf(0, "Unable to open output file\n"); |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | // write out game stats |
| 558 | #define BUFSIZE 150 |
| 559 | char buffer[BUFSIZE]; |
| 560 | char tempbuffer[25]; |
| 561 | int sortedslots[MAX_PLAYER_RECORDS]; |
| 562 | player_record *pr, *dpr; |
| 563 | tPInfoStat stat; |
| 564 | int count, p; |
| 565 | |
| 566 | // sort the stats |
| 567 | DMFCBase->GetSortedPlayerSlots(sortedslots, MAX_PLAYER_RECORDS); |
| 568 | count = 1; |
| 569 | |
| 570 | snprintf(buffer, sizeof(buffer), TXT_SAVE_HEADER, (DMFCBase->GetNetgameInfo())->name, |
| 571 | (DMFCBase->GetCurrentMission())->cur_level); |
| 572 | DLLcf_WriteString(file, buffer); |
| 573 | |
| 574 | snprintf(buffer, sizeof(buffer), "%s", TXT_SAVE_HEADERB); |
| 575 | DLLcf_WriteString(file, buffer); |
| 576 | strcpy(buffer, "-----------------------------------------------------------------------------------------------"); |
| 577 | DLLcf_WriteString(file, buffer); |
| 578 | |
| 579 | for (int s = 0; s < MAX_PLAYER_RECORDS; s++) { |
| 580 | p = sortedslots[s]; |
| 581 | pr = DMFCBase->GetPlayerRecord(p); |
| 582 | if (pr && pr->state != STATE_EMPTY) { |
| 583 | |
| 584 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 585 | continue; // skip dedicated server |
| 586 | |
| 587 | memset(buffer, ' ', BUFSIZE); |
| 588 | |
| 589 | snprintf(tempbuffer, sizeof(tempbuffer), "%d)", count); |
| 590 | memcpy(&buffer[0], tempbuffer, strlen(tempbuffer)); |
| 591 | |
| 592 | snprintf(tempbuffer, sizeof(tempbuffer), "%s%s", (pr->state == STATE_INGAME) ? "" : "*", pr->callsign); |
| 593 | memcpy(&buffer[7], tempbuffer, strlen(tempbuffer)); |
| 594 | |
| 595 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", |
| 596 | pr->dstats.kills[DSTAT_LEVEL] - pr->dstats.suicides[DSTAT_LEVEL], |
| 597 | pr->dstats.kills[DSTAT_OVERALL] - pr->dstats.suicides[DSTAT_OVERALL]); |
| 598 | memcpy(&buffer[36], tempbuffer, strlen(tempbuffer)); |
| 599 | |
| 600 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", pr->dstats.kills[DSTAT_LEVEL], |
| 601 | pr->dstats.kills[DSTAT_OVERALL]); |
| 602 | memcpy(&buffer[48], tempbuffer, strlen(tempbuffer)); |
| 603 | |
| 604 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", pr->dstats.deaths[DSTAT_LEVEL], |
| 605 | pr->dstats.deaths[DSTAT_OVERALL]); |
| 606 | memcpy(&buffer[60], tempbuffer, strlen(tempbuffer)); |
| 607 | |
| 608 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", pr->dstats.suicides[DSTAT_LEVEL], |
| 609 | pr->dstats.suicides[DSTAT_OVERALL]); |
| 610 | memcpy(&buffer[71], tempbuffer, strlen(tempbuffer)); |
| 611 | |
| 612 | snprintf(tempbuffer, sizeof(tempbuffer), "%s", DMFCBase->GetTimeString(DMFCBase->GetTimeInGame(p))); |
| 613 | memcpy(&buffer[82], tempbuffer, strlen(tempbuffer)); |
| 614 | |
| 615 | size_t pos = 82 + strlen(tempbuffer) + 1; |
| 616 | if (pos < BUFSIZE) |
| 617 | buffer[pos] = '\0'; |
| 618 | |
| 619 | buffer[BUFSIZE - 1] = '\0'; |
| 620 | DLLcf_WriteString(file, buffer); |
| 621 | count++; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | DLLcf_WriteString(file, TXT_SAVE_HEADERC); |
| 626 | |
| 627 | count = 1; |
| 628 | for (p = 0; p < MAX_PLAYER_RECORDS; p++) { |
| 629 | pr = DMFCBase->GetPlayerRecord(p); |
| 630 | if (pr && pr->state != STATE_EMPTY) { |
| 631 | |
| 632 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 633 | continue; // skip dedicated server |
| 634 | |
| 635 | // Write out header |
| 636 | snprintf(buffer, sizeof(buffer), "%d) %s%s", count, (pr->state == STATE_INGAME) ? "" : "*", pr->callsign); |
| 637 | DLLcf_WriteString(file, buffer); |
| 638 | size_t length = strlen(buffer); |
| 639 | memset(buffer, '=', length); |
| 640 | buffer[length] = '\0'; |
| 641 | DLLcf_WriteString(file, buffer); |
| 642 | |
| 643 | // time in game |
| 644 | snprintf(buffer, sizeof(buffer), TXT_SAVE_TIMEINGAME, DMFCBase->GetTimeString(DMFCBase->GetTimeInGame(p))); |
| 645 | DLLcf_WriteString(file, buffer); |
| 646 | |
| 647 | if (DMFCBase->FindPInfoStatFirst(p, &stat)) { |
| 648 | snprintf(buffer, sizeof(buffer), "%s", TXT_SAVE_KILLERLIST); |
| 649 | DLLcf_WriteString(file, buffer); |
| 650 | |
| 651 | if (stat.slot != p) { |
| 652 | memset(buffer, ' ', BUFSIZE); |
| 653 | dpr = DMFCBase->GetPlayerRecord(stat.slot); |
| 654 | |
| 655 | ASSERT(dpr != NULL); |
| 656 | if (dpr) { |
| 657 | snprintf(tempbuffer, sizeof(tempbuffer), "%s", dpr->callsign); |
| 658 | memcpy(buffer, tempbuffer, strlen(tempbuffer)); |
| 659 | |
| 660 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.kills); |
| 661 | memcpy(&buffer[30], tempbuffer, strlen(tempbuffer)); |
| 662 | |
| 663 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.deaths); |
| 664 | memcpy(&buffer[40], tempbuffer, strlen(tempbuffer)); |
| 665 | |
| 666 | size_t pos = 40 + strlen(tempbuffer) + 1; |
| 667 | if (pos < BUFSIZE) |
| 668 | buffer[pos] = '\0'; |
| 669 | |
| 670 | buffer[BUFSIZE - 1] = '\0'; |
| 671 | DLLcf_WriteString(file, buffer); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | while (DMFCBase->FindPInfoStatNext(&stat)) { |
| 676 | if (stat.slot != p) { |
| 677 | memset(buffer, ' ', BUFSIZE); |
| 678 | dpr = DMFCBase->GetPlayerRecord(stat.slot); |
| 679 | |
| 680 | if (dpr) { |
| 681 | snprintf(tempbuffer, sizeof(tempbuffer), "%s", dpr->callsign); |
| 682 | memcpy(buffer, tempbuffer, strlen(tempbuffer)); |
| 683 | |
| 684 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.kills); |
| 685 | memcpy(&buffer[30], tempbuffer, strlen(tempbuffer)); |
| 686 | |
| 687 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.deaths); |
| 688 | memcpy(&buffer[40], tempbuffer, strlen(tempbuffer)); |
| 689 | |
| 690 | size_t pos = 40 + strlen(tempbuffer) + 1; |
| 691 | if (pos < BUFSIZE) |
| 692 | buffer[pos] = '\0'; |
| 693 | |
| 694 | buffer[BUFSIZE - 1] = '\0'; |
| 695 | DLLcf_WriteString(file, buffer); |
| 696 | } |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | DMFCBase->FindPInfoStatClose(); |
| 701 | DLLcf_WriteString(file, ""); // skip a line |
| 702 | count++; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | // done writing stats |
| 707 | DLLcfclose(file); |
| 708 | DLLAddHUDMessage(TXT_MSG_SAVESTATS); |
| 709 | } |
| 710 | |
| 711 | #define ROOTFILENAME "Anarchy" |
| 712 | void OnSaveStatsToFile(void) { |
| 713 | char filename[256]; |
| 714 | DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); |
| 715 | SaveStatsToFile(filename); |
| 716 | } |
| 717 | |
| 718 | void OnLevelEndSaveStatsToFile(void) { |
| 719 | char filename[256]; |
| 720 | DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); |
| 721 | SaveStatsToFile(filename); |
| 722 | } |
| 723 | |
| 724 | void OnDisconnectSaveStatsToFile(void) { |
| 725 | char filename[256]; |
| 726 | DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); |
| 727 | SaveStatsToFile(filename); |
| 728 | } |
| 729 | |
| 730 | void OnPrintScores(int level) { |
| 731 | char buffer[256]; |
| 732 | char name[50]; |
| 733 | memset(buffer, ' ', 256); |
| 734 | |
| 735 | size_t t; |
| 736 | size_t pos[6]; |
| 737 | size_t len[6]; |
| 738 | pos[0] = 0; |
| 739 | t = len[0] = 20; // give ample room for pilot name |
| 740 | pos[1] = pos[0] + t + 1; |
| 741 | t = len[1] = strlen(TXT_POINTS); |
| 742 | pos[2] = pos[1] + t + 1; |
| 743 | t = len[2] = strlen(TXT_KILLS_SHORT); |
| 744 | pos[3] = pos[2] + t + 1; |
| 745 | t = len[3] = strlen(TXT_DEATHS_SHORT); |
| 746 | pos[4] = pos[3] + t + 1; |
| 747 | t = len[4] = strlen(TXT_SUICIDES_SHORT); |
| 748 | pos[5] = pos[4] + t + 1; |
| 749 | t = len[5] = strlen(TXT_PING); |
| 750 | |
| 751 | memcpy(&buffer[pos[0]], TXT_PILOT, strlen(TXT_PILOT)); |
| 752 | memcpy(&buffer[pos[1]], TXT_POINTS, len[1]); |
| 753 | memcpy(&buffer[pos[2]], TXT_KILLS_SHORT, len[2]); |
| 754 | memcpy(&buffer[pos[3]], TXT_DEATHS_SHORT, len[3]); |
| 755 | memcpy(&buffer[pos[4]], TXT_SUICIDES_SHORT, len[4]); |
| 756 | memcpy(&buffer[pos[5]], TXT_PING, len[5]); |
| 757 | buffer[pos[5] + len[5] + 1] = '\n'; |
| 758 | buffer[pos[5] + len[5] + 2] = '\0'; |
| 759 | DPrintf(buffer); |
| 760 | |
| 761 | int slot; |
| 762 | player_record *pr; |
| 763 | int pcount; |
| 764 | |
| 765 | if (level < 0 || level >= MAX_PLAYER_RECORDS) |
| 766 | pcount = MAX_PLAYER_RECORDS; |
| 767 | else |
| 768 | pcount = level; |
| 769 | |
| 770 | int sortedplayers[MAX_PLAYER_RECORDS]; |
| 771 | DMFCBase->GetSortedPlayerSlots(sortedplayers, MAX_PLAYER_RECORDS); |
| 772 | |
| 773 | for (int i = 0; i < pcount; i++) { |
| 774 | slot = sortedplayers[i]; |
| 775 | pr = DMFCBase->GetPlayerRecord(slot); |
| 776 | if ((pr) && (pr->state != STATE_EMPTY)) { |
| 777 | |
| 778 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 779 | continue; // skip dedicated server |
| 780 | |
| 781 | snprintf(name, sizeof(name), "%s%s:", (pr->state == STATE_DISCONNECTED) ? "*" : "", pr->callsign); |
| 782 | name[19] = '\0'; |
| 783 | |
| 784 | memset(buffer, ' ', 256); |
| 785 | t = strlen(name); |
| 786 | memcpy(&buffer[pos[0]], name, (t < len[0]) ? t : len[0]); |
| 787 | snprintf(name, sizeof(name), "%d", pr->dstats.kills[DSTAT_LEVEL] - pr->dstats.suicides[DSTAT_LEVEL]); |
| 788 | t = strlen(name); |
| 789 | memcpy(&buffer[pos[1]], name, (t < len[1]) ? t : len[1]); |
| 790 | snprintf(name, sizeof(name), "%d", pr->dstats.kills[DSTAT_LEVEL]); |
| 791 | t = strlen(name); |
| 792 | memcpy(&buffer[pos[2]], name, (t < len[2]) ? t : len[2]); |
| 793 | snprintf(name, sizeof(name), "%d", pr->dstats.deaths[DSTAT_LEVEL]); |
| 794 | t = strlen(name); |
| 795 | memcpy(&buffer[pos[3]], name, (t < len[3]) ? t : len[3]); |
| 796 | snprintf(name, sizeof(name), "%d", pr->dstats.suicides[DSTAT_LEVEL]); |
| 797 | t = strlen(name); |
| 798 | memcpy(&buffer[pos[4]], name, (t < len[4]) ? t : len[4]); |
| 799 | |
| 800 | if (pr->state == STATE_INGAME) |
| 801 | snprintf(name, sizeof(name), "%.0f", (DMFCBase->GetNetPlayers())[pr->pnum].ping_time * 1000.0f); |
| 802 | else |
| 803 | strcpy(name, "---"); |
| 804 | t = strlen(name); |
| 805 | memcpy(&buffer[pos[5]], name, (t < len[5]) ? t : len[5]); |
| 806 | buffer[pos[5] + len[5] + 1] = '\n'; |
| 807 | buffer[pos[5] + len[5] + 2] = '\0'; |
| 808 | DPrintf(buffer); |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | void DisplayHUDScores(struct tHUDItem *hitem) { |
| 814 | if (display_my_welcome) { |
| 815 | DisplayWelcomeMessage(DMFCBase->GetPlayerNum()); |
| 816 | display_my_welcome = false; |
| 817 | } |
| 818 | |
| 819 | if (DisplayScoreScreen) |
| 820 | return; |
| 821 | |
| 822 | int height = DLLgrfont_GetHeight((DMFCBase->GetGameFontTranslateArray())[HUD_FONT_INDEX]) + 3; |
| 823 | uint8_t alpha = DMFCBase->ConvertHUDAlpha((uint8_t)((DisplayScoreScreen) ? 128 : 255)); |
| 824 | int y = (DMFCBase->GetGameWindowH() / 2) - ((height * 5) / 2); |
| 825 | int x = 520; |
| 826 | ddgr_color color = 0; |
| 827 | |
| 828 | int rank = 1; |
| 829 | player_record *pr; |
| 830 | |
| 831 | // Display your Kills & Deaths on the top corners of the screen |
| 832 | pr = DMFCBase->GetPlayerRecordByPnum(DMFCBase->GetPlayerNum()); |
| 833 | if (pr) { |
| 834 | int y = 25, x; |
| 835 | int lwidth; |
| 836 | char buffer[20]; |
| 837 | |
| 838 | int w_kill, w_death, max_w; |
| 839 | w_kill = DLLgrtext_GetTextLineWidth(TXT_KILLS); |
| 840 | w_death = DLLgrtext_GetTextLineWidth(TXT_DEATHS); |
| 841 | max_w = std::max(w_kill, w_death); |
| 842 | |
| 843 | x = DMFCBase->GetGameWindowW() - DMFCBase->GetGameWindowW() * 0.0078125f; |
| 844 | DLLgrtext_SetColor(GR_GREEN); |
| 845 | DLLgrtext_SetAlpha(alpha); |
| 846 | DLLgrtext_Printf(x - (max_w / 2) - (w_kill / 2), y, TXT_KILLS); |
| 847 | y += height; |
| 848 | |
| 849 | snprintf(buffer, sizeof(buffer), "%d", pr->dstats.kills[DSTAT_LEVEL]); |
| 850 | lwidth = DLLgrtext_GetTextLineWidth(buffer); |
| 851 | DLLgrtext_SetColor(GR_GREEN); |
| 852 | DLLgrtext_SetAlpha(alpha); |
| 853 | DLLgrtext_Printf(x - (max_w / 2) - (lwidth / 2), y, buffer); |
| 854 | y += height + 3; |
| 855 | |
| 856 | DLLgrtext_SetColor(GR_GREEN); |
| 857 | DLLgrtext_SetAlpha(alpha); |
| 858 | DLLgrtext_Printf(x - (max_w / 2) - (w_death / 2), y, TXT_DEATHS); |
| 859 | y += height; |
| 860 | |
| 861 | snprintf(buffer, sizeof(buffer), "%d", pr->dstats.deaths[DSTAT_LEVEL]); |
| 862 | lwidth = DLLgrtext_GetTextLineWidth(buffer); |
| 863 | DLLgrtext_SetColor(GR_GREEN); |
| 864 | DLLgrtext_SetAlpha(alpha); |
| 865 | DLLgrtext_Printf(x - (max_w / 2) - (lwidth / 2), y, buffer); |
| 866 | } |
| 867 | |
| 868 | int ESortedPlayers[DLLMAX_PLAYERS]; |
| 869 | |
| 870 | switch (Anarchy_hud_display) { |
| 871 | case AHD_NONE: |
| 872 | return; |
| 873 | break; |
| 874 | case AHD_EFFICIENCY: |
| 875 | DMFCBase->GetSortedPlayerSlots(ESortedPlayers, DLLMAX_PLAYERS); |
| 876 | break; |
| 877 | } |
| 878 | |
| 879 | char name[30]; |
| 880 | |
| 881 | // determine coordinates to use here |
| 882 | // we'll use a virtual width of 85 pixels on a 640x480 screen |
| 883 | // so first determine the new width |
| 884 | int name_width = 85.0f * DMFCBase->GetHudAspectX(); |
| 885 | int score_width = DLLgrtext_GetTextLineWidth("888"); |
| 886 | int name_x = DMFCBase->GetGameWindowW() - name_width - score_width - 10; |
| 887 | int score_x = DMFCBase->GetGameWindowW() - score_width - 5; |
| 888 | |
| 889 | for (int i = 0; i < DLLMAX_PLAYERS; i++) { |
| 890 | int slot; |
| 891 | |
| 892 | if (Anarchy_hud_display == AHD_EFFICIENCY) |
| 893 | slot = ESortedPlayers[i]; |
| 894 | else |
| 895 | slot = SortedPlayers[i]; |
| 896 | |
| 897 | pr = DMFCBase->GetPlayerRecord(slot); |
| 898 | |
| 899 | if ((pr) && (pr->state != STATE_EMPTY)) { |
| 900 | |
| 901 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 902 | continue; // skip dedicated server |
| 903 | |
| 904 | if ((pr->state == STATE_DISCONNECTED) || (pr->state == STATE_INGAME && !DMFCBase->IsPlayerObserver(pr->pnum))) { |
| 905 | |
| 906 | if (pr->pnum == DMFCBase->GetPlayerNum()) { |
| 907 | |
| 908 | switch (HUD_color_model) { |
| 909 | case ACM_PLAYERCOLOR: |
| 910 | color = (DMFCBase->GetPlayerColors())[pr->pnum]; |
| 911 | break; |
| 912 | case ACM_NORMAL: |
| 913 | color = GR_RGB(40, 255, 40); |
| 914 | break; |
| 915 | }; |
| 916 | |
| 917 | if (Highlight_bmp > BAD_BITMAP_HANDLE) { |
| 918 | // draw the highlite bar in the background |
| 919 | DLLrend_SetAlphaValue(alpha * 0.50f); |
| 920 | DLLrend_SetZBufferState(0); |
| 921 | DLLrend_SetTextureType(TT_LINEAR); |
| 922 | DLLrend_SetLighting(LS_NONE); |
| 923 | DLLrend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 924 | DLLrend_DrawScaledBitmap(name_x - 2, y - 2, score_x + score_width + 2, y + height - 1, Highlight_bmp, 0, 0, |
| 925 | 1, 1, 1.0, -1, NULL); |
| 926 | DLLrend_SetZBufferState(1); |
| 927 | } |
| 928 | |
| 929 | strcpy(name, pr->callsign); |
| 930 | DMFCBase->ClipString(name_width, name, true); |
| 931 | |
| 932 | DLLgrtext_SetAlpha(alpha); |
| 933 | DLLgrtext_SetColor(color); |
| 934 | DLLgrtext_Printf(name_x, y, "%s", name); |
| 935 | |
| 936 | if (Anarchy_hud_display == AHD_EFFICIENCY) { |
| 937 | float t = pr->dstats.kills[DSTAT_LEVEL] + pr->dstats.suicides[DSTAT_LEVEL] + pr->dstats.deaths[DSTAT_LEVEL]; |
| 938 | float value = (float)(pr->dstats.kills[DSTAT_LEVEL]) / ((t) ? t : 0.0000001f); |
| 939 | DLLgrtext_Printf(score_x, y, "%.1f", value); |
| 940 | } else { |
| 941 | DLLgrtext_Printf(score_x, y, "%d", pr->dstats.kills[DSTAT_LEVEL] - pr->dstats.suicides[DSTAT_LEVEL]); |
| 942 | } |
| 943 | |
| 944 | y += height; |
| 945 | } else if (rank < 6) { |
| 946 | |
| 947 | if (pr->state == STATE_DISCONNECTED) { |
| 948 | color = GR_GREY; |
| 949 | } else { |
| 950 | switch (HUD_color_model) { |
| 951 | case ACM_PLAYERCOLOR: |
| 952 | color = (DMFCBase->GetPlayerColors())[pr->pnum]; |
| 953 | break; |
| 954 | case ACM_NORMAL: |
| 955 | color = GR_RGB(40, 255, 40); |
| 956 | break; |
| 957 | }; |
| 958 | } |
| 959 | strcpy(name, pr->callsign); |
| 960 | DMFCBase->ClipString(name_width, name, true); |
| 961 | |
| 962 | DLLgrtext_SetAlpha(alpha); |
| 963 | DLLgrtext_SetColor(color); |
| 964 | DLLgrtext_Printf(name_x, y, "%s", name); |
| 965 | |
| 966 | if (Anarchy_hud_display == AHD_EFFICIENCY) { |
| 967 | float t = pr->dstats.kills[DSTAT_LEVEL] + pr->dstats.suicides[DSTAT_LEVEL] + pr->dstats.deaths[DSTAT_LEVEL]; |
| 968 | float value = (float)(pr->dstats.kills[DSTAT_LEVEL]) / ((t) ? t : 0.0000001f); |
| 969 | DLLgrtext_Printf(score_x, y, "%.1f", value); |
| 970 | } else { |
| 971 | DLLgrtext_Printf(score_x, y, "%d", pr->dstats.kills[DSTAT_LEVEL] - pr->dstats.suicides[DSTAT_LEVEL]); |
| 972 | } |
| 973 | |
| 974 | y += height; |
| 975 | } |
| 976 | rank++; |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | void DisplayWelcomeMessage(int player_num) { |
| 983 | char name_buffer[64]; |
| 984 | strcpy(name_buffer, (DMFCBase->GetPlayers())[player_num].callsign); |
| 985 | |
| 986 | if (player_num == DMFCBase->GetPlayerNum()) { |
| 987 | DLLAddHUDMessage(TXT_WELCOME, name_buffer); |
| 988 | } else { |
| 989 | DLLAddHUDMessage(TXT_JOINED, name_buffer); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | void SwitchHUDColor(int i) { |
| 994 | if (i < 0 || i > 1) |
| 995 | return; |
| 996 | HUD_color_model = i; |
| 997 | |
| 998 | switch (HUD_color_model) { |
| 999 | case ACM_PLAYERCOLOR: |
| 1000 | DLLAddHUDMessage(TXT_MSG_COLORPLR); |
| 1001 | break; |
| 1002 | case ACM_NORMAL: |
| 1003 | DLLAddHUDMessage(TXT_MSG_COLORNORM); |
| 1004 | break; |
| 1005 | }; |
| 1006 | } |