public static void DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect, Predicate <IntVec3> nearPlaceValidator = null) { if ((Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund) || mode == DestroyMode.Vanish) { return; } if (mode == DestroyMode.KillFinalize && diedThing.def.filthLeaving != null) { for (int i = leavingsRect.minZ; i <= leavingsRect.maxZ; i++) { for (int j = leavingsRect.minX; j <= leavingsRect.maxX; j++) { IntVec3 c = new IntVec3(j, 0, i); FilthMaker.MakeFilth(c, map, diedThing.def.filthLeaving, Rand.RangeInclusive(1, 3)); } } } ThingOwner <Thing> thingOwner = new ThingOwner <Thing>(); if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null) { for (int k = 0; k < diedThing.def.killedLeavings.Count; k++) { Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef, null); thing.stackCount = diedThing.def.killedLeavings[k].count; thingOwner.TryAdd(thing, true); } } if (GenLeaving.CanBuildingLeaveResources(diedThing, mode)) { Frame frame = diedThing as Frame; if (frame != null) { for (int l = frame.resourceContainer.Count - 1; l >= 0; l--) { int num = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[l].stackCount); if (num > 0) { frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[l], thingOwner, num, true); } } frame.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish); } else { List <ThingDefCountClass> list = diedThing.CostListAdjusted(); for (int m = 0; m < list.Count; m++) { ThingDefCountClass thingDefCountClass = list[m]; int num2 = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingDefCountClass.count); if (num2 > 0 && mode == DestroyMode.KillFinalize && thingDefCountClass.thingDef.slagDef != null) { int count = thingDefCountClass.thingDef.slagDef.smeltProducts.First((ThingDefCountClass pro) => pro.thingDef == ThingDefOf.Steel).count; int num3 = num2 / 2 / 8; for (int n = 0; n < num3; n++) { thingOwner.TryAdd(ThingMaker.MakeThing(thingDefCountClass.thingDef.slagDef, null), true); } num2 -= num3 * count; } if (num2 > 0) { Thing thing2 = ThingMaker.MakeThing(thingDefCountClass.thingDef, null); thing2.stackCount = num2; thingOwner.TryAdd(thing2, true); } } } } List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList <IntVec3>(); int num4 = 0; while (thingOwner.Count > 0) { if (mode == DestroyMode.KillFinalize && !map.areaManager.Home[list2[num4]]) { thingOwner[0].SetForbidden(true, false); } ThingOwner <Thing> thingOwner2 = thingOwner; Thing thing3 = thingOwner[0]; IntVec3 dropLoc = list2[num4]; ThingPlaceMode mode2 = ThingPlaceMode.Near; Thing thing4; ref Thing lastResultingThing = ref thing4; if (!thingOwner2.TryDrop(thing3, dropLoc, map, mode2, out lastResultingThing, null, nearPlaceValidator)) { Log.Warning(string.Concat(new object[] { "Failed to place all leavings for destroyed thing ", diedThing, " at ", leavingsRect.CenterCell }), false); return; } num4++; if (num4 >= list2.Count) { num4 = 0; } }
public static void DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect) { if (Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund) { return; } switch (mode) { case DestroyMode.Vanish: return; case DestroyMode.KillFinalize: if (diedThing.def.filthLeaving != null) { for (int i = leavingsRect.minZ; i <= leavingsRect.maxZ; i++) { for (int j = leavingsRect.minX; j <= leavingsRect.maxX; j++) { IntVec3 c = new IntVec3(j, 0, i); FilthMaker.MakeFilth(c, map, diedThing.def.filthLeaving, Rand.RangeInclusive(1, 3)); } } } break; } ThingOwner <Thing> thingOwner = new ThingOwner <Thing>(); if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null) { for (int k = 0; k < diedThing.def.killedLeavings.Count; k++) { Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef, null); thing.stackCount = diedThing.def.killedLeavings[k].count; thingOwner.TryAdd(thing, true); } } if (GenLeaving.CanBuildingLeaveResources(diedThing, mode)) { Frame frame = diedThing as Frame; if (frame != null) { for (int num = frame.resourceContainer.Count - 1; num >= 0; num--) { int num2 = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[num].stackCount); if (num2 > 0) { frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[num], thingOwner, num2, true); } } frame.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish); } else { List <ThingCountClass> list = diedThing.CostListAdjusted(); for (int l = 0; l < list.Count; l++) { ThingCountClass thingCountClass = list[l]; int num3 = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingCountClass.count); if (num3 > 0 && mode == DestroyMode.KillFinalize && thingCountClass.thingDef.slagDef != null) { int count = thingCountClass.thingDef.slagDef.smeltProducts.First((ThingCountClass pro) => pro.thingDef == ThingDefOf.Steel).count; int num4 = num3 / 2 / 8; for (int m = 0; m < num4; m++) { thingOwner.TryAdd(ThingMaker.MakeThing(thingCountClass.thingDef.slagDef, null), true); } num3 -= num4 * count; } if (num3 > 0) { Thing thing2 = ThingMaker.MakeThing(thingCountClass.thingDef, null); thing2.stackCount = num3; thingOwner.TryAdd(thing2, true); } } } } List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList(); int num5 = 0; while (true) { if (thingOwner.Count > 0) { if (mode == DestroyMode.KillFinalize && !((Area)map.areaManager.Home)[list2[num5]]) { thingOwner[0].SetForbidden(true, false); } Thing thing3 = default(Thing); if (thingOwner.TryDrop(thingOwner[0], list2[num5], map, ThingPlaceMode.Near, out thing3, (Action <Thing, int>)null)) { num5++; if (num5 >= list2.Count) { num5 = 0; } continue; } break; } return; } Log.Warning("Failed to place all leavings for destroyed thing " + diedThing + " at " + leavingsRect.CenterCell); }