mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
While in the air: release accelerate while at nearly-still speeds, and you'll preform a minisucle air drift boost. This mechanic is meant to fix the long-standing issue where you can get stuck in 0 speed in the air and not be able to do anything.
1129 lines
37 KiB
C
1129 lines
37 KiB
C
// SONIC ROBO BLAST 2
|
|
//-----------------------------------------------------------------------------
|
|
// Copyright (C) 2012-2016 by John "JTE" Muniz.
|
|
// Copyright (C) 2012-2020 by Sonic Team Junior.
|
|
//
|
|
// This program is free software distributed under the
|
|
// terms of the GNU General Public License, version 2.
|
|
// See the 'LICENSE' file for more details.
|
|
//-----------------------------------------------------------------------------
|
|
/// \file lua_playerlib.c
|
|
/// \brief player object library for Lua scripting
|
|
|
|
#include "doomdef.h"
|
|
#include "fastcmp.h"
|
|
#include "p_mobj.h"
|
|
#include "d_player.h"
|
|
#include "g_game.h"
|
|
#include "p_local.h"
|
|
#include "d_clisrv.h"
|
|
|
|
#include "lua_script.h"
|
|
#include "lua_libs.h"
|
|
#include "lua_hud.h" // hud_running errors
|
|
#include "lua_hook.h" // hook_cmd_running errors
|
|
|
|
static int lib_iteratePlayers(lua_State *L)
|
|
{
|
|
INT32 i = -1;
|
|
|
|
if (lua_gettop(L) < 2)
|
|
{
|
|
//return luaL_error(L, "Don't call players.iterate() directly, use it as 'for player in players.iterate do <block> end'.");
|
|
lua_pushcfunction(L, lib_iteratePlayers);
|
|
return 1;
|
|
}
|
|
|
|
lua_settop(L, 2);
|
|
lua_remove(L, 1); // state is unused.
|
|
|
|
if (!lua_isnil(L, 1))
|
|
i = (INT32)(*((player_t **)luaL_checkudata(L, 1, META_PLAYER)) - players);
|
|
|
|
i++;
|
|
|
|
if (i == serverplayer)
|
|
{
|
|
return LUA_PushServerPlayer(L);
|
|
}
|
|
|
|
for (; i < MAXPLAYERS; i++)
|
|
{
|
|
if (!playeringame[i])
|
|
continue;
|
|
LUA_PushUserdata(L, &players[i], META_PLAYER);
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int lib_getPlayer(lua_State *L)
|
|
{
|
|
const char *field;
|
|
// i -> players[i]
|
|
if (lua_type(L, 2) == LUA_TNUMBER)
|
|
{
|
|
lua_Integer i = luaL_checkinteger(L, 2);
|
|
if (i < 0 || i >= MAXPLAYERS)
|
|
return luaL_error(L, "players[] index %d out of range (0 - %d)", i, MAXPLAYERS-1);
|
|
if (i == serverplayer)
|
|
return LUA_PushServerPlayer(L);
|
|
if (!playeringame[i])
|
|
return 0;
|
|
LUA_PushUserdata(L, &players[i], META_PLAYER);
|
|
return 1;
|
|
}
|
|
|
|
field = luaL_checkstring(L, 2);
|
|
if (fastcmp(field,"iterate"))
|
|
{
|
|
lua_pushcfunction(L, lib_iteratePlayers);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// #players -> MAXPLAYERS
|
|
static int lib_lenPlayer(lua_State *L)
|
|
{
|
|
lua_pushinteger(L, MAXPLAYERS);
|
|
return 1;
|
|
}
|
|
|
|
// Same deal as the three functions above but for displayplayers
|
|
|
|
static int lib_iterateDisplayplayers(lua_State *L)
|
|
{
|
|
INT32 i = -1;
|
|
INT32 temp = -1;
|
|
INT32 iter = 0;
|
|
|
|
if (lua_gettop(L) < 2)
|
|
{
|
|
//return luaL_error(L, "Don't call displayplayers.iterate() directly, use it as 'for player in displayplayers.iterate do <block> end'.");
|
|
lua_pushcfunction(L, lib_iterateDisplayplayers);
|
|
return 1;
|
|
}
|
|
lua_settop(L, 2);
|
|
lua_remove(L, 1); // state is unused.
|
|
if (!lua_isnil(L, 1))
|
|
{
|
|
temp = (INT32)(*((player_t **)luaL_checkudata(L, 1, META_PLAYER)) - players); // get the player # of the last iterated player.
|
|
|
|
// @FIXME:
|
|
// I didn't quite find a better way for this; Here, we go back to which player in displayplayers we last iterated to resume the for loop below for this new function call
|
|
// I don't understand enough about how the Lua stacks work to get this to work in possibly a single line.
|
|
// So anyone feel free to correct this!
|
|
|
|
for (; iter < MAXSPLITSCREENPLAYERS; iter++)
|
|
{
|
|
if (displayplayers[iter] == temp)
|
|
{
|
|
i = iter;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (i++; i < MAXSPLITSCREENPLAYERS; i++)
|
|
{
|
|
if (i > splitscreen || !playeringame[displayplayers[i]])
|
|
return 0; // Stop! There are no more players for us to go through. There will never be a player gap in displayplayers.
|
|
|
|
LUA_PushUserdata(L, &players[displayplayers[i]], META_PLAYER);
|
|
lua_pushinteger(L, i); // push this to recall what number we were on for the next function call. I suppose this also means you can retrieve the splitscreen player number with 'for p, n in displayplayers.iterate'!
|
|
return 2;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int lib_getDisplayplayers(lua_State *L)
|
|
{
|
|
const char *field;
|
|
// i -> players[i]
|
|
if (lua_type(L, 2) == LUA_TNUMBER)
|
|
{
|
|
lua_Integer i = luaL_checkinteger(L, 2);
|
|
if (i < 0 || i >= MAXSPLITSCREENPLAYERS)
|
|
return luaL_error(L, "displayplayers[] index %d out of range (0 - %d)", i, MAXSPLITSCREENPLAYERS-1);
|
|
if (i > splitscreen)
|
|
return 0;
|
|
if (!playeringame[displayplayers[i]])
|
|
return 0;
|
|
LUA_PushUserdata(L, &players[displayplayers[i]], META_PLAYER);
|
|
return 1;
|
|
}
|
|
|
|
field = luaL_checkstring(L, 2);
|
|
if (fastcmp(field,"iterate"))
|
|
{
|
|
lua_pushcfunction(L, lib_iterateDisplayplayers);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// #displayplayers -> MAXSPLITSCREENPLAYERS
|
|
static int lib_lenDisplayplayers(lua_State *L)
|
|
{
|
|
lua_pushinteger(L, MAXSPLITSCREENPLAYERS);
|
|
return 1;
|
|
}
|
|
|
|
static int player_get(lua_State *L)
|
|
{
|
|
player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
|
const char *field = luaL_checkstring(L, 2);
|
|
|
|
if (!plr) {
|
|
if (fastcmp(field,"valid")) {
|
|
lua_pushboolean(L, false);
|
|
return 1;
|
|
}
|
|
return LUA_ErrInvalid(L, "player_t");
|
|
}
|
|
|
|
if (fastcmp(field,"valid"))
|
|
lua_pushboolean(L, true);
|
|
else if (fastcmp(field,"name"))
|
|
lua_pushstring(L, player_names[plr-players]);
|
|
else if (fastcmp(field,"mo"))
|
|
LUA_PushUserdata(L, plr->mo, META_MOBJ);
|
|
else if (fastcmp(field,"cmd"))
|
|
LUA_PushUserdata(L, &plr->cmd, META_TICCMD);
|
|
else if (fastcmp(field,"respawn"))
|
|
LUA_PushUserdata(L, &plr->respawn, META_RESPAWN);
|
|
else if (fastcmp(field,"playerstate"))
|
|
lua_pushinteger(L, plr->playerstate);
|
|
else if (fastcmp(field,"viewz"))
|
|
lua_pushfixed(L, plr->viewz);
|
|
else if (fastcmp(field,"viewheight"))
|
|
lua_pushfixed(L, plr->viewheight);
|
|
else if (fastcmp(field,"viewrollangle"))
|
|
lua_pushangle(L, plr->viewrollangle);
|
|
else if (fastcmp(field,"aiming"))
|
|
lua_pushangle(L, plr->aiming);
|
|
else if (fastcmp(field,"drawangle"))
|
|
lua_pushangle(L, plr->drawangle);
|
|
else if (fastcmp(field,"rings"))
|
|
lua_pushinteger(L, plr->rings);
|
|
else if (fastcmp(field,"spheres"))
|
|
lua_pushinteger(L, plr->spheres);
|
|
else if (fastcmp(field,"powers"))
|
|
LUA_PushUserdata(L, plr->powers, META_POWERS);
|
|
else if (fastcmp(field,"kartstuff"))
|
|
LUA_PushUserdata(L, plr->kartstuff, META_KARTSTUFF);
|
|
else if (fastcmp(field,"karthud"))
|
|
LUA_PushUserdata(L, plr->karthud, META_KARTHUD);
|
|
else if (fastcmp(field,"airtime"))
|
|
lua_pushinteger(L, plr->airtime);
|
|
else if (fastcmp(field,"driftInput"))
|
|
lua_pushboolean(L, plr->driftInput);
|
|
else if (fastcmp(field,"airFailsafe"))
|
|
lua_pushboolean(L, plr->airFailsafe);
|
|
else if (fastcmp(field,"tumbleBounces"))
|
|
lua_pushinteger(L, plr->tumbleBounces);
|
|
else if (fastcmp(field,"tumbleHeight"))
|
|
lua_pushinteger(L, plr->tumbleHeight);
|
|
else if (fastcmp(field,"tumbleLastBounce"))
|
|
lua_pushboolean(L, plr->tumbleLastBounce);
|
|
else if (fastcmp(field,"tumbleSound"))
|
|
lua_pushboolean(L, plr->tumbleSound);
|
|
else if (fastcmp(field,"glanceDir"))
|
|
lua_pushinteger(L, plr->glanceDir);
|
|
else if (fastcmp(field,"trickpanel"))
|
|
lua_pushinteger(L, plr->trickpanel);
|
|
else if (fastcmp(field,"trickdelay"))
|
|
lua_pushinteger(L, plr->trickdelay);
|
|
else if (fastcmp(field,"trickmomx"))
|
|
lua_pushfixed(L, plr->trickmomx);
|
|
else if (fastcmp(field,"trickmomy"))
|
|
lua_pushfixed(L, plr->trickmomy);
|
|
else if (fastcmp(field,"trickmomz"))
|
|
lua_pushfixed(L, plr->trickmomz);
|
|
else if (fastcmp(field,"pflags"))
|
|
lua_pushinteger(L, plr->pflags);
|
|
else if (fastcmp(field,"panim"))
|
|
lua_pushinteger(L, plr->panim);
|
|
else if (fastcmp(field,"flashcount"))
|
|
lua_pushinteger(L, plr->flashcount);
|
|
else if (fastcmp(field,"flashpal"))
|
|
lua_pushinteger(L, plr->flashpal);
|
|
else if (fastcmp(field,"skincolor"))
|
|
lua_pushinteger(L, plr->skincolor);
|
|
else if (fastcmp(field,"score"))
|
|
lua_pushinteger(L, plr->score);
|
|
// SRB2kart
|
|
else if (fastcmp(field,"kartspeed"))
|
|
lua_pushinteger(L, plr->kartspeed);
|
|
else if (fastcmp(field,"kartweight"))
|
|
lua_pushinteger(L, plr->kartweight);
|
|
else if (fastcmp(field,"followerskin"))
|
|
lua_pushinteger(L, plr->followerskin);
|
|
else if (fastcmp(field,"followerready"))
|
|
lua_pushboolean(L, plr->followerready);
|
|
else if (fastcmp(field,"followercolor"))
|
|
lua_pushinteger(L, plr->followercolor);
|
|
else if (fastcmp(field,"follower"))
|
|
LUA_PushUserdata(L, plr->follower, META_MOBJ);
|
|
//
|
|
else if (fastcmp(field,"charflags"))
|
|
lua_pushinteger(L, plr->charflags);
|
|
else if (fastcmp(field,"followitem"))
|
|
lua_pushinteger(L, plr->followitem);
|
|
else if (fastcmp(field,"followmobj"))
|
|
LUA_PushUserdata(L, plr->followmobj, META_MOBJ);
|
|
else if (fastcmp(field,"lives"))
|
|
lua_pushinteger(L, plr->lives);
|
|
else if (fastcmp(field,"lostlife"))
|
|
lua_pushboolean(L, plr->lostlife);
|
|
else if (fastcmp(field,"continues"))
|
|
lua_pushinteger(L, plr->continues);
|
|
else if (fastcmp(field,"xtralife"))
|
|
lua_pushinteger(L, plr->xtralife);
|
|
else if (fastcmp(field,"gotcontinue"))
|
|
lua_pushinteger(L, plr->gotcontinue);
|
|
else if (fastcmp(field,"speed"))
|
|
lua_pushfixed(L, plr->speed);
|
|
else if (fastcmp(field,"secondjump"))
|
|
lua_pushinteger(L, plr->secondjump);
|
|
else if (fastcmp(field,"fly1"))
|
|
lua_pushinteger(L, plr->fly1);
|
|
else if (fastcmp(field,"scoreadd"))
|
|
lua_pushinteger(L, plr->scoreadd);
|
|
else if (fastcmp(field,"glidetime"))
|
|
lua_pushinteger(L, plr->glidetime);
|
|
else if (fastcmp(field,"climbing"))
|
|
lua_pushinteger(L, plr->climbing);
|
|
else if (fastcmp(field,"deadtimer"))
|
|
lua_pushinteger(L, plr->deadtimer);
|
|
else if (fastcmp(field,"exiting"))
|
|
lua_pushinteger(L, plr->exiting);
|
|
else if (fastcmp(field,"homing"))
|
|
lua_pushinteger(L, plr->homing);
|
|
else if (fastcmp(field,"dashmode"))
|
|
lua_pushinteger(L, plr->dashmode);
|
|
else if (fastcmp(field,"skidtime"))
|
|
lua_pushinteger(L, plr->skidtime);
|
|
else if (fastcmp(field,"cmomx"))
|
|
lua_pushfixed(L, plr->cmomx);
|
|
else if (fastcmp(field,"cmomy"))
|
|
lua_pushfixed(L, plr->cmomy);
|
|
else if (fastcmp(field,"rmomx"))
|
|
lua_pushfixed(L, plr->rmomx);
|
|
else if (fastcmp(field,"rmomy"))
|
|
lua_pushfixed(L, plr->rmomy);
|
|
else if (fastcmp(field,"numboxes"))
|
|
lua_pushinteger(L, plr->numboxes);
|
|
else if (fastcmp(field,"totalring"))
|
|
lua_pushinteger(L, plr->totalring);
|
|
else if (fastcmp(field,"realtime"))
|
|
lua_pushinteger(L, plr->realtime);
|
|
else if (fastcmp(field,"laps"))
|
|
lua_pushinteger(L, plr->laps);
|
|
else if (fastcmp(field,"ctfteam"))
|
|
lua_pushinteger(L, plr->ctfteam);
|
|
else if (fastcmp(field,"gotflag"))
|
|
lua_pushinteger(L, plr->gotflag);
|
|
else if (fastcmp(field,"weapondelay"))
|
|
lua_pushinteger(L, plr->weapondelay);
|
|
else if (fastcmp(field,"tossdelay"))
|
|
lua_pushinteger(L, plr->tossdelay);
|
|
else if (fastcmp(field,"starpostnum"))
|
|
lua_pushinteger(L, plr->starpostnum);
|
|
else if (fastcmp(field,"angle_pos"))
|
|
lua_pushangle(L, plr->angle_pos);
|
|
else if (fastcmp(field,"old_angle_pos"))
|
|
lua_pushangle(L, plr->old_angle_pos);
|
|
else if (fastcmp(field,"axis1"))
|
|
LUA_PushUserdata(L, plr->axis1, META_MOBJ);
|
|
else if (fastcmp(field,"axis2"))
|
|
LUA_PushUserdata(L, plr->axis2, META_MOBJ);
|
|
else if (fastcmp(field,"bumpertime"))
|
|
lua_pushinteger(L, plr->bumpertime);
|
|
else if (fastcmp(field,"flyangle"))
|
|
lua_pushinteger(L, plr->flyangle);
|
|
else if (fastcmp(field,"drilltimer"))
|
|
lua_pushinteger(L, plr->drilltimer);
|
|
else if (fastcmp(field,"linkcount"))
|
|
lua_pushinteger(L, plr->linkcount);
|
|
else if (fastcmp(field,"linktimer"))
|
|
lua_pushinteger(L, plr->linktimer);
|
|
else if (fastcmp(field,"anotherflyangle"))
|
|
lua_pushinteger(L, plr->anotherflyangle);
|
|
else if (fastcmp(field,"nightstime"))
|
|
lua_pushinteger(L, plr->nightstime);
|
|
else if (fastcmp(field,"drillmeter"))
|
|
lua_pushinteger(L, plr->drillmeter);
|
|
else if (fastcmp(field,"drilldelay"))
|
|
lua_pushinteger(L, plr->drilldelay);
|
|
else if (fastcmp(field,"bonustime"))
|
|
lua_pushboolean(L, plr->bonustime);
|
|
else if (fastcmp(field,"capsule"))
|
|
LUA_PushUserdata(L, plr->capsule, META_MOBJ);
|
|
else if (fastcmp(field,"drone"))
|
|
LUA_PushUserdata(L, plr->drone, META_MOBJ);
|
|
else if (fastcmp(field,"oldscale"))
|
|
lua_pushfixed(L, plr->oldscale);
|
|
else if (fastcmp(field,"mare"))
|
|
lua_pushinteger(L, plr->mare);
|
|
else if (fastcmp(field,"marelap"))
|
|
lua_pushinteger(L, plr->marelap);
|
|
else if (fastcmp(field,"marebonuslap"))
|
|
lua_pushinteger(L, plr->marebonuslap);
|
|
else if (fastcmp(field,"marebegunat"))
|
|
lua_pushinteger(L, plr->marebegunat);
|
|
else if (fastcmp(field,"startedtime"))
|
|
lua_pushinteger(L, plr->startedtime);
|
|
else if (fastcmp(field,"finishedtime"))
|
|
lua_pushinteger(L, plr->finishedtime);
|
|
else if (fastcmp(field,"lapbegunat"))
|
|
lua_pushinteger(L, plr->lapbegunat);
|
|
else if (fastcmp(field,"lapstartedtime"))
|
|
lua_pushinteger(L, plr->lapstartedtime);
|
|
else if (fastcmp(field,"finishedspheres"))
|
|
lua_pushinteger(L, plr->finishedspheres);
|
|
else if (fastcmp(field,"finishedrings"))
|
|
lua_pushinteger(L, plr->finishedrings);
|
|
else if (fastcmp(field,"marescore"))
|
|
lua_pushinteger(L, plr->marescore);
|
|
else if (fastcmp(field,"lastmarescore"))
|
|
lua_pushinteger(L, plr->lastmarescore);
|
|
else if (fastcmp(field,"totalmarescore"))
|
|
lua_pushinteger(L, plr->totalmarescore);
|
|
else if (fastcmp(field,"lastmare"))
|
|
lua_pushinteger(L, plr->lastmare);
|
|
else if (fastcmp(field,"lastmarelap"))
|
|
lua_pushinteger(L, plr->lastmarelap);
|
|
else if (fastcmp(field,"lastmarebonuslap"))
|
|
lua_pushinteger(L, plr->lastmarebonuslap);
|
|
else if (fastcmp(field,"totalmarelap"))
|
|
lua_pushinteger(L, plr->totalmarelap);
|
|
else if (fastcmp(field,"totalmarebonuslap"))
|
|
lua_pushinteger(L, plr->totalmarebonuslap);
|
|
else if (fastcmp(field,"maxlink"))
|
|
lua_pushinteger(L, plr->maxlink);
|
|
else if (fastcmp(field,"texttimer"))
|
|
lua_pushinteger(L, plr->texttimer);
|
|
else if (fastcmp(field,"textvar"))
|
|
lua_pushinteger(L, plr->textvar);
|
|
else if (fastcmp(field,"lastsidehit"))
|
|
lua_pushinteger(L, plr->lastsidehit);
|
|
else if (fastcmp(field,"lastlinehit"))
|
|
lua_pushinteger(L, plr->lastlinehit);
|
|
else if (fastcmp(field,"losstime"))
|
|
lua_pushinteger(L, plr->losstime);
|
|
else if (fastcmp(field,"timeshit"))
|
|
lua_pushinteger(L, plr->timeshit);
|
|
else if (fastcmp(field,"onconveyor"))
|
|
lua_pushinteger(L, plr->onconveyor);
|
|
else if (fastcmp(field,"awayviewmobj"))
|
|
LUA_PushUserdata(L, plr->awayviewmobj, META_MOBJ);
|
|
else if (fastcmp(field,"awayviewtics"))
|
|
lua_pushinteger(L, plr->awayviewtics);
|
|
else if (fastcmp(field,"awayviewaiming"))
|
|
lua_pushangle(L, plr->awayviewaiming);
|
|
|
|
else if (fastcmp(field,"spectator"))
|
|
lua_pushboolean(L, plr->spectator);
|
|
else if (fastcmp(field,"bot"))
|
|
lua_pushboolean(L, plr->bot);
|
|
else if (fastcmp(field,"jointime"))
|
|
lua_pushinteger(L, plr->jointime);
|
|
else if (fastcmp(field,"splitscreenindex"))
|
|
lua_pushinteger(L, plr->splitscreenindex);
|
|
else if (fastcmp(field,"quittime"))
|
|
lua_pushinteger(L, plr->quittime);
|
|
#ifdef HWRENDER
|
|
else if (fastcmp(field,"fovadd"))
|
|
lua_pushfixed(L, plr->fovadd);
|
|
#endif
|
|
else if (fastcmp(field,"ping"))
|
|
lua_pushinteger(L, playerpingtable[( plr - players )]);
|
|
else {
|
|
lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS);
|
|
I_Assert(lua_istable(L, -1));
|
|
lua_pushlightuserdata(L, plr);
|
|
lua_rawget(L, -2);
|
|
if (!lua_istable(L, -1)) { // no extra values table
|
|
CONS_Debug(DBG_LUA, M_GetText("'%s' has no extvars table or field named '%s'; returning nil.\n"), "player_t", field);
|
|
return 0;
|
|
}
|
|
lua_getfield(L, -1, field);
|
|
if (lua_isnil(L, -1)) // no value for this field
|
|
CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; returning nil.\n"), "player_t", field);
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
#define NOSET luaL_error(L, LUA_QL("player_t") " field " LUA_QS " should not be set directly.", field)
|
|
static int player_set(lua_State *L)
|
|
{
|
|
player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
|
const char *field = luaL_checkstring(L, 2);
|
|
if (!plr)
|
|
return LUA_ErrInvalid(L, "player_t");
|
|
|
|
if (hud_running)
|
|
return luaL_error(L, "Do not alter player_t in HUD rendering code!");
|
|
if (hook_cmd_running)
|
|
return luaL_error(L, "Do not alter player_t in CMD building code!");
|
|
|
|
if (hook_cmd_running)
|
|
return luaL_error(L, "Do not alter player_t in BuildCMD code!");
|
|
|
|
if (fastcmp(field,"mo")) {
|
|
mobj_t *newmo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ));
|
|
plr->mo->player = NULL; // remove player pointer from old mobj
|
|
(newmo->player = plr)->mo = newmo; // set player pointer for new mobj, and set new mobj as the player's mobj
|
|
}
|
|
else if (fastcmp(field,"cmd"))
|
|
return NOSET;
|
|
else if (fastcmp(field,"respawn"))
|
|
return NOSET;
|
|
else if (fastcmp(field,"playerstate"))
|
|
plr->playerstate = luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"viewz"))
|
|
plr->viewz = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"viewheight"))
|
|
plr->viewheight = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"viewrollangle"))
|
|
plr->viewrollangle = luaL_checkangle(L, 3);
|
|
else if (fastcmp(field,"aiming")) {
|
|
UINT8 i;
|
|
plr->aiming = luaL_checkangle(L, 3);
|
|
for (i = 0; i <= r_splitscreen; i++)
|
|
{
|
|
if (plr == &players[displayplayers[i]])
|
|
{
|
|
localaiming[i] = plr->aiming;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else if (fastcmp(field,"drawangle"))
|
|
plr->drawangle = luaL_checkangle(L, 3);
|
|
else if (fastcmp(field,"rings"))
|
|
plr->rings = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"spheres"))
|
|
plr->spheres = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"powers"))
|
|
return NOSET;
|
|
else if (fastcmp(field,"pflags"))
|
|
plr->pflags = luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"panim"))
|
|
plr->panim = luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"flashcount"))
|
|
plr->flashcount = (UINT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"flashpal"))
|
|
plr->flashpal = (UINT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"skincolor"))
|
|
{
|
|
UINT16 newcolor = (UINT16)luaL_checkinteger(L,3);
|
|
if (newcolor >= numskincolors)
|
|
return luaL_error(L, "player.skincolor %d out of range (0 - %d).", newcolor, numskincolors-1);
|
|
plr->skincolor = newcolor;
|
|
}
|
|
else if (fastcmp(field,"score"))
|
|
plr->score = (UINT32)luaL_checkinteger(L, 3);
|
|
// SRB2kart
|
|
else if (fastcmp(field,"kartstuff"))
|
|
return NOSET;
|
|
else if (fastcmp(field,"airtime"))
|
|
plr->airtime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"driftInput"))
|
|
plr->driftInput = luaL_checkboolean(L, 3);
|
|
else if (fastcmp(field,"airFailsafe"))
|
|
plr->airFailsafe = luaL_checkboolean(L, 3);
|
|
else if (fastcmp(field,"tumbleBounces"))
|
|
plr->tumbleBounces = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"tumbleHeight"))
|
|
plr->tumbleHeight = (UINT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"tumbleLastBounce"))
|
|
plr->tumbleLastBounce = luaL_checkboolean(L, 3);
|
|
else if (fastcmp(field,"tumbleSound"))
|
|
plr->tumbleSound = luaL_checkboolean(L, 3);
|
|
else if (fastcmp(field,"glanceDir"))
|
|
plr->glanceDir = (SINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"trickpanel"))
|
|
plr->trickpanel = luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"trickdelay"))
|
|
plr->trickdelay = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"trickmomx"))
|
|
plr->trickmomx = (fixed_t)luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"trickmomy"))
|
|
plr->trickmomy = (fixed_t)luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"trickmomz"))
|
|
plr->trickmomz = (fixed_t)luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"kartspeed"))
|
|
plr->kartspeed = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"kartweight"))
|
|
plr->kartweight = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"followerskin"))
|
|
plr->followerskin = luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"followercolor"))
|
|
plr->followercolor = luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"followerready"))
|
|
plr->followerready = luaL_checkboolean(L, 3);
|
|
else if (fastcmp(field,"follower")) // it's probably best we don't allow the follower mobj to change.
|
|
return NOSET;
|
|
//
|
|
else if (fastcmp(field,"charflags"))
|
|
plr->charflags = (UINT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"followitem"))
|
|
plr->followitem = luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"followmobj"))
|
|
{
|
|
mobj_t *mo = NULL;
|
|
if (!lua_isnil(L, 3))
|
|
mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ));
|
|
P_SetTarget(&plr->followmobj, mo);
|
|
}
|
|
else if (fastcmp(field,"lives"))
|
|
plr->lives = (SINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"lostlife"))
|
|
plr->lostlife = luaL_checkboolean(L, 3);
|
|
else if (fastcmp(field,"continues"))
|
|
plr->continues = (SINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"xtralife"))
|
|
plr->xtralife = (SINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"gotcontinue"))
|
|
plr->gotcontinue = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"speed"))
|
|
plr->speed = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"secondjump"))
|
|
plr->secondjump = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"fly1"))
|
|
plr->fly1 = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"scoreadd"))
|
|
plr->scoreadd = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"glidetime"))
|
|
plr->glidetime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"climbing"))
|
|
plr->climbing = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"deadtimer"))
|
|
plr->deadtimer = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"exiting"))
|
|
plr->exiting = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"homing"))
|
|
plr->homing = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"dashmode"))
|
|
plr->dashmode = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"skidtime"))
|
|
plr->skidtime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"cmomx"))
|
|
plr->cmomx = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"cmomy"))
|
|
plr->cmomy = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"rmomx"))
|
|
plr->rmomx = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"rmomy"))
|
|
plr->rmomy = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"numboxes"))
|
|
plr->numboxes = (INT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"totalring"))
|
|
plr->totalring = (INT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"realtime"))
|
|
plr->realtime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"laps"))
|
|
plr->laps = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"ctfteam"))
|
|
plr->ctfteam = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"gotflag"))
|
|
plr->gotflag = (UINT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"weapondelay"))
|
|
plr->weapondelay = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"tossdelay"))
|
|
plr->tossdelay = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"starpostnum"))
|
|
plr->starpostnum = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"angle_pos"))
|
|
plr->angle_pos = luaL_checkangle(L, 3);
|
|
else if (fastcmp(field,"old_angle_pos"))
|
|
plr->old_angle_pos = luaL_checkangle(L, 3);
|
|
else if (fastcmp(field,"axis1"))
|
|
{
|
|
mobj_t *mo = NULL;
|
|
if (!lua_isnil(L, 3))
|
|
mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ));
|
|
P_SetTarget(&plr->axis1, mo);
|
|
}
|
|
else if (fastcmp(field,"axis2"))
|
|
{
|
|
mobj_t *mo = NULL;
|
|
if (!lua_isnil(L, 3))
|
|
mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ));
|
|
P_SetTarget(&plr->axis2, mo);
|
|
}
|
|
else if (fastcmp(field,"bumpertime"))
|
|
plr->bumpertime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"flyangle"))
|
|
plr->flyangle = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"drilltimer"))
|
|
plr->drilltimer = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"linkcount"))
|
|
plr->linkcount = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"linktimer"))
|
|
plr->linktimer = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"anotherflyangle"))
|
|
plr->anotherflyangle = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"nightstime"))
|
|
plr->nightstime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"drillmeter"))
|
|
plr->drillmeter = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"drilldelay"))
|
|
plr->drilldelay = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"bonustime"))
|
|
plr->bonustime = luaL_checkboolean(L, 3);
|
|
else if (fastcmp(field,"capsule"))
|
|
{
|
|
mobj_t *mo = NULL;
|
|
if (!lua_isnil(L, 3))
|
|
mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ));
|
|
P_SetTarget(&plr->capsule, mo);
|
|
}
|
|
else if (fastcmp(field,"drone"))
|
|
{
|
|
mobj_t *mo = NULL;
|
|
if (!lua_isnil(L, 3))
|
|
mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ));
|
|
P_SetTarget(&plr->drone, mo);
|
|
}
|
|
else if (fastcmp(field,"oldscale"))
|
|
plr->oldscale = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"mare"))
|
|
plr->mare = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"marelap"))
|
|
plr->marelap = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"marebonuslap"))
|
|
plr->marebonuslap = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"marebegunat"))
|
|
plr->marebegunat = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"startedtime"))
|
|
plr->startedtime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"finishedtime"))
|
|
plr->finishedtime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"lapbegunat"))
|
|
plr->lapbegunat = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"lapstartedtime"))
|
|
plr->lapstartedtime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"finishedspheres"))
|
|
plr->finishedspheres = (INT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"finishedrings"))
|
|
plr->finishedrings = (INT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"marescore"))
|
|
plr->marescore = (UINT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"lastmarescore"))
|
|
plr->lastmarescore = (UINT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"totalmarescore"))
|
|
plr->totalmarescore = (UINT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"lastmare"))
|
|
plr->lastmare = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"lastmarelap"))
|
|
plr->lastmarelap = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"lastmarebonuslap"))
|
|
plr->lastmarebonuslap = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"totalmarelap"))
|
|
plr->totalmarelap = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"totalmarebonuslap"))
|
|
plr->totalmarebonuslap = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"maxlink"))
|
|
plr->maxlink = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"texttimer"))
|
|
plr->texttimer = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"textvar"))
|
|
plr->textvar = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"lastsidehit"))
|
|
plr->lastsidehit = (INT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"lastlinehit"))
|
|
plr->lastlinehit = (INT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"losstime"))
|
|
plr->losstime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"timeshit"))
|
|
plr->timeshit = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"onconveyor"))
|
|
plr->onconveyor = (INT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"awayviewmobj"))
|
|
{
|
|
mobj_t *mo = NULL;
|
|
if (!lua_isnil(L, 3))
|
|
mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ));
|
|
P_SetTarget(&plr->awayviewmobj, mo);
|
|
}
|
|
else if (fastcmp(field,"awayviewtics"))
|
|
{
|
|
plr->awayviewtics = (INT32)luaL_checkinteger(L, 3);
|
|
if (plr->awayviewtics && !plr->awayviewmobj) // awayviewtics must ALWAYS have an awayviewmobj set!!
|
|
P_SetTarget(&plr->awayviewmobj, plr->mo); // but since the script might set awayviewmobj immediately AFTER setting awayviewtics, use player mobj as filler for now.
|
|
}
|
|
else if (fastcmp(field,"awayviewaiming"))
|
|
plr->awayviewaiming = luaL_checkangle(L, 3);
|
|
else if (fastcmp(field,"spectator"))
|
|
plr->spectator = lua_toboolean(L, 3);
|
|
else if (fastcmp(field,"bot"))
|
|
return NOSET;
|
|
else if (fastcmp(field,"jointime"))
|
|
plr->jointime = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"splitscreenindex"))
|
|
return NOSET;
|
|
#ifdef HWRENDER
|
|
else if (fastcmp(field,"fovadd"))
|
|
plr->fovadd = luaL_checkfixed(L, 3);
|
|
#endif
|
|
else {
|
|
lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS);
|
|
I_Assert(lua_istable(L, -1));
|
|
lua_pushlightuserdata(L, plr);
|
|
lua_rawget(L, -2);
|
|
if (lua_isnil(L, -1)) {
|
|
// This index doesn't have a table for extra values yet, let's make one.
|
|
lua_pop(L, 1);
|
|
CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; adding it as Lua data.\n"), "player_t", field);
|
|
lua_newtable(L);
|
|
lua_pushlightuserdata(L, plr);
|
|
lua_pushvalue(L, -2); // ext value table
|
|
lua_rawset(L, -4); // LREG_EXTVARS table
|
|
}
|
|
lua_pushvalue(L, 3); // value to store
|
|
lua_setfield(L, -2, field);
|
|
lua_pop(L, 2);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#undef NOSET
|
|
|
|
static int player_num(lua_State *L)
|
|
{
|
|
player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
|
if (!plr)
|
|
return luaL_error(L, "accessed player_t doesn't exist anymore.");
|
|
lua_pushinteger(L, plr-players);
|
|
return 1;
|
|
}
|
|
|
|
// powers, p -> powers[p]
|
|
static int power_get(lua_State *L)
|
|
{
|
|
UINT16 *powers = *((UINT16 **)luaL_checkudata(L, 1, META_POWERS));
|
|
powertype_t p = luaL_checkinteger(L, 2);
|
|
if (p >= NUMPOWERS)
|
|
return luaL_error(L, LUA_QL("powertype_t") " cannot be %d", (INT16)p);
|
|
lua_pushinteger(L, powers[p]);
|
|
return 1;
|
|
}
|
|
|
|
// powers, p, value -> powers[p] = value
|
|
static int power_set(lua_State *L)
|
|
{
|
|
UINT16 *powers = *((UINT16 **)luaL_checkudata(L, 1, META_POWERS));
|
|
powertype_t p = luaL_checkinteger(L, 2);
|
|
UINT16 i = (UINT16)luaL_checkinteger(L, 3);
|
|
if (p >= NUMPOWERS)
|
|
return luaL_error(L, LUA_QL("powertype_t") " cannot be %d", (INT16)p);
|
|
if (hud_running)
|
|
return luaL_error(L, "Do not alter player_t in HUD rendering code!");
|
|
if (hook_cmd_running)
|
|
return luaL_error(L, "Do not alter player_t in CMD building code!");
|
|
powers[p] = i;
|
|
return 0;
|
|
}
|
|
|
|
// #powers -> NUMPOWERS
|
|
static int power_len(lua_State *L)
|
|
{
|
|
lua_pushinteger(L, NUMPOWERS);
|
|
return 1;
|
|
}
|
|
|
|
// kartstuff, ks -> kartstuff[ks]
|
|
static int kartstuff_get(lua_State *L)
|
|
{
|
|
INT32 *kartstuff = *((INT32 **)luaL_checkudata(L, 1, META_KARTSTUFF));
|
|
kartstufftype_t ks = luaL_checkinteger(L, 2);
|
|
if (ks >= NUMKARTSTUFF)
|
|
return luaL_error(L, LUA_QL("kartstufftype_t") " cannot be %u", ks);
|
|
lua_pushinteger(L, kartstuff[ks]);
|
|
return 1;
|
|
}
|
|
|
|
// kartstuff, ks, value -> kartstuff[ks] = value
|
|
static int kartstuff_set(lua_State *L)
|
|
{
|
|
INT32 *kartstuff = *((INT32 **)luaL_checkudata(L, 1, META_KARTSTUFF));
|
|
kartstufftype_t ks = luaL_checkinteger(L, 2);
|
|
INT32 i = (INT32)luaL_checkinteger(L, 3);
|
|
if (ks >= NUMKARTSTUFF)
|
|
return luaL_error(L, LUA_QL("kartstufftype_t") " cannot be %u", ks);
|
|
if (hud_running)
|
|
return luaL_error(L, "Do not alter player_t in HUD rendering code!");
|
|
if (hook_cmd_running)
|
|
return luaL_error(L, "Do not alter player_t in BuildCMD code!");
|
|
kartstuff[ks] = i;
|
|
return 0;
|
|
}
|
|
|
|
// #karthud -> NUMKARTSTUFF
|
|
static int kartstuff_len(lua_State *L)
|
|
{
|
|
lua_pushinteger(L, NUMKARTSTUFF);
|
|
return 1;
|
|
}
|
|
|
|
// karthud, ks -> karthud[ks]
|
|
static int karthud_get(lua_State *L)
|
|
{
|
|
INT32 *karthud = *((INT32 **)luaL_checkudata(L, 1, META_KARTHUD));
|
|
karthudtype_t ks = luaL_checkinteger(L, 2);
|
|
if (ks >= NUMKARTHUD)
|
|
return luaL_error(L, LUA_QL("karthudtype_t") " cannot be %u", ks);
|
|
lua_pushinteger(L, karthud[ks]);
|
|
return 1;
|
|
}
|
|
|
|
// karthud, ks, value -> kartstuff[ks] = value
|
|
static int karthud_set(lua_State *L)
|
|
{
|
|
INT32 *karthud = *((INT32 **)luaL_checkudata(L, 1, META_KARTHUD));
|
|
karthudtype_t ks = luaL_checkinteger(L, 2);
|
|
INT32 i = (INT32)luaL_checkinteger(L, 3);
|
|
if (ks >= NUMKARTHUD)
|
|
return luaL_error(L, LUA_QL("karthudtype_t") " cannot be %u", ks);
|
|
if (hud_running)
|
|
return luaL_error(L, "Do not alter player_t in HUD rendering code!");
|
|
if (hook_cmd_running)
|
|
return luaL_error(L, "Do not alter player_t in BuildCMD code!");
|
|
karthud[ks] = i;
|
|
return 0;
|
|
}
|
|
|
|
// #karthud -> NUMKARTHUD
|
|
static int karthud_len(lua_State *L)
|
|
{
|
|
lua_pushinteger(L, NUMKARTHUD);
|
|
return 1;
|
|
}
|
|
|
|
// player.cmd get/set
|
|
#define NOFIELD luaL_error(L, LUA_QL("ticcmd_t") " has no field named " LUA_QS, field)
|
|
#define NOSET luaL_error(L, LUA_QL("ticcmd_t") " field " LUA_QS " cannot be set.", field)
|
|
|
|
static int ticcmd_get(lua_State *L)
|
|
{
|
|
ticcmd_t *cmd = *((ticcmd_t **)luaL_checkudata(L, 1, META_TICCMD));
|
|
const char *field = luaL_checkstring(L, 2);
|
|
if (!cmd)
|
|
return LUA_ErrInvalid(L, "player_t");
|
|
|
|
if (fastcmp(field,"forwardmove"))
|
|
lua_pushinteger(L, cmd->forwardmove);
|
|
else if (fastcmp(field,"turning"))
|
|
lua_pushinteger(L, cmd->turning);
|
|
else if (fastcmp(field,"aiming"))
|
|
lua_pushinteger(L, cmd->aiming);
|
|
else if (fastcmp(field,"buttons"))
|
|
lua_pushinteger(L, cmd->buttons);
|
|
else if (fastcmp(field,"latency"))
|
|
lua_pushinteger(L, cmd->latency);
|
|
else if (fastcmp(field,"flags"))
|
|
lua_pushinteger(L, cmd->flags);
|
|
else
|
|
return NOFIELD;
|
|
|
|
return 1;
|
|
}
|
|
|
|
static int ticcmd_set(lua_State *L)
|
|
{
|
|
ticcmd_t *cmd = *((ticcmd_t **)luaL_checkudata(L, 1, META_TICCMD));
|
|
const char *field = luaL_checkstring(L, 2);
|
|
if (!cmd)
|
|
return LUA_ErrInvalid(L, "ticcmd_t");
|
|
|
|
if (hud_running)
|
|
return luaL_error(L, "Do not alter player_t in HUD rendering code!");
|
|
|
|
if (fastcmp(field,"forwardmove"))
|
|
cmd->forwardmove = (SINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"turning"))
|
|
cmd->turning = (INT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"aiming"))
|
|
cmd->aiming = (INT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"buttons"))
|
|
cmd->buttons = (UINT16)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"latency"))
|
|
return NOSET;
|
|
else if (fastcmp(field,"flags"))
|
|
return NOSET;
|
|
else
|
|
return NOFIELD;
|
|
|
|
return 0;
|
|
}
|
|
|
|
#undef NOFIELD
|
|
|
|
// Same shit for player.respawn variable... Why is everything in different sub-variables again now???
|
|
#define RNOFIELD luaL_error(L, LUA_QL("respawnvars_t") " has no field named " LUA_QS, field)
|
|
#define RUNIMPLEMENTED luaL_error(L, LUA_QL("respawnvars_t") " unimplemented field " LUA_QS " cannot be read or set.", field)
|
|
// @TODO: Waypoints in Lua possibly maybe? No don't count on me to do it...
|
|
|
|
static int respawn_get(lua_State *L)
|
|
{
|
|
respawnvars_t *rsp = *((respawnvars_t **)luaL_checkudata(L, 1, META_RESPAWN));
|
|
const char *field = luaL_checkstring(L, 2);
|
|
if (!rsp)
|
|
return LUA_ErrInvalid(L, "player_t");
|
|
|
|
if (fastcmp(field,"state"))
|
|
lua_pushinteger(L, rsp->state);
|
|
else if (fastcmp(field,"waypoint"))
|
|
return RUNIMPLEMENTED;
|
|
else if (fastcmp(field,"pointx"))
|
|
lua_pushfixed(L, rsp->pointx);
|
|
else if (fastcmp(field,"pointy"))
|
|
lua_pushfixed(L, rsp->pointy);
|
|
else if (fastcmp(field,"pointz"))
|
|
lua_pushfixed(L, rsp->pointz);
|
|
else if (fastcmp(field,"flip"))
|
|
lua_pushboolean(L, rsp->flip);
|
|
else if (fastcmp(field,"timer"))
|
|
lua_pushinteger(L, rsp->timer);
|
|
else if (fastcmp(field,"distanceleft"))
|
|
lua_pushinteger(L, rsp->distanceleft); // Can't possibly foresee any problem when pushing UINT32 to Lua's INT32 hahahahaha, get ready for dumb hacky shit on high distances.
|
|
else if (fastcmp(field,"dropdash"))
|
|
lua_pushinteger(L, rsp->dropdash);
|
|
else
|
|
return RNOFIELD;
|
|
|
|
return 1;
|
|
}
|
|
|
|
static int respawn_set(lua_State *L)
|
|
{
|
|
respawnvars_t *rsp = *((respawnvars_t **)luaL_checkudata(L, 1, META_RESPAWN));
|
|
const char *field = luaL_checkstring(L, 2);
|
|
if (!rsp)
|
|
return LUA_ErrInvalid(L, "respawnvars_t");
|
|
|
|
if (hud_running)
|
|
return luaL_error(L, "Do not alter player_t in HUD rendering code!");
|
|
if (hook_cmd_running)
|
|
return luaL_error(L, "Do not alter player_t in CMD building code!");
|
|
|
|
if (fastcmp(field,"state"))
|
|
rsp->state = (UINT8)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"waypoint"))
|
|
return RUNIMPLEMENTED;
|
|
else if (fastcmp(field,"pointx"))
|
|
rsp->pointx = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"pointy"))
|
|
rsp->pointy = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"pointz"))
|
|
rsp->pointz = luaL_checkfixed(L, 3);
|
|
else if (fastcmp(field,"flip"))
|
|
rsp->flip = luaL_checkboolean(L, 3);
|
|
else if (fastcmp(field,"timer"))
|
|
rsp->timer = (tic_t)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"distanceleft"))
|
|
rsp->distanceleft = (UINT32)luaL_checkinteger(L, 3);
|
|
else if (fastcmp(field,"dropdash"))
|
|
rsp->dropdash = (tic_t)luaL_checkinteger(L, 3);
|
|
else
|
|
return RNOFIELD;
|
|
|
|
return 0;
|
|
}
|
|
|
|
#undef RNOFIELD
|
|
#undef RUNIMPLEMENTED
|
|
|
|
|
|
int LUA_PlayerLib(lua_State *L)
|
|
{
|
|
luaL_newmetatable(L, META_PLAYER);
|
|
lua_pushcfunction(L, player_get);
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
lua_pushcfunction(L, player_set);
|
|
lua_setfield(L, -2, "__newindex");
|
|
|
|
lua_pushcfunction(L, player_num);
|
|
lua_setfield(L, -2, "__len");
|
|
lua_pop(L,1);
|
|
|
|
luaL_newmetatable(L, META_POWERS);
|
|
lua_pushcfunction(L, power_get);
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
lua_pushcfunction(L, power_set);
|
|
lua_setfield(L, -2, "__newindex");
|
|
|
|
lua_pushcfunction(L, power_len);
|
|
lua_setfield(L, -2, "__len");
|
|
lua_pop(L,1);
|
|
|
|
luaL_newmetatable(L, META_KARTSTUFF);
|
|
lua_pushcfunction(L, kartstuff_get);
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
lua_pushcfunction(L, kartstuff_set);
|
|
lua_setfield(L, -2, "__newindex");
|
|
|
|
lua_pushcfunction(L, kartstuff_len);
|
|
lua_setfield(L, -2, "__len");
|
|
lua_pop(L,1);
|
|
|
|
luaL_newmetatable(L, META_KARTHUD);
|
|
lua_pushcfunction(L, karthud_get);
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
lua_pushcfunction(L, karthud_set);
|
|
lua_setfield(L, -2, "__newindex");
|
|
|
|
lua_pushcfunction(L, karthud_len);
|
|
lua_setfield(L, -2, "__len");
|
|
lua_pop(L,1);
|
|
|
|
luaL_newmetatable(L, META_RESPAWN);
|
|
lua_pushcfunction(L, respawn_get);
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
lua_pushcfunction(L, respawn_set);
|
|
lua_setfield(L, -2, "__newindex");
|
|
lua_pop(L,1);
|
|
|
|
luaL_newmetatable(L, META_TICCMD);
|
|
lua_pushcfunction(L, ticcmd_get);
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
lua_pushcfunction(L, ticcmd_set);
|
|
lua_setfield(L, -2, "__newindex");
|
|
lua_pop(L,1);
|
|
|
|
lua_newuserdata(L, 0);
|
|
lua_createtable(L, 0, 2);
|
|
lua_pushcfunction(L, lib_getPlayer);
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
lua_pushcfunction(L, lib_lenPlayer);
|
|
lua_setfield(L, -2, "__len");
|
|
lua_setmetatable(L, -2);
|
|
lua_setglobal(L, "players");
|
|
|
|
// push displayplayers in the same fashion
|
|
lua_newuserdata(L, 0);
|
|
lua_createtable(L, 0, 2);
|
|
lua_pushcfunction(L, lib_getDisplayplayers);
|
|
lua_setfield(L, -2, "__index");
|
|
|
|
lua_pushcfunction(L, lib_lenDisplayplayers);
|
|
lua_setfield(L, -2, "__len");
|
|
lua_setmetatable(L, -2);
|
|
lua_setglobal(L, "displayplayers");
|
|
|
|
return 0;
|
|
}
|