示例#1
0
        // Token: 0x06000081 RID: 129 RVA: 0x000051D4 File Offset: 0x000033D4
        private Job NoCostFrameMakeJobFor(Pawn pawn, IConstructible c)
        {
            bool flag = c is Blueprint_Install;
            Job  result;

            if (flag)
            {
                result = null;
            }
            else
            {
                bool flag2 = c is Blueprint && c.MaterialsNeeded().Count == 0;
                if (flag2)
                {
                    Job job = JobMaker.MakeJob(JobDefOf.PlaceNoCostFrame);
                    job.targetA = (Thing)c;
                    result      = job;
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
 private bool IsNewValidNearbyNeeder(Thing t, HashSet <Thing> nearbyNeeders, IConstructible constructible, Pawn pawn)
 {
     if (t is IConstructible && t != constructible && !(t is Blueprint_Install) && t.Faction == pawn.Faction && !t.IsForbidden(pawn) && !nearbyNeeders.Contains(t) && GenConstruct.CanConstruct(t, pawn, false))
     {
         return(true);
     }
     return(false);
 }
 private bool IsNewValidNearbyNeeder(Thing t, HashSet <Thing> nearbyNeeders, IConstructible constructible, Pawn pawn)
 {
     if (!(t is IConstructible) || t == constructible || t is Blueprint_Install || t.Faction != pawn.Faction || t.IsForbidden(pawn) || nearbyNeeders.Contains(t) || !GenConstruct.CanConstruct(t, pawn, checkConstructionSkill: false))
     {
         return(false);
     }
     return(true);
 }
        private static Thing IConstructibleThing(IConstructible constructible)
        {
            if (constructible is CompUpgradable upgradableComp)
            {
                return(upgradableComp.parent);
            }

            return(constructible as Thing);
        }
示例#5
0
        public void CreateNonGeneric_AnyParam_ReturnsInstanceOfType_IfInitializationSucceeds2()
        {
            // Arrange & Act
            IConstructible <int> result = StaticInterfaceFactory <int> .Create(typeof(ConstructibleFromInt), 2);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ConstructibleFromInt));
            Assert.AreEqual(2, ((ConstructibleFromInt)result).Number);
        }
        public override void Construct(IConstructible<MeshDraft> constructible, Transform parentTransform)
        {
            var draft = constructible.Construct(Vector2.zero);

            var meshFilter = parentTransform.gameObject.AddComponent<MeshFilter>();
            meshFilter.mesh = draft.ToMesh();

            var meshRenderer = parentTransform.gameObject.AddComponent<MeshRenderer>();
            meshRenderer.ApplyProperties(rendererProperties);
            meshRenderer.material = roofMaterial;
        }
 public static List <ThingDefCount> MaterialsNeededSafe(this IConstructible constructible)
 {
     if (constructible is Blueprint_Install blueprintInstall)
     {
         return new List <ThingDefCount> {
                    new ThingDefCount(blueprintInstall.GetInnerIfMinified().def, 1)
         }
     }
     ;
     return(new List <ThingDefCount>(constructible.MaterialsNeeded().Select(x => (ThingDefCount)x)));
 }
 // Get materials considering that IConstructible may be a Blueprint_Install
 public static List <ThingDefCountClass> GetMaterialsNeededSafely(this IConstructible constructible)
 {
     if (constructible is Blueprint_Install bInstall)
     {
         return(new List <ThingDefCountClass>()
         {
             new ThingDefCountClass(bInstall.GetInnerIfMinified().def, 1)
         });
     }
     return(constructible.MaterialsNeeded());
 }
 public static int AmountNeededByOf(IConstructible c, ThingDef resDef)
 {
     foreach (ThingDefCountClass thingDefCountClass in c.MaterialsNeeded())
     {
         if (thingDefCountClass.thingDef == resDef)
         {
             return(thingDefCountClass.count);
         }
     }
     return(0);
 }
        private HashSet <Thing> FindNearbyNeeders(Pawn pawn, ThingCountClass need, IConstructible c, int resTotalAvailable, bool canRemoveExistingFloorUnderNearbyNeeders, out int neededTotal, out Job jobToMakeNeederAvailable)
        {
            neededTotal = need.count;
            HashSet <Thing> hashSet = new HashSet <Thing>();
            Thing           thing   = (Thing)c;

            foreach (Thing item in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 8f, true))
            {
                if (neededTotal < resTotalAvailable)
                {
                    if (this.IsNewValidNearbyNeeder(item, hashSet, c, pawn))
                    {
                        Blueprint blueprint = item as Blueprint;
                        if (blueprint == null || !WorkGiver_ConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blueprint))
                        {
                            int num = GenConstruct.AmountNeededByOf((IConstructible)item, need.thingDef);
                            if (num > 0)
                            {
                                hashSet.Add(item);
                                neededTotal += num;
                            }
                        }
                    }
                    continue;
                }
                break;
            }
            Blueprint blueprint2 = c as Blueprint;

            if (blueprint2 != null && blueprint2.def.entityDefToBuild is TerrainDef && canRemoveExistingFloorUnderNearbyNeeders && neededTotal < resTotalAvailable)
            {
                foreach (Thing item2 in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 3f, false))
                {
                    if (this.IsNewValidNearbyNeeder(item2, hashSet, c, pawn))
                    {
                        Blueprint blueprint3 = item2 as Blueprint;
                        if (blueprint3 != null)
                        {
                            Job job = this.RemoveExistingFloorJob(pawn, blueprint3);
                            if (job != null)
                            {
                                jobToMakeNeederAvailable = job;
                                return(hashSet);
                            }
                        }
                    }
                }
            }
            jobToMakeNeederAvailable = null;
            return(hashSet);
        }
示例#11
0
 private Job NoCostFrameMakeJobFor(Pawn pawn, IConstructible c)
 {
     if (c is Blueprint_Install)
     {
         return(null);
     }
     if (c is Blueprint && c.MaterialsNeeded().Count == 0)
     {
         Job job = new Job(JobDefOf.PlaceNoCostFrame);
         job.targetA = (Thing)c;
         return(job);
     }
     return(null);
 }
        private Job NoCostFrameMakeJobFor(Pawn pawn, IConstructible c)
        {
            Job result;

            if (c is Blueprint_Install)
            {
                result = null;
            }
            else if (c is Blueprint && c.MaterialsNeeded().Count == 0)
            {
                result = new Job(JobDefOf.PlaceNoCostFrame)
                {
                    targetA = (Thing)c
                };
            }
            else
            {
                result = null;
            }
            return(result);
        }
        private void UpdateTrackedFromSelObjs()
        {
            // Add new selected but untracked constructibles.
            for (int i = 0; i < Find.Selector.SelectedObjects.Count; i++)
            {
                object selectedObj = Find.Selector.SelectedObjects[i];
                if (selectedObj is IConstructible && !trackedConstructibles.Contains((IConstructible)selectedObj))
                {
                    trackedConstructibles.Add((IConstructible)selectedObj);
                }
            }
            // Remove unselected or deleted tracked constructibles.
            List <IConstructible> trackedListCopy = trackedConstructibles.ToList();

            for (int i = 0; i < trackedListCopy.Count; i++)
            {
                IConstructible trackedObj = trackedListCopy[i];
                if (!Find.Selector.SelectedObjects.Contains(trackedObj) || ((Thing)trackedObj).Destroyed)
                {
                    trackedConstructibles.Remove(trackedObj);
                }
            }
        }
示例#14
0
 static bool GetConstructible(Pawn pawn, IConstructible c)
 {
     constructible = c;
     return(true);
 }
 public Job NoCostFrameMakeJobFor(Pawn pawn, IConstructible c)
 {
     if (c is Blueprint_Install)
     {
         return null;
     }
     if (c is RimWorld.Blueprint && c.MaterialsNeeded().Count == 0)
     {
         return new Job(JobDefOf.PlaceNoCostFrame)
         {
             targetA = (Thing)c
         };
     }
     return null;
 }
示例#16
0
        protected Job ResourceDeliverJobFor(Pawn pawn, IConstructible c, bool canRemoveExistingFloorUnderNearbyNeeders = true)
        {
            Blueprint_Install blueprint_Install = c as Blueprint_Install;

            if (blueprint_Install != null)
            {
                return(this.InstallJob(pawn, blueprint_Install));
            }
            bool flag = false;
            ThingDefCountClass        thingDefCountClass = null;
            List <ThingDefCountClass> list = c.MaterialsNeeded();
            int count = list.Count;
            int i     = 0;

            while (i < count)
            {
                ThingDefCountClass need = list[i];
                if (!pawn.Map.itemAvailability.ThingsAvailableAnywhere(need, pawn))
                {
                    flag = true;
                    thingDefCountClass = need;
                    break;
                }
                Thing foundRes = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(need.thingDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, (Thing r) => WorkGiver_ConstructDeliverResources.ResourceValidator(pawn, need, r), null, 0, -1, false, RegionType.Set_Passable, false);
                if (foundRes != null)
                {
                    int resTotalAvailable;
                    this.FindAvailableNearbyResources(foundRes, pawn, out resTotalAvailable);
                    int             num;
                    Job             job;
                    HashSet <Thing> hashSet = this.FindNearbyNeeders(pawn, need, c, resTotalAvailable, canRemoveExistingFloorUnderNearbyNeeders, out num, out job);
                    if (job != null)
                    {
                        return(job);
                    }
                    hashSet.Add((Thing)c);
                    Thing thing = hashSet.MinBy((Thing nee) => IntVec3Utility.ManhattanDistanceFlat(foundRes.Position, nee.Position));
                    hashSet.Remove(thing);
                    int num2 = 0;
                    int j    = 0;
                    do
                    {
                        num2 += WorkGiver_ConstructDeliverResources.resourcesAvailable[j].stackCount;
                        j++;
                    }while (num2 < num && j < WorkGiver_ConstructDeliverResources.resourcesAvailable.Count);
                    WorkGiver_ConstructDeliverResources.resourcesAvailable.RemoveRange(j, WorkGiver_ConstructDeliverResources.resourcesAvailable.Count - j);
                    WorkGiver_ConstructDeliverResources.resourcesAvailable.Remove(foundRes);
                    Job job2 = new Job(JobDefOf.HaulToContainer);
                    job2.targetA      = foundRes;
                    job2.targetQueueA = new List <LocalTargetInfo>();
                    for (j = 0; j < WorkGiver_ConstructDeliverResources.resourcesAvailable.Count; j++)
                    {
                        job2.targetQueueA.Add(WorkGiver_ConstructDeliverResources.resourcesAvailable[j]);
                    }
                    job2.targetB = thing;
                    if (hashSet.Count > 0)
                    {
                        job2.targetQueueB = new List <LocalTargetInfo>();
                        foreach (Thing current in hashSet)
                        {
                            job2.targetQueueB.Add(current);
                        }
                    }
                    job2.targetC  = (Thing)c;
                    job2.count    = num;
                    job2.haulMode = HaulMode.ToContainer;
                    return(job2);
                }
                else
                {
                    flag = true;
                    thingDefCountClass = need;
                    i++;
                }
            }
            if (flag)
            {
                JobFailReason.Is(string.Format("{0}: {1}", WorkGiver_ConstructDeliverResources.MissingMaterialsTranslated, thingDefCountClass.thingDef.label), null);
            }
            return(null);
        }
示例#17
0
 public abstract void Construct(IConstructible <MeshDraft> constructible, Transform parentTransform);
        public static bool ResourceDeliverJobFor(WorkGiver_ConstructDeliverResources __instance, ref Job __result, Pawn pawn, IConstructible c, bool canRemoveExistingFloorUnderNearbyNeeders = true)
        {
            Blueprint_Install blueprint_Install = c as Blueprint_Install;

            if (blueprint_Install != null)
            {
                __result = InstallJob(pawn, blueprint_Install);
                return(false);
            }
            List <Thing> resourcesAvailable = new List <Thing>();

            bool flag = false;
            ThingDefCountClass        thingDefCountClass = null;
            List <ThingDefCountClass> list = c.MaterialsNeeded();
            int count = list.Count;

            for (int i = 0; i < count; i++)
            {
                ThingDefCountClass need = list[i];
                if (!pawn.Map.itemAvailability.ThingsAvailableAnywhere(need, pawn))
                {
                    flag = true;
                    thingDefCountClass = need;
                    break;
                }

                Thing foundRes = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(need.thingDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, (Thing r) => ResourceValidator(pawn, need, r));
                if (foundRes != null)
                {
                    resourcesAvailable.Clear();
                    //FindAvailableNearbyResources2(foundRes, pawn, out int resTotalAvailable, resourcesAvailable);
                    int resTotalAvailable;
                    int num0 = Mathf.Min(foundRes.def.stackLimit, pawn.carryTracker.MaxStackSpaceEver(foundRes.def));
                    resTotalAvailable = 0;
                    resourcesAvailable.Add(foundRes);
                    resTotalAvailable += foundRes.stackCount;
                    if (resTotalAvailable < num0)
                    {
                        foreach (Thing item in GenRadial.RadialDistinctThingsAround(foundRes.Position, foundRes.Map, 5f, useCenter: false))
                        {
                            if (resTotalAvailable >= num0)
                            {
                                break;
                            }
                            if (item.def == foundRes.def && GenAI.CanUseItemForWork(pawn, item))
                            {
                                resourcesAvailable.Add(item);
                                resTotalAvailable += item.stackCount;
                            }
                        }
                    }
                    int             neededTotal;
                    Job             jobToMakeNeederAvailable;
                    HashSet <Thing> hashSet = FindNearbyNeeders(pawn, need, c, resTotalAvailable, canRemoveExistingFloorUnderNearbyNeeders, out neededTotal, out jobToMakeNeederAvailable);
                    if (jobToMakeNeederAvailable != null)
                    {
                        __result = jobToMakeNeederAvailable;
                        return(false);
                    }

                    hashSet.Add((Thing)c);
                    Thing thing = hashSet.MinBy((Thing nee) => IntVec3Utility.ManhattanDistanceFlat(foundRes.Position, nee.Position));
                    hashSet.Remove(thing);
                    int num  = 0;
                    int num2 = 0;
                    do
                    {
                        num += resourcesAvailable[num2].stackCount;
                        num2++;
                    }while (num < neededTotal && num2 < resourcesAvailable.Count);
                    resourcesAvailable.RemoveRange(num2, resourcesAvailable.Count - num2);
                    resourcesAvailable.Remove(foundRes);
                    Job job = JobMaker.MakeJob(JobDefOf.HaulToContainer);
                    job.targetA      = foundRes;
                    job.targetQueueA = new List <LocalTargetInfo>();
                    for (num2 = 0; num2 < resourcesAvailable.Count; num2++)
                    {
                        job.targetQueueA.Add(resourcesAvailable[num2]);
                    }

                    job.targetB = thing;
                    if (hashSet.Count > 0)
                    {
                        job.targetQueueB = new List <LocalTargetInfo>();
                        foreach (Thing item in hashSet)
                        {
                            job.targetQueueB.Add(item);
                        }
                    }

                    job.targetC  = (Thing)c;
                    job.count    = neededTotal;
                    job.haulMode = HaulMode.ToContainer;
                    __result     = job;
                    return(false);
                }

                flag = true;
                thingDefCountClass = need;
            }

            if (flag)
            {
                JobFailReason.Is($"{MissingMaterialsTranslated}: {thingDefCountClass.thingDef.label}");
            }

            __result = null;
            return(false);
        }
        protected Job ResourceDeliverJobFor(Pawn pawn, IConstructible c, bool canRemoveExistingFloorUnderNearbyNeeders = true)
        {
            Blueprint_Install blueprint_Install = c as Blueprint_Install;

            if (blueprint_Install != null)
            {
                return(InstallJob(pawn, blueprint_Install));
            }
            bool flag = false;
            ThingDefCountClass        thingDefCountClass = null;
            List <ThingDefCountClass> list = c.MaterialsNeeded();
            int count = list.Count;

            for (int i = 0; i < count; i++)
            {
                ThingDefCountClass need = list[i];
                if (!pawn.Map.itemAvailability.ThingsAvailableAnywhere(need, pawn))
                {
                    flag = true;
                    thingDefCountClass = need;
                    break;
                }
                Thing foundRes = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(need.thingDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, (Thing r) => ResourceValidator(pawn, need, r));
                if (foundRes != null)
                {
                    FindAvailableNearbyResources(foundRes, pawn, out int resTotalAvailable);
                    int             neededTotal;
                    Job             jobToMakeNeederAvailable;
                    HashSet <Thing> hashSet = FindNearbyNeeders(pawn, need, c, resTotalAvailable, canRemoveExistingFloorUnderNearbyNeeders, out neededTotal, out jobToMakeNeederAvailable);
                    if (jobToMakeNeederAvailable != null)
                    {
                        return(jobToMakeNeederAvailable);
                    }
                    hashSet.Add((Thing)c);
                    Thing thing = hashSet.MinBy((Thing nee) => IntVec3Utility.ManhattanDistanceFlat(foundRes.Position, nee.Position));
                    hashSet.Remove(thing);
                    int num  = 0;
                    int num2 = 0;
                    do
                    {
                        num += resourcesAvailable[num2].stackCount;
                        num2++;
                    }while (num < neededTotal && num2 < resourcesAvailable.Count);
                    resourcesAvailable.RemoveRange(num2, resourcesAvailable.Count - num2);
                    resourcesAvailable.Remove(foundRes);
                    Job job = new Job(JobDefOf.HaulToContainer);
                    job.targetA      = foundRes;
                    job.targetQueueA = new List <LocalTargetInfo>();
                    for (num2 = 0; num2 < resourcesAvailable.Count; num2++)
                    {
                        job.targetQueueA.Add(resourcesAvailable[num2]);
                    }
                    job.targetB = thing;
                    if (hashSet.Count > 0)
                    {
                        job.targetQueueB = new List <LocalTargetInfo>();
                        foreach (Thing item in hashSet)
                        {
                            job.targetQueueB.Add(item);
                        }
                    }
                    job.targetC  = (Thing)c;
                    job.count    = neededTotal;
                    job.haulMode = HaulMode.ToContainer;
                    return(job);
                }
                flag = true;
                thingDefCountClass = need;
            }
            if (flag)
            {
                JobFailReason.Is($"{MissingMaterialsTranslated}: {thingDefCountClass.thingDef.label}");
            }
            return(null);
        }
        // Token: 0x06000078 RID: 120 RVA: 0x00004C7C File Offset: 0x00002E7C
        private HashSet <Thing> FindNearbyNeeders(Pawn pawn, ThingDefCountClass need, IConstructible c, int resTotalAvailable, bool canRemoveExistingFloorUnderNearbyNeeders, out int neededTotal, out Job jobToMakeNeederAvailable)
        {
            neededTotal = need.count;
            HashSet <Thing> hashSet = new HashSet <Thing>();
            Thing           thing   = (Thing)c;

            foreach (Thing thing2 in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 8f, true))
            {
                bool flag = neededTotal >= resTotalAvailable;
                if (flag)
                {
                    break;
                }
                bool flag2 = this.IsNewValidNearbyNeeder(thing2, hashSet, c, pawn);
                if (flag2)
                {
                    Blueprint blueprint = thing2 as Blueprint;
                    bool      flag3     = blueprint == null || !WorkGiver_WPConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blueprint);
                    if (flag3)
                    {
                        int  num   = GenConstruct.AmountNeededByOf((IConstructible)thing2, need.thingDef);
                        bool flag4 = num > 0;
                        if (flag4)
                        {
                            hashSet.Add(thing2);
                            neededTotal += num;
                        }
                    }
                }
            }
            Blueprint blueprint2 = c as Blueprint;
            bool      flag5      = blueprint2 != null && blueprint2.def.entityDefToBuild is TerrainDef && canRemoveExistingFloorUnderNearbyNeeders && neededTotal < resTotalAvailable;

            if (flag5)
            {
                foreach (Thing thing3 in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 3f, false))
                {
                    bool flag6 = this.IsNewValidNearbyNeeder(thing3, hashSet, c, pawn);
                    if (flag6)
                    {
                        Blueprint blueprint3 = thing3 as Blueprint;
                        bool      flag7      = blueprint3 != null;
                        if (flag7)
                        {
                            Job  job   = this.RemoveExistingFloorJob(pawn, blueprint3);
                            bool flag8 = job != null;
                            if (flag8)
                            {
                                jobToMakeNeederAvailable = job;
                                return(hashSet);
                            }
                        }
                    }
                }
            }
            jobToMakeNeederAvailable = null;
            return(hashSet);
        }