public static IEnumerable <VectorInt3> Values(this IDevicePosList list) { for (int i = 0; i < list.Count; i++) { yield return(list.GetAt(i)); } }
/// <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); } } } } } }
public void Add(IStructure structure) { if (structure == null) { return; } IDevicePosList containers = structure.GetDevices(DeviceTypeName.Container); if (containers != null) { for (int i = 0; i < containers.Count; i++) { Eleon.Modding.VectorInt3 position = containers.GetAt(i); IContainer container = structure.GetDevice <IContainer>(position); if (container == null) { continue; } this.Add(container.GetContent()); } } }
//check for newly placed or removed lcds //the timer for this should be biggish as all this is expensive internal void LCDScan(bool bCheckBlockDestroyed, IModApi api, float blockDist) { if (bCheckBlockDestroyed) { CheckAssociatedLCDs(api); } if (mStruct == null) { api.Log("Null struct in player struct list!"); return; } if (!mStruct.IsReady) { api.Log("Struct: " + mStruct + " not ready..."); return; } if (!mStruct.IsPowered) { //api.Log("Struct: " + mStruct + " not powered..."); return; } /* * string []dTypeNames =mStruct.GetDeviceTypeNames(); * foreach(string dname in dTypeNames) * { * api.Log("Device: " + dname); * }*/ IDevicePosList idplAmmo = mStruct.GetDevices("AmmoCntr"); IDevicePosList idplContainer = mStruct.GetDevices("Container"); IDevicePosList idplFridge = mStruct.GetDevices("Fridge"); IDevicePosList idplHarvest = mStruct.GetDevices("HarvestCntr"); CheckLCD(api, idplAmmo, idplContainer, idplFridge, idplHarvest, blockDist); }
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"); } } }
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); } } }