public void MountOn(Pawn pawn)
        {
            if (Driver != null)
            {
                return;
            }

            Building_Reloadable turret = (parent as Building_Reloadable);

            if (turret != null)
            {
                turret.dontReload = true;
            }

            // Check to make pawns not mount two vehicles at once
            if (ToolsForHaulUtility.IsDriver(pawn))
            {
                if (ToolsForHaulUtility.GetCartByDriver(pawn) != null)
                {
                    ToolsForHaulUtility.GetCartByDriver(pawn).mountableComp.Dismount();
                }

                if (ToolsForHaulUtility.GetTurretByDriver(pawn) != null)
                {
                    ToolsForHaulUtility.GetTurretByDriver(pawn).mountableComp.Dismount();
                }
            }

            Driver = pawn;

            MapComponent_ToolsForHaul.currentVehicle.Add(pawn, parent);

            if (Driver.RaceProps.Humanlike)
            {
                Driver.RaceProps.makesFootprints = false;
            }

            if (pawn.RaceProps.Humanlike)
            {
                driverComp = new CompDriver {
                    vehicle = parent as Building
                };
                Driver?.AllComps?.Add(driverComp);
                driverComp.parent = Driver;
            }

            Vehicle_Cart vehicleCart = parent as Vehicle_Cart;

            if (vehicleCart != null)
            {
                // Set faction of vehicle to whoever mounts it
                if (vehicleCart.Faction != Driver.Faction && vehicleCart.ClaimableBy(Driver.Faction))
                {
                    parent.SetFaction(Driver.Faction);
                }


                if (vehicleCart.IsCurrentlyMotorized())
                {
                    SoundInfo info = SoundInfo.InWorld(parent);
                    sustainerAmbient = vehicleCart.vehicleComp.compProps.soundAmbient.TrySpawnSustainer(info);
                }


                return;
            }

            Vehicle_Turret vehicleTurret = parent as Vehicle_Turret;

            if (vehicleTurret != null)
            {
                // Set faction of vehicle to whoever mounts it
                if (vehicleTurret.Faction != Driver.Faction && vehicleTurret.ClaimableBy(Driver.Faction))
                {
                    parent.SetFaction(Driver.Faction);
                }

                if (vehicleTurret.IsCurrentlyMotorized())
                {
                    SoundInfo info = SoundInfo.InWorld(parent);
                    sustainerAmbient = vehicleTurret.vehicleComp.compProps.soundAmbient.TrySpawnSustainer(info);
                }

                return;
            }
        }
Beispiel #2
0
        public override Job JobOnThing(Pawn pawn, Thing t)
        {
            Vehicle_Cart cart = null;

            if (!HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t))
            {
                return(null);
            }

            // Vehicle selection

            if (ToolsForHaulUtility.IsDriver(pawn))
            {
                cart = ToolsForHaulUtility.GetCartByDriver(pawn);

                if (cart == null)
                {
                    //  JobFailReason.Is("Can't haul with military vehicle");
                    return(ToolsForHaulUtility.DismountInBase(pawn, MapComponent_ToolsForHaul.currentVehicle[pawn]));
                }
            }


            if (cart == null)
            {
                cart = RightTools.GetRightVehicle(pawn, WorkTypeDefOf.Hauling, t) as Vehicle_Cart;

                if (cart == null)
                {
                    return(null);
                }
            }



            if (cart.IsBurning())
            {
                JobFailReason.Is(ToolsForHaulUtility.BurningLowerTrans);
                return(null);
            }

            if (!cart.allowances.Allows(t))
            {
                JobFailReason.Is("Cart does not allow that thing");
                return(null);
            }

            if (ListerHaulables.ThingsPotentiallyNeedingHauling().Count == 0 && cart.storage.Count == 0)
            {
                JobFailReason.Is("NoHaulable".Translate());
                return(null);
            }

            if (Find.SlotGroupManager.AllGroupsListInPriorityOrder.Count == 0)
            {
                JobFailReason.Is(ToolsForHaulUtility.NoEmptyPlaceLowerTrans);
                return(null);
            }

            if (ToolsForHaulUtility.AvailableAnimalCart(cart) || ToolsForHaulUtility.AvailableVehicle(pawn, cart))
            {
                return(ToolsForHaulUtility.HaulWithTools(pawn, cart, t));
            }
            JobFailReason.Is(ToolsForHaulUtility.NoAvailableCart);
            return(null);
        }