dc0da2dd9c6c242262e67b49fe73145ed51afc82
1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 function SP_Lua_ConPrint(L
: PScriptContext
): Integer; cdecl;
33 g_player
, g_map
, Math
, g_gfx
, g_game
, g_textures
,
34 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
35 g_main
, SysUtils
, e_log
, g_language
, g_basic
,
36 g_options
, g_net
, g_netmsg
, g_triggers
, g_panel
,
39 function CheckArgs(L
: PScriptContext
; MinArgs
: Integer; Error
: Boolean = True): Boolean; inline;
42 if lua_gettop(L
) < MinArgs
then
44 if Error
then g_Console_Add('SCRIPT: ERROR: expected at least ' + IntToStr(MinArgs
) + ' argument(s)');
50 >>>>>>> 3132944... made TRIGGER_SCRIPT work
52 function SP_Lua_ConPrint(L
: PScriptContext
): Integer; cdecl;
55 // game.con_print(text)
60 if not CheckArgs(L
, MINARGS
) then Exit
;
61 g_Console_Add(luaL_checkstring(L
, 1));
64 function SP_Lua_Message(L
: PScriptContext
): Integer; cdecl;
65 // game.message(type, text, channel[, uid=0, timeout=144])
70 MChan
, MKind
, MID
, MTime
: Integer;
73 if not CheckArgs(L
, MINARGS
) then exit
;
75 MKind
:= luaL_checkinteger(L
, 1);
76 MText
:= luaL_checkstring(L
, 2);
77 MChan
:= luaL_checkinteger(L
, 3);
79 MID
:= lua_tointeger(L
, 4);
80 MTime
:= lua_tointeger(L
, 5);
81 if MTime
= 0 then MTime
:= 144;
83 tr_Message(MKind
, MText
, MChan
, MTime
, MID
);
86 function SP_Lua_GetGameMode(L
: PScriptContext
): Integer; cdecl;
87 // game.get_gamemode()
92 lua_pushinteger(L
, gGameSettings
.GameMode
);
95 function SP_Lua_GetGameType(L
: PScriptContext
): Integer; cdecl;
96 // game.get_gametype()
101 lua_pushinteger(L
, gGameSettings
.GameType
);
104 function SP_Lua_GetTime(L
: PScriptContext
): Integer; cdecl;
110 lua_pushinteger(L
, gTime
);
113 function SP_Lua_PlaySound(L
: PScriptContext
): Integer; cdecl;
114 // game.sound(name[positional=false, x=0, y=0])
123 if not CheckArgs(L
, MINARGS
) then exit
;
125 SName
:= luaL_checkstring(L
, 1);
127 SPos
:= lua_toboolean(L
, 2);
128 SX
:= lua_tointeger(L
, 3);
129 SY
:= lua_tointeger(L
, 4);
132 g_Sound_PlayExAt(SName
, SX
, SY
)
134 g_Sound_PlayEx(SName
);
137 MH_SEND_Sound(SX
, SY
, SName
, SPos
);
142 function SP_Lua_PlayerGetKeys(L
: PScriptContext
): Integer; cdecl;
143 // game.player_get_keys(uid)
151 if not CheckArgs(L
, MINARGS
) then
157 UID
:= luaL_checkinteger(L
, 1);
159 if g_GetUIDType(UID
) <> UID_PLAYER
then
163 P
:= g_Player_Get(UID
);
169 lua_pushinteger(L
, P
.GetKeys
);
173 function SP_Lua_PlayerGetArmor(L
: PScriptContext
): Integer; cdecl;
174 // game.player_get_armor(uid)
182 if not CheckArgs(L
, MINARGS
) then
188 UID
:= luaL_checkinteger(L
, 1);
190 if g_GetUIDType(UID
) <> UID_PLAYER
then
194 P
:= g_Player_Get(UID
);
200 lua_pushinteger(L
, P
.Armor
);
204 function SP_Lua_PlayerGetName(L
: PScriptContext
): Integer; cdecl;
205 // game.player_get_name(uid)
213 if not CheckArgs(L
, MINARGS
) then
219 UID
:= luaL_checkinteger(L
, 1);
221 if g_GetUIDType(UID
) <> UID_PLAYER
then
225 P
:= g_Player_Get(UID
);
231 lua_pushstring(L
, P
.Name
);
235 function SP_Lua_PlayerGetTeam(L
: PScriptContext
): Integer; cdecl;
236 // game.player_get_team(uid)
244 if not CheckArgs(L
, MINARGS
) then
250 UID
:= luaL_checkinteger(L
, 1);
252 if g_GetUIDType(UID
) <> UID_PLAYER
then
256 P
:= g_Player_Get(UID
);
262 lua_pushinteger(L
, P
.Team
);
266 function SP_Lua_PlayerGetScore(L
: PScriptContext
): Integer; cdecl;
267 // game.player_get_score(uid)
275 if not CheckArgs(L
, MINARGS
) then
281 UID
:= luaL_checkinteger(L
, 1);
283 if g_GetUIDType(UID
) <> UID_PLAYER
then
287 P
:= g_Player_Get(UID
);
293 lua_pushinteger(L
, P
.Frags
);
299 function SP_Lua_ActorGetPos(L
: PScriptContext
): Integer; cdecl;
300 // game.uid_get_pos(uid)
309 if not CheckArgs(L
, MINARGS
) then
315 UID
:= luaL_checkinteger(L
, 1);
317 if g_GetUIDType(UID
) = UID_PLAYER
then
319 P
:= g_Player_Get(UID
);
326 lua_pushinteger(L
, P
.GameX
+ PLAYER_RECT_CX
);
327 lua_pushinteger(L
, P
.GameY
+ PLAYER_RECT_CY
);
329 else if g_GetUIDType(UID
) = UID_MONSTER
then
331 M
:= g_Monsters_Get(UID
);
338 lua_pushinteger(L
, M
.Obj
.X
+M
.Obj
.Rect
.X
+(M
.Obj
.Rect
.Width
div 2));
339 lua_pushinteger(L
, M
.Obj
.Y
+M
.Obj
.Rect
.Y
+(M
.Obj
.Rect
.Height
div 2));
348 function SP_Lua_ActorNearest(L
: PScriptContext
): Integer; cdecl;
349 // game.uid_nearest(x, y, [type=all, min, max])
353 i
, UID
, AType
: Integer;
354 X
, Y
, Dist
, MinDist
, MaxDist
, FMin
: Double;
357 if not CheckArgs(L
, MINARGS
) then
363 X
:= luaL_checkinteger(L
, 1);
364 Y
:= luaL_checkinteger(L
, 2);
366 AType
:= lua_tointeger(L
, 3);
367 MinDist
:= Sqr(lua_tonumber(L
, 4));
368 MaxDist
:= Sqr(lua_tonumber(L
, 5));
369 if MaxDist
< 0.01 then MaxDist
:= 1e15
;
370 if MinDist
< 0.01 then MinDist
:= 0;
374 if (AType
in [UID_GAME
, UID_PLAYER
]) and (gPlayers
<> nil) then
375 for i
:= 0 to High(gPlayers
) do
377 if gPlayers
[i
] = nil then continue
;
378 Dist
:= Sqr(X
- gPlayers
[i
].GameX
) + Sqr(Y
- gPlayers
[i
].GameY
);
379 if (Dist
> MinDist
) and (Dist
< FMin
) then
381 UID
:= gPlayers
[i
].UID
;
385 if (AType
in [UID_GAME
, UID_MONSTER
]) and (gMonsters
<> nil) then
386 for i
:= 0 to High(gMonsters
) do
388 if gMonsters
[i
] = nil then continue
;
389 Dist
:= Sqr(X
- gMonsters
[i
].GameX
) + Sqr(Y
- gMonsters
[i
].GameY
);
390 if (Dist
> MinDist
) and (Dist
< FMin
) then
392 UID
:= gMonsters
[i
].UID
;
397 lua_pushinteger(L
, UID
);
400 function SP_Lua_ActorFarthest(L
: PScriptContext
): Integer; cdecl;
401 // game.uid_farthest(x, y, [type=all, min, max])
405 i
, UID
, AType
: Integer;
406 X
, Y
, Dist
, MinDist
, MaxDist
, FMax
: Double;
409 if not CheckArgs(L
, MINARGS
) then
415 X
:= luaL_checkinteger(L
, 1);
416 Y
:= luaL_checkinteger(L
, 2);
418 AType
:= lua_tointeger(L
, 3);
419 MinDist
:= Sqr(lua_tonumber(L
, 4));
420 MaxDist
:= Sqr(lua_tonumber(L
, 5));
421 if MaxDist
< 0.01 then MaxDist
:= 1e15
;
422 if MinDist
< 0.01 then MinDist
:= 0;
426 if (AType
in [UID_GAME
, UID_PLAYER
]) and (gPlayers
<> nil) then
427 for i
:= 0 to High(gPlayers
) do
429 if gPlayers
[i
] = nil then continue
;
430 Dist
:= Sqr(X
- gPlayers
[i
].GameX
) + Sqr(Y
- gPlayers
[i
].GameY
);
431 if (Dist
< MaxDist
) and (Dist
> FMax
) then
433 UID
:= gPlayers
[i
].UID
;
437 if (AType
in [UID_GAME
, UID_MONSTER
]) and (gMonsters
<> nil) then
438 for i
:= 0 to High(gMonsters
) do
440 if gMonsters
[i
] = nil then continue
;
441 Dist
:= Sqr(X
- gMonsters
[i
].GameX
) + Sqr(Y
- gMonsters
[i
].GameY
);
442 if (Dist
< MaxDist
) and (Dist
> FMax
) then
444 UID
:= gMonsters
[i
].UID
;
449 lua_pushinteger(L
, UID
);
452 function SP_Lua_ActorGetType(L
: PScriptContext
): Integer; cdecl;
453 // game.uid_type(uid)
460 if not CheckArgs(L
, MINARGS
) then
466 UID
:= luaL_checkinteger(L
, 1);
467 if (UID
< 0) or (UID
> $FFFF) then
471 UType
:= g_GetUIDType(UID
);
472 if not (UType
in [UID_PLAYER
, UID_MONSTER
{*, UID_ITEM*}]) then
475 lua_pushinteger(L
, UType
);
479 function SP_Lua_ActorDamage(L
: PScriptContext
): Integer; cdecl;
480 // game.uid_damage(uid, amount[, hit_type=hit_some, vx=0, vy=0, attacker_uid=0])
484 UID
, AUID
, Dmg
, Atk
, VX
, VY
: Integer;
487 >>>>>>> 081369f... scripts
: uid_get_pos() now returns center
489 g_Console_Add(lua_tostring(L
, -1));