Example #1
0
        void CheckForSpecialLCD(IBlock blk, ILcd lcd)
        {
            if (mTankLCDs.Contains(lcd))
            {
                return;                 //already in use
            }
            if (mFarmLCDs.Contains(lcd))
            {
                return;                 //already in use
            }

            Dictionary <string, string> vars = new Dictionary <string, string>();

            ParseVars(blk.CustomName, vars);
            if (vars.ContainsKey("$Tnk"))
            {
                //all the stuff from stats
                mTankLCDs.Add(lcd);
                mDeviceBlocks.Add(lcd, blk);
            }
            else if (vars.ContainsKey("$Frm"))
            {
                //number of plots
                //energy used by grow lights
                //growth data on individual plots
                mFarmLCDs.Add(lcd);
                mDeviceBlocks.Add(lcd, blk);
            }
        }
Example #2
0
        void CheckCustomNames(ILcd lcd, out int columnWidth)
        {
            //check name for variables
            columnWidth = -1;
            if (mDeviceBlocks.ContainsKey(lcd))
            {
                Dictionary <string, string> vars = new Dictionary <string, string>();

                ParseVars(mDeviceBlocks[lcd].CustomName, vars);

                if (vars.ContainsKey("$Fnt"))
                {
                    int fontSize;
                    if (Int32.TryParse(vars["$Fnt"], out fontSize))
                    {
                        lcd.SetFontSize(fontSize);
                    }
                }
                if (vars.ContainsKey("$CW"))
                {
                    if (Int32.TryParse(vars["$CW"], out columnWidth))
                    {
                    }
                }
            }
        }
Example #3
0
        private static void UpdateBallPosition(ILcd lcd, Ball b)
        {
            b.Position = new PointF(b.Position.X + b.Direction.X, b.Position.Y + b.Direction.Y);
            if (b.Position.X < 0)
            {
                b.Position  = new PointF(0, b.Position.Y);
                b.Direction = new PointF(-b.Direction.X, b.Direction.Y);
            }
            if (b.Position.Y < 0)
            {
                b.Position  = new PointF(b.Position.X, 0);
                b.Direction = new PointF(b.Direction.X, -b.Direction.Y);
            }

            if (b.Position.X + b.Size.Width >= lcd.Width)
            {
                b.Position  = new PointF(lcd.Width - b.Size.Width - 1, b.Position.Y);
                b.Direction = new PointF(-b.Direction.X, b.Direction.Y);
            }

            if (b.Position.Y + b.Size.Height >= lcd.Height)
            {
                b.Position  = new PointF(b.Position.X, lcd.Height - b.Size.Height - 1);
                b.Direction = new PointF(b.Direction.X, -b.Direction.Y);
            }
        }
Example #4
0
 void NukeLCD(List <ILcd> lcds, ILcd toNuke)
 {
     if (lcds.Contains(toNuke))
     {
         lcds.Remove(toNuke);
         mDevicePositions.Remove(toNuke);
         mDeviceBlocks.Remove(toNuke);
     }
 }
Example #5
0
 public override void InitInterface <T>(T inf)
 {
     if (typeof(T) == typeof(ILcd))
     {
         lcd = (ILcd)inf;
     }
     else
     {
         base.InitInterface(inf);
     }
 }
Example #6
0
 void    ConfirmStillThere(List <ILcd> lcds, List <IDevice> toNuke)
 {
     foreach (ILcd lcd in lcds)
     {
         //check lcd
         ILcd lcdCheck = mStruct.GetDevice <ILcd>(mDevicePositions[lcd]);
         if (lcd != lcdCheck)
         {
             toNuke.Add(lcd);
         }
     }
 }
Example #7
0
        void    ConfirmStillThere(Dictionary <IContainer, ILcd> dict, List <IDevice> toNuke)
        {
            foreach (KeyValuePair <IContainer, ILcd> clcd in dict)
            {
                //check container
                IContainer cn = mStruct.GetDevice <IContainer>(mDevicePositions[clcd.Key]);
                if (cn != clcd.Key)
                {
                    toNuke.Add(clcd.Key);
                }

                //check lcd
                ILcd lcd = mStruct.GetDevice <ILcd>(mDevicePositions[clcd.Value]);
                if (lcd != clcd.Value)
                {
                    toNuke.Add(clcd.Value);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Examines an IEntity instance to see if any feature will be interested in it.
        /// </summary>
        /// <param name="entity">The IEntity instance to be examined.</param>
        private void ProcessEntity(IEntity entity)
        {
            if (entity == null)
            {
                return;
            }

            EntityTokenizer entityTokens = null;

            // Process structure data of the entity.
            IStructure structure = entity.Structure;

            if (structure != null)
            {
                //DarkCity.LogDebug($"Processing structure {structure.Entity.Name}");

                if (EmpyrionExtension.LiveLcd &&
                    ((EmpyrionExtension.Application.Mode == ApplicationMode.PlayfieldServer) || (EmpyrionExtension.Application.Mode == ApplicationMode.SinglePlayer)))
                {
                    // Process LCD devices.
                    IDevicePosList list = structure.GetDevices(DeviceTypeName.LCD);
                    if (list != null)
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            Eleon.Modding.VectorInt3 position = list.GetAt(i);
                            ILcd lcd = structure.GetDevice <ILcd>(position);
                            if (lcd != null)
                            {
                                // Prep structure tokens if not available yet.
                                if (entityTokens == null)
                                {
                                    entityTokens = new EntityTokenizer(entity);
                                }

                                // Hand off ILcd device to any potentially interested processors.
                                LiveLcd.Process(structure, lcd, position, entityTokens, this.PlayfieldTokens);
                            }
                        }
                    }
                }
            }
        }
Example #9
0
        void NukeLCD(Dictionary <IContainer, ILcd> dict, ILcd toNuke)
        {
            IContainer found = null;

            foreach (KeyValuePair <IContainer, ILcd> clcd in dict)
            {
                if (clcd.Value == toNuke)
                {
                    found = clcd.Key;
                    break;
                }
            }
            if (found != null)
            {
                dict.Remove(found);
                mDevicePositions.Remove(toNuke);
                mDevicePositions.Remove(found);
                mDeviceBlocks.Remove(toNuke);
                mDeviceBlocks.Remove(found);
            }
        }
Example #10
0
 public static void SetupLcd(Display_HD44780 display)
 {
     Lcd = new GadgeteerLcd(display);
 }
Example #11
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");
                }
            }
        }
Example #12
0
        //normally called when a block is deleted
        void CheckAssociatedLCDs(IModApi api)
        {
            List <IDevice> toNuke = new List <IDevice>();

            //check ammo
            ConfirmStillThere(mAmmoLCD, toNuke);

            //check container
            ConfirmStillThere(mContainerLCD, toNuke);

            //check fridge
            ConfirmStillThere(mFridgeLCD, toNuke);

            //check harvest
            ConfirmStillThere(mHarvestLCD, toNuke);

            //check tanks
            ConfirmStillThere(mTankLCDs, toNuke);

            //check farm
            ConfirmStillThere(mFarmLCDs, toNuke);

            if (toNuke.Count <= 0)
            {
                return;
            }

            api.Log("CheckAssociatedLCDs found " + toNuke.Count + " nuked items...");

            for (int i = 0; i < toNuke.Count; i++)
            {
                if (toNuke[i] is ILcd)
                {
                    ILcd lcd = toNuke[i] as ILcd;

                    NukeLCD(mAmmoLCD, lcd);
                    NukeLCD(mContainerLCD, lcd);
                    NukeLCD(mFridgeLCD, lcd);
                    NukeLCD(mHarvestLCD, lcd);
                    NukeLCD(mTankLCDs, lcd);
                    NukeLCD(mFarmLCDs, lcd);
                }
                else if (toNuke[i] is IContainer)
                {
                    IContainer con = toNuke[i] as IContainer;
                    ILcd       lcd = null;

                    if (mAmmoLCD.ContainsKey(con))
                    {
                        lcd = mAmmoLCD[con];
                        mAmmoLCD.Remove(con);
                    }
                    if (mContainerLCD.ContainsKey(con))
                    {
                        lcd = mContainerLCD[con];
                        mContainerLCD.Remove(con);
                    }
                    if (mFridgeLCD.ContainsKey(con))
                    {
                        lcd = mFridgeLCD[con];
                        mFridgeLCD.Remove(con);
                    }
                    if (mHarvestLCD.ContainsKey(con))
                    {
                        lcd = mHarvestLCD[con];
                        mHarvestLCD.Remove(con);
                    }

                    //make sure if one device is gone
                    //to remove the associated stuff as well
                    if (lcd != null)
                    {
                        mDevicePositions.Remove(lcd);
                        mDeviceBlocks.Remove(lcd);
                        mDevicePositions.Remove(con);
                        mDeviceBlocks.Remove(con);
                    }
                }
            }
        }
Example #13
0
        void CheckLCD(IModApi api, IDevicePosList ammo, IDevicePosList container,
                      IDevicePosList fridge, IDevicePosList harvest, float blockScanDist)
        {
            IDevicePosList idpl = mStruct.GetDevices("LCD");

            for (int i = 0; i < idpl.Count; i++)
            {
                VectorInt3 pos = idpl.GetAt(i);

                ILcd lcd = mStruct.GetDevice <ILcd>(pos);

                if (mAmmoLCD.ContainsValue(lcd))
                {
                    continue;                           //already in use
                }
                if (mContainerLCD.ContainsValue(lcd))
                {
                    continue;                           //already in use
                }
                if (mFridgeLCD.ContainsValue(lcd))
                {
                    continue;                           //already in use
                }
                if (mHarvestLCD.ContainsValue(lcd))
                {
                    continue;                           //already in use
                }

                api.Log("Unattached LCD Device at pos: " + pos);

                //find the closest device within BlockScanDistance
                float      blockDist = blockScanDist;
                float      bestDist  = float.MaxValue;
                VectorInt3 bestPos   = new VectorInt3(-1, -1, -1);
                int        bestType  = -1;
                IDevice    assoc     = null;

                for (int j = 0; j < ammo.Count; j++)
                {
                    VectorInt3 pos2 = ammo.GetAt(j);

                    float dist = VecDistance(pos, pos2);
                    if (dist < blockDist && dist < bestDist)
                    {
                        assoc    = mStruct.GetDevice <IContainer>(pos2);
                        bestDist = dist;
                        bestType = 0;
                        bestPos  = pos2;
                    }
                }

                for (int j = 0; j < container.Count; j++)
                {
                    VectorInt3 pos2 = container.GetAt(j);

                    float dist = VecDistance(pos, pos2);
                    if (dist < blockDist && dist < bestDist)
                    {
                        assoc    = mStruct.GetDevice <IContainer>(pos2);
                        bestDist = dist;
                        bestType = 1;
                        bestPos  = pos2;
                    }
                }

                for (int j = 0; j < fridge.Count; j++)
                {
                    VectorInt3 pos2 = fridge.GetAt(j);

                    float dist = VecDistance(pos, pos2);
                    if (dist < blockDist && dist < bestDist)
                    {
                        assoc    = mStruct.GetDevice <IContainer>(pos2);
                        bestDist = dist;
                        bestType = 2;
                        bestPos  = pos2;
                    }
                }

                for (int j = 0; j < harvest.Count; j++)
                {
                    VectorInt3 pos2 = harvest.GetAt(j);

                    float dist = VecDistance(pos, pos2);
                    if (dist < blockDist && dist < bestDist)
                    {
                        assoc    = mStruct.GetDevice <IContainer>(pos2);
                        bestDist = dist;
                        bestType = 3;
                        bestPos  = pos2;
                    }
                }

                IBlock lcdBlock = mStruct.GetBlock(pos);

                if (assoc == null)
                {
                    api.Log("Null Assoc");

                    //maybe since this isn't near a device
                    //it can be used for fuel or something
                    CheckForSpecialLCD(lcdBlock, lcd);
                    continue;
                }

                if (!mDevicePositions.ContainsKey(lcd))
                {
                    mDevicePositions.Add(lcd, pos);
                }
                if (!mDevicePositions.ContainsKey(assoc))
                {
                    mDevicePositions.Add(assoc, bestPos);
                }

                IBlock devBlock = mStruct.GetBlock(bestPos);

                if (lcdBlock == null)
                {
                    api.Log("Null block for lcd!");
                }
                else
                {
                    if (mDeviceBlocks.ContainsKey(lcd))
                    {
                        api.Log("BadCleanup!  Device blocks already has lcd: " + lcd + "!!");
                    }
                    else
                    {
                        mDeviceBlocks.Add(lcd, lcdBlock);
                    }
                }

                if (devBlock == null)
                {
                    api.Log("Null block for device!");
                }
                else
                {
                    if (mDeviceBlocks.ContainsKey(assoc))
                    {
                        api.Log("BadCleanup!  Device blocks already has assoc: " + assoc + "!!");
                    }
                    else
                    {
                        mDeviceBlocks.Add(assoc, devBlock);
                    }
                }

                if (bestType == 0)
                {
                    api.Log("Ammo Assoc");
                    mAmmoLCD.Add(assoc as IContainer, lcd);
                }
                else if (bestType == 1)
                {
                    api.Log("Con Assoc");
                    mContainerLCD.Add(assoc as IContainer, lcd);
                }
                else if (bestType == 2)
                {
                    api.Log("Fridge Assoc");
                    mFridgeLCD.Add(assoc as IContainer, lcd);
                }
                else if (bestType == 3)
                {
                    api.Log("Harv Assoc");
                    mHarvestLCD.Add(assoc as IContainer, lcd);
                }
            }
        }
Example #14
0
        /// <summary>
        /// Examines an ILcd device to see if it contains LiveLCD code. ILcd devices without code are ignored.
        /// </summary>
        /// <param name="structure">The IStructure instance that the ILcd device resides in.</param>
        /// <param name="source">The ILcd device to be processed for LiveLCD code.</param>
        /// <param name="position">VectorInt3 containing the position of the ILcd device within the structure.</param>
        /// <param name="tokens">Token collection representing data from the parent structure.</param>
        public static void Process(IStructure structure, ILcd source, VectorInt3 position, Tokenizer tokens, PlayfieldTokenizer playfieldTokens)
        {
            try
            {
                // Confirm that LCD has been marked as a LiveLCD.
                StringReader config = new StringReader(source.GetText());
                string       header = config.ReadLine();
                if ((header == null) || (header.Trim() != liveLcdPhrase))
                {
                    return;
                }

                //DarkCity.LogDebug($"Processing LiveLCD in {structure.Entity.Name} ({structure.Entity.Id}) @ {position}.");
                List <ILcd> targets = new List <ILcd>();

                // Process source LCD configuration.
                string line = config.ReadLine();
                while (line != null)
                {
                    // If the format phrase is found then configuration has finished.
                    line = line.Trim();
                    if (line == formatPhrase)
                    {
                        break;
                    }

                    // Split the configuration line into a key/value pair.
                    string[] kvp = line.Split(kvpSeparator, 2);
                    if (kvp.Length == 2)
                    {
                        string key   = kvp[0].Trim().ToLower();
                        string value = kvp[1].Trim();
                        switch (key)
                        {
                        // Gives the custom name of the LCD device that will display the results of formatted string from this LCD.
                        case "target":
                            ILcd target = structure.GetDevice <ILcd>(value);
                            if (target == null)
                            {
                                Log.Debug($"Could not find LiveLCD target {value}.");
                            }
                            else
                            {
                                //DarkCity.LogDebug($"Found LiveLCD target {value}.");
                                targets.Add(target);
                            }
                            break;

                        // Ignore unknown config directives.
                        default: Log.Debug($"Encountered unknown key {key}; Ignoring."); break;
                        }
                    }

                    line = config.ReadLine();
                }


                // Validate configuration.
                if (targets.Count < 1)
                {
                    Log.Debug("Live LCD did not specify a target LCD or it could not be found.");
                    return;
                }

                // Read the rest of the source LCD text as a string format specifier and apply it to the target LCDs.
                string data = tokens.Tokenize(config.ReadToEnd());
                if (playfieldTokens != null)
                {
                    playfieldTokens.UpdateWithPosition(structure.Entity.Position);
                    playfieldTokens.UpdateWithFaction(structure.Entity.Faction.Id);
                    data = playfieldTokens.Tokenize(data);
                }

                foreach (ILcd target in targets)
                {
                    target?.SetText(data);
                }
            }
            catch (Exception ex)
            {
                Log.Warn($"Failed to process LCD due to exception ({ex.GetType()}) : {ex.Message}");
            }
        }
Example #15
0
 public static void SetupLcd(Display_HD44780 display)
 {
     Lcd = new GadgeteerLcd(display);
 }