public ShroudRenderer(Player owner, Map map) { this.shroud = owner.World.WorldActor.Trait<Traits.Shroud>(); this.map = map; sprites = new Sprite[map.MapSize.X, map.MapSize.Y]; fogSprites = new Sprite[map.MapSize.X, map.MapSize.Y]; shroud.Dirty += () => dirty = true; }
///<summary>Evaluates the attractiveness of a group of actors according to all considerations</summary> public int GetAttractiveness(IEnumerable<Actor> actors, Player firedBy) { var answer = 0; foreach (var consideration in Considerations) foreach (var scrutinized in actors) answer += consideration.GetAttractiveness(scrutinized, firedBy.Stances[scrutinized.Owner], firedBy); return answer; }
public Actor( World world, string name, int2 location, Player owner ) { World = world; ActorID = world.NextAID(); Location = location; CenterLocation = Traits.Util.CenterOfCell(Location); Owner = owner; if (name != null) { Info = Rules.Info[name.ToLowerInvariant()]; Health = this.GetMaxHP(); foreach (var trait in Info.TraitsInConstructOrder()) traits.Add(trait.Create(this)); } }
///<summary>Evaluates the attractiveness of a position according to all considerations</summary> public int GetAttractiveness(WPos pos, Player firedBy) { var answer = 0; var world = firedBy.World; var targetTile = world.Map.CellContaining(pos); if (!world.Map.Contains(targetTile)) return 0; foreach (var consideration in Considerations) { var radiusToUse = new WRange(consideration.CheckRadius.Range); var checkActors = world.FindActorsInCircle(pos, radiusToUse); foreach (var scrutinized in checkActors) answer += consideration.GetAttractiveness(scrutinized, firedBy.Stances[scrutinized.Owner], firedBy); } return answer; }
public static Order StartProduction(Player subject, string item, int count) { return new Order("StartProduction", subject.PlayerActor, new int2( count, 0 ), item ); }
public bool PlayNotification(Ruleset rules, Player player, string type, string notification, string variant) { if (rules == null) throw new ArgumentNullException("rules"); if (type == null || notification == null) return false; return PlayPredefined(rules, player, null, type.ToLowerInvariant(), notification, variant, true, WPos.Zero, 1f, false); }
public static Order CancelProduction(Player subject, string item) { return new Order("CancelProduction", subject.PlayerActor, item); }
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { fuelReserve.RemoveCapacity(info.Capacity); fuelReserve = newOwner.PlayerActor.Trait<Fueltank>(); fuelReserve.AddCapacity(info.Capacity); }
public static Order PauseProduction(Player subject, string item, bool pause) { return new Order("PauseProduction", subject.PlayerActor, new int2( pause ? 1 : 0, 0 ), item); }
public static void PlayToPlayer(Player player, string name, float2 pos) { if (player == player.World.LocalPlayer) Play(name, pos); }
///<summary>Evaluates a single actor according to the rules defined in this consideration</summary> public int GetAttractiveness(Actor a, Stance stance, Player firedBy) { if (stance != Against) return 0; if (a == null) return 0; var targetable = a.TraitOrDefault<ITargetable>(); if (targetable == null) return 0; if (!targetable.TargetableBy(a, firedBy.PlayerActor)) return 0; if (Types.Intersect(targetable.TargetTypes).Any()) { switch (TargetMetric) { case DecisionMetric.Value: var valueInfo = a.Info.Traits.GetOrDefault<ValuedInfo>(); return (valueInfo != null) ? valueInfo.Cost * Attractiveness : 0; case DecisionMetric.Health: var health = a.TraitOrDefault<Health>(); return (health != null) ? (health.HP / health.MaxHP) * Attractiveness : 0; default: return Attractiveness; } } return 0; }
public bool IsAlliedWith(Player p) { // Observers are considered allies to active combatants return p == null || Stances[p] == Stance.Ally || (p.Spectating && !NonCombatant); }
public ISound PlayToPlayer(SoundType type, Player player, string name, WPos pos) { return Play(type, player, name, false, pos, 1f); }
ISound Play(SoundType type, Player player, string name, bool headRelative, WPos pos, float volumeModifier = 1f, bool loop = false) { if (string.IsNullOrEmpty(name) || (DisableWorldSounds && type == SoundType.World)) return null; if (player != null && player != player.World.LocalPlayer) return null; return soundEngine.Play2D(sounds[name], loop, headRelative, pos, InternalSoundVolume * volumeModifier, true); }
public ISound PlayToPlayer(SoundType type, Player player, string name) { return Play(type, player, name, true, WPos.Zero, 1f); }
public static void PlayToPlayer(Player player, string name) { if( player == player.World.LocalPlayer ) Play( name ); }
/* must never be relied on in synced code! */ public static bool IsVisible(this Actor a, Player byPlayer) { if (byPlayer == null) return true; // Observer if (a.World.LocalPlayer != null && a.World.LocalPlayer.Shroud.Disabled) return true; var shroud = a.World.WorldActor.Trait<Shroud>(); if (!Shroud.GetVisOrigins(a).Any(o => a.World.Map.IsInMap(o) && shroud.exploredCells[o.X, o.Y])) // covered by shroud return false; if (a.TraitsImplementing<IVisibilityModifier>().Any(t => !t.IsVisible(a, byPlayer))) return false; return true; }
// Returns true if played successfully public bool PlayPredefined(Ruleset ruleset, Player p, Actor voicedActor, string type, string definition, string variant, bool relative, WPos pos, float volumeModifier, bool attenuateVolume) { if (ruleset == null) throw new ArgumentNullException("ruleset"); if (definition == null) return false; if (ruleset.Voices == null || ruleset.Notifications == null) return false; var rules = (voicedActor != null) ? ruleset.Voices[type] : ruleset.Notifications[type]; if (rules == null) return false; var id = voicedActor != null ? voicedActor.ActorID : 0; string clip; var suffix = rules.DefaultVariant; var prefix = rules.DefaultPrefix; if (voicedActor != null) { if (!rules.VoicePools.Value.ContainsKey(definition)) throw new InvalidOperationException("Can't find {0} in voice pool.".F(definition)); clip = rules.VoicePools.Value[definition].GetNext(); } else { if (!rules.NotificationsPools.Value.ContainsKey(definition)) throw new InvalidOperationException("Can't find {0} in notification pool.".F(definition)); clip = rules.NotificationsPools.Value[definition].GetNext(); } if (string.IsNullOrEmpty(clip)) return false; if (variant != null) { if (rules.Variants.ContainsKey(variant) && !rules.DisableVariants.Contains(definition)) suffix = rules.Variants[variant][id % rules.Variants[variant].Length]; if (rules.Prefixes.ContainsKey(variant) && !rules.DisablePrefixes.Contains(definition)) prefix = rules.Prefixes[variant][id % rules.Prefixes[variant].Length]; } var name = prefix + clip + suffix; if (!string.IsNullOrEmpty(name) && (p == null || p == p.World.LocalPlayer)) { var sound = soundEngine.Play2D(sounds[name], false, relative, pos, InternalSoundVolume * volumeModifier, attenuateVolume); if (id != 0) { if (currentSounds.ContainsKey(id)) soundEngine.StopSound(currentSounds[id]); currentSounds[id] = sound; } } return true; }
public bool IsAlliedWith(Player p) { // Observers are considered as allies return p == null || Stances[p] == Stance.Ally; }
// Adds the player information at start-up. public void AddPlayer(OpenRA.Player runtimePlayer, Session lobbyInfo) { if (runtimePlayer == null) throw new ArgumentNullException("runtimePlayer"); if (lobbyInfo == null) throw new ArgumentNullException("lobbyInfo"); // We don't care about spectators and map players if (runtimePlayer.NonCombatant || !runtimePlayer.Playable) return; // Find the lobby client that created the runtime player var client = lobbyInfo.ClientWithIndex(runtimePlayer.ClientIndex); if (client == null) return; var player = new Player { ClientIndex = runtimePlayer.ClientIndex, Name = runtimePlayer.PlayerName, IsHuman = !runtimePlayer.IsBot, IsBot = runtimePlayer.IsBot, FactionName = runtimePlayer.Faction.Name, FactionId = runtimePlayer.Faction.InternalName, Color = runtimePlayer.Color, Team = client.Team, SpawnPoint = runtimePlayer.SpawnPoint, IsRandomFaction = runtimePlayer.Faction.InternalName != client.Race, IsRandomSpawnPoint = runtimePlayer.SpawnPoint != client.SpawnPoint }; playersByRuntime.Add(runtimePlayer, player); Players.Add(player); }
// Returns true if played successfully public static bool PlayPredefined(Player p, Actor voicedUnit, string type, string definition, string variant, bool attenuateVolume) { if (definition == null) return false; if (Rules.Voices == null) return false; if (Rules.Notifications == null) return false; var rules = (voicedUnit != null) ? Rules.Voices[type] : Rules.Notifications[type]; if (rules == null) return false; var ID = (voicedUnit != null) ? voicedUnit.ActorID : 0; string clip; var suffix = rules.DefaultVariant; var prefix = rules.DefaultPrefix; if (voicedUnit != null) { if (!rules.VoicePools.Value.ContainsKey("Attack")) rules.VoicePools.Value.Add("Attack", rules.VoicePools.Value["Move"]); if (!rules.VoicePools.Value.ContainsKey("AttackMove")) rules.VoicePools.Value.Add("AttackMove", rules.VoicePools.Value["Move"]); if (!rules.VoicePools.Value.ContainsKey(definition)) throw new InvalidOperationException("Can't find {0} in voice pool.".F(definition)); clip = rules.VoicePools.Value[definition].GetNext(); } else { if (!rules.NotificationsPools.Value.ContainsKey(definition)) throw new InvalidOperationException("Can't find {0} in notification pool.".F(definition)); clip = rules.NotificationsPools.Value[definition].GetNext(); } if (String.IsNullOrEmpty(clip)) return false; if (variant != null) { if (rules.Variants.ContainsKey(variant) && !rules.DisableVariants.Contains(definition)) suffix = rules.Variants[variant][ID % rules.Variants[variant].Length]; if (rules.Prefixes.ContainsKey(variant) && !rules.DisablePrefixes.Contains(definition)) prefix = rules.Prefixes[variant][ID % rules.Prefixes[variant].Length]; } var name = prefix + clip + suffix; if (!String.IsNullOrEmpty(name) && (p == null || p == p.World.LocalPlayer)) soundEngine.Play2D(sounds[name], false, true, WPos.Zero, InternalSoundVolume, attenuateVolume); return true; }
public void SetStance(Player target, Stance s) { var oldStance = Stances[target]; Stances[target] = s; target.Shroud.UpdatePlayerStance(World, this, oldStance, s); Shroud.UpdatePlayerStance(World, target, oldStance, s); foreach (var nsc in World.ActorsWithTrait<INotifyStanceChanged>()) nsc.Trait.StanceChanged(nsc.Actor, this, target, oldStance, s); }
public static ISound PlayToPlayer(Player player, string name, WPos pos) { return Play(player, name, false, pos, 1); }
static ISound Play(Player player, string name, bool headRelative, PPos pos, float volumeModifier) { if (player != null && player != player.World.LocalPlayer) return null; if (name == "" || name == null) return null; return soundEngine.Play2D(sounds[name], false, headRelative, pos.ToFloat2(), InternalSoundVolume * volumeModifier); }
public bool IsAlliedWith(Player p) { return(RelationshipWith(p) == PlayerRelationship.Ally); }
public static bool PlayNotification(Player player, string type, string notification, string variant) { if (type == null) return false; if (notification == null) return false; return PlayPredefined(player, null, type.ToLowerInvariant(), notification, variant, false); }
public static int hash_player( Player p ) { if( p != null ) return p.Index * 0x567; return 0; }
public static ISound PlayToPlayer(Player player, string name) { return Play(player, name, true, WPos.Zero, 1); }
public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 topLeft) { var buildingMaxBounds = bi.Dimensions; if( bi.Bib ) buildingMaxBounds.Y += 1; var scanStart = world.ClampToWorld( topLeft - new int2( bi.Adjacent, bi.Adjacent ) ); var scanEnd = world.ClampToWorld( topLeft + buildingMaxBounds + new int2( bi.Adjacent, bi.Adjacent ) ); var nearnessCandidates = new List<int2>(); for( int y = scanStart.Y ; y < scanEnd.Y ; y++ ) { for( int x = scanStart.X ; x < scanEnd.X ; x++ ) { var at = world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt( new int2( x, y ) ); if( at != null && at.Owner == p && at.Info.Traits.Get<BuildingInfo>().BaseNormal) nearnessCandidates.Add( new int2( x, y ) ); } } var buildingTiles = Footprint.Tiles( buildingName, bi, topLeft ).ToList(); return nearnessCandidates .Any( a => buildingTiles .Any( b => Math.Abs( a.X - b.X ) <= bi.Adjacent && Math.Abs( a.Y - b.Y ) <= bi.Adjacent ) ); }
static ISound Play(Player player, string name, bool headRelative, WPos pos, float volumeModifier) { if (String.IsNullOrEmpty(name)) return null; if (player != null && player != player.World.LocalPlayer) return null; return soundEngine.Play2D(sounds[name], false, headRelative, pos, InternalSoundVolume * volumeModifier, true); }
// Returns true if played successfully public static bool PlayPredefined(Player p, Actor voicedUnit, string type, string definition, string variant) { if (definition == null) return false; if (Rules.Voices == null) return false; if (Rules.Notifications == null) return false; var rules = (voicedUnit != null) ? Rules.Voices[type] : Rules.Notifications[type]; if (rules == null) return false; var ID = (voicedUnit != null) ? voicedUnit.ActorID : 0; var clip = (voicedUnit != null) ? rules.VoicePools.Value[definition].GetNext() : rules.NotificationsPools.Value[definition].GetNext(); if (clip == null) return false; var suffix = rules.DefaultVariant; var prefix = rules.DefaultPrefix; if (voicedUnit != null) { if (!rules.VoicePools.Value.ContainsKey("Attack")) rules.VoicePools.Value.Add("Attack", rules.VoicePools.Value["Move"]); if (!rules.VoicePools.Value.ContainsKey("AttackMove")) rules.VoicePools.Value.Add("AttackMove", rules.VoicePools.Value["Move"]); } if (variant != null) { if (rules.Variants.ContainsKey(variant) && !rules.DisableVariants.Contains(definition)) suffix = rules.Variants[variant][ID % rules.Variants[variant].Length]; if (rules.Prefixes.ContainsKey(variant) && !rules.DisablePrefixes.Contains(definition)) prefix = rules.Prefixes[variant][ID % rules.Prefixes[variant].Length]; } if (p == null) Play(prefix + clip + suffix); else PlayToPlayer(p, prefix + clip + suffix); return true; }