public static List <ShipBase> CreateDropShips(List <Pawn> pawns, Faction faction, List <ThingDef> fixedShipDefs = null) { List <ShipBase> shipsToDrop = new List <ShipBase>(); List <ThingDef> defs = new List <ThingDef>(); if (fixedShipDefs.NullOrEmpty()) { defs.AddRange(DropShipUtility.AvailableDropShipsForFaction(faction)); } else { defs.AddRange(fixedShipDefs); } defs.OrderBy(x => x.GetCompProperties <CompProperties_Ship>().maxPassengers); int num = 0; while (num < pawns.Count) { ShipBase newShip = (ShipBase)ThingMaker.MakeThing(defs.RandomElementByWeight(x => x.GetCompProperties <CompProperties_Ship>().maxPassengers)); newShip.SetFaction(faction); newShip.ShouldSpawnFueled = true; shipsToDrop.Add(newShip); num += newShip.compShip.sProps.maxPassengers; } DropShipUtility.LoadNewCargoIntoRandomShips(pawns.Cast <Thing>().ToList(), shipsToDrop); return(shipsToDrop); }
public override void GenerateIntoMap(Map map) { if (Find.TickManager.TicksGame < 1000) { ShipBase newShip = (ShipBase)ThingMaker.MakeThing(this.ShipDef); newShip.SetFaction(Faction.OfPlayer); Thing initialFuel = ThingMaker.MakeThing(ShipNamespaceDefOfs.Chemfuel); newShip.refuelableComp.Refuel(500); this.StartingShips.Add(newShip); DropShipUtility.LoadNewCargoIntoRandomShips(this.PlayerStartingThings().ToList(), this.StartingShips); DropShipUtility.DropShipGroups(map.Center, map, this.StartingShips, ShipArrivalAction.EnterMapFriendly); } }
public void ReloadStockIntoShip() { List <Thing> allCargo = this.AllLandedShipCargo.ToList <Thing>(); allCargo.AddRange(this.PawnsListForReading.Cast <Thing>().ToList()); List <Thing> remainingCargo = new List <Thing>(); for (int i = 0; i < this.PawnsListForReading.Count; i++) { this.tmpThingsToRemove.Clear(); ThingOwner carrier = this.PawnsListForReading[i].inventory.GetDirectlyHeldThings(); if (carrier != null) { for (int k = 0; k < carrier.Count; k++) { if (allCargo.Contains(carrier[k])) { this.tmpThingsToRemove.Add(carrier[k]); } else { remainingCargo.Add(carrier[k]); } } carrier.RemoveAll(x => this.tmpThingsToRemove.Contains(x)); } } List <Thing> stockInShips = new List <Thing>(); foreach (ShipBase ship in this.ships) { stockInShips.AddRange(ship.GetDirectlyHeldThings()); } for (int i = 0; i < allCargo.Count; i++) { if (!stockInShips.Contains(allCargo[i])) { remainingCargo.Add(allCargo[i]); } } DropShipUtility.LoadNewCargoIntoRandomShips(remainingCargo, this.ships); }