This commit is contained in:
Christoph Oelckers 2014-11-25 16:13:10 +01:00
commit ad5c5af6f2
12 changed files with 108 additions and 96 deletions

View file

@ -24,12 +24,14 @@ IMPLEMENT_POINTY_CLASS(DBot)
END_POINTERS END_POINTERS
DBot::DBot () DBot::DBot ()
: DThinker(STAT_BOT)
{ {
Clear (); Clear ();
} }
void DBot::Clear () void DBot::Clear ()
{ {
player = NULL;
angle = 0; angle = 0;
dest = NULL; dest = NULL;
prev = NULL; prev = NULL;
@ -64,6 +66,10 @@ void DBot::Serialize (FArchive &arc)
arc << savedyaw arc << savedyaw
<< savedpitch; << savedpitch;
} }
else if (SaveVersion >= 4516)
{
arc << player;
}
arc << angle arc << angle
<< dest << dest
@ -88,6 +94,22 @@ void DBot::Serialize (FArchive &arc)
<< oldy; << oldy;
} }
void DBot::Tick ()
{
Super::Tick ();
if (player->mo == NULL || bglobal.freeze)
{
return;
}
BotThinkCycles.Clock();
bglobal.m_Thinking = true;
bglobal.Think (player->mo, &netcmds[player - players][((gametic + 1)/ticdup)%BACKUPTICS]);
bglobal.m_Thinking = false;
BotThinkCycles.Unclock();
}
CVAR (Int, bot_next_color, 11, 0) CVAR (Int, bot_next_color, 11, 0)
CVAR (Bool, bot_observer, false, 0) CVAR (Bool, bot_observer, false, 0)

View file

@ -14,6 +14,7 @@
#include "d_ticcmd.h" #include "d_ticcmd.h"
#include "r_defs.h" #include "r_defs.h"
#include "a_pickups.h" #include "a_pickups.h"
#include "stats.h"
#define FORWARDWALK 0x1900 #define FORWARDWALK 0x1900
#define FORWARDRUN 0x3200 #define FORWARDRUN 0x3200
@ -89,20 +90,22 @@ public:
void ClearPlayer (int playernum, bool keepTeam); void ClearPlayer (int playernum, bool keepTeam);
//(B_Game.c) //(B_Game.c)
void Main (int buf); void Main ();
void Init (); void Init ();
void End(); void End();
bool SpawnBot (const char *name, int color = NOCOLOR); bool SpawnBot (const char *name, int color = NOCOLOR);
bool LoadBots ();
void ForgetBots ();
void TryAddBot (BYTE **stream, int player); void TryAddBot (BYTE **stream, int player);
void RemoveAllBots (bool fromlist); void RemoveAllBots (bool fromlist);
void DestroyAllBots (); bool LoadBots ();
void ForgetBots ();
//(B_Func.c) //(B_Func.c)
bool Check_LOS (AActor *mobj1, AActor *mobj2, angle_t vangle); bool Check_LOS (AActor *mobj1, AActor *mobj2, angle_t vangle);
void StartTravel ();
void FinishTravel ();
//(B_Think.c) //(B_Think.c)
void Think (AActor *actor, ticcmd_t *cmd);
void WhatToGet (AActor *actor, AActor *item); void WhatToGet (AActor *actor, AActor *item);
//(B_move.c) //(B_move.c)
@ -144,7 +147,6 @@ private:
bool SafeCheckPosition (AActor *actor, fixed_t x, fixed_t y, FCheckPosition &tm); bool SafeCheckPosition (AActor *actor, fixed_t x, fixed_t y, FCheckPosition &tm);
//(B_Think.c) //(B_Think.c)
void Think (AActor *actor, ticcmd_t *cmd);
void ThinkForMove (AActor *actor, ticcmd_t *cmd); void ThinkForMove (AActor *actor, ticcmd_t *cmd);
void Set_enemy (AActor *actor); void Set_enemy (AActor *actor);
@ -155,16 +157,18 @@ protected:
bool observer; //Consoleplayer is observer. bool observer; //Consoleplayer is observer.
}; };
class DBot : public DObject class DBot : public DThinker
{ {
DECLARE_CLASS(DBot,DObject) DECLARE_CLASS(DBot,DThinker)
HAS_OBJECT_POINTERS HAS_OBJECT_POINTERS
public: public:
DBot (); DBot ();
void Clear (); void Clear ();
void Serialize (FArchive &arc); void Serialize (FArchive &arc);
void Tick ();
player_t *player;
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.
@ -205,6 +209,7 @@ public:
//Externs //Externs
extern FCajunMaster bglobal; extern FCajunMaster bglobal;
extern cycle_t BotThinkCycles, BotSupportCycles;
EXTERN_CVAR (Float, bot_flag_return_time) EXTERN_CVAR (Float, bot_flag_return_time)
EXTERN_CVAR (Int, bot_next_color) EXTERN_CVAR (Int, bot_next_color)

View file

@ -552,3 +552,25 @@ bool FCajunMaster::SafeCheckPosition (AActor *actor, fixed_t x, fixed_t y, FChec
actor->flags = savedFlags; actor->flags = savedFlags;
return res; return res;
} }
void FCajunMaster::StartTravel ()
{
for (int i = 0; i < MAXPLAYERS; ++i)
{
if (players[i].Bot != NULL)
{
players[i].Bot->ChangeStatNum (STAT_TRAVELLING);
}
}
}
void FCajunMaster::FinishTravel ()
{
for (int i = 0; i < MAXPLAYERS; ++i)
{
if (players[i].Bot != NULL)
{
players[i].Bot->ChangeStatNum (STAT_BOT);
}
}
}

View file

@ -94,36 +94,14 @@ FCajunMaster::~FCajunMaster()
ForgetBots(); ForgetBots();
} }
//This function is called every tick (from g_game.c), //This function is called every tick (from g_game.c).
//send bots into thinking (+more). void FCajunMaster::Main ()
void FCajunMaster::Main (int buf)
{ {
int i;
BotThinkCycles.Reset(); BotThinkCycles.Reset();
if (demoplayback) if (demoplayback || gamestate != GS_LEVEL || consoleplayer != Net_Arbitrator)
return; return;
if (gamestate != GS_LEVEL)
return;
m_Thinking = true;
//Think for bots.
if (botnum)
{
BotThinkCycles.Clock();
for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] && players[i].mo && !freeze && players[i].Bot != NULL)
Think (players[i].mo, &netcmds[i][buf]);
}
BotThinkCycles.Unclock();
}
if (consoleplayer == Net_Arbitrator)
{
//Add new bots? //Add new bots?
if (wanted_botnum > botnum && !freeze) if (wanted_botnum > botnum && !freeze)
{ {
@ -158,9 +136,6 @@ void FCajunMaster::Main (int buf)
} }
} }
m_Thinking = false;
}
void FCajunMaster::Init () void FCajunMaster::Init ()
{ {
botnum = 0; botnum = 0;
@ -199,18 +174,13 @@ void FCajunMaster::End ()
//Arrange wanted botnum and their names, so they can be spawned next level. //Arrange wanted botnum and their names, so they can be spawned next level.
getspawned.Clear(); getspawned.Clear();
for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] && players[i].Bot != NULL)
{
if (deathmatch) if (deathmatch)
{
for (i = 0; i < MAXPLAYERS; i++)
{ {
getspawned.Push(players[i].userinfo.GetName()); getspawned.Push(players[i].userinfo.GetName());
} }
}
}
if (deathmatch)
{
wanted_botnum = botnum; wanted_botnum = botnum;
} }
} }
@ -400,7 +370,7 @@ bool FCajunMaster::DoAddBot (BYTE *info, botskill_t skill)
multiplayer = true; //Prevents cheating and so on; emulates real netgame (almost). multiplayer = true; //Prevents cheating and so on; emulates real netgame (almost).
players[bnum].Bot = new DBot; players[bnum].Bot = new DBot;
GC::WriteBarrier (players[bnum].Bot); players[bnum].Bot->player = &players[bnum];
players[bnum].Bot->skill = skill; players[bnum].Bot->skill = skill;
playeringame[bnum] = true; playeringame[bnum] = true;
players[bnum].mo = NULL; players[bnum].mo = NULL;
@ -426,7 +396,7 @@ void FCajunMaster::RemoveAllBots (bool fromlist)
for (i = 0; i < MAXPLAYERS; ++i) for (i = 0; i < MAXPLAYERS; ++i)
{ {
if (playeringame[i] && players[i].Bot != NULL) if (players[i].Bot != NULL)
{ {
// If a player is looking through this bot's eyes, make him // If a player is looking through this bot's eyes, make him
// look through his own eyes instead. // look through his own eyes instead.
@ -456,18 +426,6 @@ void FCajunMaster::RemoveAllBots (bool fromlist)
botnum = 0; 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 //Reads data for bot from

View file

@ -1128,11 +1128,8 @@ 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. //Added by MC: For some of that bot stuff. The main bot function.
bglobal.Main (buf); bglobal.Main ();
}
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
{ {
@ -1395,7 +1392,6 @@ void G_PlayerReborn (int player)
if (gamestate != GS_TITLELEVEL) if (gamestate != GS_TITLELEVEL)
{ {
// [GRB] Give inventory specified in DECORATE // [GRB] Give inventory specified in DECORATE
actor->GiveDefaultInventory (); actor->GiveDefaultInventory ();
p->ReadyWeapon = p->PendingWeapon; p->ReadyWeapon = p->PendingWeapon;
@ -1406,6 +1402,7 @@ void G_PlayerReborn (int player)
{ {
botskill_t skill = p->Bot->skill; botskill_t skill = p->Bot->skill;
p->Bot->Clear (); p->Bot->Clear ();
p->Bot->player = p;
p->Bot->skill = skill; p->Bot->skill = skill;
} }
} }

View file

@ -1164,6 +1164,8 @@ void G_StartTravel ()
} }
} }
} }
bglobal.StartTravel ();
} }
//========================================================================== //==========================================================================
@ -1261,6 +1263,8 @@ void G_FinishTravel ()
} }
} }
} }
bglobal.FinishTravel ();
} }
//========================================================================== //==========================================================================

View file

@ -1024,7 +1024,7 @@ void AInventory::Touch (AActor *toucher)
//Added by MC: Check if item taken was the roam destination of any bot //Added by MC: Check if item taken was the roam destination of any bot
for (int i = 0; i < MAXPLAYERS; i++) for (int i = 0; i < MAXPLAYERS; i++)
{ {
if (playeringame[i] && players[i].Bot != NULL && this == players[i].Bot->dest) if (players[i].Bot != NULL && this == players[i].Bot->dest)
players[i].Bot->dest = NULL; players[i].Bot->dest = NULL;
} }
} }

View file

@ -84,7 +84,6 @@ static void PlayerLandedOnThing (AActor *mo, AActor *onmobj);
// EXTERNAL DATA DECLARATIONS ---------------------------------------------- // EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern cycle_t BotSupportCycles;
extern int BotWTG; extern int BotWTG;
EXTERN_CVAR (Int, cl_rockettrails) EXTERN_CVAR (Int, cl_rockettrails)

View file

@ -4175,7 +4175,6 @@ static void P_Shutdown ()
P_FreeLevelData (); P_FreeLevelData ();
P_FreeExtraLevelData (); P_FreeExtraLevelData ();
ST_Clear(); ST_Clear();
bglobal.DestroyAllBots ();
} }
#if 0 #if 0

View file

@ -3066,7 +3066,6 @@ void player_t::Serialize (FArchive &arc)
if (SaveVersion < 4514 && IsBot) if (SaveVersion < 4514 && IsBot)
{ {
Bot = new DBot; Bot = new DBot;
GC::WriteBarrier (Bot);
arc << Bot->angle arc << Bot->angle
<< Bot->dest << Bot->dest
@ -3089,6 +3088,12 @@ void player_t::Serialize (FArchive &arc)
<< Bot->oldx << Bot->oldx
<< Bot->oldy; << Bot->oldy;
} }
if (SaveVersion < 4516 && Bot != NULL)
{
Bot->player = this;
}
if (arc.IsLoading ()) if (arc.IsLoading ())
{ {
// If the player reloaded because they pressed +use after dying, we // If the player reloaded because they pressed +use after dying, we

View file

@ -63,6 +63,7 @@ enum
STAT_SECTOREFFECT, // All sector effects that cause floor and ceiling movement STAT_SECTOREFFECT, // All sector effects that cause floor and ceiling movement
STAT_ACTORMOVER, // actor movers STAT_ACTORMOVER, // actor movers
STAT_SCRIPTS, // The ACS thinker. This is to ensure that it can't tick before all actors called PostBeginPlay STAT_SCRIPTS, // The ACS thinker. This is to ensure that it can't tick before all actors called PostBeginPlay
STAT_BOT, // Bot thinker
}; };
#endif #endif

View file

@ -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 4515 #define SAVEVER 4516
#define SAVEVERSTRINGIFY2(x) #x #define SAVEVERSTRINGIFY2(x) #x
#define SAVEVERSTRINGIFY(x) SAVEVERSTRINGIFY2(x) #define SAVEVERSTRINGIFY(x) SAVEVERSTRINGIFY2(x)