private bool ValidateMoveArrow() { Game_Unit selected_unit = get_selected_unit(); if (Move_Arrow.Any() && selected_unit != null) { int moveCost = 0; for (int i = 1; i < Move_Arrow.Count; i++) { Move_Arrow_Data loc = Move_Arrow[i]; moveCost += selected_unit.move_cost(new Vector2(loc.X, loc.Y)); } // If the arrow has exceeded the move score if (moveCost > selected_unit.canto_mov) { Move_Arrow.Clear(); Selected_Move_Total = 0; return(false); } else { Selected_Move_Total = moveCost; } } return(true); }
public void update_move_arrow() { if (Global.game_temp.menu_call || Global.game_state.is_menuing || (get_scene_map() != null && ((Scene_Map)Global.scene).changing_formation)) { return; } if (Global.game_system.Selected_Unit_Id == -1) { Move_Arrow.Clear(); } else { Game_Unit selected_unit = get_selected_unit(); int range = selected_unit.canto_mov; // If the cursor is in the move range if (Move_Range.Contains(Global.player.loc)) { if (Global.player.loc == selected_unit.loc) { Move_Arrow.Clear(); } else { int x = (int)Global.player.loc.X; int y = (int)Global.player.loc.Y; // Test if the cursor location already exists in the move arrow if (Move_Arrow.Count > 0) { // Test if the cursor is already at the endpoint if (x == Move_Arrow[Move_Arrow.Count - 1].X && y == Move_Arrow[Move_Arrow.Count - 1].Y) { return; } // Test if the cursor is somewhere else on the list bool already_on_list = false; int i; for (i = 0; i < Move_Arrow.Count - 1; i++) { if (Move_Arrow[i].X == x && Move_Arrow[i].Y == y) { already_on_list = true; break; } } if (already_on_list) { int j = Move_Arrow.Count - 1; while (j >= i) { Move_Arrow_Data loc = Move_Arrow[j]; Selected_Move_Total -= selected_unit.move_cost(new Vector2(loc.X, loc.Y)); if (Move_Arrow.Count >= 3) { Move_Arrow[Move_Arrow.Count - 2].Frame = unfix_arrow_turn(Move_Arrow[Move_Arrow.Count - 1].Frame, Move_Arrow[Move_Arrow.Count - 2].Frame); } Move_Arrow.pop(); j--; } } } bool adjacent = Move_Arrow.Count == 1; if (Move_Arrow.Count > 1) { Vector2 test_loc = new Vector2( Move_Arrow[Move_Arrow.Count - 1].X, Move_Arrow[Move_Arrow.Count - 1].Y); foreach (int[] test in new int[][] { new int[] { -1, 0 }, new int[] { 1, 0 }, new int[] { 0, -1 }, new int[] { 0, 1 } }) { if (test[0] + x == test_loc.X && test[1] + y == test_loc.Y) { adjacent = true; break; } } } if (!adjacent) { } Selected_Move_Total += selected_unit.move_cost(Global.player.loc); if (Selected_Move_Total > range || !adjacent) { reset_move_arrow(Global.player.loc, range); } else { Vector2 dir = new Vector2(x, y) - new Vector2( Move_Arrow[Move_Arrow.Count - 1].X, Move_Arrow[Move_Arrow.Count - 1].Y); Move_Arrow.Add(new Move_Arrow_Data(x, y, move_arrow_facing(dir))); Move_Arrow[Move_Arrow.Count - 2].Frame = fix_arrow_turn(Move_Arrow[Move_Arrow.Count - 1].Frame, Move_Arrow[Move_Arrow.Count - 2].Frame); } } } } }