mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 07:12:02 +00:00
- Bot movement is now calculated locally.
This commit is contained in:
parent
c28c0b8f0b
commit
a613da43dd
9 changed files with 71 additions and 151 deletions
|
@ -30,8 +30,6 @@ DBot::DBot ()
|
||||||
|
|
||||||
void DBot::Clear ()
|
void DBot::Clear ()
|
||||||
{
|
{
|
||||||
savedyaw = 0;
|
|
||||||
savedpitch = 0;
|
|
||||||
angle = 0;
|
angle = 0;
|
||||||
dest = NULL;
|
dest = NULL;
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
|
@ -59,9 +57,15 @@ void DBot::Serialize (FArchive &arc)
|
||||||
{
|
{
|
||||||
Super::Serialize (arc);
|
Super::Serialize (arc);
|
||||||
|
|
||||||
|
if (SaveVersion < 4515)
|
||||||
|
{
|
||||||
|
angle_t savedyaw;
|
||||||
|
int savedpitch;
|
||||||
arc << savedyaw
|
arc << savedyaw
|
||||||
<< savedpitch
|
<< savedpitch;
|
||||||
<< angle
|
}
|
||||||
|
|
||||||
|
arc << angle
|
||||||
<< dest
|
<< dest
|
||||||
<< prev
|
<< prev
|
||||||
<< enemy
|
<< enemy
|
||||||
|
|
|
@ -165,9 +165,6 @@ public:
|
||||||
void Clear ();
|
void Clear ();
|
||||||
void Serialize (FArchive &arc);
|
void Serialize (FArchive &arc);
|
||||||
|
|
||||||
angle_t savedyaw;
|
|
||||||
int savedpitch;
|
|
||||||
|
|
||||||
angle_t angle; // The wanted angle that the bot try to get every tic.
|
angle_t angle; // The wanted angle that the bot try to get every tic.
|
||||||
// (used to get a smooth view movement)
|
// (used to get a smooth view movement)
|
||||||
TObjPtr<AActor> dest; // Move Destination.
|
TObjPtr<AActor> dest; // Move Destination.
|
||||||
|
|
|
@ -102,7 +102,7 @@ void FCajunMaster::Main (int buf)
|
||||||
|
|
||||||
BotThinkCycles.Reset();
|
BotThinkCycles.Reset();
|
||||||
|
|
||||||
if (consoleplayer != Net_Arbitrator || demoplayback)
|
if (demoplayback)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (gamestate != GS_LEVEL)
|
if (gamestate != GS_LEVEL)
|
||||||
|
@ -122,6 +122,8 @@ void FCajunMaster::Main (int buf)
|
||||||
BotThinkCycles.Unclock();
|
BotThinkCycles.Unclock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (consoleplayer == Net_Arbitrator)
|
||||||
|
{
|
||||||
//Add new bots?
|
//Add new bots?
|
||||||
if (wanted_botnum > botnum && !freeze)
|
if (wanted_botnum > botnum && !freeze)
|
||||||
{
|
{
|
||||||
|
@ -154,6 +156,7 @@ void FCajunMaster::Main (int buf)
|
||||||
players[consoleplayer].mo->flags2 &= ~MF2_FLY;
|
players[consoleplayer].mo->flags2 &= ~MF2_FLY;
|
||||||
players[consoleplayer].mo->LinkToWorld ();
|
players[consoleplayer].mo->LinkToWorld ();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_Thinking = false;
|
m_Thinking = false;
|
||||||
}
|
}
|
||||||
|
@ -347,12 +350,9 @@ void FCajunMaster::TryAddBot (BYTE **stream, int player)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DoAddBot ((BYTE *)info, skill))
|
if (DoAddBot ((BYTE *)info, skill))
|
||||||
{
|
|
||||||
if (consoleplayer == Net_Arbitrator)
|
|
||||||
{
|
{
|
||||||
//Increment this.
|
//Increment this.
|
||||||
botnum++;
|
botnum++;
|
||||||
}
|
|
||||||
|
|
||||||
if (thebot != NULL)
|
if (thebot != NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -975,25 +975,6 @@ void D_DoomLoop ()
|
||||||
I_StartTic ();
|
I_StartTic ();
|
||||||
D_ProcessEvents ();
|
D_ProcessEvents ();
|
||||||
G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]);
|
G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]);
|
||||||
//Added by MC: For some of that bot stuff. The main bot function.
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < MAXPLAYERS; i++)
|
|
||||||
{
|
|
||||||
if (playeringame[i] && players[i].Bot != NULL && players[i].mo)
|
|
||||||
{
|
|
||||||
players[i].Bot->savedyaw = players[i].mo->angle;
|
|
||||||
players[i].Bot->savedpitch = players[i].mo->pitch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bglobal.Main (maketic%BACKUPTICS);
|
|
||||||
for (i = 0; i < MAXPLAYERS; i++)
|
|
||||||
{
|
|
||||||
if (playeringame[i] && players[i].Bot != NULL && players[i].mo)
|
|
||||||
{
|
|
||||||
players[i].mo->angle = players[i].Bot->savedyaw;
|
|
||||||
players[i].mo->pitch = players[i].Bot->savedpitch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (advancedemo)
|
if (advancedemo)
|
||||||
D_DoAdvanceDemo ();
|
D_DoAdvanceDemo ();
|
||||||
C_Ticker ();
|
C_Ticker ();
|
||||||
|
|
|
@ -824,7 +824,6 @@ void GetPackets (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (netbuffer[0] & NCMD_QUITTERS)
|
if (netbuffer[0] & NCMD_QUITTERS)
|
||||||
|
|
||||||
{
|
{
|
||||||
numplayers = netbuffer[k++];
|
numplayers = netbuffer[k++];
|
||||||
for (int i = 0; i < numplayers; ++i)
|
for (int i = 0; i < numplayers; ++i)
|
||||||
|
@ -902,62 +901,16 @@ void GetPackets (void)
|
||||||
|
|
||||||
for (i = 0; i < numplayers; ++i)
|
for (i = 0; i < numplayers; ++i)
|
||||||
{
|
{
|
||||||
int node = (players[playerbytes[i]].Bot == NULL) ?
|
int node = nodeforplayer[playerbytes[i]];
|
||||||
nodeforplayer[playerbytes[i]] : netnode;
|
|
||||||
|
|
||||||
SkipTicCmd (&start, nettics[node] - realstart);
|
SkipTicCmd (&start, nettics[node] - realstart);
|
||||||
for (tics = nettics[node]; tics < realend; tics++)
|
for (tics = nettics[node]; tics < realend; tics++)
|
||||||
ReadTicCmd (&start, playerbytes[i], tics);
|
ReadTicCmd (&start, playerbytes[i], tics);
|
||||||
}
|
|
||||||
// Update the number of tics received from each node. This must
|
|
||||||
// be separate from the above loop in case the master is also
|
|
||||||
// sending bot movements. If it's not separate, then the bots
|
|
||||||
// will only move on the master, because the other players will
|
|
||||||
// read the master's tics and then think they already got all
|
|
||||||
// the tics for the bots and skip the bot tics included in the
|
|
||||||
// packet.
|
|
||||||
for (i = 0; i < numplayers; ++i)
|
|
||||||
{
|
|
||||||
if (players[playerbytes[i]].Bot == NULL)
|
|
||||||
{
|
|
||||||
nettics[nodeforplayer[playerbytes[i]]] = realend;
|
nettics[nodeforplayer[playerbytes[i]]] = realend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdjustBots (int gameticdiv)
|
|
||||||
{
|
|
||||||
// [RH] This loop adjusts the bots' rotations for ticcmds that have
|
|
||||||
// been already created but not yet executed. This way, the bot is still
|
|
||||||
// able to create ticcmds that accurately reflect the state it wants to
|
|
||||||
// be in even when gametic lags behind maketic.
|
|
||||||
for (int i = 0; i < MAXPLAYERS; i++)
|
|
||||||
{
|
|
||||||
if (playeringame[i] && players[i].Bot != NULL && players[i].mo)
|
|
||||||
{
|
|
||||||
players[i].Bot->savedyaw = players[i].mo->angle;
|
|
||||||
players[i].Bot->savedpitch = players[i].mo->pitch;
|
|
||||||
for (int j = gameticdiv; j < maketic/ticdup; j++)
|
|
||||||
{
|
|
||||||
players[i].mo->angle += (netcmds[i][j%BACKUPTICS].ucmd.yaw << 16) * ticdup;
|
|
||||||
players[i].mo->pitch -= (netcmds[i][j%BACKUPTICS].ucmd.pitch << 16) * ticdup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UnadjustBots ()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < MAXPLAYERS; i++)
|
|
||||||
{
|
|
||||||
if (playeringame[i] && players[i].Bot != NULL && players[i].mo)
|
|
||||||
{
|
|
||||||
players[i].mo->angle = players[i].Bot->savedyaw;
|
|
||||||
players[i].mo->pitch = players[i].Bot->savedpitch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -1006,9 +959,7 @@ void NetUpdate (void)
|
||||||
newtics = 0;
|
newtics = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// build new ticcmds for console player (and bots if I am the arbitrator)
|
// build new ticcmds for console player
|
||||||
AdjustBots (gametic / ticdup);
|
|
||||||
|
|
||||||
for (i = 0; i < newtics; i++)
|
for (i = 0; i < newtics; i++)
|
||||||
{
|
{
|
||||||
I_StartTic ();
|
I_StartTic ();
|
||||||
|
@ -1018,11 +969,6 @@ void NetUpdate (void)
|
||||||
|
|
||||||
//Printf ("mk:%i ",maketic);
|
//Printf ("mk:%i ",maketic);
|
||||||
G_BuildTiccmd (&localcmds[maketic % LOCALCMDTICS]);
|
G_BuildTiccmd (&localcmds[maketic % LOCALCMDTICS]);
|
||||||
if (maketic % ticdup == 0)
|
|
||||||
{
|
|
||||||
//Added by MC: For some of that bot stuff. The main bot function.
|
|
||||||
bglobal.Main ((maketic / ticdup) % BACKUPTICS);
|
|
||||||
}
|
|
||||||
maketic++;
|
maketic++;
|
||||||
|
|
||||||
if (ticdup == 1 || maketic == 0)
|
if (ticdup == 1 || maketic == 0)
|
||||||
|
@ -1102,8 +1048,6 @@ void NetUpdate (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UnadjustBots ();
|
|
||||||
|
|
||||||
if (singletics)
|
if (singletics)
|
||||||
return; // singletic update is synchronous
|
return; // singletic update is synchronous
|
||||||
|
|
||||||
|
@ -1123,16 +1067,13 @@ void NetUpdate (void)
|
||||||
|
|
||||||
if (consoleplayer == Net_Arbitrator)
|
if (consoleplayer == Net_Arbitrator)
|
||||||
{
|
{
|
||||||
for (j = 0; j < MAXPLAYERS; j++)
|
for (j = 0; j < doomcom.numnodes; j++)
|
||||||
{
|
{
|
||||||
if (playeringame[j])
|
if (nodeingame[j] && NetMode == NET_PacketServer)
|
||||||
{
|
|
||||||
if (players[j].Bot != NULL || NetMode == NET_PacketServer)
|
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (NetMode == NET_PacketServer)
|
if (NetMode == NET_PacketServer)
|
||||||
{
|
{
|
||||||
|
@ -1265,15 +1206,12 @@ void NetUpdate (void)
|
||||||
netbuffer[0] |= NCMD_MULTI;
|
netbuffer[0] |= NCMD_MULTI;
|
||||||
netbuffer[k++] = count;
|
netbuffer[k++] = count;
|
||||||
|
|
||||||
for (l = 1, j = 0; j < MAXPLAYERS; j++)
|
for (l = 1, j = 0; j < doomcom.numnodes; j++)
|
||||||
{
|
{
|
||||||
if (playeringame[j] && j != playerfornode[i] && j != consoleplayer)
|
if (nodeingame[j] && j != i && j != nodeforplayer[consoleplayer] && NetMode == NET_PacketServer)
|
||||||
{
|
{
|
||||||
if (players[j].Bot != NULL || NetMode == NET_PacketServer)
|
playerbytes[l++] = playerfornode[j];
|
||||||
{
|
netbuffer[k++] = playerfornode[j];
|
||||||
playerbytes[l++] = j;
|
|
||||||
netbuffer[k++] = j;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1293,7 +1231,7 @@ void NetUpdate (void)
|
||||||
prev %= BACKUPTICS;
|
prev %= BACKUPTICS;
|
||||||
|
|
||||||
// The local player has their tics sent first, followed by
|
// The local player has their tics sent first, followed by
|
||||||
// the other players/bots.
|
// the other players.
|
||||||
if (l == 0)
|
if (l == 0)
|
||||||
{
|
{
|
||||||
WriteWord (localcmds[localstart].consistancy, &cmddata);
|
WriteWord (localcmds[localstart].consistancy, &cmddata);
|
||||||
|
@ -1307,12 +1245,6 @@ void NetUpdate (void)
|
||||||
localprev >= 0 ? &localcmds[localprev].ucmd : NULL, &cmddata);
|
localprev >= 0 ? &localcmds[localprev].ucmd : NULL, &cmddata);
|
||||||
}
|
}
|
||||||
else if (i != 0)
|
else if (i != 0)
|
||||||
{
|
|
||||||
if (players[playerbytes[l]].Bot != NULL)
|
|
||||||
{
|
|
||||||
WriteWord (0, &cmddata); // fake consistancy word
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
BYTE *spec;
|
BYTE *spec;
|
||||||
|
@ -1324,7 +1256,7 @@ void NetUpdate (void)
|
||||||
memcpy (cmddata, spec, len);
|
memcpy (cmddata, spec, len);
|
||||||
cmddata += len;
|
cmddata += len;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
WriteUserCmdMessage (&netcmds[playerbytes[l]][start].ucmd,
|
WriteUserCmdMessage (&netcmds[playerbytes[l]][start].ucmd,
|
||||||
prev >= 0 ? &netcmds[playerbytes[l]][prev].ucmd : NULL, &cmddata);
|
prev >= 0 ? &netcmds[playerbytes[l]][prev].ucmd : NULL, &cmddata);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1127,6 +1127,12 @@ void G_Ticker ()
|
||||||
// check, not just the player's x position like BOOM.
|
// check, not just the player's x position like BOOM.
|
||||||
DWORD rngsum = FRandom::StaticSumSeeds ();
|
DWORD rngsum = FRandom::StaticSumSeeds ();
|
||||||
|
|
||||||
|
if ((gametic % ticdup) == 0)
|
||||||
|
{
|
||||||
|
//Added by MC: For some of that bot stuff. The main bot function.
|
||||||
|
bglobal.Main (buf);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < MAXPLAYERS; i++)
|
for (i = 0; i < MAXPLAYERS; i++)
|
||||||
{
|
{
|
||||||
if (playeringame[i])
|
if (playeringame[i])
|
||||||
|
|
|
@ -606,7 +606,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags)
|
||||||
player->respawn_time = level.time + TICRATE;
|
player->respawn_time = level.time + TICRATE;
|
||||||
|
|
||||||
//Added by MC: Respawn bots
|
//Added by MC: Respawn bots
|
||||||
if (bglobal.botnum && consoleplayer == Net_Arbitrator && !demoplayback)
|
if (bglobal.botnum && !demoplayback)
|
||||||
{
|
{
|
||||||
if (player->Bot != NULL)
|
if (player->Bot != NULL)
|
||||||
player->Bot->t_respawn = (pr_botrespawn()%15)+((bglobal.botnum-1)*2)+TICRATE+1;
|
player->Bot->t_respawn = (pr_botrespawn()%15)+((bglobal.botnum-1)*2)+TICRATE+1;
|
||||||
|
|
|
@ -3228,7 +3228,7 @@ void AActor::Tick ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bglobal.botnum && consoleplayer == Net_Arbitrator && !demoplayback &&
|
if (bglobal.botnum && !demoplayback &&
|
||||||
((flags & (MF_SPECIAL|MF_MISSILE)) || (flags3 & MF3_ISMONSTER)))
|
((flags & (MF_SPECIAL|MF_MISSILE)) || (flags3 & MF3_ISMONSTER)))
|
||||||
{
|
{
|
||||||
BotSupportCycles.Clock();
|
BotSupportCycles.Clock();
|
||||||
|
|
|
@ -76,7 +76,7 @@ const char *GetVersionString();
|
||||||
|
|
||||||
// Use 4500 as the base git save version, since it's higher than the
|
// Use 4500 as the base git save version, since it's higher than the
|
||||||
// SVN revision ever got.
|
// SVN revision ever got.
|
||||||
#define SAVEVER 4514
|
#define SAVEVER 4515
|
||||||
|
|
||||||
#define SAVEVERSTRINGIFY2(x) #x
|
#define SAVEVERSTRINGIFY2(x) #x
|
||||||
#define SAVEVERSTRINGIFY(x) SAVEVERSTRINGIFY2(x)
|
#define SAVEVERSTRINGIFY(x) SAVEVERSTRINGIFY2(x)
|
||||||
|
|
Loading…
Reference in a new issue