| 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/pilot.cpp $ |
| 21 |
* $Revision: 175 $ |
| 22 |
* $Date: 3/20/00 12:07p $ |
| 23 |
* $Author: Matt $ |
| 24 |
* |
| 25 |
* Player/Pilot configuration |
| 26 |
* |
| 27 |
* $Log: /DescentIII/main/pilot.cpp $ |
| 28 |
* |
| 29 |
* 175 3/20/00 12:07p Matt |
| 30 |
* Merge of Duane's post-1.3 changes. |
| 31 |
* Changed difficulty level to be a global variable instead of a function |
| 32 |
* call |
| 33 |
* |
| 34 |
* 174 11/30/99 5:08p Jeff |
| 35 |
* don't let the Black Pyro be selected in LInux |
| 36 |
* |
| 37 |
* 173 10/21/99 9:27p Jeff |
| 38 |
* B.A. Macintosh code merge |
| 39 |
* |
| 40 |
* 172 10/19/99 4:55p Jeff |
| 41 |
* only let them select Black Pyro if they own Mercenary |
| 42 |
* |
| 43 |
* 171 10/04/99 9:57a Kevin |
| 44 |
* #ifdef for demo, only pyro is available |
| 45 |
* |
| 46 |
* 170 9/12/99 12:09a Jeff |
| 47 |
* fixed stupid axtoi bug |
| 48 |
* |
| 49 |
* 169 9/03/99 4:37p Jeff |
| 50 |
* fixed bug related to highlighting an oaf if it is supposed to be |
| 51 |
* selected in the pilot config dialog |
| 52 |
* |
| 53 |
* 168 7/23/99 2:36p Jeff |
| 54 |
* put in warning message if imported oaf file is too large |
| 55 |
* |
| 56 |
* 167 7/06/99 11:47p Jeff |
| 57 |
* Added delete buttons for audio taunts and logos |
| 58 |
* |
| 59 |
* 166 5/25/99 3:09a Jeff |
| 60 |
* don't let a player start in secret levels if they beat the game |
| 61 |
* |
| 62 |
* 165 5/24/99 7:24p Samir |
| 63 |
* use correct string length for DoEditDialog now. |
| 64 |
* |
| 65 |
* 164 5/23/99 2:22a Jeff |
| 66 |
* don't update some mission stuff for secret levels. correctly update |
| 67 |
* when finished the level |
| 68 |
* |
| 69 |
* 163 5/12/99 2:24p Jeff |
| 70 |
* Descent3 now has a setable temp directory for all temp files |
| 71 |
* |
| 72 |
* 162 5/12/99 2:02p Samir |
| 73 |
* don't open pilot interface until inputted name of new pilot. |
| 74 |
* |
| 75 |
* 161 5/10/99 10:23p Ardussi |
| 76 |
* changes to compile on Mac |
| 77 |
* |
| 78 |
* 160 5/09/99 6:30a Jeff |
| 79 |
* fixed copy controls bug when there was .pld's but only 1 plt |
| 80 |
* |
| 81 |
* 159 5/05/99 12:43a Jeff |
| 82 |
* selected imported logo, don't stop sounds |
| 83 |
* |
| 84 |
* 158 5/03/99 8:38a Jeff |
| 85 |
* fixed copy controls |
| 86 |
* |
| 87 |
* 157 5/02/99 12:55a Jeff |
| 88 |
* save ship permissions at highest level achieved and use that on restore |
| 89 |
* to a level previously played |
| 90 |
* |
| 91 |
* 156 5/01/99 12:17a Jeff |
| 92 |
* adjusted config due to new artwork |
| 93 |
* |
| 94 |
* 155 4/29/99 5:52p Jeff |
| 95 |
* if displaying 1 pilot pic, don't put index number at the end of name |
| 96 |
* |
| 97 |
* 154 4/29/99 2:19a Samir |
| 98 |
* updated art for options style menu. |
| 99 |
* |
| 100 |
* 153 4/28/99 5:06p Jeff |
| 101 |
* widened copy controls dialog |
| 102 |
* |
| 103 |
* 152 4/27/99 1:56p Jeff |
| 104 |
* audio taunts stuff in pilot menu, added stringtables |
| 105 |
* |
| 106 |
* 151 4/26/99 2:13p Jeff |
| 107 |
* go right into preset select on new pilot |
| 108 |
* |
| 109 |
* 150 4/25/99 4:53p Jeff |
| 110 |
* fixed startframe/endframe bugs in D3D |
| 111 |
* |
| 112 |
* 149 4/25/99 2:32a Jeff |
| 113 |
* fixed bug trying to read pilot files that are too new |
| 114 |
* |
| 115 |
* 148 4/23/99 9:52p Jeff |
| 116 |
* fixed messed up string for ship selection |
| 117 |
* |
| 118 |
* 147 4/21/99 4:54p Jeff |
| 119 |
* display name of pilot being configured |
| 120 |
* |
| 121 |
* 146 4/21/99 12:58p Samir |
| 122 |
* progress bar for ship config. |
| 123 |
* |
| 124 |
* 145 4/21/99 12:43p Samir |
| 125 |
* redid pilot taunt menu for newui. |
| 126 |
* |
| 127 |
* 144 4/20/99 7:28p Jeff |
| 128 |
* added guidebot name |
| 129 |
* |
| 130 |
* 143 4/18/99 7:55p Samir |
| 131 |
* new progress indicator for delays when loading data. |
| 132 |
* |
| 133 |
* 142 4/16/99 6:00p Kevin |
| 134 |
* Bunches of Demo stuff |
| 135 |
* |
| 136 |
* 141 4/16/99 12:05p Matt |
| 137 |
* Changed code to use cfile functions, & took out include of io.h. |
| 138 |
* |
| 139 |
* 140 4/16/99 12:39a Matt |
| 140 |
* Took out Linux ifdef around include of io.h, since it's a system header |
| 141 |
* file and there's no harm in including it in the Windows version. |
| 142 |
* |
| 143 |
* 139 4/14/99 3:57a Jeff |
| 144 |
* fixed case mismatch in #includes |
| 145 |
* |
| 146 |
* 138 4/09/99 7:04p Jason |
| 147 |
* changed some texture defines |
| 148 |
* |
| 149 |
* 137 4/04/99 3:27p Jeff |
| 150 |
* localized pilot.cpp |
| 151 |
* |
| 152 |
* 136 4/03/99 9:26p Jeff |
| 153 |
* changed dialogs that weren't using UID_OK and UID_CANCEL to use and |
| 154 |
* handle them properly |
| 155 |
* |
| 156 |
* 135 4/03/99 2:18a Jeff |
| 157 |
* added profanity filter stuff |
| 158 |
* |
| 159 |
* 134 3/30/99 7:41p Jeff |
| 160 |
* error handling...reset ppic if there isn't a valid one |
| 161 |
* |
| 162 |
* 133 3/30/99 5:30p Jeff |
| 163 |
* fixed bug when canceling out of multiplayer ship config |
| 164 |
* |
| 165 |
* 132 3/24/99 1:41p Jeff |
| 166 |
* some dedicated server fixups...ability to set number of teams |
| 167 |
* |
| 168 |
* 131 3/23/99 4:26p Jeff |
| 169 |
* new pilot choose dialog |
| 170 |
* |
| 171 |
* 130 3/23/99 12:45p Jeff |
| 172 |
* added preset control selection for pilot |
| 173 |
* |
| 174 |
* 129 3/22/99 6:22p Jeff |
| 175 |
* added 2 more audio taunts. a mulitplayer event when someone plays an |
| 176 |
* audio taunt. option to disable audio taunts. |
| 177 |
* |
| 178 |
* 128 3/19/99 9:14p Jeff |
| 179 |
* converted multiplayer ship selection dialog |
| 180 |
* |
| 181 |
* 127 3/18/99 2:33p Jeff |
| 182 |
* fixed bug clearing the Current pilot stuff before we were done using it |
| 183 |
* |
| 184 |
* 126 3/17/99 11:48a Jeff |
| 185 |
* enter selects pilot on dialog display |
| 186 |
* |
| 187 |
* 125 3/15/99 9:24p Gwar |
| 188 |
* |
| 189 |
* 124 3/15/99 4:31p Jeff |
| 190 |
* fixed some memory leaks |
| 191 |
* |
| 192 |
* 123 3/04/99 6:07p Samir |
| 193 |
* fixed bug with entering pilot names for the first time (buffer sent to |
| 194 |
* DoEditDialog was not null terminated.) Also added wait screen. |
| 195 |
* |
| 196 |
* 122 3/04/99 11:40a Jeff |
| 197 |
* better error messages on pilot write error |
| 198 |
* |
| 199 |
* 121 3/03/99 5:09p Samir |
| 200 |
* fixed audio taunt combobox. Passed incorrect flag values. |
| 201 |
* |
| 202 |
* 120 3/01/99 4:39p Samir |
| 203 |
* made AddOption to AddSimpleOption for options without sheets. |
| 204 |
* |
| 205 |
* 119 2/28/99 6:05p Jeff |
| 206 |
* use UID_OK and UID_CANCEL |
| 207 |
* |
| 208 |
* 118 2/28/99 3:17p Jeff |
| 209 |
* multiplayer ship selection only has Pyro-GL |
| 210 |
* |
| 211 |
* 117 2/28/99 3:06a Jeff |
| 212 |
* converted "select pilot pic" dialog |
| 213 |
* |
| 214 |
* 116 2/27/99 4:18p Jeff |
| 215 |
* added support for .pld files (used to copy pilot default controls), |
| 216 |
* audio taunt size import error fixed...removed dead code |
| 217 |
* |
| 218 |
* 115 2/25/99 4:30p Jeff |
| 219 |
* mission data of pilot keeps track of all missions, not just after you |
| 220 |
* beat a level |
| 221 |
* |
| 222 |
* 114 2/23/99 7:34p Jeff |
| 223 |
* use new ui for add dialog |
| 224 |
* |
| 225 |
* 113 2/23/99 1:47a Jeff |
| 226 |
* attempted to convert add new pilot |
| 227 |
* |
| 228 |
* 109 2/19/99 12:14a Jeff |
| 229 |
* start of new ui conversion |
| 230 |
* |
| 231 |
* 108 2/15/99 7:50p Jeff |
| 232 |
* new pilot file class and read/write system checked in...should be more |
| 233 |
* robust than old |
| 234 |
* |
| 235 |
* 107 2/10/99 4:45p Jeff |
| 236 |
* table file parser stuff |
| 237 |
* |
| 238 |
* 106 1/29/99 5:22p Jeff |
| 239 |
* localization |
| 240 |
* |
| 241 |
* 105 1/27/99 5:47p Jeff |
| 242 |
* audio taunts implemented! |
| 243 |
* |
| 244 |
* 104 1/21/99 11:15p Jeff |
| 245 |
* pulled out some structs and defines from header files and moved them |
| 246 |
* into seperate header files so that multiplayer dlls don't require major |
| 247 |
* game headers, just those new headers. Side effect is a shorter build |
| 248 |
* time. Also cleaned up some header file #includes that weren't needed. |
| 249 |
* This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 250 |
* manage.h and multi.h |
| 251 |
* |
| 252 |
* 103 1/16/99 2:55p Jeff |
| 253 |
* mission data doesn't get updated in a multiplayer game |
| 254 |
* |
| 255 |
* 102 1/11/99 4:08p Jason |
| 256 |
* added multiplayer taunt macros |
| 257 |
* |
| 258 |
* 101 12/30/98 6:51p Matt |
| 259 |
* Fixed compile warnings |
| 260 |
* |
| 261 |
* 100 12/17/98 5:59p Samir |
| 262 |
* moved mouse enabled and joy enabled to config menu. |
| 263 |
* |
| 264 |
* 99 12/17/98 12:44p Samir |
| 265 |
* fixed bugs in writing 0 length strings in pilot file! |
| 266 |
* |
| 267 |
* 98 12/16/98 1:57p Samir |
| 268 |
* added finished field to mission data structure. |
| 269 |
* |
| 270 |
* 97 12/15/98 4:28p Jeff |
| 271 |
* added mission data information to the pilot files to save what the |
| 272 |
* highest level they achieved on a mission is. Added level select dialog |
| 273 |
* (not hooked up) and level warp cheat. |
| 274 |
* |
| 275 |
* 96 12/03/98 11:06a Samir |
| 276 |
* added axis sensitivity |
| 277 |
* |
| 278 |
* 95 12/02/98 11:43a Samir |
| 279 |
* added better code to handle changes in controller function list for |
| 280 |
* pilot files (needed to have a constant giving number of controller |
| 281 |
* functions in demo 1.0) |
| 282 |
* |
| 283 |
* 94 12/01/98 5:47p Jeff |
| 284 |
* created pilot picture selection dialog |
| 285 |
* |
| 286 |
* 93 11/30/98 11:56a Jeff |
| 287 |
* fixed bug, allowing unlimited pilots |
| 288 |
* |
| 289 |
* 92 11/23/98 11:25a Jeff |
| 290 |
* fixed import animated bitmap message box bug |
| 291 |
* |
| 292 |
* 91 10/27/98 2:31p Jeff |
| 293 |
* adjusted play button for audio taunts on ship config dialog |
| 294 |
* |
| 295 |
* 90 10/23/98 2:58p Samir |
| 296 |
* set defaults for controller sensitivities. |
| 297 |
* |
| 298 |
* 89 10/22/98 10:55p Jeff |
| 299 |
* return error if reading a pilot file that is newer than we support |
| 300 |
* |
| 301 |
* 88 10/22/98 10:38p Jeff |
| 302 |
* a decent pilot file version check for later pilot file versions |
| 303 |
* |
| 304 |
* 87 10/22/98 2:58p Chris |
| 305 |
* Difficulty levels are in beta |
| 306 |
* |
| 307 |
* 86 10/22/98 2:41p Samir |
| 308 |
* fixed autoselection for good. |
| 309 |
* |
| 310 |
* 85 10/22/98 2:25p Jeff |
| 311 |
* fixed bug |
| 312 |
* |
| 313 |
* 84 10/22/98 1:35p Jeff |
| 314 |
* |
| 315 |
* 83 10/22/98 1:30p Jeff |
| 316 |
* brought back difficulty |
| 317 |
* |
| 318 |
* 82 10/21/98 11:54p Samir |
| 319 |
* fixed typos. |
| 320 |
* |
| 321 |
* 81 10/21/98 7:15p Samir |
| 322 |
* added joy and mouse sensitivities for pilot. |
| 323 |
* |
| 324 |
* 80 10/21/98 10:36a Samir |
| 325 |
* added code to turn on or off joystick or mouse. |
| 326 |
* |
| 327 |
* 79 10/20/98 1:41a Jeff |
| 328 |
* a couple more improvements to ImportGraphic |
| 329 |
* |
| 330 |
* 78 10/20/98 12:59a Jeff |
| 331 |
* fixed pilot import bitmap |
| 332 |
* |
| 333 |
* 77 10/19/98 10:41a Jeff |
| 334 |
* moved pilot select window down to uncover "demo" |
| 335 |
* |
| 336 |
* 76 10/18/98 10:07p Jeff |
| 337 |
* automatically chooses the last used pilot |
| 338 |
* |
| 339 |
* 75 10/17/98 7:31p Samir |
| 340 |
* added invertible axes |
| 341 |
* |
| 342 |
* 74 10/15/98 1:36p Jeff |
| 343 |
* allow cancel out of pilot select menu |
| 344 |
* |
| 345 |
* 73 10/15/98 11:48a Samir |
| 346 |
* fixed pilot create so it initializes the proper defaults. |
| 347 |
* |
| 348 |
* 72 10/14/98 6:39p Samir |
| 349 |
* save screen size for game. |
| 350 |
* |
| 351 |
* 71 10/14/98 2:48p Kevin |
| 352 |
* Changed memory code to comply with mem lib |
| 353 |
* |
| 354 |
* 70 10/12/98 3:02p Jeff |
| 355 |
* added a verify function, give warning when they go into Multiplayer |
| 356 |
* ship customize with a bad ship |
| 357 |
* |
| 358 |
* 69 10/11/98 3:02a Jeff |
| 359 |
* handle the case where a player has a ship selected in his pilot file, |
| 360 |
* but the ship doesn't exist in the game |
| 361 |
* |
| 362 |
* 68 10/09/98 3:32p Kevin |
| 363 |
* New memory library |
| 364 |
* |
| 365 |
* 67 10/09/98 3:36p Jeff |
| 366 |
* attempted to fix Pyro-SE for demo again |
| 367 |
* |
| 368 |
* 66 10/09/98 3:06p Jeff |
| 369 |
* fixed default_ship for demo |
| 370 |
* |
| 371 |
* 65 10/08/98 6:41p Jeff |
| 372 |
* when creating your first pilot it immediatly returns you to main menu |
| 373 |
* |
| 374 |
* 64 10/08/98 4:23p Kevin |
| 375 |
* Changed code to comply with memory library usage. Always use mem_malloc |
| 376 |
* , mem_free and mem_strdup |
| 377 |
* |
| 378 |
* 63 10/06/98 5:34p Jeff |
| 379 |
* various UI changes/improvements |
| 380 |
* |
| 381 |
* 62 10/01/98 2:19p Samir |
| 382 |
* took out DEMO define. |
| 383 |
* |
| 384 |
* 61 10/01/98 12:58p Samir |
| 385 |
* save autoselect ordering. |
| 386 |
* |
| 387 |
* 60 9/29/98 11:20a Jeff |
| 388 |
* set buffer length on pilotcreate to correct size |
| 389 |
* |
| 390 |
* 59 9/28/98 4:35p Jeff |
| 391 |
* general UI changes and improvements |
| 392 |
* |
| 393 |
* 58 9/24/98 10:45a Jeff |
| 394 |
* keep PyroGL the only ship to be allowed to be selected |
| 395 |
* |
| 396 |
* 57 9/23/98 6:19p Jeff |
| 397 |
* finished up (hopefully) updating the config/ui dialogs to meet our |
| 398 |
* standard. Keyboard/joystick config still needs some work |
| 399 |
* |
| 400 |
* 56 9/23/98 3:07p Jeff |
| 401 |
* updated the colors and various other items of config and UI |
| 402 |
* |
| 403 |
* 55 9/22/98 3:56p Samir |
| 404 |
* special demo code doesn't allow pilot and mission stuff. |
| 405 |
* |
| 406 |
* 54 9/08/98 11:41a Jeff |
| 407 |
* new pilot selection interface |
| 408 |
* |
| 409 |
* 53 9/04/98 3:52p Jeff |
| 410 |
* changes made from UI meeting |
| 411 |
* |
| 412 |
* 52 9/04/98 1:20p Jeff |
| 413 |
* updates to ship selection, now includes audio taunts, strips crc's from |
| 414 |
* filenames when displaying |
| 415 |
* |
| 416 |
* 51 9/02/98 2:54p Jeff |
| 417 |
* added defines for text colors to be used throughout the game...fixed up |
| 418 |
* buddy menu too |
| 419 |
* |
| 420 |
* 50 8/31/98 5:20p Jeff |
| 421 |
* put in callback for ship selection UI |
| 422 |
* |
| 423 |
* 49 8/31/98 12:38p Samir |
| 424 |
* don't call setlistindex. |
| 425 |
* |
| 426 |
* 48 8/29/98 6:53p Jeff |
| 427 |
* added single-player ship selection |
| 428 |
* |
| 429 |
* 47 8/15/98 5:16p Matt |
| 430 |
* Added new Base_directory variable. Got rid of D3_LOCAL check and |
| 431 |
* 'local directory' registry variable. |
| 432 |
* |
| 433 |
* 46 8/14/98 2:24p Jeff |
| 434 |
* give error message on error import |
| 435 |
* |
| 436 |
* 45 8/06/98 4:59p Jeff |
| 437 |
* now imports graphic files to ogfs |
| 438 |
* |
| 439 |
* 44 8/04/98 5:41p Jeff |
| 440 |
* fixed bug if user selected none for texture |
| 441 |
* |
| 442 |
* 43 8/03/98 12:20p Jeff |
| 443 |
* fixed some more bugs in ship config |
| 444 |
* |
| 445 |
* 42 8/03/98 10:42a Jeff |
| 446 |
* forgot to DrawPolymodel with effect on ship config |
| 447 |
* |
| 448 |
* 41 7/30/98 2:48p Jeff |
| 449 |
* |
| 450 |
* 40 7/30/98 12:32p Jeff |
| 451 |
* everything working for ship customization, including importing of ifl |
| 452 |
* |
| 453 |
* 39 7/29/98 5:39p Jeff |
| 454 |
* updated |
| 455 |
* |
| 456 |
* 38 7/28/98 4:16p Jeff |
| 457 |
* ship dialog is in and working good |
| 458 |
* |
| 459 |
* 37 7/27/98 6:26p Jeff |
| 460 |
* basic implementation of ship configurations...needs to be purtied up |
| 461 |
* |
| 462 |
* 36 6/22/98 7:31p Samir |
| 463 |
* added UIEdit::Activate, which activates an edit box manually. |
| 464 |
* |
| 465 |
* 35 6/19/98 5:39p Samir |
| 466 |
* save out hud mode too. |
| 467 |
* |
| 468 |
* 34 6/19/98 3:32p Samir |
| 469 |
* initialize hud layout in PilotInit. |
| 470 |
* |
| 471 |
* 33 6/19/98 3:30p Samir |
| 472 |
* added hud layout info in pilot file. |
| 473 |
* |
| 474 |
* 32 6/18/98 4:48p Samir |
| 475 |
* added changes for multiple configs for joystick controls. |
| 476 |
* |
| 477 |
* 31 6/17/98 3:28p Jeff |
| 478 |
* localization changes. made an init function |
| 479 |
* |
| 480 |
* 30 6/16/98 10:54a Jeff |
| 481 |
* |
| 482 |
* 29 6/12/98 5:56p Jeff |
| 483 |
* localization test |
| 484 |
* |
| 485 |
* 28 6/01/98 10:57a Jeff |
| 486 |
* Fixed Pilot read bug. Fixed name length on Pilot create dialog |
| 487 |
* |
| 488 |
* 27 5/24/98 2:56a Jeff |
| 489 |
* Pilot dialogs up to date |
| 490 |
* |
| 491 |
* 26 4/23/98 11:14p Samir |
| 492 |
* added read controller flag to pilot |
| 493 |
* |
| 494 |
* 25 4/14/98 7:31p Matt |
| 495 |
* Changed code to use ddio_MakePath() instead of sprintf() to create file |
| 496 |
* spec |
| 497 |
* |
| 498 |
* 24 4/13/98 7:01p Samir |
| 499 |
* added snazzy listbox and edit box art. |
| 500 |
* |
| 501 |
* 23 4/02/98 7:58p Samir |
| 502 |
* Fixed up control setting saving and restoring. |
| 503 |
* |
| 504 |
* 22 4/01/98 3:34p Jeff |
| 505 |
* ship_model is now a string |
| 506 |
* |
| 507 |
* 21 3/23/98 11:09a Jeff |
| 508 |
* Fixed up the "Choose A Pilot" window |
| 509 |
* |
| 510 |
* 20 3/20/98 5:34p Jeff |
| 511 |
* Added Copy Controls from a pilot support |
| 512 |
* |
| 513 |
* 19 3/20/98 1:19p Jeff |
| 514 |
* Changes made to use Default_pilot string for pilot filename to use. |
| 515 |
* |
| 516 |
* 18 3/19/98 6:57p Jeff |
| 517 |
* Pilot stuff reads and writes to the correct directories |
| 518 |
* |
| 519 |
* 17 3/18/98 7:49p Samir |
| 520 |
* Maybe fixed controller config init mess. |
| 521 |
* |
| 522 |
* 16 3/16/98 3:26p Samir |
| 523 |
* Fixed controller need ID and index discrepancy. |
| 524 |
* |
| 525 |
* 15 3/13/98 8:55p Jeff |
| 526 |
* Various changes to move control configuration into Pilot file |
| 527 |
* |
| 528 |
* 14 3/13/98 5:32p Jeff |
| 529 |
* close the display window before displaying delete confirmation box |
| 530 |
* |
| 531 |
* 13 3/13/98 5:19p Jeff |
| 532 |
* UIListBoxes have scroll button code now |
| 533 |
* |
| 534 |
* 12 3/12/98 7:10p Jeff |
| 535 |
* double clicking on pilot list selects pilot |
| 536 |
* |
| 537 |
* 11 3/12/98 2:00p Jeff |
| 538 |
* Various changes to improve pilot dialogs |
| 539 |
* |
| 540 |
* 10 3/11/98 5:38p Jeff |
| 541 |
* Now use the NewUIMessageBox for small windows |
| 542 |
* |
| 543 |
* 9 3/10/98 7:08p Jeff |
| 544 |
* Various changes due to new window class |
| 545 |
* |
| 546 |
* 8 3/10/98 11:57a Jeff |
| 547 |
* Corrected some function comments and made '.' a valid filename |
| 548 |
* character |
| 549 |
* |
| 550 |
* 7 3/10/98 11:50a Jeff |
| 551 |
* Added filename field to pilot structure, which keeps track of the pilot |
| 552 |
* filename...fixes any bugs that come with renaming a file. Made changes |
| 553 |
* to take advantage of this. |
| 554 |
* |
| 555 |
* 6 3/10/98 11:12a Jeff |
| 556 |
* Made various changes to accomodate Samir's Listbox callback paradigm |
| 557 |
* |
| 558 |
* 5 3/09/98 6:27p Jeff |
| 559 |
* Cleaned up code, made file operations more robust, pretty sturdy now |
| 560 |
* |
| 561 |
* 4 3/09/98 4:00p Jeff |
| 562 |
* Various improvements |
| 563 |
* |
| 564 |
* 3 3/06/98 6:32p Jeff |
| 565 |
* Added Pilot files and major functionality |
| 566 |
* |
| 567 |
* 2 3/05/98 4:28p Jeff |
| 568 |
* Initial creation |
| 569 |
* |
| 570 |
* $NoKeywords: $ |
| 571 |
*/ |
| 572 |
|
| 573 |
#include <cstdio> |
| 574 |
|
| 575 |
#include <stdlib.h> |
| 576 |
#include <string.h> |
| 577 |
#include <stdarg.h> |
| 578 |
|
| 579 |
#include "pilot.h" |
| 580 |
#include "mono.h" |
| 581 |
#include "renderer.h" |
| 582 |
#include "render.h" |
| 583 |
#include "ddio.h" |
| 584 |
#include "descent.h" |
| 585 |
#include "game.h" |
| 586 |
#include "cfile.h" |
| 587 |
#include "application.h" |
| 588 |
#include "manage.h" |
| 589 |
#include "newui.h" |
| 590 |
#include "grtext.h" |
| 591 |
#include "gamefont.h" |
| 592 |
#include "ConfigItem.h" |
| 593 |
#include "ctlconfig.h" |
| 594 |
#include "hud.h" |
| 595 |
#include "stringtable.h" |
| 596 |
#include "gametexture.h" |
| 597 |
#include "vclip.h" |
| 598 |
#include "hlsoundlib.h" |
| 599 |
#include "weapon.h" |
| 600 |
#include "config.h" |
| 601 |
#include "difficulty.h" |
| 602 |
#include "PilotPicsAPI.h" |
| 603 |
#include "Mission.h" |
| 604 |
#include "mem.h" |
| 605 |
#include "polymodel.h" |
| 606 |
#include "audiotaunts.h" |
| 607 |
#include "streamaudio.h" |
| 608 |
#include "ship.h" |
| 609 |
#include "dedicated_server.h" |
| 610 |
|
| 611 |
// some general defines |
| 612 |
#define IDP_SAVE 10 |
| 613 |
#define IDP_CANCEL 11 |
| 614 |
#define IDP_APPLY 12 |
| 615 |
|
| 616 |
// used for the Pilot file functions |
| 617 |
#define PLTWILDCARD "*.plt" |
| 618 |
#define PLTEXTENSION ".plt" |
| 619 |
#define DPLTWILDCARD "*.pld" |
| 620 |
#define PLTFILELEN 260 |
| 621 |
|
| 622 |
#define MAX_AUDIOTAUNTSIZE (32 * 1024) |
| 623 |
|
| 624 |
// !!!!!(PLEASE VERSION CHECK ON READ TO MAINTAIN PILOT COMPAT.)!!!! |
| 625 |
// 0x20 NEW PILOT FILE READ->WRITE |
| 626 |
// 0x12 ???? |
| 627 |
// 0x11 added finished field to mission data -Samir |
| 628 |
// 0x10 added mission data - Jeff |
| 629 |
// 0xf write out multiple joystick and mouse sensitivities.-Samir |
| 630 |
// 0xe write out number of controller functions in file-Samir |
| 631 |
// 0xd added pilot picture id |
| 632 |
// 0xc added mouse and joy sensitivities -Samir. |
| 633 |
// 0xb added invertible axes - Samir |
| 634 |
// 0xa Added game window size-Samir |
| 635 |
// 0x9 Added weapon selection info -Samir |
| 636 |
// 0x8 Added audio taunt files - Jeffrey |
| 637 |
// 0x7 Added ship logo - Jeff |
| 638 |
// 0x6 Added default hud mode- Samir |
| 639 |
// 0x5 Added hud layout info- Samir |
| 640 |
// 0x4 Added read controller flag- Samir. |
| 641 |
#define PLTFILEVERSION 0x12 |
| 642 |
|
| 643 |
// border size of the UI window |
| 644 |
#define UI_BORDERSIZE 20 |
| 645 |
|
| 646 |
/////////////////////////////////////////////// |
| 647 |
// Externals (Globals for the game) |
| 648 |
|
| 649 |
// Game global for current pilot |
| 650 |
pilot Current_pilot; |
| 651 |
char Default_pilot[_MAX_PATH] = {" "}; |
| 652 |
uint8_t ingame_difficulty = 1; |
| 653 |
|
| 654 |
/////////////////////////////////////////////// |
| 655 |
// Internals (Globals for the file) |
| 656 |
|
| 657 |
bool DisplayFileDialog(char *path, char *title, char *wildcards, int flags); |
| 658 |
|
| 659 |
// internal function prototypes |
| 660 |
bool PltDelete(pilot *Pilot); |
| 661 |
void NewPltUpdate(newuiListBox *list, char **flist, int filecount, int selected, char *filename = NULL); |
| 662 |
bool PilotChoose(pilot *Pilot, bool presets = false); |
| 663 |
bool PltCopyKeyConfig(pilot *src, pilot *dest); |
| 664 |
bool PltSelectShip(pilot *Pilot); |
| 665 |
void ShipSelectCallBack(int c); |
| 666 |
void CustomCallBack(int c); |
| 667 |
void PilotCopyDefaultControls(pilot *Pilot); |
| 668 |
|
| 669 |
int Pilot_NewRead(pilot *Pilot, bool read_keyconfig, bool read_missiondata); |
| 670 |
int Pilot_NewWrite(pilot *Pilot, bool newpilot); |
| 671 |
|
| 672 |
struct tCustomListInfo { |
| 673 |
newuiListBox *custom_bitmap_list; |
| 674 |
int needed_size; // size of allocated memory for files |
| 675 |
char *files; // string list of file names |
| 676 |
// Initializes the struct |
| 677 |
void Init() { |
| 678 |
files = NULL; |
| 679 |
custom_bitmap_list = NULL; |
| 680 |
needed_size = 0; |
| 681 |
} |
| 682 |
// Frees and resets the struct |
| 683 |
void Reset() { |
| 684 |
if (files) { |
| 685 |
mem_free(files); |
| 686 |
files = NULL; |
| 687 |
} |
| 688 |
custom_bitmap_list = NULL; |
| 689 |
needed_size = 0; |
| 690 |
} |
| 691 |
}; |
| 692 |
|
| 693 |
struct tAudioTauntComboBoxes { |
| 694 |
newuiComboBox *taunt_a, *taunt_b, *taunt_c, *taunt_d; |
| 695 |
}; |
| 696 |
|
| 697 |
// Deletes the currently selected audio taunt #4 |
| 698 |
void ShipSelectDeleteTaunt(pilot *Pilot, tCustomListInfo *cust_snds, newuiComboBox *lb, |
| 699 |
tAudioTauntComboBoxes *taunt_boxex); |
| 700 |
|
| 701 |
// Deletes the currently selected ship logo |
| 702 |
void ShipSelectDeleteLogo(tCustomListInfo *cust_bmps, newuiListBox *lb); |
| 703 |
|
| 704 |
// ------------------------------------------------------- |
| 705 |
// ShowPilotPicDialog |
| 706 |
// Purpose: |
| 707 |
// Displays the dialog to choose a pilot picture for |
| 708 |
// the given pilot. |
| 709 |
// ------------------------------------------------------- |
| 710 |
void ShowPilotPicDialog(pilot *Pilot); |
| 711 |
|
| 712 |
UITextItem *pilot_items = NULL; // array of UITextItems for use in Pilot listbox |
| 713 |
pilot temp; // pilot in use by the listbox |
| 714 |
NewUIGameWindow *PilotDisplayWindow; // pointer to display_window (needed for listbox callback) |
| 715 |
char **filelist; // list of pilot filenames |
| 716 |
int filecount; // number of pilot filenames found |
| 717 |
void PilotListSelectChangeCallback(int index); |
| 718 |
|
| 719 |
//////////////////////////////////////////////////////////////////////////// |
| 720 |
// Dialog Functions |
| 721 |
//////////////////////////////////////////////////////////////////////////// |
| 722 |
void PilotInitData(pilot *plt); |
| 723 |
|
| 724 |
void PilotShutdown(void) { |
| 725 |
Current_pilot.flush(false); |
| 726 |
Current_pilot.clean(false); |
| 727 |
} |
| 728 |
|
| 729 |
void PilotInit(void) { |
| 730 |
PilotInitData(&Current_pilot); |
| 731 |
atexit(PilotShutdown); |
| 732 |
} |
| 733 |
|
| 734 |
void PilotInitData(pilot *plt) { |
| 735 |
if (!plt) { |
| 736 |
Int3(); |
| 737 |
} else { |
| 738 |
plt->clean(true); |
| 739 |
} |
| 740 |
} |
| 741 |
|
| 742 |
// VerifyPilotData |
| 743 |
// |
| 744 |
// Call this function to check the data that is in the given pilot struct...it will verify that all files |
| 745 |
// listed are available, if they are not, then it will set them to defaults. Returns true if it had to |
| 746 |
// fix the data (you may want to save the pilot immediatly) |
| 747 |
bool VerifyPilotData(pilot *Pilot) { |
| 748 |
if (!Pilot) { |
| 749 |
Int3(); |
| 750 |
return false; |
| 751 |
} |
| 752 |
Pilot->verify(); |
| 753 |
return false; |
| 754 |
} |
| 755 |
|
| 756 |
/* |
| 757 |
*********************************************************** |
| 758 |
*/ |
| 759 |
|
| 760 |
#define IDP_SELECT 0x50 |
| 761 |
#define IDP_SEL_PILOTLIST 0x51 |
| 762 |
#define IDP_DELETE 0x52 |
| 763 |
#define IDP_ADD 0x53 |
| 764 |
#define IDP_EDIT 0x54 |
| 765 |
#define IDP_SHIPCONFIG 0x55 |
| 766 |
#define IDP_CHOOSEPIC 0x56 |
| 767 |
#define IDP_CONFIGCONT 0x57 |
| 768 |
#define IDP_CONFIGKEYB 0x58 |
| 769 |
#define IDP_COPYCONTROLS 0x59 |
| 770 |
|
| 771 |
struct pilot_select_menu { |
| 772 |
newuiSheet *sheet; |
| 773 |
|
| 774 |
newuiListBox *pilot_list; |
| 775 |
|
| 776 |
// sets the menu up. |
| 777 |
newuiSheet *setup(newuiMenu *menu) { |
| 778 |
sheet = menu->AddOption(IDP_SELECT, TXT_PILOTS, NEWUIMENU_MEDIUM); |
| 779 |
|
| 780 |
// Pilot selection list |
| 781 |
sheet->NewGroup(NULL, 6, 18); |
| 782 |
pilot_list = sheet->AddListBox(232, 168, IDP_SEL_PILOTLIST); |
| 783 |
pilot_list->SetSelectChangeCallback(PilotListSelectChangeCallback); |
| 784 |
|
| 785 |
return sheet; |
| 786 |
}; |
| 787 |
|
| 788 |
// retreive values from property sheet here. |
| 789 |
void finish() { sheet = NULL; }; |
| 790 |
|
| 791 |
// process |
| 792 |
void process(int res){}; |
| 793 |
}; |
| 794 |
|
| 795 |
struct pilot_edit_menu { |
| 796 |
newuiSheet *sheet; |
| 797 |
|
| 798 |
int *difficulty; |
| 799 |
bool *profanity; |
| 800 |
bool *audiotaunts; |
| 801 |
char *pilot_name; |
| 802 |
|
| 803 |
newuiSheet *setup(newuiMenu *menu) { |
| 804 |
sheet = menu->AddOption(IDP_EDIT, TXT_CONFIGURE, NEWUIMENU_MEDIUM); |
| 805 |
|
| 806 |
// pilot name |
| 807 |
sheet->NewGroup(NULL, 5, 0); |
| 808 |
pilot_name = sheet->AddChangeableText(64); |
| 809 |
|
| 810 |
// difficulty |
| 811 |
sheet->NewGroup(TXT_PLTDIFFICULT, 55, 12); |
| 812 |
#if 1 // ndef DEMO |
| 813 |
difficulty = sheet->AddFirstLongRadioButton(TXT_TRAINEE); |
| 814 |
sheet->AddLongRadioButton(TXT_ROOKIE); |
| 815 |
sheet->AddLongRadioButton(TXT_HOTSHOT); |
| 816 |
sheet->AddLongRadioButton(TXT_ACE); |
| 817 |
sheet->AddLongRadioButton(TXT_INSANE); |
| 818 |
*difficulty = 0; |
| 819 |
#else |
| 820 |
difficulty = sheet->AddFirstLongRadioButton(TXT_TRAINEE); |
| 821 |
sheet->AddLongRadioButton(TXT_HOTSHOT); |
| 822 |
*difficulty = 0; |
| 823 |
#endif |
| 824 |
sheet->NewGroup(TXT_CONTROLSCONFIG, 55, 93); |
| 825 |
sheet->AddLongButton(TXT_CPYKEYCONF, IDP_COPYCONTROLS); |
| 826 |
sheet->AddLongButton(TXT_CUSTKEYB, IDP_CONFIGKEYB); |
| 827 |
sheet->AddLongButton(TXT_CUSTGAMEC, IDP_CONFIGCONT); |
| 828 |
|
| 829 |
sheet->NewGroup(TXT_MULTIPLAYERCONFIG, 55, 150); |
| 830 |
#if (!defined(OEM) && !defined(DEMO)) |
| 831 |
sheet->AddLongButton(TXT_SELPILOTPIC, IDP_CHOOSEPIC); |
| 832 |
#endif |
| 833 |
sheet->AddLongButton(TXT_SHIPCUSTOMIZE, IDP_SHIPCONFIG); |
| 834 |
|
| 835 |
sheet->NewGroup(TXT_MISCELLANEOUS, 55, 195); |
| 836 |
profanity = sheet->AddLongCheckBox(TXT_PROFFILTER); |
| 837 |
audiotaunts = sheet->AddLongCheckBox(TXT_AUDIOTAUNTS); |
| 838 |
|
| 839 |
return sheet; |
| 840 |
}; |
| 841 |
|
| 842 |
// retreive values from property sheet here. |
| 843 |
void finish() { sheet = NULL; }; |
| 844 |
|
| 845 |
// process |
| 846 |
void process(int res){}; |
| 847 |
}; |
| 848 |
|
| 849 |
struct pilot_add_menu { |
| 850 |
newuiSheet *sheet; |
| 851 |
}; |
| 852 |
|
| 853 |
struct { |
| 854 |
newuiMenu *menu; |
| 855 |
pilot_select_menu *select; |
| 856 |
pilot_edit_menu *edit; |
| 857 |
|
| 858 |
bool initial_call; |
| 859 |
bool all_setup; |
| 860 |
} PilotChooseDialogInfo; |
| 861 |
pilot working_pilot; |
| 862 |
|
| 863 |
void PilotListSelectChangeCallback(int index) { |
| 864 |
if (!filecount || !PilotChooseDialogInfo.all_setup) |
| 865 |
return; |
| 866 |
|
| 867 |
pilot *Pilot = &working_pilot; |
| 868 |
char name[PILOT_STRING_SIZE]; |
| 869 |
uint8_t difficulty; |
| 870 |
bool profanity, audiotaunts; |
| 871 |
bool in_edit = false; |
| 872 |
|
| 873 |
if (PilotChooseDialogInfo.menu->GetCurrentOption() == IDP_EDIT) { |
| 874 |
in_edit = true; |
| 875 |
PilotChooseDialogInfo.edit->sheet->Realize(); |
| 876 |
} |
| 877 |
|
| 878 |
// Pilot has changed...reset all data to new pilot selected |
| 879 |
if (!PilotChooseDialogInfo.initial_call) { |
| 880 |
// save out old Pilot file so we can load up the new one |
| 881 |
char filename[PAGENAME_LEN]; |
| 882 |
working_pilot.get_filename(filename); |
| 883 |
|
| 884 |
if (cfexist(filename)) { |
| 885 |
if (in_edit) |
| 886 |
PilotChooseDialogInfo.edit->sheet->UpdateReturnValues(); |
| 887 |
|
| 888 |
// only save if the file is already there |
| 889 |
// which keeps us from bringing deleted pilots |
| 890 |
// back from the dead. |
| 891 |
difficulty = *PilotChooseDialogInfo.edit->difficulty; |
| 892 |
profanity = *PilotChooseDialogInfo.edit->profanity; |
| 893 |
audiotaunts = *PilotChooseDialogInfo.edit->audiotaunts; |
| 894 |
|
| 895 |
Pilot->set_profanity_filter(profanity); |
| 896 |
Pilot->set_difficulty(difficulty); |
| 897 |
Pilot->set_audiotaunts(audiotaunts); |
| 898 |
PltWriteFile(&working_pilot); |
| 899 |
mprintf(0, "Pilot saved\n"); |
| 900 |
} else { |
| 901 |
mprintf(0, "Skipping pilot save...has the old pilot been deleted?\n"); |
| 902 |
} |
| 903 |
|
| 904 |
working_pilot.clean(true); |
| 905 |
} |
| 906 |
|
| 907 |
Pilot->set_filename(filelist[index]); |
| 908 |
PltReadFile(Pilot); |
| 909 |
|
| 910 |
// Setup all values |
| 911 |
/////////////////////////////// |
| 912 |
Pilot->get_difficulty(&difficulty); |
| 913 |
Pilot->get_profanity_filter(&profanity); |
| 914 |
Pilot->get_audiotaunts(&audiotaunts); |
| 915 |
*PilotChooseDialogInfo.edit->difficulty = difficulty; |
| 916 |
*PilotChooseDialogInfo.edit->profanity = profanity; |
| 917 |
*PilotChooseDialogInfo.edit->audiotaunts = audiotaunts; |
| 918 |
|
| 919 |
if (in_edit) |
| 920 |
PilotChooseDialogInfo.edit->sheet->UpdateChanges(); |
| 921 |
Pilot->get_name(name); |
| 922 |
mprintf(0, "Pilot has changed to: %s\n", name); |
| 923 |
|
| 924 |
if (PilotChooseDialogInfo.edit->pilot_name) { |
| 925 |
strncpy(PilotChooseDialogInfo.edit->pilot_name, name, 63); |
| 926 |
PilotChooseDialogInfo.edit->pilot_name[63] = '\0'; |
| 927 |
} |
| 928 |
|
| 929 |
PilotChooseDialogInfo.initial_call = false; |
| 930 |
} |
| 931 |
|
| 932 |
void selectcb(newuiMenu *menu, int16_t id, void *data) { |
| 933 |
pilot_select_menu *select = (pilot_select_menu *)data; |
| 934 |
if (id == IDP_SELECT) { |
| 935 |
menu->SetFocusOnGadget(select->pilot_list); |
| 936 |
} |
| 937 |
} |
| 938 |
|
| 939 |
void PilotSelect(void) { |
| 940 |
newuiMenu menu; |
| 941 |
pilot_select_menu select; |
| 942 |
pilot_edit_menu edit; |
| 943 |
|
| 944 |
PilotChooseDialogInfo.menu = &menu; |
| 945 |
PilotChooseDialogInfo.select = &select; |
| 946 |
PilotChooseDialogInfo.edit = &edit; |
| 947 |
PilotChooseDialogInfo.initial_call = true; |
| 948 |
PilotChooseDialogInfo.all_setup = false; |
| 949 |
filelist = NULL; |
| 950 |
filecount = 0; |
| 951 |
|
| 952 |
int res = -1; |
| 953 |
bool done = false; |
| 954 |
|
| 955 |
if (cfexist(Default_pilot) != CFES_NOT_FOUND) { |
| 956 |
// ok so the default pilot file is around, mark this as the current pilot |
| 957 |
Current_pilot.set_filename(Default_pilot); |
| 958 |
PltReadFile(&Current_pilot); |
| 959 |
} |
| 960 |
|
| 961 |
char pfilename[_MAX_FNAME]; |
| 962 |
|
| 963 |
// open menu |
| 964 |
menu.Create(); |
| 965 |
|
| 966 |
select.setup(&menu); // setup pilot select menu IDP_SELECT |
| 967 |
edit.setup(&menu); // edit pilot |
| 968 |
menu.AddSimpleOption(IDP_ADD, TXT_ADD); // add |
| 969 |
menu.AddSimpleOption(IDP_DELETE, TXT_DELETE); // delete currently selected pilot |
| 970 |
menu.AddSimpleOption(UID_OK, TXT_OK); |
| 971 |
menu.AddSimpleOption(UID_CANCEL, TXT_CANCEL); |
| 972 |
menu.SetCurrentOption(IDP_SELECT); |
| 973 |
|
| 974 |
menu.SetOnOptionFocusCB(selectcb, &select); |
| 975 |
|
| 976 |
PilotChooseDialogInfo.all_setup = true; |
| 977 |
filelist = PltGetPilots(&filecount); |
| 978 |
|
| 979 |
if (!filecount) { |
| 980 |
pilot temp_pilot; |
| 981 |
// if there are currently no pilots force player to create a new pilot |
| 982 |
if (PilotCreate(&temp_pilot, true)) { |
| 983 |
PltClearList(); |
| 984 |
PltGetPilotsFree(); |
| 985 |
filelist = PltGetPilots(&filecount); |
| 986 |
NewPltUpdate(select.pilot_list, filelist, filecount, filecount - 1); |
| 987 |
|
| 988 |
int index = select.pilot_list->GetCurrentIndex(); |
| 989 |
|
| 990 |
PilotListSelectChangeCallback(index); |
| 991 |
|
| 992 |
PilotCopyDefaultControls(&working_pilot); |
| 993 |
|
| 994 |
menu.SetCurrentOption(IDP_EDIT); |
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
Current_pilot.get_filename(pfilename); |
| 999 |
NewPltUpdate(select.pilot_list, filelist, filecount, 0, pfilename); |
| 1000 |
|
| 1001 |
// if we get here than there is at least one pilot already |
| 1002 |
char old_file[_MAX_FNAME]; |
| 1003 |
|
| 1004 |
// use this in case they cancel out |
| 1005 |
Current_pilot.get_filename(pfilename); |
| 1006 |
if (cfexist(pfilename) != CFES_NOT_FOUND) { |
| 1007 |
strcpy(old_file, pfilename); |
| 1008 |
} else { |
| 1009 |
old_file[0] = '\0'; |
| 1010 |
} |
| 1011 |
|
| 1012 |
DoWaitMessage(false); |
| 1013 |
|
| 1014 |
menu.Open(); |
| 1015 |
|
| 1016 |
// run menu |
| 1017 |
do { |
| 1018 |
res = menu.DoUI(); |
| 1019 |
|
| 1020 |
switch (res) { |
| 1021 |
case IDP_EDIT: { |
| 1022 |
if (!filecount) { |
| 1023 |
menu.SetCurrentOption(IDP_SELECT); |
| 1024 |
} |
| 1025 |
} break; |
| 1026 |
|
| 1027 |
case IDP_SEL_PILOTLIST: |
| 1028 |
case UID_OK: { |
| 1029 |
// Start Game |
| 1030 |
if (filecount) { |
| 1031 |
int index = select.pilot_list->GetCurrentIndex(); |
| 1032 |
|
| 1033 |
PilotListSelectChangeCallback(index); |
| 1034 |
|
| 1035 |
char filename[PAGENAME_LEN]; |
| 1036 |
working_pilot.get_filename(filename); |
| 1037 |
Current_pilot.set_filename(filename); |
| 1038 |
PltReadFile(&Current_pilot, true, true); |
| 1039 |
|
| 1040 |
char pname[PILOT_STRING_SIZE]; |
| 1041 |
Current_pilot.get_name(pname); |
| 1042 |
mprintf(0, "Pilot To Use: %s\n", pname); |
| 1043 |
|
| 1044 |
if (VerifyPilotData(&Current_pilot)) { |
| 1045 |
// save out updated pilot since it had to be fixed |
| 1046 |
mprintf(0, "PILOT: Saving out Pilot info due to bad data in pilot file\n"); |
| 1047 |
PltWriteFile(&Current_pilot); |
| 1048 |
} |
| 1049 |
|
| 1050 |
Current_pilot.get_filename(Default_pilot); |
| 1051 |
|
| 1052 |
done = true; |
| 1053 |
|
| 1054 |
} else { |
| 1055 |
DoMessageBox(TXT_PLTERROR, TXT_NEEDTOCREATE, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1056 |
menu.SetCurrentOption(IDP_SELECT); |
| 1057 |
} |
| 1058 |
} break; |
| 1059 |
|
| 1060 |
case UID_CANCEL: { |
| 1061 |
// Cancel out |
| 1062 |
bool found_old = (cfexist(old_file) != CFES_NOT_FOUND); |
| 1063 |
bool display_error; |
| 1064 |
|
| 1065 |
if (filecount && found_old) |
| 1066 |
display_error = false; |
| 1067 |
else |
| 1068 |
display_error = true; |
| 1069 |
|
| 1070 |
if (filecount) { |
| 1071 |
int index = select.pilot_list->GetCurrentIndex(); |
| 1072 |
PilotListSelectChangeCallback(index); |
| 1073 |
|
| 1074 |
if (found_old) { |
| 1075 |
Current_pilot.set_filename(old_file); |
| 1076 |
PltReadFile(&Current_pilot, true, true); |
| 1077 |
|
| 1078 |
char pname[PILOT_STRING_SIZE]; |
| 1079 |
Current_pilot.get_name(pname); |
| 1080 |
|
| 1081 |
mprintf(0, "Pilot To Use: %s\n", pname); |
| 1082 |
if (VerifyPilotData(&Current_pilot)) { |
| 1083 |
// save out updated pilot since it had to be fixed |
| 1084 |
mprintf(0, "PILOT: Saving out Pilot info due to bad data in pilot file\n"); |
| 1085 |
PltWriteFile(&Current_pilot); |
| 1086 |
} |
| 1087 |
done = true; |
| 1088 |
} |
| 1089 |
} |
| 1090 |
|
| 1091 |
if (display_error) { |
| 1092 |
if (filecount > 0 && old_file[0] != '\0') { |
| 1093 |
DoMessageBox(TXT_PLTERROR, TXT_OLDPILOTNOEXIST, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1094 |
} else { |
| 1095 |
DoMessageBox(TXT_PLTERROR, TXT_NEEDTOCREATE, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
} break; |
| 1100 |
|
| 1101 |
case IDP_DELETE: |
| 1102 |
// delete a pilot |
| 1103 |
if (filecount) { |
| 1104 |
pilot temp_pilot; |
| 1105 |
char buff[200]; |
| 1106 |
int tindex = select.pilot_list->GetCurrentIndex(); |
| 1107 |
|
| 1108 |
PilotListSelectChangeCallback(tindex); |
| 1109 |
|
| 1110 |
temp_pilot.set_filename(filelist[tindex]); |
| 1111 |
PltReadFile(&temp_pilot); |
| 1112 |
|
| 1113 |
char pname[PILOT_STRING_SIZE]; |
| 1114 |
temp_pilot.get_name(pname); |
| 1115 |
|
| 1116 |
snprintf(buff, sizeof(buff), TXT_PLTOKDEL, pname); |
| 1117 |
if (DoMessageBox(TXT_PLTDELCONF, buff, MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) { |
| 1118 |
PltDelete(&temp_pilot); |
| 1119 |
} |
| 1120 |
|
| 1121 |
PltClearList(); |
| 1122 |
PltGetPilotsFree(); |
| 1123 |
filelist = PltGetPilots(&filecount); |
| 1124 |
if (tindex >= filecount) { |
| 1125 |
tindex = filecount - 1; |
| 1126 |
} |
| 1127 |
NewPltUpdate(select.pilot_list, filelist, filecount, tindex); |
| 1128 |
} |
| 1129 |
break; |
| 1130 |
|
| 1131 |
case IDP_ADD: { |
| 1132 |
// Create New Player |
| 1133 |
bool go_into_edit = false; |
| 1134 |
int cpilotindex = select.pilot_list->GetCurrentIndex(); |
| 1135 |
pilot temp_pilot; |
| 1136 |
if (PilotCreate(&temp_pilot, !filecount)) { |
| 1137 |
PltClearList(); |
| 1138 |
PltGetPilotsFree(); |
| 1139 |
filelist = PltGetPilots(&filecount); |
| 1140 |
|
| 1141 |
char pfilename[_MAX_FNAME]; |
| 1142 |
temp_pilot.get_filename(pfilename); |
| 1143 |
NewPltUpdate(select.pilot_list, filelist, filecount, filecount - 1, pfilename); |
| 1144 |
go_into_edit = true; |
| 1145 |
} else { |
| 1146 |
if (filecount) |
| 1147 |
NewPltUpdate(select.pilot_list, filelist, filecount, cpilotindex); |
| 1148 |
} |
| 1149 |
|
| 1150 |
int index = select.pilot_list->GetCurrentIndex(); |
| 1151 |
PilotListSelectChangeCallback(index); |
| 1152 |
|
| 1153 |
if (go_into_edit) { |
| 1154 |
PilotCopyDefaultControls(&working_pilot); |
| 1155 |
} |
| 1156 |
|
| 1157 |
if (go_into_edit) |
| 1158 |
menu.SetCurrentOption(IDP_EDIT); |
| 1159 |
else |
| 1160 |
menu.SetCurrentOption(IDP_SELECT); |
| 1161 |
} break; |
| 1162 |
|
| 1163 |
case IDP_SHIPCONFIG: { |
| 1164 |
PltSelectShip(&working_pilot); |
| 1165 |
} break; |
| 1166 |
|
| 1167 |
case IDP_CHOOSEPIC: { |
| 1168 |
char pname[PILOT_STRING_SIZE]; |
| 1169 |
working_pilot.get_name(pname); |
| 1170 |
|
| 1171 |
if (PPic_QueryPilot(pname)) { |
| 1172 |
ShowPilotPicDialog(&working_pilot); |
| 1173 |
} else { |
| 1174 |
uint16_t pid; |
| 1175 |
pid = PPIC_INVALID_ID; |
| 1176 |
working_pilot.set_multiplayer_data(NULL, NULL, NULL, &pid); |
| 1177 |
|
| 1178 |
DoMessageBox(TXT_PLTERROR, TXT_NOPICSAVAIL, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1179 |
} |
| 1180 |
|
| 1181 |
} break; |
| 1182 |
|
| 1183 |
case IDP_CONFIGCONT: |
| 1184 |
case IDP_CONFIGKEYB: { |
| 1185 |
if (!filecount) { |
| 1186 |
break; |
| 1187 |
} |
| 1188 |
|
| 1189 |
int index = select.pilot_list->GetCurrentIndex(); |
| 1190 |
|
| 1191 |
// this saves out the pilot we're currently working on |
| 1192 |
PilotListSelectChangeCallback(index); |
| 1193 |
|
| 1194 |
// read the working pilot into the Current_pilot position |
| 1195 |
char pfilename[_MAX_FNAME]; |
| 1196 |
working_pilot.get_filename(pfilename); |
| 1197 |
|
| 1198 |
Current_pilot.set_filename(pfilename); |
| 1199 |
PltReadFile(&Current_pilot, true, true); |
| 1200 |
// configure the current pilot |
| 1201 |
if (res == IDP_CONFIGKEYB) |
| 1202 |
CtlConfig(CTLCONFIG_KEYBOARD); |
| 1203 |
else |
| 1204 |
CtlConfig(CTLCONFIG_CONTROLLER); |
| 1205 |
// now save the current_pilot out to disk |
| 1206 |
PltWriteFile(&Current_pilot, false); |
| 1207 |
|
| 1208 |
PltReadFile(&working_pilot, true, true); |
| 1209 |
} break; |
| 1210 |
|
| 1211 |
case IDP_COPYCONTROLS: { |
| 1212 |
pilot s_pil; |
| 1213 |
char pfilename[_MAX_FNAME]; |
| 1214 |
working_pilot.get_filename(pfilename); |
| 1215 |
|
| 1216 |
// destroy the current list of pilots and recreate, but |
| 1217 |
// ignoring our current pilot |
| 1218 |
PltClearList(); |
| 1219 |
PltGetPilotsFree(); |
| 1220 |
filelist = PltGetPilots(&filecount, pfilename, 1); |
| 1221 |
|
| 1222 |
if (filecount >= 1) { |
| 1223 |
if (PilotChoose(&s_pil)) { |
| 1224 |
char spfilename[_MAX_FNAME]; |
| 1225 |
s_pil.get_filename(spfilename); |
| 1226 |
|
| 1227 |
if (strcmp(spfilename, pfilename) == 0) { |
| 1228 |
// user choose the same file as what he is configuring |
| 1229 |
DoMessageBox(TXT_COPYCONFERR, TXT_COPYCONFERR1, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1230 |
} else { |
| 1231 |
PltCopyKeyConfig(&s_pil, &working_pilot); |
| 1232 |
} |
| 1233 |
} |
| 1234 |
} else { |
| 1235 |
DoMessageBox(TXT_PLTERROR, TXT_NOPILOTSTOCOPY, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1236 |
} |
| 1237 |
|
| 1238 |
// Restore the pilot list, ignoring none |
| 1239 |
PltClearList(); |
| 1240 |
PltGetPilotsFree(); |
| 1241 |
filelist = PltGetPilots(&filecount); |
| 1242 |
} break; |
| 1243 |
} |
| 1244 |
|
| 1245 |
} while (!done); |
| 1246 |
|
| 1247 |
PltClearList(); |
| 1248 |
PltGetPilotsFree(); |
| 1249 |
Current_pilot.get_difficulty(&ingame_difficulty); |
| 1250 |
|
| 1251 |
// get settings |
| 1252 |
select.finish(); |
| 1253 |
edit.finish(); |
| 1254 |
menu.Close(); |
| 1255 |
menu.Destroy(); |
| 1256 |
} |
| 1257 |
|
| 1258 |
////////////////////////////////////////////////////////////// |
| 1259 |
// Brings up the Create A New Pilot Dialog |
| 1260 |
bool PilotCreate(pilot *Pilot, bool forceselection) { |
| 1261 |
bool done = false; |
| 1262 |
bool ret; |
| 1263 |
bool to_ret = false; |
| 1264 |
char pname[PILOT_STRING_SIZE]; |
| 1265 |
|
| 1266 |
while (!done) { |
| 1267 |
pname[0] = 0; |
| 1268 |
ret = DoEditDialog(TXT_PLTENTERNAME1, pname, PILOT_STRING_SIZE - 1); |
| 1269 |
|
| 1270 |
if (!ret) { |
| 1271 |
if (!forceselection) { |
| 1272 |
done = true; |
| 1273 |
to_ret = false; |
| 1274 |
} |
| 1275 |
} else { |
| 1276 |
mprintf(0, "Creating Pilot!"); |
| 1277 |
|
| 1278 |
// call this to initialize pilot data for player. |
| 1279 |
PilotInitData(Pilot); |
| 1280 |
char pfilename[_MAX_FNAME]; |
| 1281 |
|
| 1282 |
// strip whitespace |
| 1283 |
char *ptr = pname + strlen(pname) - 1; |
| 1284 |
while ((ptr > pname) && (*ptr == ' ' || *ptr == '\t')) { |
| 1285 |
*ptr = '\0'; |
| 1286 |
ptr--; |
| 1287 |
} |
| 1288 |
|
| 1289 |
ptr = pname; |
| 1290 |
while (*ptr && (*ptr == ' ' || *ptr == '\t')) |
| 1291 |
ptr++; |
| 1292 |
|
| 1293 |
if (strlen(ptr) == 0) { |
| 1294 |
DoMessageBox(TXT_PLTERROR, TXT_PLTERRORNAME, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1295 |
goto retry; |
| 1296 |
} |
| 1297 |
|
| 1298 |
Pilot->set_name(ptr); |
| 1299 |
strcpy(pfilename, ptr); |
| 1300 |
PltMakeFNValid(pfilename); |
| 1301 |
strcat(pfilename, PLTEXTENSION); |
| 1302 |
|
| 1303 |
Pilot->set_filename(pfilename); |
| 1304 |
|
| 1305 |
RestoreDefaultControls(); |
| 1306 |
|
| 1307 |
for (int id = 0; id < NUM_CONTROLLER_FUNCTIONS; id++) { |
| 1308 |
ct_type type[2]; |
| 1309 |
ct_config_data value; |
| 1310 |
uint8_t flags[2]; |
| 1311 |
Controller->get_controller_function(Controller_needs[id].id, type, &value, flags); |
| 1312 |
Pilot->controls[id].id = Controller_needs[id].id; |
| 1313 |
Pilot->controls[id].type[0] = type[0]; |
| 1314 |
Pilot->controls[id].type[1] = type[1]; |
| 1315 |
Pilot->controls[id].value = value; |
| 1316 |
Pilot->controls[id].flags[0] = flags[0]; |
| 1317 |
Pilot->controls[id].flags[1] = flags[1]; |
| 1318 |
} |
| 1319 |
switch (PltWriteFile(Pilot, true)) { |
| 1320 |
case PLTW_CFILE_FATAL: { |
| 1321 |
// real bad error trying to open file to write to |
| 1322 |
DoMessageBox(TXT_FILEERROR, TXT_PLTCFILEERR, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1323 |
done = true; |
| 1324 |
to_ret = false; // returning true, that way if they are out of drive space |
| 1325 |
// they can't get to the pilot window, and delete some pilots |
| 1326 |
} break; |
| 1327 |
|
| 1328 |
case PLTW_UNKNOWN_FATAL: { |
| 1329 |
// real bad error trying to open file to write to |
| 1330 |
DoMessageBox(TXT_FILEERROR, TXT_PLTUKNOWNERR, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1331 |
done = true; |
| 1332 |
to_ret = false; // returning true, that way if they are out of drive space |
| 1333 |
// they can't get to the pilot window, and delete some pilots |
| 1334 |
} break; |
| 1335 |
|
| 1336 |
case PLTW_FILE_CANTOPEN: { |
| 1337 |
// real bad error trying to open file to write to |
| 1338 |
DoMessageBox(TXT_FILEERROR, TXT_FILEERRPLT1, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1339 |
done = true; |
| 1340 |
to_ret = false; // returning true, that way if they are out of drive space |
| 1341 |
// they can't get to the pilot window, and delete some pilots |
| 1342 |
} break; |
| 1343 |
|
| 1344 |
case PLTW_NO_FILENAME: { |
| 1345 |
// No name was given |
| 1346 |
DoMessageBox(TXT_PLTERROR, TXT_PLTERRORNAME, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1347 |
} break; |
| 1348 |
|
| 1349 |
case PLTW_FILE_EXISTS: { |
| 1350 |
// pilot already exists so bring up error window |
| 1351 |
DoMessageBox(TXT_PLTERROR, TXT_PLTERREXISTS, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1352 |
} break; |
| 1353 |
|
| 1354 |
case PLTW_NO_ERROR: { |
| 1355 |
// File saved ok |
| 1356 |
done = true; |
| 1357 |
to_ret = true; |
| 1358 |
} break; |
| 1359 |
} |
| 1360 |
} |
| 1361 |
retry:; |
| 1362 |
} |
| 1363 |
|
| 1364 |
return to_ret; |
| 1365 |
} |
| 1366 |
|
| 1367 |
/////////////////////////////////////////////////////////////////////////////////// |
| 1368 |
// Helper funktions |
| 1369 |
/////////////////////////////////////////////////////////////////////////////////// |
| 1370 |
void PilotCopyDefaultControls(pilot *Pilot) { |
| 1371 |
PltClearList(); |
| 1372 |
PltGetPilotsFree(); |
| 1373 |
filelist = PltGetPilots(&filecount, NULL, 2); |
| 1374 |
|
| 1375 |
// if(filecount>0 && DoMessageBox(TXT_PRESETCONTROLS,TXT_USEPRESETS,MSGBOX_YESNO)) |
| 1376 |
if (filecount > 0) { |
| 1377 |
pilot s_pil; |
| 1378 |
|
| 1379 |
if (PilotChoose(&s_pil, true)) { |
| 1380 |
char spfilename[_MAX_FNAME]; |
| 1381 |
s_pil.get_filename(spfilename); |
| 1382 |
|
| 1383 |
if (cfexist(spfilename)) { |
| 1384 |
PltCopyKeyConfig(&s_pil, Pilot); |
| 1385 |
} else { |
| 1386 |
mprintf(0, "%s does not exist...not copying\n", spfilename); |
| 1387 |
Int3(); |
| 1388 |
} |
| 1389 |
} |
| 1390 |
} |
| 1391 |
|
| 1392 |
// Restore the pilot list, ignoring none |
| 1393 |
PltClearList(); |
| 1394 |
PltGetPilotsFree(); |
| 1395 |
filelist = PltGetPilots(&filecount); |
| 1396 |
} |
| 1397 |
|
| 1398 |
/////////////////////////////////////////////////////////// |
| 1399 |
// Displays a window to select a pilot |
| 1400 |
bool PilotChoose(pilot *Pilot, bool presets) { |
| 1401 |
#define IDP_PCLIST 19 |
| 1402 |
#define PCHOOSE_WND_H 288 |
| 1403 |
#define PCHOOSE_WND_W 384 |
| 1404 |
|
| 1405 |
if (filecount == 0) |
| 1406 |
return false; |
| 1407 |
|
| 1408 |
newuiTiledWindow window; |
| 1409 |
newuiSheet *sheet; |
| 1410 |
newuiListBox *pilot_list; |
| 1411 |
|
| 1412 |
bool exit_menu = false; |
| 1413 |
|
| 1414 |
if (presets) { |
| 1415 |
window.Create(TXT_PRESETCONTROLS, 0, 0, PCHOOSE_WND_W, PCHOOSE_WND_H); |
| 1416 |
} else { |
| 1417 |
window.Create(TXT_PLTCHOOSE, 0, 0, PCHOOSE_WND_W, PCHOOSE_WND_H); |
| 1418 |
} |
| 1419 |
sheet = window.GetSheet(); |
| 1420 |
|
| 1421 |
sheet->NewGroup(NULL, 57, 0); |
| 1422 |
sheet->AddText(TXT_PILOTPICTITLE); |
| 1423 |
sheet->AddText(TXT_COPYCONTB); |
| 1424 |
sheet->AddText(TXT_COPYCONTOLSC); |
| 1425 |
|
| 1426 |
sheet->NewGroup(NULL, 7, 40); |
| 1427 |
pilot_list = sheet->AddListBox(284, 100, IDP_PCLIST); |
| 1428 |
pilot_list->SetCurrentIndex(0); |
| 1429 |
NewPltUpdate(pilot_list, filelist, filecount, 0); |
| 1430 |
|
| 1431 |
sheet->NewGroup(NULL, 80, 180, NEWUI_ALIGN_HORIZ); |
| 1432 |
sheet->AddButton(TXT_OK, UID_OK); |
| 1433 |
sheet->AddButton(TXT_CANCEL, UID_CANCEL); |
| 1434 |
|
| 1435 |
bool ret = false; |
| 1436 |
|
| 1437 |
window.Open(); |
| 1438 |
|
| 1439 |
while (!exit_menu) { |
| 1440 |
int res = window.DoUI(); |
| 1441 |
|
| 1442 |
// handle all UI results. |
| 1443 |
switch (res) { |
| 1444 |
case IDP_PCLIST: |
| 1445 |
case UID_OK: { |
| 1446 |
int index = pilot_list->GetCurrentIndex(); |
| 1447 |
if (index >= 0) { |
| 1448 |
Pilot->set_filename(filelist[index]); |
| 1449 |
PltReadFile(Pilot, false); |
| 1450 |
ret = true; |
| 1451 |
exit_menu = true; |
| 1452 |
} |
| 1453 |
} break; |
| 1454 |
|
| 1455 |
case UID_CANCEL: |
| 1456 |
ret = false; |
| 1457 |
exit_menu = true; |
| 1458 |
break; |
| 1459 |
} |
| 1460 |
} |
| 1461 |
|
| 1462 |
window.Close(); |
| 1463 |
window.Destroy(); |
| 1464 |
|
| 1465 |
return ret; |
| 1466 |
} |
| 1467 |
|
| 1468 |
/////////////////////////////////////////////////////////// |
| 1469 |
// copies a pilot to another |
| 1470 |
/*************************************************** |
| 1471 |
bool PilotCopy(pilot *Src,pilot *Dest) |
| 1472 |
{ |
| 1473 |
char sname[PILOT_STRING_SIZE]; |
| 1474 |
char sship[PAGENAME_LEN]; |
| 1475 |
uint8_t sdiff; |
| 1476 |
|
| 1477 |
Src->get_name(sname); |
| 1478 |
Src->get_ship(sship); |
| 1479 |
Src->get_difficulty(&sdiff); |
| 1480 |
|
| 1481 |
Dest->set_name(sname); |
| 1482 |
Dest->set_ship(sship); |
| 1483 |
Dest->set_difficulty(sdiff); |
| 1484 |
|
| 1485 |
return PltCopyKeyConfig(Src,Dest); |
| 1486 |
} |
| 1487 |
***************************************************/ |
| 1488 |
///////////////////////////////////////////////////// |
| 1489 |
// Updates the pilot listbox |
| 1490 |
void NewPltUpdate(newuiListBox *list, char **flist, int filecount, int selected, char *filename) { |
| 1491 |
int index; |
| 1492 |
pilot tPilot; |
| 1493 |
|
| 1494 |
list->RemoveAll(); |
| 1495 |
|
| 1496 |
if (pilot_items) { |
| 1497 |
delete[] pilot_items; |
| 1498 |
pilot_items = NULL; |
| 1499 |
} |
| 1500 |
|
| 1501 |
if (filecount) { |
| 1502 |
// create UIItems |
| 1503 |
char pname[PILOT_STRING_SIZE]; |
| 1504 |
|
| 1505 |
for (index = 0; index < filecount; index++) { |
| 1506 |
tPilot.set_filename(flist[index]); |
| 1507 |
PltReadFile(&tPilot); |
| 1508 |
|
| 1509 |
tPilot.get_name(pname); |
| 1510 |
|
| 1511 |
list->AddItem(pname); |
| 1512 |
} |
| 1513 |
|
| 1514 |
list->SetCurrentIndex(selected); |
| 1515 |
|
| 1516 |
if (filename && (cfexist(filename) != CFES_NOT_FOUND)) { |
| 1517 |
// get the selected pilot from the filename |
| 1518 |
mprintf(0, "Looking for Pilot: %s\n", filename); |
| 1519 |
for (int d = 0; d < filecount; d++) { |
| 1520 |
if (!stricmp(flist[d], filename)) { |
| 1521 |
// ok we found the filename that they want as the pilot |
| 1522 |
list->SetCurrentIndex(d); |
| 1523 |
break; |
| 1524 |
} |
| 1525 |
} |
| 1526 |
} |
| 1527 |
} |
| 1528 |
} |
| 1529 |
|
| 1530 |
// updates the current pilot's information (level played, mission played, etc) |
| 1531 |
// call after every successful mission completion |
| 1532 |
void CurrentPilotUpdateMissionStatus(bool just_add_data) { |
| 1533 |
// Don't update if it's a multiplayer game |
| 1534 |
if (Game_mode & GM_MULTI) |
| 1535 |
return; |
| 1536 |
// look for the current mission in the player's data |
| 1537 |
int index; |
| 1538 |
tMissionData mission_to_use; |
| 1539 |
|
| 1540 |
index = Current_pilot.find_mission_data(Current_mission.name); |
| 1541 |
|
| 1542 |
if (index == -1) { |
| 1543 |
|
| 1544 |
// this mission doesn't exist for the pilot yet, so add the mission to the pilot |
| 1545 |
mprintf(0, "PILOT: New Mission being added to mission data (%s)\n", Current_mission.name); |
| 1546 |
mission_to_use.highest_level = 0; |
| 1547 |
mission_to_use.finished = false; |
| 1548 |
mission_to_use.num_restores = 0; |
| 1549 |
mission_to_use.num_saves = 0; |
| 1550 |
mission_to_use.ship_permissions = Default_ship_permission; |
| 1551 |
strcpy(mission_to_use.mission_name, Current_mission.name); |
| 1552 |
|
| 1553 |
Current_pilot.add_mission_data(&mission_to_use); |
| 1554 |
|
| 1555 |
index = Current_pilot.find_mission_data(Current_mission.name); |
| 1556 |
|
| 1557 |
ASSERT(index != -1); |
| 1558 |
|
| 1559 |
} else { |
| 1560 |
// this pilot has flown this mission before, just update it |
| 1561 |
mprintf(0, "PILOT: Updating previously flown mission data (%s)\n", Current_mission.name); |
| 1562 |
|
| 1563 |
Current_pilot.get_mission_data(index, &mission_to_use); |
| 1564 |
} |
| 1565 |
|
| 1566 |
if (!just_add_data) { |
| 1567 |
// bad place to do this, but this code was added at the last minute. a long term fix requires more files to fix. |
| 1568 |
int max_level; |
| 1569 |
for (max_level = 0; max_level < Current_mission.num_levels; max_level++) { |
| 1570 |
if (Current_mission.levels[max_level].flags & LVLFLAG_FINAL) { |
| 1571 |
max_level++; |
| 1572 |
break; |
| 1573 |
} |
| 1574 |
} |
| 1575 |
|
| 1576 |
if (Current_mission.cur_level > mission_to_use.highest_level && !IsCheater && |
| 1577 |
Current_mission.cur_level < max_level) { // cheaters don't win |
| 1578 |
ASSERT(!(Game_mode & GM_MULTI)); |
| 1579 |
mission_to_use.highest_level = Current_mission.cur_level; |
| 1580 |
mission_to_use.ship_permissions = Players[0].ship_permissions; |
| 1581 |
} |
| 1582 |
|
| 1583 |
// if we've reached end of mission, we've finished it. |
| 1584 |
if (Current_mission.cur_level == max_level) { |
| 1585 |
mission_to_use.finished = true; |
| 1586 |
} |
| 1587 |
|
| 1588 |
Current_pilot.edit_mission_data(index, &mission_to_use); |
| 1589 |
} |
| 1590 |
|
| 1591 |
PltWriteFile(&Current_pilot, false); |
| 1592 |
} |
| 1593 |
|
| 1594 |
// gets highest level flown for mission |
| 1595 |
int PilotGetHighestLevelAchieved(pilot *Pilot, char *mission_name) { |
| 1596 |
ASSERT(Pilot); |
| 1597 |
if (!Pilot) |
| 1598 |
return 1; |
| 1599 |
|
| 1600 |
int index = Pilot->find_mission_data(mission_name); |
| 1601 |
if (index == -1) |
| 1602 |
return 0; |
| 1603 |
|
| 1604 |
tMissionData data; |
| 1605 |
Pilot->get_mission_data(index, &data); |
| 1606 |
|
| 1607 |
return data.highest_level; |
| 1608 |
} |
| 1609 |
|
| 1610 |
// just like it says |
| 1611 |
bool HasPilotFinishedMission(pilot *Pilot, const char *mission_name) { |
| 1612 |
ASSERT(Pilot); |
| 1613 |
if (!Pilot) |
| 1614 |
return false; |
| 1615 |
|
| 1616 |
int index = Pilot->find_mission_data((char *)mission_name); |
| 1617 |
if (index == -1) |
| 1618 |
return false; |
| 1619 |
|
| 1620 |
tMissionData data; |
| 1621 |
Pilot->get_mission_data(index, &data); |
| 1622 |
return data.finished; |
| 1623 |
} |
| 1624 |
|
| 1625 |
bool HasPilotFlownMission(pilot *Pilot, const char *mission_name) { |
| 1626 |
ASSERT(Pilot); |
| 1627 |
if (!Pilot) |
| 1628 |
return false; |
| 1629 |
|
| 1630 |
int index = Pilot->find_mission_data((char *)mission_name); |
| 1631 |
if (index == -1) |
| 1632 |
return false; |
| 1633 |
return true; |
| 1634 |
} |
| 1635 |
|
| 1636 |
int GetPilotNumSavedGamesForMission(pilot *Pilot, const char *mission_name) { |
| 1637 |
ASSERT(Pilot); |
| 1638 |
if (!Pilot) |
| 1639 |
return 0; |
| 1640 |
|
| 1641 |
int index = Pilot->find_mission_data((char *)mission_name); |
| 1642 |
if (index == -1) |
| 1643 |
return 0; |
| 1644 |
|
| 1645 |
tMissionData data; |
| 1646 |
Pilot->get_mission_data(index, &data); |
| 1647 |
return data.num_saves; |
| 1648 |
} |
| 1649 |
|
| 1650 |
int GetPilotNumRestoredGamesForMission(pilot *Pilot, const char *mission_name) { |
| 1651 |
ASSERT(Pilot); |
| 1652 |
if (!Pilot) |
| 1653 |
return 0; |
| 1654 |
|
| 1655 |
int index = Pilot->find_mission_data((char *)mission_name); |
| 1656 |
if (index == -1) |
| 1657 |
return 0; |
| 1658 |
|
| 1659 |
tMissionData data; |
| 1660 |
Pilot->get_mission_data(index, &data); |
| 1661 |
return data.num_restores; |
| 1662 |
} |
| 1663 |
|
| 1664 |
void IncrementPilotSavedGamesForMission(pilot *Pilot, const char *mission_name) { |
| 1665 |
ASSERT(Pilot); |
| 1666 |
if (!Pilot) |
| 1667 |
return; |
| 1668 |
|
| 1669 |
int index = Pilot->find_mission_data((char *)mission_name); |
| 1670 |
if (index == -1) |
| 1671 |
return; |
| 1672 |
|
| 1673 |
tMissionData data; |
| 1674 |
Pilot->get_mission_data(index, &data); |
| 1675 |
data.num_saves++; |
| 1676 |
Pilot->edit_mission_data(index, &data); |
| 1677 |
|
| 1678 |
PltWriteFile(Pilot, false); |
| 1679 |
} |
| 1680 |
|
| 1681 |
void IncrementPilotRestoredGamesForMission(pilot *Pilot, const char *mission_name) { |
| 1682 |
ASSERT(Pilot); |
| 1683 |
if (!Pilot) |
| 1684 |
return; |
| 1685 |
|
| 1686 |
int index = Pilot->find_mission_data((char *)mission_name); |
| 1687 |
if (index == -1) |
| 1688 |
return; |
| 1689 |
|
| 1690 |
tMissionData data; |
| 1691 |
Pilot->get_mission_data(index, &data); |
| 1692 |
data.num_restores++; |
| 1693 |
Pilot->edit_mission_data(index, &data); |
| 1694 |
|
| 1695 |
PltWriteFile(Pilot, false); |
| 1696 |
} |
| 1697 |
|
| 1698 |
int GetPilotShipPermissions(pilot *Pilot, const char *mission_name) { |
| 1699 |
ASSERT(!(Game_mode & GM_MULTI)); |
| 1700 |
ASSERT(Pilot); |
| 1701 |
if (!Pilot) |
| 1702 |
return 1; |
| 1703 |
|
| 1704 |
int index = Pilot->find_mission_data((char *)mission_name); |
| 1705 |
if (index == -1) |
| 1706 |
return 0; |
| 1707 |
|
| 1708 |
tMissionData data; |
| 1709 |
Pilot->get_mission_data(index, &data); |
| 1710 |
|
| 1711 |
return data.ship_permissions; |
| 1712 |
} |
| 1713 |
|
| 1714 |
//////////////////////////////////////////////////////////////////////// |
| 1715 |
// Pilot file functions |
| 1716 |
//////////////////////////////////////////////////////////////////////// |
| 1717 |
///////////////////////////////////////////// |
| 1718 |
// deletes a pilot |
| 1719 |
bool PltDelete(pilot *Pilot) { |
| 1720 |
char filename[_MAX_PATH]; |
| 1721 |
char pfilename[_MAX_FNAME]; |
| 1722 |
char pname[PILOT_STRING_SIZE]; |
| 1723 |
|
| 1724 |
Pilot->get_filename(pfilename); |
| 1725 |
|
| 1726 |
if (pfilename[0] != 0) { |
| 1727 |
ddio_MakePath(filename, Base_directory_write, pfilename, NULL); |
| 1728 |
return (ddio_DeleteFile(pfilename) == 1); |
| 1729 |
} else { |
| 1730 |
Int3(); // this is odd |
| 1731 |
|
| 1732 |
// it shouldn't get to here, but if for some reason filename didn't exist |
| 1733 |
// then create the filename from the player name and delete the file |
| 1734 |
Pilot->get_name(pname); |
| 1735 |
|
| 1736 |
if (pname[0] == 0) |
| 1737 |
return false; |
| 1738 |
|
| 1739 |
PltMakeFNValid(pname); |
| 1740 |
|
| 1741 |
strcpy(pfilename, pname); |
| 1742 |
strcat(pfilename, PLTEXTENSION); |
| 1743 |
ddio_MakePath(filename, Base_directory_write, pfilename, NULL); |
| 1744 |
return (ddio_DeleteFile(filename) == 1); |
| 1745 |
} |
| 1746 |
} |
| 1747 |
|
| 1748 |
void PltCreateDedicatedServerPilot(pilot *Pilot) { |
| 1749 |
Pilot->clean(true); |
| 1750 |
Pilot->set_name("SERVER"); |
| 1751 |
} |
| 1752 |
|
| 1753 |
////////////////////////////////////////////// |
| 1754 |
// writes a pilot out to file |
| 1755 |
// make sure Pilot->filename and Pilot->name are filled in correctly!!!! |
| 1756 |
int PltWriteFile(pilot *Pilot, bool newpilot) { |
| 1757 |
if (Dedicated_server) |
| 1758 |
return PLTW_NO_ERROR; |
| 1759 |
|
| 1760 |
Pilot->write(); |
| 1761 |
return Pilot->flush(newpilot); |
| 1762 |
} |
| 1763 |
|
| 1764 |
//////////////////////////////////////////////////// |
| 1765 |
// reads in a pilot file (fill in pilot name to read in the struct before calling) |
| 1766 |
// Pilot->filename MUST be filled in (with .plt extension) |
| 1767 |
void _ReadOldPilotFile(pilot *Pilot, bool keyconfig, bool missiondata); |
| 1768 |
|
| 1769 |
void PltReadFile(pilot *Pilot, bool keyconfig, bool missiondata) { |
| 1770 |
if (Dedicated_server) { |
| 1771 |
PltCreateDedicatedServerPilot(Pilot); |
| 1772 |
return; |
| 1773 |
} |
| 1774 |
|
| 1775 |
char filename[_MAX_PATH]; |
| 1776 |
char pfilename[_MAX_FNAME]; |
| 1777 |
CFILE *file; |
| 1778 |
int filever; |
| 1779 |
|
| 1780 |
Pilot->get_filename(pfilename); |
| 1781 |
if (pfilename[0] == 0) |
| 1782 |
return; |
| 1783 |
|
| 1784 |
// open and process file |
| 1785 |
ddio_MakePath(filename, Base_directory_write, pfilename, NULL); |
| 1786 |
try { |
| 1787 |
file = cfopen(filename, "rb"); |
| 1788 |
if (!file) |
| 1789 |
return; |
| 1790 |
|
| 1791 |
filever = cf_ReadInt(file); |
| 1792 |
cfclose(file); |
| 1793 |
} catch (...) { |
| 1794 |
mprintf(0, "File exception has occured\n"); |
| 1795 |
Int3(); |
| 1796 |
Error(TXT_MAJORPLTERROR); |
| 1797 |
return; |
| 1798 |
} |
| 1799 |
|
| 1800 |
if (filever >= 0x20) { |
| 1801 |
// new pilot files! |
| 1802 |
int ret = Pilot->read(!keyconfig, !missiondata); |
| 1803 |
switch (ret) { |
| 1804 |
case PLTR_TOO_NEW: |
| 1805 |
Error(TXT_PLTFILETOONEW, pfilename); |
| 1806 |
break; |
| 1807 |
} |
| 1808 |
|
| 1809 |
return; |
| 1810 |
} else { |
| 1811 |
try { |
| 1812 |
_ReadOldPilotFile(Pilot, keyconfig, missiondata); |
| 1813 |
} catch (...) { |
| 1814 |
mprintf(0, "File exception has occured\n"); |
| 1815 |
Int3(); |
| 1816 |
Error(TXT_MAJORPLTERROR); |
| 1817 |
return; |
| 1818 |
} |
| 1819 |
} |
| 1820 |
} |
| 1821 |
|
| 1822 |
////////////////////////////////////////////////////////////// |
| 1823 |
// returns the filelist of pilots available |
| 1824 |
struct tPGetPilotStruct { |
| 1825 |
char *filename; |
| 1826 |
tPGetPilotStruct *next; |
| 1827 |
}; |
| 1828 |
static char **pltgetname_list = NULL; |
| 1829 |
static int pltgetname_count = 0; |
| 1830 |
|
| 1831 |
void PltGetPilotsFree(void) { |
| 1832 |
if (pltgetname_list) { |
| 1833 |
mem_free(pltgetname_list); |
| 1834 |
pltgetname_list = NULL; |
| 1835 |
} |
| 1836 |
pltgetname_count = 0; |
| 1837 |
} |
| 1838 |
|
| 1839 |
char **PltGetPilots(int *count, char *ignore_filename, int display_default_configs) { |
| 1840 |
static char **pname_list = NULL; |
| 1841 |
|
| 1842 |
char buffer[PLTFILELEN]; |
| 1843 |
char search[256]; |
| 1844 |
tPGetPilotStruct *root = NULL, *curr = NULL; |
| 1845 |
int loop = 1; |
| 1846 |
|
| 1847 |
if (display_default_configs == 1) |
| 1848 |
loop = 2; |
| 1849 |
|
| 1850 |
// clear list |
| 1851 |
PltClearList(); |
| 1852 |
PltGetPilotsFree(); |
| 1853 |
(*count) = 0; |
| 1854 |
root = NULL; |
| 1855 |
|
| 1856 |
for (int loop_count = 0; loop_count < loop; loop_count++) { |
| 1857 |
switch (display_default_configs) { |
| 1858 |
case 0: |
| 1859 |
ASSERT(loop_count == 0); |
| 1860 |
ddio_MakePath(search, Base_directory_write, PLTWILDCARD, NULL); |
| 1861 |
break; |
| 1862 |
case 1: |
| 1863 |
ddio_MakePath(search, Base_directory_write, (loop_count == 0) ? PLTWILDCARD : DPLTWILDCARD, NULL); |
| 1864 |
break; |
| 1865 |
case 2: |
| 1866 |
ASSERT(loop_count == 0); |
| 1867 |
ddio_MakePath(search, Base_directory_write, DPLTWILDCARD, NULL); |
| 1868 |
break; |
| 1869 |
default: |
| 1870 |
Int3(); |
| 1871 |
break; |
| 1872 |
} |
| 1873 |
|
| 1874 |
if (ddio_FindFileStart(search, buffer)) { |
| 1875 |
|
| 1876 |
if (ignore_filename && !stricmp(ignore_filename, buffer)) { |
| 1877 |
mprintf(0, "Getting Pilots...found %s, but ignoring\n", buffer); |
| 1878 |
} else { |
| 1879 |
if (root == NULL) { |
| 1880 |
root = curr = (tPGetPilotStruct *)mem_malloc(sizeof(tPGetPilotStruct)); |
| 1881 |
curr->next = NULL; |
| 1882 |
} else { |
| 1883 |
curr->next = (tPGetPilotStruct *)mem_malloc(sizeof(tPGetPilotStruct)); |
| 1884 |
curr = curr->next; |
| 1885 |
curr->next = NULL; |
| 1886 |
} |
| 1887 |
|
| 1888 |
if (curr) { |
| 1889 |
curr->filename = mem_strdup(buffer); |
| 1890 |
|
| 1891 |
if (curr->filename) { |
| 1892 |
(*count)++; |
| 1893 |
mprintf(0, "Getting Pilots..found %s\n", buffer); |
| 1894 |
} else { |
| 1895 |
Error(TXT_OUTOFMEMORY); |
| 1896 |
} |
| 1897 |
} |
| 1898 |
} |
| 1899 |
|
| 1900 |
while (ddio_FindNextFile(buffer)) { |
| 1901 |
if (ignore_filename && !stricmp(ignore_filename, buffer)) { |
| 1902 |
mprintf(0, "Getting Pilots...found %s, but ignoring\n", buffer); |
| 1903 |
} else { |
| 1904 |
if (root == NULL) { |
| 1905 |
root = curr = (tPGetPilotStruct *)mem_malloc(sizeof(tPGetPilotStruct)); |
| 1906 |
curr->next = NULL; |
| 1907 |
} else { |
| 1908 |
curr->next = (tPGetPilotStruct *)mem_malloc(sizeof(tPGetPilotStruct)); |
| 1909 |
curr = curr->next; |
| 1910 |
curr->next = NULL; |
| 1911 |
} |
| 1912 |
|
| 1913 |
if (curr) { |
| 1914 |
curr->filename = mem_strdup(buffer); |
| 1915 |
|
| 1916 |
if (curr->filename) { |
| 1917 |
(*count)++; |
| 1918 |
mprintf(0, "Getting Pilots..found %s\n", buffer); |
| 1919 |
} else { |
| 1920 |
Error(TXT_OUTOFMEMORY); |
| 1921 |
} |
| 1922 |
} |
| 1923 |
} |
| 1924 |
} |
| 1925 |
} |
| 1926 |
|
| 1927 |
ddio_FindFileClose(); |
| 1928 |
} |
| 1929 |
|
| 1930 |
// now allocate for the real list of char * and move the linked list to that array |
| 1931 |
if ((*count) > 0) { |
| 1932 |
pltgetname_list = (char **)mem_malloc((*count) * sizeof(char *)); |
| 1933 |
if (pltgetname_list) { |
| 1934 |
int end = (*count); |
| 1935 |
curr = root; |
| 1936 |
tPGetPilotStruct *next; |
| 1937 |
|
| 1938 |
for (int i = 0; i < end; i++) { |
| 1939 |
// move all the allocated buffers to this list, than we can free the node |
| 1940 |
next = curr->next; |
| 1941 |
|
| 1942 |
if (curr) { |
| 1943 |
pltgetname_list[i] = curr->filename; |
| 1944 |
} else { |
| 1945 |
pltgetname_list[i] = NULL; |
| 1946 |
} |
| 1947 |
|
| 1948 |
mem_free(curr); |
| 1949 |
curr = next; |
| 1950 |
} |
| 1951 |
} |
| 1952 |
} |
| 1953 |
pltgetname_count = (*count); |
| 1954 |
|
| 1955 |
mprintf(0, "Found %d pilots\n", (*count)); |
| 1956 |
return pltgetname_list; |
| 1957 |
} |
| 1958 |
|
| 1959 |
/////////////////////////////////////////////////////////// |
| 1960 |
// clears the file list (MUST CALL TO FREE MEMORY!!!!!!!!!) |
| 1961 |
void PltClearList(void) { |
| 1962 |
if (!pltgetname_list) |
| 1963 |
return; |
| 1964 |
|
| 1965 |
int index; |
| 1966 |
|
| 1967 |
for (index = 0; index < pltgetname_count; index++) { |
| 1968 |
if (pltgetname_list[index]) { |
| 1969 |
mem_free(pltgetname_list[index]); |
| 1970 |
pltgetname_list[index] = NULL; |
| 1971 |
} |
| 1972 |
} |
| 1973 |
} |
| 1974 |
|
| 1975 |
//////////////////////////////////////////////////////////// |
| 1976 |
// given a name, it will create a valid filename |
| 1977 |
void PltMakeFNValid(char *name) { |
| 1978 |
int whiteindex; |
| 1979 |
int end = strlen(name); |
| 1980 |
|
| 1981 |
for (whiteindex = 0; whiteindex < end; whiteindex++) { |
| 1982 |
// remove illegal character (sub _ in place) |
| 1983 |
switch (name[whiteindex]) { |
| 1984 |
case '?': |
| 1985 |
case '*': |
| 1986 |
case '\\': |
| 1987 |
case '/': |
| 1988 |
case '|': |
| 1989 |
case '<': |
| 1990 |
case '>': |
| 1991 |
case ':': |
| 1992 |
case '"': |
| 1993 |
name[whiteindex] = '_'; |
| 1994 |
break; |
| 1995 |
default: |
| 1996 |
break; |
| 1997 |
} |
| 1998 |
} |
| 1999 |
|
| 2000 |
// remove leading whitespace |
| 2001 |
whiteindex = 0; |
| 2002 |
while (name[whiteindex] == ' ') |
| 2003 |
whiteindex++; |
| 2004 |
|
| 2005 |
char temp[PLTFILELEN]; |
| 2006 |
strcpy(temp, &name[whiteindex]); |
| 2007 |
strcpy(name, temp); |
| 2008 |
} |
| 2009 |
|
| 2010 |
//////////////////////////////////////////////////////// |
| 2011 |
// Copies the key/joy config of a pilot to another (src must exist!) (Keep up to date with Read/Write file) |
| 2012 |
// this will also save out the dest, so make sure its filled in before calling function |
| 2013 |
bool PltCopyKeyConfig(pilot *src, pilot *dest) { |
| 2014 |
// check to make sure src exists |
| 2015 |
ASSERT(src); |
| 2016 |
ASSERT(dest); |
| 2017 |
|
| 2018 |
char pname[PILOT_STRING_SIZE]; |
| 2019 |
src->get_name(pname); |
| 2020 |
|
| 2021 |
if ((pname[0] != 0) && (strlen(pname) > 0) && (strcmp(pname, " ") != 0)) { |
| 2022 |
int i; |
| 2023 |
for (i = 0; i < NUM_CONTROLLER_FUNCTIONS; i++) { |
| 2024 |
dest->controls[i].id = src->controls[i].id; |
| 2025 |
dest->controls[i].type[0] = src->controls[i].type[0]; |
| 2026 |
dest->controls[i].type[1] = src->controls[i].type[1]; |
| 2027 |
dest->controls[i].value = src->controls[i].value; |
| 2028 |
dest->controls[i].flags[0] = src->controls[i].flags[0]; |
| 2029 |
dest->controls[i].flags[1] = src->controls[i].flags[1]; |
| 2030 |
} |
| 2031 |
for (i = 0; i < N_MOUSE_AXIS; i++) { |
| 2032 |
dest->mouse_sensitivity[i] = src->mouse_sensitivity[i]; |
| 2033 |
} |
| 2034 |
for (i = 0; i < N_JOY_AXIS; i++) { |
| 2035 |
dest->joy_sensitivity[i] = src->joy_sensitivity[i]; |
| 2036 |
} |
| 2037 |
dest->key_ramping = src->key_ramping; |
| 2038 |
dest->read_controller = src->read_controller; |
| 2039 |
dest->mouselook_control = src->mouselook_control; |
| 2040 |
|
| 2041 |
return true; |
| 2042 |
} else |
| 2043 |
return false; |
| 2044 |
} |
| 2045 |
|
| 2046 |
/* |
| 2047 |
************************************************************************ |
| 2048 |
* The following section is for the multiplayer ship selection * |
| 2049 |
* and configuration. * |
| 2050 |
************************************************************************ |
| 2051 |
* |
| 2052 |
*/ |
| 2053 |
|
| 2054 |
// UI3DWindow class |
| 2055 |
// |
| 2056 |
// UI class for displaying a polymodel on the UIWindow, rotating 30 deg/sec |
| 2057 |
class UI3DWindow : public UIStatic { |
| 2058 |
public: |
| 2059 |
void OnDraw(void); |
| 2060 |
}; |
| 2061 |
|
| 2062 |
// UIBmpWindow class |
| 2063 |
// |
| 2064 |
// UI class for displaying a bitmap on a UIWindow |
| 2065 |
class UIBmpWindow : public UIStatic { |
| 2066 |
public: |
| 2067 |
UIBmpWindow(); |
| 2068 |
~UIBmpWindow(); |
| 2069 |
void SetInfo(bool animated, int handle); |
| 2070 |
void OnDraw(void); |
| 2071 |
|
| 2072 |
private: |
| 2073 |
void DrawBorder(void); |
| 2074 |
bool animated; |
| 2075 |
int bm_handle; |
| 2076 |
float start_time; |
| 2077 |
UIText text; |
| 2078 |
bool created; |
| 2079 |
}; |
| 2080 |
|
| 2081 |
// struct ship_pos |
| 2082 |
// |
| 2083 |
// contains information about the ship to be displayed in the ship configuration |
| 2084 |
struct tShipPos { |
| 2085 |
matrix last_frame; |
| 2086 |
float cam_dist; |
| 2087 |
float last_time; |
| 2088 |
bool texture_changed; |
| 2089 |
int texture_type; |
| 2090 |
int texture_id; |
| 2091 |
int bm_handle; |
| 2092 |
void Init() { |
| 2093 |
vm_AnglesToMatrix(&last_frame, 0, (65535 / 2), 0); |
| 2094 |
last_time = timer_GetTime(); |
| 2095 |
texture_id = Players[0].custom_texture_handle; |
| 2096 |
bm_handle = -1; |
| 2097 |
} |
| 2098 |
}; |
| 2099 |
|
| 2100 |
tShipPos ship_pos; |
| 2101 |
int ship_model = -1; |
| 2102 |
char custom_texture[_MAX_PATH]; |
| 2103 |
UIBmpWindow *bmpwindow; |
| 2104 |
|
| 2105 |
struct tShipListInfo { |
| 2106 |
int *idlist; // array of remapping indicies (list index->ship index) |
| 2107 |
void Init() { idlist = NULL; } |
| 2108 |
void Reset() { |
| 2109 |
if (idlist) { |
| 2110 |
mem_free(idlist); |
| 2111 |
idlist = NULL; |
| 2112 |
} |
| 2113 |
} |
| 2114 |
}; |
| 2115 |
|
| 2116 |
tCustomListInfo *lp_cust_bmps = NULL; |
| 2117 |
tShipListInfo *lp_ship_info = NULL; |
| 2118 |
|
| 2119 |
// axtoi |
| 2120 |
// |
| 2121 |
// Convert a string that represents a hex value into an int (like atoi) |
| 2122 |
int axtoi(char *p) { |
| 2123 |
int value = 0; |
| 2124 |
|
| 2125 |
while ((p) && (*p)) { |
| 2126 |
*p = toupper(*p); |
| 2127 |
if ((*p >= '0') && (*p <= '9')) |
| 2128 |
value = (value * 16) + ((*p) - '0'); |
| 2129 |
else if ((*p >= 'A') && (*p <= 'F')) |
| 2130 |
value = (value * 16) + (((*p) - 'A') + 10); |
| 2131 |
else |
| 2132 |
return 0; |
| 2133 |
p++; |
| 2134 |
} |
| 2135 |
return value; |
| 2136 |
} |
| 2137 |
|
| 2138 |
// StripCRCFileName |
| 2139 |
// |
| 2140 |
// Given a filename that has the _<CRC> in it at the end of the name, it will fill |
| 2141 |
// in dest with just the filename part (without the trailing _<CRC>). |
| 2142 |
void StripCRCFileName(const char *src, char *dest) { |
| 2143 |
ASSERT(src); |
| 2144 |
ASSERT(dest); |
| 2145 |
|
| 2146 |
int full_strlen = strlen(src); |
| 2147 |
char ext[256]; |
| 2148 |
ddio_SplitPath(src, NULL, NULL, ext); |
| 2149 |
int extstrlen = strlen(ext); |
| 2150 |
int eon = full_strlen - 9 - extstrlen; |
| 2151 |
|
| 2152 |
if (eon < 1) { |
| 2153 |
// this filename doesn't have a trailing CRC |
| 2154 |
strcpy(dest, src); |
| 2155 |
return; |
| 2156 |
} |
| 2157 |
|
| 2158 |
// check to make sure the [eon] is '_' |
| 2159 |
if (src[eon] != '_') { |
| 2160 |
// it wasn't so it must not have a CRC at the end |
| 2161 |
strcpy(dest, src); |
| 2162 |
return; |
| 2163 |
} |
| 2164 |
|
| 2165 |
char hexstring[9]; |
| 2166 |
strncpy(hexstring, &src[eon + 1], 8); |
| 2167 |
hexstring[8] = '\0'; |
| 2168 |
uint32_t crc; |
| 2169 |
crc = axtoi(hexstring); |
| 2170 |
|
| 2171 |
if (crc == 0) { |
| 2172 |
// crc can't be 0? |
| 2173 |
strcpy(dest, src); |
| 2174 |
return; |
| 2175 |
} |
| 2176 |
|
| 2177 |
// strip the filename |
| 2178 |
strncpy(dest, src, eon); |
| 2179 |
dest[eon] = '\0'; |
| 2180 |
strcat(dest, ext); // put back the extension |
| 2181 |
} |
| 2182 |
|
| 2183 |
// CreateCRCFileName |
| 2184 |
// |
| 2185 |
// Given a filename, this function will open the file, make a CRC of the data |
| 2186 |
// and then fill in dest buffer with <filename>_<CRC> where <filename> is the |
| 2187 |
// original filename and <CRC> is the converted string of the CRC in hex. |
| 2188 |
// returns true on success. |
| 2189 |
// dest should be size of src + 9 (for the _ & CRC) |
| 2190 |
bool CreateCRCFileName(const char *src, char *dest) { |
| 2191 |
ASSERT(src); |
| 2192 |
ASSERT(dest); |
| 2193 |
|
| 2194 |
if (cfexist(src) != CFES_ON_DISK) |
| 2195 |
return false; |
| 2196 |
|
| 2197 |
uint32_t crc_value = cf_GetfileCRC((char *)src); |
| 2198 |
if (crc_value == 0) { |
| 2199 |
mprintf(0, "CRC WARNING: A CRC of 0 HAS BEEN GENERATED!\n"); |
| 2200 |
} |
| 2201 |
char hex_string[10]; |
| 2202 |
snprintf(hex_string, sizeof(hex_string), "_%08X", crc_value); |
| 2203 |
|
| 2204 |
char ext[256]; |
| 2205 |
ddio_SplitPath(src, NULL, NULL, ext); |
| 2206 |
|
| 2207 |
// now create the full filename |
| 2208 |
// first strip any possible CRC on the file |
| 2209 |
StripCRCFileName(src, dest); |
| 2210 |
dest[strlen(dest) - strlen(ext)] = '\0'; // lose the extension |
| 2211 |
strcat(dest, hex_string); |
| 2212 |
strcat(dest, ext); // put extension back |
| 2213 |
|
| 2214 |
return true; |
| 2215 |
} |
| 2216 |
|
| 2217 |
// CreateCRCFileName |
| 2218 |
// |
| 2219 |
// Given a file, a new filename, it will take the src file, create a new filename, with base as the base |
| 2220 |
bool CreateCRCFileName(const char *src, char *base, char *newfilename) { |
| 2221 |
ASSERT(src); |
| 2222 |
ASSERT(base); |
| 2223 |
ASSERT(newfilename); |
| 2224 |
|
| 2225 |
if (cfexist(src) != CFES_ON_DISK) |
| 2226 |
return false; |
| 2227 |
|
| 2228 |
uint32_t crc_value = cf_GetfileCRC((char *)src); |
| 2229 |
if (crc_value == 0) { |
| 2230 |
mprintf(0, "CRC WARNING: A CRC of 0 HAS BEEN GENERATED!\n"); |
| 2231 |
} |
| 2232 |
char hex_string[10]; |
| 2233 |
snprintf(hex_string, sizeof(hex_string), "_%08X", crc_value); |
| 2234 |
|
| 2235 |
char ext[256]; |
| 2236 |
ddio_SplitPath(base, NULL, NULL, ext); |
| 2237 |
|
| 2238 |
// now create the full filename |
| 2239 |
// first strip any possible CRC on the file |
| 2240 |
strcpy(newfilename, base); |
| 2241 |
newfilename[strlen(newfilename) - strlen(ext)] = '\0'; // lose the extension |
| 2242 |
strcat(newfilename, hex_string); |
| 2243 |
strcat(newfilename, ext); // put extension back |
| 2244 |
|
| 2245 |
return true; |
| 2246 |
} |
| 2247 |
|
| 2248 |
// FindAllFiles |
| 2249 |
// |
| 2250 |
// Retrieves the files in the current directory that match the pattern given. Call FindAllFilesSize() to |
| 2251 |
// determine how much memory will be needed for the buffer. pattern = wildcard pattern to use to match |
| 2252 |
// list = buffer of memory that will be filled in with the filenames (each seperated by a \0) |
| 2253 |
// size = size of memory allocated for list parm |
| 2254 |
// filecount = filled in with the number of files it found |
| 2255 |
int FindAllFiles(const char *pattern, char *list, int size, int *filecount) { |
| 2256 |
int count = 0; |
| 2257 |
char filename[_MAX_PATH]; |
| 2258 |
*filecount = 0; |
| 2259 |
int memory = 0; |
| 2260 |
|
| 2261 |
if (size <= 0) |
| 2262 |
return 0; |
| 2263 |
if (!list) |
| 2264 |
return 0; |
| 2265 |
if (!pattern) |
| 2266 |
return 0; |
| 2267 |
|
| 2268 |
if (ddio_FindFileStart(pattern, filename)) { |
| 2269 |
count++; |
| 2270 |
strcpy(&list[memory], filename); |
| 2271 |
memory += strlen(&list[memory]) + 1; |
| 2272 |
while ((count < size) && (ddio_FindNextFile(filename))) { |
| 2273 |
strcpy(&list[memory], filename); |
| 2274 |
memory += strlen(&list[memory]) + 1; |
| 2275 |
count++; |
| 2276 |
} |
| 2277 |
} |
| 2278 |
ddio_FindFileClose(); |
| 2279 |
*filecount = count; |
| 2280 |
return memory; |
| 2281 |
} |
| 2282 |
|
| 2283 |
// FindAllFilesSize |
| 2284 |
// |
| 2285 |
// Looks in the current directory and returns the number of bytes of memory that will be needed |
| 2286 |
// for a buffer of filenames (see FindAllFiles()). |
| 2287 |
// pattern = wildcard pattern to match |
| 2288 |
// filecount = will be filled in with the number of files it finds |
| 2289 |
int FindAllFilesSize(const char *pattern, int *filecount) { |
| 2290 |
if (!pattern) { |
| 2291 |
*filecount = 0; |
| 2292 |
return 0; |
| 2293 |
} |
| 2294 |
|
| 2295 |
char filename[_MAX_PATH]; |
| 2296 |
int size = 0; |
| 2297 |
int count = 0; |
| 2298 |
|
| 2299 |
if (ddio_FindFileStart(pattern, filename)) { |
| 2300 |
count++; |
| 2301 |
size += strlen(filename) + 1; |
| 2302 |
while (ddio_FindNextFile(filename)) { |
| 2303 |
count++; |
| 2304 |
size += strlen(filename) + 1; |
| 2305 |
} |
| 2306 |
ddio_FindFileClose(); |
| 2307 |
} |
| 2308 |
*filecount = count; |
| 2309 |
return size; |
| 2310 |
} |
| 2311 |
|
| 2312 |
// returns the optimal distance to place the camera |
| 2313 |
float getdist(angle ang, float height) { |
| 2314 |
float s, c, t; |
| 2315 |
vm_SinCos(ang, &s, &c); |
| 2316 |
t = s / c; |
| 2317 |
return (height / t); |
| 2318 |
} |
| 2319 |
|
| 2320 |
// ImportGraphic |
| 2321 |
// |
| 2322 |
// Takes the graphics file at the given location and imports it into the custom\graphics dir as an scaled ogf |
| 2323 |
// pathname = full path to source bitmap |
| 2324 |
// newfile = on return true is the filename of the new bitmap |
| 2325 |
bool ImportGraphic(char *pathname, char *newfile) { |
| 2326 |
ASSERT(pathname); |
| 2327 |
if (cfexist(pathname) != CFES_ON_DISK) { |
| 2328 |
mprintf(0, "'%s' not found\n", pathname); |
| 2329 |
return false; |
| 2330 |
} |
| 2331 |
|
| 2332 |
int bm_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE(pathname), 0); |
| 2333 |
if (bm_handle <= BAD_BITMAP_HANDLE) { |
| 2334 |
return false; |
| 2335 |
} |
| 2336 |
|
| 2337 |
bm_ChangeSize(bm_handle, 64, 64); |
| 2338 |
|
| 2339 |
char p[_MAX_PATH]; |
| 2340 |
char filename[_MAX_FNAME], ext[_MAX_EXT]; |
| 2341 |
char tempfilename[_MAX_PATH]; |
| 2342 |
|
| 2343 |
// Create a temporary filename, so that we can temporarily save the graphic to this file |
| 2344 |
if (!ddio_GetTempFileName(Descent3_temp_directory, "d3i", tempfilename)) { |
| 2345 |
// there was an error trying to create a temporary filename |
| 2346 |
bm_FreeBitmap(bm_handle); |
| 2347 |
mprintf(0, "Error creating temp filename\n"); |
| 2348 |
return false; |
| 2349 |
} |
| 2350 |
|
| 2351 |
// save out the file |
| 2352 |
if (bm_SaveFileBitmap(tempfilename, bm_handle) == -1) { |
| 2353 |
mprintf(0, "Error importing\n"); |
| 2354 |
bm_FreeBitmap(bm_handle); |
| 2355 |
return false; |
| 2356 |
} |
| 2357 |
|
| 2358 |
bm_FreeBitmap(bm_handle); |
| 2359 |
|
| 2360 |
// when we get here we have an .ogf file saved out as tempfilename, we need to load it back up |
| 2361 |
char blah[_MAX_PATH]; |
| 2362 |
StripCRCFileName(pathname, blah); // make sure all CRC are out of the filename |
| 2363 |
ddio_SplitPath(blah, NULL, filename, ext); |
| 2364 |
if (!CreateCRCFileName(tempfilename, filename, p)) { |
| 2365 |
mprintf(0, "Error creating CRC File\n"); |
| 2366 |
ddio_DeleteFile(tempfilename); |
| 2367 |
return false; |
| 2368 |
} |
| 2369 |
|
| 2370 |
strcpy(filename, p); |
| 2371 |
strcat(filename, ".ogf"); |
| 2372 |
|
| 2373 |
ddio_MakePath(p, LocalCustomGraphicsDir, filename, NULL); |
| 2374 |
|
| 2375 |
// p contains the real filename |
| 2376 |
// tempfilename contains old filename |
| 2377 |
bm_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE(tempfilename), 0); |
| 2378 |
if (bm_handle <= BAD_BITMAP_HANDLE) { |
| 2379 |
mprintf(0, "Error reloading bitmap for rename\n"); |
| 2380 |
ddio_DeleteFile(tempfilename); |
| 2381 |
return false; |
| 2382 |
} |
| 2383 |
|
| 2384 |
if (bm_SaveFileBitmap(p, bm_handle) == -1) { |
| 2385 |
mprintf(0, "Error importing\n"); |
| 2386 |
bm_FreeBitmap(bm_handle); |
| 2387 |
ddio_DeleteFile(tempfilename); |
| 2388 |
return false; |
| 2389 |
} |
| 2390 |
|
| 2391 |
bm_FreeBitmap(bm_handle); |
| 2392 |
ddio_DeleteFile(tempfilename); |
| 2393 |
|
| 2394 |
strcpy(newfile, p); |
| 2395 |
return true; |
| 2396 |
} |
| 2397 |
|
| 2398 |
// UpdateGraphicsListbox |
| 2399 |
// |
| 2400 |
// Updates the listbox that contains the custom textures. Make sure all double-pointer arguments passes in |
| 2401 |
// are set to NULL is they don't have memory allocated for them yet, because if they're not null this function |
| 2402 |
// will try to free up their memory |
| 2403 |
bool UpdateGraphicsListbox(tCustomListInfo *cust_bmps, newuiListBox *lb, char *selected_name) { |
| 2404 |
ASSERT(lb); |
| 2405 |
lb->RemoveAll(); |
| 2406 |
|
| 2407 |
cust_bmps->Reset(); |
| 2408 |
cust_bmps->custom_bitmap_list = lb; |
| 2409 |
|
| 2410 |
// get a list of custom textures |
| 2411 |
int count = 0; |
| 2412 |
bool ok_to_get_files; |
| 2413 |
int total_files = 0; |
| 2414 |
|
| 2415 |
// build list |
| 2416 |
char oldpath[_MAX_PATH]; |
| 2417 |
|
| 2418 |
ddio_GetWorkingDir(oldpath, _MAX_PATH); |
| 2419 |
|
| 2420 |
if (ddio_SetWorkingDir(LocalCustomGraphicsDir)) |
| 2421 |
ok_to_get_files = true; |
| 2422 |
else |
| 2423 |
ok_to_get_files = false; |
| 2424 |
|
| 2425 |
if (ok_to_get_files) { |
| 2426 |
// Get all the filenames |
| 2427 |
int totalsize, size; |
| 2428 |
int count, totalcount; |
| 2429 |
|
| 2430 |
//.oaf |
| 2431 |
//.ogf |
| 2432 |
count = totalcount = totalsize = total_files = 0; |
| 2433 |
|
| 2434 |
totalsize += FindAllFilesSize("*.oaf", &count); |
| 2435 |
totalcount += count; |
| 2436 |
totalsize += FindAllFilesSize("*.ogf", &count); |
| 2437 |
totalcount += count; |
| 2438 |
|
| 2439 |
if (totalsize) { |
| 2440 |
cust_bmps->needed_size = totalsize; |
| 2441 |
total_files = totalcount; |
| 2442 |
cust_bmps->files = (char *)mem_malloc(totalsize); |
| 2443 |
if (cust_bmps->files) { |
| 2444 |
size = 0; |
| 2445 |
count = 0; |
| 2446 |
|
| 2447 |
size += FindAllFiles("*.oaf", &cust_bmps->files[size], totalcount, &count); |
| 2448 |
totalcount -= count; |
| 2449 |
size += FindAllFiles("*.ogf", &cust_bmps->files[size], totalcount, &count); |
| 2450 |
totalcount -= count; |
| 2451 |
} else |
| 2452 |
mprintf(0, "Unable to allocate memory for %d bytes\n", totalsize); |
| 2453 |
} |
| 2454 |
} |
| 2455 |
|
| 2456 |
count = total_files + 1; // make room for "None" |
| 2457 |
|
| 2458 |
char chosen_name[256], ext[256]; |
| 2459 |
if (selected_name) { |
| 2460 |
ddio_SplitPath(selected_name, NULL, chosen_name, ext); |
| 2461 |
strcat(chosen_name, ext); |
| 2462 |
} else { |
| 2463 |
*chosen_name = '\0'; |
| 2464 |
} |
| 2465 |
|
| 2466 |
// default "None" |
| 2467 |
lb->AddItem(TXT_LBNONE); |
| 2468 |
|
| 2469 |
int memory_used; |
| 2470 |
memory_used = 0; |
| 2471 |
for (int i = 1; i < count; i++) { |
| 2472 |
char tempf[_MAX_PATH]; |
| 2473 |
StripCRCFileName(&cust_bmps->files[memory_used], tempf); |
| 2474 |
lb->AddItem(tempf); |
| 2475 |
if (!stricmp(&cust_bmps->files[memory_used], chosen_name)) { |
| 2476 |
lb->SetCurrentIndex(i); |
| 2477 |
CustomCallBack(i); |
| 2478 |
} |
| 2479 |
|
| 2480 |
memory_used += strlen(&cust_bmps->files[memory_used]) + 1; |
| 2481 |
} |
| 2482 |
|
| 2483 |
// If we are not forcing a selection, choose none |
| 2484 |
if (*chosen_name == '\0') { |
| 2485 |
lb->SetCurrentIndex(0); |
| 2486 |
CustomCallBack(0); |
| 2487 |
} |
| 2488 |
|
| 2489 |
ddio_SetWorkingDir(oldpath); |
| 2490 |
return true; |
| 2491 |
} |
| 2492 |
|
| 2493 |
// GetCustomSoundFiles |
| 2494 |
// |
| 2495 |
// Looks in the custom/sound directory and retrieves all the wav files in there. Returns the size of the buffer |
| 2496 |
// needed to get all the needed files. The filenames are stored in the buffer, seperated by \0, use count to |
| 2497 |
// determine how many were placed in the buffer |
| 2498 |
// |
| 2499 |
// buffer = Your buffer passed in, if this is NULL then it just returns a buffer size that is needed |
| 2500 |
// size = Size of your buffer passed in |
| 2501 |
// *count = filled in with the number of files that were placed into your buffer |
| 2502 |
int GetCustomSoundFiles(char *buffer = NULL, int size = 0, int *count = NULL); |
| 2503 |
int GetCustomSoundFiles(char *buffer, int size, int *count) { |
| 2504 |
int c = 0; |
| 2505 |
int isize = 0; |
| 2506 |
int len, overallsize = 0; |
| 2507 |
char tempname[_MAX_PATH]; |
| 2508 |
char oldpath[_MAX_PATH]; |
| 2509 |
ddio_GetWorkingDir(oldpath, _MAX_PATH); |
| 2510 |
ddio_SetWorkingDir(LocalCustomSoundsDir); |
| 2511 |
|
| 2512 |
if (!buffer) |
| 2513 |
size = 0; |
| 2514 |
|
| 2515 |
if (count) |
| 2516 |
*count = 0; |
| 2517 |
|
| 2518 |
if (ddio_FindFileStart("*.osf", tempname)) { |
| 2519 |
len = strlen(tempname); |
| 2520 |
overallsize += len + 1; |
| 2521 |
if (isize + len < size) { |
| 2522 |
strcpy(buffer, tempname); |
| 2523 |
isize += len + 1; |
| 2524 |
c++; |
| 2525 |
} |
| 2526 |
|
| 2527 |
while (ddio_FindNextFile(tempname)) { |
| 2528 |
len = strlen(tempname); |
| 2529 |
overallsize += len + 1; |
| 2530 |
if (isize + len < size) { |
| 2531 |
strcpy(&buffer[isize], tempname); |
| 2532 |
isize += len + 1; |
| 2533 |
c++; |
| 2534 |
} |
| 2535 |
} |
| 2536 |
} |
| 2537 |
ddio_FindFileClose(); |
| 2538 |
ddio_SetWorkingDir(oldpath); |
| 2539 |
if (count) |
| 2540 |
*count = c; |
| 2541 |
return overallsize; |
| 2542 |
} |
| 2543 |
|
| 2544 |
// GetStringInList |
| 2545 |
// |
| 2546 |
// Returns a pointer to the string in a string list (<string1>\0<string2>\0...). Be VERY careful that |
| 2547 |
// the index you pass in is a valid string index |
| 2548 |
// index = Index of string you want |
| 2549 |
// list = string list (a bunch of strings, seperated by \0) |
| 2550 |
// maxsize = size of string list buffer |
| 2551 |
// returns NULL on error (if an error can be detected) |
| 2552 |
char *GetStringInList(int index, char *list, int maxsize) { |
| 2553 |
int count = 0; |
| 2554 |
int p = 0; |
| 2555 |
char *pp; |
| 2556 |
pp = list; |
| 2557 |
|
| 2558 |
while (1) { |
| 2559 |
if (count == index) |
| 2560 |
return pp; |
| 2561 |
|
| 2562 |
if (p < maxsize) { |
| 2563 |
if (*pp == '\0') |
| 2564 |
count++; |
| 2565 |
} else |
| 2566 |
return NULL; |
| 2567 |
p++; |
| 2568 |
pp++; |
| 2569 |
} |
| 2570 |
return NULL; |
| 2571 |
} |
| 2572 |
|
| 2573 |
// UpdateAudioTauntBoxes |
| 2574 |
// |
| 2575 |
// Resets and updates the list of audio taunt combo boxes |
| 2576 |
void UpdateAudioTauntBoxes(tCustomListInfo *cust_snds, newuiComboBox *audio1_list, newuiComboBox *audio2_list, |
| 2577 |
newuiComboBox *audio3_list, newuiComboBox *audio4_list, pilot *Pilot) { |
| 2578 |
ASSERT(audio1_list); |
| 2579 |
ASSERT(audio2_list); |
| 2580 |
|
| 2581 |
audio1_list->RemoveAll(); |
| 2582 |
audio2_list->RemoveAll(); |
| 2583 |
audio3_list->RemoveAll(); |
| 2584 |
audio4_list->RemoveAll(); |
| 2585 |
|
| 2586 |
// free up allocated memory |
| 2587 |
cust_snds->Reset(); |
| 2588 |
|
| 2589 |
// Get all the audio files and put them into the lists |
| 2590 |
cust_snds->needed_size = GetCustomSoundFiles(); |
| 2591 |
if (cust_snds->needed_size) |
| 2592 |
cust_snds->files = (char *)mem_malloc(cust_snds->needed_size); |
| 2593 |
else |
| 2594 |
cust_snds->files = NULL; |
| 2595 |
|
| 2596 |
int audio_count; |
| 2597 |
|
| 2598 |
GetCustomSoundFiles(cust_snds->files, cust_snds->needed_size, &audio_count); |
| 2599 |
|
| 2600 |
int len; |
| 2601 |
|
| 2602 |
// Add <None> to both boxes |
| 2603 |
audio1_list->AddItem(TXT_LBNONE); |
| 2604 |
audio2_list->AddItem(TXT_LBNONE); |
| 2605 |
audio3_list->AddItem(TXT_LBNONE); |
| 2606 |
audio4_list->AddItem(TXT_LBNONE); |
| 2607 |
|
| 2608 |
int count = 0; |
| 2609 |
|
| 2610 |
char paudio1[PAGENAME_LEN], paudio2[PAGENAME_LEN]; |
| 2611 |
char paudio3[PAGENAME_LEN], paudio4[PAGENAME_LEN]; |
| 2612 |
Pilot->get_multiplayer_data(NULL, paudio1, paudio2, NULL, paudio3, paudio4); |
| 2613 |
|
| 2614 |
for (int i = 0; i < audio_count; i++) { |
| 2615 |
char tfn[_MAX_PATH]; |
| 2616 |
len = strlen(&cust_snds->files[count]); |
| 2617 |
StripCRCFileName(&cust_snds->files[count], tfn); |
| 2618 |
|
| 2619 |
audio1_list->AddItem((char *)(tfn)); |
| 2620 |
audio2_list->AddItem((char *)(tfn)); |
| 2621 |
audio3_list->AddItem((char *)(tfn)); |
| 2622 |
audio4_list->AddItem((char *)(tfn)); |
| 2623 |
|
| 2624 |
if (!stricmp(paudio1, &cust_snds->files[count])) { |
| 2625 |
// set this as selected index for audio #1 |
| 2626 |
audio1_list->SetCurrentIndex(i + 1); |
| 2627 |
} |
| 2628 |
if (!stricmp(paudio2, &cust_snds->files[count])) { |
| 2629 |
// set this as selected index for audio #2 |
| 2630 |
audio2_list->SetCurrentIndex(i + 1); |
| 2631 |
} |
| 2632 |
if (!stricmp(paudio3, &cust_snds->files[count])) { |
| 2633 |
// set this as selected index for audio #1 |
| 2634 |
audio3_list->SetCurrentIndex(i + 1); |
| 2635 |
} |
| 2636 |
if (!stricmp(paudio4, &cust_snds->files[count])) { |
| 2637 |
// set this as selected index for audio #2 |
| 2638 |
audio4_list->SetCurrentIndex(i + 1); |
| 2639 |
} |
| 2640 |
count += len + 1; |
| 2641 |
} |
| 2642 |
} |
| 2643 |
|
| 2644 |
pilot *AudioTauntPilot; |
| 2645 |
tCustomListInfo *AudioTauntPilotSndInfo; |
| 2646 |
void audio1changecallback(int index) { |
| 2647 |
if (index == 0) { |
| 2648 |
AudioTauntPilot->set_multiplayer_data(NULL, ""); |
| 2649 |
return; |
| 2650 |
} else { |
| 2651 |
index--; |
| 2652 |
char *p = GetStringInList(index, AudioTauntPilotSndInfo->files, AudioTauntPilotSndInfo->needed_size); |
| 2653 |
if (p) { |
| 2654 |
AudioTauntPilot->set_multiplayer_data(NULL, p); |
| 2655 |
} |
| 2656 |
} |
| 2657 |
} |
| 2658 |
|
| 2659 |
void audio2changecallback(int index) { |
| 2660 |
if (index == 0) { |
| 2661 |
AudioTauntPilot->set_multiplayer_data(NULL, NULL, ""); |
| 2662 |
return; |
| 2663 |
} else { |
| 2664 |
index--; |
| 2665 |
char *p = GetStringInList(index, AudioTauntPilotSndInfo->files, AudioTauntPilotSndInfo->needed_size); |
| 2666 |
if (p) { |
| 2667 |
AudioTauntPilot->set_multiplayer_data(NULL, NULL, p); |
| 2668 |
} |
| 2669 |
} |
| 2670 |
} |
| 2671 |
|
| 2672 |
void audio3changecallback(int index) { |
| 2673 |
if (index == 0) { |
| 2674 |
AudioTauntPilot->set_multiplayer_data(NULL, NULL, NULL, NULL, ""); |
| 2675 |
return; |
| 2676 |
} else { |
| 2677 |
index--; |
| 2678 |
char *p = GetStringInList(index, AudioTauntPilotSndInfo->files, AudioTauntPilotSndInfo->needed_size); |
| 2679 |
if (p) { |
| 2680 |
AudioTauntPilot->set_multiplayer_data(NULL, NULL, NULL, NULL, p); |
| 2681 |
} |
| 2682 |
} |
| 2683 |
} |
| 2684 |
|
| 2685 |
void audio4changecallback(int index) { |
| 2686 |
if (index == 0) { |
| 2687 |
AudioTauntPilot->set_multiplayer_data(NULL, NULL, NULL, NULL, NULL, ""); |
| 2688 |
return; |
| 2689 |
} else { |
| 2690 |
index--; |
| 2691 |
char *p = GetStringInList(index, AudioTauntPilotSndInfo->files, AudioTauntPilotSndInfo->needed_size); |
| 2692 |
if (p) { |
| 2693 |
AudioTauntPilot->set_multiplayer_data(NULL, NULL, NULL, NULL, NULL, p); |
| 2694 |
} |
| 2695 |
} |
| 2696 |
} |
| 2697 |
|
| 2698 |
#define TAUNT_MENU_W 512 |
| 2699 |
#define TAUNT_MENU_H 384 |
| 2700 |
|
| 2701 |
#define MAX_MULTIPLAYER_TAUNTS 8 |
| 2702 |
#define TAUNT_EDIT_WIDTH 400 |
| 2703 |
|
| 2704 |
void DoPilotTauntScreen(pilot *plt) { |
| 2705 |
newuiTiledWindow taunt_wnd; |
| 2706 |
newuiSheet *sheet; |
| 2707 |
char *taunt_edit[MAX_PILOT_TAUNTS]; |
| 2708 |
int cury = 10; |
| 2709 |
bool exit_menu = false; |
| 2710 |
int i; |
| 2711 |
|
| 2712 |
// create window |
| 2713 |
taunt_wnd.Create(TXT_MULTIPLAYER_TAUNTS, 0, 0, TAUNT_MENU_W, TAUNT_MENU_H); |
| 2714 |
sheet = taunt_wnd.GetSheet(); |
| 2715 |
|
| 2716 |
// Ok/Cancel buttons |
| 2717 |
for (i = 0; i < MAX_PILOT_TAUNTS; i++) { |
| 2718 |
char str[70]; |
| 2719 |
|
| 2720 |
snprintf(str, sizeof(str), "%s%d", TXT_TAUNT_NUMBER, i + 1); |
| 2721 |
sheet->NewGroup(str, 10, cury); |
| 2722 |
|
| 2723 |
taunt_edit[i] = sheet->AddEditBox(str, PILOT_TAUNT_SIZE, TAUNT_EDIT_WIDTH); |
| 2724 |
strcpy(taunt_edit[i], plt->taunts[i]); |
| 2725 |
cury += 32; |
| 2726 |
} |
| 2727 |
|
| 2728 |
sheet->NewGroup(NULL, TAUNT_MENU_W - 210, TAUNT_MENU_H - 100, NEWUI_ALIGN_HORIZ); |
| 2729 |
sheet->AddButton(TXT_OK, UID_OK); |
| 2730 |
sheet->AddButton(TXT_CANCEL, UID_CANCEL); |
| 2731 |
|
| 2732 |
taunt_wnd.Open(); |
| 2733 |
|
| 2734 |
while (!exit_menu) { |
| 2735 |
int res = taunt_wnd.DoUI(); |
| 2736 |
|
| 2737 |
// handle all UI results. |
| 2738 |
switch (res) { |
| 2739 |
case UID_OK: |
| 2740 |
for (i = 0; i < MAX_PILOT_TAUNTS; i++) { |
| 2741 |
strcpy(plt->taunts[i], taunt_edit[i]); |
| 2742 |
// taunt_edit[i].GetText(plt->taunts[i],PILOT_TAUNT_SIZE); |
| 2743 |
} |
| 2744 |
exit_menu = true; |
| 2745 |
break; |
| 2746 |
case UID_CANCEL: |
| 2747 |
exit_menu = true; |
| 2748 |
break; |
| 2749 |
default: |
| 2750 |
break; |
| 2751 |
} |
| 2752 |
} |
| 2753 |
|
| 2754 |
taunt_wnd.Close(); |
| 2755 |
taunt_wnd.Destroy(); |
| 2756 |
} |
| 2757 |
|
| 2758 |
bool PltSelectShip(pilot *Pilot) { |
| 2759 |
#define IDP_SHPLIST 19 |
| 2760 |
#define ID_GETANIM 20 |
| 2761 |
#define ID_IMPORT 21 |
| 2762 |
#define ID_PLAY1 22 |
| 2763 |
#define ID_PLAY2 23 |
| 2764 |
#define ID_PLAY3 24 |
| 2765 |
#define ID_PLAY4 25 |
| 2766 |
|
| 2767 |
#define ID_IMPORTSOUND 26 |
| 2768 |
#define ID_TAUNTS 27 |
| 2769 |
#define ID_DEL_LOGO 28 |
| 2770 |
#define ID_DEL_TAUNTA 29 |
| 2771 |
#define ID_DEL_TAUNTB 30 |
| 2772 |
#define ID_DEL_TAUNTC 31 |
| 2773 |
#define ID_DEL_TAUNTD 32 |
| 2774 |
#define PSSELECT_WND_H 384 |
| 2775 |
#define PSSELECT_WND_W 512 |
| 2776 |
|
| 2777 |
// variable declarations |
| 2778 |
newuiTiledWindow window; |
| 2779 |
newuiSheet *sheet; |
| 2780 |
newuiListBox *custom_list; |
| 2781 |
newuiComboBox *ship_list; |
| 2782 |
|
| 2783 |
int count; |
| 2784 |
char oldt1[PILOT_TAUNT_SIZE], oldt2[PILOT_TAUNT_SIZE]; |
| 2785 |
char oldt3[PILOT_TAUNT_SIZE], oldt4[PILOT_TAUNT_SIZE]; |
| 2786 |
|
| 2787 |
DoWaitMessage(true); |
| 2788 |
|
| 2789 |
Pilot->get_multiplayer_data(NULL, oldt1, oldt2, NULL, oldt3, oldt4); |
| 2790 |
|
| 2791 |
tCustomListInfo cust_snds; |
| 2792 |
tAudioTauntComboBoxes taunts_lists; |
| 2793 |
AudioTauntPilot = Pilot; |
| 2794 |
AudioTauntPilotSndInfo = &cust_snds; |
| 2795 |
|
| 2796 |
UI3DWindow ship_win; |
| 2797 |
UIBmpWindow bmp_win; |
| 2798 |
tCustomListInfo cust_bmps; |
| 2799 |
tShipListInfo ship_info; |
| 2800 |
|
| 2801 |
int old_bmhandle; |
| 2802 |
int old_flags; |
| 2803 |
bool exit_menu = false; |
| 2804 |
bool ret; |
| 2805 |
|
| 2806 |
// pre-initialize all variables |
| 2807 |
cust_bmps.Init(); |
| 2808 |
cust_snds.Init(); |
| 2809 |
|
| 2810 |
lp_cust_bmps = &cust_bmps; |
| 2811 |
lp_ship_info = &ship_info; |
| 2812 |
|
| 2813 |
ship_pos.Init(); |
| 2814 |
ship_info.Init(); |
| 2815 |
|
| 2816 |
custom_texture[0] = '\0'; |
| 2817 |
old_bmhandle = GameTextures[ship_pos.texture_id].bm_handle; |
| 2818 |
old_flags = GameTextures[ship_pos.texture_id].flags; |
| 2819 |
|
| 2820 |
// create UIWindow |
| 2821 |
window.Create(TXT_MULTISELECTSHIP, 0, 0, PSSELECT_WND_W, PSSELECT_WND_H); |
| 2822 |
sheet = window.GetSheet(); |
| 2823 |
|
| 2824 |
sheet->NewGroup(TXT_DEFAULTMSHIPS, 0, 0); |
| 2825 |
ship_list = sheet->AddComboBox(IDP_SHPLIST, 0); |
| 2826 |
|
| 2827 |
sheet->NewGroup(TXT_CUSTOMTEXTURES, 0, 36); |
| 2828 |
cust_bmps.custom_bitmap_list = custom_list = sheet->AddListBox(200, 96, IDP_SHPLIST, 0); |
| 2829 |
|
| 2830 |
sheet->NewGroup(NULL, 230, 130); |
| 2831 |
sheet->AddButton(TXT_DELETE, ID_DEL_LOGO); |
| 2832 |
|
| 2833 |
sheet->NewGroup(TXT_AUDIOTAUNTA, 0, 155); |
| 2834 |
taunts_lists.taunt_a = sheet->AddComboBox(-5, 0); |
| 2835 |
|
| 2836 |
sheet->NewGroup(TXT_AUDIOTAUNTB, 0, 192); |
| 2837 |
taunts_lists.taunt_b = sheet->AddComboBox(-5, 0); |
| 2838 |
|
| 2839 |
sheet->NewGroup(TXT_AUDIOTAUNTC, 0, 229); |
| 2840 |
taunts_lists.taunt_c = sheet->AddComboBox(-5, 0); |
| 2841 |
|
| 2842 |
sheet->NewGroup(TXT_AUDIOTAUNTD, 0, 266); |
| 2843 |
taunts_lists.taunt_d = sheet->AddComboBox(-5, 0); |
| 2844 |
|
| 2845 |
// Ship window |
| 2846 |
UITextItem itemShipWindow{""}; |
| 2847 |
ship_win.Create(&window, &itemShipWindow, 290, 50, 180, 140, 0); |
| 2848 |
|
| 2849 |
// Bitmap display of selected logo |
| 2850 |
bmpwindow = &bmp_win; |
| 2851 |
UITextItem itemLogo{""}; |
| 2852 |
bmp_win.Create(&window, &itemLogo, UI_BORDERSIZE + 200, 53, 42, 42, 0); |
| 2853 |
|
| 2854 |
// Get all the audio files and put them into the lists |
| 2855 |
UpdateAudioTauntBoxes(&cust_snds, taunts_lists.taunt_a, taunts_lists.taunt_b, taunts_lists.taunt_c, |
| 2856 |
taunts_lists.taunt_d, Pilot); |
| 2857 |
|
| 2858 |
DoWaitMessage(true); |
| 2859 |
|
| 2860 |
// Setup hotspots for audio taunt commands |
| 2861 |
sheet->NewGroup(NULL, 170, 163); |
| 2862 |
sheet->AddButton(TXT_PLAYSOUND, ID_PLAY1); |
| 2863 |
sheet->AddButton(TXT_DELETE, ID_DEL_TAUNTA); |
| 2864 |
|
| 2865 |
sheet->NewGroup(NULL, 170, 200); |
| 2866 |
sheet->AddButton(TXT_PLAYSOUND, ID_PLAY2); |
| 2867 |
sheet->AddButton(TXT_DELETE, ID_DEL_TAUNTB); |
| 2868 |
|
| 2869 |
sheet->NewGroup(NULL, 170, 237); |
| 2870 |
sheet->AddButton(TXT_PLAYSOUND, ID_PLAY3); |
| 2871 |
sheet->AddButton(TXT_DELETE, ID_DEL_TAUNTC); |
| 2872 |
|
| 2873 |
sheet->NewGroup(NULL, 170, 274); |
| 2874 |
sheet->AddButton(TXT_PLAYSOUND, ID_PLAY4); |
| 2875 |
sheet->AddButton(TXT_DELETE, ID_DEL_TAUNTD); |
| 2876 |
|
| 2877 |
// setup callback function |
| 2878 |
custom_list->SetSelectChangeCallback(CustomCallBack); |
| 2879 |
ship_list->SetSelectChangeCallback(ShipSelectCallBack); |
| 2880 |
taunts_lists.taunt_a->SetSelectChangeCallback(audio1changecallback); |
| 2881 |
taunts_lists.taunt_b->SetSelectChangeCallback(audio2changecallback); |
| 2882 |
taunts_lists.taunt_c->SetSelectChangeCallback(audio3changecallback); |
| 2883 |
taunts_lists.taunt_d->SetSelectChangeCallback(audio4changecallback); |
| 2884 |
|
| 2885 |
int i; |
| 2886 |
// get all the ship ids |
| 2887 |
count = 0; |
| 2888 |
for (i = 0; i < MAX_SHIPS; i++) { |
| 2889 |
if (Ships[i].used) |
| 2890 |
count++; |
| 2891 |
} |
| 2892 |
ship_info.idlist = (int *)mem_malloc(sizeof(int) * count); |
| 2893 |
if (!ship_info.idlist) |
| 2894 |
goto ship_id_err; |
| 2895 |
|
| 2896 |
bool found_ship; |
| 2897 |
bool shipoktoadd; |
| 2898 |
|
| 2899 |
found_ship = false; |
| 2900 |
count = 0; |
| 2901 |
char pship[PAGENAME_LEN]; |
| 2902 |
Pilot->get_ship(pship); |
| 2903 |
|
| 2904 |
for (i = 0; i < MAX_SHIPS; i++) { |
| 2905 |
if (Ships[i].used) { |
| 2906 |
ship_info.idlist[count] = i; |
| 2907 |
#ifdef DEMO |
| 2908 |
if (stricmp(Ships[i].name, DEFAULT_SHIP) == 0) { |
| 2909 |
#endif |
| 2910 |
// make sure they have mercenary in order to play with Black Pyro |
| 2911 |
if (!stricmp(Ships[i].name, "Black Pyro")) { |
| 2912 |
shipoktoadd = false; |
| 2913 |
extern bool MercInstalled(); |
| 2914 |
if (MercInstalled()) { |
| 2915 |
shipoktoadd = true; |
| 2916 |
} |
| 2917 |
} |
| 2918 |
else |
| 2919 |
shipoktoadd = true; |
| 2920 |
if (shipoktoadd) |
| 2921 |
ship_list->AddItem(Ships[i].name); |
| 2922 |
#ifdef DEMO |
| 2923 |
} |
| 2924 |
#endif |
| 2925 |
|
| 2926 |
if (!stricmp(pship, Ships[i].name)) { |
| 2927 |
ship_list->SetCurrentIndex(count); |
| 2928 |
found_ship = true; |
| 2929 |
} |
| 2930 |
count++; |
| 2931 |
} |
| 2932 |
} |
| 2933 |
|
| 2934 |
// if we couldn't find the ship than that means that the ship in their pilot file no longer |
| 2935 |
// exists and so we must set it to the default ship |
| 2936 |
if (!found_ship) { |
| 2937 |
DoMessageBox(TXT_WARNING, TXT_SHIPSELECTERR, MSGBOX_OK); |
| 2938 |
if (count > 0) { |
| 2939 |
// find the ship in the page |
| 2940 |
int index = FindShipName(DEFAULT_SHIP); |
| 2941 |
if (index == -1) { |
| 2942 |
mprintf(0, "WARNING: CAN'T FIND DEFAULT SHIP IN TABLE\n"); |
| 2943 |
} else { |
| 2944 |
// go through all the id's of the ships we found and find the ship (if FindShipName found it, |
| 2945 |
// then we'll have it here somewhere. |
| 2946 |
for (int i = 0; i < count; i++) { |
| 2947 |
if (ship_info.idlist[i] == index) { |
| 2948 |
// set this as the default ship |
| 2949 |
ship_list->SetCurrentIndex(i); |
| 2950 |
|
| 2951 |
} // endif |
| 2952 |
} // endfor |
| 2953 |
} // end else |
| 2954 |
} else { |
| 2955 |
// NO SHIPS IN THE TABLE!!! |
| 2956 |
mprintf(0, "WARNING: NO SHIPS IN THE TABLE!?\n"); |
| 2957 |
} |
| 2958 |
} |
| 2959 |
|
| 2960 |
// get a list of custom textures |
| 2961 |
char pshiplogo[PAGENAME_LEN]; |
| 2962 |
Pilot->get_multiplayer_data(pshiplogo); |
| 2963 |
|
| 2964 |
DoWaitMessage(true); |
| 2965 |
|
| 2966 |
if (!UpdateGraphicsListbox(&cust_bmps, custom_list, pshiplogo)) |
| 2967 |
goto ship_id_err; |
| 2968 |
|
| 2969 |
i = ship_list->GetCurrentIndex(); |
| 2970 |
ShipSelectCallBack(i); |
| 2971 |
|
| 2972 |
// setup hotspots |
| 2973 |
sheet->NewGroup(NULL, 250, 170); |
| 2974 |
sheet->AddLongButton(TXT_IMPORTGRAPHIC, ID_IMPORT); |
| 2975 |
sheet->AddLongButton(TXT_IMPORTIFL, ID_GETANIM); |
| 2976 |
sheet->AddLongButton(TXT_MULTIPLAYER_TAUNTS, ID_TAUNTS); |
| 2977 |
sheet->AddLongButton(TXT_IMPORTSOUND, ID_IMPORTSOUND); |
| 2978 |
sheet->NewGroup(NULL, 260, 281, NEWUI_ALIGN_HORIZ); |
| 2979 |
sheet->AddButton(TXT_OK, UID_OK); |
| 2980 |
sheet->AddButton(TXT_CANCEL, UID_CANCEL); |
| 2981 |
|
| 2982 |
// Ok, all initial setup is finally complete, time to display the window and process input |
| 2983 |
ret = false; |
| 2984 |
|
| 2985 |
DoWaitMessage(false); |
| 2986 |
|
| 2987 |
window.Open(); |
| 2988 |
while (!exit_menu) { |
| 2989 |
int res = window.DoUI(); |
| 2990 |
|
| 2991 |
// handle all UI results. |
| 2992 |
switch (res) { |
| 2993 |
case UID_OK: { |
| 2994 |
char tbuf[64]; |
| 2995 |
ship_list->GetCurrentItem(tbuf, 64); |
| 2996 |
|
| 2997 |
Pilot->set_ship(tbuf); |
| 2998 |
Pilot->set_multiplayer_data(custom_texture); |
| 2999 |
|
| 3000 |
// Retrieve Audio taunts |
| 3001 |
Pilot->set_multiplayer_data(NULL, "", "", NULL, "", ""); |
| 3002 |
|
| 3003 |
int index; |
| 3004 |
index = taunts_lists.taunt_a->GetCurrentIndex(); |
| 3005 |
if (index > 0 && cust_snds.files) { |
| 3006 |
char *p = GetStringInList(index - 1, cust_snds.files, cust_snds.needed_size); |
| 3007 |
if (p) { |
| 3008 |
Pilot->set_multiplayer_data(NULL, p); |
| 3009 |
} |
| 3010 |
} |
| 3011 |
index = taunts_lists.taunt_b->GetCurrentIndex(); |
| 3012 |
if (index > 0 && cust_snds.files) { |
| 3013 |
char *p = GetStringInList(index - 1, cust_snds.files, cust_snds.needed_size); |
| 3014 |
if (p) { |
| 3015 |
Pilot->set_multiplayer_data(NULL, NULL, p); |
| 3016 |
} |
| 3017 |
} |
| 3018 |
|
| 3019 |
index = taunts_lists.taunt_c->GetCurrentIndex(); |
| 3020 |
if (index > 0 && cust_snds.files) { |
| 3021 |
char *p = GetStringInList(index - 1, cust_snds.files, cust_snds.needed_size); |
| 3022 |
if (p) { |
| 3023 |
Pilot->set_multiplayer_data(NULL, NULL, NULL, NULL, p); |
| 3024 |
} |
| 3025 |
} |
| 3026 |
|
| 3027 |
index = taunts_lists.taunt_d->GetCurrentIndex(); |
| 3028 |
if (index > 0 && cust_snds.files) { |
| 3029 |
char *p = GetStringInList(index - 1, cust_snds.files, cust_snds.needed_size); |
| 3030 |
if (p) { |
| 3031 |
Pilot->set_multiplayer_data(NULL, NULL, NULL, NULL, NULL, p); |
| 3032 |
} |
| 3033 |
} |
| 3034 |
|
| 3035 |
char tempn[PAGENAME_LEN]; |
| 3036 |
|
| 3037 |
Pilot->get_multiplayer_data(NULL, tempn); |
| 3038 |
mprintf(0, "Audio #1: '%s'\n", tempn); |
| 3039 |
|
| 3040 |
Pilot->get_multiplayer_data(NULL, NULL, tempn); |
| 3041 |
mprintf(0, "Audio #2: '%s'\n", tempn); |
| 3042 |
|
| 3043 |
Pilot->get_multiplayer_data(NULL, NULL, NULL, NULL, tempn); |
| 3044 |
mprintf(0, "Audio #3: '%s'\n", tempn); |
| 3045 |
|
| 3046 |
Pilot->get_multiplayer_data(NULL, NULL, NULL, NULL, NULL, tempn); |
| 3047 |
mprintf(0, "Audio #4: '%s'\n", tempn); |
| 3048 |
|
| 3049 |
ret = true; |
| 3050 |
exit_menu = true; |
| 3051 |
} break; |
| 3052 |
case UID_CANCEL: |
| 3053 |
ret = false; |
| 3054 |
exit_menu = true; |
| 3055 |
GameTextures[ship_pos.texture_id].bm_handle = old_bmhandle; |
| 3056 |
GameTextures[ship_pos.texture_id].flags = old_flags; |
| 3057 |
Pilot->set_multiplayer_data(NULL, oldt1, oldt2, NULL, oldt3, oldt4); |
| 3058 |
break; |
| 3059 |
case ID_IMPORT: { |
| 3060 |
char path[_MAX_PATH]; |
| 3061 |
char newf[_MAX_FNAME]; |
| 3062 |
char wildcards[100]; |
| 3063 |
path[0] = '\0'; |
| 3064 |
strcpy(wildcards, "*.ogf;*.tga;*.pcx;*.iff"); |
| 3065 |
if (DoPathFileDialog(false, path, TXT_CHOOSE, wildcards, PFDF_FILEMUSTEXIST)) { |
| 3066 |
if (ImportGraphic(path, newf)) { |
| 3067 |
// update the listbox |
| 3068 |
if (!UpdateGraphicsListbox(&cust_bmps, custom_list, newf)) |
| 3069 |
goto ship_id_err; |
| 3070 |
} else { |
| 3071 |
DoMessageBox(TXT_ERROR, TXT_ERRORIMPORT, MSGBOX_OK); |
| 3072 |
} |
| 3073 |
} |
| 3074 |
ddio_SetWorkingDir(path); |
| 3075 |
} break; |
| 3076 |
case ID_GETANIM: { |
| 3077 |
char path[_MAX_PATH]; |
| 3078 |
char opath[_MAX_PATH]; |
| 3079 |
char wildcards[100]; |
| 3080 |
path[0] = '\0'; |
| 3081 |
strcpy(opath, path); |
| 3082 |
strcpy(wildcards, "*.ifl"); |
| 3083 |
if (DoPathFileDialog(false, path, TXT_CHOOSE, wildcards, PFDF_FILEMUSTEXIST)) { |
| 3084 |
int handle = AllocLoadIFLVClip(IGNORE_TABLE(path), SMALL_TEXTURE, 1); |
| 3085 |
|
| 3086 |
if (handle != -1) { |
| 3087 |
// change the file extension |
| 3088 |
char f[_MAX_FNAME], newf[_MAX_FNAME + _MAX_EXT], tempf[_MAX_PATH]; |
| 3089 |
if (!CreateCRCFileName(path, tempf)) { |
| 3090 |
FreeVClip(handle); |
| 3091 |
break; |
| 3092 |
} |
| 3093 |
ddio_SplitPath(tempf, NULL, f, NULL); |
| 3094 |
strcpy(newf, f); |
| 3095 |
strcat(newf, ".oaf"); |
| 3096 |
ddio_MakePath(path, LocalCustomGraphicsDir, newf, NULL); |
| 3097 |
|
| 3098 |
if (SaveVClip(path, handle) == 0) { |
| 3099 |
// error saving |
| 3100 |
DoMessageBox(TXT_ERROR, TXT_ERRORIMPORT, MSGBOX_OK); |
| 3101 |
} else { |
| 3102 |
// all went ok!!! |
| 3103 |
DoMessageBox(TXT_SUCCESS, TXT_SUCCESSIMPORT, MSGBOX_OK); |
| 3104 |
} |
| 3105 |
FreeVClip(handle); |
| 3106 |
|
| 3107 |
// check file size...make sure it isn't too big |
| 3108 |
CFILE *file = cfopen(path, "rb"); |
| 3109 |
if (file) { |
| 3110 |
if (cfilelength(file) > MAX_AUDIOTAUNTSIZE) { |
| 3111 |
// file too big!!!!!! |
| 3112 |
char message[256]; |
| 3113 |
snprintf(message, sizeof(message), TXT_COMPRESSTOOBIG, MAX_AUDIOTAUNTSIZE / 1024); |
| 3114 |
DoMessageBox(TXT_WARNING, message, MSGBOX_OK); |
| 3115 |
} |
| 3116 |
cfclose(file); |
| 3117 |
} |
| 3118 |
|
| 3119 |
// update the listbox |
| 3120 |
if (!UpdateGraphicsListbox(&cust_bmps, custom_list, newf)) |
| 3121 |
goto ship_id_err; |
| 3122 |
} |
| 3123 |
} |
| 3124 |
ddio_SetWorkingDir(opath); |
| 3125 |
} break; |
| 3126 |
case ID_PLAY1: { |
| 3127 |
// Play audio taunt #1 if <None> isn't selected |
| 3128 |
char path[_MAX_PATH]; |
| 3129 |
int index = taunts_lists.taunt_a->GetCurrentIndex(); |
| 3130 |
if (index > 0 && cust_snds.files) { |
| 3131 |
char *p = GetStringInList(index - 1, cust_snds.files, cust_snds.needed_size); |
| 3132 |
if (p) { |
| 3133 |
ddio_MakePath(path, LocalCustomSoundsDir, p, NULL); |
| 3134 |
mprintf(0, "Playing: %s\n", path); |
| 3135 |
bool cenable = taunt_AreEnabled(); |
| 3136 |
taunt_Enable(true); |
| 3137 |
taunt_PlayTauntFile(path); |
| 3138 |
taunt_Enable(cenable); |
| 3139 |
} |
| 3140 |
} |
| 3141 |
} break; |
| 3142 |
case ID_PLAY2: { |
| 3143 |
// Play audio taunt #2 if <None> isn't selected |
| 3144 |
char path[_MAX_PATH]; |
| 3145 |
int index = taunts_lists.taunt_b->GetCurrentIndex(); |
| 3146 |
if (index > 0 && cust_snds.files) { |
| 3147 |
char *p = GetStringInList(index - 1, cust_snds.files, cust_snds.needed_size); |
| 3148 |
if (p) { |
| 3149 |
ddio_MakePath(path, LocalCustomSoundsDir, p, NULL); |
| 3150 |
mprintf(0, "Playing: %s\n", path); |
| 3151 |
bool cenable = taunt_AreEnabled(); |
| 3152 |
taunt_Enable(true); |
| 3153 |
taunt_PlayTauntFile(path); |
| 3154 |
taunt_Enable(cenable); |
| 3155 |
} |
| 3156 |
} |
| 3157 |
} break; |
| 3158 |
case ID_PLAY3: { |
| 3159 |
// Play audio taunt #3 if <None> isn't selected |
| 3160 |
char path[_MAX_PATH]; |
| 3161 |
int index = taunts_lists.taunt_c->GetCurrentIndex(); |
| 3162 |
if (index > 0 && cust_snds.files) { |
| 3163 |
char *p = GetStringInList(index - 1, cust_snds.files, cust_snds.needed_size); |
| 3164 |
if (p) { |
| 3165 |
ddio_MakePath(path, LocalCustomSoundsDir, p, NULL); |
| 3166 |
mprintf(0, "Playing: %s\n", path); |
| 3167 |
bool cenable = taunt_AreEnabled(); |
| 3168 |
taunt_Enable(true); |
| 3169 |
taunt_PlayTauntFile(path); |
| 3170 |
taunt_Enable(cenable); |
| 3171 |
} |
| 3172 |
} |
| 3173 |
} break; |
| 3174 |
|
| 3175 |
case ID_PLAY4: { |
| 3176 |
// Play audio taunt #4 if <None> isn't selected |
| 3177 |
char path[_MAX_PATH]; |
| 3178 |
int index = taunts_lists.taunt_d->GetCurrentIndex(); |
| 3179 |
if (index > 0 && cust_snds.files) { |
| 3180 |
char *p = GetStringInList(index - 1, cust_snds.files, cust_snds.needed_size); |
| 3181 |
if (p) { |
| 3182 |
ddio_MakePath(path, LocalCustomSoundsDir, p, NULL); |
| 3183 |
mprintf(0, "Playing: %s\n", path); |
| 3184 |
bool cenable = taunt_AreEnabled(); |
| 3185 |
taunt_Enable(true); |
| 3186 |
taunt_PlayTauntFile(path); |
| 3187 |
taunt_Enable(cenable); |
| 3188 |
} |
| 3189 |
} |
| 3190 |
} break; |
| 3191 |
|
| 3192 |
case ID_TAUNTS: { |
| 3193 |
DoPilotTauntScreen(Pilot); |
| 3194 |
break; |
| 3195 |
} |
| 3196 |
case ID_IMPORTSOUND: { |
| 3197 |
// Import the sound, set it's sample to xx.xKhz and xbit depth, attach the CRC to the filename |
| 3198 |
// and place in custom/sounds. Then update the audio taunt combo boxes |
| 3199 |
char path[_MAX_PATH]; |
| 3200 |
char wildcards[100]; |
| 3201 |
path[0] = '\0'; |
| 3202 |
strcpy(wildcards, "*.wav"); |
| 3203 |
if (DoPathFileDialog(false, path, TXT_CHOOSE, wildcards, PFDF_FILEMUSTEXIST)) { |
| 3204 |
char dpath[_MAX_PATH * 2]; |
| 3205 |
char filename[_MAX_PATH]; |
| 3206 |
char tempfile[_MAX_PATH]; |
| 3207 |
|
| 3208 |
ddio_SplitPath(path, NULL, filename, NULL); |
| 3209 |
strcat(filename, ".osf"); |
| 3210 |
ddio_MakePath(tempfile, LocalCustomSoundsDir, filename, NULL); |
| 3211 |
|
| 3212 |
// import the sound |
| 3213 |
mprintf(0, "Importing: '%s'->'%s'\n", path, tempfile); |
| 3214 |
if (taunt_ImportWave(path, tempfile)) { |
| 3215 |
// success |
| 3216 |
|
| 3217 |
// check file size...make sure it isn't too big |
| 3218 |
CFILE *file = cfopen(tempfile, "rb"); |
| 3219 |
|
| 3220 |
if (file) { |
| 3221 |
|
| 3222 |
if (cfilelength(file) > MAX_AUDIOTAUNTSIZE) { |
| 3223 |
// file too big!!!!!! |
| 3224 |
char message[256]; |
| 3225 |
snprintf(message, sizeof(message), TXT_COMPRESSTOOBIG, MAX_AUDIOTAUNTSIZE / 1024); |
| 3226 |
DoMessageBox(TXT_WARNING, message, MSGBOX_OK); |
| 3227 |
} |
| 3228 |
|
| 3229 |
cfclose(file); |
| 3230 |
|
| 3231 |
if (CreateCRCFileName(tempfile, dpath)) { |
| 3232 |
// dpath is destination file |
| 3233 |
// tempfile is source file |
| 3234 |
if (cf_CopyFile(dpath, tempfile, 0)) { |
| 3235 |
// file copied... |
| 3236 |
DoMessageBox(TXT_SUCCESS, TXT_AUDIOIMPORTSUC, MSGBOX_OK); |
| 3237 |
// delete temp file |
| 3238 |
ddio_DeleteFile(tempfile); |
| 3239 |
// Put path in the custom\sounds as dpath (convert if needed) |
| 3240 |
UpdateAudioTauntBoxes(&cust_snds, taunts_lists.taunt_a, taunts_lists.taunt_b, taunts_lists.taunt_c, |
| 3241 |
taunts_lists.taunt_d, Pilot); |
| 3242 |
} else { |
| 3243 |
DoMessageBox(TXT_ERROR, TXT_COPYTEMPERR, MSGBOX_OK); |
| 3244 |
// delete temp file |
| 3245 |
ddio_DeleteFile(tempfile); |
| 3246 |
} |
| 3247 |
} else { |
| 3248 |
// couldn't generate a crc filename |
| 3249 |
DoMessageBox(TXT_ERROR, TXT_CANTCREATECRC, MSGBOX_OK); |
| 3250 |
// delete temp file |
| 3251 |
ddio_DeleteFile(tempfile); |
| 3252 |
} |
| 3253 |
} // end else (file size) |
| 3254 |
} else { |
| 3255 |
int imp_err = taunt_GetError(); |
| 3256 |
const char *err = taunt_GetErrorString(imp_err); |
| 3257 |
// failure |
| 3258 |
DoMessageBox(TXT_ERROR, err, MSGBOX_OK); |
| 3259 |
} |
| 3260 |
} |
| 3261 |
ddio_SetWorkingDir(path); |
| 3262 |
} break; |
| 3263 |
|
| 3264 |
case ID_DEL_LOGO: { |
| 3265 |
ShipSelectDeleteLogo(&cust_bmps, custom_list); |
| 3266 |
} break; |
| 3267 |
|
| 3268 |
case ID_DEL_TAUNTA: { |
| 3269 |
ShipSelectDeleteTaunt(Pilot, &cust_snds, taunts_lists.taunt_a, &taunts_lists); |
| 3270 |
} break; |
| 3271 |
|
| 3272 |
case ID_DEL_TAUNTB: { |
| 3273 |
ShipSelectDeleteTaunt(Pilot, &cust_snds, taunts_lists.taunt_b, &taunts_lists); |
| 3274 |
} break; |
| 3275 |
|
| 3276 |
case ID_DEL_TAUNTC: { |
| 3277 |
ShipSelectDeleteTaunt(Pilot, &cust_snds, taunts_lists.taunt_c, &taunts_lists); |
| 3278 |
} break; |
| 3279 |
|
| 3280 |
case ID_DEL_TAUNTD: { |
| 3281 |
ShipSelectDeleteTaunt(Pilot, &cust_snds, taunts_lists.taunt_d, &taunts_lists); |
| 3282 |
} break; |
| 3283 |
} |
| 3284 |
} |
| 3285 |
|
| 3286 |
ship_id_err: |
| 3287 |
|
| 3288 |
// no use for this since stream files will stop |
| 3289 |
// Sound_system.StopAllSounds(); |
| 3290 |
|
| 3291 |
taunts_lists.taunt_a = NULL; |
| 3292 |
taunts_lists.taunt_b = NULL; |
| 3293 |
taunts_lists.taunt_c = NULL; |
| 3294 |
taunts_lists.taunt_d = NULL; |
| 3295 |
|
| 3296 |
cust_snds.Reset(); |
| 3297 |
|
| 3298 |
cust_bmps.Reset(); |
| 3299 |
ship_info.Reset(); |
| 3300 |
|
| 3301 |
if ((ret) && (ship_pos.bm_handle <= BAD_BITMAP_HANDLE)) { |
| 3302 |
GameTextures[ship_pos.texture_id].flags &= ~TF_ANIMATED; |
| 3303 |
GameTextures[ship_pos.texture_id].flags &= ~TF_TEXTURE_32; |
| 3304 |
GameTextures[ship_pos.texture_id].flags |= TF_TEXTURE_64; |
| 3305 |
GameTextures[ship_pos.texture_id].bm_handle = BAD_BITMAP_HANDLE; |
| 3306 |
} |
| 3307 |
|
| 3308 |
if (ship_pos.bm_handle > BAD_BITMAP_HANDLE) { |
| 3309 |
int handle; |
| 3310 |
bool anim; |
| 3311 |
if (ret) { |
| 3312 |
handle = old_bmhandle; |
| 3313 |
anim = (bool)((old_flags & TF_ANIMATED) != 0); |
| 3314 |
} else { |
| 3315 |
handle = ship_pos.bm_handle; |
| 3316 |
anim = (bool)(ship_pos.texture_type > 0); |
| 3317 |
} |
| 3318 |
if (handle > BAD_BITMAP_HANDLE) { |
| 3319 |
if (anim) |
| 3320 |
FreeVClip(handle); |
| 3321 |
else |
| 3322 |
bm_FreeBitmap(handle); |
| 3323 |
} |
| 3324 |
} |
| 3325 |
ship_pos.bm_handle = -1; |
| 3326 |
|
| 3327 |
window.Close(); |
| 3328 |
window.Destroy(); |
| 3329 |
|
| 3330 |
return ret; |
| 3331 |
} |
| 3332 |
|
| 3333 |
void CustomCallBack(int c) { |
| 3334 |
char select_bitmap[_MAX_PATH]; |
| 3335 |
char *sbmp = GetStringInList(c - 1, lp_cust_bmps->files, lp_cust_bmps->needed_size); |
| 3336 |
if (sbmp) |
| 3337 |
strcpy(select_bitmap, sbmp); |
| 3338 |
else |
| 3339 |
select_bitmap[0] = '\0'; |
| 3340 |
|
| 3341 |
if (!strcmp(custom_texture, select_bitmap)) |
| 3342 |
return; |
| 3343 |
|
| 3344 |
if (ship_pos.bm_handle > BAD_BITMAP_HANDLE) { |
| 3345 |
if (ship_pos.texture_type) |
| 3346 |
FreeVClip(ship_pos.bm_handle); |
| 3347 |
else |
| 3348 |
bm_FreeBitmap(ship_pos.bm_handle); |
| 3349 |
ship_pos.bm_handle = -1; |
| 3350 |
} |
| 3351 |
ship_pos.texture_changed = true; |
| 3352 |
|
| 3353 |
if (c == 0) { |
| 3354 |
// None selected |
| 3355 |
custom_texture[0] = '\0'; |
| 3356 |
mprintf(0, "None selected\n"); |
| 3357 |
bmpwindow->SetInfo(false, -1); |
| 3358 |
GameTextures[ship_pos.texture_id].flags &= ~TF_ANIMATED; |
| 3359 |
GameTextures[ship_pos.texture_id].flags &= ~TF_TEXTURE_32; |
| 3360 |
GameTextures[ship_pos.texture_id].flags |= TF_TEXTURE_64; |
| 3361 |
GameTextures[ship_pos.texture_id].bm_handle = BAD_BITMAP_HANDLE; |
| 3362 |
} else { |
| 3363 |
// Get the filename |
| 3364 |
char *p = GetStringInList(c - 1, lp_cust_bmps->files, lp_cust_bmps->needed_size); |
| 3365 |
if (p) |
| 3366 |
strcpy(custom_texture, p); |
| 3367 |
else |
| 3368 |
custom_texture[0] = '\0'; |
| 3369 |
ship_pos.bm_handle = LoadTextureImage(IGNORE_TABLE(custom_texture), &ship_pos.texture_type, SMALL_TEXTURE, 1); |
| 3370 |
if (ship_pos.bm_handle > BAD_BITMAP_HANDLE) { |
| 3371 |
if (ship_pos.texture_type) |
| 3372 |
GameTextures[ship_pos.texture_id].flags |= TF_ANIMATED; |
| 3373 |
else |
| 3374 |
GameTextures[ship_pos.texture_id].flags &= ~TF_ANIMATED; |
| 3375 |
|
| 3376 |
GameTextures[ship_pos.texture_id].flags &= ~TF_TEXTURE_32; |
| 3377 |
GameTextures[ship_pos.texture_id].flags |= TF_TEXTURE_64; |
| 3378 |
|
| 3379 |
GameTextures[ship_pos.texture_id].bm_handle = ship_pos.bm_handle; |
| 3380 |
|
| 3381 |
bmpwindow->SetInfo(ship_pos.texture_type ? true : false, ship_pos.bm_handle); |
| 3382 |
|
| 3383 |
mprintf(0, "Loaded texture (%s). Type=%d, ID=%d\n", custom_texture, ship_pos.texture_type, ship_pos.texture_id); |
| 3384 |
} else |
| 3385 |
goto load_texture_err; |
| 3386 |
} |
| 3387 |
|
| 3388 |
return; |
| 3389 |
|
| 3390 |
load_texture_err: |
| 3391 |
ship_pos.bm_handle = BAD_BITMAP_HANDLE; |
| 3392 |
GameTextures[ship_pos.texture_id].flags &= ~TF_ANIMATED; |
| 3393 |
GameTextures[ship_pos.texture_id].flags &= ~TF_TEXTURE_32; |
| 3394 |
GameTextures[ship_pos.texture_id].flags |= TF_TEXTURE_64; |
| 3395 |
GameTextures[ship_pos.texture_id].bm_handle = BAD_BITMAP_HANDLE; |
| 3396 |
strcpy(custom_texture, ""); |
| 3397 |
mprintf(0, "Unable to load texture\n"); |
| 3398 |
bmpwindow->SetInfo(false, -1); |
| 3399 |
} |
| 3400 |
|
| 3401 |
extern float Render_zoom; |
| 3402 |
void ShipSelectCallBack(int c) { |
| 3403 |
if (!lp_ship_info->idlist) |
| 3404 |
return; |
| 3405 |
|
| 3406 |
float size; |
| 3407 |
ship_model = Ships[lp_ship_info->idlist[c]].model_handle; |
| 3408 |
if (ship_model == -1) { |
| 3409 |
mprintf(0, "ship_model is -1\n"); |
| 3410 |
Int3(); |
| 3411 |
} |
| 3412 |
|
| 3413 |
DoWaitMessage(true); |
| 3414 |
|
| 3415 |
PageInPolymodel(ship_model, OBJ_PLAYER, &size); |
| 3416 |
poly_model *pm = GetPolymodelPointer(ship_model); |
| 3417 |
|
| 3418 |
ship_pos.cam_dist = pm->anim_size / Render_zoom + 5; |
| 3419 |
|
| 3420 |
DoWaitMessage(false); |
| 3421 |
} |
| 3422 |
|
| 3423 |
extern char LocalCustomGraphicsDir[TABLE_NAME_LEN]; |
| 3424 |
extern char LocalCustomSoundsDir[TABLE_NAME_LEN]; |
| 3425 |
|
| 3426 |
// Deletes the currently selected ship logo |
| 3427 |
void ShipSelectDeleteLogo(tCustomListInfo *cust_bmps, newuiListBox *lb) { |
| 3428 |
ASSERT(lb); |
| 3429 |
ASSERT(cust_bmps); |
| 3430 |
|
| 3431 |
int selected_index = lb->GetCurrentIndex(); |
| 3432 |
char custom_filename[384]; |
| 3433 |
char custom_logoname[384]; |
| 3434 |
|
| 3435 |
// check for None selected |
| 3436 |
if (selected_index == 0) { |
| 3437 |
mprintf(0, "Listbox selected item is None\n"); |
| 3438 |
return; |
| 3439 |
} |
| 3440 |
|
| 3441 |
lb->GetItem(selected_index, custom_logoname, 384); |
| 3442 |
|
| 3443 |
// Get the filename |
| 3444 |
char *p = GetStringInList(selected_index - 1, cust_bmps->files, cust_bmps->needed_size); |
| 3445 |
if (p) { |
| 3446 |
strncpy(custom_filename, p, 383); |
| 3447 |
custom_filename[383] = '\0'; |
| 3448 |
} else { |
| 3449 |
mprintf(0, "Listbox selected item not found\n"); |
| 3450 |
Int3(); |
| 3451 |
return; |
| 3452 |
} |
| 3453 |
|
| 3454 |
// delete custom_filename, we don't want it.... |
| 3455 |
char buffer[512]; |
| 3456 |
snprintf(buffer, sizeof(buffer), TXT_PLTOKDEL, custom_logoname); |
| 3457 |
if (DoMessageBox(TXT_PLTDELCONF, buffer, MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) { |
| 3458 |
mprintf(0, "Deleting pilot logo %s (%s)\n", custom_logoname, custom_filename); |
| 3459 |
|
| 3460 |
char olddir[_MAX_PATH]; |
| 3461 |
ddio_GetWorkingDir(olddir, _MAX_PATH); |
| 3462 |
ddio_SetWorkingDir(LocalCustomGraphicsDir); |
| 3463 |
if (ddio_DeleteFile(custom_filename)) { |
| 3464 |
// Update the list box, select none |
| 3465 |
UpdateGraphicsListbox(cust_bmps, lb, NULL); |
| 3466 |
} else { |
| 3467 |
mprintf(0, "Unable to delete file %s\n", custom_filename); |
| 3468 |
Int3(); |
| 3469 |
} |
| 3470 |
ddio_SetWorkingDir(olddir); |
| 3471 |
} |
| 3472 |
} |
| 3473 |
|
| 3474 |
// Deletes the currently selected audio taunt |
| 3475 |
void ShipSelectDeleteTaunt(pilot *Pilot, tCustomListInfo *cust_snds, newuiComboBox *lb, |
| 3476 |
tAudioTauntComboBoxes *taunt_boxes) { |
| 3477 |
ASSERT(Pilot); |
| 3478 |
ASSERT(cust_snds); |
| 3479 |
ASSERT(taunt_boxes); |
| 3480 |
|
| 3481 |
int selected_index = lb->GetCurrentIndex(); |
| 3482 |
char custom_filename[384]; |
| 3483 |
char custom_logoname[384]; |
| 3484 |
|
| 3485 |
// check for None selected |
| 3486 |
if (selected_index == 0) { |
| 3487 |
mprintf(0, "Listbox selected item is None\n"); |
| 3488 |
return; |
| 3489 |
} |
| 3490 |
|
| 3491 |
lb->GetItem(selected_index, custom_logoname, 384); |
| 3492 |
|
| 3493 |
// Get the filename |
| 3494 |
char *p = GetStringInList(selected_index - 1, cust_snds->files, cust_snds->needed_size); |
| 3495 |
if (p) { |
| 3496 |
strncpy(custom_filename, p, 383); |
| 3497 |
custom_filename[383] = '\0'; |
| 3498 |
} else { |
| 3499 |
mprintf(0, "Listbox selected item not found\n"); |
| 3500 |
Int3(); |
| 3501 |
return; |
| 3502 |
} |
| 3503 |
|
| 3504 |
// delete custom_filename, we don't want it.... |
| 3505 |
char buffer[512]; |
| 3506 |
snprintf(buffer, sizeof(buffer), TXT_PLTOKDEL, custom_logoname); |
| 3507 |
if (DoMessageBox(TXT_PLTDELCONF, buffer, MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) { |
| 3508 |
mprintf(0, "Deleting audio taunt %s (%s)\n", custom_logoname, custom_filename); |
| 3509 |
|
| 3510 |
char olddir[_MAX_PATH]; |
| 3511 |
ddio_GetWorkingDir(olddir, _MAX_PATH); |
| 3512 |
ddio_SetWorkingDir(LocalCustomSoundsDir); |
| 3513 |
if (ddio_DeleteFile(custom_filename)) { |
| 3514 |
// Update the list boxes, select none |
| 3515 |
UpdateAudioTauntBoxes(cust_snds, taunt_boxes->taunt_a, taunt_boxes->taunt_b, taunt_boxes->taunt_c, |
| 3516 |
taunt_boxes->taunt_d, Pilot); |
| 3517 |
} else { |
| 3518 |
mprintf(0, "Unable to delete file %s\n", custom_filename); |
| 3519 |
Int3(); |
| 3520 |
} |
| 3521 |
ddio_SetWorkingDir(olddir); |
| 3522 |
} |
| 3523 |
} |
| 3524 |
|
| 3525 |
void UI3DWindow::OnDraw() { |
| 3526 |
AudioStream::Frame(); |
| 3527 |
|
| 3528 |
static polymodel_effect pefx; |
| 3529 |
|
| 3530 |
vector viewer_eye = {0, 0, 0}; |
| 3531 |
matrix viewer_orient = IDENTITY_MATRIX; |
| 3532 |
viewer_eye.z = -ship_pos.cam_dist; |
| 3533 |
|
| 3534 |
// 3d start frame |
| 3535 |
//@@@@@StartFrame(m_X,m_Y,m_X+m_W-1,m_Y+m_H-1); |
| 3536 |
g3_StartFrame(&viewer_eye, &viewer_orient, D3_DEFAULT_ZOOM); |
| 3537 |
rend_SetFlatColor(0); |
| 3538 |
|
| 3539 |
if (ship_model == -1) { |
| 3540 |
mprintf(0, "Shipmodel is -1\n"); |
| 3541 |
return; |
| 3542 |
} |
| 3543 |
|
| 3544 |
float normalized_time[MAX_SUBOBJECTS]; |
| 3545 |
float light_scalar, size; |
| 3546 |
PageInPolymodel(ship_model, OBJ_PLAYER, &size); |
| 3547 |
poly_model *pm = GetPolymodelPointer(ship_model); |
| 3548 |
vector view_pos; |
| 3549 |
vector light_vec; |
| 3550 |
matrix view_orient = IDENTITY_MATRIX; |
| 3551 |
matrix rot_mat = IDENTITY_MATRIX; |
| 3552 |
matrix final_mat = IDENTITY_MATRIX; |
| 3553 |
|
| 3554 |
// draw model. |
| 3555 |
SetNormalizedTimeAnim(0, normalized_time, pm); |
| 3556 |
|
| 3557 |
view_pos = pm->anim_size_offset; |
| 3558 |
|
| 3559 |
// move 30 degrees a sec |
| 3560 |
float new_time = timer_GetTime(); |
| 3561 |
|
| 3562 |
vm_AnglesToMatrix(&rot_mat, 0, (new_time - ship_pos.last_time) * (65535 / 360) * 30, 0); |
| 3563 |
vm_MatrixMul(&view_orient, &rot_mat, &ship_pos.last_frame); |
| 3564 |
vm_Orthogonalize(&view_orient); |
| 3565 |
ship_pos.last_frame = view_orient; |
| 3566 |
|
| 3567 |
light_vec.x = 0.0f; |
| 3568 |
light_vec.y = -1.0f; |
| 3569 |
light_vec.z = -1.0f; |
| 3570 |
light_scalar = 0.8f; |
| 3571 |
vm_NormalizeVector(&light_vec); |
| 3572 |
|
| 3573 |
rend_SetZBufferState(1); |
| 3574 |
rend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 3575 |
rend_SetAlphaValue(255); |
| 3576 |
rend_SetLighting(LS_NONE); |
| 3577 |
rend_SetColorModel(CM_MONO); |
| 3578 |
rend_SetOverlayType(OT_NONE); |
| 3579 |
|
| 3580 |
if (ship_pos.bm_handle > BAD_BITMAP_HANDLE) { |
| 3581 |
if (ship_pos.texture_changed) { |
| 3582 |
memset(&pefx, 0, sizeof(pefx)); |
| 3583 |
pefx.custom_texture = ship_pos.texture_id; |
| 3584 |
pefx.type = PEF_CUSTOM_TEXTURE; |
| 3585 |
ship_pos.texture_changed = false; |
| 3586 |
} |
| 3587 |
|
| 3588 |
SetPolymodelEffect(&pefx); |
| 3589 |
|
| 3590 |
DrawPolygonModel(&view_pos, &view_orient, ship_model, normalized_time, 0, &light_vec, light_scalar, light_scalar, |
| 3591 |
light_scalar, 0xFFFFFFFF, 1); |
| 3592 |
} else { |
| 3593 |
DrawPolygonModel(&view_pos, &view_orient, ship_model, normalized_time, 0, &light_vec, light_scalar, light_scalar, |
| 3594 |
light_scalar); |
| 3595 |
} |
| 3596 |
|
| 3597 |
g3_EndFrame(); |
| 3598 |
//@@@@@@@@@@@EndFrame(); |
| 3599 |
|
| 3600 |
UIStatic::OnDraw(); |
| 3601 |
|
| 3602 |
ship_pos.last_time = new_time; |
| 3603 |
} |
| 3604 |
|
| 3605 |
UIBmpWindow::UIBmpWindow() { |
| 3606 |
animated = false; |
| 3607 |
bm_handle = -1; |
| 3608 |
start_time = timer_GetTime(); |
| 3609 |
created = false; |
| 3610 |
} |
| 3611 |
|
| 3612 |
UIBmpWindow::~UIBmpWindow() {} |
| 3613 |
|
| 3614 |
void UIBmpWindow::SetInfo(bool anim, int handle) { |
| 3615 |
animated = anim; |
| 3616 |
bm_handle = handle; |
| 3617 |
start_time = timer_GetTime(); |
| 3618 |
} |
| 3619 |
|
| 3620 |
void UIBmpWindow::DrawBorder(void) { |
| 3621 |
int minx, maxx, miny, maxy; |
| 3622 |
|
| 3623 |
minx = 0; |
| 3624 |
maxx = m_W - 1; |
| 3625 |
miny = 0; |
| 3626 |
maxy = m_H - 1; |
| 3627 |
|
| 3628 |
rend_SetZBufferState(0); |
| 3629 |
rend_SetFlatColor(GR_RGB(40, 255, 40)); |
| 3630 |
|
| 3631 |
rend_DrawLine(minx, miny, maxx, miny); |
| 3632 |
rend_DrawLine(minx, maxy, maxx, maxy); |
| 3633 |
rend_DrawLine(minx, miny, minx, maxy); |
| 3634 |
rend_DrawLine(maxx, miny, maxx, maxy); |
| 3635 |
|
| 3636 |
rend_SetZBufferState(1); |
| 3637 |
} |
| 3638 |
|
| 3639 |
void UIBmpWindow::OnDraw(void) { |
| 3640 |
int bmh = -1; |
| 3641 |
|
| 3642 |
//@@@@@StartFrame(m_Wnd->X(),m_Wnd->Y(),m_Wnd->X()+m_Wnd->W(),m_Wnd->Y()+m_Wnd->H()); |
| 3643 |
|
| 3644 |
if (bm_handle == -1) { |
| 3645 |
UIStatic::OnDraw(); |
| 3646 |
DrawBorder(); |
| 3647 |
//@@@@@@@@@@@EndFrame(); |
| 3648 |
return; |
| 3649 |
} |
| 3650 |
|
| 3651 |
if (animated) { |
| 3652 |
vclip *vc = &GameVClips[bm_handle]; |
| 3653 |
|
| 3654 |
float elapsed_time = timer_GetTime() - start_time; |
| 3655 |
float interval = 1.0f / 10.0f; |
| 3656 |
int frames_elapsed = (int)(elapsed_time / interval); |
| 3657 |
|
| 3658 |
int frame = frames_elapsed % vc->num_frames; |
| 3659 |
bmh = vc->frames[frame]; |
| 3660 |
} else { |
| 3661 |
bmh = bm_handle; |
| 3662 |
} |
| 3663 |
|
| 3664 |
// draw the bitmap |
| 3665 |
rend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 3666 |
rend_SetAlphaValue(255); |
| 3667 |
rend_SetLighting(LS_NONE); |
| 3668 |
rend_SetColorModel(CM_MONO); |
| 3669 |
rend_SetOverlayType(OT_NONE); |
| 3670 |
rend_SetFiltering(0); |
| 3671 |
|
| 3672 |
int real_x, real_y; |
| 3673 |
|
| 3674 |
real_x = 5; |
| 3675 |
real_y = 5; |
| 3676 |
|
| 3677 |
rend_DrawScaledBitmap(real_x, real_y, real_x + 31, real_y + 31, bmh, 0, 0, 1, 1); |
| 3678 |
|
| 3679 |
rend_SetFiltering(1); |
| 3680 |
|
| 3681 |
UIStatic::OnDraw(); |
| 3682 |
|
| 3683 |
DrawBorder(); |
| 3684 |
//@@@@@@@EndFrame(); |
| 3685 |
} |
| 3686 |
|
| 3687 |
struct { |
| 3688 |
int blank_bmp; |
| 3689 |
int curr_bmp; |
| 3690 |
int curr_index; |
| 3691 |
uint16_t size; |
| 3692 |
uint16_t *id_list; |
| 3693 |
newuiListBox *listbox; |
| 3694 |
UIStatic *bmp_disp; |
| 3695 |
} PPicDlgInfo; |
| 3696 |
|
| 3697 |
void ShowPilotPicDialogListCallback(int index) { |
| 3698 |
if (index == PPicDlgInfo.curr_index) |
| 3699 |
return; |
| 3700 |
|
| 3701 |
int new_idx = index; |
| 3702 |
|
| 3703 |
if (PPicDlgInfo.blank_bmp != PPicDlgInfo.curr_bmp) { |
| 3704 |
bm_FreeBitmap(PPicDlgInfo.curr_bmp); |
| 3705 |
PPicDlgInfo.curr_bmp = -1; |
| 3706 |
} |
| 3707 |
|
| 3708 |
if (index == 0) { |
| 3709 |
//<none> is selected |
| 3710 |
PPicDlgInfo.curr_bmp = PPicDlgInfo.blank_bmp; |
| 3711 |
} else { |
| 3712 |
if (index <= PPicDlgInfo.size) { |
| 3713 |
int handle = PPic_GetBitmapHandle(PPicDlgInfo.id_list[index - 1]); |
| 3714 |
if (handle <= BAD_BITMAP_HANDLE) { |
| 3715 |
mprintf(0, "Couldn't get ID#%d's bitmap\n", PPicDlgInfo.id_list[index - 1]); |
| 3716 |
Int3(); |
| 3717 |
PPicDlgInfo.curr_bmp = PPicDlgInfo.blank_bmp; |
| 3718 |
new_idx = 0; |
| 3719 |
} else { |
| 3720 |
PPicDlgInfo.curr_bmp = handle; |
| 3721 |
} |
| 3722 |
} else { |
| 3723 |
mprintf(0, "Invalid index\n"); |
| 3724 |
Int3(); |
| 3725 |
PPicDlgInfo.curr_bmp = PPicDlgInfo.blank_bmp; |
| 3726 |
new_idx = 0; |
| 3727 |
} |
| 3728 |
} |
| 3729 |
|
| 3730 |
// change the bitmap |
| 3731 |
UIBitmapItem bmp_item(PPicDlgInfo.curr_bmp); |
| 3732 |
PPicDlgInfo.bmp_disp->SetTitle(&bmp_item); |
| 3733 |
|
| 3734 |
PPicDlgInfo.curr_index = new_idx; |
| 3735 |
PPicDlgInfo.listbox->SetCurrentIndex(new_idx); |
| 3736 |
} |
| 3737 |
|
| 3738 |
// ------------------------------------------------------- |
| 3739 |
// ShowPilotPicDialog |
| 3740 |
// Purpose: |
| 3741 |
// Displays the dialog to choose a pilot picture for |
| 3742 |
// the given pilot. |
| 3743 |
// ------------------------------------------------------- |
| 3744 |
void ShowPilotPicDialog(pilot *Pilot) { |
| 3745 |
ASSERT(Pilot); |
| 3746 |
if (!Pilot) |
| 3747 |
return; |
| 3748 |
|
| 3749 |
char pname[PILOT_STRING_SIZE]; |
| 3750 |
|
| 3751 |
Pilot->get_name(pname); |
| 3752 |
|
| 3753 |
uint16_t num_pilots = PPic_QueryPilot(pname); |
| 3754 |
int blank_bmp_handle; |
| 3755 |
|
| 3756 |
// only display the dialog if there is a pilot to choose from |
| 3757 |
if (num_pilots == 0) { |
| 3758 |
mprintf(0, "No Pilot Pics available for %s\n", pname); |
| 3759 |
uint16_t pid; |
| 3760 |
pid = PPIC_INVALID_ID; |
| 3761 |
Pilot->set_multiplayer_data(NULL, NULL, NULL, &pid); |
| 3762 |
|
| 3763 |
DoMessageBox(TXT_ERROR, TXT_NOPICSAVAIL, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 3764 |
return; |
| 3765 |
} |
| 3766 |
|
| 3767 |
blank_bmp_handle = bm_AllocBitmap(64, 64, 0); |
| 3768 |
if (blank_bmp_handle <= BAD_BITMAP_HANDLE) { |
| 3769 |
uint16_t pid; |
| 3770 |
pid = PPIC_INVALID_ID; |
| 3771 |
Pilot->set_multiplayer_data(NULL, NULL, NULL, &pid); |
| 3772 |
|
| 3773 |
mprintf(0, "Couldn't alloc bitmap\n"); |
| 3774 |
DoMessageBox(TXT_ERROR, TXT_ERRCREATINGDIALOG, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 3775 |
return; |
| 3776 |
} |
| 3777 |
uint16_t *data = bm_data(blank_bmp_handle, 0); |
| 3778 |
for (int i = 0; i < 64 * 64; i++) { |
| 3779 |
data[i] = GR_RGB16(0, 0, 0) | OPAQUE_FLAG; |
| 3780 |
} |
| 3781 |
|
| 3782 |
// create the dialog |
| 3783 |
// ----------------- |
| 3784 |
#define DLG_PPIC_W 320 |
| 3785 |
#define DLG_PPIC_H 256 |
| 3786 |
newuiTiledWindow hwnd; |
| 3787 |
newuiSheet *sheet; |
| 3788 |
newuiListBox *list; |
| 3789 |
|
| 3790 |
UIBitmapItem bmp_item(blank_bmp_handle); |
| 3791 |
UIStatic bmp_disp; |
| 3792 |
bool exit_menu = false; |
| 3793 |
|
| 3794 |
hwnd.Create(TXT_PILOTPICTURE, 0, 0, DLG_PPIC_W, DLG_PPIC_H); |
| 3795 |
sheet = hwnd.GetSheet(); |
| 3796 |
|
| 3797 |
sheet->NewGroup(NULL, 0, 0); |
| 3798 |
list = sheet->AddListBox(150, 150, IDP_SAVE, UILB_NOSORT); |
| 3799 |
list->SetSelectChangeCallback(ShowPilotPicDialogListCallback); |
| 3800 |
|
| 3801 |
sheet->NewGroup(TXT_DISPLAY, 175, 0); |
| 3802 |
bmp_disp.Create(&hwnd, &bmp_item, 215, 65, bmp_item.width(), bmp_item.height(), UIF_FIT); |
| 3803 |
|
| 3804 |
sheet->NewGroup(NULL, 170, 145); |
| 3805 |
sheet->AddButton(TXT_OK, UID_OK); |
| 3806 |
|
| 3807 |
// Initialize PPicDlgInfo data |
| 3808 |
// --------------------------- |
| 3809 |
uint16_t *id_list; |
| 3810 |
id_list = (uint16_t *)mem_malloc(num_pilots * sizeof(uint16_t)); |
| 3811 |
|
| 3812 |
if (!id_list) { |
| 3813 |
// out of memory |
| 3814 |
mprintf(0, "Out of memory\n"); |
| 3815 |
goto clean_up; |
| 3816 |
} |
| 3817 |
|
| 3818 |
PPicDlgInfo.curr_bmp = PPicDlgInfo.blank_bmp = blank_bmp_handle; |
| 3819 |
PPicDlgInfo.curr_index = 0; |
| 3820 |
PPicDlgInfo.listbox = list; |
| 3821 |
PPicDlgInfo.bmp_disp = &bmp_disp; |
| 3822 |
PPicDlgInfo.size = num_pilots; |
| 3823 |
PPicDlgInfo.id_list = id_list; |
| 3824 |
|
| 3825 |
// fill in dialog data |
| 3826 |
// ------------------- |
| 3827 |
uint16_t temp_id; |
| 3828 |
int idx; |
| 3829 |
idx = 0; |
| 3830 |
|
| 3831 |
Pilot->get_name(pname); |
| 3832 |
|
| 3833 |
if (PPic_FindFirst(pname, &temp_id)) { |
| 3834 |
id_list[idx] = temp_id; |
| 3835 |
idx++; |
| 3836 |
while (PPic_FindNext(&temp_id)) { |
| 3837 |
id_list[idx] = temp_id; |
| 3838 |
idx++; |
| 3839 |
} |
| 3840 |
} |
| 3841 |
PPic_FindClose(); |
| 3842 |
|
| 3843 |
int selected_index; |
| 3844 |
selected_index = 0; |
| 3845 |
list->AddItem(TXT_NONE); |
| 3846 |
|
| 3847 |
char temp_buffer[PILOT_STRING_SIZE + 6]; |
| 3848 |
uint16_t ppic_id; |
| 3849 |
Pilot->get_multiplayer_data(NULL, NULL, NULL, &ppic_id); |
| 3850 |
|
| 3851 |
Pilot->get_name(pname); |
| 3852 |
|
| 3853 |
if (num_pilots > 1) { |
| 3854 |
for (idx = 0; idx < num_pilots; idx++) { |
| 3855 |
|
| 3856 |
if (ppic_id == id_list[idx]) |
| 3857 |
selected_index = idx + 1; |
| 3858 |
|
| 3859 |
std::snprintf(temp_buffer, PILOT_STRING_SIZE + 6, "%s%d", pname, idx); |
| 3860 |
list->AddItem(temp_buffer); |
| 3861 |
} |
| 3862 |
} else { |
| 3863 |
if (ppic_id == id_list[idx]) |
| 3864 |
selected_index = idx + 1; |
| 3865 |
|
| 3866 |
std::snprintf(temp_buffer, PILOT_STRING_SIZE + 6, "%s", pname); |
| 3867 |
list->AddItem(temp_buffer); |
| 3868 |
} |
| 3869 |
|
| 3870 |
ShowPilotPicDialogListCallback(selected_index); |
| 3871 |
|
| 3872 |
// display dialog |
| 3873 |
// -------------- |
| 3874 |
hwnd.Open(); |
| 3875 |
while (!exit_menu) { |
| 3876 |
int res = hwnd.DoUI(); |
| 3877 |
|
| 3878 |
// handle all UI results. |
| 3879 |
switch (res) { |
| 3880 |
case UID_OK: |
| 3881 |
exit_menu = true; |
| 3882 |
break; |
| 3883 |
}; |
| 3884 |
} |
| 3885 |
|
| 3886 |
selected_index = list->GetCurrentIndex(); |
| 3887 |
uint16_t pid; |
| 3888 |
if (selected_index == 0) { |
| 3889 |
pid = PPIC_INVALID_ID; |
| 3890 |
} else { |
| 3891 |
pid = id_list[selected_index - 1]; |
| 3892 |
} |
| 3893 |
Pilot->set_multiplayer_data(NULL, NULL, NULL, &pid); |
| 3894 |
|
| 3895 |
hwnd.Close(); |
| 3896 |
hwnd.Destroy(); |
| 3897 |
|
| 3898 |
clean_up: |
| 3899 |
// free data |
| 3900 |
// --------- |
| 3901 |
if ((PPicDlgInfo.curr_bmp != PPicDlgInfo.blank_bmp) && (PPicDlgInfo.curr_bmp > BAD_BITMAP_HANDLE)) |
| 3902 |
bm_FreeBitmap(PPicDlgInfo.curr_bmp); |
| 3903 |
|
| 3904 |
bm_FreeBitmap(blank_bmp_handle); |
| 3905 |
|
| 3906 |
if (id_list) { |
| 3907 |
mem_free(id_list); |
| 3908 |
} |
| 3909 |
} |
| 3910 |
|
| 3911 |
// "Current Pilot" access functions |
| 3912 |
void dCurrentPilotName(char *buffer) { Current_pilot.get_name(buffer); } |
| 3913 |
uint8_t dCurrentPilotDifficulty(void) { |
| 3914 |
uint8_t d; |
| 3915 |
Current_pilot.get_difficulty(&d); |
| 3916 |
return d; |
| 3917 |
} |
| 3918 |
|
| 3919 |
///////////////////////////////////////////////////////////////////// |
| 3920 |
void _ReadOldPilotFile(pilot *Pilot, bool keyconfig, bool missiondata) { |
| 3921 |
char filename[_MAX_PATH]; |
| 3922 |
char pfilename[_MAX_FNAME]; |
| 3923 |
char buffer[256]; |
| 3924 |
uint8_t temp_b; |
| 3925 |
uint16_t temp_s; |
| 3926 |
int temp_i; |
| 3927 |
int filever, i, nctlfuncs; |
| 3928 |
|
| 3929 |
Pilot->get_filename(pfilename); |
| 3930 |
|
| 3931 |
// open and process file |
| 3932 |
ddio_MakePath(filename, Base_directory_write, pfilename, NULL); |
| 3933 |
CFILE *file = cfopen(filename, "rb"); |
| 3934 |
if (!file) |
| 3935 |
return; |
| 3936 |
|
| 3937 |
filever = cf_ReadInt(file); |
| 3938 |
|
| 3939 |
if (filever < 0x12) { |
| 3940 |
cfclose(file); |
| 3941 |
Error(TXT_PLTTOOOLD); |
| 3942 |
return; |
| 3943 |
} |
| 3944 |
|
| 3945 |
if (filever > PLTFILEVERSION) { |
| 3946 |
// we're reading in a version that's newer than we have |
| 3947 |
cfclose(file); |
| 3948 |
Error(TXT_PLTTOONEW, pfilename); |
| 3949 |
return; |
| 3950 |
} |
| 3951 |
|
| 3952 |
Pilot->clean(true); |
| 3953 |
Pilot->set_filename(pfilename); |
| 3954 |
|
| 3955 |
cf_ReadString(buffer, PILOT_STRING_SIZE + 1, file); |
| 3956 |
Pilot->set_name(buffer); |
| 3957 |
|
| 3958 |
cf_ReadInt(file); |
| 3959 |
cf_ReadInt(file); |
| 3960 |
|
| 3961 |
cf_ReadString(buffer, PAGENAME_LEN + 1, file); |
| 3962 |
Pilot->set_ship(buffer); |
| 3963 |
|
| 3964 |
cf_ReadString(buffer, PAGENAME_LEN + 1, file); |
| 3965 |
Pilot->set_multiplayer_data(buffer); |
| 3966 |
|
| 3967 |
temp_b = cf_ReadByte(file); |
| 3968 |
Pilot->set_difficulty(temp_b); |
| 3969 |
|
| 3970 |
// load hud info |
| 3971 |
temp_b = cf_ReadByte(file); |
| 3972 |
Pilot->set_hud_data(&temp_b); |
| 3973 |
|
| 3974 |
temp_s = cf_ReadShort(file); |
| 3975 |
Pilot->set_hud_data(NULL, &temp_s); |
| 3976 |
|
| 3977 |
temp_s = cf_ReadShort(file); |
| 3978 |
Pilot->set_hud_data(NULL, NULL, &temp_s); |
| 3979 |
|
| 3980 |
// read in audio taunts |
| 3981 |
cf_ReadString(buffer, PAGENAME_LEN + 1, file); |
| 3982 |
Pilot->set_multiplayer_data(NULL, buffer); |
| 3983 |
|
| 3984 |
cf_ReadString(buffer, PAGENAME_LEN + 1, file); |
| 3985 |
Pilot->set_multiplayer_data(NULL, NULL, buffer); |
| 3986 |
|
| 3987 |
// added in version 0x9 |
| 3988 |
int n; |
| 3989 |
uint16_t widx; |
| 3990 |
n = (int)cf_ReadByte(file); |
| 3991 |
for (i = 0; i < n; i++) { |
| 3992 |
widx = (uint16_t)cf_ReadShort(file); |
| 3993 |
SetAutoSelectPrimaryWpnIdx(i, widx); |
| 3994 |
} |
| 3995 |
n = (int)cf_ReadByte(file); |
| 3996 |
for (i = 0; i < n; i++) { |
| 3997 |
widx = (uint16_t)cf_ReadShort(file); |
| 3998 |
SetAutoSelectSecondaryWpnIdx(i, widx); |
| 3999 |
} |
| 4000 |
|
| 4001 |
temp_i = cf_ReadInt(file); |
| 4002 |
Pilot->set_hud_data(NULL, NULL, NULL, &temp_i); |
| 4003 |
temp_i = cf_ReadInt(file); |
| 4004 |
Pilot->set_hud_data(NULL, NULL, NULL, NULL, &temp_i); |
| 4005 |
|
| 4006 |
for (i = 0; i < N_MOUSE_AXIS; i++) |
| 4007 |
Pilot->mouse_sensitivity[i] = cf_ReadFloat(file); |
| 4008 |
for (i = 0; i < N_JOY_AXIS; i++) |
| 4009 |
Pilot->joy_sensitivity[i] = cf_ReadFloat(file); |
| 4010 |
|
| 4011 |
temp_s = cf_ReadShort(file); |
| 4012 |
Pilot->set_multiplayer_data(NULL, NULL, NULL, &temp_s); |
| 4013 |
|
| 4014 |
// skip over mission data |
| 4015 |
int count = cf_ReadInt(file); |
| 4016 |
if (count > 0) { |
| 4017 |
for (i = 0; i < count; i++) { |
| 4018 |
char dummy[256]; |
| 4019 |
int length; |
| 4020 |
cf_ReadByte(file); |
| 4021 |
if (filever >= 0x11) { |
| 4022 |
cf_ReadByte(file); |
| 4023 |
} |
| 4024 |
length = cf_ReadByte(file); |
| 4025 |
if (length) { |
| 4026 |
cf_ReadBytes((uint8_t *)dummy, length, file); |
| 4027 |
} |
| 4028 |
} |
| 4029 |
} |
| 4030 |
|
| 4031 |
// key/joy config MUST stay at the end of the file |
| 4032 |
Pilot->read_controller = cf_ReadByte(file); |
| 4033 |
|
| 4034 |
// needed to properly map functions between pilot versions |
| 4035 |
nctlfuncs = (filever >= 0xe) ? cf_ReadByte(file) : NUM_CTLFUNCS_DEMOv1_0; |
| 4036 |
|
| 4037 |
for (i = 0; i < nctlfuncs; i++) { |
| 4038 |
int id = cf_ReadInt(file); |
| 4039 |
ct_type type[2]; |
| 4040 |
ct_config_data value; |
| 4041 |
int y; |
| 4042 |
|
| 4043 |
type[0] = (ct_type)cf_ReadInt(file); |
| 4044 |
type[1] = (ct_type)cf_ReadInt(file); |
| 4045 |
value = (ct_config_data)cf_ReadInt(file); |
| 4046 |
for (y = 0; y < nctlfuncs; y++) |
| 4047 |
if (Controller_needs[y].id == id) { |
| 4048 |
if (type[0] == ctNone) // do this if there are new functions that don't have ctNone. |
| 4049 |
type[0] = Controller_needs[y].ctype[0]; |
| 4050 |
if (type[1] == ctNone) // do this if there are new functions that don't have ctNone. |
| 4051 |
type[1] = Controller_needs[y].ctype[1]; |
| 4052 |
break; |
| 4053 |
} |
| 4054 |
|
| 4055 |
Pilot->controls[y].id = id; |
| 4056 |
Pilot->controls[y].type[0] = type[0]; |
| 4057 |
Pilot->controls[y].type[1] = type[1]; |
| 4058 |
Pilot->controls[y].value = value; |
| 4059 |
|
| 4060 |
// new flags for each controller item. |
| 4061 |
if (filever >= 0xb) { |
| 4062 |
Pilot->controls[y].flags[0] = (uint8_t)cf_ReadByte(file); |
| 4063 |
Pilot->controls[y].flags[1] = (uint8_t)cf_ReadByte(file); |
| 4064 |
} |
| 4065 |
|
| 4066 |
if (keyconfig) |
| 4067 |
Controller->set_controller_function(Pilot->controls[y].id, Pilot->controls[y].type, Pilot->controls[y].value, |
| 4068 |
Pilot->controls[y].flags); |
| 4069 |
} |
| 4070 |
|
| 4071 |
// fill in remainder of pilot controls array. |
| 4072 |
for (; i < NUM_CONTROLLER_FUNCTIONS; i++) { |
| 4073 |
Controller->get_controller_function(Controller_needs[i].id, Pilot->controls[i].type, &Pilot->controls[i].value, |
| 4074 |
Pilot->controls[i].flags); |
| 4075 |
} |
| 4076 |
|
| 4077 |
if (Controller) { |
| 4078 |
Controller->mask_controllers((Current_pilot.read_controller & READF_JOY) ? true : false, |
| 4079 |
(Current_pilot.read_controller & READF_MOUSE) ? true : false); |
| 4080 |
} |
| 4081 |
|
| 4082 |
// Read taunts if there |
| 4083 |
for (i = 0; i < MAX_PILOT_TAUNTS; i++) |
| 4084 |
cf_ReadString(Pilot->taunts[i], PILOT_TAUNT_SIZE, file); |
| 4085 |
|
| 4086 |
cfclose(file); |
| 4087 |
} |