Skip to content

Commit cfc1088

Browse files
authored
Merge pull request #7056 from Goober5000/docked_wing_fixes
for docked wings, initialize some data before the wing is created
2 parents 0d4c222 + e3ff08e commit cfc1088

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

code/mission/missionparse.cpp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,7 @@ int parse_create_object(p_object *pobjp, bool standalone_ship)
21672167
}
21682168

21692169
void parse_bring_in_docked_wing(p_object *p_objp, int wingnum, int shipnum);
2170+
void parse_copy_wing_ai_to_ship(wing *wingp, ai_info *aip);
21702171

21712172
/**
21722173
* Given a stuffed p_object struct, create an object and fill in the necessary fields.
@@ -2200,6 +2201,20 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship)
22002201
// Goober5000 - set the collision group if one was provided
22012202
Objects[objnum].collision_group_id = p_objp->collision_group_id;
22022203

2204+
// Goober5000 - set some fields that the mission log might need (if logged via parse_bring_in_docked_wing just below)
2205+
shipp->display_name = p_objp->display_name;
2206+
shipp->alt_type_index = p_objp->alt_type_index;
2207+
shipp->callsign_index = p_objp->callsign_index;
2208+
shipp->team = p_objp->team;
2209+
shipp->ship_iff_color = p_objp->alt_iff_color;
2210+
2211+
// if this is a multiplayer dogfight game, and its from a player wing, make it team traitor
2212+
if (MULTI_DOGFIGHT && (p_objp->wingnum >= 0) && p_objp->flags[Mission::Parse_Object_Flags::SF_From_player_wing])
2213+
shipp->team = Iff_traitor;
2214+
2215+
if (Ship_info[shipp->ship_info_index].uses_team_colors && !p_objp->team_color_setting.empty())
2216+
shipp->team_name = p_objp->team_color_setting;
2217+
22032218
// Goober5000 - if this object is being created because he's docked to something,
22042219
// and he's in a wing, then mark the wing as having arrived
22052220
if (object_is_docked(p_objp) && !(p_objp->flags[Mission::Parse_Object_Flags::SF_Dock_leader]) && (p_objp->wingnum >= 0))
@@ -2212,8 +2227,6 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship)
22122227
}
22132228

22142229
shipp->group = p_objp->group;
2215-
shipp->team = p_objp->team;
2216-
shipp->display_name = p_objp->display_name;
22172230
shipp->escort_priority = p_objp->escort_priority;
22182231
shipp->ship_guardian_threshold = p_objp->ship_guardian_threshold;
22192232
shipp->use_special_explosion = p_objp->use_special_explosion;
@@ -2228,8 +2241,6 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship)
22282241
shipp->special_hitpoints = p_objp->special_hitpoints;
22292242
shipp->special_shield = p_objp->special_shield;
22302243

2231-
shipp->ship_iff_color = p_objp->alt_iff_color;
2232-
22332244
shipp->ship_max_shield_strength = p_objp->ship_max_shield_strength;
22342245
shipp->ship_max_hull_strength = p_objp->ship_max_hull_strength;
22352246
shipp->max_shield_recharge = p_objp->max_shield_recharge;
@@ -2259,14 +2270,6 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship)
22592270

22602271
shipp->respawn_priority = p_objp->respawn_priority;
22612272

2262-
// if this is a multiplayer dogfight game, and its from a player wing, make it team traitor
2263-
if (MULTI_DOGFIGHT && (p_objp->wingnum >= 0) && p_objp->flags[Mission::Parse_Object_Flags::SF_From_player_wing])
2264-
shipp->team = Iff_traitor;
2265-
2266-
// alternate stuff
2267-
shipp->alt_type_index = p_objp->alt_type_index;
2268-
shipp->callsign_index = p_objp->callsign_index;
2269-
22702273
// AI stuff. Note a lot of the AI was already initialized in ship_create.
22712274
aip = &(Ai_info[shipp->ai_index]);
22722275

@@ -2302,8 +2305,6 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship)
23022305
shipp->score = p_objp->score;
23032306
shipp->assist_score_pct = p_objp->assist_score_pct;
23042307
shipp->persona_index = p_objp->persona_index;
2305-
if (Ship_info[shipp->ship_info_index].uses_team_colors && !p_objp->team_color_setting.empty())
2306-
shipp->team_name = p_objp->team_color_setting;
23072308

23082309
if (p_objp->warpin_params_index >= 0)
23092310
shipp->warpin_params_index = p_objp->warpin_params_index;
@@ -2454,6 +2455,9 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship)
24542455
}
24552456
}
24562457

2458+
if (brought_in_docked_wing)
2459+
parse_copy_wing_ai_to_ship(&Wings[p_objp->wingnum], aip);
2460+
24572461
Assert(sip->model_num != -1);
24582462

24592463
// initialize subsystem statii here. The subsystems are given a percentage damaged. So a percent value
@@ -2835,6 +2839,8 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship)
28352839
* then it will create its component ships. If a wing arrives because all its ships were docked
28362840
* to something else, these assumptions are turned inside out. So we have to sort of bootstrap
28372841
* the creation of the wing by running a subset of the code from parse_wing_create_ships().
2842+
*
2843+
* Note that parse_copy_wing_ai_to_ship() needs to be done too but will be called in a different spot.
28382844
*/
28392845
void parse_bring_in_docked_wing(p_object *p_objp, int wingnum, int shipnum)
28402846
{
@@ -2874,19 +2880,19 @@ void parse_bring_in_docked_wing(p_object *p_objp, int wingnum, int shipnum)
28742880
// copy to parse object
28752881
p_objp->wing_status_wing_index = Ships[shipnum].wing_status_wing_index;
28762882
p_objp->wing_status_wing_pos = Ships[shipnum].wing_status_wing_pos;
2883+
}
28772884

2878-
// handle AI
2879-
ai_info *aip = &Ai_info[Ships[shipnum].ai_index];
2880-
2881-
if (wingp->flags[Ship::Wing_Flags::No_dynamic])
2882-
aip->ai_flags.set(AI::AI_Flags::No_dynamic);
2883-
2885+
void parse_copy_wing_ai_to_ship(wing *wingp, ai_info *aip)
2886+
{
28842887
// copy any goals from the wing to the newly created ship
28852888
for (int index = 0; index < MAX_AI_GOALS; index++)
28862889
{
28872890
if (wingp->ai_goals[index].ai_mode != AI_GOAL_NONE)
28882891
ai_copy_mission_wing_goal(&wingp->ai_goals[index], aip);
28892892
}
2893+
2894+
if (wingp->flags[Ship::Wing_Flags::No_dynamic])
2895+
aip->ai_flags.set(AI::AI_Flags::No_dynamic);
28902896
}
28912897

28922898
// Goober5000
@@ -4504,7 +4510,6 @@ int parse_wing_create_ships( wing *wingp, int num_to_create, bool force_create,
45044510
// (since created objects plus anything they're docked to will be removed from it)
45054511
for (SCP_vector<p_object>::iterator ii = Parse_objects.begin(); ii != Parse_objects.end(); ++ii)
45064512
{
4507-
int index;
45084513
ai_info *aip;
45094514
p_object *p_objp = &(*ii);
45104515

@@ -4617,15 +4622,7 @@ int parse_wing_create_ships( wing *wingp, int num_to_create, bool force_create,
46174622
objnum = parse_create_object(p_objp);
46184623
aip = &Ai_info[Ships[Objects[objnum].instance].ai_index];
46194624

4620-
// copy any goals from the wing to the newly created ship
4621-
for (index = 0; index < MAX_AI_GOALS; index++)
4622-
{
4623-
if (wingp->ai_goals[index].ai_mode != AI_GOAL_NONE)
4624-
ai_copy_mission_wing_goal(&wingp->ai_goals[index], aip);
4625-
}
4626-
4627-
if (wingp->flags[Ship::Wing_Flags::No_dynamic])
4628-
aip->ai_flags.set(AI::AI_Flags::No_dynamic);
4625+
parse_copy_wing_ai_to_ship(wingp, aip);
46294626

46304627
// update housekeeping variables
46314628
// NOTE: for the initial wing setup we use actual position to get around

0 commit comments

Comments
 (0)