83 SysUtils, |
86 SysUtils, |
84 uIO, |
87 uIO, |
85 uVisualGearsList, |
88 uVisualGearsList, |
86 uGearsHandlersMess, |
89 uGearsHandlersMess, |
87 uPhysFSLayer, |
90 uPhysFSLayer, |
88 typinfo |
91 SDLh |
|
92 {$IFNDEF PAS2C} |
|
93 , typinfo |
|
94 {$ENDIF} |
89 ; |
95 ; |
90 |
96 |
91 var luaState : Plua_State; |
97 var luaState : Plua_State; |
92 ScriptAmmoLoadout : shortstring; |
98 ScriptAmmoLoadout : shortstring; |
93 ScriptAmmoProbability : shortstring; |
99 ScriptAmmoProbability : shortstring; |
94 ScriptAmmoDelay : shortstring; |
100 ScriptAmmoDelay : shortstring; |
95 ScriptAmmoReinforcement : shortstring; |
101 ScriptAmmoReinforcement : shortstring; |
96 ScriptLoaded : boolean; |
102 ScriptLoaded : boolean; |
97 mapDims : boolean; |
103 mapDims : boolean; |
|
104 PointsBuffer: shortstring; |
|
105 prevCursorPoint: TPoint; // why is tpoint still in sdlh... |
98 |
106 |
99 procedure ScriptPrepareAmmoStore; forward; |
107 procedure ScriptPrepareAmmoStore; forward; |
100 procedure ScriptApplyAmmoStore; forward; |
108 procedure ScriptApplyAmmoStore; forward; |
101 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward; |
109 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward; |
102 procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward; |
110 procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward; |
103 |
111 |
|
112 var LuaDebugInfo: lua_Debug; |
|
113 |
|
114 procedure SetGlobals; forward; |
|
115 procedure LuaParseString(s: shortString); |
|
116 begin |
|
117 SetGlobals; |
|
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 |
|
127 function LuaUpdateDebugInfo(): Boolean; |
|
128 begin |
|
129 FillChar(LuaDebugInfo, sizeof(LuaDebugInfo), 0); |
|
130 |
|
131 if lua_getstack(luaState, 1, @LuaDebugInfo) = 0 then |
|
132 exit(false); // stack not deep enough |
|
133 |
|
134 // get source name and line count |
|
135 lua_getinfo(luaState, PChar('Sl'), @LuaDebugInfo); |
|
136 exit(true); |
|
137 end; |
|
138 |
104 procedure LuaError(s: shortstring); |
139 procedure LuaError(s: shortstring); |
105 begin |
140 var src: shortstring; |
|
141 const |
|
142 maxsrclen = 20; |
|
143 begin |
|
144 if LuaUpdateDebugInfo() then |
|
145 begin |
|
146 src:= StrPas(LuaDebugInfo.source); |
|
147 s:= 'LUA ERROR [ ... ' |
|
148 + copy(src, Length(src) - maxsrclen, maxsrclen - 3) + ':' |
|
149 + inttostr(LuaDebugInfo.currentLine) + ']: ' + s; |
|
150 end |
|
151 else |
|
152 s:= 'LUA ERROR: ' + s; |
106 WriteLnToConsole(s); |
153 WriteLnToConsole(s); |
107 AddChatString(#5 + s); |
154 AddChatString(#5 + s); |
108 end; |
155 if cTestLua then |
109 |
156 halt(HaltTestLuaError); |
110 procedure LuaParameterCountError(call, paramsyntax: shortstring; wrongcount: LongInt); |
157 end; |
|
158 |
|
159 procedure LuaCallError(error, call, paramsyntax: shortstring); |
|
160 begin |
|
161 LuaError(call + ': ' + error); |
|
162 LuaError('-- SYNTAX: ' + call + ' ( ' + paramsyntax + ' )'); |
|
163 end; |
|
164 |
|
165 procedure LuaParameterCountError(expected, call, paramsyntax: shortstring; wrongcount: LongInt); inline; |
111 begin |
166 begin |
112 // TODO: i18n? |
167 // TODO: i18n? |
113 LuaError('Lua: Wrong number of parameters (' + inttostr(wrongcount) + ') passed to ' + call + '! syntax: ' + call + ' ( ' + paramsyntax + ' )'); |
168 LuaCallError('Wrong number of parameters! (is: ' + inttostr(wrongcount) + ', should be: '+ expected + ')', call, paramsyntax); |
|
169 end; |
|
170 |
|
171 // compare with allowed count |
|
172 function CheckLuaParamCount(L : Plua_State; count: LongInt; call, paramsyntax: shortstring): boolean; inline; |
|
173 var c: LongInt; |
|
174 begin |
|
175 c:= lua_gettop(L); |
|
176 if c <> count then |
|
177 begin |
|
178 LuaParameterCountError('exactly ' + inttostr(count), call, paramsyntax, c); |
|
179 exit(false); |
|
180 end; |
|
181 |
|
182 CheckLuaParamCount:= true; |
|
183 end; |
|
184 |
|
185 // check if is either count1 or count2 |
|
186 function CheckAndFetchParamCount(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline; |
|
187 begin |
|
188 actual:= lua_gettop(L); |
|
189 if (actual <> count1) and (actual <> count2) then |
|
190 begin |
|
191 LuaParameterCountError('either ' + inttostr(count1) + ' or ' + inttostr(count2), call, paramsyntax, actual); |
|
192 exit(false); |
|
193 end; |
|
194 |
|
195 CheckAndFetchParamCount:= true; |
|
196 end; |
|
197 |
|
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 |
|
211 // check if is same or higher as minCount |
|
212 function CheckAndFetchLuaParamMinCount(L : Plua_State; minCount: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline; |
|
213 begin |
|
214 actual:= lua_gettop(L); |
|
215 if (actual < minCount) then |
|
216 begin |
|
217 LuaParameterCountError(inttostr(minCount) + ' or more', call, paramsyntax, actual); |
|
218 exit(false); |
|
219 end; |
|
220 |
|
221 CheckAndFetchLuaParamMinCount:= true; |
|
222 end; |
|
223 |
|
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; |
|
251 begin |
|
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 |
|
294 begin |
|
295 LuaCallError('Invalid gear type!', call, paramsyntax); |
|
296 LuaToHogEffectOrd:= -1; |
|
297 end |
|
298 else |
|
299 LuaToHogEffectOrd:= i; |
|
300 end; |
|
301 |
|
302 function LuaToCapGroupOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; |
|
303 begin |
|
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 |
|
320 begin |
|
321 LuaCallError('Invalid sprite id!', call, paramsyntax); |
|
322 LuaToSpriteOrd:= -1; |
|
323 end |
|
324 else |
|
325 LuaToSpriteOrd:= i; |
|
326 end; |
|
327 |
|
328 function LuaToMapGenOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline; |
|
329 begin |
|
330 if lua_isnoneornil(L, i) then i:= -1 |
|
331 else i:= lua_tointeger(L, i); |
|
332 if (i < ord(Low(TMapGen))) or (i > ord(High(TMapGen))) then |
|
333 begin |
|
334 LuaCallError('Invalid mapgen id!', call, paramsyntax); |
|
335 LuaToMapGenOrd:= -1; |
|
336 end |
|
337 else |
|
338 LuaToMapGenOrd:= i; |
114 end; |
339 end; |
115 |
340 |
116 // wrapped calls // |
341 // wrapped calls // |
117 |
342 |
118 // functions called from Lua: |
343 // functions called from Lua: |
119 // function(L : Plua_State) : LongInt; Cdecl; |
344 // function(L : Plua_State) : LongInt; Cdecl; |
120 // where L contains the state, returns the number of return values on the stack |
345 // where L contains the state, returns the number of return values on the stack |
121 // call lua_gettop(L) to receive number of parameters passed |
346 // call CheckLuaParamCount or CheckAndFetchParamCount |
|
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 |
122 |
350 |
123 function lc_band(L: PLua_State): LongInt; Cdecl; |
351 function lc_band(L: PLua_State): LongInt; Cdecl; |
124 begin |
352 begin |
125 if lua_gettop(L) <> 2 then |
353 if CheckLuaParamCount(L, 2, 'band', 'value1, value2') then |
126 begin |
354 lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)) |
127 LuaParameterCountError('band', 'value1, value2', lua_gettop(L)); |
355 else |
128 lua_pushnil(L); |
356 lua_pushnil(L); |
129 end |
|
130 else |
|
131 lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)); |
|
132 lc_band := 1; |
357 lc_band := 1; |
133 end; |
358 end; |
134 |
359 |
135 function lc_bor(L: PLua_State): LongInt; Cdecl; |
360 function lc_bor(L: PLua_State): LongInt; Cdecl; |
136 begin |
361 begin |
137 if lua_gettop(L) <> 2 then |
362 if CheckLuaParamCount(L, 2, 'bor', 'value1, value2') then |
138 begin |
363 lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)) |
139 LuaParameterCountError('bor', 'value1, value2', lua_gettop(L)); |
364 else |
140 lua_pushnil(L); |
365 lua_pushnil(L); |
141 end |
|
142 else |
|
143 lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)); |
|
144 lc_bor := 1; |
366 lc_bor := 1; |
145 end; |
367 end; |
146 |
368 |
147 function lc_bnot(L: PLua_State): LongInt; Cdecl; |
369 function lc_bnot(L: PLua_State): LongInt; Cdecl; |
148 begin |
370 begin |
149 if lua_gettop(L) <> 1 then |
371 if CheckLuaParamCount(L, 1, 'bnot', 'value') then |
150 begin |
372 lua_pushinteger(L, (not lua_tointeger(L, 1))) |
151 LuaParameterCountError('bnot', 'value', lua_gettop(L)); |
373 else |
152 lua_pushnil(L); |
374 lua_pushnil(L); |
153 end |
|
154 else |
|
155 lua_pushinteger(L, not lua_tointeger(L, 1)); |
|
156 lc_bnot := 1; |
375 lc_bnot := 1; |
157 end; |
376 end; |
158 |
377 |
159 function lc_div(L: PLua_State): LongInt; Cdecl; |
378 function lc_div(L: PLua_State): LongInt; Cdecl; |
160 begin |
379 begin |
161 if lua_gettop(L) <> 2 then |
380 if CheckLuaParamCount(L, 2, 'div', 'dividend, divisor') then |
162 begin |
381 lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2)) |
163 LuaParameterCountError('div', 'dividend, divisor', lua_gettop(L)); |
382 else |
164 lua_pushnil(L); |
383 lua_pushnil(L); |
165 end |
|
166 else |
|
167 lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2)); |
|
168 lc_div := 1; |
384 lc_div := 1; |
169 end; |
385 end; |
170 |
386 |
171 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl; |
387 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl; |
172 begin |
388 begin |
173 if lua_gettop(L) <> 0 then |
389 if CheckLuaParamCount(L, 0, 'GetInputMask', '') then |
174 LuaParameterCountError('GetInputMask', '', lua_gettop(L)) |
|
175 else |
|
176 lua_pushinteger(L, InputMask); |
390 lua_pushinteger(L, InputMask); |
177 lc_getinputmask:= 1 |
391 lc_getinputmask:= 1 |
178 end; |
392 end; |
179 |
393 |
180 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl; |
394 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl; |
181 begin |
395 begin |
182 if lua_gettop(L) <> 1 then |
396 if CheckLuaParamCount(L, 1, 'SetInputMask', 'mask') then |
183 LuaParameterCountError('SetInputMask', 'mask', lua_gettop(L)) |
|
184 else |
|
185 InputMask:= lua_tointeger(L, 1); |
397 InputMask:= lua_tointeger(L, 1); |
186 lc_setinputmask:= 0 |
398 lc_setinputmask:= 0 |
187 end; |
399 end; |
188 |
400 |
189 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; |
401 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; |
190 begin |
402 begin |
191 if lua_gettop(L) = 1 then |
403 if CheckLuaParamCount(L, 1, 'WriteLnToConsole', 'string') then |
192 begin |
|
193 WriteLnToConsole('Lua: ' + lua_tostring(L ,1)); |
404 WriteLnToConsole('Lua: ' + lua_tostring(L ,1)); |
194 end |
|
195 else |
|
196 LuaParameterCountError('WriteLnToConsole', 'string', lua_gettop(L)); |
|
197 lc_writelntoconsole:= 0; |
405 lc_writelntoconsole:= 0; |
198 end; |
406 end; |
199 |
407 |
200 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; |
408 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; |
201 var t: PChar; |
409 var t: PChar; |
202 i,c: LongWord; |
410 i,c: LongWord; |
203 s: shortstring; |
411 s: shortstring; |
204 begin |
412 begin |
205 if lua_gettop(L) = 1 then |
413 if CheckLuaParamCount(L, 1, 'ParseCommand', 'string') then |
206 begin |
414 begin |
207 t:= lua_tolstring(L,1,@c); |
415 t:= lua_tolstring(L, 1, Psize_t(@c)); |
208 |
416 |
209 for i:= 1 to c do s[i]:= t[i-1]; |
417 for i:= 1 to c do s[i]:= t[i-1]; |
210 s[0]:= char(c); |
418 s[0]:= char(c); |
211 |
419 |
212 ParseCommand(s, true, true); |
420 ParseCommand(s, true, true); |
213 |
421 |
214 end |
422 end; |
215 else |
|
216 LuaParameterCountError('ParseCommand', 'string', lua_gettop(L)); |
|
217 lc_parsecommand:= 0; |
423 lc_parsecommand:= 0; |
218 end; |
424 end; |
219 |
425 |
|
426 // sets weapon to the desired ammo type |
|
427 function lc_setweapon(L : Plua_State) : LongInt; Cdecl; |
|
428 var at: LongInt; |
|
429 const |
|
430 call = 'SetWeapon'; |
|
431 params = 'ammoType'; |
|
432 begin |
|
433 // no point to run this without any CurrentHedgehog |
|
434 if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 1, call, params)) then |
|
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 |
|
443 // no parameter means reset to default (and 0 means unlimited) |
|
444 function lc_setmaxbuilddistance(L : Plua_State) : LongInt; Cdecl; |
|
445 var np: LongInt; |
|
446 const |
|
447 call = 'SetMaxBuildDistance'; |
|
448 params = '[ distInPx ]'; |
|
449 begin |
|
450 if CheckAndFetchParamCountRange(L, 0, 1, call, params, np) then |
|
451 begin |
|
452 if np = 0 then |
|
453 begin |
|
454 // no args? reset |
|
455 cBuildMaxDist:= cDefaultBuildMaxDist; |
|
456 end |
|
457 else |
|
458 CBuildMaxDist:= lua_tointeger(L, 1); |
|
459 end; |
|
460 lc_setmaxbuilddistance:= 0; |
|
461 end; |
|
462 |
|
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 |
|
472 if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, call, params)) then |
|
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 |
220 function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
527 function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
221 begin |
528 begin |
222 if lua_gettop(L) = 5 then |
529 if CheckLuaParamCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then |
223 begin |
530 ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5)); |
224 ShowMission(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5)); |
|
225 end |
|
226 else |
|
227 LuaParameterCountError('ShowMission', 'caption, subcaption, text, icon, time', lua_gettop(L)); |
|
228 lc_showmission:= 0; |
531 lc_showmission:= 0; |
229 end; |
532 end; |
230 |
533 |
231 function lc_hidemission(L : Plua_State) : LongInt; Cdecl; |
534 function lc_hidemission(L : Plua_State) : LongInt; Cdecl; |
232 begin |
535 begin |
234 HideMission; |
537 HideMission; |
235 lc_hidemission:= 0; |
538 lc_hidemission:= 0; |
236 end; |
539 end; |
237 |
540 |
238 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl; |
541 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl; |
239 var i : integer; |
542 var i, n : integer; |
240 begin |
543 begin |
241 for i:= 1 to lua_gettop(L) do |
544 // can have 1 or more arguments |
242 GameFlags := GameFlags or LongWord(lua_tointeger(L, i)); |
545 if CheckAndFetchLuaParamMinCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then |
243 ScriptSetInteger('GameFlags', GameFlags); |
546 begin |
|
547 for i:= 1 to n do |
|
548 GameFlags := GameFlags or LongWord(lua_tointeger(L, i)); |
|
549 ScriptSetInteger('GameFlags', GameFlags); |
|
550 end; |
244 lc_enablegameflags:= 0; |
551 lc_enablegameflags:= 0; |
245 end; |
552 end; |
246 |
553 |
247 function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl; |
554 function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl; |
248 var i : integer; |
555 var i , n: integer; |
249 begin |
556 begin |
250 for i:= 1 to lua_gettop(L) do |
557 // can have 1 or more arguments |
251 GameFlags := GameFlags and not(LongWord(lua_tointeger(L, i))); |
558 if CheckAndFetchLuaParamMinCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then |
252 ScriptSetInteger('GameFlags', GameFlags); |
559 begin |
|
560 for i:= 1 to n do |
|
561 GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i))); |
|
562 ScriptSetInteger('GameFlags', GameFlags); |
|
563 end; |
253 lc_disablegameflags:= 0; |
564 lc_disablegameflags:= 0; |
254 end; |
565 end; |
255 |
566 |
256 function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl; |
567 function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl; |
257 begin |
568 begin |
258 // Silence hint |
569 if CheckLuaParamCount(L, 0, 'ClearGameFlags', '') then |
259 L:= L; |
570 begin |
260 GameFlags:= 0; |
571 GameFlags:= 0; |
261 ScriptSetInteger('GameFlags', GameFlags); |
572 ScriptSetInteger('GameFlags', GameFlags); |
|
573 end; |
262 lc_cleargameflags:= 0; |
574 lc_cleargameflags:= 0; |
263 end; |
575 end; |
264 |
576 |
|
577 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl; |
|
578 begin |
|
579 if CheckLuaParamCount(L, 1, 'GetGameFlag', 'gameflag') then |
|
580 lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0)) |
|
581 else |
|
582 lua_pushnil(L); |
|
583 lc_getgameflag:= 1; |
|
584 end; |
|
585 |
265 function lc_addcaption(L : Plua_State) : LongInt; Cdecl; |
586 function lc_addcaption(L : Plua_State) : LongInt; Cdecl; |
266 begin |
587 var cg: LongInt; |
267 if lua_gettop(L) = 1 then |
588 const |
268 AddCaption(lua_tostring(L, 1), cWhiteColor, capgrpMessage) |
589 call = 'AddCaption'; |
269 else if lua_gettop(L) = 3 then |
590 params = 'text [, color, captiongroup]'; |
270 begin |
591 begin |
271 AddCaption(lua_tostring(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(lua_tointeger(L, 3))); |
592 if CheckAndFetchParamCount(L, 1, 3, call, params, cg) then |
272 end |
593 begin |
273 else |
594 if cg = 1 then |
274 LuaParameterCountError('AddCaption', 'text[, color, captiongroup]', lua_gettop(L)); |
595 AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage) |
|
596 else |
|
597 begin |
|
598 cg:= LuaToCapGroupOrd(L, 3, call, params); |
|
599 if cg >= 0 then |
|
600 AddCaption(lua_tostringA(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(cg)); |
|
601 end |
|
602 end; |
275 lc_addcaption:= 0; |
603 lc_addcaption:= 0; |
276 end; |
604 end; |
277 |
605 |
278 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl; |
606 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl; |
279 begin |
607 begin |
280 if lua_gettop(L) = 1 then |
608 if CheckLuaParamCount(L, 1, 'CampaignLock', 'TODO') then |
281 begin |
609 begin |
282 // to be done |
610 // TODO |
283 end |
611 end; |
284 else |
|
285 LuaParameterCountError('CampaignLock', 'TODO', lua_gettop(L)); |
|
286 lc_campaignlock:= 0; |
612 lc_campaignlock:= 0; |
287 end; |
613 end; |
288 |
614 |
289 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl; |
615 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl; |
290 begin |
616 begin |
291 if lua_gettop(L) = 1 then |
617 if CheckLuaParamCount(L, 1, 'CampaignUnlock', 'TODO') then |
292 begin |
618 begin |
293 // to be done |
619 // TODO |
294 end |
620 end; |
295 else |
|
296 LuaParameterCountError('CampaignUnlock', 'TODO', lua_gettop(L)); |
|
297 lc_campaignunlock:= 0; |
621 lc_campaignunlock:= 0; |
298 end; |
622 end; |
299 |
623 |
300 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl; |
624 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl; |
301 var gear: PGear; |
625 var gear: PGear; |
302 begin |
626 begin |
303 if lua_gettop(L) <> 4 then |
627 if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then |
304 begin |
|
305 LuaParameterCountError('SpawnFakeHealthCrate', 'x, y, explode, poison', lua_gettop(L)); |
|
306 lua_pushnil(L); |
|
307 end |
|
308 else |
|
309 begin |
628 begin |
310 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
629 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
311 HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
630 HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
312 lua_pushinteger(L, gear^.uid); |
631 if gear <> nil then |
313 end; |
632 lua_pushinteger(L, gear^.uid) |
|
633 else lua_pushnil(L) |
|
634 end |
|
635 else |
|
636 lua_pushnil(L); |
314 lc_spawnfakehealthcrate := 1; |
637 lc_spawnfakehealthcrate := 1; |
315 end; |
638 end; |
316 |
639 |
317 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl; |
640 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl; |
318 var gear: PGear; |
641 var gear: PGear; |
319 begin |
642 begin |
320 if lua_gettop(L) <> 4 then |
643 if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then |
321 begin |
|
322 LuaParameterCountError('SpawnFakeAmmoCrate', 'x, y, explode, poison', lua_gettop(L)); |
|
323 lua_pushnil(L); |
|
324 end |
|
325 else |
|
326 begin |
644 begin |
327 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
645 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
328 AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
646 AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
329 lua_pushinteger(L, gear^.uid); |
647 if gear <> nil then |
330 end; |
648 lua_pushinteger(L, gear^.uid) |
|
649 else lua_pushnil(L) |
|
650 end |
|
651 else |
|
652 lua_pushnil(L); |
331 lc_spawnfakeammocrate := 1; |
653 lc_spawnfakeammocrate := 1; |
332 end; |
654 end; |
333 |
655 |
334 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl; |
656 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl; |
335 var gear: PGear; |
657 var gear: PGear; |
336 begin |
658 begin |
337 if lua_gettop(L) <> 4 then |
659 if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then |
338 begin |
|
339 LuaParameterCountError('SpawnFakeUtilityCrate', 'x, y, explode, poison', lua_gettop(L)); |
|
340 lua_pushnil(L); |
|
341 end |
|
342 else |
|
343 begin |
660 begin |
344 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
661 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
345 UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
662 UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
346 lua_pushinteger(L, gear^.uid); |
663 if gear <> nil then |
347 end; |
664 lua_pushinteger(L, gear^.uid) |
|
665 else lua_pushnil(L) |
|
666 end |
|
667 else |
|
668 lua_pushnil(L); |
348 lc_spawnfakeutilitycrate := 1; |
669 lc_spawnfakeutilitycrate := 1; |
349 end; |
670 end; |
350 |
671 |
351 function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl; |
672 function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl; |
352 var gear: PGear; |
673 var gear: PGear; |
353 var health: LongInt; |
674 var health, n: LongInt; |
354 begin |
675 begin |
355 if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then |
676 if CheckAndFetchParamCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then |
356 begin |
677 begin |
357 LuaParameterCountError('SpawnHealthCrate', 'x, y[, health]', lua_gettop(L)); |
678 if n = 3 then |
358 lua_pushnil(L); |
|
359 end |
|
360 else |
|
361 begin |
|
362 if lua_gettop(L) = 3 then |
|
363 health:= lua_tointeger(L, 3) |
679 health:= lua_tointeger(L, 3) |
364 else |
680 else |
365 health:= cHealthCaseAmount; |
681 health:= cHealthCaseAmount; |
366 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0); |
682 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0); |
367 if gear <> nil then |
683 if gear <> nil then |
368 lua_pushinteger(L, gear^.uid) |
684 lua_pushinteger(L, gear^.uid) |
369 else |
685 else lua_pushnil(L); |
370 lua_pushnil(L); |
686 end |
371 end; |
687 else |
|
688 lua_pushnil(L); |
372 lc_spawnhealthcrate := 1; |
689 lc_spawnhealthcrate := 1; |
373 end; |
690 end; |
374 |
691 |
375 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl; |
692 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl; |
376 var gear: PGear; |
693 var gear: PGear; |
377 begin |
694 n : LongInt; |
378 if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then |
695 begin |
379 begin |
696 if CheckAndFetchParamCount(L, 3, 4, 'SpawnAmmoCrate', 'x, y, content [, amount]', n) then |
380 LuaParameterCountError('SpawnAmmoCrate', 'x, y, content[, amount]', lua_gettop(L)); |
697 begin |
381 lua_pushnil(L); |
698 if n = 3 then |
382 end |
|
383 else |
|
384 begin |
|
385 if (lua_gettop(L) = 3) then |
|
386 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0) |
699 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0) |
387 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
700 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
388 if gear <> nil then |
701 if gear <> nil then |
389 lua_pushinteger(L, gear^.uid) |
702 lua_pushinteger(L, gear^.uid) |
390 else |
703 else lua_pushnil(L); |
391 lua_pushnil(L); |
704 end |
392 end; |
705 else |
|
706 lua_pushnil(L); |
393 lc_spawnammocrate := 1; |
707 lc_spawnammocrate := 1; |
394 end; |
708 end; |
395 |
709 |
396 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl; |
710 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl; |
397 var gear: PGear; |
711 var gear: PGear; |
398 begin |
712 n : LongInt; |
399 if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then |
713 begin |
400 begin |
714 if CheckAndFetchParamCount(L, 3, 4, 'SpawnUtilityCrate', 'x, y, content [, amount]', n) then |
401 LuaParameterCountError('SpawnUtilityCrate', 'x, y, content[, amount]', lua_gettop(L)); |
715 begin |
402 lua_pushnil(L); |
716 if n = 3 then |
403 end |
|
404 else |
|
405 begin |
|
406 if (lua_gettop(L) = 3) then |
|
407 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0) |
717 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0) |
408 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
718 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
409 if gear <> nil then |
719 if gear <> nil then |
410 lua_pushinteger(L, gear^.uid) |
720 lua_pushinteger(L, gear^.uid) |
411 else |
721 else lua_pushnil(L); |
412 lua_pushnil(L); |
722 end |
413 end; |
723 else |
|
724 lua_pushnil(L); |
414 lc_spawnutilitycrate := 1; |
725 lc_spawnutilitycrate := 1; |
415 end; |
726 end; |
416 |
727 |
417 function lc_addgear(L : Plua_State) : LongInt; Cdecl; |
728 function lc_addgear(L : Plua_State) : LongInt; Cdecl; |
418 var gear : PGear; |
729 var gear : PGear; |
419 x, y, s, t: LongInt; |
730 x, y, s, t: LongInt; |
420 dx, dy: hwFloat; |
731 dx, dy: hwFloat; |
421 gt: TGearType; |
732 gt: TGearType; |
422 begin |
733 const |
423 if lua_gettop(L) <> 7 then |
734 call = 'AddGear'; |
424 begin |
735 params = 'x, y, gearType, state, dx, dy, timer'; |
425 LuaParameterCountError('AddGear', 'x, y, gearType, state, dx, dy, timer', lua_gettop(L)); |
736 begin |
426 lua_pushnil(L); // return value on stack (nil) |
737 if CheckLuaParamCount(L, 7, call, params) then |
427 end |
738 begin |
428 else |
739 t:= LuaToGearTypeOrd(L, 3, call, params); |
429 begin |
740 if t >= 0 then |
430 x:= lua_tointeger(L, 1); |
741 begin |
431 y:= lua_tointeger(L, 2); |
742 gt:= TGearType(t); |
432 gt:= TGearType(lua_tointeger(L, 3)); |
743 x:= lua_tointeger(L, 1); |
433 s:= lua_tointeger(L, 4); |
744 y:= lua_tointeger(L, 2); |
434 dx:= int2hwFloat(lua_tointeger(L, 5)) / 1000000; |
745 s:= lua_tointeger(L, 4); |
435 dy:= int2hwFloat(lua_tointeger(L, 6)) / 1000000; |
746 dx:= int2hwFloat(lua_tointeger(L, 5)) / 1000000; |
436 t:= lua_tointeger(L, 7); |
747 dy:= int2hwFloat(lua_tointeger(L, 6)) / 1000000; |
437 |
748 t:= lua_tointeger(L, 7); |
438 gear:= AddGear(x, y, gt, s, dx, dy, t); |
749 |
439 lastGearByUID:= gear; |
750 gear:= AddGear(x, y, gt, s, dx, dy, t); |
440 lua_pushinteger(L, gear^.uid) |
751 lastGearByUID:= gear; |
441 end; |
752 lua_pushinteger(L, gear^.uid) |
|
753 end |
|
754 else |
|
755 lua_pushnil(L); |
|
756 end |
|
757 else |
|
758 lua_pushnil(L); |
442 lc_addgear:= 1; // 1 return value |
759 lc_addgear:= 1; // 1 return value |
443 end; |
760 end; |
444 |
761 |
445 function lc_deletegear(L : Plua_State) : LongInt; Cdecl; |
762 function lc_deletegear(L : Plua_State) : LongInt; Cdecl; |
446 var gear : PGear; |
763 var gear : PGear; |
447 begin |
764 begin |
448 if lua_gettop(L) <> 1 then |
765 if CheckLuaParamCount(L, 1, 'DeleteGear', 'gearUid') then |
449 begin |
|
450 LuaParameterCountError('DeleteGear', 'gearUid', lua_gettop(L)); |
|
451 end |
|
452 else |
|
453 begin |
766 begin |
454 gear:= GearByUID(lua_tointeger(L, 1)); |
767 gear:= GearByUID(lua_tointeger(L, 1)); |
455 if gear <> nil then |
768 if gear <> nil then |
456 gear^.Message:= gear^.Message or gmDelete; |
769 gear^.Message:= gear^.Message or gmDelete; |
457 end; |
770 end; |
458 lc_deletegear:= 0 |
771 lc_deletegear:= 0 |
459 end; |
772 end; |
460 |
773 |
461 function lc_addvisualgear(L : Plua_State) : LongInt; Cdecl; |
774 function lc_addvisualgear(L : Plua_State) : LongInt; Cdecl; |
462 var vg : PVisualGear; |
775 var vg : PVisualGear; |
463 x, y, s: LongInt; |
776 x, y, s, n, layer: LongInt; |
464 c: Boolean; |
777 c: Boolean; |
465 vgt: TVisualGearType; |
778 vgt: TVisualGearType; |
466 begin |
779 uid: Longword; |
467 if lua_gettop(L) <> 5 then |
780 const |
468 begin |
781 call = 'AddVisualGear'; |
469 LuaParameterCountError('AddVisualGear', 'x, y, visualGearType, state, critical', lua_gettop(L)); |
782 params = 'x, y, visualGearType, state, critical [, layer]'; |
|
783 begin |
|
784 uid:= 0; |
|
785 if CheckAndFetchParamCount(L, 5, 6, call, params, n) then |
|
786 begin |
|
787 s:= LuaToVisualGearTypeOrd(L, 3, call, params); |
|
788 if s >= 0 then |
|
789 begin |
|
790 vgt:= TVisualGearType(s); |
|
791 x:= lua_tointeger(L, 1); |
|
792 y:= lua_tointeger(L, 2); |
|
793 s:= lua_tointeger(L, 4); |
|
794 c:= lua_toboolean(L, 5); |
|
795 |
|
796 if n = 6 then |
|
797 begin |
|
798 layer:= lua_tointeger(L, 6); |
|
799 vg:= AddVisualGear(x, y, vgt, s, c, layer); |
|
800 end |
|
801 else |
|
802 vg:= AddVisualGear(x, y, vgt, s, c); |
|
803 |
|
804 if vg <> nil then |
|
805 begin |
|
806 lastVisualGearByUID:= vg; |
|
807 uid:= vg^.uid; |
|
808 lua_pushinteger(L, uid); |
|
809 end; |
|
810 end |
|
811 else |
|
812 lua_pushnil(L); |
|
813 end |
|
814 else |
470 lua_pushnil(L); // return value on stack (nil) |
815 lua_pushnil(L); // return value on stack (nil) |
471 end |
|
472 else |
|
473 begin |
|
474 x:= lua_tointeger(L, 1); |
|
475 y:= lua_tointeger(L, 2); |
|
476 vgt:= TVisualGearType(lua_tointeger(L, 3)); |
|
477 s:= lua_tointeger(L, 4); |
|
478 c:= lua_toboolean(L, 5); |
|
479 |
|
480 vg:= AddVisualGear(x, y, vgt, s, c); |
|
481 if vg <> nil then |
|
482 begin |
|
483 lastVisualGearByUID:= vg; |
|
484 lua_pushinteger(L, vg^.uid) |
|
485 end |
|
486 else |
|
487 lua_pushinteger(L, 0) |
|
488 end; |
|
489 lc_addvisualgear:= 1; // 1 return value |
816 lc_addvisualgear:= 1; // 1 return value |
490 end; |
817 end; |
491 |
818 |
492 function lc_deletevisualgear(L : Plua_State) : LongInt; Cdecl; |
819 function lc_deletevisualgear(L : Plua_State) : LongInt; Cdecl; |
493 var vg : PVisualGear; |
820 var vg : PVisualGear; |
494 begin |
821 begin |
495 if lua_gettop(L) <> 1 then |
822 vg:= nil; |
496 begin |
823 if CheckLuaParamCount(L, 1, 'DeleteVisualGear', 'vgUid') then |
497 LuaParameterCountError('DeleteVisualGear', 'vgUid', lua_gettop(L)); |
|
498 end |
|
499 else |
|
500 begin |
824 begin |
501 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
825 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
502 if vg <> nil then |
826 if vg <> nil then |
503 DeleteVisualGear(vg); |
827 DeleteVisualGear(vg); |
504 end; |
828 end; |
505 lc_deletevisualgear:= 0 |
829 // allow caller to know whether there was something to delete |
|
830 lua_pushboolean(L, vg <> nil); |
|
831 lc_deletevisualgear:= 1 |
506 end; |
832 end; |
507 |
833 |
508 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl; |
834 function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl; |
509 var vg: PVisualGear; |
835 var vg: PVisualGear; |
510 begin |
836 begin |
511 if lua_gettop(L) <> 1 then |
837 if CheckLuaParamCount(L, 1, 'GetVisualGearValues', 'vgUid') then |
512 begin |
|
513 LuaParameterCountError('GetVisualGearValues', 'vgUid', lua_gettop(L)); |
|
514 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
|
515 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L) |
|
516 end |
|
517 else |
|
518 begin |
838 begin |
519 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
839 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
520 if vg <> nil then |
840 if vg <> nil then |
521 begin |
841 begin |
522 lua_pushinteger(L, round(vg^.X)); |
842 lua_pushinteger(L, round(vg^.X)); |
531 lua_pushinteger(L, vg^.Tint); |
851 lua_pushinteger(L, vg^.Tint); |
532 end |
852 end |
533 else |
853 else |
534 begin |
854 begin |
535 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
855 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
536 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L) |
856 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
537 end |
857 end |
538 end; |
858 end |
539 lc_getvisualgearvalues:= 10; |
859 else |
|
860 begin |
|
861 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
|
862 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
|
863 end; |
|
864 lc_getvisualgearvalues:= 10 |
540 end; |
865 end; |
541 |
866 |
542 function lc_setvisualgearvalues(L : Plua_State) : LongInt; Cdecl; |
867 function lc_setvisualgearvalues(L : Plua_State) : LongInt; Cdecl; |
543 var vg : PVisualGear; |
868 var vg : PVisualGear; |
544 begin |
869 begin |
545 if lua_gettop(L) <> 11 then |
870 // Param count can be 1-11 at present |
546 begin |
871 // if CheckLuaParamCount(L, 11, 'SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint') then |
547 LuaParameterCountError('SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint', lua_gettop(L)); |
872 // begin |
548 lua_pushnil(L); // return value on stack (nil) |
|
549 end |
|
550 else |
|
551 begin |
|
552 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
873 vg:= VisualGearByUID(lua_tointeger(L, 1)); |
553 if vg <> nil then |
874 if vg <> nil then |
554 begin |
875 begin |
555 vg^.X:= lua_tointeger(L, 2); |
876 if not lua_isnoneornil(L, 2) then |
556 vg^.Y:= lua_tointeger(L, 3); |
877 vg^.X:= lua_tointeger(L, 2); |
557 vg^.dX:= lua_tonumber(L, 4); |
878 if not lua_isnoneornil(L, 3) then |
558 vg^.dY:= lua_tonumber(L, 5); |
879 vg^.Y:= lua_tointeger(L, 3); |
559 vg^.Angle:= lua_tonumber(L, 6); |
880 if not lua_isnoneornil(L, 4) then |
560 vg^.Frame:= lua_tointeger(L, 7); |
881 vg^.dX:= lua_tonumber(L, 4); |
561 if lua_tointeger(L, 8) <> 0 then |
882 if not lua_isnoneornil(L, 5) then |
562 vg^.FrameTicks:= lua_tointeger(L, 8); // find a better way to do this. maybe need to break all these up. |
883 vg^.dY:= lua_tonumber(L, 5); |
563 vg^.State:= lua_tointeger(L, 9); |
884 if not lua_isnoneornil(L, 6) then |
564 vg^.Timer:= lua_tointeger(L, 10); |
885 vg^.Angle:= lua_tonumber(L, 6); |
565 vg^.Tint:= lua_tointeger(L, 11); |
886 if not lua_isnoneornil(L, 7) then |
|
887 vg^.Frame:= lua_tointeger(L, 7); |
|
888 if not lua_isnoneornil(L, 8) then |
|
889 vg^.FrameTicks:= lua_tointeger(L, 8); |
|
890 if not lua_isnoneornil(L, 9) then |
|
891 vg^.State:= lua_tointeger(L, 9); |
|
892 if not lua_isnoneornil(L, 10) then |
|
893 vg^.Timer:= lua_tointeger(L, 10); |
|
894 if not lua_isnoneornil(L, 11) then |
|
895 vg^.Tint:= lua_tointeger(L, 11) |
|
896 end; |
|
897 // end |
|
898 // else |
|
899 // lua_pushnil(L); // return value on stack (nil) |
|
900 lc_setvisualgearvalues:= 0 |
|
901 end; |
|
902 |
|
903 // so. going to use this to get/set some of the more obscure gear values which weren't already exposed elsewhere |
|
904 // can keep adding things in the future. isnoneornil makes it safe |
|
905 function lc_getgearvalues(L : Plua_State) : LongInt; Cdecl; |
|
906 var gear: PGear; |
|
907 begin |
|
908 if CheckLuaParamCount(L, 1, 'GetGearValues', 'gearUid') then |
|
909 begin |
|
910 gear:= GearByUID(lua_tointeger(L, 1)); |
|
911 if gear <> nil then |
|
912 begin |
|
913 lua_pushinteger(L, gear^.Angle); |
|
914 lua_pushinteger(L, gear^.Power); |
|
915 lua_pushinteger(L, gear^.WDTimer); |
|
916 lua_pushinteger(L, gear^.Radius); |
|
917 lua_pushinteger(L, hwRound(gear^.Density * _10000)); |
|
918 lua_pushinteger(L, gear^.Karma); |
|
919 lua_pushnumber(L, gear^.DirAngle); |
|
920 lua_pushinteger(L, gear^.AdvBounce); |
|
921 lua_pushinteger(L, Integer(gear^.ImpactSound)); |
|
922 lua_pushinteger(L, gear^.nImpactSounds); |
|
923 lua_pushinteger(L, gear^.Tint); |
|
924 lua_pushinteger(L, gear^.Damage) |
566 end |
925 end |
567 end; |
926 else |
568 lc_setvisualgearvalues:= 0; |
927 begin |
|
928 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
|
929 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
|
930 lua_pushnil(L); lua_pushnil(L) |
|
931 end |
|
932 end |
|
933 else |
|
934 begin |
|
935 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
|
936 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
|
937 lua_pushnil(L); lua_pushnil(L) |
|
938 end; |
|
939 lc_getgearvalues:= 12 |
|
940 end; |
|
941 |
|
942 function lc_setgearvalues(L : Plua_State) : LongInt; Cdecl; |
|
943 var gear : PGear; |
|
944 begin |
|
945 // Currently allows 1-13 params |
|
946 // if CheckLuaParamCount(L, 13, 'SetGearValues', 'gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, # ImpactSounds, Tint, Damage') then |
|
947 // begin |
|
948 gear:= GearByUID(lua_tointeger(L, 1)); |
|
949 if gear <> nil then |
|
950 begin |
|
951 if not lua_isnoneornil(L, 2) then |
|
952 gear^.Angle := lua_tointeger(L, 2); |
|
953 if not lua_isnoneornil(L, 3) then |
|
954 gear^.Power := lua_tointeger(L, 3); |
|
955 if not lua_isnoneornil(L, 4) then |
|
956 gear^.WDTimer := lua_tointeger(L, 4); |
|
957 if not lua_isnoneornil(L, 5) then |
|
958 gear^.Radius := lua_tointeger(L, 5); |
|
959 if not lua_isnoneornil(L, 6) then |
|
960 gear^.Density:= int2hwFloat(lua_tointeger(L, 6)) / 10000; |
|
961 if not lua_isnoneornil(L, 7) then |
|
962 gear^.Karma := lua_tointeger(L, 7); |
|
963 if not lua_isnoneornil(L, 8) then |
|
964 gear^.DirAngle:= lua_tonumber(L, 8); |
|
965 if not lua_isnoneornil(L, 9) then |
|
966 gear^.AdvBounce := lua_tointeger(L, 9); |
|
967 if not lua_isnoneornil(L, 10) then |
|
968 gear^.ImpactSound := TSound(lua_tointeger(L, 10)); |
|
969 if not lua_isnoneornil(L, 11) then |
|
970 gear^.nImpactSounds := lua_tointeger(L, 11); |
|
971 if not lua_isnoneornil(L, 12) then |
|
972 gear^.Tint := lua_tointeger(L, 12); |
|
973 if not lua_isnoneornil(L, 13) then |
|
974 gear^.Damage := lua_tointeger(L, 13); |
|
975 end; |
|
976 // end |
|
977 // else |
|
978 // lua_pushnil(L); // return value on stack (nil) |
|
979 lc_setgearvalues:= 0 |
569 end; |
980 end; |
570 |
981 |
571 function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl; |
982 function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl; |
572 begin |
983 begin |
573 if lua_gettop(L) <> 0 then |
984 if CheckLuaParamCount(L, 0, 'GetFollowGear', '') then |
574 begin |
985 begin |
575 LuaParameterCountError('GetFollowGear', '', lua_gettop(L)); |
|
576 lua_pushnil(L); // return value on stack (nil) |
|
577 end |
|
578 else |
|
579 if FollowGear = nil then |
986 if FollowGear = nil then |
580 lua_pushnil(L) |
987 lua_pushnil(L) |
581 else |
988 else |
582 lua_pushinteger(L, FollowGear^.uid); |
989 lua_pushinteger(L, FollowGear^.uid); |
|
990 end |
|
991 else |
|
992 lua_pushnil(L); |
583 lc_getfollowgear:= 1; // 1 return value |
993 lc_getfollowgear:= 1; // 1 return value |
584 end; |
994 end; |
585 |
995 |
586 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl; |
996 function lc_getgeartype(L : Plua_State) : LongInt; Cdecl; |
587 var gear : PGear; |
997 var gear : PGear; |
588 begin |
998 begin |
589 if lua_gettop(L) <> 1 then |
999 if CheckLuaParamCount(L, 1, 'GetGearType', 'gearUid') then |
590 begin |
1000 begin |
591 LuaParameterCountError('GetGearType', 'gearUid', lua_gettop(L)); |
1001 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1002 if gear <> nil then |
|
1003 lua_pushinteger(L, ord(gear^.Kind)) |
|
1004 else |
|
1005 lua_pushnil(L); |
|
1006 end |
|
1007 else |
592 lua_pushnil(L); // return value on stack (nil) |
1008 lua_pushnil(L); // return value on stack (nil) |
593 end |
1009 lc_getgeartype:= 1 |
594 else |
1010 end; |
595 begin |
1011 |
596 gear:= GearByUID(lua_tointeger(L, 1)); |
1012 function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl; |
597 if gear <> nil then |
1013 var gear : PGear; |
598 lua_pushinteger(L, ord(gear^.Kind)) |
1014 begin |
|
1015 if CheckLuaParamCount(L, 1, 'GetGearMessage', 'gearUid') then |
|
1016 begin |
|
1017 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1018 if gear <> nil then |
|
1019 lua_pushinteger(L, gear^.message) |
599 else |
1020 else |
600 lua_pushnil(L); |
1021 lua_pushnil(L); |
601 end; |
1022 end |
602 lc_getgeartype:= 1 |
1023 else |
603 end; |
|
604 |
|
605 function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl; |
|
606 var gear : PGear; |
|
607 begin |
|
608 if lua_gettop(L) <> 1 then |
|
609 begin |
|
610 LuaParameterCountError('GetGearMessage', 'gearUid', lua_gettop(L)); |
|
611 lua_pushnil(L); // return value on stack (nil) |
1024 lua_pushnil(L); // return value on stack (nil) |
612 end |
1025 lc_getgearmessage:= 1 |
613 else |
1026 end; |
614 begin |
1027 |
615 gear:= GearByUID(lua_tointeger(L, 1)); |
1028 function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl; |
616 if gear <> nil then |
1029 var gear : PGear; |
617 lua_pushinteger(L, gear^.message) |
1030 begin |
|
1031 if CheckLuaParamCount(L, 1, 'GetGearElasticity', 'gearUid') then |
|
1032 begin |
|
1033 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1034 if gear <> nil then |
|
1035 lua_pushinteger(L, hwRound(gear^.elasticity * _10000)) |
618 else |
1036 else |
619 lua_pushnil(L); |
1037 lua_pushnil(L); |
620 end; |
1038 end |
621 lc_getgearmessage:= 1 |
1039 else |
622 end; |
|
623 |
|
624 function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl; |
|
625 var gear : PGear; |
|
626 begin |
|
627 if lua_gettop(L) <> 1 then |
|
628 begin |
|
629 LuaParameterCountError('GetGearElasticity', 'gearUid', lua_gettop(L)); |
|
630 lua_pushnil(L); // return value on stack (nil) |
1040 lua_pushnil(L); // return value on stack (nil) |
631 end |
1041 lc_getgearelasticity:= 1 |
632 else |
1042 end; |
633 begin |
1043 |
634 gear:= GearByUID(lua_tointeger(L, 1)); |
1044 function lc_setgearelasticity(L : Plua_State) : LongInt; Cdecl; |
635 if gear <> nil then |
1045 var gear: PGear; |
636 lua_pushinteger(L, hwRound(gear^.elasticity * _10000)) |
1046 begin |
|
1047 if CheckLuaParamCount(L, 2, 'SetGearElasticity', 'gearUid, Elasticity') then |
|
1048 begin |
|
1049 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1050 if gear <> nil then |
|
1051 gear^.Elasticity:= int2hwFloat(lua_tointeger(L, 2)) / 10000 |
|
1052 end; |
|
1053 lc_setgearelasticity:= 0 |
|
1054 end; |
|
1055 |
|
1056 function lc_getgearfriction(L : Plua_State) : LongInt; Cdecl; |
|
1057 var gear : PGear; |
|
1058 begin |
|
1059 if CheckLuaParamCount(L, 1, 'GetGearFriction', 'gearUid') then |
|
1060 begin |
|
1061 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1062 if gear <> nil then |
|
1063 lua_pushinteger(L, hwRound(gear^.friction * _10000)) |
637 else |
1064 else |
638 lua_pushnil(L); |
1065 lua_pushnil(L); |
639 end; |
1066 end |
640 lc_getgearelasticity:= 1 |
1067 else |
|
1068 lua_pushnil(L); // return value on stack (nil) |
|
1069 lc_getgearfriction:= 1 |
|
1070 end; |
|
1071 |
|
1072 function lc_setgearfriction(L : Plua_State) : LongInt; Cdecl; |
|
1073 var gear: PGear; |
|
1074 begin |
|
1075 if CheckLuaParamCount(L, 2, 'SetGearFriction', 'gearUid, Friction') then |
|
1076 begin |
|
1077 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1078 if gear <> nil then |
|
1079 gear^.Friction:= int2hwFloat(lua_tointeger(L, 2)) / 10000 |
|
1080 end; |
|
1081 lc_setgearfriction:= 0 |
641 end; |
1082 end; |
642 |
1083 |
643 function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl; |
1084 function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl; |
644 var gear : PGear; |
1085 var gear : PGear; |
645 begin |
1086 begin |
646 if lua_gettop(L) <> 2 then |
1087 if CheckLuaParamCount(L, 2, 'SetGearMessage', 'gearUid, message') then |
647 LuaParameterCountError('SetGearMessage', 'gearUid, message', lua_gettop(L)) |
|
648 else |
|
649 begin |
1088 begin |
650 gear:= GearByUID(lua_tointeger(L, 1)); |
1089 gear:= GearByUID(lua_tointeger(L, 1)); |
651 if gear <> nil then |
1090 if gear <> nil then |
652 gear^.message:= lua_tointeger(L, 2); |
1091 gear^.message:= lua_tointeger(L, 2); |
653 end; |
1092 end; |
751 end; |
1176 end; |
752 |
1177 |
753 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl; |
1178 function lc_gethogclan(L : Plua_State) : LongInt; Cdecl; |
754 var gear : PGear; |
1179 var gear : PGear; |
755 begin |
1180 begin |
756 if lua_gettop(L) <> 1 then |
1181 if CheckLuaParamCount(L, 1, 'GetHogClan', 'gearUid') then |
757 begin |
|
758 LuaParameterCountError('GetHogClan', 'gearUid', lua_gettop(L)); |
|
759 lua_pushnil(L); // return value on stack (nil) |
|
760 end |
|
761 else |
|
762 begin |
1182 begin |
763 gear:= GearByUID(lua_tointeger(L, 1)); |
1183 gear:= GearByUID(lua_tointeger(L, 1)); |
764 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1184 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
765 begin |
1185 begin |
766 lua_pushinteger(L, gear^.Hedgehog^.Team^.Clan^.ClanIndex) |
1186 lua_pushinteger(L, gear^.Hedgehog^.Team^.Clan^.ClanIndex) |
767 end |
1187 end |
768 else |
1188 else |
769 lua_pushnil(L); |
1189 lua_pushnil(L); |
770 end; |
1190 end |
|
1191 else |
|
1192 lua_pushnil(L); // return value on stack (nil) |
771 lc_gethogclan:= 1 |
1193 lc_gethogclan:= 1 |
772 end; |
1194 end; |
773 |
1195 |
774 function lc_getclancolor(L : Plua_State) : LongInt; Cdecl; |
1196 function lc_getclancolor(L : Plua_State) : LongInt; Cdecl; |
775 begin |
1197 begin |
776 if lua_gettop(L) <> 1 then |
1198 if CheckLuaParamCount(L, 1, 'GetClanColor', 'clan') then |
777 begin |
1199 lua_pushinteger(L, ClansArray[lua_tointeger(L, 1)]^.Color shl 8 or $FF) |
778 LuaParameterCountError('GetClanColor', 'clan', lua_gettop(L)); |
1200 else |
779 lua_pushnil(L); // return value on stack (nil) |
1201 lua_pushnil(L); // return value on stack (nil) |
780 end |
|
781 else lua_pushinteger(L, ClansArray[lua_tointeger(L, 1)]^.Color shl 8 or $FF); |
|
782 lc_getclancolor:= 1 |
1202 lc_getclancolor:= 1 |
783 end; |
1203 end; |
784 |
1204 |
785 function lc_setclancolor(L : Plua_State) : LongInt; Cdecl; |
1205 function lc_setclancolor(L : Plua_State) : LongInt; Cdecl; |
786 var clan : PClan; |
1206 var clan : PClan; |
787 team : PTeam; |
1207 team : PTeam; |
788 hh : THedgehog; |
1208 hh : THedgehog; |
789 i, j : LongInt; |
1209 i, j : LongInt; |
790 begin |
1210 begin |
791 if lua_gettop(L) <> 2 then |
1211 if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then |
792 LuaParameterCountError('SetClanColor', 'clan, color', lua_gettop(L)) |
1212 begin |
793 else |
1213 i:= lua_tointeger(L,1); |
794 begin |
1214 if i >= ClansCount then exit(0); |
795 clan := ClansArray[lua_tointeger(L, 1)]; |
1215 clan := ClansArray[i]; |
796 clan^.Color:= lua_tointeger(L, 2) shr 8; |
1216 clan^.Color:= lua_tointeger(L, 2) shr 8; |
797 |
1217 |
798 for i:= 0 to Pred(clan^.TeamsNumber) do |
1218 for i:= 0 to Pred(clan^.TeamsNumber) do |
799 begin |
1219 begin |
800 team:= clan^.Teams[i]; |
1220 team:= clan^.Teams[i]; |
801 for j:= 0 to 7 do |
1221 for j:= 0 to 7 do |
802 begin |
1222 begin |
803 hh:= team^.Hedgehogs[j]; |
1223 hh:= team^.Hedgehogs[j]; |
804 if (hh.Gear <> nil) or (hh.GearHidden <> nil) then |
1224 if (hh.Gear <> nil) or (hh.GearHidden <> nil) then |
805 begin |
1225 begin |
806 FreeTexture(hh.NameTagTex); |
1226 FreeAndNilTexture(hh.NameTagTex); |
807 hh.NameTagTex:= RenderStringTex(hh.Name, clan^.Color, fnt16); |
1227 hh.NameTagTex:= RenderStringTex(ansistring(hh.Name), clan^.Color, fnt16); |
808 RenderHealth(hh); |
1228 RenderHealth(hh); |
809 end; |
1229 end; |
810 end; |
1230 end; |
811 FreeTexture(team^.NameTagTex); |
1231 FreeAndNilTexture(team^.NameTagTex); |
812 team^.NameTagTex:= RenderStringTex(clan^.Teams[i]^.TeamName, clan^.Color, fnt16); |
1232 team^.NameTagTex:= RenderStringTex(ansistring(clan^.Teams[i]^.TeamName), clan^.Color, fnt16); |
813 end; |
1233 end; |
814 |
1234 |
|
1235 FreeAndNilTexture(clan^.HealthTex); |
815 clan^.HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, clan^.Teams[0]^.NameTagTex^.h, clan^.Color); |
1236 clan^.HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, clan^.Teams[0]^.NameTagTex^.h, clan^.Color); |
816 end; |
1237 end; |
817 |
1238 |
818 lc_setclancolor:= 0 |
1239 lc_setclancolor:= 0 |
819 end; |
1240 end; |
820 |
1241 |
|
1242 function lc_gethogvoicepack(L : Plua_State) : LongInt; Cdecl; |
|
1243 var gear : PGear; |
|
1244 begin |
|
1245 if CheckLuaParamCount(L, 1, 'GetHogVoicepack', 'gearUid') then |
|
1246 begin |
|
1247 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1248 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
|
1249 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Voicepack^.name)) |
|
1250 else |
|
1251 lua_pushnil(L); |
|
1252 end |
|
1253 else |
|
1254 lua_pushnil(L); // return value on stack (nil) |
|
1255 lc_gethogvoicepack:= 1 |
|
1256 end; |
|
1257 |
|
1258 function lc_gethoggrave(L : Plua_State) : LongInt; Cdecl; |
|
1259 var gear : PGear; |
|
1260 begin |
|
1261 if CheckLuaParamCount(L, 1, 'GetHogGrave', 'gearUid') then |
|
1262 begin |
|
1263 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1264 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
|
1265 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.GraveName)) |
|
1266 else |
|
1267 lua_pushnil(L); |
|
1268 end |
|
1269 else |
|
1270 lua_pushnil(L); // return value on stack (nil) |
|
1271 lc_gethoggrave:= 1 |
|
1272 end; |
|
1273 |
|
1274 function lc_gethogflag(L : Plua_State) : LongInt; Cdecl; |
|
1275 var gear : PGear; |
|
1276 begin |
|
1277 if CheckLuaParamCount(L, 1, 'GetHogFlag', 'gearUid') then |
|
1278 begin |
|
1279 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1280 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
|
1281 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Flag)) |
|
1282 else |
|
1283 lua_pushnil(L); |
|
1284 end |
|
1285 else |
|
1286 lua_pushnil(L); // return value on stack (nil) |
|
1287 lc_gethogflag:= 1 |
|
1288 end; |
|
1289 |
821 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl; |
1290 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl; |
822 var gear : PGear; |
1291 var gear : PGear; |
823 begin |
1292 begin |
824 if lua_gettop(L) <> 1 then |
1293 if CheckLuaParamCount(L, 1, 'GetHogTeamName', 'gearUid') then |
825 begin |
1294 begin |
826 LuaParameterCountError('GetHogTeamName', 'gearUid', lua_gettop(L)); |
1295 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1296 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
|
1297 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName)) |
|
1298 else |
|
1299 lua_pushnil(L); |
|
1300 end |
|
1301 else |
827 lua_pushnil(L); // return value on stack (nil) |
1302 lua_pushnil(L); // return value on stack (nil) |
828 end |
|
829 else |
|
830 begin |
|
831 gear:= GearByUID(lua_tointeger(L, 1)); |
|
832 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
|
833 begin |
|
834 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName)) |
|
835 end |
|
836 else |
|
837 lua_pushnil(L); |
|
838 end; |
|
839 lc_gethogteamname:= 1 |
1303 lc_gethogteamname:= 1 |
840 end; |
1304 end; |
841 |
1305 |
842 function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl; |
1306 function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl; |
843 var gear : PGear; |
1307 var gear : PGear; |
844 begin |
1308 begin |
845 if lua_gettop(L) <> 2 then |
1309 if CheckLuaParamCount(L, 2, 'SetHogTeamName', 'gearUid, name') then |
846 begin |
|
847 LuaParameterCountError('SetHogTeamName', 'gearUid, name', lua_gettop(L)); |
|
848 lua_pushnil(L); // return value on stack (nil) |
|
849 end |
|
850 else |
|
851 begin |
1310 begin |
852 gear := GearByUID(lua_tointeger(L, 1)); |
1311 gear := GearByUID(lua_tointeger(L, 1)); |
853 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1312 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
854 begin |
1313 begin |
855 gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2); |
1314 gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2); |
856 |
1315 |
857 FreeTexture(gear^.Hedgehog^.Team^.NameTagTex); |
1316 FreeAndNilTexture(gear^.Hedgehog^.Team^.NameTagTex); |
858 gear^.Hedgehog^.Team^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Team^.TeamName, gear^.Hedgehog^.Team^.Clan^.Color, fnt16); |
1317 gear^.Hedgehog^.Team^.NameTagTex:= RenderStringTex(ansistring(gear^.Hedgehog^.Team^.TeamName), gear^.Hedgehog^.Team^.Clan^.Color, fnt16); |
859 end |
1318 end |
860 else |
1319 else |
861 lua_pushnil(L); |
1320 lua_pushnil(L); |
862 end; |
1321 end |
|
1322 else |
|
1323 lua_pushnil(L); // return value on stack (nil) |
863 lc_sethogteamname:= 1 |
1324 lc_sethogteamname:= 1 |
864 end; |
1325 end; |
865 |
1326 |
866 function lc_gethogname(L : Plua_State) : LongInt; Cdecl; |
1327 function lc_gethogname(L : Plua_State) : LongInt; Cdecl; |
867 var gear : PGear; |
1328 var gear : PGear; |
868 begin |
1329 begin |
869 if lua_gettop(L) <> 1 then |
1330 if CheckLuaParamCount(L, 1, 'GetHogName', 'gearUid') then |
870 begin |
|
871 LuaParameterCountError('GetHogName', 'gearUid', lua_gettop(L)); |
|
872 lua_pushnil(L); // return value on stack (nil) |
|
873 end |
|
874 else |
|
875 begin |
1331 begin |
876 gear:= GearByUID(lua_tointeger(L, 1)); |
1332 gear:= GearByUID(lua_tointeger(L, 1)); |
877 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
1333 if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then |
878 begin |
1334 begin |
879 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Name)) |
1335 lua_pushstring(L, str2pchar(gear^.Hedgehog^.Name)) |
880 end |
1336 end |
881 else |
1337 else |
882 lua_pushnil(L); |
1338 lua_pushnil(L); |
883 end; |
1339 end |
|
1340 else |
|
1341 lua_pushnil(L); // return value on stack (nil) |
884 lc_gethogname:= 1 |
1342 lc_gethogname:= 1 |
885 end; |
1343 end; |
886 |
1344 |
887 function lc_sethogname(L : Plua_State) : LongInt; Cdecl; |
1345 function lc_sethogname(L : Plua_State) : LongInt; Cdecl; |
888 var gear : PGear; |
1346 var gear : PGear; |
889 begin |
1347 begin |
890 if lua_gettop(L) <> 2 then |
1348 if CheckLuaParamCount(L, 2, 'SetHogName', 'gearUid, name') then |
891 begin |
|
892 LuaParameterCountError('SetHogName', 'gearUid, name', lua_gettop(L)); |
|
893 lua_pushnil(L) |
|
894 end |
|
895 else |
|
896 begin |
1349 begin |
897 gear:= GearByUID(lua_tointeger(L, 1)); |
1350 gear:= GearByUID(lua_tointeger(L, 1)); |
898 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
1351 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
899 begin |
1352 begin |
900 gear^.Hedgehog^.Name:= lua_tostring(L, 2); |
1353 gear^.Hedgehog^.Name:= lua_tostring(L, 2); |
901 |
1354 |
902 FreeTexture(gear^.Hedgehog^.NameTagTex); |
1355 FreeAndNilTexture(gear^.Hedgehog^.NameTagTex); |
903 gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16) |
1356 gear^.Hedgehog^.NameTagTex:= RenderStringTex(ansistring(gear^.Hedgehog^.Name), gear^.Hedgehog^.Team^.Clan^.Color, fnt16) |
904 end |
1357 end |
905 end; |
1358 end; |
906 lc_sethogname:= 0; |
1359 lc_sethogname:= 0; |
907 end; |
1360 end; |
908 |
1361 |
909 function lc_gettimer(L : Plua_State) : LongInt; Cdecl; |
1362 function lc_gettimer(L : Plua_State) : LongInt; Cdecl; |
910 var gear : PGear; |
1363 var gear : PGear; |
911 begin |
1364 begin |
912 if lua_gettop(L) <> 1 then |
1365 if CheckLuaParamCount(L, 1, 'GetTimer', 'gearUid') then |
913 begin |
1366 begin |
914 LuaParameterCountError('GetTimer', 'gearUid', lua_gettop(L)); |
1367 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1368 if gear <> nil then |
|
1369 lua_pushinteger(L, gear^.Timer) |
|
1370 else |
|
1371 lua_pushnil(L); |
|
1372 end |
|
1373 else |
915 lua_pushnil(L); // return value on stack (nil) |
1374 lua_pushnil(L); // return value on stack (nil) |
916 end |
1375 lc_gettimer:= 1 |
917 else |
1376 end; |
918 begin |
1377 |
919 gear:= GearByUID(lua_tointeger(L, 1)); |
1378 function lc_getflighttime(L : Plua_State) : LongInt; Cdecl; |
920 if gear <> nil then |
1379 var gear : PGear; |
921 lua_pushinteger(L, gear^.Timer) |
1380 begin |
|
1381 if CheckLuaParamCount(L, 1, 'GetFlightTime', 'gearUid') then |
|
1382 begin |
|
1383 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1384 if gear <> nil then |
|
1385 lua_pushinteger(L, gear^.FlightTime) |
922 else |
1386 else |
923 lua_pushnil(L); |
1387 lua_pushnil(L); |
924 end; |
1388 end |
925 lc_gettimer:= 1 |
1389 else |
|
1390 lua_pushnil(L); // return value on stack (nil) |
|
1391 lc_getflighttime:= 1 |
926 end; |
1392 end; |
927 |
1393 |
928 function lc_gethealth(L : Plua_State) : LongInt; Cdecl; |
1394 function lc_gethealth(L : Plua_State) : LongInt; Cdecl; |
929 var gear : PGear; |
1395 var gear : PGear; |
930 begin |
1396 begin |
931 if lua_gettop(L) <> 1 then |
1397 if CheckLuaParamCount(L, 1, 'GetHealth', 'gearUid') then |
932 begin |
1398 begin |
933 LuaParameterCountError('GetHealth', 'gearUid', lua_gettop(L)); |
1399 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1400 if gear <> nil then |
|
1401 lua_pushinteger(L, gear^.Health) |
|
1402 else |
|
1403 lua_pushnil(L); |
|
1404 end |
|
1405 else |
934 lua_pushnil(L); // return value on stack (nil) |
1406 lua_pushnil(L); // return value on stack (nil) |
935 end |
1407 lc_gethealth:= 1 |
936 else |
1408 end; |
937 begin |
1409 |
938 gear:= GearByUID(lua_tointeger(L, 1)); |
1410 function lc_getx(L : Plua_State) : LongInt; Cdecl; |
939 if gear <> nil then |
1411 var gear : PGear; |
940 lua_pushinteger(L, gear^.Health) |
1412 begin |
|
1413 if CheckLuaParamCount(L, 1, 'GetX', 'gearUid') then |
|
1414 begin |
|
1415 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1416 if gear <> nil then |
|
1417 lua_pushinteger(L, hwRound(gear^.X)) |
941 else |
1418 else |
942 lua_pushnil(L); |
1419 lua_pushnil(L); |
943 end; |
1420 end |
944 lc_gethealth:= 1 |
1421 else |
945 end; |
|
946 |
|
947 function lc_getx(L : Plua_State) : LongInt; Cdecl; |
|
948 var gear : PGear; |
|
949 begin |
|
950 if lua_gettop(L) <> 1 then |
|
951 begin |
|
952 LuaParameterCountError('GetX', 'gearUid', lua_gettop(L)); |
|
953 lua_pushnil(L); // return value on stack (nil) |
1422 lua_pushnil(L); // return value on stack (nil) |
954 end |
1423 lc_getx:= 1 |
955 else |
1424 end; |
956 begin |
1425 |
957 gear:= GearByUID(lua_tointeger(L, 1)); |
1426 function lc_gety(L : Plua_State) : LongInt; Cdecl; |
958 if gear <> nil then |
1427 var gear : PGear; |
959 lua_pushinteger(L, hwRound(gear^.X)) |
1428 begin |
|
1429 if CheckLuaParamCount(L, 1, 'GetY', 'gearUid') then |
|
1430 begin |
|
1431 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1432 if gear <> nil then |
|
1433 lua_pushinteger(L, hwRound(gear^.Y)) |
960 else |
1434 else |
961 lua_pushnil(L); |
1435 lua_pushnil(L); |
962 end; |
1436 end |
963 lc_getx:= 1 |
1437 else |
964 end; |
|
965 |
|
966 function lc_gety(L : Plua_State) : LongInt; Cdecl; |
|
967 var gear : PGear; |
|
968 begin |
|
969 if lua_gettop(L) <> 1 then |
|
970 begin |
|
971 LuaParameterCountError('GetY', 'gearUid', lua_gettop(L)); |
|
972 lua_pushnil(L); // return value on stack (nil) |
1438 lua_pushnil(L); // return value on stack (nil) |
973 end |
|
974 else |
|
975 begin |
|
976 gear:= GearByUID(lua_tointeger(L, 1)); |
|
977 if gear <> nil then |
|
978 lua_pushinteger(L, hwRound(gear^.Y)) |
|
979 else |
|
980 lua_pushnil(L); |
|
981 end; |
|
982 lc_gety:= 1 |
1439 lc_gety:= 1 |
983 end; |
1440 end; |
984 |
1441 |
985 function lc_copypv(L : Plua_State) : LongInt; Cdecl; |
1442 function lc_copypv(L : Plua_State) : LongInt; Cdecl; |
986 var gears, geard : PGear; |
1443 var gears, geard : PGear; |
987 begin |
1444 begin |
988 if lua_gettop(L) <> 2 then |
1445 if CheckLuaParamCount(L, 2, 'CopyPV', 'fromGearUid, toGearUid') then |
989 begin |
|
990 LuaParameterCountError('CopyPV', 'fromGearUid, toGearUid', lua_gettop(L)); |
|
991 end |
|
992 else |
|
993 begin |
1446 begin |
994 gears:= GearByUID(lua_tointeger(L, 1)); |
1447 gears:= GearByUID(lua_tointeger(L, 1)); |
995 geard:= GearByUID(lua_tointeger(L, 2)); |
1448 geard:= GearByUID(lua_tointeger(L, 2)); |
996 if (gears <> nil) and (geard <> nil) then |
1449 if (gears <> nil) and (geard <> nil) then |
997 begin |
1450 begin |
1081 end |
1537 end |
1082 end; |
1538 end; |
1083 lc_switchhog:= 0 |
1539 lc_switchhog:= 0 |
1084 end; |
1540 end; |
1085 |
1541 |
1086 {function lc_addammo(L : Plua_State) : LongInt; Cdecl; |
1542 function lc_addammo(L : Plua_State) : LongInt; Cdecl; |
1087 var gear : PGear; |
1543 var gear : PGear; |
1088 begin |
1544 at, n: LongInt; |
1089 |
1545 const |
1090 if lua_gettop(L) = 3 then |
1546 call = 'AddAmmo'; |
1091 begin |
1547 params = 'gearUid, ammoType [, ammoCount]'; |
1092 gear:= GearByUID(lua_tointeger(L, 1)); |
1548 begin |
|
1549 if CheckAndFetchParamCount(L, 2, 3, call, params, n) then |
|
1550 begin |
|
1551 at:= LuaToAmmoTypeOrd(L, 2, call, params); |
|
1552 if at >= 0 then |
|
1553 begin |
|
1554 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1555 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
|
1556 if n = 2 then |
|
1557 AddAmmo(gear^.Hedgehog^, TAmmoType(at)) |
|
1558 else |
|
1559 SetAmmo(gear^.Hedgehog^, TAmmoType(at), lua_tointeger(L, 3)) |
|
1560 end; |
|
1561 end; |
|
1562 lc_addammo:= 0 |
|
1563 end; |
|
1564 |
|
1565 function lc_getammocount(L : Plua_State) : LongInt; Cdecl; |
|
1566 var gear : PGear; |
|
1567 ammo : PAmmo; |
|
1568 at : LongInt; |
|
1569 const |
|
1570 call = 'GetAmmoCount'; |
|
1571 params = 'gearUid, ammoType'; |
|
1572 begin |
|
1573 if CheckLuaParamCount(L, 2, call, params) then |
|
1574 begin |
|
1575 gear:= GearByUID(lua_tointeger(L, 1)); |
1093 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
1576 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
1094 AddAmmoAmount(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L,3) ); |
1577 begin |
1095 end else |
1578 at:= LuaToAmmoTypeOrd(L, 2, call, params); |
1096 |
1579 if at >= 0 then |
1097 if lua_gettop(L) = 2 then |
1580 begin |
1098 begin |
1581 ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at)); |
1099 gear:= GearByUID(lua_tointeger(L, 1)); |
1582 if ammo^.AmmoType = amNothing then |
1100 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
1583 lua_pushinteger(L, 0) |
1101 AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2))); |
1584 else |
1102 end else |
1585 lua_pushinteger(L, ammo^.Count); |
1103 begin |
1586 end; |
1104 LuaParameterCountError('AddAmmo', 'TODO', lua_gettop(L)); |
|
1105 end; |
|
1106 |
|
1107 lc_addammo:= 0; |
|
1108 |
|
1109 end;} |
|
1110 |
|
1111 function lc_addammo(L : Plua_State) : LongInt; Cdecl; |
|
1112 var gear : PGear; |
|
1113 begin |
|
1114 if (lua_gettop(L) = 3) or (lua_gettop(L) = 2) then |
|
1115 begin |
|
1116 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1117 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
|
1118 if lua_gettop(L) = 2 then |
|
1119 AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2))) |
|
1120 else |
|
1121 SetAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L, 3)) |
|
1122 end |
|
1123 else LuaParameterCountError('AddAmmo', 'gearUid, ammoType[, ammoCount]', lua_gettop(L)); |
|
1124 lc_addammo:= 0 |
|
1125 end; |
|
1126 |
|
1127 function lc_getammocount(L : Plua_State) : LongInt; Cdecl; |
|
1128 var gear : PGear; |
|
1129 ammo : PAmmo; |
|
1130 begin |
|
1131 if (lua_gettop(L) = 2) then |
|
1132 begin |
|
1133 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1134 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
|
1135 begin |
|
1136 ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2))); |
|
1137 if ammo^.AmmoType = amNothing then |
|
1138 lua_pushinteger(L, 0) |
|
1139 else |
|
1140 lua_pushinteger(L, ammo^.Count) |
|
1141 end |
1587 end |
1142 else lua_pushinteger(L, 0) |
1588 else lua_pushinteger(L, 0); |
1143 end |
1589 end |
1144 else |
1590 else |
1145 begin |
1591 lua_pushnil(L); |
1146 LuaParameterCountError('GetAmmoCount', 'gearUid, ammoType', lua_gettop(L)); |
|
1147 lua_pushnil(L) |
|
1148 end; |
|
1149 lc_getammocount:= 1 |
1592 lc_getammocount:= 1 |
1150 end; |
1593 end; |
1151 |
1594 |
1152 function lc_sethealth(L : Plua_State) : LongInt; Cdecl; |
1595 function lc_sethealth(L : Plua_State) : LongInt; Cdecl; |
1153 var gear : PGear; |
1596 var gear : PGear; |
1154 begin |
1597 begin |
1155 if lua_gettop(L) <> 2 then |
1598 if CheckLuaParamCount(L, 2, 'SetHealth', 'gearUid, health') then |
1156 begin |
|
1157 LuaParameterCountError('SetHealth', 'gearUid, health', lua_gettop(L)); |
|
1158 end |
|
1159 else |
|
1160 begin |
1599 begin |
1161 gear:= GearByUID(lua_tointeger(L, 1)); |
1600 gear:= GearByUID(lua_tointeger(L, 1)); |
1162 if gear <> nil then |
1601 if gear <> nil then |
1163 begin |
1602 begin |
1164 gear^.Health:= lua_tointeger(L, 2); |
1603 gear^.Health:= lua_tointeger(L, 2); |
1165 |
1604 |
1166 if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
1605 if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
1167 begin |
1606 begin |
1168 RenderHealth(gear^.Hedgehog^); |
1607 RenderHealth(gear^.Hedgehog^); |
1169 RecountTeamHealth(gear^.Hedgehog^.Team) |
1608 RecountTeamHealth(gear^.Hedgehog^.Team) |
1170 end; |
1609 end; |
1171 |
1610 // Why did this do a "setalltoactive" ? |
1172 SetAllToActive; |
1611 //SetAllToActive; |
|
1612 Gear^.Active:= true; |
|
1613 AllInactive:= false |
1173 end |
1614 end |
1174 end; |
1615 end; |
1175 lc_sethealth:= 0 |
1616 lc_sethealth:= 0 |
1176 end; |
1617 end; |
1177 |
1618 |
1178 function lc_settimer(L : Plua_State) : LongInt; Cdecl; |
1619 function lc_settimer(L : Plua_State) : LongInt; Cdecl; |
1179 var gear : PGear; |
1620 var gear : PGear; |
1180 begin |
1621 begin |
1181 if lua_gettop(L) <> 2 then |
1622 if CheckLuaParamCount(L, 2, 'SetTimer', 'gearUid, timer') then |
1182 begin |
|
1183 LuaParameterCountError('SetTimer', 'gearUid, timer', lua_gettop(L)); |
|
1184 end |
|
1185 else |
|
1186 begin |
1623 begin |
1187 gear:= GearByUID(lua_tointeger(L, 1)); |
1624 gear:= GearByUID(lua_tointeger(L, 1)); |
1188 if gear <> nil then gear^.Timer:= lua_tointeger(L, 2) |
1625 if gear <> nil then gear^.Timer:= lua_tointeger(L, 2) |
1189 end; |
1626 end; |
1190 lc_settimer:= 0 |
1627 lc_settimer:= 0 |
|
1628 end; |
|
1629 |
|
1630 function lc_setflighttime(L : Plua_State) : LongInt; Cdecl; |
|
1631 var gear : PGear; |
|
1632 begin |
|
1633 if CheckLuaParamCount(L, 2, 'SetFlightTime', 'gearUid, flighttime') then |
|
1634 begin |
|
1635 gear:= GearByUID(lua_tointeger(L, 1)); |
|
1636 if gear <> nil then gear^.FlightTime:= lua_tointeger(L, 2) |
|
1637 end; |
|
1638 lc_setflighttime:= 0 |
1191 end; |
1639 end; |
1192 |
1640 |
1193 function lc_seteffect(L : Plua_State) : LongInt; Cdecl; |
1641 function lc_seteffect(L : Plua_State) : LongInt; Cdecl; |
1194 var gear: PGear; |
1642 var gear: PGear; |
1195 begin |
1643 t : LongInt; |
1196 if lua_gettop(L) <> 3 then |
1644 const |
1197 LuaParameterCountError('SetEffect', 'gearUid, effect, enabled', lua_gettop(L)) |
1645 call = 'SetEffect'; |
1198 else begin |
1646 params = 'gearUid, effect, effectState'; |
1199 gear := GearByUID(lua_tointeger(L, 1)); |
1647 begin |
1200 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
1648 if CheckLuaParamCount(L, 3, call, params) then |
1201 gear^.Hedgehog^.Effects[THogEffect(lua_tointeger(L, 2))]:= lua_tointeger(L, 3); |
1649 begin |
1202 end; |
1650 t:= LuaToHogEffectOrd(L, 2, call, params); |
|
1651 if t >= 0 then |
|
1652 begin |
|
1653 gear := GearByUID(lua_tointeger(L, 1)); |
|
1654 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
|
1655 gear^.Hedgehog^.Effects[THogEffect(t)]:= lua_tointeger(L, 3); |
|
1656 end; |
|
1657 end; |
1203 lc_seteffect := 0; |
1658 lc_seteffect := 0; |
1204 end; |
1659 end; |
1205 |
1660 |
1206 function lc_geteffect(L : Plua_State) : LongInt; Cdecl; |
1661 function lc_geteffect(L : Plua_State) : LongInt; Cdecl; |
1207 var gear : PGear; |
1662 var gear : PGear; |
1208 begin |
1663 t : LongInt; |
1209 if lua_gettop(L) <> 2 then |
1664 const |
1210 begin |
1665 call = 'GetEffect'; |
1211 LuaParameterCountError('GetEffect', 'gearUid, effect', lua_gettop(L)); |
1666 params = 'gearUid, effect'; |
1212 end |
1667 begin |
1213 else |
1668 if CheckLuaParamCount(L, 2, call, params) then |
1214 begin |
1669 begin |
1215 gear:= GearByUID(lua_tointeger(L, 1)); |
1670 t:= LuaToHogEffectOrd(L, 2, call, params); |
1216 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
1671 if t >= 0 then |
1217 lua_pushinteger(L, gear^.Hedgehog^.Effects[THogEffect(lua_tointeger(L, 2))]) |
1672 begin |
1218 else |
1673 gear:= GearByUID(lua_tointeger(L, 1)); |
1219 lua_pushinteger(L, 0) |
1674 if (gear <> nil) and (gear^.Hedgehog <> nil) then |
1220 end; |
1675 lua_pushinteger(L, gear^.Hedgehog^.Effects[THogEffect(t)]) |
|
1676 else |
|
1677 lua_pushinteger(L, 0) |
|
1678 end; |
|
1679 end |
|
1680 else |
|
1681 lua_pushinteger(L, 0); |
1221 lc_geteffect:= 1 |
1682 lc_geteffect:= 1 |
1222 end; |
1683 end; |
1223 |
1684 |
1224 function lc_setstate(L : Plua_State) : LongInt; Cdecl; |
1685 function lc_setstate(L : Plua_State) : LongInt; Cdecl; |
1225 var gear : PGear; |
1686 var gear : PGear; |
1226 begin |
1687 begin |
1227 if lua_gettop(L) <> 2 then |
1688 if CheckLuaParamCount(L, 2, 'SetState', 'gearUid, state') then |
1228 begin |
|
1229 LuaParameterCountError('SetState', 'gearUid, state', lua_gettop(L)); |
|
1230 end |
|
1231 else |
|
1232 begin |
1689 begin |
1233 gear:= GearByUID(lua_tointeger(L, 1)); |
1690 gear:= GearByUID(lua_tointeger(L, 1)); |
1234 if gear <> nil then |
1691 if gear <> nil then |
1235 begin |
1692 begin |
1236 gear^.State:= lua_tointeger(L, 2); |
1693 gear^.State:= lua_tointeger(L, 2); |
1363 |
1823 |
1364 function lc_findplace(L : Plua_State) : LongInt; Cdecl; |
1824 function lc_findplace(L : Plua_State) : LongInt; Cdecl; |
1365 var gear: PGear; |
1825 var gear: PGear; |
1366 fall: boolean; |
1826 fall: boolean; |
1367 tryhard: boolean; |
1827 tryhard: boolean; |
1368 left, right: LongInt; |
1828 left, right, n: LongInt; |
1369 begin |
1829 begin |
1370 tryhard:= false; |
1830 if CheckAndFetchParamCount(L, 4, 5, 'FindPlace', 'gearUid, fall, left, right [, tryHarder]', n) then |
1371 if (lua_gettop(L) <> 4) and (lua_gettop(L) <> 5) then |
|
1372 LuaParameterCountError('FindPlace', 'gearUid, fall, left, right[, tryHarder]', lua_gettop(L)) |
|
1373 else |
|
1374 begin |
1831 begin |
1375 gear:= GearByUID(lua_tointeger(L, 1)); |
1832 gear:= GearByUID(lua_tointeger(L, 1)); |
1376 fall:= lua_toboolean(L, 2); |
1833 fall:= lua_toboolean(L, 2); |
1377 left:= lua_tointeger(L, 3); |
1834 left:= lua_tointeger(L, 3); |
1378 right:= lua_tointeger(L, 4); |
1835 right:= lua_tointeger(L, 4); |
1379 if lua_gettop(L) = 5 then |
1836 if n = 5 then |
1380 tryhard:= lua_toboolean(L, 5); |
1837 tryhard:= lua_toboolean(L, 5) |
|
1838 else |
|
1839 tryhard:= false; |
1381 if gear <> nil then |
1840 if gear <> nil then |
1382 FindPlace(gear, fall, left, right, tryhard); |
1841 FindPlace(gear, fall, left, right, tryhard); |
1383 if gear <> nil then |
1842 if gear <> nil then |
1384 lua_pushinteger(L, gear^.uid) |
1843 lua_pushinteger(L, gear^.uid) |
1385 else |
1844 else |
1386 lua_pushnil(L); |
1845 lua_pushnil(L); |
1387 end; |
1846 end |
|
1847 else |
|
1848 lua_pushnil(L); // return value on stack (nil) |
1388 lc_findplace:= 1 |
1849 lc_findplace:= 1 |
1389 end; |
1850 end; |
1390 |
1851 |
1391 function lc_playsound(L : Plua_State) : LongInt; Cdecl; |
1852 function lc_playsound(L : Plua_State) : LongInt; Cdecl; |
1392 var gear: PGear; |
1853 var gear: PGear; |
1393 begin |
1854 n, s: LongInt; |
1394 if lua_gettop(L) = 1 then |
1855 const |
1395 PlaySound(TSound(lua_tointeger(L, 1))) |
1856 call = 'PlaySound'; |
1396 else if lua_gettop(L) = 2 then |
1857 params = 'soundId [, hhGearUid]'; |
1397 begin |
1858 begin |
1398 gear:= GearByUID(lua_tointeger(L, 2)); |
1859 if CheckAndFetchParamCount(L, 1, 2, call, params, n) then |
1399 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
1860 begin |
1400 AddVoice(TSound(lua_tointeger(L, 1)),gear^.Hedgehog^.Team^.Voicepack) |
1861 s:= LuaToSoundOrd(L, 1, call, params); |
1401 end |
1862 if s >= 0 then |
1402 else LuaParameterCountError('PlaySound', 'soundId', lua_gettop(L)); |
1863 begin |
|
1864 // no gear specified |
|
1865 if n = 1 then |
|
1866 PlaySound(TSound(s)) |
|
1867 else |
|
1868 begin |
|
1869 gear:= GearByUID(lua_tointeger(L, 2)); |
|
1870 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
|
1871 AddVoice(TSound(s),gear^.Hedgehog^.Team^.Voicepack) |
|
1872 end; |
|
1873 end; |
|
1874 end; |
1403 lc_playsound:= 0; |
1875 lc_playsound:= 0; |
1404 end; |
1876 end; |
1405 |
1877 |
1406 function lc_addteam(L : Plua_State) : LongInt; Cdecl; |
1878 function lc_addteam(L : Plua_State) : LongInt; Cdecl; |
1407 var np: LongInt; |
1879 var np: LongInt; |
1408 begin |
1880 begin |
1409 np:= lua_gettop(L); |
1881 if CheckAndFetchParamCount(L, 5, 6, 'AddTeam', 'teamname, color, grave, fort, voicepack [, flag]', np) then |
1410 if (np < 5) or (np > 6) then |
|
1411 begin |
|
1412 LuaParameterCountError('AddTeam', 'teamname, color, grave, fort, voicepack[, flag]', lua_gettop(L)); |
|
1413 //lua_pushnil(L) |
|
1414 end |
|
1415 else |
|
1416 begin |
1882 begin |
1417 ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true, true); |
1883 ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true, true); |
1418 ParseCommand('grave ' + lua_tostring(L, 3), true, true); |
1884 ParseCommand('grave ' + lua_tostring(L, 3), true, true); |
1419 ParseCommand('fort ' + lua_tostring(L, 4), true, true); |
1885 ParseCommand('fort ' + lua_tostring(L, 4), true, true); |
1420 ParseCommand('voicepack ' + lua_tostring(L, 5), true, true); |
1886 ParseCommand('voicepack ' + lua_tostring(L, 5), true, true); |
1421 if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true); |
1887 if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true); |
1422 CurrentTeam^.Binds:= DefaultBinds |
1888 CurrentTeam^.Binds:= DefaultBinds |
1423 // fails on x64 |
1889 // fails on x64 |
1424 //lua_pushinteger(L, LongInt(CurrentTeam)); |
1890 //lua_pushinteger(L, LongInt(CurrentTeam)); |
1425 end; |
1891 end; |
|
1892 //else |
|
1893 //lua_pushnil(L) |
1426 lc_addteam:= 0;//1; |
1894 lc_addteam:= 0;//1; |
|
1895 end; |
|
1896 |
|
1897 function lc_dismissteam(L : Plua_State) : LongInt; Cdecl; |
|
1898 var HHGear: PGear; |
|
1899 i, h : LongInt; |
|
1900 hidden: boolean; |
|
1901 begin |
|
1902 if CheckLuaParamCount(L, 1, 'DismissTeam', 'teamname') then |
|
1903 begin |
|
1904 if TeamsCount > 0 then |
|
1905 for i:= 0 to Pred(TeamsCount) do |
|
1906 begin |
|
1907 // skip teams that don't have matching name |
|
1908 if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then |
|
1909 continue; |
|
1910 |
|
1911 // destroy all hogs of matching team, including the hidden ones |
|
1912 for h:= 0 to cMaxHHIndex do |
|
1913 begin |
|
1914 hidden:= (TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil); |
|
1915 if hidden then |
|
1916 RestoreHog(@TeamsArray[i]^.Hedgehogs[h]); |
|
1917 // destroy hedgehog gear, if any |
|
1918 HHGear:= TeamsArray[i]^.Hedgehogs[h].Gear; |
|
1919 if HHGear <> nil then |
|
1920 begin |
|
1921 // smoke effect |
|
1922 if (not hidden) then |
|
1923 begin |
|
1924 AddVisualGear(hwRound(HHGear^.X), hwRound(HHGear^.Y), vgtSmokeWhite); |
|
1925 AddVisualGear(hwRound(HHGear^.X) - 16 + Random(32), hwRound(HHGear^.Y) - 16 + Random(32), vgtSmokeWhite); |
|
1926 AddVisualGear(hwRound(HHGear^.X) - 16 + Random(32), hwRound(HHGear^.Y) - 16 + Random(32), vgtSmokeWhite); |
|
1927 AddVisualGear(hwRound(HHGear^.X) - 16 + Random(32), hwRound(HHGear^.Y) - 16 + Random(32), vgtSmokeWhite); |
|
1928 AddVisualGear(hwRound(HHGear^.X) - 16 + Random(32), hwRound(HHGear^.Y) - 16 + Random(32), vgtSmokeWhite); |
|
1929 end; |
|
1930 HHGear^.Message:= HHGear^.Message or gmDestroy; |
|
1931 end; |
|
1932 end; |
|
1933 // can't dismiss more than one team |
|
1934 break; |
|
1935 end; |
|
1936 end; |
|
1937 lc_dismissteam:= 0; |
1427 end; |
1938 end; |
1428 |
1939 |
1429 function lc_addhog(L : Plua_State) : LongInt; Cdecl; |
1940 function lc_addhog(L : Plua_State) : LongInt; Cdecl; |
1430 var temp: ShortString; |
1941 var temp: ShortString; |
1431 begin |
1942 begin |
1432 if lua_gettop(L) <> 4 then |
1943 if CheckLuaParamCount(L, 4, 'AddHog', 'hogname, botlevel, health, hat') then |
1433 begin |
|
1434 LuaParameterCountError('AddHog', 'hogname, botlevel, health, hat', lua_gettop(L)); |
|
1435 lua_pushnil(L) |
|
1436 end |
|
1437 else |
|
1438 begin |
1944 begin |
1439 temp:= lua_tostring(L, 4); |
1945 temp:= lua_tostring(L, 4); |
1440 ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true); |
1946 ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true); |
1441 ParseCommand('hat ' + temp, true, true); |
1947 ParseCommand('hat ' + temp, true, true); |
1442 lua_pushinteger(L, CurrentHedgehog^.Gear^.uid); |
1948 lua_pushinteger(L, CurrentHedgehog^.Gear^.uid); |
1443 end; |
1949 end |
|
1950 else |
|
1951 lua_pushnil(L); |
1444 lc_addhog:= 1; |
1952 lc_addhog:= 1; |
1445 end; |
1953 end; |
1446 |
1954 |
1447 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl; |
1955 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl; |
1448 var gear: PGear; |
1956 var gear: PGear; |
1449 begin |
1957 begin |
1450 if lua_gettop(L) <> 2 then |
1958 if CheckLuaParamCount(L, 2, 'HogTurnLeft', 'gearUid, boolean') then |
1451 begin |
|
1452 LuaParameterCountError('HogTurnLeft', 'gearUid, boolean', lua_gettop(L)); |
|
1453 end |
|
1454 else |
|
1455 begin |
1959 begin |
1456 gear:= GearByUID(lua_tointeger(L, 1)); |
1960 gear:= GearByUID(lua_tointeger(L, 1)); |
1457 if gear <> nil then |
1961 if gear <> nil then |
1458 gear^.dX.isNegative:= lua_toboolean(L, 2); |
1962 gear^.dX.isNegative:= lua_toboolean(L, 2); |
1459 end; |
1963 end; |
1797 end |
2273 end |
1798 end; |
2274 end; |
1799 lc_sethoghat:= 0; |
2275 lc_sethoghat:= 0; |
1800 end; |
2276 end; |
1801 |
2277 |
|
2278 function lc_placesprite(L : Plua_State) : LongInt; Cdecl; |
|
2279 var spr : TSprite; |
|
2280 lf : Word; |
|
2281 tint : LongWord; |
|
2282 i, n : LongInt; |
|
2283 placed, behind, flipHoriz, flipVert : boolean; |
|
2284 const |
|
2285 call = 'PlaceSprite'; |
|
2286 params = 'x, y, sprite, frameIdx, tint, behind, flipHoriz, flipVert, [, landFlag, ... ]'; |
|
2287 begin |
|
2288 placed:= false; |
|
2289 if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then |
|
2290 begin |
|
2291 if not lua_isnoneornil(L, 5) then |
|
2292 tint := lua_tointeger(L, 5) |
|
2293 else tint := $FFFFFFFF; |
|
2294 if not lua_isnoneornil(L, 6) then |
|
2295 behind := lua_toboolean(L, 6) |
|
2296 else behind := false; |
|
2297 if not lua_isnoneornil(L, 7) then |
|
2298 flipHoriz := lua_toboolean(L, 7) |
|
2299 else flipHoriz := false; |
|
2300 if not lua_isnoneornil(L, 8) then |
|
2301 flipVert := lua_toboolean(L, 8) |
|
2302 else flipVert := false; |
|
2303 lf:= 0; |
|
2304 |
|
2305 // accept any amount of landflags, loop is never executed if n<9 |
|
2306 for i:= 9 to n do |
|
2307 lf:= lf or lua_tointeger(L, i); |
|
2308 |
|
2309 n:= LuaToSpriteOrd(L, 3, call, params); |
|
2310 if n >= 0 then |
|
2311 begin |
|
2312 spr:= TSprite(n); |
|
2313 if SpritesData[spr].Surface = nil then |
|
2314 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' ) |
|
2315 else |
|
2316 placed:= ForcePlaceOnLand( |
|
2317 lua_tointeger(L, 1) - SpritesData[spr].Width div 2, |
|
2318 lua_tointeger(L, 2) - SpritesData[spr].Height div 2, |
|
2319 spr, lua_tointeger(L, 4), lf, tint, behind, flipHoriz, flipVert); |
|
2320 end; |
|
2321 end; |
|
2322 |
|
2323 lua_pushboolean(L, placed); |
|
2324 lc_placesprite:= 1 |
|
2325 end; |
|
2326 |
|
2327 function lc_erasesprite(L : Plua_State) : LongInt; Cdecl; |
|
2328 var spr : TSprite; |
|
2329 lf : Word; |
|
2330 i, n : LongInt; |
|
2331 eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert : boolean; |
|
2332 const |
|
2333 call = 'EraseSprite'; |
|
2334 params = 'x, y, sprite, frameIdx, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert, [, landFlag, ... ]'; |
|
2335 begin |
|
2336 if CheckAndFetchLuaParamMinCount(L, 4, call, params, n) then |
|
2337 begin |
|
2338 if not lua_isnoneornil(L, 5) then |
|
2339 eraseOnLFMatch := lua_toboolean(L, 5) |
|
2340 else eraseOnLFMatch := false; |
|
2341 if not lua_isnoneornil(L, 6) then |
|
2342 onlyEraseLF := lua_toboolean(L, 6) |
|
2343 else onlyEraseLF := false; |
|
2344 if not lua_isnoneornil(L, 7) then |
|
2345 flipHoriz := lua_toboolean(L, 7) |
|
2346 else flipHoriz := false; |
|
2347 if not lua_isnoneornil(L, 8) then |
|
2348 flipVert := lua_toboolean(L, 8) |
|
2349 else flipVert := false; |
|
2350 lf:= 0; |
|
2351 |
|
2352 // accept any amount of landflags, loop is never executed if n<9 |
|
2353 for i:= 9 to n do |
|
2354 lf:= lf or lua_tointeger(L, i); |
|
2355 |
|
2356 n:= LuaToSpriteOrd(L, 3, call, params); |
|
2357 if n >= 0 then |
|
2358 begin |
|
2359 spr:= TSprite(n); |
|
2360 if SpritesData[spr].Surface = nil then |
|
2361 LuaError(call + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' ) |
|
2362 else |
|
2363 EraseLand( |
|
2364 lua_tointeger(L, 1) - SpritesData[spr].Width div 2, |
|
2365 lua_tointeger(L, 2) - SpritesData[spr].Height div 2, |
|
2366 spr, lua_tointeger(L, 4), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert); |
|
2367 end; |
|
2368 end; |
|
2369 lc_erasesprite:= 0 |
|
2370 end; |
|
2371 |
1802 function lc_placegirder(L : Plua_State) : LongInt; Cdecl; |
2372 function lc_placegirder(L : Plua_State) : LongInt; Cdecl; |
1803 begin |
2373 var placed: boolean; |
1804 if lua_gettop(L) <> 3 then |
2374 begin |
1805 LuaParameterCountError('PlaceGirder', 'x, y, state', lua_gettop(L)) |
2375 placed:= false; |
1806 else |
2376 if CheckLuaParamCount(L, 3, 'PlaceGirder', 'x, y, frameIdx') then |
1807 TryPlaceOnLand( |
2377 placed:= TryPlaceOnLandSimple( |
1808 lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2, |
2378 lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2, |
1809 lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2, |
2379 lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2, |
1810 sprAmGirder, lua_tointeger(L, 3), true, false); |
2380 sprAmGirder, lua_tointeger(L, 3), true, false); |
1811 lc_placegirder:= 0 |
2381 |
|
2382 lua_pushboolean(L, placed); |
|
2383 lc_placegirder:= 1 |
1812 end; |
2384 end; |
1813 |
2385 |
1814 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl; |
2386 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl; |
1815 begin |
2387 begin |
1816 if lua_gettop(L) <> 0 then |
2388 if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, 'GetCurAmmoType', '')) then |
1817 LuaParameterCountError('GetCurAmmoType', '', lua_gettop(L)) |
2389 lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType)) |
1818 else |
2390 else |
1819 lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType)); |
2391 lua_pushinteger(L, ord(amNothing)); |
1820 lc_getcurammotype := 1; |
2392 lc_getcurammotype := 1; |
1821 end; |
2393 end; |
1822 |
2394 |
1823 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl; |
2395 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl; |
1824 begin |
2396 begin |
1825 if lua_gettop(L) <> 2 then |
2397 if CheckLuaParamCount(L, 2, 'SaveCampaignVar', 'varname, value') then |
1826 LuaParameterCountError('SaveCampaignVar', 'varname, value', lua_gettop(L)) |
|
1827 else begin |
|
1828 SendIPC('V!' + lua_tostring(L, 1) + ' ' + lua_tostring(L, 2) + #0); |
2398 SendIPC('V!' + lua_tostring(L, 1) + ' ' + lua_tostring(L, 2) + #0); |
1829 end; |
|
1830 lc_savecampaignvar := 0; |
2399 lc_savecampaignvar := 0; |
1831 end; |
2400 end; |
1832 |
2401 |
1833 function lc_getcampaignvar(L : Plua_State): LongInt; Cdecl; |
2402 function lc_getcampaignvar(L : Plua_State): LongInt; Cdecl; |
1834 begin |
2403 begin |
1835 if (lua_gettop(L) <> 1) then |
2404 if CheckLuaParamCount(L, 1, 'GetCampaignVar', 'varname') then |
1836 LuaParameterCountError('GetCampaignVar', 'varname', lua_gettop(L)) |
|
1837 else |
|
1838 SendIPCAndWaitReply('V?' + lua_tostring(L, 1) + #0); |
2405 SendIPCAndWaitReply('V?' + lua_tostring(L, 1) + #0); |
1839 lua_pushstring(L, str2pchar(CampaignVariable)); |
2406 lua_pushstring(L, str2pchar(CampaignVariable)); |
1840 lc_getcampaignvar := 1; |
2407 lc_getcampaignvar := 1; |
1841 end; |
2408 end; |
1842 |
2409 |
1843 function lc_hidehog(L: Plua_State): LongInt; Cdecl; |
2410 function lc_hidehog(L: Plua_State): LongInt; Cdecl; |
1844 var gear: PGear; |
2411 var gear: PGear; |
1845 begin |
2412 begin |
1846 if lua_gettop(L) <> 1 then |
2413 if CheckLuaParamCount(L, 1, 'HideHog', 'gearUid') then |
1847 LuaParameterCountError('HideHog', 'gearUid', lua_gettop(L)) |
|
1848 else |
|
1849 begin |
2414 begin |
1850 gear:= GearByUID(lua_tointeger(L, 1)); |
2415 gear:= GearByUID(lua_tointeger(L, 1)); |
1851 HideHog(gear^.hedgehog) |
2416 HideHog(gear^.hedgehog) |
1852 end; |
2417 end; |
1853 lc_hidehog := 0; |
2418 lc_hidehog := 0; |
1876 |
2439 |
1877 // boolean TestRectForObstacle(x1, y1, x2, y2, landOnly) |
2440 // boolean TestRectForObstacle(x1, y1, x2, y2, landOnly) |
1878 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl; |
2441 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl; |
1879 var rtn: Boolean; |
2442 var rtn: Boolean; |
1880 begin |
2443 begin |
1881 if lua_gettop(L) <> 5 then |
2444 if CheckLuaParamCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then |
1882 begin |
2445 begin |
1883 LuaParameterCountError('TestRectForObstacle', 'x1, y1, x2, y2, landOnly', lua_gettop(L)); |
2446 rtn:= TestRectangleForObstacle( |
1884 lua_pushnil(L); // return value on stack (nil) |
|
1885 end |
|
1886 else |
|
1887 begin |
|
1888 rtn:= TestRectancleForObstacle( |
|
1889 lua_tointeger(L, 1), |
2447 lua_tointeger(L, 1), |
1890 lua_tointeger(L, 2), |
2448 lua_tointeger(L, 2), |
1891 lua_tointeger(L, 3), |
2449 lua_tointeger(L, 3), |
1892 lua_tointeger(L, 4), |
2450 lua_tointeger(L, 4), |
1893 lua_toboolean(L, 5) |
2451 lua_toboolean(L, 5) |
1894 ); |
2452 ); |
1895 lua_pushboolean(L, rtn); |
2453 lua_pushboolean(L, rtn); |
1896 end; |
2454 end |
|
2455 else |
|
2456 lua_pushnil(L); // return value on stack (nil) |
1897 lc_testrectforobstacle:= 1 |
2457 lc_testrectforobstacle:= 1 |
1898 end; |
2458 end; |
1899 |
2459 |
1900 |
2460 |
1901 function lc_setaihintsongear(L : Plua_State) : LongInt; Cdecl; |
2461 function lc_getgravity(L : Plua_State) : LongInt; Cdecl; |
|
2462 begin |
|
2463 if CheckLuaParamCount(L, 0, 'GetGravity', '') then |
|
2464 lua_pushinteger(L, hwRound(SignAs(_0_5, cGravity) + (cGravity * 50 / cMaxWindSpeed))); |
|
2465 lc_getgravity:= 1 |
|
2466 end; |
|
2467 |
|
2468 function lc_setgravity(L : Plua_State) : LongInt; Cdecl; |
|
2469 begin |
|
2470 if CheckLuaParamCount(L, 1, 'SetGravity', 'percent') then |
|
2471 begin |
|
2472 cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed; |
|
2473 cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02 |
|
2474 end; |
|
2475 lc_setgravity:= 0 |
|
2476 end; |
|
2477 |
|
2478 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl; |
|
2479 var iterator: PGear; |
|
2480 begin |
|
2481 if CheckLuaParamCount(L, 1, 'SetWaterLine', 'waterline') then |
|
2482 begin |
|
2483 cWaterLine:= lua_tointeger(L,1); |
|
2484 AllInactive:= false; |
|
2485 iterator:= GearsList; |
|
2486 while iterator <> nil do |
|
2487 begin |
|
2488 if not (iterator^.Kind in [gtPortal, gtAirAttack]) and (iterator^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) then |
|
2489 begin |
|
2490 iterator^.Active:= true; |
|
2491 if iterator^.dY.QWordValue = 0 then iterator^.dY.isNegative:= false; |
|
2492 iterator^.State:= iterator^.State or gstMoving; |
|
2493 DeleteCI(iterator) |
|
2494 end; |
|
2495 iterator:= iterator^.NextGear |
|
2496 end |
|
2497 end; |
|
2498 lc_setwaterline:= 0 |
|
2499 end; |
|
2500 |
|
2501 function lc_setgearaihints(L : Plua_State) : LongInt; Cdecl; |
1902 var gear: PGear; |
2502 var gear: PGear; |
1903 begin |
2503 begin |
1904 if lua_gettop(L) <> 2 then |
2504 if CheckLuaParamCount(L, 2, 'SetAIHintOnGear', 'gearUid, aiHints') then |
1905 LuaParameterCountError('SetAIHintOnGear', 'gearUid, aiHints', lua_gettop(L)) |
|
1906 else |
|
1907 begin |
2505 begin |
1908 gear:= GearByUID(lua_tointeger(L, 1)); |
2506 gear:= GearByUID(lua_tointeger(L, 1)); |
1909 if gear <> nil then |
2507 if gear <> nil then |
1910 gear^.aihints:= lua_tointeger(L, 2); |
2508 gear^.aihints:= lua_tointeger(L, 2); |
1911 end; |
2509 end; |
1912 lc_setaihintsongear:= 0 |
2510 lc_setgearaihints:= 0 |
1913 end; |
2511 end; |
1914 |
2512 |
1915 |
2513 |
1916 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl; |
2514 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl; |
1917 begin |
2515 begin |
1918 if lua_gettop(L) <> 1 then |
2516 if CheckLuaParamCount(L, 1, 'HedgewarsScriptLoad', 'scriptPath') then |
1919 begin |
2517 ScriptLoad(lua_tostring(L, 1)) |
1920 LuaParameterCountError('HedgewarsScriptLoad', 'scriptPath', lua_gettop(L)); |
2518 else |
1921 lua_pushnil(L) |
2519 lua_pushnil(L); |
1922 end |
|
1923 else |
|
1924 ScriptLoad(lua_tostring(L, 1)); |
|
1925 lc_hedgewarsscriptload:= 0; |
2520 lc_hedgewarsscriptload:= 0; |
1926 end; |
2521 end; |
1927 |
2522 |
1928 |
2523 |
1929 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl; |
2524 function lc_declareachievement(L : Plua_State) : LongInt; Cdecl; |
1930 begin |
2525 begin |
1931 if lua_gettop(L) <> 4 then |
2526 if CheckLuaParamCount(L, 4, 'DeclareAchievement', 'achievementId, teamname, location, value') then |
1932 LuaParameterCountError('DeclareAchievement', 'achievementId, teamname, location, value', lua_gettop(L)) |
|
1933 else |
|
1934 declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4)); |
2527 declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4)); |
1935 lc_declareachievement:= 0 |
2528 lc_declareachievement:= 0 |
|
2529 end; |
|
2530 |
|
2531 |
|
2532 procedure ScriptFlushPoints(); |
|
2533 begin |
|
2534 ParseCommand('draw ' + PointsBuffer, true, true); |
|
2535 PointsBuffer:= ''; |
|
2536 end; |
|
2537 |
|
2538 |
|
2539 function lc_addPoint(L : Plua_State) : LongInt; Cdecl; |
|
2540 var np, param: LongInt; |
|
2541 begin |
|
2542 if CheckAndFetchParamCountRange(L, 2, 4, 'AddPoint', 'x, y [, width [, erase] ]', np) then |
|
2543 begin |
|
2544 // x |
|
2545 param:= LongInt(lua_tointeger(L,1)); |
|
2546 PointsBuffer:= PointsBuffer + char((param shr 8) and $FF); |
|
2547 PointsBuffer:= PointsBuffer + char((param and $FF)); |
|
2548 // y |
|
2549 param:= LongInt(lua_tointeger(L,2)); |
|
2550 PointsBuffer:= PointsBuffer + char((param shr 8) and $FF); |
|
2551 PointsBuffer:= PointsBuffer + char((param and $FF)); |
|
2552 // width |
|
2553 if np > 2 then |
|
2554 begin |
|
2555 param:= lua_tointeger(L,3); |
|
2556 param:= (param or $80); |
|
2557 // erase |
|
2558 if (np > 3) and lua_toboolean(L, 4) then |
|
2559 param:= (param or $40); |
|
2560 PointsBuffer:= PointsBuffer + char(param); |
|
2561 end |
|
2562 // no width defined |
|
2563 else |
|
2564 PointsBuffer:= PointsBuffer + char(0); |
|
2565 |
|
2566 // flush before shortstring limit length is reached |
|
2567 if length(PointsBuffer) > 245 then |
|
2568 ScriptFlushPoints(); |
|
2569 end; |
|
2570 lc_addPoint:= 0 |
|
2571 end; |
|
2572 |
|
2573 |
|
2574 function lc_flushPoints(L : Plua_State) : LongInt; Cdecl; |
|
2575 begin |
|
2576 if CheckLuaParamCount(L, 0, 'FlushPoints', '') then |
|
2577 if length(PointsBuffer) > 0 then |
|
2578 ScriptFlushPoints(); |
|
2579 lc_flushPoints:= 0 |
|
2580 end; |
|
2581 |
|
2582 // stuff for lua tests |
|
2583 function lc_endluatest(L : Plua_State) : LongInt; Cdecl; |
|
2584 var rstring: shortstring; |
|
2585 const |
|
2586 call = 'EndLuaTest'; |
|
2587 params = 'TEST_SUCCESSFUL or TEST_FAILED'; |
|
2588 begin |
|
2589 if CheckLuaParamCount(L, 1, call, params) then |
|
2590 begin |
|
2591 |
|
2592 case lua_tointeger(L, 1) of |
|
2593 HaltTestSuccess : rstring:= 'Success'; |
|
2594 HaltTestLuaError: rstring:= 'FAILED'; |
|
2595 else |
|
2596 begin |
|
2597 LuaCallError('Parameter must be either ' + params, call, params); |
|
2598 exit(0); |
|
2599 end; |
|
2600 end; |
|
2601 |
|
2602 if cTestLua then |
|
2603 begin |
|
2604 WriteLnToConsole('Lua test finished, result: ' + rstring); |
|
2605 halt(lua_tointeger(L, 1)); |
|
2606 end |
|
2607 else LuaError('Not in lua test mode, engine will keep running. Reported test result: ' + rstring); |
|
2608 |
|
2609 end; |
|
2610 |
|
2611 lc_endluatest:= 0; |
1936 end; |
2612 end; |
1937 /////////////////// |
2613 /////////////////// |
1938 |
2614 |
1939 procedure ScriptPrintStack; |
2615 procedure ScriptPrintStack; |
1940 var n, i : LongInt; |
2616 var n, i : LongInt; |
2448 ScriptSetInteger(EnumToStr(he), ord(he)); |
3178 ScriptSetInteger(EnumToStr(he), ord(he)); |
2449 |
3179 |
2450 for cg:= Low(TCapGroup) to High(TCapGroup) do |
3180 for cg:= Low(TCapGroup) to High(TCapGroup) do |
2451 ScriptSetInteger(EnumToStr(cg), ord(cg)); |
3181 ScriptSetInteger(EnumToStr(cg), ord(cg)); |
2452 |
3182 |
2453 ScriptSetInteger('gstDrowning' ,$00000001); |
3183 for spr:= Low(TSprite) to High(TSprite) do |
2454 ScriptSetInteger('gstHHDriven' ,$00000002); |
3184 ScriptSetInteger(EnumToStr(spr), ord(spr)); |
2455 ScriptSetInteger('gstMoving' ,$00000004); |
3185 |
2456 ScriptSetInteger('gstAttacked' ,$00000008); |
3186 for mg:= Low(TMapGen) to High(TMapGen) do |
2457 ScriptSetInteger('gstAttacking' ,$00000010); |
3187 ScriptSetInteger(EnumToStr(mg), ord(mg)); |
2458 ScriptSetInteger('gstCollision' ,$00000020); |
3188 |
2459 ScriptSetInteger('gstHHChooseTarget' ,$00000040); |
3189 ScriptSetInteger('gstDrowning' , gstDrowning); |
2460 ScriptSetInteger('gstHHJumping' ,$00000100); |
3190 ScriptSetInteger('gstHHDriven' , gstHHDriven); |
2461 ScriptSetInteger('gsttmpFlag' ,$00000200); |
3191 ScriptSetInteger('gstMoving' , gstMoving); |
2462 ScriptSetInteger('gstHHThinking' ,$00000800); |
3192 ScriptSetInteger('gstAttacked' , gstAttacked); |
2463 ScriptSetInteger('gstNoDamage' ,$00001000); |
3193 ScriptSetInteger('gstAttacking' , gstAttacking); |
2464 ScriptSetInteger('gstHHHJump' ,$00002000); |
3194 ScriptSetInteger('gstCollision' , gstCollision); |
2465 ScriptSetInteger('gstAnimation' ,$00004000); |
3195 ScriptSetInteger('gstChooseTarget' , gstChooseTarget); |
2466 ScriptSetInteger('gstHHDeath' ,$00008000); |
3196 ScriptSetInteger('gstHHJumping' , gstHHJumping); |
2467 ScriptSetInteger('gstWinner' ,$00010000); |
3197 ScriptSetInteger('gsttmpFlag' , gsttmpFlag); |
2468 ScriptSetInteger('gstWait' ,$00020000); |
3198 ScriptSetInteger('gstHHThinking' , gstHHThinking); |
2469 ScriptSetInteger('gstNotKickable' ,$00040000); |
3199 ScriptSetInteger('gstNoDamage' , gstNoDamage); |
2470 ScriptSetInteger('gstLoser' ,$00080000); |
3200 ScriptSetInteger('gstHHHJump' , gstHHHJump); |
2471 ScriptSetInteger('gstHHGone' ,$00100000); |
3201 ScriptSetInteger('gstAnimation' , gstAnimation); |
2472 ScriptSetInteger('gstInvisible' ,$00200000); |
3202 ScriptSetInteger('gstHHDeath' , gstHHDeath); |
|
3203 ScriptSetInteger('gstWinner' , gstWinner); |
|
3204 ScriptSetInteger('gstWait' , gstWait); |
|
3205 ScriptSetInteger('gstNotKickable' , gstNotKickable); |
|
3206 ScriptSetInteger('gstLoser' , gstLoser); |
|
3207 ScriptSetInteger('gstHHGone' , gstHHGone); |
|
3208 ScriptSetInteger('gstInvisible' , gstInvisible); |
|
3209 ScriptSetInteger('gstSubmersible' , gstSubmersible); |
|
3210 ScriptSetInteger('gstFrozen' , gstFrozen); |
|
3211 ScriptSetInteger('gstNoGravity' , gstNoGravity); |
2473 |
3212 |
2474 // ai hints |
3213 // ai hints |
2475 ScriptSetInteger('aihUsualProcessing' ,$00000000); |
3214 ScriptSetInteger('aihUsualProcessing', aihUsualProcessing); |
2476 ScriptSetInteger('aihDoesntMatter' ,$00000001); |
3215 ScriptSetInteger('aihDoesntMatter' , aihDoesntMatter); |
|
3216 |
|
3217 // land flags |
|
3218 ScriptSetInteger('lfIndestructible', lfIndestructible); |
|
3219 ScriptSetInteger('lfIce' , lfIce); |
|
3220 ScriptSetInteger('lfBouncy' , lfBouncy); |
2477 |
3221 |
2478 // register functions |
3222 // register functions |
2479 lua_register(luaState, _P'HideHog', @lc_hidehog); |
3223 lua_register(luaState, _P'HideHog', @lc_hidehog); |
2480 lua_register(luaState, _P'RestoreHog', @lc_restorehog); |
3224 lua_register(luaState, _P'RestoreHog', @lc_restorehog); |
2481 lua_register(luaState, _P'SaveCampaignVar', @lc_savecampaignvar); |
3225 lua_register(luaState, _P'SaveCampaignVar', @lc_savecampaignvar); |