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"); } } }
/// <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}"); } }