- Made DBot inherit from DObject.

This commit is contained in:
ChillyDoom 2014-10-15 17:54:12 +01:00
parent db323643f8
commit c400dcf736
6 changed files with 41 additions and 21 deletions

View File

@ -24,6 +24,11 @@ IMPLEMENT_POINTY_CLASS(DBot)
END_POINTERS END_POINTERS
DBot::DBot () DBot::DBot ()
{
Clear ();
}
void DBot::Clear ()
{ {
savedyaw = 0; savedyaw = 0;
savedpitch = 0; savedpitch = 0;
@ -123,6 +128,11 @@ void FCajunMaster::ClearPlayer (int i, bool keepTeam)
bot->inuse = false; bot->inuse = false;
bot->lastteam = keepTeam ? players[i].userinfo.GetTeam() : TEAM_NONE; bot->lastteam = keepTeam ? players[i].userinfo.GetTeam() : TEAM_NONE;
} }
if (players[i].Bot != NULL)
{
players[i].Bot->Destroy ();
players[i].Bot = NULL;
}
players[i].~player_t(); players[i].~player_t();
::new(&players[i]) player_t; ::new(&players[i]) player_t;
players[i].userinfo.Reset(); players[i].userinfo.Reset();

View File

@ -90,6 +90,7 @@ public:
void ForgetBots (); void ForgetBots ();
void DoAddBot (BYTE **stream); void DoAddBot (BYTE **stream);
void RemoveAllBots (bool fromlist); void RemoveAllBots (bool fromlist);
void DestroyAllBots ();
//(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);
@ -143,13 +144,14 @@ protected:
bool observer; //Consoleplayer is observer. bool observer; //Consoleplayer is observer.
}; };
class DBot : public DThinker class DBot : public DObject
{ {
DECLARE_CLASS(DBot,DThinker) DECLARE_CLASS(DBot,DObject)
HAS_OBJECT_POINTERS HAS_OBJECT_POINTERS
public: public:
DBot (); DBot ();
void Clear ();
void Serialize (FArchive &arc); void Serialize (FArchive &arc);
angle_t savedyaw; angle_t savedyaw;

View File

@ -352,6 +352,9 @@ void FCajunMaster::DoAddBot (BYTE **stream)
skill.isp = ReadByte (stream); skill.isp = ReadByte (stream);
D_ReadUserInfoStrings (bnum, &infob, false); D_ReadUserInfoStrings (bnum, &infob, false);
delete[] info;
if (!deathmatch && playerstarts[bnum].type == 0) if (!deathmatch && playerstarts[bnum].type == 0)
{ {
Printf ("%s tried to join, but there was no player %d start\n", Printf ("%s tried to join, but there was no player %d start\n",
@ -423,6 +426,18 @@ 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

@ -1341,7 +1341,7 @@ void G_PlayerReborn (int player)
APlayerPawn *actor; APlayerPawn *actor;
const PClass *cls; const PClass *cls;
FString log; FString log;
DBot *OldBot; //Added by MC: DBot *Bot; //Added by MC:
p = &players[player]; p = &players[player];
@ -1356,7 +1356,7 @@ void G_PlayerReborn (int player)
cls = p->cls; cls = p->cls;
log = p->LogText; log = p->LogText;
chasecam = p->cheats & CF_CHASECAM; chasecam = p->cheats & CF_CHASECAM;
OldBot = p->Bot; //Added by MC: Bot = p->Bot; //Added by MC:
// Reset player structure to its defaults // Reset player structure to its defaults
p->~player_t(); p->~player_t();
@ -1373,13 +1373,7 @@ void G_PlayerReborn (int player)
p->cls = cls; p->cls = cls;
p->LogText = log; p->LogText = log;
p->cheats |= chasecam; p->cheats |= chasecam;
p->Bot = Bot; //Added by MC:
//Added by MC: Init bot structure.
if (OldBot != NULL)
{
p->Bot = new DBot;
p->Bot->skill = OldBot->skill;
}
p->oldbuttons = ~0, p->attackdown = true; p->usedown = true; // don't do anything immediately p->oldbuttons = ~0, p->attackdown = true; p->usedown = true; // don't do anything immediately
p->original_oldbuttons = ~0; p->original_oldbuttons = ~0;
@ -1390,6 +1384,14 @@ void G_PlayerReborn (int player)
actor->GiveDefaultInventory (); actor->GiveDefaultInventory ();
p->ReadyWeapon = p->PendingWeapon; p->ReadyWeapon = p->PendingWeapon;
} }
//Added by MC: Init bot structure.
if (p->Bot != NULL)
{
botskill_t skill = p->Bot->skill;
p->Bot->Clear ();
p->Bot->skill = skill;
}
} }
// //

View File

@ -1110,11 +1110,6 @@ void G_StartTravel ()
P_DelSector_List (); P_DelSector_List ();
} }
} }
if (players[i].Bot != NULL)
{
players[i].Bot->ChangeStatNum (STAT_TRAVELLING);
}
} }
} }
} }
@ -1189,11 +1184,6 @@ void G_FinishTravel ()
pawn->SetState(pawn->SpawnState); pawn->SetState(pawn->SpawnState);
pawn->player->SendPitchLimits(); pawn->player->SendPitchLimits();
if (pawn->player->Bot != NULL)
{
pawn->player->Bot->ChangeStatNum (STAT_DEFAULT);
}
for (inv = pawn->Inventory; inv != NULL; inv = inv->Inventory) for (inv = pawn->Inventory; inv != NULL; inv = inv->Inventory)
{ {
inv->ChangeStatNum (STAT_INVENTORY); inv->ChangeStatNum (STAT_INVENTORY);

View File

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