public GameUnitMove getData(GameUnitMoveType id) { if (id == GameUnitMoveType.Invalid) { return(data[(int)GameUnitMoveType.None]); } return(data[(int)id]); }
public void show(int x, int y, int move, GameUnitMoveType moveType, bool fly, GameUnitCampType camp, bool fade) { gameObject.SetActive(true); clear(); isShow = true; openList.Clear(); closeList.Clear(); Cell cell = new Cell(); cell.x = x; cell.y = y; cell.f = 0; openList.Add(cell); findCell(move, moveType, fly, camp); fadeCell(fade); }
void findCell(int move, GameUnitMoveType moveType, bool fly, GameUnitCampType camp) { GameUnitMove unitMove = GameUnitMoveTypeData.instance.getData(moveType); bool user = (camp == GameUnitCampType.User); GameBattleDTL dtl = GameBattleManager.instance.ActiveDTL; closeList.Add(openList[0]); while (openList.Count > 0) { List <Cell> newOpenList = new List <Cell>(); for (int i = 0; i < openList.Count; i++) { Cell cell = openList[i]; GameBattleDTL.Point point = null; // right int index = dtl.Width * cell.y + cell.x + 1; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x + 1, cell.y, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x + 1, cell.y, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x + 1; newCell.y = cell.y; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } // left index = dtl.Width * cell.y + cell.x - 1; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x - 1, cell.y, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x - 1, cell.y, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x - 1; newCell.y = cell.y; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } // top index = dtl.Width * (cell.y - 1) + cell.x; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x, cell.y - 1, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x, cell.y - 1, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x; newCell.y = cell.y - 1; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } // bottom index = dtl.Width * (cell.y + 1) + cell.x; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x, cell.y + 1, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x, cell.y + 1, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x; newCell.y = cell.y + 1; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } } openList.Clear(); openList = null; openList = newOpenList; } for (int i = 1; i < closeList.Count;) { if (isUnit(closeList[i].x, closeList[i].y)) { closeList.RemoveAt(i); } else { i++; } } for (int i = 0; i < closeList.Count; i++) { addCell(closeList[i], user); } }