Esempio n. 1
0
/*
 * Initialize a new 'infoclr' with a real GC.
 */
static errr Infoclr_init_1(GC gc)
{
	infoclr *iclr = Infoclr;

	/* Wipe the iclr clean */
	(void)WIPE(iclr, infoclr);

	/* Assign the GC */
	iclr->gc = gc;

	/* Success */
	return (0);
}
Esempio n. 2
0
/*
 * Init an infowin by giving some data.
 *
 * Inputs:
 *	dad: The Window that should own this Window (if any)
 *	x,y: The position of this Window
 *	w,h: The size of this Window
 *	b,d: The border width and pixel depth
 *
 * Notes:
 *	If 'dad == None' assume 'dad == root'
 */
static errr Infowin_init_data(Window dad, int x, int y, int w, int h,
                              int b, Pixell fg, Pixell bg)
{
	Window xid;

	/* Wipe it clean */
	(void)WIPE(Infowin, infowin);


	/*** Error Check XXX ***/


	/*** Create the Window 'xid' from data ***/

	/* What happened here?  XXX XXX XXX */

	/* If no parent given, depend on root */
	if (dad == None)

/* #ifdef USE_GRAPHICS

		xid = XCreateWindow(Metadpy->dpy, Metadpy->root, x, y, w, h, b, 8, InputOutput, CopyFromParent, 0, 0);

	else
*/

/* #else */

		dad = Metadpy->root;

/* #endif */

	/* Create the Window XXX Error Check */
	xid = XCreateSimpleWindow(Metadpy->dpy, dad, x, y, w, h, b, fg, bg);

	/* Start out selecting No events */
	XSelectInput(Metadpy->dpy, xid, 0L);


	/*** Prepare the new infowin ***/

	/* Mark it as nukable */
	Infowin->nuke = 1;

	/* Attempt to Initialize the infowin */
	return (Infowin_prepare(xid));
}
Esempio n. 3
0
/**
 * Display list of places to jump to.
 */
bool jump_menu(int level, int *location)
{
	menu_type menu;
	menu_iter menu_f = { jump_tag, 0, jump_display, jump_action, 0 };
	region area = { 15, 1, 48, -1 };
	ui_event evt = { 0 };
	int cursor = 0, j = 0;
	size_t i;
	u16b *choice;

	/* Create the array */
	choice = C_ZNEW(15, u16b);

	/* Get the possible stages */
	//for (i = 0; i < NUM_STAGES; i++)
	//if ((stage_map[i][DEPTH] == level) && (stage_map[i][LOCALITY] != 0))
//      choice[j++] = i;

	/* Clear space */
	area.page_rows = j + 2;

	/* Save the screen and clear it */
	screen_save();

	/* Set up the menu */
	WIPE(&menu, menu);
	menu.title = "Which region do you want to be transported to?";
	menu.cmd_keys = " \n\r";
	menu_init(&menu, MN_SKIN_SCROLL, &menu_f);
	menu_setpriv(&menu, j, choice);
	menu_layout(&menu, &area);

	/* Select an entry */
	evt = menu_select(&menu, cursor, TRUE);

	/* Set it */
	if (evt.type == EVT_SELECT)
		*location = place;

	/* Free memory */
	FREE(choice);

	/* Load screen */
	screen_load();
	return (evt.type != EVT_ESCAPE);
}
Esempio n. 4
0
/*
 * Init an infofnt by its Name
 *
 * Inputs:
 *	name: The name of the requested Font
 */
static errr Infofnt_init_data(cptr name)
{
	XFontStruct *info;


	/*** Load the info Fresh, using the name ***/

	/* If the name is not given, report an error */
	if (!name) return (-1);

	/* Attempt to load the font */
	info = XLoadQueryFont(Metadpy->dpy, name);

	/* The load failed, try to recover */
	if (!info) return (-1);


	/*** Init the font ***/

	/* Wipe the thing */
	(void)WIPE(Infofnt, infofnt);

	/* Attempt to prepare it */
	if (Infofnt_prepare(info))
	{
		/* Free the font */
		XFreeFont(Metadpy->dpy, info);

		/* Fail */
		return (-1);
	}

	/* Save a copy of the font name */
	Infofnt->name = string_make(name);

	/* Mark it as nukable */
	Infofnt->nuke = 1;

	/* Success */
	return (0);
}
Esempio n. 5
0
/*
 * Prepare an object based on an object kind.
 * Use the specified randomization aspect
 */
void object_prep(object_type *o_ptr, int k_idx, int lev, aspect rand_aspect)
{
	object_kind *k_ptr = &k_info[k_idx];

	/* Clear the record */
	(void)WIPE(o_ptr, object_type);

	/* Save the kind index */
	o_ptr->k_idx = k_idx;

	/* Efficiency -- tval/sval */
	o_ptr->tval = k_ptr->tval;
	o_ptr->sval = k_ptr->sval;

	/* Default number */
	o_ptr->number = 1;

	/* Default "pval" */
	o_ptr->pval = randcalc(k_ptr->pval, lev, rand_aspect);

	/* Default weight */
	o_ptr->weight = k_ptr->weight;
	
	/* Assign charges (wands/staves only) */
	if (o_ptr->tval == TV_WAND || o_ptr->tval == TV_STAFF)
		o_ptr->pval = randcalc(k_ptr->charge, lev, rand_aspect);

	/* Default magic */
	o_ptr->to_h = randcalc(k_ptr->to_h, lev, rand_aspect);
	o_ptr->to_d = randcalc(k_ptr->to_d, lev, rand_aspect);
	o_ptr->to_a = randcalc(k_ptr->to_a, lev, rand_aspect);

	/* Default power */
	o_ptr->ac = k_ptr->ac;
	o_ptr->dd = k_ptr->dd;
	o_ptr->ds = k_ptr->ds;

	/* Hack -- cursed items are always "cursed" */
	if (of_has(k_ptr->flags, OF_LIGHT_CURSE))
	    of_on(o_ptr->flags, OF_LIGHT_CURSE);
}
Esempio n. 6
0
static void build_score(high_score *entry, const char *died_from, time_t *death_time)
{
	WIPE(entry, high_score);

	/* Save the version */
	strnfmt(entry->what, sizeof(entry->what), "%s", VERSION_STRING);

	/* Calculate and save the points */
	strnfmt(entry->pts, sizeof(entry->pts), "%9lu", (long)total_points());

	/* Save the current gold */
	strnfmt(entry->gold, sizeof(entry->gold), "%9lu", (long)p_ptr->au);

	/* Save the current turn */
	strnfmt(entry->turns, sizeof(entry->turns), "%9lu", (long)turn);

	/* Time of death */
	if (death_time)
		strftime(entry->day, sizeof(entry->day), "@%Y%m%d", localtime(death_time));
	else
		my_strcpy(entry->day, "TODAY", sizeof(entry->day));

	/* Save the player name (15 chars) */
	strnfmt(entry->who, sizeof(entry->who), "%-.15s", op_ptr->full_name);

	/* Save the player info XXX XXX XXX */
	strnfmt(entry->uid, sizeof(entry->uid), "%7u", player_uid);
	strnfmt(entry->sex, sizeof(entry->sex), "%c", (p_ptr->psex ? 'm' : 'f'));
	strnfmt(entry->p_r, sizeof(entry->p_r), "%2d", p_ptr->prace);
	strnfmt(entry->p_c, sizeof(entry->p_c), "%2d", p_ptr->pclass);

	/* Save the level and such */
	strnfmt(entry->cur_lev, sizeof(entry->cur_lev), "%3d", p_ptr->lev);
	strnfmt(entry->cur_dun, sizeof(entry->cur_dun), "%3d", p_ptr->depth);
	strnfmt(entry->max_lev, sizeof(entry->max_lev), "%3d", p_ptr->max_lev);
	strnfmt(entry->max_dun, sizeof(entry->max_dun), "%3d", p_ptr->max_depth);

	/* No cause of death */
	my_strcpy(entry->how, died_from, sizeof(entry->how));
}
Esempio n. 7
0
int accept_console(int data1, data data2) {
	eptr new_connection;
	eptr new_console;
	bool old = (data1 == -1 ? TRUE : FALSE);
	connection_type *ct = NULL;
	console_connection *cn = NULL;	

	/* Add connection */
	if (!old)
	{
		new_connection = add_connection(first_connection, data1, console_read, console_close);
		if (!first_connection) first_connection = new_connection;
		ct = new_connection->data2;
	}
	/* Update connection */
	else
	{
		ct = (connection_type *)data2;
		ct->receive_cb = console_read;
		ct->close_cb = console_close;
	}

	/* Add console */
	MAKE(cn, console_connection);
	WIPE(cn, console_connection);
	new_console = e_add(first_console, ct, cn);
	if (!first_console) first_console = new_console;
	
	/* save pointer to console in connection */
	ct->uptr = (data)cn;

	/* Initial states */
	cn->auth = cn->listen = FALSE;

	/* Inform */
	cq_printf(&ct->wbuf, "%T", "Connected\n");

	return 0;
}
Esempio n. 8
0
/**
 * Deletes all the monsters when the player leaves the level.
 *
 * This is an efficient method of simulating multiple calls to the
 * "delete_monster()" function, with no visual effects.
 *
 * Note that we do not delete the objects the monsters are carrying;
 * that must be taken care of separately via wipe_o_list().
 */
void wipe_mon_list(struct cave *c, struct player *p)
{
	int m_idx;

	/* Delete all the monsters */
	for (m_idx = cave_monster_max(cave) - 1; m_idx >= 1; m_idx--)
	{
		monster_type *m_ptr = cave_monster(cave, m_idx);

		monster_race *r_ptr = &r_info[m_ptr->r_idx];

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

		/* Hack -- Reduce the racial counter */
		r_ptr->cur_num--;

		/* Monster is gone */
		c->m_idx[m_ptr->fy][m_ptr->fx] = 0;

		/* Wipe the Monster */
		(void)WIPE(m_ptr, monster_type);
	}

	/* Reset "cave->mon_max" */
	cave->mon_max = 1;

	/* Reset "mon_cnt" */
	cave->mon_cnt = 0;

	/* Hack -- reset "reproducer" count */
	num_repro = 0;

	/* Hack -- no more target */
	target_set_monster(0);

	/* Hack -- no more tracking */
	health_track(p, 0);
}
Esempio n. 9
0
/**
* Display a list of commands.
*/
bool show_cmd_menu(bool object)
{
    menu_type menu;
    menu_iter commands_menu = { show_tag, 0, show_display, show_action, 0 };
    region area = { 0, (object ? 2 : 1), 20, 0 };

    ui_event_data evt = EVENT_EMPTY;
    int cursor = 0;

    /* Size of menu */
    area.page_rows = poss + (object ? 1 : 0);

    /* Set up the menu */
    WIPE(&menu, menu);
    menu.cmd_keys = "\x8B\x8C\n\r";
    menu.count = poss;
    menu.menu_data = comm;
    menu_init(&menu, MN_SKIN_SCROLL, &commands_menu);

    /* Select an entry */
    evt = menu_select(&menu, cursor);

    return (evt.type != EVT_ESCAPE);
}
Esempio n. 10
0
/*
 * Clear all the global "character" data
 */
static void player_wipe(void)
{
	int i;
	char history[250];
	int stat[A_MAX];

	/* Backup the player choices */
	// Initialized to soothe compilation warnings
	byte psex = 0;
	byte prace = 0;
	byte phouse = 0;
	int age = 0;
	int height = 0;
	int weight = 0;
		
	// only save the old information if there was a character loaded
	if (character_loaded_dead)
	{
		/* Backup the player choices */
		psex = p_ptr->psex;
		prace = p_ptr->prace;
		phouse = p_ptr->phouse;
		age = p_ptr->age;
		height = p_ptr->ht;
		weight = p_ptr->wt;
		sprintf(history, "%s", p_ptr->history);
		for (i = 0; i < A_MAX; i++)
		{
			stat[i] = p_ptr->stat_base[i] - (rp_ptr->r_adj[i] + hp_ptr->h_adj[i]);
		}
	}

	/* Wipe the player */
	(void)WIPE(p_ptr, player_type);

	// only save the old information if there was a character loaded
	if (character_loaded_dead)
	{
		/* Restore the choices */
		p_ptr->psex = psex;
		p_ptr->prace = prace;
		p_ptr->phouse = phouse;
		p_ptr->game_type = 0;
		p_ptr->age = age;
		p_ptr->ht = height;
		p_ptr->wt = weight;
		sprintf(p_ptr->history, "%s", history);
		for (i = 0; i < A_MAX; i++)
		{
			p_ptr->stat_base[i] = stat[i];
		}
	}
	else
	{
		/* Reset */
		p_ptr->psex = SEX_UNDEFINED;
		p_ptr->prace = 0;
		p_ptr->phouse = 0;
		p_ptr->game_type = 0;
		p_ptr->age = 0;
		p_ptr->ht = 0;
		p_ptr->wt = 0;
		p_ptr->history[0] = '\0';
		for (i = 0; i < A_MAX; i++)
		{
			p_ptr->stat_base[i] = 0;
		}
	}
	

	/* Clear the inventory */
	for (i = 0; i < INVEN_TOTAL; i++)
	{
		object_wipe(&inventory[i]);
	}

	/* Start with no artefacts made yet */
	/* and clear the slots for in-game randarts */
	for (i = 0; i < z_info->art_max; i++)
	{
		artefact_type *a_ptr = &a_info[i];

		a_ptr->cur_num = 0;
		a_ptr->found_num = 0;
	}

	/*re-set the object_level*/
	object_level = 0;

	/* Reset the "objects" */
	for (i = 1; i < z_info->k_max; i++)
	{
		object_kind *k_ptr = &k_info[i];

		/* Reset "tried" */
		k_ptr->tried = FALSE;

		/* Reset "aware" */
		k_ptr->aware = FALSE;
	}


	/* Reset the "monsters" */
	for (i = 1; i < z_info->r_max; i++)
	{
		monster_race *r_ptr = &r_info[i];
		monster_lore *l_ptr = &l_list[i];

		/* Hack -- Reset the counter */
		r_ptr->cur_num = 0;

		/* Hack -- Reset the max counter */
		r_ptr->max_num = 100;

		/* Hack -- Reset the max counter */
		if (r_ptr->flags1 & (RF1_UNIQUE)) r_ptr->max_num = 1;

		/* Clear player sights/kills */
		l_ptr->psights = 0;
		l_ptr->pkills = 0;
	}

	/*No current player ghosts*/
	bones_selector = 0;

	// give the player the most food possible without a message showing
	p_ptr->food = PY_FOOD_FULL - 1;
	
	// reset the stair info
	p_ptr->stairs_taken = 0;
	p_ptr->staircasiness = 0;

	// reset the forge info
	p_ptr->forge_drought = 5000;
	p_ptr->forge_count = 0;

	/*re-set the thefts counter*/
	recent_failed_thefts = 0;

	/*re-set the altered inventory counter*/
	allow_altered_inventory = 0;

	// reset some unique flags
	p_ptr->unique_forge_made = FALSE;
	p_ptr->unique_forge_seen = FALSE;
	for (i = 0; i < MAX_GREATER_VAULTS; i++)
	{
		p_ptr->greater_vaults[i] = 0;
	}
	
}
Esempio n. 11
0
/*
 * Read the dungeon
 *
 * The monsters/objects must be loaded in the same order
 * that they were stored, since the actual indexes matter.
 *
 * Note that the size of the dungeon is now hard-coded to
 * DUNGEON_HGT by DUNGEON_WID, and any dungeon with another
 * size will be silently discarded by this routine.
 *
 * Note that dungeon objects, including objects held by monsters, are
 * placed directly into the dungeon, using "object_copy()", which will
 * copy "iy", "ix", and "held_m_idx", leaving "next_o_idx" blank for
 * objects held by monsters, since it is not saved in the savefile.
 *
 * After loading the monsters, the objects being held by monsters are
 * linked directly into those monsters.
 */
static errr rd_dungeon(void)
{
	int i, y, x;

	s16b depth;
	s16b py, px;

	byte count;
	byte tmp8u;
	u16b tmp16u;

	u16b limit;


	/*** Basic info ***/

	/* Header info */
	rd_s16b(&depth);
	rd_u16b(&p_ptr->dungeon_type);
	/* Get dungeon capabilities */
	set_dungeon_type(p_ptr->dungeon_type);

	rd_s16b(&py);
	rd_s16b(&px);
	rd_byte(&p_ptr->cur_map_hgt);
	rd_byte(&p_ptr->cur_map_wid);
	rd_u16b(&altered_inventory_counter);
	/* Paranoia */
	allow_altered_inventory = FALSE;

	rd_u16b(&tmp16u);


	/* Ignore illegal dungeons */
	if ((depth < 0) || (depth >= MAX_DEPTH))
	{
		note(format("Ignoring illegal dungeon depth (%d)", depth));
		return (0);
	}

	/* Ignore illegal dungeons */
	if ((p_ptr->cur_map_hgt > MAX_DUNGEON_HGT) || (p_ptr->cur_map_wid > MAX_DUNGEON_WID))
	{
		/* XXX XXX XXX */
		note(format("Ignoring illegal dungeon size (%d,%d).", p_ptr->cur_map_hgt, p_ptr->cur_map_wid));
		return (0);
	}

	/* Ignore illegal dungeons */
	if ((px < 0) || (px >= p_ptr->cur_map_wid) ||
		(py < 0) || (py >= p_ptr->cur_map_hgt))
	{
		note(format("Ignoring illegal player location (%d,%d).", py, px));
		return (1);
	}


	/*** Run length decoding ***/

	/* Load the dungeon data */
	for (x = y = 0; y < p_ptr->cur_map_hgt; )
	{
		/* Grab RLE info */
		rd_byte(&count);
		rd_byte(&tmp8u);

		/* Apply the RLE info */
		for (i = count; i > 0; i--)
		{
			/* Extract "info" */
			cave_info[y][x] = tmp8u;

			/* Advance/Wrap */
			if (++x >= p_ptr->cur_map_wid)
			{
				/* Wrap */
				x = 0;

				/* Advance/Wrap */
				if (++y >= p_ptr->cur_map_hgt) break;
			}
		}
	}


	/*** Run length decoding ***/

	/* Load the dungeon data */
	for (x = y = 0; y < p_ptr->cur_map_hgt; )
	{
		/* Grab RLE info */
		rd_byte(&count);
		rd_byte(&tmp8u);

		/* Apply the RLE info */
		for (i = count; i > 0; i--)
		{
			feature_type *f_ptr;

			/* Extract "feat" */
			cave_feat[y][x] = tmp8u;

			update_los_proj_move(y, x);

			/* Get fast access to feature */
			f_ptr = &f_info[tmp8u];

			/* Handle glowing grids */
			if (_feat_ff2_match(f_ptr, FF2_GLOW))
			{
				int d;

				/* Turn on super glow */
				cave_info[y][x] |= (CAVE_HALO);

				/* Spread super glow through adjacent grids */
				for (d = 0; d < 8; d++)
				{
					/* Get coordinates */
					int yy = y + ddy_ddd[d];
					int xx = x + ddx_ddd[d];

					/* Ignore annoying locations */
					if (!in_bounds_fully(yy, xx))
					{
						continue;
					}

					/* Turn on super glow */
					cave_info[yy][xx] |= (CAVE_HALO);
				}
			}

			/* Register dynamic features */
			if (_feat_ff3_match(f_ptr, FF3_DYNAMIC))
			{
				(void)add_dynamic_terrain(y, x);
			}

			/* Update the flags of the current level */
			if (_feat_ff3_match(f_ptr, TERRAIN_MASK))
			{
				level_flag |= get_level_flag((u16b)(f_ptr - f_info));
			}

			/* Advance/Wrap */
			if (++x >= p_ptr->cur_map_wid)
			{
				/* Wrap */
				x = 0;

				/* Advance/Wrap */
				if (++y >= p_ptr->cur_map_hgt) break;
			}
		}
	}


	/*** Player ***/

	/* Load depth */
	p_ptr->depth = depth;


	/* Place player in dungeon */
	if (!player_place(py, px))
	{
		note(format("Cannot place player (%d,%d)!", py, px));
		return (-1);
	}


	/*** Objects ***/

	/* Read the item count */
	rd_u16b(&limit);

	/* Verify maximum */
	if (limit > z_info->o_max)
	{
		note(format("Too many (%d) object entries!", limit));
		return (-1);
	}

	/* Read the dungeon items */
	for (i = 1; i < limit; i++)
	{
		object_type *i_ptr;
		object_type object_type_body;

		s16b o_idx;
		object_type *o_ptr;


		/* Get the object */
		i_ptr = &object_type_body;

		/* Wipe the object */
		object_wipe(i_ptr);

		/* Read the item */
		if (rd_item(i_ptr))
		{
			note("Error reading item");
			return (-1);
		}

		/* Make an object */
		o_idx = o_pop();

		/* Paranoia */
		if (o_idx != i)
		{
			note(format("Cannot place object %d!", i));
			return (-1);
		}

		/* Get the object */
		o_ptr = &o_list[o_idx];

		/* Structure Copy */
		object_copy(o_ptr, i_ptr);

		/* Dungeon floor */
		if (!i_ptr->held_m_idx)
		{
			int x = i_ptr->ix;
			int y = i_ptr->iy;

			/* ToDo: Verify coordinates */

			/* Link the object to the pile */
			o_ptr->next_o_idx = cave_o_idx[y][x];

			/* Link the floor to the object */
			cave_o_idx[y][x] = o_idx;

			/* Rearrange stack if needed */
			rearrange_stack(y, x);
		}
	}


	/*** Monsters ***/

	/* Read the monster count */
	rd_u16b(&limit);

	/* Hack -- verify */
	if (limit > z_info->m_max)
	{
		note(format("Too many (%d) monster entries!", limit));
		return (-1);
	}

	/* Read the monsters */
	for (i = 1; i < limit; i++)
	{
		monster_type *n_ptr;
		monster_type monster_type_body;
		monster_race *r_ptr;

		int r_idx;

		/* Get local monster */
		n_ptr = &monster_type_body;

		/* Clear the monster */
		(void)WIPE(n_ptr, monster_type);

		/* Read the monster */
		rd_monster(n_ptr);

		/* Access the "r_idx" of the chosen monster */
		r_idx = n_ptr->r_idx;

		/* Access the actual race */
		r_ptr = &r_info[r_idx];

		/* If a player ghost, some special features need to be added. */
		if (r_ptr->flags2 & (RF2_PLAYER_GHOST))
		{
			(void)prepare_ghost(n_ptr->r_idx);
		}

		/* Place monster in dungeon */
		if (monster_place(n_ptr->fy, n_ptr->fx, n_ptr) != i)
		{
			note(format("Cannot place monster %d", i));
			return (-1);
		}
	}


	/*** Holding ***/

	/* Reacquire objects */
	for (i = 1; i < o_max; ++i)
	{
		object_type *o_ptr;

		monster_type *m_ptr;

		/* Get the object */
		o_ptr = &o_list[i];

		/* Ignore dungeon objects */
		if (!o_ptr->held_m_idx) continue;

		/* Verify monster index */
		if (o_ptr->held_m_idx > z_info->m_max)
		{
			note("Invalid monster index");
			return (-1);
		}

		/* Get the monster */
		m_ptr = &mon_list[o_ptr->held_m_idx];

		/* Link the object to the pile */
		o_ptr->next_o_idx = m_ptr->hold_o_idx;

		/* Link the monster to the object */
		m_ptr->hold_o_idx = i;
	}

	/*** Effects ***/
	/* Read the effect count */
	rd_u16b(&limit);

	/* Verify maximum */
	if (limit > z_info->x_max)
	{
		note(format("Too many (%d) effect entries!", limit));
		return (-1);
	}

	/* Read the dungeon items */
	for (i = 1; i < limit; i++)
	{

		/* Read the item */
		if (rd_effect())
		{
			note("Error reading effect");
			return (-1);
		}
	}


	/*** Success ***/

	/* The dungeon is ready */
	character_dungeon = TRUE;

	/* Success */
	return (0);
}
Esempio n. 12
0
/*
 * Clear all the global "character" data
 */
static void player_wipe(void)
{
    int i;

    /* Hack -- free the "last message" string */
    if (p_ptr->last_message) z_string_free(p_ptr->last_message);

    /* Hack -- zero the struct */
    (void)WIPE(p_ptr, player_type);
    p_ptr->mimic_form = MIMIC_NONE;

    /* Start with no artifacts made yet */
    for (i = 0; i < max_a_idx; i++)
    {
        artifact_type *a_ptr = &a_info[i];
        a_ptr->generated = FALSE;
        a_ptr->found = FALSE;
    }

    /* Reset the objects */
    k_info_reset();
    e_info_reset();
    stats_reset();

    /* Reset the "monsters" */
    for (i = 1; i < max_r_idx; i++)
    {
        monster_race *r_ptr = &r_info[i];

        /* Hack -- Reset the counter */
        r_ptr->cur_num = 0;

        /* Hack -- Reset the max counter */
        r_ptr->max_num = 100;
        r_ptr->flagsx = 0;

        /* Hack -- Reset the max counter */
        if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;

        /* Hack -- Non-unique Nazguls are semi-unique */
        else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
        else if (i == MON_CAMELOT_KNIGHT) r_ptr->max_num = MAX_CAMELOT_KNIGHT_NUM;

        /* Clear visible kills in this life */
        r_ptr->r_pkills = 0;

        /* Clear all kills in this life */
        r_ptr->r_akills = 0;
        r_ptr->r_skills = 0;
        r_ptr->stolen_ct = 0;

        /* Wipe out pact alliances from previous character
           Currently, flagsr is only set to make the memory field
           work, but perhaps it would be better to set this once
           and for all when a pact is made?  This would break
           my savefiles though ...*/
        r_ptr->flagsr &= ~(RFR_PACT_MONSTER);
        r_ptr->r_flagsr &= ~(RFR_PACT_MONSTER);
    }


    /* Hack -- Well fed player */
    p_ptr->food = PY_FOOD_FULL - 1;


    /* Wipe the spells */
    if (p_ptr->pclass == CLASS_SORCERER)
    {
        p_ptr->spell_learned1 = p_ptr->spell_learned2 = 0xffffffffL;
        p_ptr->spell_worked1 = p_ptr->spell_worked2 = 0xffffffffL;
    }
    else
    {
        p_ptr->spell_learned1 = p_ptr->spell_learned2 = 0L;
        p_ptr->spell_worked1 = p_ptr->spell_worked2 = 0L;
    }
    p_ptr->spell_forgotten1 = p_ptr->spell_forgotten2 = 0L;
    for (i = 0; i < 64; i++) p_ptr->spell_order[i] = 99;
    p_ptr->learned_spells = 0;
    p_ptr->add_spells = 0;
    p_ptr->knowledge = 0;

    /* Clean the mutation count */
    mutant_regenerate_mod = 100;

    /* Clear "cheat" options */
    cheat_peek = FALSE;
    cheat_hear = FALSE;
    cheat_room = FALSE;
    cheat_xtra = FALSE;
    cheat_live = FALSE;
    cheat_save = FALSE;

    /* Assume no winning game */
    p_ptr->total_winner = FALSE;

    world_player = FALSE;

    /* Assume no panic save */
    p_ptr->panic_save = 0;

    /* Assume no cheating */
    p_ptr->noscore = 0;
    p_ptr->wizard = FALSE;

    /* Not waiting to report score */
    p_ptr->wait_report_score = FALSE;

    /* Default pet command settings */
    p_ptr->pet_follow_distance = PET_FOLLOW_DIST;
    p_ptr->pet_extra_flags = (PF_TELEPORT | PF_ATTACK_SPELL | PF_SUMMON_SPELL);

    /* Wipe the recall depths */
    for (i = 0; i < max_d_idx; i++)
    {
        max_dlv[i] = 0;
        dungeon_flags[i] = 0;
    }

    p_ptr->wild_mode = FALSE;

    for (i = 0; i < MAX_MAGIC_NUM; i++)
    {
        p_ptr->magic_num1[i] = 0;
        p_ptr->magic_num2[i] = 0;
    }

    /* Level one */
    p_ptr->max_plv = p_ptr->lev = 1;

    /* Initialize arena and rewards information -KMW- */
    p_ptr->arena_number = 0;
    p_ptr->inside_arena = FALSE;
    for (i = 0; i < MAX_MANE; i++)
    {
        p_ptr->mane_spell[i] = -1;
        p_ptr->mane_dam[i] = 0;
    }
    p_ptr->mane_num = 0;
    p_ptr->exit_bldg = TRUE; /* only used for arena now -KMW- */

    /* Bounty */
    p_ptr->today_mon = 0;

    /* Reset monster arena */
    battle_monsters();

    /* Reset mutations */
    for (i = 0; i < MUT_FLAG_SIZE; ++i)
    {
        p_ptr->muta[i] = 0;
        p_ptr->muta_lock[i] = 0;
    }

    for (i = 0; i < MAX_DEMIGOD_POWERS; ++i)
        p_ptr->demigod_power[i] = -1;

    p_ptr->draconian_power = -1;

    p_ptr->duelist_target_idx = 0;

    /* Reset virtues*/
    for (i = 0; i < 8; i++) p_ptr->virtues[i]=0;

    /* Set the recall dungeon accordingly */
    if (no_wilderness)
    {
        dungeon_type = 0;
        p_ptr->recall_dungeon = DUNGEON_ANGBAND;
    }
    else
    {
        dungeon_type = 0;
        p_ptr->recall_dungeon = DUNGEON_STRONGHOLD;
    }
}
Esempio n. 13
0
/*
 * Initialize an infoclr with some data
 *
 * Inputs:
 *	fg:   The Pixell for the requested Foreground (see above)
 *	bg:   The Pixell for the requested Background (see above)
 *	op:   The Opcode for the requested Operation (see above)
 *	stip: The stipple mode
 */
static errr Infoclr_init_data(Pixell fg, Pixell bg, int op, int stip)
{
	infoclr *iclr = Infoclr;

	GC gc;
	XGCValues gcv;
	unsigned long gc_mask;



	/*** Simple error checking of opr and clr ***/

	/* Check the 'Pixells' for realism */
	if (bg > Metadpy->zg) return (-1);
	if (fg > Metadpy->zg) return (-1);

	/* Check the data for trueness */
	if ((op < 0) || (op > 15)) return (-1);


	/*** Create the requested 'GC' ***/

	/* Assign the proper GC function */
	gcv.function = op;

	/* Assign the proper GC background */
	gcv.background = bg;

	/* Assign the proper GC foreground */
	gcv.foreground = fg;

	/* Hack -- Handle XOR (xor is code 6) by hacking bg and fg */
	if (op == 6) gcv.background = 0;
	if (op == 6) gcv.foreground = (bg ^ fg);

	/* Assign the proper GC Fill Style */
	gcv.fill_style = (stip ? FillStippled : FillSolid);

	/* Turn off 'Give exposure events for pixmap copying' */
	gcv.graphics_exposures = False;

	/* Set up the GC mask */
	gc_mask = (GCFunction | GCBackground | GCForeground |
	           GCFillStyle | GCGraphicsExposures);

	/* Create the GC detailed above */
	gc = XCreateGC(Metadpy->dpy, Metadpy->root, gc_mask, &gcv);


	/*** Initialize ***/

	/* Wipe the iclr clean */
	(void)WIPE(iclr, infoclr);

	/* Assign the GC */
	iclr->gc = gc;

	/* Nuke it when done */
	iclr->nuke = 1;

	/* Assign the parms */
	iclr->fg = fg;
	iclr->bg = bg;
	iclr->code = op;
	iclr->stip = stip ? 1 : 0;

	/* Success */
	return (0);
}
Esempio n. 14
0
/**
 * Deletes a monster by index.
 *
 * When a monster is deleted, all of its objects are deleted.
 */
void delete_monster_idx(int m_idx)
{
	int x, y;
	s16b this_o_idx, next_o_idx = 0;
	monster_type *m_ptr;

	assert(m_idx > 0);

	m_ptr = cave_monster(cave, m_idx);

	/* Monster location */
	y = m_ptr->fy;
	x = m_ptr->fx;

	/* Hack -- Reduce the racial counter */
	m_ptr->race->cur_num--;

	/* Hack -- count the number of "reproducers" */
	if (rf_has(m_ptr->race->flags, RF_MULTIPLY)) num_repro--;

	/* Hack -- remove target monster */
	if (target_get_monster() == m_ptr) target_set_monster(NULL);

	/* Hack -- remove tracked monster */
	if (p_ptr->health_who == m_ptr) health_track(p_ptr, NULL);

	/* Monster is gone */
	cave->m_idx[y][x] = 0;

	/* Delete objects */
	for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
	{
		object_type *o_ptr;

		/* Get the object */
		o_ptr = object_byid(this_o_idx);

		/* Get the next object */
		next_o_idx = o_ptr->next_o_idx;

		/* Preserve unseen artifacts (we assume they were created as this
		 * monster's drop) - this will cause unintended behaviour in preserve
		 * off mode if monsters can pick up artifacts */
		if (o_ptr->artifact && !object_was_sensed(o_ptr))
			o_ptr->artifact->created = FALSE;

		/* Clear held_m_idx now to avoid wasting time in delete_object_idx */
		o_ptr->held_m_idx = 0;

		/* Delete the object */
		delete_object_idx(this_o_idx);
	}

	/* Delete mimicked objects */
	if (m_ptr->mimicked_o_idx > 0)
		delete_object_idx(m_ptr->mimicked_o_idx);

	/* Wipe the Monster */
	(void)WIPE(m_ptr, monster_type);

	/* Count monsters */
	cave->mon_cnt--;

	/* Visual update */
	cave_light_spot(cave, y, x);
}
Esempio n. 15
0
/*
 * Enters a players name on a hi-score table, if "legal", and in any
 * case, displays some relevant portion of the high score list.
 *
 * Assumes "signals_ignore_tstp()" has been called.
 */
errr top_twenty(void)
{
    int          j;

    high_score   the_score;

    time_t ct = time((time_t*)0);

    errr err;

    /* Clear the record */
    (void)WIPE(&the_score, high_score);

    /* Save the version */
    sprintf(the_score.what, "%u.%u.%u",
        VER_MAJOR, VER_MINOR, VER_PATCH);

    /* Calculate and save the points */
    sprintf(the_score.pts, "%9ld", (long)total_points());
    the_score.pts[9] = '\0';

    /* Save the current gold */
    sprintf(the_score.gold, "%9d", p_ptr->au);
    the_score.gold[9] = '\0';

    /* Save the current turn */
    sprintf(the_score.turns, "%9d", turn_real(turn));
    the_score.turns[9] = '\0';

#ifdef HIGHSCORE_DATE_HACK
    /* Save the date in a hacked up form (9 chars) */
    (void)sprintf(the_score.day, "%-.6s %-.2s", ctime(&ct) + 4, ctime(&ct) + 22);
#else
    /* Save the date in standard form (8 chars) */
/*    (void)strftime(the_score.day, 9, "%m/%d/%y", localtime(&ct)); */
    /* Save the date in standard encoded form (9 chars) */
    strftime(the_score.day, 10, "@%Y%m%d", localtime(&ct));
#endif

    /* Save the player name (15 chars) */
    sprintf(the_score.who, "%-.15s", player_name);

    /* Save the player info XXX XXX XXX */
    sprintf(the_score.uid, "%7u", player_uid);
    sprintf(the_score.sex, "%c", (p_ptr->psex ? 'm' : 'f'));
    sprintf(the_score.p_r, "%2d", p_ptr->prace);
    sprintf(the_score.p_c, "%2d", p_ptr->pclass);
    sprintf(the_score.p_a, "%2d", p_ptr->personality);

    /* Save the level and such */
    sprintf(the_score.cur_lev, "%3d", p_ptr->lev);
    sprintf(the_score.cur_dun, "%3d", dun_level);
    sprintf(the_score.max_lev, "%3d", p_ptr->max_plv);
    sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]);

    /* Save the cause of death (31 chars) */
    if (strlen(p_ptr->died_from) >= sizeof(the_score.how))
    {
        my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 3);
        strcat(the_score.how, "...");
    }
    else
    {
        strcpy(the_score.how, p_ptr->died_from);
    }

    /* Grab permissions */
    safe_setuid_grab();

    /* Lock (for writing) the highscore file, or fail */
    err = fd_lock(highscore_fd, F_WRLCK);

    /* Drop permissions */
    safe_setuid_drop();

    if (err) return (1);

    /* Add a new entry to the score list, see where it went */
    j = highscore_add(&the_score);

    /* Grab permissions */
    safe_setuid_grab();

    /* Unlock the highscore file, or fail */
    err = fd_lock(highscore_fd, F_UNLCK);

    /* Drop permissions */
    safe_setuid_drop();

    if (err) return (1);


    /* Hack -- Display the top fifteen scores */
    if (j < 10)
    {
        display_scores_aux(0, 15, j, NULL);
    }

    /* Display the scores surrounding the player */
    else
    {
        display_scores_aux(0, 5, j, NULL);
        display_scores_aux(j - 2, j + 7, j, NULL);
    }


    /* Success */
    return (0);
}
Esempio n. 16
0
/*
 * Read the dungeon
 *
 * The monsters/objects must be loaded in the same order
 * that they were stored, since the actual indexes matter.
 *
 * Note that the size of the dungeon is now hard-coded to
 * DUNGEON_HGT by DUNGEON_WID, and any dungeon with another
 * size will be silently discarded by this routine.
 *
 * Note that dungeon objects, including objects held by monsters, are
 * placed directly into the dungeon, using "object_copy()", which will
 * copy "iy", "ix", and "held_m_idx", leaving "next_o_idx" blank for
 * objects held by monsters, since it is not saved in the savefile.
 *
 * After loading the monsters, the objects being held by monsters are
 * linked directly into those monsters.
 */
static errr rd_dungeon(void)
{
	int i, y, x;
int by, bx;

	s16b town;
	s16b dungeon;
	s16b depth;
	s16b py, px;
	s16b ymax, xmax;

	byte count;
	byte tmp8u;
	u16b tmp16u;

u16b limit;

	/*** Basic info ***/

	/* Header info */
	rd_s16b(&depth);
	rd_s16b(&dungeon);
	rd_s16b(&py);
	rd_s16b(&px);
	rd_s16b(&ymax);
	rd_s16b(&xmax);
	rd_s16b(&town);
	rd_u16b(&tmp16u);


	/* Ignore illegal dungeons */
	if (town>=z_info->t_max)
	{
		note(format("Ignoring illegal dungeon (%d)", dungeon));
		return (0);
	}

	/* Ignore illegal dungeons */
	if ((depth < 0) || (depth > max_depth(dungeon)))
	{
		note(format("Ignoring illegal dungeon depth (%d)", depth));
		return (0);
	}

	/* Ignore illegal dungeons */
	if ((ymax != DUNGEON_HGT) || (xmax != DUNGEON_WID))
	{
		/* XXX XXX XXX */
		note(format("Ignoring illegal dungeon size (%d,%d).", ymax, xmax));
		return (0);
	}

	/* Ignore illegal dungeons */
	if ((px < 0) || (px >= DUNGEON_WID) ||
	    (py < 0) || (py >= DUNGEON_HGT))
	{
		note(format("Ignoring illegal player location (%d,%d).", py, px));
		return (1);
	}


	/*** Run length decoding ***/

	/* Load the dungeon data */
	for (x = y = 0; y < DUNGEON_HGT; )
	{
		/* Grab RLE info */
		rd_byte(&count);
		rd_byte(&tmp8u);

		/* Apply the RLE info */
		for (i = count; i > 0; i--)
		{
			/* Extract "info" */
			cave_info[y][x] = tmp8u;

			/* Advance/Wrap */
			if (++x >= DUNGEON_WID)
			{
				/* Wrap */
				x = 0;

				/* Advance/Wrap */
				if (++y >= DUNGEON_HGT) break;
			}
		}
	}

	/* Hack -- not fully dynamic */
	dyna_full = FALSE;

	/*** Run length decoding ***/

	/* Load the dungeon data */
	for (x = y = 0; y < DUNGEON_HGT; )
	{
		/* Grab RLE info */
		rd_byte(&count);

		if (variant_save_feats) rd_u16b(&tmp16u);
		else rd_byte(&tmp8u);

		/* Apply the RLE info */
		for (i = count; i > 0; i--)
		{
			/* Save the feat */
			if (variant_save_feats) cave_feat[y][x] = tmp16u;
			else cave_feat[y][x] = tmp8u;

			/* Check for los flag set*/
			if (f_info[cave_feat[y][x]].flags1 & (FF1_LOS))
			{
				cave_info[y][x] &= ~(CAVE_WALL);
			}

			/* Handle wall grids */
			else
			{
				cave_info[y][x] |= (CAVE_WALL);
			}

			/* Handle dynamic grids */
			if (f_info[cave_feat[y][x]].flags3 & (FF3_DYNAMIC_MASK))
			{
				if (dyna_n < (DYNA_MAX-1))
				{
					dyna_g[dyna_n++] = GRID(y,x);
				}
				else
				{
					dyna_full = TRUE;
					dyna_cent_y = 255;
					dyna_cent_x = 255;
				}
			}

			/* Advance/Wrap */
			if (++x >= DUNGEON_WID)
			{
				/* Wrap */
				x = 0;

				/* Advance/Wrap */
				if (++y >= DUNGEON_HGT) break;
			}
		}
	}

	/*** Player ***/

	/* Fix depth */
	if (depth < 1) depth = min_depth(dungeon);

	/* Fix depth */
	if (depth > max_depth(dungeon)) depth = max_depth(dungeon);

	/* Load depth */
	p_ptr->depth = depth;
	p_ptr->dungeon = dungeon;
	p_ptr->town = town;


	/* Place player in dungeon */
	if (!player_place(py, px))
	{
		note(format("Cannot place player (%d,%d)!", py, px));
		return (-1);
	}


	/*** Room descriptions ***/
   
	if (!variant_room_info)
	{
		/* Initialize the room table */
		for (by = 0; by < MAX_ROOMS_ROW; by++)
		{
			for (bx = 0; bx < MAX_ROOMS_COL; bx++)
			{
				dun_room[by][bx] = 0;
			}
		}

		/* Initialise 'zeroeth' room description */
		room_info[0].flags = 0;
	}
	else
	{

		for (bx = 0; bx < MAX_ROOMS_ROW; bx++)
		{
			for (by = 0; by < MAX_ROOMS_COL; by++)
			{
				rd_byte(&dun_room[bx][by]);
			}
		}

		for (i = 1; i < DUN_ROOMS; i++)
		{
			int j;

			rd_byte(&room_info[i].type);
			rd_byte(&room_info[i].flags);

			if (room_info[i].type == ROOM_NORMAL)
			{
				for (j = 0; j < ROOM_DESC_SECTIONS; j++)
				{
					rd_s16b(&room_info[i].section[j]);

					if (room_info[i].section[j] == -1) break;
				}
			}
		}
	}

	/*** Objects ***/

	/* Read the item count */
	rd_u16b(&limit);

	/* Verify maximum */
	if (limit > z_info->o_max)
	{
		note(format("Too many (%d) object entries!", limit));
		return (-1);
	}

	/* Read the dungeon items */
	for (i = 1; i < limit; i++)
	{
		object_type *i_ptr;
		object_type object_type_body;

		s16b o_idx;
		object_type *o_ptr;


		/* Get the object */
		i_ptr = &object_type_body;

		/* Wipe the object */
		object_wipe(i_ptr);

		/* Read the item */
		if (rd_item(i_ptr))
		{
			note("Error reading item");
			return (-1);
		}

		/* Make an object */
		o_idx = o_pop();

		/* Paranoia */
		if (o_idx != i)
		{
			note(format("Cannot place object %d!", i));
			return (-1);
		}

		/* Get the object */
		o_ptr = &o_list[o_idx];

		/* Structure Copy */
		object_copy(o_ptr, i_ptr);

		/* Dungeon floor */
		if (!i_ptr->held_m_idx)
		{
			int x = i_ptr->ix;
			int y = i_ptr->iy;

			/* ToDo: Verify coordinates */

			/* Link the object to the pile */
			o_ptr->next_o_idx = cave_o_idx[y][x];

			/* Link the floor to the object */
			cave_o_idx[y][x] = o_idx;
		}
	}


	/*** Monsters ***/

	/* Read the monster count */
	rd_u16b(&limit);

	/* Hack -- verify */
	if (limit > z_info->m_max)
	{
		note(format("Too many (%d) monster entries!", limit));
		return (-1);
	}

	/* Read the monsters */
	for (i = 1; i < limit; i++)
	{
		monster_type *n_ptr;
		monster_type monster_type_body;


		/* Get local monster */
		n_ptr = &monster_type_body;

		/* Clear the monster */
		(void)WIPE(n_ptr, monster_type);

		/* Read the monster */
		rd_monster(n_ptr);


		/* Place monster in dungeon */
		if (monster_place(n_ptr->fy, n_ptr->fx, n_ptr) != i)
		{
			note(format("Cannot place monster %d", i));
			return (-1);
		}
	}


	/*** Holding ***/

	/* Reacquire objects */
	for (i = 1; i < o_max; ++i)
	{
		object_type *o_ptr;

		monster_type *m_ptr;

		/* Get the object */
		o_ptr = &o_list[i];

		/* Ignore dungeon objects */
		if (!o_ptr->held_m_idx) continue;

		/* Verify monster index */
		if (o_ptr->held_m_idx >= z_info->m_max)
		{
			note("Invalid monster index");
			return (-1);
		}

		/* Get the monster */
		m_ptr = &m_list[o_ptr->held_m_idx];

		/* Link the object to the pile */
		o_ptr->next_o_idx = m_ptr->hold_o_idx;

		/* Link the monster to the object */
		m_ptr->hold_o_idx = i;
	}


	/*** Success ***/

	/* The dungeon is ready */
	character_dungeon = TRUE;

	/* Regenerate town in post 2.9.3 versions */
	if (older_than(2, 9, 4) && (p_ptr->depth == 0))
		character_dungeon = FALSE;

	/* Success */
	return (0);
}
Esempio n. 17
0
/*
 * Read the dungeon
 *
 * The monsters/objects must be loaded in the same order
 * that they were stored, since the actual indexes matter.
 *
 * Note that the size of the dungeon is now hard-coded to
 * DUNGEON_HGT by DUNGEON_WID, and any dungeon with another
 * size will be silently discarded by this routine.
 *
 * Note that dungeon objects, including objects held by monsters, are
 * placed directly into the dungeon, using "object_copy()", which will
 * copy "iy", "ix", and "held_m_idx", leaving "next_o_idx" blank for
 * objects held by monsters, since it is not saved in the savefile.
 *
 * After loading the monsters, the objects being held by monsters are
 * linked directly into those monsters.
 */
static errr rd_dungeon(void)
{
	int i, y, x;

	s16b depth;
	s16b py, px;

	byte count;
	byte tmp8u;

	u16b limit;


	/*** Basic info ***/

	/* Header info */
	rd_s16b(&depth);
	rd_s16b(&py);
	rd_s16b(&px);
	rd_byte(&p_ptr->cur_map_hgt);
	rd_byte(&p_ptr->cur_map_wid);

	/* Ignore illegal dungeons */
	if ((depth < 0) || (depth > MORGOTH_DEPTH))
	{
		note(format("Ignoring illegal dungeon depth (%d)", depth));
		return (0);
	}

	/* Ignore illegal dungeons */
	if ((p_ptr->cur_map_hgt > MAX_DUNGEON_HGT) || (p_ptr->cur_map_wid > MAX_DUNGEON_WID))
	{
		/* XXX XXX XXX */
		note(format("Ignoring illegal dungeon size (%d,%d).", p_ptr->cur_map_hgt, p_ptr->cur_map_wid));
		return (0);
	}

	/* Ignore illegal dungeons */
	if ((px < 0) || (px >= p_ptr->cur_map_wid) ||
		(py < 0) || (py >= p_ptr->cur_map_hgt))
	{
		note(format("Ignoring illegal player location (%d,%d).", py, px));
		return (1);
	}


	/*** Run length decoding ***/

	/* Load the dungeon data */
	for (x = y = 0; y < p_ptr->cur_map_hgt; )
	{
		/* Grab RLE info */
		rd_byte(&count);
		rd_byte(&tmp8u);

		/* Apply the RLE info */
		for (i = count; i > 0; i--)
		{
			/* Extract "info" */
			cave_info[y][x] = tmp8u;

			/* Advance/Wrap */
			if (++x >= p_ptr->cur_map_wid)
			{
				/* Wrap */
				x = 0;

				/* Advance/Wrap */
				if (++y >= p_ptr->cur_map_hgt) break;
			}
		}
	}


	/*** Run length decoding ***/

	/* Load the dungeon data */
	for (x = y = 0; y < p_ptr->cur_map_hgt; )
	{
		/* Grab RLE info */
		rd_byte(&count);
		rd_byte(&tmp8u);

		/* Apply the RLE info */
		for (i = count; i > 0; i--)
		{
			/* Extract "feat" */
			cave_set_feat(y, x, tmp8u);

			/* Advance/Wrap */
			if (++x >= p_ptr->cur_map_wid)
			{
				/* Wrap */
				x = 0;

				/* Advance/Wrap */
				if (++y >= p_ptr->cur_map_hgt) break;
			}
		}
	}


	/*** Player ***/

	/* Load depth */
	p_ptr->depth = depth;

	/* Place player in dungeon */
	if (!player_place(py, px))
	{
		note(format("Cannot place player (%d,%d)!", py, px));
		return (-1);
	}


	/*** Objects ***/

	/* Read the item count */
	rd_u16b(&limit);

	/* Verify maximum */
	if (limit > z_info->o_max)
	{
		note(format("Too many (%d) object entries!", limit));
		return (-1);
	}

	/* Read the dungeon items */
	for (i = 1; i < limit; i++)
	{
		object_type *i_ptr;
		object_type object_type_body;

		s16b o_idx;
		object_type *o_ptr;


		/* Get the object */
		i_ptr = &object_type_body;

		/* Wipe the object */
		object_wipe(i_ptr);

		/* Read the item */
		if (rd_item(i_ptr))
		{
			note("Error reading item");
			return (-1);
		}

		/* Make an object */
		o_idx = o_pop();

		/* Paranoia */
		if (o_idx != i)
		{
			note(format("Cannot place object %d!", i));
			return (-1);
		}

		/* Get the object */
		o_ptr = &o_list[o_idx];

		/* Structure Copy */
		object_copy(o_ptr, i_ptr);

		/* Dungeon floor */
		if (!i_ptr->held_m_idx)
		{
			int x = i_ptr->ix;
			int y = i_ptr->iy;

			/* ToDo: Verify coordinates */

			/* Link the object to the pile */
			o_ptr->next_o_idx = cave_o_idx[y][x];

			/* Link the floor to the object */
			cave_o_idx[y][x] = o_idx;

			/* Rearrange stack if needed */
			rearrange_stack(y, x);
		}
	}


	/*** Monsters ***/

	/* Read the monster count */
	rd_u16b(&limit);

	/* Hack -- verify */
	if (limit > z_info->m_max)
	{
		note(format("Too many (%d) monster entries!", limit));
		return (-1);
	}

	/* Read the monsters */
	for (i = 1; i < limit; i++)
	{
		monster_type *n_ptr;
		monster_type monster_type_body;
		monster_race *r_ptr;

		int r_idx;

		/* Get local monster */
		n_ptr = &monster_type_body;

		/* Clear the monster */
		(void)WIPE(n_ptr, monster_type);

		/* Read the monster */
		rd_monster(n_ptr);

		/* Access the "r_idx" of the chosen monster */
		r_idx = n_ptr->r_idx;

		/* Access the actual race */
		r_ptr = &r_info[r_idx];

		/* Place monster in dungeon */
		if (monster_place(n_ptr->fy, n_ptr->fx, n_ptr) != i)
		{
			note(format("Cannot place monster %d", i));
			return (-1);
		}
	}

	/*** Holding ***/

	/* Reacquire objects */
	for (i = 1; i < o_max; ++i)
	{
		object_type *o_ptr;

		monster_type *m_ptr;

		/* Get the object */
		o_ptr = &o_list[i];

		/* Ignore dungeon objects */
		if (!o_ptr->held_m_idx) continue;

		/* Verify monster index */
		if (o_ptr->held_m_idx > z_info->m_max)
		{
			note("Invalid monster index");
			return (-1);
		}

		/* Get the monster */
		m_ptr = &mon_list[o_ptr->held_m_idx];

		/* Link the object to the pile */
		o_ptr->next_o_idx = m_ptr->hold_o_idx;

		/* Link the monster to the object */
		m_ptr->hold_o_idx = i;
	}

	// dump the wandering monster information
	for (i = FLOW_WANDERING_HEAD; i < MAX_FLOWS; i++)
	{
		rd_byte(&flow_center_y[i]);
		rd_byte(&flow_center_x[i]);
		rd_s16b(&wandering_pause[i]);
		
		update_noise(flow_center_y[i], flow_center_x[i], i);
	}
	
		
	/*** Success ***/

	/* The dungeon is ready */
	character_dungeon = TRUE;

	/* Success */
	return (0);
}
Esempio n. 18
0
/*
 * Become unaware of objects, monster memory, and the map
 */
static void do_cmd_wiz_forget(void)
{
	int i;
	
	/* Forget info about objects on the map */
	for (i = 1; i < o_max; i++)
	{
		object_type *o_ptr = &o_list[i];
		object_kind *k_ptr = &k_info[o_ptr->k_idx];
	
		/* Skip non-objects */
		if (!o_ptr->k_idx) continue;
		
		// identify non-special non-artefact weapons/armour		
		switch (o_ptr->tval)
		{
			case TV_DIGGING:
			case TV_HAFTED:
			case TV_POLEARM:
			case TV_SWORD:
			case TV_BOW:
			case TV_ARROW:
			case TV_MAIL:
			case TV_SOFT_ARMOR:
			case TV_SHIELD:
			case TV_HELM:
			case TV_CROWN:
			case TV_CLOAK:
			case TV_GLOVES:
			case TV_BOOTS:
			case TV_LIGHT:
			{
				if (!o_ptr->name1 && !o_ptr->name2)
				{
					/* Identify it */
					object_aware(o_ptr);
					object_known(o_ptr);
					break;
				}
			}
			default:
			{
				if (!(k_ptr->flags3 & (TR3_EASY_KNOW)))
				{
					o_ptr->ident &= ~(IDENT_KNOWN);
				}
			}
		}
		
		/* Hack -- Clear the "empty" flag */
		o_ptr->ident &= ~(IDENT_EMPTY);
		
		// re pseudo id
		pseudo_id(o_ptr);
	}

	/* Forget info about carried objects */
	for (i = 0; i < INVEN_TOTAL; i++)
	{
		object_type *o_ptr = &inventory[i];
		object_kind *k_ptr = &k_info[o_ptr->k_idx];
		
		/* Skip non-objects */
		if (!o_ptr->k_idx) continue;
		
		// identify non-special non-artefact weapons/armour		
		switch (o_ptr->tval)
		{
			case TV_DIGGING:
			case TV_HAFTED:
			case TV_POLEARM:
			case TV_SWORD:
			case TV_BOW:
			case TV_ARROW:
			case TV_MAIL:
			case TV_SOFT_ARMOR:
			case TV_SHIELD:
			case TV_HELM:
			case TV_CROWN:
			case TV_CLOAK:
			case TV_GLOVES:
			case TV_BOOTS:
			case TV_LIGHT:
			{
				if (!o_ptr->name1 && !o_ptr->name2)
				{
					/* Identify it */
					object_aware(o_ptr);
					object_known(o_ptr);
					break;
				}
			}
			default:
			{
				if (!(k_ptr->flags3 & (TR3_EASY_KNOW)))
				{
					o_ptr->ident &= ~(IDENT_KNOWN);
				}
			}
		}
				
		/* Hack -- Clear the "empty" flag */
		o_ptr->ident &= ~(IDENT_EMPTY);

		// re pseudo id
		pseudo_id(o_ptr);
	}
	
	/* Reset the object kinds */
	for (i = 1; i < z_info->k_max; i++)
	{
		object_kind *k_ptr = &k_info[i];
		
		/* Reset "tried" */
		k_ptr->tried = FALSE;
		
		/* Reset "aware" */
		k_ptr->aware = FALSE;
	}

	/* Reset the special objects */
	for (i = 1; i < z_info->e_max; i++)
	{
		ego_item_type *e_ptr = &e_info[i];
		
		/* Reset "aware" */
		e_ptr->aware = FALSE;
	}

	/* Forget encountered monsters */
	for (i = 1; i < mon_max; i++)
	{
		monster_type *m_ptr = &mon_list[i];
		
		m_ptr->encountered = FALSE;
	}
		
	/* Reset the monster memory */
	for (i = 1; i < z_info->r_max; i++)
	{
		monster_lore *l_ptr = &l_list[i];
		
		WIPE(l_ptr, monster_lore);
	}

	/* Mega-Hack -- Forget the map */
	wiz_dark();

	// lose all spare experience
	//lose_exp(10000);
	
	// clear the cheat flags
	p_ptr->noscore = 0x0000;
	
	/* Forget turns */
	turn = 1;
	playerturn = 1;

	// forget all messages -- currently a bit buggy
	messages_init();
	
	// clear target
	target_set_monster(0);
	
	/* Recalculate bonuses */
	p_ptr->update |= (PU_BONUS);
	
	/* Combine / Reorder the pack (later) */
	p_ptr->notice |= (PN_COMBINE | PN_REORDER);
	
	/* Window stuff */
	p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER_0);
	
}
Esempio n. 19
0
/**
 * Attempts to place a monster of the given race at the given location.
 *
 * 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.)
 *
 * To give the player a sporting chance, some especially dangerous
 * monsters are marked as "FORCE_SLEEP" in monster.txt, which will
 * cause them to be placed with low energy. This helps ensure that
 * if such a monster suddenly appears in line-of-sight (due to a
 * summon, for instance), the player gets a chance to move before
 * they do.
 *
 * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
 *
 * This is the only function which may place a monster in the dungeon,
 * except for the savefile loading code, which calls place_monster()
 * directly.
 */
static bool place_new_monster_one(int y, int x, monster_race *race, 
		bool sleep, byte origin)
{
	int i;

	struct monster *mon;
	struct monster monster_body;

	assert(cave_in_bounds(cave, y, x));
	assert(race && race->name);

	/* Require empty space */
	if (!cave_isempty(cave, y, x)) return (FALSE);

	/* No creation on glyph of warding */
	if (cave_iswarded(cave, y, x)) return FALSE;

	/* "unique" monsters must be "unique" */
	if (rf_has(race->flags, RF_UNIQUE) && race->cur_num >= race->max_num)
		return (FALSE);

	/* Depth monsters may NOT be created out of depth */
	if (rf_has(race->flags, RF_FORCE_DEPTH) && p_ptr->depth < race->level)
		return (FALSE);

	/* Add to level feeling */
	cave->mon_rating += race->power / 20;

	/* Check out-of-depth-ness */
	if (race->level > p_ptr->depth) {
		if (rf_has(race->flags, RF_UNIQUE)) { /* OOD unique */
			if (OPT(cheat_hear))
				msg("Deep unique (%s).", race->name);
		} else { /* Normal monsters but OOD */
			if (OPT(cheat_hear))
				msg("Deep monster (%s).", race->name);
		}
		/* Boost rating by power per 10 levels OOD */
		cave->mon_rating += (race->level - p_ptr->depth) * race->power / 200;
	}
	/* Note uniques for cheaters */
	else if (rf_has(race->flags, RF_UNIQUE) && OPT(cheat_hear))
		msg("Unique (%s).", race->name);

	/* Get local monster */
	mon = &monster_body;

	/* Clean out the monster */
	(void)WIPE(mon, monster_type);

	/* Save the race */
	mon->race = race;

	/* Enforce sleeping if needed */
	if (sleep && race->sleep) {
		int val = race->sleep;
		mon->m_timed[MON_TMD_SLEEP] = ((val * 2) + randint1(val * 10));
	}

	/* Uniques get a fixed amount of HP */
	if (rf_has(race->flags, RF_UNIQUE))
		mon->maxhp = race->avg_hp;
	else {
		mon->maxhp = mon_hp(race, RANDOMISE);
		mon->maxhp = MAX(mon->maxhp, 1);
	}

	/* And start out fully healthy */
	mon->hp = mon->maxhp;

	/* Extract the monster base speed */
	mon->mspeed = race->speed;

	/* Hack -- small racial variety */
	if (!rf_has(race->flags, RF_UNIQUE)) {
		/* Allow some small variation per monster */
		i = extract_energy[race->speed] / 10;
		if (i) mon->mspeed += rand_spread(0, i);
	}

	/* Give a random starting energy */
	mon->energy = (byte)randint0(50);

	/* Force monster to wait for player */
	if (rf_has(race->flags, RF_FORCE_SLEEP))
		mon->mflag |= (MFLAG_NICE);

	/* Radiate light? */
	if (rf_has(race->flags, RF_HAS_LIGHT))
		p_ptr->update |= PU_UPDATE_VIEW;
	
	/* Is this obviously a monster? (Mimics etc. aren't) */
	if (rf_has(race->flags, RF_UNAWARE)) 
		mon->unaware = TRUE;
	else
		mon->unaware = FALSE;

	/* Set the color if necessary */
	if (rf_has(race->flags, RF_ATTR_RAND))
		mon->attr = randint1(BASIC_COLORS - 1);

	/* Place the monster in the dungeon */
	if (!place_monster(y, x, mon, origin))
		return (FALSE);

	/* Success */
	return (TRUE);
}
Esempio n. 20
0
/**
 * Move a monster from index i1 to index i2 in the monster list.
 */
static void compact_monsters_aux(int i1, int i2)
{
	int y, x;

	monster_type *m_ptr;

	s16b this_o_idx, next_o_idx = 0;

	/* Do nothing */
	if (i1 == i2) return;

	/* Old monster */
	m_ptr = cave_monster(cave, i1);
	y = m_ptr->fy;
	x = m_ptr->fx;

	/* Update the cave */
	cave->m_idx[y][x] = i2;
	
	/* Update midx */
	m_ptr->midx = i2;

	/* Repair objects being carried by monster */
	for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
	{
		object_type *o_ptr;

		/* Get the object */
		o_ptr = object_byid(this_o_idx);

		/* Get the next object */
		next_o_idx = o_ptr->next_o_idx;

		/* Reset monster pointer */
		o_ptr->held_m_idx = i2;
	}
	
	/* Move mimicked objects */
	if (m_ptr->mimicked_o_idx > 0) {
		object_type *o_ptr;

		/* Get the object */
		o_ptr = object_byid(m_ptr->mimicked_o_idx);

		/* Reset monster pointer */
		o_ptr->mimicking_m_idx = i2;
	}

	/* Hack -- Update the target */
	if (target_get_monster() == m_ptr)
		target_set_monster(cave_monster(cave, i2));

	/* Hack -- Update the health bar */
	if (p_ptr->health_who == m_ptr)
		p_ptr->health_who = cave_monster(cave, i2);

	/* Hack -- move monster */
	COPY(cave_monster(cave, i2), cave_monster(cave, i1), struct monster);

	/* Hack -- wipe hole */
	(void)WIPE(cave_monster(cave, i1), monster_type);
}
Esempio n. 21
0
static int rd_monsters(void)
{
	int i;
	u16b limit;

	/* Only if the player's alive */
	if (p_ptr->is_dead)
		return 0;
	
	/* Read the monster count */
	rd_u16b(&limit);

	/* Hack -- verify */
	if (limit > z_info->m_max)
	{
		note(format("Too many (%d) monster entries!", limit));
		return (-1);
	}

	/* Read the monsters */
	for (i = 1; i < limit; i++)
	{
		monster_type *m_ptr;
		monster_type monster_type_body;

		/* Get local monster */
		m_ptr = &monster_type_body;
		WIPE(m_ptr, monster_type);

		/* Read in record */
		rd_s16b(&m_ptr->r_idx);
		rd_byte(&m_ptr->fy);
		rd_byte(&m_ptr->fx);
		rd_s16b(&m_ptr->hp);
		rd_s16b(&m_ptr->maxhp);
		rd_s16b(&m_ptr->csleep);
		rd_byte(&m_ptr->mspeed);
		rd_byte(&m_ptr->energy);
		rd_byte(&m_ptr->stunned);
		rd_byte(&m_ptr->confused);
		rd_byte(&m_ptr->monfear);
		strip_bytes(1);

		/* Place monster in dungeon */
		if (monster_place(m_ptr->fy, m_ptr->fx, m_ptr) != i)
		{
			note(format("Cannot place monster %d", i));
			return (-1);
		}
	}

	/* Reacquire objects */
	for (i = 1; i < o_max; ++i)
	{
		object_type *o_ptr;
		monster_type *m_ptr;

		/* Get the object */
		o_ptr = &o_list[i];

		/* Ignore dungeon objects */
		if (!o_ptr->held_m_idx) continue;

		/* Verify monster index */
		if (o_ptr->held_m_idx > z_info->m_max)
		{
			note("Invalid monster index");
			return (-1);
		}

		/* Get the monster */
		m_ptr = &mon_list[o_ptr->held_m_idx];

		/* Link the object to the pile */
		o_ptr->next_o_idx = m_ptr->hold_o_idx;

		/* Link the monster to the object */
		m_ptr->hold_o_idx = i;
	}

	return 0;
}
Esempio n. 22
0
 /* For wilderness levels, dun_depth has been changed from 1 to 4 bytes. */
static void rd_item(object_type *o_ptr)
{
	byte old_dd;
	byte old_ds;

	u32b f1, f2, f3;

	object_kind *k_ptr;

	char note[128];

	start_section_read("item");
	
	/* Hack -- wipe */
	WIPE(o_ptr, object_type);

	/* Skip name */
	skip_value("name");

	/* Kind */
	o_ptr->k_idx = read_int("k_idx");

	/* Location */
	o_ptr->iy = read_int("iy");
	o_ptr->ix = read_int("ix");
	
	o_ptr->dun_depth = read_int("dun_depth");

	/* Type/Subtype */
	o_ptr->tval = read_int("tval");
	o_ptr->sval = read_int("sval");

	/* Base pval */
	o_ptr->bpval = read_int("bpval");

	/* Special pval */
	o_ptr->pval = read_int("pval");


	o_ptr->discount = read_int("discount");
	o_ptr->number = read_int("number");
	o_ptr->weight = read_int("weight");

	o_ptr->name1 = read_int("name1");
	o_ptr->name2 = read_int("name2");
	o_ptr->name3 = read_int("name3");
	o_ptr->timeout = read_int("timeout");

	o_ptr->to_h = read_int("to_h");
	o_ptr->to_d = read_int("to_d");
	o_ptr->to_a = read_int("to_a");

	o_ptr->ac = read_int("ac");

	old_dd = read_int("dd");
	old_ds = read_int("ds");

	o_ptr->ident = read_int("ident");

	/* Special powers */
	o_ptr->xtra1 = read_int("xtra1");
	o_ptr->xtra2 = read_int("xtra2");

	/* Inscription */
	read_str("inscription",note); 
 
	/* Save the inscription */
	if (note[0]) o_ptr->note = quark_add(note);

	/* Owner information */
	if (value_exists("owner_name"))
	{
		/* Name */
		read_str("owner_name",note);
		/* Save */
		if (!STRZERO(note)) o_ptr->owner_name = quark_add(note); 
		/* Id */
		o_ptr->owner_id = read_int("owner_id");
	}

	/* Monster holding object */ 
   o_ptr->held_m_idx = read_int("held_m_idx");

	end_section_read("item");

	/* Mega-Hack -- handle "dungeon objects" later */
	if ((o_ptr->k_idx >= 445) && (o_ptr->k_idx <= 479)) return;


	/* Obtain the "kind" template */
	k_ptr = &k_info[o_ptr->k_idx];

	/* Obtain tval/sval from k_info */
	o_ptr->tval = k_ptr->tval;
	o_ptr->sval = k_ptr->sval;


	/* Hack -- notice "broken" items */
	if (k_ptr->cost <= 0) o_ptr->ident |= ID_BROKEN;


	/* Repair non "wearable" items */
	if (!wearable_p(o_ptr))
	{
		/* Acquire correct fields */
		o_ptr->to_h = k_ptr->to_h;
		o_ptr->to_d = k_ptr->to_d;
		o_ptr->to_a = k_ptr->to_a;

		/* Acquire correct fields */
		o_ptr->ac = k_ptr->ac;
		o_ptr->dd = k_ptr->dd;
		o_ptr->ds = k_ptr->ds;

		/* Acquire correct weight */
		o_ptr->weight = k_ptr->weight;

		/* Paranoia */
		o_ptr->name1 = o_ptr->name2 = 0;

		/* All done */
		return;
	}


	/* Extract the flags */
	object_flags(o_ptr, &f1, &f2, &f3);


	/* Paranoia */
	if (true_artifact_p(o_ptr))
	{
		artifact_type *a_ptr;

		/* Obtain the artifact info */
		a_ptr = &a_info[o_ptr->name1];

		/* Verify that artifact */
		if (!a_ptr->name) o_ptr->name1 = 0;
	}

	/* Paranoia */
	if (o_ptr->name2)
	{
		ego_item_type *e_ptr;

		/* Obtain the ego-item info */
		e_ptr = &e_info[o_ptr->name2];

		/* Verify that ego-item */
		if (!e_ptr->name) o_ptr->name2 = 0;
	}


	/* Acquire standard fields */
	o_ptr->ac = k_ptr->ac;
	o_ptr->dd = k_ptr->dd;
	o_ptr->ds = k_ptr->ds;

	/* Acquire standard weight */
	o_ptr->weight = k_ptr->weight;

	/* Hack -- extract the "broken" flag */
	if (o_ptr->pval < 0) o_ptr->ident |= ID_BROKEN;


	/* Artifacts */
	if (artifact_p(o_ptr))
	{
		artifact_type *a_ptr;

		/* Obtain the artifact info */
#if defined(RANDART)
		if (o_ptr->name1 == ART_RANDART)
		{
			a_ptr = randart_make(o_ptr);
		}
		else
		{
#endif
		a_ptr = &a_info[o_ptr->name1];
#if defined(RANDART)
		}
#endif
		/* Acquire new artifact "pval" */
		o_ptr->pval = a_ptr->pval;

		/* Acquire new artifact fields */
		o_ptr->ac = a_ptr->ac;
		o_ptr->dd = a_ptr->dd;
		o_ptr->ds = a_ptr->ds;

		/* Acquire new artifact weight */
		o_ptr->weight = a_ptr->weight;

		/* Hack -- extract the "broken" flag */
		if (!a_ptr->cost) o_ptr->ident |= ID_BROKEN;
	}

	/* Ego items */
	if (o_ptr->name2)
	{
		ego_item_type *e_ptr;

		/* Obtain the ego-item info */
		e_ptr = &e_info[o_ptr->name2];

		/* Hack -- keep some old fields */
		if ((o_ptr->dd < old_dd) && (o_ptr->ds == old_ds))
		{
			/* Keep old boosted damage dice */
			o_ptr->dd = old_dd;
		}

		/* Hack -- extract the "broken" flag */
		if (!e_ptr->cost) o_ptr->ident |= ID_BROKEN;

		/* Mega-Hack - Enforce the special broken items */
		if ((o_ptr->name2 == EGO_BLASTED) ||
			(o_ptr->name2 == EGO_SHATTERED))
		{
			/* These were set to k_info values by preceding code */
			o_ptr->ac = 0;
			o_ptr->dd = 0;
			o_ptr->ds = 0;
		}
	}
}