author | smxx |
Mon, 15 Mar 2010 11:53:32 +0000 | |
changeset 2999 | 30c4d62cd0c3 |
parent 2997 | ca60b5638fff |
child 3003 | 0afdba08a858 |
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 |
|
37 |
procedure init_uScript; |
|
38 |
procedure free_uScript; |
|
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 |
||
2814 | 197 |
function lc_sethealth(L : Plua_State) : LongInt; Cdecl; |
198 |
var gear : PGear; |
|
199 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
200 |
if lua_gettop(L) <> 2 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
201 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
202 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetHealth!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
203 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
204 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
205 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
206 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
207 |
if (gear <> nil) and (gear^.Kind = gtHedgehog) then gear^.Health:= lua_tointeger(L, 2) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
208 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
209 |
lc_sethealth:= 0 |
2814 | 210 |
end; |
211 |
||
2786 | 212 |
function lc_endgame(L : Plua_State) : LongInt; Cdecl; |
213 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
214 |
GameState:= gsExit; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
215 |
lc_endgame:= 0 |
2786 | 216 |
end; |
217 |
||
218 |
function lc_findplace(L : Plua_State) : LongInt; Cdecl; |
|
219 |
var gear: PGear; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
220 |
fall: boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
221 |
left, right: LongInt; |
2786 | 222 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
223 |
if lua_gettop(L) <> 4 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
224 |
WriteLnToConsole('LUA: Wrong number of parameters passed to FindPlace!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
225 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
226 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
227 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
228 |
fall:= lua_toboolean(L, 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
229 |
left:= lua_tointeger(L, 3); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
230 |
right:= lua_tointeger(L, 4); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
231 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
232 |
FindPlace(gear, fall, left, right) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
233 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
234 |
lc_findplace:= 0 |
2786 | 235 |
end; |
236 |
||
237 |
function lc_playsound(L : Plua_State) : LongInt; Cdecl; |
|
238 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
239 |
if lua_gettop(L) <> 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
240 |
WriteLnToConsole('LUA: Wrong number of parameters passed to PlaySound!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
241 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
242 |
PlaySound(TSound(lua_tointeger(L, 1))); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
243 |
lc_playsound:= 0; |
2786 | 244 |
end; |
245 |
||
246 |
function lc_addteam(L : Plua_State) : LongInt; Cdecl; |
|
247 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
248 |
if lua_gettop(L) <> 5 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
249 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
250 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddTeam!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
251 |
//lua_pushnil(L) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
252 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
253 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
254 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
255 |
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
|
256 |
ParseCommand('grave ' + lua_tostring(L, 3), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
257 |
ParseCommand('fort ' + lua_tostring(L, 4), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
258 |
ParseCommand('voicepack ' + lua_tostring(L, 5), true); |
2996 | 259 |
CurrentTeam^.Binds:= DefaultBinds |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
260 |
// fails on x64 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
261 |
//lua_pushinteger(L, LongInt(CurrentTeam)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
262 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
263 |
lc_addteam:= 0;//1; |
2786 | 264 |
end; |
265 |
||
266 |
function lc_addhog(L : Plua_State) : LongInt; Cdecl; |
|
267 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
268 |
if lua_gettop(L) <> 4 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
269 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
270 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddHog!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
271 |
lua_pushnil(L) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
272 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
273 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
274 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
275 |
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
|
276 |
ParseCommand('hat ' + lua_tostring(L, 4), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
277 |
lua_pushinteger(L, CurrentHedgehog^.Gear^.uid); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
278 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
279 |
lc_addhog:= 1; |
2786 | 280 |
end; |
281 |
||
282 |
function lc_getgearposition(L : Plua_State) : LongInt; Cdecl; |
|
283 |
var gear: PGear; |
|
284 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
285 |
if lua_gettop(L) <> 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
286 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
287 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetGearPosition!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
288 |
lua_pushnil(L); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
289 |
lua_pushnil(L) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
290 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
291 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
292 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
293 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
294 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
295 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
296 |
lua_pushinteger(L, hwRound(gear^.X)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
297 |
lua_pushinteger(L, hwRound(gear^.Y)) |
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 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
300 |
lc_getgearposition:= 2; |
2786 | 301 |
end; |
302 |
||
303 |
function lc_setgearposition(L : Plua_State) : LongInt; Cdecl; |
|
304 |
var gear: PGear; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
305 |
x, y: LongInt; |
2786 | 306 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
307 |
if lua_gettop(L) <> 3 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
308 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetGearPosition!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
309 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
310 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
311 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
312 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
313 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
314 |
x:= lua_tointeger(L, 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
315 |
y:= lua_tointeger(L, 3); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
316 |
gear^.X:= int2hwfloat(x); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
317 |
gear^.Y:= int2hwfloat(y); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
318 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
319 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
320 |
lc_setgearposition:= 0 |
2786 | 321 |
end; |
322 |
||
323 |
function lc_setammo(L : Plua_State) : LongInt; Cdecl; |
|
324 |
begin |
|
2996 | 325 |
if lua_gettop(L) <> 4 then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
326 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetAmmo!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
327 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
328 |
begin |
2996 | 329 |
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
|
330 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
331 |
lc_setammo:= 0 |
2786 | 332 |
end; |
333 |
/////////////////// |
|
334 |
||
335 |
procedure ScriptPrintStack; |
|
336 |
var n, i : LongInt; |
|
337 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
338 |
n:= lua_gettop(luaState); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
339 |
WriteLnToConsole('LUA: Stack (' + inttostr(n) + ' elements):'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
340 |
for i:= 1 to n do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
341 |
if not lua_isboolean(luaState, i) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
342 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': ' + lua_tostring(luaState, i)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
343 |
else if lua_toboolean(luaState, i) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
344 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': true') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
345 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
346 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': false'); |
2786 | 347 |
end; |
348 |
||
349 |
procedure ScriptClearStack; |
|
350 |
begin |
|
351 |
lua_settop(luaState, 0) |
|
352 |
end; |
|
353 |
||
2905 | 354 |
procedure ScriptSetInteger(name : shortstring; value : LongInt); |
2786 | 355 |
begin |
356 |
lua_pushinteger(luaState, value); |
|
357 |
lua_setglobal(luaState, Str2PChar(name)); |
|
358 |
end; |
|
359 |
||
2905 | 360 |
procedure ScriptSetString(name : shortstring; value : shortstring); |
2786 | 361 |
begin |
362 |
lua_pushstring(luaState, Str2PChar(value)); |
|
363 |
lua_setglobal(luaState, Str2PChar(name)); |
|
364 |
end; |
|
365 |
||
2905 | 366 |
function ScriptGetInteger(name : shortstring) : LongInt; |
2786 | 367 |
begin |
368 |
lua_getglobal(luaState, Str2PChar(name)); |
|
369 |
ScriptGetInteger:= lua_tointeger(luaState, -1); |
|
370 |
lua_pop(luaState, 1); |
|
371 |
end; |
|
372 |
||
2905 | 373 |
function ScriptGetString(name : shortstring) : shortstring; |
2786 | 374 |
begin |
375 |
lua_getglobal(luaState, Str2PChar(name)); |
|
376 |
ScriptGetString:= lua_tostring(luaState, -1); |
|
377 |
lua_pop(luaState, 1); |
|
378 |
end; |
|
379 |
||
380 |
procedure ScriptOnGameInit; |
|
2949 | 381 |
var s, t : ansistring; |
2786 | 382 |
begin |
2949 | 383 |
// not required if there's no script to run |
384 |
if not ScriptLoaded then |
|
385 |
exit; |
|
2999 | 386 |
|
2949 | 387 |
// push game variables so they may be modified by the script |
388 |
ScriptSetInteger('GameFlags', GameFlags); |
|
389 |
ScriptSetString('Seed', cSeed); |
|
390 |
ScriptSetInteger('TurnTime', cHedgehogTurnTime); |
|
391 |
ScriptSetInteger('CaseFreq', cCaseFactor); |
|
392 |
ScriptSetInteger('LandAdds', cLandAdditions); |
|
2996 | 393 |
ScriptSetInteger('Explosives', cExplosives); |
2949 | 394 |
ScriptSetInteger('Delay', cInactDelay); |
395 |
ScriptSetString('Map', ''); |
|
396 |
ScriptSetString('Theme', ''); |
|
2786 | 397 |
|
2949 | 398 |
// import locale |
399 |
s:= cLocaleFName; |
|
400 |
SplitByChar(s, t, '.'); |
|
401 |
ScriptSetString('L', s); |
|
402 |
||
403 |
ScriptCall('onGameInit'); |
|
2786 | 404 |
|
2949 | 405 |
// pop game variables |
406 |
ParseCommand('seed ' + ScriptGetString('Seed'), true); |
|
407 |
ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true); |
|
408 |
ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true); |
|
409 |
ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true); |
|
410 |
ParseCommand('$landadds ' + ScriptGetString('LandAdds'), true); |
|
2996 | 411 |
ParseCommand('$explosives ' + ScriptGetString('Explosives'), true); |
2949 | 412 |
ParseCommand('$delay ' + ScriptGetString('Delay'), true); |
413 |
if ScriptGetString('Map') <> '' then |
|
414 |
ParseCommand('map ' + ScriptGetString('Map'), true); |
|
415 |
if ScriptGetString('Theme') <> '' then |
|
416 |
ParseCommand('theme ' + ScriptGetString('Theme'), true); |
|
417 |
||
2999 | 418 |
if ScriptExists('onAmmoStoreInit') then |
419 |
begin |
|
420 |
ScriptPrepareAmmoStore; |
|
421 |
ScriptCall('onAmmoStoreInit'); |
|
422 |
ScriptApplyAmmoStore |
|
423 |
end; |
|
424 |
||
425 |
ScriptSetInteger('ClansCount', ClansCount) |
|
2786 | 426 |
end; |
427 |
||
2905 | 428 |
procedure ScriptLoad(name : shortstring); |
2786 | 429 |
var ret : LongInt; |
430 |
begin |
|
2949 | 431 |
ret:= luaL_loadfile(luaState, Str2PChar(name)); |
432 |
if ret <> 0 then |
|
433 |
WriteLnToConsole('LUA: Failed to load ' + name + '(error ' + IntToStr(ret) + ')') |
|
434 |
else |
|
435 |
begin |
|
436 |
WriteLnToConsole('LUA: ' + name + ' loaded'); |
|
437 |
// call the script file |
|
438 |
lua_pcall(luaState, 0, 0, 0); |
|
439 |
ScriptLoaded:= true |
|
440 |
end |
|
2786 | 441 |
end; |
442 |
||
2814 | 443 |
procedure SetGlobals; |
444 |
begin |
|
2949 | 445 |
ScriptSetInteger('TurnTimeLeft', TurnTimeLeft); |
2814 | 446 |
end; |
447 |
||
448 |
procedure GetGlobals; |
|
449 |
begin |
|
2949 | 450 |
TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft'); |
2814 | 451 |
end; |
452 |
||
2905 | 453 |
procedure ScriptCall(fname : shortstring); |
2786 | 454 |
begin |
2999 | 455 |
if not ScriptLoaded or not ScriptExists(fname) then |
2949 | 456 |
exit; |
457 |
SetGlobals; |
|
458 |
lua_getglobal(luaState, Str2PChar(fname)); |
|
459 |
if lua_pcall(luaState, 0, 0, 0) <> 0 then |
|
460 |
begin |
|
461 |
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1)); |
|
462 |
lua_pop(luaState, 1) |
|
463 |
end; |
|
464 |
GetGlobals; |
|
2786 | 465 |
end; |
466 |
||
2905 | 467 |
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
2786 | 468 |
begin |
469 |
ScriptCall:= ScriptCall(fname, par1, 0, 0, 0) |
|
470 |
end; |
|
471 |
||
2905 | 472 |
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt; |
2786 | 473 |
begin |
474 |
ScriptCall:= ScriptCall(fname, par1, par2, 0, 0) |
|
475 |
end; |
|
476 |
||
2905 | 477 |
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; |
2786 | 478 |
begin |
479 |
ScriptCall:= ScriptCall(fname, par1, par2, par3, 0) |
|
480 |
end; |
|
481 |
||
2905 | 482 |
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; |
2786 | 483 |
begin |
2999 | 484 |
if not ScriptLoaded or not ScriptExists(fname) then |
2949 | 485 |
exit; |
486 |
SetGlobals; |
|
487 |
lua_getglobal(luaState, Str2PChar(fname)); |
|
488 |
lua_pushinteger(luaState, par1); |
|
489 |
lua_pushinteger(luaState, par2); |
|
490 |
lua_pushinteger(luaState, par3); |
|
491 |
lua_pushinteger(luaState, par4); |
|
492 |
ScriptCall:= 0; |
|
493 |
if lua_pcall(luaState, 4, 1, 0) <> 0 then |
|
494 |
begin |
|
495 |
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1)); |
|
496 |
lua_pop(luaState, 1) |
|
497 |
end |
|
498 |
else |
|
499 |
begin |
|
500 |
ScriptCall:= lua_tointeger(luaState, -1); |
|
501 |
lua_pop(luaState, 1) |
|
502 |
end; |
|
503 |
GetGlobals; |
|
2786 | 504 |
end; |
505 |
||
2999 | 506 |
function ScriptExists(fname : shortstring) : boolean; |
507 |
begin |
|
508 |
if not ScriptLoaded then |
|
509 |
begin |
|
510 |
ScriptExists:= false; |
|
511 |
exit |
|
512 |
end; |
|
513 |
lua_getglobal(luaState, Str2PChar(fname)); |
|
514 |
ScriptExists:= not lua_isnoneornil(luaState, -1); |
|
515 |
lua_pop(luaState, -1) |
|
516 |
end; |
|
517 |
||
2786 | 518 |
procedure ScriptPrepareAmmoStore; |
519 |
var i: ShortInt; |
|
520 |
begin |
|
2999 | 521 |
// reset ammostore (quite unclean, but works?) |
522 |
free_uAmmos; |
|
523 |
init_uAmmos; |
|
2786 | 524 |
ScriptAmmoStore:= ''; |
525 |
for i:=1 to ord(High(TAmmoType)) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
526 |
ScriptAmmoStore:= ScriptAmmoStore + '0000'; |
2786 | 527 |
end; |
528 |
||
2996 | 529 |
procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay: Byte); |
2786 | 530 |
begin |
2996 | 531 |
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
|
532 |
exit; |
2786 | 533 |
ScriptAmmoStore[ord(ammo)]:= inttostr(count)[1]; |
534 |
ScriptAmmoStore[ord(ammo) + ord(high(TAmmoType))]:= inttostr(propability)[1]; |
|
2996 | 535 |
ScriptAmmoStore[ord(ammo) + 2 * ord(high(TAmmoType))]:= inttostr(delay)[1]; |
2786 | 536 |
end; |
537 |
||
538 |
procedure ScriptApplyAmmoStore; |
|
2997 | 539 |
var i : LongInt; |
2786 | 540 |
begin |
2997 | 541 |
for i:= 0 to Pred(TeamsCount) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
542 |
AddAmmoStore(ScriptAmmoStore); |
2786 | 543 |
end; |
544 |
||
545 |
// small helper functions making registering enums a lot easier |
|
2905 | 546 |
function str(const en : TGearType) : shortstring; overload; |
2786 | 547 |
begin |
548 |
str:= GetEnumName(TypeInfo(TGearType), ord(en)) |
|
549 |
end; |
|
550 |
||
2905 | 551 |
function str(const en : TSound) : shortstring; overload; |
2786 | 552 |
begin |
553 |
str:= GetEnumName(TypeInfo(TSound), ord(en)) |
|
554 |
end; |
|
555 |
||
2905 | 556 |
function str(const en : TAmmoType) : shortstring; overload; |
2786 | 557 |
begin |
558 |
str:= GetEnumName(TypeInfo(TAmmoType), ord(en)) |
|
559 |
end; |
|
560 |
/////////////////// |
|
561 |
||
562 |
procedure init_uScript; |
|
563 |
var at : TGearType; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
564 |
am : TAmmoType; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
565 |
st : TSound; |
2786 | 566 |
begin |
567 |
// initialize lua |
|
568 |
luaState:= lua_open; |
|
569 |
||
570 |
// open internal libraries |
|
571 |
luaopen_base(luaState); |
|
572 |
luaopen_string(luaState); |
|
573 |
luaopen_math(luaState); |
|
574 |
||
575 |
// import some variables |
|
576 |
ScriptSetInteger('LAND_WIDTH', LAND_WIDTH); |
|
577 |
ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT); |
|
578 |
||
579 |
// import game flags |
|
2949 | 580 |
ScriptSetInteger('gfForts', gfForts); |
581 |
ScriptSetInteger('gfMultiWeapon', gfMultiWeapon); |
|
582 |
ScriptSetInteger('gfSolidLand', gfSolidLand); |
|
583 |
ScriptSetInteger('gfBorder', gfBorder); |
|
584 |
ScriptSetInteger('gfDivideTeams', gfDivideTeams); |
|
585 |
ScriptSetInteger('gfLowGravity', gfLowGravity); |
|
586 |
ScriptSetInteger('gfLaserSight', gfLaserSight); |
|
587 |
ScriptSetInteger('gfInvulnerable', gfInvulnerable); |
|
588 |
ScriptSetInteger('gfMines', gfMines); |
|
589 |
ScriptSetInteger('gfVampiric', gfVampiric); |
|
590 |
ScriptSetInteger('gfKarma', gfKarma); |
|
591 |
ScriptSetInteger('gfArtillery', gfArtillery); |
|
592 |
ScriptSetInteger('gfOneClanMode', gfOneClanMode); |
|
593 |
ScriptSetInteger('gfRandomOrder', gfRandomOrder); |
|
594 |
ScriptSetInteger('gfKing', gfKing); |
|
595 |
ScriptSetInteger('gfPlaceHog', gfPlaceHog); |
|
596 |
ScriptSetInteger('gfSharedAmmo', gfSharedAmmo); |
|
597 |
ScriptSetInteger('gfDisableGirders', gfDisableGirders); |
|
598 |
ScriptSetInteger('gfExplosives', gfExplosives); |
|
2786 | 599 |
|
600 |
// register gear types |
|
601 |
for at:= Low(TGearType) to High(TGearType) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
602 |
ScriptSetInteger(str(at), ord(at)); |
2786 | 603 |
|
604 |
// register sounds |
|
605 |
for st:= Low(TSound) to High(TSound) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
606 |
ScriptSetInteger(str(st), ord(st)); |
2786 | 607 |
|
608 |
// register ammo types |
|
609 |
for am:= Low(TAmmoType) to High(TAmmoType) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
610 |
ScriptSetInteger(str(am), ord(am)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
611 |
|
2786 | 612 |
// register functions |
613 |
lua_register(luaState, 'AddGear', @lc_addgear); |
|
614 |
lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole); |
|
615 |
lua_register(luaState, 'GetGearType', @lc_getgeartype); |
|
616 |
lua_register(luaState, 'EndGame', @lc_endgame); |
|
617 |
lua_register(luaState, 'FindPlace', @lc_findplace); |
|
618 |
lua_register(luaState, 'SetGearPosition', @lc_setgearposition); |
|
619 |
lua_register(luaState, 'GetGearPosition', @lc_getgearposition); |
|
620 |
lua_register(luaState, 'ParseCommand', @lc_parsecommand); |
|
621 |
lua_register(luaState, 'ShowMission', @lc_showmission); |
|
622 |
lua_register(luaState, 'HideMission', @lc_hidemission); |
|
623 |
lua_register(luaState, 'SetAmmo', @lc_setammo); |
|
624 |
lua_register(luaState, 'PlaySound', @lc_playsound); |
|
625 |
lua_register(luaState, 'AddTeam', @lc_addteam); |
|
626 |
lua_register(luaState, 'AddHog', @lc_addhog); |
|
2814 | 627 |
lua_register(luaState, 'SetHealth', @lc_sethealth); |
2999 | 628 |
lua_register(luaState, 'GetHogClan', @lc_gethogclan); |
629 |
lua_register(luaState, 'GetHogName', @lc_gethogname); |
|
2786 | 630 |
|
631 |
ScriptClearStack; // just to be sure stack is empty |
|
2793 | 632 |
ScriptLoaded:= false; |
2786 | 633 |
end; |
634 |
||
635 |
procedure free_uScript; |
|
636 |
begin |
|
637 |
lua_close(luaState); |
|
638 |
end; |
|
639 |
||
2798 | 640 |
{$ELSE} |
641 |
procedure ScriptPrintStack; |
|
642 |
begin |
|
643 |
end; |
|
644 |
||
645 |
procedure ScriptClearStack; |
|
646 |
begin |
|
647 |
end; |
|
648 |
||
2905 | 649 |
procedure ScriptLoad(name : shortstring); |
2798 | 650 |
begin |
651 |
end; |
|
652 |
||
653 |
procedure ScriptOnGameInit; |
|
654 |
begin |
|
655 |
end; |
|
656 |
||
2905 | 657 |
procedure ScriptCall(fname : shortstring); |
2798 | 658 |
begin |
659 |
end; |
|
660 |
||
2905 | 661 |
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; |
2798 | 662 |
begin |
2799 | 663 |
ScriptCall:= 0 |
664 |
end; |
|
665 |
||
2905 | 666 |
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
2799 | 667 |
begin |
668 |
ScriptCall:= 0 |
|
669 |
end; |
|
670 |
||
2905 | 671 |
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt; |
2799 | 672 |
begin |
673 |
ScriptCall:= 0 |
|
674 |
end; |
|
675 |
||
2905 | 676 |
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; |
2799 | 677 |
begin |
678 |
ScriptCall:= 0 |
|
2798 | 679 |
end; |
680 |
||
2999 | 681 |
function ScriptExists(fname : shortstring) : boolean; |
682 |
begin |
|
683 |
ScriptExists:= false |
|
684 |
end; |
|
685 |
||
2798 | 686 |
procedure init_uScript; |
687 |
begin |
|
688 |
end; |
|
689 |
||
690 |
procedure free_uScript; |
|
691 |
begin |
|
692 |
end; |
|
693 |
||
694 |
{$ENDIF} |
|
2786 | 695 |
end. |