示例#1
0
        void OnBatteryTimer(object sender, ElapsedEventArgs eea)
        {
            foreach (KeyValuePair <int, IStructure> str in mStructs)
            {
                if (!str.Value.IsReady)
                {
                    continue;
                }
                if (!str.Value.IsPowered)
                {
                    continue;
                }

                if (str.Value.FuelTank != null)
                {
                    mAPI.Log("Fuel tank capacity: " + str.Value.FuelTank.Capacity +
                             ", Content: " + str.Value.FuelTank.Content);
                }

                //located the battery through a prevous 3d search of
                //the volume of the test base (offset by 128)
                IDevice bat = str.Value.GetDevice <IDevice>(-5, 129, -1);
                if (bat == null)
                {
                    mAPI.Log("Bat null");
                }
                else
                {
                    mAPI.Log("Got device: " + bat);
                }

                BlockSearch(str.Value);

                IDevicePosList idpl = str.Value.GetDevices("AmmoCntr");
                for (int i = 0; i < idpl.Count; i++)
                {
                    VectorInt3 pos = idpl.GetAt(i);

                    mAPI.Log("Device at pos: " + pos);

                    IContainer con = str.Value.GetDevice <IContainer>(pos);

                    mAPI.Log("Ammo container has " + con.VolumeCapacity + " volume.");
                }

                idpl = str.Value.GetDevices("Container");
                for (int i = 0; i < idpl.Count; i++)
                {
                    VectorInt3 pos = idpl.GetAt(i);

                    mAPI.Log("Device at pos: " + pos);

                    IContainer con = str.Value.GetDevice <IContainer>(pos);

                    mAPI.Log("Container has " + con.VolumeCapacity + " volume.");
                }

                idpl = str.Value.GetDevices("Fridge");
                for (int i = 0; i < idpl.Count; i++)
                {
                    VectorInt3 pos = idpl.GetAt(i);

                    mAPI.Log("Device at pos: " + pos);

                    IContainer con = str.Value.GetDevice <IContainer>(pos);

                    mAPI.Log("Fridge has " + con.VolumeCapacity + " volume.");
                }

                idpl = str.Value.GetDevices("LCD");
                for (int i = 0; i < idpl.Count; i++)
                {
                    VectorInt3 pos = idpl.GetAt(i);

                    mAPI.Log("Device at pos: " + pos);

                    ILcd lcd = str.Value.GetDevice <ILcd>(pos);

                    mAPI.Log("LCD says: " + lcd.GetText());
                }

                idpl = str.Value.GetDevices("Light");
                for (int i = 0; i < idpl.Count; i++)
                {
                    VectorInt3 pos = idpl.GetAt(i);

                    mAPI.Log("Device at pos: " + pos);

                    ILight lt = str.Value.GetDevice <ILight>(pos);

                    mAPI.Log("Light has range: " + lt.GetRange());
                }

                idpl = str.Value.GetDevices("Portal");
                for (int i = 0; i < idpl.Count; i++)
                {
                    VectorInt3 pos = idpl.GetAt(i);

                    mAPI.Log("Device at pos: " + pos);

                    IPortal door = str.Value.GetDevice <IPortal>(pos);

                    mAPI.Log("Door is a door");
                }
            }
        }