Exemple #1
0
/**
 * Allocates a single random object in the dungeon.
 * \param c the current chunk
 * \param set where the entity is placed (corridor, room or either)
 * \param typ what is placed (rubble, trap, gold, item)
 * \param depth generation depth
 * \param origin item origin (if appropriate)
 *
 * 'set' controls where the object is placed (corridor, room, either).
 * 'typ' conrols the kind of object (rubble, trap, gold, item).
 */
bool alloc_object(struct chunk *c, int set, int typ, int depth, byte origin)
{
    int x = 0, y = 0;
    int tries = 0;

    /* Pick a "legal" spot */
    while (tries < 2000) {
		tries++;

		find_empty(c, &y, &x);

		/* If we are ok with a corridor and we're in one, we're done */
		if (set & SET_CORR && !square_isroom(c, y, x)) break;

		/* If we are ok with a room and we're in one, we're done */
		if (set & SET_ROOM && square_isroom(c, y, x)) break;
    }

    if (tries == 2000) return false;

    /* Place something */
    switch (typ) {
    case TYP_RUBBLE: place_rubble(c, y, x); break;
    case TYP_TRAP: place_trap(c, y, x, -1, depth); break;
    case TYP_GOLD: place_gold(c, y, x, depth, origin); break;
    case TYP_OBJECT: place_object(c, y, x, depth, false, false, origin, 0); break;
    case TYP_GOOD: place_object(c, y, x, depth, true, false, origin, 0); break;
    case TYP_GREAT: place_object(c, y, x, depth, true, true, origin, 0); break;
    }
    return true;
}
Exemple #2
0
static void do_single_step(struct pt_regs *regs)
{
	single_step_data.is_branch = disasm_next_pc((unsigned long)
		regs->ret, regs, (struct callee_regs *)
		current->thread.callee_reg,
		&single_step_data.address[0],
		&single_step_data.address[1]);

	place_trap(single_step_data.address[0], &single_step_data.opcode[0]);

	if (single_step_data.is_branch) {
		place_trap(single_step_data.address[1],
			&single_step_data.opcode[1]);
	}

	single_step_data.armed++;
}
Exemple #3
0
/**
 * Lock a closed door to a given power
 */
void square_set_door_lock(struct chunk *c, int y, int x, int power)
{
	struct trap_kind *lock = lookup_trap("door lock");
	struct trap *trap;

	/* Verify it's a closed door */
	if (!square_iscloseddoor(c, y, x))
		return;

	/* If there's no lock there, add one */
	if (!square_trap_specific(c, y, x, lock->tidx))
		place_trap(c, y, x, lock->tidx, 0);

	/* Set the power (of all locks - there should be only one) */
	trap = c->squares[y][x].trap;
	while (trap) {
		if (trap->kind == lock)
			trap->xtra = power;
		trap = trap->next;
	}
}
/*
 * Place a trap with a given displacement of point
 */
void vault_trap_aux(int y, int x, int yd, int xd)
{
    int count = 0, y1 = y, x1 = x;
    int dummy = 0;

    cave_type *c_ptr;

    /* Place traps */
    for (count = 0; count <= 5; count++)
    {
        /* Get a location */
        while (dummy < SAFE_MAX_ATTEMPTS)
        {
            y1 = rand_spread(y, yd);
            x1 = rand_spread(x, xd);
            dummy++;
            if (!in_bounds(y1, x1)) continue;
            break;
        }

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

            }
        }

        /* Require "naked" floor grids */
        c_ptr = &cave[y1][x1];
        if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;

        /* Place the trap */
        place_trap(y1, x1);

        /* Done */
        break;
    }
}
void square_add_ward(struct chunk *c, int y, int x)
{
	struct trap_kind *rune = lookup_trap("glyph of warding");
	place_trap(c, y, x, rune->tidx, 0);
}
void square_add_trap(struct chunk *c, int y, int x)
{
	place_trap(c, y, x, -1, c->depth);
}
/*
 * Allocates some objects (using "place" and "type")
 */
static void alloc_object(int set, int typ, int num)
{
	int y, x, k;
	int dummy = 0;
	cave_type *c_ptr = NULL;

	/* Place some objects */
	for (k = 0; k < num; k++)
	{
		/* Pick a "legal" spot */
		while (dummy < SAFE_MAX_ATTEMPTS)
		{
			bool room;

			dummy++;

			/* Location */
			y = rand_range(min_hgt + 1, max_hgt - 2);
			x = rand_range(min_wid + 1, max_wid - 2);

			c_ptr = &cave[y][x];

			/* Require "naked" floor grid */
			if (!cave_naked_grid(c_ptr)) continue;

			/* Check for "room" */
			room = (c_ptr->info & CAVE_ROOM) ? TRUE : FALSE;

			/* Require corridor? */
			if ((set == ALLOC_SET_CORR) && room) continue;

			/* Require room? */
			if ((set == ALLOC_SET_ROOM) && !room) continue;

			/* Traps cannot be placed on 'icky' grids (rivers/lakes) */
			if ((typ == ALLOC_TYP_TRAP) && (c_ptr->info & CAVE_ICKY)) continue;

			/* Accept it */
			break;
		}

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


		/* Place something */
		switch (typ)
		{
			case ALLOC_TYP_RUBBLE:
			{
				c_ptr->feat = FEAT_RUBBLE;
				break;
			}

			case ALLOC_TYP_TRAP:
			{
				place_trap(y, x);
				break;
			}

			case ALLOC_TYP_GOLD:
			{
				place_gold(y, x);
				break;
			}

			case ALLOC_TYP_OBJECT:
			{
				place_object(y, x, FALSE, FALSE);
				break;
			}

			case ALLOC_TYP_INVIS:
			{
				/* Create invisible wall */
				cave_set_feat(y, x, FEAT_FLOOR);
				(void)place_field(y, x, FT_WALL_INVIS);
				break;
			}
		}
	}
}
Exemple #8
0
/**
 * Allocates some objects (using "place" and "type")
 */
void alloc_object(int set, int typ, int num)
{
    int y, x, k;
    feature_type *f_ptr;

    /* Place some objects */
    for (k = 0; k < num; k++) {
	/* Pick a "legal" spot */
	while (TRUE) {
	    bool room;

	    /* Location */
	    y = randint0(DUNGEON_HGT);
	    x = randint0(DUNGEON_WID);
	    f_ptr = &f_info[cave_feat[y][x]];

	    /* Paranoia - keep objects out of the outer walls */
	    if (!in_bounds_fully(y, x))
		continue;

	    /* Require "naked" floor grid */
	    f_ptr = &f_info[cave_feat[y][x]];
	    if (!(cave_naked_bold(y, x) && tf_has(f_ptr->flags, TF_FLOOR)))
		continue;

	    /* Check for "room" */
	    room = cave_has(cave_info[y][x], CAVE_ROOM) ? TRUE : FALSE;

	    /* Require corridor? */
	    if ((set == ALLOC_SET_CORR) && room)
		continue;

	    /* Require room? */
	    if ((set == ALLOC_SET_ROOM) && !room)
		continue;

	    /* Accept it */
	    break;
	}

	/* Place something */
	switch (typ) {
	case ALLOC_TYP_RUBBLE:
	    {
		place_rubble(y, x);
		break;
	    }

	case ALLOC_TYP_TRAP:
	    {
		place_trap(y, x, -1, p_ptr->depth);
		break;
	    }

	case ALLOC_TYP_GOLD:
	    {
		place_gold(y, x);
		break;
	    }

	case ALLOC_TYP_OBJECT:
	    {
		place_object(y, x, FALSE, FALSE, FALSE);
		break;
	    }
	}
    }
}
void square_add_trap(struct chunk *c, int y, int x)
{
	assert(square_in_bounds_fully(c, y, x));
	place_trap(c, y, x, -1, c->depth);
}
/*
 * Allocates some objects (using "place" and "type")
 */
static void alloc_object(int set, int typ, int num)
{
    int y = 0, x = 0, k;

    /* A small level has few objects. */
    num = MAX(1, num * cur_hgt * cur_wid / (MAX_HGT*MAX_WID));

    /* Diligent players should be encouraged to explore more! */
    if (typ == ALLOC_TYP_OBJECT || typ == ALLOC_TYP_GOLD)
        num = num * (625 + virtue_current(VIRTUE_DILIGENCE)) / 625;

    for (k = 0; k < num; k++)
    {
        object_type forge;
        int         k_idx;

        if (!_get_loc(set, &x, &y))
        {
            if (cheat_room)
                msg_print("Warning! Could not place object!");

            return;
        }

        switch (typ)
        {
        case ALLOC_TYP_RUBBLE:
            place_rubble(y, x);
            cave[y][x].info &= ~(CAVE_FLOOR);
            break;

        case ALLOC_TYP_TRAP:
            place_trap(y, x);
            cave[y][x].info &= ~(CAVE_FLOOR);
            break;

        case ALLOC_TYP_GOLD:
            place_gold(y, x);
            break;

        case ALLOC_TYP_OBJECT:
            /* Comment: Monsters drop objects at (ML + DL)/2. In practice,
               this means that your best drops are just laying on the ground,
               and this encourages recall scumming for end game resources such
               as wands of rockets. Note: Vaults are not affected and we want
               to encourage these! Room templates need some thought ... */
            if (base_level > 31)
            {
               int n = base_level - 30;
               object_level = 30 + n/2 + randint1(n/2);
            }
            else
                object_level = base_level; /* paranoia */
            place_object(y, x, 0L);
            object_level = base_level;
            break;

        case ALLOC_TYP_FOOD:
            if (prace_is_(RACE_ENT))
                k_idx = lookup_kind(TV_POTION, SV_POTION_WATER);
            else
                k_idx = lookup_kind(TV_FOOD, SV_FOOD_RATION);
            object_prep(&forge, k_idx);
            obj_make_pile(&forge);
            drop_near(&forge, -1, y, x);
            break;

        case ALLOC_TYP_LIGHT:
            if (one_in_(3))
                k_idx = lookup_kind(TV_FLASK, SV_FLASK_OIL);
            else
                k_idx = lookup_kind(TV_LITE, SV_LITE_LANTERN);
            object_prep(&forge, k_idx);
            apply_magic(&forge, dun_level, 0);
            obj_make_pile(&forge);
            drop_near(&forge, -1, y, x);
            break;

        case ALLOC_TYP_RECALL:
            k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_WORD_OF_RECALL);
            object_prep(&forge, k_idx);
            /*obj_make_pile(&forge);*/
            drop_near(&forge, -1, y, x);
            break;

        case ALLOC_TYP_SKELETON:
            k_idx = lookup_kind(TV_CORPSE, SV_SKELETON);
            object_prep(&forge, k_idx);
            apply_magic(&forge, dun_level, 0);
            drop_near(&forge, -1, y, x);
            break;
        }
    }
}
Exemple #11
0
/*
 * Allocates some objects (using "place" and "type")
 */
static void alloc_object(int set, int typ, int num)
{
	int y = 0, x = 0, k;
	int dummy = 0;
	cave_type *c_ptr;

	/* A small level has few objects. */
	num = num * cur_hgt * cur_wid / (MAX_HGT*MAX_WID) +1;

	/* Place some objects */
	for (k = 0; k < num; k++)
	{
		/* Pick a "legal" spot */
		while (dummy < SAFE_MAX_ATTEMPTS)
		{
			bool room;

			dummy++;

			/* Location */
			y = randint0(cur_hgt);
			x = randint0(cur_wid);

			c_ptr = &cave[y][x];

			/* Require "naked" floor grid */
			if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;

			/* Avoid player location */
			if (player_bold(y, x)) continue;

			/* Check for "room" */
			room = (cave[y][x].info & CAVE_ROOM) ? TRUE : FALSE;

			/* Require corridor? */
			if ((set == ALLOC_SET_CORR) && room) continue;

			/* Require room? */
			if ((set == ALLOC_SET_ROOM) && !room) continue;

			/* Accept it */
			break;
		}

		if (dummy >= SAFE_MAX_ATTEMPTS)
		{
			if (cheat_room)
			{
#ifdef JP
msg_print("警告!アイテムを配置できません!");
#else
				msg_print("Warning! Could not place object!");
#endif

			}
			return;
		}


		/* Place something */
		switch (typ)
		{
			case ALLOC_TYP_RUBBLE:
			{
				place_rubble(y, x);
				cave[y][x].info &= ~(CAVE_FLOOR);
				break;
			}

			case ALLOC_TYP_TRAP:
			{
				place_trap(y, x);
				cave[y][x].info &= ~(CAVE_FLOOR);
				break;
			}

			case ALLOC_TYP_GOLD:
			{
				place_gold(y, x);
				break;
			}

			case ALLOC_TYP_OBJECT:
			{
				place_object(y, x, 0L);
				break;
			}
		}
	}
}