hedgewars/uScript.pas
changeset 2790 83630d5f94db
parent 2786 85f6425a4d74
child 2791 ac4b69e5f9f7
equal deleted inserted replaced
2789:2e16f732f8dc 2790:83630d5f94db
   123 		dx:= int2hwFloat(round(lua_tonumber(L, 5) * 1000)) / 1000;
   123 		dx:= int2hwFloat(round(lua_tonumber(L, 5) * 1000)) / 1000;
   124 		dy:= int2hwFloat(round(lua_tonumber(L, 6) * 1000)) / 1000;
   124 		dy:= int2hwFloat(round(lua_tonumber(L, 6) * 1000)) / 1000;
   125 		t:= lua_tointeger(L, 7);
   125 		t:= lua_tointeger(L, 7);
   126 
   126 
   127 		gear:= AddGear(x, y, gt, s, dx, dy, t);
   127 		gear:= AddGear(x, y, gt, s, dx, dy, t);
   128 		lua_pushnumber(L, LongInt(gear))
   128 		lua_pushnumber(L, gear^.uid)
   129 		end;
   129 		end;
   130 	lc_addgear:= 1; // 1 return value
   130 	lc_addgear:= 1; // 1 return value
   131 end;
   131 end;
   132 
   132 
   133 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
   133 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
       
   134 var gear : PGear;
   134 begin
   135 begin
   135 	if lua_gettop(L) <> 1 then
   136 	if lua_gettop(L) <> 1 then
   136 		begin
   137 		begin
   137 		AddFileLog('LUA: Wrong number of parameters passed to GetGearType!');
   138 		AddFileLog('LUA: Wrong number of parameters passed to GetGearType!');
   138 		lua_pushnil(L); // return value on stack (nil)
   139 		lua_pushnil(L); // return value on stack (nil)
   139 		end
   140 		end
   140 	else
   141 	else
   141 		lua_pushinteger(L, ord(PGear(lua_tointeger(L, 1))^.Kind));
   142 		begin
       
   143 		gear:= GearByUID(lua_tointeger(L, 1));
       
   144 		if gear <> nil then
       
   145 			lua_pushinteger(L, ord(gear^.Kind))
       
   146 		end;
   142 	lc_getgeartype:= 1
   147 	lc_getgeartype:= 1
   143 end;
   148 end;
   144 
   149 
   145 function lc_endgame(L : Plua_State) : LongInt; Cdecl;
   150 function lc_endgame(L : Plua_State) : LongInt; Cdecl;
   146 begin
   151 begin
   155 begin
   160 begin
   156 	if lua_gettop(L) <> 4 then
   161 	if lua_gettop(L) <> 4 then
   157 		AddFileLog('LUA: Wrong number of parameters passed to FindPlace!')
   162 		AddFileLog('LUA: Wrong number of parameters passed to FindPlace!')
   158 	else
   163 	else
   159 		begin
   164 		begin
   160 		gear:= PGear(lua_tointeger(L, 1));
   165 		gear:= GearByUID(lua_tointeger(L, 1));
   161 		fall:= lua_toboolean(L, 2);
   166 		fall:= lua_toboolean(L, 2);
   162 		left:= lua_tointeger(L, 3);
   167 		left:= lua_tointeger(L, 3);
   163 		right:= lua_tointeger(L, 4);
   168 		right:= lua_tointeger(L, 4);
   164 		FindPlace(gear, fall, left, right)
   169 		if gear <> nil then
       
   170 			FindPlace(gear, fall, left, right)
   165 		end;
   171 		end;
   166 	lc_findplace:= 0
   172 	lc_findplace:= 0
   167 end;
   173 end;
   168 
   174 
   169 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
   175 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
   217 		lua_pushnil(L);
   223 		lua_pushnil(L);
   218 		lua_pushnil(L)
   224 		lua_pushnil(L)
   219 		end
   225 		end
   220 	else
   226 	else
   221 		begin
   227 		begin
   222 		gear:= PGear(lua_tointeger(L, 1));
   228 		gear:= GearByUID(lua_tointeger(L, 1));
   223 		lua_pushinteger(L, hwRound(gear^.X));
   229 		if gear <> nil then
   224 		lua_pushinteger(L, hwRound(gear^.Y))
   230 			begin
       
   231 			lua_pushinteger(L, hwRound(gear^.X));
       
   232 			lua_pushinteger(L, hwRound(gear^.Y))
       
   233 			end
   225 		end;
   234 		end;
   226 	lc_getgearposition:= 2;
   235 	lc_getgearposition:= 2;
   227 end;
   236 end;
   228 
   237 
   229 function lc_setgearposition(L : Plua_State) : LongInt; Cdecl;
   238 function lc_setgearposition(L : Plua_State) : LongInt; Cdecl;
   232 begin
   241 begin
   233 	if lua_gettop(L) <> 3 then
   242 	if lua_gettop(L) <> 3 then
   234 		AddFileLog('LUA: Wrong number of parameters passed to SetGearPosition!')
   243 		AddFileLog('LUA: Wrong number of parameters passed to SetGearPosition!')
   235 	else
   244 	else
   236 		begin
   245 		begin
   237 		gear:= PGear(lua_tointeger(L, 1));
   246 		gear:= GearByUID(lua_tointeger(L, 1));
   238 		x:= lua_tointeger(L, 2);
   247 		if gear <> nil then
   239 		y:= lua_tointeger(L, 3);
   248 			begin
   240 		gear^.X:= int2hwfloat(x);
   249 			x:= lua_tointeger(L, 2);
   241 		gear^.Y:= int2hwfloat(y);
   250 			y:= lua_tointeger(L, 3);
       
   251 			gear^.X:= int2hwfloat(x);
       
   252 			gear^.Y:= int2hwfloat(y);
       
   253 			end
   242 		end;
   254 		end;
   243 	lc_setgearposition:= 0
   255 	lc_setgearposition:= 0
   244 end;
   256 end;
   245 
   257 
   246 function lc_setammo(L : Plua_State) : LongInt; Cdecl;
   258 function lc_setammo(L : Plua_State) : LongInt; Cdecl;