コード例 #1
0
        public override void CompTick()
        {
            // Initialize loadouts on first tick
            if (ticksToInitLoadout > 0)
            {
                ticksToInitLoadout--;
            }
            else if (!initializedLoadouts)
            {
                // Find all loadout generators
                List <LoadoutGeneratorThing> genList = new List <LoadoutGeneratorThing>();
                foreach (Thing thing in container)
                {
                    LoadoutGeneratorThing lGenThing = thing as LoadoutGeneratorThing;
                    if (lGenThing != null && lGenThing.loadoutGenerator != null)
                    {
                        genList.Add(lGenThing);
                    }
                }

                // Sort list by execution priority
                genList.Sort(delegate(LoadoutGeneratorThing x, LoadoutGeneratorThing y)
                {
                    return(x.priority.CompareTo(y.priority));
                });

                // Generate loadouts
                foreach (LoadoutGeneratorThing thing in genList)
                {
                    thing.loadoutGenerator.GenerateLoadout(this);
                    container.Remove(thing);
                }
                initializedLoadouts = true;
            }
            //Log.Message("CR-RD :: pre-base.comptick");
            base.CompTick();
            //Log.Message("CR-RD :: post-base.comptick");
            // Remove items from inventory if we're over the bulk limit

            /*
             * while (availableBulk < 0 && container.Count > 0)
             * {
             *  Log.Message("CR-RD :: Too much bulk for " + parentPawn.ToString() + ", " + (parentPawn.IsColonist ? "is colonist" : "is not colonist"));
             *  if (parentPawn.IsColonist)
             *  {
             *      if (this.parent.Position.InBounds())
             *      {
             *          Thing droppedThing;
             *          container.TryDrop(container.Last(), this.parent.Position, ThingPlaceMode.Near, 1, out droppedThing);
             *      }
             *      else
             *      {
             *          container.Remove(container.Last());
             *      }
             *  }
             * }
             */
        }
コード例 #2
0
        public override void CompTick()
        {
            // Initialize loadouts on first tick
            if (ticksToInitLoadout > 0)
            {
                ticksToInitLoadout--;
            }
            else if (!initializedLoadouts)
            {
                // Find all loadout generators
                List <LoadoutGeneratorThing> genList = new List <LoadoutGeneratorThing>();
                foreach (Thing thing in container)
                {
                    LoadoutGeneratorThing lGenThing = thing as LoadoutGeneratorThing;
                    if (lGenThing != null && lGenThing.loadoutGenerator != null)
                    {
                        genList.Add(lGenThing);
                    }
                }

                // Sort list by execution priority
                genList.Sort(delegate(LoadoutGeneratorThing x, LoadoutGeneratorThing y)
                {
                    return(x.priority.CompareTo(y.priority));
                });

                // Generate loadouts
                foreach (LoadoutGeneratorThing thing in genList)
                {
                    thing.loadoutGenerator.GenerateLoadout(this);
                    container.Remove(thing);
                }
                initializedLoadouts = true;
            }

            base.CompTick();

            // Remove items from inventory if we're over the bulk limit
            while (availableBulk < 0 && container.Count > 0)
            {
                if (this.parent.Position.InBounds())
                {
                    Thing droppedThing;
                    container.TryDrop(container.Last(), this.parent.Position, ThingPlaceMode.Near, 1, out droppedThing);
                }
                else
                {
                    container.Remove(container.Last());
                }
            }
        }