1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "ultima/nuvie/core/nuvie_defs.h"
24 #include "ultima/nuvie/core/game.h"
25 #include "ultima/nuvie/core/obj_manager.h"
26 #include "ultima/nuvie/usecode/usecode.h"
27 #include "ultima/nuvie/pathfinder/u6_astar_path.h"
28
29 namespace Ultima {
30 namespace Nuvie {
31
32 /* Return the cost of moving one step from `c1' to `c2'.
33 * Blocking objects are checked for, and doors may be passable
34 * Returns -1 if c2 is blocked.
35 */
step_cost(MapCoord & c1,MapCoord & c2)36 sint32 U6AStarPath::step_cost(MapCoord &c1, MapCoord &c2) {
37 Game *game = Game::get_game();
38 sint32 c = 1; // final cost is not necessarily the actual move cost
39
40 // FIXME: need an actor->check_move(loc2, loc1) to check one step only
41 if (c2.distance(c1) > 1)
42 return (-1);
43 if (!pf->check_loc(c2.x, c2.y, c2.z)) {
44 // check for door
45 Obj *block = game->get_obj_manager()->get_obj(c2.x, c2.y, c2.z);
46 // HACK: check the neighboring tiles for the "real" door
47 Obj *real = game->get_obj_manager()->get_obj(c2.x + 1, c2.y, c2.z);
48 if (!real || !game->get_usecode()->is_unlocked_door(real))
49 real = game->get_obj_manager()->get_obj(c2.x, c2.y + 1, c2.z);
50 if (!block || !game->get_usecode()->is_unlocked_door(block) || real)
51 return (-1);
52 c += 2;
53 }
54 // add cost of *original* step
55 // c += game->get_game_map()->get_impedance(c1.x, c1.y, c1.z);
56
57 if (c1.x != c2.x && c1.y != c2.y) // prefer non-diagonal
58 c *= 2;
59 return (c);
60 }
61
62 // Possible step cost is 1 to 16.
path_cost_est(MapCoord & s,MapCoord & g)63 uint32 U6AStarPath::path_cost_est(MapCoord &s, MapCoord &g) {
64 return (Path::path_cost_est(s, g));
65 }
66
67 } // End of namespace Nuvie
68 } // End of namespace Ultima
69