public void updateSlave(IMyTerminalBlock Master, IMyTerminalBlock Slave) { if (Master.BlockDefinition.TypeIdString.Equals(Slave.BlockDefinition.TypeIdString)) { List <ITerminalProperty> Properties = new List <ITerminalProperty>(); Master.GetProperties(Properties); for (int pi = 0; pi < Properties.Count; pi++) { ITerminalProperty Property = Properties[pi]; switch (Property.TypeName) { case "Boolean": Property.AsBool().SetValue(Slave, Property.AsBool().GetValue(Master)); break; case "Single": Property.AsFloat().SetValue(Slave, Property.AsFloat().GetValue(Master)); break; case "Color": Property.AsColor().SetValue(Slave, Property.AsColor().GetValue(Master)); break; default: break; } } } }
protected void SetPropertyOfBlock(Pathfinder pathfinder, string blockName, string propName, T propValue) { blockName = blockName.LowerRemoveWhitespace(); propName = propName.Trim(); // leave spaces in propName foreach (IMyCubeBlock fatblock in AttachedGrid.AttachedCubeBlocks(pathfinder.Mover.Block.CubeGrid, AttachedGrid.AttachmentKind.Permanent, true)) { if (!(fatblock is IMyTerminalBlock)) { continue; } if (!pathfinder.Mover.Block.Controller.canControlBlock(fatblock)) { continue; } if (!fatblock.DisplayNameText.LowerRemoveWhitespace().Contains(blockName)) { continue; } IMyTerminalBlock terminalBlock = fatblock as IMyTerminalBlock; ITerminalProperty <T> property = terminalBlock.GetProperty(propName) as ITerminalProperty <T>; if (property != null) { property.SetValue(fatblock, propValue); } } }
/// <summary> /// Retrieves a Block Property's Terminal Name /// </summary> private static string GetTooltipName(ITerminalProperty prop) { IMyTerminalControlTitleTooltip tooltip = (prop as IMyTerminalControlTitleTooltip); MyStringId id = tooltip == null?MyStringId.GetOrCompute("???") : tooltip.Title; return(MyTexts.Get(id).ToString()); }
public override void SetProperty(StringBuilder name, ITerminalProperty <bool> property, PropertyBlock block) { base.SetProperty(name, property, block); if (poolParent == null) { poolParent = block.boolPropPool; } if (property.Id == "OnOff" && block.SubtypeId.UsesSubtype(TBlockSubtypes.Powered)) // Insert power draw / output info { GetPostfixFunc = GetPowerDisplayFunc; } else if (property.Id == "Stockpile" && block.SubtypeId.UsesSubtype(TBlockSubtypes.GasTank)) // Insert gas tank info { GetPostfixFunc = GetTankFillFunc; } if (property is IMyTerminalControlOnOffSwitch) { var onOffSwitch = property as IMyTerminalControlOnOffSwitch; OnText = onOffSwitch.OnText; OffText = onOffSwitch.OffText; } else { OnText = MySpaceTexts.SwitchText_On; OffText = MySpaceTexts.SwitchText_Off; } }
private void SetOverride(IMyTerminalBlock gyro, bool enable) { if (TP_GyroOverrideToggle == null) { TP_GyroOverrideToggle = gyro.GetProperty("Override") as ITerminalProperty <bool>; } TP_GyroOverrideToggle.SetValue(gyro, enable); }
public static ColorProperty GetProperty(StringBuilder name, ITerminalProperty <Color> property, PropertyBlock block) { ColorProperty prop = block.colorPropPool.Get(); prop.SetProperty(name, property, block); return(prop); }
public static HsvColorProperty GetProperty(StringBuilder name, ITerminalProperty <Vector3> property, PropertyBlock block) { HsvColorProperty prop = block.hsvPropPool.Get(); prop.SetProperty(name, property, block); return(prop); }
public static TextProperty GetProperty(StringBuilder name, ITerminalProperty <StringBuilder> property, PropertyBlock block) { TextProperty prop = block.textPropPool.Get(); prop.SetProperty(name, property, block); return(prop); }
public static FloatProperty GetProperty(StringBuilder name, ITerminalProperty <float> property, PropertyBlock block) { FloatProperty prop = block.floatPropPool.Get(); prop.SetProperty(name, property, block); return(prop); }
public CR_AntennaBlock(IMyRadioAntenna antenna) { this.m_antenna = antenna; if (s_prop_broadcasting == null) { s_prop_broadcasting = antenna.GetProperty("EnableBroadCast").AsBool(); } }
public override void SetProperty(StringBuilder name, ITerminalProperty <StringBuilder> property, PropertyBlock block) { base.SetProperty(name, property, block); if (poolParent == null) { poolParent = block.textPropPool; } }
/// <summary> /// Property type cast /// </summary> /// <typeparam name="TValue">value of type <see cref="ITerminalProperty.TypeName"/></typeparam> /// <param name="property"><see cref="ITerminalProperty{TValue}"/> reference</param> /// <returns>reference to <see cref="ITerminalProperty{TValue}"/> value of specified type</returns> public static ITerminalProperty <TValue> Cast <TValue>(this ITerminalProperty property) { var prop = property.As <TValue>(); if (prop == null) { throw new InvalidOperationException(String.Format("Property {0} is not of type {1}, correct type is {2}", property.Id, typeof(TValue).Name, property.TypeName)); } return(prop); }
public override void SetProperty(StringBuilder name, ITerminalProperty <float> property, PropertyBlock block) { base.SetProperty(name, property, block); if (poolParent == null) { poolParent = block.floatPropPool; } var slider = control as IMyTerminalControlSlider; SliderWriter = slider?.Writer; Flags = BlockPropertyFlags.None; if (isBuildAndRepair) { MinValue = -1000f; MaxValue = 1000f; Increment = 1f; Flags |= BlockPropertyFlags.CanUseMultipliers; } else { MinValue = property.GetMinimum(block.TBlock); MaxValue = property.GetMaximum(block.TBlock); Increment = GetIncrement(); } if (block.SubtypeId.UsesSubtype(TBlockSubtypes.Thruster) && PropName == "Override") { GetScaleFunc = GetThrustEffectFunc; } else { GetScaleFunc = GetDefaultScaleFunc; } if (property.Id == "Velocity") { if (block.SubtypeId.UsesSubtype(TBlockSubtypes.Rotor)) { GetStatusFunc = GetRotorAngleFunc; } else if (block.SubtypeId.UsesSubtype(TBlockSubtypes.Piston)) { GetStatusFunc = GetPistonExtensionFunc; } } if (property.Id == "X" || property.Id == "Y" || property.Id == "Z" || property.Id.StartsWith("Rot")) { Flags |= BlockPropertyFlags.IsIntegral; } }
public static Type GetValueType(this ITerminalProperty prop) { if (!(prop is ITerminalProperty <object>)) { return(null); } var type = prop.GetType(); return(type.GenericTypeArguments[0]); }
public Program() { IMyTerminalBlock block; if (string.IsNullOrWhiteSpace(lcdName)) { block = Me; } else { block = GridTerminalSystem.GetBlockWithName(lcdName); if (block == null) { throw new Exception("Unable to find lcd."); } } if (block is IMyTextSurface) { canvas = (IMyTextSurface)block; } else if (block is IMyTextSurfaceProvider) { IMyTextSurfaceProvider temp = (IMyTextSurfaceProvider)block; lcdIndex = Math.Max(temp.SurfaceCount - 1, lcdIndex); canvas = temp.GetSurface(lcdIndex); } else { throw new Exception("Unable to find lcd."); } if (string.IsNullOrWhiteSpace(projectorName)) { List <IMyTerminalBlock> temp = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyProjector>(temp, (b) => temp.Count <= 1); projector = (IMyProjector)temp.FirstOrDefault(); } else { projector = GridTerminalSystem.GetBlockWithName(projectorName) as IMyProjector; } if (projector == null) { throw new Exception("Unable to find projector."); } spawnProjection = projector.GetActionWithName("BuildGrid"); projectedGridComps = projector.GetProperty("RequiredComponents").As <Dictionary <MyItemType, int> >(); projectedGridTimer = projector.GetProperty("GridTimerProjection").As <int>(); timer = projector.GetProperty("GridTimerCurrent").As <int>(); Runtime.UpdateFrequency = UpdateFrequency.Update10; }
/// <summary> /// Returns true if it can retrieve the current value without throwing an exception. /// </summary> public static bool CanAccessValue <TValue>(this ITerminalProperty <TValue> terminalValue, IMyTerminalBlock tBlock) { try { terminalValue.GetValue(tBlock); return(true); } catch { } return(false); }
public void GunDetect() { var gun = (IMyGunObject <MyGunBase>)Entity; var shotTime = gun.GunBase.LastShootTime.Ticks; if (shotTime > _lastShotTime) { _lastShotTime = shotTime; // fired... } _blockShootProperty = _tblock.GetProperty("Shoot").Cast <bool>(); }
public FlightControlStator(IMyMotorStator Stator) { this.Stator = Stator; this.Flipped = false; if (VelocityProperty == null) { VelocityProperty = (ITerminalProperty <float>)Stator.GetProperty("Velocity"); } ((ITerminalProperty <float>)Stator.GetProperty("LowerLimit")).SetValue(Stator, -45f); ((ITerminalProperty <float>)Stator.GetProperty("UpperLimit")).SetValue(Stator, 45f); }
private TriggerResult setProperty <T>(List <IMyTerminalBlock> blocks, string propertyName, T value) { foreach (IMyTerminalBlock b in blocks) { ITerminalProperty property = b.GetProperty(propertyName); if (property == null) { Program.Echo("No property '" + propertyName + "' for block of type '" + _tempBlocks[0].GetType() + "'"); return(TriggerResult.Error); } b.SetValue(propertyName, value); } return(TriggerResult.Ok); }
public static ITerminalProperty <TValue> Cast <TValue>(this ITerminalProperty property) { if (property == null) { throw new InvalidOperationException("Invalid property"); } ITerminalProperty <TValue> property2 = property.As <TValue>(); if (property2 == null) { throw new InvalidOperationException($"Property {property.Id} is not of type {typeof(TValue).Name}, correct type is {property.TypeName}"); } return(property2); }
public Turret(IMyCubeBlock block) : base(block) { myLogger = new Logger("Turret", block); Registrar.Add(CubeBlock, this); if (TP_TargetMissiles == null) { myLogger.debugLog("Filling Terminal Properties", Logger.severity.INFO); IMyTerminalBlock term = CubeBlock as IMyTerminalBlock; TP_TargetMissiles = term.GetProperty("TargetMissiles").AsBool(); TP_TargetMeteors = term.GetProperty("TargetMeteors").AsBool(); TP_TargetCharacters = term.GetProperty("TargetCharacters").AsBool(); TP_TargetMoving = term.GetProperty("TargetMoving").AsBool(); TP_TargetLargeGrids = term.GetProperty("TargetLargeShips").AsBool(); TP_TargetSmallGrids = term.GetProperty("TargetSmallShips").AsBool(); TP_TargetStations = term.GetProperty("TargetStations").AsBool(); } // definition limits MyLargeTurretBaseDefinition definition = CubeBlock.GetCubeBlockDefinition() as MyLargeTurretBaseDefinition; if (definition == null) throw new NullReferenceException("definition"); minElevation = Math.Max(MathHelper.ToRadians(definition.MinElevationDegrees), -0.6f); maxElevation = MathHelper.ToRadians(definition.MaxElevationDegrees); minAzimuth = MathHelper.ToRadians(definition.MinAzimuthDegrees); maxAzimuth = MathHelper.ToRadians(definition.MaxAzimuthDegrees); Can360 = Math.Abs(definition.MaxAzimuthDegrees - definition.MinAzimuthDegrees) >= 360; // speeds are in rads per ms (from S.E. source) speedElevation = definition.ElevationSpeed * 100f / 6f; speedAzimuth = definition.RotationSpeed * 100f / 6f; setElevation = myTurret.Elevation; setAzimuth = myTurret.Azimuth; // subparts for turrets form a chain var subparts = ((MyCubeBlock)CubeBlock).Subparts; while (subparts.Count != 0) { m_barrel = subparts.FirstPair().Value; subparts = m_barrel.Subparts; } //myLogger.debugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "Turret()"); //myLogger.debugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "Turret()"); }
public ColorProperty(string name, PropertyBlock pBlock, ITerminalProperty <Color> prop, Color delta, Func <string> colorDisp) { this.pBlock = pBlock; this.name = name; property = prop; name = GetTooltipName(prop); incr0 = 1; incrC = incr0 * cfg.colorMult.Z; // x64 incrB = incr0 * cfg.colorMult.Y; // x16 incrA = incr0 * cfg.colorMult.X; // x8 this.delta = delta; this.colorDisp = colorDisp; }
/// <summary> /// Adds thruster to thrustersInDirection /// </summary> /// <param name="thruster">The new thruster</param> private void newThruster(MyThrust thruster) { Log.DebugLog("thruster == null", Logger.severity.ERROR, condition: thruster == null); if (TP_ThrustOverride == null) { TP_ThrustOverride = thruster.GetProperty("Override") as ITerminalProperty <float>; } using (lock_thrustersInDirection.AcquireExclusiveUsing()) m_thrustersInDirection[(int)Base6Directions.GetFlippedDirection(thruster.Orientation.Forward)].Add(thruster); if (TP_ThrustOverride.GetValue(thruster) != 0f) { TP_ThrustOverride.SetValue(thruster, 0f); } }
public Turret(IMyCubeBlock block) : base(block) { myLogger = new Logger("Turret", block); Registrar.Add(CubeBlock, this); if (TP_TargetMissiles == null) { myLogger.debugLog("Filling Terminal Properties", "Turret()", Logger.severity.INFO); IMyTerminalBlock term = CubeBlock as IMyTerminalBlock; TP_TargetMissiles = term.GetProperty("TargetMissiles").AsBool(); TP_TargetMeteors = term.GetProperty("TargetMeteors").AsBool(); TP_TargetCharacters = term.GetProperty("TargetCharacters").AsBool(); TP_TargetMoving = term.GetProperty("TargetMoving").AsBool(); TP_TargetLargeGrids = term.GetProperty("TargetLargeShips").AsBool(); TP_TargetSmallGrids = term.GetProperty("TargetSmallShips").AsBool(); TP_TargetStations = term.GetProperty("TargetStations").AsBool(); } // definition limits MyLargeTurretBaseDefinition definition = CubeBlock.GetCubeBlockDefinition() as MyLargeTurretBaseDefinition; if (definition == null) throw new NullReferenceException("definition"); minElevation = Math.Max(MathHelper.ToRadians(definition.MinElevationDegrees), -0.6f); maxElevation = MathHelper.ToRadians(definition.MaxElevationDegrees); minAzimuth = MathHelper.ToRadians(definition.MinAzimuthDegrees); maxAzimuth = MathHelper.ToRadians(definition.MaxAzimuthDegrees); Can360 = Math.Abs(definition.MaxAzimuthDegrees - definition.MinAzimuthDegrees) >= 360; // speeds are in rads per ms (from S.E. source) speedElevation = definition.ElevationSpeed * 100f / 6f; speedAzimuth = definition.RotationSpeed * 100f / 6f; setElevation = myTurret.Elevation; setAzimuth = myTurret.Azimuth; //if (CubeBlock.OwnedNPC() && s_npcHasOpts && ArmsGuiWeapons.GetPropertyValue(myTurret, ref ArmsGuiWeapons.TP_ARMS_Control)) // myTurret.ApplyAction("ARMS_Control"); //if (myTurret is Ingame.IMyLargeInteriorTurret && myTurret.BlockDefinition.SubtypeName == "LargeInteriorTurret" && !ArmsGuiWeapons.GetPropertyValue(myTurret, ref ArmsGuiWeapons.TP_Interior_Turret)) // myTurret.ApplyAction("Interior_Turret"); myLogger.debugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "Turret()"); myLogger.debugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "Turret()"); }
public BoolProperty(string name, ITerminalProperty <bool> prop, PropertyBlock block) { this.prop = prop; this.pBlock = block; this.name = name; if (prop is IMyTerminalControlOnOffSwitch) { IMyTerminalControlOnOffSwitch onOffSwitch = (IMyTerminalControlOnOffSwitch)prop; OnText = onOffSwitch.OnText; OffText = onOffSwitch.OffText; } else { OnText = MySpaceTexts.SwitchText_On; OffText = MySpaceTexts.SwitchText_Off; } }
/// <summary> /// Retrieves a Block Property's Terminal Name. /// </summary> private static void GetTooltipName(ITerminalProperty prop, StringBuilder dst) { var tooltip = prop as IMyTerminalControlTitleTooltip; if (tooltip != null) { StringBuilder name = MyTexts.Get(tooltip.Title); // Exclude leading spaces int start = 0; for (int i = 0; i < name.Length; i++) { if (name[i] > ' ') { break; } start++; } dst.EnsureCapacity(name.Length - start); for (int n = start; n < name.Length; n++) { char ch = name[n], nextCh = name[Math.Min(n + 1, name.Length - 1)]; if ( // Exclude special chars and most punctuation (ch == ' ' || ch >= 'A' || (ch >= '0' && ch <= '9')) // Exclude repeating and trailing spaces && !(nextCh == ' ' && ch == ' ')) { dst.Append(ch); } } } else { TerminalUtilities.GetBeautifiedTypeID(prop.Id, dst); } }
/// <summary> /// check the age of the message on the panel and change colour if it is old /// </summary> private void checkAge() { if (displayIsOld) { if (DateTime.Now - writeTime < displayOldAfter) // has just become young { displayIsOld = false; ITerminalProperty <Color> backgroundColourProperty = myTextPanel.GetProperty("BackgroundColor").AsColor(); oldBackgroundColour = backgroundColourProperty.GetValue(myTextPanel); if (youngBackgroundColour == Color.Gray) { youngBackgroundColour = Color.Black; } backgroundColourProperty.SetValue(myTextPanel, youngBackgroundColour); myLogger.debugLog("Panel data is now young, storing " + oldBackgroundColour + ", using " + youngBackgroundColour, "checkAge()", Logger.severity.DEBUG); } } else { if (DateTime.Now - writeTime > displayOldAfter) // has just become old { displayIsOld = true; ITerminalProperty <Color> backgroundColourProperty = myTextPanel.GetProperty("BackgroundColor").AsColor(); youngBackgroundColour = backgroundColourProperty.GetValue(myTextPanel); if (oldBackgroundColour == Color.Black) { oldBackgroundColour = Color.Gray; } backgroundColourProperty.SetValue(myTextPanel, oldBackgroundColour); myLogger.debugLog("Panel data is now old, storing " + youngBackgroundColour + ", using " + oldBackgroundColour, "checkAge()", Logger.severity.DEBUG); } } }
private void Initialize() { if (TP_TargetMissiles == null) { myLogger.debugLog("Filling Terminal Properties", "Initialize()", Logger.severity.INFO); IMyTerminalBlock term = CubeBlock as IMyTerminalBlock; TP_TargetMissiles = term.GetProperty("TargetMissiles").AsBool(); TP_TargetMeteors = term.GetProperty("TargetMeteors").AsBool(); TP_TargetCharacters = term.GetProperty("TargetCharacters").AsBool(); TP_TargetMoving = term.GetProperty("TargetMoving").AsBool(); TP_TargetLargeGrids = term.GetProperty("TargetLargeShips").AsBool(); TP_TargetSmallGrids = term.GetProperty("TargetSmallShips").AsBool(); TP_TargetStations = term.GetProperty("TargetStations").AsBool(); } // definition limits MyLargeTurretBaseDefinition definition = CubeBlock.GetCubeBlockDefinition() as MyLargeTurretBaseDefinition; if (definition == null) throw new NullReferenceException("definition"); minElevation = Math.Max(MathHelper.ToRadians(definition.MinElevationDegrees), -0.6f); maxElevation = MathHelper.ToRadians(definition.MaxElevationDegrees); minAzimuth = MathHelper.ToRadians(definition.MinAzimuthDegrees); maxAzimuth = MathHelper.ToRadians(definition.MaxAzimuthDegrees); Can360 = Math.Abs(definition.MaxAzimuthDegrees - definition.MinAzimuthDegrees) >= 360; // speeds are in rads per ms (from S.E. source) speedElevation = definition.ElevationSpeed * 100f / 6f; speedAzimuth = definition.RotationSpeed * 100f / 6f; setElevation = myTurret.Elevation; setAzimuth = myTurret.Azimuth; AllowedState = State.Targeting; Initialized = true; myLogger.debugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "Turret()"); myLogger.debugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "Turret()"); }
public static bool TrySetValue(this ITerminalProperty prop, IMyTerminalBlock block, string value) { if (prop is ITerminalProperty <bool> pBool) { if (!bool.TryParse(value, out bool bVal)) { return(false); } pBool.SetValue(block, bVal); } else if (prop is ITerminalProperty <float> pFloat) { if (!float.TryParse(value, out float fVal)) { return(false); } pFloat.SetValue(block, fVal); } else if (prop is ITerminalProperty <Color> pColor) { var bytes = StringToByteArray(value); if (bytes.Length != 4) { return(false); } var c = new Color { R = bytes[0], G = bytes[1], B = bytes[2], A = bytes[3] }; pColor.SetValue(block, c); } else if (prop is ITerminalProperty <StringBuilder> pSb) { pSb.SetValue(block, new StringBuilder(value)); } return(true); }
public BlockProperty(ITerminalProperty property, IMyTerminalBlock block) { Name = property.Id; Type = property.TypeName; if (property is ITerminalProperty <bool> pBool) { Value = pBool.GetValue(block); } else if (property is ITerminalProperty <float> pFloat) { Value = pFloat.GetValue(block); } else if (property is ITerminalProperty <Color> pColor) { Value = pColor.GetValue(block); } else if (property is ITerminalProperty <StringBuilder> pSb) { Value = pSb.GetValue(block).ToString(); } else { #if DEBUG Log.Warn($"Falling back to reflection for type `{Type}`"); var propType = property.GetType(); if (propType.IsGenericType) { var getValueMethod = propType.GetMethod("GetValue", new[] { typeof(IMyCubeBlock) }); Value = getValueMethod.Invoke(property, new object[] { block }); } #else IsValid = false; Log.Warn($"Property {Type} not supported"); #endif } }
public FloatProperty(string name, ITerminalProperty <float> prop, PropertyBlock block) { this.prop = prop; this.pBlock = block; this.name = name; minValue = this.prop.GetMinimum(pBlock.TBlock); maxValue = this.prop.GetMaximum(pBlock.TBlock); if (float.IsInfinity(minValue) || float.IsInfinity(maxValue)) { incr0 = 1f; } else { double range = Math.Abs(maxValue - minValue), exp; if (range > maxValue) { exp = Math.Truncate(Math.Log10(range)); } else { exp = Math.Truncate(Math.Log10(2 * range)); } incr0 = (float)(Math.Pow(10d, exp) / cfg.floatDiv); } if (incr0 == 0) { incr0 = 1f; } incrC = incr0 * cfg.floatMult.Z; // x64 incrB = incr0 * cfg.floatMult.Y; // x16 incrA = incr0 * cfg.floatMult.X; // x8 }
private void ListContent(IMyTerminalBlock autopilot, List <MyTerminalControlListBoxItem> items, List <MyTerminalControlListBoxItem> selected) { string blockName = m_targetBlock.ToString().Trim(); if (string.IsNullOrWhiteSpace(blockName)) { return; } HashSet <ITerminalProperty <T> > termProps = new HashSet <ITerminalProperty <T> >(); foreach (IMyCubeBlock block in AttachedGrid.AttachedCubeBlocks((IMyCubeGrid)autopilot.CubeGrid, AttachedGrid.AttachmentKind.Permanent, true)) { if (!block.DisplayNameText.Contains(blockName, StringComparison.InvariantCultureIgnoreCase)) { continue; } IMyTerminalBlock term = block as IMyTerminalBlock; if (term == null) { continue; } term.GetProperties(null, property => { ITerminalProperty <T> propT = property as ITerminalProperty <T>; if (propT == null) { return(false); } if (termProps.Add(propT)) { items.Add(new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(propT.Id), MyStringId.NullOrEmpty, propT)); } return(false); }); } }
private void SetOverride(IMyTerminalBlock gyro, bool enable) { if (TP_GyroOverrideToggle == null) TP_GyroOverrideToggle = gyro.GetProperty("Override") as ITerminalProperty<bool>; TP_GyroOverrideToggle.SetValue(gyro, enable); }
public WeaponTargeting(IMyCubeBlock weapon) : base(weapon) { if (weapon == null) throw new ArgumentNullException("weapon"); if (!(weapon is IMyTerminalBlock) || !(weapon is IMyFunctionalBlock) || !(weapon is IMyInventoryOwner) || !(weapon is Ingame.IMyUserControllableGun)) throw new ArgumentException("weapon(" + weapon.DefinitionDisplayNameText + ") is not of correct type"); this.myTurret = weapon as Ingame.IMyLargeTurretBase; this.myLogger = new Logger("WeaponTargeting", weapon) { MinimumLevel = Logger.severity.TRACE }; this.Interpreter = new InterpreterWeapon(weapon); this.Options = new TargetingOptions(); this.IsNormalTurret = myTurret != null; this.CubeBlock.OnClose += weapon_OnClose; if (TPro_Shoot == null) TPro_Shoot = (weapon as IMyTerminalBlock).GetProperty("Shoot").AsBool(); }
static void Entities_OnCloseAll() { MyAPIGateway.Entities.OnCloseAll -= Entities_OnCloseAll; s_prop_broadcasting = null; }
private InitialTargetStatus GetInitialTarget() { if (loadedAmmo == null || loadedAmmo.MissileDefinition == null) { Log.DebugLog("no ammo"); return(InitialTargetStatus.NotReady); } if (m_weaponTarget.Options.TargetGolis.IsValid()) { Log.TraceLog("golis: " + m_weaponTarget.Options.TargetGolis); m_weaponTarget.SetTarget(new GolisTarget(CubeBlock, m_weaponTarget.Options.TargetGolis)); return(InitialTargetStatus.Golis); } if (m_weaponTarget.CurrentControl != WeaponTargeting.Control.Off && !(m_weaponTarget.CurrentTarget is NoTarget)) { Log.TraceLog("from active weapon, control: " + m_weaponTarget.CurrentControl + ", target: " + m_weaponTarget.CurrentTarget); return(InitialTargetStatus.FromWeapon); } else { Log.TraceLog("clearing weapon target"); m_weaponTarget.SetTarget(NoTarget.Instance); } RelayStorage storage = m_relayPart.GetStorage(); if (storage == null) { Log.TraceLog("Failed to get storage for launcher"); return(InitialTargetStatus.NoStorage); } else { ITerminalProperty <float> rangeProperty = CubeBlock.GetProperty("Range") as ITerminalProperty <float>; if (rangeProperty == null) { Logger.AlwaysLog("rangeProperty == null", Logger.severity.FATAL); return(InitialTargetStatus.NotReady); } float range = rangeProperty.GetValue(CubeBlock); if (range < 1f) { range = loadedAmmo.MissileDefinition.MaxTrajectory; } m_weaponTarget.GetLastSeenTarget(storage, range); if (!(m_weaponTarget.CurrentTarget is NoTarget)) { Log.TraceLog("LastSeen: " + m_weaponTarget.CurrentTarget.Entity.nameWithId()); return(InitialTargetStatus.FromWeapon); } else if (m_weaponTarget.Options.TargetEntityId != 0) { return(InitialTargetStatus.NotFoundId); } else { return(InitialTargetStatus.NotFoundAny); } } }
public WeaponTargeting(IMyCubeBlock weapon) : base(weapon) { if (weapon == null) throw new ArgumentNullException("weapon"); if (!(weapon is IMyTerminalBlock) || !(weapon is IMyFunctionalBlock) || !(weapon is IMyInventoryOwner) || !(weapon is Ingame.IMyUserControllableGun)) throw new ArgumentException("weapon(" + weapon.DefinitionDisplayNameText + ") is not of correct type"); this.myTurret = weapon as Ingame.IMyLargeTurretBase; this.myLogger = new Logger("WeaponTargeting", weapon);// { MinimumLevel = Logger.severity.DEBUG }; this.Interpreter = new InterpreterWeapon(weapon); this.Options = new TargetingOptions(); this.IsNormalTurret = myTurret != null; this.CubeBlock.OnClose += weapon_OnClose; this.value_defaultTargeting = IsNormalTurret; this.FuncBlock.AppendingCustomInfo += FuncBlock_AppendingCustomInfo; if (TPro_Shoot == null) TPro_Shoot = (weapon as IMyTerminalBlock).GetProperty("Shoot").AsBool(); myLogger.debugLog("initialized", "WeaponTargeting()", Logger.severity.INFO); }
/// <summary> /// Adds thruster to thrustersInDirection /// </summary> /// <param name="thruster">The new thruster</param> private void newThruster(IMySlimBlock thruster) { if (TP_ThrustOverride == null) TP_ThrustOverride = ((IMyTerminalBlock)thruster.FatBlock).GetProperty("Override") as ITerminalProperty<float>; using (lock_thrustersInDirection.AcquireExclusiveUsing()) thrustersInDirection[Base6Directions.GetFlippedDirection(thruster.FatBlock.Orientation.Forward)].Add(thruster.FatBlock as MyThrust); if (TP_ThrustOverride.GetValue(thruster.FatBlock) != 0f) TP_ThrustOverride.SetValue(thruster.FatBlock, 0f); }
private void SetFlag(ITerminalProperty<bool> prop, TargetType typeFlag) { if (prop.GetValue(CubeBlock)) Options.CanTarget |= typeFlag; else Options.CanTarget &= ~typeFlag; }
public CR_AntennaBlock(Ingame.IMyRadioAntenna antenna) { this.m_antenna = antenna; if (s_prop_broadcasting == null) s_prop_broadcasting = antenna.GetProperty("EnableBroadCast").AsBool(); }