public void GetNearByFoes(CombatSimulationActor actor, List <CombatSimulationActor> scratchList) { scratchList.Clear(); CombatSimulationActor foe; // North foe = GetActorAt(actor.X, actor.Y - 1); if (foe != null && foe.IsAlive && foe.Faction != actor.Faction) { scratchList.Add(foe); } // West foe = GetActorAt(actor.X - 1, actor.Y); if (foe != null && foe.IsAlive && foe.Faction != actor.Faction) { scratchList.Add(foe); } // East foe = GetActorAt(actor.X + 1, actor.Y); if (foe != null && foe.IsAlive && foe.Faction != actor.Faction) { scratchList.Add(foe); } // South foe = GetActorAt(actor.X, actor.Y + 1); if (foe != null && foe.IsAlive && foe.Faction != actor.Faction) { scratchList.Add(foe); } }
private CombatSimulationActor TryParseCombatActor(char tile, int x, int y) { CombatSimulationActor res = null; if (!IsKnownFaction(tile)) { return(res); } int num = 0; List <CombatSimulationActor> team; if (this._factions.TryGetValue(tile, out team)) { num = team.Count; } num++; int pow = GoblinAttackPower; if (tile == 'E') { pow = ElfAttackPower; } res = new CombatSimulationActor(this, tile, num, StartingHealth, pow, x, y); return(res); }
public CombatSimulation(string[] lines, int attackPower = -1) { int x = 0; int y = 0; if (attackPower > 0) { ElfAttackPower = attackPower; } List <CombatSimulationTile> tiles = new List <CombatSimulationTile>(); foreach (var line in lines) { x = 0; foreach (var character in line) { CombatSimulationActor actor = TryParseCombatActor(character, x, y); CombatSimulationTile tile; if (actor != null) { _allActors.Add(actor); List <CombatSimulationActor> myTeam; if (!_factions.TryGetValue(actor.Faction, out myTeam)) { myTeam = new List <CombatSimulationActor>(); _factions[actor.Faction] = myTeam; } myTeam.Add(actor); tile = ParseTile(EmptyTile, x, y); } else { tile = ParseTile(character, x, y); } tiles.Add(tile); x++; } _maxX = x; y++; } _maxY = y; _allTiles = new CombatSimulationTile[tiles.Count]; foreach (var tile in tiles) { tile.TileIndex = GetTileIndex(tile.X, tile.Y); _allTiles[tile.TileIndex] = tile; } _unitPositions = new CombatSimulationActor[_allTiles.Length]; foreach (var actor in _allActors) { actor.TileIndex = GetTileIndex(actor.X, actor.Y); _unitPositions[actor.TileIndex] = actor; } }
public void MoveActorToTile(CombatSimulationActor actor, CombatSimulationTile tile) { _unitPositions[actor.TileIndex] = null; actor.X = tile.X; actor.Y = tile.Y; actor.TileIndex = tile.TileIndex; _unitPositions[actor.TileIndex] = actor; }
private void AttackFoe(CombatSimulationActor foe) { foe.RemainingHealth -= this.AttackPower; Log("attacked " + foe.Id + " for " + this.AttackPower + " damage - remaining HP is " + foe.RemainingHealth); if (!foe.IsAlive) { Log(foe.Id + " died!"); } }
private int CompareActorsByLocation(CombatSimulationActor a, CombatSimulationActor b) { int rowCompare = a.Y.CompareTo(b.Y); if (rowCompare != 0) { return(rowCompare); } return(a.X.CompareTo(b.X)); }
private int CompareFoesByHealth(CombatSimulationActor a, CombatSimulationActor b) { int hpComp = a.RemainingHealth.CompareTo(b.RemainingHealth); if (hpComp != 0) { return(hpComp); } return(a.TileIndex.CompareTo(b.TileIndex)); }
public void GetAllFoes(CombatSimulationActor actor, List <CombatSimulationActor> scratchList) { scratchList.Clear(); foreach (var kvp in this._factions) { if (kvp.Key != actor.Faction) { foreach (var foe in kvp.Value) { if (foe.IsAlive) { scratchList.Add(foe); } } } } }
public void GetUnoccupiedTilesNearTile(CombatSimulationTile subject, List <CombatSimulationTile> scratchTiles) { scratchTiles.Clear(); // North CombatSimulationActor foe = GetActorAt(subject.X, subject.Y - 1); if (foe == null || !foe.IsAlive) { var tile = this.GetTileAt(subject.X, subject.Y - 1); if (!tile.IsObstruction) { scratchTiles.Add(tile); } } // West foe = GetActorAt(subject.X - 1, subject.Y); if (foe == null || !foe.IsAlive) { var tile = this.GetTileAt(subject.X - 1, subject.Y); if (!tile.IsObstruction) { scratchTiles.Add(tile); } } // East foe = GetActorAt(subject.X + 1, subject.Y); if (foe == null || !foe.IsAlive) { var tile = this.GetTileAt(subject.X + 1, subject.Y); if (!tile.IsObstruction) { scratchTiles.Add(tile); } } // South foe = GetActorAt(subject.X, subject.Y + 1); if (foe == null || !foe.IsAlive) { var tile = this.GetTileAt(subject.X, subject.Y + 1); if (!tile.IsObstruction) { scratchTiles.Add(tile); } } }
public static bool RequestPath(CombatSimulationActor actor, CombatSimulationTile targetTile, List <CombatSimulationTile> bestPath) { var startTile = actor.Tile; var sim = actor.Sim; _startCandidates.Clear(); sim.GetUnoccupiedTilesNearTile(startTile, _startCandidates); Int32 bestPathLength = Int32.MaxValue; bool hasPath = false; int indx = 0; foreach (var candidate in _startCandidates) { indx++; if (RequestPathFromTile(sim, candidate, targetTile, _startPathCopy)) { if (actor.IsDebug) { sim.RenderPath(_startPathCopy); actor.Log("Candidate had a valid path of length " + _startPathCopy.Count + " that started on tile " + candidate.X + "," + candidate.Y + " and ended on " + targetTile.X + "," + targetTile.Y + " actor was on " + startTile.X + "," + startTile.Y); } if (_startPathCopy.Count < bestPathLength) { bestPath.Clear(); bestPath.Add(candidate); bestPath.AddRange(_startPathCopy); bestPathLength = _startPathCopy.Count; hasPath = true; } } } return(hasPath); }
public void GetUnoccupiedTilesNearActor(CombatSimulationActor actor, List <CombatSimulationTile> scratchTiles) { GetUnoccupiedTilesNearTile(actor.Tile, scratchTiles); }