Beispiel #1
0
/**
 * Attempts to place a monster of the given race at the given location.
 *
 * Note that certain monsters are placed with a large group of
 * identical or similar monsters. However, if `group_okay` is false,
 * then such monsters are placed by themselves.
 *
 * If `sleep` is true, the monster is placed with its default sleep value,
 * which is given in monster.txt.
 *
 * `origin` is the item origin to use for any monster drops (e.g. ORIGIN_DROP,
 * ORIGIN_DROP_PIT, etc.)
 */
bool place_new_monster(struct chunk *c, int y, int x, struct monster_race *race,
					   bool sleep, bool group_okay, byte origin)
{
	struct monster_friends *friends;
	struct monster_friends_base *friends_base;
	int total;

	assert(c);
	assert(race);

	/* Place one monster, or fail */
	if (!place_new_monster_one(c, y, x, race, sleep, origin)) return (false);

	/* We're done unless the group flag is set */
	if (!group_okay) return (true);

	/* Go through friends flags */
	for (friends = race->friends; friends; friends = friends->next) {
		if ((unsigned int)randint0(100) >= friends->percent_chance)
			continue;

		/* Calculate the base number of monsters to place */
		total = damroll(friends->number_dice, friends->number_side);

		place_friends(c, y, x, race, friends->race, total, sleep, origin);

	}

	/* Go through the friends_base flags */
	for (friends_base = race->friends_base; friends_base;
			friends_base = friends_base->next){
		struct monster_race *friends_race;

		/* Check if we pass chance for the monster appearing */
		if ((unsigned int)randint0(100) >= friends_base->percent_chance)
			continue;

		total = damroll(friends_base->number_dice, friends_base->number_side);

		/* Set the escort index base*/
		place_monster_base = friends_base->base;

		/* Prepare allocation table */
		get_mon_num_prep(place_monster_base_okay);

		/* Pick a random race */
		friends_race = get_mon_num(race->level);

		/* Reset allocation table */
		get_mon_num_prep(NULL);

		/* Handle failure */
		if (!friends_race) break;

		place_friends(c, y, x, race, friends_race, total, sleep, origin);
	}

	/* Success */
	return (true);
}
Beispiel #2
0
/**
 * Place monsters, up to the number asked for, in a rectangle centered on 
 * y0, x0.  Accept values for monster depth, symbol, and maximum vertical 
 * and horizontal displacement.  Call monster restriction functions if 
 * needed.
 * \param c the current chunk being generated
 * \param type the type of monster (see comments to mon_restrict())
 * \param depth selection depth
 * \param num the number of monsters to try and place - inexact due to groups
 * \param y0
 * \param x0 the centre of the rectangle for monster placement
 * \param dy
 * \param dx the dimensions of the rectangle
 * \param origin the origin for monster drops
 *
 * Return prematurely if the code starts looping too much (this may happen 
 * if y0 or x0 are out of bounds, or the area is already occupied).
 */
void spread_monsters(struct chunk *c, const char *type, int depth, int num, 
					 int y0, int x0, int dy, int dx, byte origin)
{
    int i, j;			/* Limits on loops */
    int count;
    int y = y0, x = x0;
    int start_mon_num = c->mon_max;

    /* Restrict monsters.  Allow uniques. Leave area empty if none found. */
    if (!mon_restrict(type, depth, true))
		return;

    /* Build the monster probability table. */
    if (!get_mon_num(depth))
		return;


    /* Try to summon monsters within our rectangle of effect. */
    for (count = 0, i = 0; ((count < num) && (i < 50)); i++) {
		/* Get a location */
		if ((dy == 0) && (dx == 0)) {
			y = y0;
			x = x0;
			if (!square_in_bounds(c, y, x))
				return;
		} else {
			for (j = 0; j < 10; j++) {
				y = rand_spread(y0, dy);
				x = rand_spread(x0, dx);
				if (!square_in_bounds(c, y, x)) {
					if (j < 9)
						continue;
					else
						return;
				}
				break;
			}
		}

		/* Require "empty" floor grids */
		if (!square_isempty(c, y, x)) continue;

		/* Place the monster (sleeping, allow groups) */
		pick_and_place_monster(c, y, x, depth, true, true, origin);

		/* Rein in monster groups and escorts a little. */
		if (c->mon_max - start_mon_num > num * 2)
			break;

		/* Count the monster(s), reset the loop count */
		count++;
		i = 0;
    }

    /* Remove monster restrictions. */
    (void) mon_restrict(NULL, depth, true);
}
Beispiel #3
0
/**
 * Picks a monster race, makes a new monster of that race, then attempts to 
 * place it in the dungeon. The monster race chosen will be appropriate for
 * dungeon level equal to `depth`.
 *
 * If `sleep` is true, the monster is placed with its default sleep value,
 * which is given in monster.txt.
 *
 * If `group_okay` is true, we allow the placing of a group, if the chosen
 * monster appears with friends or an escort.
 *
 * `origin` is the item origin to use for any monster drops (e.g. ORIGIN_DROP,
 * ORIGIN_DROP_PIT, etc.) 
 *
 * Returns TRUE if we successfully place a monster.
 */
bool pick_and_place_monster(struct cave *c, int y, int x, int depth, bool sleep,
	bool group_okay, byte origin)
{
	/* Pick a monster race */
	monster_race *race = get_mon_num(depth);
	if (!race) return (FALSE);

	/* Attempt to place the monster */
	return (place_new_monster(c, y, x, race, sleep, group_okay, origin));
}
Beispiel #4
0
/**
 * Picks a monster race, makes a new monster of that race, then attempts to
 * place it in the dungeon. The monster race chosen will be appropriate for
 * dungeon level equal to `depth`.
 *
 * If `sleep` is true, the monster is placed with its default sleep value,
 * which is given in monster.txt.
 *
 * If `group_okay` is true, we allow the placing of a group, if the chosen
 * monster appears with friends or an escort.
 *
 * `origin` is the item origin to use for any monster drops (e.g. ORIGIN_DROP,
 * ORIGIN_DROP_PIT, etc.)
 *
 * Returns true if we successfully place a monster.
 */
bool pick_and_place_monster(struct chunk *c, int y, int x, int depth,
							bool sleep, bool group_okay, byte origin)
{
	/* Pick a monster race */
	struct monster_race *race = get_mon_num(depth);
	if (race) {
		return place_new_monster(c, y, x, race, sleep, group_okay, origin);
	} else {
		return false;
	}
}
Beispiel #5
0
/**
 * Picks a monster race, makes a new monster of that race, then attempts to 
 * place it in the dungeon. The monster race chosen will be appropriate for
 * dungeon level equal to `depth`.
 *
 * If `sleep` is true, the monster is placed with its default sleep value,
 * which is given in monster.txt.
 *
 * If `group_okay` is true, we allow the placing of a group, if the chosen
 * monster appears with friends or an escort.
 *
 * `origin` is the item origin to use for any monster drops (e.g. ORIGIN_DROP,
 * ORIGIN_DROP_PIT, etc.) 
 *
 * Returns TRUE if we successfully place a monster.
 */
bool pick_and_place_monster(struct cave *c, int y, int x, int depth, bool sleep,
	bool group_okay, byte origin)
{
	int r_idx;

	/* Pick a monster race */
	r_idx = get_mon_num(depth);

	/* Handle failure */
	if (!r_idx) return (FALSE);

	/* Attempt to place the monster */
	return (place_new_monster(c, y, x, r_idx, sleep, group_okay, origin));
}
Beispiel #6
0
/**
 * To avoid rebuilding the monster list too often (which can quickly 
 * get expensive), we handle monsters of a specified race separately.
 *
 * \param c the current chunk being generated
 * \param racial_symbol the allowable monster_base symbols
 * \param vault_type the type of vault, which affects monster selection depth
 * \param data the vault text description, which contains the racial symbol
 * \param y1 the limits of the vault
 * \param y2 the limits of the vault
 * \param x1 the limits of the vault
 * \param x2 the limits of the vault
 */
void get_vault_monsters(struct chunk *c, char racial_symbol[], char *vault_type,
						const char *data, int y1, int y2, int x1, int x2)
{
    int i, y, x, depth;
    const char *t;

    for (i = 0; racial_symbol[i] != '\0'; i++) {
		/* Require correct race, allow uniques. */
		allow_unique = true;
		my_strcpy(base_d_char, format("%c", racial_symbol[i]),
				  sizeof(base_d_char));

		/* Determine level of monster */
		if (strstr(vault_type, "Lesser vault"))
			depth = player->depth + 2;
		else if (strstr(vault_type, "Medium vault"))
			depth = player->depth + 4;
		else if (strstr(vault_type, "Greater vault"))
			depth = player->depth + 6;
		else
			depth = player->depth;

		/* Prepare allocation table */
		get_mon_num_prep(mon_select);

		/* Build the monster probability table. */
		if (!get_mon_num(depth))
			continue;


		/* Place the monsters */
		for (t = data, y = y1; y <= y2; y++) {
			for (x = x1; x <= x2; x++, t++) {
				if (*t == racial_symbol[i]) {
					/* Place a monster */
					pick_and_place_monster(c, y, x, depth, false,
										   false, ORIGIN_DROP_SPECIAL);
				}
			}
		}
    }

    /* Clear any current monster restrictions. */
	get_mon_num_prep(NULL);
}
Beispiel #7
0
/*
 * Generate a new dungeon level
 *
 * Note that "dun_body" adds about 4000 bytes of memory to the stack.
 */
static bool cave_gen(void)
{
	int i, j, k, y, x, y1, x1;

   int extraloot,ctx;

   int sizelootadjustment,totalattempts;

	int max_vault_ok = 3;

	int feat1, feat2;

	cave_type *c_ptr;

	bool destroyed = FALSE;
	bool empty_level = FALSE;
	bool cavern = FALSE;

   bool lairlevel = FALSE; /*  Lair Level  */

   int lotsorooms = 0;

	int laketype = 0;

   int droom_min = DUN_ROOMS_MIN;

   int droom_max = DUN_ROOMS_MAX;

   int dmod = p_ptr->depth;

   int dmod2 = p_ptr->depth * 3;

	dun_data dun_body;

   if (dmod < 1) dmod = 1;

   if (one_in_(2)) lotsorooms = randint1(9)+1;

	/* Prepare allocation table */
	get_mon_num_prep(get_monster_hook(), NULL);

	/* Global data */
	dun = &dun_body;

   droom_min += dmod;
   droom_max += dmod2;

   if (droom_min > droom_max) droom_min = droom_max - 10;

   if (droom_max < droom_min) droom_max = droom_min + 10;

   if (droom_min < 1)
   {
      droom_min = 5;
      droom_max = 15;
   }

   if (lotsorooms)
   {
      droom_min *= lotsorooms;
      droom_max *= lotsorooms;
   }

   if (droom_min > 100) droom_min = 100;
   if (droom_max > 300) droom_max = 300;

   if (one_in_(11)) lairlevel = TRUE;

   extraloot = 0;
   ctx = 0;
   sizelootadjustment = 0;
   totalattempts = 0;

   sizelootadjustment = ((max_hgt - min_hgt) / 22) + ((max_wid - min_wid) / 66);

   if (sizelootadjustment < 1) sizelootadjustment = 1;

	if (max_hgt - min_hgt < 23) max_vault_ok--;
	if (max_wid - min_wid < 34) max_vault_ok--;

	/* Hack - no vaults in moria mode */
	if (ironman_moria) max_vault_ok = 0;

	/* Randomize the dungeon creation values */
	dun_rooms = rand_range(droom_min, droom_max);
	dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
	dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
	dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
	dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
	dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);

	/* Empty arena levels */
	if (ironman_empty_levels || (empty_levels && one_in_(EMPTY_LEVEL)))
	{
		empty_level = TRUE;

		if (cheat_room)
			msg_print("Arena level.");
	}

	/* Hack -- Start with basic granite */
	for (y = min_hgt; y < max_hgt; y++)
	{
		for (x = min_wid; x < max_wid; x++)
		{
			if (empty_level)
				cave[y][x].feat = FEAT_FLOOR;
			else
			  /* Create granite wall */
				cave[y][x].feat = FEAT_WALL_EXTRA;
		}
	}

	/* Possible "destroyed" level */
	if ((p_ptr->depth > 15) && one_in_(DUN_DEST) && (small_levels))
	{
		destroyed = TRUE;

		/* extra rubble around the place looks cool */
		build_lake(LAKE_DESTROY);
	}

	/* Make a lake some of the time */
	if (one_in_(LAKE_LEVEL) && !empty_level && !destroyed && terrain_streams)
	{
		/* Lake of Water */
		if (p_ptr->depth > 52) laketype = LAKE_WATER;

		/* Lake of Lava */
		if (p_ptr->depth > 90) laketype = LAKE_LAVA;

		if (laketype != 0)
		{
			if (cheat_room)
				msg_print("Lake on the level.");
			build_lake(laketype);
		}
	}

	if (one_in_(DUN_CAV1/(p_ptr->depth + DUN_CAV2)) && !empty_level &&
	    (laketype == 0) && !destroyed && (p_ptr->depth >= MIN_CAVERN))
	{
		cavern = TRUE;

		/* make a large fractal cave in the middle of the dungeon */

		if (cheat_room)
			msg_print("Cavern on level.");

		build_cavern();
	}

	/* Hack -- No destroyed "quest" levels */
	if (quest_number(p_ptr->depth)) destroyed = FALSE;

	/* Actual maximum number of rooms on this level */
	dun->row_rooms = (max_hgt - min_hgt) / BLOCK_HGT;
	dun->col_rooms = (max_wid - min_hgt) / BLOCK_WID;

	/* Initialize the room table */
	for (y = 0; y < dun->row_rooms; y++)
	{
		for (x = 0; x < dun->col_rooms; x++)
		{
			dun->room_map[y][x] = FALSE;
		}
	}


	/* No "crowded" rooms yet */
	dun->crowded = 0;


	/* No rooms yet */
	dun->cent_n = 0;

	/* Build some rooms */
	for (i = 0; i < dun_rooms; i++)
	{
		/* Pick a block for the room */
		y = randint0(dun->row_rooms);
		x = randint0(dun->col_rooms);

		/* Align dungeon rooms */
		if (dungeon_align)
		{
			/* Slide some rooms right */
			if ((x % 3) == 0) x++;

			/* Slide some rooms left */
			if ((x % 3) == 2) x--;
		}

		/* Attempt an "unusual" room */
		if (ironman_rooms || (randint0(DUN_UNUSUAL) < p_ptr->depth))
		{
			/* Roll for room type */
			k = randint0(100);

			/* Attempt a very unusual room */
			if ((ironman_rooms && (randint0(DUN_UNUSUAL) < p_ptr->depth * 2)) ||
				 (randint0(DUN_UNUSUAL) < p_ptr->depth))
			{
#ifdef FORCE_V_IDX
				if (room_build(y, x, 8)) continue;
#else
				/* Type 8 -- Greater vault (10%) */
				if (k < 10)
				{
					if (max_vault_ok > 1)
					{
						if (room_build(y, x, 8)) continue;
					}
					else
					{
						if (cheat_room) msg_format("Refusing a greater vault. %d", max_vault_ok);
					}
				}

				/* Type 7 -- Lesser vault (13%) */
				if (k < 23)
				{
					if (max_vault_ok > 0)
					{
						if (room_build(y, x, 7)) continue;
					}
					else
					{
						if (cheat_room) msg_print("Refusing a lesser vault.");
					}
				}


				/* Type 5 -- Monster nest (8%) */
				if ((k < 31) && room_build(y, x, 5)) continue;

				/* Type 6 -- Monster pit (5%) */
				if ((k < 36) && room_build(y, x, 6)) continue;

				/* Type 10 -- Random vault (11%) */
				if (k < 47)
				{
					if (max_vault_ok > 0)
					{
						if (room_build(y, x, 10)) continue;
					}
					else
					{
						if (cheat_room) msg_print("Refusing a random vault.");
					}
				}
#endif
			}

			/* Type 4 -- Large room (15%) */
			if ((k < 15) && room_build(y, x, 4)) continue;

			/* Type 14 -- Large room (10%) */
			if ((k < 25) && room_build(y, x, 14)) continue;

			/* Type 13 -- Large Feature room (5%) */
			if ((k < 30) && room_build(y, x, 13)) continue;

			/* Type 3 -- Cross room (20%) */
			if ((k < 50) && room_build(y, x, 3)) continue;

			/* Type 2 -- Overlapping (25%) */
			if ((k < 75) && room_build(y, x, 2)) continue;

			/* Type 11 -- Parallelagram (5%) */
			if ((k < 80) && room_build(y, x, 15)) continue;

			/* Type 11 -- Circular (5%) */
			if ((k < 85) && room_build(y, x, 11)) continue;

			/* Type 12 -- Crypt (15%) */
			if ((k < 100) && room_build(y, x, 12)) continue;
		}

		/* The deeper you are, the more cavelike the rooms are */
		k = randint1(100);

		/* No caves when a cavern exists: they look bad */
		if ((k < p_ptr->depth) && (!cavern) && (!empty_level) && (laketype == 0))
		{
			/* Type 9 -- Fractal cave */
			if (room_build(y, x, 9)) continue;
		}
		else
		{
			/* Attempt a "trivial" room */
			if (room_build(y, x, 1)) continue;
		}
	}

	/* Make a hole in the dungeon roof sometimes at level 1 */
	if ((p_ptr->depth == 1) && terrain_streams)
	{
		while (one_in_(DUN_MOS_DEN))
		{
			place_trees(rand_range(min_wid + 1, max_wid - 2),
				 rand_range(min_hgt + 1, max_hgt - 2));
		}
	}

	/* Destroy the level if necessary */
	if (destroyed) destroy_level();

	/* Hack -- Add some rivers */
	if (one_in_(3) && (randint1(p_ptr->depth) > 5) && terrain_streams)
	{
	 	/* Choose water or lava */
		if (randint0(MAX_DEPTH * 2) > p_ptr->depth)
		{
			feat1 = FEAT_DEEP_WATER;
			feat2 = FEAT_SHAL_WATER;
		}
		else
		{
			feat1 = FEAT_DEEP_LAVA;
			feat2 = FEAT_SHAL_LAVA;
		}


	 	/* Only add river if matches lake type or if have no lake at all */
	 	if (((laketype == 1) && (feat1 == FEAT_DEEP_LAVA)) ||
	 	    ((laketype == 2) && (feat1 == FEAT_DEEP_WATER)) ||
		     (laketype == 0))
	 	{
			add_river(feat1, feat2);
		}
	}

	/* Special boundary walls -- Top */
	for (x = min_wid; x < max_wid; x++)
	{
		/* Clear previous contents, add "solid" perma-wall */
		cave[min_hgt][x].feat = FEAT_PERM_SOLID;
	}

	/* Special boundary walls -- Bottom */
	for (x = min_wid; x < max_wid; x++)
	{
		/* Clear previous contents, add "solid" perma-wall */
		cave[max_hgt - 1][x].feat = FEAT_PERM_SOLID;
	}

	/* Special boundary walls -- Left */
	for (y = min_hgt; y < max_hgt; y++)
	{
		/* Clear previous contents, add "solid" perma-wall */
		cave[y][min_wid].feat = FEAT_PERM_SOLID;
	}

	/* Special boundary walls -- Right */
	for (y = min_hgt; y < max_hgt; y++)
	{
		/* Clear previous contents, add "solid" perma-wall */
		cave[y][max_wid - 1].feat = FEAT_PERM_SOLID;
	}


	/* Hack -- Scramble the room order */
	for (i = 0; i < dun->cent_n; i++)
	{
		int pick1 = randint0(dun->cent_n);
		int pick2 = randint0(dun->cent_n);
		y1 = dun->cent[pick1].y;
		x1 = dun->cent[pick1].x;
		dun->cent[pick1].y = dun->cent[pick2].y;
		dun->cent[pick1].x = dun->cent[pick2].x;
		dun->cent[pick2].y = y1;
		dun->cent[pick2].x = x1;
	}

	/* Start with no tunnel doors */
	dun->door_n = 0;

	/* Hack -- connect the first room to the last room */
	y = dun->cent[dun->cent_n-1].y;
	x = dun->cent[dun->cent_n-1].x;

	/* Connect all the rooms together */
	for (i = 0; i < dun->cent_n; i++)
	{

		/* Reset the arrays */
		dun->tunn_n = 0;
		dun->wall_n = 0;

		/* Connect the room to the previous room */
#ifdef PILLAR_TUNNELS

		if ((randint1(20) > p_ptr->depth) && one_in_(4))
		{
			/* make catacomb-like tunnel */
			(void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 3, 30);
		}
		else if (randint1(p_ptr->depth) > 50)
#else
		if (randint1(p_ptr->depth) > 50)
#endif /* PILLAR_TUNNELS */
		{
			/* make cave-like tunnel */
			(void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
		}
		else
		{
			/* make normal tunnel */
			build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x);
		}

		/* Turn the tunnel into corridor */
		for (j = 0; j < dun->tunn_n; j++)
		{
			/* Access the grid */
			y = dun->tunn[j].y;
			x = dun->tunn[j].x;

			/* Access the grid */
			c_ptr = &cave[y][x];

			/* Deleting a locked or jammed door is problematical */
			delete_field_location(c_ptr);

			/* Clear previous contents (if not a lake), add a floor */
			if ((c_ptr->feat < FEAT_DEEP_WATER) ||
			    (c_ptr->feat > FEAT_SHAL_LAVA))
			{
				c_ptr->feat = FEAT_FLOOR;
			}
		}

		/* Apply the piercings that we found */
		for (j = 0; j < dun->wall_n; j++)
		{
			/* Access the grid */
			y = dun->wall[j].y;
			x = dun->wall[j].x;

			/* Access the grid */
			c_ptr = &cave[y][x];

			/* Deleting a locked or jammed door is problematical */
			delete_field_location(c_ptr);

			/* Clear previous contents, add up floor */
			c_ptr->feat = FEAT_FLOOR;

			/* Occasional doorway */
			if (randint0(100) < dun_tun_pen)
			{
				/* Place a random door */
				place_random_door(y, x);
			}
		}

		/* Remember the "previous" room */
		y = dun->cent[i].y;
		x = dun->cent[i].x;
	}

	/* Place intersection doors	 */
	for (i = 0; i < dun->door_n; i++)
	{
		/* Extract junction location */
		y = dun->door[i].y;
		x = dun->door[i].x;

		/* Try placing doors */
		try_door(y, x - 1);
		try_door(y, x + 1);
		try_door(y - 1, x);
		try_door(y + 1, x);
	}


	/* Hack -- Add some magma streamers */
	for (i = 0; i < DUN_STR_MAG; i++)
	{
		build_streamer(FEAT_MAGMA, DUN_STR_MC);
	}

	/* Hack -- Add some quartz streamers */
	for (i = 0; i < DUN_STR_QUA; i++)
	{
		build_streamer(FEAT_QUARTZ, DUN_STR_QC);
	}

	/* Place 3 or 4 down stairs near some walls */
	if (!alloc_stairs(FEAT_MORE, rand_range(3, 4), 3)) return FALSE;

	/* Place 1 or 2 up stairs near some walls */
	if (!alloc_stairs(FEAT_LESS, rand_range(3, 4), 3)) return FALSE;

	/* Handle the quest monster placements */
	for (i = 0; i < max_quests; i++)
	{
		if ((quest[i].status == QUEST_STATUS_TAKEN) &&
		    ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
		    (quest[i].type == QUEST_TYPE_RANDOM)) &&
		    (quest[i].level == p_ptr->depth) &&
			!(quest[i].flags & QUEST_FLAG_PRESET))
		{
			monster_race *r_ptr = &r_info[quest[i].r_idx];

			/* Hack -- "unique" monsters must be "unique" */
			if ((r_ptr->flags1 & RF1_UNIQUE) &&
			    (r_ptr->cur_num >= r_ptr->max_num))
			{
				/* The unique is already dead */
				quest[i].status = QUEST_STATUS_FINISHED;
			}
			else
			{
				bool group;

				/* Hard quests -> revive all monsters */
				if (ironman_hard_quests)
				{
					quest[i].cur_num = 0;
				}

				for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
				{
					for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
					{
						/* Find an empty grid */
						while (TRUE)
						{
							y = rand_range(min_hgt + 1, max_hgt - 2);
							x = rand_range(min_wid + 1, max_wid - 2);

							/* Access the grid */
							c_ptr = &cave[y][x];

							if (!cave_naked_grid(c_ptr)) continue;
							if (distance(y, x, p_ptr->py, p_ptr->px) < 10) continue;
							else break;
						}

						if (r_ptr->flags1 & RF1_FRIENDS)
							group = FALSE;
						else
							group = TRUE;

						/* Try to place the monster */
						if (place_monster_aux(y, x, quest[i].r_idx, FALSE, group, FALSE, FALSE))
						{
							/* Success */
							break;
						}
						else
						{
							/* Failure - Try again */
							continue;
						}
					}
				}
			}
		}
	}

	/* Basic "amount" */
	k = (p_ptr->depth / 3);
	if (k > 10) k = 10;
	if (k < 2) k = 2;

	/* Pick a base number of monsters */
	i = MIN_M_ALLOC_LEVEL;

   if (!(lairlevel))
   {

   	/* To make small levels a bit more playable */
	   if (max_hgt < MAX_HGT || max_wid < MAX_WID)
   	{
	   	int small_tester = i;

		   i = (i * max_hgt) / MAX_HGT;
   		i = (i * max_wid) / MAX_WID;
	   	i += 1;

		   if (i > small_tester) i = small_tester;
   		else if (cheat_hear)
	   	{
		   	msg_format("Reduced monsters base from %d to %d", small_tester, i);
   		}
	   }

   	i += randint1(8);

   	/* Put some monsters in the dungeon */
	   for (i = i + k; i > 0; i--)
   	{
	   	(void)alloc_monster(0, TRUE);
   	}
   }

   if (lairlevel)
   {
		int r_idx = get_mon_num(p_ptr->depth + randint1(12) + 3), attempts = (randint1(200)+100);
      monster_race *r_ptr = &r_info[r_idx];

      attempts += ((10 + sizelootadjustment) * r_ptr->level);

      if (cheat_room)
   	msg_print("Smile!  Then Die!");

      totalattempts = 0;

		while (attempts && (totalattempts <= 10000))
		{
/*         attempts--;*/

         ctx = 0;

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

			/* Access the grid */
			c_ptr = &cave[y][x];

			if (!cave_naked_grid(c_ptr)) ctx = 1;
			if (distance(y, x, p_ptr->py, p_ptr->px) < 10) ctx = 1;

   		/* Try to place the monster */
         if (ctx == 0)
         {
	   	   if (place_monster_aux(y, x, r_idx, FALSE, (one_in_(10)) ? TRUE : FALSE, FALSE, FALSE))
   		   {
               extraloot++;
               attempts--;
   		   }
         }
         totalattempts++;
      }
   }

	/* Place some traps in the dungeon */
	alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));

	/* Put some rubble in corridors */
	alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));

	/* Put some objects in rooms */
	alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));

   if (lairlevel)
   {
	   alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k*30));

   	/* Hack - Make loot desirable! */
      /* AKA - Sucker in the PC  */
	   dun_theme.treasure = qreward_theme[p_ptr->pclass].treasure;
   	dun_theme.combat = qreward_theme[p_ptr->pclass].combat;
	   dun_theme.magic = qreward_theme[p_ptr->pclass].magic;
   	dun_theme.tools = qreward_theme[p_ptr->pclass].tools;

   	/* Put loot! in the dungeon */
	   alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, extraloot);
   	alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, extraloot);
   }

	/* Hack - Reset the object theme */
	dun_theme.treasure = 20;
	dun_theme.combat = 20;
	dun_theme.magic = 20;
	dun_theme.tools = 20;

   /* Put some objects/gold in the dungeon */
	alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
   alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));

	/* Put some invisible walls in the dungeon for nightmare mode */
	if (ironman_nightmare)
	{
		alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_INVIS, randnor(DUN_AMT_INVIS, 3));
	}

	if (empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > p_ptr->depth)))
	{
		/* Lite the cave */
		for (y = min_hgt; y < max_hgt; y++)
		{
			for (x = min_hgt; x < max_wid; x++)
			{
				cave[y][x].info |= (CAVE_GLOW);
			}
		}
	}

	/* Determine the character location */
	if (!new_player_spot())
		return FALSE;

	return TRUE;
}
Beispiel #8
0
/**
 * Funtion for placing appropriate monsters in a room of chambers
 *
 * \param c the current chunk being generated
 * \param y1 the limits of the vault
 * \param x1 the limits of the vault
 * \param y2 the limits of the vault
 * \param x2 the limits of the vault
 * \param name the name of the monster type for use in mon_select()
 * \param area the total room area, used for scaling monster quantity
 */
void get_chamber_monsters(struct chunk *c, int y1, int x1, int y2, int x2, 
						  char *name, int area)
{
	int i, y, x;
	s16b monsters_left, depth;
	bool random = one_in_(20);

	/* Get a legal depth. */
	depth = c->depth + randint0(11) - 5;

	/* Choose a pit profile, using that depth. */
	if (!random)
		set_pit_type(depth, 0);

	/* Allow (slightly) tougher monsters. */
	depth = c->depth + (c->depth < 60 ? c->depth / 12 : 5);

	/* Set monster generation restrictions. Occasionally random. */
	if (random) {
		if (!mon_restrict("random", depth, true))
			return;
		my_strcpy(name, "random", sizeof(name));
	} else {
		if (!mon_restrict(dun->pit_type->name, depth, true))
			return;
		my_strcpy(name, dun->pit_type->name, sizeof(name));
	}

	/* Build the monster probability table. */
	if (!get_mon_num(depth)) {
		(void) mon_restrict(NULL, depth, false);
		name = NULL;
		return;
	}

	/* No normal monsters. */
	generate_mark(c, y1, x1, y2, x2, SQUARE_MON_RESTRICT);

	/* Allow about a monster every 20-30 grids. */
	monsters_left = area / (30 - c->depth / 10);

	/* Place the monsters. */
	for (i = 0; i < 300; i++) {
		/* Check for early completion. */
		if (!monsters_left)
			break;

		/* Pick a random in-room square. */
		y = y1 + randint0(1 + ABS(y2 - y1));
		x = x1 + randint0(1 + ABS(x2 - x1));

		/* Require a passable square with no monster in it already. */
		if (!square_isempty(c, y, x))
			continue;

		/* Place a single monster.  Sleeping 2/3rds of the time. */
		pick_and_place_monster(c, y, x, c->depth, (randint0(3) != 0), false,
											 ORIGIN_DROP_SPECIAL);

		/* One less monster to place. */
		monsters_left--;
	}

	/* Remove our restrictions. */
	(void) mon_restrict(NULL, depth, false);
}
Beispiel #9
0
/**
 * Places a monster (of the specified "type") near the given
 * location.  Return the siummoned monster's level iff a monster was
 * actually summoned.
 *
 * We will attempt to place the monster up to 10 times before giving up.
 *
 * This function takes the "monster level"
 * of the summoning monster as a parameter, and use that, along with
 * the current dungeon level, to help determine the level of the
 * desired monster.  Note that this is an upper bound, and also
 * tends to "prefer" monsters of that level.  Currently, we use
 * the average of the dungeon and monster levels, and then add
 * five to allow slight increases in monster power.
 *
 * Note that we use the new "monster allocation table" creation code
 * to restrict the "get_mon_num()" function to the set of "legal"
 * monsters, making this function much faster and more reliable.
 *
 * Note that this function may not succeed, though this is very rare.
 */
int summon_specific(int y1, int x1, int lev, int type, bool delay, bool call)
{
	int i, x = 0, y = 0;

	struct monster *mon;
	struct monster_race *race;

	/* Look for a location, allow up to 4 squares away */
	for (i = 0; i < 60; ++i) {
		/* Pick a distance */
		int d = (i / 15) + 1;

		/* Pick a location */
		scatter(cave, &y, &x, y1, x1, d, true);

		/* Require "empty" floor grid */
		if (!square_isempty(cave, y, x)) continue;

		/* No summon on glyphs */
		if (square_iswarded(cave, y, x) || square_isdecoyed(cave, y, x)) {
			continue;
		}

		/* Okay */
		break;
	}

	/* Failure */
	if (i == 60) return (0);

	/* Save the "summon" type */
	summon_specific_type = type;

	/* Use the new calling scheme if requested */
	if (call && (type != summon_name_to_idx("UNIQUE")) &&
		(type != summon_name_to_idx("WRAITH"))) {
		return (call_monster(y, x));
	}

	/* Prepare allocation table */
	get_mon_num_prep(summon_specific_okay);

	/* Pick a monster, using the level calculation */
	race = get_mon_num((player->depth + lev) / 2 + 5);

	/* Prepare allocation table */
	get_mon_num_prep(NULL);

	/* Handle failure */
	if (!race) return (0);

	/* Attempt to place the monster (awake, don't allow groups) */
	if (!place_new_monster(cave, y, x, race, false, false, ORIGIN_DROP_SUMMON))
		return (0);

	/* Success, return the level of the monster */
	mon = square_monster(cave, y, x);

	/* If delay, try to let the player act before the summoned monsters,
	 * including slowing down faster monsters for one turn */
	/* XXX should this now be hold monster for a turn? */
	if (delay) {
		mon->energy = 0;
		if (mon->race->speed > player->state.speed)
			mon_inc_timed(mon, MON_TMD_SLOW, 1,	MON_TMD_FLG_NOMESSAGE, false);
	}

	return (mon->race->level);
}
Beispiel #10
0
/**
 * Place monsters, up to the number asked for, in a rectangle centered on 
 * y0, x0.  Accept values for monster depth, symbol, and maximum vertical 
 * and horizontal displacement.  Call monster restriction functions if 
 * needed.
 *
 * Return prematurely if the code starts looping too much (this may happen 
 * if y0 or x0 are out of bounds, or the area is already occupied).
 */
extern void spread_monsters(char symbol, int depth, int num, int y0, int x0,
			    int dy, int dx)
{
    int i, j;			/* Limits on loops */
    int count;
    int y = y0, x = x0;
    int start_mon_num = m_max;
    bool dummy;

    /* Restrict monsters.  Allow uniques. */
    (void) mon_restrict(symbol, (byte) depth, &dummy, TRUE);

    /* Set generation level */
    monster_level = depth;

    /* Build the monster probability table. */
    if (!get_mon_num(depth))
	return;


    /* Try to summon monsters within our rectangle of effect. */
    for (count = 0, i = 0; ((count < num) && (i < 50)); i++) {
	/* Get a location */
	if ((dy == 0) && (dx == 0)) {
	    y = y0;
	    x = x0;
	    if (!in_bounds(y, x))
		return;
	} else {
	    for (j = 0; j < 10; j++) {
		y = rand_spread(y0, dy);
		x = rand_spread(x0, dx);
		if (!in_bounds(y, x)) {
		    if (j < 9)
			continue;
		    else
			return;
		}
		break;
	    }
	}

	/* Require "empty" floor grids */
	if (!cave_empty_bold(y, x))
	    continue;

	/* Place the monster (sleeping, allow groups, quickly) */
	(void) place_monster(y, x, TRUE, TRUE, TRUE);

	/* Rein in monster groups and escorts a little. */
	if (m_max - start_mon_num > num * 2)
	    break;

	/* Count the monster(s), reset the loop count */
	count++;
	i = 0;
    }

    /* Remove monster restrictions. */
    (void) mon_restrict('\0', (byte) depth, &dummy, TRUE);

    /* Reset monster generation level. */
    monster_level = p_ptr->danger;
}
Beispiel #11
0
extern void get_chamber_monsters(int y1, int x1, int y2, int x2)
{
    bool dummy;
    int i, y, x;
    s16b monsters_left, depth;
    char symbol;

    /* Description of monsters in room */
    char *name;

    /* Get a legal depth. */
    depth = p_ptr->danger + randint0(11) - 5;
    if (depth > 60)
	depth = 60;
    if (depth < 5)
	depth = 5;

    /* Choose a monster type, using that depth. */
    symbol = mon_symbol_at_depth[depth / 5 - 1][randint0(13)];

    /* Allow (slightly) tougher monsters. */
    depth = p_ptr->danger + (p_ptr->danger < 60 ? p_ptr->danger / 12 : 5);

    /* Set monster generation restrictions.  Describe the monsters. */
    name = mon_restrict(symbol, (byte) depth, &dummy, TRUE);

    /* A default description probably means trouble, so stop. */
    if (streq(name, "misc") || !name[0])
	return;

    /* Build the monster probability table. */
    if (!get_mon_num(depth))
	return;

    /* No normal monsters. */
    generate_mark(y1, x1, y2, x2, CAVE_TEMP);


    /* Usually, we want 35 monsters. */
    monsters_left = 35;

    /* Fewer monsters near the surface. */
    if (p_ptr->danger < 45)
	monsters_left = 5 + 2 * p_ptr->danger / 3;

    /* More monsters of kinds that tend to be weak. */
    if (strstr("abciBCFKRS", d_char_req))
	monsters_left += 15;

    /* Place the monsters. */
    for (i = 0; i < 300; i++) {
	/* Check for early completion. */
	if (!monsters_left)
	    break;

	/* Pick a random in-room square. */
	y = y1 + randint0(1 + ABS(y2 - y1));
	x = x1 + randint0(1 + ABS(x2 - x1));

	/* Require a floor square with no monster in it already. */
	if (!cave_naked_bold(y, x))
	    continue;

	/* Place a single monster.  Sleeping 2/3rds of the time. */
	place_monster_aux(y, x, get_mon_num_quick(depth), (randint0(3) != 0),
			  FALSE);

	/* One less monster to place. */
	monsters_left--;
    }

    /* Remove our restrictions. */
    (void) mon_restrict('\0', (byte) depth, &dummy, FALSE);

    /* Describe */
    if (OPT(cheat_room)) {
	/* Room type */
	msg("Room of chambers (%s)", name);
    }
}
Beispiel #12
0
/**
 * To avoid rebuilding the monster list too often (which can quickly 
 * get expensive), we handle monsters of a specified race separately.
 */
extern void get_vault_monsters(char racial_symbol[], byte vault_type, const char *data,
			       int y1, int y2, int x1, int x2)
{
    int i, y, x, temp;
    const char *t;

    for (i = 0; racial_symbol[i] != '\0'; i++) {
	/* Require correct race, allow uniques. */
	allow_unique = TRUE;
	sprintf(d_char_req, "%c", racial_symbol[i]);
	d_attr_req[0] = 0;
	d_attr_req[1] = 0;
	d_attr_req[2] = 0;
	d_attr_req[3] = 0;
	racial_flag_mask = 0;
	rsf_wipe(breath_flag_mask);

	/* Determine level of monster */
	if (vault_type == 0)
	    temp = p_ptr->danger + 3;
	else if (vault_type == 7)
	    temp = p_ptr->danger;
	else if (vault_type == 8)
	    temp = p_ptr->danger + 3;
	else if (vault_type == 9)
	    temp = p_ptr->danger + 6;
	else if (vault_type == 12)
	    temp = p_ptr->danger + 3;
	else if (vault_type == 13)
	    temp = p_ptr->danger + 6;
	else if ((vault_type > 13) && (vault_type % 2))
	    temp = p_ptr->danger + 4;
	else
	    temp = p_ptr->danger;

	/* Apply our restrictions */
	get_mon_num_hook = mon_select;

	/* Prepare allocation table */
	get_mon_num_prep();

	/* Build the monster probability table. */
	if (!get_mon_num(temp))
	    continue;


	/* Place the monsters */
	for (t = data, y = y1; y <= y2; y++) {
	    for (x = x1; x <= x2; x++, t++) {
		if (*t == racial_symbol[i]) {
		    /* Place a monster */
		    place_monster_aux(y, x, get_mon_num_quick(temp), FALSE,
				      FALSE);
		}
	    }
	}
    }

    /* Clear any current monster restrictions. */
    if (get_mon_num_hook) {
	get_mon_num_hook = NULL;
	get_mon_num_prep();
    }
}
Beispiel #13
0
/*
 * Actually read the savefile
 */
static errr rd_savefile_new_aux(void)
{
	int i, j;
	int town_count;

	s32b wild_x_size;
	s32b wild_y_size;

	byte tmp8u;
	u16b tmp16u;
	u32b tmp32u;
	u16b tmp_k_idx;

#ifdef VERIFY_CHECKSUMS
	u32b n_x_check, n_v_check;
	u32b o_x_check, o_v_check;
#endif


	/* Mention the savefile version */
#ifdef JP
	note(format("バージョン %d.%d.%d のセーブ・ファイルをロード中...",
#else
	note(format("Loading a %d.%d.%d savefile...",
#endif
		sf_major, sf_minor, sf_patch));

	/* Strip the version bytes */
	strip_bytes(4);

	/* Hack -- decrypt */
	xor_byte = sf_extra;


	/* Clear the checksums */
	v_check = 0L;
	x_check = 0L;

#if SAVEFILE_VERSION
	/* Read the version number of the savefile */
	rd_u32b(&sf_version);
#endif /* SAVEFILE_VERSION */

	/* Operating system info */
	rd_u32b(&sf_xtra);

	/* Time of savefile creation */
	rd_u32b(&sf_when);

	/* Number of resurrections */
	rd_u16b(&sf_lives);

	/* Number of times played */
	rd_u16b(&sf_saves);


	/* Later use (always zero) */
	rd_u32b(&tmp32u);

	/* Later use (always zero) */
	rd_u16b(&tmp16u);

	/* Later use (always zero) */
	rd_byte(&tmp8u);

	/* Kanji code */
	rd_byte(&kanji_code);


	/* Read RNG state */
	rd_randomizer();
#ifdef JP
	if (arg_fiddle) note("乱数情報をロードしました");
#else
	if (arg_fiddle) note("Loaded Randomizer Info");
#endif


	/* Then the options */
	rd_options();
#ifdef JP
	if (arg_fiddle) note("オプションをロードしました");
#else
	if (arg_fiddle) note("Loaded Option Flags");
#endif

	/*
	 * Munchkin players are marked
	 *
	 * XXX - should be replaced with a better method,
	 * after the new scorefile-handling is implemented.
	 */
	if (munchkin_death)
	{
		/* Mark savefile */
		noscore |= 0x0001;
	}

	/* Then the "messages" */
	rd_messages();
#ifdef JP
	if (arg_fiddle) note("メッセージをロードしました");
#else
	if (arg_fiddle) note("Loaded Messages");
#endif


	/* Monster Memory */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > max_r_idx)
	{
#ifdef JP
		note(format("モンスターの種族が多すぎる(%u)!", tmp16u));
#else
		note(format("Too many (%u) monster races!", tmp16u));
#endif
		return (21);
	}

	/* Read the available records */
	for (i = 0; i < tmp16u; i++)
	{
		/* Read the lore */
		rd_lore(i);
	}

#ifdef JP
	if (arg_fiddle) note("モンスターの思い出をロードしました");
#else
	if (arg_fiddle) note("Loaded Monster Memory");
#endif

	/* Object Memory */
	rd_u16b(&tmp_k_idx);

	/* Incompatible save files */
	if (tmp_k_idx > max_k_idx)
	{
#ifdef JP
		note(format("アイテムの種類が多すぎる(%u)!", tmp16u));
#else
		note(format("Too many (%u) object kinds!", tmp16u));
#endif
		return (22);
	}

	/* Make array for object memory */
	C_MAKE(obj_mem, tmp_k_idx, byte);

	/* Read the object memory */
	for (i = 0; i < tmp_k_idx; i++)
	{
#if 0
		byte tmp8u;
		object_kind *k_ptr = &k_info[i];

		rd_byte(&tmp8u);

		k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
		k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
#else
		rd_byte(&obj_mem[i]);
#endif
	}
#ifdef JP
	if (arg_fiddle) note("アイテムの記録をロードしました");
#else
	if (arg_fiddle) note("Loaded Object Memory");
#endif

#if 0
	/*
	 * Initialize arena and rewards information
	 */
	p_ptr->arena_number = 0;
	p_ptr->inside_arena = 0;
	p_ptr->inside_quest = 0;
	p_ptr->exit_bldg = TRUE;

	/* Start in town 1 */
	p_ptr->town_num = 1;

	p_ptr->wilderness_x = 4;
	p_ptr->wilderness_y = 4;
#endif

	/* Init the wilderness seeds */
	for (i = 0; i < max_wild_x; i++)
	{
		for (j = 0; j < max_wild_y; j++)
		{
			wilderness[j][i].seed = randint0(0x10000000);
		}
	}

	/* 2.1.3 or newer version */
	{
		u16b max_towns_load;
		u16b max_quests_load;
		byte max_rquests_load;

		/* Number of towns */
		rd_u16b(&max_towns_load);

		/* Incompatible save files */
		if (max_towns_load > max_towns)
		{
#ifdef JP
			note(format("町が多すぎる(%u)!", max_towns_load));
#else
			note(format("Too many (%u) towns!", max_towns_load));
#endif
			return (23);
		}

		/* Number of quests */
		rd_u16b(&max_quests_load);
		rd_byte(&max_rquests_load);

		/* Incompatible save files */
		if (max_quests_load > max_quests)
		{
#ifdef JP
			note(format("クエストが多すぎる(%u)!", max_quests_load));
#else
			note(format("Too many (%u) quests!", max_quests_load));
#endif
			return (23);
		}

		for (i = 0; i < max_quests_load; i++)
		{
			if (i < max_quests)
			{
				rd_s16b(&quest[i].status);
				rd_s16b(&quest[i].level);
				rd_byte(&quest[i].complev);

				/* Load quest status if quest is running */
				if ((quest[i].status == QUEST_STATUS_TAKEN)
				    || (quest[i].status == QUEST_STATUS_COMPLETED)
				    || ((i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
				{
					rd_s16b(&quest[i].cur_num);
					rd_s16b(&quest[i].max_num);
					rd_s16b(&quest[i].type);

					/* Load quest monster index */
					rd_s16b(&quest[i].r_idx);

					if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
					{
						int r_idx;
						while (1)
						{
							monster_race *r_ptr;

							/*
							 * Random monster 5 - 10 levels out of depth
							 * (depending on level)
							 */
							r_idx = get_mon_num(quest[i].level + 10);
							r_ptr = &r_info[r_idx];

							if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;

							if (r_ptr->flags1 & RF1_QUESTOR) continue;
							if (r_ptr->level >= quest[i].level + 5) continue;
							if (r_ptr->level >= quest[i].level) break;
						}

						quest[i].r_idx = r_idx;
					}

					/* Load quest item index */
					rd_s16b(&quest[i].k_idx);

					if (quest[i].k_idx)
						a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;

					/* Load quest flags */
					rd_byte(&quest[i].flags);
				}
			}
			/* Ignore the empty quests from old versions */
			else
			{
				/* Ignore quest status */
				strip_bytes(2);

				/* Ignore quest level */
				strip_bytes(2);

				/*
				 * We don't have to care about the other info,
				 * since status should be 0 for these quests anyway
				 */
			}
		}

		/* Position in the wilderness */
		rd_s32b(&p_ptr->wilderness_x);
		rd_s32b(&p_ptr->wilderness_y);

		/* Size of the wilderness */
		rd_s32b(&wild_x_size);
		rd_s32b(&wild_y_size);

		/* Incompatible save files */
		if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
		{
#ifdef JP
			note(format("荒野が大きすぎる(%u/%u)!", wild_x_size, wild_y_size));
#else
			note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
#endif
			return (23);
		}

		/* Load the wilderness seeds */
		for (i = 0; i < wild_x_size; i++)
		{
			for (j = 0; j < wild_y_size; j++)
			{
				rd_u32b(&wilderness[j][i].seed);
			}
		}
	}

#ifdef JP
	if (arg_fiddle) note("クエスト情報をロードしました");
#else
	if (arg_fiddle) note("Loaded Quests");
#endif

	/* Load the Artifacts */
	rd_u16b(&tmp16u);

	/* Incompatible save files */
	if (tmp16u > max_a_idx)
	{
#ifdef JP
		note(format("伝説のアイテムが多すぎる(%u)!", tmp16u));
#else
		note(format("Too many (%u) artifacts!", tmp16u));
#endif
		return (24);
	}

	/* Read the artifact flags */
	for (i = 0; i < tmp16u; i++)
	{
		rd_byte(&tmp8u);
		a_info[i].cur_num = tmp8u;

		rd_byte(&tmp8u);
		rd_byte(&tmp8u);
		rd_byte(&tmp8u);
	}
#ifdef JP
	if (arg_fiddle) note("伝説のアイテムをロードしました");
#else
	if (arg_fiddle) note("Loaded Artifacts");
#endif


	/* Read the extra stuff */
	rd_extra();
#ifdef JP
	if (arg_fiddle) note("特別情報をロードしました");
#else
	if (arg_fiddle) note("Loaded extra information");
#endif

	/* Read the player_hp array */
	rd_u16b(&tmp16u);

	/* Remark questor flag on random quester */
	if (!death)
	{
		for (i = MIN_RANDOM_QUEST; i <= MAX_RANDOM_QUEST; i++)
		{
			r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
		}
	}

	/* Incompatible save files */
	if (tmp16u > PY_MAX_LEVEL)
	{
#ifdef JP
		note(format("ヒットポイント配列が大きすぎる(%u)!", tmp16u));
#else
		note(format("Too many (%u) hitpoint entries!", tmp16u));
#endif
		return (25);
	}

	/* Read the player_hp array */
	for (i = 0; i < tmp16u; i++)
	{
		rd_s16b(&player_hp[i]);
	}


	/* Important -- Initialize the sex */
	sp_ptr = &sex_info[p_ptr->psex];

	/* Important -- Initialize the race/class */
	rp_ptr = &race_info[p_ptr->prace];
	cp_ptr = &class_info[p_ptr->pclass];

	/* Important -- Initialize the magic */
	mp_ptr = &m_info[p_ptr->pclass];


	/* Read spell info */
	rd_u32b(&spell_learned1);
	rd_u32b(&spell_learned2);
	rd_u32b(&spell_worked1);
	rd_u32b(&spell_worked2);
	rd_u32b(&spell_forgotten1);
	rd_u32b(&spell_forgotten2);

	for (i = 0; i < 64; i++)
	{
		rd_byte(&spell_order[i]);
	}


	/* Read the inventory */
	if (rd_inventory())
	{
#ifdef JP
		note("持ち物情報を読み込むことができません");
#else
		note("Unable to read inventory");
#endif
		return (21);
	}

	/* Read number of towns */
	rd_u16b(&tmp16u);
	town_count = tmp16u;

	/* Read the stores */
	rd_u16b(&tmp16u);
	for (i = 1; i < town_count; i++)
	{
		for (j = 0; j < tmp16u; j++)
		{
			if (rd_store(i, j)) return (22);
		}
	}

	for (i = 0; i < tmp_k_idx; i++)
	{
		byte tmp8u = obj_mem[i];
		object_kind *k_ptr = &k_info[i];

		k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
		k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
	}

	/* Free array for object memories */
	C_KILL(obj_mem, tmp_k_idx, byte);


	/* Read the pet command settings */
	if (sf_version > 2)
	{
		rd_s16b(&p_ptr->pet_follow_distance);
		rd_byte(&p_ptr->pet_open_doors);
		rd_byte(&p_ptr->pet_pickup_items);
	}
	else
	{
		rd_byte(&tmp8u);

		p_ptr->pet_follow_distance = tmp8u;

		rd_byte(&p_ptr->pet_open_doors);
		rd_byte(&p_ptr->pet_pickup_items);
	}

	/* I'm not dead yet... */
	if (!death)
	{
		/* Dead players have no dungeon */
#ifdef JP
		note("ダンジョン復元中...");
#else
		note("Restoring Dungeon...");
#endif

		if (rd_dungeon())
		{
#ifdef JP
			note("ダンジョンデータ読み込み失敗");
#else
			note("Error reading dungeon data");
#endif
			return (34);
		}

		/* Read the ghost info */
		rd_ghost();

		{
			s32b tmp32s;

			rd_s32b(&tmp32s);
			strip_bytes(tmp32s);
		}
	}


#ifdef VERIFY_CHECKSUMS

	/* Save the checksum */
	n_v_check = v_check;

	/* Read the old checksum */
	rd_u32b(&o_v_check);

	/* Verify */
	if (o_v_check != n_v_check)
	{
#ifdef JP
		note("チェックサムがおかしい");
#else
		note("Invalid checksum");
#endif
		return (11);
	}


	/* Save the encoded checksum */
	n_x_check = x_check;

	/* Read the checksum */
	rd_u32b(&o_x_check);


	/* Verify */
	if (o_x_check != n_x_check)
	{
#ifdef JP
		note("エンコードされたチェックサムがおかしい");
#else
		note("Invalid encoded checksum");
#endif
		return (11);
	}

#endif

	/* Success */
	return (0);
}
Beispiel #14
0
bool quest_poison_gen_hook(char *fmt)
{
	int cy = 1, cx = 1, x, y, try = 10000, r_idx;
	bool (*old_get_mon_num_hook)(int r_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;

	/* Find a good position */
	while (try)
	{
		/* Get a random spot */
		cy = randint(cur_hgt - 24) + 22;
		cx = randint(cur_wid - 34) + 32;

		/* Is it a good spot ? */
		if (cave_empty_bold(cy, cx)) break;

		/* One less try */
		try--;
	}

	/* Place the baddies */

	/* Backup the old hook */
	old_get_mon_num_hook = get_mon_num_hook;

	/* Require "okay" monsters */
	get_mon_num_hook = create_molds_hook;

	/* Prepare allocation table */
	get_mon_num_prep();

	/* Pick a monster, using the level calculation */
	for (x = cx - 25; x <= cx + 25; x++)
		for (y = cy - 25; y <= cy + 25; y++)
		{
			if (!in_bounds(y, x)) continue;

			if (distance(cy, cx, y, x) > 25) continue;

			if (magik(80) && ((cave[y][x].feat == FEAT_DEEP_WATER) || (cave[y][x].feat == FEAT_SHAL_WATER))) cave_set_feat(y, x, FEAT_TAINTED_WATER);

			if (distance(cy, cx, y, x) > 10) continue;

			if (magik(60))
			{
				int m_idx;

				r_idx = get_mon_num(30);
				m_idx = place_monster_one(y, x, r_idx, 0, FALSE, MSTATUS_ENEMY);

				/* Sometimes make it up some levels */
				if (magik(80) && m_idx)
				{
					monster_type *m_ptr = &m_list[m_idx];

					if (m_ptr->level < p_ptr->lev)
					{
						m_ptr->exp = MONSTER_EXP(m_ptr->level + randint(p_ptr->lev - m_ptr->level));
						monster_check_experience(m_idx, TRUE);
					}
				}
			}
		}

	/* Reset restriction */
	get_mon_num_hook = old_get_mon_num_hook;

	/* Prepare allocation table */
	get_mon_num_prep();

	return FALSE;
}
bool quest_poison_finish_hook(char *fmt)
{
	object_type forge, *q_ptr;
	s32b q_idx;

	q_idx = get_next_arg(fmt);

	if (q_idx != QUEST_POISON) return FALSE;

	c_put_str(TERM_YELLOW, "The water is clean again! Thank you so much.", 8, 0);
	c_put_str(TERM_YELLOW, "The beautiful Mallorns are safe. Take this as a proof of our gratitude.", 9, 0);

	q_ptr = &forge;
	object_prep(q_ptr, lookup_kind(TV_DRAG_ARMOR, SV_DRAGON_BLUE));
	q_ptr->found = OBJ_FOUND_REWARD;
	q_ptr->number = 1;
	q_ptr->name2 = EGO_ELVENKIND;
	apply_magic(q_ptr, 1, FALSE, FALSE, FALSE);
	object_aware(q_ptr);
	object_known(q_ptr);
	q_ptr->ident |= IDENT_STOREB;
	(void)inven_carry(q_ptr, FALSE);

	/* Continue the plot */
	*(quest[q_idx].plot) = QUEST_NULL;

	del_hook(HOOK_QUEST_FINISH, quest_poison_finish_hook);
	process_hooks_restart = TRUE;

	return TRUE;
}
Beispiel #15
0
/**
 * Attempts to place a monster of the given race at the given location.
 *
 * Note that certain monsters are placed with a large group of
 * identical or similar monsters. However, if `group_okay` is false,
 * then such monsters are placed by themselves.
 *
 * If `sleep` is true, the monster is placed with its default sleep value,
 * which is given in monster.txt.
 *
 * `origin` is the item origin to use for any monster drops (e.g. ORIGIN_DROP,
 * ORIGIN_DROP_PIT, etc.) 
 *
 * Note the "bizarre" use of non-recursion to prevent annoying output
 * when running a code profiler.
 *
 * Note the use of the "monster allocation table" to restrict
 * the "get_mon_num()" function to "legal" escort types.
 */
bool place_new_monster(struct cave *c, int y, int x, int r_idx, bool sleep,
	bool group_okay, byte origin)
{
	int i;

	monster_race *r_ptr;

	assert(c);
	
	assert(r_idx > 0);
	r_ptr = &r_info[r_idx];
	
	/* Place one monster, or fail */
	if (!place_new_monster_one(y, x, r_ptr, sleep, origin)) return (FALSE);

	/* We're done unless the group flag is set */
	if (!group_okay) return (TRUE);

	/* Friends for certain monsters */
	if (rf_has(r_ptr->flags, RF_FRIEND)) {
		int total = group_size_2(r_ptr);
		(void)place_new_monster_group(c, y, x, r_ptr, sleep, total, origin);
	}

	/* Friends for certain monsters */
	if (rf_has(r_ptr->flags, RF_FRIENDS)) {
		int total = group_size_1(r_ptr);
		(void)place_new_monster_group(c, y, x, r_ptr, sleep, total, origin);
	}

	/* Escorts for certain monsters */
	if (rf_has(r_ptr->flags, RF_ESCORT)) {
		/* Try to place several "escorts" */
		for (i = 0; i < 50; i++) {
			int nx, ny, z, d = 3;
			monster_race *z_ptr;

			/* Pick a location */
			scatter(&ny, &nx, y, x, d, 0);

			/* Require empty grids */
			if (!cave_empty_bold(ny, nx)) continue;

			/* Set the escort index */
			place_monster_idx = r_idx;

			/* Set the escort hook */
			get_mon_num_hook = place_monster_okay;

			/* Prepare allocation table */
			get_mon_num_prep();

			/* Pick a random race */
			z = get_mon_num(r_ptr->level);

			/* Remove restriction */
			get_mon_num_hook = NULL;

			/* Prepare allocation table */
			get_mon_num_prep();

			/* Handle failure */
			if (!z) break;

			/* Place a single escort */
			z_ptr = &r_info[z];
			(void)place_new_monster_one(ny, nx, z_ptr, sleep, origin);

			/* Place a "group" of escorts if needed */
			if (rf_has(z_ptr->flags, RF_FRIEND)) {
				int total = group_size_2(z_ptr);
				(void)place_new_monster_group(c, ny, nx, z_ptr, sleep, total, origin);
			}
			
			if (rf_has(z_ptr->flags, RF_FRIENDS) || rf_has(r_ptr->flags, RF_ESCORTS)) {
				int total = group_size_1(z_ptr);
				(void)place_new_monster_group(c, ny, nx, z_ptr, sleep, total, origin);
			}
		}
	}

	/* Success */
	return (TRUE);
}
Beispiel #16
0
/*
 * Show what monster races appear on the current level
 */
static void spoil_mon_gen(cptr fname)
{
	int i, num;

	/* Storage */
	u32b monster[1000];
	u32b depth[MAX_DEPTH];

	char buf[1024];

	/* We use either ascii or system-specific encoding */
	int encoding = (xchars_to_file) ? SYSTEM_SPECIFIC : ASCII;


	/* Build the filename */
	(void)path_build(buf, sizeof(buf), ANGBAND_DIR_INFO, fname);

	/* File type is "TEXT" */
	FILE_TYPE(FILE_TYPE_TEXT);

	/* Open the file */
	fff = my_fopen(buf, "w");

	/* Oops */
	if (!fff)
	{
		msg_print("Cannot create spoiler file.");
		return;
	}

	/* Dump to the spoiler file */
	text_out_hook = text_out_to_file;
	text_out_file = fff;

	/* Print header */
	print_header("Monster Generation");

	/* Clear storage. */
	for (i = 0; i < z_info->r_max; i++)
	{
		monster[i] = 0L;
	}

	/* Clear storage. */
	for (i = 0; i < MAX_DEPTH; i++)
	{
		depth[i] = 0L;
	}

	msg_print("This may take a while...");
	if (!fresh_after) (void)Term_fresh();

	/* Make a lot of monsters, and print their names out. */
	for (i = 0L; i < 1000000L; i++)
	{
		if (i % 10000 == 0)
		{
			prt(format("%ld monsters created", (long)i), 0, 0);
			if (!fresh_after) (void)Term_fresh();
		}

		/* Get a monster index */
		num = get_mon_num(p_ptr->depth);

		/* Count monster races. */
		monster[num] += 1L;

		/* Count monsters of that level. */
		depth[r_info[num].level] += 1L;
	}

	/* Print to file. */
	fprintf(fff, "\n\n\n");
	fprintf(fff, "Number of monsters of various kinds (1,000,000 total)\n");
	fprintf(fff, "         Generation Level:  %d\n\n", p_ptr->depth);

	for (i = 1; i < z_info->r_max; i++)
	{
		monster_race *r_ptr = &r_info[i];

		cptr name = (r_name + r_ptr->name);

		if (monster[i])
		{
			x_fprintf(fff, encoding, "%-45s:%6ld\n", name, (long)monster[i]);
		}
	}

	fprintf(fff, "\n\n\n");
	fprintf(fff, "Monster distribution by depth\n\n");

	for (i = 0; i < MAX_DEPTH; i++)
	{
		if (depth[i]) fprintf(fff, "Level %3d:%6ld\n", i, (long)depth[i]);
	}


	/* Check for errors */
	if (ferror(fff) || my_fclose(fff))
	{
		msg_print("Cannot close spoiler file.");
		return;
	}

	/* Message */
	msg_print("Successfully created a spoiler file.");
}