Beispiel #1
0
 void BlockFound(GridScanArgs <IMyTerminalBlock> args)
 {
     if (args.First)
     {
         Updating = true;
         Snapshots.Clear();
     }
     if (Owner.PolicyCheck(Policy, args.Item) && (!IgnoreTools || !(args.Item is IMyShipToolBase)))
     {
         for (int i = 0; i < args.Item.InventoryCount; i++)
         {
             var snap = new StorageSnapshot(args.Item, i);
             snap.UpdateStock(_Stock);
             Snapshots.Add(snap);
         }
         if (args.Item is IMyGasTank)
         {
             var snap = new TankSnapshot(args.Item);
             Snapshots.Add(snap);
             snap.UpdateStock(_Stock);
         }
     }
     if (args.Last)
     {
         SnapshotIndex = Snapshots.Count - 1;
         Updating      = false;
     }
 }
        void BlockFound(GridScanArgs <IMyTerminalBlock> item)
        {
            if (item.First)
            {
                Updating       = true;
                Charge.Current = Charge.Total = 0;
                Input.Current  = Input.Total = 0;
                Output.Current = Output.Total = 0;
                Cache.Clear();
            }
            var b = item.Item as IMyBatteryBlock;

            if (b != null && Owner.PolicyCheck(Policy, item.Item))
            {
                BatteryCache cache = new BatteryCache(b);
                cache.Update();
                Cache.Add(cache);
                Input.Add(cache.Input);
                Output.Add(cache.Output);
                Charge.Add(cache.Charge);
            }
            if (item.Last)
            {
                _PreviousRatio = Charge.GetRatio();
                Index          = Cache.Count - 1;
                Updating       = false;
            }
        }
 void GridScanComplete(GridScanArgs <IMyTerminalBlock> item)
 {
     if (item.Last)
     {
         Log("Grid scan complete.");
         BlockFound -= GridScanComplete;
     }
 }
Beispiel #4
0
 void AcquireBlock(GridScanArgs <IMyTerminalBlock> item)
 {
     if (item.First)
     {
         Updating = true;
         AssemblerUpdater.Dispose();
         foreach (var a in Assemblers)
         {
             a.Block = null;
         }
         Refineries.Clear();
     }
     if (Owner.PolicyCheck(Policy, item.Item))
     {
         if (item.Item is IMyRefinery)
         {
             Refineries.Add(item.Item as IMyRefinery);
         }
         if ((item.Item is IMyAssembler) && (!IgnoreSurvivalKits || (item.Item.BlockDefinition.TypeIdString != "MyObjectBuilder_SurvivalKit")))
         {
             bool found = false;
             foreach (var a in Assemblers)
             {
                 if (a.TryAttachBlock(item.Item))
                 {
                     found = true;
                     break;
                 }
             }
             if (!found)
             {
                 Assemblers.Add(new AssemblerInfo(item.Item as IMyAssembler));
             }
         }
     }
     if (item.Last)
     {
         for (int i = Assemblers.Count - 1; i >= 0; i--)
         {
             if (!Assemblers[i].HasBlock)
             {
                 Assemblers.RemoveAt(i);
             }
         }
         Assemblers.Sort((a, b) => a.Block.CustomName.CompareTo(b.Block.CustomName));
         Assemblers.Sort((a, b) => a.Block.CubeGrid.EntityId.CompareTo(b.Block.CubeGrid.EntityId));
         Refineries.Sort((a, b) => a.CustomName.CompareTo(b.CustomName));
         Refineries.Sort((a, b) => a.CubeGrid.EntityId.CompareTo(b.CubeGrid.EntityId));
         AssemblerUpdater = Assemblers.GetEnumerator();
         Updating         = false;
     }
 }
        void GroupScanTick(GridScanArgs <IMyBlockGroup> info)
        {
            if (!GroupBlocks.ContainsKey(info.Item))
            {
                GroupBlocks.Add(info.Item, new List <IMyTerminalBlock>());
            }
            var list = GroupBlocks[info.Item] as List <IMyTerminalBlock>;

            list.Clear();
            info.Item.GetBlocks(list);
            var kv   = new KeyValuePair <IMyBlockGroup, List <IMyTerminalBlock> >(info.Item, list);
            var args = new GridScanArgs <KeyValuePair <IMyBlockGroup, List <IMyTerminalBlock> > >(kv, info.First, info.Last);

            GroupFound?.Invoke(args);
        }
Beispiel #6
0
 void BlockFound(GridScanArgs <IMyTerminalBlock> item)
 {
     if (item.First)
     {
         Updating = true;
         Assemblers.Clear();
     }
     if ((item.Item is IMyAssembler) &&
         (!IgnoreSurvivalKits || (item.Item.BlockDefinition.TypeIdString != "MyObjectBuilder_SurvivalKit")) &&
         Owner.PolicyCheck(AssemblerPolicy, item.Item))
     {
         Assemblers.Add(item.Item as IMyAssembler);
     }
     if (item.Last)
     {
         LoadReserve = new int[Assemblers.Count];
         Updating    = false;
     }
 }
        void TryAttachScreen(GridScanArgs <IMyTerminalBlock> item)
        {   //Check if we found a surface provider block that was used by one of our windows.
            if (item.First)
            {
                Owner.Tick10 -= ScreenUpdateTick;
            }
            var p = item.Item as IMyTextSurfaceProvider;

            if (p != null)
            {
                for (int i = PendingScreens.Count - 1; i >= 0; i--)
                {
                    if (PendingScreens[i].Item1.BlockId == item.Item.EntityId)
                    {   //found a matching block!
                        object     data;
                        IHasOutput job;
                        if ((PendingScreens[i].Item1.SurfaceId <= p.SurfaceCount) && //found a matching surface
                            Jobs.TryGetValue(PendingScreens[i].Item2, out job) && //found an output provider
                            job.TryParseMode(PendingScreens[i].Item3, out data))    //managed to restore its data object
                        {
                            var surface = p.GetSurface(PendingScreens[i].Item1.SurfaceId);
                            if (!Screens.ContainsKey(surface)) //add to active screens if necessary
                            {
                                Screens[surface] = new List <Window>();
                            }
                            Screens[surface].Add(new Window(PendingScreens[i].Item1, surface, data, job));
                        }
                        PendingScreens.RemoveAt(i);
                    }
                }
            }
            if (item.Last)
            {
                PendingScreens.Clear(); //we forget any windows we couldn't restore
                Updater.Dispose();
                Updater           = Screens.GetEnumerator();
                Owner.BlockFound -= TryAttachScreen; //as such, we won't need scanning the grid again
                Owner.Tick10     += ScreenUpdateTick;
            }
        }
 void BlockFound(GridScanArgs <IMyTerminalBlock> block)
 {
     if (block.First)
     {
         Updating = true;
         Inventories.Clear();
         Tanks.Clear();
         ByCategory.Clear();
     }
     if (Owner.PolicyCheck(Policy, block.Item) && (block.Item.InventoryCount > 0 || block.Item is IMyGasTank))
     {
         string key = GetCategoryName(block.Item);
         if (!ByCategory.ContainsKey(key))
         {
             ByCategory[key] = new Ratio(0, 0, 0);
         }
         for (int i = 0; i < block.Item.InventoryCount; i++)
         {
             var inv   = block.Item.GetInventory(i);
             var cache = new InvRatio(inv, block.Item, (float)inv.MaxVolume, (float)inv.CurrentVolume, 1);
             ByCategory[key].Add(cache);
             Inventories.Add(cache);
         }
         if (block.Item is IMyGasTank)
         {
             var tank  = block.Item as IMyGasTank;
             var cache = new Ratio <IMyGasTank>(tank, tank.Capacity, (float)tank.FilledRatio * tank.Capacity, 1);
             ByCategory[key].Add(cache);
             Tanks.Add(cache);
         }
     }
     if (block.Last)
     {
         Inventories.Sort((a, b) => a.Block.CustomName.CompareTo(b.Block.CustomName));
         Tanks.Sort((a, b) => a.Target.CustomName.CompareTo(b.Target.CustomName));
         InvIndex  = Inventories.Count - 1;
         TankIndex = Tanks.Count - 1;
         Updating  = false;
     }
 }
 void GroupFound(GridScanArgs <KeyValuePair <IMyBlockGroup, List <IMyTerminalBlock> > > item)
 {
     if (item.First)
     {
         foreach (var fl in Farms)
         {
             fl.Clear();
         }
         Updating  = true;
         UpdateIdx = Farms.Length - 1;
     }
     if (Owner.PolicyCheck(Policy, item.Item.Key))
     {
         IMyMotorStator       rotor  = item.Item.Value.Find(Farm.UsefulRotor) as IMyMotorStator;
         List <IMySolarPanel> panels = new List <IMySolarPanel>();
         foreach (var b in item.Item.Value)
         {
             if ((b as IMySolarPanel)?.IsWorking ?? false)
             {
                 panels.Add(b as IMySolarPanel);
             }
         }
         if (rotor != null && panels.Count > 0)
         {
             Farms[UpdateIdx].Add(new Farm(rotor, panels));
             if (--UpdateIdx < 0)
             {
                 UpdateIdx = Farms.Length - 1;
             }
         }
     }
     if (item.Last)
     {
         UpdateIdx = Farms.Length - 1;
         Updating  = false;
     }
 }
 void BlockFound(GridScanArgs <IMyTerminalBlock> item)
 {
     if (item.First)
     {
         Updating = true;
         foreach (var d in Doors)
         {
             Intervals[d.Door.EntityId] = d.Interval;
         }
         Doors.Clear();
     }
     if (item.Item is IMyDoor &&
         Owner.PolicyCheck(Policy, item.Item) &&
         !string.IsNullOrWhiteSpace(item.Item.CustomData) &&
         parser.TryParse(item.Item.CustomData, Category))
     {
         var d = new DoorState(item.Item as IMyDoor,
                               parser.Get(Category, "Opposite").ToString(null),
                               parser.Get(Category, "Timeout").ToDouble(0));
         if (!Intervals.TryGetValue(d.Door.EntityId, out d.Interval))
         {
             d.Interval = 0;
         }
         Doors.Add(d);
     }
     if (item.Last)
     {
         Intervals.Clear();
         foreach (var d in Doors)
         {
             d.Opposite = Doors.Find((other) => string.Equals(d.OppositeDoorName, other.Door.CustomName, StringComparison.CurrentCultureIgnoreCase))?.Door;
         }
         UpdateIdx = Doors.Count - 1;
         Updating  = false;
     }
 }
 void GroupFound(GridScanArgs <KeyValuePair <IMyBlockGroup, List <IMyTerminalBlock> > > item)
 {
     if (item.First)
     {
         foreach (var kv in _Airlocks)
         {
             SavedStates[kv.Key.Name] = kv.Value.CurrentState;
         }
         _Airlocks.Clear();
     }
     if (Owner.PolicyCheck(Policy, item.Item.Key) && Airlock.IsAirlock(item.Item.Value))
     {
         var a = new Airlock(item.Item.Value);
         try
         { a.CurrentState = SavedStates[item.Item.Key.Name]; }
         catch (KeyNotFoundException)
         { a.CurrentState = "Idle"; }
         _Airlocks.Add(item.Item.Key, a);
     }
     if (item.Last)
     {
         SavedStates.Clear();
     }
 }