author | smxx |
Tue, 16 Mar 2010 19:28:15 +0000 | |
changeset 3003 | 0afdba08a858 |
parent 2999 | 30c4d62cd0c3 |
child 3004 | e9b3613cc3fb |
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 |
||
3003 | 354 |
procedure ScriptSetNil(name : shortstring); |
355 |
begin |
|
356 |
lua_pushnil(luaState); |
|
357 |
lua_setglobal(luaState, Str2PChar(name)); |
|
358 |
end; |
|
359 |
||
2905 | 360 |
procedure ScriptSetInteger(name : shortstring; value : LongInt); |
2786 | 361 |
begin |
362 |
lua_pushinteger(luaState, value); |
|
363 |
lua_setglobal(luaState, Str2PChar(name)); |
|
364 |
end; |
|
365 |
||
2905 | 366 |
procedure ScriptSetString(name : shortstring; value : shortstring); |
2786 | 367 |
begin |
368 |
lua_pushstring(luaState, Str2PChar(value)); |
|
369 |
lua_setglobal(luaState, Str2PChar(name)); |
|
370 |
end; |
|
371 |
||
2905 | 372 |
function ScriptGetInteger(name : shortstring) : LongInt; |
2786 | 373 |
begin |
374 |
lua_getglobal(luaState, Str2PChar(name)); |
|
375 |
ScriptGetInteger:= lua_tointeger(luaState, -1); |
|
376 |
lua_pop(luaState, 1); |
|
377 |
end; |
|
378 |
||
2905 | 379 |
function ScriptGetString(name : shortstring) : shortstring; |
2786 | 380 |
begin |
381 |
lua_getglobal(luaState, Str2PChar(name)); |
|
382 |
ScriptGetString:= lua_tostring(luaState, -1); |
|
383 |
lua_pop(luaState, 1); |
|
384 |
end; |
|
385 |
||
386 |
procedure ScriptOnGameInit; |
|
2949 | 387 |
var s, t : ansistring; |
2786 | 388 |
begin |
2949 | 389 |
// not required if there's no script to run |
390 |
if not ScriptLoaded then |
|
391 |
exit; |
|
2999 | 392 |
|
2949 | 393 |
// push game variables so they may be modified by the script |
394 |
ScriptSetInteger('GameFlags', GameFlags); |
|
395 |
ScriptSetString('Seed', cSeed); |
|
396 |
ScriptSetInteger('TurnTime', cHedgehogTurnTime); |
|
397 |
ScriptSetInteger('CaseFreq', cCaseFactor); |
|
398 |
ScriptSetInteger('LandAdds', cLandAdditions); |
|
2996 | 399 |
ScriptSetInteger('Explosives', cExplosives); |
2949 | 400 |
ScriptSetInteger('Delay', cInactDelay); |
401 |
ScriptSetString('Map', ''); |
|
402 |
ScriptSetString('Theme', ''); |
|
2786 | 403 |
|
2949 | 404 |
// import locale |
405 |
s:= cLocaleFName; |
|
406 |
SplitByChar(s, t, '.'); |
|
407 |
ScriptSetString('L', s); |
|
408 |
||
409 |
ScriptCall('onGameInit'); |
|
2786 | 410 |
|
2949 | 411 |
// pop game variables |
412 |
ParseCommand('seed ' + ScriptGetString('Seed'), true); |
|
413 |
ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true); |
|
414 |
ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true); |
|
415 |
ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true); |
|
416 |
ParseCommand('$landadds ' + ScriptGetString('LandAdds'), true); |
|
2996 | 417 |
ParseCommand('$explosives ' + ScriptGetString('Explosives'), true); |
2949 | 418 |
ParseCommand('$delay ' + ScriptGetString('Delay'), true); |
419 |
if ScriptGetString('Map') <> '' then |
|
420 |
ParseCommand('map ' + ScriptGetString('Map'), true); |
|
421 |
if ScriptGetString('Theme') <> '' then |
|
422 |
ParseCommand('theme ' + ScriptGetString('Theme'), true); |
|
423 |
||
2999 | 424 |
if ScriptExists('onAmmoStoreInit') then |
425 |
begin |
|
426 |
ScriptPrepareAmmoStore; |
|
427 |
ScriptCall('onAmmoStoreInit'); |
|
428 |
ScriptApplyAmmoStore |
|
429 |
end; |
|
430 |
||
431 |
ScriptSetInteger('ClansCount', ClansCount) |
|
2786 | 432 |
end; |
433 |
||
2905 | 434 |
procedure ScriptLoad(name : shortstring); |
2786 | 435 |
var ret : LongInt; |
436 |
begin |
|
2949 | 437 |
ret:= luaL_loadfile(luaState, Str2PChar(name)); |
438 |
if ret <> 0 then |
|
439 |
WriteLnToConsole('LUA: Failed to load ' + name + '(error ' + IntToStr(ret) + ')') |
|
440 |
else |
|
441 |
begin |
|
442 |
WriteLnToConsole('LUA: ' + name + ' loaded'); |
|
443 |
// call the script file |
|
444 |
lua_pcall(luaState, 0, 0, 0); |
|
445 |
ScriptLoaded:= true |
|
446 |
end |
|
2786 | 447 |
end; |
448 |
||
2814 | 449 |
procedure SetGlobals; |
450 |
begin |
|
2949 | 451 |
ScriptSetInteger('TurnTimeLeft', TurnTimeLeft); |
3003 | 452 |
if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then |
453 |
ScriptSetInteger('CurrentHedgehog', CurrentHedgehog^.Gear^.UID) |
|
454 |
else |
|
455 |
ScriptSetNil('CurrentHedgehog'); |
|
2814 | 456 |
end; |
457 |
||
458 |
procedure GetGlobals; |
|
459 |
begin |
|
2949 | 460 |
TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft'); |
2814 | 461 |
end; |
462 |
||
2905 | 463 |
procedure ScriptCall(fname : shortstring); |
2786 | 464 |
begin |
2999 | 465 |
if not ScriptLoaded or not ScriptExists(fname) then |
2949 | 466 |
exit; |
467 |
SetGlobals; |
|
468 |
lua_getglobal(luaState, Str2PChar(fname)); |
|
469 |
if lua_pcall(luaState, 0, 0, 0) <> 0 then |
|
470 |
begin |
|
471 |
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1)); |
|
472 |
lua_pop(luaState, 1) |
|
473 |
end; |
|
474 |
GetGlobals; |
|
2786 | 475 |
end; |
476 |
||
2905 | 477 |
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
2786 | 478 |
begin |
479 |
ScriptCall:= ScriptCall(fname, par1, 0, 0, 0) |
|
480 |
end; |
|
481 |
||
2905 | 482 |
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt; |
2786 | 483 |
begin |
484 |
ScriptCall:= ScriptCall(fname, par1, par2, 0, 0) |
|
485 |
end; |
|
486 |
||
2905 | 487 |
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; |
2786 | 488 |
begin |
489 |
ScriptCall:= ScriptCall(fname, par1, par2, par3, 0) |
|
490 |
end; |
|
491 |
||
2905 | 492 |
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; |
2786 | 493 |
begin |
2999 | 494 |
if not ScriptLoaded or not ScriptExists(fname) then |
2949 | 495 |
exit; |
496 |
SetGlobals; |
|
497 |
lua_getglobal(luaState, Str2PChar(fname)); |
|
498 |
lua_pushinteger(luaState, par1); |
|
499 |
lua_pushinteger(luaState, par2); |
|
500 |
lua_pushinteger(luaState, par3); |
|
501 |
lua_pushinteger(luaState, par4); |
|
502 |
ScriptCall:= 0; |
|
503 |
if lua_pcall(luaState, 4, 1, 0) <> 0 then |
|
504 |
begin |
|
505 |
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1)); |
|
506 |
lua_pop(luaState, 1) |
|
507 |
end |
|
508 |
else |
|
509 |
begin |
|
510 |
ScriptCall:= lua_tointeger(luaState, -1); |
|
511 |
lua_pop(luaState, 1) |
|
512 |
end; |
|
513 |
GetGlobals; |
|
2786 | 514 |
end; |
515 |
||
2999 | 516 |
function ScriptExists(fname : shortstring) : boolean; |
517 |
begin |
|
518 |
if not ScriptLoaded then |
|
519 |
begin |
|
520 |
ScriptExists:= false; |
|
521 |
exit |
|
522 |
end; |
|
523 |
lua_getglobal(luaState, Str2PChar(fname)); |
|
524 |
ScriptExists:= not lua_isnoneornil(luaState, -1); |
|
525 |
lua_pop(luaState, -1) |
|
526 |
end; |
|
527 |
||
2786 | 528 |
procedure ScriptPrepareAmmoStore; |
529 |
var i: ShortInt; |
|
530 |
begin |
|
2999 | 531 |
// reset ammostore (quite unclean, but works?) |
532 |
free_uAmmos; |
|
533 |
init_uAmmos; |
|
2786 | 534 |
ScriptAmmoStore:= ''; |
535 |
for i:=1 to ord(High(TAmmoType)) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
536 |
ScriptAmmoStore:= ScriptAmmoStore + '0000'; |
2786 | 537 |
end; |
538 |
||
2996 | 539 |
procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay: Byte); |
2786 | 540 |
begin |
2996 | 541 |
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
|
542 |
exit; |
2786 | 543 |
ScriptAmmoStore[ord(ammo)]:= inttostr(count)[1]; |
544 |
ScriptAmmoStore[ord(ammo) + ord(high(TAmmoType))]:= inttostr(propability)[1]; |
|
2996 | 545 |
ScriptAmmoStore[ord(ammo) + 2 * ord(high(TAmmoType))]:= inttostr(delay)[1]; |
2786 | 546 |
end; |
547 |
||
548 |
procedure ScriptApplyAmmoStore; |
|
2997 | 549 |
var i : LongInt; |
2786 | 550 |
begin |
2997 | 551 |
for i:= 0 to Pred(TeamsCount) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
552 |
AddAmmoStore(ScriptAmmoStore); |
2786 | 553 |
end; |
554 |
||
555 |
// small helper functions making registering enums a lot easier |
|
2905 | 556 |
function str(const en : TGearType) : shortstring; overload; |
2786 | 557 |
begin |
558 |
str:= GetEnumName(TypeInfo(TGearType), ord(en)) |
|
559 |
end; |
|
560 |
||
2905 | 561 |
function str(const en : TSound) : shortstring; overload; |
2786 | 562 |
begin |
563 |
str:= GetEnumName(TypeInfo(TSound), ord(en)) |
|
564 |
end; |
|
565 |
||
2905 | 566 |
function str(const en : TAmmoType) : shortstring; overload; |
2786 | 567 |
begin |
568 |
str:= GetEnumName(TypeInfo(TAmmoType), ord(en)) |
|
569 |
end; |
|
570 |
/////////////////// |
|
571 |
||
572 |
procedure init_uScript; |
|
573 |
var at : TGearType; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
574 |
am : TAmmoType; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
575 |
st : TSound; |
2786 | 576 |
begin |
577 |
// initialize lua |
|
578 |
luaState:= lua_open; |
|
579 |
||
580 |
// open internal libraries |
|
581 |
luaopen_base(luaState); |
|
582 |
luaopen_string(luaState); |
|
583 |
luaopen_math(luaState); |
|
584 |
||
585 |
// import some variables |
|
586 |
ScriptSetInteger('LAND_WIDTH', LAND_WIDTH); |
|
587 |
ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT); |
|
588 |
||
589 |
// import game flags |
|
2949 | 590 |
ScriptSetInteger('gfForts', gfForts); |
591 |
ScriptSetInteger('gfMultiWeapon', gfMultiWeapon); |
|
592 |
ScriptSetInteger('gfSolidLand', gfSolidLand); |
|
593 |
ScriptSetInteger('gfBorder', gfBorder); |
|
594 |
ScriptSetInteger('gfDivideTeams', gfDivideTeams); |
|
595 |
ScriptSetInteger('gfLowGravity', gfLowGravity); |
|
596 |
ScriptSetInteger('gfLaserSight', gfLaserSight); |
|
597 |
ScriptSetInteger('gfInvulnerable', gfInvulnerable); |
|
598 |
ScriptSetInteger('gfMines', gfMines); |
|
599 |
ScriptSetInteger('gfVampiric', gfVampiric); |
|
600 |
ScriptSetInteger('gfKarma', gfKarma); |
|
601 |
ScriptSetInteger('gfArtillery', gfArtillery); |
|
602 |
ScriptSetInteger('gfOneClanMode', gfOneClanMode); |
|
603 |
ScriptSetInteger('gfRandomOrder', gfRandomOrder); |
|
604 |
ScriptSetInteger('gfKing', gfKing); |
|
605 |
ScriptSetInteger('gfPlaceHog', gfPlaceHog); |
|
606 |
ScriptSetInteger('gfSharedAmmo', gfSharedAmmo); |
|
607 |
ScriptSetInteger('gfDisableGirders', gfDisableGirders); |
|
608 |
ScriptSetInteger('gfExplosives', gfExplosives); |
|
2786 | 609 |
|
610 |
// register gear types |
|
611 |
for at:= Low(TGearType) to High(TGearType) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
612 |
ScriptSetInteger(str(at), ord(at)); |
2786 | 613 |
|
614 |
// register sounds |
|
615 |
for st:= Low(TSound) to High(TSound) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
616 |
ScriptSetInteger(str(st), ord(st)); |
2786 | 617 |
|
618 |
// register ammo types |
|
619 |
for am:= Low(TAmmoType) to High(TAmmoType) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
620 |
ScriptSetInteger(str(am), ord(am)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
621 |
|
2786 | 622 |
// register functions |
623 |
lua_register(luaState, 'AddGear', @lc_addgear); |
|
624 |
lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole); |
|
625 |
lua_register(luaState, 'GetGearType', @lc_getgeartype); |
|
626 |
lua_register(luaState, 'EndGame', @lc_endgame); |
|
627 |
lua_register(luaState, 'FindPlace', @lc_findplace); |
|
628 |
lua_register(luaState, 'SetGearPosition', @lc_setgearposition); |
|
629 |
lua_register(luaState, 'GetGearPosition', @lc_getgearposition); |
|
630 |
lua_register(luaState, 'ParseCommand', @lc_parsecommand); |
|
631 |
lua_register(luaState, 'ShowMission', @lc_showmission); |
|
632 |
lua_register(luaState, 'HideMission', @lc_hidemission); |
|
633 |
lua_register(luaState, 'SetAmmo', @lc_setammo); |
|
634 |
lua_register(luaState, 'PlaySound', @lc_playsound); |
|
635 |
lua_register(luaState, 'AddTeam', @lc_addteam); |
|
636 |
lua_register(luaState, 'AddHog', @lc_addhog); |
|
2814 | 637 |
lua_register(luaState, 'SetHealth', @lc_sethealth); |
2999 | 638 |
lua_register(luaState, 'GetHogClan', @lc_gethogclan); |
639 |
lua_register(luaState, 'GetHogName', @lc_gethogname); |
|
2786 | 640 |
|
641 |
ScriptClearStack; // just to be sure stack is empty |
|
2793 | 642 |
ScriptLoaded:= false; |
2786 | 643 |
end; |
644 |
||
645 |
procedure free_uScript; |
|
646 |
begin |
|
647 |
lua_close(luaState); |
|
648 |
end; |
|
649 |
||
2798 | 650 |
{$ELSE} |
651 |
procedure ScriptPrintStack; |
|
652 |
begin |
|
653 |
end; |
|
654 |
||
655 |
procedure ScriptClearStack; |
|
656 |
begin |
|
657 |
end; |
|
658 |
||
2905 | 659 |
procedure ScriptLoad(name : shortstring); |
2798 | 660 |
begin |
661 |
end; |
|
662 |
||
663 |
procedure ScriptOnGameInit; |
|
664 |
begin |
|
665 |
end; |
|
666 |
||
2905 | 667 |
procedure ScriptCall(fname : shortstring); |
2798 | 668 |
begin |
669 |
end; |
|
670 |
||
2905 | 671 |
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; |
2798 | 672 |
begin |
2799 | 673 |
ScriptCall:= 0 |
674 |
end; |
|
675 |
||
2905 | 676 |
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
2799 | 677 |
begin |
678 |
ScriptCall:= 0 |
|
679 |
end; |
|
680 |
||
2905 | 681 |
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt; |
2799 | 682 |
begin |
683 |
ScriptCall:= 0 |
|
684 |
end; |
|
685 |
||
2905 | 686 |
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; |
2799 | 687 |
begin |
688 |
ScriptCall:= 0 |
|
2798 | 689 |
end; |
690 |
||
2999 | 691 |
function ScriptExists(fname : shortstring) : boolean; |
692 |
begin |
|
693 |
ScriptExists:= false |
|
694 |
end; |
|
695 |
||
2798 | 696 |
procedure init_uScript; |
697 |
begin |
|
698 |
end; |
|
699 |
||
700 |
procedure free_uScript; |
|
701 |
begin |
|
702 |
end; |
|
703 |
||
704 |
{$ENDIF} |
|
2786 | 705 |
end. |