Exemplo n.º 1
0
planeparent process(char *db, const int bits, const int db_size, \
										const dowhat todo)
{
	
	char *begin = db; // This is the start adress
	const char *end = db + db_size;
	unsigned int count = 0; // Maybe not used
	
	plane *minp = malloc(sizeof(plane));
	plane *maxp = malloc(sizeof(plane));
	minp->psingle = NULL;
	maxp->psingle = NULL;
	minp->next = NULL;
	maxp->next = NULL;
	plane *curmin = minp; // Pointers to the youngest minp child
	plane *curmax = maxp; 
	planeparent parent;
	
	for (count = 0; db < end; db++, count++) {
		char minflag = 0;
		char maxflag = 0;
		
		if(!check_care(*db)) continue; // If used or don't care are set
		
		#if DEBUG == 1
		printf("Element: %x\n", count);
		#endif
		
		if (todo == only_minterm || todo == both)
			minflag = term_plane(curmin, begin, db, bits, count, 1);
		if (todo == only_maxterm || todo == both)
			maxflag = term_plane(curmax, begin, db, bits, count, 0);

		if (minflag) {
			// There is a new element, so go to that element
			curmin = curmin->next;
			// Flag everything matching to the new plane as used
			flag_used(begin, curmin->psingle, bits);
		} else if (maxflag) {
			curmax = curmax->next;
			flag_used(begin, curmax->psingle, bits);
		}
	}
	
	// Yey, we are done processing.
	// Now skip the first elements of minp and maxp, they're useless
	plane *obsolete_p = minp;
	minp = minp->next;
	free(obsolete_p);
	// maxp not implemented yet, so just free it, will ya
	obsolete_p = maxp;
	maxp = maxp->next;
	free(obsolete_p);
	
	// Now this is what we return
	parent.minp = minp;
	parent.maxp = maxp;
	
	return parent;
}
Exemplo n.º 2
0
Arquivo: xtra1.c Projeto: jcubic/ToME
/*
 * Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window"
 */
void handle_stuff(void)
{
	/* Update stuff */
	if (p_ptr->update) update_stuff();

	/* Redraw stuff */
	if (flag_used(&p_ptr->redraw)) redraw_stuff();

	/* Window stuff */
	if (flag_used(&p_ptr->window)) window_stuff();
}
Exemplo n.º 3
0
Arquivo: xtra1.c Projeto: jcubic/ToME
/*
 * Handle "p_ptr->redraw"
 */
void redraw_stuff(void)
{
	/* Redraw stuff */
	if (!flag_used(&p_ptr->redraw)) return;


	/* Character is not ready yet, no screen updates */
	if (!character_generated) return;


	/* Character is in "icky" mode, no screen updates */
	if (character_icky) return;

	/* Should we tell lua to redisplay too ? */
	process_hooks(HOOK_REDRAW, "()");

	flag_empty(&p_ptr->redraw);
}
Exemplo n.º 4
0
Arquivo: xtra1.c Projeto: jcubic/ToME
/*
 * Handle "p_ptr->window"
 */
void window_stuff(void)
{
	/* Character is not ready yet, no screen updates */
	if (!character_generated || character_icky) return;

	/* Nothing to do */
	if (!flag_used(&p_ptr->window)) return;

	/* Display monster list */
	if (flag_exists(&p_ptr->window, FLAG_PW_M_LIST) || flag_exists(&p_ptr->window, FLAG_PW_ALL))
	{
		fix_m_list();
	}

	/* Display overhead view */
	if (flag_exists(&p_ptr->window, FLAG_PW_MESSAGE) || flag_exists(&p_ptr->window, FLAG_PW_ALL))
	{
		fix_message();
	}

	/* Display monster recall */
	if (flag_exists(&p_ptr->window, FLAG_PW_MONSTER) || flag_exists(&p_ptr->window, FLAG_PW_ALL))
	{
		fix_monster();
	}

	/* Display object recall */
	if (flag_exists(&p_ptr->window, FLAG_PW_OBJECT) || flag_exists(&p_ptr->window, FLAG_PW_ALL))
	{
		fix_object();
	}

	call_lua("windows.display", "()", "");

	flag_empty(&p_ptr->window);
}
Exemplo n.º 5
0
/*
 * Let an object fall to the ground at or near a location.
 *
 * The initial location is assumed to be "in_bounds()".
 *
 * This function takes a parameter "chance".  This is the percentage
 * chance that the item will "disappear" instead of drop.  If the object
 * has been thrown, then this is the chance of disappearance on contact.
 *
 * Hack -- this function uses "chance" to determine if it should produce
 * some form of "description" of the drop event (under the player).
 *
 * We check several locations to see if we can find a location at which
 * the object can combine, stack, or be placed.  Artifacts will try very
 * hard to be placed, including "teleporting" to a useful grid if needed.
 */
s16b drop_near(object_type *j_ptr, s32b chance, s32b y, s32b x)
{
	s32b i, k, d, s;

	s32b bs, bn;
	s32b by, bx;
	s32b dy, dx;
	s32b ty, tx;

	s16b o_idx = 0;

	cave_type *c_ptr;

	char o_name[80];

	bool flag = FALSE;

	bool plural = FALSE;


	/* Extract plural */
	if (j_ptr->number != 1) plural = TRUE;

	/* Describe object */
	object_desc(o_name, j_ptr, FALSE, 0);


	/* Handle normal "breakage" */
	if (!(j_ptr->art_name || artifact_p(j_ptr)) && (rand_int(100) < chance))
	{
		/* Message */
		msg_format("The %s disappear%s.",
		           o_name, (plural ? "" : "s"));

		/* Debug */
		if (wizard) msg_print("(breakage)");

		delete_object(j_ptr);

		/* Failure */
		return (0);
	}


	/* Score */
	bs = -1;

	/* Picker */
	bn = 0;

	/* Default */
	by = y;
	bx = x;

	/* Scan local grids */
	for (dy = -3; dy <= 3; dy++)
	{
		/* Scan local grids */
		for (dx = -3; dx <= 3; dx++)
		{
			bool comb = FALSE;

			/* Calculate actual distance */
			d = (dy * dy) + (dx * dx);

			/* Ignore distant grids */
			if (d > 10) continue;

			/* Location */
			ty = y + dy;
			tx = x + dx;

			/* Skip illegal grids */
			if (!in_bounds(ty, tx)) continue;

			/* Require line of sight */
			if (!los(y, x, ty, tx)) continue;

			/* Obtain grid */
			c_ptr = &cave[ty][tx];

			/* Require floor space (or shallow terrain) -KMW- */
			if (!has_flag(&f_info[c_ptr->feat], FLAG_FLOOR)) continue;

			/* No traps */
			if (flag_used(&c_ptr->activations)) continue;

			/* No objects */
			k = 0;

			/* Scan objects in that grid */
			for_inventory_slot(&c_ptr->inventory, o_ptr);
			{
				/* Check for possible combination */
				if (object_similar(o_ptr, j_ptr)) comb = TRUE;

				/* Count objects */
				k++;
			}
			end_inventory_slot();

			/* Add new object */
			if (!comb) k++;

			/* Paranoia */
			if (k >= inventory_limit_inven(&c_ptr->inventory)) continue;

			/* Calculate score */
			s = 1000 - (d + k * 5);

			/* Skip bad values */
			if (s < bs) continue;

			/* New best value */
			if (s > bs) bn = 0;

			/* Apply the randomizer to equivalent values */
			if ((++bn >= 2) && (rand_int(bn) != 0)) continue;

			/* Keep score */
			bs = s;

			/* Track it */
			by = ty;
			bx = tx;

			/* Okay */
			flag = TRUE;
		}
	}


	/* Handle lack of space */
	if (!flag && !(artifact_p(j_ptr) || j_ptr->art_name))
	{
		/* Message */
		msg_format("The %s disappear%s.",
		           o_name, (plural ? "" : "s"));

		/* Debug */
		if (wizard) msg_print("(no floor space)");

		delete_object(j_ptr);

		/* Failure */
		return (0);
	}


	/* Find a grid */
	for (i = 0; !flag; i++)
	{
		/* Bounce around */
		if (i < 1000)
		{
			ty = rand_spread(by, 1);
			tx = rand_spread(bx, 1);
		}

		/* Random locations */
		else
		{
			ty = rand_int(cur_hgt);
			tx = rand_int(cur_wid);
		}

		/* Grid */
		c_ptr = &cave[ty][tx];

		/* Require floor space */
		if (!has_flag(&f_info[c_ptr->feat], FLAG_FLOOR) || has_flag(&f_info[c_ptr->feat], FLAG_NO_WALK)) continue;

		/* Bounce to that location */
		by = ty;
		bx = tx;

		/* Require floor space */
		if (!cave_clean_bold(by, bx)) continue;

		/* Okay */
		flag = TRUE;
	}

	j_ptr->iy         = by;
	j_ptr->ix         = bx;
	j_ptr->held_m_idx = 0;

	/* Grid */
	c_ptr = &cave[by][bx];

	/* Carry */
	o_idx = inven_carry_inven(&c_ptr->inventory, j_ptr, FALSE);

	/*
	 * j_ptr might have been merged into an existing object and then
	 * deleted, so re-get the object.
	 */
	j_ptr = get_object(item_slot_to_item(o_idx));

	/* Note the spot */
	note_spot(by, bx);

	/* Draw the spot */
	lite_spot(by, bx);

	/* Mega-Hack -- no message if "dropped" by player */
	/* Message when an object falls under the player */
	if (chance && (by == p_ptr->py) && (bx == p_ptr->px))
	{
		msg_print("You feel something roll beneath your feet.");
		/* Sound */
		sound(SOUND_DROP);
	}

	process_hooks(HOOK_DROPPED_NEAR, "(O,b,d,d,d,d)", j_ptr, chance,
				  y, x, by, bx);

	/* XXX XXX XXX */

	/* Result */
	return (o_idx);
}
Exemplo n.º 6
0
Arquivo: cmd4.c Projeto: jcubic/ToME
/*
 * Modify the "window" options
 */
void do_cmd_options_win(void)
{
	s32b j;
	call_lua("windows.configure", "()", "");
#if 0
	s32b i, j, d;

	s32b y = 0;

	s32b x = 0;

	s32b ch;

	bool go = TRUE;

	u32b old_flag[8];


	/* Memorize old flags */
	for (j = 0; j < 8; j++)
	{
		/* Acquire current flags */
		old_flag[j] = window_flag[j];
	}


	/* Clear screen */
	Term_clear();

	/* Interact */
	while (go)
	{
		/* Prompt XXX XXX XXX */
		prt("Window Flags (<dir>, t, y, n, ESC) ", 0, 0);

		/* Display the windows */
		for (j = 0; j < 8; j++)
		{
			byte a = TERM_WHITE;

			cptr s = angband_term_name[j];

			/* Use color */
			if (use_color && (j == x)) a = TERM_L_BLUE;

			/* Window name, staggered, centered */
			Term_putstr(35 + j * 5 - strlen(s) / 2, 2 + j % 2, -1, a, s);
		}

		/* Display the options */
		for (i = 0; i < 16; i++)
		{
			byte a = TERM_WHITE;

			cptr str = window_flag_desc[i];

			/* Use color */
			if (use_color && (i == y)) a = TERM_L_BLUE;

			/* Unused option */
			if (!str) str = "(Unused option)";

			/* Flag name */
			Term_putstr(0, i + 5, -1, a, str);

			/* Display the windows */
			for (j = 0; j < 8; j++)
			{
				byte a = TERM_WHITE;

				char c = '.';

				/* Use color */
				if (use_color && (i == y) && (j == x)) a = TERM_L_BLUE;

				/* Active flag */
				if (window_flag[j] & (1L << i)) c = 'X';

				/* Flag value */
				Term_putch(35 + j * 5, i + 5, a, c);
			}
		}

		/* Place Cursor */
		Term_gotoxy(35 + x * 5, y + 5);

		/* Get key */
		ch = inkey();

		/* Analyze */
		switch (ch)
		{
		case ESCAPE:
			{
				go = FALSE;

				break;
			}

		case 'T':
		case 't':
			{
				/* Clear windows */
				for (j = 0; j < 8; j++)
				{
					window_flag[j] &= ~(1L << y);
				}

				/* Clear flags */
				for (i = 0; i < 16; i++)
				{
					window_flag[x] &= ~(1L << i);
				}

				/* Fall through */
			}

		case 'y':
		case 'Y':
			{
				/* Ignore screen */
				if (x == 0) break;

				/* Set flag */
				window_flag[x] |= (1L << y);

				break;
			}

		case 'n':
		case 'N':
			{
				/* Clear flag */
				window_flag[x] &= ~(1L << y);

				break;
			}

		default:
			{
				d = get_keymap_dir(ch);

				x = (x + ddx[d] + 8) % 8;
				y = (y + ddy[d] + 16) % 16;

				if (!d) bell();

				break;
			}
		}
	}
#endif

	/* Notice changes */
	for (j = 1; j < 8; j++)
	{
		term *old = Term;

		/* Dead window */
		if (!angband_term[j]) continue;

		/* Ignore non-changes */
//		if (window_flag[j] == old_flag[j]) continue;

		/* Activate */
		Term_activate(angband_term[j]);

		/* Erase */
		Term_clear();

		/* Refresh */
		Term_fresh();

#ifdef USE_SDL
		Term_xtra(TERM_XTRA_WINVIS, (flag_used(&window_flag[j]) ? 1 : 0));
#endif

		/* Restore */
		Term_activate(old);
	}
}