FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
cell.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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 
77  };
79 
83  public:
84  TransitionInfo(Layer* layer) { m_layer = layer; m_difflayer = false; m_immediate = true;}
87  Layer* m_layer;
94  };
95 
99  public:
100  virtual ~CellDeleteListener() {};
101 
105  virtual void onCellDeleted(Cell* cell) = 0;
106  };
107 
111  public:
112  virtual ~CellChangeListener() {};
113 
118  virtual void onInstanceEnteredCell(Cell* cell, Instance* instance) = 0;
119 
124  virtual void onInstanceExitedCell(Cell* cell, Instance* instance) = 0;
125 
131  virtual void onBlockingChangedCell(Cell* cell, CellTypeInfo type, bool blocks) = 0;
132  };
133 
136  class Cell: public FifeClass, public CellDeleteListener {
137  public:
143  Cell(int32_t coordint, ModelCoordinate coordinate, Layer* layer);
144 
147  ~Cell();
148 
152  void addInstances(const std::list<Instance*>& instances);
153 
157  void addInstance(Instance* instance);
158 
162  void changeInstance(Instance* instance);
163 
167  void removeInstance(Instance* instance);
168 
173  bool isNeighbor(Cell* cell);
174 
178  void updateCellInfo();
179 
183  bool defaultCost();
184 
188  void setCostMultiplier(double multi);
189 
193  double getCostMultiplier();
194 
197  void resetCostMultiplier();
198 
202  bool defaultSpeed();
203 
207  void setSpeedMultiplier(double multi);
208 
212  double getSpeedMultiplier();
213 
216  void resetSpeedMultiplier();
217 
221  Zone* getZone();
222 
226  void setZone(Zone* zone);
227 
231  void resetZone();
232 
236  bool isInserted();
237 
241  void setInserted(bool inserted);
242 
246  bool isZoneProtected();
247 
251  void setZoneProtected(bool protect);
252 
256  CellTypeInfo getCellType();
257 
261  void setCellType(CellTypeInfo type);
262 
266  const std::set<Instance*>& getInstances();
267 
271  void setCellId(int32_t id);
272 
276  int32_t getCellId();
277 
281  const ModelCoordinate getLayerCoordinates() const;
282 
286  void addNeighbor(Cell* cell);
287 
291  const std::vector<Cell*>& getNeighbors();
292 
295  void resetNeighbors();
296 
300  Layer* getLayer();
301 
308  void createTransition(Layer* layer, const ModelCoordinate& mc, bool immediate = false);
309 
312  void deleteTransition();
313 
317  TransitionInfo* getTransition();
318 
322  void setFoWType(CellVisualEffect type);
323 
327  CellVisualEffect getFoWType();
328 
332  void addVisitorInstance(Instance* instance);
333 
337  void removeVisitorInstance(Instance* instance);
338 
342  const std::vector<Instance*>& getVisitorInstances();
343 
347  void addDeleteListener(CellDeleteListener* listener);
348 
352  void removeDeleteListener(CellDeleteListener* listener);
353 
358  void onCellDeleted(Cell* cell);
359 
364  void addChangeListener(CellChangeListener* listener);
365 
370  void removeChangeListener(CellChangeListener* listener);
371 
376  void callOnInstanceEntered(Instance* instance);
377 
382  void callOnInstanceExited(Instance* instance);
383 
388  void callOnBlockingChanged(bool blocks);
389 
390  private:
391 
392  void updateCellBlockingInfo();
393  void updateCellFowInfo();
394 
396  int32_t m_coordId;
397 
400 
403 
406 
409 
412 
414  bool m_protect;
415 
417  CellTypeInfo m_type;
418 
420  CellVisualEffect m_fowType;
421 
422  // contained Instances
423  std::set<Instance*> m_instances;
424 
426  std::vector<Instance*> m_visitors;
427 
429  std::vector<Cell*> m_neighbors;
430 
432  std::vector<CellDeleteListener*> m_deleteListeners;
433 
435  std::vector<CellChangeListener*> m_changeListeners;
436  };
437 
438 } // FIFE
439 
440 #endif
Layer * m_layer
target layer
Definition: cell.h:85
std::vector< Instance * > m_visitors
contains visitor instances
Definition: cell.h:426
std::vector< CellChangeListener * > m_changeListeners
change listener
Definition: cell.h:435
bool m_difflayer
is target on another layer
Definition: cell.h:91
static const double MIN_CELL_Z
Definition: cell.h:48
Listener interface for changes happening on a cell.
Definition: cell.h:110
std::set< Instance * > m_instances
Definition: cell.h:423
CellVisualEffect m_fowType
visual cell status
Definition: cell.h:420
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:112
CellVisualType
Defines different cell visuals which are used for Fog of War.
Definition: cell.h:73
Listener interface for deletions happening on a cell, used for transistions.
Definition: cell.h:98
unsigned char uint8_t
Definition: core.h:38
TransitionInfo(Layer *layer)
Definition: cell.h:84
Simple class to hold the data for transistions.
Definition: cell.h:82
int32_t m_coordId
holds coordinate as a unique integer id
Definition: cell.h:396
uint8_t CellTypeInfo
Definition: cell.h:65
TransitionInfo * m_transition
Pointer to Transistion.
Definition: cell.h:408
A basic layer on a map.
Definition: layer.h:99
Layer * m_layer
parent layer
Definition: cell.h:402
A basic cell on a CellCache.
Definition: cell.h:136
uint8_t CellVisualEffect
Definition: cell.h:78
bool m_protect
protected
Definition: cell.h:414
virtual ~CellDeleteListener()
Definition: cell.h:100
ModelCoordinate m_coordinate
holds coordinate
Definition: cell.h:399
CellTypeInfo m_type
CellType.
Definition: cell.h:417
A 3D Point.
Definition: point.h:205
Zone * m_zone
parent Zone
Definition: cell.h:405
std::vector< Cell * > m_neighbors
neighbor cells
Definition: cell.h:429
std::vector< CellDeleteListener * > m_deleteListeners
delete listener
Definition: cell.h:432
bool m_inserted
already inserted
Definition: cell.h:411
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:101
bool m_immediate
use immediate
Definition: cell.h:93
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:89