コード例 #1
0
 public static void DoLeavingsFor(TerrainDef terrain, IntVec3 cell, Map map)
 {
     if (Current.ProgramState == ProgramState.Playing)
     {
         ThingOwner <Thing>     thingOwner = new ThingOwner <Thing>();
         List <ThingCountClass> list       = terrain.CostListAdjusted(null, true);
         for (int i = 0; i < list.Count; i++)
         {
             ThingCountClass thingCountClass = list[i];
             int             num             = GenMath.RoundRandom((float)thingCountClass.count * terrain.resourcesFractionWhenDeconstructed);
             if (num > 0)
             {
                 Thing thing = ThingMaker.MakeThing(thingCountClass.thingDef, null);
                 thing.stackCount = num;
                 thingOwner.TryAdd(thing, true);
             }
         }
         while (true)
         {
             if (thingOwner.Count > 0)
             {
                 Thing thing2 = default(Thing);
                 if (!thingOwner.TryDrop(thingOwner[0], cell, map, ThingPlaceMode.Near, out thing2, (Action <Thing, int>)null))
                 {
                     break;
                 }
                 continue;
             }
             return;
         }
         Log.Warning("Failed to place all leavings for removed terrain " + terrain + " at " + cell);
     }
 }
コード例 #2
0
 public override void DrawMouseAttachments()
 {
     base.DrawMouseAttachments();
     if (!ArchitectCategoryTab.InfoRect.Contains(UI.MousePositionOnUIInverted))
     {
         DesignationDragger dragger = Find.DesignatorManager.Dragger;
         int     num    = (!dragger.Dragging) ? 1 : dragger.DragCells.Count();
         float   num2   = 0f;
         Vector2 vector = Event.current.mousePosition + Designator_Build.DragPriceDrawOffset;
         List <ThingCountClass> list = this.entDef.CostListAdjusted(this.stuffDef, true);
         for (int i = 0; i < list.Count; i++)
         {
             ThingCountClass thingCountClass = list[i];
             float           y        = vector.y + num2;
             Rect            position = new Rect(vector.x, y, 27f, 27f);
             GUI.DrawTexture(position, thingCountClass.thingDef.uiIcon);
             Rect   rect = new Rect((float)(vector.x + 29.0), y, 999f, 29f);
             int    num3 = num * thingCountClass.count;
             string text = num3.ToString();
             if (base.Map.resourceCounter.GetCount(thingCountClass.thingDef) < num3)
             {
                 GUI.color = Color.red;
                 text      = text + " (" + "NotEnoughStoredLower".Translate() + ")";
             }
             Text.Font   = GameFont.Small;
             Text.Anchor = TextAnchor.MiddleLeft;
             Widgets.Label(rect, text);
             Text.Anchor = TextAnchor.UpperLeft;
             GUI.color   = Color.white;
             num2        = (float)(num2 + 29.0);
         }
     }
 }
コード例 #3
0
ファイル: History.cs プロジェクト: AndreasKarg/ColonyManager
 public Chapter(ThingCountClass thingCount, int size, Color color) : this()
 {
     label      = thingCount.thingDef.LabelCap;
     ThingCount = thingCount;
     this.size  = size;
     lineColor  = color;
 }
コード例 #4
0
        static void Postfix(ref bool __result, ItemAvailability __instance, ThingCountClass need, Pawn pawn)
        {
            if (!__result && pawn != null && pawn.Faction == Faction.OfPlayer)
            {
                foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(pawn.Map))
                {
                    if (storage.IsOperational &&
                        storage.Spawned &&
                        need != null && need.thing != null)
                    {
                        Thing thing;
                        if (storage.TryGetValue(need.thing.def, out thing))
                        {
                            if (thing.stackCount >= need.Count)
                            {
                                List <Thing> removed;
                                int          toDrop = (need.Count < thing.def.stackLimit) ? thing.def.stackLimit : need.Count;
                                if (storage.TryRemove(thing, toDrop, out removed))
                                {
                                    foreach (Thing t in removed)
                                    {
                                        BuildingUtil.DropThing(t, t.stackCount, storage, storage.Map);
                                    }

                                    __result = true;
                                    ((Dictionary <int, bool>)CachedResultsFI.GetValue(__instance))[Gen.HashCombine <Faction>(need.GetHashCode(), pawn.Faction)] = __result;
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        public bool ThingsAvailableAnywhere(ThingCountClass need, Pawn pawn)
        {
            int  key = Gen.HashCombine <Faction>(need.GetHashCode(), pawn.Faction);
            bool flag;

            if (!this.cachedResults.TryGetValue(key, out flag))
            {
                List <Thing> list = this.map.listerThings.ThingsOfDef(need.thingDef);
                int          num  = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    if (!list[i].IsForbidden(pawn))
                    {
                        num += list[i].stackCount;
                        if (num >= need.count)
                        {
                            break;
                        }
                    }
                }
                flag = (num >= need.count);
                this.cachedResults.Add(key, flag);
            }
            return(flag);
        }
コード例 #6
0
 public static Toil FailOnDespawnedNullOrForbiddenPlacedThings(this Toil toil)
 {
     toil.AddFailCondition(delegate
     {
         bool result;
         if (toil.actor.jobs.curJob.placedThings == null)
         {
             result = false;
         }
         else
         {
             for (int i = 0; i < toil.actor.jobs.curJob.placedThings.Count; i++)
             {
                 ThingCountClass thingCountClass = toil.actor.jobs.curJob.placedThings[i];
                 if (thingCountClass.thing == null || !thingCountClass.thing.Spawned || thingCountClass.thing.Map != toil.actor.Map || (!toil.actor.CurJob.ignoreForbidden && thingCountClass.thing.IsForbidden(toil.actor)))
                 {
                     return(true);
                 }
             }
             result = false;
         }
         return(result);
     });
     return(toil);
 }
コード例 #7
0
ファイル: Frame.cs プロジェクト: sachdevs/RW-Decompile
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(base.GetInspectString());
            stringBuilder.AppendLine("ContainedResources".Translate() + ":");
            List <ThingCountClass> list = this.def.entityDefToBuild.CostListAdjusted(base.Stuff, true);

            for (int i = 0; i < list.Count; i++)
            {
                ThingCountClass need = list[i];
                int             num  = need.count;
                foreach (ThingCountClass current in from needed in this.MaterialsNeeded()
                         where needed.thingDef == need.thingDef
                         select needed)
                {
                    num -= current.count;
                }
                stringBuilder.AppendLine(string.Concat(new object[]
                {
                    need.thingDef.LabelCap,
                    ": ",
                    num,
                    " / ",
                    need.count
                }));
            }
            stringBuilder.Append("WorkLeft".Translate() + ": " + this.WorkLeft.ToStringWorkAmount());
            return(stringBuilder.ToString());
        }
コード例 #8
0
        public static List <ThingCountClass> CostListAdjusted(this BuildableDef entDef, ThingDef stuff, bool errorOnNullStuff = true)
        {
            CostListPair           key  = new CostListPair(entDef, stuff);
            List <ThingCountClass> list = default(List <ThingCountClass>);

            if (!CostListCalculator.cachedCosts.TryGetValue(key, out list))
            {
                list = new List <ThingCountClass>();
                int num = 0;
                if (entDef.MadeFromStuff)
                {
                    if (errorOnNullStuff && stuff == null)
                    {
                        Log.Error("Cannot get AdjustedCostList for " + entDef + " with null Stuff.");
                        return(null);
                    }
                    if (stuff != null)
                    {
                        num = Mathf.RoundToInt((float)entDef.costStuffCount / stuff.VolumePerUnit);
                        if (num < 1)
                        {
                            num = 1;
                        }
                    }
                    else
                    {
                        num = entDef.costStuffCount;
                    }
                }
                else if (stuff != null)
                {
                    Log.Error("Got AdjustedCostList for " + entDef + " with stuff " + stuff + " but is not MadeFromStuff.");
                }
                bool flag = false;
                if (entDef.costList != null)
                {
                    for (int i = 0; i < entDef.costList.Count; i++)
                    {
                        ThingCountClass thingCountClass = entDef.costList[i];
                        if (thingCountClass.thingDef == stuff)
                        {
                            list.Add(new ThingCountClass(thingCountClass.thingDef, thingCountClass.count + num));
                            flag = true;
                        }
                        else
                        {
                            list.Add(thingCountClass);
                        }
                    }
                }
                if (!flag && num > 0)
                {
                    list.Add(new ThingCountClass(stuff, num));
                }
                CostListCalculator.cachedCosts.Add(key, list);
            }
            return(list);
        }
コード例 #9
0
        public override void DrawPanelReadout(ref float curY, float width)
        {
            if (this.entDef.costStuffCount <= 0 && this.stuffDef != null)
            {
                this.stuffDef = null;
            }
            ThingDef thingDef = this.entDef as ThingDef;

            if (thingDef != null)
            {
                Widgets.InfoCardButton((float)(width - 24.0 - 6.0), 6f, thingDef, this.stuffDef);
            }
            else
            {
                Widgets.InfoCardButton((float)(width - 24.0 - 6.0), 6f, this.entDef);
            }
            Text.Font = GameFont.Tiny;
            List <ThingCountClass> list = this.entDef.CostListAdjusted(this.stuffDef, false);

            for (int i = 0; i < list.Count; i++)
            {
                ThingCountClass thingCountClass = list[i];
                Color           color           = GUI.color;
                Texture2D       image;
                if (thingCountClass.thingDef == null)
                {
                    image = BaseContent.BadTex;
                }
                else
                {
                    image     = thingCountClass.thingDef.uiIcon;
                    GUI.color = thingCountClass.thingDef.graphicData.color;
                }
                GUI.DrawTexture(new Rect(0f, curY, 20f, 20f), image);
                GUI.color = color;
                if (thingCountClass.thingDef != null && thingCountClass.thingDef.resourceReadoutPriority != 0 && base.Map.resourceCounter.GetCount(thingCountClass.thingDef) < thingCountClass.count)
                {
                    GUI.color = Color.red;
                }
                Widgets.Label(new Rect(26f, (float)(curY + 2.0), 50f, 100f), thingCountClass.count.ToString());
                GUI.color = Color.white;
                string text   = (thingCountClass.thingDef != null) ? thingCountClass.thingDef.LabelCap : ("(" + "UnchosenStuff".Translate() + ")");
                float  width2 = (float)(width - 60.0);
                float  num    = (float)(Text.CalcHeight(text, width2) - 2.0);
                Widgets.Label(new Rect(60f, (float)(curY + 2.0), width2, num), text);
                curY += num;
            }
            if (this.entDef.constructionSkillPrerequisite > 0)
            {
                Text.Font = GameFont.Tiny;
                Rect rect = new Rect(0f, (float)(curY + 2.0), width, 24f);
                Widgets.Label(rect, string.Format("{0}: {1}", "ConstructionNeeded".Translate(), this.entDef.constructionSkillPrerequisite));
                curY += 18f;
            }
        }
        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
        public override void PostLoad()
        {
            base.PostLoad();

            if (this.products == null)
            {
                var thingCountClass = new ThingCountClass();
                DirectXmlCrossRefLoader.RegisterObjectWantsCrossRef(thingCountClass, "thingDef", "Mizu_NormalWater");
                thingCountClass.count = 1;

                this.products = new List <ThingCountClass>()
                {
                    thingCountClass,
                };
            }
        }
 private static bool ResourceValidator(Pawn pawn, ThingCountClass need, Thing th)
 {
     if (th.def != need.thingDef)
     {
         return(false);
     }
     if (th.IsForbidden(pawn))
     {
         return(false);
     }
     if (!pawn.CanReserve(th, 1, -1, null, false))
     {
         return(false);
     }
     return(true);
 }
コード例 #13
0
        public List <ThingCountClass> MaterialsNeeded()
        {
            this.cachedMaterialsNeeded.Clear();
            List <ThingCountClass> list = base.def.entityDefToBuild.CostListAdjusted(base.Stuff, true);

            for (int i = 0; i < list.Count; i++)
            {
                ThingCountClass thingCountClass = list[i];
                int             num             = this.resourceContainer.TotalStackCountOfDef(thingCountClass.thingDef);
                int             num2            = thingCountClass.count - num;
                if (num2 > 0)
                {
                    this.cachedMaterialsNeeded.Add(new ThingCountClass(thingCountClass.thingDef, num2));
                }
            }
            return(this.cachedMaterialsNeeded);
        }
コード例 #14
0
ファイル: CarnUtils.cs プロジェクト: Pyr3z/Carnivale
        public static Thing FindClosestThings(Pawn pawn, ThingCountClass things)
        {
            if (!Find.VisibleMap.itemAvailability.ThingsAvailableAnywhere(things, pawn))
            {
                return(null);
            }

            Predicate <Thing> validator = t => !t.IsForbidden(pawn) && pawn.CanReserve(t, 25, Info.feePerColonist);

            return(GenClosest.ClosestThingReachable(
                       pawn.Position,
                       pawn.Map,
                       ThingRequest.ForDef(things.thingDef),
                       PathEndMode.InteractionCell,
                       TraverseParms.For(pawn, pawn.NormalMaxDanger()),
                       9999f,
                       validator));
        }
コード例 #15
0
        internal static int CountProductsWithEquivalency(Bill_Production bill, RecipeWorkerCounter counter)
        {
            HashSet <string> eqNames = QOLTweaksPack.MealSelection.Value.InnerList;

            ThingCountClass thingCountClass = counter.recipe.products[0];

            //Log.Message("Looking for equivalencies to " + thingCountClass.thingDef);
            if (thingCountClass.thingDef.CountAsResource)
            {
                int total = 0;
                foreach (string eqName in eqNames)
                {
                    ThingDef def = DefDatabase <ThingDef> .GetNamed(eqName);

                    int local = bill.Map.resourceCounter.GetCount(def);
                    total += local;
                    //Log.Message("Counted " + local + " of " + def.defName);
                }
                return(total);
            }
            int num = bill.Map.listerThings.ThingsOfDef(thingCountClass.thingDef).Count;

            if (thingCountClass.thingDef.Minifiable)
            {
                List <Thing> list = bill.Map.listerThings.ThingsInGroup(ThingRequestGroup.MinifiedThing);
                for (int i = 0; i < list.Count; i++)
                {
                    MinifiedThing minifiedThing = (MinifiedThing)list[i];
                    if (eqNames.Contains(minifiedThing.InnerThing.def.defName))
                    {
                        num++;
                    }
                }
            }
            return(num);
        }
コード例 #16
0
ファイル: GenLeaving.cs プロジェクト: sachdevs/RW-Decompile
        public static void DoLeavingsFor(TerrainDef terrain, IntVec3 cell, Map map)
        {
            if (Current.ProgramState != ProgramState.Playing)
            {
                return;
            }
            ThingOwner <Thing>     thingOwner = new ThingOwner <Thing>();
            List <ThingCountClass> list       = terrain.CostListAdjusted(null, true);

            for (int i = 0; i < list.Count; i++)
            {
                ThingCountClass thingCountClass = list[i];
                int             num             = GenMath.RoundRandom((float)thingCountClass.count * terrain.resourcesFractionWhenDeconstructed);
                if (num > 0)
                {
                    Thing thing = ThingMaker.MakeThing(thingCountClass.thingDef, null);
                    thing.stackCount = num;
                    thingOwner.TryAdd(thing, true);
                }
            }
            while (thingOwner.Count > 0)
            {
                Thing thing2;
                if (!thingOwner.TryDrop(thingOwner[0], cell, map, ThingPlaceMode.Near, out thing2, null))
                {
                    Log.Warning(string.Concat(new object[]
                    {
                        "Failed to place all leavings for removed terrain ",
                        terrain,
                        " at ",
                        cell
                    }));
                    return;
                }
            }
        }
コード例 #17
0
 public static void GenerateInventoryFor(Pawn p, PawnGenerationRequest request)
 {
     p.inventory.DestroyAll(DestroyMode.Vanish);
     for (int i = 0; i < p.kindDef.fixedInventory.Count; i++)
     {
         ThingCountClass thingCountClass = p.kindDef.fixedInventory[i];
         Thing           thing           = ThingMaker.MakeThing(thingCountClass.thingDef, null);
         thing.stackCount = thingCountClass.count;
         p.inventory.innerContainer.TryAdd(thing, true);
     }
     if (p.kindDef.inventoryOptions != null)
     {
         foreach (Thing current in p.kindDef.inventoryOptions.GenerateThings())
         {
             p.inventory.innerContainer.TryAdd(current, true);
         }
     }
     if (request.AllowFood)
     {
         PawnInventoryGenerator.GiveRandomFood(p);
     }
     PawnInventoryGenerator.GiveDrugsIfAddicted(p);
     PawnInventoryGenerator.GiveCombatEnhancingDrugs(p);
 }
コード例 #18
0
        public static Toil PlaceHauledThingInCell(TargetIndex cellInd, Toil nextToilOnPlaceFailOrIncomplete, bool storageMode)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn    actor  = toil.actor;
                Job     curJob = actor.jobs.curJob;
                IntVec3 cell   = curJob.GetTarget(cellInd).Cell;
                if (actor.carryTracker.CarriedThing == null)
                {
                    Log.Error(actor + " tried to place hauled thing in cell but is not hauling anything.", false);
                    return;
                }
                SlotGroup slotGroup = actor.Map.haulDestinationManager.SlotGroupAt(cell);
                if (slotGroup != null && slotGroup.Settings.AllowedToAccept(actor.carryTracker.CarriedThing))
                {
                    actor.Map.designationManager.TryRemoveDesignationOn(actor.carryTracker.CarriedThing, DesignationDefOf.Haul);
                }
                Action <Thing, int> placedAction = null;
                if (curJob.def == DissectionDefOf.DoDissectionBill)
                {
                    placedAction = delegate(Thing th, int added)
                    {
                        if (curJob.placedThings == null)
                        {
                            curJob.placedThings = new List <ThingCountClass>();
                        }
                        ThingCountClass thingCountClass = curJob.placedThings.Find((ThingCountClass x) => x.thing == th);
                        if (thingCountClass != null)
                        {
                            thingCountClass.Count += added;
                        }
                        else
                        {
                            curJob.placedThings.Add(new ThingCountClass(th, added));
                        }
                    };
                }
                if (!actor.carryTracker.TryDropCarriedThing(cell, ThingPlaceMode.Direct, out Thing thing, placedAction))
                {
                    if (storageMode)
                    {
                        if (nextToilOnPlaceFailOrIncomplete != null && StoreUtility.TryFindBestBetterStoreCellFor(actor.carryTracker.CarriedThing, actor, actor.Map, StoragePriority.Unstored, actor.Faction, out IntVec3 c, true))
                        {
                            if (actor.CanReserve(c, 1, -1, null, false))
                            {
                                actor.Reserve(c, actor.CurJob, 1, -1, null, true);
                            }
                            actor.CurJob.SetTarget(cellInd, c);
                            actor.jobs.curDriver.JumpToToil(nextToilOnPlaceFailOrIncomplete);
                            return;
                        }
                        Job job = HaulAIUtility.HaulAsideJobFor(actor, actor.carryTracker.CarriedThing);
                        if (job != null)
                        {
                            curJob.targetA = job.targetA;
                            curJob.targetB = job.targetB;
                            curJob.targetC = job.targetC;
                            curJob.count   = job.count;
                            curJob.haulOpportunisticDuplicates = job.haulOpportunisticDuplicates;
                            curJob.haulMode = job.haulMode;
                            actor.jobs.curDriver.JumpToToil(nextToilOnPlaceFailOrIncomplete);
                        }
                        else
                        {
                            Log.Error(string.Concat(new object[]
                            {
                                "Incomplete haul for ",
                                actor,
                                ": Could not find anywhere to put ",
                                actor.carryTracker.CarriedThing,
                                " near ",
                                actor.Position,
                                ". Destroying. This should never happen!"
                            }), false);
                            actor.carryTracker.CarriedThing.Destroy(DestroyMode.Vanish);
                        }
                    }
                    else if (nextToilOnPlaceFailOrIncomplete != null)
                    {
                        actor.jobs.curDriver.JumpToToil(nextToilOnPlaceFailOrIncomplete);
                        return;
                    }
                }
            };
            return(toil);
        }
コード例 #19
0
 private static bool ResourceValidator(Pawn pawn, ThingCountClass need, Thing th)
 {
     return(th.def == need.thingDef && !th.IsForbidden(pawn) && pawn.CanReserve(th, 1, -1, null, false));
 }
コード例 #20
0
ファイル: GenLeaving.cs プロジェクト: sachdevs/RW-Decompile
        public static void DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect)
        {
            if ((Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund) || mode == DestroyMode.Vanish)
            {
                return;
            }
            if (mode == DestroyMode.KillFinalize && diedThing.def.filthLeaving != null)
            {
                for (int i = leavingsRect.minZ; i <= leavingsRect.maxZ; i++)
                {
                    for (int j = leavingsRect.minX; j <= leavingsRect.maxX; j++)
                    {
                        IntVec3 c = new IntVec3(j, 0, i);
                        FilthMaker.MakeFilth(c, map, diedThing.def.filthLeaving, Rand.RangeInclusive(1, 3));
                    }
                }
            }
            ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

            if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null)
            {
                for (int k = 0; k < diedThing.def.killedLeavings.Count; k++)
                {
                    Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef, null);
                    thing.stackCount = diedThing.def.killedLeavings[k].count;
                    thingOwner.TryAdd(thing, true);
                }
            }
            if (GenLeaving.CanBuildingLeaveResources(diedThing, mode))
            {
                Frame frame = diedThing as Frame;
                if (frame != null)
                {
                    for (int l = frame.resourceContainer.Count - 1; l >= 0; l--)
                    {
                        int num = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[l].stackCount);
                        if (num > 0)
                        {
                            frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[l], thingOwner, num, true);
                        }
                    }
                    frame.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                }
                else
                {
                    List <ThingCountClass> list = diedThing.CostListAdjusted();
                    for (int m = 0; m < list.Count; m++)
                    {
                        ThingCountClass thingCountClass = list[m];
                        int             num2            = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingCountClass.count);
                        if (num2 > 0 && mode == DestroyMode.KillFinalize && thingCountClass.thingDef.slagDef != null)
                        {
                            int count = thingCountClass.thingDef.slagDef.smeltProducts.First((ThingCountClass pro) => pro.thingDef == ThingDefOf.Steel).count;
                            int num3  = num2 / 2 / 8;
                            for (int n = 0; n < num3; n++)
                            {
                                thingOwner.TryAdd(ThingMaker.MakeThing(thingCountClass.thingDef.slagDef, null), true);
                            }
                            num2 -= num3 * count;
                        }
                        if (num2 > 0)
                        {
                            Thing thing2 = ThingMaker.MakeThing(thingCountClass.thingDef, null);
                            thing2.stackCount = num2;
                            thingOwner.TryAdd(thing2, true);
                        }
                    }
                }
            }
            List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList <IntVec3>();
            int            num4  = 0;

            while (thingOwner.Count > 0)
            {
                if (mode == DestroyMode.KillFinalize && !map.areaManager.Home[list2[num4]])
                {
                    thingOwner[0].SetForbidden(true, false);
                }
                Thing thing3;
                if (!thingOwner.TryDrop(thingOwner[0], list2[num4], map, ThingPlaceMode.Near, out thing3, null))
                {
                    Log.Warning(string.Concat(new object[]
                    {
                        "Failed to place all leavings for destroyed thing ",
                        diedThing,
                        " at ",
                        leavingsRect.CenterCell
                    }));
                    return;
                }
                num4++;
                if (num4 >= list2.Count)
                {
                    num4 = 0;
                }
            }
        }
コード例 #21
0
        private static Toil PlaceHauledThingInCell(TargetIndex cellInd, Toil nextToilOnPlaceFailOrIncomplete, bool storageMode)
        {
            Toil toil = new Toil();

            toil.initAction = (Action)(() =>
            {
                Pawn actor = toil.actor;
                Job curJob = actor.jobs.curJob;
                IntVec3 cell = curJob.GetTarget(cellInd).Cell;
                if (actor.carryTracker.CarriedThing == null)
                {
                    Log.Error(actor.ToString() + " tried to place hauled thing in cell but is not hauling anything.", false);
                }
                else
                {
                    SlotGroup slotGroup = actor.Map.haulDestinationManager.SlotGroupAt(cell);
                    if (slotGroup != null && slotGroup.Settings.AllowedToAccept(actor.carryTracker.CarriedThing))
                    {
                        actor.Map.designationManager.TryRemoveDesignationOn(actor.carryTracker.CarriedThing, DesignationDefOf.Haul);
                    }
                    Action <Thing, int> placedAction = (Action <Thing, int>)null;
                    placedAction = (Action <Thing, int>)((th, added) =>
                    {
                        if (curJob.placedThings == null)
                        {
                            curJob.placedThings = new List <ThingCountClass>();
                        }
                        ThingCountClass thingCountClass = curJob.placedThings.Find((Predicate <ThingCountClass>)(x => x.thing == th));
                        if (thingCountClass != null)
                        {
                            thingCountClass.Count += added;
                        }
                        else
                        {
                            curJob.placedThings.Add(new ThingCountClass(th, added));
                        }
                    });
                    Thing resultingThing;
                    if (actor.carryTracker.TryDropCarriedThing(cell, ThingPlaceMode.Direct, out resultingThing, placedAction))
                    {
                        return;
                    }
                    if (storageMode)
                    {
                        IntVec3 foundCell;
                        if (nextToilOnPlaceFailOrIncomplete != null && StoreUtility.TryFindBestBetterStoreCellFor(actor.carryTracker.CarriedThing, actor, actor.Map, StoragePriority.Unstored, actor.Faction, out foundCell, true))
                        {
                            if (actor.CanReserve((LocalTargetInfo)foundCell, 1, -1, (ReservationLayerDef)null, false))
                            {
                                actor.Reserve((LocalTargetInfo)foundCell, actor.CurJob, 1, -1, (ReservationLayerDef)null, true);
                            }
                            actor.CurJob.SetTarget(cellInd, (LocalTargetInfo)foundCell);
                            actor.jobs.curDriver.JumpToToil(nextToilOnPlaceFailOrIncomplete);
                        }
                        else
                        {
                            Job job = HaulAIUtility.HaulAsideJobFor(actor, actor.carryTracker.CarriedThing);
                            if (job != null)
                            {
                                curJob.targetA = job.targetA;
                                curJob.targetB = job.targetB;
                                curJob.targetC = job.targetC;
                                curJob.count = job.count;
                                curJob.haulOpportunisticDuplicates = job.haulOpportunisticDuplicates;
                                curJob.haulMode = job.haulMode;
                                actor.jobs.curDriver.JumpToToil(nextToilOnPlaceFailOrIncomplete);
                            }
                            else
                            {
                                Log.Error("Incomplete haul for " + (object)actor + ": Could not find anywhere to put " + (object)actor.carryTracker.CarriedThing + " near " + (object)actor.Position + ". Destroying. This should never happen!", false);
                                actor.carryTracker.CarriedThing.Destroy(DestroyMode.Vanish);
                            }
                        }
                    }
                    else
                    {
                        if (nextToilOnPlaceFailOrIncomplete == null)
                        {
                            return;
                        }
                        actor.jobs.curDriver.JumpToToil(nextToilOnPlaceFailOrIncomplete);
                    }
                }
            });
            return(toil);
        }
コード例 #22
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;
            ThingCountClass        thingCountClass = null;
            List <ThingCountClass> list            = c.MaterialsNeeded();
            int count = list.Count;
            int i     = 0;

            while (i < count)
            {
                ThingCountClass need = list[i];
                if (!pawn.Map.itemAvailability.ThingsAvailableAnywhere(need, pawn))
                {
                    flag            = true;
                    thingCountClass = 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;
                    thingCountClass = need;
                    i++;
                }
            }
            if (flag)
            {
                JobFailReason.Is(string.Format("{0}: {1}", WorkGiver_ConstructDeliverResources.MissingMaterialsTranslated, thingCountClass.thingDef.label));
            }
            return(null);
        }
コード例 #23
0
ファイル: CompCarnBuilding.cs プロジェクト: Pyr3z/Carnivale
        public override IEnumerable <FloatMenuOption> CompFloatMenuOptions(Pawn pawn)
        {
            if (Props.useJob == null)
            {
                // no useJob specified
                yield break;
            }

            if (parent.Faction != pawn.Faction)
            {
                if (!Info.Active)
                {
                    // carnival is not in town for whatever reason
                    yield break;
                }
                else if (!Info.entertainingNow)
                {
                    // Carnival is closed
                    yield return(new FloatMenuOption(this.FloatMenuOptionLabel + " (Carnival closed)", null));
                }
                else if (!pawn.CanReserve(this.parent))
                {
                    // Already reserved
                    yield return(new FloatMenuOption(this.FloatMenuOptionLabel + " (" + "Reserved".Translate() + ")", null));
                }
                else if (Props.useJob == _DefOf.Job_PayEntryFee)
                {
                    // Pay entry fee
                    yield return(new FloatMenuOption(this.FloatMenuOptionLabel + " (" + Info.feePerColonist + ")", delegate
                    {
                        var silverCount = new ThingCountClass(ThingDefOf.Silver, Info.feePerColonist);
                        var silverStack = CarnUtils.FindClosestThings(pawn, silverCount);

                        if (silverStack != null && pawn.CanReserveAndReach(silverStack, PathEndMode.Touch, pawn.NormalMaxDanger()))
                        {
                            var job = new Job(Props.useJob, silverStack)
                            {
                                expiryInterval = GenDate.TicksPerHour * 10
                            };
                            pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                        }
                    }));
                }
                else if (!Info.allowedColonists.Contains(pawn))
                {
                    // Pawn hasn't payed entry fee
                    yield return(new FloatMenuOption(this.FloatMenuOptionLabel + " (Must pay fee at entrance)", null));
                }
                else if (Props.type.Is(CarnBuildingType.Stall | CarnBuildingType.Attraction))
                {
                    // Do use job (mostly for games)
                    yield return(new FloatMenuOption(this.FloatMenuOptionLabel, delegate
                    {
                        if (pawn.CanReserveAndReach(this.parent, PathEndMode.InteractionCell, Danger.None))
                        {
                            this.TryStartUseJob(pawn);
                        }
                    }));
                }
            }
            else
            {
                if (!pawn.CanReserve(this.parent))
                {
                    // Already reserved
                    yield return(new FloatMenuOption(this.FloatMenuOptionLabel + " (" + "Reserved".Translate() + ")", null));
                }
                else if (Props.type.Is(CarnBuildingType.Stall | CarnBuildingType.Attraction))
                {
                    // Do use job (mostly for games)
                    yield return(new FloatMenuOption(this.FloatMenuOptionLabel, delegate
                    {
                        if (pawn.CanReserveAndReach(this.parent, PathEndMode.InteractionCell, Danger.None))
                        {
                            this.TryStartUseJob(pawn);
                        }
                    }));
                }
            }
        }
コード例 #24
0
 public Chapter( ThingCountClass thingCount, int size, Color color )
     : this()
 {
     this.label = thingCount.thingDef.LabelCap;
     this.ThingCount = thingCount;
     this.size = size;
     lineColor = color;
 }
コード例 #25
0
 private static Thing <> m__1(ThingCountClass p)
 {
     return(p.thing);
 }
コード例 #26
0
        public static void DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect)
        {
            if (Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund)
            {
                return;
            }
            switch (mode)
            {
            case DestroyMode.Vanish:
                return;

            case DestroyMode.KillFinalize:
                if (diedThing.def.filthLeaving != null)
                {
                    for (int i = leavingsRect.minZ; i <= leavingsRect.maxZ; i++)
                    {
                        for (int j = leavingsRect.minX; j <= leavingsRect.maxX; j++)
                        {
                            IntVec3 c = new IntVec3(j, 0, i);
                            FilthMaker.MakeFilth(c, map, diedThing.def.filthLeaving, Rand.RangeInclusive(1, 3));
                        }
                    }
                }
                break;
            }
            ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

            if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null)
            {
                for (int k = 0; k < diedThing.def.killedLeavings.Count; k++)
                {
                    Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef, null);
                    thing.stackCount = diedThing.def.killedLeavings[k].count;
                    thingOwner.TryAdd(thing, true);
                }
            }
            if (GenLeaving.CanBuildingLeaveResources(diedThing, mode))
            {
                Frame frame = diedThing as Frame;
                if (frame != null)
                {
                    for (int num = frame.resourceContainer.Count - 1; num >= 0; num--)
                    {
                        int num2 = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[num].stackCount);
                        if (num2 > 0)
                        {
                            frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[num], thingOwner, num2, true);
                        }
                    }
                    frame.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                }
                else
                {
                    List <ThingCountClass> list = diedThing.CostListAdjusted();
                    for (int l = 0; l < list.Count; l++)
                    {
                        ThingCountClass thingCountClass = list[l];
                        int             num3            = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingCountClass.count);
                        if (num3 > 0 && mode == DestroyMode.KillFinalize && thingCountClass.thingDef.slagDef != null)
                        {
                            int count = thingCountClass.thingDef.slagDef.smeltProducts.First((ThingCountClass pro) => pro.thingDef == ThingDefOf.Steel).count;
                            int num4  = num3 / 2 / 8;
                            for (int m = 0; m < num4; m++)
                            {
                                thingOwner.TryAdd(ThingMaker.MakeThing(thingCountClass.thingDef.slagDef, null), true);
                            }
                            num3 -= num4 * count;
                        }
                        if (num3 > 0)
                        {
                            Thing thing2 = ThingMaker.MakeThing(thingCountClass.thingDef, null);
                            thing2.stackCount = num3;
                            thingOwner.TryAdd(thing2, true);
                        }
                    }
                }
            }
            List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList();
            int            num5  = 0;

            while (true)
            {
                if (thingOwner.Count > 0)
                {
                    if (mode == DestroyMode.KillFinalize && !((Area)map.areaManager.Home)[list2[num5]])
                    {
                        thingOwner[0].SetForbidden(true, false);
                    }
                    Thing thing3 = default(Thing);
                    if (thingOwner.TryDrop(thingOwner[0], list2[num5], map, ThingPlaceMode.Near, out thing3, (Action <Thing, int>)null))
                    {
                        num5++;
                        if (num5 >= list2.Count)
                        {
                            num5 = 0;
                        }
                        continue;
                    }
                    break;
                }
                return;
            }
            Log.Warning("Failed to place all leavings for destroyed thing " + diedThing + " at " + leavingsRect.CenterCell);
        }
コード例 #27
0
        public static Toil PlaceHauledThingInCell(TargetIndex cellInd, Toil nextToilOnPlaceFailOrIncomplete, bool storageMode, bool tryStoreInSameStorageIfSpotCantHoldWholeStack = false)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn    actor  = toil.actor;
                Job     curJob = actor.jobs.curJob;
                IntVec3 cell   = curJob.GetTarget(cellInd).Cell;
                if (actor.carryTracker.CarriedThing == null)
                {
                    Log.Error(string.Concat(actor, " tried to place hauled thing in cell but is not hauling anything."));
                }
                else
                {
                    SlotGroup slotGroup = actor.Map.haulDestinationManager.SlotGroupAt(cell);
                    if (slotGroup != null && slotGroup.Settings.AllowedToAccept(actor.carryTracker.CarriedThing))
                    {
                        actor.Map.designationManager.TryRemoveDesignationOn(actor.carryTracker.CarriedThing, DesignationDefOf.Haul);
                    }
                    Action <Thing, int> placedAction = null;
                    if (curJob.def == JobDefOf.DoBill || curJob.def == JobDefOf.RefuelAtomic || curJob.def == JobDefOf.RearmTurretAtomic)
                    {
                        placedAction = delegate(Thing th, int added)
                        {
                            if (curJob.placedThings == null)
                            {
                                curJob.placedThings = new List <ThingCountClass>();
                            }
                            ThingCountClass thingCountClass = curJob.placedThings.Find((ThingCountClass x) => x.thing == th);
                            if (thingCountClass != null)
                            {
                                thingCountClass.Count += added;
                            }
                            else
                            {
                                curJob.placedThings.Add(new ThingCountClass(th, added));
                            }
                        };
                    }
                    if (!actor.carryTracker.TryDropCarriedThing(cell, ThingPlaceMode.Direct, out var _, placedAction))
                    {
                        if (storageMode)
                        {
                            if (nextToilOnPlaceFailOrIncomplete != null && ((tryStoreInSameStorageIfSpotCantHoldWholeStack && StoreUtility.TryFindBestBetterStoreCellForIn(actor.carryTracker.CarriedThing, actor, actor.Map, StoragePriority.Unstored, actor.Faction, cell.GetSlotGroup(actor.Map), out var foundCell)) || StoreUtility.TryFindBestBetterStoreCellFor(actor.carryTracker.CarriedThing, actor, actor.Map, StoragePriority.Unstored, actor.Faction, out foundCell)))
                            {
                                if (actor.CanReserve(foundCell))
                                {
                                    actor.Reserve(foundCell, actor.CurJob);
                                }
                                actor.CurJob.SetTarget(cellInd, foundCell);
                                actor.jobs.curDriver.JumpToToil(nextToilOnPlaceFailOrIncomplete);
                            }
                            else
                            {
                                Job job = HaulAIUtility.HaulAsideJobFor(actor, actor.carryTracker.CarriedThing);
                                if (job != null)
                                {
                                    curJob.targetA = job.targetA;
                                    curJob.targetB = job.targetB;
                                    curJob.targetC = job.targetC;
                                    curJob.count   = job.count;
                                    curJob.haulOpportunisticDuplicates = job.haulOpportunisticDuplicates;
                                    curJob.haulMode = job.haulMode;
                                    actor.jobs.curDriver.JumpToToil(nextToilOnPlaceFailOrIncomplete);
                                }
                                else
                                {
                                    Log.Error(string.Concat("Incomplete haul for ", actor, ": Could not find anywhere to put ", actor.carryTracker.CarriedThing, " near ", actor.Position, ". Destroying. This should never happen!"));
                                    actor.carryTracker.CarriedThing.Destroy();
                                }
                            }
                        }