Esempio n. 1
0
void Map::createRoom(bool first, int x1, int y1, int x2, int y2)
{
  dig (x1,y1,x2,y2);
  if (first)
  {
    // put the player in the first room
    engine.player->x=(x1+x2)/2;
    engine.player->y=(y1+y2)/2;
  } else
  {
    TCODRandom *rng=TCODRandom::getInstance();
    int nbMonsters=rng->getInt(0, MAX_ROOM_MONSTERS);
    while (nbMonsters > 0)
    {
      int x=rng->getInt(x1, x2);
      int y=rng->getInt(y1, y2);
      if (canWalk(x, y))
      {
        addMonster(x,y);
      }
      nbMonsters--;
    }    

    // add items
    int nbItems = rng->getInt(0, MAX_ROOM_ITEMS);
    while (nbItems > 0) {
      int x = rng->getInt(x1, x2);
      int y = rng->getInt(y1, y2);
      if (canWalk(x, y)) {
        addItem(x, y);
      }
      nbItems--;
    }
  }
}
Esempio n. 2
0
void tMap::createRoom(bool first, int x1, int y1, int x2, int y2, bool withActors)
{
    dig (x1,y1,x2,y2);
    if(withActors == true)
    {
        if ( first )
        {
            // put the player in the first room
            engine.m_pPlayer->m_XPosition = (x1 + x2) / 2;
            engine.m_pPlayer->m_YPosition = (y1 + y2) / 2;
        }
        else
        {
            TCODRandom *rng = TCODRandom::getInstance();
            int nbMonsters = rng->getInt(0, MAX_ROOM_MONSTERS);
            while (nbMonsters > 0)
            {
                int x = rng->getInt(x1, x2);
                int y = rng->getInt(y1, y2);
                if ( canWalk(x,y) )
                {
                    addMonster(x,y);
                }
                nbMonsters--;
            }

            int nbItems = rng->getInt(0, MAX_ROOM_ITEMS);
            while(nbItems > 0)
            {
                int x = rng->getInt(x1,x2);
                int y = rng->getInt(y1,y2);
                if(canWalk(x,y))
                {
                    addItem(x,y);
                }
                nbItems--;
            }
        }
    }
}
Esempio n. 3
0
void
Tux::tryContinueWalking(float elapsed_time)
{
  if (!moving)
    return;

  // Let tux walk
  offset += TUXSPEED * elapsed_time;

  // Do nothing if we have not yet reached the next tile
  if (offset <= 32)
    return;

  offset -= 32;

  auto sprite_change = worldmap->at_sprite_change(tile_pos);
  ChangeSprite(sprite_change);

  // if this is a special_tile with passive_message, display it
  auto special_tile = worldmap->at_special_tile();
  if(special_tile)
  {
    // direction and the apply_action_ are opposites, since they "see"
    // directions in a different way
    if((direction == D_NORTH && special_tile->apply_action_south) ||
       (direction == D_SOUTH && special_tile->apply_action_north) ||
       (direction == D_WEST && special_tile->apply_action_east) ||
       (direction == D_EAST && special_tile->apply_action_west))
    {
      process_special_tile(special_tile);
    }
  }

  // check if we are at a Teleporter
  auto teleporter = worldmap->at_teleporter(tile_pos);

  // stop if we reached a level, a WORLDMAP_STOP tile, a teleporter or a special tile without a passive_message
  if ((worldmap->at_level())
      || (worldmap->tile_data_at(tile_pos) & Tile::WORLDMAP_STOP)
      || (special_tile && !special_tile->passive_message
          && special_tile->script.empty())
      || (teleporter) || ghost_mode) {
    if(special_tile && !special_tile->map_message.empty()
       && !special_tile->passive_message)
      worldmap->passive_message_timer.start(0);
    stop();
    return;
  }

  // if user wants to change direction, try changing, else guess the direction in which to walk next
  const int tile_data = worldmap->tile_data_at(tile_pos);
  if ((direction != input_direction) && canWalk(tile_data, input_direction)) {
    direction = input_direction;
    back_direction = reverse_dir(direction);
  } else {
    Direction dir = D_NONE;
    if (tile_data & Tile::WORLDMAP_NORTH && back_direction != D_NORTH)
      dir = D_NORTH;
    else if (tile_data & Tile::WORLDMAP_SOUTH && back_direction != D_SOUTH)
      dir = D_SOUTH;
    else if (tile_data & Tile::WORLDMAP_EAST && back_direction != D_EAST)
      dir = D_EAST;
    else if (tile_data & Tile::WORLDMAP_WEST && back_direction != D_WEST)
      dir = D_WEST;

    if (dir == D_NONE) {
      // Should never be reached if tiledata is good
      log_warning << "Could not determine where to walk next" << std::endl;
      stop();
      return;
    }

    direction = dir;
    input_direction = direction;
    back_direction = reverse_dir(direction);
  }

  // Walk automatically to the next tile
  if(direction == D_NONE)
    return;

  Vector next_tile;
  if (!ghost_mode && !worldmap->path_ok(direction, tile_pos, &next_tile)) {
    log_debug << "Tilemap data is buggy" << std::endl;
    stop();
    return;
  }

  auto next_sprite = worldmap->at_sprite_change(next_tile);
  if(next_sprite != NULL && next_sprite->change_on_touch) {
    ChangeSprite(next_sprite);
  }
  //SpriteChange* last_sprite = worldmap->at_sprite_change(tile_pos);
  if(sprite_change != NULL && next_sprite != NULL) {
    log_debug << "Old: " << tile_pos << " New: " << next_tile << std::endl;
    sprite_change->set_stay_action();
  }

  tile_pos = next_tile;
}
Esempio n. 4
0
 bool Class::isMobile(const MWWorld::Ptr& ptr) const
 {
     return canSwim(ptr) || canWalk(ptr) || canFly(ptr);
 }
Esempio n. 5
0
 bool Class::isPureWaterCreature(const MWWorld::Ptr& ptr) const
 {
     return canSwim(ptr) && !canWalk(ptr);
 }