FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
cell.cpp
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 // Standard C++ library includes
23 
24 // 3rd party library includes
25 
26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder
30 #include "util/log/logger.h"
31 #include "view/visual.h"
32 
33 #include "cell.h"
34 #include "cellcache.h"
35 #include "instance.h"
36 #include "layer.h"
37 
38 namespace FIFE {
39 
40  static Logger _log(LM_STRUCTURES);
41 
42  Cell::Cell(int32_t coordint, ModelCoordinate coordinate, Layer* layer):
43  m_coordId(coordint),
44  m_coordinate(coordinate),
45  m_layer(layer),
46  m_zone(NULL),
47  m_transition(NULL),
48  m_inserted(false),
49  m_protect(false),
50  m_type(CTYPE_NO_BLOCKER),
51  m_fowType(CELLV_CONCEALED) {
52  }
53 
55  // calls CellDeleteListener, e.g. for transition
56  if (!m_deleteListeners.empty()) {
57  std::vector<CellDeleteListener*>::iterator it = m_deleteListeners.begin();
58  for (; it != m_deleteListeners.end(); ++it) {
59  if (*it) {
60  (*it)->onCellDeleted(this);
61  }
62  }
63  }
64  // remove cell from zone
65  if (m_zone) {
66  m_zone->removeCell(this);
67  }
68  // delete m_transition;
69  if (m_transition) {
71  }
72  // remove cell from cache (costs, narrow, area)
74  }
75 
76  void Cell::addInstances(const std::list<Instance*>& instances) {
77  CellCache* cache = m_layer->getCellCache();
78  for (std::list<Instance*>::const_iterator it = instances.begin(); it != instances.end(); ++it) {
79  std::pair<std::set<Instance*>::iterator, bool> ret = m_instances.insert(*it);
80  if (ret.second) {
81  if ((*it)->isVisitor()) {
82  uint16_t visitorRadius = (*it)->getVisitorRadius();
83  std::vector<Cell*> cells;
84  std::vector<Cell*> cellsExt;
85  switch((*it)->getVisitorShape()) {
86  case ITYPE_QUAD_SHAPE: {
87  Rect size(m_coordinate.x-visitorRadius, m_coordinate.y-visitorRadius,
88  (visitorRadius*2)+1, (visitorRadius*2)+1);
89  cells = cache->getCellsInRect(size);
90  Rect sizeExt(size.x-1, size.y-1, size.w+2, size.h+2);
91  cellsExt = cache->getCellsInRect(sizeExt);
92  }
93  break;
94 
95  case ITYPE_CIRCLE_SHAPE: {
96  cells = cache->getCellsInCircle(m_coordinate, visitorRadius);
97  cellsExt = cache->getCellsInCircle(m_coordinate, visitorRadius+1);
98  }
99  break;
100 
101  default: continue;
102  }
103  for (std::vector<Cell*>::iterator szit = cellsExt.begin(); szit != cellsExt.end(); ++szit) {
104  bool found = false;
105  for (std::vector<Cell*>::iterator sit = cells.begin(); sit != cells.end(); ++sit) {
106  if (*sit == *szit) {
107  found = true;
108  (*szit)->addVisitorInstance(*it);
109  (*szit)->setFoWType(CELLV_REVEALED);
110  break;
111  }
112  }
113  if (!found) {
114  const std::vector<Instance*>& cv = (*szit)->getVisitorInstances();
115  if (cv.empty()) {
116  (*szit)->setFoWType(CELLV_MASKED);
117  }
118  }
119  }
120  cache->setFowUpdate(true);
121  }
122  if ((*it)->isSpecialCost()) {
123  cache->registerCost((*it)->getCostId(), (*it)->getCost());
124  cache->addCellToCost((*it)->getCostId(), this);
125  }
126  if ((*it)->isSpecialSpeed()) {
127  cache->setSpeedMultiplier(this, (*it)->getSpeed());
128  }
129  if ((*it)->getObject()->getArea() != "") {
130  cache->addCellToArea((*it)->getObject()->getArea(), this);
131  }
133  }
134  }
136  }
137 
138  void Cell::addInstance(Instance* instance) {
139  std::pair<std::set<Instance*>::iterator, bool> ret = m_instances.insert(instance);
140  if (ret.second) {
141  CellCache* cache = m_layer->getCellCache();
142  if (instance->isVisitor()) {
143  uint16_t visitorRadius = instance->getVisitorRadius();
144  std::vector<Cell*> cells;
145  std::vector<Cell*> cellsExt;
146  switch(instance->getVisitorShape()) {
147  case ITYPE_QUAD_SHAPE: {
148  Rect size(m_coordinate.x-visitorRadius, m_coordinate.y-visitorRadius,
149  (visitorRadius*2)+1, (visitorRadius*2)+1);
150  cells = cache->getCellsInRect(size);
151  Rect sizeExt(size.x-1, size.y-1, size.w+2, size.h+2);
152  cellsExt = cache->getCellsInRect(sizeExt);
153  }
154  break;
155 
156  case ITYPE_CIRCLE_SHAPE: {
157  cells = cache->getCellsInCircle(m_coordinate, visitorRadius);
158  cellsExt = cache->getCellsInCircle(m_coordinate, visitorRadius+1);
159  }
160  break;
161 
162  default: break;
163  }
164  for (std::vector<Cell*>::iterator szit = cellsExt.begin(); szit != cellsExt.end(); ++szit) {
165  bool found = false;
166  for (std::vector<Cell*>::iterator sit = cells.begin(); sit != cells.end(); ++sit) {
167  if (*sit == *szit) {
168  found = true;
169  (*szit)->addVisitorInstance(instance);
170  (*szit)->setFoWType(CELLV_REVEALED);
171  break;
172  }
173  }
174  if (!found) {
175  const std::vector<Instance*>& cv = (*szit)->getVisitorInstances();
176  if (cv.empty()) {
177  (*szit)->setFoWType(CELLV_MASKED);
178  }
179  }
180  }
181  cache->setFowUpdate(true);
182  }
183  if (instance->isSpecialCost()) {
184  cache->registerCost(instance->getCostId(), instance->getCost());
185  cache->addCellToCost(instance->getCostId(), this);
186  }
187  if (instance->isSpecialSpeed()) {
188  cache->setSpeedMultiplier(this, instance->getSpeed());
189  }
190  if (instance->getObject()->getArea() != "") {
191  cache->addCellToArea(instance->getObject()->getArea(), this);
192  }
193  callOnInstanceEntered(instance);
195  }
196  }
197 
198  void Cell::changeInstance(Instance* instance) {
200  }
201 
202  void Cell::removeInstance(Instance* instance) {
203  if (m_instances.erase(instance) == 0) {
204  FL_ERR(_log, "Tried to remove an instance from cell, but given instance could not be found.");
205  return;
206  }
207  CellCache* cache = m_layer->getCellCache();
208  if (instance->isVisitor()) {
209  uint16_t visitorRadius = instance->getVisitorRadius();
210  std::vector<Cell*> cells;
211  switch(instance->getVisitorShape()) {
212  case ITYPE_QUAD_SHAPE: {
213  Rect size(m_coordinate.x-visitorRadius, m_coordinate.y-visitorRadius,
214  (visitorRadius*2)+1, (visitorRadius*2)+1);
215  cells = cache->getCellsInRect(size);
216  }
217  break;
218 
219  case ITYPE_CIRCLE_SHAPE: {
220  cells = cache->getCellsInCircle(m_coordinate, visitorRadius);
221  }
222  break;
223 
224  default: break;
225  }
226  for (std::vector<Cell*>::iterator it = cells.begin(); it != cells.end(); ++it) {
227  (*it)->removeVisitorInstance(instance);
228  const std::vector<Instance*>& cv = (*it)->getVisitorInstances();
229  if (!cv.empty()) {
230  (*it)->setFoWType(CELLV_REVEALED);
231  } else {
232  (*it)->setFoWType(CELLV_MASKED);
233  }
234  }
235  cache->setFowUpdate(true);
236  }
237  if (instance->isSpecialCost()) {
238  cache->removeCellFromCost(instance->getCostId(), this);
239  }
240  if (instance->isSpecialSpeed()) {
241  cache->resetSpeedMultiplier(this);
242  // try to find other speed value
243  if (!m_instances.empty()) {
244  std::set<Instance*>::iterator it = m_instances.begin();
245  for (; it != m_instances.end(); ++it) {
246  if ((*it)->isSpecialSpeed()) {
247  cache->setSpeedMultiplier(this, (*it)->getSpeed());
248  break;
249  }
250  }
251  }
252  }
253  if (instance->getObject()->getArea() != "") {
254  cache->removeCellFromArea(instance->getObject()->getArea(), this);
255  }
256  callOnInstanceExited(instance);
258  }
259 
260  bool Cell::isNeighbor(Cell* cell) {
261  std::vector<Cell*>::iterator it = m_neighbors.begin();
262  for (; it != m_neighbors.end(); ++it) {
263  if (*it == cell) {
264  return true;
265  }
266  }
267  return false;
268  }
269 
271  CellTypeInfo old_type = m_type;
273  if (!m_instances.empty()) {
274  int32_t pos = -1;
275  bool cellblock = (m_type == CTYPE_CELL_NO_BLOCKER || m_type == CTYPE_CELL_BLOCKER);
276  for (std::set<Instance*>::iterator it = m_instances.begin(); it != m_instances.end(); ++it) {
277  if (cellblock) {
278  continue;
279  }
280  uint8_t stackpos = (*it)->getCellStackPosition();
281  if (stackpos < pos) {
282  continue;
283  }
284  // update cell z
285  if (m_coordinate.z < (*it)->getLocationRef().getLayerCoordinates().z && (*it)->getObject()->isStatic()) {
286  m_coordinate.z = (*it)->getLocationRef().getLayerCoordinates().z;
287  }
288  if ((*it)->getCellStackPosition() > pos) {
289  pos = (*it)->getCellStackPosition();
290  if ((*it)->isBlocking()) {
291  if (!(*it)->getObject()->isStatic()) {
293  } else {
295  }
296  } else {
298  }
299  } else {
300  // if positions are equal then static_blockers win
301  if ((*it)->isBlocking() && m_type != CTYPE_STATIC_BLOCKER) {
302  if (!(*it)->getObject()->isStatic()) {
304  } else {
306  }
307  }
308  }
309  }
310  } else {
313  }
314  }
316  m_coordinate.z = 0;
317  }
318 
319  if (old_type != m_type) {
320  bool block = (m_type == CTYPE_STATIC_BLOCKER ||
323  callOnBlockingChanged(block);
324  }
325  }
326 
328  bool visitors = !m_visitors.empty();
329  bool instances = !m_instances.empty();
330  if (!visitors && !instances && m_fowType == CELLV_REVEALED) {
332  } else if (visitors && instances) {
333  CellCache* cache = m_layer->getCellCache();
334  std::vector<Instance*>::iterator visit = m_visitors.begin();
335  for (; visit != m_visitors.end(); ++visit) {
336  std::set<Instance*>::iterator insfind = m_instances.find(*visit);
337  if (insfind != m_instances.end()) {
338  uint16_t visitorRadius = (*visit)->getVisitorRadius();
339  std::vector<Cell*> cells;
340  std::vector<Cell*> cellsExt;
341  switch((*visit)->getVisitorShape()) {
342  case ITYPE_QUAD_SHAPE: {
343  Rect size(m_coordinate.x-visitorRadius, m_coordinate.y-visitorRadius,
344  (visitorRadius*2)+1, (visitorRadius*2)+1);
345  cells = cache->getCellsInRect(size);
346  Rect sizeExt(size.x-1, size.y-1, size.w+2, size.h+2);
347  cellsExt = cache->getCellsInRect(sizeExt);
348  }
349  break;
350 
351  case ITYPE_CIRCLE_SHAPE: {
352  cells = cache->getCellsInCircle(m_coordinate, visitorRadius);
353  cellsExt = cache->getCellsInCircle(m_coordinate, visitorRadius+1);
354  }
355  break;
356 
357  default: continue;
358  }
359 
360  for (std::vector<Cell*>::iterator szit = cellsExt.begin(); szit != cellsExt.end(); ++szit) {
361  bool found = false;
362  for (std::vector<Cell*>::iterator sit = cells.begin(); sit != cells.end(); ++sit) {
363  if (*sit == *szit) {
364  found = true;
365  (*szit)->addVisitorInstance(*visit);
366  (*szit)->setFoWType(CELLV_REVEALED);
367  break;
368  }
369  }
370  if (!found) {
371  const std::vector<Instance*>& cv = (*szit)->getVisitorInstances();
372  if (cv.empty()) {
373  (*szit)->setFoWType(CELLV_MASKED);
374  }
375  }
376  }
377  }
378  }
379  }
380  }
381 
385 
386  if (!m_deleteListeners.empty()) {
387  m_deleteListeners.erase(
388  std::remove(m_deleteListeners.begin(), m_deleteListeners.end(),
389  (CellDeleteListener*)NULL), m_deleteListeners.end());
390  }
391  if (!m_changeListeners.empty()) {
392  m_changeListeners.erase(
393  std::remove(m_changeListeners.begin(), m_changeListeners.end(),
394  (CellChangeListener*)NULL), m_changeListeners.end());
395  }
396  }
397 
399  m_fowType = type;
400  }
401 
403  return m_fowType;
404  }
405 
407  if (m_visitors.empty()) {
408  m_visitors.push_back(instance);
409  return;
410  }
411  std::vector<Instance*>::iterator it = m_visitors.begin();
412  for (; it != m_visitors.end(); ++it) {
413  if (*it == instance) {
414  return;
415  }
416  }
417  m_visitors.push_back(instance);
418  }
419 
421  std::vector<Instance*>::iterator it = m_visitors.begin();
422  for (; it != m_visitors.end(); ++it) {
423  if (*it == instance) {
424  m_visitors.erase(it);
425  break;
426  }
427  }
428  }
429 
430  const std::vector<Instance*>& Cell::getVisitorInstances() {
431  return m_visitors;
432  }
433 
435  return m_layer->getCellCache()->isDefaultCost(this);
436  }
437 
438  void Cell::setCostMultiplier(double multi) {
439  m_layer->getCellCache()->setCostMultiplier(this, multi);
440  }
441 
443  return m_layer->getCellCache()->getCostMultiplier(this);
444  }
445 
448  }
449 
451  return m_layer->getCellCache()->isDefaultSpeed(this);
452  }
453 
454  void Cell::setSpeedMultiplier(double multi) {
455  m_layer->getCellCache()->setSpeedMultiplier(this, multi);
456  }
457 
459  return m_layer->getCellCache()->getSpeedMultiplier(this);
460  }
461 
464  }
465 
467  return m_zone;
468  }
469 
470  void Cell::setZone(Zone* zone) {
471  m_zone = zone;
472  }
473 
475  m_inserted = false;
476  m_zone = NULL;
477  }
478 
480  return m_inserted;
481  }
482 
483  void Cell::setInserted(bool inserted) {
484  m_inserted = inserted;
485  }
486 
488  return m_protect;
489  }
490 
491  void Cell::setZoneProtected(bool protect) {
492  m_protect = protect;
493  }
494 
496  return m_type;
497  }
498 
500  m_type = type;
501  }
502 
503  const std::set<Instance*>& Cell::getInstances() {
504  return m_instances;
505  }
506 
507  void Cell::setCellId(int32_t id) {
508  m_coordId = id;
509  }
510 
511  int32_t Cell::getCellId() {
512  return m_coordId;
513  }
514 
516  return m_coordinate;
517  }
518 
519  void Cell::addNeighbor(Cell* cell) {
520  m_neighbors.push_back(cell);
521  }
522 
523  const std::vector<Cell*>& Cell::getNeighbors() {
524  return m_neighbors;
525  }
526 
528  m_neighbors.clear();
529  if (m_transition) {
531  if (cache) {
532  Cell* cell = cache->getCell(m_transition->m_mc);
533  if (cell) {
534  m_neighbors.push_back(cell);
535  }
536  }
537  }
538  }
539 
541  return m_layer;
542  }
543 
544  void Cell::createTransition(Layer* layer, const ModelCoordinate& mc, bool immediate) {
545  TransitionInfo* trans = new TransitionInfo(layer);
546  // if layers are the same then it's a portal
547  if (layer != m_layer) {
548  trans->m_difflayer = true;
549  }
550  trans->m_immediate = immediate;
551  trans->m_mc = mc;
552 
554 
555  m_transition = trans;
556 
557  Cell* c = layer->getCellCache()->getCell(mc);
558  if (c) {
559  m_neighbors.push_back(c);
560  c->addDeleteListener(this);
562  } else {
563  delete m_transition;
564  m_transition = NULL;
565  }
566  }
567 
569  if (m_transition) {
571  std::vector<Cell*>::iterator it = m_neighbors.begin();
572  for (; it != m_neighbors.end(); ++it) {
573  if (*it == oldc) {
574  m_neighbors.erase(it);
575  break;
576  }
577  }
578  oldc->removeDeleteListener(this);
580  delete m_transition;
581  m_transition = NULL;
582  }
583  }
584 
586  return m_transition;
587  }
588 
590  m_deleteListeners.push_back(listener);
591  }
592 
594  std::vector<CellDeleteListener*>::iterator it = m_deleteListeners.begin();
595  for (; it != m_deleteListeners.end(); ++it) {
596  if (*it == listener) {
597  *it = NULL;
598  break;
599  }
600  }
601  }
602 
603  void Cell::onCellDeleted(Cell* cell) {
604  std::vector<Cell*>::iterator it = m_neighbors.begin();
605  for (; it != m_neighbors.end(); ++it) {
606  if (*it == cell) {
608  break;
609  }
610  }
611  }
612 
614  m_changeListeners.push_back(listener);
615  }
616 
618  std::vector<CellChangeListener*>::iterator it = m_changeListeners.begin();
619  for (; it != m_changeListeners.end(); ++it) {
620  if (*it == listener) {
621  *it = NULL;
622  break;
623  }
624  }
625  }
626 
628  if (m_changeListeners.empty()) {
629  return;
630  }
631 
632  std::vector<CellChangeListener*>::iterator i = m_changeListeners.begin();
633  while (i != m_changeListeners.end()) {
634  if (*i) {
635  (*i)->onInstanceEnteredCell(this, instance);
636  }
637  ++i;
638  }
639  }
640 
642  if (m_changeListeners.empty()) {
643  return;
644  }
645 
646  std::vector<CellChangeListener*>::iterator i = m_changeListeners.begin();
647  while (i != m_changeListeners.end()) {
648  if (*i) {
649  (*i)->onInstanceExitedCell(this, instance);
650  }
651  ++i;
652  }
653  }
654 
655  void Cell::callOnBlockingChanged(bool blocks) {
656  if (m_changeListeners.empty()) {
657  return;
658  }
659 
660  std::vector<CellChangeListener*>::iterator i = m_changeListeners.begin();
661  while (i != m_changeListeners.end()) {
662  if (*i) {
663  (*i)->onBlockingChangedCell(this, m_type, blocks);
664  }
665  ++i;
666  }
667  }
668 } // FIFE
void setZoneProtected(bool protect)
Mark zone on this cell as protected.
Definition: cell.cpp:491
std::string getArea() const
Gets the area id that the instances of this object adds to their cells.
Definition: object.cpp:580
double getSpeedMultiplier(Cell *cell)
Returns speed multiplier for the cell.
Definition: cellcache.cpp:1207
std::string getCostId()
Returns cost id.
Definition: instance.cpp:1051
double getCostMultiplier()
Returns the current cell cost.
Definition: cell.cpp:442
Layer * m_layer
target layer
Definition: cell.h:85
std::vector< Instance * > m_visitors
contains visitor instances
Definition: cell.h:426
double getCostMultiplier(Cell *cell)
Returns cost multiplier for the cell.
Definition: cellcache.cpp:1177
bool isNeighbor(Cell *cell)
Called to check if given cell is a neighbor.
Definition: cell.cpp:260
std::vector< CellChangeListener * > m_changeListeners
change listener
Definition: cell.h:435
void setSpeedMultiplier(Cell *cell, double multi)
Sets speed multiplier for the cell.
Definition: cellcache.cpp:1198
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:627
void addInstance(Instance *instance)
Adds a instance to this cell.
Definition: cell.cpp:138
static const double MIN_CELL_Z
Definition: cell.h:48
T h
Height of the rectangle.
Definition: rect.h:93
Layer * getLayer()
Returns the current layer.
Definition: cell.cpp:540
bool isDefaultSpeed(Cell *cell)
Gets if cell uses default speed multiplier.
Definition: cellcache.cpp:1190
void removeTransition(Cell *cell)
Removes a cell as transition.
Definition: cellcache.cpp:1224
double getSpeedMultiplier()
Returns the current cell speed.
Definition: cell.cpp:458
const std::vector< Instance * > & getVisitorInstances()
Returns all visitor instances on this cell.
Definition: cell.cpp:430
void callOnInstanceExited(Instance *instance)
Called when a instance exited this cell.
Definition: cell.cpp:641
Listener interface for changes happening on a cell.
Definition: cell.h:110
T x
The X Coordinate.
Definition: rect.h:84
std::set< Instance * > m_instances
Definition: cell.h:423
void removeCellFromCost(Cell *cell)
Removes a cell from costs.
Definition: cellcache.cpp:1041
CellVisualEffect m_fowType
visual cell status
Definition: cell.h:420
std::vector< Cell * > getCellsInRect(const Rect &rec)
Returns all cells in the rect.
Definition: cellcache.cpp:883
bool isSpecialSpeed()
Returns true if instance or object have special speed modifier otherwise false.
Definition: instance.cpp:1062
A CellCache is an abstract depiction of one or a few layers and contains additional information...
Definition: cellcache.h:111
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:454
void addCellToCost(const std::string &costId, Cell *cell)
Assigns a cell to a cost identifier.
Definition: cellcache.cpp:1021
bool isDefaultCost(Cell *cell)
Gets if cell uses default cost multiplier.
Definition: cellcache.cpp:1160
CellCache * getCellCache()
Returns the CellCache of this layer.
Definition: layer.cpp:573
void setCellType(CellTypeInfo type)
Sets blocker type.
Definition: cell.cpp:499
void setBlockingUpdate(bool update)
Definition: cellcache.cpp:1522
static Logger _log(LM_AUDIO)
void registerCost(const std::string &costId, double cost)
Adds a cost with the given id and value.
Definition: cellcache.cpp:974
void removeInstance(Instance *instance)
Removes a instance from this cell.
Definition: cell.cpp:202
int32_t getCellId()
Returns the cell identifier.
Definition: cell.cpp:511
void resetSpeedMultiplier(Cell *cell)
Resets the speed multiplier for the cell.
Definition: cellcache.cpp:1216
void addChangeListener(CellChangeListener *listener)
Adds new cell change listener.
Definition: cell.cpp:613
bool defaultCost()
Returns if cell use default cost.
Definition: cell.cpp:434
void resetCostMultiplier()
Resets the cell cost to default, 1.0.
Definition: cell.cpp:446
void removeCell(Cell *cell)
Removes a cell from this zone.
Definition: cellcache.cpp:277
void deleteTransition()
Removes the transistion from Cell and CellCache.
Definition: cell.cpp:568
bool isSpecialCost()
Returns true if instance or object have special cost otherwise false.
Definition: instance.cpp:576
void onCellDeleted(Cell *cell)
Called when a cell gets deleted on this cell.
Definition: cell.cpp:603
void removeCellFromArea(Cell *cell)
Removes the cell from all areas.
Definition: cellcache.cpp:1407
void setFowUpdate(bool update)
Definition: cellcache.cpp:1526
#define FL_ERR(logger, msg)
Definition: logger.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
void setZone(Zone *zone)
Sets zone.
Definition: cell.cpp:470
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:519
int32_t m_coordId
holds coordinate as a unique integer id
Definition: cell.h:396
static bool Equal(T _val1, T _val2)
Definition: fife_math.h:287
Object * getObject()
Gets object where this instance is instantiated from.
Definition: instance.cpp:295
Cell * getCell(const ModelCoordinate &mc)
Returns cell on this coordinate.
Definition: cellcache.cpp:706
const std::set< Instance * > & getInstances()
Returns all instances on this cell.
Definition: cell.cpp:503
void addVisitorInstance(Instance *instance)
Adds a instance as visitor to this cell.
Definition: cell.cpp:406
bool isZoneProtected()
Returns whether the zone on this cell is protected.
Definition: cell.cpp:487
uint8_t CellTypeInfo
Definition: cell.h:65
CellTypeInfo getCellType()
Returns blocker type.
Definition: cell.cpp:495
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
const std::vector< Cell * > & getNeighbors()
Returns the layer coordinates of this cell.
Definition: cell.cpp:523
void removeDeleteListener(CellDeleteListener *listener)
Removes cell delete listener.
Definition: cell.cpp:593
A basic cell on a CellCache.
Definition: cell.h:136
unsigned short uint16_t
Definition: core.h:39
T y
The Y Coordinate.
Definition: rect.h:87
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:382
Cell(int32_t coordint, ModelCoordinate coordinate, Layer *layer)
Constructor.
Definition: cell.cpp:42
CellVisualEffect getFoWType()
Returns the cell visual.
Definition: cell.cpp:402
void changeInstance(Instance *instance)
Changes a instance on this cell.
Definition: cell.cpp:198
const ModelCoordinate getLayerCoordinates() const
Returns the layer coordinates of this cell.
Definition: cell.cpp:515
Zone * getZone()
Returns zone.
Definition: cell.cpp:466
VisitorShapeInfo getVisitorShape()
Gets the shape type for a visitor.
Definition: instance.cpp:556
void updateCellBlockingInfo()
Definition: cell.cpp:270
void setFoWType(CellVisualEffect type)
Sets the cell visual.
Definition: cell.cpp:398
void addCellToArea(const std::string &id, Cell *cell)
Adds a cell to a specific area group.
Definition: cellcache.cpp:1396
void setCellId(int32_t id)
Sets the cell identifier.
Definition: cell.cpp:507
void setCostMultiplier(double multi)
Changes the cell cost.
Definition: cell.cpp:438
std::vector< Cell * > getCellsInCircle(const ModelCoordinate &center, uint16_t radius)
Returns all cells in the circle.
Definition: cellcache.cpp:900
ModelCoordinate m_coordinate
holds coordinate
Definition: cell.h:399
CellTypeInfo m_type
CellType.
Definition: cell.h:417
A 3D Point.
Definition: point.h:205
double getCost()
Returns cost value.
Definition: instance.cpp:1044
void updateCellFowInfo()
Definition: cell.cpp:327
void setInserted(bool inserted)
Mark cell as inserted.
Definition: cell.cpp:483
Zone * m_zone
parent Zone
Definition: cell.h:405
void removeCell(Cell *cell)
Removes cell from CellCache.
Definition: cellcache.cpp:721
void removeVisitorInstance(Instance *instance)
Removes the visitor instance from this cell.
Definition: cell.cpp:420
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:544
void resetNeighbors()
Removes all neighbors from cell.
Definition: cell.cpp:527
std::vector< CellDeleteListener * > m_deleteListeners
delete listener
Definition: cell.h:432
bool m_inserted
already inserted
Definition: cell.h:411
void addTransition(Cell *cell)
Adds a cell as transition.
Definition: cellcache.cpp:1220
~Cell()
Destructor.
Definition: cell.cpp:54
TransitionInfo * getTransition()
Returns the transition.
Definition: cell.cpp:585
bool isInserted()
Returns whether the cell is part of a zone.
Definition: cell.cpp:479
uint16_t getVisitorRadius()
Gets the visitor range.
Definition: instance.cpp:564
bool isVisitor()
If instance is a visitor it returns true otherwise false.
Definition: instance.cpp:548
bool defaultSpeed()
Returns if cell use default speed.
Definition: cell.cpp:450
T w
Width of the rectangle.
Definition: rect.h:90
void addDeleteListener(CellDeleteListener *listener)
Adds new cell delete listener.
Definition: cell.cpp:589
void resetZone()
Resets zone.
Definition: cell.cpp:474
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:101
bool m_immediate
use immediate
Definition: cell.h:93
void resetCostMultiplier(Cell *cell)
Resets the cost multiplier for the cell.
Definition: cellcache.cpp:1186
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:617
void setCostMultiplier(Cell *cell, double multi)
Sets cost multiplier for the cell.
Definition: cellcache.cpp:1168
void callOnBlockingChanged(bool blocks)
Called when the blocking property of this cell changed.
Definition: cell.cpp:655
double getSpeed()
Returns speed modifier.
Definition: instance.cpp:1058
void resetSpeedMultiplier()
Resets the cell speed to default, 1.0.
Definition: cell.cpp:462