author | unc0rr |
Sun, 21 Mar 2010 19:02:03 +0000 | |
changeset 3038 | 4e48c276a468 |
parent 3034 | b576460ba8ad |
child 3043 | 3acdb4dac6eb |
permissions | -rw-r--r-- |
2786 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
19 |
{$INCLUDE "options.inc"} |
|
20 |
||
21 |
unit uScript; |
|
22 |
interface |
|
23 |
||
24 |
procedure ScriptPrintStack; |
|
25 |
procedure ScriptClearStack; |
|
26 |
||
2905 | 27 |
procedure ScriptLoad(name : shortstring); |
2786 | 28 |
procedure ScriptOnGameInit; |
29 |
||
2905 | 30 |
procedure ScriptCall(fname : shortstring); |
31 |
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
|
32 |
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt; |
|
33 |
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; |
|
34 |
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; |
|
2999 | 35 |
function ScriptExists(fname : shortstring) : boolean; |
2786 | 36 |
|
3038 | 37 |
procedure initModule; |
38 |
procedure freeModule; |
|
2786 | 39 |
|
40 |
implementation |
|
2798 | 41 |
{$IFNDEF IPHONEOS} |
2786 | 42 |
uses LuaPas in 'LuaPas.pas', |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
43 |
uConsole, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
44 |
uMisc, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
45 |
uConsts, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
46 |
uGears, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
47 |
uFloat, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
48 |
uWorld, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
49 |
uAmmos, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
50 |
uSound, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
51 |
uTeams, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
52 |
uKeys, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
53 |
typinfo; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
54 |
|
2786 | 55 |
var luaState : Plua_State; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
56 |
ScriptAmmoStore : shortstring; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
57 |
ScriptLoaded : boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
58 |
|
2786 | 59 |
procedure ScriptPrepareAmmoStore; forward; |
60 |
procedure ScriptApplyAmmoStore; forward; |
|
2996 | 61 |
procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay: Byte); forward; |
2786 | 62 |
|
63 |
// wrapped calls // |
|
64 |
||
65 |
// functions called from lua: |
|
66 |
// function(L : Plua_State) : LongInt; Cdecl; |
|
67 |
// where L contains the state, returns the number of return values on the stack |
|
68 |
// call lua_gettop(L) to receive number of parameters passed |
|
69 |
||
70 |
function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; |
|
71 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
72 |
if lua_gettop(L) = 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
73 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
74 |
WriteLnToConsole('LUA: ' + lua_tostring(L ,1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
75 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
76 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
77 |
WriteLnToConsole('LUA: Wrong number of parameters passed to WriteLnToConsole!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
78 |
lc_writelntoconsole:= 0; |
2786 | 79 |
end; |
80 |
||
81 |
function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; |
|
82 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
83 |
if lua_gettop(L) = 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
84 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
85 |
ParseCommand(lua_tostring(L ,1), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
86 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
87 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
88 |
WriteLnToConsole('LUA: Wrong number of parameters passed to ParseCommand!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
89 |
lc_parsecommand:= 0; |
2786 | 90 |
end; |
91 |
||
92 |
function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
|
93 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
94 |
if lua_gettop(L) = 5 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
95 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
96 |
ShowMission(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
97 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
98 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
99 |
WriteLnToConsole('LUA: Wrong number of parameters passed to ShowMission!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
100 |
lc_showmission:= 0; |
2786 | 101 |
end; |
102 |
||
103 |
function lc_hidemission(L : Plua_State) : LongInt; Cdecl; |
|
104 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
105 |
HideMission; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
106 |
lc_hidemission:= 0; |
2786 | 107 |
end; |
108 |
||
109 |
function lc_addgear(L : Plua_State) : LongInt; Cdecl; |
|
110 |
var gear : PGear; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
111 |
x, y, s, t: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
112 |
dx, dy: hwFloat; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
113 |
gt: TGearType; |
2786 | 114 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
115 |
if lua_gettop(L) <> 7 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
116 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
117 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddGear!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
118 |
lua_pushnil(L); // return value on stack (nil) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
119 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
120 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
121 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
122 |
x:= lua_tointeger(L, 1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
123 |
y:= lua_tointeger(L, 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
124 |
gt:= TGearType(lua_tointeger(L, 3)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
125 |
s:= lua_tointeger(L, 4); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
126 |
dx:= int2hwFloat(round(lua_tonumber(L, 5) * 1000)) / 1000; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
127 |
dy:= int2hwFloat(round(lua_tonumber(L, 6) * 1000)) / 1000; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
128 |
t:= lua_tointeger(L, 7); |
2786 | 129 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
130 |
gear:= AddGear(x, y, gt, s, dx, dy, t); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
131 |
lua_pushnumber(L, gear^.uid) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
132 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
133 |
lc_addgear:= 1; // 1 return value |
2786 | 134 |
end; |
135 |
||
136 |
function lc_getgeartype(L : Plua_State) : LongInt; Cdecl; |
|
2790 | 137 |
var gear : PGear; |
2786 | 138 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
139 |
if lua_gettop(L) <> 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
140 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
141 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetGearType!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
142 |
lua_pushnil(L); // return value on stack (nil) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
143 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
144 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
145 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
146 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
147 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
148 |
lua_pushinteger(L, ord(gear^.Kind)) |
2999 | 149 |
else |
150 |
lua_pushnil(L); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
151 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
152 |
lc_getgeartype:= 1 |
2786 | 153 |
end; |
154 |
||
2999 | 155 |
function lc_gethogclan(L : Plua_State) : LongInt; Cdecl; |
156 |
var gear : PGear; |
|
157 |
begin |
|
158 |
if lua_gettop(L) <> 1 then |
|
159 |
begin |
|
160 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetHogClan!'); |
|
161 |
lua_pushnil(L); // return value on stack (nil) |
|
162 |
end |
|
163 |
else |
|
164 |
begin |
|
165 |
gear:= GearByUID(lua_tointeger(L, 1)); |
|
166 |
if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
|
167 |
begin |
|
168 |
lua_pushinteger(L, PHedgehog(gear^.Hedgehog)^.Team^.Clan^.ClanIndex) |
|
169 |
end |
|
170 |
else |
|
171 |
lua_pushnil(L); |
|
172 |
end; |
|
173 |
lc_gethogclan:= 1 |
|
174 |
end; |
|
175 |
||
176 |
function lc_gethogname(L : Plua_State) : LongInt; Cdecl; |
|
177 |
var gear : PGear; |
|
178 |
begin |
|
179 |
if lua_gettop(L) <> 1 then |
|
180 |
begin |
|
181 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetHogName!'); |
|
182 |
lua_pushnil(L); // return value on stack (nil) |
|
183 |
end |
|
184 |
else |
|
185 |
begin |
|
186 |
gear:= GearByUID(lua_tointeger(L, 1)); |
|
187 |
if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
|
188 |
begin |
|
189 |
lua_pushstring(L, str2pchar(PHedgehog(gear^.Hedgehog)^.Name)) |
|
190 |
end |
|
191 |
else |
|
192 |
lua_pushnil(L); |
|
193 |
end; |
|
194 |
lc_gethogname:= 1 |
|
195 |
end; |
|
196 |
||
3004 | 197 |
function lc_getx(L : Plua_State) : LongInt; Cdecl; |
198 |
var gear : PGear; |
|
199 |
begin |
|
200 |
if lua_gettop(L) <> 1 then |
|
201 |
begin |
|
202 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetX!'); |
|
203 |
lua_pushnil(L); // return value on stack (nil) |
|
204 |
end |
|
205 |
else |
|
206 |
begin |
|
207 |
gear:= GearByUID(lua_tointeger(L, 1)); |
|
208 |
if gear <> nil then |
|
209 |
lua_pushnumber(L, hwRound(gear^.X)) |
|
210 |
else |
|
211 |
lua_pushnil(L); |
|
212 |
end; |
|
213 |
lc_getx:= 1 |
|
214 |
end; |
|
215 |
||
216 |
function lc_gety(L : Plua_State) : LongInt; Cdecl; |
|
217 |
var gear : PGear; |
|
218 |
begin |
|
219 |
if lua_gettop(L) <> 1 then |
|
220 |
begin |
|
221 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetY!'); |
|
222 |
lua_pushnil(L); // return value on stack (nil) |
|
223 |
end |
|
224 |
else |
|
225 |
begin |
|
226 |
gear:= GearByUID(lua_tointeger(L, 1)); |
|
227 |
if gear <> nil then |
|
228 |
lua_pushnumber(L, hwRound(gear^.Y)) |
|
229 |
else |
|
230 |
lua_pushnil(L); |
|
231 |
end; |
|
232 |
lc_gety:= 1 |
|
233 |
end; |
|
234 |
||
235 |
function lc_copypv(L : Plua_State) : LongInt; Cdecl; |
|
236 |
var gears, geard : PGear; |
|
237 |
begin |
|
238 |
if lua_gettop(L) <> 2 then |
|
239 |
begin |
|
240 |
WriteLnToConsole('LUA: Wrong number of parameters passed to CopyPV!'); |
|
241 |
end |
|
242 |
else |
|
243 |
begin |
|
244 |
gears:= GearByUID(lua_tointeger(L, 1)); |
|
245 |
geard:= GearByUID(lua_tointeger(L, 2)); |
|
246 |
if (gears <> nil) and (geard <> nil) then |
|
247 |
begin |
|
248 |
geard^.X:= gears^.X; |
|
249 |
geard^.Y:= gears^.Y; |
|
250 |
geard^.dX:= gears^.dX; |
|
251 |
geard^.dY:= gears^.dY; |
|
252 |
end |
|
253 |
end; |
|
254 |
lc_copypv:= 1 |
|
255 |
end; |
|
256 |
||
257 |
function lc_copypv2(L : Plua_State) : LongInt; Cdecl; |
|
258 |
var gears, geard : PGear; |
|
259 |
begin |
|
260 |
if lua_gettop(L) <> 2 then |
|
261 |
begin |
|
262 |
WriteLnToConsole('LUA: Wrong number of parameters passed to CopyPV2!'); |
|
263 |
end |
|
264 |
else |
|
265 |
begin |
|
266 |
gears:= GearByUID(lua_tointeger(L, 1)); |
|
267 |
geard:= GearByUID(lua_tointeger(L, 2)); |
|
268 |
if (gears <> nil) and (geard <> nil) then |
|
269 |
begin |
|
270 |
geard^.X:= gears^.X; |
|
271 |
geard^.Y:= gears^.Y; |
|
272 |
geard^.dX:= gears^.dX * 2; |
|
273 |
geard^.dY:= gears^.dY * 2; |
|
274 |
end |
|
275 |
end; |
|
276 |
lc_copypv2:= 1 |
|
277 |
end; |
|
278 |
||
279 |
function lc_followgear(L : Plua_State) : LongInt; Cdecl; |
|
280 |
var gear : PGear; |
|
281 |
begin |
|
282 |
if lua_gettop(L) <> 1 then |
|
283 |
WriteLnToConsole('LUA: Wrong number of parameters passed to FollowGear!') |
|
284 |
else |
|
285 |
begin |
|
286 |
gear:= GearByUID(lua_tointeger(L, 1)); |
|
287 |
if gear <> nil then FollowGear:= gear |
|
288 |
end; |
|
289 |
lc_followgear:= 0 |
|
290 |
end; |
|
291 |
||
2814 | 292 |
function lc_sethealth(L : Plua_State) : LongInt; Cdecl; |
293 |
var gear : PGear; |
|
294 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
295 |
if lua_gettop(L) <> 2 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
296 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
297 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetHealth!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
298 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
299 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
300 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
301 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3004 | 302 |
if gear <> nil then gear^.Health:= lua_tointeger(L, 2) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
303 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
304 |
lc_sethealth:= 0 |
2814 | 305 |
end; |
306 |
||
3004 | 307 |
function lc_setstate(L : Plua_State) : LongInt; Cdecl; |
308 |
var gear : PGear; |
|
309 |
begin |
|
310 |
if lua_gettop(L) <> 2 then |
|
311 |
begin |
|
312 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetState!'); |
|
313 |
end |
|
314 |
else |
|
315 |
begin |
|
316 |
gear:= GearByUID(lua_tointeger(L, 1)); |
|
317 |
if gear <> nil then gear^.State:= lua_tointeger(L, 2) |
|
318 |
end; |
|
319 |
lc_setstate:= 0 |
|
320 |
end; |
|
321 |
||
322 |
function lc_getstate(L : Plua_State) : LongInt; Cdecl; |
|
323 |
var gear : PGear; |
|
324 |
begin |
|
325 |
if lua_gettop(L) <> 1 then |
|
326 |
begin |
|
327 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetState!'); |
|
328 |
end |
|
329 |
else |
|
330 |
begin |
|
331 |
gear:= GearByUID(lua_tointeger(L, 1)); |
|
332 |
if gear <> nil then |
|
333 |
lua_pushinteger(L, gear^.State) |
|
334 |
else |
|
335 |
lua_pushnil(L) |
|
336 |
end; |
|
337 |
lc_getstate:= 1 |
|
338 |
end; |
|
339 |
||
340 |
function lc_settag(L : Plua_State) : LongInt; Cdecl; |
|
341 |
var gear : PGear; |
|
342 |
begin |
|
343 |
if lua_gettop(L) <> 2 then |
|
344 |
begin |
|
345 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetTag!'); |
|
346 |
end |
|
347 |
else |
|
348 |
begin |
|
349 |
gear:= GearByUID(lua_tointeger(L, 1)); |
|
350 |
if gear <> nil then gear^.Tag:= lua_tointeger(L, 2) |
|
351 |
end; |
|
352 |
lc_settag:= 0 |
|
353 |
end; |
|
354 |
||
2786 | 355 |
function lc_endgame(L : Plua_State) : LongInt; Cdecl; |
356 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
357 |
GameState:= gsExit; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
358 |
lc_endgame:= 0 |
2786 | 359 |
end; |
360 |
||
361 |
function lc_findplace(L : Plua_State) : LongInt; Cdecl; |
|
362 |
var gear: PGear; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
363 |
fall: boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
364 |
left, right: LongInt; |
2786 | 365 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
366 |
if lua_gettop(L) <> 4 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
367 |
WriteLnToConsole('LUA: Wrong number of parameters passed to FindPlace!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
368 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
369 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
370 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
371 |
fall:= lua_toboolean(L, 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
372 |
left:= lua_tointeger(L, 3); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
373 |
right:= lua_tointeger(L, 4); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
374 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
375 |
FindPlace(gear, fall, left, right) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
376 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
377 |
lc_findplace:= 0 |
2786 | 378 |
end; |
379 |
||
380 |
function lc_playsound(L : Plua_State) : LongInt; Cdecl; |
|
381 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
382 |
if lua_gettop(L) <> 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
383 |
WriteLnToConsole('LUA: Wrong number of parameters passed to PlaySound!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
384 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
385 |
PlaySound(TSound(lua_tointeger(L, 1))); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
386 |
lc_playsound:= 0; |
2786 | 387 |
end; |
388 |
||
389 |
function lc_addteam(L : Plua_State) : LongInt; Cdecl; |
|
390 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
391 |
if lua_gettop(L) <> 5 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
392 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
393 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddTeam!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
394 |
//lua_pushnil(L) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
395 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
396 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
397 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
398 |
ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
399 |
ParseCommand('grave ' + lua_tostring(L, 3), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
400 |
ParseCommand('fort ' + lua_tostring(L, 4), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
401 |
ParseCommand('voicepack ' + lua_tostring(L, 5), true); |
2996 | 402 |
CurrentTeam^.Binds:= DefaultBinds |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
403 |
// fails on x64 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
404 |
//lua_pushinteger(L, LongInt(CurrentTeam)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
405 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
406 |
lc_addteam:= 0;//1; |
2786 | 407 |
end; |
408 |
||
409 |
function lc_addhog(L : Plua_State) : LongInt; Cdecl; |
|
410 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
411 |
if lua_gettop(L) <> 4 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
412 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
413 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddHog!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
414 |
lua_pushnil(L) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
415 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
416 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
417 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
418 |
ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
419 |
ParseCommand('hat ' + lua_tostring(L, 4), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
420 |
lua_pushinteger(L, CurrentHedgehog^.Gear^.uid); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
421 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
422 |
lc_addhog:= 1; |
2786 | 423 |
end; |
424 |
||
425 |
function lc_getgearposition(L : Plua_State) : LongInt; Cdecl; |
|
426 |
var gear: PGear; |
|
427 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
428 |
if lua_gettop(L) <> 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
429 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
430 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetGearPosition!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
431 |
lua_pushnil(L); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
432 |
lua_pushnil(L) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
433 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
434 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
435 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
436 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
437 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
438 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
439 |
lua_pushinteger(L, hwRound(gear^.X)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
440 |
lua_pushinteger(L, hwRound(gear^.Y)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
441 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
442 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
443 |
lc_getgearposition:= 2; |
2786 | 444 |
end; |
445 |
||
446 |
function lc_setgearposition(L : Plua_State) : LongInt; Cdecl; |
|
447 |
var gear: PGear; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
448 |
x, y: LongInt; |
2786 | 449 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
450 |
if lua_gettop(L) <> 3 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
451 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetGearPosition!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
452 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
453 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
454 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
455 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
456 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
457 |
x:= lua_tointeger(L, 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
458 |
y:= lua_tointeger(L, 3); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
459 |
gear^.X:= int2hwfloat(x); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
460 |
gear^.Y:= int2hwfloat(y); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
461 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
462 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
463 |
lc_setgearposition:= 0 |
2786 | 464 |
end; |
465 |
||
466 |
function lc_setammo(L : Plua_State) : LongInt; Cdecl; |
|
467 |
begin |
|
2996 | 468 |
if lua_gettop(L) <> 4 then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
469 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetAmmo!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
470 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
471 |
begin |
2996 | 472 |
ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
473 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
474 |
lc_setammo:= 0 |
2786 | 475 |
end; |
476 |
/////////////////// |
|
477 |
||
478 |
procedure ScriptPrintStack; |
|
479 |
var n, i : LongInt; |
|
480 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
481 |
n:= lua_gettop(luaState); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
482 |
WriteLnToConsole('LUA: Stack (' + inttostr(n) + ' elements):'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
483 |
for i:= 1 to n do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
484 |
if not lua_isboolean(luaState, i) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
485 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': ' + lua_tostring(luaState, i)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
486 |
else if lua_toboolean(luaState, i) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
487 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': true') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
488 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
489 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': false'); |
2786 | 490 |
end; |
491 |
||
492 |
procedure ScriptClearStack; |
|
493 |
begin |
|
494 |
lua_settop(luaState, 0) |
|
495 |
end; |
|
496 |
||
3003 | 497 |
procedure ScriptSetNil(name : shortstring); |
498 |
begin |
|
499 |
lua_pushnil(luaState); |
|
500 |
lua_setglobal(luaState, Str2PChar(name)); |
|
501 |
end; |
|
502 |
||
2905 | 503 |
procedure ScriptSetInteger(name : shortstring; value : LongInt); |
2786 | 504 |
begin |
505 |
lua_pushinteger(luaState, value); |
|
506 |
lua_setglobal(luaState, Str2PChar(name)); |
|
507 |
end; |
|
508 |
||
2905 | 509 |
procedure ScriptSetString(name : shortstring; value : shortstring); |
2786 | 510 |
begin |
511 |
lua_pushstring(luaState, Str2PChar(value)); |
|
512 |
lua_setglobal(luaState, Str2PChar(name)); |
|
513 |
end; |
|
514 |
||
2905 | 515 |
function ScriptGetInteger(name : shortstring) : LongInt; |
2786 | 516 |
begin |
517 |
lua_getglobal(luaState, Str2PChar(name)); |
|
518 |
ScriptGetInteger:= lua_tointeger(luaState, -1); |
|
519 |
lua_pop(luaState, 1); |
|
520 |
end; |
|
521 |
||
2905 | 522 |
function ScriptGetString(name : shortstring) : shortstring; |
2786 | 523 |
begin |
524 |
lua_getglobal(luaState, Str2PChar(name)); |
|
525 |
ScriptGetString:= lua_tostring(luaState, -1); |
|
526 |
lua_pop(luaState, 1); |
|
527 |
end; |
|
528 |
||
529 |
procedure ScriptOnGameInit; |
|
2949 | 530 |
var s, t : ansistring; |
2786 | 531 |
begin |
3034 | 532 |
// not required if there is no script to run |
2949 | 533 |
if not ScriptLoaded then |
534 |
exit; |
|
2999 | 535 |
|
2949 | 536 |
// push game variables so they may be modified by the script |
537 |
ScriptSetInteger('GameFlags', GameFlags); |
|
538 |
ScriptSetString('Seed', cSeed); |
|
539 |
ScriptSetInteger('TurnTime', cHedgehogTurnTime); |
|
540 |
ScriptSetInteger('CaseFreq', cCaseFactor); |
|
541 |
ScriptSetInteger('LandAdds', cLandAdditions); |
|
2996 | 542 |
ScriptSetInteger('Explosives', cExplosives); |
2949 | 543 |
ScriptSetInteger('Delay', cInactDelay); |
544 |
ScriptSetString('Map', ''); |
|
545 |
ScriptSetString('Theme', ''); |
|
2786 | 546 |
|
2949 | 547 |
// import locale |
548 |
s:= cLocaleFName; |
|
549 |
SplitByChar(s, t, '.'); |
|
550 |
ScriptSetString('L', s); |
|
551 |
||
552 |
ScriptCall('onGameInit'); |
|
2786 | 553 |
|
2949 | 554 |
// pop game variables |
555 |
ParseCommand('seed ' + ScriptGetString('Seed'), true); |
|
556 |
ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true); |
|
557 |
ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true); |
|
558 |
ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true); |
|
559 |
ParseCommand('$landadds ' + ScriptGetString('LandAdds'), true); |
|
2996 | 560 |
ParseCommand('$explosives ' + ScriptGetString('Explosives'), true); |
2949 | 561 |
ParseCommand('$delay ' + ScriptGetString('Delay'), true); |
562 |
if ScriptGetString('Map') <> '' then |
|
563 |
ParseCommand('map ' + ScriptGetString('Map'), true); |
|
564 |
if ScriptGetString('Theme') <> '' then |
|
565 |
ParseCommand('theme ' + ScriptGetString('Theme'), true); |
|
566 |
||
2999 | 567 |
if ScriptExists('onAmmoStoreInit') then |
568 |
begin |
|
569 |
ScriptPrepareAmmoStore; |
|
570 |
ScriptCall('onAmmoStoreInit'); |
|
571 |
ScriptApplyAmmoStore |
|
572 |
end; |
|
573 |
||
574 |
ScriptSetInteger('ClansCount', ClansCount) |
|
2786 | 575 |
end; |
576 |
||
2905 | 577 |
procedure ScriptLoad(name : shortstring); |
2786 | 578 |
var ret : LongInt; |
579 |
begin |
|
2949 | 580 |
ret:= luaL_loadfile(luaState, Str2PChar(name)); |
581 |
if ret <> 0 then |
|
582 |
WriteLnToConsole('LUA: Failed to load ' + name + '(error ' + IntToStr(ret) + ')') |
|
583 |
else |
|
584 |
begin |
|
585 |
WriteLnToConsole('LUA: ' + name + ' loaded'); |
|
586 |
// call the script file |
|
587 |
lua_pcall(luaState, 0, 0, 0); |
|
588 |
ScriptLoaded:= true |
|
589 |
end |
|
2786 | 590 |
end; |
591 |
||
2814 | 592 |
procedure SetGlobals; |
593 |
begin |
|
2949 | 594 |
ScriptSetInteger('TurnTimeLeft', TurnTimeLeft); |
3003 | 595 |
if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then |
596 |
ScriptSetInteger('CurrentHedgehog', CurrentHedgehog^.Gear^.UID) |
|
597 |
else |
|
598 |
ScriptSetNil('CurrentHedgehog'); |
|
2814 | 599 |
end; |
600 |
||
601 |
procedure GetGlobals; |
|
602 |
begin |
|
2949 | 603 |
TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft'); |
2814 | 604 |
end; |
605 |
||
2905 | 606 |
procedure ScriptCall(fname : shortstring); |
2786 | 607 |
begin |
2999 | 608 |
if not ScriptLoaded or not ScriptExists(fname) then |
2949 | 609 |
exit; |
610 |
SetGlobals; |
|
611 |
lua_getglobal(luaState, Str2PChar(fname)); |
|
612 |
if lua_pcall(luaState, 0, 0, 0) <> 0 then |
|
613 |
begin |
|
614 |
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1)); |
|
615 |
lua_pop(luaState, 1) |
|
616 |
end; |
|
617 |
GetGlobals; |
|
2786 | 618 |
end; |
619 |
||
2905 | 620 |
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
2786 | 621 |
begin |
622 |
ScriptCall:= ScriptCall(fname, par1, 0, 0, 0) |
|
623 |
end; |
|
624 |
||
2905 | 625 |
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt; |
2786 | 626 |
begin |
627 |
ScriptCall:= ScriptCall(fname, par1, par2, 0, 0) |
|
628 |
end; |
|
629 |
||
2905 | 630 |
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; |
2786 | 631 |
begin |
632 |
ScriptCall:= ScriptCall(fname, par1, par2, par3, 0) |
|
633 |
end; |
|
634 |
||
2905 | 635 |
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; |
2786 | 636 |
begin |
2999 | 637 |
if not ScriptLoaded or not ScriptExists(fname) then |
2949 | 638 |
exit; |
639 |
SetGlobals; |
|
640 |
lua_getglobal(luaState, Str2PChar(fname)); |
|
641 |
lua_pushinteger(luaState, par1); |
|
642 |
lua_pushinteger(luaState, par2); |
|
643 |
lua_pushinteger(luaState, par3); |
|
644 |
lua_pushinteger(luaState, par4); |
|
645 |
ScriptCall:= 0; |
|
646 |
if lua_pcall(luaState, 4, 1, 0) <> 0 then |
|
647 |
begin |
|
648 |
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1)); |
|
649 |
lua_pop(luaState, 1) |
|
650 |
end |
|
651 |
else |
|
652 |
begin |
|
653 |
ScriptCall:= lua_tointeger(luaState, -1); |
|
654 |
lua_pop(luaState, 1) |
|
655 |
end; |
|
656 |
GetGlobals; |
|
2786 | 657 |
end; |
658 |
||
2999 | 659 |
function ScriptExists(fname : shortstring) : boolean; |
660 |
begin |
|
661 |
if not ScriptLoaded then |
|
662 |
begin |
|
663 |
ScriptExists:= false; |
|
664 |
exit |
|
665 |
end; |
|
666 |
lua_getglobal(luaState, Str2PChar(fname)); |
|
667 |
ScriptExists:= not lua_isnoneornil(luaState, -1); |
|
668 |
lua_pop(luaState, -1) |
|
669 |
end; |
|
670 |
||
2786 | 671 |
procedure ScriptPrepareAmmoStore; |
672 |
var i: ShortInt; |
|
673 |
begin |
|
2999 | 674 |
// reset ammostore (quite unclean, but works?) |
3038 | 675 |
uAmmos.freeModule; |
676 |
uAmmos.initModule; |
|
2786 | 677 |
ScriptAmmoStore:= ''; |
678 |
for i:=1 to ord(High(TAmmoType)) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
679 |
ScriptAmmoStore:= ScriptAmmoStore + '0000'; |
2786 | 680 |
end; |
681 |
||
2996 | 682 |
procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay: Byte); |
2786 | 683 |
begin |
2996 | 684 |
if (ord(ammo) < 1) or (count > 9) or (count < 0) or (propability < 0) or (propability > 8) or (delay < 0) or (delay > 9)then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
685 |
exit; |
2786 | 686 |
ScriptAmmoStore[ord(ammo)]:= inttostr(count)[1]; |
687 |
ScriptAmmoStore[ord(ammo) + ord(high(TAmmoType))]:= inttostr(propability)[1]; |
|
2996 | 688 |
ScriptAmmoStore[ord(ammo) + 2 * ord(high(TAmmoType))]:= inttostr(delay)[1]; |
2786 | 689 |
end; |
690 |
||
691 |
procedure ScriptApplyAmmoStore; |
|
2997 | 692 |
var i : LongInt; |
2786 | 693 |
begin |
2997 | 694 |
for i:= 0 to Pred(TeamsCount) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
695 |
AddAmmoStore(ScriptAmmoStore); |
2786 | 696 |
end; |
697 |
||
698 |
// small helper functions making registering enums a lot easier |
|
2905 | 699 |
function str(const en : TGearType) : shortstring; overload; |
2786 | 700 |
begin |
701 |
str:= GetEnumName(TypeInfo(TGearType), ord(en)) |
|
702 |
end; |
|
703 |
||
2905 | 704 |
function str(const en : TSound) : shortstring; overload; |
2786 | 705 |
begin |
706 |
str:= GetEnumName(TypeInfo(TSound), ord(en)) |
|
707 |
end; |
|
708 |
||
2905 | 709 |
function str(const en : TAmmoType) : shortstring; overload; |
2786 | 710 |
begin |
711 |
str:= GetEnumName(TypeInfo(TAmmoType), ord(en)) |
|
712 |
end; |
|
713 |
/////////////////// |
|
714 |
||
3038 | 715 |
procedure initModule; |
2786 | 716 |
var at : TGearType; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
717 |
am : TAmmoType; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
718 |
st : TSound; |
2786 | 719 |
begin |
720 |
// initialize lua |
|
721 |
luaState:= lua_open; |
|
722 |
||
723 |
// open internal libraries |
|
724 |
luaopen_base(luaState); |
|
725 |
luaopen_string(luaState); |
|
726 |
luaopen_math(luaState); |
|
727 |
||
728 |
// import some variables |
|
729 |
ScriptSetInteger('LAND_WIDTH', LAND_WIDTH); |
|
730 |
ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT); |
|
731 |
||
732 |
// import game flags |
|
2949 | 733 |
ScriptSetInteger('gfForts', gfForts); |
734 |
ScriptSetInteger('gfMultiWeapon', gfMultiWeapon); |
|
735 |
ScriptSetInteger('gfSolidLand', gfSolidLand); |
|
736 |
ScriptSetInteger('gfBorder', gfBorder); |
|
737 |
ScriptSetInteger('gfDivideTeams', gfDivideTeams); |
|
738 |
ScriptSetInteger('gfLowGravity', gfLowGravity); |
|
739 |
ScriptSetInteger('gfLaserSight', gfLaserSight); |
|
740 |
ScriptSetInteger('gfInvulnerable', gfInvulnerable); |
|
741 |
ScriptSetInteger('gfMines', gfMines); |
|
742 |
ScriptSetInteger('gfVampiric', gfVampiric); |
|
743 |
ScriptSetInteger('gfKarma', gfKarma); |
|
744 |
ScriptSetInteger('gfArtillery', gfArtillery); |
|
745 |
ScriptSetInteger('gfOneClanMode', gfOneClanMode); |
|
746 |
ScriptSetInteger('gfRandomOrder', gfRandomOrder); |
|
747 |
ScriptSetInteger('gfKing', gfKing); |
|
748 |
ScriptSetInteger('gfPlaceHog', gfPlaceHog); |
|
749 |
ScriptSetInteger('gfSharedAmmo', gfSharedAmmo); |
|
750 |
ScriptSetInteger('gfDisableGirders', gfDisableGirders); |
|
751 |
ScriptSetInteger('gfExplosives', gfExplosives); |
|
2786 | 752 |
|
753 |
// register gear types |
|
754 |
for at:= Low(TGearType) to High(TGearType) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
755 |
ScriptSetInteger(str(at), ord(at)); |
2786 | 756 |
|
757 |
// register sounds |
|
758 |
for st:= Low(TSound) to High(TSound) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
759 |
ScriptSetInteger(str(st), ord(st)); |
2786 | 760 |
|
761 |
// register ammo types |
|
762 |
for am:= Low(TAmmoType) to High(TAmmoType) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
763 |
ScriptSetInteger(str(am), ord(am)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
764 |
|
2786 | 765 |
// register functions |
766 |
lua_register(luaState, 'AddGear', @lc_addgear); |
|
767 |
lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole); |
|
768 |
lua_register(luaState, 'GetGearType', @lc_getgeartype); |
|
769 |
lua_register(luaState, 'EndGame', @lc_endgame); |
|
770 |
lua_register(luaState, 'FindPlace', @lc_findplace); |
|
771 |
lua_register(luaState, 'SetGearPosition', @lc_setgearposition); |
|
772 |
lua_register(luaState, 'GetGearPosition', @lc_getgearposition); |
|
773 |
lua_register(luaState, 'ParseCommand', @lc_parsecommand); |
|
774 |
lua_register(luaState, 'ShowMission', @lc_showmission); |
|
775 |
lua_register(luaState, 'HideMission', @lc_hidemission); |
|
776 |
lua_register(luaState, 'SetAmmo', @lc_setammo); |
|
777 |
lua_register(luaState, 'PlaySound', @lc_playsound); |
|
778 |
lua_register(luaState, 'AddTeam', @lc_addteam); |
|
779 |
lua_register(luaState, 'AddHog', @lc_addhog); |
|
2814 | 780 |
lua_register(luaState, 'SetHealth', @lc_sethealth); |
2999 | 781 |
lua_register(luaState, 'GetHogClan', @lc_gethogclan); |
782 |
lua_register(luaState, 'GetHogName', @lc_gethogname); |
|
3004 | 783 |
lua_register(luaState, 'GetX', @lc_getx); |
784 |
lua_register(luaState, 'GetY', @lc_gety); |
|
785 |
lua_register(luaState, 'CopyPV', @lc_copypv); |
|
786 |
lua_register(luaState, 'CopyPV2', @lc_copypv2); |
|
787 |
lua_register(luaState, 'FollowGear', @lc_followgear); |
|
788 |
lua_register(luaState, 'SetState', @lc_setstate); |
|
789 |
lua_register(luaState, 'GetState', @lc_getstate); |
|
790 |
lua_register(luaState, 'SetTag', @lc_settag); |
|
791 |
||
2786 | 792 |
|
793 |
ScriptClearStack; // just to be sure stack is empty |
|
2793 | 794 |
ScriptLoaded:= false; |
2786 | 795 |
end; |
796 |
||
3038 | 797 |
procedure freeModule; |
2786 | 798 |
begin |
799 |
lua_close(luaState); |
|
800 |
end; |
|
801 |
||
2798 | 802 |
{$ELSE} |
803 |
procedure ScriptPrintStack; |
|
804 |
begin |
|
805 |
end; |
|
806 |
||
807 |
procedure ScriptClearStack; |
|
808 |
begin |
|
809 |
end; |
|
810 |
||
2905 | 811 |
procedure ScriptLoad(name : shortstring); |
2798 | 812 |
begin |
813 |
end; |
|
814 |
||
815 |
procedure ScriptOnGameInit; |
|
816 |
begin |
|
817 |
end; |
|
818 |
||
2905 | 819 |
procedure ScriptCall(fname : shortstring); |
2798 | 820 |
begin |
821 |
end; |
|
822 |
||
2905 | 823 |
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; |
2798 | 824 |
begin |
2799 | 825 |
ScriptCall:= 0 |
826 |
end; |
|
827 |
||
2905 | 828 |
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
2799 | 829 |
begin |
830 |
ScriptCall:= 0 |
|
831 |
end; |
|
832 |
||
2905 | 833 |
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt; |
2799 | 834 |
begin |
835 |
ScriptCall:= 0 |
|
836 |
end; |
|
837 |
||
2905 | 838 |
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; |
2799 | 839 |
begin |
840 |
ScriptCall:= 0 |
|
2798 | 841 |
end; |
842 |
||
2999 | 843 |
function ScriptExists(fname : shortstring) : boolean; |
844 |
begin |
|
845 |
ScriptExists:= false |
|
846 |
end; |
|
847 |
||
3038 | 848 |
procedure initModule; |
2798 | 849 |
begin |
850 |
end; |
|
851 |
||
3038 | 852 |
procedure freeModule; |
2798 | 853 |
begin |
854 |
end; |
|
855 |
||
856 |
{$ENDIF} |
|
2786 | 857 |
end. |