author  sheepluva 
Wed, 02 Sep 2015 00:39:35 +0200  
changeset 11058  b91667fd6f20 
parent 11052  f55a49bd13b9 
child 11060  506b6184f4af 
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 
11046  3 
* Copyright (c) 20042015 Andrey Korotaev <unC0Rr@gmail.com> 
3043
3acdb4dac6eb
Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents:
3038
diff
changeset

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

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

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

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

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

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

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

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

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

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

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

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

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

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

18 

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

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

20 

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

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

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

25 
* 

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

27 
* 

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

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

30 
* unnoticed and render the parameter useless!) 

31 
*) 

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

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

33 

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

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

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

36 

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

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

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

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

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

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

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

43 

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

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

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

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

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

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

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

50 

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

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

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

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

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

57 

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

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

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

60 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

88 
uVisualGearsList, 
9285  89 
uGearsHandlersMess, 
10978
54a49174dbec
cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents:
10903
diff
changeset

90 
uPhysFSLayer, 
54a49174dbec
cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents:
10903
diff
changeset

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

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

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

94 
{$ENDIF} 
8031  95 
; 
3697  96 

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

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

100 
ScriptAmmoDelay : shortstring; 

101 
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

102 
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

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

104 
PointsBuffer: shortstring; 
10978
54a49174dbec
cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents:
10903
diff
changeset

105 
prevCursorPoint: TPoint; // why is tpoint still in sdlh... 
3697  106 

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

108 
procedure ScriptApplyAmmoStore; forward; 
9750  109 
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

110 
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

111 

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

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

113 

10617  114 
procedure SetGlobals; forward; 
10312  115 
procedure LuaParseString(s: shortString); 
116 
begin 

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

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

121 
begin 

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

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

124 
end; 

125 
end; 

126 

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

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

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

130 

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

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

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

133 

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

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

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

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

138 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

152 
s:= 'LUA ERROR: ' + s; 
3539  153 
WriteLnToConsole(s); 
154 
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

155 
if cTestLua then 
10306  156 
halt(HaltTestLuaError); 
3539  157 
end; 
158 

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

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

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

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

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

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

164 

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

167 
// TODO: i18n? 

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

169 
end; 

170 

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

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

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

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

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

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

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

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

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

181 

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

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

184 

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

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

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

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

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

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

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

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

194 

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

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

197 

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

200 
begin 

201 
actual:= lua_gettop(L); 

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

203 
begin 

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

205 
exit(false); 

206 
end; 

207 

208 
CheckAndFetchParamCountRange:= true; 

209 
end; 

210 

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

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

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

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

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

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

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

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

220 

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

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

223 

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

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

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

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

229 
begin 

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

231 
LuaToGearTypeOrd:= 1; 

232 
end 

233 
else 

234 
LuaToGearTypeOrd:= i; 

235 
end; 

236 

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

238 
begin 

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

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

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

242 
begin 

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

244 
LuaToVisualGearTypeOrd:= 1; 

245 
end 

246 
else 

247 
LuaToVisualGearTypeOrd:= i; 

248 
end; 

249 

250 
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

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

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

255 
begin 

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

257 
LuaToAmmoTypeOrd:= 1; 

258 
end 

259 
else 

260 
LuaToAmmoTypeOrd:= i; 

261 
end; 

262 

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

264 
begin 

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

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

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

268 
begin 

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

270 
LuaToStatInfoTypeOrd:= 1; 

271 
end 

272 
else 

273 
LuaToStatInfoTypeOrd:= i; 

274 
end; 

275 

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

277 
begin 

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

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

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

281 
begin 

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

283 
LuaToSoundOrd:= 1; 

284 
end 

285 
else 

286 
LuaToSoundOrd:= i; 

287 
end; 

288 

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

290 
begin 

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

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

293 
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

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

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

298 
else 

299 
LuaToHogEffectOrd:= i; 

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

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

301 

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

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

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

307 
begin 

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

309 
LuaToCapGroupOrd:= 1; 

310 
end 

311 
else 

312 
LuaToCapGroupOrd:= i; 

313 
end; 

314 

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

316 
begin 

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

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

319 
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

320 
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

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

324 
else 

325 
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

326 
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

327 

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

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

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

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

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

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

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

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

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

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

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

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

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

340 

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

342 

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

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

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

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

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

350 

4483  351 
function lc_band(L: PLua_State): LongInt; Cdecl; 
352 
begin 

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

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

355 
else 
4483  356 
lua_pushnil(L); 
357 
lc_band := 1; 

358 
end; 

359 

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

361 
begin 

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

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

364 
else 
4483  365 
lua_pushnil(L); 
366 
lc_bor := 1; 

367 
end; 

368 

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

370 
begin 

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

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

373 
else 
4483  374 
lua_pushnil(L); 
375 
lc_bnot := 1; 

376 
end; 

377 

6764  378 
function lc_div(L: PLua_State): LongInt; Cdecl; 
379 
begin 

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

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

382 
else 
6764  383 
lua_pushnil(L); 
384 
lc_div := 1; 

385 
end; 

386 

4523  387 
function lc_getinputmask(L : Plua_State) : LongInt; Cdecl; 
388 
begin 

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

390 
lua_pushinteger(L, InputMask); 
4523  391 
lc_getinputmask:= 1 
392 
end; 

393 

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

394 
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

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

397 
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

398 
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

399 
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

400 

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

401 
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

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

404 
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

405 
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

406 
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

407 

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

408 
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

409 
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

410 
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

411 
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

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

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

415 
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

416 

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

417 
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

418 
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

419 

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

421 

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

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

423 
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

424 
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

425 

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

429 
const 

430 
call = 'SetWeapon'; 

431 
params = 'ammoType'; 

432 
begin 

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

437 
if at >= 0 then 

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

439 
end; 

440 
lc_setweapon:= 0; 

441 
end; 

442 

11058
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

443 
// no parameter means reset to default (and 0 means unlimited) 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

444 
function lc_setmaxbuilddistance(L : Plua_State) : LongInt; Cdecl; 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

445 
var np: LongInt; 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

446 
const 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

447 
call = 'SetMaxBuildDistance'; 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

448 
params = '[ distInPx ]'; 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

449 
begin 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

450 
if CheckAndFetchParamCountRange(L, 0, 1, call, params, np) then 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

451 
begin 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

452 
if np = 0 then 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

453 
begin 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

454 
// no args? reset 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

455 
cBuildMaxDist:= cDefaultBuildMaxDist; 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

456 
end 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

457 
else 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

458 
CBuildMaxDist:= lua_tointeger(L, 1); 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

459 
end; 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

460 
lc_setmaxbuilddistance:= 0; 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

461 
end; 
b91667fd6f20
Lua API: SetMaxBuildDistance([ distInPx ])  set to 0 for no limit; call with no param to reset to default
sheepluva
parents:
11052
diff
changeset

462 

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

465 
var at : LongInt; 

466 
nextAmmo : TAmmo; 

467 
s, a, cs, fa: LongInt; 

468 
const 

469 
call = 'SetNextWeapon'; 

470 
params = ''; 

471 
begin 

10297  472 
if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, call, params)) then 
10291  473 
begin 
474 
at:= 1; 

475 
with CurrentHedgehog^ do 

476 
begin 

477 
cs:= 0; // current slot 

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

479 

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

481 
if curAmmoType <> amNothing then 

482 
begin 

483 
// get current slot index 

484 
cs:= Ammoz[CurAmmoType].Slot; 

485 
// find current ammo index 

486 
while (fa < cMaxSlotAmmoIndex) 

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

488 
inc(fa); 

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

490 
inc(fa); 

491 
end; 

492 

493 
// find first available ammo 

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

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

496 
begin 

497 
for a:= fa to cMaxSlotAmmoIndex do 

498 
begin 

499 
// check if we went full circle 

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

501 
exit(0); 

502 

503 
// get ammo 

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

505 
// only switch to ammos the hog actually has 

506 
if (nextAmmo.AmmoType <> amNothing) 

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

508 
begin 

509 
at:= ord(nextAmmo.AmmoType); 

510 
break; 

511 
end; 

512 
end; 

513 
// stop slot loop if something was found 

514 
if at >= 0 then 

515 
break; 

516 
// check following slots starting with first item 

517 
fa:= 0; 

518 
end; 

519 
end; 

520 

521 
if at >= 0 then 

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

523 
end; 

524 
lc_setnextweapon:= 0; 

525 
end; 

526 

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

527 
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

528 
begin 
10297  529 
if CheckLuaParamCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then 
10127  530 
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

531 
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

532 
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

533 

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

534 
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

535 
begin 
3407  536 
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

537 
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

538 
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

539 
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

540 

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

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

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

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

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

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

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

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

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

553 

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

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

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

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

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

560 
for i:= 1 to n do 
10078  561 
GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i))); 
10035  562 
ScriptSetInteger('GameFlags', GameFlags); 
563 
end; 

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

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

566 

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

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

568 
begin 
10297  569 
if CheckLuaParamCount(L, 0, 'ClearGameFlags', '') then 
10035  570 
begin 
571 
GameFlags:= 0; 

572 
ScriptSetInteger('GameFlags', GameFlags); 

573 
end; 

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

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

576 

10035  577 
function lc_getgameflag(L : Plua_State) : LongInt; Cdecl; 
578 
begin 

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

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

581 
else 
10035  582 
lua_pushnil(L); 
583 
lc_getgameflag:= 1; 

584 
end; 

585 

4243  586 
function lc_addcaption(L : Plua_State) : LongInt; Cdecl; 
10281  587 
var cg: LongInt; 
588 
const 

589 
call = 'AddCaption'; 

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

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

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

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

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

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

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

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

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

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

602 
end; 
4243  603 
lc_addcaption:= 0; 
604 
end; 

605 

3848  606 
function lc_campaignlock(L : Plua_State) : LongInt; Cdecl; 
607 
begin 

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

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

611 
end; 
3848  612 
lc_campaignlock:= 0; 
613 
end; 

614 

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

616 
begin 

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

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

620 
end; 
3848  621 
lc_campaignunlock:= 0; 
622 
end; 

623 

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

624 
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

625 
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

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

628 
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

629 
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

630 
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

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

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

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

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

635 
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

636 
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

637 

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

638 
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

639 
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

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

642 
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

643 
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

644 
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

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

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

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

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

649 
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

650 
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

651 

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

652 
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

653 
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

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

656 
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

657 
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

658 
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

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

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

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

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

663 
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

664 
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

665 

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

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

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

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

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

673 
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

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

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

676 
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

677 
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

678 
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

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

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

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

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

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

684 
lc_spawnhealthcrate := 1; 
3734  685 
end; 
686 

687 
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

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

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

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

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

694 
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

695 
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

696 
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

697 
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

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

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

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

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

702 
lua_pushnil(L); 
3734  703 
lc_spawnammocrate := 1; 
704 
end; 

705 

706 
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

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

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

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

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

713 
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

714 
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

715 
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

716 
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

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

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

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

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

721 
lua_pushnil(L); 
3734  722 
lc_spawnutilitycrate := 1; 
3730  723 
end; 
724 

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

725 
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

726 
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

727 
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

728 
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

729 
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

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

731 
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

732 
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

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

735 
begin 
10281  736 
t:= LuaToGearTypeOrd(L, 3, call, params); 
737 
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

738 
begin 
10281  739 
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

740 
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

741 
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

742 
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

743 
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

744 
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

745 
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

746 

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

747 
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

748 
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

749 
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

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

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

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

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

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

755 
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

756 
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

757 
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

758 

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

759 
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

760 
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

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

763 
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

764 
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

765 
if gear <> nil then 
7517  766 
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

767 
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

768 
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

769 
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

770 

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

771 
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

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

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

774 
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

775 
vgt: TVisualGearType; 
10281  776 
uid: Longword; 
777 
const 

778 
call = 'AddVisualGear'; 

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

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

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

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

783 
begin 
10281  784 
s:= LuaToVisualGearTypeOrd(L, 3, call, params); 
785 
if s >= 0 then 

786 
begin 

787 
vgt:= TVisualGearType(s); 

788 
x:= lua_tointeger(L, 1); 

789 
y:= lua_tointeger(L, 2); 

790 
s:= lua_tointeger(L, 4); 

791 
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

792 

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

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

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

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

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

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

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

800 

10281  801 
if vg <> nil then 
802 
begin 

803 
lastVisualGearByUID:= vg; 

804 
uid:= vg^.uid; 

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

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

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

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

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

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

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

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

813 
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

814 
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

815 

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

816 
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

817 
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

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

821 
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

822 
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

823 
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

824 
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

825 
end; 
10281  826 
// allow caller to know whether there was something to delete 
827 
lua_pushboolean(L, vg <> nil); 

828 
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

829 
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

830 

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

831 
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

832 
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

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

835 
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

836 
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

837 
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

838 
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

839 
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

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

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

842 
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

843 
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

844 
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

845 
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

846 
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

847 
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

848 
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

849 
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

850 
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

851 
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

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

854 
end 
10287  855 
end 
856 
else 

857 
begin 

858 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 

859 
lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); 

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

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

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

862 
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

863 

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

864 
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

865 
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

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

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

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

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

870 
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

871 
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

899 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

927 
end 
10287  928 
end 
929 
else 

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

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

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

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

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

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

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

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

937 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

974 
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

975 

3058  976 
function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl; 
977 
begin 

10297  978 
if CheckLuaParamCount(L, 0, 'GetFollowGear', '') then 
3058  979 
begin 
980 
if FollowGear = nil then 

981 
lua_pushnil(L) 

982 
else 

4484  983 
lua_pushinteger(L, FollowGear^.uid); 
10287  984 
end 
985 
else 

986 
lua_pushnil(L); 

3058  987 
lc_getfollowgear:= 1; // 1 return value 
988 
end; 

989 

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

990 
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

991 
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

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

994 
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

995 
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

996 
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

997 
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

998 
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

999 
lua_pushnil(L); 
10287  1000 
end 
1001 
else 

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

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

1003 
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

1004 
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

1005 

3892  1006 
function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl; 
1007 
var gear : PGear; 

1008 
begin 

10297  1009 
if CheckLuaParamCount(L, 1, 'GetGearMessage', 'gearUid') then 
3892  1010 
begin 
1011 
gear:= GearByUID(lua_tointeger(L, 1)); 

1012 
if gear <> nil then 

1013 
lua_pushinteger(L, gear^.message) 

1014 
else 

1015 
lua_pushnil(L); 

10287  1016 
end 
1017 
else 

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

3892  1019 
lc_getgearmessage:= 1 
1020 
end; 

1021 

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

1022 
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

1023 
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

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

1026 
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

1027 
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

1028 
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

1029 
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

1030 
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

1031 
lua_pushnil(L); 
10287  1032 
end 
1033 
else 

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

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

1035 
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

1036 
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

1037 

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

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

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

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

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

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

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

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

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

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

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

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

1049 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1065 

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

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

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

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

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

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

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

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

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

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

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

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

1077 

3896  1078 
function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl; 
1079 
var gear : PGear; 

1080 
begin 

10297  1081 
if CheckLuaParamCount(L, 2, 'SetGearMessage', 'gearUid, message') then 
3896  1082 
begin 
1083 
gear:= GearByUID(lua_tointeger(L, 1)); 

1084 
if gear <> nil then 

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

1086 
end; 

1087 
lc_setgearmessage:= 0 

1088 
end; 

1089 

6523  1090 
function lc_getgearpos(L : Plua_State) : LongInt; Cdecl; 
1091 
var gear : PGear; 

1092 
begin 

10297  1093 
if CheckLuaParamCount(L, 1, 'GetGearPos', 'gearUid') then 
6523  1094 
begin 
1095 
gear:= GearByUID(lua_tointeger(L, 1)); 

1096 
if gear <> nil then 

1097 
lua_pushinteger(L, gear^.Pos) 

1098 
else 

1099 
lua_pushnil(L); 

10287  1100 
end 
1101 
else 

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

6523  1103 
lc_getgearpos:= 1 
1104 
end; 

1105 

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

1107 
var gear : PGear; 

1108 
begin 

10297  1109 
if CheckLuaParamCount(L, 2, 'SetGearPos', 'gearUid, value') then 
6523  1110 
begin 
1111 
gear:= GearByUID(lua_tointeger(L, 1)); 

1112 
if gear <> nil then 

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

1114 
end; 

1115 
lc_setgearpos:= 0 

1116 
end; 

1117 

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

1118 
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

1119 
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

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

1122 
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

1123 
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

1124 
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

1125 
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

1126 
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

1127 
lua_pushnil(L); 
10287  1128 
end 
1129 
else 

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

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

1131 
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

1132 
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

1133 

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

1134 
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

1135 
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

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

1138 
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

1139 
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

1140 
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

1141 
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

1142 
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

1143 
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

1144 
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

1145 

3755  1146 
function lc_gethoglevel(L : Plua_State): LongInt; Cdecl; 
1147 
var gear : PGear; 

1148 
begin 

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

1150 
begin 
3755  1151 
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

1152 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 
4372  1153 
lua_pushinteger(L, gear^.Hedgehog^.BotLevel) 
3755  1154 
else 
1155 
lua_pushnil(L); 

1156 
end; 

1157 
lc_gethoglevel := 1; 

1158 
end; 

1159 

4496  1160 
function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl; 
1161 
var gear : PGear; 

1162 
begin 

10297  1163 
if CheckLuaParamCount(L, 2, 'SetHogLevel', 'gearUid, level') then 
4496  1164 
begin 
1165 
gear:= GearByUID(lua_tointeger(L, 1)); 

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

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

1168 
end; 

1169 
lc_sethoglevel:= 0 

1170 
end; 

1171 

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

1172 
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

1173 
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

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

1176 
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

1177 
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

1178 
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

1179 
begin 
4372  1180 
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

1181 
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

1182 
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

1183 
lua_pushnil(L); 
10287  1184 
end 
1185 
else 

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

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

1187 
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

1188 
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

1189 

4498  1190 
function lc_getclancolor(L : Plua_State) : LongInt; Cdecl; 
1191 
begin 

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

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

1197 
end; 

1198 

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

1199 
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

1200 
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

1201 
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

1202 
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

1203 
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

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

1206 
begin 
10581  1207 
i:= lua_tointeger(L,1); 
1208 
if i >= ClansCount then exit(0); 

1209 
clan := ClansArray[i]; 

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

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

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

1212 
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

1213 
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

1214 
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

1215 
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

1216 
begin 
4891  1217 
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

1218 
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

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

1220 
FreeAndNilTexture(hh.NameTagTex); 
10127  1221 
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

1222 
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

1223 
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

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

1225 
FreeAndNilTexture(team^.NameTagTex); 
10127  1226 
team^.NameTagTex:= RenderStringTex(ansistring(clan^.Teams[i]^.TeamName), clan^.Color, fnt16); 
9656  1227 
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

1228 

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

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

1232 

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

1233 
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

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

1235 

11029
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1236 
function lc_gethogvoicepack(L : Plua_State) : LongInt; Cdecl; 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1237 
var gear : PGear; 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1238 
begin 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1239 
if CheckLuaParamCount(L, 1, 'GetHogVoicepack', 'gearUid') then 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1240 
begin 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1241 
gear:= GearByUID(lua_tointeger(L, 1)); 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1242 
if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1243 
lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Voicepack^.name)) 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1244 
else 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1245 
lua_pushnil(L); 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1246 
end 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1247 
else 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1248 
lua_pushnil(L); // return value on stack (nil) 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1249 
lc_gethogvoicepack:= 1 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1250 
end; 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1251 

854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1252 
function lc_gethoggrave(L : Plua_State) : LongInt; Cdecl; 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1253 
var gear : PGear; 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1254 
begin 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1255 
if CheckLuaParamCount(L, 1, 'GetHogGrave', 'gearUid') then 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1256 
begin 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1257 
gear:= GearByUID(lua_tointeger(L, 1)); 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1258 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1259 
lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.GraveName)) 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1260 
else 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1261 
lua_pushnil(L); 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1262 
end 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1263 
else 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1264 
lua_pushnil(L); // return value on stack (nil) 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1265 
lc_gethoggrave:= 1 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1266 
end; 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1267 

854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1268 
function lc_gethogflag(L : Plua_State) : LongInt; Cdecl; 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1269 
var gear : PGear; 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1270 
begin 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1271 
if CheckLuaParamCount(L, 1, 'GetHogFlag', 'gearUid') then 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1272 
begin 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1273 
gear:= GearByUID(lua_tointeger(L, 1)); 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1274 
if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1275 
lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Flag)) 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1276 
else 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1277 
lua_pushnil(L); 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1278 
end 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1279 
else 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1280 
lua_pushnil(L); // return value on stack (nil) 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1281 
lc_gethogflag:= 1 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1282 
end; 
854f30498a98
GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents:
11022
diff
changeset

1283 

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

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

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

1286 
begin 
10297  1287 
if CheckLuaParamCount(L, 1, 'GetHogTeamName', 'gearUid') then 
4236
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

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

1289 
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

1290 
if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then 
4372  1291 
lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName)) 
4236
fa2680cfff86
added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents:
4235
diff
changeset

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

1293 
lua_pushnil(L); 
10287  1294 
end 
1295 
else 

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

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

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

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

1299 

9788  1300 
function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl; 
1301 
var gear : PGear; 

1302 
begin 

10297 