From 54ae277bff20522dab31a43f02098e488bc00877 Mon Sep 17 00:00:00 2001 From: Latapostrophe Date: Sun, 17 Feb 2019 23:39:00 +0100 Subject: [PATCH 1/4] Expose battlefullscreen and battlecomebacktimer huds to lua --- src/k_kart.c | 18 +++++++++++++++--- src/lua_hud.h | 2 ++ src/lua_hudlib.c | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index b006ae3b..39da4a22 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7838,6 +7838,11 @@ static void K_drawBattleFullscreen(void) INT32 y = -64+(stplyr->kartstuff[k_cardanimation]); // card animation goes from 0 to 164, 164 is the middle of the screen INT32 splitflags = V_SNAPTOTOP; // I don't feel like properly supporting non-green resolutions, so you can have a misuse of SNAPTO instead fixed_t scale = FRACUNIT; + boolean drawcomebacktimer = true; // lazy hack because it's cleaner in the long run. +#ifdef HAVE_BLUA + if (!LUA_HudEnabled(hud_battlecomebacktimer)) + drawcomebacktimer = false; +#endif if (splitscreen) { @@ -7889,7 +7894,7 @@ static void K_drawBattleFullscreen(void) else K_drawKartFinish(); } - else if (stplyr->kartstuff[k_bumper] <= 0 && stplyr->kartstuff[k_comebacktimer] && comeback && !stplyr->spectator) + else if (stplyr->kartstuff[k_bumper] <= 0 && stplyr->kartstuff[k_comebacktimer] && comeback && !stplyr->spectator && drawcomebacktimer) { UINT16 t = stplyr->kartstuff[k_comebacktimer]/(10*TICRATE); INT32 txoff, adjust = (splitscreen > 1) ? 4 : 6; // normal string is 8, kart string is 12, half of that for ease @@ -8449,8 +8454,15 @@ void K_drawKartHUD(void) if (battlefullscreen) { - K_drawBattleFullscreen(); - return; +#ifdef HAVE_BLUA + if (LUA_HudEnabled(hud_battlefullscreen)) + { +#endif + K_drawBattleFullscreen(); + return; +#ifdef HAVE_BLUA + } // yes we legit checked if we had lua to close a single bracket. Not my proudest code edit tbh. +#endif } // Draw the item window diff --git a/src/lua_hud.h b/src/lua_hud.h index 4fbbbace..88d7fd6b 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -21,6 +21,8 @@ enum hud { hud_position, hud_minirankings, // Rankings to the left hud_battlebumpers, // mini rankings battle bumpers. + hud_battlefullscreen, // battle huge text (WAIT, WIN, LOSE ...) + karma comeback time + hud_battlecomebacktimer, // comeback timer in battlefullscreen. separated for ease of use. hud_wanted, hud_speedometer, hud_freeplay, diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index cd8e0392..e0a360ad 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -48,6 +48,8 @@ static const char *const hud_disable_options[] = { "position", "minirankings", // Gametype rankings to the left "battlerankingsbumpers", // bumper drawer for battle. Useful if you want to make a custom battle gamemode without bumpers being involved. + "battlefullscreen", // battlefullscreen func (WAIT, ATTACK OR PROTECT ...) + "battlecomebacktimer", // come back timer in battlefullscreen "wanted", "speedometer", "freeplay", From cb742284695707c49cee8684978d0a81a0f170df Mon Sep 17 00:00:00 2001 From: Latapostrophe Date: Sun, 26 May 2019 11:19:26 +0200 Subject: [PATCH 2/4] fix banana's SpinPlayer using the wrong inflictor --- src/p_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_map.c b/src/p_map.c index 2c766349..fd1047da 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1076,7 +1076,7 @@ static boolean PIT_CheckThing(mobj_t *thing) S_StartSound(tmthing, sfx_bsnipe); // Player Damage - K_SpinPlayer(tmthing->player, thing->target, 0, tmthing, (thing->type == MT_BANANA || thing->type == MT_BANANA_SHIELD)); + K_SpinPlayer(tmthing->player, thing->target, 0, thing, (thing->type == MT_BANANA || thing->type == MT_BANANA_SHIELD)); // Other Item Damage if (thing->eflags & MFE_VERTICALFLIP) From a7917cb4b9e62ff73c0ae327d973d19e9f077df4 Mon Sep 17 00:00:00 2001 From: Latapostrophe Date: Sun, 26 May 2019 15:05:10 +0200 Subject: [PATCH 3/4] Lua fixes + new drawOnMinimap function --- src/k_kart.c | 8 +-- src/lua_hudlib.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++ src/p_map.c | 2 +- src/p_user.c | 4 +- 4 files changed, 181 insertions(+), 7 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index e32295ad..fc155229 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8184,7 +8184,7 @@ static void K_drawBattleFullscreen(void) #ifdef HAVE_BLUA if (!LUA_HudEnabled(hud_battlecomebacktimer)) drawcomebacktimer = false; -#endif +#endif if (splitscreen) { @@ -8796,13 +8796,13 @@ void K_drawKartHUD(void) { #ifdef HAVE_BLUA if (LUA_HudEnabled(hud_battlefullscreen)) - { -#endif + { +#endif K_drawBattleFullscreen(); return; #ifdef HAVE_BLUA } // yes we legit checked if we had lua to close a single bracket. Not my proudest code edit tbh. -#endif +#endif } // Draw the item window diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 3a72a32d..22c89a23 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -383,6 +383,179 @@ static int libd_drawScaled(lua_State *L) return 0; } +// KART: draw patch on minimap from x, y coordinates on the map +static int libd_drawOnMinimap(lua_State *L) +{ + fixed_t x, y, scale; // coordinates of the object + patch_t *patch; // patch we want to draw + const UINT8 *colormap = NULL; // do we want to colormap this patch? + boolean centered; // the patch is centered and doesn't need readjusting on x/y coordinates. + + // variables used to replicate k_kart's mmap drawer: + INT32 lumpnum; + patch_t *AutomapPic; + INT32 mx, my; + INT32 splitflags, minimaptrans; + + // base position of the minimap which also takes splits into account: + INT32 MM_X, MM_Y; + + // variables used for actually drawing the icon: + fixed_t amnumxpos, amnumypos; + INT32 amxpos, amypos; + + node_t *bsp = &nodes[numnodes-1]; + fixed_t maxx, minx, maxy, miny; + + fixed_t mapwidth, mapheight; + fixed_t xoffset, yoffset; + fixed_t xscale, yscale, zoom; + fixed_t patchw, patchh; + + HUDONLY // only run this function in hud hooks + x = luaL_checkinteger(L, 1); + y = luaL_checkinteger(L, 2); + scale = luaL_checkinteger(L, 3); + patch = *((patch_t **)luaL_checkudata(L, 4, META_PATCH)); + if (!lua_isnoneornil(L, 5)) + colormap = *((UINT8 **)luaL_checkudata(L, 5, META_COLORMAP)); + centered = lua_optboolean(L, 6); + + // replicate exactly what source does for its minimap drawer; AKA hardcoded garbo. + + // first, check what position the mmap is supposed to be in (pasted from k_kart.c): + MM_X = BASEVIDWIDTH - 50; // 270 + MM_Y = (BASEVIDHEIGHT/2)-16; // 84 + if (splitscreen) + { + MM_Y = (BASEVIDHEIGHT/2); + if (splitscreen > 1) // 3P : bottom right + { + MM_X = (3*BASEVIDWIDTH/4); + MM_Y = (3*BASEVIDHEIGHT/4); + + if (splitscreen > 2) // 4P: centered + { + MM_X = (BASEVIDWIDTH/2); + MM_Y = (BASEVIDHEIGHT/2); + } + } + } + + // splitscreen flags + splitflags = (splitscreen == 3 ? 0 : V_SNAPTORIGHT); // flags should only be 0 when it's centered (4p split) + + // translucency: + if (timeinmap > 105) + { + minimaptrans = cv_kartminimap.value; + if (timeinmap <= 113) + minimaptrans = ((((INT32)timeinmap) - 105)*minimaptrans)/(113-105); + if (!minimaptrans) + return 0; + } + else + return 0; + + + minimaptrans = ((10-minimaptrans)<width/2); + my = MM_Y - (AutomapPic->height/2); + + // let offsets transfer to the heads, too! + if (encoremode) + mx += SHORT(AutomapPic->leftoffset); + else + mx -= SHORT(AutomapPic->leftoffset); + my -= SHORT(AutomapPic->topoffset); + + // now that we have replicated this behavior, we can draw an icon from our supplied x, y coordinates by replicating k_kart.c's totally understandable uncommented code!!! + + // get map boundaries using nodes + maxx = maxy = INT32_MAX; + minx = miny = INT32_MIN; + minx = bsp->bbox[0][BOXLEFT]; + maxx = bsp->bbox[0][BOXRIGHT]; + miny = bsp->bbox[0][BOXBOTTOM]; + maxy = bsp->bbox[0][BOXTOP]; + + if (bsp->bbox[1][BOXLEFT] < minx) + minx = bsp->bbox[1][BOXLEFT]; + if (bsp->bbox[1][BOXRIGHT] > maxx) + maxx = bsp->bbox[1][BOXRIGHT]; + if (bsp->bbox[1][BOXBOTTOM] < miny) + miny = bsp->bbox[1][BOXBOTTOM]; + if (bsp->bbox[1][BOXTOP] > maxy) + maxy = bsp->bbox[1][BOXTOP]; + + // You might be wondering why these are being bitshift here + // it's because mapwidth and height would otherwise overflow for maps larger than half the size possible... + // map boundaries and sizes will ALWAYS be whole numbers thankfully + // later calculations take into consideration that these are actually not in terms of FRACUNIT though + minx >>= FRACBITS; + maxx >>= FRACBITS; + miny >>= FRACBITS; + maxy >>= FRACBITS; + + // these are our final map boundaries: + mapwidth = maxx - minx; + mapheight = maxy - miny; + + // These should always be small enough to be bitshift back right now + xoffset = (minx + mapwidth/2)<width, mapwidth); + yscale = FixedDiv(AutomapPic->height, mapheight); + zoom = FixedMul(min(xscale, yscale), FRACUNIT-FRACUNIT/20); + + amnumxpos = (FixedMul(x, zoom) - FixedMul(xoffset, zoom)); + amnumypos = -(FixedMul(y, zoom) - FixedMul(yoffset, zoom)); + + if (encoremode) + amnumxpos = -amnumxpos; + + // scale patch coords + patchw = patch->width*scale /2; + patchh = patch->height*scale /2; + + if (centered) + patchw = patchh = 0; // patch is supposedly already centered, don't butt in. + + amxpos = amnumxpos + ((mx + AutomapPic->width/2)<height/2)<state == &states[S_MINEEXPLOSION1]) K_ExplodePlayer(tmthing->player, thing->target, thing); else - K_SpinPlayer(tmthing->player, thing->target, 0, tmthing, false); + K_SpinPlayer(tmthing->player, thing->target, 0, thing, false); return true; } diff --git a/src/p_user.c b/src/p_user.c index a9ea8443..c43e0929 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -7377,7 +7377,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall if (P_CameraThinker(player, thiscam, resetcalled)) return true; - + if (thiscam == &camera[1]) // Camera 2 { num = 1; @@ -8495,7 +8495,7 @@ void P_PlayerThink(player_t *player) if (player->powers[pw_invulnerability] && player->powers[pw_invulnerability] < UINT16_MAX) player->powers[pw_invulnerability]--; - if (player->powers[pw_flashing] && player->powers[pw_flashing] < UINT16_MAX && + if (player->powers[pw_flashing] && player->powers[pw_flashing] < UINT16_MAX && (player->spectator || player->powers[pw_flashing] < K_GetKartFlashing(player))) player->powers[pw_flashing]--; From c28e1702eb8d8df83245a901bd1b028b46e86758 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Tue, 28 May 2019 06:56:35 -0500 Subject: [PATCH 4/4] Don't guard the return --- src/k_kart.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index fc155229..9964140d 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8796,13 +8796,9 @@ void K_drawKartHUD(void) { #ifdef HAVE_BLUA if (LUA_HudEnabled(hud_battlefullscreen)) - { #endif K_drawBattleFullscreen(); - return; -#ifdef HAVE_BLUA - } // yes we legit checked if we had lua to close a single bracket. Not my proudest code edit tbh. -#endif + return; } // Draw the item window