private void _syncBots() { if (GetTree().IsNetworkServer()) { // Calculate the target amount of spawned bots int bot_count = network.serverinfo.max_players - network.networkPlayers.Count; if (SpawnBots.Count > bot_count) { while (SpawnBots.Count > bot_count) { foreach (Agent spawnBot in SpawnBots.Values) { _removeUnitOnNetwork(spawnBot.Name); break; } } } else if (SpawnBots.Count < bot_count) { // If bot_count while (SpawnBots.Count < bot_count) { TeamMapAI targetAI = null; // Set the initial to max bot count int smallestUnitCount = bot_count; foreach (TeamMapAI currentAI in TeamMapAIs) { if (currentAI.GetAutoSpawnMember() && currentAI.isNewUnitAllow()) { if (currentAI.GetUnitsContainer().GetChildren().Count <= smallestUnitCount) { smallestUnitCount = currentAI.GetUnitsContainer().GetChildren().Count; targetAI = currentAI; } } } if (targetAI != null) { String botId = (int)targetAI.GetCurrentTeam() + ";" + AgentPrefix + AgentBotCounter; AgentBotCounter++; Rpc(nameof(_addBotOnNetwork), botId); _addBotOnNetwork(botId); } else { // No longer allowed to add more bot now, so exit loop break; } } } _checkGameWinningCondition(); } }
public virtual void Initialize(GameWorld gameWorld, String unitName, String displayName, TeamMapAI teamMapAI, PathFinding pathFinding) { _team = (Team)GetNode("Team"); _teamMapAI = teamMapAI; _gameWorld = gameWorld; SetCurrentTeam(_teamMapAI.GetCurrentTeam()); SetUnitName(unitName); SetDisplayName(displayName); _health = MaxHealth; _energy = MaxEnergy; CurrentInventory.Initialize(this); _initializeWeapon(LeftWeapons); _initializeWeapon(RightWeapons); }