public override void UpdateBeforeSimulation() { if (!IsInit) { if (MyAPIGateway.Session == null) { return; } Init(); } else { GuidedMissileSingleton.Update(); if ((MyAPIGateway.Multiplayer.MultiplayerActive) && (MyAPIGateway.Multiplayer.IsServer)) { if (MyAPIGateway.Session.ElapsedPlayTime.Milliseconds % 2000 == 0) { int nextSeedNumber = _r.Next(100000); Int32Converter i = nextSeedNumber; byte[] byteArray = { i.Byte1, i.Byte2, i.Byte3, i.Byte4 }; MyAPIGateway.Multiplayer.SendMessageToOthers(2, byteArray); // Log.Info("sent message to others"); _r = new Random(nextSeedNumber); // Log.Info("created new random with Seed " + nextSeedNumber); } } } }
protected virtual HashSet <IMyEntity> GetMissilesInBoundingBox() { BoundingBoxD box = Entity.WorldAABB.GetInflated(BbInflateAmount); if (Math.Abs(BoundingBoxOffsetFront) > double.Epsilon) { box = box.Translate(Entity.LocalMatrix.Forward * (float)BoundingBoxOffsetFront); } //Log.Info("Bounding box in GetMissilesInBoundingBox for "+ GetType()+ " is " + box.Size); List <IMyEntity> entitiesFound = MyAPIGateway.Entities.GetEntitiesInAABB(ref box); HashSet <IMyEntity> entitySet = new HashSet <IMyEntity>(); foreach (IMyEntity ent in entitiesFound) { // Log.Info("in guidedmissilehook: found Entity : " + ent); if ((ent.GetType().ToString() == GuidedMissileSingleton.SandboxGameWeaponsMyMissile) && (!GuidedMissileSingleton.IsGuidedMissile(ent))) { Log.Info("detected something not yet added with speed: " + (ent.Physics.LinearVelocity - Entity.GetTopMostParent().Physics.LinearVelocity).Length()); Log.Info("topmostparent velocity was " + Entity.GetTopMostParent().Physics.LinearVelocity); if ((ent.Physics.LinearVelocity - Entity.GetTopMostParent().Physics.LinearVelocity).Length() < MaxSpeedForGuidance) { entitySet.Add(ent); } else { Log.Info("Missile was too fast! Adding to ignoreSet"); GuidedMissileSingleton.GetInstance().IgnoreSet.Add(ent); } } } return(entitySet); }
protected HashSet <IMyEntity> GetMissilesInBoundingBox() { BoundingBoxD box = Entity.WorldAABB.GetInflated(2.0); // box = box.Translate(Entity.LocalMatrix.Forward * 0.2f); //Log.Info("Bounding box in GetMissilesInBoundingBox for "+ GetType()+ " is " + box.Size); List <IMyEntity> entitiesFound = MyAPIGateway.Entities.GetEntitiesInAABB(ref box); HashSet <IMyEntity> entitySet = new HashSet <IMyEntity>(); foreach (IMyEntity ent in entitiesFound) { if ((ent.GetType().ToString() == GuidedMissileSingleton.SandboxGameWeaponsMyMissile) && (!GuidedMissileSingleton.IsGuidedMissile(ent))) { // Log.Info("detected something not yet added with speed: " + (ent.Physics.LinearVelocity - Entity.GetTopMostParent().Physics.LinearVelocity).Length()); // Log.Info("topmostparent velocity was " + Entity.GetTopMostParent().Physics.LinearVelocity); if ((ent.Physics.LinearVelocity - Entity.GetTopMostParent().Physics.LinearVelocity).Length() > 110) { Log.Info("found something"); entitySet.Add(ent); } else { // Log.Info("Missile was too fast! Adding to ignoreSet"); GuidedMissileSingleton.GetInstance().IgnoreSet.Add(ent); } } } return(entitySet); }
public static GuidedMissileSingleton GetInstance() { if (_instance == null) { _instance = new GuidedMissileSingleton(); } return(_instance); }
protected override void GuideMissiles(HashSet <IMyEntity> missileSet) { // Log.Info("called guidemissiles in flarelauncher"); try { if (missileSet == null) { return; } if (missileSet.Count == 0) { return; } Log.Info("Set wasnt 0 or empty"); ISet <IMyEntity> incomingMissiles = GuidedMissileSingleton.GetMissilesByTargetGrid(Entity.GetTopMostParent()); if (incomingMissiles.Count == 0) { return; } foreach (IMyEntity guidedMissile in incomingMissiles) { foreach (IMyEntity flare in missileSet) { if (!_flareSet.Contains(flare)) { Log.Info("got a flare: "); _flareSet.Add(flare); int randomNumber = GuidedMissileCore.GetSyncedRandom().Next(1, 10); if (randomNumber > (int)Math.Round(DeflectChance * 10)) { GuidedMissileSingleton.SetTargetForMissile(guidedMissile, flare); Log.Info("won dice roll! setting flare target for missile! " + randomNumber); } else { Log.Info("failed dice roll! not deflecting missile! " + randomNumber); } } } } foreach (IMyEntity flare in _flareSet) { if ((flare == null) || (flare.MarkedForClose)) { _deleteSet.Add(flare); } _flareSet.ExceptWith(_deleteSet); _deleteSet.Clear(); } } catch (Exception e) { Log.Info("flares failed to work! caught exception: " + e); } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { this._objectBuilder = objectBuilder; // Log.Info("A missile Control turret was created"); try { GuidedMissileSingleton.GetInstance().AddTurretToSet(Entity); } catch { Log.Info("apparently entity or something else was null...tracking"); Log.Info("GuidedMissileSingleton.GetInstance: " + GuidedMissileSingleton.GetInstance()); Log.Info("Entity: " + Entity); } Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; }
protected virtual void GuideMissiles(HashSet <IMyEntity> missileSet) { if (missileSet == null) { return; } if (missileSet.Count == 0) { return; } Action <IMyEntity> onExplode = OnExplodeMissile; //Hook for implementation of abstract method foreach (IMyEntity ent in missileSet) { var target = GetTarget(ent); if (target != null) { GuidedMissileSingleton.GetInstance().AddMissileToDict(ent, target, SafetyTimer, DeathTimer, TurningSpeed, onExplode, HasPhysicsSteering); } } }