FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
cell.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_CELL_H
23 #define FIFE_CELL_H
24 
25 // Standard C++ library includes
26 #include <vector>
27 #include <set>
28 #include <list>
29 #include <map>
30 
31 // 3rd party library includes
32 
33 // FIFE includes
34 // These includes are split up in two parts, separated by one empty line
35 // First block: files included from the FIFE root src directory
36 // Second block: files included from the same folder
37 #include "util/base/fifeclass.h"
39 
40 
41 namespace FIFE {
42 
43  class Instance;
44  class Layer;
45  class Cell;
46  class Zone;
47 
48  static const double MIN_CELL_Z = -9999999;
49 
58  enum CellType {
64  };
66 
70  public:
71  TransitionInfo(Layer* layer) { m_layer = layer; m_difflayer = false; m_immediate = true;}
74  Layer* m_layer;
81  };
82 
86  public:
87  virtual ~CellDeleteListener() {};
88 
92  virtual void onCellDeleted(Cell* cell) = 0;
93  };
94 
98  public:
99  virtual ~CellChangeListener() {};
100 
105  virtual void onInstanceEnteredCell(Cell* cell, Instance* instance) = 0;
106 
111  virtual void onInstanceExitedCell(Cell* cell, Instance* instance) = 0;
112 
118  virtual void onBlockingChangedCell(Cell* cell, CellTypeInfo type, bool blocks) = 0;
119  };
120 
123  class Cell: public FifeClass, public CellDeleteListener {
124  public:
130  Cell(int32_t coordint, ModelCoordinate coordinate, Layer* layer);
131 
134  ~Cell();
135 
139  void addInstances(const std::list<Instance*>& instances);
140 
144  void addInstance(Instance* instance);
145 
149  void changeInstance(Instance* instance);
150 
154  void removeInstance(Instance* instance);
155 
160  bool isNeighbor(Cell* cell);
161 
165  void updateCellInfo();
166 
170  bool defaultCost();
171 
175  void setCostMultiplier(double multi);
176 
180  double getCostMultiplier();
181 
184  void resetCostMultiplier();
185 
189  bool defaultSpeed();
190 
194  void setSpeedMultiplier(double multi);
195 
199  double getSpeedMultiplier();
200 
203  void resetSpeedMultiplier();
204 
208  Zone* getZone();
209 
213  void setZone(Zone* zone);
214 
218  void resetZone();
219 
223  bool isInserted();
224 
228  void setInserted(bool inserted);
229 
233  bool isZoneProtected();
234 
238  void setZoneProtected(bool protect);
239 
243  CellTypeInfo getCellType();
244 
248  void setCellType(CellTypeInfo type);
249 
253  const std::set<Instance*>& getInstances();
254 
258  void setCellId(int32_t id);
259 
263  int32_t getCellId();
264 
268  const ModelCoordinate getLayerCoordinates() const;
269 
273  void addNeighbor(Cell* cell);
274 
278  const std::vector<Cell*>& getNeighbors();
279 
282  void resetNeighbors();
283 
287  Layer* getLayer();
288 
295  void createTransition(Layer* layer, const ModelCoordinate& mc, bool immediate = false);
296 
299  void deleteTransition();
300 
304  TransitionInfo* getTransition();
305 
309  void addDeleteListener(CellDeleteListener* listener);
310 
314  void removeDeleteListener(CellDeleteListener* listener);
315 
320  void onCellDeleted(Cell* cell);
321 
326  void addChangeListener(CellChangeListener* listener);
327 
332  void removeChangeListener(CellChangeListener* listener);
333 
338  void callOnInstanceEntered(Instance* instance);
339 
344  void callOnInstanceExited(Instance* instance);
345 
350  void callOnBlockingChanged(bool blocks);
351 
352  private:
353 
354  void updateCellBlockingInfo();
355 
357  int32_t m_coordId;
358 
361 
364 
367 
370 
373 
375  bool m_protect;
376 
378  CellTypeInfo m_type;
379 
380  // contained Instances
381  std::set<Instance*> m_instances;
382 
384  std::vector<Cell*> m_neighbors;
385 
387  std::vector<CellDeleteListener*> m_deleteListeners;
388 
390  std::vector<CellChangeListener*> m_changeListeners;
391  };
392 
393 } // FIFE
394 
395 #endif
Layer * m_layer
target layer
Definition: cell.h:72
std::vector< CellChangeListener * > m_changeListeners
change listener
Definition: cell.h:390
bool m_difflayer
is target on another layer
Definition: cell.h:78
static const double MIN_CELL_Z
Definition: cell.h:48
Listener interface for changes happening on a cell.
Definition: cell.h:97
std::set< Instance * > m_instances
Definition: cell.h:381
CellType
Defines different blocker types.
Definition: cell.h:58
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
virtual ~CellChangeListener()
Definition: cell.h:99
Listener interface for deletions happening on a cell, used for transistions.
Definition: cell.h:85
unsigned char uint8_t
Definition: core.h:38
TransitionInfo(Layer *layer)
Definition: cell.h:71
Simple class to hold the data for transistions.
Definition: cell.h:69
int32_t m_coordId
holds coordinate as a unique integer id
Definition: cell.h:357
uint8_t CellTypeInfo
Definition: cell.h:65
TransitionInfo * m_transition
Pointer to Transistion.
Definition: cell.h:369
A basic layer on a map.
Definition: layer.h:99
Layer * m_layer
parent layer
Definition: cell.h:363
A basic cell on a CellCache.
Definition: cell.h:123
bool m_protect
protected
Definition: cell.h:375
virtual ~CellDeleteListener()
Definition: cell.h:87
ModelCoordinate m_coordinate
holds coordinate
Definition: cell.h:360
CellTypeInfo m_type
CellType.
Definition: cell.h:378
A 3D Point.
Definition: point.h:205
Zone * m_zone
parent Zone
Definition: cell.h:366
std::vector< Cell * > m_neighbors
neighbor cells
Definition: cell.h:384
std::vector< CellDeleteListener * > m_deleteListeners
delete listener
Definition: cell.h:387
bool m_inserted
already inserted
Definition: cell.h:372
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:94
bool m_immediate
use immediate
Definition: cell.h:80
A Zone is an abstract depiction of a CellCache or of a part of it.
Definition: cellcache.h:50
ModelCoordinate m_mc
target coordinates
Definition: cell.h:76