private void AffectCell(IntVec3 c) { if (!c.InBounds(base.Map)) { return; } bool flag = this.ShouldCellBeAffectedOnlyByDamage(c); if (!flag && Rand.Chance(this.preExplosionSpawnChance) && c.Walkable(base.Map)) { if (c.DistanceTo(this.center) < 1) { this.TrySpawnExplosionThing(this.preExplosionSpawnThingDef, c, this.preExplosionSpawnThingCount); } } this.damType.Worker.ExplosionAffectCell(this, c, this.damagedThings, this.ignoredThings, !flag); if (!flag && Rand.Chance(this.postExplosionSpawnChance) && c.Walkable(base.Map)) { if (c.DistanceTo(this.center) < 1) { this.TrySpawnExplosionThing(this.postExplosionSpawnThingDef, c, this.postExplosionSpawnThingCount); } } float num = this.chanceToStartFire; if (this.damageFalloff) { num *= Mathf.Lerp(1f, 0.2f, c.DistanceTo(base.Position) / this.radius); } if (Rand.Chance(num)) { FireUtility.TryStartFireIn(c, base.Map, Rand.Range(0.1f, 0.925f)); } }
protected virtual void Explode() { Map map = base.Map; Destroy(DestroyMode.Vanish); if (base.def.projectile.explosionEffect != null) { Effecter effecter = base.def.projectile.explosionEffect.Spawn(); effecter.Trigger(new TargetInfo(base.Position, map, false), new TargetInfo(base.Position, map, false)); effecter.Cleanup(); } IntVec3 position = base.Position; Map map2 = map; float explosionRadius = base.def.projectile.explosionRadius; DamageDef damageDef = base.def.projectile.damageDef; Thing launcher = base.launcher; int damageAmount = base.DamageAmount; float armorPenetration = base.ArmorPenetration; SoundDef soundExplode = base.def.projectile.soundExplode; ThingDef equipmentDef = base.equipmentDef; ThingDef def = base.def; Thing thing = intendedTarget.Thing; ThingDef postExplosionSpawnThingDef = base.def.projectile.postExplosionSpawnThingDef; float postExplosionSpawnChance = base.def.projectile.postExplosionSpawnChance; int postExplosionSpawnThingCount = base.def.projectile.postExplosionSpawnThingCount; ThingDef preExplosionSpawnThingDef = base.def.projectile.preExplosionSpawnThingDef; GenExplosion.DoExplosion(position, map2, explosionRadius, damageDef, launcher, damageAmount, armorPenetration, soundExplode, equipmentDef, def, thing, postExplosionSpawnThingDef, postExplosionSpawnChance, postExplosionSpawnThingCount, base.def.projectile.applyDamageToExplosionCellsNeighbors, preExplosionSpawnThingDef, base.def.projectile.preExplosionSpawnChance, base.def.projectile.preExplosionSpawnThingCount, base.def.projectile.explosionChanceToStartFire, base.def.projectile.explosionDamageFalloff); foreach (Pawn pawn in map.mapPawns.AllPawns) { if (pawn.Dead) { continue; } try { if (position.DistanceTo(pawn.Position) < 5f) { pawn.health.AddHediff(HediffDef.Named("HeavyRadiationPoisoning")); } else if (position.DistanceTo(pawn.Position) < 20f && position.DistanceTo(pawn.Position) > 5f) { pawn.health.AddHediff(HediffDef.Named("MediumRadiationPoisoning")); } } catch (Exception e) { Log.Message(e.ToString()); } } }
private static void AffectCell(Explosion __instance, IntVec3 c) { if (!c.InBounds(__instance.Map)) { return; } bool flag = ShouldCellBeAffectedOnlyByDamage(__instance, c); if (!flag && Rand.Chance(__instance.preExplosionSpawnChance) && c.Walkable(__instance.Map)) { TrySpawnExplosionThing(__instance, __instance.preExplosionSpawnThingDef, c, __instance.preExplosionSpawnThingCount); } if (null != __instance.damType) { __instance.damType.Worker.ExplosionAffectCell(__instance, c, damagedThings(__instance), ignoredThingsFR(__instance), !flag); } if (!flag && Rand.Chance(__instance.postExplosionSpawnChance) && c.Walkable(__instance.Map)) { TrySpawnExplosionThing(__instance, __instance.postExplosionSpawnThingDef, c, __instance.postExplosionSpawnThingCount); } float num = __instance.chanceToStartFire; if (__instance.damageFalloff) { num *= Mathf.Lerp(1f, 0.2f, c.DistanceTo(__instance.Position) / __instance.radius); } if (Rand.Chance(num)) { FireUtility.TryStartFireIn(c, __instance.Map, Rand.Range(0.1f, 0.925f)); } }
// Token: 0x0600650C RID: 25868 RVA: 0x00233C80 File Offset: 0x00231E80 public override void Resolve(ResolveParams rp) { Faction = rp.faction; HiveFactionExtension hiveFaction = Faction.def.GetModExtension <HiveFactionExtension>(); cells.Clear(); Map map = BaseGen.globalSettings.map; IntVec3 CenterCell = rp.rect.CenterCell; float dist = rp.rect.TopRight.DistanceTo(rp.rect.BottomLeft); // Log.Message(Faction+" hive radius "+ dist); cells = map.AllCells.Where(x => x.DistanceTo(CenterCell) <= dist).ToList(); RoofGrid roofGrid = BaseGen.globalSettings.map.roofGrid; RoofDef def = rp.roofDef ?? RoofDefOf.RoofRockThick; List <IntVec3> cellst = cells.Where(x => x.DistanceTo(CenterCell) < dist - 10).ToList(); List <IntVec3> celle = cells.Where(x => x.DistanceTo(CenterCell) > dist - 5 && x.DistanceTo(CenterCell) < dist).ToList(); for (int i = 0; i < dist / 5; i++) { IntVec3 ce = celle.RandomElement(); Rand.PushState(); float size = Rand.Range(5, 10); Rand.PopState(); cells.RemoveAll(x => ce.DistanceTo(x) < size); } foreach (IntVec3 c in cells) { roofGrid.SetRoof(c, def); map.terrainGrid.SetTerrain(c, TerrainDefOf.Gravel); this.TrySpawnWall(c, rp); } }
private void AffectCell(IntVec3 c) { if (!c.InBounds(base.Map)) { return; } var flag = ShouldCellBeAffectedOnlyByDamage(c); var spawnMote = c.GetFirstThing(Map, damType.explosionCellMote) == null; if (!flag && Rand.Chance(preExplosionSpawnChance) && c.Walkable(Map)) { TrySpawnExplosionThing(preExplosionSpawnThingDef, c, preExplosionSpawnThingCount); } damType.Worker.ExplosionAffectCell(this, c, damagedThings, null, spawnMote && !flag); if (!flag && Rand.Chance(postExplosionSpawnChance) && c.Walkable(Map)) { TrySpawnExplosionThing(postExplosionSpawnThingDef, c, postExplosionSpawnThingCount); } var num = chanceToStartFire; if (damageFalloff) { num *= Mathf.Lerp(1f, (float)DamageAtEdge / damAmount, c.DistanceTo(Position) / radius); } if (Rand.Chance(num)) { FireUtility.TryStartFireIn(c, Map, Rand.Range(0.1f, 0.925f)); } //ExplosionCE (this) can be Destroyed after ExplosionAffectCell }
public static void Postfix(ref Verb __instance, ref bool __result, IntVec3 root, LocalTargetInfo targ) { if (!Main.Instance.IsModEnabled()) { return; } if (!__result || !__instance.CasterIsPawn || !targ.IsValid) { return; } if (targ.Thing != null && targ.Thing == __instance.caster) { return; } if (root.DistanceTo(targ.Cell) <= 2f) { return; } var pawn = __instance.CasterPawn; if (!Main.Instance.GetExtendedDataStorage().ShouldPawnAvoidFriendlyFire(pawn)) { return; } __result = Main.Instance.GetFireManager().CanHitTargetSafely( new FireProperties(pawn, targ.Cell)); }
private void BlinkTargeted(IntVec3 target) { float distanceToTarget = target.DistanceTo(pawn.Position); if (distanceToTarget <= def.radius && !target.Impassable(pawn.Map)) { Blink(target); return; } Vector3 pos = pawn.Position.ToVector3(); Vector3 dest = target.ToVector3(); Vector3 dir = (dest - pos).normalized; pos = pos + dir * Mathf.Min(distanceToTarget, def.radius); for (float distance = distanceToTarget; distance >= 0; distance -= 1) { IntVec3 newTarget = pos.ToIntVec3(); if (!newTarget.Impassable(pawn.Map)) { Blink(newTarget); return; } pos -= dir; } Blink(pawn.Position); }
private float GetDistToCave(IntVec3 cell, List <IntVec3> group, Map map, float maxDist, bool treatOpenSpaceAsCave) { MapGenFloatGrid caves = MapGenerator.Caves; GenStep_Caves.tmpGroupSet.Clear(); GenStep_Caves.tmpGroupSet.AddRange(group); int num = GenRadial.NumCellsInRadius(maxDist); IntVec3[] radialPattern = GenRadial.RadialPattern; for (int i = 0; i < num; i++) { IntVec3 intVec = cell + radialPattern[i]; if (treatOpenSpaceAsCave && !GenStep_Caves.tmpGroupSet.Contains(intVec)) { goto IL_007b; } if (intVec.InBounds(map) && caves[intVec] > 0.0) { goto IL_007b; } continue; IL_007b: return(cell.DistanceTo(intVec)); } return(maxDist); }
public static bool IsAffectedByInstrument(ThingDef instrumentDef, IntVec3 instrumentPos, IntVec3 pawnPos, Map map) { if (instrumentPos.DistanceTo(pawnPos) < instrumentDef.building.instrumentRange) { return(instrumentPos.GetRoom(map) == pawnPos.GetRoom(map)); } return(false); }
public float GetArmorPenetrationAt(IntVec3 c) { if (!this.damageFalloff) { return(this.armorPenetration); } float t = c.DistanceTo(base.Position) / this.radius; return(Mathf.Lerp(this.armorPenetration, this.armorPenetration * 0.2f, t)); }
public int GetDamageAmountAt(IntVec3 c) { if (!this.damageFalloff) { return(this.damAmount); } float t = c.DistanceTo(base.Position) / this.radius; return(Mathf.Max(GenMath.RoundRandom(Mathf.Lerp((float)this.damAmount, (float)this.damAmount * 0.2f, t)), 1)); }
//New methods public int GetDamageAmountAtCE(IntVec3 c) //t => t^(0.333f) { if (!damageFalloff) { return(damAmount); } var t = c.DistanceTo(Position) / radius; t = Mathf.Pow(t, 0.333f); return(Mathf.Max(GenMath.RoundRandom(Mathf.Lerp((float)damAmount, DamageAtEdge, t)), 1)); }
public float GetArmorPenetrationAtCE(IntVec3 c) //t => t^(0.55f), penetrationAmount => damAmount * PressurePerDamage { var basePen = Mathf.Max(damAmount * PressurePerDamage, armorPenetration); if (!damageFalloff) { return(basePen); } var t = c.DistanceTo(Position) / radius; t = Mathf.Pow(t, 0.55f); return(Mathf.Lerp(basePen, PenAtEdge, t)); }
private void DamageCloseThings() { int num = GenRadial.NumCellsInRadius(3f); for (int i = 0; i < num; i++) { IntVec3 intVec = base.Position + GenRadial.RadialPattern[i]; if (intVec.InBounds(base.Map) && !this.CellImmuneToDamage(intVec)) { Pawn firstPawn = intVec.GetFirstPawn(base.Map); if (firstPawn == null || !firstPawn.Downed || !Rand.Bool) { float damageFactor = GenMath.LerpDouble(0f, 3f, 1f, 0.2f, intVec.DistanceTo(base.Position)); this.DoDamage(intVec, damageFactor); } } } }
private float GetDistToCave(IntVec3 cell, List <IntVec3> group, Map map, float maxDist, bool treatOpenSpaceAsCave) { MapGenFloatGrid caves = MapGenerator.Caves; tmpGroupSet.Clear(); tmpGroupSet.AddRange(group); int cellCount = GenRadial.NumCellsInRadius(maxDist); IntVec3[] radialPattern = GenRadial.RadialPattern; for (int i = 0; i < cellCount; i++) { IntVec3 loc = cell + radialPattern[i]; if ((treatOpenSpaceAsCave && !tmpGroupSet.Contains(loc)) || (loc.InBounds(map) && caves[loc] > 0f)) { return(cell.DistanceTo(loc)); } } return(maxDist); }
private float GetDistToCave(IntVec3 cell, List <IntVec3> group, Map map, float maxDist, bool treatOpenSpaceAsCave) { MapGenFloatGrid caves = MapGenerator.Caves; GenStep_ElevateEvelationForUnderground.tmpGroupSet.Clear(); GenStep_ElevateEvelationForUnderground.tmpGroupSet.AddRange(group); int num = GenRadial.NumCellsInRadius(maxDist); IntVec3[] radialPattern = GenRadial.RadialPattern; for (int i = 0; i < num; i++) { IntVec3 intVec = cell + radialPattern[i]; if ((treatOpenSpaceAsCave && !GenStep_ElevateEvelationForUnderground.tmpGroupSet.Contains(intVec)) || (intVec.InBounds(map) && caves[intVec] > 0f)) { return(cell.DistanceTo(intVec)); } } return(maxDist); }
public void RenderPriorityMarks() { if (Find.CurrentMap == null) { return; } Map map = Find.CurrentMap; IntVec3 mouseAt = UI.MouseCell(); CellRect cameraRect = Find.CameraDriver.CurrentViewRect; cameraRect.ClipInsideMap(map); cameraRect = cameraRect.ExpandedBy(1); List <Thing> newDrawLabels = new List <Thing>(); foreach (Thing t in map.GetPriorityData().RenderCache.ThingCache) { if (t.DestroyedOrNull()) { continue; } IntVec3 pos = t.Position; if (cameraRect.Contains(pos)) { DrawPriorityMarkTo(t); if (mouseAt.DistanceTo(pos) < 9f) { newDrawLabels.Add(t); } } } toDrawLabels = newDrawLabels; }
public LocalTargetInfo GetDestination(LocalTargetInfo target) { Map map = parent.pawn.Map; switch (Props.destination) { case AbilityEffectDestination.Caster: return(new LocalTargetInfo(parent.pawn.InteractionCell)); case AbilityEffectDestination.RandomInRange: { cells.Clear(); int num = GenRadial.NumCellsInRadius(Props.randomRange.max); for (int i = 0; i < num; i++) { IntVec3 intVec = GenRadial.RadialPattern[i]; if (!(intVec.DistanceTo(IntVec3.Zero) < Props.randomRange.min)) { IntVec3 intVec2 = target.Cell + intVec; if (intVec2.Standable(map) && (!Props.requiresLineOfSight || GenSight.LineOfSight(target.Cell, intVec2, map))) { cells.Add(intVec2); } } } if (cells.Any()) { return(new LocalTargetInfo(cells.RandomElement())); } Messages.Message("NoValidDestinationFound".Translate(parent.def.LabelCap), MessageTypeDefOf.RejectInput); return(LocalTargetInfo.Invalid); } case AbilityEffectDestination.Selected: return(target); default: throw new ArgumentOutOfRangeException(); } }
private bool CanUseSpot(Pawn pawn, LocalTargetInfo spot) { IntVec3 cell = spot.Cell; if (cell.DistanceTo(parent.Position) > 3.9f) { return(false); } if (!cell.Standable(parent.Map)) { return(false); } if (!GenSight.LineOfSight(cell, parent.Position, parent.Map)) { return(false); } if (!pawn.CanReach(spot, PathEndMode.OnCell, Danger.Deadly)) { return(false); } return(true); }
private void AffectCell(IntVec3 c) { var flag = ShouldCellBeAffectedOnlyByDamage(c); if (!flag && Rand.Chance(preExplosionSpawnChance) && c.Walkable(Map)) { TrySpawnExplosionThing(preExplosionSpawnThingDef, c, preExplosionSpawnThingCount); } damType.Worker.ExplosionAffectCell(this, c, damagedThings, !flag); if (!flag && Rand.Chance(postExplosionSpawnChance) && c.Walkable(Map)) { TrySpawnExplosionThing(postExplosionSpawnThingDef, c, postExplosionSpawnThingCount); } var num = chanceToStartFire; if (damageFalloff) { num *= Mathf.Lerp(1f, (float)DamageAtEdge / damAmount, c.DistanceTo(Position) / radius); } if (Rand.Chance(num)) { FireUtility.TryStartFireIn(c, Map, Rand.Range(0.1f, 0.925f)); } }
public void GenerateQuad(IntVec3 CenterCell, Rot4 rot, List <IntVec3> QuadCells, float entranceChance, float radius, int minCaves) { Map map = BaseGen.globalSettings.map; List <IntVec3> nodes = new List <IntVec3>(); nodes.Add(CenterCell); // Log.Message("Generatirng " + rot.ToStringHuman().CapitalizeFirst() + " Quad Small Chambers"); Rand.PushState(); float dist2 = Rand.RangeInclusive(7, 10); Rand.PopState(); IntVec3 BigCaveCenter = cellforbigcave.Where(x => !bigCaveCenters.Any(y => x.DistanceTo(y) < 20)).RandomElement(); nodes.Add(BigCaveCenter); bigCaveCenters.Add(BigCaveCenter); List <IntVec3> BigCavecells = GenRadial.RadialCellsAround(BigCaveCenter, dist2, true).ToList(); cavecells.AddRange(BigCavecells); // Log.Message("Generatirng "+rot.ToStringHuman().CapitalizeFirst()+ " Quad Small Chambers"); Rand.PushState(); int cavecountSmall = Rand.RangeInclusive(minCaves, (int)radius / 10); Rand.PopState(); for (int i2 = 0; i2 < cavecountSmall; i2++) { Rand.PushState(); float dist = Rand.RangeInclusive(3, 6); Rand.PopState(); IntVec3 cell = cellforlittlecave.Where(x => !smallCaveCenters.Any(y => y.DistanceTo(x) < dist)).RandomElement(); nodes.Add(cell); smallCaveCenters.Add(cell); List <IntVec3> ccells = GenRadial.RadialCellsAround(cell, dist, true).ToList(); cavecells.AddRange(ccells); } Rand.PushState(); if (Rand.Chance(entranceChance)) { // Log.Message("Generatirng " + rot.ToStringHuman().CapitalizeFirst() + " Quad Entrance"); entranceChance -= 0.0f; float dist = Rand.RangeInclusive(3, 10); List <IntVec3> ecells = new List <IntVec3>(); ecells.AddRange(cells.Where(x => InQuad(x, CenterCell, rot) && GenRadial.RadialCellsAround(x, dist, true).Any(z => map.reachability.CanReachMapEdge(z, TraverseParms.For(TraverseMode.ByPawn))) && GenRadial.RadialCellsAround(x, dist, true).Any(z => QuadCells.Contains(z)))); IntVec3 cell = ecells.NullOrEmpty() ? IntVec3.Invalid : ecells.RandomElement(); if (cell != IntVec3.Invalid) { // nodes.Add(cell); List <IntVec3> ccells = GenRadial.RadialCellsAround(cell, dist, true).ToList(); cavecells.AddRange(ccells); entranceCaveCenters.Add(cell); List <IntVec3> tcells = nodes; /* * List<IntVec3> tcells = new List<IntVec3>(); * tcells.AddRange(smallCaveCenters); * tcells.AddRange(bigCaveCenters); */ List <IntVec3> ncells = new List <IntVec3>(); // ncells = tcells.Where(x => x.DistanceTo(CenterCell) < radius - 5 && !cell.WithinRegions(x, map, 10, TraverseParms.For(TraverseMode.ByPawn), RegionType.Set_Passable)).OrderBy(x => x.DistanceTo(cell)).ToList(); // Log.Message("Generatirng " + rot.ToStringHuman().CapitalizeFirst() + " Quad path " + ncells.Count + " Nodes located"); IntVec3 prevnode = cell; nodes.OrderByDescending(x => x.DistanceTo(prevnode)); for (int i = 0; i < nodes.Count; i++) { IntVec3 node = nodes[i]; IntVec3 offset = prevnode - node; float num = 0f; if ((prevnode.ToVector3() - node.ToVector3()).MagnitudeHorizontalSquared() > 0.001f) { num = (prevnode.ToVector3() - node.ToVector3()).AngleFlat(); } num += 90f; int trX = prevnode.x < node.x ? prevnode.x : node.x; int trY = prevnode.z < node.z ? prevnode.z : node.z; CellRect rect = new CellRect(trX, trY, (int)node.DistanceTo(prevnode), (int)node.DistanceTo(prevnode)); // Log.Message((i == 0 ? "Entrance at " : "Prevous node at ") + prevnode + " next node at " + node + " distance: " + node.DistanceTo(prevnode) + " Angele: " + num + " Bottom Left: " + rect.BottomLeft + " Top Right: " + rect.TopRight); Dig(prevnode, num, 3, rect.ToList(), map, closed: false); prevnode = node; } } else { Log.Warning("Generatirng " + rot.ToStringHuman().CapitalizeFirst() + " Quad Entrance, no suitable cell found out of " + ecells.Count + " potential targets"); } } Rand.PopState(); cellforlittlecave.RemoveAll(x => QuadCells.Contains(x)); cellforbigcave.RemoveAll(x => QuadCells.Contains(x)); }
private void Dig(IntVec3 start, float dir, float width, List <IntVec3> group, Map map, bool closed, HashSet <IntVec3> visited = null) { Vector3 vect = start.ToVector3Shifted(); float distcovered = 0f; IntVec3 intVec = start; float num = 0f; MapGenFloatGrid elevation = MapGenerator.Elevation; MapGenFloatGrid caves = MapGenerator.Caves; bool flag = false; bool flag2 = false; if (visited == null) { visited = new HashSet <IntVec3>(); } tmpGroupSet.Clear(); tmpGroupSet.AddRange(group); int num2 = 0; while (true) { if (closed) { int num3 = GenRadial.NumCellsInRadius(width / 2f + 1.5f); for (int i = 0; i < num3; i++) { IntVec3 intVec2 = intVec + GenRadial.RadialPattern[i]; if (!visited.Contains(intVec2) && (!tmpGroupSet.Contains(intVec2))) { return; } } } if (num2 >= 15 && width > 1.8f + BranchedTunnelWidthOffset.max) { Rand.PushState(); if (!flag && Rand.Chance(0.05f)) { DigInBestDirection(intVec, dir, new FloatRange(40f, 90f), width - BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag = true; } if (!flag2 && Rand.Chance(0.05f)) { DigInBestDirection(intVec, dir, new FloatRange(-90f, -40f), width - BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag2 = true; } Rand.PopState(); } SetCaveAround(intVec, width, map, visited, out bool hitAnotherTunnel); if (hitAnotherTunnel) { // Log.Message(intVec + " hitAnotherTunnel"); break; } while (vect.ToIntVec3() == intVec) { vect += Vector3Utility.FromAngleFlat(dir) * 0.5f; num += 0.5f; } if (!tmpGroupSet.Contains(vect.ToIntVec3())) { // Log.Message(vect.ToIntVec3() + " not in group"); break; } IntVec3 intVec3 = new IntVec3(intVec.x, 0, vect.ToIntVec3().z); if (IsRock(intVec3, elevation, map)) { caves[intVec3] = Mathf.Max(caves[intVec3], width); visited.Add(intVec3); } cavecells.Add(intVec); // Log.Message(intVec + " added to cavecells, currently: "+ cavecells.Count); intVec = vect.ToIntVec3(); /* * // Log.Message(intVec + " added to cavecells, currently: " + cavecells.Count); * // Log.Message("Randomize angel Original: "+ dir); * // Log.Message("Randomize angel num: " + num); * // Log.Message("Randomize angel start.x: " + start.x); * // Log.Message("Randomize angel start.z: " + start.z); */ if (directionNoise == null) { Rand.PushState(); directionNoise = new Perlin(0.0020500000100582838, 2.0, 0.5, 4, Rand.Int, QualityMode.Medium); Rand.PopState(); } dir += (float)directionNoise.GetValue(num * 60f, (float)start.x * 200f, (float)start.z * 200f) * 8f; // Log.Message("angel = "+ dir); width -= 0.005f; // Log.Message("Tunneling heading: " + dir + ", current width: " + width); if (!(width < 1.4f)) { num2++; continue; } distcovered = start.DistanceTo(intVec); break; } // Log.Message("Tunneling from "+ start + " heading: " + dir +" Distance: " + distcovered + " complete"); }
public static Thing FindEquipment(Pawn pawn) { debugSb = null; AddDebugLine(string.Concat("JobDriver_AcquireEquipment.FindEquipment - Scanning for ", pawn, " at ", pawn.Position)); CompMeeseeksMemory compMeeseeksMemory = pawn.GetComp <CompMeeseeksMemory>(); if (compMeeseeksMemory == null || compMeeseeksMemory.savedJob == null || compMeeseeksMemory.savedJob.targetA == null || !compMeeseeksMemory.savedJob.targetA.IsValid) { if (DebugViewSettings.debugApparelOptimize) { AddDebugLine(string.Concat("Meeseeks, job or target invalid.")); Log.Message(debugSb.ToString()); debugSb = null; } return(null); } AddDebugLine(string.Concat(compMeeseeksMemory.savedJob.def.ToString())); if (Find.TickManager.TicksGame < compMeeseeksMemory.acquiredEquipmentTick + rescanEquipmentDelay) { if (DebugViewSettings.debugApparelOptimize) { AddDebugLine(string.Concat("Cannot find equipment for " + ((compMeeseeksMemory.acquiredEquipmentTick + rescanEquipmentDelay) - Find.TickManager.TicksGame).ToString() + " ticks.")); Log.Message(debugSb.ToString()); debugSb = null; } return(null); } List <SkillDef> relevantSkills = null; if (compMeeseeksMemory.savedJob.workGiverDef == null) { AddDebugLine(string.Concat("No workGiverDef")); relevantSkills = new List <SkillDef>(); } else { relevantSkills = new List <SkillDef>(compMeeseeksMemory.savedJob.workGiverDef.workType.relevantSkills); } // For some reason the entry for melee doesn't seem to get read for the kill job, so we'll do it manually... bool killJob = (compMeeseeksMemory.savedJob.def == MeeseeksDefOf.CM_Meeseeks_Box_Job_Kill); bool combatJob = (killJob || pawn.Drafted || compMeeseeksMemory.guardPosition.IsValid); if (compMeeseeksMemory.savedJob.def == JobDefOf.AttackMelee || combatJob) { relevantSkills.Add(SkillDefOf.Melee); } if (compMeeseeksMemory.savedJob.def == JobDefOf.AttackStatic || combatJob) { relevantSkills.Add(SkillDefOf.Shooting); } combatJob = (combatJob || (relevantSkills.Contains(SkillDefOf.Melee) || relevantSkills.Contains(SkillDefOf.Shooting))); AddDebugLine("combatJob == " + combatJob.ToString()); foreach (SkillDef skill in relevantSkills) { AddDebugLine(skill.defName); } // I mean this shouldn't be possible but... if (combatJob && pawn.RaceProps.Humanlike && pawn.WorkTagIsDisabled(WorkTags.Violent)) { return(null); } IntVec3 savedJobTarget = compMeeseeksMemory.savedJob.targetA.Cell; float distanceToTarget = savedJobTarget.DistanceTo(pawn.PositionHeld); float maxTotalDistance = distanceToTarget * 2.5f; float maxDistanceToEquipment = distanceToTarget * 0.75f; if (!killJob) { maxTotalDistance *= 2.0f; maxDistanceToEquipment *= 2.0f; } AddDebugLine("distanceToTarget: " + distanceToTarget.ToString()); AddDebugLine("maxTotalDistance: " + maxTotalDistance.ToString()); AddDebugLine("maxDistanceToEquipment: " + maxDistanceToEquipment.ToString()); bool isWeapon = (pawn.equipment.Primary == null); Thing selectedEquipment = null; float selectedEquipmentScore = 0.0f; List <Thing> availableEquipment = new List <Thing>(); if (isWeapon) { AddDebugLine("scanning for weapons..."); availableEquipment = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Weapon).Where(t => CanEquipThis(combatJob, pawn, compMeeseeksMemory, t, relevantSkills)).ToList(); } if (availableEquipment.Count == 0) { // If the weapon search fails, default to an apparel search isWeapon = false; AddDebugLine("scanning for apparel..."); availableEquipment = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel).Where(t => CanWearThis(pawn, compMeeseeksMemory, t, relevantSkills)).ToList(); } AddDebugLine("availableEquipment: " + availableEquipment.Count.ToString()); if (availableEquipment.Count == 0) { if (DebugViewSettings.debugApparelOptimize) { Log.Message(debugSb.ToString()); debugSb = null; } return(null); } foreach (Thing equippable in availableEquipment) { float distanceToEquippable = equippable.PositionHeld.DistanceTo(pawn.PositionHeld); float distanceEquippableToTarget = equippable.PositionHeld.DistanceTo(savedJobTarget); float totalDistance = distanceToTarget + distanceToEquippable + distanceEquippableToTarget; //AddDebugLine("distanceToEquippable: " + equippable.def.defName + " - " + distanceToEquippable); //AddDebugLine("distanceEquippableToTarget: " + equippable.def.defName + " - " + distanceEquippableToTarget); //AddDebugLine("totalDistance: " + equippable.def.defName + " - " + totalDistance); if (distanceToEquippable < maxDistanceToEquipment && totalDistance <= maxTotalDistance) { float equipmentScore = GetEquipmentScore(pawn, equippable, relevantSkills); float distanceFactor = totalDistance + 1.0f; equipmentScore = (equipmentScore * equipmentScore) / (distanceFactor * distanceFactor); //AddDebugLine("equipmentScore: " + equippable.def.defName + " - " + equipmentScore); if (DebugViewSettings.debugApparelOptimize && equipmentScore > 0.0f) { debugSb.AppendLine(equippable.LabelCap + ": " + equipmentScore.ToString("F2")); } if (equipmentScore > selectedEquipmentScore) { selectedEquipment = equippable; selectedEquipmentScore = equipmentScore; } } else { AddDebugLine("Too far away: " + equippable.GetUniqueLoadID()); } } AddDebugLine("BEST: " + selectedEquipment); if (DebugViewSettings.debugApparelOptimize) { Log.Message(debugSb.ToString()); debugSb = null; } if (selectedEquipment != null) { return(selectedEquipment); } return(null); }
private static int GetCellAffectTickReversed(Explosion explosion, int startTick, IntVec3 cell) { return(startTick + (int)((explosion.radius - cell.DistanceTo(explosion.Position)) * 1.5)); }
public Job TryOpportunisticJob(Job job) { Job result; if (this.pawn.def.race.intelligence < Intelligence.Humanlike) { result = null; } else if (this.pawn.Faction != Faction.OfPlayer) { result = null; } else if (this.pawn.Drafted) { result = null; } else if (job.playerForced) { result = null; } else if (this.pawn.RaceProps.intelligence < Intelligence.Humanlike) { result = null; } else if (!job.def.allowOpportunisticPrefix) { result = null; } else if (this.pawn.story.WorkTagIsDisabled(WorkTags.ManualDumb | WorkTags.Hauling)) { result = null; } else if (this.pawn.InMentalState) { result = null; } else { IntVec3 cell = job.targetA.Cell; if (!cell.IsValid) { result = null; } else { float num = this.pawn.Position.DistanceTo(cell); if (num < AITuning.OpportunisticJobMinDistPawnToDest) { result = null; } else { List <Thing> list = this.pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling(); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (this.pawn.Map.reservationManager.FirstRespectedReserver(thing, this.pawn) == null) { float num2 = this.pawn.Position.DistanceTo(thing.Position); if (num2 <= AITuning.OpportunisticJobMaxDistPawnToItem) { if (num2 <= num * AITuning.OpportunisticJobMaxPickupDistanceFactor) { if (num2 + thing.Position.DistanceTo(cell) <= num * AITuning.OpportunisticJobMaxRatioOppHaulDistanceToDestDistance) { if (HaulAIUtility.PawnCanAutomaticallyHaulFast(this.pawn, thing, false)) { StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing); IntVec3 invalid = IntVec3.Invalid; if (StoreUtility.TryFindBestBetterStoreCellFor(thing, this.pawn, this.pawn.Map, currentPriority, this.pawn.Faction, out invalid, true)) { float num3 = invalid.DistanceTo(cell); if (num3 <= AITuning.OpportunisticJobMaxDistDestToDropoff) { if (num3 <= num * AITuning.OpportunisticJobMaxDistDestToDropoffFactor) { if (num2 + thing.Position.DistanceTo(invalid) + num3 <= num * AITuning.OpportunisticJobMaxRatioOppHaulDistanceToDestDistance) { if (num2 + num3 <= num) { if (this.pawn.Position.WithinRegions(thing.Position, this.pawn.Map, AITuning.OpportunisticJobMaxPickupRegions, TraverseParms.For(this.pawn, Danger.Deadly, TraverseMode.ByPawn, false), RegionType.Set_Passable)) { if (invalid.WithinRegions(cell, this.pawn.Map, AITuning.OpportunisticJobMaxDropoffRegions, TraverseParms.For(this.pawn, Danger.Deadly, TraverseMode.ByPawn, false), RegionType.Set_Passable)) { if (DebugViewSettings.drawOpportunisticJobs) { Log.Message("Opportunistic job spawned", false); this.pawn.Map.debugDrawer.FlashLine(this.pawn.Position, thing.Position, 600, SimpleColor.Red); this.pawn.Map.debugDrawer.FlashLine(thing.Position, invalid, 600, SimpleColor.Green); this.pawn.Map.debugDrawer.FlashLine(invalid, cell, 600, SimpleColor.Blue); } return(HaulAIUtility.HaulToCellStorageJob(this.pawn, thing, invalid, false)); } } } } } } } } } } } } } result = null; } } } return(result); }
private void DamageCloseThings() { int num = GenRadial.NumCellsInRadius(2f); for (int i = 0; i < num; i++) { IntVec3 intVec = this.Position + GenRadial.RadialPattern[i]; if (this.Map != null) { if (intVec.InBounds(this.Map)) { Pawn firstPawn = intVec.GetFirstPawn(this.Map); if (firstPawn == null || !firstPawn.Downed || !Rand.Bool) { float damageFactor; //= GenMath.LerpDouble(0f, 4.2f, 1f, 0.2f, intVec.DistanceTo(this.Position)); //damageFactor = (UnityEngine.Random.Range(0f, 1f) * this.DamageAmount) * (2 - intVec.DistanceTo(this.Position)); damageFactor = Mathf.Max((float)(UnityEngine.Random.Range(0.5f, 1f) * this.DamageAmount * (2 - intVec.DistanceTo(this.Position))), 3f); //Verse.Log.Message(damageFactor.ToString() + "df", false); this.DoDamage(intVec, damageFactor); } } } } }
protected virtual void Explode() { Map map = base.Map; Destroy(DestroyMode.Vanish); if (base.def.projectile.explosionEffect != null) { Effecter effecter = base.def.projectile.explosionEffect.Spawn(); effecter.Trigger(new TargetInfo(base.Position, map, false), new TargetInfo(base.Position, map, false)); effecter.Cleanup(); } IntVec3 position = base.Position; Map map2 = map; float explosionRadius = base.def.projectile.explosionRadius; DamageDef damageDef = base.def.projectile.damageDef; Thing launcher = base.launcher; int damageAmount = base.DamageAmount; float armorPenetration = base.ArmorPenetration; SoundDef soundExplode = base.def.projectile.soundExplode; ThingDef equipmentDef = base.equipmentDef; ThingDef def = base.def; Thing thing = intendedTarget.Thing; ThingDef postExplosionSpawnThingDef = base.def.projectile.postExplosionSpawnThingDef; float postExplosionSpawnChance = base.def.projectile.postExplosionSpawnChance; int postExplosionSpawnThingCount = base.def.projectile.postExplosionSpawnThingCount; ThingDef preExplosionSpawnThingDef = base.def.projectile.preExplosionSpawnThingDef; foreach (Pawn pawn in map.mapPawns.AllPawns) { if (pawn.Dead) { continue; } try { if (position.DistanceTo(pawn.Position) <= explosionRadius) { pawn.health.AddHediff(HediffDef.Named("LethalRadiationPoisoning")); } } catch (Exception e) { Log.Message(e.ToString()); continue; } } IEnumerable <IntVec3> radius = GenRadial.RadialCellsAround(position, explosionRadius, true); for (int i = 0; i < 3; i++) { foreach (IntVec3 pos in radius) { IEnumerable <Thing> thingsToDestroy = map.thingGrid.ThingsAt(pos); foreach (Thing thingToDestroy in thingsToDestroy) { thingToDestroy.Destroy(); } } } GenExplosion.DoExplosion(position, map2, explosionRadius, damageDef, launcher, damageAmount, armorPenetration, soundExplode, equipmentDef, def, thing, postExplosionSpawnThingDef, postExplosionSpawnChance, postExplosionSpawnThingCount, base.def.projectile.applyDamageToExplosionCellsNeighbors, preExplosionSpawnThingDef, base.def.projectile.preExplosionSpawnChance, base.def.projectile.preExplosionSpawnThingCount, base.def.projectile.explosionChanceToStartFire, base.def.projectile.explosionDamageFalloff); }
private float <StartRandomFireAndDoFlameDamage> m__1(IntVec3 x) { return(1f - Mathf.Min(x.DistanceTo(base.Position) / 15f, 1f) + 0.05f); }
private float BlightChanceFactor(IntVec3 c, IntVec3 root) { return(Mathf.InverseLerp(15f, 7.5f, c.DistanceTo(root))); }
public Job TryOpportunisticJob(Job job) { if ((int)pawn.def.race.intelligence < 2) { return(null); } if (pawn.Faction != Faction.OfPlayer) { return(null); } if (pawn.Drafted) { return(null); } if (job.playerForced) { return(null); } if ((int)pawn.RaceProps.intelligence < 2) { return(null); } if (!job.def.allowOpportunisticPrefix) { return(null); } if (pawn.WorkTagIsDisabled(WorkTags.ManualDumb | WorkTags.Hauling)) { return(null); } if (pawn.InMentalState || pawn.IsBurning()) { return(null); } IntVec3 cell = job.targetA.Cell; if (!cell.IsValid || cell.IsForbidden(pawn)) { return(null); } float num = pawn.Position.DistanceTo(cell); if (num < 3f) { return(null); } List <Thing> list = pawn.Map.listerHaulables.ThingsPotentiallyNeedingHauling(); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; float num2 = pawn.Position.DistanceTo(thing.Position); if (num2 > 30f || num2 > num * 0.5f || num2 + thing.Position.DistanceTo(cell) > num * 1.7f || pawn.Map.reservationManager.FirstRespectedReserver(thing, pawn) != null || thing.IsForbidden(pawn) || !HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, thing, forced: false)) { continue; } StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(thing); IntVec3 foundCell = IntVec3.Invalid; if (!StoreUtility.TryFindBestBetterStoreCellFor(thing, pawn, pawn.Map, currentPriority, pawn.Faction, out foundCell)) { continue; } float num3 = foundCell.DistanceTo(cell); if (!(num3 > 50f) && !(num3 > num * 0.6f) && !(num2 + thing.Position.DistanceTo(foundCell) + num3 > num * 1.7f) && !(num2 + num3 > num) && pawn.Position.WithinRegions(thing.Position, pawn.Map, 25, TraverseParms.For(pawn)) && foundCell.WithinRegions(cell, pawn.Map, 25, TraverseParms.For(pawn))) { if (DebugViewSettings.drawOpportunisticJobs) { Log.Message("Opportunistic job spawned"); pawn.Map.debugDrawer.FlashLine(pawn.Position, thing.Position, 600, SimpleColor.Red); pawn.Map.debugDrawer.FlashLine(thing.Position, foundCell, 600, SimpleColor.Green); pawn.Map.debugDrawer.FlashLine(foundCell, cell, 600, SimpleColor.Blue); } return(HaulAIUtility.HaulToCellStorageJob(pawn, thing, foundCell, fitInStoreCell: false)); } } return(null); }