示例#1
0
 public Dialog_LoadShip(Map map, ShipBase ship)
 {
     this.map        = map;
     this.ship       = ship;
     this.forcePause = true;
     this.absorbInputAroundWindow = true;
 }
示例#2
0
        public static float ApproxDaysWorthOfFood_Ship(ShipBase ship, List <TransferableOneWay> transferables, bool canEatPlants)
        {
            tmpTransferables.Clear();

            for (int i = 0; i < transferables.Count; i++)
            {
                TransferableOneWay oneWay = new TransferableOneWay();
                oneWay.things.AddRange(transferables[i].things);
                oneWay.AdjustTo(transferables[i].CountToTransfer);
                Pawn pawn = oneWay.AnyThing as Pawn;

                tmpTransferables.Add(oneWay);
            }

            foreach (Pawn current in ship.GetDirectlyHeldThings().Where(x => x is Pawn))
            {
                DropShipUtility.AddThingsToTransferables(tmpTransferables, current);
            }
            for (int i = 0; i < ship.GetDirectlyHeldThings().Count; i++)
            {
                if (!(ship.GetDirectlyHeldThings()[i] is Pawn))
                {
                    DropShipUtility.AddThingsToTransferables(tmpTransferables, ship.GetDirectlyHeldThings()[i]);
                }
            }
            return(DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(tmpTransferables, canEatPlants, IgnorePawnsInventoryMode.DontIgnore));
        }
示例#3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 10));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch));

            Toil toil = new Toil();

            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = 50;
            toil.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f);
            yield return(toil);

            yield return(new Toil
            {
                initAction = delegate
                {
                    ShipBase ship = (ShipBase)TargetA.Thing;
                    Action action = delegate
                    {
                        ship.TryAcceptThing(pawn, true);
                    };

                    ship.compShip.Notify_PawnEntered(this.pawn);

                    action();
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            yield break;
        }
示例#4
0
 private ShipBase FindAppropriateShipToEnter(Pawn p)
 {
     if (p.mindState.duty != null && p.mindState.duty.focus != null)
     {
         ShipBase ship = (ShipBase)p.mindState.duty.focus;
         if (ship != null)
         {
             List <TransferableOneWay> leftToLoad = ship.compShip.leftToLoad;
             if (leftToLoad != null)
             {
                 for (int j = 0; j < leftToLoad.Count; j++)
                 {
                     if (leftToLoad[j].AnyThing is Pawn)
                     {
                         List <Thing> things = leftToLoad[j].things;
                         for (int k = 0; k < things.Count; k++)
                         {
                             if (things[k] == p)
                             {
                                 return(ship);
                             }
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
示例#5
0
        public static float ApproxDaysWorthOfFood_Ship(ShipBase ship, List <TransferableOneWay> transferables, bool canEatPlants)
        {
            tmpTransferables.Clear();

            for (int i = 0; i < transferables.Count; i++)
            {
                TransferableOneWay oneWay = new TransferableOneWay();
                oneWay.things.AddRange(transferables[i].things);
                oneWay.AdjustTo(transferables[i].CountToTransfer);
                Pawn pawn = oneWay.AnyThing as Pawn;

                tmpTransferables.Add(oneWay);
            }

            foreach (Pawn current in ship.GetDirectlyHeldThings().Where(x => x is Pawn))
            {
                DropShipUtility.AddThingsToTransferables(tmpTransferables, current);
            }
            for (int i = 0; i < ship.GetDirectlyHeldThings().Count; i++)
            {
                if (!(ship.GetDirectlyHeldThings()[i] is Pawn))
                {
                    DropShipUtility.AddThingsToTransferables(tmpTransferables, ship.GetDirectlyHeldThings()[i]);
                }
            }
            var potentialFood = tmpTransferables.Where(t => (t.AnyThing is Pawn) == false).SelectMany(x => x.things).ToList();
            var pawns         = tmpTransferables.Where(t => t.AnyThing is Pawn).SelectMany(x => x.things).Cast <Pawn>().ToList();

            return(DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(pawns, potentialFood, 0, IgnorePawnsInventoryMode.DontIgnore, ship.Faction));
        }
示例#6
0
        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 void AddShip(ShipBase ship, bool justLeftTheMap)
 {
     if (!this.ships.Contains(ship))
     {
         this.ships.Add(ship);
     }
 }
示例#8
0
        public static Job JobLoadShipCargo(Pawn p, ShipBase ship)
        {
            if (p.jobs.jobQueue.Any(x => x.job.def == ShipNamespaceDefOfs.LoadContainerMultiplePawns))
            {
                return(null);
            }
            Thing thing = LoadShipCargoUtility.FindThingToLoad(p, ship);
            TransferableOneWay transferable = TransferableUtility.TransferableMatchingDesperate(thing, ship.compShip.leftToLoad);

            if (thing != null && transferable != null)
            {
                int thingCount = transferable.CountToTransfer;
                if (thingCount < 0)
                {
                    thingCount = 1;
                }
                return(new Job(ShipNamespaceDefOfs.LoadContainerMultiplePawns, thing, ship)
                {
                    count = thingCount,
                    ignoreForbidden = true,
                    playerForced = true
                });
            }

            else
            {
                Log.Message("No Transferable found.");
            }
            return(null);
        }
示例#9
0
        public static float ApproxDaysWorthOfFood_Ship(ShipBase ship, List <TransferableOneWay> transferables)
        {
            List <TransferableOneWay> tmp = new List <TransferableOneWay>();

            tmp.AddRange(transferables);

            List <TransferableOneWay> tmpPawns = new List <TransferableOneWay>();
            List <TransferableOneWay> tmpItems = new List <TransferableOneWay>();

            foreach (Pawn current in ship.GetInnerContainer().Where(x => x is Pawn))
            {
                if (!current.RaceProps.Eats(FoodTypeFlags.Plant))
                {
                    DropShipUtility.AddThingsToTransferables(tmp, current);
                }
            }
            for (int i = 0; i < ship.GetInnerContainer().Count; i++)
            {
                if (!(ship.GetInnerContainer()[i] is Pawn))
                {
                    DropShipUtility.AddThingsToTransferables(tmp, ship.GetInnerContainer()[i]);
                }
            }

            return(DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(tmp));
        }
示例#10
0
        public static void DrawDropSpotShadow(ShipBase ship, int ticks, ShipBase_Traveling travelingShip = null)
        {
            if (ticks < 0)
            {
                ticks = 0;
            }

            Vector3 result = Gen.TrueCenter(ship);

            if (travelingShip != null)
            {
                result = travelingShip.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.FlyingItem);
            }
            result  += DropShipUtility.drawOffsetFor(ship, ticks, true);
            result.y = Altitudes.AltitudeFor(AltitudeLayer.Shadows);

            Color white = Color.white;

            white.a = Mathf.InverseLerp(200f, 150f, (float)ticks);

            DropShipUtility.shadowPropertyBlock.SetColor(ShaderIDs.ColorId, white);
            Matrix4x4 matrix = default(Matrix4x4);

            matrix.SetTRS(result, ship.compShip.parent.Rotation.AsQuat, new Vector3(1f, 1f, 1f));
            Graphics.DrawMesh(ship.compShip.parent.Graphic.MeshAt(ship.compShip.parent.Rotation), matrix, ship.compShip.dropShadow.MatSingle, 0, null, 0, DropShipUtility.shadowPropertyBlock);
        }
示例#11
0
 public Dialog_LoadShipCargo(Map map, ShipBase ship)
 {
     this.map                     = map;
     this.ship                    = ship;
     this.closeOnEscapeKey        = true;
     this.forcePause              = true;
     this.absorbInputAroundWindow = true;
 }
示例#12
0
        public static void NotifyAddedPostfix(ref ThingOwner __instance, Thing item)
        {
            ShipBase ship = __instance.Owner as ShipBase;

            if (ship != null)
            {
                ship.compShip.NotifyItemAdded(item, item.stackCount);
            }
        }
示例#13
0
        public static void NotifyAddedAndMergedWithPostfix(ref ThingOwner __instance, Thing item, int mergedCount)
        {
            ShipBase ship = __instance.Owner as ShipBase;

            if (ship != null)
            {
                ship.compShip.NotifyItemAdded(item, mergedCount);
            }
        }
示例#14
0
 public Dialog_LoadShipCargo(Map map, ShipBase ship)
 {
     this.map                               = map;
     this.ship                              = ship;
     this.closeOnEscapeKey                  = true;
     this.forcePause                        = true;
     this.absorbInputAroundWindow           = true;
     OHUShipsModSettings.CargoLoadingActive = true;
 }
示例#15
0
 public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
 {
     if (t is ShipBase)
     {
         ShipBase ship = (ShipBase)t;
         return(ship.weaponsToInstall.Count > 0 && !t.Map.reservationManager.IsReservedByAnyoneOf(t, pawn.Faction));
     }
     return(false);
 }
示例#16
0
 public override bool HasJobOnThing(Pawn pawn, Thing t)
 {
     if (t is ShipBase)
     {
         ShipBase ship = (ShipBase)t;
         return(ship.weaponsToUninstall.Count > 0);
     }
     return(false);
 }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnDestroyedNullOrForbidden(TargetIndex.B);
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

            yield return(Toils_Reserve.ReserveQueue(TargetIndex.A, 1));

            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1));

            yield return(Toils_Reserve.ReserveQueue(TargetIndex.B, 1));

            Toil toil = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnSomeonePhysicallyInteracting(TargetIndex.A);

            yield return(toil);

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A, false, true));

            yield return(Toils_Haul.JumpIfAlsoCollectingNextTargetInQueue(toil, TargetIndex.A));

            Toil toil2 = Toils_Goto.Goto(TargetIndex.B, PathEndMode.ClosestTouch);

            yield return(toil2);

            Toil toil3 = new Toil();

            toil3.defaultCompleteMode = ToilCompleteMode.Delay;
            toil3.defaultDuration     = 500;
            toil3.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f);
            yield return(toil3);

            yield return(new Toil
            {
                initAction = delegate
                {
                    ShipBase ship = (ShipBase)TargetB.Thing;
                    ThingWithComps thing = (ThingWithComps)TargetA.Thing;
                    CompShipWeapon comp = thing.TryGetComp <CompShipWeapon>();

                    Action action = delegate
                    {
                        if (ship.TryInstallTurret(comp.slotToInstall, comp))
                        {
                            this.pawn.carryTracker.GetInnerContainer().Remove(TargetA.Thing);
                            ship.weaponsToInstall.Remove(comp.slotToInstall);
                        }
                    };

                    action();
                },

                defaultCompleteMode = ToilCompleteMode.Instant
            });

            yield break;
        }
示例#18
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            ShipBase ship = this.FindAppropriateShipToEnter(pawn);

            if (ship == null || !pawn.CanReserveAndReach(ship, PathEndMode.Touch, Danger.Deadly, 1))
            {
                return(null);
            }
            return(new Job(ShipNamespaceDefOfs.EnterShip, ship));
        }
示例#19
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            ShipBase ship = (ShipBase)pawn.mindState.duty.focus;

            if (LoadShipCargoUtility.HasJobOnShip(pawn, ship))
            {
                return(LoadShipCargoUtility.JobLoadShipCargo(pawn, ship));
            }

            return(null);
        }
        public ShipBase_Traveling(ShipBase ship, bool launchAsFleet = false, ShipArrivalAction arrivalAction = ShipArrivalAction.StayOnWorldMap)
        {
            this.containingShip  = ship;
            this.def             = ship.compShip.sProps.LeavingShipDef;
            this.def.size        = ship.def.size;
            this.def.graphicData = ship.def.graphicData;
            this.launchAsFleet   = launchAsFleet;
            this.Rotation        = ship.Rotation;

            this.arrivalAction = arrivalAction;
        }
示例#21
0
        public static void DropSingleShip(Map map, IntVec3 dropLoc, ShipBase ship, ShipArrivalAction arrivalAction, bool dropPawns = true, bool dropItems = false)
        {
            ship.drawTickOffset          = ship.compShip.sProps.TicksToImpact + Rand.Range(10, 60);
            ship.ActivatedLaunchSequence = false;
            ship.shipState = ShipState.Incoming;
            ShipBase_Traveling incomingShip = new ShipBase_Traveling(ship, false, arrivalAction);

            incomingShip.dropPawnsOnTochdown  = dropPawns;
            incomingShip.dropItemsOnTouchdown = dropItems;
            GenSpawn.Spawn(incomingShip, dropLoc, map);
        }
示例#22
0
        public int MaxLaunchDistanceEverPossible(bool LaunchAsFleet, bool includeReturnFlight = false)
        {
            if (LaunchAsFleet && this.fleetID != -1)
            {
                List <ShipBase> fleetShips = DropShipUtility.currentShipTracker.ShipsInFleet(this.fleetID);

                ShipBase lowest = fleetShips.Aggregate((curMin, x) => (curMin == null || x.MaxLaunchDistanceEverPossible(false) < curMin.MaxLaunchDistanceEverPossible(false) ? x : curMin));
                return((int)((lowest.MaxShipFlightTicks * lowest.compShip.sProps.WorldMapTravelSpeedFactor * 0.0000416f) / 0.005F));
            }
            return((int)((this.MaxShipFlightTicks * this.compShip.sProps.WorldMapTravelSpeedFactor * 0.0000416f) / 0.005F));
        }
示例#23
0
 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);
     }
 }
示例#24
0
        public override Job JobOnThing(Pawn pawn, Thing t)
        {
            ShipBase ship = (ShipBase)t;
            KeyValuePair <ShipWeaponSlot, Thing> weaponSpecs = ship.weaponsToUninstall.RandomElement();

            weaponSpecs.Value.TryGetComp <CompShipWeapon>().slotToInstall = weaponSpecs.Key;

            return(new Job(ShipNamespaceDefOfs.UninstallShipWeapon, weaponSpecs.Value, ship)
            {
                count = 1,
                ignoreForbidden = false
            });
        }
示例#25
0
 private void InterfaceDrop(Thing thing, ShipBase ship)
 {
     ship.GetDirectlyHeldThings().TryDrop(thing, ThingPlaceMode.Near, out thing);
     if (thing is Pawn)
     {
         Pawn pawn     = (Pawn)thing;
         Lord LoadLord = LoadShipCargoUtility.FindLoadLord(ship, ship.Map);
         if (LoadLord != null)
         {
             LoadLord.ownedPawns.Remove(pawn);
         }
     }
 }
示例#26
0
        public int MaxLaunchDistanceEverPossible(bool LaunchAsFleet)
        {
            float fuel = this.refuelableComp.Fuel;

            if (LaunchAsFleet && this.fleetID != -1)
            {
                List <ShipBase> fleetShips = DropShipUtility.currentShipTracker.ShipsInFleet(this.fleetID);
                ShipBase        lowest     = fleetShips.Aggregate((curMin, x) => (curMin == null || x.refuelableComp.Props.fuelCapacity < curMin.refuelableComp.Props.fuelCapacity ? x : curMin));
                fuel = lowest.refuelableComp.Fuel;
            }

            return(Mathf.FloorToInt(fuel / 2.25f));
        }
 public ShipBase_Traveling(ShipBase ship, RimWorld.Planet.GlobalTargetInfo target, PawnsArrivalModeDef arriveMode, ShipArrivalAction arrivalAction = ShipArrivalAction.StayOnWorldMap, bool leavingForTarget = true)
 {
     this.containingShip   = ship;
     this.def              = ship.compShip.sProps.LeavingShipDef;
     this.def.size         = ship.def.size;
     this.def.graphicData  = ship.def.graphicData;
     this.destinationTile  = target.Tile;
     this.destinationCell  = target.Cell;
     this.pawnArriveMode   = arriveMode;
     this.leavingForTarget = leavingForTarget;
     this.Rotation         = ship.Rotation;
     this.arrivalAction    = arrivalAction;
 }
        public static Toil EnterShip(Pawn pawn, ShipBase ship)
        {
            Toil gotoShip = new Toil
            {
                initAction = delegate
                {
                    ship.TryAcceptThing(pawn, true);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            };

            return(gotoShip);
        }
示例#29
0
        private void DrawFleetMember(ref float curX, float curY, ShipBase ship)
        {
            Rect buttonRect = new Rect(curX, curY, 20f, 20f);

            GUI.DrawTexture(buttonRect, ship.compShip.fleetIconTexture);
            if (Mouse.IsOver(buttonRect))
            {
                Rect      rect = new Rect(buttonRect.x, buttonRect.y, 100f, 30f);
                TipSignal tip  = ship.LabelCap + " : " + ship.ShipNick;
                TooltipHandler.TipRegion(rect, tip);
            }
            curX += 30f;
        }
示例#30
0
        public static void ReimbarkWorldPawnsForLandedShip(ShipBase ship)
        {
            List <Thing> pawnsToMove = new List <Thing>();

            foreach (Pawn current in ship.worldPawns)
            {
                if (!ship.GetInnerContainer().Contains(current))
                {
                    pawnsToMove.Add(current);
                }
            }
            ship.GetInnerContainer().TryAddMany(pawnsToMove);
            ship.worldPawns.RemoveAll(x => pawnsToMove.Contains(x));
        }