Advertisement
klassekatze

Untitled

Aug 2nd, 2024
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. class targetReserve
  2. {
  3.     public targetReserve(IMyFunctionalBlock we, long e, int ex)
  4.     {
  5.         w = we; eid = e; expire = ex;
  6.     }
  7.     public IMyFunctionalBlock w;
  8.     public long eid;
  9.     public int expire;
  10. }
  11. List<IMyFunctionalBlock> desynced = new List<IMyFunctionalBlock>();
  12. List<targetReserve> reservations = new List<targetReserve>();
  13. targetReserve targetReserved(long e)
  14. {
  15.     foreach (var r in reservations) if (r.eid == e) return r;
  16.     return null;
  17. }
  18. static Profiler wpndsyncP = new Profiler("wpndsync");
  19. void weaponDesync()
  20. {
  21.     wpndsyncP.s();
  22.     for (int i = 0; i < reservations.Count;)
  23.     {
  24.         if (tick > reservations[i].expire) reservations.RemoveAt(i);
  25.         else i++;
  26.     }
  27.     foreach (var w in desynced)
  28.     {
  29.         w.Enabled = true;
  30.         APIWC.SetWeaponTarget(w, Me.EntityId, 0);
  31.     }
  32.     desynced.Clear();
  33.  
  34.     if (tick % 60 == 0)
  35.     {
  36.         foreach (var w in desyncGroup)
  37.         {
  38.             APIWC.SetWeaponTarget(w, Me.EntityId, 0);
  39.             if (!desynced.Contains(w) && APIWC.IsWeaponReadyToFire(w))
  40.             {
  41.                 var t = APIWC.GetWeaponTarget(w).GetValueOrDefault();
  42.                 if (t.Type == MyDetectedEntityType.LargeGrid || t.Type == MyDetectedEntityType.SmallGrid)
  43.                 {
  44.                     var reservetime = tick + (60 * 2) - 1;
  45.                     WeaponState ws = null;
  46.                     wsdict.TryGetValue(w, out ws);
  47.                     if (ws != null)
  48.                     {
  49.                         var apx_ttt = (w.GetPosition() - t.Position).Length() / ws.settings.ammoVel;
  50.                         reservetime = (int)(apx_ttt * 60) + 30;
  51.                     }
  52.  
  53.                     var reserved = targetReserved(t.EntityId);
  54.                     if (reserved != null)
  55.                     {
  56.                         if (reserved.w != w)
  57.                         {
  58.                             w.Enabled = false;
  59.                             desynced.Add(w);
  60.                         }
  61.                         else reserved.expire = reservetime;
  62.                         //effectively, it won't count down until we actually fire
  63.                     }
  64.                     else
  65.                     {
  66.                         reservations.Add(new targetReserve(w, t.EntityId, reservetime));
  67.                     }
  68.                 }
  69.             }
  70.         }
  71.     }
  72.     wpndsyncP.e();
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement