4
public string protocol;
7
public string args = "";
8
public string[] easy_options;
9
public string[] normal_options;
10
public string[] hard_options;
13
public List<AIProfile> load_ai_profiles (string filename)
15
var profiles = new List<AIProfile> ();
17
var file = new KeyFile ();
20
file.load_from_file (filename, KeyFileFlags.NONE);
22
catch (KeyFileError e)
24
warning ("Failed to load AI profiles: %s", e.message);
29
warning ("Failed to load AI profiles: %s", e.message);
33
foreach (string name in file.get_groups ())
35
debug ("Loading AI profile %s", name);
36
var profile = new AIProfile ();
40
profile.protocol = file.get_value (name, "protocol");
41
profile.binary = file.get_value (name, "binary");
42
if (file.has_key (name, "args"))
43
profile.args = file.get_value (name, "args");
44
profile.easy_options = load_options (file, name, "easy");
45
profile.normal_options = load_options (file, name, "normal");
46
profile.hard_options = load_options (file, name, "hard");
48
catch (KeyFileError e)
53
var path = Environment.find_program_in_path (profile.binary);
57
profiles.append (profile);
64
private string[] load_options (KeyFile file, string name, string difficulty) throws KeyFileError
67
while (file.has_key (name, "option-%s-%d".printf (difficulty, count)))
70
string[] options = new string[count];
71
for (var i = 0; i < count; i++)
72
options[i] = file.get_value (name, "option-%s-%d".printf (difficulty, i));