mirror of
https://github.com/FalloutCollaborationProject/FCP-Tools.git
synced 2026-07-27 16:59:37 -07:00
Reformat IncidentWorker_AnimalPasses
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
// ReSharper disable UnassignedField.Global
|
||||
|
||||
namespace FCP.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Configuration ModExtension for the IncidentWorker_AnimalPasses
|
||||
/// </summary>
|
||||
[UsedImplicitly, SuppressMessage("ReSharper", "UnassignedField.Global")]
|
||||
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
|
||||
public class ModExtension_AnimalPassesConfig : DefModExtension
|
||||
{
|
||||
public ThingDef animalThing;
|
||||
|
||||
@@ -8,44 +8,44 @@ namespace FCP.Core;
|
||||
/// </summary>
|
||||
public class IncidentWorker_AnimalPasses : IncidentWorker
|
||||
{
|
||||
private ModExtension_AnimalPassesConfig Config =>
|
||||
private ModExtension_AnimalPassesConfig Config =>
|
||||
def.GetModExtension<ModExtension_AnimalPassesConfig>();
|
||||
|
||||
|
||||
protected override bool CanFireNowSub(IncidentParms parms)
|
||||
{
|
||||
Map map = (Map)parms.target;
|
||||
|
||||
bool toxicFalloutActive = !Config.ignoreToxicFallout &&
|
||||
map.gameConditionManager
|
||||
.ConditionIsActive(GameConditionDefOf.ToxicFallout);
|
||||
|
||||
bool noxiousHazeActive = ModsConfig.BiotechActive &&
|
||||
map.gameConditionManager
|
||||
.ConditionIsActive(GameConditionDefOf.NoxiousHaze);
|
||||
|
||||
bool temperatureUnacceptable = !Config.ignoreTemperature &&
|
||||
!map.mapTemperature
|
||||
.SeasonAndOutdoorTemperatureAcceptableFor(Config.animalThing);
|
||||
|
||||
return !toxicFalloutActive &&
|
||||
!noxiousHazeActive &&
|
||||
!temperatureUnacceptable &&
|
||||
if (parms.target is not Map map)
|
||||
return false;
|
||||
|
||||
bool toxicFalloutActive = !Config.ignoreToxicFallout &&
|
||||
map.gameConditionManager.ConditionIsActive(GameConditionDefOf.ToxicFallout);
|
||||
|
||||
bool noxiousHazeActive = ModsConfig.BiotechActive &&
|
||||
map.gameConditionManager.ConditionIsActive(GameConditionDefOf.NoxiousHaze);
|
||||
|
||||
bool temperatureUnacceptable = !Config.ignoreTemperature &&
|
||||
!map.mapTemperature.SeasonAndOutdoorTemperatureAcceptableFor(Config.animalThing);
|
||||
|
||||
return !toxicFalloutActive &&
|
||||
!noxiousHazeActive &&
|
||||
!temperatureUnacceptable &&
|
||||
TryFindEntryCell(map, out _);
|
||||
}
|
||||
|
||||
|
||||
protected override bool TryExecuteWorker(IncidentParms parms)
|
||||
{
|
||||
Map map = (Map)parms.target;
|
||||
|
||||
if (!TryFindEntryCell(map, out IntVec3 cell))
|
||||
if (parms.target is not Map map)
|
||||
return false;
|
||||
|
||||
PawnKindDef pawnKindDef = Config.animalPawnKind;
|
||||
|
||||
|
||||
if (!TryFindEntryCell(map, out IntVec3 cell))
|
||||
return false;
|
||||
|
||||
PawnKindDef animalPawnKind = Config.animalPawnKind;
|
||||
|
||||
int animalCount = GenMath.RoundRandom(StorytellerUtility
|
||||
.DefaultThreatPointsNow(map) / pawnKindDef.combatPower);
|
||||
|
||||
animalCount = Mathf.Clamp(animalCount, min: Config.minCount,
|
||||
.DefaultThreatPointsNow(map) / animalPawnKind.combatPower);
|
||||
|
||||
animalCount = Mathf.Clamp(animalCount,
|
||||
min: Config.minCount,
|
||||
max: Config.maxRangeInclusive.RandomInRange);
|
||||
|
||||
if (!RCellFinder.TryFindRandomCellOutsideColonyNearTheCenterOfTheMap(
|
||||
@@ -53,34 +53,36 @@ public class IncidentWorker_AnimalPasses : IncidentWorker
|
||||
{
|
||||
forcedGotoPosition = IntVec3.Invalid;
|
||||
}
|
||||
|
||||
|
||||
Pawn generatedPawn = null;
|
||||
for (int i = 0; i < animalCount; i++)
|
||||
{
|
||||
// create and spawn the pawns
|
||||
IntVec3 enterCell = CellFinder.RandomClosewalkCellNear(cell, map, 10);
|
||||
|
||||
generatedPawn = PawnGenerator.GeneratePawn(pawnKindDef);
|
||||
|
||||
generatedPawn = PawnGenerator.GeneratePawn(animalPawnKind);
|
||||
GenSpawn.Spawn(generatedPawn, enterCell, map, Rot4.Random);
|
||||
|
||||
|
||||
// leave the map after a random amount of ticks.
|
||||
generatedPawn.mindState.exitMapAfterTick = Find.TickManager.TicksGame +
|
||||
Config.ticksToLeave.RandomInRange;
|
||||
if (forcedGotoPosition.IsValid)
|
||||
{
|
||||
generatedPawn.mindState.forcedGotoPosition = CellFinder
|
||||
.RandomClosewalkCellNear(forcedGotoPosition, map, 10);
|
||||
generatedPawn.mindState.forcedGotoPosition =
|
||||
CellFinder.RandomClosewalkCellNear(forcedGotoPosition, map, 10);
|
||||
}
|
||||
}
|
||||
|
||||
SendStandardLetter(def.letterLabel.Translate(), def.letterText.Translate(),
|
||||
LetterDefOf.PositiveEvent, parms, generatedPawn);
|
||||
|
||||
SendStandardLetter(def.letterLabel.Translate(), def.letterText.Translate(),
|
||||
baseLetterDef: LetterDefOf.PositiveEvent,
|
||||
parms: parms,
|
||||
lookTargets: generatedPawn);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected virtual bool TryFindEntryCell(Map map, out IntVec3 cell)
|
||||
{
|
||||
return RCellFinder.TryFindRandomPawnEntryCell(out cell, map,
|
||||
CellFinder.EdgeRoadChance_Animal + 0.2f);
|
||||
return RCellFinder.TryFindRandomPawnEntryCell(out cell, map, CellFinder.EdgeRoadChance_Animal + 0.2f);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user