| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/dmfc/dmfcclient.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003/08/26 03:57:20 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Client Event handlers |
| 26 | * |
| 27 | * $Log: dmfcclient.cpp,v $ |
| 28 | * Revision 1.1.1.1 2003/08/26 03:57:20 kevinb |
| 29 | * initial 1.5 import |
| 30 | * |
| 31 | * |
| 32 | * 92 9/05/01 6:04p Matt |
| 33 | * Added code to save the user's preferred HUD name level setting even if |
| 34 | * the server bashes it down. |
| 35 | * |
| 36 | * 91 7/15/99 3:33p Jeff |
| 37 | * play a sound when a player disconnects/leaves the game |
| 38 | * |
| 39 | * 90 7/13/99 12:11p Jeff |
| 40 | * added some specific text taunt token decoding |
| 41 | * |
| 42 | * 89 7/13/99 10:05a Jeff |
| 43 | * text taunt token decoding |
| 44 | * |
| 45 | * 88 7/09/99 7:02p Jeff |
| 46 | * put in countdown timer for when a level is about to end |
| 47 | * |
| 48 | * 87 7/09/99 6:17p Jeff |
| 49 | * added $remoteadminlogout and $wait commands |
| 50 | * |
| 51 | * 86 7/09/99 2:53p Jeff |
| 52 | * handle gametime better (pause it when needed) if the server is 'waiting |
| 53 | * for players' |
| 54 | * |
| 55 | * 85 7/08/99 9:56p Jeff |
| 56 | * added event handler for weapon fired event |
| 57 | * |
| 58 | * 84 7/08/99 2:39a Jeff |
| 59 | * rough implementation of remote administration checked in. Still needs |
| 60 | * some polishing, but should work basically. |
| 61 | * |
| 62 | * 83 7/07/99 6:10p Jeff |
| 63 | * don't count the time that a player is in observer mode for death/kill |
| 64 | * messages |
| 65 | * |
| 66 | * 82 6/22/99 5:41p Jeff |
| 67 | * removed int3 (causing probs in Linux) |
| 68 | * |
| 69 | * 81 6/11/99 5:36p Jeff |
| 70 | * removed ai_info #ifdefs (better way of doing it) |
| 71 | * |
| 72 | * 80 6/10/99 12:41p Jeff |
| 73 | * no ai_info in non-Outrage builds |
| 74 | * |
| 75 | * 79 5/24/99 11:05p Jeff |
| 76 | * fixed bug for dedicated server team getting reset on endlevel |
| 77 | * |
| 78 | * 78 5/11/99 9:42p Jeff |
| 79 | * fixed bug changing teams while dead |
| 80 | * |
| 81 | * 77 5/10/99 2:43a Jeff |
| 82 | * handle new scheme of player's joining in a team game, where the team is |
| 83 | * set before player enters game in the main code, but the team is |
| 84 | * determined via event call to dmfc |
| 85 | * |
| 86 | * 76 5/08/99 4:45a Jeff |
| 87 | * fixed printscreen position |
| 88 | * |
| 89 | * 75 5/08/99 4:30a Jeff |
| 90 | * fixed sequencing bug where clients never got a level end event for the |
| 91 | * multiplayer games |
| 92 | * |
| 93 | * 74 5/07/99 5:16p Jeff |
| 94 | * fixed player disconnect at level end |
| 95 | * |
| 96 | * 73 5/07/99 2:21p Jeff |
| 97 | * fixed (?) not disconnecting clients on level end |
| 98 | * |
| 99 | * 72 5/04/99 8:46p Jeff |
| 100 | * display icon when someone plays an audio taunt |
| 101 | * |
| 102 | * 71 4/03/99 4:06p Jeff |
| 103 | * added loss/ping gauge |
| 104 | * |
| 105 | * 70 3/30/99 7:42p Jeff |
| 106 | * fixed a misspelling on a function name |
| 107 | * |
| 108 | * 69 3/22/99 6:20p Jeff |
| 109 | * added 2 more audio taunts. a mulitplayer event when someone plays an |
| 110 | * audio taunt. option to disable audio taunts. |
| 111 | * |
| 112 | * 68 3/22/99 1:55p Jeff |
| 113 | * make sure initialization happens (possible crashing) |
| 114 | * |
| 115 | * 67 3/17/99 12:23p Jeff |
| 116 | * converted DMFC to be COM interface |
| 117 | * |
| 118 | * 66 2/11/99 12:50a Jeff |
| 119 | * changed names of exported variables |
| 120 | * |
| 121 | * 65 2/09/99 3:32p Jeff |
| 122 | * table file parser takes quotes strings for force keywords |
| 123 | * |
| 124 | * 64 2/07/99 1:19a Jeff |
| 125 | * added new multiplayer game events EVT_GAMEOBJKILLED and |
| 126 | * EVT_GAMEOBJDESTROYED |
| 127 | * |
| 128 | * 63 2/05/99 8:24p Jeff |
| 129 | * added table file parser macros |
| 130 | * |
| 131 | * 62 2/04/99 7:17p Jeff |
| 132 | * put in sounds for hud messages |
| 133 | * |
| 134 | * 61 2/02/99 8:43a Chris |
| 135 | * I made buildings with AI work correctly (ie really big robots should be |
| 136 | * buildings) |
| 137 | * anim to and from states are now shorts instead of bytes |
| 138 | * |
| 139 | * 60 2/01/99 10:52p Jeff |
| 140 | * added sounds for kills (teammate and regular) |
| 141 | * |
| 142 | * 59 1/31/99 7:26p Matt |
| 143 | * Renamed a bunch of functions to have HUD capitalized |
| 144 | * |
| 145 | * 58 1/19/99 3:55a Jeff |
| 146 | * all strings localized out |
| 147 | * |
| 148 | * 56 1/15/99 3:54a Jeff |
| 149 | * exported a couple more functions. Added event handlers for Weapon |
| 150 | * collide event |
| 151 | * |
| 152 | * 55 1/12/99 2:55p Jeff |
| 153 | * added/finished the waiting for player's to join dialog |
| 154 | * |
| 155 | * 54 1/10/99 7:41p Jeff |
| 156 | * added initial version of waitforplayers dialog |
| 157 | * |
| 158 | * 53 1/07/99 5:01p Jeff |
| 159 | * added Int3's and updated all net games to use stats manager...correctly |
| 160 | * too |
| 161 | * |
| 162 | * 52 1/06/99 7:02p Jeff |
| 163 | * added a multiplayer event for game controls |
| 164 | * |
| 165 | * 51 12/23/98 6:38p Kevin |
| 166 | * All UDP data (except gamespy) now uses one (registered) port number |
| 167 | * |
| 168 | * 50 12/08/98 4:47p Jeff |
| 169 | * umm, various changes, fixed pilot pics so that they work for everyone |
| 170 | * now |
| 171 | * |
| 172 | * 49 12/08/98 3:29p Jeff |
| 173 | * updated the team control dialog so the server can determine if they |
| 174 | * want to make the clients wait |
| 175 | * |
| 176 | * 48 12/08/98 12:17p Jeff |
| 177 | * various changes that include an improved Team Control dialog (doesn't |
| 178 | * switch teams until exit..) and spew/respawn players that change teams |
| 179 | * |
| 180 | * 47 12/03/98 7:05p Jeff |
| 181 | * updated new stats |
| 182 | * |
| 183 | * 46 12/01/98 6:56p Jeff |
| 184 | * put in quick and dirty implementation of pilot pics for testing |
| 185 | * |
| 186 | * 45 11/19/98 5:56p Jeff |
| 187 | * added slider exported and improved Hoard |
| 188 | * |
| 189 | * 44 11/17/98 6:29p Jeff |
| 190 | * mod can specify whether or not to display the team setup dialog on team |
| 191 | * game start. Added a menu item to display team setup dialog in mid-game |
| 192 | * |
| 193 | * 43 11/16/98 5:35p Jeff |
| 194 | * removed log functions, added support for changing team names, fixed ctf |
| 195 | * to work better with different team names |
| 196 | * |
| 197 | * 42 11/11/98 7:19p Jeff |
| 198 | * changes made so that a dedicated server's team is always -1 (team game |
| 199 | * or not) |
| 200 | * |
| 201 | * 41 11/11/98 12:47p Jeff |
| 202 | * fixed bug where it would give team change messages in a non-team game |
| 203 | * |
| 204 | * 40 11/01/98 1:59a Jeff |
| 205 | * made a $help inputcommand for help in a dedicated server environment |
| 206 | * |
| 207 | * 39 10/30/98 12:47p Jeff |
| 208 | * cut down a couple bytes on memory usage |
| 209 | * |
| 210 | * 38 10/29/98 7:01p Jeff |
| 211 | * creation of team placement dialog. Moved TranslateEvent into DMFC |
| 212 | * |
| 213 | * 37 10/20/98 12:16p Jeff |
| 214 | * added death message filter, hud callsign filter |
| 215 | * |
| 216 | * 36 10/18/98 7:59p Jeff |
| 217 | * functions added to dmfc for client->server objnum matching. Banning |
| 218 | * now uses tracker id when available. |
| 219 | * |
| 220 | * 35 10/15/98 6:18p Jeff |
| 221 | * created the is player banned event, removed prejoin event |
| 222 | * |
| 223 | * 34 10/15/98 1:34p Jeff |
| 224 | * added scrollable onscreen menu. Remove ban in dmfc. prejoin event |
| 225 | * |
| 226 | * 33 10/13/98 2:15a Jeff |
| 227 | * created new event for when a player leaves a multiplayer game. Fixed |
| 228 | * some 'english' bugs in the network games. |
| 229 | * |
| 230 | * 32 10/11/98 2:57a Jeff |
| 231 | * added new multiplayer event EVT_GAME_INTERVAL, which is to be called on |
| 232 | * interval, and EVT_HUD_INTERVAL is only to be called when the hud is to |
| 233 | * be rendered |
| 234 | * |
| 235 | * 31 10/08/98 3:37p Jeff |
| 236 | * general improvements (Netgame info things, save to registry). Changes |
| 237 | * so it would send packets on NETSEQ_OBJECTS |
| 238 | * |
| 239 | * 30 10/05/98 2:49p Jeff |
| 240 | * |
| 241 | * 29 10/01/98 7:02p Jeff |
| 242 | * implemented colored HUD callsigns |
| 243 | * |
| 244 | * 28 10/01/98 11:30a Jeff |
| 245 | * made the observer mode events into just a client event |
| 246 | * |
| 247 | * 27 9/30/98 4:21p Jeff |
| 248 | * team changing is handled correctly |
| 249 | * |
| 250 | * 26 9/30/98 4:07p Jeff |
| 251 | * |
| 252 | * 25 9/30/98 3:50p Jeff |
| 253 | * general improvements (many) |
| 254 | * |
| 255 | * 24 9/28/98 5:05p Jeff |
| 256 | * made the statisitical death messages an option in the menu |
| 257 | * |
| 258 | * 23 9/25/98 7:57p Jeff |
| 259 | * removed CheckPInfo call |
| 260 | * |
| 261 | * 22 9/25/98 7:25p Jeff |
| 262 | * |
| 263 | * 21 9/25/98 4:50p Jeff |
| 264 | * |
| 265 | * 20 9/24/98 6:54p Jeff |
| 266 | * added DisconnectMe() and made use of it when you get kicked/banned |
| 267 | * |
| 268 | * 19 9/24/98 5:52p Jeff |
| 269 | * starting adding statistical death messages, checked in for testing |
| 270 | * |
| 271 | * 18 9/23/98 4:56p Jeff |
| 272 | * set teams always for 1 team game |
| 273 | * |
| 274 | * 17 9/23/98 4:17p Jeff |
| 275 | * basic changes/improvements, started changing death messages |
| 276 | * |
| 277 | * 16 9/21/98 7:11p Jeff |
| 278 | * made InputCommand interface API and moved existing input commands to |
| 279 | * the interface. Changed mprintf/ASSERT so they are valid in DMFC |
| 280 | * |
| 281 | * $NoKeywords: $ |
| 282 | */ |
| 283 | |
| 284 | #include "gamedll_header.h" |
| 285 | #include "DMFC.h" |
| 286 | #include "dmfcinternal.h" |
| 287 | |
| 288 | #define SND_MYTEAM_TEAMMATE_KILLED "PlayerDeath" |
| 289 | #define SND_NONTEAM_KILL "PlayerDeath" |
| 290 | |
| 291 | /* |
| 292 | $$TABLE_SOUND "PlayerDeath" |
| 293 | */ |
| 294 | |
| 295 | // ######################### Client allowed event handlers############################ |
| 296 | |
| 297 | // DMFCBase::OnClientPlayerKilled (Only called if server tells client to execute) |
| 298 | // |
| 299 | // Event handler for when a player gets killed, either by another player or some other way. |
| 300 | // killer_obj = object pointer to the object that killed the player |
| 301 | // victim_pnum = player number of the player that got killed |
| 302 | void DMFCBase::OnClientPlayerKilled(object *killer_obj, int victim_pnum) { |
| 303 | uint32_t hash = 0xFFFFFFFF; |
| 304 | int kpnum; |
| 305 | player_record *kpr, *vpr; |
| 306 | |
| 307 | if (!killer_obj) { |
| 308 | kpnum = -1; |
| 309 | } else { |
| 310 | if ((killer_obj->type == OBJ_PLAYER) || (killer_obj->type == OBJ_GHOST) || (killer_obj->type == OBJ_OBSERVER)) { |
| 311 | kpnum = killer_obj->id; |
| 312 | |
| 313 | // now we need to extract out the weapon of the kill |
| 314 | if (Data->iParam != -1) |
| 315 | hash = (uint32_t)Data->iParam; |
| 316 | } else if (killer_obj->type == OBJ_ROBOT || (killer_obj->type == OBJ_BUILDING && killer_obj->ai_info)) { |
| 317 | // countermeasure kill |
| 318 | kpnum = GetCounterMeasureOwner(killer_obj); |
| 319 | } else |
| 320 | kpnum = -1; |
| 321 | } |
| 322 | |
| 323 | if (victim_pnum != -1) { |
| 324 | if (kpnum == victim_pnum) { |
| 325 | // suicide |
| 326 | vpr = PRec_GetPRecordByPnum(victim_pnum); |
| 327 | if (vpr) { |
| 328 | vpr->dstats.suicides[DSTAT_LEVEL]++; |
| 329 | vpr->dstats.suicides[DSTAT_OVERALL]++; |
| 330 | } |
| 331 | UpdatePInfo(kpnum, kpnum, 1); |
| 332 | } else { |
| 333 | // regular death |
| 334 | vpr = PRec_GetPRecordByPnum(victim_pnum); |
| 335 | |
| 336 | if (vpr) { |
| 337 | vpr->dstats.deaths[DSTAT_LEVEL]++; |
| 338 | vpr->dstats.deaths[DSTAT_OVERALL]++; |
| 339 | } |
| 340 | |
| 341 | if (kpnum != -1) { |
| 342 | kpr = PRec_GetPRecordByPnum(kpnum); |
| 343 | if (kpr) { |
| 344 | kpr->dstats.kills[DSTAT_LEVEL]++; |
| 345 | kpr->dstats.kills[DSTAT_OVERALL]++; |
| 346 | } |
| 347 | UpdatePInfo(victim_pnum, kpnum, 1); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | static int teammate_kill_id = -2; |
| 353 | static int nonteam_kill_id = -2; |
| 354 | |
| 355 | if (killer_obj && killer_obj->type == OBJ_PLAYER && victim_pnum != -1) { |
| 356 | |
| 357 | if (Players[killer_obj->id].team == Players[victim_pnum].team && (GetNumTeams() >= 2) && |
| 358 | (killer_obj->id != victim_pnum)) { |
| 359 | // a teammate killed another teammate! |
| 360 | if (teammate_kill_id == -2) { |
| 361 | teammate_kill_id = DLLFindSoundName(IGNORE_TABLE(SND_MYTEAM_TEAMMATE_KILLED)); |
| 362 | } |
| 363 | if (teammate_kill_id != -1) { |
| 364 | DLLPlay2dSound(teammate_kill_id, MAX_GAME_VOLUME / 2); |
| 365 | } |
| 366 | } else { |
| 367 | // normal kill sound |
| 368 | if (nonteam_kill_id == -2) { |
| 369 | nonteam_kill_id = DLLFindSoundName(IGNORE_TABLE(SND_NONTEAM_KILL)); |
| 370 | } |
| 371 | if (nonteam_kill_id != -1) { |
| 372 | DLLPlay2dSound(nonteam_kill_id, MAX_GAME_VOLUME / 2); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | // if DMFC is supposed to handle Deathmessages, than do one |
| 378 | if (m_iProtectedFlags & DMFC_PRF_AUTODEATHMSG) |
| 379 | DoRandomDeathMessage(GetItObjNum(), GetMeObjNum(), hash); |
| 380 | } |
| 381 | |
| 382 | // DMFCBase::OnClientPlayerExploded (Only called if server tells client to execute) |
| 383 | // |
| 384 | // Event handler for when a player explodes. Gets called after a EVT_GAMEPLAYERKILLED event. |
| 385 | // player_num = player number of the player exploding |
| 386 | void DMFCBase::OnClientPlayerExploded(int player_num) {} |
| 387 | |
| 388 | // DMFCBase::OnClientCollide (Only called if server tells client to execute) |
| 389 | // |
| 390 | // Event handler for when two objects collide. At least one of the two objects is a player or a robot. |
| 391 | // Be aware that this event will be called twice per collision, the second time it is called the me and |
| 392 | // it objects will be flipped. |
| 393 | // ALSO NOTE: In order for the OnClientCollide() that passes the point and normal to have valid values |
| 394 | // the server must pass true to the parameter to send arguments in CallClientEvent(). |
| 395 | // me_obj = object pointer to the me object |
| 396 | // it_obj = object pointer to the it object |
| 397 | void DMFCBase::OnClientCollide(object *me_obj, object *it_obj) {} |
| 398 | void DMFCBase::OnClientCollide(object *me_obj, object *it_obj, vector *point, vector *normal) {} |
| 399 | |
| 400 | // DMFCBase::OnClientPlayerChangeSegment (Only called if server tells client to execute) |
| 401 | // |
| 402 | // Event handler for when a player changes rooms or a "large" terrain cell |
| 403 | // (8x8 Terrain block). |
| 404 | // player_num = player number of the player who just changed the room/segment |
| 405 | // newseg = New room/cell location |
| 406 | // oldseg = Old room/cell location |
| 407 | void DMFCBase::OnClientPlayerChangeSegment(int player_num, int newseg, int oldseg) {} |
| 408 | |
| 409 | // DMFCBase::OnClientObjectChangeSegment (Only called if server tells client to execute) |
| 410 | // |
| 411 | // Event handler for when a player changes rooms or a "large" terrain cell |
| 412 | // (8x8 Terrain block). |
| 413 | // obj = Object pointer of the object who just changed the room/segment |
| 414 | // newseg = New room/cell location |
| 415 | // oldseg = Old room/cell location |
| 416 | void DMFCBase::OnClientObjectChangeSegment(object *obj, int newseg, int oldseg) {} |
| 417 | |
| 418 | // DMFCBase::OnClientPlayerEntersGame (Only called if server tells client to execute) |
| 419 | // |
| 420 | // Event handler for when a player enters the game. This will only get called once per |
| 421 | // player, it usually gets called right after they connect to the server to start playing. |
| 422 | // player_num = player number of the player entering the game |
| 423 | void DMFCBase::OnClientPlayerEntersGame(int player_num) { |
| 424 | if ((GetLocalRole() == LR_SERVER) || (player_num != GetPlayerNum())) { |
| 425 | int slot; |
| 426 | |
| 427 | if (IsMasterTrackerGame()) |
| 428 | slot = PRec_FindPlayer(Players[player_num].callsign, NULL, Players[player_num].tracker_id); |
| 429 | else |
| 430 | slot = PRec_FindPlayer(Players[player_num].callsign, &NetPlayers[player_num].addr, NULL); |
| 431 | |
| 432 | if (slot == -1) { |
| 433 | // we have a new player |
| 434 | slot = PRec_GetFreeSlot(); |
| 435 | if (!PRec_AssignPlayerToSlot(player_num, slot, Players, NetPlayers)) |
| 436 | mprintf(0, "Unable to assign New Player (%s) to Player Record slot #%d\n", Players[player_num].callsign, slot); |
| 437 | else |
| 438 | mprintf(0, "(%s) has been assigned to Player Record slot #%d\n", Players[player_num].callsign, slot); |
| 439 | CallOnPlayerConnect(player_num); |
| 440 | } else { |
| 441 | // we have a reconnecting player |
| 442 | if (!PRec_ReconnectPlayerToSlot(player_num, slot, Players, NetPlayers)) |
| 443 | mprintf(0, "Unable to reassign reconnecting player (%s) to Player Record slot #%d\n", |
| 444 | Players[player_num].callsign, slot); |
| 445 | else |
| 446 | mprintf(0, "Reconnected player (%s) to Player Record slot #%d\n", Players[player_num].callsign, slot); |
| 447 | CallOnPlayerReconnect(player_num); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | // If the correct options are set, go into the D1/D2 style wait screen |
| 452 | if (GetLocalRole() == LR_SERVER && (player_num == GetPlayerNum())) { |
| 453 | |
| 454 | if (GetNumTeams() > 1 && (!(m_iProtectedFlags & DMFC_PRF_NOTEAMSELECTONSTART))) { |
| 455 | // Display the team placement dialog |
| 456 | static char enable; |
| 457 | enable = 1; |
| 458 | StartUIWindow(UIID_TEAMPLACEMENT, &enable); |
| 459 | } |
| 460 | |
| 461 | if (GetNumTeams() < 2 && (!(m_iProtectedFlags & DMFC_PRF_NOWAITFORPLAYERS))) { |
| 462 | StartUIWindow(UIID_WAITFORPLAYERS, NULL); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | // Load up the pilot picture bitmap |
| 467 | //-------------------------------- |
| 468 | if (player_num == GetPlayerNum()) { |
| 469 | // since we are entering the game, go through all the players and setup their bitmaps |
| 470 | for (int w = 0; w < DLLMAX_PLAYERS; w++) { |
| 471 | if (CheckPlayerNum(w) || (w == 0 && GetLocalRole() == LR_SERVER)) { |
| 472 | if (PilotPicBmpHandles[w] > BAD_BITMAP_HANDLE) { |
| 473 | DLLbm_FreeBitmap(PilotPicBmpHandles[w]); |
| 474 | PilotPicBmpHandles[w] = BAD_BITMAP_HANDLE; |
| 475 | } |
| 476 | |
| 477 | mprintf(0, "PPIC ID: %d is %d\n", w, NetPlayers[w].pilot_pic_id); |
| 478 | if (NetPlayers[w].pilot_pic_id != 65535) { |
| 479 | PilotPicBmpHandles[w] = DLLPPic_GetBitmapHandle(NetPlayers[w].pilot_pic_id); |
| 480 | if (PilotPicBmpHandles[w] < BAD_BITMAP_HANDLE) |
| 481 | PilotPicBmpHandles[w] = BAD_BITMAP_HANDLE; |
| 482 | } else { |
| 483 | PilotPicBmpHandles[w] = BAD_BITMAP_HANDLE; |
| 484 | } |
| 485 | } else { |
| 486 | PilotPicBmpHandles[w] = BAD_BITMAP_HANDLE; |
| 487 | } |
| 488 | } |
| 489 | } else { |
| 490 | if (PilotPicBmpHandles[player_num] > BAD_BITMAP_HANDLE) { |
| 491 | DLLbm_FreeBitmap(PilotPicBmpHandles[player_num]); |
| 492 | PilotPicBmpHandles[player_num] = BAD_BITMAP_HANDLE; |
| 493 | } |
| 494 | |
| 495 | mprintf(0, "PPIC ID: %d is %d\n", player_num, NetPlayers[player_num].pilot_pic_id); |
| 496 | if (NetPlayers[player_num].pilot_pic_id != 65535) { |
| 497 | PilotPicBmpHandles[player_num] = DLLPPic_GetBitmapHandle(NetPlayers[player_num].pilot_pic_id); |
| 498 | if (PilotPicBmpHandles[player_num] < BAD_BITMAP_HANDLE) |
| 499 | PilotPicBmpHandles[player_num] = BAD_BITMAP_HANDLE; |
| 500 | } else { |
| 501 | PilotPicBmpHandles[player_num] = BAD_BITMAP_HANDLE; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | // Play the player hud message sound |
| 506 | static int sound_id = -2; |
| 507 | if (sound_id == -2) { |
| 508 | sound_id = DLLFindSoundName("Hudmessage"); |
| 509 | } |
| 510 | |
| 511 | if (sound_id > -1 && GetPlayerNum() != player_num) { |
| 512 | DLLPlay2dSound(sound_id, MAX_GAME_VOLUME / 2); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | // DMFCBase::OnClientPlayerDisconnect |
| 517 | // |
| 518 | // Event handler for when a player disconnects from the server. |
| 519 | // player_num = player number of the player that just disconnected |
| 520 | void DMFCBase::OnClientPlayerDisconnect(int player_num) { |
| 521 | // Play the player hud message sound |
| 522 | static int sound_id = -2; |
| 523 | if (sound_id == -2) { |
| 524 | sound_id = DLLFindSoundName("Hudmessage"); |
| 525 | } |
| 526 | |
| 527 | if (sound_id > -1 && GetPlayerNum() != player_num) { |
| 528 | DLLPlay2dSound(sound_id, MAX_GAME_VOLUME / 2); |
| 529 | } |
| 530 | |
| 531 | // save the team |
| 532 | PRec_SetPlayerTeam(player_num, Players[player_num].team); |
| 533 | |
| 534 | if (!PRec_DisconnectPlayer(player_num)) |
| 535 | mprintf(0, "Unable to disconnect player (%s) from Player Records\n", Players[player_num].callsign); |
| 536 | else |
| 537 | mprintf(0, "Disconnected player (%s) from Player Records\n", Players[player_num].callsign); |
| 538 | } |
| 539 | |
| 540 | // DMFCBase::OnMeDisconnectFromServer |
| 541 | // |
| 542 | // Event handler that gets called if we disconnect from the server for some reason (not purposesly quit) |
| 543 | void DMFCBase::OnMeDisconnectFromServer(void) { |
| 544 | // We're disconnecting so save the stats to file |
| 545 | if (m_iProtectedFlags & DMFC_PRF_AUTOSAVEDISC) |
| 546 | CallOnDisconnectSaveStatsToFile(); |
| 547 | } |
| 548 | |
| 549 | // DMFCBase::OnClientGameCreated (Only called if server tells client to execute) |
| 550 | // |
| 551 | // Event handler when the server's game first gets started. This will only be called once |
| 552 | // while the server is running, and that is when the server first starts up. |
| 553 | void DMFCBase::OnClientGameCreated(void) {} |
| 554 | |
| 555 | // DMFCBase::OnClientLevelChange (Only called if server tells client to execute) |
| 556 | // |
| 557 | // Event handler when the server changes levels. This will get called after a level ends and a server |
| 558 | // is starting a new level. |
| 559 | void DMFCBase::OnClientLevelChange(void) {} |
| 560 | |
| 561 | // DMFCBase::OnClientLevelStart (Only called if server tells client to execute) |
| 562 | // |
| 563 | // Event handler for when a multiplayer level is starting up. This will get called right before the level |
| 564 | // starts. |
| 565 | void DMFCBase::OnClientLevelStart(void) { |
| 566 | // Clear this array so we don't get weird anomalies |
| 567 | ResetPlayersInGame(); |
| 568 | |
| 569 | // Reset the timers |
| 570 | InitTimers(); |
| 571 | |
| 572 | // Reset level stats of Player Records |
| 573 | PRec_LevelReset(); |
| 574 | |
| 575 | // reset the pinfo list |
| 576 | ResetPInfo(); |
| 577 | |
| 578 | // Request Player Records |
| 579 | SendRequestForPlayerRecords(); |
| 580 | |
| 581 | DisplayTauntIndicator = false; |
| 582 | } |
| 583 | |
| 584 | // DMFCBase::OnClientLevelEnd |
| 585 | // |
| 586 | // Event handler for when a multiplayer level is ending. |
| 587 | void DMFCBase::OnClientLevelEnd(void) { |
| 588 | MarkPlayersInGame(); |
| 589 | |
| 590 | if (m_iProtectedFlags & DMFC_PRF_AUTOSAVELEVELEND) |
| 591 | CallOnLevelEndSaveStatsToFile(); |
| 592 | |
| 593 | KillAllTimers(); |
| 594 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PLRFIRSTTIME); |
| 595 | |
| 596 | // Call PLRInit so data can be initialized |
| 597 | CallOnPLRInit(); |
| 598 | |
| 599 | for (int i = 0; i < DLLMAX_PLAYERS; i++) { |
| 600 | if ((NetPlayers[i].flags & NPF_CONNECTED) && |
| 601 | (NetPlayers[i].sequence >= NETSEQ_PLAYING || NetPlayers[i].sequence == NETSEQ_WAITING_FOR_LEVEL)) { |
| 602 | |
| 603 | // save the team |
| 604 | PRec_SetPlayerTeam(i, Players[i].team); |
| 605 | |
| 606 | if (!PRec_DisconnectPlayer(i)) |
| 607 | mprintf(0, "Unable to disconnect player (%s) from Player Records\n", Players[i].callsign); |
| 608 | else |
| 609 | mprintf(0, "Disconnected player (%s) from Player Records\n", Players[i].callsign); |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | // DMFCBase::OnPlayerEntersObserver |
| 615 | // |
| 616 | // Event handler when a player becomes an observer mode |
| 617 | // If they are piggybacking another player than piggy is the object pointer, else it's NULL |
| 618 | void DMFCBase::OnPlayerEntersObserver(int pnum, object *piggy) { |
| 619 | mprintf(0, "Player %d entering observermode %s\n", pnum, (piggy) ? "Piggyback" : "Roam"); |
| 620 | player_record *pr = PRec_GetPRecordByPnum(pnum); |
| 621 | if (pr && pr->state == STATE_INGAME) { |
| 622 | PInfo *pi = pr->pinfo; |
| 623 | ASSERT(pi != NULL); |
| 624 | pi->EnterObserverMode(); |
| 625 | } else { |
| 626 | Int3(); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | // DMFCBase::OnPlayerExitsObserver |
| 631 | // |
| 632 | // Event handler when a player is leaving observer mode |
| 633 | void DMFCBase::OnPlayerExitsObserver(int pnum) { |
| 634 | mprintf(0, "Player %d leaving observer mode\n", pnum); |
| 635 | player_record *pr = PRec_GetPRecordByPnum(pnum); |
| 636 | if (pr && pr->state == STATE_INGAME) { |
| 637 | PInfo *pi = pr->pinfo; |
| 638 | ASSERT(pi != NULL); |
| 639 | pi->ExitObserverMode(); |
| 640 | } else { |
| 641 | Int3(); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | // DMFCBase::OnCanChangeTeam |
| 646 | // |
| 647 | // Called to determine if a player can change teams, you can override this so the server won't |
| 648 | // let a player change teams if it is not desired (for that player) |
| 649 | bool DMFCBase::OnCanChangeTeam(int pnum, int newteam) { |
| 650 | if (Players[pnum].team == -1) |
| 651 | return false; // no team switching for dedicated server |
| 652 | |
| 653 | // AnnounceTeamChangeDeny(pnum); |
| 654 | return true; |
| 655 | } |
| 656 | |
| 657 | // DMFCBase::OnSaveStatsToFile |
| 658 | // |
| 659 | // |
| 660 | // The user is requesting the game stats to be saved to file, you must handle this completly on |
| 661 | // the game's side, nothing is done in DMFC |
| 662 | void DMFCBase::OnSaveStatsToFile(void) { mprintf(0, "User requested stats to be saved!\n"); } |
| 663 | |
| 664 | // DMFCBase::OnLevelEndSaveStatsToFile |
| 665 | // |
| 666 | // |
| 667 | // The game should save the "End of Level" stats to file. You must handle this completly on |
| 668 | // the game's side, nothing is done in DMFC |
| 669 | void DMFCBase::OnLevelEndSaveStatsToFile(void) {} |
| 670 | |
| 671 | // DMFCBase::OnDisconnectSaveStatsToFile |
| 672 | // |
| 673 | // |
| 674 | // The game should save the stats because the player (only ourself as the client in the game), |
| 675 | // has disconnected. |
| 676 | void DMFCBase::OnDisconnectSaveStatsToFile(void) {} |
| 677 | |
| 678 | // DMFCBase::OnSpecialPacket |
| 679 | // |
| 680 | // Event handler for when a special packet arrives and needs to be processed. |
| 681 | // Both the server and client can get this event, although it is more common for the |
| 682 | // client to recieve these. |
| 683 | void DMFCBase::OnSpecialPacket(void) { |
| 684 | if (!SPRoot) |
| 685 | return; |
| 686 | |
| 687 | // see if we have a handler for the ID, if so, call the handler, else do nothing |
| 688 | uint8_t *data = Data->special_data; |
| 689 | int id = data[0]; |
| 690 | |
| 691 | tSPHandler *current; |
| 692 | current = SPRoot; |
| 693 | while (current) { |
| 694 | if (current->ID == id) { |
| 695 | // we got a winner |
| 696 | switch (current->type) { |
| 697 | case SPH_DMFCFUNC: |
| 698 | if (current->DMFCfunc) |
| 699 | (this->*current->DMFCfunc)(data + 1); |
| 700 | break; |
| 701 | case SPH_FUNC: |
| 702 | if (current->func) |
| 703 | (*current->func)(data + 1); |
| 704 | break; |
| 705 | } |
| 706 | return; |
| 707 | } |
| 708 | current = current->next; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | // DMFCBase::OnHUDInterval |
| 713 | // |
| 714 | // Event handler that gets called once a frame when it's time to render the HUD images |
| 715 | void DMFCBase::OnHUDInterval(void) { |
| 716 | if (m_bMakeClientsWait) |
| 717 | WaitingForServerLoop(); |
| 718 | if (m_iProtectedFlags & DMFC_PRF_DISPPLAYERINFO) |
| 719 | DisplayPlayerInfo(MenuBackgroundBMP); |
| 720 | if (m_iProtectedFlags & DMFC_PRF_DISPNETGAMEINFO) |
| 721 | DisplayNetGameInfo(MenuBackgroundBMP); |
| 722 | LossGuageFrame(); |
| 723 | DisplayTauntIndicatorFrame(); |
| 724 | |
| 725 | if (m_iProtectedFlags & DMFC_PRF_INOPTIONS) { |
| 726 | // Update all the state submenus so they are reporting the correct value |
| 727 | if (TeamMenuItem) |
| 728 | TeamMenuItem->SetState(GetPlayerTeam(GetPlayerNum())); |
| 729 | if (AutoBalanceItem) |
| 730 | AutoBalanceItem->SetState((m_iProtectedFlags & DMFC_PRF_AUTOTEAMSELECT) ? 1 : 0); |
| 731 | if (AllowTeamChangeItem) |
| 732 | AllowTeamChangeItem->SetState(AllowTeamChange() ? 1 : 0); |
| 733 | if (ObserverItem) |
| 734 | ObserverItem->SetState((Objects[Players[GetPlayerNum()].objnum].type == OBJ_OBSERVER) ? 1 : 0); |
| 735 | if (StatisticMessagesItem) |
| 736 | StatisticMessagesItem->SetState((m_iProtectedFlags & DMFC_PRF_DISPSTATHUDMSGS) ? 1 : 0); |
| 737 | if (SaveStatsLevelEndItem) |
| 738 | SaveStatsLevelEndItem->SetState((m_iProtectedFlags & DMFC_PRF_AUTOSAVELEVELEND) ? 1 : 0); |
| 739 | if (SaveStatsDisconnectItem) |
| 740 | SaveStatsDisconnectItem->SetState((m_iProtectedFlags & DMFC_PRF_AUTOSAVEDISC) ? 1 : 0); |
| 741 | if (MenuBackgroundItem) |
| 742 | MenuBackgroundItem->SetState((m_iProtectedFlags & DMFC_PRF_DISPMENUBACKGR) ? 1 : 0); |
| 743 | if (NetGameInfoItem) |
| 744 | NetGameInfoItem->SetState(IsDisplayingNetGameInfo() ? 1 : 0); |
| 745 | if (HUDCallsignsItem) |
| 746 | HUDCallsignsItem->SetState(m_iMyCurrentHUDCallsignLevel); |
| 747 | if (ServerHUDCallsignsItem) |
| 748 | ServerHUDCallsignsItem->SetState(m_iServerHUDCallsignLevel); |
| 749 | if (DeathMessageFilterItem) |
| 750 | DeathMessageFilterItem->SetState(m_iDeathMessageFilter); |
| 751 | if (ShipLogosItem) |
| 752 | ShipLogosItem->SetState(AreLogosEnabled() ? 1 : 0); |
| 753 | if (HUDIndicatorItem) |
| 754 | HUDIndicatorItem->SetState(LossGuageEnabled ? 1 : 0); |
| 755 | |
| 756 | // We have an options screen up, so draw it |
| 757 | DrawMenu(); |
| 758 | } |
| 759 | |
| 760 | // DisplayPilotPicsFrame(); |
| 761 | |
| 762 | // Display countdown if needed |
| 763 | DisplayTimelimitCountdown(); |
| 764 | |
| 765 | DLLgrtext_Flush(); |
| 766 | } |
| 767 | |
| 768 | // DMFCBase::OnInterval |
| 769 | // |
| 770 | // Event handler that gets called once a frame |
| 771 | void DMFCBase::OnInterval(void) { |
| 772 | if (!(m_iProtectedFlags & DMFC_PRF_PAUSETIME)) { |
| 773 | RealGametime += *Frametime; // increment the timer |
| 774 | } |
| 775 | |
| 776 | // If we are a dedicated server, we are waiting, and there is a wait time |
| 777 | // check to see if it's time to disable |
| 778 | if (GetLocalRole() == LR_SERVER && IAmDedicatedServer() && m_bMakeClientsWait) { |
| 779 | if (DedicatedLevelWait > 0 && DedicatedLevelWait <= (*Gametime)) { |
| 780 | // time to stop waiting! |
| 781 | mprintf(0, "Telling clients that they can play!\n"); |
| 782 | DPrintf("Allowing Clients To Play\n"); |
| 783 | PauseRealGameTime(false); |
| 784 | MakeClientsWait(false); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | // CheckPInfo(); |
| 789 | |
| 790 | // Process remote admin frame |
| 791 | Remote_ProcessFrame(); |
| 792 | |
| 793 | // Process all currently running timers |
| 794 | ProcessTimers(); |
| 795 | |
| 796 | // Handle time limit games |
| 797 | float tleft; |
| 798 | if (GetLocalRole() == LR_SERVER) { |
| 799 | if ((m_iProtectedFlags & DMFC_PRF_AUTOTIMELIMIT) && (GetTimeLeft(&tleft))) { |
| 800 | if (tleft <= 0) { |
| 801 | EndLevel(); |
| 802 | return; |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | // DMFCBase::OnPLRInterval |
| 809 | // |
| 810 | // Event handler that gets called once a frame when the Post Level Results screen is being display |
| 811 | void DMFCBase::OnPLRInterval(void) { |
| 812 | DLLgrtext_SetFont(Game_fonts[SMALL_UI_FONT_INDEX]); |
| 813 | DLLgrtext_SetColor(GR_RGB(255, 40, 40)); |
| 814 | DLLgrtext_CenteredPrintf(0, 13, Netgame->scriptname); |
| 815 | DLLgrtext_CenteredPrintf(0, 461, DTXT_PRESSPRNTSCRN); |
| 816 | } |
| 817 | |
| 818 | // DMFCBase::OnPLRInit |
| 819 | // |
| 820 | // Event handler that gets called the first frame of the PLR screen for each level |
| 821 | void DMFCBase::OnPLRInit(void) { DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PLRFIRSTTIME); } |
| 822 | |
| 823 | // DMFCBase::OnKeypress |
| 824 | // |
| 825 | // Event handler for when a user presses a key while in the game |
| 826 | // key = Key code of the key being pressed |
| 827 | void DMFCBase::OnKeypress(int key) { |
| 828 | if (m_iProtectedFlags & DMFC_PRF_INOPTIONS) { |
| 829 | Data->iRet = 1; |
| 830 | // Handle keyboard input for an options menu |
| 831 | if (key == K_F6 || key == K_ESC) { // escape out of options |
| 832 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_INOPTIONS); |
| 833 | } |
| 834 | if (key == K_ENTER) { |
| 835 | Menu.Execute(); |
| 836 | } |
| 837 | switch (key) { |
| 838 | case K_DOWN: { |
| 839 | Menu.Down(); |
| 840 | } break; |
| 841 | case K_UP: { |
| 842 | Menu.Up(); |
| 843 | } break; |
| 844 | case K_RIGHT: { |
| 845 | Menu.Forward(); |
| 846 | } break; |
| 847 | case K_LEFT: { |
| 848 | Menu.Back(); |
| 849 | } break; |
| 850 | } |
| 851 | } else if (key == K_F6) { |
| 852 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_INOPTIONS); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | // DMFCBase::OnInputString |
| 857 | // |
| 858 | // Event handler for when the user types a message at the console (F8) that begins with a $ |
| 859 | // input_string = string that was typed |
| 860 | void DMFCBase::OnInputString(char *input_string) { |
| 861 | if (!InputCommandHandle(input_string)) { |
| 862 | // The input command wasn't handled! |
| 863 | mprintf(0, "DMFC Warning: Input Command '%s' wasn't handled\n", input_string); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | // DMFCBase::OnPlayerChangeTeam |
| 868 | // |
| 869 | // Called when a player changes team |
| 870 | void DMFCBase::OnPlayerChangeTeam(int player_num, int newteam, bool announce, bool spew_everything) { |
| 871 | player_record *pr = GetPlayerRecordByPnum(player_num); |
| 872 | if (pr) { |
| 873 | if (GetNumTeams() > 1 && announce && newteam != -1) |
| 874 | DLLAddHUDMessage(DTXT_CHANGETEAM, pr->callsign, GetTeamString(newteam)); |
| 875 | pr->team = newteam; |
| 876 | |
| 877 | // only respawn them if they are not dead |
| 878 | if (!((Players[player_num].flags & PLAYER_FLAGS_DYING) || (Players[player_num].flags & PLAYER_FLAGS_DEAD))) { |
| 879 | RespawnPlayer(player_num, false, spew_everything); |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | // DMFCBase::OnClientObjectShieldsChanged |
| 885 | // |
| 886 | // Event handler for when an objects shield's change |
| 887 | void DMFCBase::OnClientObjectShieldsChanged(object *obj, float amount) {} |
| 888 | |
| 889 | // DMFCBase::OnWeaponFired |
| 890 | // |
| 891 | // Event handler for when an object fires a weapon |
| 892 | void DMFCBase::OnWeaponFired(object *weapon_obj, object *shooter) {} |
| 893 | |
| 894 | // DMFCBase::OnPlayerReconnect |
| 895 | // |
| 896 | // |
| 897 | // This player is reconnecting to the game |
| 898 | void DMFCBase::OnPlayerReconnect(int player_num) { |
| 899 | if (GetLocalRole() == LR_SERVER) { |
| 900 | // restore their team |
| 901 | int team = PRec_GetPlayerTeam(player_num); |
| 902 | if (team != Players[player_num].team) { |
| 903 | // hey! Jason hasn't set the correct team for this player |
| 904 | ASSERT(player_num == 0); // this is only going to happen for the server |
| 905 | } |
| 906 | |
| 907 | SendTeamAssignment(player_num, team, false); |
| 908 | Players[player_num].team = team; |
| 909 | CallOnPlayerChangeTeam(player_num, team, false, false); |
| 910 | mprintf(0, "Reassigning (%s) to %s team\n", Players[player_num].callsign, GetTeamString(team)); |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | // DMFCBase::OnPlayerConnect |
| 915 | // |
| 916 | // |
| 917 | // This player is connecting to the game for the first time |
| 918 | void DMFCBase::OnPlayerConnect(int player_num) { |
| 919 | if (GetLocalRole() == LR_SERVER) { |
| 920 | |
| 921 | // a dedicated server MUST be given a -1 team |
| 922 | //------------------------------------------ |
| 923 | if (player_num == 0 && IAmDedicatedServer()) { |
| 924 | Players[0].team = -1; |
| 925 | } |
| 926 | |
| 927 | // get team assignment |
| 928 | if (m_iProtectedFlags & DMFC_PRF_AUTOTEAMSELECT) { |
| 929 | // JEFF: Commented out since team's are now determined right when a client connects |
| 930 | //@@int team = GetTeamForNewPlayer(player_num,m_iNumTeams); |
| 931 | int team = Players[player_num].team; |
| 932 | SendTeamAssignment(player_num, team, false); |
| 933 | //@@Players[player_num].team = team; |
| 934 | CallOnPlayerChangeTeam(player_num, team, false, false); |
| 935 | mprintf(0, "Assigning (%s) to %s team\n", Players[player_num].callsign, GetTeamString(team)); |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | // DMFCBase::OnControlMessage |
| 941 | // |
| 942 | // |
| 943 | // There is a control message sent from someone |
| 944 | void DMFCBase::OnControlMessage(uint8_t msg, int from_pnum) { |
| 945 | switch (msg) { |
| 946 | case CM_KICKED: { |
| 947 | DLLAddHUDMessage(DTXT_KICKEDMSG); |
| 948 | DisconnectMe(); |
| 949 | } break; |
| 950 | case CM_BANNED: { |
| 951 | DLLAddHUDMessage(DTXT_BANNEDMSG); |
| 952 | DisconnectMe(); |
| 953 | } break; |
| 954 | case CM_TEAMCHANGEDENIED: { |
| 955 | // if we get this, the server is telling us that the request for a |
| 956 | // team change has been denied |
| 957 | AnnounceTeamChangeDeny(*Player_num); |
| 958 | } break; |
| 959 | case CM_SIGNALSTART: { |
| 960 | if (from_pnum == 0) { |
| 961 | // we can move!! |
| 962 | WaitForServer(false); |
| 963 | } |
| 964 | } break; |
| 965 | case CM_SIGNALWAIT: { |
| 966 | if (from_pnum == 0) { |
| 967 | // we got to wait |
| 968 | WaitForServer(true); |
| 969 | } |
| 970 | } break; |
| 971 | case CM_PAUSETIME: { |
| 972 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME); |
| 973 | } break; |
| 974 | case CM_UNPAUSETIME: { |
| 975 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME); |
| 976 | } break; |
| 977 | }; |
| 978 | } |
| 979 | |
| 980 | // DMFCBase::OnAllowObserverChange |
| 981 | // |
| 982 | // |
| 983 | // returns true if the requested change for observer mode should go through |
| 984 | bool DMFCBase::OnAllowObserverChange(bool turnonobserver) { return true; } |
| 985 | |
| 986 | // DMFCBase::OnClientShowUI |
| 987 | // |
| 988 | // |
| 989 | // The game is saying it's ok to do any UI |
| 990 | void DMFCBase::OnClientShowUI(int id, void *user_data) { |
| 991 | switch (id) { |
| 992 | case UIID_TEAMPLACEMENT: { |
| 993 | bool clients_wait; |
| 994 | bool call_from_game; |
| 995 | uint8_t d = *(uint8_t *)user_data; |
| 996 | |
| 997 | clients_wait = (d & 0x01) ? true : false; |
| 998 | call_from_game = (d & 0x02) ? false : true; |
| 999 | |
| 1000 | DoDMFCUITeamPlacement(clients_wait, call_from_game); |
| 1001 | } break; |
| 1002 | case UIID_WAITFORPLAYERS: { |
| 1003 | DoDMFCUIWaitForPlayers(true); |
| 1004 | } break; |
| 1005 | }; |
| 1006 | } |
| 1007 | |
| 1008 | // DMFCBase::OnPrintScores |
| 1009 | // |
| 1010 | // |
| 1011 | // The user is requesting that the scores be printed out (For Dedicated Server use). Use DPrintf |
| 1012 | // level: -1 Requesting all the available scores |
| 1013 | // n Print only the top n scores |
| 1014 | // Override this to how you see fit, but it should conform to the above. |
| 1015 | void DMFCBase::OnPrintScores(int level) {} |
| 1016 | |
| 1017 | // DMFCBase::OnGetHudCallSignColor |
| 1018 | // |
| 1019 | // This is an event sent in by the game requesting what color it should draw the HUD callsign |
| 1020 | // of the passed in playernum. Using GR_RGB return the color from the function. This function |
| 1021 | // gets called every frame that the player is on the clients HUD. |
| 1022 | ddgr_color DMFCBase::OnGetHudCallSignColor(int playernum) { |
| 1023 | if (!CheckPlayerNum(playernum)) |
| 1024 | return GR_RGB(255, 255, 255); |
| 1025 | |
| 1026 | if (GetNumTeams() <= 1) |
| 1027 | return GR_RGB(0, 255, 0); |
| 1028 | |
| 1029 | return GetTeamColor(GetPlayerTeam(playernum)); |
| 1030 | } |
| 1031 | |
| 1032 | // DMFCBase::OnTeamChangeName |
| 1033 | // |
| 1034 | // This event occurs on the client when a team's name has just changed |
| 1035 | void DMFCBase::OnTeamChangeName(int team, char *oldname, char *newname) { |
| 1036 | char names[DLLMAX_TEAMS][MAX_TEAMNAME_LEN]; |
| 1037 | strcpy(names[RED_TEAM], GetTeamString(RED_TEAM)); |
| 1038 | strcpy(names[BLUE_TEAM], GetTeamString(BLUE_TEAM)); |
| 1039 | if (TeamMenuItem) { |
| 1040 | switch (m_iNumTeams) { |
| 1041 | case 2: |
| 1042 | TeamMenuItem->SetStateItemList(m_iNumTeams, names[RED_TEAM], names[BLUE_TEAM]); |
| 1043 | break; |
| 1044 | case 3: |
| 1045 | strcpy(names[GREEN_TEAM], GetTeamString(GREEN_TEAM)); |
| 1046 | TeamMenuItem->SetStateItemList(m_iNumTeams, names[RED_TEAM], names[BLUE_TEAM], names[GREEN_TEAM]); |
| 1047 | break; |
| 1048 | case 4: |
| 1049 | strcpy(names[GREEN_TEAM], GetTeamString(GREEN_TEAM)); |
| 1050 | strcpy(names[YELLOW_TEAM], GetTeamString(YELLOW_TEAM)); |
| 1051 | TeamMenuItem->SetStateItemList(m_iNumTeams, names[RED_TEAM], names[BLUE_TEAM], names[GREEN_TEAM], |
| 1052 | names[YELLOW_TEAM]); |
| 1053 | break; |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | // DMFCBase::OnDoControls |
| 1059 | // |
| 1060 | // This event occurs when there is a new back of game controls data |
| 1061 | void DMFCBase::OnDoControls(game_controls *controls) { |
| 1062 | memcpy(&Last_game_controls, controls, sizeof(Last_game_controls)); |
| 1063 | } |
| 1064 | |
| 1065 | // DMFCBase::OnClientWallCollide |
| 1066 | // |
| 1067 | // Called by the game when their is a collision between an object and a wall |
| 1068 | void DMFCBase::OnClientWallCollide(object *obj, float hitspeed, int hitseg, int hitwall, vector *hitpt, |
| 1069 | vector *wall_normal, float hit_dot) {} |
| 1070 | |
| 1071 | // DMFCBase::OnClientObjectKilled |
| 1072 | // |
| 1073 | // Called when an object is being killed |
| 1074 | // Not automatically sent to clients (OnClientObjectKilled) |
| 1075 | // killer might not be valid (NULL) |
| 1076 | void DMFCBase::OnClientObjectKilled(object *obj, object *killer) {} |
| 1077 | |
| 1078 | // DMFCBase::OnClientObjectDestroyed |
| 1079 | // |
| 1080 | // Called when an object is about to be deleted |
| 1081 | // Not automatically sent to clients |
| 1082 | void DMFCBase::OnClientObjectDestroyed(object *obj) {} |
| 1083 | |
| 1084 | // DMFCBase::OnPlayAudioTaunt |
| 1085 | // |
| 1086 | // This event occurs when a player plays an audio taunt |
| 1087 | void DMFCBase::OnPlayAudioTaunt(int pnum) { |
| 1088 | mprintf(0, "%s plays an audio taunt\n", Players[pnum].callsign); |
| 1089 | SetPlayerTauntIndicator(pnum); |
| 1090 | } |
| 1091 | |
| 1092 | // DMFCBase::OnGetTokenString |
| 1093 | // |
| 1094 | // This event occurs when a text macro is being used that has tokens |
| 1095 | // in it, if you have a specific token, override this event to handle it. |
| 1096 | void DMFCBase::OnGetTokenString(char *src, char *dest, int dest_size) { |
| 1097 | *dest = '\0'; |
| 1098 | |
| 1099 | if (!stricmp(src, "e")) { |
| 1100 | // energy |
| 1101 | char buffer[64]; |
| 1102 | int mypnum = GetPlayerNum(); |
| 1103 | snprintf(buffer, sizeof(buffer), "%.0f", Players[mypnum].energy); |
| 1104 | strncpy(dest, buffer, dest_size - 1); |
| 1105 | dest[dest_size - 1] = '\0'; |
| 1106 | return; |
| 1107 | } |
| 1108 | |
| 1109 | if (!stricmp(src, "s")) { |
| 1110 | // shields |
| 1111 | char buffer[64]; |
| 1112 | int mypnum = GetPlayerNum(); |
| 1113 | snprintf(buffer, sizeof(buffer), "%.0f", Objects[Players[mypnum].objnum].shields); |
| 1114 | strncpy(dest, buffer, dest_size - 1); |
| 1115 | dest[dest_size - 1] = '\0'; |
| 1116 | return; |
| 1117 | } |
| 1118 | } |