| 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/monsterball/monsterball.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003/08/26 03:58:29 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Monmsterball Multiplayer game |
| 26 | * |
| 27 | * $Log: monsterball.cpp,v $ |
| 28 | * Revision 1.1.1.1 2003/08/26 03:58:29 kevinb |
| 29 | * initial 1.5 import |
| 30 | * |
| 31 | * |
| 32 | * 43 9/24/01 3:17p Matt |
| 33 | * Only show results for two teams, since there are always only two teams. |
| 34 | * |
| 35 | * 42 9/24/01 2:28p Matt |
| 36 | * Allowed room for longer team name on results screen. |
| 37 | * |
| 38 | * 41 9/13/01 5:30p Matt |
| 39 | * Added a team member list to the stats display. |
| 40 | * |
| 41 | * 40 10/21/99 2:46p Kevin |
| 42 | * Macintosh merge! |
| 43 | * |
| 44 | * 39 8/17/99 5:53p Jeff |
| 45 | * track ranks on PXO |
| 46 | * |
| 47 | * 38 7/15/99 1:18a Jeff |
| 48 | * fixed up $scores |
| 49 | * |
| 50 | * 37 7/12/99 2:27p Jeff |
| 51 | * fixed PLR to only display the team label for the disconnected list if |
| 52 | * there are people in the list |
| 53 | * |
| 54 | * 36 7/11/99 6:55p Jeff |
| 55 | * fixed PLR so it doesn't go off the screen on long lists and active |
| 56 | * players in the game are shown first |
| 57 | * |
| 58 | * 35 5/23/99 3:04a Jason |
| 59 | * fixed bug with player rankings not being updated correctly |
| 60 | * |
| 61 | * 34 5/13/99 5:08p Ardussi |
| 62 | * changes for compiling on the Mac |
| 63 | * |
| 64 | * 33 5/12/99 11:04p Jeff |
| 65 | * dmfc and multiplayer games now have endian friendly packets (*whew*) |
| 66 | * |
| 67 | * 32 5/12/99 11:29a Jeff |
| 68 | * changed for loop variable for sanity... |
| 69 | * |
| 70 | * 31 5/09/99 6:20a Jeff |
| 71 | * improved Entropy (added sounds, max virii per room). Fixed rendering |
| 72 | * bugs for other multiplayer dlls. |
| 73 | * |
| 74 | * 30 5/08/99 3:54p Jeff |
| 75 | * fixed Post level results screen. Fixed welcome messages. Fixed save |
| 76 | * stats to file generation |
| 77 | * |
| 78 | * 29 5/08/99 5:07a Jeff |
| 79 | * a little touch ups on PLR (needs work) |
| 80 | * |
| 81 | * 28 5/07/99 1:45p Jeff |
| 82 | * don't count dedicated server in team size count |
| 83 | * |
| 84 | * 27 4/30/99 7:37p Jeff |
| 85 | * cool effects when you score |
| 86 | * |
| 87 | * 26 4/28/99 4:24a Jeff |
| 88 | * added safety checks to prevent crashes |
| 89 | * |
| 90 | * 25 4/27/99 3:44p Jeff |
| 91 | * fixed requirement keywords |
| 92 | * |
| 93 | * 24 4/23/99 6:15p Jeff |
| 94 | * fixed double calls to GameClose |
| 95 | * |
| 96 | * 23 4/23/99 12:43p Jeff |
| 97 | * forgot to call CloseGame |
| 98 | * |
| 99 | * 22 4/22/99 7:15p Jeff |
| 100 | * changed requirement strings |
| 101 | * |
| 102 | * 21 4/21/99 5:34p Jeff |
| 103 | * added requirements |
| 104 | * |
| 105 | * 20 4/19/99 6:23p Jeff |
| 106 | * Linux compile |
| 107 | * |
| 108 | * 19 3/31/99 5:49p Jeff |
| 109 | * fixed bug of displaying icon accidently |
| 110 | * |
| 111 | * 18 3/27/99 4:53p Jeff |
| 112 | * player rankings in multiplayer games implemented. Fixed join message |
| 113 | * so it doesn't get cut off |
| 114 | * |
| 115 | * 17 3/19/99 5:42p Jeff |
| 116 | * high res font fixups |
| 117 | * |
| 118 | * 16 3/19/99 12:54p Jeff |
| 119 | * base support for requesting the number of teams for a multiplayer game |
| 120 | * |
| 121 | * 15 3/17/99 12:23p Jeff |
| 122 | * converted DMFC to be COM interface |
| 123 | * |
| 124 | * 14 2/11/99 6:09p Jeff |
| 125 | * localized |
| 126 | * |
| 127 | * 13 2/11/99 12:49a Jeff |
| 128 | * changed names of exported variables |
| 129 | * |
| 130 | * 12 2/10/99 1:48p Matt |
| 131 | * Changed object handle symbolic constants |
| 132 | * |
| 133 | * 11 2/09/99 3:32p Jeff |
| 134 | * table file parser takes quotes strings for force keywords |
| 135 | * |
| 136 | * 10 2/05/99 7:03p Jeff |
| 137 | * table file parsing macros put in |
| 138 | * |
| 139 | * 9 1/31/99 7:26p Matt |
| 140 | * Renamed a bunch of functions to have HUD capitalized |
| 141 | * |
| 142 | * 8 1/24/99 8:32p Jeff |
| 143 | * a bunch of updates to get 100% up to date, added individual scoring. |
| 144 | * |
| 145 | * 7 1/21/99 11:16p Jeff |
| 146 | * exported vecmat functions |
| 147 | * |
| 148 | * 6 1/20/99 8:05p Jeff |
| 149 | * fixed some bugs |
| 150 | * |
| 151 | * 5 1/20/99 2:28p Jeff |
| 152 | * |
| 153 | * 4 1/19/99 9:54p Jeff |
| 154 | * improvements added...very complete |
| 155 | * |
| 156 | * 3 1/19/99 5:34p Jeff |
| 157 | * updated monsterball |
| 158 | * |
| 159 | * 2 1/18/99 12:06a Jeff |
| 160 | * updated to get 90% of base functionality in |
| 161 | * |
| 162 | * $NoKeywords: $ |
| 163 | */ |
| 164 | |
| 165 | #include <cmath> |
| 166 | |
| 167 | #include "gamedll_header.h" |
| 168 | #include "idmfc.h" |
| 169 | #include "monsterball.h" |
| 170 | #include <string.h> |
| 171 | #include "monsterstr.h" |
| 172 | |
| 173 | #include <algorithm> |
| 174 | |
| 175 | IDMFC *DMFCBase = NULL; |
| 176 | static IDmfcStats *dstat = NULL; |
| 177 | static room *dRooms; |
| 178 | static object *dObjects; |
| 179 | static player *dPlayers; |
| 180 | static vis_effect *dVisEffects; |
| 181 | ////////////////////////////////// |
| 182 | // defines |
| 183 | #define SPID_NEWPLAYER 0 |
| 184 | #define SPID_HITINFO 1 |
| 185 | |
| 186 | #define MONSTERBALL_ID_NAME "Monsterball" |
| 187 | #define MONSTERBALL_SND_SCORE "Extra life" |
| 188 | #define MONSTERBALL_SND_PICKUP "IGotIt" |
| 189 | #define MONSTERBALL_SND_HIT "Monsterball Hit" |
| 190 | #define MONSTERBALL_LOSE "Drop unknown " |
| 191 | /* |
| 192 | $$TABLE_SOUND "Extra life" |
| 193 | $$TABLE_GENERIC "Monsterball" |
| 194 | $$TABLE_SOUND "IGotIt" |
| 195 | $$TABLE_SOUND "Monsterball Hit" |
| 196 | $$TABLE_SOUND "Drop unknown " |
| 197 | */ |
| 198 | |
| 199 | #define SCORE_DRAGIN 3 |
| 200 | #define SCORE_HITIN 1 |
| 201 | |
| 202 | #define MAX_MONSTERBALL_VEL 120.0f |
| 203 | |
| 204 | ////////////////////////////////// |
| 205 | // Structs |
| 206 | |
| 207 | struct tPlayerStat { |
| 208 | int Score[2]; |
| 209 | int BadScore[2]; |
| 210 | }; |
| 211 | |
| 212 | static int pack_pstat(tPlayerStat *user_info, uint8_t *data); |
| 213 | static int unpack_pstat(tPlayerStat *user_info, uint8_t *data); |
| 214 | |
| 215 | int pack_pstat(tPlayerStat *user_info, uint8_t *data) { |
| 216 | int count = 0; |
| 217 | MultiAddInt(user_info->Score[0], data, &count); |
| 218 | MultiAddInt(user_info->Score[1], data, &count); |
| 219 | MultiAddInt(user_info->BadScore[0], data, &count); |
| 220 | MultiAddInt(user_info->BadScore[1], data, &count); |
| 221 | return count; |
| 222 | } |
| 223 | |
| 224 | int unpack_pstat(tPlayerStat *user_info, uint8_t *data) { |
| 225 | int count = 0; |
| 226 | user_info->Score[0] = MultiGetInt(data, &count); |
| 227 | user_info->Score[1] = MultiGetInt(data, &count); |
| 228 | user_info->BadScore[0] = MultiGetInt(data, &count); |
| 229 | user_info->BadScore[1] = MultiGetInt(data, &count); |
| 230 | return count; |
| 231 | } |
| 232 | |
| 233 | struct weapon_collide_info { |
| 234 | vector rotvel; |
| 235 | vector velocity; |
| 236 | vector pos; |
| 237 | matrix orient; |
| 238 | float mass; |
| 239 | float size; |
| 240 | }; |
| 241 | |
| 242 | struct { |
| 243 | int id, room; |
| 244 | int objhandle; |
| 245 | int owner_handle; |
| 246 | int icon; |
| 247 | vector pos; |
| 248 | } Monsterball_info; |
| 249 | |
| 250 | ////////////////////////////////// |
| 251 | // Globals |
| 252 | |
| 253 | static int SortedPLRPlayers[DLLMAX_TEAMS][MAX_PLAYER_RECORDS]; |
| 254 | static int TeamScores[DLLMAX_TEAMS]; |
| 255 | static int SortedTeams[DLLMAX_TEAMS]; |
| 256 | static int SortedPlayers[MAX_PLAYER_RECORDS]; |
| 257 | |
| 258 | static int NumOfTeams = 2; |
| 259 | static int WhoJustScored = -1, WhoJustScoredTimer = -1; |
| 260 | static int GoalRooms[DLLMAX_TEAMS]; |
| 261 | static int Highlight_bmp; |
| 262 | static int LastHitPnum = -1; |
| 263 | |
| 264 | static bool players_sorted = false; // the Sorted*[] have been sorted |
| 265 | static bool DisplayPowerBBlink = true; |
| 266 | static bool DisplayScoreBlink = true; |
| 267 | static bool DisplayScoreScreen = false; |
| 268 | static bool display_my_welcome = false; |
| 269 | static bool monsterball_info_set = false; |
| 270 | |
| 271 | /////////////////////////////////////////////// |
| 272 | // localization info |
| 273 | static char **StringTable; |
| 274 | static int StringTableSize = 0; |
| 275 | static const char *_ErrorString = "Missing String"; |
| 276 | const char *GetStringFromTable(int d) { |
| 277 | if ((d < 0) || (d >= StringTableSize)) |
| 278 | return _ErrorString; |
| 279 | else |
| 280 | return StringTable[d]; |
| 281 | } |
| 282 | /////////////////////////////////////////////// |
| 283 | |
| 284 | ////////////////////////////////// |
| 285 | // Prototypes |
| 286 | static void DisplayHUDScores(struct tHUDItem *hitem); |
| 287 | static void DisplayStats(void); |
| 288 | static void GetGameStartPacket(uint8_t *data); |
| 289 | static void SendGameStartPacket(int pnum); |
| 290 | static bool GetMonsterballInfo(int id); |
| 291 | static void SortTeams(void); |
| 292 | static void DisplayWelcomeMessage(int player_num); |
| 293 | static void OnTimerScore(void); |
| 294 | static void OnTimer(void); |
| 295 | static void OnTimerScoreKill(void); |
| 296 | static void OnTimerKill(void); |
| 297 | static void OnTimerRegen(void); |
| 298 | static void OnTimerRegenKill(void); |
| 299 | static void SaveStatsToFile(char *filename); |
| 300 | static void SortPlayerSlots(int *sorted_list, int count); |
| 301 | static void SendLastHitInfo(void); |
| 302 | static void GetLastHitInfo(uint8_t *data); |
| 303 | |
| 304 | static void HandlePickupPowerball(object *owner); |
| 305 | static void HandleLosePowerball(bool play_sound); |
| 306 | static void HandleMonsterballCollideWithObject(object *ball, object *player, vector *point, vector *normal); |
| 307 | static void HandleMonsterballCollideWithWeapon(object *ball, weapon_collide_info *winfo, vector *point, vector *normal); |
| 308 | static void bump_object(object *object0, vector *rotvel, vector *velocity, vector *pos, matrix *orient, float mass, |
| 309 | float size, vector *collision_point, vector *collision_normal, float rot_scale, |
| 310 | float vel_scale); |
| 311 | static void DoMonsterballScoreEffect(void); |
| 312 | static void OnClientPlayerEntersGame(int player_num); |
| 313 | |
| 314 | static bool ValidateOwner(int *pnum, object **obj); |
| 315 | |
| 316 | void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size) { |
| 317 | player_record *pr = DMFCBase->GetPlayerRecord(precord_num); |
| 318 | if (!pr || pr->state == STATE_EMPTY) { |
| 319 | buffer[0] = '\0'; |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | tPlayerStat *stat = (tPlayerStat *)pr->user_info; |
| 324 | |
| 325 | if (column_num == 2) { |
| 326 | snprintf(buffer, buffer_size, "%d", (stat) ? stat->Score[DSTAT_LEVEL] : 0); |
| 327 | } else { |
| 328 | snprintf(buffer, buffer_size, "%d", (stat) ? stat->BadScore[DSTAT_LEVEL] : 0); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | void TeamScoreCallback(int team, char *buffer, int buffer_size) { |
| 333 | ASSERT(team >= 0 && team < DLLMAX_TEAMS); |
| 334 | |
| 335 | snprintf(buffer, buffer_size, " %d", TeamScores[team]); |
| 336 | } |
| 337 | |
| 338 | void ShowStatBitmap(int precord_num, int column_num, int x, int y, int w, int h, uint8_t alpha_to_use) { |
| 339 | player_record *pr = DMFCBase->GetPlayerRecord(precord_num); |
| 340 | |
| 341 | if (!pr || pr->state != STATE_INGAME) |
| 342 | return; |
| 343 | |
| 344 | int pnum; |
| 345 | object *owner; |
| 346 | |
| 347 | if (!ValidateOwner(&pnum, &owner)) |
| 348 | return; |
| 349 | |
| 350 | // the owner is still valid |
| 351 | if (pnum == pr->pnum) { |
| 352 | DLLRenderHUDQuad(x + 2, y, 10, 10, 0, 0, 1, 1, Monsterball_info.icon, alpha_to_use, 0); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | #define NUM_TEAMS 2 |
| 357 | |
| 358 | // This function gets called by the game when it wants to learn some info about the game |
| 359 | void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options) { |
| 360 | options->flags = DOF_MAXTEAMS | DOF_MINTEAMS; |
| 361 | options->max_teams = NUM_TEAMS; |
| 362 | options->min_teams = NUM_TEAMS; |
| 363 | strcpy(options->game_name, TXT_GAMENAME); |
| 364 | strcpy(options->requirements, "MINGOALS2,GOALPERTEAM,SPEC1"); |
| 365 | } |
| 366 | |
| 367 | // Initializes the game function pointers |
| 368 | void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_use) { |
| 369 | *all_ok = 1; |
| 370 | DMFCBase = CreateDMFC(); |
| 371 | if (!DMFCBase) { |
| 372 | *all_ok = 0; |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | dstat = CreateDmfcStats(); |
| 377 | if (!dstat) { |
| 378 | *all_ok = 0; |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | DMFCBase->LoadFunctions(api_func); |
| 383 | |
| 384 | // Setup event handlers |
| 385 | DMFCBase->Set_OnCanChangeTeam(OnCanChangeTeam); |
| 386 | DMFCBase->Set_OnClientPlayerDisconnect(OnClientPlayerDisconnect); |
| 387 | DMFCBase->Set_OnPlayerEntersObserver(OnPlayerEntersObserver); |
| 388 | DMFCBase->Set_OnClientPlayerKilled(OnClientPlayerKilled); |
| 389 | DMFCBase->Set_OnServerObjectShieldsChanged(OnServerObjectShieldsChanged); |
| 390 | DMFCBase->Set_OnGameStateRequest(OnGameStateRequest); |
| 391 | DMFCBase->Set_OnServerGameCreated(OnServerGameCreated); |
| 392 | DMFCBase->Set_OnClientLevelStart(OnClientLevelStart); |
| 393 | DMFCBase->Set_OnPlayerConnect(OnPlayerConnect); |
| 394 | DMFCBase->Set_OnInterval(OnInterval); |
| 395 | DMFCBase->Set_OnHUDInterval(OnHUDInterval); |
| 396 | DMFCBase->Set_OnKeypress(OnKeypress); |
| 397 | DMFCBase->Set_OnServerCollide(OnServerCollide); |
| 398 | DMFCBase->Set_OnClientCollide(OnClientCollide); |
| 399 | DMFCBase->Set_OnServerPlayerChangeSegment(OnServerPlayerChangeSegment); |
| 400 | DMFCBase->Set_OnClientPlayerChangeSegment(OnClientPlayerChangeSegment); |
| 401 | DMFCBase->Set_OnServerObjectChangeSegment(OnServerObjectChangeSegment); |
| 402 | DMFCBase->Set_OnClientObjectChangeSegment(OnClientObjectChangeSegment); |
| 403 | DMFCBase->Set_OnSaveStatsToFile(OnSaveStatsToFile); |
| 404 | DMFCBase->Set_OnLevelEndSaveStatsToFile(OnLevelEndSaveStatsToFile); |
| 405 | DMFCBase->Set_OnDisconnectSaveStatsToFile(OnDisconnectSaveStatsToFile); |
| 406 | DMFCBase->Set_OnPLRInterval(OnPLRInterval); |
| 407 | DMFCBase->Set_OnPLRInit(OnPLRInit); |
| 408 | DMFCBase->Set_OnPrintScores(OnPrintScores); |
| 409 | DMFCBase->Set_OnClientPlayerEntersGame(OnClientPlayerEntersGame); |
| 410 | |
| 411 | // setup arrays |
| 412 | dRooms = DMFCBase->GetRooms(); |
| 413 | dObjects = DMFCBase->GetObjects(); |
| 414 | dPlayers = DMFCBase->GetPlayers(); |
| 415 | dVisEffects = DMFCBase->GetVisEffectArray(); |
| 416 | |
| 417 | netgame_info *Netgame = DMFCBase->GetNetgameInfo(); |
| 418 | Netgame->flags |= (NF_TRACK_RANK); |
| 419 | |
| 420 | DMFCBase->GameInit(NumOfTeams); |
| 421 | DLLCreateStringTable("monster.str", &StringTable, &StringTableSize); |
| 422 | DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); |
| 423 | |
| 424 | // add the death and suicide messages |
| 425 | DMFCBase->AddDeathMessage(TXT_KILLEDA, true); |
| 426 | DMFCBase->AddSuicideMessage(TXT_SUICIDEA); |
| 427 | |
| 428 | // setup the Playerstats struct so DMFC can handle it automatically when a new player enters the game |
| 429 | DMFCBase->SetupPlayerRecord(sizeof(tPlayerStat), (int (*)(void *, uint8_t *))pack_pstat, |
| 430 | (int (*)(void *, uint8_t *))unpack_pstat); |
| 431 | |
| 432 | // register special packet receivers |
| 433 | DMFCBase->RegisterPacketReceiver(SPID_NEWPLAYER, GetGameStartPacket); |
| 434 | DMFCBase->RegisterPacketReceiver(SPID_HITINFO, GetLastHitInfo); |
| 435 | |
| 436 | DMFCBase->SetNumberOfTeams(NumOfTeams); |
| 437 | |
| 438 | DMFCBase->AddHUDItemCallback(HI_TEXT, DisplayHUDScores); |
| 439 | |
| 440 | Monsterball_info.icon = DLLbm_AllocLoadFileBitmap("PowerballIcon.ogf", 0, BITMAP_FORMAT_1555); |
| 441 | if (Monsterball_info.icon == -1) |
| 442 | Monsterball_info.icon = BAD_BITMAP_HANDLE; |
| 443 | |
| 444 | DisplayScoreScreen = false; |
| 445 | |
| 446 | // TableFileAdd("Monsterball.Gam"); |
| 447 | |
| 448 | Highlight_bmp = DLLbm_AllocBitmap(32, 32, 0); |
| 449 | if (Highlight_bmp > BAD_BITMAP_HANDLE) { |
| 450 | uint16_t *data = DLLbm_data(Highlight_bmp, 0); |
| 451 | if (!data) { |
| 452 | // bail on out of here |
| 453 | *all_ok = 0; |
| 454 | return; |
| 455 | } |
| 456 | for (int x = 0; x < 32 * 32; x++) { |
| 457 | data[x] = GR_RGB16(50, 50, 50) | OPAQUE_FLAG; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | // Initialize the Stats Manager |
| 462 | // ---------------------------- |
| 463 | tDmfcStatsInit tsi; |
| 464 | tDmfcStatsColumnInfo pl_col[8]; |
| 465 | char gname[20]; |
| 466 | strcpy(gname, TXT_STATGAMENAME); |
| 467 | |
| 468 | tsi.flags = DSIF_SHOW_PIC | DSIF_SHOW_OBSERVERICON | DSIF_SEPERATE_BY_TEAM; |
| 469 | tsi.cColumnCountDetailed = 0; |
| 470 | tsi.cColumnCountPlayerList = 8; |
| 471 | tsi.clbDetailedColumnBMP = NULL; |
| 472 | tsi.clbDetailedColumn = NULL; |
| 473 | tsi.clbPlayerColumn = DetermineScore; |
| 474 | tsi.clbPlayerColumnBMP = ShowStatBitmap; |
| 475 | tsi.DetailedColumns = NULL; |
| 476 | tsi.GameName = gname; |
| 477 | tsi.MaxNumberDisplayed = NULL; |
| 478 | tsi.PlayerListColumns = pl_col; |
| 479 | tsi.SortedPlayerRecords = SortedPlayers; |
| 480 | tsi.clTeamLine = TeamScoreCallback; |
| 481 | |
| 482 | pl_col[0].color_type = DSCOLOR_TEAM; |
| 483 | pl_col[0].title[0] = '\0'; |
| 484 | pl_col[0].type = DSCOL_BMP; |
| 485 | pl_col[0].width = 15; |
| 486 | |
| 487 | pl_col[1].color_type = DSCOLOR_TEAM; |
| 488 | strcpy(pl_col[1].title, TXT_PILOT); |
| 489 | pl_col[1].type = DSCOL_PILOT_NAME; |
| 490 | pl_col[1].width = 110; |
| 491 | |
| 492 | pl_col[2].color_type = DSCOLOR_TEAM; |
| 493 | strcpy(pl_col[2].title, TXT_POINTS); |
| 494 | pl_col[2].type = DSCOL_CUSTOM; |
| 495 | pl_col[2].width = 51; |
| 496 | |
| 497 | pl_col[3].color_type = DSCOLOR_TEAM; |
| 498 | strcpy(pl_col[3].title, TXT_BLUNDERS); |
| 499 | pl_col[3].type = DSCOL_CUSTOM; |
| 500 | pl_col[3].width = 64; |
| 501 | |
| 502 | pl_col[4].color_type = DSCOLOR_TEAM; |
| 503 | strcpy(pl_col[4].title, TXT_KILLSSHORT); |
| 504 | pl_col[4].type = DSCOL_KILLS_LEVEL; |
| 505 | pl_col[4].width = 41; |
| 506 | |
| 507 | pl_col[5].color_type = DSCOLOR_TEAM; |
| 508 | strcpy(pl_col[5].title, TXT_DEATHSSHORT); |
| 509 | pl_col[5].type = DSCOL_DEATHS_LEVEL; |
| 510 | pl_col[5].width = 41; |
| 511 | |
| 512 | pl_col[6].color_type = DSCOLOR_TEAM; |
| 513 | strcpy(pl_col[6].title, TXT_SUICIDESSHORT); |
| 514 | pl_col[6].type = DSCOL_SUICIDES_LEVEL; |
| 515 | pl_col[6].width = 41; |
| 516 | |
| 517 | pl_col[7].color_type = DSCOLOR_TEAM; |
| 518 | strcpy(pl_col[7].title, TXT_PING); |
| 519 | pl_col[7].type = DSCOL_PING; |
| 520 | pl_col[7].width = 40; |
| 521 | |
| 522 | dstat->Initialize(&tsi); |
| 523 | } |
| 524 | |
| 525 | // Called when the DLL is shutdown |
| 526 | void DLLFUNCCALL DLLGameClose() { |
| 527 | if (Monsterball_info.icon > BAD_BITMAP_HANDLE) |
| 528 | DLLbm_FreeBitmap(Monsterball_info.icon); |
| 529 | |
| 530 | DLLDestroyStringTable(StringTable, StringTableSize); |
| 531 | |
| 532 | if (dstat) { |
| 533 | dstat->DestroyPointer(); |
| 534 | dstat = NULL; |
| 535 | } |
| 536 | |
| 537 | if (DMFCBase) { |
| 538 | DMFCBase->GameClose(); |
| 539 | DMFCBase->DestroyPointer(); |
| 540 | DMFCBase = NULL; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | bool OnCanChangeTeam(int pnum, int newteam) { |
| 545 | if (!DMFCBase->OnCanChangeTeam(pnum, newteam)) |
| 546 | return false; |
| 547 | |
| 548 | int p; |
| 549 | if (!ValidateOwner(&p, NULL)) |
| 550 | return true; |
| 551 | |
| 552 | if (p == pnum) |
| 553 | return false; |
| 554 | |
| 555 | return true; |
| 556 | } |
| 557 | |
| 558 | void OnHUDInterval(void) { |
| 559 | dstat->DoFrame(); |
| 560 | DMFCBase->DisplayOutrageLogo(); |
| 561 | |
| 562 | DMFCBase->OnHUDInterval(); |
| 563 | } |
| 564 | |
| 565 | void OnInterval(void) { |
| 566 | SortPlayerSlots(SortedPlayers, MAX_PLAYER_RECORDS); |
| 567 | players_sorted = true; |
| 568 | SortTeams(); |
| 569 | |
| 570 | if (DMFCBase->GetLocalRole() == LR_SERVER) { |
| 571 | // make sure velocity of the ball isn't more than MAX_MONSTERBALL_VEL |
| 572 | object *ball; |
| 573 | if (!DLLObjGet(Monsterball_info.objhandle, &ball)) { |
| 574 | // blah! |
| 575 | FatalError("MONSTERBALL IS MISSING\n"); |
| 576 | } |
| 577 | |
| 578 | float mag = DLLvm_GetMagnitudeFast(&ball->mtype.phys_info.velocity); |
| 579 | if (mag > MAX_MONSTERBALL_VEL) { |
| 580 | ball->mtype.phys_info.velocity /= mag; |
| 581 | ball->mtype.phys_info.velocity *= MAX_MONSTERBALL_VEL; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | DMFCBase->OnInterval(); |
| 586 | } |
| 587 | |
| 588 | void OnKeypress(int key) { |
| 589 | dllinfo *Data = DMFCBase->GetDLLInfoCallData(); |
| 590 | switch (key) { |
| 591 | case K_F7: |
| 592 | DisplayScoreScreen = !DisplayScoreScreen; |
| 593 | DMFCBase->EnableOnScreenMenu(false); |
| 594 | dstat->Enable(DisplayScoreScreen); |
| 595 | break; |
| 596 | case K_PAGEDOWN: |
| 597 | if (DisplayScoreScreen) { |
| 598 | dstat->ScrollDown(); |
| 599 | Data->iRet = 1; |
| 600 | } |
| 601 | break; |
| 602 | case K_PAGEUP: |
| 603 | if (DisplayScoreScreen) { |
| 604 | dstat->ScrollUp(); |
| 605 | Data->iRet = 1; |
| 606 | } |
| 607 | break; |
| 608 | case K_F6: |
| 609 | DisplayScoreScreen = false; |
| 610 | dstat->Enable(false); |
| 611 | break; |
| 612 | case K_ESC: |
| 613 | if (DisplayScoreScreen) { |
| 614 | dstat->Enable(false); |
| 615 | DisplayScoreScreen = false; |
| 616 | Data->iRet = 1; |
| 617 | } |
| 618 | break; |
| 619 | } |
| 620 | |
| 621 | DMFCBase->OnKeypress(key); |
| 622 | } |
| 623 | |
| 624 | // The server has just started, so clear out all the stats and game info |
| 625 | void OnServerGameCreated(void) { |
| 626 | DMFCBase->OnServerGameCreated(); |
| 627 | tPlayerStat *stat; |
| 628 | player_record *pr; |
| 629 | int i; |
| 630 | |
| 631 | for (i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 632 | pr = DMFCBase->GetPlayerRecord(i); |
| 633 | if (!pr) |
| 634 | continue; |
| 635 | |
| 636 | stat = (tPlayerStat *)pr->user_info; |
| 637 | if (stat) { |
| 638 | stat->Score[DSTAT_LEVEL] = stat->Score[DSTAT_OVERALL] = 0; |
| 639 | stat->BadScore[DSTAT_LEVEL] = stat->BadScore[DSTAT_OVERALL] = 0; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | for (i = 0; i < NumOfTeams; i++) { |
| 644 | TeamScores[i] = 0; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | void OnServerCollide(object *me_obj, object *it_obj, vector *point, vector *normal) { |
| 649 | if (!me_obj || !it_obj) { |
| 650 | DMFCBase->OnServerCollide(me_obj, it_obj, point, normal); |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | // check to see if the collision was with the Monsterball |
| 655 | if (me_obj->handle == Monsterball_info.objhandle) { |
| 656 | |
| 657 | LastHitPnum = -1; |
| 658 | |
| 659 | switch (it_obj->type) { |
| 660 | case OBJ_PLAYER: { |
| 661 | if (DMFCBase->IsPlayerAlive(it_obj->id)) { |
| 662 | LastHitPnum = it_obj->id; |
| 663 | |
| 664 | // call the event on the client so they can do any physics sim |
| 665 | DMFCBase->CallClientEvent(EVT_CLIENT_GAMECOLLIDE, DMFCBase->GetMeObjNum(), DMFCBase->GetItObjNum(), -1, true); |
| 666 | DMFCBase->CallOnClientCollide(me_obj, it_obj, point, normal); |
| 667 | } |
| 668 | } break; |
| 669 | case OBJ_WEAPON: { |
| 670 | object *parent; |
| 671 | DLLGetUltimateParentForObject(&parent, it_obj); |
| 672 | if (parent->type == OBJ_PLAYER) { |
| 673 | LastHitPnum = parent->id; |
| 674 | } |
| 675 | |
| 676 | weapon_collide_info winfo; |
| 677 | winfo.rotvel.x = it_obj->mtype.phys_info.rotvel.x; |
| 678 | winfo.rotvel.y = it_obj->mtype.phys_info.rotvel.y; |
| 679 | winfo.rotvel.z = it_obj->mtype.phys_info.rotvel.z; |
| 680 | winfo.velocity.x = it_obj->mtype.phys_info.velocity.x; |
| 681 | winfo.velocity.y = it_obj->mtype.phys_info.velocity.y; |
| 682 | winfo.velocity.z = it_obj->mtype.phys_info.velocity.z; |
| 683 | winfo.pos.x = it_obj->pos.x; |
| 684 | winfo.pos.y = it_obj->pos.y; |
| 685 | winfo.pos.z = it_obj->pos.z; |
| 686 | winfo.orient.fvec.x = it_obj->orient.fvec.x; |
| 687 | winfo.orient.fvec.y = it_obj->orient.fvec.y; |
| 688 | winfo.orient.fvec.z = it_obj->orient.fvec.z; |
| 689 | winfo.orient.uvec.x = it_obj->orient.uvec.x; |
| 690 | winfo.orient.uvec.y = it_obj->orient.uvec.y; |
| 691 | winfo.orient.uvec.z = it_obj->orient.uvec.z; |
| 692 | winfo.orient.rvec.x = it_obj->orient.rvec.x; |
| 693 | winfo.orient.rvec.y = it_obj->orient.rvec.y; |
| 694 | winfo.orient.rvec.z = it_obj->orient.rvec.z; |
| 695 | winfo.mass = it_obj->mtype.phys_info.mass; |
| 696 | winfo.size = it_obj->size; |
| 697 | HandleMonsterballCollideWithWeapon(me_obj, &winfo, point, normal); |
| 698 | } break; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | // check to see if the collision was between a player and another player, who has the powerball |
| 703 | if (me_obj->type == OBJ_PLAYER && (it_obj->type == OBJ_PLAYER || it_obj->type == OBJ_WEAPON)) { |
| 704 | if (it_obj->type == OBJ_PLAYER && !DMFCBase->IsPlayerAlive(it_obj->id)) { |
| 705 | // the collided player isn't alive |
| 706 | } else { |
| 707 | int p; |
| 708 | if (ValidateOwner(&p, NULL)) { |
| 709 | if (p == me_obj->id) { |
| 710 | // the player has the powerball |
| 711 | DMFCBase->CallClientEvent(EVT_CLIENT_GAMECOLLIDE, DMFCBase->GetMeObjNum(), DMFCBase->GetItObjNum(), -1, true); |
| 712 | DMFCBase->CallOnClientCollide(me_obj, it_obj, point, normal); |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | DMFCBase->OnServerCollide(me_obj, it_obj, point, normal); |
| 719 | } |
| 720 | |
| 721 | void OnClientPlayerDisconnect(int player_num) { |
| 722 | int p; |
| 723 | if (ValidateOwner(&p, NULL)) { |
| 724 | if (p == player_num) { |
| 725 | HandleLosePowerball(true); |
| 726 | } |
| 727 | } |
| 728 | DMFCBase->OnClientPlayerDisconnect(player_num); |
| 729 | } |
| 730 | |
| 731 | void OnPlayerEntersObserver(int pnum, object *piggy) { |
| 732 | int p; |
| 733 | if (ValidateOwner(&p, NULL)) { |
| 734 | if (p == pnum) { |
| 735 | HandleLosePowerball(true); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | DMFCBase->OnPlayerEntersObserver(pnum, piggy); |
| 740 | } |
| 741 | |
| 742 | void OnClientPlayerKilled(object *killer_obj, int victim_pnum) { |
| 743 | int p; |
| 744 | if (ValidateOwner(&p, NULL)) { |
| 745 | if (p == victim_pnum) { |
| 746 | HandleLosePowerball(true); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | DMFCBase->OnClientPlayerKilled(killer_obj, victim_pnum); |
| 751 | } |
| 752 | |
| 753 | void HandleLosePowerball(bool play_sound) { |
| 754 | static int sound = -1; |
| 755 | |
| 756 | object *owner; |
| 757 | if (!ValidateOwner(NULL, &owner)) |
| 758 | return; |
| 759 | |
| 760 | object *ball; |
| 761 | if (!DLLObjGet(Monsterball_info.objhandle, &ball)) { |
| 762 | // blah! |
| 763 | FatalError("MONSTERBALL IS MISSING\n"); |
| 764 | } |
| 765 | |
| 766 | if (play_sound) { |
| 767 | if (sound == -1) |
| 768 | sound = DLLFindSoundName(IGNORE_TABLE(MONSTERBALL_LOSE)); |
| 769 | if (sound != -1) |
| 770 | DLLPlay2dSound(sound, 1); |
| 771 | } |
| 772 | |
| 773 | if (DMFCBase->GetLocalRole() == LR_SERVER) |
| 774 | DLLUnattachFromParent(ball); |
| 775 | |
| 776 | Monsterball_info.owner_handle = OBJECT_HANDLE_NONE; |
| 777 | } |
| 778 | |
| 779 | void HandlePickupPowerball(object *owner) { |
| 780 | static int sound = -1; |
| 781 | |
| 782 | if (sound == -1) |
| 783 | sound = DLLFindSoundName(IGNORE_TABLE(MONSTERBALL_SND_PICKUP)); |
| 784 | if (sound != -1) |
| 785 | DLLPlay2dSound(sound, MAX_GAME_VOLUME / 2); |
| 786 | |
| 787 | if (DMFCBase->GetLocalRole() == LR_SERVER) { |
| 788 | // if it was a player, attach the ball to the player |
| 789 | object *bobj; |
| 790 | if (!DLLObjGet(Monsterball_info.objhandle, &bobj)) { |
| 791 | FatalError("Monster Ball not found\n"); |
| 792 | } |
| 793 | |
| 794 | bool ret = DLLAttachObject(owner, 0, bobj, 0, true); |
| 795 | if (!ret) { |
| 796 | // blah! |
| 797 | mprintf(0, "COULDN'T ATTACH MONSTERBALL TO PLAYER!!!!!!\n"); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | Monsterball_info.owner_handle = owner->handle; |
| 802 | } |
| 803 | |
| 804 | void OnClientCollide(object *me_obj, object *it_obj, vector *point, vector *normal) { |
| 805 | // three things can happen in here |
| 806 | // 1) The collision is between the ball (with no owner) and a player |
| 807 | // 2) The collision is between the owner and another player or weapon |
| 808 | // 3) The collision is between the ball and a robot |
| 809 | |
| 810 | if (me_obj && me_obj->type == OBJ_PLAYER) { |
| 811 | // case 2: me_obj = owner |
| 812 | // Result: The owner is to lose the monsterball |
| 813 | HandleLosePowerball(true); |
| 814 | DMFCBase->OnClientCollide(me_obj, it_obj, point, normal); |
| 815 | return; |
| 816 | } |
| 817 | |
| 818 | if (me_obj && me_obj->type == OBJ_ROBOT) { |
| 819 | |
| 820 | if (it_obj->type == OBJ_ROBOT) { |
| 821 | // case 3: me_obj = monsterball it_obj = robot |
| 822 | if (DMFCBase->GetLocalRole() == LR_SERVER) { |
| 823 | // do the physics on the Monsterball |
| 824 | HandleMonsterballCollideWithObject(me_obj, it_obj, point, normal); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | if (it_obj->type == OBJ_PLAYER) { |
| 829 | // case 1: me_obj = monsterball it_obj = player |
| 830 | // Result: The player is to pickup the monsterball (as long as it has no owner) |
| 831 | int p = 0; |
| 832 | if (!ValidateOwner(&p, NULL) && p != it_obj->id) { |
| 833 | ASSERT(it_obj->type == OBJ_PLAYER); |
| 834 | // HandlePickupPowerball(it_obj); |
| 835 | HandleMonsterballCollideWithObject(me_obj, it_obj, point, normal); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | DMFCBase->OnClientCollide(me_obj, it_obj, point, normal); |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | DMFCBase->OnClientCollide(me_obj, it_obj, point, normal); |
| 844 | } |
| 845 | |
| 846 | void OnServerObjectShieldsChanged(object *obj, float amount) { |
| 847 | if (!obj) |
| 848 | return; |
| 849 | if (obj->handle == Monsterball_info.objhandle) { |
| 850 | obj->shields += amount; |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | void OnServerObjectChangeSegment(object *obj, int newseg, int oldseg) { |
| 855 | if (!obj) { |
| 856 | DMFCBase->OnServerObjectChangeSegment(obj, newseg, oldseg); |
| 857 | return; |
| 858 | } |
| 859 | |
| 860 | if (obj->type == OBJ_ROBOT && obj->handle == Monsterball_info.objhandle) { |
| 861 | // this is the monster ball, see if it's going into a goal room |
| 862 | bool is_goal = false; |
| 863 | for (int i = 0; i < NumOfTeams; i++) { |
| 864 | if (newseg == GoalRooms[i]) { |
| 865 | is_goal = true; |
| 866 | break; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | if (is_goal && !ValidateOwner(NULL, NULL)) { |
| 871 | // it's a team goal |
| 872 | SendLastHitInfo(); |
| 873 | DMFCBase->CallClientEvent(EVT_CLIENT_GAMEOBJCHANGESEG, DMFCBase->GetMeObjNum(), DMFCBase->GetItObjNum(), -1, |
| 874 | true); |
| 875 | DMFCBase->CallOnClientObjectChangeSegment(obj, newseg, oldseg); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | DMFCBase->OnServerObjectChangeSegment(obj, newseg, oldseg); |
| 880 | } |
| 881 | |
| 882 | void OnClientObjectChangeSegment(object *obj, int newseg, int oldseg) { |
| 883 | static int sound = -1; |
| 884 | |
| 885 | if (!obj) { |
| 886 | DMFCBase->OnClientObjectChangeSegment(obj, newseg, oldseg); |
| 887 | FatalError("INVALID OBJECT PASSED INTO OnClientObjectChangeSegment()"); |
| 888 | return; |
| 889 | } |
| 890 | int team = -1; |
| 891 | |
| 892 | for (int i = 0; i < NumOfTeams; i++) { |
| 893 | if (newseg == GoalRooms[i]) { |
| 894 | team = i; |
| 895 | break; |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | if (team < 0 || team >= NumOfTeams) { |
| 900 | FatalError("NOT A GOAL ROOM\n"); |
| 901 | return; |
| 902 | } |
| 903 | |
| 904 | if (sound == -1) |
| 905 | sound = DLLFindSoundName(IGNORE_TABLE(MONSTERBALL_SND_SCORE)); |
| 906 | if (sound != -1) |
| 907 | DLLPlay2dSound(sound, MAX_GAME_VOLUME * 0.66f); |
| 908 | |
| 909 | DoMonsterballScoreEffect(); |
| 910 | |
| 911 | DLLvm_MakeVectorZero(&obj->mtype.phys_info.velocity); |
| 912 | DLLvm_MakeIdentity(&obj->orient); |
| 913 | DLLObjSetPos(obj, &Monsterball_info.pos, Monsterball_info.room, NULL, false); |
| 914 | |
| 915 | if (!DMFCBase->CheckPlayerNum(LastHitPnum)) { |
| 916 | if (SCORE_HITIN == 1) { |
| 917 | DLLAddHUDMessage(TXT_SCOREONE, DMFCBase->GetTeamString(team)); |
| 918 | } else { |
| 919 | DLLAddHUDMessage(TXT_SCOREMULTI, DMFCBase->GetTeamString(team), SCORE_HITIN); |
| 920 | } |
| 921 | } else { |
| 922 | int last_hit_team = dPlayers[LastHitPnum].team; |
| 923 | char *callsign = dPlayers[LastHitPnum].callsign; |
| 924 | tPlayerStat *stat = (tPlayerStat *)DMFCBase->GetPlayerRecordData(LastHitPnum); |
| 925 | |
| 926 | if (last_hit_team != team) { |
| 927 | // he scored for the other team!!! |
| 928 | |
| 929 | if (SCORE_HITIN == 1) { |
| 930 | DLLAddHUDMessage(TXT_BLUNDERSCORE, callsign, DMFCBase->GetTeamString(team)); |
| 931 | } else { |
| 932 | DLLAddHUDMessage(TXT_BLUNDERMULTISCORE, callsign, SCORE_HITIN, DMFCBase->GetTeamString(team)); |
| 933 | } |
| 934 | |
| 935 | if (stat) { |
| 936 | stat->BadScore[DSTAT_LEVEL]++; |
| 937 | stat->BadScore[DSTAT_OVERALL]++; |
| 938 | } |
| 939 | } else { |
| 940 | // good score! |
| 941 | if (SCORE_HITIN == 1) { |
| 942 | DLLAddHUDMessage(TXT_PLAYERSCORE, callsign, DMFCBase->GetTeamString(team)); |
| 943 | } else { |
| 944 | DLLAddHUDMessage(TXT_PLAYERMULTISCORE, callsign, DMFCBase->GetTeamString(team), SCORE_HITIN); |
| 945 | } |
| 946 | |
| 947 | if (stat) { |
| 948 | stat->Score[DSTAT_LEVEL]++; |
| 949 | stat->Score[DSTAT_OVERALL]++; |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | TeamScores[team] += SCORE_HITIN; |
| 955 | |
| 956 | // do killgoal check |
| 957 | int goal; |
| 958 | if ((DMFCBase->GetScoreLimit(&goal)) && (DMFCBase->GetLocalRole() == LR_SERVER)) { |
| 959 | if (TeamScores[team] >= goal) |
| 960 | DMFCBase->EndLevel(); |
| 961 | } |
| 962 | |
| 963 | // Set a Timer to display |
| 964 | if (WhoJustScoredTimer != -1) |
| 965 | DMFCBase->KillTimer(WhoJustScoredTimer); |
| 966 | WhoJustScoredTimer = DMFCBase->SetTimerInterval(OnTimerScore, 0.5f, 5.0f, OnTimerScoreKill); |
| 967 | WhoJustScored = team; |
| 968 | |
| 969 | DMFCBase->OnClientObjectChangeSegment(obj, newseg, oldseg); |
| 970 | } |
| 971 | |
| 972 | void OnServerPlayerChangeSegment(int player_num, int newseg, int oldseg) { |
| 973 | if (player_num == -1) |
| 974 | return; |
| 975 | if (newseg == GoalRooms[DMFCBase->GetPlayerTeam(player_num)]) { |
| 976 | // check to see if a player dragged the ball into the goal |
| 977 | int p; |
| 978 | if (ValidateOwner(&p, NULL)) { |
| 979 | // a player currently has the monsterball |
| 980 | if (p == player_num) { |
| 981 | // it's this player |
| 982 | DMFCBase->CallClientEvent(EVT_CLIENT_GAMEPLAYERCHANGESEG, DMFCBase->GetMeObjNum(), DMFCBase->GetItObjNum(), -1); |
| 983 | DMFCBase->CallOnClientPlayerChangeSegment(player_num, newseg, oldseg); |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | DMFCBase->OnServerPlayerChangeSegment(player_num, newseg, oldseg); |
| 988 | } |
| 989 | |
| 990 | void OnClientPlayerChangeSegment(int player_num, int newseg, int oldseg) { |
| 991 | // If we get here, than a player dragged the powerball into their goal |
| 992 | static int sound = -1; |
| 993 | object *bobj; |
| 994 | int p; |
| 995 | |
| 996 | // if we got here than the player with the Monsterball has entered his team's goal! |
| 997 | |
| 998 | if (DMFCBase->IsPlayerDedicatedServer(player_num)) |
| 999 | return; // dedicated server |
| 1000 | |
| 1001 | if (!ValidateOwner(&p, NULL)) { |
| 1002 | return; |
| 1003 | } |
| 1004 | if (p != player_num) |
| 1005 | return; |
| 1006 | |
| 1007 | HandleLosePowerball(false); |
| 1008 | |
| 1009 | if (!DLLObjGet(Monsterball_info.objhandle, &bobj)) { |
| 1010 | FatalError("MonsterBall Is Missing!\n"); |
| 1011 | } |
| 1012 | |
| 1013 | DLLObjSetPos(bobj, &Monsterball_info.pos, Monsterball_info.room, NULL, false); |
| 1014 | |
| 1015 | if (SCORE_DRAGIN == 1) |
| 1016 | DLLAddHUDMessage(TXT_SCOREONE, DMFCBase->GetTeamString(dPlayers[player_num].team)); |
| 1017 | else |
| 1018 | DLLAddHUDMessage(TXT_SCOREMULTI, DMFCBase->GetTeamString(dPlayers[player_num].team), SCORE_DRAGIN); |
| 1019 | |
| 1020 | TeamScores[dPlayers[player_num].team] += SCORE_DRAGIN; |
| 1021 | |
| 1022 | if (sound == -1) |
| 1023 | sound = DLLFindSoundName(IGNORE_TABLE(MONSTERBALL_SND_SCORE)); |
| 1024 | if (sound != -1) |
| 1025 | DLLPlay2dSound(sound, MAX_GAME_VOLUME / 2); |
| 1026 | |
| 1027 | // do killgoal check |
| 1028 | int goal; |
| 1029 | if ((DMFCBase->GetScoreLimit(&goal)) && (DMFCBase->GetLocalRole() == LR_SERVER)) { |
| 1030 | if (TeamScores[dPlayers[player_num].team] >= goal) |
| 1031 | DMFCBase->EndLevel(); |
| 1032 | } |
| 1033 | |
| 1034 | // Set a Timer to display |
| 1035 | if (WhoJustScoredTimer != -1) |
| 1036 | DMFCBase->KillTimer(WhoJustScoredTimer); |
| 1037 | WhoJustScoredTimer = DMFCBase->SetTimerInterval(OnTimerScore, 0.5f, 5.0f, OnTimerScoreKill); |
| 1038 | WhoJustScored = dPlayers[player_num].team; |
| 1039 | } |
| 1040 | |
| 1041 | // The server has started a new level, so clear out any scores needed to be reset |
| 1042 | void OnClientLevelStart(void) { |
| 1043 | DMFCBase->OnClientLevelStart(); |
| 1044 | |
| 1045 | tPlayerStat *stat; |
| 1046 | int i; |
| 1047 | player_record *pr; |
| 1048 | |
| 1049 | for (i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 1050 | pr = DMFCBase->GetPlayerRecord(i); |
| 1051 | if (pr) |
| 1052 | stat = (tPlayerStat *)pr->user_info; |
| 1053 | else |
| 1054 | stat = NULL; |
| 1055 | if (stat) { |
| 1056 | stat->Score[DSTAT_LEVEL] = 0; |
| 1057 | stat->BadScore[DSTAT_LEVEL] = 0; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | for (i = 0; i < NumOfTeams; i++) { |
| 1062 | TeamScores[i] = 0; |
| 1063 | GoalRooms[i] = DLLGetGoalRoomForTeam(i); |
| 1064 | } |
| 1065 | LastHitPnum = -1; |
| 1066 | |
| 1067 | DLLMultiPaintGoalRooms(NULL); |
| 1068 | |
| 1069 | DLLmprintf(0, "Getting Monsterball info\n"); |
| 1070 | if (!GetMonsterballInfo(DLLFindObjectIDName(IGNORE_TABLE(MONSTERBALL_ID_NAME)))) { |
| 1071 | FatalError("Error finding Monsterball room\n"); |
| 1072 | } |
| 1073 | |
| 1074 | if (DMFCBase->GetLocalRole() == LR_SERVER) { |
| 1075 | int objnum = DLLObjCreate(OBJ_ROBOT, Monsterball_info.id, Monsterball_info.room, &Monsterball_info.pos, NULL, |
| 1076 | OBJECT_HANDLE_NONE); |
| 1077 | if (objnum == -1) |
| 1078 | FatalError("Unable to create Monsterball"); |
| 1079 | |
| 1080 | dObjects[objnum].mtype.phys_info.rotdrag = 5.0f; |
| 1081 | |
| 1082 | DLLMultiSendObject(&dObjects[objnum], 1, true); |
| 1083 | Monsterball_info.objhandle = dObjects[objnum].handle; |
| 1084 | Monsterball_info.owner_handle = OBJECT_HANDLE_NONE; |
| 1085 | monsterball_info_set = true; |
| 1086 | } else { |
| 1087 | DMFCBase->RequestGameState(); |
| 1088 | } |
| 1089 | players_sorted = false; |
| 1090 | } |
| 1091 | |
| 1092 | // A New Player has entered the game, so we want to send him a game status packet that |
| 1093 | // has information about the game |
| 1094 | void OnGameStateRequest(int player_num) { |
| 1095 | SendGameStartPacket(player_num); |
| 1096 | DMFCBase->OnGameStateRequest(player_num); |
| 1097 | } |
| 1098 | |
| 1099 | // A new player has entered the game, zero their stats out |
| 1100 | void OnPlayerConnect(int player_num) { |
| 1101 | tPlayerStat *stat = (tPlayerStat *)DMFCBase->GetPlayerRecordData(player_num); |
| 1102 | if (stat) { |
| 1103 | stat->Score[DSTAT_LEVEL] = 0; |
| 1104 | stat->Score[DSTAT_OVERALL] = 0; |
| 1105 | stat->BadScore[DSTAT_LEVEL] = 0; |
| 1106 | stat->BadScore[DSTAT_OVERALL] = 0; |
| 1107 | } |
| 1108 | |
| 1109 | DMFCBase->OnPlayerConnect(player_num); |
| 1110 | } |
| 1111 | |
| 1112 | // A new player has entered the game, zero there stats out |
| 1113 | void OnClientPlayerEntersGame(int player_num) { |
| 1114 | DMFCBase->OnClientPlayerEntersGame(player_num); |
| 1115 | if (player_num != DMFCBase->GetPlayerNum()) |
| 1116 | DisplayWelcomeMessage(player_num); |
| 1117 | else |
| 1118 | display_my_welcome = true; |
| 1119 | } |
| 1120 | |
| 1121 | bool compare_slots(int a, int b) { |
| 1122 | int ascore, bscore; |
| 1123 | player_record *apr, *bpr; |
| 1124 | tPlayerStat *astat, *bstat; |
| 1125 | |
| 1126 | apr = DMFCBase->GetPlayerRecord(a); |
| 1127 | bpr = DMFCBase->GetPlayerRecord(b); |
| 1128 | if (!apr) |
| 1129 | return true; |
| 1130 | if (!bpr) |
| 1131 | return false; |
| 1132 | if (apr->state == STATE_EMPTY) |
| 1133 | return true; |
| 1134 | if (bpr->state == STATE_EMPTY) |
| 1135 | return false; |
| 1136 | astat = (tPlayerStat *)apr->user_info; |
| 1137 | bstat = (tPlayerStat *)bpr->user_info; |
| 1138 | |
| 1139 | if ((apr->state == STATE_INGAME) && (bpr->state == STATE_INGAME)) { |
| 1140 | // both players were in the game |
| 1141 | ascore = (astat) ? astat->Score[DSTAT_LEVEL] : 0; |
| 1142 | bscore = (bstat) ? bstat->Score[DSTAT_LEVEL] : 0; |
| 1143 | return (ascore < bscore); |
| 1144 | } |
| 1145 | if ((apr->state == STATE_INGAME) && (bpr->state == STATE_DISCONNECTED)) { |
| 1146 | // apr gets priority since he was in the game on exit |
| 1147 | return false; |
| 1148 | } |
| 1149 | if ((apr->state == STATE_DISCONNECTED) && (bpr->state == STATE_INGAME)) { |
| 1150 | // bpr gets priority since he was in the game on exit |
| 1151 | return true; |
| 1152 | } |
| 1153 | // if we got here then both players were disconnected |
| 1154 | ascore = (astat) ? astat->Score[DSTAT_LEVEL] : 0; |
| 1155 | bscore = (bstat) ? bstat->Score[DSTAT_LEVEL] : 0; |
| 1156 | return (ascore < bscore); |
| 1157 | } |
| 1158 | |
| 1159 | void SortPlayerSlots(int *sorted_list, int count) { |
| 1160 | int tempsort[MAX_PLAYER_RECORDS]; |
| 1161 | int i, t, j; |
| 1162 | |
| 1163 | for (i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 1164 | tempsort[i] = i; |
| 1165 | } |
| 1166 | |
| 1167 | for (i = 1; i <= MAX_PLAYER_RECORDS - 1; i++) { |
| 1168 | t = tempsort[i]; |
| 1169 | // Shift elements down until |
| 1170 | // insertion point found. |
| 1171 | for (j = i - 1; j >= 0 && compare_slots(tempsort[j], t); j--) { |
| 1172 | tempsort[j + 1] = tempsort[j]; |
| 1173 | } |
| 1174 | // insert |
| 1175 | tempsort[j + 1] = t; |
| 1176 | } |
| 1177 | |
| 1178 | // copy the array over |
| 1179 | memcpy(sorted_list, tempsort, count * sizeof(int)); |
| 1180 | } |
| 1181 | |
| 1182 | void OnPLRInit(void) { |
| 1183 | monsterball_info_set = false; // for the next level |
| 1184 | |
| 1185 | SortPlayerSlots(SortedPlayers, MAX_PLAYER_RECORDS); |
| 1186 | |
| 1187 | // Now fill in the final structure of sorted names |
| 1188 | int TeamCount[DLLMAX_TEAMS]; |
| 1189 | player_record *pr; |
| 1190 | int team, i; |
| 1191 | |
| 1192 | for (i = 0; i < DLLMAX_TEAMS; i++) |
| 1193 | TeamCount[i] = 0; |
| 1194 | for (i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 1195 | int slot = SortedPlayers[i]; |
| 1196 | pr = DMFCBase->GetPlayerRecord(slot); |
| 1197 | if (pr->state != STATE_EMPTY) { |
| 1198 | |
| 1199 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 1200 | continue; // skip dedicated server |
| 1201 | |
| 1202 | team = (pr->state == STATE_INGAME) ? dPlayers[pr->pnum].team : pr->team; |
| 1203 | |
| 1204 | if (team >= NumOfTeams) |
| 1205 | team = 0; |
| 1206 | SortedPLRPlayers[team][TeamCount[team]] = slot; |
| 1207 | TeamCount[team]++; |
| 1208 | } |
| 1209 | } |
| 1210 | for (i = 0; i < DLLMAX_TEAMS; i++) { |
| 1211 | if (TeamCount[i] < MAX_PLAYER_RECORDS) |
| 1212 | SortedPLRPlayers[i][TeamCount[i]] = -1; |
| 1213 | } |
| 1214 | |
| 1215 | DMFCBase->OnPLRInit(); |
| 1216 | } |
| 1217 | |
| 1218 | void OnPLRInterval(void) { |
| 1219 | DMFCBase->OnPLRInterval(); |
| 1220 | |
| 1221 | int TeamCol = 35; |
| 1222 | int NameCol = 190; |
| 1223 | int PointCol = 280; |
| 1224 | int BlunderCol = 340; |
| 1225 | int KillsCol = 410; |
| 1226 | int DeathsCol = 450; |
| 1227 | int SuicidesCol = 490; |
| 1228 | int y = 40; |
| 1229 | int slot; |
| 1230 | player_record *pr; |
| 1231 | tPlayerStat *stat; |
| 1232 | |
| 1233 | DLLgrtext_SetFont((DMFCBase->GetGameFontTranslateArray())[SMALL_UI_FONT_INDEX]); |
| 1234 | int height = DLLgrfont_GetHeight((DMFCBase->GetGameFontTranslateArray())[SMALL_UI_FONT_INDEX]) + 1; |
| 1235 | |
| 1236 | // print out header |
| 1237 | DLLgrtext_SetColor(GR_RGB(255, 255, 150)); |
| 1238 | DLLgrtext_Printf(NameCol, y, TXT_PILOT); |
| 1239 | DLLgrtext_Printf(PointCol, y, TXT_POINTS); |
| 1240 | DLLgrtext_Printf(BlunderCol, y, TXT_BLUNDERS); |
| 1241 | DLLgrtext_Printf(KillsCol, y, TXT_KILLSSHORT); |
| 1242 | DLLgrtext_Printf(DeathsCol, y, TXT_DEATHSSHORT); |
| 1243 | DLLgrtext_Printf(SuicidesCol, y, TXT_SUICIDESSHORT); |
| 1244 | y += height; |
| 1245 | bool has_members; |
| 1246 | bool doing_connected = true; |
| 1247 | do_disconnected_folk: |
| 1248 | |
| 1249 | for (int team = 0; team < NUM_TEAMS; team++) { |
| 1250 | // process this team |
| 1251 | bool show_team_label; |
| 1252 | show_team_label = false; |
| 1253 | |
| 1254 | if (!doing_connected) { |
| 1255 | int temp_idx; |
| 1256 | temp_idx = 0; |
| 1257 | |
| 1258 | while (SortedPLRPlayers[team][temp_idx] != -1) { |
| 1259 | int pnum = DMFCBase->WasPlayerInGameAtLevelEnd(SortedPLRPlayers[team][temp_idx]); |
| 1260 | if (pnum == -1) { |
| 1261 | show_team_label = true; |
| 1262 | break; |
| 1263 | } |
| 1264 | temp_idx++; |
| 1265 | } |
| 1266 | } else { |
| 1267 | show_team_label = true; |
| 1268 | } |
| 1269 | |
| 1270 | if (show_team_label) { |
| 1271 | // is there anyone on this team? |
| 1272 | DLLgrtext_SetColor(DMFCBase->GetTeamColor(team)); |
| 1273 | DLLgrtext_Printf(TeamCol, y, TXT_HUDDISPLAY, DMFCBase->GetTeamString(team), TeamScores[team]); |
| 1274 | } |
| 1275 | has_members = false; |
| 1276 | |
| 1277 | for (int index = 0; index < MAX_PLAYER_RECORDS; index++) { |
| 1278 | // get the player num |
| 1279 | slot = SortedPLRPlayers[team][index]; |
| 1280 | if (slot == -1) // we are done with this team |
| 1281 | break; |
| 1282 | |
| 1283 | pr = DMFCBase->GetPlayerRecord(slot); |
| 1284 | if (pr && pr->state != STATE_EMPTY) { |
| 1285 | |
| 1286 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 1287 | continue; // skip dedicated server |
| 1288 | |
| 1289 | int pnum = DMFCBase->WasPlayerInGameAtLevelEnd(slot); |
| 1290 | |
| 1291 | if ((doing_connected && pnum == -1) || (!doing_connected && pnum != -1)) |
| 1292 | continue; // we're not handling them right now |
| 1293 | |
| 1294 | if (pnum != -1) { |
| 1295 | DLLgrtext_SetColor(DMFCBase->GetTeamColor(team)); |
| 1296 | } else { |
| 1297 | DLLgrtext_SetColor(GR_RGB(128, 128, 128)); |
| 1298 | } |
| 1299 | |
| 1300 | char tempbuffer[40]; |
| 1301 | strcpy(tempbuffer, pr->callsign); |
| 1302 | DMFCBase->ClipString(PointCol - NameCol - 10, tempbuffer, true); |
| 1303 | |
| 1304 | // valid player |
| 1305 | stat = (tPlayerStat *)pr->user_info; |
| 1306 | DLLgrtext_Printf(NameCol, y, "%s", tempbuffer); |
| 1307 | DLLgrtext_Printf(PointCol, y, "%d", (stat) ? stat->Score[DSTAT_LEVEL] : 0); |
| 1308 | DLLgrtext_Printf(BlunderCol, y, "%d", (stat) ? stat->BadScore[DSTAT_LEVEL] : 0); |
| 1309 | DLLgrtext_Printf(KillsCol, y, "%d", pr->dstats.kills[DSTAT_LEVEL]); |
| 1310 | DLLgrtext_Printf(DeathsCol, y, "%d", pr->dstats.deaths[DSTAT_LEVEL]); |
| 1311 | DLLgrtext_Printf(SuicidesCol, y, "%d", pr->dstats.suicides[DSTAT_LEVEL]); |
| 1312 | y += height; |
| 1313 | has_members = true; |
| 1314 | |
| 1315 | if (y >= 440) |
| 1316 | goto quick_exit; |
| 1317 | } |
| 1318 | } // end for |
| 1319 | // on to the next team |
| 1320 | |
| 1321 | if (!has_members) |
| 1322 | y += height; // on to the next line |
| 1323 | |
| 1324 | if (y >= 440) |
| 1325 | goto quick_exit; |
| 1326 | } // end for |
| 1327 | |
| 1328 | if (doing_connected) { |
| 1329 | doing_connected = false; |
| 1330 | goto do_disconnected_folk; |
| 1331 | } |
| 1332 | |
| 1333 | quick_exit:; |
| 1334 | } |
| 1335 | |
| 1336 | void OnPrintScores(int level) { |
| 1337 | char buffer[256]; |
| 1338 | char name[50]; |
| 1339 | size_t t; |
| 1340 | size_t pos[7]; |
| 1341 | size_t len[7]; |
| 1342 | |
| 1343 | for (int i = 0; i < NumOfTeams; i++) { |
| 1344 | snprintf(buffer, sizeof(buffer), "%s:%d\n", DMFCBase->GetTeamString(i), TeamScores[i]); |
| 1345 | DPrintf(buffer); |
| 1346 | } |
| 1347 | |
| 1348 | memset(buffer, ' ', 256); |
| 1349 | pos[0] = 0; |
| 1350 | t = len[0] = 20; // give ample room for pilot name |
| 1351 | pos[1] = pos[0] + t + 1; |
| 1352 | t = len[1] = strlen(TXT_POINTS); |
| 1353 | pos[2] = pos[1] + t + 1; |
| 1354 | t = len[2] = strlen(TXT_BLUNDERS); |
| 1355 | pos[3] = pos[1] + t + 1; |
| 1356 | t = len[3] = strlen(TXT_KILLS); |
| 1357 | pos[4] = pos[2] + t + 1; |
| 1358 | t = len[4] = strlen(TXT_DEATHS); |
| 1359 | pos[5] = pos[3] + t + 1; |
| 1360 | t = len[5] = strlen(TXT_SUICIDES); |
| 1361 | pos[6] = pos[4] + t + 1; |
| 1362 | t = len[6] = strlen(TXT_PING); |
| 1363 | |
| 1364 | memcpy(&buffer[pos[0]], TXT_PILOT, strlen(TXT_PILOT)); |
| 1365 | memcpy(&buffer[pos[1]], TXT_POINTS, len[1]); |
| 1366 | memcpy(&buffer[pos[2]], TXT_BLUNDERS, len[2]); |
| 1367 | memcpy(&buffer[pos[3]], TXT_KILLS, len[3]); |
| 1368 | memcpy(&buffer[pos[4]], TXT_DEATHS, len[4]); |
| 1369 | memcpy(&buffer[pos[5]], TXT_SUICIDES, len[5]); |
| 1370 | memcpy(&buffer[pos[6]], TXT_PING, len[6]); |
| 1371 | buffer[pos[6] + len[6] + 1] = '\n'; |
| 1372 | buffer[pos[6] + len[6] + 2] = '\0'; |
| 1373 | DPrintf(buffer); |
| 1374 | |
| 1375 | int slot; |
| 1376 | player_record *pr; |
| 1377 | int pcount; |
| 1378 | |
| 1379 | if (level < 0 || level >= MAX_PLAYER_RECORDS) |
| 1380 | pcount = MAX_PLAYER_RECORDS; |
| 1381 | else |
| 1382 | pcount = level; |
| 1383 | |
| 1384 | int sortedplayers[MAX_PLAYER_RECORDS]; |
| 1385 | DMFCBase->GetSortedPlayerSlots(sortedplayers, MAX_PLAYER_RECORDS); |
| 1386 | |
| 1387 | for (int i = 0; i < pcount; i++) { |
| 1388 | slot = sortedplayers[i]; |
| 1389 | pr = DMFCBase->GetPlayerRecord(slot); |
| 1390 | tPlayerStat *stat; |
| 1391 | if ((pr) && (pr->state != STATE_EMPTY)) { |
| 1392 | |
| 1393 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 1394 | continue; // skip dedicated server |
| 1395 | |
| 1396 | snprintf(name, sizeof(name), "%s%s:", (pr->state == STATE_DISCONNECTED) ? "*" : "", pr->callsign); |
| 1397 | name[19] = '\0'; |
| 1398 | |
| 1399 | stat = (tPlayerStat *)pr->user_info; |
| 1400 | |
| 1401 | memset(buffer, ' ', 256); |
| 1402 | t = strlen(name); |
| 1403 | memcpy(&buffer[pos[0]], name, (t < len[0]) ? t : len[0]); |
| 1404 | snprintf(name, sizeof(name), "%d", (stat) ? stat->Score[DSTAT_LEVEL] : 0); |
| 1405 | t = strlen(name); |
| 1406 | memcpy(&buffer[pos[1]], name, (t < len[1]) ? t : len[1]); |
| 1407 | snprintf(name, sizeof(name), "%d", (stat) ? stat->BadScore[DSTAT_LEVEL] : 0); |
| 1408 | t = strlen(name); |
| 1409 | memcpy(&buffer[pos[2]], name, (t < len[2]) ? t : len[2]); |
| 1410 | snprintf(name, sizeof(name), "%d", pr->dstats.kills[DSTAT_LEVEL]); |
| 1411 | t = strlen(name); |
| 1412 | memcpy(&buffer[pos[3]], name, (t < len[2]) ? t : len[3]); |
| 1413 | snprintf(name, sizeof(name), "%d", pr->dstats.deaths[DSTAT_LEVEL]); |
| 1414 | t = strlen(name); |
| 1415 | memcpy(&buffer[pos[4]], name, (t < len[3]) ? t : len[4]); |
| 1416 | snprintf(name, sizeof(name), "%d", pr->dstats.suicides[DSTAT_LEVEL]); |
| 1417 | t = strlen(name); |
| 1418 | memcpy(&buffer[pos[5]], name, (t < len[4]) ? t : len[5]); |
| 1419 | |
| 1420 | if (pr->state == STATE_INGAME) |
| 1421 | snprintf(name, sizeof(name), "%.0f", (DMFCBase->GetNetPlayers())[pr->pnum].ping_time * 1000.0f); |
| 1422 | else |
| 1423 | strcpy(name, "---"); |
| 1424 | t = strlen(name); |
| 1425 | memcpy(&buffer[pos[6]], name, (t < len[6]) ? t : len[6]); |
| 1426 | buffer[pos[6] + len[6] + 1] = '\n'; |
| 1427 | buffer[pos[6] + len[6] + 2] = '\0'; |
| 1428 | DPrintf(buffer); |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | void SaveStatsToFile(char *filename) { |
| 1434 | CFILE *file; |
| 1435 | DLLOpenCFILE(&file, filename, "wt"); |
| 1436 | if (!file) { |
| 1437 | DLLmprintf(0, "Unable to open output file\n"); |
| 1438 | return; |
| 1439 | } |
| 1440 | |
| 1441 | // write out game stats |
| 1442 | #define BUFSIZE 150 |
| 1443 | char buffer[BUFSIZE]; |
| 1444 | char tempbuffer[25]; |
| 1445 | int sortedslots[MAX_PLAYER_RECORDS]; |
| 1446 | player_record *pr, *dpr; |
| 1447 | tPInfoStat stat; |
| 1448 | int count, p; |
| 1449 | tPlayerStat *st; |
| 1450 | |
| 1451 | // sort the stats |
| 1452 | DMFCBase->GetSortedPlayerSlots(sortedslots, MAX_PLAYER_RECORDS); |
| 1453 | SortTeams(); |
| 1454 | count = 1; |
| 1455 | |
| 1456 | snprintf(buffer, sizeof(buffer), TXT_SAVESTATSA, (DMFCBase->GetNetgameInfo())->name, |
| 1457 | (DMFCBase->GetCurrentMission())->cur_level); |
| 1458 | DLLcf_WriteString(file, buffer); |
| 1459 | |
| 1460 | for (p = 0; p < NumOfTeams; p++) { |
| 1461 | int team_i = SortedTeams[p]; |
| 1462 | memset(buffer, ' ', BUFSIZE); |
| 1463 | snprintf(tempbuffer, sizeof(tempbuffer), TXT_SAVESTATSTEAM, DMFCBase->GetTeamString(team_i)); |
| 1464 | memcpy(&buffer[0], tempbuffer, strlen(tempbuffer)); |
| 1465 | snprintf(tempbuffer, sizeof(tempbuffer), "[%d]", TeamScores[team_i]); |
| 1466 | memcpy(&buffer[20], tempbuffer, strlen(tempbuffer)); |
| 1467 | buffer[20 + strlen(tempbuffer)] = '\0'; |
| 1468 | DLLcf_WriteString(file, buffer); |
| 1469 | } |
| 1470 | |
| 1471 | // Write team members |
| 1472 | DLLcf_WriteString(file, ""); // blank line |
| 1473 | for (int t = 0; t < NumOfTeams; t++) { |
| 1474 | int team_i = SortedTeams[t]; |
| 1475 | |
| 1476 | snprintf(buffer, sizeof(buffer), TXT_SAVESTATSTEAM, DMFCBase->GetTeamString(team_i)); |
| 1477 | strncat(buffer, ":", sizeof(buffer) - strlen(buffer) - 1); |
| 1478 | DLLcf_WriteString(file, buffer); |
| 1479 | |
| 1480 | for (p = 0; p < MAX_PLAYER_RECORDS; p++) { |
| 1481 | pr = DMFCBase->GetPlayerRecord(sortedslots[p]); |
| 1482 | if (pr && pr->state != STATE_EMPTY) { |
| 1483 | |
| 1484 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 1485 | continue; // skip dedicated server |
| 1486 | |
| 1487 | if (pr->team == team_i) { // Check if current team |
| 1488 | snprintf(buffer, sizeof(buffer), " %s", pr->callsign); |
| 1489 | DLLcf_WriteString(file, buffer); |
| 1490 | } |
| 1491 | } |
| 1492 | } |
| 1493 | } |
| 1494 | DLLcf_WriteString(file, ""); // blank line |
| 1495 | |
| 1496 | snprintf(buffer, sizeof(buffer), "%s", TXT_SAVESTATSB); |
| 1497 | DLLcf_WriteString(file, buffer); |
| 1498 | |
| 1499 | snprintf(buffer, sizeof(buffer), "%s", TXT_SAVESTATSC); |
| 1500 | DLLcf_WriteString(file, buffer); |
| 1501 | strcpy(buffer, "--------------------------------------------------------------------------------------"); |
| 1502 | DLLcf_WriteString(file, buffer); |
| 1503 | |
| 1504 | for (p = 0; p < MAX_PLAYER_RECORDS; p++) { |
| 1505 | pr = DMFCBase->GetPlayerRecord(sortedslots[p]); |
| 1506 | if (pr && pr->state != STATE_EMPTY) { |
| 1507 | |
| 1508 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 1509 | continue; // skip dedicated server |
| 1510 | |
| 1511 | st = (tPlayerStat *)pr->user_info; |
| 1512 | memset(buffer, ' ', BUFSIZE); |
| 1513 | |
| 1514 | snprintf(tempbuffer, sizeof(tempbuffer), "%d)", count); |
| 1515 | memcpy(&buffer[0], tempbuffer, strlen(tempbuffer)); |
| 1516 | |
| 1517 | snprintf(tempbuffer, sizeof(tempbuffer), "%s%s", (pr->state == STATE_INGAME) ? "" : "*", pr->callsign); |
| 1518 | memcpy(&buffer[5], tempbuffer, strlen(tempbuffer)); |
| 1519 | |
| 1520 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", (st) ? st->Score[DSTAT_LEVEL] : 0, |
| 1521 | (st) ? st->Score[DSTAT_OVERALL] : 0); |
| 1522 | memcpy(&buffer[34], tempbuffer, strlen(tempbuffer)); |
| 1523 | |
| 1524 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", (st) ? st->BadScore[DSTAT_LEVEL] : 0, |
| 1525 | (st) ? st->BadScore[DSTAT_OVERALL] : 0); |
| 1526 | memcpy(&buffer[42], tempbuffer, strlen(tempbuffer)); |
| 1527 | |
| 1528 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", pr->dstats.kills[DSTAT_LEVEL], |
| 1529 | pr->dstats.kills[DSTAT_OVERALL]); |
| 1530 | memcpy(&buffer[55], tempbuffer, strlen(tempbuffer)); |
| 1531 | |
| 1532 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", pr->dstats.deaths[DSTAT_LEVEL], |
| 1533 | pr->dstats.deaths[DSTAT_OVERALL]); |
| 1534 | memcpy(&buffer[67], tempbuffer, strlen(tempbuffer)); |
| 1535 | |
| 1536 | snprintf(tempbuffer, sizeof(tempbuffer), "%d[%d]", pr->dstats.suicides[DSTAT_LEVEL], |
| 1537 | pr->dstats.suicides[DSTAT_OVERALL]); |
| 1538 | memcpy(&buffer[78], tempbuffer, strlen(tempbuffer)); |
| 1539 | |
| 1540 | size_t pos = 78 + strlen(tempbuffer) + 1; |
| 1541 | if (pos < BUFSIZE) |
| 1542 | buffer[pos] = '\0'; |
| 1543 | |
| 1544 | buffer[BUFSIZE - 1] = '\0'; |
| 1545 | DLLcf_WriteString(file, buffer); |
| 1546 | count++; |
| 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | DLLcf_WriteString(file, TXT_SAVESTATSD); |
| 1551 | |
| 1552 | count = 1; |
| 1553 | for (p = 0; p < MAX_PLAYER_RECORDS; p++) { |
| 1554 | pr = DMFCBase->GetPlayerRecord(p); |
| 1555 | if (pr && pr->state != STATE_EMPTY) { |
| 1556 | |
| 1557 | if (DMFCBase->IsPlayerDedicatedServer(pr)) |
| 1558 | continue; // skip dedicated server |
| 1559 | |
| 1560 | // Write out header |
| 1561 | snprintf(buffer, sizeof(buffer), "%d) %s%s (%s)", count, (pr->state == STATE_INGAME) ? "" : "*", pr->callsign, |
| 1562 | DMFCBase->GetTeamString(pr->team)); |
| 1563 | DLLcf_WriteString(file, buffer); |
| 1564 | size_t length = strlen(buffer); |
| 1565 | memset(buffer, '=', length); |
| 1566 | buffer[length] = '\0'; |
| 1567 | DLLcf_WriteString(file, buffer); |
| 1568 | |
| 1569 | // time in game |
| 1570 | snprintf(buffer, sizeof(buffer), TXT_TIMEINGAME, DMFCBase->GetTimeString(DMFCBase->GetTimeInGame(p))); |
| 1571 | DLLcf_WriteString(file, buffer); |
| 1572 | |
| 1573 | if (DMFCBase->FindPInfoStatFirst(p, &stat)) { |
| 1574 | snprintf(buffer, sizeof(buffer), "%s", TXT_SAVESTATSE); |
| 1575 | DLLcf_WriteString(file, buffer); |
| 1576 | |
| 1577 | if (stat.slot != p) { |
| 1578 | memset(buffer, ' ', BUFSIZE); |
| 1579 | dpr = DMFCBase->GetPlayerRecord(stat.slot); |
| 1580 | |
| 1581 | if (dpr) { |
| 1582 | strncpy(tempbuffer, DMFCBase->GetTeamString(dpr->team), sizeof(tempbuffer)); |
| 1583 | memcpy(buffer, tempbuffer, strlen(tempbuffer)); |
| 1584 | |
| 1585 | strcpy(tempbuffer, dpr->callsign); |
| 1586 | memcpy(&buffer[6], tempbuffer, strlen(tempbuffer)); |
| 1587 | |
| 1588 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.kills); |
| 1589 | memcpy(&buffer[36], tempbuffer, strlen(tempbuffer)); |
| 1590 | |
| 1591 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.deaths); |
| 1592 | memcpy(&buffer[46], tempbuffer, strlen(tempbuffer)); |
| 1593 | |
| 1594 | size_t pos = 46 + strlen(tempbuffer) + 1; |
| 1595 | if (pos < BUFSIZE) |
| 1596 | buffer[pos] = '\0'; |
| 1597 | |
| 1598 | buffer[BUFSIZE - 1] = '\0'; |
| 1599 | DLLcf_WriteString(file, buffer); |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | while (DMFCBase->FindPInfoStatNext(&stat)) { |
| 1604 | if (stat.slot != p) { |
| 1605 | memset(buffer, ' ', BUFSIZE); |
| 1606 | dpr = DMFCBase->GetPlayerRecord(stat.slot); |
| 1607 | if (dpr) { |
| 1608 | strcpy(tempbuffer, dpr->callsign); |
| 1609 | memcpy(buffer, tempbuffer, strlen(tempbuffer)); |
| 1610 | |
| 1611 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.kills); |
| 1612 | memcpy(&buffer[30], tempbuffer, strlen(tempbuffer)); |
| 1613 | |
| 1614 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.deaths); |
| 1615 | memcpy(&buffer[40], tempbuffer, strlen(tempbuffer)); |
| 1616 | |
| 1617 | size_t pos = 40 + strlen(tempbuffer) + 1; |
| 1618 | if (pos < BUFSIZE) |
| 1619 | buffer[pos] = '\0'; |
| 1620 | |
| 1621 | buffer[BUFSIZE - 1] = '\0'; |
| 1622 | DLLcf_WriteString(file, buffer); |
| 1623 | } |
| 1624 | } |
| 1625 | } |
| 1626 | } |
| 1627 | DMFCBase->FindPInfoStatClose(); |
| 1628 | DLLcf_WriteString(file, ""); // skip a line |
| 1629 | count++; |
| 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | // done writing stats |
| 1634 | DLLcfclose(file); |
| 1635 | DLLAddHUDMessage(TXT_STATSSAVED); |
| 1636 | } |
| 1637 | |
| 1638 | #define ROOTFILENAME "MonsterBall" |
| 1639 | void OnSaveStatsToFile(void) { |
| 1640 | char filename[256]; |
| 1641 | DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); |
| 1642 | SaveStatsToFile(filename); |
| 1643 | } |
| 1644 | |
| 1645 | void OnLevelEndSaveStatsToFile(void) { |
| 1646 | char filename[256]; |
| 1647 | DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); |
| 1648 | SaveStatsToFile(filename); |
| 1649 | } |
| 1650 | |
| 1651 | void OnDisconnectSaveStatsToFile(void) { |
| 1652 | char filename[256]; |
| 1653 | DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); |
| 1654 | SaveStatsToFile(filename); |
| 1655 | } |
| 1656 | |
| 1657 | ////////////////////////////////////////////// |
| 1658 | // NON-DMFC Functions |
| 1659 | ////////////////////////////////////////////// |
| 1660 | void DisplayHUDScores(struct tHUDItem *hitem) { |
| 1661 | if (display_my_welcome) { |
| 1662 | DisplayWelcomeMessage(DMFCBase->GetPlayerNum()); |
| 1663 | display_my_welcome = false; |
| 1664 | } |
| 1665 | |
| 1666 | if (!monsterball_info_set || !players_sorted || |
| 1667 | DisplayScoreScreen) // interval hasn't been called yet or we are display the stats |
| 1668 | return; |
| 1669 | |
| 1670 | int height = DLLgrfont_GetHeight((DMFCBase->GetGameFontTranslateArray())[HUD_FONT_INDEX]) + 3; |
| 1671 | int y, x, team, p; |
| 1672 | |
| 1673 | uint8_t alpha = DMFCBase->ConvertHUDAlpha((uint8_t)255); |
| 1674 | |
| 1675 | if (!ValidateOwner(&p, NULL)) { |
| 1676 | p = -1; |
| 1677 | } |
| 1678 | |
| 1679 | y = (DMFCBase->GetGameWindowH() / 2) - ((height * 2) / 2); |
| 1680 | x = 510; |
| 1681 | |
| 1682 | team = DMFCBase->GetMyTeam(); |
| 1683 | DLLRenderHUDText(DMFCBase->GetTeamColor(team), 255, 0, x, 0, TXT_SAVESTATSTEAM, DMFCBase->GetTeamString(team)); |
| 1684 | |
| 1685 | int powerteam = -1; |
| 1686 | if (p != -1) |
| 1687 | powerteam = DMFCBase->GetPlayerTeam(p); |
| 1688 | |
| 1689 | int myteam = DMFCBase->GetMyTeam(); |
| 1690 | int team_count; |
| 1691 | |
| 1692 | // determine coordinates to use here |
| 1693 | // we'll use a virtual width of 85 pixels on a 640x480 screen |
| 1694 | // so first determine the new width |
| 1695 | int name_width = 100.0f * DMFCBase->GetHudAspectX(); |
| 1696 | int score_width = DLLgrtext_GetTextLineWidth("888"); |
| 1697 | int name_x = DMFCBase->GetGameWindowW() - name_width - score_width - 10; |
| 1698 | int score_x = DMFCBase->GetGameWindowW() - score_width - 5; |
| 1699 | int icon_size = height - 3; |
| 1700 | int icon_x = name_x - icon_size - 3; |
| 1701 | DLLgrtext_SetAlpha(alpha); |
| 1702 | char name[256]; |
| 1703 | |
| 1704 | for (int i = 0; i < NumOfTeams; i++) { |
| 1705 | team = SortedTeams[i]; |
| 1706 | |
| 1707 | if ((WhoJustScored != team) || (DisplayScoreBlink)) { |
| 1708 | if (team == myteam && Highlight_bmp > BAD_BITMAP_HANDLE) { |
| 1709 | // draw the highlite bar in the background |
| 1710 | DLLrend_SetAlphaValue(alpha * 0.50f); |
| 1711 | DLLrend_SetZBufferState(0); |
| 1712 | DLLrend_SetTextureType(TT_LINEAR); |
| 1713 | DLLrend_SetLighting(LS_NONE); |
| 1714 | DLLrend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 1715 | DLLrend_DrawScaledBitmap(name_x - 2, y - 2, score_x + score_width + 2, y + height - 1, Highlight_bmp, 0, 0, 1, |
| 1716 | 1, 1.0, -1, NULL); |
| 1717 | DLLrend_SetZBufferState(1); |
| 1718 | } |
| 1719 | |
| 1720 | team_count = 0; |
| 1721 | for (int q = 0; q < DLLMAX_PLAYERS; q++) { |
| 1722 | if (DMFCBase->CheckPlayerNum(q) && dPlayers[q].team == team && !DMFCBase->IsPlayerDedicatedServer(q)) |
| 1723 | team_count++; |
| 1724 | } |
| 1725 | |
| 1726 | DLLgrtext_SetColor(DMFCBase->GetTeamColor(team)); |
| 1727 | |
| 1728 | snprintf(name, sizeof(name), TXT_HUDSCORE, team_count, DMFCBase->GetTeamString(team)); |
| 1729 | DMFCBase->ClipString(name_width, name, true); |
| 1730 | |
| 1731 | DLLgrtext_Printf(name_x, y, name); |
| 1732 | DLLgrtext_Printf(score_x, y, "[%d]", TeamScores[team]); |
| 1733 | } |
| 1734 | y += height; |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | void GetLastHitInfo(uint8_t *data) { |
| 1739 | int size = 0; |
| 1740 | |
| 1741 | LastHitPnum = (int8_t)MultiGetByte(data, &size); |
| 1742 | } |
| 1743 | void SendLastHitInfo(void) { |
| 1744 | int size = 0; |
| 1745 | uint8_t data[MAX_GAME_DATA_SIZE]; |
| 1746 | |
| 1747 | DMFCBase->StartPacket(data, SPID_HITINFO, &size); |
| 1748 | |
| 1749 | MultiAddByte(LastHitPnum, data, &size); |
| 1750 | |
| 1751 | DMFCBase->SendPacket(data, size, SP_ALL); |
| 1752 | } |
| 1753 | |
| 1754 | void GetGameStartPacket(uint8_t *data) { |
| 1755 | int i, count = 0; |
| 1756 | |
| 1757 | // team scores |
| 1758 | for (i = 0; i < DLLMAX_TEAMS; i++) { |
| 1759 | TeamScores[i] = MultiGetInt(data, &count); |
| 1760 | } |
| 1761 | |
| 1762 | // who has the Monsterball |
| 1763 | int8_t temp; |
| 1764 | temp = (int8_t)MultiGetByte(data, &count); |
| 1765 | if (temp == -1) { |
| 1766 | Monsterball_info.owner_handle = OBJECT_HANDLE_NONE; |
| 1767 | } else { |
| 1768 | if (DMFCBase->CheckPlayerNum(temp)) |
| 1769 | Monsterball_info.owner_handle = dObjects[dPlayers[temp].objnum].handle; |
| 1770 | else |
| 1771 | Monsterball_info.owner_handle = OBJECT_HANDLE_NONE; |
| 1772 | } |
| 1773 | |
| 1774 | monsterball_info_set = true; |
| 1775 | |
| 1776 | temp = (int8_t)MultiGetByte(data, &count); |
| 1777 | NumOfTeams = temp; |
| 1778 | |
| 1779 | // we need to find the objnum of the Monsterball...its there somewhere |
| 1780 | DLLmprintf(0, "Looking for Monsterball in level\n"); |
| 1781 | int objnum = -1; |
| 1782 | |
| 1783 | for (i = 0; i < MAX_OBJECTS; i++) { |
| 1784 | if ((dObjects[i].type == OBJ_ROBOT) && (dObjects[i].id == Monsterball_info.id)) { |
| 1785 | // here it is |
| 1786 | objnum = i; |
| 1787 | break; |
| 1788 | } |
| 1789 | } |
| 1790 | DLLmprintf(0, "Monsterball %s\n", (objnum == -1) ? "Not Found" : "Found"); |
| 1791 | if (objnum == -1) { |
| 1792 | FatalError("Couldn't Find Monsterball when it should be there"); |
| 1793 | } |
| 1794 | |
| 1795 | Monsterball_info.objhandle = dObjects[objnum].handle; |
| 1796 | } |
| 1797 | |
| 1798 | void SendGameStartPacket(int pnum) { |
| 1799 | int i, count = 0; |
| 1800 | uint8_t data[MAX_GAME_DATA_SIZE]; |
| 1801 | |
| 1802 | DMFCBase->StartPacket(data, SPID_NEWPLAYER, &count); |
| 1803 | |
| 1804 | // add the team scores |
| 1805 | for (i = 0; i < DLLMAX_TEAMS; i++) { |
| 1806 | MultiAddInt(TeamScores[i], data, &count); |
| 1807 | } |
| 1808 | |
| 1809 | int8_t temp; |
| 1810 | int p; |
| 1811 | |
| 1812 | // who has the Monsterball if anyone |
| 1813 | if (ValidateOwner(&p, NULL)) { |
| 1814 | temp = p; |
| 1815 | } else { |
| 1816 | temp = -1; |
| 1817 | } |
| 1818 | MultiAddByte(temp, data, &count); |
| 1819 | |
| 1820 | // number of teams |
| 1821 | temp = NumOfTeams; |
| 1822 | MultiAddByte(temp, data, &count); |
| 1823 | |
| 1824 | // we're done |
| 1825 | DLLmprintf(0, "Sending Game State to %s\n", dPlayers[pnum].callsign); |
| 1826 | DMFCBase->SendPacket(data, count, pnum); |
| 1827 | } |
| 1828 | |
| 1829 | bool GetMonsterballInfo(int id) { |
| 1830 | if (id == -1) |
| 1831 | return false; |
| 1832 | |
| 1833 | Monsterball_info.id = id; |
| 1834 | |
| 1835 | // find the room with the RF_SPECIAL1 |
| 1836 | for (int i = 0; i <= DMFCBase->GetHighestRoomIndex(); i++) { |
| 1837 | if (dRooms[i].flags & RF_SPECIAL1) { |
| 1838 | // here's the Monsterball! |
| 1839 | Monsterball_info.room = i; |
| 1840 | DLLComputeRoomCenter(&Monsterball_info.pos, &dRooms[i]); |
| 1841 | return true; |
| 1842 | } |
| 1843 | } |
| 1844 | return false; |
| 1845 | } |
| 1846 | |
| 1847 | #define compGT(a, b) (a < b) |
| 1848 | // insert sort |
| 1849 | void SortTeams(void) { |
| 1850 | int t; |
| 1851 | int i, j; |
| 1852 | |
| 1853 | // copy scores into scoreinfo array |
| 1854 | for (i = 0; i < DLLMAX_TEAMS; i++) { |
| 1855 | SortedTeams[i] = i; |
| 1856 | } |
| 1857 | |
| 1858 | for (i = 1; i <= DLLMAX_TEAMS - 1; i++) { |
| 1859 | t = SortedTeams[i]; |
| 1860 | |
| 1861 | // Shift elements down until |
| 1862 | // insertion point found. |
| 1863 | for (j = i - 1; j >= 0 && compGT(TeamScores[SortedTeams[j]], TeamScores[t]); j--) { |
| 1864 | SortedTeams[j + 1] = SortedTeams[j]; |
| 1865 | } |
| 1866 | |
| 1867 | // insert |
| 1868 | SortedTeams[j + 1] = t; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | void DisplayWelcomeMessage(int player_num) { |
| 1873 | char name_buffer[64]; |
| 1874 | strcpy(name_buffer, (DMFCBase->GetPlayers())[player_num].callsign); |
| 1875 | |
| 1876 | if (player_num == DMFCBase->GetPlayerNum()) { |
| 1877 | int team = DMFCBase->GetMyTeam(); |
| 1878 | if (team == -1) |
| 1879 | return; |
| 1880 | |
| 1881 | DLLAddHUDMessage(TXT_WELCOME, name_buffer); |
| 1882 | DLLAddColoredHUDMessage(DMFCBase->GetTeamColor(team), TXT_ONTEAM, DMFCBase->GetTeamString(team)); |
| 1883 | } else { |
| 1884 | int team = dPlayers[player_num].team; |
| 1885 | if (team == -1) |
| 1886 | return; |
| 1887 | |
| 1888 | DLLAddColoredHUDMessage(DMFCBase->GetTeamColor(team), TXT_JOINED, name_buffer, DMFCBase->GetTeamString(team)); |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | void OnTimerScore(void) { DisplayScoreBlink = !DisplayScoreBlink; } |
| 1893 | void OnTimerScoreKill(void) { |
| 1894 | DisplayScoreBlink = true; |
| 1895 | WhoJustScored = WhoJustScoredTimer = -1; |
| 1896 | } |
| 1897 | |
| 1898 | // ------------------------------------------------------------------------- |
| 1899 | |
| 1900 | void HandleMonsterballCollideWithObject(object *ball, object *player, vector *point, vector *normal) { |
| 1901 | static int sound = -1; |
| 1902 | if (sound == -1) |
| 1903 | sound = DLLFindSoundName(IGNORE_TABLE(MONSTERBALL_SND_HIT)); |
| 1904 | if (sound != -1) |
| 1905 | DLLPlay3dSound(sound, ball, MAX_GAME_VOLUME / 3, 0); |
| 1906 | |
| 1907 | // bump_object(ball,&player->mtype.phys_info.rotvel,&player->mtype.phys_info.velocity, |
| 1908 | // &player->pos, &player->orient, player->mtype.phys_info.mass, player->size,point,normal,1.0f,1.0f); |
| 1909 | } |
| 1910 | |
| 1911 | void HandleMonsterballCollideWithWeapon(object *ball, weapon_collide_info *winfo, vector *point, vector *normal) { |
| 1912 | static int sound = -1; |
| 1913 | if (sound == -1) |
| 1914 | sound = DLLFindSoundName(IGNORE_TABLE(MONSTERBALL_SND_HIT)); |
| 1915 | if (sound != -1) |
| 1916 | DLLPlay3dSound(sound, ball, 0, 0); // FIXME: volume was set to 0 here, is that right? |
| 1917 | |
| 1918 | bump_object(ball, &winfo->rotvel, &winfo->velocity, &winfo->pos, &winfo->orient, winfo->mass, winfo->size, point, |
| 1919 | normal, -0.3f, 5.0f); |
| 1920 | } |
| 1921 | |
| 1922 | void bump_object(object *object0, vector *rotvel, vector *velocity, vector *pos, matrix *orient, float mass, float size, |
| 1923 | vector *collision_point, vector *collision_normal, float rot_scalar, float vel_scalar) { |
| 1924 | object *t = NULL; |
| 1925 | object *other = NULL; |
| 1926 | |
| 1927 | ASSERT(std::isfinite(rotvel->x)); |
| 1928 | ASSERT(std::isfinite(rotvel->y)); |
| 1929 | ASSERT(std::isfinite(rotvel->z)); |
| 1930 | ASSERT(std::isfinite(object0->mtype.phys_info.rotvel.x)); |
| 1931 | ASSERT(std::isfinite(object0->mtype.phys_info.rotvel.y)); |
| 1932 | ASSERT(std::isfinite(object0->mtype.phys_info.rotvel.z)); |
| 1933 | ASSERT(std::isfinite(velocity->x)); |
| 1934 | ASSERT(std::isfinite(velocity->y)); |
| 1935 | ASSERT(std::isfinite(velocity->z)); |
| 1936 | ASSERT(std::isfinite(object0->mtype.phys_info.velocity.x)); |
| 1937 | ASSERT(std::isfinite(object0->mtype.phys_info.velocity.y)); |
| 1938 | ASSERT(std::isfinite(object0->mtype.phys_info.velocity.z)); |
| 1939 | |
| 1940 | vector r1 = *collision_point - object0->pos; |
| 1941 | vector r2 = *collision_point - (*pos); |
| 1942 | vector w1; |
| 1943 | vector w2; |
| 1944 | vector n1; |
| 1945 | vector n2; |
| 1946 | float temp1; |
| 1947 | float temp2; |
| 1948 | |
| 1949 | float j; |
| 1950 | |
| 1951 | matrix o_t1 = object0->orient; |
| 1952 | matrix o_t2 = *orient; |
| 1953 | |
| 1954 | DLLvm_TransposeMatrix(&o_t1); |
| 1955 | DLLvm_TransposeMatrix(&o_t2); |
| 1956 | |
| 1957 | vector cmp1 = object0->mtype.phys_info.rotvel * o_t1; |
| 1958 | vector cmp2 = (*rotvel) * o_t2; |
| 1959 | |
| 1960 | DLLConvertEulerToAxisAmount(&cmp1, &n1, &temp1); |
| 1961 | DLLConvertEulerToAxisAmount(&cmp2, &n2, &temp2); |
| 1962 | |
| 1963 | n1 *= temp1; |
| 1964 | n2 *= temp2; |
| 1965 | |
| 1966 | if (temp1 != 0.0f) { |
| 1967 | DLLvm_CrossProduct(&w1, &n1, &r1); |
| 1968 | } else { |
| 1969 | w1.x = 0; |
| 1970 | w1.y = 0; |
| 1971 | w1.z = 0; |
| 1972 | } |
| 1973 | |
| 1974 | if (temp2 != 0.0f) { |
| 1975 | DLLvm_CrossProduct(&w2, &n2, &r2); |
| 1976 | } else { |
| 1977 | w2.x = 0; |
| 1978 | w2.y = 0; |
| 1979 | w2.z = 0; |
| 1980 | } |
| 1981 | |
| 1982 | vector p1 = object0->mtype.phys_info.velocity + w1; |
| 1983 | vector p2 = (*velocity) + w2; |
| 1984 | float v_rel; |
| 1985 | |
| 1986 | float m1 = object0->mtype.phys_info.mass; |
| 1987 | float m2 = mass; |
| 1988 | |
| 1989 | ASSERT(m1 != 0.0f && m2 != 0.0f); |
| 1990 | |
| 1991 | v_rel = *collision_normal * (p1 - p2); |
| 1992 | |
| 1993 | float e; |
| 1994 | e = vel_scalar; |
| 1995 | |
| 1996 | vector c1; |
| 1997 | vector c2; |
| 1998 | vector cc1; |
| 1999 | vector cc2; |
| 2000 | float cv1; |
| 2001 | float cv2; |
| 2002 | |
| 2003 | float i1 = (2.0f / 5.0f) * m1 * object0->size * object0->size; |
| 2004 | float i2 = (2.0f / 5.0f) * m2 * size; |
| 2005 | |
| 2006 | if (i1 < .0000001) |
| 2007 | i1 = .0000001f; |
| 2008 | if (i2 < .0000001) |
| 2009 | i2 = .0000001f; |
| 2010 | |
| 2011 | DLLvm_CrossProduct(&c1, &r1, collision_normal); |
| 2012 | DLLvm_CrossProduct(&c2, &r2, collision_normal); |
| 2013 | |
| 2014 | c1 = c1 / i1; |
| 2015 | c2 = c2 / i2; |
| 2016 | |
| 2017 | DLLvm_CrossProduct(&cc1, &c1, &r1); |
| 2018 | DLLvm_CrossProduct(&cc2, &c2, &r2); |
| 2019 | |
| 2020 | cv1 = (*collision_normal) * c1; |
| 2021 | cv2 = (*collision_normal) * c2; |
| 2022 | |
| 2023 | j = (-(1.0f + e)) * v_rel; |
| 2024 | j /= (1 / m1 + 1 / m2 + cv1 + cv2); |
| 2025 | |
| 2026 | // apply the force to the player |
| 2027 | vector new_vel; |
| 2028 | new_vel = ((j * (*collision_normal)) / m1); |
| 2029 | |
| 2030 | // make sure the velocity falls within a valid range |
| 2031 | float mag = DLLvm_GetMagnitudeFast(&new_vel); |
| 2032 | |
| 2033 | new_vel /= mag; |
| 2034 | |
| 2035 | mag = std::clamp(mag, 10.0f, 20.0f); |
| 2036 | |
| 2037 | new_vel *= mag; |
| 2038 | |
| 2039 | object0->mtype.phys_info.velocity += new_vel; |
| 2040 | |
| 2041 | vector jcn = j * (*collision_normal); |
| 2042 | |
| 2043 | DLLvm_CrossProduct(&c1, &r1, &jcn); |
| 2044 | |
| 2045 | n1 = (c1) / i1; |
| 2046 | |
| 2047 | temp1 = DLLvm_NormalizeVector(&n1); |
| 2048 | |
| 2049 | vector txx1; |
| 2050 | DLLConvertAxisAmountToEuler(&n1, &temp1, &txx1); |
| 2051 | |
| 2052 | float rotscale1; |
| 2053 | rotscale1 = rot_scalar; |
| 2054 | |
| 2055 | // change the player's rotational velocity |
| 2056 | object0->mtype.phys_info.rotvel += (txx1 * object0->orient) * rotscale1; |
| 2057 | |
| 2058 | ASSERT(std::isfinite(object0->mtype.phys_info.rotvel.x)); |
| 2059 | ASSERT(std::isfinite(object0->mtype.phys_info.rotvel.y)); |
| 2060 | ASSERT(std::isfinite(object0->mtype.phys_info.rotvel.z)); |
| 2061 | ASSERT(std::isfinite(object0->mtype.phys_info.velocity.x)); |
| 2062 | ASSERT(std::isfinite(object0->mtype.phys_info.velocity.y)); |
| 2063 | ASSERT(std::isfinite(object0->mtype.phys_info.velocity.z)); |
| 2064 | } |
| 2065 | |
| 2066 | bool ValidateOwner(int *pnum, object **obj) { |
| 2067 | if (Monsterball_info.owner_handle == OBJECT_HANDLE_NONE) |
| 2068 | return false; |
| 2069 | |
| 2070 | object *owner; |
| 2071 | if (!DLLObjGet(Monsterball_info.owner_handle, &owner)) { |
| 2072 | // the object no longer exists |
| 2073 | Monsterball_info.owner_handle = OBJECT_HANDLE_NONE; |
| 2074 | return false; |
| 2075 | } |
| 2076 | |
| 2077 | if (owner->type != OBJ_PLAYER || (dPlayers[owner->id].flags & (PLAYER_FLAGS_DYING | PLAYER_FLAGS_DEAD))) { |
| 2078 | // the owner isn't a player playing |
| 2079 | Monsterball_info.owner_handle = OBJECT_HANDLE_NONE; |
| 2080 | return false; |
| 2081 | } |
| 2082 | |
| 2083 | if (pnum) |
| 2084 | *pnum = owner->id; |
| 2085 | if (obj) |
| 2086 | *obj = owner; |
| 2087 | return true; |
| 2088 | } |
| 2089 | |
| 2090 | void DoMonsterballScoreEffect(void) { |
| 2091 | object *Monsterball; |
| 2092 | if (!DLLObjGet(Monsterball_info.objhandle, &Monsterball)) |
| 2093 | return; |
| 2094 | |
| 2095 | vector start_pos, end_pos; |
| 2096 | int start_room, end_room; |
| 2097 | bool doing_start = false; |
| 2098 | |
| 2099 | vector m_pos, i_pos; |
| 2100 | int m_room, i_room; |
| 2101 | |
| 2102 | m_pos = Monsterball->pos; |
| 2103 | m_room = Monsterball->roomnum; |
| 2104 | i_pos = Monsterball_info.pos; |
| 2105 | i_room = Monsterball_info.room; |
| 2106 | |
| 2107 | ////////////////////////////////////// |
| 2108 | float lifetime = 4.0f; |
| 2109 | float thickness = 17.5f; |
| 2110 | float slidetime = 0.3f; |
| 2111 | uint16_t color = GR_RGB16(30, 255, 30); |
| 2112 | int numtiles = 1; |
| 2113 | bool autotile = true; |
| 2114 | int sat_count = 2; |
| 2115 | int texture_id = DLLFindTextureName("ThickLineLightning"); |
| 2116 | ////////////////////////////////////// |
| 2117 | |
| 2118 | for (int q = 0; q < 2; q++) { |
| 2119 | //////////////////////////////// |
| 2120 | vector check_pos; |
| 2121 | fvi_query fq; |
| 2122 | fvi_info hit_data; |
| 2123 | int hit_type; |
| 2124 | |
| 2125 | fq.p0 = (doing_start) ? &m_pos : &i_pos; |
| 2126 | fq.p1 = &check_pos; |
| 2127 | fq.startroom = (doing_start) ? m_room : i_room; |
| 2128 | fq.rad = 3.0f; |
| 2129 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 2130 | fq.thisobjnum = Monsterball - dObjects; |
| 2131 | fq.ignore_obj_list = NULL; |
| 2132 | |
| 2133 | // find top of room |
| 2134 | check_pos = (doing_start) ? m_pos : i_pos; |
| 2135 | check_pos.y *= 50000; |
| 2136 | hit_type = DLLfvi_FindIntersection(&fq, &hit_data, false); |
| 2137 | |
| 2138 | if (hit_type == HIT_NONE) |
| 2139 | return; |
| 2140 | |
| 2141 | start_room = hit_data.hit_room; |
| 2142 | start_pos = hit_data.hit_pnt; |
| 2143 | |
| 2144 | check_pos = (doing_start) ? m_pos : i_pos; |
| 2145 | check_pos.y *= -50000; |
| 2146 | hit_type = DLLfvi_FindIntersection(&fq, &hit_data, false); |
| 2147 | |
| 2148 | if (hit_type == HIT_NONE) |
| 2149 | return; |
| 2150 | |
| 2151 | end_room = hit_data.hit_room; |
| 2152 | end_pos = hit_data.hit_pnt; |
| 2153 | |
| 2154 | int visnum = DLLVisEffectCreate(VIS_FIREBALL, THICK_LIGHTNING_INDEX, start_room, &start_pos); |
| 2155 | if (visnum >= 0) { |
| 2156 | vis_effect *vis = &dVisEffects[visnum]; |
| 2157 | vis->lifeleft = lifetime; |
| 2158 | vis->lifetime = lifetime; |
| 2159 | vis->end_pos = end_pos; |
| 2160 | |
| 2161 | vis->custom_handle = texture_id; |
| 2162 | |
| 2163 | vis->lighting_color = color; |
| 2164 | vis->billboard_info.width = thickness; |
| 2165 | vis->billboard_info.texture = autotile; |
| 2166 | vis->velocity.x = sat_count; |
| 2167 | vis->velocity.y = slidetime; |
| 2168 | vis->velocity.z = numtiles; |
| 2169 | |
| 2170 | vis->flags = VF_USES_LIFELEFT | VF_WINDSHIELD_EFFECT | VF_LINK_TO_VIEWER | VF_EXPAND; |
| 2171 | vis->size = DLLvm_VectorDistanceQuick(&vis->pos, &vis->end_pos); |
| 2172 | } |
| 2173 | |
| 2174 | color = GR_RGB16(100, 255, 150); |
| 2175 | visnum = DLLVisEffectCreate(VIS_FIREBALL, SUN_CORONA_INDEX, start_room, &start_pos); |
| 2176 | if (visnum >= 0) { |
| 2177 | vis_effect *vis = &dVisEffects[visnum]; |
| 2178 | vis->lifeleft = lifetime; |
| 2179 | vis->lifetime = lifetime; |
| 2180 | |
| 2181 | vis->lighting_color = color; |
| 2182 | |
| 2183 | vis->flags = VF_USES_LIFELEFT | VF_WINDSHIELD_EFFECT | VF_LINK_TO_VIEWER; |
| 2184 | vis->size = 4; |
| 2185 | } |
| 2186 | visnum = DLLVisEffectCreate(VIS_FIREBALL, SUN_CORONA_INDEX, end_room, &end_pos); |
| 2187 | if (visnum >= 0) { |
| 2188 | vis_effect *vis = &dVisEffects[visnum]; |
| 2189 | vis->lifeleft = lifetime; |
| 2190 | vis->lifetime = lifetime; |
| 2191 | |
| 2192 | vis->lighting_color = color; |
| 2193 | |
| 2194 | vis->flags = VF_USES_LIFELEFT | VF_WINDSHIELD_EFFECT | VF_LINK_TO_VIEWER; |
| 2195 | vis->size = 4; |
| 2196 | } |
| 2197 | |
| 2198 | DLLCreateRandomSparks(rand() % 200 + 50, (doing_start) ? &m_pos : &i_pos, (doing_start) ? m_room : i_room, |
| 2199 | HOT_SPARK_INDEX, (rand() % 3) + 2); |
| 2200 | |
| 2201 | doing_start = !doing_start; |
| 2202 | } |
| 2203 | |
| 2204 | if (Monsterball->effect_info) { |
| 2205 | Monsterball->effect_info->type_flags &= ~EF_CLOAKED; |
| 2206 | Monsterball->effect_info->type_flags |= EF_FADING_IN; |
| 2207 | Monsterball->effect_info->fade_time = 4.0f; |
| 2208 | Monsterball->effect_info->cloak_time = 0; |
| 2209 | Monsterball->effect_info->fade_max_time = 4.0f; |
| 2210 | } |
| 2211 | } |