public PathSearch(Actor self) { this.self = self; world = self.World; cellInfo = InitCellInfo(); mobile = self.Trait<Mobile>(); queue = new PriorityQueue<PathDistance>(); }
public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr) { World = world; InternalName = pr.Name; PlayerReference = pr; string botType = null; // Real player or host-created bot if (client != null) { ClientIndex = client.Index; Color = client.Color; PlayerName = client.Name; botType = client.Bot; Country = ChooseCountry(world, client.Country); } else { // Map player ClientIndex = 0; // Owned by the host (TODO: fix this) Color = pr.Color; PlayerName = pr.Name; NonCombatant = pr.NonCombatant; botType = pr.Bot; Country = ChooseCountry(world, pr.Race); } PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); Shroud = PlayerActor.Trait<Shroud>(); // Enable the bot logic on the host IsBot = botType != null; if (IsBot && Game.IsHost) { var logic = PlayerActor.TraitsImplementing<IBot>() .FirstOrDefault(b => b.Info.Name == botType); if (logic == null) Log.Write("debug", "Invalid bot type: {0}", botType); else logic.Activate(this); } }
public Player(World world, Session.Client client, PlayerReference pr) { string botType; World = world; InternalName = pr.Name; PlayerReference = pr; // Real player or host-created bot if (client != null) { ClientIndex = client.Index; Color = client.Color; PlayerName = client.Name; botType = client.Bot; Faction = ChooseFaction(world, client.Faction, !pr.LockFaction); DisplayFaction = ChooseDisplayFaction(world, client.Faction); } else { // Map player ClientIndex = 0; // Owned by the host (TODO: fix this) Color = pr.Color; PlayerName = pr.Name; NonCombatant = pr.NonCombatant; Playable = pr.Playable; Spectating = pr.Spectating; botType = pr.Bot; Faction = ChooseFaction(world, pr.Faction, false); DisplayFaction = ChooseDisplayFaction(world, pr.Faction); } PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); Shroud = PlayerActor.Trait<Shroud>(); fogVisibilities = PlayerActor.TraitsImplementing<IFogVisibilityModifier>().ToArray(); // Enable the bot logic on the host IsBot = botType != null; if (IsBot && Game.IsHost) { var logic = PlayerActor.TraitsImplementing<IBot>().FirstOrDefault(b => b.Info.Name == botType); if (logic == null) Log.Write("debug", "Invalid bot type: {0}", botType); else logic.Activate(this); } }
public bool CanViewActor(Actor a) { if (a.TraitsImplementing<IVisibilityModifier>().Any(t => !t.IsVisible(a, this))) return false; return a.Trait<IDefaultVisibility>().IsVisible(a, this); }
public Player(World world, Session.Client client, PlayerReference pr) { World = world; InternalName = pr.Name; PlayerReference = pr; inMissionMap = world.Map.Visibility.HasFlag(MapVisibility.MissionSelector); // Real player or host-created bot if (client != null) { ClientIndex = client.Index; Color = client.Color; if (client.Bot != null) { var botInfo = world.Map.Rules.Actors["player"].TraitInfos <IBotInfo>().First(b => b.Type == client.Bot); var botsOfSameType = world.LobbyInfo.Clients.Where(c => c.Bot == client.Bot).ToArray(); PlayerName = botsOfSameType.Length == 1 ? botInfo.Name : "{0} {1}".F(botInfo.Name, botsOfSameType.IndexOf(client) + 1); } else { PlayerName = client.Name; } BotType = client.Bot; Faction = ChooseFaction(world, client.Faction, !pr.LockFaction); DisplayFaction = ChooseDisplayFaction(world, client.Faction); } else { // Map player ClientIndex = 0; // Owned by the host (TODO: fix this) Color = pr.Color; PlayerName = pr.Name; NonCombatant = pr.NonCombatant; Playable = pr.Playable; Spectating = pr.Spectating; BotType = pr.Bot; Faction = ChooseFaction(world, pr.Faction, false); DisplayFaction = ChooseDisplayFaction(world, pr.Faction); } if (!Spectating) { PlayerMask = new LongBitSet <PlayerBitMask>(InternalName); } // Set this property before running any Created callbacks on the player actor IsBot = BotType != null; // Special case handling is required for the Player actor: // Since Actor.Created would be called before PlayerActor is assigned here // querying player traits in INotifyCreated.Created would crash. // Therefore assign the uninitialized actor and run the Created callbacks // by calling Initialize ourselves. var playerActorType = world.Type == WorldType.Editor ? EditorPlayerActorType : PlayerActorType; PlayerActor = new Actor(world, playerActorType, new TypeDictionary { new OwnerInit(this) }); PlayerActor.Initialize(true); Shroud = PlayerActor.Trait <Shroud>(); FrozenActorLayer = PlayerActor.TraitOrDefault <FrozenActorLayer>(); // Enable the bot logic on the host if (IsBot && Game.IsHost) { var logic = PlayerActor.TraitsImplementing <IBot>().FirstOrDefault(b => b.Info.Type == BotType); if (logic == null) { Log.Write("debug", "Invalid bot type: {0}", BotType); } else { logic.Activate(this); } } stanceColors.Self = ChromeMetrics.Get <Color>("PlayerStanceColorSelf"); stanceColors.Allies = ChromeMetrics.Get <Color>("PlayerStanceColorAllies"); stanceColors.Enemies = ChromeMetrics.Get <Color>("PlayerStanceColorEnemies"); stanceColors.Neutrals = ChromeMetrics.Get <Color>("PlayerStanceColorNeutrals"); unlockRenderPlayer = PlayerActor.TraitsImplementing <IUnlocksRenderPlayer>().ToArray(); }
public Player(World world, Session.Client client, PlayerReference pr, MersenneTwister playerRandom) { World = world; InternalName = pr.Name; PlayerReference = pr; inMissionMap = world.Map.Visibility.HasFlag(MapVisibility.MissionSelector); // Real player or host-created bot if (client != null) { ClientIndex = client.Index; Color = client.Color; PlayerName = ResolvePlayerName(client, world.LobbyInfo.Clients, world.Map.Rules.Actors[SystemActors.Player].TraitInfos <IBotInfo>()); BotType = client.Bot; Faction = ResolveFaction(world, client.Faction, playerRandom, !pr.LockFaction); DisplayFaction = ResolveDisplayFaction(world, client.Faction); var assignSpawnPoints = world.WorldActor.TraitOrDefault <IAssignSpawnPoints>(); HomeLocation = assignSpawnPoints?.AssignHomeLocation(world, client, playerRandom) ?? pr.HomeLocation; SpawnPoint = assignSpawnPoints?.SpawnPointForPlayer(this) ?? client.SpawnPoint; DisplaySpawnPoint = client.SpawnPoint; Handicap = client.Handicap; } else { // Map player ClientIndex = world.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin)?.Index ?? 0; // Owned by the host (TODO: fix this) Color = pr.Color; PlayerName = pr.Name; NonCombatant = pr.NonCombatant; Playable = pr.Playable; spectating = pr.Spectating; BotType = pr.Bot; Faction = ResolveFaction(world, pr.Faction, playerRandom, false); DisplayFaction = ResolveDisplayFaction(world, pr.Faction); HomeLocation = pr.HomeLocation; SpawnPoint = DisplaySpawnPoint = 0; Handicap = pr.Handicap; } if (!spectating) { PlayerMask = new LongBitSet <PlayerBitMask>(InternalName); } // Set this property before running any Created callbacks on the player actor IsBot = BotType != null; // Special case handling is required for the Player actor: // Since Actor.Created would be called before PlayerActor is assigned here // querying player traits in INotifyCreated.Created would crash. // Therefore assign the uninitialized actor and run the Created callbacks // by calling Initialize ourselves. var playerActorType = world.Type == WorldType.Editor ? SystemActors.EditorPlayer : SystemActors.Player; PlayerActor = new Actor(world, playerActorType.ToString(), new TypeDictionary { new OwnerInit(this) }); PlayerActor.Initialize(true); Shroud = PlayerActor.Trait <Shroud>(); FrozenActorLayer = PlayerActor.TraitOrDefault <FrozenActorLayer>(); // Enable the bot logic on the host if (IsBot && Game.IsHost) { var logic = PlayerActor.TraitsImplementing <IBot>().FirstOrDefault(b => b.Info.Type == BotType); if (logic == null) { Log.Write("debug", "Invalid bot type: {0}", BotType); } else { logic.Activate(this); } } stanceColors.Self = ChromeMetrics.Get <Color>("PlayerStanceColorSelf"); stanceColors.Allies = ChromeMetrics.Get <Color>("PlayerStanceColorAllies"); stanceColors.Enemies = ChromeMetrics.Get <Color>("PlayerStanceColorEnemies"); stanceColors.Neutrals = ChromeMetrics.Get <Color>("PlayerStanceColorNeutrals"); unlockRenderPlayer = PlayerActor.TraitsImplementing <IUnlocksRenderPlayer>().ToArray(); notifyDisconnected = PlayerActor.TraitsImplementing <INotifyPlayerDisconnected>().ToArray(); }
public Player(World world, Session.Client client, PlayerReference pr) { World = world; InternalName = pr.Name; PlayerReference = pr; inMissionMap = world.Map.Visibility.HasFlag(MapVisibility.MissionSelector); // Real player or host-created bot if (client != null) { ClientIndex = client.Index; Color = client.Color; if (client.Bot != null) { var botInfo = world.Map.Rules.Actors["player"].TraitInfos <IBotInfo>().First(b => b.Type == client.Bot); var botsOfSameType = world.LobbyInfo.Clients.Where(c => c.Bot == client.Bot).ToArray(); PlayerName = botsOfSameType.Length == 1 ? botInfo.Name : "{0} {1}".F(botInfo.Name, botsOfSameType.IndexOf(client) + 1); } else { PlayerName = client.Name; } BotType = client.Bot; Faction = ChooseFaction(world, client.Faction, !pr.LockFaction); DisplayFaction = ChooseDisplayFaction(world, client.Faction); } else { // Map player ClientIndex = 0; // Owned by the host (TODO: fix this) Color = pr.Color; PlayerName = pr.Name; NonCombatant = pr.NonCombatant; Playable = pr.Playable; Spectating = pr.Spectating; BotType = pr.Bot; Faction = ChooseFaction(world, pr.Faction, false); DisplayFaction = ChooseDisplayFaction(world, pr.Faction); } if (!Spectating) { PlayerMask = new LongBitSet <PlayerBitMask>(InternalName); } var playerActorType = world.Type == WorldType.Editor ? "EditorPlayer" : "Player"; PlayerActor = world.CreateActor(playerActorType, new TypeDictionary { new OwnerInit(this) }); Shroud = PlayerActor.Trait <Shroud>(); FrozenActorLayer = PlayerActor.TraitOrDefault <FrozenActorLayer>(); // Enable the bot logic on the host IsBot = BotType != null; if (IsBot && Game.IsHost) { var logic = PlayerActor.TraitsImplementing <IBot>().FirstOrDefault(b => b.Info.Type == BotType); if (logic == null) { Log.Write("debug", "Invalid bot type: {0}", BotType); } else { logic.Activate(this); } } stanceColors.Self = ChromeMetrics.Get <Color>("PlayerStanceColorSelf"); stanceColors.Allies = ChromeMetrics.Get <Color>("PlayerStanceColorAllies"); stanceColors.Enemies = ChromeMetrics.Get <Color>("PlayerStanceColorEnemies"); stanceColors.Neutrals = ChromeMetrics.Get <Color>("PlayerStanceColorNeutrals"); unlockRenderPlayer = PlayerActor.TraitsImplementing <IUnlocksRenderPlayer>().ToArray(); }
internal World(ModData modData, Map map, OrderManager orderManager, WorldType type) { Type = type; OrderManager = orderManager; orderGenerator = new UnitOrderGenerator(); Map = map; Timestep = orderManager.LobbyInfo.GlobalSettings.Timestep; SharedRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed); LocalRandom = new MersenneTwister(); ModelCache = modData.ModelSequenceLoader.CacheModels(map, modData, map.Rules.ModelSequences); var worldActorType = type == WorldType.Editor ? "EditorWorld" : "World"; WorldActor = CreateActor(worldActorType, new TypeDictionary()); ActorMap = WorldActor.Trait <IActorMap>(); ScreenMap = WorldActor.Trait <ScreenMap>(); Selection = WorldActor.Trait <ISelection>(); OrderValidators = WorldActor.TraitsImplementing <IValidateOrder>().ToArray(); // Reset mask LongBitSet <PlayerBitMask> .Reset(); // Add players // Create an isolated RNG to simplify synchronization between client and server player faction/spawn assignments var playerRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed); foreach (var cmp in WorldActor.TraitsImplementing <ICreatePlayers>()) { cmp.CreatePlayers(this, playerRandom); } // Set defaults for any unset stances foreach (var p in Players) { if (!p.Spectating) { AllPlayersMask = AllPlayersMask.Union(p.PlayerMask); } foreach (var q in Players) { SetUpPlayerMask(p, q); if (!p.Stances.ContainsKey(q)) { p.Stances[q] = Stance.Neutral; } } } Game.Sound.SoundVolumeModifier = 1.0f; gameInfo = new GameInformation { Mod = Game.ModData.Manifest.Id, Version = Game.ModData.Manifest.Metadata.Version, MapUid = Map.Uid, MapTitle = Map.Title }; RulesContainTemporaryBlocker = map.Rules.Actors.Any(a => a.Value.HasTraitInfo <ITemporaryBlockerInfo>()); }