Skip to content

Commit

Permalink
Update to 2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
askeladdk committed Feb 15, 2017
1 parent 0ab3694 commit 409d816
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 77 deletions.
2 changes: 1 addition & 1 deletion AssemblyInfo.cs
Expand Up @@ -56,4 +56,4 @@
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
[assembly: AssemblyFileVersionAttribute("2.0.2")]
[assembly: AssemblyFileVersionAttribute("2.0.3")]
26 changes: 21 additions & 5 deletions IniParser.cs
Expand Up @@ -12,13 +12,14 @@ public class IniParser
/**
* New parser reads .ini into dictionary.
*/
public static IniDictionary ParseToDictionary(StreamReader stream)
public static IniDictionary ParseToDictionary(StreamReader stream, string filename, Logger logger)
{
IniDictionary ini = new IniDictionary();
OrderedDictionary section = null;
string key, val, line;
int index;
int linenr = 0;
string sectionKey = "";

while( (line = stream.ReadLine()) != null )
{
Expand All @@ -39,27 +40,42 @@ public static IniDictionary ParseToDictionary(StreamReader stream)
else if(line[0] == '[')
{
if( (index = line.IndexOf(']')) == -1 ) continue;
key = line.Substring(1, index - 1);
sectionKey = line.Substring(1, index - 1);
section = new OrderedDictionary();
if( !ini.ContainsKey(key) ) ini.Add(key, section);
if (!ini.ContainsKey(sectionKey))
{
ini.Add(sectionKey, section);
}
else
{
logger.Add("Duplicate section [" + sectionKey + "] in " + filename + "!");
}
}
// key=value pair
else if(section != null)
{
if ((index = line.IndexOf('=')) == -1) continue;
key = line.Substring(0, index).Trim();
val = line.Substring(index + 1).Trim();

if (section.Contains(key))
{
logger.Add("Duplicate tag/index [" + sectionKey + "] => " + key + " in " + filename + "!");
}

section[key] = val;
}
}

return ini;
}

public static IniDictionary ParseToDictionary(string path)
public static IniDictionary ParseToDictionary(string path, Logger logger)
{
StreamReader reader = new StreamReader(path);
IniDictionary d = ParseToDictionary(reader);
string[] fullname = path.Split('\\');

IniDictionary d = ParseToDictionary(reader, fullname[fullname.Length - 1], logger);
reader.Close();
return d;
}
Expand Down
Binary file modified ObjectListView.dll
Binary file not shown.
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -14,6 +14,22 @@ Link: https://github.com/askeladdk/aiedit

## Changelog ##

### v2.0.3 ###
- Changed the wording of the error log messages to be more consistent.
- Updated to ObjectListView 2.9.10.

### v2.0.2.2 (by E1 Elite) ###
- Crash fix, Script Type/Task Force need not have entries in sequence like Name first or Group last.
- Crash fix, Techno Types can have negative cost in rules.
- Bug fix, AITrigger Techno Type <none> entries won't be replaced with another technotype ID
if any Techno Type Name falls before <none> in sorting.
- More log info for possible errors, also duplicate cases logged from rules to certain extent.
- Additional side placeholder entries in config files, just in case user forgets to edit them when
having additional sides.

### v2.0.2.1 (by E1 Elite) ###
- Techno Type name is appended with its ID.

### v2.0.2 ###
- Fixed bug where the last Task Force entry would be swallowed if the Group tag was missing.
- Names are trimmed when new object is created.
Expand Down
43 changes: 26 additions & 17 deletions ScriptType.cs
Expand Up @@ -331,27 +331,36 @@ public void Write(StreamWriter stream)
stream.WriteLine();
}

public static ScriptType Parse(string id, OrderedDictionary section, List<IActionType> types)
public static ScriptType Parse(string id, OrderedDictionary section, List<IActionType> types,
Logger logger)
{
int starti = 1;
string name = section["Name"] as string;
string name = id;
List<ScriptAction> actions = new List<ScriptAction>();

if (name == null)
foreach(DictionaryEntry entry in section)
{
starti = 0;
name = id;
}

for (int i = starti; i < section.Count; i++)
{
string[] split = (section[i] as string).Split(',');
int a = int.Parse(split[0]);
uint p = uint.Parse(split[1]);
IActionType actionType = types[a];

ScriptAction action = new ScriptAction(actionType, p);
actions.Add(action);
if ((entry.Key as string) == "Name")
{
name = entry.Value as string;
}
else
{
string[] split = (entry.Value as string).Split(',');

if (split.Length < 2)
{
logger.Add("ScriptType " + id + ": Entry not in format: <Index>=<Action>,<Parameter>");
}
else
{
int a = int.Parse(split[0]);
uint p = uint.Parse(split[1]);
IActionType actionType = types[a];

ScriptAction action = new ScriptAction(actionType, p);
actions.Add(action);
}
}
}

return new ScriptType(id, name, actions);
Expand Down
78 changes: 47 additions & 31 deletions TaskForce.cs
Expand Up @@ -17,11 +17,11 @@ public class TaskForceEntry
public string Name { get { return unit.Name; } }
public uint Count { get { return count; } set { count = value; } }

public uint Cost
public int Cost
{
get
{
return unit.Cost * count;
return unit.Cost * (int)count;
}
}

Expand Down Expand Up @@ -84,9 +84,9 @@ private TaskForceEntry Add(TechnoType unit, uint count)
return entry;
}

public uint TotalCost()
public int TotalCost()
{
uint cost = 0;
int cost = 0;
foreach(TaskForceEntry entry in this.units)
{
cost += entry.Cost;
Expand Down Expand Up @@ -173,41 +173,57 @@ public void Write(StreamWriter stream)
List<TechnoType> technoTypes, List<AITypeListEntry> groupTypes,
Logger logger)
{
int starti = 1;
int endi = section.Count - 1;
string name = section.GetOrDefault("Name", null);
string name = id;
int groupi = -1;
List<TaskForceEntry> units = new List<TaskForceEntry>();
TechnoType deftt = technoTypes[0] as TechnoType;

int groupi = int.Parse(section.GetOrDefault("Group", "-1"));
AITypeListEntry group = groupTypes.SingleOrDefault(g => g.Index == groupi);
if (group == null) group = groupTypes[0];

if (name == null)
{
starti = 0;
name = id;
}

if (!section.Contains("Group")) endi = section.Count;

for (int i = starti; i < endi; i++)
foreach(DictionaryEntry entry in section)
{
string[] split = (section[i] as string).Split(',');
uint count = uint.Parse(split[0] as string);
string unitid = split[1] as string;
TechnoType tt = technoTypes.SingleOrDefault(t => t.ID == unitid);
string currKey = entry.Key as string;
string currValue = entry.Value as string;

if (tt == null)
if (currKey == "Name")
{
logger.Add("TechnoType " + unitid + " referenced by Task Force " + id + " does not exist!");
tt = new TechnoType(unitid, unitid, 0, 0);
technoTypes.Add(tt);
name = currValue;
}
else if (currKey == "Group")
{
groupi = int.Parse(currValue);
}
else
{
string[] split = currValue.Split(',');

if (split.Length < 2)
{
logger.Add("Task Force [" + id + "] not in format: <Index>=<Unit Count>,<Unit Id>");
}
else
{
uint count = uint.Parse(split[0] as string);
string unitid = split[1] as string;
TechnoType tt = technoTypes.SingleOrDefault(t => t.ID == unitid);

if (tt == null)
{
logger.Add("TechnoType [" + unitid + "] referenced by Task Force [" + id + "] does not exist!");
tt = new TechnoType(unitid, unitid, 0, 0);
technoTypes.Add(tt);
}

if (int.Parse(currKey) > 5)
{
logger.Add("Task Force [" + id + "]: Game ignores unit entry index greater than 5.");
}

units.Add(new TaskForceEntry(tt, count));
}
}

units.Add(new TaskForceEntry(tt, count));
}

AITypeListEntry group = groupTypes.SingleOrDefault(g => g.Index == groupi);
if (group == null) group = groupTypes[0];

return new TaskForce(id, name, group, units);
}
}
Expand Down
6 changes: 3 additions & 3 deletions TechnoType.cs
Expand Up @@ -6,10 +6,10 @@ namespace AIEdit
public class TechnoType : IParamListEntry, IComparable<TechnoType>
{
private string name, owner, id;
private uint cost;
private int cost;
private uint tableIndex;

public TechnoType(string id, string name, uint cost, uint tableIndex)
public TechnoType(string id, string name, int cost, uint tableIndex)
{
this.id = id;
this.name = name;
Expand All @@ -21,7 +21,7 @@ public TechnoType(string id, string name, uint cost, uint tableIndex)
public string Name { get { return name; } set { name = value; } }
public string Owner { get { return owner; } set { owner = value; } }
public string ID { get { return id; } set { id = value; } }
public uint Cost { get { return cost; } set { cost = value; } }
public int Cost { get { return cost; } set { cost = value; } }
public uint TableIndex { get { return tableIndex; } }

public int CompareTo(TechnoType other)
Expand Down
4 changes: 2 additions & 2 deletions TriggerType.cs
Expand Up @@ -311,7 +311,7 @@ public void Write(StreamWriter stream)

if(split.Length < 18)
{
logger.Add("Trigger \"" + name + "\" cannot be parsed because it has an invalid number of parameters!");
logger.Add("Trigger [" + name + "] cannot be parsed because it has an invalid number of parameters!");
return null;
}

Expand Down Expand Up @@ -350,7 +350,7 @@ public void Write(StreamWriter stream)
value = option.FindByString(unitid);
if (value == null)
{
logger.Add("TechnoType " + split[5] + " referenced by Trigger " + id + " does not exist!");
logger.Add("TechnoType [" + split[5] + "] referenced by Trigger [" + id + "] does not exist!");
value = new TechnoType(unitid, unitid, 0, 0);
option.List.Add(value);
}
Expand Down
7 changes: 7 additions & 0 deletions config/ra2.ini
Expand Up @@ -9,6 +9,13 @@ Digest=pciAS/TnHWXQNmZa4GbC9emvP3M=
0=<all>
1=Allies
2=Soviets
3=<Side 3 Placeholder>
4=<Side 4 Placeholder>
5=<Side 5 Placeholder>
6=<Side 6 Placeholder>
7=<Side 7 Placeholder>
8=<Side 8 Placeholder>
9=<Side 9 Placeholder>

[TeamTypeOptions]
0=VeteranLevel,Veterancy,VETERANCY
Expand Down
7 changes: 7 additions & 0 deletions config/ts.ini
Expand Up @@ -9,6 +9,13 @@ Digest=aG6xg9lMqJoMyUqKRzv4QJZ2vmk=
0=<all>
1=GDI
2=Nod
3=<Side 3 Placeholder>
4=<Side 4 Placeholder>
5=<Side 5 Placeholder>
6=<Side 6 Placeholder>
7=<Side 7 Placeholder>
8=<Side 8 Placeholder>
9=<Side 9 Placeholder>

[TeamTypeOptions]
0=VeteranLevel,Veterancy,VETERANCY
Expand Down
9 changes: 9 additions & 0 deletions config/yr.ini
Expand Up @@ -10,6 +10,15 @@ Digest=m+F1aOs8y7FvcCJjyEsh2JEPw4I=
1=Allies
2=Soviets
3=Yuri
4=<Side 4 Placeholder>
5=<Side 5 Placeholder>
6=<Side 6 Placeholder>
7=<Side 7 Placeholder>
8=<Side 8 Placeholder>
9=<Side 9 Placeholder>
10=<Side 10 Placeholder>
11=<Side 11 Placeholder>
12=<Side 12 Placeholder>

[TeamTypeOptions]
0=VeteranLevel,Veterancy,VETERANCY
Expand Down
2 changes: 1 addition & 1 deletion frmMainNew.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frmMainNew.cs
Expand Up @@ -740,7 +740,7 @@ void LoadAI(string rulesfile, string aifile)

if(logger.Count > 0)
{
MessageBox.Show("Encountered " + logger.Count + " error(s) while loading. See the Error Log tab for details.");
MessageBox.Show("Possibly " + logger.Count + " error(s) while loading. See the Error Log tab for details.");
}
}

Expand Down

0 comments on commit 409d816

Please sign in to comment.