| 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/manage/shippage.cpp $ |
| 21 | * $Revision: 46 $ |
| 22 | * $Date: 10/22/01 12:41p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * $Log: /DescentIII/Main/manage/shippage.cpp $ |
| 26 | * |
| 27 | * 46 10/22/01 12:41p Matt |
| 28 | * After loading a ship model to check for errors, unload it so it can get |
| 29 | * loaded again later after the textures have been read in. |
| 30 | * |
| 31 | * 45 10/08/01 4:20p Matt |
| 32 | * Added system to check for errors when reading in add-on data. |
| 33 | * |
| 34 | * 44 9/06/01 10:32a Matt |
| 35 | * Added code to fix problem poping add-on pages when the original pages |
| 36 | * were in the extra.gam file. |
| 37 | * |
| 38 | * 43 4/19/00 5:07p Matt |
| 39 | * From Duane for 1.4 |
| 40 | * Added checks, asserts, and fixes for bad return values |
| 41 | * |
| 42 | * 42 10/26/99 3:30p Jeff |
| 43 | * handle extra.gam addon tablefile |
| 44 | * |
| 45 | * 41 10/20/99 6:27p Jeff |
| 46 | * sped up addon page popping (by saving page offsets) |
| 47 | * |
| 48 | * 40 10/20/99 1:30p Jeff |
| 49 | * fixed fusion recharge hack |
| 50 | * |
| 51 | * 39 8/11/99 5:32p Jeff |
| 52 | * changes to fix addon tablefile support so it works correctly |
| 53 | * |
| 54 | * 38 7/27/99 1:14p Jason |
| 55 | * fixed fusion firing time |
| 56 | * |
| 57 | * 37 5/14/99 11:56a Jeff |
| 58 | * fixed copy/paste bug (Jason) |
| 59 | * |
| 60 | * 36 4/14/99 1:33a Jeff |
| 61 | * fixed case mismatched #includes |
| 62 | * |
| 63 | * 35 3/04/99 4:47p Jason |
| 64 | * temp fix (ie BAD HACK) for OEM table file woes |
| 65 | * |
| 66 | * 34 1/13/99 7:05a Jeff |
| 67 | * put #ifdef around #include <windows.h> |
| 68 | * |
| 69 | * 33 12/29/98 4:30p Jason |
| 70 | * added add-on data functionality |
| 71 | * |
| 72 | * 32 11/13/98 12:30p Jason |
| 73 | * changes for weapons |
| 74 | * |
| 75 | * 31 11/06/98 12:35p Jason |
| 76 | * more speedups for manage system |
| 77 | * |
| 78 | * 30 11/05/98 7:55p Jason |
| 79 | * changes for new manage system |
| 80 | * |
| 81 | * 29 11/03/98 6:16p Chris |
| 82 | * Starting to make on/off and spray weapons accessable to robots |
| 83 | * |
| 84 | * 28 11/02/98 6:02p Jason |
| 85 | * made yes network updates much faster |
| 86 | * |
| 87 | * 27 10/13/98 12:56p Matt |
| 88 | * Finished (hopefully) with the ammo system. Added support for napalm |
| 89 | * fuel. |
| 90 | * |
| 91 | * 26 10/09/98 2:27p Jason |
| 92 | * reorganized table file system |
| 93 | * |
| 94 | * 25 10/02/98 1:47p Jason |
| 95 | * added lod player ships |
| 96 | * |
| 97 | * 24 10/01/98 11:51a Matt |
| 98 | * When loading or saving the player ship page, check for spew powerups |
| 99 | * that aren't powerups & fix them. |
| 100 | * |
| 101 | * 23 9/21/98 8:19p Chris |
| 102 | * Improved volatile and forcefield hits |
| 103 | * |
| 104 | * 22 9/10/98 11:53a Jason |
| 105 | * added hud config filename to ship page |
| 106 | * |
| 107 | * 21 8/24/98 2:37p Jason |
| 108 | * made table file more efficient with regards to invalid names |
| 109 | * |
| 110 | * 20 8/14/98 5:25p Jeff |
| 111 | * fixed stupid bug setting wrong varible (nothing dangerous) |
| 112 | * |
| 113 | * 19 8/14/98 4:56p Jeff |
| 114 | * added quad fire mask for weapon battery |
| 115 | * |
| 116 | * 18 8/07/98 2:06p Jason |
| 117 | * now saves flags field |
| 118 | * |
| 119 | * 17 7/31/98 5:23p Jason |
| 120 | * added ship armor scalars |
| 121 | * |
| 122 | * 16 6/01/98 10:37a Matt |
| 123 | * Added system to spew powerups when the player dies. Still needs Jason |
| 124 | * to deal with mng_FindSpecificGenericPage(). |
| 125 | * |
| 126 | * 15 5/04/98 6:08p Jason |
| 127 | * sped up predictive pagefile loading |
| 128 | * |
| 129 | * 14 4/02/98 3:54p Jason |
| 130 | * first pass in getting polymodel paging to work |
| 131 | * |
| 132 | * 13 3/19/98 1:07p Jason |
| 133 | * added cockpit name |
| 134 | * |
| 135 | * 12 2/23/98 1:22p Jason |
| 136 | * made FindSpecific* read from the local drive, not the net drive - when |
| 137 | * starting the editor |
| 138 | * |
| 139 | * 11 2/17/98 8:12p Matt |
| 140 | * Added looping & release sounds for player weapons |
| 141 | * |
| 142 | * 10 1/23/98 6:25p Jason |
| 143 | * Got spray weapons working |
| 144 | * |
| 145 | * 9 1/15/98 6:22p Jason |
| 146 | * added safety checks so the network won't copy over a primitive you have |
| 147 | * held locally |
| 148 | * |
| 149 | * 8 12/22/97 6:19p Chris |
| 150 | * Moved weapon battery firing sound off the projectile (weapon) and into |
| 151 | * the weapon battery. |
| 152 | * |
| 153 | * 7 11/12/97 5:35p Jason |
| 154 | * made energy/ammo usage work with weapon batteries |
| 155 | * |
| 156 | * 6 11/12/97 1:13p Jason |
| 157 | * added weapons that can ramp up |
| 158 | * |
| 159 | * 5 11/05/97 12:22p Chris |
| 160 | * Fixed size of wb_info in the page file |
| 161 | * |
| 162 | * 4 11/05/97 10:45a Chris |
| 163 | * Now init's the ship struct to zero (and fills in some values) before |
| 164 | * reading. |
| 165 | * |
| 166 | * 3 11/04/97 6:18p Chris |
| 167 | * Added support so that the player ship uses the robot's firing dialog. |
| 168 | * |
| 169 | * 2 10/21/97 11:57a Jason |
| 170 | * added ability to set dying model for player ship |
| 171 | * |
| 172 | * 8 5/08/97 12:41p Jason |
| 173 | * made manage system work with device dependant path names |
| 174 | * |
| 175 | * 7 4/25/97 6:16p Jason |
| 176 | * added switcheroo function |
| 177 | * |
| 178 | * 6 4/09/97 9:57p Chris |
| 179 | * Added more ability to customize ships/objects. |
| 180 | * |
| 181 | * 5 4/08/97 1:16a Chris |
| 182 | * Fixed the bug with initial values for some items being random. It also |
| 183 | * fixed a intermitent bug that was caused because the used flag was |
| 184 | * random... we wanted it to be 1 (non-zero), but it was random so there |
| 185 | * was a chance it could be zero(1 in 2^(sizeof(used_flag))) |
| 186 | * |
| 187 | * 4 4/07/97 3:13p Chris |
| 188 | * |
| 189 | * 3 4/04/97 2:44p Matt |
| 190 | * Changed object pages to store physics info in a physics_info structure. |
| 191 | * |
| 192 | * 2 3/31/97 4:34p Jason |
| 193 | * added player ship page |
| 194 | * |
| 195 | * 1 3/31/97 12:10p Jason |
| 196 | * Page file for player ship management |
| 197 | * |
| 198 | * $NoKeywords: $ |
| 199 | */ |
| 200 | |
| 201 | #include <cstring> |
| 202 | #include <filesystem> |
| 203 | |
| 204 | #include "cfile.h" |
| 205 | #include "manage.h" |
| 206 | #include "ship.h" |
| 207 | #include "shippage.h" |
| 208 | #include "mono.h" |
| 209 | #include "pserror.h" |
| 210 | #include "polymodel.h" |
| 211 | #include "ddio.h" |
| 212 | #include "robotfire.h" |
| 213 | #include "weaponpage.h" |
| 214 | #include "soundload.h" |
| 215 | #include "sounds.h" |
| 216 | #include "soundpage.h" |
| 217 | #include "genericpage.h" |
| 218 | #include "args.h" |
| 219 | |
| 220 | // shippage commands that are read/written |
| 221 | // A command is followed by a byte count describing how many bytes |
| 222 | // are in the data for the command |
| 223 | #define SHIPPAGE_COMMAND_NAME 1 |
| 224 | #define SHIPPAGE_COMMAND_END 2 |
| 225 | #define SHIPPAGE_COMMAND_IMAGE_NAME 3 |
| 226 | #define SHIPPAGE_COMMAND_VERSION 4 |
| 227 | #define SHIPPAGE_COMMAND_MASS 5 |
| 228 | #define SHIPPAGE_COMMAND_DRAG 6 |
| 229 | #define SHIPPAGE_COMMAND_SIZE 7 |
| 230 | #define SHIPPAGE_COMMAND_WIGGLE_AMPLITUDE 8 |
| 231 | #define SHIPPAGE_COMMAND_THRUST 9 |
| 232 | #define SHIPPAGE_COMMAND_ROTTHRUST 10 |
| 233 | #define SHIPPAGE_COMMAND_TURNROLLRATE 11 |
| 234 | #define SHIPPAGE_COMMAND_ROTDRAG 12 |
| 235 | #define SHIPPAGE_COMMAND_PHYSICS_FLAGS 13 |
| 236 | #define SHIPPAGE_COMMAND_WIGGLE_PER_SEC 14 |
| 237 | #define SHIPPAGE_COMMAND_TURNROLL_RATIO 15 |
| 238 | #define SHIPPAGE_COMMAND_DYING_IMAGE_NAME 16 |
| 239 | #define SHIPPAGE_COMMAND_WB_INFO 17 |
| 240 | #define SHIPPAGE_COMMAND_WB_WEAPON 18 |
| 241 | #define SHIPPAGE_COMMAND_FIRE_FLAGS 19 |
| 242 | #define SHIPPAGE_COMMAND_RESOURCE_USAGE 20 |
| 243 | #define SHIPPAGE_COMMAND_WB_FIRE_SOUND 21 |
| 244 | #define SHIPPAGE_COMMAND_WB_FLAGS 22 |
| 245 | #define SHIPPAGE_COMMAND_FIRING_SOUND 23 |
| 246 | #define SHIPPAGE_COMMAND_RELEASE_SOUND 24 |
| 247 | #define SHIPPAGE_COMMAND_COCKPIT_NAME 25 |
| 248 | #define SHIPPAGE_COMMAND_SPEW_POWERUP 26 |
| 249 | #define SHIPPAGE_COMMAND_ARMOR_SCALAR 27 |
| 250 | #define SHIPPAGE_COMMAND_FLAGS 28 |
| 251 | #define SHIPPAGE_COMMAND_WB_QUADMASK 29 |
| 252 | #define SHIPPAGE_COMMAND_HUD_NAME 30 |
| 253 | #define SHIPPAGE_COMMAND_LOD_MODELS 31 |
| 254 | #define SHIPPAGE_COMMAND_LOD_DISTANCE 32 |
| 255 | #define SHIPPAGE_COMMAND_MAX_AMMO 33 |
| 256 | |
| 257 | #define SHIPPAGE_VERSION 6 |
| 258 | |
| 259 | extern char *TablefileNameOverride; |
| 260 | |
| 261 | // Given an open file pointer and a ship_page struct, writes that ship page out |
| 262 | void mng_WriteShipPage(CFILE *outfile, mngs_ship_page *shippage) { |
| 263 | int i; |
| 264 | int j; |
| 265 | int size; |
| 266 | |
| 267 | ASSERT(outfile != NULL); |
| 268 | ASSERT(shippage != NULL); |
| 269 | |
| 270 | cf_WriteByte(outfile, PAGETYPE_SHIP); |
| 271 | |
| 272 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_VERSION); |
| 273 | cf_WriteByte(outfile, 1); |
| 274 | cf_WriteByte(outfile, SHIPPAGE_VERSION); |
| 275 | |
| 276 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_NAME); // write out ship name |
| 277 | cf_WriteByte(outfile, PAGENAME_LEN); |
| 278 | for (i = 0; i < PAGENAME_LEN; i++) |
| 279 | cf_WriteByte(outfile, shippage->ship_struct.name[i]); |
| 280 | |
| 281 | // Write out cockpit name |
| 282 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_COCKPIT_NAME); // write out ship name |
| 283 | cf_WriteByte(outfile, strlen(shippage->ship_struct.cockpit_name) + 1); |
| 284 | cf_WriteString(outfile, shippage->ship_struct.cockpit_name); |
| 285 | |
| 286 | // Write out hud config name |
| 287 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_HUD_NAME); // write out ship name |
| 288 | cf_WriteByte(outfile, strlen(shippage->ship_struct.hud_config_name) + 1); |
| 289 | cf_WriteString(outfile, shippage->ship_struct.hud_config_name); |
| 290 | |
| 291 | // Write out its models name |
| 292 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_IMAGE_NAME); // get ready to write out name |
| 293 | cf_WriteByte(outfile, PAGENAME_LEN); |
| 294 | for (i = 0; i < PAGENAME_LEN; i++) |
| 295 | cf_WriteByte(outfile, shippage->image_name[i]); |
| 296 | |
| 297 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_DYING_IMAGE_NAME); // get ready to write out name |
| 298 | cf_WriteByte(outfile, strlen(shippage->dying_image_name) + 1); |
| 299 | cf_WriteString(outfile, shippage->dying_image_name); |
| 300 | |
| 301 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_MASS); |
| 302 | cf_WriteByte(outfile, 4); |
| 303 | cf_WriteFloat(outfile, shippage->ship_struct.phys_info.mass); |
| 304 | |
| 305 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_DRAG); |
| 306 | cf_WriteByte(outfile, 4); |
| 307 | cf_WriteFloat(outfile, shippage->ship_struct.phys_info.drag); |
| 308 | |
| 309 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_SIZE); |
| 310 | cf_WriteByte(outfile, 4); |
| 311 | cf_WriteFloat(outfile, shippage->ship_struct.size); |
| 312 | |
| 313 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_WIGGLE_AMPLITUDE); |
| 314 | cf_WriteByte(outfile, 4); |
| 315 | cf_WriteFloat(outfile, shippage->ship_struct.phys_info.wiggle_amplitude); |
| 316 | |
| 317 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_THRUST); |
| 318 | cf_WriteByte(outfile, 4); |
| 319 | cf_WriteFloat(outfile, shippage->ship_struct.phys_info.full_thrust); |
| 320 | |
| 321 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_ROTTHRUST); |
| 322 | cf_WriteByte(outfile, 4); |
| 323 | cf_WriteFloat(outfile, shippage->ship_struct.phys_info.full_rotthrust); |
| 324 | |
| 325 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_TURNROLLRATE); |
| 326 | cf_WriteByte(outfile, 4); |
| 327 | cf_WriteFloat(outfile, shippage->ship_struct.phys_info.max_turnroll_rate); |
| 328 | |
| 329 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_ROTDRAG); |
| 330 | cf_WriteByte(outfile, 4); |
| 331 | cf_WriteFloat(outfile, shippage->ship_struct.phys_info.rotdrag); |
| 332 | |
| 333 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_WIGGLE_PER_SEC); |
| 334 | cf_WriteByte(outfile, 4); |
| 335 | cf_WriteFloat(outfile, shippage->ship_struct.phys_info.wiggles_per_sec); |
| 336 | |
| 337 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_TURNROLL_RATIO); |
| 338 | cf_WriteByte(outfile, 4); |
| 339 | cf_WriteFloat(outfile, shippage->ship_struct.phys_info.turnroll_ratio); |
| 340 | |
| 341 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_PHYSICS_FLAGS); |
| 342 | cf_WriteByte(outfile, 4); |
| 343 | cf_WriteInt(outfile, shippage->ship_struct.phys_info.flags); |
| 344 | |
| 345 | // Write the LOD model names |
| 346 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_LOD_MODELS); |
| 347 | size = strlen(shippage->med_image_name) + 1; |
| 348 | size += strlen(shippage->lo_image_name) + 1; |
| 349 | |
| 350 | cf_WriteByte(outfile, size); |
| 351 | cf_WriteString(outfile, shippage->med_image_name); |
| 352 | cf_WriteString(outfile, shippage->lo_image_name); |
| 353 | |
| 354 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_LOD_DISTANCE); |
| 355 | cf_WriteByte(outfile, 8); |
| 356 | cf_WriteFloat(outfile, shippage->ship_struct.med_lod_distance); |
| 357 | cf_WriteFloat(outfile, shippage->ship_struct.lo_lod_distance); |
| 358 | |
| 359 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_ARMOR_SCALAR); |
| 360 | cf_WriteByte(outfile, 4); |
| 361 | cf_WriteFloat(outfile, shippage->ship_struct.armor_scalar); |
| 362 | |
| 363 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_FLAGS); |
| 364 | cf_WriteByte(outfile, 4); |
| 365 | cf_WriteInt(outfile, shippage->ship_struct.flags); |
| 366 | |
| 367 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 368 | int j; |
| 369 | int size; |
| 370 | |
| 371 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_WB_INFO); |
| 372 | size = sizeof(otype_wb_info); |
| 373 | size++; // add a byte for the wb index |
| 374 | |
| 375 | cf_WriteByte(outfile, size); |
| 376 | |
| 377 | cf_WriteByte(outfile, i); |
| 378 | for (j = 0; j < MAX_WB_GUNPOINTS; j++) |
| 379 | cf_WriteShort(outfile, shippage->ship_struct.static_wb[i].gp_weapon_index[j]); |
| 380 | cf_WriteShort(outfile, shippage->ship_struct.static_wb[i].aiming_gp_index); |
| 381 | |
| 382 | cf_WriteByte(outfile, shippage->ship_struct.static_wb[i].num_masks); |
| 383 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) |
| 384 | cf_WriteByte(outfile, shippage->ship_struct.static_wb[i].gp_fire_masks[j]); |
| 385 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) |
| 386 | cf_WriteFloat(outfile, shippage->ship_struct.static_wb[i].gp_fire_wait[j]); |
| 387 | |
| 388 | cf_WriteByte(outfile, shippage->ship_struct.static_wb[i].aiming_flags); |
| 389 | cf_WriteFloat(outfile, shippage->ship_struct.static_wb[i].aiming_3d_dot); |
| 390 | cf_WriteFloat(outfile, shippage->ship_struct.static_wb[i].aiming_3d_dist); |
| 391 | cf_WriteFloat(outfile, shippage->ship_struct.static_wb[i].aiming_XZ_dot); |
| 392 | } |
| 393 | |
| 394 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_WB_FLAGS); |
| 395 | cf_WriteByte(outfile, MAX_PLAYER_WEAPONS); |
| 396 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) |
| 397 | cf_WriteByte(outfile, shippage->ship_struct.static_wb[i].flags); |
| 398 | |
| 399 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_WB_QUADMASK); |
| 400 | cf_WriteByte(outfile, MAX_PLAYER_WEAPONS); |
| 401 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) |
| 402 | cf_WriteByte(outfile, shippage->ship_struct.static_wb[i].gp_quad_fire_mask); |
| 403 | |
| 404 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 405 | for (j = 0; j < MAX_WB_GUNPOINTS; j++) { |
| 406 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_WB_WEAPON); |
| 407 | size = strlen(shippage->weapon_name[i][j]) + 1 + 2; // 1 for the null charactor and 2 for the 2 indices |
| 408 | |
| 409 | cf_WriteByte(outfile, size); |
| 410 | |
| 411 | cf_WriteByte(outfile, i); |
| 412 | cf_WriteByte(outfile, j); |
| 413 | cf_WriteString(outfile, shippage->weapon_name[i][j]); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 418 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) { |
| 419 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_WB_FIRE_SOUND); |
| 420 | size = strlen(shippage->fire_sound_name[i][j]) + 1 + 2; // 1 for the null charactor and 2 for the 2 indices |
| 421 | |
| 422 | cf_WriteByte(outfile, size); |
| 423 | |
| 424 | cf_WriteByte(outfile, i); |
| 425 | cf_WriteByte(outfile, j); |
| 426 | cf_WriteString(outfile, shippage->fire_sound_name[i][j]); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 431 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_FIRE_FLAGS); |
| 432 | cf_WriteByte(outfile, 2); |
| 433 | |
| 434 | cf_WriteByte(outfile, i); |
| 435 | cf_WriteByte(outfile, shippage->ship_struct.fire_flags[i]); |
| 436 | } |
| 437 | |
| 438 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 439 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_RESOURCE_USAGE); |
| 440 | cf_WriteByte(outfile, 9); |
| 441 | |
| 442 | cf_WriteByte(outfile, i); |
| 443 | cf_WriteFloat(outfile, shippage->ship_struct.static_wb[i].energy_usage); |
| 444 | cf_WriteFloat(outfile, shippage->ship_struct.static_wb[i].ammo_usage); |
| 445 | } |
| 446 | |
| 447 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 448 | if (shippage->firing_sound_name[i][0] != 0) { |
| 449 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_FIRING_SOUND); |
| 450 | size = strlen(shippage->firing_sound_name[i]) + 1 + 1; // 1 for the null charactor and 1 for the index |
| 451 | cf_WriteByte(outfile, size); |
| 452 | cf_WriteByte(outfile, i); |
| 453 | cf_WriteString(outfile, shippage->firing_sound_name[i]); |
| 454 | } |
| 455 | } |
| 456 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 457 | if (shippage->release_sound_name[i][0] != 0) { |
| 458 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_RELEASE_SOUND); |
| 459 | size = strlen(shippage->release_sound_name[i]) + 1 + 1; // 1 for the null charactor and 1 for the index |
| 460 | cf_WriteByte(outfile, size); |
| 461 | cf_WriteByte(outfile, i); |
| 462 | cf_WriteString(outfile, shippage->release_sound_name[i]); |
| 463 | } |
| 464 | } |
| 465 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 466 | if (shippage->spew_powerup_name[i][0] != 0) { |
| 467 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_SPEW_POWERUP); |
| 468 | size = strlen(shippage->spew_powerup_name[i]) + 1 + 1; // 1 for the null charactor and 1 for the index |
| 469 | cf_WriteByte(outfile, size); |
| 470 | cf_WriteByte(outfile, i); |
| 471 | cf_WriteString(outfile, shippage->spew_powerup_name[i]); |
| 472 | } |
| 473 | } |
| 474 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 475 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_MAX_AMMO); |
| 476 | cf_WriteByte(outfile, 5); |
| 477 | |
| 478 | cf_WriteByte(outfile, i); |
| 479 | cf_WriteInt(outfile, shippage->ship_struct.max_ammo[i]); |
| 480 | } |
| 481 | |
| 482 | cf_WriteByte(outfile, SHIPPAGE_COMMAND_END); // we're all done |
| 483 | cf_WriteByte(outfile, 0); |
| 484 | } |
| 485 | |
| 486 | // Given an open file pointer and a ship_page struct, writes that ship page out |
| 487 | void mng_WriteNewShipPage(CFILE *outfile, mngs_ship_page *shippage) { |
| 488 | int i; |
| 489 | |
| 490 | ASSERT(outfile != NULL); |
| 491 | ASSERT(shippage != NULL); |
| 492 | |
| 493 | int offset = StartManagePage(outfile, PAGETYPE_SHIP); |
| 494 | |
| 495 | cf_WriteShort(outfile, SHIPPAGE_VERSION); |
| 496 | |
| 497 | cf_WriteString(outfile, shippage->ship_struct.name); |
| 498 | |
| 499 | cf_WriteString(outfile, shippage->ship_struct.cockpit_name); |
| 500 | |
| 501 | cf_WriteString(outfile, shippage->ship_struct.hud_config_name); |
| 502 | |
| 503 | // Write out its models name |
| 504 | cf_WriteString(outfile, shippage->image_name); |
| 505 | cf_WriteString(outfile, shippage->dying_image_name); |
| 506 | cf_WriteString(outfile, shippage->med_image_name); |
| 507 | cf_WriteString(outfile, shippage->lo_image_name); |
| 508 | |
| 509 | // Write out lod distance |
| 510 | cf_WriteFloat(outfile, shippage->ship_struct.med_lod_distance); |
| 511 | cf_WriteFloat(outfile, shippage->ship_struct.lo_lod_distance); |
| 512 | |
| 513 | mng_WritePhysicsChunk(&shippage->ship_struct.phys_info, outfile); |
| 514 | |
| 515 | cf_WriteFloat(outfile, shippage->ship_struct.size); |
| 516 | cf_WriteFloat(outfile, shippage->ship_struct.armor_scalar); |
| 517 | cf_WriteInt(outfile, shippage->ship_struct.flags); |
| 518 | |
| 519 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 520 | int j; |
| 521 | |
| 522 | cf_WriteByte(outfile, shippage->ship_struct.fire_flags[i]); |
| 523 | cf_WriteString(outfile, shippage->firing_sound_name[i]); |
| 524 | cf_WriteString(outfile, shippage->release_sound_name[i]); |
| 525 | cf_WriteString(outfile, shippage->spew_powerup_name[i]); |
| 526 | cf_WriteInt(outfile, shippage->ship_struct.max_ammo[i]); |
| 527 | |
| 528 | mng_WriteWeaponBatteryChunk(&shippage->ship_struct.static_wb[i], outfile); |
| 529 | |
| 530 | for (j = 0; j < MAX_WB_GUNPOINTS; j++) |
| 531 | cf_WriteString(outfile, shippage->fire_sound_name[i][j]); |
| 532 | |
| 533 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) |
| 534 | cf_WriteString(outfile, shippage->weapon_name[i][j]); |
| 535 | } |
| 536 | |
| 537 | EndManagePage(outfile, offset); |
| 538 | } |
| 539 | |
| 540 | // Reads a ship page from an open file. Returns 0 on error. |
| 541 | int mng_ReadNewShipPage(CFILE *infile, mngs_ship_page *shippage) { |
| 542 | int i, j; |
| 543 | |
| 544 | ASSERT(infile != NULL); |
| 545 | |
| 546 | // Defaults |
| 547 | memset(shippage, 0, sizeof(mngs_ship_page)); |
| 548 | |
| 549 | int version = cf_ReadShort(infile); |
| 550 | |
| 551 | // Read In misc names |
| 552 | cf_ReadString(shippage->ship_struct.name, PAGENAME_LEN, infile); |
| 553 | cf_ReadString(shippage->ship_struct.cockpit_name, PAGENAME_LEN, infile); |
| 554 | cf_ReadString(shippage->ship_struct.hud_config_name, PAGENAME_LEN, infile); |
| 555 | |
| 556 | // Read in model names |
| 557 | cf_ReadString(shippage->image_name, PAGENAME_LEN, infile); |
| 558 | cf_ReadString(shippage->dying_image_name, PAGENAME_LEN, infile); |
| 559 | cf_ReadString(shippage->med_image_name, PAGENAME_LEN, infile); |
| 560 | cf_ReadString(shippage->lo_image_name, PAGENAME_LEN, infile); |
| 561 | |
| 562 | // read lod distance |
| 563 | shippage->ship_struct.med_lod_distance = cf_ReadFloat(infile); |
| 564 | shippage->ship_struct.lo_lod_distance = cf_ReadFloat(infile); |
| 565 | |
| 566 | // Read physics |
| 567 | mng_ReadPhysicsChunk(&shippage->ship_struct.phys_info, infile); |
| 568 | |
| 569 | shippage->ship_struct.size = cf_ReadFloat(infile); |
| 570 | shippage->ship_struct.armor_scalar = cf_ReadFloat(infile); |
| 571 | shippage->ship_struct.flags = cf_ReadInt(infile); |
| 572 | |
| 573 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 574 | shippage->ship_struct.fire_flags[i] = cf_ReadByte(infile); |
| 575 | cf_ReadString(shippage->firing_sound_name[i], PAGENAME_LEN, infile); |
| 576 | cf_ReadString(shippage->release_sound_name[i], PAGENAME_LEN, infile); |
| 577 | cf_ReadString(shippage->spew_powerup_name[i], PAGENAME_LEN, infile); |
| 578 | shippage->ship_struct.max_ammo[i] = cf_ReadInt(infile); |
| 579 | |
| 580 | if (version >= 6) |
| 581 | mng_ReadWeaponBatteryChunk(&shippage->ship_struct.static_wb[i], infile, 2); |
| 582 | else |
| 583 | mng_ReadWeaponBatteryChunk(&shippage->ship_struct.static_wb[i], infile, 1); |
| 584 | |
| 585 | for (j = 0; j < MAX_WB_GUNPOINTS; j++) |
| 586 | cf_ReadString(shippage->fire_sound_name[i][j], PAGENAME_LEN, infile); |
| 587 | |
| 588 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) |
| 589 | cf_ReadString(shippage->weapon_name[i][j], PAGENAME_LEN, infile); |
| 590 | } |
| 591 | |
| 592 | // Mark the newly filled structure as used |
| 593 | shippage->ship_struct.used = 1; |
| 594 | |
| 595 | // Bash Fusion recharge times for the ships |
| 596 | if (!stricmp(shippage->ship_struct.name, "Pyro-GL")) { |
| 597 | // Pyro-GL |
| 598 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) |
| 599 | shippage->ship_struct.static_wb[FUSION_INDEX].gp_fire_wait[j] = 0.66f; |
| 600 | } else if (!stricmp(shippage->ship_struct.name, "Phoenix")) { |
| 601 | // Phoenix |
| 602 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) |
| 603 | shippage->ship_struct.static_wb[FUSION_INDEX].gp_fire_wait[j] = 0.792f; |
| 604 | } else if (!stricmp(shippage->ship_struct.name, "Magnum-AHT")) { |
| 605 | // Magnum |
| 606 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) |
| 607 | shippage->ship_struct.static_wb[FUSION_INDEX].gp_fire_wait[j] = 1.122f; |
| 608 | } else { |
| 609 | // Other |
| 610 | } |
| 611 | |
| 612 | return 1; // successfully read |
| 613 | } |
| 614 | |
| 615 | // Reads a ship page from an open file. Returns 0 on error. |
| 616 | int mng_ReadShipPage(CFILE *infile, mngs_ship_page *shippage) { |
| 617 | int done = 0; |
| 618 | char command; |
| 619 | uint8_t len; |
| 620 | int i; |
| 621 | int version = 0; |
| 622 | |
| 623 | if (!Old_table_method) |
| 624 | return mng_ReadNewShipPage(infile, shippage); |
| 625 | |
| 626 | strcpy(shippage->dying_image_name, ""); |
| 627 | ASSERT(infile != NULL); |
| 628 | |
| 629 | // Defaults |
| 630 | memset(shippage, 0, sizeof(mngs_ship_page)); |
| 631 | shippage->ship_struct.armor_scalar = 1.0; |
| 632 | |
| 633 | strcpy(shippage->med_image_name, ""); |
| 634 | strcpy(shippage->lo_image_name, ""); |
| 635 | |
| 636 | shippage->ship_struct.med_lod_distance = DEFAULT_MED_LOD_DISTANCE; |
| 637 | shippage->ship_struct.lo_lod_distance = DEFAULT_LO_LOD_DISTANCE; |
| 638 | |
| 639 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 640 | shippage->ship_struct.static_wb[i].aiming_3d_dist = 1.0; |
| 641 | shippage->ship_struct.static_wb[i].num_masks = 1; |
| 642 | shippage->ship_struct.fire_flags[i] = 0; |
| 643 | shippage->firing_sound_name[i][0] = 0; |
| 644 | shippage->release_sound_name[i][0] = 0; |
| 645 | shippage->spew_powerup_name[i][0] = 0; |
| 646 | shippage->ship_struct.max_ammo[i] = 0; |
| 647 | } |
| 648 | |
| 649 | while (!done) { |
| 650 | // Read in command byte then read in the length of that commands data |
| 651 | |
| 652 | command = cf_ReadByte(infile); |
| 653 | len = cf_ReadByte(infile); |
| 654 | |
| 655 | switch (command) { |
| 656 | case SHIPPAGE_COMMAND_END: |
| 657 | done = 1; |
| 658 | break; |
| 659 | case SHIPPAGE_COMMAND_VERSION: |
| 660 | version = cf_ReadByte(infile); |
| 661 | break; |
| 662 | case SHIPPAGE_COMMAND_IMAGE_NAME: // the name of the ship model |
| 663 | for (i = 0; i < PAGENAME_LEN; i++) |
| 664 | shippage->image_name[i] = cf_ReadByte(infile); |
| 665 | break; |
| 666 | case SHIPPAGE_COMMAND_DYING_IMAGE_NAME: |
| 667 | cf_ReadString(shippage->dying_image_name, PAGENAME_LEN, infile); |
| 668 | break; |
| 669 | case SHIPPAGE_COMMAND_LOD_MODELS: // the name of the lower res models |
| 670 | cf_ReadString(shippage->med_image_name, len + 1, infile); |
| 671 | cf_ReadString(shippage->lo_image_name, len + 1, infile); |
| 672 | break; |
| 673 | case SHIPPAGE_COMMAND_LOD_DISTANCE: |
| 674 | shippage->ship_struct.med_lod_distance = cf_ReadFloat(infile); |
| 675 | shippage->ship_struct.lo_lod_distance = cf_ReadFloat(infile); |
| 676 | break; |
| 677 | case SHIPPAGE_COMMAND_COCKPIT_NAME: |
| 678 | cf_ReadString(shippage->ship_struct.cockpit_name, PAGENAME_LEN, infile); |
| 679 | break; |
| 680 | case SHIPPAGE_COMMAND_HUD_NAME: |
| 681 | cf_ReadString(shippage->ship_struct.hud_config_name, PAGENAME_LEN, infile); |
| 682 | break; |
| 683 | case SHIPPAGE_COMMAND_NAME: |
| 684 | for (i = 0; i < PAGENAME_LEN; i++) |
| 685 | shippage->ship_struct.name[i] = cf_ReadByte(infile); |
| 686 | break; |
| 687 | case SHIPPAGE_COMMAND_SIZE: |
| 688 | shippage->ship_struct.size = cf_ReadFloat(infile); |
| 689 | break; |
| 690 | case SHIPPAGE_COMMAND_ARMOR_SCALAR: |
| 691 | shippage->ship_struct.armor_scalar = cf_ReadFloat(infile); |
| 692 | break; |
| 693 | case SHIPPAGE_COMMAND_MASS: |
| 694 | shippage->ship_struct.phys_info.mass = cf_ReadFloat(infile); |
| 695 | break; |
| 696 | case SHIPPAGE_COMMAND_DRAG: |
| 697 | shippage->ship_struct.phys_info.drag = cf_ReadFloat(infile); |
| 698 | break; |
| 699 | case SHIPPAGE_COMMAND_WIGGLE_AMPLITUDE: |
| 700 | shippage->ship_struct.phys_info.wiggle_amplitude = cf_ReadFloat(infile); |
| 701 | break; |
| 702 | case SHIPPAGE_COMMAND_THRUST: |
| 703 | shippage->ship_struct.phys_info.full_thrust = cf_ReadFloat(infile); |
| 704 | break; |
| 705 | case SHIPPAGE_COMMAND_ROTTHRUST: |
| 706 | shippage->ship_struct.phys_info.full_rotthrust = cf_ReadFloat(infile); |
| 707 | break; |
| 708 | case SHIPPAGE_COMMAND_TURNROLLRATE: |
| 709 | shippage->ship_struct.phys_info.max_turnroll_rate = cf_ReadFloat(infile); |
| 710 | break; |
| 711 | case SHIPPAGE_COMMAND_ROTDRAG: |
| 712 | shippage->ship_struct.phys_info.rotdrag = cf_ReadFloat(infile); |
| 713 | break; |
| 714 | case SHIPPAGE_COMMAND_WIGGLE_PER_SEC: |
| 715 | shippage->ship_struct.phys_info.wiggles_per_sec = cf_ReadFloat(infile); |
| 716 | break; |
| 717 | case SHIPPAGE_COMMAND_TURNROLL_RATIO: |
| 718 | shippage->ship_struct.phys_info.turnroll_ratio = cf_ReadFloat(infile); |
| 719 | break; |
| 720 | case SHIPPAGE_COMMAND_PHYSICS_FLAGS: |
| 721 | shippage->ship_struct.phys_info.flags = cf_ReadInt(infile); |
| 722 | break; |
| 723 | case SHIPPAGE_COMMAND_FLAGS: |
| 724 | shippage->ship_struct.flags = cf_ReadInt(infile); |
| 725 | break; |
| 726 | case SHIPPAGE_COMMAND_WB_FLAGS: { |
| 727 | for (int i = 0; i < MAX_PLAYER_WEAPONS; i++) |
| 728 | shippage->ship_struct.static_wb[i].flags = cf_ReadByte(infile); |
| 729 | } break; |
| 730 | case SHIPPAGE_COMMAND_WB_QUADMASK: { |
| 731 | for (int i = 0; i < MAX_PLAYER_WEAPONS; i++) |
| 732 | shippage->ship_struct.static_wb[i].gp_quad_fire_mask = cf_ReadByte(infile); |
| 733 | } break; |
| 734 | case SHIPPAGE_COMMAND_WB_INFO: { |
| 735 | int i, j; |
| 736 | i = cf_ReadByte(infile); |
| 737 | |
| 738 | if (version < 1) { |
| 739 | for (j = 0; j < MAX_WB_GUNPOINTS; j++) |
| 740 | shippage->ship_struct.static_wb[i].gp_weapon_index[j] = cf_ReadInt(infile); |
| 741 | shippage->ship_struct.static_wb[i].aiming_gp_index = cf_ReadInt(infile); |
| 742 | } else { |
| 743 | for (j = 0; j < MAX_WB_GUNPOINTS; j++) |
| 744 | shippage->ship_struct.static_wb[i].gp_weapon_index[j] = cf_ReadShort(infile); |
| 745 | shippage->ship_struct.static_wb[i].aiming_gp_index = cf_ReadShort(infile); |
| 746 | } |
| 747 | shippage->ship_struct.static_wb[i].num_masks = cf_ReadByte(infile); |
| 748 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) |
| 749 | shippage->ship_struct.static_wb[i].gp_fire_masks[j] = cf_ReadByte(infile); |
| 750 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) |
| 751 | shippage->ship_struct.static_wb[i].gp_fire_wait[j] = cf_ReadFloat(infile); |
| 752 | |
| 753 | shippage->ship_struct.static_wb[i].aiming_flags = cf_ReadByte(infile); |
| 754 | shippage->ship_struct.static_wb[i].aiming_3d_dot = cf_ReadFloat(infile); |
| 755 | shippage->ship_struct.static_wb[i].aiming_3d_dist = cf_ReadFloat(infile); |
| 756 | shippage->ship_struct.static_wb[i].aiming_XZ_dot = cf_ReadFloat(infile); |
| 757 | break; |
| 758 | } |
| 759 | |
| 760 | case SHIPPAGE_COMMAND_WB_WEAPON: { |
| 761 | int i, j; |
| 762 | |
| 763 | i = cf_ReadByte(infile); |
| 764 | j = cf_ReadByte(infile); |
| 765 | cf_ReadString(shippage->weapon_name[i][j], len - 1, infile); |
| 766 | break; |
| 767 | } |
| 768 | case SHIPPAGE_COMMAND_WB_FIRE_SOUND: { |
| 769 | int i, j; |
| 770 | |
| 771 | i = cf_ReadByte(infile); |
| 772 | j = cf_ReadByte(infile); |
| 773 | cf_ReadString(shippage->fire_sound_name[i][j], len - 1, infile); |
| 774 | break; |
| 775 | } |
| 776 | case SHIPPAGE_COMMAND_FIRING_SOUND: { |
| 777 | int i = cf_ReadByte(infile); |
| 778 | cf_ReadString(shippage->firing_sound_name[i], len, infile); |
| 779 | break; |
| 780 | } |
| 781 | case SHIPPAGE_COMMAND_RELEASE_SOUND: { |
| 782 | int i = cf_ReadByte(infile); |
| 783 | cf_ReadString(shippage->release_sound_name[i], len, infile); |
| 784 | break; |
| 785 | } |
| 786 | case SHIPPAGE_COMMAND_SPEW_POWERUP: { |
| 787 | int i = cf_ReadByte(infile); |
| 788 | cf_ReadString(shippage->spew_powerup_name[i], len, infile); |
| 789 | break; |
| 790 | } |
| 791 | case SHIPPAGE_COMMAND_FIRE_FLAGS: { |
| 792 | uint8_t slot; |
| 793 | |
| 794 | slot = cf_ReadByte(infile); |
| 795 | shippage->ship_struct.fire_flags[slot] = cf_ReadByte(infile); |
| 796 | break; |
| 797 | } |
| 798 | case SHIPPAGE_COMMAND_MAX_AMMO: { |
| 799 | uint8_t slot; |
| 800 | |
| 801 | slot = cf_ReadByte(infile); |
| 802 | shippage->ship_struct.max_ammo[slot] = cf_ReadInt(infile); |
| 803 | break; |
| 804 | } |
| 805 | case SHIPPAGE_COMMAND_RESOURCE_USAGE: { |
| 806 | uint8_t slot; |
| 807 | |
| 808 | slot = cf_ReadByte(infile); |
| 809 | shippage->ship_struct.static_wb[slot].energy_usage = cf_ReadFloat(infile); |
| 810 | shippage->ship_struct.static_wb[slot].ammo_usage = cf_ReadFloat(infile); |
| 811 | break; |
| 812 | } |
| 813 | default: |
| 814 | // Ignore the ones we don't know |
| 815 | for (i = 0; i < len; i++) |
| 816 | cf_ReadByte(infile); |
| 817 | break; |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | for (int xxx = 0; xxx < MAX_WBS_PER_OBJ; xxx++) { |
| 822 | if ((version < 5) && (shippage->ship_struct.fire_flags[xxx] & 2)) { |
| 823 | shippage->ship_struct.static_wb[xxx].flags |= WBF_ON_OFF; |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | shippage->ship_struct.phys_info.num_bounces = -1; |
| 828 | shippage->ship_struct.phys_info.coeff_restitution = 1.0f; |
| 829 | |
| 830 | // Mark the newly filled structure as used |
| 831 | shippage->ship_struct.used = 1; |
| 832 | |
| 833 | return 1; // successfully read |
| 834 | } |
| 835 | |
| 836 | // Reads in the ship named "name" into shippage struct |
| 837 | // Returns 0 on error or couldn't find, else 1 if all is good |
| 838 | int mng_FindSpecificShipPage(char *name, mngs_ship_page *shippage, int offset) { |
| 839 | CFILE *infile; |
| 840 | uint8_t pagetype; |
| 841 | int done = 0, found = 0; |
| 842 | int first_try = 1; |
| 843 | std::filesystem::path tablename; |
| 844 | |
| 845 | if (Loading_locals) { |
| 846 | infile = cfopen(LocalTableFilename, "rb"); |
| 847 | } else if (Loading_addon_table != -1) { |
| 848 | infile = cfopen(AddOnDataTables[Loading_addon_table].AddOnTableFilename, "rb"); |
| 849 | } else { |
| 850 | if (Network_up && Starting_editor) { |
| 851 | int farg = FindArg("-filter"); |
| 852 | |
| 853 | if (farg) |
| 854 | tablename = GameArgs[farg + 1]; |
| 855 | else |
| 856 | tablename = LocalTableDir / NET_TABLE; |
| 857 | |
| 858 | infile = cfopen(tablename, "rb"); |
| 859 | } else { |
| 860 | infile = NULL; |
| 861 | if (TablefileNameOverride) { |
| 862 | infile = cfopen(TablefileNameOverride, "rb"); |
| 863 | } |
| 864 | |
| 865 | if (!infile) |
| 866 | infile = cfopen(TableFilename, "rb"); |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | if (!infile) { |
| 871 | mprintf(0, "Couldn't open table file to find ship!\n"); |
| 872 | Int3(); |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | try_again:; |
| 877 | |
| 878 | if (offset) |
| 879 | cfseek(infile, offset, SEEK_SET); |
| 880 | |
| 881 | // Read in the entire page file until we find the page we want |
| 882 | while (!done) { |
| 883 | if (cfeof(infile)) { |
| 884 | done = 1; |
| 885 | continue; |
| 886 | } |
| 887 | pagetype = cf_ReadByte(infile); |
| 888 | int len = cf_ReadInt(infile); |
| 889 | |
| 890 | // If not a ship page, just read it in and ignore it |
| 891 | if (pagetype != PAGETYPE_SHIP) { |
| 892 | cfseek(infile, len - 4, SEEK_CUR); |
| 893 | continue; |
| 894 | } |
| 895 | |
| 896 | mng_ReadNewShipPage(infile, shippage); |
| 897 | |
| 898 | if (!stricmp(name, shippage->ship_struct.name)) { |
| 899 | // This is the page we want |
| 900 | found = 1; |
| 901 | done = 1; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | cfclose(infile); |
| 906 | |
| 907 | if (!found && first_try) { |
| 908 | done = first_try = 0; |
| 909 | infile = cfopen("extra.gam", "rb"); |
| 910 | if (infile) |
| 911 | goto try_again; |
| 912 | } |
| 913 | |
| 914 | return found; // successful! |
| 915 | } |
| 916 | |
| 917 | // Given a ship page, allocs a ship and calls AssignShipPageToShip to actually |
| 918 | // load models and values. Rturns ship handle on success, -1 if fail |
| 919 | int mng_SetAndLoadShip(mngs_ship_page *shippage, CFILE *infile) { |
| 920 | int n; |
| 921 | |
| 922 | n = AllocShip(); |
| 923 | if (n < 0) |
| 924 | return -1; |
| 925 | if (!mng_AssignShipPageToShip(shippage, n, infile)) |
| 926 | return -1; |
| 927 | |
| 928 | return n; |
| 929 | } |
| 930 | |
| 931 | // Given a shippage and a ship handle, attempts to make ship n correspond to |
| 932 | // to the shippage. |
| 933 | // Returns 1 on success, 0 otherwise |
| 934 | int mng_AssignShipPageToShip(mngs_ship_page *shippage, int n, CFILE *infile) { |
| 935 | ship *shippointer = &Ships[n]; |
| 936 | int img_handle; |
| 937 | int i, j; |
| 938 | |
| 939 | // copy our values |
| 940 | memcpy(shippointer, &shippage->ship_struct, sizeof(ship)); |
| 941 | strcpy(shippointer->name, shippage->ship_struct.name); |
| 942 | |
| 943 | // First see if our image differs from the one on the net |
| 944 | // If it is, make a copy |
| 945 | // If its a release version, don't do any of this |
| 946 | |
| 947 | #ifndef RELEASE |
| 948 | if (Network_up) { |
| 949 | UpdatePrimitive(LocalModelsDir / shippage->image_name, NetModelsDir / shippage->image_name, shippage->image_name, |
| 950 | PAGETYPE_SHIP, shippointer->name); |
| 951 | |
| 952 | if (stricmp("INVALID IMAGE NAME", shippage->dying_image_name) != 0 && shippage->dying_image_name[0] != 0) { |
| 953 | UpdatePrimitive(LocalModelsDir / shippage->dying_image_name, NetModelsDir / shippage->dying_image_name, |
| 954 | shippage->dying_image_name, PAGETYPE_SHIP, shippointer->name); |
| 955 | } |
| 956 | |
| 957 | if (shippage->med_image_name[0] != 0) { |
| 958 | UpdatePrimitive(LocalModelsDir / shippage->med_image_name, NetModelsDir / shippage->med_image_name, |
| 959 | shippage->med_image_name, PAGETYPE_SHIP, shippointer->name); |
| 960 | } |
| 961 | |
| 962 | if (shippage->lo_image_name[0] != 0) { |
| 963 | UpdatePrimitive(LocalModelsDir / shippage->lo_image_name, NetModelsDir / shippage->lo_image_name, |
| 964 | shippage->lo_image_name, PAGETYPE_SHIP, shippointer->name); |
| 965 | } |
| 966 | } |
| 967 | #endif |
| 968 | |
| 969 | // Try and load our ship model from the disk |
| 970 | |
| 971 | img_handle = LoadPolyModel(shippage->image_name, 1); |
| 972 | |
| 973 | if (img_handle < 0) { |
| 974 | mprintf(0, "Couldn't load file '%s' in AssignShipPage...\n", shippage->image_name); |
| 975 | shippointer->model_handle = -1; |
| 976 | return 0; |
| 977 | } else |
| 978 | shippointer->model_handle = img_handle; |
| 979 | |
| 980 | if (stricmp("INVALID IMAGE NAME", shippage->dying_image_name) && shippage->dying_image_name[0] != 0) { |
| 981 | img_handle = LoadPolyModel(shippage->dying_image_name, 1); |
| 982 | |
| 983 | if (img_handle < 0) { |
| 984 | mprintf(0, "Couldn't load file '%s' in AssignShipPage...\n", shippage->dying_image_name); |
| 985 | shippointer->dying_model_handle = -1; |
| 986 | return 0; |
| 987 | } else |
| 988 | shippointer->dying_model_handle = img_handle; |
| 989 | } else |
| 990 | shippointer->dying_model_handle = -1; |
| 991 | |
| 992 | // Load lo-res stuff |
| 993 | if (shippage->med_image_name[0] != 0) { |
| 994 | img_handle = LoadPolyModel(shippage->med_image_name, 1); |
| 995 | |
| 996 | if (img_handle < 0) { |
| 997 | mprintf(0, "Couldn't load file '%s' in AssignShipPage...\n", shippage->med_image_name); |
| 998 | shippointer->med_render_handle = -1; |
| 999 | return 0; |
| 1000 | } else |
| 1001 | shippointer->med_render_handle = img_handle; |
| 1002 | } else |
| 1003 | shippointer->med_render_handle = -1; |
| 1004 | |
| 1005 | if (shippage->lo_image_name[0] != 0) { |
| 1006 | img_handle = LoadPolyModel(shippage->lo_image_name, 1); |
| 1007 | |
| 1008 | if (img_handle < 0) { |
| 1009 | mprintf(0, "Couldn't load file '%s' in AssignGenericPage...\n", shippage->lo_image_name); |
| 1010 | shippointer->lo_render_handle = -1; |
| 1011 | return 0; |
| 1012 | } else |
| 1013 | shippointer->lo_render_handle = img_handle; |
| 1014 | } else |
| 1015 | shippointer->lo_render_handle = -1; |
| 1016 | |
| 1017 | // Try and load the various weapons |
| 1018 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 1019 | for (j = 0; j < MAX_WB_GUNPOINTS; j++) { |
| 1020 | if (shippage->weapon_name[i][j][0] != '\0') { |
| 1021 | int weapon_handle = mng_GetGuaranteedWeaponPage(shippage->weapon_name[i][j], infile); |
| 1022 | |
| 1023 | if (weapon_handle < 0) { |
| 1024 | mprintf(0, "Couldn't load weapon file '%s' in AssignPowPage %s...\n", shippage->weapon_name[i][j], |
| 1025 | shippage->ship_struct.name); |
| 1026 | shippointer->static_wb[i].gp_weapon_index[j] = LASER_INDEX; |
| 1027 | } else |
| 1028 | shippointer->static_wb[i].gp_weapon_index[j] = weapon_handle; |
| 1029 | } else |
| 1030 | shippointer->static_wb[i].gp_weapon_index[j] = LASER_INDEX; |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | // Try and load the various weapons |
| 1035 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 1036 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) { |
| 1037 | if (shippage->fire_sound_name[i][j][0] != '\0') { |
| 1038 | int fire_sound_handle = mng_GetGuaranteedSoundPage(shippage->fire_sound_name[i][j], infile); |
| 1039 | |
| 1040 | if (fire_sound_handle < 0) { |
| 1041 | mprintf(0, "Couldn't load fire_sound file '%s' in AssignPowPage %s...\n", shippage->fire_sound_name[i][j], |
| 1042 | shippage->ship_struct.name); |
| 1043 | shippointer->static_wb[i].fm_fire_sound_index[j] = SOUND_NONE_INDEX; |
| 1044 | } else |
| 1045 | shippointer->static_wb[i].fm_fire_sound_index[j] = fire_sound_handle; |
| 1046 | } else |
| 1047 | shippointer->static_wb[i].fm_fire_sound_index[j] = SOUND_NONE_INDEX; |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 1052 | if (shippage->firing_sound_name[i][0] != 0) { |
| 1053 | int sound_handle = mng_GetGuaranteedSoundPage(shippage->firing_sound_name[i], infile); |
| 1054 | |
| 1055 | if (sound_handle < 0) { |
| 1056 | mprintf(0, "Couldn't load firing_sound file '%s' in AssignPowPage %s...\n", shippage->firing_sound_name[i], |
| 1057 | shippage->ship_struct.name); |
| 1058 | shippointer->firing_sound[i] = SOUND_NONE_INDEX; |
| 1059 | } else |
| 1060 | shippointer->firing_sound[i] = sound_handle; |
| 1061 | } else |
| 1062 | shippointer->firing_sound[i] = -1; |
| 1063 | |
| 1064 | if (shippage->release_sound_name[i][0] != 0) { |
| 1065 | int sound_handle = mng_GetGuaranteedSoundPage(shippage->release_sound_name[i], infile); |
| 1066 | |
| 1067 | if (sound_handle < 0) { |
| 1068 | mprintf(0, "Couldn't load firing_sound file '%s' in AssignPowPage %s...\n", shippage->release_sound_name[i], |
| 1069 | shippage->ship_struct.name); |
| 1070 | shippointer->firing_release_sound[i] = SOUND_NONE_INDEX; |
| 1071 | } else |
| 1072 | shippointer->firing_release_sound[i] = sound_handle; |
| 1073 | } else |
| 1074 | shippointer->firing_release_sound[i] = -1; |
| 1075 | |
| 1076 | if (shippage->spew_powerup_name[i][0] != 0) { |
| 1077 | shippointer->spew_powerup[i] = mng_GetGuaranteedGenericPage(shippage->spew_powerup_name[i], infile); |
| 1078 | if (shippointer->spew_powerup[i] > -1 && |
| 1079 | Object_info[shippointer->spew_powerup[i]].type != OBJ_POWERUP) { // DAJ -1FIX |
| 1080 | mprintf(1, "Spew powerup is not a powerup! Setting to none.\n"); |
| 1081 | shippointer->spew_powerup[i] = -1; |
| 1082 | } |
| 1083 | } else |
| 1084 | shippointer->spew_powerup[i] = -1; |
| 1085 | } |
| 1086 | |
| 1087 | return 1; |
| 1088 | } |
| 1089 | |
| 1090 | // Copies values from a ship into a ship_page |
| 1091 | void mng_AssignShipToShipPage(int n, mngs_ship_page *shippage) { |
| 1092 | ship *shippointer = &Ships[n]; |
| 1093 | int i, j; |
| 1094 | |
| 1095 | // Assign the values |
| 1096 | memcpy(&shippage->ship_struct, shippointer, sizeof(ship)); |
| 1097 | |
| 1098 | strcpy(shippage->ship_struct.name, shippointer->name); |
| 1099 | |
| 1100 | if (shippointer->model_handle != -1) |
| 1101 | strcpy(shippage->image_name, Poly_models[shippointer->model_handle].name); |
| 1102 | else |
| 1103 | strcpy(shippage->image_name, ""); |
| 1104 | |
| 1105 | if (shippointer->dying_model_handle != -1) |
| 1106 | strcpy(shippage->dying_image_name, Poly_models[shippointer->dying_model_handle].name); |
| 1107 | else |
| 1108 | strcpy(shippage->dying_image_name, ""); |
| 1109 | |
| 1110 | if (shippointer->med_render_handle != -1) |
| 1111 | strcpy(shippage->med_image_name, Poly_models[shippointer->med_render_handle].name); |
| 1112 | else |
| 1113 | strcpy(shippage->med_image_name, ""); |
| 1114 | |
| 1115 | if (shippointer->lo_render_handle != -1) |
| 1116 | strcpy(shippage->lo_image_name, Poly_models[shippointer->lo_render_handle].name); |
| 1117 | else |
| 1118 | strcpy(shippage->lo_image_name, ""); |
| 1119 | |
| 1120 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 1121 | for (j = 0; j < MAX_WB_GUNPOINTS; j++) { |
| 1122 | if (shippointer->static_wb[i].gp_weapon_index[j] >= 0) |
| 1123 | strcpy(shippage->weapon_name[i][j], Weapons[shippointer->static_wb[i].gp_weapon_index[j]].name); |
| 1124 | else |
| 1125 | strcpy(shippage->weapon_name[i][j], "Laser"); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 1130 | for (j = 0; j < MAX_WB_FIRING_MASKS; j++) { |
| 1131 | if (shippointer->static_wb[i].fm_fire_sound_index[j] >= 0) |
| 1132 | strcpy(shippage->fire_sound_name[i][j], Sounds[shippointer->static_wb[i].fm_fire_sound_index[j]].name); |
| 1133 | else |
| 1134 | strcpy(shippage->fire_sound_name[i][j], ""); |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 1139 | |
| 1140 | if (shippointer->firing_sound[i] != -1) |
| 1141 | strcpy(shippage->firing_sound_name[i], Sounds[shippointer->firing_sound[i]].name); |
| 1142 | else |
| 1143 | shippage->firing_sound_name[i][0] = 0; |
| 1144 | |
| 1145 | if (shippointer->firing_release_sound[i] != -1) |
| 1146 | strcpy(shippage->release_sound_name[i], Sounds[shippointer->firing_release_sound[i]].name); |
| 1147 | else |
| 1148 | shippage->release_sound_name[i][0] = 0; |
| 1149 | |
| 1150 | if (shippointer->spew_powerup[i] != -1) { |
| 1151 | if (Object_info[shippointer->spew_powerup[i]].type != OBJ_POWERUP) { |
| 1152 | mprintf(1, "Spew powerup is not a powerup! Setting to none.\n"); |
| 1153 | shippage->spew_powerup_name[i][0] = 0; |
| 1154 | } else |
| 1155 | strcpy(shippage->spew_powerup_name[i], Object_info[shippointer->spew_powerup[i]].name); |
| 1156 | } else |
| 1157 | shippage->spew_powerup_name[i][0] = 0; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | // Loads a ship found in the net table file. It then allocs a ship and |
| 1162 | // then calls SetAndLoadShip to actually load in any images/models associated |
| 1163 | // with it |
| 1164 | void mng_LoadNetShipPage(CFILE *infile, bool overlay) { |
| 1165 | mngs_ship_page shippage; |
| 1166 | // Have to zero out all fields that are not in the page (some physics fields), else we |
| 1167 | // end up with random values for initial velocity and the such... :) |
| 1168 | memset(&shippage, 0, sizeof(mngs_ship_page)); |
| 1169 | |
| 1170 | if (mng_ReadNewShipPage(infile, &shippage)) { |
| 1171 | int n = FindShipName(shippage.ship_struct.name); |
| 1172 | if (n != -1) { |
| 1173 | if (overlay) { |
| 1174 | mprintf(0, "OVERLAYING SHIP %s\n", shippage.ship_struct.name); |
| 1175 | mng_FreePagetypePrimitives(PAGETYPE_SHIP, shippage.ship_struct.name, 0); |
| 1176 | mng_AssignShipPageToShip(&shippage, n); |
| 1177 | } |
| 1178 | return; |
| 1179 | } |
| 1180 | int ret = mng_SetAndLoadShip(&shippage, infile); |
| 1181 | ASSERT(ret >= 0); |
| 1182 | } else |
| 1183 | mprintf(0, "Could not load shippage named %s!\n", shippage.ship_struct.name); |
| 1184 | } |
| 1185 | |
| 1186 | // Reads a ship page from a local table file. It then allocs a ship and |
| 1187 | // loads any images/models associated with that ship |
| 1188 | void mng_LoadLocalShipPage(CFILE *infile) { |
| 1189 | mngs_ship_page shippage; |
| 1190 | int ok = 0; |
| 1191 | // Have to zero out all fields that are not in the page (some physics fields), else we |
| 1192 | // end up with random values for initial velocity and the such... :) |
| 1193 | memset(&shippage, 0, sizeof(mngs_ship_page)); |
| 1194 | |
| 1195 | if (mng_ReadNewShipPage(infile, &shippage)) { |
| 1196 | // Check to see if this is a local copy that is supposed |
| 1197 | // to go over a network copy (supersede the net copy) |
| 1198 | |
| 1199 | int i = FindShipName(shippage.ship_struct.name); |
| 1200 | if (i != -1) { |
| 1201 | // Make sure we really have this page checked out |
| 1202 | mngs_Pagelock pl; |
| 1203 | |
| 1204 | strcpy(pl.name, shippage.ship_struct.name); |
| 1205 | pl.pagetype = PAGETYPE_SHIP; |
| 1206 | |
| 1207 | /*if (Network_up && Stand_alone==0) |
| 1208 | { |
| 1209 | int locked=mng_CheckIfPageOwned(&pl,TableUser); |
| 1210 | if (locked!=1) |
| 1211 | Int3(); // Your local vs net copies of the lock file do not match |
| 1212 | }*/ |
| 1213 | ok = 1; |
| 1214 | bool need_to_load_page = true; |
| 1215 | |
| 1216 | if (Loading_addon_table != -1) { |
| 1217 | AddOnTablefile *addon; |
| 1218 | int tidx; |
| 1219 | |
| 1220 | // see if we really need to load this page |
| 1221 | // check to see if we already have loaded this page (because it was |
| 1222 | // a dependancy of another) |
| 1223 | addon = &AddOnDataTables[Loading_addon_table]; |
| 1224 | for (tidx = 0; tidx < addon->Num_addon_tracklocks; tidx++) { |
| 1225 | if (addon->Addon_tracklocks[tidx].pagetype == PAGETYPE_SHIP && |
| 1226 | !stricmp(addon->Addon_tracklocks[tidx].name, shippage.ship_struct.name)) { |
| 1227 | // found it!! |
| 1228 | mprintf(0, "ShipPage: %s previously loaded\n", shippage.ship_struct.name); |
| 1229 | need_to_load_page = false; |
| 1230 | break; |
| 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | if (need_to_load_page) { |
| 1236 | mng_FreePagetypePrimitives(PAGETYPE_SHIP, shippage.ship_struct.name, 0); |
| 1237 | mng_AssignShipPageToShip(&shippage, i); |
| 1238 | |
| 1239 | // For addon data |
| 1240 | if (ok && Loading_addon_table != -1) { |
| 1241 | // this is an overlay of some sort..see which we are overlaying |
| 1242 | int overlay = 1; |
| 1243 | int addidx, tidx; |
| 1244 | bool found = false; |
| 1245 | for (addidx = Num_addon_tables - 1; addidx >= 0; addidx--) { |
| 1246 | if (addidx == Loading_addon_table) |
| 1247 | continue; |
| 1248 | AddOnTablefile *addon = &AddOnDataTables[addidx]; |
| 1249 | |
| 1250 | // look for the page in this table file |
| 1251 | for (tidx = 0; tidx < addon->Num_addon_tracklocks; tidx++) { |
| 1252 | if (addon->Addon_tracklocks[tidx].pagetype == PAGETYPE_SHIP && |
| 1253 | !stricmp(addon->Addon_tracklocks[tidx].name, shippage.ship_struct.name)) { |
| 1254 | // found it!! |
| 1255 | found = true; |
| 1256 | overlay = addidx + 2; |
| 1257 | break; |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | if (found) |
| 1262 | break; |
| 1263 | } |
| 1264 | |
| 1265 | mng_PushAddonPage(PAGETYPE_SHIP, shippage.ship_struct.name, overlay); |
| 1266 | } |
| 1267 | } |
| 1268 | } else { |
| 1269 | // This is a local ship that has never been checked in |
| 1270 | if ((i = mng_SetAndLoadShip(&shippage, infile)) < 0) |
| 1271 | ok = 0; |
| 1272 | else |
| 1273 | ok = 1; |
| 1274 | |
| 1275 | // For addon data |
| 1276 | if (ok && Loading_addon_table != -1) |
| 1277 | mng_PushAddonPage(PAGETYPE_SHIP, shippage.ship_struct.name, 0); |
| 1278 | } |
| 1279 | |
| 1280 | ASSERT(ok == 1); |
| 1281 | |
| 1282 | if (Loading_addon_table == -1) |
| 1283 | mng_AllocTrackLock(shippage.ship_struct.name, PAGETYPE_SHIP); |
| 1284 | |
| 1285 | if (i != -1) { |
| 1286 | poly_model *pm = GetPolymodelPointer(Ships[i].model_handle); // page in the model |
| 1287 | if (pm->n_attach < 3) { // check for enough attach points |
| 1288 | DataError("Model <%s> for ship <%s> has %d attach points (must have at least 3)\n", pm->name, Ships[i].name, |
| 1289 | pm->n_attach); |
| 1290 | } |
| 1291 | FreePolymodelData( |
| 1292 | Ships[i].model_handle); // Unload the data so it will get loaded later after the textures are in memory |
| 1293 | } |
| 1294 | } else |
| 1295 | |
| 1296 | mprintf(0, "Could not load shippage named %s!\n", shippage.ship_struct.name); |
| 1297 | } |