hedgewars/uScript.pas
changeset 3004 e9b3613cc3fb
parent 3003 0afdba08a858
child 3034 b576460ba8ad
equal deleted inserted replaced
3003:0afdba08a858 3004:e9b3613cc3fb
   192             lua_pushnil(L);
   192             lua_pushnil(L);
   193         end;
   193         end;
   194     lc_gethogname:= 1
   194     lc_gethogname:= 1
   195 end;
   195 end;
   196 
   196 
       
   197 function lc_getx(L : Plua_State) : LongInt; Cdecl;
       
   198 var gear : PGear;
       
   199 begin
       
   200     if lua_gettop(L) <> 1 then
       
   201         begin
       
   202         WriteLnToConsole('LUA: Wrong number of parameters passed to GetX!');
       
   203         lua_pushnil(L); // return value on stack (nil)
       
   204         end
       
   205     else
       
   206         begin
       
   207         gear:= GearByUID(lua_tointeger(L, 1));
       
   208         if gear <> nil then
       
   209             lua_pushnumber(L, hwRound(gear^.X))
       
   210         else
       
   211             lua_pushnil(L);
       
   212         end;
       
   213     lc_getx:= 1
       
   214 end;
       
   215 
       
   216 function lc_gety(L : Plua_State) : LongInt; Cdecl;
       
   217 var gear : PGear;
       
   218 begin
       
   219     if lua_gettop(L) <> 1 then
       
   220         begin
       
   221         WriteLnToConsole('LUA: Wrong number of parameters passed to GetY!');
       
   222         lua_pushnil(L); // return value on stack (nil)
       
   223         end
       
   224     else
       
   225         begin
       
   226         gear:= GearByUID(lua_tointeger(L, 1));
       
   227         if gear <> nil then
       
   228             lua_pushnumber(L, hwRound(gear^.Y))
       
   229         else
       
   230             lua_pushnil(L);
       
   231         end;
       
   232     lc_gety:= 1
       
   233 end;
       
   234 
       
   235 function lc_copypv(L : Plua_State) : LongInt; Cdecl;
       
   236 var gears, geard : PGear;
       
   237 begin
       
   238     if lua_gettop(L) <> 2 then
       
   239         begin
       
   240         WriteLnToConsole('LUA: Wrong number of parameters passed to CopyPV!');
       
   241         end
       
   242     else
       
   243         begin
       
   244         gears:= GearByUID(lua_tointeger(L, 1));
       
   245         geard:= GearByUID(lua_tointeger(L, 2));
       
   246         if (gears <> nil) and (geard <> nil) then
       
   247             begin
       
   248             geard^.X:= gears^.X;
       
   249             geard^.Y:= gears^.Y;
       
   250             geard^.dX:= gears^.dX;
       
   251             geard^.dY:= gears^.dY;
       
   252             end
       
   253         end;
       
   254     lc_copypv:= 1
       
   255 end;
       
   256 
       
   257 function lc_copypv2(L : Plua_State) : LongInt; Cdecl;
       
   258 var gears, geard : PGear;
       
   259 begin
       
   260     if lua_gettop(L) <> 2 then
       
   261         begin
       
   262         WriteLnToConsole('LUA: Wrong number of parameters passed to CopyPV2!');
       
   263         end
       
   264     else
       
   265         begin
       
   266         gears:= GearByUID(lua_tointeger(L, 1));
       
   267         geard:= GearByUID(lua_tointeger(L, 2));
       
   268         if (gears <> nil) and (geard <> nil) then
       
   269             begin
       
   270             geard^.X:= gears^.X;
       
   271             geard^.Y:= gears^.Y;
       
   272             geard^.dX:= gears^.dX * 2;
       
   273             geard^.dY:= gears^.dY * 2;
       
   274             end
       
   275         end;
       
   276     lc_copypv2:= 1
       
   277 end;
       
   278 
       
   279 function lc_followgear(L : Plua_State) : LongInt; Cdecl;
       
   280 var gear : PGear;
       
   281 begin
       
   282     if lua_gettop(L) <> 1 then
       
   283         WriteLnToConsole('LUA: Wrong number of parameters passed to FollowGear!')
       
   284     else
       
   285         begin
       
   286         gear:= GearByUID(lua_tointeger(L, 1));
       
   287         if gear <> nil then FollowGear:= gear
       
   288         end;
       
   289     lc_followgear:= 0
       
   290 end;
       
   291 
   197 function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
   292 function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
   198 var gear : PGear;
   293 var gear : PGear;
   199 begin
   294 begin
   200     if lua_gettop(L) <> 2 then
   295     if lua_gettop(L) <> 2 then
   201         begin
   296         begin
   202         WriteLnToConsole('LUA: Wrong number of parameters passed to SetHealth!');
   297         WriteLnToConsole('LUA: Wrong number of parameters passed to SetHealth!');
   203         end
   298         end
   204     else
   299     else
   205         begin
   300         begin
   206         gear:= GearByUID(lua_tointeger(L, 1));
   301         gear:= GearByUID(lua_tointeger(L, 1));
   207         if (gear <> nil) and (gear^.Kind = gtHedgehog) then gear^.Health:= lua_tointeger(L, 2)
   302         if gear <> nil then gear^.Health:= lua_tointeger(L, 2)
   208         end;
   303         end;
   209     lc_sethealth:= 0
   304     lc_sethealth:= 0
       
   305 end;
       
   306 
       
   307 function lc_setstate(L : Plua_State) : LongInt; Cdecl;
       
   308 var gear : PGear;
       
   309 begin
       
   310     if lua_gettop(L) <> 2 then
       
   311         begin
       
   312         WriteLnToConsole('LUA: Wrong number of parameters passed to SetState!');
       
   313         end
       
   314     else
       
   315         begin
       
   316         gear:= GearByUID(lua_tointeger(L, 1));
       
   317         if gear <> nil then gear^.State:= lua_tointeger(L, 2)
       
   318         end;
       
   319     lc_setstate:= 0
       
   320 end;
       
   321 
       
   322 function lc_getstate(L : Plua_State) : LongInt; Cdecl;
       
   323 var gear : PGear;
       
   324 begin
       
   325     if lua_gettop(L) <> 1 then
       
   326         begin
       
   327         WriteLnToConsole('LUA: Wrong number of parameters passed to GetState!');
       
   328         end
       
   329     else
       
   330         begin
       
   331         gear:= GearByUID(lua_tointeger(L, 1));
       
   332         if gear <> nil then
       
   333             lua_pushinteger(L, gear^.State)
       
   334         else
       
   335             lua_pushnil(L)
       
   336         end;
       
   337     lc_getstate:= 1
       
   338 end;
       
   339 
       
   340 function lc_settag(L : Plua_State) : LongInt; Cdecl;
       
   341 var gear : PGear;
       
   342 begin
       
   343     if lua_gettop(L) <> 2 then
       
   344         begin
       
   345         WriteLnToConsole('LUA: Wrong number of parameters passed to SetTag!');
       
   346         end
       
   347     else
       
   348         begin
       
   349         gear:= GearByUID(lua_tointeger(L, 1));
       
   350         if gear <> nil then gear^.Tag:= lua_tointeger(L, 2)
       
   351         end;
       
   352     lc_settag:= 0
   210 end;
   353 end;
   211 
   354 
   212 function lc_endgame(L : Plua_State) : LongInt; Cdecl;
   355 function lc_endgame(L : Plua_State) : LongInt; Cdecl;
   213 begin
   356 begin
   214     GameState:= gsExit;
   357     GameState:= gsExit;
   635 lua_register(luaState, 'AddTeam', @lc_addteam);
   778 lua_register(luaState, 'AddTeam', @lc_addteam);
   636 lua_register(luaState, 'AddHog', @lc_addhog);
   779 lua_register(luaState, 'AddHog', @lc_addhog);
   637 lua_register(luaState, 'SetHealth', @lc_sethealth);
   780 lua_register(luaState, 'SetHealth', @lc_sethealth);
   638 lua_register(luaState, 'GetHogClan', @lc_gethogclan);
   781 lua_register(luaState, 'GetHogClan', @lc_gethogclan);
   639 lua_register(luaState, 'GetHogName', @lc_gethogname);
   782 lua_register(luaState, 'GetHogName', @lc_gethogname);
       
   783 lua_register(luaState, 'GetX', @lc_getx);
       
   784 lua_register(luaState, 'GetY', @lc_gety);
       
   785 lua_register(luaState, 'CopyPV', @lc_copypv);
       
   786 lua_register(luaState, 'CopyPV2', @lc_copypv2);
       
   787 lua_register(luaState, 'FollowGear', @lc_followgear);
       
   788 lua_register(luaState, 'SetState', @lc_setstate);
       
   789 lua_register(luaState, 'GetState', @lc_getstate);
       
   790 lua_register(luaState, 'SetTag', @lc_settag);
       
   791 
   640 
   792 
   641 ScriptClearStack; // just to be sure stack is empty
   793 ScriptClearStack; // just to be sure stack is empty
   642 ScriptLoaded:= false;
   794 ScriptLoaded:= false;
   643 end;
   795 end;
   644 
   796