Skip to content

Commit dfc716d

Browse files
authored
Merge pull request #5501 from naomimyselfandi/zero-out-persona-bitfields
Explicitly zero out persona bitfields
2 parents 8dd6a27 + fc6a140 commit dfc716d

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

code/mission/missionmessage.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const char *Persona_type_names[MAX_PERSONA_TYPES] =
141141
//XSTR:ON
142142
};
143143

144-
int Default_command_persona;
144+
int Default_command_persona, Default_support_persona;
145145

146146
// Goober5000
147147
// NOTE - these are truncated filenames, i.e. without extensions
@@ -202,6 +202,8 @@ int comm_between_player_and_ship(int other_shipnum, bool for_death_scream);
202202
void persona_parse()
203203
{
204204
Persona this_persona;
205+
this_persona.flags = 0;
206+
this_persona.species_bitfield = 0;
205207

206208
required_string("$Persona:");
207209
stuff_string(this_persona.name, F_NAME, NAME_LENGTH);
@@ -273,13 +275,16 @@ void persona_parse()
273275
}
274276

275277
if (!dup) {
278+
int persona_index = (int) Personas.size();
276279
Personas.push_back(this_persona);
277280

278-
// save the Command persona in a global
281+
// Save some important personae for later
279282
if (this_persona.flags & PERSONA_FLAG_COMMAND) {
280-
// always use the most recent Command persona
281-
// found, since that's how retail does it
282-
Default_command_persona = ((int)Personas.size() - 1);
283+
// Always use the most recent Command persona found, since that's how retail does it
284+
Default_command_persona = persona_index;
285+
}
286+
if ((this_persona.flags & PERSONA_FLAG_SUPPORT) && (Default_support_persona == -1)) {
287+
Default_support_persona = persona_index;
283288
}
284289
}
285290
}
@@ -735,6 +740,7 @@ void messages_init()
735740

736741
if ( !table_read ) {
737742
Default_command_persona = -1;
743+
Default_support_persona = -1;
738744

739745
// speed things up a little by setting the capacities for the message vectors to roughly the FS2 amounts
740746
Messages.reserve(500);
@@ -1969,14 +1975,18 @@ int pick_persona(ship* shipp) {
19691975
return i;
19701976
}
19711977
}
1972-
int count = (int)candidates.size();
1973-
if (count == 0) {
1974-
return -1;
1975-
} else if (count == 1) {
1978+
int count = (int) candidates.size();
1979+
if (count == 1) {
19761980
return candidates[0];
1977-
} else {
1981+
} else if (count > 1) {
19781982
return candidates[Random::next(0, count)];
1979-
}
1983+
} else if (persona_type & PERSONA_FLAG_SUPPORT) {
1984+
// Species without a support persona (e.g. the UEF) historically used the
1985+
// first support persona; retain that behavior
1986+
return Default_support_persona;
1987+
} else {
1988+
return -1;
1989+
}
19801990
}
19811991

19821992
bool can_auto_assign_persona(ship* shipp) {

0 commit comments

Comments
 (0)