Description: port to D language version 2
  With this patch the code is accepted by gdc-4.6 0.29.1-4.6.4-3 without
  triggering deprecated feature warnings/errors.
Author: Barry deFreese <bdefreese@debian.org>
Author: Peter De Wachter <pdewacht@gmail.com>

--- a/src/abagames/util/Rand.d
+++ b/src/abagames/util/Rand.d
@@ -6,27 +6,30 @@
 module abagames.util.Rand;
 
 import std.random;
-import std.date;
+import std.datetime;
 
 /**
  * Random number generator.
  */
 public class Rand {
+  private Random rand;
   
   public this() {
-    d_time timer = getUTCtime();
-    rand_seed(timer, 0);   
+    rand.seed(unpredictableSeed);
   }
 
   public int nextInt(int n) {
-    return rand() % n;
+    rand.popFront();
+    return rand.front() % n;
   }
 
   public int nextSignedInt(int n) {
-    return rand() % (n * 2) - n;
+    rand.popFront();
+    return rand.front() % (n * 2) - n;
   }
 
   public float nextFloat(float n) {
-    return (cast(float)(rand() % (n * 10000))) / 10000;
+    rand.popFront();
+    return (cast(float)(rand.front() % (n * 10000))) / 10000;
   }
 }
--- a/src/abagames/util/sdl/Sound.d
+++ b/src/abagames/util/sdl/Sound.d
@@ -5,7 +5,8 @@
  */
 module abagames.util.sdl.Sound;
 
-import string = std.string;
+import std.conv;
+import std.string;
 import SDL;
 import SDL_mixer;
 import abagames.util.sdl.SDLInitFailedException;
@@ -18,8 +19,8 @@
  public:
   static bool noSound = false;
   static int fadeOutSpeed = 1280;
-  static char[] soundsDir = "/usr/share/games/a7xpg/sounds/";
-  static char[] chunksDir = "/usr/share/games/a7xpg/sounds/";
+  static string soundsDir = "/usr/share/games/a7xpg/sounds/";
+  static string chunksDir = "/usr/share/games/a7xpg/sounds/";
 
   public static void init() {
     if (noSound) return;
@@ -31,7 +32,7 @@
 
     if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
       noSound = 1;
-      derr.writeLine("Unable to initialize SDL audio: " ~ string.toString(SDL_GetError()));
+      derr.writeLine("Unable to initialize SDL audio: " ~ to!string(SDL_GetError()));
     }
 
     audio_rate = 44100;
@@ -40,7 +41,7 @@
     audio_buffers = 4096;
     if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
       noSound = 1;
-      derr.writeLine("Couldn't open audio: " ~ string.toString(SDL_GetError()));
+      derr.writeLine("Couldn't open audio: " ~ to!string(SDL_GetError()));
     }
     Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
   }
@@ -62,25 +63,25 @@
 
   // Load a sound or a chunk.
 
-  public void loadSound(char[] name) {
+  public void loadSound(string name) {
     if (noSound) return;
-    char[] fileName = soundsDir ~ name;
-    music = Mix_LoadMUS(string.toStringz(fileName));
+    string fileName = soundsDir ~ name;
+    music = Mix_LoadMUS(toStringz(fileName));
     if (!music) {
       noSound = true;
       throw new SDLInitFailedException("Couldn't load: " ~ fileName ~ 
-				       " (" ~ string.toString(Mix_GetError()) ~ ")");
+				       " (" ~ to!string(Mix_GetError()) ~ ")");
     }
   }
   
-  public void loadChunk(char[] name, int ch) {
+  public void loadChunk(string name, int ch) {
     if (noSound) return;
-    char[] fileName = chunksDir ~ name;
-    chunk = Mix_LoadWAV(string.toStringz(fileName));
+    string fileName = chunksDir ~ name;
+    chunk = Mix_LoadWAV(toStringz(fileName));
     if (!chunk) {
       noSound = true;
       throw new SDLInitFailedException("Couldn't load: " ~ fileName ~ 
-				       " (" ~ string.toString(Mix_GetError()) ~ ")");
+				       " (" ~ to!string(Mix_GetError()) ~ ")");
     }
     chunkChannel = ch;
   }
--- a/src/abagames/util/sdl/SDLInitFailedException.d
+++ b/src/abagames/util/sdl/SDLInitFailedException.d
@@ -9,7 +9,7 @@
  * SDL initialize failed.
  */
 public class SDLInitFailedException: Exception {
-  public this(char[] msg) {
+  public this(string msg) {
     super(msg);
   }
 }
--- a/src/abagames/a7xpg/A7xBoot.d
+++ b/src/abagames/a7xpg/A7xBoot.d
@@ -5,6 +5,7 @@
  */
 module abagames.a7xpg.A7xBoot;
 
+import std.conv;
 import std.string;
 import std.c.stdlib: exit, EXIT_SUCCESS, EXIT_FAILURE;
 import abagames.a7xpg.A7xScreen;
@@ -30,7 +31,7 @@
     ("Usage: a7xpg [-brightness [0-100]] [-luminous [0-100]] [-nosound] [-window] [-fullscreen] [-lowres]");
 }
 
-private void parseArgs(char[][] args) {
+private void parseArgs(string[] args) {
   for (int i = 1; i < args.length; i++) {
     switch (args[i]) {
     case "-brightness":
@@ -39,7 +40,7 @@
 	exit(EXIT_FAILURE);
       }
       i++;
-      float b = cast(float) atoi(args[i]) / 100;
+      float b = to!float(args[i]) / 100;
       if (b < 0 || b > 1) {
 	usage();
 	exit(EXIT_FAILURE);
@@ -52,7 +53,7 @@
 	exit(EXIT_FAILURE);
       }
       i++;
-      float l = cast(float) atoi(args[i]) / 100;
+      float l = to!float(args[i]) / 100;
       if (l < 0 || l > 1) {
 	usage();
 	exit(EXIT_FAILURE);
@@ -81,7 +82,7 @@
   }
 }
 
-public int main(char[][] args) {
+public int main(string[] args) {
   screen = new A7xScreen;
   input = new Input;
   try {
--- a/src/abagames/a7xpg/A7xGameManager.d
+++ b/src/abagames/a7xpg/A7xGameManager.d
@@ -126,18 +126,18 @@
     ship = new Ship;
     ship.init(input, field, this);
     Gold.createDisplayLists();
-    auto Gold goldClass = new Gold;
-    auto GoldInitializer gi = new GoldInitializer(ship, field, rand, this);
+    scope Gold goldClass = new Gold;
+    scope GoldInitializer gi = new GoldInitializer(ship, field, rand, this);
     golds = new LuminousActorPool(16, goldClass, gi);
     Enemy.createDisplayLists();
-    auto Enemy enemyClass = new Enemy;
-    auto EnemyInitializer ei = new EnemyInitializer(ship, field, rand, this);
+    scope Enemy enemyClass = new Enemy;
+    scope EnemyInitializer ei = new EnemyInitializer(ship, field, rand, this);
     enemies = new LuminousActorPool(ENEMY_MAX, enemyClass, ei);
-    auto Particle particleClass = new Particle;
-    auto ParticleInitializer pi = new ParticleInitializer(field, rand);
+    scope Particle particleClass = new Particle;
+    scope ParticleInitializer pi = new ParticleInitializer(field, rand);
     particles = new LuminousActorPool(256, particleClass, pi);
-    auto Bonus bonusClass = new Bonus;
-    auto BonusInitializer bi = new BonusInitializer();
+    scope Bonus bonusClass = new Bonus;
+    scope BonusInitializer bi = new BonusInitializer();
     bonuses = new ActorPool(8, bonusClass, bi);
     LetterRender.createDisplayLists();
     for (int i = 0; i < bgm.length; i++)
--- a/src/abagames/a7xpg/A7xPrefManager.d
+++ b/src/abagames/a7xpg/A7xPrefManager.d
@@ -8,6 +8,7 @@
 import std.stream;
 import std.c.stdlib;
 import std.string;
+import std.conv;
 import abagames.util.PrefManager;
 
 /**
@@ -16,22 +17,22 @@
 public class A7xPrefManager: PrefManager {
  public:
   static const int VERSION_NUM = 10;
-  static const char[] PREF_FILE = ".a7xpg.prf";
+  static const string PREF_FILE = ".a7xpg.prf";
   int hiScore;
 
   private void init() {
     hiScore = 0;
   }
 
-  public char[] pref_file() {
+  public string pref_file() {
     char * home = getenv("HOME");
     if (home is null)
       throw new Error("HOME environment variable is not defined");
-    return std.string.toString(home) ~ "/" ~ PREF_FILE;
+    return to!string(home) ~ "/" ~ PREF_FILE;
   }
 
-  public void load() {
-    auto File fd = new File;
+  public override void load() {
+    scope File fd = new File;
     try {
       int ver;
       fd.open(pref_file());
@@ -46,8 +47,8 @@
     }
   }
 
-  public void save() {
-    auto File fd = new File;
+  public override void save() {
+    scope File fd = new File;
     fd.create(pref_file());
     fd.write(VERSION_NUM);
     fd.write(hiScore);
--- a/src/abagames/a7xpg/A7xScreen.d
+++ b/src/abagames/a7xpg/A7xScreen.d
@@ -14,7 +14,7 @@
  */
 public class A7xScreen: Screen3D {
  public:
-  static const char[] CAPTION = "A7Xpg";
+  static const string CAPTION = "A7Xpg";
   static float brightness = 1;
   static float luminous = 0.5;
 
--- a/src/abagames/a7xpg/LetterRender.d
+++ b/src/abagames/a7xpg/LetterRender.d
@@ -31,7 +31,7 @@
     glPopMatrix();
   }
 
-  public static void drawString(char[] str, float lx, float y, float s) {
+  public static void drawString(string str, float lx, float y, float s) {
     float x = lx;
     int c;
     int idx;
--- a/src/abagames/util/ActorPool.d
+++ b/src/abagames/util/ActorPool.d
@@ -14,7 +14,7 @@
  public:
   Actor[] actor;
  protected:
-  int actorIdx;
+  ptrdiff_t actorIdx;
 
   public this(int n, Actor act, ActorInitializer ini) {
     actor = new Actor[n];
--- a/src/abagames/util/Logger.d
+++ b/src/abagames/util/Logger.d
@@ -11,11 +11,11 @@
  * Logger(error/info).
  */
 public class Logger {
-  public static void info(char[] msg) {
+  public static void info(string msg) {
     derr.writeLine("Info: " ~ msg);
   }
 
-  public static void error(char[] msg) {
+  public static void error(string msg) {
     //derr.writeLine("Error: " ~ msg);
     throw new Exception("Error: " ~ msg ~ "\0");
   }
--- a/src/abagames/util/sdl/Input.d
+++ b/src/abagames/util/sdl/Input.d
@@ -5,7 +5,8 @@
  */
 module abagames.util.sdl.Input;
 
-import string = std.string;
+import std.conv;
+import std.string;
 import SDL;
 import abagames.util.sdl.SDLInitFailedException;
 
@@ -30,7 +31,7 @@
   public void openJoystick() {
     if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) {
       throw new SDLInitFailedException(
-	"Unable to init SDL joystick: " ~ string.toString(SDL_GetError()));
+	"Unable to init SDL joystick: " ~ to!string(SDL_GetError()));
     }
     stick = SDL_JoystickOpen(0);
   }
--- a/src/abagames/util/sdl/MainLoop.d
+++ b/src/abagames/util/sdl/MainLoop.d
@@ -90,7 +90,7 @@
       frame = cast(int) (nowTick-prvTickCount) / interval;
       if (frame <= 0) {
 	frame = 1;
-	SDL_Delay(prvTickCount+interval-nowTick);
+	SDL_Delay(cast(uint) (prvTickCount+interval-nowTick));
 	if (accframe) {
 	  prvTickCount = SDL_GetTicks();
 	} else {
--- a/src/abagames/util/sdl/Screen3D.d
+++ b/src/abagames/util/sdl/Screen3D.d
@@ -5,7 +5,8 @@
  */
 module abagames.util.sdl.Screen3D;
 
-import string = std.string;
+import std.conv;
+import std.string;
 import std.c.stdlib;
 import SDL;
 import opengl;
@@ -31,7 +32,7 @@
   protected abstract void init();
   protected abstract void close();
 
-  public void initSDL() {
+  public override void initSDL() {
     if (lowres) {
       width /= 2;
       height /= 2;
@@ -39,7 +40,7 @@
     // Initialize SDL.
     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
       throw new SDLInitFailedException(
-	"Unable to initialize SDL: " ~ string.toString(SDL_GetError()));
+	"Unable to initialize SDL: " ~ to!string(SDL_GetError()));
     }
     // Create an OpenGL screen.
     if (windowMode) {
@@ -49,7 +50,7 @@
     } 
     if (SDL_SetVideoMode(width, height, 0, videoFlags) == null) {
       throw new SDLInitFailedException
-	("Unable to create SDL screen: " ~ string.toString(SDL_GetError()));
+	("Unable to create SDL screen: " ~ to!string(SDL_GetError()));
     }
     glViewport(0, 0, width, height);
     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@@ -63,7 +64,7 @@
   public void screenResized() {
     if (SDL_SetVideoMode(width, height, 0, videoFlags) == null) {
       throw new Exception
-        ("Unable to resize SDL screen: " ~ std.string.toString(SDL_GetError()));
+        ("Unable to resize SDL screen: " ~ to!string(SDL_GetError()));
     }
 
     glViewport(0, 0, width, height);
@@ -83,17 +84,17 @@
     screenResized();
   }
 
-  public void closeSDL() {
+  public override void closeSDL() {
     close();
     SDL_ShowCursor(SDL_ENABLE);
   }
 
-  public void flip() {
+  public override void flip() {
     handleError();
     SDL_GL_SwapBuffers();
   }
 
-  public void clear() {
+  public override void clear() {
     glClear(GL_COLOR_BUFFER_BIT);
   }
 
@@ -105,7 +106,7 @@
     exit(EXIT_FAILURE);
   }
 
-  protected void setCaption(char[] name) {
-    SDL_WM_SetCaption(string.toStringz(name), null);
+  protected void setCaption(string name) {
+    SDL_WM_SetCaption(toStringz(name), null);
   }
 }
--- a/src/abagames/util/sdl/Texture.d
+++ b/src/abagames/util/sdl/Texture.d
@@ -5,7 +5,7 @@
  */
 module abagames.util.sdl.Texture;
 
-import string = std.string;
+import std.string;
 import opengl;
 import SDL;
 import abagames.util.sdl.SDLInitFailedException;
@@ -15,15 +15,15 @@
  */
 public class Texture {
  public:
-  static char[] imagesDir = "/usr/share/games/a7xpg/images/";
+  static string imagesDir = "/usr/share/games/a7xpg/images/";
 
  private:
   GLuint num;
 
-  public this(char[] name) {
-    char[] fileName = imagesDir ~ name;
+  public this(string name) {
+    string fileName = imagesDir ~ name;
     SDL_Surface *surface;    
-    surface = SDL_LoadBMP(string.toStringz(fileName));
+    surface = SDL_LoadBMP(toStringz(fileName));
     if (!surface) {
       throw new SDLInitFailedException("Unable to load: " ~ fileName);
     }
