public override string CompInspectStringExtra() { CompProperties_Facility props = Props; if (props.statOffsets == null) { return(null); } bool flag = AmIActiveForAnyone(); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < props.statOffsets.Count; i++) { StatModifier statModifier = props.statOffsets[i]; StatDef stat = statModifier.stat; stringBuilder.Append(stat.LabelCap); stringBuilder.Append(": "); stringBuilder.Append(statModifier.value.ToStringByStyle(stat.toStringStyle, ToStringNumberSense.Offset)); if (!flag) { stringBuilder.Append(" ("); stringBuilder.Append("InactiveFacility".Translate()); stringBuilder.Append(")"); } if (i < props.statOffsets.Count - 1) { stringBuilder.AppendLine(); } } return(stringBuilder.ToString()); }
public bool CanPotentiallyLinkTo(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot) { if (!CompAffectedByFacilities.CanPotentiallyLinkTo_Static(facilityDef, facilityPos, facilityRot, this.parent.def, this.parent.Position, this.parent.Rotation)) { return(false); } if (!this.IsPotentiallyValidFacilityForMe(facilityDef, facilityPos, facilityRot)) { return(false); } int num = 0; bool flag = false; for (int i = 0; i < this.linkedFacilities.Count; i++) { if (this.linkedFacilities[i].def == facilityDef) { num++; if (this.IsBetter(facilityDef, facilityPos, facilityRot, this.linkedFacilities[i])) { flag = true; break; } } } if (flag) { return(true); } CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>(); return(num + 1 <= compProperties.maxSimultaneous); }
public static IEnumerable <Thing> PotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { _003CPotentialThingsToLinkTo_003Ec__Iterator1 _003CPotentialThingsToLinkTo_003Ec__Iterator = (_003CPotentialThingsToLinkTo_003Ec__Iterator1) /*Error near IL_0034: stateMachine*/; CompAffectedByFacilities.alreadyReturnedCount.Clear(); CompProperties_AffectedByFacilities myProps = myDef.GetCompProperties <CompProperties_AffectedByFacilities>(); if (myProps.linkableFacilities != null) { IEnumerable <Thing> candidates = Enumerable.Empty <Thing>(); for (int i = 0; i < myProps.linkableFacilities.Count; i++) { candidates = candidates.Concat(map.listerThings.ThingsOfDef(myProps.linkableFacilities[i])); } Vector3 myTrueCenter = Gen.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); IOrderedEnumerable <Thing> sortedCandidates = (from x in candidates orderby Vector3.Distance(myTrueCenter, x.TrueCenter()) select x).ThenBy(delegate(Thing x) { IntVec3 position2 = x.Position; return(position2.x); }).ThenBy(delegate(Thing x) { IntVec3 position = x.Position; return(position.z); }); foreach (Thing item in sortedCandidates) { if (CompAffectedByFacilities.CanPotentiallyLinkTo_Static(item, myDef, myPos, myRot)) { CompProperties_Facility facilityProps = item.def.GetCompProperties <CompProperties_Facility>(); if (CompAffectedByFacilities.alreadyReturnedCount.ContainsKey(item.def)) { if (CompAffectedByFacilities.alreadyReturnedCount[item.def] < facilityProps.maxSimultaneous) { goto IL_0232; } continue; } CompAffectedByFacilities.alreadyReturnedCount.Add(item.def, 0); goto IL_0232; } continue; IL_0232: Dictionary <ThingDef, int> dictionary; ThingDef def; (dictionary = CompAffectedByFacilities.alreadyReturnedCount)[def = item.def] = dictionary[def] + 1; yield return(item); /*Error: Unable to find new state assignment for yield return*/; } } yield break; IL_02b1: /*Error near IL_02b2: Unexpected return in MoveNext()*/; }
public void GetStatsExplanation(StatDef stat, StringBuilder sb) { this.alreadyUsed.Clear(); bool flag = false; for (int i = 0; i < this.linkedFacilities.Count; i++) { bool flag2 = false; int num = 0; while (num < this.alreadyUsed.Count) { if (this.alreadyUsed[num] != this.linkedFacilities[i].def) { num++; continue; } flag2 = true; break; } if (!flag2 && this.IsFacilityActive(this.linkedFacilities[i])) { CompProperties_Facility compProperties = this.linkedFacilities[i].def.GetCompProperties <CompProperties_Facility>(); if (compProperties.statOffsets != null) { float statOffsetFromList = compProperties.statOffsets.GetStatOffsetFromList(stat); if (statOffsetFromList != 0.0) { if (!flag) { flag = true; sb.AppendLine(); sb.AppendLine("StatsReport_Facilities".Translate() + ":"); } int num2 = 0; for (int j = 0; j < this.linkedFacilities.Count; j++) { if (this.IsFacilityActive(this.linkedFacilities[j]) && this.linkedFacilities[j].def == this.linkedFacilities[i].def) { num2++; } } statOffsetFromList *= (float)num2; sb.Append(" "); if (num2 != 1) { sb.Append(num2.ToString() + "x "); } sb.AppendLine(this.linkedFacilities[i].LabelCap + ": " + statOffsetFromList.ToStringByStyle(stat.toStringStyle, ToStringNumberSense.Offset)); this.alreadyUsed.Add(this.linkedFacilities[i].def); } } } } }
public void GetStatsExplanation(StatDef stat, StringBuilder sb) { alreadyUsed.Clear(); bool flag = false; for (int i = 0; i < linkedFacilities.Count; i++) { bool flag2 = false; for (int j = 0; j < alreadyUsed.Count; j++) { if (alreadyUsed[j] == linkedFacilities[i].def) { flag2 = true; break; } } if (flag2 || !IsFacilityActive(linkedFacilities[i])) { continue; } CompProperties_Facility compProperties = linkedFacilities[i].def.GetCompProperties <CompProperties_Facility>(); if (compProperties.statOffsets == null) { continue; } float statOffsetFromList = compProperties.statOffsets.GetStatOffsetFromList(stat); if (statOffsetFromList == 0f) { continue; } if (!flag) { flag = true; sb.AppendLine(); sb.AppendLine("StatsReport_Facilities".Translate() + ":"); } int num = 0; for (int k = 0; k < linkedFacilities.Count; k++) { if (IsFacilityActive(linkedFacilities[k]) && linkedFacilities[k].def == linkedFacilities[i].def) { num++; } } statOffsetFromList *= (float)num; sb.Append(" "); if (num != 1) { sb.Append(num + "x "); } sb.AppendLine(linkedFacilities[i].LabelCap + ": " + statOffsetFromList.ToStringByStyle(stat.toStringStyle, ToStringNumberSense.Offset)); alreadyUsed.Add(linkedFacilities[i].def); } }
private Thing GetPotentiallySupplantedFacility(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot) { Thing thing = null; int num = 0; for (int i = 0; i < this.linkedFacilities.Count; i++) { if (this.linkedFacilities[i].def == facilityDef) { if (thing == null) { thing = this.linkedFacilities[i]; } num++; } } Thing result; if (num == 0) { result = null; } else { CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>(); if (num + 1 <= compProperties.maxSimultaneous) { result = null; } else { Thing thing2 = thing; for (int j = 0; j < this.linkedFacilities.Count; j++) { if (facilityDef == this.linkedFacilities[j].def) { if (this.IsBetter(thing2.def, thing2.Position, thing2.Rotation, this.linkedFacilities[j])) { thing2 = this.linkedFacilities[j]; } } } result = thing2; } } return(result); }
public float GetStatOffset(StatDef stat) { float num = 0f; for (int i = 0; i < this.linkedFacilities.Count; i++) { if (this.IsFacilityActive(this.linkedFacilities[i])) { CompProperties_Facility compProperties = this.linkedFacilities[i].def.GetCompProperties <CompProperties_Facility>(); if (compProperties.statOffsets != null) { num += compProperties.statOffsets.GetStatOffsetFromList(stat); } } } return(num); }
public static bool CanPotentiallyLinkTo_Static(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot, ThingDef myDef, IntVec3 myPos, Rot4 myRot) { CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>(); if (compProperties.mustBePlacedAdjacent) { CellRect rect = GenAdj.OccupiedRect(myPos, myRot, myDef.size); CellRect rect2 = GenAdj.OccupiedRect(facilityPos, facilityRot, facilityDef.size); if (!GenAdj.AdjacentTo8WayOrInside(rect, rect2)) { return(false); } } if (compProperties.mustBePlacedAdjacentCardinalToBedHead) { if (!myDef.IsBed) { return(false); } CellRect other = GenAdj.OccupiedRect(facilityPos, facilityRot, facilityDef.size); bool flag = false; int sleepingSlotsCount = BedUtility.GetSleepingSlotsCount(myDef.size); for (int i = 0; i < sleepingSlotsCount; i++) { IntVec3 sleepingSlotPos = BedUtility.GetSleepingSlotPos(i, myPos, myRot, myDef.size); if (sleepingSlotPos.IsAdjacentToCardinalOrInside(other)) { flag = true; } } if (!flag) { return(false); } } if (!compProperties.mustBePlacedAdjacent && !compProperties.mustBePlacedAdjacentCardinalToBedHead) { Vector3 a = Gen.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); Vector3 b = Gen.TrueCenter(facilityPos, facilityRot, facilityDef.size, facilityDef.Altitude); if (Vector3.Distance(a, b) > compProperties.maxDistance) { return(false); } } return(true); }
public static void DrawLinesToPotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { CompProperties_Facility compProperties = myDef.GetCompProperties <CompProperties_Facility>(); Vector3 a = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); for (int i = 0; i < compProperties.linkableBuildings.Count; i++) { foreach (Thing item in map.listerThings.ThingsOfDef(compProperties.linkableBuildings[i])) { CompAffectedByFacilities compAffectedByFacilities = item.TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities != null && compAffectedByFacilities.CanPotentiallyLinkTo(myDef, myPos, myRot)) { GenDraw.DrawLineBetween(a, item.TrueCenter()); compAffectedByFacilities.DrawRedLineToPotentiallySupplantedFacility(myDef, myPos, myRot); } } } }
private bool IsPotentiallyValidFacilityForMe(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot) { if (!CompAffectedByFacilities.IsPotentiallyValidFacilityForMe_Static(facilityDef, facilityPos, facilityRot, this.parent.def, this.parent.Position, this.parent.Rotation, this.parent.Map)) { return(false); } CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>(); if (compProperties.canLinkToMedBedsOnly) { Building_Bed building_Bed = this.parent as Building_Bed; if (building_Bed == null || !building_Bed.Medical) { return(false); } } return(true); }
public static IEnumerable <Thing> PotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { CompAffectedByFacilities.alreadyReturnedCount.Clear(); CompProperties_AffectedByFacilities myProps = myDef.GetCompProperties <CompProperties_AffectedByFacilities>(); if (myProps.linkableFacilities == null) { yield break; } IEnumerable <Thing> candidates = Enumerable.Empty <Thing>(); for (int i = 0; i < myProps.linkableFacilities.Count; i++) { candidates = candidates.Concat(map.listerThings.ThingsOfDef(myProps.linkableFacilities[i])); } Vector3 myTrueCenter = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); IOrderedEnumerable <Thing> sortedCandidates = from x in candidates orderby Vector3.Distance(myTrueCenter, x.TrueCenter()), x.Position.x, x.Position.z select x; foreach (Thing th in sortedCandidates) { if (CompAffectedByFacilities.CanPotentiallyLinkTo_Static(th, myDef, myPos, myRot)) { CompProperties_Facility facilityProps = th.def.GetCompProperties <CompProperties_Facility>(); if (CompAffectedByFacilities.alreadyReturnedCount.ContainsKey(th.def)) { if (CompAffectedByFacilities.alreadyReturnedCount[th.def] >= facilityProps.maxSimultaneous) { continue; } } else { CompAffectedByFacilities.alreadyReturnedCount.Add(th.def, 0); } Dictionary <ThingDef, int> dictionary; ThingDef def; (dictionary = CompAffectedByFacilities.alreadyReturnedCount)[def = th.def] = dictionary[def] + 1; yield return(th); } } yield break; }
public static IEnumerable <Thing> PotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { alreadyReturnedCount.Clear(); CompProperties_AffectedByFacilities compProperties = myDef.GetCompProperties <CompProperties_AffectedByFacilities>(); if (compProperties.linkableFacilities == null) { yield break; } IEnumerable <Thing> enumerable = Enumerable.Empty <Thing>(); for (int i = 0; i < compProperties.linkableFacilities.Count; i++) { enumerable = enumerable.Concat(map.listerThings.ThingsOfDef(compProperties.linkableFacilities[i])); } Vector3 myTrueCenter = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); IOrderedEnumerable <Thing> orderedEnumerable = from x in enumerable orderby Vector3.Distance(myTrueCenter, x.TrueCenter()), x.Position.x, x.Position.z select x; foreach (Thing item in orderedEnumerable) { if (!CanPotentiallyLinkTo_Static(item, myDef, myPos, myRot)) { continue; } CompProperties_Facility compProperties2 = item.def.GetCompProperties <CompProperties_Facility>(); if (alreadyReturnedCount.ContainsKey(item.def)) { if (alreadyReturnedCount[item.def] >= compProperties2.maxSimultaneous) { continue; } } else { alreadyReturnedCount.Add(item.def, 0); } alreadyReturnedCount[item.def]++; yield return(item); } }
private void LinkToNearbyBuildings() { UnlinkAll(); CompProperties_Facility props = Props; if (props.linkableBuildings != null) { for (int i = 0; i < props.linkableBuildings.Count; i++) { foreach (Thing item in parent.Map.listerThings.ThingsOfDef(props.linkableBuildings[i])) { CompAffectedByFacilities compAffectedByFacilities = item.TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities != null && compAffectedByFacilities.CanLinkTo(parent)) { linkedBuildings.Add(item); compAffectedByFacilities.Notify_NewLink(parent); } } } } }
private void LinkToNearbyBuildings() { this.UnlinkAll(); CompProperties_Facility props = this.Props; if (props.linkableBuildings == null) { return; } for (int i = 0; i < props.linkableBuildings.Count; i++) { foreach (Thing current in this.parent.Map.listerThings.ThingsOfDef(props.linkableBuildings[i])) { CompAffectedByFacilities compAffectedByFacilities = current.TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities != null && compAffectedByFacilities.CanLinkTo(this.parent)) { this.linkedBuildings.Add(current); compAffectedByFacilities.Notify_NewLink(this.parent); } } } }