public void Push(string symbol, ResolveParams resolveParams) { this.stack.Push(new Pair <string, ResolveParams>(symbol, resolveParams)); }
public override void Resolve(ResolveParams rp) { ThingDef ship_Beam = ThingDefOf.Ship_Beam; Map map = BaseGen.globalSettings.map; if (!rp.thingRot.HasValue && !rp.thrustAxis.HasValue) { rp.thrustAxis = Rot4.Random; rp.thingRot = rp.thrustAxis; } IntVec2 intVec = IntVec2.Invalid; IntVec2 b = IntVec2.Invalid; IntVec2 toIntVec = rp.thingRot.Value.FacingCell.ToIntVec2; int num = 0; while (true) { if (rp.thingRot.Value.IsHorizontal) { int newZ = Rand.Range(rp.rect.minZ + 1, rp.rect.maxZ - 2); intVec = new IntVec2((!(rp.thingRot.Value == Rot4.East)) ? rp.rect.maxX : rp.rect.minX, newZ); b = new IntVec2((!(rp.thingRot.Value == Rot4.East)) ? rp.rect.minX : rp.rect.maxX, newZ); } else { int newX = Rand.Range(rp.rect.minX + 1, rp.rect.maxX - 2); intVec = new IntVec2(newX, (!(rp.thingRot.Value == Rot4.North)) ? rp.rect.maxZ : rp.rect.minZ); b = new IntVec2(newX, (!(rp.thingRot.Value == Rot4.North)) ? rp.rect.minZ : rp.rect.maxZ); } bool?allowPlacementOffEdge = rp.allowPlacementOffEdge; if (allowPlacementOffEdge.HasValue && !allowPlacementOffEdge.Value && !(intVec - toIntVec).ToIntVec3.GetThingList(map).Any((Thing thing) => thing.def == ThingDefOf.Ship_Beam)) { if (num != 20) { num++; continue; } return; } break; } int magnitudeManhattan = (intVec - b).MagnitudeManhattan; float magnitude = (intVec - b).Magnitude; IntVec2 size = ship_Beam.Size; if (!(magnitude < (float)size.z)) { int num2; int num5; while (true) { bool?allowPlacementOffEdge2 = rp.allowPlacementOffEdge; num2 = ((!allowPlacementOffEdge2.HasValue || allowPlacementOffEdge2.Value) ? Rand.Range(0, 7) : 0); int num3 = Rand.Range(0, 7); num2 = 0; num3 = 0; int num4 = magnitudeManhattan - num2 - num3; IntVec2 size2 = ship_Beam.Size; num5 = num4 / size2.z; if (num5 > 0) { break; } } IntVec2 a = intVec; IntVec2 a2 = toIntVec; int num6 = num2; IntVec2 size3 = ship_Beam.Size; IntVec2 intVec2 = a + a2 * (num6 + size3.z / 2 - 1); Thing t = null; for (int i = 0; i < num5; i++) { Thing thing2 = ThingMaker.MakeThing(ship_Beam, null); thing2.SetFaction(rp.faction, null); t = GenSpawn.Spawn(thing2, intVec2.ToIntVec3, map, rp.thingRot.Value, false); IntVec2 a3 = intVec2; IntVec2 a4 = toIntVec; IntVec2 size4 = ship_Beam.Size; intVec2 = a3 + a4 * size4.z; } bool?allowPlacementOffEdge3 = rp.allowPlacementOffEdge; if (!allowPlacementOffEdge3.HasValue || allowPlacementOffEdge3.Value) { BaseGen.symbolStack.Push("ship_populate", rp); } CellRect rect; Rot4 value; CellRect rect2; Rot4 value2; if (rp.thingRot.Value.IsHorizontal) { rect = rp.rect; CellRect cellRect = t.OccupiedRect(); rect.minZ = cellRect.maxZ + 1; value = Rot4.North; rect2 = rp.rect; CellRect cellRect2 = t.OccupiedRect(); rect2.maxZ = cellRect2.minZ - 1; value2 = Rot4.South; } else { rect = rp.rect; CellRect cellRect3 = t.OccupiedRect(); rect.maxX = cellRect3.minX - 1; value = Rot4.West; rect2 = rp.rect; CellRect cellRect4 = t.OccupiedRect(); rect2.minX = cellRect4.maxX + 1; value2 = Rot4.East; } bool?allowPlacementOffEdge4 = rp.allowPlacementOffEdge; if (!allowPlacementOffEdge4.HasValue || allowPlacementOffEdge4.Value || Rand.Value < 0.30000001192092896) { ResolveParams resolveParams = rp; resolveParams.rect = rect; resolveParams.thingRot = value; resolveParams.allowPlacementOffEdge = false; BaseGen.symbolStack.Push("ship_spine", resolveParams); } bool?allowPlacementOffEdge5 = rp.allowPlacementOffEdge; if (!allowPlacementOffEdge5.HasValue || allowPlacementOffEdge5.Value || Rand.Value < 0.30000001192092896) { ResolveParams resolveParams2 = rp; resolveParams2.rect = rect2; resolveParams2.thingRot = value2; resolveParams2.allowPlacementOffEdge = false; BaseGen.symbolStack.Push("ship_spine", resolveParams2); } ResolveParams resolveParams3 = rp; resolveParams3.floorDef = TerrainDefOf.Concrete; BaseGen.symbolStack.Push("floor", resolveParams3); } }
public override bool CanResolve(ResolveParams rp) { return(base.CanResolve(rp) && rp.rect.Width <= 15 && rp.rect.Height <= 15 && rp.rect.Width > 5 && rp.rect.Height > 5); }
public override void Resolve(ResolveParams rp) { if (rp.singleThingToSpawn is Pawn) { ResolveParams resolveParams = rp; resolveParams.singlePawnToSpawn = (Pawn)rp.singleThingToSpawn; BaseGen.symbolStack.Push("pawn", resolveParams); return; } if (rp.singleThingToSpawn != null && rp.singleThingToSpawn.Spawned) { return; } ThingDef thingDef; if (rp.singleThingToSpawn == null) { ThingDef arg_9B_0; if ((arg_9B_0 = rp.singleThingDef) == null) { arg_9B_0 = (from x in ThingSetMakerUtility.allGeneratableItems where x.IsWeapon || x.IsMedicine || x.IsDrug select x).RandomElement <ThingDef>(); } thingDef = arg_9B_0; } else { thingDef = rp.singleThingToSpawn.def; } Rot4? rot = rp.thingRot; IntVec3 intVec; if (thingDef.category == ThingCategory.Item) { rot = new Rot4?(Rot4.North); if (!this.TryFindSpawnCellForItem(rp.rect, out intVec)) { if (rp.singleThingToSpawn != null) { rp.singleThingToSpawn.Destroy(DestroyMode.Vanish); } return; } } else { bool flag; bool flag2; intVec = this.FindBestSpawnCellForNonItem(rp.rect, thingDef, ref rot, out flag, out flag2); if ((flag || flag2) && rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit.HasValue && rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit.Value) { return; } } if (!rot.HasValue) { Log.Error("Could not resolve rotation. Bug.", false); } Thing thing; if (rp.singleThingToSpawn == null) { ThingDef stuff; if (rp.singleThingStuff != null && rp.singleThingStuff.stuffProps.CanMake(thingDef)) { stuff = rp.singleThingStuff; } else { stuff = GenStuff.RandomStuffInexpensiveFor(thingDef, rp.faction); } thing = ThingMaker.MakeThing(thingDef, stuff); Thing arg_1D7_0 = thing; int? singleThingStackCount = rp.singleThingStackCount; arg_1D7_0.stackCount = ((!singleThingStackCount.HasValue) ? 1 : singleThingStackCount.Value); if (thing.stackCount <= 0) { thing.stackCount = 1; } if (thing.def.CanHaveFaction && thing.Faction != rp.faction) { thing.SetFaction(rp.faction, null); } CompQuality compQuality = thing.TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(QualityUtility.GenerateQualityBaseGen(), ArtGenerationContext.Outsider); } if (rp.postThingGenerate != null) { rp.postThingGenerate(thing); } } else { thing = rp.singleThingToSpawn; } if (!rp.spawnBridgeIfTerrainCantSupportThing.HasValue || rp.spawnBridgeIfTerrainCantSupportThing.Value) { BaseGenUtility.CheckSpawnBridgeUnder(thing.def, intVec, rot.Value); } thing = GenSpawn.Spawn(thing, intVec, BaseGen.globalSettings.map, rot.Value, WipeMode.Vanish, false); if (thing != null && thing.def.category == ThingCategory.Item) { thing.SetForbidden(true, false); } if (rp.postThingSpawn != null) { rp.postThingSpawn(thing); } }
public override void Resolve(ResolveParams rp) { if (rp.singleThingToSpawn is Pawn) { ResolveParams resolveParams = rp; resolveParams.singlePawnToSpawn = (Pawn)rp.singleThingToSpawn; BaseGen.symbolStack.Push("pawn", resolveParams); } else { if (rp.singleThingToSpawn != null && rp.singleThingToSpawn.Spawned) { return; } ThingDef thingDef = ((rp.singleThingToSpawn != null) ? rp.singleThingToSpawn.def : (rp.singleThingDef ?? ThingSetMakerUtility.allGeneratableItems.Where((ThingDef x) => x.IsWeapon || x.IsMedicine || x.IsDrug).RandomElement())); Rot4? rot = rp.thingRot; IntVec3 result; if (thingDef.category == ThingCategory.Item) { rot = Rot4.North; if (!TryFindSpawnCellForItem(rp.rect, out result)) { if (rp.singleThingToSpawn != null) { rp.singleThingToSpawn.Destroy(); } return; } } else { result = FindBestSpawnCellForNonItem(rp.rect, thingDef, ref rot, out var hasToWipeBuilding, out var doesntFit); if ((hasToWipeBuilding || doesntFit) && rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit.HasValue && rp.skipSingleThingIfHasToWipeBuildingOrDoesntFit.Value) { return; } } if (!rot.HasValue) { Log.Error("Could not resolve rotation. Bug."); } Thing thing; if (rp.singleThingToSpawn == null) { ThingDef stuff = ((rp.singleThingStuff == null || !rp.singleThingStuff.stuffProps.CanMake(thingDef)) ? GenStuff.RandomStuffInexpensiveFor(thingDef, rp.faction) : rp.singleThingStuff); thing = ThingMaker.MakeThing(thingDef, stuff); thing.stackCount = rp.singleThingStackCount ?? 1; if (thing.stackCount <= 0) { thing.stackCount = 1; } if (thing.def.CanHaveFaction && thing.Faction != rp.faction) { thing.SetFaction(rp.faction); } thing.TryGetComp <CompQuality>()?.SetQuality(QualityUtility.GenerateQualityBaseGen(), ArtGenerationContext.Outsider); if (rp.postThingGenerate != null) { rp.postThingGenerate(thing); } } else { thing = rp.singleThingToSpawn; } if (!rp.spawnBridgeIfTerrainCantSupportThing.HasValue || rp.spawnBridgeIfTerrainCantSupportThing.Value) { BaseGenUtility.CheckSpawnBridgeUnder(thing.def, result, rot.Value); } thing = GenSpawn.Spawn(thing, result, BaseGen.globalSettings.map, rot.Value); if (thing != null && thing.def.category == ThingCategory.Item) { thing.SetForbidden(value: true, warnOnFail: false); } if (rp.postThingSpawn != null) { rp.postThingSpawn(thing); } } }
private void ResolveOption(int roomsPerRowX, int pathwayWidthX, int roomsPerRowZ, int pathwayWidthZ, ResolveParams rp) { Map map = BaseGen.globalSettings.map; int roomSize = this.GetRoomSize(roomsPerRowX, pathwayWidthX, rp.rect.Width); int roomSize2 = this.GetRoomSize(roomsPerRowZ, pathwayWidthZ, rp.rect.Height); ThingDef thingDef = null; if (pathwayWidthX >= 3) { if (rp.faction == null || rp.faction.def.techLevel >= TechLevel.Industrial) { thingDef = ThingDefOf.StandingLamp; } else { thingDef = ThingDefOf.TorchLamp; } } TerrainDef floorDef = rp.pathwayFloorDef ?? BaseGenUtility.RandomBasicFloorDef(rp.faction, false); int num = roomSize; for (int i = 0; i < roomsPerRowX - 1; i++) { CellRect rect = new CellRect(rp.rect.minX + num, rp.rect.minZ, pathwayWidthX, rp.rect.Height); ResolveParams resolveParams = rp; resolveParams.rect = rect; resolveParams.floorDef = floorDef; resolveParams.streetHorizontal = new bool?(false); BaseGen.symbolStack.Push("street", resolveParams); num += roomSize + pathwayWidthX; } int num2 = roomSize2; for (int j = 0; j < roomsPerRowZ - 1; j++) { CellRect rect2 = new CellRect(rp.rect.minX, rp.rect.minZ + num2, rp.rect.Width, pathwayWidthZ); ResolveParams resolveParams2 = rp; resolveParams2.rect = rect2; resolveParams2.floorDef = floorDef; resolveParams2.streetHorizontal = new bool?(true); BaseGen.symbolStack.Push("street", resolveParams2); num2 += roomSize2 + pathwayWidthZ; } num = 0; num2 = 0; this.children.Clear(); for (int k = 0; k < roomsPerRowX; k++) { for (int l = 0; l < roomsPerRowZ; l++) { SymbolResolver_BasePart_Outdoors_Division_Grid.Child child = new SymbolResolver_BasePart_Outdoors_Division_Grid.Child(); child.rect = new CellRect(rp.rect.minX + num, rp.rect.minZ + num2, roomSize, roomSize2); child.gridX = k; child.gridY = l; this.children.Add(child); num2 += roomSize2 + pathwayWidthZ; } num += roomSize + pathwayWidthX; num2 = 0; } this.MergeRandomChildren(); this.children.Shuffle <SymbolResolver_BasePart_Outdoors_Division_Grid.Child>(); for (int m = 0; m < this.children.Count; m++) { if (thingDef != null) { IntVec3 c = new IntVec3(this.children[m].rect.maxX + 1, 0, this.children[m].rect.maxZ); if (rp.rect.Contains(c) && c.Standable(map)) { ResolveParams resolveParams3 = rp; resolveParams3.rect = CellRect.SingleCell(c); resolveParams3.singleThingDef = thingDef; BaseGen.symbolStack.Push("thing", resolveParams3); } } ResolveParams resolveParams4 = rp; resolveParams4.rect = this.children[m].rect; BaseGen.symbolStack.Push("basePart_outdoors", resolveParams4); } }
private bool TryResolveRandomOption(int maxWidthHeightDiff, int maxPathwayWidthDiff, ResolveParams rp) { SymbolResolver_BasePart_Outdoors_Division_Grid.options.Clear(); for (int i = 0; i < this.optionsX.Count; i++) { int first = this.optionsX[i].First; int second = this.optionsX[i].Second; int roomSize = this.GetRoomSize(first, second, rp.rect.Width); for (int j = 0; j < this.optionsZ.Count; j++) { int first2 = this.optionsZ[j].First; int second2 = this.optionsZ[j].Second; int roomSize2 = this.GetRoomSize(first2, second2, rp.rect.Height); if (Mathf.Abs(roomSize - roomSize2) <= maxWidthHeightDiff && Mathf.Abs(second - second2) <= maxPathwayWidthDiff) { SymbolResolver_BasePart_Outdoors_Division_Grid.options.Add(new Pair <Pair <int, int>, Pair <int, int> >(this.optionsX[i], this.optionsZ[j])); } } } if (SymbolResolver_BasePart_Outdoors_Division_Grid.options.Any <Pair <Pair <int, int>, Pair <int, int> > >()) { Pair <Pair <int, int>, Pair <int, int> > pair = SymbolResolver_BasePart_Outdoors_Division_Grid.options.RandomElement <Pair <Pair <int, int>, Pair <int, int> > >(); this.ResolveOption(pair.First.First, pair.First.Second, pair.Second.First, pair.Second.Second, rp); return(true); } return(false); }