diff --git a/src/k_hud.cpp b/src/k_hud.cpp index 8a1bd177e..616861b37 100644 --- a/src/k_hud.cpp +++ b/src/k_hud.cpp @@ -229,6 +229,12 @@ static patch_t *kp_voice_remotemuted; static patch_t *kp_voice_remotedeafened; static patch_t *kp_voice_tagactive[3]; +static patch_t *kp_team_bar[2]; +static patch_t *kp_team_sticker[2]; +static patch_t *kp_team_underlay[2][2]; +static patch_t *kp_team_minihead; +static patch_t *kp_team_you; + patch_t *kp_autoroulette; patch_t *kp_autoring; @@ -1044,6 +1050,17 @@ void K_LoadKartHUDGraphics(void) { HU_UpdatePatch(&kp_voice_tagactive[i], "VOXCTA%d", i); } + + HU_UpdatePatch(&kp_team_bar[0], "TEAM_B"); + HU_UpdatePatch(&kp_team_sticker[0], "TEAM_S"); + HU_UpdatePatch(&kp_team_bar[1], "TEAM4B"); + HU_UpdatePatch(&kp_team_sticker[1], "TEAM4S"); + HU_UpdatePatch(&kp_team_underlay[0][0], "TEAM_UL"); + HU_UpdatePatch(&kp_team_underlay[0][1], "TEAM_UR"); + HU_UpdatePatch(&kp_team_underlay[1][0], "TEAM4UL"); + HU_UpdatePatch(&kp_team_underlay[1][1], "TEAM4UR"); + HU_UpdatePatch(&kp_team_minihead, "TEAM4H"); + HU_UpdatePatch(&kp_team_you, "TEAM_YOU"); } // For the item toggle menu @@ -3212,6 +3229,12 @@ INT32 K_GetTransFlagFromFixed(fixed_t value) } } +static INT32 easedallyscore = 0; +static tic_t scorechangecooldown = 0; +// Mildly ugly. Don't want to export this to khud when it's so nicely handled here, +// but HUD hooks run at variable timing based on your actual framerate. +static tic_t lastleveltime = 0; + static void K_drawKartTeamScores(void) { if (G_GametypeHasTeams() == false) @@ -3219,6 +3242,273 @@ static void K_drawKartTeamScores(void) return; } + if (TEAM__MAX != 3) + return; // "maybe someday" - the magic conch + + // I get to write HUD code from scratch, so it's going to be horribly + // verbose and obnoxious. + + UINT8 use4p = (r_splitscreen > 1) ? 1 : 0; + + INT32 basex = BASEVIDWIDTH/2 + 20; + INT32 basey = 0; + INT32 flags = V_HUDTRANS|V_SLIDEIN; + INT32 snapflags = V_SNAPTOTOP|V_SNAPTORIGHT; + if (use4p) + snapflags = V_SNAPTOTOP; + flags |= snapflags; + + // bar stuff, relative to base + INT32 barwidth = 124; + INT32 barheight = 4; + INT32 barx = 5; // 58 + INT32 bary = 12; // -8 + + // team score stuff, relative to base + INT32 scorex = 67; + INT32 scorey = 20; + INT32 scoregap = 8; + INT32 scoreoffset = 1; + + // your score, relative to base + INT32 youx = 108; + INT32 youy = 26; // youy you arrive at the rising sus + + // minimap team leaders, relative to BARS + INT32 facex = -4; + INT32 facey = -4; + INT32 faceoff = 7; + INT32 facesize = 2; + + if (use4p) + { + basex = 127; + basey = 5; + + barwidth = 62; + barheight = 2; + barx = 2; + bary = 6; + + scorex = 33; + scorey = 10; + scoregap = 2; + + facex = -2; + facey = -5; + faceoff = 4; + } + + UINT8 allies = stplyr->team; + UINT8 enemies = (allies == TEAM_ORANGE) ? TEAM_BLUE : TEAM_ORANGE; + + UINT8 *allycolor = R_GetTranslationColormap(TC_RAINBOW, g_teaminfo[allies].color, GTC_CACHE); + UINT8 *enemycolor = R_GetTranslationColormap(TC_RAINBOW, g_teaminfo[enemies].color, GTC_CACHE); + + UINT16 allyscore = g_teamscores[allies]; + UINT16 enemyscore = g_teamscores[enemies]; + UINT16 totalscore = allyscore + enemyscore; + + using srb2::Draw; + srb2::Draw::Font scorefont = Draw::Font::kTimer; + + if (totalscore > 99) + { + scorefont = Draw::Font::kThinTimer; + scoreoffset--; + } + + if (use4p) + { + if (totalscore > 99) + { + scorefont = Draw::Font::kPing; + } + else + { + scorefont = Draw::Font::kZVote; + } + } + + UINT32 youscore = stplyr->teamimportance; + if (gametyperules & GTR_POINTLIMIT) + { + youscore = stplyr->roundscore; + } + + UINT8 ri = 6; // "ramp index", picks drawfill color from team skincolors + INT32 allyfill = skincolors[g_teaminfo[allies].color].ramp[ri]; + INT32 enemyfill = skincolors[g_teaminfo[enemies].color].ramp[ri]; + + INT32 winning = 0; + if (allyscore > enemyscore) + winning = 1; + else if (enemyscore > allyscore) + winning = -1; + + UINT8 *winnercolor = (winning == 1) ? + R_GetTranslationColormap(TC_RAINBOW, g_teaminfo[allies].color, GTC_CACHE) : + R_GetTranslationColormap(TC_RAINBOW, g_teaminfo[enemies].color, GTC_CACHE); + + if (scorechangecooldown) + scorechangecooldown--; + + // prevent giga flicker on team scoring + if (easedallyscore == allyscore) + { + // :O + } + else + { + if (lastleveltime != leveltime) // Timing consistency + { + INT32 delta = abs(easedallyscore - allyscore); // how wrong is display score? + + if (scorechangecooldown == 0) + { + if (allyscore > easedallyscore) + { + easedallyscore++; + if (!cv_reducevfx.value) + allycolor = R_GetTranslationColormap(TC_BLINK, SKINCOLOR_WHITE, GTC_CACHE); + } + else + { + easedallyscore--; + if (!cv_reducevfx.value) + enemycolor = R_GetTranslationColormap(TC_BLINK, SKINCOLOR_WHITE, GTC_CACHE); + } + scorechangecooldown = TICRATE/delta; + } + } + + // replace scores with eased scores + allyscore = easedallyscore; + enemyscore = totalscore - allyscore; + } + + lastleveltime = leveltime; + + fixed_t enemypercent = FixedDiv(enemyscore*FRACUNIT, totalscore*FRACUNIT); + // fixed_t allypercent = FixedDiv(allyscore*FRACUNIT, totalscore*FRACUNIT); + INT32 enemywidth = FixedInt(FixedMul(enemypercent, barwidth*FRACUNIT)); + INT32 allywidth = barwidth - enemywidth; + + player_t *bestenemy = NULL; + INT32 bestenemyscore = -1; + player_t *bestally = NULL; + INT32 bestallyscore = -1; + + boolean useroundscore = false; + if (gametyperules & GTR_POINTLIMIT) + useroundscore = true; + + for (UINT8 i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator || players[i].team == TEAM_UNASSIGNED) + continue; + + INT32 score = useroundscore ? players[i].roundscore : players[i].teamimportance; + + if (players[i].team == allies) + { + if (bestallyscore < score || (bestallyscore == score && useroundscore == false && players[i].teamposition < bestally->teamposition)) + { + bestallyscore = score; + bestally = &players[i]; + } + } + else + { + if (bestenemyscore < score || (bestenemyscore == score && useroundscore == false && players[i].teamposition < bestenemy->teamposition)) + { + bestenemyscore = score; + bestenemy = &players[i]; + } + } + } + + // Draw at the top and bottom of the screen in 4P. + boolean goagain = use4p; + + draw: + + V_DrawScaledPatch(basex, basey, flags, kp_team_sticker[use4p]); + V_DrawMappedPatch(basex, basey, flags, kp_team_underlay[use4p][0], enemycolor); + V_DrawMappedPatch(basex, basey, flags, kp_team_underlay[use4p][1], allycolor); + V_DrawMappedPatch(basex, basey, flags, kp_team_bar[use4p], winnercolor); + if (!use4p) + V_DrawScaledPatch(basex, basey, flags, kp_team_you); + + if (V_GetHUDTranslucency(0) != 10) + return; + + V_DrawFill(basex+barx, basey+bary, enemywidth, barheight, enemyfill|flags); + V_DrawFill(basex+barx+enemywidth, basey+bary, allywidth, barheight, allyfill|flags); + + // Goofy, but we want the winning team to draw on top + boolean drawally = (winning != 1); + for (UINT8 drew = 0; drew < 2; drew++) + { + if (use4p) + { + if (bestenemy && !drawally) + { + V_DrawMappedPatch(basex+barx+facex+enemywidth-facesize+faceoff, basey+bary+facey, flags|V_FLIP, kp_team_minihead, enemycolor); + } + if (bestally && drawally) + { + V_DrawMappedPatch(basex+barx+facex+enemywidth+facesize, basey+bary+facey, flags, kp_team_minihead, allycolor); + } + } + else + { + if (bestenemy && !drawally) + { + UINT8 *colormap = R_GetTranslationColormap(bestenemy->skin, static_cast(bestenemy->skincolor), GTC_CACHE); + V_DrawMappedPatch(basex+barx+facex+enemywidth-facesize+faceoff, basey+bary+facey, flags|V_FLIP, faceprefix[bestenemy->skin][FACE_MINIMAP], colormap); + } + if (bestally && drawally) + { + UINT8 *colormap = R_GetTranslationColormap(bestally->skin, static_cast(bestally->skincolor), GTC_CACHE); + V_DrawMappedPatch(basex+barx+facex+enemywidth+facesize, basey+bary+facey, flags, faceprefix[bestally->skin][FACE_MINIMAP], colormap); + } + } + + + drawally = !drawally; + } + + Draw enemynum = Draw(basex+scorex-scoregap, basey+scorey).flags(flags).font(scorefont).align(Draw::Align::kRight).colorize(g_teaminfo[enemies].color); + Draw allynum = Draw(basex+scorex+scoregap+scoreoffset, basey+scorey).flags(flags).font(scorefont).align(Draw::Align::kLeft).colorize(g_teaminfo[allies].color); + + if (totalscore > 99) + { + enemynum.text("{:03}", enemyscore); + allynum.text("{:03}", allyscore); + } + else + { + enemynum.text("{:02}", enemyscore); + allynum.text("{:02}", allyscore); + } + + if (!use4p) + { + Draw you = Draw(basex+youx, basey+youy).flags(flags).font(Draw::Font::kZVote).colorize(g_teaminfo[allies].color); + you.text("{:02}", youscore); + } + + if (goagain) + { + goagain = false; + flags |= V_SNAPTOBOTTOM; + flags &= ~V_SNAPTOTOP; + basey = 170; + goto draw; + } + + /* for (INT32 i = TEAM_UNASSIGNED+1; i < TEAM__MAX; i++) { INT32 x = BASEVIDWIDTH/2; @@ -3238,6 +3528,7 @@ static void K_drawKartTeamScores(void) V_DrawCenteredString(x, 15, g_teaminfo[i].chat_color, va("+%d", individual_score)); } } + */ } static boolean K_drawKartLaps(void) @@ -6857,7 +7148,7 @@ void K_drawKartHUD(void) if (r_splitscreen == 1) { - if (LUA_HudEnabled(hud_time)) + if (LUA_HudEnabled(hud_time) && ((gametyperules & GTR_TIMELIMIT) || cv_drawtimer.value)) { K_drawKart2PTimestamp(); } @@ -6869,7 +7160,7 @@ void K_drawKartHUD(void) } else if (viewnum == r_splitscreen) { - if (LUA_HudEnabled(hud_time)) + if (LUA_HudEnabled(hud_time) && ((gametyperules & GTR_TIMELIMIT) || cv_drawtimer.value)) { K_drawKart4PTimestamp(); } diff --git a/src/k_kart.c b/src/k_kart.c index 7ccf885d5..0371c1134 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1478,6 +1478,9 @@ static boolean K_TryDraft(player_t *player, mobj_t *dest, fixed_t minDist, fixed return false; } + if (dest->player && G_SameTeam(player, dest->player)) + draftdistance = FixedMul(draftdistance, K_TeamComebackMultiplier(player)); + // Not close enough to draft. if (dist > draftdistance && draftdistance > 0) { @@ -4147,7 +4150,9 @@ void K_SpawnAmps(player_t *player, UINT8 amps, mobj_t *impact) scaledamps /= 2; */ - for (int i = 0; i < (scaledamps/2); i++) + UINT16 finalreward = max(1, scaledamps/2); + + for (int i = 0; i < finalreward; i++) { mobj_t *pickup = P_SpawnMobj(impact->x, impact->y, impact->z, MT_AMPS); pickup->momx = P_RandomRange(PR_ITEM_DEBRIS, -40*mapobjectscale, 40*mapobjectscale); @@ -15503,6 +15508,9 @@ fixed_t K_GetGradingMultAdjustment(player_t *player) fixed_t stablerate = 3*FRACUNIT/10; // how low is your placement before losing XP? 4*FRACUNIT/10 = top 40% of race will gain fixed_t result = 0; + if (g_teamplay) + power = 3 * power / 4; + INT32 live_players = 0; // players we are competing against for (INT32 i = 0; i < MAXPLAYERS; i++) @@ -15714,4 +15722,33 @@ boolean K_TryPickMeUp(mobj_t *m1, mobj_t *m2) return true; } +fixed_t K_TeamComebackMultiplier(player_t *player) +{ + INT32 myteam = player->team; + INT32 theirteam = (myteam == TEAM_ORANGE) ? TEAM_BLUE : TEAM_ORANGE; + + if (g_teamscores[myteam] >= g_teamscores[theirteam]) + return FRACUNIT; + + UINT32 ourdistance = 0; + UINT32 theirdistance = 0; + + for (UINT8 i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + continue; + + if (players[i].team == myteam) + ourdistance += K_GetItemRouletteDistance(&players[i], players[i].itemRoulette.playing); + else + theirdistance += K_GetItemRouletteDistance(&players[i], players[i].itemRoulette.playing); + } + + fixed_t multiplier = FixedDiv(ourdistance, theirdistance); + multiplier = min(multiplier, 3*FRACUNIT); + multiplier = max(multiplier, FRACUNIT); + + return multiplier; +} + //} diff --git a/src/k_kart.h b/src/k_kart.h index ccc32c6f9..cd5dee152 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -322,6 +322,8 @@ void K_BotHitPenalty(player_t *player); boolean K_TryPickMeUp(mobj_t *m1, mobj_t *m2); +fixed_t K_TeamComebackMultiplier(player_t *player); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/p_inter.c b/src/p_inter.c index 6d83c4a8f..2df953dec 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -3209,6 +3209,26 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da K_SpawnAmps(source->player, K_PvPAmpReward((type == DMG_WHUMBLE) ? 30 : 20, source->player, player), target); K_BotHitPenalty(player); + if (G_SameTeam(source->player, player)) + { + if (type != DMG_EXPLODE) + type = DMG_STUMBLE; + } + else + { + for (UINT8 i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator || !players[i].mo || P_MobjWasRemoved(players[i].mo)) + continue; + if (!G_SameTeam(source->player, &players[i])) + continue; + if (source->player == &players[i]) + continue; + K_SpawnAmps(&players[i], FixedInt(FixedMul(5, K_TeamComebackMultiplier(player))), target); + } + } + + // Extend the invincibility if the hit was a direct hit. if (inflictor == source && source->player->invincibilitytimer && !K_PowerUpRemaining(source->player, POWERUP_SMONITOR)) diff --git a/src/p_spec.c b/src/p_spec.c index db4cc3d4e..5c80fc35f 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2071,6 +2071,20 @@ static void K_HandleLapIncrement(player_t *player) K_SpawnDriftElectricSparks(player, SKINCOLOR_SILVER, false); K_SpawnAmps(player, 35, player->mo); + if (g_teamplay) + { + for (UINT8 j = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[j] || players[j].spectator || !players[j].mo || P_MobjWasRemoved(players[j].mo)) + continue; + if (!G_SameTeam(player, &players[j])) + continue; + if (player == &players[j]) + continue; + K_SpawnAmps(&players[j], 10, player->mo); + } + } + rainbowstartavailable = false; }