public static WPos LerpQuadratic(WPos a, WPos b, WAngle pitch, int mul, int div) { // Start with a linear lerp between the points var ret = Lerp(a, b, mul, div); if (pitch.Angle == 0) return ret; // Add an additional quadratic variation to height // Attempts to avoid integer overflow by keeping the intermediate variables reasonably sized var offset = (int)(((((((long)(b - a).Length * mul) / div) * (div - mul)) / div) * pitch.Tan()) / 1024); return new WPos(ret.X, ret.Y, ret.Z + offset); }
public static WPos LerpQuadratic(WPos a, WPos b, WAngle pitch, int mul, int div) { // Start with a linear lerp between the points var ret = Lerp(a, b, mul, div); if (pitch.Angle == 0) return ret; // Add an additional quadratic variation to height // Uses fp to avoid integer overflow var offset = (int)((float)((float)(b - a).Length*pitch.Tan()*mul*(div - mul)) / (float)(1024*div*div)); return new WPos(ret.X, ret.Y, ret.Z + offset); }
public OpenAlSound(int source, int buffer, bool looping, bool relative, WPos pos, float volume) { if (source == -1) return; Source = source; Volume = volume; AL.Source(source, ALSourcef.Pitch, 1f); AL.Source(source, ALSource3f.Position, pos.X, pos.Y, pos.Z); AL.Source(source, ALSource3f.Velocity, 0f, 0f, 0f); AL.Source(source, ALSourcei.Buffer, buffer); AL.Source(source, ALSourceb.Looping, looping); AL.Source(source, ALSourceb.SourceRelative, relative); AL.Source(source, ALSourcef.ReferenceDistance, 6826); AL.Source(source, ALSourcef.MaxDistance, 136533); AL.SourcePlay(source); }
///<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 WDist DistanceToEdge(WPos pos, WVec dir) { var projectedPos = pos - new WVec(0, pos.Z, pos.Z); var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? ProjectedTopLeft.X : ProjectedBottomRight.X) - projectedPos.X) / dir.X; var y = dir.Y == 0 ? int.MaxValue : ((dir.Y < 0 ? ProjectedTopLeft.Y : ProjectedBottomRight.Y) - projectedPos.Y) / dir.Y; return new WDist(Math.Min(x, y) * dir.Length); }
public static bool PlayVoiceLocal(string phrase, Actor voicedUnit, string variant, WPos pos, float volume) { if (voicedUnit == null || phrase == null) return false; var mi = voicedUnit.Info.Traits.GetOrDefault<SelectableInfo>(); if (mi == null || mi.Voice == null) return false; var type = mi.Voice.ToLowerInvariant(); return PlayPredefined(voicedUnit.World.Map.Rules, null, voicedUnit, type, phrase, variant, false, pos, volume, true); }
public void SetListenerPosition(WPos position) { // Move the listener out of the plane so that sounds near the middle of the screen aren't too positional AL.Listener(ALListener3f.Position, position.X, position.Y, position.Z + 2133); var orientation = new[] { 0f, 0f, 1f, 0f, -1f, 0f }; AL.Listener(ALListenerfv.Orientation, ref orientation); AL.Listener(ALListenerf.EfxMetersPerUnit, .01f); }
public CPos CellContaining(WPos pos) { if (Grid.Type == MapGridType.Rectangular) return new CPos(pos.X / 1024, pos.Y / 1024); // Convert from world position to isometric cell position: // (a) Subtract (512, 512) to move the rotation center to the middle of the corner cell // (b) Rotate axes by -pi/4 // (c) Divide through by sqrt(2) to bring us to an equivalent world pos aligned with u,v axes // (d) Apply an offset so that the integer division by 1024 rounds in the right direction: // (i) u is always positive, so add 512 (which then partially cancels the -1024 term from the rotation) // (ii) v can be negative, so we need to be careful about rounding directions. We add 512 *away from 0* (negative if y > x). // (e) Divide by 1024 to bring into cell coords. var u = (pos.Y + pos.X - 512) / 1024; var v = (pos.Y - pos.X + (pos.Y > pos.X ? 512 : -512)) / 1024; return new CPos(u, v); }
public static ISound Play(string name, WPos pos) { return Play(null, name, false, pos, 1); }
// Returns true if played successfully public static bool PlayPredefined(Ruleset ruleset, Player p, Actor voicedUnit, 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 = (voicedUnit != null) ? ruleset.Voices[type] : ruleset.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, relative, pos, InternalSoundVolume * volumeModifier, attenuateVolume); } return(true); }
public static ISound PlayToPlayer(Player player, string name, WPos pos) { return(Play(player, name, false, pos, 1f)); }
public ISound PlayLooped(string name, WPos pos) { return Play(null, name, true, pos, 1f, true); }
public static ISound Play(string name, WPos pos) { return(Play(null, name, false, pos, 1f)); }
public static ISound Play(string name, WPos pos, float volumeModifier) { return(Play(null, name, false, pos, volumeModifier)); }
public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume) { if (sound == null) { Log.Write("sound", "Attempt to Play2D a null `ISoundSource`"); return(null); } var currFrame = Game.OrderManager.LocalFrameNumber; var atten = 1f; // Check if max # of instances-per-location reached: if (attenuateVolume) { int instances = 0, activeCount = 0; foreach (var s in sourcePool.Values) { if (!s.IsActive) { continue; } if (s.IsRelative != relative) { continue; } ++activeCount; if (s.Sound != sound) { continue; } if (currFrame - s.FrameStarted >= 5) { continue; } // Too far away to count? var lensqr = (s.Pos - pos).LengthSquared; if (lensqr >= GroupDistanceSqr) { continue; } // If we are starting too many instances of the same sound within a short time then stop this one: if (++instances == MaxInstancesPerFrame) { return(null); } } // Attenuate a little bit based on number of active sounds: atten = 0.66f * ((PoolSize - activeCount * 0.5f) / PoolSize); } var source = GetSourceFromPool(); if (source == -1) { return(null); } var slot = sourcePool[source]; slot.Pos = pos; slot.FrameStarted = currFrame; slot.Sound = sound; slot.IsRelative = relative; return(new OpenAlSound(source, ((OpenAlSoundSource)sound).Buffer, loop, relative, pos, volume * atten)); }
public static Order Deserialize(World world, BinaryReader r) { try { var magic = r.ReadByte(); switch (magic) { case 0xFF: { var order = r.ReadString(); var subjectId = r.ReadUInt32(); var flags = (OrderFields)r.ReadByte(); Actor subject = null; if (world != null) { TryGetActorFromUInt(world, subjectId, out subject); } var target = Target.Invalid; if (flags.HasField(OrderFields.Target)) { switch ((TargetType)r.ReadByte()) { case TargetType.Actor: { Actor targetActor; if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out targetActor)) { target = Target.FromActor(targetActor); } break; } case TargetType.FrozenActor: { var playerActorID = r.ReadUInt32(); var frozenActorID = r.ReadUInt32(); Actor playerActor; if (world == null || !TryGetActorFromUInt(world, playerActorID, out playerActor)) { break; } if (playerActor.Owner.FrozenActorLayer == null) { break; } var frozen = playerActor.Owner.FrozenActorLayer.FromID(frozenActorID); if (frozen != null) { target = Target.FromFrozenActor(frozen); } break; } case TargetType.Terrain: { if (flags.HasField(OrderFields.TargetIsCell)) { var cell = new CPos(r.ReadInt32()); var subCell = (SubCell)r.ReadByte(); if (world != null) { target = Target.FromCell(world, cell, subCell); } } else { var pos = new WPos(r.ReadInt32(), r.ReadInt32(), r.ReadInt32()); target = Target.FromPos(pos); } break; } } } var targetString = flags.HasField(OrderFields.TargetString) ? r.ReadString() : null; var queued = flags.HasField(OrderFields.Queued); var extraLocation = flags.HasField(OrderFields.ExtraLocation) ? new CPos(r.ReadInt32()) : CPos.Zero; var extraData = flags.HasField(OrderFields.ExtraData) ? r.ReadUInt32() : 0; if (world == null) { return(new Order(order, null, target, targetString, queued, extraLocation, extraData)); } if (subject == null && subjectId != uint.MaxValue) { return(null); } return(new Order(order, subject, target, targetString, queued, extraLocation, extraData)); } case 0xfe: { var name = r.ReadString(); var flags = (OrderFields)r.ReadByte(); var targetString = flags.HasField(OrderFields.TargetString) ? r.ReadString() : null; var extraData = flags.HasField(OrderFields.ExtraData) ? r.ReadUInt32() : 0; return(new Order(name, null, false) { IsImmediate = true, TargetString = targetString, ExtraData = extraData }); } default: { Log.Write("debug", "Received unknown order with magic {0}", magic); return(null); } } } catch (Exception e) { Log.Write("debug", "Caught exception while processing order"); Log.Write("debug", e.ToString()); // HACK: this can hopefully go away in the future Game.Debug("Ignoring malformed order that would have crashed the game"); Game.Debug("Please file a bug report and include the replay from this match"); return(null); } }
public static bool PlayVoiceLocal(string phrase, Actor voicedUnit, string variant, WPos pos, float volume) { if (voicedUnit == null || phrase == null) { return(false); } var mi = voicedUnit.Info.Traits.GetOrDefault <SelectableInfo>(); if (mi == null || mi.Voice == null) { return(false); } var type = mi.Voice.ToLowerInvariant(); return(PlayPredefined(voicedUnit.World.Map.Rules, null, voicedUnit, type, phrase, variant, false, pos, volume, true)); }
public void SetListenerPosition(WPos position) { }
public static ISound PlayLooped(string name, WPos pos) { return(Play(null, name, true, pos, 1f, true)); }
public static PPos FromWPos(WPos pos) { return new PPos(Game.CellSize*pos.X/1024, Game.CellSize*pos.Y/1024); }
// Returns true if played successfully public bool PlayPredefined(SoundType soundType, 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 || DisableAllSounds || (DisableWorldSounds && soundType == SoundType.World)) { 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; SoundPool pool; 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)); } pool = rules.VoicePools.Value[definition]; } else { if (!rules.NotificationsPools.Value.ContainsKey(definition)) { throw new InvalidOperationException("Can't find {0} in notification pool.".F(definition)); } pool = rules.NotificationsPools.Value[definition]; } var clip = pool.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 * pool.VolumeModifier, attenuateVolume); if (id != 0) { if (currentSounds.ContainsKey(id)) { soundEngine.StopSound(currentSounds[id]); } currentSounds[id] = sound; } } return(true); }
public CPos CellContaining(WPos pos) { if (TileShape == TileShape.Rectangle) return new CPos(pos.X / 1024, pos.Y / 1024); // Convert from world position to diamond cell position: // (a) Subtract (512, 512) to move the rotation center to the middle of the corner cell // (b) Rotate axes by -pi/4 // (c) Add (512, 512) to move back to the center of the cell // (d) Divide by 1024 to find final cell coords var u = (pos.Y + pos.X - 512) / 1024; var v = (pos.Y - pos.X - 512) / 1024; return new CPos(u, v); }
public bool FogObscures(WPos pos) { return(RenderPlayer != null && !RenderPlayer.Shroud.IsVisible(pos)); }
public static ISound PlayToPlayer(Player player, string name, WPos pos) { return Play(player, name, false, pos, 1); }
public bool ShroudObscures(WPos pos) { return(RenderPlayer != null && !RenderPlayer.Shroud.IsExplored(pos)); }
public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume) { return(new NullSound()); }
public static Order Deserialize(World world, BinaryReader r) { var magic = r.ReadByte(); switch (magic) { case 0xFF: { var order = r.ReadString(); var subjectId = r.ReadUInt32(); var flags = (OrderFields)r.ReadByte(); Actor subject = null; if (world != null) { TryGetActorFromUInt(world, subjectId, out subject); } var target = Target.Invalid; if (flags.HasField(OrderFields.Target)) { switch ((TargetType)r.ReadByte()) { case TargetType.Actor: { Actor targetActor; if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out targetActor)) { target = Target.FromActor(targetActor); } break; } case TargetType.FrozenActor: { var playerActorID = r.ReadUInt32(); var frozenActorID = r.ReadUInt32(); Actor playerActor; if (world == null || !TryGetActorFromUInt(world, playerActorID, out playerActor)) { break; } var frozenLayer = playerActor.TraitOrDefault <FrozenActorLayer>(); if (frozenLayer == null) { break; } var frozen = frozenLayer.FromID(frozenActorID); if (frozen != null) { target = Target.FromFrozenActor(frozen); } break; } case TargetType.Terrain: { if (flags.HasField(OrderFields.TargetIsCell)) { var cell = new CPos(r.ReadInt32(), r.ReadInt32(), r.ReadByte()); var subCell = (SubCell)r.ReadInt32(); if (world != null) { target = Target.FromCell(world, cell, subCell); } } else { var pos = new WPos(r.ReadInt32(), r.ReadInt32(), r.ReadInt32()); target = Target.FromPos(pos); } break; } } } var targetString = flags.HasField(OrderFields.TargetString) ? r.ReadString() : null; var queued = flags.HasField(OrderFields.Queued); var extraLocation = flags.HasField(OrderFields.ExtraLocation) ? new CPos(r.ReadInt32(), r.ReadInt32(), r.ReadByte()) : CPos.Zero; var extraData = flags.HasField(OrderFields.ExtraData) ? r.ReadUInt32() : 0; if (world == null) { return(new Order(order, null, target, targetString, queued, extraLocation, extraData)); } if (subject == null && subjectId != uint.MaxValue) { return(null); } return(new Order(order, subject, target, targetString, queued, extraLocation, extraData)); } case 0xfe: { var name = r.ReadString(); var data = r.ReadString(); return(new Order(name, null, false) { IsImmediate = true, TargetString = data }); } default: { Log.Write("debug", "Received unknown order with magic {0}", magic); return(null); } } }
public static Actor ClosestTo(this IEnumerable <Actor> actors, WPos pos) { return(actors.MinByOrDefault(a => (a.CenterPosition - pos).LengthSquared)); }
public PPos ProjectedCellCovering(WPos pos) { var projectedPos = pos - new WVec(0, pos.Z, pos.Z); return((PPos)CellContaining(projectedPos).ToMPos(Grid.Type)); }
public WDist DistanceAboveTerrain(WPos pos) { var cell = CellContaining(pos); var delta = pos - CenterOfCell(cell); return new WDist(delta.Z); }
public void SetListenerPosition(WPos position) { soundEngine.SetListenerPosition(position); }
public PPos ProjectedCellCovering(WPos pos) { var projectedPos = pos - new WVec(0, pos.Z, pos.Z); return (PPos)CellContaining(projectedPos).ToMPos(Grid.Type); }
public ISound Play(SoundType type, string name, WPos pos, float volumeModifier) { return(Play(type, null, name, false, pos, volumeModifier)); }
public void SetBounds(MPos tl, MPos br) { // The tl and br coordinates are inclusive, but the Rectangle // is exclusive. Pad the right and bottom edges to match. Bounds = Rectangle.FromLTRB(tl.U, tl.V, br.U + 1, br.V + 1); CellsInsideBounds = new CellRegion(TileShape, tl.ToCPos(this), br.ToCPos(this)); // Directly calculate the projected map corners in world units avoiding unnecessary // conversions. This abuses the definition that the width of the cell is always // 1024 units, and that the height of two rows is 2048 for classic cells and 1024 // for diamond cells. var wtop = tl.V * 1024; var wbottom = (br.V + 1) * 1024; if (TileShape == TileShape.Diamond) { wtop /= 2; wbottom /= 2; } ProjectedTopLeft = new WPos(tl.U * 1024, wtop, 0); ProjectedBottomRight = new WPos(br.U * 1024 - 1, wbottom - 1, 0); }
public ISound PlayToPlayer(SoundType type, Player player, string name, WPos pos) { return(Play(type, player, name, false, pos, 1f)); }
// Temporary hack for things that throw away altitude and // cache screen positions directly. This can go once all // the callers understand world coordinates public static PPos FromWPosHackZ(WPos pos) { return new PPos(Game.CellSize*pos.X/1024, Game.CellSize*(pos.Y - pos.Z)/1024); }
public ISound PlayLooped(SoundType type, string name, WPos pos) { return(Play(type, null, name, false, pos, 1f, true)); }
public static WPos Lerp(WPos a, WPos b, int mul, int div) { return a + (b - a) * mul / div; }
public ISound Play(SoundType type, string[] names, World world, WPos pos, Player player = null, float volumeModifier = 1f) { return(Play(type, player, names.Random(world.LocalRandom), false, pos, volumeModifier)); }
// 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; }
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); }
public WRange DistanceToEdge(WPos pos, WVec dir) { var tl = CenterOfCell(Cells.TopLeft) - new WVec(512, 512, 0); var br = CenterOfCell(Cells.BottomRight) + new WVec(511, 511, 0); var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? tl.X : br.X) - pos.X) / dir.X; var y = dir.Y == 0 ? int.MaxValue : ((dir.Y < 0 ? tl.Y : br.Y) - pos.Y) / dir.Y; return new WRange(Math.Min(x, y) * dir.Length); }
public static ISound Play(string name, WPos pos, float volumeModifier) { return Play(null, name, false, pos, volumeModifier); }
public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume) { if (sound == null) { Log.Write("sound", "Attempt to Play2D a null `ISoundSource`"); return null; } var world = Game.orderManager.world; int currFrame = world != null ? world.FrameNumber : 0; float atten = 1f; // Check if max # of instances-per-location reached: if (attenuateVolume) { int instances = 0, activeCount = 0; foreach (var s in sourcePool.Values) { if (!s.isActive) continue; if (s.isRelative != relative) continue; ++activeCount; if (s.sound != sound) continue; if (currFrame - s.frameStarted >= 5) continue; // Too far away to count? var lensqr = (s.pos - pos).LengthSquared; if (lensqr >= groupDistanceSqr) continue; // If we are starting too many instances of the same sound within a short time then stop this one: if (++instances == maxInstancesPerFrame) return null; } // Attenuate a little bit based on number of active sounds: atten = 0.66f * ((POOL_SIZE - activeCount * 0.5f) / POOL_SIZE); } int source = GetSourceFromPool(); if (source == -1) return null; var slot = sourcePool[source]; slot.pos = pos; slot.frameStarted = currFrame; slot.sound = sound; slot.isRelative = relative; return new OpenAlSound(source, (sound as OpenAlSoundSource).buffer, loop, relative, pos, volume * atten); }
public static void SetListenerPosition(WPos position) { soundEngine.SetListenerPosition(position); }
public static WPos PositionClosestTo(this IEnumerable <WPos> positions, WPos pos) { return(positions.MinByOrDefault(p => (p - pos).LengthSquared)); }
public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume) { return new NullSound(); }
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 OpenAlSound(int source, int buffer, bool looping, bool relative, WPos pos, float volume) { if (source == -1) return; this.source = source; Al.alSourcef(source, Al.AL_PITCH, 1f); Volume = volume; Al.alSource3f(source, Al.AL_POSITION, pos.X, pos.Y, pos.Z); Al.alSource3f(source, Al.AL_VELOCITY, 0f, 0f, 0f); Al.alSourcei(source, Al.AL_BUFFER, buffer); Al.alSourcei(source, Al.AL_LOOPING, looping ? Al.AL_TRUE : Al.AL_FALSE); Al.alSourcei(source, Al.AL_SOURCE_RELATIVE, relative ? 1 : 0); Al.alSourcef(source, Al.AL_REFERENCE_DISTANCE, 6826); Al.alSourcef(source, Al.AL_MAX_DISTANCE, 136533); Al.alSourcePlay(source); }
public CPos(WPos a) { X = a.X / 1024; Y = a.Y / 1024; }
public void SetListenerPosition(WPos position) { // Move the listener out of the plane so that sounds near the middle of the screen aren't too positional Al.alListener3f(Al.AL_POSITION, position.X, position.Y, position.Z + 2133); var orientation = new[] { 0f, 0f, 1f, 0f, -1f, 0f }; Al.alListenerfv(Al.AL_ORIENTATION, ref orientation[0]); Al.alListenerf(Al.AL_METERS_PER_UNIT, .01f); }
public static Order Deserialize(World world, BinaryReader r) { try { var type = (OrderType)r.ReadByte(); switch (type) { case OrderType.Fields: { var order = r.ReadString(); var flags = (OrderFields)r.ReadInt16(); Actor subject = null; if (flags.HasField(OrderFields.Subject)) { var subjectId = r.ReadUInt32(); if (world != null) { TryGetActorFromUInt(world, subjectId, out subject); } } var target = Target.Invalid; if (flags.HasField(OrderFields.Target)) { switch ((TargetType)r.ReadByte()) { case TargetType.Actor: { if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out var targetActor)) { target = Target.FromActor(targetActor); } break; } case TargetType.FrozenActor: { var playerActorID = r.ReadUInt32(); var frozenActorID = r.ReadUInt32(); if (world == null || !TryGetActorFromUInt(world, playerActorID, out var playerActor)) { break; } if (playerActor.Owner.FrozenActorLayer == null) { break; } var frozen = playerActor.Owner.FrozenActorLayer.FromID(frozenActorID); if (frozen != null) { target = Target.FromFrozenActor(frozen); } break; } case TargetType.Terrain: { if (flags.HasField(OrderFields.TargetIsCell)) { var cell = new CPos(r.ReadInt32()); var subCell = (SubCell)r.ReadByte(); if (world != null) { target = Target.FromCell(world, cell, subCell); } } else { var pos = new WPos(r.ReadInt32(), r.ReadInt32(), r.ReadInt32()); target = Target.FromPos(pos); } break; } } } var targetString = flags.HasField(OrderFields.TargetString) ? r.ReadString() : null; var queued = flags.HasField(OrderFields.Queued); Actor[] extraActors = null; if (flags.HasField(OrderFields.ExtraActors)) { var count = r.ReadInt32(); if (world != null) { extraActors = Exts.MakeArray(count, _ => world.GetActorById(r.ReadUInt32())); } else { r.ReadBytes(4 * count); } } var extraLocation = flags.HasField(OrderFields.ExtraLocation) ? new CPos(r.ReadInt32()) : CPos.Zero; var extraData = flags.HasField(OrderFields.ExtraData) ? r.ReadUInt32() : 0; Actor[] groupedActors = null; if (flags.HasField(OrderFields.Grouped)) { var count = r.ReadInt32(); if (world != null) { groupedActors = Exts.MakeArray(count, _ => world.GetActorById(r.ReadUInt32())); } else { r.ReadBytes(4 * count); } } if (world == null) { return(new Order(order, null, target, targetString, queued, extraActors, extraLocation, extraData, groupedActors)); } if (subject == null && flags.HasField(OrderFields.Subject)) { return(null); } return(new Order(order, subject, target, targetString, queued, extraActors, extraLocation, extraData, groupedActors)); } case OrderType.Handshake: { var name = r.ReadString(); var targetString = r.ReadString(); return(new Order(name, null, false) { Type = OrderType.Handshake, TargetString = targetString }); } default: { Log.Write("debug", "Received unknown order with type {0}", type); return(null); } } } catch (Exception e) { Log.Write("debug", "Caught exception while processing order"); Log.Write("debug", e.ToString()); // HACK: this can hopefully go away in the future Game.Debug("Ignoring malformed order that would have crashed the game"); Game.Debug("Please file a bug report and include the replay from this match"); return(null); } }