- Moved bot thinking logic into DBot.
This commit is contained in:
parent
5e6c375974
commit
ee977f94d7
12 changed files with 153 additions and 135 deletions
144
src/b_game.cpp
144
src/b_game.cpp
|
|
@ -94,71 +94,46 @@ FCajunMaster::~FCajunMaster()
|
|||
ForgetBots();
|
||||
}
|
||||
|
||||
//This function is called every tick (from g_game.c),
|
||||
//send bots into thinking (+more).
|
||||
void FCajunMaster::Main (int buf)
|
||||
//This function is called every tick (from g_game.c).
|
||||
void FCajunMaster::Main ()
|
||||
{
|
||||
int i;
|
||||
|
||||
BotThinkCycles.Reset();
|
||||
|
||||
if (demoplayback)
|
||||
if (demoplayback || gamestate != GS_LEVEL || consoleplayer != Net_Arbitrator)
|
||||
return;
|
||||
|
||||
if (gamestate != GS_LEVEL)
|
||||
return;
|
||||
|
||||
m_Thinking = true;
|
||||
|
||||
//Think for bots.
|
||||
if (botnum)
|
||||
//Add new bots?
|
||||
if (wanted_botnum > botnum && !freeze)
|
||||
{
|
||||
BotThinkCycles.Clock();
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
if (t_join == ((wanted_botnum - botnum) * SPAWN_DELAY))
|
||||
{
|
||||
if (playeringame[i] && players[i].mo && !freeze && players[i].Bot != NULL)
|
||||
Think (players[i].mo, &netcmds[i][buf]);
|
||||
if (!SpawnBot (getspawned[spawn_tries]))
|
||||
wanted_botnum--;
|
||||
spawn_tries++;
|
||||
}
|
||||
BotThinkCycles.Unclock();
|
||||
|
||||
t_join--;
|
||||
}
|
||||
|
||||
if (consoleplayer == Net_Arbitrator)
|
||||
//Check if player should go observer. Or un observe
|
||||
if (bot_observer && !observer && !netgame)
|
||||
{
|
||||
//Add new bots?
|
||||
if (wanted_botnum > botnum && !freeze)
|
||||
{
|
||||
if (t_join == ((wanted_botnum - botnum) * SPAWN_DELAY))
|
||||
{
|
||||
if (!SpawnBot (getspawned[spawn_tries]))
|
||||
wanted_botnum--;
|
||||
spawn_tries++;
|
||||
}
|
||||
|
||||
t_join--;
|
||||
}
|
||||
|
||||
//Check if player should go observer. Or un observe
|
||||
if (bot_observer && !observer && !netgame)
|
||||
{
|
||||
Printf ("%s is now observer\n", players[consoleplayer].userinfo.GetName());
|
||||
observer = true;
|
||||
players[consoleplayer].mo->UnlinkFromWorld ();
|
||||
players[consoleplayer].mo->flags = MF_DROPOFF|MF_NOBLOCKMAP|MF_NOCLIP|MF_NOTDMATCH|MF_NOGRAVITY|MF_FRIENDLY;
|
||||
players[consoleplayer].mo->flags2 |= MF2_FLY;
|
||||
players[consoleplayer].mo->LinkToWorld ();
|
||||
}
|
||||
else if (!bot_observer && observer && !netgame) //Go back
|
||||
{
|
||||
Printf ("%s returned to the fray\n", players[consoleplayer].userinfo.GetName());
|
||||
observer = false;
|
||||
players[consoleplayer].mo->UnlinkFromWorld ();
|
||||
players[consoleplayer].mo->flags = MF_SOLID|MF_SHOOTABLE|MF_DROPOFF|MF_PICKUP|MF_NOTDMATCH|MF_FRIENDLY;
|
||||
players[consoleplayer].mo->flags2 &= ~MF2_FLY;
|
||||
players[consoleplayer].mo->LinkToWorld ();
|
||||
}
|
||||
Printf ("%s is now observer\n", players[consoleplayer].userinfo.GetName());
|
||||
observer = true;
|
||||
players[consoleplayer].mo->UnlinkFromWorld ();
|
||||
players[consoleplayer].mo->flags = MF_DROPOFF|MF_NOBLOCKMAP|MF_NOCLIP|MF_NOTDMATCH|MF_NOGRAVITY|MF_FRIENDLY;
|
||||
players[consoleplayer].mo->flags2 |= MF2_FLY;
|
||||
players[consoleplayer].mo->LinkToWorld ();
|
||||
}
|
||||
else if (!bot_observer && observer && !netgame) //Go back
|
||||
{
|
||||
Printf ("%s returned to the fray\n", players[consoleplayer].userinfo.GetName());
|
||||
observer = false;
|
||||
players[consoleplayer].mo->UnlinkFromWorld ();
|
||||
players[consoleplayer].mo->flags = MF_SOLID|MF_SHOOTABLE|MF_DROPOFF|MF_PICKUP|MF_NOTDMATCH|MF_FRIENDLY;
|
||||
players[consoleplayer].mo->flags2 &= ~MF2_FLY;
|
||||
players[consoleplayer].mo->LinkToWorld ();
|
||||
}
|
||||
|
||||
m_Thinking = false;
|
||||
}
|
||||
|
||||
void FCajunMaster::Init ()
|
||||
|
|
@ -195,22 +170,18 @@ void FCajunMaster::Init ()
|
|||
//Called on each level exit (from g_game.c).
|
||||
void FCajunMaster::End ()
|
||||
{
|
||||
int i;
|
||||
|
||||
//Arrange wanted botnum and their names, so they can be spawned next level.
|
||||
getspawned.Clear();
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (playeringame[i] && players[i].Bot != NULL)
|
||||
{
|
||||
if (deathmatch)
|
||||
{
|
||||
getspawned.Push(players[i].userinfo.GetName());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deathmatch)
|
||||
{
|
||||
DBot *Bot;
|
||||
TThinkerIterator<DBot> it;
|
||||
|
||||
while ((Bot = it.Next ()) != NULL)
|
||||
{
|
||||
getspawned.Push(Bot->player->userinfo.GetName());
|
||||
}
|
||||
|
||||
wanted_botnum = botnum;
|
||||
}
|
||||
}
|
||||
|
|
@ -400,7 +371,7 @@ bool FCajunMaster::DoAddBot (BYTE *info, botskill_t skill)
|
|||
|
||||
multiplayer = true; //Prevents cheating and so on; emulates real netgame (almost).
|
||||
players[bnum].Bot = new DBot;
|
||||
GC::WriteBarrier (players[bnum].Bot);
|
||||
players[bnum].Bot->player = &players[bnum];
|
||||
players[bnum].Bot->skill = skill;
|
||||
playeringame[bnum] = true;
|
||||
players[bnum].mo = NULL;
|
||||
|
|
@ -422,31 +393,30 @@ bool FCajunMaster::DoAddBot (BYTE *info, botskill_t skill)
|
|||
|
||||
void FCajunMaster::RemoveAllBots (bool fromlist)
|
||||
{
|
||||
int i, j;
|
||||
DBot *Bot;
|
||||
TThinkerIterator<DBot> it;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; ++i)
|
||||
while ((Bot = it.Next ()) != NULL)
|
||||
{
|
||||
if (playeringame[i] && players[i].Bot != NULL)
|
||||
// If a player is looking through this bot's eyes, make him
|
||||
// look through his own eyes instead.
|
||||
for (i = 0; i < MAXPLAYERS; ++i)
|
||||
{
|
||||
// If a player is looking through this bot's eyes, make him
|
||||
// look through his own eyes instead.
|
||||
for (j = 0; j < MAXPLAYERS; ++j)
|
||||
if (Bot->player != &players[i] && playeringame[i] && players[i].Bot == NULL)
|
||||
{
|
||||
if (i != j && playeringame[j] && players[j].Bot == NULL)
|
||||
if (players[i].camera == Bot->player->mo)
|
||||
{
|
||||
if (players[j].camera == players[i].mo)
|
||||
players[i].camera = players[i].mo;
|
||||
if (i == consoleplayer)
|
||||
{
|
||||
players[j].camera = players[j].mo;
|
||||
if (j == consoleplayer)
|
||||
{
|
||||
StatusBar->AttachToPlayer (players + j);
|
||||
}
|
||||
StatusBar->AttachToPlayer (players + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
ClearPlayer (i, !fromlist);
|
||||
FBehavior::StaticStartTypedScripts (SCRIPT_Disconnect, NULL, true, i);
|
||||
}
|
||||
ClearPlayer (Bot->player - players, !fromlist);
|
||||
FBehavior::StaticStartTypedScripts (SCRIPT_Disconnect, NULL, true, Bot->player - players);
|
||||
}
|
||||
|
||||
if (fromlist)
|
||||
|
|
@ -456,18 +426,6 @@ void FCajunMaster::RemoveAllBots (bool fromlist)
|
|||
botnum = 0;
|
||||
}
|
||||
|
||||
void FCajunMaster::DestroyAllBots ()
|
||||
{
|
||||
for (int i = 0; i < MAXPLAYERS; ++i)
|
||||
{
|
||||
if (players[i].Bot != NULL)
|
||||
{
|
||||
players[i].Bot->Destroy ();
|
||||
players[i].Bot = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------
|
||||
//Reads data for bot from
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue