Beispiel #1
0
        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;
        }
Beispiel #3
0
        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;
        }
Beispiel #5
0
 public static Order StartProduction(Player subject, string item, int count)
 {
     return new Order("StartProduction", subject.PlayerActor, new int2( count, 0 ), item );
 }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 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);
 }
Beispiel #9
0
 public static Order PauseProduction(Player subject, string item, bool pause)
 {
     return new Order("PauseProduction", subject.PlayerActor, new int2( pause ? 1 : 0, 0 ), item);
 }
Beispiel #10
0
 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;
            }
Beispiel #12
0
		public bool IsAlliedWith(Player p)
		{
			// Observers are considered allies to active combatants
			return p == null || Stances[p] == Stance.Ally || (p.Spectating && !NonCombatant);
		}
Beispiel #13
0
 public ISound PlayToPlayer(SoundType type, Player player, string name, WPos pos)
 {
     return Play(type, player, name, false, pos, 1f);
 }
Beispiel #14
0
        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);
        }
Beispiel #15
0
 public ISound PlayToPlayer(SoundType type, Player player, string name)
 {
     return Play(type, player, name, true, WPos.Zero, 1f);
 }
Beispiel #16
0
 public static void PlayToPlayer(Player player, string name)
 {
     if( player == player.World.LocalPlayer )
         Play( name );
 }
Beispiel #17
0
        /* 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;
        }
Beispiel #18
0
        // 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;
        }
Beispiel #19
0
		public bool IsAlliedWith(Player p)
		{
			// Observers are considered as allies
			return p == null || Stances[p] == Stance.Ally;
		}
Beispiel #20
0
        // 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);
        }
Beispiel #21
0
        // 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;
        }
Beispiel #22
0
		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);
		}
Beispiel #23
0
 public static ISound PlayToPlayer(Player player, string name, WPos pos)
 {
     return Play(player, name, false, pos, 1);
 }
Beispiel #24
0
        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);
        }
Beispiel #25
0
 public bool IsAlliedWith(Player p)
 {
     return(RelationshipWith(p) == PlayerRelationship.Ally);
 }
Beispiel #26
0
        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);
        }
Beispiel #27
0
 public static int hash_player( Player p )
 {
     if( p != null )
         return p.Index * 0x567;
     return 0;
 }
Beispiel #28
0
 public static ISound PlayToPlayer(Player player, string name)
 {
     return Play(player, name, true, WPos.Zero, 1);
 }
Beispiel #29
0
        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 ) );
        }
Beispiel #30
0
        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);
        }
Beispiel #31
0
        // 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;
        }