public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore) { var res = world.WorldActor.traits.Get<ResourceLayer>(); return !Footprint.Tiles(name, building, topLeft).Any( t => !world.Map.IsInMap(t.X, t.Y) || res.GetResource(t) != null || !world.IsCellBuildable(t, building.WaterBound, toIgnore)); }
public Player( World world, Session.Client client ) { World = world; Shroud = new ShroudRenderer(this, world.Map); PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this); if (client != null) { Index = client.Index; Palette = PlayerColors[client.PaletteIndex % PlayerColors.Count()].a; Color = PlayerColors[client.PaletteIndex % PlayerColors.Count()].c; PlayerName = client.Name; InternalName = "Multi{0}".F(client.Index); } else { Index = -1; PlayerName = InternalName = "Neutral"; Palette = "neutral"; Color = Color.Gray; // HACK HACK } Country = world.GetCountries() .FirstOrDefault(c => client != null && client.Country == c.Name) ?? world.GetCountries().Random(world.SharedRandom); }
public void Add(World w, Actor a) { actors.Add(a); foreach (var sel in a.TraitsImplementing<INotifySelected>()) sel.Selected(a); foreach (var ns in w.WorldActor.TraitsImplementing<INotifySelection>()) ns.SelectionChanged(); }
public PathSearch(Actor self) { this.self = self; world = self.World; cellInfo = InitCellInfo(); mobile = self.Trait<Mobile>(); queue = new PriorityQueue<PathDistance>(); }
public override Activity Tick(Actor self) { if (move == null || refuelsNear == null) return NextActivity; self.SetTargetLine(target, Color.Green); return ActivityUtils.SequenceActivities(move.MoveWithinRange(target, refuelsNear.Info.Range), NextActivity); }
public static PathSearch Search(World world, MobileInfo mi, Actor self, bool checkForBlocked) { var search = new PathSearch(world, mi, self) { CheckForBlocked = checkForBlocked }; return search; }
public Order(string orderString, Actor subject, Actor targetActor, int2 targetLocation, string targetString) { this.OrderString = orderString; this.Subject = subject; this.TargetActor = targetActor; this.TargetLocation = targetLocation; this.TargetString = targetString; }
public static PathSearch FromPoint( Actor self, int2 from, int2 target, bool checkForBlocked ) { var search = new PathSearch(self) { heuristic = DefaultEstimator( target ), checkForBlocked = checkForBlocked }; search.AddInitialCell( self.World, from ); return search; }
Order(string orderString, Actor subject, Actor targetActor, int2 targetLocation, string targetString, bool queued, int2 extraLocation) { this.OrderString = orderString; this.Subject = subject; this.TargetActor = targetActor; this.TargetLocation = targetLocation; this.TargetString = targetString; this.Queued = queued; this.ExtraLocation = extraLocation; }
public static PathSearch FromPoint(World world, MobileInfo mi, Actor self, CPos from, CPos target, bool checkForBlocked) { var search = new PathSearch(world, mi, self) { Heuristic = DefaultEstimator(target), CheckForBlocked = checkForBlocked }; search.AddInitialCell(from); return search; }
public PathSearch(World world, MobileInfo mobileInfo, Actor self) { this.self = self; CellInfo = InitCellInfo(); this.mobileInfo = mobileInfo; this.self = self; customCost = null; Queue = new PriorityQueue<PathDistance>(); Considered = new HashSet<CPos>(); MaxCost = 0; nextDirections = CVec.directions.Select(d => new Pair<CVec, int>(d, 0)).ToArray(); }
Order(string orderString, Actor subject, Actor targetActor, CPos targetLocation, string targetString, bool queued, CPos extraLocation, uint extraData) { this.OrderString = orderString; this.Subject = subject; this.TargetActor = targetActor; this.TargetLocation = targetLocation; this.TargetString = targetString; this.Queued = queued; this.ExtraLocation = extraLocation; this.ExtraData = extraData; }
Order(string orderString, Actor subject, Actor targetActor, CPos targetLocation, string targetString, bool queued, CPos extraLocation, uint extraData) { OrderString = orderString; Subject = subject; TargetActor = targetActor; TargetLocation = targetLocation; TargetString = targetString; Queued = queued; ExtraLocation = extraLocation; ExtraData = extraData; }
public static PathSearch FromPoints(World world, MobileInfo mi, Actor self, IEnumerable<CPos> froms, CPos target, bool checkForBlocked) { var search = new PathSearch(world, mi, self) { Heuristic = DefaultEstimator(target), CheckForBlocked = checkForBlocked }; foreach (var sl in froms) search.AddInitialCell(sl); return search; }
public static void DoExplosion(Actor attacker, string weapontype, int2 location, int altitude) { var args = new ProjectileArgs { src = location, dest = location, srcAltitude = altitude, destAltitude = altitude, firedBy = attacker, target = null, weapon = Rules.Weapons[ weapontype.ToLowerInvariant() ], facing = 0 }; DoImpacts(args, location); }
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; Playable = pr.Playable; Spectating = pr.Spectating; 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, PlayerReference pr, int index) { World = world; Index = index; Palette = "player" + index; ColorRamp = pr.ColorRamp; ClientIndex = 0; /* it's a map player, "owned" by host */ PlayerName = InternalName = pr.Name; NonCombatant = pr.NonCombatant; Country = world.GetCountries() .FirstOrDefault(c => pr.Race == c.Race) ?? world.GetCountries().Random(world.SharedRandom); PlayerRef = pr; PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); }
public PathSearch WithIgnoredBuilding(Actor b) { IgnoreBuilding = b; return this; }
public static bool PlayVoice(string phrase, Actor voicedUnit, string variant) { if (voicedUnit == null) return false; if (phrase == null) return false; var mi = voicedUnit.Info.Traits.GetOrDefault<SelectableInfo>(); if (mi == null) return false; if (mi.Voice == null) return false; var type = mi.Voice.ToLowerInvariant(); return PlayPredefined(null, voicedUnit, type, phrase, variant, true); }
// 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 bool Contains(Actor a) { return actors.AsEnumerable().Contains(a); }
public void Update(Actor self, IOccupySpace unit) { Remove(self, unit); if (!self.IsDead()) Add(self, unit); }
public RefuelNear(Actor self, Actor host) { move = self.TraitOrDefault<IMove>(); target = Target.FromActor(host); refuelsNear = host.TraitOrDefault<RefuelsUnitsNear>(); }
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; ColorRamp = client.ColorRamp; PlayerName = client.Name; botType = client.Bot; Country = world.GetCountries() .FirstOrDefault(c => client.Country == c.Race) ?? world.GetCountries().Random(world.SharedRandom); } else { // Map player ClientIndex = 0; // Owned by the host (todo: fix this) ColorRamp = pr.ColorRamp; PlayerName = pr.Name; NonCombatant = pr.NonCombatant; botType = pr.Bot; Country = world.GetCountries() .FirstOrDefault(c => pr.Race == c.Race) ?? world.GetCountries().Random(world.SharedRandom); } PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); // 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 void Add( Actor self, IOccupySpace unit ) { if (unit != null) foreach( var c in unit.OccupiedCells() ) influence[ c.First.X, c.First.Y ] = new InfluenceNode { next = influence[ c.First.X, c.First.Y ], subCell = c.Second, actor = self }; }
void RemoveInner( ref InfluenceNode influenceNode, Actor toRemove ) { if( influenceNode == null ) return; else if( influenceNode.actor == toRemove ) influenceNode = influenceNode.next; if (influenceNode != null) RemoveInner( ref influenceNode.next, toRemove ); }
public bool CanViewActor(Actor a) { return a.CanBeViewedByPlayer(this); }
// Returns true if it played a phrase public static bool PlayVoice(string phrase, Actor voicedUnit, string variant) { if (voicedUnit == null) return false; if (phrase == null) return false; var mi = voicedUnit.Info.Traits.GetOrDefault<SelectableInfo>(); if (mi == null) return false; if (mi.Voice == null) return false; var vi = Rules.Voices[mi.Voice.ToLowerInvariant()]; if (!vi.Pools.Value.ContainsKey(phrase)) return false; var clip = vi.Pools.Value[phrase].GetNext(); if (clip == null) return false; var variantExt = (vi.Variants.ContainsKey(variant) && !vi.DisableVariants.Contains(phrase)) ? vi.Variants[variant][voicedUnit.ActorID % vi.Variants[variant].Length] : vi.DefaultVariant; var prefix = (vi.Prefixes.ContainsKey(variant) && !vi.DisablePrefixes.Contains(phrase)) ? vi.Prefixes[variant][voicedUnit.ActorID % vi.Prefixes[variant].Length] : vi.DefaultPrefix; Play(prefix + clip + variantExt); return true; }
public int? GetControlGroupForActor(Actor a) { return controlGroups.Where(g => g.Value.Contains(a)) .Select(g => (int?)g.Key) .FirstOrDefault(); }
public bool CanTargetActor(Actor a) { if (HasFogVisibility && fogVisibilities.Any(f => f.IsVisible(a))) return true; return CanViewActor(a); }