public override void DrawWorker(Vector3 loc, Rot4 rot, ThingDef thingDef, Thing thing, float extraRotation) { DrawMoteInternal(loc, rot, thingDef, thing, 0); }
public Material HairMatAt(Rot4 facing) { Material baseMat = hairGraphic.MatAt(facing); return(flasher.GetDamagedMat(baseMat)); }
public static Vector3 TrueCenter(IntVec3 loc, Rot4 rotation, IntVec2 thingSize, float altitude) { Vector3 result = loc.ToVector3ShiftedWithAltitude(altitude); if (thingSize.x != 1 || thingSize.z != 1) { if (rotation.IsHorizontal) { int x = thingSize.x; thingSize.x = thingSize.z; thingSize.z = x; } switch (rotation.AsInt) { case 0: if (thingSize.x % 2 == 0) { result.x += 0.5f; } if (thingSize.z % 2 == 0) { result.z += 0.5f; } break; case 1: if (thingSize.x % 2 == 0) { result.x += 0.5f; } if (thingSize.z % 2 == 0) { result.z -= 0.5f; } break; case 2: if (thingSize.x % 2 == 0) { result.x -= 0.5f; } if (thingSize.z % 2 == 0) { result.z -= 0.5f; } break; case 3: if (thingSize.x % 2 == 0) { result.x -= 0.5f; } if (thingSize.z % 2 == 0) { result.z += 0.5f; } break; } } return(result); }
public static bool TryFindRandomAdjacentCell8WayWithRoomGroup(IntVec3 center, Rot4 rot, IntVec2 size, Map map, out IntVec3 result) { GenAdj.AdjustForRotation(ref center, ref size, rot); GenAdj.validCells.Clear(); foreach (IntVec3 item in GenAdj.CellsAdjacent8Way(center, rot, size)) { if (item.InBounds(map) && item.GetRoomGroup(map) != null) { GenAdj.validCells.Add(item); } } return(((IEnumerable <IntVec3>)GenAdj.validCells).TryRandomElement <IntVec3>(out result)); }
public static CellRect OccupiedRect(IntVec3 center, Rot4 rot, IntVec2 size) { GenAdj.AdjustForRotation(ref center, ref size, rot); return(new CellRect(center.x - (size.x - 1) / 2, center.z - (size.z - 1) / 2, size.x, size.z)); }
public override Material MatAt(Rot4 rot, Thing thing = null) { return(this.mat); }
public static IEnumerable <IntVec3> CellsAdjacentAlongEdge(IntVec3 thingCent, Rot4 thingRot, IntVec2 thingSize, LinkDirections dir) { GenAdj.AdjustForRotation(ref thingCent, ref thingSize, thingRot); int minX = thingCent.x - (thingSize.x - 1) / 2 - 1; int minZ = thingCent.z - (thingSize.z - 1) / 2 - 1; int maxX = minX + thingSize.x + 1; int maxZ = minZ + thingSize.z + 1; if (dir == LinkDirections.Down) { int x2 = minX; if (x2 <= maxX) { yield return(new IntVec3(x2, thingCent.y, minZ - 1)); /*Error: Unable to find new state assignment for yield return*/; } } if (dir == LinkDirections.Up) { int x = minX; if (x <= maxX) { yield return(new IntVec3(x, thingCent.y, maxZ + 1)); /*Error: Unable to find new state assignment for yield return*/; } } if (dir == LinkDirections.Left) { int z2 = minZ; if (z2 <= maxZ) { yield return(new IntVec3(minX - 1, thingCent.y, z2)); /*Error: Unable to find new state assignment for yield return*/; } } if (dir == LinkDirections.Right) { int z = minZ; if (z <= maxZ) { yield return(new IntVec3(maxX + 1, thingCent.y, z)); /*Error: Unable to find new state assignment for yield return*/; } } }
public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false) { if (map == null) { Log.Error("Tried to spawn " + newThing.ToStringSafe() + " in a null map."); return(null); } if (!loc.InBounds(map)) { Log.Error(string.Concat("Tried to spawn ", newThing.ToStringSafe(), " out of bounds at ", loc, ".")); return(null); } if (newThing.def.randomizeRotationOnSpawn) { rot = Rot4.Random; } CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size); if (!occupiedRect.InBounds(map)) { Log.Error(string.Concat("Tried to spawn ", newThing.ToStringSafe(), " out of bounds at ", loc, " (out of bounds because size is ", newThing.def.Size, ").")); return(null); } if (newThing.Spawned) { Log.Error(string.Concat("Tried to spawn ", newThing, " but it's already spawned.")); return(newThing); } switch (wipeMode) { case WipeMode.Vanish: WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish); break; case WipeMode.FullRefund: WipeAndRefundExistingThings(loc, rot, newThing.def, map); break; case WipeMode.VanishOrMoveAside: CheckMoveItemsAside(loc, rot, newThing.def, map); WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish); break; } if (newThing.def.category == ThingCategory.Item) { foreach (IntVec3 item in occupiedRect) { foreach (Thing item2 in item.GetThingList(map).ToList()) { if (item2 != newThing && item2.def.category == ThingCategory.Item) { item2.DeSpawn(); if (!GenPlace.TryPlaceThing(item2, item, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x))) { item2.Destroy(); } } } } } newThing.Rotation = rot; newThing.Position = loc; if (newThing.holdingOwner != null) { newThing.holdingOwner.Remove(newThing); } newThing.SpawnSetup(map, respawningAfterLoad); if (newThing.Spawned && newThing.stackCount == 0) { Log.Error("Spawned thing with 0 stackCount: " + newThing); newThing.Destroy(); return(null); } if (newThing.def.passability == Traversability.Impassable) { foreach (IntVec3 item3 in occupiedRect) { foreach (Thing item4 in item3.GetThingList(map).ToList()) { if (item4 != newThing) { (item4 as Pawn)?.pather.TryRecoverFromUnwalkablePosition(error: false); } } } return(newThing); } return(newThing); }
public static bool WouldWipeAnythingWith(IntVec3 thingPos, Rot4 thingRot, BuildableDef thingDef, Map map, Predicate <Thing> predicate) { return(WouldWipeAnythingWith(GenAdj.OccupiedRect(thingPos, thingRot, thingDef.Size), thingDef, map, predicate)); }
public static bool TryFindRandomEdgeCellWith(Predicate <IntVec3> validator, Map map, Rot4 dir, float roadChance, out IntVec3 result) { if (Rand.Value < roadChance) { bool flag = (from c in map.roadInfo.roadEdgeTiles where validator(c) && c.OnEdge(map, dir) select c).TryRandomElement(out result); if (flag) { return(flag); } } for (int i = 0; i < 100; i++) { result = CellFinder.RandomEdgeCell(dir, map); if (validator(result)) { return(true); } } int asInt = dir.AsInt; if (CellFinder.mapSingleEdgeCells[asInt] == null || map.Size != CellFinder.mapSingleEdgeCellsSize) { CellFinder.mapSingleEdgeCellsSize = map.Size; CellFinder.mapSingleEdgeCells[asInt] = new List <IntVec3>(); foreach (IntVec3 item in CellRect.WholeMap(map).GetEdgeCells(dir)) { CellFinder.mapSingleEdgeCells[asInt].Add(item); } } List <IntVec3> list = CellFinder.mapSingleEdgeCells[asInt]; list.Shuffle <IntVec3>(); int j = 0; int count = list.Count; while (j < count) { try { if (validator(list[j])) { result = list[j]; return(true); } } catch (Exception ex) { Log.Error(string.Concat(new object[] { "TryFindRandomEdgeCellWith exception validating ", list[j], ": ", ex.ToString() }), false); } j++; } result = IntVec3.Invalid; return(false); }
public static IntVec3 FindNoWipeSpawnLocNear(IntVec3 near, Map map, ThingDef thingToSpawn, Rot4 rot, int maxDist = 2, Predicate <IntVec3> extraValidator = null) { int num = GenRadial.NumCellsInRadius((float)maxDist); IntVec3 intVec = IntVec3.Invalid; float num2 = 0f; for (int i = 0; i < num; i++) { IntVec3 intVec2 = near + GenRadial.RadialPattern[i]; if (intVec2.InBounds(map)) { CellRect cellRect = GenAdj.OccupiedRect(intVec2, rot, thingToSpawn.size); if (cellRect.InBounds(map)) { if (GenSight.LineOfSight(near, intVec2, map, true, null, 0, 0)) { if (extraValidator == null || extraValidator(intVec2)) { if (thingToSpawn.category != ThingCategory.Building || GenConstruct.CanBuildOnTerrain(thingToSpawn, intVec2, map, rot, null)) { bool flag = false; bool flag2 = false; CellFinder.tmpUniqueWipedThings.Clear(); CellRect.CellRectIterator iterator = cellRect.GetIterator(); while (!iterator.Done()) { if (iterator.Current.Impassable(map)) { flag2 = true; } List <Thing> thingList = iterator.Current.GetThingList(map); for (int j = 0; j < thingList.Count; j++) { if (thingList[j] is Pawn) { flag = true; } else if (GenSpawn.SpawningWipes(thingToSpawn, thingList[j].def) && !CellFinder.tmpUniqueWipedThings.Contains(thingList[j])) { CellFinder.tmpUniqueWipedThings.Add(thingList[j]); } } iterator.MoveNext(); } if (flag && thingToSpawn.passability == Traversability.Impassable) { CellFinder.tmpUniqueWipedThings.Clear(); } else if (flag2 && thingToSpawn.category == ThingCategory.Item) { CellFinder.tmpUniqueWipedThings.Clear(); } else { float num3 = 0f; for (int k = 0; k < CellFinder.tmpUniqueWipedThings.Count; k++) { if (CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Building && !CellFinder.tmpUniqueWipedThings[k].def.costList.NullOrEmpty <ThingDefCountClass>() && CellFinder.tmpUniqueWipedThings[k].def.costStuffCount == 0) { List <ThingDefCountClass> list = CellFinder.tmpUniqueWipedThings[k].CostListAdjusted(); for (int l = 0; l < list.Count; l++) { num3 += list[l].thingDef.GetStatValueAbstract(StatDefOf.MarketValue, null) * (float)list[l].count * (float)CellFinder.tmpUniqueWipedThings[k].stackCount; } } else { num3 += CellFinder.tmpUniqueWipedThings[k].MarketValue * (float)CellFinder.tmpUniqueWipedThings[k].stackCount; } if (CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Building || CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Item) { num3 = Mathf.Max(num3, 0.001f); } } CellFinder.tmpUniqueWipedThings.Clear(); if (!intVec.IsValid || num3 < num2) { if (num3 == 0f) { return(intVec2); } intVec = intVec2; num2 = num3; } } } } } } } } return((!intVec.IsValid) ? near : intVec); }
public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false) { if (map == null) { Log.Error("Tried to spawn " + newThing.ToStringSafe <Thing>() + " in a null map.", false); return(null); } if (!loc.InBounds(map)) { Log.Error(string.Concat(new object[] { "Tried to spawn ", newThing.ToStringSafe <Thing>(), " out of bounds at ", loc, "." }), false); return(null); } if (newThing.def.randomizeRotationOnSpawn) { rot = Rot4.Random; } CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size); if (!occupiedRect.InBounds(map)) { Log.Error(string.Concat(new object[] { "Tried to spawn ", newThing.ToStringSafe <Thing>(), " out of bounds at ", loc, " (out of bounds because size is ", newThing.def.Size, ")." }), false); return(null); } if (newThing.Spawned) { Log.Error("Tried to spawn " + newThing + " but it's already spawned.", false); return(newThing); } if (wipeMode == WipeMode.Vanish) { GenSpawn.WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish); } else if (wipeMode == WipeMode.FullRefund) { GenSpawn.WipeAndRefundExistingThings(loc, rot, newThing.def, map); } if (newThing.def.category == ThingCategory.Item) { foreach (IntVec3 intVec in occupiedRect) { foreach (Thing thing in intVec.GetThingList(map).ToList <Thing>()) { if (thing != newThing) { if (thing.def.category == ThingCategory.Item) { thing.DeSpawn(DestroyMode.Vanish); if (!GenPlace.TryPlaceThing(thing, intVec, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x))) { thing.Destroy(DestroyMode.Vanish); } } } } } } newThing.Rotation = rot; newThing.Position = loc; if (newThing.holdingOwner != null) { newThing.holdingOwner.Remove(newThing); } newThing.SpawnSetup(map, respawningAfterLoad); if (newThing.Spawned && newThing.stackCount == 0) { Log.Error("Spawned thing with 0 stackCount: " + newThing, false); newThing.Destroy(DestroyMode.Vanish); return(null); } if (newThing.def.passability == Traversability.Impassable) { foreach (IntVec3 c in occupiedRect) { foreach (Thing thing2 in c.GetThingList(map).ToList <Thing>()) { if (thing2 != newThing) { Pawn pawn = thing2 as Pawn; if (pawn != null) { pawn.pather.TryRecoverFromUnwalkablePosition(false); } } } } } return(newThing); }
public override void DrawWorker(Vector3 loc, Rot4 rot, ThingDef thingDef, Thing thing, float extraRotation) { Log.ErrorOnce("Graphic_Scatter cannot draw realtime.", 9432243); }
public virtual AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null) { return(AcceptanceReport.WasAccepted); }
public virtual void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot, Color ghostCol) { }
public virtual void PostPlace(Map map, BuildableDef def, IntVec3 loc, Rot4 rot) { }