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