author | unc0rr |
Sat, 06 Mar 2010 10:59:20 +0000 | |
changeset 2948 | 3f21a9dc93d0 |
parent 2924 | 908851e59958 |
child 2949 | d137a9da7701 |
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; |
|
2786 | 35 |
|
36 |
procedure init_uScript; |
|
37 |
procedure free_uScript; |
|
38 |
||
39 |
implementation |
|
2798 | 40 |
{$IFNDEF IPHONEOS} |
2786 | 41 |
uses LuaPas in 'LuaPas.pas', |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
42 |
uConsole, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
43 |
uMisc, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
44 |
uConsts, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
45 |
uGears, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
46 |
uFloat, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
47 |
uWorld, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
48 |
uAmmos, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
49 |
uSound, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
50 |
uTeams, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
51 |
uKeys, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
52 |
typinfo; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
53 |
|
2786 | 54 |
var luaState : Plua_State; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
55 |
ScriptAmmoStore : shortstring; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
56 |
ScriptLoaded : boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
57 |
|
2786 | 58 |
procedure ScriptPrepareAmmoStore; forward; |
59 |
procedure ScriptApplyAmmoStore; forward; |
|
60 |
procedure ScriptSetAmmo(ammo : TAmmoType; count, propability: Byte); forward; |
|
61 |
||
62 |
// wrapped calls // |
|
63 |
||
64 |
// functions called from lua: |
|
65 |
// function(L : Plua_State) : LongInt; Cdecl; |
|
66 |
// where L contains the state, returns the number of return values on the stack |
|
67 |
// call lua_gettop(L) to receive number of parameters passed |
|
68 |
||
69 |
function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; |
|
70 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
71 |
if lua_gettop(L) = 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
72 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
73 |
WriteLnToConsole('LUA: ' + lua_tostring(L ,1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
74 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
75 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
76 |
WriteLnToConsole('LUA: Wrong number of parameters passed to WriteLnToConsole!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
77 |
lc_writelntoconsole:= 0; |
2786 | 78 |
end; |
79 |
||
80 |
function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; |
|
81 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
82 |
if lua_gettop(L) = 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
83 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
84 |
ParseCommand(lua_tostring(L ,1), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
85 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
86 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
87 |
WriteLnToConsole('LUA: Wrong number of parameters passed to ParseCommand!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
88 |
lc_parsecommand:= 0; |
2786 | 89 |
end; |
90 |
||
91 |
function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
|
92 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
93 |
if lua_gettop(L) = 5 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
94 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
95 |
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
|
96 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
97 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
98 |
WriteLnToConsole('LUA: Wrong number of parameters passed to ShowMission!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
99 |
lc_showmission:= 0; |
2786 | 100 |
end; |
101 |
||
102 |
function lc_hidemission(L : Plua_State) : LongInt; Cdecl; |
|
103 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
104 |
HideMission; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
105 |
lc_hidemission:= 0; |
2786 | 106 |
end; |
107 |
||
108 |
function lc_addgear(L : Plua_State) : LongInt; Cdecl; |
|
109 |
var gear : PGear; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
110 |
x, y, s, t: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
111 |
dx, dy: hwFloat; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
112 |
gt: TGearType; |
2786 | 113 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
114 |
if lua_gettop(L) <> 7 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
115 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
116 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddGear!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
117 |
lua_pushnil(L); // return value on stack (nil) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
118 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
119 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
120 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
121 |
x:= lua_tointeger(L, 1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
122 |
y:= lua_tointeger(L, 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
123 |
gt:= TGearType(lua_tointeger(L, 3)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
124 |
s:= lua_tointeger(L, 4); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
125 |
dx:= int2hwFloat(round(lua_tonumber(L, 5) * 1000)) / 1000; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
126 |
dy:= int2hwFloat(round(lua_tonumber(L, 6) * 1000)) / 1000; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
127 |
t:= lua_tointeger(L, 7); |
2786 | 128 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
129 |
gear:= AddGear(x, y, gt, s, dx, dy, t); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
130 |
lua_pushnumber(L, gear^.uid) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
131 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
132 |
lc_addgear:= 1; // 1 return value |
2786 | 133 |
end; |
134 |
||
135 |
function lc_getgeartype(L : Plua_State) : LongInt; Cdecl; |
|
2790 | 136 |
var gear : PGear; |
2786 | 137 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
138 |
if lua_gettop(L) <> 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
139 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
140 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetGearType!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
141 |
lua_pushnil(L); // return value on stack (nil) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
142 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
143 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
144 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
145 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
146 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
147 |
lua_pushinteger(L, ord(gear^.Kind)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
148 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
149 |
lc_getgeartype:= 1 |
2786 | 150 |
end; |
151 |
||
2814 | 152 |
function lc_sethealth(L : Plua_State) : LongInt; Cdecl; |
153 |
var gear : PGear; |
|
154 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
155 |
if lua_gettop(L) <> 2 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
156 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
157 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetHealth!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
158 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
159 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
160 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
161 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
162 |
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
|
163 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
164 |
lc_sethealth:= 0 |
2814 | 165 |
end; |
166 |
||
2786 | 167 |
function lc_endgame(L : Plua_State) : LongInt; Cdecl; |
168 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
169 |
GameState:= gsExit; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
170 |
lc_endgame:= 0 |
2786 | 171 |
end; |
172 |
||
173 |
function lc_findplace(L : Plua_State) : LongInt; Cdecl; |
|
174 |
var gear: PGear; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
175 |
fall: boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
176 |
left, right: LongInt; |
2786 | 177 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
178 |
if lua_gettop(L) <> 4 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
179 |
WriteLnToConsole('LUA: Wrong number of parameters passed to FindPlace!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
180 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
181 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
182 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
183 |
fall:= lua_toboolean(L, 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
184 |
left:= lua_tointeger(L, 3); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
185 |
right:= lua_tointeger(L, 4); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
186 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
187 |
FindPlace(gear, fall, left, right) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
188 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
189 |
lc_findplace:= 0 |
2786 | 190 |
end; |
191 |
||
192 |
function lc_playsound(L : Plua_State) : LongInt; Cdecl; |
|
193 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
194 |
if lua_gettop(L) <> 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
195 |
WriteLnToConsole('LUA: Wrong number of parameters passed to PlaySound!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
196 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
197 |
PlaySound(TSound(lua_tointeger(L, 1))); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
198 |
lc_playsound:= 0; |
2786 | 199 |
end; |
200 |
||
201 |
function lc_addteam(L : Plua_State) : LongInt; Cdecl; |
|
202 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
203 |
if lua_gettop(L) <> 5 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
204 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
205 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddTeam!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
206 |
//lua_pushnil(L) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
207 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
208 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
209 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
210 |
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
|
211 |
ParseCommand('grave ' + lua_tostring(L, 3), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
212 |
ParseCommand('fort ' + lua_tostring(L, 4), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
213 |
ParseCommand('voicepack ' + lua_tostring(L, 5), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
214 |
CurrentTeam^.Binds:= DefaultBinds; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
215 |
// fails on x64 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
216 |
//lua_pushinteger(L, LongInt(CurrentTeam)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
217 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
218 |
lc_addteam:= 0;//1; |
2786 | 219 |
end; |
220 |
||
221 |
function lc_addhog(L : Plua_State) : LongInt; Cdecl; |
|
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 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
225 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddHog!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
226 |
lua_pushnil(L) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
227 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
228 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
229 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
230 |
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
|
231 |
ParseCommand('hat ' + lua_tostring(L, 4), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
232 |
lua_pushinteger(L, CurrentHedgehog^.Gear^.uid); |
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_addhog:= 1; |
2786 | 235 |
end; |
236 |
||
237 |
function lc_getgearposition(L : Plua_State) : LongInt; Cdecl; |
|
238 |
var gear: PGear; |
|
239 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
240 |
if lua_gettop(L) <> 1 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
241 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
242 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetGearPosition!'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
243 |
lua_pushnil(L); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
244 |
lua_pushnil(L) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
245 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
246 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
247 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
248 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
249 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
250 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
251 |
lua_pushinteger(L, hwRound(gear^.X)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
252 |
lua_pushinteger(L, hwRound(gear^.Y)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
253 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
254 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
255 |
lc_getgearposition:= 2; |
2786 | 256 |
end; |
257 |
||
258 |
function lc_setgearposition(L : Plua_State) : LongInt; Cdecl; |
|
259 |
var gear: PGear; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
260 |
x, y: LongInt; |
2786 | 261 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
262 |
if lua_gettop(L) <> 3 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
263 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetGearPosition!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
264 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
265 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
266 |
gear:= GearByUID(lua_tointeger(L, 1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
267 |
if gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
268 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
269 |
x:= lua_tointeger(L, 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
270 |
y:= lua_tointeger(L, 3); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
271 |
gear^.X:= int2hwfloat(x); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
272 |
gear^.Y:= int2hwfloat(y); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
273 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
274 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
275 |
lc_setgearposition:= 0 |
2786 | 276 |
end; |
277 |
||
278 |
function lc_setammo(L : Plua_State) : LongInt; Cdecl; |
|
279 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
280 |
if lua_gettop(L) <> 3 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
281 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetAmmo!') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
282 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
283 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
284 |
ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
285 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
286 |
lc_setammo:= 0 |
2786 | 287 |
end; |
288 |
/////////////////// |
|
289 |
||
290 |
procedure ScriptPrintStack; |
|
291 |
var n, i : LongInt; |
|
292 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
293 |
n:= lua_gettop(luaState); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
294 |
WriteLnToConsole('LUA: Stack (' + inttostr(n) + ' elements):'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
295 |
for i:= 1 to n do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
296 |
if not lua_isboolean(luaState, i) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
297 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': ' + lua_tostring(luaState, i)) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
298 |
else if lua_toboolean(luaState, i) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
299 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': true') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
300 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
301 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': false'); |
2786 | 302 |
end; |
303 |
||
304 |
procedure ScriptClearStack; |
|
305 |
begin |
|
306 |
lua_settop(luaState, 0) |
|
307 |
end; |
|
308 |
||
2905 | 309 |
procedure ScriptSetInteger(name : shortstring; value : LongInt); |
2786 | 310 |
begin |
311 |
lua_pushinteger(luaState, value); |
|
312 |
lua_setglobal(luaState, Str2PChar(name)); |
|
313 |
end; |
|
314 |
||
2905 | 315 |
procedure ScriptSetString(name : shortstring; value : shortstring); |
2786 | 316 |
begin |
317 |
lua_pushstring(luaState, Str2PChar(value)); |
|
318 |
lua_setglobal(luaState, Str2PChar(name)); |
|
319 |
end; |
|
320 |
||
2905 | 321 |
function ScriptGetInteger(name : shortstring) : LongInt; |
2786 | 322 |
begin |
323 |
lua_getglobal(luaState, Str2PChar(name)); |
|
324 |
ScriptGetInteger:= lua_tointeger(luaState, -1); |
|
325 |
lua_pop(luaState, 1); |
|
326 |
end; |
|
327 |
||
2905 | 328 |
function ScriptGetString(name : shortstring) : shortstring; |
2786 | 329 |
begin |
330 |
lua_getglobal(luaState, Str2PChar(name)); |
|
331 |
ScriptGetString:= lua_tostring(luaState, -1); |
|
332 |
lua_pop(luaState, 1); |
|
333 |
end; |
|
334 |
||
335 |
procedure ScriptOnGameInit; |
|
336 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
337 |
// not required if there's no script to run |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
338 |
if not ScriptLoaded then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
339 |
exit; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
340 |
|
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
341 |
// push game variables so they may be modified by the script |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
342 |
ScriptSetInteger('GameFlags', GameFlags); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
343 |
ScriptSetString('Seed', cSeed); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
344 |
ScriptSetInteger('TurnTime', cHedgehogTurnTime); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
345 |
ScriptSetInteger('CaseFreq', cCaseFactor); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
346 |
ScriptSetInteger('LandAdds', cLandAdditions); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
347 |
ScriptSetInteger('Delay', cInactDelay); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
348 |
ScriptSetString('Map', ''); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
349 |
ScriptSetString('Theme', ''); |
2786 | 350 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
351 |
ScriptCall('onGameInit'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
352 |
|
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
353 |
// pop game variables |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
354 |
ParseCommand('seed ' + ScriptGetString('Seed'), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
355 |
ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
356 |
ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
357 |
ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
358 |
ParseCommand('$landadds ' + ScriptGetString('LandAdds'), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
359 |
ParseCommand('$delay ' + ScriptGetString('Delay'), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
360 |
if ScriptGetString('Map') <> '' then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
361 |
ParseCommand('map ' + ScriptGetString('Map'), true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
362 |
if ScriptGetString('Theme') <> '' then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
363 |
ParseCommand('theme ' + ScriptGetString('Theme'), true); |
2786 | 364 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
365 |
ScriptPrepareAmmoStore; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
366 |
ScriptCall('onAmmoStoreInit'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
367 |
ScriptApplyAmmoStore; |
2786 | 368 |
end; |
369 |
||
2905 | 370 |
procedure ScriptLoad(name : shortstring); |
2786 | 371 |
var ret : LongInt; |
372 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
373 |
ret:= luaL_loadfile(luaState, Str2PChar(name)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
374 |
if ret <> 0 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
375 |
WriteLnToConsole('LUA: Failed to load ' + name + '(error ' + IntToStr(ret) + ')') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
376 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
377 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
378 |
WriteLnToConsole('LUA: ' + name + ' loaded'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
379 |
// call the script file |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
380 |
lua_pcall(luaState, 0, 0, 0); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
381 |
ScriptLoaded:= true |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
382 |
end |
2786 | 383 |
end; |
384 |
||
2814 | 385 |
procedure SetGlobals; |
386 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
387 |
ScriptSetInteger('TurnTimeLeft', TurnTimeLeft); |
2814 | 388 |
end; |
389 |
||
390 |
procedure GetGlobals; |
|
391 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
392 |
TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft'); |
2814 | 393 |
end; |
394 |
||
2905 | 395 |
procedure ScriptCall(fname : shortstring); |
2786 | 396 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
397 |
if not ScriptLoaded then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
398 |
exit; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
399 |
SetGlobals; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
400 |
lua_getglobal(luaState, Str2PChar(fname)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
401 |
if lua_pcall(luaState, 0, 0, 0) <> 0 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
402 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
403 |
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
404 |
lua_pop(luaState, 1) |
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 |
GetGlobals; |
2786 | 407 |
end; |
408 |
||
2905 | 409 |
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
2786 | 410 |
begin |
411 |
ScriptCall:= ScriptCall(fname, par1, 0, 0, 0) |
|
412 |
end; |
|
413 |
||
2905 | 414 |
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt; |
2786 | 415 |
begin |
416 |
ScriptCall:= ScriptCall(fname, par1, par2, 0, 0) |
|
417 |
end; |
|
418 |
||
2905 | 419 |
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; |
2786 | 420 |
begin |
421 |
ScriptCall:= ScriptCall(fname, par1, par2, par3, 0) |
|
422 |
end; |
|
423 |
||
2905 | 424 |
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; |
2786 | 425 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
426 |
if not ScriptLoaded then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
427 |
exit; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
428 |
SetGlobals; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
429 |
lua_getglobal(luaState, Str2PChar(fname)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
430 |
lua_pushinteger(luaState, par1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
431 |
lua_pushinteger(luaState, par2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
432 |
lua_pushinteger(luaState, par3); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
433 |
lua_pushinteger(luaState, par4); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
434 |
ScriptCall:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
435 |
if lua_pcall(luaState, 4, 1, 0) <> 0 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
436 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
437 |
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
438 |
lua_pop(luaState, 1) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
439 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
440 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
441 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
442 |
ScriptCall:= lua_tointeger(luaState, -1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
443 |
lua_pop(luaState, 1) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
444 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
445 |
GetGlobals; |
2786 | 446 |
end; |
447 |
||
448 |
procedure ScriptPrepareAmmoStore; |
|
449 |
var i: ShortInt; |
|
450 |
begin |
|
451 |
ScriptAmmoStore:= ''; |
|
452 |
for i:=1 to ord(High(TAmmoType)) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
453 |
ScriptAmmoStore:= ScriptAmmoStore + '0000'; |
2786 | 454 |
end; |
455 |
||
456 |
procedure ScriptSetAmmo(ammo : TAmmoType; count, propability: Byte); |
|
457 |
begin |
|
458 |
if (ord(ammo) < 1) or (count > 9) or (count < 0) or (propability < 0) or (propability > 8) then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
459 |
exit; |
2786 | 460 |
ScriptAmmoStore[ord(ammo)]:= inttostr(count)[1]; |
461 |
ScriptAmmoStore[ord(ammo) + ord(high(TAmmoType))]:= inttostr(propability)[1]; |
|
462 |
end; |
|
463 |
||
464 |
procedure ScriptApplyAmmoStore; |
|
465 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
466 |
AddAmmoStore(ScriptAmmoStore); |
2786 | 467 |
end; |
468 |
||
469 |
// small helper functions making registering enums a lot easier |
|
2905 | 470 |
function str(const en : TGearType) : shortstring; overload; |
2786 | 471 |
begin |
472 |
str:= GetEnumName(TypeInfo(TGearType), ord(en)) |
|
473 |
end; |
|
474 |
||
2905 | 475 |
function str(const en : TSound) : shortstring; overload; |
2786 | 476 |
begin |
477 |
str:= GetEnumName(TypeInfo(TSound), ord(en)) |
|
478 |
end; |
|
479 |
||
2905 | 480 |
function str(const en : TAmmoType) : shortstring; overload; |
2786 | 481 |
begin |
482 |
str:= GetEnumName(TypeInfo(TAmmoType), ord(en)) |
|
483 |
end; |
|
484 |
/////////////////// |
|
485 |
||
486 |
procedure init_uScript; |
|
487 |
var at : TGearType; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
488 |
am : TAmmoType; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
489 |
st : TSound; |
2786 | 490 |
begin |
491 |
// initialize lua |
|
492 |
luaState:= lua_open; |
|
493 |
||
494 |
// open internal libraries |
|
495 |
luaopen_base(luaState); |
|
496 |
luaopen_string(luaState); |
|
497 |
luaopen_math(luaState); |
|
498 |
||
499 |
// import some variables |
|
500 |
ScriptSetInteger('LAND_WIDTH', LAND_WIDTH); |
|
501 |
ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT); |
|
502 |
||
503 |
// import game flags |
|
504 |
ScriptSetInteger('gfForts',gfForts); |
|
505 |
ScriptSetInteger('gfMultiWeapon',gfMultiWeapon); |
|
506 |
ScriptSetInteger('gfSolidLand',gfSolidLand); |
|
507 |
ScriptSetInteger('gfBorder',gfBorder); |
|
508 |
ScriptSetInteger('gfDivideTeams',gfDivideTeams); |
|
509 |
ScriptSetInteger('gfLowGravity',gfLowGravity); |
|
510 |
ScriptSetInteger('gfLaserSight',gfLaserSight); |
|
511 |
ScriptSetInteger('gfInvulnerable',gfInvulnerable); |
|
512 |
ScriptSetInteger('gfMines',gfMines); |
|
513 |
ScriptSetInteger('gfVampiric',gfVampiric); |
|
514 |
ScriptSetInteger('gfKarma',gfKarma); |
|
515 |
ScriptSetInteger('gfArtillery',gfArtillery); |
|
516 |
ScriptSetInteger('gfOneClanMode',gfOneClanMode); |
|
517 |
ScriptSetInteger('gfRandomOrder',gfRandomOrder); |
|
518 |
ScriptSetInteger('gfKing',gfKing); |
|
519 |
||
520 |
// register gear types |
|
521 |
for at:= Low(TGearType) to High(TGearType) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
522 |
ScriptSetInteger(str(at), ord(at)); |
2786 | 523 |
|
524 |
// register sounds |
|
525 |
for st:= Low(TSound) to High(TSound) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
526 |
ScriptSetInteger(str(st), ord(st)); |
2786 | 527 |
|
528 |
// register ammo types |
|
529 |
for am:= Low(TAmmoType) to High(TAmmoType) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
530 |
ScriptSetInteger(str(am), ord(am)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2924
diff
changeset
|
531 |
|
2786 | 532 |
// register functions |
533 |
lua_register(luaState, 'AddGear', @lc_addgear); |
|
534 |
lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole); |
|
535 |
lua_register(luaState, 'GetGearType', @lc_getgeartype); |
|
536 |
lua_register(luaState, 'EndGame', @lc_endgame); |
|
537 |
lua_register(luaState, 'FindPlace', @lc_findplace); |
|
538 |
lua_register(luaState, 'SetGearPosition', @lc_setgearposition); |
|
539 |
lua_register(luaState, 'GetGearPosition', @lc_getgearposition); |
|
540 |
lua_register(luaState, 'ParseCommand', @lc_parsecommand); |
|
541 |
lua_register(luaState, 'ShowMission', @lc_showmission); |
|
542 |
lua_register(luaState, 'HideMission', @lc_hidemission); |
|
543 |
lua_register(luaState, 'SetAmmo', @lc_setammo); |
|
544 |
lua_register(luaState, 'PlaySound', @lc_playsound); |
|
545 |
lua_register(luaState, 'AddTeam', @lc_addteam); |
|
546 |
lua_register(luaState, 'AddHog', @lc_addhog); |
|
2814 | 547 |
lua_register(luaState, 'SetHealth', @lc_sethealth); |
2786 | 548 |
|
549 |
ScriptClearStack; // just to be sure stack is empty |
|
2793 | 550 |
ScriptLoaded:= false; |
2786 | 551 |
end; |
552 |
||
553 |
procedure free_uScript; |
|
554 |
begin |
|
555 |
lua_close(luaState); |
|
556 |
end; |
|
557 |
||
2798 | 558 |
{$ELSE} |
559 |
procedure ScriptPrintStack; |
|
560 |
begin |
|
561 |
end; |
|
562 |
||
563 |
procedure ScriptClearStack; |
|
564 |
begin |
|
565 |
end; |
|
566 |
||
2905 | 567 |
procedure ScriptLoad(name : shortstring); |
2798 | 568 |
begin |
569 |
end; |
|
570 |
||
571 |
procedure ScriptOnGameInit; |
|
572 |
begin |
|
573 |
end; |
|
574 |
||
2905 | 575 |
procedure ScriptCall(fname : shortstring); |
2798 | 576 |
begin |
577 |
end; |
|
578 |
||
2905 | 579 |
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; |
2798 | 580 |
begin |
2799 | 581 |
ScriptCall:= 0 |
582 |
end; |
|
583 |
||
2905 | 584 |
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
2799 | 585 |
begin |
586 |
ScriptCall:= 0 |
|
587 |
end; |
|
588 |
||
2905 | 589 |
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt; |
2799 | 590 |
begin |
591 |
ScriptCall:= 0 |
|
592 |
end; |
|
593 |
||
2905 | 594 |
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt; |
2799 | 595 |
begin |
596 |
ScriptCall:= 0 |
|
2798 | 597 |
end; |
598 |
||
599 |
procedure init_uScript; |
|
600 |
begin |
|
601 |
end; |
|
602 |
||
603 |
procedure free_uScript; |
|
604 |
begin |
|
605 |
end; |
|
606 |
||
607 |
{$ENDIF} |
|
2786 | 608 |
end. |