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
00030
00031
00032
00033
00034
00035
00036 #include "util/base/resourceclass.h"
00037 #include "model/metamodel/modelcoords.h"
00038 #include "model/metamodel/object.h"
00039
00040 #include "instance.h"
00041
00042 namespace FIFE {
00043
00044 class Map;
00045 class Selection;
00046 class CellGrid;
00047 class Object;
00048 class InstanceTree;
00049
00056 enum PathingStrategy {
00057 CELL_EDGES_ONLY,
00058 CELL_EDGES_AND_DIAGONALS,
00059 FREEFORM
00060 };
00061
00064 class LayerChangeListener {
00065 public:
00066 virtual ~LayerChangeListener() {};
00067
00073 virtual void onLayerChanged(Layer* layer, std::vector<Instance*>& changedInstances) = 0;
00074
00079 virtual void onInstanceCreate(Layer* layer, Instance* instance) = 0;
00080
00086 virtual void onInstanceDelete(Layer* layer, Instance* instance) = 0;
00087 };
00088
00089
00092 class Layer : public ResourceClass {
00093 public:
00098 Layer(const std::string& identifier, Map* map, CellGrid* grid);
00099
00102 ~Layer();
00103
00106 const std::string& getId() const { return m_id; }
00107
00110 void setId(const std::string& id) { m_id = id; }
00111
00114 Map* getMap() const { return m_map; }
00115
00119 CellGrid* getCellGrid() const { return m_grid; }
00120
00123 void setCellGrid(CellGrid* grid) { m_grid = grid; }
00124
00128 InstanceTree* getInstanceTree(void) const { return m_instanceTree; }
00129
00133 bool hasInstances() const;
00134
00137 Instance* createInstance(Object* object, const ModelCoordinate& p, const std::string& id="");
00138
00141 Instance* createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id="");
00142
00146 bool addInstance(Instance* instance, const ExactModelCoordinate& p);
00147
00150 void deleteInstance(Instance* object);
00151
00154 const std::vector<Instance*>& getInstances() const { return m_instances; }
00155
00158 std::vector<Instance*> getInstances(const std::string& id);
00159
00164 std::vector<Instance*> getInstancesAt(Location& loc, bool use_exactcoordinates=false);
00165
00168 Instance* getInstance(const std::string& identifier);
00169
00172 void setInstancesVisible(bool vis);
00173
00177 void setLayerTransparency(uint8_t transparency);
00178
00181 uint8_t getLayerTransparency();
00182
00188 void getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer = 0) const;
00189
00195 bool cellContainsBlockingInstance(const ModelCoordinate& cellCoordinate);
00196
00200 void toggleInstancesVisible();
00201
00205 bool areInstancesVisible() const { return m_instances_visibility; }
00206
00210 bool update();
00211
00215 void setPathingStrategy(PathingStrategy strategy) { m_pathingstrategy = strategy; }
00216
00220 PathingStrategy getPathingStrategy() const { return m_pathingstrategy; }
00221
00225 void addChangeListener(LayerChangeListener* listener);
00226
00230 void removeChangeListener(LayerChangeListener* listener);
00231
00234 bool isChanged() { return m_changed; }
00235
00239 std::vector<Instance*>& getChangedInstances() { return m_changedinstances; }
00240
00241 protected:
00242 std::string m_id;
00243
00244 Map* m_map;
00245
00246 bool m_instances_visibility;
00247
00248 uint8_t m_transparency;
00249
00250
00251 std::vector<Instance*> m_instances;
00252
00253
00254 InstanceTree* m_instanceTree;
00255
00256
00257 CellGrid* m_grid;
00258
00259
00260 PathingStrategy m_pathingstrategy;
00261
00262
00263 std::vector<LayerChangeListener*> m_changelisteners;
00264
00265
00266 std::vector<Instance*> m_changedinstances;
00267
00268
00269 bool m_changed;
00270 };
00271
00272 }
00273
00274 #endif