public static bool RegrowIfBeehouseNearby(ref Plant __instance) { if (__instance.def.plant.HarvestDestroys && __instance.def.plant.Sowable && !__instance.def.plant.IsTree) { int num = GenRadial.NumCellsInRadius(6); for (int i = 0; i < num; i++) { IntVec3 current = __instance.Position + GenRadial.RadialPattern[i]; if (current.InBounds(__instance.Map)) { Building getbeehouse = current.GetEdifice(__instance.Map); if ((getbeehouse != null) && ((getbeehouse.def.defName == "RB_Beehouse") || (getbeehouse.def.defName == "RB_AdvancedClimatizedBeehouse") || (getbeehouse.def.defName == "RB_ClimatizedBeehouse") || (getbeehouse.def.defName == "RB_AdvancedBeehouse"))) { Building_Beehouse thebeehouse = (Building_Beehouse)getbeehouse; if (thebeehouse.BeehouseIsRunning) { Random random = new Random(); if (random.NextDouble() > 0.75) { Thing thing = ThingMaker.MakeThing(ThingDef.Named(__instance.def.defName), null); Plant plant = (Plant)thing; GenSpawn.Spawn(plant, __instance.Position, __instance.Map); plant.Growth = 0.25f; __instance.Map.mapDrawer.MapMeshDirty(__instance.Position, MapMeshFlag.Things); return(true); } } } } } return(true); } else { return(true); } }
private static float FriendlyFireBlastRadiusTargetScoreOffset(IAttackTarget target, IAttackTargetSearcher searcher, Verb verb) { if (verb.verbProps.ai_AvoidFriendlyFireRadius <= 0f) { return(0f); } Map map = target.Thing.Map; IntVec3 position = target.Thing.Position; int num = GenRadial.NumCellsInRadius(verb.verbProps.ai_AvoidFriendlyFireRadius); float num2 = 0f; for (int i = 0; i < num; i++) { IntVec3 intVec = position + GenRadial.RadialPattern[i]; if (!intVec.InBounds(map)) { continue; } bool flag = true; List <Thing> thingList = intVec.GetThingList(map); for (int j = 0; j < thingList.Count; j++) { if (!(thingList[j] is IAttackTarget) || thingList[j] == target) { continue; } if (flag) { if (!GenSight.LineOfSight(position, intVec, map, skipFirstCell: true)) { break; } flag = false; } float num3 = (thingList[j] == searcher) ? 40f : ((!(thingList[j] is Pawn)) ? 10f : (thingList[j].def.race.Animal ? 7f : 18f)); num2 = ((!searcher.Thing.HostileTo(thingList[j])) ? (num2 - num3) : (num2 + num3 * 0.6f)); } } return(num2); }
public bool TryFindLinkSpot(Pawn pawn, out LocalTargetInfo spot) { spot = MeditationUtility.FindMeditationSpot(pawn).spot; if (CanUseSpot(pawn, spot)) { return(true); } int num = GenRadial.NumCellsInRadius(2.9f); int num2 = GenRadial.NumCellsInRadius(3.9f); for (int i = num; i < num2; i++) { IntVec3 c = parent.Position + GenRadial.RadialPattern[i]; if (CanUseSpot(pawn, c)) { spot = c; return(true); } } spot = IntVec3.Zero; return(false); }
public static List <IntVec3> GetGasVentArea(IntVec3 ventPos, Map map, float radius) { // simple flood fill implementation. // Note that we use this over GenRadial because that set of functions does // not and cannot take blockers into account (e.g. walls). // A FIFO flood fill will produce what is essentially a diamond pattern, if // unconstrained by walls. Ideally, we'd want to use a priority queue for // distance from the center, but that becomes tricky in a constrained sit- // uation, as you'd have to take line-of-sight into account. // return number of cells based on radius. var cellCount = GenRadial.NumCellsInRadius(radius); var room = ventPos.GetRoomGroup(map); // prep data structures _queue.Clear(); _cells.Clear(); _checked.Clear(); // start the process _queue.Enqueue(ventPos); _checked.Add(ventPos); while (_queue.Count > 0 && _cells.Count < cellCount) { var cell = _queue.Dequeue(); _cells.Add(cell); foreach (var adj in GenAdjFast.AdjacentCellsCardinal(cell) .Where(adj => !adj.Impassable(map) && !_checked.Contains(adj) && adj.GetRoomGroup(map) == room)) { _queue.Enqueue(adj); _checked.Add(adj); } } return(_cells.ToList()); }
public static void MakeRadialEffects(float radius, ThingDef mote, Vector3 loc, Map map, float scale, float directionAngle, float velocity, float rotationRate, float lookAngle, float solidTime, float fadeIn, float fadeOut, bool colorShift) { int num = GenRadial.NumCellsInRadius(radius); for (int i = 0; i < num; i++) { IntVec3 intVec = loc.ToIntVec3() + GenRadial.RadialPattern[i]; if (intVec.IsValid && intVec.InBounds(map)) { //-1 denotes "outward" from center if (directionAngle == -1) { directionAngle = (Quaternion.AngleAxis(90, Vector3.up) * GetVector(loc.ToIntVec3(), intVec)).ToAngleFlat(); } if (lookAngle == -1) { lookAngle = (Quaternion.AngleAxis(90, Vector3.up) * GetVector(loc.ToIntVec3(), intVec)).ToAngleFlat(); } EffectMaker.MakeEffect(mote, intVec.ToVector3Shifted(), map, scale, directionAngle, velocity, rotationRate, lookAngle, solidTime, fadeIn, fadeOut, false); } } }
public static IEnumerable <IntVec3> CellsToBurn(IntVec3 center, Map map, float radius, IntVec3?needLOSToCell1 = null, IntVec3?needLOSToCell2 = null) { List <IntVec3> openCells = new List <IntVec3>(); List <IntVec3> adjWallCells = new List <IntVec3>(); int num = GenRadial.NumCellsInRadius(radius); for (int i = 0; i < num; i++) { IntVec3 intVec = center + GenRadial.RadialPattern[i]; if (intVec.InBounds(map) && GenSight.LineOfSight(center, intVec, map, true, null, 0, 0)) { if (needLOSToCell1 != null || needLOSToCell2 != null) { bool flag = needLOSToCell1 != null && GenSight.LineOfSight(needLOSToCell1.Value, intVec, map, false, null, 0, 0); bool flag2 = needLOSToCell2 != null && GenSight.LineOfSight(needLOSToCell2.Value, intVec, map, false, null, 0, 0); if (!flag && !flag2) { continue; } } openCells.Add(intVec); } } foreach (IntVec3 intVec2 in openCells) { if (intVec2.Walkable(map)) { for (int k = 0; k < 4; k++) { IntVec3 intVec3 = intVec2 + GenAdj.CardinalDirections[k]; if (intVec3.InHorDistOf(center, radius) && intVec3.InBounds(map) && !intVec3.Standable(map) && intVec3.GetEdifice(map) != null && !openCells.Contains(intVec3) && adjWallCells.Contains(intVec3)) { adjWallCells.Add(intVec3); } } } } return(openCells.Concat(adjWallCells)); }
public override void Impact_Override(Thing hitThing) { base.Impact_Override(hitThing); if (hitThing is Pawn p && p.BloodNeed() is Need_Blood bn) { GenExplosion.DoExplosion(p.PositionHeld, p.MapHeld, 3.9f, DamageDefOf.Flame, p); bn.AdjustBlood(-7); int num = GenRadial.NumCellsInRadius(3.9f); for (int i = 0; i < num; i++) { FilthMaker.TryMakeFilth(hitThing.PositionHeld + GenRadial.RadialPattern[i], hitThing.MapHeld, ((Pawn)hitThing).RaceProps.BloodDef, ((Pawn)hitThing).LabelIndefinite()); } List <BodyPartRecord> parts = p.health.hediffSet.GetNotMissingParts().ToList().FindAll(x => x.depth == BodyPartDepth.Inside); for (int j = 0; j < 4; j++) { if (!p.Dead) { p.TakeDamage(new DamageInfo(DamageDefOf.Burn, Rand.Range(8, 13), 1f, -1, Caster, parts.RandomElement())); } } } }
private void SetCaveAround(IntVec3 around, float tunnelWidth, Map map, HashSet <IntVec3> visited, out bool hitAnotherTunnel) { hitAnotherTunnel = false; int num = GenRadial.NumCellsInRadius(tunnelWidth / 2f); MapGenFloatGrid elevation = MapGenerator.Elevation; MapGenFloatGrid caves = MapGenerator.Caves; for (int i = 0; i < num; i++) { IntVec3 intVec = around + GenRadial.RadialPattern[i]; if (IsRock(intVec, elevation, map)) { if (caves[intVec] > 0f && !visited.Contains(intVec)) { hitAnotherTunnel = true; } caves[intVec] = Mathf.Max(caves[intVec], tunnelWidth); visited.Add(intVec); } cavecells.Add(intVec); } }
private static float FriendlyFireShootingTargetScoreOffset(IAttackTarget target, IAttackTargetSearcher searcher, Verb verb) { if (verb.verbProps.ai_AvoidFriendlyFireRadius <= 0.0) { return(0f); } Map map = target.Thing.Map; IntVec3 position = target.Thing.Position; int num = GenRadial.NumCellsInRadius(verb.verbProps.ai_AvoidFriendlyFireRadius); float num2 = 0f; for (int i = 0; i < num; i++) { IntVec3 intVec = position + GenRadial.RadialPattern[i]; if (intVec.InBounds(map)) { bool flag = true; List <Thing> thingList = intVec.GetThingList(map); for (int j = 0; j < thingList.Count; j++) { if (thingList[j] is IAttackTarget && thingList[j] != target) { if (flag) { if (!GenSight.LineOfSight(position, intVec, map, true, null, 0, 0)) { break; } flag = false; } float num3 = (float)((thingList[j] != searcher) ? ((!(thingList[j] is Pawn)) ? 10.0 : ((!thingList[j].def.race.Animal) ? 18.0 : 7.0)) : 40.0); num2 = (float)((!searcher.Thing.HostileTo(thingList[j])) ? (num2 - num3) : (num2 + num3 * 0.60000002384185791)); } } } } return(Mathf.Min(num2, 0f)); }
private static FloatMenuOption GotoLocationOption(IntVec3 clickCell, Pawn pawn) { int num = GenRadial.NumCellsInRadius(2.9f); IntVec3 curLoc; for (int i = 0; i < num; i++) { curLoc = GenRadial.RadialPattern[i] + clickCell; if (curLoc.Standable(pawn.Map)) { if (curLoc != pawn.Position) { if (!pawn.CanReach(curLoc, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)) { return(new FloatMenuOption("CannotGoNoPath".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null)); } Action action = delegate { IntVec3 intVec = RCellFinder.BestOrderedGotoDestNear(curLoc, pawn); Job job = new Job(JobDefOf.Goto, intVec); if (pawn.Map.exitMapGrid.IsExitCell(UI.MouseCell())) { job.exitMapOnArrival = true; } if (pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc)) { MoteMaker.MakeStaticMote(intVec, pawn.Map, ThingDefOf.Mote_FeedbackGoto, 1f); } }; FloatMenuOption floatMenuOption = new FloatMenuOption("GoHere".Translate(), action, MenuOptionPriority.GoHere, null, null, 0f, null, null); floatMenuOption.autoTakeable = true; return(floatMenuOption); } return(null); } } return(null); }
public static float GetAquaticCellsProportionInRadius(IntVec3 position, Map map, float radius) { if (radius <= 0) { return(0f); } float aquaticCellsNumber = 0; foreach (IntVec3 cell in GenRadial.RadialCellsAround(position, radius, true)) { if (cell.InBounds(map) == false) { continue; } if (IsAquaticTerrain(map, cell)) { aquaticCellsNumber++; } } float aquaticCellsNumberProportion = aquaticCellsNumber / (float)GenRadial.NumCellsInRadius(radius); return(aquaticCellsNumberProportion); }
public static IEnumerable <IntVec3> circularSectorCellsStartedCaster(IntVec3 center, Map map, IntVec3 target, float radius, float angle, bool useCenter = false) { int cellCount = GenRadial.NumCellsInRadius(radius); float currentDirectionAngle = Vector3Utility.AngleFlat(target.ToVector3Shifted() - center.ToVector3Shifted()); float angleMin = AngleWrapped(currentDirectionAngle - angle * 0.5f); float angleMax = AngleWrapped(angleMin + angle); if (useCenter) { yield return(GenRadial.RadialPattern[0] + center); } for (int i = 1; i < cellCount; i++) { IntVec3 cell = GenRadial.RadialPattern[i] + center; float targetCellAngle = Vector3Utility.AngleFlat(cell.ToVector3Shifted() - center.ToVector3Shifted()); bool flag = (angleMin > angleMax) ? (targetCellAngle >= angleMin || targetCellAngle <= angleMax) : (targetCellAngle >= angleMin && targetCellAngle <= angleMax); if (GenGrid.InBounds(cell, map) && Verse.GenSight.LineOfSight(center, cell, map, true) && flag) { yield return(cell); } } yield break; }
public void Init() { HashSet <IntVec3> centers = new HashSet <IntVec3>(Find.CurrentMap.listerThings.ThingsOfDef(CoverageDef()).Select(t => t.Position)); centers.AddRange(Find.CurrentMap.listerThings.ThingsInGroup(ThingRequestGroup.Blueprint) .Where(bp => GenConstruct.BuiltDefOf(bp.def) == CoverageDef()).Select(t => t.Position).ToList()); centers.AddRange(Find.CurrentMap.listerThings.ThingsInGroup(ThingRequestGroup.BuildingFrame) .Where(frame => GenConstruct.BuiltDefOf(frame.def) == CoverageDef()).Select(t => t.Position).ToList()); covered.Clear(); float radius = Radius(); foreach (IntVec3 center in centers) { int num = GenRadial.NumCellsInRadius(radius); for (int i = 0; i < num; i++) { covered.Add(center + GenRadial.RadialPattern[i]); } } }
public virtual void Effect() { CasterPawn.Drawer.Notify_DebugAffected(); MoteMaker.ThrowText(CasterPawn.DrawPos, CasterPawn.Map, AbilityUser.StringsToTranslate.AU_CastSuccess); int num = GenRadial.NumCellsInRadius(3.9f); for (int i = 0; i < num; i++) { IntVec3 curCell = CasterPawn.PositionHeld + GenRadial.RadialPattern[i]; if (curCell.GetThingList(CasterPawn.MapHeld) is List <Thing> things && !things.NullOrEmpty()) { List <Thing> temp = new List <Thing>(things); foreach (Thing t in temp) { if (t.def.defName == "FilthBlood") { CasterPawn.BloodNeed().AdjustBlood(1); t.Destroy(); } } } } }
public static bool TryDrawFiringCone(IntVec3 centre, Rot4 rot, float distance, float arc) { if (!(arc < 360)) { return(false); } if (distance > GenRadial.MaxRadialPatternRadius) { if ((bool)NonPublicFields.GenDraw_maxRadiusMessaged.GetValue(null)) { return(false); } Log.Error("Cannot draw radius ring of radius " + distance + ": not enough squares in the precalculated list."); NonPublicFields.GenDraw_maxRadiusMessaged.SetValue(null, true); return(false); } var ringDrawCells = (List <IntVec3>)NonPublicFields.GenDraw_ringDrawCells.GetValue(null); ringDrawCells.Clear(); var num = GenRadial.NumCellsInRadius(distance); for (var i = 0; i < num; i++) { var curCell = centre + GenRadial.RadialPattern[i]; if (curCell.WithinFiringArcOf(centre, rot, arc)) { ringDrawCells.Add(curCell); } } GenDraw.DrawFieldEdges(ringDrawCells); return(true); }
public bool EnoughAmmoAround(Building_TurretGunCE turret) { //Prevent ammo being dropped as a result of the turret being reloaded at the time if (turret.isReloading || turret.FullMagazine) { return(true); } var ammoComp = turret.CompAmmo; int num = GenRadial.NumCellsInRadius(20f); int num2 = ammoComp.CurMagCount; int num3 = Mathf.CeilToInt((float)ammoComp.Props.magazineSize / 6f); for (int i = 0; i < num; i++) { IntVec3 c = parent.Position + GenRadial.RadialPattern[i]; if (c.InBounds(parent.Map)) { List <Thing> thingList = c.GetThingList(parent.Map); for (int j = 0; j < thingList.Count; j++) { if ((ammoComp != null && ammoComp.CurrentAmmo == thingList[j].def)) { num2 += thingList[j].stackCount; if (num2 > num3) { return(true); } } } } } return(false); }
private bool InSellablePosition(Thing t, out string reason) { if (!t.Spawned) { reason = null; return(false); } if (t.Position.Fogged(t.Map)) { reason = null; return(false); } Room room = t.GetRoom(); if (room != null) { int num = GenRadial.NumCellsInRadius(6.9f); for (int i = 0; i < num; i++) { IntVec3 intVec = t.Position + GenRadial.RadialPattern[i]; if (!intVec.InBounds(t.Map) || intVec.GetRoom(t.Map) != room) { continue; } List <Thing> thingList = intVec.GetThingList(t.Map); for (int j = 0; j < thingList.Count; j++) { if (thingList[j].PreventPlayerSellingThingsNearby(out reason)) { return(false); } } } } reason = null; return(true); }
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; Plant plant; bool result; if (!this.TryFindRandomBlightablePlant(map, out plant)) { result = false; } else { Room room = plant.GetRoom(RegionType.Set_Passable); plant.CropBlighted(); int i = 0; int num = GenRadial.NumCellsInRadius(16f); while (i < num) { IntVec3 intVec = plant.Position + GenRadial.RadialPattern[i]; if (intVec.InBounds(map) && intVec.GetRoom(map, RegionType.Set_Passable) == room) { Plant firstBlightableNowPlant = BlightUtility.GetFirstBlightableNowPlant(intVec, map); if (firstBlightableNowPlant != null && firstBlightableNowPlant != plant) { if (Rand.Chance(0.1f * this.BlightChanceFactor(firstBlightableNowPlant.Position, plant.Position))) { firstBlightableNowPlant.CropBlighted(); } } } i++; } Find.LetterStack.ReceiveLetter("LetterLabelCropBlight".Translate(), "LetterCropBlight".Translate(), LetterDefOf.NegativeEvent, new TargetInfo(plant.Position, map, false), null, null); result = true; } return(result); }
// Token: 0x060029E2 RID: 10722 RVA: 0x0013D1E4 File Offset: 0x0013B5E4 public void CalculateNextHiveLikeSpawnTick() { Room room = this.parent.GetRoom(RegionType.Set_Passable); int num = 0; int num2 = GenRadial.NumCellsInRadius(9f); for (int i = 0; i < num2; i++) { IntVec3 intVec = this.parent.Position + GenRadial.RadialPattern[i]; if (intVec.InBounds(this.parent.Map)) { if (intVec.GetRoom(this.parent.Map, RegionType.Set_Passable) == room) { if (intVec.GetThingList(this.parent.Map).Any((Thing t) => t is HiveLike)) { num++; } } } } float num3 = this.Props.ReproduceRateFactorFromNearbyHiveCountCurve.Evaluate((float)num); this.nextHiveSpawnTick = Find.TickManager.TicksGame + (int)(this.Props.HiveSpawnIntervalDays.RandomInRange * 60000f / (num3 * Find.Storyteller.difficulty.enemyReproductionRateFactor)); }
public void CalculateNextHiveSpawnTick() { Room room = this.parent.GetRoom(RegionType.Set_Passable); int num = 0; int num2 = GenRadial.NumCellsInRadius(9f); for (int i = 0; i < num2; i++) { IntVec3 intVec = this.parent.Position + GenRadial.RadialPattern[i]; if (intVec.InBounds(this.parent.Map)) { if (intVec.GetRoom(this.parent.Map, RegionType.Set_Passable) == room) { if (intVec.GetThingList(this.parent.Map).Any((Thing t) => t is Hive)) { num++; } } } } float num3 = GenMath.LerpDouble(0f, 7f, 1f, 0.35f, (float)Mathf.Clamp(num, 0, 7)); this.nextHiveSpawnTick = Find.TickManager.TicksGame + (int)(this.Props.HiveSpawnIntervalDays.RandomInRange * 60000f / (num3 * Find.Storyteller.difficulty.enemyReproductionRateFactor)); }
public void DoFlyingObjectDamage() { IntVec3 center = this.ExactPosition.ToIntVec3(); int num = GenRadial.NumCellsInRadius(this.attackRadius); for (int i = 0; i < num; i++) { IntVec3 intVec = center + GenRadial.RadialPattern[i]; if (intVec.IsValid && intVec.InBounds(base.Map)) { List <Thing> hitList = intVec.GetThingList(base.Map); for (int j = 0; j < hitList.Count(); j++) { if (hitList[j] is Pawn) { if (hitList[j].Faction != this.pawn.Faction) { DamageEntities(hitList[j], WizardryDefOf.LotRW_HauntDD.defaultDamage, WizardryDefOf.LotRW_HauntDD); } } } } } }
private bool SaturatedAt(IntVec3 c, float plantDensity, bool cavePlants, float wholeMapNumDesiredPlants) { int num = GenRadial.NumCellsInRadius(20f); float num2 = wholeMapNumDesiredPlants * ((float)num / (float)this.map.Area); bool result; if (num2 <= 4f || !this.map.Biome.wildPlantsCareAboutLocalFertility) { result = ((float)this.map.listerThings.ThingsInGroup(ThingRequestGroup.Plant).Count >= wholeMapNumDesiredPlants); } else { float numDesiredPlantsLocally = 0f; int numPlants = 0; RegionTraverser.BreadthFirstTraverse(c, this.map, (Region from, Region to) => c.InHorDistOf(to.extentsClose.ClosestCellTo(c), 20f), delegate(Region reg) { numDesiredPlantsLocally += this.GetDesiredPlantsCountIn(reg, c, plantDensity); numPlants += reg.ListerThings.ThingsInGroup(ThingRequestGroup.Plant).Count; return(false); }, 999999, RegionType.Set_Passable); result = ((float)numPlants >= numDesiredPlantsLocally); } return(result); }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); RadialCellCount = GenRadial.NumCellsInRadius(def.specialDisplayRadius); }
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"); }
/// <summary> /// Tries the cast shot. /// </summary> /// <returns></returns> protected override bool TryCastShot() { if (currentTarget.HasThing && currentTarget.Thing.Map != caster.Map) { return(false); } ThingDef projectile = Projectile; if (projectile == null) { return(false); } ShootLine resultingLine; bool flag = TryFindShootLineFromTo(caster.Position, currentTarget, out resultingLine); if (verbProps.stopBurstWithoutLos && !flag) { return(false); } if (base.EquipmentSource != null) { base.EquipmentSource.GetComp <CompChangeableProjectile>()?.Notify_ProjectileLaunched(); } Thing launcher = caster; Thing equipment = base.EquipmentSource; CompMannable compMannable = caster.TryGetComp <CompMannable>(); if (compMannable != null && compMannable.ManningPawn != null) { launcher = compMannable.ManningPawn; equipment = caster; } Vector3 drawPos = caster.DrawPos; Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, resultingLine.Source, caster.Map); if (verbProps.forcedMissRadius > 0.5f) { float num = VerbUtility.CalculateAdjustedForcedMiss(verbProps.forcedMissRadius, currentTarget.Cell - caster.Position); if (num > 0.5f) { int max = GenRadial.NumCellsInRadius(num); int num2 = Rand.Range(0, max); if (num2 > 0) { IntVec3 c = currentTarget.Cell + GenRadial.RadialPattern[num2]; ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld; if (Rand.Chance(0.5f)) { projectileHitFlags = ProjectileHitFlags.All; } if (!canHitNonTargetPawnsNow) { projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns; } projectile2.Launch(launcher, drawPos, c, currentTarget, projectileHitFlags, equipment); return(true); } } } ShotReport shotReport = ShotReport.HitReportFor(caster, this, currentTarget); Thing randomCoverToMissInto = shotReport.GetRandomCoverToMissInto(); ThingDef targetCoverDef = randomCoverToMissInto?.def; //never miss ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget; if (currentTarget.Thing != null) { projectile2.Launch(launcher, drawPos, currentTarget, currentTarget, projectileHitFlags4, equipment, targetCoverDef); } else { projectile2.Launch(launcher, drawPos, resultingLine.Dest, currentTarget, projectileHitFlags4, equipment, targetCoverDef); } return(true); }
protected virtual void FireTurret(VehicleTurret turret) { float horizontalOffset = turret.turretDef.projectileShifting.NotNullAndAny() ? turret.turretDef.projectileShifting[turret.CurrentTurretFiring] : 0; Vector3 launchPos = TurretLocation(turret) + new Vector3(horizontalOffset, 1f, turret.turretDef.projectileOffset); Vector3 targetPos = Target(turret); float range = Vector3.Distance(TurretLocation(turret), targetPos); IntVec3 target = targetPos.ToIntVec3() + GenRadial.RadialPattern[Rand.Range(0, GenRadial.NumCellsInRadius(turret.CurrentFireMode.spreadRadius * (range / turret.turretDef.maxRange)))]; if (turret.CurrentTurretFiring >= turret.turretDef.projectileShifting.Count) { turret.CurrentTurretFiring = 0; } ThingDef projectile; if (turret.turretDef.ammunition != null && !turret.turretDef.genericAmmo) { projectile = turret.loadedAmmo?.projectileWhenLoaded; } else { projectile = turret.turretDef.projectile; } try { float speedTicksPerTile = projectile.projectile.SpeedTilesPerTick; if (turret.turretDef.projectileSpeed > 0) { speedTicksPerTile = turret.turretDef.projectileSpeed; } ProjectileSkyfaller projectile2 = ProjectileSkyfallerMaker.WrapProjectile(ProjectileSkyfallerDefOf.ProjectileSkyfaller, projectile, this, launchPos, target.ToVector3Shifted(), speedTicksPerTile); //REDO - RANDOMIZE TARGETED CELLS GenSpawn.Spawn(projectile2, target.ClampInsideMap(Map), Map); if (turret.turretDef.ammunition != null) { turret.ConsumeShellChambered(); } if (turret.turretDef.cannonSound != null) { turret.turretDef.cannonSound.PlayOneShot(new TargetInfo(Position, Map, false)); } turret.PostTurretFire(); } catch (Exception ex) { Log.Error($"Exception when firing Cannon: {turret.turretDef.LabelCap} on Pawn: {vehicle.LabelCap}. Exception: {ex.Message}"); } }
private void TryExpandSnow() { if (this.parent.Map.mapTemperature.OutdoorTemp > 10f) { this.snowRadius = 0f; } else { if (this.snowNoise == null) { this.snowNoise = new Perlin(0.054999999701976776, 2.0, 0.5, 5, Rand.Range(0, 651431), QualityMode.Medium); } if (this.snowRadius < 8f) { this.snowRadius += 1.3f; } else if (this.snowRadius < 17f) { this.snowRadius += 0.7f; } else if (this.snowRadius < 30f) { this.snowRadius += 0.4f; } else { this.snowRadius += 0.1f; } this.snowRadius = Mathf.Min(this.snowRadius, this.Props.maxRadius); CellRect occupiedRect = this.parent.OccupiedRect(); CompSnowExpand.reachableCells.Clear(); this.parent.Map.floodFiller.FloodFill(this.parent.Position, (IntVec3 x) => (float)x.DistanceToSquared(this.parent.Position) <= this.snowRadius * this.snowRadius && (occupiedRect.Contains(x) || !x.Filled(this.parent.Map)), delegate(IntVec3 x) { CompSnowExpand.reachableCells.Add(x); }, int.MaxValue, false, null); int num = GenRadial.NumCellsInRadius(this.snowRadius); for (int i = 0; i < num; i++) { IntVec3 intVec = this.parent.Position + GenRadial.RadialPattern[i]; if (intVec.InBounds(this.parent.Map)) { if (CompSnowExpand.reachableCells.Contains(intVec)) { float num2 = this.snowNoise.GetValue(intVec); num2 += 1f; num2 *= 0.5f; if (num2 < 0.1f) { num2 = 0.1f; } if (this.parent.Map.snowGrid.GetDepth(intVec) <= num2) { float lengthHorizontal = (intVec - this.parent.Position).LengthHorizontal; float num3 = 1f - lengthHorizontal / this.snowRadius; this.parent.Map.snowGrid.AddDepth(intVec, num3 * this.Props.addAmount * num2); } } } } } }
private static FloatMenuOption GuardLocationOption(CompMeeseeksMemory compMeeseeksMemory, IntVec3 clickCell, Pawn pawn) { int num = GenRadial.NumCellsInRadius(2.9f); IntVec3 curLoc; for (int i = 0; i < num; i++) { curLoc = GenRadial.RadialPattern[i] + clickCell; if (!curLoc.Standable(pawn.Map)) { continue; } if (curLoc != pawn.Position) { if (!pawn.CanReach(curLoc, PathEndMode.OnCell, Danger.Deadly)) { return(new FloatMenuOption("CannotGoNoPath".Translate(), null)); } Action action = delegate { //IntVec3 guardPosition = RCellFinder.BestOrderedGotoDestNear(curLoc, pawn); compMeeseeksMemory.guardPosition = curLoc; Job job = JobMaker.MakeJob(JobDefOf.Goto, curLoc); job.playerForced = true; //if (pawn.Map.exitMapGrid.IsExitCell(UI.MouseCell())) //{ // job.exitMapOnArrival = true; //} //else if (!pawn.Map.IsPlayerHome && !pawn.Map.exitMapGrid.MapUsesExitGrid && CellRect.WholeMap(pawn.Map).IsOnEdge(UI.MouseCell(), 3) && pawn.Map.Parent.GetComponent<FormCaravanComp>() != null && MessagesRepeatAvoider.MessageShowAllowed("MessagePlayerTriedToLeaveMapViaExitGrid-" + pawn.Map.uniqueID, 60f)) //{ // if (pawn.Map.Parent.GetComponent<FormCaravanComp>().CanFormOrReformCaravanNow) // { // Messages.Message("MessagePlayerTriedToLeaveMapViaExitGrid_CanReform".Translate(), pawn.Map.Parent, MessageTypeDefOf.RejectInput, historical: false); // } // else // { // Messages.Message("MessagePlayerTriedToLeaveMapViaExitGrid_CantReform".Translate(), pawn.Map.Parent, MessageTypeDefOf.RejectInput, historical: false); // } //} pawn.drafter.Drafted = true; if (pawn.jobs.TryTakeOrderedJob(job)) { MoteMaker.MakeStaticMote(curLoc, pawn.Map, ThingDefOf.Mote_FeedbackGoto); } else { pawn.drafter.Drafted = false; } }; return(new FloatMenuOption("CM_Meeseeks_Box_GuardHere".Translate(), action, MenuOptionPriority.GoHere) { autoTakeable = false, autoTakeablePriority = 10f }); } return(null); } return(null); }
private void Dig(IntVec3 start, float dir, float width, List <IntVec3> group, Map map, bool closed, HashSet <IntVec3> visited = null) { Vector3 vector = start.ToVector3Shifted(); 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>(); } GenStep_Cavern.tmpGroupSet.Clear(); GenStep_Cavern.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)) { if (!GenStep_Cavern.tmpGroupSet.Contains(intVec2) || caves[intVec2] > 0f) { return; } } } } if (num2 >= 30 && width > 4f + GenStep_Cavern.BranchedTunnelWidthOffset.max) { if (!flag && Rand.Chance(0.6f)) { this.DigInBestDirection(intVec, dir, new FloatRange(40f, 90f), width - GenStep_Cavern.BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag = true; } if (!flag2 && Rand.Chance(0.6f)) { this.DigInBestDirection(intVec, dir, new FloatRange(-90f, -40f), width - GenStep_Cavern.BranchedTunnelWidthOffset.RandomInRange, group, map, closed, visited); flag2 = true; } } bool flag3; this.SetCaveAround(intVec, width, map, visited, out flag3); if (flag3) { return; } while (vector.ToIntVec3() == intVec) { vector += Vector3Utility.FromAngleFlat(dir) * 0.5f; num += 0.5f; } if (!GenStep_Cavern.tmpGroupSet.Contains(vector.ToIntVec3())) { return; } IntVec3 intVec3 = new IntVec3(intVec.x, 0, vector.ToIntVec3().z); if (this.IsRock(intVec3, elevation, map)) { caves[intVec3] = Mathf.Max(caves[intVec3], width); visited.Add(intVec3); } intVec = vector.ToIntVec3(); dir += (float)this.directionNoise.GetValue((double)(num * 60f), (double)((float)start.x * 200f), (double)((float)start.z * 200f)) * 8f; width -= 0.01f; if (width < 1.4f) { return; } num2++; } }
protected new void Impact(Thing hitThing) { bool flag = hitThing == null; if (flag) { Pawn pawn; bool flag2 = (pawn = base.Position.GetThingList(base.Map).FirstOrDefault((Thing x) => x == this.assignedTarget) as Pawn) != null; if (flag2) { hitThing = pawn; } } if (hitThing != null) { damageEntities(hitThing, Mathf.RoundToInt(Rand.Range(this.def.projectile.GetDamageAmount(1, null) * .8f, this.def.projectile.GetDamageAmount(1, null) * 1.4f) * this.arcaneDmg)); } TM_MoteMaker.ThrowShadowCleaveMote(this.ExactPosition, this.Map, 2f + (.4f * pwrVal), .05f, .1f, .3f, 0, 5f + pwrVal, this.directionAngle); TorannMagicDefOf.TM_SoftExplosion.PlayOneShot(new TargetInfo(this.ExactPosition.ToIntVec3(), this.pawn.Map, false)); int num = GenRadial.NumCellsInRadius(1 + (.4f * pwrVal)); Vector3 cleaveVector; IntVec3 intVec; for (int i = 0; i < num; i++) { cleaveVector = this.ExactPosition + (Quaternion.AngleAxis(-45, Vector3.up) * ((1.5f + (.5f * pwrVal)) * this.direction)); intVec = cleaveVector.ToIntVec3() + GenRadial.RadialPattern[i]; //GenExplosion.DoExplosion(intVec, base.Map, .4f, TMDamageDefOf.DamageDefOf.TM_Shadow, this.launcher as Pawn, Mathf.RoundToInt((Rand.Range(.6f * this.def.projectile.GetDamageAmount(1,null), 1.1f * this.def.projectile.GetDamageAmount(1,null)) + (5f * pwrVal)) * this.arcaneDmg), this.def.projectile.soundExplode, def, null, null, 0f, 1, false, null, 0f, 0, 0.0f, true); if (intVec.IsValid && intVec.InBounds(this.Map)) { List<Thing> hitList = new List<Thing>(); hitList = intVec.GetThingList(base.Map); for (int j = 0; j < hitList.Count; j++) { if (hitList[j] is Pawn && hitList[j] != this.pawn) { damageEntities(hitList[j], Mathf.RoundToInt(Rand.Range(this.def.projectile.GetDamageAmount(1, null) * .6f, this.def.projectile.GetDamageAmount(1, null) * .8f) * (float)(1f + (.1 * pwrVal)) * this.arcaneDmg)); } } } cleaveVector = this.ExactPosition + (Quaternion.AngleAxis(45, Vector3.up) * ((1.5f + (.5f * pwrVal)) * this.direction)); intVec = cleaveVector.ToIntVec3() + GenRadial.RadialPattern[i]; //GenExplosion.DoExplosion(intVec, base.Map, .4f, TMDamageDefOf.DamageDefOf.TM_Shadow, this.launcher as Pawn, Mathf.RoundToInt((Rand.Range(.6f * this.def.projectile.GetDamageAmount(1,null), 1.1f * this.def.projectile.GetDamageAmount(1,null)) + (5f * pwrVal)) * this.arcaneDmg), this.def.projectile.soundExplode, def, null, null, 0f, 1, false, null, 0f, 0, 0.0f, true); if (intVec.IsValid && intVec.InBounds(this.Map)) { List<Thing> hitList = new List<Thing>(); hitList = intVec.GetThingList(base.Map); for (int j = 0; j < hitList.Count; j++) { if (hitList[j] is Pawn && hitList[j] != this.pawn) { damageEntities(hitList[j], Mathf.RoundToInt(Rand.Range(this.def.projectile.GetDamageAmount(1, null) * .5f, this.def.projectile.GetDamageAmount(1, null) * .7f) * (float)(1f + (.1 * pwrVal)) * this.arcaneDmg)); } } } cleaveVector = this.ExactPosition + ((2 + (.3f * (float)pwrVal)) * this.direction); intVec = cleaveVector.ToIntVec3() + GenRadial.RadialPattern[i]; //GenExplosion.DoExplosion(intVec, base.Map, .4f, TMDamageDefOf.DamageDefOf.TM_Shadow, this.launcher as Pawn, Mathf.RoundToInt((Rand.Range(.6f*this.def.projectile.GetDamageAmount(1,null), 1.1f*this.def.projectile.GetDamageAmount(1,null)) + (5f * pwrVal)) * this.arcaneDmg), this.def.projectile.soundExplode, def, null, null, 0f, 1, false, null, 0f, 0, 0.0f, true); if (intVec.IsValid && intVec.InBounds(this.Map)) { List<Thing> hitList = new List<Thing>(); hitList = intVec.GetThingList(base.Map); for (int j = 0; j < hitList.Count; j++) { if (hitList[j] is Pawn && hitList[j] != this.pawn) { damageEntities(hitList[j], Mathf.RoundToInt(Rand.Range(this.def.projectile.GetDamageAmount(1, null) * .5f, this.def.projectile.GetDamageAmount(1, null) * .7f) * (float)(1f + (.1 * pwrVal)) * this.arcaneDmg)); } } } } this.Destroy(DestroyMode.Vanish); //GenExplosion.DoExplosion(base.Position, base.Map, this.radius, TMDamageDefOf.DamageDefOf.TM_DeathBolt, this.launcher as Pawn, Mathf.RoundToInt((Rand.Range(.6f*this.def.projectile.GetDamageAmount(1,null), 1.1f*this.def.projectile.GetDamageAmount(1,null)) + (5f * pwrVal)) * this.arcaneDmg), this.def.projectile.soundExplode, def, null, null, 0f, 1, false, null, 0f, 0, 0.0f, true); }