1 /* 2 * Copyright (C) Volition, Inc. 1999. All rights reserved. 3 * 4 * All source code herein is the property of Volition, Inc. You may not sell 5 * or otherwise commercially exploit the source or things you created based on the 6 * source. 7 * 8 */ 9 10 #ifndef _PARSE_H 11 #define _PARSE_H 12 13 #include <csetjmp> 14 15 #include "ai/ai.h" 16 #include "ai/ai_profiles.h" 17 #include "graphics/2d.h" 18 #include "io/keycontrol.h" 19 #include "model/model.h" 20 #include "object/object.h" 21 #include "parse/sexp.h" 22 #include "sound/sound.h" 23 #include "mission/mission_flags.h" 24 25 //WMC - This should be here 26 #define FS_MISSION_FILE_EXT NOX(".fs2") 27 28 struct wing; 29 struct p_dock_instance; 30 31 #define NUM_NEBULAS 3 // how many background nebulas we have altogether 32 #define NUM_NEBULA_COLORS 9 33 34 #define DEFAULT_AMBIENT_LIGHT_LEVEL 0x00787878 35 36 // arrival anchor types 37 // mask should be high enough to avoid conflicting with ship anchors 38 #define SPECIAL_ARRIVAL_ANCHOR_FLAG 0x1000 39 #define SPECIAL_ARRIVAL_ANCHOR_PLAYER_FLAG 0x0100 40 41 int get_special_anchor(const char *name); 42 43 // update version when mission file format changes, and add approprate code 44 // to check loaded mission version numbers in the parse code. Also, be sure 45 // to update both MissionParse and MissionSave (FRED) when changing the 46 // mission file format! 47 #define MISSION_VERSION 0.10f 48 #define FRED_MISSION_VERSION 0.10f 49 50 #define WING_PLAYER_BASE 0x80000 // used by Fred to tell ship_index in a wing points to a player 51 52 // mission parse flags used for parse_mission() to tell what kind of information to get from the mission file 53 #define MPF_ONLY_MISSION_INFO (1 << 0) 54 #define MPF_IMPORT_FSM (1 << 1) 55 56 // bitfield definitions for missions game types 57 #define OLD_MAX_GAME_TYPES 4 // needed for compatibility 58 #define OLD_GAME_TYPE_SINGLE_ONLY 0 59 #define OLD_GAME_TYPE_MULTI_ONLY 1 60 #define OLD_GAME_TYPE_SINGLE_MULTI 2 61 #define OLD_GAME_TYPE_TRAINING 3 62 63 #define MAX_MISSION_TYPES 5 64 #define MISSION_TYPE_SINGLE (1<<0) 65 #define MISSION_TYPE_MULTI (1<<1) 66 #define MISSION_TYPE_TRAINING (1<<2) 67 #define MISSION_TYPE_MULTI_COOP (1<<3) 68 #define MISSION_TYPE_MULTI_TEAMS (1<<4) 69 #define MISSION_TYPE_MULTI_DOGFIGHT (1<<5) 70 71 // some mice macros for mission type 72 #define IS_MISSION_MULTI_COOP (The_mission.game_type & MISSION_TYPE_MULTI_COOP) 73 #define IS_MISSION_MULTI_TEAMS (The_mission.game_type & MISSION_TYPE_MULTI_TEAMS) 74 #define IS_MISSION_MULTI_DOGFIGHT (The_mission.game_type & MISSION_TYPE_MULTI_DOGFIGHT) 75 76 77 // Goober5000 78 typedef struct support_ship_info { 79 int arrival_location; // arrival location 80 int arrival_anchor; // arrival anchor 81 int departure_location; // departure location 82 int departure_anchor; // departure anchor 83 float max_hull_repair_val; // % of a ship's hull that can be repaired -C 84 float max_subsys_repair_val; // same thing, except for subsystems -C 85 int max_support_ships; // max number of consecutive support ships 86 int max_concurrent_ships; // max number of concurrent support ships in mission per team 87 int ship_class; // ship class of support ship 88 int tally; // number of support ships so far 89 int support_available_for_species; // whether support is available for a given species (this is a bitfield) 90 } support_ship_info; 91 92 // movie type defines 93 #define MOVIE_PRE_FICTION 0 94 #define MOVIE_PRE_CMD_BRIEF 1 95 #define MOVIE_PRE_BRIEF 2 96 #define MOVIE_PRE_GAME 3 97 #define MOVIE_PRE_DEBRIEF 4 98 #define MOVIE_END_CAMPAIGN 5 99 100 // defines a mission cutscene. 101 typedef struct mission_cutscene { 102 int type; 103 char filename[MAX_FILENAME_LEN]; 104 int formula; 105 } mission_cutscene; 106 107 typedef struct mission { 108 char name[NAME_LENGTH]; 109 char author[NAME_LENGTH]; 110 float version; 111 char created[DATE_TIME_LENGTH]; 112 char modified[DATE_TIME_LENGTH]; 113 char notes[NOTES_LENGTH]; 114 char mission_desc[MISSION_DESC_LENGTH]; 115 int game_type; 116 flagset<Mission::Mission_Flags> flags; 117 int num_players; // valid in multiplayer missions -- number of players supported 118 uint num_respawns; // valid in multiplayer missions -- number of respawns allowed 119 int max_respawn_delay; // valid in multiplayer missions -- number of respawns allowed 120 support_ship_info support_ships; // Goober5000 121 char squad_filename[MAX_FILENAME_LEN]; // if the player has been reassigned to a squadron, this is the filename of the logo, otherwise empty string 122 char squad_name[NAME_LENGTH]; // if the player has been reassigned to a squadron, this is the name of the squadron, otherwise empty string 123 char loading_screen[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN]; 124 char skybox_model[MAX_FILENAME_LEN]; 125 matrix skybox_orientation; 126 char envmap_name[MAX_FILENAME_LEN]; 127 int skybox_flags; 128 int contrail_threshold; 129 int ambient_light_level; 130 float neb_far_multi; 131 float neb_near_multi; 132 sound_env sound_environment; 133 134 // Goober5000 135 int command_persona; 136 char command_sender[NAME_LENGTH]; 137 int debriefing_persona; 138 139 // Goober5000 140 char event_music_name[NAME_LENGTH]; 141 char briefing_music_name[NAME_LENGTH]; 142 char substitute_event_music_name[NAME_LENGTH]; 143 char substitute_briefing_music_name[NAME_LENGTH]; 144 145 // Goober5000 146 ai_profile_t *ai_profile; 147 148 SCP_vector<mission_cutscene> cutscenes; 149 Resetmission150 void Reset( ) 151 { 152 int i = 0; 153 name[ 0 ] = '\0'; 154 author[ 0 ] = '\0'; 155 version = 0.; 156 created[ 0 ] = '\0'; 157 modified[ 0 ] = '\0'; 158 notes[ 0 ] = '\0'; 159 mission_desc[ 0 ] = '\0'; 160 game_type = 0; 161 flags.reset(); 162 num_players = 0; 163 num_respawns = 0; 164 max_respawn_delay = 0; 165 memset(&Ignored_keys, 0, sizeof(int)*CCFG_MAX); 166 memset( &support_ships, 0, sizeof( support_ships ) ); 167 squad_filename[ 0 ] = '\0'; 168 squad_name[ 0 ] = '\0'; 169 for ( i = 0; i < GR_NUM_RESOLUTIONS; i++ ) 170 loading_screen[ i ][ 0 ] = '\0'; 171 skybox_model[ 0 ] = '\0'; 172 vm_set_identity(&skybox_orientation); 173 skybox_flags = 0; 174 envmap_name[ 0 ] = '\0'; 175 contrail_threshold = 0; 176 ambient_light_level = DEFAULT_AMBIENT_LIGHT_LEVEL; 177 sound_environment.id = -1; 178 command_persona = 0; 179 command_sender[ 0 ] = '\0'; 180 debriefing_persona = -1; 181 event_music_name[ 0 ] = '\0'; 182 briefing_music_name[ 0 ] = '\0'; 183 substitute_event_music_name[ 0 ] = '\0'; 184 substitute_briefing_music_name[ 0 ] = '\0'; 185 ai_profile = NULL; 186 cutscenes.clear( ); 187 } 188 missionmission189 mission( ) 190 { 191 Reset( ); 192 } 193 } mission; 194 195 // cargo defines 196 // NOTE: MAX_CARGO MUST REMAIN <= 64 (CARGO_NO_DEPLETE) for NO_DEPLETE to work. 197 // FURTHER NOTE (Goober5000): If a new flag is added here, the code (particularly in sexp.cpp) 198 // must be reworked so that all the flags are maintained from function to function 199 #define CARGO_INDEX_MASK 0xBF 200 #define CARGO_NO_DEPLETE 0x40 // CARGO_NO_DEPLETE + CARGO_INDEX_MASK must == FF 201 #define MAX_CARGO 30 202 203 204 // Goober5000 - contrail threshold (previously defined in ShipContrails.cpp) 205 #define CONTRAIL_THRESHOLD_DEFAULT 45 206 207 extern mission The_mission; 208 extern char Mission_filename[80]; // filename of mission in The_mission (Fred only) 209 210 #define MAX_FORMATION_NAMES 3 211 #define MAX_STATUS_NAMES 3 212 213 // defines for arrival locations. These defines should match their counterparts in the arrival location 214 // array 215 #define MAX_ARRIVAL_NAMES 4 216 #define ARRIVE_AT_LOCATION 0 217 #define ARRIVE_NEAR_SHIP 1 218 #define ARRIVE_IN_FRONT_OF_SHIP 2 219 #define ARRIVE_FROM_DOCK_BAY 3 220 221 // defines for departure locations. These defines should match their counterparts in the departure location 222 // array 223 #define MAX_DEPARTURE_NAMES 2 224 #define DEPART_AT_LOCATION 0 225 #define DEPART_AT_DOCK_BAY 1 226 227 #define MAX_GOAL_TYPE_NAMES 3 228 229 // alternate ship type names 230 #define MAX_ALT_TYPE_NAMES 100 231 extern char Mission_alt_types[MAX_ALT_TYPE_NAMES][NAME_LENGTH]; 232 extern int Mission_alt_type_count; 233 234 // callsign 235 #define MAX_CALLSIGNS 100 236 extern char Mission_callsigns[MAX_CALLSIGNS][NAME_LENGTH]; 237 extern int Mission_callsign_count; 238 239 // path restrictions 240 #define MAX_PATH_RESTRICTIONS 10 241 typedef struct path_restriction_t { 242 int num_paths; 243 int cached_mask; 244 char path_names[MAX_SHIP_BAY_PATHS][MAX_NAME_LEN]; 245 } path_restriction_t; 246 247 extern const char *Ship_class_names[MAX_SHIP_CLASSES]; 248 extern const char *Ai_behavior_names[MAX_AI_BEHAVIORS]; 249 extern char *Formation_names[MAX_FORMATION_NAMES]; 250 extern const char *Status_desc_names[MAX_STATUS_NAMES]; 251 extern const char *Status_type_names[MAX_STATUS_NAMES]; 252 extern const char *Status_target_names[MAX_STATUS_NAMES]; 253 extern const char *Arrival_location_names[MAX_ARRIVAL_NAMES]; 254 extern const char *Departure_location_names[MAX_DEPARTURE_NAMES]; 255 extern const char *Goal_type_names[MAX_GOAL_TYPE_NAMES]; 256 257 extern const char *Reinforcement_type_names[]; 258 extern char *Object_flags[]; 259 extern flag_def_list_new<Mission::Parse_Object_Flags> Parse_object_flags[]; 260 extern const size_t num_parse_object_flags; 261 extern const char *Icon_names[]; 262 extern const char *Mission_event_log_flags[]; 263 264 extern int Num_mission_event_flags; 265 extern flag_def_list Mission_event_flags[]; 266 267 extern char *Cargo_names[MAX_CARGO]; 268 extern char Cargo_names_buf[MAX_CARGO][NAME_LENGTH]; 269 270 extern char Mission_parse_storm_name[NAME_LENGTH]; 271 272 extern int Num_iff; 273 extern int Num_ai_behaviors; 274 extern int Num_ai_classes; 275 extern int Num_cargo; 276 extern int Num_status_names; 277 extern int Num_arrival_names; 278 extern int Num_formation_names; 279 extern int Num_goal_type_names; 280 extern int Num_reinforcement_type_names; 281 extern int Player_starts; 282 extern fix Entry_delay_time; 283 extern int Loading_screen_bm_index; 284 285 extern int Num_unknown_ship_classes; 286 extern int Num_unknown_weapon_classes; 287 extern int Num_unknown_loadout_classes; 288 289 extern ushort Current_file_checksum; 290 extern int Current_file_length; 291 292 #define SUBSYS_STATUS_NO_CHANGE -999 293 294 // Squadron Default Name 295 #define NO_SQUAD "<none>" 296 297 typedef struct subsys_status { 298 char name[NAME_LENGTH]; 299 float percent; // percent damaged 300 int primary_banks[MAX_SHIP_PRIMARY_BANKS]; 301 int primary_ammo[MAX_SHIP_PRIMARY_BANKS]; 302 int secondary_banks[MAX_SHIP_SECONDARY_BANKS]; 303 int secondary_ammo[MAX_SHIP_SECONDARY_BANKS]; 304 int ai_class; 305 int subsys_cargo_name; 306 } subsys_status; 307 308 typedef struct texture_replace { 309 char ship_name[NAME_LENGTH]; 310 char old_texture[MAX_FILENAME_LEN]; 311 char new_texture[MAX_FILENAME_LEN]; 312 int new_texture_id; 313 bool from_table; 314 } texture_replace; 315 316 extern SCP_vector<texture_replace> Fred_texture_replacements; 317 318 typedef struct alt_class { 319 int ship_class; 320 int variable_index; // if set allows the class to be set by a variable 321 bool default_to_this_class; 322 }alt_class; 323 324 #define MAX_OBJECT_STATUS 10 325 326 // a parse object 327 // information from a $OBJECT: definition is read into this struct to 328 // be copied into the real object, ship, etc. structs 329 class p_object 330 { 331 public: 332 char name[NAME_LENGTH]; 333 SCP_string display_name; 334 p_object *next, *prev; 335 336 vec3d pos; 337 matrix orient; 338 int ship_class; 339 int team; 340 int loadout_team; // original team, should never be changed after being set!! 341 int behavior; // ai_class; 342 int ai_goals; // sexp of lists of goals that this ship should try and do 343 char cargo1; 344 SCP_string team_color_setting; 345 346 int status_count; 347 int status_type[MAX_OBJECT_STATUS]; 348 int status[MAX_OBJECT_STATUS]; 349 int target[MAX_OBJECT_STATUS]; 350 351 int subsys_index; // index into subsys_status array 352 int subsys_count; // number of elements used in subsys_status array 353 int initial_velocity; 354 int initial_hull; 355 int initial_shields; 356 357 int arrival_location; 358 int arrival_distance; // used when arrival location is near or in front of some ship 359 int arrival_anchor; // ship used for anchoring an arrival point 360 int arrival_path_mask; // Goober5000 361 int arrival_cue; // Index in Sexp_nodes of this sexp. 362 int arrival_delay; 363 364 int departure_location; 365 int departure_anchor; 366 int departure_path_mask; // Goober5000 367 int departure_cue; // Index in Sexp_nodes of this sexp. 368 int departure_delay; 369 370 int warpin_params_index; 371 int warpout_params_index; 372 373 char misc[NAME_LENGTH]; 374 375 int wingnum; // set to -1 if not in a wing -- Wing array index otherwise 376 int pos_in_wing; // Goober5000 - needed for FRED with the new way things work 377 378 flagset<Mission::Parse_Object_Flags> flags; // mission savable flags 379 int escort_priority; // priority in escort list 380 int ai_class; 381 int hotkey; // hotkey number (between 0 and 9) -1 means no hotkey 382 int score; 383 float assist_score_pct; // percentage of the score which players who gain an assist will get when this ship is killed 384 int orders_accepted; // which orders this ship will accept from the player 385 p_dock_instance *dock_list; // Goober5000 - parse objects this parse object is docked to 386 object *created_object; // Goober5000 387 int group; // group object is within or -1 if none. 388 int persona_index; 389 int kamikaze_damage; // base damage for a kamikaze attack 390 391 bool use_special_explosion; // new special explosion/hitpoints system 392 int special_exp_damage; 393 int special_exp_blast; 394 int special_exp_inner; 395 int special_exp_outer; 396 bool use_shockwave; 397 int special_exp_shockwave_speed; 398 int special_exp_deathroll_time; 399 400 int special_hitpoints; 401 int special_shield; 402 403 ushort net_signature; // network signature this object can have 404 int destroy_before_mission_time; 405 406 char wing_status_wing_index; // wing index (0-4) in wingman status gauge 407 char wing_status_wing_pos; // wing position (0-5) in wingman status gauge 408 409 uint respawn_count; // number of respawns for this object. Applies only to player wing ships in multiplayer 410 int respawn_priority; // priority this ship has for controlling respawn points 411 412 int alt_type_index; // optional alt type index 413 int callsign_index; // optional callsign index 414 415 float ship_max_hull_strength; // Needed to deal with special hitpoints 416 float ship_max_shield_strength; 417 418 float max_shield_recharge; 419 420 // Goober5000 421 SCP_vector<texture_replace> replacement_textures; 422 423 SCP_vector<alt_class> alt_classes; 424 425 int alt_iff_color[MAX_IFFS][MAX_IFFS]; 426 427 p_object(); 428 ~p_object(); 429 430 const char* get_display_name(); 431 bool has_display_name(); 432 }; 433 434 // Goober5000 - this is now dynamic 435 extern SCP_vector<p_object> Parse_objects; 436 #define POBJ_INDEX(pobjp) (int)(pobjp - &Parse_objects[0]) // yes, this arithmetic is valid :D 437 438 extern p_object Support_ship_pobj, *Arriving_support_ship; 439 extern p_object Ship_arrival_list; 440 441 typedef struct { 442 // ships 443 int default_ship; // default ship type for player start point (recommended choice) 444 int num_ship_choices; // number of ship choices inside ship_list 445 int loadout_total; // Total number of ships available of all classes 446 int ship_list[MAX_SHIP_CLASSES]; 447 char ship_list_variables[MAX_SHIP_CLASSES][TOKEN_LENGTH]; 448 int ship_count[MAX_SHIP_CLASSES]; 449 char ship_count_variables[MAX_SHIP_CLASSES][TOKEN_LENGTH]; 450 451 // weapons 452 int num_weapon_choices; 453 int weaponry_pool[MAX_WEAPON_TYPES]; 454 int weaponry_count[MAX_WEAPON_TYPES]; 455 char weaponry_pool_variable[MAX_WEAPON_TYPES][TOKEN_LENGTH]; 456 char weaponry_amount_variable[MAX_WEAPON_TYPES][TOKEN_LENGTH]; 457 bool weapon_required[MAX_WEAPON_TYPES]; 458 } team_data; 459 460 #define MAX_P_WINGS 16 461 #define MAX_SHIP_LIST 16 462 463 extern team_data Team_data[MAX_TVT_TEAMS]; 464 extern subsys_status *Subsys_status; 465 extern int Subsys_index; 466 467 extern vec3d Parse_viewer_pos; 468 extern matrix Parse_viewer_orient; 469 470 extern int Mission_arrival_timestamp; 471 extern int Mission_departure_timestamp; 472 extern fix Mission_end_time; 473 474 extern char Parse_names[MAX_SHIPS + MAX_WINGS][NAME_LENGTH]; 475 extern int Num_parse_names; 476 extern int Num_teams; 477 478 extern char Player_start_shipname[NAME_LENGTH]; 479 extern int Player_start_shipnum; 480 extern p_object *Player_start_pobject; 481 482 extern int Mission_palette; // index of palette file to use for mission 483 extern int Nebula_index; // index into Nebula_filenames[] of nebula to use in mission. 484 extern const char *Nebula_filenames[NUM_NEBULAS]; 485 extern const char *Nebula_colors[NUM_NEBULA_COLORS]; 486 extern p_object *Arriving_support_ship; 487 488 extern char Neb2_texture_name[MAX_FILENAME_LEN]; 489 490 491 bool parse_main(const char *mission_name, int flags = 0); 492 p_object *mission_parse_get_arrival_ship(ushort net_signature); 493 p_object *mission_parse_get_arrival_ship(const char *name); 494 bool mission_check_ship_yet_to_arrive(const char *name); 495 p_object *mission_parse_get_parse_object(ushort net_signature); 496 p_object *mission_parse_get_parse_object(const char *name); 497 int parse_create_object(p_object *objp); 498 void resolve_parse_flags(object *objp, flagset<Mission::Parse_Object_Flags> &parse_flags); 499 500 void mission_parse_close(); 501 502 // used in squadmate messaging stuff to create wings from reinforcements. 503 int parse_wing_create_ships(wing *wingp, int num_to_create, int force = 0, int specific_instance = -1 ); 504 505 // function for getting basic mission data without loading whole mission 506 int mission_parse_is_multi(const char *filename, char *mission_name ); 507 int mission_parse_get_multi_mission_info(const char *filename); 508 509 // called externally from multiplayer code 510 int mission_do_departure(object *objp, bool goal_is_to_warp = false); 511 512 // called externally from freespace.cpp 513 void mission_parse_fixup_players(void); 514 515 // get a index to a perminently kept around name of a ship or wing 516 int get_parse_name_index(const char *name); 517 518 // called from freespace game level loop 519 void mission_parse_eval_stuff(); 520 521 // code to bring in a repair ship. 522 void mission_bring_in_support_ship( object *requester_objp ); 523 int mission_is_support_ship_arriving( void ); 524 void mission_add_to_arriving_support( object *requester_objp ); 525 int mission_is_repair_scheduled( object *objp ); 526 int mission_remove_scheduled_repair( object *objp ); 527 void mission_parse_support_arrived( int objnum ); 528 529 // alternate name stuff 530 int mission_parse_lookup_alt(const char *name); 531 const char *mission_parse_lookup_alt_index(int index); 532 int mission_parse_add_alt(const char *name); 533 void mission_parse_remove_alt(const char *name); 534 void mission_parse_reset_alt(); 535 void mission_process_alt_types(); 536 537 // callsign stuff 538 int mission_parse_lookup_callsign(const char *name); 539 const char *mission_parse_lookup_callsign_index(int index); 540 int mission_parse_add_callsign(const char *name); 541 void mission_parse_remove_callsign(const char *name); 542 void mission_parse_reset_callsign(); 543 544 // is training mission 545 int is_training_mission(); 546 547 // code to save/restore mission parse stuff 548 int get_mission_info(const char *filename, mission *missionp = NULL, bool basic = true); 549 550 // Goober5000 551 void parse_dock_one_docked_object(p_object *pobjp, p_object *parent_pobjp); 552 553 // Goober5000 554 extern int Knossos_warp_ani_used; 555 556 // Karajorma 557 void swap_parse_object(p_object *p_obj, int ship_class); 558 void clear_texture_replacements(); 559 560 // Goober5000 561 subsys_status *parse_get_subsys_status(p_object *pobjp, const char *subsys_name); 562 563 564 #endif 565 566