hedgewars/uScript.pas
changeset 7805 2a249a4faf5b
parent 7771 ce6d4dd0c780
child 7887 e987dff8e5f2
equal deleted inserted replaced
7804:9122461ae32b 7805:2a249a4faf5b
    44 function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
    44 function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
    45 function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
    45 function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
    46 function ScriptExists(fname : shortstring) : boolean;
    46 function ScriptExists(fname : shortstring) : boolean;
    47 
    47 
    48 
    48 
    49 function ParseCommandOverride(key, value : shortstring) : shortstring;
    49 //function ParseCommandOverride(key, value : shortstring) : shortstring;  This did not work out well
    50 
    50 
    51 procedure initModule;
    51 procedure initModule;
    52 procedure freeModule;
    52 procedure freeModule;
    53 
    53 
    54 implementation
    54 implementation
   194         t:= lua_tolstring(L,1,@c);
   194         t:= lua_tolstring(L,1,@c);
   195 
   195 
   196         for i:= 1 to c do s[i]:= t[i-1];
   196         for i:= 1 to c do s[i]:= t[i-1];
   197         s[0]:= char(c);
   197         s[0]:= char(c);
   198 
   198 
   199         ParseCommand(s, true);
   199         ParseCommand(s, true, true);
   200 
   200 
   201         end
   201         end
   202     else
   202     else
   203         LuaError('Lua: Wrong number of parameters passed to ParseCommand!');
   203         LuaError('Lua: Wrong number of parameters passed to ParseCommand!');
   204     lc_parsecommand:= 0;
   204     lc_parsecommand:= 0;
  1304         LuaError('Lua: Wrong number of parameters passed to AddTeam!');
  1304         LuaError('Lua: Wrong number of parameters passed to AddTeam!');
  1305         //lua_pushnil(L)
  1305         //lua_pushnil(L)
  1306         end
  1306         end
  1307     else
  1307     else
  1308         begin
  1308         begin
  1309         ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true);
  1309         ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true, true);
  1310         ParseCommand('grave ' + lua_tostring(L, 3), true);
  1310         ParseCommand('grave ' + lua_tostring(L, 3), true, true);
  1311         ParseCommand('fort ' + lua_tostring(L, 4), true);
  1311         ParseCommand('fort ' + lua_tostring(L, 4), true, true);
  1312         ParseCommand('voicepack ' + lua_tostring(L, 5), true);
  1312         ParseCommand('voicepack ' + lua_tostring(L, 5), true, true);
  1313         if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true);
  1313         if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true);
  1314         CurrentTeam^.Binds:= DefaultBinds
  1314         CurrentTeam^.Binds:= DefaultBinds
  1315         // fails on x64
  1315         // fails on x64
  1316         //lua_pushinteger(L, LongInt(CurrentTeam));
  1316         //lua_pushinteger(L, LongInt(CurrentTeam));
  1317         end;
  1317         end;
  1318     lc_addteam:= 0;//1;
  1318     lc_addteam:= 0;//1;
  1327         lua_pushnil(L)
  1327         lua_pushnil(L)
  1328         end
  1328         end
  1329     else
  1329     else
  1330         begin
  1330         begin
  1331         temp:= lua_tostring(L, 4);
  1331         temp:= lua_tostring(L, 4);
  1332         ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true);
  1332         ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
  1333         ParseCommand('hat ' + temp, true);
  1333         ParseCommand('hat ' + temp, true, true);
  1334         lua_pushinteger(L, CurrentHedgehog^.Gear^.uid);
  1334         lua_pushinteger(L, CurrentHedgehog^.Gear^.uid);
  1335         end;
  1335         end;
  1336     lc_addhog:= 1;
  1336     lc_addhog:= 1;
  1337 end;
  1337 end;
  1338 
  1338 
  1869 ScriptSetString('Goals', '');
  1869 ScriptSetString('Goals', '');
  1870 
  1870 
  1871 ScriptCall('onGameInit');
  1871 ScriptCall('onGameInit');
  1872 
  1872 
  1873 // pop game variables
  1873 // pop game variables
  1874 ParseCommand('seed ' + ScriptGetString('Seed'), true);
  1874 ParseCommand('seed ' + ScriptGetString('Seed'), true, true);
  1875 cTemplateFilter  := ScriptGetInteger('TemplateFilter');
  1875 cTemplateFilter  := ScriptGetInteger('TemplateFilter');
  1876 LuaTemplateNumber:= ScriptGetInteger('TemplateNumber');
  1876 LuaTemplateNumber:= ScriptGetInteger('TemplateNumber');
  1877 cMapGen          := ScriptGetInteger('MapGen');
  1877 cMapGen          := ScriptGetInteger('MapGen');
  1878 GameFlags        := ScriptGetInteger('GameFlags');
  1878 GameFlags        := ScriptGetInteger('GameFlags');
  1879 cHedgehogTurnTime:= ScriptGetInteger('TurnTime');
  1879 cHedgehogTurnTime:= ScriptGetInteger('TurnTime');
  1891 cSuddenDTurns    := ScriptGetInteger('SuddenDeathTurns');
  1891 cSuddenDTurns    := ScriptGetInteger('SuddenDeathTurns');
  1892 cWaterRise       := ScriptGetInteger('WaterRise');
  1892 cWaterRise       := ScriptGetInteger('WaterRise');
  1893 cHealthDecrease  := ScriptGetInteger('HealthDecrease');
  1893 cHealthDecrease  := ScriptGetInteger('HealthDecrease');
  1894 
  1894 
  1895 if cMapName <> ScriptGetString('Map') then
  1895 if cMapName <> ScriptGetString('Map') then
  1896     ParseCommand('map ' + ScriptGetString('Map'), true);
  1896     ParseCommand('map ' + ScriptGetString('Map'), true, true);
  1897 if ScriptGetString('Theme') <> '' then
  1897 if ScriptGetString('Theme') <> '' then
  1898     ParseCommand('theme ' + ScriptGetString('Theme'), true);
  1898     ParseCommand('theme ' + ScriptGetString('Theme'), true, true);
  1899 LuaGoals:= ScriptGetString('Goals');
  1899 LuaGoals:= ScriptGetString('Goals');
  1900 
  1900 
  1901 // Support lua changing the ammo layout - assume all hogs have same ammo, note this might leave a few ammo stores lying around.
  1901 // Support lua changing the ammo layout - assume all hogs have same ammo, note this might leave a few ammo stores lying around.
  1902 k:= 0;
  1902 k:= 0;
  1903 if (GameFlags and gfSharedAmmo) <> 0 then
  1903 if (GameFlags and gfSharedAmmo) <> 0 then
  2015     lua_pop(luaState, 1)
  2015     lua_pop(luaState, 1)
  2016     end;
  2016     end;
  2017 GetGlobals;
  2017 GetGlobals;
  2018 end;
  2018 end;
  2019 
  2019 
       
  2020 (*
  2020 function ParseCommandOverride(key, value : shortstring) : shortstring;
  2021 function ParseCommandOverride(key, value : shortstring) : shortstring;
  2021 begin
  2022 begin
  2022 ParseCommandOverride:= value;
  2023 ParseCommandOverride:= value;
  2023 if not ScriptExists('ParseCommandOverride') then
  2024 if not ScriptExists('ParseCommandOverride') then
  2024     exit;
  2025     exit;
  2034     begin
  2035     begin
  2035     ParseCommandOverride:= lua_tostring(luaState, -1);
  2036     ParseCommandOverride:= lua_tostring(luaState, -1);
  2036     lua_pop(luaState, 1)
  2037     lua_pop(luaState, 1)
  2037     end;
  2038     end;
  2038 end;
  2039 end;
       
  2040 *)
  2039 
  2041 
  2040 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
  2042 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
  2041 begin
  2043 begin
  2042 ScriptCall:= ScriptCall(fname, par1, 0, 0, 0)
  2044 ScriptCall:= ScriptCall(fname, par1, 0, 0, 0)
  2043 end;
  2045 end;
  2448 function ScriptExists(fname : shortstring) : boolean;
  2450 function ScriptExists(fname : shortstring) : boolean;
  2449 begin
  2451 begin
  2450     fname:= fname; // avoid hint
  2452     fname:= fname; // avoid hint
  2451     ScriptExists:= false
  2453     ScriptExists:= false
  2452 end;
  2454 end;
  2453 
  2455 (*
  2454 function ParseCommandOverride(key, value : shortstring) : shortstring;
  2456 function ParseCommandOverride(key, value : shortstring) : shortstring;
  2455 begin
  2457 begin
  2456     // avoid hints
  2458     // avoid hints
  2457     key:= key;
  2459     key:= key;
  2458     value:= value;
  2460     value:= value;
  2459     ParseCommandOverride:= ''
  2461     ParseCommandOverride:= ''
  2460 end;
  2462 end;
       
  2463 *)
  2461 
  2464 
  2462 procedure ScriptOnScreenResize;
  2465 procedure ScriptOnScreenResize;
  2463 begin
  2466 begin
  2464 end;
  2467 end;
  2465 
  2468