Ejemplo n.º 1
0
 void Load(MyIni state)
 {
     InventorySlice = state.Get(JobName, "InventorySlice").ToUInt16(50);
     Policy         = state.Get(JobName, "Policy").ToString("SameConstruct");
     Owner.Unsubscribe(UpdateInventoryTick, Tick);
     Tick = Owner.Subscribe(UpdateInventoryTick, state.Get(JobName, "Update").ToString(), "update100s");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempts to parse a string into a policy descriptor. Format examples:<para/>
        /// Any - accept any blocks available to PB<para/>
        /// SameGrid - only accept blocks on the same grid as PB<para/>
        /// SameConstruct|GroupName:TheGroup - accept blocks on the same construct that are a part of the group named "TheGroup"<para/>
        /// SameConstruct|SameOwner - accept blocks on the same construct that have same owner as PB<para/>
        /// SameConstruct|BlockTag:Name Tag - accept blocks on the same construct that have "Name Tag" in their CustomName.<para/>
        /// </summary>
        /// <param name="data">Input string.</param>
        /// <param name="policy">Policy object.</param>
        /// <returns>True if parsing was successful.</returns>
        public static bool TryParse(string data, out GridPolicy policy)
        {
            policy = new GridPolicy();
            Types  type = Types.Any;
            Types  part;
            int    name_sep = data.IndexOf(':');
            string types    = (name_sep < 0) ? data : data.Substring(0, name_sep);
            int    lastidx  = 0;

            while (lastidx < types.Length)
            {
                int idx = types.IndexOf("|", lastidx);
                if (idx < 0)
                {
                    idx = types.Length;
                }
                if (!Enum.TryParse(types.Substring(lastidx, idx - lastidx), true, out part))
                {
                    return(false);
                }
                type   |= part;
                lastidx = idx + 2;
            }
            string name = (name_sep < 0) ? string.Empty : data.Substring(name_sep + 1);
            byte   v    = (byte)(type & (Types.BlockName | Types.BlockTag | Types.GroupName | Types.GroupTag));

            //ensure no more than one of those flags is set
            //ensure if one of those flags is set, name is set too
            if (((v & (v - 1)) != 0) || (v != 0 && string.IsNullOrEmpty(name)))
            {
                return(false);
            }
            policy = new GridPolicy(type, name);
            return(true);
        }
Ejemplo n.º 3
0
 public JobSmartAirlock(Scheduler owner, GridPolicy policy, string tick)
 {
     Owner             = owner;
     Policy            = policy;
     Owner.GroupFound += GroupFound;
     Airlocks          = _Airlocks;
 }
Ejemplo n.º 4
0
 public JobBattery(Scheduler owner, GridPolicy policy, string tick)
 {
     Owner             = owner;
     Owner.BlockFound += BlockFound;
     Batteries         = Cache;
     Policy            = policy;
     Tick              = tick;
     Owner.Subscribe(UpdateBlock, tick);
 }
 public JobCapacityMonitor(Scheduler owner, ScreenManager manager)
 {
     Owner             = owner;
     Manager           = manager;
     Policy            = GridPolicy.Types.SameConstruct;
     owner.BlockFound += BlockFound;
     owner.Saving     += Save;
     owner.Loading    += Load;
 }
 public JobCapacityMonitor(Scheduler owner, ScreenManager manager, GridPolicy policy, string updateTick)
 {
     Owner   = owner;
     Manager = manager;
     Policy  = policy;
     Tick    = updateTick;
     Owner.Subscribe(UpdateBlocks, Tick);
     owner.BlockFound += BlockFound;
 }
Ejemplo n.º 7
0
 public JobStockUpkeep(Scheduler owner, JobInventory tracker, GridPolicy assmpolicy, bool ignoresurvkits, string tick)
 {
     Owner              = owner;
     Tracker            = tracker;
     AssemblerPolicy    = assmpolicy;
     IgnoreSurvivalKits = ignoresurvkits;
     Tick              = Owner.Subscribe(RecalculateStock, tick);
     Owner.BlockFound += BlockFound;
 }
Ejemplo n.º 8
0
 void Load(MyIni state)
 {
     if (!GridPolicy.TryParse(state.Get(ID, "Policy").ToString(), out Policy))
     {
         Policy = GridPolicy.Types.SameConstruct;
     }
     Owner.Unsubscribe(UpdateBlock, Tick);
     Tick = Owner.Subscribe(UpdateBlock, state.Get(ID, "Update").ToString(), "update100s");
 }
Ejemplo n.º 9
0
 public JobBattery(Scheduler owner)
 {
     Owner             = owner;
     Owner.BlockFound += BlockFound;
     Owner.Loading    += Load;
     Owner.Saving     += Save;
     Batteries         = Cache;
     Policy            = GridPolicy.Types.SameConstruct;
     Tick              = "update100s";
 }
 void Load(MyIni state)
 {
     InventorySlice = state.Get(ID, "InventorySlice").ToInt32(50);
     if (!GridPolicy.TryParse(state.Get(ID, "Policy").ToString("SameGrid"), out Policy))
     {
         Policy = GridPolicy.Types.SameGrid;
     }
     Owner.Unsubscribe(UpdateBlocks, Tick);
     Tick = Owner.Subscribe(UpdateBlocks, state.Get(ID, "Update").ToString(), "update100s");
 }
Ejemplo n.º 11
0
 public JobSolarSimple(Scheduler owner)
 {
     Owner             = owner;
     Policy            = new GridPolicy(GridPolicy.Types.SameConstruct | GridPolicy.Types.GroupTag, "Solar");
     Tick              = "update100";
     Owner.Fault      += Fault;
     Owner.GroupFound += GroupFound;
     Owner.Loading    += Load;
     Owner.Saving     += Save;
 }
Ejemplo n.º 12
0
 public JobDoorControl(Scheduler owner, GridPolicy policy)
 {
     Owner             = owner;
     Policy            = policy;
     Owner.BlockFound += BlockFound;
     Owner.Tick10     += Update;
     Owner.Loading    += Load;
     Owner.Saving     += Save;
     LoadConfig        = false;
 }
Ejemplo n.º 13
0
 public JobStockUpkeep(Scheduler owner, JobInventory tracker)
 {
     Owner              = owner;
     Tracker            = tracker;
     AssemblerPolicy    = GridPolicy.Types.SameGrid;
     IgnoreSurvivalKits = true;
     Tick              = "update100s";
     Owner.BlockFound += BlockFound;
     Owner.Loading    += Load;
     Owner.Saving     += Save;
 }
Ejemplo n.º 14
0
 /// <summary>This constructor uses provided paramaters to configure the job.</summary>
 /// <param name="owner">Scheduler to attach to.</param>
 /// <param name="block_policy">Which blocks to use.</param>
 /// <param name="ignore_tools">If True, ship tools (welders/grinders/drills) are ignored.</param>
 public JobInventory(Scheduler owner, GridPolicy block_policy, bool ignore_tools, string tick)
 {
     Owner             = owner;
     Stock             = _Stock;
     Owner.BlockFound += BlockFound;
     Owner.RegisterCommand(JobName, Command);
     Inventories = Snapshots;
     Tick        = Owner.Subscribe(UpdateInventoryTick, tick);
     Policy      = block_policy;
     IgnoreTools = ignore_tools;
 }
Ejemplo n.º 15
0
 public JobProductionMonitor(Scheduler owner, ScreenManager manager, GridPolicy policy, string tick, bool ignore_survkits)
 {
     Owner              = owner;
     Manager            = manager;
     LoadConfig         = false;
     Policy             = policy;
     IgnoreSurvivalKits = ignore_survkits;
     Tick              = Owner.Subscribe(UpdateProductionState, tick);
     Owner.Saving     += Save;
     Owner.Loading    += Load;
     Owner.BlockFound += AcquireBlock;
 }
Ejemplo n.º 16
0
 public JobProductionMonitor(Scheduler owner, ScreenManager manager)
 {
     Owner              = owner;
     Manager            = manager;
     LoadConfig         = true;
     Policy             = GridPolicy.Types.SameConstruct;
     IgnoreSurvivalKits = true;
     Tick              = "update100s";
     Owner.Saving     += Save;
     Owner.Loading    += Load;
     Owner.BlockFound += AcquireBlock;
 }
Ejemplo n.º 17
0
 /// <summary>This constructor will have job config loaded from saved state instead.</summary>
 /// <param name="owner">Scheduler to attach to.</param>
 public JobInventory(Scheduler owner)
 {
     Owner             = owner;
     Stock             = _Stock;
     Owner.BlockFound += BlockFound;
     Owner.RegisterCommand(JobName, Command);
     Inventories    = Snapshots;
     Policy         = GridPolicy.Types.SameConstruct;
     IgnoreTools    = true;
     Tick           = "update100s";
     Owner.Loading += Load;
     Owner.Saving  += Save;
 }
Ejemplo n.º 18
0
 void Load(MyIni state)
 {
     if (!GridPolicy.TryParse(state.Get(ID, "Policy").ToString(), out Policy))
     {
         Policy = new GridPolicy(GridPolicy.Types.SameConstruct | GridPolicy.Types.GroupTag, "Solar");
     }
     Tick     = Owner.Subscribe(Update, state.Get(ID, "Update").ToString(), "update100");
     Velocity = (float)state.Get(ID, "VelocityRad").ToDouble(0.04);
     Farms    = new List <Farm> [state.Get(ID, "UpdateMultiplier").ToInt32(3)];
     for (int i = 0; i < Farms.Length; i++)
     {
         Farms[i] = new List <Farm>();
     }
 }
Ejemplo n.º 19
0
 public JobSolarSimple(Scheduler owner, GridPolicy policy, string tick, float velocity, int every = 3)
 {
     Owner             = owner;
     Policy            = policy;
     Tick              = Owner.Subscribe(Update, tick);
     Velocity          = velocity;
     Owner.Fault      += Fault;
     Owner.GroupFound += GroupFound;
     Farms             = new List <Farm> [every];
     for (int i = 0; i < Farms.Length; i++)
     {
         Farms[i] = new List <Farm>();
     }
 }
Ejemplo n.º 20
0
        /// <summary>Convenience method for a job to check if this job should use this particular block group.</summary>
        /// <param name="policy">Structure describing block usage policy. See <see cref="GridPolicy"/>.</param>
        /// <param name="group">Block group to be tested.</param>
        /// <returns>True if group matches the policy.</returns>
        public bool PolicyCheck(GridPolicy policy, IMyBlockGroup group)
        {
            bool success = true;

            success = success && (((policy.Type & GridPolicy.Types.SameOwner) == 0) || Groups[group].All((b) => PB.Me.OwnerId == b.OwnerId));
            success = success && (((policy.Type & GridPolicy.Types.SameConstruct) == 0) || Groups[group].All((b) => PB.Me.IsSameConstructAs(b)));
            success = success && (((policy.Type & GridPolicy.Types.SameGrid) == 0) || Groups[group].All((b) => PB.Me.CubeGrid == b.CubeGrid));
            if (success && (policy.Type & GridPolicy.Types.GroupName) != 0)
            {
                success = string.Equals(policy.Name, group.Name, StringComparison.CurrentCultureIgnoreCase);
            }
            else if (success && (policy.Type & GridPolicy.Types.GroupTag) != 0)
            {
                success = group.Name.IndexOf(policy.Name, StringComparison.CurrentCultureIgnoreCase) >= 0;
            }
            return(success);
        }
Ejemplo n.º 21
0
        void Load(MyIni state)
        {
            if (LoadConfig)
            {
                Policy             = state.Get(ID, "Policy").ToString();
                IgnoreSurvivalKits = state.Get(ID, "IgnoreSurvivalKits").ToBoolean(true);
                Owner.Unsubscribe(UpdateProductionState, Tick);
                Tick = Owner.Subscribe(UpdateProductionState, state.Get(ID, "Update").ToString(), "update100s");
            }
            List <MyIniKey> keys = new List <MyIniKey>();

            Assemblers.Clear();
            Refineries.Clear();
            state.GetKeys(ID + ".Assemblers", keys);
            foreach (var key in keys)
            {
                Assemblers.Add(new AssemblerInfo(key.Name, state.Get(key).ToString()));
            }
        }
Ejemplo n.º 22
0
        /// <summary>Convenience method for a job to check if this job should use this particular block.</summary>
        /// <param name="policy">Structure describing block usage policy. See <see cref="GridPolicy"/>.</param>
        /// <param name="block">Block to be tested.</param>
        /// <returns>True if block matches the policy.</returns>
        public bool PolicyCheck(GridPolicy policy, IMyTerminalBlock block)
        {
            bool success = true;

            success = success && (((policy.Type & GridPolicy.Types.SameOwner) == 0) || (block.OwnerId == PB.Me.OwnerId));
            success = success && (((policy.Type & GridPolicy.Types.SameConstruct) == 0) || PB.Me.IsSameConstructAs(block));
            success = success && (((policy.Type & GridPolicy.Types.SameGrid) == 0) || (block.CubeGrid == PB.Me.CubeGrid));
            if (success && (policy.Type & GridPolicy.Types.BlockName) != 0)
            {
                success = success && string.Equals(block.CustomName, policy.Name, StringComparison.CurrentCultureIgnoreCase);
            }
            else if (success && (policy.Type & GridPolicy.Types.BlockTag) != 0)
            {
                success = success && (block.CustomName.IndexOf(policy.Name, StringComparison.CurrentCultureIgnoreCase) >= 0);
            }
            else if (success && (policy.Type & GridPolicy.Types.GroupName) != 0)
            {
                success = false;
                foreach (var kv in GroupBlocks)
                {
                    if (string.Equals(policy.Name, kv.Key.Name, StringComparison.CurrentCultureIgnoreCase) && kv.Value.Contains(block))
                    {
                        success = true;
                        break;
                    }
                }
            }
            else if (success && (policy.Type & GridPolicy.Types.GroupTag) != 0)
            {
                success = false;
                foreach (var kv in GroupBlocks)
                {
                    if (kv.Key.Name.IndexOf(policy.Name, StringComparison.CurrentCultureIgnoreCase) >= 0 && kv.Value.Contains(block))
                    {
                        success = true;
                        break;
                    }
                }
            }
            return(success);
        }
Ejemplo n.º 23
0
        void Load(MyIni state)
        {
            AssemblerPolicy    = state.Get(ID, "Policy").ToString();
            IgnoreSurvivalKits = state.Get(ID, "IgnoreSurvivalKits").ToBoolean(true);
            MaxQueue           = state.Get(ID, "MaxQueue").ToInt32(1000);
            Owner.Unsubscribe(RecalculateStock, Tick);
            Tick = Owner.Subscribe(RecalculateStock, state.Get(ID, "Update").ToString(), "update100s");
            string          cat  = ID + ".Limits";
            List <MyIniKey> keys = new List <MyIniKey>();

            state.GetKeys(cat, keys);
            MyItemType type;
            int        amount;

            foreach (MyIniKey key in keys)
            {
                if (AddBlueprint(key.Name, out type) && ((amount = state.Get(key).ToInt32(0)) > 0))
                {
                    DesiredStock[type] = amount;
                }
            }
        }
Ejemplo n.º 24
0
        void Load(MyIni state)
        {
            if (LoadConfig)
            {
                Slice = state.Get(ID, "Slice").ToInt32(50);
                if (!GridPolicy.TryParse(state.Get(ID, "Policy").ToString(), out Policy))
                {
                    Policy = GridPolicy.Types.SameGrid;
                }
            }
            List <MyIniKey> keys = new List <MyIniKey>();

            state.GetKeys(ID + ".Doors", keys);
            long eid;

            foreach (var key in keys)
            {
                if (long.TryParse(key.Name, out eid))
                {
                    Intervals[eid] = Math.Max(0, state.Get(key).ToDouble(0));
                }
            }
        }