Engine:
authorsmxx
Wed, 10 Feb 2010 09:52:00 +0000
changeset 2790 83630d5f94db
parent 2789 2e16f732f8dc
child 2791 ac4b69e5f9f7
Engine: * Identify gears in Lua using their unique id instead of their pointer address - this should keep training from crashing on x64 platforms * Removed obsolete script call to "onTeamSetup" even before any script is loaded
hedgewars/hwengine.pas
hedgewars/uGears.pas
hedgewars/uScript.pas
share/hedgewars/Data/Missions/Bazooka Training.hwt
--- a/hedgewars/hwengine.pas	Wed Feb 10 02:03:41 2010 +0000
+++ b/hedgewars/hwengine.pas	Wed Feb 10 09:52:00 2010 +0000
@@ -288,8 +288,6 @@
 	    LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName);
         end;
 
-	ScriptCall('onTeamSetup');
-		
 	if recordFileName = '' then
 		SendIPCAndWaitReply('C')        // ask for game config
 	else
--- a/hedgewars/uGears.pas	Wed Feb 10 02:03:41 2010 +0000
+++ b/hedgewars/uGears.pas	Wed Feb 10 09:52:00 2010 +0000
@@ -84,6 +84,7 @@
 procedure FreeGearsList;
 procedure AddMiscGears;
 procedure AssignHHCoords;
+function GearByUID(uid : Longword) : PGear;
 procedure InsertGearToList(Gear: PGear);
 procedure RemoveGearFromList(Gear: PGear);
 function ModifyDamage(dmg: Longword; Gear: PGear): Longword;
@@ -2093,6 +2094,22 @@
    ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent)
 end;
 
+function GearByUID(uid : Longword) : PGear;
+var gear: PGear;
+begin
+GearByUID:= nil;
+gear:= GearsList;
+while gear <> nil do
+	begin
+	if gear^.uid = uid then
+		begin
+			GearByUID:= gear;
+			exit
+		end;
+	gear:= gear^.NextGear
+	end
+end;
+
 procedure init_uGears;
 begin
 	CurAmmoGear:= nil;
--- a/hedgewars/uScript.pas	Wed Feb 10 02:03:41 2010 +0000
+++ b/hedgewars/uScript.pas	Wed Feb 10 09:52:00 2010 +0000
@@ -125,12 +125,13 @@
 		t:= lua_tointeger(L, 7);
 
 		gear:= AddGear(x, y, gt, s, dx, dy, t);
-		lua_pushnumber(L, LongInt(gear))
+		lua_pushnumber(L, gear^.uid)
 		end;
 	lc_addgear:= 1; // 1 return value
 end;
 
 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
 begin
 	if lua_gettop(L) <> 1 then
 		begin
@@ -138,7 +139,11 @@
 		lua_pushnil(L); // return value on stack (nil)
 		end
 	else
-		lua_pushinteger(L, ord(PGear(lua_tointeger(L, 1))^.Kind));
+		begin
+		gear:= GearByUID(lua_tointeger(L, 1));
+		if gear <> nil then
+			lua_pushinteger(L, ord(gear^.Kind))
+		end;
 	lc_getgeartype:= 1
 end;
 
@@ -157,11 +162,12 @@
 		AddFileLog('LUA: Wrong number of parameters passed to FindPlace!')
 	else
 		begin
-		gear:= PGear(lua_tointeger(L, 1));
+		gear:= GearByUID(lua_tointeger(L, 1));
 		fall:= lua_toboolean(L, 2);
 		left:= lua_tointeger(L, 3);
 		right:= lua_tointeger(L, 4);
-		FindPlace(gear, fall, left, right)
+		if gear <> nil then
+			FindPlace(gear, fall, left, right)
 		end;
 	lc_findplace:= 0
 end;
@@ -219,9 +225,12 @@
 		end
 	else
 		begin
-		gear:= PGear(lua_tointeger(L, 1));
-		lua_pushinteger(L, hwRound(gear^.X));
-		lua_pushinteger(L, hwRound(gear^.Y))
+		gear:= GearByUID(lua_tointeger(L, 1));
+		if gear <> nil then
+			begin
+			lua_pushinteger(L, hwRound(gear^.X));
+			lua_pushinteger(L, hwRound(gear^.Y))
+			end
 		end;
 	lc_getgearposition:= 2;
 end;
@@ -234,11 +243,14 @@
 		AddFileLog('LUA: Wrong number of parameters passed to SetGearPosition!')
 	else
 		begin
-		gear:= PGear(lua_tointeger(L, 1));
-		x:= lua_tointeger(L, 2);
-		y:= lua_tointeger(L, 3);
-		gear^.X:= int2hwfloat(x);
-		gear^.Y:= int2hwfloat(y);
+		gear:= GearByUID(lua_tointeger(L, 1));
+		if gear <> nil then
+			begin
+			x:= lua_tointeger(L, 2);
+			y:= lua_tointeger(L, 3);
+			gear^.X:= int2hwfloat(x);
+			gear^.Y:= int2hwfloat(y);
+			end
 		end;
 	lc_setgearposition:= 0
 end;
--- a/share/hedgewars/Data/Missions/Bazooka Training.hwt	Wed Feb 10 02:03:41 2010 +0000
+++ b/share/hedgewars/Data/Missions/Bazooka Training.hwt	Wed Feb 10 09:52:00 2010 +0000
@@ -49,7 +49,7 @@
 	-- Things we don't modify here will use their default values.
 
 	-- The base number for the random number generator
-	Seed = 1337
+	Seed = 0
 	-- Game settings and rules
 	GameFlags = gfMultiWeapon + gfOneClanMode + gfSolidLand
 	-- The time the player has to move each round (in ms)