| 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/weaponpage.cpp $ |
| 21 | * $Revision: 71 $ |
| 22 | * $Date: 10/08/01 4:20p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * For loading/saving of weapon types |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/manage/weaponpage.cpp $ |
| 28 | * |
| 29 | * 71 10/08/01 4:20p Matt |
| 30 | * Added system to check for errors when reading in add-on data. |
| 31 | * |
| 32 | * 69 9/06/01 10:32a Matt |
| 33 | * Added code to fix problem poping add-on pages when the original pages |
| 34 | * were in the extra.gam file. |
| 35 | * |
| 36 | * 68 10/26/99 4:26p Jeff |
| 37 | * handle extra.gam |
| 38 | * |
| 39 | * 67 10/26/99 3:31p Jeff |
| 40 | * handle extra.gam addon tablefile |
| 41 | * |
| 42 | * 66 9/18/99 8:49p Jeff |
| 43 | * fixed bug with addon pages that have dependencies on other pages in the |
| 44 | * addon tablefile |
| 45 | * |
| 46 | * 65 8/11/99 5:32p Jeff |
| 47 | * changes to fix addon tablefile support so it works correctly |
| 48 | * |
| 49 | * 64 7/22/99 4:38p Jason |
| 50 | * made EMD time out faster to help balance it out |
| 51 | * |
| 52 | * 63 4/14/99 1:34a Jeff |
| 53 | * fixed case mismatched #includes |
| 54 | * |
| 55 | * 62 4/12/99 12:49p Jeff |
| 56 | * added recoil_force to weapon's page |
| 57 | * |
| 58 | * 61 3/08/99 7:48p Jeff |
| 59 | * oem hack for napalm barrel |
| 60 | * |
| 61 | * 60 3/04/99 4:47p Jason |
| 62 | * temp fix (ie BAD HACK) for OEM table file woes |
| 63 | * |
| 64 | * 59 3/04/99 1:47p Jason |
| 65 | * fixed some manage problems |
| 66 | * |
| 67 | * 58 2/22/99 2:03p Jason |
| 68 | * added different damages for players and generics |
| 69 | * |
| 70 | * 57 1/13/99 7:05a Jeff |
| 71 | * put #ifdef around #include <windows.h> |
| 72 | * |
| 73 | * 56 12/29/98 4:30p Jason |
| 74 | * added add-on data functionality |
| 75 | * |
| 76 | * 55 11/06/98 12:35p Jason |
| 77 | * more speedups for manage system |
| 78 | * |
| 79 | * 54 11/05/98 7:55p Jason |
| 80 | * changes for new manage system |
| 81 | * |
| 82 | * 53 11/02/98 6:02p Jason |
| 83 | * made yes network updates much faster |
| 84 | * |
| 85 | * 52 10/15/98 6:46p Chris |
| 86 | * Added custom size for weapons |
| 87 | * |
| 88 | * 51 10/09/98 2:55p Jason |
| 89 | * fixed bug with my last rev |
| 90 | * |
| 91 | * 50 10/09/98 2:27p Jason |
| 92 | * reorganized table file system |
| 93 | * |
| 94 | * 49 10/08/98 10:03p Jason |
| 95 | * more filtered table file stuff |
| 96 | * |
| 97 | * 48 9/18/98 3:58p Jason |
| 98 | * change weapon reordering to do countermeasure weapons after generics |
| 99 | * |
| 100 | * 47 9/01/98 4:41p Matt |
| 101 | * Removed obsolete fields in the weapon structure |
| 102 | * |
| 103 | * 46 8/24/98 2:37p Jason |
| 104 | * made table file more efficient with regards to invalid names |
| 105 | * |
| 106 | * 45 8/06/98 1:00p Chris |
| 107 | * Added new homing flags |
| 108 | * |
| 109 | * 44 7/30/98 11:09a Jason |
| 110 | * added weapons that freeze and deform terrain |
| 111 | * |
| 112 | * 43 7/28/98 12:29p Jason |
| 113 | * chagned text string |
| 114 | * |
| 115 | * 42 7/01/98 12:11p Jason |
| 116 | * added countermeasures |
| 117 | * |
| 118 | * 41 6/26/98 5:26p Sean |
| 119 | * fixed some remaining weapons issues |
| 120 | * |
| 121 | * 40 6/22/98 6:26p Jason |
| 122 | * added gravity field effect for weapons |
| 123 | * |
| 124 | * 39 6/19/98 12:04p Jason |
| 125 | * |
| 126 | * 38 6/12/98 1:06p Jason |
| 127 | * added smart loading from local table file |
| 128 | * |
| 129 | * 37 5/25/98 8:36p Matt |
| 130 | * Added code to set different sizes for different weapon scorch marks. |
| 131 | * Also, don't leave scorch marks on lights. |
| 132 | * |
| 133 | * 36 5/25/98 6:39p Jason |
| 134 | * got icons working for weapons |
| 135 | * |
| 136 | * 35 5/25/98 4:16p Jason |
| 137 | * added more verbose mprintfs |
| 138 | * |
| 139 | * 34 5/22/98 12:34p Matt |
| 140 | * Added scorch mark/bullet hole system. |
| 141 | * |
| 142 | * 33 5/19/98 5:09a Chris |
| 143 | * Initial values are better |
| 144 | * |
| 145 | * 32 5/19/98 5:02a Chris |
| 146 | * More adjustments |
| 147 | * |
| 148 | * 31 5/19/98 4:42a Chris |
| 149 | * Added shockwave's -- enjoy. :) |
| 150 | * |
| 151 | * 30 5/13/98 6:35p Chris |
| 152 | * Fixed problems with hit die dot |
| 153 | * |
| 154 | * 29 5/07/98 1:41p Chris |
| 155 | * Added hit_death_dot |
| 156 | * |
| 157 | * 28 5/04/98 6:08p Jason |
| 158 | * sped up predictive pagefile loading |
| 159 | * |
| 160 | * 27 4/07/98 3:31p Jason |
| 161 | * got particle effects working with weapons |
| 162 | * |
| 163 | * 26 4/02/98 3:54p Jason |
| 164 | * first pass in getting polymodel paging to work |
| 165 | * |
| 166 | * 25 2/23/98 1:22p Jason |
| 167 | * made FindSpecific* read from the local drive, not the net drive - when |
| 168 | * starting the editor |
| 169 | * |
| 170 | * 24 2/16/98 11:42a Jason |
| 171 | * added better error checking for checking out files |
| 172 | * |
| 173 | * 23 2/11/98 3:52p Jason |
| 174 | * |
| 175 | * 22 2/11/98 2:04p Jason |
| 176 | * got spawning weapons working |
| 177 | * |
| 178 | * 21 2/05/98 6:29p Jason |
| 179 | * added user settable explode time/size |
| 180 | * |
| 181 | * 20 2/04/98 9:28p Jason |
| 182 | * added some new weapons effects |
| 183 | * |
| 184 | * 19 1/23/98 6:25p Jason |
| 185 | * Got spray weapons working |
| 186 | * |
| 187 | * 18 1/15/98 6:22p Jason |
| 188 | * added safety checks so the network won't copy over a primitive you have |
| 189 | * held locally |
| 190 | * |
| 191 | * 17 12/22/97 6:19p Chris |
| 192 | * Moved weapon battery firing sound off the projectile (weapon) and into |
| 193 | * the weapon battery. |
| 194 | * |
| 195 | * 16 12/11/97 11:55a Jason |
| 196 | * better error checking for dependant weapon pages |
| 197 | * |
| 198 | * 15 12/04/97 6:59p Jason |
| 199 | * fixed stupid off-by-one bug in cf_ReadString |
| 200 | * |
| 201 | * 14 12/04/97 12:15p Jason |
| 202 | * gave designers the ability to set their own weapon-to-wall hit vclips |
| 203 | * |
| 204 | * 13 12/03/97 11:54a Jason |
| 205 | * added designer-settable smoketrails |
| 206 | * |
| 207 | * 12 12/01/97 9:54a Chris |
| 208 | * Added support for concussive forces, generalized robot collisions to |
| 209 | * generic collisions |
| 210 | * |
| 211 | * 11 11/14/97 9:55p Jason |
| 212 | * took out size fix because we changed out minds |
| 213 | * |
| 214 | * 10 11/14/97 9:31p Jason |
| 215 | * automatically adjust size of weapon polymodels |
| 216 | * |
| 217 | * 9 10/30/97 5:00p Jason |
| 218 | * Made weapons use generic lighting code |
| 219 | * |
| 220 | * 8 10/20/97 4:46p Jason |
| 221 | * changes for explosions |
| 222 | * |
| 223 | * 7 10/15/97 5:20p Jason |
| 224 | * did a HUGE overhaul of the bitmap system |
| 225 | * |
| 226 | * 6 9/10/97 11:44a Chris |
| 227 | * Added major functionality for wb info |
| 228 | * FIXED a big remapping bug |
| 229 | * |
| 230 | * 5 9/03/97 3:54p Jason |
| 231 | * got objects to cast light |
| 232 | * |
| 233 | * 4 8/08/97 11:44a Jason |
| 234 | * got rid of annoying sound loading of a blank string |
| 235 | * |
| 236 | * 3 8/07/97 5:27p Chris |
| 237 | * Expanded the weapon system |
| 238 | * |
| 239 | * 2 8/06/97 4:34p Chris |
| 240 | * Expanded the weapons page |
| 241 | * |
| 242 | * 14 5/15/97 6:24p Mark |
| 243 | * fixed small bugs with sound loading invalid names |
| 244 | * |
| 245 | * 13 5/08/97 12:41p Jason |
| 246 | * made manage system work with device dependant path names |
| 247 | * |
| 248 | * 12 4/28/97 6:46p Jason |
| 249 | * made ships have multiple gun points |
| 250 | * |
| 251 | * 11 4/25/97 6:16p Jason |
| 252 | * added switcheroo function |
| 253 | * |
| 254 | * 10 4/25/97 2:18p Jason |
| 255 | * added fire_delay functionality |
| 256 | * |
| 257 | * 9 4/24/97 5:42p Jason |
| 258 | * got fireball vclips working |
| 259 | * |
| 260 | * 8 4/23/97 3:04p Jason |
| 261 | * added more stuff to weapon pages |
| 262 | * |
| 263 | * 7 4/16/97 11:50a Jason |
| 264 | * finally got weapons to fire |
| 265 | * |
| 266 | * 6 4/14/97 5:09p Jason |
| 267 | * fixed dumb bug with weapon flags |
| 268 | * |
| 269 | * 5 4/14/97 4:35p Jason |
| 270 | * added thrust field to page file |
| 271 | * |
| 272 | * 4 4/14/97 1:50p Jason |
| 273 | * first pass at getting weapons to fire |
| 274 | * |
| 275 | * 3 4/08/97 2:25a Chris |
| 276 | * Fixed a problem with uninitialized data. In addition it |
| 277 | * fixed a problem with the .used flag that would happen |
| 278 | * 1 out of 2^(sizeof(used_flag)) times (it would be zero |
| 279 | * when it was supposed to be non-zero) |
| 280 | * |
| 281 | * 2 3/31/97 4:35p Jason |
| 282 | * added weapon page functionality |
| 283 | * |
| 284 | * 1 3/31/97 3:40p Jason |
| 285 | * weaponpage implementation file |
| 286 | * |
| 287 | * $NoKeywords: $ |
| 288 | */ |
| 289 | |
| 290 | #include <cstring> |
| 291 | #include <filesystem> |
| 292 | |
| 293 | #include "cfile.h" |
| 294 | #include "manage.h" |
| 295 | #include "weapon.h" |
| 296 | #include "weaponpage.h" |
| 297 | #include "mono.h" |
| 298 | #include "pserror.h" |
| 299 | #include "vclip.h" |
| 300 | #include "polymodel.h" |
| 301 | #include "soundpage.h" |
| 302 | #include "soundload.h" |
| 303 | #include "ddio.h" |
| 304 | #include "gametexture.h" |
| 305 | #include "texpage.h" |
| 306 | #include "sounds.h" |
| 307 | #include "genericpage.h" |
| 308 | #include "args.h" |
| 309 | |
| 310 | // weaponpage commands that are read/written |
| 311 | // A command is followed by a byte count describing how many bytes |
| 312 | // are in the data for the command |
| 313 | #define WEAPONPAGE_COMMAND_NAME 1 |
| 314 | #define WEAPONPAGE_COMMAND_END 2 |
| 315 | #define WEAPONPAGE_COMMAND_HUD_IMAGE_NAME 3 |
| 316 | #define WEAPONPAGE_COMMAND_VERSION 4 |
| 317 | #define WEAPONPAGE_COMMAND_MASS 5 |
| 318 | #define WEAPONPAGE_COMMAND_DRAG 6 |
| 319 | #define WEAPONPAGE_COMMAND_FLAGS 7 |
| 320 | #define WEAPONPAGE_COMMAND_FIRE_IMAGE_NAME 8 |
| 321 | // #define WEAPONPAGE_COMMAND_THRUST 9 // not used anymore |
| 322 | #define WEAPONPAGE_COMMAND_FULL_THRUST 10 |
| 323 | #define WEAPONPAGE_COMMAND_SOUND_NAME 11 |
| 324 | #define WEAPONPAGE_COMMAND_AMMO_USAGE 12 |
| 325 | #define WEAPONPAGE_COMMAND_ENERGY_USAGE 13 |
| 326 | // #define WEAPONPAGE_COMMAND_EXPLODE_NAME 14 // exploding vclip name (not used anymore) |
| 327 | #define WEAPONPAGE_COMMAND_FIRE_DELAY 15 |
| 328 | #define WEAPONPAGE_COMMAND_NUM_SHOTS 16 |
| 329 | #define WEAPONPAGE_COMMAND_PHYS_FLAGS 17 |
| 330 | #define WEAPONPAGE_COMMAND_SIZE 18 |
| 331 | #define WEAPONPAGE_COMMAND_IMPACT_SIZE 19 |
| 332 | #define WEAPONPAGE_COMMAND_FLASH_SIZE 20 |
| 333 | #define WEAPONPAGE_COMMAND_ROT_DRAG 21 |
| 334 | #define WEAPONPAGE_COMMAND_FULL_ROT_THRUST 22 |
| 335 | #define WEAPONPAGE_COMMAND_MAX_BOUNCES 23 |
| 336 | #define WEAPONPAGE_COMMAND_INIT_VELOCITY 24 |
| 337 | #define WEAPONPAGE_COMMAND_INIT_ROT_VEL_X 25 |
| 338 | #define WEAPONPAGE_COMMAND_INIT_ROT_VEL_Y 26 |
| 339 | #define WEAPONPAGE_COMMAND_INIT_ROT_VEL_Z 27 |
| 340 | #define WEAPONPAGE_COMMAND_LIFE_TIME 28 |
| 341 | #define WEAPONPAGE_COMMAND_THRUST_TIME 29 |
| 342 | #define WEAPONPAGE_COMMAND_WIGGLE_AMP 30 |
| 343 | #define WEAPONPAGE_COMMAND_WIGGLE_FREQ 31 |
| 344 | #define WEAPONPAGE_COMMAND_COEFF_RESTITUTION 32 |
| 345 | #define WEAPONPAGE_COMMAND_LIGHT_CAST 33 |
| 346 | #define WEAPONPAGE_COMMAND_DAMAGE 34 |
| 347 | #define WEAPONPAGE_COMMAND_BETTER_LIGHT_CAST 35 |
| 348 | #define WEAPONPAGE_COMMAND_IMPACT_TIME 36 |
| 349 | #define WEAPONPAGE_COMMAND_SMOKE_NAME 37 |
| 350 | #define WEAPONPAGE_COMMAND_EXPLOSION_NAME 38 // Wall hit vclip |
| 351 | #define WEAPONPAGE_COMMAND_ALPHA 39 |
| 352 | #define WEAPONPAGE_COMMAND_EXPLODE_TIME 40 |
| 353 | #define WEAPONPAGE_COMMAND_EXPLODE_SIZE 41 |
| 354 | #define WEAPONPAGE_COMMAND_SPAWN_COUNT 42 |
| 355 | #define WEAPONPAGE_COMMAND_SPAWN_NAME 43 |
| 356 | #define WEAPONPAGE_COMMAND_FIRE_IMAGE_NULL 44 |
| 357 | #define WEAPONPAGE_COMMAND_HUD_IMAGE_NULL 45 |
| 358 | #define WEAPONPAGE_COMMAND_NAME_NULL 46 |
| 359 | #define WEAPONPAGE_COMMAND_PARTICLE_NAME 47 |
| 360 | #define WEAPONPAGE_COMMAND_PARTICLE_DATA 48 |
| 361 | #define WEAPONPAGE_COMMAND_HIT_DIE_DOT 49 |
| 362 | #define WEAPONPAGE_COMMAND_IMPACT_FORCE 50 |
| 363 | #define WEAPONPAGE_COMMAND_IMPACT_DAMAGE 51 |
| 364 | #define WEAPONPAGE_COMMAND_SCORCH_NAME 52 |
| 365 | #define WEAPONPAGE_COMMAND_ICON_NAME 53 |
| 366 | #define WEAPONPAGE_COMMAND_SCORCH_SIZE 54 |
| 367 | #define WEAPONPAGE_COMMAND_ALT_SPAWN_NAME 55 |
| 368 | #define WEAPONPAGE_COMMAND_ALT_CHANCE 56 |
| 369 | #define WEAPONPAGE_COMMAND_GRAVITY_FIELD 57 |
| 370 | #define WEAPONPAGE_COMMAND_ROBOT_SPAWN_NAME 58 |
| 371 | #define WEAPONPAGE_COMMAND_TERRAIN_DAMAGE 59 |
| 372 | #define WEAPONPAGE_COMMAND_HOMING_FOV 60 |
| 373 | #define WEAPONPAGE_COMMAND_CUSTOM_SIZE 61 |
| 374 | |
| 375 | #define WEAPONPAGE_VERSION 8 |
| 376 | |
| 377 | void mng_WriteLightingChunk(light_info *lighting_info, CFILE *outfile); |
| 378 | void mng_ReadLightingChunk(light_info *lighting_info, CFILE *infile); |
| 379 | |
| 380 | extern char *TablefileNameOverride; |
| 381 | |
| 382 | // Sets a page structure to default values |
| 383 | void mng_InitWeaponPage(mngs_weapon_page *weaponpage) { |
| 384 | int i; |
| 385 | |
| 386 | memset(weaponpage, 0, sizeof(mngs_weapon_page)); |
| 387 | strcpy(weaponpage->hud_image_name, ""); |
| 388 | strcpy(weaponpage->fire_image_name, ""); |
| 389 | strcpy(weaponpage->explode_image_name, ""); |
| 390 | strcpy(weaponpage->spawn_name, ""); |
| 391 | strcpy(weaponpage->alternate_spawn_name, ""); |
| 392 | strcpy(weaponpage->robot_spawn_name, ""); |
| 393 | strcpy(weaponpage->smoke_image_name, ""); |
| 394 | strcpy(weaponpage->scorch_image_name, ""); |
| 395 | strcpy(weaponpage->icon_name, ""); |
| 396 | strcpy(weaponpage->particle_name, ""); |
| 397 | |
| 398 | weaponpage->weapon_struct.alpha = 1.0; |
| 399 | weaponpage->weapon_struct.alternate_chance = 0; |
| 400 | weaponpage->weapon_struct.explode_time = 1.0; |
| 401 | weaponpage->weapon_struct.explode_size = 1.0; |
| 402 | weaponpage->weapon_struct.particle_count = 0; |
| 403 | weaponpage->weapon_struct.scorch_size = 1.0; |
| 404 | weaponpage->weapon_struct.terrain_damage_size = 0; |
| 405 | weaponpage->weapon_struct.terrain_damage_depth = 0; |
| 406 | weaponpage->weapon_struct.homing_fov = 0.4f; |
| 407 | weaponpage->weapon_struct.custom_size = 0.0f; |
| 408 | weaponpage->weapon_struct.recoil_force = 0.0f; |
| 409 | |
| 410 | weaponpage->weapon_struct.phys_info.hit_die_dot = 1.0f; |
| 411 | |
| 412 | for (i = 0; i < MAX_WEAPON_SOUNDS; i++) |
| 413 | strcpy(weaponpage->sound_name[i], ""); |
| 414 | } |
| 415 | |
| 416 | // Given an open file pointer and a weapon_page struct, writes that weapon page out |
| 417 | void mng_WriteWeaponPage(CFILE *outfile, mngs_weapon_page *weaponpage) { |
| 418 | int i; |
| 419 | |
| 420 | ASSERT(outfile != NULL); |
| 421 | ASSERT(weaponpage != NULL); |
| 422 | |
| 423 | cf_WriteByte(outfile, PAGETYPE_WEAPON); |
| 424 | |
| 425 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_VERSION); |
| 426 | cf_WriteByte(outfile, 1); |
| 427 | cf_WriteByte(outfile, WEAPONPAGE_VERSION); |
| 428 | |
| 429 | if ((strlen(weaponpage->weapon_struct.name)) < 2) |
| 430 | Int3(); // Get Jason, right now |
| 431 | |
| 432 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_NAME_NULL); // get ready to write out name |
| 433 | cf_WriteByte(outfile, (strlen(weaponpage->weapon_struct.name)) + 1); |
| 434 | cf_WriteString(outfile, weaponpage->weapon_struct.name); |
| 435 | |
| 436 | // Write out its image name |
| 437 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_EXPLOSION_NAME); // get ready to write out name |
| 438 | cf_WriteByte(outfile, (strlen(weaponpage->explode_image_name)) + 1); |
| 439 | cf_WriteString(outfile, weaponpage->explode_image_name); |
| 440 | |
| 441 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_PARTICLE_NAME); // get ready to write out name |
| 442 | cf_WriteByte(outfile, (strlen(weaponpage->particle_name)) + 1); |
| 443 | cf_WriteString(outfile, weaponpage->particle_name); |
| 444 | |
| 445 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_PARTICLE_DATA); |
| 446 | cf_WriteByte(outfile, 9); |
| 447 | cf_WriteByte(outfile, weaponpage->weapon_struct.particle_count); |
| 448 | cf_WriteFloat(outfile, weaponpage->weapon_struct.particle_life); |
| 449 | cf_WriteFloat(outfile, weaponpage->weapon_struct.particle_size); |
| 450 | |
| 451 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_SPAWN_NAME); // get ready to write out name |
| 452 | cf_WriteByte(outfile, (strlen(weaponpage->spawn_name)) + 1); |
| 453 | cf_WriteString(outfile, weaponpage->spawn_name); |
| 454 | |
| 455 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_SPAWN_COUNT); |
| 456 | cf_WriteByte(outfile, 1); |
| 457 | cf_WriteByte(outfile, weaponpage->weapon_struct.spawn_count); |
| 458 | |
| 459 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_ROBOT_SPAWN_NAME); // get ready to write out name |
| 460 | cf_WriteByte(outfile, (strlen(weaponpage->robot_spawn_name)) + 1); |
| 461 | cf_WriteString(outfile, weaponpage->robot_spawn_name); |
| 462 | |
| 463 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_ALT_SPAWN_NAME); // get ready to write out name |
| 464 | cf_WriteByte(outfile, (strlen(weaponpage->alternate_spawn_name)) + 1); |
| 465 | cf_WriteString(outfile, weaponpage->alternate_spawn_name); |
| 466 | |
| 467 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_ALT_CHANCE); |
| 468 | cf_WriteByte(outfile, 1); |
| 469 | cf_WriteByte(outfile, weaponpage->weapon_struct.alternate_chance); |
| 470 | |
| 471 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_HUD_IMAGE_NULL); // get ready to write out name |
| 472 | cf_WriteByte(outfile, (strlen(weaponpage->hud_image_name)) + 1); |
| 473 | cf_WriteString(outfile, weaponpage->hud_image_name); |
| 474 | |
| 475 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_FIRE_IMAGE_NULL); // get ready to write out name |
| 476 | cf_WriteByte(outfile, (strlen(weaponpage->fire_image_name)) + 1); |
| 477 | cf_WriteString(outfile, weaponpage->fire_image_name); |
| 478 | |
| 479 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_HOMING_FOV); |
| 480 | cf_WriteByte(outfile, 4); |
| 481 | cf_WriteFloat(outfile, weaponpage->weapon_struct.homing_fov); |
| 482 | |
| 483 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_CUSTOM_SIZE); |
| 484 | cf_WriteByte(outfile, 4); |
| 485 | cf_WriteFloat(outfile, weaponpage->weapon_struct.custom_size); |
| 486 | |
| 487 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_GRAVITY_FIELD); |
| 488 | cf_WriteByte(outfile, 8); |
| 489 | cf_WriteFloat(outfile, weaponpage->weapon_struct.gravity_time); |
| 490 | cf_WriteFloat(outfile, weaponpage->weapon_struct.gravity_size); |
| 491 | |
| 492 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_MASS); |
| 493 | cf_WriteByte(outfile, 4); |
| 494 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.mass); |
| 495 | |
| 496 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_DRAG); |
| 497 | cf_WriteByte(outfile, 4); |
| 498 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.drag); |
| 499 | |
| 500 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_FULL_THRUST); |
| 501 | cf_WriteByte(outfile, 4); |
| 502 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.full_thrust); |
| 503 | |
| 504 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_FLAGS); |
| 505 | cf_WriteByte(outfile, 4); |
| 506 | cf_WriteInt(outfile, weaponpage->weapon_struct.flags); |
| 507 | |
| 508 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_PHYS_FLAGS); |
| 509 | cf_WriteByte(outfile, 4); |
| 510 | cf_WriteInt(outfile, weaponpage->weapon_struct.phys_info.flags); |
| 511 | |
| 512 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_SIZE); |
| 513 | cf_WriteByte(outfile, 4); |
| 514 | cf_WriteFloat(outfile, weaponpage->weapon_struct.size); |
| 515 | |
| 516 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_TERRAIN_DAMAGE); |
| 517 | cf_WriteByte(outfile, 5); |
| 518 | cf_WriteFloat(outfile, weaponpage->weapon_struct.terrain_damage_size); |
| 519 | cf_WriteByte(outfile, weaponpage->weapon_struct.terrain_damage_depth); |
| 520 | |
| 521 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_ALPHA); |
| 522 | cf_WriteByte(outfile, 4); |
| 523 | cf_WriteFloat(outfile, weaponpage->weapon_struct.alpha); |
| 524 | |
| 525 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_EXPLODE_TIME); |
| 526 | cf_WriteByte(outfile, 4); |
| 527 | cf_WriteFloat(outfile, weaponpage->weapon_struct.explode_time); |
| 528 | |
| 529 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_EXPLODE_SIZE); |
| 530 | cf_WriteByte(outfile, 4); |
| 531 | cf_WriteFloat(outfile, weaponpage->weapon_struct.explode_size); |
| 532 | |
| 533 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_DAMAGE); |
| 534 | cf_WriteByte(outfile, 4); |
| 535 | cf_WriteFloat(outfile, weaponpage->weapon_struct.player_damage); |
| 536 | |
| 537 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_IMPACT_SIZE); |
| 538 | cf_WriteByte(outfile, 4); |
| 539 | cf_WriteFloat(outfile, weaponpage->weapon_struct.impact_size); |
| 540 | |
| 541 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_IMPACT_TIME); |
| 542 | cf_WriteByte(outfile, 4); |
| 543 | cf_WriteFloat(outfile, weaponpage->weapon_struct.impact_time); |
| 544 | |
| 545 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_IMPACT_DAMAGE); |
| 546 | cf_WriteByte(outfile, 4); |
| 547 | cf_WriteFloat(outfile, weaponpage->weapon_struct.impact_player_damage); |
| 548 | |
| 549 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_IMPACT_FORCE); |
| 550 | cf_WriteByte(outfile, 4); |
| 551 | cf_WriteFloat(outfile, weaponpage->weapon_struct.impact_force); |
| 552 | |
| 553 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_ROT_DRAG); |
| 554 | cf_WriteByte(outfile, 4); |
| 555 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.rotdrag); |
| 556 | |
| 557 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_FULL_ROT_THRUST); |
| 558 | cf_WriteByte(outfile, 4); |
| 559 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.full_rotthrust); |
| 560 | |
| 561 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_MAX_BOUNCES); |
| 562 | cf_WriteByte(outfile, 4); |
| 563 | cf_WriteInt(outfile, weaponpage->weapon_struct.phys_info.num_bounces); |
| 564 | |
| 565 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_INIT_VELOCITY); |
| 566 | cf_WriteByte(outfile, 4); |
| 567 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.velocity.z); |
| 568 | |
| 569 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_INIT_ROT_VEL_X); |
| 570 | cf_WriteByte(outfile, 4); |
| 571 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.rotvel.x); |
| 572 | |
| 573 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_INIT_ROT_VEL_Y); |
| 574 | cf_WriteByte(outfile, 4); |
| 575 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.rotvel.y); |
| 576 | |
| 577 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_INIT_ROT_VEL_Z); |
| 578 | cf_WriteByte(outfile, 4); |
| 579 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.rotvel.z); |
| 580 | |
| 581 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_LIFE_TIME); |
| 582 | cf_WriteByte(outfile, 4); |
| 583 | cf_WriteFloat(outfile, weaponpage->weapon_struct.life_time); |
| 584 | |
| 585 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_THRUST_TIME); |
| 586 | cf_WriteByte(outfile, 4); |
| 587 | cf_WriteFloat(outfile, weaponpage->weapon_struct.thrust_time); |
| 588 | |
| 589 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_WIGGLE_AMP); |
| 590 | cf_WriteByte(outfile, 4); |
| 591 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.wiggle_amplitude); |
| 592 | |
| 593 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_WIGGLE_FREQ); |
| 594 | cf_WriteByte(outfile, 4); |
| 595 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.wiggles_per_sec); |
| 596 | |
| 597 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_COEFF_RESTITUTION); |
| 598 | cf_WriteByte(outfile, 4); |
| 599 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.coeff_restitution); |
| 600 | |
| 601 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_HIT_DIE_DOT); |
| 602 | cf_WriteByte(outfile, 4); |
| 603 | cf_WriteFloat(outfile, weaponpage->weapon_struct.phys_info.hit_die_dot); |
| 604 | |
| 605 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_BETTER_LIGHT_CAST); |
| 606 | cf_WriteByte(outfile, (10 * 4) + 2); |
| 607 | cf_WriteFloat(outfile, weaponpage->weapon_struct.lighting_info.light_distance); |
| 608 | cf_WriteFloat(outfile, weaponpage->weapon_struct.lighting_info.red_light1); |
| 609 | cf_WriteFloat(outfile, weaponpage->weapon_struct.lighting_info.green_light1); |
| 610 | cf_WriteFloat(outfile, weaponpage->weapon_struct.lighting_info.blue_light1); |
| 611 | cf_WriteFloat(outfile, weaponpage->weapon_struct.lighting_info.time_interval); |
| 612 | |
| 613 | cf_WriteFloat(outfile, weaponpage->weapon_struct.lighting_info.red_light2); |
| 614 | cf_WriteFloat(outfile, weaponpage->weapon_struct.lighting_info.green_light2); |
| 615 | cf_WriteFloat(outfile, weaponpage->weapon_struct.lighting_info.blue_light2); |
| 616 | cf_WriteInt(outfile, weaponpage->weapon_struct.lighting_info.flags); |
| 617 | cf_WriteInt(outfile, weaponpage->weapon_struct.lighting_info.timebits); |
| 618 | cf_WriteByte(outfile, weaponpage->weapon_struct.lighting_info.angle); |
| 619 | cf_WriteByte(outfile, weaponpage->weapon_struct.lighting_info.lighting_render_type); |
| 620 | |
| 621 | // Write out its sounds name |
| 622 | |
| 623 | for (i = 0; i < MAX_WEAPON_SOUNDS; i++) { |
| 624 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_SOUND_NAME); |
| 625 | cf_WriteByte(outfile, strlen(weaponpage->sound_name[i]) + 2); // 1 for sound index, 1 for null term |
| 626 | cf_WriteByte(outfile, i); |
| 627 | cf_WriteString(outfile, weaponpage->sound_name[i]); |
| 628 | } |
| 629 | |
| 630 | // Write smoke name |
| 631 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_SMOKE_NAME); |
| 632 | cf_WriteByte(outfile, strlen(weaponpage->smoke_image_name) + 1); // 1 for null term |
| 633 | cf_WriteString(outfile, weaponpage->smoke_image_name); |
| 634 | |
| 635 | // Write scorch name |
| 636 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_SCORCH_NAME); |
| 637 | cf_WriteByte(outfile, strlen(weaponpage->scorch_image_name) + 1); // 1 for null term |
| 638 | cf_WriteString(outfile, weaponpage->scorch_image_name); |
| 639 | |
| 640 | // Write icon name |
| 641 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_ICON_NAME); |
| 642 | cf_WriteByte(outfile, strlen(weaponpage->icon_name) + 1); // 1 for null term |
| 643 | cf_WriteString(outfile, weaponpage->icon_name); |
| 644 | |
| 645 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_SCORCH_SIZE); |
| 646 | cf_WriteByte(outfile, 4); |
| 647 | cf_WriteFloat(outfile, weaponpage->weapon_struct.scorch_size); |
| 648 | |
| 649 | cf_WriteByte(outfile, WEAPONPAGE_COMMAND_END); // we're all done |
| 650 | cf_WriteByte(outfile, 0); |
| 651 | } |
| 652 | |
| 653 | // Given an open file pointer and a weapon_page struct, writes that weapon page out |
| 654 | void mng_WriteNewWeaponPage(CFILE *outfile, mngs_weapon_page *weaponpage) { |
| 655 | int i; |
| 656 | |
| 657 | ASSERT(outfile != NULL); |
| 658 | ASSERT(weaponpage != NULL); |
| 659 | |
| 660 | int offset = StartManagePage(outfile, PAGETYPE_WEAPON); |
| 661 | |
| 662 | cf_WriteShort(outfile, WEAPONPAGE_VERSION); |
| 663 | |
| 664 | if ((strlen(weaponpage->weapon_struct.name)) < 2) |
| 665 | Int3(); // Get Jason, right now |
| 666 | |
| 667 | cf_WriteString(outfile, weaponpage->weapon_struct.name); |
| 668 | |
| 669 | // Write hud image name |
| 670 | cf_WriteString(outfile, weaponpage->hud_image_name); |
| 671 | |
| 672 | // Write fire image |
| 673 | cf_WriteString(outfile, weaponpage->fire_image_name); |
| 674 | |
| 675 | // Write out particle data |
| 676 | cf_WriteString(outfile, weaponpage->particle_name); |
| 677 | |
| 678 | cf_WriteByte(outfile, weaponpage->weapon_struct.particle_count); |
| 679 | cf_WriteFloat(outfile, weaponpage->weapon_struct.particle_life); |
| 680 | cf_WriteFloat(outfile, weaponpage->weapon_struct.particle_size); |
| 681 | |
| 682 | // Write flags |
| 683 | cf_WriteInt(outfile, weaponpage->weapon_struct.flags); |
| 684 | |
| 685 | // Write spawn data |
| 686 | cf_WriteString(outfile, weaponpage->spawn_name); |
| 687 | cf_WriteByte(outfile, weaponpage->weapon_struct.spawn_count); |
| 688 | |
| 689 | cf_WriteString(outfile, weaponpage->robot_spawn_name); |
| 690 | |
| 691 | cf_WriteString(outfile, weaponpage->alternate_spawn_name); |
| 692 | |
| 693 | cf_WriteByte(outfile, weaponpage->weapon_struct.alternate_chance); |
| 694 | |
| 695 | // Write gravity stuff |
| 696 | cf_WriteFloat(outfile, weaponpage->weapon_struct.gravity_time); |
| 697 | cf_WriteFloat(outfile, weaponpage->weapon_struct.gravity_size); |
| 698 | |
| 699 | // Write misc stuff |
| 700 | cf_WriteFloat(outfile, weaponpage->weapon_struct.homing_fov); |
| 701 | cf_WriteFloat(outfile, weaponpage->weapon_struct.custom_size); |
| 702 | cf_WriteFloat(outfile, weaponpage->weapon_struct.size); |
| 703 | cf_WriteFloat(outfile, weaponpage->weapon_struct.thrust_time); |
| 704 | |
| 705 | // Write physics stuff |
| 706 | mng_WritePhysicsChunk(&weaponpage->weapon_struct.phys_info, outfile); |
| 707 | |
| 708 | // Write terrain damage |
| 709 | cf_WriteFloat(outfile, weaponpage->weapon_struct.terrain_damage_size); |
| 710 | cf_WriteByte(outfile, weaponpage->weapon_struct.terrain_damage_depth); |
| 711 | |
| 712 | // Write alpha |
| 713 | cf_WriteFloat(outfile, weaponpage->weapon_struct.alpha); |
| 714 | |
| 715 | // Write explosion data |
| 716 | cf_WriteString(outfile, weaponpage->explode_image_name); |
| 717 | cf_WriteFloat(outfile, weaponpage->weapon_struct.explode_time); |
| 718 | cf_WriteFloat(outfile, weaponpage->weapon_struct.explode_size); |
| 719 | |
| 720 | // Write damage data |
| 721 | cf_WriteFloat(outfile, weaponpage->weapon_struct.player_damage); |
| 722 | cf_WriteFloat(outfile, weaponpage->weapon_struct.generic_damage); |
| 723 | cf_WriteFloat(outfile, weaponpage->weapon_struct.impact_size); |
| 724 | cf_WriteFloat(outfile, weaponpage->weapon_struct.impact_time); |
| 725 | cf_WriteFloat(outfile, weaponpage->weapon_struct.impact_player_damage); |
| 726 | cf_WriteFloat(outfile, weaponpage->weapon_struct.impact_generic_damage); |
| 727 | cf_WriteFloat(outfile, weaponpage->weapon_struct.impact_force); |
| 728 | |
| 729 | // Write lifetime |
| 730 | cf_WriteFloat(outfile, weaponpage->weapon_struct.life_time); |
| 731 | |
| 732 | // Write lighting |
| 733 | mng_WriteLightingChunk(&weaponpage->weapon_struct.lighting_info, outfile); |
| 734 | |
| 735 | // Write recoil force |
| 736 | cf_WriteFloat(outfile, weaponpage->weapon_struct.recoil_force); |
| 737 | |
| 738 | // Write out its sounds name |
| 739 | for (i = 0; i < MAX_WEAPON_SOUNDS; i++) |
| 740 | cf_WriteString(outfile, weaponpage->sound_name[i]); |
| 741 | |
| 742 | // Write smoke name |
| 743 | cf_WriteString(outfile, weaponpage->smoke_image_name); |
| 744 | |
| 745 | // Write scorch data |
| 746 | cf_WriteString(outfile, weaponpage->scorch_image_name); |
| 747 | cf_WriteFloat(outfile, weaponpage->weapon_struct.scorch_size); |
| 748 | |
| 749 | // Write icon name |
| 750 | cf_WriteString(outfile, weaponpage->icon_name); |
| 751 | |
| 752 | EndManagePage(outfile, offset); |
| 753 | } |
| 754 | |
| 755 | #ifdef OEM |
| 756 | void DoOEMNapalmBarrelHack(mngs_weapon_page *weaponpage) { |
| 757 | if (!strcmp(weaponpage->weapon_struct.name, "NapalmBarrelPart2")) { |
| 758 | mprintf(0, "BASHING NAPALMBARRELPART2!!!!!!\n"); |
| 759 | weaponpage->weapon_struct.flags |= (WF_SATURATE | WF_NO_ROTATE | WF_CUSTOM_SIZE | WF_NAPALM); |
| 760 | weaponpage->weapon_struct.custom_size = 6.0f; |
| 761 | weaponpage->weapon_struct.phys_info.mass = 0.6f; |
| 762 | weaponpage->weapon_struct.phys_info.drag = 0.01f; |
| 763 | weaponpage->weapon_struct.phys_info.rotdrag = 0.001f; |
| 764 | |
| 765 | weaponpage->weapon_struct.phys_info.velocity.x = 0; |
| 766 | weaponpage->weapon_struct.phys_info.velocity.y = 0; |
| 767 | weaponpage->weapon_struct.phys_info.velocity.z = 50.0f; |
| 768 | |
| 769 | } else { |
| 770 | mprintf(0, "BASHING NAPALMBARREL!!!!!!\n"); |
| 771 | weaponpage->weapon_struct.flags |= (WF_INVISIBLE | WF_CUSTOM_SIZE | WF_NAPALM); |
| 772 | weaponpage->weapon_struct.custom_size = 1.0f; |
| 773 | weaponpage->weapon_struct.phys_info.flags |= PF_USES_PARENT_VELOCITY; |
| 774 | |
| 775 | weaponpage->weapon_struct.phys_info.velocity.x = 0; |
| 776 | weaponpage->weapon_struct.phys_info.velocity.y = 0; |
| 777 | weaponpage->weapon_struct.phys_info.velocity.z = 110.0f; |
| 778 | } |
| 779 | } |
| 780 | #endif |
| 781 | |
| 782 | // Given an open file pointer and a weapon_page struct, reads a weapon page |
| 783 | int mng_ReadNewWeaponPage(CFILE *infile, mngs_weapon_page *weaponpage) { |
| 784 | int i; |
| 785 | |
| 786 | mng_InitWeaponPage(weaponpage); |
| 787 | |
| 788 | int version = cf_ReadShort(infile); |
| 789 | |
| 790 | cf_ReadString(weaponpage->weapon_struct.name, PAGENAME_LEN, infile); |
| 791 | |
| 792 | // Read hud image name |
| 793 | cf_ReadString(weaponpage->hud_image_name, PAGENAME_LEN, infile); |
| 794 | |
| 795 | // Read fire image |
| 796 | cf_ReadString(weaponpage->fire_image_name, PAGENAME_LEN, infile); |
| 797 | |
| 798 | // Read particle data |
| 799 | cf_ReadString(weaponpage->particle_name, PAGENAME_LEN, infile); |
| 800 | |
| 801 | weaponpage->weapon_struct.particle_count = cf_ReadByte(infile); |
| 802 | weaponpage->weapon_struct.particle_life = cf_ReadFloat(infile); |
| 803 | weaponpage->weapon_struct.particle_size = cf_ReadFloat(infile); |
| 804 | |
| 805 | // Read flags |
| 806 | weaponpage->weapon_struct.flags = cf_ReadInt(infile); |
| 807 | |
| 808 | // Read spawn data |
| 809 | cf_ReadString(weaponpage->spawn_name, PAGENAME_LEN, infile); |
| 810 | weaponpage->weapon_struct.spawn_count = cf_ReadByte(infile); |
| 811 | |
| 812 | cf_ReadString(weaponpage->robot_spawn_name, PAGENAME_LEN, infile); |
| 813 | cf_ReadString(weaponpage->alternate_spawn_name, PAGENAME_LEN, infile); |
| 814 | |
| 815 | weaponpage->weapon_struct.alternate_chance = cf_ReadByte(infile); |
| 816 | |
| 817 | // Read gravity stuff |
| 818 | weaponpage->weapon_struct.gravity_time = cf_ReadFloat(infile); |
| 819 | weaponpage->weapon_struct.gravity_size = cf_ReadFloat(infile); |
| 820 | |
| 821 | // Read size and homing data |
| 822 | weaponpage->weapon_struct.homing_fov = cf_ReadFloat(infile); |
| 823 | weaponpage->weapon_struct.custom_size = cf_ReadFloat(infile); |
| 824 | weaponpage->weapon_struct.size = cf_ReadFloat(infile); |
| 825 | weaponpage->weapon_struct.thrust_time = cf_ReadFloat(infile); |
| 826 | |
| 827 | // Read physics info |
| 828 | mng_ReadPhysicsChunk(&weaponpage->weapon_struct.phys_info, infile); |
| 829 | |
| 830 | // Read terrain damage |
| 831 | weaponpage->weapon_struct.terrain_damage_size = cf_ReadFloat(infile); |
| 832 | weaponpage->weapon_struct.terrain_damage_depth = cf_ReadByte(infile); |
| 833 | |
| 834 | // Read alpha |
| 835 | weaponpage->weapon_struct.alpha = cf_ReadFloat(infile); |
| 836 | |
| 837 | // Read explosion data |
| 838 | cf_ReadString(weaponpage->explode_image_name, PAGENAME_LEN, infile); |
| 839 | weaponpage->weapon_struct.explode_time = cf_ReadFloat(infile); |
| 840 | weaponpage->weapon_struct.explode_size = cf_ReadFloat(infile); |
| 841 | |
| 842 | // Read damage data |
| 843 | weaponpage->weapon_struct.player_damage = cf_ReadFloat(infile); |
| 844 | |
| 845 | if (version >= 7) |
| 846 | weaponpage->weapon_struct.generic_damage = cf_ReadFloat(infile); |
| 847 | else |
| 848 | weaponpage->weapon_struct.generic_damage = weaponpage->weapon_struct.player_damage; |
| 849 | |
| 850 | weaponpage->weapon_struct.impact_size = cf_ReadFloat(infile); |
| 851 | weaponpage->weapon_struct.impact_time = cf_ReadFloat(infile); |
| 852 | weaponpage->weapon_struct.impact_player_damage = cf_ReadFloat(infile); |
| 853 | |
| 854 | if (version >= 7) |
| 855 | weaponpage->weapon_struct.impact_generic_damage = cf_ReadFloat(infile); |
| 856 | else |
| 857 | weaponpage->weapon_struct.impact_generic_damage = weaponpage->weapon_struct.impact_player_damage; |
| 858 | |
| 859 | weaponpage->weapon_struct.impact_force = cf_ReadFloat(infile); |
| 860 | |
| 861 | // Read lifetime |
| 862 | weaponpage->weapon_struct.life_time = cf_ReadFloat(infile); |
| 863 | |
| 864 | // read lighting |
| 865 | mng_ReadLightingChunk(&weaponpage->weapon_struct.lighting_info, infile); |
| 866 | |
| 867 | // read recoil force |
| 868 | if (version >= 8) |
| 869 | weaponpage->weapon_struct.recoil_force = cf_ReadFloat(infile); |
| 870 | else |
| 871 | weaponpage->weapon_struct.recoil_force = 0.0f; |
| 872 | |
| 873 | // Read its sound names |
| 874 | for (i = 0; i < MAX_WEAPON_SOUNDS; i++) |
| 875 | cf_ReadString(weaponpage->sound_name[i], PAGENAME_LEN, infile); |
| 876 | |
| 877 | // Read smoke name |
| 878 | cf_ReadString(weaponpage->smoke_image_name, PAGENAME_LEN, infile); |
| 879 | |
| 880 | // Read scorch data |
| 881 | cf_ReadString(weaponpage->scorch_image_name, PAGENAME_LEN, infile); |
| 882 | weaponpage->weapon_struct.scorch_size = cf_ReadFloat(infile); |
| 883 | |
| 884 | // Read icon name |
| 885 | cf_ReadString(weaponpage->icon_name, PAGENAME_LEN, infile); |
| 886 | |
| 887 | weaponpage->weapon_struct.used = 1; |
| 888 | |
| 889 | #ifdef OEM |
| 890 | if (!strcmp(weaponpage->weapon_struct.name, "NapalmBarrelPart2") || |
| 891 | !strcmp(weaponpage->weapon_struct.name, "NapalmBarrel")) { |
| 892 | // Do OEM hack |
| 893 | DoOEMNapalmBarrelHack(weaponpage); |
| 894 | } |
| 895 | #endif |
| 896 | |
| 897 | if (!stricmp(weaponpage->weapon_struct.name, "EMDBlob")) { |
| 898 | weaponpage->weapon_struct.life_time = 1.7f; |
| 899 | } |
| 900 | |
| 901 | return 1; // successfully read |
| 902 | } |
| 903 | |
| 904 | // Reads a weapon page from an open file. Returns 0 on error. |
| 905 | int mng_ReadWeaponPage(CFILE *infile, mngs_weapon_page *weaponpage) { |
| 906 | int done = 0; |
| 907 | char command; |
| 908 | uint8_t len; |
| 909 | int i, t; |
| 910 | int version = 0; |
| 911 | |
| 912 | if (!Old_table_method) |
| 913 | return mng_ReadNewWeaponPage(infile, weaponpage); |
| 914 | |
| 915 | ASSERT(infile != NULL); |
| 916 | |
| 917 | mng_InitWeaponPage(weaponpage); |
| 918 | |
| 919 | while (!done) { |
| 920 | // Read in command byte then read in the length of that commands data |
| 921 | |
| 922 | command = cf_ReadByte(infile); |
| 923 | len = cf_ReadByte(infile); |
| 924 | |
| 925 | switch (command) { |
| 926 | case WEAPONPAGE_COMMAND_END: |
| 927 | done = 1; |
| 928 | break; |
| 929 | case WEAPONPAGE_COMMAND_VERSION: |
| 930 | version = cf_ReadByte(infile); |
| 931 | break; |
| 932 | case WEAPONPAGE_COMMAND_HUD_IMAGE_NAME: // the name of the weapon model |
| 933 | for (i = 0; i < PAGENAME_LEN; i++) |
| 934 | weaponpage->hud_image_name[i] = cf_ReadByte(infile); |
| 935 | break; |
| 936 | case WEAPONPAGE_COMMAND_FIRE_IMAGE_NAME: // the name of the weapon model |
| 937 | for (i = 0; i < PAGENAME_LEN; i++) |
| 938 | weaponpage->fire_image_name[i] = cf_ReadByte(infile); |
| 939 | break; |
| 940 | case WEAPONPAGE_COMMAND_NAME_NULL: |
| 941 | cf_ReadString(weaponpage->weapon_struct.name, len + 1, infile); |
| 942 | break; |
| 943 | case WEAPONPAGE_COMMAND_FIRE_IMAGE_NULL: |
| 944 | cf_ReadString(weaponpage->fire_image_name, len + 1, infile); |
| 945 | break; |
| 946 | case WEAPONPAGE_COMMAND_HUD_IMAGE_NULL: |
| 947 | cf_ReadString(weaponpage->hud_image_name, len + 1, infile); |
| 948 | break; |
| 949 | case WEAPONPAGE_COMMAND_SPAWN_NAME: |
| 950 | cf_ReadString(weaponpage->spawn_name, len + 1, infile); |
| 951 | break; |
| 952 | case WEAPONPAGE_COMMAND_SPAWN_COUNT: |
| 953 | weaponpage->weapon_struct.spawn_count = cf_ReadByte(infile); |
| 954 | break; |
| 955 | case WEAPONPAGE_COMMAND_ALT_SPAWN_NAME: |
| 956 | cf_ReadString(weaponpage->alternate_spawn_name, len + 1, infile); |
| 957 | break; |
| 958 | case WEAPONPAGE_COMMAND_ROBOT_SPAWN_NAME: |
| 959 | cf_ReadString(weaponpage->robot_spawn_name, len + 1, infile); |
| 960 | break; |
| 961 | case WEAPONPAGE_COMMAND_ALT_CHANCE: |
| 962 | weaponpage->weapon_struct.alternate_chance = cf_ReadByte(infile); |
| 963 | break; |
| 964 | case WEAPONPAGE_COMMAND_NAME: |
| 965 | for (i = 0; i < PAGENAME_LEN; i++) |
| 966 | weaponpage->weapon_struct.name[i] = cf_ReadByte(infile); |
| 967 | break; |
| 968 | case WEAPONPAGE_COMMAND_EXPLOSION_NAME: |
| 969 | cf_ReadString(weaponpage->explode_image_name, len + 1, infile); |
| 970 | break; |
| 971 | case WEAPONPAGE_COMMAND_PARTICLE_NAME: |
| 972 | cf_ReadString(weaponpage->particle_name, len + 1, infile); |
| 973 | break; |
| 974 | case WEAPONPAGE_COMMAND_FLAGS: |
| 975 | weaponpage->weapon_struct.flags = cf_ReadInt(infile); |
| 976 | break; |
| 977 | case WEAPONPAGE_COMMAND_MASS: |
| 978 | weaponpage->weapon_struct.phys_info.mass = cf_ReadFloat(infile); |
| 979 | break; |
| 980 | case WEAPONPAGE_COMMAND_HOMING_FOV: |
| 981 | weaponpage->weapon_struct.homing_fov = cf_ReadFloat(infile); |
| 982 | break; |
| 983 | case WEAPONPAGE_COMMAND_CUSTOM_SIZE: |
| 984 | weaponpage->weapon_struct.custom_size = cf_ReadFloat(infile); |
| 985 | break; |
| 986 | case WEAPONPAGE_COMMAND_GRAVITY_FIELD: |
| 987 | weaponpage->weapon_struct.gravity_time = cf_ReadFloat(infile); |
| 988 | weaponpage->weapon_struct.gravity_size = cf_ReadFloat(infile); |
| 989 | break; |
| 990 | case WEAPONPAGE_COMMAND_FULL_THRUST: |
| 991 | weaponpage->weapon_struct.phys_info.full_thrust = cf_ReadFloat(infile); |
| 992 | break; |
| 993 | case WEAPONPAGE_COMMAND_DRAG: |
| 994 | weaponpage->weapon_struct.phys_info.drag = cf_ReadFloat(infile); |
| 995 | break; |
| 996 | case WEAPONPAGE_COMMAND_TERRAIN_DAMAGE: |
| 997 | weaponpage->weapon_struct.terrain_damage_size = cf_ReadFloat(infile); |
| 998 | weaponpage->weapon_struct.terrain_damage_depth = cf_ReadByte(infile); |
| 999 | break; |
| 1000 | case WEAPONPAGE_COMMAND_SOUND_NAME: |
| 1001 | t = cf_ReadByte(infile); |
| 1002 | cf_ReadString(weaponpage->sound_name[t], len, infile); |
| 1003 | break; |
| 1004 | case WEAPONPAGE_COMMAND_PHYS_FLAGS: |
| 1005 | weaponpage->weapon_struct.phys_info.flags = cf_ReadInt(infile); |
| 1006 | break; |
| 1007 | case WEAPONPAGE_COMMAND_SIZE: |
| 1008 | weaponpage->weapon_struct.size = cf_ReadFloat(infile); |
| 1009 | break; |
| 1010 | case WEAPONPAGE_COMMAND_ALPHA: |
| 1011 | weaponpage->weapon_struct.alpha = cf_ReadFloat(infile); |
| 1012 | break; |
| 1013 | case WEAPONPAGE_COMMAND_EXPLODE_TIME: |
| 1014 | weaponpage->weapon_struct.explode_time = cf_ReadFloat(infile); |
| 1015 | break; |
| 1016 | case WEAPONPAGE_COMMAND_EXPLODE_SIZE: |
| 1017 | weaponpage->weapon_struct.explode_size = cf_ReadFloat(infile); |
| 1018 | break; |
| 1019 | case WEAPONPAGE_COMMAND_PARTICLE_DATA: |
| 1020 | weaponpage->weapon_struct.particle_count = cf_ReadByte(infile); |
| 1021 | weaponpage->weapon_struct.particle_life = cf_ReadFloat(infile); |
| 1022 | weaponpage->weapon_struct.particle_size = cf_ReadFloat(infile); |
| 1023 | break; |
| 1024 | case WEAPONPAGE_COMMAND_DAMAGE: |
| 1025 | weaponpage->weapon_struct.player_damage = cf_ReadFloat(infile); |
| 1026 | break; |
| 1027 | case WEAPONPAGE_COMMAND_IMPACT_SIZE: |
| 1028 | weaponpage->weapon_struct.impact_size = cf_ReadFloat(infile); |
| 1029 | break; |
| 1030 | case WEAPONPAGE_COMMAND_IMPACT_TIME: |
| 1031 | weaponpage->weapon_struct.impact_time = cf_ReadFloat(infile); |
| 1032 | break; |
| 1033 | case WEAPONPAGE_COMMAND_IMPACT_DAMAGE: |
| 1034 | weaponpage->weapon_struct.impact_player_damage = cf_ReadFloat(infile); |
| 1035 | break; |
| 1036 | case WEAPONPAGE_COMMAND_IMPACT_FORCE: |
| 1037 | weaponpage->weapon_struct.impact_force = cf_ReadFloat(infile); |
| 1038 | break; |
| 1039 | case WEAPONPAGE_COMMAND_ROT_DRAG: |
| 1040 | weaponpage->weapon_struct.phys_info.rotdrag = cf_ReadFloat(infile); |
| 1041 | break; |
| 1042 | case WEAPONPAGE_COMMAND_FULL_ROT_THRUST: |
| 1043 | weaponpage->weapon_struct.phys_info.full_rotthrust = cf_ReadFloat(infile); |
| 1044 | break; |
| 1045 | case WEAPONPAGE_COMMAND_MAX_BOUNCES: |
| 1046 | weaponpage->weapon_struct.phys_info.num_bounces = cf_ReadInt(infile); |
| 1047 | break; |
| 1048 | case WEAPONPAGE_COMMAND_INIT_VELOCITY: |
| 1049 | weaponpage->weapon_struct.phys_info.velocity.z = cf_ReadFloat(infile); |
| 1050 | break; |
| 1051 | case WEAPONPAGE_COMMAND_INIT_ROT_VEL_X: |
| 1052 | weaponpage->weapon_struct.phys_info.rotvel.x = cf_ReadFloat(infile); |
| 1053 | break; |
| 1054 | case WEAPONPAGE_COMMAND_INIT_ROT_VEL_Y: |
| 1055 | weaponpage->weapon_struct.phys_info.rotvel.y = cf_ReadFloat(infile); |
| 1056 | break; |
| 1057 | case WEAPONPAGE_COMMAND_INIT_ROT_VEL_Z: |
| 1058 | weaponpage->weapon_struct.phys_info.rotvel.z = cf_ReadFloat(infile); |
| 1059 | break; |
| 1060 | case WEAPONPAGE_COMMAND_LIFE_TIME: |
| 1061 | weaponpage->weapon_struct.life_time = cf_ReadFloat(infile); |
| 1062 | break; |
| 1063 | case WEAPONPAGE_COMMAND_THRUST_TIME: |
| 1064 | weaponpage->weapon_struct.thrust_time = cf_ReadFloat(infile); |
| 1065 | break; |
| 1066 | case WEAPONPAGE_COMMAND_WIGGLE_AMP: |
| 1067 | weaponpage->weapon_struct.phys_info.wiggle_amplitude = cf_ReadFloat(infile); |
| 1068 | break; |
| 1069 | case WEAPONPAGE_COMMAND_WIGGLE_FREQ: |
| 1070 | weaponpage->weapon_struct.phys_info.wiggles_per_sec = cf_ReadFloat(infile); |
| 1071 | break; |
| 1072 | case WEAPONPAGE_COMMAND_COEFF_RESTITUTION: |
| 1073 | weaponpage->weapon_struct.phys_info.coeff_restitution = cf_ReadFloat(infile); |
| 1074 | break; |
| 1075 | case WEAPONPAGE_COMMAND_HIT_DIE_DOT: |
| 1076 | weaponpage->weapon_struct.phys_info.hit_die_dot = cf_ReadFloat(infile); |
| 1077 | break; |
| 1078 | case WEAPONPAGE_COMMAND_LIGHT_CAST: |
| 1079 | weaponpage->weapon_struct.lighting_info.light_distance = cf_ReadFloat(infile); |
| 1080 | weaponpage->weapon_struct.lighting_info.red_light1 = cf_ReadFloat(infile); |
| 1081 | weaponpage->weapon_struct.lighting_info.green_light1 = cf_ReadFloat(infile); |
| 1082 | weaponpage->weapon_struct.lighting_info.blue_light1 = cf_ReadFloat(infile); |
| 1083 | weaponpage->weapon_struct.lighting_info.timebits = 0xFFFFFFFF; |
| 1084 | break; |
| 1085 | case WEAPONPAGE_COMMAND_BETTER_LIGHT_CAST: |
| 1086 | weaponpage->weapon_struct.lighting_info.light_distance = cf_ReadFloat(infile); |
| 1087 | |
| 1088 | weaponpage->weapon_struct.lighting_info.red_light1 = cf_ReadFloat(infile); |
| 1089 | weaponpage->weapon_struct.lighting_info.green_light1 = cf_ReadFloat(infile); |
| 1090 | weaponpage->weapon_struct.lighting_info.blue_light1 = cf_ReadFloat(infile); |
| 1091 | |
| 1092 | weaponpage->weapon_struct.lighting_info.time_interval = cf_ReadFloat(infile); |
| 1093 | |
| 1094 | weaponpage->weapon_struct.lighting_info.red_light2 = cf_ReadFloat(infile); |
| 1095 | weaponpage->weapon_struct.lighting_info.green_light2 = cf_ReadFloat(infile); |
| 1096 | weaponpage->weapon_struct.lighting_info.blue_light2 = cf_ReadFloat(infile); |
| 1097 | |
| 1098 | weaponpage->weapon_struct.lighting_info.flags = cf_ReadInt(infile); |
| 1099 | weaponpage->weapon_struct.lighting_info.timebits = cf_ReadInt(infile); |
| 1100 | weaponpage->weapon_struct.lighting_info.angle = cf_ReadByte(infile); |
| 1101 | weaponpage->weapon_struct.lighting_info.lighting_render_type = cf_ReadByte(infile); |
| 1102 | break; |
| 1103 | case WEAPONPAGE_COMMAND_SMOKE_NAME: |
| 1104 | cf_ReadString(weaponpage->smoke_image_name, len + 1, infile); |
| 1105 | break; |
| 1106 | case WEAPONPAGE_COMMAND_SCORCH_NAME: |
| 1107 | cf_ReadString(weaponpage->scorch_image_name, len + 1, infile); |
| 1108 | break; |
| 1109 | case WEAPONPAGE_COMMAND_SCORCH_SIZE: |
| 1110 | weaponpage->weapon_struct.scorch_size = cf_ReadFloat(infile); |
| 1111 | break; |
| 1112 | case WEAPONPAGE_COMMAND_ICON_NAME: |
| 1113 | cf_ReadString(weaponpage->icon_name, len + 1, infile); |
| 1114 | break; |
| 1115 | default: |
| 1116 | // Ignore the ones we don't know |
| 1117 | for (i = 0; i < len; i++) |
| 1118 | cf_ReadByte(infile); |
| 1119 | break; |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | if (version < 2) { |
| 1124 | weaponpage->weapon_struct.impact_player_damage = weaponpage->weapon_struct.player_damage; |
| 1125 | weaponpage->weapon_struct.impact_force = weaponpage->weapon_struct.player_damage * 100.0f; |
| 1126 | if (weaponpage->weapon_struct.impact_size > 0.0) { |
| 1127 | weaponpage->weapon_struct.impact_time = weaponpage->weapon_struct.explode_time; |
| 1128 | weaponpage->weapon_struct.impact_size = weaponpage->weapon_struct.explode_size * 1.5; |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | // Clear out old strings |
| 1133 | if (!strnicmp("INVALID", weaponpage->explode_image_name, 7)) |
| 1134 | strcpy(weaponpage->explode_image_name, ""); |
| 1135 | if (!strnicmp("INVALID", weaponpage->smoke_image_name, 7)) |
| 1136 | strcpy(weaponpage->smoke_image_name, ""); |
| 1137 | if (!strnicmp("INVALID", weaponpage->scorch_image_name, 7)) |
| 1138 | strcpy(weaponpage->scorch_image_name, ""); |
| 1139 | if (!strnicmp("INVALID", weaponpage->icon_name, 7)) |
| 1140 | strcpy(weaponpage->icon_name, ""); |
| 1141 | if (!strnicmp("INVALID", weaponpage->spawn_name, 7)) |
| 1142 | strcpy(weaponpage->spawn_name, ""); |
| 1143 | if (!strnicmp("INVALID", weaponpage->alternate_spawn_name, 7)) |
| 1144 | strcpy(weaponpage->alternate_spawn_name, ""); |
| 1145 | if (!strnicmp("INVALID", weaponpage->robot_spawn_name, 7)) |
| 1146 | strcpy(weaponpage->robot_spawn_name, ""); |
| 1147 | if (!strnicmp("INVALID", weaponpage->particle_name, 7)) |
| 1148 | strcpy(weaponpage->particle_name, ""); |
| 1149 | |
| 1150 | for (i = 0; i < MAX_WEAPON_SOUNDS; i++) { |
| 1151 | if (!strnicmp("INVALID", weaponpage->sound_name[i], 7)) |
| 1152 | strcpy(weaponpage->sound_name[i], ""); |
| 1153 | } |
| 1154 | |
| 1155 | // This is a valid new page |
| 1156 | weaponpage->weapon_struct.used = 1; |
| 1157 | |
| 1158 | return 1; // successfully read |
| 1159 | } |
| 1160 | |
| 1161 | // Reads in the weapon named "name" into weaponpage struct |
| 1162 | // Returns 0 on error or couldn't find, else 1 if all is good |
| 1163 | int mng_FindSpecificWeaponPage(char *name, mngs_weapon_page *weaponpage) { |
| 1164 | CFILE *infile; |
| 1165 | uint8_t pagetype; |
| 1166 | int done = 0, found = 0; |
| 1167 | int first_try = 1; |
| 1168 | std::filesystem::path tablename; |
| 1169 | |
| 1170 | if (Loading_locals) { |
| 1171 | infile = cfopen(LocalTableFilename, "rb"); |
| 1172 | } else if (Loading_addon_table != -1) { |
| 1173 | infile = cfopen(AddOnDataTables[Loading_addon_table].AddOnTableFilename, "rb"); |
| 1174 | } else { |
| 1175 | if (Network_up && Starting_editor) { |
| 1176 | int farg = FindArg("-filter"); |
| 1177 | |
| 1178 | if (farg) |
| 1179 | tablename = GameArgs[farg + 1]; |
| 1180 | else |
| 1181 | tablename = LocalTableDir / NET_TABLE; |
| 1182 | |
| 1183 | infile = cfopen(tablename, "rb"); |
| 1184 | } else { |
| 1185 | infile = NULL; |
| 1186 | if (TablefileNameOverride) { |
| 1187 | infile = cfopen(TablefileNameOverride, "rb"); |
| 1188 | } |
| 1189 | |
| 1190 | if (!infile) |
| 1191 | infile = cfopen(TableFilename, "rb"); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | if (!infile) { |
| 1196 | mprintf(0, "Couldn't open table file to find weapon!\n"); |
| 1197 | Int3(); |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | try_again:; |
| 1202 | |
| 1203 | // Read in the entire page file until we find the page we want |
| 1204 | while (!done) { |
| 1205 | if (cfeof(infile)) { |
| 1206 | done = 1; |
| 1207 | continue; |
| 1208 | } |
| 1209 | pagetype = cf_ReadByte(infile); |
| 1210 | int len = cf_ReadInt(infile); |
| 1211 | |
| 1212 | // If not a weapon page, just read it in and ignore it |
| 1213 | if (pagetype != PAGETYPE_WEAPON) { |
| 1214 | cfseek(infile, len - 4, SEEK_CUR); |
| 1215 | continue; |
| 1216 | } |
| 1217 | |
| 1218 | mng_ReadNewWeaponPage(infile, weaponpage); |
| 1219 | |
| 1220 | if (!stricmp(name, weaponpage->weapon_struct.name)) { |
| 1221 | // This is the page we want |
| 1222 | found = 1; |
| 1223 | done = 1; |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | cfclose(infile); |
| 1228 | |
| 1229 | if (!found && first_try) { |
| 1230 | done = first_try = 0; |
| 1231 | infile = cfopen("extra.gam", "rb"); |
| 1232 | if (infile) |
| 1233 | goto try_again; |
| 1234 | } |
| 1235 | |
| 1236 | return found; // successful! |
| 1237 | } |
| 1238 | |
| 1239 | // Reads in the weapon named "name" into weaponpage struct |
| 1240 | // Returns 0 on error or couldn't find, else 1 if all is good |
| 1241 | int mng_FindSpecificWeaponPage(char *name, mngs_weapon_page *weaponpage, int offset) { |
| 1242 | CFILE *infile; |
| 1243 | uint8_t pagetype; |
| 1244 | int done = 0, found = 0; |
| 1245 | |
| 1246 | if (Loading_locals) { |
| 1247 | infile = cfopen(LocalTableFilename, "rb"); |
| 1248 | } else if (Loading_addon_table != -1) { |
| 1249 | infile = cfopen(AddOnDataTables[Loading_addon_table].AddOnTableFilename, "rb"); |
| 1250 | } else { |
| 1251 | if (Network_up && Starting_editor) { |
| 1252 | std::filesystem::path tablename; |
| 1253 | |
| 1254 | int farg = FindArg("-filter"); |
| 1255 | if (farg) |
| 1256 | tablename = GameArgs[farg + 1]; |
| 1257 | else |
| 1258 | tablename = LocalTableDir / NET_TABLE; |
| 1259 | |
| 1260 | infile = cfopen(tablename, "rb"); |
| 1261 | } else { |
| 1262 | infile = NULL; |
| 1263 | if (TablefileNameOverride) { |
| 1264 | infile = cfopen(TablefileNameOverride, "rb"); |
| 1265 | } |
| 1266 | |
| 1267 | if (!infile) |
| 1268 | infile = cfopen(TableFilename, "rb"); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | if (!infile) { |
| 1273 | mprintf(0, "Couldn't open table file to find weapon!\n"); |
| 1274 | Int3(); |
| 1275 | return 0; |
| 1276 | } |
| 1277 | |
| 1278 | if (offset) |
| 1279 | cfseek(infile, offset, SEEK_SET); |
| 1280 | |
| 1281 | // Read in the entire page file until we find the page we want |
| 1282 | while (!done) { |
| 1283 | if (cfeof(infile)) { |
| 1284 | done = 1; |
| 1285 | continue; |
| 1286 | } |
| 1287 | pagetype = cf_ReadByte(infile); |
| 1288 | int len = cf_ReadInt(infile); |
| 1289 | |
| 1290 | // If not a weapon page, just read it in and ignore it |
| 1291 | if (pagetype != PAGETYPE_WEAPON) { |
| 1292 | cfseek(infile, len - 4, SEEK_CUR); |
| 1293 | continue; |
| 1294 | } |
| 1295 | |
| 1296 | mng_ReadNewWeaponPage(infile, weaponpage); |
| 1297 | |
| 1298 | if (!stricmp(name, weaponpage->weapon_struct.name)) { |
| 1299 | // This is the page we want |
| 1300 | found = 1; |
| 1301 | done = 1; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | cfclose(infile); |
| 1306 | |
| 1307 | return found; // successful! |
| 1308 | } |
| 1309 | |
| 1310 | const char *Weapon_error = NULL; |
| 1311 | const char *Weapon_error_filename = NULL; |
| 1312 | |
| 1313 | // First searches through the weapon index to see if the weapon is already |
| 1314 | // loaded. If not, searches in the table file and loads it. |
| 1315 | // Returns index of weapon found, -1 if not |
| 1316 | int mng_GetGuaranteedWeaponPage(char *name, CFILE *infile) { |
| 1317 | int i; |
| 1318 | mngs_weapon_page weaponpage; |
| 1319 | |
| 1320 | // See if its in memory |
| 1321 | i = FindWeaponName(name); |
| 1322 | if (i != -1) |
| 1323 | return i; |
| 1324 | |
| 1325 | // Not in memory. Load it from the table file. Start searching from the |
| 1326 | // current spot in the open table file |
| 1327 | |
| 1328 | int ret = mng_FindSpecificWeaponPage(name, &weaponpage, infile ? infile->position : 0); |
| 1329 | |
| 1330 | if (!ret) |
| 1331 | return -1; |
| 1332 | |
| 1333 | // We've found it in the table file, now load it. |
| 1334 | ret = mng_SetAndLoadWeapon(&weaponpage, infile); |
| 1335 | // ASSERT (ret>=0); |
| 1336 | if (ret < 0) |
| 1337 | DataError("Error loading weapon <%s>: %s, file <%s>\n", weaponpage.weapon_struct.name, Weapon_error, |
| 1338 | Weapon_error_filename); |
| 1339 | |
| 1340 | if (Loading_addon_table != -1) { |
| 1341 | // we're loading addon table pages, this will not overlay anything |
| 1342 | mng_PushAddonPage(PAGETYPE_WEAPON, weaponpage.weapon_struct.name, 0); |
| 1343 | } |
| 1344 | |
| 1345 | return ret; |
| 1346 | } |
| 1347 | |
| 1348 | // Given a weapon page, allocs a weapon and calls AssignWeaponPageToWeapon to actually |
| 1349 | // load models and values. Rturns weapon handle on success, -1 if fail |
| 1350 | int mng_SetAndLoadWeapon(mngs_weapon_page *weaponpage, CFILE *infile) { |
| 1351 | int n; |
| 1352 | |
| 1353 | Weapon_error = Weapon_error_filename = ""; |
| 1354 | |
| 1355 | n = AllocWeapon(); |
| 1356 | if (n < 0) { |
| 1357 | Weapon_error = "No free weapon slots"; |
| 1358 | return -1; |
| 1359 | } |
| 1360 | if (!mng_AssignWeaponPageToWeapon(weaponpage, n, infile)) |
| 1361 | return -1; |
| 1362 | |
| 1363 | return n; |
| 1364 | } |
| 1365 | |
| 1366 | // Given a weaponpage and a weapon handle, attempts to make weapon n correspond to |
| 1367 | // to the weaponpage. |
| 1368 | // Returns 1 on success, 0 otherwise |
| 1369 | int mng_AssignWeaponPageToWeapon(mngs_weapon_page *weaponpage, int n, CFILE *infile) { |
| 1370 | weapon *weaponpointer = &Weapons[n]; |
| 1371 | int img_handle, i, sound_handle; |
| 1372 | |
| 1373 | // copy our values |
| 1374 | memcpy(weaponpointer, &weaponpage->weapon_struct, sizeof(weapon)); |
| 1375 | strcpy(weaponpointer->name, weaponpage->weapon_struct.name); |
| 1376 | |
| 1377 | // First see if our image differs from the one on the net |
| 1378 | // If it is, make a copy |
| 1379 | // If its a release version, don't do any of this |
| 1380 | |
| 1381 | #ifndef RELEASE |
| 1382 | if (Network_up) { |
| 1383 | std::filesystem::path str = LocalManageGraphicsDir; |
| 1384 | std::filesystem::path netstr = ManageGraphicsDir; |
| 1385 | |
| 1386 | UpdatePrimitive(str / weaponpage->hud_image_name, netstr / weaponpage->hud_image_name, weaponpage->hud_image_name, |
| 1387 | PAGETYPE_WEAPON, weaponpointer->name); |
| 1388 | |
| 1389 | // Now copy the discharge image, depending on whether or not its a model |
| 1390 | if (!((weaponpage->weapon_struct.flags & WF_IMAGE_BITMAP) || (weaponpage->weapon_struct.flags & WF_IMAGE_VCLIP))) { |
| 1391 | str = LocalModelsDir; |
| 1392 | netstr = NetModelsDir; |
| 1393 | } |
| 1394 | |
| 1395 | UpdatePrimitive(str / weaponpage->fire_image_name, netstr / weaponpage->fire_image_name, |
| 1396 | weaponpage->fire_image_name, PAGETYPE_WEAPON, weaponpointer->name); |
| 1397 | } |
| 1398 | #endif |
| 1399 | |
| 1400 | // Try and load our weapon model from the disk |
| 1401 | |
| 1402 | if (weaponpointer->flags & WF_HUD_ANIMATED) |
| 1403 | img_handle = AllocLoadVClip(weaponpage->hud_image_name, NOT_TEXTURE, 0); |
| 1404 | else |
| 1405 | img_handle = bm_AllocLoadFileBitmap(weaponpage->hud_image_name, 0); |
| 1406 | |
| 1407 | if (img_handle < 0) { |
| 1408 | mprintf(0, "Couldn't load bitmap '%s' in AssignWeaponPage...\n", weaponpage->hud_image_name); |
| 1409 | weaponpointer->hud_image_handle = -1; |
| 1410 | Weapon_error = "Can't load HUD image"; |
| 1411 | Weapon_error_filename = weaponpage->hud_image_name; |
| 1412 | return 0; |
| 1413 | } else |
| 1414 | weaponpointer->hud_image_handle = img_handle; |
| 1415 | |
| 1416 | if (weaponpointer->flags & WF_IMAGE_BITMAP) |
| 1417 | img_handle = bm_AllocLoadFileBitmap(weaponpage->fire_image_name, 0); |
| 1418 | else if (weaponpointer->flags & WF_IMAGE_VCLIP) |
| 1419 | img_handle = AllocLoadVClip(weaponpage->fire_image_name, NOT_TEXTURE, 0); |
| 1420 | else |
| 1421 | img_handle = LoadPolyModel(weaponpage->fire_image_name, 1); |
| 1422 | |
| 1423 | if (img_handle < 0) { |
| 1424 | mprintf(0, "Couldn't load bitmap/model '%s' in AssignWeaponPage...\n", weaponpage->fire_image_name); |
| 1425 | weaponpointer->fire_image_handle = -1; |
| 1426 | Weapon_error = "Can't load fire image"; |
| 1427 | Weapon_error_filename = weaponpage->fire_image_name; |
| 1428 | return 0; |
| 1429 | } else { |
| 1430 | weaponpointer->fire_image_handle = img_handle; |
| 1431 | |
| 1432 | /*// Fix size |
| 1433 | if (!(weaponpointer->flags & WF_IMAGE_BITMAP)) |
| 1434 | { |
| 1435 | if (Poly_models[img_handle].new_style && Poly_models[img_handle].flags & PMF_TIMED) |
| 1436 | { |
| 1437 | weaponpointer->size=ComputeDefaultSize(img_handle); |
| 1438 | } |
| 1439 | }*/ |
| 1440 | } |
| 1441 | |
| 1442 | if (stricmp(weaponpage->explode_image_name, "INVALID NAME") && weaponpage->explode_image_name[0] != 0) { |
| 1443 | img_handle = mng_GetGuaranteedTexturePage(weaponpage->explode_image_name, infile); |
| 1444 | |
| 1445 | if (img_handle < 0) { |
| 1446 | mprintf(0, "Couldn't load bitmap/model '%s' in AssignWeaponPage...\n", weaponpage->explode_image_name); |
| 1447 | weaponpointer->explode_image_handle = -1; |
| 1448 | } else |
| 1449 | weaponpointer->explode_image_handle = img_handle; |
| 1450 | } else |
| 1451 | weaponpointer->explode_image_handle = -1; |
| 1452 | |
| 1453 | // Try to load particle texture |
| 1454 | if (stricmp(weaponpage->particle_name, "INVALID NAME") && weaponpage->particle_name[0] != 0) { |
| 1455 | img_handle = mng_GetGuaranteedTexturePage(weaponpage->particle_name, infile); |
| 1456 | |
| 1457 | if (img_handle < 0) { |
| 1458 | mprintf(0, "Couldn't load bitmap/model '%s' in AssignWeaponPage...\n", weaponpage->particle_name); |
| 1459 | weaponpointer->particle_handle = -1; |
| 1460 | } else |
| 1461 | weaponpointer->particle_handle = img_handle; |
| 1462 | } else |
| 1463 | weaponpointer->particle_handle = -1; |
| 1464 | |
| 1465 | // Try to load spawn weapons |
| 1466 | if (stricmp(weaponpage->spawn_name, "INVALID NAME") && weaponpage->spawn_name[0] != 0) { |
| 1467 | img_handle = mng_GetGuaranteedWeaponPage(weaponpage->spawn_name, infile); |
| 1468 | |
| 1469 | if (img_handle < 0) { |
| 1470 | mprintf(0, "Couldn't load spawn weapon '%s' in AssignWeaponPage...\n", weaponpage->spawn_name); |
| 1471 | weaponpointer->spawn_handle = -1; |
| 1472 | } else |
| 1473 | weaponpointer->spawn_handle = img_handle; |
| 1474 | } else |
| 1475 | weaponpointer->spawn_handle = -1; |
| 1476 | |
| 1477 | if (stricmp(weaponpage->alternate_spawn_name, "INVALID NAME") && weaponpage->alternate_spawn_name[0] != 0) { |
| 1478 | img_handle = mng_GetGuaranteedWeaponPage(weaponpage->alternate_spawn_name, infile); |
| 1479 | |
| 1480 | if (img_handle < 0) { |
| 1481 | mprintf(0, "Couldn't load alternate spawn weapon '%s' in AssignWeaponPage...\n", |
| 1482 | weaponpage->alternate_spawn_name); |
| 1483 | weaponpointer->alternate_spawn_handle = -1; |
| 1484 | } else |
| 1485 | weaponpointer->alternate_spawn_handle = img_handle; |
| 1486 | } else |
| 1487 | weaponpointer->alternate_spawn_handle = -1; |
| 1488 | |
| 1489 | // Try to load robot spawn |
| 1490 | if (stricmp(weaponpage->robot_spawn_name, "INVALID NAME") && weaponpage->robot_spawn_name[0] != 0) { |
| 1491 | img_handle = mng_GetGuaranteedGenericPage(weaponpage->robot_spawn_name, infile); |
| 1492 | |
| 1493 | if (img_handle < 0) { |
| 1494 | mprintf(0, "Couldn't load robot spawn weapon '%s' in AssignWeaponPage...\n", weaponpage->robot_spawn_name); |
| 1495 | weaponpointer->robot_spawn_handle = -1; |
| 1496 | } else |
| 1497 | weaponpointer->robot_spawn_handle = img_handle; |
| 1498 | } else |
| 1499 | weaponpointer->robot_spawn_handle = -1; |
| 1500 | |
| 1501 | // Try to load smoke |
| 1502 | if (stricmp(weaponpage->smoke_image_name, "INVALID NAME") && weaponpage->smoke_image_name[0] != 0) { |
| 1503 | img_handle = mng_GetGuaranteedTexturePage(weaponpage->smoke_image_name, infile); |
| 1504 | |
| 1505 | if (img_handle < 0) { |
| 1506 | mprintf(0, "Couldn't load smoke trail file '%s' in AssignWeaponPage...\n", weaponpage->smoke_image_name); |
| 1507 | weaponpointer->flags &= ~WF_SMOKE; |
| 1508 | weaponpointer->smoke_handle = -1; |
| 1509 | |
| 1510 | } else |
| 1511 | weaponpointer->smoke_handle = img_handle; |
| 1512 | } else { |
| 1513 | weaponpointer->flags &= ~WF_SMOKE; |
| 1514 | weaponpointer->smoke_handle = -1; |
| 1515 | } |
| 1516 | |
| 1517 | // Try to load scorch |
| 1518 | if (stricmp(weaponpage->scorch_image_name, "INVALID NAME") && weaponpage->scorch_image_name[0] != 0) { |
| 1519 | img_handle = mng_GetGuaranteedTexturePage(weaponpage->scorch_image_name, infile); |
| 1520 | |
| 1521 | if (img_handle < 0) { |
| 1522 | mprintf(0, "Couldn't load scorch file '%s' in AssignWeaponPage...\n", weaponpage->scorch_image_name); |
| 1523 | weaponpointer->scorch_handle = -1; |
| 1524 | |
| 1525 | } else |
| 1526 | weaponpointer->scorch_handle = img_handle; |
| 1527 | } else { |
| 1528 | weaponpointer->scorch_handle = -1; |
| 1529 | } |
| 1530 | |
| 1531 | // Try to load icone |
| 1532 | if (stricmp(weaponpage->icon_name, "INVALID NAME") && weaponpage->icon_name[0] != 0) { |
| 1533 | img_handle = mng_GetGuaranteedTexturePage(weaponpage->icon_name, infile); |
| 1534 | |
| 1535 | if (img_handle < 0) { |
| 1536 | mprintf(0, "Couldn't load icon file '%s' in AssignWeaponPage...\n", weaponpage->icon_name); |
| 1537 | weaponpointer->icon_handle = -1; |
| 1538 | |
| 1539 | } else |
| 1540 | weaponpointer->icon_handle = img_handle; |
| 1541 | } else { |
| 1542 | weaponpointer->icon_handle = -1; |
| 1543 | } |
| 1544 | |
| 1545 | // Try and load the various sounds |
| 1546 | for (i = 0; i < MAX_WEAPON_SOUNDS; i++) { |
| 1547 | if (stricmp(weaponpage->sound_name[i], "INVALID NAME") && (strlen(weaponpage->sound_name[i]) > 3)) { |
| 1548 | sound_handle = mng_GetGuaranteedSoundPage(weaponpage->sound_name[i]); |
| 1549 | |
| 1550 | if (sound_handle < 0) { |
| 1551 | mprintf(0, "Couldn't load sound file '%s' in AssignWeaponPage. Weapon=%s\n", weaponpage->sound_name[i], |
| 1552 | weaponpage->weapon_struct.name); |
| 1553 | weaponpointer->sounds[i] = SOUND_NONE_INDEX; |
| 1554 | } else |
| 1555 | weaponpointer->sounds[i] = sound_handle; |
| 1556 | } else |
| 1557 | weaponpointer->sounds[i] = SOUND_NONE_INDEX; |
| 1558 | } |
| 1559 | |
| 1560 | return 1; |
| 1561 | } |
| 1562 | |
| 1563 | // Copies values from a weapon into a weapon_page |
| 1564 | void mng_AssignWeaponToWeaponPage(int n, mngs_weapon_page *weaponpage) { |
| 1565 | weapon *weaponpointer = &Weapons[n]; |
| 1566 | int i; |
| 1567 | |
| 1568 | // Assign the values |
| 1569 | memcpy(&weaponpage->weapon_struct, weaponpointer, sizeof(weapon)); |
| 1570 | |
| 1571 | strcpy(weaponpage->weapon_struct.name, weaponpointer->name); |
| 1572 | |
| 1573 | if (weaponpointer->hud_image_handle != -1) { |
| 1574 | if (weaponpointer->flags & WF_HUD_ANIMATED) |
| 1575 | strcpy(weaponpage->hud_image_name, GameVClips[weaponpointer->hud_image_handle].name); |
| 1576 | else |
| 1577 | strcpy(weaponpage->hud_image_name, GameBitmaps[weaponpointer->hud_image_handle].name); |
| 1578 | } else |
| 1579 | strcpy(weaponpage->hud_image_name, ""); |
| 1580 | |
| 1581 | if (weaponpointer->fire_image_handle != -1) { |
| 1582 | if (weaponpointer->flags & WF_IMAGE_BITMAP) |
| 1583 | strcpy(weaponpage->fire_image_name, GameBitmaps[weaponpointer->fire_image_handle].name); |
| 1584 | else if (weaponpointer->flags & WF_IMAGE_VCLIP) |
| 1585 | strcpy(weaponpage->fire_image_name, GameVClips[weaponpointer->fire_image_handle].name); |
| 1586 | else |
| 1587 | strcpy(weaponpage->fire_image_name, Poly_models[weaponpointer->fire_image_handle].name); |
| 1588 | } else |
| 1589 | strcpy(weaponpage->fire_image_name, ""); |
| 1590 | |
| 1591 | // do explosion name |
| 1592 | |
| 1593 | if (weaponpointer->explode_image_handle != -1) |
| 1594 | strcpy(weaponpage->explode_image_name, GameTextures[weaponpointer->explode_image_handle].name); |
| 1595 | else |
| 1596 | strcpy(weaponpage->explode_image_name, ""); |
| 1597 | |
| 1598 | // Do particle name |
| 1599 | if (weaponpointer->particle_handle != -1) |
| 1600 | strcpy(weaponpage->particle_name, GameTextures[weaponpointer->particle_handle].name); |
| 1601 | else |
| 1602 | strcpy(weaponpage->particle_name, ""); |
| 1603 | |
| 1604 | // Do spawn name |
| 1605 | if (weaponpointer->spawn_handle != -1) |
| 1606 | strcpy(weaponpage->spawn_name, Weapons[weaponpointer->spawn_handle].name); |
| 1607 | else |
| 1608 | strcpy(weaponpage->spawn_name, ""); |
| 1609 | |
| 1610 | // Do spawn name |
| 1611 | if (weaponpointer->alternate_spawn_handle != -1) |
| 1612 | strcpy(weaponpage->alternate_spawn_name, Weapons[weaponpointer->alternate_spawn_handle].name); |
| 1613 | else |
| 1614 | strcpy(weaponpage->alternate_spawn_name, ""); |
| 1615 | |
| 1616 | // Do robot spawn name |
| 1617 | if (weaponpointer->robot_spawn_handle != -1) |
| 1618 | strcpy(weaponpage->robot_spawn_name, Object_info[weaponpointer->robot_spawn_handle].name); |
| 1619 | else |
| 1620 | strcpy(weaponpage->robot_spawn_name, ""); |
| 1621 | |
| 1622 | if ((weaponpointer->flags & WF_SMOKE) && weaponpointer->smoke_handle >= 0 && |
| 1623 | GameTextures[weaponpointer->smoke_handle].used) { |
| 1624 | strcpy(weaponpage->smoke_image_name, GameTextures[weaponpointer->smoke_handle].name); |
| 1625 | } else |
| 1626 | strcpy(weaponpage->smoke_image_name, ""); |
| 1627 | |
| 1628 | if (weaponpointer->scorch_handle >= 0 && GameTextures[weaponpointer->scorch_handle].used) { |
| 1629 | strcpy(weaponpage->scorch_image_name, GameTextures[weaponpointer->scorch_handle].name); |
| 1630 | } else |
| 1631 | strcpy(weaponpage->scorch_image_name, ""); |
| 1632 | |
| 1633 | if (weaponpointer->icon_handle >= 0 && GameTextures[weaponpointer->icon_handle].used) { |
| 1634 | strcpy(weaponpage->icon_name, GameTextures[weaponpointer->icon_handle].name); |
| 1635 | } else |
| 1636 | strcpy(weaponpage->icon_name, ""); |
| 1637 | |
| 1638 | for (i = 0; i < MAX_WEAPON_SOUNDS; i++) { |
| 1639 | if (weaponpointer->sounds[i] != SOUND_NONE_INDEX) |
| 1640 | strcpy(weaponpage->sound_name[i], Sounds[weaponpointer->sounds[i]].name); |
| 1641 | else |
| 1642 | strcpy(weaponpage->sound_name[i], ""); |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | // Loads a weapon found in the net table file. It then allocs a weapon and |
| 1647 | // then calls SetAndLoadWeapon to actually load in any images/models associated |
| 1648 | // with it |
| 1649 | void mng_LoadNetWeaponPage(CFILE *infile, bool overlay) { |
| 1650 | mngs_weapon_page weaponpage; |
| 1651 | memset(&weaponpage, 0, sizeof(mngs_weapon_page)); |
| 1652 | |
| 1653 | if (mng_ReadNewWeaponPage(infile, &weaponpage)) { |
| 1654 | int n = FindWeaponName(weaponpage.weapon_struct.name); |
| 1655 | if (n != -1) { |
| 1656 | if (overlay) { |
| 1657 | mprintf(0, "OVERLAYING WEAPON %s\n", weaponpage.weapon_struct.name); |
| 1658 | mng_FreePagetypePrimitives(PAGETYPE_WEAPON, weaponpage.weapon_struct.name, 0); |
| 1659 | mng_AssignWeaponPageToWeapon(&weaponpage, n); |
| 1660 | } |
| 1661 | // mprintf(0,"Found weapon dependency! You probably should reorder the netpages.\n"); |
| 1662 | return; |
| 1663 | } |
| 1664 | |
| 1665 | int ret = mng_SetAndLoadWeapon(&weaponpage, infile); |
| 1666 | ASSERT(ret >= 0); |
| 1667 | } else |
| 1668 | mprintf(0, "Could not load weaponpage named %s!\n", weaponpage.weapon_struct.name); |
| 1669 | } |
| 1670 | |
| 1671 | // Reads a weapon page from a local table file. It then allocs a weapon and |
| 1672 | // loads any images/models associated with that weapon |
| 1673 | void mng_LoadLocalWeaponPage(CFILE *infile) { |
| 1674 | mngs_weapon_page weaponpage; |
| 1675 | int ok = 0; |
| 1676 | memset(&weaponpage, 0, sizeof(mngs_weapon_page)); |
| 1677 | |
| 1678 | if (mng_ReadNewWeaponPage(infile, &weaponpage)) { |
| 1679 | // Check to see if this is a local copy that is supposed |
| 1680 | // to go over a network copy (supersede the net copy) |
| 1681 | |
| 1682 | int i = FindWeaponName(weaponpage.weapon_struct.name); |
| 1683 | if (i != -1) { |
| 1684 | // Make sure we really have this page checked out |
| 1685 | mngs_Pagelock pl; |
| 1686 | |
| 1687 | strcpy(pl.name, weaponpage.weapon_struct.name); |
| 1688 | pl.pagetype = PAGETYPE_WEAPON; |
| 1689 | |
| 1690 | /*if (Network_up && Stand_alone==0) |
| 1691 | { |
| 1692 | int locked=mng_CheckIfPageOwned(&pl,TableUser); |
| 1693 | if (locked!=1) |
| 1694 | Int3(); // Your local vs net copies of the lock file do not match |
| 1695 | }*/ |
| 1696 | ok = 1; |
| 1697 | bool need_to_load_page = true; |
| 1698 | |
| 1699 | if (Loading_addon_table != -1) { |
| 1700 | AddOnTablefile *addon; |
| 1701 | int tidx; |
| 1702 | |
| 1703 | // see if we really need to load this page |
| 1704 | // check to see if we already have loaded this page (because it was |
| 1705 | // a dependancy of another) |
| 1706 | addon = &AddOnDataTables[Loading_addon_table]; |
| 1707 | for (tidx = 0; tidx < addon->Num_addon_tracklocks; tidx++) { |
| 1708 | if (addon->Addon_tracklocks[tidx].pagetype == PAGETYPE_WEAPON && |
| 1709 | !stricmp(addon->Addon_tracklocks[tidx].name, weaponpage.weapon_struct.name)) { |
| 1710 | // found it!! |
| 1711 | mprintf(0, "WeaponPage: %s previously loaded\n", weaponpage.weapon_struct.name); |
| 1712 | need_to_load_page = false; |
| 1713 | break; |
| 1714 | } |
| 1715 | } |
| 1716 | } |
| 1717 | |
| 1718 | if (need_to_load_page) { |
| 1719 | mng_FreePagetypePrimitives(PAGETYPE_WEAPON, weaponpage.weapon_struct.name, 0); |
| 1720 | mng_AssignWeaponPageToWeapon(&weaponpage, i); |
| 1721 | |
| 1722 | // For addon data |
| 1723 | if (ok && Loading_addon_table != -1) { |
| 1724 | // this is an overlay of some sort..see which we are overlaying |
| 1725 | int overlay = 1; |
| 1726 | int addidx, tidx; |
| 1727 | bool found = false; |
| 1728 | for (addidx = Num_addon_tables - 1; addidx >= 0; addidx--) { |
| 1729 | if (addidx == Loading_addon_table) |
| 1730 | continue; |
| 1731 | AddOnTablefile *addon = &AddOnDataTables[addidx]; |
| 1732 | |
| 1733 | // look for the page in this table file |
| 1734 | for (tidx = 0; tidx < addon->Num_addon_tracklocks; tidx++) { |
| 1735 | if (addon->Addon_tracklocks[tidx].pagetype == PAGETYPE_WEAPON && |
| 1736 | !stricmp(addon->Addon_tracklocks[tidx].name, weaponpage.weapon_struct.name)) { |
| 1737 | // found it!! |
| 1738 | found = true; |
| 1739 | overlay = addidx + 2; |
| 1740 | break; |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | if (found) |
| 1745 | break; |
| 1746 | } |
| 1747 | |
| 1748 | mng_PushAddonPage(PAGETYPE_WEAPON, weaponpage.weapon_struct.name, overlay); |
| 1749 | } |
| 1750 | } |
| 1751 | } else { |
| 1752 | // This is a local weapon that has never been checked in |
| 1753 | if ((i = mng_SetAndLoadWeapon(&weaponpage, infile)) < 0) |
| 1754 | ok = 0; |
| 1755 | else |
| 1756 | ok = 1; |
| 1757 | |
| 1758 | // For addon data |
| 1759 | if (ok && Loading_addon_table != -1) |
| 1760 | mng_PushAddonPage(PAGETYPE_WEAPON, weaponpage.weapon_struct.name, 0); |
| 1761 | } |
| 1762 | |
| 1763 | // ASSERT (ok==1); |
| 1764 | if (ok != 1) |
| 1765 | DataError("Error loading weapon <%s>: %s, file <%s>\n", weaponpage.weapon_struct.name, Weapon_error, |
| 1766 | Weapon_error_filename); |
| 1767 | |
| 1768 | if (Loading_addon_table == -1) |
| 1769 | mng_AllocTrackLock(weaponpage.weapon_struct.name, PAGETYPE_WEAPON); |
| 1770 | } else |
| 1771 | |
| 1772 | mprintf(0, "Could not load weaponpage named %s!\n", weaponpage.weapon_struct.name); |
| 1773 | } |