public static void Postfix(Map __instance) { Log.Message("WeatherChecker: " + __instance.ToString()); bool comeFromOuterSource; var tempComp = new WorldObjectComp_InfectedTile(); tempComp.infectedTile = __instance.Tile; if (PurpleIvyUtils.getFogProgressWithOuterSources(0, tempComp, out comeFromOuterSource) > 0f && !__instance.gameConditionManager.ConditionIsActive(PurpleIvyDefOf.PurpleFogGameCondition)) { GameCondition_PurpleFog gameCondition = (GameCondition_PurpleFog)GameConditionMaker.MakeConditionPermanent (PurpleIvyDefOf.PurpleFogGameCondition); __instance.gameConditionManager.RegisterCondition(gameCondition); tempComp.parent = __instance.Parent; tempComp.StartInfection(); tempComp.gameConditionCaused = PurpleIvyDefOf.PurpleFogGameCondition; tempComp.counter = 0; tempComp.infected = false; tempComp.infectedTile = __instance.Tile; tempComp.radius = tempComp.GetRadius(); PurpleIvyData.TotalFogProgress[tempComp] = PurpleIvyUtils.getFogProgress(tempComp.counter); tempComp.fillRadius(); __instance.Parent.AllComps.Add(tempComp); } }
public override void LoadedGame() { base.LoadedGame(); PurpleIvyData.TotalFogProgress = new Dictionary <WorldObjectComp_InfectedTile, float>(); PurpleIvyData.TotalPollutedBiomes = new List <int>(); foreach (var worldObject in Find.WorldObjects.AllWorldObjects) { var comp = worldObject.GetComponent <WorldObjectComp_InfectedTile>(); if (comp != null) { PurpleIvyData.TotalFogProgress[comp] = PurpleIvyUtils.getFogProgress(comp.counter); //comp.fillRadius(forced: true); // causes crash when loading a save with infected sites } } for (int i = 0; i < Find.WorldGrid.TilesCount; i++) { if (Find.WorldGrid[i].biome.defName.Contains("PI_")) { PurpleIvyData.TotalPollutedBiomes.Add(i); } } if (Find.FactionManager.AllFactions.Where(x => x.def == PurpleIvyDefOf.Genny).Count() == 0) { Log.Message("No alien faction in the game, fixing it"); Faction faction = FactionGenerator.NewGeneratedFaction(PurpleIvyDefOf.Genny); faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Hostile, false, null, null); Find.FactionManager.Add(faction); } }
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = parms.target as Map; bool result; int num; if (TileFinder.TryFindNewSiteTile(out num, 7, 27, false, true, -1)) { Site site = (Site)WorldObjectMaker.MakeWorldObject(PurpleIvyDefOf.PI_InfectedTile); site.Tile = num; site.SetFaction(PurpleIvyData.AlienFaction); site.AddPart(new SitePart(site, PurpleIvyDefOf.InfectedSite, PurpleIvyDefOf.InfectedSite.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), num, PurpleIvyData.AlienFaction))); var comp = site.GetComponent <WorldObjectComp_InfectedTile>(); comp.StartInfection(); comp.gameConditionCaused = PurpleIvyDefOf.PurpleFogGameCondition; comp.counter = 600; comp.infectedTile = site.Tile; comp.radius = comp.GetRadius(); PurpleIvyData.TotalFogProgress[comp] = PurpleIvyUtils.getFogProgress(comp.counter); comp.fillRadius(true); site.GetComponent <TimeoutComp>().StartTimeout(30 * 60000); Find.WorldObjects.Add(site); Find.LetterStack.ReceiveLetter("InfectedTile".Translate(), "InfectedTileDesc".Translate(), LetterDefOf.ThreatBig, site); result = true; } else { result = false; } return(result); }
public override float SkyTargetLerpFactor(Map map) { if (this.fogProgress.ContainsKey(map)) { return(this.fogProgress[map]); } else { Log.Error("Something went wrong with the map " + map + ". It was not represented in " + "the fogProgress dictionary."); bool temp; var comp = map.Parent.GetComponent <WorldObjectComp_InfectedTile>(); if (comp == null) { Log.Message("Adding new comp, due missing the one in the mapParent"); comp = new WorldObjectComp_InfectedTile(); int count = map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy).Count; count += map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSac).Count; count += map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacBeta).Count; count += map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacGamma).Count; count += map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacNestGuard).Count; count += map.listerThings.ThingsOfDef(PurpleIvyDefOf.ParasiteEgg).Count; count += map.listerThings.ThingsOfDef(PurpleIvyDefOf.GasPump).Count; count += map.listerThings.ThingsOfDef(PurpleIvyDefOf.GenTurretBase).Count; count += map.listerThings.ThingsOfDef(PurpleIvyDefOf.Turret_GenMortarSeed).Count; count += map.listerThings.ThingsOfDef(PurpleIvyDefOf.PI_Nest).Count; comp.parent = map.Parent; comp.StartInfection(); comp.gameConditionCaused = PurpleIvyDefOf.PurpleFogGameCondition; comp.counter = count; comp.infectedTile = map.Tile; comp.radius = comp.GetRadius(); PurpleIvyData.TotalFogProgress[comp] = PurpleIvyUtils.getFogProgress(comp.counter); comp.fillRadius(); map.Parent.AllComps.Add(comp); PurpleIvyData.TotalFogProgress[comp] = PurpleIvyUtils.getFogProgress(count); this.fogProgress[map] = PurpleIvyUtils.getFogProgressWithOuterSources(count, comp, out temp); } else { this.fogProgress[map] = 0f; Log.Message("The fogProgress value is reset to 0"); } return(this.fogProgress[map]); } }
public static float getFogProgressWithOuterSources(int count, WorldObjectComp_InfectedTile comp, out bool comeFromOuterSource) { var result = PurpleIvyUtils.getFogProgress(count); //Log.Message("fog progress: " + result.ToString()); var outerSource = 0f; foreach (var data in PurpleIvyData.TotalFogProgress.Where(data => data.Key != comp)) { int distance = Find.WorldGrid.TraversalDistanceBetween(comp.infectedTile, data.Key.infectedTile, true, int.MaxValue); if (distance <= data.Key.radius) { float floatRadius = ((float)data.Key.counter - 500f) / 100f; if (floatRadius < 0) { floatRadius = 0; } float newValue = GetPartFromPercentage(GetPercentageFromPartWhole(floatRadius, distance) / 100f, data.Value); if (newValue > data.Value) { outerSource += data.Value; } else { outerSource += newValue; } } } if (outerSource < 0f) { outerSource = 0f; } if (result == 0f && outerSource > 0f) { comeFromOuterSource = true; } else { comeFromOuterSource = false; } return(result + outerSource); }
public override void MapComponentTick() { base.MapComponentTick(); if (Find.TickManager.TicksGame % 250 == 0) { var plants = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy); //Log.Message("Checking orbital strike, " + this.OrbitalHelpActive + " - " + plants.Count); if (plants != null && ((this.OrbitalHelpActive == true && plants.Count > 0) || plants.Count > 2000)) // && Rand.Chance(PurpleIvyData.getFogProgress(plants.Count))) { if (this.OrbitalHelpActive == false) { this.OrbitalHelpActive = true; Find.LetterStack.ReceiveLetter("OrbitalHelpFromAncients".Translate(), "OrbitalHelpFromAncientsDesc".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(plants.RandomElement().Position, map, false)); } PowerBeam powerBeam = (PowerBeam)GenSpawn.Spawn(PurpleIvyDefOf.PI_PowerBeam, plants.RandomElement().Position, this.map, 0); powerBeam.duration = 200; powerBeam.instigator = null; powerBeam.weaponDef = null; powerBeam.StartStrike(); } if ((plants.Count <= 0 || plants == null) && this.OrbitalHelpActive == true) { Log.Message("Orbital help"); this.OrbitalHelpActive = false; List <Pawn> list = new List <Pawn>(); var alpha = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteAlpha); var beta = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteBeta); var gamma = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteGamma); var omega = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteOmega); var guard = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteNestGuard); int pawnCount = alpha.Count; pawnCount += beta.Count; pawnCount += gamma.Count; pawnCount += omega.Count; pawnCount += guard.Count; Predicate <IntVec3> predicate = delegate(IntVec3 c) { return(!GridsUtility.Fogged(c, map) && !GridsUtility.Roofed(c, map) && GenGrid.InBounds(c, map) && GenRadial.RadialCellsAround(c, 10, true).Where(x => map.thingGrid.ThingsListAt(x).Where(y => y.Faction == PurpleIvyData.AlienFaction) != null) != null); }; IntVec3 position = CellFinder.RandomClosewalkCellNear(this.map.Center, this.map, 500, predicate); foreach (var num in Enumerable.Range(1, pawnCount / 2)) { Faction faction = FactionUtility.DefaultFactionFrom(PurpleIvyDefOf.KorsolianFaction); Pawn NewPawn = PawnGenerator.GeneratePawn(PurpleIvyDefOf.KorsolianSoldier, faction); if (faction != null && faction != Faction.OfPlayer) { Lord lord = null; if (this.map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != NewPawn)) { lord = ((Pawn)GenClosest.ClosestThing_Global(NewPawn.Position, this.map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, (Thing p) => p != NewPawn && ((Pawn)p).GetLord() != null, null)).GetLord(); } if (lord == null) { var lordJob = new LordJob_AssistColony(Faction.OfPlayer, position); //LordJob_DefendPoint lordJob = new LordJob_DefendPoint(position); lord = LordMaker.MakeNewLord(faction, lordJob, this.map, null); } lord.AddPawn(NewPawn); } Log.Message(NewPawn?.Faction?.def?.defName); list.Add(NewPawn); } DropPodUtility.DropThingsNear(position, this.map, list, 30, false, true, true, true); Find.LetterStack.ReceiveLetter("AncientsLandOnTheGround".Translate(), "AncientsLandOnTheGroundDesc".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(position, map, false)); } //Log.Message("Alpha limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteAlpha.defName]); //Log.Message("Beta limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteBeta.defName]); //Log.Message("Gamma limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteGamma.defName]); //Log.Message("Omega limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteOmega.defName]); int count = plants.Count; bool comeFromOuterSource; var tempComp = new WorldObjectComp_InfectedTile(); tempComp.infectedTile = map.Tile; if (PurpleIvyUtils.getFogProgressWithOuterSources(count, tempComp, out comeFromOuterSource) > 0f && !map.gameConditionManager.ConditionIsActive(PurpleIvyDefOf.PurpleFogGameCondition)) { GameCondition_PurpleFog gameCondition = (GameCondition_PurpleFog)GameConditionMaker.MakeConditionPermanent (PurpleIvyDefOf.PurpleFogGameCondition); map.gameConditionManager.RegisterCondition(gameCondition); if (comeFromOuterSource == false) { Find.LetterStack.ReceiveLetter(gameCondition.LabelCap, gameCondition.LetterText, gameCondition.def.letterDef, new TargetInfo(map.Center, map, false)); } else { Find.LetterStack.ReceiveLetter("PurpleFogСomesFromInfectedSites".Translate(), "PurpleFogСomesFromInfectedSitesDesc".Translate(), LetterDefOf.ThreatBig, new TargetInfo(map.Center, map, false)); Log.Message("PurpleFogСomesFromInfectedSites: " + map.ToString() + " - " + Find.TickManager.TicksGame.ToString()); } if (map.Parent.GetComponent <WorldObjectComp_InfectedTile>() == null) { var comp = new WorldObjectComp_InfectedTile(); comp.parent = map.Parent; comp.StartInfection(); comp.gameConditionCaused = PurpleIvyDefOf.PurpleFogGameCondition; comp.counter = count; comp.infectedTile = map.Tile; comp.radius = comp.GetRadius(); PurpleIvyData.TotalFogProgress[comp] = PurpleIvyUtils.getFogProgress(comp.counter); comp.fillRadius(); map.Parent.AllComps.Add(comp); Log.Message("Adding comp to: " + map.Parent.ToString()); } } } if (Find.TickManager.TicksGame % 60000 == 0) { int count = 0; var alphaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSac); var betaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacBeta); var gammaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacGamma); var nestsEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacNestGuard); var omegaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.ParasiteEgg); Log.Message("Total PurpleIvy count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy).Count.ToString(), true); count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteAlpha).Count; if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteAlpha.defName]) { foreach (var egg in alphaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = true; } } else { foreach (var egg in alphaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = false; } } Log.Message("Total Genny_ParasiteAlpha count on the map: " + count.ToString(), true); count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteBeta).Count; if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteBeta.defName]) { foreach (var egg in betaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = true; } } else { foreach (var egg in betaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = false; } } Log.Message("Total Genny_ParasiteBeta count on the map: " + count.ToString(), true); count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteGamma).Count; if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteGamma.defName]) { foreach (var egg in gammaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = true; } } else { foreach (var egg in gammaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = false; } } Log.Message("Total Genny_ParasiteGamma count on the map: " + count.ToString(), true); count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteOmega).Count; if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteOmega.defName]) { foreach (var egg in omegaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = true; } } else { foreach (var egg in omegaEggs) { var eggSac = (Building_EggSac)egg; eggSac.TryGetComp <AlienInfection>().stopSpawning = false; } } Log.Message("Total Genny_ParasiteOmega count on the map: " + count.ToString(), true); Log.Message("Total Genny_ParasiteNestGuard count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteNestGuard).Count.ToString(), true); Log.Message("Total EggSac count on the map: " + alphaEggs.Count.ToString(), true); Log.Message("Total EggSac beta count on the map: " + betaEggs.Count.ToString(), true); Log.Message("Total EggSac gamma count on the map: " + gammaEggs.Count.ToString(), true); Log.Message("Total EggSac NestGuard count on the map: " + nestsEggs.Count.ToString(), true); Log.Message("Total ParasiteEgg count on the map: " + omegaEggs.Count.ToString(), true); Log.Message("Total GasPump count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.GasPump).Count.ToString(), true); Log.Message("Total GenTurretBase count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.GenTurretBase).Count.ToString(), true); Log.Message("Total Turret_GenMortarSeed count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Turret_GenMortarSeed).Count.ToString(), true); Log.Message("Total Nest count on the map: " + this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PI_Nest).Count.ToString(), true); } }
public override void CompTick() { base.CompTick(); if (this.active && this.infected) { if (Find.TickManager.TicksGame % 600 == 0) { this.counter++; this.fillRadius(); if (this.counter > 750 && this.delay < Find.TickManager.TicksGame) { int num; Predicate <int> predicate = (int x) => this.infectedTile != x && !Find.WorldObjects.AnyWorldObjectAt (x, PurpleIvyDefOf.PI_InfectedTile); if (TileFinder.TryFindPassableTileWithTraversalDistance(this.parent.Tile, 0, 1, out num, predicate, false, true, false)) { Site site = null; bool infected = false; if (!Find.WorldObjects.AnyMapParentAt(num)) { site = (Site)WorldObjectMaker.MakeWorldObject(PurpleIvyDefOf.PI_InfectedTile); site.Tile = num; site.SetFaction(PurpleIvyData.AlienFaction); } else { var worldObject = Find.WorldObjects.MapParentAt(num); if (worldObject is Site) { Log.Message("Infect other non-infected sites"); site = (Site)worldObject; infected = true; } else { Log.Message("Error: " + worldObject.ToString()); } } if (infected == true) { site.AddPart(new SitePart(site, PurpleIvyDefOf.InfectedSite, PurpleIvyDefOf.InfectedSite.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), num, PurpleIvyData.AlienFaction))); site.AddPart(new SitePart(site, PurpleIvyDefOf.InfectedSite, PurpleIvyDefOf.InfectedSite.Worker.GenerateDefaultParams (StorytellerUtility.DefaultSiteThreatPointsNow(), num, PurpleIvyData.AlienFaction))); var comp = site.GetComponent <WorldObjectComp_InfectedTile>(); comp.StartInfection(); comp.gameConditionCaused = PurpleIvyDefOf.PurpleFogGameCondition; comp.counter = 0; comp.infectedTile = site.Tile; comp.radius = comp.GetRadius(); PurpleIvyData.TotalFogProgress[comp] = PurpleIvyUtils.getFogProgress(comp.counter); comp.fillRadius(); site.GetComponent <TimeoutComp>().StartTimeout(30 * 60000); Find.WorldObjects.Add(site); Find.LetterStack.ReceiveLetter("InfectedTileSpreading".Translate(), "InfectedTileSpreadingDesc".Translate(), LetterDefOf.ThreatBig, site); this.delay = Find.TickManager.TicksGame + new IntRange(220000, 270000).RandomInRange; } } } } if (Find.TickManager.TicksGame % 60 == 0) { MapParent mapParent = this.parent as MapParent; if (mapParent != null && mapParent.Map != null) { int count = mapParent.Map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy).Count; if (count > 0) { this.counter = count; } else if (count <= 0) { this.counter = 0; this.StopInfection(); } } PurpleIvyData.TotalFogProgress[this] = PurpleIvyUtils.getFogProgress(this.counter); } } }