Skip to content

Commit 88b87b8

Browse files
authored
Merge pull request #1378 from asarium/fix/fredHasShields
Fix inverted "Has shields" flag in initial status dialog
2 parents a3ab30c + b34ca3c commit 88b87b8

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

fred2/initialstatus.cpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ void initial_status_mark_dock_leader_helper(object *objp, dock_function_info *in
3030
void initial_status_unmark_dock_handled_flag(object *objp, dock_function_info *infop);
3131
void reset_arrival_to_false(int shipnum, bool reset_wing);
3232

33+
/**
34+
* @brief Handles setting a flag on a flagset when the value is inconsistent
35+
*
36+
* This is necessary in case multiple ships with inconsistent object flags have been selected in which case
37+
* that flag may not be edited since it would corrupt the value of that flag. This function simplifies handling
38+
* that case.
39+
*/
40+
template<typename T>
41+
static void handle_inconsistent_flag(flagset<T>& flags, T flag, int value) {
42+
if (value == 1) {
43+
flags.set(flag);
44+
} else if (value == 0) {
45+
flags.remove(flag);
46+
}
47+
}
3348

3449
/////////////////////////////////////////////////////////////////////////////
3550
// initial_status dialog
@@ -438,17 +453,21 @@ void initial_status::OnOK()
438453
if (hflag)
439454
MODIFY(objp->hull_strength, (float) m_hull);
440455

441-
objp->flags.set(Object::Object_Flags::No_shields, m_has_shields == 0);
456+
if (m_has_shields == 1)
457+
objp->flags.remove(Object::Object_Flags::No_shields);
458+
else if (m_has_shields == 0)
459+
objp->flags.set(Object::Object_Flags::No_shields);
442460

443461
auto shipp = &Ships[get_ship_from_obj(objp)];
444462

445-
shipp->flags.set(Ship::Ship_Flags::Force_shields_on, m_force_shields == 1);
446-
shipp->flags.set(Ship::Ship_Flags::Ship_locked, m_ship_locked == 1);
447-
shipp->flags.set(Ship::Ship_Flags::Weapons_locked, m_weapons_locked == 1);
448-
shipp->flags.set(Ship::Ship_Flags::Primaries_locked, m_primaries_locked == 1);
449-
shipp->flags.set(Ship::Ship_Flags::Secondaries_locked, m_secondaries_locked == 1);
450-
shipp->flags.set(Ship::Ship_Flags::Lock_all_turrets_initially, m_turrets_locked == 1);
451-
shipp->flags.set(Ship::Ship_Flags::Afterburner_locked, m_afterburner_locked == 1);
463+
// We need to ensure that we handle the inconsistent "boolean" value correctly
464+
handle_inconsistent_flag(shipp->flags, Ship::Ship_Flags::Force_shields_on, m_force_shields);
465+
handle_inconsistent_flag(shipp->flags, Ship::Ship_Flags::Ship_locked, m_ship_locked);
466+
handle_inconsistent_flag(shipp->flags, Ship::Ship_Flags::Weapons_locked, m_weapons_locked);
467+
handle_inconsistent_flag(shipp->flags, Ship::Ship_Flags::Primaries_locked, m_primaries_locked);
468+
handle_inconsistent_flag(shipp->flags, Ship::Ship_Flags::Secondaries_locked, m_secondaries_locked);
469+
handle_inconsistent_flag(shipp->flags, Ship::Ship_Flags::Lock_all_turrets_initially, m_turrets_locked);
470+
handle_inconsistent_flag(shipp->flags, Ship::Ship_Flags::Afterburner_locked, m_afterburner_locked);
452471
}
453472

454473
objp = GET_NEXT(objp);
@@ -459,15 +478,16 @@ void initial_status::OnOK()
459478
MODIFY(Objects[cur_object_index].shield_quadrant[0], (float) m_shields);
460479
MODIFY(Objects[cur_object_index].hull_strength, (float) m_hull);
461480

462-
Objects[cur_object_index].flags.set(Object::Object_Flags::No_shields, m_has_shields != 0);
481+
Objects[cur_object_index].flags.set(Object::Object_Flags::No_shields, m_has_shields == 0);
463482

464-
Ships[m_ship].flags.set(Ship::Ship_Flags::Force_shields_on, m_force_shields == 1);
465-
Ships[m_ship].flags.set(Ship::Ship_Flags::Ship_locked, m_ship_locked == 1);
466-
Ships[m_ship].flags.set(Ship::Ship_Flags::Weapons_locked, m_weapons_locked == 1);
467-
Ships[m_ship].flags.set(Ship::Ship_Flags::Primaries_locked, m_primaries_locked == 1);
468-
Ships[m_ship].flags.set(Ship::Ship_Flags::Secondaries_locked, m_secondaries_locked == 1);
469-
Ships[m_ship].flags.set(Ship::Ship_Flags::Lock_all_turrets_initially, m_turrets_locked == 1);
470-
Ships[m_ship].flags.set(Ship::Ship_Flags::Afterburner_locked, m_afterburner_locked == 1);
483+
// We need to ensure that we handle the inconsistent "boolean" value correctly. Not strictly needed here but just to be safe...
484+
handle_inconsistent_flag(Ships[m_ship].flags, Ship::Ship_Flags::Force_shields_on, m_force_shields);
485+
handle_inconsistent_flag(Ships[m_ship].flags, Ship::Ship_Flags::Ship_locked, m_ship_locked);
486+
handle_inconsistent_flag(Ships[m_ship].flags, Ship::Ship_Flags::Weapons_locked, m_weapons_locked);
487+
handle_inconsistent_flag(Ships[m_ship].flags, Ship::Ship_Flags::Primaries_locked, m_primaries_locked);
488+
handle_inconsistent_flag(Ships[m_ship].flags, Ship::Ship_Flags::Secondaries_locked, m_secondaries_locked);
489+
handle_inconsistent_flag(Ships[m_ship].flags, Ship::Ship_Flags::Lock_all_turrets_initially, m_turrets_locked);
490+
handle_inconsistent_flag(Ships[m_ship].flags, Ship::Ship_Flags::Afterburner_locked, m_afterburner_locked);
471491
}
472492

473493
if (m_team_color_setting.IsWindowEnabled() && m_team_color_setting.GetCurSel() > 0)

0 commit comments

Comments
 (0)