changeset 10297 | e5ed72b40c57 |
parent 10295 | ec6b68241575 |
child 10306 | 4fca8bcfaff0 |
10296:fbc5f217f291 | 10297:e5ed72b40c57 |
---|---|
113 |
113 |
114 if lua_getstack(luaState, 1, @LuaDebugInfo) = 0 then |
114 if lua_getstack(luaState, 1, @LuaDebugInfo) = 0 then |
115 exit(false); // stack not deep enough |
115 exit(false); // stack not deep enough |
116 |
116 |
117 // get source name and line count |
117 // get source name and line count |
118 lua_getinfo(luaState, 'Sl', @LuaDebugInfo); |
118 lua_getinfo(luaState, PChar('Sl'), @LuaDebugInfo); |
119 exit(true); |
119 exit(true); |
120 end; |
120 end; |
121 |
121 |
122 procedure LuaError(s: shortstring); |
122 procedure LuaError(s: shortstring); |
123 var src: shortstring; |
123 var src: shortstring; |
150 // TODO: i18n? |
150 // TODO: i18n? |
151 LuaCallError('Wrong number of parameters! (is: ' + inttostr(wrongcount) + ', should be: '+ expected + ')', call, paramsyntax); |
151 LuaCallError('Wrong number of parameters! (is: ' + inttostr(wrongcount) + ', should be: '+ expected + ')', call, paramsyntax); |
152 end; |
152 end; |
153 |
153 |
154 // compare with allowed count |
154 // compare with allowed count |
155 function CheckLuaParameterCount(L : Plua_State; count: LongInt; call, paramsyntax: shortstring): boolean; inline; |
155 function CheckLuaParamCount(L : Plua_State; count: LongInt; call, paramsyntax: shortstring): boolean; inline; |
156 var c: LongInt; |
156 var c: LongInt; |
157 begin |
157 begin |
158 c:= lua_gettop(L); |
158 c:= lua_gettop(L); |
159 if c <> count then |
159 if c <> count then |
160 begin |
160 begin |
161 LuaParameterCountError('exactly ' + inttostr(count), call, paramsyntax, c); |
161 LuaParameterCountError('exactly ' + inttostr(count), call, paramsyntax, c); |
162 exit(false); |
162 exit(false); |
163 end; |
163 end; |
164 |
164 |
165 CheckLuaParameterCount:= true; |
165 CheckLuaParamCount:= true; |
166 end; |
166 end; |
167 |
167 |
168 // check if is either count1 or count2 |
168 // check if is either count1 or count2 |
169 function CheckAndFetchLuaParameterCount(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline; |
169 function CheckAndFetchParamCount(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline; |
170 begin |
170 begin |
171 actual:= lua_gettop(L); |
171 actual:= lua_gettop(L); |
172 if (actual <> count1) and (actual <> count2) then |
172 if (actual <> count1) and (actual <> count2) then |
173 begin |
173 begin |
174 LuaParameterCountError('either ' + inttostr(count1) + ' or ' + inttostr(count2), call, paramsyntax, actual); |
174 LuaParameterCountError('either ' + inttostr(count1) + ' or ' + inttostr(count2), call, paramsyntax, actual); |
175 exit(false); |
175 exit(false); |
176 end; |
176 end; |
177 |
177 |
178 CheckAndFetchLuaParameterCount:= true; |
178 CheckAndFetchParamCount:= true; |
179 end; |
179 end; |
180 |
180 |
181 // check if is same or higher as minCount |
181 // check if is same or higher as minCount |
182 function CheckAndFetchLuaParameterCount(L : Plua_State; minCount: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline; |
182 function CheckAndFetchLuaParamMinCount(L : Plua_State; minCount: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline; |
183 begin |
183 begin |
184 actual:= lua_gettop(L); |
184 actual:= lua_gettop(L); |
185 if (actual < minCount) then |
185 if (actual < minCount) then |
186 begin |
186 begin |
187 LuaParameterCountError(inttostr(minCount) + ' or more', call, paramsyntax, actual); |
187 LuaParameterCountError(inttostr(minCount) + ' or more', call, paramsyntax, actual); |
188 exit(false); |
188 exit(false); |
189 end; |
189 end; |
190 |
190 |
191 CheckAndFetchLuaParameterCount:= true; |
191 CheckAndFetchLuaParamMinCount:= true; |
192 end; |
192 end; |
193 |
193 |
194 function LuaToGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; |
194 function LuaToGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; |
195 begin |
195 begin |
196 if lua_isnoneornil(L, i) then i:= -1 |
196 if lua_isnoneornil(L, i) then i:= -1 |
298 // wrapped calls // |
298 // wrapped calls // |
299 |
299 |
300 // functions called from Lua: |
300 // functions called from Lua: |
301 // function(L : Plua_State) : LongInt; Cdecl; |
301 // function(L : Plua_State) : LongInt; Cdecl; |
302 // where L contains the state, returns the number of return values on the stack |
302 // where L contains the state, returns the number of return values on the stack |
303 // call CheckLuaParameterCount or CheckAndFetchLuaParameterCount |
303 // call CheckLuaParamCount or CheckAndFetchParamCount |
304 // to validate/get the number of passed arguments (see their call definitions) |
304 // to validate/get the number of passed arguments (see their call definitions) |
305 // |
305 // |
306 // use as return value the number of variables pushed back to the lua script |
306 // use as return value the number of variables pushed back to the lua script |
307 |
307 |
308 function lc_band(L: PLua_State): LongInt; Cdecl; |
308 function lc_band(L: PLua_State): LongInt; Cdecl; |
309 begin |
309 begin |
310 if CheckLuaParameterCount(L, 2, 'band', 'value1, value2') then |
310 if CheckLuaParamCount(L, 2, 'band', 'value1, value2') then |
311 lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)) |
311 lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)) |
312 else |
312 else |
313 lua_pushnil(L); |
313 lua_pushnil(L); |
314 lc_band := 1; |
314 lc_band := 1; |
315 end; |
315 end; |
316 |
316 |
317 function lc_bor(L: PLua_State): LongInt; Cdecl; |
317 function lc_bor(L: PLua_State): LongInt; Cdecl; |
318 begin |
318 begin |
319 if CheckLuaParameterCount(L, 2, 'bor', 'value1, value2') then |
319 if CheckLuaParamCount(L, 2, 'bor', 'value1, value2') then |
320 lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)) |
320 lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)) |
321 else |
321 else |
322 lua_pushnil(L); |
322 lua_pushnil(L); |
323 lc_bor := 1; |
323 lc_bor := 1; |
324 end; |
324 end; |
325 |
325 |
326 function lc_bnot(L: PLua_State): LongInt; Cdecl; |
326 function lc_bnot(L: PLua_State): LongInt; Cdecl; |
327 begin |
327 begin |
328 if CheckLuaParameterCount(L, 1, 'bnot', 'value') then |
328 if CheckLuaParamCount(L, 1, 'bnot', 'value') then |
329 lua_pushinteger(L, (not lua_tointeger(L, 1))) |
329 lua_pushinteger(L, (not lua_tointeger(L, 1))) |
330 else |
330 else |
331 lua_pushnil(L); |
331 lua_pushnil(L); |
332 lc_bnot := 1; |
332 lc_bnot := 1; |
333 end; |
333 end; |
334 |
334 |
335 function lc_div(L: PLua_State): LongInt; Cdecl; |
335 function lc_div(L: PLua_State): LongInt; Cdecl; |
336 begin |
336 begin |
337 if CheckLuaParameterCount(L, 2, 'div', 'dividend, divisor') then |
337 if CheckLuaParamCount(L, 2, 'div', 'dividend, divisor') then |
338 lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2)) |
338 lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2)) |
339 else |
339 else |
340 lua_pushnil(L); |
340 lua_pushnil(L); |
341 lc_div := 1; |
341 lc_div := 1; |
342 end; |
342 end; |
343 |
343 |
344 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl; |
344 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl; |
345 begin |
345 begin |
346 if CheckLuaParameterCount(L, 0, 'GetInputMask', '') then |
346 if CheckLuaParamCount(L, 0, 'GetInputMask', '') then |
347 lua_pushinteger(L, InputMask); |
347 lua_pushinteger(L, InputMask); |
348 lc_getinputmask:= 1 |
348 lc_getinputmask:= 1 |
349 end; |
349 end; |
350 |
350 |
351 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl; |
351 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl; |
352 begin |
352 begin |
353 if CheckLuaParameterCount(L, 1, 'SetInputMask', 'mask') then |
353 if CheckLuaParamCount(L, 1, 'SetInputMask', 'mask') then |
354 InputMask:= lua_tointeger(L, 1); |
354 InputMask:= lua_tointeger(L, 1); |
355 lc_setinputmask:= 0 |
355 lc_setinputmask:= 0 |
356 end; |
356 end; |
357 |
357 |
358 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; |
358 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; |
359 begin |
359 begin |
360 if CheckLuaParameterCount(L, 1, 'WriteLnToConsole', 'string') then |
360 if CheckLuaParamCount(L, 1, 'WriteLnToConsole', 'string') then |
361 WriteLnToConsole('Lua: ' + lua_tostring(L ,1)); |
361 WriteLnToConsole('Lua: ' + lua_tostring(L ,1)); |
362 lc_writelntoconsole:= 0; |
362 lc_writelntoconsole:= 0; |
363 end; |
363 end; |
364 |
364 |
365 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; |
365 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; |
366 var t: PChar; |
366 var t: PChar; |
367 i,c: LongWord; |
367 i,c: LongWord; |
368 s: shortstring; |
368 s: shortstring; |
369 begin |
369 begin |
370 if CheckLuaParameterCount(L, 1, 'ParseCommand', 'string') then |
370 if CheckLuaParamCount(L, 1, 'ParseCommand', 'string') then |
371 begin |
371 begin |
372 t:= lua_tolstring(L, 1, Psize_t(@c)); |
372 t:= lua_tolstring(L, 1, Psize_t(@c)); |
373 |
373 |
374 for i:= 1 to c do s[i]:= t[i-1]; |
374 for i:= 1 to c do s[i]:= t[i-1]; |
375 s[0]:= char(c); |
375 s[0]:= char(c); |
386 const |
386 const |
387 call = 'SetWeapon'; |
387 call = 'SetWeapon'; |
388 params = 'ammoType'; |
388 params = 'ammoType'; |
389 begin |
389 begin |
390 // no point to run this without any CurrentHedgehog |
390 // no point to run this without any CurrentHedgehog |
391 if (CurrentHedgehog <> nil) and (CheckLuaParameterCount(L, 1, call, params)) then |
391 if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 1, call, params)) then |
392 begin |
392 begin |
393 at:= LuaToAmmoTypeOrd(L, 1, call, params); |
393 at:= LuaToAmmoTypeOrd(L, 1, call, params); |
394 if at >= 0 then |
394 if at >= 0 then |
395 ParseCommand('setweap ' + char(at), true, true); |
395 ParseCommand('setweap ' + char(at), true, true); |
396 end; |
396 end; |
404 s, a, cs, fa: LongInt; |
404 s, a, cs, fa: LongInt; |
405 const |
405 const |
406 call = 'SetNextWeapon'; |
406 call = 'SetNextWeapon'; |
407 params = ''; |
407 params = ''; |
408 begin |
408 begin |
409 if (CurrentHedgehog <> nil) and (CheckLuaParameterCount(L, 0, call, params)) then |
409 if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, call, params)) then |
410 begin |
410 begin |
411 at:= -1; |
411 at:= -1; |
412 with CurrentHedgehog^ do |
412 with CurrentHedgehog^ do |
413 begin |
413 begin |
414 cs:= 0; // current slot |
414 cs:= 0; // current slot |
461 lc_setnextweapon:= 0; |
461 lc_setnextweapon:= 0; |
462 end; |
462 end; |
463 |
463 |
464 function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
464 function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
465 begin |
465 begin |
466 if CheckLuaParameterCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then |
466 if CheckLuaParamCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then |
467 ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5)); |
467 ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5)); |
468 lc_showmission:= 0; |
468 lc_showmission:= 0; |
469 end; |
469 end; |
470 |
470 |
471 function lc_hidemission(L : Plua_State) : LongInt; Cdecl; |
471 function lc_hidemission(L : Plua_State) : LongInt; Cdecl; |
477 |
477 |
478 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl; |
478 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl; |
479 var i, n : integer; |
479 var i, n : integer; |
480 begin |
480 begin |
481 // can have 1 or more arguments |
481 // can have 1 or more arguments |
482 if CheckAndFetchLuaParameterCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then |
482 if CheckAndFetchLuaParamMinCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then |
483 begin |
483 begin |
484 for i:= 1 to n do |
484 for i:= 1 to n do |
485 GameFlags := GameFlags or LongWord(lua_tointeger(L, i)); |
485 GameFlags := GameFlags or LongWord(lua_tointeger(L, i)); |
486 ScriptSetInteger('GameFlags', GameFlags); |
486 ScriptSetInteger('GameFlags', GameFlags); |
487 end; |
487 end; |
490 |
490 |
491 function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl; |
491 function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl; |
492 var i , n: integer; |
492 var i , n: integer; |
493 begin |
493 begin |
494 // can have 1 or more arguments |
494 // can have 1 or more arguments |
495 if CheckAndFetchLuaParameterCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then |
495 if CheckAndFetchLuaParamMinCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then |
496 begin |
496 begin |
497 for i:= 1 to n do |
497 for i:= 1 to n do |
498 GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i))); |
498 GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i))); |
499 ScriptSetInteger('GameFlags', GameFlags); |
499 ScriptSetInteger('GameFlags', GameFlags); |
500 end; |
500 end; |
501 lc_disablegameflags:= 0; |
501 lc_disablegameflags:= 0; |
502 end; |
502 end; |
503 |
503 |
504 function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl; |
504 function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl; |
505 begin |
505 begin |
506 if CheckLuaParameterCount(L, 0, 'ClearGameFlags', '') then |
506 if CheckLuaParamCount(L, 0, 'ClearGameFlags', '') then |
507 begin |
507 begin |
508 GameFlags:= 0; |
508 GameFlags:= 0; |
509 ScriptSetInteger('GameFlags', GameFlags); |
509 ScriptSetInteger('GameFlags', GameFlags); |
510 end; |
510 end; |
511 lc_cleargameflags:= 0; |
511 lc_cleargameflags:= 0; |
512 end; |
512 end; |
513 |
513 |
514 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl; |
514 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl; |
515 begin |
515 begin |
516 if CheckLuaParameterCount(L, 1, 'GetGameFlag', 'gameflag') then |
516 if CheckLuaParamCount(L, 1, 'GetGameFlag', 'gameflag') then |
517 lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0)) |
517 lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0)) |
518 else |
518 else |
519 lua_pushnil(L); |
519 lua_pushnil(L); |
520 lc_getgameflag:= 1; |
520 lc_getgameflag:= 1; |
521 end; |
521 end; |
524 var cg: LongInt; |
524 var cg: LongInt; |
525 const |
525 const |
526 call = 'AddCaption'; |
526 call = 'AddCaption'; |
527 params = 'text [, color, captiongroup]'; |
527 params = 'text [, color, captiongroup]'; |
528 begin |
528 begin |
529 if CheckAndFetchLuaParameterCount(L, 1, 3, call, params, cg) then |
529 if CheckAndFetchParamCount(L, 1, 3, call, params, cg) then |
530 begin |
530 begin |
531 if cg = 1 then |
531 if cg = 1 then |
532 AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage) |
532 AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage) |
533 else |
533 else |
534 begin |
534 begin |
540 lc_addcaption:= 0; |
540 lc_addcaption:= 0; |
541 end; |
541 end; |
542 |
542 |
543 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl; |
543 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl; |
544 begin |
544 begin |
545 if CheckLuaParameterCount(L, 1, 'CampaignLock', 'TODO') then |
545 if CheckLuaParamCount(L, 1, 'CampaignLock', 'TODO') then |
546 begin |
546 begin |
547 // TODO |
547 // TODO |
548 end; |
548 end; |
549 lc_campaignlock:= 0; |
549 lc_campaignlock:= 0; |
550 end; |
550 end; |
551 |
551 |
552 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl; |
552 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl; |
553 begin |
553 begin |
554 if CheckLuaParameterCount(L, 1, 'CampaignUnlock', 'TODO') then |
554 if CheckLuaParamCount(L, 1, 'CampaignUnlock', 'TODO') then |
555 begin |
555 begin |
556 // TODO |
556 // TODO |
557 end; |
557 end; |
558 lc_campaignunlock:= 0; |
558 lc_campaignunlock:= 0; |
559 end; |
559 end; |
560 |
560 |
561 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl; |
561 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl; |
562 var gear: PGear; |
562 var gear: PGear; |
563 begin |
563 begin |
564 if CheckLuaParameterCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then |
564 if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then |
565 begin |
565 begin |
566 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
566 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
567 HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
567 HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
568 lua_pushinteger(L, gear^.uid); |
568 lua_pushinteger(L, gear^.uid); |
569 end |
569 end |
573 end; |
573 end; |
574 |
574 |
575 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl; |
575 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl; |
576 var gear: PGear; |
576 var gear: PGear; |
577 begin |
577 begin |
578 if CheckLuaParameterCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then |
578 if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then |
579 begin |
579 begin |
580 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
580 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
581 AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
581 AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
582 lua_pushinteger(L, gear^.uid); |
582 lua_pushinteger(L, gear^.uid); |
583 end |
583 end |
587 end; |
587 end; |
588 |
588 |
589 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl; |
589 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl; |
590 var gear: PGear; |
590 var gear: PGear; |
591 begin |
591 begin |
592 if CheckLuaParameterCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then |
592 if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then |
593 begin |
593 begin |
594 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
594 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
595 UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
595 UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
596 lua_pushinteger(L, gear^.uid); |
596 lua_pushinteger(L, gear^.uid); |
597 end |
597 end |
602 |
602 |
603 function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl; |
603 function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl; |
604 var gear: PGear; |
604 var gear: PGear; |
605 var health, n: LongInt; |
605 var health, n: LongInt; |
606 begin |
606 begin |
607 if CheckAndFetchLuaParameterCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then |
607 if CheckAndFetchParamCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then |
608 begin |
608 begin |
609 if n = 3 then |
609 if n = 3 then |
610 health:= lua_tointeger(L, 3) |
610 health:= lua_tointeger(L, 3) |
611 else |
611 else |
612 health:= cHealthCaseAmount; |
612 health:= cHealthCaseAmount; |
623 |
623 |
624 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl; |
624 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl; |
625 var gear: PGear; |
625 var gear: PGear; |
626 n : LongInt; |
626 n : LongInt; |
627 begin |
627 begin |
628 if CheckAndFetchLuaParameterCount(L, 3, 4, 'SpawnAmmoCrate', 'x, y, content [, amount]', n) then |
628 if CheckAndFetchParamCount(L, 3, 4, 'SpawnAmmoCrate', 'x, y, content [, amount]', n) then |
629 begin |
629 begin |
630 if n = 3 then |
630 if n = 3 then |
631 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0) |
631 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0) |
632 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
632 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
633 if gear <> nil then |
633 if gear <> nil then |
642 |
642 |
643 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl; |
643 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl; |
644 var gear: PGear; |
644 var gear: PGear; |
645 n : LongInt; |
645 n : LongInt; |
646 begin |
646 begin |
647 if CheckAndFetchLuaParameterCount(L, 3, 4, 'SpawnUtilityCrate', 'x, y, content [, amount]', n) then |
647 if CheckAndFetchParamCount(L, 3, 4, 'SpawnUtilityCrate', 'x, y, content [, amount]', n) then |
648 begin |
648 begin |
649 if n = 3 then |
649 if n = 3 then |
650 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0) |
650 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0) |
651 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
651 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
652 if gear <> nil then |
652 if gear <> nil then |
666 gt: TGearType; |
666 gt: TGearType; |
667 const |
667 const |
668 call = 'AddGear'; |
668 call = 'AddGear'; |
669 params = 'x, y, gearType, state, dx, dy, timer'; |
669 params = 'x, y, gearType, state, dx, dy, timer'; |
670 begin |
670 begin |
671 if CheckLuaParameterCount(L, 7, call, params) then |
671 if CheckLuaParamCount(L, 7, call, params) then |
672 begin |
672 begin |
673 t:= LuaToGearTypeOrd(L, 3, call, params); |
673 t:= LuaToGearTypeOrd(L, 3, call, params); |
674 if t >= 0 then |
674 if t >= 0 then |
675 begin |
675 begin |
676 gt:= TGearType(t); |
676 gt:= TGearType(t); |
694 end; |
694 end; |
695 |
695 |
696 function lc_deletegear(L : Plua_State) : LongInt; Cdecl; |
696 function lc_deletegear(L : Plua_State) : LongInt; Cdecl; |
697 var gear : PGear; |
697 var gear : PGear; |
698 begin |
698 begin |
699 if CheckLuaParameterCount(L, 1, 'DeleteGear', 'gearUid') then |
699 if CheckLuaParamCount(L, 1, 'DeleteGear', 'gearUid') then |
700 begin |
700 begin |
701 gear:= GearByUID(lua_tointeger(L, 1)); |
701 gear:= GearByUID(lua_tointeger(L, 1)); |
702 if gear <> nil then |
702 if gear <> nil then |
703 gear^.Message:= gear^.Message or gmDelete; |
703 gear^.Message:= gear^.Message or gmDelete; |
704 end; |
704 end; |
714 const |
714 const |
715 call = 'AddVisualGear'; |
715 call = 'AddVisualGear'; |
716 params = 'x, y, visualGearType, state, critical'; |
716 params = 'x, y, visualGearType, state, critical'; |
717 begin |
717 begin |
718 uid:= 0; |
718 uid:= 0; |
719 if CheckLuaParameterCount(L, 5, call, params) then |
719 if CheckLuaParamCount(L, 5, call, params) then |
720 begin |
720 begin |
721 s:= LuaToVisualGearTypeOrd(L, 3, call, params); |
721 s:= LuaToVisualGearTypeOrd(L, 3, call, params); |
722 if s >= 0 then |
722 if s >= 0 then |
723 begin |
723 begin |
724 vgt:= TVisualGearType(s); |
724 vgt:= TVisualGearType(s); |
745 |
745 |
746 function lc_deletevisualgear(L : Plua_State) : LongInt; Cdecl; |
746 function lc_deletevisualgear(L : Plua_State) : LongInt; Cdecl; |
747 var vg : PVisualGear; |
747 var vg : PVisualGear; |
748 begin |
748 begin |
749 vg:= nil; |
749 vg:= nil; |
750 if CheckLuaParameterCount(L, 1, 'DeleteVisualGear', 'vgUid') then |
750 if CheckLuaParamCount(L, 1, 'DeleteVisualGear', 'vgUid') then |
751 begin |
751 begin |
752 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
752 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
753 if vg <> nil then |
753 if vg <> nil then |
754 DeleteVisualGear(vg); |
754 DeleteVisualGear(vg); |
755 end; |
755 end; |
759 end; |
759 end; |
760 |
760 |
761 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl; |
761 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl; |
762 var vg: PVisualGear; |
762 var vg: PVisualGear; |
763 begin |
763 begin |
764 if CheckLuaParameterCount(L, 1, 'GetVisualGearValues', 'vgUid') then |
764 if CheckLuaParamCount(L, 1, 'GetVisualGearValues', 'vgUid') then |
765 begin |
765 begin |
766 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
766 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
767 if vg <> nil then |
767 if vg <> nil then |
768 begin |
768 begin |
769 lua_pushinteger(L, round(vg^.X)); |
769 lua_pushinteger(L, round(vg^.X)); |
792 end; |
792 end; |
793 |
793 |
794 function lc_setvisualgearvalues(L : Plua_State) : LongInt; Cdecl; |
794 function lc_setvisualgearvalues(L : Plua_State) : LongInt; Cdecl; |
795 var vg : PVisualGear; |
795 var vg : PVisualGear; |
796 begin |
796 begin |
797 if CheckLuaParameterCount(L, 11, 'SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint') then |
797 if CheckLuaParamCount(L, 11, 'SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint') then |
798 begin |
798 begin |
799 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
799 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
800 if vg <> nil then |
800 if vg <> nil then |
801 begin |
801 begin |
802 vg^.X:= lua_tointeger(L, 2); |
802 vg^.X:= lua_tointeger(L, 2); |
817 lc_setvisualgearvalues:= 0; |
817 lc_setvisualgearvalues:= 0; |
818 end; |
818 end; |
819 |
819 |
820 function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl; |
820 function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl; |
821 begin |
821 begin |
822 if CheckLuaParameterCount(L, 0, 'GetFollowGear', '') then |
822 if CheckLuaParamCount(L, 0, 'GetFollowGear', '') then |
823 begin |
823 begin |
824 if FollowGear = nil then |
824 if FollowGear = nil then |
825 lua_pushnil(L) |
825 lua_pushnil(L) |
826 else |
826 else |
827 lua_pushinteger(L, FollowGear^.uid); |
827 lua_pushinteger(L, FollowGear^.uid); |
832 end; |
832 end; |
833 |
833 |
834 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl; |
834 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl; |
835 var gear : PGear; |
835 var gear : PGear; |
836 begin |
836 begin |
837 if CheckLuaParameterCount(L, 1, 'GetGearType', 'gearUid') then |
837 if CheckLuaParamCount(L, 1, 'GetGearType', 'gearUid') then |
838 begin |
838 begin |
839 gear:= GearByUID(lua_tointeger(L, 1)); |
839 gear:= GearByUID(lua_tointeger(L, 1)); |
840 if gear <> nil then |
840 if gear <> nil then |
841 lua_pushinteger(L, ord(gear^.Kind)) |
841 lua_pushinteger(L, ord(gear^.Kind)) |
842 else |
842 else |
848 end; |
848 end; |
849 |
849 |
850 function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl; |
850 function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl; |
851 var gear : PGear; |
851 var gear : PGear; |
852 begin |
852 begin |
853 if CheckLuaParameterCount(L, 1, 'GetGearMessage', 'gearUid') then |
853 if CheckLuaParamCount(L, 1, 'GetGearMessage', 'gearUid') then |
854 begin |
854 begin |
855 gear:= GearByUID(lua_tointeger(L, 1)); |
855 gear:= GearByUID(lua_tointeger(L, 1)); |
856 if gear <> nil then |
856 if gear <> nil then |
857 lua_pushinteger(L, gear^.message) |
857 lua_pushinteger(L, gear^.message) |
858 else |
858 else |
864 end; |
864 end; |
865 |
865 |
866 function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl; |
866 function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl; |
867 var gear : PGear; |
867 var gear : PGear; |
868 begin |
868 begin |
869 if CheckLuaParameterCount(L, 1, 'GetGearElasticity', 'gearUid') then |
869 if CheckLuaParamCount(L, 1, 'GetGearElasticity', 'gearUid') then |
870 begin |
870 begin |
871 gear:= GearByUID(lua_tointeger(L, 1)); |
871 gear:= GearByUID(lua_tointeger(L, 1)); |
872 if gear <> nil then |
872 if gear <> nil then |
873 lua_pushinteger(L, hwRound(gear^.elasticity * _10000)) |
873 lua_pushinteger(L, hwRound(gear^.elasticity * _10000)) |
874 else |
874 else |
880 end; |
880 end; |
881 |
881 |
882 function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl; |
882 function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl; |
883 var gear : PGear; |
883 var gear : PGear; |
884 begin |
884 begin |
885 if CheckLuaParameterCount(L, 2, 'SetGearMessage', 'gearUid, message') then |
885 if CheckLuaParamCount(L, 2, 'SetGearMessage', 'gearUid, message') then |
886 begin |
886 begin |
887 gear:= GearByUID(lua_tointeger(L, 1)); |
887 gear:= GearByUID(lua_tointeger(L, 1)); |
888 if gear <> nil then |
888 if gear <> nil then |
889 gear^.message:= lua_tointeger(L, 2); |
889 gear^.message:= lua_tointeger(L, 2); |
890 end; |
890 end; |
892 end; |
892 end; |
893 |
893 |
894 function lc_getgearpos(L : Plua_State) : LongInt; Cdecl; |
894 function lc_getgearpos(L : Plua_State) : LongInt; Cdecl; |
895 var gear : PGear; |
895 var gear : PGear; |
896 begin |
896 begin |
897 if CheckLuaParameterCount(L, 1, 'GetGearPos', 'gearUid') then |
897 if CheckLuaParamCount(L, 1, 'GetGearPos', 'gearUid') then |
898 begin |
898 begin |
899 gear:= GearByUID(lua_tointeger(L, 1)); |
899 gear:= GearByUID(lua_tointeger(L, 1)); |
900 if gear <> nil then |
900 if gear <> nil then |
901 lua_pushinteger(L, gear^.Pos) |
901 lua_pushinteger(L, gear^.Pos) |
902 else |
902 else |
908 end; |
908 end; |
909 |
909 |
910 function lc_setgearpos(L : Plua_State) : LongInt; Cdecl; |
910 function lc_setgearpos(L : Plua_State) : LongInt; Cdecl; |
911 var gear : PGear; |
911 var gear : PGear; |
912 begin |
912 begin |
913 if CheckLuaParameterCount(L, 2, 'SetGearPos', 'gearUid, value') then |
913 if CheckLuaParamCount(L, 2, 'SetGearPos', 'gearUid, value') then |
914 begin |
914 begin |
915 gear:= GearByUID(lua_tointeger(L, 1)); |
915 gear:= GearByUID(lua_tointeger(L, 1)); |
916 if gear <> nil then |
916 if gear <> nil then |
917 gear^.Pos:= lua_tointeger(L, 2); |
917 gear^.Pos:= lua_tointeger(L, 2); |
918 end; |
918 end; |
920 end; |
920 end; |
921 |
921 |
922 function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl; |
922 function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl; |
923 var gear : PGear; |
923 var gear : PGear; |
924 begin |
924 begin |
925 if CheckLuaParameterCount(L, 1, 'GetGearCollisionMask', 'gearUid') then |
925 if CheckLuaParamCount(L, 1, 'GetGearCollisionMask', 'gearUid') then |
926 begin |
926 begin |
927 gear:= GearByUID(lua_tointeger(L, 1)); |
927 gear:= GearByUID(lua_tointeger(L, 1)); |
928 if gear <> nil then |
928 if gear <> nil then |
929 lua_pushinteger(L, gear^.CollisionMask) |
929 lua_pushinteger(L, gear^.CollisionMask) |
930 else |
930 else |
936 end; |
936 end; |
937 |
937 |
938 function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl; |
938 function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl; |
939 var gear : PGear; |
939 var gear : PGear; |
940 begin |
940 begin |
941 if CheckLuaParameterCount(L, 2, 'SetGearCollisionMask', 'gearUid, mask') then |
941 if CheckLuaParamCount(L, 2, 'SetGearCollisionMask', 'gearUid, mask') then |
942 begin |
942 begin |
943 gear:= GearByUID(lua_tointeger(L, 1)); |
943 gear:= GearByUID(lua_tointeger(L, 1)); |
944 if gear <> nil then |
944 if gear <> nil then |
945 gear^.CollisionMask:= lua_tointeger(L, 2); |
945 gear^.CollisionMask:= lua_tointeger(L, 2); |
946 end; |
946 end; |
948 end; |
948 end; |
949 |
949 |
950 function lc_gethoglevel(L : Plua_State): LongInt; Cdecl; |
950 function lc_gethoglevel(L : Plua_State): LongInt; Cdecl; |
951 var gear : PGear; |
951 var gear : PGear; |
952 begin |
952 begin |
953 if CheckLuaParameterCount(L, 1, 'GetHogLevel', 'gearUid') then |
953 if CheckLuaParamCount(L, 1, 'GetHogLevel', 'gearUid') then |
954 begin |
954 begin |
955 gear := GearByUID(lua_tointeger(L, 1)); |
955 gear := GearByUID(lua_tointeger(L, 1)); |
956 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
956 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
957 lua_pushinteger(L, gear^.Hedgehog^.BotLevel) |
957 lua_pushinteger(L, gear^.Hedgehog^.BotLevel) |
958 else |
958 else |
962 end; |
962 end; |
963 |
963 |
964 function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl; |
964 function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl; |
965 var gear : PGear; |
965 var gear : PGear; |
966 begin |
966 begin |
967 if CheckLuaParameterCount(L, 2, 'SetHogLevel', 'gearUid, level') then |
967 if CheckLuaParamCount(L, 2, 'SetHogLevel', 'gearUid, level') then |
968 begin |
968 begin |
969 gear:= GearByUID(lua_tointeger(L, 1)); |
969 gear:= GearByUID(lua_tointeger(L, 1)); |
970 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
970 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
971 gear^.Hedgehog^.BotLevel:= lua_tointeger(L, 2); |
971 gear^.Hedgehog^.BotLevel:= lua_tointeger(L, 2); |
972 end; |
972 end; |
974 end; |
974 end; |
975 |
975 |
976 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl; |
976 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl; |
977 var gear : PGear; |
977 var gear : PGear; |
978 begin |
978 begin |
979 if CheckLuaParameterCount(L, 1, 'GetHogClan', 'gearUid') then |
979 if CheckLuaParamCount(L, 1, 'GetHogClan', 'gearUid') then |
980 begin |
980 begin |
981 gear:= GearByUID(lua_tointeger(L, 1)); |
981 gear:= GearByUID(lua_tointeger(L, 1)); |
982 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
982 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
983 begin |
983 begin |
984 lua_pushinteger(L, gear^.Hedgehog^.Team^.Clan^.ClanIndex) |
984 lua_pushinteger(L, gear^.Hedgehog^.Team^.Clan^.ClanIndex) |
991 lc_gethogclan:= 1 |
991 lc_gethogclan:= 1 |
992 end; |
992 end; |
993 |
993 |
994 function lc_getclancolor(L : Plua_State) : LongInt; Cdecl; |
994 function lc_getclancolor(L : Plua_State) : LongInt; Cdecl; |
995 begin |
995 begin |
996 if CheckLuaParameterCount(L, 1, 'GetClanColor', 'clan') then |
996 if CheckLuaParamCount(L, 1, 'GetClanColor', 'clan') then |
997 lua_pushinteger(L, ClansArray[lua_tointeger(L, 1)]^.Color shl 8 or $FF) |
997 lua_pushinteger(L, ClansArray[lua_tointeger(L, 1)]^.Color shl 8 or $FF) |
998 else |
998 else |
999 lua_pushnil(L); // return value on stack (nil) |
999 lua_pushnil(L); // return value on stack (nil) |
1000 lc_getclancolor:= 1 |
1000 lc_getclancolor:= 1 |
1001 end; |
1001 end; |
1004 var clan : PClan; |
1004 var clan : PClan; |
1005 team : PTeam; |
1005 team : PTeam; |
1006 hh : THedgehog; |
1006 hh : THedgehog; |
1007 i, j : LongInt; |
1007 i, j : LongInt; |
1008 begin |
1008 begin |
1009 if CheckLuaParameterCount(L, 2, 'SetClanColor', 'clan, color') then |
1009 if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then |
1010 begin |
1010 begin |
1011 clan := ClansArray[lua_tointeger(L, 1)]; |
1011 clan := ClansArray[lua_tointeger(L, 1)]; |
1012 clan^.Color:= lua_tointeger(L, 2) shr 8; |
1012 clan^.Color:= lua_tointeger(L, 2) shr 8; |
1013 |
1013 |
1014 for i:= 0 to Pred(clan^.TeamsNumber) do |
1014 for i:= 0 to Pred(clan^.TeamsNumber) do |
1035 end; |
1035 end; |
1036 |
1036 |
1037 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl; |
1037 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl; |
1038 var gear : PGear; |
1038 var gear : PGear; |
1039 begin |
1039 begin |
1040 if CheckLuaParameterCount(L, 1, 'GetHogTeamName', 'gearUid') then |
1040 if CheckLuaParamCount(L, 1, 'GetHogTeamName', 'gearUid') then |
1041 begin |
1041 begin |
1042 gear:= GearByUID(lua_tointeger(L, 1)); |
1042 gear:= GearByUID(lua_tointeger(L, 1)); |
1043 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1043 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1044 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName)) |
1044 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName)) |
1045 else |
1045 else |
1051 end; |
1051 end; |
1052 |
1052 |
1053 function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl; |
1053 function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl; |
1054 var gear : PGear; |
1054 var gear : PGear; |
1055 begin |
1055 begin |
1056 if CheckLuaParameterCount(L, 2, 'SetHogTeamName', 'gearUid, name') then |
1056 if CheckLuaParamCount(L, 2, 'SetHogTeamName', 'gearUid, name') then |
1057 begin |
1057 begin |
1058 gear := GearByUID(lua_tointeger(L, 1)); |
1058 gear := GearByUID(lua_tointeger(L, 1)); |
1059 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1059 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1060 begin |
1060 begin |
1061 gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2); |
1061 gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2); |
1072 end; |
1072 end; |
1073 |
1073 |
1074 function lc_gethogname(L : Plua_State) : LongInt; Cdecl; |
1074 function lc_gethogname(L : Plua_State) : LongInt; Cdecl; |
1075 var gear : PGear; |
1075 var gear : PGear; |
1076 begin |
1076 begin |
1077 if CheckLuaParameterCount(L, 1, 'GetHogName', 'gearUid') then |
1077 if CheckLuaParamCount(L, 1, 'GetHogName', 'gearUid') then |
1078 begin |
1078 begin |
1079 gear:= GearByUID(lua_tointeger(L, 1)); |
1079 gear:= GearByUID(lua_tointeger(L, 1)); |
1080 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1080 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1081 begin |
1081 begin |
1082 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Name)) |
1082 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Name)) |
1090 end; |
1090 end; |
1091 |
1091 |
1092 function lc_sethogname(L : Plua_State) : LongInt; Cdecl; |
1092 function lc_sethogname(L : Plua_State) : LongInt; Cdecl; |
1093 var gear : PGear; |
1093 var gear : PGear; |
1094 begin |
1094 begin |
1095 if CheckLuaParameterCount(L, 2, 'SetHogName', 'gearUid, name') then |
1095 if CheckLuaParamCount(L, 2, 'SetHogName', 'gearUid, name') then |
1096 begin |
1096 begin |
1097 gear:= GearByUID(lua_tointeger(L, 1)); |
1097 gear:= GearByUID(lua_tointeger(L, 1)); |
1098 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
1098 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
1099 begin |
1099 begin |
1100 gear^.Hedgehog^.Name:= lua_tostring(L, 2); |
1100 gear^.Hedgehog^.Name:= lua_tostring(L, 2); |
1107 end; |
1107 end; |
1108 |
1108 |
1109 function lc_gettimer(L : Plua_State) : LongInt; Cdecl; |
1109 function lc_gettimer(L : Plua_State) : LongInt; Cdecl; |
1110 var gear : PGear; |
1110 var gear : PGear; |
1111 begin |
1111 begin |
1112 if CheckLuaParameterCount(L, 1, 'GetTimer', 'gearUid') then |
1112 if CheckLuaParamCount(L, 1, 'GetTimer', 'gearUid') then |
1113 begin |
1113 begin |
1114 gear:= GearByUID(lua_tointeger(L, 1)); |
1114 gear:= GearByUID(lua_tointeger(L, 1)); |
1115 if gear <> nil then |
1115 if gear <> nil then |
1116 lua_pushinteger(L, gear^.Timer) |
1116 lua_pushinteger(L, gear^.Timer) |
1117 else |
1117 else |
1123 end; |
1123 end; |
1124 |
1124 |
1125 function lc_gethealth(L : Plua_State) : LongInt; Cdecl; |
1125 function lc_gethealth(L : Plua_State) : LongInt; Cdecl; |
1126 var gear : PGear; |
1126 var gear : PGear; |
1127 begin |
1127 begin |
1128 if CheckLuaParameterCount(L, 1, 'GetHealth', 'gearUid') then |
1128 if CheckLuaParamCount(L, 1, 'GetHealth', 'gearUid') then |
1129 begin |
1129 begin |
1130 gear:= GearByUID(lua_tointeger(L, 1)); |
1130 gear:= GearByUID(lua_tointeger(L, 1)); |
1131 if gear <> nil then |
1131 if gear <> nil then |
1132 lua_pushinteger(L, gear^.Health) |
1132 lua_pushinteger(L, gear^.Health) |
1133 else |
1133 else |
1139 end; |
1139 end; |
1140 |
1140 |
1141 function lc_getx(L : Plua_State) : LongInt; Cdecl; |
1141 function lc_getx(L : Plua_State) : LongInt; Cdecl; |
1142 var gear : PGear; |
1142 var gear : PGear; |
1143 begin |
1143 begin |
1144 if CheckLuaParameterCount(L, 1, 'GetX', 'gearUid') then |
1144 if CheckLuaParamCount(L, 1, 'GetX', 'gearUid') then |
1145 begin |
1145 begin |
1146 gear:= GearByUID(lua_tointeger(L, 1)); |
1146 gear:= GearByUID(lua_tointeger(L, 1)); |
1147 if gear <> nil then |
1147 if gear <> nil then |
1148 lua_pushinteger(L, hwRound(gear^.X)) |
1148 lua_pushinteger(L, hwRound(gear^.X)) |
1149 else |
1149 else |
1155 end; |
1155 end; |
1156 |
1156 |
1157 function lc_gety(L : Plua_State) : LongInt; Cdecl; |
1157 function lc_gety(L : Plua_State) : LongInt; Cdecl; |
1158 var gear : PGear; |
1158 var gear : PGear; |
1159 begin |
1159 begin |
1160 if CheckLuaParameterCount(L, 1, 'GetY', 'gearUid') then |
1160 if CheckLuaParamCount(L, 1, 'GetY', 'gearUid') then |
1161 begin |
1161 begin |
1162 gear:= GearByUID(lua_tointeger(L, 1)); |
1162 gear:= GearByUID(lua_tointeger(L, 1)); |
1163 if gear <> nil then |
1163 if gear <> nil then |
1164 lua_pushinteger(L, hwRound(gear^.Y)) |
1164 lua_pushinteger(L, hwRound(gear^.Y)) |
1165 else |
1165 else |
1171 end; |
1171 end; |
1172 |
1172 |
1173 function lc_copypv(L : Plua_State) : LongInt; Cdecl; |
1173 function lc_copypv(L : Plua_State) : LongInt; Cdecl; |
1174 var gears, geard : PGear; |
1174 var gears, geard : PGear; |
1175 begin |
1175 begin |
1176 if CheckLuaParameterCount(L, 2, 'CopyPV', 'fromGearUid, toGearUid') then |
1176 if CheckLuaParamCount(L, 2, 'CopyPV', 'fromGearUid, toGearUid') then |
1177 begin |
1177 begin |
1178 gears:= GearByUID(lua_tointeger(L, 1)); |
1178 gears:= GearByUID(lua_tointeger(L, 1)); |
1179 geard:= GearByUID(lua_tointeger(L, 2)); |
1179 geard:= GearByUID(lua_tointeger(L, 2)); |
1180 if (gears <> nil) and (geard <> nil) then |
1180 if (gears <> nil) and (geard <> nil) then |
1181 begin |
1181 begin |
1189 end; |
1189 end; |
1190 |
1190 |
1191 function lc_followgear(L : Plua_State) : LongInt; Cdecl; |
1191 function lc_followgear(L : Plua_State) : LongInt; Cdecl; |
1192 var gear : PGear; |
1192 var gear : PGear; |
1193 begin |
1193 begin |
1194 if CheckLuaParameterCount(L, 1, 'FollowGear', 'gearUid') then |
1194 if CheckLuaParamCount(L, 1, 'FollowGear', 'gearUid') then |
1195 begin |
1195 begin |
1196 gear:= GearByUID(lua_tointeger(L, 1)); |
1196 gear:= GearByUID(lua_tointeger(L, 1)); |
1197 if gear <> nil then FollowGear:= gear |
1197 if gear <> nil then FollowGear:= gear |
1198 end; |
1198 end; |
1199 lc_followgear:= 0 |
1199 lc_followgear:= 0 |
1203 var gear : PGear; |
1203 var gear : PGear; |
1204 vgear : PVisualGear; |
1204 vgear : PVisualGear; |
1205 s : LongWord; |
1205 s : LongWord; |
1206 n : LongInt; |
1206 n : LongInt; |
1207 begin |
1207 begin |
1208 if CheckAndFetchLuaParameterCount(L, 3, 4, 'HogSay', 'gearUid, text, manner [, vgState]', n) then |
1208 if CheckAndFetchParamCount(L, 3, 4, 'HogSay', 'gearUid, text, manner [, vgState]', n) then |
1209 begin |
1209 begin |
1210 gear:= GearByUID(lua_tointeger(L, 1)); |
1210 gear:= GearByUID(lua_tointeger(L, 1)); |
1211 if gear <> nil then |
1211 if gear <> nil then |
1212 begin |
1212 begin |
1213 // state defaults to 0 if state param is given |
1213 // state defaults to 0 if state param is given |
1241 end; |
1241 end; |
1242 |
1242 |
1243 function lc_switchhog(L : Plua_State) : LongInt; Cdecl; |
1243 function lc_switchhog(L : Plua_State) : LongInt; Cdecl; |
1244 var gear, prevgear : PGear; |
1244 var gear, prevgear : PGear; |
1245 begin |
1245 begin |
1246 if CheckLuaParameterCount(L, 1, 'SwitchHog', 'gearUid') then |
1246 if CheckLuaParamCount(L, 1, 'SwitchHog', 'gearUid') then |
1247 begin |
1247 begin |
1248 gear:= GearByUID(lua_tointeger(L, 1)); |
1248 gear:= GearByUID(lua_tointeger(L, 1)); |
1249 // should we allow this when there is no current hedgehog? might do some odd(er) things to turn sequence. |
1249 // should we allow this when there is no current hedgehog? might do some odd(er) things to turn sequence. |
1250 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (CurrentHedgehog <> nil) then |
1250 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (CurrentHedgehog <> nil) then |
1251 begin |
1251 begin |
1275 at, n: LongInt; |
1275 at, n: LongInt; |
1276 const |
1276 const |
1277 call = 'AddAmmo'; |
1277 call = 'AddAmmo'; |
1278 params = 'gearUid, ammoType [, ammoCount]'; |
1278 params = 'gearUid, ammoType [, ammoCount]'; |
1279 begin |
1279 begin |
1280 if CheckAndFetchLuaParameterCount(L, 2, 3, call, params, n) then |
1280 if CheckAndFetchParamCount(L, 2, 3, call, params, n) then |
1281 begin |
1281 begin |
1282 at:= LuaToAmmoTypeOrd(L, 2, call, params); |
1282 at:= LuaToAmmoTypeOrd(L, 2, call, params); |
1283 if at >= 0 then |
1283 if at >= 0 then |
1284 begin |
1284 begin |
1285 gear:= GearByUID(lua_tointeger(L, 1)); |
1285 gear:= GearByUID(lua_tointeger(L, 1)); |
1299 at : LongInt; |
1299 at : LongInt; |
1300 const |
1300 const |
1301 call = 'GetAmmoCount'; |
1301 call = 'GetAmmoCount'; |
1302 params = 'gearUid, ammoType'; |
1302 params = 'gearUid, ammoType'; |
1303 begin |
1303 begin |
1304 if CheckLuaParameterCount(L, 2, call, params) then |
1304 if CheckLuaParamCount(L, 2, call, params) then |
1305 begin |
1305 begin |
1306 gear:= GearByUID(lua_tointeger(L, 1)); |
1306 gear:= GearByUID(lua_tointeger(L, 1)); |
1307 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
1307 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
1308 begin |
1308 begin |
1309 at:= LuaToAmmoTypeOrd(L, 2, call, params); |
1309 at:= LuaToAmmoTypeOrd(L, 2, call, params); |
1324 end; |
1324 end; |
1325 |
1325 |
1326 function lc_sethealth(L : Plua_State) : LongInt; Cdecl; |
1326 function lc_sethealth(L : Plua_State) : LongInt; Cdecl; |
1327 var gear : PGear; |
1327 var gear : PGear; |
1328 begin |
1328 begin |
1329 if CheckLuaParameterCount(L, 2, 'SetHealth', 'gearUid, health') then |
1329 if CheckLuaParamCount(L, 2, 'SetHealth', 'gearUid, health') then |
1330 begin |
1330 begin |
1331 gear:= GearByUID(lua_tointeger(L, 1)); |
1331 gear:= GearByUID(lua_tointeger(L, 1)); |
1332 if gear <> nil then |
1332 if gear <> nil then |
1333 begin |
1333 begin |
1334 gear^.Health:= lua_tointeger(L, 2); |
1334 gear^.Health:= lua_tointeger(L, 2); |
1348 end; |
1348 end; |
1349 |
1349 |
1350 function lc_settimer(L : Plua_State) : LongInt; Cdecl; |
1350 function lc_settimer(L : Plua_State) : LongInt; Cdecl; |
1351 var gear : PGear; |
1351 var gear : PGear; |
1352 begin |
1352 begin |
1353 if CheckLuaParameterCount(L, 2, 'SetTimer', 'gearUid, timer') then |
1353 if CheckLuaParamCount(L, 2, 'SetTimer', 'gearUid, timer') then |
1354 begin |
1354 begin |
1355 gear:= GearByUID(lua_tointeger(L, 1)); |
1355 gear:= GearByUID(lua_tointeger(L, 1)); |
1356 if gear <> nil then gear^.Timer:= lua_tointeger(L, 2) |
1356 if gear <> nil then gear^.Timer:= lua_tointeger(L, 2) |
1357 end; |
1357 end; |
1358 lc_settimer:= 0 |
1358 lc_settimer:= 0 |
1363 t : LongInt; |
1363 t : LongInt; |
1364 const |
1364 const |
1365 call = 'SetEffect'; |
1365 call = 'SetEffect'; |
1366 params = 'gearUid, effect, effectState'; |
1366 params = 'gearUid, effect, effectState'; |
1367 begin |
1367 begin |
1368 if CheckLuaParameterCount(L, 3, call, params) then |
1368 if CheckLuaParamCount(L, 3, call, params) then |
1369 begin |
1369 begin |
1370 t:= LuaToHogEffectOrd(L, 2, call, params); |
1370 t:= LuaToHogEffectOrd(L, 2, call, params); |
1371 if t >= 0 then |
1371 if t >= 0 then |
1372 begin |
1372 begin |
1373 gear := GearByUID(lua_tointeger(L, 1)); |
1373 gear := GearByUID(lua_tointeger(L, 1)); |
1383 t : LongInt; |
1383 t : LongInt; |
1384 const |
1384 const |
1385 call = 'GetEffect'; |
1385 call = 'GetEffect'; |
1386 params = 'gearUid, effect'; |
1386 params = 'gearUid, effect'; |
1387 begin |
1387 begin |
1388 if CheckLuaParameterCount(L, 2, call, params) then |
1388 if CheckLuaParamCount(L, 2, call, params) then |
1389 begin |
1389 begin |
1390 t:= LuaToHogEffectOrd(L, 2, call, params); |
1390 t:= LuaToHogEffectOrd(L, 2, call, params); |
1391 if t >= 0 then |
1391 if t >= 0 then |
1392 begin |
1392 begin |
1393 gear:= GearByUID(lua_tointeger(L, 1)); |
1393 gear:= GearByUID(lua_tointeger(L, 1)); |
1403 end; |
1403 end; |
1404 |
1404 |
1405 function lc_setstate(L : Plua_State) : LongInt; Cdecl; |
1405 function lc_setstate(L : Plua_State) : LongInt; Cdecl; |
1406 var gear : PGear; |
1406 var gear : PGear; |
1407 begin |
1407 begin |
1408 if CheckLuaParameterCount(L, 2, 'SetState', 'gearUid, state') then |
1408 if CheckLuaParamCount(L, 2, 'SetState', 'gearUid, state') then |
1409 begin |
1409 begin |
1410 gear:= GearByUID(lua_tointeger(L, 1)); |
1410 gear:= GearByUID(lua_tointeger(L, 1)); |
1411 if gear <> nil then |
1411 if gear <> nil then |
1412 begin |
1412 begin |
1413 gear^.State:= lua_tointeger(L, 2); |
1413 gear^.State:= lua_tointeger(L, 2); |
1418 end; |
1418 end; |
1419 |
1419 |
1420 function lc_getstate(L : Plua_State) : LongInt; Cdecl; |
1420 function lc_getstate(L : Plua_State) : LongInt; Cdecl; |
1421 var gear : PGear; |
1421 var gear : PGear; |
1422 begin |
1422 begin |
1423 if CheckLuaParameterCount(L, 1, 'GetState', 'gearUid') then |
1423 if CheckLuaParamCount(L, 1, 'GetState', 'gearUid') then |
1424 begin |
1424 begin |
1425 gear:= GearByUID(lua_tointeger(L, 1)); |
1425 gear:= GearByUID(lua_tointeger(L, 1)); |
1426 if gear <> nil then |
1426 if gear <> nil then |
1427 lua_pushinteger(L, gear^.State) |
1427 lua_pushinteger(L, gear^.State) |
1428 else |
1428 else |
1434 end; |
1434 end; |
1435 |
1435 |
1436 function lc_gettag(L : Plua_State) : LongInt; Cdecl; |
1436 function lc_gettag(L : Plua_State) : LongInt; Cdecl; |
1437 var gear : PGear; |
1437 var gear : PGear; |
1438 begin |
1438 begin |
1439 if CheckLuaParameterCount(L, 1, 'GetTag', 'gearUid') then |
1439 if CheckLuaParamCount(L, 1, 'GetTag', 'gearUid') then |
1440 begin |
1440 begin |
1441 gear:= GearByUID(lua_tointeger(L, 1)); |
1441 gear:= GearByUID(lua_tointeger(L, 1)); |
1442 if gear <> nil then |
1442 if gear <> nil then |
1443 lua_pushinteger(L, gear^.Tag) |
1443 lua_pushinteger(L, gear^.Tag) |
1444 else |
1444 else |
1450 end; |
1450 end; |
1451 |
1451 |
1452 function lc_settag(L : Plua_State) : LongInt; Cdecl; |
1452 function lc_settag(L : Plua_State) : LongInt; Cdecl; |
1453 var gear : PGear; |
1453 var gear : PGear; |
1454 begin |
1454 begin |
1455 if CheckLuaParameterCount(L, 2, 'SetTag', 'gearUid, tag') then |
1455 if CheckLuaParamCount(L, 2, 'SetTag', 'gearUid, tag') then |
1456 begin |
1456 begin |
1457 gear:= GearByUID(lua_tointeger(L, 1)); |
1457 gear:= GearByUID(lua_tointeger(L, 1)); |
1458 if gear <> nil then |
1458 if gear <> nil then |
1459 begin |
1459 begin |
1460 gear^.Tag:= lua_tointeger(L, 2); |
1460 gear^.Tag:= lua_tointeger(L, 2); |
1478 needsTn : boolean; |
1478 needsTn : boolean; |
1479 const |
1479 const |
1480 call = 'SendStat'; |
1480 call = 'SendStat'; |
1481 params = 'statInfoType, color [, teamname]'; |
1481 params = 'statInfoType, color [, teamname]'; |
1482 begin |
1482 begin |
1483 if CheckAndFetchLuaParameterCount(L, 2, 3, call, params, n) then |
1483 if CheckAndFetchParamCount(L, 2, 3, call, params, n) then |
1484 begin |
1484 begin |
1485 i:= LuaToStatInfoTypeOrd(L, 1, call, params); |
1485 i:= LuaToStatInfoTypeOrd(L, 1, call, params); |
1486 if i >= 0 then |
1486 if i >= 0 then |
1487 begin |
1487 begin |
1488 statInfo:= TStatInfoType(i); |
1488 statInfo:= TStatInfoType(i); |
1545 var gear: PGear; |
1545 var gear: PGear; |
1546 fall: boolean; |
1546 fall: boolean; |
1547 tryhard: boolean; |
1547 tryhard: boolean; |
1548 left, right, n: LongInt; |
1548 left, right, n: LongInt; |
1549 begin |
1549 begin |
1550 if CheckAndFetchLuaParameterCount(L, 4, 5, 'FindPlace', 'gearUid, fall, left, right [, tryHarder]', n) then |
1550 if CheckAndFetchParamCount(L, 4, 5, 'FindPlace', 'gearUid, fall, left, right [, tryHarder]', n) then |
1551 begin |
1551 begin |
1552 gear:= GearByUID(lua_tointeger(L, 1)); |
1552 gear:= GearByUID(lua_tointeger(L, 1)); |
1553 fall:= lua_toboolean(L, 2); |
1553 fall:= lua_toboolean(L, 2); |
1554 left:= lua_tointeger(L, 3); |
1554 left:= lua_tointeger(L, 3); |
1555 right:= lua_tointeger(L, 4); |
1555 right:= lua_tointeger(L, 4); |
1572 n, s: LongInt; |
1572 n, s: LongInt; |
1573 const |
1573 const |
1574 call = 'PlaySound'; |
1574 call = 'PlaySound'; |
1575 params = 'soundId [, hhGearUid]'; |
1575 params = 'soundId [, hhGearUid]'; |
1576 begin |
1576 begin |
1577 if CheckAndFetchLuaParameterCount(L, 1, 2, call, params, n) then |
1577 if CheckAndFetchParamCount(L, 1, 2, call, params, n) then |
1578 begin |
1578 begin |
1579 s:= LuaToSoundOrd(L, 1, call, params); |
1579 s:= LuaToSoundOrd(L, 1, call, params); |
1580 if s >= 0 then |
1580 if s >= 0 then |
1581 begin |
1581 begin |
1582 // no gear specified |
1582 // no gear specified |
1594 end; |
1594 end; |
1595 |
1595 |
1596 function lc_addteam(L : Plua_State) : LongInt; Cdecl; |
1596 function lc_addteam(L : Plua_State) : LongInt; Cdecl; |
1597 var np: LongInt; |
1597 var np: LongInt; |
1598 begin |
1598 begin |
1599 if CheckAndFetchLuaParameterCount(L, 5, 6, 'AddTeam', 'teamname, color, grave, fort, voicepack [, flag]', np) then |
1599 if CheckAndFetchParamCount(L, 5, 6, 'AddTeam', 'teamname, color, grave, fort, voicepack [, flag]', np) then |
1600 begin |
1600 begin |
1601 ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true, true); |
1601 ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true, true); |
1602 ParseCommand('grave ' + lua_tostring(L, 3), true, true); |
1602 ParseCommand('grave ' + lua_tostring(L, 3), true, true); |
1603 ParseCommand('fort ' + lua_tostring(L, 4), true, true); |
1603 ParseCommand('fort ' + lua_tostring(L, 4), true, true); |
1604 ParseCommand('voicepack ' + lua_tostring(L, 5), true, true); |
1604 ParseCommand('voicepack ' + lua_tostring(L, 5), true, true); |
1612 lc_addteam:= 0;//1; |
1612 lc_addteam:= 0;//1; |
1613 end; |
1613 end; |
1614 |
1614 |
1615 function lc_dismissteam(L : Plua_State) : LongInt; Cdecl; |
1615 function lc_dismissteam(L : Plua_State) : LongInt; Cdecl; |
1616 begin |
1616 begin |
1617 if CheckLuaParameterCount(L, 1, 'DismissTeam', 'teamname') then |
1617 if CheckLuaParamCount(L, 1, 'DismissTeam', 'teamname') then |
1618 ParseCommand('teamgone ' + lua_tostring(L, 1), true, true); |
1618 ParseCommand('teamgone ' + lua_tostring(L, 1), true, true); |
1619 lc_dismissteam:= 0;; |
1619 lc_dismissteam:= 0;; |
1620 end; |
1620 end; |
1621 |
1621 |
1622 function lc_addhog(L : Plua_State) : LongInt; Cdecl; |
1622 function lc_addhog(L : Plua_State) : LongInt; Cdecl; |
1623 var temp: ShortString; |
1623 var temp: ShortString; |
1624 begin |
1624 begin |
1625 if CheckLuaParameterCount(L, 4, 'AddHog', 'hogname, botlevel, health, hat') then |
1625 if CheckLuaParamCount(L, 4, 'AddHog', 'hogname, botlevel, health, hat') then |
1626 begin |
1626 begin |
1627 temp:= lua_tostring(L, 4); |
1627 temp:= lua_tostring(L, 4); |
1628 ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true); |
1628 ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true); |
1629 ParseCommand('hat ' + temp, true, true); |
1629 ParseCommand('hat ' + temp, true, true); |
1630 lua_pushinteger(L, CurrentHedgehog^.Gear^.uid); |
1630 lua_pushinteger(L, CurrentHedgehog^.Gear^.uid); |
1635 end; |
1635 end; |
1636 |
1636 |
1637 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl; |
1637 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl; |
1638 var gear: PGear; |
1638 var gear: PGear; |
1639 begin |
1639 begin |
1640 if CheckLuaParameterCount(L, 2, 'HogTurnLeft', 'gearUid, boolean') then |
1640 if CheckLuaParamCount(L, 2, 'HogTurnLeft', 'gearUid, boolean') then |
1641 begin |
1641 begin |
1642 gear:= GearByUID(lua_tointeger(L, 1)); |
1642 gear:= GearByUID(lua_tointeger(L, 1)); |
1643 if gear <> nil then |
1643 if gear <> nil then |
1644 gear^.dX.isNegative:= lua_toboolean(L, 2); |
1644 gear^.dX.isNegative:= lua_toboolean(L, 2); |
1645 end; |
1645 end; |
1647 end; |
1647 end; |
1648 |
1648 |
1649 function lc_getgearposition(L : Plua_State) : LongInt; Cdecl; |
1649 function lc_getgearposition(L : Plua_State) : LongInt; Cdecl; |
1650 var gear: PGear; |
1650 var gear: PGear; |
1651 begin |
1651 begin |
1652 if CheckLuaParameterCount(L, 1, 'GetGearPosition', 'gearUid') then |
1652 if CheckLuaParamCount(L, 1, 'GetGearPosition', 'gearUid') then |
1653 begin |
1653 begin |
1654 gear:= GearByUID(lua_tointeger(L, 1)); |
1654 gear:= GearByUID(lua_tointeger(L, 1)); |
1655 if gear <> nil then |
1655 if gear <> nil then |
1656 begin |
1656 begin |
1657 lua_pushinteger(L, hwRound(gear^.X)); |
1657 lua_pushinteger(L, hwRound(gear^.X)); |
1674 function lc_setgearposition(L : Plua_State) : LongInt; Cdecl; |
1674 function lc_setgearposition(L : Plua_State) : LongInt; Cdecl; |
1675 var gear: PGear; |
1675 var gear: PGear; |
1676 col: boolean; |
1676 col: boolean; |
1677 x, y: LongInt; |
1677 x, y: LongInt; |
1678 begin |
1678 begin |
1679 if CheckLuaParameterCount(L, 3, 'SetGearPosition', 'gearUid, x, y') then |
1679 if CheckLuaParamCount(L, 3, 'SetGearPosition', 'gearUid, x, y') then |
1680 begin |
1680 begin |
1681 gear:= GearByUID(lua_tointeger(L, 1)); |
1681 gear:= GearByUID(lua_tointeger(L, 1)); |
1682 if gear <> nil then |
1682 if gear <> nil then |
1683 begin |
1683 begin |
1684 col:= gear^.CollisionIndex >= 0; |
1684 col:= gear^.CollisionIndex >= 0; |
1697 end; |
1697 end; |
1698 |
1698 |
1699 function lc_getgeartarget(L : Plua_State) : LongInt; Cdecl; |
1699 function lc_getgeartarget(L : Plua_State) : LongInt; Cdecl; |
1700 var gear: PGear; |
1700 var gear: PGear; |
1701 begin |
1701 begin |
1702 if CheckLuaParameterCount(L, 1, 'GetGearTarget', 'gearUid') then |
1702 if CheckLuaParamCount(L, 1, 'GetGearTarget', 'gearUid') then |
1703 begin |
1703 begin |
1704 gear:= GearByUID(lua_tointeger(L, 1)); |
1704 gear:= GearByUID(lua_tointeger(L, 1)); |
1705 if gear <> nil then |
1705 if gear <> nil then |
1706 begin |
1706 begin |
1707 lua_pushinteger(L, gear^.Target.X); |
1707 lua_pushinteger(L, gear^.Target.X); |
1722 end; |
1722 end; |
1723 |
1723 |
1724 function lc_setgeartarget(L : Plua_State) : LongInt; Cdecl; |
1724 function lc_setgeartarget(L : Plua_State) : LongInt; Cdecl; |
1725 var gear: PGear; |
1725 var gear: PGear; |
1726 begin |
1726 begin |
1727 if CheckLuaParameterCount(L, 3, 'SetGearTarget', 'gearUid, x, y') then |
1727 if CheckLuaParamCount(L, 3, 'SetGearTarget', 'gearUid, x, y') then |
1728 begin |
1728 begin |
1729 gear:= GearByUID(lua_tointeger(L, 1)); |
1729 gear:= GearByUID(lua_tointeger(L, 1)); |
1730 if gear <> nil then |
1730 if gear <> nil then |
1731 begin |
1731 begin |
1732 gear^.Target.X:= lua_tointeger(L, 2); |
1732 gear^.Target.X:= lua_tointeger(L, 2); |
1738 |
1738 |
1739 function lc_getgearvelocity(L : Plua_State) : LongInt; Cdecl; |
1739 function lc_getgearvelocity(L : Plua_State) : LongInt; Cdecl; |
1740 var gear: PGear; |
1740 var gear: PGear; |
1741 var t: LongInt; |
1741 var t: LongInt; |
1742 begin |
1742 begin |
1743 if CheckLuaParameterCount(L, 1, 'GetGearVelocity', 'gearUid') then |
1743 if CheckLuaParamCount(L, 1, 'GetGearVelocity', 'gearUid') then |
1744 begin |
1744 begin |
1745 gear:= GearByUID(lua_tointeger(L, 1)); |
1745 gear:= GearByUID(lua_tointeger(L, 1)); |
1746 if gear <> nil then |
1746 if gear <> nil then |
1747 begin |
1747 begin |
1748 t:= hwRound(gear^.dX * 1000000); |
1748 t:= hwRound(gear^.dX * 1000000); |
1761 end; |
1761 end; |
1762 |
1762 |
1763 function lc_setgearvelocity(L : Plua_State) : LongInt; Cdecl; |
1763 function lc_setgearvelocity(L : Plua_State) : LongInt; Cdecl; |
1764 var gear: PGear; |
1764 var gear: PGear; |
1765 begin |
1765 begin |
1766 if CheckLuaParameterCount(L, 3, 'SetGearVelocity', 'gearUid, dx, dy') then |
1766 if CheckLuaParamCount(L, 3, 'SetGearVelocity', 'gearUid, dx, dy') then |
1767 begin |
1767 begin |
1768 gear:= GearByUID(lua_tointeger(L, 1)); |
1768 gear:= GearByUID(lua_tointeger(L, 1)); |
1769 if gear <> nil then |
1769 if gear <> nil then |
1770 begin |
1770 begin |
1771 gear^.dX:= int2hwFloat(lua_tointeger(L, 2)) / 1000000; |
1771 gear^.dX:= int2hwFloat(lua_tointeger(L, 2)) / 1000000; |
1776 lc_setgearvelocity:= 0 |
1776 lc_setgearvelocity:= 0 |
1777 end; |
1777 end; |
1778 |
1778 |
1779 function lc_setzoom(L : Plua_State) : LongInt; Cdecl; |
1779 function lc_setzoom(L : Plua_State) : LongInt; Cdecl; |
1780 begin |
1780 begin |
1781 if CheckLuaParameterCount(L, 1, 'SetZoom', 'zoomLevel') then |
1781 if CheckLuaParamCount(L, 1, 'SetZoom', 'zoomLevel') then |
1782 begin |
1782 begin |
1783 ZoomValue:= lua_tonumber(L, 1); |
1783 ZoomValue:= lua_tonumber(L, 1); |
1784 if ZoomValue < cMaxZoomLevel then |
1784 if ZoomValue < cMaxZoomLevel then |
1785 ZoomValue:= cMaxZoomLevel; |
1785 ZoomValue:= cMaxZoomLevel; |
1786 if ZoomValue > cMinZoomLevel then |
1786 if ZoomValue > cMinZoomLevel then |
1789 lc_setzoom:= 0 |
1789 lc_setzoom:= 0 |
1790 end; |
1790 end; |
1791 |
1791 |
1792 function lc_getzoom(L : Plua_State) : LongInt; Cdecl; |
1792 function lc_getzoom(L : Plua_State) : LongInt; Cdecl; |
1793 begin |
1793 begin |
1794 if CheckLuaParameterCount(L, 0, 'GetZoom', '') then |
1794 if CheckLuaParamCount(L, 0, 'GetZoom', '') then |
1795 lua_pushnumber(L, ZoomValue) |
1795 lua_pushnumber(L, ZoomValue) |
1796 else |
1796 else |
1797 lua_pushnil(L); |
1797 lua_pushnil(L); |
1798 lc_getzoom:= 1 |
1798 lc_getzoom:= 1 |
1799 end; |
1799 end; |
1802 var np, at: LongInt; |
1802 var np, at: LongInt; |
1803 const |
1803 const |
1804 call = 'SetAmmo'; |
1804 call = 'SetAmmo'; |
1805 params = 'ammoType, count, probability, delay [, numberInCrate]'; |
1805 params = 'ammoType, count, probability, delay [, numberInCrate]'; |
1806 begin |
1806 begin |
1807 if CheckAndFetchLuaParameterCount(L, 4, 5, call, params, np) then |
1807 if CheckAndFetchParamCount(L, 4, 5, call, params, np) then |
1808 begin |
1808 begin |
1809 at:= LuaToAmmoTypeOrd(L, 1, call, params); |
1809 at:= LuaToAmmoTypeOrd(L, 1, call, params); |
1810 if at >= 0 then |
1810 if at >= 0 then |
1811 begin |
1811 begin |
1812 if np = 4 then |
1812 if np = 4 then |
1822 var at: LongInt; |
1822 var at: LongInt; |
1823 const |
1823 const |
1824 call = 'SetAmmoDelay'; |
1824 call = 'SetAmmoDelay'; |
1825 params = 'ammoType, delay'; |
1825 params = 'ammoType, delay'; |
1826 begin |
1826 begin |
1827 if CheckLuaParameterCount(L, 2, call, params) then |
1827 if CheckLuaParamCount(L, 2, call, params) then |
1828 begin |
1828 begin |
1829 at:= LuaToAmmoTypeOrd(L, 1, call, params); |
1829 at:= LuaToAmmoTypeOrd(L, 1, call, params); |
1830 if at >= 0 then |
1830 if at >= 0 then |
1831 ScriptSetAmmoDelay(TAmmoType(at), lua_tointeger(L, 2)); |
1831 ScriptSetAmmoDelay(TAmmoType(at), lua_tointeger(L, 2)); |
1832 end; |
1832 end; |
1833 lc_setammodelay:= 0 |
1833 lc_setammodelay:= 0 |
1834 end; |
1834 end; |
1835 |
1835 |
1836 function lc_setammostore(L : Plua_State) : LongInt; Cdecl; |
1836 function lc_setammostore(L : Plua_State) : LongInt; Cdecl; |
1837 begin |
1837 begin |
1838 if CheckLuaParameterCount(L, 4, 'SetAmmoStore', 'loadouts, probabilities, delays, reinforments') then |
1838 if CheckLuaParamCount(L, 4, 'SetAmmoStore', 'loadouts, probabilities, delays, reinforments') then |
1839 begin |
1839 begin |
1840 ScriptAmmoLoadout:= lua_tostring(L, 1); |
1840 ScriptAmmoLoadout:= lua_tostring(L, 1); |
1841 ScriptAmmoProbability:= lua_tostring(L, 2); |
1841 ScriptAmmoProbability:= lua_tostring(L, 2); |
1842 ScriptAmmoDelay:= lua_tostring(L, 3); |
1842 ScriptAmmoDelay:= lua_tostring(L, 3); |
1843 ScriptAmmoReinforcement:= lua_tostring(L, 4); |
1843 ScriptAmmoReinforcement:= lua_tostring(L, 4); |
1846 end; |
1846 end; |
1847 |
1847 |
1848 function lc_getrandom(L : Plua_State) : LongInt; Cdecl; |
1848 function lc_getrandom(L : Plua_State) : LongInt; Cdecl; |
1849 var m : LongInt; |
1849 var m : LongInt; |
1850 begin |
1850 begin |
1851 if CheckLuaParameterCount(L, 1, 'GetRandom', 'number') then |
1851 if CheckLuaParamCount(L, 1, 'GetRandom', 'number') then |
1852 begin |
1852 begin |
1853 m:= lua_tointeger(L, 1); |
1853 m:= lua_tointeger(L, 1); |
1854 if (m > 0) then |
1854 if (m > 0) then |
1855 lua_pushinteger(L, GetRandom(m)) |
1855 lua_pushinteger(L, GetRandom(m)) |
1856 else |
1856 else |
1864 lc_getrandom:= 1 |
1864 lc_getrandom:= 1 |
1865 end; |
1865 end; |
1866 |
1866 |
1867 function lc_setwind(L : Plua_State) : LongInt; Cdecl; |
1867 function lc_setwind(L : Plua_State) : LongInt; Cdecl; |
1868 begin |
1868 begin |
1869 if CheckLuaParameterCount(L, 1, 'SetWind', 'windSpeed') then |
1869 if CheckLuaParamCount(L, 1, 'SetWind', 'windSpeed') then |
1870 begin |
1870 begin |
1871 cWindSpeed:= int2hwfloat(lua_tointeger(L, 1)) / 100 * cMaxWindSpeed; |
1871 cWindSpeed:= int2hwfloat(lua_tointeger(L, 1)) / 100 * cMaxWindSpeed; |
1872 cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue; |
1872 cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue; |
1873 if cWindSpeed.isNegative then |
1873 if cWindSpeed.isNegative then |
1874 CWindSpeedf := -cWindSpeedf; |
1874 CWindSpeedf := -cWindSpeedf; |
1877 lc_setwind:= 0 |
1877 lc_setwind:= 0 |
1878 end; |
1878 end; |
1879 |
1879 |
1880 function lc_getdatapath(L : Plua_State) : LongInt; Cdecl; |
1880 function lc_getdatapath(L : Plua_State) : LongInt; Cdecl; |
1881 begin |
1881 begin |
1882 if CheckLuaParameterCount(L, 0, 'GetDataPath', '') then |
1882 if CheckLuaParamCount(L, 0, 'GetDataPath', '') then |
1883 lua_pushstring(L, str2pchar(cPathz[ptData])) |
1883 lua_pushstring(L, str2pchar(cPathz[ptData])) |
1884 else |
1884 else |
1885 lua_pushnil(L); |
1885 lua_pushnil(L); |
1886 lc_getdatapath:= 1 |
1886 lc_getdatapath:= 1 |
1887 end; |
1887 end; |
1888 |
1888 |
1889 function lc_getuserdatapath(L : Plua_State) : LongInt; Cdecl; |
1889 function lc_getuserdatapath(L : Plua_State) : LongInt; Cdecl; |
1890 begin |
1890 begin |
1891 if CheckLuaParameterCount(L, 0, 'GetUserDataPath', '') then |
1891 if CheckLuaParamCount(L, 0, 'GetUserDataPath', '') then |
1892 lua_pushstring(L, str2pchar(cPathz[ptData])) |
1892 lua_pushstring(L, str2pchar(cPathz[ptData])) |
1893 else |
1893 else |
1894 lua_pushnil(L); |
1894 lua_pushnil(L); |
1895 lc_getuserdatapath:= 1 |
1895 lc_getuserdatapath:= 1 |
1896 end; |
1896 end; |
1897 |
1897 |
1898 function lc_maphasborder(L : Plua_State) : LongInt; Cdecl; |
1898 function lc_maphasborder(L : Plua_State) : LongInt; Cdecl; |
1899 begin |
1899 begin |
1900 if CheckLuaParameterCount(L, 0, 'MapHasBorder', '') then |
1900 if CheckLuaParamCount(L, 0, 'MapHasBorder', '') then |
1901 lua_pushboolean(L, hasBorder) |
1901 lua_pushboolean(L, hasBorder) |
1902 else |
1902 else |
1903 lua_pushnil(L); |
1903 lua_pushnil(L); |
1904 lc_maphasborder:= 1 |
1904 lc_maphasborder:= 1 |
1905 end; |
1905 end; |
1906 |
1906 |
1907 function lc_getgearradius(L : Plua_State) : LongInt; Cdecl; |
1907 function lc_getgearradius(L : Plua_State) : LongInt; Cdecl; |
1908 var gear : PGear; |
1908 var gear : PGear; |
1909 begin |
1909 begin |
1910 if CheckLuaParameterCount(L, 1, 'GetGearRadius', 'gearUid') then |
1910 if CheckLuaParamCount(L, 1, 'GetGearRadius', 'gearUid') then |
1911 begin |
1911 begin |
1912 gear:= GearByUID(lua_tointeger(L, 1)); |
1912 gear:= GearByUID(lua_tointeger(L, 1)); |
1913 if gear <> nil then |
1913 if gear <> nil then |
1914 lua_pushinteger(L, gear^.Radius) |
1914 lua_pushinteger(L, gear^.Radius) |
1915 else |
1915 else |
1921 end; |
1921 end; |
1922 |
1922 |
1923 function lc_gethoghat(L : Plua_State): LongInt; Cdecl; |
1923 function lc_gethoghat(L : Plua_State): LongInt; Cdecl; |
1924 var gear : PGear; |
1924 var gear : PGear; |
1925 begin |
1925 begin |
1926 if CheckLuaParameterCount(L, 1, 'GetHogHat', 'gearUid') then |
1926 if CheckLuaParamCount(L, 1, 'GetHogHat', 'gearUid') then |
1927 begin |
1927 begin |
1928 gear := GearByUID(lua_tointeger(L, 1)); |
1928 gear := GearByUID(lua_tointeger(L, 1)); |
1929 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1929 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1930 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Hat)) |
1930 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Hat)) |
1931 else |
1931 else |
1938 |
1938 |
1939 function lc_sethoghat(L : Plua_State) : LongInt; Cdecl; |
1939 function lc_sethoghat(L : Plua_State) : LongInt; Cdecl; |
1940 var gear : PGear; |
1940 var gear : PGear; |
1941 hat: ShortString; |
1941 hat: ShortString; |
1942 begin |
1942 begin |
1943 if CheckLuaParameterCount(L, 2, 'SetHogHat', 'gearUid, hat') then |
1943 if CheckLuaParamCount(L, 2, 'SetHogHat', 'gearUid, hat') then |
1944 begin |
1944 begin |
1945 gear:= GearByUID(lua_tointeger(L, 1)); |
1945 gear:= GearByUID(lua_tointeger(L, 1)); |
1946 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
1946 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
1947 begin |
1947 begin |
1948 hat:= lua_tostring(L, 2); |
1948 hat:= lua_tostring(L, 2); |
1965 const |
1965 const |
1966 call = 'PlaceSprite'; |
1966 call = 'PlaceSprite'; |
1967 params = 'x, y, sprite, frameIdx [, landFlags, ... ]'; |
1967 params = 'x, y, sprite, frameIdx [, landFlags, ... ]'; |
1968 begin |
1968 begin |
1969 placed:= false; |
1969 placed:= false; |
1970 if CheckAndFetchLuaParameterCount(L, 4, call, params, n) then |
1970 if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then |
1971 begin |
1971 begin |
1972 lf:= 0; |
1972 lf:= 0; |
1973 |
1973 |
1974 // accept any amount of landflags, loop is never executed if n>5 |
1974 // accept any amount of landflags, loop is never executed if n>5 |
1975 for i:= 5 to n do |
1975 for i:= 5 to n do |
1995 |
1995 |
1996 function lc_placegirder(L : Plua_State) : LongInt; Cdecl; |
1996 function lc_placegirder(L : Plua_State) : LongInt; Cdecl; |
1997 var placed: boolean; |
1997 var placed: boolean; |
1998 begin |
1998 begin |
1999 placed:= false; |
1999 placed:= false; |
2000 if CheckLuaParameterCount(L, 3, 'PlaceGirder', 'x, y, frameIdx') then |
2000 if CheckLuaParamCount(L, 3, 'PlaceGirder', 'x, y, frameIdx') then |
2001 placed:= TryPlaceOnLandSimple( |
2001 placed:= TryPlaceOnLandSimple( |
2002 lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2, |
2002 lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2, |
2003 lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2, |
2003 lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2, |
2004 sprAmGirder, lua_tointeger(L, 3), true, false); |
2004 sprAmGirder, lua_tointeger(L, 3), true, false); |
2005 |
2005 |
2007 lc_placegirder:= 1 |
2007 lc_placegirder:= 1 |
2008 end; |
2008 end; |
2009 |
2009 |
2010 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl; |
2010 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl; |
2011 begin |
2011 begin |
2012 if (CurrentHedgehog <> nil) and (CheckLuaParameterCount(L, 0, 'GetCurAmmoType', '')) then |
2012 if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, 'GetCurAmmoType', '')) then |
2013 lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType)) |
2013 lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType)) |
2014 else |
2014 else |
2015 lua_pushinteger(L, ord(amNothing)); |
2015 lua_pushinteger(L, ord(amNothing)); |
2016 lc_getcurammotype := 1; |
2016 lc_getcurammotype := 1; |
2017 end; |
2017 end; |
2018 |
2018 |
2019 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl; |
2019 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl; |
2020 begin |
2020 begin |
2021 if CheckLuaParameterCount(L, 2, 'SaveCampaignVar', 'varname, value') then |
2021 if CheckLuaParamCount(L, 2, 'SaveCampaignVar', 'varname, value') then |
2022 SendIPC('V!' + lua_tostring(L, 1) + ' ' + lua_tostring(L, 2) + #0); |
2022 SendIPC('V!' + lua_tostring(L, 1) + ' ' + lua_tostring(L, 2) + #0); |
2023 lc_savecampaignvar := 0; |
2023 lc_savecampaignvar := 0; |
2024 end; |
2024 end; |
2025 |
2025 |
2026 function lc_getcampaignvar(L : Plua_State): LongInt; Cdecl; |
2026 function lc_getcampaignvar(L : Plua_State): LongInt; Cdecl; |
2027 begin |
2027 begin |
2028 if CheckLuaParameterCount(L, 1, 'GetCampaignVar', 'varname') then |
2028 if CheckLuaParamCount(L, 1, 'GetCampaignVar', 'varname') then |
2029 SendIPCAndWaitReply('V?' + lua_tostring(L, 1) + #0); |
2029 SendIPCAndWaitReply('V?' + lua_tostring(L, 1) + #0); |
2030 lua_pushstring(L, str2pchar(CampaignVariable)); |
2030 lua_pushstring(L, str2pchar(CampaignVariable)); |
2031 lc_getcampaignvar := 1; |
2031 lc_getcampaignvar := 1; |
2032 end; |
2032 end; |
2033 |
2033 |
2034 function lc_hidehog(L: Plua_State): LongInt; Cdecl; |
2034 function lc_hidehog(L: Plua_State): LongInt; Cdecl; |
2035 var gear: PGear; |
2035 var gear: PGear; |
2036 begin |
2036 begin |
2037 if CheckLuaParameterCount(L, 1, 'HideHog', 'gearUid') then |
2037 if CheckLuaParamCount(L, 1, 'HideHog', 'gearUid') then |
2038 begin |
2038 begin |
2039 gear:= GearByUID(lua_tointeger(L, 1)); |
2039 gear:= GearByUID(lua_tointeger(L, 1)); |
2040 HideHog(gear^.hedgehog) |
2040 HideHog(gear^.hedgehog) |
2041 end; |
2041 end; |
2042 lc_hidehog := 0; |
2042 lc_hidehog := 0; |
2044 |
2044 |
2045 function lc_restorehog(L: Plua_State): LongInt; Cdecl; |
2045 function lc_restorehog(L: Plua_State): LongInt; Cdecl; |
2046 var i, h: LongInt; |
2046 var i, h: LongInt; |
2047 uid: LongWord; |
2047 uid: LongWord; |
2048 begin |
2048 begin |
2049 if CheckLuaParameterCount(L, 1, 'RestoreHog', 'gearUid') then |
2049 if CheckLuaParamCount(L, 1, 'RestoreHog', 'gearUid') then |
2050 begin |
2050 begin |
2051 uid:= LongWord(lua_tointeger(L, 1)); |
2051 uid:= LongWord(lua_tointeger(L, 1)); |
2052 if TeamsCount > 0 then |
2052 if TeamsCount > 0 then |
2053 for i:= 0 to Pred(TeamsCount) do |
2053 for i:= 0 to Pred(TeamsCount) do |
2054 for h:= 0 to cMaxHHIndex do |
2054 for h:= 0 to cMaxHHIndex do |
2063 |
2063 |
2064 // boolean TestRectForObstacle(x1, y1, x2, y2, landOnly) |
2064 // boolean TestRectForObstacle(x1, y1, x2, y2, landOnly) |
2065 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl; |
2065 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl; |
2066 var rtn: Boolean; |
2066 var rtn: Boolean; |
2067 begin |
2067 begin |
2068 if CheckLuaParameterCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then |
2068 if CheckLuaParamCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then |
2069 begin |
2069 begin |
2070 rtn:= TestRectancleForObstacle( |
2070 rtn:= TestRectancleForObstacle( |
2071 lua_tointeger(L, 1), |
2071 lua_tointeger(L, 1), |
2072 lua_tointeger(L, 2), |
2072 lua_tointeger(L, 2), |
2073 lua_tointeger(L, 3), |
2073 lua_tointeger(L, 3), |
2082 end; |
2082 end; |
2083 |
2083 |
2084 |
2084 |
2085 function lc_getgravity(L : Plua_State) : LongInt; Cdecl; |
2085 function lc_getgravity(L : Plua_State) : LongInt; Cdecl; |
2086 begin |
2086 begin |
2087 if CheckLuaParameterCount(L, 0, 'GetGravity', '') then |
2087 if CheckLuaParamCount(L, 0, 'GetGravity', '') then |
2088 lua_pushinteger(L, hwRound(SignAs(_0_5, cGravity) + (cGravity * 50 / cMaxWindSpeed))); |
2088 lua_pushinteger(L, hwRound(SignAs(_0_5, cGravity) + (cGravity * 50 / cMaxWindSpeed))); |
2089 lc_getgravity:= 1 |
2089 lc_getgravity:= 1 |
2090 end; |
2090 end; |
2091 |
2091 |
2092 function lc_setgravity(L : Plua_State) : LongInt; Cdecl; |
2092 function lc_setgravity(L : Plua_State) : LongInt; Cdecl; |
2093 begin |
2093 begin |
2094 if CheckLuaParameterCount(L, 1, 'SetGravity', 'percent') then |
2094 if CheckLuaParamCount(L, 1, 'SetGravity', 'percent') then |
2095 begin |
2095 begin |
2096 cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed; |
2096 cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed; |
2097 cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02 |
2097 cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02 |
2098 end; |
2098 end; |
2099 lc_setgravity:= 0 |
2099 lc_setgravity:= 0 |
2100 end; |
2100 end; |
2101 |
2101 |
2102 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl; |
2102 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl; |
2103 var iterator: PGear; |
2103 var iterator: PGear; |
2104 begin |
2104 begin |
2105 if CheckLuaParameterCount(L, 1, 'SetWaterLine', 'waterline') then |
2105 if CheckLuaParamCount(L, 1, 'SetWaterLine', 'waterline') then |
2106 begin |
2106 begin |
2107 cWaterLine:= lua_tointeger(L,1); |
2107 cWaterLine:= lua_tointeger(L,1); |
2108 AllInactive:= false; |
2108 AllInactive:= false; |
2109 iterator:= GearsList; |
2109 iterator:= GearsList; |
2110 while iterator <> nil do |
2110 while iterator <> nil do |
2123 end; |
2123 end; |
2124 |
2124 |
2125 function lc_setaihintsongear(L : Plua_State) : LongInt; Cdecl; |
2125 function lc_setaihintsongear(L : Plua_State) : LongInt; Cdecl; |
2126 var gear: PGear; |
2126 var gear: PGear; |
2127 begin |
2127 begin |
2128 if CheckLuaParameterCount(L, 2, 'SetAIHintOnGear', 'gearUid, aiHints') then |
2128 if CheckLuaParamCount(L, 2, 'SetAIHintOnGear', 'gearUid, aiHints') then |
2129 begin |
2129 begin |
2130 gear:= GearByUID(lua_tointeger(L, 1)); |
2130 gear:= GearByUID(lua_tointeger(L, 1)); |
2131 if gear <> nil then |
2131 if gear <> nil then |
2132 gear^.aihints:= lua_tointeger(L, 2); |
2132 gear^.aihints:= lua_tointeger(L, 2); |
2133 end; |
2133 end; |
2135 end; |
2135 end; |
2136 |
2136 |
2137 |
2137 |
2138 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl; |
2138 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl; |
2139 begin |
2139 begin |
2140 if CheckLuaParameterCount(L, 1, 'HedgewarsScriptLoad', 'scriptPath') then |
2140 if CheckLuaParamCount(L, 1, 'HedgewarsScriptLoad', 'scriptPath') then |
2141 ScriptLoad(lua_tostring(L, 1)) |
2141 ScriptLoad(lua_tostring(L, 1)) |
2142 else |
2142 else |
2143 lua_pushnil(L); |
2143 lua_pushnil(L); |
2144 lc_hedgewarsscriptload:= 0; |
2144 lc_hedgewarsscriptload:= 0; |
2145 end; |
2145 end; |
2146 |
2146 |
2147 |
2147 |
2148 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl; |
2148 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl; |
2149 begin |
2149 begin |
2150 if CheckLuaParameterCount(L, 4, 'DeclareAchievement', 'achievementId, teamname, location, value') then |
2150 if CheckLuaParamCount(L, 4, 'DeclareAchievement', 'achievementId, teamname, location, value') then |
2151 declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4)); |
2151 declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4)); |
2152 lc_declareachievement:= 0 |
2152 lc_declareachievement:= 0 |
2153 end; |
2153 end; |
2154 |
2154 |
2155 // stuff for testing the lua API |
2155 // stuff for testing the lua API |
2156 function lc_endluatest(L : Plua_State) : LongInt; Cdecl; |
2156 function lc_endluatest(L : Plua_State) : LongInt; Cdecl; |
2157 begin |
2157 begin |
2158 if CheckLuaParameterCount(L, 1, 'EndLuaAPITest', 'LUA_API_TEST_SUCCESSFUL or LUA_API_TEST_FAILED') then |
2158 if CheckLuaParamCount(L, 1, 'EndLuaAPITest', 'LUA_API_TEST_SUCCESSFUL or LUA_API_TEST_FAILED') then |
2159 begin |
2159 begin |
2160 WriteLnToConsole('Lua test finished'); |
2160 WriteLnToConsole('Lua test finished'); |
2161 halt(lua_tointeger(L, 1)); |
2161 halt(lua_tointeger(L, 1)); |
2162 end |
2162 end |
2163 else |
2163 else |