diff --git a/src/cmdapp/GenieEngineApp.csproj b/src/cmdapp/GenieEngineApp.csproj
index da8f000..c09987b 100644
--- a/src/cmdapp/GenieEngineApp.csproj
+++ b/src/cmdapp/GenieEngineApp.csproj
@@ -32,19 +32,20 @@
+
+
-
@@ -65,11 +66,12 @@
+
+
..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll
-
diff --git a/src/cmdapp/src/AddBitmapCommand.cs b/src/cmdapp/src/AddBitmapCommand.cs
index a1d2669..c910fd9 100644
--- a/src/cmdapp/src/AddBitmapCommand.cs
+++ b/src/cmdapp/src/AddBitmapCommand.cs
@@ -1,12 +1,13 @@
using System.IO;
using System.Drawing;
+using System.Drawing.Imaging;
using AdrianKousz.Util;
namespace AdrianKousz.GenieEngine
{
- public class AddBitmapCommand : CmdApp.Command
+ public class AddBitmapCommand : BaseCommand
{
- override public void Run(string[] args)
+ override public void Run()
{
using (var input = File.OpenRead(args[0]))
using (var output = File.OpenWrite(args[1]))
@@ -22,11 +23,20 @@ namespace AdrianKousz.GenieEngine
GenieFile.Serialize(scn, output);
}
}
- public AddBitmapCommand()
+
+ override public int GetArgumentCount()
{
- MinArgumentCount = 3;
- Description = "Add a pregame bitmap";
- Help = "Add a pregame bitmap to a scenario."
+ return 3;
+ }
+
+ override public string GetDescription()
+ {
+ return "Add a pregame bitmap";
+ }
+
+ override public string GetHelp()
+ {
+ return "Add a pregame bitmap to a scenario."
+ "\nThe bitmap has to be indexed, otherwise, the game will probably crash."
+ "\nAdditionally, a game-specific palette will be used to display the image."
+ "\n"
diff --git a/src/cmdapp/src/BaseCommand.cs b/src/cmdapp/src/BaseCommand.cs
new file mode 100644
index 0000000..7976ded
--- /dev/null
+++ b/src/cmdapp/src/BaseCommand.cs
@@ -0,0 +1,36 @@
+using System;
+using AdrianKousz.Util;
+
+namespace AdrianKousz.GenieEngine
+{
+ public class BaseCommand : ICommand
+ {
+ protected string[] args;
+
+ virtual public string GetDescription()
+ {
+ return "(Empty description)";
+ }
+
+ virtual public string GetHelp()
+ {
+ return "(Empty help text)";
+ }
+
+ virtual public int GetArgumentCount()
+ {
+ return 1;
+ }
+
+ virtual public void SetArguments(string[] args)
+ {
+ this.args = args;
+ }
+
+ virtual public void Run()
+ {
+ foreach (var str in args)
+ Console.WriteLine(str);
+ }
+ }
+}
diff --git a/src/cmdapp/src/BitmapHelpers.cs b/src/cmdapp/src/BitmapHelpers.cs
index 0e6a026..f4dc23a 100644
--- a/src/cmdapp/src/BitmapHelpers.cs
+++ b/src/cmdapp/src/BitmapHelpers.cs
@@ -9,24 +9,25 @@ namespace AdrianKousz.GenieEngine
{
public static class BitmapHelpers
{
- public static unsafe void FillMap(Scenario scn, Bitmap bmp1, Bitmap bmp2)
+ public static unsafe void FillMap(Scenario scn, Bitmap bmp, Bitmap bmp2)
{
- using (var ubmp1 = new UnsafeBitmap(bmp1))
+ using (var ubmp = new UnsafeBitmap(bmp))
using (var ubmp2 = new UnsafeBitmap(bmp2))
{
var factory = new ScnDefaultFactory();
- EnsureValid(ubmp1, ubmp2);
+ Check(ubmp);
+ Check(ubmp2);
- var ptr1 = ubmp1.Scan0;
- var last1 = ptr1 + ubmp1.Stride * ubmp1.Height;
+ var ptr = ubmp.Scan0;
+ var last = ptr + ubmp.Stride * ubmp.Height;
var ptr2 = ubmp2.Scan0;
var last2 = ptr2 + ubmp2.Stride * ubmp2.Height;
var map = factory.MakeMap();
- map.SizeX = ubmp1.Width;
- map.SizeY = ubmp1.Height;
+ map.SizeX = ubmp.Width;
+ map.SizeY = ubmp.Height;
map.LinearTiles = new Scenario.ScnMap.Tile[map.SizeX * map.SizeY];
var gaiaunits = new List();
@@ -40,37 +41,26 @@ namespace AdrianKousz.GenieEngine
treemapping[20] = 349;
var i = 0;
- var id = 0;
- while (ptr1 < last1 && ptr2 < last2) {
- var treeid = treemapping[*ptr1];
+ while (ptr < last && ptr2 < last2) {
+ var treeid = treemapping[*ptr];
if (treeid != 0) {
var unit = factory.MakeUnit();
var posy = i / map.SizeX;
var posx = i - (posy * map.SizeX);
- unit.Id = id++;
unit.UnitId = treeid;
unit.PosX = posx + 0.5f;
unit.PosY = posy + 0.5f;
- unit.Rotation = unit.InitialFrame = (short)Util.Math.Rand(0, 14);
+ unit.Rotation = (short)Util.Math.Rand(0, 13);
gaiaunits.Add(unit);
}
- map.LinearTiles[i++] = new Scenario.ScnMap.Tile(*ptr1++, (byte)(*ptr2++ / 40), 0);
+ map.LinearTiles[i++] = new Scenario.ScnMap.Tile(*ptr++, (byte)(*ptr2++ / 37), 0);
}
- scn.NextId = id;
scn.Map = map;
scn.Units[0] = gaiaunits;
}
}
- private static void EnsureValid(UnsafeBitmap ubmp1, UnsafeBitmap ubmp2)
- {
- if (ubmp1.Width != ubmp2.Width || ubmp1.Height != ubmp2.Height)
- throw new ArgumentException("Bitmaps have unequal dimensions");
- Check(ubmp1);
- Check(ubmp2);
- }
-
private static void Check(UnsafeBitmap ubmp)
{
if (ubmp.PixelFormat != PixelFormat.Format8bppIndexed)
diff --git a/src/cmdapp/src/Bmp2MapCommand.cs b/src/cmdapp/src/Bmp2MapCommand.cs
index 42d94da..9946a28 100644
--- a/src/cmdapp/src/Bmp2MapCommand.cs
+++ b/src/cmdapp/src/Bmp2MapCommand.cs
@@ -1,12 +1,13 @@
-using System.IO;
+using System;
+using System.IO;
using System.Drawing;
using AdrianKousz.Util;
namespace AdrianKousz.GenieEngine
{
- public class Bmp2MapCommand : CmdApp.Command
+ public class Bmp2MapCommand : BaseCommand
{
- override public void Run(string[] args)
+ override public void Run()
{
using (var srcstream = File.OpenRead(args[0]))
using (var outstream = File.OpenWrite(args[1]))
@@ -22,16 +23,24 @@ namespace AdrianKousz.GenieEngine
}
}
- public Bmp2MapCommand()
+ override public int GetArgumentCount()
{
- MinArgumentCount = 4;
- Description = "Generate a scenario map based on bitmaps";
- Help = "Generate a scenario map based on bitmaps with automatic forest generation."
+ return 4;
+ }
+
+ override public string GetDescription()
+ {
+ return "Generate a scenario map based on bitmaps";
+ }
+
+ override public string GetHelp()
+ {
+ return "Generate a scenario map based on bitmaps with automatic forest generation."
+ "\n"
+ "\nTwo bitmaps need to be specified: One terrain map and one elevation map."
+ "\nBoth bitmaps need to be indexed or grayscale."
+ "\nThe index/gray values of the first bitmap are translated directly to a terrain ID."
- + "\nThe index/gray values of the second bitmap are divided by 40 to generate elevations 0-6."
+ + "\nThe index/gray values of the second bitmap are divided by 37 to generate elevations 0-6."
+ "\n"
+ "\nParameters:"
+ "\n