void invoke() { if (WaitForTurn.WaitOne(10)) { List <Position> newUpdatedPositions = new List <Position>(); foreach (Position pos in MapInfo.Pheromones.Keys) { MapPheromone mapPheromone = MapInfo.Pheromones[pos]; HexCell hexCell = GroundCells[pos]; hexCell.Update(mapPheromone); newUpdatedPositions.Add(pos); updatedPositions.Remove(pos); } foreach (Position pos in updatedPositions) { HexCell hexCell = GroundCells[pos]; hexCell.Update(null); } updatedPositions = newUpdatedPositions; // foreach (MapPlayerInfo mapPlayerInfo in MapInfo.PlayerInfo.Values) { } foreach (UnitFrame unitFrame in Units.Values) { //if (unitFrame.FinalDestination != null) { unitFrame.JumpToTarget(unitFrame.FinalDestination); //unitFrame.FinalDestination = null; } unitFrame.NextMove = null; } foreach (Move move in newMoves) { if (move.MoveType == MoveType.Add) { if (Units.ContainsKey(move.UnitId)) { // Happend in player view } else { CreateUnit(move); } } else if (move.MoveType == MoveType.UpdateStats) { if (Units.ContainsKey(move.UnitId)) { UnitFrame unit = Units[move.UnitId]; unit.UpdateStats(move.Stats); } else { // Happend in player view } } else if (move.MoveType == MoveType.Move || move.MoveType == MoveType.Extract || move.MoveType == MoveType.Fire) { UnitFrame unit = Units[move.UnitId]; unit.NextMove = move; } else if (move.MoveType == MoveType.Hit) { UnitFrame unit = Units[move.UnitId]; unit.NextMove = move; } else if (move.MoveType == MoveType.Upgrade) { UnitFrame unit = Units[move.OtherUnitId]; unit.NextMove = move; } else if (move.MoveType == MoveType.UpdateGround) { HexCell hexCell = GroundCells[move.Positions[0]]; hexCell.NextMove = move; hexCell.UpdateGround(); } else if (move.MoveType == MoveType.Delete) { Debug.Log("Delete Unit " + move.UnitId); UnitFrame unit = Units[move.UnitId]; unit.NextMove = null; unit.Delete(); Units.Remove(move.UnitId); } } newMoves.Clear(); WaitForDraw.Set(); } }
public void Update() { if (!useThread) { lastDeltaTime += Time.deltaTime; if (lastDeltaTime > 1) { lastDeltaTime = 0; Move nextMove = new Move(); nextMove.MoveType = MoveType.None; List <Move> newMoves = game.ProcessMove(0, nextMove); foreach (Move move in newMoves) { if (move.MoveType == MoveType.Add) { CreateUnit(move); } else if (move.MoveType == MoveType.UpdateStats) { UnitFrame unit = Units[move.UnitId]; unit.UpdateStats(move.Stats); } else if (move.MoveType == MoveType.Move || move.MoveType == MoveType.Extract || move.MoveType == MoveType.Fire) { UnitFrame unit = Units[move.UnitId]; unit.NextMove = move; } else if (move.MoveType == MoveType.Hit) { UnitFrame unit = Units[move.UnitId]; unit.NextMove = move; } else if (move.MoveType == MoveType.Upgrade) { UnitFrame unit = Units[move.OtherUnitId]; unit.NextMove = move; } else if (move.MoveType == MoveType.UpdateGround) { HexCell hexCell = GroundCells[move.Positions[0]]; hexCell.NextMove = move; hexCell.UpdateGround(); } else if (move.MoveType == MoveType.Delete) { Debug.Log("Delete Unit " + move.UnitId); UnitFrame unit = Units[move.UnitId]; unit.NextMove = null; unit.Delete(); Units.Remove(move.UnitId); } } } } }