Esempio n. 1
0
bool Virus::tryTakeoverCell(Cell *cell) {
  bool success = false;

  if (!reproduceCooldown) {
    Mantis::RandomNumberGenerator *randomGenerator =
      Mantis::RandomNumberGenerator::instance();
    
    if (!cell->isTaken()) {
      unsigned char proteinTypes = virusData->getProteinTypes();
      if (proteinTypes & cell->getProteinType()) {
	double p = randomGenerator->getProbability();
	if (p < 0.75) {
	  takenCell = cell;
	  takenCell->notifyInvasion();
	  state = VIRUSSTATE_TAKINGCELL;

	  Tile *previous = map->getTile(position);
	  Tile *current = map->getTile(takenCell->getPosition());
	  previous->removeEntity(this);
	  current->addEntity(this);

	  goTo(takenCell->getPosition());
	  success = true;
	} else {
	  reproduceCooldown = 300;
	}
      }
    }
  }

  return success;
}
Esempio n. 2
0
void    Entity::updateEnclosingTile()
{
    Tile* t = Play_ST::G_viewport.enclosingTile(pos_);

    assert(t != 0);

    if (t != cur_tile_) {
        t->addEntity(this);

        if (cur_tile_ != 0) { // cur_tile_ points to nothing
            // when the game first starts
            cur_tile_->removeEntity(this);
        }

        cur_tile_ = t;
    }
}