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); } } }
private void SetOverride(IMyTerminalBlock gyro, bool enable) { if (TP_GyroOverrideToggle == null) { TP_GyroOverrideToggle = gyro.GetProperty("Override") as ITerminalProperty <bool>; } TP_GyroOverrideToggle.SetValue(gyro, enable); }
/*private Func<long, int, MyDetectedEntityInfo> _getAiFocus; * private Func<IMyTerminalBlock, long, int, bool> _setAiFocus; * private Func<IMyTerminalBlock, int, MyDetectedEntityInfo> _getWeaponTarget; * private Action<IMyTerminalBlock, long, int> _setWeaponTarget; * private Action<IMyTerminalBlock, bool, int> _fireWeaponOnce; * private Action<IMyTerminalBlock, bool, bool, int> _toggleWeaponFire; * private Func<IMyTerminalBlock, int, bool, bool, bool> _isWeaponReadyToFire; * private Func<IMyTerminalBlock, int, float> _getMaxWeaponRange; * private Func<IMyTerminalBlock, ICollection<string>, int, bool> _getTurretTargetTypes; * private Action<IMyTerminalBlock, ICollection<string>, int> _setTurretTargetTypes; * private Action<IMyTerminalBlock, float> _setBlockTrackingRange; * private Func<IMyTerminalBlock, long, int, bool> _isTargetAligned; * private Func<IMyTerminalBlock, long, int, bool> _canShootTarget; * private Func<IMyTerminalBlock, long, int, Vector3D?> _getPredictedTargetPos; * private Func<IMyTerminalBlock, float> _getHeatLevel; * private Func<IMyTerminalBlock, float> _currentPowerConsumption; * private Func<MyDefinitionId, float> _getMaxPower; * private Func<long, bool> _hasGridAi; * private Func<IMyTerminalBlock, bool> _hasCoreWeapon; * private Func<long, float> _getOptimalDps; * private Func<IMyTerminalBlock, int, string> _getActiveAmmo; * private Action<IMyTerminalBlock, int, string> _setActiveAmmo; * private Action<Action<Vector3, float>> _registerProjectileAdded; * private Action<Action<Vector3, float>> _unRegisterProjectileAdded; * private Func<long, float> _getConstructEffectiveDps; * private Func<IMyTerminalBlock, long> _getPlayerController; * private Func<IMyTerminalBlock, int, Matrix> _getWeaponAzimuthMatrix; * private Func<IMyTerminalBlock, int, Matrix> _getWeaponElevationMatrix;*/ public bool Activate(IMyTerminalBlock pbBlock) { var dict = pbBlock.GetProperty("WcPbAPI")?.As <Dictionary <string, Delegate> >().GetValue(pbBlock); if (dict == null) { throw new Exception($"WcPbAPI failed to activate"); } return(ApiAssign(dict)); }
public static bool isOn(IMyTerminalBlock block) { var prop = block.GetProperty("OnOff"); if (prop != null) { return(block.GetValue <bool>("OnOff") && block.IsFunctional); } return(block.IsFunctional); }
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 static T GetValue <T>(IMyTerminalBlock block, string propertyName) { ITerminalProperty prop; if (_terminalPropertyDict.TryGetValue(propertyName, out prop)) { return(prop.Cast <T>().GetValue(block)); } prop = block.GetProperty(propertyName); _terminalPropertyDict[propertyName] = prop; return(prop.Cast <T>().GetValue(block)); }
public static void SetValue <T>(IMyTerminalBlock block, string propertyName, T value) { ITerminalProperty prop; if (_terminalPropertyDict.TryGetValue(propertyName, out prop)) { prop.Cast <T>().SetValue(block, value); return; } prop = block.GetProperty(propertyName); _terminalPropertyDict[propertyName] = prop; prop.Cast <T>().SetValue(block, value); }
public void SetActiveShield(IMyTerminalBlock block) => _block = block; // AutoSet to TapiFrontend(block) if shield exists on grid. public PbApiWrapper(IMyTerminalBlock block) { _block = block; var delegates = _block.GetProperty("DefenseSystemsPbAPI")?.As <Dictionary <string, Delegate> >().GetValue(_block); if (delegates == null) { return; } _rayIntersectShield = (Func <IMyTerminalBlock, RayD, Vector3D?>)delegates["RayIntersectShield"]; _lineIntersectShield = (Func <IMyTerminalBlock, LineD, Vector3D?>)delegates["LineIntersectShield"]; _pointInShield = (Func <IMyTerminalBlock, Vector3D, bool>)delegates["PointInShield"]; _getShieldPercent = (Func <IMyTerminalBlock, float>)delegates["GetShieldPercent"]; _getShieldHeat = (Func <IMyTerminalBlock, int>)delegates["GetShieldHeat"]; _getChargeRate = (Func <IMyTerminalBlock, float>)delegates["GetChargeRate"]; _hpToChargeRatio = (Func <IMyTerminalBlock, int>)delegates["HpToChargeRatio"]; _getMaxCharge = (Func <IMyTerminalBlock, float>)delegates["GetMaxCharge"]; _getCharge = (Func <IMyTerminalBlock, float>)delegates["GetCharge"]; _getPowerUsed = (Func <IMyTerminalBlock, float>)delegates["GetPowerUsed"]; _getPowerCap = (Func <IMyTerminalBlock, float>)delegates["GetPowerCap"]; _getMaxHpCap = (Func <IMyTerminalBlock, float>)delegates["GetMaxHpCap"]; _isShieldUp = (Func <IMyTerminalBlock, bool>)delegates["IsShieldUp"]; _shieldStatus = (Func <IMyTerminalBlock, string>)delegates["ShieldStatus"]; _entityBypass = (Func <IMyTerminalBlock, IMyEntity, bool, bool>)delegates["EntityBypass"]; _entityBypassPb = (Func <IMyTerminalBlock, long, bool, bool>)delegates["EntityBypassPb"]; _gridHasShield = (Func <IMyCubeGrid, bool>)delegates["GridHasShield"]; _gridShieldOnline = (Func <IMyCubeGrid, bool>)delegates["GridShieldOnline"]; _protectedByShield = (Func <IMyEntity, bool>)delegates["ProtectedByShield"]; _getShieldBlock = (Func <IMyEntity, IMyTerminalBlock>)delegates["GetShieldBlock"]; _isShieldBlock = (Func <IMyTerminalBlock, bool>)delegates["IsShieldBlock"]; _getClosestShield = (Func <Vector3D, IMyTerminalBlock>)delegates["GetClosestShield"]; _getDistanceToShield = (Func <IMyTerminalBlock, Vector3D, double>)delegates["GetDistanceToShield"]; _getClosestShieldPoint = (Func <IMyTerminalBlock, Vector3D, Vector3D?>)delegates["GetClosestShieldPoint"]; if (!IsShieldBlock()) { _block = GetShieldBlock(_block.CubeGrid) ?? _block; } }
public void BroadcastRecursive(IMyTerminalBlock source, string message, int remainingHops, HashSet <IMyTerminalBlock> exclude, bool processLocal = true) { Debug.Write("broadcastrecursive"); if (exclude.Contains(source)) { return; } exclude.Add(source); if (processLocal) { ProcessMessage(source, message); } if (remainingHops <= 0) { return; } remainingHops--; var radius = source.GetProperty("Radius").AsFloat().GetValue(source); var receivers = GetValidReceivers(source.Position, radius); foreach (var rec in receivers) { if ((Config.GetProperties(source.EntityId).Channel != Config.GetProperties(rec.EntityId).Channel) || !rec.HasPlayerAccess(source.OwnerId)) { exclude.Add(rec); continue; } BroadcastRecursive(rec, message, remainingHops, exclude); } }
public static void SetValue <T>(this IMyTerminalBlock block, string propertyId, T value) { block.GetProperty(propertyId).Cast <T>().SetValue(block, value); }
public static T GetValue <T>(this IMyTerminalBlock block, string propertyId) => block.GetProperty(propertyId).Cast <T>().GetValue(block);
public static T GetMininum <T>(this IMyTerminalBlock block, string propertyId) => block.GetProperty(propertyId).Cast <T>().GetMinimum(block);
public void ExecuteInstruction() { if (Instructions.Count <= 0 || Instructions.Count < Line) { return; } Instruction instruction = Instructions[Line]; string name, mode, action, search, property, source; float value1 = 0f; float value2 = 0f; float epsilon = 0.1f; bool bool1 = false; bool bool2 = false; Object var; switch (instruction.Command) { case Command.Comment: Line++; break; case Command.Var: // var <var name> <float value> name = instruction.Fields[0]; ParseFieldFloat(instruction.Fields[1], out value1); Vars.Add(name, value1); Line++; break; case Command.Add: case Command.Sub: case Command.Mul: case Command.Div: // <operator> <var name> <var name|float value> <float value> name = instruction.Fields[0]; ParseFieldFloat(instruction.Fields[1], out value1); ParseFieldFloat(instruction.Fields[2], out value2); float result = 0f; switch (instruction.Command) { case Command.Add: result = value1 + value2; break; case Command.Sub: result = value1 - value2; break; case Command.Mul: result = value1 * value2; break; case Command.Div: result = value1 / value2; break; } Vars[name] = result; Line++; break; case Command.Print: bool append = true; string message = ParseFieldString(instruction.Fields[0]); message = "\n" + message; if (instruction.Fields.Count > 1) { List <string> args = new List <string>(); for (int i = 1; i < instruction.Fields.Count; i++) { float value; ParseFieldFloat(instruction.Fields[1], out value); args.Add(value.ToString()); } myProgram.drawingSurface.WriteText(string.Format(message, args.ToArray()), append); } else { myProgram.drawingSurface.WriteText(message, append); } Line++; break; case Command.Select: // select <var name> <mode> <string value> //myProgram.drawingSurface.WriteText($"\nSelect fields={instruction.Fields.Count}", true); name = instruction.Fields[0]; mode = instruction.Fields[1]; search = instruction.Fields[2]; List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); switch (mode) { case "tag": myProgram.GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(blocks, myBlock => myBlock.CustomName.Contains(search)); if (blocks.Count > 0) { Vars.Add(name, blocks); } break; case "group": IMyBlockGroup group = myProgram.GridTerminalSystem.GetBlockGroupWithName(search); group.GetBlocks(blocks); if (blocks.Count > 0) { Vars.Add(name, blocks); } break; default: IMyTerminalBlock block = myProgram.GridTerminalSystem.GetBlockWithName(search); if (block != null) { blocks.Add(block); Vars.Add(name, blocks); } break; } Line++; break; case Command.Action: // action <var name> <action> name = instruction.Fields[0]; action = instruction.Fields[1]; Vars.TryGetValue(name, out var); if (instruction.Fields.Count == 3) { ParseFieldFloat(instruction.Fields[2], out value1); } if (var != null) { blocks = (List <IMyTerminalBlock>)var; blocks.ForEach(delegate(IMyTerminalBlock block) { block.ApplyAction(action); }); } Line++; break; case Command.Set: // set <var name> <property> <value> name = instruction.Fields[0]; property = instruction.Fields[1]; Vars.TryGetValue(name, out var); if (var != null) { if (var is List <IMyTerminalBlock> ) { blocks = (List <IMyTerminalBlock>)var; if (blocks.Count > 0) { IMyTerminalBlock firstBlock = blocks[0]; ITerminalProperty prop = firstBlock.GetProperty(property); //myProgram.drawingSurface.WriteText($"\nProperty={prop.TypeName}", true); switch (prop.TypeName) { case "Single": ParseFieldFloat(instruction.Fields[2], out value1); break; case "Boolean": ParseFieldBool(instruction.Fields[2], out bool1); break; } blocks.ForEach(delegate(IMyTerminalBlock block) { switch (prop.TypeName) { case "Single": block.SetValueFloat(property, value1); break; case "Boolean": block.SetValueBool(property, bool1); break; } }); } } } Line++; break; case Command.Get: // get <var name> <property> <var name> name = instruction.Fields[0]; property = instruction.Fields[1]; source = instruction.Fields[2]; Vars.TryGetValue(source, out var); if (var != null) { if (var is List <IMyTerminalBlock> ) { blocks = (List <IMyTerminalBlock>)var; if (blocks.Count > 0) { IMyTerminalBlock firstBlock = blocks[0]; ITerminalProperty prop = firstBlock.GetProperty(property); switch (prop.TypeName) { case "Single": Vars.Add(name, firstBlock.GetValueFloat(property)); break; case "Boolean": Vars.Add(name, firstBlock.GetValueBool(property)); break; } } } } Line++; break; case Command.Wait: // wait <var name> <property> <value> <epsilon> name = instruction.Fields[0]; property = instruction.Fields[1]; if (instruction.Fields.Count > 3) { ParseFieldFloat(instruction.Fields[3], out epsilon); } Vars.TryGetValue(name, out var); bool isState = true; if (var != null) { if (var is List <IMyTerminalBlock> ) { blocks = (List <IMyTerminalBlock>)var; if (blocks.Count > 0) { ITerminalProperty prop = null; IMyTerminalBlock firstBlock = blocks[0]; prop = firstBlock.GetProperty(property); if (prop == null) { switch (GetAttibutType(property)) { case "Single": ParseFieldFloat(instruction.Fields[2], out value1); break; case "Boolean": ParseFieldBool(instruction.Fields[2], out bool1); break; } } else { switch (prop.TypeName) { case "Single": ParseFieldFloat(instruction.Fields[2], out value1); break; case "Boolean": ParseFieldBool(instruction.Fields[2], out bool1); break; } break; } blocks.ForEach(delegate(IMyTerminalBlock block) { if (prop == null) { switch (GetAttibutType(property)) { case "Single": value2 = GetAttibutFloat(block, property); if (Math.Abs(value2 - value1) > epsilon) { isState = false; } break; case "Boolean": bool2 = GetAttibutBool(block, property); if (bool2 != bool1) { isState = false; } break; } } else { switch (prop.TypeName) { case "Single": value2 = block.GetValueFloat(property); if (Math.Abs(value2 - value1) > epsilon) { isState = false; } break; case "Boolean": bool2 = block.GetValueBool(property); if (bool2 != bool1) { isState = false; } break; } } }); } } } if (isState) { Line++; } break; } }
public bool Activate(IMyTerminalBlock pbBlock) { var dict = pbBlock.GetProperty("WcPbAPI")?.As <IReadOnlyDictionary <string, Delegate> >().GetValue(pbBlock); return(ApiAssign(dict)); }
private void SetOverride(IMyTerminalBlock gyro, bool enable) { if (TP_GyroOverrideToggle == null) TP_GyroOverrideToggle = gyro.GetProperty("Override") as ITerminalProperty<bool>; TP_GyroOverrideToggle.SetValue(gyro, enable); }