Engine:
authorsmxx
Mon, 12 Apr 2010 20:58:32 +0000
changeset 3337 75e7455c69ed
parent 3336 d7c1ffed1e15
child 3338 dee9beba85cc
Engine: * Moved "enum member to string" functions to uMisc * Print gear types in debug log instead of ordinals
hedgewars/uGears.pas
hedgewars/uMisc.pas
hedgewars/uScript.pas
--- a/hedgewars/uGears.pas	Sun Apr 11 09:53:28 2010 +0000
+++ b/hedgewars/uGears.pas	Mon Apr 12 20:58:32 2010 +0000
@@ -225,7 +225,7 @@
 begin
 inc(Counter);
 {$IFDEF DEBUGFILE}
-AddFileLog('AddGear: #' + inttostr(Counter) + ' (' + inttostr(x) + ',' + inttostr(y) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + inttostr(ord(Kind)));
+AddFileLog('AddGear: #' + inttostr(Counter) + ' (' + inttostr(x) + ',' + inttostr(y) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind));
 {$ENDIF}
 
 New(gear);
@@ -528,7 +528,7 @@
         RecountTeamHealth(team)
         end;
 {$IFDEF DEBUGFILE}
-with Gear^ do AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + inttostr(ord(Kind)));
+with Gear^ do AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind));
 {$ENDIF}
 
 if CurAmmoGear = Gear then CurAmmoGear:= nil;
--- a/hedgewars/uMisc.pas	Sun Apr 11 09:53:28 2010 +0000
+++ b/hedgewars/uMisc.pas	Mon Apr 12 20:58:32 2010 +0000
@@ -133,6 +133,9 @@
 procedure freeModule;
 procedure SplitBySpace(var a, b: shortstring);
 procedure SplitByChar(var a, b: ansistring; c: char);
+function EnumToStr(const en : TGearType) : shortstring; overload;
+function EnumToStr(const en : TSound) : shortstring; overload;
+function EnumToStr(const en : TAmmoType) : shortstring; overload;
 procedure movecursor(dx, dy: LongInt);
 function  hwSign(r: hwFloat): LongInt;
 function  Min(a, b: LongInt): LongInt;
@@ -167,7 +170,7 @@
 {$ENDIF}
 
 implementation
-uses Math, uConsole, uStore, uIO, uRandom, uSound;
+uses Math, uConsole, uStore, uIO, uRandom, uSound, typinfo;
 
 var KBnum: Longword;
 {$IFDEF DEBUGFILE}
@@ -199,6 +202,21 @@
     end else b:= '';
 end;
 
+function EnumToStr(const en : TGearType) : shortstring; overload;
+begin
+EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
+end;
+
+function EnumToStr(const en : TSound) : shortstring; overload;
+begin
+EnumToStr:= GetEnumName(TypeInfo(TSound), ord(en))
+end;
+
+function EnumToStr(const en : TAmmoType) : shortstring; overload;
+begin
+EnumToStr:= GetEnumName(TypeInfo(TAmmoType), ord(en))
+end;
+
 procedure movecursor(dx, dy: LongInt);
 var x, y: LongInt;
 begin
--- a/hedgewars/uScript.pas	Sun Apr 11 09:53:28 2010 +0000
+++ b/hedgewars/uScript.pas	Mon Apr 12 20:58:32 2010 +0000
@@ -50,8 +50,7 @@
     uAmmos,
     uSound,
     uTeams,
-    uKeys,
-    typinfo;
+    uKeys;
     
 var luaState : Plua_State;
     ScriptAmmoStore : shortstring;
@@ -715,23 +714,6 @@
     AddAmmoStore(ScriptAmmoStore);
 end;
 
-// small helper functions making registering enums a lot easier
-function str(const en : TGearType) : shortstring; overload;
-begin
-str:= GetEnumName(TypeInfo(TGearType), ord(en))
-end;
-
-function str(const en : TSound) : shortstring; overload;
-begin
-str:= GetEnumName(TypeInfo(TSound), ord(en))
-end;
-
-function str(const en : TAmmoType) : shortstring; overload;
-begin
-str:= GetEnumName(TypeInfo(TAmmoType), ord(en))
-end;
-///////////////////
-
 procedure initModule;
 var at : TGearType;
     am : TAmmoType;
@@ -773,15 +755,15 @@
 
 // register gear types
 for at:= Low(TGearType) to High(TGearType) do
-    ScriptSetInteger(str(at), ord(at));
+    ScriptSetInteger(EnumToStr(at), ord(at));
 
 // register sounds
 for st:= Low(TSound) to High(TSound) do
-    ScriptSetInteger(str(st), ord(st));
+    ScriptSetInteger(EnumToStr(st), ord(st));
 
 // register ammo types
 for am:= Low(TAmmoType) to High(TAmmoType) do
-    ScriptSetInteger(str(am), ord(am));
+    ScriptSetInteger(EnumToStr(am), ord(am));
     
 // register functions
 lua_register(luaState, 'AddGear', @lc_addgear);