internal void SendReassignTargetUpdate(GridAi ai, long targetId, int focusId) { if (IsClient) { PacketsToServer.Add(new FocusPacket { EntityId = ai.MyGrid.EntityId, SenderId = MultiplayerId, PType = PacketType.ReassignTargetUpdate, TargetId = targetId, FocusId = focusId }); } else if (HandlesInput) { PacketsToClient.Add(new PacketInfo { Entity = ai.MyGrid, Packet = new FocusPacket { EntityId = ai.MyGrid.EntityId, SenderId = MultiplayerId, PType = PacketType.ReassignTargetUpdate, TargetId = targetId, FocusId = focusId } }); } }
internal void SendActiveControlUpdate(GridAi ai, MyCubeBlock controlBlock, bool active) { if (IsClient) { uint[] mIds; if (PlayerMIds.TryGetValue(MultiplayerId, out mIds)) { PacketsToServer.Add(new BoolUpdatePacket { MId = ++mIds[(int)PacketType.ActiveControlUpdate], EntityId = controlBlock.EntityId, SenderId = MultiplayerId, PType = PacketType.ActiveControlUpdate, Data = active }); } else { Log.Line($"SendActiveControlUpdate no player MIds found"); } } else if (HandlesInput) { ai.Construct.UpdateConstructsPlayers(controlBlock, PlayerId, active); } else { Log.Line($"SendActiveControlUpdate should never be called on Dedicated"); } }
internal void BuildMasterCollections(GridAi ai) { _masterTargets.Clear(); for (int i = 0; i < ai.Construct.RefreshedAis.Count; i++) { var subTargets = ai.Construct.RefreshedAis[i].SortedTargets; for (int j = 0; j < subTargets.Count; j++) { var tInfo = subTargets[j]; if (tInfo.Target.MarkedForClose) { continue; } HashSet <long> playerSet; var controlType = tInfo.Drone ? TargetControl.Drone : tInfo.IsGrid && _session.PlayerGrids.TryGetValue((MyCubeGrid)tInfo.Target, out playerSet) ? TargetControl.Player : tInfo.IsGrid && !_session.GridHasPower((MyCubeGrid)tInfo.Target) ? TargetControl.Trash : TargetControl.Other; _masterTargets[tInfo.Target] = new MyTuple <float, TargetControl>(tInfo.OffenseRating, controlType); _toPruneMasterDict[tInfo.Target] = tInfo; } } _sortedMasterList.Clear(); _toSortMasterList.AddRange(_toPruneMasterDict.Values); _toPruneMasterDict.Clear(); _toSortMasterList.Sort(_session.TargetCompare); for (int i = 0; i < _toSortMasterList.Count; i++) { _sortedMasterList.Add(_toSortMasterList[i].Target); } _toSortMasterList.Clear(); MasterUpdateTick = ai.Session.Tick; }
internal void SendFakeTargetUpdate(GridAi ai, Vector3 hitPos) { if (IsClient) { PacketsToServer.Add(new FakeTargetPacket { EntityId = ai.MyGrid.EntityId, SenderId = ai.Session.MultiplayerId, PType = PacketType.FakeTargetUpdate, Data = hitPos, }); } else if (HandlesInput) { PacketsToClient.Add(new PacketInfo { Entity = ai.MyGrid, Packet = new FakeTargetPacket { EntityId = ai.MyGrid.EntityId, SenderId = ai.Session.MultiplayerId, PType = PacketType.FakeTargetUpdate, Data = hitPos, } }); } }
internal void SendReleaseActiveUpdate(GridAi ai) { if (IsClient) { PacketsToServer.Add(new FocusPacket { EntityId = ai.MyGrid.EntityId, SenderId = MultiplayerId, PType = PacketType.ReleaseActiveUpdate }); } else if (HandlesInput) { PacketsToClient.Add(new PacketInfo { Entity = ai.MyGrid, Packet = new FocusPacket { EntityId = ai.MyGrid.EntityId, SenderId = MultiplayerId, PType = PacketType.ReleaseActiveUpdate } }); } }
internal void BuildMasterCollections(GridAi ai) { _masterTargets.Clear(); for (int i = 0; i < ai.Construct.RefreshedAis.Count; i++) { var subTargets = ai.Construct.RefreshedAis[i].SortedTargets; for (int j = 0; j < subTargets.Count; j++) { var tInfo = subTargets[j]; if (tInfo.Target.MarkedForClose) { continue; } _masterTargets[tInfo.Target] = tInfo.OffenseRating; _toPruneMasterDict[tInfo.Target] = tInfo; } } _sortedMasterList.Clear(); _toSortMasterList.AddRange(_toPruneMasterDict.Values); _toPruneMasterDict.Clear(); _toSortMasterList.Sort(_session.TargetCompare); for (int i = 0; i < _toSortMasterList.Count; i++) { _sortedMasterList.Add(_toSortMasterList[i].Target); } _toSortMasterList.Clear(); MasterUpdateTick = ai.Session.Tick; }
internal void SendReleaseActiveUpdate(GridAi ai) { if (IsClient) { uint[] mIds; if (PlayerMIds.TryGetValue(MultiplayerId, out mIds)) { PacketsToServer.Add(new FocusPacket { MId = ++mIds[(int)PacketType.ReleaseActiveUpdate], EntityId = ai.MyGrid.EntityId, SenderId = MultiplayerId, PType = PacketType.ReleaseActiveUpdate }); } else { Log.Line($"SendReleaseActiveUpdate no player MIds found"); } } else if (HandlesInput) { PacketsToClient.Add(new PacketInfo { Entity = ai.MyGrid, Packet = new FocusPacket { MId = ++ai.MIds[(int)PacketType.ReleaseActiveUpdate], EntityId = ai.MyGrid.EntityId, SenderId = MultiplayerId, PType = PacketType.ReleaseActiveUpdate } }); } }
internal void SendAiData(GridAi ai) { if (IsServer) { PacketInfo oldInfo; AiDataPacket iPacket; if (PrunedPacketsToClient.TryGetValue(ai.Data.Repo, out oldInfo)) { iPacket = (AiDataPacket)oldInfo.Packet; iPacket.EntityId = ai.MyGrid.EntityId; iPacket.Data = ai.Data.Repo; } else { iPacket = PacketAiPool.Get(); iPacket.MId = ++ai.MIds[(int)PacketType.AiData]; iPacket.EntityId = ai.MyGrid.EntityId; iPacket.SenderId = MultiplayerId; iPacket.PType = PacketType.AiData; iPacket.Data = ai.Data.Repo; } ++ai.Data.Repo.Revision; PrunedPacketsToClient[ai.Data.Repo] = new PacketInfo { Entity = ai.MyGrid, Packet = iPacket, }; } else { Log.Line($"SendAiData should never be called on Client"); } }
internal void SendConstruct(GridAi ai) { if (IsServer) { PrunedPacketsToClient.Remove(ai.Construct.Data.Repo.FocusData); ++ai.Construct.Data.Repo.FocusData.Revision; PacketInfo oldInfo; ConstructPacket iPacket; if (PrunedPacketsToClient.TryGetValue(ai.Construct.Data.Repo, out oldInfo)) { iPacket = (ConstructPacket)oldInfo.Packet; iPacket.EntityId = ai.MyGrid.EntityId; iPacket.Data = ai.Construct.Data.Repo; } else { iPacket = PacketConstructPool.Get(); iPacket.MId = ++ai.MIds[(int)PacketType.Construct]; iPacket.EntityId = ai.MyGrid.EntityId; iPacket.SenderId = MultiplayerId; iPacket.PType = PacketType.Construct; iPacket.Data = ai.Construct.Data.Repo; } PrunedPacketsToClient[ai.Construct.Data.Repo] = new PacketInfo { Entity = ai.MyGrid, Packet = iPacket, }; } else { Log.Line($"SendConstruct should never be called on Client"); } }
private static ConcurrentCachingList <MyCubeBlock> QueryBlockCaches(GridAi ai, MyCubeGrid targetGrid, AreaEffectType effectType) { ConcurrentDictionary <TargetingDef.BlockTypes, ConcurrentCachingList <MyCubeBlock> > blockTypeMap; if (!ai.Session.GridToBlockTypeMap.TryGetValue(targetGrid, out blockTypeMap)) { return(null); } ConcurrentCachingList <MyCubeBlock> cubes; switch (effectType) { case JumpNullField: if (blockTypeMap.TryGetValue(TargetingDef.BlockTypes.Jumping, out cubes)) { return(cubes); } break; case EnergySinkField: if (blockTypeMap.TryGetValue(TargetingDef.BlockTypes.Power, out cubes)) { return(cubes); } break; case AnchorField: if (blockTypeMap.TryGetValue(TargetingDef.BlockTypes.Thrust, out cubes)) { return(cubes); } break; case NavField: if (blockTypeMap.TryGetValue(TargetingDef.BlockTypes.Steering, out cubes)) { return(cubes); } break; case OffenseField: if (blockTypeMap.TryGetValue(TargetingDef.BlockTypes.Offense, out cubes)) { return(cubes); } break; case EmpField: case DotField: GridMap gridMap; if (ai.Session.GridToInfoMap.TryGetValue(targetGrid, out gridMap)) { return(gridMap.MyCubeBocks); } break; } return(null); }
internal void SendOverRidesUpdate(GridAi ai, string groupName, GroupOverrides overRides) { if (MpActive) { ai.UiMId++; if (IsClient) { PacketsToServer.Add(new OverRidesPacket { EntityId = ai.MyGrid.EntityId, SenderId = MultiplayerId, MId = ai.UiMId, GroupName = groupName, PType = PacketType.OverRidesUpdate, Data = overRides, }); } else if (IsServer) { PacketsToClient.Add(new PacketInfo { Entity = ai.MyGrid, Packet = new OverRidesPacket { EntityId = ai.MyGrid.EntityId, SenderId = 0, MId = ai.UiMId, GroupName = groupName, PType = PacketType.OverRidesUpdate, Data = overRides, } }); } } }
internal void SendNextActiveUpdate(GridAi ai, bool addSecondary) { if (IsClient) { PacketsToServer.Add(new FocusPacket { EntityId = ai.MyGrid.EntityId, SenderId = MultiplayerId, PType = PacketType.NextActiveUpdate, AddSecondary = addSecondary }); } else if (HandlesInput) { PacketsToClient.Add(new PacketInfo { Entity = ai.MyGrid, Packet = new FocusPacket { EntityId = ai.MyGrid.EntityId, SenderId = MultiplayerId, PType = PacketType.NextActiveUpdate, AddSecondary = addSecondary } }); } }
private static void SetWeaponTarget(IMyTerminalBlock weaponBlock, IMyEntity target, int weaponId = 0) { WeaponComponent comp; if (weaponBlock.Components.TryGet(out comp) && comp.Platform.State == Ready && comp.Platform.Weapons.Length > weaponId) { GridAi.AcquireTarget(comp.Platform.Weapons[weaponId], false, (MyEntity)target); } }
internal void Clean() { System = null; HitPos = Vector3D.Zero; Ai = null; AmmoDef = null; AttackerId = 0; Damage = 0; Hits = 0; }
public void Init(GridAi ai) { Ai = ai; StorageInit(); Load(); if (Ai.Session.IsServer) { Repo.ControllingPlayers.Clear(); } }
internal void Init(GridAi ai) { Ai = ai; StorageInit(); Load(); if (Ai.Session.IsServer) { Repo.FocusData = new FocusData { Target = new long[2], Locked = new FocusData.LockModes[2] }; } }
private void CheckAcquire() { for (int i = AcquireTargets.Count - 1; i >= 0; i--) { var w = AcquireTargets[i]; var comp = w.Comp; if (w.Comp.IsAsleep || w.Comp.Ai == null || comp.Ai.MyGrid.MarkedForClose || !comp.Ai.HasPower || comp.Ai.Concealed || comp.MyCube.MarkedForClose || !comp.Ai.DbReady || !comp.IsWorking || w.NoMagsToLoad && w.Ammo.CurrentAmmo == 0 && Tick - w.LastMagSeenTick > 600) { w.AcquiringTarget = false; AcquireTargets.RemoveAtFast(i); continue; } if (!w.Acquire.Monitoring && IsServer && w.TrackTarget) { AcqManager.Monitor(w.Acquire); } var acquire = (w.Acquire.IsSleeping && AsleepCount == w.Acquire.SlotId || !w.Acquire.IsSleeping && AwakeCount == w.Acquire.SlotId); var seekProjectile = w.ProjectilesNear || w.System.TrackProjectile && w.Comp.Data.Repo.Base.Set.Overrides.Projectiles && w.Comp.Ai.CheckProjectiles; var checkTime = w.Target.TargetChanged || acquire || seekProjectile || w.FastTargetResetTick == Tick; if (checkTime || w.Comp.Ai.TargetResetTick == Tick && w.Target.HasTarget) { if (seekProjectile || comp.Data.Repo.Base.State.TrackingReticle || (comp.TargetNonThreats && w.Comp.Ai.TargetingInfo.OtherInRange || w.Comp.Ai.TargetingInfo.ThreatInRange) && w.Comp.Ai.TargetingInfo.ValidTargetExists(w)) { if (comp.TrackingWeapon != null && comp.TrackingWeapon.System.DesignatorWeapon && comp.TrackingWeapon != w && comp.TrackingWeapon.Target.HasTarget) { var topMost = comp.TrackingWeapon.Target.Entity?.GetTopMostParent(); GridAi.AcquireTarget(w, false, topMost); } else { GridAi.AcquireTarget(w, w.Comp.Ai.TargetResetTick == Tick); } } if (w.Target.HasTarget || !(comp.TargetNonThreats && w.Comp.Ai.TargetingInfo.OtherInRange || w.Comp.Ai.TargetingInfo.ThreatInRange)) { w.AcquiringTarget = false; AcquireTargets.RemoveAtFast(i); if (w.Target.HasTarget && MpActive) { w.Target.PushTargetToClient(w); } } } } }
internal bool CheckTarget(GridAi ai) { if (!ai.Focus.IsFocused(ai)) { return(false); } if (ai != TrackingAi) { TrackingAi = null; return(false); } return(ai.Focus.HasFocus); }
internal bool CheckTarget(GridAi ai) { if (!ai.Construct.Focus.ClientIsFocused(ai)) { return(false); } if (ai != TrackingAi) { TrackingAi = null; return(false); } return(ai.Construct.Data.Repo.FocusData.HasFocus); }
internal static void SyncGridOverrides(GridAi ai, string groupName, GroupOverrides o) { ai.BlockGroups[groupName].Settings["Active"] = o.Activate ? 1 : 0; ai.BlockGroups[groupName].Settings["Neutrals"] = o.Neutrals ? 1 : 0; ai.BlockGroups[groupName].Settings["Projectiles"] = o.Projectiles ? 1 : 0; ai.BlockGroups[groupName].Settings["Biologicals"] = o.Biologicals ? 1 : 0; ai.BlockGroups[groupName].Settings["Meteors"] = o.Meteors ? 1 : 0; ai.BlockGroups[groupName].Settings["Friendly"] = o.Friendly ? 1 : 0; ai.BlockGroups[groupName].Settings["Unowned"] = o.Unowned ? 1 : 0; ai.BlockGroups[groupName].Settings["TargetPainter"] = o.TargetPainter ? 1 : 0; ai.BlockGroups[groupName].Settings["ManualControl"] = o.ManualControl ? 1 : 0; ai.BlockGroups[groupName].Settings["FocusTargets"] = o.FocusTargets ? 1 : 0; ai.BlockGroups[groupName].Settings["FocusSubSystem"] = o.FocusSubSystem ? 1 : 0; ai.BlockGroups[groupName].Settings["SubSystems"] = (int)o.SubSystem; }
internal void SendFakeTargetUpdate(GridAi ai, GridAi.FakeTarget fake) { if (IsClient) { uint[] mIds; if (PlayerMIds.TryGetValue(MultiplayerId, out mIds)) { PacketsToServer.Add(new FakeTargetPacket { MId = ++mIds[(int)PacketType.FakeTargetUpdate], EntityId = ai.MyGrid.EntityId, SenderId = ai.Session.MultiplayerId, PType = PacketType.FakeTargetUpdate, Pos = fake.Position, TargetId = fake.EntityId, }); } else { Log.Line($"SendFakeTargetUpdate no player MIds found"); } } else if (HandlesInput) { PacketsToClient.Add(new PacketInfo { Entity = ai.MyGrid, Packet = new FakeTargetPacket { MId = ++ai.MIds[(int)PacketType.FakeTargetUpdate], EntityId = ai.MyGrid.EntityId, SenderId = ai.Session.MultiplayerId, PType = PacketType.FakeTargetUpdate, Pos = fake.Position, TargetId = fake.EntityId, } }); } else { Log.Line($"SendFakeTargetUpdate should never be called on Dedicated"); } }
internal static GroupOverrides GetOverrides(GridAi ai, string groupName) { var o = new GroupOverrides(); o.Activate = ai.BlockGroups[groupName].Settings["Active"] == 1 ? true : false; o.Neutrals = ai.BlockGroups[groupName].Settings["Neutrals"] == 1 ? true : false; o.Projectiles = ai.BlockGroups[groupName].Settings["Projectiles"] == 1 ? true : false; o.Biologicals = ai.BlockGroups[groupName].Settings["Biologicals"] == 1 ? true : false; o.Meteors = ai.BlockGroups[groupName].Settings["Meteors"] == 1 ? true : false; o.Friendly = ai.BlockGroups[groupName].Settings["Friendly"] == 1 ? true : false; o.Unowned = ai.BlockGroups[groupName].Settings["Unowned"] == 1 ? true : false; o.TargetPainter = ai.BlockGroups[groupName].Settings["TargetPainter"] == 1 ? true : false; o.ManualControl = ai.BlockGroups[groupName].Settings["ManualControl"] == 1 ? true : false; o.FocusTargets = ai.BlockGroups[groupName].Settings["FocusTargets"] == 1 ? true : false; o.FocusSubSystem = ai.BlockGroups[groupName].Settings["FocusSubSystem"] == 1 ? true : false; o.SubSystem = (BlockTypes)ai.BlockGroups[groupName].Settings["SubSystems"]; return(o); }
internal void SetTarget(MyEntity entity, GridAi ai, Dictionary <MyEntity, float> masterTargets) { TrackingAi = ai; ai.Construct.Focus.RequestAddFocus(entity, ai); GridAi gridAi; TargetArmed = false; var grid = entity as MyCubeGrid; if (grid != null && GridToMasterAi.TryGetValue(grid, out gridAi)) { TargetArmed = true; } else { float offenseRating; if (!masterTargets.TryGetValue(entity, out offenseRating)) { return; } ConcurrentDictionary <BlockTypes, ConcurrentCachingList <MyCubeBlock> > typeDict; var tGrid = entity as MyCubeGrid; if (tGrid != null && GridToBlockTypeMap.TryGetValue(tGrid, out typeDict)) { ConcurrentCachingList <MyCubeBlock> fatList; if (typeDict.TryGetValue(Offense, out fatList)) { TargetArmed = fatList.Count > 0; } else { TargetArmed = false; } } else { TargetArmed = false; } } }
internal void SetTarget(MyEntity entity, GridAi ai) { TrackingAi = ai; TrackingAi.Focus.AddFocus(entity, ai); GridAi gridAi; TargetArmed = false; var grid = entity as MyCubeGrid; if (grid != null && GridTargetingAIs.TryGetValue(grid, out gridAi)) { TargetArmed = true; } else { TargetInfo info; if (!ai.Targets.TryGetValue(entity, out info)) { return; } ConcurrentDictionary <BlockTypes, ConcurrentCachingList <MyCubeBlock> > typeDict; if (info.IsGrid && GridToBlockTypeMap.TryGetValue((MyCubeGrid)info.Target, out typeDict)) { ConcurrentCachingList <MyCubeBlock> fatList; if (typeDict.TryGetValue(WeaponDefinition.TargetingDef.BlockTypes.Offense, out fatList)) { TargetArmed = fatList.Count > 0; } else { TargetArmed = false; } } else { TargetArmed = false; } } }
internal void SendMouseUpdate(GridAi ai, MyEntity entity) { if (IsClient) { uint[] mIds; if (PlayerMIds.TryGetValue(MultiplayerId, out mIds)) { PacketsToServer.Add(new InputPacket { MId = ++mIds[(int)PacketType.ClientMouseEvent], EntityId = entity.EntityId, SenderId = MultiplayerId, PType = PacketType.ClientMouseEvent, Data = UiInput.ClientInputState }); } else { Log.Line($"SendMouseUpdate no player MIds found"); } } else if (HandlesInput) { PacketsToClient.Add(new PacketInfo { Entity = entity, Packet = new InputPacket { MId = ++ai.MIds[(int)PacketType.ClientMouseEvent], EntityId = entity.EntityId, SenderId = MultiplayerId, PType = PacketType.ClientMouseEvent, Data = UiInput.ClientInputState } }); } else { Log.Line($"SendMouseUpdate should never be called on Dedicated"); } }
internal void SendConstructFoci(GridAi ai) { if (IsServer) { ++ai.Construct.Data.Repo.FocusData.Revision; if (!PrunedPacketsToClient.ContainsKey(ai.Construct.Data.Repo)) { PacketInfo oldInfo; ConstructFociPacket iPacket; if (PrunedPacketsToClient.TryGetValue(ai.Construct.Data.Repo.FocusData, out oldInfo)) { iPacket = (ConstructFociPacket)oldInfo.Packet; iPacket.EntityId = ai.MyGrid.EntityId; iPacket.Data = ai.Construct.Data.Repo.FocusData; } else { iPacket = PacketConstructFociPool.Get(); iPacket.MId = ++ai.MIds[(int)PacketType.ConstructFoci]; iPacket.EntityId = ai.MyGrid.EntityId; iPacket.SenderId = MultiplayerId; iPacket.PType = PacketType.ConstructFoci; iPacket.Data = ai.Construct.Data.Repo.FocusData; } PrunedPacketsToClient[ai.Construct.Data.Repo.FocusData] = new PacketInfo { Entity = ai.MyGrid, Packet = iPacket, }; } else { SendConstruct(ai); } } else { Log.Line($"SendConstructGroups should never be called on Client"); } }
internal static void GetCubesForEffect(GridAi ai, MyCubeGrid grid, Vector3D hitPos, AreaEffectType effectType, List <IMySlimBlock> cubes) { var fats = QueryBlockCaches(ai, grid, effectType); if (fats == null) { return; } for (int i = 0; i < fats.Count; i++) { cubes.Add(fats[i].SlimBlock); } cubes.Sort((a, b) => { var aPos = grid.GridIntegerToWorld(a.Position); var bPos = grid.GridIntegerToWorld(b.Position); return(Vector3D.DistanceSquared(aPos, hitPos).CompareTo(Vector3D.DistanceSquared(bPos, hitPos))); }); }
internal bool NewTarget() { var giveUp = HadTarget && ++NewTargets > Info.ConsumableDef.Const.MaxTargets && Info.ConsumableDef.Const.MaxTargets != 0; ChaseAge = Info.Age; PickTarget = false; if (giveUp || !GridAi.ReacquireTarget(this)) { Info.Target.Entity = null; if (Info.Target.IsProjectile) { UnAssignProjectile(true); } return(false); } if (Info.Target.IsProjectile) { UnAssignProjectile(false); } return(true); }
public void Sync(GridAi ai, FocusData sync, bool localCall = false) { if (ai.Session.IsServer || sync.Revision > Revision) { Revision = sync.Revision; ActiveId = sync.ActiveId; HasFocus = sync.HasFocus; DistToNearestFocusSqr = sync.DistToNearestFocusSqr; for (int i = 0; i < Target.Length; i++) { Target[i] = sync.Target[i]; Locked[i] = sync.Locked[i]; } if (ai == ai.Construct.RootAi && localCall) { ai.Construct.UpdateLeafFoci(); } } //else Log.Line($"FocusData older revision: {sync.Revision} > {Revision}"); }
private TargetStatus.Awareness AggressionState(GridAi ai, GridAi targetAi) { if (targetAi.Construct.Data.Repo.FocusData.HasFocus) { var fd = targetAi.Construct.Data.Repo.FocusData; foreach (var tId in fd.Target) { foreach (var sub in ai.SubGrids) { if (sub.EntityId == tId) { return(TargetStatus.Awareness.FOCUSFIRE); } } } } var tracking = targetAi.Targets.ContainsKey(ai.MyGrid); var hasAggressed = targetAi.Construct.RootAi.Construct.PreviousTargets.Contains(ai.MyGrid); var stalking = tracking && hasAggressed; var seeking = !tracking && hasAggressed; if (stalking) { return(TargetStatus.Awareness.STALKING); } if (seeking) { return(TargetStatus.Awareness.SEEKING); } if (tracking) { return(TargetStatus.Awareness.TRACKING); } return(TargetStatus.Awareness.OBLIVIOUS); }