author  nemo 
Sun, 25 Jan 2015 16:10:20 0500  
changeset 10809  bb2e4e9944f7 
parent 10808  1e39630d7c2e 
child 10818  f642a28cab0c 
permissions  rwrr 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1 
(* 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

2 
* Hedgewars, a free turn based strategy game 
9998  3 
* Copyright (c) 20042014 Andrey Korotaev <unC0Rr@gmail.com> 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

4 
* 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

5 
* This program is free software; you can redistribute it and/or modify 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

6 
* it under the terms of the GNU General Public License as published by 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

7 
* the Free Software Foundation; version 2 of the License 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

8 
* 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

9 
* This program is distributed in the hope that it will be useful, 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

10 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

11 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

12 
* GNU General Public License for more details. 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

13 
* 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

14 
* You should have received a copy of the GNU General Public License 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

15 
* along with this program; if not, write to the Free Software 
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright  but I ain't gonna touch their copyright headers
sheepluva
parents:
10078
diff
changeset

16 
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 021101301 USA 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

17 
*) 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

18 

3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

19 
{$INCLUDE "options.inc"} 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

20 

3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

21 
unit uScript; 
5124  22 
(* 
23 
* This unit defines, implements and registers functions and 

24 
* variables/constants bindings for usage in Lua scripts. 

25 
* 

26 
* Please keep http://code.google.com/p/hedgewars/wiki/LuaAPI up to date! 

27 
* 

28 
* Note: If you add a new function, make sure to test if _all_ parameters 

29 
* work as intended! (Especially conversions errors can sneak in 

30 
* unnoticed and render the parameter useless!) 

31 
*) 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

32 
interface 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

33 

3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

34 
procedure ScriptPrintStack; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

35 
procedure ScriptClearStack; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

36 

3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

37 
procedure ScriptLoad(name : shortstring); 
10150
fa5c83fd0ad9
Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents:
10143
diff
changeset

38 
procedure ScriptOnPreviewInit; 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

39 
procedure ScriptOnGameInit; 
7030
09984acadece
invert LUA symbol meaning and avoid hints when compiling without it
koda
parents:
7010
diff
changeset

40 
procedure ScriptOnScreenResize; 
8366
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

41 
procedure ScriptSetInteger(name : shortstring; value : LongInt); 
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9917
diff
changeset

42 
procedure ScriptSetString(name : shortstring; value : shortstring); 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

43 

3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

44 
procedure ScriptCall(fname : shortstring); 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

45 
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

46 
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

47 
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

48 
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

49 
function ScriptExists(fname : shortstring) : boolean; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

50 

10312  51 
procedure LuaParseString(s: shortString); 
5410  52 

7805  53 
//function ParseCommandOverride(key, value : shortstring) : shortstring; This did not work out well 
5577  54 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

55 
procedure initModule; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

56 
procedure freeModule; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

57 

3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

58 
implementation 
7030
09984acadece
invert LUA symbol meaning and avoid hints when compiling without it
koda
parents:
7010
diff
changeset

59 
{$IFDEF USE_LUA_SCRIPT} 
9205
abce6011f86c
aaaaand let's not forget about lua, which has also a slightly revised build process
koda
parents:
9180
diff
changeset

60 

6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6430
diff
changeset

61 
uses LuaPas, 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

62 
uConsole, 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

63 
uConsts, 
6543  64 
uGears, 
6468  65 
uGearsList, 
6543  66 
uGearsUtils, 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

67 
uFloat, 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

68 
uWorld, 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

69 
uAmmos, 
6763  70 
uTeams, 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

71 
uSound, 
4235
6b1dfbd60a45
added TeamsCount and TotalTurns to lua as requested by mikade
Henek
parents:
4221
diff
changeset

72 
uChat, 
4243  73 
uStats, 
4875  74 
uStore, 
4357
a1fcfc341a52
Introduce unit uTypes in order to remove some cyclic unit dependencies
unC0Rr
parents:
4319
diff
changeset

75 
uRandom, 
4359  76 
uTypes, 
4373  77 
uVariables, 
4374  78 
uCommands, 
4377  79 
uUtils, 
4403  80 
uCaptions, 
4832  81 
uDebug, 
4889
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

82 
uCollisions, 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

83 
uRenderUtils, 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

84 
uTextures, 
4985  85 
uLandGraphics, 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

86 
SysUtils, 
8031  87 
uIO, 
9283
76e68c136a11
Refactoring: VGSHandlers.inc > uVisualGearsHandlers.pas
unc0rr
parents:
9245
diff
changeset

88 
uVisualGearsList, 
9285  89 
uGearsHandlersMess, 
9952
32f5982604f4
Fix build (no idea what's going on in this branch btw)
unc0rr
parents:
9950
diff
changeset

90 
uPhysFSLayer 
10129
cd2a64a1f4aa
 Pas2C: make use of 'external' function decorator
unc0rr
parents:
10127
diff
changeset

91 
{$IFNDEF PAS2C} 
9952
32f5982604f4
Fix build (no idea what's going on in this branch btw)
unc0rr
parents:
9950
diff
changeset

92 
, typinfo 
9521
8054d9d775fd
merge with latest defaul, fixing compiling with fpc, parsing and rendering with pas2c, some minor problems with compiling with clang
koda
diff
changeset

93 
{$ENDIF} 
8031  94 
; 
3697  95 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

96 
var luaState : Plua_State; 
3346  97 
ScriptAmmoLoadout : shortstring; 
98 
ScriptAmmoProbability : shortstring; 

99 
ScriptAmmoDelay : shortstring; 

100 
ScriptAmmoReinforcement : shortstring; 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

101 
ScriptLoaded : boolean; 
9567
42bc1b58a242
This test is intended to avoid repeatedly calling 5 ScriptSetIntegers each script call, that won't ever change after the map is created.
nemo
parents:
9531
diff
changeset

102 
mapDims : boolean; 
10615
e3dcb235a354
fix some things I messed up with the drawing functions
sheepluva
parents:
10613
diff
changeset

103 
PointsBuffer: shortstring; 
3697  104 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

105 
procedure ScriptPrepareAmmoStore; forward; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

106 
procedure ScriptApplyAmmoStore; forward; 
9750  107 
procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward; 
9751
7a6038c3faa2
lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support perclan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cooldown behavior)
sheepluva
parents:
9750
diff
changeset

108 
procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward; 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

109 

10293
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

110 
var LuaDebugInfo: lua_Debug; 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

111 

10617  112 
procedure SetGlobals; forward; 
10312  113 
procedure LuaParseString(s: shortString); 
114 
begin 

10617  115 
SetGlobals; 
10312  116 
AddFileLog('[Lua] input string: ' + s); 
117 
AddChatString(#3 + '[Lua] > ' + s); 

118 
if luaL_dostring(luaState, Str2PChar(s)) <> 0 then 

119 
begin 

120 
AddFileLog('[Lua] input string parsing error!'); 

121 
AddChatString(#5 + '[Lua] Error while parsing!'); 

122 
end; 

123 
end; 

124 

10293
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

125 
function LuaUpdateDebugInfo(): Boolean; 
3539  126 
begin 
10293
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

127 
FillChar(LuaDebugInfo, sizeof(LuaDebugInfo), 0); 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

128 

201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

129 
if lua_getstack(luaState, 1, @LuaDebugInfo) = 0 then 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

130 
exit(false); // stack not deep enough 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

131 

201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

132 
// get source name and line count 
10297  133 
lua_getinfo(luaState, PChar('Sl'), @LuaDebugInfo); 
10293
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

134 
exit(true); 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

135 
end; 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

136 

201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

137 
procedure LuaError(s: shortstring); 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

138 
var src: shortstring; 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

139 
const 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

140 
maxsrclen = 20; 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

141 
begin 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

142 
if LuaUpdateDebugInfo() then 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

143 
begin 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

144 
src:= StrPas(LuaDebugInfo.source); 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

145 
s:= 'LUA ERROR [ ... ' 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

146 
+ copy(src, Length(src)  maxsrclen, maxsrclen  3) + ':' 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

147 
+ inttostr(LuaDebugInfo.currentLine) + ']: ' + s; 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

148 
end 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

149 
else 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

150 
s:= 'LUA ERROR: ' + s; 
3539  151 
WriteLnToConsole(s); 
152 
AddChatString(#5 + s); 

9988
317d46a2afd2
simple mechanism to run luabased test cases. experimental  I will back it out if it turns out to be nonsense
sheepluva
parents:
9987
diff
changeset

153 
if cTestLua then 
10306  154 
halt(HaltTestLuaError); 
3539  155 
end; 
156 

10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

157 
procedure LuaCallError(error, call, paramsyntax: shortstring); 
10279
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

158 
begin 
10293
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

159 
LuaError(call + ': ' + error); 
201ea4989985
state file name and line number in lua error messages
sheepluva
parents:
10291
diff
changeset

160 
LuaError(' SYNTAX: ' + call + ' ( ' + paramsyntax + ' )'); 
10279
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

161 
end; 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

162 

10285  163 
procedure LuaParameterCountError(expected, call, paramsyntax: shortstring; wrongcount: LongInt); inline; 
164 
begin 

165 
// TODO: i18n? 

166 
LuaCallError('Wrong number of parameters! (is: ' + inttostr(wrongcount) + ', should be: '+ expected + ')', call, paramsyntax); 

167 
end; 

168 

10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

169 
// compare with allowed count 
10297  170 
function CheckLuaParamCount(L : Plua_State; count: LongInt; call, paramsyntax: shortstring): boolean; inline; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

171 
var c: LongInt; 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

172 
begin 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

173 
c:= lua_gettop(L); 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

174 
if c <> count then 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

175 
begin 
10285  176 
LuaParameterCountError('exactly ' + inttostr(count), call, paramsyntax, c); 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

177 
exit(false); 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

178 
end; 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

179 

10297  180 
CheckLuaParamCount:= true; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

181 
end; 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

182 

e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

183 
// check if is either count1 or count2 
10297  184 
function CheckAndFetchParamCount(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

185 
begin 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

186 
actual:= lua_gettop(L); 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

187 
if (actual <> count1) and (actual <> count2) then 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

188 
begin 
10285  189 
LuaParameterCountError('either ' + inttostr(count1) + ' or ' + inttostr(count2), call, paramsyntax, actual); 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

190 
exit(false); 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

191 
end; 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

192 

10297  193 
CheckAndFetchParamCount:= true; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

194 
end; 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

195 

10611  196 
// check if is in range of count1 and count2 
197 
function CheckAndFetchParamCountRange(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline; 

198 
begin 

199 
actual:= lua_gettop(L); 

200 
if (actual < count1) or (actual > count2) then 

201 
begin 

202 
LuaParameterCountError('at least ' + inttostr(count1) + ', but at most ' + inttostr(count2), call, paramsyntax, actual); 

203 
exit(false); 

204 
end; 

205 

206 
CheckAndFetchParamCountRange:= true; 

207 
end; 

208 

10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

209 
// check if is same or higher as minCount 
10297  210 
function CheckAndFetchLuaParamMinCount(L : Plua_State; minCount: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

211 
begin 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

212 
actual:= lua_gettop(L); 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

213 
if (actual < minCount) then 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

214 
begin 
10285  215 
LuaParameterCountError(inttostr(minCount) + ' or more', call, paramsyntax, actual); 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

216 
exit(false); 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

217 
end; 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

218 

10297  219 
CheckAndFetchLuaParamMinCount:= true; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

220 
end; 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

221 

10281  222 
function LuaToGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; 
223 
begin 

224 
if lua_isnoneornil(L, i) then i:= 1 

225 
else i:= lua_tointeger(L, i); 

226 
if (i < ord(Low(TGearType))) or (i > ord(High(TGearType))) then 

227 
begin 

228 
LuaCallError('Invalid gearType!', call, paramsyntax); 

229 
LuaToGearTypeOrd:= 1; 

230 
end 

231 
else 

232 
LuaToGearTypeOrd:= i; 

233 
end; 

234 

235 
function LuaToVisualGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; 

236 
begin 

237 
if lua_isnoneornil(L, i) then i:= 1 

238 
else i:= lua_tointeger(L, i); 

239 
if (i < ord(Low(TVisualGearType))) or (i > ord(High(TVisualGearType))) then 

240 
begin 

241 
LuaCallError('Invalid visualGearType!', call, paramsyntax); 

242 
LuaToVisualGearTypeOrd:= 1; 

243 
end 

244 
else 

245 
LuaToVisualGearTypeOrd:= i; 

246 
end; 

247 

248 
function LuaToAmmoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; 

10279
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

249 
begin 
10281  250 
if lua_isnoneornil(L, i) then i:= 1 
251 
else i:= lua_tointeger(L, i); 

252 
if (i < ord(Low(TAmmoType))) or (i > ord(High(TAmmoType))) then 

253 
begin 

254 
LuaCallError('Invalid ammoType!', call, paramsyntax); 

255 
LuaToAmmoTypeOrd:= 1; 

256 
end 

257 
else 

258 
LuaToAmmoTypeOrd:= i; 

259 
end; 

260 

261 
function LuaToStatInfoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; 

262 
begin 

263 
if lua_isnoneornil(L, i) then i:= 1 

264 
else i:= lua_tointeger(L, i); 

265 
if (i < ord(Low(TStatInfoType))) or (i > ord(High(TStatInfoType))) then 

266 
begin 

267 
LuaCallError('Invalid statInfoType!', call, paramsyntax); 

268 
LuaToStatInfoTypeOrd:= 1; 

269 
end 

270 
else 

271 
LuaToStatInfoTypeOrd:= i; 

272 
end; 

273 

274 
function LuaToSoundOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; 

275 
begin 

276 
if lua_isnoneornil(L, i) then i:= 1 

277 
else i:= lua_tointeger(L, i); 

278 
if (i < ord(Low(TSound))) or (i > ord(High(TSound))) then 

279 
begin 

280 
LuaCallError('Invalid soundId!', call, paramsyntax); 

281 
LuaToSoundOrd:= 1; 

282 
end 

283 
else 

284 
LuaToSoundOrd:= i; 

285 
end; 

286 

287 
function LuaToHogEffectOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; 

288 
begin 

289 
if lua_isnoneornil(L, i) then i:= 1 

290 
else i:= lua_tointeger(L, i); 

291 
if (i < ord(Low(THogEffect))) or (i > ord(High(THogEffect))) then 

10279
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

292 
begin 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

293 
LuaCallError('Invalid gear type!', call, paramsyntax); 
10281  294 
LuaToHogEffectOrd:= 1; 
295 
end 

296 
else 

297 
LuaToHogEffectOrd:= i; 

9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

298 
end; 
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

299 

10281  300 
function LuaToCapGroupOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; 
10280
762c256552e9
WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents:
10279
diff
changeset

301 
begin 
10281  302 
if lua_isnoneornil(L, i) then i:= 1 
303 
else i:= lua_tointeger(L, i); 

304 
if (i < ord(Low(TCapGroup))) or (i > ord(High(TCapGroup))) then 

305 
begin 

306 
LuaCallError('Invalid capgroup type!', call, paramsyntax); 

307 
LuaToCapGroupOrd:= 1; 

308 
end 

309 
else 

310 
LuaToCapGroupOrd:= i; 

311 
end; 

312 

313 
function LuaToSpriteOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; 

314 
begin 

315 
if lua_isnoneornil(L, i) then i:= 1 

316 
else i:= lua_tointeger(L, i); 

317 
if (i < ord(Low(TSprite))) or (i > ord(High(TSprite))) then 

10280
762c256552e9
WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents:
10279
diff
changeset

318 
begin 
762c256552e9
WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents:
10279
diff
changeset

319 
LuaCallError('Invalid sprite id!', call, paramsyntax); 
10281  320 
LuaToSpriteOrd:= 1; 
321 
end 

322 
else 

323 
LuaToSpriteOrd:= i; 

10280
762c256552e9
WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents:
10279
diff
changeset

324 
end; 
762c256552e9
WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents:
10279
diff
changeset

325 

10603
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

326 
function LuaToMapGenOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

327 
begin 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

328 
if lua_isnoneornil(L, i) then i:= 1 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

329 
else i:= lua_tointeger(L, i); 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

330 
if (i < ord(Low(TMapGen))) or (i > ord(High(TMapGen))) then 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

331 
begin 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

332 
LuaCallError('Invalid mapgen id!', call, paramsyntax); 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

333 
LuaToMapGenOrd:= 1; 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

334 
end 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

335 
else 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

336 
LuaToMapGenOrd:= i; 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

337 
end; 
bda5c7caf396
switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents:
10589
diff
changeset

338 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

339 
// wrapped calls // 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

340 

3539  341 
// functions called from Lua: 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

342 
// function(L : Plua_State) : LongInt; Cdecl; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

343 
// where L contains the state, returns the number of return values on the stack 
10297  344 
// call CheckLuaParamCount or CheckAndFetchParamCount 
10287  345 
// to validate/get the number of passed arguments (see their call definitions) 
346 
// 

347 
// use as return value the number of variables pushed back to the lua script 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

348 

4483  349 
function lc_band(L: PLua_State): LongInt; Cdecl; 
350 
begin 

10297  351 
if CheckLuaParamCount(L, 2, 'band', 'value1, value2') then 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

352 
lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)) 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

353 
else 
4483  354 
lua_pushnil(L); 
355 
lc_band := 1; 

356 
end; 

357 

358 
function lc_bor(L: PLua_State): LongInt; Cdecl; 

359 
begin 

10297  360 
if CheckLuaParamCount(L, 2, 'bor', 'value1, value2') then 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

361 
lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)) 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

362 
else 
4483  363 
lua_pushnil(L); 
364 
lc_bor := 1; 

365 
end; 

366 

367 
function lc_bnot(L: PLua_State): LongInt; Cdecl; 

368 
begin 

10297  369 
if CheckLuaParamCount(L, 1, 'bnot', 'value') then 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

370 
lua_pushinteger(L, (not lua_tointeger(L, 1))) 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

371 
else 
4483  372 
lua_pushnil(L); 
373 
lc_bnot := 1; 

374 
end; 

375 

6764  376 
function lc_div(L: PLua_State): LongInt; Cdecl; 
377 
begin 

10297  378 
if CheckLuaParamCount(L, 2, 'div', 'dividend, divisor') then 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

379 
lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2)) 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

380 
else 
6764  381 
lua_pushnil(L); 
382 
lc_div := 1; 

383 
end; 

384 

4523  385 
function lc_getinputmask(L : Plua_State) : LongInt; Cdecl; 
386 
begin 

10297  387 
if CheckLuaParamCount(L, 0, 'GetInputMask', '') then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

388 
lua_pushinteger(L, InputMask); 
4523  389 
lc_getinputmask:= 1 
390 
end; 

391 

4522
0f590eefd531
Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents:
4517
diff
changeset

392 
function lc_setinputmask(L : Plua_State) : LongInt; Cdecl; 
0f590eefd531
Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents:
4517
diff
changeset

393 
begin 
10297  394 
if CheckLuaParamCount(L, 1, 'SetInputMask', 'mask') then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

395 
InputMask:= lua_tointeger(L, 1); 
4522
0f590eefd531
Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents:
4517
diff
changeset

396 
lc_setinputmask:= 0 
0f590eefd531
Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents:
4517
diff
changeset

397 
end; 
0f590eefd531
Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents:
4517
diff
changeset

398 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

399 
function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

400 
begin 
10297  401 
if CheckLuaParamCount(L, 1, 'WriteLnToConsole', 'string') then 
5549
ccfb9b8ab9d1
sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents:
5547
diff
changeset

402 
WriteLnToConsole('Lua: ' + lua_tostring(L ,1)); 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

403 
lc_writelntoconsole:= 0; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

404 
end; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

405 

3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

406 
function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; 
7307
f830a65d6a6d
This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents:
7270
diff
changeset

407 
var t: PChar; 
f830a65d6a6d
This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents:
7270
diff
changeset

408 
i,c: LongWord; 
f830a65d6a6d
This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents:
7270
diff
changeset

409 
s: shortstring; 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

410 
begin 
10297  411 
if CheckLuaParamCount(L, 1, 'ParseCommand', 'string') then 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

412 
begin 
10131
4b4a043111f4
 pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10129
diff
changeset

413 
t:= lua_tolstring(L, 1, Psize_t(@c)); 
7307
f830a65d6a6d
This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents:
7270
diff
changeset

414 

f830a65d6a6d
This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents:
7270
diff
changeset

415 
for i:= 1 to c do s[i]:= t[i1]; 
f830a65d6a6d
This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents:
7270
diff
changeset

416 
s[0]:= char(c); 
f830a65d6a6d
This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents:
7270
diff
changeset

417 

7805  418 
ParseCommand(s, true, true); 
7307
f830a65d6a6d
This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents:
7270
diff
changeset

419 

10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

420 
end; 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

421 
lc_parsecommand:= 0; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

422 
end; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

423 

10291  424 
// sets weapon to the desired ammo type 
10289  425 
function lc_setweapon(L : Plua_State) : LongInt; Cdecl; 
426 
var at: LongInt; 

427 
const 

428 
call = 'SetWeapon'; 

429 
params = 'ammoType'; 

430 
begin 

10291  431 
// no point to run this without any CurrentHedgehog 
10297  432 
if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 1, call, params)) then 
10289  433 
begin 
434 
at:= LuaToAmmoTypeOrd(L, 1, call, params); 

435 
if at >= 0 then 

436 
ParseCommand('setweap ' + char(at), true, true); 

437 
end; 

438 
lc_setweapon:= 0; 

439 
end; 

440 

10291  441 
// sets weapon to whatever weapons is next (wraps around, amSkip is skipped) 
442 
function lc_setnextweapon(L : Plua_State) : LongInt; Cdecl; 

443 
var at : LongInt; 

444 
nextAmmo : TAmmo; 

445 
s, a, cs, fa: LongInt; 

446 
const 

447 
call = 'SetNextWeapon'; 

448 
params = ''; 

449 
begin 

10297  450 
if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, call, params)) then 
10291  451 
begin 
452 
at:= 1; 

453 
with CurrentHedgehog^ do 

454 
begin 

455 
cs:= 0; // current slot 

456 
fa:= 0; // first ammo item to check 

457 

458 
// if something is selected, find it's successor 

459 
if curAmmoType <> amNothing then 

460 
begin 

461 
// get current slot index 

462 
cs:= Ammoz[CurAmmoType].Slot; 

463 
// find current ammo index 

464 
while (fa < cMaxSlotAmmoIndex) 

465 
and (Ammo^[cs, fa].AmmoType <> CurAmmoType) do 

466 
inc(fa); 

467 
// increase once more because we won't successor 

468 
inc(fa); 

469 
end; 

470 

471 
// find first available ammo 

472 
// revisit current slot too (current item might not be first) 

473 
for s:= cs to cs + cMaxSlotIndex + 1 do 

474 
begin 

475 
for a:= fa to cMaxSlotAmmoIndex do 

476 
begin 

477 
// check if we went full circle 

478 
if (a = fa) and (s = cs + cMaxSlotIndex + 1) then 

479 
exit(0); 

480 

481 
// get ammo 

482 
nextAmmo:= Ammo^[s mod (cMaxSlotIndex + 1), a]; 

483 
// only switch to ammos the hog actually has 

484 
if (nextAmmo.AmmoType <> amNothing) 

485 
and (nextAmmo.AmmoType <> amSkip) and (nextAmmo.Count > 0) then 

486 
begin 

487 
at:= ord(nextAmmo.AmmoType); 

488 
break; 

489 
end; 

490 
end; 

491 
// stop slot loop if something was found 

492 
if at >= 0 then 

493 
break; 

494 
// check following slots starting with first item 

495 
fa:= 0; 

496 
end; 

497 
end; 

498 

499 
if at >= 0 then 

500 
ParseCommand('setweap ' + char(at), true, true); 

501 
end; 

502 
lc_setnextweapon:= 0; 

503 
end; 

504 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

505 
function lc_showmission(L : Plua_State) : LongInt; Cdecl; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

506 
begin 
10297  507 
if CheckLuaParamCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then 
10127  508 
ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5)); 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

509 
lc_showmission:= 0; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

510 
end; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

511 

3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

512 
function lc_hidemission(L : Plua_State) : LongInt; Cdecl; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

513 
begin 
3407  514 
L:= L; // avoid compiler hint 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

515 
HideMission; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

516 
lc_hidemission:= 0; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

517 
end; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

518 

8366
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

519 
function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

520 
var i, n : integer; 
8366
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

521 
begin 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

522 
// can have 1 or more arguments 
10297  523 
if CheckAndFetchLuaParamMinCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then 
10035  524 
begin 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

525 
for i:= 1 to n do 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

526 
GameFlags := GameFlags or LongWord(lua_tointeger(L, i)); 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

527 
ScriptSetInteger('GameFlags', GameFlags); 
10035  528 
end; 
8370  529 
lc_enablegameflags:= 0; 
8366
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

530 
end; 
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

531 

67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

532 
function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

533 
var i , n: integer; 
8366
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

534 
begin 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

535 
// can have 1 or more arguments 
10297  536 
if CheckAndFetchLuaParamMinCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then 
10035  537 
begin 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

538 
for i:= 1 to n do 
10078  539 
GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i))); 
10035  540 
ScriptSetInteger('GameFlags', GameFlags); 
541 
end; 

8370  542 
lc_disablegameflags:= 0; 
8366
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

543 
end; 
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

544 

67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

545 
function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl; 
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

546 
begin 
10297  547 
if CheckLuaParamCount(L, 0, 'ClearGameFlags', '') then 
10035  548 
begin 
549 
GameFlags:= 0; 

550 
ScriptSetInteger('GameFlags', GameFlags); 

551 
end; 

8370  552 
lc_cleargameflags:= 0; 
8366
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

553 
end; 
67c7ba2b82a3
lua API functions to enable or disable game flags
martin_bede
parents:
8228
diff
changeset

554 

10035  555 
function lc_getgameflag(L : Plua_State) : LongInt; Cdecl; 
556 
begin 

10297  557 
if CheckLuaParamCount(L, 1, 'GetGameFlag', 'gameflag') then 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

558 
lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0)) 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

559 
else 
10035  560 
lua_pushnil(L); 
561 
lc_getgameflag:= 1; 

562 
end; 

563 

4243  564 
function lc_addcaption(L : Plua_State) : LongInt; Cdecl; 
10281  565 
var cg: LongInt; 
566 
const 

567 
call = 'AddCaption'; 

568 
params = 'text [, color, captiongroup]'; 

4243  569 
begin 
10297  570 
if CheckAndFetchParamCount(L, 1, 3, call, params, cg) then 
4243  571 
begin 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

572 
if cg = 1 then 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

573 
AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage) 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

574 
else 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

575 
begin 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

576 
cg:= LuaToCapGroupOrd(L, 3, call, params); 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

577 
if cg >= 0 then 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

578 
AddCaption(lua_tostringA(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(cg)); 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

579 
end 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

580 
end; 
4243  581 
lc_addcaption:= 0; 
582 
end; 

583 

3848  584 
function lc_campaignlock(L : Plua_State) : LongInt; Cdecl; 
585 
begin 

10297  586 
if CheckLuaParamCount(L, 1, 'CampaignLock', 'TODO') then 
3848  587 
begin 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

588 
// TODO 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

589 
end; 
3848  590 
lc_campaignlock:= 0; 
591 
end; 

592 

593 
function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl; 

594 
begin 

10297  595 
if CheckLuaParamCount(L, 1, 'CampaignUnlock', 'TODO') then 
3848  596 
begin 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

597 
// TODO 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

598 
end; 
3848  599 
lc_campaignunlock:= 0; 
600 
end; 

601 

5313
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

602 
function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

603 
var gear: PGear; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

604 
begin 
10297  605 
if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

606 
begin 
5313
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

607 
gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

608 
HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); 
5313
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

609 
lua_pushinteger(L, gear^.uid); 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

610 
end 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

611 
else 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

612 
lua_pushnil(L); 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

613 
lc_spawnfakehealthcrate := 1; 
5313
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

614 
end; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

615 

5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

616 
function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

617 
var gear: PGear; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

618 
begin 
10297  619 
if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

620 
begin 
5313
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

621 
gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

622 
AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); 
5313
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

623 
lua_pushinteger(L, gear^.uid); 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

624 
end 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

625 
else 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

626 
lua_pushnil(L); 
5313
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

627 
lc_spawnfakeammocrate := 1; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

628 
end; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

629 

5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

630 
function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

631 
var gear: PGear; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

632 
begin 
10297  633 
if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

634 
begin 
5313
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

635 
gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

636 
UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); 
5313
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

637 
lua_pushinteger(L, gear^.uid); 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

638 
end 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

639 
else 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

640 
lua_pushnil(L); 
5313
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

641 
lc_spawnfakeutilitycrate := 1; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

642 
end; 
5e18eaef65d0
now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents:
5277
diff
changeset

643 

3730  644 
function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl; 
3750
3aa85b5f3318
SpawnCustomCrateAt: spawn crate at random position for x=y=0, also let it return the gear, and luabindings the gear uid
burp
parents:
3736
diff
changeset

645 
var gear: PGear; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

646 
var health, n: LongInt; 
3730  647 
begin 
10297  648 
if CheckAndFetchParamCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

649 
begin 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

650 
if n = 3 then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

651 
health:= lua_tointeger(L, 3) 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

652 
else 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

653 
health:= cHealthCaseAmount; 
7337
c224cd2d32f3
Allow script to set number of ammo in a crate. untested.
nemo
parents:
7307
diff
changeset

654 
gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

655 
if gear <> nil then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

656 
lua_pushinteger(L, gear^.uid) 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

657 
else 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

658 
lua_pushnil(L); 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

659 
end 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

660 
else 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

661 
lua_pushnil(L); 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

662 
lc_spawnhealthcrate := 1; 
3734  663 
end; 
664 

665 
function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl; 

3750
3aa85b5f3318
SpawnCustomCrateAt: spawn crate at random position for x=y=0, also let it return the gear, and luabindings the gear uid
burp
parents:
3736
diff
changeset

666 
var gear: PGear; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

667 
n : LongInt; 
3734  668 
begin 
10297  669 
if CheckAndFetchParamCount(L, 3, 4, 'SpawnAmmoCrate', 'x, y, content [, amount]', n) then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

670 
begin 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

671 
if n = 3 then 
7337
c224cd2d32f3
Allow script to set number of ammo in a crate. untested.
nemo
parents:
7307
diff
changeset

672 
gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0) 
c224cd2d32f3
Allow script to set number of ammo in a crate. untested.
nemo
parents:
7307
diff
changeset

673 
else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

674 
if gear <> nil then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

675 
lua_pushinteger(L, gear^.uid) 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

676 
else 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

677 
lua_pushnil(L); 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

678 
end 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

679 
else 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

680 
lua_pushnil(L); 
3734  681 
lc_spawnammocrate := 1; 
682 
end; 

683 

684 
function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl; 

3750
3aa85b5f3318
SpawnCustomCrateAt: spawn crate at random position for x=y=0, also let it return the gear, and luabindings the gear uid
burp
parents:
3736
diff
changeset

685 
var gear: PGear; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

686 
n : LongInt; 
3734  687 
begin 
10297  688 
if CheckAndFetchParamCount(L, 3, 4, 'SpawnUtilityCrate', 'x, y, content [, amount]', n) then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

689 
begin 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

690 
if n = 3 then 
7337
c224cd2d32f3
Allow script to set number of ammo in a crate. untested.
nemo
parents:
7307
diff
changeset

691 
gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0) 
c224cd2d32f3
Allow script to set number of ammo in a crate. untested.
nemo
parents:
7307
diff
changeset

692 
else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

693 
if gear <> nil then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

694 
lua_pushinteger(L, gear^.uid) 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

695 
else 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

696 
lua_pushnil(L); 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

697 
end 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

698 
else 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

699 
lua_pushnil(L); 
3734  700 
lc_spawnutilitycrate := 1; 
3730  701 
end; 
702 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

703 
function lc_addgear(L : Plua_State) : LongInt; Cdecl; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

704 
var gear : PGear; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

705 
x, y, s, t: LongInt; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

706 
dx, dy: hwFloat; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

707 
gt: TGearType; 
10279
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

708 
const 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

709 
call = 'AddGear'; 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

710 
params = 'x, y, gearType, state, dx, dy, timer'; 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

711 
begin 
10297  712 
if CheckLuaParamCount(L, 7, call, params) then 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

713 
begin 
10281  714 
t:= LuaToGearTypeOrd(L, 3, call, params); 
715 
if t >= 0 then 

10279
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

716 
begin 
10281  717 
gt:= TGearType(t); 
10279
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

718 
x:= lua_tointeger(L, 1); 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

719 
y:= lua_tointeger(L, 2); 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

720 
s:= lua_tointeger(L, 4); 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

721 
dx:= int2hwFloat(lua_tointeger(L, 5)) / 1000000; 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

722 
dy:= int2hwFloat(lua_tointeger(L, 6)) / 1000000; 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

723 
t:= lua_tointeger(L, 7); 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

724 

10279
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

725 
gear:= AddGear(x, y, gt, s, dx, dy, t); 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

726 
lastGearByUID:= gear; 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

727 
lua_pushinteger(L, gear^.uid) 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

728 
end 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

729 
else 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

730 
lua_pushnil(L); 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

731 
end 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

732 
else 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

733 
lua_pushnil(L); 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

734 
lc_addgear:= 1; // 1 return value 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

735 
end; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

736 

4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

737 
function lc_deletegear(L : Plua_State) : LongInt; Cdecl; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

738 
var gear : PGear; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

739 
begin 
10297  740 
if CheckLuaParamCount(L, 1, 'DeleteGear', 'gearUid') then 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

741 
begin 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

742 
gear:= GearByUID(lua_tointeger(L, 1)); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

743 
if gear <> nil then 
7517  744 
gear^.Message:= gear^.Message or gmDelete; 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

745 
end; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

746 
lc_deletegear:= 0 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

747 
end; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

748 

d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

749 
function lc_addvisualgear(L : Plua_State) : LongInt; Cdecl; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

750 
var vg : PVisualGear; 
10346
dd22bcf08e4f
lua api: allow to specify layer when adding visual gear
sheepluva
parents:
10312
diff
changeset

751 
x, y, s, n, layer: LongInt; 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

752 
c: Boolean; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

753 
vgt: TVisualGearType; 
10281  754 
uid: Longword; 
755 
const 

756 
call = 'AddVisualGear'; 

10346
dd22bcf08e4f
lua api: allow to specify layer when adding visual gear
sheepluva
parents:
10312
diff
changeset

757 
params = 'x, y, visualGearType, state, critical [, layer]'; 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

758 
begin 
10281  759 
uid:= 0; 
10346
dd22bcf08e4f
lua api: allow to specify layer when adding visual gear
sheepluva
parents:
10312
diff
changeset

760 
if CheckAndFetchParamCount(L, 5, 6, call, params, n) then 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

761 
begin 
10281  762 
s:= LuaToVisualGearTypeOrd(L, 3, call, params); 
763 
if s >= 0 then 

764 
begin 

765 
vgt:= TVisualGearType(s); 

766 
x:= lua_tointeger(L, 1); 

767 
y:= lua_tointeger(L, 2); 

768 
s:= lua_tointeger(L, 4); 

769 
c:= lua_toboolean(L, 5); 

4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

770 

10346
dd22bcf08e4f
lua api: allow to specify layer when adding visual gear
sheepluva
parents:
10312
diff
changeset

771 
if n = 6 then 
dd22bcf08e4f
lua api: allow to specify layer when adding visual gear
sheepluva
parents:
10312
diff
changeset

772 
begin 
dd22bcf08e4f
lua api: allow to specify layer when adding visual gear
sheepluva
parents:
10312
diff
changeset

773 
layer:= lua_tointeger(L, 6); 
10347  774 
vg:= AddVisualGear(x, y, vgt, s, c, layer); 
10346
dd22bcf08e4f
lua api: allow to specify layer when adding visual gear
sheepluva
parents:
10312
diff
changeset

775 
end 
dd22bcf08e4f
lua api: allow to specify layer when adding visual gear
sheepluva
parents:
10312
diff
changeset

776 
else 
dd22bcf08e4f
lua api: allow to specify layer when adding visual gear
sheepluva
parents:
10312
diff
changeset

777 
vg:= AddVisualGear(x, y, vgt, s, c); 
dd22bcf08e4f
lua api: allow to specify layer when adding visual gear
sheepluva
parents:
10312
diff
changeset

778 

10281  779 
if vg <> nil then 
780 
begin 

781 
lastVisualGearByUID:= vg; 

782 
uid:= vg^.uid; 

10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

783 
lua_pushinteger(L, uid); 
10281  784 
end; 
10284
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

785 
end 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

786 
else 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

787 
lua_pushnil(L); 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

788 
end 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

789 
else 
e9c85a0acdd2
placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents:
10283
diff
changeset

790 
lua_pushnil(L); // return value on stack (nil) 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

791 
lc_addvisualgear:= 1; // 1 return value 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

792 
end; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

793 

d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

794 
function lc_deletevisualgear(L : Plua_State) : LongInt; Cdecl; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

795 
var vg : PVisualGear; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

796 
begin 
10281  797 
vg:= nil; 
10297  798 
if CheckLuaParamCount(L, 1, 'DeleteVisualGear', 'vgUid') then 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

799 
begin 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

800 
vg:= VisualGearByUID(lua_tointeger(L, 1)); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

801 
if vg <> nil then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

802 
DeleteVisualGear(vg); 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

803 
end; 
10281  804 
// allow caller to know whether there was something to delete 
805 
lua_pushboolean(L, vg <> nil); 

806 
lc_deletevisualgear:= 1 

4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

807 
end; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

808 

d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

809 
function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

810 
var vg: PVisualGear; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

811 
begin 
10297  812 
if CheckLuaParamCount(L, 1, 'GetVisualGearValues', 'vgUid') then 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

813 
begin 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

814 
vg:= VisualGearByUID(lua_tointeger(L, 1)); 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

815 
if vg <> nil then 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

816 
begin 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

817 
lua_pushinteger(L, round(vg^.X)); 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

818 
lua_pushinteger(L, round(vg^.Y)); 
5075
59b13b38a827
not useful for visual gears, and apparently not helpful for consistency
nemo
parents:
5074
diff
changeset

819 
lua_pushnumber(L, vg^.dX); 
59b13b38a827
not useful for visual gears, and apparently not helpful for consistency
nemo
parents:
5074
diff
changeset

820 
lua_pushnumber(L, vg^.dY); 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

821 
lua_pushnumber(L, vg^.Angle); 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

822 
lua_pushinteger(L, vg^.Frame); 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

823 
lua_pushinteger(L, vg^.FrameTicks); 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

824 
lua_pushinteger(L, vg^.State); 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

825 
lua_pushinteger(L, vg^.Timer); 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

826 
lua_pushinteger(L, vg^.Tint); 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

827 
end 
4767
4ee4a49549e2
return nil values if an invalid visual gear is passed to the get, add a check in Control map lua
nemo
parents:
4682
diff
changeset

828 
else 
4ee4a49549e2
return nil values if an invalid visual gear is passed to the get, add a check in Control map lua
nemo
parents:
4682
diff
changeset

829 
begin 
4ee4a49549e2
return nil values if an invalid visual gear is passed to the get, add a check in Control map lua
nemo
parents:
4682
diff
changeset

830 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 
10287  831 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 
4767
4ee4a49549e2
return nil values if an invalid visual gear is passed to the get, add a check in Control map lua
nemo
parents:
4682
diff
changeset

832 
end 
10287  833 
end 
834 
else 

835 
begin 

836 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 

837 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 

4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

838 
end; 
10809
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

839 
lc_getvisualgearvalues:= 10 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

840 
end; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

841 

d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

842 
function lc_setvisualgearvalues(L : Plua_State) : LongInt; Cdecl; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

843 
var vg : PVisualGear; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

844 
begin 
10809
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

845 
// Param count can be 111 at present 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

846 
// if CheckLuaParamCount(L, 11, 'SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint') then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

847 
// begin 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

848 
vg:= VisualGearByUID(lua_tointeger(L, 1)); 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

849 
if vg <> nil then 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

850 
begin 
10808
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

851 
if not lua_isnoneornil(L, 2) then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

852 
vg^.X:= lua_tointeger(L, 2); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

853 
if not lua_isnoneornil(L, 3) then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

854 
vg^.Y:= lua_tointeger(L, 3); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

855 
if not lua_isnoneornil(L, 4) then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

856 
vg^.dX:= lua_tonumber(L, 4); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

857 
if not lua_isnoneornil(L, 5) then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

858 
vg^.dY:= lua_tonumber(L, 5); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

859 
if not lua_isnoneornil(L, 6) then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

860 
vg^.Angle:= lua_tonumber(L, 6); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

861 
if not lua_isnoneornil(L, 7) then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

862 
vg^.Frame:= lua_tointeger(L, 7); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

863 
if not lua_isnoneornil(L, 8) then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

864 
vg^.FrameTicks:= lua_tointeger(L, 8); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

865 
if not lua_isnoneornil(L, 9) then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

866 
vg^.State:= lua_tointeger(L, 9); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

867 
if not lua_isnoneornil(L, 10) then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

868 
vg^.Timer:= lua_tointeger(L, 10); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

869 
if not lua_isnoneornil(L, 11) then 
10809
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

870 
vg^.Tint:= lua_tointeger(L, 11) 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

871 
end; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

872 
// end 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

873 
// else 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

874 
// lua_pushnil(L); // return value on stack (nil) 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

875 
lc_setvisualgearvalues:= 0 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

876 
end; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

877 

bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

878 
// so. going to use this to get/set some of the more obscure gear values which weren't already exposed elsewhere 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

879 
// can keep adding things in the future. isnoneornil makes it safe 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

880 
function lc_getgearvalues(L : Plua_State) : LongInt; Cdecl; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

881 
var gear: PGear; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

882 
begin 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

883 
if CheckLuaParamCount(L, 1, 'GetGearValues', 'gearUid') then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

884 
begin 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

885 
gear:= GearByUID(lua_tointeger(L, 1)); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

886 
if gear <> nil then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

887 
begin 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

888 
lua_pushinteger(L, gear^.Angle); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

889 
lua_pushinteger(L, gear^.Power); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

890 
lua_pushinteger(L, gear^.WDTimer); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

891 
lua_pushinteger(L, gear^.Radius); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

892 
lua_pushinteger(L, hwRound(gear^.Density * _10000)); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

893 
lua_pushinteger(L, gear^.Karma); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

894 
lua_pushnumber(L, gear^.DirAngle); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

895 
lua_pushinteger(L, gear^.AdvBounce); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

896 
lua_pushinteger(L, Integer(gear^.ImpactSound)); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

897 
lua_pushinteger(L, gear^.nImpactSounds); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

898 
lua_pushinteger(L, gear^.Tint) 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

899 
end 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

900 
else 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

901 
begin 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

902 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

903 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

904 
lua_pushnil(L) 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

905 
end 
10287  906 
end 
907 
else 

10809
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

908 
begin 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

909 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

910 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

911 
lua_pushnil(L) 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

912 
end; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

913 
lc_getgearvalues:= 11 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

914 
end; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

915 

bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

916 
function lc_setgearvalues(L : Plua_State) : LongInt; Cdecl; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

917 
var gear : PGear; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

918 
begin 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

919 
// Currently allows 112 params 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

920 
// if CheckLuaParamCount(L, 12, 'SetGearValues', 'gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, # ImpactSounds, Tint') then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

921 
// begin 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

922 
gear:= GearByUID(lua_tointeger(L, 1)); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

923 
if gear <> nil then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

924 
begin 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

925 
if not lua_isnoneornil(L, 2) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

926 
gear^.Angle := lua_tointeger(L, 2); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

927 
if not lua_isnoneornil(L, 3) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

928 
gear^.Power := lua_tointeger(L, 3); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

929 
if not lua_isnoneornil(L, 4) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

930 
gear^.WDTimer := lua_tointeger(L, 4); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

931 
if not lua_isnoneornil(L, 5) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

932 
gear^.Radius := lua_tointeger(L, 5); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

933 
if not lua_isnoneornil(L, 6) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

934 
gear^.Density:= int2hwFloat(lua_tointeger(L, 6)) / 10000; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

935 
if not lua_isnoneornil(L, 7) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

936 
gear^.Karma := lua_tointeger(L, 7); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

937 
if not lua_isnoneornil(L, 8) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

938 
gear^.DirAngle:= lua_tonumber(L, 8); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

939 
if not lua_isnoneornil(L, 9) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

940 
gear^.AdvBounce := lua_tointeger(L, 9); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

941 
if not lua_isnoneornil(L, 10) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

942 
gear^.ImpactSound := TSound(lua_tointeger(L, 10)); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

943 
if not lua_isnoneornil(L, 11) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

944 
gear^.nImpactSounds := lua_tointeger(L, 11); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

945 
if not lua_isnoneornil(L, 12) then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

946 
gear^.Tint := lua_tointeger(L, 12) 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

947 
end; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

948 
// end 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

949 
// else 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

950 
// lua_pushnil(L); // return value on stack (nil) 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

951 
lc_setgearvalues:= 0 
4443
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

952 
end; 
d393b9ccd328
Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents:
4411
diff
changeset

953 

3058  954 
function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl; 
955 
begin 

10297  956 
if CheckLuaParamCount(L, 0, 'GetFollowGear', '') then 
3058  957 
begin 
958 
if FollowGear = nil then 

959 
lua_pushnil(L) 

960 
else 

4484  961 
lua_pushinteger(L, FollowGear^.uid); 
10287  962 
end 
963 
else 

964 
lua_pushnil(L); 

3058  965 
lc_getfollowgear:= 1; // 1 return value 
966 
end; 

967 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

968 
function lc_getgeartype(L : Plua_State) : LongInt; Cdecl; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

969 
var gear : PGear; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

970 
begin 
10297  971 
if CheckLuaParamCount(L, 1, 'GetGearType', 'gearUid') then 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

972 
begin 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

973 
gear:= GearByUID(lua_tointeger(L, 1)); 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

974 
if gear <> nil then 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

975 
lua_pushinteger(L, ord(gear^.Kind)) 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

976 
else 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

977 
lua_pushnil(L); 
10287  978 
end 
979 
else 

980 
lua_pushnil(L); // return value on stack (nil) 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

981 
lc_getgeartype:= 1 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

982 
end; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

983 

3892  984 
function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl; 
985 
var gear : PGear; 

986 
begin 

10297  987 
if CheckLuaParamCount(L, 1, 'GetGearMessage', 'gearUid') then 
3892  988 
begin 
989 
gear:= GearByUID(lua_tointeger(L, 1)); 

990 
if gear <> nil then 

991 
lua_pushinteger(L, gear^.message) 

992 
else 

993 
lua_pushnil(L); 

10287  994 
end 
995 
else 

996 
lua_pushnil(L); // return value on stack (nil) 

3892  997 
lc_getgearmessage:= 1 
998 
end; 

999 

4682
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1000 
function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl; 
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1001 
var gear : PGear; 
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1002 
begin 
10297  1003 
if CheckLuaParamCount(L, 1, 'GetGearElasticity', 'gearUid') then 
4682
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1004 
begin 
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1005 
gear:= GearByUID(lua_tointeger(L, 1)); 
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1006 
if gear <> nil then 
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1007 
lua_pushinteger(L, hwRound(gear^.elasticity * _10000)) 
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1008 
else 
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1009 
lua_pushnil(L); 
10287  1010 
end 
1011 
else 

1012 
lua_pushnil(L); // return value on stack (nil) 

4682
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1013 
lc_getgearelasticity:= 1 
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1014 
end; 
0fc1ff341482
add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat  I assume large values will just overflow to negative)
nemo
parents:
4629
diff
changeset

1015 

10808
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1016 
function lc_setgearelasticity(L : Plua_State) : LongInt; Cdecl; 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1017 
var gear: PGear; 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1018 
begin 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1019 
if CheckLuaParamCount(L, 2, 'SetGearElasticity', 'gearUid, Elasticity') then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1020 
begin 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1021 
gear:= GearByUID(lua_tointeger(L, 1)); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1022 
if gear <> nil then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1023 
gear^.Elasticity:= int2hwFloat(lua_tointeger(L, 2)) / 10000 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1024 
end; 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1025 
lc_setgearelasticity:= 0 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1026 
end; 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1027 

10809
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1028 
function lc_getgearfriction(L : Plua_State) : LongInt; Cdecl; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1029 
var gear : PGear; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1030 
begin 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1031 
if CheckLuaParamCount(L, 1, 'GetGearFriction', 'gearUid') then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1032 
begin 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1033 
gear:= GearByUID(lua_tointeger(L, 1)); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1034 
if gear <> nil then 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1035 
lua_pushinteger(L, hwRound(gear^.friction * _10000)) 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1036 
else 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1037 
lua_pushnil(L); 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1038 
end 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1039 
else 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1040 
lua_pushnil(L); // return value on stack (nil) 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1041 
lc_getgearfriction:= 1 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1042 
end; 
bb2e4e9944f7
Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents:
10808
diff
changeset

1043 

10808
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1044 
function lc_setgearfriction(L : Plua_State) : LongInt; Cdecl; 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1045 
var gear: PGear; 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1046 
begin 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1047 
if CheckLuaParamCount(L, 2, 'SetGearFriction', 'gearUid, Friction') then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1048 
begin 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1049 
gear:= GearByUID(lua_tointeger(L, 1)); 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1050 
if gear <> nil then 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1051 
gear^.Friction:= int2hwFloat(lua_tointeger(L, 2)) / 10000 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1052 
end; 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1053 
lc_setgearfriction:= 0 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1054 
end; 
1e39630d7c2e
Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents:
10671
diff
changeset

1055 

3896  1056 
function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl; 
1057 
var gear : PGear; 

1058 
begin 

10297  1059 
if CheckLuaParamCount(L, 2, 'SetGearMessage', 'gearUid, message') then 
3896  1060 
begin 
1061 
gear:= GearByUID(lua_tointeger(L, 1)); 

1062 
if gear <> nil then 

1063 
gear^.message:= lua_tointeger(L, 2); 

1064 
end; 

1065 
lc_setgearmessage:= 0 

1066 
end; 

1067 

6523  1068 
function lc_getgearpos(L : Plua_State) : LongInt; Cdecl; 
1069 
var gear : PGear; 

1070 
begin 

10297  1071 
if CheckLuaParamCount(L, 1, 'GetGearPos', 'gearUid') then 
6523  1072 
begin 
1073 
gear:= GearByUID(lua_tointeger(L, 1)); 

1074 
if gear <> nil then 

1075 
lua_pushinteger(L, gear^.Pos) 

1076 
else 

1077 
lua_pushnil(L); 

10287  1078 
end 
1079 
else 

1080 
lua_pushnil(L); // return value on stack (nil) 

6523  1081 
lc_getgearpos:= 1 
1082 
end; 

1083 

1084 
function lc_setgearpos(L : Plua_State) : LongInt; Cdecl; 

1085 
var gear : PGear; 

1086 
begin 

10297  1087 
if CheckLuaParamCount(L, 2, 'SetGearPos', 'gearUid, value') then 
6523  1088 
begin 
1089 
gear:= GearByUID(lua_tointeger(L, 1)); 

1090 
if gear <> nil then 

1091 
gear^.Pos:= lua_tointeger(L, 2); 

1092 
end; 

1093 
lc_setgearpos:= 0 

1094 
end; 

1095 

7726
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1096 
function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl; 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1097 
var gear : PGear; 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1098 
begin 
10297  1099 
if CheckLuaParamCount(L, 1, 'GetGearCollisionMask', 'gearUid') then 
7726
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1100 
begin 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1101 
gear:= GearByUID(lua_tointeger(L, 1)); 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1102 
if gear <> nil then 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1103 
lua_pushinteger(L, gear^.CollisionMask) 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1104 
else 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1105 
lua_pushnil(L); 
10287  1106 
end 
1107 
else 

1108 
lua_pushnil(L); // return value on stack (nil) 

7726
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1109 
lc_getgearcollisionmask:= 1 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1110 
end; 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1111 

1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1112 
function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl; 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1113 
var gear : PGear; 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1114 
begin 
10297  1115 
if CheckLuaParamCount(L, 2, 'SetGearCollisionMask', 'gearUid, mask') then 
7726
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1116 
begin 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1117 
gear:= GearByUID(lua_tointeger(L, 1)); 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1118 
if gear <> nil then 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1119 
gear^.CollisionMask:= lua_tointeger(L, 2); 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1120 
end; 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1121 
lc_setgearcollisionmask:= 0 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1122 
end; 
1137406bce12
Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents:
7721
diff
changeset

1123 

3755  1124 
function lc_gethoglevel(L : Plua_State): LongInt; Cdecl; 
1125 
var gear : PGear; 

1126 
begin 

10297  1127 
if CheckLuaParamCount(L, 1, 'GetHogLevel', 'gearUid') then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

1128 
begin 
3755  1129 
gear := GearByUID(lua_tointeger(L, 1)); 
8228
8cc5dc7f7ef9
kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents:
8145
diff
changeset

1130 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 
4372  1131 
lua_pushinteger(L, gear^.Hedgehog^.BotLevel) 
3755  1132 
else 
1133 
lua_pushnil(L); 

1134 
end; 

1135 
lc_gethoglevel := 1; 

1136 
end; 

1137 

4496  1138 
function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl; 
1139 
var gear : PGear; 

1140 
begin 

10297  1141 
if CheckLuaParamCount(L, 2, 'SetHogLevel', 'gearUid, level') then 
4496  1142 
begin 
1143 
gear:= GearByUID(lua_tointeger(L, 1)); 

1144 
if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then 

1145 
gear^.Hedgehog^.BotLevel:= lua_tointeger(L, 2); 

1146 
end; 

1147 
lc_sethoglevel:= 0 

1148 
end; 

1149 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1150 
function lc_gethogclan(L : Plua_State) : LongInt; Cdecl; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1151 
var gear : PGear; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1152 
begin 
10297  1153 
if CheckLuaParamCount(L, 1, 'GetHogClan', 'gearUid') then 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1154 
begin 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1155 
gear:= GearByUID(lua_tointeger(L, 1)); 
8228
8cc5dc7f7ef9
kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents:
8145
diff
changeset

1156 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1157 
begin 
4372  1158 
lua_pushinteger(L, gear^.Hedgehog^.Team^.Clan^.ClanIndex) 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1159 
end 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1160 
else 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1161 
lua_pushnil(L); 
10287  1162 
end 
1163 
else 

1164 
lua_pushnil(L); // return value on stack (nil) 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1165 
lc_gethogclan:= 1 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1166 
end; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1167 

4498  1168 
function lc_getclancolor(L : Plua_State) : LongInt; Cdecl; 
1169 
begin 

10297  1170 
if CheckLuaParamCount(L, 1, 'GetClanColor', 'clan') then 
10287  1171 
lua_pushinteger(L, ClansArray[lua_tointeger(L, 1)]^.Color shl 8 or $FF) 
1172 
else 

4498  1173 
lua_pushnil(L); // return value on stack (nil) 
1174 
lc_getclancolor:= 1 

1175 
end; 

1176 

4882
b4c84db92d8f
expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents:
4875
diff
changeset

1177 
function lc_setclancolor(L : Plua_State) : LongInt; Cdecl; 
4889
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1178 
var clan : PClan; 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1179 
team : PTeam; 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1180 
hh : THedgehog; 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1181 
i, j : LongInt; 
4882
b4c84db92d8f
expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents:
4875
diff
changeset

1182 
begin 
10297  1183 
if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then 
4889
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1184 
begin 
10581  1185 
i:= lua_tointeger(L,1); 
1186 
if i >= ClansCount then exit(0); 

1187 
clan := ClansArray[i]; 

4889
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1188 
clan^.Color:= lua_tointeger(L, 2) shr 8; 
9656  1189 

4889
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1190 
for i:= 0 to Pred(clan^.TeamsNumber) do 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1191 
begin 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1192 
team:= clan^.Teams[i]; 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1193 
for j:= 0 to 7 do 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1194 
begin 
4891  1195 
hh:= team^.Hedgehogs[j]; 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

1196 
if (hh.Gear <> nil) or (hh.GearHidden <> nil) then 
4889
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1197 
begin 
10634
35d059bd0932
Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents:
10618
diff
changeset

1198 
FreeAndNilTexture(hh.NameTagTex); 
10127  1199 
hh.NameTagTex:= RenderStringTex(ansistring(hh.Name), clan^.Color, fnt16); 
4889
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1200 
RenderHealth(hh); 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1201 
end; 
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1202 
end; 
10634
35d059bd0932
Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents:
10618
diff
changeset

1203 
FreeAndNilTexture(team^.NameTagTex); 
10127  1204 
team^.NameTagTex:= RenderStringTex(ansistring(clan^.Teams[i]^.TeamName), clan^.Color, fnt16); 
9656  1205 
end; 
4889
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1206 

10634
35d059bd0932
Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents:
10618
diff
changeset

1207 
FreeAndNilTexture(clan^.HealthTex); 
9656  1208 
clan^.HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, clan^.Teams[0]^.NameTagTex^.h, clan^.Color); 
1209 
end; 

4889
f71e30eb1d37
Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents:
4883
diff
changeset

1210 

4882
b4c84db92d8f
expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents:
4875
diff
changeset

1211 
lc_setclancolor:= 0 
b4c84db92d8f
expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents:
4875
diff
changeset

1212 
end; 
b4c84db92d8f
expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents:
4875
diff
changeset

1213 

4236
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1214 
function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl; 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1215 
var gear : PGear; 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1216 
begin 
10297  1217 
if CheckLuaParamCount(L, 1, 'GetHogTeamName', 'gearUid') then 
4236
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1218 
begin 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1219 
gear:= GearByUID(lua_tointeger(L, 1)); 
8228
8cc5dc7f7ef9
kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents:
8145
diff
changeset

1220 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 
4372  1221 
lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName)) 
4236
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1222 
else 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1223 
lua_pushnil(L); 
10287  1224 
end 
1225 
else 

1226 
lua_pushnil(L); // return value on stack (nil) 

4236
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1227 
lc_gethogteamname:= 1 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1228 
end; 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1229 

9788  1230 
function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl; 
1231 
var gear : PGear; 

1232 
begin 

10297  1233 
if CheckLuaParamCount(L, 2, 'SetHogTeamName', 'gearUid, name') then 
9788  1234 
begin 
1235 
gear := GearByUID(lua_tointeger(L, 1)); 

1236 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 

1237 
begin 

1238 
gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2); 

1239 

10634
35d059bd0932
Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents:
10618
diff
changeset

1240 
FreeAndNilTexture(gear^.Hedgehog^.Team^.NameTagTex); 
10127  1241 
gear^.Hedgehog^.Team^.NameTagTex:= RenderStringTex(ansistring(gear^.Hedgehog^.Team^.TeamName), gear^.Hedgehog^.Team^.Clan^.Color, fnt16); 
9788  1242 
end 
1243 
else 

1244 
lua_pushnil(L); 

10287  1245 
end 
1246 
else 

1247 
lua_pushnil(L); // return value on stack (nil) 

9788  1248 
lc_sethogteamname:= 1 
1249 
end; 

1250 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1251 
function lc_gethogname(L : Plua_State) : LongInt; Cdecl; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1252 
var gear : PGear; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1253 
begin 
10297  1254 
if CheckLuaParamCount(L, 1, 'GetHogName', 'gearUid') then 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1255 
begin 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1256 
gear:= GearByUID(lua_tointeger(L, 1)); 
8228
8cc5dc7f7ef9
kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents:
8145
diff
changeset

1257 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1258 
begin 
4372  1259 
lua_pushstring(L, str2pchar(gear^.Hedgehog^.Name)) 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1260 
end 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1261 
else 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1262 
lua_pushnil(L); 
10287  1263 
end 
1264 
else 

1265 
lua_pushnil(L); // return value on stack (nil) 

3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1266 
lc_gethogname:= 1 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1267 
end; 
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

1268 

5245
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1269 
function lc_sethogname(L : Plua_State) : LongInt; Cdecl; 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1270 
var gear : PGear; 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1271 
begin 
10297  1272 
if CheckLuaParamCount(L, 2, 'SetHogName', 'gearUid, name') then 
5245
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1273 
begin 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1274 
gear:= GearByUID(lua_tointeger(L, 1)); 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1275 
if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then 
9748
b0286b0c91ce
sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents:
9718
diff
changeset

1276 
begin 
b0286b0c91ce
sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents:
9718
diff
changeset

1277 
gear^.Hedgehog^.Name:= lua_tostring(L, 2); 
5245
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1278 

10634
35d059bd0932
Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents:
10618
diff
changeset

1279 
FreeAndNilTexture(gear^.Hedgehog^.NameTagTex); 
10127  1280 
gear^.Hedgehog^.NameTagTex:= RenderStringTex(ansistring(gear^.Hedgehog^.Name), gear^.Hedgehog^.Team^.Clan^.Color, fnt16) 
9748
b0286b0c91ce
sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents:
9718
diff
changeset

1281 
end 
5245
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1282 
end; 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1283 
lc_sethogname:= 0; 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1284 
end; 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1285 

3722  1286 
function lc_gettimer(L : Plua_State) : LongInt; Cdecl; 
1287 
var gear : PGear; 

1288 
begin 

10297  1289 
if CheckLuaParamCount(L, 1, 'GetTimer', 'gearUid') then 
3722  1290 
begin 
1291 
gear:= GearByUID(lua_tointeger(L, 1)); 

1292 
if gear <> nil then 

4484  1293 
lua_pushinteger(L, gear^.Timer) 
3722  1294 
else 
1295 
lua_pushnil(L); 

10287  1296 
end 
1297 
else 

1298 
lua_pushnil(L); // return value on stack (nil) 

3722  1299 
lc_gettimer:= 1 
1300 
end; 

1301 

10589
98ea597e5cd9
expose FlightTime to lua, disable inair flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents:
10581
diff
changeset

1302 
function lc_getflighttime(L : Plua_State) : LongInt; Cdecl; 
98ea597e5cd9
expose FlightTime to lua, disable inair flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents:
10581
diff
changeset

1303 
var gear : PGear; 
98ea597e5cd9
expose FlightTime to lua, disable inair flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents:
10581
diff
changeset

1304 
begin 
98ea597e5cd9
expose FlightTime to lua, disable inair flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents:
10581
diff
changeset

1305 
if CheckLuaParamCount(L, 1, 'GetFlightTime', 'gearUid') then 
98ea597e5cd9
expose FlightTime to lua, disable inair flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents:
10581
diff
changeset

1306 
begin 
98ea597e5cd9
expose FlightTime to lua, disable inair flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents:
10581
diff
changeset

1307 
gear:= GearByUID(lua_tointeger(L, 1)); 
98ea597e5cd9
expose FlightTime to lua, disable inair flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents:
10581
diff
