| 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/hoard/hoard.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003/08/26 03:57:53 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * <insert description of file here> |
| 26 | * |
| 27 | * $Log: hoard.cpp,v $ |
| 28 | * Revision 1.1.1.1 2003/08/26 03:57:53 kevinb |
| 29 | * initial 1.5 import |
| 30 | * |
| 31 | * |
| 32 | * 91 10/21/99 9:27p Jeff |
| 33 | * B.A. Macintosh code merge |
| 34 | * |
| 35 | * 90 8/11/99 6:37p Jeff |
| 36 | * added input command for min count to score |
| 37 | * |
| 38 | * 89 7/12/99 1:22p Jeff |
| 39 | * updated for new netflags |
| 40 | * |
| 41 | * 88 7/12/99 1:16p Jeff |
| 42 | * fixed bug when a player dies they sometimes pickup their orb |
| 43 | * |
| 44 | * 87 7/11/99 6:44p Jeff |
| 45 | * cleaner plr if the list is too long |
| 46 | * |
| 47 | * 86 5/23/99 3:08a Jeff |
| 48 | * fixed stats display |
| 49 | * |
| 50 | * 85 5/23/99 3:04a Jason |
| 51 | * fixed bug with player rankings not being updated correctly |
| 52 | * |
| 53 | * 84 5/20/99 9:40p Jeff |
| 54 | * fixed hardlock for a client just joining the game if someone has a |
| 55 | * hoard orb |
| 56 | * |
| 57 | * 83 5/12/99 11:04p Jeff |
| 58 | * dmfc and multiplayer games now have endian friendly packets (*whew*) |
| 59 | * |
| 60 | * 82 5/12/99 11:28a Jeff |
| 61 | * added sourcesafe comment block |
| 62 | * |
| 63 | * $NoKeywords: $ |
| 64 | */ |
| 65 | |
| 66 | #include "gamedll_header.h" |
| 67 | #include <string.h> |
| 68 | #include "idmfc.h" |
| 69 | #include "Hoard.h" |
| 70 | #include "hoardstr.h" |
| 71 | #include "hoardaux.h" |
| 72 | |
| 73 | #include <algorithm> |
| 74 | |
| 75 | IDMFC *DMFCBase = NULL; |
| 76 | static IDmfcStats *dstat = NULL; |
| 77 | static IMenuItem *OSMenuSave = NULL; |
| 78 | static object *dObjects = NULL; |
| 79 | static player *dPlayers = NULL; |
| 80 | |
| 81 | #define SPID_INVINFO 1 // packet for hoard inventory info |
| 82 | #define SPID_GAMECONFIG 2 |
| 83 | |
| 84 | #define HOARD_CONFIG_DLG 1234 |
| 85 | #define HCM_PLAYERCOLOR 0 |
| 86 | #define HCM_NORMAL 1 |
| 87 | |
| 88 | struct tPlayerStat { |
| 89 | int Score[2]; |
| 90 | int HighestScore[2]; |
| 91 | }; |
| 92 | static int pack_pstat(tPlayerStat *user_info, uint8_t *data); |
| 93 | static int unpack_pstat(tPlayerStat *user_info, uint8_t *data); |
| 94 | int pack_pstat(tPlayerStat *user_info, uint8_t *data) { |
| 95 | int count = 0; |
| 96 | MultiAddInt(user_info->Score[0], data, &count); |
| 97 | MultiAddInt(user_info->Score[1], data, &count); |
| 98 | MultiAddInt(user_info->HighestScore[0], data, &count); |
| 99 | MultiAddInt(user_info->HighestScore[1], data, &count); |
| 100 | return count; |
| 101 | } |
| 102 | |
| 103 | int unpack_pstat(tPlayerStat *user_info, uint8_t *data) { |
| 104 | int count = 0; |
| 105 | user_info->Score[0] = MultiGetInt(data, &count); |
| 106 | user_info->Score[1] = MultiGetInt(data, &count); |
| 107 | user_info->HighestScore[0] = MultiGetInt(data, &count); |
| 108 | user_info->HighestScore[1] = MultiGetInt(data, &count); |
| 109 | return count; |
| 110 | } |
| 111 | |
| 112 | static tGameConfig config; |
| 113 | |
| 114 | static int SortedPlayers[MAX_PLAYER_RECORDS]; // sorted player nums |
| 115 | static bool DisplayScoreScreen; |
| 116 | static int HoardID = 0; |
| 117 | static int HoardOrbIcon = BAD_BITMAP_HANDLE; |
| 118 | static bool DisplayBlink = true; |
| 119 | static int WhoJustScored = -1; |
| 120 | static int WhoJustScoredTimer = -1; |
| 121 | static uint8_t HUD_color_model = HCM_PLAYERCOLOR; |
| 122 | static int Highlight_bmp = -1; |
| 123 | static bool display_my_welcome = false; |
| 124 | |
| 125 | static void OnTimer(void); |
| 126 | static void OnTimerKill(void); |
| 127 | static void DisplayWelcomeMessage(int player_num); |
| 128 | static void DisplayHUDScores(struct tHUDItem *hitem); |
| 129 | static void SortPlayerScores(int *sortedindex, int size); |
| 130 | static void DisplayWelcomeMessage(int player_num); |
| 131 | static void DoBallsEffect(int i, int count); |
| 132 | static void ReceiveHoardInv(uint8_t *data); |
| 133 | static void SendHoardInv(int playernum); |
| 134 | static void SaveStatsToFile(char *filename); |
| 135 | static void ReceiveGameConfig(uint8_t *data); |
| 136 | static void OnClientPlayerEntersGame(int player_num); |
| 137 | |
| 138 | static bool Config_displayed = false; |
| 139 | |
| 140 | /////////////////////////////////////////////// |
| 141 | // localization info |
| 142 | static char **StringTable; |
| 143 | static int StringTableSize = 0; |
| 144 | static const char *_ErrorString = "Missing String"; |
| 145 | const char *GetStringFromTable(int d) { |
| 146 | if ((d < 0) || (d >= StringTableSize)) |
| 147 | return _ErrorString; |
| 148 | else |
| 149 | return StringTable[d]; |
| 150 | } |
| 151 | /////////////////////////////////////////////// |
| 152 | |
| 153 | // This function gets called by the game when it wants to learn some info about the game |
| 154 | void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options) { |
| 155 | options->flags = DOF_MAXTEAMS; |
| 156 | options->max_teams = 1; |
| 157 | strcpy(options->game_name, TXT_GAMENAME); |
| 158 | strcpy(options->requirements, "MINGOALS1"); |
| 159 | } |
| 160 | |
| 161 | void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size) { |
| 162 | player_record *pr = DMFCBase->GetPlayerRecord(precord_num); |
| 163 | if (!pr || pr->state == STATE_EMPTY) { |
| 164 | buffer[0] = '\0'; |
| 165 | return; |
| 166 | } |
| 167 | tPlayerStat *stat = (tPlayerStat *)pr->user_info; |
| 168 | |
| 169 | if (column_num == 2) { |
| 170 | // Score |
| 171 | snprintf(buffer, buffer_size, "%d[%d]", stat->Score[DSTAT_LEVEL], stat->Score[DSTAT_OVERALL]); |
| 172 | } else { |
| 173 | // Highest Score |
| 174 | snprintf(buffer, buffer_size, "%d[%d]", stat->HighestScore[DSTAT_LEVEL], stat->HighestScore[DSTAT_OVERALL]); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | void ShowStatBitmap(int precord_num, int column_num, int x, int y, int w, int h, uint8_t alpha_to_use) { |
| 179 | player_record *pr = DMFCBase->GetPlayerRecord(precord_num); |
| 180 | float ratio = DEFAULT_HUD_WIDTH / ((float)DMFCBase->GetGameWindowW()); |
| 181 | |
| 182 | if (pr && pr->state == STATE_INGAME) { |
| 183 | DLLRenderHUDText(GR_GREY, alpha_to_use, 0, x, y, "%d", DLLInvGetTypeIDCount(pr->pnum, OBJ_POWERUP, HoardID)); |
| 184 | x += (ratio * ((float)DLLgrtext_GetTextLineWidth("12"))) + 1; |
| 185 | DLLRenderHUDQuad(x, y, 10, 10, 0, 0, 1, 1, HoardOrbIcon, alpha_to_use, 0); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | // We import these from DMFC |
| 190 | bool StringParseNumber(const char *string, int *number, const char **newpos); |
| 191 | bool StringParseWord(const char *string, char *word, int size, const char **newpos); |
| 192 | /* |
| 193 | bool StringParseWord(const char *string,char *word,int size,const char **newpos) |
| 194 | { |
| 195 | *newpos = string; |
| 196 | word[0] = '\0'; |
| 197 | |
| 198 | //get through all the whitespace |
| 199 | while( *string && *string==' ') string++; |
| 200 | if(!(*string)){ |
| 201 | //nothing is left in the string |
| 202 | *newpos = string; |
| 203 | return false; |
| 204 | } |
| 205 | |
| 206 | //we're at the beginning of a word |
| 207 | while( *string && *string!=' '){ |
| 208 | if(size>1){ |
| 209 | *word = *string; |
| 210 | size--; |
| 211 | } |
| 212 | |
| 213 | word++; |
| 214 | string++; |
| 215 | } |
| 216 | |
| 217 | //tack on an ending \0 |
| 218 | *word = '\0'; |
| 219 | |
| 220 | *newpos = string; |
| 221 | return true; |
| 222 | } |
| 223 | |
| 224 | bool StringParseNumber(const char *string,int *number,const char **newpos) |
| 225 | { |
| 226 | char temp[10]; |
| 227 | bool ret = StringParseWord(string,temp,10,newpos); |
| 228 | if(!ret){ |
| 229 | *number = 0; |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | *number = atoi(temp); |
| 234 | return true; |
| 235 | } |
| 236 | */ |
| 237 | void DMFCInputCommand_MinCount(const char *input_string) { |
| 238 | if (DMFCBase->GetLocalRole() != LR_SERVER) |
| 239 | return; |
| 240 | if (!DMFCBase->IAmDedicatedServer()) |
| 241 | return; |
| 242 | |
| 243 | char s[20]; |
| 244 | |
| 245 | // parse "$mincount" |
| 246 | if (!StringParseWord(input_string, s, 20, &input_string)) { |
| 247 | DMFCBase->DisplayInputCommandHelp("mincount"); |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | // parse count |
| 252 | int count; |
| 253 | if (!StringParseNumber(input_string, &count, &input_string)) { |
| 254 | DMFCBase->DisplayInputCommandHelp("mincount"); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | if (count < 1) |
| 259 | count = 1; |
| 260 | if (count > 12) |
| 261 | count = 12; |
| 262 | |
| 263 | config.min_hoard = count; |
| 264 | DLLAddHUDMessage("Hoard Orb Score Minimum Count Set To %d", count); |
| 265 | } |
| 266 | |
| 267 | // Initializes the game function pointers |
| 268 | void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_use) { |
| 269 | *all_ok = 1; |
| 270 | DMFCBase = CreateDMFC(); |
| 271 | if (!DMFCBase) { |
| 272 | *all_ok = 0; |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | dstat = CreateDmfcStats(); |
| 277 | if (!dstat) { |
| 278 | *all_ok = 0; |
| 279 | return; |
| 280 | } |
| 281 | |
| 282 | DMFCBase->LoadFunctions(api_func); |
| 283 | |
| 284 | // Setup event handlers |
| 285 | DMFCBase->Set_OnInterval(OnInterval); |
| 286 | DMFCBase->Set_OnHUDInterval(OnHUDInterval); |
| 287 | DMFCBase->Set_OnKeypress(OnKeypress); |
| 288 | DMFCBase->Set_OnServerGameCreated(OnServerGameCreated); |
| 289 | DMFCBase->Set_OnClientLevelStart(OnClientLevelStart); |
| 290 | DMFCBase->Set_OnClientLevelEnd(OnClientLevelEnd); |
| 291 | DMFCBase->Set_OnGameStateRequest(OnGameStateRequest); |
| 292 | DMFCBase->Set_OnPlayerConnect(OnPlayerConnect); |
| 293 | DMFCBase->Set_OnServerPlayerChangeSegment(OnServerPlayerChangeSegment); |
| 294 | DMFCBase->Set_OnClientPlayerChangeSegment(OnClientPlayerChangeSegment); |
| 295 | DMFCBase->Set_OnServerCollide(OnServerCollide); |
| 296 | DMFCBase->Set_OnClientCollide(OnClientCollide); |
| 297 | DMFCBase->Set_OnClientPlayerKilled(OnClientPlayerKilled); |
| 298 | DMFCBase->Set_OnPLRInterval(OnPLRInterval); |
| 299 | DMFCBase->Set_OnPrintScores(OnPrintScores); |
| 300 | DMFCBase->Set_OnPLRInit(OnPLRInit); |
| 301 | DMFCBase->Set_OnSaveStatsToFile(OnSaveStatsToFile); |
| 302 | DMFCBase->Set_OnClientShowUI(OnClientShowUI); |
| 303 | DMFCBase->Set_OnDisconnectSaveStatsToFile(OnDisconnectSaveStatsToFile); |
| 304 | DMFCBase->Set_OnLevelEndSaveStatsToFile(OnLevelEndSaveStatsToFile); |
| 305 | DMFCBase->Set_OnClientPlayerEntersGame(OnClientPlayerEntersGame); |
| 306 | |
| 307 | // Setup arrays for easier to read code |
| 308 | dObjects = DMFCBase->GetObjects(); |
| 309 | dPlayers = DMFCBase->GetPlayers(); |
| 310 | |
| 311 | DLLCreateStringTable("Hoard.str", &StringTable, &StringTableSize); |
| 312 | DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); |
| 313 | if (!StringTableSize) { |
| 314 | *all_ok = 0; |
| 315 | return; |
| 316 | } |
| 317 | |
| 318 | // setup default config |
| 319 | config.min_hoard = 1; |
| 320 | |
| 321 | if (DMFCBase->AddInputCommand("mincount", |
| 322 | "[Dedicated Server Only]\nSets the minimum number of hoard orbs needed to score.\n", |
| 323 | DMFCInputCommand_MinCount, true) < 1) |
| 324 | mprintf(0, "Hoard Warning: Error Adding Input Command\n"); |
| 325 | |
| 326 | HoardGameInit(1); |
| 327 | |
| 328 | // add the death and suicide messages |
| 329 | DMFCBase->AddDeathMessage(TXT_DEATH1, true); |
| 330 | DMFCBase->AddDeathMessage(TXT_DEATH2, true); |
| 331 | DMFCBase->AddDeathMessage(TXT_DEATH3, false); |
| 332 | DMFCBase->AddDeathMessage(TXT_DEATH4, false); |
| 333 | DMFCBase->AddDeathMessage(TXT_DEATH5, true); |
| 334 | DMFCBase->AddDeathMessage(TXT_DEATH6, true); |
| 335 | DMFCBase->AddDeathMessage(TXT_DEATH7, false); |
| 336 | DMFCBase->AddDeathMessage(TXT_DEATH8, true); |
| 337 | DMFCBase->AddDeathMessage(TXT_DEATH9, true); |
| 338 | DMFCBase->AddDeathMessage(TXT_DEATH10, true); |
| 339 | |
| 340 | DMFCBase->AddSuicideMessage(TXT_SUICIDE1); |
| 341 | DMFCBase->AddSuicideMessage(TXT_SUICIDE2); |
| 342 | DMFCBase->AddSuicideMessage(TXT_SUICIDE3); |
| 343 | DMFCBase->AddSuicideMessage(TXT_SUICIDE4); |
| 344 | DMFCBase->AddSuicideMessage(TXT_SUICIDE5); |
| 345 | DMFCBase->AddSuicideMessage(TXT_SUICIDE6); |
| 346 | |
| 347 | HoardID = DLLFindObjectIDName("Hoardorb"); |
| 348 | if (HoardID == -1) { |
| 349 | DLLmprintf(0, "HOARD: BIG WARNING, COULDN'T FIND HOARD ORB ID...YOUR GAME IS IN JEOPARDY!\n"); |
| 350 | *all_ok = 0; |
| 351 | return; |
| 352 | } |
| 353 | |
| 354 | DMFCBase->SetupPlayerRecord(sizeof(tPlayerStat), (int (*)(void *, uint8_t *))pack_pstat, |
| 355 | (int (*)(void *, uint8_t *))unpack_pstat); |
| 356 | |
| 357 | DMFCBase->RegisterPacketReceiver(SPID_INVINFO, ReceiveHoardInv); |
| 358 | DMFCBase->RegisterPacketReceiver(SPID_GAMECONFIG, ReceiveGameConfig); |
| 359 | |
| 360 | DMFCBase->SetNumberOfTeams(1); |
| 361 | (DMFCBase->GetNetgameInfo())->flags |= (NF_DAMAGE_FRIENDLY | NF_TRACK_RANK); |
| 362 | |
| 363 | DMFCBase->AddHUDItemCallback(HI_TEXT, DisplayHUDScores); |
| 364 | |
| 365 | DisplayScoreScreen = false; |
| 366 | |
| 367 | HoardOrbIcon = DLLbm_AllocLoadFileBitmap("HoardICON.ogf", 0, BITMAP_FORMAT_1555); |
| 368 | if (HoardOrbIcon == -1) { |
| 369 | *all_ok = 0; |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | Highlight_bmp = DLLbm_AllocBitmap(32, 32, 0); |
| 374 | if (Highlight_bmp > BAD_BITMAP_HANDLE) { |
| 375 | uint16_t *data = DLLbm_data(Highlight_bmp, 0); |
| 376 | if (!data) { |
| 377 | // bail on out of here |
| 378 | *all_ok = 0; |
| 379 | return; |
| 380 | } |
| 381 | for (int x = 0; x < 32 * 32; x++) { |
| 382 | data[x] = GR_RGB16(50, 50, 50) | OPAQUE_FLAG; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | // Initialize the Stats Manager |
| 387 | // ---------------------------- |
| 388 | tDmfcStatsInit tsi; |
| 389 | tDmfcStatsColumnInfo pl_col[8]; |
| 390 | char gname[20]; |
| 391 | strcpy(gname, TXT_STATGAMENAME); |
| 392 | |
| 393 | tsi.flags = DSIF_SHOW_PIC | DSIF_SHOW_OBSERVERICON; |
| 394 | tsi.cColumnCountDetailed = 0; |
| 395 | tsi.cColumnCountPlayerList = 8; |
| 396 | tsi.clbDetailedColumn = NULL; |
| 397 | tsi.clbDetailedColumnBMP = NULL; |
| 398 | tsi.clbPlayerColumn = DetermineScore; |
| 399 | tsi.clbPlayerColumnBMP = ShowStatBitmap; |
| 400 | tsi.DetailedColumns = NULL; |
| 401 | tsi.GameName = gname; |
| 402 | tsi.MaxNumberDisplayed = NULL; |
| 403 | tsi.PlayerListColumns = pl_col; |
| 404 | tsi.SortedPlayerRecords = SortedPlayers; |
| 405 | |
| 406 | pl_col[0].color_type = DSCOLOR_TEAM; |
| 407 | pl_col[0].title[0] = '\0'; |
| 408 | pl_col[0].type = DSCOL_BMP; |
| 409 | pl_col[0].width = 27; |
| 410 | |
| 411 | pl_col[1].color_type = DSCOLOR_SHIPCOLOR; |
| 412 | strcpy(pl_col[1].title, TXT_PILOT); |
| 413 | pl_col[1].type = DSCOL_PILOT_NAME; |
| 414 | pl_col[1].width = 84; |
| 415 | |
| 416 | pl_col[2].color_type = DSCOLOR_SHIPCOLOR; |
| 417 | strcpy(pl_col[2].title, TXT_SCORE); |
| 418 | pl_col[2].type = DSCOL_CUSTOM; |
| 419 | pl_col[2].width = 49; |
| 420 | |
| 421 | pl_col[3].color_type = DSCOLOR_SHIPCOLOR; |
| 422 | strcpy(pl_col[3].title, TXT_HIGHEST); |
| 423 | pl_col[3].type = DSCOL_CUSTOM; |
| 424 | pl_col[3].width = 65; |
| 425 | |
| 426 | pl_col[4].color_type = DSCOLOR_SHIPCOLOR; |
| 427 | strcpy(pl_col[4].title, TXT_KILLS_SHORT); |
| 428 | pl_col[4].type = DSCOL_KILLS_LEVEL; |
| 429 | pl_col[4].width = 40; |
| 430 | |
| 431 | pl_col[5].color_type = DSCOLOR_SHIPCOLOR; |
| 432 | strcpy(pl_col[5].title, TXT_DEATHS_SHORT); |
| 433 | pl_col[5].type = DSCOL_DEATHS_LEVEL; |
| 434 | pl_col[5].width = 40; |
| 435 | |
| 436 | pl_col[6].color_type = DSCOLOR_SHIPCOLOR; |
| 437 | strcpy(pl_col[6].title, TXT_SUICIDES_SHORT); |
| 438 | pl_col[6].type = DSCOL_SUICIDES_LEVEL; |
| 439 | pl_col[6].width = 40; |
| 440 | |
| 441 | pl_col[7].color_type = DSCOLOR_SHIPCOLOR; |
| 442 | strcpy(pl_col[7].title, TXT_PING); |
| 443 | pl_col[7].type = DSCOL_PING; |
| 444 | pl_col[7].width = 40; |
| 445 | |
| 446 | dstat->Initialize(&tsi); |
| 447 | } |
| 448 | |
| 449 | // Called when the DLL is shutdown |
| 450 | void DLLFUNCCALL DLLGameClose() { |
| 451 | if (Highlight_bmp > BAD_BITMAP_HANDLE) |
| 452 | DLLbm_FreeBitmap(Highlight_bmp); |
| 453 | |
| 454 | DLLDestroyStringTable(StringTable, StringTableSize); |
| 455 | if (HoardOrbIcon > BAD_BITMAP_HANDLE) |
| 456 | DLLbm_FreeBitmap(HoardOrbIcon); |
| 457 | |
| 458 | if (dstat) { |
| 459 | dstat->DestroyPointer(); |
| 460 | dstat = NULL; |
| 461 | } |
| 462 | |
| 463 | if (DMFCBase) { |
| 464 | DMFCBase->GameClose(); |
| 465 | DMFCBase->DestroyPointer(); |
| 466 | DMFCBase = NULL; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | // DMFCApp::GameInit |
| 471 | // |
| 472 | // Sets up all the DLL functions and pointers and preps the class for use. This ABSOLUTLY must be |
| 473 | // called, so if you override DMFCApp::GameInit, make sure that you put a call to this somewhere in |
| 474 | // the override. |
| 475 | void ShowGameConfigDialog(int i); |
| 476 | void SwitchHUDColor(int i); |
| 477 | void HoardGameInit(int teams) { |
| 478 | IMenuItem *lev1, *lev2; |
| 479 | lev1 = CreateMenuItemWArgs(TXT_GAMENAME, MIT_NORMAL, 0, NULL); |
| 480 | |
| 481 | lev2 = CreateMenuItemWArgs(TXT_HUDSCORECOLORS, MIT_STATE, 0, SwitchHUDColor); |
| 482 | lev2->SetStateItemList(2, TXT_PLAYERCOLORS, TXT_NORMAL); |
| 483 | lev2->SetState(HUD_color_model); |
| 484 | lev1->AddSubMenu(lev2); |
| 485 | |
| 486 | // lev2 = CreateMenuItemWArgs(TXT_GAMECONFIG,MIT_NORMAL,0,ShowGameConfigDialog); |
| 487 | // lev1->AddSubMenu(lev2); |
| 488 | |
| 489 | IMenuItem *MainMenu = DMFCBase->GetOnScreenMenu(); |
| 490 | MainMenu->AddSubMenu(lev1); |
| 491 | |
| 492 | DMFCBase->GameInit(teams); |
| 493 | } |
| 494 | |
| 495 | void OnPrintScores(int level) { |
| 496 | char buffer[256]; |
| 497 | char name[50]; |
| 498 | memset(buffer, ' ', 256); |
| 499 | |
| 500 | size_t t; |
| 501 | size_t pos[6]; |
| 502 | size_t len[6]; |
| 503 | pos[0] = 0; |
| 504 | t = len[0] = 20; // give ample room for pilot name |
| 505 | pos[1] = pos[0] + t + 1; |
| 506 | t = len[1] = strlen(TXT_POINTS); |
| 507 | pos[2] = pos[1] + t + 1; |
| 508 | t = len[2] = strlen(TXT_KILLS); |
| 509 | pos[3] = pos[2] + t + 1; |
| 510 | t = len[3] = strlen(TXT_DEATHS); |
| 511 | pos[4] = pos[3] + t + 1; |
| 512 | t = len[4] = strlen(TXT_SUICIDES); |
| 513 | pos[5] = pos[4] + t + 1; |
| 514 | t = len[5] = strlen(TXT_PING); |
| 515 | |
| 516 | memcpy(&buffer[pos[0]], TXT_PILOT, strlen(TXT_PILOT)); |
| 517 | memcpy(&buffer[pos[1]], TXT_POINTS, len[1]); |
| 518 | memcpy(&buffer[pos[2]], TXT_KILLS, len[2]); |
| 519 | memcpy(&buffer[pos[3]], TXT_DEATHS, len[3]); |
| 520 | memcpy(&buffer[pos[4]], TXT_SUICIDES, len[4]); |
| 521 | memcpy(&buffer[pos[5]], TXT_PING, len[5]); |
| 522 | buffer[pos[5] + len[5] + 1] = '\n'; |
| 523 | buffer[pos[5] + len[5] + 2] = '\0'; |
| 524 | DPrintf(buffer); |
| 525 | |
| 526 | int slot; |
| 527 | player_record *pr; |
| 528 | int pcount; |
| 529 | |
| 530 | if (level < 0 || level >= MAX_PLAYER_RECORDS) |
| 531 | pcount = MAX_PLAYER_RECORDS; |
| 532 | else |
| 533 | pcount = level; |
| 534 | |
| 535 | int sortedplayers[MAX_PLAYER_RECORDS]; |
| 536 | DMFCBase->GetSortedPlayerSlots(sortedplayers, MAX_PLAYER_RECORDS); |
| 537 | |
| 538 | for (int i = 0; i < pcount; i++) { |
| 539 | slot = sortedplayers[i]; |
| 540 | pr = DMFCBase->GetPlayerRecord(slot); |
| 541 | if ((pr) && (pr->state != STATE_EMPTY)) { |
| 542 | |
| 543 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 544 | continue; // skip dedicated server |
| 545 | |
| 546 | snprintf(name, sizeof(name), "%s%s:", (pr->state == STATE_DISCONNECTED) ? "*" : "", pr->callsign); |
| 547 | name[19] = '\0'; |
| 548 | |
| 549 | tPlayerStat *stat = (tPlayerStat *)pr->user_info; |
| 550 | |
| 551 | memset(buffer, ' ', 256); |
| 552 | t = strlen(name); |
| 553 | memcpy(&buffer[pos[0]], name, (t < len[0]) ? t : len[0]); |
| 554 | snprintf(name, sizeof(name), "%d[%d]", (stat) ? stat->Score[DSTAT_LEVEL] : 0, |
| 555 | (stat) ? stat->Score[DSTAT_OVERALL] : 0); |
| 556 | t = strlen(name); |
| 557 | memcpy(&buffer[pos[1]], name, (t < len[1]) ? t : len[1]); |
| 558 | snprintf(name, sizeof(name), "%d[%d]", pr->dstats.kills[DSTAT_LEVEL], pr->dstats.kills[DSTAT_OVERALL]); |
| 559 | t = strlen(name); |
| 560 | memcpy(&buffer[pos[2]], name, (t < len[2]) ? t : len[2]); |
| 561 | snprintf(name, sizeof(name), "%d[%d]", pr->dstats.deaths[DSTAT_LEVEL], pr->dstats.deaths[DSTAT_OVERALL]); |
| 562 | t = strlen(name); |
| 563 | memcpy(&buffer[pos[3]], name, (t < len[3]) ? t : len[3]); |
| 564 | snprintf(name, sizeof(name), "%d[%d]", pr->dstats.suicides[DSTAT_LEVEL], pr->dstats.suicides[DSTAT_OVERALL]); |
| 565 | t = strlen(name); |
| 566 | memcpy(&buffer[pos[4]], name, (t < len[4]) ? t : len[4]); |
| 567 | |
| 568 | if (pr->state == STATE_INGAME) |
| 569 | snprintf(name, sizeof(name), "%.0f", (DMFCBase->GetNetPlayers())[pr->pnum].ping_time * 1000.0f); |
| 570 | else |
| 571 | strcpy(name, "---"); |
| 572 | t = strlen(name); |
| 573 | memcpy(&buffer[pos[5]], name, (t < len[5]) ? t : len[5]); |
| 574 | buffer[pos[5] + len[5] + 1] = '\n'; |
| 575 | buffer[pos[5] + len[5] + 2] = '\0'; |
| 576 | DPrintf(buffer); |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | void OnHUDInterval(void) { |
| 582 | dstat->DoFrame(); |
| 583 | DMFCBase->DisplayOutrageLogo(); |
| 584 | |
| 585 | DMFCBase->OnHUDInterval(); |
| 586 | } |
| 587 | |
| 588 | void OnInterval(void) { |
| 589 | SortPlayerScores(SortedPlayers, MAX_PLAYER_RECORDS); |
| 590 | DMFCBase->OnInterval(); |
| 591 | } |
| 592 | |
| 593 | void OnKeypress(int key) { |
| 594 | dllinfo *Data = DMFCBase->GetDLLInfoCallData(); |
| 595 | |
| 596 | switch (key) { |
| 597 | case K_F7: |
| 598 | DisplayScoreScreen = !DisplayScoreScreen; |
| 599 | DMFCBase->EnableOnScreenMenu(false); |
| 600 | dstat->Enable(DisplayScoreScreen); |
| 601 | break; |
| 602 | case K_PAGEDOWN: |
| 603 | if (DisplayScoreScreen) { |
| 604 | dstat->ScrollDown(); |
| 605 | Data->iRet = 1; |
| 606 | } |
| 607 | break; |
| 608 | case K_PAGEUP: |
| 609 | if (DisplayScoreScreen) { |
| 610 | dstat->ScrollUp(); |
| 611 | Data->iRet = 1; |
| 612 | } |
| 613 | break; |
| 614 | case K_F6: |
| 615 | DisplayScoreScreen = false; |
| 616 | dstat->Enable(false); |
| 617 | break; |
| 618 | case K_ESC: |
| 619 | if (DisplayScoreScreen) { |
| 620 | dstat->Enable(false); |
| 621 | DisplayScoreScreen = false; |
| 622 | Data->iRet = 1; |
| 623 | } |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | DMFCBase->OnKeypress(key); |
| 628 | } |
| 629 | |
| 630 | // The server has just started, so clear out all the stats and game info |
| 631 | void OnServerGameCreated(void) { |
| 632 | DMFCBase->OnServerGameCreated(); |
| 633 | player_record *pr; |
| 634 | tPlayerStat *stat; |
| 635 | for (int i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 636 | pr = DMFCBase->GetPlayerRecord(i); |
| 637 | if (pr) |
| 638 | stat = (tPlayerStat *)pr->user_info; |
| 639 | else |
| 640 | stat = NULL; |
| 641 | if (stat) { |
| 642 | stat->Score[DSTAT_LEVEL] = 0; |
| 643 | stat->Score[DSTAT_OVERALL] = 0; |
| 644 | stat->HighestScore[DSTAT_LEVEL] = 0; |
| 645 | stat->HighestScore[DSTAT_OVERALL] = 0; |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | // The server has started a new level, so clear out level scores |
| 651 | void OnClientLevelStart(void) { |
| 652 | DMFCBase->OnClientLevelStart(); |
| 653 | player_record *pr; |
| 654 | tPlayerStat *stat; |
| 655 | for (int i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 656 | pr = DMFCBase->GetPlayerRecord(i); |
| 657 | if (pr) |
| 658 | stat = (tPlayerStat *)pr->user_info; |
| 659 | else |
| 660 | stat = NULL; |
| 661 | |
| 662 | if (stat) { |
| 663 | stat->Score[DSTAT_LEVEL] = 0; |
| 664 | stat->HighestScore[DSTAT_LEVEL] = 0; |
| 665 | } |
| 666 | } |
| 667 | DMFCBase->RequestGameState(); |
| 668 | int grooms[4]; |
| 669 | grooms[0] = grooms[1] = grooms[2] = grooms[3] = DLLFindTextureName("GreenBase"); |
| 670 | DLLMultiPaintGoalRooms(grooms); |
| 671 | |
| 672 | // display the config dialog |
| 673 | if (!Config_displayed && DMFCBase->GetLocalRole() == LR_SERVER) { |
| 674 | DMFCBase->StartUIWindow(HOARD_CONFIG_DLG, &config); |
| 675 | Config_displayed = true; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | void OnClientShowUI(int id, void *user_data) { |
| 680 | if (id == HOARD_CONFIG_DLG) |
| 681 | DisplayHoardConfigDialog((tGameConfig *)user_data); |
| 682 | |
| 683 | if (id == 0xEEE1) { |
| 684 | // block off wait for players dialog |
| 685 | DisplayHoardConfigDialog(&config); |
| 686 | return; |
| 687 | } |
| 688 | |
| 689 | DMFCBase->OnClientShowUI(id, user_data); |
| 690 | } |
| 691 | |
| 692 | void OnClientLevelEnd(void) { DMFCBase->OnClientLevelEnd(); } |
| 693 | |
| 694 | // We need to send all the inventory info out to the new player |
| 695 | void OnGameStateRequest(int player_num) { |
| 696 | SendHoardInv(player_num); |
| 697 | DMFCBase->OnGameStateRequest(player_num); |
| 698 | } |
| 699 | |
| 700 | // A new player has entered the game, zero there stats out |
| 701 | void OnPlayerConnect(int player_num) { |
| 702 | DMFCBase->OnPlayerConnect(player_num); |
| 703 | |
| 704 | tPlayerStat *stat = (tPlayerStat *)DMFCBase->GetPlayerRecordData(player_num); |
| 705 | if (stat) { |
| 706 | stat->Score[DSTAT_LEVEL] = 0; |
| 707 | stat->Score[DSTAT_OVERALL] = 0; |
| 708 | stat->HighestScore[DSTAT_LEVEL] = 0; |
| 709 | stat->HighestScore[DSTAT_OVERALL] = 0; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | void OnServerPlayerChangeSegment(int player_num, int newseg, int oldseg) { |
| 714 | int g1, g2, g3, g4; |
| 715 | g1 = DLLGetGoalRoomForTeam(0); |
| 716 | g2 = DLLGetGoalRoomForTeam(1); |
| 717 | g3 = DLLGetGoalRoomForTeam(2); |
| 718 | g4 = DLLGetGoalRoomForTeam(3); |
| 719 | |
| 720 | int count = DLLInvCheckItem(player_num, OBJ_POWERUP, HoardID); |
| 721 | |
| 722 | if ((count) && ((newseg == g1) || (newseg == g2) || (newseg == g3) || (newseg == g4))) { |
| 723 | |
| 724 | DMFCBase->CallClientEvent(EVT_CLIENT_GAMEPLAYERCHANGESEG, DMFCBase->GetMeObjNum(), DMFCBase->GetItObjNum(), -1); |
| 725 | DMFCBase->CallOnClientPlayerChangeSegment(player_num, newseg, oldseg); |
| 726 | } |
| 727 | DMFCBase->OnServerPlayerChangeSegment(player_num, newseg, oldseg); |
| 728 | } |
| 729 | |
| 730 | void OnClientPlayerChangeSegment(int player_num, int newseg, int oldseg) { |
| 731 | int score, count, i; |
| 732 | |
| 733 | count = DLLInvGetTypeIDCount(player_num, OBJ_POWERUP, HoardID); |
| 734 | score = count; |
| 735 | |
| 736 | if (count < config.min_hoard) { |
| 737 | if (player_num == DMFCBase->GetPlayerNum()) |
| 738 | DLLAddHUDMessage(TXT_NEEDMOREOBS, config.min_hoard); |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | for (i = 0; i < count; i++) { |
| 743 | score += i; |
| 744 | DLLInvRemove(player_num, OBJ_POWERUP, HoardID); |
| 745 | } |
| 746 | |
| 747 | if (score == 0) |
| 748 | return; |
| 749 | |
| 750 | tPlayerStat *stat; |
| 751 | stat = (tPlayerStat *)DMFCBase->GetPlayerRecordData(player_num); |
| 752 | |
| 753 | if (stat) { |
| 754 | // increment scores |
| 755 | stat->Score[DSTAT_LEVEL] += score; |
| 756 | stat->Score[DSTAT_OVERALL] += score; |
| 757 | if (stat->HighestScore[DSTAT_LEVEL] < score) |
| 758 | stat->HighestScore[DSTAT_LEVEL] = score; |
| 759 | if (stat->HighestScore[DSTAT_OVERALL] < score) |
| 760 | stat->HighestScore[DSTAT_OVERALL] = score; |
| 761 | } |
| 762 | |
| 763 | char buffer[100]; |
| 764 | if (score == 1) |
| 765 | snprintf(buffer, sizeof(buffer), TXT_SCOREONE, dPlayers[player_num].callsign, |
| 766 | (stat) ? stat->Score[DSTAT_LEVEL] : 0); |
| 767 | else |
| 768 | snprintf(buffer, sizeof(buffer), TXT_SCOREMULTI, dPlayers[player_num].callsign, score, |
| 769 | (stat) ? stat->Score[DSTAT_LEVEL] : 0); |
| 770 | int sound = DLLFindSoundName("PwrHoardScore"); |
| 771 | if (sound != -1) |
| 772 | DLLPlay3dSound(sound, &dObjects[dPlayers[DMFCBase->GetPlayerNum()].objnum], 1, 0); |
| 773 | |
| 774 | // Set a Timer to display |
| 775 | if (WhoJustScoredTimer != -1) |
| 776 | DMFCBase->KillTimer(WhoJustScoredTimer); |
| 777 | WhoJustScoredTimer = DMFCBase->SetTimerInterval(OnTimer, 0.5f, 5.0f, OnTimerKill); |
| 778 | WhoJustScored = player_num; |
| 779 | |
| 780 | // remove the balls |
| 781 | DLLPlayerSetRotatingBall(player_num, 0, 0, NULL, NULL, NULL); |
| 782 | |
| 783 | DLLAddHUDMessage(buffer); |
| 784 | |
| 785 | if (DMFCBase->GetLocalRole() == LR_SERVER) { |
| 786 | // check the score to see if we hit the limit |
| 787 | if (DMFCBase->GetScoreLimit(&score)) { |
| 788 | if (score <= ((stat) ? stat->Score[DSTAT_LEVEL] : 0)) { |
| 789 | DLLmprintf(0, "Score limit reached\n"); |
| 790 | DMFCBase->EndLevel(); |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | DMFCBase->OnClientPlayerChangeSegment(player_num, newseg, oldseg); |
| 795 | } |
| 796 | |
| 797 | // A new player has entered the game, zero there stats out |
| 798 | void OnClientPlayerEntersGame(int player_num) { |
| 799 | DMFCBase->OnClientPlayerEntersGame(player_num); |
| 800 | if (player_num != DMFCBase->GetPlayerNum()) |
| 801 | DisplayWelcomeMessage(player_num); |
| 802 | else |
| 803 | display_my_welcome = true; |
| 804 | } |
| 805 | |
| 806 | void OnServerCollide(object *me_obj, object *it_obj) { |
| 807 | // see if we need to send this event to the clients |
| 808 | // only if me==player it==hoard powerup |
| 809 | |
| 810 | if (!me_obj || !it_obj) { |
| 811 | DMFCBase->OnServerCollide(me_obj, it_obj); |
| 812 | return; |
| 813 | } |
| 814 | |
| 815 | if ((me_obj->type == OBJ_PLAYER) && (it_obj->type == OBJ_POWERUP) && (it_obj->id == HoardID)) { |
| 816 | // check to make sure the player isn't dying or dead |
| 817 | player *plyr_ptr = &dPlayers[me_obj->id]; |
| 818 | if ((plyr_ptr->flags & PLAYER_FLAGS_DYING) || (plyr_ptr->flags & PLAYER_FLAGS_DEAD)) { |
| 819 | // this player is dying or dead...ignore it |
| 820 | DMFCBase->OnServerCollide(me_obj, it_obj); |
| 821 | return; |
| 822 | } |
| 823 | |
| 824 | DMFCBase->CallClientEvent(EVT_CLIENT_GAMECOLLIDE, DMFCBase->GetMeObjNum(), DMFCBase->GetItObjNum(), -1); |
| 825 | DMFCBase->CallOnClientCollide(me_obj, it_obj); |
| 826 | |
| 827 | // test to see if they are in a goal room, if so score |
| 828 | int current_room = me_obj->roomnum; |
| 829 | int g1, g2, g3, g4; |
| 830 | g1 = DLLGetGoalRoomForTeam(0); |
| 831 | g2 = DLLGetGoalRoomForTeam(1); |
| 832 | g3 = DLLGetGoalRoomForTeam(2); |
| 833 | g4 = DLLGetGoalRoomForTeam(3); |
| 834 | |
| 835 | if ((current_room == g1) || (current_room == g2) || (current_room == g3) || (current_room == g4)) { |
| 836 | DMFCBase->CallClientEvent(EVT_CLIENT_GAMEPLAYERCHANGESEG, DMFCBase->GetMeObjNum(), DMFCBase->GetItObjNum(), -1); |
| 837 | DMFCBase->CallOnClientPlayerChangeSegment(me_obj->id, current_room, current_room); |
| 838 | } |
| 839 | } |
| 840 | DMFCBase->OnServerCollide(me_obj, it_obj); |
| 841 | } |
| 842 | |
| 843 | void OnClientCollide(object *me_obj, object *it_obj) { |
| 844 | int playernum = me_obj->id; |
| 845 | int count = DLLInvGetTypeIDCount(playernum, OBJ_POWERUP, HoardID); |
| 846 | |
| 847 | if (count < 12) { |
| 848 | if (DMFCBase->GetPlayerNum() == playernum) { |
| 849 | DLLAddHUDMessage(TXT_GOTHOARD); |
| 850 | } |
| 851 | int sound = DLLFindSoundName("PwrHoardPickup"); |
| 852 | if (sound != -1) |
| 853 | DLLPlay3dSound(sound, me_obj, 1, 0); |
| 854 | if (it_obj->type == OBJ_POWERUP) { |
| 855 | DLLInvAddTypeID(playernum, it_obj->type, it_obj->id, -1, -1, 0, NULL); |
| 856 | if (DMFCBase->GetLocalRole() == LR_SERVER) { |
| 857 | DLLSetObjectDeadFlag(it_obj, true, false); |
| 858 | } |
| 859 | } else |
| 860 | DLLmprintf(0, "HOARD BIG WARNING: TRYING TO ADD NONPOWERUP TO INVENTORY! (%d)\n", it_obj->type); |
| 861 | |
| 862 | // add rotating balls if necessary |
| 863 | DoBallsEffect(playernum, count + 1); |
| 864 | } else { |
| 865 | // they have max orbs |
| 866 | if (DMFCBase->GetPlayerNum() == playernum) { |
| 867 | DLLAddHUDMessage(TXT_MAXHOARDS); |
| 868 | } |
| 869 | } |
| 870 | DMFCBase->OnClientCollide(me_obj, it_obj); |
| 871 | } |
| 872 | |
| 873 | // used for the clients when a player dies, to print out a message and other stuff |
| 874 | void OnClientPlayerKilled(object *killer_obj, int victim_pnum) { |
| 875 | int kpnum = -1; |
| 876 | |
| 877 | if (killer_obj) { |
| 878 | if ((killer_obj->type == OBJ_PLAYER) || (killer_obj->type == OBJ_GHOST)) |
| 879 | kpnum = killer_obj->id; |
| 880 | else if (killer_obj->type == OBJ_ROBOT) { |
| 881 | // countermeasure kill |
| 882 | kpnum = DMFCBase->GetCounterMeasureOwner(killer_obj); |
| 883 | } else { |
| 884 | kpnum = -1; |
| 885 | } |
| 886 | } else |
| 887 | kpnum = -1; |
| 888 | |
| 889 | // add an extra hoard to the inventory if they didn't kill themselves |
| 890 | if (kpnum != victim_pnum) { |
| 891 | DLLInvAddTypeID(victim_pnum, OBJ_POWERUP, HoardID, -1, -1, 0, NULL); |
| 892 | } |
| 893 | |
| 894 | // remove the balls |
| 895 | DLLPlayerSetRotatingBall(victim_pnum, 0, 0, NULL, NULL, NULL); |
| 896 | |
| 897 | DMFCBase->OnClientPlayerKilled(killer_obj, victim_pnum); |
| 898 | } |
| 899 | |
| 900 | bool compare_slots(int a, int b) { |
| 901 | int ascore, bscore; |
| 902 | player_record *apr, *bpr; |
| 903 | tPlayerStat *astat, *bstat; |
| 904 | |
| 905 | apr = DMFCBase->GetPlayerRecord(a); |
| 906 | bpr = DMFCBase->GetPlayerRecord(b); |
| 907 | if (!apr) |
| 908 | return true; |
| 909 | if (!bpr) |
| 910 | return false; |
| 911 | if (apr->state == STATE_EMPTY) |
| 912 | return true; |
| 913 | if (bpr->state == STATE_EMPTY) |
| 914 | return false; |
| 915 | astat = (tPlayerStat *)apr->user_info; |
| 916 | bstat = (tPlayerStat *)bpr->user_info; |
| 917 | |
| 918 | if ((apr->state == STATE_INGAME) && (bpr->state == STATE_INGAME)) { |
| 919 | // both players were in the game |
| 920 | ascore = (astat) ? astat->Score[DSTAT_LEVEL] : 0; |
| 921 | bscore = (bstat) ? bstat->Score[DSTAT_LEVEL] : 0; |
| 922 | return (ascore < bscore); |
| 923 | } |
| 924 | if ((apr->state == STATE_INGAME) && (bpr->state == STATE_DISCONNECTED)) { |
| 925 | // apr gets priority since he was in the game on exit |
| 926 | return false; |
| 927 | } |
| 928 | if ((apr->state == STATE_DISCONNECTED) && (bpr->state == STATE_INGAME)) { |
| 929 | // bpr gets priority since he was in the game on exit |
| 930 | return true; |
| 931 | } |
| 932 | // if we got here then both players were disconnected |
| 933 | ascore = (astat) ? astat->Score[DSTAT_LEVEL] : 0; |
| 934 | bscore = (bstat) ? bstat->Score[DSTAT_LEVEL] : 0; |
| 935 | return (ascore < bscore); |
| 936 | } |
| 937 | void OnPLRInit(void) { |
| 938 | int i, t, j; |
| 939 | |
| 940 | for (i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 941 | SortedPlayers[i] = i; |
| 942 | } |
| 943 | |
| 944 | for (i = 1; i <= MAX_PLAYER_RECORDS - 1; i++) { |
| 945 | t = SortedPlayers[i]; |
| 946 | // Shift elements down until |
| 947 | // insertion point found. |
| 948 | for (j = i - 1; j >= 0 && compare_slots(SortedPlayers[j], t); j--) { |
| 949 | SortedPlayers[j + 1] = SortedPlayers[j]; |
| 950 | } |
| 951 | // insert |
| 952 | SortedPlayers[j + 1] = t; |
| 953 | } |
| 954 | |
| 955 | DMFCBase->OnPLRInit(); |
| 956 | } |
| 957 | |
| 958 | void OnPLRInterval(void) { |
| 959 | #define PLAYERS_COL 100 |
| 960 | #define SCORE_COL 200 |
| 961 | #define HIGH_COL 260 |
| 962 | #define KILLS_COL 320 |
| 963 | #define DEATHS_COL 380 |
| 964 | #define SUICIDES_COL 440 |
| 965 | |
| 966 | DMFCBase->OnPLRInterval(); |
| 967 | |
| 968 | int y = 40; |
| 969 | int height = DLLgrfont_GetHeight((DMFCBase->GetGameFontTranslateArray())[SMALL_UI_FONT_INDEX]) + 1; |
| 970 | |
| 971 | DLLgrtext_SetFont((DMFCBase->GetGameFontTranslateArray())[SMALL_UI_FONT_INDEX]); |
| 972 | |
| 973 | // print out header |
| 974 | DLLgrtext_SetColor(GR_RGB(255, 255, 150)); |
| 975 | DLLgrtext_Printf(PLAYERS_COL, y, TXT_PILOT); |
| 976 | DLLgrtext_Printf(SCORE_COL, y, TXT_LEVEL); |
| 977 | DLLgrtext_Printf(SCORE_COL, y + height, TXT_POINTS); |
| 978 | DLLgrtext_Printf(HIGH_COL, y, TXT_HIGH); |
| 979 | DLLgrtext_Printf(HIGH_COL, y + height, TXT_GOAL); |
| 980 | DLLgrtext_Printf(KILLS_COL, y, TXT_KILLS); |
| 981 | DLLgrtext_Printf(DEATHS_COL, y, TXT_DEATHS); |
| 982 | DLLgrtext_Printf(SUICIDES_COL, y, TXT_SUICIDES); |
| 983 | y += (2 * height); |
| 984 | |
| 985 | // print out player stats |
| 986 | int rank = 1; |
| 987 | int slot; |
| 988 | player_record *pr; |
| 989 | tPlayerStat *stat; |
| 990 | |
| 991 | for (int i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 992 | slot = SortedPlayers[i]; |
| 993 | pr = DMFCBase->GetPlayerRecord(slot); |
| 994 | if (pr && pr->state != STATE_EMPTY) { |
| 995 | |
| 996 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 997 | continue; // skip dedicated server |
| 998 | |
| 999 | int pnum = DMFCBase->WasPlayerInGameAtLevelEnd(slot); |
| 1000 | if (pnum != -1) { |
| 1001 | DLLgrtext_SetColor((DMFCBase->GetPlayerColors())[pnum]); |
| 1002 | } else { |
| 1003 | DLLgrtext_SetColor(GR_RGB(128, 128, 128)); |
| 1004 | } |
| 1005 | |
| 1006 | stat = (tPlayerStat *)pr->user_info; |
| 1007 | |
| 1008 | DLLgrtext_Printf(PLAYERS_COL, y, "%d)%s", rank, pr->callsign); |
| 1009 | DLLgrtext_Printf(SCORE_COL, y, "%d[%d]", (stat) ? stat->Score[DSTAT_LEVEL] : 0, |
| 1010 | (stat) ? stat->Score[DSTAT_OVERALL] : 0); |
| 1011 | DLLgrtext_Printf(HIGH_COL, y, "%d[%d]", (stat) ? stat->HighestScore[DSTAT_LEVEL] : 0, |
| 1012 | (stat) ? stat->HighestScore[DSTAT_OVERALL] : 0); |
| 1013 | DLLgrtext_Printf(KILLS_COL, y, "%d[%d]", pr->dstats.kills[DSTAT_LEVEL], pr->dstats.kills[DSTAT_OVERALL]); |
| 1014 | DLLgrtext_Printf(DEATHS_COL, y, "%d[%d]", pr->dstats.deaths[DSTAT_LEVEL], pr->dstats.deaths[DSTAT_OVERALL]); |
| 1015 | DLLgrtext_Printf(SUICIDES_COL, y, "%d[%d]", pr->dstats.suicides[DSTAT_LEVEL], pr->dstats.suicides[DSTAT_OVERALL]); |
| 1016 | |
| 1017 | y += height; |
| 1018 | rank++; |
| 1019 | |
| 1020 | if (y >= 440) |
| 1021 | goto quick_exit; |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | quick_exit:; |
| 1026 | } |
| 1027 | |
| 1028 | void SaveStatsToFile(char *filename) { |
| 1029 | CFILE *file; |
| 1030 | DLLOpenCFILE(&file, filename, "wt"); |
| 1031 | if (!file) { |
| 1032 | DLLmprintf(0, "Unable to open output file\n"); |
| 1033 | return; |
| 1034 | } |
| 1035 | |
| 1036 | // write out game stats |
| 1037 | #define BUFSIZE 150 |
| 1038 | char buffer[BUFSIZE]; |
| 1039 | char tempbuffer[25]; |
| 1040 | int sortedslots[MAX_PLAYER_RECORDS]; |
| 1041 | player_record *pr, *dpr; |
| 1042 | tPInfoStat stat; |
| 1043 | tPlayerStat *ps; |
| 1044 | int count, p; |
| 1045 | |
| 1046 | // sort the stats |
| 1047 | SortPlayerScores(sortedslots, MAX_PLAYER_RECORDS); |
| 1048 | count = 1; |
| 1049 | |
| 1050 | snprintf(buffer, sizeof(buffer), TXT_STATSSAVEA, (DMFCBase->GetNetgameInfo())->name, |
| 1051 | (DMFCBase->GetCurrentMission())->cur_level); |
| 1052 | DLLcf_WriteString(file, buffer); |
| 1053 | |
| 1054 | snprintf(buffer, sizeof(buffer), "%s", TXT_SAVESTATSB); |
| 1055 | DLLcf_WriteString(file, buffer); |
| 1056 | |
| 1057 | snprintf(buffer, sizeof(buffer), "%s", TXT_SAVESTATSC); |
| 1058 | DLLcf_WriteString(file, buffer); |
| 1059 | strcpy( |
| 1060 | buffer, |
| 1061 | "-------------------------------------------------------------------------------------------------------------"); |
| 1062 | DLLcf_WriteString(file, buffer); |
| 1063 | |
| 1064 | for (p = 0; p < MAX_PLAYER_RECORDS; p++) { |
| 1065 | pr = DMFCBase->GetPlayerRecord(sortedslots[p]); |
| 1066 | if (pr && pr->state != STATE_EMPTY) { |
| 1067 | |
| 1068 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 1069 | continue; // skip dedicated server |
| 1070 | |
| 1071 | memset(buffer, ' ', BUFSIZE); |
| 1072 | |
| 1073 | ps = (tPlayerStat *)pr->user_info; |
| 1074 | |
| 1075 | snprintf(tempbuffer, sizeof(tempbuffer), "%d)", count); |
| 1076 | memcpy(&buffer[0], tempbuffer, strlen(tempbuffer)); |
| 1077 | |
| 1078 | snprintf(tempbuffer, sizeof(tempbuffer), "%s%s", (pr->state == STATE_INGAME) ? "" : "*", pr->callsign); |
| 1079 | memcpy(&buffer[7], tempbuffer, strlen(tempbuffer)); |
| 1080 | |
| 1081 | if (ps) { |
| 1082 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", ps->Score[DSTAT_LEVEL], ps->Score[DSTAT_OVERALL]); |
| 1083 | memcpy(&buffer[35], tempbuffer, strlen(tempbuffer)); |
| 1084 | } |
| 1085 | |
| 1086 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", pr->dstats.kills[DSTAT_LEVEL], |
| 1087 | pr->dstats.kills[DSTAT_OVERALL]); |
| 1088 | memcpy(&buffer[47], tempbuffer, strlen(tempbuffer)); |
| 1089 | |
| 1090 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", pr->dstats.deaths[DSTAT_LEVEL], |
| 1091 | pr->dstats.deaths[DSTAT_OVERALL]); |
| 1092 | memcpy(&buffer[59], tempbuffer, strlen(tempbuffer)); |
| 1093 | |
| 1094 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", pr->dstats.suicides[DSTAT_LEVEL], |
| 1095 | pr->dstats.suicides[DSTAT_OVERALL]); |
| 1096 | memcpy(&buffer[70], tempbuffer, strlen(tempbuffer)); |
| 1097 | |
| 1098 | if (ps) { |
| 1099 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", ps->HighestScore[DSTAT_LEVEL], |
| 1100 | ps->HighestScore[DSTAT_OVERALL]); |
| 1101 | memcpy(&buffer[81], tempbuffer, strlen(tempbuffer)); |
| 1102 | } |
| 1103 | |
| 1104 | snprintf(tempbuffer, sizeof(tempbuffer), "%s", DMFCBase->GetTimeString(DMFCBase->GetTimeInGame(sortedslots[p]))); |
| 1105 | memcpy(&buffer[96], tempbuffer, strlen(tempbuffer)); |
| 1106 | |
| 1107 | size_t pos = 96 + strlen(tempbuffer) + 1; |
| 1108 | |
| 1109 | if (pos < BUFSIZE) |
| 1110 | buffer[pos] = '\0'; |
| 1111 | |
| 1112 | buffer[BUFSIZE - 1] = '\0'; |
| 1113 | DLLcf_WriteString(file, buffer); |
| 1114 | count++; |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | DLLcf_WriteString(file, TXT_SAVESTATSD); |
| 1119 | |
| 1120 | count = 1; |
| 1121 | for (p = 0; p < MAX_PLAYER_RECORDS; p++) { |
| 1122 | pr = DMFCBase->GetPlayerRecord(p); |
| 1123 | if (pr && pr->state != STATE_EMPTY) { |
| 1124 | |
| 1125 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 1126 | continue; // skip dedicated server |
| 1127 | |
| 1128 | // Write out header |
| 1129 | snprintf(buffer, sizeof(buffer), "%d) %s%s", count, (pr->state == STATE_INGAME) ? "" : "*", pr->callsign); |
| 1130 | DLLcf_WriteString(file, buffer); |
| 1131 | size_t length = strlen(buffer); |
| 1132 | memset(buffer, '=', length); |
| 1133 | buffer[length] = '\0'; |
| 1134 | DLLcf_WriteString(file, buffer); |
| 1135 | |
| 1136 | // time in game |
| 1137 | snprintf(buffer, sizeof(buffer), TXT_TIMEINGAME, DMFCBase->GetTimeString(DMFCBase->GetTimeInGame(p))); |
| 1138 | DLLcf_WriteString(file, buffer); |
| 1139 | |
| 1140 | if (DMFCBase->FindPInfoStatFirst(p, &stat)) { |
| 1141 | snprintf(buffer, sizeof(buffer), "%s", TXT_SAVESTATSE); |
| 1142 | DLLcf_WriteString(file, buffer); |
| 1143 | |
| 1144 | if (stat.slot != p) { |
| 1145 | memset(buffer, ' ', BUFSIZE); |
| 1146 | dpr = DMFCBase->GetPlayerRecord(stat.slot); |
| 1147 | |
| 1148 | if (dpr) { |
| 1149 | snprintf(tempbuffer, sizeof(tempbuffer), "%s", dpr->callsign); |
| 1150 | memcpy(buffer, tempbuffer, strlen(tempbuffer)); |
| 1151 | |
| 1152 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.kills); |
| 1153 | memcpy(&buffer[30], tempbuffer, strlen(tempbuffer)); |
| 1154 | |
| 1155 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.deaths); |
| 1156 | memcpy(&buffer[40], tempbuffer, strlen(tempbuffer)); |
| 1157 | |
| 1158 | size_t pos = 40 + strlen(tempbuffer) + 1; |
| 1159 | if (pos < BUFSIZE) |
| 1160 | buffer[pos] = '\0'; |
| 1161 | |
| 1162 | buffer[BUFSIZE - 1] = '\0'; |
| 1163 | DLLcf_WriteString(file, buffer); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | while (DMFCBase->FindPInfoStatNext(&stat)) { |
| 1168 | if (stat.slot != p) { |
| 1169 | memset(buffer, ' ', BUFSIZE); |
| 1170 | dpr = DMFCBase->GetPlayerRecord(stat.slot); |
| 1171 | if (dpr) { |
| 1172 | snprintf(tempbuffer, sizeof(tempbuffer), "%s", dpr->callsign); |
| 1173 | memcpy(buffer, tempbuffer, strlen(tempbuffer)); |
| 1174 | |
| 1175 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.kills); |
| 1176 | memcpy(&buffer[30], tempbuffer, strlen(tempbuffer)); |
| 1177 | |
| 1178 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.deaths); |
| 1179 | memcpy(&buffer[40], tempbuffer, strlen(tempbuffer)); |
| 1180 | |
| 1181 | size_t pos = 40 + strlen(tempbuffer) + 1; |
| 1182 | if (pos < BUFSIZE) |
| 1183 | buffer[pos] = '\0'; |
| 1184 | |
| 1185 | buffer[BUFSIZE - 1] = '\0'; |
| 1186 | DLLcf_WriteString(file, buffer); |
| 1187 | } |
| 1188 | } |
| 1189 | } |
| 1190 | } |
| 1191 | DMFCBase->FindPInfoStatClose(); |
| 1192 | DLLcf_WriteString(file, ""); // skip a line |
| 1193 | count++; |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | // done writing stats |
| 1198 | DLLcfclose(file); |
| 1199 | DLLAddHUDMessage(TXT_STATSSAVED); |
| 1200 | } |
| 1201 | |
| 1202 | #define ROOTFILENAME "Hoard" |
| 1203 | void OnSaveStatsToFile(void) { |
| 1204 | char filename[256]; |
| 1205 | DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); |
| 1206 | SaveStatsToFile(filename); |
| 1207 | } |
| 1208 | |
| 1209 | void OnLevelEndSaveStatsToFile(void) { |
| 1210 | char filename[256]; |
| 1211 | DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); |
| 1212 | SaveStatsToFile(filename); |
| 1213 | } |
| 1214 | |
| 1215 | void OnDisconnectSaveStatsToFile(void) { |
| 1216 | char filename[256]; |
| 1217 | DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); |
| 1218 | SaveStatsToFile(filename); |
| 1219 | } |
| 1220 | |
| 1221 | // handles a hoard inventory packet |
| 1222 | void ReceiveHoardInv(uint8_t *data) { |
| 1223 | int x, i, count = 0; |
| 1224 | int size; |
| 1225 | |
| 1226 | for (x = 0; x < DLLMAX_PLAYERS; x++) { |
| 1227 | // see if we have a valid player |
| 1228 | size = MultiGetByte(data, &count); |
| 1229 | |
| 1230 | if (DMFCBase->CheckPlayerNum(x)) { |
| 1231 | // we have a valid player, add orbs |
| 1232 | ASSERT(size >= 0); |
| 1233 | DoBallsEffect(x, size); |
| 1234 | for (i = 0; i < size; i++) { |
| 1235 | DLLInvAddTypeID(x, OBJ_POWERUP, HoardID, -1, -1, 0, NULL); |
| 1236 | } // end for |
| 1237 | } // end if |
| 1238 | } // end for |
| 1239 | } |
| 1240 | |
| 1241 | // sends a hoard inventory packet to a player |
| 1242 | void SendHoardInv(int playernum) { |
| 1243 | uint8_t data[MAX_GAME_DATA_SIZE]; |
| 1244 | int i; |
| 1245 | int count = 0; |
| 1246 | |
| 1247 | DMFCBase->StartPacket(data, SPID_INVINFO, &count); |
| 1248 | |
| 1249 | for (i = 0; i < DLLMAX_PLAYERS; i++) { |
| 1250 | if (DMFCBase->CheckPlayerNum(i)) { |
| 1251 | MultiAddByte(DLLInvGetTypeIDCount(i, OBJ_POWERUP, HoardID), data, &count); |
| 1252 | } else { |
| 1253 | MultiAddByte(0, data, &count); |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | DMFCBase->SendPacket(data, count, playernum); |
| 1258 | |
| 1259 | SendGameConfig(playernum); |
| 1260 | } |
| 1261 | |
| 1262 | void DisplayHUDScores(struct tHUDItem *hitem) { |
| 1263 | if (display_my_welcome) { |
| 1264 | DisplayWelcomeMessage(DMFCBase->GetPlayerNum()); |
| 1265 | display_my_welcome = false; |
| 1266 | } |
| 1267 | |
| 1268 | if (DisplayScoreScreen) |
| 1269 | return; |
| 1270 | |
| 1271 | int x = 520; |
| 1272 | int height = DLLgrfont_GetHeight((DMFCBase->GetGameFontTranslateArray())[HUD_FONT_INDEX]) + 3; |
| 1273 | uint8_t alpha = DMFCBase->ConvertHUDAlpha((uint8_t)((DisplayScoreScreen) ? 128 : 255)); |
| 1274 | int y = (DMFCBase->GetGameWindowH() / 2) - ((height * 5) / 2); |
| 1275 | int rank = 1; |
| 1276 | ddgr_color color; |
| 1277 | |
| 1278 | char name[50]; |
| 1279 | player_record *pr; |
| 1280 | tPlayerStat *stat; |
| 1281 | |
| 1282 | // determine coordinates to use here |
| 1283 | // we'll use a virtual width of 85 pixels on a 640x480 screen |
| 1284 | // so first determine the new width |
| 1285 | int name_width = 85.0f * DMFCBase->GetHudAspectX(); |
| 1286 | int score_width = DLLgrtext_GetTextLineWidth("888"); |
| 1287 | int name_x = DMFCBase->GetGameWindowW() - name_width - score_width - 10; |
| 1288 | int score_x = DMFCBase->GetGameWindowW() - score_width - 5; |
| 1289 | DLLgrtext_SetAlpha(alpha); |
| 1290 | |
| 1291 | for (int i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 1292 | int slot = SortedPlayers[i]; |
| 1293 | pr = DMFCBase->GetPlayerRecord(slot); |
| 1294 | if (pr && pr->state != STATE_EMPTY) { |
| 1295 | |
| 1296 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 1297 | continue; // skip dedicated server |
| 1298 | |
| 1299 | if ((pr->state == STATE_DISCONNECTED) || (pr->state == STATE_INGAME && !DMFCBase->IsPlayerObserver(pr->pnum))) { |
| 1300 | |
| 1301 | stat = (tPlayerStat *)pr->user_info; |
| 1302 | strcpy(name, pr->callsign); |
| 1303 | DMFCBase->ClipString(name_width, name, true); |
| 1304 | |
| 1305 | if (pr->state == STATE_INGAME && pr->pnum == DMFCBase->GetPlayerNum()) { |
| 1306 | |
| 1307 | switch (HUD_color_model) { |
| 1308 | case HCM_PLAYERCOLOR: |
| 1309 | color = (DMFCBase->GetPlayerColors())[pr->pnum]; |
| 1310 | break; |
| 1311 | case HCM_NORMAL: |
| 1312 | color = GR_RGB(40, 255, 40); |
| 1313 | break; |
| 1314 | }; |
| 1315 | |
| 1316 | if (Highlight_bmp > BAD_BITMAP_HANDLE) { |
| 1317 | // draw the highlight bar in the background |
| 1318 | DLLrend_SetAlphaValue(alpha * 0.50f); |
| 1319 | DLLrend_SetZBufferState(0); |
| 1320 | DLLrend_SetTextureType(TT_LINEAR); |
| 1321 | DLLrend_SetLighting(LS_NONE); |
| 1322 | DLLrend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 1323 | |
| 1324 | DLLrend_DrawScaledBitmap(name_x - 2, y - 2, score_x + score_width + 2, y + height - 1, Highlight_bmp, 0, 0, |
| 1325 | 1, 1, 1.0f, -1, NULL); |
| 1326 | DLLrend_SetZBufferState(1); |
| 1327 | } |
| 1328 | |
| 1329 | if ((WhoJustScored != pr->pnum) || (DisplayBlink)) { |
| 1330 | DLLgrtext_SetColor(color); |
| 1331 | DLLgrtext_Printf(name_x, y, name); |
| 1332 | DLLgrtext_Printf(score_x, y, "%d", (stat) ? stat->Score[DSTAT_LEVEL] : 0); |
| 1333 | } |
| 1334 | y += height; |
| 1335 | } else if (rank < 6) { |
| 1336 | if (pr->state == STATE_DISCONNECTED) { |
| 1337 | color = GR_GREY; |
| 1338 | } else { |
| 1339 | switch (HUD_color_model) { |
| 1340 | case HCM_PLAYERCOLOR: |
| 1341 | color = (DMFCBase->GetPlayerColors())[pr->pnum]; |
| 1342 | break; |
| 1343 | case HCM_NORMAL: |
| 1344 | color = GR_RGB(40, 255, 40); |
| 1345 | break; |
| 1346 | }; |
| 1347 | } |
| 1348 | |
| 1349 | if ((pr->state == STATE_DISCONNECTED) || (WhoJustScored != pr->pnum) || (DisplayBlink)) { |
| 1350 | DLLgrtext_SetColor(color); |
| 1351 | DLLgrtext_Printf(name_x, y, name); |
| 1352 | DLLgrtext_Printf(score_x, y, "%d", (stat) ? stat->Score[DSTAT_LEVEL] : 0); |
| 1353 | } |
| 1354 | y += height; |
| 1355 | } |
| 1356 | rank++; |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | // draw the hoard orb count |
| 1362 | int w = DLLbm_w(HoardOrbIcon, 0); |
| 1363 | char buffer[4]; |
| 1364 | snprintf(buffer, sizeof(buffer), "%d", DLLInvGetTypeIDCount(DMFCBase->GetPlayerNum(), OBJ_POWERUP, HoardID)); |
| 1365 | int x1, x2, y1, y2; |
| 1366 | x1 = DMFCBase->GetGameWindowW() - 5 - DLLbm_w(HoardOrbIcon, 0); |
| 1367 | y1 = 25; |
| 1368 | x2 = x1 + DLLbm_w(HoardOrbIcon, 0); |
| 1369 | y2 = y1 + DLLbm_h(HoardOrbIcon, 0); |
| 1370 | |
| 1371 | DLLrend_SetAlphaValue(alpha); |
| 1372 | DLLrend_SetZBufferState(0); |
| 1373 | DLLrend_SetTextureType(TT_LINEAR); |
| 1374 | DLLrend_SetLighting(LS_NONE); |
| 1375 | DLLrend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 1376 | DLLrend_DrawScaledBitmap(x1, y1, x2, y2, HoardOrbIcon, 0, 0, 1, 1, 1.0f, -1, NULL); |
| 1377 | DLLrend_SetZBufferState(1); |
| 1378 | |
| 1379 | x1 += w / 2; |
| 1380 | y1 += DLLbm_h(HoardOrbIcon, 0) / 2; |
| 1381 | x1 -= ((float)DLLgrtext_GetTextLineWidth(buffer)) / 2.0f; |
| 1382 | y1 -= ((height - 3) / 2.0); |
| 1383 | |
| 1384 | DLLgrtext_SetColor(GR_RGB(128, 128, 128)); |
| 1385 | DLLgrtext_SetAlpha(std::min(alpha + 30, 255)); |
| 1386 | DLLgrtext_Printf(x1, y1, buffer); |
| 1387 | } |
| 1388 | |
| 1389 | void SortPlayerScores(int *sortedindex, int size) { |
| 1390 | int tempsort[MAX_PLAYER_RECORDS]; |
| 1391 | int i, t, j; |
| 1392 | |
| 1393 | for (i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 1394 | tempsort[i] = i; |
| 1395 | } |
| 1396 | |
| 1397 | for (i = 1; i <= MAX_PLAYER_RECORDS - 1; i++) { |
| 1398 | t = tempsort[i]; |
| 1399 | // Shift elements down until |
| 1400 | // insertion point found. |
| 1401 | for (j = i - 1; j >= 0 && compare_slots(tempsort[j], t); j--) { |
| 1402 | tempsort[j + 1] = tempsort[j]; |
| 1403 | } |
| 1404 | // insert |
| 1405 | tempsort[j + 1] = t; |
| 1406 | } |
| 1407 | |
| 1408 | // copy the array over |
| 1409 | memcpy(sortedindex, tempsort, ((size > MAX_PLAYER_RECORDS) ? MAX_PLAYER_RECORDS : size) * sizeof(int)); |
| 1410 | } |
| 1411 | |
| 1412 | void DisplayWelcomeMessage(int player_num) { |
| 1413 | char name_buffer[64]; |
| 1414 | strcpy(name_buffer, (DMFCBase->GetPlayers())[player_num].callsign); |
| 1415 | |
| 1416 | if (player_num == DMFCBase->GetPlayerNum()) { |
| 1417 | DLLAddHUDMessage(TXT_WELCOME, name_buffer); |
| 1418 | } else { |
| 1419 | DLLAddHUDMessage(TXT_JOINED, name_buffer); |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | void DoBallsEffect(int i, int count) { |
| 1424 | float redb[4]; |
| 1425 | float greenb[4]; |
| 1426 | float blueb[4]; |
| 1427 | |
| 1428 | for (int x = 0; x < 4; x++) { |
| 1429 | redb[x] = blueb[x] = 0; |
| 1430 | greenb[x] = 1; |
| 1431 | } |
| 1432 | |
| 1433 | switch (count) { |
| 1434 | case 0: |
| 1435 | DLLPlayerSetRotatingBall(i, 0, 0, redb, greenb, blueb); |
| 1436 | break; |
| 1437 | case 1: |
| 1438 | DLLPlayerSetRotatingBall(i, 1, 4, redb, greenb, blueb); |
| 1439 | break; |
| 1440 | case 2: |
| 1441 | DLLPlayerSetRotatingBall(i, 1, 3, redb, greenb, blueb); |
| 1442 | break; |
| 1443 | case 3: |
| 1444 | DLLPlayerSetRotatingBall(i, 1, 2, redb, greenb, blueb); |
| 1445 | break; |
| 1446 | case 4: |
| 1447 | DLLPlayerSetRotatingBall(i, 1, 1, redb, greenb, blueb); |
| 1448 | break; |
| 1449 | case 5: |
| 1450 | DLLPlayerSetRotatingBall(i, 2, 4, redb, greenb, blueb); |
| 1451 | break; |
| 1452 | case 6: |
| 1453 | DLLPlayerSetRotatingBall(i, 2, 3, redb, greenb, blueb); |
| 1454 | break; |
| 1455 | case 7: |
| 1456 | DLLPlayerSetRotatingBall(i, 2, 2, redb, greenb, blueb); |
| 1457 | break; |
| 1458 | case 8: |
| 1459 | DLLPlayerSetRotatingBall(i, 2, 1, redb, greenb, blueb); |
| 1460 | break; |
| 1461 | case 9: |
| 1462 | DLLPlayerSetRotatingBall(i, 3, 4, redb, greenb, blueb); |
| 1463 | break; |
| 1464 | case 10: |
| 1465 | DLLPlayerSetRotatingBall(i, 3, 3, redb, greenb, blueb); |
| 1466 | break; |
| 1467 | case 11: |
| 1468 | DLLPlayerSetRotatingBall(i, 3, 2, redb, greenb, blueb); |
| 1469 | break; |
| 1470 | case 12: |
| 1471 | DLLPlayerSetRotatingBall(i, 3, 1, redb, greenb, blueb); |
| 1472 | break; |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | ///////////////////////////////// |
| 1477 | // Timer event handlers |
| 1478 | void OnTimer(void) { DisplayBlink = !DisplayBlink; } |
| 1479 | void OnTimerKill(void) { |
| 1480 | DisplayBlink = true; |
| 1481 | WhoJustScored = WhoJustScoredTimer = -1; |
| 1482 | } |
| 1483 | |
| 1484 | // game config send/receive |
| 1485 | void SendGameConfig(int towho) { |
| 1486 | uint8_t data[MAX_GAME_DATA_SIZE]; |
| 1487 | int count = 0; |
| 1488 | |
| 1489 | DMFCBase->StartPacket(data, SPID_GAMECONFIG, &count); |
| 1490 | |
| 1491 | MultiAddByte(config.min_hoard, data, &count); |
| 1492 | |
| 1493 | DMFCBase->SendPacket(data, count, towho); |
| 1494 | } |
| 1495 | |
| 1496 | void ReceiveGameConfig(uint8_t *data) { |
| 1497 | int count = 0; |
| 1498 | config.min_hoard = MultiGetByte(data, &count); |
| 1499 | } |
| 1500 | |
| 1501 | void ShowGameConfigDialog(int i) { |
| 1502 | DMFCBase->EnableOnScreenMenu(false); |
| 1503 | DMFCBase->StartUIWindow(HOARD_CONFIG_DLG, &config); |
| 1504 | } |
| 1505 | |
| 1506 | void SwitchHUDColor(int i) { HUD_color_model = i; } |