hedgewars/uScript.pas
changeset 11677 6a1170def888
parent 11617 aed348042a77
child 11678 b76b7372a2a6
equal deleted inserted replaced
11676:7180ddb4bf5b 11677:6a1170def888
   336         end
   336         end
   337     else
   337     else
   338         LuaToMapGenOrd:= i;
   338         LuaToMapGenOrd:= i;
   339 end;
   339 end;
   340 
   340 
   341 // wrapped calls //
   341 // wrapped calls
   342 
   342 
   343 // functions called from Lua:
   343 // functions called from Lua:
   344 // function(L : Plua_State) : LongInt; Cdecl;
   344 // function(L : Plua_State) : LongInt; Cdecl;
   345 // where L contains the state, returns the number of return values on the stack
   345 // where L contains the state, returns the number of return values on the stack
   346 // call CheckLuaParamCount or CheckAndFetchParamCount
   346 // call CheckLuaParamCount or CheckAndFetchParamCount
   488         with CurrentHedgehog^ do
   488         with CurrentHedgehog^ do
   489             begin
   489             begin
   490             cs:= 0; // current slot
   490             cs:= 0; // current slot
   491             fa:= 0; // first ammo item to check
   491             fa:= 0; // first ammo item to check
   492 
   492 
   493             // if something is selected, find it's successor
   493             // if something is selected, find it is successor
   494             if curAmmoType <> amNothing then
   494             if curAmmoType <> amNothing then
   495                 begin
   495                 begin
   496                 // get current slot index
   496                 // get current slot index
   497                 cs:= Ammoz[CurAmmoType].Slot;
   497                 cs:= Ammoz[CurAmmoType].Slot;
   498                 // find current ammo index
   498                 // find current ammo index
   499                 while (fa < cMaxSlotAmmoIndex)
   499                 while (fa < cMaxSlotAmmoIndex)
   500                     and (Ammo^[cs, fa].AmmoType <> CurAmmoType) do
   500                     and (Ammo^[cs, fa].AmmoType <> CurAmmoType) do
   501                         inc(fa);
   501                         inc(fa);
   502                 // increase once more because we won't successor
   502                 // increase once more because we will not successor
   503                 inc(fa);
   503                 inc(fa);
   504                 end;
   504                 end;
   505 
   505 
   506             // find first available ammo
   506             // find first available ammo
   507             // revisit current slot too (current item might not be first)
   507             // revisit current slot too (current item might not be first)
   911 //    else
   911 //    else
   912 //        lua_pushnil(L); // return value on stack (nil)
   912 //        lua_pushnil(L); // return value on stack (nil)
   913     lc_setvisualgearvalues:= 0
   913     lc_setvisualgearvalues:= 0
   914 end;
   914 end;
   915 
   915 
   916 // so. going to use this to get/set some of the more obscure gear values which weren't already exposed elsewhere
   916 // so. going to use this to get/set some of the more obscure gear values which were not already exposed elsewhere
   917 // can keep adding things in the future. isnoneornil makes it safe
   917 // can keep adding things in the future. isnoneornil makes it safe
   918 function lc_getgearvalues(L : Plua_State) : LongInt; Cdecl;
   918 function lc_getgearvalues(L : Plua_State) : LongInt; Cdecl;
   919 var gear: PGear;
   919 var gear: PGear;
   920 begin
   920 begin
   921     if CheckLuaParamCount(L, 1, 'GetGearValues', 'gearUid') then
   921     if CheckLuaParamCount(L, 1, 'GetGearValues', 'gearUid') then
  1224     hh   : THedgehog;
  1224     hh   : THedgehog;
  1225     i, j : LongInt;
  1225     i, j : LongInt;
  1226 begin
  1226 begin
  1227     if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then
  1227     if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then
  1228         begin
  1228         begin
  1229 	i:= lua_tointeger(L,1);
  1229         i:= lua_tointeger(L,1);
  1230 	if i >= ClansCount then exit(0);
  1230         if i >= ClansCount then exit(0);
  1231         clan := ClansArray[i];
  1231         clan := ClansArray[i];
  1232         clan^.Color:= lua_tointeger(L, 2) shr 8;
  1232         clan^.Color:= lua_tointeger(L, 2) shr 8;
  1233 
  1233 
  1234         for i:= 0 to Pred(clan^.TeamsNumber) do
  1234         for i:= 0 to Pred(clan^.TeamsNumber) do
  1235             begin
  1235             begin
  1246                 end;
  1246                 end;
  1247             FreeAndNilTexture(team^.NameTagTex);
  1247             FreeAndNilTexture(team^.NameTagTex);
  1248             team^.NameTagTex:= RenderStringTex(ansistring(clan^.Teams[i]^.TeamName), clan^.Color, fnt16);
  1248             team^.NameTagTex:= RenderStringTex(ansistring(clan^.Teams[i]^.TeamName), clan^.Color, fnt16);
  1249             end;
  1249             end;
  1250 
  1250 
  1251 	    FreeAndNilTexture(clan^.HealthTex);
  1251         FreeAndNilTexture(clan^.HealthTex);
  1252         clan^.HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, clan^.Teams[0]^.NameTagTex^.h, clan^.Color);
  1252         clan^.HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, clan^.Teams[0]^.NameTagTex^.h, clan^.Color);
  1253         end;
  1253         end;
  1254 
  1254 
  1255     lc_setclancolor:= 0
  1255     lc_setclancolor:= 0
  1256 end;
  1256 end;
  2285 begin
  2285 begin
  2286     placed:= false;
  2286     placed:= false;
  2287     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2287     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2288         begin
  2288         begin
  2289         if not lua_isnoneornil(L, 5) then
  2289         if not lua_isnoneornil(L, 5) then
  2290 	        tint := lua_tointeger(L, 5)
  2290             tint := lua_tointeger(L, 5)
  2291         else tint := $FFFFFFFF;
  2291         else tint := $FFFFFFFF;
  2292         if not lua_isnoneornil(L, 6) then
  2292         if not lua_isnoneornil(L, 6) then
  2293 	        behind := lua_toboolean(L, 6)
  2293             behind := lua_toboolean(L, 6)
  2294         else behind := false;
  2294         else behind := false;
  2295         if not lua_isnoneornil(L, 7) then
  2295         if not lua_isnoneornil(L, 7) then
  2296 	        flipHoriz := lua_toboolean(L, 7)
  2296             flipHoriz := lua_toboolean(L, 7)
  2297         else flipHoriz := false;
  2297         else flipHoriz := false;
  2298         if not lua_isnoneornil(L, 8) then
  2298         if not lua_isnoneornil(L, 8) then
  2299 	        flipVert := lua_toboolean(L, 8)
  2299             flipVert := lua_toboolean(L, 8)
  2300         else flipVert := false;
  2300         else flipVert := false;
  2301         lf:= 0;
  2301         lf:= 0;
  2302 
  2302 
  2303         // accept any amount of landflags, loop is never executed if n<9
  2303         // accept any amount of landflags, loop is never executed if n<9
  2304         for i:= 9 to n do
  2304         for i:= 9 to n do
  2332     params = 'x, y, sprite, frameIdx, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert, [, landFlag, ... ]';
  2332     params = 'x, y, sprite, frameIdx, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert, [, landFlag, ... ]';
  2333 begin
  2333 begin
  2334     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2334     if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then
  2335         begin
  2335         begin
  2336         if not lua_isnoneornil(L, 5) then
  2336         if not lua_isnoneornil(L, 5) then
  2337 	        eraseOnLFMatch := lua_toboolean(L, 5)
  2337             eraseOnLFMatch := lua_toboolean(L, 5)
  2338         else eraseOnLFMatch := false;
  2338         else eraseOnLFMatch := false;
  2339         if not lua_isnoneornil(L, 6) then
  2339         if not lua_isnoneornil(L, 6) then
  2340 	        onlyEraseLF := lua_toboolean(L, 6)
  2340             onlyEraseLF := lua_toboolean(L, 6)
  2341         else onlyEraseLF := false;
  2341         else onlyEraseLF := false;
  2342         if not lua_isnoneornil(L, 7) then
  2342         if not lua_isnoneornil(L, 7) then
  2343 	        flipHoriz := lua_toboolean(L, 7)
  2343             flipHoriz := lua_toboolean(L, 7)
  2344         else flipHoriz := false;
  2344         else flipHoriz := false;
  2345         if not lua_isnoneornil(L, 8) then
  2345         if not lua_isnoneornil(L, 8) then
  2346 	        flipVert := lua_toboolean(L, 8)
  2346             flipVert := lua_toboolean(L, 8)
  2347         else flipVert := false;
  2347         else flipVert := false;
  2348         lf:= 0;
  2348         lf:= 0;
  2349 
  2349 
  2350         // accept any amount of landflags, loop is never executed if n<9
  2350         // accept any amount of landflags, loop is never executed if n<9
  2351         for i:= 9 to n do
  2351         for i:= 9 to n do
  2867 ScriptSetInteger('GameTime', GameTicks);
  2867 ScriptSetInteger('GameTime', GameTicks);
  2868 ScriptSetInteger('TotalRounds', TotalRounds);
  2868 ScriptSetInteger('TotalRounds', TotalRounds);
  2869 ScriptSetInteger('WaterLine', cWaterLine);
  2869 ScriptSetInteger('WaterLine', cWaterLine);
  2870 if isCursorVisible and (not bShowAmmoMenu) then
  2870 if isCursorVisible and (not bShowAmmoMenu) then
  2871     begin
  2871     begin
  2872     if (prevCursorPoint.X <> CursorPoint.X) or 
  2872     if (prevCursorPoint.X <> CursorPoint.X) or
  2873        (prevCursorPoint.Y <> CursorPoint.Y) then
  2873        (prevCursorPoint.Y <> CursorPoint.Y) then
  2874         begin
  2874         begin
  2875         ScriptSetInteger('CursorX', CursorPoint.X - WorldDx);
  2875         ScriptSetInteger('CursorX', CursorPoint.X - WorldDx);
  2876         ScriptSetInteger('CursorY', cScreenHeight - CursorPoint.Y- WorldDy);
  2876         ScriptSetInteger('CursorY', cScreenHeight - CursorPoint.Y- WorldDy);
  2877         prevCursorPoint.X:= CursorPoint.X;
  2877         prevCursorPoint.X:= CursorPoint.X;
  3026 ScriptAmmoReinforcement[ord(ammo)]:= inttostr(reinforcement)[1];
  3026 ScriptAmmoReinforcement[ord(ammo)]:= inttostr(reinforcement)[1];
  3027 end;
  3027 end;
  3028 
  3028 
  3029 procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte);
  3029 procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte);
  3030 begin
  3030 begin
  3031 // change loadout string if ammo store hasn't been initialized yet
  3031 // change loadout string if ammo store has not been initialized yet
  3032 if (StoreCnt = 0) then
  3032 if (StoreCnt = 0) then
  3033 begin
  3033 begin
  3034     if (delay <= 9) then
  3034     if (delay <= 9) then
  3035         ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1];
  3035         ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1];
  3036 end
  3036 end
  3037 // change "live" delay values
  3037 // change 'live' delay values
  3038 else if (CurrentTeam <> nil) then
  3038 else if (CurrentTeam <> nil) then
  3039         ammoz[ammo].SkipTurns:= CurrentTeam^.Clan^.TurnNumber + delay;
  3039         ammoz[ammo].SkipTurns:= CurrentTeam^.Clan^.TurnNumber + delay;
  3040 end;
  3040 end;
  3041 
  3041 
  3042 procedure ScriptApplyAmmoStore;
  3042 procedure ScriptApplyAmmoStore;