/// <summary> /// Adds AI player to the specification of players. /// </summary> /// <param name="type">The type of the player.</param> /// <param name="teamID">The team the player will be part of.</param> /// <param name="insignia">The graphical representation of the player.</param> public void AddAIPlayer(PlayerType type, int teamID, PlayerInsignia insignia) { if (type == null) { throw new ArgumentNullException(nameof(type), "Cannot add AI player without AI"); } playerInfos.Add(PlayerInfo.CreateAIPlayer(type, teamID, insignia)); }
protected PlayerInfo(PlayerType playerType, int teamID, PlayerInsignia insignia, bool isHuman, bool isNeutral) { this.PlayerType = playerType; this.TeamID = teamID; this.Insignia = insignia; this.IsHuman = isHuman; this.IsNeutral = isNeutral; }
/// <summary> /// Creates player info for ai player that will be of the given <paramref name="playerType"/>. /// Checks that the given player type has category <see cref="PlayerTypeCategory.AI"/> /// </summary> /// <param name="playerType">The type of the player.</param> /// <param name="teamID">ID of the team the ai player will be part of.</param> /// <param name="insignia">The graphical identifications of the player.</param> /// <returns>Info to initialize the player with.</returns> /// <exception cref="ArgumentException">Thrown when the given <paramref name="playerType"/> is not ai category.</exception> public static PlayerInfo CreateAIPlayer(PlayerType playerType, int teamID, PlayerInsignia insignia) { if (playerType.Category != PlayerTypeCategory.AI) { throw new ArgumentException("Player type was not of type category AI"); } return(new PlayerInfo(playerType, teamID, insignia, false, false)); }
/// <summary> /// Creates a player to serve as a placeholder for future player with AI. /// Placeholder serves only as a container of units, buildings and projectiles, with no behavior. /// /// Player is added to the level. /// </summary> /// <param name="insignia">Icons and healthbars for the players units.</param> /// <returns>The new placeholder player, initialized and placed into the level.</returns> protected Player CreatePlaceholderPlayer(PlayerInsignia insignia) { var newPlayer = Player.CreatePlaceholderPlayer(Level.GetNewID(Level.players), Level, insignia); Level.LevelNode.AddComponent(newPlayer); Level.players.Add(newPlayer.ID, newPlayer); return(newPlayer); }
public static PlayerItem CreateAndAddToList(ListView list, Screen screen, PlayerInsignia insignia, int initialTeamID, PlayerTypeCategory playerTypeCategory) { var newItem = new PlayerItem(screen, insignia, initialTeamID, playerTypeCategory); list.AddItem(newItem); newItem.SetStyle("PlayerItem"); return(newItem); }
/// <summary> /// Sets the human player settings. /// </summary> /// <param name="type">The type of the player.</param> /// <param name="teamID">The team the player will be part of.</param> /// <param name="insignia">The graphical representation of the player.</param> public void SetHumanPlayer(PlayerType type, int teamID, PlayerInsignia insignia) { if (PlayerWithInput != null) { throw new InvalidOperationException("Level has to have exactly one human player"); } //Can add human player without AI PlayerWithInput = PlayerInfo.CreateHumanPlayer(type, teamID, insignia); playerInfos.Add(PlayerWithInput); }
/// <summary> /// Starts the loading process. /// </summary> /// <returns>Task representing the loading process.</returns> public override async Task <ILevelManager> StartLoading() { Urho.IO.Log.Write(LogLevel.Debug, $"Loading default level. MapSize: {mapSize}, LevelName: {LevelRep.Name}, GamePack: {LevelRep.GamePack}"); try { Progress.SendTextUpdate("Initializing level"); Level = await PostToMainThread <LevelManager>(InitializeLevel); Progress.SendUpdate(initLPartSize, "Initialized level"); PlayerInsignia.InitInsignias(Game.PackageManager); Progress.SendTextUpdate("Loading map"); Level.map = await PostToMainThread(CreateDefaultMap); //Map percentage is updated by Subsection watcher Progress.SendTextUpdate("Loaded map"); Level.Minimap = new Minimap(Level, 4); await PostToMainThread(CreateCamera); Progress.SendTextUpdate("Creating players"); await PostToMainThread(CreatePlayers); Progress.SendUpdate(playersLPartSize, "Created players"); Progress.SendTextUpdate("Giving player controls"); await PostToMainThread(CreateControl); Progress.SendUpdate(controlLPartSize, "Player controls created"); Progress.SendTextUpdate("Starting level"); await PostToMainThread(StartLevel); Progress.SendFinished(); return(Level); } catch (Exception e) { string message = $"Level loading failed with: {e.Message}"; Urho.IO.Log.Write(LogLevel.Error, message); Level?.Dispose(); CurrentLevel = null; Progress.SendFailed(message); return(null); } }
/// <summary> /// Starts the loading process of the level. /// </summary> /// <returns>Task representing the loading process of the level.</returns> public override async Task <ILevelManager> StartLoading() { Urho.IO.Log.Write(LogLevel.Debug, $"Loading stored level. LevelName: {LevelRep.Name}, GamePack: {LevelRep.GamePack}, EditorMode: {EditorMode}"); try { Loaders = new List <ILoader>(); Progress.SendTextUpdate("Initializing level"); Level = await PostToMainThread(InitializeLevel); Progress.SendUpdate(initLPartSize, "Initialized level"); PlayerInsignia.InitInsignias(Game.PackageManager); var mapLoader = await PostToMainThread(StartMapLoader); Loaders.Add(mapLoader); Level.map = mapLoader.Map; Level.Minimap = new Minimap(Level, 4); await PostToMainThread(CreateCamera); //ALT: Maybe give each its own subsection watcher await PostToMainThread(LoadUnits); await PostToMainThread(LoadBuildings); await PostToMainThread(LoadProjectiles); await PostToMainThread(LoadPlayers); await PostToMainThread(LoadToolsAndControllers); await PostToMainThread(LoadLevelPlugin); await PostToMainThread(ConnectReferences); await PostToMainThread(FinishLoading); await PostToMainThread(StartLevel); Progress.SendFinished(); return(Level); } catch (Exception e) { string message = $"Level loading failed with: {e.Message}"; Urho.IO.Log.Write(LogLevel.Error, message); Level?.Dispose(); CurrentLevel = null; Progress.SendFailed(message); return(null); } }
/// <summary> /// Creates new instance of a player. /// </summary> /// <param name="id">Unique identifier of the player.</param> /// <param name="teamID">Identifier of the team this player is on.</param> /// <param name="level">The level this player is spawning into.</param> /// <param name="insignia">The graphical identifications of the player.</param> /// <param name="type">The type of the player.</param> /// <param name="newPluginInstance">If new plugin instance should be created.</param> protected Player(int id, int teamID, ILevelManager level, PlayerInsignia insignia, PlayerType type, bool newPluginInstance) { ReceiveSceneUpdates = true; this.ID = id; this.TeamID = teamID; units = new Dictionary <UnitType, List <IUnit> >(); buildings = new Dictionary <BuildingType, List <IBuilding> >(); resources = new Dictionary <ResourceType, double>(); this.Level = level; this.Insignia = insignia; this.PlayerType = type; this.Plugin = newPluginInstance ? type.GetNewInstancePlugin(this, level) : type.GetInstancePluginForLoading(this, level); }
protected PlayerItem(Screen screen, PlayerInsignia insignia, int initialTeamID, PlayerTypeCategory playerTypeCategory) { this.Insignia = insignia; elementToTypeMap = new Dictionary <UIElement, PlayerType>(); elementToTeamMap = new Dictionary <UIElement, int>(); var child = screen.Game.UI.LoadLayout(screen.Game.PackageManager.GetXmlFile("UI/PlayerItemLayout.xml", true)); AddChild(child); BorderImage playerShield = (BorderImage)child.GetChild("PlayerShield", true); playerTypeList = (DropDownList)child.GetChild("PlayerTypeList", true); teamList = (DropDownList)child.GetChild("TeamList", true); playerShield.Texture = insignia.ShieldTexture; playerShield.ImageRect = insignia.ShieldRectangle; foreach (var player in screen.Level.GamePack.GetPlayersWithTypeCategory(playerTypeCategory)) { var item = InitTypeItem(player, screen.Game, screen.MenuUIManager); playerTypeList.AddItem(item); elementToTypeMap.Add(item, player); } if (playerTypeCategory != PlayerTypeCategory.Neutral) { for (int teamID = 1; teamID <= screen.Level.MaxNumberOfPlayers; teamID++) { UIElement item = InitTeamItem(teamID, screen.Game, screen.MenuUIManager); teamList.AddItem(item); elementToTeamMap.Add(item, teamID); if (teamID == initialTeamID) { teamList.Selection = teamList.NumItems - 1; } } } else { teamList.Visible = false; } }
/// <summary> /// Creates a loader that loads one of the <paramref name="storedPlayers"/> that corresponds to the data in /// <paramref name="newInfo"/>. /// </summary> /// <param name="level">The level to load the player into.</param> /// <param name="storedPlayers">The stored data of all players.</param> /// <param name="insigniaGetter">The source of graphical representations of the players.</param> /// <param name="newInfo">Info of the player to load.</param> public Loader(LevelManager level, IList <StPlayer> storedPlayers, InsigniaGetter insigniaGetter, PlayerInfo newInfo) { this.level = level; this.storedPlayer = (from stPlayer in storedPlayers where stPlayer.InsigniaID == newInfo.Insignia.Index select stPlayer).FirstOrDefault(); if (storedPlayer == null) { throw new ArgumentException("StoredPlayers did not contain player entry for player with provided playerInfo", nameof(storedPlayers)); } this.type = newInfo.PlayerType; this.teamID = newInfo.TeamID; this.insignia = insigniaGetter.MarkUsed(newInfo.Insignia); //Clear the stored player plugin data storedPlayer.UserPlugin = new PluginData(); }
/// <summary> /// Creates a loader that loads the given <paramref name="storedPlayer"/> into the <paramref name="level"/>. /// </summary> /// <param name="level">The level to load the player into.</param> /// <param name="storedPlayer">Stored data of the player.</param> /// <param name="insigniaGetter">The source of graphical representations of the players.</param> /// <param name="loadPlaceholder">If the player should be loaded as a placeholder player, or if it should be loaded with it's /// actual type and plugin.</param> public Loader(LevelManager level, StPlayer storedPlayer, InsigniaGetter insigniaGetter, bool loadPlaceholder) { this.level = level; this.storedPlayer = storedPlayer; this.insignia = insigniaGetter.GetUnusedInsignia(storedPlayer.InsigniaID); if (loadPlaceholder) { this.type = PlayerType.Placeholder; teamID = 0; } else { if (storedPlayer.TypeID == 0) { throw new ArgumentException("StoredPlayer had no type", nameof(storedPlayer)); } type = level.Package.GetPlayerType(storedPlayer.TypeID); teamID = storedPlayer.TeamID; } }
/// <summary> /// Creates a player for level editing, where player serves only as a container of his units, buildings and resources /// </summary> /// <param name="id">Unique identifier of the player.</param> /// <param name="level">The level this player is spawning into.</param> /// <param name="insignia">The graphical identifications of the player.</param> /// <returns>New instance of placeholder player.</returns> public static Player CreatePlaceholderPlayer(int id, ILevelManager level, PlayerInsignia insignia) { return(new Player(id, 0, level, insignia, PlayerType.Placeholder, true)); }