public ItemId PreformAction(Colony colony, RoamingJobState machineState) { if (machineState.GetActionEnergy(MachineConstants.REFUEL) < .75f) { var stockpile = colony.Stockpile; foreach (var item in FuelValues) { while ((stockpile.AmountContained(item.Key) > 100 || item.Key == ColonyBuiltIn.ItemTypes.FIREWOOD || item.Key == ColonyBuiltIn.ItemTypes.COALORE) && machineState.GetActionEnergy(MachineConstants.REFUEL) < RoamingJobState.GetActionsMaxEnergy(MachineConstants.REFUEL, colony, MachineConstants.MECHANICAL)) { stockpile.TryRemove(item.Key); machineState.AddToActionEmergy(MachineConstants.REFUEL, item.Value); } } if (machineState.GetActionEnergy(MachineConstants.REFUEL) < RoamingJobState.GetActionsMaxEnergy(MachineConstants.REFUEL, colony, MachineConstants.MECHANICAL)) { return(FuelValues.First().Key); } } return(ObjectiveLoadEmptyIcon); }
public static ItemId Refuel(Colony colony, RoamingJobState machineState) { if (machineState.GetActionEnergy(MachineConstants.REFUEL) < .75f) { RoamingJobState paired = null; if (_paired.ContainsKey(machineState.Position)) { GetPadAt(_paired[machineState.Position], out paired); } var stockpile = colony.Stockpile; while (stockpile.TryRemove(SettlersBuiltIn.ItemTypes.MANA) && machineState.GetActionEnergy(MachineConstants.REFUEL) < RoamingJobState.GetActionsMaxEnergy(MachineConstants.REFUEL, colony, MachineConstants.MECHANICAL)) { machineState.AddToActionEmergy(MachineConstants.REFUEL, 0.20f); if (paired != null) { paired.AddToActionEmergy(MachineConstants.REFUEL, 0.20f); } } if (machineState.GetActionEnergy(MachineConstants.REFUEL) < RoamingJobState.GetActionsMaxEnergy(MachineConstants.REFUEL, colony, MachineConstants.MECHANICAL)) { return(SettlersBuiltIn.ItemTypes.MANA); } } return(ItemId.GetItemId(GameLoader.NAMESPACE + ".Refuel")); }
public static ItemId Reload(Colony colony, RoamingJobState machineState) { var retval = ItemId.GetItemId(GameLoader.NAMESPACE + ".Reload"); try { if (TurretSettings.ContainsKey(machineState.RoamObjective) && machineState.GetActionEnergy(MachineConstants.RELOAD) < .75f) { var stockpile = colony.Stockpile; while (stockpile.Contains(TurretSettings[machineState.RoamObjective].Ammo) && machineState.GetActionEnergy(MachineConstants.RELOAD) <= RoamingJobState.GetActionsMaxEnergy(MachineConstants.RELOAD, colony, MachineConstants.MECHANICAL)) { if (stockpile.TryRemove(TurretSettings[machineState.RoamObjective].Ammo)) { machineState.AddToActionEmergy(MachineConstants.RELOAD, TurretSettings[machineState.RoamObjective].AmmoReloadValue); if (TurretSettings[machineState.RoamObjective].Ammo.Any(itm => itm.Type == ColonyBuiltIn.ItemTypes.GUNPOWDERPOUCH)) { stockpile.Add(ColonyBuiltIn.ItemTypes.LINENPOUCH); } } } if (machineState.GetActionEnergy(MachineConstants.RELOAD) < RoamingJobState.GetActionsMaxEnergy(MachineConstants.RELOAD, colony, MachineConstants.MECHANICAL)) { retval = ItemId.GetItemId(TurretSettings[machineState.RoamObjective].Ammo.FirstOrDefault(ammo => !stockpile.Contains(ammo)).Type); } } } catch (Exception ex) { SettlersLogger.LogError(ex); } return(retval); }