layer.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIFE_LAYER_H
00023 #define FIFE_LAYER_H
00024
00025
00026 #include <algorithm>
00027 #include <string>
00028 #include <vector>
00029 #include <set>
00030
00031
00032
00033
00034
00035
00036
00037 #include "util/base/resourceclass.h"
00038 #include "model/metamodel/modelcoords.h"
00039 #include "model/metamodel/object.h"
00040
00041 #include "instance.h"
00042
00043 namespace FIFE {
00044
00045 class Map;
00046 class Selection;
00047 class CellGrid;
00048 class Object;
00049 class InstanceTree;
00050
00057 enum PathingStrategy {
00058 CELL_EDGES_ONLY,
00059 CELL_EDGES_AND_DIAGONALS,
00060 FREEFORM
00061 };
00062
00065 class LayerChangeListener {
00066 public:
00067 virtual ~LayerChangeListener() {};
00068
00074 virtual void onLayerChanged(Layer* layer, std::vector<Instance*>& changedInstances) = 0;
00075
00080 virtual void onInstanceCreate(Layer* layer, Instance* instance) = 0;
00081
00087 virtual void onInstanceDelete(Layer* layer, Instance* instance) = 0;
00088 };
00089
00090
00093 class Layer : public ResourceClass {
00094 public:
00099 Layer(const std::string& identifier, Map* map, CellGrid* grid);
00100
00103 ~Layer();
00104
00107 const std::string& getId() const { return m_id; }
00108
00111 void setId(const std::string& id) { m_id = id; }
00112
00115 Map* getMap() const { return m_map; }
00116
00120 CellGrid* getCellGrid() const { return m_grid; }
00121
00124 void setCellGrid(CellGrid* grid) { m_grid = grid; }
00125
00129 InstanceTree* getInstanceTree(void) const { return m_instanceTree; }
00130
00134 bool hasInstances() const;
00135
00138 Instance* createInstance(Object* object, const ModelCoordinate& p, const std::string& id="");
00139
00142 Instance* createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id="");
00143
00147 bool addInstance(Instance* instance, const ExactModelCoordinate& p);
00148
00151 void deleteInstance(Instance* object);
00152
00155 const std::vector<Instance*>& getInstances() const { return m_instances; }
00156
00159 std::vector<Instance*> getInstances(const std::string& id);
00160
00165 std::vector<Instance*> getInstancesAt(Location& loc, bool use_exactcoordinates=false);
00166
00169 Instance* getInstance(const std::string& identifier);
00170
00173 void setInstancesVisible(bool vis);
00174
00178 void setLayerTransparency(uint8_t transparency);
00179
00182 uint8_t getLayerTransparency();
00183
00189 void getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer = 0) const;
00190
00196 bool cellContainsBlockingInstance(const ModelCoordinate& cellCoordinate);
00197
00201 void toggleInstancesVisible();
00202
00206 bool areInstancesVisible() const { return m_instances_visibility; }
00207
00211 bool update();
00212
00216 void setPathingStrategy(PathingStrategy strategy) { m_pathingstrategy = strategy; }
00217
00221 PathingStrategy getPathingStrategy() const { return m_pathingstrategy; }
00222
00226 void addChangeListener(LayerChangeListener* listener);
00227
00231 void removeChangeListener(LayerChangeListener* listener);
00232
00235 bool isChanged() { return m_changed; }
00236
00240 std::vector<Instance*>& getChangedInstances() { return m_changedinstances; }
00241
00242 void setInstanceActivityStatus(Instance* instance, bool active);
00243
00244 protected:
00245 std::string m_id;
00246
00247 Map* m_map;
00248
00249 bool m_instances_visibility;
00250
00251 uint8_t m_transparency;
00252
00253
00254 std::vector<Instance*> m_instances;
00255
00256
00257 std::set<Instance*> m_active_instances;
00258
00259
00260 InstanceTree* m_instanceTree;
00261
00262
00263 CellGrid* m_grid;
00264
00265
00266 PathingStrategy m_pathingstrategy;
00267
00268
00269 std::vector<LayerChangeListener*> m_changelisteners;
00270
00271
00272 std::vector<Instance*> m_changedinstances;
00273
00274
00275 bool m_changed;
00276 };
00277
00278 }
00279
00280 #endif