Skip to content

Commit 65cb525

Browse files
committed
Add map issue check for a difficulty-specific trigger disabling a trigger of a different difficulty level
1 parent d0bf1aa commit 65cb525

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/TSMapEditor/Config/Translations/en/Translation_en.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Map.CheckForIssues.TriggerTooManyActions=Trigger '{0}' has more than {1} actions
135135
Map.CheckForIssues.SpecialWaypointUsed=The map makes use of waypoint #{0}. In Tiberian Sun, this waypoint is reserved for special use cases (WAYPT_SPECIAL). Using it as a normal waypoint may cause issues as it may be dynamically moved by game events.
136136
Map.CheckForAITriggerTeamWithMaxZeroIssue.TeamTypeMax=Team '{0}', linked to AITrigger '{1}', has Max=0. This prevents the AI from building the team.
137137
Map.CheckForIssues.MismatchedDifficultyForEnableTrigger=The trigger "{0}" has "{1}" as its difficulty level, but it enables a trigger "{2}" which has "{3}" as its difficulty.
138+
Map.CheckForIssues.MismatchedDifficultyForDisableTrigger=The trigger "{0}" has "{1}" as its difficulty level, but it disables a trigger "{2}" which has "{3}" as its difficulty.
138139

139140
; *************************************************
140141
; Difficulty

src/TSMapEditor/Misc/MapIssueChecker.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace TSMapEditor.Misc
1111
public static class MapIssueChecker
1212
{
1313
private const int EnableTriggerActionIndex = 53;
14+
private const int DisableTriggerActionIndex = 54;
1415
private const int TriggerParamIndex = 1;
1516

1617
/// <summary>
@@ -71,8 +72,6 @@ public static List<string> CheckForIssues(Map map)
7172
"TeamType \"{0}\" has no Script set!"), tt.Name));
7273
});
7374

74-
const int DisableTriggerActionIndex = 54;
75-
7675
// Check for triggers that are disabled and are never enabled by any other triggers
7776
map.Triggers.ForEach(trigger =>
7877
{
@@ -427,6 +426,7 @@ public static List<string> CheckForIssues(Map map)
427426
}
428427

429428
CheckForMismatchedDifficultyEnableIssue(map, issueList);
429+
CheckForMismatchedDifficultyDisableIssue(map, issueList);
430430

431431
return issueList;
432432
}
@@ -522,5 +522,38 @@ private static void CheckForMismatchedDifficultyEnableIssue(Map map, List<string
522522
}
523523
}
524524
}
525+
526+
private static void CheckForMismatchedDifficultyDisableIssue(Map map, List<string> issueList)
527+
{
528+
foreach (var trigger in map.Triggers)
529+
{
530+
Difficulty difficulty = GetTriggerDifficulty(map, trigger);
531+
532+
if (difficulty == Difficulty.None)
533+
continue;
534+
535+
// Check if this trigger disables a trigger that does not match its difficulty level.
536+
// If yes, report that as a bug.
537+
for (int i = 0; i < trigger.Actions.Count; i++)
538+
{
539+
TriggerAction action = trigger.Actions[i];
540+
541+
if (action.ActionIndex == DisableTriggerActionIndex)
542+
{
543+
var otherTrigger = map.Triggers.Find(t => t.ID == action.Parameters[TriggerParamIndex]);
544+
if (otherTrigger != null)
545+
{
546+
Difficulty otherTriggerDifficulty = GetTriggerDifficulty(map, otherTrigger);
547+
if (otherTriggerDifficulty != Difficulty.None && difficulty != otherTriggerDifficulty)
548+
{
549+
issueList.Add(string.Format(Translate(map, "CheckForIssues.MismatchedDifficultyForDisableTrigger",
550+
"The trigger \"{0}\" has \"{1}\" as its difficulty level, but it disables a trigger \"{2}\" which has \"{3}\" as its difficulty."),
551+
trigger.Name, Helpers.DifficultyToTranslatedString(difficulty), otherTrigger.Name, Helpers.DifficultyToTranslatedString(otherTriggerDifficulty)));
552+
}
553+
}
554+
}
555+
}
556+
}
557+
}
525558
}
526559
}

0 commit comments

Comments
 (0)