From 696fde69b819b04fb197312dd8b1c08631d4fd5e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 26 Mar 2016 01:30:28 +0100 Subject: [PATCH] - moved the bot support code from AActor::Tick to a subfunction in the bot sources. No need to pollute a main game file with this stuff. --- src/b_bot.h | 1 + src/b_func.cpp | 42 +++++++++++++++++++++++++++++++ src/p_mobj.cpp | 39 +--------------------------- src/thingdef/thingdef_codeptr.cpp | 2 +- 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/b_bot.h b/src/b_bot.h index e56b03f00..9f9fe55ba 100644 --- a/src/b_bot.h +++ b/src/b_bot.h @@ -106,6 +106,7 @@ public: void SetBodyAt (const DVector3 &pos, int hostnum); double FakeFire (AActor *source, AActor *dest, ticcmd_t *cmd); bool SafeCheckPosition (AActor *actor, double x, double y, FCheckPosition &tm); + void BotTick(AActor *mo); //(b_move.cpp) bool CleanAhead (AActor *thing, double x, double y, ticcmd_t *cmd); diff --git a/src/b_func.cpp b/src/b_func.cpp index 0e36d93d6..e292fd67d 100644 --- a/src/b_func.cpp +++ b/src/b_func.cpp @@ -284,6 +284,48 @@ bool FCajunMaster::IsLeader (player_t *player) return false; } +extern int BotWTG; + +void FCajunMaster::BotTick(AActor *mo) +{ + BotSupportCycles.Clock(); + bglobal.m_Thinking = true; + for (int i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].Bot == NULL) + continue; + + if (mo->flags3 & MF3_ISMONSTER) + { + if (mo->health > 0 + && !players[i].Bot->enemy + && mo->player ? !mo->IsTeammate(players[i].mo) : true + && mo->Distance2D(players[i].mo) < MAX_MONSTER_TARGET_DIST + && P_CheckSight(players[i].mo, mo, SF_SEEPASTBLOCKEVERYTHING)) + { //Probably a monster, so go kill it. + players[i].Bot->enemy = mo; + } + } + else if (mo->flags & MF_SPECIAL) + { //Item pickup time + //clock (BotWTG); + players[i].Bot->WhatToGet(mo); + //unclock (BotWTG); + BotWTG++; + } + else if (mo->flags & MF_MISSILE) + { + if (!players[i].Bot->missile && (mo->flags3 & MF3_WARNBOT)) + { //warn for incoming missiles. + if (mo->target != players[i].mo && players[i].Bot->Check_LOS(mo, 90.)) + players[i].Bot->missile = mo; + } + } + } + bglobal.m_Thinking = false; + BotSupportCycles.Unclock(); +} + //This function is called every //tick (for each bot) to set //the mate (teammate coop mate). diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 56f741494..76aa87127 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -3532,46 +3532,9 @@ void AActor::Tick () if (bglobal.botnum && !demoplayback && ((flags & (MF_SPECIAL|MF_MISSILE)) || (flags3 & MF3_ISMONSTER))) { - BotSupportCycles.Clock(); - bglobal.m_Thinking = true; - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] || players[i].Bot == NULL) - continue; - - if (flags3 & MF3_ISMONSTER) - { - if (health > 0 - && !players[i].Bot->enemy - && player ? !IsTeammate (players[i].mo) : true - && AproxDistance (players[i].mo) < MAX_MONSTER_TARGET_DIST - && P_CheckSight (players[i].mo, this, SF_SEEPASTBLOCKEVERYTHING)) - { //Probably a monster, so go kill it. - players[i].Bot->enemy = this; - } - } - else if (flags & MF_SPECIAL) - { //Item pickup time - //clock (BotWTG); - players[i].Bot->WhatToGet (this); - //unclock (BotWTG); - BotWTG++; - } - else if (flags & MF_MISSILE) - { - if (!players[i].Bot->missile && (flags3 & MF3_WARNBOT)) - { //warn for incoming missiles. - if (target != players[i].mo && players[i].Bot->Check_LOS (this, 90.)) - players[i].Bot->missile = this; - } - } - } - bglobal.m_Thinking = false; - BotSupportCycles.Unclock(); + bglobal.BotTick(this); } - //End of MC - // [RH] Consider carrying sectors here fixed_t cummx = 0, cummy = 0; if ((level.Scrolls != NULL || player != NULL) && !(flags & MF_NOCLIP) && !(flags & MF_NOSECTOR)) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index c79b2e6db..1a356796d 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -6505,7 +6505,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckProximity) if (ptrWillChange) { - current = ref->AproxDistance(mo); + current = ref->Distance2D(mo); if ((flags & CPXF_CLOSEST) && (current < closer)) {