public override void Tick()
 {
     if (!this.onOff.On)
     {
         return;
     }
     try
     {
         if (updateThrottle.DoUpdate)
         {
             if (!this.isConveyorBelt(back) && this.isConveyorEmpty())
             {
                 this.PullFromBack();
             }
             else
             {
                 this.PushFront();
             }
         }
     }
     catch (System.Exception)
     {
         front = null;
         back  = null;
     }
 }
        protected override void Initialize()
        {
            base.Initialize();
            Vector3 rot = this.Rotation.Right;

            if (rot.x == 1)
            {
                _orientation = Orientation.NORTH;
            }
            else if (rot.z < -0.9 && rot.z > -1.1)
            {
                _orientation = Orientation.EAST;
            }
            else if (rot.x == -1)
            {
                _orientation = Orientation.SOUTH;
            }
            else if (rot.z > 0.9 && rot.z < 1.1)
            {
                _orientation = Orientation.WEST;
            }


            this.GetComponent <StockpileComponent>().Initialize(DefaultDim);
            this.onOff = this.GetComponent <OnOffComponent>();

            PublicStorageComponent storage = this.GetComponent <PublicStorageComponent>();

            storage.Initialize(DefaultDim.x * DefaultDim.z);
            storage.Storage.AddInvRestriction(new StockpileStackRestriction(DefaultDim.y)); // limit stack sizes to the y-height of the stockpile
            this.GetComponent <LinkComponent>().Initialize(1);
        }
 private bool isConveyorBelt(PublicStorageComponent conveyor)
 {
     if (conveyor == null || conveyor.Parent == null || !(conveyor.Parent is ConveyorBeltObject))
     {
         return(false);
     }
     return(true);
 }
        private void PullFromBack()
        {
            if (back == null || !(back is PublicStorageComponent) || !back.Enabled)
            {
                back = null;
                this.UpdateBlock(true);
            }
            PublicStorageComponent our = this.GetComponent <PublicStorageComponent>();

            MoveFromTo(back, our);
        }
        private void PushFront()
        {
            if (front == null || !(front is PublicStorageComponent) || !front.Enabled)
            {
                front = null;
                this.UpdateBlock(false);
            }
            PublicStorageComponent our = this.GetComponent <PublicStorageComponent>();

            MoveFromTo(our, front);
        }
        public void Initialize(List <string> layers, double passed)
        {
            this.rate = passed;
            base.Initialize();
            var animalLayers = new List <AnimalLayer>();

            foreach (var layerName in layers)
            {
                animalLayers.Add(WorldLayerManager.SpeciesToLayers[EcoSim.AllSpecies.FirstOrDefault(x => x.Name == layerName)] as AnimalLayer);
            }
            this.targetLayers = animalLayers;
            this.storage      = this.Parent.GetComponent <PublicStorageComponent>();
            this.storage.Initialize(4);

            this.storage.Inventory.OnChanged.Add(this.UpdateAnimalCount);
            this.UpdateAnimalCount();
        }
Exemple #7
0
 public static Inventory SearchInventoryFromObject(WorldObject obj)
 {
     if (obj != null)
     {
         PublicStorageComponent compStorage = obj.GetComponent <PublicStorageComponent>();
         if (compStorage != null)
         {
             return(compStorage.Inventory);
         }
     }
     if (obj != null)
     {
         FuelSupplyComponent compfuel = obj.GetComponent <FuelSupplyComponent>();
         if (compfuel != null)
         {
             return(compfuel.Inventory);
         }
     }
     return(null);
 }
        private void MoveFromTo(PublicStorageComponent from, PublicStorageComponent to)
        {
            if (from == null || to == null)
            {
                return;
            }

            Inventory fromStorage = from.Storage;

            if (fromStorage == null)
            {
                return;
            }

            Inventory toStorage = to.Storage;

            if (toStorage == null)
            {
                return;
            }

            MoveFromTo(fromStorage, toStorage);
        }
        private void UpdateBlock(bool inverted)
        {
            Vector3i wantedPosition;

            if ((!inverted && _orientation == Orientation.NORTH) || (inverted && _orientation == Orientation.SOUTH))
            {
                wantedPosition = new Vector3i(this.Position3i.x, this.Position3i.y, this.Position3i.z + 1);
            }
            else if ((!inverted && _orientation == Orientation.EAST) || (inverted && _orientation == Orientation.WEST))
            {
                wantedPosition = new Vector3i(this.Position3i.x + 1, this.Position3i.y, this.Position3i.z);
            }
            else if ((!inverted && _orientation == Orientation.SOUTH) || (inverted && _orientation == Orientation.NORTH))
            {
                wantedPosition = new Vector3i(this.Position3i.x, this.Position3i.y, this.Position3i.z - 1);
            }
            else if ((!inverted && _orientation == Orientation.WEST) || (inverted && _orientation == Orientation.EAST))
            {
                wantedPosition = new Vector3i(this.Position3i.x - 1, this.Position3i.y, this.Position3i.z);
            }
            else
            {
                wantedPosition = new Vector3i(this.Position3i.x, this.Position3i.y, this.Position3i.z);
            }

            // check front then front-top then front-bottom
            Vector3i blockTop    = wantedPosition + new Vector3i(0, 1, 0);
            Vector3i blockBottom = wantedPosition + new Vector3i(0, -1, 0);

            IEnumerable <WorldObject> list = WorldObjectManager.GetObjectsWithin(this.Position3i, 5f);

            if (list == null)
            {
                return;
            }
            foreach (WorldObject item in list)
            {
                if (item == null)
                {
                    return;
                }

                List <Vector3i> occupancy = item.WorldOccupancy;
                if (occupancy == null)
                {
                    return;
                }

                foreach (Vector3i position in occupancy)
                {
                    if (!inverted)
                    {
                        if (front == null && (position == wantedPosition || position == blockTop || position == blockBottom))
                        {
                            front = item.GetComponent <PublicStorageComponent>();
                            // ChatManager.ServerMessageToAll(Localizer.Format("WHAT IT IS FROM ? {0}", con.GetStatus()), true);
                            return;
                        }
                    }
                    else
                    {
                        if (back == null && (position == wantedPosition || position == blockTop || position == blockBottom))
                        {
                            back = item.GetComponent <PublicStorageComponent>();
                            // ChatManager.ServerMessageToAll(Localizer.Format("UPDATE BACK {0}", back), true);
                            return;
                        }
                    }
                }
            }
        }