-
Notifications
You must be signed in to change notification settings - Fork 180
make the reinforcements collection dynamic #7449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Goober5000
wants to merge
2
commits into
scp-fs2open:master
Choose a base branch
from
Goober5000:feature/dynamic_reinforcements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5995,60 +5995,58 @@ void parse_messages(mission *pm, int flags) | |
|
|
||
| void parse_reinforcement(mission *pm) | ||
| { | ||
| reinforcements *ptr; | ||
| reinforcements reinforcement; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this new vector format, should we add default member initializers to ensure when the optional sections are absent, these are left with indeterminate values:? |
||
| p_object *rforce_obj = NULL; | ||
| int instance = -1; | ||
|
|
||
| Assert(Num_reinforcements < MAX_REINFORCEMENTS); | ||
| Assert(pm != NULL); | ||
| ptr = &Reinforcements[Num_reinforcements]; | ||
|
|
||
| required_string("$Name:"); | ||
| stuff_string(ptr->name, F_NAME, NAME_LENGTH); | ||
| stuff_string(reinforcement.name, F_NAME, NAME_LENGTH); | ||
|
|
||
| find_and_stuff("$Type:", &ptr->type, F_NAME, Reinforcement_type_names, Num_reinforcement_type_names, "reinforcement type"); | ||
| find_and_stuff("$Type:", &reinforcement.type, F_NAME, Reinforcement_type_names, Num_reinforcement_type_names, "reinforcement type"); | ||
|
|
||
| required_string("$Num times:"); | ||
| stuff_int(&ptr->uses); | ||
| ptr->num_uses = 0; | ||
| stuff_int(&reinforcement.uses); | ||
| reinforcement.num_uses = 0; | ||
|
|
||
| // reset the flags to 0 | ||
| ptr->flags = 0; | ||
| reinforcement.flags = 0; | ||
|
|
||
| if ( optional_string("+Arrival delay:") ) | ||
| { | ||
| int delay; | ||
| stuff_int(&delay); | ||
| if (delay < 0) | ||
| { | ||
| Warning(LOCATION, "Cannot have arrival delay < 0 on reinforcement %s", ptr->name); | ||
| Warning(LOCATION, "Cannot have arrival delay < 0 on reinforcement %s", reinforcement.name); | ||
| delay = 0; | ||
| } | ||
|
|
||
| ptr->arrival_delay = delay; | ||
| reinforcement.arrival_delay = delay; | ||
| } | ||
|
|
||
| if ( optional_string("+No Messages:") ){ | ||
| stuff_string_list( ptr->no_messages, MAX_REINFORCEMENT_MESSAGES ); | ||
| stuff_string_list( reinforcement.no_messages, MAX_REINFORCEMENT_MESSAGES ); | ||
| } | ||
|
|
||
| if ( optional_string("+Yes Messages:") ){ | ||
| stuff_string_list( ptr->yes_messages, MAX_REINFORCEMENT_MESSAGES ); | ||
| stuff_string_list( reinforcement.yes_messages, MAX_REINFORCEMENT_MESSAGES ); | ||
| } | ||
|
|
||
| // sanity check on the names of reinforcements | ||
| rforce_obj = mission_parse_find_parse_object(ptr->name); | ||
| rforce_obj = mission_parse_find_parse_object(reinforcement.name); | ||
|
|
||
| if (rforce_obj == NULL) { | ||
| if ((instance = wing_name_lookup(ptr->name, 1)) == -1) { | ||
| Warning(LOCATION, "Reinforcement %s not found as ship or wing", ptr->name); | ||
| if ((instance = wing_name_lookup(reinforcement.name, 1)) == -1) { | ||
| Warning(LOCATION, "Reinforcement %s not found as ship or wing", reinforcement.name); | ||
| return; | ||
| } | ||
| } else { | ||
| // Individual ships in wings can't be reinforcements - FUBAR | ||
| if (rforce_obj->wingnum >= 0) | ||
| { | ||
| Warning(LOCATION, "Reinforcement %s is part of a wing - Ignoring reinforcement declaration", ptr->name); | ||
| Warning(LOCATION, "Reinforcement %s is part of a wing - Ignoring reinforcement declaration", reinforcement.name); | ||
| return; | ||
| } | ||
| else | ||
|
|
@@ -6060,10 +6058,10 @@ void parse_reinforcement(mission *pm) | |
| // now, if the reinforcement is a wing, then set the number of waves of the wing == number of | ||
| // uses of the reinforcement | ||
| if (instance >= 0) { | ||
| Wings[instance].num_waves = ptr->uses; | ||
| Wings[instance].num_waves = reinforcement.uses; | ||
| } | ||
|
|
||
| Num_reinforcements++; | ||
| Reinforcements.push_back(std::move(reinforcement)); | ||
| } | ||
|
|
||
| void parse_reinforcements(mission *pm) | ||
|
|
@@ -7305,7 +7303,7 @@ void mission_init(mission *pm, bool quick_init) | |
| for (int i = 0; i < MAX_WINGS; i++) | ||
| Wings[i].clear(); | ||
|
|
||
| Num_reinforcements = 0; | ||
| Reinforcements.clear(); | ||
|
|
||
| Parse_props.clear(); | ||
|
|
||
|
|
@@ -8055,27 +8053,24 @@ int mission_set_arrival_location(anchor_t anchor, ArrivalLocation location, int | |
| /** | ||
| * Mark a reinforcement as available | ||
| */ | ||
| void mission_parse_mark_reinforcement_available(char *name) | ||
| void mission_parse_mark_reinforcement_available(const char *name) | ||
| { | ||
| int i; | ||
| reinforcements *rp; | ||
|
|
||
| for (i = 0; i < Num_reinforcements; i++) { | ||
| rp = &Reinforcements[i]; | ||
| if ( !stricmp(rp->name, name) ) { | ||
| if ( !(rp->flags & RF_IS_AVAILABLE) ) { | ||
| rp->flags |= RF_IS_AVAILABLE; | ||
| int i = find_item_with_string(Reinforcements, &reinforcements::name, name); | ||
| if (i >= 0) | ||
| { | ||
| auto &r = Reinforcements[i]; | ||
| if (!(r.flags & RF_IS_AVAILABLE)) | ||
| { | ||
| r.flags |= RF_IS_AVAILABLE; | ||
|
|
||
| // tell all of the clients. | ||
| if ( MULTIPLAYER_MASTER ) { | ||
| send_reinforcement_avail( i ); | ||
| } | ||
| } | ||
| return; | ||
| // tell all of the clients. | ||
| if (MULTIPLAYER_MASTER) | ||
| send_reinforcement_avail(i); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| Assert ( i < Num_reinforcements ); | ||
| Assertion(false, "Reinforcement '%s' not found!", name); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -8101,12 +8096,9 @@ int mission_did_ship_arrive(p_object *objp, bool force_arrival) | |
|
|
||
| // if we're forcing the arrival, then "use" the reinforcement; otherwise don't process anything else | ||
| if (force_arrival) { | ||
| for (int i = 0; i < Num_reinforcements; i++) { | ||
| auto rp = &Reinforcements[i]; | ||
| if (!stricmp(rp->name, objp->name)) { | ||
| rp->num_uses++; | ||
| break; | ||
| } | ||
| int i = find_item_with_string(Reinforcements, &reinforcements::name, objp->name); | ||
| if (i >= 0) { | ||
| Reinforcements[i].num_uses++; | ||
| } | ||
| } else { | ||
| return -1; | ||
|
|
@@ -8358,12 +8350,9 @@ bool mission_maybe_make_wing_arrive(int wingnum, bool force_arrival) | |
|
|
||
| // if we're forcing the arrival, then "use" the reinforcement; otherwise don't process anything else | ||
| if (force_arrival && wingp->current_count == 0) { | ||
| for (int i = 0; i < Num_reinforcements; i++) { | ||
| auto rp = &Reinforcements[i]; | ||
| if (!stricmp(rp->name, wingp->name)) { | ||
| rp->num_uses++; | ||
| break; | ||
| } | ||
| int i = find_item_with_string(Reinforcements, &reinforcements::name, wingp->name); | ||
| if (i >= 0) { | ||
| Reinforcements[i].num_uses++; | ||
| } | ||
| } else { | ||
| // reinforcement wings skip the rest of the function | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be a bit more robust or safer for any future changes if we used something like
for (size_t i = 0; i < Reinforcements.size(); ++i)here instead ofi = -1and theni++?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so; this is a less common pattern, but it's perfectly valid, and it allows the loop to use the ranged for, just as other loops do.