Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class targetReserve
- {
- public targetReserve(IMyFunctionalBlock we, long e, int ex)
- {
- w = we; eid = e; expire = ex;
- }
- public IMyFunctionalBlock w;
- public long eid;
- public int expire;
- }
- List<IMyFunctionalBlock> desynced = new List<IMyFunctionalBlock>();
- List<targetReserve> reservations = new List<targetReserve>();
- targetReserve targetReserved(long e)
- {
- foreach (var r in reservations) if (r.eid == e) return r;
- return null;
- }
- static Profiler wpndsyncP = new Profiler("wpndsync");
- void weaponDesync()
- {
- wpndsyncP.s();
- for (int i = 0; i < reservations.Count;)
- {
- if (tick > reservations[i].expire) reservations.RemoveAt(i);
- else i++;
- }
- foreach (var w in desynced)
- {
- w.Enabled = true;
- APIWC.SetWeaponTarget(w, Me.EntityId, 0);
- }
- desynced.Clear();
- if (tick % 60 == 0)
- {
- foreach (var w in desyncGroup)
- {
- APIWC.SetWeaponTarget(w, Me.EntityId, 0);
- if (!desynced.Contains(w) && APIWC.IsWeaponReadyToFire(w))
- {
- var t = APIWC.GetWeaponTarget(w).GetValueOrDefault();
- if (t.Type == MyDetectedEntityType.LargeGrid || t.Type == MyDetectedEntityType.SmallGrid)
- {
- var reservetime = tick + (60 * 2) - 1;
- WeaponState ws = null;
- wsdict.TryGetValue(w, out ws);
- if (ws != null)
- {
- var apx_ttt = (w.GetPosition() - t.Position).Length() / ws.settings.ammoVel;
- reservetime = (int)(apx_ttt * 60) + 30;
- }
- var reserved = targetReserved(t.EntityId);
- if (reserved != null)
- {
- if (reserved.w != w)
- {
- w.Enabled = false;
- desynced.Add(w);
- }
- else reserved.expire = reservetime;
- //effectively, it won't count down until we actually fire
- }
- else
- {
- reservations.Add(new targetReserve(w, t.EntityId, reservetime));
- }
- }
- }
- }
- }
- wpndsyncP.e();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement