FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cell.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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 
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 
318 
322  void setFoWType(CellVisualEffect type);
323 
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 
353 
358  void onCellDeleted(Cell* cell);
359 
364  void addChangeListener(CellChangeListener* listener);
365 
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 
418 
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
void setZoneProtected(bool protect)
Mark zone on this cell as protected.
Definition: cell.cpp:472
double getCostMultiplier()
Returns the current cell cost.
Definition: cell.cpp:423
Layer * m_layer
target layer
Definition: cell.h:85
std::vector< Instance * > m_visitors
contains visitor instances
Definition: cell.h:426
bool isNeighbor(Cell *cell)
Called to check if given cell is a neighbor.
Definition: cell.cpp:241
std::vector< CellChangeListener * > m_changeListeners
change listener
Definition: cell.h:435
bool m_difflayer
is target on another layer
Definition: cell.h:91
void callOnInstanceEntered(Instance *instance)
Called when a instance entered this cell.
Definition: cell.cpp:608
void addInstance(Instance *instance)
Adds a instance to this cell.
Definition: cell.cpp:135
static const double MIN_CELL_Z
Definition: cell.h:48
virtual void onInstanceExitedCell(Cell *cell, Instance *instance)=0
Called when some instance exited the cell.
virtual void onCellDeleted(Cell *cell)=0
Called when a cell gets deleted.
Layer * getLayer()
Returns the current layer.
Definition: cell.cpp:521
double getSpeedMultiplier()
Returns the current cell speed.
Definition: cell.cpp:439
virtual void onInstanceEnteredCell(Cell *cell, Instance *instance)=0
Called when some instance entered the cell.
const std::vector< Instance * > & getVisitorInstances()
Returns all visitor instances on this cell.
Definition: cell.cpp:411
void callOnInstanceExited(Instance *instance)
Called when a instance exited this cell.
Definition: cell.cpp:622
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
void addInstances(const std::list< Instance * > &instances)
Adds instances to this cell.
Definition: cell.cpp:76
void setSpeedMultiplier(double multi)
Changes the cell speed.
Definition: cell.cpp:435
void setCellType(CellTypeInfo type)
Sets blocker type.
Definition: cell.cpp:480
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
void removeInstance(Instance *instance)
Removes a instance from this cell.
Definition: cell.cpp:196
CellVisualType
Defines different cell visuals which are used for Fog of War.
Definition: cell.h:73
int32_t getCellId()
Returns the cell identifier.
Definition: cell.cpp:492
void addChangeListener(CellChangeListener *listener)
Adds new cell change listener.
Definition: cell.cpp:594
bool defaultCost()
Returns if cell use default cost.
Definition: cell.cpp:415
void resetCostMultiplier()
Resets the cell cost to default, 1.0.
Definition: cell.cpp:427
void deleteTransition()
Removes the transistion from Cell and CellCache.
Definition: cell.cpp:549
void onCellDeleted(Cell *cell)
Called when a cell gets deleted on this cell.
Definition: cell.cpp:584
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
void setZone(Zone *zone)
Sets zone.
Definition: cell.cpp:451
Simple class to hold the data for transistions.
Definition: cell.h:82
void addNeighbor(Cell *cell)
Adds a neighbor cell to this cell.
Definition: cell.cpp:500
int32_t m_coordId
holds coordinate as a unique integer id
Definition: cell.h:396
const std::set< Instance * > & getInstances()
Returns all instances on this cell.
Definition: cell.cpp:484
void addVisitorInstance(Instance *instance)
Adds a instance as visitor to this cell.
Definition: cell.cpp:387
bool isZoneProtected()
Returns whether the zone on this cell is protected.
Definition: cell.cpp:468
uint8_t CellTypeInfo
Definition: cell.h:65
CellTypeInfo getCellType()
Returns blocker type.
Definition: cell.cpp:476
TransitionInfo * m_transition
Pointer to Transistion.
Definition: cell.h:408
A basic layer on a map.
Definition: layer.h:98
Layer * m_layer
parent layer
Definition: cell.h:402
virtual void onBlockingChangedCell(Cell *cell, CellTypeInfo type, bool blocks)=0
Called when some instance changed its blocking property.
const std::vector< Cell * > & getNeighbors()
Returns the layer coordinates of this cell.
Definition: cell.cpp:504
void removeDeleteListener(CellDeleteListener *listener)
Removes cell delete listener.
Definition: cell.cpp:574
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
void updateCellInfo()
Called to update cell data.
Definition: cell.cpp:363
Cell(int32_t coordint, ModelCoordinate coordinate, Layer *layer)
Constructor.
Definition: cell.cpp:42
CellVisualEffect getFoWType()
Returns the cell visual.
Definition: cell.cpp:383
void changeInstance(Instance *instance)
Changes a instance on this cell.
Definition: cell.cpp:192
virtual ~CellDeleteListener()
Definition: cell.h:100
const ModelCoordinate getLayerCoordinates() const
Returns the layer coordinates of this cell.
Definition: cell.cpp:496
Zone * getZone()
Returns zone.
Definition: cell.cpp:447
void updateCellBlockingInfo()
Definition: cell.cpp:251
void setFoWType(CellVisualEffect type)
Sets the cell visual.
Definition: cell.cpp:379
void setCellId(int32_t id)
Sets the cell identifier.
Definition: cell.cpp:488
void setCostMultiplier(double multi)
Changes the cell cost.
Definition: cell.cpp:419
ModelCoordinate m_coordinate
holds coordinate
Definition: cell.h:399
CellTypeInfo m_type
CellType.
Definition: cell.h:417
A 3D Point.
Definition: point.h:202
void updateCellFowInfo()
Definition: cell.cpp:308
void setInserted(bool inserted)
Mark cell as inserted.
Definition: cell.cpp:464
Zone * m_zone
parent Zone
Definition: cell.h:405
void removeVisitorInstance(Instance *instance)
Removes the visitor instance from this cell.
Definition: cell.cpp:401
std::vector< Cell * > m_neighbors
neighbor cells
Definition: cell.h:429
void createTransition(Layer *layer, const ModelCoordinate &mc, bool immediate=false)
Creates a transistion from this cell to the given layer and coordinates.
Definition: cell.cpp:525
void resetNeighbors()
Removes all neighbors from cell.
Definition: cell.cpp:508
std::vector< CellDeleteListener * > m_deleteListeners
delete listener
Definition: cell.h:432
bool m_inserted
already inserted
Definition: cell.h:411
~Cell()
Destructor.
Definition: cell.cpp:54
TransitionInfo * getTransition()
Returns the transition.
Definition: cell.cpp:566
bool isInserted()
Returns whether the cell is part of a zone.
Definition: cell.cpp:460
bool defaultSpeed()
Returns if cell use default speed.
Definition: cell.cpp:431
void addDeleteListener(CellDeleteListener *listener)
Adds new cell delete listener.
Definition: cell.cpp:570
void resetZone()
Resets zone.
Definition: cell.cpp:455
An Instance is an &quot;instantiation&quot; of an Object at a Location.
Definition: instance.h:97
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
void removeChangeListener(CellChangeListener *listener)
Removes cell change listener.
Definition: cell.cpp:598
void callOnBlockingChanged(bool blocks)
Called when the blocking property of this cell changed.
Definition: cell.cpp:636
void resetSpeedMultiplier()
Resets the cell speed to default, 1.0.
Definition: cell.cpp:443