hedgewars/uScript.pas
branchhedgeroid
changeset 5385 a864a0aeed96
parent 5366 bfdd925e89a5
child 5410 8e7787065e2d
child 5489 f7ec6e5ad054
equal deleted inserted replaced
5383:cb217271f344 5385:a864a0aeed96
    41 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
    41 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
    42 function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt;
    42 function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt;
    43 function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
    43 function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
    44 function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
    44 function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
    45 function ScriptExists(fname : shortstring) : boolean;
    45 function ScriptExists(fname : shortstring) : boolean;
       
    46 function ParseCommandOverride(key, value : shortstring) : shortstring;
    46 
    47 
    47 procedure initModule;
    48 procedure initModule;
    48 procedure freeModule;
    49 procedure freeModule;
    49 
    50 
    50 implementation
    51 implementation
   224 end;
   225 end;
   225 
   226 
   226 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   227 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   227 var gear: PGear;
   228 var gear: PGear;
   228 begin
   229 begin
   229     if lua_gettop(L) <> 3 then begin
   230     if lua_gettop(L) <> 4 then begin
   230         LuaError('Lua: Wrong number of parameters passed to SpawnFakeHealthCrate!');
   231         LuaError('Lua: Wrong number of parameters passed to SpawnFakeHealthCrate!');
   231         lua_pushnil(L);
   232         lua_pushnil(L);
   232     end
   233     end
   233     else begin
   234     else begin
   234         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   235         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   235             HealthCrate, lua_toboolean(L, 3));
   236             HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   236         lua_pushinteger(L, gear^.uid);
   237         lua_pushinteger(L, gear^.uid);
   237     end;
   238     end;
   238     lc_spawnfakehealthcrate := 1;        
   239     lc_spawnfakehealthcrate := 1;        
   239 end;
   240 end;
   240 
   241 
   241 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
   242 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
   242 var gear: PGear;
   243 var gear: PGear;
   243 begin
   244 begin
   244     if lua_gettop(L) <> 3 then begin
   245     if lua_gettop(L) <> 4 then begin
   245         LuaError('Lua: Wrong number of parameters passed to SpawnFakeAmmoCrate!');
   246         LuaError('Lua: Wrong number of parameters passed to SpawnFakeAmmoCrate!');
   246         lua_pushnil(L);
   247         lua_pushnil(L);
   247     end
   248     end
   248     else begin
   249     else begin
   249         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   250         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   250             AmmoCrate, lua_toboolean(L, 3));
   251             AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   251         lua_pushinteger(L, gear^.uid);
   252         lua_pushinteger(L, gear^.uid);
   252     end;
   253     end;
   253     lc_spawnfakeammocrate := 1;
   254     lc_spawnfakeammocrate := 1;
   254 end;
   255 end;
   255 
   256 
   256 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
   257 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
   257 var gear: PGear;
   258 var gear: PGear;
   258 begin
   259 begin
   259     if lua_gettop(L) <> 3 then begin
   260     if lua_gettop(L) <> 4 then begin
   260         LuaError('Lua: Wrong number of parameters passed to SpawnFakeUtilityCrate!');
   261         LuaError('Lua: Wrong number of parameters passed to SpawnFakeUtilityCrate!');
   261         lua_pushnil(L);
   262         lua_pushnil(L);
   262     end
   263     end
   263     else begin  
   264     else begin  
   264         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   265         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   265             UtilityCrate, lua_toboolean(L, 3));
   266             UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   266         lua_pushinteger(L, gear^.uid);
   267         lua_pushinteger(L, gear^.uid);
   267     end;
   268     end;
   268     lc_spawnfakeutilitycrate := 1;
   269     lc_spawnfakeutilitycrate := 1;
   269 end;
   270 end;
   270 
   271 
  1303         begin
  1304         begin
  1304         cWindSpeed:= int2hwfloat(lua_tointeger(L, 1)) / 100 * cMaxWindSpeed;
  1305         cWindSpeed:= int2hwfloat(lua_tointeger(L, 1)) / 100 * cMaxWindSpeed;
  1305         cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
  1306         cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
  1306         if cWindSpeed.isNegative then
  1307         if cWindSpeed.isNegative then
  1307             CWindSpeedf := -cWindSpeedf;
  1308             CWindSpeedf := -cWindSpeedf;
  1308         AddGear(0, 0, gtATSmoothWindCh, 0, _0, _0, 1)^.Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed);
  1309         AddVisualGear(0, 0, vgtSmoothWindBar);
  1309         end;
  1310         end;
  1310     lc_setwind:= 0
  1311     lc_setwind:= 0
  1311 end;
  1312 end;
  1312 
  1313 
  1313 function lc_getdatapath(L : Plua_State) : LongInt; Cdecl;
  1314 function lc_getdatapath(L : Plua_State) : LongInt; Cdecl;
  1586     lua_pop(luaState, 1)
  1587     lua_pop(luaState, 1)
  1587     end;
  1588     end;
  1588 GetGlobals;
  1589 GetGlobals;
  1589 end;
  1590 end;
  1590 
  1591 
       
  1592 function ParseCommandOverride(key, value : shortstring) : shortstring;
       
  1593 begin
       
  1594 ParseCommandOverride:= value;
       
  1595 if not ScriptExists('ParseCommandOverride') then exit;
       
  1596 lua_getglobal(luaState, Str2PChar('ParseCommandOverride'));
       
  1597 lua_pushstring(luaState, Str2PChar(key));
       
  1598 lua_pushstring(luaState, Str2PChar(value));
       
  1599 if lua_pcall(luaState, 2, 1, 0) <> 0 then
       
  1600     begin
       
  1601     LuaError('Lua: Error while calling ParseCommandOverride: ' + lua_tostring(luaState, -1));
       
  1602     lua_pop(luaState, 1)
       
  1603     end
       
  1604 else
       
  1605     begin
       
  1606     ParseCommandOverride:= lua_tostring(luaState, -1);
       
  1607     lua_pop(luaState, 1)
       
  1608     end;
       
  1609 end;
       
  1610 
  1591 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
  1611 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
  1592 begin
  1612 begin
  1593 ScriptCall:= ScriptCall(fname, par1, 0, 0, 0)
  1613 ScriptCall:= ScriptCall(fname, par1, 0, 0, 0)
  1594 end;
  1614 end;
  1595 
  1615 
  1667 ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1];
  1687 ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1];
  1668 ScriptAmmoReinforcement[ord(ammo)]:= inttostr(reinforcement)[1];
  1688 ScriptAmmoReinforcement[ord(ammo)]:= inttostr(reinforcement)[1];
  1669 end;
  1689 end;
  1670 
  1690 
  1671 procedure ScriptApplyAmmoStore;
  1691 procedure ScriptApplyAmmoStore;
  1672 var i : LongInt;
  1692 var i, j : LongInt;
  1673 begin
  1693 begin
  1674 SetAmmoLoadout(ScriptAmmoLoadout);
  1694 SetAmmoLoadout(ScriptAmmoLoadout);
  1675 SetAmmoProbability(ScriptAmmoProbability);
  1695 SetAmmoProbability(ScriptAmmoProbability);
  1676 SetAmmoDelay(ScriptAmmoDelay);
  1696 SetAmmoDelay(ScriptAmmoDelay);
  1677 SetAmmoReinforcement(ScriptAmmoReinforcement);
  1697 SetAmmoReinforcement(ScriptAmmoReinforcement);
  1678 for i:= 0 to Pred(TeamsCount) do
  1698 
  1679     AddAmmoStore;
  1699 if (GameFlags and gfSharedAmmo) <> 0 then
       
  1700     for i:= 0 to Pred(ClansCount) do
       
  1701         AddAmmoStore
       
  1702 else if (GameFlags and gfPerHogAmmo) <> 0 then
       
  1703     for i:= 0 to Pred(TeamsCount) do
       
  1704         for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do
       
  1705             AddAmmoStore
       
  1706 else 
       
  1707     for i:= 0 to Pred(TeamsCount) do
       
  1708         AddAmmoStore
  1680 end;
  1709 end;
  1681 
  1710 
  1682 procedure initModule;
  1711 procedure initModule;
  1683 var at : TGearType;
  1712 var at : TGearType;
  1684     vgt: TVisualGearType;
  1713     vgt: TVisualGearType;