Skip to content

Commit

Permalink
fixed player mobj change; added crash animaton for dropped items
Browse files Browse the repository at this point in the history
  • Loading branch information
kgsws committed Mar 30, 2018
1 parent 3796cbd commit b3cef45
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
26 changes: 25 additions & 1 deletion kg_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ static int func_set_radius(lua_State *L, void *dst, void *o);
static int func_set_mobj(lua_State *L, void *dst, void *o);
static int func_get_ptr(lua_State *L, void *dst, void *o);
static int func_get_sector(lua_State *L, void *dst, void *o);
static int func_set_playermobj(lua_State *L, void *dst, void *o);

static int func_get_removemobj(lua_State *L, void *dst, void *o);
static int func_get_facemobj(lua_State *L, void *dst, void *o);
Expand Down Expand Up @@ -529,7 +530,7 @@ static const lua_table_model_t lua_mobj[] =
// all player values
static const lua_table_model_t lua_player[] =
{
{"mo", offsetof(player_t, mo), LUA_TLIGHTUSERDATA, func_set_mobj, func_get_ptr},
{"mo", offsetof(player_t, mo), LUA_TLIGHTUSERDATA, func_set_playermobj, func_get_ptr},
{"refire", offsetof(player_t, refire), LUA_TNUMBER},
{"colormap", offsetof(player_t, viewmap), LUA_TSTRING, func_set_colormap, func_get_colormap},
{"extralight", offsetof(player_t, extralight), LUA_TNUMBER},
Expand Down Expand Up @@ -1201,6 +1202,29 @@ static int func_set_mobj(lua_State *L, void *dst, void *o)
return 0;
}

// special player mobj changes
static int func_set_playermobj(lua_State *L, void *dst, void *o)
{
thinker_t *th;
mobj_t *mo = *(void**)dst;
player_t *pl = mo->player;

th = lua_touserdata(L, -1);
if(th && th->lua_type != TT_MOBJ)
return luaL_error(L, "invalid thinker type, mobj expected");

// remove player from original mobj
mo->player = NULL;
// add player to new mobj
mo = (mobj_t*)th;
mo->player = pl;

// TODO: server; tell clients about this

*(void**)dst = th;
return 0;
}

// get special type (mobj, player, sector ...)
static int func_get_ptr(lua_State *L, void *dst, void *o)
{
Expand Down
16 changes: 13 additions & 3 deletions p_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -1720,12 +1720,22 @@ boolean PIT_ChangeSector (mobj_t* thing)
// crunch dropped items
if (thing->flags & MF_DROPPED)
{
if(!thing->info->crushstate)
{
#ifdef SERVER
P_RemoveMobj (thing, true);
P_RemoveMobj (thing, true);
#else
if(!netgame)
P_RemoveMobj (thing);
if(!netgame)
P_RemoveMobj (thing);
#endif
} else
{
P_SetMobjAnimation(thing, ANIM_CRUSH, 0);
#ifdef SERVER
// tell clients about this
SV_UpdateMobj(thing, SV_MOBJF_AUTO | SV_MOBJF_STATE);
#endif
}
// keep checking
return true;
}
Expand Down

0 comments on commit b3cef45

Please sign in to comment.