Esempio n. 1
0
 public static void DebugWriteHaulingPawn(Pawn pawn)
 {
     AppendLine(pawn.LabelCap + " Report: Cart " + ToolsForHaulUtility.Cart.Count + " Job: " + (pawn.CurJob != null ? pawn.CurJob.def.defName : "No Job")
                + " Backpack: " + (ToolsForHaulUtility.TryGetBackpack(pawn) != null ? "True" : "False")
                + " lastGivenWorkType: " + pawn.mindState.lastGivenWorkType);
     foreach (Pawn other in Find.MapPawns.FreeColonistsSpawned)
     {
         //Vanilla haul or Haul with backpack
         if (other.CurJob != null && (other.CurJob.def == JobDefOf.HaulToCell || other.CurJob.def == HaulJobDefOf.HaulWithBackpack))
         {
             AppendLine(other.LabelCap + " Job: " + other.CurJob.def.defName
                        + " Backpack: " + (ToolsForHaulUtility.TryGetBackpack(other) != null ? "True" : "False")
                        + " lastGivenWorkType: " + other.mindState.lastGivenWorkType);
         }
     }
     foreach (Vehicle_Cart cart in ToolsForHaulUtility.Cart)
     {
         string driver = cart.mountableComp.IsMounted ? cart.mountableComp.Driver.LabelCap : "No Driver";
         string state  = "";
         if (cart.IsForbidden(pawn.Faction))
         {
             state = string.Concat(state, "Forbidden ");
         }
         if (pawn.CanReserveAndReach(cart, PathEndMode.Touch, Danger.Some))
         {
             state = string.Concat(state, "CanReserveAndReach ");
         }
         if (ToolsForHaulUtility.AvailableVehicle(pawn, cart))
         {
             state = string.Concat(state, "AvailableCart ");
         }
         if (ToolsForHaulUtility.AvailableAnimalCart(cart))
         {
             state = string.Concat(state, "AvailableAnimalCart ");
         }
         Pawn reserver = Find.Reservations.FirstReserverOf(cart, Faction.OfPlayer);
         if (reserver != null)
         {
             state = string.Concat(state, reserver.LabelCap, " Job: ", reserver.CurJob.def.defName);
         }
         AppendLine(cart.LabelCap + "- " + driver + ": " + state);
     }
     LogMessage();
 }
Esempio n. 2
0
        /// <summary>
        /// Selects the appropriate vehicle by worktype
        /// </summary>
        /// <param name="pawn"></param>
        /// <param name="worktype"></param>
        /// <returns></returns>
        public static Thing GetRightVehicle(Pawn pawn, WorkTypeDef worktype, Thing t = null)
        {
            Thing cart = null;

            if (worktype.Equals(WorkTypeDefOf.Hunting))
            {
                bool skip = false;
                IOrderedEnumerable <Thing> orderedEnumerable =
                    ToolsForHaulUtility.CartTurret.OrderBy(x => pawn.Position.DistanceToSquared(x.Position));
                foreach (Thing thing in orderedEnumerable)
                {
                    Vehicle_Turret vehicleTurret = (Vehicle_Turret)thing;
                    if (vehicleTurret == null)
                    {
                        continue;
                    }
                    if (!ToolsForHaulUtility.AvailableVehicle(pawn, vehicleTurret))
                    {
                        continue;
                    }
                    if (!vehicleTurret.IsCurrentlyMotorized())
                    {
                        continue;
                    }
                    if (vehicleTurret.vehicleComp.tankLeaking)
                    {
                        continue;
                    }
                    cart = vehicleTurret;
                    skip = true;
                    break;
                }
                if (!skip)
                {
                    IOrderedEnumerable <Thing> orderedEnumerable2 =
                        ToolsForHaulUtility.Cart.OrderBy(x => pawn.Position.DistanceToSquared(x.Position));
                    foreach (Thing thing in orderedEnumerable2)
                    {
                        Vehicle_Cart vehicleCart = (Vehicle_Cart)thing;
                        if (vehicleCart == null)
                        {
                            continue;
                        }
                        if (!ToolsForHaulUtility.AvailableVehicle(pawn, vehicleCart))
                        {
                            continue;
                        }
                        if (!vehicleCart.IsCurrentlyMotorized())
                        {
                            continue;
                        }
                        if (vehicleCart.vehicleComp.tankLeaking)
                        {
                            continue;
                        }
                        cart = vehicleCart;
                        break;
                    }
                }
            }
            if (worktype.Equals(WorkTypeDefOf.Hauling))
            {
                IOrderedEnumerable <Thing> orderedEnumerable2 =
                    ToolsForHaulUtility.Cart.OrderByDescending(x => (x as Vehicle_Cart).MaxItem).ThenBy(x => pawn.Position.DistanceToSquared(x.Position));

                foreach (Thing thing in orderedEnumerable2)
                {
                    Vehicle_Cart vehicleCart = (Vehicle_Cart)thing;
                    if (vehicleCart == null)
                    {
                        continue;
                    }
                    if (!ToolsForHaulUtility.AvailableVehicle(pawn, vehicleCart))
                    {
                        continue;
                    }
                    if (vehicleCart.vehicleComp.tankLeaking)
                    {
                        continue;
                    }
                    cart = vehicleCart;
                    break;
                }
            }
            if (worktype.Equals(WorkTypeDefOf.Construction))
            {
                IOrderedEnumerable <Thing> orderedEnumerable2 =
                    ToolsForHaulUtility.Cart.OrderBy(x => pawn.Position.DistanceToSquared(x.Position)).ThenByDescending(x => (x as Vehicle_Cart).VehicleSpeed);
                foreach (Thing thing in orderedEnumerable2)
                {
                    Vehicle_Cart vehicleCart = (Vehicle_Cart)thing;
                    if (vehicleCart == null)
                    {
                        continue;
                    }
                    if (!ToolsForHaulUtility.AvailableVehicle(pawn, vehicleCart))
                    {
                        continue;
                    }
                    if (!vehicleCart.IsCurrentlyMotorized())
                    {
                        continue;
                    }
                    if (vehicleCart.vehicleComp.tankLeaking)
                    {
                        continue;
                    }
                    cart = vehicleCart;
                    break;
                }
            }
            return(cart);
        }