public static Thing GetFirstSpawnedParentThing(Thing thing) { Thing result; if (thing.Spawned) { result = thing; } else { for (IThingHolder parentHolder = thing.ParentHolder; parentHolder != null; parentHolder = parentHolder.ParentHolder) { Thing thing2 = parentHolder as Thing; if (thing2 != null && thing2.Spawned) { return(thing2); } ThingComp thingComp = parentHolder as ThingComp; if (thingComp != null && thingComp.parent.Spawned) { return(thingComp.parent); } } result = null; } return(result); }
public static GlobalTargetInfo GetAdjustedTarget(GlobalTargetInfo target) { if (target.HasThing) { Thing thing = target.Thing; if (thing.Spawned) { return(thing); } GlobalTargetInfo result = GlobalTargetInfo.Invalid; for (IThingHolder parentHolder = thing.ParentHolder; parentHolder != null; parentHolder = parentHolder.ParentHolder) { Thing thing2 = parentHolder as Thing; if (thing2 != null && thing2.Spawned) { result = thing2; break; } ThingComp thingComp = parentHolder as ThingComp; if (thingComp != null && thingComp.parent.Spawned) { result = thingComp.parent; break; } WorldObject worldObject = parentHolder as WorldObject; if (worldObject != null && worldObject.Spawned) { result = worldObject; break; } } if (result.IsValid) { return(result); } if (thing.Tile >= 0) { return(new GlobalTargetInfo(thing.Tile)); } } else if (target.Cell.IsValid && target.Tile >= 0 && target.Map != null && !Find.Maps.Contains(target.Map)) { MapParent parent = target.Map.info.parent; if (parent != null && parent.Spawned) { return(parent); } if (parent != null && parent.Tile >= 0) { return(new GlobalTargetInfo(target.Map.Tile)); } return(GlobalTargetInfo.Invalid); } else if (target.HasWorldObject && !target.WorldObject.Spawned && target.WorldObject.Tile >= 0) { return(new GlobalTargetInfo(target.WorldObject.Tile)); } return(target); }
public void InitializeComps() { if (base.def.comps.Any()) { this.comps = new List <ThingComp>(); for (int i = 0; i < base.def.comps.Count; i++) { ThingComp thingComp = (ThingComp)Activator.CreateInstance(base.def.comps[i].compClass); thingComp.parent = this; this.comps.Add(thingComp); thingComp.Initialize(base.def.comps[i]); } } }
public static bool SpawnedOrAnyParentSpawned(IThingHolder holder) { while (holder != null) { Thing thing = holder as Thing; if (thing != null && thing.Spawned) { return(true); } ThingComp thingComp = holder as ThingComp; if (thingComp != null && thingComp.parent.Spawned) { return(true); } holder = holder.ParentHolder; } return(false); }
public static Thing SpawnedParentOrMe(IThingHolder holder) { while (holder != null) { Thing thing = holder as Thing; if (thing != null && thing.Spawned) { return(thing); } ThingComp thingComp = holder as ThingComp; if (thingComp != null && thingComp.parent.Spawned) { return(thingComp.parent); } holder = holder.ParentHolder; } return(null); }
public static IntVec3 GetRootPosition(IThingHolder holder) { IntVec3 result = IntVec3.Invalid; while (holder != null) { Thing thing = holder as Thing; if (thing != null && thing.Position.IsValid) { result = thing.Position; } else { ThingComp thingComp = holder as ThingComp; if (thingComp != null && thingComp.parent.Position.IsValid) { result = thingComp.parent.Position; } } holder = holder.ParentHolder; } return(result); }
public void InitializeComps() { if (def.comps.Any()) { comps = new List <ThingComp>(); for (int i = 0; i < def.comps.Count; i++) { ThingComp thingComp = null; try { thingComp = (ThingComp)Activator.CreateInstance(def.comps[i].compClass); thingComp.parent = this; comps.Add(thingComp); thingComp.Initialize(def.comps[i]); } catch (Exception arg) { Log.Error("Could not instantiate or initialize a ThingComp: " + arg); comps.Remove(thingComp); } } } }
public static Thing SpawnedParentOrMe(IThingHolder holder) { while (holder != null) { Thing thing = holder as Thing; Thing result; if (thing != null && thing.Spawned) { result = thing; } else { ThingComp thingComp = holder as ThingComp; if (thingComp == null || !thingComp.parent.Spawned) { holder = holder.ParentHolder; continue; } result = thingComp.parent; } return(result); } return(null); }
public static GlobalTargetInfo GetAdjustedTarget(GlobalTargetInfo target) { if (target.HasThing) { Thing thing = target.Thing; if (thing.Spawned) { return(thing); } GlobalTargetInfo result = GlobalTargetInfo.Invalid; for (IThingHolder parentHolder = thing.ParentHolder; parentHolder != null; parentHolder = parentHolder.ParentHolder) { Thing thing2 = parentHolder as Thing; if (thing2 != null && thing2.Spawned) { result = thing2; break; } ThingComp thingComp = parentHolder as ThingComp; if (thingComp != null && thingComp.parent.Spawned) { result = thingComp.parent; break; } WorldObject worldObject = parentHolder as WorldObject; if (worldObject != null && worldObject.Spawned) { result = worldObject; break; } } if (result.IsValid) { return(result); } if (target.Thing.TryGetComp <CompCauseGameCondition>() != null) { List <Site> sites = Find.WorldObjects.Sites; for (int i = 0; i < sites.Count; i++) { for (int j = 0; j < sites[i].parts.Count; j++) { if (sites[i].parts[j].conditionCauser == target.Thing) { return(sites[i]); } } } } if (thing.Tile >= 0) { return(new GlobalTargetInfo(thing.Tile)); } } else if (target.Cell.IsValid && target.Tile >= 0 && target.Map != null && !Find.Maps.Contains(target.Map)) { MapParent parent = target.Map.Parent; if (parent != null && parent.Spawned) { return(parent); } return(GlobalTargetInfo.Invalid); } return(target); }