blankart/src/lua_playerlib.c
2025-01-06 08:25:45 -05:00

1686 lines
50 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 "blua/lua.h"
#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 > r_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 > r_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,"oldcmd"))
LUA_PushUserdata(L, &plr->oldcmd, META_TICCMD);
else if (fastcmp(field,"playerstate"))
lua_pushinteger(L, plr->playerstate);
else if (fastcmp(field,"health"))
{
if (plr->mo)
lua_pushinteger(L, plr->mo->health);
else
lua_pushinteger(L, 0);
}
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,"frameangle"))
lua_pushangle(L, plr->drawangle);
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,"nocontrol"))
lua_pushinteger(L, plr->nocontrol);
else if (fastcmp(field,"carry"))
lua_pushinteger(L, plr->carry);
else if (fastcmp(field,"dye"))
lua_pushinteger(L, plr->dye);
else if (fastcmp(field,"position"))
lua_pushinteger(L, plr->position);
else if (fastcmp(field,"oldposition"))
lua_pushinteger(L, plr->oldposition);
else if (fastcmp(field,"positiondelay"))
lua_pushinteger(L, plr->positiondelay);
else if (fastcmp(field,"prevcheck"))
lua_pushinteger(L, plr->prevcheck);
else if (fastcmp(field,"nextcheck"))
lua_pushinteger(L, plr->nextcheck);
else if (fastcmp(field,"distancetofinish"))
lua_pushinteger(L, plr->distancetofinish);
else if (fastcmp(field,"distancetofinishprev"))
lua_pushinteger(L, plr->distancetofinishprev);
else if (fastcmp(field,"airtime"))
lua_pushinteger(L, plr->airtime);
else if (fastcmp(field,"flashing"))
lua_pushinteger(L, plr->flashing);
else if (fastcmp(field,"spinouttimer"))
lua_pushinteger(L, plr->spinouttimer);
else if (fastcmp(field,"spinouttype"))
lua_pushinteger(L, plr->spinouttype);
else if (fastcmp(field,"instashield"))
lua_pushinteger(L, plr->instashield);
else if (fastcmp(field,"wipeoutslow"))
lua_pushinteger(L, plr->wipeoutslow);
else if (fastcmp(field,"justbumped"))
lua_pushinteger(L, plr->justbumped);
else if (fastcmp(field,"drift"))
lua_pushinteger(L, plr->drift);
else if (fastcmp(field,"driftcharge"))
lua_pushinteger(L, plr->driftcharge);
else if (fastcmp(field,"driftboost"))
lua_pushinteger(L, plr->driftboost);
else if (fastcmp(field,"boostcharge"))
lua_pushinteger(L, plr->boostcharge);
else if (fastcmp(field,"startboost"))
lua_pushinteger(L, plr->startboost);
else if (fastcmp(field,"dropdash"))
lua_pushinteger(L, plr->dropdash);
else if (fastcmp(field,"respawn"))
lua_pushinteger(L, plr->respawn);
else if (fastcmp(field,"aizdriftstrat"))
lua_pushinteger(L, plr->aizdriftstrat);
else if (fastcmp(field,"aizdrifttilt"))
lua_pushinteger(L, plr->aizdrifttilt);
else if (fastcmp(field,"aizdriftturn"))
lua_pushinteger(L, plr->aizdriftturn);
else if (fastcmp(field,"offroad"))
lua_pushinteger(L, plr->offroad);
else if (fastcmp(field,"pogospring"))
lua_pushinteger(L, plr->pogospring);
else if (fastcmp(field,"brakestop"))
lua_pushinteger(L, plr->brakestop);
else if (fastcmp(field,"waterskip"))
lua_pushinteger(L, plr->waterskip);
else if (fastcmp(field,"dashpadcooldown"))
lua_pushinteger(L, plr->dashpadcooldown);
else if (fastcmp(field,"boostpower"))
lua_pushinteger(L, plr->boostpower);
else if (fastcmp(field,"speedboost"))
lua_pushinteger(L, plr->speedboost);
else if (fastcmp(field,"accelboost"))
lua_pushinteger(L, plr->accelboost);
else if (fastcmp(field,"boostangle"))
lua_pushangle(L, plr->boostangle);
else if (fastcmp(field,"tripwireState"))
lua_pushinteger(L, plr->tripwireState);
else if (fastcmp(field,"tripwirePass"))
lua_pushinteger(L, plr->tripwirePass);
else if (fastcmp(field,"tripwireLeniency"))
lua_pushinteger(L, plr->tripwireLeniency);
else if (fastcmp(field,"tripwireReboundDelay"))
lua_pushinteger(L, plr->tripwireReboundDelay);
else if (fastcmp(field,"itemroulette"))
lua_pushinteger(L, plr->itemroulette);
else if (fastcmp(field,"roulettetype"))
lua_pushinteger(L, plr->roulettetype);
else if (fastcmp(field,"itemtype"))
lua_pushinteger(L, plr->itemtype);
else if (fastcmp(field,"itemamount"))
lua_pushinteger(L, plr->itemamount);
else if (fastcmp(field,"throwdir"))
lua_pushinteger(L, plr->throwdir);
else if (fastcmp(field,"sadtimer"))
lua_pushinteger(L, plr->sadtimer);
else if (fastcmp(field,"rings"))
lua_pushinteger(L, plr->rings);
else if (fastcmp(field,"pickuprings"))
lua_pushinteger(L, plr->pickuprings);
else if (fastcmp(field,"ringdelay"))
lua_pushinteger(L, plr->ringdelay);
else if (fastcmp(field,"ringboost"))
lua_pushinteger(L, plr->ringboost);
else if (fastcmp(field,"superring"))
lua_pushinteger(L, plr->superring);
else if (fastcmp(field,"curshield"))
lua_pushinteger(L, plr->curshield);
else if (fastcmp(field,"bubblecool"))
lua_pushinteger(L, plr->bubblecool);
else if (fastcmp(field,"bubbleblowup"))
lua_pushinteger(L, plr->bubbleblowup);
else if (fastcmp(field,"flamedash"))
lua_pushinteger(L, plr->flamedash);
else if (fastcmp(field,"flamemeter"))
lua_pushinteger(L, plr->flamemeter);
else if (fastcmp(field,"flamelength"))
lua_pushinteger(L, plr->flamelength);
else if (fastcmp(field,"hyudorotimer"))
lua_pushinteger(L, plr->hyudorotimer);
else if (fastcmp(field,"stealingtimer"))
lua_pushinteger(L, plr->stealingtimer);
else if (fastcmp(field,"stolentimer"))
lua_pushinteger(L, plr->stolentimer);
else if (fastcmp(field,"sneakertimer"))
lua_pushinteger(L, plr->sneakertimer);
else if (fastcmp(field,"floorboost"))
lua_pushinteger(L, plr->floorboost);
else if (fastcmp(field,"waterrun"))
lua_pushinteger(L, plr->waterrun);
else if (fastcmp(field,"growshrinktimer"))
lua_pushinteger(L, plr->growshrinktimer);
else if (fastcmp(field,"growcancel"))
lua_pushinteger(L, plr->growcancel);
else if (fastcmp(field,"squishedtimer"))
lua_pushinteger(L, plr->squishedtimer);
else if (fastcmp(field,"rocketsneakertimer"))
lua_pushinteger(L, plr->rocketsneakertimer);
else if (fastcmp(field,"invincibilitytimer"))
lua_pushinteger(L, plr->invincibilitytimer);
else if (fastcmp(field,"eggmanexplode"))
lua_pushinteger(L, plr->eggmanexplode);
else if (fastcmp(field,"eggmanblame"))
lua_pushinteger(L, plr->eggmanblame);
else if (fastcmp(field,"bananadrag"))
lua_pushinteger(L, plr->bananadrag);
else if (fastcmp(field,"lastjawztarget"))
lua_pushinteger(L, plr->lastjawztarget);
else if (fastcmp(field,"jawztargetdelay"))
lua_pushinteger(L, plr->jawztargetdelay);
else if (fastcmp(field,"confirmVictim"))
lua_pushinteger(L, plr->confirmVictim);
else if (fastcmp(field,"confirmVictimDelay"))
lua_pushinteger(L, plr->confirmVictimDelay);
else if (fastcmp(field,"glanceDir"))
lua_pushinteger(L, plr->glanceDir);
else if (fastcmp(field,"roundscore"))
plr->roundscore = luaL_checkinteger(L, 3);
else if (fastcmp(field,"marescore"))
plr->roundscore = luaL_checkinteger(L, 3);
else if (fastcmp(field,"emeralds"))
lua_pushinteger(L, plr->emeralds);
else if (fastcmp(field,"bumpers"))
lua_pushinteger(L, plr->bumper);
else if (fastcmp(field,"karmadelay"))
lua_pushinteger(L, plr->karmadelay);
else if (fastcmp(field,"spheres"))
lua_pushinteger(L, plr->spheres);
else if (fastcmp(field,"spheredigestion"))
lua_pushinteger(L, plr->spheredigestion);
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,"skin"))
lua_pushinteger(L, plr->skin);
else if (fastcmp(field,"availabilities"))
lua_pushinteger(L, plr->availabilities);
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,"xtralife"))
lua_pushinteger(L, plr->xtralife);
else if (fastcmp(field,"speed"))
lua_pushfixed(L, plr->speed);
else if (fastcmp(field,"lastspeed"))
lua_pushfixed(L, plr->lastspeed);
else if (fastcmp(field,"deadtimer"))
lua_pushinteger(L, plr->deadtimer);
else if (fastcmp(field,"exiting"))
lua_pushinteger(L, plr->exiting);
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,"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,"latestlap"))
lua_pushinteger(L, plr->latestlap);
else if (fastcmp(field,"ctfteam"))
lua_pushinteger(L, plr->ctfteam);
else if (fastcmp(field,"checkskip"))
lua_pushinteger(L, plr->checkskip);
else if (fastcmp(field,"starpostx"))
lua_pushfixed(L, plr->starpostx);
else if (fastcmp(field,"starposty"))
lua_pushfixed(L, plr->starposty);
else if (fastcmp(field,"starpostz"))
lua_pushfixed(L, plr->starpostz);
else if (fastcmp(field,"starpostangle"))
lua_pushangle(L, plr->starpostangle);
else if (fastcmp(field,"starpostflip"))
lua_pushboolean(L, plr->starpostflip);
else if (fastcmp(field,"starpostnum"))
lua_pushinteger(L, plr->starpostnum);
else if (fastcmp(field,"starposttime"))
lua_pushinteger(L, plr->starposttime);
else if (fastcmp(field,"lastsidehit"))
lua_pushinteger(L, plr->lastsidehit);
else if (fastcmp(field,"lastlinehit"))
lua_pushinteger(L, plr->lastlinehit);
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,"spectatewait"))
lua_pushinteger(L, plr->spectatewait);
else if (fastcmp(field,"bot"))
lua_pushboolean(L, plr->bot);
else if (fastcmp(field,"jointime"))
lua_pushinteger(L, plr->jointime);
else if (fastcmp(field,"spectatorreentry"))
lua_pushinteger(L, plr->spectatorreentry);
else if (fastcmp(field,"grieftime"))
lua_pushinteger(L, plr->grieftime);
else if (fastcmp(field,"griefstrikes"))
lua_pushinteger(L, plr->griefstrikes);
else if (fastcmp(field,"splitscreenindex"))
lua_pushinteger(L, plr->splitscreenindex);
#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 (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,"oldcmd"))
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,"frameangle"))
plr->drawangle = luaL_checkangle(L, 3);
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 = luaL_checkinteger(L, 3);
else if (fastcmp(field,"flashpal"))
plr->flashpal = luaL_checkinteger(L, 3);
else if (fastcmp(field,"skincolor"))
{
UINT16 newcolor = 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,"skin"))
return NOSET;
else if (fastcmp(field,"availabilities"))
return NOSET;
else if (fastcmp(field,"score"))
plr->score = luaL_checkinteger(L, 3);
// SRB2kart
else if (fastcmp(field,"kartstuff"))
return NOSET;
else if (fastcmp(field,"nocontrol"))
plr->nocontrol = luaL_checkinteger(L, 3);
else if (fastcmp(field,"carry"))
plr->carry = luaL_checkinteger(L, 3);
else if (fastcmp(field,"dye"))
plr->dye = luaL_checkinteger(L, 3);
else if (fastcmp(field,"position"))
plr->position = luaL_checkinteger(L, 3);
else if (fastcmp(field,"oldposition"))
plr->oldposition = luaL_checkinteger(L, 3);
else if (fastcmp(field,"positiondelay"))
plr->positiondelay = luaL_checkinteger(L, 3);
else if (fastcmp(field,"prevcheck"))
plr->prevcheck = luaL_checkinteger(L, 3);
else if (fastcmp(field,"nextcheck"))
plr->nextcheck = luaL_checkinteger(L, 3);
else if (fastcmp(field,"distancetofinish"))
return NOSET;
else if (fastcmp(field,"distancetofinishprev"))
return NOSET;
else if (fastcmp(field,"airtime"))
plr->airtime = luaL_checkinteger(L, 3);
else if (fastcmp(field,"flashing"))
plr->flashing = luaL_checkinteger(L, 3);
else if (fastcmp(field,"spinouttimer"))
plr->spinouttimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"spinouttype"))
plr->spinouttype = luaL_checkinteger(L, 3);
else if (fastcmp(field,"instashield"))
plr->instashield = luaL_checkinteger(L, 3);
else if (fastcmp(field,"wipeoutslow"))
plr->wipeoutslow = luaL_checkinteger(L, 3);
else if (fastcmp(field,"justbumped"))
plr->justbumped = luaL_checkinteger(L, 3);
else if (fastcmp(field,"drift"))
plr->drift = luaL_checkinteger(L, 3);
else if (fastcmp(field,"driftcharge"))
plr->driftcharge = luaL_checkinteger(L, 3);
else if (fastcmp(field,"driftboost"))
plr->driftboost = luaL_checkinteger(L, 3);
else if (fastcmp(field,"boostcharge"))
plr->boostcharge = luaL_checkinteger(L, 3);
else if (fastcmp(field,"startboost"))
plr->startboost = luaL_checkinteger(L, 3);
else if (fastcmp(field,"dropdash"))
plr->dropdash = luaL_checkinteger(L, 3);
else if (fastcmp(field,"respawn"))
plr->respawn = luaL_checkinteger(L, 3);
else if (fastcmp(field,"aizdriftstrat"))
plr->aizdriftstrat = luaL_checkinteger(L, 3);
else if (fastcmp(field,"aizdrifttilt"))
plr->aizdrifttilt = luaL_checkinteger(L, 3);
else if (fastcmp(field,"aizdriftturn"))
plr->aizdriftturn = luaL_checkinteger(L, 3);
else if (fastcmp(field,"offroad"))
plr->offroad = luaL_checkinteger(L, 3);
else if (fastcmp(field,"pogospring"))
plr->pogospring = luaL_checkinteger(L, 3);
else if (fastcmp(field,"brakestop"))
plr->brakestop = luaL_checkinteger(L, 3);
else if (fastcmp(field,"waterskip"))
plr->waterskip = luaL_checkinteger(L, 3);
else if (fastcmp(field,"dashpadcooldown"))
plr->dashpadcooldown = luaL_checkinteger(L, 3);
else if (fastcmp(field,"boostpower"))
plr->boostpower = luaL_checkinteger(L, 3);
else if (fastcmp(field,"speedboost"))
plr->speedboost = luaL_checkinteger(L, 3);
else if (fastcmp(field,"accelboost"))
plr->accelboost = luaL_checkinteger(L, 3);
else if (fastcmp(field,"boostangle"))
plr->boostangle = luaL_checkangle(L, 3);
else if (fastcmp(field,"tripwireState"))
plr->tripwireState = luaL_checkinteger(L, 3);
else if (fastcmp(field,"tripwirePass"))
plr->tripwirePass = luaL_checkinteger(L, 3);
else if (fastcmp(field,"tripwireLeniency"))
plr->tripwireLeniency = luaL_checkinteger(L, 3);
else if (fastcmp(field,"tripwireReboundDelay"))
plr->tripwireReboundDelay = luaL_checkinteger(L, 3);
else if (fastcmp(field,"itemroulette"))
plr->itemroulette = luaL_checkinteger(L, 3);
else if (fastcmp(field,"roulettetype"))
plr->roulettetype = luaL_checkinteger(L, 3);
else if (fastcmp(field,"itemtype"))
plr->itemtype = luaL_checkinteger(L, 3);
else if (fastcmp(field,"itemamount"))
plr->itemamount = luaL_checkinteger(L, 3);
else if (fastcmp(field,"throwdir"))
plr->throwdir = luaL_checkinteger(L, 3);
else if (fastcmp(field,"sadtimer"))
plr->sadtimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"rings"))
plr->rings = luaL_checkinteger(L, 3);
else if (fastcmp(field,"pickuprings"))
plr->pickuprings = luaL_checkinteger(L, 3);
else if (fastcmp(field,"ringdelay"))
plr->ringdelay = luaL_checkinteger(L, 3);
else if (fastcmp(field,"ringboost"))
plr->ringboost = luaL_checkinteger(L, 3);
else if (fastcmp(field,"superring"))
plr->superring = luaL_checkinteger(L, 3);
else if (fastcmp(field,"curshield"))
plr->curshield = luaL_checkinteger(L, 3);
else if (fastcmp(field,"bubblecool"))
plr->bubblecool = luaL_checkinteger(L, 3);
else if (fastcmp(field,"bubbleblowup"))
plr->bubbleblowup = luaL_checkinteger(L, 3);
else if (fastcmp(field,"flamedash"))
plr->flamedash = luaL_checkinteger(L, 3);
else if (fastcmp(field,"flamemeter"))
plr->flamemeter = luaL_checkinteger(L, 3);
else if (fastcmp(field,"flamelength"))
plr->flamelength = luaL_checkinteger(L, 3);
else if (fastcmp(field,"hyudorotimer"))
plr->hyudorotimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"stealingtimer"))
plr->stealingtimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"stolentimer"))
plr->stealingtimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"sneakertimer"))
plr->sneakertimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"floorboost"))
plr->floorboost = luaL_checkinteger(L, 3);
else if (fastcmp(field,"waterrun"))
plr->waterrun = luaL_checkboolean(L, 3);
else if (fastcmp(field,"growshrinktimer"))
plr->growshrinktimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"growcancel"))
plr->growcancel = luaL_checkinteger(L, 3);
else if (fastcmp(field,"squishedtimer"))
plr->squishedtimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"rocketsneakertimer"))
plr->rocketsneakertimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"invincibilitytimer"))
plr->invincibilitytimer = luaL_checkinteger(L, 3);
else if (fastcmp(field,"eggmanexplode"))
plr->eggmanexplode = luaL_checkinteger(L, 3);
else if (fastcmp(field,"eggmanblame"))
plr->eggmanblame = luaL_checkinteger(L, 3);
else if (fastcmp(field,"bananadrag"))
plr->bananadrag = luaL_checkinteger(L, 3);
else if (fastcmp(field,"lastjawztarget"))
plr->lastjawztarget = luaL_checkinteger(L, 3);
else if (fastcmp(field,"jawztargetdelay"))
plr->jawztargetdelay = luaL_checkinteger(L, 3);
else if (fastcmp(field,"confirmVictim"))
plr->confirmVictim = luaL_checkinteger(L, 3);
else if (fastcmp(field,"confirmVictimDelay"))
plr->confirmVictimDelay = luaL_checkinteger(L, 3);
else if (fastcmp(field,"glanceDir"))
plr->glanceDir = luaL_checkinteger(L, 3);
else if (fastcmp(field,"roundscore"))
lua_pushinteger(L, plr->roundscore);
else if (fastcmp(field,"marescore"))
lua_pushinteger(L, plr->roundscore);
else if (fastcmp(field,"emeralds"))
plr->emeralds = luaL_checkinteger(L, 3);
else if (fastcmp(field,"bumpers"))
plr->bumper = luaL_checkinteger(L, 3);
else if (fastcmp(field,"karmadelay"))
plr->karmadelay = luaL_checkinteger(L, 3);
else if (fastcmp(field,"spheres"))
plr->spheres = luaL_checkinteger(L, 3);
else if (fastcmp(field,"spheredigestion"))
plr->spheredigestion = luaL_checkinteger(L, 3);
else if (fastcmp(field,"kartspeed"))
plr->kartspeed = luaL_checkinteger(L, 3);
else if (fastcmp(field,"kartweight"))
plr->kartweight = 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,"xtralife"))
plr->xtralife = (SINT8)luaL_checkinteger(L, 3);
else if (fastcmp(field,"speed"))
plr->speed = luaL_checkfixed(L, 3);
else if (fastcmp(field,"lastspeed"))
plr->lastspeed = luaL_checkfixed(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,"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,"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,"latestlap"))
plr->latestlap = (UINT8)luaL_checkinteger(L, 3);
else if (fastcmp(field,"ctfteam"))
plr->ctfteam = (INT32)luaL_checkinteger(L, 3);
else if (fastcmp(field,"checkskip"))
plr->checkskip = (INT32)luaL_checkinteger(L, 3);
else if (fastcmp(field,"starpostx"))
plr->starpostx = luaL_checkfixed(L, 3);
else if (fastcmp(field,"starposty"))
plr->starposty = luaL_checkfixed(L, 3);
else if (fastcmp(field,"starpostz"))
plr->starpostz = luaL_checkfixed(L, 3);
else if (fastcmp(field,"starpostangle"))
plr->starpostangle = luaL_checkangle(L, 3);
else if (fastcmp(field,"starpostflip"))
plr->starpostflip = luaL_checkboolean(L, 3);
else if (fastcmp(field,"starpostnum"))
plr->starpostnum = (INT32)luaL_checkinteger(L, 3);
else if (fastcmp(field,"starposttime"))
plr->starposttime = (tic_t)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,"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,"spectatewait"))
plr->spectatewait = luaL_checkinteger(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,"spectatorreentry"))
plr->spectatorreentry = (tic_t)luaL_checkinteger(L, 3);
else if (fastcmp(field,"grieftime"))
plr->grieftime = (tic_t)luaL_checkinteger(L, 3);
else if (fastcmp(field,"griefstrikes"))
plr->griefstrikes = (UINT8)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);
player_t *plr = (player_t*)((void*)powers - offsetof(player_t, powers));
if (p >= NUMPOWERS)
return luaL_error(L, LUA_QL("powertype_t") " cannot be %u", p);
switch (p)
{
case pw_flashing:
lua_pushinteger(L, plr->flashing);
return 1;
case pw_nocontrol:
lua_pushinteger(L, plr->nocontrol);
return 1;
case pw_ingoop:
if (plr->mo)
lua_pushinteger(L, P_IsObjectInGoop(plr->mo));
else
lua_pushinteger(L, 0);
return 1;
default:
lua_pushinteger(L, powers[p]);
return 1;
}
return 1;
}
#define NOSET luaL_error(L, LUA_QL("powertype_t") " field " LUA_QS " should not be set directly.", p)
// 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);
player_t *plr = (player_t*)((void*)powers - offsetof(player_t, powers));
UINT16 i = (UINT16)luaL_checkinteger(L, 3);
if (p >= NUMPOWERS)
return luaL_error(L, LUA_QL("powertype_t") " cannot be %u", 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 BuildCMD code!");
switch (p)
{
case pw_flashing:
plr->flashing = i;
break;
case pw_nocontrol:
plr->nocontrol = i;
break;
case pw_ingoop:
return NOSET;
default:
powers[p] = i;
break;
}
return 0;
}
#undef NOSET
// #powers -> NUMPOWERS
static int power_len(lua_State *L)
{
lua_pushinteger(L, NUMPOWERS);
return 1;
}
// ???, ks -> kartstuff[ks]
static int kartstuff_get(lua_State *L)
{
INT32 *kartstuff = *((INT32 **)luaL_checkudata(L, 1, META_KARTSTUFF));
player_t *plr = (player_t*)((void*)kartstuff - offsetof(player_t, kartstuff));
kartstufftype_t ks = luaL_checkinteger(L, 2);
if (ks >= NUMKARTSTUFF)
return luaL_error(L, LUA_QL("kartstufftype_t") " cannot be %u", ks);
switch (ks)
{
case k_position:
lua_pushinteger(L, plr->position);
return 1;
case k_oldposition:
lua_pushinteger(L, plr->oldposition);
return 1;
case k_positiondelay:
lua_pushinteger(L, plr->positiondelay);
return 1;
case k_prevcheck:
lua_pushinteger(L, plr->prevcheck);
return 1;
case k_nextcheck:
lua_pushinteger(L, plr->nextcheck);
return 1;
/*case k_waypoint:
lua_pushinteger(L, plr->waypoint);
return 1;*/
/*case k_starpostwp:
lua_pushinteger(L, plr->starpostwp);
return 1;*/
case k_starpostflip:
lua_pushinteger(L, plr->starpostflip);
return 1;
case k_respawn:
lua_pushinteger(L, plr->respawn);
return 1;
case k_dropdash:
lua_pushinteger(L, plr->dropdash);
return 1;
case k_throwdir:
lua_pushinteger(L, plr->throwdir);
return 1;
case k_lapanimation:
lua_pushinteger(L, plr->karthud[khud_lapanimation]);
return 1;
case k_laphand:
lua_pushinteger(L, plr->karthud[khud_laphand]);
return 1;
case k_cardanimation:
lua_pushinteger(L, plr->karthud[khud_cardanimation]);
return 1;
case k_voices:
lua_pushinteger(L, plr->karthud[khud_voices]);
return 1;
case k_tauntvoices:
lua_pushinteger(L, plr->karthud[khud_tauntvoices]);
return 1;
case k_instashield:
lua_pushinteger(L, plr->instashield);
return 1;
case k_enginesnd:
lua_pushinteger(L, plr->karthud[khud_enginesnd]);
return 1;
case k_floorboost:
lua_pushinteger(L, plr->floorboost);
return 1;
case k_spinouttype:
lua_pushinteger(L, plr->spinouttype);
return 1;
case k_drift:
lua_pushinteger(L, plr->drift);
return 1;
case k_driftend:
lua_pushinteger(L, (plr->pflags & PF_DRIFTEND));
return 1;
case k_driftcharge:
lua_pushinteger(L, plr->driftcharge);
return 1;
case k_driftboost:
lua_pushinteger(L, plr->driftboost);
return 1;
case k_boostcharge:
lua_pushinteger(L, plr->boostcharge);
return 1;
case k_startboost:
lua_pushinteger(L, plr->startboost);
return 1;
case k_jmp:
lua_pushinteger(L, (plr->pflags & PF_DRIFTINPUT));
return 1;
case k_offroad:
lua_pushinteger(L, plr->offroad);
return 1;
case k_pogospring:
lua_pushinteger(L, plr->pogospring);
return 1;
case k_brakestop:
lua_pushinteger(L, plr->brakestop);
return 1;
case k_waterskip:
lua_pushinteger(L, plr->waterskip);
return 1;
case k_dashpadcooldown:
lua_pushinteger(L, plr->dashpadcooldown);
return 1;
case k_boostpower:
lua_pushinteger(L, plr->boostpower);
return 1;
case k_speedboost:
lua_pushinteger(L, plr->speedboost);
return 1;
case k_accelboost:
lua_pushinteger(L, plr->accelboost);
return 1;
case k_boostangle:
lua_pushinteger(L, plr->boostangle);
return 1;
case k_boostcam:
lua_pushinteger(L, plr->karthud[khud_boostcam]);
return 1;
case k_destboostcam:
lua_pushinteger(L, plr->karthud[khud_destboostcam]);
return 1;
case k_timeovercam:
lua_pushinteger(L, plr->karthud[khud_timeovercam]);
return 1;
case k_aizdriftstrat:
lua_pushinteger(L, plr->aizdriftstrat);
return 1;
case k_brakedrift:
lua_pushinteger(L, (plr->pflags & PF_BRAKEDRIFT));
return 1;
case k_itemroulette:
lua_pushinteger(L, plr->itemroulette);
return 1;
case k_roulettetype:
lua_pushinteger(L, plr->roulettetype);
return 1;
case k_itemtype:
lua_pushinteger(L, plr->itemtype);
return 1;
case k_itemamount:
lua_pushinteger(L, plr->itemamount);
return 1;
case k_itemheld:
lua_pushinteger(L, (plr->pflags & PF_ITEMOUT));
return 1;
case k_curshield:
lua_pushinteger(L, plr->curshield);
return 1;
case k_hyudorotimer:
lua_pushinteger(L, plr->hyudorotimer);
return 1;
case k_stealingtimer:
lua_pushinteger(L, plr->stealingtimer);
return 1;
case k_stolentimer:
lua_pushinteger(L, plr->stolentimer);
return 1;
case k_sneakertimer:
lua_pushinteger(L, plr->sneakertimer);
return 1;
case k_growshrinktimer:
lua_pushinteger(L, plr->growshrinktimer);
return 1;
case k_squishedtimer:
lua_pushinteger(L, plr->squishedtimer);
return 1;
case k_rocketsneakertimer:
lua_pushinteger(L, plr->rocketsneakertimer);
return 1;
case k_invincibilitytimer:
lua_pushinteger(L, plr->invincibilitytimer);
return 1;
case k_eggmanheld:
lua_pushinteger(L, (plr->pflags & PF_EGGMANOUT));
return 1;
case k_eggmanexplode:
lua_pushinteger(L, plr->eggmanexplode);
return 1;
case k_eggmanblame:
lua_pushinteger(L, plr->eggmanblame);
return 1;
case k_lastjawztarget:
lua_pushinteger(L, plr->lastjawztarget);
return 1;
case k_bananadrag:
lua_pushinteger(L, plr->bananadrag);
return 1;
case k_spinouttimer:
lua_pushinteger(L, plr->spinouttimer);
return 1;
case k_wipeoutslow:
lua_pushinteger(L, plr->wipeoutslow);
return 1;
case k_justbumped:
lua_pushinteger(L, plr->justbumped);
return 1;
case k_comebacktimer:
lua_pushinteger(L, plr->karmadelay);
return 1;
case k_sadtimer:
lua_pushinteger(L, plr->sadtimer);
return 1;
// Battle Mode vars
case k_bumper:
lua_pushinteger(L, plr->bumper);
return 1;
case k_comebackpoints:
lua_pushinteger(L, plr->karmapoints);
return 1;
case k_comebackmode:
lua_pushinteger(L, plr->karmamode);
return 1;
case k_wanted:
lua_pushinteger(L, plr->wanted);
return 1;
case k_yougotem:
lua_pushinteger(L, plr->karthud[khud_yougotem]);
return 1;
// v1.0.2+ vars
case k_itemblink:
lua_pushinteger(L, plr->karthud[khud_itemblink]);
return 1;
case k_itemblinkmode:
lua_pushinteger(L, plr->karthud[khud_itemblinkmode]);
return 1;
case k_getsparks:
lua_pushinteger(L, (plr->pflags & PF_GETSPARKS));
return 1;
case k_jawztargetdelay:
lua_pushinteger(L, plr->jawztargetdelay);
return 1;
case k_spectatewait:
lua_pushinteger(L, plr->spectatewait);
return 1;
case k_growcancel:
lua_pushinteger(L, plr->growcancel);
return 1;
default:
return luaL_error(L, LUA_QL("kartstufftype_t") " cannot be %u", ks);
}
return 1;
}
// kartstuff, ks, value -> plt->??? = value
static int kartstuff_set(lua_State *L)
{
INT32 *kartstuff = *((INT32 **)luaL_checkudata(L, 1, META_KARTSTUFF));
player_t *plr = (player_t*)((void*)kartstuff - offsetof(player_t, 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 CMD building code!");
switch (ks)
{
case k_position:
plr->position = i;
break;
case k_oldposition:
plr->oldposition = i;
break;
case k_positiondelay:
plr->positiondelay = i;
break;
case k_prevcheck:
plr->prevcheck = i;
break;
case k_nextcheck:
plr->nextcheck = i;
break;
/*case k_waypoint:
* lua_pushinteger(L, plr->waypoint);
* break;*/
/*case k_starpostwp:
* lua_pushinteger(L, plr->starpostwp);
* break;*/
case k_starpostflip:
plr->starpostflip = i;
break;
case k_respawn:
plr->respawn = i;
break;
case k_dropdash:
plr->dropdash = i;
break;
case k_throwdir:
plr->throwdir = i;
break;
case k_lapanimation:
plr->karthud[khud_lapanimation] = i;
break;
case k_laphand:
plr->karthud[khud_laphand] = i;
break;
case k_cardanimation:
plr->karthud[khud_cardanimation] = i;
break;
case k_voices:
plr->karthud[khud_voices] = i;
break;
case k_tauntvoices:
plr->karthud[khud_tauntvoices] = i;
break;
case k_instashield:
plr->instashield = i;
break;
case k_enginesnd:
plr->karthud[khud_enginesnd] = i;
break;
case k_floorboost:
plr->floorboost = i;
break;
case k_spinouttype:
plr->spinouttype = i;
break;
case k_drift:
plr->drift = i;
break;
case k_driftend:
if (i > 0)
plr->pflags |= PF_DRIFTEND;
break;
case k_driftcharge:
plr->driftcharge = i;
break;
case k_driftboost:
plr->driftboost = i;
break;
case k_boostcharge:
plr->boostcharge = i;
break;
case k_startboost:
plr->startboost = i;
break;
/*case k_jmp:
plr->pflags |= PF_DRIFTINPUT;
return 1;*/
case k_offroad:
plr->offroad = i;
break;
case k_pogospring:
plr->pogospring = i;
break;
case k_brakestop:
plr->brakestop = i;
break;
case k_waterskip:
plr->waterskip = i;
break;
case k_dashpadcooldown:
plr->dashpadcooldown = i;
break;
case k_boostpower:
plr->boostpower = i;
break;
case k_speedboost:
plr->speedboost = i;
break;
case k_accelboost:
plr->accelboost = i;
break;
case k_boostangle:
plr->boostangle = i;
break;
case k_boostcam:
plr->karthud[khud_boostcam] = i;
break;
case k_destboostcam:
plr->karthud[khud_destboostcam] = i;
break;
case k_timeovercam:
plr->karthud[khud_timeovercam] = i;
break;
case k_aizdriftstrat:
plr->aizdriftstrat = i;
break;
case k_brakedrift:
if (i > 0)
plr->pflags |= PF_BRAKEDRIFT;
break;
case k_itemroulette:
plr->itemroulette = i;
break;
case k_roulettetype:
plr->roulettetype = i;
break;
case k_itemtype:
plr->itemtype = i;
break;
case k_itemamount:
plr->itemamount = i;
break;
case k_itemheld:
if (i > 0)
plr->pflags |= PF_ITEMOUT;
break;
case k_curshield:
plr->curshield = i;
break;
case k_hyudorotimer:
plr->hyudorotimer = i;
break;
case k_stealingtimer:
plr->stealingtimer = i;
break;
case k_stolentimer:
plr->stolentimer = i;
break;
case k_sneakertimer:
plr->sneakertimer = i;
break;
case k_growshrinktimer:
plr->growshrinktimer = i;
break;
case k_squishedtimer:
plr->squishedtimer = i;
break;
case k_rocketsneakertimer:
plr->rocketsneakertimer = i;
break;
case k_invincibilitytimer:
plr->invincibilitytimer = i;
break;
case k_eggmanheld:
if (i > 0)
plr->pflags |= PF_EGGMANOUT;
break;
case k_eggmanexplode:
plr->eggmanexplode = i;
break;
case k_eggmanblame:
plr->eggmanblame = i;
break;
case k_lastjawztarget:
plr->lastjawztarget = i;
break;
case k_bananadrag:
plr->bananadrag = i;
break;
case k_spinouttimer:
plr->spinouttimer = i;
break;
case k_wipeoutslow:
plr->wipeoutslow = i;
break;
case k_justbumped:
plr->justbumped = i;
break;;
case k_comebacktimer:
plr->karmadelay = i;
break;
case k_sadtimer:
plr->sadtimer = i;
break;
// Battle Mode vars
case k_bumper:
plr->bumper = i;
break;
case k_comebackpoints:
plr->karmapoints = i;
break;
case k_comebackmode:
plr->karmamode = i;
break;
case k_wanted:
plr->wanted = i;
break;
case k_yougotem:
plr->karthud[khud_yougotem] = i;
break;
// v1.0.2+ vars
case k_itemblink:
plr->karthud[khud_itemblink] = i;
break;
case k_itemblinkmode:
plr->karthud[khud_itemblinkmode] = i;
break;
case k_getsparks:
if (i > 0)
plr->pflags |= PF_GETSPARKS;
break;
case k_jawztargetdelay:
plr->jawztargetdelay = i;
break;
case k_spectatewait:
plr->spectatewait = i;
break;
case k_growcancel:
plr->growcancel = i;
break;
default:
return luaL_error(L, LUA_QL("kartstufftype_t") " cannot be %u", ks);
}
return 0;
}
// #kartstuff -> 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 -> karthud[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 CMD building 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,"sidemove"))
lua_pushinteger(L, cmd->sidemove);
else if (fastcmp(field,"turning"))
lua_pushinteger(L, cmd->turning);
else if (fastcmp(field,"driftturn"))
lua_pushinteger(L, cmd->turning);
else if (fastcmp(field,"angle"))
lua_pushinteger(L, cmd->angle);
else if (fastcmp(field,"angleturn"))
lua_pushinteger(L, cmd->angle);
else if (fastcmp(field,"throwdir"))
lua_pushinteger(L, cmd->throwdir);
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,"driftturn"))
cmd->turning = (INT16)luaL_checkinteger(L, 3);
else if (fastcmp(field,"angle"))
cmd->angle = (INT16)luaL_checkinteger(L, 3);
else if (fastcmp(field,"angleturn"))
cmd->angle = (INT16)luaL_checkinteger(L, 3);
else if (fastcmp(field,"throwdir"))
cmd->throwdir = (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
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_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;
}