private void Close(IMyEntity entity) { //if (needToRelease) // lock_notMyUpdate.ReleaseExclusive(); if (myTerminal != null) { myTerminal.CustomNameChanged -= TurretBase_CustomNameChanged; myTerminal.OwnershipChanged -= myTerminal_OwnershipChanged; } myCubeBlock = null; myTurretBase = null; controlEnabled = false; }
public TurretBase(IMyCubeBlock CubeBlock) { try { if (!Settings.boolSettings[Settings.BoolSetName.bAllowTurretControl]) { return; } this.myCubeBlock = CubeBlock; this.myTerminal = CubeBlock as IMyTerminalBlock; this.myTurretBase = CubeBlock as Ingame.IMyLargeTurretBase; this.myLogger = new Logger(myCubeBlock.CubeGrid.DisplayName, "TurretBase", myCubeBlock.DisplayNameText); this.myCubeBlock.throwIfNull_variable("myCubeBlock"); this.myTerminal.throwIfNull_variable("myTerminal"); this.myTurretBase.throwIfNull_variable("myTurretBase"); myLogger.debugLog("created for: " + myCubeBlock.DisplayNameText, "DelayedInit()"); //EnforcedUpdate = Sandbox.Common.MyEntityUpdateEnum.EACH_FRAME; // want as many opportunities to lock main thread as possible if (!(myTurretBase.DisplayNameText.Contains("[") || myTurretBase.DisplayNameText.Contains("]"))) { if (myTurretBase.OwnerId.Is_ID_NPC()) { myTurretBase.SetCustomName(myTurretBase.DisplayNameText + " " + Settings.stringSettings[Settings.StringSetName.sSmartTurretDefaultNPC]); } else { myTurretBase.SetCustomName(myTurretBase.DisplayNameText + " " + Settings.stringSettings[Settings.StringSetName.sSmartTurretDefaultPlayer]); } } TurretBase_CustomNameChanged(null); myTerminal.CustomNameChanged += TurretBase_CustomNameChanged; myTerminal.OwnershipChanged += myTerminal_OwnershipChanged; // definition limits MyLargeTurretBaseDefinition definition = MyDefinitionManager.Static.GetCubeBlockDefinition(myCubeBlock.getSlimObjectBuilder()) as MyLargeTurretBaseDefinition; definition.throwIfNull_variable("definition"); minElevation = (float)Math.Max(definition.MinElevationDegrees / 180 * Math.PI, -0.6); // -0.6 was determined empirically maxElevation = (float)Math.Min(definition.MaxElevationDegrees / 180 * Math.PI, Math.PI / 2); minAzimuth = (float)(definition.MinAzimuthDegrees / 180 * Math.PI); maxAzimuth = (float)(definition.MaxAzimuthDegrees / 180 * Math.PI); myLogger.debugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "DelayedInit()"); myLogger.debugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "DelayedInit()"); CubeBlock.OnClosing += Close; } catch (Exception e) { if (myCubeBlock == null) { myLogger.log("failed to initialize myCubeBlock == null, Exception:" + e, "DelayedInit()", Logger.severity.ERROR); } else { myLogger.log("failed to initialize for " + myCubeBlock.DisplayNameText + ", Exception:" + e, "DelayedInit()", Logger.severity.WARNING); } Close(null); return; } }
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); }
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(); }