Last active
January 2, 2019 03:59
-
-
Save descention/1c201f8c25e47973eb7de34518c9a428 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MiningJob | |
{ | |
public Asteroid TargetAsteroid { get; set; } | |
public int Row { get; set; } | |
public int Column { get; set; } | |
internal MiningVessel _vessel; | |
public bool FinishedBore { get; internal set; } | |
internal Size BoreSize{get;set;} | |
public MiningJob(Asteroid asteroid, MiningVessel vessel) | |
{ | |
_vessel = vessel; | |
TargetAsteroid = asteroid; | |
Row = 0; | |
Column = 0; | |
} | |
<snip> | |
internal double? _progressFromIni = null; | |
public double Progress | |
{ | |
get | |
{ | |
if (_progressFromIni.HasValue) | |
return _progressFromIni.Value; | |
try | |
{ | |
return IsInsideAsteroidSoi ? 0.0 : FinishedBore ? 1.0 : GetDistanceFromBoreStart / (CurrentVectorStart - CurrentVectorEnd).Length(); | |
} | |
catch | |
{ | |
return 0.0; | |
} | |
} | |
internal set | |
{ | |
_progressFromIni = value; | |
} | |
} | |
public string ToIini(MyIni ini = null, string section = nameof(MiningJob)) | |
{ | |
if (ini == null) | |
ini = new MyIni(); | |
ini.Set(section, nameof(Row), Row); | |
ini.Set(section, nameof(Column), Column); | |
ini.Set(section, nameof(Progress), Progress); | |
ini.Set(section, nameof(GetDistanceFromBoreStart), GetDistanceFromBoreStart); | |
TargetAsteroid.ToIni(ini); | |
return ini.ToString(); | |
} | |
public static MiningJob FromIni(MyIni ini, string section = nameof(MiningJob)) | |
{ | |
try | |
{ | |
var target = Asteroid.TryParseFromIni(ini); | |
if (target == null) | |
return null; | |
var job = new MiningJob(target, null); | |
job.Row = ini.Get(section, nameof(job.Row)).ToInt32(); | |
job.Column = ini.Get(section, nameof(job.Column)).ToInt32(); | |
job.Progress = ini.Get(section, nameof(job.Progress)).ToDouble(); | |
job.GetDistanceFromBoreStart = ini.Get(section, nameof(job.GetDistanceFromBoreStart)).ToDouble(); | |
return job; | |
} | |
catch | |
{ | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment