hedgewars/uScript.pas
branchwebgl
changeset 9950 2759212a27de
parent 9521 8054d9d775fd
parent 9917 1ca194a8b509
child 9952 32f5982604f4
equal deleted inserted replaced
9521:8054d9d775fd 9950:2759212a27de
    78     uDebug,
    78     uDebug,
    79     uCollisions,
    79     uCollisions,
    80     uRenderUtils,
    80     uRenderUtils,
    81     uTextures,
    81     uTextures,
    82     uLandGraphics,
    82     uLandGraphics,
    83     SDLh,
       
    84     SysUtils,
    83     SysUtils,
    85     uIO,
    84     uIO,
    86     uVisualGearsList,
    85     uVisualGearsList,
    87     uGearsHandlersMess,
    86     uGearsHandlersMess,
    88     uPhysFSLayer,
    87     uPhysFSLayer,
    97     ScriptAmmoLoadout : shortstring;
    96     ScriptAmmoLoadout : shortstring;
    98     ScriptAmmoProbability : shortstring;
    97     ScriptAmmoProbability : shortstring;
    99     ScriptAmmoDelay : shortstring;
    98     ScriptAmmoDelay : shortstring;
   100     ScriptAmmoReinforcement : shortstring;
    99     ScriptAmmoReinforcement : shortstring;
   101     ScriptLoaded : boolean;
   100     ScriptLoaded : boolean;
       
   101     mapDims : boolean;
   102 
   102 
   103 procedure ScriptPrepareAmmoStore; forward;
   103 procedure ScriptPrepareAmmoStore; forward;
   104 procedure ScriptApplyAmmoStore; forward;
   104 procedure ScriptApplyAmmoStore; forward;
   105 procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay, reinforcement: Byte); forward;
   105 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward;
       
   106 procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward;
   106 
   107 
   107 procedure LuaError(s: shortstring);
   108 procedure LuaError(s: shortstring);
   108 begin
   109 begin
   109     WriteLnToConsole(s);
   110     WriteLnToConsole(s);
   110     AddChatString(#5 + s);
   111     AddChatString(#5 + s);
       
   112 end;
       
   113 
       
   114 procedure LuaParameterCountError(call, paramsyntax: shortstring; wrongcount: LongInt);
       
   115 begin
       
   116     // TODO: i18n?
       
   117     LuaError('Lua: Wrong number of parameters (' + inttostr(wrongcount) + ') passed to ' + call + '!     syntax: ' + call + ' ( ' + paramsyntax + ' )');
   111 end;
   118 end;
   112 
   119 
   113 // wrapped calls //
   120 // wrapped calls //
   114 
   121 
   115 // functions called from Lua:
   122 // functions called from Lua:
   119 
   126 
   120 function lc_band(L: PLua_State): LongInt; Cdecl;
   127 function lc_band(L: PLua_State): LongInt; Cdecl;
   121 begin
   128 begin
   122     if lua_gettop(L) <> 2 then
   129     if lua_gettop(L) <> 2 then
   123         begin
   130         begin
   124         LuaError('Lua: Wrong number of parameters passed to band!');
   131         LuaParameterCountError('band', 'value1, value2', lua_gettop(L));
   125         lua_pushnil(L);
   132         lua_pushnil(L);
   126         end
   133         end
   127     else
   134     else
   128         lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1));
   135         lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1));
   129     lc_band := 1;
   136     lc_band := 1;
   131 
   138 
   132 function lc_bor(L: PLua_State): LongInt; Cdecl;
   139 function lc_bor(L: PLua_State): LongInt; Cdecl;
   133 begin
   140 begin
   134     if lua_gettop(L) <> 2 then
   141     if lua_gettop(L) <> 2 then
   135         begin
   142         begin
   136         LuaError('Lua: Wrong number of parameters passed to bor!');
   143         LuaParameterCountError('bor', 'value1, value2', lua_gettop(L));
   137         lua_pushnil(L);
   144         lua_pushnil(L);
   138         end
   145         end
   139     else
   146     else
   140         lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1));
   147         lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1));
   141     lc_bor := 1;
   148     lc_bor := 1;
   143 
   150 
   144 function lc_bnot(L: PLua_State): LongInt; Cdecl;
   151 function lc_bnot(L: PLua_State): LongInt; Cdecl;
   145 begin
   152 begin
   146     if lua_gettop(L) <> 1 then
   153     if lua_gettop(L) <> 1 then
   147         begin
   154         begin
   148         LuaError('Lua: Wrong number of parameters passed to bnot!');
   155         LuaParameterCountError('bnot', 'value', lua_gettop(L));
   149         lua_pushnil(L);
   156         lua_pushnil(L);
   150         end
   157         end
   151     else
   158     else
   152         lua_pushinteger(L, (not lua_tointeger(L, 1)));
   159         lua_pushinteger(L, (not lua_tointeger(L, 1)));
   153     lc_bnot := 1;
   160     lc_bnot := 1;
   155 
   162 
   156 function lc_div(L: PLua_State): LongInt; Cdecl;
   163 function lc_div(L: PLua_State): LongInt; Cdecl;
   157 begin
   164 begin
   158     if lua_gettop(L) <> 2 then
   165     if lua_gettop(L) <> 2 then
   159         begin
   166         begin
   160         LuaError('Lua: Wrong number of parameters passed to div!');
   167         LuaParameterCountError('div', 'dividend, divisor', lua_gettop(L));
   161         lua_pushnil(L);
   168         lua_pushnil(L);
   162         end
   169         end
   163     else
   170     else
   164         lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2));
   171         lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2));
   165     lc_div := 1;
   172     lc_div := 1;
   166 end;
   173 end;
   167 
   174 
   168 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl;
   175 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl;
   169 begin
   176 begin
   170     if lua_gettop(L) <> 0 then
   177     if lua_gettop(L) <> 0 then
   171         LuaError('Lua: Wrong number of parameters passed to GetInputMask!')
   178         LuaParameterCountError('GetInputMask', '', lua_gettop(L))
   172     else
   179     else
   173         lua_pushinteger(L, InputMask);
   180         lua_pushinteger(L, InputMask);
   174     lc_getinputmask:= 1
   181     lc_getinputmask:= 1
   175 end;
   182 end;
   176 
   183 
   177 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl;
   184 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl;
   178 begin
   185 begin
   179     if lua_gettop(L) <> 1 then
   186     if lua_gettop(L) <> 1 then
   180         LuaError('Lua: Wrong number of parameters passed to SetInputMask!')
   187         LuaParameterCountError('SetInputMask', 'mask', lua_gettop(L))
   181     else
   188     else
   182         InputMask:= lua_tointeger(L, 1);
   189         InputMask:= lua_tointeger(L, 1);
   183     lc_setinputmask:= 0
   190     lc_setinputmask:= 0
   184 end;
   191 end;
   185 
   192 
   188     if lua_gettop(L) = 1 then
   195     if lua_gettop(L) = 1 then
   189         begin
   196         begin
   190         WriteLnToConsole('Lua: ' + lua_tostring(L ,1));
   197         WriteLnToConsole('Lua: ' + lua_tostring(L ,1));
   191         end
   198         end
   192     else
   199     else
   193         LuaError('Lua: Wrong number of parameters passed to WriteLnToConsole!');
   200         LuaParameterCountError('WriteLnToConsole', 'string', lua_gettop(L));
   194     lc_writelntoconsole:= 0;
   201     lc_writelntoconsole:= 0;
   195 end;
   202 end;
   196 
   203 
   197 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
   204 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
   198 var t: PChar;
   205 var t: PChar;
   208 
   215 
   209         ParseCommand(s, true, true);
   216         ParseCommand(s, true, true);
   210 
   217 
   211         end
   218         end
   212     else
   219     else
   213         LuaError('Lua: Wrong number of parameters passed to ParseCommand!');
   220         LuaParameterCountError('ParseCommand', 'string', lua_gettop(L));
   214     lc_parsecommand:= 0;
   221     lc_parsecommand:= 0;
   215 end;
   222 end;
   216 
   223 
   217 function lc_showmission(L : Plua_State) : LongInt; Cdecl;
   224 function lc_showmission(L : Plua_State) : LongInt; Cdecl;
   218 begin
   225 begin
   219     if lua_gettop(L) = 5 then
   226     if lua_gettop(L) = 5 then
   220         begin
   227         begin
   221         ShowMission(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   228         ShowMission(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   222         end
   229         end
   223     else
   230     else
   224         LuaError('Lua: Wrong number of parameters passed to ShowMission!');
   231         LuaParameterCountError('ShowMission', 'caption, subcaption, text, icon, time', lua_gettop(L));
   225     lc_showmission:= 0;
   232     lc_showmission:= 0;
   226 end;
   233 end;
   227 
   234 
   228 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   235 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   229 begin
   236 begin
   266     else if lua_gettop(L) = 3 then
   273     else if lua_gettop(L) = 3 then
   267         begin
   274         begin
   268         AddCaption(lua_tostring(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(lua_tointeger(L, 3)));
   275         AddCaption(lua_tostring(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(lua_tointeger(L, 3)));
   269         end
   276         end
   270     else
   277     else
   271         LuaError('Lua: Wrong number of parameters passed to AddCaption!');
   278         LuaParameterCountError('AddCaption', 'text[, color, captiongroup]', lua_gettop(L));
   272     lc_addcaption:= 0;
   279     lc_addcaption:= 0;
   273 end;
   280 end;
   274 
   281 
   275 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl;
   282 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl;
   276 begin
   283 begin
   277     if lua_gettop(L) = 1 then
   284     if lua_gettop(L) = 1 then
   278         begin
   285         begin
   279         // to be done
   286         // to be done
   280         end
   287         end
   281     else
   288     else
   282         LuaError('Lua: Wrong number of parameters passed to CampaignLock!');
   289         LuaParameterCountError('CampaignLock', 'TODO', lua_gettop(L));
   283     lc_campaignlock:= 0;
   290     lc_campaignlock:= 0;
   284 end;
   291 end;
   285 
   292 
   286 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl;
   293 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl;
   287 begin
   294 begin
   288     if lua_gettop(L) = 1 then
   295     if lua_gettop(L) = 1 then
   289         begin
   296         begin
   290         // to be done
   297         // to be done
   291         end
   298         end
   292     else
   299     else
   293         LuaError('Lua: Wrong number of parameters passed to CampaignUnlock!');
   300         LuaParameterCountError('CampaignUnlock', 'TODO', lua_gettop(L));
   294     lc_campaignunlock:= 0;
   301     lc_campaignunlock:= 0;
   295 end;
   302 end;
   296 
   303 
   297 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   304 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
   298 var gear: PGear;
   305 var gear: PGear;
   299 begin
   306 begin
   300     if lua_gettop(L) <> 4 then
   307     if lua_gettop(L) <> 4 then
   301         begin
   308         begin
   302         LuaError('Lua: Wrong number of parameters passed to SpawnFakeHealthCrate!');
   309         LuaParameterCountError('SpawnFakeHealthCrate', 'x, y, explode, poison', lua_gettop(L));
   303         lua_pushnil(L);
   310         lua_pushnil(L);
   304         end
   311         end
   305     else
   312     else
   306         begin
   313         begin
   307         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   314         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   314 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
   321 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
   315 var gear: PGear;
   322 var gear: PGear;
   316 begin
   323 begin
   317     if lua_gettop(L) <> 4 then
   324     if lua_gettop(L) <> 4 then
   318         begin
   325         begin
   319         LuaError('Lua: Wrong number of parameters passed to SpawnFakeAmmoCrate!');
   326         LuaParameterCountError('SpawnFakeAmmoCrate', 'x, y, explode, poison', lua_gettop(L));
   320         lua_pushnil(L);
   327         lua_pushnil(L);
   321         end
   328         end
   322     else
   329     else
   323         begin
   330         begin
   324         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   331         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   331 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
   338 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
   332 var gear: PGear;
   339 var gear: PGear;
   333 begin
   340 begin
   334     if lua_gettop(L) <> 4 then
   341     if lua_gettop(L) <> 4 then
   335         begin
   342         begin
   336         LuaError('Lua: Wrong number of parameters passed to SpawnFakeUtilityCrate!');
   343         LuaParameterCountError('SpawnFakeUtilityCrate', 'x, y, explode, poison', lua_gettop(L));
   337         lua_pushnil(L);
   344         lua_pushnil(L);
   338         end
   345         end
   339     else
   346     else
   340         begin
   347         begin
   341         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   348         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   349 var gear: PGear;
   356 var gear: PGear;
   350 var health: LongInt;
   357 var health: LongInt;
   351 begin
   358 begin
   352     if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then
   359     if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then
   353         begin
   360         begin
   354         LuaError('Lua: Wrong number of parameters passed to SpawnHealthCrate!');
   361         LuaParameterCountError('SpawnHealthCrate', 'x, y[, health]', lua_gettop(L));
   355         lua_pushnil(L);
   362         lua_pushnil(L);
   356         end
   363         end
   357     else
   364     else
   358         begin
   365         begin
   359         if lua_gettop(L) = 3 then
   366         if lua_gettop(L) = 3 then
   372 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl;
   379 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl;
   373 var gear: PGear;
   380 var gear: PGear;
   374 begin
   381 begin
   375     if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then
   382     if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then
   376         begin
   383         begin
   377         LuaError('Lua: Wrong number of parameters passed to SpawnAmmoCrate!');
   384         LuaParameterCountError('SpawnAmmoCrate', 'x, y, content[, amount]', lua_gettop(L));
   378         lua_pushnil(L);
   385         lua_pushnil(L);
   379         end
   386         end
   380     else
   387     else
   381         begin
   388         begin
   382         if (lua_gettop(L) = 3) then
   389         if (lua_gettop(L) = 3) then
   393 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl;
   400 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl;
   394 var gear: PGear;
   401 var gear: PGear;
   395 begin
   402 begin
   396     if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then
   403     if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then
   397         begin
   404         begin
   398         LuaError('Lua: Wrong number of parameters passed to SpawnUtilityCrate!');
   405         LuaParameterCountError('SpawnUtilityCrate', 'x, y, content[, amount]', lua_gettop(L));
   399         lua_pushnil(L);
   406         lua_pushnil(L);
   400         end
   407         end
   401     else
   408     else
   402         begin
   409         begin
   403         if (lua_gettop(L) = 3) then
   410         if (lua_gettop(L) = 3) then
   417     dx, dy: hwFloat;
   424     dx, dy: hwFloat;
   418     gt: TGearType;
   425     gt: TGearType;
   419 begin
   426 begin
   420     if lua_gettop(L) <> 7 then
   427     if lua_gettop(L) <> 7 then
   421         begin
   428         begin
   422         LuaError('Lua: Wrong number of parameters passed to AddGear!');
   429         LuaParameterCountError('AddGear', 'x, y, gearType, state, dx, dy, timer', lua_gettop(L));
   423         lua_pushnil(L); // return value on stack (nil)
   430         lua_pushnil(L); // return value on stack (nil)
   424         end
   431         end
   425     else
   432     else
   426         begin
   433         begin
   427         x:= lua_tointeger(L, 1);
   434         x:= lua_tointeger(L, 1);
   442 function lc_deletegear(L : Plua_State) : LongInt; Cdecl;
   449 function lc_deletegear(L : Plua_State) : LongInt; Cdecl;
   443 var gear : PGear;
   450 var gear : PGear;
   444 begin
   451 begin
   445     if lua_gettop(L) <> 1 then
   452     if lua_gettop(L) <> 1 then
   446         begin
   453         begin
   447         LuaError('Lua: Wrong number of parameters passed to DeleteGear!');
   454         LuaParameterCountError('DeleteGear', 'gearUid', lua_gettop(L));
   448         end
   455         end
   449     else
   456     else
   450         begin
   457         begin
   451         gear:= GearByUID(lua_tointeger(L, 1));
   458         gear:= GearByUID(lua_tointeger(L, 1));
   452         if gear <> nil then
   459         if gear <> nil then
   461     c: Boolean;
   468     c: Boolean;
   462     vgt: TVisualGearType;
   469     vgt: TVisualGearType;
   463 begin
   470 begin
   464     if lua_gettop(L) <> 5 then
   471     if lua_gettop(L) <> 5 then
   465         begin
   472         begin
   466         LuaError('Lua: Wrong number of parameters passed to AddVisualGear!');
   473         LuaParameterCountError('AddVisualGear', 'x, y, visualGearType, state, critical', lua_gettop(L));
   467         lua_pushnil(L); // return value on stack (nil)
   474         lua_pushnil(L); // return value on stack (nil)
   468         end
   475         end
   469     else
   476     else
   470         begin
   477         begin
   471         x:= lua_tointeger(L, 1);
   478         x:= lua_tointeger(L, 1);
   489 function lc_deletevisualgear(L : Plua_State) : LongInt; Cdecl;
   496 function lc_deletevisualgear(L : Plua_State) : LongInt; Cdecl;
   490 var vg : PVisualGear;
   497 var vg : PVisualGear;
   491 begin
   498 begin
   492     if lua_gettop(L) <> 1 then
   499     if lua_gettop(L) <> 1 then
   493         begin
   500         begin
   494         LuaError('Lua: Wrong number of parameters passed to DeleteVisualGear!');
   501         LuaParameterCountError('DeleteVisualGear', 'vgUid', lua_gettop(L));
   495         end
   502         end
   496     else
   503     else
   497         begin
   504         begin
   498         vg:= VisualGearByUID(lua_tointeger(L, 1));
   505         vg:= VisualGearByUID(lua_tointeger(L, 1));
   499         if vg <> nil then
   506         if vg <> nil then
   505 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
   512 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
   506 var vg: PVisualGear;
   513 var vg: PVisualGear;
   507 begin
   514 begin
   508     if lua_gettop(L) <> 1 then
   515     if lua_gettop(L) <> 1 then
   509         begin
   516         begin
   510         LuaError('Lua: Wrong number of parameters passed to GetVisualGearValues!');
   517         LuaParameterCountError('GetVisualGearValues', 'vgUid', lua_gettop(L));
   511         lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   518         lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   512         lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L)
   519         lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L)
   513         end
   520         end
   514     else
   521     else
   515         begin
   522         begin
   539 function lc_setvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
   546 function lc_setvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
   540 var vg : PVisualGear;
   547 var vg : PVisualGear;
   541 begin
   548 begin
   542     if lua_gettop(L) <> 11 then
   549     if lua_gettop(L) <> 11 then
   543         begin
   550         begin
   544         LuaError('Lua: Wrong number of parameters passed to SetVisualGearValues!');
   551         LuaParameterCountError('SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint', lua_gettop(L));
   545         lua_pushnil(L); // return value on stack (nil)
   552         lua_pushnil(L); // return value on stack (nil)
   546         end
   553         end
   547     else
   554     else
   548         begin
   555         begin
   549         vg:= VisualGearByUID(lua_tointeger(L, 1));
   556         vg:= VisualGearByUID(lua_tointeger(L, 1));
   567 
   574 
   568 function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl;
   575 function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl;
   569 begin
   576 begin
   570     if lua_gettop(L) <> 0 then
   577     if lua_gettop(L) <> 0 then
   571         begin
   578         begin
   572         LuaError('Lua: Wrong number of parameters passed to GetFollowGear!');
   579         LuaParameterCountError('GetFollowGear', '', lua_gettop(L));
   573         lua_pushnil(L); // return value on stack (nil)
   580         lua_pushnil(L); // return value on stack (nil)
   574         end
   581         end
   575     else
   582     else
   576         if FollowGear = nil then
   583         if FollowGear = nil then
   577             lua_pushnil(L)
   584             lua_pushnil(L)
   583 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
   590 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
   584 var gear : PGear;
   591 var gear : PGear;
   585 begin
   592 begin
   586     if lua_gettop(L) <> 1 then
   593     if lua_gettop(L) <> 1 then
   587         begin
   594         begin
   588         LuaError('Lua: Wrong number of parameters passed to GetGearType!');
   595         LuaParameterCountError('GetGearType', 'gearUid', lua_gettop(L));
   589         lua_pushnil(L); // return value on stack (nil)
   596         lua_pushnil(L); // return value on stack (nil)
   590         end
   597         end
   591     else
   598     else
   592         begin
   599         begin
   593         gear:= GearByUID(lua_tointeger(L, 1));
   600         gear:= GearByUID(lua_tointeger(L, 1));
   602 function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl;
   609 function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl;
   603 var gear : PGear;
   610 var gear : PGear;
   604 begin
   611 begin
   605     if lua_gettop(L) <> 1 then
   612     if lua_gettop(L) <> 1 then
   606         begin
   613         begin
   607         LuaError('Lua: Wrong number of parameters passed to GetGearMessage!');
   614         LuaParameterCountError('GetGearMessage', 'gearUid', lua_gettop(L));
   608         lua_pushnil(L); // return value on stack (nil)
   615         lua_pushnil(L); // return value on stack (nil)
   609         end
   616         end
   610     else
   617     else
   611         begin
   618         begin
   612         gear:= GearByUID(lua_tointeger(L, 1));
   619         gear:= GearByUID(lua_tointeger(L, 1));
   621 function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl;
   628 function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl;
   622 var gear : PGear;
   629 var gear : PGear;
   623 begin
   630 begin
   624     if lua_gettop(L) <> 1 then
   631     if lua_gettop(L) <> 1 then
   625         begin
   632         begin
   626         LuaError('Lua: Wrong number of parameters passed to GetGearElasticity!');
   633         LuaParameterCountError('GetGearElasticity', 'gearUid', lua_gettop(L));
   627         lua_pushnil(L); // return value on stack (nil)
   634         lua_pushnil(L); // return value on stack (nil)
   628         end
   635         end
   629     else
   636     else
   630         begin
   637         begin
   631         gear:= GearByUID(lua_tointeger(L, 1));
   638         gear:= GearByUID(lua_tointeger(L, 1));
   639 
   646 
   640 function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl;
   647 function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl;
   641 var gear : PGear;
   648 var gear : PGear;
   642 begin
   649 begin
   643     if lua_gettop(L) <> 2 then
   650     if lua_gettop(L) <> 2 then
   644         LuaError('Lua: Wrong number of parameters passed to SetGearMessage!')
   651         LuaParameterCountError('SetGearMessage', 'gearUid, message', lua_gettop(L))
   645     else
   652     else
   646         begin
   653         begin
   647         gear:= GearByUID(lua_tointeger(L, 1));
   654         gear:= GearByUID(lua_tointeger(L, 1));
   648         if gear <> nil then
   655         if gear <> nil then
   649             gear^.message:= lua_tointeger(L, 2);
   656             gear^.message:= lua_tointeger(L, 2);
   654 function lc_getgearpos(L : Plua_State) : LongInt; Cdecl;
   661 function lc_getgearpos(L : Plua_State) : LongInt; Cdecl;
   655 var gear : PGear;
   662 var gear : PGear;
   656 begin
   663 begin
   657     if lua_gettop(L) <> 1 then
   664     if lua_gettop(L) <> 1 then
   658         begin
   665         begin
   659         LuaError('Lua: Wrong number of parameters passed to GetGearPos!');
   666         LuaParameterCountError('GetGearPos', 'gearUid', lua_gettop(L));
   660         lua_pushnil(L); // return value on stack (nil)
   667         lua_pushnil(L); // return value on stack (nil)
   661         end
   668         end
   662     else
   669     else
   663         begin
   670         begin
   664         gear:= GearByUID(lua_tointeger(L, 1));
   671         gear:= GearByUID(lua_tointeger(L, 1));
   672 
   679 
   673 function lc_setgearpos(L : Plua_State) : LongInt; Cdecl;
   680 function lc_setgearpos(L : Plua_State) : LongInt; Cdecl;
   674 var gear : PGear;
   681 var gear : PGear;
   675 begin
   682 begin
   676     if lua_gettop(L) <> 2 then
   683     if lua_gettop(L) <> 2 then
   677         LuaError('Lua: Wrong number of parameters passed to SetGearPos!')
   684         LuaParameterCountError('SetGearPos', 'gearUid, value', lua_gettop(L))
   678     else
   685     else
   679         begin
   686         begin
   680         gear:= GearByUID(lua_tointeger(L, 1));
   687         gear:= GearByUID(lua_tointeger(L, 1));
   681         if gear <> nil then
   688         if gear <> nil then
   682             gear^.Pos:= lua_tointeger(L, 2);
   689             gear^.Pos:= lua_tointeger(L, 2);
   687 function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
   694 function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
   688 var gear : PGear;
   695 var gear : PGear;
   689 begin
   696 begin
   690     if lua_gettop(L) <> 1 then
   697     if lua_gettop(L) <> 1 then
   691         begin
   698         begin
   692         LuaError('Lua: Wrong number of parameters passed to GetGearCollisionMask!');
   699         LuaParameterCountError('GetGearCollisionMask', 'gearUid', lua_gettop(L));
   693         lua_pushnil(L); // return value on stack (nil)
   700         lua_pushnil(L); // return value on stack (nil)
   694         end
   701         end
   695     else
   702     else
   696         begin
   703         begin
   697         gear:= GearByUID(lua_tointeger(L, 1));
   704         gear:= GearByUID(lua_tointeger(L, 1));
   705 
   712 
   706 function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
   713 function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
   707 var gear : PGear;
   714 var gear : PGear;
   708 begin
   715 begin
   709     if lua_gettop(L) <> 2 then
   716     if lua_gettop(L) <> 2 then
   710         LuaError('Lua: Wrong number of parameters passed to SetGearCollisionMask!')
   717         LuaParameterCountError('SetGearCollisionMask', 'gearUid, mask', lua_gettop(L))
   711     else
   718     else
   712         begin
   719         begin
   713         gear:= GearByUID(lua_tointeger(L, 1));
   720         gear:= GearByUID(lua_tointeger(L, 1));
   714         if gear <> nil then
   721         if gear <> nil then
   715             gear^.CollisionMask:= lua_tointeger(L, 2);
   722             gear^.CollisionMask:= lua_tointeger(L, 2);
   719 
   726 
   720 function lc_gethoglevel(L : Plua_State): LongInt; Cdecl;
   727 function lc_gethoglevel(L : Plua_State): LongInt; Cdecl;
   721 var gear : PGear;
   728 var gear : PGear;
   722 begin
   729 begin
   723     if lua_gettop(L) <> 1 then
   730     if lua_gettop(L) <> 1 then
   724         LuaError('Lua: Wrong number of parameters passed to GetHogLevel!')
   731         LuaParameterCountError('GetHogLevel', 'gearUid', lua_gettop(L))
   725     else
   732     else
   726         begin
   733         begin
   727         gear := GearByUID(lua_tointeger(L, 1));
   734         gear := GearByUID(lua_tointeger(L, 1));
   728         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
   735         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
   729             lua_pushinteger(L, gear^.Hedgehog^.BotLevel)
   736             lua_pushinteger(L, gear^.Hedgehog^.BotLevel)
   735 
   742 
   736 function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl;
   743 function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl;
   737 var gear : PGear;
   744 var gear : PGear;
   738 begin
   745 begin
   739     if lua_gettop(L) <> 2 then
   746     if lua_gettop(L) <> 2 then
   740         LuaError('Lua: Wrong number of parameters passed to SetHogLevel!')
   747         LuaParameterCountError('SetHogLevel', 'gearUid, level', lua_gettop(L))
   741     else
   748     else
   742         begin
   749         begin
   743         gear:= GearByUID(lua_tointeger(L, 1));
   750         gear:= GearByUID(lua_tointeger(L, 1));
   744         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
   751         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
   745             gear^.Hedgehog^.BotLevel:= lua_tointeger(L, 2);
   752             gear^.Hedgehog^.BotLevel:= lua_tointeger(L, 2);
   750 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl;
   757 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl;
   751 var gear : PGear;
   758 var gear : PGear;
   752 begin
   759 begin
   753     if lua_gettop(L) <> 1 then
   760     if lua_gettop(L) <> 1 then
   754         begin
   761         begin
   755         LuaError('Lua: Wrong number of parameters passed to GetHogClan!');
   762         LuaParameterCountError('GetHogClan', 'gearUid', lua_gettop(L));
   756         lua_pushnil(L); // return value on stack (nil)
   763         lua_pushnil(L); // return value on stack (nil)
   757         end
   764         end
   758     else
   765     else
   759         begin
   766         begin
   760         gear:= GearByUID(lua_tointeger(L, 1));
   767         gear:= GearByUID(lua_tointeger(L, 1));
   770 
   777 
   771 function lc_getclancolor(L : Plua_State) : LongInt; Cdecl;
   778 function lc_getclancolor(L : Plua_State) : LongInt; Cdecl;
   772 begin
   779 begin
   773     if lua_gettop(L) <> 1 then
   780     if lua_gettop(L) <> 1 then
   774         begin
   781         begin
   775         LuaError('Lua: Wrong number of parameters passed to GetClanColor!');
   782         LuaParameterCountError('GetClanColor', 'clan', lua_gettop(L));
   776         lua_pushnil(L); // return value on stack (nil)
   783         lua_pushnil(L); // return value on stack (nil)
   777         end
   784         end
   778     else lua_pushinteger(L, ClansArray[lua_tointeger(L, 1)]^.Color shl 8 or $FF);
   785     else lua_pushinteger(L, ClansArray[lua_tointeger(L, 1)]^.Color shl 8 or $FF);
   779     lc_getclancolor:= 1
   786     lc_getclancolor:= 1
   780 end;
   787 end;
   782 function lc_setclancolor(L : Plua_State) : LongInt; Cdecl;
   789 function lc_setclancolor(L : Plua_State) : LongInt; Cdecl;
   783 var clan : PClan;
   790 var clan : PClan;
   784     team : PTeam;
   791     team : PTeam;
   785     hh   : THedgehog;
   792     hh   : THedgehog;
   786     i, j : LongInt;
   793     i, j : LongInt;
   787     r, rr: TSDL_Rect;
       
   788     texsurf: PSDL_Surface;
       
   789 begin
   794 begin
   790     if lua_gettop(L) <> 2 then
   795     if lua_gettop(L) <> 2 then
   791         LuaError('Lua: Wrong number of parameters passed to SetClanColor!')
   796         LuaParameterCountError('SetClanColor', 'clan, color', lua_gettop(L))
   792     else
   797     else
   793         begin
   798         begin
   794         clan := ClansArray[lua_tointeger(L, 1)];
   799         clan := ClansArray[lua_tointeger(L, 1)];
   795         clan^.Color:= lua_tointeger(L, 2) shr 8;
   800         clan^.Color:= lua_tointeger(L, 2) shr 8;
       
   801 
   796         for i:= 0 to Pred(clan^.TeamsNumber) do
   802         for i:= 0 to Pred(clan^.TeamsNumber) do
   797             begin
   803             begin
   798             team:= clan^.Teams[i];
   804             team:= clan^.Teams[i];
   799             for j:= 0 to 7 do
   805             for j:= 0 to 7 do
   800                 begin
   806                 begin
   806                     RenderHealth(hh);
   812                     RenderHealth(hh);
   807                     end;
   813                     end;
   808                 end;
   814                 end;
   809             FreeTexture(team^.NameTagTex);
   815             FreeTexture(team^.NameTagTex);
   810             team^.NameTagTex:= RenderStringTex(clan^.Teams[i]^.TeamName, clan^.Color, fnt16);
   816             team^.NameTagTex:= RenderStringTex(clan^.Teams[i]^.TeamName, clan^.Color, fnt16);
   811             r.w:= cTeamHealthWidth + 5;
   817             end;
   812             r.h:= team^.NameTagTex^.h;
   818 
   813 
   819         clan^.HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, clan^.Teams[0]^.NameTagTex^.h, clan^.Color);
   814             texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask);
   820         end;
   815             TryDo(texsurf <> nil, errmsgCreateSurface, true);
   821 
   816             TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
       
   817 
       
   818             DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true);
       
   819             rr:= r;
       
   820             inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
       
   821             DrawRoundRect(@rr, clan^.Color, clan^.Color, texsurf, false);
       
   822 
       
   823             FreeTexture(team^.HealthTex);
       
   824             team^.HealthTex:= Surface2Tex(texsurf, false);
       
   825             SDL_FreeSurface(texsurf);
       
   826             MakeCrossHairs
       
   827             end
       
   828         end;
       
   829     lc_setclancolor:= 0
   822     lc_setclancolor:= 0
   830 end;
   823 end;
   831 
   824 
   832 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl;
   825 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl;
   833 var gear : PGear;
   826 var gear : PGear;
   834 begin
   827 begin
   835     if lua_gettop(L) <> 1 then
   828     if lua_gettop(L) <> 1 then
   836         begin
   829         begin
   837         LuaError('Lua: Wrong number of parameters passed to GetHogTeamName!');
   830         LuaParameterCountError('GetHogTeamName', 'gearUid', lua_gettop(L));
   838         lua_pushnil(L); // return value on stack (nil)
   831         lua_pushnil(L); // return value on stack (nil)
   839         end
   832         end
   840     else
   833     else
   841         begin
   834         begin
   842         gear:= GearByUID(lua_tointeger(L, 1));
   835         gear:= GearByUID(lua_tointeger(L, 1));
   848             lua_pushnil(L);
   841             lua_pushnil(L);
   849         end;
   842         end;
   850     lc_gethogteamname:= 1
   843     lc_gethogteamname:= 1
   851 end;
   844 end;
   852 
   845 
       
   846 function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl;
       
   847 var gear : PGear;
       
   848 begin
       
   849     if lua_gettop(L) <> 2 then
       
   850         begin
       
   851         LuaParameterCountError('SetHogTeamName', 'gearUid, name', lua_gettop(L));
       
   852         lua_pushnil(L); // return value on stack (nil)
       
   853         end
       
   854     else
       
   855         begin
       
   856         gear := GearByUID(lua_tointeger(L, 1));
       
   857         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
       
   858             begin
       
   859             gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2);
       
   860 
       
   861             FreeTexture(gear^.Hedgehog^.Team^.NameTagTex);
       
   862             gear^.Hedgehog^.Team^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Team^.TeamName, gear^.Hedgehog^.Team^.Clan^.Color, fnt16);
       
   863             end
       
   864         else
       
   865             lua_pushnil(L);
       
   866         end;
       
   867     lc_sethogteamname:= 1
       
   868 end;
       
   869 
   853 function lc_gethogname(L : Plua_State) : LongInt; Cdecl;
   870 function lc_gethogname(L : Plua_State) : LongInt; Cdecl;
   854 var gear : PGear;
   871 var gear : PGear;
   855 begin
   872 begin
   856     if lua_gettop(L) <> 1 then
   873     if lua_gettop(L) <> 1 then
   857         begin
   874         begin
   858         LuaError('Lua: Wrong number of parameters passed to GetHogName!');
   875         LuaParameterCountError('GetHogName', 'gearUid', lua_gettop(L));
   859         lua_pushnil(L); // return value on stack (nil)
   876         lua_pushnil(L); // return value on stack (nil)
   860         end
   877         end
   861     else
   878     else
   862         begin
   879         begin
   863         gear:= GearByUID(lua_tointeger(L, 1));
   880         gear:= GearByUID(lua_tointeger(L, 1));
   871     lc_gethogname:= 1
   888     lc_gethogname:= 1
   872 end;
   889 end;
   873 
   890 
   874 function lc_sethogname(L : Plua_State) : LongInt; Cdecl;
   891 function lc_sethogname(L : Plua_State) : LongInt; Cdecl;
   875 var gear : PGear;
   892 var gear : PGear;
   876   hogName: ShortString;
       
   877 begin
   893 begin
   878     if lua_gettop(L) <> 2 then
   894     if lua_gettop(L) <> 2 then
   879         begin
   895         begin
   880         LuaError('Lua: Wrong number of parameters passed to SetHogName!');
   896         LuaParameterCountError('SetHogName', 'gearUid, name', lua_gettop(L));
   881         lua_pushnil(L)
   897         lua_pushnil(L)
   882         end
   898         end
   883     else
   899     else
   884         begin
   900         begin
   885         gear:= GearByUID(lua_tointeger(L, 1));
   901         gear:= GearByUID(lua_tointeger(L, 1));
   886         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
   902         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
   887 
   903             begin
   888         hogName:= lua_tostring(L, 2);
   904             gear^.Hedgehog^.Name:= lua_tostring(L, 2);
   889             gear^.Hedgehog^.Name:= hogName;
   905 
   890 
   906             FreeTexture(gear^.Hedgehog^.NameTagTex);
   891         FreeTexture(gear^.Hedgehog^.NameTagTex);
   907             gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16)
   892         gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16);
   908             end
   893 
       
   894         end;
   909         end;
   895     lc_sethogname:= 0;
   910     lc_sethogname:= 0;
   896 end;
   911 end;
   897 
   912 
   898 function lc_gettimer(L : Plua_State) : LongInt; Cdecl;
   913 function lc_gettimer(L : Plua_State) : LongInt; Cdecl;
   899 var gear : PGear;
   914 var gear : PGear;
   900 begin
   915 begin
   901     if lua_gettop(L) <> 1 then
   916     if lua_gettop(L) <> 1 then
   902         begin
   917         begin
   903         LuaError('Lua: Wrong number of parameters passed to GetTimer!');
   918         LuaParameterCountError('GetTimer', 'gearUid', lua_gettop(L));
   904         lua_pushnil(L); // return value on stack (nil)
   919         lua_pushnil(L); // return value on stack (nil)
   905         end
   920         end
   906     else
   921     else
   907         begin
   922         begin
   908         gear:= GearByUID(lua_tointeger(L, 1));
   923         gear:= GearByUID(lua_tointeger(L, 1));
   917 function lc_gethealth(L : Plua_State) : LongInt; Cdecl;
   932 function lc_gethealth(L : Plua_State) : LongInt; Cdecl;
   918 var gear : PGear;
   933 var gear : PGear;
   919 begin
   934 begin
   920     if lua_gettop(L) <> 1 then
   935     if lua_gettop(L) <> 1 then
   921         begin
   936         begin
   922         LuaError('Lua: Wrong number of parameters passed to GetHealth!');
   937         LuaParameterCountError('GetHealth', 'gearUid', lua_gettop(L));
   923         lua_pushnil(L); // return value on stack (nil)
   938         lua_pushnil(L); // return value on stack (nil)
   924         end
   939         end
   925     else
   940     else
   926         begin
   941         begin
   927         gear:= GearByUID(lua_tointeger(L, 1));
   942         gear:= GearByUID(lua_tointeger(L, 1));
   936 function lc_getx(L : Plua_State) : LongInt; Cdecl;
   951 function lc_getx(L : Plua_State) : LongInt; Cdecl;
   937 var gear : PGear;
   952 var gear : PGear;
   938 begin
   953 begin
   939     if lua_gettop(L) <> 1 then
   954     if lua_gettop(L) <> 1 then
   940         begin
   955         begin
   941         LuaError('Lua: Wrong number of parameters passed to GetX!');
   956         LuaParameterCountError('GetX', 'gearUid', lua_gettop(L));
   942         lua_pushnil(L); // return value on stack (nil)
   957         lua_pushnil(L); // return value on stack (nil)
   943         end
   958         end
   944     else
   959     else
   945         begin
   960         begin
   946         gear:= GearByUID(lua_tointeger(L, 1));
   961         gear:= GearByUID(lua_tointeger(L, 1));
   955 function lc_gety(L : Plua_State) : LongInt; Cdecl;
   970 function lc_gety(L : Plua_State) : LongInt; Cdecl;
   956 var gear : PGear;
   971 var gear : PGear;
   957 begin
   972 begin
   958     if lua_gettop(L) <> 1 then
   973     if lua_gettop(L) <> 1 then
   959         begin
   974         begin
   960         LuaError('Lua: Wrong number of parameters passed to GetY!');
   975         LuaParameterCountError('GetY', 'gearUid', lua_gettop(L));
   961         lua_pushnil(L); // return value on stack (nil)
   976         lua_pushnil(L); // return value on stack (nil)
   962         end
   977         end
   963     else
   978     else
   964         begin
   979         begin
   965         gear:= GearByUID(lua_tointeger(L, 1));
   980         gear:= GearByUID(lua_tointeger(L, 1));
   974 function lc_copypv(L : Plua_State) : LongInt; Cdecl;
   989 function lc_copypv(L : Plua_State) : LongInt; Cdecl;
   975 var gears, geard : PGear;
   990 var gears, geard : PGear;
   976 begin
   991 begin
   977     if lua_gettop(L) <> 2 then
   992     if lua_gettop(L) <> 2 then
   978         begin
   993         begin
   979         LuaError('Lua: Wrong number of parameters passed to CopyPV!');
   994         LuaParameterCountError('CopyPV', 'fromGearUid, toGearUid', lua_gettop(L));
   980         end
   995         end
   981     else
   996     else
   982         begin
   997         begin
   983         gears:= GearByUID(lua_tointeger(L, 1));
   998         gears:= GearByUID(lua_tointeger(L, 1));
   984         geard:= GearByUID(lua_tointeger(L, 2));
   999         geard:= GearByUID(lua_tointeger(L, 2));
   995 
  1010 
   996 function lc_followgear(L : Plua_State) : LongInt; Cdecl;
  1011 function lc_followgear(L : Plua_State) : LongInt; Cdecl;
   997 var gear : PGear;
  1012 var gear : PGear;
   998 begin
  1013 begin
   999     if lua_gettop(L) <> 1 then
  1014     if lua_gettop(L) <> 1 then
  1000         LuaError('Lua: Wrong number of parameters passed to FollowGear!')
  1015         LuaParameterCountError('FollowGear', 'gearUid', lua_gettop(L))
  1001     else
  1016     else
  1002         begin
  1017         begin
  1003         gear:= GearByUID(lua_tointeger(L, 1));
  1018         gear:= GearByUID(lua_tointeger(L, 1));
  1004         if gear <> nil then FollowGear:= gear
  1019         if gear <> nil then FollowGear:= gear
  1005         end;
  1020         end;
  1027                vgear^.Text:= lua_tostring(L, 2);
  1042                vgear^.Text:= lua_tostring(L, 2);
  1028                vgear^.Hedgehog:= gear^.Hedgehog;
  1043                vgear^.Hedgehog:= gear^.Hedgehog;
  1029                vgear^.FrameTicks:= lua_tointeger(L, 3);
  1044                vgear^.FrameTicks:= lua_tointeger(L, 3);
  1030                if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then
  1045                if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then
  1031                    vgear^.FrameTicks:= 1;
  1046                    vgear^.FrameTicks:= 1;
  1032                lua_pushinteger(L, vgear^.Uid)
  1047                lua_pushinteger(L, vgear^.Uid);
       
  1048                AddChatString(#1+'[' + gear^.Hedgehog^.Name + '] '+vgear^.text)
  1033                end
  1049                end
  1034             end
  1050             end
  1035             else
  1051             else
  1036                 lua_pushnil(L)
  1052                 lua_pushnil(L)
  1037         end
  1053         end
  1038     else LuaError('Lua: Wrong number of parameters passed to HogSay!');
  1054     else LuaParameterCountError('HogSay', 'gearUid, text, manner[, vgState]', lua_gettop(L));
  1039     lc_hogsay:= 1
  1055     lc_hogsay:= 1
  1040 end;
  1056 end;
  1041 
  1057 
  1042 function lc_switchhog(L : Plua_State) : LongInt; Cdecl;
  1058 function lc_switchhog(L : Plua_State) : LongInt; Cdecl;
  1043 var gear, prevgear : PGear;
  1059 var gear, prevgear : PGear;
  1044 begin
  1060 begin
  1045     if lua_gettop(L) <> 1 then
  1061     if lua_gettop(L) <> 1 then
  1046         LuaError('Lua: Wrong number of parameters passed to SwitchHog!')
  1062         LuaParameterCountError('SwitchHog', 'gearUid', lua_gettop(L))
  1047     else
  1063     else
  1048         begin
  1064         begin
  1049         gear:= GearByUID(lua_tointeger(L, 1));
  1065         gear:= GearByUID(lua_tointeger(L, 1));
  1050 // should we allow this when there is no current hedgehog? might do some odd(er) things to turn sequence.
  1066 // should we allow this when there is no current hedgehog? might do some odd(er) things to turn sequence.
  1051         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (CurrentHedgehog <> nil) then
  1067         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (CurrentHedgehog <> nil) then
  1087     gear:= GearByUID(lua_tointeger(L, 1));
  1103     gear:= GearByUID(lua_tointeger(L, 1));
  1088         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1104         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1089             AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)));
  1105             AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)));
  1090     end else
  1106     end else
  1091     begin
  1107     begin
  1092         LuaError('Lua: Wrong number of parameters passed to AddAmmo!');
  1108         LuaParameterCountError('AddAmmo', 'TODO', lua_gettop(L));
  1093     end;
  1109     end;
  1094 
  1110 
  1095     lc_addammo:= 0;
  1111     lc_addammo:= 0;
  1096 
  1112 
  1097 end;}
  1113 end;}
  1106             if lua_gettop(L) = 2 then
  1122             if lua_gettop(L) = 2 then
  1107                 AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)))
  1123                 AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)))
  1108             else
  1124             else
  1109                 SetAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L, 3))
  1125                 SetAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L, 3))
  1110         end
  1126         end
  1111     else LuaError('Lua: Wrong number of parameters passed to AddAmmo!');
  1127     else LuaParameterCountError('AddAmmo', 'gearUid, ammoType[, ammoCount]', lua_gettop(L));
  1112     lc_addammo:= 0
  1128     lc_addammo:= 0
  1113 end;
  1129 end;
  1114 
  1130 
  1115 function lc_getammocount(L : Plua_State) : LongInt; Cdecl;
  1131 function lc_getammocount(L : Plua_State) : LongInt; Cdecl;
  1116 var gear : PGear;
  1132 var gear : PGear;
  1129             end
  1145             end
  1130         else lua_pushinteger(L, 0)
  1146         else lua_pushinteger(L, 0)
  1131         end
  1147         end
  1132     else
  1148     else
  1133         begin
  1149         begin
  1134         LuaError('Lua: Wrong number of parameters passed to GetAmmoCount!');
  1150         LuaParameterCountError('GetAmmoCount', 'gearUid, ammoType', lua_gettop(L));
  1135         lua_pushnil(L)
  1151         lua_pushnil(L)
  1136         end;
  1152         end;
  1137     lc_getammocount:= 1
  1153     lc_getammocount:= 1
  1138 end;
  1154 end;
  1139 
  1155 
  1140 function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
  1156 function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
  1141 var gear : PGear;
  1157 var gear : PGear;
  1142 begin
  1158 begin
  1143     if lua_gettop(L) <> 2 then
  1159     if lua_gettop(L) <> 2 then
  1144         begin
  1160         begin
  1145         LuaError('Lua: Wrong number of parameters passed to SetHealth!');
  1161         LuaParameterCountError('SetHealth', 'gearUid, health', lua_gettop(L));
  1146         end
  1162         end
  1147     else
  1163     else
  1148         begin
  1164         begin
  1149         gear:= GearByUID(lua_tointeger(L, 1));
  1165         gear:= GearByUID(lua_tointeger(L, 1));
  1150         if gear <> nil then
  1166         if gear <> nil then
  1151             begin
  1167             begin
  1152             gear^.Health:= lua_tointeger(L, 2);
  1168             gear^.Health:= lua_tointeger(L, 2);
  1153 
  1169 
  1154         if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1170             if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1155             begin
  1171                 begin
  1156             RenderHealth(gear^.Hedgehog^);
  1172                 RenderHealth(gear^.Hedgehog^);
  1157             RecountTeamHealth(gear^.Hedgehog^.Team)
  1173                 RecountTeamHealth(gear^.Hedgehog^.Team)
  1158             end;
  1174                 end;
  1159 
  1175             // Why did this do a "setalltoactive" ?
  1160             SetAllToActive;
  1176             //SetAllToActive;  
       
  1177             Gear^.Active:= true;
       
  1178             AllInactive:= false
  1161             end
  1179             end
  1162         end;
  1180         end;
  1163     lc_sethealth:= 0
  1181     lc_sethealth:= 0
  1164 end;
  1182 end;
  1165 
  1183 
  1166 function lc_settimer(L : Plua_State) : LongInt; Cdecl;
  1184 function lc_settimer(L : Plua_State) : LongInt; Cdecl;
  1167 var gear : PGear;
  1185 var gear : PGear;
  1168 begin
  1186 begin
  1169     if lua_gettop(L) <> 2 then
  1187     if lua_gettop(L) <> 2 then
  1170         begin
  1188         begin
  1171         LuaError('Lua: Wrong number of parameters passed to SetTimer!');
  1189         LuaParameterCountError('SetTimer', 'gearUid, timer', lua_gettop(L));
  1172         end
  1190         end
  1173     else
  1191     else
  1174         begin
  1192         begin
  1175         gear:= GearByUID(lua_tointeger(L, 1));
  1193         gear:= GearByUID(lua_tointeger(L, 1));
  1176         if gear <> nil then gear^.Timer:= lua_tointeger(L, 2)
  1194         if gear <> nil then gear^.Timer:= lua_tointeger(L, 2)
  1180 
  1198 
  1181 function lc_seteffect(L : Plua_State) : LongInt; Cdecl;
  1199 function lc_seteffect(L : Plua_State) : LongInt; Cdecl;
  1182 var gear: PGear;
  1200 var gear: PGear;
  1183 begin
  1201 begin
  1184     if lua_gettop(L) <> 3 then
  1202     if lua_gettop(L) <> 3 then
  1185         LuaError('Lua: Wrong number of parameters passed to SetEffect!')
  1203         LuaParameterCountError('SetEffect', 'gearUid, effect, enabled', lua_gettop(L))
  1186     else begin
  1204     else begin
  1187         gear := GearByUID(lua_tointeger(L, 1));
  1205         gear := GearByUID(lua_tointeger(L, 1));
  1188         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1206         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1189             gear^.Hedgehog^.Effects[THogEffect(lua_tointeger(L, 2))]:= lua_tointeger(L, 3);
  1207             gear^.Hedgehog^.Effects[THogEffect(lua_tointeger(L, 2))]:= lua_tointeger(L, 3);
  1190     end;
  1208     end;
  1191     lc_seteffect := 0;
  1209     lc_seteffect := 0;
  1192 end;
  1210 end;
       
  1211 
  1193 function lc_geteffect(L : Plua_State) : LongInt; Cdecl;
  1212 function lc_geteffect(L : Plua_State) : LongInt; Cdecl;
  1194 var gear : PGear;
  1213 var gear : PGear;
  1195 begin
  1214 begin
  1196     if lua_gettop(L) <> 2 then
  1215     if lua_gettop(L) <> 2 then
  1197         begin
  1216         begin
  1198         LuaError('Lua: Wrong number of parameters passed to GetEffect!');
  1217         LuaParameterCountError('GetEffect', 'gearUid, effect', lua_gettop(L));
  1199         end
  1218         end
  1200     else
  1219     else
  1201         begin
  1220         begin
  1202         gear:= GearByUID(lua_tointeger(L, 1));
  1221         gear:= GearByUID(lua_tointeger(L, 1));
  1203         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1222         if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1211 function lc_setstate(L : Plua_State) : LongInt; Cdecl;
  1230 function lc_setstate(L : Plua_State) : LongInt; Cdecl;
  1212 var gear : PGear;
  1231 var gear : PGear;
  1213 begin
  1232 begin
  1214     if lua_gettop(L) <> 2 then
  1233     if lua_gettop(L) <> 2 then
  1215         begin
  1234         begin
  1216         LuaError('Lua: Wrong number of parameters passed to SetState!');
  1235         LuaParameterCountError('SetState', 'gearUid, state', lua_gettop(L));
  1217         end
  1236         end
  1218     else
  1237     else
  1219         begin
  1238         begin
  1220         gear:= GearByUID(lua_tointeger(L, 1));
  1239         gear:= GearByUID(lua_tointeger(L, 1));
  1221         if gear <> nil then
  1240         if gear <> nil then
  1230 function lc_getstate(L : Plua_State) : LongInt; Cdecl;
  1249 function lc_getstate(L : Plua_State) : LongInt; Cdecl;
  1231 var gear : PGear;
  1250 var gear : PGear;
  1232 begin
  1251 begin
  1233     if lua_gettop(L) <> 1 then
  1252     if lua_gettop(L) <> 1 then
  1234         begin
  1253         begin
  1235         LuaError('Lua: Wrong number of parameters passed to GetState!');
  1254         LuaParameterCountError('GetState', 'gearUid', lua_gettop(L));
  1236         end
  1255         end
  1237     else
  1256     else
  1238         begin
  1257         begin
  1239         gear:= GearByUID(lua_tointeger(L, 1));
  1258         gear:= GearByUID(lua_tointeger(L, 1));
  1240         if gear <> nil then
  1259         if gear <> nil then
  1248 function lc_gettag(L : Plua_State) : LongInt; Cdecl;
  1267 function lc_gettag(L : Plua_State) : LongInt; Cdecl;
  1249 var gear : PGear;
  1268 var gear : PGear;
  1250 begin
  1269 begin
  1251     if lua_gettop(L) <> 1 then
  1270     if lua_gettop(L) <> 1 then
  1252         begin
  1271         begin
  1253         LuaError('Lua: Wrong number of parameters passed to GetX!');
  1272         LuaParameterCountError('GetTag', 'gearUid', lua_gettop(L));
  1254         lua_pushnil(L); // return value on stack (nil)
  1273         lua_pushnil(L); // return value on stack (nil)
  1255         end
  1274         end
  1256     else
  1275     else
  1257         begin
  1276         begin
  1258         gear:= GearByUID(lua_tointeger(L, 1));
  1277         gear:= GearByUID(lua_tointeger(L, 1));
  1267 function lc_settag(L : Plua_State) : LongInt; Cdecl;
  1286 function lc_settag(L : Plua_State) : LongInt; Cdecl;
  1268 var gear : PGear;
  1287 var gear : PGear;
  1269 begin
  1288 begin
  1270     if lua_gettop(L) <> 2 then
  1289     if lua_gettop(L) <> 2 then
  1271         begin
  1290         begin
  1272         LuaError('Lua: Wrong number of parameters passed to SetTag!');
  1291         LuaParameterCountError('SetTag', 'gearUid, tag', lua_gettop(L));
  1273         end
  1292         end
  1274     else
  1293     else
  1275         begin
  1294         begin
  1276         gear:= GearByUID(lua_tointeger(L, 1));
  1295         gear:= GearByUID(lua_tointeger(L, 1));
  1277         if gear <> nil then
  1296         if gear <> nil then
  1297 begin
  1316 begin
  1298     statInfo := TStatInfoType(lua_tointeger(L, 1));
  1317     statInfo := TStatInfoType(lua_tointeger(L, 1));
  1299     if (lua_gettop(L) <> 2) and ((statInfo <> siPlayerKills)
  1318     if (lua_gettop(L) <> 2) and ((statInfo <> siPlayerKills)
  1300             and (statInfo <> siClanHealth)) then
  1319             and (statInfo <> siClanHealth)) then
  1301         begin
  1320         begin
  1302         LuaError('Lua: Wrong number of parameters passed to SendStat! Expected 2 parameters.');
  1321         LuaParameterCountError('SendStat', 'statInfoType, color', lua_gettop(L));
  1303         end
  1322         end
  1304     else if (lua_gettop(L) <> 3) and ((statInfo = siPlayerKills)
  1323     else if (lua_gettop(L) <> 3) and ((statInfo = siPlayerKills)
  1305             or (statInfo = siClanHealth)) then
  1324             or (statInfo = siClanHealth)) then
  1306         begin
  1325         begin
  1307         LuaError('Lua: Wrong number of parameters passed to SendStat! Expected 3 parameters.');
  1326         LuaParameterCountError('SendStat', 'siClanHealth, color, teamname', lua_gettop(L));
  1308         end
  1327         end
  1309     else
  1328     else
  1310         begin
  1329         begin
  1311         if ((statInfo = siPlayerKills) or (statInfo = siClanHealth)) then
  1330         if ((statInfo = siPlayerKills) or (statInfo = siClanHealth)) then
  1312             begin
  1331             begin
  1354     tryhard: boolean;
  1373     tryhard: boolean;
  1355     left, right: LongInt;
  1374     left, right: LongInt;
  1356 begin
  1375 begin
  1357     tryhard:= false;
  1376     tryhard:= false;
  1358     if (lua_gettop(L) <> 4) and (lua_gettop(L) <> 5) then
  1377     if (lua_gettop(L) <> 4) and (lua_gettop(L) <> 5) then
  1359         LuaError('Lua: Wrong number of parameters passed to FindPlace!')
  1378         LuaParameterCountError('FindPlace', 'gearUid, fall, left, right[, tryHarder]', lua_gettop(L))
  1360     else
  1379     else
  1361         begin
  1380         begin
  1362         gear:= GearByUID(lua_tointeger(L, 1));
  1381         gear:= GearByUID(lua_tointeger(L, 1));
  1363         fall:= lua_toboolean(L, 2);
  1382         fall:= lua_toboolean(L, 2);
  1364         left:= lua_tointeger(L, 3);
  1383         left:= lua_tointeger(L, 3);
  1384         begin
  1403         begin
  1385         gear:= GearByUID(lua_tointeger(L, 2));
  1404         gear:= GearByUID(lua_tointeger(L, 2));
  1386         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1405         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1387             AddVoice(TSound(lua_tointeger(L, 1)),gear^.Hedgehog^.Team^.Voicepack)
  1406             AddVoice(TSound(lua_tointeger(L, 1)),gear^.Hedgehog^.Team^.Voicepack)
  1388         end
  1407         end
  1389     else LuaError('Lua: Wrong number of parameters passed to PlaySound!');
  1408     else LuaParameterCountError('PlaySound', 'soundId', lua_gettop(L));
  1390     lc_playsound:= 0;
  1409     lc_playsound:= 0;
  1391 end;
  1410 end;
  1392 
  1411 
  1393 function lc_addteam(L : Plua_State) : LongInt; Cdecl;
  1412 function lc_addteam(L : Plua_State) : LongInt; Cdecl;
  1394 var np: LongInt;
  1413 var np: LongInt;
  1395 begin
  1414 begin
  1396     np:= lua_gettop(L);
  1415     np:= lua_gettop(L);
  1397     if (np < 5) or (np > 6) then
  1416     if (np < 5) or (np > 6) then
  1398         begin
  1417         begin
  1399         LuaError('Lua: Wrong number of parameters passed to AddTeam!');
  1418         LuaParameterCountError('AddTeam', 'teamname, color, grave, fort, voicepack[, flag]', lua_gettop(L));
  1400         //lua_pushnil(L)
  1419         //lua_pushnil(L)
  1401         end
  1420         end
  1402     else
  1421     else
  1403         begin
  1422         begin
  1404         ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true, true);
  1423         ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true, true);
  1416 function lc_addhog(L : Plua_State) : LongInt; Cdecl;
  1435 function lc_addhog(L : Plua_State) : LongInt; Cdecl;
  1417 var temp: ShortString;
  1436 var temp: ShortString;
  1418 begin
  1437 begin
  1419     if lua_gettop(L) <> 4 then
  1438     if lua_gettop(L) <> 4 then
  1420         begin
  1439         begin
  1421         LuaError('Lua: Wrong number of parameters passed to AddHog!');
  1440         LuaParameterCountError('AddHog', 'hogname, botlevel, health, hat', lua_gettop(L));
  1422         lua_pushnil(L)
  1441         lua_pushnil(L)
  1423         end
  1442         end
  1424     else
  1443     else
  1425         begin
  1444         begin
  1426         temp:= lua_tostring(L, 4);
  1445         temp:= lua_tostring(L, 4);
  1434 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl;
  1453 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl;
  1435 var gear: PGear;
  1454 var gear: PGear;
  1436 begin
  1455 begin
  1437     if lua_gettop(L) <> 2 then
  1456     if lua_gettop(L) <> 2 then
  1438         begin
  1457         begin
  1439         LuaError('Lua: Wrong number of parameters passed to HogTurnLeft!');
  1458         LuaParameterCountError('HogTurnLeft', 'gearUid, boolean', lua_gettop(L));
  1440         end
  1459         end
  1441     else
  1460     else
  1442         begin
  1461         begin
  1443         gear:= GearByUID(lua_tointeger(L, 1));
  1462         gear:= GearByUID(lua_tointeger(L, 1));
  1444         if gear <> nil then
  1463         if gear <> nil then
  1450 function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
  1469 function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
  1451 var gear: PGear;
  1470 var gear: PGear;
  1452 begin
  1471 begin
  1453     if lua_gettop(L) <> 1 then
  1472     if lua_gettop(L) <> 1 then
  1454         begin
  1473         begin
  1455         LuaError('Lua: Wrong number of parameters passed to GetGearPosition!');
  1474         LuaParameterCountError('GetGearPosition', 'gearUid', lua_gettop(L));
  1456         lua_pushnil(L);
  1475         lua_pushnil(L);
  1457         lua_pushnil(L)
  1476         lua_pushnil(L)
  1458         end
  1477         end
  1459     else
  1478     else
  1460         begin
  1479         begin
  1477 var gear: PGear;
  1496 var gear: PGear;
  1478     col: boolean;
  1497     col: boolean;
  1479     x, y: LongInt;
  1498     x, y: LongInt;
  1480 begin
  1499 begin
  1481     if lua_gettop(L) <> 3 then
  1500     if lua_gettop(L) <> 3 then
  1482         LuaError('Lua: Wrong number of parameters passed to SetGearPosition!')
  1501         LuaParameterCountError('SetGearPosition', 'gearUid, x, y', lua_gettop(L))
  1483     else
  1502     else
  1484         begin
  1503         begin
  1485         gear:= GearByUID(lua_tointeger(L, 1));
  1504         gear:= GearByUID(lua_tointeger(L, 1));
  1486         if gear <> nil then
  1505         if gear <> nil then
  1487             begin
  1506             begin
  1503 function lc_getgeartarget(L : Plua_State) : LongInt; Cdecl;
  1522 function lc_getgeartarget(L : Plua_State) : LongInt; Cdecl;
  1504 var gear: PGear;
  1523 var gear: PGear;
  1505 begin
  1524 begin
  1506     if lua_gettop(L) <> 1 then
  1525     if lua_gettop(L) <> 1 then
  1507         begin
  1526         begin
  1508         LuaError('Lua: Wrong number of parameters passed to GetGearTarget!');
  1527         LuaParameterCountError('GetGearTarget', 'gearUid', lua_gettop(L));
  1509         lua_pushnil(L);
  1528         lua_pushnil(L);
  1510         lua_pushnil(L)
  1529         lua_pushnil(L)
  1511         end
  1530         end
  1512     else
  1531     else
  1513         begin
  1532         begin
  1528 
  1547 
  1529 function lc_setgeartarget(L : Plua_State) : LongInt; Cdecl;
  1548 function lc_setgeartarget(L : Plua_State) : LongInt; Cdecl;
  1530 var gear: PGear;
  1549 var gear: PGear;
  1531 begin
  1550 begin
  1532     if lua_gettop(L) <> 3 then
  1551     if lua_gettop(L) <> 3 then
  1533         LuaError('Lua: Wrong number of parameters passed to SetGearTarget!')
  1552         LuaParameterCountError('SetGearTarget', 'gearUid, x, y', lua_gettop(L))
  1534     else
  1553     else
  1535         begin
  1554         begin
  1536         gear:= GearByUID(lua_tointeger(L, 1));
  1555         gear:= GearByUID(lua_tointeger(L, 1));
  1537         if gear <> nil then
  1556         if gear <> nil then
  1538             begin
  1557             begin
  1547 var gear: PGear;
  1566 var gear: PGear;
  1548 var t: LongInt;
  1567 var t: LongInt;
  1549 begin
  1568 begin
  1550     if lua_gettop(L) <> 1 then
  1569     if lua_gettop(L) <> 1 then
  1551         begin
  1570         begin
  1552         LuaError('Lua: Wrong number of parameters passed to GetGearVelocity!');
  1571         LuaParameterCountError('GetGearVelocity', 'gearUid', lua_gettop(L));
  1553         lua_pushnil(L);
  1572         lua_pushnil(L);
  1554         lua_pushnil(L)
  1573         lua_pushnil(L)
  1555         end
  1574         end
  1556     else
  1575     else
  1557         begin
  1576         begin
  1570 
  1589 
  1571 function lc_setgearvelocity(L : Plua_State) : LongInt; Cdecl;
  1590 function lc_setgearvelocity(L : Plua_State) : LongInt; Cdecl;
  1572 var gear: PGear;
  1591 var gear: PGear;
  1573 begin
  1592 begin
  1574     if lua_gettop(L) <> 3 then
  1593     if lua_gettop(L) <> 3 then
  1575         LuaError('Lua: Wrong number of parameters passed to SetGearVelocity!')
  1594         LuaParameterCountError('SetGearVelocity', 'gearUid, dx, dy', lua_gettop(L))
  1576     else
  1595     else
  1577         begin
  1596         begin
  1578         gear:= GearByUID(lua_tointeger(L, 1));
  1597         gear:= GearByUID(lua_tointeger(L, 1));
  1579         if gear <> nil then
  1598         if gear <> nil then
  1580             begin
  1599             begin
  1587 end;
  1606 end;
  1588 
  1607 
  1589 function lc_setzoom(L : Plua_State) : LongInt; Cdecl;
  1608 function lc_setzoom(L : Plua_State) : LongInt; Cdecl;
  1590 begin
  1609 begin
  1591     if lua_gettop(L) <> 1 then
  1610     if lua_gettop(L) <> 1 then
  1592         LuaError('Lua: Wrong number of parameters passed to SetZoom!')
  1611         LuaParameterCountError('SetZoom', 'zoomLevel', lua_gettop(L))
  1593     else
  1612     else
  1594         begin
  1613         begin
  1595         ZoomValue:= lua_tonumber(L, 1);
  1614         ZoomValue:= lua_tonumber(L, 1);
  1596         if ZoomValue < cMaxZoomLevel then
  1615         if ZoomValue < cMaxZoomLevel then
  1597             ZoomValue:= cMaxZoomLevel;
  1616             ZoomValue:= cMaxZoomLevel;
  1603 
  1622 
  1604 function lc_getzoom(L : Plua_State) : LongInt; Cdecl;
  1623 function lc_getzoom(L : Plua_State) : LongInt; Cdecl;
  1605 begin
  1624 begin
  1606     if lua_gettop(L) <> 0 then
  1625     if lua_gettop(L) <> 0 then
  1607         begin
  1626         begin
  1608         LuaError('Lua: Wrong number of parameters passed to GetZoom!');
  1627         LuaParameterCountError('GetZoom', '', lua_gettop(L));
  1609         lua_pushnil(L)
  1628         lua_pushnil(L)
  1610         end
  1629         end
  1611     else
  1630     else
  1612         lua_pushnumber(L, ZoomValue);
  1631         lua_pushnumber(L, ZoomValue);
  1613     lc_getzoom:= 1
  1632     lc_getzoom:= 1
  1616 function lc_setammo(L : Plua_State) : LongInt; Cdecl;
  1635 function lc_setammo(L : Plua_State) : LongInt; Cdecl;
  1617 var np: LongInt;
  1636 var np: LongInt;
  1618 begin
  1637 begin
  1619     np:= lua_gettop(L);
  1638     np:= lua_gettop(L);
  1620     if (np < 4) or (np > 5) then
  1639     if (np < 4) or (np > 5) then
  1621         LuaError('Lua: Wrong number of parameters passed to SetAmmo!')
  1640         LuaParameterCountError('SetAmmo', 'ammoType, count, probability, delay[, numberInCrate]', lua_gettop(L))
  1622     else if np = 4 then
  1641     else if np = 4 then
  1623         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), 1)
  1642         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), 1)
  1624     else
  1643     else
  1625         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
  1644         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
  1626     lc_setammo:= 0
  1645     lc_setammo:= 0
  1627 end;
  1646 end;
  1628 
  1647 
       
  1648 function lc_setammodelay(L : Plua_State) : LongInt; Cdecl;
       
  1649 var np: LongInt;
       
  1650 begin
       
  1651     np:= lua_gettop(L);
       
  1652     if (np <> 2) then
       
  1653         LuaParameterCountError('SetAmmoDelay', 'ammoType, delay', lua_gettop(L))
       
  1654     else
       
  1655         ScriptSetAmmoDelay(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2));
       
  1656     lc_setammodelay:= 0
       
  1657 end;
       
  1658 
  1629 function lc_setammostore(L : Plua_State) : LongInt; Cdecl;
  1659 function lc_setammostore(L : Plua_State) : LongInt; Cdecl;
  1630 var np: LongInt;
  1660 var np: LongInt;
  1631 begin
  1661 begin
  1632     np:= lua_gettop(L);
  1662     np:= lua_gettop(L);
  1633     if (np <> 4) then
  1663     if (np <> 4) then
  1634         LuaError('Lua: Wrong number of parameters passed to SetAmmoStore!')
  1664         LuaParameterCountError('SetAmmoStore', 'loadouts, probabilities, delays, reinforments', lua_gettop(L))
  1635     else
  1665     else
  1636         begin
  1666         begin
  1637         ScriptAmmoLoadout:= lua_tostring(L, 1);
  1667         ScriptAmmoLoadout:= lua_tostring(L, 1);
  1638         ScriptAmmoProbability:= lua_tostring(L, 2);
  1668         ScriptAmmoProbability:= lua_tostring(L, 2);
  1639         ScriptAmmoDelay:= lua_tostring(L, 3);
  1669         ScriptAmmoDelay:= lua_tostring(L, 3);
  1645 function lc_getrandom(L : Plua_State) : LongInt; Cdecl;
  1675 function lc_getrandom(L : Plua_State) : LongInt; Cdecl;
  1646 var m : LongInt;
  1676 var m : LongInt;
  1647 begin
  1677 begin
  1648     if lua_gettop(L) <> 1 then
  1678     if lua_gettop(L) <> 1 then
  1649         begin
  1679         begin
  1650         LuaError('Lua: Wrong number of parameters passed to GetRandom!');
  1680         LuaParameterCountError('GetRandom', 'number', lua_gettop(L));
  1651         lua_pushnil(L); // return value on stack (nil)
  1681         lua_pushnil(L); // return value on stack (nil)
  1652         end
  1682         end
  1653     else
  1683     else
  1654         begin
  1684         begin
  1655         m:= lua_tointeger(L, 1);
  1685         m:= lua_tointeger(L, 1);
  1665 end;
  1695 end;
  1666 
  1696 
  1667 function lc_setwind(L : Plua_State) : LongInt; Cdecl;
  1697 function lc_setwind(L : Plua_State) : LongInt; Cdecl;
  1668 begin
  1698 begin
  1669     if lua_gettop(L) <> 1 then
  1699     if lua_gettop(L) <> 1 then
  1670         LuaError('Lua: Wrong number of parameters passed to SetWind!')
  1700         LuaParameterCountError('SetWind', 'windSpeed', lua_gettop(L))
  1671     else
  1701     else
  1672         begin
  1702         begin
  1673         cWindSpeed:= int2hwfloat(lua_tointeger(L, 1)) / 100 * cMaxWindSpeed;
  1703         cWindSpeed:= int2hwfloat(lua_tointeger(L, 1)) / 100 * cMaxWindSpeed;
  1674         cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
  1704         cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
  1675         if cWindSpeed.isNegative then
  1705         if cWindSpeed.isNegative then
  1681 
  1711 
  1682 function lc_getdatapath(L : Plua_State) : LongInt; Cdecl;
  1712 function lc_getdatapath(L : Plua_State) : LongInt; Cdecl;
  1683 begin
  1713 begin
  1684     if lua_gettop(L) <> 0 then
  1714     if lua_gettop(L) <> 0 then
  1685         begin
  1715         begin
  1686         LuaError('Lua: Wrong number of parameters passed to GetDataPath!');
  1716         LuaParameterCountError('GetDataPath', '', lua_gettop(L));
  1687         lua_pushnil(L);
  1717         lua_pushnil(L);
  1688         end
  1718         end
  1689     else
  1719     else
  1690         lua_pushstring(L, str2pchar(cPathz[ptData]));
  1720         lua_pushstring(L, str2pchar(cPathz[ptData]));
  1691     lc_getdatapath:= 1
  1721     lc_getdatapath:= 1
  1693 
  1723 
  1694 function lc_getuserdatapath(L : Plua_State) : LongInt; Cdecl;
  1724 function lc_getuserdatapath(L : Plua_State) : LongInt; Cdecl;
  1695 begin
  1725 begin
  1696     if lua_gettop(L) <> 0 then
  1726     if lua_gettop(L) <> 0 then
  1697         begin
  1727         begin
  1698         LuaError('Lua: Wrong number of parameters passed to GetUserDataPath!');
  1728         LuaParameterCountError('GetUserDataPath', '', lua_gettop(L));
  1699         lua_pushnil(L);
  1729         lua_pushnil(L);
  1700         end
  1730         end
  1701     else
  1731     else
  1702         lua_pushstring(L, str2pchar(cPathz[ptData]));
  1732         lua_pushstring(L, str2pchar(cPathz[ptData]));
  1703     lc_getuserdatapath:= 1
  1733     lc_getuserdatapath:= 1
  1705 
  1735 
  1706 function lc_maphasborder(L : Plua_State) : LongInt; Cdecl;
  1736 function lc_maphasborder(L : Plua_State) : LongInt; Cdecl;
  1707 begin
  1737 begin
  1708     if lua_gettop(L) <> 0 then
  1738     if lua_gettop(L) <> 0 then
  1709         begin
  1739         begin
  1710         LuaError('Lua: Wrong number of parameters passed to MapHasBorder!');
  1740         LuaParameterCountError('MapHasBorder', '', lua_gettop(L));
  1711         lua_pushnil(L);
  1741         lua_pushnil(L);
  1712         end
  1742         end
  1713     else
  1743     else
  1714         lua_pushboolean(L, hasBorder);
  1744         lua_pushboolean(L, hasBorder);
  1715     lc_maphasborder:= 1
  1745     lc_maphasborder:= 1
  1718 function lc_getgearradius(L : Plua_State) : LongInt; Cdecl;
  1748 function lc_getgearradius(L : Plua_State) : LongInt; Cdecl;
  1719 var gear : PGear;
  1749 var gear : PGear;
  1720 begin
  1750 begin
  1721     if lua_gettop(L) <> 1 then
  1751     if lua_gettop(L) <> 1 then
  1722         begin
  1752         begin
  1723         LuaError('Lua: Wrong number of parameters passed to GetGearRadius!');
  1753         LuaParameterCountError('GetGearRadius', 'gearUid', lua_gettop(L));
  1724         lua_pushnil(L); // return value on stack (nil)
  1754         lua_pushnil(L); // return value on stack (nil)
  1725         end
  1755         end
  1726     else
  1756     else
  1727         begin
  1757         begin
  1728         gear:= GearByUID(lua_tointeger(L, 1));
  1758         gear:= GearByUID(lua_tointeger(L, 1));
  1736 
  1766 
  1737 function lc_gethoghat(L : Plua_State): LongInt; Cdecl;
  1767 function lc_gethoghat(L : Plua_State): LongInt; Cdecl;
  1738 var gear : PGear;
  1768 var gear : PGear;
  1739 begin
  1769 begin
  1740     if lua_gettop(L) <> 1 then
  1770     if lua_gettop(L) <> 1 then
  1741         LuaError('Lua: Wrong number of parameters passed to GetHogHat!')
  1771         LuaParameterCountError('GetHogHat', 'gearUid', lua_gettop(L))
  1742     else begin
  1772     else begin
  1743         gear := GearByUID(lua_tointeger(L, 1));
  1773         gear := GearByUID(lua_tointeger(L, 1));
  1744         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1774         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
  1745             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Hat))
  1775             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Hat))
  1746         else
  1776         else
  1753 var gear : PGear;
  1783 var gear : PGear;
  1754     hat: ShortString;
  1784     hat: ShortString;
  1755 begin
  1785 begin
  1756     if lua_gettop(L) <> 2 then
  1786     if lua_gettop(L) <> 2 then
  1757         begin
  1787         begin
  1758         LuaError('Lua: Wrong number of parameters passed to SetHogHat!');
  1788         LuaParameterCountError('SetHogHat', 'gearUid, hat', lua_gettop(L));
  1759         lua_pushnil(L)
  1789         lua_pushnil(L)
  1760         end
  1790         end
  1761     else
  1791     else
  1762         begin
  1792         begin
  1763         gear:= GearByUID(lua_tointeger(L, 1));
  1793         gear:= GearByUID(lua_tointeger(L, 1));
  1764         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
  1794         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
       
  1795             begin
  1765             hat:= lua_tostring(L, 2);
  1796             hat:= lua_tostring(L, 2);
  1766             gear^.Hedgehog^.Hat:= hat;
  1797             gear^.Hedgehog^.Hat:= hat;
  1767 AddFileLog('Changed hat to: '+hat);
  1798             AddFileLog('Changed hat to: '+hat);
  1768             if (Length(hat) > 39) and (Copy(hat,1,8) = 'Reserved') and (Copy(hat,9,32) = gear^.Hedgehog^.Team^.PlayerHash) then
  1799             if (Length(hat) > 39) and (Copy(hat,1,8) = 'Reserved') and (Copy(hat,9,32) = gear^.Hedgehog^.Team^.PlayerHash) then
  1769                 LoadHedgehogHat(gear^.Hedgehog^, 'Reserved/' + Copy(hat,9,Length(hat)-8))
  1800                 LoadHedgehogHat(gear^.Hedgehog^, 'Reserved/' + Copy(hat,9,Length(hat)-8))
  1770             else
  1801             else
  1771                 LoadHedgehogHat(gear^.Hedgehog^, hat);
  1802                 LoadHedgehogHat(gear^.Hedgehog^, hat)
       
  1803             end
  1772         end;
  1804         end;
  1773     lc_sethoghat:= 0;
  1805     lc_sethoghat:= 0;
  1774 end;
  1806 end;
  1775 
  1807 
  1776 function lc_placegirder(L : Plua_State) : LongInt; Cdecl;
  1808 function lc_placegirder(L : Plua_State) : LongInt; Cdecl;
  1777 begin
  1809 begin
  1778     if lua_gettop(L) <> 3 then
  1810     if lua_gettop(L) <> 3 then
  1779         LuaError('Lua: Wrong number of parameters passed to PlaceGirder!')
  1811         LuaParameterCountError('PlaceGirder', 'x, y, state', lua_gettop(L))
  1780     else
  1812     else
  1781         TryPlaceOnLand(
  1813         TryPlaceOnLand(
  1782             lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2,
  1814             lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2,
  1783             lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2,
  1815             lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2,
  1784             sprAmGirder, lua_tointeger(L, 3), true, false);
  1816             sprAmGirder, lua_tointeger(L, 3), true, false);
  1786 end;
  1818 end;
  1787 
  1819 
  1788 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
  1820 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
  1789 begin
  1821 begin
  1790     if lua_gettop(L) <> 0 then
  1822     if lua_gettop(L) <> 0 then
  1791         LuaError('Lua: Wrong number of parameters passed to GetCurAmmoType!')
  1823         LuaParameterCountError('GetCurAmmoType', '', lua_gettop(L))
  1792     else
  1824     else
  1793         lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType));
  1825         lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType));
  1794     lc_getcurammotype := 1;
  1826     lc_getcurammotype := 1;
  1795 end;
  1827 end;
  1796 
  1828 
  1797 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl;
  1829 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl;
  1798 begin
  1830 begin
  1799     if lua_gettop(L) <> 2 then
  1831     if lua_gettop(L) <> 2 then
  1800         LuaError('Lua: Wrong number of parameters passed to SaveCampaignVar!')
  1832         LuaParameterCountError('SaveCampaignVar', 'varname, value', lua_gettop(L))
  1801     else begin
  1833     else begin
  1802         SendIPC('V!' + lua_tostring(L, 1) + ' ' + lua_tostring(L, 2) + #0);
  1834         SendIPC('V!' + lua_tostring(L, 1) + ' ' + lua_tostring(L, 2) + #0);
  1803     end;
  1835     end;
  1804     lc_savecampaignvar := 0;
  1836     lc_savecampaignvar := 0;
  1805 end;
  1837 end;
  1806 
  1838 
  1807 function lc_getcampaignvar(L : Plua_State): LongInt; Cdecl;
  1839 function lc_getcampaignvar(L : Plua_State): LongInt; Cdecl;
  1808 begin
  1840 begin
  1809     if (lua_gettop(L) <> 1) then
  1841     if (lua_gettop(L) <> 1) then
  1810         LuaError('Lua: Wrong number of parameters passed to GetCampaignVar!')
  1842         LuaParameterCountError('GetCampaignVar', 'varname', lua_gettop(L))
  1811     else
  1843     else
  1812         SendIPCAndWaitReply('V?' + lua_tostring(L, 1));
  1844         SendIPCAndWaitReply('V?' + lua_tostring(L, 1) + #0);
  1813     lua_pushstring(L, str2pchar(CampaignVariable));
  1845     lua_pushstring(L, str2pchar(CampaignVariable));
  1814     lc_getcampaignvar := 1;
  1846     lc_getcampaignvar := 1;
  1815 end;
  1847 end;
  1816 
  1848 
  1817 function lc_hidehog(L: Plua_State): LongInt; Cdecl;
  1849 function lc_hidehog(L: Plua_State): LongInt; Cdecl;
  1818 var gear: PGear;
  1850 var gear: PGear;
  1819 begin
  1851 begin
  1820     if lua_gettop(L) <> 1 then
  1852     if lua_gettop(L) <> 1 then
  1821         LuaError('Lua: Wrong number of parameters passed to HideHog!')
  1853         LuaParameterCountError('HideHog', 'gearUid', lua_gettop(L))
  1822     else
  1854     else
  1823         begin
  1855         begin
  1824         gear:= GearByUID(lua_tointeger(L, 1));
  1856         gear:= GearByUID(lua_tointeger(L, 1));
  1825         HideHog(gear^.hedgehog)
  1857         HideHog(gear^.hedgehog)
  1826         end;
  1858         end;
  1830 function lc_restorehog(L: Plua_State): LongInt; Cdecl;
  1862 function lc_restorehog(L: Plua_State): LongInt; Cdecl;
  1831 var i, h: LongInt;
  1863 var i, h: LongInt;
  1832     uid: LongWord;
  1864     uid: LongWord;
  1833 begin
  1865 begin
  1834     if lua_gettop(L) <> 1 then
  1866     if lua_gettop(L) <> 1 then
  1835         LuaError('Lua: Wrong number of parameters passed to RestoreHog!')
  1867         LuaParameterCountError('RestoreHog', 'gearUid', lua_gettop(L))
  1836     else
  1868     else
  1837         begin
  1869         begin
  1838         uid:= LongWord(lua_tointeger(L, 1));
  1870         uid:= LongWord(lua_tointeger(L, 1));
  1839         if TeamsCount > 0 then
  1871         if TeamsCount > 0 then
  1840             for i:= 0 to Pred(TeamsCount) do
  1872             for i:= 0 to Pred(TeamsCount) do
  1852 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl;
  1884 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl;
  1853 var rtn: Boolean;
  1885 var rtn: Boolean;
  1854 begin
  1886 begin
  1855     if lua_gettop(L) <> 5 then
  1887     if lua_gettop(L) <> 5 then
  1856         begin
  1888         begin
  1857         LuaError('Lua: Wrong number of parameters passed to TestRectForObstacle!');
  1889         LuaParameterCountError('TestRectForObstacle', 'x1, y1, x2, y2, landOnly', lua_gettop(L));
  1858         lua_pushnil(L); // return value on stack (nil)
  1890         lua_pushnil(L); // return value on stack (nil)
  1859         end
  1891         end
  1860     else
  1892     else
  1861         begin
  1893         begin
  1862         rtn:= TestRectancleForObstacle(
  1894         rtn:= TestRectancleForObstacle(
  1870         end;
  1902         end;
  1871     lc_testrectforobstacle:= 1
  1903     lc_testrectforobstacle:= 1
  1872 end;
  1904 end;
  1873 
  1905 
  1874 
  1906 
       
  1907 function lc_getgravity(L : Plua_State) : LongInt; Cdecl;
       
  1908 begin
       
  1909     if lua_gettop(L) <> 0 then
       
  1910         LuaParameterCountError('GetGravity', '', lua_gettop(L))
       
  1911     else
       
  1912         lua_pushinteger(L, hwRound(cGravity * 50 / cWindSpeed));
       
  1913     lc_getgravity:= 1
       
  1914 end;
       
  1915 
       
  1916 function lc_setgravity(L : Plua_State) : LongInt; Cdecl;
       
  1917 begin
       
  1918     if lua_gettop(L) <> 1 then
       
  1919         LuaParameterCountError('SetGravity', 'gravity', lua_gettop(L))
       
  1920     else
       
  1921         begin
       
  1922         cGravity:= cMaxWindSpeed * lua_tointeger(L, 1) * _0_02;
       
  1923         cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02
       
  1924         end;
       
  1925     lc_setgravity:= 0
       
  1926 end;
       
  1927 
       
  1928 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl;
       
  1929 var iterator: PGear;
       
  1930 begin
       
  1931     if lua_gettop(L) <> 1 then
       
  1932          LuaParameterCountError('SetWaterLine', 'waterline', lua_gettop(L))
       
  1933     else
       
  1934         begin
       
  1935         cWaterLine:= lua_tointeger(L,1);
       
  1936         AllInactive:= false;
       
  1937         iterator:= GearsList;
       
  1938         while iterator <> nil do
       
  1939             begin
       
  1940             if not (iterator^.Kind in [gtPortal, gtAirAttack]) and (iterator^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) then
       
  1941                 begin
       
  1942                 iterator^.Active:= true;
       
  1943                 if iterator^.dY.QWordValue = 0 then iterator^.dY.isNegative:= false;
       
  1944                 iterator^.State:= iterator^.State or gstMoving;
       
  1945                 DeleteCI(iterator)
       
  1946                 end;
       
  1947             iterator:= iterator^.NextGear
       
  1948             end
       
  1949         end;
       
  1950     lc_setwaterline:= 0
       
  1951 end;
       
  1952 
  1875 function lc_setaihintsongear(L : Plua_State) : LongInt; Cdecl;
  1953 function lc_setaihintsongear(L : Plua_State) : LongInt; Cdecl;
  1876 var gear: PGear;
  1954 var gear: PGear;
  1877 begin
  1955 begin
  1878     if lua_gettop(L) <> 2 then
  1956     if lua_gettop(L) <> 2 then
  1879         LuaError('Lua: Wrong number of parameters passed to SetAIHintOnGear!')
  1957         LuaParameterCountError('SetAIHintOnGear', 'gearUid, aiHints', lua_gettop(L))
  1880     else
  1958     else
  1881         begin
  1959         begin
  1882         gear:= GearByUID(lua_tointeger(L, 1));
  1960         gear:= GearByUID(lua_tointeger(L, 1));
  1883         if gear <> nil then
  1961         if gear <> nil then
  1884             gear^.aihints:= lua_tointeger(L, 2);
  1962             gear^.aihints:= lua_tointeger(L, 2);
  1889 
  1967 
  1890 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl;
  1968 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl;
  1891 begin
  1969 begin
  1892     if lua_gettop(L) <> 1 then
  1970     if lua_gettop(L) <> 1 then
  1893         begin
  1971         begin
  1894         LuaError('Lua: Wrong number of parameters passed to HedgewarsScriptLoad!');
  1972         LuaParameterCountError('HedgewarsScriptLoad', 'scriptPath', lua_gettop(L));
  1895         lua_pushnil(L)
  1973         lua_pushnil(L)
  1896         end
  1974         end
  1897     else
  1975     else
  1898         ScriptLoad(lua_tostring(L, 1));
  1976         ScriptLoad(lua_tostring(L, 1));
  1899     lc_hedgewarsscriptload:= 0;
  1977     lc_hedgewarsscriptload:= 0;
  1900 end;
  1978 end;
  1901 
  1979 
  1902 
  1980 
  1903 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
  1981 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
  1904 var gear: PGear;
       
  1905 begin
  1982 begin
  1906     if lua_gettop(L) <> 4 then
  1983     if lua_gettop(L) <> 4 then
  1907         LuaError('Lua: Wrong number of parameters passed to DeclareAchievement!')
  1984         LuaParameterCountError('DeclareAchievement', 'achievementId, teamname, location, value', lua_gettop(L))
  1908     else
  1985     else
  1909         declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4));
  1986         declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4));
  1910     lc_declareachievement:= 0
  1987     lc_declareachievement:= 0
  1911 end;
  1988 end;
  1912 ///////////////////
  1989 ///////////////////
  1991 ScriptSetInteger('Delay', cInactDelay);
  2068 ScriptSetInteger('Delay', cInactDelay);
  1992 ScriptSetInteger('Ready', cReadyDelay);
  2069 ScriptSetInteger('Ready', cReadyDelay);
  1993 ScriptSetInteger('SuddenDeathTurns', cSuddenDTurns);
  2070 ScriptSetInteger('SuddenDeathTurns', cSuddenDTurns);
  1994 ScriptSetInteger('WaterRise', cWaterRise);
  2071 ScriptSetInteger('WaterRise', cWaterRise);
  1995 ScriptSetInteger('HealthDecrease', cHealthDecrease);
  2072 ScriptSetInteger('HealthDecrease', cHealthDecrease);
       
  2073 ScriptSetInteger('GetAwayTime', cGetAwayTime);
  1996 ScriptSetString('Map', cMapName);
  2074 ScriptSetString('Map', cMapName);
  1997 
       
  1998 ScriptSetString('Theme', '');
  2075 ScriptSetString('Theme', '');
  1999 ScriptSetString('Goals', '');
  2076 ScriptSetString('Goals', '');
       
  2077 ScriptSetString('ScriptParam', cScriptParam);
  2000 
  2078 
  2001 ScriptCall('onGameInit');
  2079 ScriptCall('onGameInit');
  2002 
  2080 
  2003 // pop game variables
  2081 // pop game variables
  2004 ParseCommand('seed ' + ScriptGetString('Seed'), true, true);
  2082 ParseCommand('seed ' + ScriptGetString('Seed'), true, true);
  2019 cInactDelay      := ScriptGetInteger('Delay');
  2097 cInactDelay      := ScriptGetInteger('Delay');
  2020 cReadyDelay      := ScriptGetInteger('Ready');
  2098 cReadyDelay      := ScriptGetInteger('Ready');
  2021 cSuddenDTurns    := ScriptGetInteger('SuddenDeathTurns');
  2099 cSuddenDTurns    := ScriptGetInteger('SuddenDeathTurns');
  2022 cWaterRise       := ScriptGetInteger('WaterRise');
  2100 cWaterRise       := ScriptGetInteger('WaterRise');
  2023 cHealthDecrease  := ScriptGetInteger('HealthDecrease');
  2101 cHealthDecrease  := ScriptGetInteger('HealthDecrease');
       
  2102 cGetAwayTime     := ScriptGetInteger('GetAwayTime');
  2024 
  2103 
  2025 if cMapName <> ScriptGetString('Map') then
  2104 if cMapName <> ScriptGetString('Map') then
  2026     ParseCommand('map ' + ScriptGetString('Map'), true, true);
  2105     ParseCommand('map ' + ScriptGetString('Map'), true, true);
  2027 if ScriptGetString('Theme') <> '' then
  2106 if ScriptGetString('Theme') <> '' then
  2028     ParseCommand('theme ' + ScriptGetString('Theme'), true, true);
  2107     ParseCommand('theme ' + ScriptGetString('Theme'), true, true);
  2067         end;
  2146         end;
  2068     ScriptApplyAmmoStore
  2147     ScriptApplyAmmoStore
  2069     end;
  2148     end;
  2070 
  2149 
  2071 ScriptSetInteger('ClansCount', ClansCount);
  2150 ScriptSetInteger('ClansCount', ClansCount);
  2072 ScriptSetInteger('TeamsCount', TeamsCount)
  2151 ScriptSetInteger('TeamsCount', TeamsCount);
       
  2152 mapDims:= false
  2073 end;
  2153 end;
  2074 
  2154 
  2075 
  2155 
  2076 // Update values of screen dimensions and allow script to react to resolution change
  2156 // Update values of screen dimensions and allow script to react to resolution change
  2077 procedure ScriptOnScreenResize();
  2157 procedure ScriptOnScreenResize();
  2090       f : PFSFile;
  2170       f : PFSFile;
  2091     buf : array[0..Pred(BUFSIZE)] of byte;
  2171     buf : array[0..Pred(BUFSIZE)] of byte;
  2092 begin
  2172 begin
  2093 s:= cPathz[ptData] + name;
  2173 s:= cPathz[ptData] + name;
  2094 if not pfsExists(s) then
  2174 if not pfsExists(s) then
       
  2175     begin
       
  2176     AddFileLog('[LUA] Script not found: ' + name);
  2095     exit;
  2177     exit;
       
  2178     end;
  2096 
  2179 
  2097 f:= pfsOpenRead(s);
  2180 f:= pfsOpenRead(s);
  2098 if f = nil then
  2181 if f = nil then
  2099     exit;
  2182     exit;
  2100 
  2183 
  2121 begin
  2204 begin
  2122 ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
  2205 ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
  2123 ScriptSetInteger('GameTime', GameTicks);
  2206 ScriptSetInteger('GameTime', GameTicks);
  2124 ScriptSetInteger('TotalRounds', TotalRounds);
  2207 ScriptSetInteger('TotalRounds', TotalRounds);
  2125 ScriptSetInteger('WaterLine', cWaterLine);
  2208 ScriptSetInteger('WaterLine', cWaterLine);
  2126 if GameTicks = 0 then
  2209 if not mapDims then
  2127     begin
  2210     begin
       
  2211     mapDims:= true;
  2128     ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
  2212     ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
  2129     ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT);
  2213     ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT);
  2130     ScriptSetInteger('LeftX', leftX);
  2214     ScriptSetInteger('LeftX', leftX);
  2131     ScriptSetInteger('RightX', rightX);
  2215     ScriptSetInteger('RightX', rightX);
  2132     ScriptSetInteger('TopY', topY)
  2216     ScriptSetInteger('TopY', topY)
  2243     ScriptAmmoDelay:= ScriptAmmoDelay + '0';
  2327     ScriptAmmoDelay:= ScriptAmmoDelay + '0';
  2244     ScriptAmmoReinforcement:= ScriptAmmoReinforcement + '0';
  2328     ScriptAmmoReinforcement:= ScriptAmmoReinforcement + '0';
  2245     end;
  2329     end;
  2246 end;
  2330 end;
  2247 
  2331 
  2248 procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay, reinforcement: Byte);
  2332 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte);
  2249 begin
  2333 begin
  2250 //if (ord(ammo) < 1) or (count > 9) or (count < 0) or (propability < 0) or (propability > 8) or (delay < 0) or (delay > 9) or (reinforcement < 0) or (reinforcement > 8) then
  2334 //if (ord(ammo) < 1) or (count > 9) or (count < 0) or (probability < 0) or (probability > 8) or (delay < 0) or (delay > 9) or (reinforcement < 0) or (reinforcement > 8) then
  2251 if (ord(ammo) < 1) or (count > 9) or (propability > 8) or (delay > 9) or (reinforcement > 8) then
  2335 if (ord(ammo) < 1) or (count > 9) or (probability > 8) or (delay > 9) or (reinforcement > 8) then
  2252     exit;
  2336     exit;
  2253 ScriptAmmoLoadout[ord(ammo)]:= inttostr(count)[1];
  2337 ScriptAmmoLoadout[ord(ammo)]:= inttostr(count)[1];
  2254 ScriptAmmoProbability[ord(ammo)]:= inttostr(propability)[1];
  2338 ScriptAmmoProbability[ord(ammo)]:= inttostr(probability)[1];
  2255 ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1];
  2339 ScriptSetAmmoDelay(ammo, delay);
  2256 ScriptAmmoReinforcement[ord(ammo)]:= inttostr(reinforcement)[1];
  2340 ScriptAmmoReinforcement[ord(ammo)]:= inttostr(reinforcement)[1];
       
  2341 end;
       
  2342 
       
  2343 procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte);
       
  2344 begin
       
  2345 // change loadout string if ammo store hasn't been initialized yet
       
  2346 if (StoreCnt = 0) then
       
  2347 begin
       
  2348     if (delay <= 9) then
       
  2349         ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1];
       
  2350 end
       
  2351 // change "live" delay values
       
  2352 else if (CurrentTeam <> nil) then
       
  2353         ammoz[ammo].SkipTurns:= CurrentTeam^.Clan^.TurnNumber + delay;
  2257 end;
  2354 end;
  2258 
  2355 
  2259 procedure ScriptApplyAmmoStore;
  2356 procedure ScriptApplyAmmoStore;
  2260 var i, j, k : LongInt;
  2357 var i, j, k : LongInt;
  2261 begin
  2358 begin
  2312 
  2409 
  2313 procedure initModule;
  2410 procedure initModule;
  2314 var at : TGearType;
  2411 var at : TGearType;
  2315     vgt: TVisualGearType;
  2412     vgt: TVisualGearType;
  2316     am : TAmmoType;
  2413     am : TAmmoType;
       
  2414     si : TStatInfoType;
  2317     st : TSound;
  2415     st : TSound;
  2318     he : THogEffect;
  2416     he : THogEffect;
  2319     cg : TCapGroup;
  2417     cg : TCapGroup;
  2320 begin
  2418 begin
  2321 // initialize lua
  2419 // initialize lua
  2374 ScriptSetInteger('gmTimer', gmTimer);
  2472 ScriptSetInteger('gmTimer', gmTimer);
  2375 ScriptSetInteger('gmAnimate', gmAnimate);
  2473 ScriptSetInteger('gmAnimate', gmAnimate);
  2376 ScriptSetInteger('gmPrecise', gmPrecise);
  2474 ScriptSetInteger('gmPrecise', gmPrecise);
  2377 ScriptSetInteger('gmAllStoppable', gmAllStoppable);
  2475 ScriptSetInteger('gmAllStoppable', gmAllStoppable);
  2378 
  2476 
  2379 
       
  2380 // speech bubbles
  2477 // speech bubbles
  2381 ScriptSetInteger('SAY_SAY', 1);
  2478 ScriptSetInteger('SAY_SAY', 1);
  2382 ScriptSetInteger('SAY_THINK', 2);
  2479 ScriptSetInteger('SAY_THINK', 2);
  2383 ScriptSetInteger('SAY_SHOUT', 3);
  2480 ScriptSetInteger('SAY_SHOUT', 3);
  2384 
  2481 
  2394     ScriptSetInteger(EnumToStr(st), ord(st));
  2491     ScriptSetInteger(EnumToStr(st), ord(st));
  2395 
  2492 
  2396 // register ammo types
  2493 // register ammo types
  2397 for am:= Low(TAmmoType) to High(TAmmoType) do
  2494 for am:= Low(TAmmoType) to High(TAmmoType) do
  2398     ScriptSetInteger(EnumToStr(am), ord(am));
  2495     ScriptSetInteger(EnumToStr(am), ord(am));
       
  2496 
       
  2497 for si:= Low(TStatInfoType) to High(TStatInfoType) do
       
  2498     ScriptSetInteger(EnumToStr(si), ord(si));
  2399 
  2499 
  2400 for he:= Low(THogEffect) to High(THogEffect) do
  2500 for he:= Low(THogEffect) to High(THogEffect) do
  2401     ScriptSetInteger(EnumToStr(he), ord(he));
  2501     ScriptSetInteger(EnumToStr(he), ord(he));
  2402 
  2502 
  2403 for cg:= Low(TCapGroup) to High(TCapGroup) do
  2503 for cg:= Low(TCapGroup) to High(TCapGroup) do
  2469 lua_register(luaState, _P'ParseCommand', @lc_parsecommand);
  2569 lua_register(luaState, _P'ParseCommand', @lc_parsecommand);
  2470 lua_register(luaState, _P'ShowMission', @lc_showmission);
  2570 lua_register(luaState, _P'ShowMission', @lc_showmission);
  2471 lua_register(luaState, _P'HideMission', @lc_hidemission);
  2571 lua_register(luaState, _P'HideMission', @lc_hidemission);
  2472 lua_register(luaState, _P'AddCaption', @lc_addcaption);
  2572 lua_register(luaState, _P'AddCaption', @lc_addcaption);
  2473 lua_register(luaState, _P'SetAmmo', @lc_setammo);
  2573 lua_register(luaState, _P'SetAmmo', @lc_setammo);
       
  2574 lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
  2474 lua_register(luaState, _P'SetAmmoStore', @lc_setammostore);
  2575 lua_register(luaState, _P'SetAmmoStore', @lc_setammostore);
  2475 lua_register(luaState, _P'PlaySound', @lc_playsound);
  2576 lua_register(luaState, _P'PlaySound', @lc_playsound);
  2476 lua_register(luaState, _P'AddTeam', @lc_addteam);
  2577 lua_register(luaState, _P'AddTeam', @lc_addteam);
  2477 lua_register(luaState, _P'AddHog', @lc_addhog);
  2578 lua_register(luaState, _P'AddHog', @lc_addhog);
  2478 lua_register(luaState, _P'AddAmmo', @lc_addammo);
  2579 lua_register(luaState, _P'AddAmmo', @lc_addammo);
  2483 lua_register(luaState, _P'GetEffect', @lc_geteffect);
  2584 lua_register(luaState, _P'GetEffect', @lc_geteffect);
  2484 lua_register(luaState, _P'GetHogClan', @lc_gethogclan);
  2585 lua_register(luaState, _P'GetHogClan', @lc_gethogclan);
  2485 lua_register(luaState, _P'GetClanColor', @lc_getclancolor);
  2586 lua_register(luaState, _P'GetClanColor', @lc_getclancolor);
  2486 lua_register(luaState, _P'SetClanColor', @lc_setclancolor);
  2587 lua_register(luaState, _P'SetClanColor', @lc_setclancolor);
  2487 lua_register(luaState, _P'GetHogTeamName', @lc_gethogteamname);
  2588 lua_register(luaState, _P'GetHogTeamName', @lc_gethogteamname);
       
  2589 lua_register(luaState, _P'SetHogTeamName', @lc_sethogteamname);
  2488 lua_register(luaState, _P'GetHogName', @lc_gethogname);
  2590 lua_register(luaState, _P'GetHogName', @lc_gethogname);
  2489 lua_register(luaState, _P'SetHogName', @lc_sethogname);
  2591 lua_register(luaState, _P'SetHogName', @lc_sethogname);
  2490 lua_register(luaState, _P'GetHogLevel', @lc_gethoglevel);
  2592 lua_register(luaState, _P'GetHogLevel', @lc_gethoglevel);
  2491 lua_register(luaState, _P'SetHogLevel', @lc_sethoglevel);
  2593 lua_register(luaState, _P'SetHogLevel', @lc_sethoglevel);
  2492 lua_register(luaState, _P'GetX', @lc_getx);
  2594 lua_register(luaState, _P'GetX', @lc_getx);
  2523 lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
  2625 lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
  2524 lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
  2626 lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
  2525 lua_register(luaState, _P'PlaceGirder', @lc_placegirder);
  2627 lua_register(luaState, _P'PlaceGirder', @lc_placegirder);
  2526 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);
  2628 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);
  2527 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle);
  2629 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle);
       
  2630 lua_register(luaState, _P'GetGravity', @lc_getgravity);
       
  2631 lua_register(luaState, _P'SetGravity', @lc_setgravity);
       
  2632 lua_register(luaState, _P'SetWaterLine', @lc_setwaterline);
  2528 
  2633 
  2529 lua_register(luaState, _P'SetGearAIHints', @lc_setaihintsongear);
  2634 lua_register(luaState, _P'SetGearAIHints', @lc_setaihintsongear);
  2530 lua_register(luaState, _P'HedgewarsScriptLoad', @lc_hedgewarsscriptload);
  2635 lua_register(luaState, _P'HedgewarsScriptLoad', @lc_hedgewarsscriptload);
  2531 lua_register(luaState, _P'DeclareAchievement', @lc_declareachievement);
  2636 lua_register(luaState, _P'DeclareAchievement', @lc_declareachievement);
  2532 
  2637 
  2620 begin
  2725 begin
  2621 end;
  2726 end;
  2622 
  2727 
  2623 procedure initModule;
  2728 procedure initModule;
  2624 begin
  2729 begin
       
  2730 mapDims:= false;
  2625 end;
  2731 end;
  2626 
  2732 
  2627 procedure freeModule;
  2733 procedure freeModule;
  2628 begin
  2734 begin
  2629 end;
  2735 end;