File: paths.h

package info (click to toggle)
exult 1.12.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 43,608 kB
  • sloc: cpp: 169,917; xml: 7,400; yacc: 2,850; makefile: 2,419; java: 1,901; ansic: 1,654; lex: 673; sh: 539; objc: 416
file content (179 lines) | stat: -rw-r--r-- 6,272 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 *  Paths.h - Various pathfinding clients.
 *
 *  Copyright (C) 2000-2022  The Exult Team
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef PATHS_H
#define PATHS_H 1

#include "PathFinder.h"
#include "chunks.h"
#include "rect.h"
#include "tiles.h"

class Actor;
class Game_object;
class Game_window;

/*
 *  This class provides A* cost methods.
 */
class Actor_pathfinder_client : public Pathfinder_client {
	int    dist;           // Distance for success.
	Actor* npc;            // Who this represents.
	bool   ignore_npcs;    // If NPCs are nonblocking.
	int    check_blocking(const Tile_coord& from, const Tile_coord& to) const;

public:
	//	Actor_pathfinder_client(Actor *npc, int d = 0) : dist(d)
	//		{ set_move_flags(mf); }
	Actor_pathfinder_client(Actor* npc, int d = 0, bool ign = false);
	// Figure when to give up.
	int get_max_cost(int cost_to_goal) const override;
	// Figure cost for a single step.
	int get_step_cost(const Tile_coord& frm, Tile_coord& to) const override;
	// Estimate cost between two points.
	int estimate_cost(
			const Tile_coord& from, const Tile_coord& to) const override;
	// Is tile at the goal?
	bool at_goal(const Tile_coord& tile, const Tile_coord& goal) const override;

	bool ignores_npcs() const {
		return ignore_npcs;
	}
};

/*
 *  This client succeeds when the path makes it to just one X/Y coord.
 *  It assumes that a -1 was placed in the coord. that we should ignore.
 */
class Onecoord_pathfinder_client : public Actor_pathfinder_client {
public:
	Onecoord_pathfinder_client(Actor* n, bool ign = false)
			: Actor_pathfinder_client(n, 0, ign) {}

	// Estimate cost between two points.
	int estimate_cost(
			const Tile_coord& from, const Tile_coord& to) const override;
	// Is tile at the goal?
	bool at_goal(const Tile_coord& tile, const Tile_coord& goal) const override;
};

/*
 *  This client succeeds when the path makes it offscreen.
 *  Only the tz coord. of the dest. is used.
 */
class Offscreen_pathfinder_client : public Actor_pathfinder_client {
	TileRect   screen;    // Screen rect. in tiles.
	Tile_coord best;      // Best offscreen pt. to aim for.
public:
	Offscreen_pathfinder_client(Actor* n, bool ign = false);
	Offscreen_pathfinder_client(
			Actor* n, const Tile_coord& b, bool ign = false);
	// Figure cost for a single step.
	int get_step_cost(const Tile_coord& from, Tile_coord& to) const override;
	// Estimate cost between two points.
	int estimate_cost(
			const Tile_coord& from, const Tile_coord& to) const override;
	// Is tile at the goal?
	bool at_goal(const Tile_coord& tile, const Tile_coord& goal) const override;
};

/*
 *  This class provides A* cost methods for going to an object.
 */
class Approach_object_pathfinder_client : public Actor_pathfinder_client {
	TileRect destbox;    // Got to intersect this box.
public:
	Approach_object_pathfinder_client(
			Actor* from, const Tile_coord& dest, int dist);
	Approach_object_pathfinder_client(Actor* from, Game_object* to, int dist);
	// Is tile at the goal?
	bool at_goal(const Tile_coord& tile, const Tile_coord& goal) const override;
};

/*
 *  This client is supposed to fail quickly, so that it can be used to
 *  test for when an object can be grabbed.
 */
class Fast_pathfinder_client : public Pathfinder_client {
	TileRect    destbox;                      // Got to intersect this box.
	int         axtiles, aytiles, aztiles;    // NPC's dims. in tiles.
	void        init(Game_object* from, Game_object* to, int dist);
	static bool is_grabable_internal(
			Game_object* from, const Tile_coord& ct, const Tile_coord& dt,
			const Block& tovol, Fast_pathfinder_client& client);

public:
	Fast_pathfinder_client(
			Game_object* from, const Tile_coord& dest, int dist,
			int mf = 1 << 5);
	Fast_pathfinder_client(
			Game_object* from, Game_object* to, int dist, int mf = 1 << 5);
	Fast_pathfinder_client(Actor* from, const Tile_coord& dest, int dist);
	Fast_pathfinder_client(Actor* from, Game_object* to, int dist);
	// Figure when to give up.
	int get_max_cost(int cost_to_goal) const override;
	// Figure cost for a single step.
	int get_step_cost(const Tile_coord& from, Tile_coord& to) const override;
	// Estimate cost between two points.
	int estimate_cost(
			const Tile_coord& from, const Tile_coord& to) const override;
	// Is tile at the goal?
	bool at_goal(const Tile_coord& tile, const Tile_coord& goal) const override;

	int get_axtiles() const {
		return axtiles;
	}

	int get_aytiles() const {
		return aytiles;
	}

	int get_aztiles() const {
		return aztiles;
	}

	static bool is_grabable(
			Game_object* from, Game_object* to, int mf = 1 << 5);
	static bool is_grabable(
			Game_object* from, const Tile_coord& to, int mf = 1 << 5);
	static bool is_grabable(Actor* from, Game_object* to);
	static bool is_grabable(Actor* from, const Tile_coord& to);
	// Check for unblocked straight path.
	static bool is_straight_path(const Tile_coord& from, const Tile_coord& to);
	static bool is_straight_path(Game_object* from, Game_object* to);
};

/*
 *  Pathfinding for monsters, who may be bigger than 1x1:
 */
class Monster_pathfinder_client : public Fast_pathfinder_client {
	int intelligence;    // NPC's intelligence.
public:
	Monster_pathfinder_client(Actor* npc, const Tile_coord& dest, int dist);
	// For combat:
	Monster_pathfinder_client(
			Actor* attacker, int reach, Game_object* opponent);
	// Figure when to give up.
	int get_max_cost(int cost_to_goal) const override;
	// Figure cost for a single step.
	int get_step_cost(const Tile_coord& from, Tile_coord& to) const override;
};

#endif /* INCL_PATHS */