mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Try to fix the podium bot spawning (again)
- Podium waypoint initialize is done always directly after spawning the player, instead of trying to detect it in K_UpdatePodiumWaypoints. - Position is manually calculated for K_InitializePodiumWaypoint, instead of needing K_UpdateAllPlayerPositions to be called. - Instead of calling K_UpdateAllPlayerPositions every time a player spawns, do it at the end of the spawning loops. - Prioritize spawning bots in further away spots instead of 1st available, as spots 1st to 3rd spots are more important.
This commit is contained in:
parent
1dccf5dfea
commit
20dedb6602
6 changed files with 205 additions and 89 deletions
50
src/g_game.c
50
src/g_game.c
|
|
@ -2140,10 +2140,20 @@ void G_Ticker(boolean run)
|
|||
// do player reborns if needed
|
||||
if (G_GamestateUsesLevel() == true)
|
||||
{
|
||||
boolean changed = false;
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (playeringame[i] && players[i].playerstate == PST_REBORN)
|
||||
{
|
||||
G_DoReborn(i);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed == true)
|
||||
{
|
||||
K_UpdateAllPlayerPositions();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2937,40 +2947,8 @@ mapthing_t *G_FindPodiumStart(INT32 playernum)
|
|||
|
||||
if (numcoopstarts)
|
||||
{
|
||||
UINT8 pos = K_GetPodiumPosition(&players[playernum]) - 1;
|
||||
UINT8 i;
|
||||
UINT8 pos = 0;
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (!playeringame[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i == playernum)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (players[i].score > players[playernum].score)
|
||||
{
|
||||
// Final score is the important part.
|
||||
pos++;
|
||||
}
|
||||
else if (players[i].score == players[playernum].score)
|
||||
{
|
||||
if (players[i].bot == false && players[playernum].bot == true)
|
||||
{
|
||||
// Bots are never as important as players.
|
||||
pos++;
|
||||
}
|
||||
else if (i < playernum)
|
||||
{
|
||||
// Port priority is the final tie breaker.
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (G_CheckSpot(playernum, playerstarts[pos % numcoopstarts]))
|
||||
{
|
||||
|
|
@ -2980,8 +2958,10 @@ mapthing_t *G_FindPodiumStart(INT32 playernum)
|
|||
// Your spot isn't available? Find whatever you can get first.
|
||||
for (i = 0; i < numcoopstarts; i++)
|
||||
{
|
||||
if (G_CheckSpot(playernum, playerstarts[i]))
|
||||
return playerstarts[i];
|
||||
if (G_CheckSpot(playernum, playerstarts[(pos + i) % numcoopstarts]))
|
||||
{
|
||||
return playerstarts[(pos + i) % numcoopstarts];
|
||||
}
|
||||
}
|
||||
|
||||
if (doprints)
|
||||
|
|
|
|||
53
src/k_kart.c
53
src/k_kart.c
|
|
@ -8498,59 +8498,6 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
|
|||
return bestwaypoint;
|
||||
}
|
||||
|
||||
static void K_UpdatePodiumWaypoint(player_t *const player, waypoint_t *const waypoint)
|
||||
{
|
||||
// Set the new waypoint.
|
||||
player->currentwaypoint = waypoint;
|
||||
|
||||
if ((waypoint == NULL)
|
||||
|| (waypoint->nextwaypoints == NULL)
|
||||
|| (waypoint->numnextwaypoints == 0U))
|
||||
{
|
||||
// No waypoint, or no next waypoint.
|
||||
player->nextwaypoint = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
// Simply use the first available next waypoint.
|
||||
// No need for split paths in these cutscenes.
|
||||
player->nextwaypoint = waypoint->nextwaypoints[0];
|
||||
}
|
||||
|
||||
static void K_UpdatePodiumWaypoints(player_t *const player)
|
||||
{
|
||||
if ((player != NULL) && (player->mo != NULL))
|
||||
{
|
||||
if ((player->currentwaypoint == NULL)
|
||||
&& (player->position > 0 && player->position <= MAXPLAYERS)
|
||||
&& (leveltime <= introtime || player->jointime <= 1))
|
||||
{
|
||||
// Initialize our first waypoint to the one that
|
||||
// matches our position.
|
||||
K_UpdatePodiumWaypoint(player, K_GetWaypointFromID(player->position));
|
||||
}
|
||||
|
||||
if (player->currentwaypoint != NULL)
|
||||
{
|
||||
const fixed_t xydist = P_AproxDistance(
|
||||
player->mo->x - player->currentwaypoint->mobj->x,
|
||||
player->mo->y - player->currentwaypoint->mobj->y
|
||||
);
|
||||
const fixed_t xyzdist = P_AproxDistance(
|
||||
xydist,
|
||||
player->mo->z - player->currentwaypoint->mobj->z
|
||||
);
|
||||
//const fixed_t speed = P_AproxDistance(player->mo->momx, player->mo->momy);
|
||||
|
||||
if (xyzdist <= player->mo->radius + player->currentwaypoint->mobj->radius)
|
||||
{
|
||||
// Reached waypoint, go to the next waypoint.
|
||||
K_UpdatePodiumWaypoint(player, player->nextwaypoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
void K_UpdateDistanceFromFinishLine(player_t *const player)
|
||||
|
||||
|
|
|
|||
134
src/k_podium.c
134
src/k_podium.c
|
|
@ -62,6 +62,140 @@ boolean K_PodiumSequence(void)
|
|||
return (gamestate == GS_CEREMONY);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
UINT8 K_GetPodiumPosition(player_t *player)
|
||||
|
||||
See header file for description.
|
||||
--------------------------------------------------*/
|
||||
UINT8 K_GetPodiumPosition(player_t *player)
|
||||
{
|
||||
UINT8 position = 1;
|
||||
INT32 i;
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
player_t *other = NULL;
|
||||
if (playeringame[i] == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
other = &players[i];
|
||||
if (other->spectator == true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (other->score > player->score)
|
||||
{
|
||||
// Final score is the important part.
|
||||
position++;
|
||||
}
|
||||
else if (other->score == player->score)
|
||||
{
|
||||
if (other->bot == false && player->bot == true)
|
||||
{
|
||||
// Bots are never as important as players.
|
||||
position++;
|
||||
}
|
||||
else if (i < player - players)
|
||||
{
|
||||
// Port priority is the final tie breaker.
|
||||
position++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
static void K_SetPodiumWaypoint(player_t *const player, waypoint_t *const waypoint)
|
||||
|
||||
Changes the player's current and next waypoints, for
|
||||
use during the podium sequence.
|
||||
|
||||
Input Arguments:-
|
||||
player - The player to update the waypoints of.
|
||||
waypoint - The new current waypoint.
|
||||
|
||||
Return:-
|
||||
None
|
||||
--------------------------------------------------*/
|
||||
static void K_SetPodiumWaypoint(player_t *const player, waypoint_t *const waypoint)
|
||||
{
|
||||
// Set the new waypoint.
|
||||
player->currentwaypoint = waypoint;
|
||||
|
||||
if ((waypoint == NULL)
|
||||
|| (waypoint->nextwaypoints == NULL)
|
||||
|| (waypoint->numnextwaypoints == 0U))
|
||||
{
|
||||
// No waypoint, or no next waypoint.
|
||||
player->nextwaypoint = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
// Simply use the first available next waypoint.
|
||||
// No need for split paths in these cutscenes.
|
||||
player->nextwaypoint = waypoint->nextwaypoints[0];
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
void K_InitializePodiumWaypoint(player_t *const player)
|
||||
|
||||
See header file for description.
|
||||
--------------------------------------------------*/
|
||||
void K_InitializePodiumWaypoint(player_t *const player)
|
||||
{
|
||||
if ((player != NULL) && (player->mo != NULL))
|
||||
{
|
||||
player->position = K_GetPodiumPosition(player);
|
||||
|
||||
if (player->position > 0 && player->position <= MAXPLAYERS)
|
||||
{
|
||||
// Initialize our first waypoint to the one that
|
||||
// matches our position.
|
||||
K_SetPodiumWaypoint(player, K_GetWaypointFromID(player->position));
|
||||
}
|
||||
else
|
||||
{
|
||||
// None does, so remove it if we happen to have one.
|
||||
K_SetPodiumWaypoint(player, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
void K_UpdatePodiumWaypoints(player_t *const player)
|
||||
|
||||
See header file for description.
|
||||
--------------------------------------------------*/
|
||||
void K_UpdatePodiumWaypoints(player_t *const player)
|
||||
{
|
||||
if ((player != NULL) && (player->mo != NULL))
|
||||
{
|
||||
if (player->currentwaypoint != NULL)
|
||||
{
|
||||
const fixed_t xydist = P_AproxDistance(
|
||||
player->mo->x - player->currentwaypoint->mobj->x,
|
||||
player->mo->y - player->currentwaypoint->mobj->y
|
||||
);
|
||||
const fixed_t xyzdist = P_AproxDistance(
|
||||
xydist,
|
||||
player->mo->z - player->currentwaypoint->mobj->z
|
||||
);
|
||||
//const fixed_t speed = P_AproxDistance(player->mo->momx, player->mo->momy);
|
||||
|
||||
if (xyzdist <= player->mo->radius + player->currentwaypoint->mobj->radius)
|
||||
{
|
||||
// Reached waypoint, go to the next waypoint.
|
||||
K_SetPodiumWaypoint(player, player->nextwaypoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
boolean K_StartCeremony(void)
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,56 @@ extern "C" {
|
|||
boolean K_PodiumSequence(void);
|
||||
|
||||
|
||||
/*--------------------------------------------------
|
||||
UINT8 K_GetPodiumPosition(player_t *player);
|
||||
|
||||
Calculates what the player's position would
|
||||
be at the final standings.
|
||||
|
||||
Input Arguments:-
|
||||
player - The player to do the calculation for.
|
||||
|
||||
Return:-
|
||||
The player's final position, as a number
|
||||
between 1 and MAXPLAYERS.
|
||||
--------------------------------------------------*/
|
||||
|
||||
UINT8 K_GetPodiumPosition(player_t *player);
|
||||
|
||||
|
||||
/*--------------------------------------------------
|
||||
void K_InitializePodiumWaypoint(player_t *const player);
|
||||
|
||||
Sets a bot's current waypoint to one matching
|
||||
their final podium position.
|
||||
|
||||
Input Arguments:-
|
||||
player - The podium bot to update.
|
||||
|
||||
Return:-
|
||||
N/A
|
||||
--------------------------------------------------*/
|
||||
|
||||
void K_InitializePodiumWaypoint(player_t *const player);
|
||||
|
||||
|
||||
/*--------------------------------------------------
|
||||
void K_UpdatePodiumWaypoints(player_t *const player);
|
||||
|
||||
Helps a bot move along a predetermined path by
|
||||
updating their current and next waypoints as
|
||||
they move. Intended for the podium sequence.
|
||||
|
||||
Input Arguments:-
|
||||
player - The podium bot to update.
|
||||
|
||||
Return:-
|
||||
N/A
|
||||
--------------------------------------------------*/
|
||||
|
||||
void K_UpdatePodiumWaypoints(player_t *const player);
|
||||
|
||||
|
||||
/*--------------------------------------------------
|
||||
boolean K_StartCeremony(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -11954,7 +11954,10 @@ void P_AfterPlayerSpawn(INT32 playernum)
|
|||
if (CheckForReverseGravity)
|
||||
P_CheckGravity(mobj, false);
|
||||
|
||||
K_UpdateAllPlayerPositions();
|
||||
if (K_PodiumSequence() == true)
|
||||
{
|
||||
K_InitializePodiumWaypoint(p);
|
||||
}
|
||||
}
|
||||
|
||||
// spawn it at a playerspawn mapthing
|
||||
|
|
|
|||
|
|
@ -7373,6 +7373,8 @@ static void P_InitPlayers(void)
|
|||
G_SpawnPlayer(i);
|
||||
}
|
||||
}
|
||||
|
||||
K_UpdateAllPlayerPositions();
|
||||
}
|
||||
|
||||
static void P_InitGametype(void)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue