protected override bool ShouldStop(Actor self, CPos oldTargetPosition) { // We are now in range. Don't move any further! // HACK: This works around the pathfinder not returning the shortest path var cp = self.CenterPosition; return target.IsInRange(cp, maxRange) && !target.IsInRange(cp, minRange); }
public bool SimilarTerrain(CPos xy, CPos sourceLocation) { if (!Self.Owner.Shroud.IsExplored(xy)) return false; var range = ((ChronoshiftPowerInfo)Info).Range; var sourceTiles = Self.World.Map.FindTilesInCircle(xy, range); var destTiles = Self.World.Map.FindTilesInCircle(sourceLocation, range); using (var se = sourceTiles.GetEnumerator()) using (var de = destTiles.GetEnumerator()) while (se.MoveNext() && de.MoveNext()) { var a = se.Current; var b = de.Current; if (!Self.Owner.Shroud.IsExplored(a) || !Self.Owner.Shroud.IsExplored(b)) return false; if (Self.World.Map.GetTerrainIndex(a) != Self.World.Map.GetTerrainIndex(b)) return false; } return true; }
ClearSides FindClearSides(ResourceType t, CPos p) { var ret = ClearSides.None; if (Tiles[p + new CVec(0, -1)].Type != t) ret |= ClearSides.Top | ClearSides.TopLeft | ClearSides.TopRight; if (Tiles[p + new CVec(-1, 0)].Type != t) ret |= ClearSides.Left | ClearSides.TopLeft | ClearSides.BottomLeft; if (Tiles[p + new CVec(1, 0)].Type != t) ret |= ClearSides.Right | ClearSides.TopRight | ClearSides.BottomRight; if (Tiles[p + new CVec(0, 1)].Type != t) ret |= ClearSides.Bottom | ClearSides.BottomLeft | ClearSides.BottomRight; if (Tiles[p + new CVec(-1, -1)].Type != t) ret |= ClearSides.TopLeft; if (Tiles[p + new CVec(1, -1)].Type != t) ret |= ClearSides.TopRight; if (Tiles[p + new CVec(-1, 1)].Type != t) ret |= ClearSides.BottomLeft; if (Tiles[p + new CVec(1, 1)].Type != t) ret |= ClearSides.BottomRight; return ret; }
public string GetCursor(World world, CPos xy, MouseInput mi) { var useSelect = false; var underCursor = world.ScreenMap.ActorsAt(mi) .Where(a => !world.FogObscures(a) && a.HasTrait<ITargetable>()) .OrderByDescending(a => a.Info.SelectionPriority()) .FirstOrDefault(); if (underCursor != null && (mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any())) { var selectable = underCursor.TraitOrDefault<Selectable>(); if (selectable != null && selectable.Info.Selectable) useSelect = true; } Target target; if (underCursor != null) target = Target.FromActor(underCursor); else { var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, mi) .Where(a => a.Info.Traits.Contains<ITargetableInfo>()) .OrderByDescending(a => a.Info.SelectionPriority()) .FirstOrDefault(); target = frozen != null ? Target.FromFrozenActor(frozen) : Target.FromCell(xy); } var orders = world.Selection.Actors .Select(a => OrderForUnit(a, target, mi)) .Where(o => o != null) .ToArray(); var cursorName = orders.Select(o => o.Cursor).FirstOrDefault(); return cursorName ?? (useSelect ? "select" : "default"); }
public Teleport(Actor chronosphere, CPos destination, bool killCargo, string sound) { this.chronosphere = chronosphere; this.destination = destination; this.killCargo = killCargo; this.sound = sound; }
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi) { if (mi.Button == MouseButton.Right) world.CancelInputMode(); return OrderInner(world, xy, mi); }
public override CellContents UpdateDirtyTile(CPos c) { var t = Tiles[c]; // Empty tile if (t.Type == null) { t.Sprite = null; return t; } t.Density = ResourceDensityAt(c); int index; var clear = FindClearSides(t.Type, c); if (clear == ClearSides.None) { var sprites = D2kResourceLayer.Variants[t.Variant]; var frame = t.Density > t.Type.Info.MaxDensity / 2 ? 1 : 0; t.Sprite = t.Type.Variants.First().Value[sprites[frame]]; } else if (D2kResourceLayer.SpriteMap.TryGetValue(clear, out index)) t.Sprite = t.Type.Variants.First().Value[index]; else t.Sprite = null; return t; }
public void Tick(Actor self) { // todo: don't tick all the time. if(self.Owner == null) return; if (previousLocation != self.Location && v != null) { previousLocation = self.Location; var shrouds = self.World.ActorsWithTrait<Shroud>().Select(s => s.Actor.Owner.Shroud); foreach (var shroud in shrouds) { shroud.UnhideActor(self, v, Info.Range); } } if (!self.TraitsImplementing<IDisable>().Any(d => d.Disabled)) { var shrouds = self.World.ActorsWithTrait<Shroud>().Select(s => s.Actor.Owner.Shroud); foreach (var shroud in shrouds) { shroud.HideActor(self, Info.Range); } } else { var shrouds = self.World.ActorsWithTrait<Shroud>().Select(s => s.Actor.Owner.Shroud); foreach (var shroud in shrouds) { shroud.UnhideActor(self, v, Info.Range); } } v = new Shroud.ActorVisibility { vis = Shroud.GetVisOrigins(self).ToArray() }; }
public string GetCursor(World world, CPos xy, MouseInput mi) { var useSelect = false; var underCursor = world.ScreenMap.ActorsAt(mi) .Where(a => !world.FogObscures(a) && a.HasTrait<ITargetable>()) .WithHighestSelectionPriority(); if (underCursor != null && (mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any())) { var selectable = underCursor.TraitOrDefault<Selectable>(); if (selectable != null && selectable.Info.Selectable) useSelect = true; } Target target; if (underCursor != null) target = Target.FromActor(underCursor); else { var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, mi) .Where(a => a.Info.Traits.Contains<ITargetableInfo>() && !a.Footprint.All(world.ShroudObscures)) .WithHighestSelectionPriority(); target = frozen != null ? Target.FromFrozenActor(frozen) : Target.FromCell(world, xy); } var ordersWithCursor = world.Selection.Actors .Select(a => OrderForUnit(a, target, mi)) .Where(o => o != null && o.Cursor != null); var cursorOrder = ordersWithCursor.MaxByOrDefault(o => o.Order.OrderPriority); return cursorOrder != null ? cursorOrder.Cursor : (useSelect ? "select" : "default"); }
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi) { var underCursor = world.FindUnitsAtMouse(mi.Location) .Where(a => a.HasTrait<ITargetable>()) .OrderByDescending(a => a.Info.SelectionPriority()) .FirstOrDefault(); Target target; if (underCursor != null) target = Target.FromActor(underCursor); else { var frozen = world.FindFrozenActorsAtMouse(mi.Location) .Where(a => a.Info.Traits.Contains<ITargetableInfo>()) .OrderByDescending(a => a.Info.SelectionPriority()) .FirstOrDefault(); target = frozen != null ? Target.FromFrozenActor(frozen) : Target.FromCell(xy); } var orders = world.Selection.Actors .Select(a => OrderForUnit(a, target, mi)) .Where(o => o != null) .ToArray(); var actorsInvolved = orders.Select(o => o.self).Distinct(); if (actorsInvolved.Any()) yield return new Order("CreateGroup", actorsInvolved.First().Owner.PlayerActor, false) { TargetString = actorsInvolved.Select(a => a.ActorID).JoinWith(",") }; foreach (var o in orders) yield return CheckSameOrder(o.iot, o.trait.IssueOrder(o.self, o.iot, o.target, mi.Modifiers.HasModifier(Modifiers.Shift))); }
protected override void UpdateRenderedSprite(CPos p) { // Need to update neighbouring tiles too UpdateRenderedTileInner(p); UpdateRenderedTileInner(p + new CVec(-1, -1)); UpdateRenderedTileInner(p + new CVec(0, -1)); UpdateRenderedTileInner(p + new CVec(1, -1)); UpdateRenderedTileInner(p + new CVec(-1, 0)); UpdateRenderedTileInner(p + new CVec(1, 0)); UpdateRenderedTileInner(p + new CVec(-1, 1)); UpdateRenderedTileInner(p + new CVec(0, 1)); UpdateRenderedTileInner(p + new CVec(1, 1)); UpdateRenderedTileInner(p + new CVec(-2, -2)); UpdateRenderedTileInner(p + new CVec(-1, -2)); UpdateRenderedTileInner(p + new CVec(0, -2)); UpdateRenderedTileInner(p + new CVec(1, -2)); UpdateRenderedTileInner(p + new CVec(2, -2)); UpdateRenderedTileInner(p + new CVec(2, -1)); UpdateRenderedTileInner(p + new CVec(2, 0)); UpdateRenderedTileInner(p + new CVec(2, 1)); UpdateRenderedTileInner(p + new CVec(2, 2)); UpdateRenderedTileInner(p + new CVec(1, 2)); UpdateRenderedTileInner(p + new CVec(0, 2)); UpdateRenderedTileInner(p + new CVec(-1, 2)); UpdateRenderedTileInner(p + new CVec(-2, 2)); UpdateRenderedTileInner(p + new CVec(-2, 1)); UpdateRenderedTileInner(p + new CVec(-2, 0)); UpdateRenderedTileInner(p + new CVec(-2, -1)); }
ClearSides FindClearSides(ResourceType t, CPos p) { var ret = ClearSides.None; if (!CellContains(p + new CVec(0, -1), t)) ret |= ClearSides.Top | ClearSides.TopLeft | ClearSides.TopRight; if (!CellContains(p + new CVec(-1, 0), t)) ret |= ClearSides.Left | ClearSides.TopLeft | ClearSides.BottomLeft; if (!CellContains(p + new CVec(1, 0), t)) ret |= ClearSides.Right | ClearSides.TopRight | ClearSides.BottomRight; if (!CellContains(p + new CVec(0, 1), t)) ret |= ClearSides.Bottom | ClearSides.BottomLeft | ClearSides.BottomRight; if (!CellContains(p + new CVec(-1, -1), t)) ret |= ClearSides.TopLeft; if (!CellContains(p + new CVec(1, -1), t)) ret |= ClearSides.TopRight; if (!CellContains(p + new CVec(-1, 1), t)) ret |= ClearSides.BottomLeft; if (!CellContains(p + new CVec(1, 1), t)) ret |= ClearSides.BottomRight; return ret; }
public void AddSmudge(CPos loc) { if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage) world.AddFrameEndTask(w => w.Add(new SpriteEffect(world.Map.CenterOfCell(loc), w, Info.SmokeType, Info.SmokeSequence, Info.SmokePalette))); // A null Sprite indicates a deleted smudge. if ((!dirty.ContainsKey(loc) || dirty[loc].Sprite == null) && !tiles.ContainsKey(loc)) { // No smudge; create a new one var st = smudges.Keys.Random(Game.CosmeticRandom); dirty[loc] = new Smudge { Type = st, Depth = 0, Sprite = smudges[st][0] }; } else { // Existing smudge; make it deeper // A null Sprite indicates a deleted smudge. var tile = dirty.ContainsKey(loc) && dirty[loc].Sprite != null ? dirty[loc] : tiles[loc]; var maxDepth = smudges[tile.Type].Length; if (tile.Depth < maxDepth - 1) { tile.Depth++; tile.Sprite = smudges[tile.Type][tile.Depth]; } dirty[loc] = tile; } }
public void AddSmudge(CPos loc) { if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage) world.AddFrameEndTask(w => w.Add(new Smoke(w, world.Map.CenterOfCell(loc), Info.SmokeType))); if (!dirty.ContainsKey(loc) && !tiles.ContainsKey(loc)) { // No smudge; create a new one var st = smudges.Keys.Random(world.SharedRandom); dirty[loc] = new Smudge { Type = st, Depth = 0, Sprite = smudges[st][0] }; } else { // Existing smudge; make it deeper var tile = dirty.ContainsKey(loc) ? dirty[loc] : tiles[loc]; var maxDepth = smudges[tile.Type].Length; if (tile.Depth < maxDepth - 1) { tile.Depth++; tile.Sprite = smudges[tile.Type][tile.Depth]; } dirty[loc] = tile; } }
public IonCannon(Actor firedBy, World world, CPos location) { this.firedBy = firedBy; target = Target.FromCell(location); anim = new Animation("ionsfx"); anim.PlayThen("idle", () => Finish(world)); }
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi) { world.CancelInputMode(); if (mi.Button == MouseButton.Left) yield return new Order("PlaceBeacon", world.LocalPlayer.PlayerActor, false) { TargetLocation = cell, SuppressVisualFeedback = true }; }
public override void Draw() { if (world == null) return; var o = new float2(mapRect.Location.X, mapRect.Location.Y + world.Map.Bounds.Height * previewScale * (1 - radarMinimapHeight)/2); var s = new float2(mapRect.Size.Width, mapRect.Size.Height*radarMinimapHeight); var rsr = Game.Renderer.RgbaSpriteRenderer; rsr.DrawSprite(terrainSprite, o, s); rsr.DrawSprite(customTerrainSprite, o, s); rsr.DrawSprite(actorSprite, o, s); rsr.DrawSprite(shroudSprite, o, s); // Draw viewport rect if (hasRadar && !animating) { var wr = Game.viewport.WorldRect; var wro = new CPos(wr.X, wr.Y); var tl = CellToMinimapPixel(wro); var br = CellToMinimapPixel(wro + new CVec(wr.Width, wr.Height)); Game.Renderer.EnableScissor((int)mapRect.Left, (int)mapRect.Top, (int)mapRect.Width, (int)mapRect.Height); Game.Renderer.LineRenderer.DrawRect(tl, br, Color.White); Game.Renderer.DisableScissor(); } }
void AddAdjacentWall(CPos location, CPos otherLocation) { if (otherLocation == location + new CVec(0, -1)) adjacentWalls |= 1; if (otherLocation == location + new CVec(+1, 0)) adjacentWalls |= 2; if (otherLocation == location + new CVec(0, +1)) adjacentWalls |= 4; if (otherLocation == location + new CVec(-1, 0)) adjacentWalls |= 8; }
// Used to check for neighbouring bridges public Bridge GetBridge(CPos cell) { if (!world.Map.IsInMap(cell)) return null; return Bridges[ cell.X, cell.Y ]; }
public Actor[] Reinforce(Player owner, string[] actorTypes, CPos[] entryPath, int interval = 25, LuaFunction actionFunc = null) { var actors = new List<Actor>(); for (var i = 0; i < actorTypes.Length; i++) { var af = actionFunc != null ? actionFunc.CopyReference() as LuaFunction : null; var actor = CreateActor(owner, actorTypes[i], false, entryPath[0], entryPath.Length > 1 ? entryPath[1] : (CPos?)null); actors.Add(actor); var actionDelay = i * interval; Action actorAction = () => { Context.World.Add(actor); for (var j = 1; j < entryPath.Length; j++) Move(actor, entryPath[j]); if (af != null) { actor.QueueActivity(new CallFunc(() => { af.Call(actor.ToLuaValue(Context)); af.Dispose(); })); } }; Context.World.AddFrameEndTask(w => w.Add(new DelayedAction(actionDelay, actorAction))); } return actors.ToArray(); }
public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "BeginMinefield") minefieldStart = order.TargetLocation; if (order.OrderString == "PlaceMine") { minefieldStart = order.TargetLocation; Minefield = new CPos[] { order.TargetLocation }; self.CancelActivity(); self.QueueActivity(new LayMines()); } if (order.OrderString == "PlaceMinefield") { var movement = self.Trait<IPositionable>(); Minefield = GetMinefieldCells(minefieldStart, order.TargetLocation, self.Info.Traits.Get<MinelayerInfo>().MinefieldDepth) .Where(p => movement.CanEnterCell(p)).ToArray(); self.CancelActivity(); self.QueueActivity(new LayMines()); } }
public Actor GetBuildingAt(CPos cell) { if (!map.IsInMap(cell)) return null; return influence[cell.X, cell.Y]; }
public static bool IsCellBuildable(this World world, CPos a, BuildingInfo bi, Actor toIgnore) { if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(a) != null) return false; if (world.ActorMap.GetUnitsAt(a).Any(b => b != toIgnore)) return false; return world.Map.IsInMap(a) && bi.TerrainTypes.Contains(world.GetTerrainType(a)); }
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { var occupied = OccupiesSpace ? new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } } : new Dictionary<CPos, SubCell>(); return new ReadOnlyDictionary<CPos, SubCell>(occupied); }
public override CellContents UpdateDirtyTile(CPos c) { var t = Tiles[c]; // Empty tile if (t.Type == null) { t.Sprite = null; return t; } NetWorth -= t.Density * t.Type.Info.ValuePerUnit; t.Density = ResourceDensityAt(c); NetWorth += t.Density * t.Type.Info.ValuePerUnit; int index; var clear = FindClearSides(t.Type, c); if (clear == ClearSides.None && CellContainsMaxDensity(c, t.Type)) { var maxDensityClear = FindMaxDensityClearSides(t.Type, c); if (D2ResourceLayer.SpriteMap.TryGetValue(maxDensityClear, out index)) t.Sprite = t.Type.Variants.First().Value[16 + index]; else t.Sprite = null; } else if (D2ResourceLayer.SpriteMap.TryGetValue(clear, out index)) t.Sprite = t.Type.Variants.First().Value[index]; else t.Sprite = null; return t; }
public void CoarseToMapProjection() { foreach (var gridType in Enum.GetValues(typeof(MapGridType)).Cast<MapGridType>()) { for (var x = 0; x < 12; x++) { for (var y = 0; y < 12; y++) { var cell = new CPos(x, y); try { Assert.That(cell, Is.EqualTo(cell.ToMPos(gridType).ToCPos(gridType))); } catch { // Known problem on isometric mods that shouldn't be visible to players as these are outside the map. if (gridType == MapGridType.RectangularIsometric && y > x) continue; Console.WriteLine("Coordinate {0} on grid type {1} failed to convert back.".F(cell, gridType)); throw; } } } } }
public void RequestTransport(CPos destination, Activity afterLandActivity) { var destPos = self.World.Map.CenterOfCell(destination); if (destination == CPos.Zero || (self.CenterPosition - destPos).LengthSquared < info.MinDistance.LengthSquared) { WantsTransport = false; // Be sure to cancel any pending transports return; } Destination = destination; this.afterLandActivity = afterLandActivity; WantsTransport = true; if (locked || Reserved) return; // Inform all idle carriers var carriers = self.World.ActorsWithTrait<Carryall>() .Where(c => !c.Trait.IsBusy && !c.Actor.IsDead && c.Actor.Owner == self.Owner && c.Actor.IsInWorld) .OrderBy(p => (self.Location - p.Actor.Location).LengthSquared); // Is any carrier able to transport the actor? // Any will return once it finds a carrier that returns true. carriers.Any(carrier => carrier.Trait.RequestTransportNotify(self)); }
// Used to check for neighbouring bridges public Bridge GetBridge(CPos cell) { if (!bridges.Contains(cell)) return null; return bridges[cell]; }
public CellInfo(int costSoFar, int estimatedTotal, CPos previousPos, CellStatus status) { CostSoFar = costSoFar; PreviousPos = previousPos; Status = status; EstimatedTotal = estimatedTotal; }
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi) { var underCursor = world.ScreenMap.ActorsAt(mi) .Where(a => !world.FogObscures(a) && a.HasTrait<ITargetable>()) .WithHighestSelectionPriority(); Target target; if (underCursor != null) target = Target.FromActor(underCursor); else { var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, mi) .Where(a => a.Info.Traits.Contains<ITargetableInfo>() && !a.Footprint.All(world.ShroudObscures)) .WithHighestSelectionPriority(); target = frozen != null ? Target.FromFrozenActor(frozen) : Target.FromCell(world, xy); } var orders = world.Selection.Actors .Select(a => OrderForUnit(a, target, mi)) .Where(o => o != null) .ToList(); var actorsInvolved = orders.Select(o => o.Actor).Distinct(); if (actorsInvolved.Any()) yield return new Order("CreateGroup", actorsInvolved.First().Owner.PlayerActor, false) { TargetString = actorsInvolved.Select(a => a.ActorID).JoinWith(",") }; foreach (var o in orders) yield return CheckSameOrder(o.Order, o.Trait.IssueOrder(o.Actor, o.Order, o.Target, mi.Modifiers.HasModifier(Modifiers.Shift))); }
public string GetCursor(World world, CPos xy, MouseInput mi) { mi.Button = MouseButton.Left; return(cursor + (OrderInner(world, mi).Any() ? "" : "-blocked")); }
public void SetLZ(CPos lz, bool checkLandingCell) { target = Target.FromCell(self.World, lz); checkForSuitableCell = checkLandingCell; }
public void Update(CPos cell, ISpriteSequence sequence, PaletteReference palette, int frame) { Update(cell, sequence.GetSprite(frame), palette, sequence.Scale, sequence.GetAlpha(frame), sequence.IgnoreWorldTint); }
public void Clear(CPos cell) { Update(cell, null, null, 1f, 1f, true); }
public bool CanEnterCell(CPos a, Actor ignoreActor = null, bool checkTransientActors = true) { return(GetAvailableSubCell(a, SubCell.Any, ignoreActor, checkTransientActors) != SubCell.Invalid); }
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any) { return(self.Location == location && ticks + 1 == info.Lifetime * 25); }
public bool AnyBuildingAt(CPos cell) { return(influence.Contains(cell) && influence[cell] != null); }
public static void NotifyBlocker(this Actor self, CPos position) { NotifyBlocker(self, self.World.ActorMap.GetActorsAt(position)); }
public SelectDestination(World world, string order, SupportPowerManager manager, ChronoshiftPower power, CPos sourceLocation) { this.manager = manager; this.order = order; this.power = power; this.sourceLocation = sourceLocation; var info = (ChronoshiftPowerInfo)power.Info; footprint = info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray(); dimensions = info.Dimensions; var sequences = world.Map.Rules.Sequences; var tilesetValid = info.ValidFootprintSequence + "-" + world.Map.Tileset.ToLowerInvariant(); if (sequences.HasSequence(info.FootprintImage, tilesetValid)) { var validSequence = sequences.GetSequence(info.FootprintImage, tilesetValid); validTile = validSequence.GetSprite(0); validAlpha = validSequence.GetAlpha(0); } else { var validSequence = sequences.GetSequence(info.FootprintImage, info.ValidFootprintSequence); validTile = validSequence.GetSprite(0); validAlpha = validSequence.GetAlpha(0); } var invalidSequence = sequences.GetSequence(info.FootprintImage, info.InvalidFootprintSequence); invalidTile = invalidSequence.GetSprite(0); invalidAlpha = invalidSequence.GetAlpha(0); var sourceSequence = sequences.GetSequence(info.FootprintImage, info.SourceFootprintSequence); sourceTile = sourceSequence.GetSprite(0); sourceAlpha = sourceSequence.GetAlpha(0); }
public static WPos BetweenCells(CPos from, CPos to) { return(WPos.Lerp(from.CenterPosition, to.CenterPosition, 1, 2)); }
public FindAndDeliverResources(Actor self, CPos orderLocation) : this(self, null) { this.orderLocation = orderLocation; }
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { var powerInfo = (ChronoshiftPowerInfo)power.Info; return(IsValidTarget(cell) ? powerInfo.TargetCursor : powerInfo.TargetBlockedCursor); }
public SelectDestination(World world, string order, SupportPowerManager manager, ChronoshiftPower power, CPos sourceLocation) { this.manager = manager; this.order = order; this.power = power; this.sourceLocation = sourceLocation; this.range = ((ChronoshiftPowerInfo)power.Info).Range; var tileset = manager.Self.World.TileSet.Id.ToLowerInvariant(); validTile = world.Map.SequenceProvider.GetSequence("overlay", "target-valid-{0}".F(tileset)).GetSprite(0); invalidTile = world.Map.SequenceProvider.GetSequence("overlay", "target-invalid").GetSprite(0); sourceTile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0); }
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return(((ChronoshiftPowerInfo)power.Info).SelectionCursor); }
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return(IsValidTarget(world, cell) ? cursor : cursorBlocked); }
public string GetCursor(World world, CPos xy, MouseInput mi) { return(IsValidTarget(xy) ? "chrono-target" : "move-blocked"); }
/* Adds spice fields to the map. */ void AddSpice(uint minSpiceFields, uint maxSpiceFields) { const uint maxCount = 65535; var count = 0; var i = 0L; /* ENHANCEMENT: spice field controls. */ if ((minSpiceFields == 0) && (maxSpiceFields == 0)) { i = seed.Random() & 0x2F; } else { var a = Math.Min(minSpiceFields, 255); var b = Math.Min(maxSpiceFields, 255); minSpiceFields = Math.Min(a, b); maxSpiceFields = Math.Max(a, b); var range = (maxSpiceFields - minSpiceFields + 1); i = (int)(seed.Random()) * range / 256 + minSpiceFields; } while (i-- != 0) { ushort y = 0; ushort x = 0; while (true) { y = (ushort)(seed.Random() & 0x3F); x = (ushort)(seed.Random() & 0x3F); var tile = m[PackXY(x, y)]; if (CanBecomeSpice(tile)) { break; } /* ENHANCEMENT: ensure termination. */ count++; if (count > maxCount) { return; } } var x1 = ((x & 0x3F) << 8) | 0x80; var y1 = ((y & 0x3F) << 8) | 0x80; var j = (ushort)seed.Random() & 0x1F; while (j-- != 0) { CPos coord; while (true) { var dist = seed.Random() & 0x3F; var pos = MoveByRandom(new TilePos(x1, y1), dist); var x2 = (pos.X >> 8) & 0x3F; var y2 = (pos.Y >> 8) & 0x3F; coord = new CPos(x2, y2); if (!IsOutOfMap(coord)) { break; } } var tile = m[PackXY((ushort)coord.X, (ushort)coord.Y)]; if (map.Resources[coord].Type == 1) { CreateSpiceField(coord, 2, true); } else { CreateSpiceField(coord, 1, true); } } } }
public string GetCursor(World world, CPos xy, MouseInput mi) { return("chrono-select"); }
/// <summary> /// Returns the most appropriate order for a given actor and target. /// First priority is given to orders that interact with the given actors. /// Second priority is given to actors in the given cell. /// </summary> static UnitOrderResult OrderForUnit(Actor self, Target target, List <Actor> actorsAt, CPos xy, MouseInput mi) { if (mi.Button != Game.Settings.Game.MouseButtonPreference.Action) { return(null); } if (self.Owner != self.World.LocalPlayer) { return(null); } if (self.World.IsGameOver) { return(null); } if (self.Disposed || !target.IsValidFor(self)) { return(null); } var modifiers = TargetModifiers.None; if (mi.Modifiers.HasModifier(Modifiers.Ctrl)) { modifiers |= TargetModifiers.ForceAttack; } if (mi.Modifiers.HasModifier(Modifiers.Shift)) { modifiers |= TargetModifiers.ForceQueue; } if (mi.Modifiers.HasModifier(Modifiers.Alt)) { modifiers |= TargetModifiers.ForceMove; } // The Select(x => x) is required to work around an issue on mono 5.0 // where calling OrderBy* on SelectManySingleSelectorIterator can in some // circumstances (which we were unable to identify) replace entries in the // enumeration with duplicates of other entries. // Other action that replace the SelectManySingleSelectorIterator with a // different enumerator type (e.g. .Where(true) or .ToList()) also work. var orders = self.TraitsImplementing <IIssueOrder>() .SelectMany(trait => trait.Orders.Select(x => new { Trait = trait, Order = x })) .Select(x => x) .OrderByDescending(x => x.Order.OrderPriority); for (var i = 0; i < 2; i++) { foreach (var o in orders) { var localModifiers = modifiers; string cursor = null; if (o.Order.CanTarget(self, target, actorsAt, ref localModifiers, ref cursor)) { return(new UnitOrderResult(self, o.Order, o.Trait, cursor, target)); } } // No valid orders, so check for orders against the cell target = Target.FromCell(self.World, xy); } return(null); }
public GraphConnection(CPos destination, int cost) { Destination = destination; Cost = cost; }
bool IsRallyPointValid(CPos x, BuildingInfo info) { return(info != null && world.IsCellBuildable(x, null, info)); }
bool IsOutOfMap(CPos pos) { return(pos.X < 0 || pos.X >= map.MapSize.X || pos.Y < 0 || pos.Y >= map.MapSize.Y); }
void IBotPositionsUpdated.UpdatedBaseCenter(CPos newLocation) { initialBaseCenter = newLocation; }
public virtual void DoAction(Actor self, CPos targetCell) { throw new NotImplementedException("Base class Wanders does not implement method DoAction!"); }
public ResourceType GetResourceType(CPos cell) { return(Content[cell].Type); }
void IBotPositionsUpdated.UpdatedDefenseCenter(CPos newLocation) { defenseCenter = newLocation; }
public bool IsFull(CPos cell) { var cellContents = Content[cell]; return(cellContents.Density == cellContents.Type.Info.MaxDensity); }
public int GetResourceDensity(CPos cell) { return(Content[cell].Density); }
public string GetCursor(World world, CPos xy, MouseInput mi) { return(world.Map.IsInMap(xy) ? cursor : "generic-blocked"); }
public CellContents GetResource(CPos cell) { return(Content[cell]); }