Skip to content

Commit b3bafb8

Browse files
Remove Unused Code and Add Skip Validation
1 parent 9783e96 commit b3bafb8

File tree

5 files changed

+541
-722
lines changed

5 files changed

+541
-722
lines changed

qtfred/src/mission/dialogs/LoadoutEditorDialogModel.cpp

Lines changed: 12 additions & 238 deletions
Original file line numberDiff line numberDiff line change
@@ -267,97 +267,6 @@ SCP_vector<std::pair<SCP_string, bool>> LoadoutDialogModel::getWeaponEnablerVari
267267
return _weaponVarList;
268268
}
269269

270-
void LoadoutDialogModel::setShipInfo(SCP_string textIn, bool enabled, int extraAllocated, SCP_string varForCount)
271-
{
272-
bool found = false, previouslyEnabled;
273-
int index = 0;
274-
275-
for (auto& item : _teams[_currentTeam].ships) {
276-
if (textIn == Ship_info[item.infoIndex].name) {
277-
previouslyEnabled = item.enabled;
278-
item.enabled = enabled;
279-
item.extraAllocated = extraAllocated;
280-
item.varCountIndex = get_index_sexp_variable_name(varForCount);
281-
found = true;
282-
283-
// need to check if this ship will hold more than the last highest capacity
284-
if (enabled) {
285-
if (Ship_info[item.infoIndex].num_primary_banks > _teams[_currentTeam].largestPrimaryBankCount) {
286-
_teams[_currentTeam].largestPrimaryBankCount = Ship_info[item.infoIndex].num_primary_banks;
287-
}
288-
289-
int capacity = 0;
290-
291-
for (int i = 0; i < Ship_info[item.infoIndex].num_secondary_banks; i++){
292-
capacity += Ship_info[item.infoIndex].secondary_bank_ammo_capacity[i];
293-
}
294-
295-
if (capacity > _teams[_currentTeam].largestSecondaryCapacity) {
296-
_teams[_currentTeam].largestSecondaryCapacity = capacity;
297-
}
298-
299-
if (!previouslyEnabled && item.varCountIndex == -1) {
300-
item.extraAllocated = _teams[_currentTeam].startingShipCount / 2;
301-
}
302-
303-
}
304-
305-
// now that all the data is correctly set, rebuild the corresponding string.
306-
_shipList[index].first = createItemString(true, false, index);
307-
_shipList[index].second = enabled;
308-
309-
break;
310-
}
311-
index++;
312-
}
313-
314-
// rebuild the lists that the UI depends on.
315-
buildCurrentLists();
316-
Assert(found);
317-
modelChanged();
318-
}
319-
320-
void LoadoutDialogModel::setWeaponInfo(SCP_string textIn, bool enabled, int extraAllocated, SCP_string varForCount)
321-
{
322-
bool found = false, previouslyEnabled;
323-
int index = 0;
324-
325-
for (auto& item : _teams[_currentTeam].weapons) {
326-
if (textIn == Weapon_info[item.infoIndex].name) {
327-
previouslyEnabled = !item.enabled;
328-
329-
item.enabled = enabled;
330-
item.extraAllocated = extraAllocated;
331-
item.varCountIndex = get_index_sexp_variable_name(varForCount);
332-
333-
if(item.varCountIndex == -1 && !previouslyEnabled)
334-
{
335-
if (Weapon_info[item.infoIndex].subtype == WP_LASER) {
336-
item.extraAllocated = (_teams[_currentTeam].startingShipCount * _teams[_currentTeam].largestPrimaryBankCount) / 2;
337-
}
338-
else {
339-
Assert(Weapon_info[item.infoIndex].cargo_size > 0);
340-
item.extraAllocated = (_teams[_currentTeam].startingShipCount * _teams[_currentTeam].largestSecondaryCapacity) / (2 * Weapon_info[item.infoIndex].cargo_size);
341-
}
342-
343-
}
344-
345-
// now that all the data is correctly set, rebuild the corresponding string.
346-
_weaponList[index].first = createItemString(false, false, index);
347-
_weaponList[index].second = enabled;
348-
349-
found = true;
350-
break;
351-
}
352-
index++;
353-
}
354-
355-
Assert(found);
356-
buildCurrentLists();
357-
358-
modelChanged();
359-
}
360-
361270
SCP_string LoadoutDialogModel::createItemString(bool ship, bool variable, int itemIndex, const char* variableIn)
362271
{
363272
// Using a pointer here seems to lead to memory corruption, so I'll just use a temp Loadout Item
@@ -435,152 +344,6 @@ void LoadoutDialogModel::switchTeam(int teamIn)
435344
modelChanged();
436345
}
437346

438-
void LoadoutDialogModel::setShipEnablerVariables(SCP_vector<SCP_string> variablesIn, bool enabled, int extraAllocated, SCP_string varForCount)
439-
{
440-
for (auto& nameIn : variablesIn) { // FIXME, this is trash
441-
for (auto& variable : _shipVarList) {
442-
if (nameIn == variable.first) {
443-
variable.second = enabled;
444-
break;
445-
}
446-
}
447-
}
448-
449-
// if they are enabled, we need to add them to the list.
450-
if (enabled) {
451-
for (auto& nameIn : variablesIn) {
452-
bool found = false;
453-
for (auto& item : _teams[_currentTeam].varShips) {
454-
455-
// check to see if it was already added
456-
if (item.name == nameIn) {
457-
found = true;
458-
item.varCountIndex = get_index_sexp_variable_name(varForCount);
459-
if (extraAllocated == 0 && item.varCountIndex == -1) {
460-
item.extraAllocated = (int)((float)_teams[_currentTeam].startingShipCount / 2.0f);
461-
462-
// at least have 1
463-
if (item.extraAllocated < 1) {
464-
item.extraAllocated = 1;
465-
}
466-
}
467-
else {
468-
item.extraAllocated = extraAllocated;
469-
}
470-
471-
break;
472-
}
473-
}
474-
475-
if (!found) {
476-
_teams[_currentTeam].varShips.emplace_back(
477-
get_index_sexp_variable_name(nameIn),
478-
true,
479-
false, // it cannot be required because this is var enabled
480-
0, // there cannot be any because this is var enabled.
481-
ShipVarDefault, // default o f.
482-
-1, // no var for count until one can be selected.
483-
SCP_string(nameIn));
484-
}
485-
}
486-
487-
} // if they are disabled, remove them.
488-
else {
489-
for (auto& nameIn : variablesIn) {
490-
auto item = _teams[_currentTeam].varShips.begin();
491-
while (item != _teams[_currentTeam].varShips.end()) {
492-
// check to see if it was already added, and get rid of the info.
493-
if (item->name == nameIn) {
494-
item->enabled = false;
495-
item->extraAllocated = 0;
496-
item->infoIndex = -1;
497-
item->varCountIndex = get_index_sexp_variable_name(nameIn);
498-
item->countInWings = 0;
499-
break;
500-
}
501-
}
502-
}
503-
}
504-
505-
_spinBoxUpdateRequired = true;
506-
buildCurrentLists();
507-
modelChanged();
508-
}
509-
510-
void LoadoutDialogModel::setWeaponEnablerVariables(SCP_vector<SCP_string> variablesIn, bool enabled, int extraAllocated, SCP_string varForCount)
511-
{
512-
for (auto& nameIn : variablesIn) {
513-
for (auto& variable : _weaponVarList) {
514-
if (nameIn == variable.first) {
515-
variable.second = enabled;
516-
break;
517-
}
518-
}
519-
}
520-
521-
// if they are enabled, we need to add them to the list.
522-
if (enabled) {
523-
for (auto& nameIn : variablesIn) {
524-
bool found = false;
525-
526-
for (auto& item : _teams[_currentTeam].varWeapons) {
527-
528-
// check to see if it was already added
529-
if (item.name == nameIn) {
530-
found = true;
531-
item.varCountIndex = get_index_sexp_variable_name(varForCount);
532-
533-
if (extraAllocated == 0 && item.varCountIndex == -1) {
534-
item.extraAllocated = (int)((float)_teams[_currentTeam].startingShipCount / 2.0f);
535-
536-
// at least have 1
537-
if (item.extraAllocated < 1) {
538-
item.extraAllocated = 1;
539-
}
540-
}
541-
else {
542-
item.extraAllocated = extraAllocated;
543-
}
544-
545-
break;
546-
}
547-
}
548-
549-
if (!found) {
550-
_teams[_currentTeam].varShips.emplace_back(
551-
get_index_sexp_variable_name(nameIn),
552-
true,
553-
false, // it cannot be required because it is var enabled
554-
0, // there cannot be any because this is var enabled.
555-
WeaponVarDefault * _teams[_currentTeam].startingShipCount,
556-
-1, // no var for count until one can be selected.
557-
SCP_string(nameIn));
558-
}
559-
}
560-
561-
} // if they are disabled, remove them.
562-
else {
563-
for (auto& nameIn : variablesIn) {
564-
auto item = _teams[_currentTeam].varWeapons.begin();
565-
while (item != _teams[_currentTeam].varWeapons.end()) {
566-
// check to see if it was already added, and get rid of the info.
567-
if (item->name == nameIn) {
568-
item->enabled = false;
569-
item->extraAllocated = 0;
570-
item->infoIndex = -1;
571-
item->varCountIndex = get_index_sexp_variable_name(nameIn);
572-
item->countInWings = 0;
573-
break;
574-
}
575-
}
576-
}
577-
}
578-
579-
_spinBoxUpdateRequired = true;
580-
buildCurrentLists();
581-
modelChanged();
582-
}
583-
584347
bool LoadoutDialogModel::apply() {
585348

586349
int currentTeam = 0;
@@ -659,8 +422,9 @@ bool LoadoutDialogModel::apply() {
659422

660423

661424
Team_data[currentTeam].num_weapon_choices = index;
425+
Team_data[currentTeam].do_not_validate = modelTeam.skipValidation;
662426
}
663-
427+
664428
Entry_delay_time = fl2f(_playerEntryDelay);
665429

666430

@@ -1170,6 +934,16 @@ void LoadoutDialogModel::setRequiredWeapon(const SCP_vector<SCP_string>& list, c
1170934
buildCurrentLists();
1171935
}
1172936

937+
bool LoadoutDialogModel::getSkipValidation() {
938+
return _teams[_currentTeam].skipValidation;
939+
}
940+
941+
void LoadoutDialogModel::setSkipValidation(const bool skipIt) {
942+
// this is designed to be a global control, so turn this off in TvT, until we hear from someone otherwise.
943+
for (auto& team : _teams) {
944+
team.skipValidation = skipIt;
945+
}
946+
}
1173947

1174948
}
1175949
}

qtfred/src/mission/dialogs/LoadoutEditorDialogModel.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct TeamLoadout {
3232
weapons = {};
3333
varShips = {};
3434
varWeapons = {};
35+
skipValidation = false;
3536
}
3637

3738
int startingShipCount; // TODO: Make sure this gets pop everywhere
@@ -41,6 +42,7 @@ struct TeamLoadout {
4142
SCP_vector<LoadoutItem> weapons;
4243
SCP_vector<LoadoutItem> varShips;
4344
SCP_vector<LoadoutItem> varWeapons;
45+
bool skipValidation;
4446
};
4547

4648
class LoadoutDialogModel : public AbstractDialogModel {
@@ -71,6 +73,7 @@ class LoadoutDialogModel : public AbstractDialogModel {
7173
int getExtraAllocatedWeapons(SCP_vector<SCP_string> namesIn);
7274
int getExtraAllocatedShipEnabler(SCP_vector<SCP_string> namesIn);
7375
int getExtraAllocatedWeaponEnabler(SCP_vector<SCP_string> namesIn);
76+
bool getSkipValidation();
7477

7578
void setShipEnabled(const SCP_vector<SCP_string>& list, bool enabled);
7679
void setShipVariableEnabled(const SCP_vector<SCP_string>& list, bool enabled);
@@ -82,12 +85,8 @@ class LoadoutDialogModel : public AbstractDialogModel {
8285
void setExtraAllocatedForWeaponVariablesCount(const SCP_vector<SCP_string>& list, const uint count);
8386

8487
void setExtraAllocatedViaVariable(const SCP_vector<SCP_string>& list, const SCP_string& variable, const bool ship, const bool variableMode);
85-
86-
void setShipInfo(SCP_string textIn, bool enabled, int extraAllocated, SCP_string varForCount);
87-
void setWeaponInfo(SCP_string textIn, bool enabled, int extraAllocated, SCP_string varForCount);
88-
void setShipEnablerVariables(SCP_vector<SCP_string> variablesIn, bool enabled, int extraAllocated, SCP_string varForCount);
89-
void setWeaponEnablerVariables(SCP_vector<SCP_string> variablesIn, bool enabled, int extraAllocated, SCP_string varForCount);
9088
void setRequiredWeapon(const SCP_vector<SCP_string>& list, const bool required);
89+
void setSkipValidation(const bool skipIt);
9190

9291
void switchTeam(int teamIn);
9392
void copyToOtherTeam();

0 commit comments

Comments
 (0)