hedgewars/uScript.pas
author unc0rr
Sun, 16 Feb 2014 22:51:25 +0400
changeset 10143 3636106f5b70
parent 10131 4b4a043111f4
child 10150 fa5c83fd0ad9
permissions -rw-r--r--
Fix setting lc_endluatest result
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
     1
(*
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
     2
 * Hedgewars, a free turn based strategy game
9998
736015b847e3 update copyright to 2014
sheepluva
parents: 9988
diff changeset
     3
 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
     4
 *
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
     8
 *
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    12
 * GNU General Public License for more details.
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    13
 *
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    14
 * You should have received a copy of the GNU General Public License
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 10078
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    17
 *)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    18
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    19
{$INCLUDE "options.inc"}
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    20
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    21
unit uScript;
5124
84267f79879b comments
sheepluva
parents: 5120
diff changeset
    22
(*
84267f79879b comments
sheepluva
parents: 5120
diff changeset
    23
 * This unit defines, implements and registers functions and
84267f79879b comments
sheepluva
parents: 5120
diff changeset
    24
 * variables/constants bindings for usage in Lua scripts.
84267f79879b comments
sheepluva
parents: 5120
diff changeset
    25
 *
84267f79879b comments
sheepluva
parents: 5120
diff changeset
    26
 * Please keep http://code.google.com/p/hedgewars/wiki/LuaAPI up to date!
84267f79879b comments
sheepluva
parents: 5120
diff changeset
    27
 *
84267f79879b comments
sheepluva
parents: 5120
diff changeset
    28
 * Note: If you add a new function, make sure to test if _all_ parameters
84267f79879b comments
sheepluva
parents: 5120
diff changeset
    29
 *       work as intended! (Especially conversions errors can sneak in
84267f79879b comments
sheepluva
parents: 5120
diff changeset
    30
 *       unnoticed and render the parameter useless!)
84267f79879b comments
sheepluva
parents: 5120
diff changeset
    31
 *)
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    32
interface
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    33
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    34
procedure ScriptPrintStack;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    35
procedure ScriptClearStack;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    36
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    37
procedure ScriptLoad(name : shortstring);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    38
procedure ScriptOnGameInit;
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
    39
procedure ScriptOnScreenResize;
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
    40
procedure ScriptSetInteger(name : shortstring; value : LongInt);
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9917
diff changeset
    41
procedure ScriptSetString(name : shortstring; value : shortstring);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    42
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    43
procedure ScriptCall(fname : shortstring);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    44
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    45
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    46
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    47
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    48
function ScriptExists(fname : shortstring) : boolean;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    49
5410
8e7787065e2d small fix to have LUA_DISABLED working again
Xeli
parents: 5366
diff changeset
    50
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
    51
//function ParseCommandOverride(key, value : shortstring) : shortstring;  This did not work out well
5577
Xeli
parents: 5548 5554
diff changeset
    52
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    53
procedure initModule;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    54
procedure freeModule;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    55
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    56
implementation
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
    57
{$IFDEF USE_LUA_SCRIPT}
9205
abce6011f86c aaaaand let's not forget about lua, which has also a slightly revised build process
koda
parents: 9180
diff changeset
    58
6453
11c578d30bd3 Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents: 6430
diff changeset
    59
uses LuaPas,
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    60
    uConsole,
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    61
    uConsts,
6543
697e9b730189 Fix build
unc0rr
parents: 6529
diff changeset
    62
    uGears,
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents: 6453
diff changeset
    63
    uGearsList,
6543
697e9b730189 Fix build
unc0rr
parents: 6529
diff changeset
    64
    uGearsUtils,
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    65
    uFloat,
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    66
    uWorld,
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    67
    uAmmos,
6763
8a06161ede49 Recount team health if modifying hedgehog health
nemo
parents: 6752
diff changeset
    68
    uTeams,
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    69
    uSound,
4235
6b1dfbd60a45 added TeamsCount and TotalTurns to lua as requested by mikade
Henek
parents: 4221
diff changeset
    70
    uChat,
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
    71
    uStats,
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
    72
    uStore,
4357
a1fcfc341a52 Introduce unit uTypes in order to remove some cyclic unit dependencies
unC0Rr
parents: 4319
diff changeset
    73
    uRandom,
4359
83ef50815535 Move variables from uMisc to uVariables
unC0Rr
parents: 4357
diff changeset
    74
    uTypes,
4373
fe0e3903bb9e Introduce uCommands.pas
unC0Rr
parents: 4372
diff changeset
    75
    uVariables,
4374
bcefeeabaa33 Move some stuff from uMisc to uUtils
unC0Rr
parents: 4373
diff changeset
    76
    uCommands,
4377
43945842da0c Haven't found a better place than uIO for OutError
unC0Rr
parents: 4374
diff changeset
    77
    uUtils,
4403
unc0rr
parents: 4399
diff changeset
    78
    uCaptions,
4832
e55e2b6f59b0 update collision in set gear position
nemo
parents: 4780
diff changeset
    79
    uDebug,
4889
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
    80
    uCollisions,
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
    81
    uRenderUtils,
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
    82
    uTextures,
4985
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
    83
    uLandGraphics,
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
    84
    SysUtils,
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
    85
    uIO,
9283
76e68c136a11 Refactoring: VGSHandlers.inc -> uVisualGearsHandlers.pas
unc0rr
parents: 9245
diff changeset
    86
    uVisualGearsList,
9285
8e8b908970c2 Refactoring: get rid of GSHandlers.inc
unc0rr
parents: 9283
diff changeset
    87
    uGearsHandlersMess,
9952
32f5982604f4 Fix build (no idea what's going on in this branch btw)
unc0rr
parents: 9950
diff changeset
    88
    uPhysFSLayer
10129
cd2a64a1f4aa - Pas2C: make use of 'external' function decorator
unc0rr
parents: 10127
diff changeset
    89
{$IFNDEF PAS2C}
9952
32f5982604f4 Fix build (no idea what's going on in this branch btw)
unc0rr
parents: 9950
diff changeset
    90
    , typinfo
9521
8054d9d775fd merge with latest defaul, fixing compiling with fpc, parsing and rendering with pas2c, some minor problems with compiling with clang
koda
parents: 9264 9409
diff changeset
    91
{$ENDIF}
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
    92
    ;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3539
diff changeset
    93
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    94
var luaState : Plua_State;
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
    95
    ScriptAmmoLoadout : shortstring;
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
    96
    ScriptAmmoProbability : shortstring;
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
    97
    ScriptAmmoDelay : shortstring;
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
    98
    ScriptAmmoReinforcement : shortstring;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    99
    ScriptLoaded : boolean;
9567
42bc1b58a242 This test is intended to avoid repeatedly calling 5 ScriptSetIntegers each script call, that won't ever change after the map is created.
nemo
parents: 9531
diff changeset
   100
    mapDims : boolean;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3539
diff changeset
   101
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   102
procedure ScriptPrepareAmmoStore; forward;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   103
procedure ScriptApplyAmmoStore; forward;
9750
8963312df207 fix misspelled variable name (cosmetic change)
sheepluva
parents: 9748
diff changeset
   104
procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward;
9751
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
   105
procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   106
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   107
procedure LuaError(s: shortstring);
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   108
begin
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   109
    WriteLnToConsole(s);
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   110
    AddChatString(#5 + s);
9988
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
   111
    if cTestLua then
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
   112
        halt(rtnTestLuaErr);
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   113
end;
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   114
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   115
procedure LuaParameterCountError(call, paramsyntax: shortstring; wrongcount: LongInt);
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   116
begin
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   117
    // TODO: i18n?
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   118
    LuaError('Lua: Wrong number of parameters (' + inttostr(wrongcount) + ') passed to ' + call + '!     syntax: ' + call + ' ( ' + paramsyntax + ' )');
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   119
end;
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   120
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   121
// wrapped calls //
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   122
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   123
// functions called from Lua:
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   124
// function(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   125
// where L contains the state, returns the number of return values on the stack
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   126
// call lua_gettop(L) to receive number of parameters passed
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   127
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   128
function lc_band(L: PLua_State): LongInt; Cdecl;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   129
begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   130
    if lua_gettop(L) <> 2 then
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   131
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   132
        LuaParameterCountError('band', 'value1, value2', lua_gettop(L));
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   133
        lua_pushnil(L);
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   134
        end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   135
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   136
        lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1));
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   137
    lc_band := 1;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   138
end;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   139
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   140
function lc_bor(L: PLua_State): LongInt; Cdecl;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   141
begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   142
    if lua_gettop(L) <> 2 then
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   143
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   144
        LuaParameterCountError('bor', 'value1, value2', lua_gettop(L));
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   145
        lua_pushnil(L);
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   146
        end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   147
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   148
        lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1));
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   149
    lc_bor := 1;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   150
end;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   151
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   152
function lc_bnot(L: PLua_State): LongInt; Cdecl;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   153
begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   154
    if lua_gettop(L) <> 1 then
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   155
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   156
        LuaParameterCountError('bnot', 'value', lua_gettop(L));
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   157
        lua_pushnil(L);
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   158
        end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   159
    else
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 8012
diff changeset
   160
        lua_pushinteger(L, (not lua_tointeger(L, 1)));
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   161
    lc_bnot := 1;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   162
end;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   163
6764
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   164
function lc_div(L: PLua_State): LongInt; Cdecl;
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   165
begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   166
    if lua_gettop(L) <> 2 then
6764
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   167
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   168
        LuaParameterCountError('div', 'dividend, divisor', lua_gettop(L));
6764
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   169
        lua_pushnil(L);
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   170
        end
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   171
    else
7135
4d863aadd0b2 Add onGameTick20 to try and encourage lua to be a bit more efficient. Rewrite Space Invasion to use it. Top speed of aliens is 25% higher now, although that could be changed, I kinda liked it. Change parameter order of div().
nemo
parents: 7072
diff changeset
   172
        lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2));
6764
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   173
    lc_div := 1;
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   174
end;
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   175
4523
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   176
function lc_getinputmask(L : Plua_State) : LongInt; Cdecl;
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   177
begin
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   178
    if lua_gettop(L) <> 0 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   179
        LuaParameterCountError('GetInputMask', '', lua_gettop(L))
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   180
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   181
        lua_pushinteger(L, InputMask);
4523
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   182
    lc_getinputmask:= 1
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   183
end;
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   184
4522
0f590eefd531 Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents: 4517
diff changeset
   185
function lc_setinputmask(L : Plua_State) : LongInt; Cdecl;
0f590eefd531 Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents: 4517
diff changeset
   186
begin
0f590eefd531 Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents: 4517
diff changeset
   187
    if lua_gettop(L) <> 1 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   188
        LuaParameterCountError('SetInputMask', 'mask', lua_gettop(L))
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   189
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   190
        InputMask:= lua_tointeger(L, 1);
4522
0f590eefd531 Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents: 4517
diff changeset
   191
    lc_setinputmask:= 0
0f590eefd531 Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents: 4517
diff changeset
   192
end;
0f590eefd531 Add an input mask for setting of gear messages. Intended for intercepting user messages. This is totally untested. I don't think it should desync but seriously needs a lot of testing. Esp the doPut behaviour.
nemo
parents: 4517
diff changeset
   193
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   194
function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   195
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   196
    if lua_gettop(L) = 1 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   197
        begin
5549
ccfb9b8ab9d1 sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents: 5547
diff changeset
   198
        WriteLnToConsole('Lua: ' + lua_tostring(L ,1));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   199
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   200
    else
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   201
        LuaParameterCountError('WriteLnToConsole', 'string', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   202
    lc_writelntoconsole:= 0;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   203
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   204
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   205
function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
7307
f830a65d6a6d This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents: 7270
diff changeset
   206
var t: PChar;
f830a65d6a6d This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents: 7270
diff changeset
   207
    i,c: LongWord;
f830a65d6a6d This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents: 7270
diff changeset
   208
    s: shortstring;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   209
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   210
    if lua_gettop(L) = 1 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   211
        begin
10131
4b4a043111f4 - pas2c recognizes typecasts in initialization expressions
unc0rr
parents: 10129
diff changeset
   212
        t:= lua_tolstring(L, 1, Psize_t(@c));
7307
f830a65d6a6d This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents: 7270
diff changeset
   213
f830a65d6a6d This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents: 7270
diff changeset
   214
        for i:= 1 to c do s[i]:= t[i-1];
f830a65d6a6d This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents: 7270
diff changeset
   215
        s[0]:= char(c);
f830a65d6a6d This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents: 7270
diff changeset
   216
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
   217
        ParseCommand(s, true, true);
7307
f830a65d6a6d This is necessary because commands can contain 0s, and StrPas used by LuaPas halts at the first 0. It might be necessary to change the base string handling.
nemo
parents: 7270
diff changeset
   218
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   219
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   220
    else
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   221
        LuaParameterCountError('ParseCommand', 'string', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   222
    lc_parsecommand:= 0;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   223
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   224
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   225
function lc_showmission(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   226
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   227
    if lua_gettop(L) = 5 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   228
        begin
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10122
diff changeset
   229
        ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   230
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   231
    else
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   232
        LuaParameterCountError('ShowMission', 'caption, subcaption, text, icon, time', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   233
    lc_showmission:= 0;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   234
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   235
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   236
function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   237
begin
3407
dcc129c4352e Engine:
smxx
parents: 3368
diff changeset
   238
    L:= L; // avoid compiler hint
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   239
    HideMission;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   240
    lc_hidemission:= 0;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   241
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   242
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   243
function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   244
var i : integer;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   245
begin
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   246
    if lua_gettop(L) = 0 then
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   247
        begin
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   248
        LuaParameterCountError('EnableGameFlags', '', lua_gettop(L));
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   249
        lua_pushnil(L);
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   250
        end
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   251
    else
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   252
        begin
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   253
            for i:= 1 to lua_gettop(L) do
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   254
                GameFlags := GameFlags or LongWord(lua_tointeger(L, i));
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   255
            ScriptSetInteger('GameFlags', GameFlags);
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   256
        end;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8368
diff changeset
   257
    lc_enablegameflags:= 0;
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   258
end;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   259
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   260
function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   261
var i : integer;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   262
begin
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   263
    if lua_gettop(L) = 0 then
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   264
        begin
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   265
        LuaParameterCountError('DisableGameFlags', '', lua_gettop(L));
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   266
        lua_pushnil(L);
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   267
        end
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   268
    else
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   269
        begin
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   270
        for i:= 1 to lua_gettop(L) do
10078
8572d1f8b2f0 Some love to pas2c
unc0rr
parents: 10040
diff changeset
   271
            GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i)));
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   272
        ScriptSetInteger('GameFlags', GameFlags);
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   273
        end;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8368
diff changeset
   274
    lc_disablegameflags:= 0;
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   275
end;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   276
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   277
function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   278
begin
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   279
    if lua_gettop(L) <> 0 then
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   280
        begin
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   281
        LuaParameterCountError('ClearGameFlags', '', lua_gettop(L));
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   282
        lua_pushnil(L);
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   283
        end
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   284
    else
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   285
        begin
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   286
        GameFlags:= 0;
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   287
        ScriptSetInteger('GameFlags', GameFlags);
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   288
        end;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8368
diff changeset
   289
    lc_cleargameflags:= 0;
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   290
end;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   291
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   292
function lc_getgameflag(L : Plua_State) : LongInt; Cdecl;
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   293
begin
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   294
    if lua_gettop(L) <> 1 then
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   295
        begin
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   296
        LuaParameterCountError('GetGameFlag', 'gameflag', lua_gettop(L));
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   297
        lua_pushnil(L);
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   298
        end
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   299
    else
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   300
        begin
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   301
        lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0));
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   302
        end;
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   303
    lc_getgameflag:= 1;
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   304
end;
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   305
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   306
function lc_addcaption(L : Plua_State) : LongInt; Cdecl;
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   307
begin
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   308
    if lua_gettop(L) = 1 then
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10122
diff changeset
   309
        AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage)
5118
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
   310
    else if lua_gettop(L) = 3 then
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   311
        begin
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10122
diff changeset
   312
        AddCaption(lua_tostringA(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(lua_tointeger(L, 3)));
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   313
        end
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   314
    else
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   315
        LuaParameterCountError('AddCaption', 'text[, color, captiongroup]', lua_gettop(L));
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   316
    lc_addcaption:= 0;
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   317
end;
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   318
3848
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   319
function lc_campaignlock(L : Plua_State) : LongInt; Cdecl;
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   320
begin
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   321
    if lua_gettop(L) = 1 then
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   322
        begin
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   323
        // to be done
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   324
        end
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   325
    else
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   326
        LuaParameterCountError('CampaignLock', 'TODO', lua_gettop(L));
3848
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   327
    lc_campaignlock:= 0;
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   328
end;
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   329
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   330
function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl;
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   331
begin
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   332
    if lua_gettop(L) = 1 then
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   333
        begin
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   334
        // to be done
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   335
        end
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   336
    else
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   337
        LuaParameterCountError('CampaignUnlock', 'TODO', lua_gettop(L));
3848
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   338
    lc_campaignunlock:= 0;
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   339
end;
32ceb775906b Engine:
smaxx
parents: 3836
diff changeset
   340
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   341
function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   342
var gear: PGear;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   343
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   344
    if lua_gettop(L) <> 4 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   345
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   346
        LuaParameterCountError('SpawnFakeHealthCrate', 'x, y, explode, poison', lua_gettop(L));
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   347
        lua_pushnil(L);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   348
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   349
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   350
        begin
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   351
        gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   352
        HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   353
        lua_pushinteger(L, gear^.uid);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   354
        end;
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   355
    lc_spawnfakehealthcrate := 1;
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   356
end;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   357
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   358
function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   359
var gear: PGear;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   360
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   361
    if lua_gettop(L) <> 4 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   362
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   363
        LuaParameterCountError('SpawnFakeAmmoCrate', 'x, y, explode, poison', lua_gettop(L));
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   364
        lua_pushnil(L);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   365
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   366
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   367
        begin
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   368
        gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   369
        AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   370
        lua_pushinteger(L, gear^.uid);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   371
        end;
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   372
    lc_spawnfakeammocrate := 1;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   373
end;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   374
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   375
function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   376
var gear: PGear;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   377
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   378
    if lua_gettop(L) <> 4 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   379
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   380
        LuaParameterCountError('SpawnFakeUtilityCrate', 'x, y, explode, poison', lua_gettop(L));
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   381
        lua_pushnil(L);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   382
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   383
    else
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   384
        begin
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   385
        gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   386
        UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   387
        lua_pushinteger(L, gear^.uid);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   388
        end;
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   389
    lc_spawnfakeutilitycrate := 1;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   390
end;
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   391
3730
aecea9aa53dc Engine:
smaxx
parents: 3724
diff changeset
   392
function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl;
3750
3aa85b5f3318 SpawnCustomCrateAt: spawn crate at random position for x=y=0, also let it return the gear, and luabindings the gear uid
burp
parents: 3736
diff changeset
   393
var gear: PGear;
5313
5e18eaef65d0 now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values
Henek
parents: 5277
diff changeset
   394
var health: LongInt;
3730
aecea9aa53dc Engine:
smaxx
parents: 3724
diff changeset
   395
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   396
    if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   397
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   398
        LuaParameterCountError('SpawnHealthCrate', 'x, y[, health]', lua_gettop(L));
3730
aecea9aa53dc Engine:
smaxx
parents: 3724
diff changeset
   399
        lua_pushnil(L);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   400
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   401
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   402
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   403
        if lua_gettop(L) = 3 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   404
            health:= lua_tointeger(L, 3)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   405
        else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   406
            health:= cHealthCaseAmount;
7337
c224cd2d32f3 Allow script to set number of ammo in a crate. untested.
nemo
parents: 7307
diff changeset
   407
        gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   408
        if gear <> nil then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   409
            lua_pushinteger(L, gear^.uid)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   410
        else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   411
            lua_pushnil(L);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   412
        end;
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   413
    lc_spawnhealthcrate := 1;
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   414
end;
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   415
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   416
function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl;
3750
3aa85b5f3318 SpawnCustomCrateAt: spawn crate at random position for x=y=0, also let it return the gear, and luabindings the gear uid
burp
parents: 3736
diff changeset
   417
var gear: PGear;
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   418
begin
7337
c224cd2d32f3 Allow script to set number of ammo in a crate. untested.
nemo
parents: 7307
diff changeset
   419
    if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   420
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   421
        LuaParameterCountError('SpawnAmmoCrate', 'x, y, content[, amount]', lua_gettop(L));
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   422
        lua_pushnil(L);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   423
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   424
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   425
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   426
        if (lua_gettop(L) = 3) then
7337
c224cd2d32f3 Allow script to set number of ammo in a crate. untested.
nemo
parents: 7307
diff changeset
   427
             gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0)
c224cd2d32f3 Allow script to set number of ammo in a crate. untested.
nemo
parents: 7307
diff changeset
   428
        else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   429
        if gear <> nil then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   430
            lua_pushinteger(L, gear^.uid)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   431
        else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   432
            lua_pushnil(L);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   433
        end;
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   434
    lc_spawnammocrate := 1;
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   435
end;
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   436
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   437
function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl;
3750
3aa85b5f3318 SpawnCustomCrateAt: spawn crate at random position for x=y=0, also let it return the gear, and luabindings the gear uid
burp
parents: 3736
diff changeset
   438
var gear: PGear;
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   439
begin
7337
c224cd2d32f3 Allow script to set number of ammo in a crate. untested.
nemo
parents: 7307
diff changeset
   440
    if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   441
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   442
        LuaParameterCountError('SpawnUtilityCrate', 'x, y, content[, amount]', lua_gettop(L));
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   443
        lua_pushnil(L);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   444
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   445
    else
7337
c224cd2d32f3 Allow script to set number of ammo in a crate. untested.
nemo
parents: 7307
diff changeset
   446
        begin
7339
5984b749ad9b free up power for use by script
nemo
parents: 7337
diff changeset
   447
        if (lua_gettop(L) = 3) then
7337
c224cd2d32f3 Allow script to set number of ammo in a crate. untested.
nemo
parents: 7307
diff changeset
   448
             gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0)
c224cd2d32f3 Allow script to set number of ammo in a crate. untested.
nemo
parents: 7307
diff changeset
   449
        else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   450
        if gear <> nil then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   451
            lua_pushinteger(L, gear^.uid)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   452
        else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   453
            lua_pushnil(L);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   454
       end;
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   455
    lc_spawnutilitycrate := 1;
3730
aecea9aa53dc Engine:
smaxx
parents: 3724
diff changeset
   456
end;
aecea9aa53dc Engine:
smaxx
parents: 3724
diff changeset
   457
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   458
function lc_addgear(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   459
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   460
    x, y, s, t: LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   461
    dx, dy: hwFloat;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   462
    gt: TGearType;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   463
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   464
    if lua_gettop(L) <> 7 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   465
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   466
        LuaParameterCountError('AddGear', 'x, y, gearType, state, dx, dy, timer', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   467
        lua_pushnil(L); // return value on stack (nil)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   468
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   469
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   470
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   471
        x:= lua_tointeger(L, 1);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   472
        y:= lua_tointeger(L, 2);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   473
        gt:= TGearType(lua_tointeger(L, 3));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   474
        s:= lua_tointeger(L, 4);
5074
16f9e2d1f3b2 eh. 1,000,000 might be better...
nemo
parents: 5073
diff changeset
   475
        dx:= int2hwFloat(lua_tointeger(L, 5)) / 1000000;
16f9e2d1f3b2 eh. 1,000,000 might be better...
nemo
parents: 5073
diff changeset
   476
        dy:= int2hwFloat(lua_tointeger(L, 6)) / 1000000;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   477
        t:= lua_tointeger(L, 7);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   478
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   479
        gear:= AddGear(x, y, gt, s, dx, dy, t);
4780
8571151411b3 add a couple of variables to speed up UID lookups. Based on the assumption new visual gears and gears will tend to be at the end of the list. Set them on successful lookup or script gear creation, clear on delete. Oh also pick up a couple of TrevInc's translation changes
nemo
parents: 4767
diff changeset
   480
        lastGearByUID:= gear;
4484
b7a098f2649a these should probably be expressly integer
nemo
parents: 4483
diff changeset
   481
        lua_pushinteger(L, gear^.uid)
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   482
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   483
    lc_addgear:= 1; // 1 return value
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   484
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   485
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   486
function lc_deletegear(L : Plua_State) : LongInt; Cdecl;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   487
var gear : PGear;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   488
begin
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   489
    if lua_gettop(L) <> 1 then
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   490
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   491
        LuaParameterCountError('DeleteGear', 'gearUid', lua_gettop(L));
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   492
        end
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   493
    else
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   494
        begin
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   495
        gear:= GearByUID(lua_tointeger(L, 1));
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   496
        if gear <> nil then
7517
f287f00063e8 Allow scripting to delete gears
nemo
parents: 7426
diff changeset
   497
            gear^.Message:= gear^.Message or gmDelete;
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   498
        end;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   499
    lc_deletegear:= 0
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   500
end;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   501
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   502
function lc_addvisualgear(L : Plua_State) : LongInt; Cdecl;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   503
var vg : PVisualGear;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   504
    x, y, s: LongInt;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   505
    c: Boolean;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   506
    vgt: TVisualGearType;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   507
begin
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   508
    if lua_gettop(L) <> 5 then
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   509
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   510
        LuaParameterCountError('AddVisualGear', 'x, y, visualGearType, state, critical', lua_gettop(L));
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   511
        lua_pushnil(L); // return value on stack (nil)
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   512
        end
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   513
    else
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   514
        begin
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   515
        x:= lua_tointeger(L, 1);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   516
        y:= lua_tointeger(L, 2);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   517
        vgt:= TVisualGearType(lua_tointeger(L, 3));
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   518
        s:= lua_tointeger(L, 4);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   519
        c:= lua_toboolean(L, 5);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   520
4780
8571151411b3 add a couple of variables to speed up UID lookups. Based on the assumption new visual gears and gears will tend to be at the end of the list. Set them on successful lookup or script gear creation, clear on delete. Oh also pick up a couple of TrevInc's translation changes
nemo
parents: 4767
diff changeset
   521
        vg:= AddVisualGear(x, y, vgt, s, c);
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   522
        if vg <> nil then
4780
8571151411b3 add a couple of variables to speed up UID lookups. Based on the assumption new visual gears and gears will tend to be at the end of the list. Set them on successful lookup or script gear creation, clear on delete. Oh also pick up a couple of TrevInc's translation changes
nemo
parents: 4767
diff changeset
   523
            begin
8571151411b3 add a couple of variables to speed up UID lookups. Based on the assumption new visual gears and gears will tend to be at the end of the list. Set them on successful lookup or script gear creation, clear on delete. Oh also pick up a couple of TrevInc's translation changes
nemo
parents: 4767
diff changeset
   524
            lastVisualGearByUID:= vg;
8571151411b3 add a couple of variables to speed up UID lookups. Based on the assumption new visual gears and gears will tend to be at the end of the list. Set them on successful lookup or script gear creation, clear on delete. Oh also pick up a couple of TrevInc's translation changes
nemo
parents: 4767
diff changeset
   525
            lua_pushinteger(L, vg^.uid)
8571151411b3 add a couple of variables to speed up UID lookups. Based on the assumption new visual gears and gears will tend to be at the end of the list. Set them on successful lookup or script gear creation, clear on delete. Oh also pick up a couple of TrevInc's translation changes
nemo
parents: 4767
diff changeset
   526
            end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   527
        else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   528
            lua_pushinteger(L, 0)
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   529
        end;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   530
    lc_addvisualgear:= 1; // 1 return value
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   531
end;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   532
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   533
function lc_deletevisualgear(L : Plua_State) : LongInt; Cdecl;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   534
var vg : PVisualGear;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   535
begin
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   536
    if lua_gettop(L) <> 1 then
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   537
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   538
        LuaParameterCountError('DeleteVisualGear', 'vgUid', lua_gettop(L));
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   539
        end
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   540
    else
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   541
        begin
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   542
        vg:= VisualGearByUID(lua_tointeger(L, 1));
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   543
        if vg <> nil then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   544
            DeleteVisualGear(vg);
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   545
        end;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   546
    lc_deletevisualgear:= 0
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   547
end;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   548
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   549
function lc_getvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   550
var vg: PVisualGear;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   551
begin
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   552
    if lua_gettop(L) <> 1 then
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   553
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   554
        LuaParameterCountError('GetVisualGearValues', 'vgUid', lua_gettop(L));
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   555
        lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   556
        lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L)
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   557
        end
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   558
    else
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   559
        begin
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   560
        vg:= VisualGearByUID(lua_tointeger(L, 1));
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   561
        if vg <> nil then
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   562
            begin
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   563
            lua_pushinteger(L, round(vg^.X));
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   564
            lua_pushinteger(L, round(vg^.Y));
5075
59b13b38a827 not useful for visual gears, and apparently not helpful for consistency
nemo
parents: 5074
diff changeset
   565
            lua_pushnumber(L, vg^.dX);
59b13b38a827 not useful for visual gears, and apparently not helpful for consistency
nemo
parents: 5074
diff changeset
   566
            lua_pushnumber(L, vg^.dY);
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   567
            lua_pushnumber(L, vg^.Angle);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   568
            lua_pushinteger(L, vg^.Frame);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   569
            lua_pushinteger(L, vg^.FrameTicks);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   570
            lua_pushinteger(L, vg^.State);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   571
            lua_pushinteger(L, vg^.Timer);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   572
            lua_pushinteger(L, vg^.Tint);
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   573
            end
4767
4ee4a49549e2 return nil values if an invalid visual gear is passed to the get, add a check in Control map lua
nemo
parents: 4682
diff changeset
   574
        else
4ee4a49549e2 return nil values if an invalid visual gear is passed to the get, add a check in Control map lua
nemo
parents: 4682
diff changeset
   575
            begin
4ee4a49549e2 return nil values if an invalid visual gear is passed to the get, add a check in Control map lua
nemo
parents: 4682
diff changeset
   576
            lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
4ee4a49549e2 return nil values if an invalid visual gear is passed to the get, add a check in Control map lua
nemo
parents: 4682
diff changeset
   577
            lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L)
4ee4a49549e2 return nil values if an invalid visual gear is passed to the get, add a check in Control map lua
nemo
parents: 4682
diff changeset
   578
            end
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   579
        end;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   580
    lc_getvisualgearvalues:= 10;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   581
end;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   582
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   583
function lc_setvisualgearvalues(L : Plua_State) : LongInt; Cdecl;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   584
var vg : PVisualGear;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   585
begin
4450
b8d30b0e4829 forgot the passed in uid
nemo
parents: 4443
diff changeset
   586
    if lua_gettop(L) <> 11 then
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   587
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   588
        LuaParameterCountError('SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint', lua_gettop(L));
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   589
        lua_pushnil(L); // return value on stack (nil)
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   590
        end
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   591
    else
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   592
        begin
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   593
        vg:= VisualGearByUID(lua_tointeger(L, 1));
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   594
        if vg <> nil then
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   595
            begin
4450
b8d30b0e4829 forgot the passed in uid
nemo
parents: 4443
diff changeset
   596
            vg^.X:= lua_tointeger(L, 2);
b8d30b0e4829 forgot the passed in uid
nemo
parents: 4443
diff changeset
   597
            vg^.Y:= lua_tointeger(L, 3);
5075
59b13b38a827 not useful for visual gears, and apparently not helpful for consistency
nemo
parents: 5074
diff changeset
   598
            vg^.dX:= lua_tonumber(L, 4);
59b13b38a827 not useful for visual gears, and apparently not helpful for consistency
nemo
parents: 5074
diff changeset
   599
            vg^.dY:= lua_tonumber(L, 5);
4450
b8d30b0e4829 forgot the passed in uid
nemo
parents: 4443
diff changeset
   600
            vg^.Angle:= lua_tonumber(L, 6);
b8d30b0e4829 forgot the passed in uid
nemo
parents: 4443
diff changeset
   601
            vg^.Frame:= lua_tointeger(L, 7);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   602
            if lua_tointeger(L, 8) <> 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   603
                vg^.FrameTicks:= lua_tointeger(L, 8);  // find a better way to do this. maybe need to break all these up.
4450
b8d30b0e4829 forgot the passed in uid
nemo
parents: 4443
diff changeset
   604
            vg^.State:= lua_tointeger(L, 9);
b8d30b0e4829 forgot the passed in uid
nemo
parents: 4443
diff changeset
   605
            vg^.Timer:= lua_tointeger(L, 10);
b8d30b0e4829 forgot the passed in uid
nemo
parents: 4443
diff changeset
   606
            vg^.Tint:= lua_tointeger(L, 11);
4443
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   607
            end
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   608
        end;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   609
    lc_setvisualgearvalues:= 0;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   610
end;
d393b9ccd328 Add an extra pass in FindPlace for AI resurrection mode to try to make it unwinnable, add DeleteGear, DeleteVisualGear, AddVisualGear, GetVisualGearValues, SetVisualGearValues to Lua
nemo
parents: 4411
diff changeset
   611
3058
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   612
function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl;
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   613
begin
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   614
    if lua_gettop(L) <> 0 then
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   615
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   616
        LuaParameterCountError('GetFollowGear', '', lua_gettop(L));
3058
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   617
        lua_pushnil(L); // return value on stack (nil)
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   618
        end
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   619
    else
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   620
        if FollowGear = nil then
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   621
            lua_pushnil(L)
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   622
        else
4484
b7a098f2649a these should probably be expressly integer
nemo
parents: 4483
diff changeset
   623
            lua_pushinteger(L, FollowGear^.uid);
3058
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   624
    lc_getfollowgear:= 1; // 1 return value
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   625
end;
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
   626
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   627
function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   628
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   629
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   630
    if lua_gettop(L) <> 1 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   631
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   632
        LuaParameterCountError('GetGearType', 'gearUid', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   633
        lua_pushnil(L); // return value on stack (nil)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   634
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   635
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   636
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   637
        gear:= GearByUID(lua_tointeger(L, 1));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   638
        if gear <> nil then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   639
            lua_pushinteger(L, ord(gear^.Kind))
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   640
        else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   641
            lua_pushnil(L);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   642
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   643
    lc_getgeartype:= 1
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   644
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   645
3892
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   646
function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl;
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   647
var gear : PGear;
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   648
begin
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   649
    if lua_gettop(L) <> 1 then
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   650
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   651
        LuaParameterCountError('GetGearMessage', 'gearUid', lua_gettop(L));
3892
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   652
        lua_pushnil(L); // return value on stack (nil)
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   653
        end
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   654
    else
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   655
        begin
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   656
        gear:= GearByUID(lua_tointeger(L, 1));
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   657
        if gear <> nil then
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   658
            lua_pushinteger(L, gear^.message)
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   659
        else
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   660
            lua_pushnil(L);
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   661
        end;
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   662
    lc_getgearmessage:= 1
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   663
end;
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
   664
4682
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   665
function lc_getgearelasticity(L : Plua_State) : LongInt; Cdecl;
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   666
var gear : PGear;
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   667
begin
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   668
    if lua_gettop(L) <> 1 then
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   669
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   670
        LuaParameterCountError('GetGearElasticity', 'gearUid', lua_gettop(L));
4682
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   671
        lua_pushnil(L); // return value on stack (nil)
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   672
        end
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   673
    else
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   674
        begin
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   675
        gear:= GearByUID(lua_tointeger(L, 1));
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   676
        if gear <> nil then
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   677
            lua_pushinteger(L, hwRound(gear^.elasticity * _10000))
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   678
        else
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   679
            lua_pushnil(L);
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   680
        end;
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   681
    lc_getgearelasticity:= 1
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   682
end;
0fc1ff341482 add a GetGearElasticity since Mikade kept asking for it. (actually return *10000 to handle it being an hwFloat - I assume large values will just overflow to negative)
nemo
parents: 4629
diff changeset
   683
3896
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   684
function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl;
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   685
var gear : PGear;
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   686
begin
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   687
    if lua_gettop(L) <> 2 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   688
        LuaParameterCountError('SetGearMessage', 'gearUid, message', lua_gettop(L))
3896
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   689
    else
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   690
        begin
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   691
        gear:= GearByUID(lua_tointeger(L, 1));
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   692
        if gear <> nil then
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   693
            gear^.message:= lua_tointeger(L, 2);
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   694
        end;
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   695
    lc_setgearmessage:= 0
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   696
end;
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
   697
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   698
function lc_getgearpos(L : Plua_State) : LongInt; Cdecl;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   699
var gear : PGear;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   700
begin
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   701
    if lua_gettop(L) <> 1 then
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   702
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   703
        LuaParameterCountError('GetGearPos', 'gearUid', lua_gettop(L));
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   704
        lua_pushnil(L); // return value on stack (nil)
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   705
        end
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   706
    else
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   707
        begin
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   708
        gear:= GearByUID(lua_tointeger(L, 1));
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   709
        if gear <> nil then
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   710
            lua_pushinteger(L, gear^.Pos)
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   711
        else
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   712
            lua_pushnil(L);
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   713
        end;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   714
    lc_getgearpos:= 1
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   715
end;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   716
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   717
function lc_setgearpos(L : Plua_State) : LongInt; Cdecl;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   718
var gear : PGear;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   719
begin
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   720
    if lua_gettop(L) <> 2 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   721
        LuaParameterCountError('SetGearPos', 'gearUid, value', lua_gettop(L))
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   722
    else
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   723
        begin
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   724
        gear:= GearByUID(lua_tointeger(L, 1));
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   725
        if gear <> nil then
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   726
            gear^.Pos:= lua_tointeger(L, 2);
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   727
        end;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   728
    lc_setgearpos:= 0
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   729
end;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
   730
7726
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   731
function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   732
var gear : PGear;
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   733
begin
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   734
    if lua_gettop(L) <> 1 then
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   735
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   736
        LuaParameterCountError('GetGearCollisionMask', 'gearUid', lua_gettop(L));
7726
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   737
        lua_pushnil(L); // return value on stack (nil)
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   738
        end
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   739
    else
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   740
        begin
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   741
        gear:= GearByUID(lua_tointeger(L, 1));
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   742
        if gear <> nil then
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   743
            lua_pushinteger(L, gear^.CollisionMask)
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   744
        else
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   745
            lua_pushnil(L);
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   746
        end;
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   747
    lc_getgearcollisionmask:= 1
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   748
end;
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   749
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   750
function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl;
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   751
var gear : PGear;
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   752
begin
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   753
    if lua_gettop(L) <> 2 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   754
        LuaParameterCountError('SetGearCollisionMask', 'gearUid, mask', lua_gettop(L))
7726
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   755
    else
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   756
        begin
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   757
        gear:= GearByUID(lua_tointeger(L, 1));
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   758
        if gear <> nil then
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   759
            gear^.CollisionMask:= lua_tointeger(L, 2);
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   760
        end;
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   761
    lc_setgearcollisionmask:= 0
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   762
end;
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
   763
3755
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   764
function lc_gethoglevel(L : Plua_State): LongInt; Cdecl;
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   765
var gear : PGear;
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   766
begin
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   767
    if lua_gettop(L) <> 1 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   768
        LuaParameterCountError('GetHogLevel', 'gearUid', lua_gettop(L))
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   769
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   770
        begin
3755
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   771
        gear := GearByUID(lua_tointeger(L, 1));
8228
8cc5dc7f7ef9 kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents: 8145
diff changeset
   772
        if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
4372
3836973380b9 remove some more PHedgehog casts
nemo
parents: 4371
diff changeset
   773
            lua_pushinteger(L, gear^.Hedgehog^.BotLevel)
3755
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   774
        else
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   775
            lua_pushnil(L);
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   776
    end;
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   777
    lc_gethoglevel := 1;
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   778
end;
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
   779
4496
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   780
function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl;
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   781
var gear : PGear;
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   782
begin
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   783
    if lua_gettop(L) <> 2 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   784
        LuaParameterCountError('SetHogLevel', 'gearUid, level', lua_gettop(L))
4496
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   785
    else
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   786
        begin
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   787
        gear:= GearByUID(lua_tointeger(L, 1));
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   788
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   789
            gear^.Hedgehog^.BotLevel:= lua_tointeger(L, 2);
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   790
        end;
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   791
    lc_sethoglevel:= 0
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   792
end;
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
   793
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   794
function lc_gethogclan(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   795
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   796
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   797
    if lua_gettop(L) <> 1 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   798
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   799
        LuaParameterCountError('GetHogClan', 'gearUid', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   800
        lua_pushnil(L); // return value on stack (nil)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   801
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   802
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   803
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   804
        gear:= GearByUID(lua_tointeger(L, 1));
8228
8cc5dc7f7ef9 kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents: 8145
diff changeset
   805
        if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   806
            begin
4372
3836973380b9 remove some more PHedgehog casts
nemo
parents: 4371
diff changeset
   807
            lua_pushinteger(L, gear^.Hedgehog^.Team^.Clan^.ClanIndex)
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   808
            end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   809
        else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   810
            lua_pushnil(L);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   811
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   812
    lc_gethogclan:= 1
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   813
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   814
4498
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
   815
function lc_getclancolor(L : Plua_State) : LongInt; Cdecl;
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
   816
begin
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
   817
    if lua_gettop(L) <> 1 then
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
   818
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   819
        LuaParameterCountError('GetClanColor', 'clan', lua_gettop(L));
4498
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
   820
        lua_pushnil(L); // return value on stack (nil)
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
   821
        end
4499
d2454e4dbd03 return RGBA
nemo
parents: 4498
diff changeset
   822
    else lua_pushinteger(L, ClansArray[lua_tointeger(L, 1)]^.Color shl 8 or $FF);
4498
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
   823
    lc_getclancolor:= 1
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
   824
end;
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
   825
4882
b4c84db92d8f expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents: 4875
diff changeset
   826
function lc_setclancolor(L : Plua_State) : LongInt; Cdecl;
4889
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   827
var clan : PClan;
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   828
    team : PTeam;
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   829
    hh   : THedgehog;
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   830
    i, j : LongInt;
4882
b4c84db92d8f expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents: 4875
diff changeset
   831
begin
b4c84db92d8f expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents: 4875
diff changeset
   832
    if lua_gettop(L) <> 2 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   833
        LuaParameterCountError('SetClanColor', 'clan, color', lua_gettop(L))
4889
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   834
    else
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   835
        begin
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   836
        clan := ClansArray[lua_tointeger(L, 1)];
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   837
        clan^.Color:= lua_tointeger(L, 2) shr 8;
9656
18422d205080 - More HealthTex to clan structure
unc0rr
parents: 9648
diff changeset
   838
4889
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   839
        for i:= 0 to Pred(clan^.TeamsNumber) do
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   840
            begin
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   841
            team:= clan^.Teams[i];
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   842
            for j:= 0 to 7 do
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   843
                begin
4891
nemo
parents: 4890
diff changeset
   844
                hh:= team^.Hedgehogs[j];
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   845
                if (hh.Gear <> nil) or (hh.GearHidden <> nil) then
4889
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   846
                    begin
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   847
                    FreeTexture(hh.NameTagTex);
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10122
diff changeset
   848
                    hh.NameTagTex:= RenderStringTex(ansistring(hh.Name), clan^.Color, fnt16);
4889
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   849
                    RenderHealth(hh);
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   850
                    end;
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   851
                end;
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   852
            FreeTexture(team^.NameTagTex);
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10122
diff changeset
   853
            team^.NameTagTex:= RenderStringTex(ansistring(clan^.Teams[i]^.TeamName), clan^.Color, fnt16);
9656
18422d205080 - More HealthTex to clan structure
unc0rr
parents: 9648
diff changeset
   854
            end;
4889
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   855
9656
18422d205080 - More HealthTex to clan structure
unc0rr
parents: 9648
diff changeset
   856
        clan^.HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, clan^.Teams[0]^.NameTagTex^.h, clan^.Color);
18422d205080 - More HealthTex to clan structure
unc0rr
parents: 9648
diff changeset
   857
        end;
4889
f71e30eb1d37 Reset things using team colour on change in SetClanColor in lua. This routine had better have been worth it.
nemo
parents: 4883
diff changeset
   858
4882
b4c84db92d8f expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents: 4875
diff changeset
   859
    lc_setclancolor:= 0
b4c84db92d8f expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents: 4875
diff changeset
   860
end;
b4c84db92d8f expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents: 4875
diff changeset
   861
4236
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   862
function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl;
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   863
var gear : PGear;
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   864
begin
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   865
    if lua_gettop(L) <> 1 then
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   866
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   867
        LuaParameterCountError('GetHogTeamName', 'gearUid', lua_gettop(L));
4236
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   868
        lua_pushnil(L); // return value on stack (nil)
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   869
        end
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   870
    else
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   871
        begin
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   872
        gear:= GearByUID(lua_tointeger(L, 1));
8228
8cc5dc7f7ef9 kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents: 8145
diff changeset
   873
        if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
4236
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   874
            begin
4372
3836973380b9 remove some more PHedgehog casts
nemo
parents: 4371
diff changeset
   875
            lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName))
4236
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   876
            end
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   877
        else
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   878
            lua_pushnil(L);
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   879
        end;
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   880
    lc_gethogteamname:= 1
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   881
end;
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
   882
9788
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   883
function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl;
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   884
var gear : PGear;
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   885
begin
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   886
    if lua_gettop(L) <> 2 then
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   887
        begin
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   888
        LuaParameterCountError('SetHogTeamName', 'gearUid, name', lua_gettop(L));
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   889
        lua_pushnil(L); // return value on stack (nil)
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   890
        end
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   891
    else
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   892
        begin
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   893
        gear := GearByUID(lua_tointeger(L, 1));
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   894
        if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   895
            begin
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   896
            gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2);
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   897
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   898
            FreeTexture(gear^.Hedgehog^.Team^.NameTagTex);
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10122
diff changeset
   899
            gear^.Hedgehog^.Team^.NameTagTex:= RenderStringTex(ansistring(gear^.Hedgehog^.Team^.TeamName), gear^.Hedgehog^.Team^.Clan^.Color, fnt16);
9788
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   900
            end
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   901
        else
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   902
            lua_pushnil(L);
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   903
        end;
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   904
    lc_sethogteamname:= 1
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   905
end;
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
   906
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   907
function lc_gethogname(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   908
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   909
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   910
    if lua_gettop(L) <> 1 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   911
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   912
        LuaParameterCountError('GetHogName', 'gearUid', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   913
        lua_pushnil(L); // return value on stack (nil)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   914
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   915
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   916
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   917
        gear:= GearByUID(lua_tointeger(L, 1));
8228
8cc5dc7f7ef9 kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents: 8145
diff changeset
   918
        if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   919
            begin
4372
3836973380b9 remove some more PHedgehog casts
nemo
parents: 4371
diff changeset
   920
            lua_pushstring(L, str2pchar(gear^.Hedgehog^.Name))
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   921
            end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   922
        else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   923
            lua_pushnil(L);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   924
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   925
    lc_gethogname:= 1
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   926
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   927
5245
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   928
function lc_sethogname(L : Plua_State) : LongInt; Cdecl;
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   929
var gear : PGear;
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   930
begin
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   931
    if lua_gettop(L) <> 2 then
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   932
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   933
        LuaParameterCountError('SetHogName', 'gearUid, name', lua_gettop(L));
5245
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   934
        lua_pushnil(L)
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   935
        end
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   936
    else
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   937
        begin
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   938
        gear:= GearByUID(lua_tointeger(L, 1));
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   939
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
9748
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
   940
            begin
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
   941
            gear^.Hedgehog^.Name:= lua_tostring(L, 2);
5245
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   942
9748
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
   943
            FreeTexture(gear^.Hedgehog^.NameTagTex);
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10122
diff changeset
   944
            gear^.Hedgehog^.NameTagTex:= RenderStringTex(ansistring(gear^.Hedgehog^.Name), gear^.Hedgehog^.Team^.Clan^.Color, fnt16)
9748
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
   945
            end
5245
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   946
        end;
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   947
    lc_sethogname:= 0;
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   948
end;
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
   949
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   950
function lc_gettimer(L : Plua_State) : LongInt; Cdecl;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   951
var gear : PGear;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   952
begin
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   953
    if lua_gettop(L) <> 1 then
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   954
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   955
        LuaParameterCountError('GetTimer', 'gearUid', lua_gettop(L));
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   956
        lua_pushnil(L); // return value on stack (nil)
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   957
        end
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   958
    else
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   959
        begin
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   960
        gear:= GearByUID(lua_tointeger(L, 1));
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   961
        if gear <> nil then
4484
b7a098f2649a these should probably be expressly integer
nemo
parents: 4483
diff changeset
   962
            lua_pushinteger(L, gear^.Timer)
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   963
        else
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   964
            lua_pushnil(L);
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   965
        end;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   966
    lc_gettimer:= 1
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   967
end;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   968
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   969
function lc_gethealth(L : Plua_State) : LongInt; Cdecl;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   970
var gear : PGear;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   971
begin
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   972
    if lua_gettop(L) <> 1 then
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   973
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   974
        LuaParameterCountError('GetHealth', 'gearUid', lua_gettop(L));
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   975
        lua_pushnil(L); // return value on stack (nil)
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   976
        end
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   977
    else
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   978
        begin
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   979
        gear:= GearByUID(lua_tointeger(L, 1));
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   980
        if gear <> nil then
4484
b7a098f2649a these should probably be expressly integer
nemo
parents: 4483
diff changeset
   981
            lua_pushinteger(L, gear^.Health)
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   982
        else
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   983
            lua_pushnil(L);
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   984
        end;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   985
    lc_gethealth:= 1
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   986
end;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
   987
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   988
function lc_getx(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   989
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   990
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   991
    if lua_gettop(L) <> 1 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   992
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   993
        LuaParameterCountError('GetX', 'gearUid', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   994
        lua_pushnil(L); // return value on stack (nil)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   995
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   996
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   997
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   998
        gear:= GearByUID(lua_tointeger(L, 1));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   999
        if gear <> nil then
4484
b7a098f2649a these should probably be expressly integer
nemo
parents: 4483
diff changeset
  1000
            lua_pushinteger(L, hwRound(gear^.X))
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1001
        else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1002
            lua_pushnil(L);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1003
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1004
    lc_getx:= 1
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1005
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1006
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1007
function lc_gety(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1008
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1009
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1010
    if lua_gettop(L) <> 1 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1011
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1012
        LuaParameterCountError('GetY', 'gearUid', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1013
        lua_pushnil(L); // return value on stack (nil)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1014
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1015
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1016
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1017
        gear:= GearByUID(lua_tointeger(L, 1));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1018
        if gear <> nil then
4484
b7a098f2649a these should probably be expressly integer
nemo
parents: 4483
diff changeset
  1019
            lua_pushinteger(L, hwRound(gear^.Y))
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1020
        else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1021
            lua_pushnil(L);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1022
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1023
    lc_gety:= 1
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1024
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1025
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1026
function lc_copypv(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1027
var gears, geard : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1028
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1029
    if lua_gettop(L) <> 2 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1030
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1031
        LuaParameterCountError('CopyPV', 'fromGearUid, toGearUid', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1032
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1033
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1034
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1035
        gears:= GearByUID(lua_tointeger(L, 1));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1036
        geard:= GearByUID(lua_tointeger(L, 2));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1037
        if (gears <> nil) and (geard <> nil) then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1038
            begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1039
            geard^.X:= gears^.X;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1040
            geard^.Y:= gears^.Y;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1041
            geard^.dX:= gears^.dX;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1042
            geard^.dY:= gears^.dY;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1043
            end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1044
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1045
    lc_copypv:= 1
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1046
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1047
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1048
function lc_followgear(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1049
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1050
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1051
    if lua_gettop(L) <> 1 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1052
        LuaParameterCountError('FollowGear', 'gearUid', lua_gettop(L))
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1053
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1054
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1055
        gear:= GearByUID(lua_tointeger(L, 1));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1056
        if gear <> nil then FollowGear:= gear
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1057
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1058
    lc_followgear:= 0
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1059
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1060
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1061
function lc_hogsay(L : Plua_State) : LongInt; Cdecl;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1062
var gear : PGear;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1063
   vgear : PVisualGear;
4533
8d35c3e0e6ba add optional state parameter to hogsay
nemo
parents: 4523
diff changeset
  1064
       s : LongWord;
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1065
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1066
    if lua_gettop(L) = 4 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1067
        s:= lua_tointeger(L, 4)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1068
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1069
        s:= 0;
4533
8d35c3e0e6ba add optional state parameter to hogsay
nemo
parents: 4523
diff changeset
  1070
8d35c3e0e6ba add optional state parameter to hogsay
nemo
parents: 4523
diff changeset
  1071
    if (lua_gettop(L) = 4) or (lua_gettop(L) = 3) then
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1072
        begin
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1073
        gear:= GearByUID(lua_tointeger(L, 1));
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1074
        if gear <> nil then
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1075
            begin
4533
8d35c3e0e6ba add optional state parameter to hogsay
nemo
parents: 4523
diff changeset
  1076
            vgear:= AddVisualGear(0, 0, vgtSpeechBubble, s, true);
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1077
            if vgear <> nil then
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1078
               begin
5549
ccfb9b8ab9d1 sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents: 5547
diff changeset
  1079
               vgear^.Text:= lua_tostring(L, 2);
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1080
               vgear^.Hedgehog:= gear^.Hedgehog;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1081
               vgear^.FrameTicks:= lua_tointeger(L, 3);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1082
               if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1083
                   vgear^.FrameTicks:= 1;
9764
8dc9d268330f revert r938d1c08d0d1 in favour of putting it in the chat log. I think this addresses main concern about missing text. There've been complaints in past too about conversation in bubbles not being visible in history. If the objection is that r938d1c08d0d1 offers a more æsthetic solution, I think it should augment this, be flagged, and fix the visual issues first.
nemo
parents: 9752
diff changeset
  1084
               lua_pushinteger(L, vgear^.Uid);
8dc9d268330f revert r938d1c08d0d1 in favour of putting it in the chat log. I think this addresses main concern about missing text. There've been complaints in past too about conversation in bubbles not being visible in history. If the objection is that r938d1c08d0d1 offers a more æsthetic solution, I think it should augment this, be flagged, and fix the visual issues first.
nemo
parents: 9752
diff changeset
  1085
               AddChatString(#1+'[' + gear^.Hedgehog^.Name + '] '+vgear^.text)
5529
9a47cff3910a return visual gear in hogsay
nemo
parents: 5527
diff changeset
  1086
               end
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1087
            end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1088
            else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1089
                lua_pushnil(L)
4533
8d35c3e0e6ba add optional state parameter to hogsay
nemo
parents: 4523
diff changeset
  1090
        end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1091
    else LuaParameterCountError('HogSay', 'gearUid, text, manner[, vgState]', lua_gettop(L));
5529
9a47cff3910a return visual gear in hogsay
nemo
parents: 5527
diff changeset
  1092
    lc_hogsay:= 1
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1093
end;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1094
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1095
function lc_switchhog(L : Plua_State) : LongInt; Cdecl;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1096
var gear, prevgear : PGear;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1097
begin
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1098
    if lua_gettop(L) <> 1 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1099
        LuaParameterCountError('SwitchHog', 'gearUid', lua_gettop(L))
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1100
    else
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1101
        begin
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1102
        gear:= GearByUID(lua_tointeger(L, 1));
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1103
// should we allow this when there is no current hedgehog? might do some odd(er) things to turn sequence.
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1104
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (CurrentHedgehog <> nil) then
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1105
            begin
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1106
            prevgear := CurrentHedgehog^.Gear;
7573
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1107
            if prevgear <> nil then
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1108
                begin
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1109
                prevgear^.Active := false;
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1110
                prevgear^.State:= prevgear^.State and (not gstHHDriven);
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1111
                prevgear^.Z := cHHZ;
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1112
                prevgear^.Message:= prevgear^.Message or gmRemoveFromList or gmAddToList;
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1113
                end;
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1114
7270
93e92e82d5c8 Step 1. Add current hedgehog as top bit of bottom byte.
nemo
parents: 7156
diff changeset
  1115
            SwitchCurrentHedgehog(gear^.Hedgehog);
93e92e82d5c8 Step 1. Add current hedgehog as top bit of bottom byte.
nemo
parents: 7156
diff changeset
  1116
            CurrentTeam:= CurrentHedgehog^.Team;
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1117
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1118
            gear^.State:= gear^.State or gstHHDriven;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1119
            gear^.Active := true;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1120
            gear^.Z := cCurrHHZ;
7401
4c3ec3dca0c7 oh yeah, these too
nemo
parents: 7339
diff changeset
  1121
            gear^.Message:= gear^.Message or gmRemoveFromList or gmAddToList;
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1122
            end
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1123
        end;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1124
    lc_switchhog:= 0
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1125
end;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1126
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1127
{function lc_addammo(L : Plua_State) : LongInt; Cdecl;
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1128
var gear : PGear;
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1129
begin
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1130
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1131
    if lua_gettop(L) = 3 then
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1132
    begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1133
    gear:= GearByUID(lua_tointeger(L, 1));
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1134
        if (gear <> nil) and (gear^.Hedgehog <> nil) then
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1135
            AddAmmoAmount(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L,3) );
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1136
    end else
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1137
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1138
    if lua_gettop(L) = 2 then
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1139
    begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1140
    gear:= GearByUID(lua_tointeger(L, 1));
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1141
        if (gear <> nil) and (gear^.Hedgehog <> nil) then
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1142
            AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)));
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1143
    end else
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1144
    begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1145
        LuaParameterCountError('AddAmmo', 'TODO', lua_gettop(L));
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1146
    end;
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1147
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1148
    lc_addammo:= 0;
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1149
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1150
end;}
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 5272
diff changeset
  1151
4481
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1152
function lc_addammo(L : Plua_State) : LongInt; Cdecl;
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1153
var gear : PGear;
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1154
begin
5272
a85d331ab5bb Allow scripting to set arbitrary weapon counts
nemo
parents: 5245
diff changeset
  1155
    if (lua_gettop(L) = 3) or (lua_gettop(L) = 2) then
4481
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1156
        begin
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1157
        gear:= GearByUID(lua_tointeger(L, 1));
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1158
        if (gear <> nil) and (gear^.Hedgehog <> nil) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1159
            if lua_gettop(L) = 2 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1160
                AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)))
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1161
            else
6924
57b66ee3bff3 Get rid of overloaded functions in uAmmo
unc0rr
parents: 6828
diff changeset
  1162
                SetAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L, 3))
5272
a85d331ab5bb Allow scripting to set arbitrary weapon counts
nemo
parents: 5245
diff changeset
  1163
        end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1164
    else LuaParameterCountError('AddAmmo', 'gearUid, ammoType[, ammoCount]', lua_gettop(L));
4481
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1165
    lc_addammo:= 0
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1166
end;
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1167
5676
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1168
function lc_getammocount(L : Plua_State) : LongInt; Cdecl;
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1169
var gear : PGear;
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1170
    ammo : PAmmo;
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1171
begin
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1172
    if (lua_gettop(L) = 2) then
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1173
        begin
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1174
        gear:= GearByUID(lua_tointeger(L, 1));
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1175
        if (gear <> nil) and (gear^.Hedgehog <> nil) then
5676
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1176
            begin
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1177
            ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)));
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1178
            if ammo^.AmmoType = amNothing then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1179
                lua_pushinteger(L, 0)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1180
            else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1181
                lua_pushinteger(L, ammo^.Count)
5676
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1182
            end
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1183
        else lua_pushinteger(L, 0)
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1184
        end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1185
    else
6046
d681b8127523 this needs to actually return something
nemo
parents: 6019
diff changeset
  1186
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1187
        LuaParameterCountError('GetAmmoCount', 'gearUid, ammoType', lua_gettop(L));
6046
d681b8127523 this needs to actually return something
nemo
parents: 6019
diff changeset
  1188
        lua_pushnil(L)
d681b8127523 this needs to actually return something
nemo
parents: 6019
diff changeset
  1189
        end;
d681b8127523 this needs to actually return something
nemo
parents: 6019
diff changeset
  1190
    lc_getammocount:= 1
5676
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1191
end;
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  1192
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1193
function lc_sethealth(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1194
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1195
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1196
    if lua_gettop(L) <> 2 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1197
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1198
        LuaParameterCountError('SetHealth', 'gearUid, health', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1199
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1200
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1201
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1202
        gear:= GearByUID(lua_tointeger(L, 1));
3723
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1203
        if gear <> nil then
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1204
            begin
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1205
            gear^.Health:= lua_tointeger(L, 2);
5245
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
  1206
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1207
            if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1208
                begin
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1209
                RenderHealth(gear^.Hedgehog^);
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1210
                RecountTeamHealth(gear^.Hedgehog^.Team)
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1211
                end;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1212
            // Why did this do a "setalltoactive" ?
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 10009 9952
diff changeset
  1213
            //SetAllToActive;
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1214
            Gear^.Active:= true;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1215
            AllInactive:= false
3723
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1216
            end
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1217
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1218
    lc_sethealth:= 0
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1219
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1220
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1221
function lc_settimer(L : Plua_State) : LongInt; Cdecl;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1222
var gear : PGear;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1223
begin
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1224
    if lua_gettop(L) <> 2 then
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1225
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1226
        LuaParameterCountError('SetTimer', 'gearUid, timer', lua_gettop(L));
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1227
        end
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1228
    else
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1229
        begin
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1230
        gear:= GearByUID(lua_tointeger(L, 1));
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1231
        if gear <> nil then gear^.Timer:= lua_tointeger(L, 2)
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1232
        end;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1233
    lc_settimer:= 0
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1234
end;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1235
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  1236
function lc_seteffect(L : Plua_State) : LongInt; Cdecl;
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  1237
var gear: PGear;
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  1238
begin
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  1239
    if lua_gettop(L) <> 3 then
9987
8f07b47a641b fix seteffect documentation, lua wiki misled me there
sheepluva
parents: 9985
diff changeset
  1240
        LuaParameterCountError('SetEffect', 'gearUid, effect, effectState', lua_gettop(L))
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  1241
    else begin
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  1242
        gear := GearByUID(lua_tointeger(L, 1));
5489
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1243
        if (gear <> nil) and (gear^.Hedgehog <> nil) then
7010
10a0a31804f3 Switch effects to longint for convenience of tracking ice states. I could add a new Hedgehog value, but since we have this effects list being all useless as booleans anyway...
nemo
parents: 6982
diff changeset
  1244
            gear^.Hedgehog^.Effects[THogEffect(lua_tointeger(L, 2))]:= lua_tointeger(L, 3);
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  1245
    end;
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  1246
    lc_seteffect := 0;
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  1247
end;
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1248
5489
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1249
function lc_geteffect(L : Plua_State) : LongInt; Cdecl;
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1250
var gear : PGear;
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1251
begin
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1252
    if lua_gettop(L) <> 2 then
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1253
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1254
        LuaParameterCountError('GetEffect', 'gearUid, effect', lua_gettop(L));
5489
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1255
        end
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1256
    else
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1257
        begin
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1258
        gear:= GearByUID(lua_tointeger(L, 1));
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1259
        if (gear <> nil) and (gear^.Hedgehog <> nil) then
7010
10a0a31804f3 Switch effects to longint for convenience of tracking ice states. I could add a new Hedgehog value, but since we have this effects list being all useless as booleans anyway...
nemo
parents: 6982
diff changeset
  1260
            lua_pushinteger(L, gear^.Hedgehog^.Effects[THogEffect(lua_tointeger(L, 2))])
5489
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1261
        else
7010
10a0a31804f3 Switch effects to longint for convenience of tracking ice states. I could add a new Hedgehog value, but since we have this effects list being all useless as booleans anyway...
nemo
parents: 6982
diff changeset
  1262
            lua_pushinteger(L, 0)
5489
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1263
        end;
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1264
    lc_geteffect:= 1
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  1265
end;
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  1266
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1267
function lc_setstate(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1268
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1269
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1270
    if lua_gettop(L) <> 2 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1271
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1272
        LuaParameterCountError('SetState', 'gearUid, state', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1273
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1274
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1275
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1276
        gear:= GearByUID(lua_tointeger(L, 1));
3723
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1277
        if gear <> nil then
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1278
            begin
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1279
            gear^.State:= lua_tointeger(L, 2);
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1280
            SetAllToActive;
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1281
            end
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1282
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1283
    lc_setstate:= 0
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1284
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1285
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1286
function lc_getstate(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1287
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1288
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1289
    if lua_gettop(L) <> 1 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1290
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1291
        LuaParameterCountError('GetState', 'gearUid', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1292
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1293
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1294
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1295
        gear:= GearByUID(lua_tointeger(L, 1));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1296
        if gear <> nil then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1297
            lua_pushinteger(L, gear^.State)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1298
        else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1299
            lua_pushnil(L)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1300
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1301
    lc_getstate:= 1
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1302
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1303
7156
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1304
function lc_gettag(L : Plua_State) : LongInt; Cdecl;
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1305
var gear : PGear;
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1306
begin
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1307
    if lua_gettop(L) <> 1 then
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1308
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1309
        LuaParameterCountError('GetTag', 'gearUid', lua_gettop(L));
7156
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1310
        lua_pushnil(L); // return value on stack (nil)
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1311
        end
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1312
    else
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1313
        begin
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1314
        gear:= GearByUID(lua_tointeger(L, 1));
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1315
        if gear <> nil then
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1316
            lua_pushinteger(L, gear^.Tag)
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1317
        else
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1318
            lua_pushnil(L);
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1319
        end;
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1320
    lc_gettag:= 1
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1321
end;
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  1322
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1323
function lc_settag(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1324
var gear : PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1325
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1326
    if lua_gettop(L) <> 2 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1327
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1328
        LuaParameterCountError('SetTag', 'gearUid, tag', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1329
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1330
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1331
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1332
        gear:= GearByUID(lua_tointeger(L, 1));
3723
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1333
        if gear <> nil then
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1334
            begin
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1335
            gear^.Tag:= lua_tointeger(L, 2);
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1336
            SetAllToActive;
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1337
            end
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1338
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1339
    lc_settag:= 0
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1340
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1341
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1342
function lc_endgame(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1343
begin
3407
dcc129c4352e Engine:
smxx
parents: 3368
diff changeset
  1344
    L:= L; // avoid compiler hint
8460
75e771c3c039 fix EndGame call. w/o a proper exit, demos weren't being saved
nemo
parents: 8370
diff changeset
  1345
    AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1346
    lc_endgame:= 0
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1347
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1348
9171
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  1349
function lc_sendstat(L : Plua_State) : LongInt; Cdecl;
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  1350
var statInfo : TStatInfoType;
9173
575dd8fe4a55 LuaAPI sendstat finds correct clan colors by team names on siPlayerKills
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9171
diff changeset
  1351
var i : LongInt;
9176
c21c88dca14c correct health statsend for lua scritps
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9174
diff changeset
  1352
var color : shortstring;
9171
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  1353
begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1354
    statInfo := TStatInfoType(lua_tointeger(L, 1));
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1355
    if (lua_gettop(L) <> 2) and ((statInfo <> siPlayerKills)
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1356
            and (statInfo <> siClanHealth)) then
9171
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  1357
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1358
        LuaParameterCountError('SendStat', 'statInfoType, color', lua_gettop(L));
9171
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  1359
        end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1360
    else if (lua_gettop(L) <> 3) and ((statInfo = siPlayerKills)
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1361
            or (statInfo = siClanHealth)) then
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1362
        begin
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1363
        LuaParameterCountError('SendStat', 'siClanHealth, color, teamname', lua_gettop(L));
9173
575dd8fe4a55 LuaAPI sendstat finds correct clan colors by team names on siPlayerKills
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9171
diff changeset
  1364
        end
9171
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  1365
    else
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1366
        begin
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1367
        if ((statInfo = siPlayerKills) or (statInfo = siClanHealth)) then
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1368
            begin
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1369
            // 3: team name
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1370
            for i:= 0 to Pred(TeamsCount) do
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1371
                begin
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1372
                with TeamsArray[i]^ do
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1373
                    begin
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1374
                        if TeamName = lua_tostring(L, 3) then
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1375
                            begin
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1376
                            color := uUtils.IntToStr(Clan^.Color);
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1377
                            Break;
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1378
                            end
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1379
                    end
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1380
                end;
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1381
            if (statInfo = siPlayerKills) then
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1382
                begin
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1383
                    SendStat(siPlayerKills, color + ' ' +
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1384
                        lua_tostring(L, 2) + ' ' + TeamsArray[i]^.TeamName);
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1385
                end
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1386
            else if (statInfo = siClanHealth) then
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1387
                begin
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1388
                    SendStat(siClanHealth, color + ' ' +
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1389
                        lua_tostring(L, 2));
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1390
                end
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1391
            end
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1392
        else
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1393
            begin
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1394
            SendStat(statInfo,lua_tostring(L, 2));
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1395
            end;
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1396
        end;
9171
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  1397
    lc_sendstat:= 0
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  1398
end;
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  1399
9180
d19c09670ec8 changed variable and function name
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9179
diff changeset
  1400
function lc_sendhealthstatsoff(L : Plua_State) : LongInt; Cdecl;
9174
d328fe17b195 made lua scripts able to turn off automatic game stats
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9173
diff changeset
  1401
begin
d328fe17b195 made lua scripts able to turn off automatic game stats
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9173
diff changeset
  1402
    L:= L; // avoid compiler hint
9180
d19c09670ec8 changed variable and function name
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9179
diff changeset
  1403
    uStats.SendHealthStatsOn := false;
d19c09670ec8 changed variable and function name
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9179
diff changeset
  1404
    lc_sendhealthstatsoff:= 0
9174
d328fe17b195 made lua scripts able to turn off automatic game stats
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9173
diff changeset
  1405
end;
d328fe17b195 made lua scripts able to turn off automatic game stats
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9173
diff changeset
  1406
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1407
function lc_findplace(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1408
var gear: PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1409
    fall: boolean;
4629
b5d726bc4f8d FindPlace in lua now returns null for failure to find a place, and accepts a 5th parameter to try finding a place without considering proximity (note that this can place a gear right next to mines).
nemo
parents: 4590
diff changeset
  1410
    tryhard: boolean;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1411
    left, right: LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1412
begin
4629
b5d726bc4f8d FindPlace in lua now returns null for failure to find a place, and accepts a 5th parameter to try finding a place without considering proximity (note that this can place a gear right next to mines).
nemo
parents: 4590
diff changeset
  1413
    tryhard:= false;
b5d726bc4f8d FindPlace in lua now returns null for failure to find a place, and accepts a 5th parameter to try finding a place without considering proximity (note that this can place a gear right next to mines).
nemo
parents: 4590
diff changeset
  1414
    if (lua_gettop(L) <> 4) and (lua_gettop(L) <> 5) then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1415
        LuaParameterCountError('FindPlace', 'gearUid, fall, left, right[, tryHarder]', lua_gettop(L))
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1416
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1417
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1418
        gear:= GearByUID(lua_tointeger(L, 1));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1419
        fall:= lua_toboolean(L, 2);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1420
        left:= lua_tointeger(L, 3);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1421
        right:= lua_tointeger(L, 4);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1422
        if lua_gettop(L) = 5 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1423
            tryhard:= lua_toboolean(L, 5);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1424
        if gear <> nil then
4629
b5d726bc4f8d FindPlace in lua now returns null for failure to find a place, and accepts a 5th parameter to try finding a place without considering proximity (note that this can place a gear right next to mines).
nemo
parents: 4590
diff changeset
  1425
            FindPlace(gear, fall, left, right, tryhard);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1426
        if gear <> nil then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1427
            lua_pushinteger(L, gear^.uid)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1428
        else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1429
            lua_pushnil(L);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1430
        end;
4629
b5d726bc4f8d FindPlace in lua now returns null for failure to find a place, and accepts a 5th parameter to try finding a place without considering proximity (note that this can place a gear right next to mines).
nemo
parents: 4590
diff changeset
  1431
    lc_findplace:= 1
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1432
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1433
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1434
function lc_playsound(L : Plua_State) : LongInt; Cdecl;
4516
ecf012a762d8 add PlaySound(soundType, hogGearUID) -- this roundabout way to reference a team seems to be how things are done in lua right now. might need changing in future
nemo
parents: 4502
diff changeset
  1435
var gear: PGear;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1436
begin
4516
ecf012a762d8 add PlaySound(soundType, hogGearUID) -- this roundabout way to reference a team seems to be how things are done in lua right now. might need changing in future
nemo
parents: 4502
diff changeset
  1437
    if lua_gettop(L) = 1 then
ecf012a762d8 add PlaySound(soundType, hogGearUID) -- this roundabout way to reference a team seems to be how things are done in lua right now. might need changing in future
nemo
parents: 4502
diff changeset
  1438
        PlaySound(TSound(lua_tointeger(L, 1)))
ecf012a762d8 add PlaySound(soundType, hogGearUID) -- this roundabout way to reference a team seems to be how things are done in lua right now. might need changing in future
nemo
parents: 4502
diff changeset
  1439
    else if lua_gettop(L) = 2 then
ecf012a762d8 add PlaySound(soundType, hogGearUID) -- this roundabout way to reference a team seems to be how things are done in lua right now. might need changing in future
nemo
parents: 4502
diff changeset
  1440
        begin
ecf012a762d8 add PlaySound(soundType, hogGearUID) -- this roundabout way to reference a team seems to be how things are done in lua right now. might need changing in future
nemo
parents: 4502
diff changeset
  1441
        gear:= GearByUID(lua_tointeger(L, 2));
ecf012a762d8 add PlaySound(soundType, hogGearUID) -- this roundabout way to reference a team seems to be how things are done in lua right now. might need changing in future
nemo
parents: 4502
diff changeset
  1442
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
5638
e35ba2a400d8 Try to avoid overlapping voices for major statements (not things like byebye or oof)
nemo
parents: 5612
diff changeset
  1443
            AddVoice(TSound(lua_tointeger(L, 1)),gear^.Hedgehog^.Team^.Voicepack)
4516
ecf012a762d8 add PlaySound(soundType, hogGearUID) -- this roundabout way to reference a team seems to be how things are done in lua right now. might need changing in future
nemo
parents: 4502
diff changeset
  1444
        end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1445
    else LuaParameterCountError('PlaySound', 'soundId', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1446
    lc_playsound:= 0;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1447
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1448
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1449
function lc_addteam(L : Plua_State) : LongInt; Cdecl;
4517
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1450
var np: LongInt;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1451
begin
4517
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1452
    np:= lua_gettop(L);
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1453
    if (np < 5) or (np > 6) then
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1454
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1455
        LuaParameterCountError('AddTeam', 'teamname, color, grave, fort, voicepack[, flag]', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1456
        //lua_pushnil(L)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1457
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1458
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1459
        begin
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  1460
        ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true, true);
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  1461
        ParseCommand('grave ' + lua_tostring(L, 3), true, true);
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  1462
        ParseCommand('fort ' + lua_tostring(L, 4), true, true);
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  1463
        ParseCommand('voicepack ' + lua_tostring(L, 5), true, true);
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  1464
        if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1465
        CurrentTeam^.Binds:= DefaultBinds
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1466
        // fails on x64
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1467
        //lua_pushinteger(L, LongInt(CurrentTeam));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1468
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1469
    lc_addteam:= 0;//1;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1470
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1471
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1472
function lc_addhog(L : Plua_State) : LongInt; Cdecl;
3271
0405e07ca44b * add some kind of SniperRifle training mission
sheepluva
parents: 3209
diff changeset
  1473
var temp: ShortString;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1474
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1475
    if lua_gettop(L) <> 4 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1476
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1477
        LuaParameterCountError('AddHog', 'hogname, botlevel, health, hat', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1478
        lua_pushnil(L)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1479
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1480
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1481
        begin
5549
ccfb9b8ab9d1 sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents: 5547
diff changeset
  1482
        temp:= lua_tostring(L, 4);
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  1483
        ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  1484
        ParseCommand('hat ' + temp, true, true);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1485
        lua_pushinteger(L, CurrentHedgehog^.Gear^.uid);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1486
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1487
    lc_addhog:= 1;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1488
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1489
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1490
function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1491
var gear: PGear;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1492
begin
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1493
    if lua_gettop(L) <> 2 then
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1494
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1495
        LuaParameterCountError('HogTurnLeft', 'gearUid, boolean', lua_gettop(L));
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1496
        end
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1497
    else
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1498
        begin
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1499
        gear:= GearByUID(lua_tointeger(L, 1));
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1500
        if gear <> nil then
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1501
            gear^.dX.isNegative:= lua_toboolean(L, 2);
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1502
        end;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1503
    lc_hogturnleft:= 0;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1504
end;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1505
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1506
function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1507
var gear: PGear;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1508
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1509
    if lua_gettop(L) <> 1 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1510
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1511
        LuaParameterCountError('GetGearPosition', 'gearUid', lua_gettop(L));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1512
        lua_pushnil(L);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1513
        lua_pushnil(L)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1514
        end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1515
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1516
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1517
        gear:= GearByUID(lua_tointeger(L, 1));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1518
        if gear <> nil then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1519
            begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1520
            lua_pushinteger(L, hwRound(gear^.X));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1521
            lua_pushinteger(L, hwRound(gear^.Y))
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1522
            end
5964
44d2dc3b438f return nil for position if no gear
nemo
parents: 5900
diff changeset
  1523
        else
44d2dc3b438f return nil for position if no gear
nemo
parents: 5900
diff changeset
  1524
            begin
44d2dc3b438f return nil for position if no gear
nemo
parents: 5900
diff changeset
  1525
            lua_pushnil(L);
44d2dc3b438f return nil for position if no gear
nemo
parents: 5900
diff changeset
  1526
            lua_pushnil(L)
44d2dc3b438f return nil for position if no gear
nemo
parents: 5900
diff changeset
  1527
            end;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1528
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1529
    lc_getgearposition:= 2;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1530
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1531
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1532
function lc_setgearposition(L : Plua_State) : LongInt; Cdecl;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1533
var gear: PGear;
4832
e55e2b6f59b0 update collision in set gear position
nemo
parents: 4780
diff changeset
  1534
    col: boolean;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1535
    x, y: LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1536
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1537
    if lua_gettop(L) <> 3 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1538
        LuaParameterCountError('SetGearPosition', 'gearUid, x, y', lua_gettop(L))
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1539
    else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1540
        begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1541
        gear:= GearByUID(lua_tointeger(L, 1));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1542
        if gear <> nil then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1543
            begin
4832
e55e2b6f59b0 update collision in set gear position
nemo
parents: 4780
diff changeset
  1544
            col:= gear^.CollisionIndex >= 0;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1545
            x:= lua_tointeger(L, 2);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1546
            y:= lua_tointeger(L, 3);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1547
            if col then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1548
                DeleteCI(gear);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1549
            gear^.X:= int2hwfloat(x);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1550
            gear^.Y:= int2hwfloat(y);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1551
            if col then
9291
15f7bb217b66 Make add/delete consistent (this has bugged me for so long)
nemo
parents: 9285
diff changeset
  1552
                AddCI(gear);
4832
e55e2b6f59b0 update collision in set gear position
nemo
parents: 4780
diff changeset
  1553
            SetAllToActive
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1554
            end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1555
        end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1556
    lc_setgearposition:= 0
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1557
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1558
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1559
function lc_getgeartarget(L : Plua_State) : LongInt; Cdecl;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1560
var gear: PGear;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1561
begin
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1562
    if lua_gettop(L) <> 1 then
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1563
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1564
        LuaParameterCountError('GetGearTarget', 'gearUid', lua_gettop(L));
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1565
        lua_pushnil(L);
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1566
        lua_pushnil(L)
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1567
        end
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1568
    else
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1569
        begin
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1570
        gear:= GearByUID(lua_tointeger(L, 1));
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1571
        if gear <> nil then
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1572
            begin
5612
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  1573
            lua_pushinteger(L, gear^.Target.X);
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  1574
            lua_pushinteger(L, gear^.Target.Y)
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  1575
            end
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  1576
        else
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  1577
            begin
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  1578
            lua_pushnil(L);
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  1579
            lua_pushnil(L)
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1580
            end
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1581
        end;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1582
    lc_getgeartarget:= 2;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1583
end;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1584
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1585
function lc_setgeartarget(L : Plua_State) : LongInt; Cdecl;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1586
var gear: PGear;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1587
begin
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1588
    if lua_gettop(L) <> 3 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1589
        LuaParameterCountError('SetGearTarget', 'gearUid, x, y', lua_gettop(L))
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1590
    else
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1591
        begin
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1592
        gear:= GearByUID(lua_tointeger(L, 1));
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1593
        if gear <> nil then
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1594
            begin
5612
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  1595
            gear^.Target.X:= lua_tointeger(L, 2);
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  1596
            gear^.Target.Y:= lua_tointeger(L, 3)
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1597
            end
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1598
        end;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1599
    lc_setgeartarget:= 0
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1600
end;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  1601
4517
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1602
function lc_getgearvelocity(L : Plua_State) : LongInt; Cdecl;
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1603
var gear: PGear;
6780
166ee5275915 tweak take 2
nemo
parents: 6779
diff changeset
  1604
var t: LongInt;
4517
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1605
begin
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1606
    if lua_gettop(L) <> 1 then
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1607
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1608
        LuaParameterCountError('GetGearVelocity', 'gearUid', lua_gettop(L));
4517
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1609
        lua_pushnil(L);
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1610
        lua_pushnil(L)
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1611
        end
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1612
    else
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1613
        begin
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1614
        gear:= GearByUID(lua_tointeger(L, 1));
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1615
        if gear <> nil then
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1616
            begin
6780
166ee5275915 tweak take 2
nemo
parents: 6779
diff changeset
  1617
            t:= hwRound(gear^.dX * 1000000);
6779
ccd8aecaff6d Small tweak to return something more useful in the negative 0 case on dX
nemo
parents: 6764
diff changeset
  1618
            // gear dX determines hog orientation
6780
166ee5275915 tweak take 2
nemo
parents: 6779
diff changeset
  1619
            if (gear^.dX.isNegative) and (t = 0) then t:= -1;
166ee5275915 tweak take 2
nemo
parents: 6779
diff changeset
  1620
            lua_pushinteger(L, t);
5074
16f9e2d1f3b2 eh. 1,000,000 might be better...
nemo
parents: 5073
diff changeset
  1621
            lua_pushinteger(L, hwRound(gear^.dY * 1000000))
4517
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1622
            end
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1623
        end;
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1624
    lc_getgearvelocity:= 2;
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1625
end;
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1626
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1627
function lc_setgearvelocity(L : Plua_State) : LongInt; Cdecl;
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1628
var gear: PGear;
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1629
begin
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1630
    if lua_gettop(L) <> 3 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1631
        LuaParameterCountError('SetGearVelocity', 'gearUid, dx, dy', lua_gettop(L))
4517
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1632
    else
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1633
        begin
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1634
        gear:= GearByUID(lua_tointeger(L, 1));
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1635
        if gear <> nil then
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1636
            begin
5074
16f9e2d1f3b2 eh. 1,000,000 might be better...
nemo
parents: 5073
diff changeset
  1637
            gear^.dX:= int2hwFloat(lua_tointeger(L, 2)) / 1000000;
16f9e2d1f3b2 eh. 1,000,000 might be better...
nemo
parents: 5073
diff changeset
  1638
            gear^.dY:= int2hwFloat(lua_tointeger(L, 3)) / 1000000;
4517
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1639
            SetAllToActive;
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1640
            end
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1641
        end;
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1642
    lc_setgearvelocity:= 0
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1643
end;
0618b31023dc added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead.
Henek
parents: 4516
diff changeset
  1644
3736
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1645
function lc_setzoom(L : Plua_State) : LongInt; Cdecl;
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1646
begin
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1647
    if lua_gettop(L) <> 1 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1648
        LuaParameterCountError('SetZoom', 'zoomLevel', lua_gettop(L))
3736
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1649
    else
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1650
        begin
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1651
        ZoomValue:= lua_tonumber(L, 1);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1652
        if ZoomValue < cMaxZoomLevel then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1653
            ZoomValue:= cMaxZoomLevel;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1654
        if ZoomValue > cMinZoomLevel then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1655
            ZoomValue:= cMinZoomLevel;
3736
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1656
        end;
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1657
    lc_setzoom:= 0
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1658
end;
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1659
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1660
function lc_getzoom(L : Plua_State) : LongInt; Cdecl;
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1661
begin
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1662
    if lua_gettop(L) <> 0 then
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1663
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1664
        LuaParameterCountError('GetZoom', '', lua_gettop(L));
3736
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1665
        lua_pushnil(L)
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1666
        end
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1667
    else
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1668
        lua_pushnumber(L, ZoomValue);
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1669
    lc_getzoom:= 1
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1670
end;
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  1671
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1672
function lc_setammo(L : Plua_State) : LongInt; Cdecl;
3368
791fa4664209 Engine:
smxx
parents: 3346
diff changeset
  1673
var np: LongInt;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1674
begin
3368
791fa4664209 Engine:
smxx
parents: 3346
diff changeset
  1675
    np:= lua_gettop(L);
791fa4664209 Engine:
smxx
parents: 3346
diff changeset
  1676
    if (np < 4) or (np > 5) then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1677
        LuaParameterCountError('SetAmmo', 'ammoType, count, probability, delay[, numberInCrate]', lua_gettop(L))
3368
791fa4664209 Engine:
smxx
parents: 3346
diff changeset
  1678
    else if np = 4 then
791fa4664209 Engine:
smxx
parents: 3346
diff changeset
  1679
        ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), 1)
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1680
    else
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  1681
        ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1682
    lc_setammo:= 0
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1683
end;
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1684
9751
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  1685
function lc_setammodelay(L : Plua_State) : LongInt; Cdecl;
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  1686
var np: LongInt;
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  1687
begin
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  1688
    np:= lua_gettop(L);
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  1689
    if (np <> 2) then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1690
        LuaParameterCountError('SetAmmoDelay', 'ammoType, delay', lua_gettop(L))
9751
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  1691
    else
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  1692
        ScriptSetAmmoDelay(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2));
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  1693
    lc_setammodelay:= 0
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  1694
end;
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  1695
6529
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1696
function lc_setammostore(L : Plua_State) : LongInt; Cdecl;
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1697
var np: LongInt;
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1698
begin
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1699
    np:= lua_gettop(L);
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1700
    if (np <> 4) then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1701
        LuaParameterCountError('SetAmmoStore', 'loadouts, probabilities, delays, reinforments', lua_gettop(L))
6529
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1702
    else
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1703
        begin
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1704
        ScriptAmmoLoadout:= lua_tostring(L, 1);
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1705
        ScriptAmmoProbability:= lua_tostring(L, 2);
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1706
        ScriptAmmoDelay:= lua_tostring(L, 3);
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1707
        ScriptAmmoReinforcement:= lua_tostring(L, 4);
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1708
        end;
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1709
    lc_setammostore:= 0
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1710
end;
40f9ef7d824d added SetAmmoStore to lua for convinience
Henek
parents: 6523
diff changeset
  1711
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1712
function lc_getrandom(L : Plua_State) : LongInt; Cdecl;
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1713
var m : LongInt;
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1714
begin
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1715
    if lua_gettop(L) <> 1 then
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1716
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1717
        LuaParameterCountError('GetRandom', 'number', lua_gettop(L));
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1718
        lua_pushnil(L); // return value on stack (nil)
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1719
        end
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1720
    else
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1721
        begin
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1722
        m:= lua_tointeger(L, 1);
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1723
        if (m > 0) then
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1724
            lua_pushinteger(L, GetRandom(m))
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1725
        else
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1726
            begin
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1727
            LuaError('Lua: Tried to pass 0 to GetRandom!');
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1728
            lua_pushnil(L);
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1729
            end
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1730
        end;
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1731
    lc_getrandom:= 1
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  1732
end;
4399
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1733
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1734
function lc_setwind(L : Plua_State) : LongInt; Cdecl;
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1735
begin
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1736
    if lua_gettop(L) <> 1 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1737
        LuaParameterCountError('SetWind', 'windSpeed', lua_gettop(L))
4399
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1738
    else
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1739
        begin
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1740
        cWindSpeed:= int2hwfloat(lua_tointeger(L, 1)) / 100 * cMaxWindSpeed;
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1741
        cWindSpeedf:= SignAs(cWindSpeed,cWindSpeed).QWordValue / SignAs(_1,_1).QWordValue;
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1742
        if cWindSpeed.isNegative then
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1743
            CWindSpeedf := -cWindSpeedf;
5357
ec36f3d53f3c Tiny optimization: convert smooth wind indicator change gear into visual gear
unc0rr
parents: 5313
diff changeset
  1744
        AddVisualGear(0, 0, vgtSmoothWindBar);
4399
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1745
        end;
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1746
    lc_setwind:= 0
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  1747
end;
4502
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  1748
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  1749
function lc_getdatapath(L : Plua_State) : LongInt; Cdecl;
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  1750
begin
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  1751
    if lua_gettop(L) <> 0 then
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  1752
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1753
        LuaParameterCountError('GetDataPath', '', lua_gettop(L));
4502
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  1754
        lua_pushnil(L);
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  1755
        end
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  1756
    else
8025
07862ab415c8 Get rid of Pathz and UserPathz
unc0rr
parents: 8012
diff changeset
  1757
        lua_pushstring(L, str2pchar(cPathz[ptData]));
4502
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  1758
    lc_getdatapath:= 1
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  1759
end;
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1760
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5124
diff changeset
  1761
function lc_getuserdatapath(L : Plua_State) : LongInt; Cdecl;
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5124
diff changeset
  1762
begin
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5124
diff changeset
  1763
    if lua_gettop(L) <> 0 then
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5124
diff changeset
  1764
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1765
        LuaParameterCountError('GetUserDataPath', '', lua_gettop(L));
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5124
diff changeset
  1766
        lua_pushnil(L);
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5124
diff changeset
  1767
        end
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5124
diff changeset
  1768
    else
8025
07862ab415c8 Get rid of Pathz and UserPathz
unc0rr
parents: 8012
diff changeset
  1769
        lua_pushstring(L, str2pchar(cPathz[ptData]));
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5124
diff changeset
  1770
    lc_getuserdatapath:= 1
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5124
diff changeset
  1771
end;
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 5124
diff changeset
  1772
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1773
function lc_maphasborder(L : Plua_State) : LongInt; Cdecl;
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1774
begin
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1775
    if lua_gettop(L) <> 0 then
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1776
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1777
        LuaParameterCountError('MapHasBorder', '', lua_gettop(L));
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1778
        lua_pushnil(L);
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1779
        end
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1780
    else
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1781
        lua_pushboolean(L, hasBorder);
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1782
    lc_maphasborder:= 1
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  1783
end;
4869
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1784
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1785
function lc_getgearradius(L : Plua_State) : LongInt; Cdecl;
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1786
var gear : PGear;
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1787
begin
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1788
    if lua_gettop(L) <> 1 then
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1789
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1790
        LuaParameterCountError('GetGearRadius', 'gearUid', lua_gettop(L));
4869
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1791
        lua_pushnil(L); // return value on stack (nil)
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1792
        end
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1793
    else
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1794
        begin
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1795
        gear:= GearByUID(lua_tointeger(L, 1));
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1796
        if gear <> nil then
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1797
            lua_pushinteger(L, gear^.Radius)
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1798
        else
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1799
            lua_pushnil(L);
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1800
        end;
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1801
    lc_getgearradius:= 1
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  1802
end;
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1803
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1804
function lc_gethoghat(L : Plua_State): LongInt; Cdecl;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1805
var gear : PGear;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1806
begin
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1807
    if lua_gettop(L) <> 1 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1808
        LuaParameterCountError('GetHogHat', 'gearUid', lua_gettop(L))
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1809
    else begin
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1810
        gear := GearByUID(lua_tointeger(L, 1));
8228
8cc5dc7f7ef9 kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents: 8145
diff changeset
  1811
        if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1812
            lua_pushstring(L, str2pchar(gear^.Hedgehog^.Hat))
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1813
        else
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1814
            lua_pushnil(L);
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1815
    end;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1816
    lc_gethoghat := 1;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1817
end;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1818
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1819
function lc_sethoghat(L : Plua_State) : LongInt; Cdecl;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1820
var gear : PGear;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1821
    hat: ShortString;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1822
begin
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1823
    if lua_gettop(L) <> 2 then
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1824
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1825
        LuaParameterCountError('SetHogHat', 'gearUid, hat', lua_gettop(L));
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1826
        lua_pushnil(L)
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1827
        end
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1828
    else
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1829
        begin
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1830
        gear:= GearByUID(lua_tointeger(L, 1));
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1831
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
9748
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
  1832
            begin
5549
ccfb9b8ab9d1 sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents: 5547
diff changeset
  1833
            hat:= lua_tostring(L, 2);
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1834
            gear^.Hedgehog^.Hat:= hat;
9748
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
  1835
            AddFileLog('Changed hat to: '+hat);
7887
e987dff8e5f2 fix reserved hats from scripting
nemo
parents: 7805
diff changeset
  1836
            if (Length(hat) > 39) and (Copy(hat,1,8) = 'Reserved') and (Copy(hat,9,32) = gear^.Hedgehog^.Team^.PlayerHash) then
e987dff8e5f2 fix reserved hats from scripting
nemo
parents: 7805
diff changeset
  1837
                LoadHedgehogHat(gear^.Hedgehog^, 'Reserved/' + Copy(hat,9,Length(hat)-8))
e987dff8e5f2 fix reserved hats from scripting
nemo
parents: 7805
diff changeset
  1838
            else
9748
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
  1839
                LoadHedgehogHat(gear^.Hedgehog^, hat)
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
  1840
            end
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1841
        end;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1842
    lc_sethoghat:= 0;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  1843
end;
4985
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1844
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1845
function lc_placegirder(L : Plua_State) : LongInt; Cdecl;
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1846
begin
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1847
    if lua_gettop(L) <> 3 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1848
        LuaParameterCountError('PlaceGirder', 'x, y, state', lua_gettop(L))
4985
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1849
    else
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1850
        TryPlaceOnLand(
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1851
            lua_tointeger(L, 1) - SpritesData[sprAmGirder].Width div 2,
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1852
            lua_tointeger(L, 2) - SpritesData[sprAmGirder].Height div 2,
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1853
            sprAmGirder, lua_tointeger(L, 3), true, false);
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1854
    lc_placegirder:= 0
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  1855
end;
5013
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  1856
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  1857
function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  1858
begin
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  1859
    if lua_gettop(L) <> 0 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1860
        LuaParameterCountError('GetCurAmmoType', '', lua_gettop(L))
5013
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  1861
    else
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  1862
        lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType));
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  1863
    lc_getcurammotype := 1;
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  1864
end;
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1865
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1866
function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1867
begin
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1868
    if lua_gettop(L) <> 2 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1869
        LuaParameterCountError('SaveCampaignVar', 'varname, value', lua_gettop(L))
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1870
    else begin
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1871
        SendIPC('V!' + lua_tostring(L, 1) + ' ' + lua_tostring(L, 2) + #0);
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1872
    end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1873
    lc_savecampaignvar := 0;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1874
end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1875
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1876
function lc_getcampaignvar(L : Plua_State): LongInt; Cdecl;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1877
begin
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1878
    if (lua_gettop(L) <> 1) then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1879
        LuaParameterCountError('GetCampaignVar', 'varname', lua_gettop(L))
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1880
    else
9718
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9670
diff changeset
  1881
        SendIPCAndWaitReply('V?' + lua_tostring(L, 1) + #0);
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1882
    lua_pushstring(L, str2pchar(CampaignVariable));
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1883
    lc_getcampaignvar := 1;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1884
end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1885
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1886
function lc_hidehog(L: Plua_State): LongInt; Cdecl;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1887
var gear: PGear;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1888
begin
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1889
    if lua_gettop(L) <> 1 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1890
        LuaParameterCountError('HideHog', 'gearUid', lua_gettop(L))
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1891
    else
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1892
        begin
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1893
        gear:= GearByUID(lua_tointeger(L, 1));
8012
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1894
        HideHog(gear^.hedgehog)
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1895
        end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1896
    lc_hidehog := 0;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1897
end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1898
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1899
function lc_restorehog(L: Plua_State): LongInt; Cdecl;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8368
diff changeset
  1900
var i, h: LongInt;
8012
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1901
    uid: LongWord;
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1902
begin
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1903
    if lua_gettop(L) <> 1 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1904
        LuaParameterCountError('RestoreHog', 'gearUid', lua_gettop(L))
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1905
    else
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1906
        begin
8012
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1907
        uid:= LongWord(lua_tointeger(L, 1));
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1908
        if TeamsCount > 0 then
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1909
            for i:= 0 to Pred(TeamsCount) do
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1910
                for h:= 0 to cMaxHHIndex do
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1911
                    if (TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil) and (TeamsArray[i]^.Hedgehogs[h].GearHidden^.uid = uid) then
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1912
                        begin
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1913
                        RestoreHog(@TeamsArray[i]^.Hedgehogs[h]);
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1914
                        exit(0)
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  1915
                        end
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1916
        end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1917
    lc_restorehog := 0;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1918
end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  1919
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1920
// boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1921
function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1922
var rtn: Boolean;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1923
begin
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1924
    if lua_gettop(L) <> 5 then
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1925
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1926
        LuaParameterCountError('TestRectForObstacle', 'x1, y1, x2, y2, landOnly', lua_gettop(L));
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1927
        lua_pushnil(L); // return value on stack (nil)
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1928
        end
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1929
    else
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1930
        begin
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1931
        rtn:= TestRectancleForObstacle(
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1932
                    lua_tointeger(L, 1),
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1933
                    lua_tointeger(L, 2),
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1934
                    lua_tointeger(L, 3),
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1935
                    lua_tointeger(L, 4),
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1936
                    lua_toboolean(L, 5)
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1937
                    );
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1938
        lua_pushboolean(L, rtn);
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1939
        end;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1940
    lc_testrectforobstacle:= 1
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  1941
end;
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  1942
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  1943
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1944
function lc_getgravity(L : Plua_State) : LongInt; Cdecl;
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1945
begin
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1946
    if lua_gettop(L) <> 0 then
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1947
        LuaParameterCountError('GetGravity', '', lua_gettop(L))
10030
f40fdc566e94 * fix divbyzero found by GetGravity test (cWindSpeed was used where cMaxWindSpeed should have been)
sheepluva
parents: 10009
diff changeset
  1948
    else if cGravity.isNegative then
f40fdc566e94 * fix divbyzero found by GetGravity test (cWindSpeed was used where cMaxWindSpeed should have been)
sheepluva
parents: 10009
diff changeset
  1949
        lua_pushinteger(L, hwRound(-_0_5 + (cGravity * 50 / cMaxWindSpeed)))
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1950
    else
10030
f40fdc566e94 * fix divbyzero found by GetGravity test (cWindSpeed was used where cMaxWindSpeed should have been)
sheepluva
parents: 10009
diff changeset
  1951
        lua_pushinteger(L, hwRound( _0_5 + (cGravity * 50 / cMaxWindSpeed)));
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1952
    lc_getgravity:= 1
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1953
end;
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1954
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1955
function lc_setgravity(L : Plua_State) : LongInt; Cdecl;
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1956
begin
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1957
    if lua_gettop(L) <> 1 then
10030
f40fdc566e94 * fix divbyzero found by GetGravity test (cWindSpeed was used where cMaxWindSpeed should have been)
sheepluva
parents: 10009
diff changeset
  1958
        LuaParameterCountError('SetGravity', 'percent', lua_gettop(L))
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1959
    else
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1960
        begin
10030
f40fdc566e94 * fix divbyzero found by GetGravity test (cWindSpeed was used where cMaxWindSpeed should have been)
sheepluva
parents: 10009
diff changeset
  1961
        cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed;
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1962
        cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1963
        end;
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1964
    lc_setgravity:= 0
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1965
end;
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1966
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1967
function lc_setwaterline(L : Plua_State) : LongInt; Cdecl;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1968
var iterator: PGear;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1969
begin
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1970
    if lua_gettop(L) <> 1 then
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1971
         LuaParameterCountError('SetWaterLine', 'waterline', lua_gettop(L))
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1972
    else
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1973
        begin
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1974
        cWaterLine:= lua_tointeger(L,1);
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1975
        AllInactive:= false;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1976
        iterator:= GearsList;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1977
        while iterator <> nil do
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1978
            begin
9917
nemo
parents: 9914
diff changeset
  1979
            if not (iterator^.Kind in [gtPortal, gtAirAttack]) and (iterator^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) then
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1980
                begin
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1981
                iterator^.Active:= true;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1982
                if iterator^.dY.QWordValue = 0 then iterator^.dY.isNegative:= false;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1983
                iterator^.State:= iterator^.State or gstMoving;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1984
                DeleteCI(iterator)
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1985
                end;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1986
            iterator:= iterator^.NextGear
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1987
            end
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1988
        end;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1989
    lc_setwaterline:= 0
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1990
end;
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  1991
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  1992
function lc_setaihintsongear(L : Plua_State) : LongInt; Cdecl;
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  1993
var gear: PGear;
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  1994
begin
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  1995
    if lua_gettop(L) <> 2 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1996
        LuaParameterCountError('SetAIHintOnGear', 'gearUid, aiHints', lua_gettop(L))
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  1997
    else
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  1998
        begin
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  1999
        gear:= GearByUID(lua_tointeger(L, 1));
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2000
        if gear <> nil then
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2001
            gear^.aihints:= lua_tointeger(L, 2);
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2002
        end;
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2003
    lc_setaihintsongear:= 0
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2004
end;
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2005
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2006
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2007
function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl;
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2008
begin
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2009
    if lua_gettop(L) <> 1 then
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2010
        begin
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2011
        LuaParameterCountError('HedgewarsScriptLoad', 'scriptPath', lua_gettop(L));
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2012
        lua_pushnil(L)
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2013
        end
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2014
    else
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2015
        ScriptLoad(lua_tostring(L, 1));
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2016
    lc_hedgewarsscriptload:= 0;
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2017
end;
9397
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  2018
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  2019
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  2020
function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  2021
begin
9409
6564baf7dedf Store TrophyRace records in database
unc0rr
parents: 9397
diff changeset
  2022
    if lua_gettop(L) <> 4 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2023
        LuaParameterCountError('DeclareAchievement', 'achievementId, teamname, location, value', lua_gettop(L))
9397
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  2024
    else
9409
6564baf7dedf Store TrophyRace records in database
unc0rr
parents: 9397
diff changeset
  2025
        declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4));
9397
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  2026
    lc_declareachievement:= 0
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  2027
end;
9988
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2028
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2029
// stuff for testing the lua API
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2030
function lc_endluatest(L : Plua_State) : LongInt; Cdecl;
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2031
begin
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2032
    if lua_gettop(L) <> 1 then
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2033
        begin
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2034
        LuaParameterCountError('EndLuaAPITest', 'LUA_API_TEST_SUCCESSFUL or LUA_API_TEST_FAILED', lua_gettop(L));
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2035
        lua_pushnil(L);
10143
3636106f5b70 Fix setting lc_endluatest result
unc0rr
parents: 10131
diff changeset
  2036
        lc_endluatest:= 0;
9988
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2037
        end
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2038
    else
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2039
        begin
10031
9353632dc661 let log know when a test finished properly, so that an unexpected termination (segfault, divbyzero, etc) is easier to tell apart from test fail
sheepluva
parents: 10030
diff changeset
  2040
        WriteLnToConsole('Lua test finished');
9988
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2041
        halt(lua_tointeger(L, 1));
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2042
        end;
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2043
end;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2044
///////////////////
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2045
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2046
procedure ScriptPrintStack;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2047
var n, i : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2048
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2049
    n:= lua_gettop(luaState);
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
  2050
    WriteLnToConsole('Lua: Stack (' + inttostr(n) + ' elements):');
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2051
    for i:= 1 to n do
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2052
        if not lua_isboolean(luaState, i) then
5549
ccfb9b8ab9d1 sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents: 5547
diff changeset
  2053
            WriteLnToConsole('Lua:  ' + inttostr(i) + ': ' + lua_tostring(luaState, i))
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2054
        else if lua_toboolean(luaState, i) then
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
  2055
            WriteLnToConsole('Lua:  ' + inttostr(i) + ': true')
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2056
        else
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
  2057
            WriteLnToConsole('Lua:  ' + inttostr(i) + ': false');
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2058
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2059
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2060
procedure ScriptClearStack;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2061
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2062
    lua_settop(luaState, 0)
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2063
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2064
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2065
procedure ScriptSetNil(name : shortstring);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2066
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2067
    lua_pushnil(luaState);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2068
    lua_setglobal(luaState, Str2PChar(name));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2069
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2070
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2071
procedure ScriptSetInteger(name : shortstring; value : LongInt);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2072
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2073
    lua_pushinteger(luaState, value);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2074
    lua_setglobal(luaState, Str2PChar(name));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2075
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2076
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2077
procedure ScriptSetString(name : shortstring; value : shortstring);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2078
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2079
    lua_pushstring(luaState, Str2PChar(value));
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2080
    lua_setglobal(luaState, Str2PChar(name));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2081
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2082
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2083
function ScriptGetInteger(name : shortstring) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2084
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2085
    lua_getglobal(luaState, Str2PChar(name));
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2086
    ScriptGetInteger:= lua_tointeger(luaState, -1);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2087
    lua_pop(luaState, 1);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2088
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2089
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2090
function ScriptGetString(name : shortstring) : shortstring;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2091
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2092
    lua_getglobal(luaState, Str2PChar(name));
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2093
    ScriptGetString:= lua_tostring(luaState, -1);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2094
    lua_pop(luaState, 1);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2095
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2096
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2097
procedure ScriptOnGameInit;
6578
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2098
var i, j, k: LongInt;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2099
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2100
// not required if there is no script to run
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2101
if not ScriptLoaded then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2102
    exit;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2103
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2104
// push game variables so they may be modified by the script
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6924
diff changeset
  2105
ScriptSetInteger('BorderColor', ExplosionBorderColor);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2106
ScriptSetInteger('GameFlags', GameFlags);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2107
ScriptSetString('Seed', cSeed);
5676
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  2108
ScriptSetInteger('TemplateFilter', cTemplateFilter);
7567
da2aa8355d91 allow lua to specify template by number
nemo
parents: 7546
diff changeset
  2109
ScriptSetInteger('TemplateNumber', LuaTemplateNumber);
5676
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  2110
ScriptSetInteger('MapGen', cMapGen);
5583
63b274a4fb01 At mikade's request, expose screenheight/screenwidth and allow setting tag zoom level
nemo
parents: 5554
diff changeset
  2111
ScriptSetInteger('ScreenHeight', cScreenHeight);
63b274a4fb01 At mikade's request, expose screenheight/screenwidth and allow setting tag zoom level
nemo
parents: 5554
diff changeset
  2112
ScriptSetInteger('ScreenWidth', cScreenWidth);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2113
ScriptSetInteger('TurnTime', cHedgehogTurnTime);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2114
ScriptSetInteger('CaseFreq', cCaseFactor);
4162
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  2115
ScriptSetInteger('HealthCaseProb', cHealthCaseProb);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  2116
ScriptSetInteger('HealthCaseAmount', cHealthCaseAmount);
4221
a1bf0f6b0d65 added missing game modifiers to lua
Henek
parents: 4219
diff changeset
  2117
ScriptSetInteger('DamagePercent', cDamagePercent);
6557
e3cad9020778 Push RopePercent to lua to fix rope if not set
enveezee
parents: 6543
diff changeset
  2118
ScriptSetInteger('RopePercent', cRopePercent);
4003
ca0600ab38bf disable gfMines and update variable names (landadds -> minesnum, cLandAdditions -> cLandMines)
koda
parents: 3999
diff changeset
  2119
ScriptSetInteger('MinesNum', cLandMines);
4221
a1bf0f6b0d65 added missing game modifiers to lua
Henek
parents: 4219
diff changeset
  2120
ScriptSetInteger('MinesTime', cMinesTime);
a1bf0f6b0d65 added missing game modifiers to lua
Henek
parents: 4219
diff changeset
  2121
ScriptSetInteger('MineDudPercent', cMineDudPercent);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2122
ScriptSetInteger('Explosives', cExplosives);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2123
ScriptSetInteger('Delay', cInactDelay);
3774
af0e68ca273e Engine:
smaxx
parents: 3761
diff changeset
  2124
ScriptSetInteger('Ready', cReadyDelay);
3197
smxx
parents: 3058
diff changeset
  2125
ScriptSetInteger('SuddenDeathTurns', cSuddenDTurns);
4162
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  2126
ScriptSetInteger('WaterRise', cWaterRise);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  2127
ScriptSetInteger('HealthDecrease', cHealthDecrease);
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9815
diff changeset
  2128
ScriptSetInteger('GetAwayTime', cGetAwayTime);
6828
6a5d33bff0b0 At mikade's request. give scripting access to the map name prior to override.
nemo
parents: 6790
diff changeset
  2129
ScriptSetString('Map', cMapName);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2130
ScriptSetString('Theme', '');
4883
7cddc9201a1d added dummy for tardis and ugly icons for tardis and structure
Henek
parents: 4882
diff changeset
  2131
ScriptSetString('Goals', '');
7cddc9201a1d added dummy for tardis and ugly icons for tardis and structure
Henek
parents: 4882
diff changeset
  2132
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2133
ScriptCall('onGameInit');
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2134
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2135
// pop game variables
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2136
ParseCommand('seed ' + ScriptGetString('Seed'), true, true);
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2137
cTemplateFilter  := ScriptGetInteger('TemplateFilter');
7567
da2aa8355d91 allow lua to specify template by number
nemo
parents: 7546
diff changeset
  2138
LuaTemplateNumber:= ScriptGetInteger('TemplateNumber');
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2139
cMapGen          := ScriptGetInteger('MapGen');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2140
GameFlags        := ScriptGetInteger('GameFlags');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2141
cHedgehogTurnTime:= ScriptGetInteger('TurnTime');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2142
cCaseFactor      := ScriptGetInteger('CaseFreq');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2143
cHealthCaseProb  := ScriptGetInteger('HealthCaseProb');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2144
cHealthCaseAmount:= ScriptGetInteger('HealthCaseAmount');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2145
cDamagePercent   := ScriptGetInteger('DamagePercent');
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  2146
cRopePercent     := ScriptGetInteger('RopePercent');
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2147
cLandMines       := ScriptGetInteger('MinesNum');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2148
cMinesTime       := ScriptGetInteger('MinesTime');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2149
cMineDudPercent  := ScriptGetInteger('MineDudPercent');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2150
cExplosives      := ScriptGetInteger('Explosives');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2151
cInactDelay      := ScriptGetInteger('Delay');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2152
cReadyDelay      := ScriptGetInteger('Ready');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2153
cSuddenDTurns    := ScriptGetInteger('SuddenDeathTurns');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2154
cWaterRise       := ScriptGetInteger('WaterRise');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2155
cHealthDecrease  := ScriptGetInteger('HealthDecrease');
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9815
diff changeset
  2156
cGetAwayTime     := ScriptGetInteger('GetAwayTime');
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  2157
7771
ce6d4dd0c780 fix trophyrace. also tweak it a little
nemo
parents: 7754
diff changeset
  2158
if cMapName <> ScriptGetString('Map') then
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2159
    ParseCommand('map ' + ScriptGetString('Map'), true, true);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2160
if ScriptGetString('Theme') <> '' then
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2161
    ParseCommand('theme ' + ScriptGetString('Theme'), true, true);
4883
7cddc9201a1d added dummy for tardis and ugly icons for tardis and structure
Henek
parents: 4882
diff changeset
  2162
LuaGoals:= ScriptGetString('Goals');
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2163
6578
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2164
// Support lua changing the ammo layout - assume all hogs have same ammo, note this might leave a few ammo stores lying around.
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2165
k:= 0;
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2166
if (GameFlags and gfSharedAmmo) <> 0 then
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2167
    for i:= 0 to Pred(ClansCount) do
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2168
        for j:= 0 to Pred(ClansArray[i]^.TeamsNumber) do
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2169
            for k:= 0 to Pred(ClansArray[i]^.Teams[j]^.HedgehogsNumber) do
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2170
                ClansArray[i]^.Teams[j]^.Hedgehogs[k].AmmoStore:= i
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2171
else if (GameFlags and gfPerHogAmmo) <> 0 then
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2172
    for i:= 0 to Pred(TeamsCount) do
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2173
        for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2174
            begin
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2175
            TeamsArray[i]^.Hedgehogs[j].AmmoStore:= k;
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2176
            if StoreCnt-1 < k then AddAmmoStore;
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2177
            inc(k)
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2178
            end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2179
else
6578
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2180
    for i:= 0 to Pred(TeamsCount) do
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2181
        begin
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2182
        for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2183
            TeamsArray[i]^.Hedgehogs[j].AmmoStore:= k;
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2184
        if StoreCnt-1 < k then AddAmmoStore;
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2185
        inc(k)
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  2186
        end;
6743
864bf0f52a8c make onAmmoStoreInit optional in the case of onNewAmmoStore
nemo
parents: 6742
diff changeset
  2187
if ScriptExists('onAmmoStoreInit') or ScriptExists('onNewAmmoStore') then
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2188
    begin
6740
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2189
    // reset ammostore (quite unclean, but works?)
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2190
    uAmmos.freeModule;
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2191
    uAmmos.initModule;
6743
864bf0f52a8c make onAmmoStoreInit optional in the case of onNewAmmoStore
nemo
parents: 6742
diff changeset
  2192
    if ScriptExists('onAmmoStoreInit') then
864bf0f52a8c make onAmmoStoreInit optional in the case of onNewAmmoStore
nemo
parents: 6742
diff changeset
  2193
        begin
6752
nemo
parents: 6746
diff changeset
  2194
        ScriptPrepareAmmoStore;
6743
864bf0f52a8c make onAmmoStoreInit optional in the case of onNewAmmoStore
nemo
parents: 6742
diff changeset
  2195
        ScriptCall('onAmmoStoreInit');
6746
nemo
parents: 6743
diff changeset
  2196
        SetAmmoLoadout(ScriptAmmoLoadout);
nemo
parents: 6743
diff changeset
  2197
        SetAmmoProbability(ScriptAmmoProbability);
nemo
parents: 6743
diff changeset
  2198
        SetAmmoDelay(ScriptAmmoDelay);
nemo
parents: 6743
diff changeset
  2199
        SetAmmoReinforcement(ScriptAmmoReinforcement)
6743
864bf0f52a8c make onAmmoStoreInit optional in the case of onNewAmmoStore
nemo
parents: 6742
diff changeset
  2200
        end;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2201
    ScriptApplyAmmoStore
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2202
    end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2203
4235
6b1dfbd60a45 added TeamsCount and TotalTurns to lua as requested by mikade
Henek
parents: 4221
diff changeset
  2204
ScriptSetInteger('ClansCount', ClansCount);
9567
42bc1b58a242 This test is intended to avoid repeatedly calling 5 ScriptSetIntegers each script call, that won't ever change after the map is created.
nemo
parents: 9531
diff changeset
  2205
ScriptSetInteger('TeamsCount', TeamsCount);
42bc1b58a242 This test is intended to avoid repeatedly calling 5 ScriptSetIntegers each script call, that won't ever change after the map is created.
nemo
parents: 9531
diff changeset
  2206
mapDims:= false
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2207
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2208
5825
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  2209
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  2210
// Update values of screen dimensions and allow script to react to resolution change
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  2211
procedure ScriptOnScreenResize();
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  2212
begin
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  2213
ScriptSetInteger('ScreenHeight', cScreenHeight);
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  2214
ScriptSetInteger('ScreenWidth', cScreenWidth);
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  2215
ScriptCall('onScreenResize');
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  2216
end;
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  2217
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  2218
// custom script loader via physfs, passed to lua_load
8034
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents: 8031
diff changeset
  2219
const BUFSIZE = 1024;
5825
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  2220
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2221
procedure ScriptLoad(name : shortstring);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2222
var ret : LongInt;
5243
f2e31a7f953a check alternate script loading path
nemo
parents: 5238
diff changeset
  2223
      s : shortstring;
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  2224
      f : PFSFile;
8034
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents: 8031
diff changeset
  2225
    buf : array[0..Pred(BUFSIZE)] of byte;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2226
begin
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  2227
s:= cPathz[ptData] + name;
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  2228
if not pfsExists(s) then
9531
7fcdedc45589 Unbreak access to Data dir in profile broken in r8b48c27201af
unc0rr
parents: 9409
diff changeset
  2229
    begin
7fcdedc45589 Unbreak access to Data dir in profile broken in r8b48c27201af
unc0rr
parents: 9409
diff changeset
  2230
    AddFileLog('[LUA] Script not found: ' + name);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2231
    exit;
9531
7fcdedc45589 Unbreak access to Data dir in profile broken in r8b48c27201af
unc0rr
parents: 9409
diff changeset
  2232
    end;
6088
47d1b04003d1 - Frontend: don't pass /script for missions
unc0rr
parents: 6046
diff changeset
  2233
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  2234
f:= pfsOpenRead(s);
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2235
if f = nil then
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  2236
    exit;
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  2237
8073
5a289ef40fdb physfs compilation on windows
koda
parents: 8063
diff changeset
  2238
physfsReaderSetBuffer(@buf);
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  2239
ret:= lua_load(luaState, @physfsReader, f, Str2PChar(s));
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  2240
pfsClose(f);
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  2241
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2242
if ret <> 0 then
3774
af0e68ca273e Engine:
smaxx
parents: 3761
diff changeset
  2243
    begin
af0e68ca273e Engine:
smaxx
parents: 3761
diff changeset
  2244
    LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
5549
ccfb9b8ab9d1 sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents: 5547
diff changeset
  2245
    LuaError('Lua: ' + lua_tostring(luaState, -1));
3774
af0e68ca273e Engine:
smaxx
parents: 3761
diff changeset
  2246
    end
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2247
else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2248
    begin
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
  2249
    WriteLnToConsole('Lua: ' + name + ' loaded');
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2250
    // call the script file
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2251
    lua_pcall(luaState, 0, 0, 0);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2252
    ScriptLoaded:= true
8978
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8473
diff changeset
  2253
    end;
e6ef8fe314bd suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents: 8473
diff changeset
  2254
    hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp'));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2255
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2256
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2257
procedure SetGlobals;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2258
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2259
ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2260
ScriptSetInteger('GameTime', GameTicks);
4235
6b1dfbd60a45 added TeamsCount and TotalTurns to lua as requested by mikade
Henek
parents: 4221
diff changeset
  2261
ScriptSetInteger('TotalRounds', TotalRounds);
5676
a655dfab27d7 Scripting changes. Add override of mapgen, templatefilter. Expose waterline, add "GetAmmoCount". Default to amNothing in uAmmos if entry is not found.
nemo
parents: 5638
diff changeset
  2262
ScriptSetInteger('WaterLine', cWaterLine);
9567
42bc1b58a242 This test is intended to avoid repeatedly calling 5 ScriptSetIntegers each script call, that won't ever change after the map is created.
nemo
parents: 9531
diff changeset
  2263
if not mapDims then
7650
ffa26ebdf8ae LAND_HEIGHT/LAND_WIDTH need setting later now
nemo
parents: 7628
diff changeset
  2264
    begin
9567
42bc1b58a242 This test is intended to avoid repeatedly calling 5 ScriptSetIntegers each script call, that won't ever change after the map is created.
nemo
parents: 9531
diff changeset
  2265
    mapDims:= true;
7650
ffa26ebdf8ae LAND_HEIGHT/LAND_WIDTH need setting later now
nemo
parents: 7628
diff changeset
  2266
    ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
ffa26ebdf8ae LAND_HEIGHT/LAND_WIDTH need setting later now
nemo
parents: 7628
diff changeset
  2267
    ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT);
ffa26ebdf8ae LAND_HEIGHT/LAND_WIDTH need setting later now
nemo
parents: 7628
diff changeset
  2268
    ScriptSetInteger('LeftX', leftX);
ffa26ebdf8ae LAND_HEIGHT/LAND_WIDTH need setting later now
nemo
parents: 7628
diff changeset
  2269
    ScriptSetInteger('RightX', rightX);
ffa26ebdf8ae LAND_HEIGHT/LAND_WIDTH need setting later now
nemo
parents: 7628
diff changeset
  2270
    ScriptSetInteger('TopY', topY)
ffa26ebdf8ae LAND_HEIGHT/LAND_WIDTH need setting later now
nemo
parents: 7628
diff changeset
  2271
    end;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2272
if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2273
    ScriptSetInteger('CurrentHedgehog', CurrentHedgehog^.Gear^.UID)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2274
else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2275
    ScriptSetNil('CurrentHedgehog');
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2276
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2277
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2278
procedure GetGlobals;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2279
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2280
TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft');
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2281
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2282
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2283
procedure ScriptCall(fname : shortstring);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2284
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 8012
diff changeset
  2285
if (not ScriptLoaded) or (not ScriptExists(fname)) then
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2286
    exit;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2287
SetGlobals;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2288
lua_getglobal(luaState, Str2PChar(fname));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2289
if lua_pcall(luaState, 0, 0, 0) <> 0 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2290
    begin
5549
ccfb9b8ab9d1 sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents: 5547
diff changeset
  2291
    LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2292
    lua_pop(luaState, 1)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2293
    end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2294
GetGlobals;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2295
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2296
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2297
(*
5352
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2298
function ParseCommandOverride(key, value : shortstring) : shortstring;
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2299
begin
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2300
ParseCommandOverride:= value;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2301
if not ScriptExists('ParseCommandOverride') then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2302
    exit;
5352
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2303
lua_getglobal(luaState, Str2PChar('ParseCommandOverride'));
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2304
lua_pushstring(luaState, Str2PChar(key));
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2305
lua_pushstring(luaState, Str2PChar(value));
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2306
if lua_pcall(luaState, 2, 1, 0) <> 0 then
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2307
    begin
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2308
    LuaError('Lua: Error while calling ParseCommandOverride: ' + lua_tostring(luaState, -1));
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2309
    lua_pop(luaState, 1)
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2310
    end
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2311
else
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2312
    begin
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2313
    ParseCommandOverride:= lua_tostring(luaState, -1);
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2314
    lua_pop(luaState, 1)
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2315
    end;
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2316
end;
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2317
*)
5352
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2318
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2319
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2320
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2321
ScriptCall:= ScriptCall(fname, par1, 0, 0, 0)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2322
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2323
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2324
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2325
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2326
ScriptCall:= ScriptCall(fname, par1, par2, 0, 0)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2327
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2328
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2329
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2330
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2331
ScriptCall:= ScriptCall(fname, par1, par2, par3, 0)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2332
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2333
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2334
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2335
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 8012
diff changeset
  2336
if (not ScriptLoaded) or (not ScriptExists(fname)) then
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2337
    exit;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2338
SetGlobals;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2339
lua_getglobal(luaState, Str2PChar(fname));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2340
lua_pushinteger(luaState, par1);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2341
lua_pushinteger(luaState, par2);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2342
lua_pushinteger(luaState, par3);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2343
lua_pushinteger(luaState, par4);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2344
ScriptCall:= 0;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2345
if lua_pcall(luaState, 4, 1, 0) <> 0 then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2346
    begin
5549
ccfb9b8ab9d1 sheepluva pointed out there are 2 StrPas in pascal, in different units. Do conversion in LuaPas instead
nemo
parents: 5547
diff changeset
  2347
    LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2348
    lua_pop(luaState, 1)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2349
    end
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2350
else
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2351
    begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2352
    ScriptCall:= lua_tointeger(luaState, -1);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2353
    lua_pop(luaState, 1)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2354
    end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2355
GetGlobals;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2356
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2357
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2358
function ScriptExists(fname : shortstring) : boolean;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2359
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2360
if not ScriptLoaded then
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2361
    begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2362
    ScriptExists:= false;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2363
    exit
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2364
    end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2365
lua_getglobal(luaState, Str2PChar(fname));
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2366
ScriptExists:= not lua_isnoneornil(luaState, -1);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2367
lua_pop(luaState, -1)
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2368
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2369
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2370
procedure ScriptPrepareAmmoStore;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2371
var i: ShortInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2372
begin
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2373
ScriptAmmoLoadout:= '';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2374
ScriptAmmoDelay:= '';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2375
ScriptAmmoProbability:= '';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2376
ScriptAmmoReinforcement:= '';
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2377
for i:=1 to ord(High(TAmmoType)) do
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2378
    begin
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2379
    ScriptAmmoLoadout:= ScriptAmmoLoadout + '0';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2380
    ScriptAmmoProbability:= ScriptAmmoProbability + '0';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2381
    ScriptAmmoDelay:= ScriptAmmoDelay + '0';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2382
    ScriptAmmoReinforcement:= ScriptAmmoReinforcement + '0';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2383
    end;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2384
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2385
9750
8963312df207 fix misspelled variable name (cosmetic change)
sheepluva
parents: 9748
diff changeset
  2386
procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2387
begin
9750
8963312df207 fix misspelled variable name (cosmetic change)
sheepluva
parents: 9748
diff changeset
  2388
//if (ord(ammo) < 1) or (count > 9) or (count < 0) or (probability < 0) or (probability > 8) or (delay < 0) or (delay > 9) or (reinforcement < 0) or (reinforcement > 8) then
8963312df207 fix misspelled variable name (cosmetic change)
sheepluva
parents: 9748
diff changeset
  2389
if (ord(ammo) < 1) or (count > 9) or (probability > 8) or (delay > 9) or (reinforcement > 8) then
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2390
    exit;
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2391
ScriptAmmoLoadout[ord(ammo)]:= inttostr(count)[1];
9750
8963312df207 fix misspelled variable name (cosmetic change)
sheepluva
parents: 9748
diff changeset
  2392
ScriptAmmoProbability[ord(ammo)]:= inttostr(probability)[1];
9751
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2393
ScriptSetAmmoDelay(ammo, delay);
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  2394
ScriptAmmoReinforcement[ord(ammo)]:= inttostr(reinforcement)[1];
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2395
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2396
9751
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2397
procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte);
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2398
begin
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2399
// change loadout string if ammo store hasn't been initialized yet
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2400
if (StoreCnt = 0) then
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2401
begin
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2402
    if (delay <= 9) then
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2403
        ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1];
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2404
end
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2405
// change "live" delay values
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2406
else if (CurrentTeam <> nil) then
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2407
        ammoz[ammo].SkipTurns:= CurrentTeam^.Clan^.TurnNumber + delay;
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2408
end;
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2409
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2410
procedure ScriptApplyAmmoStore;
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2411
var i, j, k : LongInt;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2412
begin
5352
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2413
if (GameFlags and gfSharedAmmo) <> 0 then
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2414
    for i:= 0 to Pred(ClansCount) do
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2415
        begin
6740
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2416
        if ScriptExists('onNewAmmoStore') then
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2417
            begin
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2418
            ScriptPrepareAmmoStore;
6746
nemo
parents: 6743
diff changeset
  2419
            ScriptCall('onNewAmmoStore',i,-1);
nemo
parents: 6743
diff changeset
  2420
            SetAmmoLoadout(ScriptAmmoLoadout);
nemo
parents: 6743
diff changeset
  2421
            SetAmmoProbability(ScriptAmmoProbability);
nemo
parents: 6743
diff changeset
  2422
            SetAmmoDelay(ScriptAmmoDelay);
nemo
parents: 6743
diff changeset
  2423
            SetAmmoReinforcement(ScriptAmmoReinforcement)
6740
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2424
            end;
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2425
        AddAmmoStore;
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2426
        for j:= 0 to Pred(ClansArray[i]^.TeamsNumber) do
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2427
            for k:= 0 to Pred(ClansArray[i]^.Teams[j]^.HedgehogsNumber) do
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2428
                ClansArray[i]^.Teams[j]^.Hedgehogs[k].AmmoStore:= StoreCnt - 1
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2429
        end
5352
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2430
else if (GameFlags and gfPerHogAmmo) <> 0 then
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2431
    for i:= 0 to Pred(TeamsCount) do
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2432
        for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2433
            begin
6740
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2434
            if ScriptExists('onNewAmmoStore') then
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2435
                begin
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2436
                ScriptPrepareAmmoStore;
6746
nemo
parents: 6743
diff changeset
  2437
                ScriptCall('onNewAmmoStore',i,j);
nemo
parents: 6743
diff changeset
  2438
                SetAmmoLoadout(ScriptAmmoLoadout);
nemo
parents: 6743
diff changeset
  2439
                SetAmmoProbability(ScriptAmmoProbability);
nemo
parents: 6743
diff changeset
  2440
                SetAmmoDelay(ScriptAmmoDelay);
nemo
parents: 6743
diff changeset
  2441
                SetAmmoReinforcement(ScriptAmmoReinforcement)
6740
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2442
                end;
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2443
            AddAmmoStore;
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2444
            TeamsArray[i]^.Hedgehogs[j].AmmoStore:= StoreCnt - 1
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2445
            end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2446
else
5352
7f57d0c7816a Fix random weapons with per-hog ammo, fix ammo store loadout number in scripting for per-clan and per-hog ammo, add an advanced script hook into parsecommand to override values, add check for empty map in chSetMap, load script earlier in game params from frontend
nemo
parents: 5343
diff changeset
  2447
    for i:= 0 to Pred(TeamsCount) do
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2448
        begin
6740
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2449
        if ScriptExists('onNewAmmoStore') then
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2450
            begin
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2451
            ScriptPrepareAmmoStore;
6746
nemo
parents: 6743
diff changeset
  2452
            ScriptCall('onNewAmmoStore',i,-1);
nemo
parents: 6743
diff changeset
  2453
            SetAmmoLoadout(ScriptAmmoLoadout);
nemo
parents: 6743
diff changeset
  2454
            SetAmmoProbability(ScriptAmmoProbability);
nemo
parents: 6743
diff changeset
  2455
            SetAmmoDelay(ScriptAmmoDelay);
nemo
parents: 6743
diff changeset
  2456
            SetAmmoReinforcement(ScriptAmmoReinforcement)
6740
4167ebd563d9 Add a new script hook. onNewAmmoStore. This will allow scripts like The Specialists to define separate ammo sets for each hog
nemo
parents: 6700
diff changeset
  2457
            end;
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2458
        AddAmmoStore;
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2459
        for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2460
            TeamsArray[i]^.Hedgehogs[j].AmmoStore:= StoreCnt - 1
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  2461
        end
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2462
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2463
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2464
procedure initModule;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2465
var at : TGearType;
4453
15a483b2558a add visual gear registration
nemo
parents: 4450
diff changeset
  2466
    vgt: TVisualGearType;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2467
    am : TAmmoType;
9642
8a691e0f117a use consts for TStatInfo enum
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9291
diff changeset
  2468
    si : TStatInfoType;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2469
    st : TSound;
5118
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
  2470
    he : THogEffect;
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
  2471
    cg : TCapGroup;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2472
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2473
// initialize lua
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2474
luaState:= lua_open;
3045
41732f986b4f Clean Augean stables
unc0rr
parents: 3043
diff changeset
  2475
TryDo(luaState <> nil, 'lua_open failed', true);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2476
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2477
// open internal libraries
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2478
luaopen_base(luaState);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2479
luaopen_string(luaState);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2480
luaopen_math(luaState);
3724
b8678667e7dc Engine:
smaxx
parents: 3723
diff changeset
  2481
luaopen_table(luaState);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2482
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2483
// import some variables
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2484
ScriptSetString(_S'L', cLocale);
4502
759c1a3bb156 lua access to data dir by GetDataPath and made a new scripting translation system with Locale.lua as library and .lua files under Locale. Updated maps Basketball and Knockball to this new system.
Henek
parents: 4499
diff changeset
  2485
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2486
// import game flags
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2487
ScriptSetInteger('gfForts', gfForts);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2488
ScriptSetInteger('gfMultiWeapon', gfMultiWeapon);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2489
ScriptSetInteger('gfSolidLand', gfSolidLand);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2490
ScriptSetInteger('gfBorder', gfBorder);
8980
37f4cdd9cd2c don't draw a border if there's already a bottom border, avoid placing objects over gaps in the floor
nemo
parents: 8978
diff changeset
  2491
ScriptSetInteger('gfBottomBorder', gfBottomBorder);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2492
ScriptSetInteger('gfDivideTeams', gfDivideTeams);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2493
ScriptSetInteger('gfLowGravity', gfLowGravity);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2494
ScriptSetInteger('gfLaserSight', gfLaserSight);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2495
ScriptSetInteger('gfInvulnerable', gfInvulnerable);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2496
ScriptSetInteger('gfVampiric', gfVampiric);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2497
ScriptSetInteger('gfKarma', gfKarma);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2498
ScriptSetInteger('gfArtillery', gfArtillery);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2499
ScriptSetInteger('gfOneClanMode', gfOneClanMode);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2500
ScriptSetInteger('gfRandomOrder', gfRandomOrder);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2501
ScriptSetInteger('gfKing', gfKing);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2502
ScriptSetInteger('gfPlaceHog', gfPlaceHog);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2503
ScriptSetInteger('gfSharedAmmo', gfSharedAmmo);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2504
ScriptSetInteger('gfDisableGirders', gfDisableGirders);
4162
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  2505
ScriptSetInteger('gfDisableLandObjects', gfDisableLandObjects);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  2506
ScriptSetInteger('gfAISurvival', gfAISurvival);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  2507
ScriptSetInteger('gfInfAttack', gfInfAttack);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  2508
ScriptSetInteger('gfResetWeps', gfResetWeps);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  2509
ScriptSetInteger('gfPerHogAmmo', gfPerHogAmmo);
4219
4162db7c11bb fix so gfDisableWind can infact be used in lua
Henek
parents: 4162
diff changeset
  2510
ScriptSetInteger('gfDisableWind', gfDisableWind);
4319
81391b54b078 clean up and lua update, very minor
Henek
parents: 4243
diff changeset
  2511
ScriptSetInteger('gfMoreWind', gfMoreWind);
5016
9347d82a26cc added game mode Tag Team, mostly untested, please test :)
Henek
parents: 5013
diff changeset
  2512
ScriptSetInteger('gfTagTeam', gfTagTeam);
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9291
diff changeset
  2513
ScriptSetInteger('gfShoppaBorder', gfShoppaBorder);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2514
3894
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2515
ScriptSetInteger('gmLeft', gmLeft);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2516
ScriptSetInteger('gmRight', gmRight);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2517
ScriptSetInteger('gmUp', gmUp);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2518
ScriptSetInteger('gmDown', gmDown);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2519
ScriptSetInteger('gmSwitch', gmSwitch);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2520
ScriptSetInteger('gmAttack', gmAttack);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2521
ScriptSetInteger('gmLJump', gmLJump);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2522
ScriptSetInteger('gmHJump', gmHJump);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2523
ScriptSetInteger('gmDestroy', gmDestroy);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2524
ScriptSetInteger('gmSlot', gmSlot);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2525
ScriptSetInteger('gmWeapon', gmWeapon);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2526
ScriptSetInteger('gmTimer', gmTimer);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2527
ScriptSetInteger('gmAnimate', gmAnimate);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  2528
ScriptSetInteger('gmPrecise', gmPrecise);
3892
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  2529
ScriptSetInteger('gmAllStoppable', gmAllStoppable);
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  2530
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2531
// speech bubbles
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2532
ScriptSetInteger('SAY_SAY', 1);
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2533
ScriptSetInteger('SAY_THINK', 2);
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2534
ScriptSetInteger('SAY_SHOUT', 3);
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2535
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2536
// register gear types
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2537
for at:= Low(TGearType) to High(TGearType) do
3337
75e7455c69ed Engine:
smxx
parents: 3271
diff changeset
  2538
    ScriptSetInteger(EnumToStr(at), ord(at));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2539
4453
15a483b2558a add visual gear registration
nemo
parents: 4450
diff changeset
  2540
for vgt:= Low(TVisualGearType) to High(TVisualGearType) do
15a483b2558a add visual gear registration
nemo
parents: 4450
diff changeset
  2541
    ScriptSetInteger(EnumToStr(vgt), ord(vgt));
15a483b2558a add visual gear registration
nemo
parents: 4450
diff changeset
  2542
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2543
// register sounds
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2544
for st:= Low(TSound) to High(TSound) do
3337
75e7455c69ed Engine:
smxx
parents: 3271
diff changeset
  2545
    ScriptSetInteger(EnumToStr(st), ord(st));
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2546
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2547
// register ammo types
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2548
for am:= Low(TAmmoType) to High(TAmmoType) do
3337
75e7455c69ed Engine:
smxx
parents: 3271
diff changeset
  2549
    ScriptSetInteger(EnumToStr(am), ord(am));
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3539
diff changeset
  2550
9642
8a691e0f117a use consts for TStatInfo enum
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9291
diff changeset
  2551
for si:= Low(TStatInfoType) to High(TStatInfoType) do
8a691e0f117a use consts for TStatInfo enum
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9291
diff changeset
  2552
    ScriptSetInteger(EnumToStr(si), ord(si));
8a691e0f117a use consts for TStatInfo enum
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9291
diff changeset
  2553
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  2554
for he:= Low(THogEffect) to High(THogEffect) do
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  2555
    ScriptSetInteger(EnumToStr(he), ord(he));
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  2556
5118
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
  2557
for cg:= Low(TCapGroup) to High(TCapGroup) do
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
  2558
    ScriptSetInteger(EnumToStr(cg), ord(cg));
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
  2559
5527
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2560
ScriptSetInteger('gstDrowning'       ,$00000001);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2561
ScriptSetInteger('gstHHDriven'       ,$00000002);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2562
ScriptSetInteger('gstMoving'         ,$00000004);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2563
ScriptSetInteger('gstAttacked'       ,$00000008);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2564
ScriptSetInteger('gstAttacking'      ,$00000010);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2565
ScriptSetInteger('gstCollision'      ,$00000020);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2566
ScriptSetInteger('gstHHChooseTarget' ,$00000040);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2567
ScriptSetInteger('gstHHJumping'      ,$00000100);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2568
ScriptSetInteger('gsttmpFlag'        ,$00000200);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2569
ScriptSetInteger('gstHHThinking'     ,$00000800);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2570
ScriptSetInteger('gstNoDamage'       ,$00001000);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2571
ScriptSetInteger('gstHHHJump'        ,$00002000);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2572
ScriptSetInteger('gstAnimation'      ,$00004000);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2573
ScriptSetInteger('gstHHDeath'        ,$00008000);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2574
ScriptSetInteger('gstWinner'         ,$00010000);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2575
ScriptSetInteger('gstWait'           ,$00020000);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2576
ScriptSetInteger('gstNotKickable'    ,$00040000);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2577
ScriptSetInteger('gstLoser'          ,$00080000);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2578
ScriptSetInteger('gstHHGone'         ,$00100000);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2579
ScriptSetInteger('gstInvisible'      ,$00200000);
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  2580
8145
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 8077
diff changeset
  2581
// ai hints
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2582
ScriptSetInteger('aihUsualProcessing' ,$00000000);
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2583
ScriptSetInteger('aihDoesntMatter'    ,$00000001);
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2584
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2585
// register functions
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  2586
lua_register(luaState, _P'HideHog', @lc_hidehog);
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  2587
lua_register(luaState, _P'RestoreHog', @lc_restorehog);
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  2588
lua_register(luaState, _P'SaveCampaignVar', @lc_savecampaignvar);
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  2589
lua_register(luaState, _P'GetCampaignVar', @lc_getcampaignvar);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2590
lua_register(luaState, _P'band', @lc_band);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2591
lua_register(luaState, _P'bor', @lc_bor);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2592
lua_register(luaState, _P'bnot', @lc_bnot);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2593
lua_register(luaState, _P'div', @lc_div);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2594
lua_register(luaState, _P'GetInputMask', @lc_getinputmask);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2595
lua_register(luaState, _P'SetInputMask', @lc_setinputmask);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2596
lua_register(luaState, _P'AddGear', @lc_addgear);
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
  2597
lua_register(luaState, _P'EnableGameFlags', @lc_enablegameflags);
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
  2598
lua_register(luaState, _P'DisableGameFlags', @lc_disablegameflags);
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
  2599
lua_register(luaState, _P'ClearGameFlags', @lc_cleargameflags);
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
  2600
lua_register(luaState, _P'GetGameFlag', @lc_getgameflag);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2601
lua_register(luaState, _P'DeleteGear', @lc_deletegear);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2602
lua_register(luaState, _P'AddVisualGear', @lc_addvisualgear);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2603
lua_register(luaState, _P'DeleteVisualGear', @lc_deletevisualgear);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2604
lua_register(luaState, _P'GetVisualGearValues', @lc_getvisualgearvalues);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2605
lua_register(luaState, _P'SetVisualGearValues', @lc_setvisualgearvalues);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2606
lua_register(luaState, _P'SpawnHealthCrate', @lc_spawnhealthcrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2607
lua_register(luaState, _P'SpawnAmmoCrate', @lc_spawnammocrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2608
lua_register(luaState, _P'SpawnUtilityCrate', @lc_spawnutilitycrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2609
lua_register(luaState, _P'SpawnFakeHealthCrate', @lc_spawnfakehealthcrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2610
lua_register(luaState, _P'SpawnFakeAmmoCrate', @lc_spawnfakeammocrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2611
lua_register(luaState, _P'SpawnFakeUtilityCrate', @lc_spawnfakeutilitycrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2612
lua_register(luaState, _P'WriteLnToConsole', @lc_writelntoconsole);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2613
lua_register(luaState, _P'GetGearType', @lc_getgeartype);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2614
lua_register(luaState, _P'EndGame', @lc_endgame);
9171
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  2615
lua_register(luaState, _P'SendStat', @lc_sendstat);
9180
d19c09670ec8 changed variable and function name
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9179
diff changeset
  2616
lua_register(luaState, _P'SendHealthStatsOff', @lc_sendhealthstatsoff);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2617
lua_register(luaState, _P'FindPlace', @lc_findplace);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2618
lua_register(luaState, _P'SetGearPosition', @lc_setgearposition);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2619
lua_register(luaState, _P'GetGearPosition', @lc_getgearposition);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2620
lua_register(luaState, _P'SetGearTarget', @lc_setgeartarget);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2621
lua_register(luaState, _P'GetGearTarget', @lc_getgeartarget);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2622
lua_register(luaState, _P'SetGearVelocity', @lc_setgearvelocity);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2623
lua_register(luaState, _P'GetGearVelocity', @lc_getgearvelocity);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2624
lua_register(luaState, _P'ParseCommand', @lc_parsecommand);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2625
lua_register(luaState, _P'ShowMission', @lc_showmission);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2626
lua_register(luaState, _P'HideMission', @lc_hidemission);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2627
lua_register(luaState, _P'AddCaption', @lc_addcaption);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2628
lua_register(luaState, _P'SetAmmo', @lc_setammo);
9751
7a6038c3faa2 lua call SetAmmoDelay(ammotype, delay). note: as the engine does not yet support per-clan/team/hog ammo delay values, lua scripters will have to keep track of individual delays and set them accordingly before a hedgehog's turn (if they want usage cool-down behavior)
sheepluva
parents: 9750
diff changeset
  2629
lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2630
lua_register(luaState, _P'SetAmmoStore', @lc_setammostore);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2631
lua_register(luaState, _P'PlaySound', @lc_playsound);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2632
lua_register(luaState, _P'AddTeam', @lc_addteam);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2633
lua_register(luaState, _P'AddHog', @lc_addhog);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2634
lua_register(luaState, _P'AddAmmo', @lc_addammo);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2635
lua_register(luaState, _P'GetAmmoCount', @lc_getammocount);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2636
lua_register(luaState, _P'SetHealth', @lc_sethealth);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2637
lua_register(luaState, _P'GetHealth', @lc_gethealth);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2638
lua_register(luaState, _P'SetEffect', @lc_seteffect);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2639
lua_register(luaState, _P'GetEffect', @lc_geteffect);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2640
lua_register(luaState, _P'GetHogClan', @lc_gethogclan);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2641
lua_register(luaState, _P'GetClanColor', @lc_getclancolor);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2642
lua_register(luaState, _P'SetClanColor', @lc_setclancolor);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2643
lua_register(luaState, _P'GetHogTeamName', @lc_gethogteamname);
9788
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  2644
lua_register(luaState, _P'SetHogTeamName', @lc_sethogteamname);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2645
lua_register(luaState, _P'GetHogName', @lc_gethogname);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2646
lua_register(luaState, _P'SetHogName', @lc_sethogname);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2647
lua_register(luaState, _P'GetHogLevel', @lc_gethoglevel);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2648
lua_register(luaState, _P'SetHogLevel', @lc_sethoglevel);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2649
lua_register(luaState, _P'GetX', @lc_getx);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2650
lua_register(luaState, _P'GetY', @lc_gety);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2651
lua_register(luaState, _P'CopyPV', @lc_copypv);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2652
lua_register(luaState, _P'FollowGear', @lc_followgear);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2653
lua_register(luaState, _P'GetFollowGear', @lc_getfollowgear);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2654
lua_register(luaState, _P'SetState', @lc_setstate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2655
lua_register(luaState, _P'GetState', @lc_getstate);
7156
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  2656
lua_register(luaState, _P'GetTag', @lc_gettag);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2657
lua_register(luaState, _P'SetTag', @lc_settag);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2658
lua_register(luaState, _P'SetTimer', @lc_settimer);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2659
lua_register(luaState, _P'GetTimer', @lc_gettimer);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2660
lua_register(luaState, _P'SetZoom', @lc_setzoom);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2661
lua_register(luaState, _P'GetZoom', @lc_getzoom);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2662
lua_register(luaState, _P'HogSay', @lc_hogsay);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2663
lua_register(luaState, _P'SwitchHog', @lc_switchhog);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2664
lua_register(luaState, _P'HogTurnLeft', @lc_hogturnleft);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2665
lua_register(luaState, _P'CampaignLock', @lc_campaignlock);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2666
lua_register(luaState, _P'CampaignUnlock', @lc_campaignunlock);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2667
lua_register(luaState, _P'GetGearElasticity', @lc_getgearelasticity);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2668
lua_register(luaState, _P'GetGearRadius', @lc_getgearradius);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2669
lua_register(luaState, _P'GetGearMessage', @lc_getgearmessage);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2670
lua_register(luaState, _P'SetGearMessage', @lc_setgearmessage);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2671
lua_register(luaState, _P'GetGearPos', @lc_getgearpos);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2672
lua_register(luaState, _P'SetGearPos', @lc_setgearpos);
7726
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
  2673
lua_register(luaState, _P'GetGearCollisionMask', @lc_getgearcollisionmask);
1137406bce12 Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420
nemo
parents: 7721
diff changeset
  2674
lua_register(luaState, _P'SetGearCollisionMask', @lc_setgearcollisionmask);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2675
lua_register(luaState, _P'GetRandom', @lc_getrandom);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2676
lua_register(luaState, _P'SetWind', @lc_setwind);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2677
lua_register(luaState, _P'GetDataPath', @lc_getdatapath);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2678
lua_register(luaState, _P'GetUserDataPath', @lc_getuserdatapath);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2679
lua_register(luaState, _P'MapHasBorder', @lc_maphasborder);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2680
lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2681
lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2682
lua_register(luaState, _P'PlaceGirder', @lc_placegirder);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2683
lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  2684
lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle);
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  2685
lua_register(luaState, _P'GetGravity', @lc_getgravity);
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  2686
lua_register(luaState, _P'SetGravity', @lc_setgravity);
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  2687
lua_register(luaState, _P'SetWaterLine', @lc_setwaterline);
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2688
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2689
lua_register(luaState, _P'SetGearAIHints', @lc_setaihintsongear);
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  2690
lua_register(luaState, _P'HedgewarsScriptLoad', @lc_hedgewarsscriptload);
9397
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  2691
lua_register(luaState, _P'DeclareAchievement', @lc_declareachievement);
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  2692
9988
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2693
if cTestLua then
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2694
    begin
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2695
    ScriptSetInteger('TEST_SUCCESSFUL'  ,rtnTestSuccess);
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2696
    ScriptSetInteger('TEST_FAILED'      ,rtnTestFailed);
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2697
    lua_register(luaState, _P'EndLuaTest', @lc_endluatest);
317d46a2afd2 simple mechanism to run lua-based test cases. experimental - I will back it out if it turns out to be nonsense
sheepluva
parents: 9987
diff changeset
  2698
    end;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2699
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2700
ScriptClearStack; // just to be sure stack is empty
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2701
ScriptLoaded:= false;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2702
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2703
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2704
procedure freeModule;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2705
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2706
lua_close(luaState);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2707
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2708
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2709
{$ELSE}
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2710
procedure ScriptPrintStack;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2711
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2712
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2713
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2714
procedure ScriptClearStack;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2715
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2716
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2717
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2718
procedure ScriptLoad(name : shortstring);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2719
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2720
    name:= name; // avoid hint
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2721
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2722
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2723
procedure ScriptOnGameInit;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2724
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2725
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2726
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2727
procedure ScriptCall(fname : shortstring);
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2728
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2729
    fname:= fname; // avoid hint
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2730
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2731
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2732
function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2733
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2734
    // avoid hints
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2735
    fname:= fname;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2736
    par1:= par1;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2737
    par2:= par2;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2738
    par3:= par3;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2739
    par4:= par4;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2740
    ScriptCall:= 0
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2741
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2742
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2743
function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2744
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2745
    // avoid hints
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2746
    fname:= fname;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2747
    par1:= par1;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2748
    ScriptCall:= 0
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2749
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2750
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2751
function ScriptCall(fname : shortstring; par1, par2: LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2752
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2753
    // avoid hints
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2754
    fname:= fname;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2755
    par1:= par1;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2756
    par2:= par2;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2757
    ScriptCall:= 0
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2758
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2759
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2760
function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2761
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2762
    // avoid hints
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2763
    fname:= fname;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2764
    par1:= par1;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2765
    par2:= par2;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2766
    par3:= par3;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2767
    ScriptCall:= 0
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2768
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2769
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2770
function ScriptExists(fname : shortstring) : boolean;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2771
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2772
    fname:= fname; // avoid hint
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2773
    ScriptExists:= false
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2774
end;
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2775
(*
5410
8e7787065e2d small fix to have LUA_DISABLED working again
Xeli
parents: 5366
diff changeset
  2776
function ParseCommandOverride(key, value : shortstring) : shortstring;
8e7787065e2d small fix to have LUA_DISABLED working again
Xeli
parents: 5366
diff changeset
  2777
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2778
    // avoid hints
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2779
    key:= key;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2780
    value:= value;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  2781
    ParseCommandOverride:= ''
5410
8e7787065e2d small fix to have LUA_DISABLED working again
Xeli
parents: 5366
diff changeset
  2782
end;
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2783
*)
5410
8e7787065e2d small fix to have LUA_DISABLED working again
Xeli
parents: 5366
diff changeset
  2784
6430
93eefff23bcd fix compiling with LUA_DISABLED
koda
parents: 6415
diff changeset
  2785
procedure ScriptOnScreenResize;
93eefff23bcd fix compiling with LUA_DISABLED
koda
parents: 6415
diff changeset
  2786
begin
93eefff23bcd fix compiling with LUA_DISABLED
koda
parents: 6415
diff changeset
  2787
end;
93eefff23bcd fix compiling with LUA_DISABLED
koda
parents: 6415
diff changeset
  2788
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2789
procedure initModule;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2790
begin
9567
42bc1b58a242 This test is intended to avoid repeatedly calling 5 ScriptSetIntegers each script call, that won't ever change after the map is created.
nemo
parents: 9531
diff changeset
  2791
mapDims:= false;
3043
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2792
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2793
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2794
procedure freeModule;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2795
begin
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2796
end;
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2797
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2798
{$ENDIF}
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2799
end.