hedgewars/uScript.pas
author alfadur
Mon, 12 Feb 2024 21:26:35 +0300
changeset 16017 0b2e0a7d0431
parent 15998 91c487e7d11d
child 16004 2146cb7be36f
permissions -rw-r--r--
fix server build
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
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 11029
diff changeset
     3
 * Copyright (c) 2004-2015 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
 *
12107
0695302f3f5f Fix ScriptExists() destroying lua stack (fixes Bug #146)
sheepluva
parents: 12090
diff changeset
    26
 * Please keep https://hedgewars.org/kb/LuaAPI up to date!
5124
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
13728
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
    37
function ScriptLoad(name : shortstring; mustExist : boolean): boolean;
10150
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
    38
procedure ScriptOnPreviewInit;
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
    39
procedure ScriptOnGameInit;
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
    40
procedure ScriptOnScreenResize;
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
    41
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
    42
procedure ScriptSetString(name : shortstring; value : shortstring);
13754
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13752
diff changeset
    43
procedure ScriptSetMapGlobals;
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
    44
3acdb4dac6eb 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
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
    46
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
    47
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
    48
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
    49
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
    50
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
    51
10312
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
    52
procedure LuaParseString(s: shortString);
5410
8e7787065e2d small fix to have LUA_DISABLED working again
Xeli
parents: 5366
diff changeset
    53
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
    54
//function ParseCommandOverride(key, value : shortstring) : shortstring;  This did not work out well
5577
Xeli
parents: 5548 5554
diff changeset
    55
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
    56
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
    57
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
    58
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
    59
implementation
9205
abce6011f86c aaaaand let's not forget about lua, which has also a slightly revised build process
koda
parents: 9180
diff changeset
    60
6453
11c578d30bd3 Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents: 6430
diff changeset
    61
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
    62
    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
    63
    uConsts,
6543
697e9b730189 Fix build
unc0rr
parents: 6529
diff changeset
    64
    uGears,
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents: 6453
diff changeset
    65
    uGearsList,
6543
697e9b730189 Fix build
unc0rr
parents: 6529
diff changeset
    66
    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
    67
    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
    68
    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
    69
    uAmmos,
6763
8a06161ede49 Recount team health if modifying hedgehog health
nemo
parents: 6752
diff changeset
    70
    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
    71
    uSound,
4235
6b1dfbd60a45 added TeamsCount and TotalTurns to lua as requested by mikade
Henek
parents: 4221
diff changeset
    72
    uChat,
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
    73
    uStats,
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
    74
    uStore,
4357
a1fcfc341a52 Introduce unit uTypes in order to remove some cyclic unit dependencies
unC0Rr
parents: 4319
diff changeset
    75
    uRandom,
4359
83ef50815535 Move variables from uMisc to uVariables
unC0Rr
parents: 4357
diff changeset
    76
    uTypes,
4373
fe0e3903bb9e Introduce uCommands.pas
unC0Rr
parents: 4372
diff changeset
    77
    uVariables,
4374
bcefeeabaa33 Move some stuff from uMisc to uUtils
unC0Rr
parents: 4373
diff changeset
    78
    uCommands,
4403
unc0rr
parents: 4399
diff changeset
    79
    uCaptions,
4832
e55e2b6f59b0 update collision in set gear position
nemo
parents: 4780
diff changeset
    80
    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
    81
    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
    82
    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
    83
    uTextures,
4985
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
    84
    uLandGraphics,
11821
d8844d4c67de always include uUtils _after_ SysUtils
sheepluva
parents: 11737
diff changeset
    85
    uUtils,
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
    86
    uIO,
9283
76e68c136a11 Refactoring: VGSHandlers.inc -> uVisualGearsHandlers.pas
unc0rr
parents: 9245
diff changeset
    87
    uVisualGearsList,
9285
8e8b908970c2 Refactoring: get rid of GSHandlers.inc
unc0rr
parents: 9283
diff changeset
    88
    uGearsHandlersMess,
10978
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
    89
    uPhysFSLayer,
13674
3f6fae745f84 Make engine chat syntax translatable
Wuzzy <Wuzzy2@mail.ru>
parents: 13663
diff changeset
    90
    uLocale,
10978
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
    91
    SDLh
10129
cd2a64a1f4aa - Pas2C: make use of 'external' function decorator
unc0rr
parents: 10127
diff changeset
    92
{$IFNDEF PAS2C}
9952
32f5982604f4 Fix build (no idea what's going on in this branch btw)
unc0rr
parents: 9950
diff changeset
    93
    , 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
    94
{$ENDIF}
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
    95
    ;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3539
diff changeset
    96
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
    97
var luaState : Plua_State;
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
    98
    ScriptAmmoLoadout : shortstring;
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
    99
    ScriptAmmoProbability : shortstring;
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
   100
    ScriptAmmoDelay : shortstring;
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
   101
    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
   102
    ScriptLoaded : boolean;
10615
e3dcb235a354 fix some things I messed up with the drawing functions
sheepluva
parents: 10613
diff changeset
   103
    PointsBuffer: shortstring;
13216
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
   104
    PrevCursorX, PrevCursorY: LongInt;
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   105
    PendingTurnTimeLeft, PendingReadyTimeLeft: LongWord;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   106
    isPendingTurnTimeLeft, isPendingReadyTimeLeft: boolean;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3539
diff changeset
   107
11678
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
   108
{$IFDEF USE_LUA_SCRIPT}
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
   109
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
   110
procedure ScriptApplyAmmoStore; forward;
9750
8963312df207 fix misspelled variable name (cosmetic change)
sheepluva
parents: 9748
diff changeset
   111
procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward;
14640
03033213e800 Lua: Fix SetAmmoDelay not working properly when called after initialization
Wuzzy <Wuzzy2@mail.ru>
parents: 14639
diff changeset
   112
procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: LongWord); 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
   113
10293
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   114
var LuaDebugInfo: lua_Debug;
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   115
10617
457730f03c47 set globals in commandline lua
nemo
parents: 10615
diff changeset
   116
procedure SetGlobals; forward;
13747
be265ab8a4fb Call GetGlobals after entering Lua command with /lua
Wuzzy <Wuzzy2@mail.ru>
parents: 13745
diff changeset
   117
procedure GetGlobals; forward;
10312
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
   118
procedure LuaParseString(s: shortString);
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
   119
begin
10617
457730f03c47 set globals in commandline lua
nemo
parents: 10615
diff changeset
   120
    SetGlobals;
10312
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
   121
    AddFileLog('[Lua] input string: ' + s);
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
   122
    AddChatString(#3 + '[Lua] > ' + s);
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
   123
    if luaL_dostring(luaState, Str2PChar(s)) <> 0 then
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
   124
        begin
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
   125
        AddFileLog('[Lua] input string parsing error!');
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
   126
        AddChatString(#5 + '[Lua] Error while parsing!');
13747
be265ab8a4fb Call GetGlobals after entering Lua command with /lua
Wuzzy <Wuzzy2@mail.ru>
parents: 13745
diff changeset
   127
        end
be265ab8a4fb Call GetGlobals after entering Lua command with /lua
Wuzzy <Wuzzy2@mail.ru>
parents: 13745
diff changeset
   128
    else
be265ab8a4fb Call GetGlobals after entering Lua command with /lua
Wuzzy <Wuzzy2@mail.ru>
parents: 13745
diff changeset
   129
        GetGlobals();
10312
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
   130
end;
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
   131
10293
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   132
function LuaUpdateDebugInfo(): Boolean;
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   133
begin
10293
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   134
    FillChar(LuaDebugInfo, sizeof(LuaDebugInfo), 0);
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   135
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   136
    if lua_getstack(luaState, 1, @LuaDebugInfo) = 0 then
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   137
        exit(false); // stack not deep enough
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   138
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   139
    // get source name and line count
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   140
    lua_getinfo(luaState, PChar('Sl'), @LuaDebugInfo);
10293
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   141
    exit(true);
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   142
end;
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   143
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   144
procedure LuaErrorOrWarning(s: shortstring; isWarning: boolean);
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   145
var src, intro: shortstring;
10293
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   146
const
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   147
    maxsrclen = 20;
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   148
begin
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   149
    if isWarning then
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   150
        intro:= 'LUA WARNING'
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   151
    else
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   152
        intro:= 'LUA ERROR';
10293
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   153
    if LuaUpdateDebugInfo() then
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   154
        begin
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   155
        src:= StrPas(LuaDebugInfo.source);
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   156
        s:= intro + ': [ ... '
10293
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   157
            + copy(src, Length(src) - maxsrclen, maxsrclen - 3) + ':'
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   158
            + inttostr(LuaDebugInfo.currentLine) + ']: ' + s;
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   159
        end
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   160
    else
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   161
        s:= intro + ': ' + s;
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   162
    WriteLnToConsole(s);
13744
cb2857f55130 Change chat text color for Lua warnings to yellow
Wuzzy <Wuzzy2@mail.ru>
parents: 13743
diff changeset
   163
    if isWarning then
cb2857f55130 Change chat text color for Lua warnings to yellow
Wuzzy <Wuzzy2@mail.ru>
parents: 13743
diff changeset
   164
        AddChatString(#0 + s)
cb2857f55130 Change chat text color for Lua warnings to yellow
Wuzzy <Wuzzy2@mail.ru>
parents: 13743
diff changeset
   165
    else
cb2857f55130 Change chat text color for Lua warnings to yellow
Wuzzy <Wuzzy2@mail.ru>
parents: 13743
diff changeset
   166
        AddChatString(#5 + s);
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   167
    if cTestLua and (not isWarning) then
10306
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10297
diff changeset
   168
        halt(HaltTestLuaError);
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   169
end;
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   170
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   171
procedure LuaError(s: shortstring);
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   172
begin
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   173
    LuaErrorOrWarning(s, false);
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   174
end;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   175
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   176
procedure LuaWarning(s: shortstring);
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   177
begin
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   178
    LuaErrorOrWarning(s, true);
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   179
end;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
   180
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   181
procedure LuaCallError(error, call, paramsyntax: shortstring);
10279
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   182
begin
10293
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   183
    LuaError(call + ': ' + error);
201ea4989985 state file name and line number in lua error messages
sheepluva
parents: 10291
diff changeset
   184
    LuaError('-- SYNTAX: ' + call + ' ( ' + paramsyntax + ' )');
10279
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   185
end;
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   186
10285
03b615d3c6e1 further WIP (better error messages)
sheepluva
parents: 10284
diff changeset
   187
procedure LuaParameterCountError(expected, call, paramsyntax: shortstring; wrongcount: LongInt); inline;
03b615d3c6e1 further WIP (better error messages)
sheepluva
parents: 10284
diff changeset
   188
begin
03b615d3c6e1 further WIP (better error messages)
sheepluva
parents: 10284
diff changeset
   189
    // TODO: i18n?
03b615d3c6e1 further WIP (better error messages)
sheepluva
parents: 10284
diff changeset
   190
    LuaCallError('Wrong number of parameters! (is: ' + inttostr(wrongcount) + ', should be: '+ expected + ')', call, paramsyntax);
03b615d3c6e1 further WIP (better error messages)
sheepluva
parents: 10284
diff changeset
   191
end;
03b615d3c6e1 further WIP (better error messages)
sheepluva
parents: 10284
diff changeset
   192
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   193
// compare with allowed count
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   194
function CheckLuaParamCount(L : Plua_State; count: LongInt; call, paramsyntax: shortstring): boolean; inline;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   195
var c: LongInt;
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   196
begin
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   197
    c:= lua_gettop(L);
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   198
    if c <> count then
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   199
        begin
10285
03b615d3c6e1 further WIP (better error messages)
sheepluva
parents: 10284
diff changeset
   200
        LuaParameterCountError('exactly ' + inttostr(count), call, paramsyntax, c);
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   201
        exit(false);
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   202
        end;
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   203
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   204
    CheckLuaParamCount:= true;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   205
end;
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   206
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   207
// check if is either count1 or count2
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   208
function CheckAndFetchParamCount(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   209
begin
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   210
    actual:= lua_gettop(L);
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   211
    if (actual <> count1) and (actual <> count2) then
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   212
        begin
10285
03b615d3c6e1 further WIP (better error messages)
sheepluva
parents: 10284
diff changeset
   213
        LuaParameterCountError('either ' + inttostr(count1) + ' or ' + inttostr(count2), call, paramsyntax, actual);
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   214
        exit(false);
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   215
        end;
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   216
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   217
    CheckAndFetchParamCount:= true;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   218
end;
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   219
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   220
// check if is in range of count1 and count2
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   221
function CheckAndFetchParamCountRange(L : Plua_State; count1, count2: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline;
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   222
begin
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   223
    actual:= lua_gettop(L);
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   224
    if (actual < count1) or (actual > count2) then
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   225
        begin
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   226
        LuaParameterCountError('at least ' + inttostr(count1) + ', but at most ' + inttostr(count2), call, paramsyntax, actual);
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   227
        exit(false);
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   228
        end;
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   229
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   230
    CheckAndFetchParamCountRange:= true;
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   231
end;
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
   232
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   233
// check if is same or higher as minCount
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   234
function CheckAndFetchLuaParamMinCount(L : Plua_State; minCount: LongInt; call, paramsyntax: shortstring; out actual: LongInt): boolean; inline;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   235
begin
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   236
    actual:= lua_gettop(L);
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   237
    if (actual < minCount) then
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   238
        begin
10285
03b615d3c6e1 further WIP (better error messages)
sheepluva
parents: 10284
diff changeset
   239
        LuaParameterCountError(inttostr(minCount) + ' or more', call, paramsyntax, actual);
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   240
        exit(false);
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   241
        end;
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   242
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   243
    CheckAndFetchLuaParamMinCount:= true;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   244
end;
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   245
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   246
function LuaToGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   247
begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   248
    if lua_isnoneornil(L, i) then i:= -1
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   249
    else i:= Trunc(lua_tonumber(L, i));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   250
    if (i < ord(Low(TGearType))) or (i > ord(High(TGearType))) then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   251
        begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   252
        LuaCallError('Invalid gearType!', call, paramsyntax);
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   253
        LuaToGearTypeOrd:= -1;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   254
        end
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   255
    else
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   256
        LuaToGearTypeOrd:= i;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   257
end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   258
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   259
function LuaToVisualGearTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   260
begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   261
    if lua_isnoneornil(L, i) then i:= -1
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   262
    else i:= Trunc(lua_tonumber(L, i));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   263
    if (i < ord(Low(TVisualGearType))) or (i > ord(High(TVisualGearType))) then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   264
        begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   265
        LuaCallError('Invalid visualGearType!', call, paramsyntax);
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   266
        LuaToVisualGearTypeOrd:= -1;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   267
        end
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   268
    else
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   269
        LuaToVisualGearTypeOrd:= i;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   270
end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   271
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   272
function LuaToAmmoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
10279
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   273
begin
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   274
    if lua_isnoneornil(L, i) then i:= -1
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   275
    else i:= Trunc(lua_tonumber(L, i));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   276
    if (i < ord(Low(TAmmoType))) or (i > ord(High(TAmmoType))) then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   277
        begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   278
        LuaCallError('Invalid ammoType!', call, paramsyntax);
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   279
        LuaToAmmoTypeOrd:= -1;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   280
        end
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   281
    else
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   282
        LuaToAmmoTypeOrd:= i;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   283
end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   284
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   285
function LuaToStatInfoTypeOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   286
begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   287
    if lua_isnoneornil(L, i) then i:= -1
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   288
    else i:= Trunc(lua_tonumber(L, i));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   289
    if (i < ord(Low(TStatInfoType))) or (i > ord(High(TStatInfoType))) then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   290
        begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   291
        LuaCallError('Invalid statInfoType!', call, paramsyntax);
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   292
        LuaToStatInfoTypeOrd:= -1;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   293
        end
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   294
    else
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   295
        LuaToStatInfoTypeOrd:= i;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   296
end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   297
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   298
function LuaToSoundOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   299
begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   300
    if lua_isnoneornil(L, i) then i:= -1
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   301
    else i:= Trunc(lua_tonumber(L, i));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   302
    if (i < ord(Low(TSound))) or (i > ord(High(TSound))) then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   303
        begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   304
        LuaCallError('Invalid soundId!', call, paramsyntax);
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   305
        LuaToSoundOrd:= -1;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   306
        end
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   307
    else
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   308
        LuaToSoundOrd:= i;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   309
end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   310
15998
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   311
function LuaToMsgStrIdOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   312
begin
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   313
    if lua_isnoneornil(L, i) then i:= -1
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   314
    else i:= Trunc(lua_tonumber(L, i));
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   315
    if (i < ord(Low(TMsgStrId))) or (i > ord(High(TMsgStrId))) then
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   316
        begin
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   317
        LuaCallError('Invalid message ID!', call, paramsyntax);
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   318
        LuaToMsgStrIdOrd:= -1;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   319
        end
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   320
    else
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   321
        LuaToMsgStrIdOrd:= i;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   322
end;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   323
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   324
function LuaToGoalStrIdOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   325
begin
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   326
    if lua_isnoneornil(L, i) then i:= -1
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   327
    else i:= Trunc(lua_tonumber(L, i));
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   328
    if (i < ord(Low(TGoalStrId))) or (i > ord(High(TGoalStrId))) then
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   329
        begin
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   330
        LuaCallError('Invalid goal string ID!', call, paramsyntax);
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   331
        LuaToGoalStrIdOrd:= -1;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   332
        end
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   333
    else
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   334
        LuaToGoalStrIdOrd:= i;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   335
end;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   336
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   337
function LuaToHogEffectOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   338
begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   339
    if lua_isnoneornil(L, i) then i:= -1
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   340
    else i:= Trunc(lua_tonumber(L, i));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   341
    if (i < ord(Low(THogEffect))) or (i > ord(High(THogEffect))) then
10279
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   342
        begin
11844
a784866c91ad Lua API: fix incorrect error message. thanks to TheAnachron and rhino for pointing this out
sheepluva
parents: 11823
diff changeset
   343
        LuaCallError('Invalid effect type!', call, paramsyntax);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   344
        LuaToHogEffectOrd:= -1;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   345
        end
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   346
    else
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   347
        LuaToHogEffectOrd:= i;
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   348
end;
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   349
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   350
function LuaToCapGroupOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
   351
begin
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   352
    if lua_isnoneornil(L, i) then i:= -1
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   353
    else i:= Trunc(lua_tonumber(L, i));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   354
    if (i < ord(Low(TCapGroup))) or (i > ord(High(TCapGroup))) then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   355
        begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   356
        LuaCallError('Invalid capgroup type!', call, paramsyntax);
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   357
        LuaToCapGroupOrd:= -1;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   358
        end
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   359
    else
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   360
        LuaToCapGroupOrd:= i;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   361
end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   362
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   363
function LuaToSpriteOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   364
begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   365
    if lua_isnoneornil(L, i) then i:= -1
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   366
    else i:= Trunc(lua_tonumber(L, i));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   367
    if (i < ord(Low(TSprite))) or (i > ord(High(TSprite))) then
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
   368
        begin
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
   369
        LuaCallError('Invalid sprite id!', call, paramsyntax);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   370
        LuaToSpriteOrd:= -1;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   371
        end
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   372
    else
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   373
        LuaToSpriteOrd:= i;
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
   374
end;
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
   375
10603
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   376
function LuaToMapGenOrd(L : Plua_State; i: LongInt; call, paramsyntax: shortstring): LongInt; inline;
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   377
begin
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   378
    if lua_isnoneornil(L, i) then i:= -1
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   379
    else i:= Trunc(lua_tonumber(L, i));
10603
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   380
    if (i < ord(Low(TMapGen))) or (i > ord(High(TMapGen))) then
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   381
        begin
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   382
        LuaCallError('Invalid mapgen id!', call, paramsyntax);
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   383
        LuaToMapGenOrd:= -1;
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   384
        end
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   385
    else
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   386
        LuaToMapGenOrd:= i;
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   387
end;
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
   388
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
   389
// wrapped calls
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
   390
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
   391
// 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
   392
// 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
   393
// where L contains the state, returns the number of return values on the stack
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   394
// call CheckLuaParamCount or CheckAndFetchParamCount
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
   395
// to validate/get the number of passed arguments (see their call definitions)
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
   396
//
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
   397
// use as return value the number of variables pushed back to the lua script
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
   398
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   399
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
   400
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   401
    if CheckLuaParamCount(L, 2, 'band', 'value1, value2') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   402
        lua_pushnumber(L, Trunc(lua_tonumber(L, 2)) and Trunc(lua_tonumber(L, 1)))
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   403
    else
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   404
        lua_pushnil(L);
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   405
    lc_band := 1;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   406
end;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   407
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   408
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
   409
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   410
    if CheckLuaParamCount(L, 2, 'bor', 'value1, value2') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   411
        lua_pushnumber(L, Trunc(lua_tonumber(L, 2)) or Trunc(lua_tonumber(L, 1)))
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   412
    else
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   413
        lua_pushnil(L);
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   414
    lc_bor := 1;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   415
end;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   416
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   417
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
   418
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   419
    if CheckLuaParamCount(L, 1, 'bnot', 'value') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   420
        lua_pushnumber(L, (not Trunc(lua_tonumber(L, 1))))
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   421
    else
4483
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   422
        lua_pushnil(L);
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   423
    lc_bnot := 1;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   424
end;
ad1524a177bd band/bor/bnot to support Lua 5.1 lack of binary ops
nemo
parents: 4481
diff changeset
   425
6764
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   426
function lc_div(L: PLua_State): LongInt; Cdecl;
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   427
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   428
    if CheckLuaParamCount(L, 2, 'div', 'dividend, divisor') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   429
        lua_pushnumber(L, Trunc(lua_tonumber(L, 1)) div Trunc(lua_tonumber(L, 2)))
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   430
    else
6764
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   431
        lua_pushnil(L);
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   432
    lc_div := 1;
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   433
end;
e56ff0231540 Add div to allow safe integer division from lua
nemo
parents: 6763
diff changeset
   434
4523
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   435
function lc_getinputmask(L : Plua_State) : LongInt; Cdecl;
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   436
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   437
    if CheckLuaParamCount(L, 0, 'GetInputMask', '') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   438
        lua_pushnumber(L, InputMask);
4523
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   439
    lc_getinputmask:= 1
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   440
end;
23ed16e6c7d2 oops. forgot the getter.
nemo
parents: 4522
diff changeset
   441
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
   442
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
   443
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   444
    if CheckLuaParamCount(L, 1, 'SetInputMask', 'mask') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   445
        InputMask:= Trunc(lua_tonumber(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
   446
    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
   447
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
   448
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
   449
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
   450
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   451
    if CheckLuaParamCount(L, 1, 'WriteLnToConsole', 'string') 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
   452
        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
   453
    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
   454
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
   455
12910
383445810e42 Lua API: Add WriteLnToChat
Wuzzy <Wuzzy2@mail.ru>
parents: 12848
diff changeset
   456
function lc_writelntochat(L : Plua_State) : LongInt; Cdecl;
383445810e42 Lua API: Add WriteLnToChat
Wuzzy <Wuzzy2@mail.ru>
parents: 12848
diff changeset
   457
begin
383445810e42 Lua API: Add WriteLnToChat
Wuzzy <Wuzzy2@mail.ru>
parents: 12848
diff changeset
   458
    if CheckLuaParamCount(L, 1, 'WriteLnToChat', 'string') then
383445810e42 Lua API: Add WriteLnToChat
Wuzzy <Wuzzy2@mail.ru>
parents: 12848
diff changeset
   459
        AddChatString(#2 + lua_tostring(L, 1));
383445810e42 Lua API: Add WriteLnToChat
Wuzzy <Wuzzy2@mail.ru>
parents: 12848
diff changeset
   460
    lc_writelntochat:= 0;
383445810e42 Lua API: Add WriteLnToChat
Wuzzy <Wuzzy2@mail.ru>
parents: 12848
diff changeset
   461
end;
383445810e42 Lua API: Add WriteLnToChat
Wuzzy <Wuzzy2@mail.ru>
parents: 12848
diff changeset
   462
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
   463
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
   464
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
   465
    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
   466
    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
   467
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   468
    if CheckLuaParamCount(L, 1, 'ParseCommand', 'string') 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
   469
        begin
10131
4b4a043111f4 - pas2c recognizes typecasts in initialization expressions
unc0rr
parents: 10129
diff changeset
   470
        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
   471
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
   472
        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
   473
        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
   474
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
   475
        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
   476
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   477
        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
   478
    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
   479
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
   480
10291
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   481
// sets weapon to the desired ammo type
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   482
function lc_setweapon(L : Plua_State) : LongInt; Cdecl;
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   483
var at: LongInt;
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   484
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   485
    callStr = 'SetWeapon';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   486
    paramsStr = 'ammoType';
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   487
begin
10291
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   488
    // no point to run this without any CurrentHedgehog
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   489
    if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 1, callStr, paramsStr)) then
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   490
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   491
        at:= LuaToAmmoTypeOrd(L, 1, callStr, paramsStr);
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   492
        if at >= 0 then
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   493
            ParseCommand('setweap ' + char(at), true, true);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   494
        end;
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   495
    lc_setweapon:= 0;
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   496
end;
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
   497
11520
663ecfb05df6 Lua API: SetCinematicMode(enable)
sheepluva
parents: 11515
diff changeset
   498
// enable/disable cinematic effects
663ecfb05df6 Lua API: SetCinematicMode(enable)
sheepluva
parents: 11515
diff changeset
   499
function lc_setcinematicmode(L : Plua_State) : LongInt; Cdecl;
663ecfb05df6 Lua API: SetCinematicMode(enable)
sheepluva
parents: 11515
diff changeset
   500
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   501
    callStr = 'SetCinematicMode';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   502
    paramsStr = 'enable';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   503
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   504
    if (CheckLuaParamCount(L, 1, callStr, paramsStr)) then
11520
663ecfb05df6 Lua API: SetCinematicMode(enable)
sheepluva
parents: 11515
diff changeset
   505
        begin
663ecfb05df6 Lua API: SetCinematicMode(enable)
sheepluva
parents: 11515
diff changeset
   506
        CinematicScript:= lua_toboolean(L, 1);
663ecfb05df6 Lua API: SetCinematicMode(enable)
sheepluva
parents: 11515
diff changeset
   507
        end;
663ecfb05df6 Lua API: SetCinematicMode(enable)
sheepluva
parents: 11515
diff changeset
   508
    lc_setcinematicmode:= 0;
663ecfb05df6 Lua API: SetCinematicMode(enable)
sheepluva
parents: 11515
diff changeset
   509
end;
663ecfb05df6 Lua API: SetCinematicMode(enable)
sheepluva
parents: 11515
diff changeset
   510
11058
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   511
// no parameter means reset to default (and 0 means unlimited)
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   512
function lc_setmaxbuilddistance(L : Plua_State) : LongInt; Cdecl;
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   513
var np: LongInt;
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   514
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   515
    callStr = 'SetMaxBuildDistance';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   516
    paramsStr = '[ distInPx ]';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   517
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   518
    if CheckAndFetchParamCountRange(L, 0, 1, callStr, paramsStr, np) then
11058
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   519
        begin
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   520
        if np = 0 then
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   521
            begin
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   522
            // no args? reset
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   523
            cBuildMaxDist:= cDefaultBuildMaxDist;
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   524
            end
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   525
        else
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   526
            CBuildMaxDist:= Trunc(lua_tonumber(L, 1));
11058
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   527
        end;
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   528
    lc_setmaxbuilddistance:= 0;
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   529
end;
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
   530
10291
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   531
// sets weapon to whatever weapons is next (wraps around, amSkip is skipped)
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   532
function lc_setnextweapon(L : Plua_State) : LongInt; Cdecl;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   533
var at          : LongInt;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   534
    nextAmmo    : TAmmo;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   535
    s, a, cs, fa: LongInt;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   536
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   537
    callStr = 'SetNextWeapon';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   538
    paramsStr = '';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   539
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   540
    if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, callStr, paramsStr)) then
10291
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   541
        begin
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   542
        at:= -1;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   543
        with CurrentHedgehog^ do
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   544
            begin
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   545
            cs:= 0; // current slot
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   546
            fa:= 0; // first ammo item to check
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   547
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
   548
            // if something is selected, find it is successor
10291
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   549
            if curAmmoType <> amNothing then
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   550
                begin
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   551
                // get current slot index
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   552
                cs:= Ammoz[CurAmmoType].Slot;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   553
                // find current ammo index
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   554
                while (fa < cMaxSlotAmmoIndex)
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   555
                    and (Ammo^[cs, fa].AmmoType <> CurAmmoType) do
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   556
                        inc(fa);
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
   557
                // increase once more because we will not successor
10291
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   558
                inc(fa);
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   559
                end;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   560
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   561
            // find first available ammo
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   562
            // revisit current slot too (current item might not be first)
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   563
            for s:= cs to cs + cMaxSlotIndex + 1 do
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   564
                begin
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   565
                for a:= fa to cMaxSlotAmmoIndex do
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   566
                    begin
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   567
                    // check if we went full circle
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   568
                    if (a = fa) and (s = cs + cMaxSlotIndex + 1)  then
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   569
                        exit(0);
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   570
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   571
                    // get ammo
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   572
                    nextAmmo:= Ammo^[s mod (cMaxSlotIndex + 1), a];
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   573
                    // only switch to ammos the hog actually has
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   574
                    if (nextAmmo.AmmoType <> amNothing)
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   575
                        and (nextAmmo.AmmoType <> amSkip) and (nextAmmo.Count > 0) then
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   576
                            begin
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   577
                            at:= ord(nextAmmo.AmmoType);
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   578
                            break;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   579
                            end;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   580
                    end;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   581
                // stop slot loop if something was found
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   582
                if at >= 0 then
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   583
                    break;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   584
                // check following slots starting with first item
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   585
                fa:= 0;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   586
                end;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   587
            end;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   588
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   589
        if at >= 0 then
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   590
            ParseCommand('setweap ' + char(at), true, true);
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   591
        end;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   592
    lc_setnextweapon:= 0;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   593
end;
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
   594
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
   595
function lc_showmission(L : Plua_State) : LongInt; Cdecl;
13467
854caa3c9212 Lua API: Add parameter forceDisplay to ShowMission to prevent manual hiding
Wuzzy <Wuzzy2@mail.ru>
parents: 13457
diff changeset
   596
var n: 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
   597
begin
13467
854caa3c9212 Lua API: Add parameter forceDisplay to ShowMission to prevent manual hiding
Wuzzy <Wuzzy2@mail.ru>
parents: 13457
diff changeset
   598
    if CheckAndFetchParamCount(L, 5, 6, 'ShowMission', 'caption, subcaption, text, icon, time [, forceDisplay]', n) then
854caa3c9212 Lua API: Add parameter forceDisplay to ShowMission to prevent manual hiding
Wuzzy <Wuzzy2@mail.ru>
parents: 13457
diff changeset
   599
        if n = 5 then
854caa3c9212 Lua API: Add parameter forceDisplay to ShowMission to prevent manual hiding
Wuzzy <Wuzzy2@mail.ru>
parents: 13457
diff changeset
   600
            ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), Trunc(lua_tonumber(L, 4)), Trunc(lua_tonumber(L, 5)))
854caa3c9212 Lua API: Add parameter forceDisplay to ShowMission to prevent manual hiding
Wuzzy <Wuzzy2@mail.ru>
parents: 13457
diff changeset
   601
        else
854caa3c9212 Lua API: Add parameter forceDisplay to ShowMission to prevent manual hiding
Wuzzy <Wuzzy2@mail.ru>
parents: 13457
diff changeset
   602
            ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), Trunc(lua_tonumber(L, 4)), Trunc(lua_tonumber(L, 5)), lua_toboolean(L, 6));
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
   603
    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
   604
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
   605
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
   606
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
   607
begin
3407
dcc129c4352e Engine:
smxx
parents: 3368
diff changeset
   608
    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
   609
    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
   610
    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
   611
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
   612
15998
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   613
function lc_getenginestring(L : Plua_state) : LongInt; Cdecl;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   614
var stringType: shortstring;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   615
    msgId: LongInt;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   616
const callStr = 'GetEngineString';
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   617
      paramsStr = 'stringType, msgId';
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   618
begin
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   619
    if CheckLuaParamCount(L, 2, callStr, paramsStr) then
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   620
        begin
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   621
            stringType:= lua_tostring(L, 1);
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   622
            if (not lua_isnumber(L, 2)) then
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   623
                begin
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   624
                LuaError('Argument ''msgId'' must be a number!');
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   625
                lua_pushnil(L);
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   626
                end
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   627
            else if stringType = 'TMsgStrId' then
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   628
                begin
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   629
                msgId:= LuaToMsgStrIdOrd(L, 2, callStr, paramsStr);
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   630
                if msgId = -1 then
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   631
                    lua_pushnil(L)
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   632
                else
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   633
                    lua_pushstring(L, PChar(trmsg[TMsgStrId(msgId)]))
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   634
                end
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   635
            else if stringType = 'TGoalStrId' then
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   636
                begin
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   637
                msgId:= LuaToGoalStrIdOrd(L, 2, callStr, paramsStr);
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   638
                if msgId = -1 then
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   639
                    lua_pushnil(L)
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   640
                else
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   641
                    lua_pushstring(L, PChar(trgoal[TGoalStrId(msgId)]));
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   642
                end
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   643
            else
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   644
                begin
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   645
                LuaError('Invalid stringType!');
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   646
                lua_pushnil(L);
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   647
                end
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   648
        end
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   649
    else
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   650
        lua_pushnil(L);
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   651
    lc_getenginestring:= 1;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   652
end;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
   653
11939
c7ec309cd685 Add Lua API function SetAmmoTexts (see issue 82)
Wuzzy <almikes@aol.com>
parents: 11880
diff changeset
   654
function lc_setammotexts(L : Plua_State) : LongInt; Cdecl;
c7ec309cd685 Add Lua API function SetAmmoTexts (see issue 82)
Wuzzy <almikes@aol.com>
parents: 11880
diff changeset
   655
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   656
    callStr = 'SetAmmoTexts';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   657
    paramsStr = 'ammoType, name, caption, description [, showExtra]';
13370
e202d58236b1 Lua API: Add 5th parameter showExtra to SetAmmoTexts to hide extra text
Wuzzy <Wuzzy2@mail.ru>
parents: 13349
diff changeset
   658
var n: integer;
e202d58236b1 Lua API: Add 5th parameter showExtra to SetAmmoTexts to hide extra text
Wuzzy <Wuzzy2@mail.ru>
parents: 13349
diff changeset
   659
    showExtra: boolean;
11939
c7ec309cd685 Add Lua API function SetAmmoTexts (see issue 82)
Wuzzy <almikes@aol.com>
parents: 11880
diff changeset
   660
begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   661
    if CheckAndFetchParamCount(L, 4, 5, callStr, paramsStr, n) then
13370
e202d58236b1 Lua API: Add 5th parameter showExtra to SetAmmoTexts to hide extra text
Wuzzy <Wuzzy2@mail.ru>
parents: 13349
diff changeset
   662
        begin
e202d58236b1 Lua API: Add 5th parameter showExtra to SetAmmoTexts to hide extra text
Wuzzy <Wuzzy2@mail.ru>
parents: 13349
diff changeset
   663
        if n = 5 then
e202d58236b1 Lua API: Add 5th parameter showExtra to SetAmmoTexts to hide extra text
Wuzzy <Wuzzy2@mail.ru>
parents: 13349
diff changeset
   664
            showExtra:= lua_toboolean(L, 5)
e202d58236b1 Lua API: Add 5th parameter showExtra to SetAmmoTexts to hide extra text
Wuzzy <Wuzzy2@mail.ru>
parents: 13349
diff changeset
   665
        else
e202d58236b1 Lua API: Add 5th parameter showExtra to SetAmmoTexts to hide extra text
Wuzzy <Wuzzy2@mail.ru>
parents: 13349
diff changeset
   666
            showExtra:= true;
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   667
        SetAmmoTexts(TAmmoType(LuaToAmmoTypeOrd(L, 1, callStr, paramsStr)), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tostringA(L, 4), showExtra);
13370
e202d58236b1 Lua API: Add 5th parameter showExtra to SetAmmoTexts to hide extra text
Wuzzy <Wuzzy2@mail.ru>
parents: 13349
diff changeset
   668
        end;
11939
c7ec309cd685 Add Lua API function SetAmmoTexts (see issue 82)
Wuzzy <almikes@aol.com>
parents: 11880
diff changeset
   669
    lc_setammotexts:= 0;
c7ec309cd685 Add Lua API function SetAmmoTexts (see issue 82)
Wuzzy <almikes@aol.com>
parents: 11880
diff changeset
   670
end;
c7ec309cd685 Add Lua API function SetAmmoTexts (see issue 82)
Wuzzy <almikes@aol.com>
parents: 11880
diff changeset
   671
11941
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   672
function lc_setammodescriptionappendix(L : Plua_State) : LongInt; Cdecl;
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   673
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   674
    callStr = 'SetAmmoDescriptionAppendix';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   675
    paramsStr = 'ammoType, descAppend';
11941
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   676
var
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   677
    ammoType: TAmmoType;
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   678
    descAppend: ansistring;
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   679
begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   680
    if CheckLuaParamCount(L, 2, callStr, paramsStr) then
11941
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   681
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   682
        ammoType := TAmmoType(LuaToAmmoTypeOrd(L, 1, callStr, paramsStr));
11941
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   683
        descAppend := lua_tostringA(L, 2);
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   684
        trluaammoa[Ammoz[ammoType].NameId] := descAppend;
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   685
        end;
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   686
    lc_setammodescriptionappendix := 0;
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   687
end;
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
   688
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   689
function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   690
var i, n : integer;
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   691
begin
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   692
    // can have 1 or more arguments
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   693
    if CheckAndFetchLuaParamMinCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   694
        begin
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   695
        for i:= 1 to n do
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   696
            GameFlags := GameFlags or LongWord(Trunc(lua_tonumber(L, i)));
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   697
        ScriptSetInteger('GameFlags', GameFlags);
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   698
        end;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8368
diff changeset
   699
    lc_enablegameflags:= 0;
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   700
end;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   701
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   702
function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   703
var i , n: integer;
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   704
begin
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   705
    // can have 1 or more arguments
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   706
    if CheckAndFetchLuaParamMinCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   707
        begin
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   708
        for i:= 1 to n do
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   709
            GameFlags := GameFlags and (not LongWord(Trunc(lua_tonumber(L, i))));
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   710
        ScriptSetInteger('GameFlags', GameFlags);
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   711
        end;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8368
diff changeset
   712
    lc_disablegameflags:= 0;
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   713
end;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   714
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   715
function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   716
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   717
    if CheckLuaParamCount(L, 0, 'ClearGameFlags', '') then
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   718
        begin
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   719
        GameFlags:= 0;
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   720
        ScriptSetInteger('GameFlags', GameFlags);
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   721
        end;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8368
diff changeset
   722
    lc_cleargameflags:= 0;
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   723
end;
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
   724
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   725
function lc_getgameflag(L : Plua_State) : LongInt; Cdecl;
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   726
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   727
    if CheckLuaParamCount(L, 1, 'GetGameFlag', 'gameflag') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   728
        lua_pushboolean(L, (GameFlags and LongWord(Trunc(lua_tonumber(L, 1))) <> 0))
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   729
    else
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   730
        lua_pushnil(L);
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   731
    lc_getgameflag:= 1;
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   732
end;
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
   733
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   734
function lc_addcaption(L : Plua_State) : LongInt; Cdecl;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   735
var cg: LongInt;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   736
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   737
    callStr = 'AddCaption';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   738
    paramsStr = 'text [, color, captiongroup]';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   739
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   740
    if CheckAndFetchParamCount(L, 1, 3, callStr, paramsStr, cg) then
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   741
        begin
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   742
        if cg = 1 then
13642
3d14950641a4 Refactor text color variable names, export 2 color values to Lua
Wuzzy <Wuzzy2@mail.ru>
parents: 13627
diff changeset
   743
            AddCaption(lua_tostringA(L, 1), capcolDefault, capgrpMessage)
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   744
        else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   745
            begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   746
            cg:= LuaToCapGroupOrd(L, 3, callStr, paramsStr);
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   747
            if cg >= 0 then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   748
                AddCaption(lua_tostringA(L, 1), Trunc(lua_tonumber(L, 2)) shr 8, TCapGroup(cg));
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   749
            end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   750
        end;
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   751
    lc_addcaption:= 0;
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   752
end;
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
   753
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
   754
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
   755
var gear: PGear;
14414
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   756
    explode, poison: boolean;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   757
    n: LongInt;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   758
begin
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   759
    if CheckAndFetchParamCountRange(L, 2, 4, 'SpawnFakeHealthCrate', 'x, y [, explode [, poison]]', n) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   760
        begin
14414
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   761
        explode:= false;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   762
        poison:= false;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   763
        if (n >= 3) and (not lua_isnil(L, 3)) then
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   764
            explode:= lua_toboolean(L, 3);
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   765
        if (n = 4) and (not lua_isnil(L, 4)) then
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   766
            poison:= lua_toboolean(L, 4);
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   767
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   768
        gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
14414
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   769
        HealthCrate, explode, poison);
11196
f4cf2cdea8e5 Add nil check in fake crate spawn for if crate fails to spawn
nemo
parents: 11179
diff changeset
   770
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   771
             lua_pushnumber(L, gear^.uid)
11196
f4cf2cdea8e5 Add nil check in fake crate spawn for if crate fails to spawn
nemo
parents: 11179
diff changeset
   772
        else lua_pushnil(L)
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   773
        end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   774
    else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   775
        lua_pushnil(L);
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   776
    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
   777
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
   778
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
   779
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
   780
var gear: PGear;
14414
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   781
    explode, poison: boolean;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   782
    n: LongInt;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   783
begin
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   784
    if CheckAndFetchParamCountRange(L, 2, 4, 'SpawnFakeAmmoCrate', 'x, y [, explode [, poison]]', n) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   785
        begin
14414
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   786
        explode:= false;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   787
        poison:= false;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   788
        if (n >= 3) and (not lua_isnil(L, 3)) then
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   789
            explode:= lua_toboolean(L, 3);
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   790
        if (n = 4) and (not lua_isnil(L, 4)) then
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   791
            poison:= lua_toboolean(L, 4);
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   792
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   793
        gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
14414
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   794
        AmmoCrate, explode, poison);
11251
66796cd627d8 few more missing nil checks in crate spawn
nemo
parents: 11196
diff changeset
   795
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   796
             lua_pushnumber(L, gear^.uid)
11251
66796cd627d8 few more missing nil checks in crate spawn
nemo
parents: 11196
diff changeset
   797
        else lua_pushnil(L)
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   798
        end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   799
    else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   800
        lua_pushnil(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
   801
    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
   802
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
   803
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
   804
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
   805
var gear: PGear;
14414
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   806
    explode, poison: boolean;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   807
    n: LongInt;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   808
begin
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   809
    if CheckAndFetchParamCountRange(L, 2, 4, 'SpawnFakeUtilityCrate', 'x, y [, explode [, poison]]', n) then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   810
        begin
14414
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   811
        explode:= false;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   812
        poison:= false;
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   813
        if (n >= 3) and (not lua_isnil(L, 3)) then
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   814
            explode:= lua_toboolean(L, 3);
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   815
        if (n = 4) and (not lua_isnil(L, 4)) then
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   816
            poison:= lua_toboolean(L, 4);
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   817
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   818
        gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
14414
c2cd3f64b9f7 Lua API: Make the last 2 params optional in the SpawnFake*Crate functions
Wuzzy <Wuzzy2@mail.ru>
parents: 14387
diff changeset
   819
        UtilityCrate, explode, poison);
11251
66796cd627d8 few more missing nil checks in crate spawn
nemo
parents: 11196
diff changeset
   820
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   821
             lua_pushnumber(L, gear^.uid)
11251
66796cd627d8 few more missing nil checks in crate spawn
nemo
parents: 11196
diff changeset
   822
        else lua_pushnil(L)
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   823
        end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   824
    else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   825
        lua_pushnil(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
   826
    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
   827
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
   828
3730
aecea9aa53dc Engine:
smaxx
parents: 3724
diff changeset
   829
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
   830
var gear: PGear;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   831
var health, n: LongInt;
3730
aecea9aa53dc Engine:
smaxx
parents: 3724
diff changeset
   832
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   833
    if CheckAndFetchParamCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   834
        begin
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   835
        if n = 3 then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   836
            health:= Trunc(lua_tonumber(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
   837
        else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   838
            health:= cHealthCaseAmount;
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   839
        gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(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
   840
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   841
             lua_pushnumber(L, gear^.uid)
11251
66796cd627d8 few more missing nil checks in crate spawn
nemo
parents: 11196
diff changeset
   842
        else lua_pushnil(L);
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   843
        end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   844
    else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   845
        lua_pushnil(L);
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
   846
    lc_spawnhealthcrate := 1;
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   847
end;
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   848
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   849
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
   850
var gear: PGear;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   851
    n   : LongInt;
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   852
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   853
    if CheckAndFetchParamCount(L, 3, 4, 'SpawnAmmoCrate', 'x, y, content [, amount]', n) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   854
        begin
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   855
        if n = 3 then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   856
             gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), AmmoCrate, Trunc(lua_tonumber(L, 3)), 0)
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   857
        else gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), AmmoCrate, Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(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
   858
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   859
             lua_pushnumber(L, gear^.uid)
11251
66796cd627d8 few more missing nil checks in crate spawn
nemo
parents: 11196
diff changeset
   860
        else lua_pushnil(L);
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   861
        end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   862
    else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   863
        lua_pushnil(L);
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   864
    lc_spawnammocrate := 1;
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   865
end;
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   866
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   867
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
   868
var gear: PGear;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   869
    n   : LongInt;
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   870
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   871
    if CheckAndFetchParamCount(L, 3, 4, 'SpawnUtilityCrate', 'x, y, content [, amount]', n) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
   872
        begin
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   873
        if n = 3 then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   874
             gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), UtilityCrate, Trunc(lua_tonumber(L, 3)), 0)
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   875
        else gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), UtilityCrate, Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(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
   876
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   877
             lua_pushnumber(L, gear^.uid)
11251
66796cd627d8 few more missing nil checks in crate spawn
nemo
parents: 11196
diff changeset
   878
        else lua_pushnil(L);
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   879
       end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   880
    else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   881
        lua_pushnil(L);
3734
304a83637eb4 * SpawnCustomCrateAt procedure + lua bindings
burp
parents: 3730
diff changeset
   882
    lc_spawnutilitycrate := 1;
3730
aecea9aa53dc Engine:
smaxx
parents: 3724
diff changeset
   883
end;
aecea9aa53dc Engine:
smaxx
parents: 3724
diff changeset
   884
12932
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   885
function lc_spawnsupplycrate(L: PLua_State): LongInt; Cdecl;
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   886
var gear: PGear;
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   887
    n, at:LongInt;
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   888
    t:    TCrateType;
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   889
begin
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   890
    if CheckAndFetchParamCount(L, 3, 4, 'SpawnSupplyCrate', 'x, y, content [, amount]', n) then
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   891
        begin
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   892
        // Get crate type (ammo or utility)
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   893
        at:= Trunc(lua_tonumber(L, 3));
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   894
        if (Ammoz[TAmmoType(at)].Ammo.Propz and ammoprop_Utility) <> 0 then
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   895
            t:= UtilityCrate
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   896
        else
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   897
            t:= AmmoCrate;
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   898
        if n = 3 then
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   899
             gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), t, at, 0)
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   900
        else gear := SpawnCustomCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), t, at, Trunc(lua_tonumber(L, 4)));
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   901
        if gear <> nil then
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   902
             lua_pushnumber(L, gear^.uid)
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   903
        else lua_pushnil(L);
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   904
        end
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   905
    else
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   906
        lua_pushnil(L);
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   907
    lc_spawnsupplycrate := 1;
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   908
end;
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
   909
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
   910
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
   911
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
   912
    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
   913
    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
   914
    gt: TGearType;
10279
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   915
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   916
    callStr = 'AddGear';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   917
    paramsStr = 'x, y, gearType, state, dx, dy, timer';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   918
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   919
    if CheckLuaParamCount(L, 7, callStr, paramsStr) 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
   920
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   921
        t:= LuaToGearTypeOrd(L, 3, callStr, paramsStr);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   922
        if t >= 0 then
10279
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   923
            begin
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   924
            gt:= TGearType(t);
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   925
            x:= Trunc(lua_tonumber(L, 1));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   926
            y:= Trunc(lua_tonumber(L, 2));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   927
            s:= Trunc(lua_tonumber(L, 4));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   928
            dx:= int2hwFloat(Trunc(lua_tonumber(L, 5))) / 1000000;
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   929
            dy:= int2hwFloat(Trunc(lua_tonumber(L, 6))) / 1000000;
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   930
            t:= Trunc(lua_tonumber(L, 7));
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
   931
10279
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   932
            gear:= AddGear(x, y, gt, s, dx, dy, t);
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   933
            lastGearByUID:= gear;
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   934
            lua_pushnumber(L, gear^.uid)
10279
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   935
            end
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   936
        else
b75e7ebfbe11 fix possible engine crash that a lua script could cause by passing an invalid geartype to addgear
sheepluva
parents: 10278
diff changeset
   937
            lua_pushnil(L);
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   938
        end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   939
    else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   940
        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
   941
    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
   942
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
   943
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
   944
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
   945
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
   946
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
   947
    if CheckLuaParamCount(L, 1, 'DeleteGear', 'gearUid') 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
   948
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   949
        gear:= GearByUID(Trunc(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
   950
        if gear <> nil then
7517
f287f00063e8 Allow scripting to delete gears
nemo
parents: 7426
diff changeset
   951
            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
   952
        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
   953
    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
   954
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
   955
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
   956
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
   957
var vg : PVisualGear;
10346
dd22bcf08e4f lua api: allow to specify layer when adding visual gear
sheepluva
parents: 10312
diff changeset
   958
    x, y, s, n, layer: LongInt;
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
   959
    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
   960
    vgt: TVisualGearType;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   961
    uid: Longword;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   962
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   963
    callStr = 'AddVisualGear';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   964
    paramsStr = 'x, y, visualGearType, state, critical [, layer]';
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
   965
begin
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   966
    uid:= 0;
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   967
    if CheckAndFetchParamCount(L, 5, 6, callStr, paramsStr, n) 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
   968
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
   969
        s:= LuaToVisualGearTypeOrd(L, 3, callStr, paramsStr);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   970
        if s >= 0 then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   971
            begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   972
            vgt:= TVisualGearType(s);
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   973
            x:= Trunc(lua_tonumber(L, 1));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   974
            y:= Trunc(lua_tonumber(L, 2));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   975
            s:= Trunc(lua_tonumber(L, 4));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   976
            c:= lua_toboolean(L, 5);
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
   977
10346
dd22bcf08e4f lua api: allow to specify layer when adding visual gear
sheepluva
parents: 10312
diff changeset
   978
            if n = 6 then
dd22bcf08e4f lua api: allow to specify layer when adding visual gear
sheepluva
parents: 10312
diff changeset
   979
                begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   980
                layer:= Trunc(lua_tonumber(L, 6));
10347
fd80921a8f81 add assignment I forgot
sheepluva
parents: 10346
diff changeset
   981
                vg:= AddVisualGear(x, y, vgt, s, c, layer);
10346
dd22bcf08e4f lua api: allow to specify layer when adding visual gear
sheepluva
parents: 10312
diff changeset
   982
                end
dd22bcf08e4f lua api: allow to specify layer when adding visual gear
sheepluva
parents: 10312
diff changeset
   983
            else
dd22bcf08e4f lua api: allow to specify layer when adding visual gear
sheepluva
parents: 10312
diff changeset
   984
                vg:= AddVisualGear(x, y, vgt, s, c);
dd22bcf08e4f lua api: allow to specify layer when adding visual gear
sheepluva
parents: 10312
diff changeset
   985
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   986
            if vg <> nil then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   987
                begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   988
                lastVisualGearByUID:= vg;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   989
                uid:= vg^.uid;
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
   990
                lua_pushnumber(L, uid);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
   991
                end;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   992
            end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   993
            else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   994
                lua_pushnil(L);
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   995
        end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   996
    else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
   997
        lua_pushnil(L); // return value on stack (nil)
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
   998
    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
   999
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
  1000
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
  1001
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
  1002
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
  1003
begin
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1004
    vg:= nil;
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1005
    if CheckLuaParamCount(L, 1, 'DeleteVisualGear', 'vgUid') 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
  1006
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1007
        vg:= VisualGearByUID(Trunc(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
  1008
        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
  1009
            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
  1010
        end;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1011
    // allow caller to know whether there was something to delete
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1012
    lua_pushboolean(L, vg <> nil);
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1013
    lc_deletevisualgear:= 1
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
  1014
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
  1015
11880
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1016
function lc_getvisualgeartype(L : Plua_State) : LongInt; Cdecl;
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1017
var vg : PVisualGear;
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1018
begin
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1019
    if CheckLuaParamCount(L, 1, 'GetVisualGearType', 'vgUid') then
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1020
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1021
        vg := VisualGearByUID(Trunc(lua_tonumber(L, 1)));
11880
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1022
        if vg <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1023
            lua_pushnumber(L, ord(vg^.Kind))
11880
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1024
        else
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1025
            lua_pushnil(L);
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1026
        end
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1027
    else
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1028
        lua_pushnil(L); // return value on stack (nil)
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1029
    lc_getvisualgeartype:= 1
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1030
end;
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1031
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  1032
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
  1033
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
  1034
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
  1035
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1036
    if CheckLuaParamCount(L, 1, 'GetVisualGearValues', 'vgUid') 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
  1037
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1038
        vg:= VisualGearByUID(Trunc(lua_tonumber(L, 1)));
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
  1039
        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
  1040
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1041
            lua_pushnumber(L, round(vg^.X));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1042
            lua_pushnumber(L, round(vg^.Y));
5075
59b13b38a827 not useful for visual gears, and apparently not helpful for consistency
nemo
parents: 5074
diff changeset
  1043
            lua_pushnumber(L, vg^.dX);
59b13b38a827 not useful for visual gears, and apparently not helpful for consistency
nemo
parents: 5074
diff changeset
  1044
            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
  1045
            lua_pushnumber(L, vg^.Angle);
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1046
            lua_pushnumber(L, vg^.Frame);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1047
            lua_pushnumber(L, vg^.FrameTicks);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1048
            lua_pushnumber(L, vg^.State);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1049
            lua_pushnumber(L, vg^.Timer);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1050
            lua_pushnumber(L, vg^.Tint);
14188
48b9da0178eb oups getter should have it too
nemo
parents: 14058
diff changeset
  1051
            lua_pushnumber(L, vg^.Scale);
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
  1052
            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
  1053
        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
  1054
            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
  1055
            lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
14188
48b9da0178eb oups getter should have it too
nemo
parents: 14058
diff changeset
  1056
            lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
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
  1057
            end
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1058
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1059
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1060
        begin
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1061
        lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
14188
48b9da0178eb oups getter should have it too
nemo
parents: 14058
diff changeset
  1062
        lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(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
  1063
        end;
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1064
    lc_getvisualgearvalues:= 10
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
  1065
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
  1066
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
  1067
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
  1068
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
  1069
begin
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1070
// Param count can be 1-11 at present
14188
48b9da0178eb oups getter should have it too
nemo
parents: 14058
diff changeset
  1071
//    if CheckLuaParamCount(L, 11, 'SetVisualGearValues', 'vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint, Scale') then
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1072
//        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1073
        vg:= VisualGearByUID(Trunc(lua_tonumber(L, 1)));
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
  1074
        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
  1075
            begin
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1076
            if not lua_isnoneornil(L, 2) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1077
                vg^.X:= Trunc(lua_tonumber(L, 2));
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1078
            if not lua_isnoneornil(L, 3) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1079
                vg^.Y:= Trunc(lua_tonumber(L, 3));
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1080
            if not lua_isnoneornil(L, 4) then
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1081
                vg^.dX:= lua_tonumber(L, 4);
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1082
            if not lua_isnoneornil(L, 5) then
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1083
                vg^.dY:= lua_tonumber(L, 5);
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1084
            if not lua_isnoneornil(L, 6) then
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1085
                vg^.Angle:= lua_tonumber(L, 6);
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1086
            if not lua_isnoneornil(L, 7) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1087
                vg^.Frame:= Trunc(lua_tonumber(L, 7));
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1088
            if not lua_isnoneornil(L, 8) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1089
                vg^.FrameTicks:= Trunc(lua_tonumber(L, 8));
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1090
            if not lua_isnoneornil(L, 9) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1091
                vg^.State:= Trunc(lua_tonumber(L, 9));
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1092
            if not lua_isnoneornil(L, 10) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1093
                vg^.Timer:= Trunc(lua_tonumber(L, 10));
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1094
            if not lua_isnoneornil(L, 11) then
13434
745e9174038e somehow scale was omitted from this catch-all VG init. late addition to the struct perhaps.
nemo
parents: 13394
diff changeset
  1095
                vg^.Tint:= Trunc(lua_tonumber(L, 11));
745e9174038e somehow scale was omitted from this catch-all VG init. late addition to the struct perhaps.
nemo
parents: 13394
diff changeset
  1096
            if not lua_isnoneornil(L, 12) then
745e9174038e somehow scale was omitted from this catch-all VG init. late addition to the struct perhaps.
nemo
parents: 13394
diff changeset
  1097
                vg^.Scale:= Trunc(lua_tonumber(L, 12))
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1098
            end;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1099
//        end
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1100
//    else
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1101
//        lua_pushnil(L); // return value on stack (nil)
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1102
    lc_setvisualgearvalues:= 0
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1103
end;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1104
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  1105
// so. going to use this to get/set some of the more obscure gear values which were not already exposed elsewhere
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1106
// can keep adding things in the future. isnoneornil makes it safe
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1107
function lc_getgearvalues(L : Plua_State) : LongInt; Cdecl;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1108
var gear: PGear;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1109
begin
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1110
    if CheckLuaParamCount(L, 1, 'GetGearValues', 'gearUid') then
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1111
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1112
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1113
        if gear <> nil then
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1114
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1115
            lua_pushnumber(L, gear^.Angle);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1116
            lua_pushnumber(L, gear^.Power);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1117
            lua_pushnumber(L, gear^.WDTimer);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1118
            lua_pushnumber(L, gear^.Radius);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1119
            lua_pushnumber(L, hwRound(gear^.Density * _10000));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1120
            lua_pushnumber(L, gear^.Karma);
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1121
            lua_pushnumber(L,  gear^.DirAngle);
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1122
            lua_pushnumber(L, gear^.AdvBounce);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1123
            lua_pushnumber(L, Integer(gear^.ImpactSound));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1124
            lua_pushnumber(L, gear^.nImpactSounds);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1125
            lua_pushnumber(L, gear^.Tint);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1126
            lua_pushnumber(L, gear^.Damage);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1127
            lua_pushnumber(L, gear^.Boom)
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1128
            end
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1129
        else
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1130
            begin
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1131
            lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1132
            lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
11468
2f6f8baa2a97 Make weapon damage in most cases be a structure value and also expose it to lua. Needs testing/review due to conditions at time of doing this (w/ one arm, dizzy/tingling due to sodium citrate), and just number of places changed..
nemo
parents: 11317
diff changeset
  1133
            lua_pushnil(L); lua_pushnil(L); lua_pushnil(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
  1134
            end
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1135
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1136
    else
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1137
        begin
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1138
        lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1139
        lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
11468
2f6f8baa2a97 Make weapon damage in most cases be a structure value and also expose it to lua. Needs testing/review due to conditions at time of doing this (w/ one arm, dizzy/tingling due to sodium citrate), and just number of places changed..
nemo
parents: 11317
diff changeset
  1140
        lua_pushnil(L); lua_pushnil(L); lua_pushnil(L)
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1141
        end;
11468
2f6f8baa2a97 Make weapon damage in most cases be a structure value and also expose it to lua. Needs testing/review due to conditions at time of doing this (w/ one arm, dizzy/tingling due to sodium citrate), and just number of places changed..
nemo
parents: 11317
diff changeset
  1142
    lc_getgearvalues:= 13
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1143
end;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1144
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1145
function lc_setgearvalues(L : Plua_State) : LongInt; Cdecl;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1146
var gear : PGear;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1147
begin
11468
2f6f8baa2a97 Make weapon damage in most cases be a structure value and also expose it to lua. Needs testing/review due to conditions at time of doing this (w/ one arm, dizzy/tingling due to sodium citrate), and just number of places changed..
nemo
parents: 11317
diff changeset
  1148
// Currently allows 1-14 params
2f6f8baa2a97 Make weapon damage in most cases be a structure value and also expose it to lua. Needs testing/review due to conditions at time of doing this (w/ one arm, dizzy/tingling due to sodium citrate), and just number of places changed..
nemo
parents: 11317
diff changeset
  1149
//    if CheckLuaParamCount(L, 14, 'SetGearValues', 'gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, # ImpactSounds, Tint, Damage, Boom') then
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1150
//        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1151
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1152
        if gear <> nil then
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1153
            begin
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1154
            if not lua_isnoneornil(L, 2) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1155
                gear^.Angle := Trunc(lua_tonumber(L, 2));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1156
            if not lua_isnoneornil(L, 3) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1157
                gear^.Power := Trunc(lua_tonumber(L, 3));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1158
            if not lua_isnoneornil(L, 4) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1159
                gear^.WDTimer := Trunc(lua_tonumber(L, 4));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1160
            if not lua_isnoneornil(L, 5) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1161
                gear^.Radius := Trunc(lua_tonumber(L, 5));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1162
            if not lua_isnoneornil(L, 6) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1163
                gear^.Density:= int2hwFloat(Trunc(lua_tonumber(L, 6))) / 10000;
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1164
            if not lua_isnoneornil(L, 7) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1165
                gear^.Karma := Trunc(lua_tonumber(L, 7));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1166
            if not lua_isnoneornil(L, 8) then
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1167
                gear^.DirAngle:= lua_tonumber(L, 8);
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1168
            if not lua_isnoneornil(L, 9) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1169
                gear^.AdvBounce := Trunc(lua_tonumber(L, 9));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1170
            if not lua_isnoneornil(L, 10) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1171
                gear^.ImpactSound := TSound(Trunc(lua_tonumber(L, 10)));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1172
            if not lua_isnoneornil(L, 11) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1173
                gear^.nImpactSounds := Trunc(lua_tonumber(L, 11));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1174
            if not lua_isnoneornil(L, 12) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1175
                gear^.Tint := Trunc(lua_tonumber(L, 12));
11172
78f9fd42fa46 Add damage to gear values to mess with
nemo
parents: 11066
diff changeset
  1176
            if not lua_isnoneornil(L, 13) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1177
                gear^.Damage := Trunc(lua_tonumber(L, 13));
11468
2f6f8baa2a97 Make weapon damage in most cases be a structure value and also expose it to lua. Needs testing/review due to conditions at time of doing this (w/ one arm, dizzy/tingling due to sodium citrate), and just number of places changed..
nemo
parents: 11317
diff changeset
  1178
            if not lua_isnoneornil(L, 14) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1179
                gear^.Boom := Trunc(lua_tonumber(L, 14));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1180
            end;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1181
//        end
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1182
//    else
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1183
//        lua_pushnil(L); // return value on stack (nil)
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1184
    lc_setgearvalues:= 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
  1185
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
  1186
3058
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
  1187
function lc_getfollowgear(L : Plua_State) : LongInt; Cdecl;
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
  1188
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1189
    if CheckLuaParamCount(L, 0, 'GetFollowGear', '') then
3058
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
  1190
        begin
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
  1191
        if FollowGear = nil then
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
  1192
            lua_pushnil(L)
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
  1193
        else
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1194
            lua_pushnumber(L, FollowGear^.uid);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1195
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1196
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1197
        lua_pushnil(L);
3058
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
  1198
    lc_getfollowgear:= 1; // 1 return value
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
  1199
end;
2ebc20485344 Engine:
smxx
parents: 3045
diff changeset
  1200
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
  1201
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
  1202
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
  1203
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1204
    if CheckLuaParamCount(L, 1, 'GetGearType', 'gearUid') 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
  1205
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1206
        gear:= GearByUID(Trunc(lua_tonumber(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
  1207
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1208
            lua_pushnumber(L, ord(gear^.Kind))
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
  1209
        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
  1210
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1211
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1212
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1213
        lua_pushnil(L); // return value on stack (nil)
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
  1214
    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
  1215
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
  1216
3892
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  1217
function lc_getgearmessage(L : Plua_State) : LongInt; Cdecl;
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  1218
var gear : PGear;
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  1219
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1220
    if CheckLuaParamCount(L, 1, 'GetGearMessage', 'gearUid') then
3892
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  1221
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1222
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
3892
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  1223
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1224
            lua_pushnumber(L, gear^.message)
3892
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  1225
        else
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  1226
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1227
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1228
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1229
        lua_pushnil(L); // return value on stack (nil)
3892
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  1230
    lc_getgearmessage:= 1
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  1231
end;
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  1232
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
  1233
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
  1234
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
  1235
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1236
    if CheckLuaParamCount(L, 1, 'GetGearElasticity', 'gearUid') then
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
  1237
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1238
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
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
  1239
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1240
            lua_pushnumber(L, hwRound(gear^.elasticity * _10000))
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
  1241
        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
  1242
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1243
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1244
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1245
        lua_pushnil(L); // return value on stack (nil)
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
  1246
    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
  1247
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
  1248
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1249
function lc_setgearelasticity(L : Plua_State) : LongInt; Cdecl;
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1250
var gear: PGear;
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1251
begin
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1252
    if CheckLuaParamCount(L, 2, 'SetGearElasticity', 'gearUid, Elasticity') then
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1253
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1254
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1255
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1256
            gear^.Elasticity:= int2hwFloat(Trunc(lua_tonumber(L, 2))) / 10000
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1257
        end;
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1258
    lc_setgearelasticity:= 0
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1259
end;
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1260
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1261
function lc_getgearfriction(L : Plua_State) : LongInt; Cdecl;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1262
var gear : PGear;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1263
begin
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1264
    if CheckLuaParamCount(L, 1, 'GetGearFriction', 'gearUid') then
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1265
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1266
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1267
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1268
            lua_pushnumber(L, hwRound(gear^.friction * _10000))
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1269
        else
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1270
            lua_pushnil(L);
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1271
        end
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1272
    else
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1273
        lua_pushnil(L); // return value on stack (nil)
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1274
    lc_getgearfriction:= 1
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1275
end;
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  1276
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1277
function lc_setgearfriction(L : Plua_State) : LongInt; Cdecl;
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1278
var gear: PGear;
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1279
begin
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1280
    if CheckLuaParamCount(L, 2, 'SetGearFriction', 'gearUid, Friction') then
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1281
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1282
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1283
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1284
            gear^.Friction:= int2hwFloat(Trunc(lua_tonumber(L, 2))) / 10000
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1285
        end;
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1286
    lc_setgearfriction:= 0
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1287
end;
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  1288
3896
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
  1289
function lc_setgearmessage(L : Plua_State) : LongInt; Cdecl;
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
  1290
var gear : PGear;
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
  1291
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1292
    if CheckLuaParamCount(L, 2, 'SetGearMessage', 'gearUid, message') then
3896
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
  1293
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1294
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
3896
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
  1295
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1296
            gear^.message:= Trunc(lua_tonumber(L, 2));
3896
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
  1297
        end;
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
  1298
    lc_setgearmessage:= 0
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
  1299
end;
59de68d541f1 Engine:
smaxx
parents: 3894
diff changeset
  1300
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1301
function lc_getgearpos(L : Plua_State) : LongInt; Cdecl;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1302
var gear : PGear;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1303
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1304
    if CheckLuaParamCount(L, 1, 'GetGearPos', 'gearUid') then
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1305
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1306
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1307
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1308
            lua_pushnumber(L, gear^.Pos)
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1309
        else
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1310
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1311
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1312
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1313
        lua_pushnil(L); // return value on stack (nil)
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1314
    lc_getgearpos:= 1
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1315
end;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1316
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1317
function lc_setgearpos(L : Plua_State) : LongInt; Cdecl;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1318
var gear : PGear;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1319
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1320
    if CheckLuaParamCount(L, 2, 'SetGearPos', 'gearUid, value') then
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1321
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1322
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1323
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1324
            gear^.Pos:= Trunc(lua_tonumber(L, 2));
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1325
        end;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1326
    lc_setgearpos:= 0
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1327
end;
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  1328
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
  1329
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
  1330
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
  1331
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1332
    if CheckLuaParamCount(L, 1, 'GetGearCollisionMask', 'gearUid') then
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
  1333
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1334
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
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
  1335
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1336
            lua_pushnumber(L, gear^.CollisionMask)
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
  1337
        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
  1338
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1339
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1340
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1341
        lua_pushnil(L); // return value on stack (nil)
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
  1342
    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
  1343
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
  1344
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
  1345
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
  1346
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
  1347
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1348
    if CheckLuaParamCount(L, 2, 'SetGearCollisionMask', 'gearUid, mask') then
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
  1349
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1350
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
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
  1351
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1352
            gear^.CollisionMask:= Trunc(lua_tonumber(L, 2));
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
  1353
        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
  1354
    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
  1355
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
  1356
3755
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
  1357
function lc_gethoglevel(L : Plua_State): LongInt; Cdecl;
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
  1358
var gear : PGear;
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
  1359
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1360
    if CheckLuaParamCount(L, 1, 'GetHogLevel', 'gearUid') then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  1361
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1362
        gear := GearByUID(Trunc(lua_tonumber(L, 1)));
8228
8cc5dc7f7ef9 kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents: 8145
diff changeset
  1363
        if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1364
            lua_pushnumber(L, gear^.Hedgehog^.BotLevel)
3755
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
  1365
        else
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
  1366
            lua_pushnil(L);
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
  1367
    end;
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
  1368
    lc_gethoglevel := 1;
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
  1369
end;
02dc9fcb6477 GetHogLevel lua function
burp
parents: 3750
diff changeset
  1370
4496
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
  1371
function lc_sethoglevel(L : Plua_State) : LongInt; Cdecl;
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
  1372
var gear : PGear;
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
  1373
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1374
    if CheckLuaParamCount(L, 2, 'SetHogLevel', 'gearUid, level') then
4496
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
  1375
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1376
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
4496
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
  1377
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1378
            gear^.Hedgehog^.BotLevel:= Trunc(lua_tonumber(L, 2));
4496
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
  1379
        end;
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
  1380
    lc_sethoglevel:= 0
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
  1381
end;
ba5da3388110 add missing setter for botlevel
nemo
parents: 4484
diff changeset
  1382
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
  1383
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
  1384
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
  1385
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1386
    if CheckLuaParamCount(L, 1, 'GetHogClan', 'gearUid') 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
  1387
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1388
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
8228
8cc5dc7f7ef9 kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents: 8145
diff changeset
  1389
        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
  1390
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1391
            lua_pushnumber(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
  1392
            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
  1393
        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
  1394
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1395
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1396
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1397
        lua_pushnil(L); // return value on stack (nil)
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
  1398
    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
  1399
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
  1400
4498
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
  1401
function lc_getclancolor(L : Plua_State) : LongInt; Cdecl;
11736
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1402
var idx: integer;
4498
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
  1403
begin
11736
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1404
    if CheckLuaParamCount(L, 1, 'GetClanColor', 'clanIdx') then
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1405
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1406
        idx:= Trunc(lua_tonumber(L, 1));
11736
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1407
        if (not lua_isnumber(L, 1)) then
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1408
            begin
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1409
            LuaError('Argument ''clanIdx'' must be a number!');
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1410
            lua_pushnil(L);
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1411
            end
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1412
        else if (idx < 0) or (idx >= ClansCount) then
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1413
            begin
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1414
            LuaError('Argument ''clanIdx'' out of range! (There are currently ' + IntToStr(ClansCount) + ' clans, so valid range is: 0-' + IntToStr(ClansCount-1) + ')');
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1415
            lua_pushnil(L);
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1416
            end
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1417
        else
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1418
            lua_pushnumber(L, ClansArray[idx]^.Color shl 8 or $FF);
11736
e9481c5a130b Lua-API - GetClanColor: Verify argument and display error message on fail (instead of engine crash)
sheepluva
parents: 11678
diff changeset
  1419
        end
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1420
    else
4498
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
  1421
        lua_pushnil(L); // return value on stack (nil)
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
  1422
    lc_getclancolor:= 1
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
  1423
end;
8c9595e39539 clan color fetch
nemo
parents: 4496
diff changeset
  1424
4882
b4c84db92d8f expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents: 4875
diff changeset
  1425
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
  1426
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
  1427
    team : PTeam;
14666
9e7092e5990a Simplify code for SetClanColor
Wuzzy <Wuzzy2@mail.ru>
parents: 14663
diff changeset
  1428
    hh  : THedgehog;
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
  1429
    i, j : LongInt;
14663
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1430
    colorArg: Int64;
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1431
    color: LongWord;
4882
b4c84db92d8f expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents: 4875
diff changeset
  1432
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1433
    if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') 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
  1434
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1435
        i:= Trunc(lua_tonumber(L,1));
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  1436
        if i >= ClansCount then exit(0);
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10560
diff changeset
  1437
        clan := ClansArray[i];
14663
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1438
        colorArg:= Trunc(lua_tonumber(L, 2));
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1439
        if (colorArg < 0) and (abs(colorArg) <= cClanColors) then
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1440
            // Pick clan color from settings (recommended)
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1441
            color:= ClanColorArray[Pred(abs(colorArg))]
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1442
        else if (colorArg >= 0) and (colorArg <= $ffffffff) then
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1443
            // Specify color directly
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1444
            color:= colorArg shr 8
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1445
        else
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1446
            begin
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1447
            OutError('Lua error: SetClanColor: Invalid ''color'' argument, must be between '+IntToStr(-cClanColors)+' and 0xffffffff!', true);
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1448
            lc_setclancolor:= 0;
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1449
            exit;
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1450
            end;
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1451
bc4296649bbf SetClanColor: Accept negative color argument to select user color
Wuzzy <Wuzzy2@mail.ru>
parents: 14662
diff changeset
  1452
        clan^.Color:= color;
9656
18422d205080 - More HealthTex to clan structure
unc0rr
parents: 9648
diff changeset
  1453
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
  1454
        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
  1455
            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
  1456
            team:= clan^.Teams[i];
13618
edffc9b7ad58 Add comments for most hwengine constants
Wuzzy <Wuzzy2@mail.ru>
parents: 13617
diff changeset
  1457
            for j:= 0 to cMaxHHIndex do
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
  1458
                begin
14666
9e7092e5990a Simplify code for SetClanColor
Wuzzy <Wuzzy2@mail.ru>
parents: 14663
diff changeset
  1459
                hh:= team^.Hedgehogs[j];
9e7092e5990a Simplify code for SetClanColor
Wuzzy <Wuzzy2@mail.ru>
parents: 14663
diff changeset
  1460
                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
  1461
                    begin
14666
9e7092e5990a Simplify code for SetClanColor
Wuzzy <Wuzzy2@mail.ru>
parents: 14663
diff changeset
  1462
                    FreeAndNilTexture(hh.NameTagTex);
9e7092e5990a Simplify code for SetClanColor
Wuzzy <Wuzzy2@mail.ru>
parents: 14663
diff changeset
  1463
                    hh.NameTagTex:= RenderStringTex(ansistring(hh.Name), clan^.Color, fnt16);
9e7092e5990a Simplify code for SetClanColor
Wuzzy <Wuzzy2@mail.ru>
parents: 14663
diff changeset
  1464
                    RenderHealth(hh);
9e7092e5990a Simplify code for SetClanColor
Wuzzy <Wuzzy2@mail.ru>
parents: 14663
diff changeset
  1465
                    team^.Hedgehogs[j]:= hh;
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
  1466
                    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
  1467
                end;
10634
35d059bd0932 Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents: 10618
diff changeset
  1468
            FreeAndNilTexture(team^.NameTagTex);
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10122
diff changeset
  1469
            team^.NameTagTex:= RenderStringTex(ansistring(clan^.Teams[i]^.TeamName), clan^.Color, fnt16);
9656
18422d205080 - More HealthTex to clan structure
unc0rr
parents: 9648
diff changeset
  1470
            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
  1471
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  1472
        FreeAndNilTexture(clan^.HealthTex);
15604
6a38a30e772a Fix wrong team health bar height after calling SetClanColor
Wuzzy <Wuzzy2@mail.ru>
parents: 15198
diff changeset
  1473
        clan^.HealthTex:= makeHealthBarTexture(cTeamHealthWidth + 5, cTeamHealthHeight, clan^.Color);
9656
18422d205080 - More HealthTex to clan structure
unc0rr
parents: 9648
diff changeset
  1474
        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
  1475
4882
b4c84db92d8f expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents: 4875
diff changeset
  1476
    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
  1477
end;
b4c84db92d8f expose set clan color for Cairo. might also be useful for betrayals in campaign mode or somesuch
nemo
parents: 4875
diff changeset
  1478
11029
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1479
function lc_gethogvoicepack(L : Plua_State) : LongInt; Cdecl;
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1480
var gear : PGear;
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1481
begin
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1482
    if CheckLuaParamCount(L, 1, 'GetHogVoicepack', 'gearUid') then
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1483
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1484
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
11029
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1485
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1486
            lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Voicepack^.name))
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1487
        else
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1488
            lua_pushnil(L);
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1489
        end
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1490
    else
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1491
        lua_pushnil(L); // return value on stack (nil)
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1492
    lc_gethogvoicepack:= 1
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1493
end;
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1494
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1495
function lc_gethoggrave(L : Plua_State) : LongInt; Cdecl;
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1496
var gear : PGear;
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1497
begin
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1498
    if CheckLuaParamCount(L, 1, 'GetHogGrave', 'gearUid') then
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1499
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1500
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
11029
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1501
        if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1502
            lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.GraveName))
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1503
        else
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1504
            lua_pushnil(L);
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1505
        end
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1506
    else
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1507
        lua_pushnil(L); // return value on stack (nil)
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1508
    lc_gethoggrave:= 1
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1509
end;
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1510
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1511
function lc_gethogflag(L : Plua_State) : LongInt; Cdecl;
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1512
var gear : PGear;
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1513
begin
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1514
    if CheckLuaParamCount(L, 1, 'GetHogFlag', 'gearUid') then
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1515
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1516
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
11847
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1517
        // TODO error messages
11029
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1518
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1519
            lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.Flag))
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1520
        else
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1521
            lua_pushnil(L);
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1522
        end
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1523
    else
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1524
        lua_pushnil(L); // return value on stack (nil)
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1525
    lc_gethogflag:= 1
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1526
end;
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  1527
12046
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1528
function lc_gethogfort(L : Plua_State) : LongInt; Cdecl;
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1529
var gear : PGear;
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1530
begin
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1531
    if CheckLuaParamCount(L, 1, 'GetHogFort', 'gearUid') then
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1532
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1533
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
12046
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1534
        // TODO error messages
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1535
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1536
            lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.FortName))
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1537
        else
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1538
            lua_pushnil(L);
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1539
        end
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1540
    else
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1541
        lua_pushnil(L); // return value on stack (nil)
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1542
    lc_gethogfort:= 1
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1543
end;
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  1544
15100
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1545
function lc_ishogalive(L : Plua_State) : LongInt; Cdecl;
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1546
var gear : PGear;
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1547
begin
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1548
    if CheckLuaParamCount(L, 1, 'IsHogAlive', 'gearUid') then
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1549
        begin
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1550
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1551
        if gear <> nil then
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1552
            if gear^.Kind = gtHedgehog then
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1553
                if (gear^.Health > 0) and (gear^.Health > gear^.Damage) and ((gear^.State and (gstDrowning or gstHHDeath)) = 0) and ((gear^.Message and gmDestroy) = 0) then
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1554
                    lua_pushboolean(L, true)
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1555
                else
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1556
                    lua_pushboolean(L, false)
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1557
            else
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1558
                lua_pushboolean(L, false)
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1559
        else
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1560
            lua_pushboolean(L, false);
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1561
        end
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1562
    else
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1563
        lua_pushnil(L); // return value on stack (nil)
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1564
    lc_ishogalive:= 1
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1565
end;
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  1566
11847
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1567
function lc_ishoglocal(L : Plua_State) : LongInt; Cdecl;
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1568
var gear : PGear;
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1569
begin
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1570
    if CheckLuaParamCount(L, 1, 'IsHogLocal', 'gearUid') then
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1571
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1572
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
11847
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1573
        // TODO error messages
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1574
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1575
            lua_pushboolean(L, IsHogLocal(gear^.Hedgehog))
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1576
        else
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1577
            lua_pushnil(L);
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1578
        end
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1579
    else
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1580
        lua_pushnil(L); // return value on stack (nil)
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1581
    lc_ishoglocal:= 1
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1582
end;
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1583
4236
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
  1584
function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl;
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
  1585
var gear : PGear;
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
  1586
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1587
    if CheckLuaParamCount(L, 1, 'GetHogTeamName', 'gearUid') then
4236
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
  1588
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1589
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
11847
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  1590
        // TODO error messages
8228
8cc5dc7f7ef9 kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents: 8145
diff changeset
  1591
        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
  1592
            lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName))
4236
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
  1593
        else
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
  1594
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1595
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1596
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1597
        lua_pushnil(L); // return value on stack (nil)
4236
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
  1598
    lc_gethogteamname:= 1
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
  1599
end;
fa2680cfff86 added function GetHogTeamName to lua, makes TeamsCount more useful
Henek
parents: 4235
diff changeset
  1600
9788
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1601
function lc_sethogteamname(L : Plua_State) : LongInt; Cdecl;
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1602
var gear : PGear;
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1603
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1604
    if CheckLuaParamCount(L, 2, 'SetHogTeamName', 'gearUid, name') then
9788
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1605
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1606
        gear := GearByUID(Trunc(lua_tonumber(L, 1)));
9788
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1607
        if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1608
            begin
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1609
            gear^.Hedgehog^.Team^.TeamName := lua_tostring(L, 2);
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1610
10634
35d059bd0932 Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents: 10618
diff changeset
  1611
            FreeAndNilTexture(gear^.Hedgehog^.Team^.NameTagTex);
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10122
diff changeset
  1612
            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
  1613
            end
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1614
        else
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1615
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1616
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1617
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1618
        lua_pushnil(L); // return value on stack (nil)
9788
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1619
    lc_sethogteamname:= 1
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1620
end;
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  1621
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
  1622
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
  1623
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
  1624
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1625
    if CheckLuaParamCount(L, 1, 'GetHogName', 'gearUid') 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
  1626
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1627
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
8228
8cc5dc7f7ef9 kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents: 8145
diff changeset
  1628
        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
  1629
            begin
4372
3836973380b9 remove some more PHedgehog casts
nemo
parents: 4371
diff changeset
  1630
            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
  1631
            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
  1632
        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
  1633
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1634
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1635
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1636
        lua_pushnil(L); // return value on stack (nil)
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
  1637
    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
  1638
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
  1639
5245
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
  1640
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
  1641
var gear : PGear;
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
  1642
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1643
    if CheckLuaParamCount(L, 2, 'SetHogName', 'gearUid, name') then
5245
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
  1644
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1645
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
5245
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
  1646
        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
  1647
            begin
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
  1648
            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
  1649
10634
35d059bd0932 Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents: 10618
diff changeset
  1650
            FreeAndNilTexture(gear^.Hedgehog^.NameTagTex);
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10122
diff changeset
  1651
            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
  1652
            end
5245
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
  1653
        end;
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
  1654
    lc_sethogname:= 0;
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
  1655
end;
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
  1656
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1657
function lc_gettimer(L : Plua_State) : LongInt; Cdecl;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1658
var gear : PGear;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1659
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1660
    if CheckLuaParamCount(L, 1, 'GetTimer', 'gearUid') then
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1661
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1662
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1663
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1664
            lua_pushnumber(L, gear^.Timer)
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1665
        else
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1666
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1667
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1668
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1669
        lua_pushnil(L); // return value on stack (nil)
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1670
    lc_gettimer:= 1
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1671
end;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1672
10589
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1673
function lc_getflighttime(L : Plua_State) : LongInt; Cdecl;
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1674
var gear : PGear;
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1675
begin
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1676
    if CheckLuaParamCount(L, 1, 'GetFlightTime', 'gearUid') then
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1677
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1678
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
10589
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1679
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1680
            lua_pushnumber(L, gear^.FlightTime)
10589
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1681
        else
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1682
            lua_pushnil(L);
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1683
        end
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1684
    else
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1685
        lua_pushnil(L); // return value on stack (nil)
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1686
    lc_getflighttime:= 1
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1687
end;
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  1688
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1689
function lc_gethealth(L : Plua_State) : LongInt; Cdecl;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1690
var gear : PGear;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1691
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1692
    if CheckLuaParamCount(L, 1, 'GetHealth', 'gearUid') then
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1693
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1694
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1695
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1696
            lua_pushnumber(L, gear^.Health)
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1697
        else
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1698
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1699
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1700
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1701
        lua_pushnil(L); // return value on stack (nil)
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1702
    lc_gethealth:= 1
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1703
end;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1704
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
  1705
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
  1706
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
  1707
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1708
    if CheckLuaParamCount(L, 1, 'GetX', 'gearUid') 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
  1709
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1710
        gear:= GearByUID(Trunc(lua_tonumber(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
  1711
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1712
            lua_pushnumber(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
  1713
        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
  1714
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1715
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1716
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1717
        lua_pushnil(L); // return value on stack (nil)
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
  1718
    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
  1719
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
  1720
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1721
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
  1722
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
  1723
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1724
    if CheckLuaParamCount(L, 1, 'GetY', 'gearUid') 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
  1725
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1726
        gear:= GearByUID(Trunc(lua_tonumber(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
  1727
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1728
            lua_pushnumber(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
  1729
        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
  1730
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1731
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1732
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1733
        lua_pushnil(L); // return value on stack (nil)
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
  1734
    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
  1735
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
  1736
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1737
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
  1738
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
  1739
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1740
    if CheckLuaParamCount(L, 2, 'CopyPV', 'fromGearUid, toGearUid') 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
  1741
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1742
        gears:= GearByUID(Trunc(lua_tonumber(L, 1)));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1743
        geard:= GearByUID(Trunc(lua_tonumber(L, 2)));
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
  1744
        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
  1745
            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
  1746
            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
  1747
            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
  1748
            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
  1749
            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
  1750
            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
  1751
        end;
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1752
    lc_copypv:= 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
  1753
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
  1754
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  1755
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
  1756
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
  1757
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1758
    if CheckLuaParamCount(L, 1, 'FollowGear', 'gearUid') 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
  1759
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1760
        gear:= GearByUID(Trunc(lua_tonumber(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
  1761
        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
  1762
        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
  1763
    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
  1764
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
  1765
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1766
function lc_hogsay(L : Plua_State) : LongInt; Cdecl;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1767
var gear : PGear;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1768
   vgear : PVisualGear;
4533
8d35c3e0e6ba add optional state parameter to hogsay
nemo
parents: 4523
diff changeset
  1769
       s : LongWord;
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1770
       n : LongInt;
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1771
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1772
    if CheckAndFetchParamCount(L, 3, 4, 'HogSay', 'gearUid, text, manner [, vgState]', n) then
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1773
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1774
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1775
        if gear <> nil then
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1776
            begin
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1777
            // state defaults to 0 if state param is given
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1778
            if n = 4 then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1779
                s:= Trunc(lua_tonumber(L, 4))
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1780
            else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1781
                s:= 0;
4533
8d35c3e0e6ba add optional state parameter to hogsay
nemo
parents: 4523
diff changeset
  1782
            vgear:= AddVisualGear(0, 0, vgtSpeechBubble, s, true);
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1783
            if vgear <> nil then
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1784
               begin
10518
dbbe2f6c0a96 make gear ability to speak somewhat less ironic
sheepluva
parents: 10516
diff changeset
  1785
               vgear^.Text:= lua_tostring(L, 2);
10210
1a6b9a98147c hm. I think I forgot to commit this when adding speech bubble change
nemo
parents: 10150
diff changeset
  1786
               if Gear^.Kind = gtHedgehog then
1a6b9a98147c hm. I think I forgot to commit this when adding speech bubble change
nemo
parents: 10150
diff changeset
  1787
                   begin
13897
aa321e51da14 make explicit for pas2c some string casts that fpc was probably doing automatically
nemo
parents: 13891
diff changeset
  1788
                   AddChatString(#9+Format(shortstring(trmsg[sidChatHog]), gear^.Hedgehog^.Name, vgear^.text));
10210
1a6b9a98147c hm. I think I forgot to commit this when adding speech bubble change
nemo
parents: 10150
diff changeset
  1789
                   vgear^.Hedgehog:= gear^.Hedgehog
1a6b9a98147c hm. I think I forgot to commit this when adding speech bubble change
nemo
parents: 10150
diff changeset
  1790
                   end
1a6b9a98147c hm. I think I forgot to commit this when adding speech bubble change
nemo
parents: 10150
diff changeset
  1791
               else vgear^.Frame:= gear^.uid;
1a6b9a98147c hm. I think I forgot to commit this when adding speech bubble change
nemo
parents: 10150
diff changeset
  1792
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1793
               vgear^.FrameTicks:= Trunc(lua_tonumber(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
  1794
               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
  1795
                   vgear^.FrameTicks:= 1;
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1796
               lua_pushnumber(L, vgear^.Uid);
5529
9a47cff3910a return visual gear in hogsay
nemo
parents: 5527
diff changeset
  1797
               end
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1798
            end
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  1799
        else
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  1800
            lua_pushnil(L)
4533
8d35c3e0e6ba add optional state parameter to hogsay
nemo
parents: 4523
diff changeset
  1801
        end
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1802
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1803
        lua_pushnil(L);
5529
9a47cff3910a return visual gear in hogsay
nemo
parents: 5527
diff changeset
  1804
    lc_hogsay:= 1
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1805
end;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  1806
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1807
function lc_switchhog(L : Plua_State) : LongInt; Cdecl;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1808
var gear, prevgear : PGear;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1809
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1810
    if CheckLuaParamCount(L, 1, 'SwitchHog', 'gearUid') then
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1811
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1812
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1813
// 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
  1814
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (CurrentHedgehog <> nil) then
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1815
            begin
15053
b181ff6367c9 Reset MultiShootAttacks to 0 when calling SwitchHog in Lua
Wuzzy <Wuzzy2@mail.ru>
parents: 15038
diff changeset
  1816
            CurrentHedgehog^.MultiShootAttacks:= 0;
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1817
            prevgear := CurrentHedgehog^.Gear;
7573
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1818
            if prevgear <> nil then
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1819
                begin
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1820
                prevgear^.Active := false;
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1821
                prevgear^.State:= prevgear^.State and (not gstHHDriven);
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1822
                prevgear^.Z := cHHZ;
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1823
                prevgear^.Message:= prevgear^.Message or gmRemoveFromList or gmAddToList;
364cd923db43 extra nil check for lua hog switch
nemo
parents: 7567
diff changeset
  1824
                end;
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1825
7270
93e92e82d5c8 Step 1. Add current hedgehog as top bit of bottom byte.
nemo
parents: 7156
diff changeset
  1826
            SwitchCurrentHedgehog(gear^.Hedgehog);
12371
2b1dd699b371 Lua: Fix SwitchHog breaking the ammo menu of the new hog
Wuzzy <almikes@aol.com>
parents: 12360
diff changeset
  1827
            AmmoMenuInvalidated:= true;
7270
93e92e82d5c8 Step 1. Add current hedgehog as top bit of bottom byte.
nemo
parents: 7156
diff changeset
  1828
            CurrentTeam:= CurrentHedgehog^.Team;
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1829
12371
2b1dd699b371 Lua: Fix SwitchHog breaking the ammo menu of the new hog
Wuzzy <almikes@aol.com>
parents: 12360
diff changeset
  1830
            repeat
2b1dd699b371 Lua: Fix SwitchHog breaking the ammo menu of the new hog
Wuzzy <almikes@aol.com>
parents: 12360
diff changeset
  1831
                CurrentTeam^.CurrHedgehog := (CurrentTeam^.CurrHedgehog + 1) mod CurrentTeam^.HedgehogsNumber
2b1dd699b371 Lua: Fix SwitchHog breaking the ammo menu of the new hog
Wuzzy <almikes@aol.com>
parents: 12360
diff changeset
  1832
            until
2b1dd699b371 Lua: Fix SwitchHog breaking the ammo menu of the new hog
Wuzzy <almikes@aol.com>
parents: 12360
diff changeset
  1833
                CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear = CurrentHedgehog^.Gear;
2b1dd699b371 Lua: Fix SwitchHog breaking the ammo menu of the new hog
Wuzzy <almikes@aol.com>
parents: 12360
diff changeset
  1834
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1835
            gear^.State:= gear^.State or gstHHDriven;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1836
            gear^.Active := true;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1837
            gear^.Z := cCurrHHZ;
7401
4c3ec3dca0c7 oh yeah, these too
nemo
parents: 7339
diff changeset
  1838
            gear^.Message:= gear^.Message or gmRemoveFromList or gmAddToList;
4851
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1839
            end
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1840
        end;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1841
    lc_switchhog:= 0
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1842
end;
3ba1ecc06dc6 SwitchHog in scripting
nemo
parents: 4850
diff changeset
  1843
13378
c53530142442 Lua API: Add EnableSwitchHog to manually enable hog switching
Wuzzy <Wuzzy2@mail.ru>
parents: 13373
diff changeset
  1844
function lc_enableswitchhog(L : Plua_State) : LongInt; Cdecl;
13380
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1845
var gear, iterator: PGear;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1846
    alreadySwitching: boolean;
13378
c53530142442 Lua API: Add EnableSwitchHog to manually enable hog switching
Wuzzy <Wuzzy2@mail.ru>
parents: 13373
diff changeset
  1847
begin
c53530142442 Lua API: Add EnableSwitchHog to manually enable hog switching
Wuzzy <Wuzzy2@mail.ru>
parents: 13373
diff changeset
  1848
    if CheckLuaParamCount(L, 0, 'EnableSwitchHog', '') then
13380
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1849
        if ((CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil)) then
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1850
            begin
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1851
            alreadySwitching:= false;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1852
            iterator:= GearsList;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1853
            // Check if there's already a switcher gear
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1854
            while (iterator <> nil) do
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1855
                begin
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1856
                if (iterator^.Kind = gtSwitcher) then
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1857
                    begin
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1858
                    alreadySwitching:= true;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1859
                    lua_pushnumber(L, iterator^.Uid);
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1860
                    break;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1861
                    end;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1862
                iterator:= iterator^.NextGear;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1863
                end;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1864
            if (not alreadySwitching) then
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1865
                begin
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1866
                // Enable switching and return gear UID
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1867
                gear:= AddGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), gtSwitcher, 0, _0, _0, 0);
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1868
                CurAmmoGear:= gear;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1869
                lastGearByUID:= gear;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1870
                bShowFinger:= false;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1871
                lua_pushnumber(L, gear^.Uid);
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1872
                end;
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1873
            end
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1874
    // Return nil on failure
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1875
        else
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1876
            lua_pushnil(L)
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1877
    else
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1878
        lua_pushnil(L);
cd55c7f25e04 Make EnableSwitchHog() more robust against failure, return gear UID
Wuzzy <Wuzzy2@mail.ru>
parents: 13378
diff changeset
  1879
    lc_enableswitchhog:= 1;
13378
c53530142442 Lua API: Add EnableSwitchHog to manually enable hog switching
Wuzzy <Wuzzy2@mail.ru>
parents: 13373
diff changeset
  1880
end;
c53530142442 Lua API: Add EnableSwitchHog to manually enable hog switching
Wuzzy <Wuzzy2@mail.ru>
parents: 13373
diff changeset
  1881
4481
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1882
function lc_addammo(L : Plua_State) : LongInt; Cdecl;
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1883
var gear : PGear;
12947
c8b7bc04eb4c Lua API: AddAmmo unselects weapons before it would remove current ammo from current hog
Wuzzy <Wuzzy2@mail.ru>
parents: 12939
diff changeset
  1884
    at, n, c: LongInt;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1885
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  1886
    callStr = 'AddAmmo';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  1887
    paramsStr = 'gearUid, ammoType [, ammoCount]';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  1888
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  1889
    if CheckAndFetchParamCount(L, 2, 3, callStr, paramsStr, n) then
4481
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1890
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  1891
        at:= LuaToAmmoTypeOrd(L, 2, callStr, paramsStr);
12947
c8b7bc04eb4c Lua API: AddAmmo unselects weapons before it would remove current ammo from current hog
Wuzzy <Wuzzy2@mail.ru>
parents: 12939
diff changeset
  1892
        if (at >= 0) and (TAmmoType(at) <> amNothing) then
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1893
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1894
            gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1895
            if (gear <> nil) and (gear^.Hedgehog <> nil) then
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1896
                if n = 2 then
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1897
                    AddAmmo(gear^.Hedgehog^, TAmmoType(at))
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1898
                else
12947
c8b7bc04eb4c Lua API: AddAmmo unselects weapons before it would remove current ammo from current hog
Wuzzy <Wuzzy2@mail.ru>
parents: 12939
diff changeset
  1899
                    begin
c8b7bc04eb4c Lua API: AddAmmo unselects weapons before it would remove current ammo from current hog
Wuzzy <Wuzzy2@mail.ru>
parents: 12939
diff changeset
  1900
                    c:= Trunc(lua_tonumber(L, 3));
c8b7bc04eb4c Lua API: AddAmmo unselects weapons before it would remove current ammo from current hog
Wuzzy <Wuzzy2@mail.ru>
parents: 12939
diff changeset
  1901
                    if (c = 0) and (CurrentHedgehog = gear^.Hedgehog) and (gear^.Hedgehog^.CurAmmoType = TAmmoType(at)) then
c8b7bc04eb4c Lua API: AddAmmo unselects weapons before it would remove current ammo from current hog
Wuzzy <Wuzzy2@mail.ru>
parents: 12939
diff changeset
  1902
                        ParseCommand('setweap ' + char(0), true, true);
c8b7bc04eb4c Lua API: AddAmmo unselects weapons before it would remove current ammo from current hog
Wuzzy <Wuzzy2@mail.ru>
parents: 12939
diff changeset
  1903
                    SetAmmo(gear^.Hedgehog^, TAmmoType(at), c);
c8b7bc04eb4c Lua API: AddAmmo unselects weapons before it would remove current ammo from current hog
Wuzzy <Wuzzy2@mail.ru>
parents: 12939
diff changeset
  1904
                    end;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1905
            end;
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1906
        end;
4481
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1907
    lc_addammo:= 0
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1908
end;
0d73e7db3d59 Eh. Since you asked. AddAmmo hook for Lua
nemo
parents: 4456
diff changeset
  1909
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
  1910
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
  1911
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
  1912
    ammo : PAmmo;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1913
    at   : LongInt;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1914
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  1915
    callStr = 'GetAmmoCount';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  1916
    paramsStr = 'gearUid, ammoType';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  1917
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  1918
    if CheckLuaParamCount(L, 2, callStr, paramsStr) 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
  1919
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1920
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  1921
        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
  1922
            begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  1923
            at:= LuaToAmmoTypeOrd(L, 2, callStr, paramsStr);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1924
            if at >= 0 then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1925
                begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1926
                ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1927
                if ammo^.AmmoType = amNothing then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1928
                    lua_pushnumber(L, 0)
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1929
                else
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1930
                    lua_pushnumber(L, ammo^.Count);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  1931
                end;
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
  1932
            end
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1933
        else lua_pushnumber(L, 0);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1934
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1935
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  1936
        lua_pushnil(L);
6046
d681b8127523 this needs to actually return something
nemo
parents: 6019
diff changeset
  1937
    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
  1938
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
  1939
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
  1940
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
  1941
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
  1942
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1943
    if CheckLuaParamCount(L, 2, 'SetHealth', 'gearUid, health') 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
  1944
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1945
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
3723
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1946
        if gear <> nil then
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1947
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1948
            gear^.Health:= Trunc(lua_tonumber(L, 2));
5245
ce407084728f Fully playable version of Space Invasion (fingers crossed). No bugs known.
mikade
parents: 5243
diff changeset
  1949
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1950
            if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1951
                begin
13597
f7cbf7d8298d Cap hedgehog health to prevent overflow bugs
Wuzzy <Wuzzy2@mail.ru>
parents: 13595
diff changeset
  1952
                if gear^.Health > cMaxHogHealth then
f7cbf7d8298d Cap hedgehog health to prevent overflow bugs
Wuzzy <Wuzzy2@mail.ru>
parents: 13595
diff changeset
  1953
                    gear^.Health:= cMaxHogHealth;
f7cbf7d8298d Cap hedgehog health to prevent overflow bugs
Wuzzy <Wuzzy2@mail.ru>
parents: 13595
diff changeset
  1954
                if gear^.Health < 0 then
f7cbf7d8298d Cap hedgehog health to prevent overflow bugs
Wuzzy <Wuzzy2@mail.ru>
parents: 13595
diff changeset
  1955
                    gear^.Health:= 0;
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1956
                RenderHealth(gear^.Hedgehog^);
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1957
                RecountTeamHealth(gear^.Hedgehog^.Team)
14775
b39da9cf7616 Renew crate health display when health changed
Wuzzy <Wuzzy2@mail.ru>
parents: 14771
diff changeset
  1958
                end
b39da9cf7616 Renew crate health display when health changed
Wuzzy <Wuzzy2@mail.ru>
parents: 14771
diff changeset
  1959
            else if (gear^.RenderHealth) and (gear^.Tex <> nil) then
b39da9cf7616 Renew crate health display when health changed
Wuzzy <Wuzzy2@mail.ru>
parents: 14771
diff changeset
  1960
                FreeAndNilTexture(gear^.Tex);
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1961
            Gear^.Active:= true;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  1962
            AllInactive:= false
3723
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  1963
            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
  1964
        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
  1965
    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
  1966
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
  1967
12939
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1968
function lc_healhog(L : Plua_State) : LongInt; Cdecl;
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1969
var gear : PGear;
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1970
    healthBoost, n: LongInt;
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1971
begin
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1972
    if CheckAndFetchParamCountRange(L, 2, 4, 'HealHog', 'gearUid, healthBoost [, showMessage [, tint]]', n) then
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1973
        begin
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1974
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1975
        healthBoost:= Trunc(lua_tonumber(L, 2));
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1976
        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) and (healthBoost >= 1) then
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1977
            begin
13617
a6abc2c1fc1a Show correct health increase when hog health cap is reached
Wuzzy <Wuzzy2@mail.ru>
parents: 13604
diff changeset
  1978
            healthBoost:= IncHogHealth(gear^.Hedgehog, healthBoost);
12939
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1979
            RenderHealth(gear^.Hedgehog^);
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1980
            RecountTeamHealth(gear^.Hedgehog^.Team);
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1981
            if n = 4 then
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1982
                HHHeal(gear^.Hedgehog, healthBoost, lua_toboolean(L, 3), Trunc(lua_tonumber(L, 4)))
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1983
            else if n = 3 then
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1984
                HHHeal(gear^.Hedgehog, healthBoost, lua_toboolean(L, 3))
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1985
            else if n = 2 then
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1986
                HHHeal(gear^.Hedgehog, healthBoost, true);
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1987
            Gear^.Active:= true;
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1988
            AllInactive:= false
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1989
            end
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1990
        end;
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1991
    lc_healhog:= 0
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1992
end;
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  1993
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1994
function lc_settimer(L : Plua_State) : LongInt; Cdecl;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1995
var gear : PGear;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1996
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  1997
    if CheckLuaParamCount(L, 2, 'SetTimer', 'gearUid, timer') then
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  1998
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  1999
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
14771
ab7bf5036314 Render mine timer if gear info is active
Wuzzy <Wuzzy2@mail.ru>
parents: 14666
diff changeset
  2000
        if gear <> nil then
ab7bf5036314 Render mine timer if gear info is active
Wuzzy <Wuzzy2@mail.ru>
parents: 14666
diff changeset
  2001
            begin
ab7bf5036314 Render mine timer if gear info is active
Wuzzy <Wuzzy2@mail.ru>
parents: 14666
diff changeset
  2002
            gear^.Timer:= Trunc(lua_tonumber(L, 2));
ab7bf5036314 Render mine timer if gear info is active
Wuzzy <Wuzzy2@mail.ru>
parents: 14666
diff changeset
  2003
            if gear^.RenderTimer and (gear^.Tex <> nil) then
ab7bf5036314 Render mine timer if gear info is active
Wuzzy <Wuzzy2@mail.ru>
parents: 14666
diff changeset
  2004
                FreeAndNilTexture(gear^.Tex);
ab7bf5036314 Render mine timer if gear info is active
Wuzzy <Wuzzy2@mail.ru>
parents: 14666
diff changeset
  2005
            end;
3722
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  2006
        end;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  2007
    lc_settimer:= 0
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  2008
end;
eadebe4c45c9 Engine:
smaxx
parents: 3697
diff changeset
  2009
10589
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  2010
function lc_setflighttime(L : Plua_State) : LongInt; Cdecl;
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  2011
var gear : PGear;
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  2012
begin
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  2013
    if CheckLuaParamCount(L, 2, 'SetFlightTime', 'gearUid, flighttime') then
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  2014
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2015
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2016
        if gear <> nil then gear^.FlightTime:= Trunc(lua_tonumber(L, 2))
10589
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  2017
        end;
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  2018
    lc_setflighttime:= 0
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  2019
end;
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  2020
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  2021
function lc_seteffect(L : Plua_State) : LongInt; Cdecl;
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  2022
var gear: PGear;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2023
    t   : LongInt;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2024
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2025
    callStr = 'SetEffect';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2026
    paramsStr = 'gearUid, effect, effectState';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2027
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2028
    if CheckLuaParamCount(L, 3, callStr, paramsStr) then
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2029
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2030
        t:= LuaToHogEffectOrd(L, 2, callStr, paramsStr);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2031
        if t >= 0 then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2032
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2033
            gear := GearByUID(Trunc(lua_tonumber(L, 1)));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2034
            if (gear <> nil) and (gear^.Hedgehog <> nil) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2035
                gear^.Hedgehog^.Effects[THogEffect(t)]:= Trunc(lua_tonumber(L, 3));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2036
            end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2037
        end;
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  2038
    lc_seteffect := 0;
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  2039
end;
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2040
5489
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  2041
function lc_geteffect(L : Plua_State) : LongInt; Cdecl;
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  2042
var gear : PGear;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2043
    t    : LongInt;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2044
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2045
    callStr = 'GetEffect';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2046
    paramsStr = 'gearUid, effect';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2047
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2048
    if CheckLuaParamCount(L, 2, callStr, paramsStr) then
5489
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  2049
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2050
        t:= LuaToHogEffectOrd(L, 2, callStr, paramsStr);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2051
        if t >= 0 then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2052
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2053
            gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2054
            if (gear <> nil) and (gear^.Hedgehog <> nil) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2055
                lua_pushnumber(L, gear^.Hedgehog^.Effects[THogEffect(t)])
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2056
            else
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2057
                lua_pushnumber(L, 0)
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2058
            end;
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2059
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2060
    else
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2061
        lua_pushnumber(L, 0);
5489
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  2062
    lc_geteffect:= 1
f7ec6e5ad054 add getter for effects. untested.
nemo
parents: 5366
diff changeset
  2063
end;
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  2064
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
  2065
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
  2066
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
  2067
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2068
    if CheckLuaParamCount(L, 2, 'SetState', 'gearUid, state') 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
  2069
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2070
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
3723
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  2071
        if gear <> nil then
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  2072
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2073
            gear^.State:= Trunc(lua_tonumber(L, 2));
3723
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  2074
            SetAllToActive;
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  2075
            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
  2076
        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
  2077
    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
  2078
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
  2079
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2080
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
  2081
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
  2082
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2083
    if CheckLuaParamCount(L, 1, 'GetState', 'gearUid') 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
  2084
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2085
        gear:= GearByUID(Trunc(lua_tonumber(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
  2086
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2087
            lua_pushnumber(L, gear^.State)
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
        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
  2089
            lua_pushnil(L)
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2090
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2091
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2092
        lua_pushnil(L); // return value on stack (nil)
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
  2093
    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
  2094
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
  2095
7156
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  2096
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
  2097
var gear : PGear;
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  2098
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2099
    if CheckLuaParamCount(L, 1, 'GetTag', 'gearUid') then
7156
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  2100
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2101
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
7156
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  2102
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2103
            lua_pushnumber(L, gear^.Tag)
7156
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  2104
        else
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  2105
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2106
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2107
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2108
        lua_pushnil(L); // return value on stack (nil)
7156
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  2109
    lc_gettag:= 1
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  2110
end;
09262f82e99d Add a GetTag method so that SetTag doesn't feel lonely.
mikade <redgrinner@gmail.com>
parents: 7135
diff changeset
  2111
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
  2112
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
  2113
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
  2114
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2115
    if CheckLuaParamCount(L, 2, 'SetTag', 'gearUid, tag') 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
  2116
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2117
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
3723
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  2118
        if gear <> nil then
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  2119
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2120
            gear^.Tag:= Trunc(lua_tonumber(L, 2));
3723
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  2121
            SetAllToActive;
958eeaf84714 Engine:
smaxx
parents: 3722
diff changeset
  2122
            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
  2123
        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
  2124
    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
  2125
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
  2126
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2127
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
  2128
begin
3407
dcc129c4352e Engine:
smxx
parents: 3368
diff changeset
  2129
    L:= L; // avoid compiler hint
14948
9d6a25239d00 Set GameOver to true in EndGame (Lua)
Wuzzy <Wuzzy2@mail.ru>
parents: 14775
diff changeset
  2130
    GameOver:= true;
8460
75e771c3c039 fix EndGame call. w/o a proper exit, demos weren't being saved
nemo
parents: 8370
diff changeset
  2131
    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
  2132
    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
  2133
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
  2134
12286
b4dde7035fe2 New Lua call: EndTurn to end turn
Wuzzy <almikes@aol.com>
parents: 12162
diff changeset
  2135
function lc_endturn(L : Plua_State) : LongInt; Cdecl;
b4dde7035fe2 New Lua call: EndTurn to end turn
Wuzzy <almikes@aol.com>
parents: 12162
diff changeset
  2136
var n: LongInt;
b4dde7035fe2 New Lua call: EndTurn to end turn
Wuzzy <almikes@aol.com>
parents: 12162
diff changeset
  2137
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2138
    callStr = 'EndTurn';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2139
    paramsStr = '[noTaunts]';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2140
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2141
    if CheckAndFetchParamCount(L, 0, 1, callStr, paramsStr, n) then
12286
b4dde7035fe2 New Lua call: EndTurn to end turn
Wuzzy <almikes@aol.com>
parents: 12162
diff changeset
  2142
        if n >= 1 then
b4dde7035fe2 New Lua call: EndTurn to end turn
Wuzzy <almikes@aol.com>
parents: 12162
diff changeset
  2143
            LuaNoEndTurnTaunts:= lua_toboolean(L, 1);
b4dde7035fe2 New Lua call: EndTurn to end turn
Wuzzy <almikes@aol.com>
parents: 12162
diff changeset
  2144
    LuaEndTurnRequested:= true;
b4dde7035fe2 New Lua call: EndTurn to end turn
Wuzzy <almikes@aol.com>
parents: 12162
diff changeset
  2145
    lc_endturn:= 0
b4dde7035fe2 New Lua call: EndTurn to end turn
Wuzzy <almikes@aol.com>
parents: 12162
diff changeset
  2146
end;
b4dde7035fe2 New Lua call: EndTurn to end turn
Wuzzy <almikes@aol.com>
parents: 12162
diff changeset
  2147
13340
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2148
function lc_retreat(L : Plua_State) : LongInt; Cdecl;
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2149
var n, time: LongInt;
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2150
    respectFactor: Boolean;
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2151
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2152
    callStr = 'Retreat';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2153
    paramsStr = 'time [, respectGetAwayTimeFactor]';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2154
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2155
    if CheckAndFetchParamCount(L, 1, 2, callStr, paramsStr, n) then
13340
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2156
        begin
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2157
        IsGetAwayTime:= true;
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2158
        AttackBar:= 0;
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2159
        time:= Trunc(lua_tonumber(L, 1));
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2160
        if n = 2 then
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2161
            respectFactor:= lua_toboolean(L, 2)
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2162
        else
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2163
            respectFactor:= True;
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2164
        if respectFactor then
13745
d7b72ea8d136 Fix buggy behaviour when setting TurnTimeLeft through Retreat
Wuzzy <Wuzzy2@mail.ru>
parents: 13744
diff changeset
  2165
            PendingTurnTimeLeft:= (time * cGetAwayTime) div 100
13340
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2166
        else
13745
d7b72ea8d136 Fix buggy behaviour when setting TurnTimeLeft through Retreat
Wuzzy <Wuzzy2@mail.ru>
parents: 13744
diff changeset
  2167
            PendingTurnTimeLeft:= time;
d7b72ea8d136 Fix buggy behaviour when setting TurnTimeLeft through Retreat
Wuzzy <Wuzzy2@mail.ru>
parents: 13744
diff changeset
  2168
        isPendingTurnTimeLeft:= true;
13340
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2169
        if ((CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil)) then
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2170
            begin
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2171
            CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstAttacked;
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2172
            CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State and (not gstAttacking);
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2173
            end;
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2174
        end;
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2175
    lc_retreat:= 0
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2176
end;
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  2177
13170
98a0edb4bb5a Lua API: Add SkipTurn() to replace ParseCommand("skip")
Wuzzy <Wuzzy2@mail.ru>
parents: 13122
diff changeset
  2178
function lc_skipturn(L : Plua_State): LongInt; Cdecl;
98a0edb4bb5a Lua API: Add SkipTurn() to replace ParseCommand("skip")
Wuzzy <Wuzzy2@mail.ru>
parents: 13122
diff changeset
  2179
begin
98a0edb4bb5a Lua API: Add SkipTurn() to replace ParseCommand("skip")
Wuzzy <Wuzzy2@mail.ru>
parents: 13122
diff changeset
  2180
    L:= L; // avoid compiler hint
98a0edb4bb5a Lua API: Add SkipTurn() to replace ParseCommand("skip")
Wuzzy <Wuzzy2@mail.ru>
parents: 13122
diff changeset
  2181
    ParseCommand('skip', true, true);
98a0edb4bb5a Lua API: Add SkipTurn() to replace ParseCommand("skip")
Wuzzy <Wuzzy2@mail.ru>
parents: 13122
diff changeset
  2182
    lc_skipturn:= 0;
98a0edb4bb5a Lua API: Add SkipTurn() to replace ParseCommand("skip")
Wuzzy <Wuzzy2@mail.ru>
parents: 13122
diff changeset
  2183
end;
98a0edb4bb5a Lua API: Add SkipTurn() to replace ParseCommand("skip")
Wuzzy <Wuzzy2@mail.ru>
parents: 13122
diff changeset
  2184
9171
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  2185
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
  2186
var statInfo : TStatInfoType;
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2187
    i, n     : LongInt;
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2188
    color, tn: shortstring;
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2189
    needsTn  : boolean;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2190
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2191
    callStr = 'SendStat';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2192
    paramsStr = 'statInfoType, color [, teamname]';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2193
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2194
    if CheckAndFetchParamCount(L, 2, 3, callStr, paramsStr, n) then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2195
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2196
        i:= LuaToStatInfoTypeOrd(L, 1, callStr, paramsStr);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2197
        if i >= 0 then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2198
            begin
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2199
            statInfo:= TStatInfoType(i);
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2200
            needsTn:= ((statInfo = siPlayerKills) or (statInfo = siClanHealth));
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2201
            // check if param count is correct for the used statInfo
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2202
            if (n = 3) <> needsTn then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2203
                begin
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2204
                if n = 3 then
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2205
                    LuaCallError(EnumToStr(statInfo) + ' does not support the teamname parameter', callStr, paramsStr)
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2206
                else
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2207
                    LuaCallError(EnumToStr(statInfo) + ' requires the teamname parameter', callStr, paramsStr);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2208
                end
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2209
            else // count is correct!
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2210
                begin
10542
383328755384 small cleanup
sheepluva
parents: 10518
diff changeset
  2211
                if needsTn then
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2212
                    begin
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2213
                    // 3: team name
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2214
                    for i:= 0 to Pred(TeamsCount) do
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2215
                        begin
10282
f02cf95b8424 Fix pas2c build
unc0rr
parents: 10281
diff changeset
  2216
                        color:= _S'0';
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2217
                        tn:= lua_tostring(L, 3);
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2218
                        with TeamsArray[i]^ do
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2219
                            begin
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2220
                                if TeamName = tn then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2221
                                    begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2222
                                    color := uUtils.IntToStr(Clan^.Color);
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2223
                                    Break;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2224
                                    end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2225
                            end
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2226
                        end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2227
                    if (statInfo = siPlayerKills) then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2228
                        begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2229
                            SendStat(siPlayerKills, color + ' ' +
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2230
                                lua_tostring(L, 2) + ' ' + tn);
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2231
                        end
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2232
                    else if (statInfo = siClanHealth) then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2233
                        begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2234
                            SendStat(siClanHealth, color + ' ' +
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2235
                                lua_tostring(L, 2));
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2236
                        end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2237
                    end
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2238
                else
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2239
                    begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2240
                    SendStat(statInfo,lua_tostring(L, 2));
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2241
                    end;
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2242
                end;
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2243
            end;
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  2244
        end;
9171
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  2245
    lc_sendstat:= 0
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  2246
end;
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  2247
12332
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2248
function lc_sendgameresultoff(L : Plua_State) : LongInt; Cdecl;
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2249
begin
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2250
    L:= L; // avoid compiler hint
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2251
    uStats.SendGameResultOn := false;
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2252
    lc_sendgameresultoff:= 0
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2253
end;
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2254
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2255
function lc_sendrankingstatsoff(L : Plua_State) : LongInt; Cdecl;
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2256
begin
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2257
    L:= L; // avoid compiler hint
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2258
    uStats.SendRankingStatsOn := false;
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2259
    lc_sendrankingstatsoff:= 0
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2260
end;
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2261
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2262
function lc_sendachievementsstatsoff(L : Plua_State) : LongInt; Cdecl;
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2263
begin
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2264
    L:= L; // avoid compiler hint
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2265
    uStats.SendAchievementsStatsOn := false;
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2266
    lc_sendachievementsstatsoff:= 0
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2267
end;
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  2268
9180
d19c09670ec8 changed variable and function name
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9179
diff changeset
  2269
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
  2270
begin
d328fe17b195 made lua scripts able to turn off automatic game stats
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9173
diff changeset
  2271
    L:= L; // avoid compiler hint
9180
d19c09670ec8 changed variable and function name
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9179
diff changeset
  2272
    uStats.SendHealthStatsOn := false;
d19c09670ec8 changed variable and function name
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9179
diff changeset
  2273
    lc_sendhealthstatsoff:= 0
9174
d328fe17b195 made lua scripts able to turn off automatic game stats
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9173
diff changeset
  2274
end;
d328fe17b195 made lua scripts able to turn off automatic game stats
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9173
diff changeset
  2275
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
  2276
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
  2277
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
  2278
    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
  2279
    tryhard: boolean;
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2280
    left, right, n: 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
  2281
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2282
    if CheckAndFetchParamCount(L, 4, 5, 'FindPlace', 'gearUid, fall, left, right [, tryHarder]', n) 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
  2283
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2284
        gear:= GearByUID(Trunc(lua_tonumber(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
  2285
        fall:= lua_toboolean(L, 2);
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2286
        left:= Trunc(lua_tonumber(L, 3));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2287
        right:= Trunc(lua_tonumber(L, 4));
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2288
        if n = 5 then
10496
ba166d4e66f3 Fix use of uninitialized variable
unc0rr
parents: 10421
diff changeset
  2289
            tryhard:= lua_toboolean(L, 5)
ba166d4e66f3 Fix use of uninitialized variable
unc0rr
parents: 10421
diff changeset
  2290
        else
ba166d4e66f3 Fix use of uninitialized variable
unc0rr
parents: 10421
diff changeset
  2291
            tryhard:= 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
  2292
        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
  2293
            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
  2294
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2295
            lua_pushnumber(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
  2296
        else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2297
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2298
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2299
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2300
        lua_pushnil(L); // return value on stack (nil)
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
  2301
    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
  2302
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
  2303
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  2304
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
  2305
var gear: PGear;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2306
    n, s: LongInt;
13122
d52d79f35558 Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
Wuzzy <Wuzzy2@mail.ru>
parents: 13121
diff changeset
  2307
    instaVoice: boolean;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2308
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2309
    callStr = 'PlaySound';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2310
    paramsStr = 'soundId [, hhGearUid [, instaVoice]]';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2311
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2312
    if CheckAndFetchParamCountRange(L, 1, 3, callStr, paramsStr, n) then
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
  2313
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2314
        s:= LuaToSoundOrd(L, 1, callStr, paramsStr);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2315
        if s >= 0 then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2316
            begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2317
            // no gear specified
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2318
            if n = 1 then
13121
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2319
                PlaySound(TSound(s), false, true)
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2320
            else
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2321
                begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2322
                gear:= GearByUID(Trunc(lua_tonumber(L, 2)));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2323
                if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
13122
d52d79f35558 Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
Wuzzy <Wuzzy2@mail.ru>
parents: 13121
diff changeset
  2324
                    begin
d52d79f35558 Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
Wuzzy <Wuzzy2@mail.ru>
parents: 13121
diff changeset
  2325
                    instaVoice:= false;
d52d79f35558 Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
Wuzzy <Wuzzy2@mail.ru>
parents: 13121
diff changeset
  2326
                    if n = 3 then
d52d79f35558 Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
Wuzzy <Wuzzy2@mail.ru>
parents: 13121
diff changeset
  2327
                        instaVoice:= lua_toboolean(L, 3);
d52d79f35558 Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
Wuzzy <Wuzzy2@mail.ru>
parents: 13121
diff changeset
  2328
                    if instaVoice then
d52d79f35558 Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
Wuzzy <Wuzzy2@mail.ru>
parents: 13121
diff changeset
  2329
                        PlaySoundV(TSound(s), gear^.Hedgehog^.Team^.Voicepack, false, true)
d52d79f35558 Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
Wuzzy <Wuzzy2@mail.ru>
parents: 13121
diff changeset
  2330
                    else
14058
bf8b7c166b3c Play another voice as fallback if sndRevenge could not be found
Wuzzy <Wuzzy2@mail.ru>
parents: 13997
diff changeset
  2331
                        AddVoice(TSound(s), gear^.Hedgehog^.Team^.Voicepack, true, false);
13122
d52d79f35558 Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
Wuzzy <Wuzzy2@mail.ru>
parents: 13121
diff changeset
  2332
                    end;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2333
                end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2334
            end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2335
        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
  2336
    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
  2337
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
  2338
13997
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2339
function lc_playmusicsound(L : Plua_State) : LongInt; Cdecl;
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2340
var s: LongInt;
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2341
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2342
    callStr = 'PlayMusicSound';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2343
    paramsStr = 'soundId';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2344
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2345
    if CheckLuaParamCount(L, 1, callStr, paramsStr) then
13997
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2346
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2347
        s:= LuaToSoundOrd(L, 1, callStr, paramsStr);
13997
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2348
        if s >= 0 then
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2349
            PlayMusicSound(TSound(s))
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2350
        end;
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2351
    lc_playmusicsound:= 0;
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2352
end;
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2353
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2354
function lc_stopmusicsound(L : Plua_State) : LongInt; Cdecl;
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2355
var s: LongInt;
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2356
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2357
    callStr = 'StopMusicSound';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2358
    paramsStr = 'soundId';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2359
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2360
    if CheckLuaParamCount(L, 1, callStr, paramsStr) then
13997
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2361
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2362
        s:= LuaToSoundOrd(L, 1, callStr, paramsStr);
13997
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2363
        if s >= 0 then
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2364
            StopMusicSound(TSound(s))
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2365
        end;
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2366
    lc_stopmusicsound:= 0;
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2367
end;
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2368
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  2369
13121
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2370
function lc_setsoundmask(L : Plua_State) : LongInt; Cdecl;
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2371
var s: LongInt;
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2372
    soundState: boolean;
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2373
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2374
    callStr = 'SetSoundMask';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2375
    paramsStr = 'soundId, isMasked';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2376
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2377
    if CheckLuaParamCount(L, 2, callStr, paramsStr) then
13121
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2378
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2379
        s:= LuaToSoundOrd(L, 1, callStr, paramsStr);
13121
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2380
        if s <> Ord(sndNone) then
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2381
            begin
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2382
            soundState:= lua_toboolean(L, 2);
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2383
            MaskedSounds[TSound(s)]:= soundState;
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2384
            end;
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2385
        end;
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2386
    lc_setsoundmask:= 0;
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2387
end;
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  2388
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
  2389
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
  2390
var np: LongInt;
13582
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2391
    colorArg: Int64;
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2392
    colorStr: 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
  2393
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2394
    if CheckAndFetchParamCount(L, 5, 6, 'AddTeam', 'teamname, color, grave, fort, voicepack [, flag]', np) 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
  2395
        begin
13582
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2396
        colorArg:= Trunc(lua_tonumber(L, 2));
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2397
        if (colorArg < 0) and (abs(colorArg) <= cClanColors) then
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2398
            // Pick clan color from settings (recommended)
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2399
            colorStr:= IntToStr(ClanColorArray[Pred(abs(colorArg))])
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2400
        else if (colorArg >= 0) and (colorArg <= $ffffffff) then
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2401
            // Specify color directly
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2402
            colorStr:= IntToStr(colorArg)
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2403
        else
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2404
            begin
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2405
            OutError('Lua error: AddTeam: Invalid ''color'' argument, must be between '+IntToStr(-cClanColors)+' and 0xffffffff!', true);
14505
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2406
            lua_pushnil(L);
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2407
            lua_pushnil(L);
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2408
            lc_addteam:= 2;
13582
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2409
            exit;
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2410
            end;
517b26009073 Lua: Allow to use negative value for AddTeam to select a default clan color
Wuzzy <Wuzzy2@mail.ru>
parents: 13577
diff changeset
  2411
        ParseCommand('addteam x ' + colorStr + ' ' + lua_tostring(L, 1), true, true);
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2412
        ParseCommand('grave ' + lua_tostring(L, 3), true, true);
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2413
        ParseCommand('fort ' + lua_tostring(L, 4), true, true);
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2414
        ParseCommand('voicepack ' + lua_tostring(L, 5), true, true);
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2415
        if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true);
14558
ce40351e0690 Use player team's control scheme for all teams if there's a mission team
Wuzzy <Wuzzy2@mail.ru>
parents: 14557
diff changeset
  2416
        // If there's a mission team, copy it's control scheme.
ce40351e0690 Use player team's control scheme for all teams if there's a mission team
Wuzzy <Wuzzy2@mail.ru>
parents: 14557
diff changeset
  2417
        // So in singleplayer missions, all teams use the player team's controls.
ce40351e0690 Use player team's control scheme for all teams if there's a mission team
Wuzzy <Wuzzy2@mail.ru>
parents: 14557
diff changeset
  2418
        if MissionTeam <> nil then
ce40351e0690 Use player team's control scheme for all teams if there's a mission team
Wuzzy <Wuzzy2@mail.ru>
parents: 14557
diff changeset
  2419
            CurrentTeam^.Binds:= MissionTeam^.Binds
ce40351e0690 Use player team's control scheme for all teams if there's a mission team
Wuzzy <Wuzzy2@mail.ru>
parents: 14557
diff changeset
  2420
        // Default keys otherwise
ce40351e0690 Use player team's control scheme for all teams if there's a mission team
Wuzzy <Wuzzy2@mail.ru>
parents: 14557
diff changeset
  2421
        else
ce40351e0690 Use player team's control scheme for all teams if there's a mission team
Wuzzy <Wuzzy2@mail.ru>
parents: 14557
diff changeset
  2422
            CurrentTeam^.Binds:= DefaultBinds;
14505
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2423
        // push team name and index
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2424
        lua_pushstring(L, str2pchar(CurrentTeam^.TeamName));
14500
4e5280a9e782 Lua: AddTeam / AddMissionTeam now return team index
Wuzzy <Wuzzy2@mail.ru>
parents: 14498
diff changeset
  2425
        lua_pushnumber(L, TeamsCount - 1);
4e5280a9e782 Lua: AddTeam / AddMissionTeam now return team index
Wuzzy <Wuzzy2@mail.ru>
parents: 14498
diff changeset
  2426
        end
4e5280a9e782 Lua: AddTeam / AddMissionTeam now return team index
Wuzzy <Wuzzy2@mail.ru>
parents: 14498
diff changeset
  2427
    else
14505
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2428
        begin
14500
4e5280a9e782 Lua: AddTeam / AddMissionTeam now return team index
Wuzzy <Wuzzy2@mail.ru>
parents: 14498
diff changeset
  2429
        lua_pushnil(L);
14505
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2430
        lua_pushnil(L);
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2431
        end;
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2432
    lc_addteam:= 2;
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
  2433
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
  2434
14498
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2435
function lc_addmissionteam(L : Plua_State) : LongInt; Cdecl;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2436
var colorArg: Int64;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2437
    colorStr: shortstring;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2438
begin
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2439
    if CheckLuaParamCount(L, 1, 'AddMissionTeam', 'color') then
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2440
        begin
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2441
        if(MissionTeam = nil) then
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2442
            begin
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2443
            OutError('Lua error: AddMissionTeam: Could not add team. Note: This function only works in singleplayer missions!', true);
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2444
            lc_addmissionteam:= 0;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2445
            exit;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2446
            end;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2447
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2448
        colorArg:= Trunc(lua_tonumber(L, 1));
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2449
        if (colorArg < 0) and (abs(colorArg) <= cClanColors) then
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2450
            // Pick clan color from settings (recommended)
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2451
            colorStr:= IntToStr(ClanColorArray[Pred(abs(colorArg))])
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2452
        else if (colorArg >= 0) and (colorArg <= $ffffffff) then
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2453
            // Specify color directly
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2454
            colorStr:= IntToStr(colorArg)
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2455
        else
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2456
            begin
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2457
            OutError('Lua error: AddMissionTeam: Invalid ''color'' argument, must be between '+IntToStr(-cClanColors)+' and 0xffffffff!', true);
14505
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2458
            lua_pushnil(L);
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2459
            lua_pushnil(L);
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2460
            lc_addmissionteam:= 2;
14498
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2461
            exit;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2462
            end;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2463
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2464
        ParseCommand('addteam x ' + colorStr + ' ' + MissionTeam^.TeamName, true, true);
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2465
        ParseCommand('grave ' + MissionTeam^.GraveName, true, true);
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2466
        ParseCommand('fort ' + MissionTeam^.FortName, true, true);
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2467
        ParseCommand('voicepack ' + MissionTeam^.Voicepack^.name, true, true);
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2468
        ParseCommand('flag ' + MissionTeam^.Flag, true, true);
14557
181509fe1ae8 Fix player team ignoring custom team control scheme in campaign/missions
Wuzzy <Wuzzy2@mail.ru>
parents: 14543
diff changeset
  2469
        CurrentTeam^.Binds:= MissionTeam^.Binds;
14505
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2470
        // push real team name and team index
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2471
        lua_pushstring(L, str2pchar(CurrentTeam^.TeamName));
14500
4e5280a9e782 Lua: AddTeam / AddMissionTeam now return team index
Wuzzy <Wuzzy2@mail.ru>
parents: 14498
diff changeset
  2472
        lua_pushnumber(L, TeamsCount - 1);
4e5280a9e782 Lua: AddTeam / AddMissionTeam now return team index
Wuzzy <Wuzzy2@mail.ru>
parents: 14498
diff changeset
  2473
        end
4e5280a9e782 Lua: AddTeam / AddMissionTeam now return team index
Wuzzy <Wuzzy2@mail.ru>
parents: 14498
diff changeset
  2474
    else
14505
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2475
        begin
14500
4e5280a9e782 Lua: AddTeam / AddMissionTeam now return team index
Wuzzy <Wuzzy2@mail.ru>
parents: 14498
diff changeset
  2476
        lua_pushnil(L);
14505
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2477
        lua_pushnil(L);
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2478
        end;
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14500
diff changeset
  2479
    lc_addmissionteam:= 2;
14498
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2480
end;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2481
13018
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2482
function lc_setteamlabel(L : Plua_State) : LongInt; Cdecl;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2483
var teamValue: ansistring;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2484
    i, n: LongInt;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2485
    success: boolean;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2486
begin
14304
9548edd9ebcf uninitialised values
nemo
parents: 14240
diff changeset
  2487
	success:= false;
13018
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2488
    if CheckAndFetchParamCount(L, 1, 2, 'SetTeamLabel', 'teamname[, label]', n) then
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2489
        begin
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2490
        success:= false;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2491
        // fetch team
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2492
        if TeamsCount > 0 then
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2493
            for i:= 0 to Pred(TeamsCount) do
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2494
                begin
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2495
                // skip teams that don't have matching name
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2496
                if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2497
                    continue;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2498
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2499
                // value of type nil? Then let's clear the team value
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2500
                if (n < 2) or lua_isnil(L, 2) then
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2501
                    begin
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2502
                    FreeAndNilTexture(TeamsArray[i]^.LuaTeamValueTex);
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2503
                    TeamsArray[i]^.hasLuaTeamValue:= false;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2504
                    success:= true;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2505
                    end
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2506
                // value of type string? Then let's set the team value
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2507
                else if (lua_isstring(L, 2)) then
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2508
                    begin
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2509
                    teamValue:= lua_tostring(L, 2);
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2510
                    TeamsArray[i]^.LuaTeamValue:= teamValue;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2511
                    FreeAndNilTexture(TeamsArray[i]^.LuaTeamValueTex);
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2512
                    TeamsArray[i]^.LuaTeamValueTex := RenderStringTex(teamValue, TeamsArray[i]^.Clan^.Color, fnt16);
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2513
                    TeamsArray[i]^.hasLuaTeamValue:= true;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2514
                    success:= true;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2515
                    end;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2516
                // don't change more than one team
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2517
                break;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2518
                end;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2519
        end;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2520
    // return true if operation was successful, false otherwise
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2521
    lua_pushboolean(L, success);
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2522
    lc_setteamlabel:= 1;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2523
end;
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  2524
14632
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2525
function lc_setteampassive(L : Plua_State) : LongInt; Cdecl;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2526
var i, j: LongInt;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2527
    success, passive, passiveClan: boolean;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2528
begin
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2529
	success:= false;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2530
    if CheckLuaParamCount(L, 2, 'SetTeamPassive', 'teamname, isPassive') then
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2531
        begin
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2532
        success:= false;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2533
        // fetch team
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2534
        if TeamsCount > 0 then
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2535
            for i:= 0 to Pred(TeamsCount) do
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2536
                if TeamsArray[i]^.TeamName = lua_tostring(L, 1) then
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2537
                    begin
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2538
                    passive:= lua_toboolean(L, 2);
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2539
                    TeamsArray[i]^.Passive:= passive;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2540
                    // also update clan state
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2541
                    if passive then
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2542
                        begin
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2543
                        passiveClan:= true;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2544
                        for j:= 0 to Pred(TeamsCount) do
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2545
                            if (not TeamsArray[j]^.Passive) then
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2546
                                begin
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2547
                                passiveClan:= false;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2548
                                break;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2549
                                end;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2550
                        end
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2551
                    else
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2552
                        passiveClan:= false;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2553
                    TeamsArray[i]^.Clan^.Passive:= passiveClan;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2554
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2555
                    success:= true;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2556
                    // don't change more than one team
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2557
                    break;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2558
                    end;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2559
        end;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2560
    // return true if operation was successful, false otherwise
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2561
    lua_pushboolean(L, success);
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2562
    lc_setteampassive:= 1;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2563
end;
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  2564
12931
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2565
function lc_getteamname(L : Plua_State) : LongInt; Cdecl;
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2566
var t: LongInt;
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2567
begin
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2568
    if CheckLuaParamCount(L, 1, 'GetTeamName', 'teamIdx') then
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2569
        begin
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2570
        t:= Trunc(lua_tonumber(L, 1));
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2571
        if (t < 0) or (t >= TeamsCount) then
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2572
            lua_pushnil(L)
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2573
        else
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2574
            lua_pushstring(L, str2pchar(TeamsArray[t]^.TeamName));
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2575
        end
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2576
    else
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2577
        lua_pushnil(L);
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2578
    lc_getteamname:= 1;
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2579
end;
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  2580
13020
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2581
function lc_getteamindex(L : Plua_state) : LongInt; Cdecl;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2582
var i: LongInt;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2583
    found: boolean;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2584
begin
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2585
    found:= false;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2586
    if CheckLuaParamCount(L, 1, 'GetTeamIndex', 'teamname') then
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2587
        if TeamsCount > 0 then
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2588
            for i:= 0 to Pred(TeamsCount) do
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2589
                begin
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2590
                // skip teams that don't have matching name
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2591
                if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2592
                    continue;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2593
                lua_pushnumber(L, i);
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2594
                found:= true;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2595
                break;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2596
                end;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2597
    if (not found) then
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2598
        lua_pushnil(L);
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2599
    lc_getteamindex:= 1;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2600
end;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2601
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2602
function lc_getteamclan(L : Plua_state) : LongInt; Cdecl;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2603
var i: LongInt;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2604
    found: boolean;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2605
begin
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2606
    found:= false;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2607
    if CheckLuaParamCount(L, 1, 'GetTeamClan', 'teamname') then
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2608
        if TeamsCount > 0 then
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2609
            for i:= 0 to Pred(TeamsCount) do
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2610
                begin
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2611
                // skip teams that don't have matching name
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2612
                if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2613
                    continue;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2614
                lua_pushnumber(L, TeamsArray[i]^.Clan^.ClanIndex);
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2615
                found:= true;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2616
                break;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2617
                end;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2618
    if (not found) then
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2619
        lua_pushnil(L);
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2620
    lc_getteamclan:= 1;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2621
end;
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  2622
10290
42efccba0711 lua api: DismissTeam(teamname)
sheepluva
parents: 10289
diff changeset
  2623
function lc_dismissteam(L : Plua_State) : LongInt; Cdecl;
10553
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2624
var HHGear: PGear;
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2625
    i, h  : LongInt;
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2626
    hidden: boolean;
10290
42efccba0711 lua api: DismissTeam(teamname)
sheepluva
parents: 10289
diff changeset
  2627
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2628
    if CheckLuaParamCount(L, 1, 'DismissTeam', 'teamname') then
10553
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2629
        begin
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2630
        if TeamsCount > 0 then
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2631
            for i:= 0 to Pred(TeamsCount) do
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2632
                begin
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2633
                // skip teams that don't have matching name
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2634
                if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2635
                    continue;
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2636
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2637
                // destroy all hogs of matching team, including the hidden ones
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2638
                for h:= 0 to cMaxHHIndex do
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2639
                    begin
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2640
                    hidden:= (TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil);
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2641
                    if hidden then
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2642
                        RestoreHog(@TeamsArray[i]^.Hedgehogs[h]);
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2643
                    // destroy hedgehog gear, if any
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2644
                    HHGear:= TeamsArray[i]^.Hedgehogs[h].Gear;
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2645
                    if HHGear <> nil then
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2646
                        begin
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2647
                        // smoke effect
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2648
                        if (not hidden) then
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2649
                            begin
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2650
                            AddVisualGear(hwRound(HHGear^.X), hwRound(HHGear^.Y), vgtSmokeWhite);
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2651
                            AddVisualGear(hwRound(HHGear^.X) - 16 + Random(32), hwRound(HHGear^.Y) - 16 + Random(32), vgtSmokeWhite);
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2652
                            AddVisualGear(hwRound(HHGear^.X) - 16 + Random(32), hwRound(HHGear^.Y) - 16 + Random(32), vgtSmokeWhite);
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2653
                            AddVisualGear(hwRound(HHGear^.X) - 16 + Random(32), hwRound(HHGear^.Y) - 16 + Random(32), vgtSmokeWhite);
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2654
                            AddVisualGear(hwRound(HHGear^.X) - 16 + Random(32), hwRound(HHGear^.Y) - 16 + Random(32), vgtSmokeWhite);
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2655
                            end;
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2656
                        HHGear^.Message:= HHGear^.Message or gmDestroy;
14639
7c5a9c1b9d4e Fix DismissTeam not clearing the team properly
Wuzzy <Wuzzy2@mail.ru>
parents: 14632
diff changeset
  2657
                        HHGear^.Active:= true;
7c5a9c1b9d4e Fix DismissTeam not clearing the team properly
Wuzzy <Wuzzy2@mail.ru>
parents: 14632
diff changeset
  2658
                        AllInactive:= false;
10553
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2659
                        end;
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2660
                    end;
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2661
                // can't dismiss more than one team
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2662
                break;
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2663
                end;
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2664
        end;
67c6de2a0213 new implementation for Lua API DismissTeam. all hedgehogs of the team are now removed without using teamgone
sheepluva
parents: 10542
diff changeset
  2665
    lc_dismissteam:= 0;
10290
42efccba0711 lua api: DismissTeam(teamname)
sheepluva
parents: 10289
diff changeset
  2666
end;
42efccba0711 lua api: DismissTeam(teamname)
sheepluva
parents: 10289
diff changeset
  2667
12536
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2668
function lc_getteamstats(L : Plua_State) : LongInt; Cdecl;
12621
d972b31f8881 fix some fpc hints
sheepluva
parents: 12600
diff changeset
  2669
var i: LongInt;
12536
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2670
begin
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2671
    if CheckLuaParamCount(L, 1, 'GetTeamStats', 'teamname') then
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2672
        begin
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2673
        if TeamsCount > 0 then
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2674
            for i:= 0 to Pred(TeamsCount) do
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2675
                begin
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2676
                // skip teams that don't have matching name
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2677
                if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2678
                    continue;
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2679
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2680
                lua_newtable(L);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2681
12600
ef780eda6e48 pas2c happiness initiative 2017, continued
sheepluva
parents: 12596
diff changeset
  2682
                lua_pushstring(L, str2pchar('Kills'));
12536
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2683
                lua_pushnumber(L, TeamsArray[i]^.stats.Kills);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2684
                lua_settable(L, -3);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2685
12600
ef780eda6e48 pas2c happiness initiative 2017, continued
sheepluva
parents: 12596
diff changeset
  2686
                lua_pushstring(L, str2pchar('Suicides'));
12536
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2687
                lua_pushnumber(L, TeamsArray[i]^.stats.Suicides);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2688
                lua_settable(L, -3);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2689
12600
ef780eda6e48 pas2c happiness initiative 2017, continued
sheepluva
parents: 12596
diff changeset
  2690
                lua_pushstring(L, str2pchar('AIKills'));
12536
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2691
                lua_pushnumber(L, TeamsArray[i]^.stats.AIKills);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2692
                lua_settable(L, -3);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2693
12600
ef780eda6e48 pas2c happiness initiative 2017, continued
sheepluva
parents: 12596
diff changeset
  2694
                lua_pushstring(L, str2pchar('TeamKills'));
12536
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2695
                lua_pushnumber(L, TeamsArray[i]^.stats.TeamKills);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2696
                lua_settable(L, -3);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2697
12600
ef780eda6e48 pas2c happiness initiative 2017, continued
sheepluva
parents: 12596
diff changeset
  2698
                lua_pushstring(L, str2pchar('TurnSkips'));
12536
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2699
                lua_pushnumber(L, TeamsArray[i]^.stats.TurnSkips);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2700
                lua_settable(L, -3);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2701
12600
ef780eda6e48 pas2c happiness initiative 2017, continued
sheepluva
parents: 12596
diff changeset
  2702
                lua_pushstring(L, str2pchar('TeamDamage'));
12536
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2703
                lua_pushnumber(L, TeamsArray[i]^.stats.TeamDamage);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2704
                lua_settable(L, -3);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2705
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2706
                end;
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2707
        end
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2708
    else
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2709
        lua_pushnil(L);
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2710
    lc_getteamstats:= 1;
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2711
end;
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2712
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2713
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  2714
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
  2715
function lc_addhog(L : Plua_State) : LongInt; Cdecl;
14498
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2716
var hatName: 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
  2717
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2718
    if CheckLuaParamCount(L, 4, 'AddHog', 'hogname, botlevel, health, hat') 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
  2719
        begin
14498
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2720
        hatName:= lua_tostring(L, 4);
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  2721
        ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
14498
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2722
        ParseCommand('hat ' + hatName, true, true);
15038
d610d1c9fd55 Add error messages when calling AddHog or AddMissionHog wrongly
Wuzzy <Wuzzy2@mail.ru>
parents: 14948
diff changeset
  2723
        if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then
d610d1c9fd55 Add error messages when calling AddHog or AddMissionHog wrongly
Wuzzy <Wuzzy2@mail.ru>
parents: 14948
diff changeset
  2724
            lua_pushnumber(L, CurrentHedgehog^.Gear^.uid)
d610d1c9fd55 Add error messages when calling AddHog or AddMissionHog wrongly
Wuzzy <Wuzzy2@mail.ru>
parents: 14948
diff changeset
  2725
        else
d610d1c9fd55 Add error messages when calling AddHog or AddMissionHog wrongly
Wuzzy <Wuzzy2@mail.ru>
parents: 14948
diff changeset
  2726
            OutError('Lua error: AddHog: Error adding hog. Maybe function was called outside of onGameInit.', true);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2727
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2728
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2729
        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
  2730
    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
  2731
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
  2732
14498
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2733
function lc_addmissionhog(L : Plua_State) : LongInt; Cdecl;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2734
var hatName: ShortString;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2735
begin
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2736
    if CheckLuaParamCount(L, 1, 'AddMissionHog', 'health') then
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2737
        begin
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2738
        if(MissionTeam = nil) then
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2739
            begin
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2740
            OutError('Lua error: AddMissionHog: Could not add hog. Mission team is not set!', true);
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2741
            lua_pushnil(L);
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2742
            lc_addmissionhog:= 1;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2743
            exit;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2744
            end;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2745
        with MissionTeam^.Hedgehogs[CurrentTeam^.HedgehogsNumber] do
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2746
            begin
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2747
            hatName:= Hat;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2748
            ParseCommand('addhh ' + IntToStr(BotLevel) + ' ' + lua_tostring(L, 1) + ' ' + Name, true, true);
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2749
            ParseCommand('hat ' + hatName, true, true);
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2750
            end;
15038
d610d1c9fd55 Add error messages when calling AddHog or AddMissionHog wrongly
Wuzzy <Wuzzy2@mail.ru>
parents: 14948
diff changeset
  2751
        if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then
d610d1c9fd55 Add error messages when calling AddHog or AddMissionHog wrongly
Wuzzy <Wuzzy2@mail.ru>
parents: 14948
diff changeset
  2752
            lua_pushnumber(L, CurrentHedgehog^.Gear^.uid)
d610d1c9fd55 Add error messages when calling AddHog or AddMissionHog wrongly
Wuzzy <Wuzzy2@mail.ru>
parents: 14948
diff changeset
  2753
        else
d610d1c9fd55 Add error messages when calling AddHog or AddMissionHog wrongly
Wuzzy <Wuzzy2@mail.ru>
parents: 14948
diff changeset
  2754
            OutError('Lua error: AddMissionHog: Error adding hog. Maybe function was called outside of onGameInit.', true);
14498
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2755
        end
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2756
    else
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2757
        lua_pushnil(L);
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2758
    lc_addmissionhog:= 1;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2759
end;
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  2760
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2761
function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2762
var gear: PGear;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2763
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2764
    if CheckLuaParamCount(L, 2, 'HogTurnLeft', 'gearUid, boolean') then
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2765
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2766
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2767
        if gear <> nil then
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2768
            gear^.dX.isNegative:= lua_toboolean(L, 2);
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2769
        end;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2770
    lc_hogturnleft:= 0;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2771
end;
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  2772
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
  2773
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
  2774
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
  2775
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2776
    if CheckLuaParamCount(L, 1, 'GetGearPosition', 'gearUid') 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
  2777
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2778
        gear:= GearByUID(Trunc(lua_tonumber(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
  2779
        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
  2780
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2781
            lua_pushnumber(L, hwRound(gear^.X));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2782
            lua_pushnumber(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
  2783
            end
5964
44d2dc3b438f return nil for position if no gear
nemo
parents: 5900
diff changeset
  2784
        else
44d2dc3b438f return nil for position if no gear
nemo
parents: 5900
diff changeset
  2785
            begin
44d2dc3b438f return nil for position if no gear
nemo
parents: 5900
diff changeset
  2786
            lua_pushnil(L);
44d2dc3b438f return nil for position if no gear
nemo
parents: 5900
diff changeset
  2787
            lua_pushnil(L)
44d2dc3b438f return nil for position if no gear
nemo
parents: 5900
diff changeset
  2788
            end;
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2789
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2790
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2791
        begin
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2792
        lua_pushnil(L);
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2793
        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
  2794
        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
  2795
    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
  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
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
  2799
var gear: PGear;
4832
e55e2b6f59b0 update collision in set gear position
nemo
parents: 4780
diff changeset
  2800
    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
  2801
    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
  2802
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2803
    if CheckLuaParamCount(L, 3, 'SetGearPosition', 'gearUid, x, y') 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
  2804
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2805
        gear:= GearByUID(Trunc(lua_tonumber(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
  2806
        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
  2807
            begin
4832
e55e2b6f59b0 update collision in set gear position
nemo
parents: 4780
diff changeset
  2808
            col:= gear^.CollisionIndex >= 0;
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2809
            x:= Trunc(lua_tonumber(L, 2));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2810
            y:= Trunc(lua_tonumber(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
  2811
            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
  2812
                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
  2813
            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
  2814
            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
  2815
            if col then
9291
15f7bb217b66 Make add/delete consistent (this has bugged me for so long)
nemo
parents: 9285
diff changeset
  2816
                AddCI(gear);
4832
e55e2b6f59b0 update collision in set gear position
nemo
parents: 4780
diff changeset
  2817
            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
  2818
            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
  2819
        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
  2820
    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
  2821
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
  2822
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2823
function lc_getgeartarget(L : Plua_State) : LongInt; Cdecl;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2824
var gear: PGear;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2825
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2826
    if CheckLuaParamCount(L, 1, 'GetGearTarget', 'gearUid') then
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2827
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2828
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2829
        if gear <> nil then
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2830
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2831
            lua_pushnumber(L, gear^.Target.X);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2832
            lua_pushnumber(L, gear^.Target.Y)
5612
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  2833
            end
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  2834
        else
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  2835
            begin
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  2836
            lua_pushnil(L);
2638dec1b323 This really should have been a TPoint for consistency
nemo
parents: 5583
diff changeset
  2837
            lua_pushnil(L)
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2838
            end
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2839
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2840
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2841
        begin
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2842
        lua_pushnil(L);
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2843
        lua_pushnil(L)
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2844
        end;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2845
    lc_getgeartarget:= 2;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2846
end;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2847
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2848
function lc_setgeartarget(L : Plua_State) : LongInt; Cdecl;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2849
var gear: PGear;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2850
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2851
    if CheckLuaParamCount(L, 3, 'SetGearTarget', 'gearUid, x, y') then
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2852
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2853
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2854
        if gear <> nil then
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2855
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2856
            gear^.Target.X:= Trunc(lua_tonumber(L, 2));
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2857
            gear^.Target.Y:= Trunc(lua_tonumber(L, 3))
5517
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2858
            end
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2859
        end;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2860
    lc_setgeartarget:= 0
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2861
end;
80bc6c0be5d4 Expose TargetX/TargetY to scripting
nemo
parents: 5489
diff changeset
  2862
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
  2863
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
  2864
var gear: PGear;
6780
166ee5275915 tweak take 2
nemo
parents: 6779
diff changeset
  2865
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
  2866
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2867
    if CheckLuaParamCount(L, 1, 'GetGearVelocity', 'gearUid') then
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
  2868
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2869
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
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
  2870
        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
  2871
            begin
6780
166ee5275915 tweak take 2
nemo
parents: 6779
diff changeset
  2872
            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
  2873
            // gear dX determines hog orientation
6780
166ee5275915 tweak take 2
nemo
parents: 6779
diff changeset
  2874
            if (gear^.dX.isNegative) and (t = 0) then t:= -1;
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2875
            lua_pushnumber(L, t);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2876
            lua_pushnumber(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
  2877
            end
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2878
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2879
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2880
        begin
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2881
        lua_pushnil(L);
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2882
        lua_pushnil(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
  2883
        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
  2884
    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
  2885
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
  2886
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
  2887
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
  2888
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
  2889
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2890
    if CheckLuaParamCount(L, 3, 'SetGearVelocity', 'gearUid, dx, dy') then
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
  2891
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2892
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
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
  2893
        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
  2894
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2895
            gear^.dX:= int2hwFloat(Trunc(lua_tonumber(L, 2))) / 1000000;
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2896
            gear^.dY:= int2hwFloat(Trunc(lua_tonumber(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
  2897
            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
  2898
            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
  2899
        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
  2900
    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
  2901
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
  2902
3736
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2903
function lc_setzoom(L : Plua_State) : LongInt; Cdecl;
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2904
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2905
    if CheckLuaParamCount(L, 1, 'SetZoom', 'zoomLevel') then
3736
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2906
        begin
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2907
        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
  2908
        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
  2909
            ZoomValue:= cMaxZoomLevel;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  2910
        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
  2911
            ZoomValue:= cMinZoomLevel;
3736
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2912
        end;
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2913
    lc_setzoom:= 0
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2914
end;
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2915
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2916
function lc_getzoom(L : Plua_State) : LongInt; Cdecl;
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2917
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  2918
    if CheckLuaParamCount(L, 0, 'GetZoom', '') then
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2919
        lua_pushnumber(L, ZoomValue)
3736
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2920
    else
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  2921
        lua_pushnil(L);
3736
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2922
    lc_getzoom:= 1
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2923
end;
d8982f9e7e2c Engine:
smaxx
parents: 3734
diff changeset
  2924
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
  2925
function lc_setammo(L : Plua_State) : LongInt; Cdecl;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2926
var np, at: LongInt;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2927
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2928
    callStr = 'SetAmmo';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2929
    paramsStr = 'ammoType, count, probability, delay [, numberInCrate]';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2930
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2931
    if CheckAndFetchParamCount(L, 4, 5, callStr, paramsStr, np) then
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2932
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2933
        at:= LuaToAmmoTypeOrd(L, 1, callStr, paramsStr);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2934
        if at >= 0 then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2935
            begin
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2936
            if np = 4 then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2937
                ScriptSetAmmo(TAmmoType(at), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(L, 4)), 1)
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2938
            else
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  2939
                ScriptSetAmmo(TAmmoType(at), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), Trunc(lua_tonumber(L, 4)), Trunc(lua_tonumber(L, 5)));
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2940
            end;
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2941
        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
  2942
    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
  2943
end;
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  2944
13456
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2945
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2946
function lc_getammo(L : Plua_State) : LongInt; Cdecl;
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2947
var i, at, rawProb, probLevel: LongInt;
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2948
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2949
    callStr = 'GetAmmo';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2950
    paramsStr = 'ammoType';
13456
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2951
begin
14309
21e719e35f43 Fix build
unc0rr
parents: 14305
diff changeset
  2952
    lc_getammo:= 0;
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2953
    if CheckLuaParamCount(L, 1, callStr, paramsStr) then
13456
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2954
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2955
        at:= LuaToAmmoTypeOrd(L, 1, callStr, paramsStr);
13456
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2956
        if at >= 0 then
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2957
            begin
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2958
            // Ammo count
13457
38814954a248 Fix GetAmmo getting wrong ammo count
Wuzzy <Wuzzy2@mail.ru>
parents: 13456
diff changeset
  2959
            i:= InitialAmmoCounts[TAmmoType(at)];
13456
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2960
            if i = AMMO_INFINITE then
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2961
                i:= 9;
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2962
            lua_pushnumber(L, i);
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2963
            // Probability
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2964
            rawProb:=  Ammoz[TAmmoType(at)].Probability;
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2965
            probLevel:= -1;
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2966
            for i := 0 to High(probabilityLevels) do
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2967
                if rawProb = probabilityLevels[i] then
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2968
                    probLevel:= i;
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2969
            lua_pushnumber(L, probLevel);
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2970
            // Delay in turns
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2971
            lua_pushnumber(L, Ammoz[TAmmoType(at)].SkipTurns);
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2972
            // Number in case
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2973
            lua_pushnumber(L, Ammoz[TAmmoType(at)].NumberInCase);
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2974
            lc_getammo:= 4
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2975
            end
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2976
        end;
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2977
end;
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2978
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  2979
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
  2980
function lc_setammodelay(L : Plua_State) : LongInt; Cdecl;
14661
e6363b84b3fe SetAmmoDelay: Unselect weapon if neccessary
Wuzzy <Wuzzy2@mail.ru>
parents: 14640
diff changeset
  2981
var at, delay: LongInt;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2982
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2983
    callStr = 'SetAmmoDelay';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2984
    paramsStr = 'ammoType, delay';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2985
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2986
    if CheckLuaParamCount(L, 2, callStr, paramsStr) then
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2987
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  2988
        at:= LuaToAmmoTypeOrd(L, 1, callStr, paramsStr);
14661
e6363b84b3fe SetAmmoDelay: Unselect weapon if neccessary
Wuzzy <Wuzzy2@mail.ru>
parents: 14640
diff changeset
  2989
        delay:= Trunc(lua_tonumber(L, 2));
e6363b84b3fe SetAmmoDelay: Unselect weapon if neccessary
Wuzzy <Wuzzy2@mail.ru>
parents: 14640
diff changeset
  2990
        if (at >= 0) and (TAmmoType(at) <> amNothing) then
e6363b84b3fe SetAmmoDelay: Unselect weapon if neccessary
Wuzzy <Wuzzy2@mail.ru>
parents: 14640
diff changeset
  2991
            begin
e6363b84b3fe SetAmmoDelay: Unselect weapon if neccessary
Wuzzy <Wuzzy2@mail.ru>
parents: 14640
diff changeset
  2992
            ScriptSetAmmoDelay(TAmmoType(at), delay);
e6363b84b3fe SetAmmoDelay: Unselect weapon if neccessary
Wuzzy <Wuzzy2@mail.ru>
parents: 14640
diff changeset
  2993
            // Unselect weapon if neccessary
e6363b84b3fe SetAmmoDelay: Unselect weapon if neccessary
Wuzzy <Wuzzy2@mail.ru>
parents: 14640
diff changeset
  2994
            if (delay > 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.CurAmmoType = TAmmoType(at)) then
e6363b84b3fe SetAmmoDelay: Unselect weapon if neccessary
Wuzzy <Wuzzy2@mail.ru>
parents: 14640
diff changeset
  2995
                ParseCommand('setweap ' + char(0), true, true);
e6363b84b3fe SetAmmoDelay: Unselect weapon if neccessary
Wuzzy <Wuzzy2@mail.ru>
parents: 14640
diff changeset
  2996
            end;
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  2997
        end;
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
  2998
    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
  2999
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
  3000
15152
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3001
function lc_setammoslot(L : Plua_State) : LongInt; Cdecl;
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3002
var at, slot: LongInt;
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3003
begin
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3004
    if CheckLuaParamCount(L, 2, 'SetAmmoSlot', 'ammoType, slot') then
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3005
        begin
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3006
        at:= Trunc(lua_tonumber(L, 1));
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3007
        slot:= Trunc(lua_tonumber(L, 2));
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3008
        Ammoz[TAmmoType(at)].Slot:= slot - 1;
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3009
        AmmoMenuInvalidated:= true;
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3010
        end;
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3011
    lc_setammoslot:= 0;
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3012
end;
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  3013
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3014
function lc_getrandom(L : Plua_State) : LongInt; Cdecl;
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3015
var m : LongInt;
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3016
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3017
    if CheckLuaParamCount(L, 1, 'GetRandom', 'number') then
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3018
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3019
        m:= Trunc(lua_tonumber(L, 1));
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3020
        if (m > 0) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3021
            lua_pushnumber(L, GetRandom(m))
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3022
        else
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3023
            begin
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3024
            LuaError('Lua: Tried to pass 0 to GetRandom!');
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3025
            lua_pushnil(L);
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3026
            end
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3027
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3028
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3029
        lua_pushnil(L); // return value on stack (nil)
4243
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3030
    lc_getrandom:= 1
bbf7451f6b4e added getrandom and addcaption to lua
Henek
parents: 4236
diff changeset
  3031
end;
4399
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  3032
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  3033
function lc_setwind(L : Plua_State) : LongInt; Cdecl;
13062
bcb87269867e Lua API: Fix SetWind not updating flake direction
Wuzzy <Wuzzy2@mail.ru>
parents: 13038
diff changeset
  3034
var vg: PVisualGear;
4399
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  3035
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3036
    if CheckLuaParamCount(L, 1, 'SetWind', 'windSpeed') then
4399
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  3037
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3038
        cWindSpeed:= int2hwfloat(Trunc(lua_tonumber(L, 1))) / 100 * cMaxWindSpeed;
4399
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  3039
        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
  3040
        if cWindSpeed.isNegative then
13062
bcb87269867e Lua API: Fix SetWind not updating flake direction
Wuzzy <Wuzzy2@mail.ru>
parents: 13038
diff changeset
  3041
            cWindSpeedf := -cWindSpeedf;
bcb87269867e Lua API: Fix SetWind not updating flake direction
Wuzzy <Wuzzy2@mail.ru>
parents: 13038
diff changeset
  3042
        vg:= AddVisualGear(0, 0, vgtSmoothWindBar);
bcb87269867e Lua API: Fix SetWind not updating flake direction
Wuzzy <Wuzzy2@mail.ru>
parents: 13038
diff changeset
  3043
        if vg <> nil then vg^.dAngle:= hwFloat2Float(cWindSpeed);
14240
de21f6eb2366 Fix desync bomb
unc0rr
parents: 14238
diff changeset
  3044
            AddFileLog('Script set wind = '+FloatToStr(cWindSpeed));
4399
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  3045
        end;
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  3046
    lc_setwind:= 0
87bc4a9e6ef0 fix key binds for lua created teams and added wind control
Henek
parents: 4393
diff changeset
  3047
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
  3048
12930
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3049
function lc_getwind(L : Plua_State) : LongInt; Cdecl;
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3050
var wind: extended;
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3051
begin
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3052
    if CheckLuaParamCount(L, 0, 'GetWind', '') then
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3053
        begin
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3054
        wind:= hwFloat2float((cWindSpeed / cMaxWindSpeed) * 100);
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3055
        if wind < -100 then
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3056
            wind:= -100
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3057
        else if wind > 100 then
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3058
            wind:= 100;
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3059
        lua_pushnumber(L, wind);
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3060
        end
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3061
    else
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3062
        lua_pushnil(L);
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3063
    lc_getwind:= 1
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3064
end;
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  3065
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  3066
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
  3067
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3068
    if CheckLuaParamCount(L, 0, 'MapHasBorder', '') then
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3069
        lua_pushboolean(L, hasBorder)
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3070
    else
4590
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  3071
        lua_pushnil(L);
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  3072
    lc_maphasborder:= 1
d9fed5a816e9 added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
Henek
parents: 4546
diff changeset
  3073
end;
4869
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  3074
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  3075
function lc_getgearradius(L : Plua_State) : LongInt; Cdecl;
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  3076
var gear : PGear;
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  3077
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3078
    if CheckLuaParamCount(L, 1, 'GetGearRadius', 'gearUid') then
4869
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  3079
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3080
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
4869
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  3081
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3082
            lua_pushnumber(L, gear^.Radius)
4869
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  3083
        else
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  3084
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3085
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3086
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3087
        lua_pushnil(L); // return value on stack (nil)
4869
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  3088
    lc_getgearradius:= 1
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4851
diff changeset
  3089
end;
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3090
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3091
function lc_gethoghat(L : Plua_State): LongInt; Cdecl;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3092
var gear : PGear;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3093
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3094
    if CheckLuaParamCount(L, 1, 'GetHogHat', 'gearUid') then
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3095
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3096
        gear := GearByUID(Trunc(lua_tonumber(L, 1)));
8228
8cc5dc7f7ef9 kinda treat graves like hedgehogs for the purpose of looking up hog info
nemo
parents: 8145
diff changeset
  3097
        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
  3098
            lua_pushstring(L, str2pchar(gear^.Hedgehog^.Hat))
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3099
        else
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3100
            lua_pushnil(L);
10287
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3101
        end
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3102
    else
e17fe8572478 more of the same
sheepluva
parents: 10286
diff changeset
  3103
        lua_pushnil(L);
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3104
    lc_gethoghat := 1;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3105
end;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3106
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3107
function lc_sethoghat(L : Plua_State) : LongInt; Cdecl;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3108
var gear : PGear;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3109
    hat: ShortString;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3110
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3111
    if CheckLuaParamCount(L, 2, 'SetHogHat', 'gearUid, hat') then
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3112
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3113
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3114
        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
  3115
            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
  3116
            hat:= lua_tostring(L, 2);
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3117
            gear^.Hedgehog^.Hat:= hat;
9748
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
  3118
            AddFileLog('Changed hat to: '+hat);
7887
e987dff8e5f2 fix reserved hats from scripting
nemo
parents: 7805
diff changeset
  3119
            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
  3120
                LoadHedgehogHat(gear^.Hedgehog^, 'Reserved/' + Copy(hat,9,Length(hat)-8))
e987dff8e5f2 fix reserved hats from scripting
nemo
parents: 7805
diff changeset
  3121
            else
9748
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
  3122
                LoadHedgehogHat(gear^.Hedgehog^, hat)
b0286b0c91ce sethogname/hat need to wrap entire operation around test of hog/gear
nemo
parents: 9718
diff changeset
  3123
            end
4875
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3124
        end;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3125
    lc_sethoghat:= 0;
2a37a0e0892d lua: getter and setter for hedgehog hats
sheepluva
parents: 4869
diff changeset
  3126
end;
4985
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  3127
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3128
function lc_placesprite(L : Plua_State) : LongInt; Cdecl;
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3129
var spr   : TSprite;
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3130
    lf    : Word;
10897
8ea636ce120a Add options to set colouring, behind existing land, and horizontal/vertical flipping to PlaceSprite
nemo
parents: 10818
diff changeset
  3131
    tint  : LongWord;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
  3132
    i, n : LongInt;
10897
8ea636ce120a Add options to set colouring, behind existing land, and horizontal/vertical flipping to PlaceSprite
nemo
parents: 10818
diff changeset
  3133
    placed, behind, flipHoriz, flipVert : boolean;
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3134
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3135
    callStr = 'PlaceSprite';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3136
    paramsStr = 'x, y, sprite, frameIdx, tint, behind, flipHoriz, flipVert [, landFlag, ... ]';
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3137
begin
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3138
    placed:= false;
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3139
    if CheckAndFetchLuaParamMinCount(L, 4, callStr, paramsStr, n) then
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3140
        begin
10897
8ea636ce120a Add options to set colouring, behind existing land, and horizontal/vertical flipping to PlaceSprite
nemo
parents: 10818
diff changeset
  3141
        if not lua_isnoneornil(L, 5) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3142
            tint := Trunc(lua_tonumber(L, 5))
10897
8ea636ce120a Add options to set colouring, behind existing land, and horizontal/vertical flipping to PlaceSprite
nemo
parents: 10818
diff changeset
  3143
        else tint := $FFFFFFFF;
8ea636ce120a Add options to set colouring, behind existing land, and horizontal/vertical flipping to PlaceSprite
nemo
parents: 10818
diff changeset
  3144
        if not lua_isnoneornil(L, 6) then
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  3145
            behind := lua_toboolean(L, 6)
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3146
        else behind := false;
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3147
        if not lua_isnoneornil(L, 7) then
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  3148
            flipHoriz := lua_toboolean(L, 7)
10897
8ea636ce120a Add options to set colouring, behind existing land, and horizontal/vertical flipping to PlaceSprite
nemo
parents: 10818
diff changeset
  3149
        else flipHoriz := false;
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3150
        if not lua_isnoneornil(L, 8) then
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  3151
            flipVert := lua_toboolean(L, 8)
10897
8ea636ce120a Add options to set colouring, behind existing land, and horizontal/vertical flipping to PlaceSprite
nemo
parents: 10818
diff changeset
  3152
        else flipVert := false;
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
  3153
        lf:= 0;
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
  3154
11061
2f1efb11ddf3 Lua API: expose MapFeatureSize during init
sheepluva
parents: 11060
diff changeset
  3155
        // accept any amount of landflags, loop is never executed if n<9
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3156
        for i:= 9 to n do
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3157
            lf:= lf or Trunc(lua_tonumber(L, i));
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3158
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3159
        n:= LuaToSpriteOrd(L, 3, callStr, paramsStr);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  3160
        if n >= 0 then
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  3161
            begin
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3162
            spr:= TSprite(n);
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3163
            if SpritesData[spr].Surface = nil then
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3164
                LuaError(callStr + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3165
            else
10368
7ebb71a36e95 Forced sprites placing mode, exposed to scripts (not tested at all)
unc0rr
parents: 10347
diff changeset
  3166
                placed:= ForcePlaceOnLand(
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3167
                    Trunc(lua_tonumber(L, 1)) - SpritesData[spr].Width div 2,
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3168
                    Trunc(lua_tonumber(L, 2)) - SpritesData[spr].Height div 2,
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3169
                    spr, Trunc(lua_tonumber(L, 4)), lf, tint, behind, flipHoriz, flipVert);
10281
dedc8f23e35e make enums crash-safe. and other fixes
sheepluva
parents: 10280
diff changeset
  3170
            end;
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3171
        end;
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3172
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3173
    lua_pushboolean(L, placed);
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3174
    lc_placesprite:= 1
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3175
end;
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3176
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3177
function lc_erasesprite(L : Plua_State) : LongInt; Cdecl;
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3178
var spr   : TSprite;
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3179
    lf    : Word;
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3180
    i, n : LongInt;
10903
c9a0cdee4267 tweak erase
nemo
parents: 10901
diff changeset
  3181
    eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert : boolean;
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3182
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3183
    callStr = 'EraseSprite';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3184
    paramsStr = 'x, y, sprite, frameIdx, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert [, landFlag, ... ]';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3185
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3186
    if CheckAndFetchLuaParamMinCount(L, 4, callStr, paramsStr, n) then
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3187
        begin
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3188
        if not lua_isnoneornil(L, 5) then
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  3189
            eraseOnLFMatch := lua_toboolean(L, 5)
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3190
        else eraseOnLFMatch := false;
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3191
        if not lua_isnoneornil(L, 6) then
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  3192
            onlyEraseLF := lua_toboolean(L, 6)
10903
c9a0cdee4267 tweak erase
nemo
parents: 10901
diff changeset
  3193
        else onlyEraseLF := false;
c9a0cdee4267 tweak erase
nemo
parents: 10901
diff changeset
  3194
        if not lua_isnoneornil(L, 7) then
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  3195
            flipHoriz := lua_toboolean(L, 7)
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3196
        else flipHoriz := false;
10903
c9a0cdee4267 tweak erase
nemo
parents: 10901
diff changeset
  3197
        if not lua_isnoneornil(L, 8) then
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  3198
            flipVert := lua_toboolean(L, 8)
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3199
        else flipVert := false;
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3200
        lf:= 0;
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3201
11060
506b6184f4af fix on-code documentation of EraseSprite
sheepluva
parents: 11058
diff changeset
  3202
        // accept any amount of landflags, loop is never executed if n<9
10903
c9a0cdee4267 tweak erase
nemo
parents: 10901
diff changeset
  3203
        for i:= 9 to n do
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3204
            lf:= lf or Trunc(lua_tonumber(L, i));
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3205
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3206
        n:= LuaToSpriteOrd(L, 3, callStr, paramsStr);
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3207
        if n >= 0 then
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3208
            begin
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3209
            spr:= TSprite(n);
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3210
            if SpritesData[spr].Surface = nil then
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3211
                LuaError(callStr + ': ' + EnumToStr(spr) + ' cannot be placed! (required information not loaded)' )
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3212
            else
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3213
                EraseLand(
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3214
                    Trunc(lua_tonumber(L, 1)) - SpritesData[spr].Width div 2,
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3215
                    Trunc(lua_tonumber(L, 2)) - SpritesData[spr].Height div 2,
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3216
                    spr, Trunc(lua_tonumber(L, 4)), lf, eraseOnLFMatch, onlyEraseLF, flipHoriz, flipVert);
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3217
            end;
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3218
        end;
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3219
    lc_erasesprite:= 0
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3220
end;
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  3221
4985
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  3222
function lc_placegirder(L : Plua_State) : LongInt; Cdecl;
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3223
var placed: boolean;
4985
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  3224
begin
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3225
    placed:= false;
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3226
    if CheckLuaParamCount(L, 3, 'PlaceGirder', 'x, y, frameIdx') then
10295
ec6b68241575 fix some pas2c related overloading issue
sheepluva
parents: 10294
diff changeset
  3227
        placed:= TryPlaceOnLandSimple(
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3228
            Trunc(lua_tonumber(L, 1)) - SpritesData[sprAmGirder].Width div 2,
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3229
            Trunc(lua_tonumber(L, 2)) - SpritesData[sprAmGirder].Height div 2,
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3230
            sprAmGirder, Trunc(lua_tonumber(L, 3)), true, false);
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3231
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3232
    lua_pushboolean(L, placed);
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  3233
    lc_placegirder:= 1
4985
304d149bb3dd added PlaceGirder to lua
Henek
parents: 4976
diff changeset
  3234
end;
5013
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  3235
12090
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3236
function lc_placerubber(L : Plua_State) : LongInt; Cdecl;
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3237
var placed: boolean;
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3238
begin
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3239
    placed:= false;
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3240
    if CheckLuaParamCount(L, 3, 'PlaceRubber', 'x, y, frameIdx') then
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3241
        placed:= TryPlaceOnLand(
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3242
            Trunc(lua_tonumber(L, 1)) - SpritesData[sprAmRubber].Width div 2,
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3243
            Trunc(lua_tonumber(L, 2)) - SpritesData[sprAmRubber].Height div 2,
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3244
            sprAmRubber, Trunc(lua_tonumber(L, 3)), true, lfBouncy);
12090
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3245
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3246
    lua_pushboolean(L, placed);
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3247
    lc_placerubber:= 1
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3248
end;
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  3249
5013
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  3250
function lc_getcurammotype(L : Plua_State): LongInt; Cdecl;
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  3251
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3252
    if (CurrentHedgehog <> nil) and (CheckLuaParamCount(L, 0, 'GetCurAmmoType', '')) then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3253
        lua_pushnumber(L, ord(CurrentHedgehog^.CurAmmoType))
10291
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
  3254
    else
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3255
        lua_pushnumber(L, ord(amNothing));
5013
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  3256
    lc_getcurammotype := 1;
04789ba3f200 added GetCurAmmoType to lua
Henek
parents: 4985
diff changeset
  3257
end;
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3258
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3259
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
  3260
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3261
    if CheckLuaParamCount(L, 2, 'SaveCampaignVar', 'varname, value') then
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3262
        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
  3263
    lc_savecampaignvar := 0;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3264
end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3265
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3266
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
  3267
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3268
    if CheckLuaParamCount(L, 1, 'GetCampaignVar', 'varname') then
9718
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9670
diff changeset
  3269
        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
  3270
    lua_pushstring(L, str2pchar(CampaignVariable));
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3271
    lc_getcampaignvar := 1;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3272
end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3273
14484
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3274
function lc_savemissionvar(L : Plua_State): LongInt; Cdecl;
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3275
begin
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3276
    if CheckLuaParamCount(L, 2, 'SaveMissionVar', 'varname, value') then
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3277
        SendIPC('v!' + lua_tostring(L, 1) + ' ' + lua_tostring(L, 2) + #0);
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3278
    lc_savemissionvar := 0;
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3279
end;
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3280
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3281
function lc_getmissionvar(L : Plua_State): LongInt; Cdecl;
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3282
begin
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3283
    if CheckLuaParamCount(L, 1, 'GetMissionVar', 'varname') then
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3284
        SendIPCAndWaitReply('v?' + lua_tostring(L, 1) + #0);
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3285
    lua_pushstring(L, str2pchar(MissionVariable));
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3286
    lc_getmissionvar := 1;
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3287
end;
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  3288
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3289
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
  3290
var gear: PGear;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3291
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3292
    if CheckLuaParamCount(L, 1, 'HideHog', 'gearUid') then
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3293
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3294
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
15937
1becf4a0e907 forbid hiding already hidden hogs
nemo
parents: 15198
diff changeset
  3295
        if (gear <> nil) and (gear^.hedgehog <> nil) and (gear^.hedgehog^.gear <> nil) then
12360
a775a61e02ab Lua: Fix HideHog causing engine crash when provided with invalid gear ID or hog was hidden
Wuzzy <almikes@aol.com>
parents: 12332
diff changeset
  3296
            begin
a775a61e02ab Lua: Fix HideHog causing engine crash when provided with invalid gear ID or hog was hidden
Wuzzy <almikes@aol.com>
parents: 12332
diff changeset
  3297
            HideHog(gear^.hedgehog);
a775a61e02ab Lua: Fix HideHog causing engine crash when provided with invalid gear ID or hog was hidden
Wuzzy <almikes@aol.com>
parents: 12332
diff changeset
  3298
            lua_pushboolean(L, true);
a775a61e02ab Lua: Fix HideHog causing engine crash when provided with invalid gear ID or hog was hidden
Wuzzy <almikes@aol.com>
parents: 12332
diff changeset
  3299
            end
a775a61e02ab Lua: Fix HideHog causing engine crash when provided with invalid gear ID or hog was hidden
Wuzzy <almikes@aol.com>
parents: 12332
diff changeset
  3300
        else
a775a61e02ab Lua: Fix HideHog causing engine crash when provided with invalid gear ID or hog was hidden
Wuzzy <almikes@aol.com>
parents: 12332
diff changeset
  3301
            lua_pushboolean(L, false);
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3302
        end;
12360
a775a61e02ab Lua: Fix HideHog causing engine crash when provided with invalid gear ID or hog was hidden
Wuzzy <almikes@aol.com>
parents: 12332
diff changeset
  3303
    lc_hidehog := 1;
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3304
end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3305
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3306
function lc_restorehog(L: Plua_State): LongInt; Cdecl;
8370
0c79946e96f8 Fix tons of warnings
martin_bede
parents: 8368
diff changeset
  3307
var i, h: LongInt;
8012
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  3308
    uid: LongWord;
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3309
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3310
    if CheckLuaParamCount(L, 1, 'RestoreHog', 'gearUid') then
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3311
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3312
        uid:= LongWord(Trunc(lua_tonumber(L, 1)));
8012
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  3313
        if TeamsCount > 0 then
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  3314
            for i:= 0 to Pred(TeamsCount) do
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  3315
                for h:= 0 to cMaxHHIndex do
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  3316
                    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
  3317
                        begin
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  3318
                        RestoreHog(@TeamsArray[i]^.Hedgehogs[h]);
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  3319
                        exit(0)
2a61631a4505 this wasn't needed IMO
nemo
parents: 7996
diff changeset
  3320
                        end
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3321
        end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3322
    lc_restorehog := 0;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3323
end;
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  3324
13577
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3325
function lc_ishoghidden(L: Plua_State): LongInt; Cdecl;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3326
var i, h: LongInt;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3327
    uid: LongWord;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3328
    gear: PGear;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3329
begin
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3330
    if CheckLuaParamCount(L, 1, 'IsHogHidden', 'gearUid') then
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3331
        begin
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3332
        uid:= LongWord(Trunc(lua_tonumber(L, 1)));
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3333
        gear:= GearByUID(uid);
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3334
        if (gear <> nil) and (gear^.hedgehog <> nil) then
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3335
            begin
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3336
            lua_pushboolean(L, false);
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3337
            lc_ishoghidden:= 1;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3338
            exit;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3339
            end
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3340
        else
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3341
            if TeamsCount > 0 then
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3342
                for i:= 0 to Pred(TeamsCount) do
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3343
                    for h:= 0 to cMaxHHIndex do
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3344
                        if (TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil) and (TeamsArray[i]^.Hedgehogs[h].GearHidden^.uid = uid) then
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3345
                            begin
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3346
                            lua_pushboolean(L, true);
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3347
                            lc_ishoghidden:= 1;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3348
                            exit;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3349
                            end
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3350
        end;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3351
    lua_pushnil(L);
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3352
    lc_ishoghidden:= 1;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3353
end;
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  3354
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3355
// boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3356
function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3357
var rtn: Boolean;
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3358
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3359
    if CheckLuaParamCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3360
        begin
10818
f642a28cab0c Add placement of airmines in engine outside of hog proximity. Has a bug, only protecting 1st team. Also fix a spelling error and rename gstHHChooseTarget to gstChooseTarget
nemo
parents: 10809
diff changeset
  3361
        rtn:= TestRectangleForObstacle(
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3362
                    Trunc(lua_tonumber(L, 1)),
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3363
                    Trunc(lua_tonumber(L, 2)),
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3364
                    Trunc(lua_tonumber(L, 3)),
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3365
                    Trunc(lua_tonumber(L, 4)),
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3366
                    lua_toboolean(L, 5)
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3367
                    );
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3368
        lua_pushboolean(L, rtn);
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
  3369
        end
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
  3370
    else
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
  3371
        lua_pushnil(L); // return value on stack (nil)
5896
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3372
    lc_testrectforobstacle:= 1
9ce1cf4e5a32 lua: boolean TestRectForObstacle(x1, y1, x2, y2, landOnly)
sheepluva
parents: 5825
diff changeset
  3373
end;
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  3374
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  3375
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3376
function lc_getgravity(L : Plua_State) : LongInt; Cdecl;
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3377
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3378
    if CheckLuaParamCount(L, 0, 'GetGravity', '') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3379
        lua_pushnumber(L, hwRound(SignAs(_0_5, cGravity) + (cGravity * 50 / cMaxWindSpeed)));
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3380
    lc_getgravity:= 1
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3381
end;
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3382
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3383
function lc_setgravity(L : Plua_State) : LongInt; Cdecl;
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3384
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3385
    if CheckLuaParamCount(L, 1, 'SetGravity', 'percent') then
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3386
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3387
        cGravity:= _0_02 * Trunc(lua_tonumber(L, 1)) * cMaxWindSpeed;
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3388
        cGravityf:= 0.00025 * Trunc(lua_tonumber(L, 1)) * 0.02
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3389
        end;
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3390
    lc_setgravity:= 0
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3391
end;
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3392
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3393
function lc_setwaterline(L : Plua_State) : LongInt; Cdecl;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3394
var iterator: PGear;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3395
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3396
    if CheckLuaParamCount(L, 1, 'SetWaterLine', 'waterline') then
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3397
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3398
        cWaterLine:= Trunc(lua_tonumber(L,1));
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3399
        AllInactive:= false;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3400
        iterator:= GearsList;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3401
        while iterator <> nil do
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3402
            begin
9917
nemo
parents: 9914
diff changeset
  3403
            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
  3404
                begin
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3405
                iterator^.Active:= true;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3406
                if iterator^.dY.QWordValue = 0 then iterator^.dY.isNegative:= false;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3407
                iterator^.State:= iterator^.State or gstMoving;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3408
                DeleteCI(iterator)
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3409
                end;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3410
            iterator:= iterator^.NextGear
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3411
            end
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3412
        end;
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3413
    lc_setwaterline:= 0
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  3414
end;
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  3415
11066
f10a4bdfa0f4 fix internal function name
sheepluva
parents: 11062
diff changeset
  3416
function lc_setgearaihints(L : Plua_State) : LongInt; Cdecl;
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  3417
var gear: PGear;
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  3418
begin
13036
434bcdd9562c Fix inconsistent name of SetGearAIHints
Wuzzy <Wuzzy2@mail.ru>
parents: 13020
diff changeset
  3419
    if CheckLuaParamCount(L, 2, 'SetGearAIHints', 'gearUid, aiHints') then
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  3420
        begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3421
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  3422
        if gear <> nil then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3423
            gear^.aihints:= Trunc(lua_tonumber(L, 2));
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  3424
        end;
11066
f10a4bdfa0f4 fix internal function name
sheepluva
parents: 11062
diff changeset
  3425
    lc_setgearaihints:= 0
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  3426
end;
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  3427
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  3428
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  3429
function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl;
13728
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3430
var success : boolean;
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3431
    n : LongInt;
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  3432
begin
14304
9548edd9ebcf uninitialised values
nemo
parents: 14240
diff changeset
  3433
	success:= false;
13728
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3434
    if CheckAndFetchParamCount(L, 1, 2, 'HedgewarsScriptLoad', 'scriptPath [, mustExist]', n) then
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3435
        begin
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3436
        if n = 1 then
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3437
            success:= ScriptLoad(lua_tostring(L, 1), true)
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3438
        else
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3439
            success:= ScriptLoad(lua_tostring(L, 1), lua_toboolean(L, 2));
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3440
        end
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  3441
    else
13728
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3442
        success:= false;
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3443
    lua_pushboolean(L, success);
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3444
    lc_hedgewarsscriptload:= 1;
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  3445
end;
9397
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  3446
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  3447
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  3448
function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  3449
begin
10297
e5ed72b40c57 fix pas2c build for real this time...
sheepluva
parents: 10295
diff changeset
  3450
    if CheckLuaParamCount(L, 4, 'DeclareAchievement', 'achievementId, teamname, location, value') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3451
        declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), Trunc(lua_tonumber(L, 4)));
9397
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  3452
    lc_declareachievement:= 0
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  3453
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
  3454
11846
6bf91006d630 Lua API: GetAmmoName(ammoType)
sheepluva
parents: 11844
diff changeset
  3455
function lc_getammoname(L : Plua_state) : LongInt; Cdecl;
11945
1e58845fa3c1 Allow to ignore overwritten ammo name in GetAmmoName
Wuzzy <almikes@aol.com>
parents: 11944
diff changeset
  3456
var np, at: LongInt;
1e58845fa3c1 Allow to ignore overwritten ammo name in GetAmmoName
Wuzzy <almikes@aol.com>
parents: 11944
diff changeset
  3457
    ignoreOverwrite: Boolean;
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3458
const callStr = 'GetAmmoName';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3459
      paramsStr = 'ammoType [, ignoreOverwrite ]';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3460
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3461
    if CheckAndFetchParamCountRange(L, 1, 2, callStr, paramsStr, np) then
11846
6bf91006d630 Lua API: GetAmmoName(ammoType)
sheepluva
parents: 11844
diff changeset
  3462
        begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3463
        at:= LuaToAmmoTypeOrd(L, 1, callStr, paramsStr);
11945
1e58845fa3c1 Allow to ignore overwritten ammo name in GetAmmoName
Wuzzy <almikes@aol.com>
parents: 11944
diff changeset
  3464
        ignoreOverwrite := false;
1e58845fa3c1 Allow to ignore overwritten ammo name in GetAmmoName
Wuzzy <almikes@aol.com>
parents: 11944
diff changeset
  3465
        if np > 1 then
1e58845fa3c1 Allow to ignore overwritten ammo name in GetAmmoName
Wuzzy <almikes@aol.com>
parents: 11944
diff changeset
  3466
            ignoreOverwrite := lua_toboolean(L, 2);
12596
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3467
        if at >= 0 then
11945
1e58845fa3c1 Allow to ignore overwritten ammo name in GetAmmoName
Wuzzy <almikes@aol.com>
parents: 11944
diff changeset
  3468
            if (not ignoreOverwrite) and (length(trluaammo[Ammoz[TAmmoType(at)].NameId]) > 0) then
11944
87edf67f2107 GetAmmoName now returns ammo name overwritten by SetAmmoTexts
Wuzzy <almikes@aol.com>
parents: 11941
diff changeset
  3469
                lua_pushstring(L, PChar(trluaammo[Ammoz[TAmmoType(at)].NameId]))
87edf67f2107 GetAmmoName now returns ammo name overwritten by SetAmmoTexts
Wuzzy <almikes@aol.com>
parents: 11941
diff changeset
  3470
            else
87edf67f2107 GetAmmoName now returns ammo name overwritten by SetAmmoTexts
Wuzzy <almikes@aol.com>
parents: 11941
diff changeset
  3471
                lua_pushstring(L, PChar(trammo[Ammoz[TAmmoType(at)].NameId]));
11846
6bf91006d630 Lua API: GetAmmoName(ammoType)
sheepluva
parents: 11844
diff changeset
  3472
        end
6bf91006d630 Lua API: GetAmmoName(ammoType)
sheepluva
parents: 11844
diff changeset
  3473
    else
6bf91006d630 Lua API: GetAmmoName(ammoType)
sheepluva
parents: 11844
diff changeset
  3474
        lua_pushnil(L);
6bf91006d630 Lua API: GetAmmoName(ammoType)
sheepluva
parents: 11844
diff changeset
  3475
    lc_getammoname:= 1;
6bf91006d630 Lua API: GetAmmoName(ammoType)
sheepluva
parents: 11844
diff changeset
  3476
end;
6bf91006d630 Lua API: GetAmmoName(ammoType)
sheepluva
parents: 11844
diff changeset
  3477
13371
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3478
function lc_getammotimer(L : Plua_state) : LongInt; Cdecl;
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3479
var at: LongInt;
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3480
    weapon: PAmmo;
13373
0a93948e8ec7 Fix GetAmmoTimer implementation, swap arguments
Wuzzy <Wuzzy2@mail.ru>
parents: 13371
diff changeset
  3481
    gear: PGear;
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3482
const callStr = 'GetAmmoTimer';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3483
      paramsStr = 'gearUid, ammoType';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3484
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3485
    if CheckLuaParamCount(L, 2, callStr, paramsStr) then
13371
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3486
        begin
13373
0a93948e8ec7 Fix GetAmmoTimer implementation, swap arguments
Wuzzy <Wuzzy2@mail.ru>
parents: 13371
diff changeset
  3487
        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
0a93948e8ec7 Fix GetAmmoTimer implementation, swap arguments
Wuzzy <Wuzzy2@mail.ru>
parents: 13371
diff changeset
  3488
        if (gear <> nil) and (gear^.Hedgehog <> nil) then
0a93948e8ec7 Fix GetAmmoTimer implementation, swap arguments
Wuzzy <Wuzzy2@mail.ru>
parents: 13371
diff changeset
  3489
            begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3490
            at:= LuaToAmmoTypeOrd(L, 2, callStr, paramsStr);
13373
0a93948e8ec7 Fix GetAmmoTimer implementation, swap arguments
Wuzzy <Wuzzy2@mail.ru>
parents: 13371
diff changeset
  3491
            weapon:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
0a93948e8ec7 Fix GetAmmoTimer implementation, swap arguments
Wuzzy <Wuzzy2@mail.ru>
parents: 13371
diff changeset
  3492
            if (Ammoz[TAmmoType(at)].Ammo.Propz and ammoprop_Timerable) <> 0 then
0a93948e8ec7 Fix GetAmmoTimer implementation, swap arguments
Wuzzy <Wuzzy2@mail.ru>
parents: 13371
diff changeset
  3493
                lua_pushnumber(L, weapon^.Timer)
0a93948e8ec7 Fix GetAmmoTimer implementation, swap arguments
Wuzzy <Wuzzy2@mail.ru>
parents: 13371
diff changeset
  3494
            else
0a93948e8ec7 Fix GetAmmoTimer implementation, swap arguments
Wuzzy <Wuzzy2@mail.ru>
parents: 13371
diff changeset
  3495
                lua_pushnil(L);
0a93948e8ec7 Fix GetAmmoTimer implementation, swap arguments
Wuzzy <Wuzzy2@mail.ru>
parents: 13371
diff changeset
  3496
            end
13371
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3497
        else
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3498
            lua_pushnil(L);
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3499
        end
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3500
    else
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3501
        lua_pushnil(L);
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3502
    lc_getammotimer:= 1;
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3503
end;
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  3504
12929
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3505
function lc_setvampiric(L : Plua_state) : LongInt; Cdecl;
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3506
begin
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3507
    if CheckLuaParamCount(L, 1, 'SetVampiric', 'bool') then
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3508
        cVampiric := lua_toboolean(L, 1);
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3509
    lc_setvampiric := 0;
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3510
end;
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3511
13576
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3512
function lc_getvampiric(L : Plua_state) : LongInt; Cdecl;
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3513
begin
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3514
    lua_pushboolean(L, cVampiric);
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3515
    lc_getvampiric := 1;
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3516
end;
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3517
12929
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3518
function lc_setlasersight(L : Plua_state) : LongInt; Cdecl;
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3519
begin
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3520
    if CheckLuaParamCount(L, 1, 'SetLaserSight', 'bool') then
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3521
        cLaserSighting:= lua_toboolean(L, 1);
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3522
    lc_setlasersight:= 0;
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3523
end;
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  3524
13576
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3525
function lc_getlasersight(L : Plua_state) : LongInt; Cdecl;
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3526
begin
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3527
    lua_pushboolean(L, cLaserSighting);
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3528
    lc_getlasersight:= 1;
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3529
end;
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  3530
13270
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3531
function lc_explode(L : Plua_state) : LongInt; Cdecl;
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3532
var mask: LongWord;
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3533
    n: LongInt;
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3534
begin
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3535
    if CheckAndFetchParamCount(L, 3, 4, 'Explode', 'x, y, radius[, options]', n) then
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3536
        if CurrentHedgehog <> nil then
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3537
            begin
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3538
            mask:= EXPLAutoSound;
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3539
            if (n = 4) then
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3540
                mask:= Trunc(lua_tonumber(L, 4));
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3541
            doMakeExplosion(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)), Trunc(lua_tonumber(L, 3)), CurrentHedgehog, mask);
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3542
            lua_pushboolean(L, true);
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3543
            end
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3544
        else
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3545
            lua_pushboolean(L, false)
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3546
    else
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3547
        lua_pushboolean(L, false);
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3548
    lc_explode:= 1;
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3549
end;
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  3550
13741
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  3551
function lc_setturntimeleft(L : Plua_State) : LongInt; Cdecl;
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3552
var number: Int64;
13741
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  3553
begin
13812
e2d902745fd5 Fix some syntax errors in internal Lua syntax documentation
Wuzzy <Wuzzy2@mail.ru>
parents: 13766
diff changeset
  3554
    if CheckLuaParamCount(L, 1, 'SetTurnTimeLeft', 'newTurnTimeLeft') then
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3555
        begin
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3556
        number:= Trunc(lua_tonumber(L, 1));
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3557
        if number < 0 then
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3558
            number:= 0;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3559
        if number > cMaxTurnTime then
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3560
            number:= cMaxTurnTime;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3561
        // The real TurnTimeLeft will be set in SetGlobals
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3562
        PendingTurnTimeLeft:= number;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3563
        isPendingTurnTimeLeft:= true;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3564
        end;
13741
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  3565
    lc_setturntimeleft:= 0;
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  3566
end;
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  3567
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  3568
function lc_setreadytimeleft(L : Plua_State) : LongInt; Cdecl;
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3569
var number: Int64;
13741
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  3570
begin
13812
e2d902745fd5 Fix some syntax errors in internal Lua syntax documentation
Wuzzy <Wuzzy2@mail.ru>
parents: 13766
diff changeset
  3571
    if CheckLuaParamCount(L, 1, 'SetReadyTimeLeft', 'newReadyTimeLeft') then
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3572
        begin
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3573
        number:= Trunc(lua_tonumber(L, 1));
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3574
        if number < 0 then
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3575
            number:= 0;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3576
        if number > cMaxTurnTime then
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3577
            number:= cMaxTurnTime;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3578
        // The real ReadyTimeLeft will be set in SetGlobals
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3579
        PendingReadyTimeLeft:= number;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3580
        isPendingReadyTimeLeft:= true;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  3581
        end;
13741
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  3582
    lc_setreadytimeleft:= 0;
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  3583
end;
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  3584
14415
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3585
function lc_setturntimepaused(L : Plua_State) : LongInt; Cdecl;
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3586
begin
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3587
    if CheckLuaParamCount(L, 1, 'SetTurnTimePaused', 'isPaused') then
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3588
        LuaClockPaused:= lua_toboolean(L, 1);
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3589
    lc_setturntimepaused:= 0;
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3590
end;
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3591
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3592
function lc_getturntimepaused(L : Plua_State) : LongInt; Cdecl;
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3593
begin
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3594
    if CheckLuaParamCount(L, 0, 'GetTurnTimePaused', '') then
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3595
        lua_pushboolean(L, LuaClockPaused)
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3596
    else
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3597
        lua_pushnil(L);
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3598
    lc_getturntimepaused:= 1;
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3599
end;
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  3600
11569
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3601
function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl;
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3602
begin
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3603
    if CheckLuaParamCount(L, 1, 'StartGhostPoints', 'count') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3604
        startGhostPoints(Trunc(lua_tonumber(L, 1)));
11569
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3605
    lc_startghostpoints:= 0
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3606
end;
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3607
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3608
function lc_dumppoint(L : Plua_State) : LongInt; Cdecl;
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3609
begin
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3610
    if CheckLuaParamCount(L, 2, 'DumpPoint', 'x, y') then
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3611
        dumpPoint(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)));
11569
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3612
    lc_dumppoint:= 0
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3613
end;
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  3614
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3615
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3616
procedure ScriptFlushPoints();
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3617
begin
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3618
    ParseCommand('draw ' + PointsBuffer, true, true);
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3619
    PointsBuffer:= '';
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3620
end;
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3621
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3622
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3623
function lc_addPoint(L : Plua_State) : LongInt; Cdecl;
10660
79fa79c77c38 fix size of PtrInt. enable tests for pas2c (all passing now)
sheepluva
parents: 10634
diff changeset
  3624
var np, param: LongInt;
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3625
begin
10613
f2597a21f562 update changelog
sheepluva
parents: 10611
diff changeset
  3626
    if CheckAndFetchParamCountRange(L, 2, 4, 'AddPoint', 'x, y [, width [, erase] ]', np) then
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3627
        begin
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3628
        // x
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3629
        param:= LongInt(Trunc(lua_tonumber(L,1)));
10660
79fa79c77c38 fix size of PtrInt. enable tests for pas2c (all passing now)
sheepluva
parents: 10634
diff changeset
  3630
        PointsBuffer:= PointsBuffer + char((param shr 8) and $FF);
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3631
        PointsBuffer:= PointsBuffer + char((param and $FF));
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3632
        // y
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3633
        param:= LongInt(Trunc(lua_tonumber(L,2)));
10660
79fa79c77c38 fix size of PtrInt. enable tests for pas2c (all passing now)
sheepluva
parents: 10634
diff changeset
  3634
        PointsBuffer:= PointsBuffer + char((param shr 8) and $FF);
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3635
        PointsBuffer:= PointsBuffer + char((param and $FF));
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3636
        // width
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3637
        if np > 2 then
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3638
            begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3639
            param:= Trunc(lua_tonumber(L,3));
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3640
            param:= (param or $80);
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3641
            // erase
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3642
            if (np > 3) and lua_toboolean(L, 4) then
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3643
                param:= (param or $40);
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3644
            PointsBuffer:= PointsBuffer + char(param);
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3645
            end
10615
e3dcb235a354 fix some things I messed up with the drawing functions
sheepluva
parents: 10613
diff changeset
  3646
        // no width defined
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3647
        else
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3648
            PointsBuffer:= PointsBuffer + char(0);
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3649
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3650
        // flush before shortstring limit length is reached
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3651
        if length(PointsBuffer) > 245 then
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3652
            ScriptFlushPoints();
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3653
        end;
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3654
    lc_addPoint:= 0
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3655
end;
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3656
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3657
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3658
function lc_flushPoints(L : Plua_State) : LongInt; Cdecl;
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3659
begin
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3660
    if CheckLuaParamCount(L, 0, 'FlushPoints', '') then
10615
e3dcb235a354 fix some things I messed up with the drawing functions
sheepluva
parents: 10613
diff changeset
  3661
        if length(PointsBuffer) > 0 then
e3dcb235a354 fix some things I messed up with the drawing functions
sheepluva
parents: 10613
diff changeset
  3662
            ScriptFlushPoints();
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3663
    lc_flushPoints:= 0
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3664
end;
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  3665
10618
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3666
// stuff for lua tests
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
  3667
function lc_endluatest(L : Plua_State) : LongInt; Cdecl;
10618
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3668
var rstring: shortstring;
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3669
const
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3670
    callStr = 'EndLuaTest';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3671
    paramsStr = 'TEST_SUCCESSFUL or TEST_FAILED';
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3672
begin
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3673
    if CheckLuaParamCount(L, 1, callStr, paramsStr) then
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
  3674
        begin
10618
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3675
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3676
        case Trunc(lua_tonumber(L, 1)) of
10618
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3677
            HaltTestSuccess : rstring:= 'Success';
11617
aed348042a77 fix check for wrong value
sheepluva
parents: 11569
diff changeset
  3678
            HaltTestFailed: rstring:= 'FAILED';
10618
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3679
        else
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3680
            begin
15980
77f1973611ec Refactor const names in uScript, no logic change
unc0rr
parents: 15938
diff changeset
  3681
            LuaCallError('Parameter must be either ' + paramsStr, callStr, paramsStr);
10618
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3682
            exit(0);
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3683
            end;
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3684
        end;
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3685
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3686
        if cTestLua then
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3687
            begin
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3688
            WriteLnToConsole('Lua test finished, result: ' + rstring);
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3689
            halt(Trunc(lua_tonumber(L, 1)));
10618
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3690
            end
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3691
        else LuaError('Not in lua test mode, engine will keep running. Reported test result: ' + rstring);
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3692
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3693
        end;
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  3694
10284
e9c85a0acdd2 placeSprite accepts any amount of landflags now; further WIP wrt cleanup/fixing
sheepluva
parents: 10283
diff changeset
  3695
    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
  3696
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
  3697
///////////////////
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  3698
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  3699
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
  3700
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
  3701
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
  3702
    n:= lua_gettop(luaState);
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
  3703
    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
  3704
    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
  3705
        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
  3706
            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
  3707
        else if lua_toboolean(luaState, i) then
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
  3708
            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
  3709
        else
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
  3710
            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
  3711
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
  3712
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  3713
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
  3714
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  3715
    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
  3716
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
  3717
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  3718
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
  3719
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  3720
    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
  3721
    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
  3722
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
  3723
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  3724
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
  3725
begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3726
    lua_pushnumber(luaState, value);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  3727
    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
  3728
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
  3729
15198
a22013a817e4 Lua: Fix incorrect values for capcolDefault, capcolSetting
Wuzzy <Wuzzy2@mail.ru>
parents: 15152
diff changeset
  3730
procedure ScriptSetLongWord(name : shortstring; value : LongWord);
a22013a817e4 Lua: Fix incorrect values for capcolDefault, capcolSetting
Wuzzy <Wuzzy2@mail.ru>
parents: 15152
diff changeset
  3731
begin
a22013a817e4 Lua: Fix incorrect values for capcolDefault, capcolSetting
Wuzzy <Wuzzy2@mail.ru>
parents: 15152
diff changeset
  3732
    lua_pushnumber(luaState, value);
a22013a817e4 Lua: Fix incorrect values for capcolDefault, capcolSetting
Wuzzy <Wuzzy2@mail.ru>
parents: 15152
diff changeset
  3733
    lua_setglobal(luaState, Str2PChar(name));
a22013a817e4 Lua: Fix incorrect values for capcolDefault, capcolSetting
Wuzzy <Wuzzy2@mail.ru>
parents: 15152
diff changeset
  3734
end;
a22013a817e4 Lua: Fix incorrect values for capcolDefault, capcolSetting
Wuzzy <Wuzzy2@mail.ru>
parents: 15152
diff changeset
  3735
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
  3736
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
  3737
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  3738
    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
  3739
    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
  3740
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
  3741
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  3742
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
  3743
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  3744
    lua_getglobal(luaState, Str2PChar(name));
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  3745
    ScriptGetInteger:= Trunc(lua_tonumber(luaState, -1));
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  3746
    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
  3747
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
  3748
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  3749
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
  3750
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  3751
    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
  3752
    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
  3753
    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
  3754
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
  3755
12749
1df909b46c05 Lua API: Fix Goals text being cut off at ca. 255 characters
Wuzzy <Wuzzy2@mail.ru>
parents: 12683
diff changeset
  3756
function ScriptGetAnsiString(name : shortstring) : ansistring;
1df909b46c05 Lua API: Fix Goals text being cut off at ca. 255 characters
Wuzzy <Wuzzy2@mail.ru>
parents: 12683
diff changeset
  3757
begin
1df909b46c05 Lua API: Fix Goals text being cut off at ca. 255 characters
Wuzzy <Wuzzy2@mail.ru>
parents: 12683
diff changeset
  3758
    lua_getglobal(luaState, Str2PChar(name));
1df909b46c05 Lua API: Fix Goals text being cut off at ca. 255 characters
Wuzzy <Wuzzy2@mail.ru>
parents: 12683
diff changeset
  3759
    ScriptGetAnsiString:= lua_tostringa(luaState, -1);
1df909b46c05 Lua API: Fix Goals text being cut off at ca. 255 characters
Wuzzy <Wuzzy2@mail.ru>
parents: 12683
diff changeset
  3760
    lua_pop(luaState, 1);
1df909b46c05 Lua API: Fix Goals text being cut off at ca. 255 characters
Wuzzy <Wuzzy2@mail.ru>
parents: 12683
diff changeset
  3761
end;
1df909b46c05 Lua API: Fix Goals text being cut off at ca. 255 characters
Wuzzy <Wuzzy2@mail.ru>
parents: 12683
diff changeset
  3762
10150
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3763
procedure ScriptOnPreviewInit;
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3764
begin
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3765
// not required if there is no script to run
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3766
if not ScriptLoaded then
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3767
    exit;
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3768
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3769
ScriptSetString('Seed', cSeed);
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3770
ScriptSetInteger('TemplateFilter', cTemplateFilter);
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3771
ScriptSetInteger('TemplateNumber', LuaTemplateNumber);
10603
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
  3772
ScriptSetInteger('MapGen', ord(cMapGen));
11062
46f293e8cbfb also expose MapFeatureSize in onPreviewInit
sheepluva
parents: 11061
diff changeset
  3773
ScriptSetInteger('MapFeatureSize', cFeatureSize);
10150
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3774
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3775
ScriptCall('onPreviewInit');
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3776
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3777
// pop game variables
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3778
ParseCommand('seed ' + ScriptGetString('Seed'), true, true);
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3779
cTemplateFilter  := ScriptGetInteger('TemplateFilter');
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3780
LuaTemplateNumber:= ScriptGetInteger('TemplateNumber');
10603
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
  3781
cMapGen          := TMapGen(ScriptGetInteger('MapGen'));
11062
46f293e8cbfb also expose MapFeatureSize in onPreviewInit
sheepluva
parents: 11061
diff changeset
  3782
cFeatureSize     := ScriptGetInteger('MapFeatureSize');
10150
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3783
end;
fa5c83fd0ad9 Allow lua drawn maps (shoppamap, tunnels, diagonal maze etc) to generate previews.
nemo
parents: 10143
diff changeset
  3784
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
  3785
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
  3786
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
  3787
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
  3788
// 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
  3789
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
  3790
    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
  3791
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  3792
// push game variables so they may be modified by the script
13216
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  3793
ScriptSetInteger('CursorX', NoPointX);
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  3794
ScriptSetInteger('CursorY', NoPointX);
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
  3795
ScriptSetInteger('GameFlags', GameFlags);
11879
c6eafb6f2735 Add WorldEdge to Lua API to expose/change world edge type
Wuzzy <almikes@aol.com>
parents: 11849
diff changeset
  3796
ScriptSetInteger('WorldEdge', ord(WorldEdge));
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
  3797
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
  3798
ScriptSetInteger('TemplateFilter', cTemplateFilter);
7567
da2aa8355d91 allow lua to specify template by number
nemo
parents: 7546
diff changeset
  3799
ScriptSetInteger('TemplateNumber', LuaTemplateNumber);
10603
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
  3800
ScriptSetInteger('MapGen', ord(cMapGen));
11061
2f1efb11ddf3 Lua API: expose MapFeatureSize during init
sheepluva
parents: 11060
diff changeset
  3801
ScriptSetInteger('MapFeatureSize', cFeatureSize);
5583
63b274a4fb01 At mikade's request, expose screenheight/screenwidth and allow setting tag zoom level
nemo
parents: 5554
diff changeset
  3802
ScriptSetInteger('ScreenHeight', cScreenHeight);
63b274a4fb01 At mikade's request, expose screenheight/screenwidth and allow setting tag zoom level
nemo
parents: 5554
diff changeset
  3803
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
  3804
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
  3805
ScriptSetInteger('CaseFreq', cCaseFactor);
13627
605767bbd022 Move max. number of crate spawns into variable
Wuzzy <Wuzzy2@mail.ru>
parents: 13618
diff changeset
  3806
ScriptSetInteger('MaxCaseDrops', cMaxCaseDrops);
4162
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  3807
ScriptSetInteger('HealthCaseProb', cHealthCaseProb);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  3808
ScriptSetInteger('HealthCaseAmount', cHealthCaseAmount);
14543
d0441c7e9000 Lua: Add InitHealth, read-only variable containing the initial hog health setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14505
diff changeset
  3809
ScriptSetInteger('InitHealth', cInitHealth);
4221
a1bf0f6b0d65 added missing game modifiers to lua
Henek
parents: 4219
diff changeset
  3810
ScriptSetInteger('DamagePercent', cDamagePercent);
6557
e3cad9020778 Push RopePercent to lua to fix rope if not set
enveezee
parents: 6543
diff changeset
  3811
ScriptSetInteger('RopePercent', cRopePercent);
4003
ca0600ab38bf disable gfMines and update variable names (landadds -> minesnum, cLandAdditions -> cLandMines)
koda
parents: 3999
diff changeset
  3812
ScriptSetInteger('MinesNum', cLandMines);
4221
a1bf0f6b0d65 added missing game modifiers to lua
Henek
parents: 4219
diff changeset
  3813
ScriptSetInteger('MinesTime', cMinesTime);
a1bf0f6b0d65 added missing game modifiers to lua
Henek
parents: 4219
diff changeset
  3814
ScriptSetInteger('MineDudPercent', cMineDudPercent);
11963
0c1420aaa59e Expose number of air mines in Lua variable AirMinesNum
Wuzzy <almikes@aol.com>
parents: 11945
diff changeset
  3815
ScriptSetInteger('AirMinesNum', cAirMines);
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
  3816
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
  3817
ScriptSetInteger('Delay', cInactDelay);
3774
af0e68ca273e Engine:
smaxx
parents: 3761
diff changeset
  3818
ScriptSetInteger('Ready', cReadyDelay);
3197
smxx
parents: 3058
diff changeset
  3819
ScriptSetInteger('SuddenDeathTurns', cSuddenDTurns);
4162
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  3820
ScriptSetInteger('WaterRise', cWaterRise);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  3821
ScriptSetInteger('HealthDecrease', cHealthDecrease);
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9815
diff changeset
  3822
ScriptSetInteger('GetAwayTime', cGetAwayTime);
12301
46e1e25fec5e Lua variable: AmmoTypeMax (maximum ammo type ID for iterating)
Wuzzy <almikes@aol.com>
parents: 12294
diff changeset
  3823
ScriptSetInteger('AmmoTypeMax', Ord(High(TAmmoType)));
6828
6a5d33bff0b0 At mikade's request. give scripting access to the map name prior to override.
nemo
parents: 6790
diff changeset
  3824
ScriptSetString('Map', cMapName);
11737
571d06a86bb6 fix for issue 71: Lua API: “Theme” variable is set to empty string initially
Wuzzy <almikes@aol.com>
parents: 11736
diff changeset
  3825
ScriptSetString('Theme', Theme);
4883
7cddc9201a1d added dummy for tardis and ugly icons for tardis and structure
Henek
parents: 4882
diff changeset
  3826
ScriptSetString('Goals', '');
7cddc9201a1d added dummy for tardis and ugly icons for tardis and structure
Henek
parents: 4882
diff changeset
  3827
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
  3828
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
  3829
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  3830
// pop game variables
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  3831
ParseCommand('seed ' + ScriptGetString('Seed'), true, true);
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3832
cTemplateFilter  := ScriptGetInteger('TemplateFilter');
7567
da2aa8355d91 allow lua to specify template by number
nemo
parents: 7546
diff changeset
  3833
LuaTemplateNumber:= ScriptGetInteger('TemplateNumber');
10603
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
  3834
cMapGen          := TMapGen(ScriptGetInteger('MapGen'));
11061
2f1efb11ddf3 Lua API: expose MapFeatureSize during init
sheepluva
parents: 11060
diff changeset
  3835
cFeatureSize     := ScriptGetInteger('MapFeatureSize');
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3836
GameFlags        := ScriptGetInteger('GameFlags');
11879
c6eafb6f2735 Add WorldEdge to Lua API to expose/change world edge type
Wuzzy <almikes@aol.com>
parents: 11849
diff changeset
  3837
WorldEdge        := TWorldEdge(ScriptGetInteger('WorldEdge'));
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3838
cHedgehogTurnTime:= ScriptGetInteger('TurnTime');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3839
cCaseFactor      := ScriptGetInteger('CaseFreq');
13627
605767bbd022 Move max. number of crate spawns into variable
Wuzzy <Wuzzy2@mail.ru>
parents: 13618
diff changeset
  3840
cMaxCaseDrops    := ScriptGetInteger('MaxCaseDrops');
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3841
cHealthCaseProb  := ScriptGetInteger('HealthCaseProb');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3842
cHealthCaseAmount:= ScriptGetInteger('HealthCaseAmount');
14543
d0441c7e9000 Lua: Add InitHealth, read-only variable containing the initial hog health setting
Wuzzy <Wuzzy2@mail.ru>
parents: 14505
diff changeset
  3843
cInitHealth      := ScriptGetInteger('InitHealth');
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3844
cDamagePercent   := ScriptGetInteger('DamagePercent');
6523
666fccd5cb3a enable lua to also set rope length percent
Henek
parents: 6468
diff changeset
  3845
cRopePercent     := ScriptGetInteger('RopePercent');
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3846
cLandMines       := ScriptGetInteger('MinesNum');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3847
cMinesTime       := ScriptGetInteger('MinesTime');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3848
cMineDudPercent  := ScriptGetInteger('MineDudPercent');
11963
0c1420aaa59e Expose number of air mines in Lua variable AirMinesNum
Wuzzy <almikes@aol.com>
parents: 11945
diff changeset
  3849
cAirMines        := ScriptGetInteger('AirMinesNum');
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3850
cExplosives      := ScriptGetInteger('Explosives');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3851
cInactDelay      := ScriptGetInteger('Delay');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3852
cReadyDelay      := ScriptGetInteger('Ready');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3853
cSuddenDTurns    := ScriptGetInteger('SuddenDeathTurns');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3854
cWaterRise       := ScriptGetInteger('WaterRise');
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3855
cHealthDecrease  := ScriptGetInteger('HealthDecrease');
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9815
diff changeset
  3856
cGetAwayTime     := ScriptGetInteger('GetAwayTime');
6312
658055a3f160 fix map/template override, remove some pointless command calls
nemo
parents: 6131
diff changeset
  3857
7771
ce6d4dd0c780 fix trophyrace. also tweak it a little
nemo
parents: 7754
diff changeset
  3858
if cMapName <> ScriptGetString('Map') then
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  3859
    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
  3860
if ScriptGetString('Theme') <> '' then
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  3861
    ParseCommand('theme ' + ScriptGetString('Theme'), true, true);
12749
1df909b46c05 Lua API: Fix Goals text being cut off at ca. 255 characters
Wuzzy <Wuzzy2@mail.ru>
parents: 12683
diff changeset
  3862
LuaGoals:= ScriptGetAnsiString('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
  3863
6578
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  3864
// 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
  3865
k:= 0;
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  3866
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
  3867
    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
  3868
        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
  3869
            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
  3870
                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
  3871
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
  3872
    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
  3873
        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
  3874
            begin
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  3875
            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
  3876
            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
  3877
            inc(k)
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  3878
            end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  3879
else
6578
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  3880
    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
  3881
        begin
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  3882
        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
  3883
            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
  3884
        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
  3885
        inc(k)
d4ad42283125 Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
nemo
parents: 6563
diff changeset
  3886
        end;
6743
864bf0f52a8c make onAmmoStoreInit optional in the case of onNewAmmoStore
nemo
parents: 6742
diff changeset
  3887
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
  3888
    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
  3889
    // 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
  3890
    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
  3891
    uAmmos.initModule;
6743
864bf0f52a8c make onAmmoStoreInit optional in the case of onNewAmmoStore
nemo
parents: 6742
diff changeset
  3892
    if ScriptExists('onAmmoStoreInit') then
864bf0f52a8c make onAmmoStoreInit optional in the case of onNewAmmoStore
nemo
parents: 6742
diff changeset
  3893
        begin
6752
nemo
parents: 6746
diff changeset
  3894
        ScriptPrepareAmmoStore;
6743
864bf0f52a8c make onAmmoStoreInit optional in the case of onNewAmmoStore
nemo
parents: 6742
diff changeset
  3895
        ScriptCall('onAmmoStoreInit');
6746
nemo
parents: 6743
diff changeset
  3896
        SetAmmoLoadout(ScriptAmmoLoadout);
nemo
parents: 6743
diff changeset
  3897
        SetAmmoProbability(ScriptAmmoProbability);
nemo
parents: 6743
diff changeset
  3898
        SetAmmoDelay(ScriptAmmoDelay);
nemo
parents: 6743
diff changeset
  3899
        SetAmmoReinforcement(ScriptAmmoReinforcement)
6743
864bf0f52a8c make onAmmoStoreInit optional in the case of onNewAmmoStore
nemo
parents: 6742
diff changeset
  3900
        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
  3901
    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
  3902
    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
  3903
4235
6b1dfbd60a45 added TeamsCount and TotalTurns to lua as requested by mikade
Henek
parents: 4221
diff changeset
  3904
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
  3905
ScriptSetInteger('TeamsCount', TeamsCount);
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
  3906
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
  3907
5825
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  3908
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  3909
// 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
  3910
procedure ScriptOnScreenResize();
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  3911
begin
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  3912
ScriptSetInteger('ScreenHeight', cScreenHeight);
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  3913
ScriptSetInteger('ScreenWidth', cScreenWidth);
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  3914
ScriptCall('onScreenResize');
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  3915
end;
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  3916
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  3917
// custom script loader via physfs, passed to lua_load
8034
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents: 8031
diff changeset
  3918
const BUFSIZE = 1024;
5825
a6eab1b7c00d Scripting: Update screen dimensions on screen resize and introduce onScreenResize() event.
sheepluva
parents: 5703
diff changeset
  3919
12454
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3920
var inComment: boolean;
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3921
var inQuote: boolean;
12459
06bf46238a89 ranges for alnum were silly. also lets not fail to same value
nemo
parents: 12458
diff changeset
  3922
var locSum: LongWord;
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3923
var braceCount: LongWord;
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3924
var wordCount: LongWord;
12454
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3925
var lastChar: char;
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3926
function  ScriptReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; Cdecl;
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3927
var mybuf: PChar;
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3928
    i: LongInt;
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3929
begin
13863
35ba3a550cad Backed out changeset 5f6208031658 (fixes 652)
Wuzzy <Wuzzy2@mail.ru>
parents: 13857
diff changeset
  3930
    SetRandomSeed(cSeed,true);
12454
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3931
    mybuf := physfsReader(L, f, sz);
12596
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3932
    if (mybuf <> nil) and ((sz^) > 0) then
12454
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3933
        begin
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3934
            for i:= 0 to sz^-1 do
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3935
                begin
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3936
                    if (lastChar = '-') and (mybuf[i] = '-') then
14237
3d4a5a10d2cd lua comment handling is seriously WTF, but let's at least allow some partial single line
nemo
parents: 14188
diff changeset
  3937
                        inComment := true
12454
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3938
                    else if not inComment and (byte(mybuf[i]) > $20) and (byte(mybuf[i]) < $7F) and (mybuf[i]<>'-') then
12494
1b483882b60f mix it up some more. also had screwed up -- inside quotes
nemo
parents: 12493
diff changeset
  3939
                        begin
1b483882b60f mix it up some more. also had screwed up -- inside quotes
nemo
parents: 12493
diff changeset
  3940
                        AddRandomness(byte(mybuf[i]));  // wish I had the seed...
1b483882b60f mix it up some more. also had screwed up -- inside quotes
nemo
parents: 12493
diff changeset
  3941
                        CheckSum := CheckSum xor GetRandom($FFFFFFFF);
1b483882b60f mix it up some more. also had screwed up -- inside quotes
nemo
parents: 12493
diff changeset
  3942
                        end;
12454
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3943
                    lastChar := mybuf[i];
14237
3d4a5a10d2cd lua comment handling is seriously WTF, but let's at least allow some partial single line
nemo
parents: 14188
diff changeset
  3944
                    // lua apparently allows --  [===============[  as a valid block comment start.  
3d4a5a10d2cd lua comment handling is seriously WTF, but let's at least allow some partial single line
nemo
parents: 14188
diff changeset
  3945
                    // I can't be bothered to check for that nonsense. Will allow limited single line without [
14238
nemo
parents: 14237
diff changeset
  3946
                    if (byte(mybuf[i]) = $0D) or (byte(mybuf[i]) = $0A) or (mybuf[i] = '[') then
12596
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3947
                        inComment := false
12454
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3948
                end;
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3949
        end;
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3950
    ScriptReader:= mybuf
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3951
end;
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3952
function  ScriptLocaleReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; Cdecl;
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3953
var mybuf: PChar;
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3954
    i: LongInt;
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3955
begin
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3956
    mybuf := physfsReader(L, f, sz);
12596
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3957
    if (mybuf <> nil) and ((sz^) > 0) then
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3958
        begin
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3959
            for i:= 0 to sz^-1 do
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3960
                begin
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3961
                    if not inComment and (mybuf[i] = '"') and (lastChar <> '\') then
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3962
                        inQuote := not inQuote;
12494
1b483882b60f mix it up some more. also had screwed up -- inside quotes
nemo
parents: 12493
diff changeset
  3963
                    if not inQuote and (lastChar = '-') and (mybuf[i] = '-') then
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3964
                        inComment := true;
12596
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3965
                    if not inComment and (not inQuote) then
12459
06bf46238a89 ranges for alnum were silly. also lets not fail to same value
nemo
parents: 12458
diff changeset
  3966
                       locSum := locSum xor (byte(mybuf[i]) shl (i mod 4));
12596
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3967
                    if not inComment and (not inQuote) and
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3968
                        ((mybuf[i] = '(') or
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3969
                        (mybuf[i] = ')') or
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3970
                        (mybuf[i] = '+') or
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3971
                        (mybuf[i] = '#') or
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3972
                        (braceCount > 2) or
12596
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3973
                        (wordCount > 6)) then
12459
06bf46238a89 ranges for alnum were silly. also lets not fail to same value
nemo
parents: 12458
diff changeset
  3974
                       CheckSum := locSum;
12596
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3975
                    if not inComment and (not inQuote) and ((mybuf[i] = '{') or (mybuf[i] = '}')) then
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3976
                        inc(braceCount);
12596
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3977
                    if not inComment and (not inQuote) and
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3978
                        (((byte(mybuf[i]) > $40) and (byte(mybuf[i]) < $5B)) or
12459
06bf46238a89 ranges for alnum were silly. also lets not fail to same value
nemo
parents: 12458
diff changeset
  3979
                        ((byte(mybuf[i]) > $60) and (byte(mybuf[i]) < $7B)) or
06bf46238a89 ranges for alnum were silly. also lets not fail to same value
nemo
parents: 12458
diff changeset
  3980
                        ((byte(mybuf[i]) >= $30) and (byte(mybuf[i]) < $3A))) then
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3981
                        inc(wordCount);
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3982
                    lastChar := mybuf[i];
14237
3d4a5a10d2cd lua comment handling is seriously WTF, but let's at least allow some partial single line
nemo
parents: 14188
diff changeset
  3983
                    // this allows at least supporting the commented strings at end of line with lua script names
14238
nemo
parents: 14237
diff changeset
  3984
                    if (byte(mybuf[i]) = $0D) or (byte(mybuf[i]) = $0A) or (mybuf[i] = '[') then
12596
c9711561f947 fix some things that annoy pas2c and whitespaces
sheepluva
parents: 12576
diff changeset
  3985
                        inComment := false
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3986
                end;
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3987
        end;
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3988
    ScriptLocaleReader:= mybuf
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3989
end;
12454
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3990
13728
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  3991
function ScriptLoad(name : shortstring; mustExist : boolean): 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
  3992
var ret : LongInt;
5243
f2e31a7f953a check alternate script loading path
nemo
parents: 5238
diff changeset
  3993
      s : shortstring;
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  3994
      f : PFSFile;
8034
fc032c0f7b23 Implement reader in C ffs
unc0rr
parents: 8031
diff changeset
  3995
    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
  3996
begin
12454
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3997
inComment:= false;
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  3998
inQuote:= false;
12454
a675a94b5cc1 Totally untested. Trying to ensure scripts loaded more or less match.
nemo
parents: 12371
diff changeset
  3999
lastChar:= 'X';
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  4000
braceCount:= 0;
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  4001
wordCount:= 0;
12459
06bf46238a89 ranges for alnum were silly. also lets not fail to same value
nemo
parents: 12458
diff changeset
  4002
locSum:= 0;
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  4003
s:= cPathz[ptData] + name;
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  4004
if not pfsExists(s) then
9531
7fcdedc45589 Unbreak access to Data dir in profile broken in r8b48c27201af
unc0rr
parents: 9409
diff changeset
  4005
    begin
13723
61095cb5f58a Critical error if loading a script has failed
Wuzzy <Wuzzy2@mail.ru>
parents: 13674
diff changeset
  4006
    if mustExist then
61095cb5f58a Critical error if loading a script has failed
Wuzzy <Wuzzy2@mail.ru>
parents: 13674
diff changeset
  4007
        OutError('Script not found: ' + name, true)
61095cb5f58a Critical error if loading a script has failed
Wuzzy <Wuzzy2@mail.ru>
parents: 13674
diff changeset
  4008
    else
61095cb5f58a Critical error if loading a script has failed
Wuzzy <Wuzzy2@mail.ru>
parents: 13674
diff changeset
  4009
        AddFileLog('[LUA] Script not found: ' + name);
13728
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  4010
    ScriptLoad:= false;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6578
diff changeset
  4011
    exit;
9531
7fcdedc45589 Unbreak access to Data dir in profile broken in r8b48c27201af
unc0rr
parents: 9409
diff changeset
  4012
    end;
6088
47d1b04003d1 - Frontend: don't pass /script for missions
unc0rr
parents: 6046
diff changeset
  4013
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  4014
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
  4015
if f = nil then
13723
61095cb5f58a Critical error if loading a script has failed
Wuzzy <Wuzzy2@mail.ru>
parents: 13674
diff changeset
  4016
    OutError('Error reading script: ' + name, true);
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  4017
13393
ae5d6448c5be Make wrapping a lua and its sidecar actually work.
nemo
parents: 13340
diff changeset
  4018
hedgewarsMountPackage(Str2PChar(copy(s, 3, length(s)-6)+'.hwp'));
12316
d09eba2e1dd8 Move sidecar lua load to prior to script load. This should let the script use it for dependencies.
nemo
parents: 12301
diff changeset
  4019
8073
5a289ef40fdb physfs compilation on windows
koda
parents: 8063
diff changeset
  4020
physfsReaderSetBuffer(@buf);
13824
552f0d5ab3e7 use locale rules for the challenge hashes
nemo
parents: 13812
diff changeset
  4021
if (Pos('Locale/',s) <> 0) or (s = 'Scripts/OfficialChallengeHashes.lua') then
12457
19e7838bedad Try to prevent the script safety checking from totally screwing up localisation. Also untested.
nemo
parents: 12455
diff changeset
  4022
     ret:= lua_load(luaState, @ScriptLocaleReader, f, Str2PChar(s))
13349
40742f3f7dd9 Seed reset seems fine when moved out of the loader. Also bump protocol
nemo
parents: 13348
diff changeset
  4023
else
14237
3d4a5a10d2cd lua comment handling is seriously WTF, but let's at least allow some partial single line
nemo
parents: 14188
diff changeset
  4024
    begin
13349
40742f3f7dd9 Seed reset seems fine when moved out of the loader. Also bump protocol
nemo
parents: 13348
diff changeset
  4025
    SetRandomSeed(cSeed,true);
14237
3d4a5a10d2cd lua comment handling is seriously WTF, but let's at least allow some partial single line
nemo
parents: 14188
diff changeset
  4026
    ret:= lua_load(luaState, @ScriptReader, f, Str2PChar(s))
3d4a5a10d2cd lua comment handling is seriously WTF, but let's at least allow some partial single line
nemo
parents: 14188
diff changeset
  4027
    end;
8031
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  4028
pfsClose(f);
fc40b343c45c Script loading via physfs which doesn't work:
unc0rr
parents: 8025
diff changeset
  4029
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
  4030
if ret <> 0 then
3774
af0e68ca273e Engine:
smaxx
parents: 3761
diff changeset
  4031
    begin
10312
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
  4032
    LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
  4033
    LuaError(lua_tostring(luaState, -1));
13728
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  4034
    ScriptLoad:= false;
3774
af0e68ca273e Engine:
smaxx
parents: 3761
diff changeset
  4035
    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
  4036
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
  4037
    begin
3539
c3d1fccbe0ed General:
smaxx
parents: 3407
diff changeset
  4038
    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
  4039
    // 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
  4040
    lua_pcall(luaState, 0, 0, 0);
13728
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  4041
    ScriptLoaded:= true;
247d1bcf3c5e Add 2nd optional parameter to HedgewarsScriptLoad. If false, its OK if file does not exist. Also, return true/false on success
Wuzzy <Wuzzy2@mail.ru>
parents: 13727
diff changeset
  4042
    ScriptLoad:= 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
  4043
    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
  4044
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
  4045
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4046
procedure SetGlobals;
13216
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4047
var x, y: 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
  4048
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
  4049
ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
12576
1fb961480b3c Lua API: Add ReadyTimeLeft variable
Wuzzy <almikes@aol.com>
parents: 12536
diff changeset
  4050
ScriptSetInteger('ReadyTimeLeft', ReadyTimeLeft);
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  4051
ScriptSetInteger('GameTime', GameTicks);
13651
56a925256039 Add separate TotalRounds var for Lua to count the *actual* number of rounds that have been played
Wuzzy <Wuzzy2@mail.ru>
parents: 13642
diff changeset
  4052
ScriptSetInteger('TotalRounds', TotalRoundsReal);
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
  4053
ScriptSetInteger('WaterLine', cWaterLine);
10978
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
  4054
if isCursorVisible and (not bShowAmmoMenu) then
10989
0ea100eefae7 ambiguous
nemo
parents: 10978
diff changeset
  4055
    begin
13216
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4056
    x:= CursorPoint.X - WorldDx;
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4057
    y:= cScreenHeight - CursorPoint.Y - WorldDy;
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4058
    if (PrevCursorX <> x) or
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4059
       (PrevCursorY <> y) then
10978
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
  4060
        begin
13216
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4061
        ScriptSetInteger('CursorX', x);
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4062
        ScriptSetInteger('CursorY', y);
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4063
        PrevCursorX:= x;
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4064
        PrevCursorY:= y;
10978
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
  4065
        end
10989
0ea100eefae7 ambiguous
nemo
parents: 10978
diff changeset
  4066
    end
10978
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
  4067
else
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
  4068
    begin
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
  4069
    ScriptSetInteger('CursorX', NoPointX);
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
  4070
    ScriptSetInteger('CursorY', NoPointX);
13216
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4071
    PrevCursorX:= NoPointX;
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4072
    PrevCursorY:= NoPointX
10978
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
  4073
    end;
54a49174dbec cursor x/y when targeting for mikade's visual effects. this is not synced
nemo
parents: 10903
diff changeset
  4074
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
  4075
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
  4076
    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
  4077
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
  4078
    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
  4079
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
  4080
13754
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13752
diff changeset
  4081
procedure ScriptSetMapGlobals;
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13752
diff changeset
  4082
begin
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13752
diff changeset
  4083
ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13752
diff changeset
  4084
ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT);
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13752
diff changeset
  4085
ScriptSetInteger('LeftX', leftX);
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13752
diff changeset
  4086
ScriptSetInteger('RightX', rightX);
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13752
diff changeset
  4087
ScriptSetInteger('TopY', topY);
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13752
diff changeset
  4088
end;
f1c66a34f2fe Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
Wuzzy <Wuzzy2@mail.ru>
parents: 13752
diff changeset
  4089
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
  4090
procedure GetGlobals;
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4091
var currentTTL, currentRTL, newTTL, newRTL: 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
  4092
begin
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4093
// Setting TurnTimeLeft and ReadyTimeLeft should now be done in the setter functions.
13741
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  4094
// SetTurnTimeLeft and SetReadTimeLeft.
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  4095
// GetGloals should be removed in a future release.
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4096
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4097
// DEPRECATED: Read TurnTimeLeft and ReadyTimeLeft from script directly.
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4098
// TODO: Remove this behaviour in a future version.
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4099
currentTTL:= TurnTimeLeft;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4100
currentRTL:= ReadyTimeLeft;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4101
newTTL:= ScriptGetInteger('TurnTimeLeft');
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4102
newRTL:= ScriptGetInteger('ReadyTimeLeft');
13766
c46998ecd8fa Don't write TurnTimeLeft deprecation warning if setter function was used
Wuzzy <Wuzzy2@mail.ru>
parents: 13754
diff changeset
  4103
if (currentTTL <> newTTL) and (not isPendingTurnTimeLeft) then
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4104
    begin
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4105
    TurnTimeLeft:= newTTL;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4106
    LuaWarning('Writing to TurnTimeLeft directly is deprecated! Use SetTurnTimeLeft instead!');
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4107
    end;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4108
13766
c46998ecd8fa Don't write TurnTimeLeft deprecation warning if setter function was used
Wuzzy <Wuzzy2@mail.ru>
parents: 13754
diff changeset
  4109
if (currentRTL <> newRTL) and (not isPendingReadyTimeLeft) then
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4110
    begin
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4111
    ReadyTimeLeft:= newRTL;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4112
    LuaWarning('Writing to ReadyTimeLeft directly is deprecated! Use SetReadyTimeLeft instead!');
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4113
    end;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4114
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4115
// Set TurnTimeLeft and ReadyTimeLeft if activated by SetTurnTimeLeft and SetReadyTimeLeft before
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4116
if isPendingTurnTimeLeft then
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4117
    begin
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4118
    TurnTimeLeft:= PendingTurnTimeLeft;
13835
0beff00d223a Set script globals TurnTimeLeft and ReadyTimeLeft immediately after they were changed by Lua call
Wuzzy <Wuzzy2@mail.ru>
parents: 13824
diff changeset
  4119
    ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4120
    isPendingTurnTimeLeft:= false;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4121
    end;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4122
if isPendingReadyTimeLeft then
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4123
    begin
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4124
    ReadyTimeLeft:= PendingReadyTimeLeft;
13835
0beff00d223a Set script globals TurnTimeLeft and ReadyTimeLeft immediately after they were changed by Lua call
Wuzzy <Wuzzy2@mail.ru>
parents: 13824
diff changeset
  4125
    ScriptSetInteger('ReadyTimeLeft', ReadyTimeLeft);
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4126
    isPendingReadyTimeLeft:= false;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4127
    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
  4128
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
  4129
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4130
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
  4131
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 8012
diff changeset
  4132
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
  4133
    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
  4134
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
  4135
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
  4136
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
  4137
    begin
10312
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
  4138
    LuaError('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
  4139
    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
  4140
    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
  4141
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
  4142
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
  4143
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  4144
(*
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
  4145
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
  4146
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
  4147
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
  4148
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
  4149
    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
  4150
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
  4151
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
  4152
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
  4153
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
  4154
    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
  4155
    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
  4156
    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
  4157
    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
  4158
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
  4159
    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
  4160
    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
  4161
    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
  4162
    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
  4163
end;
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  4164
*)
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
  4165
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
  4166
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
  4167
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
  4168
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
  4169
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
  4170
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4171
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
  4172
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
  4173
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
  4174
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
  4175
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4176
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
  4177
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
  4178
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
  4179
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
  4180
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4181
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
  4182
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 8012
diff changeset
  4183
if (not ScriptLoaded) or (not ScriptExists(fname)) then
10560
9f09196d92a6 fix some pas2c related issues
sheepluva
parents: 10553
diff changeset
  4184
    exit(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
  4185
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
  4186
lua_getglobal(luaState, Str2PChar(fname));
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  4187
lua_pushnumber(luaState, par1);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  4188
lua_pushnumber(luaState, par2);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  4189
lua_pushnumber(luaState, par3);
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  4190
lua_pushnumber(luaState, par4);
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
  4191
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
  4192
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
  4193
    begin
10312
eda8d563f677 various tweaks
sheepluva
parents: 10306
diff changeset
  4194
    LuaError('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
  4195
    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
  4196
    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
  4197
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
  4198
    begin
12294
0deabf747b8f For testing purposes, drop tointeger and pushint since Lua uses ptrdiff causing inconsistent behaviour if we try to get a longword value from tointeger on 64 bit vs 32bit. This should improve script reliability a bit
nemo
parents: 12286
diff changeset
  4199
    ScriptCall:= Trunc(lua_tonumber(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
  4200
    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
  4201
    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
  4202
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
  4203
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
  4204
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4205
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
  4206
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
  4207
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
  4208
    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
  4209
    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
  4210
    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
  4211
    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
  4212
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
  4213
ScriptExists:= not lua_isnoneornil(luaState, -1);
12107
0695302f3f5f Fix ScriptExists() destroying lua stack (fixes Bug #146)
sheepluva
parents: 12090
diff changeset
  4214
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
  4215
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
  4216
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4217
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
  4218
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
  4219
begin
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4220
ScriptAmmoLoadout:= '';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4221
ScriptAmmoDelay:= '';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4222
ScriptAmmoProbability:= '';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4223
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
  4224
for i:=1 to ord(High(TAmmoType)) do
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4225
    begin
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4226
    ScriptAmmoLoadout:= ScriptAmmoLoadout + '0';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4227
    ScriptAmmoProbability:= ScriptAmmoProbability + '0';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4228
    ScriptAmmoDelay:= ScriptAmmoDelay + '0';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4229
    ScriptAmmoReinforcement:= ScriptAmmoReinforcement + '0';
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4230
    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
  4231
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
  4232
9750
8963312df207 fix misspelled variable name (cosmetic change)
sheepluva
parents: 9748
diff changeset
  4233
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
  4234
begin
9750
8963312df207 fix misspelled variable name (cosmetic change)
sheepluva
parents: 9748
diff changeset
  4235
//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
  4236
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
  4237
    exit;
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4238
ScriptAmmoLoadout[ord(ammo)]:= inttostr(count)[1];
9750
8963312df207 fix misspelled variable name (cosmetic change)
sheepluva
parents: 9748
diff changeset
  4239
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
  4240
ScriptSetAmmoDelay(ammo, delay);
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3337
diff changeset
  4241
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
  4242
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
  4243
14640
03033213e800 Lua: Fix SetAmmoDelay not working properly when called after initialization
Wuzzy <Wuzzy2@mail.ru>
parents: 14639
diff changeset
  4244
procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: LongWord);
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
  4245
begin
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  4246
// change loadout string if ammo store has not been initialized yet
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
  4247
if (StoreCnt = 0) then
14640
03033213e800 Lua: Fix SetAmmoDelay not working properly when called after initialization
Wuzzy <Wuzzy2@mail.ru>
parents: 14639
diff changeset
  4248
    begin
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
  4249
    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
  4250
        ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1];
14640
03033213e800 Lua: Fix SetAmmoDelay not working properly when called after initialization
Wuzzy <Wuzzy2@mail.ru>
parents: 14639
diff changeset
  4251
    end
11677
6a1170def888 uscript cosmetics
koda
parents: 11617
diff changeset
  4252
// change 'live' delay values
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
  4253
else if (CurrentTeam <> nil) then
14640
03033213e800 Lua: Fix SetAmmoDelay not working properly when called after initialization
Wuzzy <Wuzzy2@mail.ru>
parents: 14639
diff changeset
  4254
    begin
03033213e800 Lua: Fix SetAmmoDelay not working properly when called after initialization
Wuzzy <Wuzzy2@mail.ru>
parents: 14639
diff changeset
  4255
    ammoz[ammo].SkipTurns:= CurrentTeam^.Clan^.TurnNumber + delay;
03033213e800 Lua: Fix SetAmmoDelay not working properly when called after initialization
Wuzzy <Wuzzy2@mail.ru>
parents: 14639
diff changeset
  4256
    if ammoz[ammo].SkipTurns > 0 then
03033213e800 Lua: Fix SetAmmoDelay not working properly when called after initialization
Wuzzy <Wuzzy2@mail.ru>
parents: 14639
diff changeset
  4257
        dec(ammoz[ammo].SkipTurns);
03033213e800 Lua: Fix SetAmmoDelay not working properly when called after initialization
Wuzzy <Wuzzy2@mail.ru>
parents: 14639
diff changeset
  4258
    AmmoMenuInvalidated:= true;
03033213e800 Lua: Fix SetAmmoDelay not working properly when called after initialization
Wuzzy <Wuzzy2@mail.ru>
parents: 14639
diff changeset
  4259
    end;
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
  4260
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
  4261
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
  4262
procedure ScriptApplyAmmoStore;
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  4263
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
  4264
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
  4265
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
  4266
    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
  4267
        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
  4268
        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
  4269
            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
  4270
            ScriptPrepareAmmoStore;
6746
nemo
parents: 6743
diff changeset
  4271
            ScriptCall('onNewAmmoStore',i,-1);
nemo
parents: 6743
diff changeset
  4272
            SetAmmoLoadout(ScriptAmmoLoadout);
nemo
parents: 6743
diff changeset
  4273
            SetAmmoProbability(ScriptAmmoProbability);
nemo
parents: 6743
diff changeset
  4274
            SetAmmoDelay(ScriptAmmoDelay);
nemo
parents: 6743
diff changeset
  4275
            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
  4276
            end;
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  4277
        AddAmmoStore;
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  4278
        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
  4279
            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
  4280
                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
  4281
        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
  4282
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
  4283
    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
  4284
        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
  4285
            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
  4286
            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
  4287
                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
  4288
                ScriptPrepareAmmoStore;
6746
nemo
parents: 6743
diff changeset
  4289
                ScriptCall('onNewAmmoStore',i,j);
nemo
parents: 6743
diff changeset
  4290
                SetAmmoLoadout(ScriptAmmoLoadout);
nemo
parents: 6743
diff changeset
  4291
                SetAmmoProbability(ScriptAmmoProbability);
nemo
parents: 6743
diff changeset
  4292
                SetAmmoDelay(ScriptAmmoDelay);
nemo
parents: 6743
diff changeset
  4293
                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
  4294
                end;
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  4295
            AddAmmoStore;
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  4296
            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
  4297
            end
9752
656c511ab0f3 here have some lua love: make parameter count error messages more helpful to lua devs
sheepluva
parents: 9751
diff changeset
  4298
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
  4299
    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
  4300
        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
  4301
        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
  4302
            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
  4303
            ScriptPrepareAmmoStore;
6746
nemo
parents: 6743
diff changeset
  4304
            ScriptCall('onNewAmmoStore',i,-1);
nemo
parents: 6743
diff changeset
  4305
            SetAmmoLoadout(ScriptAmmoLoadout);
nemo
parents: 6743
diff changeset
  4306
            SetAmmoProbability(ScriptAmmoProbability);
nemo
parents: 6743
diff changeset
  4307
            SetAmmoDelay(ScriptAmmoDelay);
nemo
parents: 6743
diff changeset
  4308
            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
  4309
            end;
6563
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  4310
        AddAmmoStore;
30e042398411 Assign ammo counts as well, in case the game flags were changed by the script
nemo
parents: 6557
diff changeset
  4311
        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
  4312
            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
  4313
        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
  4314
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
  4315
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4316
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
  4317
var at : TGearType;
4453
15a483b2558a add visual gear registration
nemo
parents: 4450
diff changeset
  4318
    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
  4319
    am : TAmmoType;
9642
8a691e0f117a use consts for TStatInfo enum
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9291
diff changeset
  4320
    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
  4321
    st : TSound;
5118
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
  4322
    he : THogEffect;
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
  4323
    cg : TCapGroup;
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  4324
    spr: TSprite;
10603
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
  4325
    mg : TMapGen;
11879
c6eafb6f2735 Add WorldEdge to Lua API to expose/change world edge type
Wuzzy <almikes@aol.com>
parents: 11849
diff changeset
  4326
    we : TWorldEdge;
15998
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
  4327
    msi: TMsgStrId;
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
  4328
    gsi: TGoalStrId;
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
  4329
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
  4330
// initialize lua
10239
ed8bab6e92ba rolling back the rest
sheepluva
parents: 10230
diff changeset
  4331
luaState:= lua_open;
11532
bf86c6cb9341 Bye-bye TryDo
unc0rr
parents: 11520
diff changeset
  4332
if checkFails(luaState <> nil, 'lua_open failed', true) then exit;
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
  4333
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4334
// open internal libraries
10239
ed8bab6e92ba rolling back the rest
sheepluva
parents: 10230
diff changeset
  4335
luaopen_base(luaState);
ed8bab6e92ba rolling back the rest
sheepluva
parents: 10230
diff changeset
  4336
luaopen_string(luaState);
ed8bab6e92ba rolling back the rest
sheepluva
parents: 10230
diff changeset
  4337
luaopen_math(luaState);
ed8bab6e92ba rolling back the rest
sheepluva
parents: 10230
diff changeset
  4338
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
  4339
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4340
// import some variables
14619
62dea281e4d5 Refactor hwengine: Rename cLocale to cLanguage
Wuzzy <Wuzzy2@mail.ru>
parents: 14558
diff changeset
  4341
ScriptSetString(_S'LOCALE', cLanguage);
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
  4342
14318
a6c5ce147530 Lua API: Change PLATFORM to INTERFACE
Wuzzy <Wuzzy2@mail.ru>
parents: 14309
diff changeset
  4343
{$IFDEF USE_TOUCH_INTERFACE}
a6c5ce147530 Lua API: Change PLATFORM to INTERFACE
Wuzzy <Wuzzy2@mail.ru>
parents: 14309
diff changeset
  4344
ScriptSetString(_S'INTERFACE', 'touch');
13954
429945a9b8db Lua: Add PLATFORM global var to distinguish between desktop and mobile builds
Wuzzy <Wuzzy2@mail.ru>
parents: 13897
diff changeset
  4345
{$ELSE}
14318
a6c5ce147530 Lua API: Change PLATFORM to INTERFACE
Wuzzy <Wuzzy2@mail.ru>
parents: 14309
diff changeset
  4346
ScriptSetString(_S'INTERFACE', 'desktop');
13954
429945a9b8db Lua: Add PLATFORM global var to distinguish between desktop and mobile builds
Wuzzy <Wuzzy2@mail.ru>
parents: 13897
diff changeset
  4347
{$ENDIF}
429945a9b8db Lua: Add PLATFORM global var to distinguish between desktop and mobile builds
Wuzzy <Wuzzy2@mail.ru>
parents: 13897
diff changeset
  4348
13872
f01798038c2e Rename amDuck and related symbols to amCreeper, gtCreeper, etc.
Wuzzy <Wuzzy2@mail.ru>
parents: 13863
diff changeset
  4349
// Add aliases for amDuck and gtDuck because rubber duck was removed.
f01798038c2e Rename amDuck and related symbols to amCreeper, gtCreeper, etc.
Wuzzy <Wuzzy2@mail.ru>
parents: 13863
diff changeset
  4350
// amDuck and gtDuck are deprecated and should be removed later.
f01798038c2e Rename amDuck and related symbols to amCreeper, gtCreeper, etc.
Wuzzy <Wuzzy2@mail.ru>
parents: 13863
diff changeset
  4351
// TODO: Remove these aliases in a later version.
f01798038c2e Rename amDuck and related symbols to amCreeper, gtCreeper, etc.
Wuzzy <Wuzzy2@mail.ru>
parents: 13863
diff changeset
  4352
ScriptSetInteger('amDuck', Ord(amCreeper));
f01798038c2e Rename amDuck and related symbols to amCreeper, gtCreeper, etc.
Wuzzy <Wuzzy2@mail.ru>
parents: 13863
diff changeset
  4353
ScriptSetInteger('gtDuck', Ord(gtCreeper));
f01798038c2e Rename amDuck and related symbols to amCreeper, gtCreeper, etc.
Wuzzy <Wuzzy2@mail.ru>
parents: 13863
diff changeset
  4354
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
  4355
// import game flags
13272
5984e8c6cbeb Add new game flag gfSwitchHog, enable hog switching at turn start
Wuzzy <Wuzzy2@mail.ru>
parents: 13270
diff changeset
  4356
ScriptSetInteger('gfSwitchHog', gfSwitchHog);
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
  4357
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
  4358
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
  4359
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
  4360
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
  4361
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
  4362
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
  4363
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
  4364
ScriptSetInteger('gfInvulnerable', gfInvulnerable);
10671
17dd6265a08a Issue 865: gfResetHealth is not exposed to Lua
sheepluva
parents: 10660
diff changeset
  4365
ScriptSetInteger('gfResetHealth', gfResetHealth);
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
  4366
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
  4367
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
  4368
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
  4369
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
  4370
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
  4371
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
  4372
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
  4373
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
  4374
ScriptSetInteger('gfDisableGirders', gfDisableGirders);
4162
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  4375
ScriptSetInteger('gfDisableLandObjects', gfDisableLandObjects);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  4376
ScriptSetInteger('gfAISurvival', gfAISurvival);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  4377
ScriptSetInteger('gfInfAttack', gfInfAttack);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  4378
ScriptSetInteger('gfResetWeps', gfResetWeps);
923db448ad16 update and fix some lua stuff
Henek
parents: 4003
diff changeset
  4379
ScriptSetInteger('gfPerHogAmmo', gfPerHogAmmo);
4219
4162db7c11bb fix so gfDisableWind can infact be used in lua
Henek
parents: 4162
diff changeset
  4380
ScriptSetInteger('gfDisableWind', gfDisableWind);
4319
81391b54b078 clean up and lua update, very minor
Henek
parents: 4243
diff changeset
  4381
ScriptSetInteger('gfMoreWind', gfMoreWind);
5016
9347d82a26cc added game mode Tag Team, mostly untested, please test :)
Henek
parents: 5013
diff changeset
  4382
ScriptSetInteger('gfTagTeam', gfTagTeam);
9387
6478ed9ead25 gfShoppaBorder
unc0rr
parents: 9291
diff changeset
  4383
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
  4384
3894
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4385
ScriptSetInteger('gmLeft', gmLeft);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4386
ScriptSetInteger('gmRight', gmRight);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4387
ScriptSetInteger('gmUp', gmUp);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4388
ScriptSetInteger('gmDown', gmDown);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4389
ScriptSetInteger('gmSwitch', gmSwitch);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4390
ScriptSetInteger('gmAttack', gmAttack);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4391
ScriptSetInteger('gmLJump', gmLJump);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4392
ScriptSetInteger('gmHJump', gmHJump);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4393
ScriptSetInteger('gmDestroy', gmDestroy);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4394
ScriptSetInteger('gmSlot', gmSlot);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4395
ScriptSetInteger('gmWeapon', gmWeapon);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4396
ScriptSetInteger('gmTimer', gmTimer);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4397
ScriptSetInteger('gmAnimate', gmAnimate);
9abce5468583 Engine:
smaxx
parents: 3892
diff changeset
  4398
ScriptSetInteger('gmPrecise', gmPrecise);
3892
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  4399
ScriptSetInteger('gmAllStoppable', gmAllStoppable);
60d9709f2d8e Engine:
smaxx
parents: 3848
diff changeset
  4400
3761
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  4401
// speech bubbles
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  4402
ScriptSetInteger('SAY_SAY', 1);
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  4403
ScriptSetInteger('SAY_THINK', 2);
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  4404
ScriptSetInteger('SAY_SHOUT', 3);
f96b99f944e6 Engine:
smaxx
parents: 3756
diff changeset
  4405
13593
083733ec7941 Add support for infinite fly time of jetpack and Birdy
Wuzzy <Wuzzy2@mail.ru>
parents: 13582
diff changeset
  4406
// other
13595
0adc82afb784 Add Lua globals: AMMO_INFINITE and NoPointX
Wuzzy <Wuzzy2@mail.ru>
parents: 13593
diff changeset
  4407
ScriptSetInteger('AMMO_INFINITE', AMMO_INFINITE);
13593
083733ec7941 Add support for infinite fly time of jetpack and Birdy
Wuzzy <Wuzzy2@mail.ru>
parents: 13582
diff changeset
  4408
ScriptSetInteger('JETPACK_FUEL_INFINITE', JETPACK_FUEL_INFINITE);
083733ec7941 Add support for infinite fly time of jetpack and Birdy
Wuzzy <Wuzzy2@mail.ru>
parents: 13582
diff changeset
  4409
ScriptSetInteger('BIRDY_ENERGY_INFINITE', BIRDY_ENERGY_INFINITE);
13752
110d6c1e817f Lua: Rename globals: NoPointX→NO_CURSOR, cMaxTurnTime→MAX_TURN_TIME, cMaxHogHealth→MAX_HOG_HEALTH
Wuzzy <Wuzzy2@mail.ru>
parents: 13747
diff changeset
  4410
ScriptSetInteger('NO_CURSOR', NoPointX);
110d6c1e817f Lua: Rename globals: NoPointX→NO_CURSOR, cMaxTurnTime→MAX_TURN_TIME, cMaxHogHealth→MAX_HOG_HEALTH
Wuzzy <Wuzzy2@mail.ru>
parents: 13747
diff changeset
  4411
ScriptSetInteger('MAX_HOG_HEALTH', cMaxHogHealth);
110d6c1e817f Lua: Rename globals: NoPointX→NO_CURSOR, cMaxTurnTime→MAX_TURN_TIME, cMaxHogHealth→MAX_HOG_HEALTH
Wuzzy <Wuzzy2@mail.ru>
parents: 13747
diff changeset
  4412
ScriptSetInteger('MAX_TURN_TIME', cMaxTurnTime);
13593
083733ec7941 Add support for infinite fly time of jetpack and Birdy
Wuzzy <Wuzzy2@mail.ru>
parents: 13582
diff changeset
  4413
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
  4414
// 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
  4415
for at:= Low(TGearType) to High(TGearType) do
3337
75e7455c69ed Engine:
smxx
parents: 3271
diff changeset
  4416
    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
  4417
4453
15a483b2558a add visual gear registration
nemo
parents: 4450
diff changeset
  4418
for vgt:= Low(TVisualGearType) to High(TVisualGearType) do
15a483b2558a add visual gear registration
nemo
parents: 4450
diff changeset
  4419
    ScriptSetInteger(EnumToStr(vgt), ord(vgt));
15a483b2558a add visual gear registration
nemo
parents: 4450
diff changeset
  4420
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
  4421
// 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
  4422
for st:= Low(TSound) to High(TSound) do
3337
75e7455c69ed Engine:
smxx
parents: 3271
diff changeset
  4423
    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
  4424
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4425
// 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
  4426
for am:= Low(TAmmoType) to High(TAmmoType) do
3337
75e7455c69ed Engine:
smxx
parents: 3271
diff changeset
  4427
    ScriptSetInteger(EnumToStr(am), ord(am));
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3539
diff changeset
  4428
9642
8a691e0f117a use consts for TStatInfo enum
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9291
diff changeset
  4429
for si:= Low(TStatInfoType) to High(TStatInfoType) do
8a691e0f117a use consts for TStatInfo enum
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9291
diff changeset
  4430
    ScriptSetInteger(EnumToStr(si), ord(si));
8a691e0f117a use consts for TStatInfo enum
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9291
diff changeset
  4431
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  4432
for he:= Low(THogEffect) to High(THogEffect) do
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  4433
    ScriptSetInteger(EnumToStr(he), ord(he));
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3755
diff changeset
  4434
5118
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
  4435
for cg:= Low(TCapGroup) to High(TCapGroup) do
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
  4436
    ScriptSetInteger(EnumToStr(cg), ord(cg));
9cfdb9bc6140 For mikade - bit more flexibility in script captions
nemo
parents: 5075
diff changeset
  4437
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  4438
for spr:= Low(TSprite) to High(TSprite) do
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  4439
    ScriptSetInteger(EnumToStr(spr), ord(spr));
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  4440
10603
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
  4441
for mg:= Low(TMapGen) to High(TMapGen) do
bda5c7caf396 switch mapgen to enum. should still try and make sure the values are backwards compatible if possible.
nemo
parents: 10589
diff changeset
  4442
    ScriptSetInteger(EnumToStr(mg), ord(mg));
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  4443
11879
c6eafb6f2735 Add WorldEdge to Lua API to expose/change world edge type
Wuzzy <almikes@aol.com>
parents: 11849
diff changeset
  4444
for we:= Low(TWorldEdge) to High(TWorldEdge) do
c6eafb6f2735 Add WorldEdge to Lua API to expose/change world edge type
Wuzzy <almikes@aol.com>
parents: 11849
diff changeset
  4445
    ScriptSetInteger(EnumToStr(we), ord(we));
c6eafb6f2735 Add WorldEdge to Lua API to expose/change world edge type
Wuzzy <almikes@aol.com>
parents: 11849
diff changeset
  4446
15998
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
  4447
// register message IDs
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
  4448
for msi:= Low(TMsgStrId) to High(TMsgStrId) do
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
  4449
    ScriptSetInteger(EnumToStr(msi), ord(msi));
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
  4450
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
  4451
for gsi:= Low(TGoalStrId) to High(TGoalStrId) do
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
  4452
    ScriptSetInteger(EnumToStr(gsi), ord(gsi));
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
  4453
15198
a22013a817e4 Lua: Fix incorrect values for capcolDefault, capcolSetting
Wuzzy <Wuzzy2@mail.ru>
parents: 15152
diff changeset
  4454
ScriptSetLongWord('capcolDefault'   , capcolDefaultLua);
a22013a817e4 Lua: Fix incorrect values for capcolDefault, capcolSetting
Wuzzy <Wuzzy2@mail.ru>
parents: 15152
diff changeset
  4455
ScriptSetLongWord('capcolSetting'   , capcolSettingLua);
13642
3d14950641a4 Refactor text color variable names, export 2 color values to Lua
Wuzzy <Wuzzy2@mail.ru>
parents: 13627
diff changeset
  4456
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4457
ScriptSetInteger('gstDrowning'      , gstDrowning);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4458
ScriptSetInteger('gstHHDriven'      , gstHHDriven);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4459
ScriptSetInteger('gstMoving'        , gstMoving);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4460
ScriptSetInteger('gstAttacked'      , gstAttacked);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4461
ScriptSetInteger('gstAttacking'     , gstAttacking);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4462
ScriptSetInteger('gstCollision'     , gstCollision);
11052
f55a49bd13b9 add missing state binds in lua
nemo
parents: 11046
diff changeset
  4463
ScriptSetInteger('gstChooseTarget'  , gstChooseTarget);
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4464
ScriptSetInteger('gstHHJumping'     , gstHHJumping);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4465
ScriptSetInteger('gsttmpFlag'       , gsttmpFlag);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4466
ScriptSetInteger('gstHHThinking'    , gstHHThinking);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4467
ScriptSetInteger('gstNoDamage'      , gstNoDamage);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4468
ScriptSetInteger('gstHHHJump'       , gstHHHJump);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4469
ScriptSetInteger('gstAnimation'     , gstAnimation);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4470
ScriptSetInteger('gstHHDeath'       , gstHHDeath);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4471
ScriptSetInteger('gstWinner'        , gstWinner);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4472
ScriptSetInteger('gstWait'          , gstWait);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4473
ScriptSetInteger('gstNotKickable'   , gstNotKickable);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4474
ScriptSetInteger('gstLoser'         , gstLoser);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4475
ScriptSetInteger('gstHHGone'        , gstHHGone);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4476
ScriptSetInteger('gstInvisible'     , gstInvisible);
11052
f55a49bd13b9 add missing state binds in lua
nemo
parents: 11046
diff changeset
  4477
ScriptSetInteger('gstSubmersible'   , gstSubmersible);
f55a49bd13b9 add missing state binds in lua
nemo
parents: 11046
diff changeset
  4478
ScriptSetInteger('gstFrozen'        , gstFrozen);
f55a49bd13b9 add missing state binds in lua
nemo
parents: 11046
diff changeset
  4479
ScriptSetInteger('gstNoGravity'     , gstNoGravity);
5527
418741abd209 gear state flag names for scripting
nemo
parents: 5517
diff changeset
  4480
8145
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 8077
diff changeset
  4481
// ai hints
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4482
ScriptSetInteger('aihUsualProcessing', aihUsualProcessing);
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4483
ScriptSetInteger('aihDoesntMatter'   , aihDoesntMatter);
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  4484
13037
3718637c14be Expose 5 land flags to Lua for use with SetGearCollisionMask
Wuzzy <Wuzzy2@mail.ru>
parents: 13036
diff changeset
  4485
// land flags (partial)
10283
f5573ef8cda9 expose lfIndestructable, lfIce and lfBounce
sheepluva
parents: 10282
diff changeset
  4486
ScriptSetInteger('lfIndestructible', lfIndestructible);
10421
87e47843018e use constants for mapgen, expose those to lua
sheepluva
parents: 10368
diff changeset
  4487
ScriptSetInteger('lfIce'           , lfIce);
87e47843018e use constants for mapgen, expose those to lua
sheepluva
parents: 10368
diff changeset
  4488
ScriptSetInteger('lfBouncy'        , lfBouncy);
87e47843018e use constants for mapgen, expose those to lua
sheepluva
parents: 10368
diff changeset
  4489
13037
3718637c14be Expose 5 land flags to Lua for use with SetGearCollisionMask
Wuzzy <Wuzzy2@mail.ru>
parents: 13036
diff changeset
  4490
ScriptSetInteger('lfLandMask'      , lfLandMask);
13469
f1d349a52bc7 Refactor: lfCurrentHog→lfCurHogCrate, lfNotCurrentMask→lfNotCurHogCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 13467
diff changeset
  4491
ScriptSetInteger('lfCurHogCrate'   , lfCurHogCrate);
13037
3718637c14be Expose 5 land flags to Lua for use with SetGearCollisionMask
Wuzzy <Wuzzy2@mail.ru>
parents: 13036
diff changeset
  4492
ScriptSetInteger('lfHHMask'        , lfHHMask);
3718637c14be Expose 5 land flags to Lua for use with SetGearCollisionMask
Wuzzy <Wuzzy2@mail.ru>
parents: 13036
diff changeset
  4493
ScriptSetInteger('lfNotHHObjMask'  , lfNotHHObjMask);
3718637c14be Expose 5 land flags to Lua for use with SetGearCollisionMask
Wuzzy <Wuzzy2@mail.ru>
parents: 13036
diff changeset
  4494
ScriptSetInteger('lfAllObjMask'    , lfAllObjMask);
3718637c14be Expose 5 land flags to Lua for use with SetGearCollisionMask
Wuzzy <Wuzzy2@mail.ru>
parents: 13036
diff changeset
  4495
13270
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  4496
// explosion constants
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  4497
ScriptSetInteger('EXPLAutoSound'    , EXPLAutoSound);
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  4498
ScriptSetInteger('EXPLNoDamage'     , EXPLNoDamage);
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  4499
ScriptSetInteger('EXPLDoNotTouchHH' , EXPLDoNotTouchHH);
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  4500
ScriptSetInteger('EXPLDontDraw'     , EXPLDontDraw);
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  4501
ScriptSetInteger('EXPLNoGfx'        , EXPLNoGfx);
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  4502
ScriptSetInteger('EXPLPoisoned'     , EXPLPoisoned);
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  4503
ScriptSetInteger('EXPLDoNotTouchAny', EXPLDoNotTouchAny);
13604
73b096e1d895 Fix hammer/pickhammer not digging land with gfSolidLand on
Wuzzy <Wuzzy2@mail.ru>
parents: 13597
diff changeset
  4504
ScriptSetInteger('EXPLForceDraw'    , EXPLForceDraw);
13270
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  4505
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
  4506
// register functions
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  4507
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
  4508
lua_register(luaState, _P'RestoreHog', @lc_restorehog);
13577
66460d5f0d9b Lua API: Add IsHogHidden
Wuzzy <Wuzzy2@mail.ru>
parents: 13576
diff changeset
  4509
lua_register(luaState, _P'IsHogHidden', @lc_ishoghidden);
7201
dc17ffdf0702 The first campaign commit with a lot of changes...
belphegorr <szabibibi@gmail.com>
parents: 7156
diff changeset
  4510
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
  4511
lua_register(luaState, _P'GetCampaignVar', @lc_getcampaignvar);
14484
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  4512
lua_register(luaState, _P'SaveMissionVar', @lc_savemissionvar);
bd1db668b7c0 Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents: 14415
diff changeset
  4513
lua_register(luaState, _P'GetMissionVar', @lc_getmissionvar);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4514
lua_register(luaState, _P'band', @lc_band);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4515
lua_register(luaState, _P'bor', @lc_bor);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4516
lua_register(luaState, _P'bnot', @lc_bnot);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4517
lua_register(luaState, _P'div', @lc_div);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4518
lua_register(luaState, _P'GetInputMask', @lc_getinputmask);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4519
lua_register(luaState, _P'SetInputMask', @lc_setinputmask);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4520
lua_register(luaState, _P'AddGear', @lc_addgear);
10290
42efccba0711 lua api: DismissTeam(teamname)
sheepluva
parents: 10289
diff changeset
  4521
lua_register(luaState, _P'DismissTeam', @lc_dismissteam);
8366
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
  4522
lua_register(luaState, _P'EnableGameFlags', @lc_enablegameflags);
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
  4523
lua_register(luaState, _P'DisableGameFlags', @lc_disablegameflags);
67c7ba2b82a3 lua API functions to enable or disable game flags
martin_bede
parents: 8228
diff changeset
  4524
lua_register(luaState, _P'ClearGameFlags', @lc_cleargameflags);
10035
ec523f66d0ff luaAPI:
sheepluva
parents: 10031
diff changeset
  4525
lua_register(luaState, _P'GetGameFlag', @lc_getgameflag);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4526
lua_register(luaState, _P'DeleteGear', @lc_deletegear);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4527
lua_register(luaState, _P'AddVisualGear', @lc_addvisualgear);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4528
lua_register(luaState, _P'DeleteVisualGear', @lc_deletevisualgear);
11880
2eac7a96b342 Lua API: Add GetVisualGearType, onVisualGearAdd, onVisualGearDelete
Wuzzy <almikes@aol.com>
parents: 11879
diff changeset
  4529
lua_register(luaState, _P'GetVisualGearType', @lc_getvisualgeartype);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4530
lua_register(luaState, _P'GetVisualGearValues', @lc_getvisualgearvalues);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4531
lua_register(luaState, _P'SetVisualGearValues', @lc_setvisualgearvalues);
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  4532
lua_register(luaState, _P'GetGearValues', @lc_getgearvalues);
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  4533
lua_register(luaState, _P'SetGearValues', @lc_setgearvalues);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4534
lua_register(luaState, _P'SpawnHealthCrate', @lc_spawnhealthcrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4535
lua_register(luaState, _P'SpawnAmmoCrate', @lc_spawnammocrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4536
lua_register(luaState, _P'SpawnUtilityCrate', @lc_spawnutilitycrate);
12932
e0da398805b6 Lua API: Add SpawnSupplyCrate
Wuzzy <Wuzzy2@mail.ru>
parents: 12931
diff changeset
  4537
lua_register(luaState, _P'SpawnSupplyCrate', @lc_spawnsupplycrate);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4538
lua_register(luaState, _P'SpawnFakeHealthCrate', @lc_spawnfakehealthcrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4539
lua_register(luaState, _P'SpawnFakeAmmoCrate', @lc_spawnfakeammocrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4540
lua_register(luaState, _P'SpawnFakeUtilityCrate', @lc_spawnfakeutilitycrate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4541
lua_register(luaState, _P'WriteLnToConsole', @lc_writelntoconsole);
12910
383445810e42 Lua API: Add WriteLnToChat
Wuzzy <Wuzzy2@mail.ru>
parents: 12848
diff changeset
  4542
lua_register(luaState, _P'WriteLnToChat', @lc_writelntochat);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4543
lua_register(luaState, _P'GetGearType', @lc_getgeartype);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4544
lua_register(luaState, _P'EndGame', @lc_endgame);
12286
b4dde7035fe2 New Lua call: EndTurn to end turn
Wuzzy <almikes@aol.com>
parents: 12162
diff changeset
  4545
lua_register(luaState, _P'EndTurn', @lc_endturn);
13340
85644a45e988 New Lua call: Retreat, to force turn into Retreat time
Wuzzy <Wuzzy2@mail.ru>
parents: 13272
diff changeset
  4546
lua_register(luaState, _P'Retreat', @lc_retreat);
13170
98a0edb4bb5a Lua API: Add SkipTurn() to replace ParseCommand("skip")
Wuzzy <Wuzzy2@mail.ru>
parents: 13122
diff changeset
  4547
lua_register(luaState, _P'SkipTurn', @lc_skipturn);
12536
e54039ea3934 New Lua API function: GetTeamStats, to get team stats
Wuzzy <almikes@aol.com>
parents: 12494
diff changeset
  4548
lua_register(luaState, _P'GetTeamStats', @lc_getteamstats);
9171
e72f4f37a444 added sendstat and sendstats support for lua scripts
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9080
diff changeset
  4549
lua_register(luaState, _P'SendStat', @lc_sendstat);
12332
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  4550
lua_register(luaState, _P'SendGameResultOff', @lc_sendgameresultoff);
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  4551
lua_register(luaState, _P'SendRankingStatsOff', @lc_sendrankingstatsoff);
657a8d63c99d Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
Wuzzy <almikes@aol.com>
parents: 12316
diff changeset
  4552
lua_register(luaState, _P'SendAchievementsStatsOff', @lc_sendachievementsstatsoff);
9180
d19c09670ec8 changed variable and function name
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9179
diff changeset
  4553
lua_register(luaState, _P'SendHealthStatsOff', @lc_sendhealthstatsoff);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4554
lua_register(luaState, _P'FindPlace', @lc_findplace);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4555
lua_register(luaState, _P'SetGearPosition', @lc_setgearposition);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4556
lua_register(luaState, _P'GetGearPosition', @lc_getgearposition);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4557
lua_register(luaState, _P'SetGearTarget', @lc_setgeartarget);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4558
lua_register(luaState, _P'GetGearTarget', @lc_getgeartarget);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4559
lua_register(luaState, _P'SetGearVelocity', @lc_setgearvelocity);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4560
lua_register(luaState, _P'GetGearVelocity', @lc_getgearvelocity);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4561
lua_register(luaState, _P'ParseCommand', @lc_parsecommand);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4562
lua_register(luaState, _P'ShowMission', @lc_showmission);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4563
lua_register(luaState, _P'HideMission', @lc_hidemission);
15998
91c487e7d11d Add GetEngineString function to expose some string IDs to Lua
Wuzzy <Wuzzy@disroot.org>
parents: 15980
diff changeset
  4564
lua_register(luaState, _P'GetEngineString', @lc_getenginestring);
11939
c7ec309cd685 Add Lua API function SetAmmoTexts (see issue 82)
Wuzzy <almikes@aol.com>
parents: 11880
diff changeset
  4565
lua_register(luaState, _P'SetAmmoTexts', @lc_setammotexts);
11941
7ece39a537bd Add SetAmmoDescriptionAppendix to Lua API, see issue 82
Wuzzy <almikes@aol.com>
parents: 11939
diff changeset
  4566
lua_register(luaState, _P'SetAmmoDescriptionAppendix', @lc_setammodescriptionappendix);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4567
lua_register(luaState, _P'AddCaption', @lc_addcaption);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4568
lua_register(luaState, _P'SetAmmo', @lc_setammo);
13456
794dcf69a5aa New Lua API function: GetAmmo, to get ammo config
Wuzzy <Wuzzy2@mail.ru>
parents: 13434
diff changeset
  4569
lua_register(luaState, _P'GetAmmo', @lc_getammo);
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
  4570
lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
15152
a77b0e339929 Lua API: Add SetAmmoSlot
Wuzzy <Wuzzy2@mail.ru>
parents: 15100
diff changeset
  4571
lua_register(luaState, _P'SetAmmoSlot', @lc_setammoslot);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4572
lua_register(luaState, _P'PlaySound', @lc_playsound);
13997
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  4573
lua_register(luaState, _P'PlayMusicSound', @lc_playmusicsound);
2828ec67c47c Add PlayMusicSound/StopMusicSound to Lua API
Wuzzy <Wuzzy2@mail.ru>
parents: 13975
diff changeset
  4574
lua_register(luaState, _P'StopMusicSound', @lc_stopmusicsound);
13121
de07c8423beb Lua API: Add SetSoundMask to disable playing certain sounds
Wuzzy <Wuzzy2@mail.ru>
parents: 13088
diff changeset
  4575
lua_register(luaState, _P'SetSoundMask', @lc_setsoundmask);
12931
c27dd59a3ffe Lua API: Add GetTeamName
Wuzzy <Wuzzy2@mail.ru>
parents: 12930
diff changeset
  4576
lua_register(luaState, _P'GetTeamName', @lc_getteamname);
13020
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  4577
lua_register(luaState, _P'GetTeamIndex', @lc_getteamindex);
d1e7f2420f00 Lua API: Add functons: GetTeamIndex and GetTeamClan
Wuzzy <Wuzzy2@mail.ru>
parents: 13018
diff changeset
  4578
lua_register(luaState, _P'GetTeamClan', @lc_getteamclan);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4579
lua_register(luaState, _P'AddTeam', @lc_addteam);
14498
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  4580
lua_register(luaState, _P'AddMissionTeam', @lc_addmissionteam);
13018
0248cf0da834 Add SetTeamLabel to Lua API, can set arbitrary string as team label
Wuzzy <Wuzzy2@mail.ru>
parents: 12947
diff changeset
  4581
lua_register(luaState, _P'SetTeamLabel', @lc_setteamlabel);
14632
3cf7799e04b5 Add SetTeamPassive. Passive teams are treated like frozen teams
Wuzzy <Wuzzy2@mail.ru>
parents: 14619
diff changeset
  4582
lua_register(luaState, _P'SetTeamPassive', @lc_setteampassive);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4583
lua_register(luaState, _P'AddHog', @lc_addhog);
14498
4b678aad50e9 Lua API: Add functions to add team selected in campaign/mission page
Wuzzy <Wuzzy2@mail.ru>
parents: 14484
diff changeset
  4584
lua_register(luaState, _P'AddMissionHog', @lc_addmissionhog);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4585
lua_register(luaState, _P'AddAmmo', @lc_addammo);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4586
lua_register(luaState, _P'GetAmmoCount', @lc_getammocount);
12939
0112ef349ddc Lua API: Add HealHog to heal hog with visual effects + message
Wuzzy <Wuzzy2@mail.ru>
parents: 12932
diff changeset
  4587
lua_register(luaState, _P'HealHog', @lc_healhog);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4588
lua_register(luaState, _P'SetHealth', @lc_sethealth);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4589
lua_register(luaState, _P'GetHealth', @lc_gethealth);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4590
lua_register(luaState, _P'SetEffect', @lc_seteffect);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4591
lua_register(luaState, _P'GetEffect', @lc_geteffect);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4592
lua_register(luaState, _P'GetHogClan', @lc_gethogclan);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4593
lua_register(luaState, _P'GetClanColor', @lc_getclancolor);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4594
lua_register(luaState, _P'SetClanColor', @lc_setclancolor);
11029
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  4595
lua_register(luaState, _P'GetHogVoicepack', @lc_gethogvoicepack);
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  4596
lua_register(luaState, _P'GetHogFlag', @lc_gethogflag);
12046
553f97b1e4fe Add GetHogFort to Lua API
Wuzzy <almikes@aol.com>
parents: 11963
diff changeset
  4597
lua_register(luaState, _P'GetHogFort', @lc_gethogfort);
11029
854f30498a98 GetHogVoicepack,GetHogFlag,GetHogGrave
mikade <redgrinner@gmail.com>
parents: 11022
diff changeset
  4598
lua_register(luaState, _P'GetHogGrave', @lc_gethoggrave);
15100
424e3b132dd3 Lua: Add IsHogAlive
Wuzzy <Wuzzy2@mail.ru>
parents: 15053
diff changeset
  4599
lua_register(luaState, _P'IsHogAlive', @lc_ishogalive);
11847
38e7206a5df4 Lua API: IsHogLocal(gearUid)
sheepluva
parents: 11846
diff changeset
  4600
lua_register(luaState, _P'IsHogLocal', @lc_ishoglocal);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4601
lua_register(luaState, _P'GetHogTeamName', @lc_gethogteamname);
9788
af04cfdb1684 add SetHogTeamName
cairo
parents: 9764
diff changeset
  4602
lua_register(luaState, _P'SetHogTeamName', @lc_sethogteamname);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4603
lua_register(luaState, _P'GetHogName', @lc_gethogname);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4604
lua_register(luaState, _P'SetHogName', @lc_sethogname);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4605
lua_register(luaState, _P'GetHogLevel', @lc_gethoglevel);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4606
lua_register(luaState, _P'SetHogLevel', @lc_sethoglevel);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4607
lua_register(luaState, _P'GetX', @lc_getx);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4608
lua_register(luaState, _P'GetY', @lc_gety);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4609
lua_register(luaState, _P'CopyPV', @lc_copypv);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4610
lua_register(luaState, _P'FollowGear', @lc_followgear);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4611
lua_register(luaState, _P'GetFollowGear', @lc_getfollowgear);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4612
lua_register(luaState, _P'SetState', @lc_setstate);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4613
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
  4614
lua_register(luaState, _P'GetTag', @lc_gettag);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4615
lua_register(luaState, _P'SetTag', @lc_settag);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4616
lua_register(luaState, _P'SetTimer', @lc_settimer);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4617
lua_register(luaState, _P'GetTimer', @lc_gettimer);
10589
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  4618
lua_register(luaState, _P'SetFlightTime', @lc_setflighttime);
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10581
diff changeset
  4619
lua_register(luaState, _P'GetFlightTime', @lc_getflighttime);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4620
lua_register(luaState, _P'SetZoom', @lc_setzoom);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4621
lua_register(luaState, _P'GetZoom', @lc_getzoom);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4622
lua_register(luaState, _P'HogSay', @lc_hogsay);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4623
lua_register(luaState, _P'SwitchHog', @lc_switchhog);
13378
c53530142442 Lua API: Add EnableSwitchHog to manually enable hog switching
Wuzzy <Wuzzy2@mail.ru>
parents: 13373
diff changeset
  4624
lua_register(luaState, _P'EnableSwitchHog', @lc_enableswitchhog);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4625
lua_register(luaState, _P'HogTurnLeft', @lc_hogturnleft);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4626
lua_register(luaState, _P'GetGearElasticity', @lc_getgearelasticity);
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  4627
lua_register(luaState, _P'SetGearElasticity', @lc_setgearelasticity);
10809
bb2e4e9944f7 Add generic getter/setter for a bunch of more obscure gear structure values
nemo
parents: 10808
diff changeset
  4628
lua_register(luaState, _P'GetGearFriction', @lc_getgearfriction);
10808
1e39630d7c2e Add a couple of more variable bindings, make all the set visual gear values optional, to allow skipping trailing params or specifying ones in the middle as nil to not set. Should make using it more convenient in simple cases.
nemo
parents: 10671
diff changeset
  4629
lua_register(luaState, _P'SetGearFriction', @lc_setgearfriction);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4630
lua_register(luaState, _P'GetGearRadius', @lc_getgearradius);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4631
lua_register(luaState, _P'GetGearMessage', @lc_getgearmessage);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4632
lua_register(luaState, _P'SetGearMessage', @lc_setgearmessage);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4633
lua_register(luaState, _P'GetGearPos', @lc_getgearpos);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4634
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
  4635
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
  4636
lua_register(luaState, _P'SetGearCollisionMask', @lc_setgearcollisionmask);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4637
lua_register(luaState, _P'GetRandom', @lc_getrandom);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4638
lua_register(luaState, _P'SetWind', @lc_setwind);
12930
330b6c353093 Lua API: Add GetWind function to get current wind
Wuzzy <Wuzzy2@mail.ru>
parents: 12929
diff changeset
  4639
lua_register(luaState, _P'GetWind', @lc_getwind);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4640
lua_register(luaState, _P'MapHasBorder', @lc_maphasborder);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4641
lua_register(luaState, _P'GetHogHat', @lc_gethoghat);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4642
lua_register(luaState, _P'SetHogHat', @lc_sethoghat);
10901
fbf6fbe66092 also erase
nemo
parents: 10899
diff changeset
  4643
lua_register(luaState, _P'EraseSprite', @lc_erasesprite);
10280
762c256552e9 WIP: PlaceSprite for lua API. also changed PlaceGirder so that it will return true/false for whether placing was successful too
sheepluva
parents: 10279
diff changeset
  4644
lua_register(luaState, _P'PlaceSprite', @lc_placesprite);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4645
lua_register(luaState, _P'PlaceGirder', @lc_placegirder);
12090
fac17dd2bc2f Add PlaceRubber to Lua API
Wuzzy <almikes@aol.com>
parents: 12046
diff changeset
  4646
lua_register(luaState, _P'PlaceRubber', @lc_placerubber);
7072
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4647
lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);
159616c24bb8 More magic
unc0rr
parents: 7063
diff changeset
  4648
lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle);
9815
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  4649
lua_register(luaState, _P'GetGravity', @lc_getgravity);
d4621fb76284 - Fix typo in frontend debug output
unc0rr
parents: 9788
diff changeset
  4650
lua_register(luaState, _P'SetGravity', @lc_setgravity);
9914
ba26595503ab hey, if unc0rr can screw with gravity...
nemo
parents: 9902
diff changeset
  4651
lua_register(luaState, _P'SetWaterLine', @lc_setwaterline);
10291
d9893b1b76a0 lua api: SetNextWeapon()
sheepluva
parents: 10290
diff changeset
  4652
lua_register(luaState, _P'SetNextWeapon', @lc_setnextweapon);
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 10288
diff changeset
  4653
lua_register(luaState, _P'SetWeapon', @lc_setweapon);
11520
663ecfb05df6 Lua API: SetCinematicMode(enable)
sheepluva
parents: 11515
diff changeset
  4654
lua_register(luaState, _P'SetCinematicMode', @lc_setcinematicmode);
11058
b91667fd6f20 Lua API: SetMaxBuildDistance([ distInPx ]) -- set to 0 for no limit; call with no param to reset to default
sheepluva
parents: 11052
diff changeset
  4655
lua_register(luaState, _P'SetMaxBuildDistance', @lc_setmaxbuilddistance);
11846
6bf91006d630 Lua API: GetAmmoName(ammoType)
sheepluva
parents: 11844
diff changeset
  4656
lua_register(luaState, _P'GetAmmoName', @lc_getammoname);
13371
da913fc1d350 Lua API: GetAmmoTimer, to get the player-set timer for an ammo
Wuzzy <Wuzzy2@mail.ru>
parents: 13370
diff changeset
  4657
lua_register(luaState, _P'GetAmmoTimer', @lc_getammotimer);
12929
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  4658
lua_register(luaState, _P'SetVampiric', @lc_setvampiric);
13576
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  4659
lua_register(luaState, _P'GetVampiric', @lc_getvampiric);
12929
1d7d7d21914a Lua API: Add SetVampiric and SetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 12910
diff changeset
  4660
lua_register(luaState, _P'SetLaserSight', @lc_setlasersight);
13576
e5761b37e99c Lua: Add GetVampiric, GetLaserSight
Wuzzy <Wuzzy2@mail.ru>
parents: 13469
diff changeset
  4661
lua_register(luaState, _P'GetLaserSight', @lc_getlasersight);
13270
969aacfa229c Lua API: Add Explode function
Wuzzy <Wuzzy2@mail.ru>
parents: 13216
diff changeset
  4662
lua_register(luaState, _P'Explode', @lc_explode);
13741
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  4663
lua_register(luaState, _P'SetTurnTimeLeft', @lc_setturntimeleft);
b3b55b03d499 Lua API: Add SetTurnTimeLeft, SetReadyTimeLeft
Wuzzy <Wuzzy2@mail.ru>
parents: 13728
diff changeset
  4664
lua_register(luaState, _P'SetReadyTimeLeft', @lc_setreadytimeleft);
14415
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  4665
lua_register(luaState, _P'SetTurnTimePaused', @lc_setturntimepaused);
d670e4efe1ed Lua API: SetTurnTimePaused/GetTurnTimePaused
Wuzzy <Wuzzy2@mail.ru>
parents: 14414
diff changeset
  4666
lua_register(luaState, _P'GetTurnTimePaused', @lc_getturntimepaused);
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  4667
// drawn map functions
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  4668
lua_register(luaState, _P'AddPoint', @lc_addPoint);
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  4669
lua_register(luaState, _P'FlushPoints', @lc_flushPoints);
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
  4670
11066
f10a4bdfa0f4 fix internal function name
sheepluva
parents: 11062
diff changeset
  4671
lua_register(luaState, _P'SetGearAIHints', @lc_setgearaihints);
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 8034
diff changeset
  4672
lua_register(luaState, _P'HedgewarsScriptLoad', @lc_hedgewarsscriptload);
9397
7b7ee65f82ad Declare achievements in console statistics output
unc0rr
parents: 9387
diff changeset
  4673
lua_register(luaState, _P'DeclareAchievement', @lc_declareachievement);
11569
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  4674
lua_register(luaState, _P'StartGhostPoints', @lc_startghostpoints);
294ce0fa65d0 Dump best time ghost on console
unc0rr
parents: 11561
diff changeset
  4675
lua_register(luaState, _P'DumpPoint', @lc_dumppoint);
7996
66e8ac9c2274 Try to beat AI in Mutant!
unc0rr
parents: 7889
diff changeset
  4676
10618
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  4677
ScriptSetInteger('TEST_SUCCESSFUL'   , HaltTestSuccess);
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  4678
ScriptSetInteger('TEST_FAILED'       , HaltTestFailed);
7b72cf27cd04 tweaking the lua test function thingy
sheepluva
parents: 10617
diff changeset
  4679
lua_register(luaState, _P'EndLuaTest', @lc_endluatest);
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
  4680
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4681
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
  4682
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
  4683
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
  4684
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4685
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
  4686
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
  4687
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
  4688
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
  4689
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4690
{$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
  4691
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
  4692
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
  4693
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
  4694
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4695
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
  4696
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
  4697
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
  4698
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4699
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
  4700
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4701
    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
  4702
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
  4703
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4704
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
  4705
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
  4706
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
  4707
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4708
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
  4709
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4710
    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
  4711
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
  4712
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4713
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
  4714
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4715
    // avoid hints
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4716
    fname:= fname;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4717
    par1:= par1;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4718
    par2:= par2;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4719
    par3:= par3;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4720
    par4:= par4;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4721
    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
  4722
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
  4723
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4724
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
  4725
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4726
    // avoid hints
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4727
    fname:= fname;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4728
    par1:= par1;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4729
    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
  4730
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
  4731
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4732
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
  4733
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4734
    // avoid hints
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4735
    fname:= fname;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4736
    par1:= par1;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4737
    par2:= par2;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4738
    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
  4739
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
  4740
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4741
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
  4742
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4743
    // avoid hints
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4744
    fname:= fname;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4745
    par1:= par1;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4746
    par2:= par2;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4747
    par3:= par3;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4748
    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
  4749
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
  4750
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4751
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
  4752
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4753
    fname:= fname; // avoid hint
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4754
    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
  4755
end;
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  4756
(*
5410
8e7787065e2d small fix to have LUA_DISABLED working again
Xeli
parents: 5366
diff changeset
  4757
function ParseCommandOverride(key, value : shortstring) : shortstring;
8e7787065e2d small fix to have LUA_DISABLED working again
Xeli
parents: 5366
diff changeset
  4758
begin
7030
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4759
    // avoid hints
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4760
    key:= key;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4761
    value:= value;
09984acadece invert LUA symbol meaning and avoid hints when compiling without it
koda
parents: 7010
diff changeset
  4762
    ParseCommandOverride:= ''
5410
8e7787065e2d small fix to have LUA_DISABLED working again
Xeli
parents: 5366
diff changeset
  4763
end;
7805
2a249a4faf5b Flag script parsecommands to avoid echoing to net
nemo
parents: 7771
diff changeset
  4764
*)
5410
8e7787065e2d small fix to have LUA_DISABLED working again
Xeli
parents: 5366
diff changeset
  4765
6430
93eefff23bcd fix compiling with LUA_DISABLED
koda
parents: 6415
diff changeset
  4766
procedure ScriptOnScreenResize;
93eefff23bcd fix compiling with LUA_DISABLED
koda
parents: 6415
diff changeset
  4767
begin
93eefff23bcd fix compiling with LUA_DISABLED
koda
parents: 6415
diff changeset
  4768
end;
93eefff23bcd fix compiling with LUA_DISABLED
koda
parents: 6415
diff changeset
  4769
11678
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4770
procedure ScriptOnPreviewInit;
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4771
begin
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4772
end;
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4773
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4774
procedure ScriptSetInteger(name : shortstring; value : LongInt);
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4775
begin
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4776
end;
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4777
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4778
procedure ScriptSetString(name : shortstring; value : shortstring);
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4779
begin
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4780
end;
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4781
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4782
procedure LuaParseString(s : ShortString);
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4783
begin
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4784
end;
b76b7372a2a6 Add missing functions to fully disable lua at compile time
koda
parents: 11677
diff changeset
  4785
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
  4786
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
  4787
begin
10611
58cad46782ff move functionality of Draw.lua into engine
sheepluva
parents: 10603
diff changeset
  4788
PointsBuffer:= '';
13216
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4789
PrevCursorX:= NoPointX;
95311e220eb6 Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
Wuzzy <Wuzzy2@mail.ru>
parents: 13170
diff changeset
  4790
PrevCursorY:= NoPointX;
13743
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4791
isPendingTurnTimeLeft:= false;
e8f26bc793d9 Add deprecation warning for setting TurnTimeLeft/ReadyTimeLeft directly, fix SetTurnTimeLeft/SetReadyTimeLeft not setting vars reliably
Wuzzy <Wuzzy2@mail.ru>
parents: 13741
diff changeset
  4792
isPendingReadyTimeLeft:= 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
  4793
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
  4794
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4795
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
  4796
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
  4797
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
  4798
3acdb4dac6eb Just tidying up a bit. Comments, moving uMisc to end of frees in case ones above it need logging
nemo
parents: 3038
diff changeset
  4799
{$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
  4800
end.