Example #1
0
bool mp_linear_step_object(const double x, const double y, const double stepsize, const int object, const bool solid_only)
{
    enigma::object_collisions* const inst = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
    if (fequal(inst->x, x) && fequal(inst->y, y))
        return true;

    inst->direction = atan2(inst->y - y, x - inst->x)*(180/M_PI);
    if (hypot(x - inst->x, y - inst->y) <= stepsize)
    {
        if (solid_only ? (place_free(x, y)) : (!place_meeting(x, y, object)))
        {
            inst->x = x;
            inst->y = y;
            return true;
        }
        return false;
    }

    double xstep, ystep;
    xstep = cos(inst->direction*M_PI/180)*stepsize;
    ystep = -sin(inst->direction*M_PI/180)*stepsize;
    if (solid_only ? (place_free(inst->x + xstep, inst->y + ystep)) : (!place_meeting(inst->x + xstep, inst->y + ystep, object)))
    {
        inst->x += xstep;
        inst->y += ystep;
        return true;
    }
    return false;
}
static void
add_file_chooser_response (GtkDialog *widget,
                           GtkResponseType response,
                           gpointer user_data)
{
  Place *place;
  GPtrArray *new_values;

  if (response != GTK_RESPONSE_OK)
    {
      gtk_widget_destroy (GTK_WIDGET (widget));
      return;
    }

  place = g_slice_new0 (Place);
  place->location = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (widget));
  place->settings_key = TRACKER_KEY_RECURSIVE_DIRECTORIES;
  place->display_name = g_file_get_basename (place->location);

  new_values = place_get_new_settings_values (place, FALSE);
  g_settings_set_strv (tracker_preferences, place->settings_key, (const gchar **) new_values->pdata);

  g_ptr_array_unref (new_values);
  gtk_widget_destroy (GTK_WIDGET (widget));
  place_free (place);
}
Example #3
0
void create_up_stairs(dungeon_t* src, branch_t* to_branch, dungeon_t* to_dungeon, stairs_t* to_stairs)
{
  int stairs_x, stairs_y;

  do
  {
    stairs_x = random(1, src->width - 1);
    stairs_y = random(1, src->height - 1);
  } while (!place_free(src, stairs_x, stairs_y) || stairs_at(src, stairs_x, stairs_y) || (get_tile_at(src, stairs_x, stairs_y)->properties & TILE_PROP_NO_SPAWN));

  to_stairs->to = src;
  to_stairs->warp_x = stairs_x;
  to_stairs->warp_y = stairs_y;

  stairs_t* up = new stairs_t;
  up->to = to_dungeon;
  up->to_branch = to_branch->name;
  up->x = stairs_x;
  up->y = stairs_y;
  up->warp_x = to_stairs->x;
  up->warp_y = to_stairs->y;

  set_tile_at(src, stairs_x, stairs_y, TILES[TILE_STAIRS_UP]);
  src->stairs[src->num_stairs] = up;
  src->num_stairs++;
}
Example #4
0
static void clear(struct mwServicePlace *srvc) {

  if(srvc->handler && srvc->handler->clear)
    srvc->handler->clear(srvc);

  while(srvc->places)
    place_free(srvc->places->data);
}
Example #5
0
void creature_t::blink()
{
  std::vector<coord_t> valid_coords;

  for (int y = pos.y - FOV_RADIUS; y <= pos.y + FOV_RADIUS; y++)
  {
    for (int x = pos.x - FOV_RADIUS; x <= pos.x + FOV_RADIUS; x++)
    {
      if (sees(x, y) && place_free(current_dungeon, x, y, this))
      {
        valid_coords.push_back(coord_t {x, y});
      }
    }
  }

  if (valid_coords.size())
  {
    std::random_shuffle(valid_coords.begin(), valid_coords.end());

    if (identity == IDENT_PLAYER)
    {
      append_msg_log("You feel a wrenching sensation!");
    }

    cloud_create_translocation_effect(pos.x, pos.y);

    coord_t target = valid_coords.front();
    pos = target;

    if (identity != IDENT_PLAYER)
    {
      if (player.sees(this))
      {
        append_msg_log("%s blinks!", capitalize(get_full_name()).c_str());
      }
      else
      {
        append_msg_log("%s suddenly disappears!", capitalize(get_full_name()).c_str());
      }
    }
  }
  else
  {
    if (identity == IDENT_PLAYER)
    {
      append_msg_log("You shudder for a moment.");
    }
    else if (player.sees(this))
    {
      append_msg_log("%s shudders for a moment.", capitalize(get_full_name()).c_str());
    }
  }
}
Example #6
0
bool mp_linear_path_object(int path, const double x, const double y, const double stepsize, const int object, const bool solid_only)
{
    enigma::object_collisions* const inst = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
    double pathpx = inst->x, pathpy = inst->y, pathpdir = atan2(pathpy - y, x - pathpx)*(180/M_PI);
    path_clear_points(path);
    path_add_point(path, pathpx, pathpy, 100);
    if (fequal(pathpx, x) && fequal(pathpy, y))
        return true;

    double xstep, ystep;
    bool pathfound;
    const double max_dist = hypot(x - pathpx, y - pathpy);
    while (path_get_length(path) < max_dist)
    {
        pathfound = false;
        if (hypot(x - pathpx, y - pathpy) <= stepsize)
        {
            if (solid_only ? (place_free(x, y)) : (!place_meeting(x, y, object)))
            {
                path_add_point(path, x, y, 100);
                return true;
            }
            return false;
        }

        xstep = cos(pathpdir*M_PI/180)*stepsize;
        ystep = -sin(pathpdir*M_PI/180)*stepsize;
        if (solid_only ? (place_free(pathpx + xstep, pathpy + ystep)) : (!place_meeting(pathpx + xstep, pathpy + ystep, object)))
        {
            pathpx += xstep;
            pathpy += ystep;
            path_add_point(path, pathpx, pathpy, 100);
            pathfound = true;
        }
        if (!pathfound)
            return false;
    }
    return false;
}
Example #7
0
int mwPlace_destroy(struct mwPlace *p, guint32 code) {
  int ret = 0;

  place_state(p, mwPlace_CLOSING);

  if(p->channel) {
    ret = mwChannel_destroy(p->channel, code, NULL);
    p->channel = NULL;
  }

  place_free(p);

  return ret;
}
Example #8
0
void FireBall::onStep() {
	switch (dir) {
		case UPLEFT:
			y -= sp; x -= sp;
			break;
		case DOWNRIGHT:
			y += sp; x += sp;
			break;
		case DOWNLEFT:
			y += sp; x -= sp;
			break;
		case UPRIGHT:
			y -= sp; x += sp;
			break;
	}
	((SpriteMap*) graphic)->playAnim("shake");

	if (!place_free(x, y)) instance_destroy();

	depth = y;
};
Example #9
0
void creature_t::split_creature()
{
  std::vector<coord_t> valid_coords;

  for (int y = pos.y - 1; y <= pos.y + 1; y++)
  {
    for (int x = pos.x - 1; x <= pos.x + 1; x++)
    {
      if (place_free(current_dungeon, x, y, this))
      {
        valid_coords.push_back(coord_t { x, y });
      }
    }
  }

  if (valid_coords.size())
  {
    std::random_shuffle(valid_coords.begin(), valid_coords.end());
    coord_t pos = valid_coords.front();

    if (player.sees(this))
    {
      append_msg_log("%s multiplies!", capitalize(get_full_name()).c_str());
    }

    creature_t* new_creature = create_creature_by_name(name);
    new_creature->hp = hp;
    new_creature->challenge_rating = 0; // Award no exp for multiplied creature.
    add_creature_to_dungeon(current_dungeon, new_creature, pos.x, pos.y);
  }
  else
  {
    if (player.sees(this))
    {
      append_msg_log("%s jiggles.", capitalize(get_full_name()).c_str());
    }
  }
}
Example #10
0
void create_empty_stairs(dungeon_t* src, const std::string& to_branch)
{
  int src_x, src_y;

  do
  {
    src_x = random(1, src->width - 1);
    src_y = random(1, src->height - 1);
  } while (!place_free(src, src_x, src_y) || stairs_at(src, src_x, src_y) || (get_tile_at(src, src_x, src_y)->properties & TILE_PROP_NO_SPAWN));

  stairs_t* down = new stairs_t;

  down->to = nullptr;
  down->to_branch = to_branch;

  down->x = src_x;
  down->y = src_y;
  down->warp_x = -1;
  down->warp_y = -1;

  set_tile_at(src, src_x, src_y, TILES[TILE_STAIRS_DOWN]);
  src->stairs[src->num_stairs] = down;
  src->num_stairs++;
}
Example #11
0
void creature_t::teleport()
{
  // TODO: Controlled teleport.
  if (identity != IDENT_PLAYER)
  {
    if (player.sees(this))
    {
      MAKE_CAPITAL(prefix, prefix, 8);
      append_msg_log("%s %s teleports away.", prefix, name);
    }
  }

  int x, y;
  do
  {
    x = random(0, current_dungeon->width - 1);
    y = random(0, current_dungeon->height - 1);
  } while (!place_free(current_dungeon, x, y, this));

  cloud_create_translocation_effect(pos.x, pos.y);

  pos.x = x;
  pos.y = y;
}
static GList *
get_places_list (void)
{
  GList *list, *l;
  GHashTable *places;
  Place *place, *old_place;
  GList *places_list;

  places = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, NULL, (GDestroyNotify) place_free);

  /* add home */
  place = g_slice_new0 (Place);
  place->location = g_file_new_for_path (g_get_home_dir ());
  place->place_type = PLACE_XDG;
  place->display_name = g_strdup (_("Home"));
  g_hash_table_insert (places, place->location, place);

  /* first, load the XDG dirs */
  list = get_xdg_dirs ();
  for (l = list; l != NULL; l = l->next)
    {
      place = l->data;
      g_hash_table_insert (places, place->location, place);
    }
  g_list_free (list);

  /* then, insert all the tracker locations that are not XDG dirs */
  list = get_tracker_locations ();
  for (l = list; l != NULL; l = l->next)
    {
      place = l->data;
      old_place = g_hash_table_lookup (places, place->location);
      if (old_place == NULL)
        g_hash_table_insert (places, place->location, place);
      else
        place_free (place);
    }
  g_list_free (list);

  /* finally, load bookmarks, and possibly update attributes */
  list = get_bookmarks ();
  for (l = list; l != NULL; l = l->next)
    {
      place = l->data;
      old_place = g_hash_table_lookup (places, place->location);
      if (old_place == NULL)
        {
          g_hash_table_insert (places, place->location, place);
        }
      else
        {
          g_free (old_place->display_name);
          old_place->display_name = g_strdup (place->display_name);

          if (old_place->place_type == PLACE_OTHER)
            old_place->place_type = PLACE_BOOKMARKS;

          place_free (place);
        }
    }
  g_list_free (list);

  places_list = g_hash_table_get_values (places);
  g_hash_table_steal_all (places);
  g_hash_table_unref (places);

  return places_list;
}
Example #13
0
bool mp_potential_step_object(const double x, const double y, const double stepsize, const int object, const bool solid_only)
{
    enigma::object_collisions* const inst = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
    if (fequal(inst->x, x) && fequal(inst->y, y))
        return true;

    double dir, xstep, ystep, goaldir;
    goaldir = atan2(inst->y - y, x - inst->x)*(180/M_PI);
    dir = (goaldir + 360) %(variant) 360;

    //direct goal direction
    if (abs((dir - inst->direction + 540) %(variant) 360 - 180) <= mp_potential::maxrot)
    {
        if (hypot(x - inst->x, y - inst->y) <= stepsize)
        {
            if (solid_only ? (place_free(x, y)) : (!place_meeting(x, y, object)))
            {
                inst->direction = dir;
                inst->x = x;
                inst->y = y;
                return true;
            }
            if (mp_potential::onspot)
            {
                inst->direction += min(mp_potential::maxrot, max(-mp_potential::maxrot, (goaldir - inst->direction + 540) %(variant) 360 - 180));
            }
            return false;
        }
        xstep = cos(dir*M_PI/180)*stepsize;
        ystep = -sin(dir*M_PI/180)*stepsize;
        if (solid_only ? (place_free(inst->x + mp_potential::ahead*xstep, y + mp_potential::ahead*ystep) && place_free(inst->x + xstep,inst->y + ystep))
                       : (!place_meeting(inst->x + mp_potential::ahead*xstep, y + mp_potential::ahead*ystep, object) && !place_meeting(inst->x + xstep, inst->y + ystep, object)))
        {
            inst->direction = dir;
            inst->x += xstep;
            inst->y += ystep;
            return true;
        }
    }

    //alternate either side of the goal direction full circle
    for (int i = mp_potential::rotstep; i < 180; i += mp_potential::rotstep)
    {
        dir = (goaldir - i + 360) %(variant) 360;
        if (abs((dir - inst->direction + 540) %(variant) 360 - 180) <= mp_potential::maxrot)
        {
            xstep = cos(dir*M_PI/180)*stepsize;
            ystep = -sin(dir*M_PI/180)*stepsize;
            if (solid_only ? (place_free(inst->x + mp_potential::ahead*xstep, y + mp_potential::ahead*ystep) && place_free(inst->x + xstep,inst->y + ystep))
                           : (!place_meeting(inst->x + mp_potential::ahead*xstep, y + mp_potential::ahead*ystep, object) && !place_meeting(inst->x + xstep, inst->y + ystep, object)))
            {
                inst->direction = dir;
                inst->x += xstep;
                inst->y += ystep;
                return true;
            }
        }
        dir = (goaldir + i + 360) %(variant) 360;
        if (abs((dir - inst->direction + 540) %(variant) 360 - 180) <= mp_potential::maxrot)
        {
            xstep = cos(dir*M_PI/180)*stepsize;
            ystep = -sin(dir*M_PI/180)*stepsize;
            if (solid_only ? (place_free(inst->x + mp_potential::ahead*xstep, inst->y + mp_potential::ahead*ystep) && place_free(inst->x + xstep, inst->y + ystep))
                           : (!place_meeting(inst->x + mp_potential::ahead*xstep, inst->y + mp_potential::ahead*ystep, object) && !place_meeting(inst->x + xstep, inst->y + ystep, object)))
            {
                inst->direction = dir;
                inst->x += xstep;
                inst->y += ystep;
                return true;
            }
        }
    }
    if (mp_potential::onspot)
    {
        inst->direction += min(mp_potential::maxrot, max(-mp_potential::maxrot, (goaldir - inst->direction + 540) %(variant) 360 - 180));
    }
    return false;
}
Example #14
0
bool mp_potential_path_object(int path, const double x, const double y, const double stepsize, double factor, const int object, const bool solid_only)
{
    enigma::object_collisions* const inst = ((enigma::object_collisions*)enigma::instance_event_iterator->inst);
    double pathpx = inst->x, pathpy = inst->y, pathpdir = inst->direction;
    path_clear_points(path);
    path_add_point(path, pathpx, pathpy, 100);
    if (fequal(pathpx, x) && fequal(pathpy, y))
        return true;

    if (factor < 1)
        return false;

    double dir, xstep, ystep, goaldir;
    bool pathfound;
    const double max_dist = factor*hypot(x - pathpx, y - pathpy);
    while (path_get_length(path) < max_dist)
    {
        goaldir = atan2(pathpy - y, x - pathpx)*(180/M_PI);
        pathfound = false;

        //direct goal direction
        dir = (goaldir + 360) %(variant) 360;
        if (abs((dir - pathpdir + 540) %(variant) 360 - 180) <= mp_potential::maxrot)
        {
            if (hypot(x - pathpx, y - pathpy) <= stepsize)
            {
                if (solid_only ? (place_free(x, y)) : (!place_meeting(x, y, object)))
                {
                   path_add_point(path, x, y, 100);
                   return true;
                }
                return false;
            }
            xstep = cos(dir*M_PI/180)*stepsize;
            ystep = -sin(dir*M_PI/180)*stepsize;
            if (solid_only ? (place_free(pathpx + mp_potential::ahead*xstep, pathpy + mp_potential::ahead*ystep) && place_free(pathpx + xstep, pathpy + ystep))
                           : (!place_meeting(pathpx + mp_potential::ahead*xstep, pathpy + mp_potential::ahead*ystep, object) && !place_meeting(pathpx + xstep, pathpy + ystep, object)))
            {
                pathpdir = dir;
                pathpx += xstep;
                pathpy += ystep;
                path_add_point(path, pathpx, pathpy, 100);
                pathfound = true;
            }
        }

        if (!pathfound)
        {
            //alternate either side of the goal direction full circle
            for (int i = mp_potential::rotstep; i < 180; i += mp_potential::rotstep)
            {
                dir = (goaldir - i + 360) %(variant) 360;
                if (abs((dir - pathpdir + 540) %(variant) 360 - 180) <= mp_potential::maxrot)
                {
                    xstep = cos(dir*M_PI/180)*stepsize;
                    ystep = -sin(dir*M_PI/180)*stepsize;
                    if (solid_only ? (place_free(pathpx + mp_potential::ahead*xstep, pathpy + mp_potential::ahead*ystep) && place_free(pathpx + xstep, pathpy + ystep))
                                   : (!place_meeting(pathpx + mp_potential::ahead*xstep, pathpy + mp_potential::ahead*ystep, object) && !place_meeting(pathpx + xstep, pathpy + ystep, object)))
                    {
                        pathpdir = dir;
                        pathpx += xstep;
                        pathpy += ystep;
                        path_add_point(path, pathpx, pathpy, 100);
                        pathfound = true;
                        break;
                    }
                }
                dir = (goaldir + i + 360) %(variant) 360;
                if (abs((dir - pathpdir + 540) %(variant) 360 - 180) <= mp_potential::maxrot)
                {
                    xstep = cos(dir*M_PI/180)*stepsize;
                    ystep = -sin(dir*M_PI/180)*stepsize;
                    if (solid_only ? (place_free(pathpx + mp_potential::ahead*xstep, pathpy + mp_potential::ahead*ystep) && place_free(pathpx + xstep, pathpy + ystep))
                                   : (!place_meeting(pathpx + mp_potential::ahead*xstep, pathpy + mp_potential::ahead*ystep, object) && !place_meeting(pathpx + xstep, pathpy + ystep, object)))
                    {
                        pathpdir = dir;
                        pathpx += xstep;
                        pathpy += ystep;
                        path_add_point(path, pathpx, pathpy, 100);
                        pathfound = true;
                        break;
                    }
                }
            }
            if (!pathfound)
                return false;
        }
    }
    return false;
}
Example #15
0
void _take_stairs(stairs_t* stairs)
{
    dungeon_t* prev_dungeon = current_dungeon;

    TRACE("take_stairs: stairs->to_branch=%s", stairs->to_branch.c_str());

    // Arrive from town to infinite dungeon: clear infinite dungeon.
    if (stairs->to && stairs->to_branch == BRANCH_INFINITE_DUNGEON && current_branch->name != BRANCH_INFINITE_DUNGEON)
    {
        stairs->to = nullptr;
        branch_t* inf_branch = find_branch(stairs->to_branch);

        for (dungeon_t* dungeon : inf_branch->dungeons)
        {
            destroy_dungeon(dungeon);
        }
        inf_branch->dungeons.clear();
    }

    // Generate the next dungeon if needed.
    if (stairs->to == nullptr && stairs->to_branch == current_branch->name)
    {
        dungeon_t* next_level = generate_next_level(current_branch);
        create_up_stairs(next_level, current_branch, prev_dungeon, stairs);
    }
    else if (stairs->to == nullptr)
    {
        // Stairs to a new branch.
        branch_t* prev_branch = current_branch;
        current_branch = create_branch(stairs->to_branch);

        dungeon_t* next_level = current_branch->dungeons.front();

        // Check if the level has stairs that lead back to the branch already.
        bool has_stairs = false;
        for (int i = 0; i < next_level->num_stairs; i++)
        {
            if (next_level->stairs[i]->to_branch == prev_branch->name)
                has_stairs = true;
        }

        if (!has_stairs)
            create_up_stairs(next_level, prev_branch, prev_dungeon, stairs);
        else
            stairs->to = next_level;
    }

    dungeon_t* dst = stairs->to;
    current_dungeon = dst;
    current_branch = find_branch(stairs->to_branch);

    player.pos.x = stairs->warp_x;
    player.pos.y = stairs->warp_y;

    // Do not follow player to the world map.
    if (current_branch->name != "World")
    {
        std::vector<coord_t> free_coords;
        for (int y = player.pos.y - 1; y <= player.pos.y + 1; y++)
            for (int x = player.pos.x - 1; x <= player.pos.x + 1; x++)
                if (place_free(current_dungeon, x, y))
                    free_coords.push_back( coord_t { x, y} );

        std::vector<creature_t*> following_creatures;
        for (int y = stairs->y - 1; y <= stairs->y + 1; y++)
        {
            for (int x = stairs->x - 1; x <= stairs->x + 1; x++)
            {
                creature_t* creature = get_creature_at(prev_dungeon, x, y);

                if (creature && following_creatures.size() < free_coords.size())
                {
                    following_creatures.push_back(creature);
                    remove_creature_no_destroy(prev_dungeon, creature);
                }
            }
        }

        for (size_t i = 0; i < following_creatures.size(); i++)
        {
            add_creature_to_dungeon(current_dungeon, following_creatures[i], free_coords[i].x, free_coords[i].y);
        }

        if (following_creatures.size() == 1)
            append_msg_log("%s follows you.", capitalize(following_creatures.front()->get_full_name()).c_str());
        else if (following_creatures.size() > 1)
            append_msg_log("Some creatures follow you.");
    }

    clear_action_list();
    append_action_list(&player);
}
Example #16
0
void _select_direction()
{
    const std::string move_keys = "lkjhyubn12346789";
    int state = statestack_top();

    char key = io::getchar();

    if (char_in(key, move_keys))
    {
        if (state == STATE_CLOSE_DOOR)
        {
            int x, y;
            x = player.pos.x;
            y = player.pos.y;

            compute_xy_by_direction(direction_from_key(key), &x, &y);

            tile_t* tile = get_tile_at(current_dungeon, x, y);
            if (tile->id == TILE_DOOR_OPEN)
            {
                if (place_free(current_dungeon, x, y)
                        && count_items_at(current_dungeon, x, y) == 0)
                {
                    close_door(current_dungeon, &player, x, y);
                    player.ap -= player.speed;
                }
                else
                {
                    append_msg_log("The door is blocked!");
                }
            }
            else if (tile->id == TILE_DOOR_CLOSED)
            {
                append_msg_log("That door is already closed.");
            }
            else
            {
                append_msg_log("There is no door there!");
            }
            statestack_pop();
        }
        else if (state == STATE_CHAT)
        {
            int x = player.pos.x;
            int y = player.pos.y;

            compute_xy_by_direction(direction_from_key(key), &x, &y);
            creature_t* creature = get_creature_at(current_dungeon, x, y);

            if (creature)
            {
                chat(creature);
            }
            else
            {
                append_msg_log("There is no one there to talk to!");
            }

            statestack_pop();
        }

        return;
    }

    if (key == '\x1B')
    {
        append_msg_log("Nevermind.");
        statestack_pop();
    }
}