mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 13:47:58 +03:00
Merge pull request #634 from smallmodel/bot_player_association_rework
Bot player association rework
This commit is contained in:
commit
4399e2ab31
3 changed files with 36 additions and 16 deletions
|
@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
static saved_bot_t *saved_bots = NULL;
|
||||
static unsigned int num_saved_bots = 0;
|
||||
static unsigned int current_bot_count = 0;
|
||||
static unsigned int botId = 0;
|
||||
|
||||
Container<str> alliedModelList;
|
||||
|
@ -438,7 +437,6 @@ void G_AddBot(const saved_bot_t *saved)
|
|||
|
||||
clientNum = e - g_entities;
|
||||
|
||||
current_bot_count++;
|
||||
// increase the unique ID
|
||||
botId++;
|
||||
|
||||
|
@ -504,7 +502,6 @@ void G_RemoveBot(gentity_t *ent)
|
|||
}
|
||||
|
||||
G_ClientDisconnect(ent);
|
||||
current_bot_count--;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -583,17 +580,19 @@ void G_SaveBots()
|
|||
saved_bots = NULL;
|
||||
}
|
||||
|
||||
if (!current_bot_count) {
|
||||
const BotControllerManager& manager = botManager.getControllerManager();
|
||||
unsigned int numSpawnedBots = manager.getControllers().NumObjects();
|
||||
|
||||
if (!numSpawnedBots) {
|
||||
return;
|
||||
}
|
||||
|
||||
saved_bots = new saved_bot_t[current_bot_count];
|
||||
saved_bots = new saved_bot_t[numSpawnedBots];
|
||||
num_saved_bots = 0;
|
||||
|
||||
const BotControllerManager& manager = botManager.getControllerManager();
|
||||
|
||||
count = manager.getControllers().NumObjects();
|
||||
assert(count <= current_bot_count);
|
||||
assert(count <= numSpawnedBots);
|
||||
|
||||
for (n = 1; n <= count; n++) {
|
||||
const BotController *controller = manager.getControllers().ObjectAt(n);
|
||||
|
@ -700,8 +699,7 @@ void G_ResetBots()
|
|||
|
||||
botManager.Cleanup();
|
||||
|
||||
current_bot_count = 0;
|
||||
botId = 0;
|
||||
botId = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -754,6 +752,7 @@ void G_SpawnBots()
|
|||
{
|
||||
unsigned int numClients;
|
||||
unsigned int numBotsToSpawn;
|
||||
unsigned int numSpawnedBots;
|
||||
|
||||
//
|
||||
// Check the minimum bot count
|
||||
|
@ -776,12 +775,14 @@ void G_SpawnBots()
|
|||
numBotsToSpawn = Q_min(numBotsToSpawn, sv_maxbots->integer);
|
||||
}
|
||||
|
||||
numSpawnedBots = botManager.getControllerManager().getControllers().NumObjects();
|
||||
|
||||
//
|
||||
// Spawn bots
|
||||
//
|
||||
if (numBotsToSpawn > current_bot_count) {
|
||||
G_AddBots(numBotsToSpawn - current_bot_count);
|
||||
} else if (numBotsToSpawn < current_bot_count) {
|
||||
G_RemoveBots(current_bot_count - numBotsToSpawn);
|
||||
if (numBotsToSpawn > numSpawnedBots) {
|
||||
G_AddBots(numBotsToSpawn - numSpawnedBots);
|
||||
} else if (numBotsToSpawn < numSpawnedBots) {
|
||||
G_RemoveBots(numSpawnedBots - numBotsToSpawn);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2209,6 +2209,12 @@ Player::~Player()
|
|||
// when the player is deleted
|
||||
RemoveFromVehiclesAndTurrets();
|
||||
|
||||
// Added in OPM
|
||||
// Remove the player at destructor
|
||||
if (g_gametype->integer != GT_SINGLE_PLAYER && dmManager.PlayerCount()) {
|
||||
dmManager.RemovePlayer(this);
|
||||
}
|
||||
|
||||
entflags &= ~ECF_PLAYER;
|
||||
}
|
||||
|
||||
|
@ -9704,9 +9710,9 @@ void Player::Disconnect(void)
|
|||
ev->AddListener(this);
|
||||
scriptedEvents[SE_DISCONNECTED].Trigger(ev);
|
||||
|
||||
if (g_gametype->integer != GT_SINGLE_PLAYER) {
|
||||
dmManager.RemovePlayer(this);
|
||||
}
|
||||
// if (g_gametype->integer != GT_SINGLE_PLAYER) {
|
||||
// dmManager.RemovePlayer(this);
|
||||
// }
|
||||
}
|
||||
|
||||
void Player::CallVote(Event *ev)
|
||||
|
|
|
@ -1198,6 +1198,19 @@ void BotControllerManager::ThinkControllers()
|
|||
{
|
||||
int i;
|
||||
|
||||
// Delete controllers that don't have associated player entity
|
||||
// This cannot happen unless some mods remove them
|
||||
for (i = controllers.NumObjects(); i > 0; i--) {
|
||||
BotController* controller = controllers.ObjectAt(i);
|
||||
if (!controller->getControlledEntity()) {
|
||||
gi.DPrintf("Bot %d has no associated player entity. This shouldn't happen unless the entity has been removed by a script. The controller will be removed, please fix.\n", i);
|
||||
|
||||
// Remove the controller, it will be recreated later to match `sv_numbots`
|
||||
delete controller;
|
||||
controllers.RemoveObjectAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i <= controllers.NumObjects(); i++) {
|
||||
BotController *controller = controllers.ObjectAt(i);
|
||||
controller->Think();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue