using System;
using Sandbox.ModAPI.Ingame;
using VRage.Game.ModAPI.Ingame.Utilities;
namespace AutoMiningScript
{
public partial class Program : MyGridProgram
{
public class Settings
{
readonly MyIni ini;
public readonly string Id, FleetId, BaseId, Role;
public Settings(string source, string defaultRole, string defaultId)
{
ini=new MyIni(); MyIniParseResult result;
if(!string.IsNullOrWhiteSpace(source) && !ini.TryParse(source,out result)) throw new ArgumentException(L.F(L.CommonCustomDataInvalid,result.ToString()));
Role=Text("System","Role",defaultRole).ToLowerInvariant();
if(Role!=defaultRole) throw new ArgumentException(L.F(L.CommonRoleMismatch,defaultRole));
Id=Text("System","Id",defaultId);FleetId=Text("System","FleetId","mining");BaseId=Text("System","BaseId","base");
if(Id.Length==0 || FleetId.Length==0 || BaseId.Length==0 || Id.Length>64 || FleetId.Length>64) throw new ArgumentException(L.CommonIdLength);
if(Id.IndexOf('\n')>=0 || FleetId.IndexOf('\n')>=0) throw new ArgumentException(L.CommonIdNewline);
}
public string Text(string section,string key,string fallback) { return ini.ContainsKey(section,key)?ini.Get(section,key).ToString().Trim():fallback; }
public double Number(string section,string key,double fallback,double min,double max)
{
double value=Data.ReadNumber(ini,section,key,fallback);
if(value<min || value>max) throw new ArgumentException(L.F(L.CommonConfigRange,section,key,min,max));
return value;
}
public int Integer(string section,string key,int fallback,int min,int max)
{
long value=Data.ReadLong(ini,section,key,fallback);
if(value<min || value>max) throw new ArgumentException(L.F(L.CommonConfigRange,section,key,min,max)); return (int)value;
}
public bool Flag(string section,string key,bool fallback)
{
if(!ini.ContainsKey(section,key)) return fallback;
bool value; if(!bool.TryParse(ini.Get(section,key).ToString(),out value)) throw new ArgumentException(L.F(L.CommonConfigBool,section,key)); return value;
}
public static string Template(string role,string id)
{
return "; "+L.CommonTemplateIntro+"\n[System]\nRole="+role+"\nId="+id+"\nFleetId=mining\nBaseId=base\n\n[Flight]\n; "+L.CommonTemplateMass+"\nDepartureMass=0\n\n[Mining]\nTargetOres=Iron,Nickel,Cobalt\nFootprintWidth=6\nFootprintHeight=6\nOverlap=0.15\nHoleRadius=3\nDrillSpeed=0.5\nSortieDepthBudget=15\nMaxEntryRelief=5\nApproachDistance=20\n\n[Survey]\nBaseClearance=80\nSpacing=60\nExpansionWidth=60\nExpansionHeight=60\nMaxDepth=100\nMaxJobs=2048\n\n[Energy]\nReturnBattery=0.25\nChargeTarget=0.90\n\n[Cargo]\nReturnFill=0.95\n\n[Dock]\nMaxBaseSpeed=5\nMaxBaseAngularDeg=0.2\nMaxBaseAcceleration=0.1\nMaxTelemetryAge=0.5\nApproachDistance=30\nFinalSpeed=0.2\n\n[Fleet]\nDockGroup=AMS Docks\nCargoGroup=AMS Cargo\nMaxMiners=16\n\n[Display]\nTag=[AMS LCD]\nPage=0\nBuiltIn=true\nBuiltInPage=config\nFont=Debug\nAutoPage=true\nPageInterval=8\nManualHoldSeconds=20\n\n[Watchdog]\nEnabled=false\nTimeout=3\n";
}
}
}
}
using System;
using Sandbox.ModAPI.Ingame;
using VRage.Game.ModAPI.Ingame.Utilities;
namespace AutoMiningScript
{
public partial class Program : MyGridProgram
{
public class Settings
{
readonly MyIni ini;
public readonly string Id, FleetId, BaseId, Role;
public Settings(string source, string defaultRole, string defaultId)
{
ini=new MyIni(); MyIniParseResult result;
if(!string.IsNullOrWhiteSpace(source) && !ini.TryParse(source,out result)) throw new ArgumentException(L.F(L.CommonCustomDataInvalid,result.ToString()));
Role=Text("System","Role",defaultRole).ToLowerInvariant();
if(Role!=defaultRole) throw new ArgumentException(L.F(L.CommonRoleMismatch,defaultRole));
Id=Text("System","Id",defaultId);FleetId=Text("System","FleetId","mining");BaseId=Text("System","BaseId","base");
if(Id.Length==0 || FleetId.Length==0 || BaseId.Length==0 || Id.Length>64 || FleetId.Length>64) throw new ArgumentException(L.CommonIdLength);
if(Id.IndexOf('\n')>=0 || FleetId.IndexOf('\n')>=0) throw new ArgumentException(L.CommonIdNewline);
}
public string Text(string section,string key,string fallback) { return ini.ContainsKey(section,key)?ini.Get(section,key).ToString().Trim():fallback; }
public double Number(string section,string key,double fallback,double min,double max)
{
double value=Data.ReadNumber(ini,section,key,fallback);
if(value<min || value>max) throw new ArgumentException(L.F(L.CommonConfigRange,section,key,min,max));
return value;
}
public int Integer(string section,string key,int fallback,int min,int max)
{
long value=Data.ReadLong(ini,section,key,fallback);
if(value<min || value>max) throw new ArgumentException(L.F(L.CommonConfigRange,section,key,min,max)); return (int)value;
}
public bool Flag(string section,string key,bool fallback)
{
if(!ini.ContainsKey(section,key)) return fallback;
bool value; if(!bool.TryParse(ini.Get(section,key).ToString(),out value)) throw new ArgumentException(L.F(L.CommonConfigBool,section,key)); return value;
}
public static string Template(string role,string id)
{
return "; "+L.CommonTemplateIntro+"\n[System]\nRole="+role+"\nId="+id+"\nFleetId=mining\nBaseId=base\n\n[Flight]\n; "+L.CommonTemplateMass+"\nDepartureMass=0\n\n[Mining]\nTargetOres=Iron,Nickel,Cobalt\nFootprintWidth=6\nFootprintHeight=6\nOverlap=0.15\nHoleRadius=3\nDrillSpeed=0.5\nSortieDepthBudget=15\nMaxEntryRelief=5\nApproachDistance=20\n\n[Survey]\nBaseClearance=80\nSpacing=60\nExpansionWidth=60\nExpansionHeight=60\nMaxDepth=100\nMaxJobs=2048\n\n[Energy]\nReturnBattery=0.25\nChargeTarget=0.90\n\n[Cargo]\nReturnFill=0.95\n\n[Dock]\nMaxBaseSpeed=5\nMaxBaseAngularDeg=0.2\nMaxBaseAcceleration=0.1\nMaxTelemetryAge=0.5\nApproachDistance=30\nFinalSpeed=0.2\n\n[Fleet]\nDockGroup=AMS Docks\nCargoGroup=AMS Cargo\nMaxMiners=16\n\n[Display]\nTag=[AMS LCD]\nPage=0\nBuiltIn=true\nBuiltInPage=config\nFont=Debug\nAutoPage=true\nPageInterval=8\nManualHoldSeconds=20\n\n[Watchdog]\nEnabled=false\nTimeout=3\n";
}
}
}
}