author  sheepluva 
Thu, 12 Jun 2014 05:40:58 +0200  
changeset 10281  dedc8f23e35e 
parent 10280  762c256552e9 
child 10282  f02cf95b8424 
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 

5410  51 

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

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

54 
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

55 
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

56 

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 
implementation 
7030
09984acadece
invert LUA symbol meaning and avoid hints when compiling without it
koda
parents:
7010
diff
changeset

58 
{$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

59 

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

60 
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

61 
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

62 
uConsts, 
6543  63 
uGears, 
6468  64 
uGearsList, 
6543  65 
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

66 
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

67 
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

68 
uAmmos, 
6763  69 
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

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

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

74 
uRandom, 
4359  75 
uTypes, 
4373  76 
uVariables, 
4374  77 
uCommands, 
4377  78 
uUtils, 
4403  79 
uCaptions, 
4832  80 
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

81 
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

82 
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

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

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

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

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

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

91 
, 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

92 
{$ENDIF} 
8031  93 
; 
3697  94 

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

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

98 
ScriptAmmoDelay : shortstring; 

99 
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

100 
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

101 
mapDims : boolean; 
3697  102 

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

103 
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

104 
procedure ScriptApplyAmmoStore; forward; 
9750  105 
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

106 
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

107 

3539  108 
procedure LuaError(s: shortstring); 
109 
begin 

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

110 
s:= 'Luascript error: ' + s; 
3539  111 
WriteLnToConsole(s); 
112 
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

113 
if cTestLua then 
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

114 
halt(rtnTestLuaErr); 
3539  115 
end; 
116 

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

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

118 
begin 
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

119 
LuaError(call + ': ' + error + ' function 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

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

121 

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

122 
procedure LuaParameterCountError(call, paramsyntax: shortstring; wrongcount: LongInt); 
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

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

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

125 
LuaCallError('Wrong number of parameters (' + inttostr(wrongcount) + ')!', call, paramsyntax); 
b75e7ebfbe11
fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents:
10278
diff
changeset

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

127 

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

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

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

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

133 
begin 

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

135 
LuaToGearTypeOrd:= 1; 

136 
end 

137 
else 

138 
LuaToGearTypeOrd:= i; 

139 
end; 

140 

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

142 
begin 

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

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

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

146 
begin 

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

148 
LuaToVisualGearTypeOrd:= 1; 

149 
end 

150 
else 

151 
LuaToVisualGearTypeOrd:= i; 

152 
end; 

153 

154 
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

155 
begin 
10281  156 
if lua_isnoneornil(L, i) then i:= 1 
157 
else i:= lua_tointeger(L, i); 

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

159 
begin 

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

161 
LuaToAmmoTypeOrd:= 1; 

162 
end 

163 
else 

164 
LuaToAmmoTypeOrd:= i; 

165 
end; 

166 

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

168 
begin 

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

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

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

172 
begin 

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

174 
LuaToStatInfoTypeOrd:= 1; 

175 
end 

176 
else 

177 
LuaToStatInfoTypeOrd:= i; 

178 
end; 

179 

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

181 
begin 

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

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

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

185 
begin 

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

187 
LuaToSoundOrd:= 1; 

188 
end 

189 
else 

190 
LuaToSoundOrd:= i; 

191 
end; 

192 

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

194 
begin 

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

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

197 
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

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

199 
LuaCallError('Invalid gear type!', call, paramsyntax); 
10281  200 
LuaToHogEffectOrd:= 1; 
201 
end 

202 
else 

203 
LuaToHogEffectOrd:= i; 

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

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

205 

10281  206 
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

207 
begin 
10281  208 
if lua_isnoneornil(L, i) then i:= 1 
209 
else i:= lua_tointeger(L, i); 

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

211 
begin 

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

213 
LuaToCapGroupOrd:= 1; 

214 
end 

215 
else 

216 
LuaToCapGroupOrd:= i; 

217 
end; 

218 

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

220 
begin 

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

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

223 
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

224 
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

225 
LuaCallError('Invalid sprite id!', call, paramsyntax); 
10281  226 
LuaToSpriteOrd:= 1; 
227 
end 

228 
else 

229 
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

230 
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

231 

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

232 
// 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

233 

3539  234 
// 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

235 
// 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

236 
// where L contains the state, returns the number of return values on the stack 
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

237 
// call lua_gettop(L) to receive number of parameters passed 
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

238 

4483  239 
function lc_band(L: PLua_State): LongInt; Cdecl; 
240 
begin 

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

241 
if lua_gettop(L) <> 2 then 
4483  242 
begin 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

243 
LuaParameterCountError('band', 'value1, value2', lua_gettop(L)); 
4483  244 
lua_pushnil(L); 
245 
end 

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

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

247 
lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)); 
4483  248 
lc_band := 1; 
249 
end; 

250 

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

252 
begin 

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

253 
if lua_gettop(L) <> 2 then 
4483  254 
begin 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

255 
LuaParameterCountError('bor', 'value1, value2', lua_gettop(L)); 
4483  256 
lua_pushnil(L); 
257 
end 

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

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

259 
lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)); 
4483  260 
lc_bor := 1; 
261 
end; 

262 

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

264 
begin 

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

265 
if lua_gettop(L) <> 1 then 
4483  266 
begin 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

267 
LuaParameterCountError('bnot', 'value', lua_gettop(L)); 
4483  268 
lua_pushnil(L); 
269 
end 

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

270 
else 
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
8012
diff
changeset

271 
lua_pushinteger(L, (not lua_tointeger(L, 1))); 
4483  272 
lc_bnot := 1; 
273 
end; 

274 

6764  275 
function lc_div(L: PLua_State): LongInt; Cdecl; 
276 
begin 

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

277 
if lua_gettop(L) <> 2 then 
6764  278 
begin 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

279 
LuaParameterCountError('div', 'dividend, divisor', lua_gettop(L)); 
6764  280 
lua_pushnil(L); 
281 
end 

282 
else 

7135
4d863aadd0b2
Add onGameTick20 to try and encourage lua to be a bit more efficient. Rewrite Space Invasion to use it. Top speed of aliens is 25% higher now, although that could be changed, I kinda liked it. Change parameter order of div().
nemo
parents:
7072
diff
changeset

283 
lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2)); 
6764  284 
lc_div := 1; 
285 
end; 

286 

4523  287 
function lc_getinputmask(L : Plua_State) : LongInt; Cdecl; 
288 
begin 

289 
if lua_gettop(L) <> 0 then 

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

290 
LuaParameterCountError('GetInputMask', '', lua_gettop(L)) 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

292 
lua_pushinteger(L, InputMask); 
4523  293 
lc_getinputmask:= 1 
294 
end; 

295 

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

296 
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

297 
begin 
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

298 
if lua_gettop(L) <> 1 then 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

299 
LuaParameterCountError('SetInputMask', 'mask', lua_gettop(L)) 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

301 
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

302 
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

303 
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

304 

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

305 
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

306 
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

307 
if lua_gettop(L) = 1 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

308 
begin 
5549
ccfb9b8ab9d1
sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents:
5547
diff
changeset

309 
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

310 
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

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

312 
LuaParameterCountError('WriteLnToConsole', 'string', lua_gettop(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

313 
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

314 
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

315 

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

316 
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

317 
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

318 
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

319 
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

320 
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

321 
if lua_gettop(L) = 1 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

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

323 
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

324 

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

325 
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

326 
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

327 

7805  328 
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

329 

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

330 
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

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

332 
LuaParameterCountError('ParseCommand', 'string', lua_gettop(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

333 
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

334 
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

335 

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

336 
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

337 
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

338 
if lua_gettop(L) = 5 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

339 
begin 
10127  340 
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

341 
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

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

343 
LuaParameterCountError('ShowMission', 'caption, subcaption, text, icon, time', lua_gettop(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

344 
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

345 
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

346 

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

347 
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

348 
begin 
3407  349 
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

350 
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

351 
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

352 
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

353 

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

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

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

356 
begin 
10035  357 
if lua_gettop(L) = 0 then 
358 
begin 

359 
LuaParameterCountError('EnableGameFlags', '', lua_gettop(L)); 

360 
lua_pushnil(L); 

361 
end 

362 
else 

363 
begin 

364 
for i:= 1 to lua_gettop(L) do 

365 
GameFlags := GameFlags or LongWord(lua_tointeger(L, i)); 

366 
ScriptSetInteger('GameFlags', GameFlags); 

367 
end; 

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

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

370 

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

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

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

373 
begin 
10035  374 
if lua_gettop(L) = 0 then 
375 
begin 

376 
LuaParameterCountError('DisableGameFlags', '', lua_gettop(L)); 

377 
lua_pushnil(L); 

378 
end 

379 
else 

380 
begin 

381 
for i:= 1 to lua_gettop(L) do 

10078  382 
GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i))); 
10035  383 
ScriptSetInteger('GameFlags', GameFlags); 
384 
end; 

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

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

387 

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

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

389 
begin 
10035  390 
if lua_gettop(L) <> 0 then 
391 
begin 

392 
LuaParameterCountError('ClearGameFlags', '', lua_gettop(L)); 

393 
lua_pushnil(L); 

394 
end 

395 
else 

396 
begin 

397 
GameFlags:= 0; 

398 
ScriptSetInteger('GameFlags', GameFlags); 

399 
end; 

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

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

402 

10035  403 
function lc_getgameflag(L : Plua_State) : LongInt; Cdecl; 
404 
begin 

405 
if lua_gettop(L) <> 1 then 

406 
begin 

407 
LuaParameterCountError('GetGameFlag', 'gameflag', lua_gettop(L)); 

408 
lua_pushnil(L); 

409 
end 

410 
else 

411 
begin 

412 
lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0)); 

413 
end; 

414 
lc_getgameflag:= 1; 

415 
end; 

416 

4243  417 
function lc_addcaption(L : Plua_State) : LongInt; Cdecl; 
10281  418 
var cg: LongInt; 
419 
const 

420 
call = 'AddCaption'; 

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

4243  422 
begin 
423 
if lua_gettop(L) = 1 then 

10127  424 
AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage) 
5118  425 
else if lua_gettop(L) = 3 then 
4243  426 
begin 
10281  427 
cg:= LuaToCapGroupOrd(L, 3, call, params); 
428 
AddCaption(lua_tostringA(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(cg)); 

4243  429 
end 
430 
else 

10281  431 
LuaParameterCountError(call, params, lua_gettop(L)); 
4243  432 
lc_addcaption:= 0; 
433 
end; 

434 

3848  435 
function lc_campaignlock(L : Plua_State) : LongInt; Cdecl; 
436 
begin 

437 
if lua_gettop(L) = 1 then 

438 
begin 

439 
// to be done 

440 
end 

441 
else 

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

442 
LuaParameterCountError('CampaignLock', 'TODO', lua_gettop(L)); 
3848  443 
lc_campaignlock:= 0; 
444 
end; 

445 

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

447 
begin 

448 
if lua_gettop(L) = 1 then 

449 
begin 

450 
// to be done 

451 
end 

452 
else 

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

453 
LuaParameterCountError('CampaignUnlock', 'TODO', lua_gettop(L)); 
3848  454 
lc_campaignunlock:= 0; 
455 
end; 

456 

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

457 
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

458 
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

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

460 
if lua_gettop(L) <> 4 then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

462 
LuaParameterCountError('SpawnFakeHealthCrate', 'x, y, explode, poison', lua_gettop(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

463 
lua_pushnil(L); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

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

466 
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

467 
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

468 
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

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

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

471 
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

472 
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

473 

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

474 
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

475 
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

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

477 
if lua_gettop(L) <> 4 then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

479 
LuaParameterCountError('SpawnFakeAmmoCrate', 'x, y, explode, poison', lua_gettop(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

480 
lua_pushnil(L); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

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

483 
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

484 
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

485 
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

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

487 
end; 
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

488 
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

489 
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

490 

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

491 
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

492 
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

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

494 
if lua_gettop(L) <> 4 then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

496 
LuaParameterCountError('SpawnFakeUtilityCrate', 'x, y, explode, poison', lua_gettop(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

497 
lua_pushnil(L); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

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

500 
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

501 
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

502 
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

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

504 
end; 
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

505 
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

506 
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

507 

3730  508 
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

509 
var gear: PGear; 
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

510 
var health: LongInt; 
3730  511 
begin 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

512 
if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

513 
begin 
10281  514 
LuaParameterCountError('SpawnHealthCrate', 'x, y [, health]', lua_gettop(L)); 
3730  515 
lua_pushnil(L); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

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

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

519 
if lua_gettop(L) = 3 then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

520 
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

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

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

523 
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

524 
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

525 
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

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

527 
lua_pushnil(L); 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

529 
lc_spawnhealthcrate := 1; 
3734  530 
end; 
531 

532 
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

533 
var gear: PGear; 
3734  534 
begin 
7337
c224cd2d32f3
Allow script to set number of ammo in a crate. untested.
nemo
parents:
7307
diff
changeset

535 
if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

536 
begin 
10281  537 
LuaParameterCountError('SpawnAmmoCrate', 'x, y, content [, amount]', lua_gettop(L)); 
3734  538 
lua_pushnil(L); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

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

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

542 
if (lua_gettop(L) = 3) then 
7337
c224cd2d32f3
Allow script to set number of ammo in a crate. untested.
nemo
parents:
7307
diff
changeset

543 
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

544 
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

545 
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

546 
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

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

548 
lua_pushnil(L); 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

549 
end; 
3734  550 
lc_spawnammocrate := 1; 
551 
end; 

552 

553 
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

554 
var gear: PGear; 
3734  555 
begin 
7337
c224cd2d32f3
Allow script to set number of ammo in a crate. untested.
nemo
parents:
7307
diff
changeset

556 
if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

557 
begin 
10281  558 
LuaParameterCountError('SpawnUtilityCrate', 'x, y, content [, amount]', lua_gettop(L)); 
3734  559 
lua_pushnil(L); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

561 
else 
7337
c224cd2d32f3
Allow script to set number of ammo in a crate. untested.
nemo
parents:
7307
diff
changeset

562 
begin 
7339  563 
if (lua_gettop(L) = 3) then 
7337
c224cd2d32f3
Allow script to set number of ammo in a crate. untested.
nemo
parents:
7307
diff
changeset

564 
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

565 
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

566 
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

567 
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

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

569 
lua_pushnil(L); 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

570 
end; 
3734  571 
lc_spawnutilitycrate := 1; 
3730  572 
end; 
573 

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

574 
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

575 
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

576 
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

577 
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

578 
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

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

580 
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

581 
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

582 
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

583 
if lua_gettop(L) <> 7 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

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

585 
LuaParameterCountError(call, params, lua_gettop(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

586 
lua_pushnil(L); // return value on stack (nil) 
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

587 
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

588 
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

589 
begin 
10281  590 
t:= LuaToGearTypeOrd(L, 3, call, params); 
591 
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

592 
begin 
10281  593 
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

594 
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

595 
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

596 
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

597 
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

598 
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

599 
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

600 

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

601 
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

602 
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

603 
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

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

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

606 
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

607 
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

608 
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

609 
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

610 

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

611 
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

612 
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

613 
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

614 
if lua_gettop(L) <> 1 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

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

616 
LuaParameterCountError('DeleteGear', 'gearUid', lua_gettop(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

617 
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

618 
else 
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

619 
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

620 
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

621 
if gear <> nil then 
7517  622 
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

623 
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

624 
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

625 
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

626 

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

627 
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

628 
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

629 
x, y, s: LongInt; 
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

630 
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

631 
vgt: TVisualGearType; 
10281  632 
uid: Longword; 
633 
const 

634 
call = 'AddVisualGear'; 

635 
params = 'x, y, visualGearType, state, critical'; 

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

636 
begin 
10281  637 
uid:= 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

638 
if lua_gettop(L) <> 5 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

639 
begin 
10281  640 
LuaParameterCountError(call, params, lua_gettop(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

641 
lua_pushnil(L); // return value on stack (nil) 
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

642 
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

643 
else 
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

644 
begin 
10281  645 
s:= LuaToVisualGearTypeOrd(L, 3, call, params); 
646 
if s >= 0 then 

647 
begin 

648 
vgt:= TVisualGearType(s); 

649 
x:= lua_tointeger(L, 1); 

650 
y:= lua_tointeger(L, 2); 

651 
s:= lua_tointeger(L, 4); 

652 
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

653 

10281  654 
vg:= AddVisualGear(x, y, vgt, s, c); 
655 
if vg <> nil then 

656 
begin 

657 
lastVisualGearByUID:= vg; 

658 
uid:= vg^.uid; 

659 
end; 

660 
end; 

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

661 
end; 
10281  662 
lua_pushinteger(L, uid); 
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

663 
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

664 
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

665 

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

666 
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

667 
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

668 
begin 
10281  669 
vg:= 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

670 
if lua_gettop(L) <> 1 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

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

672 
LuaParameterCountError('DeleteVisualGear', 'vgUid', lua_gettop(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

673 
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

674 
else 
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

675 
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

676 
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

677 
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

678 
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

679 
end; 
10281  680 
// allow caller to know whether there was something to delete 
681 
lua_pushboolean(L, vg <> nil); 

682 
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

683 
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

684 

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

685 
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

686 
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

687 
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

688 
if lua_gettop(L) <> 1 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

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

690 
LuaParameterCountError('GetVisualGearValues', 'vgUid', lua_gettop(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

691 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 
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

692 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L) 
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

693 
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

694 
else 
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

695 
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

696 
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

697 
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

698 
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

699 
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

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

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

702 
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

703 
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

704 
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

705 
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

706 
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

707 
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

708 
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

709 
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

710 
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

711 
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

712 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 
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

713 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L) 
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

714 
end 
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

715 
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

716 
lc_getvisualgearvalues:= 10; 
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

717 
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

718 

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

719 
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

720 
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

721 
begin 
4450  722 
if lua_gettop(L) <> 11 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

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

724 
LuaParameterCountError('SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint', lua_gettop(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

725 
lua_pushnil(L); // return value on stack (nil) 
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

726 
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

727 
else 
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

728 
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

729 
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

730 
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

731 
begin 
4450  732 
vg^.X:= lua_tointeger(L, 2); 
733 
vg^.Y:= lua_tointeger(L, 3); 

5075
59b13b38a827
not useful for visual gears, and apparently not helpful for consistency
nemo
parents:
5074
diff
changeset

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

735 
vg^.dY:= lua_tonumber(L, 5); 
4450  736 
vg^.Angle:= lua_tonumber(L, 6); 
737 
vg^.Frame:= lua_tointeger(L, 7); 

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

738 
if lua_tointeger(L, 8) <> 0 then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

739 
vg^.FrameTicks:= lua_tointeger(L, 8); // find a better way to do this. maybe need to break all these up. 
4450  740 
vg^.State:= lua_tointeger(L, 9); 
741 
vg^.Timer:= lua_tointeger(L, 10); 

742 
vg^.Tint:= lua_tointeger(L, 11); 

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

743 
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

744 
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

745 
lc_setvisualgearvalues:= 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

746 
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

747 

3058  748 
function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl; 
749 
begin 

750 
if lua_gettop(L) <> 0 then 

751 
begin 

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

752 
LuaParameterCountError('GetFollowGear', '', lua_gettop(L)); 
3058  753 
lua_pushnil(L); // return value on stack (nil) 
754 
end 

755 
else 

756 
if FollowGear = nil then 

757 
lua_pushnil(L) 

758 
else 

4484  759 
lua_pushinteger(L, FollowGear^.uid); 
3058  760 
lc_getfollowgear:= 1; // 1 return value 
761 
end; 

762 

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

763 
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

764 
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

765 
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

766 
if lua_gettop(L) <> 1 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

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

768 
LuaParameterCountError('GetGearType', 'gearUid', lua_gettop(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

769 
lua_pushnil(L); // return value on stack (nil) 
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

770 
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

771 
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

772 
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

773 
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

774 
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

775 
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

776 
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

777 
lua_pushnil(L); 
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

778 
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

779 
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

780 
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

781 

3892  782 
function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl; 
783 
var gear : PGear; 

784 
begin 

785 
if lua_gettop(L) <> 1 then 

786 
begin 

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

787 
LuaParameterCountError('GetGearMessage', 'gearUid', lua_gettop(L)); 
3892  788 
lua_pushnil(L); // return value on stack (nil) 
789 
end 

790 
else 

791 
begin 

792 
gear:= GearByUID(lua_tointeger(L, 1)); 

793 
if gear <> nil then 

794 
lua_pushinteger(L, gear^.message) 

795 
else 

796 
lua_pushnil(L); 

797 
end; 

798 
lc_getgearmessage:= 1 

799 
end; 

800 

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

801 
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

802 
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

803 
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

804 
if lua_gettop(L) <> 1 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

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

806 
LuaParameterCountError('GetGearElasticity', 'gearUid', lua_gettop(L)); 
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

807 
lua_pushnil(L); // return value on stack (nil) 
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

808 
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

809 
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

810 
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

811 
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

812 
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

813 
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

814 
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

815 
lua_pushnil(L); 
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

816 
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

817 
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

818 
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

819 

3896  820 
function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl; 
821 
var gear : PGear; 

822 
begin 

823 
if lua_gettop(L) <> 2 then 

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

824 
LuaParameterCountError('SetGearMessage', 'gearUid, message', lua_gettop(L)) 
3896  825 
else 
826 
begin 

827 
gear:= GearByUID(lua_tointeger(L, 1)); 

828 
if gear <> nil then 

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

830 
end; 

831 
lc_setgearmessage:= 0 

832 
end; 

833 

6523  834 
function lc_getgearpos(L : Plua_State) : LongInt; Cdecl; 
835 
var gear : PGear; 

836 
begin 

837 
if lua_gettop(L) <> 1 then 

838 
begin 

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

839 
LuaParameterCountError('GetGearPos', 'gearUid', lua_gettop(L)); 
6523  840 
lua_pushnil(L); // return value on stack (nil) 
841 
end 

842 
else 

843 
begin 

844 
gear:= GearByUID(lua_tointeger(L, 1)); 

845 
if gear <> nil then 

846 
lua_pushinteger(L, gear^.Pos) 

847 
else 

848 
lua_pushnil(L); 

849 
end; 

850 
lc_getgearpos:= 1 

851 
end; 

852 

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

854 
var gear : PGear; 

855 
begin 

856 
if lua_gettop(L) <> 2 then 

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

857 
LuaParameterCountError('SetGearPos', 'gearUid, value', lua_gettop(L)) 
6523  858 
else 
859 
begin 

860 
gear:= GearByUID(lua_tointeger(L, 1)); 

861 
if gear <> nil then 

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

863 
end; 

864 
lc_setgearpos:= 0 

865 
end; 

866 

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

867 
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

868 
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

869 
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

870 
if lua_gettop(L) <> 1 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

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

872 
LuaParameterCountError('GetGearCollisionMask', 'gearUid', lua_gettop(L)); 
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

873 
lua_pushnil(L); // return value on stack (nil) 
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

874 
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

875 
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

876 
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

877 
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

878 
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

879 
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

880 
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

881 
lua_pushnil(L); 
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

882 
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

883 
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

884 
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

885 

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

886 
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

887 
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

888 
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

889 
if lua_gettop(L) <> 2 then 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

890 
LuaParameterCountError('SetGearCollisionMask', 'gearUid, mask', lua_gettop(L)) 
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

891 
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

892 
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

893 
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

894 
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

895 
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

896 
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

897 
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

898 
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

899 

3755  900 
function lc_gethoglevel(L : Plua_State): LongInt; Cdecl; 
901 
var gear : PGear; 

902 
begin 

903 
if lua_gettop(L) <> 1 then 

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

904 
LuaParameterCountError('GetHogLevel', 'gearUid', lua_gettop(L)) 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

906 
begin 
3755  907 
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

908 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 
4372  909 
lua_pushinteger(L, gear^.Hedgehog^.BotLevel) 
3755  910 
else 
911 
lua_pushnil(L); 

912 
end; 

913 
lc_gethoglevel := 1; 

914 
end; 

915 

4496  916 
function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl; 
917 
var gear : PGear; 

918 
begin 

919 
if lua_gettop(L) <> 2 then 

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

920 
LuaParameterCountError('SetHogLevel', 'gearUid, level', lua_gettop(L)) 
4496  921 
else 
922 
begin 

923 
gear:= GearByUID(lua_tointeger(L, 1)); 

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

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

926 
end; 

927 
lc_sethoglevel:= 0 

928 
end; 

929 

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

930 
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

931 
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

932 
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

933 
if lua_gettop(L) <> 1 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

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

935 
LuaParameterCountError('GetHogClan', 'gearUid', lua_gettop(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

936 
lua_pushnil(L); // return value on stack (nil) 
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

937 
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

938 
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

939 
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

940 
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

941 
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

942 
begin 
4372  943 
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

944 
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

945 
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

946 
lua_pushnil(L); 
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

947 
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

948 
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

949 
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

950 

4498  951 
function lc_getclancolor(L : Plua_State) : LongInt; Cdecl; 
952 
begin 

953 
if lua_gettop(L) <> 1 then 

954 
begin 

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

955 
LuaParameterCountError('GetClanColor', 'clan', lua_gettop(L)); 
4498  956 
lua_pushnil(L); // return value on stack (nil) 
957 
end 

4499  958 
else lua_pushinteger(L, ClansArray[lua_tointeger(L, 1)]^.Color shl 8 or $FF); 
4498  959 
lc_getclancolor:= 1 
960 
end; 

961 

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

962 
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

963 
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

964 
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

965 
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

966 
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

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

968 
if lua_gettop(L) <> 2 then 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

969 
LuaParameterCountError('SetClanColor', 'clan, color', lua_gettop(L)) 
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

970 
else 
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

971 
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

972 
clan := ClansArray[lua_tointeger(L, 1)]; 
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

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

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

975 
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

976 
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

977 
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

978 
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

979 
begin 
4891  980 
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

981 
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

982 
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

983 
FreeTexture(hh.NameTagTex); 
10127  984 
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

985 
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

986 
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

987 
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

988 
FreeTexture(team^.NameTagTex); 
10127  989 
team^.NameTagTex:= RenderStringTex(ansistring(clan^.Teams[i]^.TeamName), clan^.Color, fnt16); 
9656  990 
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

991 

9656  992 
clan^.HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, clan^.Teams[0]^.NameTagTex^.h, clan^.Color); 
993 
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

994 

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

995 
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

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

997 

4236
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

998 
function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl; 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

999 
var gear : PGear; 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1000 
begin 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1001 
if lua_gettop(L) <> 1 then 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

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

1003 
LuaParameterCountError('GetHogTeamName', 'gearUid', lua_gettop(L)); 
4236
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1004 
lua_pushnil(L); // return value on stack (nil) 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1005 
end 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1006 
else 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1007 
begin 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1008 
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

1009 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 
4236
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1010 
begin 
4372  1011 
lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName)) 
4236
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1012 
end 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1013 
else 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1014 
lua_pushnil(L); 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1015 
end; 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1016 
lc_gethogteamname:= 1 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1017 
end; 
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

1018 

9788  1019 
function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl; 
1020 
var gear : PGear; 

1021 
begin 

1022 
if lua_gettop(L) <> 2 then 

1023 
begin 

1024 
LuaParameterCountError('SetHogTeamName', 'gearUid, name', lua_gettop(L)); 

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

1026 
end 

1027 
else 

1028 
begin 

1029 
gear := GearByUID(lua_tointeger(L, 1)); 

1030 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 

1031 
begin 

1032 
gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2); 

1033 

1034 
FreeTexture(gear^.Hedgehog^.Team^.NameTagTex); 

10127  1035 
gear^.Hedgehog^.Team^.NameTagTex:= RenderStringTex(ansistring(gear^.Hedgehog^.Team^.TeamName), gear^.Hedgehog^.Team^.Clan^.Color, fnt16); 
9788  1036 
end 
1037 
else 

1038 
lua_pushnil(L); 

1039 
end; 

1040 
lc_sethogteamname:= 1 

1041 
end; 

1042 

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

1043 
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

1044 
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

1045 
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

1046 
if lua_gettop(L) <> 1 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

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

1048 
LuaParameterCountError('GetHogName', 'gearUid', lua_gettop(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

1049 
lua_pushnil(L); // return value on stack (nil) 
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

1050 
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

1051 
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

1052 
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

1053 
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

1054 
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

1055 
begin 
4372  1056 
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

1057 
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

1058 
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

1059 
lua_pushnil(L); 
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

1060 
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

1061 
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

1062 
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

1063 

5245
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1064 
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

1065 
var gear : PGear; 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1066 
begin 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1067 
if lua_gettop(L) <> 2 then 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

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

1069 
LuaParameterCountError('SetHogName', 'gearUid, name', lua_gettop(L)); 
5245
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1070 
lua_pushnil(L) 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1071 
end 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1072 
else 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1073 
begin 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1074 
gear:= GearByUID(lua_tointeger(L, 1)); 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1075 
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

1076 
begin 
b0286b0c91ce
sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents:
9718
diff
changeset

1077 
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

1078 

9748
b0286b0c91ce
sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents:
9718
diff
changeset

1079 
FreeTexture(gear^.Hedgehog^.NameTagTex); 
10127  1080 
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

1081 
end 
5245
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1082 
end; 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1083 
lc_sethogname:= 0; 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1084 
end; 
ce407084728f
Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents:
5243
diff
changeset

1085 

3722  1086 
function lc_gettimer(L : Plua_State) : LongInt; Cdecl; 
1087 
var gear : PGear; 

1088 
begin 

1089 
if lua_gettop(L) <> 1 then 

1090 
begin 

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

1091 
LuaParameterCountError('GetTimer', 'gearUid', lua_gettop(L)); 
3722  1092 
lua_pushnil(L); // return value on stack (nil) 
1093 
end 

1094 
else 

1095 
begin 

1096 
gear:= GearByUID(lua_tointeger(L, 1)); 

1097 
if gear <> nil then 

4484  1098 
lua_pushinteger(L, gear^.Timer) 
3722  1099 
else 
1100 
lua_pushnil(L); 

1101 
end; 

1102 
lc_gettimer:= 1 

1103 
end; 

1104 

1105 
function lc_gethealth(L : Plua_State) : LongInt; Cdecl; 

1106 
var gear : PGear; 

1107 
begin 

1108 
if lua_gettop(L) <> 1 then 

1109 
begin 

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

1110 
LuaParameterCountError('GetHealth', 'gearUid', lua_gettop(L)); 
3722  1111 
lua_pushnil(L); // return value on stack (nil) 
1112 
end 

1113 
else 

1114 
begin 

1115 
gear:= GearByUID(lua_tointeger(L, 1)); 

1116 
if gear <> nil then 

4484  1117 
lua_pushinteger(L, gear^.Health) 
3722  1118 
else 
1119 
lua_pushnil(L); 

1120 
end; 

1121 
lc_gethealth:= 1 

1122 
end; 

1123 

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

1124 
function lc_getx(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

1125 
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

1126 
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

1127 
if lua_gettop(L) <> 1 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

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

1129 
LuaParameterCountError('GetX', 'gearUid', lua_gettop(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

1130 
lua_pushnil(L); // return value on stack (nil) 
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

1131 
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

1132 
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

1133 
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

1134 
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

1135 
if gear <> nil then 
4484  1136 
lua_pushinteger(L, hwRound(gear^.X)) 
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

1137 
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

1138 
lua_pushnil(L); 
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

1139 
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

1140 
lc_getx:= 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

1141 
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

1142 

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

1143 
function lc_gety(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

1144 
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

1145 
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

1146 
if lua_gettop(L) <> 1 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

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

1148 
LuaParameterCountError('GetY', 'gearUid', lua_gettop(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

1149 
lua_pushnil(L); // return value on stack (nil) 
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 
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

1151 
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

1152 
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

1153 
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

1154 
if gear <> nil then 
4484  1155 
lua_pushinteger(L, hwRound(gear^.Y)) 
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

1156 
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

1157 
lua_pushnil(L); 
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

1158 
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

1159 
lc_gety:= 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

1160 
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

1161 

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

1162 
function lc_copypv(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

1163 
var gears, geard : 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

1164 
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

1165 
if lua_gettop(L) <> 2 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

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

1167 
LuaParameterCountError('CopyPV', 'fromGearUid, toGearUid', lua_gettop(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

1168 
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

1169 
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

1170 
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

1171 
gears:= 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

1172 
geard:= GearByUID(lua_tointeger(L, 2)); 
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

1173 
if (gears <> nil) and (geard <> 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

1174 
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

1175 
geard^.X:= gears^.X; 
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

1176 
geard^.Y:= gears^.Y; 
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

1177 
geard^.dX:= gears^.dX; 
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

1178 
geard^.dY:= gears^.dY; 
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

1179 
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

1180 
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

1181 
lc_copypv:= 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

1182 
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

1183 

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

1184 
function lc_followgear(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

1185 
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

1186 
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

1187 
if lua_gettop(L) <> 1 then 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

1188 
LuaParameterCountError('FollowGear', 'gearUid', lua_gettop(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

1189 
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

1190 
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

1191 
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

1192 
if gear <> nil then FollowGear:= gear 
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

1193 
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

1194 
lc_followgear:= 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

1195 
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

1196 

3761  1197 
function lc_hogsay(L : Plua_State) : LongInt; Cdecl; 
1198 
var gear : PGear; 

1199 
vgear : PVisualGear; 

4533  1200 
s : LongWord; 
3761  1201 
begin 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

1202 
if lua_gettop(L) = 4 then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

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

1205 
s:= 0; 
4533  1206 

1207 
if (lua_gettop(L) = 4) or (lua_gettop(L) = 3) then 

3761  1208 
begin 
1209 
gear:= GearByUID(lua_tointeger(L, 1)); 

1210 
if gear <> nil then 

1211 
begin 

4533  1212 
vgear:= AddVisualGear(0, 0, vgtSpeechBubble, s, true); 
3761  1213 
if vgear <> nil then 
1214 
begin 

10210
1a6b9a98147c
hm. I think I forgot to commit this when adding speech bubble change
nemo
parents:
10150
diff
changeset

1215 
if Gear^.Kind = gtHedgehog then 
1a6b9a98147c
hm. I think I forgot to commit this when adding speech bubble change
nemo
parents:
10150
diff
changeset

1216 
begin 
1a6b9a98147c
hm. I think I forgot to commit this when adding speech bubble change
nemo
parents:
10150
diff
changeset

1217 
AddChatString(#1+'[' + gear^.Hedgehog^.Name + '] '+vgear^.text); 
1a6b9a98147c
hm. I think I forgot to commit this when adding speech bubble change
nemo
parents:
10150
diff
changeset

1218 
vgear^.Hedgehog:= gear^.Hedgehog 
1a6b9a98147c
hm. I think I forgot to commit this when adding speech bubble change
nemo
parents:
10150
diff
changeset

1219 
end 
1a6b9a98147c
hm. I think I forgot to commit this when adding speech bubble change
nemo
parents:
10150
diff
changeset

1220 
else vgear^.Frame:= gear^.uid; 
1a6b9a98147c
hm. I think I forgot to commit this when adding speech bubble change
nemo
parents:
10150
diff
changeset

1221 

5549
ccfb9b8ab9d1
sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents:
5547
diff
changeset

1222 
vgear^.Text:= lua_tostring(L, 2); 
3761  1223 
vgear^.FrameTicks:= lua_tointeger(L, 3); 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

1224 
if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then 
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

1225 
vgear^.FrameTicks:= 1; 
9764
8dc9d268330f
revert r938d1c08d0d1 in favour of putting it in the chat log. I think this addresses main concern about missing text. There've been complaints in past too about conversation in bubbles not being visible in history. If the objection is that r938d1c08d0d1 offers a more Ã¦sthetic solution, I think it should augment this, be flagged, and fix the visual issues first.
nemo
parents:
9752
diff
changeset

1226 
lua_pushinteger(L, vgear^.Uid); 
5529  1227 
end 
3761  1228 
end 
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6578
diff
changeset

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

1230 
lua_pushnil(L) 
4533  1231 
end 
10281  1232 
else LuaParameterCountError('HogSay', 'gearUid, text, manner [, vgState]', lua_gettop(L)); 
5529  1233 
lc_hogsay:= 1 
3761  1234 
end; 
1235 

4851  1236 
function lc_switchhog(L : Plua_State) : LongInt; Cdecl; 
1237 
var gear, prevgear : PGear; 

1238 
begin 

1239 
if lua_gettop(L) <> 1 then 

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

1240 
LuaParameterCountError('SwitchHog', 'gearUid', lua_gettop(L)) 
4851  1241 
else 
1242 
begin 

1243 
gear:= GearByUID(lua_tointeger(L, 1)); 

1244 
// should we allow this when there is no current hedgehog? might do some odd(er) things to turn sequence. 

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

1246 
begin 

1247 
prevgear := CurrentHedgehog^.Gear; 

7573  1248 
if prevgear <> nil then 
1249 
begin 

1250 
prevgear^.Active := false; 

1251 
prevgear^.State:= prevgear^.State and (not gstHHDriven); 

1252 
prevgear^.Z := cHHZ; 

1253 
prevgear^.Message:= prevgear^.Message or gmRemoveFromList or gmAddToList; 

1254 
end; 

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

1255 

7270
93e92e82d5c8
Step 1. Add current hedgehog as top bit of bottom byte.
nemo
parents:
7156
diff
changeset

1256 
SwitchCurrentHedgehog(gear^.Hedgehog); 
93e92e82d5c8
Step 1. Add current hedgehog as top bit of bottom byte.
nemo
parents:
7156
diff
changeset

1257 
CurrentTeam:= CurrentHedgehog^.Team; 
4851  1258 

1259 
gear^.State:= gear^.State or gstHHDriven; 

1260 
gear^.Active := true; 

1261 
gear^.Z := cCurrHHZ; 

7401  1262 
gear^.Message:= gear^.Message or gmRemoveFromList or gmAddToList; 
4851  1263 
end 
1264 
end; 

1265 
lc_switchhog:= 0 

1266 
end; 

1267 

4481  1268 
function lc_addammo(L : Plua_State) : LongInt; Cdecl; 
1269 
var gear : PGear; 

10281  1270 
at : LongInt; 
1271 
const 

1272 
call = 'AddAmmo'; 

1273 
params = 'gearUid, ammoType [, ammoCount]'; 

4481  1274 
begin 
5272  1275 
if (lua_gettop(L) = 3) or (lua_gettop(L) = 2) then 
4481  1276 
begin 
10281  1277 
at:= LuaToAmmoTypeOrd(L, 2, call, params); 
1278 
if at >= 0 then 

1279 
begin 

1280 
gear:= GearByUID(lua_tointeger(L, 1)); 

1281 
if (gear <> nil) and (gear^.Hedgehog <> nil) then 

1282 
if lua_gettop(L) = 2 then 

1283 
AddAmmo(gear^.Hedgehog^, TAmmoType(at)) 

1284 
else 

1285 
SetAmmo(gear^.Hedgehog^, TAmmoType(at), lua_tointeger(L, 3)) 

1286 
end; 

5272  1287 
end 
10281  1288 
else LuaParameterCountError(call, params, lua_gettop(L)); 
4481  1289 
lc_addammo:= 0 
1290 
end; 

1291 

5676
a655dfab27d7
Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents:
5638
diff
changeset

1292 
function lc_getammocount(L : Plua_State) : LongInt; Cdecl; 
a655dfab27d7
Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents:
5638
diff
changeset

1293 
var gear : PGear; 
a655dfab27d7
Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents:
5638
diff
changeset

1294 
ammo : PAmmo; 
10281  1295 
at : LongInt; 
1296 
const 

1297 
call = 'GetAmmoCount'; 

1298 
params = 'gearUid, ammoType'; 

5676
a655dfab27d7
Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents:
5638
diff
changeset

1299 
begin 
10281  1300 
if (lua_gettop(L) <> 2) then 
1301 
begin 

1302 
LuaParameterCountError(call, params, lua_gettop(L)); 

1303 
lua_pushnil(L); 

1304 
end 

1305 
else 

5676
a655dfab27d7
Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents:
5638
diff
changeset

1306 
begin 
a655dfab27d7
Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents:
5638
diff
changeset

1307 
gear:= GearByUID(lua_tointeger(L, 1)); 
9752
656c511ab0f3
here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents:
9751
diff
changeset

1308 
if (gear <> nil) and (gear^.Hedgehog <> nil) then 
5676
a655dfab27d7
Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents:
5638
diff
changeset

1309 
begin 
10281  1310 
at:= LuaToAmmoTypeOrd(L, 2, call, params); 
1311 
if at >= 0 then 

1312 
begin 

1313 
ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at)); 

1314 
if ammo^.AmmoType = amNothing then 

1315 
lua_pushinteger(L, 0) 

1316 
else 

1317 
lua_pushinteger(L, ammo^.Count); 
