mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-26 12:01:47 +00:00
tabs, thank you vscode for not reading the room
This commit is contained in:
parent
8a2be85563
commit
5d3fb30a07
1 changed files with 119 additions and 119 deletions
238
src/k_director.c
238
src/k_director.c
|
|
@ -37,164 +37,164 @@ INT32 gap[MAXPLAYERS] = {0}; // gap between a given position and their closest p
|
||||||
INT32 boredom[MAXPLAYERS] = {0}; // how long has a given position had no credible attackers?
|
INT32 boredom[MAXPLAYERS] = {0}; // how long has a given position had no credible attackers?
|
||||||
|
|
||||||
fixed_t K_GetFinishGap(INT32 leader, INT32 follower) {
|
fixed_t K_GetFinishGap(INT32 leader, INT32 follower) {
|
||||||
fixed_t dista = players[follower].distancetofinish;
|
fixed_t dista = players[follower].distancetofinish;
|
||||||
fixed_t distb = players[leader].distancetofinish;
|
fixed_t distb = players[leader].distancetofinish;
|
||||||
if (players[follower].position < players[leader].position) {
|
if (players[follower].position < players[leader].position) {
|
||||||
return distb-dista;
|
return distb-dista;
|
||||||
} else {
|
} else {
|
||||||
return dista-distb;
|
return dista-distb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void K_UpdateDirectorPositions(void) {
|
void K_UpdateDirectorPositions(void) {
|
||||||
INT32 playernum;
|
INT32 playernum;
|
||||||
|
|
||||||
memset(sortedplayers, -1, sizeof(sortedplayers));
|
memset(sortedplayers, -1, sizeof(sortedplayers));
|
||||||
for (playernum = 0; playernum < MAXPLAYERS; ++playernum) {
|
for (playernum = 0; playernum < MAXPLAYERS; ++playernum) {
|
||||||
if (playeringame[playernum])
|
if (playeringame[playernum])
|
||||||
sortedplayers[players[playernum].position-1] = playernum;
|
sortedplayers[players[playernum].position-1] = playernum;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(gap, INT32_MAX, sizeof(gap));
|
memset(gap, INT32_MAX, sizeof(gap));
|
||||||
for (playernum = 0; playernum < MAXPLAYERS-1; ++playernum) {
|
for (playernum = 0; playernum < MAXPLAYERS-1; ++playernum) {
|
||||||
if (sortedplayers[playernum] == -1 || sortedplayers[playernum+1] == -1)
|
if (sortedplayers[playernum] == -1 || sortedplayers[playernum+1] == -1)
|
||||||
break;
|
break;
|
||||||
gap[playernum] = P_ScaleFromMap(K_GetFinishGap(sortedplayers[playernum], sortedplayers[playernum+1]), FRACUNIT);
|
gap[playernum] = P_ScaleFromMap(K_GetFinishGap(sortedplayers[playernum], sortedplayers[playernum+1]), FRACUNIT);
|
||||||
if (gap[playernum] >= BREAKAWAYDIST)
|
if (gap[playernum] >= BREAKAWAYDIST)
|
||||||
boredom[playernum] = min(BOREDOMTIME*2, boredom[playernum]+1);
|
boredom[playernum] = min(BOREDOMTIME*2, boredom[playernum]+1);
|
||||||
else if (boredom[playernum] > 0)
|
else if (boredom[playernum] > 0)
|
||||||
boredom[playernum]--;
|
boredom[playernum]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
maxdist = P_ScaleFromMap(players[sortedplayers[0]].distancetofinish, FRACUNIT);
|
maxdist = P_ScaleFromMap(players[sortedplayers[0]].distancetofinish, FRACUNIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean K_CanSwitchDirector(void) {
|
boolean K_CanSwitchDirector(void) {
|
||||||
INT32 *displayplayerp = &displayplayers[0];
|
INT32 *displayplayerp = &displayplayers[0];
|
||||||
if (players[*displayplayerp].trickpanel > 0)
|
if (players[*displayplayerp].trickpanel > 0)
|
||||||
return false;
|
return false;
|
||||||
if (cooldown < SWITCHTIME)
|
if (cooldown < SWITCHTIME)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void K_DirectorSwitch(INT32 player, boolean force) {
|
void K_DirectorSwitch(INT32 player, boolean force) {
|
||||||
if (P_IsDisplayPlayer(&players[player]))
|
if (P_IsDisplayPlayer(&players[player]))
|
||||||
return;
|
return;
|
||||||
if (players[player].exiting)
|
if (players[player].exiting)
|
||||||
return;
|
return;
|
||||||
if (!force && !K_CanSwitchDirector())
|
if (!force && !K_CanSwitchDirector())
|
||||||
return;
|
return;
|
||||||
G_ResetView(1, player, true);
|
G_ResetView(1, player, true);
|
||||||
cooldown = 0;
|
cooldown = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void K_DirectorForceSwitch(INT32 player, INT32 time) {
|
void K_DirectorForceSwitch(INT32 player, INT32 time) {
|
||||||
if (players[player].exiting)
|
if (players[player].exiting)
|
||||||
return;
|
return;
|
||||||
attacker = player;
|
attacker = player;
|
||||||
freeze = time;
|
freeze = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
void K_DirectorFollowAttack(player_t *player, mobj_t *inflictor, mobj_t *source) {
|
void K_DirectorFollowAttack(player_t *player, mobj_t *inflictor, mobj_t *source) {
|
||||||
if (!P_IsDisplayPlayer(player))
|
if (!P_IsDisplayPlayer(player))
|
||||||
return;
|
return;
|
||||||
if (inflictor && inflictor->player)
|
if (inflictor && inflictor->player)
|
||||||
K_DirectorForceSwitch(inflictor->player-players, TRANSFERTIME);
|
K_DirectorForceSwitch(inflictor->player-players, TRANSFERTIME);
|
||||||
if (source && source->player)
|
if (source && source->player)
|
||||||
K_DirectorForceSwitch(source->player-players, TRANSFERTIME);
|
K_DirectorForceSwitch(source->player-players, TRANSFERTIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
void K_DrawDirectorDebugger(void) {
|
void K_DrawDirectorDebugger(void) {
|
||||||
INT32 playernum;
|
INT32 playernum;
|
||||||
INT32 leader;
|
INT32 leader;
|
||||||
INT32 follower;
|
INT32 follower;
|
||||||
INT32 ytxt;
|
INT32 ytxt;
|
||||||
|
|
||||||
if (!cv_kartdebugdirector.value)
|
if (!cv_kartdebugdirector.value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
V_DrawThinString(10, 0, V_70TRANS, va("PLACE"));
|
V_DrawThinString(10, 0, V_70TRANS, va("PLACE"));
|
||||||
V_DrawThinString(40, 0, V_70TRANS, va("CONF?"));
|
V_DrawThinString(40, 0, V_70TRANS, va("CONF?"));
|
||||||
V_DrawThinString(80, 0, V_70TRANS, va("GAP"));
|
V_DrawThinString(80, 0, V_70TRANS, va("GAP"));
|
||||||
V_DrawThinString(120, 0, V_70TRANS, va("BORED"));
|
V_DrawThinString(120, 0, V_70TRANS, va("BORED"));
|
||||||
V_DrawThinString(150, 0, V_70TRANS, va("COOLDOWN: %d", cooldown));
|
V_DrawThinString(150, 0, V_70TRANS, va("COOLDOWN: %d", cooldown));
|
||||||
V_DrawThinString(230, 0, V_70TRANS, va("MAXDIST: %d", maxdist));
|
V_DrawThinString(230, 0, V_70TRANS, va("MAXDIST: %d", maxdist));
|
||||||
|
|
||||||
for (playernum = 0; playernum < MAXPLAYERS-1; ++playernum) {
|
for (playernum = 0; playernum < MAXPLAYERS-1; ++playernum) {
|
||||||
ytxt = 10*playernum+10;
|
ytxt = 10*playernum+10;
|
||||||
leader = sortedplayers[playernum];
|
leader = sortedplayers[playernum];
|
||||||
follower = sortedplayers[playernum+1];
|
follower = sortedplayers[playernum+1];
|
||||||
if (leader == -1 || follower == -1)
|
if (leader == -1 || follower == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
V_DrawThinString(10, ytxt, V_70TRANS, va("%d", playernum));
|
V_DrawThinString(10, ytxt, V_70TRANS, va("%d", playernum));
|
||||||
V_DrawThinString(20, ytxt, V_70TRANS, va("%d", playernum+1));
|
V_DrawThinString(20, ytxt, V_70TRANS, va("%d", playernum+1));
|
||||||
if (players[leader].positiondelay)
|
if (players[leader].positiondelay)
|
||||||
V_DrawThinString(40, ytxt, V_70TRANS, va("NG"));
|
V_DrawThinString(40, ytxt, V_70TRANS, va("NG"));
|
||||||
V_DrawThinString(80, ytxt, V_70TRANS, va("%d", gap[playernum]));
|
V_DrawThinString(80, ytxt, V_70TRANS, va("%d", gap[playernum]));
|
||||||
if (boredom[playernum] >= BOREDOMTIME)
|
if (boredom[playernum] >= BOREDOMTIME)
|
||||||
V_DrawThinString(120, ytxt, V_70TRANS, va("BORED"));
|
V_DrawThinString(120, ytxt, V_70TRANS, va("BORED"));
|
||||||
else
|
else
|
||||||
V_DrawThinString(120, ytxt, V_70TRANS, va("%d", boredom[playernum]));
|
V_DrawThinString(120, ytxt, V_70TRANS, va("%d", boredom[playernum]));
|
||||||
V_DrawThinString(150, ytxt, V_70TRANS, va("%s", player_names[leader]));
|
V_DrawThinString(150, ytxt, V_70TRANS, va("%s", player_names[leader]));
|
||||||
V_DrawThinString(230, ytxt, V_70TRANS, va("%s", player_names[follower]));
|
V_DrawThinString(230, ytxt, V_70TRANS, va("%s", player_names[follower]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void K_UpdateDirector(void) {
|
void K_UpdateDirector(void) {
|
||||||
INT32 *displayplayerp = &displayplayers[0];
|
INT32 *displayplayerp = &displayplayers[0];
|
||||||
INT32 targetposition;
|
INT32 targetposition;
|
||||||
|
|
||||||
if (!cv_director.value)
|
if (!cv_director.value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
K_UpdateDirectorPositions();
|
K_UpdateDirectorPositions();
|
||||||
cooldown++;
|
cooldown++;
|
||||||
|
|
||||||
// handle pending forced switches
|
// handle pending forced switches
|
||||||
if (freeze > 0) {
|
if (freeze > 0) {
|
||||||
if (freeze == 1)
|
if (freeze == 1)
|
||||||
K_DirectorSwitch(attacker, true);
|
K_DirectorSwitch(attacker, true);
|
||||||
freeze--;
|
freeze--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// aaight, time to walk through the standings to find the first interesting pair
|
// aaight, time to walk through the standings to find the first interesting pair
|
||||||
for(targetposition = 0; targetposition < MAXPLAYERS-1; targetposition++) {
|
for(targetposition = 0; targetposition < MAXPLAYERS-1; targetposition++) {
|
||||||
INT32 target;
|
INT32 target;
|
||||||
|
|
||||||
// you are out of players, try again
|
// you are out of players, try again
|
||||||
if (sortedplayers[targetposition+1] == -1)
|
if (sortedplayers[targetposition+1] == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// pair too far apart? try the next one
|
// pair too far apart? try the next one
|
||||||
if (boredom[targetposition] >= BOREDOMTIME)
|
if (boredom[targetposition] >= BOREDOMTIME)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// pair finished? try the next one
|
// pair finished? try the next one
|
||||||
if (players[sortedplayers[targetposition+1]].exiting)
|
if (players[sortedplayers[targetposition+1]].exiting)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// don't risk switching away from forward pairs at race end, might miss something!
|
// don't risk switching away from forward pairs at race end, might miss something!
|
||||||
if (maxdist > PINCHDIST) {
|
if (maxdist > PINCHDIST) {
|
||||||
// if the "next" player is close enough, they should be able to see everyone fine!
|
// if the "next" player is close enough, they should be able to see everyone fine!
|
||||||
// walk back through the standings to find a vantage that gets everyone in frame.
|
// walk back through the standings to find a vantage that gets everyone in frame.
|
||||||
// (also creates a pretty cool effect w/ overtakes at speed)
|
// (also creates a pretty cool effect w/ overtakes at speed)
|
||||||
while (targetposition < MAXPLAYERS && gap[targetposition+1] < WALKBACKDIST) {
|
while (targetposition < MAXPLAYERS && gap[targetposition+1] < WALKBACKDIST) {
|
||||||
targetposition++;
|
targetposition++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
target = sortedplayers[targetposition+1];
|
target = sortedplayers[targetposition+1];
|
||||||
|
|
||||||
// if we're certain the back half of the pair is actually in this position, try to switch
|
// if we're certain the back half of the pair is actually in this position, try to switch
|
||||||
if (*displayplayerp != target && !players[target].positiondelay)
|
if (*displayplayerp != target && !players[target].positiondelay)
|
||||||
K_DirectorSwitch(target, false);
|
K_DirectorSwitch(target, false);
|
||||||
// even if we're not certain, if we're certain we're watching the WRONG player, try to switch
|
// even if we're not certain, if we're certain we're watching the WRONG player, try to switch
|
||||||
if (players[*displayplayerp].position != targetposition && !players[target].positiondelay)
|
if (players[*displayplayerp].position != targetposition && !players[target].positiondelay)
|
||||||
K_DirectorSwitch(target, false);
|
K_DirectorSwitch(target, false);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue