Merge remote-tracking branch 'srb2public/next'

This commit is contained in:
TehRealSalt 2018-11-08 17:37:05 -05:00
commit 1e4d196e5e
13 changed files with 480 additions and 10 deletions

View File

@ -2419,7 +2419,7 @@ void CL_ClearPlayer(INT32 playernum)
// //
// Removes a player from the current game // Removes a player from the current game
// //
static void CL_RemovePlayer(INT32 playernum) static void CL_RemovePlayer(INT32 playernum, INT32 reason)
{ {
// Sanity check: exceptional cases (i.e. c-fails) can cause multiple // Sanity check: exceptional cases (i.e. c-fails) can cause multiple
// kick commands to be issued for the same player. // kick commands to be issued for the same player.
@ -2478,6 +2478,10 @@ static void CL_RemovePlayer(INT32 playernum)
} }
} }
#ifdef HAVE_BLUA
LUAh_PlayerQuit(&players[playernum], reason); // Lua hook for player quitting
#endif
// Reset player data // Reset player data
CL_ClearPlayer(playernum); CL_ClearPlayer(playernum);
@ -2757,6 +2761,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
INT32 pnum, msg; INT32 pnum, msg;
XBOXSTATIC char buf[3 + MAX_REASONLENGTH]; XBOXSTATIC char buf[3 + MAX_REASONLENGTH];
char *reason = buf; char *reason = buf;
kickreason_t kickreason = KR_KICK;
pnum = READUINT8(*p); pnum = READUINT8(*p);
msg = READUINT8(*p); msg = READUINT8(*p);
@ -2831,14 +2836,17 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
{ {
case KICK_MSG_GO_AWAY: case KICK_MSG_GO_AWAY:
HU_AddChatText(va("\x82*%s has been kicked (Go away)", player_names[pnum]), false); HU_AddChatText(va("\x82*%s has been kicked (Go away)", player_names[pnum]), false);
kickreason = KR_KICK;
break; break;
#ifdef NEWPING #ifdef NEWPING
case KICK_MSG_PING_HIGH: case KICK_MSG_PING_HIGH:
HU_AddChatText(va("\x82*%s left the game (Broke ping limit)", player_names[pnum]), false); HU_AddChatText(va("\x82*%s left the game (Broke ping limit)", player_names[pnum]), false);
kickreason = KR_PINGLIMIT;
break; break;
#endif #endif
case KICK_MSG_CON_FAIL: case KICK_MSG_CON_FAIL:
HU_AddChatText(va("\x82*%s left the game (Synch Failure)", player_names[pnum]), false); HU_AddChatText(va("\x82*%s left the game (Synch Failure)", player_names[pnum]), false);
kickreason = KR_SYNCH;
if (M_CheckParm("-consisdump")) // Helps debugging some problems if (M_CheckParm("-consisdump")) // Helps debugging some problems
{ {
@ -2875,21 +2883,26 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
break; break;
case KICK_MSG_TIMEOUT: case KICK_MSG_TIMEOUT:
HU_AddChatText(va("\x82*%s left the game (Connection timeout)", player_names[pnum]), false); HU_AddChatText(va("\x82*%s left the game (Connection timeout)", player_names[pnum]), false);
kickreason = KR_TIMEOUT;
break; break;
case KICK_MSG_PLAYER_QUIT: case KICK_MSG_PLAYER_QUIT:
if (netgame) // not splitscreen/bots if (netgame) // not splitscreen/bots
HU_AddChatText(va("\x82*%s left the game", player_names[pnum]), false); HU_AddChatText(va("\x82*%s left the game", player_names[pnum]), false);
kickreason = KR_LEAVE;
break; break;
case KICK_MSG_BANNED: case KICK_MSG_BANNED:
HU_AddChatText(va("\x82*%s has been banned (Don't come back)", player_names[pnum]), false); HU_AddChatText(va("\x82*%s has been banned (Don't come back)", player_names[pnum]), false);
kickreason = KR_BAN;
break; break;
case KICK_MSG_CUSTOM_KICK: case KICK_MSG_CUSTOM_KICK:
READSTRINGN(*p, reason, MAX_REASONLENGTH+1); READSTRINGN(*p, reason, MAX_REASONLENGTH+1);
HU_AddChatText(va("\x82*%s has been kicked (%s)", player_names[pnum], reason), false); HU_AddChatText(va("\x82*%s has been kicked (%s)", player_names[pnum], reason), false);
kickreason = KR_KICK;
break; break;
case KICK_MSG_CUSTOM_BAN: case KICK_MSG_CUSTOM_BAN:
READSTRINGN(*p, reason, MAX_REASONLENGTH+1); READSTRINGN(*p, reason, MAX_REASONLENGTH+1);
HU_AddChatText(va("\x82*%s has been banned (%s)", player_names[pnum], reason), false); HU_AddChatText(va("\x82*%s has been banned (%s)", player_names[pnum], reason), false);
kickreason = KR_BAN;
break; break;
} }
@ -2918,7 +2931,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
} }
else if (server) else if (server)
{ {
XBOXSTATIC UINT8 buf[0]; XBOXSTATIC UINT8 buf[2];
// Sal: Because kicks (and a lot of other commands) are player-based, we can't tell which player pnum is on the node from a glance. // Sal: Because kicks (and a lot of other commands) are player-based, we can't tell which player pnum is on the node from a glance.
// When we want to remove everyone from a node, we have to get the kicked player's node, then remove everyone on that node manually so we don't miss any. // When we want to remove everyone from a node, we have to get the kicked player's node, then remove everyone on that node manually so we don't miss any.
@ -2930,10 +2943,15 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
#define removethisplayer(otherp) \ #define removethisplayer(otherp) \
if (otherp >= 0) \ if (otherp >= 0) \
{ \ { \
if (otherp != pnum) \
HU_AddChatText(va("\x82*%s left the game (Joined with %s)", player_names[otherp], player_names[pnum]), false); \
buf[0] = (UINT8)otherp; \ buf[0] = (UINT8)otherp; \
SendNetXCmd(XD_REMOVEPLAYER, &buf, 1); \ if (otherp != pnum) \
{ \
HU_AddChatText(va("\x82*%s left the game (Joined with %s)", player_names[otherp], player_names[pnum]), false); \
buf[1] = KR_LEAVE; \
} \
else \
buf[1] = (UINT8)kickreason; \
SendNetXCmd(XD_REMOVEPLAYER, &buf, 2); \
otherp = -1; \ otherp = -1; \
} }
removethisplayer(nodetoplayer[playernode[pnum]]) removethisplayer(nodetoplayer[playernode[pnum]])
@ -3275,6 +3293,8 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
// Xcmd XD_REMOVEPLAYER // Xcmd XD_REMOVEPLAYER
static void Got_RemovePlayer(UINT8 **p, INT32 playernum) static void Got_RemovePlayer(UINT8 **p, INT32 playernum)
{ {
SINT8 pnum, reason;
if (playernum != serverplayer && !IsPlayerAdmin(playernum)) if (playernum != serverplayer && !IsPlayerAdmin(playernum))
{ {
// protect against hacked/buggy client // protect against hacked/buggy client
@ -3290,7 +3310,10 @@ static void Got_RemovePlayer(UINT8 **p, INT32 playernum)
return; return;
} }
CL_RemovePlayer(READUINT8(*p)); pnum = READUINT8(*p);
reason = READUINT8(*p);
CL_RemovePlayer(pnum, reason);
} }
static boolean SV_AddWaitingPlayers(void) static boolean SV_AddWaitingPlayers(void)

View File

@ -483,6 +483,17 @@ extern consvar_t cv_playbackspeed;
#define KICK_MSG_CUSTOM_KICK 7 #define KICK_MSG_CUSTOM_KICK 7
#define KICK_MSG_CUSTOM_BAN 8 #define KICK_MSG_CUSTOM_BAN 8
typedef enum
{
KR_KICK = 1, //Kicked by server
KR_PINGLIMIT = 2, //Broke Ping Limit
KR_SYNCH = 3, //Synch Failure
KR_TIMEOUT = 4, //Connection Timeout
KR_BAN = 5, //Banned by server
KR_LEAVE = 6, //Quit the game
} kickreason_t;
extern boolean server; extern boolean server;
#define client (!server) #define client (!server)
extern boolean dedicated; // For dedicated server extern boolean dedicated; // For dedicated server

View File

@ -32,6 +32,7 @@
#include "fastcmp.h" #include "fastcmp.h"
#include "lua_script.h" #include "lua_script.h"
#include "lua_hook.h" #include "lua_hook.h"
#include "d_clisrv.h"
#include "m_cond.h" #include "m_cond.h"
@ -8661,6 +8662,14 @@ struct {
{"FF_COLORMAPONLY",FF_COLORMAPONLY}, ///< Only copy the colormap, not the lightlevel {"FF_COLORMAPONLY",FF_COLORMAPONLY}, ///< Only copy the colormap, not the lightlevel
{"FF_GOOWATER",FF_GOOWATER}, ///< Used with ::FF_SWIMMABLE. Makes thick bouncey goop. {"FF_GOOWATER",FF_GOOWATER}, ///< Used with ::FF_SWIMMABLE. Makes thick bouncey goop.
#ifdef ESLOPE
// Slope flags
{"SL_NOPHYSICS",SL_NOPHYSICS}, // Don't do momentum adjustment with this slope
{"SL_NODYNAMIC",SL_NODYNAMIC}, // Slope will never need to move during the level, so don't fuss with recalculating it
{"SL_ANCHORVERTEX",SL_ANCHORVERTEX},// Slope is using a Slope Vertex Thing to anchor its position
{"SL_VERTEXSLOPE",SL_VERTEXSLOPE}, // Slope is built from three Slope Vertex Things
#endif
// Angles // Angles
{"ANG1",ANG1}, {"ANG1",ANG1},
{"ANG2",ANG2}, {"ANG2",ANG2},
@ -8789,6 +8798,14 @@ struct {
{"V_CHARCOLORSHIFT",V_CHARCOLORSHIFT}, {"V_CHARCOLORSHIFT",V_CHARCOLORSHIFT},
{"V_ALPHASHIFT",V_ALPHASHIFT}, {"V_ALPHASHIFT",V_ALPHASHIFT},
//Kick Reasons
{"KR_KICK",KR_KICK},
{"KR_PINGLIMIT",KR_PINGLIMIT},
{"KR_SYNCH",KR_SYNCH},
{"KR_TIMEOUT",KR_TIMEOUT},
{"KR_BAN",KR_BAN},
{"KR_LEAVE",KR_LEAVE},
// SRB2Kart // SRB2Kart
// kartitems_t // kartitems_t
{"KITEM_SAD",KITEM_SAD}, // Actual items (can be set for k_itemtype) {"KITEM_SAD",KITEM_SAD}, // Actual items (can be set for k_itemtype)
@ -9662,6 +9679,9 @@ static inline int lib_getenum(lua_State *L)
} else if (fastcmp(word,"maptol")) { } else if (fastcmp(word,"maptol")) {
lua_pushinteger(L, maptol); lua_pushinteger(L, maptol);
return 1; return 1;
} else if (fastcmp(word,"ultimatemode")) {
lua_pushboolean(L, ultimatemode != 0);
return 1;
} else if (fastcmp(word,"mariomode")) { } else if (fastcmp(word,"mariomode")) {
lua_pushboolean(L, mariomode != 0); lua_pushboolean(L, mariomode != 0);
return 1; return 1;

View File

@ -262,6 +262,33 @@ static void wattcp_outch(char s)
} }
#endif #endif
#ifdef USE_WINSOCK
// stupid microsoft makes things complicated
static char *get_WSAErrorStr(int e)
{
static char buf[256]; // allow up to 255 bytes
buf[0] = '\0';
FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
(DWORD)e,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)buf,
sizeof (buf),
NULL);
if (!buf[0]) // provide a fallback error message if no message is available for some reason
sprintf(buf, "Unknown error");
return buf;
}
#undef strerror
#define strerror get_WSAErrorStr
#endif
#ifdef USE_WINSOCK2 #ifdef USE_WINSOCK2
#define inet_ntop inet_ntopA #define inet_ntop inet_ntopA
#define HAVE_NTOP #define HAVE_NTOP
@ -740,9 +767,13 @@ static void SOCK_Send(void)
c = SOCK_SendToAddr(nodesocket[doomcom->remotenode], &clientaddress[doomcom->remotenode]); c = SOCK_SendToAddr(nodesocket[doomcom->remotenode], &clientaddress[doomcom->remotenode]);
} }
if (c == ERRSOCKET && errno != ECONNREFUSED && errno != EWOULDBLOCK) if (c == ERRSOCKET)
{
int e = errno; // save error code so it can't be modified later
if (e != ECONNREFUSED && e != EWOULDBLOCK)
I_Error("SOCK_Send, error sending to node %d (%s) #%u: %s", doomcom->remotenode, I_Error("SOCK_Send, error sending to node %d (%s) #%u: %s", doomcom->remotenode,
SOCK_GetNodeAddress(doomcom->remotenode), errno, strerror(errno)); SOCK_GetNodeAddress(doomcom->remotenode), e, strerror(e));
}
} }
#endif #endif

View File

@ -14,6 +14,9 @@
#ifdef HAVE_BLUA #ifdef HAVE_BLUA
#include "p_local.h" #include "p_local.h"
#include "p_setup.h" // So we can have P_SetupLevelSky #include "p_setup.h" // So we can have P_SetupLevelSky
#ifdef ESLOPE
#include "p_slopes.h" // P_GetZAt
#endif
#include "z_zone.h" #include "z_zone.h"
#include "r_main.h" #include "r_main.h"
#include "r_things.h" #include "r_things.h"
@ -1618,6 +1621,24 @@ static int lib_evCrumbleChain(lua_State *L)
return 0; return 0;
} }
#ifdef ESLOPE
// P_SLOPES
////////////
static int lib_pGetZAt(lua_State *L)
{
pslope_t *slope = *((pslope_t **)luaL_checkudata(L, 1, META_SLOPE));
fixed_t x = luaL_checkfixed(L, 2);
fixed_t y = luaL_checkfixed(L, 3);
//HUDSAFE
if (!slope)
return LUA_ErrInvalid(L, "pslope_t");
lua_pushfixed(L, P_GetZAt(slope, x, y));
return 1;
}
#endif
// R_DEFS // R_DEFS
//////////// ////////////
@ -2571,6 +2592,11 @@ static luaL_Reg lib[] = {
{"P_StartQuake",lib_pStartQuake}, {"P_StartQuake",lib_pStartQuake},
{"EV_CrumbleChain",lib_evCrumbleChain}, {"EV_CrumbleChain",lib_evCrumbleChain},
#ifdef ESLOPE
// p_slopes
{"P_GetZAt",lib_pGetZAt},
#endif
// r_defs // r_defs
{"R_PointToAngle",lib_rPointToAngle}, {"R_PointToAngle",lib_rPointToAngle},
{"R_PointToAngle2",lib_rPointToAngle2}, {"R_PointToAngle2",lib_rPointToAngle2},

View File

@ -43,6 +43,7 @@ enum hook {
hook_PlayerMsg, hook_PlayerMsg,
hook_HurtMsg, hook_HurtMsg,
hook_PlayerSpawn, hook_PlayerSpawn,
hook_PlayerQuit,
hook_MAX // last hook hook_MAX // last hook
}; };
@ -77,5 +78,6 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook
boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg, int mute); // Hook for chat messages boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg, int mute); // Hook for chat messages
boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source); // Hook for hurt messages boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source); // Hook for hurt messages
#define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for G_SpawnPlayer #define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for G_SpawnPlayer
void LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting
#endif #endif

View File

@ -54,6 +54,7 @@ const char *const hookNames[hook_MAX+1] = {
"PlayerMsg", "PlayerMsg",
"HurtMsg", "HurtMsg",
"PlayerSpawn", "PlayerSpawn",
"PlayerQuit",
NULL NULL
}; };
@ -1081,4 +1082,30 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc)
// stack: tables // stack: tables
} }
void LUAh_PlayerQuit(player_t *plr, int reason)
{
hook_p hookp;
if (!gL || !(hooksAvailable[hook_PlayerQuit/8] & (1<<(hook_PlayerQuit%8))))
return;
lua_settop(gL, 0);
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_PlayerQuit)
{
if (lua_gettop(gL) == 0)
{
LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit
lua_pushinteger(gL, reason); // Reason for quitting
}
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
lua_gettable(gL, LUA_REGISTRYINDEX);
lua_pushvalue(gL, -3);
lua_pushvalue(gL, -3);
LUA_Call(gL, 2);
}
lua_settop(gL, 0);
}
#endif #endif

View File

@ -40,6 +40,11 @@ extern lua_State *gL;
#define META_SUBSECTOR "SUBSECTOR_T*" #define META_SUBSECTOR "SUBSECTOR_T*"
#define META_SECTOR "SECTOR_T*" #define META_SECTOR "SECTOR_T*"
#define META_FFLOOR "FFLOOR_T*" #define META_FFLOOR "FFLOOR_T*"
#ifdef ESLOPE
#define META_SLOPE "PSLOPE_T*"
#define META_VECTOR2 "VECTOR2_T"
#define META_VECTOR3 "VECTOR3_T"
#endif
#define META_MAPHEADER "MAPHEADER_T*" #define META_MAPHEADER "MAPHEADER_T*"
#define META_CVAR "CONSVAR_T*" #define META_CVAR "CONSVAR_T*"

View File

@ -16,6 +16,10 @@
#include "p_local.h" #include "p_local.h"
#include "p_setup.h" #include "p_setup.h"
#include "z_zone.h" #include "z_zone.h"
#ifdef ESLOPE
#include "p_slopes.h"
#endif
#include "r_main.h"
#include "lua_script.h" #include "lua_script.h"
#include "lua_libs.h" #include "lua_libs.h"
@ -38,7 +42,13 @@ enum sector_e {
sector_heightsec, sector_heightsec,
sector_camsec, sector_camsec,
sector_lines, sector_lines,
#ifdef ESLOPE
sector_ffloors,
sector_fslope,
sector_cslope
#else
sector_ffloors sector_ffloors
#endif
}; };
static const char *const sector_opt[] = { static const char *const sector_opt[] = {
@ -55,6 +65,10 @@ static const char *const sector_opt[] = {
"camsec", "camsec",
"lines", "lines",
"ffloors", "ffloors",
#ifdef ESLOPE
"f_slope",
"c_slope",
#endif
NULL}; NULL};
enum subsector_e { enum subsector_e {
@ -160,6 +174,10 @@ enum ffloor_e {
ffloor_toplightlevel, ffloor_toplightlevel,
ffloor_bottomheight, ffloor_bottomheight,
ffloor_bottompic, ffloor_bottompic,
#ifdef ESLOPE
ffloor_tslope,
ffloor_bslope,
#endif
ffloor_sector, ffloor_sector,
ffloor_flags, ffloor_flags,
ffloor_master, ffloor_master,
@ -176,6 +194,10 @@ static const char *const ffloor_opt[] = {
"toplightlevel", "toplightlevel",
"bottomheight", "bottomheight",
"bottompic", "bottompic",
#ifdef ESLOPE
"t_slope",
"b_slope",
#endif
"sector", // secnum pushed as control sector userdata "sector", // secnum pushed as control sector userdata
"flags", "flags",
"master", // control linedef "master", // control linedef
@ -185,6 +207,47 @@ static const char *const ffloor_opt[] = {
"alpha", "alpha",
NULL}; NULL};
#ifdef ESLOPE
enum slope_e {
slope_valid = 0,
slope_o,
slope_d,
slope_zdelta,
slope_normal,
slope_zangle,
slope_xydirection,
slope_sourceline,
slope_refpos,
slope_flags
};
static const char *const slope_opt[] = {
"valid",
"o",
"d",
"zdelta",
"normal",
"zangle",
"xydirection",
"sourceline",
"refpos",
"flags",
NULL};
// shared by both vector2_t and vector3_t
enum vector_e {
vector_x = 0,
vector_y,
vector_z
};
static const char *const vector_opt[] = {
"x",
"y",
"z",
NULL};
#endif
static const char *const array_opt[] ={"iterate",NULL}; static const char *const array_opt[] ={"iterate",NULL};
static const char *const valid_opt[] ={"valid",NULL}; static const char *const valid_opt[] ={"valid",NULL};
@ -399,6 +462,14 @@ static int sector_get(lua_State *L)
LUA_PushUserdata(L, sector->ffloors, META_FFLOOR); LUA_PushUserdata(L, sector->ffloors, META_FFLOOR);
lua_pushcclosure(L, sector_iterate, 2); // push lib_iterateFFloors and sector->ffloors as upvalues for the function lua_pushcclosure(L, sector_iterate, 2); // push lib_iterateFFloors and sector->ffloors as upvalues for the function
return 1; return 1;
#ifdef ESLOPE
case sector_fslope: // f_slope
LUA_PushUserdata(L, sector->f_slope, META_SLOPE);
return 1;
case sector_cslope: // c_slope
LUA_PushUserdata(L, sector->c_slope, META_SLOPE);
return 1;
#endif
} }
return 0; return 0;
} }
@ -421,6 +492,10 @@ static int sector_set(lua_State *L)
case sector_heightsec: // heightsec case sector_heightsec: // heightsec
case sector_camsec: // camsec case sector_camsec: // camsec
case sector_ffloors: // ffloors case sector_ffloors: // ffloors
#ifdef ESLOPE
case sector_fslope: // f_slope
case sector_cslope: // c_slope
#endif
default: default:
return luaL_error(L, "sector_t field " LUA_QS " cannot be set.", sector_opt[field]); return luaL_error(L, "sector_t field " LUA_QS " cannot be set.", sector_opt[field]);
case sector_floorheight: { // floorheight case sector_floorheight: { // floorheight
@ -1055,6 +1130,14 @@ static int ffloor_get(lua_State *L)
lua_pushlstring(L, levelflat->name, 8); lua_pushlstring(L, levelflat->name, 8);
return 1; return 1;
} }
#ifdef ESLOPE
case ffloor_tslope:
LUA_PushUserdata(L, *ffloor->t_slope, META_SLOPE);
return 1;
case ffloor_bslope:
LUA_PushUserdata(L, *ffloor->b_slope, META_SLOPE);
return 1;
#endif
case ffloor_sector: case ffloor_sector:
LUA_PushUserdata(L, &sectors[ffloor->secnum], META_SECTOR); LUA_PushUserdata(L, &sectors[ffloor->secnum], META_SECTOR);
return 1; return 1;
@ -1094,6 +1177,10 @@ static int ffloor_set(lua_State *L)
switch(field) switch(field)
{ {
case ffloor_valid: // valid case ffloor_valid: // valid
#ifdef ESLOPE
case ffloor_tslope: // t_slope
case ffloor_bslope: // b_slope
#endif
case ffloor_sector: // sector case ffloor_sector: // sector
case ffloor_master: // master case ffloor_master: // master
case ffloor_target: // target case ffloor_target: // target
@ -1154,6 +1241,181 @@ static int ffloor_set(lua_State *L)
return 0; return 0;
} }
#ifdef ESLOPE
static int slope_get(lua_State *L)
{
pslope_t *slope = *((pslope_t **)luaL_checkudata(L, 1, META_SLOPE));
enum slope_e field = luaL_checkoption(L, 2, slope_opt[0], slope_opt);
if (!slope)
{
if (field == slope_valid) {
lua_pushboolean(L, 0);
return 1;
}
return luaL_error(L, "accessed pslope_t doesn't exist anymore.");
}
switch(field)
{
case slope_valid: // valid
lua_pushboolean(L, 1);
return 1;
case slope_o: // o
LUA_PushUserdata(L, &slope->o, META_VECTOR3);
return 1;
case slope_d: // d
LUA_PushUserdata(L, &slope->d, META_VECTOR2);
return 1;
case slope_zdelta: // zdelta
lua_pushfixed(L, slope->zdelta);
return 1;
case slope_normal: // normal
LUA_PushUserdata(L, &slope->normal, META_VECTOR3);
return 1;
case slope_zangle: // zangle
lua_pushangle(L, slope->zangle);
return 1;
case slope_xydirection: // xydirection
lua_pushangle(L, slope->xydirection);
return 1;
case slope_sourceline: // source linedef
LUA_PushUserdata(L, slope->sourceline, META_LINE);
return 1;
case slope_refpos: // refpos
lua_pushinteger(L, slope->refpos);
return 1;
case slope_flags: // flags
lua_pushinteger(L, slope->flags);
return 1;
}
return 0;
}
static int slope_set(lua_State *L)
{
pslope_t *slope = *((pslope_t **)luaL_checkudata(L, 1, META_SLOPE));
enum slope_e field = luaL_checkoption(L, 2, slope_opt[0], slope_opt);
if (!slope)
return luaL_error(L, "accessed pslope_t doesn't exist anymore.");
if (hud_running)
return luaL_error(L, "Do not alter pslope_t in HUD rendering code!");
switch(field) // todo: reorganize this shit
{
case slope_valid: // valid
case slope_sourceline: // sourceline
case slope_d: // d
case slope_flags: // flags
case slope_normal: // normal
case slope_refpos: // refpos
default:
return luaL_error(L, "pslope_t field " LUA_QS " cannot be set.", slope_opt[field]);
case slope_o: { // o
luaL_checktype(L, 3, LUA_TTABLE);
lua_getfield(L, 3, "x");
if (lua_isnil(L, -1))
{
lua_pop(L, 1);
lua_rawgeti(L, 3, 1);
}
if (!lua_isnil(L, -1))
slope->o.x = luaL_checkfixed(L, -1);
else
slope->o.x = 0;
lua_pop(L, 1);
lua_getfield(L, 3, "y");
if (lua_isnil(L, -1))
{
lua_pop(L, 1);
lua_rawgeti(L, 3, 2);
}
if (!lua_isnil(L, -1))
slope->o.y = luaL_checkfixed(L, -1);
else
slope->o.y = 0;
lua_pop(L, 1);
lua_getfield(L, 3, "z");
if (lua_isnil(L, -1))
{
lua_pop(L, 1);
lua_rawgeti(L, 3, 3);
}
if (!lua_isnil(L, -1))
slope->o.z = luaL_checkfixed(L, -1);
else
slope->o.z = 0;
lua_pop(L, 1);
break;
}
case slope_zdelta: { // zdelta, this is temp until i figure out wtf to do
slope->zdelta = luaL_checkfixed(L, 3);
slope->zangle = R_PointToAngle2(0, 0, FRACUNIT, -slope->zdelta);
P_CalculateSlopeNormal(slope);
break;
}
case slope_zangle: { // zangle
angle_t zangle = luaL_checkangle(L, 3);
if (zangle == ANGLE_90 || zangle == ANGLE_270)
return luaL_error(L, "invalid zangle for slope!");
slope->zangle = zangle;
slope->zdelta = -FINETANGENT(((slope->zangle+ANGLE_90)>>ANGLETOFINESHIFT) & 4095);
P_CalculateSlopeNormal(slope);
break;
}
case slope_xydirection: // xydirection
slope->xydirection = luaL_checkangle(L, 3);
slope->d.x = -FINECOSINE((slope->xydirection>>ANGLETOFINESHIFT) & FINEMASK);
slope->d.y = -FINESINE((slope->xydirection>>ANGLETOFINESHIFT) & FINEMASK);
P_CalculateSlopeNormal(slope);
break;
}
return 0;
}
static int vector2_get(lua_State *L)
{
vector2_t *vec = *((vector2_t **)luaL_checkudata(L, 1, META_VECTOR2));
enum vector_e field = luaL_checkoption(L, 2, vector_opt[0], vector_opt);
if (!vec)
return luaL_error(L, "accessed vector2_t doesn't exist anymore.");
switch(field)
{
case vector_x: lua_pushfixed(L, vec->x); return 1;
case vector_y: lua_pushfixed(L, vec->y); return 1;
default: break;
}
return 0;
}
static int vector3_get(lua_State *L)
{
vector3_t *vec = *((vector3_t **)luaL_checkudata(L, 1, META_VECTOR3));
enum vector_e field = luaL_checkoption(L, 2, vector_opt[0], vector_opt);
if (!vec)
return luaL_error(L, "accessed vector3_t doesn't exist anymore.");
switch(field)
{
case vector_x: lua_pushfixed(L, vec->x); return 1;
case vector_y: lua_pushfixed(L, vec->y); return 1;
case vector_z: lua_pushfixed(L, vec->z); return 1;
default: break;
}
return 0;
}
#endif
static int lib_getMapheaderinfo(lua_State *L) static int lib_getMapheaderinfo(lua_State *L)
{ {
// i -> mapheaderinfo[i-1] // i -> mapheaderinfo[i-1]
@ -1336,6 +1598,26 @@ int LUA_MapLib(lua_State *L)
lua_setfield(L, -2, "__newindex"); lua_setfield(L, -2, "__newindex");
lua_pop(L, 1); lua_pop(L, 1);
#ifdef ESLOPE
luaL_newmetatable(L, META_SLOPE);
lua_pushcfunction(L, slope_get);
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, slope_set);
lua_setfield(L, -2, "__newindex");
lua_pop(L, 1);
luaL_newmetatable(L, META_VECTOR2);
lua_pushcfunction(L, vector2_get);
lua_setfield(L, -2, "__index");
lua_pop(L, 1);
luaL_newmetatable(L, META_VECTOR3);
lua_pushcfunction(L, vector3_get);
lua_setfield(L, -2, "__index");
lua_pop(L, 1);
#endif
luaL_newmetatable(L, META_MAPHEADER); luaL_newmetatable(L, META_MAPHEADER);
lua_pushcfunction(L, mapheaderinfo_get); lua_pushcfunction(L, mapheaderinfo_get);
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");

View File

@ -81,6 +81,9 @@ enum mobj_e {
mobj_extravalue2, mobj_extravalue2,
mobj_cusval, mobj_cusval,
mobj_cvmem, mobj_cvmem,
#ifdef ESLOPE
mobj_standingslope,
#endif
mobj_colorized mobj_colorized
}; };
@ -141,6 +144,9 @@ static const char *const mobj_opt[] = {
"extravalue2", "extravalue2",
"cusval", "cusval",
"cvmem", "cvmem",
#ifdef ESLOPE
"standingslope",
#endif
"colorized", "colorized",
NULL}; NULL};
@ -345,6 +351,11 @@ static int mobj_get(lua_State *L)
case mobj_cvmem: case mobj_cvmem:
lua_pushinteger(L, mo->cvmem); lua_pushinteger(L, mo->cvmem);
break; break;
#ifdef ESLOPE
case mobj_standingslope:
LUA_PushUserdata(L, mo->standingslope, META_SLOPE);
break;
#endif
case mobj_colorized: case mobj_colorized:
lua_pushboolean(L, mo->colorized); lua_pushboolean(L, mo->colorized);
break; break;
@ -655,6 +666,10 @@ static int mobj_set(lua_State *L)
case mobj_cvmem: case mobj_cvmem:
mo->cvmem = luaL_checkinteger(L, 3); mo->cvmem = luaL_checkinteger(L, 3);
break; break;
#ifdef ESLOPE
case mobj_standingslope:
return NOSET;
#endif
case mobj_colorized: case mobj_colorized:
mo->colorized = luaL_checkboolean(L, 3); mo->colorized = luaL_checkboolean(L, 3);
break; break;

View File

@ -22,6 +22,9 @@
#include "byteptr.h" #include "byteptr.h"
#include "p_saveg.h" #include "p_saveg.h"
#include "p_local.h" #include "p_local.h"
#ifdef ESLOPE
#include "p_slopes.h" // for P_SlopeById
#endif
#ifdef LUA_ALLOW_BYTECODE #ifdef LUA_ALLOW_BYTECODE
#include "d_netfil.h" // for LUA_DumpFile #include "d_netfil.h" // for LUA_DumpFile
#endif #endif
@ -458,6 +461,9 @@ enum
ARCH_SIDE, ARCH_SIDE,
ARCH_SUBSECTOR, ARCH_SUBSECTOR,
ARCH_SECTOR, ARCH_SECTOR,
#ifdef ESLOPE
ARCH_SLOPE,
#endif
ARCH_MAPHEADER, ARCH_MAPHEADER,
ARCH_TEND=0xFF, ARCH_TEND=0xFF,
@ -477,6 +483,9 @@ static const struct {
{META_SIDE, ARCH_SIDE}, {META_SIDE, ARCH_SIDE},
{META_SUBSECTOR,ARCH_SUBSECTOR}, {META_SUBSECTOR,ARCH_SUBSECTOR},
{META_SECTOR, ARCH_SECTOR}, {META_SECTOR, ARCH_SECTOR},
#ifdef ESLOPE
{META_SLOPE, ARCH_SLOPE},
#endif
{META_MAPHEADER, ARCH_MAPHEADER}, {META_MAPHEADER, ARCH_MAPHEADER},
{NULL, ARCH_NULL} {NULL, ARCH_NULL}
}; };
@ -681,6 +690,19 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
} }
break; break;
} }
#ifdef ESLOPE
case ARCH_SLOPE:
{
pslope_t *slope = *((pslope_t **)lua_touserdata(gL, myindex));
if (!slope)
WRITEUINT8(save_p, ARCH_NULL);
else {
WRITEUINT8(save_p, ARCH_SLOPE);
WRITEUINT16(save_p, slope->id);
}
break;
}
#endif
case ARCH_MAPHEADER: case ARCH_MAPHEADER:
{ {
mapheader_t *header = *((mapheader_t **)lua_touserdata(gL, myindex)); mapheader_t *header = *((mapheader_t **)lua_touserdata(gL, myindex));
@ -885,6 +907,11 @@ static UINT8 UnArchiveValue(int TABLESINDEX)
case ARCH_SECTOR: case ARCH_SECTOR:
LUA_PushUserdata(gL, &sectors[READUINT16(save_p)], META_SECTOR); LUA_PushUserdata(gL, &sectors[READUINT16(save_p)], META_SECTOR);
break; break;
#ifdef ESLOPE
case ARCH_SLOPE:
LUA_PushUserdata(gL, P_SlopeById(READUINT16(save_p)), META_SLOPE);
break;
#endif
case ARCH_MAPHEADER: case ARCH_MAPHEADER:
LUA_PushUserdata(gL, mapheaderinfo[READUINT16(save_p)], META_MAPHEADER); LUA_PushUserdata(gL, mapheaderinfo[READUINT16(save_p)], META_MAPHEADER);
break; break;

View File

@ -29,7 +29,7 @@ static pslope_t *slopelist = NULL;
static UINT16 slopecount = 0; static UINT16 slopecount = 0;
// Calculate line normal // Calculate line normal
static void P_CalculateSlopeNormal(pslope_t *slope) { void P_CalculateSlopeNormal(pslope_t *slope) {
slope->normal.z = FINECOSINE(slope->zangle>>ANGLETOFINESHIFT); slope->normal.z = FINECOSINE(slope->zangle>>ANGLETOFINESHIFT);
slope->normal.x = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.x); slope->normal.x = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.x);
slope->normal.y = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.y); slope->normal.y = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.y);

View File

@ -14,6 +14,7 @@
#define P_SLOPES_H__ #define P_SLOPES_H__
#ifdef ESLOPE #ifdef ESLOPE
void P_CalculateSlopeNormal(pslope_t *slope);
void P_ResetDynamicSlopes(void); void P_ResetDynamicSlopes(void);
void P_RunDynamicSlopes(void); void P_RunDynamicSlopes(void);
// P_SpawnSlope_Line // P_SpawnSlope_Line