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