public GuidedMissileLauncher(WeaponTargeting weapon) { m_weaponTarget = weapon; myLogger = new Logger("GuidedMissileLauncher", CubeBlock); m_relayPart = RelayClient.GetOrCreateRelayPart(m_weaponTarget.CubeBlock); var defn = CubeBlock.GetCubeBlockDefinition(); Vector3[] points = new Vector3[3]; Vector3 forwardAdjust = Vector3.Forward * WeaponDescription.GetFor(CubeBlock).MissileSpawnForward; points[0] = CubeBlock.LocalAABB.Min + forwardAdjust; points[1] = CubeBlock.LocalAABB.Max + forwardAdjust; points[2] = CubeBlock.LocalAABB.Min + Vector3.Up * CubeBlock.GetCubeBlockDefinition().Size.Y * CubeBlock.CubeGrid.GridSize + forwardAdjust; MissileSpawnBox = BoundingBox.CreateFromPoints(points); if (m_weaponTarget.myTurret != null) { //myLogger.debugLog("original box: " + MissileSpawnBox, "GuidedMissileLauncher()"); MissileSpawnBox.Inflate(CubeBlock.CubeGrid.GridSize * 2f); } //myLogger.debugLog("MissileSpawnBox: " + MissileSpawnBox, "GuidedMissileLauncher()"); myInventory = ((MyEntity)CubeBlock).GetInventoryBase(0); Registrar.Add(weapon.FuncBlock, this); m_weaponTarget.GuidedLauncher = true; }
public GuidedMissileLauncher(WeaponTargeting weapon) { m_weaponTarget = weapon; m_relayPart = RelayClient.GetOrCreateRelayPart(m_weaponTarget.CubeBlock); this._initialTarget = NoTarget.Instance; MyWeaponBlockDefinition defn = (MyWeaponBlockDefinition)CubeBlock.GetCubeBlockDefinition(); Vector3[] points = new Vector3[3]; Vector3 forwardAdjust = Vector3.Forward * WeaponDescription.GetFor(CubeBlock).MissileSpawnForward; points[0] = CubeBlock.LocalAABB.Min + forwardAdjust; points[1] = CubeBlock.LocalAABB.Max + forwardAdjust; points[2] = CubeBlock.LocalAABB.Min + Vector3.Up * defn.Size.Y * CubeBlock.CubeGrid.GridSize + forwardAdjust; MissileSpawnBox = BoundingBox.CreateFromPoints(points); if (m_weaponTarget.myTurret != null) { Log.TraceLog("original box: " + MissileSpawnBox); MissileSpawnBox.Inflate(CubeBlock.CubeGrid.GridSize * 2f); } Log.TraceLog("MissileSpawnBox: " + MissileSpawnBox); myInventory = ((MyEntity)CubeBlock).GetInventoryBase(0); Registrar.Add(weapon.CubeBlock, this); m_weaponTarget.GuidedLauncher = true; m_gameCooldownTime = TimeSpan.FromSeconds(60d / MyDefinitionManager.Static.GetWeaponDefinition(defn.WeaponDefinitionId).WeaponAmmoDatas[(int)MyAmmoType.Missile].RateOfFire); Log.TraceLog("m_gameCooldownTime: " + m_gameCooldownTime); CubeBlock.AppendingCustomInfo += CubeBlock_AppendingCustomInfo; }
private void Update() { IMyEntity controlled = myPlayer.Controller.ControlledEntity as IMyEntity; if (controlled != m_controlled) { m_controlled = controlled; if (controlled is IMyCharacter) { m_soundEmitter = null; m_threat = null; RelayNode charNode; if (!Registrar.TryGetValue(controlled, out charNode)) { Log.DebugLog("Failed to get node for character: " + controlled.getBestName(), Logger.severity.WARNING); m_storage = null; return; } m_storage = () => charNode.Storage; Log.DebugLog("now controlling a character", Logger.severity.DEBUG); } else if (controlled is IMyCubeBlock) { IRelayPart shipClient = RelayClient.GetOrCreateRelayPart((IMyCubeBlock)controlled); m_storage = shipClient.GetStorage; m_soundEmitter = new MyEntity3DSoundEmitter((MyEntity)controlled); Log.DebugLog("now controlling a ship", Logger.severity.DEBUG); } else { Log.TraceLog("player controlling incompatible entity: " + controlled.getBestName(), Logger.severity.TRACE); m_storage = null; m_soundEmitter = null; m_threat = null; return; } } else if (m_storage == null || m_storage.Invoke() == null) { Log.TraceLog("no storage", Logger.severity.TRACE); m_threat = null; return; } if (UserSettings.GetSetting(UserSettings.BoolSettingName.MissileWarning)) { UpdateMissileThreat(); } else { m_threat = null; } }
public static bool TryGetRelayPart(IMyCubeBlock block, out IRelayPart relayPart) { RelayNode node; if (Registrar.TryGetValue(block, out node)) { relayPart = node; return(true); } RelayClient client; if (Registrar.TryGetValue(block, out client)) { relayPart = client; return(true); } relayPart = null; return(false); }