| 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/dmfcbase.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003/08/26 03:57:20 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Base functions for DMFC implementation |
| 26 | * |
| 27 | * $Log: dmfcbase.cpp,v $ |
| 28 | * Revision 1.1.1.1 2003/08/26 03:57:20 kevinb |
| 29 | * initial 1.5 import |
| 30 | * |
| 31 | * |
| 32 | * 170 9/28/01 2:09p Matt |
| 33 | * Don't show ping/loss info on HUD if peer-to-peer game. |
| 34 | * |
| 35 | * 169 9/07/01 8:57a Matt |
| 36 | * Fixed hud name bug from previous change. |
| 37 | * |
| 38 | * 168 9/05/01 6:04p Matt |
| 39 | * Added code to save the user's preferred HUD name level setting even if |
| 40 | * the server bashes it down. |
| 41 | * |
| 42 | * 167 10/26/99 10:31a Jeff |
| 43 | * fixed COM interface bug |
| 44 | * |
| 45 | * 166 10/21/99 9:27p Jeff |
| 46 | * B.A. Macintosh code merge |
| 47 | * |
| 48 | * 165 8/21/99 12:33a Jeff |
| 49 | * Changed the name of the GetRealGametime function to |
| 50 | * GetRealGametimePacket since it was confusing some compilers with the |
| 51 | * other GetRealGametime function. |
| 52 | * |
| 53 | * 164 8/15/99 4:36p Jeff |
| 54 | * finished exporting all inventory class functions. export object_info |
| 55 | * array. added check for -nooutragelogo to display Outrage logo display. |
| 56 | * |
| 57 | * 163 8/11/99 6:36p Jeff |
| 58 | * don't set input command list root to NULL when creating input commands |
| 59 | * (it would create a memleak and ignore any ICs added by a custom mod) |
| 60 | * |
| 61 | * 162 8/11/99 1:21p Jeff |
| 62 | * exported needed functions for camera windows |
| 63 | * |
| 64 | * 161 7/30/99 11:59a Jeff |
| 65 | * fixed bug with autobalance being turned off |
| 66 | * |
| 67 | * 160 7/14/99 11:47a Jeff |
| 68 | * localized text for patch fixes |
| 69 | * |
| 70 | * 159 7/13/99 10:05a Jeff |
| 71 | * text taunt token decoding |
| 72 | * |
| 73 | * 158 7/11/99 3:31p Jeff |
| 74 | * exported game arguments, made command line option to specify |
| 75 | * autoexec.dmfc |
| 76 | * |
| 77 | * 157 7/09/99 7:02p Jeff |
| 78 | * put in countdown timer for when a level is about to end |
| 79 | * |
| 80 | * 156 7/09/99 6:17p Jeff |
| 81 | * added $remoteadminlogout and $wait commands |
| 82 | * |
| 83 | * 155 7/09/99 2:53p Jeff |
| 84 | * handle gametime better (pause it when needed) if the server is 'waiting |
| 85 | * for players' |
| 86 | * |
| 87 | * 154 7/08/99 6:25p Jeff |
| 88 | * remote admin in and working |
| 89 | * |
| 90 | * 153 7/08/99 2:39a Jeff |
| 91 | * rough implementation of remote administration checked in. Still needs |
| 92 | * some polishing, but should work basically. |
| 93 | * |
| 94 | * 152 7/07/99 5:00p Jeff |
| 95 | * removed vararg functions from interface functions, just made different |
| 96 | * versions of them |
| 97 | * |
| 98 | * 151 6/11/99 5:36p Jeff |
| 99 | * removed ai_info #ifdefs (better way of doing it) |
| 100 | * |
| 101 | * 150 6/10/99 12:34p Jeff |
| 102 | * GetCounterMeasureOwner doesn't use ->ai_info for non-Outrage versions |
| 103 | * |
| 104 | * 149 6/10/99 11:10a Jeff |
| 105 | * don't display the Outrage logo for non-Outrage games |
| 106 | * |
| 107 | * 148 5/22/99 1:12a Jeff |
| 108 | * correctly handle Viewer_object |
| 109 | * |
| 110 | * 147 5/20/99 5:32p Jeff |
| 111 | * called PlayerStopSounds if respawning a player |
| 112 | * |
| 113 | * 146 5/20/99 3:51p Jeff |
| 114 | * for apply damage to player, server says should be 1 (so it works in |
| 115 | * peer-peer) |
| 116 | * |
| 117 | * 145 5/13/99 4:55p Ardussi |
| 118 | * changes for compiling on the Mac |
| 119 | * |
| 120 | * 144 5/12/99 11:04p Jeff |
| 121 | * dmfc and multiplayer games now have endian friendly packets (*whew*) |
| 122 | * |
| 123 | * 143 5/10/99 2:43a Jeff |
| 124 | * handle new scheme of player's joining in a team game, where the team is |
| 125 | * set before player enters game in the main code, but the team is |
| 126 | * determined via event call to dmfc |
| 127 | * |
| 128 | * 142 5/09/99 6:20a Jeff |
| 129 | * improved Entropy (added sounds, max virii per room). Fixed rendering |
| 130 | * bugs for other multiplayer dlls. |
| 131 | * |
| 132 | * 141 5/08/99 11:06a Jeff |
| 133 | * |
| 134 | * 140 5/07/99 4:34p Jason |
| 135 | * fixed audio taunt icon |
| 136 | * |
| 137 | * 139 5/07/99 12:52p Jeff |
| 138 | * audio taunt icon is ppic if available. coop has hard max team set of 4 |
| 139 | * |
| 140 | * 138 5/04/99 8:46p Jeff |
| 141 | * display icon when someone plays an audio taunt |
| 142 | * |
| 143 | * 137 5/03/99 8:39a Jeff |
| 144 | * fixed apply damage to player |
| 145 | * |
| 146 | * 136 4/30/99 10:52p Jeff |
| 147 | * added $warp command |
| 148 | * |
| 149 | * 135 4/30/99 7:36p Jeff |
| 150 | * exported vis_effects to dmfc |
| 151 | * |
| 152 | * 134 4/27/99 1:56p Jeff |
| 153 | * audio taunts stuff in pilot menu, added stringtables |
| 154 | * |
| 155 | * 133 4/26/99 3:41p Jeff |
| 156 | * put in debug multiplayer command dump to file |
| 157 | * |
| 158 | * 132 4/25/99 7:18p Jeff |
| 159 | * added code to handle suicides in pinfo |
| 160 | * |
| 161 | * 131 4/23/99 6:15p Jeff |
| 162 | * fixed double calls to GameClose |
| 163 | * |
| 164 | * 130 4/23/99 4:49p Jason |
| 165 | * played with loss colors a bit |
| 166 | * |
| 167 | * 129 4/23/99 4:24p Jason |
| 168 | * fixed ping display bug |
| 169 | * |
| 170 | * 128 4/23/99 12:46p Jeff |
| 171 | * lag loss indicator on by default |
| 172 | * |
| 173 | * 127 4/22/99 11:28a Jeff |
| 174 | * changed percent sign as a result of Samir's change |
| 175 | * |
| 176 | * 126 4/21/99 10:35p Jeff |
| 177 | * fixed lag/loss displays |
| 178 | * |
| 179 | * 125 4/20/99 8:57p Jeff |
| 180 | * compile for Linux |
| 181 | * |
| 182 | * 124 4/14/99 3:03p Jeff |
| 183 | * |
| 184 | * 123 4/12/99 11:39a Jeff |
| 185 | * removed movement smoothing, added permissable cs to netgame info |
| 186 | * |
| 187 | * 122 4/04/99 4:55p Jeff |
| 188 | * added functionality to call osiris functions from multiplayer d3ms |
| 189 | * |
| 190 | * 121 4/03/99 4:06p Jeff |
| 191 | * added loss/ping gauge |
| 192 | * |
| 193 | * 120 4/02/99 9:02p Jeff |
| 194 | * fixed crashes if there was an error initializing module |
| 195 | * |
| 196 | * 119 3/30/99 9:01p Jeff |
| 197 | * exported polymodels |
| 198 | * |
| 199 | * 118 3/30/99 7:42p Jeff |
| 200 | * fixed a misspelling on a function name |
| 201 | * |
| 202 | * 117 3/22/99 6:20p Jeff |
| 203 | * added 2 more audio taunts. a mulitplayer event when someone plays an |
| 204 | * audio taunt. option to disable audio taunts. |
| 205 | * |
| 206 | * 116 3/22/99 1:55p Jeff |
| 207 | * make sure initialization happens (possible crashing) |
| 208 | * |
| 209 | * 115 3/17/99 12:23p Jeff |
| 210 | * converted DMFC to be COM interface |
| 211 | * |
| 212 | * 114 3/09/99 1:13p Jeff |
| 213 | * fixed control packet for wait being overflowed out and accidently sent |
| 214 | * by the client |
| 215 | * |
| 216 | * 113 3/05/99 1:29p Jeff |
| 217 | * fixed 99% of the high res issues |
| 218 | * |
| 219 | * 112 3/01/99 8:48p Jeff |
| 220 | * fixed banning bug (when not a master tracker game) |
| 221 | * |
| 222 | * 111 2/25/99 8:54p Jeff |
| 223 | * Inventory supports level change persistant items. Inventory supports |
| 224 | * time-out objects. Inventory Reset changed (takes a level of reset |
| 225 | * now). Quad lasers stay across level change (single player). Guidebot |
| 226 | * bug fixed (now back in ship on level start). Quads time out when |
| 227 | * spewed. Invulnerability and cloak powerups no longer use game |
| 228 | * event/callbacks, so they can be saved in game saves (moved to |
| 229 | * MakePlayerInvulnerable and MakeObjectInvisible) |
| 230 | * |
| 231 | * 110 2/11/99 12:50a Jeff |
| 232 | * changed names of exported variables |
| 233 | * |
| 234 | * 109 2/10/99 1:47p Matt |
| 235 | * Changed object handle symbolic constants |
| 236 | * |
| 237 | * 108 2/09/99 3:32p Jeff |
| 238 | * table file parser takes quotes strings for force keywords |
| 239 | * |
| 240 | * 107 2/07/99 2:06a Jeff |
| 241 | * updated coop...fixed bug when getting countermeasure owner, if owner is |
| 242 | * observer |
| 243 | * |
| 244 | * 106 2/07/99 1:19a Jeff |
| 245 | * added new multiplayer game events EVT_GAMEOBJKILLED and |
| 246 | * EVT_GAMEOBJDESTROYED |
| 247 | * |
| 248 | * 105 2/05/99 8:24p Jeff |
| 249 | * added table file parser macros |
| 250 | * |
| 251 | * 104 2/03/99 4:09p Jeff |
| 252 | * moved function pointers to seperate file. created autoexec.dmfc |
| 253 | * |
| 254 | * 103 2/02/99 8:43a Chris |
| 255 | * I made buildings with AI work correctly (ie really big robots should be |
| 256 | * buildings) |
| 257 | * anim to and from states are now shorts instead of bytes |
| 258 | * |
| 259 | * 102 1/31/99 7:26p Matt |
| 260 | * Renamed a bunch of functions to have HUD capitalized |
| 261 | * |
| 262 | * 101 1/21/99 11:16p Jeff |
| 263 | * exported vecmat functions |
| 264 | * |
| 265 | * 100 1/20/99 8:06p Jeff |
| 266 | * added members into DLLinfo struct for game change segment events, pass |
| 267 | * them over on execute dll packets |
| 268 | * |
| 269 | * 99 1/19/99 5:34p Jeff |
| 270 | * updated monsterball |
| 271 | * |
| 272 | * 98 1/18/99 7:27p Jeff |
| 273 | * localized strings in dmfcbase.cpp |
| 274 | * |
| 275 | * 97 1/17/99 11:52p Jeff |
| 276 | * added some new events, and changed a couple event handlers |
| 277 | * |
| 278 | * 96 1/15/99 8:29p Jeff |
| 279 | * updates to powerball |
| 280 | * |
| 281 | * 95 1/15/99 7:52p Chris |
| 282 | * Updated ObjSetPos() to include a f_update_attach_children flag |
| 283 | * |
| 284 | * 94 1/15/99 3:53a Jeff |
| 285 | * exported a couple more functions. Added event handlers for Weapon |
| 286 | * collide event |
| 287 | * |
| 288 | * 93 1/12/99 2:55p Jeff |
| 289 | * added/finished the waiting for player's to join dialog |
| 290 | * |
| 291 | * 92 1/12/99 11:29a Jason |
| 292 | * fixed a broken externed function |
| 293 | * |
| 294 | * 91 1/07/99 5:01p Jeff |
| 295 | * added Int3's and updated all net games to use stats manager...correctly |
| 296 | * too |
| 297 | * |
| 298 | * 90 1/06/99 7:02p Jeff |
| 299 | * added a multiplayer event for game controls |
| 300 | * |
| 301 | * 89 1/06/99 12:53a Jeff |
| 302 | * put in support for $piggyback and $observer |
| 303 | * |
| 304 | * 88 1/04/99 8:11p Jason |
| 305 | * fixed packet loss tracking problem |
| 306 | * |
| 307 | * 87 1/04/99 2:19p Jeff |
| 308 | * exported table file management functions |
| 309 | * |
| 310 | * 86 1/04/99 12:21p Jeff |
| 311 | * added support for hosts.allow/deny and updates stats manager a little |
| 312 | * |
| 313 | * 85 12/13/98 5:32p Jeff |
| 314 | * fixed ugly crash due to freeing memory allocated in another heap |
| 315 | * |
| 316 | * 84 12/09/98 12:38p Jeff |
| 317 | * removed possible security bug displaying a player's ip address (now |
| 318 | * server only can see it) |
| 319 | * |
| 320 | * 83 12/08/98 4:47p Jeff |
| 321 | * umm, various changes, fixed pilot pics so that they work for everyone |
| 322 | * now |
| 323 | * |
| 324 | * 82 12/08/98 3:29p Jeff |
| 325 | * updated the team control dialog so the server can determine if they |
| 326 | * want to make the clients wait |
| 327 | * |
| 328 | * 81 12/08/98 12:17p Jeff |
| 329 | * various changes that include an improved Team Control dialog (doesn't |
| 330 | * switch teams until exit..) and spew/respawn players that change teams |
| 331 | * |
| 332 | * 80 12/04/98 7:04p Jeff |
| 333 | * almost finished up dmfc stat manager |
| 334 | * |
| 335 | * 79 12/01/98 6:56p Jeff |
| 336 | * put in quick and dirty implementation of pilot pics for testing |
| 337 | * |
| 338 | * 78 11/19/98 5:56p Jeff |
| 339 | * added slider exported and improved Hoard |
| 340 | * |
| 341 | * 77 11/17/98 6:29p Jeff |
| 342 | * mod can specify whether or not to display the team setup dialog on team |
| 343 | * game start. Added a menu item to display team setup dialog in mid-game |
| 344 | * |
| 345 | * 76 11/17/98 12:36p Jeff |
| 346 | * fixed dedicated server detection and display a dprintf for setting new |
| 347 | * team |
| 348 | * |
| 349 | * 75 11/16/98 5:35p Jeff |
| 350 | * removed log functions, added support for changing team names, fixed ctf |
| 351 | * to work better with different team names |
| 352 | * |
| 353 | * 74 11/13/98 6:36p Jeff |
| 354 | * created dmfc_dll (a DLL version of DMFC) and converted current mods to |
| 355 | * use it |
| 356 | * |
| 357 | * 73 11/12/98 12:16p Jeff |
| 358 | * more changes to handle (ignore) dedicated server |
| 359 | * |
| 360 | * 72 11/11/98 7:19p Jeff |
| 361 | * changes made so that a dedicated server's team is always -1 (team game |
| 362 | * or not) |
| 363 | * |
| 364 | * 71 11/02/98 4:38p Jeff |
| 365 | * added ability to sort and display by efficiency |
| 366 | * |
| 367 | * 70 11/01/98 1:59a Jeff |
| 368 | * made a $help inputcommand for help in a dedicated server environment |
| 369 | * |
| 370 | * 69 10/30/98 12:47p Jeff |
| 371 | * cut down a couple bytes on memory usage |
| 372 | * |
| 373 | * 68 10/29/98 7:01p Jeff |
| 374 | * creation of team placement dialog. Moved TranslateEvent into DMFC |
| 375 | * |
| 376 | * 67 10/24/98 2:35p Matt |
| 377 | * Changed "callsign" to "name" or "player name" in the multiplayer menus |
| 378 | * and commands. |
| 379 | * |
| 380 | * 66 10/24/98 2:18p Jeff |
| 381 | * |
| 382 | * 65 10/23/98 6:51p Jeff |
| 383 | * fixed hud num of teams sort in ctf, and memory overwrite in registry |
| 384 | * |
| 385 | * 64 10/23/98 11:22a Jeff |
| 386 | * changes to handle mixcase, and display the client netgame info |
| 387 | * correctly |
| 388 | * |
| 389 | * 63 10/21/98 5:02p Jeff |
| 390 | * removed player from HUD if in observer nide |
| 391 | * |
| 392 | * 62 10/20/98 4:35p Jeff |
| 393 | * added a flag for menu to add a <None> to MIT_PLIST... |
| 394 | * |
| 395 | * 61 10/20/98 12:16p Jeff |
| 396 | * added death message filter, hud callsign filter |
| 397 | * |
| 398 | * 60 10/19/98 7:19p Matt |
| 399 | * Added system to support different types of damage to the player and |
| 400 | * have these different types make different sounds. |
| 401 | * |
| 402 | * 59 10/18/98 7:59p Jeff |
| 403 | * functions added to dmfc for client->server objnum matching. Banning |
| 404 | * now uses tracker id when available. |
| 405 | * |
| 406 | * 58 10/17/98 7:30p Jeff |
| 407 | * network_address compares don't compare port on somethings |
| 408 | * |
| 409 | * 57 10/15/98 6:18p Jeff |
| 410 | * created the is player banned event, removed prejoin event |
| 411 | * |
| 412 | * 56 10/15/98 1:34p Jeff |
| 413 | * added scrollable onscreen menu. Remove ban in dmfc. prejoin event |
| 414 | * |
| 415 | * 55 10/13/98 6:01p Jeff |
| 416 | * added attaching |
| 417 | * |
| 418 | * 54 10/13/98 2:15a Jeff |
| 419 | * created new event for when a player leaves a multiplayer game. Fixed |
| 420 | * some 'english' bugs in the network games. |
| 421 | * |
| 422 | * 53 10/08/98 3:37p Jeff |
| 423 | * general improvements (Netgame info things, save to registry). Changes |
| 424 | * so it would send packets on NETSEQ_OBJECTS |
| 425 | * |
| 426 | * 51 10/05/98 2:49p Jeff |
| 427 | * |
| 428 | * 50 10/02/98 6:10p Jeff |
| 429 | * |
| 430 | * 49 10/01/98 11:30a Jeff |
| 431 | * made the observer mode events into just a client event |
| 432 | * |
| 433 | * 48 9/30/98 4:21p Jeff |
| 434 | * team changing is handled correctly |
| 435 | * |
| 436 | * 47 9/30/98 3:50p Jeff |
| 437 | * general improvements (many) |
| 438 | * |
| 439 | * 46 9/29/98 3:04p Jeff |
| 440 | * added time in game and start_time support |
| 441 | * |
| 442 | * 45 9/28/98 5:05p Jeff |
| 443 | * made the statisitical death messages an option in the menu |
| 444 | * |
| 445 | * 44 9/25/98 7:25p Jeff |
| 446 | * |
| 447 | * 43 9/25/98 4:50p Jeff |
| 448 | * |
| 449 | * 42 9/24/98 6:54p Jeff |
| 450 | * added DisconnectMe() and made use of it when you get kicked/banned |
| 451 | * |
| 452 | * 41 9/24/98 6:29p Jeff |
| 453 | * |
| 454 | * 40 9/24/98 5:52p Jeff |
| 455 | * starting adding statistical death messages, checked in for testing |
| 456 | * |
| 457 | * 39 9/23/98 5:27p Jeff |
| 458 | * fixed death message bug (using objnum instead of pnum) |
| 459 | * |
| 460 | * 38 9/23/98 4:17p Jeff |
| 461 | * basic changes/improvements, started changing death messages |
| 462 | * |
| 463 | * 37 9/21/98 7:11p Jeff |
| 464 | * made InputCommand interface API and moved existing input commands to |
| 465 | * the interface. Changed mprintf/ASSERT so they are valid in DMFC |
| 466 | * |
| 467 | * $NoKeywords: $ |
| 468 | */ |
| 469 | |
| 470 | #include "gamedll_header.h" |
| 471 | #include "DMFC.h" |
| 472 | #include "dmfcinternal.h" |
| 473 | #include "dmfcinputcommands.h" |
| 474 | |
| 475 | #include <stdlib.h> |
| 476 | #include <stdarg.h> |
| 477 | #include <algorithm> |
| 478 | |
| 479 | char **DMFCStringTable; |
| 480 | int DMFCStringTableSize = 0; |
| 481 | const char *_DMFCErrorString = "DMFC Missing String"; |
| 482 | uint8_t seeds1[31] = {49, 73, 0, 44, 87, 253, 35, 74, 62, 250, 4, 247, 251, 72, 244, 30, |
| 483 | 59, 61, 60, 52, 50, 237, 23, 48, 56, 55, 65, 232, 231, 230, 0}; |
| 484 | uint8_t seeds2[6] = {70, 95, 103, 102, 112, 0}; |
| 485 | |
| 486 | const char *DMFCGetString(int d) { |
| 487 | if ((d < 0) || (d >= DMFCStringTableSize)) |
| 488 | return _DMFCErrorString; |
| 489 | else |
| 490 | return DMFCStringTable[d]; |
| 491 | } |
| 492 | |
| 493 | DMFCBase::DMFCBase(void) { |
| 494 | m_cPtrs = 0; |
| 495 | |
| 496 | m_iServerHUDCallsignLevel = HUD_CALLSIGN_LEVEL_FULL; |
| 497 | m_iMyCurrentHUDCallsignLevel = m_iMyPreferredHUDCallsignLevel = HUD_CALLSIGN_LEVEL_FULL; |
| 498 | m_iProtectedFlags = 0; |
| 499 | m_bHasInitialized = false; |
| 500 | LossGuageEnabled = true; |
| 501 | DMFCInit = false; |
| 502 | RealGametime = 0; |
| 503 | DedicatedLevelWait = 0; |
| 504 | m_bDisplayTimelimitCountdown = true; |
| 505 | m_iTimeLimitCountdown = 10; |
| 506 | |
| 507 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PLRFIRSTTIME | DMFC_PRF_CANTEAMCHANGE); |
| 508 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVELEVELEND); |
| 509 | ENABLE_FLAGS(m_iProtectedFlags, |
| 510 | DMFC_PRF_AUTOTIMELIMIT | DMFC_PRF_AUTODEATHMSG | DMFC_PRF_AUTOTEAMSELECT | DMFC_PRF_DISPSTATHUDMSGS); |
| 511 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_INOPTIONS | DMFC_PRF_DISPPLAYERINFO | DMFC_PRF_DISPNETGAMEINFO); |
| 512 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVEDISC | DMFC_PRF_DISPMENUBACKGR | DMFC_PRF_PAUSETIME); |
| 513 | |
| 514 | m_iNumBanPlayers = 0; |
| 515 | m_bMakeClientsWait = false; |
| 516 | m_iPlayerDisplayed = 0; |
| 517 | |
| 518 | DatabaseRegisteredName[0] = '\0'; |
| 519 | |
| 520 | SPRoot = NULL; // no special packet handlers yet |
| 521 | |
| 522 | int i; |
| 523 | |
| 524 | for (i = 0; i < MAX_DEATH_MSGS; i++) { |
| 525 | DeathMsgs[i].inuse = false; |
| 526 | DeathMsgs[i].message = NULL; |
| 527 | SuicideMsgs[i].inuse = false; |
| 528 | SuicideMsgs[i].message = NULL; |
| 529 | } |
| 530 | |
| 531 | for (i = 0; i < MAX_WEAPONS; i++) { |
| 532 | WeaponMessages[i].inuse = false; |
| 533 | WeaponMessages[i].message = NULL; |
| 534 | WeaponHash[i] = -1; |
| 535 | } |
| 536 | |
| 537 | m_iDeathMsgCount = 0; |
| 538 | m_iSuicideMsgCount = 0; |
| 539 | m_iUIWindowID = -1; |
| 540 | m_UIUserData = NULL; |
| 541 | |
| 542 | m_DenyList = NULL; |
| 543 | m_AllowList = NULL; |
| 544 | m_InputCommandRootNode = NULL; |
| 545 | Hard_max_players = DLLMAX_PLAYERS; |
| 546 | |
| 547 | DecryptData(seeds2, 5); |
| 548 | |
| 549 | TeamMenuItem = NULL; |
| 550 | AutoBalanceItem = NULL; |
| 551 | AllowTeamChangeItem = NULL; |
| 552 | ObserverItem = NULL; |
| 553 | m_BanList = NULL; |
| 554 | StatisticMessagesItem = NULL; |
| 555 | SaveStatsLevelEndItem = NULL; |
| 556 | SaveStatsDisconnectItem = NULL; |
| 557 | NetGameInfoItem = NULL; |
| 558 | MenuBackgroundItem = NULL; |
| 559 | ServerHUDCallsignsItem = NULL; |
| 560 | HUDCallsignsItem = NULL; |
| 561 | DeathMessageFilterItem = NULL; |
| 562 | ShipLogosItem = NULL; |
| 563 | HUDIndicatorItem = NULL; |
| 564 | |
| 565 | DisplayTauntIndicator = false; |
| 566 | TauntIndicatorPlayerNum = -1; |
| 567 | TauntIndicatorStartTime = 0; |
| 568 | TauntIndicatorBMP = -1; |
| 569 | |
| 570 | for (i = 0; i < DLLMAX_TEAMS; i++) |
| 571 | DMFC_team_names[i][0] = '\0'; |
| 572 | |
| 573 | for (i = 0; i < DLLMAX_PLAYERS; i++) { |
| 574 | PilotPicBmpHandles[i] = BAD_BITMAP_HANDLE; |
| 575 | } |
| 576 | |
| 577 | InitializeVirtualHandles(); |
| 578 | } |
| 579 | |
| 580 | DMFCBase::~DMFCBase(void) { |
| 581 | int i; |
| 582 | |
| 583 | ResetPInfo(); |
| 584 | |
| 585 | RemoveAllBans(); |
| 586 | |
| 587 | for (i = 0; i < DLLMAX_PLAYERS; i++) { |
| 588 | if (PilotPicBmpHandles[i] > BAD_BITMAP_HANDLE) { |
| 589 | DLLbm_FreeBitmap(PilotPicBmpHandles[i]); |
| 590 | PilotPicBmpHandles[i] = BAD_BITMAP_HANDLE; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | if (TauntIndicatorBMP > BAD_BITMAP_HANDLE) { |
| 595 | DLLbm_FreeBitmap(TauntIndicatorBMP); |
| 596 | TauntIndicatorBMP = BAD_BITMAP_HANDLE; |
| 597 | } |
| 598 | |
| 599 | for (i = 0; i < MAX_DEATH_MSGS; i++) { |
| 600 | if (DeathMsgs[i].inuse) { |
| 601 | if (DeathMsgs[i].message) |
| 602 | free(DeathMsgs[i].message); |
| 603 | DeathMsgs[i].inuse = false; |
| 604 | } |
| 605 | if (SuicideMsgs[i].inuse) { |
| 606 | if (SuicideMsgs[i].message) |
| 607 | free(SuicideMsgs[i].message); |
| 608 | SuicideMsgs[i].inuse = false; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | for (i = 0; i < MAX_WEAPONS; i++) { |
| 613 | if (WeaponMessages[i].inuse) { |
| 614 | if (WeaponMessages[i].message) { |
| 615 | free(WeaponMessages[i].message); |
| 616 | WeaponMessages[i].message = NULL; |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | // remove all the special packet handlers |
| 622 | tSPHandler *current, *next; |
| 623 | current = next = SPRoot; |
| 624 | while (current) { |
| 625 | next = current->next; |
| 626 | free(current); |
| 627 | current = next; |
| 628 | } |
| 629 | SPRoot = NULL; |
| 630 | } |
| 631 | |
| 632 | // ##################Setup and processing functions####################### |
| 633 | |
| 634 | // DMFCBase::InitializeForLevel |
| 635 | // |
| 636 | // |
| 637 | void DMFCBase::InitializeForLevel(void) { |
| 638 | if (m_bHasInitialized) |
| 639 | return; |
| 640 | |
| 641 | // Reset the timers |
| 642 | InitTimers(); |
| 643 | |
| 644 | m_bHasInitialized = true; |
| 645 | } |
| 646 | |
| 647 | // DMFCBase::LoadSettings |
| 648 | // |
| 649 | // Loads the settings of DMFC from the registry and initializes those variables |
| 650 | void DMFCBase::LoadSettings(void) { |
| 651 | // set default values |
| 652 | ENABLE_FLAGS(m_iProtectedFlags, |
| 653 | DMFC_PRF_AUTOTIMELIMIT | DMFC_PRF_AUTODEATHMSG | DMFC_PRF_AUTOTEAMSELECT | DMFC_PRF_DISPSTATHUDMSGS); |
| 654 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVELEVELEND | DMFC_PRF_CANTEAMCHANGE); |
| 655 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVEDISC | DMFC_PRF_DISPMENUBACKGR); |
| 656 | m_iServerHUDCallsignLevel = HUD_CALLSIGN_LEVEL_FULL; |
| 657 | m_iMyCurrentHUDCallsignLevel = m_iMyPreferredHUDCallsignLevel = HUD_CALLSIGN_LEVEL_FULL; |
| 658 | m_iDeathMessageFilter = DM_FILTER_FULL; |
| 659 | LossGuageEnabled = true; |
| 660 | |
| 661 | bool bTemp; |
| 662 | |
| 663 | if (DatabaseRead3("DMFCAutoTimeLimit", &bTemp)) { |
| 664 | if (bTemp) |
| 665 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOTIMELIMIT); |
| 666 | else |
| 667 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOTIMELIMIT); |
| 668 | } |
| 669 | |
| 670 | if (DatabaseRead3("DMFCAutoDeathMessage", &bTemp)) { |
| 671 | if (bTemp) |
| 672 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTODEATHMSG); |
| 673 | else |
| 674 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTODEATHMSG); |
| 675 | } |
| 676 | |
| 677 | if (DatabaseRead3("DMFCAutoTeamSelect", &bTemp)) { |
| 678 | if (bTemp) |
| 679 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOTEAMSELECT); |
| 680 | else |
| 681 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOTEAMSELECT); |
| 682 | } |
| 683 | |
| 684 | if (DatabaseRead3("DMFCStatHUDMessages", &bTemp)) { |
| 685 | if (bTemp) |
| 686 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPSTATHUDMSGS); |
| 687 | else |
| 688 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPSTATHUDMSGS); |
| 689 | } |
| 690 | |
| 691 | if (DatabaseRead3("DMFCAutoSaveStatLevelEnd", &bTemp)) { |
| 692 | if (bTemp) |
| 693 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVELEVELEND); |
| 694 | else |
| 695 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVELEVELEND); |
| 696 | } |
| 697 | |
| 698 | if (DatabaseRead3("DMFCAutoSaveStatDisconnect", &bTemp)) { |
| 699 | if (bTemp) |
| 700 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVEDISC); |
| 701 | else |
| 702 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVEDISC); |
| 703 | } |
| 704 | |
| 705 | if (DatabaseRead3("DMFCMenuBackground", &bTemp)) { |
| 706 | if (bTemp) |
| 707 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPMENUBACKGR); |
| 708 | else |
| 709 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPMENUBACKGR); |
| 710 | } |
| 711 | |
| 712 | if (DatabaseRead3("DMFCCanChangeTeams", &bTemp)) { |
| 713 | if (bTemp) |
| 714 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_CANTEAMCHANGE); |
| 715 | else |
| 716 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_CANTEAMCHANGE); |
| 717 | } |
| 718 | |
| 719 | DatabaseRead3("DMFCLagLossIndicator", &LossGuageEnabled); |
| 720 | |
| 721 | DatabaseRead2("DMFCShowHudCallsigns", &m_iMyPreferredHUDCallsignLevel, sizeof(m_iMyPreferredHUDCallsignLevel)); |
| 722 | DatabaseRead2("DMFCServerShowHudCallsigns", &m_iServerHUDCallsignLevel, sizeof(m_iServerHUDCallsignLevel)); |
| 723 | DatabaseRead2("DMFCDeathMessageFilter", &m_iDeathMessageFilter, sizeof(m_iDeathMessageFilter)); |
| 724 | |
| 725 | m_iMyCurrentHUDCallsignLevel = m_iMyPreferredHUDCallsignLevel; |
| 726 | } |
| 727 | |
| 728 | // DMFCBase::SaveSettings |
| 729 | // |
| 730 | // Saves out the settings of DMFC to the registry |
| 731 | void DMFCBase::SaveSettings(void) { |
| 732 | bool bTemp; |
| 733 | |
| 734 | bTemp = (bool)((m_iProtectedFlags & DMFC_PRF_AUTOTIMELIMIT) != 0); |
| 735 | DatabaseWrite2("DMFCAutoTimeLimit", bTemp); |
| 736 | |
| 737 | bTemp = (bool)((m_iProtectedFlags & DMFC_PRF_AUTODEATHMSG) != 0); |
| 738 | DatabaseWrite2("DMFCAutoDeathMessage", bTemp); |
| 739 | |
| 740 | bTemp = (bool)((m_iProtectedFlags & DMFC_PRF_AUTOTEAMSELECT) != 0); |
| 741 | DatabaseWrite2("DMFCAutoTeamSelect", bTemp); |
| 742 | |
| 743 | bTemp = (bool)((m_iProtectedFlags & DMFC_PRF_DISPSTATHUDMSGS) != 0); |
| 744 | DatabaseWrite2("DMFCStatHUDMessages", bTemp); |
| 745 | |
| 746 | bTemp = (bool)((m_iProtectedFlags & DMFC_PRF_AUTOSAVELEVELEND) != 0); |
| 747 | DatabaseWrite2("DMFCAutoSaveStatLevelEnd", bTemp); |
| 748 | |
| 749 | bTemp = (bool)((m_iProtectedFlags & DMFC_PRF_AUTOSAVEDISC) != 0); |
| 750 | DatabaseWrite2("DMFCAutoSaveStatDisconnect", bTemp); |
| 751 | |
| 752 | bTemp = (bool)((m_iProtectedFlags & DMFC_PRF_DISPMENUBACKGR) != 0); |
| 753 | DatabaseWrite2("DMFCMenuBackground", bTemp); |
| 754 | |
| 755 | bTemp = (bool)((m_iProtectedFlags & DMFC_PRF_CANTEAMCHANGE) != 0); |
| 756 | DatabaseWrite2("DMFCCanChangeTeams", bTemp); |
| 757 | |
| 758 | DatabaseWrite2("DMFCLagLossIndicator", LossGuageEnabled); |
| 759 | |
| 760 | DatabaseWrite2("DMFCShowHudCallsigns", m_iMyPreferredHUDCallsignLevel); |
| 761 | DatabaseWrite2("DMFCServerShowHudCallsigns", m_iServerHUDCallsignLevel); |
| 762 | DatabaseWrite2("DMFCDeathMessageFilter", m_iDeathMessageFilter); |
| 763 | } |
| 764 | |
| 765 | // DMFCBase::LoadFunctions |
| 766 | // |
| 767 | // Initialized all the functions for a multiplayer game...must be first thing called |
| 768 | void DMFCBase::LoadFunctions(int *api_func) { |
| 769 | DLLGetGameAPI = (GetGameAPI_fp)api_func; |
| 770 | DLLGetGameAPI(&API); |
| 771 | |
| 772 | Objects = (object *)API.objs; |
| 773 | Rooms = (room *)API.rooms; |
| 774 | Terrain_seg = (terrain_segment *)API.terrain; |
| 775 | Players = (player *)API.players; |
| 776 | Netgame = (netgame_info *)API.netgame; |
| 777 | NetPlayers = (netplayer *)API.netplayers; |
| 778 | Ships = (ship *)API.ships; |
| 779 | Weapons = (weapon *)API.weapons; |
| 780 | Current_mission = (tMission *)API.Current_mission; |
| 781 | GameTextures = (texture *)API.GameTextures; |
| 782 | GameVClips = (vclip *)API.GameVClips; |
| 783 | |
| 784 | // Do functions, variables |
| 785 | // Note, these must match the ordering on the D3 side (Game2DLL.cpp) |
| 786 | DLLAddHUDMessage = (AddHUDMessage_fp)API.fp[0]; |
| 787 | DLLMultiSendClientExecuteDLL = (MultiSendClientExecuteDLL_fp)API.fp[1]; |
| 788 | DLLFindObjectIDName = (FindObjectIDName_fp)API.fp[2]; |
| 789 | DLLGetGoalRoomForTeam = (GetGoalRoomForTeam_fp)API.fp[3]; |
| 790 | DLLSetMaxTeams = (SetMaxTeams_fp)API.fp[4]; |
| 791 | DLLComputeRoomCenter = (ComputeRoomCenter_fp)API.fp[5]; |
| 792 | DLLObjCreate = (ObjCreate_fp)API.fp[6]; |
| 793 | DLLMultiSendObject = (MultiSendObject_fp)API.fp[7]; |
| 794 | DLLMultiPaintGoalRooms = (MultiPaintGoalRooms_fp)API.fp[8]; |
| 795 | DLLMultiSendSpecialPacket = (MultiSendSpecialPacket_fp)API.fp[9]; |
| 796 | DLLIncTeamScore = (IncTeamScore_fp)API.fp[10]; |
| 797 | DLLDebug_ConsolePrintf = (Debug_ConsolePrintf_fp)API.fp[11]; |
| 798 | DLLObjSetPosNoMark = (ObjSetPosNoMark_fp)API.fp[12]; |
| 799 | DLLInvCheckItem = (InvCheckItem_fp)API.fp[13]; |
| 800 | DLLInvAddTypeID = (InvAddTypeID_fp)API.fp[14]; |
| 801 | DLLInvRemove = (InvRemove_fp)API.fp[15]; |
| 802 | DLLPlayerSetLighting = (PlayerSetLighting_fp)API.fp[16]; |
| 803 | DLLFindShipName = (FindShipName_fp)API.fp[17]; |
| 804 | DLLPlayerSetRotatingBall = (PlayerSetRotatingBall_fp)API.fp[18]; |
| 805 | DLLPlayerChangeShip = (PlayerChangeShip_fp)API.fp[19]; |
| 806 | DLLInvGetTypeIDCount = (InvGetTypeIDCount_fp)API.fp[20]; |
| 807 | DLLPlay3dSound = (D3W_Play3dSound_fp)API.fp[21]; |
| 808 | DLLFindSoundName = (FindSoundName_fp)API.fp[22]; |
| 809 | DLLSpewCreate = (SpewCreate_fp)API.fp[23]; |
| 810 | DLLSpewClearEvent = (SpewClearEvent_fp)API.fp[24]; |
| 811 | DLLbm_AllocLoadFileBitmap = (bm_AllocLoadFileBitmap_fp)API.fp[25]; |
| 812 | DLLbm_FreeBitmap = (bm_FreeBitmap_fp)API.fp[26]; |
| 813 | DLLrend_DrawScaledBitmap = (rend_DrawScaledBitmap_fp)API.fp[27]; |
| 814 | DLLgrtext_Printf = (grtext_Printf_fp)API.fp[28]; |
| 815 | DLLgrtext_Flush = (grtext_Flush_fp)API.fp[29]; |
| 816 | DLLgrtext_SetColor = (grtext_SetColor_fp)API.fp[30]; |
| 817 | DLLgrtext_SetFancyColor = (grtext_SetFancyColor_fp)API.fp[31]; |
| 818 | DLLgrtext_SetAlpha = (grtext_SetAlpha_fp)API.fp[32]; |
| 819 | DLLgrtext_GetAlpha = (grtext_GetAlpha_fp)API.fp[33]; |
| 820 | DLLgrtext_SetFont = (grtext_SetFont_fp)API.fp[34]; |
| 821 | DLLgrtext_GetFont = (grtext_GetFont_fp)API.fp[35]; |
| 822 | DLLgrtext_GetTextLineWidth = (grtext_GetTextLineWidth_fp)API.fp[36]; |
| 823 | DLLgrfont_GetHeight = (grfont_GetHeight_fp)API.fp[37]; |
| 824 | DLLgrtext_CenteredPrintf = (grtext_CenteredPrintf_fp)API.fp[38]; |
| 825 | DLLAddColoredHUDMessage = (AddColoredHUDMessage_fp)API.fp[39]; |
| 826 | DLLbm_w = (bm_w_fp)API.fp[40]; |
| 827 | DLLbm_h = (bm_h_fp)API.fp[41]; |
| 828 | DLLrend_DrawSimpleBitmap = (rend_DrawSimpleBitmap_fp)API.fp[42]; |
| 829 | DLLMultiClientSendSpecialPacket = (MultiClientSendSpecialPacket_fp)API.fp[43]; |
| 830 | DLLAddBlinkingHUDMessage = (AddBlinkingHUDMessage_fp)API.fp[44]; |
| 831 | DLLInvReset = (InvReset_fp)API.fp[45]; |
| 832 | DLLAddHUDItem = (AddHUDItem_fp)API.fp[46]; |
| 833 | DLLRenderHUDQuad = (RenderHUDQuad_fp)API.fp[47]; |
| 834 | DLLRenderHUDText = (RenderHUDText_fp)API.fp[48]; |
| 835 | DLLMultiEndLevel = (MultiEndLevel_fp)API.fp[49]; |
| 836 | DLLbm_data = (bm_data_fp)API.fp[50]; |
| 837 | DLLbm_AllocBitmap = (bm_AllocBitmap_fp)API.fp[51]; |
| 838 | DLLrend_FillRect = (rend_FillRect_fp)API.fp[52]; |
| 839 | DLLbm_CreateChunkedBitmap = (bm_CreateChunkedBitmap_fp)API.fp[53]; |
| 840 | DLLbm_DestroyChunkedBitmap = (bm_DestroyChunkedBitmap_fp)API.fp[54]; |
| 841 | DLLrend_DrawChunkedBitmap = (rend_DrawChunkedBitmap_fp)API.fp[55]; |
| 842 | DLLrend_DrawScaledChunkedBitmap = (rend_DrawScaledChunkedBitmap_fp)API.fp[56]; |
| 843 | DLLOpenCFILE = (OpenCFILE_fp)API.fp[57]; |
| 844 | DLLcfclose = (cfclose_fp)API.fp[58]; |
| 845 | DLLcfeof = (cfeof_fp)API.fp[59]; |
| 846 | DLLcfexist = (cfexist_fp)API.fp[60]; |
| 847 | DLLcf_ReadBytes = (cf_ReadBytes_fp)API.fp[61]; |
| 848 | DLLcf_ReadInt = (cf_ReadInt_fp)API.fp[62]; |
| 849 | DLLcf_ReadShort = (cf_ReadShort_fp)API.fp[63]; |
| 850 | DLLcf_ReadByte = (cf_ReadByte_fp)API.fp[64]; |
| 851 | DLLcf_ReadFloat = (cf_ReadFloat_fp)API.fp[65]; |
| 852 | DLLcf_ReadDouble = (cf_ReadDouble_fp)API.fp[66]; |
| 853 | DLLcf_ReadString = (cf_ReadString_fp)API.fp[67]; |
| 854 | DLLcf_WriteBytes = (cf_WriteBytes_fp)API.fp[68]; |
| 855 | DLLcf_WriteString = (cf_WriteString_fp)API.fp[69]; |
| 856 | DLLcf_WriteInt = (cf_WriteInt_fp)API.fp[70]; |
| 857 | DLLcf_WriteShort = (cf_WriteShort_fp)API.fp[71]; |
| 858 | DLLcf_WriteByte = (cf_WriteByte_fp)API.fp[72]; |
| 859 | DLLcf_WriteFloat = (cf_WriteFloat_fp)API.fp[73]; |
| 860 | DLLcf_WriteDouble = (cf_WriteDouble_fp)API.fp[74]; |
| 861 | DLLcf_CopyFile = (cf_CopyFile_fp)API.fp[75]; |
| 862 | DLLcf_Diff = (cf_Diff_fp)API.fp[76]; |
| 863 | DLLMultiDisconnectPlayer = (MultiDisconnectPlayer_fp)API.fp[77]; |
| 864 | DLLnw_GetNumbersFromHostAddress = (nw_GetNumbersFromHostAddress_fp)API.fp[78]; |
| 865 | DLLnw_GetThisIP = (nw_GetThisIP_fp)API.fp[79]; |
| 866 | DLLCreateStringTable = (CreateStringTable_fp)API.fp[80]; |
| 867 | DLLDestroyStringTable = (DestroyStringTable_fp)API.fp[81]; |
| 868 | DLLRenderHUDTextFlags = (RenderHUDTextFlags_fp)API.fp[82]; |
| 869 | DLLPlayerSpewInventory = (PlayerSpewInventory_fp)API.fp[83]; |
| 870 | DLLPlayerSetHUDNameFOV = (PlayerSetHUDNameFOV_fp)API.fp[84]; |
| 871 | DLLGetUltimateParentForObject = (GetUltimateParentForObject_fp)API.fp[85]; |
| 872 | DLLSetObjectDeadFlagRaw = (SetObjectDeadFlagRaw_fp)API.fp[86]; |
| 873 | FatalError = (DLLFatalError_fp)API.fp[87]; |
| 874 | DLLassert = (assertdll_fp)API.fp[88]; |
| 875 | DLLMultiMatchWeapon = (MultiMatchWeapon_fp)API.fp[89]; |
| 876 | DLLMultiGetMatchChecksum = (MultiGetMatchChecksum_fp)API.fp[90]; |
| 877 | DLLFindWeaponName = (FindWeaponName_fp)API.fp[91]; |
| 878 | DLLcf_OpenLibrary = (cf_OpenLibrary_fp)API.fp[92]; |
| 879 | DLLcf_CloseLibrary = (cf_CloseLibrary_fp)API.fp[93]; |
| 880 | DLLMultiSendRequestToObserve = (MultiSendRequestToObserve_fp)API.fp[94]; |
| 881 | DLLFindTextureName = (FindTextureName_fp)API.fp[95]; |
| 882 | DLLApplyDamageToPlayer = (ApplyDamageToPlayer_fp)API.fp[96]; |
| 883 | DLLMultiMatchGeneric = (MultiMatchGeneric_fp)API.fp[97]; |
| 884 | DLLSetUITextItemText = (SetUITextItemText_fp)API.fp[98]; |
| 885 | DLLNewUIWindowCreate = (NewUIWindowCreate_fp)API.fp[99]; |
| 886 | DLLNewUIWindowDestroy = (NewUIWindowDestroy_fp)API.fp[100]; |
| 887 | DLLNewUIWindowOpen = (NewUIWindowOpen_fp)API.fp[101]; |
| 888 | DLLNewUIWindowClose = (NewUIWindowClose_fp)API.fp[102]; |
| 889 | DLLTextCreate = (TextCreate_fp)API.fp[103]; |
| 890 | DLLEditCreate = (EditCreate_fp)API.fp[104]; |
| 891 | DLLButtonCreate = (ButtonCreate_fp)API.fp[105]; |
| 892 | DLLListCreate = (ListCreate_fp)API.fp[106]; |
| 893 | DLLListRemoveAll = (ListRemoveAll_fp)API.fp[107]; |
| 894 | DLLListAddItem = (ListAddItem_fp)API.fp[108]; |
| 895 | DLLListRemoveItem = (ListRemoveItem_fp)API.fp[109]; |
| 896 | DLLListSelectItem = (ListSelectItem_fp)API.fp[110]; |
| 897 | DLLListGetItem = (ListGetItem_fp)API.fp[111]; |
| 898 | DLLListGetSelectedIndex = (ListGetSelectedIndex_fp)API.fp[112]; |
| 899 | DLLEditSetText = (EditSetText_fp)API.fp[113]; |
| 900 | DLLEditGetText = (EditGetText_fp)API.fp[114]; |
| 901 | DLLDoUI = (DoUI_fp)API.fp[115]; |
| 902 | DLLDoMessageBox = (DoMessageBox_fp)API.fp[116]; |
| 903 | DLLDescentDefer = (DescentDefer_fp)API.fp[117]; |
| 904 | DLLNewUIGameWindowCreate = (NewUIGameWindowCreate_fp)API.fp[118]; |
| 905 | DLLNewUIGameWindowDestroy = (NewUIGameWindowDestroy_fp)API.fp[119]; |
| 906 | DLLNewUIGameWindowOpen = (NewUIGameWindowOpen_fp)API.fp[120]; |
| 907 | DLLNewUIGameWindowClose = (NewUIGameWindowClose_fp)API.fp[121]; |
| 908 | DLLHotSpotCreate = (HotSpotCreate_fp)API.fp[122]; |
| 909 | DLLPollUI = (PollUI_fp)API.fp[123]; |
| 910 | DLLRemoveUITextItem = (RemoveUITextItem_fp)API.fp[124]; |
| 911 | DLLCreateNewUITextItem = (CreateNewUITextItem_fp)API.fp[125]; |
| 912 | DLLUIConsoleGadgetCreate = (UIConsoleGadgetCreate_fp)API.fp[126]; |
| 913 | DLLUIConsoleGadgetputs = (UIConsoleGadgetputs_fp)API.fp[127]; |
| 914 | DLLNewUIWindowSetFocusOnEditGadget = (NewUIWindowSetFocusOnEditGadget_fp)API.fp[128]; |
| 915 | DLLOldEditCreate = (OldEditCreate_fp)API.fp[129]; |
| 916 | DLLOldListCreate = (OldListCreate_fp)API.fp[130]; |
| 917 | DLLOldListRemoveAll = (OldListRemoveAll_fp)API.fp[131]; |
| 918 | DLLOldListAddItem = (OldListAddItem_fp)API.fp[132]; |
| 919 | DLLOldListRemoveItem = (OldListRemoveItem_fp)API.fp[133]; |
| 920 | DLLOldListSelectItem = (OldListSelectItem_fp)API.fp[134]; |
| 921 | DLLOldListGetItem = (OldListGetItem_fp)API.fp[135]; |
| 922 | DLLOldListGetSelectedIndex = (OldListGetSelectedIndex_fp)API.fp[136]; |
| 923 | DLLOldEditSetText = (OldEditSetText_fp)API.fp[137]; |
| 924 | DLLOldEditGetText = (OldEditGetText_fp)API.fp[138]; |
| 925 | DLLToggleUICallback = (ToggleUICallback_fp)API.fp[139]; |
| 926 | DLLSetOldEditBufferLen = (SetOldEditBufferLen_fp)API.fp[140]; |
| 927 | DLLNewUIWindowLoadBackgroundImage = (NewUIWindowLoadBackgroundImage_fp)API.fp[141]; |
| 928 | DLLDeleteUIItem = (DeleteUIItem_fp)API.fp[142]; |
| 929 | DLLHotSpotSetStates = (HotSpotSetStates_fp)API.fp[143]; |
| 930 | DLLSetUICallback = (SetUICallback_fp)API.fp[144]; |
| 931 | DLLGetUICallback = (RetrieveUICallback_fp)API.fp[145]; |
| 932 | DLLSuspendControls = (SuspendControls_fp)API.fp[146]; |
| 933 | DLLResumeControls = (ResumeControls_fp)API.fp[147]; |
| 934 | DLLShowCursor = (ui_ShowCursor_fp)API.fp[148]; |
| 935 | DLLHideCursor = (ui_HideCursor_fp)API.fp[149]; |
| 936 | DLLGameFrame = (GameFrame_fp)API.fp[150]; |
| 937 | DPrintf = (DPrintf_fp)API.fp[151]; |
| 938 | DLLddio_MakePath = (ddio_MakePath_fp)API.fp[152]; |
| 939 | DLLddio_SplitPath = (ddio_SplitPath_fp)API.fp[153]; |
| 940 | DLLPlay2dSound = (Play2dSound_fp)API.fp[154]; |
| 941 | DLLTouchSound = (TouchSound_fp)API.fp[155]; |
| 942 | DatabaseRead1 = (dDatabaseRead_fp1)API.fp[156]; |
| 943 | DatabaseRead2 = (dDatabaseRead_fp2)API.fp[157]; |
| 944 | DatabaseRead3 = (dDatabaseRead_fp3)API.fp[158]; |
| 945 | DatabaseWrite1 = (dDatabaseWrite_fp1)API.fp[159]; |
| 946 | DatabaseWrite2 = (dDatabaseWrite_fp2)API.fp[160]; |
| 947 | DLLAttachObject = (AttachObject_fp)API.fp[161]; |
| 948 | DLLObjGet = (ObjGet_fp)API.fp[162]; |
| 949 | DLLListSetSelectedIndex = (ListSetSelectedIndex_fp)API.fp[163]; |
| 950 | DLLRemoveUIBmpItem = (RemoveUIBmpItem_fp)API.fp[164]; |
| 951 | DLLCreateNewUIBmpItem = (CreateNewUIBmpItem_fp)API.fp[165]; |
| 952 | DLLGetUIItemWidth = (GetUIItemWidth_fp)API.fp[166]; |
| 953 | DLLGetUIItemHeight = (GetUIItemHeight_fp)API.fp[167]; |
| 954 | DLLSliderCreate = (SliderCreate_fp)API.fp[168]; |
| 955 | DLLSliderSetRange = (SliderSetRange_fp)API.fp[169]; |
| 956 | DLLSliderGetRange = (SliderGetRange_fp)API.fp[170]; |
| 957 | DLLSliderSetPos = (SliderSetPos_fp)API.fp[171]; |
| 958 | DLLSliderGetPos = (SliderGetPos_fp)API.fp[172]; |
| 959 | DLLSliderSetSelectChangeCallback = (SliderSetSelectChangeCallback_fp)API.fp[173]; |
| 960 | DLLSliderSetSelectChangeCallbackWData = (SliderSetSelectChangeCallbackWData_fp)API.fp[174]; |
| 961 | DLLTextSetTitle = (TextSetTitle_fp)API.fp[175]; |
| 962 | DLLPPic_GetPilot = (PPic_GetPilot_fp)API.fp[176]; |
| 963 | DLLPPic_GetBitmapHandle = (PPic_GetBitmapHandle_fp)API.fp[177]; |
| 964 | DLLrend_DrawLine = (rend_DrawLine_fp)API.fp[178]; |
| 965 | DLLrend_SetFlatColor = (rend_SetFlatColor_fp)API.fp[179]; |
| 966 | DLLMultiSetLogoState = (MultiSetLogoState_fp)API.fp[180]; |
| 967 | DLLPlayerGetRandomStartPosition = (PlayerGetRandomStartPosition_fp)API.fp[181]; |
| 968 | DLLInitPlayerNewShip = (InitPlayerNewShip_fp)API.fp[182]; |
| 969 | DLLCheckBoxCreate = (CheckBoxCreate_fp)API.fp[183]; |
| 970 | DLLCheckBoxSetCheck = (CheckBoxSetCheck_fp)API.fp[184]; |
| 971 | DLLCheckBoxIsChecked = (CheckBoxIsChecked_fp)API.fp[185]; |
| 972 | DLLnw_GetHostAddressFromNumbers = (nw_GetHostAddressFromNumbers_fp)API.fp[186]; |
| 973 | TableFilesClear = (TableFilesClear_fp)API.fp[187]; |
| 974 | TableFileAdd = (TableFileAdd_fp)API.fp[188]; |
| 975 | DLLDebugBreak_callback_stop = (DebugBreak_callback_stop_fp)API.fp[189]; |
| 976 | DLLDebugBreak_callback_resume = (DebugBreak_callback_resume_fp)API.fp[190]; |
| 977 | DLLInt3MessageBox = (Int3MessageBox_fp)API.fp[191]; |
| 978 | DLLGetUIItemPosition = (GetUIItemPosition_fp)API.fp[192]; |
| 979 | DLLAttachObjectRadius = (AttachObjectRadius_fp)API.fp[193]; |
| 980 | DLLUnattachChildren = (UnattachChildren_fp)API.fp[194]; |
| 981 | DLLUnattachChild = (UnattachChild_fp)API.fp[195]; |
| 982 | DLLUnattachFromParent = (UnattachFromParent_fp)API.fp[196]; |
| 983 | DLLvm_GetMagnitude = (vm_GetMagnitude_fp)API.fp[197]; |
| 984 | DLLvm_MatrixMulVector = (vm_MatrixMulVector_fp)API.fp[198]; |
| 985 | DLLphys_apply_force = (phys_apply_force_fp)API.fp[199]; |
| 986 | DLLphys_apply_rot = (phys_apply_rot_fp)API.fp[200]; |
| 987 | DLLvm_TransposeMatrix = (vm_TransposeMatrix_fp)API.fp[201]; |
| 988 | DLLvm_CrossProduct = (vm_CrossProduct_fp)API.fp[202]; |
| 989 | DLLvm_NormalizeVector = (vm_NormalizeVector_fp)API.fp[203]; |
| 990 | DLLConvertEulerToAxisAmount = (ConvertEulerToAxisAmount_fp)API.fp[204]; |
| 991 | DLLConvertAxisAmountToEuler = (ConvertAxisAmountToEuler_fp)API.fp[205]; |
| 992 | DLLvm_GetMagnitudeFast = (vm_GetMagnitudeFast_fp)API.fp[206]; |
| 993 | DLLvm_MakeIdentity = (vm_MakeIdentity_fp)API.fp[207]; |
| 994 | DLLvm_MakeVectorZero = (vm_MakeVectorZero_fp)API.fp[208]; |
| 995 | DLLvm_MakeAngleZero = (vm_MakeAngleZero_fp)API.fp[209]; |
| 996 | DLLvm_VectorMulTMatrix = (vm_VectorMulTMatrix_fp)API.fp[210]; |
| 997 | DLLvm_MatrixMul = (vm_MatrixMul_fp)API.fp[211]; |
| 998 | DLLvm_MatrixMulTMatrix = (vm_MatrixMulTMatrix_fp)API.fp[212]; |
| 999 | DLLvm_DotProduct = (vm_DotProduct_fp)API.fp[213]; |
| 1000 | DLLvm_SubVectors = (vm_SubVectors_fp)API.fp[214]; |
| 1001 | DLLvm_AddVectors = (vm_AddVectors_fp)API.fp[215]; |
| 1002 | DLLvm_AverageVector = (vm_AverageVector_fp)API.fp[216]; |
| 1003 | DLLvm_ScaleVector = (vm_ScaleVector_fp)API.fp[217]; |
| 1004 | DLLvm_ScaleAddVector = (vm_ScaleAddVector_fp)API.fp[218]; |
| 1005 | DLLvm_DivVector = (vm_DivVector_fp)API.fp[219]; |
| 1006 | DLLvm_NormalizeVectorFast = (vm_NormalizeVectorFast_fp)API.fp[220]; |
| 1007 | DLLvm_ClearMatrix = (vm_ClearMatrix_fp)API.fp[221]; |
| 1008 | DLLvm_AnglesToMatrix = (vm_AnglesToMatrix_fp)API.fp[222]; |
| 1009 | DLLvm_Orthogonalize = (vm_Orthogonalize_fp)API.fp[223]; |
| 1010 | DLLvm_VectorToMatrix = (vm_VectorToMatrix_fp)API.fp[224]; |
| 1011 | DLLvm_VectorAngleToMatrix = (vm_VectorAngleToMatrix_fp)API.fp[225]; |
| 1012 | DLLvm_SinCos = (vm_SinCos_fp)API.fp[226]; |
| 1013 | DLLvm_GetSlope = (vm_GetSlope_fp)API.fp[227]; |
| 1014 | DLLvm_GetPerp = (vm_GetPerp_fp)API.fp[228]; |
| 1015 | DLLvm_GetNormal = (vm_GetNormal_fp)API.fp[229]; |
| 1016 | DLLvm_VectorDistance = (vm_VectorDistance_fp)API.fp[230]; |
| 1017 | DLLvm_VectorDistanceQuick = (vm_VectorDistanceQuick_fp)API.fp[231]; |
| 1018 | DLLvm_GetNormalizedDir = (vm_GetNormalizedDir_fp)API.fp[232]; |
| 1019 | DLLvm_GetNormalizedDirFast = (vm_GetNormalizedDirFast_fp)API.fp[233]; |
| 1020 | DLLvm_ExtractAnglesFromMatrix = (vm_ExtractAnglesFromMatrix_fp)API.fp[234]; |
| 1021 | DLLvm_DeltaAngVec = (vm_DeltaAngVec_fp)API.fp[235]; |
| 1022 | DLLvm_DeltaAngVecNorm = (vm_DeltaAngVecNorm_fp)API.fp[236]; |
| 1023 | DLLvm_DistToPlane = (vm_DistToPlane_fp)API.fp[237]; |
| 1024 | DLLvm_CalcDetValue = (vm_CalcDetValue_fp)API.fp[238]; |
| 1025 | DLLvm_MakeInverseMatrix = (vm_MakeInverseMatrix_fp)API.fp[239]; |
| 1026 | DLLvm_SinCosToMatrix = (vm_SinCosToMatrix_fp)API.fp[240]; |
| 1027 | DLLvm_GetCentroid = (vm_GetCentroid_fp)API.fp[241]; |
| 1028 | DLLvm_MakeRandomVector = (vm_MakeRandomVector_fp)API.fp[242]; |
| 1029 | DLLvm_ComputeBoundingSphere = (vm_ComputeBoundingSphere_fp)API.fp[243]; |
| 1030 | DLLvm_GetCentroidFast = (vm_GetCentroidFast_fp)API.fp[244]; |
| 1031 | DLLRenderHUDGetTextLineWidth = (RenderHUDGetTextLineWidth_fp)API.fp[245]; |
| 1032 | DLLRenderHUDGetTextHeight = (RenderHUDGetTextHeight_fp)API.fp[246]; |
| 1033 | DLLStartFrame = (StartFrame_fp)API.fp[247]; |
| 1034 | DLLEndFrame = (EndFrame_fp)API.fp[248]; |
| 1035 | DLLResetFacings = (ResetFacings_fp)API.fp[249]; |
| 1036 | DLLGameRenderWorld = (GameRenderWorld_fp)API.fp[250]; |
| 1037 | DLLGetFrameParameters = (GetFrameParameters_fp)API.fp[251]; |
| 1038 | DLLrend_SetZBufferState = (rend_SetZBufferState_fp)API.fp[252]; |
| 1039 | DLLrend_SetLighting = (rend_SetLighting_fp)API.fp[253]; |
| 1040 | DLLrend_SetColorModel = (rend_SetColorModel_fp)API.fp[254]; |
| 1041 | DLLrend_SetTextureType = (rend_SetTextureType_fp)API.fp[255]; |
| 1042 | DLLrend_DrawPolygon = (rend_DrawPolygon_fp)API.fp[256]; |
| 1043 | DLLrend_SetMipState = (rend_SetMipState_fp)API.fp[257]; |
| 1044 | DLLrend_SetFogState = (rend_SetFogState_fp)API.fp[258]; |
| 1045 | DLLrend_SetFiltering = (rend_SetFiltering_fp)API.fp[259]; |
| 1046 | DLLrend_SetOverlayMap = (rend_SetOverlayMap_fp)API.fp[260]; |
| 1047 | DLLrend_SetOverlayType = (rend_SetOverlayType_fp)API.fp[261]; |
| 1048 | DLLrend_ClearScreen = (rend_ClearScreen_fp)API.fp[262]; |
| 1049 | DLLrend_SetPixel = (rend_SetPixel_fp)API.fp[263]; |
| 1050 | DLLrend_GetPixel = (rend_GetPixel_fp)API.fp[264]; |
| 1051 | DLLrend_FillCircle = (rend_FillCircle_fp)API.fp[265]; |
| 1052 | DLLrend_DrawCircle = (rend_DrawCircle_fp)API.fp[266]; |
| 1053 | DLLrend_SetAlphaType = (rend_SetAlphaType_fp)API.fp[267]; |
| 1054 | DLLrend_SetAlphaValue = (rend_SetAlphaValue_fp)API.fp[268]; |
| 1055 | DLLrend_SetWrapType = (rend_SetWrapType_fp)API.fp[269]; |
| 1056 | DLLrend_SetZBias = (rend_SetZBias_fp)API.fp[270]; |
| 1057 | DLLrend_SetZBufferWriteMask = (rend_SetZBufferWriteMask_fp)API.fp[271]; |
| 1058 | DLLrend_GetLFBLock = (rend_GetLFBLock_fp)API.fp[272]; |
| 1059 | DLLrend_ReleaseLFBLock = (rend_ReleaseLFBLock_fp)API.fp[273]; |
| 1060 | DLLrend_DrawLFBBitmap = (rend_DrawLFBBitmap_fp)API.fp[274]; |
| 1061 | DLLrend_DrawSpecialLine = (rend_DrawSpecialLine_fp)API.fp[275]; |
| 1062 | DLLfvi_FindIntersection = (fvi_FindIntersection_fp)API.fp[276]; |
| 1063 | DLLfvi_QuickDistFaceList = (fvi_QuickDistFaceList_fp)API.fp[277]; |
| 1064 | DLLfvi_QuickDistCellList = (fvi_QuickDistCellList_fp)API.fp[278]; |
| 1065 | DLLfvi_QuickDistObjectList = (fvi_QuickDistObjectList_fp)API.fp[279]; |
| 1066 | DLLfvi_QuickRoomCheck = (fvi_QuickRoomCheck_fp)API.fp[280]; |
| 1067 | DLLObjSetPos = (ObjSetPos_fp)API.fp[281]; |
| 1068 | DLLSetObjectDeadFlag = (SetObjectDeadFlag_fp)API.fp[282]; |
| 1069 | DLLtaunt_AreEnabled = (taunt_AreEnabled_fp)API.fp[283]; |
| 1070 | DLLtaunt_Enable = (taunt_Enable_fp)API.fp[284]; |
| 1071 | GetPlayerRankIndex = (GetPlayerRankIndex_fp)API.fp[285]; |
| 1072 | DLLVisEffectAllocate = (VisEffectAllocate_fp)API.fp[286]; |
| 1073 | DLLVisEffectFree = (VisEffectFree_fp)API.fp[287]; |
| 1074 | DLLVisEffectInitType = (VisEffectInitType_fp)API.fp[288]; |
| 1075 | DLLVisEffectCreate = (VisEffectCreate_fp)API.fp[289]; |
| 1076 | DLLVisEffectLink = (VisEffectLink_fp)API.fp[290]; |
| 1077 | DLLVisEffectUnlink = (VisEffectUnlink_fp)API.fp[291]; |
| 1078 | DLLVisEffectRelink = (VisEffectRelink_fp)API.fp[292]; |
| 1079 | DLLVisEffectDelete = (VisEffectDelete_fp)API.fp[293]; |
| 1080 | DLLCreateRandomSparks = (CreateRandomSparks_fp)API.fp[294]; |
| 1081 | DLLCreateRandomLineSparks = (CreateRandomLineSparks_fp)API.fp[295]; |
| 1082 | DLLVisEffectCreateControlled = (VisEffectCreateControlled_fp)API.fp[296]; |
| 1083 | DLLCreateRandomParticles = (CreateRandomParticles_fp)API.fp[297]; |
| 1084 | DLLAttachRandomNapalmEffectsToObject = (AttachRandomNapalmEffectsToObject_fp)API.fp[298]; |
| 1085 | DLLInitObjectScripts = (InitObjectScripts_fp)API.fp[299]; |
| 1086 | DLLg3_StartFrame = (g3_StartFrame_fp)API.fp[300]; |
| 1087 | DLLg3_EndFrame = (g3_EndFrame_fp)API.fp[301]; |
| 1088 | DLLg3_GetViewPosition = (g3_GetViewPosition_fp)API.fp[302]; |
| 1089 | DLLg3_GetViewMatrix = (g3_GetViewMatrix_fp)API.fp[303]; |
| 1090 | DLLg3_GetUnscaledMatrix = (g3_GetUnscaledMatrix_fp)API.fp[304]; |
| 1091 | DLLg3_StartInstanceMatrix = (g3_StartInstanceMatrix_fp)API.fp[305]; |
| 1092 | DLLg3_StartInstanceAngles = (g3_StartInstanceAngles_fp)API.fp[306]; |
| 1093 | DLLg3_DoneInstance = (g3_DoneInstance_fp)API.fp[307]; |
| 1094 | DLLg3_CheckNormalFacing = (g3_CheckNormalFacing_fp)API.fp[308]; |
| 1095 | DLLg3_RotatePoint = (g3_RotatePoint_fp)API.fp[309]; |
| 1096 | DLLg3_ProjectPoint = (g3_ProjectPoint_fp)API.fp[310]; |
| 1097 | DLLg3_CalcPointDepth = (g3_CalcPointDepth_fp)API.fp[311]; |
| 1098 | DLLg3_Point2Vec = (g3_Point2Vec_fp)API.fp[312]; |
| 1099 | DLLg3_CodePoint = (g3_CodePoint_fp)API.fp[313]; |
| 1100 | DLLg3_RotateDeltaX = (g3_RotateDeltaX_fp)API.fp[314]; |
| 1101 | DLLg3_RotateDeltaY = (g3_RotateDeltaY_fp)API.fp[315]; |
| 1102 | DLLg3_RotateDeltaZ = (g3_RotateDeltaZ_fp)API.fp[316]; |
| 1103 | DLLg3_RotateDeltaVec = (g3_RotateDeltaVec_fp)API.fp[317]; |
| 1104 | DLLg3_AddDeltaVec = (g3_AddDeltaVec_fp)API.fp[318]; |
| 1105 | DLLg3_DrawPoly = (g3_DrawPoly_fp)API.fp[319]; |
| 1106 | DLLg3_DrawSphere = (g3_DrawSphere_fp)API.fp[320]; |
| 1107 | DLLg3_CheckAndDrawPoly = (g3_CheckAndDrawPoly_fp)API.fp[321]; |
| 1108 | DLLg3_DrawLine = (g3_DrawLine_fp)API.fp[322]; |
| 1109 | DLLg3_DrawBitmap = (g3_DrawBitmap_fp)API.fp[323]; |
| 1110 | DLLg3_DrawRotatedBitmap = (g3_DrawRotatedBitmap_fp)API.fp[324]; |
| 1111 | DLLg3_DrawBox = (g3_DrawBox_fp)API.fp[325]; |
| 1112 | DLLg3_SetCustomClipPlane = (g3_SetCustomClipPlane_fp)API.fp[326]; |
| 1113 | DLLg3_SetFarClipZ = (g3_SetFarClipZ_fp)API.fp[327]; |
| 1114 | DLLg3_ClipPolygon = (g3_ClipPolygon_fp)API.fp[328]; |
| 1115 | DLLg3_FreeTempPoints = (g3_FreeTempPoints_fp)API.fp[329]; |
| 1116 | DLLg3_GetMatrixScale = (g3_GetMatrixScale_fp)API.fp[330]; |
| 1117 | DLLg3_SetTriangulationTest = (g3_SetTriangulationTest_fp)API.fp[331]; |
| 1118 | DLLg3_DrawSpecialLine = (g3_DrawSpecialLine_fp)API.fp[332]; |
| 1119 | DLLg3_DrawPlanarRotatedBitmap = (g3_DrawPlanarRotatedBitmap_fp)API.fp[333]; |
| 1120 | DLLPlayerStopSounds = (PlayerStopSounds_fp)API.fp[334]; |
| 1121 | DLLFindArg = (FindArg_fp)API.fp[335]; |
| 1122 | DLLFireWeaponFromObject = (FireWeaponFromObject_fp)API.fp[336]; |
| 1123 | DLLCreateAndFireWeapon = (CreateAndFireWeapon_fp)API.fp[337]; |
| 1124 | DLLSelectNextCameraView = (SelectNextCameraView_fp)API.fp[338]; |
| 1125 | Inven_Add = (dInven_Add_fp)API.fp[339]; |
| 1126 | Inven_AddObject = (dInven_AddObject_fp)API.fp[340]; |
| 1127 | Inven_AddCounterMeasure = (dInven_AddCounterMeasure_fp)API.fp[341]; |
| 1128 | Inven_Remove = (dInven_Remove_fp)API.fp[342]; |
| 1129 | Inven_Use = (dInven_Use_fp)API.fp[343]; |
| 1130 | Inven_UseObjHandle = (dInven_UseObjHandle_fp)API.fp[344]; |
| 1131 | Inven_Size = (dInven_Size_fp)API.fp[345]; |
| 1132 | Inven_CheckItem = (dInven_CheckItem_fp)API.fp[346]; |
| 1133 | Inven_Reset = (dInven_Reset_fp)API.fp[347]; |
| 1134 | Inven_ResetPos = (dInven_ResetPos_fp)API.fp[348]; |
| 1135 | Inven_NextPos = (dInven_NextPos_fp)API.fp[349]; |
| 1136 | Inven_PrevPos = (dInven_PrevPos_fp)API.fp[350]; |
| 1137 | Inven_GetPosTypeID = (dInven_GetPosTypeID_fp)API.fp[351]; |
| 1138 | Inven_GetAuxPosTypeID = (dInven_GetAuxPosTypeID_fp)API.fp[352]; |
| 1139 | Inven_GetPosDescription = (dInven_GetPosDescription_fp)API.fp[353]; |
| 1140 | Inven_GetPosIconName = (dInven_GetPosIconName_fp)API.fp[354]; |
| 1141 | Inven_GetPosName = (dInven_GetPosName_fp)API.fp[355]; |
| 1142 | Inven_GetPosInfo = (dInven_GetPosInfo_fp)API.fp[356]; |
| 1143 | Inven_GetPosCount = (dInven_GetPosCount_fp)API.fp[357]; |
| 1144 | Inven_AtBeginning = (dInven_AtBeginning_fp)API.fp[358]; |
| 1145 | Inven_AtEnd = (dInven_AtEnd_fp)API.fp[359]; |
| 1146 | Inven_GotoPos = (dInven_GotoPos_fp)API.fp[360]; |
| 1147 | Inven_GotoPosTypeID = (dInven_GotoPosTypeID_fp)API.fp[361]; |
| 1148 | Inven_UsePos = (dInven_UsePos_fp)API.fp[362]; |
| 1149 | Inven_GetPos = (dInven_GetPos_fp)API.fp[363]; |
| 1150 | Inven_ValidatePos = (dInven_ValidatePos_fp)API.fp[364]; |
| 1151 | Inven_IsSelectable = (dInven_IsSelectable_fp)API.fp[365]; |
| 1152 | Inven_IsUsable = (dInven_IsUsable_fp)API.fp[366]; |
| 1153 | Inven_GetTypeIDCount = (dInven_GetTypeIDCount_fp)API.fp[367]; |
| 1154 | Inven_FindPos = (dInven_FindPos_fp)API.fp[368]; |
| 1155 | Inven_GetInventoryItemList = (dInven_GetInventoryItemList_fp)API.fp[369]; |
| 1156 | |
| 1157 | // Do variables |
| 1158 | Player_num = (int *)API.vp[0]; |
| 1159 | Highest_room_index = (int *)API.vp[1]; |
| 1160 | Game_window_w = (int *)API.vp[2]; |
| 1161 | Game_window_h = (int *)API.vp[3]; |
| 1162 | Game_fonts = (int *)API.vp[4]; |
| 1163 | Frametime = (float *)API.vp[5]; |
| 1164 | Gametime = (float *)API.vp[6]; |
| 1165 | ShieldDelta = (float *)API.vp[7]; |
| 1166 | Game_interface_mode = (int *)API.vp[8]; |
| 1167 | LocalD3Dir = (char *)API.vp[9]; |
| 1168 | m_bTrackerGame = (int *)API.vp[10]; |
| 1169 | Local_object_list = (uint16_t *)API.vp[11]; |
| 1170 | Server_object_list = (uint16_t *)API.vp[12]; |
| 1171 | Dedicated_server = (bool *)API.vp[13]; |
| 1172 | Player_colors = (ddgr_color *)API.vp[14]; |
| 1173 | Hud_aspect_x = (float *)API.vp[15]; |
| 1174 | Hud_aspect_y = (float *)API.vp[16]; |
| 1175 | Viewer_object = (object **)API.vp[17]; |
| 1176 | Render_zoom = (float *)API.vp[18]; |
| 1177 | Game_window_x = (int *)API.vp[19]; |
| 1178 | Game_window_y = (int *)API.vp[20]; |
| 1179 | Poly_models = (poly_model *)API.vp[21]; |
| 1180 | VisEffects = (vis_effect *)API.vp[22]; |
| 1181 | Highest_vis_effect_index = (int *)API.vp[23]; |
| 1182 | Multi_next_level = (int *)API.vp[24]; |
| 1183 | Level_info = (level_info *)API.vp[25]; |
| 1184 | GameArgs = (void *)API.vp[26]; |
| 1185 | Camera_view_mode = (int *)API.vp[27]; |
| 1186 | Object_info = (object_info *)API.vp[28]; |
| 1187 | } |
| 1188 | |
| 1189 | // DMFCBase::GameInit |
| 1190 | // |
| 1191 | // Sets up all the DLL functions and pointers and preps the class for use. This ABSOLUTLY must be |
| 1192 | // called, so if you override DMFCApp::GameInit, make sure that you put a call to this somewhere in |
| 1193 | // the override. |
| 1194 | void DMFCBase::GameInit(int teams) { |
| 1195 | ASSERT(!DMFCInit); |
| 1196 | DMFCInit = true; |
| 1197 | |
| 1198 | LoadSettings(); |
| 1199 | |
| 1200 | DLLCreateStringTable("dmfc.str", &DMFCStringTable, &DMFCStringTableSize); |
| 1201 | mprintf(0, "DMFC Note: %d strings loaded from string table\n", DMFCStringTableSize); |
| 1202 | |
| 1203 | // initialize player records |
| 1204 | PRec_Init(); |
| 1205 | |
| 1206 | // initialize remote administration |
| 1207 | Remote_Initialize(); |
| 1208 | |
| 1209 | // see if we should display Outrage logo at all |
| 1210 | if (DLLFindArg("-nooutragelogo")) |
| 1211 | m_bDisplayOutrageLogo = false; |
| 1212 | else |
| 1213 | m_bDisplayOutrageLogo = true; |
| 1214 | |
| 1215 | SetNumberOfTeams(teams); |
| 1216 | |
| 1217 | SetTeamName(RED_TEAM, DTXT_RED, false); |
| 1218 | SetTeamName(BLUE_TEAM, DTXT_BLUE, false); |
| 1219 | SetTeamName(GREEN_TEAM, DTXT_GREEN, false); |
| 1220 | SetTeamName(YELLOW_TEAM, DTXT_YELLOW, false); |
| 1221 | |
| 1222 | // Load bitmaps |
| 1223 | hBitmapObserver = DLLbm_AllocLoadFileBitmap("observer icon.ogf", 0, BITMAP_FORMAT_1555); |
| 1224 | if (hBitmapObserver <= BAD_BITMAP_HANDLE) |
| 1225 | hBitmapObserver = BAD_BITMAP_HANDLE; |
| 1226 | |
| 1227 | RegisterPacketReceiver(SPID_TEAMASSIGNMENT, &DMFCBase::GetTeamAssignmentPacket); |
| 1228 | RegisterPacketReceiver(SPID_CHANGETEAM, &DMFCBase::GetChangeTeamPacket); |
| 1229 | RegisterPacketReceiver(SPID_REQGAMESTATE, &DMFCBase::GetGameStateRequest); |
| 1230 | RegisterPacketReceiver(SPID_DMFCGAMEINFO, &DMFCBase::GetDMFCGameInfo); |
| 1231 | RegisterPacketReceiver(SPID_VERSIONID, &DMFCBase::GetDMFCVersionCheck); |
| 1232 | RegisterPacketReceiver(SPID_PRECORD, PRec_ReceivePRecFromServer); |
| 1233 | RegisterPacketReceiver(SPID_PRECORDREQ, &DMFCBase::ReceiveRequestForPlayerRecords); |
| 1234 | RegisterPacketReceiver(SPID_CONTROLMSG, &DMFCBase::ReceiveControlMessage); |
| 1235 | RegisterPacketReceiver(SPID_NETGAMESYNC, &DMFCBase::ReceiveNetGameInfoSync); |
| 1236 | RegisterPacketReceiver(SPID_NEWTEAMNAME, &DMFCBase::ReceiveNewTeamName); |
| 1237 | RegisterPacketReceiver(SPID_REMOTEKEY, &DMFCBase::GetRemoteKey); |
| 1238 | RegisterPacketReceiver(SPID_REALGAMETIME, &DMFCBase::GetRealGametimePacket); |
| 1239 | AddWeaponHash("Laser", "Laser Level 1 - Red", "Laser Level 2 - Blue", "Laser Level 3 - Purple", |
| 1240 | "Laser Level 4 - Green", NULL); |
| 1241 | AddWeaponHash("Vauss", "Vauss Spark", NULL); |
| 1242 | AddWeaponHash("Raygun", NULL); |
| 1243 | AddWeaponHash("Plasma", "plasma sparks", NULL); |
| 1244 | AddWeaponHash("Fusion", NULL); |
| 1245 | AddWeaponHash("Super Laser", "Laser Level 5 -Yellow", "Laser Level 6 -White", NULL); |
| 1246 | AddWeaponHash("Mass Driver", NULL); |
| 1247 | AddWeaponHash("Napalm", NULL); |
| 1248 | AddWeaponHash("EMDyellowleft", "EMDyellowright", "EMDgreenleft", "EMDgreenright", NULL); |
| 1249 | AddWeaponHash("Omega", NULL); |
| 1250 | AddWeaponHash("Concussion", NULL); |
| 1251 | AddWeaponHash("Homing", NULL); |
| 1252 | AddWeaponHash("Smart", "SmartPlasmaHomers", NULL); |
| 1253 | AddWeaponHash("Mega", "MegaExplosion", NULL); |
| 1254 | AddWeaponHash("Frag", "frag particles", NULL); |
| 1255 | AddWeaponHash("Guided", NULL); |
| 1256 | AddWeaponHash("NapalmRocket", "NapalmBlob", "NapalmParticles", NULL); |
| 1257 | AddWeaponHash("Cyclone Pack", "Swarm", NULL); |
| 1258 | AddWeaponHash("Yellow Flare", NULL); |
| 1259 | |
| 1260 | SetWeaponDeathMessage("Laser", DTXT_DEATHLASER, false); |
| 1261 | SetWeaponDeathMessage("Vauss", DTXT_DEATHVAUSS, false); |
| 1262 | SetWeaponDeathMessage("RayGun", DTXT_DEATHMICROWAVE, true); |
| 1263 | SetWeaponDeathMessage("Plasma", DTXT_DEATHPLASMA, false); |
| 1264 | SetWeaponDeathMessage("Fusion", DTXT_DEATHFUSION, false); |
| 1265 | SetWeaponDeathMessage("Super Laser", DTXT_DEATHSUPERLASER, false); |
| 1266 | SetWeaponDeathMessage("Mass Driver", DTXT_DEATHMASS, false); |
| 1267 | SetWeaponDeathMessage("Napalm", DTXT_DEATHNAPALM, false); |
| 1268 | SetWeaponDeathMessage("EMDyellowleft", DTXT_DEATHEMD, false); |
| 1269 | SetWeaponDeathMessage("Omega", DTXT_DEATHOMEGA, false); |
| 1270 | SetWeaponDeathMessage("Concussion", DTXT_DEATHCONC, true); |
| 1271 | SetWeaponDeathMessage("Homing", DTXT_DEATHHOMING, false); |
| 1272 | SetWeaponDeathMessage("Smart", DTXT_DEATHSMART, true); |
| 1273 | SetWeaponDeathMessage("Mega", DTXT_DEATHMEGA, false); |
| 1274 | SetWeaponDeathMessage("Frag", DTXT_DEATHFRAG, true); |
| 1275 | SetWeaponDeathMessage("Guided", DTXT_DEATHGUIDED, false); |
| 1276 | SetWeaponDeathMessage("NapalmRocket", DTXT_DEATHNAPALMROCKET, true); |
| 1277 | SetWeaponDeathMessage("Cyclone Pack", DTXT_DEATHCYCLONE, false); |
| 1278 | SetWeaponDeathMessage("Yellow Flare", DTXT_DEATHFLARE, false); |
| 1279 | |
| 1280 | /* |
| 1281 | $$TABLE_WEAPON "Laser" |
| 1282 | $$TABLE_WEAPON "Laser Level 1 - Red" |
| 1283 | $$TABLE_WEAPON "Laser Level 2 - Blue" |
| 1284 | $$TABLE_WEAPON "Laser Level 3 - Purple" |
| 1285 | $$TABLE_WEAPON "Laser Level 4 - Green" |
| 1286 | $$TABLE_WEAPON "Vauss" |
| 1287 | $$TABLE_WEAPON "Vauss Spark" |
| 1288 | $$TABLE_WEAPON "Raygun" |
| 1289 | $$TABLE_WEAPON "Plasma" |
| 1290 | $$TABLE_WEAPON "plasma sparks" |
| 1291 | $$TABLE_WEAPON "Fusion" |
| 1292 | $$TABLE_WEAPON "Super Laser" |
| 1293 | $$TABLE_WEAPON "Laser Level 5 -Yellow" |
| 1294 | $$TABLE_WEAPON "Laser Level 6 -White" |
| 1295 | $$TABLE_WEAPON "Mass Driver" |
| 1296 | $$TABLE_WEAPON "Napalm" |
| 1297 | $$TABLE_WEAPON "EMDyellowleft" |
| 1298 | $$TABLE_WEAPON "EMDyellowright" |
| 1299 | $$TABLE_WEAPON "EMDgreenleft" |
| 1300 | $$TABLE_WEAPON "EMDgreenright" |
| 1301 | $$TABLE_WEAPON "Omega" |
| 1302 | $$TABLE_WEAPON "Concussion" |
| 1303 | $$TABLE_WEAPON "Homing" |
| 1304 | $$TABLE_WEAPON "Smart" |
| 1305 | $$TABLE_WEAPON "SmartPlasmaHomers" |
| 1306 | $$TABLE_WEAPON "Mega" |
| 1307 | $$TABLE_WEAPON "MegaExplosion" |
| 1308 | $$TABLE_WEAPON "Frag" |
| 1309 | $$TABLE_WEAPON "frag particles" |
| 1310 | $$TABLE_WEAPON "Guided" |
| 1311 | $$TABLE_WEAPON "NapalmRocket" |
| 1312 | $$TABLE_WEAPON "NapalmBlob" |
| 1313 | $$TABLE_WEAPON "NapalmParticles" |
| 1314 | $$TABLE_WEAPON "Cyclone Pack" |
| 1315 | $$TABLE_WEAPON "Swarm" |
| 1316 | $$TABLE_WEAPON "Yellow Flare" |
| 1317 | */ |
| 1318 | |
| 1319 | // Set up default messages so we have something |
| 1320 | AddDeathMessage(DTXT_KILLED1, true); |
| 1321 | AddSuicideMessage(DTXT_SUICIDE1); |
| 1322 | |
| 1323 | // Setup InputCommand handlers |
| 1324 | InputCommandInit(); |
| 1325 | |
| 1326 | ParseStartupScript(); |
| 1327 | |
| 1328 | TauntIndicatorBMP = DLLbm_AllocLoadFileBitmap("Taunt.ogf", 0, BITMAP_FORMAT_1555); |
| 1329 | |
| 1330 | MenuBackgroundBMP = DLLbm_AllocBitmap(32, 32, 0); |
| 1331 | if (MenuBackgroundBMP > BAD_BITMAP_HANDLE) { |
| 1332 | uint16_t *data = DLLbm_data(MenuBackgroundBMP, 0); |
| 1333 | int j; |
| 1334 | for (j = 0; j < 32 * 32; j++) |
| 1335 | data[j] = OPAQUE_FLAG | GR_RGB(0, 0, 0); |
| 1336 | } |
| 1337 | |
| 1338 | MenuItem *lev1, *lev2, *lev3; |
| 1339 | |
| 1340 | if (GetLocalRole() == LR_SERVER) { |
| 1341 | // Start Server Commands Menu |
| 1342 | lev1 = new MenuItem(DTXT_MNUSRVRCOMMAND, MIT_NORMAL, 0, NULL); // Server |
| 1343 | lev2 = new MenuItem(DTXT_MNUKICK, MIT_PLIST, 0, KickPlayer); // |- Kick |
| 1344 | lev1->AddSubMenu(lev2); |
| 1345 | lev2 = new MenuItem(DTXT_MNUBAN, MIT_PLIST, 0, BanPlayer); // |- Ban |
| 1346 | lev1->AddSubMenu(lev2); |
| 1347 | |
| 1348 | tCustomMenu cm; |
| 1349 | cm.GetItem = GetBannedPlayerString; |
| 1350 | cm.GetListCount = GetBanPlayerList; |
| 1351 | lev2 = new MenuItem(DTXT_OSM_REMOVEBAN, MIT_CUSTOM, 0, RemoveBanByIndex, &cm); |
| 1352 | lev1->AddSubMenu(lev2); |
| 1353 | |
| 1354 | lev2 = new MenuItem(DTXT_OSM_REHASHLIST, MIT_NORMAL, 0, RehashAllowDenyLists); |
| 1355 | lev1->AddSubMenu(lev2); |
| 1356 | |
| 1357 | lev2 = new MenuItem(DTXT_MNUENDLEVEL, MIT_NORMAL, 0, EndMultiLevel); // |- End Level |
| 1358 | lev1->AddSubMenu(lev2); |
| 1359 | ServerHUDCallsignsItem = lev2 = |
| 1360 | new MenuItem(DTXT_OSM_MAXHUDNAME, MIT_STATE, 0, SwitchServerHudPlayerName, 3, m_iServerHUDCallsignLevel, |
| 1361 | DTXT_PLAIN_NONE, DTXT_OSM_TEAMONLY, DTXT_OSM_FULL); |
| 1362 | lev1->AddSubMenu(lev2); |
| 1363 | if (teams > 1) { |
| 1364 | // Team Game Stuff here |
| 1365 | lev2 = new MenuItem(DTXT_MNUTEAMCONTROL, MIT_NORMAL, 0, NULL); // |- Team Control |
| 1366 | lev3 = new MenuItem(DTXT_MNUBALANCE, MIT_NORMAL, 0, BalanceTeams); // |- Balance Teams |
| 1367 | lev2->AddSubMenu(lev3); // |- AutoTeam Balance Off/On |
| 1368 | AutoBalanceItem = lev3 = |
| 1369 | new MenuItem(DTXT_MNUAUTOBALANCE, MIT_STATE, 0, SwitchAutoTeamSelect, 2, |
| 1370 | (m_iProtectedFlags & DMFC_PRF_AUTOTEAMSELECT) ? 1 : 0, DTXT_MNUOFF, DTXT_MNUON); |
| 1371 | lev2->AddSubMenu(lev3); |
| 1372 | AllowTeamChangeItem = lev3 = new MenuItem(DTXT_MNUALLOWTEAMCNG, MIT_STATE, 0, SwitchTeamChange, 2, |
| 1373 | AllowTeamChange() ? 1 : 0, DTXT_MNUOFF, DTXT_MNUON); |
| 1374 | lev2->AddSubMenu(lev3); |
| 1375 | lev3 = new MenuItem(DTXT_OSM_TEAMCONFIG, MIT_NORMAL, 0, OnScreenDisplayTeamConfig); |
| 1376 | lev2->AddSubMenu(lev3); |
| 1377 | lev1->AddSubMenu(lev2); |
| 1378 | } |
| 1379 | |
| 1380 | Menu.AddSubMenu(lev1); |
| 1381 | |
| 1382 | // End Server Commands Menu |
| 1383 | } |
| 1384 | |
| 1385 | if (GetLocalRole() == LR_CLIENT) { |
| 1386 | // Start Client Commands Menu |
| 1387 | bool peertopeer = (bool)((Netgame->flags & NF_PEER_PEER) != 0); |
| 1388 | if (!peertopeer) { |
| 1389 | lev1 = HUDIndicatorItem = new MenuItem(DTXT_LOSSPINGIND, MIT_STATE, 0, SwitchLossPingIndicator, 2, |
| 1390 | (LossGuageEnabled) ? 1 : 0, DTXT_MNUOFF, DTXT_MNUON); |
| 1391 | Menu.AddSubMenu(lev1); |
| 1392 | } |
| 1393 | // End Client Commands Menu |
| 1394 | } |
| 1395 | |
| 1396 | // Do General stuff here |
| 1397 | lev1 = new MenuItem(DTXT_MNUOBSERVER, MIT_NORMAL, 0, NULL); |
| 1398 | ObserverItem = lev2 = new MenuItem(DTXT_MNUOBSERVER, MIT_STATE, 0, SwitchObserverMode, 2, 0, DTXT_MNUOFF, DTXT_MNUON); |
| 1399 | lev1->AddSubMenu(lev2); |
| 1400 | |
| 1401 | lev2 = new MenuItem(DTXT_OSM_PIGGYBACK, MIT_PLIST, 0, SwitchPiggyBack); |
| 1402 | lev1->AddSubMenu(lev2); |
| 1403 | Menu.AddSubMenu(lev1); |
| 1404 | |
| 1405 | /* |
| 1406 | lev1 = new MenuItem("OnScreen Menu Options",MIT_NORMAL,0,NULL); |
| 1407 | lev2 = MenuBackgroundItem = new MenuItem("Background",MIT_STATE,0,SwitchMenuBackground,2,0,DTXT_MNUOFF,DTXT_MNUON); |
| 1408 | lev1->AddSubMenu(lev2); |
| 1409 | Menu.AddSubMenu(lev1); |
| 1410 | */ |
| 1411 | lev1 = MenuBackgroundItem = |
| 1412 | new MenuItem(DTXT_OSM_BACKGROUND, MIT_STATE, 0, SwitchMenuBackground, 2, 0, DTXT_MNUOFF, DTXT_MNUON); |
| 1413 | Menu.AddSubMenu(lev1); |
| 1414 | |
| 1415 | HUDCallsignsItem = lev1 = |
| 1416 | new MenuItem(DTXT_OSM_HUDNAMELEVEL, MIT_STATE, 0, SwitchHudPlayerNum, 3, m_iMyPreferredHUDCallsignLevel, |
| 1417 | DTXT_PLAIN_NONE, DTXT_OSM_TEAMONLY, DTXT_OSM_FULL); |
| 1418 | Menu.AddSubMenu(lev1); |
| 1419 | |
| 1420 | ShipLogosItem = lev1 = new MenuItem(DTXT_OSM_SHIPLOGOS, MIT_STATE, 0, SwitchShipLogoEnable, 2, |
| 1421 | (AreLogosEnabled()) ? 1 : 0, DTXT_MNUOFF, DTXT_MNUON); |
| 1422 | Menu.AddSubMenu(lev1); |
| 1423 | |
| 1424 | AudioTauntsItem = lev1 = new MenuItem(DTXT_OSM_AUDIOTAUNTS, MIT_STATE, 0, SwitchAudioTauntsEnable, 2, |
| 1425 | (AreTauntsEnabled()) ? 1 : 0, DTXT_MNUOFF, DTXT_MNUON); |
| 1426 | Menu.AddSubMenu(lev1); |
| 1427 | |
| 1428 | // File Statitics menu |
| 1429 | lev1 = new MenuItem(DTXT_OSM_STATSTOFILE, MIT_NORMAL, 0, NULL); |
| 1430 | |
| 1431 | lev2 = new MenuItem(DTXT_SAVESTATS, MIT_NORMAL, 0, SaveStatsToFile); |
| 1432 | lev1->AddSubMenu(lev2); |
| 1433 | |
| 1434 | SaveStatsLevelEndItem = lev2 = |
| 1435 | new MenuItem(DTXT_OSM_STATLEVELEND, MIT_STATE, 0, SwitchSaveStatsLevelEnd, 2, 1, DTXT_MNUOFF, DTXT_MNUON); |
| 1436 | lev1->AddSubMenu(lev2); |
| 1437 | |
| 1438 | SaveStatsDisconnectItem = lev2 = |
| 1439 | new MenuItem(DTXT_OSM_STATDISCONNECT, MIT_STATE, 0, SwitchSaveStatsDisconnect, 2, 1, DTXT_MNUOFF, DTXT_MNUON); |
| 1440 | lev1->AddSubMenu(lev2); |
| 1441 | |
| 1442 | Menu.AddSubMenu(lev1); |
| 1443 | |
| 1444 | lev1 = new MenuItem(DTXT_MNUGETPLYRINFO, MIT_PLIST, MIF_INCLUDENONE, SwitchPlayerInfo); |
| 1445 | Menu.AddSubMenu(lev1); |
| 1446 | |
| 1447 | NetGameInfoItem = lev1 = |
| 1448 | new MenuItem(DTXT_OSM_NETGAMEINFO, MIT_STATE, 0, SwitchNetGameInfo, 2, |
| 1449 | (m_iProtectedFlags & DMFC_PRF_DISPNETGAMEINFO) ? 1 : 0, DTXT_MNUOFF, DTXT_MNUON); |
| 1450 | Menu.AddSubMenu(lev1); |
| 1451 | |
| 1452 | lev1 = new MenuItem(DTXT_OSM_HUDFILTER, MIT_NORMAL, 0, NULL); |
| 1453 | lev2 = DeathMessageFilterItem = new MenuItem(DTXT_OSM_KILLMESSAGES, MIT_STATE, 0, SwitchDeathMessageFilter, 3, |
| 1454 | m_iDeathMessageFilter, DTXT_PLAIN_NONE, DTXT_OSM_SIMPLE, DTXT_OSM_FULL); |
| 1455 | lev1->AddSubMenu(lev2); |
| 1456 | |
| 1457 | lev2 = StatisticMessagesItem = |
| 1458 | new MenuItem(DTXT_OSM_STATMESSAGES, MIT_STATE, 0, SwitchStatHUDMessages, 2, 1, DTXT_MNUOFF, DTXT_MNUON); |
| 1459 | lev1->AddSubMenu(lev2); |
| 1460 | Menu.AddSubMenu(lev1); |
| 1461 | |
| 1462 | if (teams > 1) { |
| 1463 | // Team Game Stuff here |
| 1464 | char names[DLLMAX_TEAMS][MAX_TEAMNAME_LEN]; |
| 1465 | strcpy(names[RED_TEAM], GetTeamString(RED_TEAM)); |
| 1466 | strcpy(names[BLUE_TEAM], GetTeamString(BLUE_TEAM)); |
| 1467 | switch (teams) { |
| 1468 | case 2: |
| 1469 | TeamMenuItem = lev1 = new MenuItem(DTXT_MNUCHANGETEAMS, MIT_STATE, 0, ChangeTeams, 2, |
| 1470 | GetPlayerTeam(GetPlayerNum()), names[RED_TEAM], names[BLUE_TEAM]); |
| 1471 | break; |
| 1472 | case 3: |
| 1473 | strcpy(names[GREEN_TEAM], GetTeamString(GREEN_TEAM)); |
| 1474 | TeamMenuItem = lev1 = |
| 1475 | new MenuItem(DTXT_MNUCHANGETEAMS, MIT_STATE, 0, ChangeTeams, 3, GetPlayerTeam(GetPlayerNum()), |
| 1476 | names[RED_TEAM], names[BLUE_TEAM], names[GREEN_TEAM]); |
| 1477 | break; |
| 1478 | case 4: |
| 1479 | strcpy(names[GREEN_TEAM], GetTeamString(GREEN_TEAM)); |
| 1480 | strcpy(names[YELLOW_TEAM], GetTeamString(YELLOW_TEAM)); |
| 1481 | TeamMenuItem = lev1 = |
| 1482 | new MenuItem(DTXT_MNUCHANGETEAMS, MIT_STATE, 0, ChangeTeams, 4, GetPlayerTeam(GetPlayerNum()), |
| 1483 | names[RED_TEAM], names[BLUE_TEAM], names[GREEN_TEAM], names[YELLOW_TEAM]); |
| 1484 | break; |
| 1485 | } |
| 1486 | Menu.AddSubMenu(lev1); |
| 1487 | } |
| 1488 | |
| 1489 | lev1 = new MenuItem(DTXT_OSM_EXIT, MIT_NORMAL, 0, MenuExitMenu); |
| 1490 | Menu.AddSubMenu(lev1); |
| 1491 | |
| 1492 | // save the hud level var |
| 1493 | int curr_call_level = m_iMyPreferredHUDCallsignLevel; |
| 1494 | m_iMyCurrentHUDCallsignLevel = -1; // set this to -1 so it definitly gets changes/set |
| 1495 | SwitchShowHudCallsignLevel(curr_call_level, false); |
| 1496 | |
| 1497 | Menu.SetInputFocus(); |
| 1498 | |
| 1499 | EnableShipLogos(true); |
| 1500 | |
| 1501 | ReadInHostsAllowDeny(); |
| 1502 | |
| 1503 | InitializeForLevel(); |
| 1504 | } |
| 1505 | |
| 1506 | // DMFCBase::GameClose |
| 1507 | // |
| 1508 | // Closes up any needed DLL and DMFC tasks. This ABSOLUTLY must be called, so if you override |
| 1509 | // DMFCApp::GameClose, make sure that you put a call to this somewhere in the override |
| 1510 | void DMFCBase::GameClose(void) { |
| 1511 | ASSERT(DMFCInit); |
| 1512 | DMFCInit = false; |
| 1513 | |
| 1514 | SaveSettings(); |
| 1515 | |
| 1516 | // Free bitmaps |
| 1517 | if (hBitmapObserver > BAD_BITMAP_HANDLE) { |
| 1518 | DLLbm_FreeBitmap(hBitmapObserver); |
| 1519 | hBitmapObserver = BAD_BITMAP_HANDLE; |
| 1520 | } |
| 1521 | |
| 1522 | FreeHostsLists(); |
| 1523 | |
| 1524 | // Close up InputCommands |
| 1525 | InputCommandFree(); |
| 1526 | |
| 1527 | // close up and free player records |
| 1528 | PRec_Close(); |
| 1529 | |
| 1530 | if (MenuBackgroundBMP > BAD_BITMAP_HANDLE) |
| 1531 | DLLbm_FreeBitmap(MenuBackgroundBMP); |
| 1532 | |
| 1533 | DLLDestroyStringTable(DMFCStringTable, DMFCStringTableSize); |
| 1534 | } |
| 1535 | |
| 1536 | void DMFCBase::DrawMenu(void) { |
| 1537 | DLLgrtext_SetFont(Game_fonts[HUD_FONT_INDEX]); |
| 1538 | |
| 1539 | // Menu.Draw(10,100,DLLgrfont_GetHeight(Game_fonts[HUD_FONT_INDEX])+1,this,(m_iProtectedFlags&DMFC_PRF_DISPMENUBACKGR)?MenuBackgroundBMP:-1); |
| 1540 | // Menu.Draw(10,100,DLLRenderHUDGetTextHeight("X")+1,this,(m_iProtectedFlags&DMFC_PRF_DISPMENUBACKGR)?MenuBackgroundBMP:-1); |
| 1541 | int font_height = DLLgrfont_GetHeight(Game_fonts[HUD_FONT_INDEX]); |
| 1542 | |
| 1543 | Menu.Draw(10, (font_height * 8) + 10, font_height + 1, |
| 1544 | (m_iProtectedFlags & DMFC_PRF_DISPMENUBACKGR) ? MenuBackgroundBMP : -1); |
| 1545 | } |
| 1546 | |
| 1547 | char DMFCPlayerInfo[6][100]; |
| 1548 | void DMFCBase::SetPlayerInfo(int pnum) { |
| 1549 | if (!CheckPlayerNum(pnum)) { |
| 1550 | return; |
| 1551 | } |
| 1552 | |
| 1553 | m_iPlayerDisplayed = pnum; |
| 1554 | |
| 1555 | int x, y; |
| 1556 | char buffer[100]; |
| 1557 | y = 0; |
| 1558 | x = 15; |
| 1559 | int index = 0; |
| 1560 | bool display_addr = false; |
| 1561 | |
| 1562 | // Print out callsign |
| 1563 | snprintf(buffer, sizeof(buffer), "%s (%s)", Players[pnum].callsign, (0 == pnum) ? DTXT_SERVER : DTXT_CLIENT); |
| 1564 | strcpy(DMFCPlayerInfo[index], buffer); |
| 1565 | index++; |
| 1566 | |
| 1567 | if (m_iNumTeams > 1 && Players[pnum].team != -1) { |
| 1568 | snprintf(buffer, sizeof(buffer), DTXT_TEAMFORMAT, GetTeamString(GetPlayerTeam(pnum))); |
| 1569 | strcpy(DMFCPlayerInfo[index], buffer); |
| 1570 | index++; |
| 1571 | } |
| 1572 | |
| 1573 | // Print out playernum |
| 1574 | snprintf(buffer, sizeof(buffer), DTXT_PLRNUMFORMAT, pnum); |
| 1575 | strcpy(DMFCPlayerInfo[index], buffer); |
| 1576 | index++; |
| 1577 | |
| 1578 | #ifdef _DEBUG |
| 1579 | display_addr = true; |
| 1580 | #endif |
| 1581 | if (GetLocalRole() == LR_SERVER) |
| 1582 | display_addr = true; |
| 1583 | |
| 1584 | // Print out net address |
| 1585 | if (display_addr) { |
| 1586 | network_protocol proto = NP_NONE; |
| 1587 | |
| 1588 | if (pnum != GetPlayerNum()) |
| 1589 | proto = NetPlayers[pnum].addr.connection_type; |
| 1590 | else |
| 1591 | proto = NP_TCP; |
| 1592 | |
| 1593 | if (proto != NP_NONE) { |
| 1594 | char string[32]; |
| 1595 | if (pnum != 0) { |
| 1596 | DLLnw_GetNumbersFromHostAddress(&NetPlayers[pnum].addr, string); |
| 1597 | } else { |
| 1598 | int addr = DLLnw_GetThisIP(); |
| 1599 | network_address local_addr; |
| 1600 | memset(&local_addr, 0, sizeof(network_address)); |
| 1601 | memcpy(local_addr.address, &addr, sizeof(int)); |
| 1602 | local_addr.connection_type = NP_TCP; |
| 1603 | |
| 1604 | DLLnw_GetNumbersFromHostAddress(&local_addr, string); |
| 1605 | } |
| 1606 | strcpy(DMFCPlayerInfo[index], string); |
| 1607 | index++; |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | // Print out Ship info |
| 1612 | snprintf(buffer, sizeof(buffer), DTXT_SHIPFORM, Ships[Players[pnum].ship_index].name); |
| 1613 | strcpy(DMFCPlayerInfo[index], buffer); |
| 1614 | index++; |
| 1615 | |
| 1616 | for (; index < 5; index++) { |
| 1617 | DMFCPlayerInfo[index][0] = '\0'; |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | void DMFCBase::DisplayPlayerInfo(int background_bmp, bool dedicated_server) { |
| 1622 | DLLgrtext_SetFont(Game_fonts[HUD_FONT_INDEX]); |
| 1623 | |
| 1624 | int height = DLLgrfont_GetHeight(Game_fonts[HUD_FONT_INDEX]) + 1; |
| 1625 | // int height = DLLRenderHUDGetTextHeight("X")+1; |
| 1626 | ddgr_color color = GR_RGB(180, 255, 180); |
| 1627 | int x, y; |
| 1628 | y = 0; |
| 1629 | x = 15; |
| 1630 | int index = 0; |
| 1631 | |
| 1632 | if (!CheckPlayerNum(m_iPlayerDisplayed)) { |
| 1633 | m_iPlayerDisplayed = -1; |
| 1634 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPPLAYERINFO); |
| 1635 | return; |
| 1636 | } |
| 1637 | |
| 1638 | if ((m_iProtectedFlags & DMFC_PRF_DISPMENUBACKGR) && background_bmp > BAD_BITMAP_HANDLE) { |
| 1639 | // draw the background bitmap |
| 1640 | DLLrend_SetAlphaValue(255 * 0.85f); |
| 1641 | DLLrend_SetZBufferState(0); |
| 1642 | DLLrend_SetTextureType(TT_LINEAR); |
| 1643 | DLLrend_SetLighting(LS_NONE); |
| 1644 | DLLrend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 1645 | DLLrend_DrawScaledBitmap(0, 0, *Game_window_w, 6 * height, background_bmp, 0, 0, 1, 1, 1.0, -1, NULL); |
| 1646 | DLLrend_SetZBufferState(1); |
| 1647 | } |
| 1648 | |
| 1649 | // Print out callsign |
| 1650 | // DLLRenderHUDText(color,255,0,x,y,DMFCPlayerInfo[index]); y+=height; |
| 1651 | DLLgrtext_SetColor(color); |
| 1652 | DLLgrtext_SetAlpha(255); |
| 1653 | DLLgrtext_Printf(x, y, DMFCPlayerInfo[index]); |
| 1654 | y += height; |
| 1655 | |
| 1656 | if (dedicated_server) |
| 1657 | DPrintf("%s\n", DMFCPlayerInfo[index]); |
| 1658 | index++; |
| 1659 | color = GR_RGB(40, 255, 40); |
| 1660 | |
| 1661 | for (; index < 5; index++) { |
| 1662 | // DLLRenderHUDText(color,255,0,x,y,DMFCPlayerInfo[index]); |
| 1663 | DLLgrtext_SetColor(color); |
| 1664 | DLLgrtext_SetAlpha(255); |
| 1665 | DLLgrtext_Printf(x, y, DMFCPlayerInfo[index]); |
| 1666 | |
| 1667 | if (DMFCPlayerInfo[index][0] != '\0') |
| 1668 | y += height; |
| 1669 | if (dedicated_server) |
| 1670 | DPrintf("%s\n", DMFCPlayerInfo[index]); |
| 1671 | } |
| 1672 | |
| 1673 | // print out the volatile information |
| 1674 | player_record *pr = PRec_GetPRecordByPnum(m_iPlayerDisplayed); |
| 1675 | char temp[150]; |
| 1676 | |
| 1677 | if (!pr || pr->state != STATE_INGAME) |
| 1678 | return; |
| 1679 | |
| 1680 | int precindex = translate_precptr_to_index(pr); |
| 1681 | float ti = GetTimeInGame(precindex); |
| 1682 | |
| 1683 | snprintf(temp, sizeof(temp), DTXT_PI_TIMEINGAME, GetTimeString(ti)); |
| 1684 | // DLLRenderHUDText(color,255,0,x,y,temp); y+=height; |
| 1685 | DLLgrtext_SetColor(color); |
| 1686 | DLLgrtext_SetAlpha(255); |
| 1687 | DLLgrtext_Printf(x, y, temp); |
| 1688 | y += height; |
| 1689 | |
| 1690 | if (dedicated_server) |
| 1691 | DPrintf("%s\n", temp); |
| 1692 | } |
| 1693 | |
| 1694 | // DMFCBase::SwitchPlayerInfoDisplay |
| 1695 | // |
| 1696 | // Switches on/off displaying a Playerinfo |
| 1697 | void DMFCBase::SwitchPlayerInfoDisplay(int pnum) { |
| 1698 | m_iProtectedFlags ^= DMFC_PRF_DISPPLAYERINFO; |
| 1699 | if (m_iProtectedFlags & DMFC_PRF_DISPPLAYERINFO) { |
| 1700 | |
| 1701 | if (IsDisplayingNetGameInfo()) // if we are displaying netgame info, turn it off |
| 1702 | SwitchNetGameInfoDisplay(0); |
| 1703 | |
| 1704 | if (!CheckPlayerNum(pnum)) { |
| 1705 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPPLAYERINFO); |
| 1706 | return; |
| 1707 | } |
| 1708 | SetPlayerInfo(pnum); |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | // DMFCBase::SwitchNetGameInfoDisplay |
| 1713 | // |
| 1714 | // Switches on/off displaying netgame info |
| 1715 | void DMFCBase::SwitchNetGameInfoDisplay(int on) { |
| 1716 | if (on) |
| 1717 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPNETGAMEINFO); |
| 1718 | else |
| 1719 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPNETGAMEINFO); |
| 1720 | |
| 1721 | if (on) { |
| 1722 | if (DisplayingPlayerInfo() != -1) { |
| 1723 | // turn on displaying of player info before displaying netgame info |
| 1724 | SwitchPlayerInfoDisplay(-1); |
| 1725 | } |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | // DMFCBase::IsDisplayingNetGameInfo |
| 1730 | // |
| 1731 | // returns true if we are currently displaying netgame info |
| 1732 | bool DMFCBase::IsDisplayingNetGameInfo(void) { return (m_iProtectedFlags & DMFC_PRF_DISPNETGAMEINFO) ? true : false; } |
| 1733 | |
| 1734 | // DMFCBase::DisplayingPlayerInfo |
| 1735 | // |
| 1736 | // Returns the pnum of the player info being displayed, -1 if none |
| 1737 | int DMFCBase::DisplayingPlayerInfo(void) { |
| 1738 | if (m_iProtectedFlags & DMFC_PRF_DISPPLAYERINFO) |
| 1739 | return m_iPlayerDisplayed; |
| 1740 | else |
| 1741 | return -1; |
| 1742 | } |
| 1743 | |
| 1744 | // DMFCBase::SetTeamName |
| 1745 | // |
| 1746 | // Sets the team name for a given team |
| 1747 | // team: integer value of the team to change |
| 1748 | // name: new name for the team |
| 1749 | // announce: if this is true, and we are the server, it will tell all the clients about the change |
| 1750 | bool DMFCBase::SetTeamName(int team, const char *name, bool announce) { |
| 1751 | if (team < 0 || team > DLLMAX_TEAMS) |
| 1752 | return false; |
| 1753 | if (!name) |
| 1754 | return false; |
| 1755 | |
| 1756 | char old_teamname[MAX_TEAMNAME_LEN]; |
| 1757 | strcpy(old_teamname, DMFC_team_names[team]); |
| 1758 | |
| 1759 | strncpy(DMFC_team_names[team], name, MAX_TEAMNAME_LEN - 1); |
| 1760 | DMFC_team_names[team][MAX_TEAMNAME_LEN - 1] = '\0'; |
| 1761 | |
| 1762 | CallOnTeamChangeName(team, old_teamname, DMFC_team_names[team]); |
| 1763 | |
| 1764 | if (announce && GetLocalRole() == LR_SERVER) { |
| 1765 | // tell the clients about the new team name |
| 1766 | SendNewTeamName(team); |
| 1767 | DPrintf(DTXT_SETTEAMNAME, old_teamname, name); |
| 1768 | } |
| 1769 | |
| 1770 | return true; |
| 1771 | } |
| 1772 | |
| 1773 | // DMFCBase::GetTeamFromString |
| 1774 | // |
| 1775 | // Returns the int value of a team based on a string, -1 if not a team |
| 1776 | int DMFCBase::GetTeamFromString(char *str) { |
| 1777 | if (!str) |
| 1778 | return -1; |
| 1779 | for (int i = 0; i < DLLMAX_TEAMS; i++) { |
| 1780 | if (!stricmp(str, DMFC_team_names[i])) |
| 1781 | return i; |
| 1782 | } |
| 1783 | return -1; |
| 1784 | } |
| 1785 | |
| 1786 | // DMFCBase::GetPlayerNum |
| 1787 | // |
| 1788 | // Returns your playernum, useful when finding out if an event is referring to you (by looking at |
| 1789 | // the playernum passed to the event handler, compared to your playernum |
| 1790 | int DMFCBase::GetPlayerNum(void) { return *Player_num; } |
| 1791 | |
| 1792 | // DMFCBase::GetLocalRole |
| 1793 | // |
| 1794 | // Returns your role in the multiplayer game. The result returned will be either LR_SERVER or LR_CLIENT |
| 1795 | int DMFCBase::GetLocalRole(void) { return Netgame->local_role; } |
| 1796 | |
| 1797 | // DMFCBase::CheckPlayerNum |
| 1798 | // |
| 1799 | // Returns true if the player number passed in is a valid player number (the player is connected) |
| 1800 | bool DMFCBase::CheckPlayerNum(int player_num) { |
| 1801 | if ((player_num < 0) || (player_num >= DLLMAX_PLAYERS)) |
| 1802 | return false; |
| 1803 | if ((NetPlayers[player_num].flags & NPF_CONNECTED) && (NetPlayers[player_num].sequence >= NETSEQ_PLAYING)) |
| 1804 | return true; |
| 1805 | else |
| 1806 | return false; |
| 1807 | } |
| 1808 | |
| 1809 | // DMFCBase::PacketCheckPlayerNum |
| 1810 | // |
| 1811 | // Returns true if it's ok to send a packet to this player |
| 1812 | bool DMFCBase::PacketCheckPlayerNum(int player_num) { |
| 1813 | if ((player_num < 0) || (player_num >= DLLMAX_PLAYERS)) |
| 1814 | return false; |
| 1815 | if ((NetPlayers[player_num].flags & NPF_CONNECTED) && (NetPlayers[player_num].sequence >= NETSEQ_OBJECTS)) |
| 1816 | return true; |
| 1817 | else |
| 1818 | return false; |
| 1819 | } |
| 1820 | |
| 1821 | // DMFCBase::CallClientEvent |
| 1822 | // |
| 1823 | // Server Only. This will send an event to a client for it to execute. |
| 1824 | // event = An EVT_CLIENT_* |
| 1825 | // me_objnum,it_objnum = Object numbers of the objects to be me and it for the event |
| 1826 | // destination = Player number of the client to send to, 0or -1 if to send to all |
| 1827 | void DMFCBase::CallClientEvent(int event, int me_objnum, int it_objnum, int destination, bool parms) { |
| 1828 | if (GetLocalRole() != LR_SERVER) |
| 1829 | return; |
| 1830 | if ((destination < -1) || (destination > DLLMAX_PLAYERS)) |
| 1831 | return; |
| 1832 | DLLMultiSendClientExecuteDLL(event, me_objnum, it_objnum, destination, parms ? Data : NULL); |
| 1833 | } |
| 1834 | |
| 1835 | // DMFCBase::GetTimeLeft |
| 1836 | // |
| 1837 | // Server Only. This will fill in the float pointer passed to it with how much time is |
| 1838 | // left in the multiplayer game. The value placed in the float is only valid if GetTimeLeft |
| 1839 | // returns true. If it returns false it was because either it is not a game with a time limit |
| 1840 | // or it is being called on a client. |
| 1841 | bool DMFCBase::GetTimeLeft(float *time) { |
| 1842 | if (GetLocalRole() != LR_SERVER) |
| 1843 | return false; |
| 1844 | if (Netgame->flags & NF_TIMER) { |
| 1845 | *time = (Netgame->timelimit * 60.0f) - RealGametime; |
| 1846 | return true; |
| 1847 | } |
| 1848 | return false; |
| 1849 | } |
| 1850 | |
| 1851 | // DMFCBase::EndLevel |
| 1852 | // |
| 1853 | // Server Only. This will end the current multiplayer level, and will go on to the next level. |
| 1854 | void DMFCBase::EndLevel(void) { |
| 1855 | if (GetLocalRole() != LR_SERVER) |
| 1856 | return; |
| 1857 | DLLMultiEndLevel(); |
| 1858 | } |
| 1859 | |
| 1860 | // DMFCBase::GetScoreLimit |
| 1861 | // |
| 1862 | // Server Only. This will fill in the int pointer passed to it with what the scoring limit |
| 1863 | // is, set in in the multiplayer options. The value point into the int is only valid if |
| 1864 | // GetScoreLimit returns true. If it returns false it is because you are either not the |
| 1865 | // server or this option wasn't set in the multiplayer options |
| 1866 | bool DMFCBase::GetScoreLimit(int *limit) { |
| 1867 | if (GetLocalRole() != LR_SERVER) |
| 1868 | return false; |
| 1869 | if (Netgame->flags & NF_KILLGOAL) { |
| 1870 | *limit = Netgame->killgoal; |
| 1871 | return true; |
| 1872 | } |
| 1873 | return false; |
| 1874 | } |
| 1875 | |
| 1876 | // DMFCBase::AutoTimeLimit |
| 1877 | // |
| 1878 | // Server Only. This turns off or on the automatic level ending by DMFC of a timed multiplayer game. |
| 1879 | // If you turn it off, it is your responsibility to end a time multiplayer game when it's time |
| 1880 | // is up. If it is turned on, DMFC will automatically handle ending the game. By default it is on. |
| 1881 | void DMFCBase::AutoTimeLimit(bool turnon) { |
| 1882 | if (GetLocalRole() != LR_SERVER) |
| 1883 | return; |
| 1884 | if ((Netgame->flags & NF_TIMER) == 0) |
| 1885 | return; |
| 1886 | if (turnon) |
| 1887 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOTIMELIMIT); |
| 1888 | else |
| 1889 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOTIMELIMIT); |
| 1890 | } |
| 1891 | |
| 1892 | // DMFCBase::AutoDeathMessage |
| 1893 | // |
| 1894 | // This turns on or off DMFC's automatic handling of death messages. If it is turned on (Default) |
| 1895 | // then when a player dies it will display a random death message from the list added by you using |
| 1896 | // AddDeathMessage. If it is turned off, then it is your responsibility to handle the messages, you |
| 1897 | // can use DoRandomDeathMessage to display one when appropriate. |
| 1898 | void DMFCBase::AutoDeathMessage(bool turnon) { |
| 1899 | if (turnon) |
| 1900 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTODEATHMSG); |
| 1901 | else |
| 1902 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTODEATHMSG); |
| 1903 | } |
| 1904 | |
| 1905 | // DMFCBase::AddDeathMessage |
| 1906 | // |
| 1907 | // This will add a death message to DMFC. |
| 1908 | // format = string in a "printf" type format (using %s for player callsigns) of the message |
| 1909 | // victim_first = Set this to true if the victim is listed first in the format |
| 1910 | void DMFCBase::AddDeathMessage(const char *string, bool victim_first) { |
| 1911 | if ((m_iDeathMsgCount >= 0) && (m_iDeathMsgCount < MAX_DEATH_MSGS)) { |
| 1912 | DeathMsgs[m_iDeathMsgCount].message = (char *)malloc(strlen(string) + 1); |
| 1913 | if (DeathMsgs[m_iDeathMsgCount].message) { |
| 1914 | DeathMsgs[m_iDeathMsgCount].inuse = true; |
| 1915 | DeathMsgs[m_iDeathMsgCount].victim_first = victim_first; |
| 1916 | strcpy(DeathMsgs[m_iDeathMsgCount].message, string); |
| 1917 | m_iDeathMsgCount++; |
| 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | // DMFCBase::AddSuicideMessage |
| 1923 | // |
| 1924 | // This will add a death message to DMFC. |
| 1925 | // format = string in a "printf" type format (using %s for player callsigns) of the message |
| 1926 | void DMFCBase::AddSuicideMessage(const char *string) { |
| 1927 | if ((m_iSuicideMsgCount >= 0) && (m_iSuicideMsgCount < MAX_DEATH_MSGS)) { |
| 1928 | SuicideMsgs[m_iSuicideMsgCount].message = (char *)malloc(strlen(string) + 1); |
| 1929 | if (SuicideMsgs[m_iSuicideMsgCount].message) { |
| 1930 | SuicideMsgs[m_iSuicideMsgCount].inuse = true; |
| 1931 | strcpy(SuicideMsgs[m_iSuicideMsgCount].message, string); |
| 1932 | m_iSuicideMsgCount++; |
| 1933 | } |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | // DMFCBase::GetItObjNum |
| 1938 | // |
| 1939 | // Returns the it object number of the current event for use. |
| 1940 | int DMFCBase::GetItObjNum(void) { |
| 1941 | if (Data->it_handle == OBJECT_HANDLE_NONE) |
| 1942 | return -1; |
| 1943 | |
| 1944 | return Data->it_handle & HANDLE_OBJNUM_MASK; |
| 1945 | } |
| 1946 | |
| 1947 | // DMFCBase::GetMeObjNum |
| 1948 | // |
| 1949 | // Returns the me object number of the current event for use. |
| 1950 | int DMFCBase::GetMeObjNum(void) { |
| 1951 | if (Data->me_handle == OBJECT_HANDLE_NONE) |
| 1952 | return -1; |
| 1953 | return Data->me_handle & HANDLE_OBJNUM_MASK; |
| 1954 | } |
| 1955 | |
| 1956 | // DMFCBase::OnGameStateRequest |
| 1957 | // |
| 1958 | // Server only. Override this to listen for Game state requests from the clients |
| 1959 | // When this function is called a client (who's player number is passed in) is requesting |
| 1960 | // game state information. Do what you need to do to send game state information to that player |
| 1961 | void DMFCBase::OnGameStateRequest(int pnum) { |
| 1962 | if (pnum == -1) |
| 1963 | return; |
| 1964 | mprintf(0, "%s is requesting Game State information\n", Players[pnum].callsign); |
| 1965 | } |
| 1966 | |
| 1967 | // DMFCBase::GetTeamForNewPlayer |
| 1968 | // |
| 1969 | // A Helper function (Server only), which will give you the optimum team assignment (whoever has the |
| 1970 | // lowest amount of players on their team, for a new player. |
| 1971 | // player_num = player number of the new player |
| 1972 | // num_teams = The number of teams in your game |
| 1973 | int DMFCBase::GetTeamForNewPlayer(int player_num, int num_teams) { |
| 1974 | if ((player_num < 0) || (player_num >= DLLMAX_PLAYERS)) |
| 1975 | return 0; |
| 1976 | |
| 1977 | // see if it's a dedicated server game, and if so, are we the server |
| 1978 | if (IAmDedicatedServer() && (player_num == GetPlayerNum())) { |
| 1979 | return -1; // place on the special "no team" |
| 1980 | } |
| 1981 | |
| 1982 | int i; |
| 1983 | int *Teams; |
| 1984 | Teams = (int *)malloc(sizeof(int) * num_teams); |
| 1985 | if (!Teams) |
| 1986 | return 0; |
| 1987 | |
| 1988 | for (i = 0; i < num_teams; i++) |
| 1989 | Teams[i] = 0; |
| 1990 | |
| 1991 | for (i = 0; i < DLLMAX_PLAYERS; i++) { |
| 1992 | if ((i != player_num) && (CheckPlayerNum(i)) && (Players[i].team != -1)) { |
| 1993 | if (Players[i].team < num_teams) |
| 1994 | Teams[Players[i].team]++; |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | int low_team, low_count; |
| 1999 | |
| 2000 | low_count = Teams[0]; |
| 2001 | low_team = 0; |
| 2002 | |
| 2003 | for (i = 0; i < num_teams; i++) { |
| 2004 | if (low_count > Teams[i]) { |
| 2005 | low_count = Teams[i]; |
| 2006 | low_team = i; |
| 2007 | } |
| 2008 | } |
| 2009 | free(Teams); |
| 2010 | return low_team; |
| 2011 | } |
| 2012 | |
| 2013 | // DMFCBase::SetNumberOfTeams |
| 2014 | // |
| 2015 | // Sets the number of teams to be used in the game. By default there is 1 team (everyone against everyone). |
| 2016 | // You can set up to a maximum of 4 teams. Call this function as soon as possible. |
| 2017 | // teams = number of teams |
| 2018 | void DMFCBase::SetNumberOfTeams(int teams) { |
| 2019 | if ((teams < 1) || (teams > 4)) |
| 2020 | return; |
| 2021 | |
| 2022 | DLLSetMaxTeams(teams); |
| 2023 | DLLMultiPaintGoalRooms(NULL); |
| 2024 | |
| 2025 | m_iNumTeams = teams; |
| 2026 | |
| 2027 | char names[DLLMAX_TEAMS][MAX_TEAMNAME_LEN]; |
| 2028 | strcpy(names[RED_TEAM], GetTeamString(RED_TEAM)); |
| 2029 | strcpy(names[BLUE_TEAM], GetTeamString(BLUE_TEAM)); |
| 2030 | if (TeamMenuItem) { |
| 2031 | switch (m_iNumTeams) { |
| 2032 | case 2: |
| 2033 | TeamMenuItem->SetStateItemList(m_iNumTeams, names[RED_TEAM], names[BLUE_TEAM]); |
| 2034 | break; |
| 2035 | case 3: |
| 2036 | strcpy(names[GREEN_TEAM], GetTeamString(GREEN_TEAM)); |
| 2037 | TeamMenuItem->SetStateItemList(m_iNumTeams, names[RED_TEAM], names[BLUE_TEAM], names[GREEN_TEAM]); |
| 2038 | break; |
| 2039 | case 4: |
| 2040 | strcpy(names[GREEN_TEAM], GetTeamString(GREEN_TEAM)); |
| 2041 | strcpy(names[YELLOW_TEAM], GetTeamString(YELLOW_TEAM)); |
| 2042 | TeamMenuItem->SetStateItemList(m_iNumTeams, names[RED_TEAM], names[BLUE_TEAM], names[GREEN_TEAM], |
| 2043 | names[YELLOW_TEAM]); |
| 2044 | break; |
| 2045 | } |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | // DMFCBase::AutoTeamSelect |
| 2050 | // |
| 2051 | // Turns on or off DMFC's auto team assignment. If it is on, then when a new player joins, they will |
| 2052 | // be placed on the team with fewest players. If it is off, then you must handle that. Defualt on. |
| 2053 | void DMFCBase::AutoTeamSelect(bool turnon) { |
| 2054 | if (turnon) |
| 2055 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOTEAMSELECT); |
| 2056 | else |
| 2057 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOTEAMSELECT); |
| 2058 | } |
| 2059 | |
| 2060 | // DMFCBase::RequestChangeTeams |
| 2061 | // |
| 2062 | // If you are the server it will make the player change teams. If you |
| 2063 | // are a client then it sends a request to the server to change teams |
| 2064 | void DMFCBase::RequestTeamChange(int team, int pnum, bool spew_on_respawn) { |
| 2065 | if (!CheckPlayerNum(pnum)) |
| 2066 | return; |
| 2067 | if (Players[pnum].team == -1) // Dedicated server can't change teams |
| 2068 | return; |
| 2069 | if ((team < 0) || (team >= m_iNumTeams)) |
| 2070 | return; |
| 2071 | if (Players[pnum].team == team) |
| 2072 | return; |
| 2073 | |
| 2074 | if (GetLocalRole() == LR_SERVER) { |
| 2075 | if (!AllowTeamChange()) { |
| 2076 | return; |
| 2077 | } |
| 2078 | if (!CallOnCanChangeTeam(pnum, team)) { |
| 2079 | return; |
| 2080 | } |
| 2081 | |
| 2082 | Players[pnum].team = team; |
| 2083 | CallOnPlayerChangeTeam(pnum, team, true, spew_on_respawn); |
| 2084 | SendTeamAssignment(pnum, team, spew_on_respawn); |
| 2085 | } else { |
| 2086 | if (pnum != GetPlayerNum()) |
| 2087 | return; |
| 2088 | SendChangeTeamRequest(team, spew_on_respawn); |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | // DMFCBase::AddHudItemCallback |
| 2093 | // |
| 2094 | // Adds an item to the hud. Everytime the hud needs to be updated, it will call the |
| 2095 | // handler passed in. The handler must be declared as: |
| 2096 | // void func(struct tHUDItem *item); |
| 2097 | // type = HI_BITMAP for bitmap, HI_TEXT for a text item |
| 2098 | // func = function callback |
| 2099 | void DMFCBase::AddHUDItemCallback(int type, void (*func)(struct tHUDItem *)) { |
| 2100 | // add all the needed Hud Items |
| 2101 | tHUDItem item; |
| 2102 | switch (type) { |
| 2103 | case HI_TEXT: |
| 2104 | item.type = HUD_ITEM_CUSTOMTEXT; |
| 2105 | break; |
| 2106 | case HI_BITMAP: |
| 2107 | item.type = HUD_ITEM_CUSTOMIMAGE; |
| 2108 | break; |
| 2109 | default: |
| 2110 | item.type = HUD_ITEM_CUSTOMTEXT; |
| 2111 | break; |
| 2112 | } |
| 2113 | item.stat = STAT_CUSTOM; |
| 2114 | item.flags = HUD_FLAG_PERSISTANT; |
| 2115 | item.data.text = NULL; |
| 2116 | item.render_fn = func; |
| 2117 | item.y = 0; |
| 2118 | item.x = 0; |
| 2119 | DLLAddHUDItem(&item); |
| 2120 | } |
| 2121 | |
| 2122 | // DMFCBase::GetMyTeam |
| 2123 | // |
| 2124 | // Returns the int value of the team you are on...only useful in a team game. |
| 2125 | int DMFCBase::GetMyTeam(void) { return Players[GetPlayerNum()].team; } |
| 2126 | |
| 2127 | // DMFCBase::GetTeamString |
| 2128 | // |
| 2129 | // Returns a pointer to a string name of a team |
| 2130 | // team = integer value of the team |
| 2131 | const char *DMFCBase::GetTeamString(int team) { |
| 2132 | static char name[20]; |
| 2133 | |
| 2134 | if (team >= 0 && team < DLLMAX_TEAMS) |
| 2135 | strcpy(name, DMFC_team_names[team]); |
| 2136 | else |
| 2137 | strcpy(name, DTXT_LONER); |
| 2138 | |
| 2139 | return name; |
| 2140 | } |
| 2141 | |
| 2142 | // DMFCBase::GetTeamColor |
| 2143 | // |
| 2144 | // Returns the color components of a team |
| 2145 | // team = integer value of the team |
| 2146 | ddgr_color DMFCBase::GetTeamColor(int team) { |
| 2147 | switch (team) { |
| 2148 | case RED_TEAM: |
| 2149 | return GR_RGB(255, 40, 40); |
| 2150 | break; |
| 2151 | case BLUE_TEAM: |
| 2152 | return GR_RGB(40, 40, 255); |
| 2153 | break; |
| 2154 | case GREEN_TEAM: |
| 2155 | return GR_RGB(40, 255, 40); |
| 2156 | break; |
| 2157 | case YELLOW_TEAM: |
| 2158 | return GR_RGB(255, 255, 40); |
| 2159 | break; |
| 2160 | default: |
| 2161 | return GR_RGB(255, 255, 255); |
| 2162 | break; |
| 2163 | } |
| 2164 | } |
| 2165 | |
| 2166 | // DMFCBase::GetNumTeams |
| 2167 | // |
| 2168 | // Returns the number of teams in the game |
| 2169 | int DMFCBase::GetNumTeams(void) { return m_iNumTeams; } |
| 2170 | |
| 2171 | // DMFCBase::AllowTeamChange |
| 2172 | // |
| 2173 | // Returns true if team changing is allowed |
| 2174 | bool DMFCBase::AllowTeamChange(void) { return (m_iProtectedFlags & DMFC_PRF_CANTEAMCHANGE) ? true : false; } |
| 2175 | |
| 2176 | // DMFCBase::SwitchAllowTeamChange |
| 2177 | // |
| 2178 | // Turns on/off allowing of team changing |
| 2179 | void DMFCBase::SwitchAllowTeamChange(bool turnon) { |
| 2180 | if (turnon) |
| 2181 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_CANTEAMCHANGE); |
| 2182 | else |
| 2183 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_CANTEAMCHANGE); |
| 2184 | } |
| 2185 | |
| 2186 | // DMFCBase::IsMenuUp |
| 2187 | // |
| 2188 | // Returns true if the on screen menu is being shown |
| 2189 | bool DMFCBase::IsMenuUp(void) { return (m_iProtectedFlags & DMFC_PRF_INOPTIONS) ? true : false; } |
| 2190 | |
| 2191 | // DMFCBase::ClipString |
| 2192 | // |
| 2193 | // Given a width, the string will be clipped to that width. If you pass true for arrow, then an arrow will be |
| 2194 | // appended if the string has been clipped. Based off current font |
| 2195 | void DMFCBase::ClipString(int width, char *string, bool arrow) { |
| 2196 | if (!string) |
| 2197 | return; |
| 2198 | |
| 2199 | // float ratio = DEFAULT_HUD_WIDTH / ((float)*Game_window_w); |
| 2200 | |
| 2201 | int string_length = strlen(string); |
| 2202 | char arrow_string[2]; |
| 2203 | int arrow_length = 0; |
| 2204 | snprintf(arrow_string, sizeof(arrow_string), "%c", CHAR_RIGHT_ARROW); |
| 2205 | if (arrow) { |
| 2206 | // arrow_length = ratio * ((float)DLLRenderHUDGetTextLineWidth(arrow_string)); |
| 2207 | arrow_length = DLLgrtext_GetTextLineWidth(arrow_string); |
| 2208 | } |
| 2209 | |
| 2210 | if (width < arrow_length) { |
| 2211 | // Nothing can fit |
| 2212 | strcpy(string, ""); |
| 2213 | return; |
| 2214 | } |
| 2215 | |
| 2216 | // adjust width based on the arrow |
| 2217 | width -= arrow_length; |
| 2218 | |
| 2219 | int size = 0; |
| 2220 | char save = string[0]; |
| 2221 | while (size < string_length) { |
| 2222 | string[size] = '\0'; |
| 2223 | // if((((float)DLLRenderHUDGetTextLineWidth(string))*ratio)>=width){ |
| 2224 | if (DLLgrtext_GetTextLineWidth(string) >= width) { |
| 2225 | // We have to clip |
| 2226 | size--; |
| 2227 | if (arrow) { |
| 2228 | string[size] = CHAR_RIGHT_ARROW; |
| 2229 | string[size + 1] = '\0'; |
| 2230 | } |
| 2231 | return; |
| 2232 | } |
| 2233 | // replace the char and move to the next |
| 2234 | string[size] = save; |
| 2235 | size++; |
| 2236 | save = string[size]; |
| 2237 | } |
| 2238 | // The string didn't need to be clipped |
| 2239 | } |
| 2240 | |
| 2241 | // DMFCBase::ConvertHUDAlpha |
| 2242 | // |
| 2243 | // Returns a converted alpha based on what you give, it will be a more transparent if the onscreen menu is up |
| 2244 | float DMFCBase::ConvertHUDAlpha(float normal) { |
| 2245 | if (!IsMenuUp()) |
| 2246 | return normal; |
| 2247 | return normal * 0.3f; |
| 2248 | } |
| 2249 | uint8_t DMFCBase::ConvertHUDAlpha(uint8_t normal) { |
| 2250 | if (!IsMenuUp()) |
| 2251 | return normal; |
| 2252 | |
| 2253 | float conv = ((float)normal); |
| 2254 | conv = conv * 0.3f; |
| 2255 | return (uint8_t)conv; |
| 2256 | } |
| 2257 | |
| 2258 | bool DMFCBase::DMFC_compare_slots(int a, int b) { |
| 2259 | int ascore, bscore; |
| 2260 | player_record *apr, *bpr; |
| 2261 | apr = GetPlayerRecord(a); |
| 2262 | bpr = GetPlayerRecord(b); |
| 2263 | if (!apr) |
| 2264 | return true; |
| 2265 | if (!bpr) |
| 2266 | return false; |
| 2267 | if (apr->state == STATE_EMPTY) |
| 2268 | return true; |
| 2269 | if (bpr->state == STATE_EMPTY) |
| 2270 | return false; |
| 2271 | if ((apr->state == STATE_INGAME) && (bpr->state == STATE_INGAME)) { |
| 2272 | // both players were in the game |
| 2273 | ascore = apr->dstats.kills[DSTAT_LEVEL] - apr->dstats.suicides[DSTAT_LEVEL]; |
| 2274 | bscore = bpr->dstats.kills[DSTAT_LEVEL] - bpr->dstats.suicides[DSTAT_LEVEL]; |
| 2275 | return (ascore < bscore); |
| 2276 | } |
| 2277 | if ((apr->state == STATE_INGAME) && (bpr->state == STATE_DISCONNECTED)) { |
| 2278 | // apr gets priority since he was in the game on exit |
| 2279 | return false; |
| 2280 | } |
| 2281 | if ((apr->state == STATE_DISCONNECTED) && (bpr->state == STATE_INGAME)) { |
| 2282 | // bpr gets priority since he was in the game on exit |
| 2283 | return true; |
| 2284 | } |
| 2285 | // if we got here then both players were disconnected |
| 2286 | ascore = apr->dstats.kills[DSTAT_LEVEL] - apr->dstats.suicides[DSTAT_LEVEL]; |
| 2287 | bscore = bpr->dstats.kills[DSTAT_LEVEL] - bpr->dstats.suicides[DSTAT_LEVEL]; |
| 2288 | return (ascore < bscore); |
| 2289 | } |
| 2290 | |
| 2291 | // kills/(kills+deaths+suicides) |
| 2292 | bool DMFCBase::DMFC_compare_slots_efficiency(int a, int b) { |
| 2293 | int ascore, bscore; |
| 2294 | player_record *apr, *bpr; |
| 2295 | float atemp, btemp; |
| 2296 | |
| 2297 | apr = GetPlayerRecord(a); |
| 2298 | bpr = GetPlayerRecord(b); |
| 2299 | if (!apr) |
| 2300 | return true; |
| 2301 | if (!bpr) |
| 2302 | return false; |
| 2303 | if (apr->state == STATE_EMPTY) |
| 2304 | return true; |
| 2305 | if (bpr->state == STATE_EMPTY) |
| 2306 | return false; |
| 2307 | if ((apr->state == STATE_INGAME) && (bpr->state == STATE_INGAME)) { |
| 2308 | // both players were in the game |
| 2309 | atemp = |
| 2310 | (float)(apr->dstats.kills[DSTAT_LEVEL] + apr->dstats.suicides[DSTAT_LEVEL] + apr->dstats.deaths[DSTAT_LEVEL]); |
| 2311 | ascore = (float)(apr->dstats.kills[DSTAT_LEVEL]) / ((atemp) ? atemp : 0.0000001f); |
| 2312 | |
| 2313 | btemp = |
| 2314 | (float)(bpr->dstats.kills[DSTAT_LEVEL] + bpr->dstats.suicides[DSTAT_LEVEL] + bpr->dstats.deaths[DSTAT_LEVEL]); |
| 2315 | bscore = (float)(bpr->dstats.kills[DSTAT_LEVEL]) / ((btemp) ? btemp : 0.0000001f); |
| 2316 | return (ascore < bscore); |
| 2317 | } |
| 2318 | if ((apr->state == STATE_INGAME) && (bpr->state == STATE_DISCONNECTED)) { |
| 2319 | // apr gets priority since he was in the game on exit |
| 2320 | return false; |
| 2321 | } |
| 2322 | if ((apr->state == STATE_DISCONNECTED) && (bpr->state == STATE_INGAME)) { |
| 2323 | // bpr gets priority since he was in the game on exit |
| 2324 | return true; |
| 2325 | } |
| 2326 | // if we got here then both players were disconnected |
| 2327 | atemp = (float)(apr->dstats.kills[DSTAT_LEVEL] + apr->dstats.suicides[DSTAT_LEVEL] + apr->dstats.deaths[DSTAT_LEVEL]); |
| 2328 | ascore = (float)(apr->dstats.kills[DSTAT_LEVEL]) / ((atemp) ? atemp : 0.0000001f); |
| 2329 | |
| 2330 | btemp = (float)(bpr->dstats.kills[DSTAT_LEVEL] + bpr->dstats.suicides[DSTAT_LEVEL] + bpr->dstats.deaths[DSTAT_LEVEL]); |
| 2331 | bscore = (float)(bpr->dstats.kills[DSTAT_LEVEL]) / ((btemp) ? btemp : 0.0000001f); |
| 2332 | return (ascore < bscore); |
| 2333 | } |
| 2334 | |
| 2335 | // DMFCBase::GetSortedPlayerSlots |
| 2336 | // |
| 2337 | // Fills in the passed array (of size maxsize) with the playernums sorted by (kills-suicides) |
| 2338 | void DMFCBase::GetSortedPlayerSlots(int *sortedindex, int maxsize) { |
| 2339 | int t; |
| 2340 | int i, j; |
| 2341 | int tempsort[MAX_PLAYER_RECORDS]; |
| 2342 | |
| 2343 | // copy scores into scoreinfo array |
| 2344 | for (i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 2345 | tempsort[i] = i; |
| 2346 | } |
| 2347 | |
| 2348 | for (i = 1; i <= MAX_PLAYER_RECORDS - 1; i++) { |
| 2349 | t = tempsort[i]; |
| 2350 | |
| 2351 | // Shift elements down until |
| 2352 | // insertion point found. |
| 2353 | for (j = i - 1; j >= 0 && DMFC_compare_slots(tempsort[j], t); j--) { |
| 2354 | tempsort[j + 1] = tempsort[j]; |
| 2355 | } |
| 2356 | |
| 2357 | // insert |
| 2358 | tempsort[j + 1] = t; |
| 2359 | } |
| 2360 | |
| 2361 | if (maxsize < MAX_PLAYER_RECORDS) |
| 2362 | memcpy(sortedindex, tempsort, maxsize * sizeof(int)); |
| 2363 | else |
| 2364 | memcpy(sortedindex, tempsort, MAX_PLAYER_RECORDS * sizeof(int)); |
| 2365 | } |
| 2366 | |
| 2367 | // DMFCBase::GetSortedPlayerSlotsByEfficiency |
| 2368 | // |
| 2369 | // Fills in the passed array (of size maxsize) with the playernums sorted by kills/(kills+deaths+suicides) |
| 2370 | void DMFCBase::GetSortedPlayerSlotsByEfficiency(int *sortedindex, int maxsize) { |
| 2371 | int t; |
| 2372 | int i, j; |
| 2373 | int tempsort[MAX_PLAYER_RECORDS]; |
| 2374 | |
| 2375 | // copy scores into scoreinfo array |
| 2376 | for (i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 2377 | tempsort[i] = i; |
| 2378 | } |
| 2379 | |
| 2380 | for (i = 1; i <= MAX_PLAYER_RECORDS - 1; i++) { |
| 2381 | t = tempsort[i]; |
| 2382 | |
| 2383 | // Shift elements down until |
| 2384 | // insertion point found. |
| 2385 | for (j = i - 1; j >= 0 && DMFC_compare_slots_efficiency(tempsort[j], t); j--) { |
| 2386 | tempsort[j + 1] = tempsort[j]; |
| 2387 | } |
| 2388 | |
| 2389 | // insert |
| 2390 | tempsort[j + 1] = t; |
| 2391 | } |
| 2392 | |
| 2393 | if (maxsize < MAX_PLAYER_RECORDS) |
| 2394 | memcpy(sortedindex, tempsort, maxsize * sizeof(int)); |
| 2395 | else |
| 2396 | memcpy(sortedindex, tempsort, MAX_PLAYER_RECORDS * sizeof(int)); |
| 2397 | } |
| 2398 | |
| 2399 | // DMFCBase::DisplayOutrageLogo(void) |
| 2400 | // |
| 2401 | // Displays the Outrage Logo for 5 seconds (call repeatedly, after 5 seconds it will just short circuit) |
| 2402 | // Doesn't do anything for non-Outrage games |
| 2403 | void DMFCBase::DisplayOutrageLogo(void) { |
| 2404 | if (!m_bDisplayOutrageLogo) |
| 2405 | return; |
| 2406 | |
| 2407 | #ifdef OUTRAGE_VERSION |
| 2408 | static bool done = false; |
| 2409 | static float time = 0; |
| 2410 | static bool loadflag = true; |
| 2411 | static chunked_bitmap bmp; |
| 2412 | |
| 2413 | if (done) |
| 2414 | return; |
| 2415 | |
| 2416 | if (loadflag) { |
| 2417 | // We need to load the handle |
| 2418 | loadflag = false; |
| 2419 | int temp = DLLbm_AllocLoadFileBitmap("Outlogo.ogf", 0, BITMAP_FORMAT_1555); |
| 2420 | DLLbm_CreateChunkedBitmap(temp, &bmp); |
| 2421 | DLLbm_FreeBitmap(temp); |
| 2422 | time = 0; |
| 2423 | } |
| 2424 | |
| 2425 | // draw the Outrage Logo if its time |
| 2426 | if (time < 5.0) { |
| 2427 | int x, y; |
| 2428 | x = (*Game_window_w) - bmp.pw; |
| 2429 | y = (*Game_window_h) - bmp.ph; |
| 2430 | DLLrend_DrawScaledChunkedBitmap(&bmp, x, y, bmp.pw, bmp.ph, 128); |
| 2431 | time += (*Frametime); |
| 2432 | } else { |
| 2433 | // we are done |
| 2434 | done = true; |
| 2435 | DLLbm_DestroyChunkedBitmap(&bmp); |
| 2436 | } |
| 2437 | #endif |
| 2438 | } |
| 2439 | |
| 2440 | // DMFCBase::SwitchShowHudCallsignLevel |
| 2441 | // |
| 2442 | // |
| 2443 | // Sets the level for displaying of Player's Callsigns on the HUD |
| 2444 | void DMFCBase::SwitchShowHudCallsignLevel(uint8_t level, bool announce) { |
| 2445 | m_iMyPreferredHUDCallsignLevel = level; |
| 2446 | |
| 2447 | if (level > m_iServerHUDCallsignLevel) |
| 2448 | level = m_iServerHUDCallsignLevel; |
| 2449 | |
| 2450 | if (m_iMyCurrentHUDCallsignLevel == level) |
| 2451 | return; |
| 2452 | |
| 2453 | m_iMyCurrentHUDCallsignLevel = level; |
| 2454 | |
| 2455 | switch (level) { |
| 2456 | case HUD_CALLSIGN_LEVEL_FULL: |
| 2457 | DLLPlayerSetHUDNameFOV(10); |
| 2458 | if (announce) |
| 2459 | DLLAddHUDMessage(DTXT_HUDLEVEL_FULL); |
| 2460 | break; |
| 2461 | case HUD_CALLSIGN_LEVEL_TEAM: |
| 2462 | DLLPlayerSetHUDNameFOV(10); |
| 2463 | if (announce) |
| 2464 | DLLAddHUDMessage(DTXT_HUDLEVEL_TEAM); |
| 2465 | break; |
| 2466 | case HUD_CALLSIGN_LEVEL_NONE: |
| 2467 | DLLPlayerSetHUDNameFOV(-1); |
| 2468 | if (announce) |
| 2469 | DLLAddHUDMessage(DTXT_HUDLEVEL_NONE); |
| 2470 | break; |
| 2471 | default: |
| 2472 | mprintf(0, "DMFC: Invalid HUD Name Level\n"); |
| 2473 | return; |
| 2474 | break; |
| 2475 | }; |
| 2476 | } |
| 2477 | |
| 2478 | // DMFCBase::SwitchServerHudCallsignLevel |
| 2479 | // |
| 2480 | // |
| 2481 | // Sets the max level of HUD callsign displayage...determined by the server |
| 2482 | void DMFCBase::SwitchServerHudCallsignLevel(uint8_t level) { |
| 2483 | switch (level) { |
| 2484 | case HUD_CALLSIGN_LEVEL_FULL: |
| 2485 | m_iServerHUDCallsignLevel = level; |
| 2486 | DLLAddHUDMessage(DTXT_SHUDLEVEL_FULL); |
| 2487 | break; |
| 2488 | case HUD_CALLSIGN_LEVEL_TEAM: |
| 2489 | m_iServerHUDCallsignLevel = level; |
| 2490 | DLLAddHUDMessage(DTXT_SHUDLEVEL_TEAM); |
| 2491 | break; |
| 2492 | case HUD_CALLSIGN_LEVEL_NONE: |
| 2493 | m_iServerHUDCallsignLevel = level; |
| 2494 | DLLAddHUDMessage(DTXT_SHUDLEVEL_NONE); |
| 2495 | break; |
| 2496 | default: |
| 2497 | mprintf(0, "DMFC: Invalid Server HUD Name Level\n"); |
| 2498 | return; |
| 2499 | break; |
| 2500 | } |
| 2501 | |
| 2502 | // make sure we're not set higher than the server allows |
| 2503 | SwitchShowHudCallsignLevel(m_iMyPreferredHUDCallsignLevel); |
| 2504 | |
| 2505 | if (GetLocalRole() == LR_SERVER) |
| 2506 | SendDMFCGameInfo(SP_ALL); |
| 2507 | } |
| 2508 | |
| 2509 | // DMFCBase::ShouldIDisplayHUDName |
| 2510 | // |
| 2511 | // Given a player num, it will determine if the callsign should be drawn on the HUD |
| 2512 | bool DMFCBase::ShouldIDisplayHUDName(int pnum) { |
| 2513 | switch (m_iMyCurrentHUDCallsignLevel) { |
| 2514 | case HUD_CALLSIGN_LEVEL_FULL: |
| 2515 | return true; |
| 2516 | break; |
| 2517 | case HUD_CALLSIGN_LEVEL_TEAM: { |
| 2518 | // see if this is a team game |
| 2519 | if (GetNumTeams() >= 2) { |
| 2520 | // ok it's a team game, see if this player is on my team, if so, than disply |
| 2521 | if (Players[pnum].team == GetMyTeam()) { |
| 2522 | return true; |
| 2523 | } else { |
| 2524 | return false; |
| 2525 | } |
| 2526 | } |
| 2527 | return false; |
| 2528 | } break; |
| 2529 | case HUD_CALLSIGN_LEVEL_NONE: |
| 2530 | return false; |
| 2531 | break; |
| 2532 | } |
| 2533 | return false; |
| 2534 | } |
| 2535 | |
| 2536 | // DMFCBase::GetCounterMeasureOwner |
| 2537 | // |
| 2538 | // |
| 2539 | // Given a counter measure it will determine the pnum of it's owner...if it can't find it, it returns -1 |
| 2540 | int DMFCBase::GetCounterMeasureOwner(object *robot) { |
| 2541 | if (!robot) |
| 2542 | return -1; |
| 2543 | |
| 2544 | if (robot->type != OBJ_ROBOT && (!(robot->type == OBJ_BUILDING && robot->ai_info))) |
| 2545 | return -1; |
| 2546 | |
| 2547 | object *killer; |
| 2548 | DLLGetUltimateParentForObject(&killer, robot); |
| 2549 | |
| 2550 | if (killer == robot) |
| 2551 | return -1; |
| 2552 | |
| 2553 | if ((killer->type != OBJ_PLAYER) && (killer->type != OBJ_OBSERVER)) |
| 2554 | return -1; |
| 2555 | |
| 2556 | return killer->id; |
| 2557 | } |
| 2558 | |
| 2559 | // DMFCBase::EncryptData |
| 2560 | // |
| 2561 | // Encrypts (weak) a buffer of data |
| 2562 | void DMFCBase::EncryptData(uint8_t *data, int size) { |
| 2563 | if (!data) |
| 2564 | return; |
| 2565 | if (size <= 0) |
| 2566 | return; |
| 2567 | |
| 2568 | int offset = size; |
| 2569 | |
| 2570 | for (int i = 0; i < size; i++) { |
| 2571 | data[i] = data[i] + i - (offset + i); |
| 2572 | offset++; |
| 2573 | } |
| 2574 | } |
| 2575 | |
| 2576 | // DMFCBase::DecryptData |
| 2577 | // |
| 2578 | // Decrypts a buffer of data |
| 2579 | void DMFCBase::DecryptData(uint8_t *data, int size) { |
| 2580 | if (!data) |
| 2581 | return; |
| 2582 | if (size <= 0) |
| 2583 | return; |
| 2584 | |
| 2585 | int offset = size; |
| 2586 | |
| 2587 | for (int i = 0; i < size; i++) { |
| 2588 | data[i] = data[i] - i + (offset + i); |
| 2589 | offset++; |
| 2590 | } |
| 2591 | } |
| 2592 | |
| 2593 | void DMFCBase::VersionCheck(int pnum) { SendVersionToClient(pnum); } |
| 2594 | |
| 2595 | // DMFCBase::FindPInfo |
| 2596 | // |
| 2597 | // Given a player number it will search the list and find that player, returning the pointer, or NULL if it |
| 2598 | // can't be found or created |
| 2599 | PInfo *DMFCBase::FindPInfo(int pnum) { |
| 2600 | ASSERT((pnum >= 0) && (pnum < DLLMAX_PLAYERS)); |
| 2601 | player_record *pr = GetPlayerRecordByPnum(pnum); |
| 2602 | if (!pr) |
| 2603 | return NULL; |
| 2604 | return pr->pinfo; |
| 2605 | } |
| 2606 | |
| 2607 | // DMFCBase::UpdatePInfo |
| 2608 | // |
| 2609 | // |
| 2610 | // Updates a victim's pinfo stat (pass in player nums) |
| 2611 | void DMFCBase::UpdatePInfo(int victim, int killer, int amount) { |
| 2612 | ASSERT((victim >= 0) || (victim < DLLMAX_PLAYERS) || (killer >= 0) || (killer < DLLMAX_PLAYERS)); |
| 2613 | if ((victim < 0) || (victim >= DLLMAX_PLAYERS) || (killer < 0) || (killer >= DLLMAX_PLAYERS)) { |
| 2614 | |
| 2615 | return; |
| 2616 | } |
| 2617 | |
| 2618 | PInfo *id; |
| 2619 | int victim_slot = PRec_GetPlayerSlot(victim); |
| 2620 | tPKillerInfo ki; |
| 2621 | |
| 2622 | memset(&ki, 0, sizeof(tPKillerInfo)); |
| 2623 | id = FindPInfo(killer); |
| 2624 | |
| 2625 | if ((id == NULL) || (victim_slot == -1)) { |
| 2626 | mprintf(0, "Unable to find PInfos\n"); |
| 2627 | return; |
| 2628 | } |
| 2629 | |
| 2630 | // update killer |
| 2631 | ki.kills = amount; |
| 2632 | id->Update(victim_slot, &ki); |
| 2633 | |
| 2634 | PInfo *kpi, *vpi; |
| 2635 | kpi = id; |
| 2636 | vpi = FindPInfo(victim); |
| 2637 | int killer_slot = PRec_GetPlayerSlot(killer); |
| 2638 | |
| 2639 | if ((vpi == NULL) || (killer_slot == -1)) { |
| 2640 | mprintf(0, "Unable to find PInfos\n"); |
| 2641 | return; |
| 2642 | } |
| 2643 | |
| 2644 | if (victim != killer) { |
| 2645 | // regular kill |
| 2646 | kpi->HandleKill(victim_slot); |
| 2647 | vpi->HandleDeath(killer_slot); |
| 2648 | } else { |
| 2649 | // suicide |
| 2650 | kpi->HandleSuicide(); |
| 2651 | } |
| 2652 | } |
| 2653 | |
| 2654 | // DMFCBase::ResetPInfo |
| 2655 | // |
| 2656 | // |
| 2657 | // Resets all the PInfo stats (and frees memory) |
| 2658 | void DMFCBase::ResetPInfo(void) { |
| 2659 | for (int i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 2660 | player_record *pr = GetPlayerRecord(i); |
| 2661 | if (pr && pr->pinfo) { |
| 2662 | pr->pinfo->ResetAll(); |
| 2663 | } |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | // DMFCBase::WriteDMFCStatsToFile |
| 2668 | // |
| 2669 | // |
| 2670 | // This function will write out DMFC's stats to the file given (it must be opened for writing) |
| 2671 | void DMFCBase::WriteDMFCStatsToFile(CFILE *file) { |
| 2672 | #define BUFSIZE 150 |
| 2673 | ASSERT(file != NULL); |
| 2674 | char buffer[BUFSIZE]; |
| 2675 | player_record *pr, *dpr; |
| 2676 | tPInfoStat stat; |
| 2677 | int count, length; |
| 2678 | |
| 2679 | count = 1; |
| 2680 | |
| 2681 | for (int p = 0; p < MAX_PLAYER_RECORDS; p++) { |
| 2682 | pr = GetPlayerRecord(p); |
| 2683 | if (pr && pr->state != STATE_EMPTY) { |
| 2684 | // Write out header |
| 2685 | snprintf(buffer, sizeof(buffer), "%d) %s%s", count, (pr->state == STATE_INGAME) ? "" : "*", pr->callsign); |
| 2686 | DLLcf_WriteString(file, buffer); |
| 2687 | length = strlen(buffer); |
| 2688 | memset(buffer, '=', length); |
| 2689 | buffer[length] = '\0'; |
| 2690 | DLLcf_WriteString(file, buffer); |
| 2691 | |
| 2692 | if (FindPInfoStatFirst(p, &stat)) { |
| 2693 | char tempbuffer[25]; |
| 2694 | snprintf(buffer, sizeof(buffer), "%s", DTXT_DMFC_STAT_HEADER); |
| 2695 | DLLcf_WriteString(file, buffer); |
| 2696 | memset(buffer, ' ', BUFSIZE); |
| 2697 | dpr = GetPlayerRecord(stat.slot); |
| 2698 | |
| 2699 | snprintf(tempbuffer, sizeof(tempbuffer), "%s", dpr->callsign); |
| 2700 | memcpy(buffer, tempbuffer, strlen(tempbuffer)); |
| 2701 | |
| 2702 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.kills); |
| 2703 | memcpy(&buffer[30], tempbuffer, strlen(tempbuffer)); |
| 2704 | |
| 2705 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.deaths); |
| 2706 | memcpy(&buffer[40], tempbuffer, strlen(tempbuffer)); |
| 2707 | |
| 2708 | int pos; |
| 2709 | pos = 40 + strlen(tempbuffer) + 1; |
| 2710 | if (pos < BUFSIZE) |
| 2711 | buffer[pos] = '\0'; |
| 2712 | |
| 2713 | buffer[BUFSIZE - 1] = '\0'; |
| 2714 | DLLcf_WriteString(file, buffer); |
| 2715 | |
| 2716 | while (FindPInfoStatNext(&stat)) { |
| 2717 | memset(buffer, ' ', BUFSIZE); |
| 2718 | dpr = GetPlayerRecord(stat.slot); |
| 2719 | |
| 2720 | snprintf(tempbuffer, sizeof(tempbuffer), "%s", dpr->callsign); |
| 2721 | memcpy(buffer, tempbuffer, strlen(tempbuffer)); |
| 2722 | |
| 2723 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.kills); |
| 2724 | memcpy(&buffer[30], tempbuffer, strlen(tempbuffer)); |
| 2725 | |
| 2726 | snprintf(tempbuffer, sizeof(tempbuffer), "%d", stat.deaths); |
| 2727 | memcpy(&buffer[40], tempbuffer, strlen(tempbuffer)); |
| 2728 | |
| 2729 | int pos; |
| 2730 | pos = 40 + strlen(tempbuffer) + 1; |
| 2731 | if (pos < BUFSIZE) |
| 2732 | buffer[pos] = '\0'; |
| 2733 | |
| 2734 | buffer[BUFSIZE - 1] = '\0'; |
| 2735 | DLLcf_WriteString(file, buffer); |
| 2736 | } |
| 2737 | } |
| 2738 | FindPInfoStatClose(); |
| 2739 | DLLcf_WriteString(file, ""); // skip a line |
| 2740 | count++; |
| 2741 | } |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | tPInfoStat _CurrentPInfoStat; |
| 2746 | int _CurrentPInfoSlot = -1; |
| 2747 | bool _DoneWithKills = false; |
| 2748 | bool _SlotsUsed[MAX_PLAYER_RECORDS]; |
| 2749 | |
| 2750 | // DMFCBase::FindPInfoStatFirst |
| 2751 | // |
| 2752 | // Fills in a tPInfoStat that contains information about a given player record slot. Returns true on success, false |
| 2753 | // if there is no information available for the given slot. Call this first, then follow with repeated calls to |
| 2754 | // FindPInfoStatNext until you get a false value returned...call FindPInfoStatClose when done. |
| 2755 | bool DMFCBase::FindPInfoStatFirst(int slot, tPInfoStat *stat) { |
| 2756 | for (int i = 0; i < MAX_PLAYER_RECORDS; i++) |
| 2757 | _SlotsUsed[i] = false; |
| 2758 | |
| 2759 | if (slot < 0 || slot >= MAX_PLAYER_RECORDS) |
| 2760 | return false; |
| 2761 | |
| 2762 | if (!stat) |
| 2763 | return false; |
| 2764 | |
| 2765 | FindPInfoStatClose(); |
| 2766 | |
| 2767 | player_record *pr, *dpr; |
| 2768 | tPKillerInfo *killer, *victim; |
| 2769 | int deaths; |
| 2770 | |
| 2771 | _SlotsUsed[slot] = true; |
| 2772 | _CurrentPInfoSlot = slot; |
| 2773 | memset(&_CurrentPInfoStat, 0, sizeof(tPInfoStat)); |
| 2774 | |
| 2775 | // return the given slot |
| 2776 | pr = GetPlayerRecord(slot); |
| 2777 | if (!pr || pr->state == STATE_EMPTY || !pr->pinfo) |
| 2778 | return false; |
| 2779 | |
| 2780 | killer = pr->pinfo->GetFirstKiller(); |
| 2781 | victim = NULL; |
| 2782 | |
| 2783 | if (!killer) { |
| 2784 | _DoneWithKills = true; |
| 2785 | // go through the slots looking for deaths |
| 2786 | for (int p = 0; p < MAX_PLAYER_RECORDS; p++) { |
| 2787 | if (!_SlotsUsed[p]) { |
| 2788 | _SlotsUsed[p] = true; |
| 2789 | dpr = GetPlayerRecord(p); |
| 2790 | deaths = 0; |
| 2791 | if (dpr && dpr->state != STATE_EMPTY && dpr->pinfo) { |
| 2792 | victim = ((PInfo *)dpr->pinfo)->GetKillerInfo(slot); |
| 2793 | if (victim) |
| 2794 | deaths = victim->kills; |
| 2795 | } |
| 2796 | if (deaths > 0) { |
| 2797 | _CurrentPInfoStat.slot = p; |
| 2798 | _CurrentPInfoStat.kills = 0; |
| 2799 | _CurrentPInfoStat.deaths = deaths; |
| 2800 | memcpy(stat, &_CurrentPInfoStat, sizeof(tPInfoStat)); |
| 2801 | return true; |
| 2802 | } |
| 2803 | } |
| 2804 | } |
| 2805 | return false; |
| 2806 | } |
| 2807 | |
| 2808 | _CurrentPInfoStat.slot = killer->slot; |
| 2809 | _CurrentPInfoStat.kills = killer->kills; |
| 2810 | |
| 2811 | deaths = 0; |
| 2812 | dpr = GetPlayerRecord(killer->slot); |
| 2813 | if (dpr && dpr->state != STATE_EMPTY && dpr->pinfo) { |
| 2814 | victim = ((PInfo *)dpr->pinfo)->GetKillerInfo(slot); |
| 2815 | } |
| 2816 | |
| 2817 | if (victim) |
| 2818 | deaths = victim->kills; |
| 2819 | |
| 2820 | _CurrentPInfoStat.deaths = deaths; |
| 2821 | _SlotsUsed[killer->slot] = true; |
| 2822 | |
| 2823 | memcpy(stat, &_CurrentPInfoStat, sizeof(tPInfoStat)); |
| 2824 | return true; |
| 2825 | } |
| 2826 | |
| 2827 | // DMFCBase::FindPInfoStatNext |
| 2828 | // |
| 2829 | // Call this repeatedly until you get a value of false, finish by calling FindPInfoStatClose |
| 2830 | bool DMFCBase::FindPInfoStatNext(tPInfoStat *stat) { |
| 2831 | if (_CurrentPInfoSlot == -1) |
| 2832 | return false; |
| 2833 | if (!stat) |
| 2834 | return false; |
| 2835 | |
| 2836 | int slot; |
| 2837 | player_record *pr, *dpr; |
| 2838 | slot = _CurrentPInfoSlot; |
| 2839 | tPKillerInfo *killer, *victim; |
| 2840 | int deaths = 0; |
| 2841 | memset(&_CurrentPInfoStat, 0, sizeof(tPInfoStat)); |
| 2842 | |
| 2843 | // return the given slot |
| 2844 | pr = GetPlayerRecord(slot); |
| 2845 | if (!pr || pr->state == STATE_EMPTY || !pr->pinfo) |
| 2846 | return false; |
| 2847 | |
| 2848 | killer = pr->pinfo->GetNextKiller(); |
| 2849 | victim = NULL; |
| 2850 | |
| 2851 | if (!killer) { |
| 2852 | _DoneWithKills = true; |
| 2853 | // go through the slots looking for deaths |
| 2854 | for (int p = 0; p < MAX_PLAYER_RECORDS; p++) { |
| 2855 | if (!_SlotsUsed[p]) { |
| 2856 | _SlotsUsed[p] = true; |
| 2857 | dpr = GetPlayerRecord(p); |
| 2858 | deaths = 0; |
| 2859 | if (dpr && dpr->state != STATE_EMPTY && dpr->pinfo) { |
| 2860 | victim = ((PInfo *)dpr->pinfo)->GetKillerInfo(slot); |
| 2861 | if (victim) |
| 2862 | deaths = victim->kills; |
| 2863 | } |
| 2864 | if (deaths > 0) { |
| 2865 | _CurrentPInfoStat.slot = p; |
| 2866 | _CurrentPInfoStat.kills = 0; |
| 2867 | _CurrentPInfoStat.deaths = deaths; |
| 2868 | memcpy(stat, &_CurrentPInfoStat, sizeof(tPInfoStat)); |
| 2869 | return true; |
| 2870 | } |
| 2871 | } |
| 2872 | } |
| 2873 | return false; |
| 2874 | } |
| 2875 | |
| 2876 | _CurrentPInfoStat.slot = killer->slot; |
| 2877 | _CurrentPInfoStat.kills = killer->kills; |
| 2878 | |
| 2879 | deaths = 0; |
| 2880 | dpr = GetPlayerRecord(killer->slot); |
| 2881 | if (dpr && dpr->state != STATE_EMPTY && dpr->pinfo) { |
| 2882 | victim = dpr->pinfo->GetKillerInfo(slot); |
| 2883 | } |
| 2884 | |
| 2885 | if (victim) |
| 2886 | deaths = victim->kills; |
| 2887 | |
| 2888 | _CurrentPInfoStat.deaths = deaths; |
| 2889 | _SlotsUsed[killer->slot] = true; |
| 2890 | |
| 2891 | memcpy(stat, &_CurrentPInfoStat, sizeof(tPInfoStat)); |
| 2892 | return true; |
| 2893 | } |
| 2894 | |
| 2895 | // DMFCBase::FindPInfoStatClose |
| 2896 | // |
| 2897 | // Closes up a FindPInfo series of calls |
| 2898 | void DMFCBase::FindPInfoStatClose(void) { |
| 2899 | _CurrentPInfoSlot = -1; |
| 2900 | _DoneWithKills = false; |
| 2901 | } |
| 2902 | |
| 2903 | // DMFCBase::SetWeaponDeathMessage |
| 2904 | // |
| 2905 | // Sets a death message for a weapon kill |
| 2906 | bool DMFCBase::SetWeaponDeathMessage(const char *weapon_name, const char *message, bool victim_first) { |
| 2907 | ASSERT(weapon_name != NULL); |
| 2908 | ASSERT(message != NULL); |
| 2909 | |
| 2910 | int weapon_index = DLLFindWeaponName(IGNORE_TABLE(weapon_name)); |
| 2911 | if (weapon_index == -1) { |
| 2912 | mprintf(0, "Unable to set WeaponMessage for %s...can't find it\n", weapon_name); |
| 2913 | return false; |
| 2914 | } |
| 2915 | |
| 2916 | int real_weapon = WeaponHash[weapon_index]; |
| 2917 | |
| 2918 | if (real_weapon == -1) { |
| 2919 | mprintf(0, "You forgot to call AddWeaponHash before adding this Message\n"); |
| 2920 | return false; |
| 2921 | } |
| 2922 | |
| 2923 | if ((WeaponMessages[real_weapon].inuse) && (WeaponMessages[real_weapon].message)) { |
| 2924 | free(WeaponMessages[real_weapon].message); |
| 2925 | WeaponMessages[real_weapon].message = NULL; |
| 2926 | } |
| 2927 | |
| 2928 | WeaponMessages[real_weapon].message = (char *)malloc(strlen(message) + 1); |
| 2929 | if (WeaponMessages[real_weapon].message) { |
| 2930 | strcpy(WeaponMessages[real_weapon].message, message); |
| 2931 | WeaponMessages[real_weapon].inuse = true; |
| 2932 | WeaponMessages[real_weapon].victim_first = victim_first; |
| 2933 | } |
| 2934 | |
| 2935 | return WeaponMessages[real_weapon].inuse; |
| 2936 | } |
| 2937 | |
| 2938 | // DMFCBase::GetWeaponDeathMessage |
| 2939 | // |
| 2940 | // Returns the format string for a weapon death message, NULL if it doesn't exist |
| 2941 | char *DMFCBase::GetWeaponDeathMessage(int index, bool *victim_first) { |
| 2942 | if ((index < 0) || (index >= MAX_WEAPONS)) |
| 2943 | return NULL; |
| 2944 | |
| 2945 | int real_weapon; |
| 2946 | |
| 2947 | real_weapon = WeaponHash[index]; |
| 2948 | |
| 2949 | if (real_weapon == -1) |
| 2950 | return NULL; |
| 2951 | |
| 2952 | if (!WeaponMessages[real_weapon].inuse) |
| 2953 | return NULL; |
| 2954 | |
| 2955 | *victim_first = WeaponMessages[real_weapon].victim_first; |
| 2956 | return WeaponMessages[real_weapon].message; |
| 2957 | } |
| 2958 | |
| 2959 | // DMFCBase::AddWeaponHash |
| 2960 | // |
| 2961 | // Since one weapon may actually consist of many weapons, in order to save space you can create |
| 2962 | // one weapon where all those other weapon id's will be mapped to it...use WeaponHash[id] to |
| 2963 | // get the actual weapon. End list of children with a NULL |
| 2964 | void DMFCBase::AddWeaponHash(const char *parent, ...) { |
| 2965 | ASSERT(parent != NULL); |
| 2966 | |
| 2967 | int parent_id = DLLFindWeaponName(IGNORE_TABLE(parent)); |
| 2968 | if (parent_id == -1) { |
| 2969 | mprintf(0, "Unable to find parent weapon ID in AddWeaponHash (%s)\n", parent); |
| 2970 | return; |
| 2971 | } |
| 2972 | |
| 2973 | va_list marker; |
| 2974 | va_start(marker, parent); |
| 2975 | |
| 2976 | WeaponHash[parent_id] = parent_id; |
| 2977 | |
| 2978 | bool done = false; |
| 2979 | |
| 2980 | while (!done) { |
| 2981 | int id; |
| 2982 | char *name; |
| 2983 | name = va_arg(marker, char *); |
| 2984 | if (name) |
| 2985 | id = DLLFindWeaponName(IGNORE_TABLE(name)); |
| 2986 | else |
| 2987 | id = -1; |
| 2988 | |
| 2989 | if (id == -1) { |
| 2990 | done = true; |
| 2991 | } else { |
| 2992 | if ((id < 0) || (id >= MAX_WEAPONS)) |
| 2993 | done = true; |
| 2994 | else { |
| 2995 | WeaponHash[id] = parent_id; |
| 2996 | } |
| 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | va_end(marker); |
| 3001 | } |
| 3002 | |
| 3003 | // DMFCBase::AddWeaponHashArray |
| 3004 | // |
| 3005 | // Since one weapon may actually consist of many weapons, in order to save space you can create |
| 3006 | // one weapon where all those other weapon id's will be mapped to it...use WeaponHash[id] to |
| 3007 | // get the actual weapon. |
| 3008 | void DMFCBase::AddWeaponHashArray(const char *parent, int count, char **array) { |
| 3009 | ASSERT(parent != NULL); |
| 3010 | |
| 3011 | int parent_id = DLLFindWeaponName(IGNORE_TABLE(parent)); |
| 3012 | if (parent_id == -1) { |
| 3013 | mprintf(0, "Unable to find parent weapon ID in AddWeaponHash (%s)\n", parent); |
| 3014 | return; |
| 3015 | } |
| 3016 | |
| 3017 | WeaponHash[parent_id] = parent_id; |
| 3018 | |
| 3019 | int index = 0; |
| 3020 | while (index < count) { |
| 3021 | int id; |
| 3022 | char *name; |
| 3023 | name = array[index++]; |
| 3024 | if (name) |
| 3025 | id = DLLFindWeaponName(IGNORE_TABLE(name)); |
| 3026 | else |
| 3027 | break; |
| 3028 | |
| 3029 | if (id >= 0 && id < MAX_WEAPONS) { |
| 3030 | WeaponHash[id] = parent_id; |
| 3031 | } |
| 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | // DMFCBase::SetupPlayerRecord |
| 3036 | // |
| 3037 | // Sets up memory for multiplayer mod user defined data in the Player Records. Pass in the size (in bytes) |
| 3038 | // of 1 struct (each player will get one). Use GetPlayerRecordData to retrieve a pointer to the data. |
| 3039 | // |
| 3040 | // pack_callback : callback function called when data from the struct needs to be packed |
| 3041 | // into a packet. It is SUPER important that this function packs the data |
| 3042 | // in little endian format. This function gets a pointer to the struct that |
| 3043 | // needs to be packed (user_info), and a buffer in which to pack it to. This |
| 3044 | // function is to return the number of bytes it has packed. |
| 3045 | // unpack_callback : callback function called when data from the struct needs to be unpacket |
| 3046 | // from a packet. This data will be in little endian format. Returns the number of |
| 3047 | // bytes unpacked. |
| 3048 | // returns: 1 if size given was <=0 (if so all previous user stats will be removed) |
| 3049 | // 0 all went ok |
| 3050 | // -1 out of memory (all user stats memory will be freed) |
| 3051 | int DMFCBase::SetupPlayerRecord(int sizeof_individual_data, int (*pack_callback)(void *user_info, uint8_t *data), |
| 3052 | int (*unpack_callback)(void *user_info, uint8_t *data)) { |
| 3053 | return PRec_SetupUserPRec(sizeof_individual_data, pack_callback, unpack_callback); |
| 3054 | } |
| 3055 | |
| 3056 | // DMFCBase::GetPlayerRecordData |
| 3057 | // |
| 3058 | // Returns a pointer to the memory set aside for a particular player (NULL on error) |
| 3059 | void *DMFCBase::GetPlayerRecordData(int pnum) { |
| 3060 | int slot; |
| 3061 | slot = PRec_GetPlayerSlot(pnum); |
| 3062 | if (slot == -1) |
| 3063 | return NULL; |
| 3064 | return PRec_GetUserStats(slot); |
| 3065 | } |
| 3066 | |
| 3067 | // DMFCBase::GetPlayerRecord |
| 3068 | // |
| 3069 | // Returns a pointer to the player record at the given slot (passed in slot must be in the range |
| 3070 | // 0<=slot<MAX_PLAYER_RECORDS) |
| 3071 | player_record *DMFCBase::GetPlayerRecord(int slot) { return PRec_GetPRecord(slot); } |
| 3072 | |
| 3073 | // DMFCBase::GetPlayerRecordByPnum |
| 3074 | // |
| 3075 | // Same as above, but you can specify by a player's pnum, return NULL on error |
| 3076 | player_record *DMFCBase::GetPlayerRecordByPnum(int pnum) { |
| 3077 | int slot; |
| 3078 | slot = PRec_GetPlayerSlot(pnum); |
| 3079 | if (slot == -1) |
| 3080 | return NULL; |
| 3081 | return PRec_GetPRecord(slot); |
| 3082 | } |
| 3083 | |
| 3084 | // DMFCBase::BanPlayerFromGame |
| 3085 | // |
| 3086 | // Puts a temp ban on a player which will only last the duration of the game |
| 3087 | void DMFCBase::BanPlayerFromGame(int pnum) { |
| 3088 | if (pnum >= 0 && pnum < DLLMAX_PLAYERS) { |
| 3089 | mprintf(0, "Banning %s\n", Players[pnum].callsign); |
| 3090 | DPrintf(DTXT_DEDS_BAN, Players[pnum].callsign); |
| 3091 | tBanItem *c; |
| 3092 | c = m_BanList; |
| 3093 | if (!m_BanList) { |
| 3094 | c = m_BanList = (tBanItem *)malloc(sizeof(tBanItem)); |
| 3095 | if (!c) |
| 3096 | return; |
| 3097 | } else { |
| 3098 | while (c->next) { |
| 3099 | c = c->next; |
| 3100 | } |
| 3101 | c->next = (tBanItem *)malloc(sizeof(tBanItem)); |
| 3102 | c = c->next; |
| 3103 | if (!c) |
| 3104 | return; |
| 3105 | } |
| 3106 | c->next = NULL; |
| 3107 | memcpy(&c->addr, &NetPlayers[pnum].addr, sizeof(network_address)); |
| 3108 | strncpy(c->callsign, Players[pnum].callsign, MAX_CALLSIGN_SIZE - 1); |
| 3109 | c->callsign[MAX_CALLSIGN_SIZE - 1] = '\0'; |
| 3110 | c->tracker_id[0] = '\0'; |
| 3111 | |
| 3112 | if (IsMasterTrackerGame()) { |
| 3113 | strcpy(c->tracker_id, Players[pnum].tracker_id); |
| 3114 | } |
| 3115 | |
| 3116 | m_iNumBanPlayers++; |
| 3117 | } else { |
| 3118 | mprintf(0, "Unable to ban player...pnum not valid\n"); |
| 3119 | DPrintf(DTXT_DEDS_BAN_ERROR); |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | // DMFCBase::RemoveAllBans |
| 3124 | // |
| 3125 | // Removes all the temp bans |
| 3126 | void DMFCBase::RemoveAllBans(void) { |
| 3127 | tBanItem *c, *n; |
| 3128 | c = n = m_BanList; |
| 3129 | while (c) { |
| 3130 | n = c->next; |
| 3131 | free(c); |
| 3132 | c = n; |
| 3133 | } |
| 3134 | m_BanList = NULL; |
| 3135 | m_iNumBanPlayers = 0; |
| 3136 | } |
| 3137 | |
| 3138 | // DMFCBase::GetNumBannedPlayers |
| 3139 | // |
| 3140 | // Returns the number of players banned from the server |
| 3141 | int DMFCBase::GetNumBannedPlayers(void) { return m_iNumBanPlayers; } |
| 3142 | |
| 3143 | // DMCBase::GetBannedPlayerCallsign |
| 3144 | // |
| 3145 | // Returns the callsign of the banned player at position index, NULL on error |
| 3146 | char *DMFCBase::GetBannedPlayerCallsign(int index) { |
| 3147 | if (index < 0 || index >= m_iNumBanPlayers) |
| 3148 | return NULL; |
| 3149 | |
| 3150 | tBanItem *c; |
| 3151 | c = m_BanList; |
| 3152 | while (c) { |
| 3153 | if (index == 0) { |
| 3154 | return c->callsign; |
| 3155 | } |
| 3156 | index--; |
| 3157 | c = c->next; |
| 3158 | } |
| 3159 | return NULL; |
| 3160 | } |
| 3161 | |
| 3162 | // DMFCBase::RemoveBan |
| 3163 | // |
| 3164 | // Removes a temp ban on given the ban #...returns true on success |
| 3165 | bool DMFCBase::RemoveBan(int index) { |
| 3166 | if (index < 0 || index >= m_iNumBanPlayers) |
| 3167 | return false; |
| 3168 | |
| 3169 | tBanItem *c, *p; |
| 3170 | c = m_BanList; |
| 3171 | p = NULL; |
| 3172 | while (c) { |
| 3173 | if (!index) { |
| 3174 | // we found em, remove em |
| 3175 | if (p) { |
| 3176 | p->next = c->next; |
| 3177 | free(c); |
| 3178 | m_iNumBanPlayers--; |
| 3179 | } else { |
| 3180 | m_BanList = c->next; |
| 3181 | free(c); |
| 3182 | m_iNumBanPlayers--; |
| 3183 | } |
| 3184 | return true; |
| 3185 | } |
| 3186 | p = c; |
| 3187 | c = c->next; |
| 3188 | index--; |
| 3189 | } |
| 3190 | return false; |
| 3191 | } |
| 3192 | |
| 3193 | // DMFCBase::IsPlayerBanned |
| 3194 | // |
| 3195 | // returns true is the given pnum is banned from the game |
| 3196 | bool DMFCBase::IsPlayerBanned(int pnum) { |
| 3197 | mprintf(0, "Checking a ban on a player..."); |
| 3198 | |
| 3199 | if (pnum < 0 || pnum >= DLLMAX_PLAYERS) { |
| 3200 | mprintf(0, "Playernum not valid\n"); |
| 3201 | return false; |
| 3202 | } |
| 3203 | |
| 3204 | if (IsAddressBanned(&NetPlayers[pnum].addr, Players[pnum].tracker_id)) { |
| 3205 | return true; |
| 3206 | } |
| 3207 | |
| 3208 | return false; |
| 3209 | } |
| 3210 | |
| 3211 | // DMFCBase::IsAddressBanned |
| 3212 | // |
| 3213 | // returns true if the given address is banned from the game |
| 3214 | bool DMFCBase::IsAddressBanned(network_address *addr, const char *tracker_id) { |
| 3215 | tBanItem *c; |
| 3216 | c = m_BanList; |
| 3217 | |
| 3218 | mprintf(0, "Checking a ban on an address..."); |
| 3219 | |
| 3220 | while (c) { |
| 3221 | if (addr && CompareNetworkAddress(&c->addr, addr, false)) { |
| 3222 | mprintf(0, "Player addr IS BANNED\n"); |
| 3223 | return true; |
| 3224 | } |
| 3225 | if (*m_bTrackerGame) { |
| 3226 | if (tracker_id && !strcmp(tracker_id, c->tracker_id)) { |
| 3227 | mprintf(0, "Player tid IS BANNED\n"); |
| 3228 | return true; |
| 3229 | } |
| 3230 | } |
| 3231 | |
| 3232 | c = c->next; |
| 3233 | } |
| 3234 | |
| 3235 | if (!addr) { |
| 3236 | mprintf(0, "Player not banned\n"); |
| 3237 | return false; |
| 3238 | } |
| 3239 | |
| 3240 | // ok, the player doesn't have a temp ban on him, now, if it's tcp/ip, check |
| 3241 | // the hosts.allow/.deny |
| 3242 | |
| 3243 | if (addr->connection_type != NP_TCP) { |
| 3244 | mprintf(0, "Player not banned\n"); |
| 3245 | return false; |
| 3246 | } |
| 3247 | |
| 3248 | uint32_t address; |
| 3249 | tHostsNode *curr; |
| 3250 | |
| 3251 | memcpy(&address, &addr->address, 4); |
| 3252 | |
| 3253 | // check the allow list, if the address is specified on this list, |
| 3254 | // than it isn't banned |
| 3255 | curr = m_AllowList; |
| 3256 | while (curr) { |
| 3257 | if ((address & curr->mask) == (curr->ip & curr->mask)) { |
| 3258 | // its a match |
| 3259 | mprintf(0, "Player not banned\n"); |
| 3260 | return false; |
| 3261 | } |
| 3262 | curr = curr->next; |
| 3263 | } |
| 3264 | |
| 3265 | // check the deny list, if the address is specified on this list, |
| 3266 | // than it is banned |
| 3267 | curr = m_DenyList; |
| 3268 | while (curr) { |
| 3269 | if ((address & curr->mask) == (curr->ip & curr->mask)) { |
| 3270 | // its a match |
| 3271 | mprintf(0, "Player IS banned\n"); |
| 3272 | return true; |
| 3273 | } |
| 3274 | curr = curr->next; |
| 3275 | } |
| 3276 | |
| 3277 | mprintf(0, "Player not banned\n"); |
| 3278 | return false; |
| 3279 | } |
| 3280 | |
| 3281 | // DMFCBase::DoDamageToPlayer |
| 3282 | // |
| 3283 | // Server only...applies damage to player |
| 3284 | void DMFCBase::DoDamageToPlayer(int pnum, int type, float amount, bool playsound) { |
| 3285 | if (GetLocalRole() != LR_SERVER) |
| 3286 | return; |
| 3287 | if (!CheckPlayerNum(pnum)) |
| 3288 | return; |
| 3289 | if (pnum == GetPlayerNum()) { |
| 3290 | // apply it to myself |
| 3291 | if (amount <= 0) { |
| 3292 | // just add it...no damage sound |
| 3293 | Objects[Players[pnum].objnum].shields -= amount; |
| 3294 | } else { |
| 3295 | DLLApplyDamageToPlayer(&Objects[Players[pnum].objnum], NULL, type, amount, 1, 255, playsound); |
| 3296 | } |
| 3297 | } else { |
| 3298 | // add it to additional damage |
| 3299 | DLLApplyDamageToPlayer(&Objects[Players[pnum].objnum], NULL, type, amount, 1, 255, playsound); |
| 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | // DMFCBase::StartUIWindow |
| 3304 | // |
| 3305 | // Prepares the game so that you can display UI stuff |
| 3306 | void DMFCBase::StartUIWindow(int id, void *user_data) { |
| 3307 | if (m_iUIWindowID != -1) { |
| 3308 | mprintf(0, "DMFCBase::StartUIWindow(): A Window ID (0x%X) is already defined\n", m_iUIWindowID); |
| 3309 | return; |
| 3310 | } |
| 3311 | |
| 3312 | *Game_interface_mode = GAME_DLL_INTERFACE; |
| 3313 | m_iUIWindowID = id; |
| 3314 | m_UIUserData = user_data; |
| 3315 | } |
| 3316 | |
| 3317 | // DMFCBase::EnableStatisticalMessages |
| 3318 | // |
| 3319 | // Turns on or off the statistical HUD messages that appear due to a player death |
| 3320 | void DMFCBase::EnableStatisticalMessages(bool on) { |
| 3321 | if (on) |
| 3322 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPSTATHUDMSGS); |
| 3323 | else |
| 3324 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPSTATHUDMSGS); |
| 3325 | } |
| 3326 | |
| 3327 | // DMFCBase::GetTimeInGame |
| 3328 | // |
| 3329 | // Returns the totaltime the player has been in the game at the moment you call |
| 3330 | // this function. Pass in the player record slot. |
| 3331 | float DMFCBase::GetTimeInGame(int slot) { |
| 3332 | if (slot < 0 || slot >= MAX_PLAYER_RECORDS) |
| 3333 | return 0; |
| 3334 | |
| 3335 | player_record *pr = PRec_GetPRecord(slot); |
| 3336 | |
| 3337 | if (!pr || pr->state == STATE_EMPTY) |
| 3338 | return 0; |
| 3339 | |
| 3340 | float ti = pr->total_time_in_game; |
| 3341 | |
| 3342 | if (pr->state == STATE_INGAME) |
| 3343 | ti += RealGametime - pr->start_time; |
| 3344 | |
| 3345 | return ti; |
| 3346 | } |
| 3347 | |
| 3348 | // DMFCBase::GetTimeString |
| 3349 | // |
| 3350 | // Returns a string that contains a formated time (i.e. 32 seconds, 1:15 minutes, 3:21:23 hours) |
| 3351 | char *DMFCBase::GetTimeString(float sec) { |
| 3352 | static char buffer[20]; |
| 3353 | int minutes, seconds, hours; |
| 3354 | minutes = seconds = hours = 0; |
| 3355 | |
| 3356 | seconds = (int)sec; |
| 3357 | |
| 3358 | // we have seconds, so convert to minutes:seconds |
| 3359 | minutes = seconds / 60; |
| 3360 | seconds = seconds % 60; |
| 3361 | |
| 3362 | // now we have minutes and seconds, so convert minutes to hours:minutes |
| 3363 | hours = minutes / 60; |
| 3364 | minutes = minutes % 60; |
| 3365 | |
| 3366 | // now form our string hh:mm:ss |
| 3367 | if (hours) { |
| 3368 | if (hours == 1 && minutes == 0 && seconds == 0) |
| 3369 | snprintf(buffer, sizeof(buffer), "%s", DTXT_TIME_HOUR); |
| 3370 | else |
| 3371 | snprintf(buffer, sizeof(buffer), DTXT_TIME_HOURS, hours, minutes, seconds); |
| 3372 | } else if (minutes) { |
| 3373 | if (minutes == 1 && seconds == 0) |
| 3374 | snprintf(buffer, sizeof(buffer), "%s", DTXT_TIME_MINUTE); |
| 3375 | else |
| 3376 | snprintf(buffer, sizeof(buffer), DTXT_TIME_MINUTES, minutes, seconds); |
| 3377 | } else { |
| 3378 | if (seconds == 1) |
| 3379 | snprintf(buffer, sizeof(buffer), "%s", DTXT_TIME_SECOND); |
| 3380 | else |
| 3381 | snprintf(buffer, sizeof(buffer), DTXT_TIME_SECONDS, seconds); |
| 3382 | } |
| 3383 | return buffer; |
| 3384 | } |
| 3385 | |
| 3386 | // DMFCBase::PauseRealGameTime |
| 3387 | // |
| 3388 | // Pauses/unpauses the realgame time |
| 3389 | void DMFCBase::PauseRealGameTime(bool enable) { |
| 3390 | if (GetLocalRole() != LR_SERVER) |
| 3391 | return; |
| 3392 | |
| 3393 | if (enable) { |
| 3394 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME); |
| 3395 | SendControlMessageToPlayer(SP_ALL, CM_PAUSETIME); |
| 3396 | } else { |
| 3397 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_PAUSETIME); |
| 3398 | SendControlMessageToPlayer(SP_ALL, CM_UNPAUSETIME); |
| 3399 | } |
| 3400 | } |
| 3401 | |
| 3402 | /* |
| 3403 | ******************************************************************************** |
| 3404 | * * |
| 3405 | * Input Command Functions |
| 3406 | ** |
| 3407 | * * |
| 3408 | ******************************************************************************** |
| 3409 | * |
| 3410 | */ |
| 3411 | |
| 3412 | // DMFCBase::InputCommandHandle |
| 3413 | // |
| 3414 | // Goes through the list of input commands and calls the associated handle (if it exists). Returns |
| 3415 | // true if it called a handler, else false. |
| 3416 | bool DMFCBase::InputCommandHandle(char *command_string) { |
| 3417 | ASSERT(command_string != NULL); |
| 3418 | |
| 3419 | // make sure it's a valid command (starts with a $) |
| 3420 | if (command_string[0] != '$') |
| 3421 | return false; |
| 3422 | |
| 3423 | /* |
| 3424 | if(!stricmp(command_string,"$help dump")) |
| 3425 | { |
| 3426 | mprintf(0,"Dumping help commands to file\n"); |
| 3427 | tInputCommandNode *node = m_InputCommandRootNode; |
| 3428 | |
| 3429 | CFILE *file; |
| 3430 | DLLOpenCFILE(&file,"C:\\DMFCHelp.txt","wt"); |
| 3431 | |
| 3432 | if(!file) |
| 3433 | return false; |
| 3434 | |
| 3435 | char buffer[1024]; |
| 3436 | |
| 3437 | while(node){ |
| 3438 | |
| 3439 | sprintf(buffer,"$%s",node->data); |
| 3440 | DLLcf_WriteString(file,buffer); |
| 3441 | DLLcf_WriteString(file,"-------------------------------------------"); |
| 3442 | sprintf(buffer,"%s\n",node->desc); |
| 3443 | DLLcf_WriteString(file,buffer); |
| 3444 | node = node->next; |
| 3445 | } |
| 3446 | |
| 3447 | DLLcfclose(file); |
| 3448 | } |
| 3449 | */ |
| 3450 | |
| 3451 | // now extract the command |
| 3452 | char command[64], index = 0; |
| 3453 | char *p = &command_string[1]; |
| 3454 | |
| 3455 | // lowercase the command_string |
| 3456 | while (*p && *p != ' ') { |
| 3457 | if ((*p >= 'A') && (*p <= 'Z')) { |
| 3458 | *p = tolower(*p); |
| 3459 | } |
| 3460 | p++; |
| 3461 | } |
| 3462 | |
| 3463 | p = &command_string[1]; |
| 3464 | |
| 3465 | // break off the first string |
| 3466 | while ((*p) && (*p != ' ')) { |
| 3467 | ASSERT(index < 64); |
| 3468 | command[index] = *p; |
| 3469 | p++; |
| 3470 | index++; |
| 3471 | } |
| 3472 | command[index] = '\0'; // tack on an ending NULL |
| 3473 | |
| 3474 | // now go through our list and see if we can find the command added by the user |
| 3475 | tInputCommandNode *node = m_InputCommandRootNode; |
| 3476 | while (node) { |
| 3477 | if (!stricmp(node->data, command)) { |
| 3478 | // we found a match! |
| 3479 | if (node->handler) { |
| 3480 | (*node->handler)(command_string); |
| 3481 | return true; |
| 3482 | } |
| 3483 | return false; // for some reason the handler is NULL (it should never happen) |
| 3484 | } |
| 3485 | node = node->next; |
| 3486 | } |
| 3487 | |
| 3488 | // if we got here than no nodes match |
| 3489 | return false; |
| 3490 | } |
| 3491 | |
| 3492 | // DMFCBase::InputCommandFree |
| 3493 | // |
| 3494 | // Frees up all memory allocated for the input commands ($ messages) |
| 3495 | void DMFCBase::InputCommandFree(void) { |
| 3496 | tInputCommandNode *next, *node = m_InputCommandRootNode; |
| 3497 | |
| 3498 | // Destroy the linked list of nodes |
| 3499 | while (node) { |
| 3500 | next = node->next; |
| 3501 | if (node->data) |
| 3502 | free(node->data); |
| 3503 | if (node->desc) |
| 3504 | free(node->desc); |
| 3505 | free(node); |
| 3506 | node = next; |
| 3507 | } |
| 3508 | |
| 3509 | // set the root to NULL to finish up |
| 3510 | m_InputCommandRootNode = NULL; |
| 3511 | } |
| 3512 | |
| 3513 | // DMFCBase::InputCommandInit |
| 3514 | // |
| 3515 | // Initializes the variables and data for the input commands. Default DMFC commands are to |
| 3516 | // be placed in here. |
| 3517 | void DMFCBase::InputCommandInit(void) { |
| 3518 | if (AddInputCommand(DTXT_IC_ALLOWTEAMCHANGE, DTXT_IC_ALLOWTEAMCHANGED, DMFCInputCommand_AllowTeamChange, true) < 1) |
| 3519 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3520 | |
| 3521 | if (AddInputCommand(DTXT_IC_AUTOBALANCE, DTXT_IC_AUTOBALANCED, DMFCInputCommand_AutoBalance, true) < 1) |
| 3522 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3523 | |
| 3524 | if (AddInputCommand(DTXT_IC_AUTOSAVEDISC, DTXT_IC_AUTOSAVEDISCD, DMFCInputCommand_AutoSaveDisconnect, true) < 1) |
| 3525 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3526 | |
| 3527 | if (AddInputCommand(DTXT_IC_AUTOSAVELEVEL, DTXT_IC_AUTOSAVELEVELD, DMFCInputCommand_AutoSaveLevel, true) < 1) |
| 3528 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3529 | |
| 3530 | if (AddInputCommand(DTXT_IC_BALANCE, DTXT_IC_BALANCED, DMFCInputCommand_Balance, true) < 1) |
| 3531 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3532 | |
| 3533 | if (AddInputCommand(DTXT_IC_BAN, DTXT_IC_BAND, DMFCInputCommand_Ban, true) < 1) |
| 3534 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3535 | |
| 3536 | if (AddInputCommand(DTXT_IC_BANLIST, DTXT_IC_BANLISTD, DMFCInputCommand_BanList) < 1) |
| 3537 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3538 | |
| 3539 | if (AddInputCommand(DTXT_IC_CHANGETEAM, DTXT_IC_CHANGETEAMD, DMFCInputCommand_ChangeTeam, true) < 1) |
| 3540 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3541 | |
| 3542 | if (AddInputCommand(DTXT_IC_ENDLEVEL, DTXT_IC_ENDLEVELD, DMFCInputCommand_EndLevel, true) < 1) |
| 3543 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3544 | |
| 3545 | if (AddInputCommand(DTXT_IC_HELP, DTXT_IC_HELPD, DMFCInputCommand_Help) < 1) |
| 3546 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3547 | |
| 3548 | if (AddInputCommand(DTXT_IC_HUDNAME, DTXT_IC_HUDNAMED, DMFCInputCommand_HudCallsigns) < 1) |
| 3549 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3550 | |
| 3551 | if (AddInputCommand(DTXT_IC_KICK, DTXT_IC_KICKD, DMFCInputCommand_Kick, true) < 1) |
| 3552 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3553 | |
| 3554 | if (AddInputCommand(DTXT_IC_KILLMSGFILTER, DTXT_IC_KILLMSGFILTERD, DMFCInputCommand_KillMsgFilter) < 1) |
| 3555 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3556 | |
| 3557 | if (AddInputCommand(DTXT_IC_NETGAMEINFO, DTXT_IC_NETGAMEINFO, DMFCInputCommand_NetGameInfo) < 1) |
| 3558 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3559 | |
| 3560 | if (AddInputCommand(DTXT_IC_OBSERVER, DTXT_IC_OBSERVERD, DMFCInputCommand_Observer) < 1) |
| 3561 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3562 | |
| 3563 | if (AddInputCommand(DTXT_IC_PIGGYBACK, DTXT_IC_PIGGYBACKD, DMFCInputCommand_Piggyback) < 1) |
| 3564 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3565 | |
| 3566 | if (AddInputCommand(DTXT_IC_PLAYERINFO, DTXT_IC_PLAYERINFOD, DMFCInputCommand_PlayerInfo) < 1) |
| 3567 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3568 | |
| 3569 | if (AddInputCommand(DTXT_IC_PLAYERS, DTXT_IC_PLAYERSD, DMFCInputCommand_Players) < 1) |
| 3570 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3571 | |
| 3572 | if (AddInputCommand(DTXT_IC_REHASH, DTXT_IC_REHASHD, DMFCInputCommand_Rehash, true) < 1) |
| 3573 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3574 | |
| 3575 | if (AddInputCommand(DTXT_IC_REMOTE, DTXT_IC_REMOTED, DMFCInputCommand_Remote) < 1) |
| 3576 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3577 | |
| 3578 | if (AddInputCommand(DTXT_IC_REMOTEADMIN, DTXT_IC_REMOTEADMIND, DMFCInputCommand_RemoteAdmin, true) < 1) |
| 3579 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3580 | |
| 3581 | if (AddInputCommand(DTXT_IC_REMOTEADMINLOGOUT, DTXT_IC_REMOTEADMINLOGOUTD, DMFCInputCommand_RemoteAdminLogout) < 1) |
| 3582 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3583 | |
| 3584 | if (AddInputCommand(DTXT_IC_REMOTEADMINPASS, DTXT_IC_REMOTEADMINPASSD, DMFCInputCommand_RemoteAdminPass, true) < 1) |
| 3585 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3586 | |
| 3587 | if (AddInputCommand(DTXT_IC_REMOVEBAN, DTXT_IC_REMOVEBAND, DMFCInputCommand_RemoveBan, true) < 1) |
| 3588 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3589 | |
| 3590 | if (AddInputCommand(DTXT_IC_SAVESTATS, DTXT_IC_SAVESTATSD, DMFCInputCommand_SaveStats, true) < 1) |
| 3591 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3592 | |
| 3593 | if (AddInputCommand(DTXT_IC_SCORES, DTXT_IC_SCORESD, DMFCInputCommand_Scores) < 1) |
| 3594 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3595 | |
| 3596 | if (AddInputCommand(DTXT_IC_SERVERHUDNAMES, DTXT_IC_SERVERHUDNAMESD, DMFCInputCommand_ServerHudCallsigns, true) < 1) |
| 3597 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3598 | |
| 3599 | if (AddInputCommand(DTXT_IC_SETGOALLIMIT, DTXT_IC_SETGOALLIMITD, DMFCInputCommand_SetGoalLimit, true) < 1) |
| 3600 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3601 | |
| 3602 | if (AddInputCommand(DTXT_IC_SETMAXPLAYERS, DTXT_IC_SETMAXPLAYERSD, DMFCInputCommand_SetMaxPlayers, true) < 1) |
| 3603 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3604 | |
| 3605 | if (AddInputCommand(DTXT_IC_SETPPS, DTXT_IC_SETPPSD, DMFCInputCommand_SetPPS, true) < 1) |
| 3606 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3607 | |
| 3608 | if (AddInputCommand(DTXT_IC_SETRESPAWNTIME, DTXT_IC_SETRESPAWNTIMED, DMFCInputCommand_SetRespawnTime, true) < 1) |
| 3609 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3610 | |
| 3611 | if (AddInputCommand(DTXT_IC_SETTEAMNAME, DTXT_IC_SETTEAMNAMED, DMFCInputCommand_SetTeamName, true) < 1) |
| 3612 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3613 | |
| 3614 | if (AddInputCommand(DTXT_IC_SETTIMELIMIT, DTXT_IC_SETTIMELIMITD, DMFCInputCommand_SetTimeLimit, true) < 1) |
| 3615 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3616 | |
| 3617 | if (AddInputCommand(DTXT_IC_STATMSGS, DTXT_IC_STATMSGSD, DMFCInputCommand_StatMsgs) < 1) |
| 3618 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3619 | |
| 3620 | if (AddInputCommand(DTXT_IC_TEAM, DTXT_IC_TEAMD, DMFCInputCommand_Team) < 1) |
| 3621 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3622 | |
| 3623 | if (AddInputCommand(DTXT_IC_WAIT, DTXT_IC_WAITD, DMFCInputCommand_Wait, true) < 1) |
| 3624 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3625 | |
| 3626 | if (AddInputCommand(DTXT_IC_WARP, DTXT_IC_WARPD, DMFCInputCommand_Warp, true) < 1) |
| 3627 | mprintf(0, "DMFC Warning: Error Adding Input Command\n"); |
| 3628 | } |
| 3629 | |
| 3630 | // Returns true if the input command can be called remotely |
| 3631 | // |
| 3632 | // Returns 1 if the input command can be called remotely |
| 3633 | // Returns -1 if the input command is not found |
| 3634 | // Returns 0 if the input command can be called remotely |
| 3635 | int DMFCBase::CanInputCommandBeUsedRemotely(char *command) { |
| 3636 | tInputCommandNode *node = m_InputCommandRootNode; |
| 3637 | |
| 3638 | while (node) { |
| 3639 | if (!stricmp(node->data, command)) { |
| 3640 | // we found a match! |
| 3641 | return (node->allow_remote) ? 1 : 0; |
| 3642 | } |
| 3643 | node = node->next; |
| 3644 | } |
| 3645 | |
| 3646 | return -1; |
| 3647 | } |
| 3648 | |
| 3649 | // Displays dedicated server help |
| 3650 | void DMFCBase::DisplayInputCommandHelp(const char *s) { |
| 3651 | if (!IAmDedicatedServer()) |
| 3652 | return; |
| 3653 | |
| 3654 | tInputCommandNode *node = m_InputCommandRootNode; |
| 3655 | |
| 3656 | if (s[0] == '\0') { |
| 3657 | char buffer[80]; |
| 3658 | DPrintf(DTXT_IC_HEADEERLIST); |
| 3659 | DPrintf(DTXT_IC_HEADERINSTRUCT); |
| 3660 | // just display the list of commands |
| 3661 | while (node) { |
| 3662 | memset(buffer, ' ', 80); |
| 3663 | memcpy(&buffer[0], node->data, strlen(node->data)); |
| 3664 | node = node->next; |
| 3665 | if (node) { |
| 3666 | memcpy(&buffer[30], node->data, strlen(node->data)); |
| 3667 | int pos = 30 + strlen(node->data); |
| 3668 | if (pos <= 78) { |
| 3669 | buffer[pos] = '\n'; |
| 3670 | buffer[pos + 1] = '\0'; |
| 3671 | } |
| 3672 | } |
| 3673 | buffer[78] = '\n'; |
| 3674 | buffer[79] = '\0'; |
| 3675 | |
| 3676 | DPrintf(buffer); |
| 3677 | |
| 3678 | if (node) |
| 3679 | node = node->next; |
| 3680 | } |
| 3681 | |
| 3682 | return; |
| 3683 | } |
| 3684 | |
| 3685 | // display help description |
| 3686 | while (node) { |
| 3687 | if (!stricmp(node->data, s)) { |
| 3688 | // we found a match! |
| 3689 | DPrintf("%s:\n", node->data); |
| 3690 | if (node->desc) |
| 3691 | DPrintf("%s\n", node->desc); |
| 3692 | else |
| 3693 | DPrintf(DTXT_IC_NOADDITIONALINFO); |
| 3694 | return; |
| 3695 | } |
| 3696 | node = node->next; |
| 3697 | } |
| 3698 | |
| 3699 | DPrintf(DTXT_IC_COMMANDNOTFOUND); |
| 3700 | } |
| 3701 | |
| 3702 | // copies a string from src to dest, making dest all lower case |
| 3703 | void strlowcpy(char *dest, const char *src) { |
| 3704 | ASSERT((dest != NULL) && (src != NULL)); |
| 3705 | char *s, *d; |
| 3706 | s = (char *)src; |
| 3707 | d = dest; |
| 3708 | |
| 3709 | while (*s) { |
| 3710 | *d = tolower(*s); |
| 3711 | s++; |
| 3712 | d++; |
| 3713 | } |
| 3714 | // do the final NULL |
| 3715 | *d = '\0'; |
| 3716 | } |
| 3717 | |
| 3718 | // DMFCBase::AddInputCommand |
| 3719 | // |
| 3720 | // When the client (or dedicated server) types a message that begins with a $, DMFC will look through |
| 3721 | // all the values you passed to AddInputCommand() and see if any match. If so it passes the entire |
| 3722 | // command string to the given function handler. Returns 1 on success, -1 if out of memory, 0 if it already |
| 3723 | // exists. These commands are not case sensitive. |
| 3724 | // Ex. AddInputCommand("team"); //this handles all the '$team' passed in |
| 3725 | int8_t DMFCBase::AddInputCommand(const char *command, const char *description, void (*handler)(const char *), bool allow_remotely) { |
| 3726 | ASSERT(command != NULL); |
| 3727 | ASSERT(handler != NULL); |
| 3728 | |
| 3729 | // traverse to the end of the list checking for duplicates along the way |
| 3730 | tInputCommandNode *node = m_InputCommandRootNode; |
| 3731 | |
| 3732 | if (!node) { |
| 3733 | // there is none currently in the list, add it now |
| 3734 | node = (tInputCommandNode *)malloc(sizeof(tInputCommandNode)); |
| 3735 | if (!node) { |
| 3736 | return -1; |
| 3737 | } |
| 3738 | // fill in data |
| 3739 | node->next = NULL; |
| 3740 | node->handler = handler; |
| 3741 | node->allow_remote = allow_remotely; |
| 3742 | node->data = (char *)malloc(strlen(command) + 1); |
| 3743 | if (!node->data) { // out of memory |
| 3744 | free(node); |
| 3745 | return -1; |
| 3746 | } |
| 3747 | strlowcpy(node->data, command); |
| 3748 | |
| 3749 | node->desc = (char *)malloc(strlen(description) + 1); |
| 3750 | if (node->desc) |
| 3751 | strcpy(node->desc, description); |
| 3752 | |
| 3753 | // all went ok |
| 3754 | m_InputCommandRootNode = node; |
| 3755 | return 1; |
| 3756 | } |
| 3757 | |
| 3758 | while (node->next) { |
| 3759 | // check this node to make sure it's not a duplicate |
| 3760 | if (!stricmp(node->data, command)) { |
| 3761 | // we found a duplicate |
| 3762 | return 0; |
| 3763 | } |
| 3764 | node = node->next; |
| 3765 | } |
| 3766 | |
| 3767 | // we need to check the current node since while(node->next) breaks out before checking the last node |
| 3768 | if (!stricmp(node->data, command)) { |
| 3769 | // we found a duplicate |
| 3770 | return 0; |
| 3771 | } |
| 3772 | |
| 3773 | // it looks like everything went ok, now just create a new node and tack it on to the end |
| 3774 | // of the list. All that can go wrong now is an out of memory error. |
| 3775 | tInputCommandNode *temp; |
| 3776 | temp = (tInputCommandNode *)malloc(sizeof(tInputCommandNode)); |
| 3777 | if (!temp) { // out of memory |
| 3778 | return -1; |
| 3779 | } |
| 3780 | temp->next = NULL; |
| 3781 | temp->handler = handler; |
| 3782 | temp->allow_remote = allow_remotely; |
| 3783 | temp->data = (char *)malloc(strlen(command) + 1); |
| 3784 | if (!temp->data) { // out of memory |
| 3785 | free(temp); |
| 3786 | return -1; |
| 3787 | } |
| 3788 | strlowcpy(temp->data, command); |
| 3789 | |
| 3790 | temp->desc = (char *)malloc(strlen(description) + 1); |
| 3791 | if (temp->desc) |
| 3792 | strcpy(temp->desc, description); |
| 3793 | |
| 3794 | // now tack it on the end of the list and thats all |
| 3795 | node->next = temp; |
| 3796 | return 1; |
| 3797 | } |
| 3798 | |
| 3799 | // DMFCBase::DisconnectMe |
| 3800 | // |
| 3801 | // Disconnects yourself from the game. It should be called when you are kicked or banned to make the |
| 3802 | // whole process a bit nicer/cleaner. Even if it doesn't get called when kicked, you will still |
| 3803 | // eventually disconnect. |
| 3804 | void DMFCBase::DisconnectMe(void) { Netgame->flags |= NF_EXIT_NOW; } |
| 3805 | |
| 3806 | // Does a check on on the pinfo info making sure it is valid |
| 3807 | void DMFCBase::CheckPInfo() { |
| 3808 | for (int slot = 0; slot < MAX_PLAYER_RECORDS; slot++) { |
| 3809 | player_record *pr = GetPlayerRecord(slot); |
| 3810 | if (pr && pr->state != STATE_EMPTY) { |
| 3811 | // now go through the victim list and check |
| 3812 | tPKillerInfo *node; |
| 3813 | |
| 3814 | ASSERT(pr->pinfo != NULL); |
| 3815 | node = pr->pinfo->GetFirstKiller(); |
| 3816 | |
| 3817 | while (node) { |
| 3818 | ASSERT(node->slot >= 0 && node->slot < 64); |
| 3819 | node = node->next; |
| 3820 | } |
| 3821 | } |
| 3822 | } |
| 3823 | } |
| 3824 | |
| 3825 | // DMFCBase::EnableOnScreenMenu |
| 3826 | // |
| 3827 | // Turns on/off the onscreen menu |
| 3828 | void DMFCBase::EnableOnScreenMenu(bool enable) { |
| 3829 | if (enable) |
| 3830 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_INOPTIONS); |
| 3831 | else |
| 3832 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_INOPTIONS); |
| 3833 | } |
| 3834 | |
| 3835 | // DMFCBase::EnableAutoSaveLevelEnd |
| 3836 | // |
| 3837 | // Disables/Enables the autosaving of game stats to file on level end |
| 3838 | void DMFCBase::EnableAutoSaveLevelEnd(bool enable) { |
| 3839 | if (enable) |
| 3840 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVELEVELEND); |
| 3841 | else |
| 3842 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVELEVELEND); |
| 3843 | } |
| 3844 | |
| 3845 | // DMFCBase::EnableAutoSaveDisconnect |
| 3846 | // |
| 3847 | // Disables/Enables the autosaving of game stats to file on disconnect from the game |
| 3848 | void DMFCBase::EnableAutoSaveDisconnect(bool enable) { |
| 3849 | if (enable) |
| 3850 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVEDISC); |
| 3851 | else |
| 3852 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVEDISC); |
| 3853 | } |
| 3854 | |
| 3855 | // DMFCBase::GenerateStatFilename |
| 3856 | // |
| 3857 | // Given the following information it will return a full path to what |
| 3858 | // the recommended filename to save stats to should be. |
| 3859 | // root = Multiplayer DLL Name (filename will start with this) |
| 3860 | // end_of_level = pass true if this is the end of a level stats |
| 3861 | void DMFCBase::GenerateStatFilename(char *filename, const char *root, bool end_of_level) { |
| 3862 | int level = Current_mission->cur_level; |
| 3863 | char *name = Netgame->name; |
| 3864 | struct tm *newtime; |
| 3865 | time_t long_time; |
| 3866 | |
| 3867 | time(&long_time); |
| 3868 | newtime = localtime(&long_time); |
| 3869 | |
| 3870 | char fname[256]; |
| 3871 | char timestr[100]; |
| 3872 | char day[8], month[8]; |
| 3873 | |
| 3874 | switch (newtime->tm_wday) { |
| 3875 | case 0: |
| 3876 | strcpy(day, DTXT_SUNDAY); |
| 3877 | break; |
| 3878 | case 1: |
| 3879 | strcpy(day, DTXT_MONDAY); |
| 3880 | break; |
| 3881 | case 2: |
| 3882 | strcpy(day, DTXT_TUESDAY); |
| 3883 | break; |
| 3884 | case 3: |
| 3885 | strcpy(day, DTXT_WEDNESDAY); |
| 3886 | break; |
| 3887 | case 4: |
| 3888 | strcpy(day, DTXT_THURSDAY); |
| 3889 | break; |
| 3890 | case 5: |
| 3891 | strcpy(day, DTXT_FRIDAY); |
| 3892 | break; |
| 3893 | case 6: |
| 3894 | strcpy(day, DTXT_SATURDAY); |
| 3895 | break; |
| 3896 | } |
| 3897 | |
| 3898 | switch (newtime->tm_mon) { |
| 3899 | case 0: |
| 3900 | strcpy(month, DTXT_JANUARY); |
| 3901 | break; |
| 3902 | case 1: |
| 3903 | strcpy(month, DTXT_FEBRUARY); |
| 3904 | break; |
| 3905 | case 2: |
| 3906 | strcpy(month, DTXT_MARCH); |
| 3907 | break; |
| 3908 | case 3: |
| 3909 | strcpy(month, DTXT_APRIL); |
| 3910 | break; |
| 3911 | case 4: |
| 3912 | strcpy(month, DTXT_MAY); |
| 3913 | break; |
| 3914 | case 5: |
| 3915 | strcpy(month, DTXT_JUNE); |
| 3916 | break; |
| 3917 | case 6: |
| 3918 | strcpy(month, DTXT_JULY); |
| 3919 | break; |
| 3920 | case 7: |
| 3921 | strcpy(month, DTXT_AUGUST); |
| 3922 | break; |
| 3923 | case 8: |
| 3924 | strcpy(month, DTXT_SEPTEMBER); |
| 3925 | break; |
| 3926 | case 9: |
| 3927 | strcpy(month, DTXT_OCTOBER); |
| 3928 | break; |
| 3929 | case 10: |
| 3930 | strcpy(month, DTXT_NOVEMBER); |
| 3931 | break; |
| 3932 | case 11: |
| 3933 | strcpy(month, DTXT_DECEMBER); |
| 3934 | break; |
| 3935 | } |
| 3936 | |
| 3937 | snprintf(timestr, sizeof(timestr), "%s._%s._%d_%d_%02d%02d", day, month, newtime->tm_mday, newtime->tm_year + 1900, |
| 3938 | newtime->tm_hour, newtime->tm_min); |
| 3939 | snprintf(fname, sizeof(fname), "%s_%s_%d_%s%s.stats", root, name, level, (end_of_level) ? DTXT_ENDOFLEVELCONCAT : "", |
| 3940 | timestr); |
| 3941 | |
| 3942 | // remove all spaces (convert to _) |
| 3943 | char *p = fname; |
| 3944 | while ((*p)) { |
| 3945 | if (*p == ' ') |
| 3946 | *p = '_'; |
| 3947 | p++; |
| 3948 | } |
| 3949 | |
| 3950 | // build the path info here |
| 3951 | DLLddio_MakePath(filename, LocalD3Dir, "netgames", fname, NULL); |
| 3952 | } |
| 3953 | |
| 3954 | // DMFCBase::IsPlayerObserver |
| 3955 | // |
| 3956 | // Returns true if the given pnum is currently an observer in the game, else returns false. |
| 3957 | // If an invalid pnum is given, then it returns false |
| 3958 | bool DMFCBase::IsPlayerObserver(int pnum) { |
| 3959 | if (!CheckPlayerNum(pnum)) |
| 3960 | return false; |
| 3961 | |
| 3962 | if (Objects[Players[pnum].objnum].type == OBJ_OBSERVER) |
| 3963 | return true; |
| 3964 | |
| 3965 | return false; |
| 3966 | } |
| 3967 | |
| 3968 | // DMFCBase::EnableOnScreenMenuBackground |
| 3969 | // |
| 3970 | // Enables/disables the onscreen menu background |
| 3971 | void DMFCBase::EnableOnScreenMenuBackground(bool enable) { |
| 3972 | if (enable) |
| 3973 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPMENUBACKGR); |
| 3974 | else |
| 3975 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_DISPMENUBACKGR); |
| 3976 | } |
| 3977 | |
| 3978 | // DMFCBase::DisplayNetGameInfo |
| 3979 | // |
| 3980 | // Displays information about the Netgame that is currently being played |
| 3981 | // on to the screen. |
| 3982 | void DMFCBase::DisplayNetGameInfo(int background_bmp, bool dedicated_server) { |
| 3983 | // char server_config_name[PAGENAME_LEN]; |
| 3984 | // char connection_name[PAGENAME_LEN]; |
| 3985 | DLLgrtext_SetFont(Game_fonts[HUD_FONT_INDEX]); |
| 3986 | |
| 3987 | int height = DLLgrfont_GetHeight(Game_fonts[HUD_FONT_INDEX]) + 1; |
| 3988 | // int height = DLLRenderHUDGetTextHeight("X")+1; |
| 3989 | ddgr_color color = GR_RGB(180, 255, 180); |
| 3990 | int x, y; |
| 3991 | y = 0; |
| 3992 | x = 15; |
| 3993 | int w, maxx = 0; |
| 3994 | char fullbuffer[1024]; |
| 3995 | |
| 3996 | int topy = 0; |
| 3997 | bool peertopeer = (bool)((Netgame->flags & NF_PEER_PEER) != 0); |
| 3998 | bool permissable = (bool)((Netgame->flags & NF_PERMISSABLE) != 0); |
| 3999 | |
| 4000 | if ((m_iProtectedFlags & DMFC_PRF_DISPMENUBACKGR) && background_bmp > BAD_BITMAP_HANDLE) { |
| 4001 | // draw the background bitmap |
| 4002 | DLLrend_SetAlphaValue(255 * 0.85f); |
| 4003 | DLLrend_SetZBufferState(0); |
| 4004 | DLLrend_SetTextureType(TT_LINEAR); |
| 4005 | DLLrend_SetLighting(LS_NONE); |
| 4006 | DLLrend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 4007 | DLLrend_DrawScaledBitmap(0, 0, *Game_window_w, 8 * height, background_bmp, 0, 0, 1, 1, 1.0, -1, NULL); |
| 4008 | DLLrend_SetZBufferState(1); |
| 4009 | } |
| 4010 | |
| 4011 | // Print out Title |
| 4012 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_HEADING); y+=height; |
| 4013 | DLLgrtext_SetColor(color); |
| 4014 | DLLgrtext_SetAlpha(255); |
| 4015 | snprintf(fullbuffer, sizeof(fullbuffer), "%s", DTXT_NGI_HEADING); |
| 4016 | DLLgrtext_Printf(x, y, fullbuffer); |
| 4017 | w = DLLgrtext_GetTextLineWidth(fullbuffer); |
| 4018 | maxx = (w > maxx) ? w : maxx; |
| 4019 | y += height; |
| 4020 | |
| 4021 | if (dedicated_server) |
| 4022 | DPrintf(DTXT_NGI_HEADING); |
| 4023 | color = GR_RGB(0, 255, 0); |
| 4024 | topy = y; // save this position |
| 4025 | |
| 4026 | // Print out Game name |
| 4027 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_GAMENAME,Netgame->name); y+=height; |
| 4028 | DLLgrtext_SetColor(color); |
| 4029 | DLLgrtext_SetAlpha(255); |
| 4030 | snprintf(fullbuffer, sizeof(fullbuffer), DTXT_NGI_GAMENAME, Netgame->name); |
| 4031 | DLLgrtext_Printf(x, y, fullbuffer); |
| 4032 | w = DLLgrtext_GetTextLineWidth(fullbuffer); |
| 4033 | maxx = (w > maxx) ? w : maxx; |
| 4034 | y += height; |
| 4035 | |
| 4036 | if (dedicated_server) |
| 4037 | DPrintf(DTXT_NGI_GAMENAME, Netgame->name); |
| 4038 | |
| 4039 | // Print out Mission name |
| 4040 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_MISSIONNAME,Netgame->mission); y+=height; |
| 4041 | DLLgrtext_SetColor(color); |
| 4042 | DLLgrtext_SetAlpha(255); |
| 4043 | snprintf(fullbuffer, sizeof(fullbuffer), DTXT_NGI_MISSIONNAME, Netgame->mission); |
| 4044 | DLLgrtext_Printf(x, y, fullbuffer); |
| 4045 | w = DLLgrtext_GetTextLineWidth(fullbuffer); |
| 4046 | maxx = (w > maxx) ? w : maxx; |
| 4047 | y += height; |
| 4048 | |
| 4049 | if (dedicated_server) |
| 4050 | DPrintf(DTXT_NGI_MISSIONNAME, Netgame->mission); |
| 4051 | |
| 4052 | // Print out Script name |
| 4053 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_SCRIPTNAME,Netgame->scriptname); y+=height; |
| 4054 | DLLgrtext_SetColor(color); |
| 4055 | DLLgrtext_SetAlpha(255); |
| 4056 | snprintf(fullbuffer, sizeof(fullbuffer), DTXT_NGI_SCRIPTNAME, Netgame->scriptname); |
| 4057 | DLLgrtext_Printf(x, y, fullbuffer); |
| 4058 | w = DLLgrtext_GetTextLineWidth(fullbuffer); |
| 4059 | maxx = (w > maxx) ? w : maxx; |
| 4060 | y += height; |
| 4061 | |
| 4062 | if (dedicated_server) |
| 4063 | DPrintf(DTXT_NGI_SCRIPTNAME, Netgame->scriptname); |
| 4064 | |
| 4065 | // Print out PPS |
| 4066 | if (GetLocalRole() == LR_SERVER) { |
| 4067 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_PPS,Netgame->packets_per_second); y+=height; |
| 4068 | DLLgrtext_SetColor(color); |
| 4069 | DLLgrtext_SetAlpha(255); |
| 4070 | snprintf(fullbuffer, sizeof(fullbuffer), DTXT_NGI_PPS, Netgame->packets_per_second); |
| 4071 | DLLgrtext_Printf(x, y, fullbuffer); |
| 4072 | w = DLLgrtext_GetTextLineWidth(fullbuffer); |
| 4073 | maxx = (w > maxx) ? w : maxx; |
| 4074 | y += height; |
| 4075 | |
| 4076 | if (dedicated_server) |
| 4077 | DPrintf(DTXT_NGI_PPS, Netgame->packets_per_second); |
| 4078 | } else { |
| 4079 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_PPSSERVER,Netgame->packets_per_second,NetPlayers[GetPlayerNum()].pps); |
| 4080 | // y+=height; |
| 4081 | DLLgrtext_SetColor(color); |
| 4082 | DLLgrtext_SetAlpha(255); |
| 4083 | snprintf(fullbuffer, sizeof(fullbuffer), DTXT_NGI_PPSSERVER, Netgame->packets_per_second, |
| 4084 | NetPlayers[GetPlayerNum()].pps); |
| 4085 | DLLgrtext_Printf(x, y, fullbuffer); |
| 4086 | w = DLLgrtext_GetTextLineWidth(fullbuffer); |
| 4087 | maxx = (w > maxx) ? w : maxx; |
| 4088 | y += height; |
| 4089 | |
| 4090 | if (dedicated_server) |
| 4091 | DPrintf(DTXT_NGI_PPSSERVER, Netgame->packets_per_second, NetPlayers[GetPlayerNum()].pps); |
| 4092 | } |
| 4093 | |
| 4094 | // Print out Max Players |
| 4095 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_MAXPLAYERS,Netgame->max_players); y+=height; |
| 4096 | DLLgrtext_SetColor(color); |
| 4097 | DLLgrtext_SetAlpha(255); |
| 4098 | snprintf(fullbuffer, sizeof(fullbuffer), DTXT_NGI_MAXPLAYERS, Netgame->max_players); |
| 4099 | DLLgrtext_Printf(x, y, fullbuffer); |
| 4100 | w = DLLgrtext_GetTextLineWidth(fullbuffer); |
| 4101 | maxx = (w > maxx) ? w : maxx; |
| 4102 | y += height; |
| 4103 | |
| 4104 | if (dedicated_server) |
| 4105 | DPrintf(DTXT_NGI_MAXPLAYERS, Netgame->max_players); |
| 4106 | |
| 4107 | // Accurate Collision Detection |
| 4108 | bool use_acc_weap = (bool)((Netgame->flags & NF_USE_ACC_WEAP) != 0); |
| 4109 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_ACCURATECOLL,(use_acc_weap)?DTXT_MNUON:DTXT_MNUOFF); y+=height; |
| 4110 | DLLgrtext_SetColor(color); |
| 4111 | DLLgrtext_SetAlpha(255); |
| 4112 | snprintf(fullbuffer, sizeof(fullbuffer), DTXT_NGI_ACCURATECOLL, (use_acc_weap) ? DTXT_MNUON : DTXT_MNUOFF); |
| 4113 | DLLgrtext_Printf(x, y, fullbuffer); |
| 4114 | w = DLLgrtext_GetTextLineWidth(fullbuffer); |
| 4115 | maxx = (w > maxx) ? w : maxx; |
| 4116 | y += height; |
| 4117 | |
| 4118 | if (dedicated_server) |
| 4119 | DPrintf(DTXT_NGI_ACCURATECOLL, (use_acc_weap) ? DTXT_MNUON : DTXT_MNUOFF); |
| 4120 | |
| 4121 | // move to second column |
| 4122 | y = topy; |
| 4123 | x += (maxx + 10); |
| 4124 | |
| 4125 | // Rotatitional Velocity |
| 4126 | bool rot_vel_sent = (bool)((Netgame->flags & NF_SENDROTVEL) != 0); |
| 4127 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_SENDROTATIONAL,(rot_vel_sent)?DTXT_MNUON:DTXT_MNUOFF); y+=height; |
| 4128 | DLLgrtext_SetColor(color); |
| 4129 | DLLgrtext_SetAlpha(255); |
| 4130 | snprintf(fullbuffer, sizeof(fullbuffer), DTXT_NGI_SENDROTATIONAL, (rot_vel_sent) ? DTXT_MNUON : DTXT_MNUOFF); |
| 4131 | DLLgrtext_Printf(x, y, fullbuffer); |
| 4132 | w = DLLgrtext_GetTextLineWidth(fullbuffer); |
| 4133 | y += height; |
| 4134 | |
| 4135 | if (dedicated_server) |
| 4136 | DPrintf(DTXT_NGI_SENDROTATIONAL, (rot_vel_sent) ? DTXT_MNUON : DTXT_MNUOFF); |
| 4137 | |
| 4138 | // Print out time limit |
| 4139 | if (Netgame->flags & NF_TIMER) { |
| 4140 | DLLgrtext_SetColor(color); |
| 4141 | DLLgrtext_SetAlpha(255); |
| 4142 | DLLgrtext_Printf(x, y, DTXT_NGI_TIMELIMIT, Netgame->timelimit, |
| 4143 | (Netgame->timelimit == 1) ? DTXT_MINUTE : DTXT_MINUTES); |
| 4144 | y += height; |
| 4145 | |
| 4146 | if (dedicated_server) |
| 4147 | DPrintf(DTXT_NGI_TIMELIMIT, Netgame->timelimit, (Netgame->timelimit == 1) ? DTXT_MINUTE : DTXT_MINUTES); |
| 4148 | |
| 4149 | float t_left = 0; |
| 4150 | t_left = (Netgame->timelimit * 60.0f) - RealGametime; |
| 4151 | |
| 4152 | // Print out time left |
| 4153 | DLLgrtext_SetColor(color); |
| 4154 | DLLgrtext_SetAlpha(255); |
| 4155 | DLLgrtext_Printf(x, y, DTXT_NGI_TIMELEFT, GetTimeString(t_left)); |
| 4156 | y += height; |
| 4157 | |
| 4158 | if (dedicated_server) |
| 4159 | DPrintf(DTXT_NGI_TIMELEFT, GetTimeString(t_left)); |
| 4160 | } else { |
| 4161 | DLLgrtext_SetColor(color); |
| 4162 | DLLgrtext_SetAlpha(255); |
| 4163 | DLLgrtext_Printf(x, y, DTXT_NGI_NOTIMELIMIT); |
| 4164 | y += height; |
| 4165 | |
| 4166 | if (dedicated_server) |
| 4167 | DPrintf(DTXT_NGI_NOTIMELIMIT); |
| 4168 | } |
| 4169 | |
| 4170 | // Print out Goal |
| 4171 | if (Netgame->killgoal > 0) { |
| 4172 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_GOALLIMIT,Netgame->killgoal); y+=height; |
| 4173 | DLLgrtext_SetColor(color); |
| 4174 | DLLgrtext_SetAlpha(255); |
| 4175 | DLLgrtext_Printf(x, y, DTXT_NGI_GOALLIMIT, Netgame->killgoal); |
| 4176 | y += height; |
| 4177 | |
| 4178 | if (dedicated_server) |
| 4179 | DPrintf(DTXT_NGI_GOALLIMIT, Netgame->killgoal); |
| 4180 | } else { |
| 4181 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_NOGOAL); y+=height; |
| 4182 | DLLgrtext_SetColor(color); |
| 4183 | DLLgrtext_SetAlpha(255); |
| 4184 | DLLgrtext_Printf(x, y, DTXT_NGI_NOGOAL); |
| 4185 | y += height; |
| 4186 | |
| 4187 | if (dedicated_server) |
| 4188 | DPrintf(DTXT_NGI_NOGOAL); |
| 4189 | } |
| 4190 | |
| 4191 | // Print out Respawn time |
| 4192 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_RESPAWNTIME,GetTimeString(Netgame->respawn_time)); y+=height; |
| 4193 | DLLgrtext_SetColor(color); |
| 4194 | DLLgrtext_SetAlpha(255); |
| 4195 | DLLgrtext_Printf(x, y, DTXT_NGI_RESPAWNTIME, GetTimeString(Netgame->respawn_time)); |
| 4196 | y += height; |
| 4197 | |
| 4198 | if (dedicated_server) |
| 4199 | DPrintf(DTXT_NGI_RESPAWNTIME, GetTimeString(Netgame->respawn_time)); |
| 4200 | |
| 4201 | // Print out Client/Server Packet Loss |
| 4202 | if ((GetPlayerNum() == 0) || peertopeer) { |
| 4203 | // packet loss info not available |
| 4204 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_PACKETLOSSNA); y+= height; |
| 4205 | DLLgrtext_SetColor(color); |
| 4206 | DLLgrtext_SetAlpha(255); |
| 4207 | DLLgrtext_Printf(x, y, DTXT_NGI_PACKETLOSSNA); |
| 4208 | y += height; |
| 4209 | |
| 4210 | if (dedicated_server) |
| 4211 | DPrintf(DTXT_NGI_PACKETLOSSNA); |
| 4212 | } else { |
| 4213 | float packetloss = NetPlayers[GetPlayerNum()].percent_loss; |
| 4214 | |
| 4215 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_PACKETLOSS,packetloss); y+=height; |
| 4216 | DLLgrtext_SetColor(color); |
| 4217 | DLLgrtext_SetAlpha(255); |
| 4218 | DLLgrtext_Printf(x, y, DTXT_NGI_PACKETLOSS, packetloss); |
| 4219 | y += height; |
| 4220 | |
| 4221 | if (dedicated_server) |
| 4222 | DPrintf(DTXT_NGI_PACKETLOSS, packetloss); |
| 4223 | } |
| 4224 | |
| 4225 | // Print out Architecture |
| 4226 | // DLLRenderHUDText(color,255,0,x,y,DTXT_NGI_NETWORKMODEL,(peertopeer)?DTXT_PEERTOPEER:DTXT_CLIENTSERVER); y+=height; |
| 4227 | DLLgrtext_SetColor(color); |
| 4228 | DLLgrtext_SetAlpha(255); |
| 4229 | DLLgrtext_Printf(x, y, DTXT_NGI_NETWORKMODEL, |
| 4230 | (peertopeer) ? DTXT_PEERTOPEER : ((permissable) ? DTXT_PERMISSABLE : DTXT_CLIENTSERVER)); |
| 4231 | y += height; |
| 4232 | |
| 4233 | if (dedicated_server) |
| 4234 | DPrintf(DTXT_NGI_NETWORKMODEL, |
| 4235 | (peertopeer) ? DTXT_PEERTOPEER : ((permissable) ? DTXT_PERMISSABLE : DTXT_CLIENTSERVER)); |
| 4236 | } |
| 4237 | |
| 4238 | /* |
| 4239 | **************************************************************** |
| 4240 | * Registry Database Functions * |
| 4241 | **************************************************************** |
| 4242 | */ |
| 4243 | |
| 4244 | // DatabaseRegister |
| 4245 | // Registers your multiplayer game with the database. This must be |
| 4246 | // called before any other database function, or they will fail until this |
| 4247 | // is called. |
| 4248 | void DMFCBase::DatabaseRegister(char *name) { |
| 4249 | if (name) { |
| 4250 | strncpy(DatabaseRegisteredName, name, MAX_DBNAME_SIZE - 1); |
| 4251 | DatabaseRegisteredName[MAX_DBNAME_SIZE - 1] = '\0'; |
| 4252 | } |
| 4253 | } |
| 4254 | |
| 4255 | // DatabaseRead |
| 4256 | // Reads a string from the database |
| 4257 | bool DMFCBase::DatabaseRead(const char *label, char *entry, int *entrylen) { |
| 4258 | if (DatabaseRegisteredName[0] == '\0') |
| 4259 | return false; |
| 4260 | if (!label || !entry || !entrylen) |
| 4261 | return false; |
| 4262 | |
| 4263 | int reg_len = strlen(DatabaseRegisteredName); |
| 4264 | int copy = MAX_DBLABEL_SIZE - 1 - reg_len; |
| 4265 | char buffer[MAX_DBLABEL_SIZE]; |
| 4266 | |
| 4267 | strcpy(buffer, DatabaseRegisteredName); |
| 4268 | strncpy(&buffer[reg_len], label, copy); |
| 4269 | buffer[MAX_DBLABEL_SIZE - 1] = '\0'; |
| 4270 | |
| 4271 | return DatabaseRead1(buffer, entry, entrylen); |
| 4272 | } |
| 4273 | |
| 4274 | // DatabaseRead |
| 4275 | // Reads wordsize bytes from the database |
| 4276 | bool DMFCBase::DatabaseRead(const char *label, void *entry, int wordsize) { |
| 4277 | if (DatabaseRegisteredName[0] == '\0') |
| 4278 | return false; |
| 4279 | if (!label || !entry) |
| 4280 | return false; |
| 4281 | |
| 4282 | int reg_len = strlen(DatabaseRegisteredName); |
| 4283 | int copy = MAX_DBLABEL_SIZE - 1 - reg_len; |
| 4284 | char buffer[MAX_DBLABEL_SIZE]; |
| 4285 | |
| 4286 | strcpy(buffer, DatabaseRegisteredName); |
| 4287 | strncpy(&buffer[reg_len], label, copy); |
| 4288 | buffer[MAX_DBLABEL_SIZE - 1] = '\0'; |
| 4289 | |
| 4290 | return DatabaseRead2(buffer, entry, wordsize); |
| 4291 | } |
| 4292 | |
| 4293 | // DatabaseRead |
| 4294 | // Reads a bool from the database |
| 4295 | bool DMFCBase::DatabaseRead(const char *label, bool *entry) { |
| 4296 | if (DatabaseRegisteredName[0] == '\0') |
| 4297 | return false; |
| 4298 | if (!label || !entry) |
| 4299 | return false; |
| 4300 | |
| 4301 | int reg_len = strlen(DatabaseRegisteredName); |
| 4302 | int copy = MAX_DBLABEL_SIZE - 1 - reg_len; |
| 4303 | char buffer[MAX_DBLABEL_SIZE]; |
| 4304 | |
| 4305 | strcpy(buffer, DatabaseRegisteredName); |
| 4306 | strncpy(&buffer[reg_len], label, copy); |
| 4307 | buffer[MAX_DBLABEL_SIZE - 1] = '\0'; |
| 4308 | |
| 4309 | return DatabaseRead3(buffer, entry); |
| 4310 | } |
| 4311 | |
| 4312 | // DatabaseWrite |
| 4313 | // Writes/Updates a string to the database |
| 4314 | bool DMFCBase::DatabaseWrite(const char *label, const char *entry, int entrylen) { |
| 4315 | if (DatabaseRegisteredName[0] == '\0') |
| 4316 | return false; |
| 4317 | if (!label || !entry) |
| 4318 | return false; |
| 4319 | |
| 4320 | int reg_len = strlen(DatabaseRegisteredName); |
| 4321 | int copy = MAX_DBLABEL_SIZE - 1 - reg_len; |
| 4322 | char buffer[MAX_DBLABEL_SIZE]; |
| 4323 | |
| 4324 | strcpy(buffer, DatabaseRegisteredName); |
| 4325 | strncpy(&buffer[reg_len], label, copy); |
| 4326 | buffer[MAX_DBLABEL_SIZE - 1] = '\0'; |
| 4327 | |
| 4328 | return DatabaseWrite(buffer, entry, entrylen); |
| 4329 | } |
| 4330 | |
| 4331 | // DatabaseWrite |
| 4332 | // Writes/Updates a value to the database |
| 4333 | bool DMFCBase::DatabaseWrite(const char *label, int entry) { |
| 4334 | if (DatabaseRegisteredName[0] == '\0') |
| 4335 | return false; |
| 4336 | if (!label) |
| 4337 | return false; |
| 4338 | |
| 4339 | int reg_len = strlen(DatabaseRegisteredName); |
| 4340 | int copy = MAX_DBLABEL_SIZE - 1 - reg_len; |
| 4341 | char buffer[MAX_DBLABEL_SIZE]; |
| 4342 | |
| 4343 | strcpy(buffer, DatabaseRegisteredName); |
| 4344 | strncpy(&buffer[reg_len], label, copy); |
| 4345 | buffer[MAX_DBLABEL_SIZE - 1] = '\0'; |
| 4346 | |
| 4347 | return DatabaseWrite(buffer, entry); |
| 4348 | } |
| 4349 | |
| 4350 | // CompareNetworkAddress |
| 4351 | // |
| 4352 | // Compare's two network addresses, returns true if they are the same, false if not. |
| 4353 | // use_port: if this is true, than it will consider the port part of the network address |
| 4354 | bool DMFCBase::CompareNetworkAddress(network_address *one, network_address *two, bool use_port) { |
| 4355 | if (use_port) { |
| 4356 | // compare the whole darned thing |
| 4357 | if (!memcmp(one, two, sizeof(network_address))) |
| 4358 | return true; |
| 4359 | else |
| 4360 | return false; |
| 4361 | } else { |
| 4362 | // compare all but the port |
| 4363 | if (!memcmp(one->address, two->address, 6) && !memcmp(one->net_id, two->net_id, 4) && |
| 4364 | !memcmp(&one->connection_type, &two->connection_type, sizeof(network_protocol))) { |
| 4365 | // looks the same to me |
| 4366 | return true; |
| 4367 | } else { |
| 4368 | // something didn't match |
| 4369 | return false; |
| 4370 | } |
| 4371 | } |
| 4372 | |
| 4373 | return false; |
| 4374 | } |
| 4375 | |
| 4376 | // IsMasterTrackerGame |
| 4377 | // |
| 4378 | // returns true if this game is being played on the master tracker |
| 4379 | bool DMFCBase::IsMasterTrackerGame(void) { return (bool)((*m_bTrackerGame) != 0); } |
| 4380 | |
| 4381 | // ConvertLocalToServerObjnum |
| 4382 | // |
| 4383 | // Given an objnum, it will convert the number from your local objnum to the server's objnum |
| 4384 | // It will return -1 on error |
| 4385 | int DMFCBase::ConvertLocalToServerObjnum(int objnum) { |
| 4386 | if (GetLocalRole() == LR_SERVER) |
| 4387 | return (objnum < 0 || objnum >= MAX_OBJECTS) ? -1 : objnum; |
| 4388 | |
| 4389 | if (objnum < 0 || objnum >= MAX_OBJECTS) |
| 4390 | return -1; |
| 4391 | |
| 4392 | int s = Local_object_list[objnum]; |
| 4393 | |
| 4394 | return (s == 65535) ? -1 : s; |
| 4395 | } |
| 4396 | |
| 4397 | // ConvertServerToLocalObjnum |
| 4398 | // |
| 4399 | // Given an objnum from the server, this function will convert the objnum to your local objnum |
| 4400 | // It will return -1 on error |
| 4401 | int DMFCBase::ConvertServerToLocalObjnum(int objnum) { |
| 4402 | if (GetLocalRole() == LR_SERVER) |
| 4403 | return (objnum < 0 || objnum >= MAX_OBJECTS) ? -1 : objnum; |
| 4404 | |
| 4405 | if (objnum < 0 || objnum >= MAX_OBJECTS) |
| 4406 | return -1; |
| 4407 | |
| 4408 | int s = Server_object_list[objnum]; |
| 4409 | |
| 4410 | return (s == 65535) ? -1 : s; |
| 4411 | } |
| 4412 | |
| 4413 | // DMFCBase::AnnounceTeamChangeDeny |
| 4414 | // |
| 4415 | // Tells a player that team change request was denied |
| 4416 | void DMFCBase::AnnounceTeamChangeDeny(int pnum) { |
| 4417 | if (pnum == *Player_num) { |
| 4418 | DLLAddHUDMessage(DTXT_CHANGETEAMDENIED); |
| 4419 | } else { |
| 4420 | if (GetLocalRole() == LR_SERVER) { |
| 4421 | // tell the client the change has been denied |
| 4422 | SendControlMessageToPlayer(pnum, CM_TEAMCHANGEDENIED); |
| 4423 | } |
| 4424 | } |
| 4425 | } |
| 4426 | |
| 4427 | // DMFCBase::SetDeathMessageFilter |
| 4428 | // |
| 4429 | // Sets the death message filter |
| 4430 | void DMFCBase::SetDeathMessageFilter(int level) { |
| 4431 | if (level < 0) |
| 4432 | level = 0; |
| 4433 | if (level > 2) |
| 4434 | level = 2; |
| 4435 | |
| 4436 | if (level == m_iDeathMessageFilter) |
| 4437 | return; |
| 4438 | |
| 4439 | m_iDeathMessageFilter = level; |
| 4440 | switch (level) { |
| 4441 | case DM_FILTER_FULL: |
| 4442 | DLLAddHUDMessage(DTXT_KILLMSGFULL); |
| 4443 | break; |
| 4444 | case DM_FILTER_SIMPLE: |
| 4445 | DLLAddHUDMessage(DTXT_KILLMSGSIMPLE); |
| 4446 | break; |
| 4447 | case DM_FILTER_NONE: |
| 4448 | DLLAddHUDMessage(DTXT_KILLMSGNONE); |
| 4449 | break; |
| 4450 | }; |
| 4451 | } |
| 4452 | |
| 4453 | // DMFCBase::MakeClientsWait |
| 4454 | // |
| 4455 | // If passed true than all joining clients are forced to wait until they are given the signal to |
| 4456 | // join, either through SignalClientStart() or by passing false to MakeClientsWait |
| 4457 | void DMFCBase::MakeClientsWait(bool wait) { |
| 4458 | m_bMakeClientsWait = wait; |
| 4459 | |
| 4460 | if (!wait) { |
| 4461 | // tell all the clients it's time to start |
| 4462 | for (int i = 0; i < DLLMAX_PLAYERS; i++) { |
| 4463 | if (CheckPlayerNum(i)) { |
| 4464 | SignalClientStart(i); |
| 4465 | } |
| 4466 | } |
| 4467 | } else { |
| 4468 | // tell all the clients to hold up |
| 4469 | WaitForServer(true); |
| 4470 | } |
| 4471 | } |
| 4472 | |
| 4473 | // DMFCBase::SignalClientStart |
| 4474 | // |
| 4475 | // Given a player num, it tells the client that they can start moving and playing |
| 4476 | void DMFCBase::SignalClientStart(int pnum) { |
| 4477 | if (GetLocalRole() != LR_SERVER) { |
| 4478 | return; |
| 4479 | } |
| 4480 | |
| 4481 | SendControlMessageToPlayer(pnum, CM_SIGNALSTART); |
| 4482 | if (pnum == GetPlayerNum()) |
| 4483 | WaitForServer(false); |
| 4484 | } |
| 4485 | |
| 4486 | // DMFCBase::WaitForServer |
| 4487 | // |
| 4488 | // Call this to start waiting, until the server tells us to stop (by passing false as a parm) |
| 4489 | void DMFCBase::WaitForServer(bool wait) { |
| 4490 | if (wait) { |
| 4491 | Players[GetPlayerNum()].movement_scalar = 0; |
| 4492 | Players[GetPlayerNum()].weapon_recharge_scalar = 99999.9f; |
| 4493 | m_bMakeClientsWait = true; |
| 4494 | } else { |
| 4495 | Players[GetPlayerNum()].movement_scalar = 1.0f; |
| 4496 | Players[GetPlayerNum()].weapon_recharge_scalar = 1.0f; |
| 4497 | m_bMakeClientsWait = false; |
| 4498 | } |
| 4499 | |
| 4500 | if (GetLocalRole() != LR_SERVER) |
| 4501 | return; |
| 4502 | |
| 4503 | if (!wait) |
| 4504 | return; |
| 4505 | |
| 4506 | for (int i = 0; i < DLLMAX_PLAYERS; i++) { |
| 4507 | if (CheckPlayerNum(i)) { |
| 4508 | SendControlMessageToPlayer(i, CM_SIGNALWAIT); |
| 4509 | } |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | // DMFCBase::WaitingForServerLoop |
| 4514 | // |
| 4515 | // Called per frame while waiting for the server to signal go |
| 4516 | void DMFCBase::WaitingForServerLoop(void) { |
| 4517 | static float time_ac = 0; |
| 4518 | static bool show = true; |
| 4519 | |
| 4520 | time_ac += *Frametime; |
| 4521 | |
| 4522 | if (time_ac > 0.5) { |
| 4523 | time_ac = 0; |
| 4524 | show = !show; |
| 4525 | } |
| 4526 | |
| 4527 | if (show) { |
| 4528 | DLLgrtext_SetFont(Game_fonts[MENU_FONT_INDEX]); |
| 4529 | |
| 4530 | int height = DLLgrfont_GetHeight(Game_fonts[MENU_FONT_INDEX]); |
| 4531 | |
| 4532 | DLLRenderHUDTextFlags(HUDTEXT_CENTERED, GR_WHITE, 255, 0, 0, 240 - (height / 2), DTXT_WAITFORSERVER); |
| 4533 | DLLgrtext_Flush(); |
| 4534 | } |
| 4535 | |
| 4536 | // Make sure we stay waiting... |
| 4537 | Players[GetPlayerNum()].movement_scalar = 0; |
| 4538 | Players[GetPlayerNum()].weapon_recharge_scalar = 99999.9f; |
| 4539 | } |
| 4540 | |
| 4541 | // DMFCBase::IAmDedicatedServer |
| 4542 | // |
| 4543 | // Returns true if we are a dedicated server |
| 4544 | bool DMFCBase::IAmDedicatedServer(void) { return *Dedicated_server; } |
| 4545 | |
| 4546 | // DMFCBase::IsPlayerDedicatedServer |
| 4547 | // |
| 4548 | // Returns true if the passed in pnum/player_record is a dedicated server |
| 4549 | bool DMFCBase::IsPlayerDedicatedServer(int pnum) { |
| 4550 | // since we are looking for a server, the pnum must be 0 |
| 4551 | if (pnum != 0) |
| 4552 | return false; |
| 4553 | |
| 4554 | if (Players[pnum].team == -1) |
| 4555 | return true; |
| 4556 | |
| 4557 | return false; |
| 4558 | } |
| 4559 | bool DMFCBase::IsPlayerDedicatedServer(player_record *pr) { |
| 4560 | if (pr->state == STATE_EMPTY) |
| 4561 | return false; |
| 4562 | |
| 4563 | if (pr->state == STATE_DISCONNECTED) |
| 4564 | return (pr->team == -1) ? true : false; |
| 4565 | |
| 4566 | return IsPlayerDedicatedServer(pr->pnum); |
| 4567 | } |
| 4568 | |
| 4569 | // DMFCBase::GetPlayerTeam |
| 4570 | // |
| 4571 | // Returns the team of the player...call this instead of accessing .team directly |
| 4572 | int DMFCBase::GetPlayerTeam(int pnum) { return (Players[pnum].team == -1) ? 0 : Players[pnum].team; } |
| 4573 | |
| 4574 | // DMFCBase::ConvertHUDCoord |
| 4575 | // |
| 4576 | // Given an x,y based on a virtual 640x480 screen, this will convert it to the x,y that should be |
| 4577 | // used based on the current screen size |
| 4578 | void DMFCBase::ConvertHUDCoord(int x, int y, int *rx, int *ry) { |
| 4579 | *rx = ((float)(x) * (*Hud_aspect_x)); |
| 4580 | *ry = ((float)(y) * (*Hud_aspect_y)); |
| 4581 | } |
| 4582 | |
| 4583 | // DMFCBase::GetPlayerLogoBmp |
| 4584 | // |
| 4585 | // Given a player_num, it will return a bitmap handle to that player's ship logo, or |
| 4586 | // -1 if they don't have a logo for their ship. |
| 4587 | // if is_vclip comes back as true, than it is not a bitmap handle, but a handle |
| 4588 | // to a vclip (animated bitmap). It is an index into the DLLGameVClips[]. |
| 4589 | int DMFCBase::GetPlayerLogoBmp(int player_num, bool *is_vclip) { |
| 4590 | if (!CheckPlayerNum(player_num)) |
| 4591 | return -1; // invalid pnum |
| 4592 | |
| 4593 | int texture_handle = Players[player_num].custom_texture_handle; |
| 4594 | |
| 4595 | if (GameTextures[texture_handle].bm_handle <= BAD_BITMAP_HANDLE) |
| 4596 | return -1; |
| 4597 | |
| 4598 | *is_vclip = (GameTextures[texture_handle].flags & TF_ANIMATED) ? true : false; |
| 4599 | |
| 4600 | return GameTextures[texture_handle].bm_handle; |
| 4601 | } |
| 4602 | |
| 4603 | // DMFCBase::EnableShipLogos |
| 4604 | // |
| 4605 | // Disables or enables logo displaying for the client |
| 4606 | void DMFCBase::EnableShipLogos(bool enable) { |
| 4607 | if (enable) { |
| 4608 | ENABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_SHIPLOGOSENABLED); |
| 4609 | } else { |
| 4610 | DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_SHIPLOGOSENABLED); |
| 4611 | } |
| 4612 | |
| 4613 | DLLMultiSetLogoState(enable); |
| 4614 | } |
| 4615 | |
| 4616 | // DMFCBase::AreLogosEnabled |
| 4617 | // |
| 4618 | // returns true if ship logos are enabled |
| 4619 | bool DMFCBase::AreLogosEnabled(void) { return (bool)((m_iProtectedFlags & DMFC_PRF_SHIPLOGOSENABLED) != 0); } |
| 4620 | |
| 4621 | // DMFCBase::EnableAudioTaunts |
| 4622 | // |
| 4623 | // Disables or enables audio taunts |
| 4624 | void DMFCBase::EnableAudioTaunts(bool enable) { DLLtaunt_Enable(enable); } |
| 4625 | |
| 4626 | // DMFCBase::AreTauntsEnabled(void) |
| 4627 | // |
| 4628 | // returns true if audio taunts are enabled |
| 4629 | bool DMFCBase::AreTauntsEnabled(void) { return DLLtaunt_AreEnabled(); } |
| 4630 | |
| 4631 | // DMFCBase::RespawnPlayer |
| 4632 | // |
| 4633 | // Takes the given player and respawns his at a random start point (in a team game, team respawn |
| 4634 | // points are taken into consideration, so make sure the player is on the correct team before you |
| 4635 | // respawn him. spew_everything, if false, will override spew_energy_and_shields |
| 4636 | void DMFCBase::RespawnPlayer(int pnum, bool spew_energy_and_shields, bool spew_everything) { |
| 4637 | if (!CheckPlayerNum(pnum)) |
| 4638 | return; |
| 4639 | |
| 4640 | object *obj = &Objects[Players[pnum].objnum]; |
| 4641 | |
| 4642 | if (spew_everything) |
| 4643 | DLLPlayerSpewInventory(obj, spew_energy_and_shields, spew_everything); |
| 4644 | |
| 4645 | DLLPlayerStopSounds(pnum); |
| 4646 | |
| 4647 | DLLInitPlayerNewShip(pnum, (spew_everything) ? INVRESET_ALL : INVRESET_DEATHSPEW); |
| 4648 | |
| 4649 | if (pnum != GetPlayerNum()) |
| 4650 | return; |
| 4651 | |
| 4652 | int slot = DLLPlayerGetRandomStartPosition(pnum); |
| 4653 | |
| 4654 | DLLObjSetPos(obj, &Players[slot].start_pos, Players[slot].start_roomnum, &Players[slot].start_orient, false); |
| 4655 | } |
| 4656 | |
| 4657 | // If you are going to create submenus you MUST use this function. along with: |
| 4658 | // void SetState(int state); |
| 4659 | // bool SetStateItemList(int count, ... ); for MIT_STATE items |
| 4660 | MenuItem *DMFCBase::CreateMenuItem(const char *title, char type, uint8_t flags, void (*fp)(int), ...) { |
| 4661 | MenuItem *p; |
| 4662 | |
| 4663 | if (type != MIT_CUSTOM && type != MIT_STATE) { |
| 4664 | p = new MenuItem(title, type, flags, fp); |
| 4665 | return p; |
| 4666 | } else { |
| 4667 | if (type == MIT_CUSTOM) { |
| 4668 | tCustomMenu cm; |
| 4669 | |
| 4670 | va_list marker; |
| 4671 | va_start(marker, fp); |
| 4672 | memcpy(&cm, va_arg(marker, tCustomMenu *), sizeof(tCustomMenu)); |
| 4673 | va_end(marker); |
| 4674 | |
| 4675 | p = new MenuItem(title, type, flags, fp, &cm); |
| 4676 | return p; |
| 4677 | } else { |
| 4678 | p = new MenuItem(title, type, flags, fp, 0, 0); // set initially to 0 state items |
| 4679 | return p; |
| 4680 | } |
| 4681 | } |
| 4682 | |
| 4683 | return NULL; |
| 4684 | } |
| 4685 | |
| 4686 | void ParseHostsFile(char *filename, tHostsNode **root) { |
| 4687 | CFILE *file; |
| 4688 | DLLOpenCFILE(&file, filename, "rt"); |
| 4689 | |
| 4690 | tHostsNode *curr = *root; |
| 4691 | |
| 4692 | if (!file) |
| 4693 | return; |
| 4694 | |
| 4695 | char buffer[256]; |
| 4696 | char save_buffer[256]; |
| 4697 | |
| 4698 | char s_ip[16], s_mask[16]; |
| 4699 | uint32_t ip_address; |
| 4700 | uint32_t mask; |
| 4701 | char *ptr; |
| 4702 | |
| 4703 | while (!DLLcfeof(file)) { |
| 4704 | DLLcf_ReadString(buffer, 256, file); |
| 4705 | |
| 4706 | // handle the buffer of data |
| 4707 | ptr = buffer; |
| 4708 | |
| 4709 | // parse white space |
| 4710 | while (*ptr && (*ptr == ' ' || *ptr == '\t')) |
| 4711 | ptr++; |
| 4712 | strcpy(save_buffer, ptr); |
| 4713 | |
| 4714 | if (*ptr) { |
| 4715 | // attempt to parse the dotted ip address (only 0-9,'.' and '*' allowed) |
| 4716 | char *start = ptr; |
| 4717 | |
| 4718 | // check to make sure its in a valid form |
| 4719 | |
| 4720 | int dot_count = 0; |
| 4721 | while (*ptr) { |
| 4722 | if (*ptr == '.') |
| 4723 | dot_count++; |
| 4724 | if ((*ptr < '0' || *ptr > '9') && *ptr != '*' && *ptr != '.') |
| 4725 | goto error_parse; // invalid character |
| 4726 | ptr++; |
| 4727 | } |
| 4728 | if (dot_count != 3) |
| 4729 | goto error_parse; // not enough dots |
| 4730 | ptr = start; |
| 4731 | |
| 4732 | // check the string length, no matter what it shouldn't be more than 15 |
| 4733 | if (strlen(ptr) > 15) |
| 4734 | goto error_parse; |
| 4735 | |
| 4736 | // break up the string into seperate strings |
| 4737 | while (*ptr) { |
| 4738 | if (*ptr == '.') |
| 4739 | *ptr = '\0'; |
| 4740 | ptr++; |
| 4741 | } |
| 4742 | ptr = start; |
| 4743 | |
| 4744 | // check to make sure the string length of each string isn't more than 3 |
| 4745 | int length, count; |
| 4746 | |
| 4747 | for (count = 0; count < 4; count++) { |
| 4748 | length = strlen(ptr); |
| 4749 | if (length > 3 || length == 0) |
| 4750 | goto error_parse; |
| 4751 | |
| 4752 | if (length != 1) { |
| 4753 | // make sure it's a pure number |
| 4754 | char *save = ptr; |
| 4755 | while (*ptr) { |
| 4756 | if (!isdigit(*ptr)) |
| 4757 | goto error_parse; |
| 4758 | ptr++; |
| 4759 | } |
| 4760 | ptr = save; |
| 4761 | int value = atoi(ptr); |
| 4762 | if (value < 0 || value > 255) |
| 4763 | goto error_parse; |
| 4764 | } |
| 4765 | |
| 4766 | ptr += length + 1; |
| 4767 | } |
| 4768 | ptr = start; |
| 4769 | |
| 4770 | // Its a valid IP address mask! yeah...*whew* that was fun |
| 4771 | |
| 4772 | int value; |
| 4773 | char temp_str[16]; |
| 4774 | s_ip[0] = s_mask[0] = '\0'; |
| 4775 | |
| 4776 | for (count = 0; count < 4; count++) { |
| 4777 | length = strlen(ptr); |
| 4778 | |
| 4779 | // Mask |
| 4780 | if (*ptr == '*') { |
| 4781 | value = 0; |
| 4782 | } else { |
| 4783 | value = 255; |
| 4784 | } |
| 4785 | snprintf(temp_str, sizeof(temp_str), "%d", value); |
| 4786 | strcat(s_mask, temp_str); |
| 4787 | if (count != 3) |
| 4788 | strcat(s_mask, "."); |
| 4789 | |
| 4790 | // IP Address |
| 4791 | if (*ptr == '*') { |
| 4792 | value = 0; |
| 4793 | } else { |
| 4794 | value = atoi(ptr); |
| 4795 | } |
| 4796 | snprintf(temp_str, sizeof(temp_str), "%d", value); |
| 4797 | strcat(s_ip, temp_str); |
| 4798 | if (count != 3) |
| 4799 | strcat(s_ip, "."); |
| 4800 | |
| 4801 | ptr += length + 1; |
| 4802 | } |
| 4803 | |
| 4804 | // we now have a valid mask (s_mask) and a valid ip (s_ip) |
| 4805 | mprintf(0, "IP: %s Mask: %s\n", s_ip, s_mask); |
| 4806 | ip_address = DLLnw_GetHostAddressFromNumbers(s_ip); |
| 4807 | mask = DLLnw_GetHostAddressFromNumbers(s_mask); |
| 4808 | |
| 4809 | // add the node |
| 4810 | if (!curr) { |
| 4811 | curr = *root = (tHostsNode *)malloc(sizeof(tHostsNode)); |
| 4812 | } else { |
| 4813 | curr->next = (tHostsNode *)malloc(sizeof(tHostsNode)); |
| 4814 | curr = curr->next; |
| 4815 | } |
| 4816 | if (curr) { |
| 4817 | curr->next = NULL; |
| 4818 | curr->ip = ip_address; |
| 4819 | curr->mask = mask; |
| 4820 | } |
| 4821 | |
| 4822 | goto noerror_parse; |
| 4823 | } |
| 4824 | |
| 4825 | error_parse: |
| 4826 | mprintf(0, "Error parsing IP Address Mask: %s\n", save_buffer); |
| 4827 | |
| 4828 | noerror_parse:; |
| 4829 | } |
| 4830 | |
| 4831 | DLLcfclose(file); |
| 4832 | } |
| 4833 | |
| 4834 | // DMFCBase::ReadInHostsAllowDeny |
| 4835 | // |
| 4836 | // Reads in the hosts.allow and hosts.deny files (if available) |
| 4837 | void DMFCBase::ReadInHostsAllowDeny(void) { |
| 4838 | char allow_fn[_MAX_PATH], deny_fn[_MAX_PATH]; |
| 4839 | bool allow_exist, deny_exist; |
| 4840 | |
| 4841 | // build the path info here |
| 4842 | DLLddio_MakePath(allow_fn, LocalD3Dir, "netgames", "hosts.allow", NULL); |
| 4843 | DLLddio_MakePath(deny_fn, LocalD3Dir, "netgames", "hosts.deny", NULL); |
| 4844 | |
| 4845 | allow_exist = (bool)(DLLcfexist(allow_fn) != 0); |
| 4846 | deny_exist = (bool)(DLLcfexist(deny_fn) != 0); |
| 4847 | |
| 4848 | m_DenyList = NULL; |
| 4849 | m_AllowList = NULL; |
| 4850 | |
| 4851 | // parse away |
| 4852 | if (deny_exist) { |
| 4853 | mprintf(0, "Parsing hosts.deny\n"); |
| 4854 | ParseHostsFile(deny_fn, &m_DenyList); |
| 4855 | } |
| 4856 | if (allow_exist) { |
| 4857 | mprintf(0, "Parsing hosts.allow\n"); |
| 4858 | ParseHostsFile(allow_fn, &m_AllowList); |
| 4859 | } |
| 4860 | } |
| 4861 | |
| 4862 | // DMFCBase::FreeHostsLists |
| 4863 | // |
| 4864 | // Frees all the memory allocated for the host allow/deny lists |
| 4865 | void DMFCBase::FreeHostsLists(void) { |
| 4866 | tHostsNode *curr = NULL, *next; |
| 4867 | |
| 4868 | curr = m_DenyList; |
| 4869 | while (curr) { |
| 4870 | next = curr->next; |
| 4871 | free(curr); |
| 4872 | curr = next; |
| 4873 | } |
| 4874 | |
| 4875 | curr = m_AllowList; |
| 4876 | while (curr) { |
| 4877 | next = curr->next; |
| 4878 | free(curr); |
| 4879 | curr = next; |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | // DMFCBase::RehashAllowDeny |
| 4884 | // |
| 4885 | // Flushes and reloads the hosts.allow/.deny lists |
| 4886 | void DMFCBase::RehashAllowDeny(void) { |
| 4887 | FreeHostsLists(); |
| 4888 | ReadInHostsAllowDeny(); |
| 4889 | } |
| 4890 | |
| 4891 | // DMFCBase::IsPlayerAlive |
| 4892 | // |
| 4893 | // Returns true is the given pnum is a player, flying around the level (not dying, dead or observing) |
| 4894 | bool DMFCBase::IsPlayerAlive(int pnum) { |
| 4895 | if (!CheckPlayerNum(pnum)) |
| 4896 | return false; |
| 4897 | |
| 4898 | if (Objects[Players[pnum].objnum].type != OBJ_PLAYER) |
| 4899 | return false; |
| 4900 | |
| 4901 | if (Players[pnum].flags & (PLAYER_FLAGS_DYING | PLAYER_FLAGS_DEAD)) |
| 4902 | return false; |
| 4903 | return true; |
| 4904 | } |
| 4905 | |
| 4906 | // DMFCBase::ParseStartupScript |
| 4907 | // |
| 4908 | // |
| 4909 | // Loads up the startup script and sets variables accordingly |
| 4910 | void DMFCBase::ParseStartupScript(void) { |
| 4911 | CFILE *file; |
| 4912 | char path[_MAX_PATH]; |
| 4913 | char buffer[256]; |
| 4914 | int size; |
| 4915 | bool ok_to_read; |
| 4916 | |
| 4917 | int autoexec_arg = -1; |
| 4918 | |
| 4919 | if ((autoexec_arg = DLLFindArg("-autoexec")) != 0) { |
| 4920 | // a specific autoexec.dmfc file was specified, use that |
| 4921 | strcpy(path, GetGameArg(autoexec_arg + 1)); |
| 4922 | mprintf(0, "Override AUTOEXEC.DMFC to %s\n", path); |
| 4923 | } else { |
| 4924 | // use the default autoexec.dmfc |
| 4925 | DLLddio_MakePath(path, LocalD3Dir, "netgames", "autoexec.dmfc", NULL); |
| 4926 | } |
| 4927 | |
| 4928 | DLLOpenCFILE(&file, path, "rt"); |
| 4929 | if (!file) |
| 4930 | return; |
| 4931 | |
| 4932 | while (!DLLcfeof(file)) { |
| 4933 | ok_to_read = true; |
| 4934 | |
| 4935 | size = DLLcf_ReadString(&buffer[1], 254, file); |
| 4936 | buffer[255] = '\0'; |
| 4937 | |
| 4938 | if (size >= 254) { |
| 4939 | // invalid string, too long..trash the rest of the line |
| 4940 | ok_to_read = false; |
| 4941 | while (size >= 254) { |
| 4942 | size = DLLcf_ReadString(buffer, 254, file); |
| 4943 | } |
| 4944 | } |
| 4945 | |
| 4946 | if (!ok_to_read) { |
| 4947 | mprintf(0, "AUTOEXEC.DMFC: Line too long\n"); |
| 4948 | } else { |
| 4949 | if (buffer[1] == '$') { |
| 4950 | InputCommandHandle(&buffer[1]); |
| 4951 | } else { |
| 4952 | buffer[0] = '$'; // insert starting $ sign for input command |
| 4953 | InputCommandHandle(buffer); |
| 4954 | } |
| 4955 | } |
| 4956 | } |
| 4957 | |
| 4958 | DLLcfclose(file); |
| 4959 | } |
| 4960 | |
| 4961 | dllinfo *DMFCBase::GetDLLInfoCallData(void) { return Data; } |
| 4962 | |
| 4963 | int DMFCBase::GetHighestRoomIndex(void) { return *Highest_room_index; } |
| 4964 | |
| 4965 | int DMFCBase::GetGameWindowW(void) { return *Game_window_w; } |
| 4966 | |
| 4967 | int DMFCBase::GetGameWindowH(void) { return *Game_window_h; } |
| 4968 | |
| 4969 | int DMFCBase::GetGameWindowX(void) { return *Game_window_x; } |
| 4970 | |
| 4971 | int DMFCBase::GetGameWindowY(void) { return *Game_window_y; } |
| 4972 | |
| 4973 | int *DMFCBase::GetGameFontTranslateArray(void) { return Game_fonts; } |
| 4974 | |
| 4975 | int DMFCBase::GetObserverModeBitmap(void) { return hBitmapObserver; } |
| 4976 | |
| 4977 | float DMFCBase::GetFrametime(void) { return *Frametime; } |
| 4978 | |
| 4979 | float DMFCBase::GetGametime(void) { return *Gametime; } |
| 4980 | |
| 4981 | float DMFCBase::GetRealGametime(bool *ispaused) { |
| 4982 | if (ispaused) { |
| 4983 | *ispaused = (m_iProtectedFlags & DMFC_PRF_PAUSETIME) ? true : false; |
| 4984 | } |
| 4985 | |
| 4986 | return RealGametime; |
| 4987 | } |
| 4988 | |
| 4989 | float *DMFCBase::GetShieldDeltaArray(void) { return ShieldDelta; } |
| 4990 | |
| 4991 | float DMFCBase::GetHudAspectX(void) { return *Hud_aspect_x; } |
| 4992 | |
| 4993 | float DMFCBase::GetHudAspectY(void) { return *Hud_aspect_y; } |
| 4994 | |
| 4995 | const char *DMFCBase::GetLocalD3Dir(void) { return LocalD3Dir; } |
| 4996 | |
| 4997 | const tMission *DMFCBase::GetCurrentMission(void) { return Current_mission; } |
| 4998 | |
| 4999 | room *DMFCBase::GetRooms(void) { return Rooms; } |
| 5000 | |
| 5001 | object *DMFCBase::GetObjects(void) { return Objects; } |
| 5002 | |
| 5003 | terrain_segment *DMFCBase::GetTerrainSegs(void) { return Terrain_seg; } |
| 5004 | |
| 5005 | netgame_info *DMFCBase::GetNetgameInfo(void) { return Netgame; } |
| 5006 | |
| 5007 | player *DMFCBase::GetPlayers(void) { return Players; } |
| 5008 | |
| 5009 | netplayer *DMFCBase::GetNetPlayers(void) { return NetPlayers; } |
| 5010 | |
| 5011 | ship *DMFCBase::GetShips(void) { return Ships; } |
| 5012 | |
| 5013 | weapon *DMFCBase::GetWeapons(void) { return Weapons; } |
| 5014 | |
| 5015 | texture *DMFCBase::GetGameTextures(void) { return GameTextures; } |
| 5016 | |
| 5017 | vclip *DMFCBase::GetGameVClips(void) { return GameVClips; } |
| 5018 | |
| 5019 | poly_model *DMFCBase::GetGamePolyModels(void) { return Poly_models; } |
| 5020 | |
| 5021 | ddgr_color *DMFCBase::GetPlayerColors(void) { return Player_colors; } |
| 5022 | |
| 5023 | game_controls DMFCBase::GetLastGameControls(void) { return Last_game_controls; } |
| 5024 | |
| 5025 | int *DMFCBase::GetPilotPicBitmapHandles(void) { return PilotPicBmpHandles; } |
| 5026 | |
| 5027 | void DMFCBase::GetViewerObjectPtr(object **v_obj) { *v_obj = *Viewer_object; } |
| 5028 | |
| 5029 | void DMFCBase::SetViewerObjectPtr(object *v_obj) { *Viewer_object = v_obj; } |
| 5030 | |
| 5031 | float DMFCBase::GetRenderZoom(void) { return *Render_zoom; } |
| 5032 | |
| 5033 | IMenuItem *DMFCBase::GetOnScreenMenu(void) { return &Menu; } |
| 5034 | |
| 5035 | tOSIRISModuleInit *DMFCBase::GetOsirisModuleData(void) { return API.osiris_functions; } |
| 5036 | |
| 5037 | vis_effect *DMFCBase::GetVisEffectArray(int **Highviseptr) { |
| 5038 | if (Highviseptr) |
| 5039 | *Highviseptr = Highest_vis_effect_index; |
| 5040 | |
| 5041 | return VisEffects; |
| 5042 | } |
| 5043 | |
| 5044 | char *DMFCBase::GetGameArg(int arg) { |
| 5045 | static char EMPTY_ARG[1] = ""; |
| 5046 | |
| 5047 | ASSERT(arg >= 0 && arg < MAX_ARGS); |
| 5048 | if (arg < 0 || arg >= MAX_ARGS) |
| 5049 | return (char *)EMPTY_ARG; |
| 5050 | |
| 5051 | char *arguments = (char *)GameArgs; |
| 5052 | |
| 5053 | int position = arg * MAX_CHARS_PER_ARG; |
| 5054 | |
| 5055 | return &arguments[position]; |
| 5056 | } |
| 5057 | |
| 5058 | // DMFCBase::EnableLossGuage |
| 5059 | // |
| 5060 | // Turns on/off the Loss guage on the screen |
| 5061 | void DMFCBase::EnableLossGuage(bool enable) { |
| 5062 | bool peertopeer = (bool)((Netgame->flags & NF_PEER_PEER) != 0); |
| 5063 | |
| 5064 | if ((GetLocalRole() == LR_SERVER) || peertopeer) { |
| 5065 | return; |
| 5066 | } |
| 5067 | |
| 5068 | LossGuageEnabled = enable; |
| 5069 | } |
| 5070 | |
| 5071 | ddgr_color GetTriLinColor(float val, float low, float med, float hi, ddgr_color lowc, ddgr_color medc, ddgr_color hic) { |
| 5072 | ddgr_color low_col, hi_col; |
| 5073 | float perc; |
| 5074 | |
| 5075 | if (val <= low) { |
| 5076 | // we're pure lowc |
| 5077 | perc = 1.0f; |
| 5078 | low_col = hi_col = lowc; |
| 5079 | } else if (val <= med) { |
| 5080 | // we're between lowc and medc |
| 5081 | low_col = lowc; |
| 5082 | hi_col = medc; |
| 5083 | |
| 5084 | perc = (val - low) / (med - low); |
| 5085 | } else if (val <= hi) { |
| 5086 | // we're between medc and hic |
| 5087 | low_col = medc; |
| 5088 | hi_col = hic; |
| 5089 | perc = (val - med) / (hi - med); |
| 5090 | } else { |
| 5091 | // we're pure hic |
| 5092 | perc = 1.0f; |
| 5093 | low_col = hi_col = hic; |
| 5094 | } |
| 5095 | |
| 5096 | if (perc < 0.0f) |
| 5097 | perc = 0.0f; |
| 5098 | if (perc > 1.0f) |
| 5099 | perc = 1.0f; |
| 5100 | |
| 5101 | ddgr_color color_to_use; |
| 5102 | int r, g, b; |
| 5103 | float amount_low, amount_hi; |
| 5104 | |
| 5105 | amount_low = 1.0 - perc; |
| 5106 | amount_hi = perc; |
| 5107 | |
| 5108 | r = GR_COLOR_RED(low_col) * amount_low + GR_COLOR_RED(hi_col) * amount_hi; |
| 5109 | g = GR_COLOR_GREEN(low_col) * amount_low + GR_COLOR_GREEN(hi_col) * amount_hi; |
| 5110 | b = GR_COLOR_BLUE(low_col) * amount_low + GR_COLOR_BLUE(hi_col) * amount_hi; |
| 5111 | |
| 5112 | color_to_use = GR_RGB(r, g, b); |
| 5113 | |
| 5114 | return color_to_use; |
| 5115 | } |
| 5116 | |
| 5117 | // DMFCBase::LossGuageFrame |
| 5118 | // |
| 5119 | // Processes the Loss guage for the frame |
| 5120 | void DMFCBase::LossGuageFrame(void) { |
| 5121 | if (!LossGuageEnabled) |
| 5122 | return; |
| 5123 | |
| 5124 | if (GetLocalRole() == LR_SERVER) |
| 5125 | return; |
| 5126 | |
| 5127 | // Don't show if peer-to-peer |
| 5128 | if (Netgame->flags & NF_PEER_PEER) |
| 5129 | return; |
| 5130 | |
| 5131 | #define LOW_COLOR GR_RGB(20, 255, 20) |
| 5132 | #define MED_COLOR GR_RGB(255, 255, 40) |
| 5133 | #define HI_COLOR GR_RGB(255, 20, 20) |
| 5134 | #define LOW_LOSS 1.0f |
| 5135 | #define MED_LOSS 5.0f |
| 5136 | #define HI_LOSS 10.0f |
| 5137 | |
| 5138 | float packetloss = NetPlayers[GetPlayerNum()].percent_loss; |
| 5139 | |
| 5140 | ddgr_color loss_color = GetTriLinColor(packetloss, LOW_LOSS, MED_LOSS, HI_LOSS, LOW_COLOR, MED_COLOR, HI_COLOR); |
| 5141 | ddgr_color ping_color = |
| 5142 | GetTriLinColor(NetPlayers[GetPlayerNum()].ping_time * 1000.0f, 0, 200.0f, 400.0f, LOW_COLOR, MED_COLOR, HI_COLOR); |
| 5143 | |
| 5144 | DLLgrtext_SetFont(Game_fonts[HUD_FONT_INDEX]); |
| 5145 | |
| 5146 | int max_x = 0; |
| 5147 | int y = 2; |
| 5148 | |
| 5149 | DLLRenderHUDText(loss_color, 255, 2, 0, y, DTXT_NETWORK_LOSS); |
| 5150 | max_x = DLLRenderHUDGetTextLineWidth(DTXT_NETWORK_LOSS); |
| 5151 | |
| 5152 | DLLRenderHUDText(ping_color, 255, 2, 0, y + 10, DTXT_NETWORK_PING); |
| 5153 | max_x = std::max(max_x, DLLRenderHUDGetTextLineWidth(DTXT_NETWORK_PING)); |
| 5154 | |
| 5155 | max_x += 10; |
| 5156 | DLLRenderHUDText(loss_color, 255, 0, 2 + max_x, y, "%.2f%%", packetloss); |
| 5157 | DLLRenderHUDText(ping_color, 255, 0, 2 + max_x, y + 10, "%dms", |
| 5158 | (int)(NetPlayers[GetPlayerNum()].ping_time * 1000.0f)); |
| 5159 | } |
| 5160 | |
| 5161 | level_info *DMFCBase::GetLevelInfo(void) { return Level_info; } |
| 5162 | |
| 5163 | // 1 - (num_levels) |
| 5164 | void DMFCBase::WarpToLevel(int lev) { |
| 5165 | if (GetLocalRole() != LR_SERVER) |
| 5166 | return; |
| 5167 | |
| 5168 | if (lev < 1 || lev > Current_mission->num_levels) |
| 5169 | return; |
| 5170 | |
| 5171 | *Multi_next_level = lev; |
| 5172 | EndLevel(); |
| 5173 | } |
| 5174 | |
| 5175 | void DMFCBase::SetPlayerTauntIndicator(int pnum) { |
| 5176 | if (!CheckPlayerNum(pnum)) |
| 5177 | return; |
| 5178 | |
| 5179 | DisplayTauntIndicator = true; |
| 5180 | TauntIndicatorStartTime = *Gametime; |
| 5181 | TauntIndicatorPlayerNum = pnum; |
| 5182 | } |
| 5183 | |
| 5184 | void DMFCBase::DisplayTauntIndicatorFrame(void) { |
| 5185 | if (!DisplayTauntIndicator) |
| 5186 | return; |
| 5187 | |
| 5188 | if (!CheckPlayerNum(TauntIndicatorPlayerNum)) { |
| 5189 | DisplayTauntIndicator = false; |
| 5190 | return; |
| 5191 | } |
| 5192 | |
| 5193 | float alpha, perc; |
| 5194 | int igt = floor((*Gametime)); |
| 5195 | float igth = (*Gametime) - igt; |
| 5196 | if (igth > 0.5f) { |
| 5197 | igth -= 0.5f; |
| 5198 | } |
| 5199 | |
| 5200 | if (igth > 0.25f) { |
| 5201 | perc = 1.0f - ((igth - 0.25) / 0.25f); |
| 5202 | } else { |
| 5203 | perc = (igth / 0.25f); |
| 5204 | } |
| 5205 | |
| 5206 | float base_alpha = 0.40f; |
| 5207 | float range = 1.0f - base_alpha; |
| 5208 | |
| 5209 | alpha = base_alpha + (perc * range); |
| 5210 | if (alpha < base_alpha) |
| 5211 | alpha = base_alpha; |
| 5212 | if (alpha > 1.0f) |
| 5213 | alpha = 1.0f; |
| 5214 | |
| 5215 | int bmp = TauntIndicatorBMP; |
| 5216 | if (PilotPicBmpHandles[TauntIndicatorPlayerNum] > BAD_BITMAP_HANDLE) { |
| 5217 | bmp = PilotPicBmpHandles[TauntIndicatorPlayerNum]; |
| 5218 | } |
| 5219 | |
| 5220 | if (bmp <= BAD_BITMAP_HANDLE) { |
| 5221 | DisplayTauntIndicator = false; |
| 5222 | return; |
| 5223 | } |
| 5224 | |
| 5225 | int bmh = 32; |
| 5226 | int bmw = 32; |
| 5227 | int x, y; |
| 5228 | |
| 5229 | x = 10; |
| 5230 | y = 200; |
| 5231 | |
| 5232 | DLLrend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 5233 | DLLrend_SetAlphaValue(alpha * 255); |
| 5234 | DLLrend_SetLighting(LS_NONE); |
| 5235 | DLLrend_SetColorModel(CM_MONO); |
| 5236 | DLLrend_SetOverlayType(OT_NONE); |
| 5237 | DLLrend_SetFiltering(0); |
| 5238 | DLLrend_SetWrapType(WT_CLAMP); |
| 5239 | DLLrend_SetZBufferState(0); |
| 5240 | DLLrend_SetTextureType(TT_LINEAR); |
| 5241 | |
| 5242 | DLLrend_DrawScaledBitmap(x, y, x + bmw, y + bmh, bmp, 0, 0, 1, 1, 1, -1, NULL); |
| 5243 | DLLrend_SetFiltering(1); |
| 5244 | DLLrend_SetZBufferState(1); |
| 5245 | |
| 5246 | int font_height; |
| 5247 | |
| 5248 | DLLgrtext_SetFont(Game_fonts[HUD_FONT_INDEX]); |
| 5249 | font_height = DLLgrfont_GetHeight(Game_fonts[HUD_FONT_INDEX]); |
| 5250 | |
| 5251 | x = 15 + bmw; |
| 5252 | y = (y + (bmh / 2)) - (font_height / 2); |
| 5253 | |
| 5254 | DLLgrtext_SetColor(GR_GREEN); |
| 5255 | DLLgrtext_SetAlpha(alpha * 255.0f); |
| 5256 | DLLgrtext_Printf(x, y, Players[TauntIndicatorPlayerNum].callsign); |
| 5257 | |
| 5258 | if ((*Gametime - TauntIndicatorStartTime) > 3.0f) |
| 5259 | DisplayTauntIndicator = false; |
| 5260 | } |
| 5261 | |
| 5262 | // DMFCBase::SetMaxPlayerHardLimit |
| 5263 | // |
| 5264 | // Sets a hard limit to the max number of players allowed in the game |
| 5265 | // changing the number of players can never go above this...defaults |
| 5266 | // to DLLMAX_PLAYERS |
| 5267 | void DMFCBase::SetMaxPlayerHardLimit(int max) { |
| 5268 | if (GetLocalRole() != LR_SERVER) |
| 5269 | return; |
| 5270 | if (max > DLLMAX_PLAYERS || max < 1) |
| 5271 | return; |
| 5272 | |
| 5273 | Hard_max_players = max; |
| 5274 | if (Netgame->max_players > Hard_max_players) { |
| 5275 | Netgame->max_players = max; |
| 5276 | DLLAddHUDMessage(DTXT_MAXPLAYERSSETMSG, max); |
| 5277 | SendNetGameInfoSync(); |
| 5278 | } |
| 5279 | } |
| 5280 | |
| 5281 | // DMFCBase::MarkPlayersInGame |
| 5282 | // |
| 5283 | // Goes through all the player records and marks those that are in the game |
| 5284 | // This is needed because at level end, all clients disconnect, so we lose |
| 5285 | // that information. |
| 5286 | void DMFCBase::MarkPlayersInGame(void) { |
| 5287 | player_record *pr; |
| 5288 | for (int i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 5289 | pr = GetPlayerRecord(i); |
| 5290 | |
| 5291 | if (pr && pr->state == STATE_INGAME) { |
| 5292 | players_in_game[i] = pr->pnum; |
| 5293 | } else { |
| 5294 | players_in_game[i] = -1; |
| 5295 | } |
| 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | // DMFCBase::ResetPlayersInGame |
| 5300 | // |
| 5301 | // Resets the Players-in-game list |
| 5302 | void DMFCBase::ResetPlayersInGame(void) { |
| 5303 | for (int i = 0; i < MAX_PLAYER_RECORDS; i++) { |
| 5304 | players_in_game[i] = -1; |
| 5305 | } |
| 5306 | } |
| 5307 | |
| 5308 | // DMFCBase::WasPlayerInGameAtLevelEnd |
| 5309 | // |
| 5310 | // Given a player record it returns true/false whether |
| 5311 | // the player was in the game at the time the level ended. |
| 5312 | int DMFCBase::WasPlayerInGameAtLevelEnd(int prec) { |
| 5313 | if (prec < 0 || prec >= MAX_PLAYER_RECORDS) |
| 5314 | return -1; |
| 5315 | |
| 5316 | return players_in_game[prec]; |
| 5317 | } |
| 5318 | |
| 5319 | // DMFCBase::GetConnectingPlayerTeam |
| 5320 | // |
| 5321 | // Returns the team of a player just connecting, this is to be set by the |
| 5322 | // game and is DMFC assumes that all players have the correct team on join |
| 5323 | int DMFCBase::GetConnectingPlayerTeam(int slot) { |
| 5324 | if (GetLocalRole() != LR_SERVER) |
| 5325 | return -2; |
| 5326 | |
| 5327 | int prec_num; |
| 5328 | if (IsMasterTrackerGame()) |
| 5329 | prec_num = PRec_FindPlayer(Players[slot].callsign, NULL, Players[slot].tracker_id); |
| 5330 | else |
| 5331 | prec_num = PRec_FindPlayer(Players[slot].callsign, &NetPlayers[slot].addr, NULL); |
| 5332 | |
| 5333 | int team = -2; |
| 5334 | |
| 5335 | if (prec_num != -1) { |
| 5336 | // we have a reconnecting player |
| 5337 | |
| 5338 | // we need to reconnect the player to the player records before we get the team |
| 5339 | if (!PRec_ReconnectPlayerToSlot(slot, prec_num, Players, NetPlayers)) { |
| 5340 | mprintf(0, "Unable to reassign reconnecting player (%s) to Player Record slot #%d\n", |
| 5341 | Players[slot].callsign, |
| 5342 | prec_num); |
| 5343 | Int3(); |
| 5344 | } else { |
| 5345 | team = PRec_GetPlayerTeam(slot); |
| 5346 | |
| 5347 | // disconnect the player again since he isn't in the game just yet |
| 5348 | PRec_DisconnectPlayer(slot); |
| 5349 | } |
| 5350 | } else { |
| 5351 | // we have a new player |
| 5352 | |
| 5353 | if (slot == 0 && IAmDedicatedServer()) { |
| 5354 | team = -1; |
| 5355 | } else { |
| 5356 | // get team assignment |
| 5357 | if (m_iProtectedFlags & DMFC_PRF_AUTOTEAMSELECT) { |
| 5358 | team = GetTeamForNewPlayer(slot, m_iNumTeams); |
| 5359 | } else { |
| 5360 | team = RED_TEAM; |
| 5361 | } |
| 5362 | } |
| 5363 | } |
| 5364 | |
| 5365 | mprintf(0, "CONNECTING PLAYER (%s): Team assigned to %d\n", Players[slot].callsign, team); |
| 5366 | |
| 5367 | return team; |
| 5368 | } |
| 5369 | |
| 5370 | // DMFCBase::SetDedicatedWait |
| 5371 | // |
| 5372 | // Sets the level wait time for the dedicated server. A dedicated server will make all |
| 5373 | // clients wait until this time (in seconds) is up each level. |
| 5374 | void DMFCBase::SetDedicatedWait(float time_secs) { |
| 5375 | if (time_secs < 0) |
| 5376 | time_secs = 0; |
| 5377 | |
| 5378 | DedicatedLevelWait = time_secs; |
| 5379 | } |
| 5380 | |
| 5381 | // DMFCBase::EnableTimelimitCountdown |
| 5382 | // |
| 5383 | // Enables/Disables the timelimit countdown (if there is a level time limit) |
| 5384 | // Optionally you can specify what time to start the count down. (default 10) |
| 5385 | void DMFCBase::EnableTimelimitCountdown(bool enable, int seconds) { |
| 5386 | m_bDisplayTimelimitCountdown = enable; |
| 5387 | |
| 5388 | if (enable && seconds > 0) { |
| 5389 | m_iTimeLimitCountdown = seconds; |
| 5390 | } |
| 5391 | } |
| 5392 | |
| 5393 | // DMFCBase::DisplayTimelimitCountdown |
| 5394 | // |
| 5395 | // Displays (if needed) the time limit countdown |
| 5396 | void DMFCBase::DisplayTimelimitCountdown(void) { |
| 5397 | if (!m_bDisplayTimelimitCountdown) |
| 5398 | return; |
| 5399 | |
| 5400 | if (!(Netgame->flags & NF_TIMER)) |
| 5401 | return; |
| 5402 | |
| 5403 | float time_left = (Netgame->timelimit * 60.0f) - RealGametime; |
| 5404 | |
| 5405 | if (time_left > m_iTimeLimitCountdown || time_left < 0) |
| 5406 | return; |
| 5407 | |
| 5408 | // display a countdown! |
| 5409 | DLLgrtext_SetFont(Game_fonts[HUD_FONT_INDEX]); |
| 5410 | DLLgrtext_SetColor(GR_WHITE); |
| 5411 | DLLgrtext_SetAlpha(255); |
| 5412 | |
| 5413 | char buffer[256]; |
| 5414 | snprintf(buffer, sizeof(buffer), "Time Left: T - %d", (int)time_left); |
| 5415 | |
| 5416 | int font_height = DLLgrfont_GetHeight(Game_fonts[HUD_FONT_INDEX]); |
| 5417 | DLLgrtext_CenteredPrintf(0, font_height * 10, buffer); |
| 5418 | } |
| 5419 | |
| 5420 | // DMFCBase::TranslateTextMacro |
| 5421 | // |
| 5422 | // Given a macro with tokens, this function will replace the tokens |
| 5423 | // and create a new string for display. |
| 5424 | // All tokens begin with $$ (i.e. $$TEAMBASE) |
| 5425 | void DMFCBase::TranslateTextMacro(const char *src, char *destination, int dest_size) { |
| 5426 | ASSERT(destination != NULL); |
| 5427 | ASSERT(src != NULL); |
| 5428 | ASSERT(dest_size >= 0); |
| 5429 | |
| 5430 | if (dest_size <= 0) |
| 5431 | return; |
| 5432 | |
| 5433 | char token[128]; |
| 5434 | char token_string[512]; |
| 5435 | |
| 5436 | char *curr_dest = destination; |
| 5437 | int src_idx = 0; |
| 5438 | bool done = false; |
| 5439 | |
| 5440 | // now we need to go through the src and copy to destination |
| 5441 | // while looking for tokens, and making sure we don't go over our size |
| 5442 | while (dest_size > 1 && !done) { |
| 5443 | switch (src[src_idx]) { |
| 5444 | case '$': { |
| 5445 | // possible token!, check the next character |
| 5446 | if (src[src_idx + 1] == '$') { |
| 5447 | // TOKEN!!! |
| 5448 | src_idx += 2; // move to the beginning of the token |
| 5449 | if (src[src_idx] == ' ' || src[src_idx] == '\0') { |
| 5450 | // ok, maybe it isn't a token |
| 5451 | *curr_dest = src[src_idx - 2]; |
| 5452 | curr_dest++; |
| 5453 | dest_size--; |
| 5454 | *curr_dest = src[src_idx - 1]; |
| 5455 | curr_dest++; |
| 5456 | dest_size--; |
| 5457 | *curr_dest = src[src_idx]; |
| 5458 | if (*curr_dest == '\0') { |
| 5459 | done = true; |
| 5460 | } else { |
| 5461 | src_idx++; |
| 5462 | } |
| 5463 | curr_dest++; |
| 5464 | dest_size--; |
| 5465 | } else { |
| 5466 | // process it, it's gotta be a token |
| 5467 | |
| 5468 | // extract the token out |
| 5469 | char *ptr = token; |
| 5470 | while (src[src_idx] != ' ' && src[src_idx] != '\0') { |
| 5471 | *ptr = src[src_idx]; |
| 5472 | ptr++; |
| 5473 | src_idx++; |
| 5474 | } |
| 5475 | *ptr = '\0'; |
| 5476 | |
| 5477 | // now replace the token... |
| 5478 | *token_string = '\0'; |
| 5479 | mprintf(0, "Looking for token for %s\n", token); |
| 5480 | CallOnGetTokenString(token, token_string, 512); |
| 5481 | |
| 5482 | // make sure we don't go too far |
| 5483 | int len = strlen(token_string); |
| 5484 | if (len > (dest_size - 1)) |
| 5485 | len = dest_size - 1; |
| 5486 | |
| 5487 | ptr = token_string; |
| 5488 | |
| 5489 | while (len > 0) { |
| 5490 | *curr_dest = *ptr; |
| 5491 | curr_dest++; |
| 5492 | dest_size--; |
| 5493 | ptr++; |
| 5494 | len--; |
| 5495 | } |
| 5496 | } |
| 5497 | } else { |
| 5498 | // just copy the character over |
| 5499 | *curr_dest = src[src_idx]; |
| 5500 | src_idx++; |
| 5501 | curr_dest++; |
| 5502 | dest_size--; |
| 5503 | } |
| 5504 | } break; |
| 5505 | case '\0': |
| 5506 | done = true; |
| 5507 | break; |
| 5508 | default: { |
| 5509 | // just copy the character over |
| 5510 | *curr_dest = src[src_idx]; |
| 5511 | src_idx++; |
| 5512 | curr_dest++; |
| 5513 | dest_size--; |
| 5514 | } break; |
| 5515 | } |
| 5516 | } |
| 5517 | |
| 5518 | *curr_dest = '\0'; // NULL terminate |
| 5519 | } |
| 5520 | |
| 5521 | // DMFCBase::SelectNextCameraView |
| 5522 | // |
| 5523 | // This function, given which window (corresponds to left, middle, right), switches the |
| 5524 | // current view of the small camera windows on the screen |
| 5525 | void DMFCBase::SelectNextCameraView(int window) { |
| 5526 | if (window < 0 || window >= NUM_CAMERA_VIEWS) |
| 5527 | return; |
| 5528 | DLLSelectNextCameraView(window); |
| 5529 | } |
| 5530 | |
| 5531 | int DMFCBase::GetCameraViewType(int window) { |
| 5532 | if (window < 0 || window >= NUM_CAMERA_VIEWS) |
| 5533 | return -1; |
| 5534 | return Camera_view_mode[window]; |
| 5535 | } |
| 5536 | |
| 5537 | // Given a generic object (OBJ_POWERUP,OBJ_ROBOT,OBJ_BUILDING or OBJ_CLUTTER) id |
| 5538 | // in the range of 0 to MAX_OBJECT_IDS, this returns a pointer to it's information (see objinfo.h) |
| 5539 | // It returns NULL if an invalid id is given (or it's not used) |
| 5540 | object_info *DMFCBase::GetObjectInfo(int objinfo_id) { |
| 5541 | if (objinfo_id < 0 || objinfo_id >= MAX_OBJECT_IDS) |
| 5542 | return NULL; |
| 5543 | |
| 5544 | if (Object_info[objinfo_id].type == OBJ_NONE) |
| 5545 | return NULL; |
| 5546 | |
| 5547 | return &Object_info[objinfo_id]; |
| 5548 | } |