/// <summary> /// Generate VehicleSkyfaller with newly generated vehicle /// </summary> /// <param name="def">test</param> /// <param name="vehicleDef"></param> /// <param name="faction"></param> public static VehicleSkyfaller MakeSkyfaller(ThingDef def, VehicleDef vehicleDef, Faction faction, bool randomizeColors = false, bool randomizeMask = false, bool cleanSlate = true) { VehicleSkyfaller skyfaller = (VehicleSkyfaller)ThingMaker.MakeThing(def); skyfaller.vehicle = VehicleSpawner.GenerateVehicle(new VehicleGenerationRequest(vehicleDef, faction, randomizeColors, randomizeMask, cleanSlate)); return(skyfaller); }
private static void SpawnVehicleWithFaction() { List <DebugMenuOption> vehicles = new List <DebugMenuOption>(); List <DebugMenuOption> factions = new List <DebugMenuOption>(); Faction factionLocal = null; foreach (Faction faction in Find.World.factionManager.GetFactions(true, false, true, TechLevel.Undefined).OrderBy(f => f.def.defName)) { factions.Add(new DebugMenuOption(faction.def.defName, DebugMenuOptionMode.Action, delegate() { factionLocal = faction; foreach (VehicleDef vehicleDef in DefDatabase <VehicleDef> .AllDefs.OrderBy(d => d.defName)) { vehicles.Add(new DebugMenuOption(vehicleDef.defName, DebugMenuOptionMode.Tool, delegate() { Faction factionAssigned = faction; VehicleSpawner.SpawnVehicleRandomized(vehicleDef, Verse.UI.MouseCell(), Find.CurrentMap, factionLocal is null ? factionAssigned : factionLocal, Rot4.North, true); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(vehicles)); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(factions)); }
public static bool CompleteConstructionVehicle(Pawn worker, Frame __instance) { if (__instance.def.entityDefToBuild is VehicleBuildDef def && def.thingToSpawn != null) { VehiclePawn vehicle = VehicleSpawner.GenerateVehicle(def.thingToSpawn, worker.Faction); __instance.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish); Map map = __instance.Map; __instance.Destroy(DestroyMode.Vanish); if (def.soundBuilt != null) { def.soundBuilt.PlayOneShot(new TargetInfo(__instance.Position, map, false)); } vehicle.SetFaction(worker.Faction); GenSpawn.Spawn(vehicle, __instance.Position, map, __instance.Rotation, WipeMode.FullRefund, false); worker.records.Increment(RecordDefOf.ThingsConstructed); vehicle.Rename(); //Quality? //Art? //Tale RecordTale LongConstructionProject? AchievementsHelper.TriggerVehicleConstructionEvent(vehicle); return(false); } return(true); }
private static void SpawnVehicleRandomized() { List <DebugMenuOption> list = new List <DebugMenuOption>(); foreach (VehicleDef vehicleDef in DefDatabase <VehicleDef> .AllDefs.OrderBy(d => d.defName)) { list.Add(new DebugMenuOption(vehicleDef.defName, DebugMenuOptionMode.Tool, delegate() { Faction faction = Faction.OfPlayer; VehicleSpawner.SpawnVehicleRandomized(vehicleDef, Verse.UI.MouseCell(), Find.CurrentMap, faction); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list)); }
private static void SpawnCrashingShuttle() { List <DebugMenuOption> list = new List <DebugMenuOption>(); foreach (VehicleDef vehicleDef in DefDatabase <VehicleDef> .AllDefs.OrderBy(d => d.defName)) { list.Add(new DebugMenuOption(vehicleDef.defName, DebugMenuOptionMode.Tool, delegate() { Faction faction = Faction.OfPlayer; VehiclePawn vehicle = VehicleSpawner.GenerateVehicle(vehicleDef, faction); vehicle.CompVehicleLauncher?.InitializeLaunchProtocols(false); AerialVehicleInFlight flyingVehicle = (AerialVehicleInFlight)WorldObjectMaker.MakeWorldObject(WorldObjectDefOfVehicles.AerialVehicle); flyingVehicle.vehicle = vehicle; flyingVehicle.vehicle.CompVehicleLauncher.inFlight = true; flyingVehicle.Tile = Find.CurrentMap.Tile; flyingVehicle.SetFaction(vehicle.Faction); flyingVehicle.Initialize(); (VehicleIncidentDefOf.BlackHawkDown.Worker as IncidentWorker_ShuttleDowned).TryExecuteEvent(flyingVehicle, null, Verse.UI.MouseCell()); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list)); }
/// <summary> /// Catch All for vehicle related Things spawned in. Handles GodMode placing of vehicle buildings, corrects immovable spawn locations, and registers air defenses /// </summary> /// <param name="newThing"></param> /// <param name="loc"></param> /// <param name="map"></param> /// <param name="rot"></param> /// <param name="__result"></param> /// <param name="wipeMode"></param> /// <param name="respawningAfterLoad"></param> /// <returns></returns> public static bool RegisterThingSpawned(Thing newThing, ref IntVec3 loc, Map map, Rot4 rot, Thing __result, WipeMode wipeMode, bool respawningAfterLoad) { if (newThing.def is VehicleBuildDef def) { if (!VehicleMod.settings.debug.debugSpawnVehicleBuildingGodMode && newThing.HitPoints == newThing.MaxHitPoints) { VehiclePawn vehiclePawn = VehicleSpawner.GenerateVehicle(def.thingToSpawn, newThing.Faction); // (VehiclePawn)PawnGenerator.GeneratePawn(def.thingToSpawn); if (def.soundBuilt != null) { def.soundBuilt.PlayOneShot(new TargetInfo(loc, map, false)); } VehiclePawn vehicleSpawned = (VehiclePawn)GenSpawn.Spawn(vehiclePawn, loc, map, rot, WipeMode.FullRefund, false); vehicleSpawned.Rename(); __result = vehicleSpawned; AchievementsHelper.TriggerVehicleConstructionEvent(vehicleSpawned); return(false); } } else if (newThing is VehiclePawn vehicle) { bool standable = true; foreach (IntVec3 c in vehicle.PawnOccupiedCells(loc, rot)) { if (!c.InBounds(map) || (vehicle.IsBoat() ? GenGridVehicles.Impassable(c, map) : GenGrid.Impassable(c, map))) { standable = false; break; } } bool validator(IntVec3 c) { foreach (IntVec3 c2 in vehicle.PawnOccupiedCells(c, rot)) { if (vehicle.IsBoat() ? GenGridVehicles.Impassable(c, map) : GenGrid.Impassable(c, map)) { return(false); } } return(true); } if (standable) { return(true); } if (!CellFinder.TryFindRandomCellNear(loc, map, 20, validator, out IntVec3 newLoc, 100)) { Log.Error($"Unable to find location to spawn {newThing.LabelShort} after 100 attempts. Aborting spawn."); return(false); } loc = newLoc; } else if (newThing is Pawn pawn && !pawn.Dead) { try { var positionManager = map.GetCachedMapComponent <VehiclePositionManager>(); if (positionManager.PositionClaimed(loc)) { VehiclePawn inPlaceVehicle = positionManager.ClaimedBy(loc); CellRect occupiedRect = inPlaceVehicle.OccupiedRect().ExpandedBy(1); Rand.PushState(); for (int i = 0; i < 3; i++) { IntVec3 newLoc = occupiedRect.EdgeCells.Where(c => GenGrid.InBounds(c, map) && GenGrid.Standable(c, map)).RandomElementWithFallback(inPlaceVehicle.Position); if (occupiedRect.EdgeCells.Contains(newLoc)) { loc = newLoc; break; } occupiedRect = occupiedRect.ExpandedBy(1); } Rand.PopState(); } } catch (Exception ex) { Log.Error($"Pawn {newThing.Label} could not be readjusted for spawn location. Exception={ex.Message}"); } }