mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 13:47:58 +03:00
Remove PlayerBot class and use delegates instead
This commit is contained in:
parent
9242faaa49
commit
ee970a3fce
7 changed files with 38 additions and 82 deletions
|
@ -1843,7 +1843,7 @@ void DM_Manager::BuildTeamInfo_ver6(DM_Team *dmTeam)
|
|||
for (int i = iNumPlayers; i > 0; i--) {
|
||||
pTeamPlayer = dmTeam->m_players.ObjectAt(i);
|
||||
|
||||
if (pTeamPlayer->IsSubclassOfBot()) {
|
||||
if (pTeamPlayer->edict->r.svFlags & SVF_BOT) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1888,7 +1888,7 @@ void DM_Manager::BuildTeamInfo_ver15(DM_Team *dmTeam)
|
|||
for (int i = iNumPlayers; i > 0; i--) {
|
||||
pTeamPlayer = dmTeam->m_players.ObjectAt(i);
|
||||
|
||||
if (pTeamPlayer->IsSubclassOfBot()) {
|
||||
if (pTeamPlayer->edict->r.svFlags & SVF_BOT) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1962,7 +1962,7 @@ void DM_Manager::BuildPlayerTeamInfo(DM_Team *dmTeam, int *iPlayerList, DM_Team
|
|||
pTeamPlayer->GetNumKills(),
|
||||
pTeamPlayer->GetNumDeaths(),
|
||||
G_TimeString(level.svsFloatTime - pTeamPlayer->edict->client->pers.enterTime),
|
||||
pTeamPlayer->IsSubclassOfBot() ? "bot" : va("%d", pTeamPlayer->client->ps.ping)
|
||||
(pTeamPlayer->edict->r.svFlags & SVF_BOT) ? "bot" : va("%d", pTeamPlayer->client->ps.ping)
|
||||
);
|
||||
} else {
|
||||
Com_sprintf(
|
||||
|
@ -1973,7 +1973,7 @@ void DM_Manager::BuildPlayerTeamInfo(DM_Team *dmTeam, int *iPlayerList, DM_Team
|
|||
pTeamPlayer->GetNumKills(),
|
||||
pTeamPlayer->GetNumDeaths(),
|
||||
G_TimeString(level.svsFloatTime - pTeamPlayer->edict->client->pers.enterTime),
|
||||
pTeamPlayer->IsSubclassOfBot() ? "bot" : va("%d", pTeamPlayer->client->ps.ping)
|
||||
(pTeamPlayer->edict->r.svFlags & SVF_BOT) ? "bot" : va("%d", pTeamPlayer->client->ps.ping)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -157,16 +157,16 @@ Begin spawning a new bot entity
|
|||
*/
|
||||
void G_BotBegin(gentity_t *ent)
|
||||
{
|
||||
PlayerBot *player;
|
||||
Player *player;
|
||||
BotController *controller;
|
||||
|
||||
level.spawn_entnum = ent->s.number;
|
||||
player = new PlayerBot;
|
||||
player = new Player;
|
||||
|
||||
G_ClientBegin(ent, NULL);
|
||||
|
||||
controller = botManager.getControllerManager().createController(player);
|
||||
player->setController(controller);
|
||||
//player->setController(controller);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -271,7 +271,7 @@ void G_BotShift(int clientNum)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!ent->entity->IsSubclassOfBot()) {
|
||||
if (!botManager.getControllerManager().findController(ent->entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -355,7 +355,7 @@ bool G_IsBot(gentity_t *ent)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!ent->entity || !ent->entity->IsSubclassOfBot()) {
|
||||
if (!ent->entity || !botManager.getControllerManager().findController(ent->entity)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -375,7 +375,7 @@ bool G_IsPlayer(gentity_t *ent)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!ent->entity || ent->entity->IsSubclassOfBot()) {
|
||||
if (!ent->entity || botManager.getControllerManager().findController(ent->entity)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -827,6 +827,7 @@ void G_BotConnect(int clientNum, qboolean firstTime, const char *userinfo)
|
|||
|
||||
ent->client = game.clients + clientNum;
|
||||
ent->s.number = clientNum;
|
||||
ent->r.svFlags |= SVF_BOT;
|
||||
|
||||
client = ent->client;
|
||||
|
||||
|
|
|
@ -76,6 +76,15 @@ BotController::BotController()
|
|||
m_RunLabel.TrySetScript("global/bot_run.scr");
|
||||
}
|
||||
|
||||
BotController::~BotController()
|
||||
{
|
||||
if (controlledEnt) {
|
||||
controlledEnt->delegate_gotKill.Remove(delegateHandle_gotKill);
|
||||
controlledEnt->delegate_killed.Remove(delegateHandle_killed);
|
||||
controlledEnt->delegate_stufftext.Remove(delegateHandle_stufftext);
|
||||
}
|
||||
}
|
||||
|
||||
BotMovement& BotController::GetMovement()
|
||||
{
|
||||
return movement;
|
||||
|
@ -1051,7 +1060,7 @@ void BotController::Think()
|
|||
G_ClientThink(controlledEnt->edict, &ucmd, &eyeinfo);
|
||||
}
|
||||
|
||||
void BotController::Killed(Event *ev)
|
||||
void BotController::Killed(const Event& ev)
|
||||
{
|
||||
Entity *attacker;
|
||||
|
||||
|
@ -1068,7 +1077,7 @@ void BotController::Killed(Event *ev)
|
|||
m_botEyes.angles[0] = 0;
|
||||
m_botEyes.angles[1] = 0;
|
||||
|
||||
attacker = ev->GetEntity(1);
|
||||
attacker = ev.GetEntity(1);
|
||||
|
||||
if (attacker && rand() % 5 == 0) {
|
||||
// 1/5 chance to go back to the attacker position
|
||||
|
@ -1093,7 +1102,7 @@ void BotController::Killed(Event *ev)
|
|||
G_ClientUserinfoChanged(controlledEnt->edict, controlledEnt->client->pers.userinfo);
|
||||
}
|
||||
|
||||
void BotController::GotKill(Event *ev)
|
||||
void BotController::GotKill(const Event& ev)
|
||||
{
|
||||
ClearEnemy();
|
||||
m_iCuriousTime = 0;
|
||||
|
@ -1118,9 +1127,9 @@ void BotController::GotKill(Event *ev)
|
|||
}
|
||||
}
|
||||
|
||||
void BotController::EventStuffText(Event *ev)
|
||||
void BotController::EventStuffText(const str& text)
|
||||
{
|
||||
SendCommand(ev->GetString(1));
|
||||
SendCommand(text);
|
||||
}
|
||||
|
||||
void BotController::setControlledEntity(Player *player)
|
||||
|
@ -1128,6 +1137,10 @@ void BotController::setControlledEntity(Player *player)
|
|||
controlledEnt = player;
|
||||
movement.SetControlledEntity(player);
|
||||
rotation.SetControlledEntity(player);
|
||||
|
||||
delegateHandle_gotKill = player->delegate_gotKill.Add(std::bind(&BotController::GotKill, this, std::placeholders::_1));
|
||||
delegateHandle_killed = player->delegate_killed.Add(std::bind(&BotController::Killed, this, std::placeholders::_1));
|
||||
delegateHandle_stufftext = player->delegate_stufftext.Add(std::bind(&BotController::EventStuffText, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
Player *BotController::getControlledEntity() const
|
||||
|
@ -1216,42 +1229,3 @@ void BotControllerManager::ThinkControllers()
|
|||
controller->Think();
|
||||
}
|
||||
}
|
||||
|
||||
CLASS_DECLARATION(Player, PlayerBot, NULL) {
|
||||
{&EV_Killed, &PlayerBot::Killed },
|
||||
{&EV_GotKill, &PlayerBot::GotKill },
|
||||
{&EV_Player_StuffText, &PlayerBot::EventStuffText},
|
||||
{NULL, NULL }
|
||||
};
|
||||
|
||||
PlayerBot::PlayerBot()
|
||||
{
|
||||
entflags |= ECF_BOT;
|
||||
controller = NULL;
|
||||
}
|
||||
|
||||
void PlayerBot::setController(BotController *controlledBy)
|
||||
{
|
||||
controller = controlledBy;
|
||||
}
|
||||
|
||||
void PlayerBot::Spawned(void)
|
||||
{
|
||||
controller->Spawned();
|
||||
|
||||
Player::Spawned();
|
||||
}
|
||||
|
||||
void PlayerBot::Killed(Event *ev)
|
||||
{
|
||||
Player::Killed(ev);
|
||||
|
||||
controller->Killed(ev);
|
||||
}
|
||||
|
||||
void PlayerBot::GotKill(Event *ev)
|
||||
{
|
||||
Player::GotKill(ev);
|
||||
|
||||
controller->GotKill(ev);
|
||||
}
|
||||
|
|
|
@ -160,6 +160,11 @@ private:
|
|||
// Taunts
|
||||
int m_iNextTauntTime;
|
||||
|
||||
private:
|
||||
DelegateHandle delegateHandle_gotKill;
|
||||
DelegateHandle delegateHandle_killed;
|
||||
DelegateHandle delegateHandle_stufftext;
|
||||
|
||||
private:
|
||||
Weapon* FindWeaponWithAmmo(void);
|
||||
Weapon* FindMeleeWeapon(void);
|
||||
|
@ -209,6 +214,7 @@ public:
|
|||
CLASS_PROTOTYPE(BotController);
|
||||
|
||||
BotController();
|
||||
~BotController();
|
||||
|
||||
static void Init(void);
|
||||
|
||||
|
@ -229,9 +235,9 @@ public:
|
|||
|
||||
void Spawned(void);
|
||||
|
||||
void Killed(Event *ev);
|
||||
void GotKill(Event *ev);
|
||||
void EventStuffText(Event *ev);
|
||||
void Killed(const Event& ev);
|
||||
void GotKill(const Event& ev);
|
||||
void EventStuffText(const str& text);
|
||||
|
||||
BotMovement& GetMovement();
|
||||
|
||||
|
@ -282,22 +288,3 @@ private:
|
|||
};
|
||||
|
||||
extern BotManager botManager;
|
||||
|
||||
class PlayerBot : public Player
|
||||
{
|
||||
public:
|
||||
CLASS_PROTOTYPE(PlayerBot);
|
||||
|
||||
public:
|
||||
PlayerBot();
|
||||
|
||||
void setController(BotController *controlledBy);
|
||||
|
||||
void Spawned(void) override;
|
||||
|
||||
void Killed(Event *ev) override;
|
||||
void GotKill(Event *ev);
|
||||
|
||||
private:
|
||||
BotController *controller;
|
||||
};
|
||||
|
|
|
@ -356,11 +356,6 @@ int SimpleEntity::IsSubclassOfCrateObject(void) const
|
|||
return (entflags & ECF_CRATEOBJECT);
|
||||
}
|
||||
|
||||
int SimpleEntity::IsSubclassOfBot(void) const
|
||||
{
|
||||
return (entflags & ECF_BOT);
|
||||
}
|
||||
|
||||
void SimpleEntity::SetTargetName(str targetname)
|
||||
{
|
||||
if (!world) {
|
||||
|
|
|
@ -91,7 +91,6 @@ public:
|
|||
int IsSubclassOfVehiclePoint(void) const;
|
||||
int IsSubclassOfSplinePath(void) const;
|
||||
int IsSubclassOfCrateObject(void) const;
|
||||
int IsSubclassOfBot(void) const;
|
||||
|
||||
void GetOrigin(Event *ev);
|
||||
void SetOrigin(Event *ev);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue