Logic.UnitAction IPlayerAI.SelectAction(Logic.API.Info.UnitInfo unitInfo) { Array values = Enum.GetValues(typeof(Direction)); Direction direction = (Direction)values.GetValue(Random.Next(Enum.GetValues(typeof(Direction)).Length)); UnitAction action = null; double choice = Random.NextDouble() * 100; if (choice < 30) action = new ShootAction() { Direction = direction }; else if (choice < 60) action = new ScanAction() { Direction = direction }; else action = new MoveAction() { Direction = direction }; return action; }
public void Scan(Unit unit, ScanAction action) { ScanInfo scanInfo = new ScanInfo(); if (action.Direction == API.Direction.Down || action.Direction == API.Direction.Up) { int del; if (action.Direction == API.Direction.Down) del = -1; else del = 1; for (int x=-1;x<1;x++) { int ax = unit.X + x; int ay = unit.Y + del; if (ax < 0 || ax >= Data.Map.MapWidth) return; if (ay < 0 || ay >= Data.Map.MapLength) return; Tile tile = Data.Map.Tiles[ay][ax]; if (tile != null) scanInfo.Tiles.Add(tile.GetInfo()); } } if (action.Direction == API.Direction.Left || action.Direction == API.Direction.Right) { int del; if (action.Direction == API.Direction.Left) del = -1; else del = 1; for (int y = -1; y < 1; y++) { int ax = unit.X + del; int ay = unit.Y + y; if (ax < 0 || ax >= Data.Map.MapWidth) return; if (ay < 0 || ay >= Data.Map.MapLength) return; Tile tile = Data.Map.Tiles[ay][ax]; if (tile != null) scanInfo.Tiles.Add(tile.GetInfo()); } } unit.Player.AI.ReceiveScanInfo(scanInfo); }