hedgewars/uScript.pas
author smxx
Wed, 10 Feb 2010 09:52:00 +0000
changeset 2790 83630d5f94db
parent 2786 85f6425a4d74
child 2791 ac4b69e5f9f7
permissions -rw-r--r--
Engine: * Identify gears in Lua using their unique id instead of their pointer address - this should keep training from crashing on x64 platforms * Removed obsolete script call to "onTeamSetup" even before any script is loaded
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
     1
(*
85f6425a4d74 Engine:
smxx
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
85f6425a4d74 Engine:
smxx
parents:
diff changeset
     3
 * Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com>
85f6425a4d74 Engine:
smxx
parents:
diff changeset
     4
 *
85f6425a4d74 Engine:
smxx
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
85f6425a4d74 Engine:
smxx
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
85f6425a4d74 Engine:
smxx
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
85f6425a4d74 Engine:
smxx
parents:
diff changeset
     8
 *
85f6425a4d74 Engine:
smxx
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    12
 * GNU General Public License for more details.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    13
 *
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    17
 *)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    18
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    20
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    21
unit uScript;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    22
interface
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    23
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    24
procedure ScriptPrintStack;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    25
procedure ScriptClearStack;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    26
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    27
procedure ScriptLoad(name : string);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    28
procedure ScriptOnGameInit;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    29
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    30
procedure ScriptCall(fname : string);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    31
function ScriptCall(fname : string; par1: LongInt) : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    32
function ScriptCall(fname : string; par1, par2: LongInt) : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    33
function ScriptCall(fname : string; par1, par2, par3: LongInt) : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    34
function ScriptCall(fname : string; par1, par2, par3, par4 : LongInt) : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    35
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    36
procedure init_uScript;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    37
procedure free_uScript;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    38
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    39
implementation
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    40
uses LuaPas in 'LuaPas.pas',
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    41
	uConsole,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    42
	uMisc,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    43
	uConsts,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    44
	uGears,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    45
	uFloat,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    46
	uWorld,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    47
	uAmmos,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    48
	uSound,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    49
	uTeams,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    50
	uKeys,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    51
	typinfo;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    52
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    53
var luaState : Plua_State;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    54
	ScriptAmmoStore : string;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    55
	
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    56
procedure ScriptPrepareAmmoStore; forward;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    57
procedure ScriptApplyAmmoStore; forward;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    58
procedure ScriptSetAmmo(ammo : TAmmoType; count, propability: Byte); forward;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    59
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    60
// wrapped calls //
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    61
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    62
// functions called from lua:
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    63
// function(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    64
// where L contains the state, returns the number of return values on the stack
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    65
// call lua_gettop(L) to receive number of parameters passed
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    66
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    67
function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    68
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    69
	if lua_gettop(L) = 1 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    70
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    71
		WriteLnToConsole('LUA: ' + lua_tostring(L ,1));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    72
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    73
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    74
		AddFileLog('LUA: Wrong number of parameters passed to WriteLnToConsole!');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    75
	lc_writelntoconsole:= 0;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    76
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    77
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    78
function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    79
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    80
	if lua_gettop(L) = 1 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    81
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    82
		ParseCommand(lua_tostring(L ,1), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    83
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    84
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    85
		AddFileLog('LUA: Wrong number of parameters passed to ParseCommand!');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    86
	lc_parsecommand:= 0;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    87
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    88
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    89
function lc_showmission(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    90
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    91
	if lua_gettop(L) = 5 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    92
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    93
		ShowMission(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    94
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    95
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    96
		AddFileLog('LUA: Wrong number of parameters passed to ShowMission!');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    97
	lc_showmission:= 0;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    98
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    99
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   100
function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   101
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   102
	HideMission;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   103
	lc_hidemission:= 0;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   104
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   105
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   106
function lc_addgear(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   107
var gear : PGear;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   108
	x, y, s, t: LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   109
	dx, dy: hwFloat;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   110
	gt: TGearType;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   111
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   112
	if lua_gettop(L) <> 7 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   113
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   114
		AddFileLog('LUA: Wrong number of parameters passed to AddGear!');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   115
		lua_pushnil(L); // return value on stack (nil)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   116
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   117
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   118
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   119
		x:= lua_tointeger(L, 1);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   120
		y:= lua_tointeger(L, 2);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   121
		gt:= TGearType(lua_tointeger(L, 3));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   122
		s:= lua_tointeger(L, 4);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   123
		dx:= int2hwFloat(round(lua_tonumber(L, 5) * 1000)) / 1000;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   124
		dy:= int2hwFloat(round(lua_tonumber(L, 6) * 1000)) / 1000;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   125
		t:= lua_tointeger(L, 7);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   126
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   127
		gear:= AddGear(x, y, gt, s, dx, dy, t);
2790
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   128
		lua_pushnumber(L, gear^.uid)
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   129
		end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   130
	lc_addgear:= 1; // 1 return value
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   131
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   132
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   133
function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
2790
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   134
var gear : PGear;
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   135
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   136
	if lua_gettop(L) <> 1 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   137
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   138
		AddFileLog('LUA: Wrong number of parameters passed to GetGearType!');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   139
		lua_pushnil(L); // return value on stack (nil)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   140
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   141
	else
2790
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   142
		begin
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   143
		gear:= GearByUID(lua_tointeger(L, 1));
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   144
		if gear <> nil then
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   145
			lua_pushinteger(L, ord(gear^.Kind))
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   146
		end;
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   147
	lc_getgeartype:= 1
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   148
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   149
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   150
function lc_endgame(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   151
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   152
	GameState:= gsExit;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   153
	lc_endgame:= 0
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   154
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   155
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   156
function lc_findplace(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   157
var gear: PGear;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   158
	fall: boolean;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   159
	left, right: LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   160
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   161
	if lua_gettop(L) <> 4 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   162
		AddFileLog('LUA: Wrong number of parameters passed to FindPlace!')
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   163
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   164
		begin
2790
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   165
		gear:= GearByUID(lua_tointeger(L, 1));
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   166
		fall:= lua_toboolean(L, 2);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   167
		left:= lua_tointeger(L, 3);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   168
		right:= lua_tointeger(L, 4);
2790
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   169
		if gear <> nil then
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   170
			FindPlace(gear, fall, left, right)
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   171
		end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   172
	lc_findplace:= 0
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   173
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   174
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   175
function lc_playsound(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   176
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   177
	if lua_gettop(L) <> 1 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   178
		AddFileLog('LUA: Wrong number of parameters passed to PlaySound!')
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   179
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   180
		PlaySound(TSound(lua_tointeger(L, 1)));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   181
	lc_playsound:= 0;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   182
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   183
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   184
function lc_addteam(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   185
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   186
	if lua_gettop(L) <> 5 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   187
		AddFileLog('LUA: Wrong number of parameters passed to AddTeam!')
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   188
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   189
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   190
		ParseCommand('addteam ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   191
		ParseCommand('grave ' + lua_tostring(L, 3), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   192
		ParseCommand('fort ' + lua_tostring(L, 4), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   193
		ParseCommand('voicepack ' + lua_tostring(L, 5), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   194
		CurrentTeam^.Binds:= DefaultBinds;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   195
		lua_pushinteger(L, LongInt(CurrentTeam));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   196
		end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   197
	lc_addteam:= 1;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   198
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   199
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   200
function lc_addhog(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   201
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   202
	if lua_gettop(L) <> 4 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   203
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   204
		AddFileLog('LUA: Wrong number of parameters passed to AddHog!');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   205
		lua_pushnil(L)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   206
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   207
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   208
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   209
		ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   210
		ParseCommand('hat ' + lua_tostring(L, 4), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   211
		WriteLnToConsole('last hog: ' + inttostr(LongInt(CurrentHedgehog)));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   212
		lua_pushinteger(L, LongInt(CurrentHedgehog^.Gear));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   213
		end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   214
	lc_addhog:= 1;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   215
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   216
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   217
function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   218
var gear: PGear;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   219
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   220
	if lua_gettop(L) <> 1 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   221
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   222
		AddFileLog('LUA: Wrong number of parameters passed to GetGearPosition!');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   223
		lua_pushnil(L);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   224
		lua_pushnil(L)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   225
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   226
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   227
		begin
2790
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   228
		gear:= GearByUID(lua_tointeger(L, 1));
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   229
		if gear <> nil then
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   230
			begin
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   231
			lua_pushinteger(L, hwRound(gear^.X));
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   232
			lua_pushinteger(L, hwRound(gear^.Y))
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   233
			end
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   234
		end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   235
	lc_getgearposition:= 2;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   236
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   237
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   238
function lc_setgearposition(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   239
var gear: PGear;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   240
	x, y: LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   241
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   242
	if lua_gettop(L) <> 3 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   243
		AddFileLog('LUA: Wrong number of parameters passed to SetGearPosition!')
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   244
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   245
		begin
2790
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   246
		gear:= GearByUID(lua_tointeger(L, 1));
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   247
		if gear <> nil then
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   248
			begin
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   249
			x:= lua_tointeger(L, 2);
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   250
			y:= lua_tointeger(L, 3);
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   251
			gear^.X:= int2hwfloat(x);
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   252
			gear^.Y:= int2hwfloat(y);
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
   253
			end
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   254
		end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   255
	lc_setgearposition:= 0
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   256
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   257
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   258
function lc_setammo(L : Plua_State) : LongInt; Cdecl;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   259
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   260
	if lua_gettop(L) <> 3 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   261
		AddFileLog('LUA: Wrong number of parameters passed to SetAmmo!')
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   262
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   263
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   264
		ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   265
		end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   266
	lc_setammo:= 0
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   267
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   268
///////////////////
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   269
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   270
procedure ScriptPrintStack;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   271
var n, i : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   272
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   273
	n:= lua_gettop(luaState);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   274
	AddFileLog('LUA: Stack (' + inttostr(n) + ' elements):');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   275
	for i:= 1 to n do
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   276
		if not lua_isboolean(luaState, i) then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   277
			AddFileLog('LUA:  ' + inttostr(i) + ': ' + lua_tostring(luaState, i))
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   278
		else if lua_toboolean(luaState, i) then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   279
			AddFileLog('LUA:  ' + inttostr(i) + ': true')
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   280
		else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   281
			AddFileLog('LUA:  ' + inttostr(i) + ': false');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   282
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   283
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   284
procedure ScriptClearStack;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   285
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   286
lua_settop(luaState, 0)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   287
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   288
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   289
procedure ScriptSetInteger(name : string; value : LongInt);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   290
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   291
lua_pushinteger(luaState, value);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   292
lua_setglobal(luaState, Str2PChar(name));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   293
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   294
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   295
procedure ScriptSetString(name : string; value : string);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   296
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   297
lua_pushstring(luaState, Str2PChar(value));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   298
lua_setglobal(luaState, Str2PChar(name));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   299
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   300
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   301
function ScriptGetInteger(name : string) : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   302
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   303
lua_getglobal(luaState, Str2PChar(name));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   304
ScriptGetInteger:= lua_tointeger(luaState, -1);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   305
lua_pop(luaState, 1);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   306
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   307
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   308
function ScriptGetString(name : string) : string;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   309
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   310
lua_getglobal(luaState, Str2PChar(name));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   311
ScriptGetString:= lua_tostring(luaState, -1);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   312
lua_pop(luaState, 1);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   313
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   314
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   315
procedure ScriptOnGameInit;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   316
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   317
		// push game variables so they may be modified by the script
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   318
		ScriptSetInteger('GameFlags', GameFlags);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   319
		ScriptSetString('Seed', cSeed);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   320
		ScriptSetInteger('TurnTime', cHedgehogTurnTime);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   321
		ScriptSetInteger('CaseFreq', cCaseFactor);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   322
		ScriptSetInteger('LandAdds', cLandAdditions);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   323
		ScriptSetInteger('Delay', cInactDelay);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   324
		ScriptSetString('Map', '');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   325
		ScriptSetString('Theme', '');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   326
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   327
		ScriptCall('onGameInit');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   328
		
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   329
		// pop game variables
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   330
		ParseCommand('seed ' + ScriptGetString('Seed'), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   331
		ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   332
		ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   333
		ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   334
		ParseCommand('$landadds ' + ScriptGetString('LandAdds'), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   335
		ParseCommand('$delay ' + ScriptGetString('Delay'), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   336
		if ScriptGetString('Map') <> '' then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   337
			ParseCommand('map ' + ScriptGetString('Map'), true);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   338
		if ScriptGetString('Theme') <> '' then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   339
			ParseCommand('theme ' + ScriptGetString('Theme'), true);	
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   340
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   341
	ScriptPrepareAmmoStore;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   342
	ScriptCall('onAmmoStoreInit');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   343
	ScriptApplyAmmoStore;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   344
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   345
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   346
procedure ScriptLoad(name : string);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   347
var ret : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   348
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   349
	ret:= luaL_loadfile(luaState, Str2PChar(name));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   350
	if ret <> 0 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   351
		AddFileLog('LUA: Failed to load ' + name + '(error ' + IntToStr(ret) + ')')
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   352
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   353
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   354
		AddFileLog('LUA: ' + name + ' loaded');
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   355
		// call the script file
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   356
		lua_pcall(luaState, 0, 0, 0);	
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   357
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   358
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   359
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   360
procedure ScriptCall(fname : string);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   361
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   362
	lua_getglobal(luaState, Str2PChar(fname));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   363
	if lua_pcall(luaState, 0, 0, 0) <> 0 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   364
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   365
		AddFileLog('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   366
		lua_pop(luaState, 1)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   367
		end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   368
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   369
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   370
function ScriptCall(fname : string; par1: LongInt) : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   371
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   372
ScriptCall:= ScriptCall(fname, par1, 0, 0, 0)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   373
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   374
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   375
function ScriptCall(fname : string; par1, par2: LongInt) : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   376
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   377
ScriptCall:= ScriptCall(fname, par1, par2, 0, 0)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   378
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   379
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   380
function ScriptCall(fname : string; par1, par2, par3: LongInt) : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   381
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   382
ScriptCall:= ScriptCall(fname, par1, par2, par3, 0)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   383
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   384
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   385
function ScriptCall(fname : string; par1, par2, par3, par4 : LongInt) : LongInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   386
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   387
	lua_getglobal(luaState, Str2PChar(fname));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   388
	lua_pushinteger(luaState, par1);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   389
	lua_pushinteger(luaState, par2);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   390
	lua_pushinteger(luaState, par3);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   391
	lua_pushinteger(luaState, par4);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   392
	ScriptCall:= 0;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   393
	if lua_pcall(luaState, 4, 1, 0) <> 0 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   394
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   395
		AddFileLog('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   396
		lua_pop(luaState, 1)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   397
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   398
	else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   399
		begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   400
		ScriptCall:= lua_tointeger(luaState, -1);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   401
		lua_pop(luaState, 1)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   402
		end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   403
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   404
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   405
procedure ScriptPrepareAmmoStore;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   406
var i: ShortInt;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   407
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   408
ScriptAmmoStore:= '';
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   409
for i:=1 to ord(High(TAmmoType)) do
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   410
	ScriptAmmoStore:= ScriptAmmoStore + '00';
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   411
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   412
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   413
procedure ScriptSetAmmo(ammo : TAmmoType; count, propability: Byte);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   414
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   415
if (ord(ammo) < 1) or (count > 9) or (count < 0) or (propability < 0) or (propability > 8) then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   416
	exit;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   417
ScriptAmmoStore[ord(ammo)]:= inttostr(count)[1];
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   418
ScriptAmmoStore[ord(ammo) + ord(high(TAmmoType))]:= inttostr(propability)[1];
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   419
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   420
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   421
procedure ScriptApplyAmmoStore;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   422
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   423
	AddAmmoStore(ScriptAmmoStore);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   424
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   425
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   426
// small helper functions making registering enums a lot easier
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   427
function str(const en : TGearType) : string; overload;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   428
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   429
str:= GetEnumName(TypeInfo(TGearType), ord(en))
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   430
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   431
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   432
function str(const en : TSound) : string; overload;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   433
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   434
str:= GetEnumName(TypeInfo(TSound), ord(en))
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   435
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   436
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   437
function str(const en : TAmmoType) : string; overload;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   438
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   439
str:= GetEnumName(TypeInfo(TAmmoType), ord(en))
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   440
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   441
///////////////////
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   442
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   443
procedure init_uScript;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   444
var at : TGearType;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   445
	am : TAmmoType;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   446
	st : TSound;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   447
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   448
// initialize lua
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   449
luaState:= lua_open;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   450
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   451
// open internal libraries
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   452
luaopen_base(luaState);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   453
luaopen_string(luaState);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   454
luaopen_math(luaState);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   455
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   456
// import some variables
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   457
ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   458
ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   459
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   460
// import game flags
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   461
ScriptSetInteger('gfForts',gfForts);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   462
ScriptSetInteger('gfMultiWeapon',gfMultiWeapon);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   463
ScriptSetInteger('gfSolidLand',gfSolidLand);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   464
ScriptSetInteger('gfBorder',gfBorder);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   465
ScriptSetInteger('gfDivideTeams',gfDivideTeams);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   466
ScriptSetInteger('gfLowGravity',gfLowGravity);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   467
ScriptSetInteger('gfLaserSight',gfLaserSight);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   468
ScriptSetInteger('gfInvulnerable',gfInvulnerable);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   469
ScriptSetInteger('gfMines',gfMines);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   470
ScriptSetInteger('gfVampiric',gfVampiric);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   471
ScriptSetInteger('gfKarma',gfKarma);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   472
ScriptSetInteger('gfArtillery',gfArtillery);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   473
ScriptSetInteger('gfOneClanMode',gfOneClanMode);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   474
ScriptSetInteger('gfRandomOrder',gfRandomOrder);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   475
ScriptSetInteger('gfKing',gfKing);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   476
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   477
// register gear types
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   478
for at:= Low(TGearType) to High(TGearType) do
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   479
	ScriptSetInteger(str(at), ord(at));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   480
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   481
// register sounds
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   482
for st:= Low(TSound) to High(TSound) do
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   483
	ScriptSetInteger(str(st), ord(st));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   484
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   485
// register ammo types
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   486
for am:= Low(TAmmoType) to High(TAmmoType) do
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   487
	ScriptSetInteger(str(am), ord(am));
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   488
	
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   489
// register functions
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   490
lua_register(luaState, 'AddGear', @lc_addgear);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   491
lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   492
lua_register(luaState, 'GetGearType', @lc_getgeartype);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   493
lua_register(luaState, 'EndGame', @lc_endgame);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   494
lua_register(luaState, 'FindPlace', @lc_findplace);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   495
lua_register(luaState, 'SetGearPosition', @lc_setgearposition);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   496
lua_register(luaState, 'GetGearPosition', @lc_getgearposition);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   497
lua_register(luaState, 'ParseCommand', @lc_parsecommand);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   498
lua_register(luaState, 'ShowMission', @lc_showmission);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   499
lua_register(luaState, 'HideMission', @lc_hidemission);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   500
lua_register(luaState, 'SetAmmo', @lc_setammo);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   501
lua_register(luaState, 'PlaySound', @lc_playsound);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   502
lua_register(luaState, 'AddTeam', @lc_addteam);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   503
lua_register(luaState, 'AddHog', @lc_addhog);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   504
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   505
ScriptClearStack; // just to be sure stack is empty
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   506
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   507
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   508
procedure free_uScript;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   509
begin
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   510
lua_close(luaState);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   511
end;
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   512
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   513
end.