ScummVM API documentation
actor_manager.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef NUVIE_ACTORS_ACTOR_MANAGER_H
23#define NUVIE_ACTORS_ACTOR_MANAGER_H
24
25#include "common/str.h"
26#include "ultima/nuvie/core/obj_manager.h"
27#include "ultima/nuvie/misc/actor_list.h"
28#include "ultima/nuvie/actors/actor.h"
29
30namespace Ultima {
31namespace Nuvie {
32
33class Configuration;
34class Map;
35class TileManager;
36class GameClock;
37class MapCoord;
38
39
40#define ACTORMANAGER_MAX_ACTORS 256
41
43 const Configuration *config;
44 TileManager *tile_manager;
45 ObjManager *obj_manager;
46
47 bool update; // ActorManager is not paused
48 bool wait_for_player; // Player's turn; wait until updateActors() is called
49 bool combat_movement; // Defines actor movement type (individual/party)
50 bool should_clean_temp_actors; // If set, temp actors are cleaned when > 19 tiles from player.
51
52 Map *map;
53 Actor *actors[ACTORMANAGER_MAX_ACTORS];
54 uint8 player_actor;
55 uint8 temp_actor_offset;
56 GameClock *_clock;
57
58 uint16 last_obj_blk_x, last_obj_blk_y;
59 uint8 last_obj_blk_z;
60 uint16 cur_x, cur_y;
61 uint8 cur_z;
62 MapCoord *cmp_actor_loc; // data for sort_distance() & cmp_distance_to_loc()
63
64public:
65
66 ActorManager(const Configuration *cfg, Map *m, TileManager *tm, ObjManager *om, GameClock *c);
68
69 void init();
70 void clean();
71
72 bool load(NuvieIO *objlist);
73 bool save(NuvieIO *objlist);
74// ActorList
75 ActorList *get_actor_list(); // *returns a NEW list*
76 ActorList *sort_nearest(ActorList *list, uint16 x, uint16 y, uint8 z); // ascending distance
77 ActorList *filter_distance(ActorList *list, uint16 x, uint16 y, uint8 z, uint16 dist);
78 ActorList *filter_alignment(ActorList *list, ActorAlignment align);
79 ActorList *filter_party(ActorList *list);
80
81 Actor *get_actor(uint8 actor_num) const;
82 Actor *get_actor(uint16 x, uint16 y, uint8 z, bool inc_surrounding_objs = true, Actor *excluded_actor = nullptr);
83 Actor *get_actor_holding_obj(Obj *obj);
84
85 private:
86 Actor *findActorAtImpl(uint16 x, uint16 y, uint8 z, bool(*predicateWrapper)(void *, const Actor *), bool incDoubleTile, bool incSurroundingObjs, void *predicate) const;
87
88 public:
99 template<typename F>
100 Actor *findActorAt(uint16 x, uint16 y, uint8 z, F predicate, bool incDoubleTile = true, bool incSurroundingObjs = true) {
101 // This is a template so it can take lambdas.
102 // To keep the implementation out of the header, the type of the passed lambda/function
103 // is hidden inside a wrapping lambda, which is then passed as a function pointer.
104 // TODO: Use a class for this.
105 auto predicateWrapper = +[](void *wrappedPredicate, const Actor *a) -> bool {
106 return (*(F*)wrappedPredicate)(a);
107 };
108 return findActorAtImpl(x, y, z, predicateWrapper, incDoubleTile, incSurroundingObjs, &predicate);
109 }
110
111 Actor *get_avatar();
112
113 Actor *get_player();
114 void set_player(Actor *a);
115
116 const char *look_actor(const Actor *a, bool show_prefix = true);
117
118 void set_update(bool u) {
119 update = u;
120 }
121 bool get_update() const {
122 return update;
123 }
124 void set_combat_movement(bool c);
125
126 void updateActors(uint16 x, uint16 y, uint8 z);
127 void twitchActors();
128 void moveActors();
129 void startActors();
130 void updateSchedules(bool teleport = false);
131
132 void clear_actor(Actor *actor);
133 bool resurrect_actor(Obj *actor_obj, MapCoord new_position);
134
135 bool is_temp_actor(Actor *actor);
136 bool is_temp_actor(uint8 id_n);
137 bool create_temp_actor(uint16 obj_n, uint8 obj_status, uint16 x, uint16 y, uint8 z, ActorAlignment alignment, uint8 worktype, Actor **new_actor = nullptr);
138 bool clone_actor(Actor *actor, Actor **new_actor, MapCoord new_location);
139 bool toss_actor(Actor *actor, uint16 xrange, uint16 yrange);
140 bool toss_actor_get_location(uint16 start_x, uint16 start_y, uint8 start_z, uint16 xrange, uint16 yrange, MapCoord *location);
141 void print_actor(Actor *actor);
142 bool can_put_actor(const MapCoord &location);
143 void enable_temp_actor_cleaning(bool value) {
144 should_clean_temp_actors = value;
145 }
146
147protected:
148
149 Actor *get_multi_tile_actor(uint16 x, uint16 y, uint8 z);
150
151 bool loadActorSchedules();
152 inline Actor *find_free_temp_actor();
153 inline ActorList *filter_active_actors(ActorList *list, uint16 x, uint16 y, uint8 z);
154
155 void update_temp_actors(uint16 x, uint16 y, uint8 z);
156 void clean_temp_actors_from_level(uint8 level);
157 void clean_temp_actors_from_area(uint16 x, uint16 y);
158
159 inline void clean_temp_actor(Actor *actor);
160
161private:
162
163 bool loadCustomTiles(nuvie_game_t game_type);
164 void loadNPCTiles(const Common::Path &datadir);
165 void loadAvatarTiles(const Common::Path &datadir);
166 void loadCustomBaseTiles();
167 Common::Array<Common::String> getCustomTileFilenames(const Common::Path &datadir, const Common::String &filenamePrefix);
168};
169
170} // End of namespace Nuvie
171} // End of namespace Ultima
172
173#endif
Definition: array.h:52
Definition: path.h:52
Definition: str.h:59
Definition: actor.h:174
Definition: actor_manager.h:42
Actor * findActorAt(uint16 x, uint16 y, uint8 z, F predicate, bool incDoubleTile=true, bool incSurroundingObjs=true)
Find first actor at location for which predicate function returns true.
Definition: actor_manager.h:100
Definition: configuration.h:60
Definition: game_clock.h:45
Definition: map.h:84
Definition: map.h:147
Definition: nuvie_io.h:32
Definition: obj.h:84
Definition: obj_manager.h:74
Definition: tile_manager.h:145