BrettRyland / BDArmory

Gun turrets and other weapon systems for KSP
32 stars 23 forks source link

S5R1 gungame mutator support #609

Closed SuicidalInsanity closed 5 months ago

SuicidalInsanity commented 5 months ago

-Add support for Apply-on-Kill mutators to work their way through a list, instead of random . -Fix cont. spawn vessels not having HOS/Mutator/round-specific stuff applied to them if spawning after comp start. -Better handling of hasCharged for chargable weapons when reloading/overheated/disabled.

BrettRyland commented 5 months ago

OK, I did some quick testing with the gunGameMutators.cfg and I noticed a few issues:

  1. The mutator duration slider maximum is based on the competition duration, which, when it's set to 0 makes the mutator duration slider inoperable. I'd suggest changing line 3243 of BDArmorySetup.cs to something like:

    BDArmorySettings.MUTATOR_DURATION = (float)Math.Round(GUI.HorizontalSlider(SRightSliderRect(line), BDArmorySettings.MUTATOR_DURATION, 0f, BDArmorySettings.COMPETITION_DURATION > 0 ? BDArmorySettings.COMPETITION_DURATION : 15), 1);

    and / or having MUTATOR_DURATION being overridden for S6R1.

  2. The first mutator isn't applied until a kill is made, which means craft are starting with their initial load-out. If the only weapons allowed are brownings, then this isn't too much of a problem, but it means you need two kills to progress to the next weapon type. I think this is due to SpawnUtilsInstance.ApplyMutators not having the extra code for S6R1 that is in BDACompetitionMode.cs (lines 2898—2909), which should probably just be calling SpawnUtils.ApplyMutators(loadedVessels.Current, true) anyway.

  3. The user has to enable mutators and manually select the correct set of mutators for S6R1. This isn't a big deal, but it would be nicer if the RWP S6R1 slider could automatically set this up.

BrettRyland commented 5 months ago

I think this should fix the first two points:

diff --git a/BDArmory/Competition/BDACompetitionMode.cs b/BDArmory/Competition/BDACompetitionMode.cs
index 2855b75c4..4fb91d020 100644
--- a/BDArmory/Competition/BDACompetitionMode.cs
+++ b/BDArmory/Competition/BDACompetitionMode.cs
@@ -2896,15 +2896,3 @@ public void DoUpdate()
                                         {
-                                            var MM = loadedVessels.Current.rootPart.FindModuleImplementing<BDAMutator>(); //replace with vesselregistry?
-                                            if (MM == null)
-                                            {
-                                                MM = (BDAMutator)loadedVessels.Current.rootPart.AddModule("BDAMutator");
-                                            }
-                                            if (BDArmorySettings.RUNWAY_PROJECT && BDArmorySettings.RUNWAY_PROJECT_ROUND == 61) //gungame
-                                            {
-                                                MM.EnableMutator(BDArmorySettings.MUTATOR_LIST[MM.progressionIndex]); //increment to next mutator on list
-                                                MM.progressionIndex++;
-                                                if (MM.progressionIndex > BDArmorySettings.MUTATOR_LIST.Count - 1) MM.progressionIndex = BDArmorySettings.MUTATOR_LIST.Count - 1; //= 0 and have mutator list cycle instead??
-                                            }
-                                            else MM.EnableMutator();//random mutator
-                                            competitionStatus.Add(Scores.ScoreData[player].lastPersonWhoDamagedMe + " gains " + MM.mutatorName + (BDArmorySettings.MUTATOR_DURATION > 0 ? " for " + BDArmorySettings.MUTATOR_DURATION * 60 + " seconds!" : "!"));
+                                            SpawnUtils.ApplyMutators(loadedVessels.Current, true);
                                             break;
diff --git a/BDArmory/UI/BDArmorySetup.cs b/BDArmory/UI/BDArmorySetup.cs
index 6788bf08c..1612344e6 100644
--- a/BDArmory/UI/BDArmorySetup.cs
+++ b/BDArmory/UI/BDArmorySetup.cs
@@ -3242,3 +3242,3 @@ void WindowSettings(int windowID)
                         GUI.Label(SLeftSliderRect(++line), $"{StringUtils.Localize("#LOC_BDArmory_Settings_MutatorDuration")}: ({(BDArmorySettings.MUTATOR_DURATION > 0 ? BDArmorySettings.MUTATOR_DURATION + (BDArmorySettings.MUTATOR_DURATION > 1 ? " mins" : " min") : "Unlimited")})", leftLabel);
-                        BDArmorySettings.MUTATOR_DURATION = (float)Math.Round(GUI.HorizontalSlider(SRightSliderRect(line), BDArmorySettings.MUTATOR_DURATION, 0f, BDArmorySettings.COMPETITION_DURATION), 1);
+                        BDArmorySettings.MUTATOR_DURATION = (float)Math.Round(GUI.HorizontalSlider(SRightSliderRect(line), BDArmorySettings.MUTATOR_DURATION, 0f, BDArmorySettings.COMPETITION_DURATION > 0 ? BDArmorySettings.COMPETITION_DURATION : 15), 1);

diff --git a/BDArmory/VesselSpawning/SpawnUtils.cs b/BDArmory/VesselSpawning/SpawnUtils.cs
index 21ae6bc3f..72545b0f4 100644
--- a/BDArmory/VesselSpawning/SpawnUtils.cs
+++ b/BDArmory/VesselSpawning/SpawnUtils.cs
@@ -835,5 +835,5 @@ public void ApplyMutators(Vessel vessel, bool enable)
             {
+                var MM = vessel.rootPart.FindModuleImplementing<BDAMutator>();
                 if (enable)
                 {
-                    var MM = vessel.rootPart.FindModuleImplementing<BDAMutator>();
                     if (MM == null)
@@ -842,3 +842,9 @@ public void ApplyMutators(Vessel vessel, bool enable)
                     }
-                    if (BDArmorySettings.MUTATOR_APPLY_GLOBAL) //selected mutator applied globally
+                    if (BDArmorySettings.RUNWAY_PROJECT && BDArmorySettings.RUNWAY_PROJECT_ROUND == 61) //gungame
+                    {
+                        MM.EnableMutator(BDArmorySettings.MUTATOR_LIST[MM.progressionIndex]); //increment to next mutator on list
+                        MM.progressionIndex++;
+                        if (MM.progressionIndex > BDArmorySettings.MUTATOR_LIST.Count - 1) MM.progressionIndex = BDArmorySettings.MUTATOR_LIST.Count - 1; //= 0 and have mutator list cycle instead??
+                    }
+                    else if (BDArmorySettings.MUTATOR_APPLY_GLOBAL) //selected mutator applied globally
                     {
@@ -846,3 +852,3 @@ public void ApplyMutators(Vessel vessel, bool enable)
                     }
-                    if (BDArmorySettings.MUTATOR_APPLY_TIMER && !BDArmorySettings.MUTATOR_APPLY_GLOBAL) //mutator applied on a per-craft basis
+                    else if (BDArmorySettings.MUTATOR_APPLY_TIMER) //mutator applied on a per-craft basis
                     {
@@ -850,2 +856,3 @@ public void ApplyMutators(Vessel vessel, bool enable)
                     }
+                    BDACompetitionMode.Instance.competitionStatus.Add($"{vessel.vesselName} gains {MM.mutatorName}{(BDArmorySettings.MUTATOR_DURATION > 0 ? $" for {BDArmorySettings.MUTATOR_DURATION * 60} seconds!" : "!")}");
                 }
@@ -853,3 +860,2 @@ public void ApplyMutators(Vessel vessel, bool enable)
                 {
-                    var MM = vessel.rootPart.FindModuleImplementing<BDAMutator>();
                     if (MM != null)

though it still would be good if the S6R1 slider overrode the MUTATOR_DURATION to be 0.