Ejemplo n.º 1
0
double Map::cast(Player* player, double angle, double dist) {
    double x = player->x;
    double y = player->y;
    double dx = cos(angle);
    double dy = sin(angle);
    while (distance(player->x, player->y, x, y) < dist) {
        double next_x = round(x, dx);
        double next_y = round(y, dy);
        if ((next_x - x)/dx > (next_y - y)/dy) {
            x += ((next_y - y)/dy) * dx;
            y = next_y;
            double curr_dist = distance(player->x, player->y, x, y);
            if (curr_dist < dist && wallgrid[(int)(floor(x) + size*y)] == 1 &&
                    wallgrid[(int)(ceil(x) + size*y)] == 1 &&
                    in_bounds(floor(x), y) && in_bounds(ceil(x), y)) {
                return curr_dist;
            }
        } else {
            y += ((next_x - x)/dx) * dy;
            x = next_x;
            double curr_dist = distance(player->x, player->y, x, y);
            if (curr_dist < dist && wallgrid[(int)(x + size*floor(y))] == 1 &&
                    wallgrid[(int)(x + size*ceil(y))] == 1 &&
                    in_bounds(floor(x), y) && in_bounds(ceil(x), y)) {
                return curr_dist;
            }
        }
    }
    return INFINITY;
}
/*
 * Count the number of walls adjacent to the given grid.
 *
 * Note -- Assumes "in_bounds(y, x)"
 *
 * We count only granite walls and permanent walls.
 */
static int next_to_walls(int y, int x)
{
    int k = 0;

    if (in_bounds(y + 1, x) && is_extra_bold(y + 1, x)) k++;
    if (in_bounds(y - 1, x) && is_extra_bold(y - 1, x)) k++;
    if (in_bounds(y, x + 1) && is_extra_bold(y, x + 1)) k++;
    if (in_bounds(y, x - 1) && is_extra_bold(y, x - 1)) k++;

    return (k);
}
Ejemplo n.º 3
0
/*!
 * @brief モンスターにとって所定の地点が召還に相応しい地点かどうかを返す。 /
 * Determine if there is a space near the player in which a summoned creature can appear
 * @param y1 判定を行いたいマスのY座標
 * @param x1 判定を行いたいマスのX座標
 * @return 召還に相応しいならばTRUEを返す
 */
bool summon_possible(int y1, int x1)
{
	int y, x;

	/* Start at the player's location, and check 2 grids in each dir */
	for (y = y1 - 2; y <= y1 + 2; y++)
	{
		for (x = x1 - 2; x <= x1 + 2; x++)
		{
			/* Ignore illegal locations */
			if (!in_bounds(y, x)) continue;

			/* Only check a circular area */
			if (distance(y1, x1, y, x)>2) continue;

			/* ...nor on the Pattern */
			if (pattern_tile(y, x)) continue;

			/* Require empty floor grid in line of projection */
			if (cave_empty_bold(y, x) && projectable(y1, x1, y, x) && projectable(y, x, y1, x1)) return (TRUE);
		}
	}

	return FALSE;
}
Ejemplo n.º 4
0
int mobility_list(position_t *p, color_t color, square_t* laser_list, int laser_list_len, full_board_t* board) {
  int mobility = 0;
  square_t king_sq = board->pieces[color][0];
  mobility++;

  for (int i = 0; i < laser_list_len-1; i++){
    square_t start = laser_list[i];
    square_t end = laser_list[i+1];
    //check if the square is between laser_list[i] and laser_list[i+1]. if so add to mobility
    if(between(rnk_of(king_sq), rnk_of(start), rnk_of(end)) && between(fil_of(king_sq), fil_of(start), fil_of(end))) {
      mobility--;
      break;
    }
  }
  for (int d = 0; d < 8; ++d) {
    square_t sq = king_sq + dir_of(d);
    if (in_bounds(sq)) {
      mobility++;
      //decrement if it is in laser path
      for (int i = 0; i < laser_list_len-1; i++){
      //check if the square is between laser_list[i] and laser_list[i+1]. if so add to mobility
        square_t start = laser_list[i];
        square_t end = laser_list[i+1];

        if(between(rnk_of(sq), rnk_of(start), rnk_of(end)) && between(fil_of(sq), fil_of(start), fil_of(end))) {
          mobility--;
          break;
        }
      }
    }
  }
  return mobility;
}
Ejemplo n.º 5
0
static void _excavation_spell(int cmd, variant *res)
{
    switch (cmd)
    {
    case SPELL_NAME:
        var_set_string(res, "Excavation");
        break;
    case SPELL_DESC:
        var_set_string(res, "You break walls on your quest for treasure!  This takes a bit more time, though.");
        break;
    case SPELL_ENERGY:
        {
            int n = 200;
            
            if (equip_find_object(TV_DIGGING, SV_ANY))
                n -= 120 * p_ptr->lev / 50;
            else
                n -= 80 * p_ptr->lev / 50;

            var_set_int(res, n);
        }
        break;
    case SPELL_CAST:
        {
            int dir = 5;
            bool b = FALSE;

            if ( get_rep_dir2(&dir)
              && dir != 5 )
            {
                int x, y;
                y = py + ddy[dir];
                x = px + ddx[dir];

                if (!in_bounds(y, x))
                {
                    msg_print("You may excavate no further.");
                }
                else if ( cave_have_flag_bold(y, x, FF_WALL)
                       || cave_have_flag_bold(y, x, FF_TREE) 
                       || cave_have_flag_bold(y, x, FF_CAN_DIG) )
                {
                    msg_print("You dig your way to treasure!");
                    cave_alter_feat(y, x, FF_TUNNEL);
                    teleport_player_to(y, x, TELEPORT_NONMAGICAL); /*??*/
                    b = TRUE;
                }
                else
                {
                    msg_print("There is nothing to excavate.");
                }
            }
            var_set_bool(res, b);
        }
        break;
    default:
        default_spell(cmd, res);
        break;
    }
}
Ejemplo n.º 6
0
/*
 * Get the indexes of effects at a given effects grid.
 *
 * Return the number of effect indexes acquired.
 *
 * Never acquire more than "size" object indexes, and never return a
 * number bigger than "size", even if more floor objects exist.
 *
 */
int scan_effects_grid(int *effects, int size, int y, int x)
{
	int this_x_idx, next_x_idx;

	int num = 0;

	/* Sanity */
	if (!in_bounds(y, x)) return (0);

	/* Scan all effects in the grid */
	for (this_x_idx = cave_x_idx[y][x]; this_x_idx; this_x_idx = next_x_idx)
	{
		effect_type *x_ptr;

		/* Get the effect */
		x_ptr = &x_list[this_x_idx];

		/* Get the next effect */
		next_x_idx = x_ptr->next_x_idx;

		/* Accept this item */
		effects[num++] = this_x_idx;

		/* Enforce size limit */
		if (num >= size) break;
	}

	/* Result */
	return (num);
}
Ejemplo n.º 7
0
void Map::set_maze_wallgrid(int* mazegrid, int size) {
    int WIDTH = 5;
    int OFFSET = WIDTH/2 + size*WIDTH*(WIDTH/2);
    this->wallgrid = new int[(int) pow(size*WIDTH, 2)];
    this->size = size*WIDTH;
    //Mark the borders with walls
    for (int i = 0; i < size*WIDTH; i++) {
        wallgrid[i] = 1;
        wallgrid[WIDTH*size*i] = 1;
        wallgrid[size*WIDTH*(size*WIDTH - 1) + i] = 1;
        wallgrid[WIDTH*size*i + (size*WIDTH - 1)] = 1;
    }
    //Draw a wall between each 0 and 1 in the grid
    for (int i = 0; i < size*size; i++) {
        int x = i % size;
        int y = i / size;
        for (int j = -3; j <= 3; j += 2) {
            int x_offset = fmod(j, 3);
            int y_offset = j / 3;
            int curr_x = x + x_offset;
            int curr_y = y + y_offset;
            if (in_bounds(curr_x, curr_y) && mazegrid[i] != mazegrid[curr_x + curr_y*size]) {
                for (int k = 0; k <= WIDTH/2 + 1; k++) {
                    wallgrid[OFFSET + (x*WIDTH + x_offset*(WIDTH/2)) + (y*WIDTH + y_offset*(WIDTH/2))*size*WIDTH + k*(x_offset*size*WIDTH + y_offset)] = 1;
                    wallgrid[OFFSET + (x*WIDTH + x_offset*(WIDTH/2)) + (y*WIDTH + y_offset*(WIDTH/2))*size*WIDTH - k*(x_offset*size*WIDTH + y_offset)] = 1;
                }
            }
        }
    }
}
Ejemplo n.º 8
0
/**
 * Hack -- Check for a "known wall" (see below)
 */
static int see_wall(int dir, int y, int x)
{
    feature_type *f_ptr;

    /* Get the new location */
    y += ddy[dir];
    x += ddx[dir];

    /* Illegal grids are not known walls XXX XXX XXX */
    if (!in_bounds(y, x))
	return (FALSE);

    f_ptr = &f_info[cave_feat[y][x]];

    /* Non-wall grids are not known walls */
    if (!tf_has(f_ptr->flags, TF_WALL))
	return (FALSE);

    /* Unknown walls are not known walls */
    if (!cave_has(cave_info[y][x], CAVE_MARK))
	return (FALSE);

    /* Default */
    return (TRUE);
}
static void _cavern_creation_spell(int cmd, variant *res)
{
    switch (cmd)
    {
    case SPELL_NAME:
        var_set_string(res, "Cavern Creation");
        break;
    case SPELL_DESC:
        var_set_string(res, "Stone to Mud all surrounding walls.");
        break;
    case SPELL_CAST:
    {
        int dir, x, y, ct = 0;
        for (dir = 0; dir < 8; dir++)
        {
            y = py + ddy_ddd[dir];
            x = px + ddx_ddd[dir];

            if (!in_bounds(y, x)) continue;
            if (!cave_have_flag_bold(y, x, FF_HURT_ROCK))  continue;
            cave_alter_feat(y, x, FF_HURT_ROCK);
            ct++;
        }
        if (ct)
            p_ptr->update |= (PU_FLOW | PU_BONUS);

        var_set_bool(res, TRUE);
        break;
    }
    default:
        default_spell(cmd, res);
        break;
    }
}
Ejemplo n.º 10
0
static bool _elemental_healing(int flag)
{
    int dir, ct = 0;

    if (!cave_have_flag_bold(py, px, flag))
    {
        msg_print("Failed! You are out of your element!");
        return FALSE;
    }

    for (dir = 0; dir < 8; dir++)
    {
        int x = px + ddx_ddd[dir];
        int y = py + ddy_ddd[dir];
        
        if (!in_bounds(y, x)) continue;
        if (cave_have_flag_bold(y, x, flag)) ct++;
    }

    if (ct < 4)
    {
        msg_print("Failed! You need to be surrounded by your element!");
        return FALSE;
    }

    msg_print("You bask in your element and slowly feel your life returning ... ");
    hp_player(100 + p_ptr->lev * 3);
    return TRUE;
}
GArray *
available_squares(Level world, EntitySet * others)
{
	unsigned int i;
	unsigned int j;
	float fi, fj;
	GArray * available;

	unsigned int * coord;

	available = g_array_new(FALSE, FALSE, sizeof(unsigned int *)); 

	for (i = 0; i < level_width; i++)
	{
		for (j = 0; j < level_height; j++)
		{
			fi = (float) i;
			fj = (float) j;
			if (in_bounds(world, fi, fj) && NULL == collision(NULL, fi, fj, others))
			{
				coord = (unsigned int *) zone(sizeof(int) * 2);
				coord[0] = i;
				coord[1] = j;
				g_array_append_val(available, coord);
			}
		}
	}

	return available;
}
Ejemplo n.º 12
0
/* Always insert into root (first).
   If you insert into another node,
   you're a dick. */
bool QTnode::insert(Particle p)
{
  int i;
  bool inserted;

  inserted = false;

  if (in_bounds(p)) {
    if (children.size() == 0) {
      /* If we are at a leaf node. Just insert. */
      particles.push_back(p);
      psize++;
      inserted = true;
    } else {
      /* Otherwise, see if you can store in a child. */
      for (i = 0; i < children.size(); i++) {
        if (children[i]->in_bounds(p)) {
          inserted = children[i]->insert(p);
          break;
        }
      }
    }
  } else {
    /* You are at a singularity. YOLO. */
    return false;
  }

  /* If you inserted a particle into your child,
     then re-calculate your number of particles. */
  if (inserted) {
    recalc_num_particles();
  }

  return inserted;
}
Ejemplo n.º 13
0
/**
 * Deletes the monster, if any, at the given location.
 */
void delete_monster(int y, int x)
{
	assert(in_bounds(y, x));

	/* Delete the monster (if any) */
	if (cave->m_idx[y][x] > 0)
		delete_monster_idx(cave->m_idx[y][x]);
}
Ejemplo n.º 14
0
/*
 * Delete the monster, if any, at a given location
 */
void delete_monster(int y, int x)
{
	/* Paranoia */
	if (!in_bounds(y, x)) return;

	/* Delete the monster (if any) */
	if (cave.m_idx[y][x] > 0) delete_monster_idx(cave.m_idx[y][x]);
}
Ejemplo n.º 15
0
Archivo: misc.c Proyecto: evanlev/cpd
/* returns if samples is in bounds */
int in_bounds( const long D, long *sample, const long *dims ){
    if( D == 1 ){
        return (sample[0] >= 0 && sample[0] < dims[0]);
    }else{
        return (sample[0] >= 0 && sample[0] < dims[0])
                  && in_bounds(D-1, &sample[1], &dims[1]);
    }
}
Ejemplo n.º 16
0
static bool _place_web(int y, int x)
{
    if (!in_bounds(y, x))
        return FALSE;
    if (!cave_clean_bold(y,x) || cave[y][x].m_idx)
        return FALSE;
    cave_set_feat(y, x, feat_web);
    return TRUE;
}
Ejemplo n.º 17
0
/*
 * Attempt to place an object (normal or good/great) at the given location.
 *
 * This routine plays nasty games to generate the "special artifacts".
 *
 * This routine uses "object_level" for the "generation level".
 *
 * This routine requires a clean floor grid destination.
 */
void place_object(s32b y, s32b x, bool good, bool great, s32b where)
{
	object_type *q_ptr;


	/* Paranoia -- check bounds */
	if (!in_bounds(y, x)) return;

	/* Require clean floor space */
	if (!cave_clean_bold(y, x)) return;


	/* Get local object */
	q_ptr = make_object(good, great, NULL);

	/* Make an object (if possible) */
	if (q_ptr == NULL)
		return;

	if (where == OBJ_FOUND_VAULT)
	{
		q_ptr->found = OBJ_FOUND_VAULT;
		q_ptr->found_aux1 = dungeon_type;
		q_ptr->found_aux2 = level_or_feat(dungeon_type, dun_level);
	}
	else if (where == OBJ_FOUND_FLOOR)
	{
		q_ptr->found = OBJ_FOUND_FLOOR;
		q_ptr->found_aux1 = dungeon_type;
		q_ptr->found_aux2 = level_or_feat(dungeon_type, dun_level);
	}
	else if (where == OBJ_FOUND_SPECIAL)
	{
		q_ptr->found = OBJ_FOUND_SPECIAL;
	}
	else if (where == OBJ_FOUND_RUBBLE)
	{
		q_ptr->found = OBJ_FOUND_RUBBLE;
	}

	/* Object array overflow */
	if (!floor_carry(y, x, q_ptr))
	{
		/* Hack -- Preserve artifacts */
		if (q_ptr->artifact_id)
		{
			a_info[q_ptr->artifact_id].cur_num = 0;
		}
		else if (has_flag(&k_info[q_ptr->k_idx], FLAG_NORM_ART))
		{
			k_info[q_ptr->k_idx].artifact = 0;
		}

		delete_object(q_ptr);
	}
}
Ejemplo n.º 18
0
/*
 * Create up to "num" objects near the given coordinates
 * Only really called by some of the "vault" routines.
 */
void vault_objects(int y, int x, int num)
{
    int dummy = 0;
    int i = 0, j = y, k = x;

    cave_type *c_ptr;


    /* Attempt to place 'num' objects */
    for (; num > 0; --num)
    {
        /* Try up to 11 spots looking for empty space */
        for (i = 0; i < 11; ++i)
        {
            /* Pick a random location */
            while (dummy < SAFE_MAX_ATTEMPTS)
            {
                j = rand_spread(y, 2);
                k = rand_spread(x, 3);
                dummy++;
                if (!in_bounds(j, k)) continue;
                break;
            }


            if (dummy >= SAFE_MAX_ATTEMPTS)
            {
                if (cheat_room)
                {
                    msg_print("Warning! Could not place vault object!");

                }
            }


            /* Require "clean" floor space */
            c_ptr = &cave[j][k];
            if (!is_floor_grid(c_ptr) || c_ptr->o_idx) continue;

            /* Place an item */
            if (randint0(100) < 75)
            {
                place_object(j, k, 0L);
            }

            /* Place gold */
            else
            {
                place_gold(j, k);
            }

            /* Placement accomplished */
            break;
        }
    }
}
Ejemplo n.º 19
0
/*
 * Returns random co-ordinates for player/monster/object
 */
bool new_player_spot(void)
{
    int    y = 0, x = 0;
    int max_attempts = 10000;

    cave_type *c_ptr;
    feature_type *f_ptr;

    /* Place the player */
    while (max_attempts--)
    {
        /* Pick a legal spot */
        y = rand_range(1, cur_hgt - 2);
        x = rand_range(1, cur_wid - 2);

        c_ptr = &cave[y][x];

        /* Must be a "naked" floor grid */
        if (c_ptr->m_idx) continue;
        if (dun_level)
        {
            f_ptr = &f_info[c_ptr->feat];

            if (max_attempts > 5000) /* Rule 1 */
            {
                if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
            }
            else /* Rule 2 */
            {
                if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
                if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
            }

            /* Refuse to start on anti-teleport grids in dungeon */
            if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
        }
        if (!player_can_enter(c_ptr->feat, 0)) continue;
        if (!in_bounds(y, x)) continue;

        /* Refuse to start on anti-teleport grids */
        if (c_ptr->info & (CAVE_ICKY)) continue;

        /* Done */
        break;
    }

    if (max_attempts < 1) /* Should be -1, actually if we failed... */
        return FALSE;

    /* Save the new player grid */
    py = y;
    px = x;

    return TRUE;
}
Ejemplo n.º 20
0
//ask the user for a play
void get_play(Board board) {
	int enter_row, enter_col;
	while(1){ //while still true, keep going through this loop
		printf("Enter row a row between 0-%d and a column between 0-%d: ", board.row - 1, board.col - 1);
		scanf("%d %d", &enter_row, &enter_col);
		enter_row = board.row - enter_row - 1;
		if (in_bounds(board, enter_row, enter_col)) {
			if (board.tile[enter_row][enter_col].revealed == '!') {
				if (option_2(board, enter_row, enter_col)) {
					break;
				}
				else {
					continue;
				}
			}
			else if (board.tile[enter_row][enter_col].revealed == '?') {
				if (option_3(board, enter_row, enter_col)) {
					break;
				}
				else {
					continue;
				}
			}
			else if (board.tile[enter_row][enter_col].revealed == '#') {
				if (option_1(board, enter_row, enter_col)) {
					reveal_board(board, enter_row, enter_col, 0); 
					break;
				}
				else {
					continue;
				}
			}
			else {
				printf("This tile is already revealed.\n");
				continue;
			}
		}
		else {
			continue;
		}
	}
	if (check_win(board)) {
			print_board(board);
			printf("You Won!!\n");
			exit (0); //end the program because the game is over and the user has lost 
	}

	if (isgameover(board)) {
			print_board(board);
			printf("You Lost :(\n");
			exit(0); //end the program because the game is over and the user has lost
	}
	return;
}
Ejemplo n.º 21
0
void reset_button_action(GameState * state) {
	Mouse * mouse = &state->mouse;
	Button * buttons = state->hud.buttons;
	int i;

	for (i = 0; i < BUTTON_AMOUNT; i++) {
		if (in_bounds(mouse->screen_x, mouse->screen_y, buttons[i].bounds)) {
			buttons[i].state = BUTTON_UP;
		}
	}
}
Ejemplo n.º 22
0
/* Find the next codel following the DP. next contains the current
 * codel and will be changed. Return true if the codel is in the
 * program.. */
static int get_next_codel_dp(struct codel *next)
{
	switch(interp.dp) {
	case 0: next->x++; break;
	case 1: next->y++; break;
	case 2: next->x--; break;
	case 3: next->y--; break;
	default: abort();
	}

	return in_bounds(next);
}
Ejemplo n.º 23
0
void nested_mpi::choose_step(){

  double val=1;
  do {
    dice.generate_ellipse();
    for (int i=0;i<nb_var;++i) 
      trial_vector[i]=dice.get_value(i)+ave_cov[i];
    if (in_bounds(trial_vector) != -FLT_MAX)
      if (log_prior(trial_vector) != -FLT_MAX)
        if (log(statistics::random_2()) <= (log_prior(trial_vector))) val=0;
  } while (val == 1); 
}
Ejemplo n.º 24
0
bool quest_poison_drop_hook(char *fmt)
{
	s32b mcnt = 0, i, x, y, o_idx;
	object_type *o_ptr;

	o_idx = get_next_arg(fmt);
	o_ptr = &p_ptr->inventory[o_idx];

	if (cquest.status != QUEST_STATUS_TAKEN) return FALSE;
	if (p_ptr->wilderness_y != wild_locs[cquest.data[0]][0]) return FALSE;
	if (p_ptr->wilderness_x != wild_locs[cquest.data[0]][1]) return FALSE;
	if (p_ptr->wild_mode) return FALSE;

	if (o_ptr->tval != TV_POTION2) return FALSE;
	if (o_ptr->sval != SV_POTION2_CURE_WATER) return FALSE;

	for (i = m_max - 1; i >= 1; i--)
	{
		/* Access the monster */
		monster_type *m_ptr = &m_list[i];

		/* Ignore "dead" monsters */
		if (!m_ptr->r_idx) continue;

		if (m_ptr->status <= MSTATUS_NEUTRAL) mcnt++;
	}

	if (mcnt < 10)
	{
		for (x = 1; x < cur_wid - 1; x++)
			for (y = 1; y < cur_hgt - 1; y++)
			{
				if (!in_bounds(y, x)) continue;

				if (cave[y][x].feat == FEAT_TAINTED_WATER) cave_set_feat(y, x, FEAT_SHAL_WATER);
			}

		cmsg_print(TERM_YELLOW, "Well done! The water seems to be clean now.");

		cquest.status = QUEST_STATUS_COMPLETED;

		del_hook(HOOK_DROP, quest_poison_drop_hook);
		process_hooks_restart = TRUE;

		return FALSE;
	}
	else
	{
		msg_print("There are too many monsters left to cure the water.");
		return TRUE;
	}
	return FALSE;
}
Ejemplo n.º 25
0
struct cpi_disp_font *
cpi_get_disp_font (cpi_handle_t *handle, 
  struct cpi_entry *entry, int rows, int cols)
{
  int i;
  long p;
  struct cpi_font_info *info;
  struct cpi_disp_font *font;
  
  if (!in_bounds (handle, entry->font_info_ptr))
  {
    ERROR ("cpi_get_disp_font: font info out of bounds!\n");
    return NULL;
  }
  
  info = (struct cpi_font_info *) ((handle->font_is_nt ? 
    (void *) entry + sizeof (struct cpi_entry) : 
      handle->cpi_file + entry->font_info_ptr));
  p = (long) info + sizeof (struct cpi_font_info);
  
  for (i = 0; i < info->font_no; i++)
  {
    if (!in_bounds (handle, p - (long) handle->cpi_file))
    {
      ERROR ("cpi_get_disp_font: font 0x%lx (%d) out of bounds!\n", 
        p, i);
      return NULL;
    }
    
    font = (struct cpi_disp_font *) p;
    
    if (font->cols == cols && font->rows == rows)
      return font;
        
    p += sizeof (struct cpi_disp_font) + 
      BITS2BYTES (font->chars * font->rows * font->cols);
  }
  
  return NULL;
}
Ejemplo n.º 26
0
/* Function that sees if a square is a floor.  (Includes range checking.) */
bool get_is_floor(int x, int y)
{
    if (!in_bounds(y, x))
    {
        /* Out of bounds */
        return (FALSE);
    }

    /* Do the real check */
    if (is_floor_bold(y, x)) return (TRUE);

    return (FALSE);
}
Ejemplo n.º 27
0
/*
 * Builds the entire set of neighborlists for all particles during the first iteration
 *
 * arguments:
 *      particles:  The spatially decomposed particle information
 *      neighbors:  The array of all neighbor lists
 *      my_rank:    The rank of the node
 */
void build_neighbor_lists_initial(Particle* particles[XDiv][YDiv][ZDiv], Neighbor** neighbors, int my_rank){
    int x, y, z, i;
    Particle p;
    
    int tag = 0;
    int rank = my_rank;
    for (x = node_boundries[rank][0]; x <= node_boundries[rank][1]; ++x){
        for (y = node_boundries[rank][2]; y <= node_boundries[rank][3]; ++y){
            for (z = node_boundries[rank][4]; z <= node_boundries[rank][5]; ++z){
                if(in_bounds(x, XDiv) && in_bounds(y, YDiv) && in_bounds(z, ZDiv)){
#pragma omp for private(p)
                    for (i = 0; i < block_size; ++i){
                        p = particles[x][y][z][i];
                        if (p.index != -1) {
                            build_list_full(particles, neighbors[tag + i], x, y, z, i);
                        }
                    }
                    tag = tag + block_size;
                }
            }
        }
    }
}
Ejemplo n.º 28
0
void set_button_hover_state(GameState * state) {
	int i;
	Button * buttons = state->hud.buttons;
	Mouse * mouse = &state->mouse;

	for (i = 0; i < BUTTON_AMOUNT; i++) {
		if (in_bounds(mouse->screen_x, mouse->screen_y, buttons[i].bounds)) {
			buttons[i].state = BUTTON_HOVER;
		} 
		else {
			buttons[i].state = BUTTON_UP;
		}
	}
}
Ejemplo n.º 29
0
/*
 * Put trees near a hole in the dungeon roof  (rubble on ground + up stairway)
 * This happens in real world lava tubes.
 */
void place_trees(int x, int y)
{
    int i, j;
    cave_type *c_ptr;

    /* place trees/ rubble in ovalish distribution */
    for (i = x - 3; i < x + 4; i++)
    {
        for (j = y - 3; j < y + 4; j++)
        {
            if (!in_bounds(j, i)) continue;
            c_ptr = &cave[j][i];

            if (c_ptr->info & CAVE_ICKY) continue;
            if (c_ptr->o_idx) continue;

            /* Want square to be in the circle and accessable. */
            if ((distance(j, i, y, x) < 4) && !cave_perma_grid(c_ptr))
            {
                /*
                 * Clear previous contents, add feature
                 * The border mainly gets trees, while the center gets rubble
                 */
                if ((distance(j, i, y, x) > 1) || (randint1(100) < 25))
                {
                    if (randint1(100) < 75)
                        cave[j][i].feat = feat_tree;
                }
                else
                {
                    cave[j][i].feat = feat_rubble;
                }

                /* Clear garbage of hidden trap or door */
                c_ptr->mimic = 0;

                /* Light area since is open above */
                if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[j][i].info |= (CAVE_GLOW | CAVE_ROOM);
            }
        }
    }

    /* No up stairs in ironman mode */
    if (!ironman_downward && one_in_(3))
    {
        /* up stair */
        cave[y][x].feat = feat_up_stair;
    }
}
Ejemplo n.º 30
0
/*
 * Create a feature near the player.
 */
static void do_cmd_wiz_feature(int feat)
{
	int px = p_ptr->px;
	int py = p_ptr->py;

	int y, x, d = 3, attempts = 30;

	while (1)
	{
		/* Find a location */
		y = rand_spread(py, d);
		x = rand_spread(px, d);

		/* Reject illegal grids */
		if (!in_bounds(y, x)) continue;

		/* Reject the player */
		if ((y == py) && (x == px)) continue;

		attempts--;

		if (!attempts)
		{
			d++;
			attempts = 8 * d;
		}

		/* Try to place a new feature */
		if (area(y, x)->feat == feat) continue;

		/* Okay */
		break;
	}

	/* Nuke objects */
	delete_object_idx(area(y, x)->o_idx);

	/* Nuke monsters */
	delete_monster_idx(area(y, x)->m_idx);

	/* Forget this grid */
	area(y, x)->info &= ~(CAVE_MARK);

	/* Place the feature */
	cave_set_feat(y, x, feat);

	/* Update stuff */
	p_ptr->update |= (PU_VIEW | PU_MONSTERS | PU_MON_LITE);
}