Skip to content

Commit

Permalink
Updated to version 2.0.3.9 with the fixes made by E1 Elite (thanks).
Browse files Browse the repository at this point in the history
  • Loading branch information
askeladdk committed Feb 3, 2019
1 parent 409d816 commit f540dfd
Show file tree
Hide file tree
Showing 16 changed files with 2,977 additions and 4,303 deletions.
3,090 changes: 0 additions & 3,090 deletions AI.htm

This file was deleted.

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.3")]
[assembly: AssemblyFileVersionAttribute("2.0.3.9")]
36 changes: 36 additions & 0 deletions README.md
Expand Up @@ -14,6 +14,42 @@ Link: https://github.com/askeladdk/aiedit

## Changelog ##

### v2.0.3.9 ###
- TS config file fix of veteran level and removed unused AITrigger condition choices
- Skipped across list duplicate ID check for AITrigger IDs as vanilla TS has such
- Added version number to application title text
- Updated the AIGuide for script action Attack TargetType (0,n)

### v2.0.3.8 ###
- Reverted back non-essential changes in the form designer file.

### v2.0.3.7 ###
- Fixed additional number of duplicate messages on reloading INI files.

### v2.0.3.6 ###
- Added AI Guide for offline reference.
- Removed the usage of [AIEdit] section for ID generation.
- Provided StartIndex, IDPrefix and IDSuffix fields in config file for customizing IDs.
- Config files updated for corrections and for ID related fields.
- Added duplicate ID check across lists in AI ini.
- Parsing exception message box will now close the application.

### v2.0.3.5 ###
- Avoid creating duplicate IDs even if [AIEdit] section is deleted from AI ini.

### v2.0.3.4 ###
- TeamType fields of Max/Priority/Techlevel now allows negative numbers.

### v2.0.3.3 ###
- Script action's parameters now allow negative numbers wherever needed.
- Script actions 53, 54 and 55 now has editable parameters for YR (config\yr.ini).

### v2.0.3.2 ###
- Added an error message with faulty ID before throwing an exception while parsing AI ini.

### v2.0.3.1 ###
- Application path is used to compute the full path of config files.

### v2.0.3 ###
- Changed the wording of the error log messages to be more consistent.
- Updated to ObjectListView 2.9.10.
Expand Down
112 changes: 81 additions & 31 deletions ScriptType.cs
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace AIEdit
{
Expand Down Expand Up @@ -40,6 +41,7 @@ public int CompareTo(object other)
public enum ScriptParamType
{
Number,
NumPlusMinus,
List,
TechnoType,
AIObject
Expand All @@ -52,8 +54,8 @@ public interface IActionType
string Description { get; }
IList List { get; }
ScriptParamType ParamType { get; }
string ParamToString(uint param);
IParamListEntry ParamEntry(uint param);
string ParamToString(int param);
IParamListEntry ParamEntry(int param);
}

public class ActionTypeNumber : IActionType, IComparable
Expand All @@ -67,12 +69,12 @@ public class ActionTypeNumber : IActionType, IComparable
public IList List { get { return null; } }
public ScriptParamType ParamType { get { return ScriptParamType.Number; } }

public string ParamToString(uint param)
public string ParamToString(int param)
{
return param.ToString();
}

public IParamListEntry ParamEntry(uint param)
public IParamListEntry ParamEntry(int param)
{
return null;
}
Expand All @@ -95,6 +97,45 @@ public int CompareTo(object other)
}
}

public class ActionTypeNumPlusMinus : IActionType, IComparable
{
private uint code;
private string name, desc;

public uint Code { get { return code; } }
public string Name { get { return name; } }
public string Description { get { return desc; } }
public IList List { get { return null; } }
public ScriptParamType ParamType { get { return ScriptParamType.NumPlusMinus; } }

public string ParamToString(int param)
{
return param.ToString();
}

public IParamListEntry ParamEntry(int param)
{
return null;
}

public ActionTypeNumPlusMinus(uint code, string name, string desc)
{
this.code = code;
this.name = name;
this.desc = desc;
}

public override string ToString()
{
return name;
}

public int CompareTo(object other)
{
return name.CompareTo((other as IActionType).Name);
}
}

public class ActionTypeList : IActionType, IComparable
{
private uint code;
Expand All @@ -108,16 +149,16 @@ public class ActionTypeList : IActionType, IComparable
public IList List { get { return list; } }
public ScriptParamType ParamType { get { return paramType; } }

public IParamListEntry ParamEntry(uint param)
public IParamListEntry ParamEntry(int param)
{
foreach (IParamListEntry entry in list)
{
if (entry.ParamListIndex == param) return entry;
if (entry.ParamListIndex == (uint)param) return entry;
}
return null;
}

public string ParamToString(uint param)
public string ParamToString(int param)
{
IParamListEntry entry = ParamEntry(param);
return entry != null ? entry.ToString() : "<error>";
Expand Down Expand Up @@ -148,10 +189,10 @@ public int CompareTo(object other)
/// </summary>
public class ScriptAction
{
private static uint[] offsets = { 0, 65536, 131072, 196608 };
private static int[] offsets = { 0, 65536, 131072, 196608 };
private static string[] offsetsDesc = { "Least Threat", "Most Threat", "Closest", "Farthest" };
private IActionType action;
private uint param, offset;
private int param, offset;

public IActionType Action
{
Expand All @@ -170,8 +211,8 @@ public IActionType Action
}
}

public uint Param { get { return param; } set { param = value; } }
public uint Offset { get { return offset; } set { offset = value; } }
public int Param { get { return param; } set { param = value; } }
public int Offset { get { return offset; } set { offset = value; } }

public string ParamString { get { return action.ParamToString(param); } }

Expand All @@ -192,7 +233,7 @@ public IParamListEntry ParamEntry
}
}

public ScriptAction(IActionType action, uint param)
public ScriptAction(IActionType action, int param)
{
this.action = action;
GetOffset(param, out this.param, out offset);
Expand All @@ -208,18 +249,18 @@ public ScriptAction(ScriptAction other)
public void Write(StreamWriter stream, int index)
{
uint a = action.Code;
uint p = param + offsets[offset];
int p = param + offsets[offset];
stream.WriteLine(index.ToString() + "=" + a.ToString() + "," + p.ToString());
}

private static void GetOffset(uint index, out uint param, out uint offset)
private static void GetOffset(int index, out int param, out int offset)
{
for (int i = offsets.Length - 1; i >= 0; i--)
{
if (index >= offsets[i])
{
param = index - offsets[i];
offset = (uint)i;
offset = i;
return;
}
}
Expand Down Expand Up @@ -337,31 +378,40 @@ public void Write(StreamWriter stream)
string name = id;
List<ScriptAction> actions = new List<ScriptAction>();

foreach(DictionaryEntry entry in section)
try
{
if ((entry.Key as string) == "Name")
{
name = entry.Value as string;
}
else
foreach(DictionaryEntry entry in section)
{
string[] split = (entry.Value as string).Split(',');

if (split.Length < 2)
if ((entry.Key as string) == "Name")
{
logger.Add("ScriptType " + id + ": Entry not in format: <Index>=<Action>,<Parameter>");
name = entry.Value as string;
}
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);
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]);
int p = int.Parse(split[1]);
IActionType actionType = types[a];

ScriptAction action = new ScriptAction(actionType, p);
actions.Add(action);
}
}
}
}
catch (Exception )
{
string msg = "Error occured at ScriptType: [" + id + "]" + "\nPlease verify its format. Application will now close.";
MessageBox.Show(msg, "Parse Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
Application.Exit();
}

return new ScriptType(id, name, actions);
}
Expand Down
69 changes: 39 additions & 30 deletions TaskForce.cs
Expand Up @@ -177,53 +177,62 @@ public void Write(StreamWriter stream)
int groupi = -1;
List<TaskForceEntry> units = new List<TaskForceEntry>();

foreach(DictionaryEntry entry in section)
try
{
string currKey = entry.Key as string;
string currValue = entry.Value as string;

if (currKey == "Name")
{
name = currValue;
}
else if (currKey == "Group")
foreach(DictionaryEntry entry in section)
{
groupi = int.Parse(currValue);
}
else
{
string[] split = currValue.Split(',');
string currKey = entry.Key as string;
string currValue = entry.Value as string;

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

if (tt == null)
if (split.Length < 2)
{
logger.Add("TechnoType [" + unitid + "] referenced by Task Force [" + id + "] does not exist!");
tt = new TechnoType(unitid, unitid, 0, 0);
technoTypes.Add(tt);
logger.Add("Task Force [" + id + "] not in format: <Index>=<Unit Count>,<Unit Id>");
}

if (int.Parse(currKey) > 5)
else
{
logger.Add("Task Force [" + id + "]: Game ignores unit entry index greater than 5.");
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));
}
}
}
catch (Exception )
{
string msg = "Error occured at TaskForce: [" + id + "]" + "\nPlease verify its format. Application will now close.";
MessageBox.Show(msg, "Parse Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
Application.Exit();
}

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

return new TaskForce(id, name, group, units);
}
}
Expand Down

0 comments on commit f540dfd

Please sign in to comment.