From c400dcf7365f5624d8a18881244b6675c64389e4 Mon Sep 17 00:00:00 2001 From: ChillyDoom Date: Wed, 15 Oct 2014 17:54:12 +0100 Subject: [PATCH] - Made DBot inherit from DObject. --- src/b_bot.cpp | 10 ++++++++++ src/b_bot.h | 6 ++++-- src/b_game.cpp | 15 +++++++++++++++ src/g_game.cpp | 20 +++++++++++--------- src/g_level.cpp | 10 ---------- src/p_setup.cpp | 1 + 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/b_bot.cpp b/src/b_bot.cpp index 30a8e4877..3494dc4c4 100644 --- a/src/b_bot.cpp +++ b/src/b_bot.cpp @@ -24,6 +24,11 @@ IMPLEMENT_POINTY_CLASS(DBot) END_POINTERS DBot::DBot () +{ + Clear (); +} + +void DBot::Clear () { savedyaw = 0; savedpitch = 0; @@ -123,6 +128,11 @@ void FCajunMaster::ClearPlayer (int i, bool keepTeam) bot->inuse = false; 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(); ::new(&players[i]) player_t; players[i].userinfo.Reset(); diff --git a/src/b_bot.h b/src/b_bot.h index f414a9687..7844597cd 100644 --- a/src/b_bot.h +++ b/src/b_bot.h @@ -90,6 +90,7 @@ public: void ForgetBots (); void DoAddBot (BYTE **stream); void RemoveAllBots (bool fromlist); + void DestroyAllBots (); //(B_Func.c) bool Check_LOS (AActor *mobj1, AActor *mobj2, angle_t vangle); @@ -143,13 +144,14 @@ protected: bool observer; //Consoleplayer is observer. }; -class DBot : public DThinker +class DBot : public DObject { - DECLARE_CLASS(DBot,DThinker) + DECLARE_CLASS(DBot,DObject) HAS_OBJECT_POINTERS public: DBot (); + void Clear (); void Serialize (FArchive &arc); angle_t savedyaw; diff --git a/src/b_game.cpp b/src/b_game.cpp index 35de6ec86..30c2c483b 100644 --- a/src/b_game.cpp +++ b/src/b_game.cpp @@ -352,6 +352,9 @@ void FCajunMaster::DoAddBot (BYTE **stream) skill.isp = ReadByte (stream); D_ReadUserInfoStrings (bnum, &infob, false); + + delete[] info; + if (!deathmatch && playerstarts[bnum].type == 0) { Printf ("%s tried to join, but there was no player %d start\n", @@ -423,6 +426,18 @@ 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 diff --git a/src/g_game.cpp b/src/g_game.cpp index fad7d9eb1..a58753b86 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -1341,7 +1341,7 @@ void G_PlayerReborn (int player) APlayerPawn *actor; const PClass *cls; FString log; - DBot *OldBot; //Added by MC: + DBot *Bot; //Added by MC: p = &players[player]; @@ -1356,7 +1356,7 @@ void G_PlayerReborn (int player) cls = p->cls; log = p->LogText; chasecam = p->cheats & CF_CHASECAM; - OldBot = p->Bot; //Added by MC: + Bot = p->Bot; //Added by MC: // Reset player structure to its defaults p->~player_t(); @@ -1373,13 +1373,7 @@ void G_PlayerReborn (int player) p->cls = cls; p->LogText = log; p->cheats |= chasecam; - - //Added by MC: Init bot structure. - if (OldBot != NULL) - { - p->Bot = new DBot; - p->Bot->skill = OldBot->skill; - } + p->Bot = Bot; //Added by MC: p->oldbuttons = ~0, p->attackdown = true; p->usedown = true; // don't do anything immediately p->original_oldbuttons = ~0; @@ -1390,6 +1384,14 @@ void G_PlayerReborn (int player) actor->GiveDefaultInventory (); 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; + } } // diff --git a/src/g_level.cpp b/src/g_level.cpp index 2d3aeee3a..d84a48776 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1110,11 +1110,6 @@ void G_StartTravel () 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->player->SendPitchLimits(); - if (pawn->player->Bot != NULL) - { - pawn->player->Bot->ChangeStatNum (STAT_DEFAULT); - } - for (inv = pawn->Inventory; inv != NULL; inv = inv->Inventory) { inv->ChangeStatNum (STAT_INVENTORY); diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 6b5d9403f..53b288798 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -4175,6 +4175,7 @@ static void P_Shutdown () P_FreeLevelData (); P_FreeExtraLevelData (); ST_Clear(); + bglobal.DestroyAllBots (); } #if 0