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