Skins, rudimentary ticcmd building for bots

This commit is contained in:
Sally Cochenour 2020-03-28 12:39:27 -04:00
parent e5ae9d1513
commit ff621d3e46
9 changed files with 214 additions and 313 deletions

View file

@ -49,6 +49,7 @@
#include "k_kart.h"
#include "k_battle.h"
#include "k_pwrlv.h"
#include "k_bot.h"
#ifdef CLIENT_LOADINGSCREEN
// cl loading screen
@ -3612,6 +3613,7 @@ static void Got_RemovePlayer(UINT8 **p, INT32 playernum)
static void Got_AddBot(UINT8 **p, INT32 playernum)
{
INT16 newplayernum;
UINT8 skinnum = 0;
if (playernum != serverplayer && !IsPlayerAdmin(playernum))
{
@ -3629,6 +3631,7 @@ static void Got_AddBot(UINT8 **p, INT32 playernum)
}
newplayernum = (UINT8)READUINT8(*p);
skinnum = (UINT8)READUINT8(*p);
CONS_Debug(DBG_NETPLAY, "addbot: %d\n", newplayernum);
@ -3643,7 +3646,9 @@ static void Got_AddBot(UINT8 **p, INT32 playernum)
players[newplayernum].splitscreenindex = 0;
players[newplayernum].bot = true;
playerconsole[newplayernum] = 0;
players[newplayernum].skincolor = skins[skinnum].prefcolor;
sprintf(player_names[newplayernum], "%s", skins[skinnum].realname);
SetPlayerSkinByNum(newplayernum, skinnum);
if (netgame)
{
@ -3777,6 +3782,8 @@ boolean SV_SpawnServer(void)
if (!dedicated)
CL_ConnectToServer(false);
else doomcom->numslots = 1;
K_AddBots(7); // test
}
return SV_AddWaitingPlayers();

View file

@ -49,7 +49,6 @@
#include "k_kart.h" // SRB2kart
#include "k_battle.h"
#include "k_pwrlv.h"
#include "k_bot.h"
#include "y_inter.h"
#ifdef NETGAME_DEVMODE
@ -2737,8 +2736,6 @@ void D_MapChange(INT32 mapnum, INT32 newgametype, boolean pencoremode, boolean r
return;
}
K_AddBots(13);
chmappending++;
if (netgame)
WRITEUINT32(buf_p, M_RandomizedSeed()); // random seed

View file

@ -1297,6 +1297,11 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
return;
}
if (K_PlayerUsesBotMovement(player))
{
return;
}
switch (ssplayer)
{
case 2:
@ -1601,9 +1606,8 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
//Reset away view if a command is given.
if ((cmd->forwardmove || cmd->sidemove || cmd->buttons)
&& ! r_splitscreen && displayplayers[0] != consoleplayer && ssplayer == 1)
&& !r_splitscreen && displayplayers[0] != consoleplayer && ssplayer == 1)
displayplayers[0] = consoleplayer;
}
// User has designated that they want
@ -2373,12 +2377,20 @@ void G_Ticker(boolean run)
cmd = &players[i].cmd;
if (playeringame[i])
{
if (K_PlayerUsesBotMovement(&players[i]))
{
K_BuildBotTiccmd(&players[i], cmd);
cmd->latency = 0;
}
else
{
G_CopyTiccmd(cmd, &netcmds[buf][i], 1);
// Use the leveltime sent in the player's ticcmd to determine control lag
cmd->latency = modeattacking ? 0 : min(((leveltime & 0xFF) - cmd->latency) & 0xFF, MAXPREDICTTICS-1); //@TODO add a cvar to allow setting this max
}
}
}
// do main actions
switch (gamestate)

View file

@ -19,24 +19,20 @@
#include "lua_hook.h"
#include "byteptr.h"
#include "d_net.h" // nodetoplayer
// If you want multiple bots, variables like this will
// have to be stuffed in something accessible through player_t.
static boolean lastForward = false;
static boolean lastBlocked = false;
static boolean blocked = false;
#include "k_kart.h"
void K_AddBots(UINT8 numbots)
{
UINT8 newplayernum = 0;
UINT8 buf[4];
UINT8 *buf_p = buf;
if (dedicated)
newplayernum = 1;
while (numbots > 0)
{
UINT8 buf[2];
UINT8 *buf_p = buf;
numbots--;
// search for a free playernum
@ -56,13 +52,19 @@ void K_AddBots(UINT8 numbots)
break;
}
// should never happen since we check the playernum
// before accepting the join
I_Assert(newplayernum < MAXPLAYERS);
WRITEUINT8(buf_p, newplayernum);
SendNetXCmd(XD_ADDPLAYER, buf, buf_p - buf);
// test skins
if (numbots == 6)
WRITEUINT8(buf_p, 0);
else if (numbots == 5)
WRITEUINT8(buf_p, 1);
else if (numbots == 4)
WRITEUINT8(buf_p, 9);
else
WRITEUINT8(buf_p, 10);
SendNetXCmd(XD_ADDBOT, buf, buf_p - buf);
DEBFILE(va("Server added bot %d\n", newplayernum));
// use the next free slot (we can't put playeringame[newplayernum] = true here)
@ -70,90 +72,30 @@ void K_AddBots(UINT8 numbots)
}
}
static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
boolean K_PlayerUsesBotMovement(player_t *player)
{
boolean forward=false, backward=false, left=false, right=false, jump=false, spin=false;
angle_t angle;
INT16 rangle;
fixed_t dist;
if (player->bot || player->exiting)
return true;
// We can't follow Sonic if he's not around!
if (!sonic || sonic->health <= 0)
return;
#ifdef HAVE_BLUA
// Lua can handle it!
if (LUAh_BotAI(sonic, tails, cmd))
return;
#endif
if (tails->player->pflags & (PF_MACESPIN|PF_ITEMHANG))
{
dist = P_AproxDistance(tails->x-sonic->x, tails->y-sonic->y);
if (sonic->player->cmd.buttons & BT_DRIFT && sonic->player->pflags & (PF_JUMPED|PF_MACESPIN|PF_ITEMHANG))
cmd->buttons |= BT_DRIFT;
if (sonic->player->pflags & (PF_MACESPIN|PF_ITEMHANG))
{
cmd->forwardmove = sonic->player->cmd.forwardmove;
cmd->angleturn = abs((signed)(tails->angle - sonic->angle))>>16;
if (sonic->angle < tails->angle)
cmd->angleturn = -cmd->angleturn;
} else if (dist > FixedMul(512*FRACUNIT, tails->scale))
cmd->buttons |= BT_DRIFT;
return;
}
// Gather data about the environment
dist = P_AproxDistance(tails->x-sonic->x, tails->y-sonic->y);
if (tails->player->pflags & PF_STARTDASH)
angle = sonic->angle;
else
angle = R_PointToAngle2(tails->x, tails->y, sonic->x, sonic->y);
// Decide which direction to turn
angle = (tails->angle - angle);
if (angle < ANGLE_180) {
right = true; // We need to turn right
rangle = AngleFixed(angle)>>FRACBITS;
} else {
left = true; // We need to turn left
rangle = 360-(AngleFixed(angle)>>FRACBITS);
}
// Decide to move forward if you're finished turning
if (abs(rangle) < 10) { // We're facing the right way?
left = right = false; // Stop turning
forward = true; // and walk forward instead.
}
if (dist < (sonic->radius+tails->radius)*3) // We're close enough?
forward = false; // Stop walking.
// Decide when to jump
if (!(tails->player->pflags & (PF_JUMPED|PF_JUMPDOWN))) { // We're not jumping yet...
if (forward && lastForward && blocked && lastBlocked) // We've been stopped by a wall or something
jump = true; // Try to jump up
} else if ((tails->player->pflags & (PF_JUMPDOWN|PF_JUMPED)) == (PF_JUMPDOWN|PF_JUMPED)) { // When we're already jumping...
if (lastForward && blocked) // We're still stuck on something?
jump = true;
if (sonic->floorz > tails->floorz) // He's still above us? Jump HIGHER, then!
jump = true;
}
// Decide when to spin
if (sonic->player->pflags & PF_STARTDASH
&& (tails->player->pflags & PF_STARTDASH || (P_AproxDistance(tails->momx, tails->momy) < 2*FRACUNIT && !forward)))
spin = true;
// Turn the virtual keypresses into ticcmd_t.
B_KeysToTiccmd(tails, cmd, forward, backward, left, right, false, false, jump, spin);
// Update our status
lastForward = forward;
lastBlocked = blocked;
blocked = false;
return false;
}
void B_BuildTiccmd(player_t *player, ticcmd_t *cmd)
fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y, fixed_t cx, fixed_t cy)
{
fixed_t v1toc[2] = {cx - v1x, cy - v1y};
fixed_t v1tov2[2] = {v2x - v1x, v2y - v1y};
fixed_t mag = FixedMul(v1tov2[0], v1tov2[0]) + FixedMul(v1tov2[1], v1tov2[1]);
fixed_t dot = FixedMul(v1toc[0], v1tov2[0]) + FixedMul(v1toc[1], v1tov2[1]);
fixed_t t = FixedDiv(dot, mag);
fixed_t px = v1x + FixedMul(v1tov2[0], t);
fixed_t py = v1y + FixedMul(v1tov2[1], t);
return P_AproxDistance(cx - px, cy - py);
}
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
{
// Can't build a ticcmd if we aren't spawned...
if (!player->mo)
@ -161,162 +103,113 @@ void B_BuildTiccmd(player_t *player, ticcmd_t *cmd)
if (player->playerstate == PST_DEAD)
{
if (B_CheckRespawn(player))
cmd->buttons |= BT_DRIFT;
cmd->buttons |= BT_ACCELERATE;
return;
}
// Bot AI isn't programmed in analog.
//CV_SetValue(&cv_analog2, false);
#ifdef HAVE_BLUA
// Let Lua scripts build ticcmds
if (LUAh_BotTiccmd(player, cmd))
return;
#endif
// We don't have any main character AI, sorry. D:
if (player-players == consoleplayer)
return;
if (player->nextwaypoint != NULL && player->nextwaypoint->mobj != NULL && !P_MobjWasRemoved(player->nextwaypoint->mobj))
{
INT16 turnamt = KART_FULLTURN;
SINT8 turnsign = 0;
angle_t wpangle, moveangle, angle;
INT16 anglediff;
// Basic Tails AI
B_BuildTailsTiccmd(players[consoleplayer].mo, player->mo, cmd);
}
wpangle = R_PointToAngle2(player->mo->x, player->mo->y, player->nextwaypoint->mobj->x, player->nextwaypoint->mobj->y);
void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward, boolean left, boolean right, boolean strafeleft, boolean straferight, boolean jump, boolean spin)
{
// Turn the virtual keypresses into ticcmd_t.
if (twodlevel || mo->flags2 & MF2_TWOD) {
if (players[consoleplayer].climbing
|| mo->player->pflags & PF_GLIDING) {
// Don't mess with bot inputs during these unhandled movement conditions.
// The normal AI doesn't use abilities, so custom AI should be sending us exactly what it wants anyway.
if (forward)
cmd->forwardmove += MAXPLMOVE<<FRACBITS>>16;
if (backward)
cmd->forwardmove -= MAXPLMOVE<<FRACBITS>>16;
if (left || strafeleft)
cmd->sidemove -= MAXPLMOVE<<FRACBITS>>16;
if (right || straferight)
cmd->sidemove += MAXPLMOVE<<FRACBITS>>16;
} else {
// In standard 2D mode, interpret "forward" as "the way you're facing" and everything else as "the way you're not facing"
if (left || right)
backward = true;
left = right = false;
if (forward) {
if (mo->angle < ANGLE_90 || mo->angle > ANGLE_270)
right = true;
if (player->mo->momx || player->mo->momy)
{
angle_t movevswp;
moveangle = R_PointToAngle2(0, 0, player->mo->momx, player->mo->momy);
movevswp = (moveangle - wpangle);
if (movevswp > ANGLE_180)
{
movevswp = InvAngle(movevswp);
}
if (movevswp > ANGLE_45)
{
// Use facing direction when going the wrong way
moveangle = player->mo->angle;
}
}
else
left = true;
} else if (backward) {
if (mo->angle < ANGLE_90 || mo->angle > ANGLE_270)
left = true;
{
// Default to facing direction
moveangle = player->mo->angle;
}
angle = (moveangle - wpangle);
if (angle < ANGLE_180)
{
turnsign = -1; // Turn right
anglediff = AngleFixed(angle)>>FRACBITS;
}
else
right = true;
{
turnsign = 1; // Turn left
anglediff = 360-(AngleFixed(angle)>>FRACBITS);
}
if (left || strafeleft)
cmd->sidemove -= MAXPLMOVE<<FRACBITS>>16;
if (right || straferight)
cmd->sidemove += MAXPLMOVE<<FRACBITS>>16;
}
} else {
if (forward)
cmd->forwardmove += MAXPLMOVE<<FRACBITS>>16;
if (backward)
cmd->forwardmove -= MAXPLMOVE<<FRACBITS>>16;
if (left)
cmd->angleturn += 1280;
if (right)
cmd->angleturn -= 1280;
if (strafeleft)
cmd->sidemove -= MAXPLMOVE<<FRACBITS>>16;
if (straferight)
cmd->sidemove += MAXPLMOVE<<FRACBITS>>16;
}
if (jump)
cmd->buttons |= BT_DRIFT;
if (spin)
anglediff = abs(anglediff);
if (anglediff > 90)
{
// Wrong way!
cmd->forwardmove = -25;
cmd->buttons |= BT_BRAKE;
}
}
else
{
fixed_t rad = player->nextwaypoint->mobj->radius - (player->mo->radius*2);
fixed_t dirdist = K_DistanceOfLineFromPoint(
player->mo->x, player->mo->y,
player->mo->x + FINECOSINE(moveangle >> ANGLETOFINESHIFT), player->mo->y + FINESINE(moveangle >> ANGLETOFINESHIFT),
player->nextwaypoint->mobj->x, player->nextwaypoint->mobj->y
);
void B_MoveBlocked(player_t *player)
{
(void)player;
blocked = true;
}
if (player == &players[displayplayers[0]])
CONS_Printf("perpendicular dist: %d\n", dirdist / FRACUNIT);
boolean B_CheckRespawn(player_t *player)
{
mobj_t *sonic = players[consoleplayer].mo;
mobj_t *tails = player->mo;
cmd->buttons |= BT_ACCELERATE;
// We can't follow Sonic if he's not around!
if (!sonic || sonic->health <= 0)
return false;
// Full speed ahead!
cmd->forwardmove = 50;
// Check if Sonic is busy first.
// If he's doing any of these things, he probably doesn't want to see us.
if (sonic->player->pflags & (PF_ROPEHANG|PF_GLIDING|PF_CARRIED|PF_SLIDING|PF_ITEMHANG|PF_MACESPIN|PF_NIGHTSMODE)
|| (sonic->player->panim != PA_IDLE && sonic->player->panim != PA_WALK))
return false;
// Low ceiling, do not want!
if (sonic->ceilingz - sonic->z < 2*sonic->height)
return false;
// If you're dead, wait a few seconds to respawn.
if (player->playerstate == PST_DEAD) {
if (player->deadtimer > 4*TICRATE)
return true;
return false;
if (dirdist <= 3*rad/4)
{
if (dirdist < rad/4)
{
// Don't need to turn!
turnamt = 0;
}
else
{
// Make minor adjustments
turnamt /= 4;
}
}
else
{
// Actually, don't go too fast...
cmd->forwardmove /= 2;
cmd->buttons |= BT_BRAKE;
}
}
// If you can't see Sonic, I guess we should?
if (!P_CheckSight(sonic, tails) && P_AproxDistance(P_AproxDistance(tails->x-sonic->x, tails->y-sonic->y), tails->z-sonic->z) > FixedMul(1024*FRACUNIT, tails->scale))
return true;
return false;
}
void B_RespawnBot(INT32 playernum)
{
player_t *player = &players[playernum];
fixed_t x,y,z;
mobj_t *sonic = players[consoleplayer].mo;
mobj_t *tails;
if (!sonic || sonic->health <= 0)
return;
P_SpawnPlayer(playernum);
tails = player->mo;
x = sonic->x;
y = sonic->y;
if (sonic->eflags & MFE_VERTICALFLIP) {
tails->eflags |= MFE_VERTICALFLIP;
z = sonic->z - FixedMul(512*FRACUNIT,sonic->scale);
if (z < sonic->floorz)
z = sonic->floorz;
} else {
z = sonic->z + sonic->height + FixedMul(512*FRACUNIT,sonic->scale);
if (z > sonic->ceilingz - sonic->height)
z = sonic->ceilingz - sonic->height;
if (turnamt != 0)
{
cmd->driftturn = KART_FULLTURN * turnsign;
cmd->angleturn += KART_FULLTURN * turnsign;
}
}
if (sonic->flags2 & MF2_OBJECTFLIP)
tails->flags2 |= MF2_OBJECTFLIP;
if (sonic->flags2 & MF2_TWOD)
tails->flags2 |= MF2_TWOD;
if (sonic->eflags & MFE_UNDERWATER)
tails->eflags |= MFE_UNDERWATER;
player->powers[pw_underwater] = sonic->player->powers[pw_underwater];
player->powers[pw_spacetime] = sonic->player->powers[pw_spacetime];
player->powers[pw_gravityboots] = sonic->player->powers[pw_gravityboots];
player->powers[pw_nocontrol] = sonic->player->powers[pw_nocontrol];
P_TeleportMove(tails, x, y, z);
P_SetPlayerMobjState(tails, S_KART_STND1); // SRB2kart - was S_PLAY_FALL1
P_SetScale(tails, sonic->scale);
tails->destscale = sonic->destscale;
}

View file

@ -11,8 +11,6 @@
/// \brief Basic bot handling
void K_AddBots(UINT8 numbots);
void B_BuildTiccmd(player_t *player, ticcmd_t *cmd);
void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward, boolean left, boolean right, boolean strafeleft, boolean straferight, boolean jump, boolean spin);
boolean B_CheckRespawn(player_t *player);
void B_MoveBlocked(player_t *player);
void B_RespawnBot(INT32 playernum);
boolean K_PlayerUsesBotMovement(player_t *player);
fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y, fixed_t cx, fixed_t cy);
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd);

View file

@ -27,6 +27,7 @@
#include "lua_hook.h" // For MobjDamage and ShouldDamage
#include "k_waypoint.h"
#include "k_bot.h"
// SOME IMPORTANT VARIABLES DEFINED IN DOOMDEF.H:
// gamespeed is cc (0 for easy, 1 for normal, 2 for hard)
@ -6402,7 +6403,8 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
}
}
if ((waypoint->prevwaypoints != NULL) && (waypoint->numprevwaypoints > 0U))
if ((waypoint->prevwaypoints != NULL) && (waypoint->numprevwaypoints > 0U)
&& !K_PlayerUsesBotMovement(player))
{
for (i = 0U; i < waypoint->numprevwaypoints; i++)
{
@ -6556,13 +6558,6 @@ static boolean K_PlayerCloserToNextWaypoints(waypoint_t *const waypoint, player_
static void K_UpdateDistanceFromFinishLine(player_t *const player)
{
if ((player != NULL) && (player->mo != NULL))
{
if (player->exiting)
{
player->nextwaypoint = K_GetFinishLineWaypoint();
player->distancetofinish = 0U;
}
else
{
waypoint_t *finishline = K_GetFinishLineWaypoint();
waypoint_t *nextwaypoint = K_GetPlayerNextWaypoint(player);
@ -6575,7 +6570,12 @@ static void K_UpdateDistanceFromFinishLine(player_t *const player)
}
// nextwaypoint is now the waypoint that is in front of us
if ((player->nextwaypoint != NULL) && (finishline != NULL))
if (player->exiting)
{
// Player has finished, we don't need to calculate distance
player->distancetofinish = 0U;
}
else if ((player->nextwaypoint != NULL) && (finishline != NULL))
{
const boolean useshortcuts = false;
const boolean huntbackwards = false;
@ -6626,7 +6626,6 @@ static void K_UpdateDistanceFromFinishLine(player_t *const player)
}
}
}
}
}
// Returns false if this player being placed here causes them to collide with any other player

View file

@ -945,6 +945,12 @@ boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd)
// Hook for B_BuildTailsTiccmd by skin name
boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
{
#if 1
(void)sonic;
(void)tails;
(void)cmd;
return false;
#else
hook_p hookp;
boolean hooked = false;
if (!gL || !(hooksAvailable[hook_BotAI/8] & (1<<(hook_BotAI%8))))
@ -1001,6 +1007,7 @@ boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
lua_settop(gL, 0);
return hooked;
#endif
}
// Hook for linedef executors

View file

@ -1978,7 +1978,7 @@ boolean P_CheckRacers(void)
// Check if all the players in the race have finished. If so, end the level.
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator || players[i].exiting || !players[i].lives)
if (!playeringame[i] || players[i].spectator || players[i].exiting || players[i].bot || !players[i].lives)
continue;
break;

View file

@ -8023,18 +8023,6 @@ void P_PlayerThink(player_t *player)
player->playerstate = PST_DEAD;
}
if (player->bot)
{
if (player->playerstate == PST_LIVE || player->playerstate == PST_DEAD)
{
if (B_CheckRespawn(player))
player->playerstate = PST_REBORN;
}
if (player->playerstate == PST_REBORN)
return;
}
#ifdef SEENAMES
if (netgame && player == &players[displayplayers[0]] && !(leveltime % (TICRATE/5)) && !r_splitscreen)
{