public GuidedMissileLauncher(FixedWeapon weapon) { myFixed = weapon; FuncBlock = CubeBlock as IMyFunctionalBlock; myLogger = new Logger("GuidedMissileLauncher", CubeBlock); MissileSpawnBox = CubeBlock.LocalAABB; // might need this again for shorter range missiles //MissileSpawnBox = MissileSpawnBox.Include(MissileSpawnBox.Min + CubeBlock.LocalMatrix.Forward * 10f); //MissileSpawnBox = MissileSpawnBox.Include(MissileSpawnBox.Max + CubeBlock.LocalMatrix.Forward * 10f); myLogger.debugLog("MissileSpawnBox: " + MissileSpawnBox, "GuidedMissileLauncher()"); myInventory = (CubeBlock as Interfaces.IMyInventoryOwner).GetInventory(0); myFixed.AllowedState = WeaponTargeting.State.GetOptions; Registrar.Add(weapon.FuncBlock, this); }
private void UpdateWeaponData() { m_weaponRange_min = float.MaxValue; m_cumulative_targeting.Clear(); m_destroySet = false; foreach (WeaponTargeting weapon in m_weapons_all) { if (!weapon.CubeBlock.IsWorking) { m_weapons_all.Remove(weapon); FixedWeapon asFixed = weapon as FixedWeapon; if (asFixed != null) { m_weapons_fixed.Remove(asFixed); asFixed.EngagerReleaseControl(); } continue; } bool destroy = weapon.Options.CanTargetType(TargetType.Destroy); if (!weapon.Options.CanTargetType(TargetType.AllGrid) && !destroy) { continue; } float TargetingRange = weapon.Options.TargetingRange; if (TargetingRange < 1f) { continue; } if (TargetingRange < m_weaponRange_min) { m_weaponRange_min = TargetingRange; } if (m_destroySet) { continue; } if (destroy) { Log.DebugLog("destroy set for " + weapon.CubeBlock.DisplayNameText); m_destroySet = true; m_cumulative_targeting.Clear(); continue; } else { Log.DebugLog("destroy NOT set for " + weapon.CubeBlock.DisplayNameText); } foreach (TargetType type in CumulativeTypes) { if (weapon.Options.CanTargetType(type)) { AddToCumulative(type, weapon.Options.listOfBlocks); } } } m_weapons_fixed.ApplyRemovals(); m_weapons_all.ApplyRemovals(); if (m_weapons_all.Count == 0) { Log.DebugLog("No working weapons, " + GetType().Name + " is done here", Logger.severity.INFO); m_navSet.OnTaskComplete_NavEngage(); } m_weaponDataDirty = false; }
/// <summary> /// Scripts that use UpdateManager and run on clients as well as on server shall be added here. /// </summary> private void RegisterScripts_ClientAndServer() { #region Attached RegisterForBlock(new MyObjectBuilderType[] { typeof(MyObjectBuilder_MotorStator), typeof(MyObjectBuilder_MotorAdvancedStator), typeof(MyObjectBuilder_MotorSuspension) }, block => RegisterForUpdates(100, (new StatorRotor.Stator(block)).Update, block)); RegisterForBlock(typeof(MyObjectBuilder_ExtendedPistonBase), (block) => { Piston.PistonBase pistonBase = new Piston.PistonBase(block); RegisterForUpdates(100, pistonBase.Update, block); }); RegisterForBlock(typeof(MyObjectBuilder_ShipConnector), (block) => { Connector conn = new Connector(block); RegisterForUpdates(10, conn.Update, block); }); RegisterForBlock(typeof(MyObjectBuilder_LandingGear), (block) => { if (!Hacker.IsHacker(block)) { new LandingGear(block); } }); #endregion #region Antenna Communication Action <IMyCubeBlock> nodeConstruct = block => { RelayNode node = new RelayNode(block); RegisterForUpdates(100, node.Update100, block); }; RegisterForBlock(typeof(MyObjectBuilder_Beacon), nodeConstruct); RegisterForBlock(typeof(MyObjectBuilder_LaserAntenna), nodeConstruct); RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), nodeConstruct); RegisterForCharacter(character => { if (character.IsPlayer) { RelayNode node = new RelayNode(character); RegisterForUpdates(100, node.Update100, (IMyEntity)character); } }); RegisterForBlock(typeof(MyObjectBuilder_MyProgrammableBlock), block => { ProgrammableBlock pb = new ProgrammableBlock(block); if (MyAPIGateway.Multiplayer.IsServer) { RegisterForUpdates(100, pb.Update100, block); } }); RegisterForBlock(typeof(MyObjectBuilder_TextPanel), block => { TextPanel tp = new TextPanel(block); if (MyAPIGateway.Multiplayer.IsServer) { RegisterForUpdates(100, tp.Update100, block); } }); RegisterForBlock(typeof(MyObjectBuilder_Projector), block => { Projector p = new Projector(block); if (MyAPIGateway.Session.Player != null) { RegisterForUpdates(100, p.Update100, block); RegisterForUpdates(1, p.Update1, block); } }); if (MyAPIGateway.Session.Player != null) { new Player(); } #endregion #region Autopilot if (!MyAPIGateway.Multiplayer.IsServer) { //RadarEquipment.Definition apRadar = new RadarEquipment.Definition() //{ // Radar = true, // LineOfSight = false, // MaxTargets_Tracking = 3, // MaxPowerLevel = 1000 //}; Action <IMyCubeBlock> apConstruct = (block) => { if (ShipAutopilot.IsAutopilotBlock(block)) { nodeConstruct(block); new AutopilotTerminal(block); //RadarEquipment r = new RadarEquipment(block, apRadar, block); //RegisterForUpdates(100, r.Update100, block); } }; if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bUseRemoteControl)) { RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), apConstruct); } RegisterForBlock(typeof(MyObjectBuilder_Cockpit), apConstruct); } if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAirResistanceBeta)) { RegisterForGrid(grid => { AeroEffects aero = new AeroEffects(grid); RegisterForUpdates(1, aero.Update1, grid); if (MyAPIGateway.Multiplayer.IsServer) { RegisterForUpdates(100, aero.Update100, grid); } }); RegisterForBlock(typeof(MyObjectBuilder_Cockpit), block => RegisterForUpdates(1, (new CockpitTerminal(block)).Update1, block)); } #endregion #region Radar if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowRadar)) { RegisterForBlock(typeof(MyObjectBuilder_Beacon), (block) => { if (RadarEquipment.IsDefinedRadarEquipment(block)) { new RadarEquipment(block); } }); RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), (block) => { if (RadarEquipment.IsDefinedRadarEquipment(block)) { new RadarEquipment(block); } }); RegisterForUpdates(100, RadarEquipment.UpdateAll); } #endregion #region Terminal Control RegisterForBlock(new MyObjectBuilderType[] { typeof(MyObjectBuilder_RadioAntenna), typeof(MyObjectBuilder_LaserAntenna) }, block => new ManualMessage(block)); #endregion Terminal Control #region Weapon Control if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowWeaponControl)) { #region Turrets Action <IMyCubeBlock> constructor; if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowGuidedMissile)) { constructor = block => { if (!WeaponTargeting.ValidWeaponBlock(block)) { return; } Turret t = new Turret(block); RegisterForUpdates(1, t.Update_Targeting, block); if (GuidedMissileLauncher.IsGuidedMissileLauncher(block)) { GuidedMissileLauncher gml = new GuidedMissileLauncher(t); RegisterForUpdates(1, gml.Update1, block); } } } ; else { constructor = block => { if (!WeaponTargeting.ValidWeaponBlock(block)) { return; } Turret t = new Turret(block); RegisterForUpdates(1, t.Update_Targeting, block); } }; RegisterForBlock(typeof(MyObjectBuilder_LargeGatlingTurret), constructor); RegisterForBlock(typeof(MyObjectBuilder_LargeMissileTurret), constructor); RegisterForBlock(typeof(MyObjectBuilder_InteriorTurret), constructor); #endregion #region Fixed if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowGuidedMissile)) { constructor = block => { if (!WeaponTargeting.ValidWeaponBlock(block)) { return; } FixedWeapon w = new FixedWeapon(block); RegisterForUpdates(1, w.Update_Targeting, block); if (GuidedMissileLauncher.IsGuidedMissileLauncher(block)) { GuidedMissileLauncher gml = new GuidedMissileLauncher(w); RegisterForUpdates(1, gml.Update1, block); } }; } else { constructor = block => { if (!WeaponTargeting.ValidWeaponBlock(block)) { return; } FixedWeapon w = new FixedWeapon(block); RegisterForUpdates(1, w.Update_Targeting, block); } }; RegisterForBlock(typeof(MyObjectBuilder_SmallGatlingGun), constructor); RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncher), constructor); RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncherReload), constructor); #endregion // apparently missiles do not have their positions synced RegisterForUpdates(1, GuidedMissile.Update1); RegisterForUpdates(10, GuidedMissile.Update10); RegisterForUpdates(100, GuidedMissile.Update100); } else { Log.DebugLog("Weapon Control is disabled", Logger.severity.INFO); } #endregion #region Solar if (!MyAPIGateway.Multiplayer.IsServer) { RegisterForBlock(typeof(MyObjectBuilder_OxygenFarm), (block) => new Solar(block)); RegisterForBlock(typeof(MyObjectBuilder_SolarPanel), (block) => new Solar(block)); } #endregion new ChatHandler(); Globals.Update100(); RegisterForUpdates(100, Globals.Update100); Action <IMyCubeBlock> act = (block) => MainCockpitFix.AddController((IMyShipController)block); RegisterForBlock(typeof(MyObjectBuilder_Cockpit), act); RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), act); }
/// <summary> /// Finds a primary weapon for m_weapon_primary and m_weapon_primary_pseudo. /// A primary weapon can be any working weapon with ammo. /// Preference is given to fixed weapons and weapons with targets. /// If no weapons have ammo, m_weapon_primary and m_weapon_primary_pseudo will be null. /// </summary> private void GetPrimaryWeapon() { if (m_weapon_primary != null && m_weapon_primary.CubeBlock.IsWorking && m_weapon_primary.CurrentTarget.Entity != null) { return; } WeaponTargeting weapon_primary = null; bool removed = false; foreach (FixedWeapon weapon in m_weapons_fixed) { if (weapon.CubeBlock.IsWorking) { if (weapon.HasAmmo) { weapon_primary = weapon; if (weapon.CurrentTarget.Entity != null) { Log.DebugLog("has target: " + weapon.CubeBlock.DisplayNameText); break; } } else { Log.DebugLog("no ammo: " + weapon.CubeBlock.DisplayNameText); } } else { Log.DebugLog("not working: " + weapon.CubeBlock.DisplayNameText); m_weapons_fixed.Remove(weapon); weapon.EngagerReleaseControl(); removed = true; } } if (weapon_primary == null) { foreach (WeaponTargeting weapon in m_weapons_all) { if (weapon.CubeBlock.IsWorking) { if (weapon.HasAmmo) { weapon_primary = weapon; if (weapon.CurrentTarget.Entity != null) { Log.DebugLog("has target: " + weapon.CubeBlock.DisplayNameText); break; } } else { Log.DebugLog("no ammo: " + weapon.CubeBlock.DisplayNameText); } } else { Log.DebugLog("not working: " + weapon.CubeBlock.DisplayNameText); m_weapons_all.Remove(weapon); removed = true; } } } if (removed) { m_weapons_fixed.ApplyRemovals(); m_weapons_all.ApplyRemovals(); m_weaponDataDirty = true; } if (weapon_primary == null) { m_weapon_primary = null; m_weapon_primary_pseudo = null; return; } if (m_weapon_primary != weapon_primary) { m_weapon_primary = weapon_primary; IMyCubeBlock faceBlock; FixedWeapon fixedWeapon = weapon_primary as FixedWeapon; if (fixedWeapon != null && fixedWeapon.CubeBlock.CubeGrid != m_controlBlock.CubeGrid) { faceBlock = fixedWeapon.MotorTurretFaceBlock(); Log.DebugLog("MotorTurretFaceBlock == null", Logger.severity.FATAL, condition: faceBlock == null); } else { faceBlock = weapon_primary.CubeBlock; } if (m_mover.SignificantGravity()) { if (m_mover.Thrust.Standard.LocalMatrix.Forward == faceBlock.LocalMatrix.Forward) { Log.DebugLog("primary forward matches Standard forward"); Matrix localMatrix = m_mover.Thrust.Standard.LocalMatrix; localMatrix.Translation = faceBlock.LocalMatrix.Translation; m_weapon_primary_pseudo = new PseudoBlock(() => faceBlock.CubeGrid, localMatrix); return; } if (m_mover.Thrust.Gravity.LocalMatrix.Forward == faceBlock.LocalMatrix.Forward) { Log.DebugLog("primary forward matches Gravity forward"); Matrix localMatrix = m_mover.Thrust.Gravity.LocalMatrix; localMatrix.Translation = faceBlock.LocalMatrix.Translation; m_weapon_primary_pseudo = new PseudoBlock(() => faceBlock.CubeGrid, localMatrix); return; } Log.DebugLog("cannot match primary forward to a standard flight matrix. primary forward: " + faceBlock.LocalMatrix.Forward + ", Standard forward: " + m_mover.Thrust.Standard.LocalMatrix.Forward + ", gravity forward: " + m_mover.Thrust.Gravity.LocalMatrix.Forward); } m_weapon_primary_pseudo = new PseudoBlock(faceBlock); } }