Exemplo n.º 1
0
//returns the number of the next object in a segment, skipping the player
static objnum_t get_next_object(const vsegptr_t seg,objnum_t id)
{
	if (id == object_none)
		return get_first_object(seg);
	for (auto o = vobjptr(id);;)
	{
		id = o->next;
		if (id == object_none)
			return get_first_object(seg);
		o = vobjptr(id);
		if (o != ConsoleObject)
			return id;
	}
}
Exemplo n.º 2
0
/*
 * Hack -- determine if a given location is "interesting"
 */
static bool target_set_interactive_accept(int y, int x)
{
	object_type *o_ptr;

	/* Player grids are always interesting */
	if (cave_m_idx[y][x] < 0) return (TRUE);

	/* Handle hallucination */
	if (p_ptr->timed[TMD_IMAGE]) return (FALSE);

	/* Visible monsters */
	if (cave_m_idx[y][x] > 0)
	{
		monster_type *m_ptr = &mon_list[cave_m_idx[y][x]];

		/* Visible monsters */
		if (m_ptr->ml) return (TRUE);
	}

	/* Scan all objects in the grid */
	for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr))
	{
		/* Memorized object */
		if (o_ptr->marked) return (TRUE);
	}

	/* Interesting memorized features */
	/* Ignore unknown features */
	if (!(cave_info[y][x] & (CAVE_MARK))) return (FALSE);

	/* Find interesting effects */
   	if (cave_x_idx[y][x] > 0)
	{
		/* Get the first effect */
		u16b x_idx = cave_x_idx[y][x];

		/* Scan the effects on that grid */
		while (x_idx)
		{
			/* Get the effect data */
			effect_type *x_ptr = &x_list[x_idx];

			/* Point to the next effect */
			x_idx = x_ptr->next_x_idx;

			/* Ignore hidden effects */
			if (!(x_ptr->x_f_idx) ||
				(x_ptr->x_flags & (EF1_HIDDEN))) continue;

			/* We have an interesting effect */
			return (TRUE);
		}
	}

	/* Check grid type with dungeon capabilities */
	return ((*dun_cap->can_target_feature)(cave_feat[y][x]));
}
Exemplo n.º 3
0
//returns the number of the next object in a segment, skipping the player
int get_next_object(segment *seg,int id)
{
	if (id==-1 || (id=Objects[id].next)==-1)
		return get_first_object(seg);

	if (id == (ConsoleObject-Objects))
		return get_next_object(seg,id);

	return id;
}
Exemplo n.º 4
0
/*
 * Hack -- determine if a given location is "interesting"
 */
static bool target_set_interactive_accept(int y, int x)
{
	object_type *o_ptr;


	/* Player grids are always interesting */
	if (cave->m_idx[y][x] < 0) return (TRUE);


	/* Handle hallucination */
	if (p_ptr->timed[TMD_IMAGE]) return (FALSE);


	/* Visible monsters */
	if (cave->m_idx[y][x] > 0)
	{
		monster_type *m_ptr = cave_monster_at(cave, y, x);

		/* Visible monsters */
		if (m_ptr->ml && !m_ptr->unaware) return (TRUE);
	}

	/* Scan all objects in the grid */
	for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr))
	{
		/* Memorized object */
		if (o_ptr->marked && !squelch_item_ok(o_ptr)) return (TRUE);
	}

	/* Interesting memorized features */
	if (cave->info[y][x] & (CAVE_MARK) && !cave_isboring(cave, y, x))
		return (TRUE);

	/* Nope */
	return (FALSE);
}
Exemplo n.º 5
0
/*
 * Hack -- determine if a given location is "interesting"
 */
static bool target_set_interactive_accept(int y, int x)
{
	object_type *o_ptr;


	/* Player grids are always interesting */
	if (cave_m_idx[y][x] < 0) return (TRUE);


	/* Handle hallucination */
	if (p_ptr->timed[TMD_IMAGE]) return (FALSE);


	/* Visible monsters */
	if (cave_m_idx[y][x] > 0)
	{
		monster_type *m_ptr = &mon_list[cave_m_idx[y][x]];

		/* Visible monsters */
		if (m_ptr->ml) return (TRUE);
	}

	/* Scan all objects in the grid */
	for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr))
	{
		/* Memorized object */
		if (o_ptr->marked && !squelch_hide_item(o_ptr)) return (TRUE);
	}

	/* Interesting memorized features */
	if (cave_info[y][x] & (CAVE_MARK))
	{
		/* Notice glyphs */
		if (cave_feat[y][x] == FEAT_GLYPH) return (TRUE);

		/* Notice doors */
		if (cave_feat[y][x] == FEAT_OPEN) return (TRUE);
		if (cave_feat[y][x] == FEAT_BROKEN) return (TRUE);

		/* Notice stairs */
		if (cave_feat[y][x] == FEAT_LESS) return (TRUE);
		if (cave_feat[y][x] == FEAT_MORE) return (TRUE);

		/* Notice shops */
		if ((cave_feat[y][x] >= FEAT_SHOP_HEAD) &&
		    (cave_feat[y][x] <= FEAT_SHOP_TAIL)) return (TRUE);

		/* Notice traps */
		if ((cave_feat[y][x] >= FEAT_TRAP_HEAD) &&
		    (cave_feat[y][x] <= FEAT_TRAP_TAIL)) return (TRUE);

		/* Notice doors */
		if ((cave_feat[y][x] >= FEAT_DOOR_HEAD) &&
		    (cave_feat[y][x] <= FEAT_DOOR_TAIL)) return (TRUE);

		/* Notice rubble */
		if (cave_feat[y][x] == FEAT_RUBBLE) return (TRUE);

		/* Notice veins with treasure */
		if (cave_feat[y][x] == FEAT_MAGMA_K) return (TRUE);
		if (cave_feat[y][x] == FEAT_QUARTZ_K) return (TRUE);
	}

	/* Nope */
	return (FALSE);
}
Exemplo n.º 6
0
/*
 * Search for hidden things.  Returns true if a search was attempted, returns
 * false when the player has a 0% chance of finding anything.  Prints messages
 * for negative confirmation when verbose mode is requested.
 */
bool search(bool verbose)
{
	int py = p_ptr->py;
	int px = p_ptr->px;

	int y, x, chance;

	bool found = FALSE;

	object_type *o_ptr;


	/* Start with base search ability */
	chance = p_ptr->state.skills[SKILL_SEARCH];

	/* Penalize various conditions */
	if (p_ptr->timed[TMD_BLIND] || no_light()) chance = chance / 10;
	if (p_ptr->timed[TMD_CONFUSED] || p_ptr->timed[TMD_IMAGE]) chance = chance / 10;

	/* Prevent fruitless searches */
	if (chance <= 0)
	{
		if (verbose)
		{
			msg("You can't make out your surroundings well enough to search.");

			/* Cancel repeat */
			disturb(p_ptr, 0, 0);
		}

		return FALSE;
	}

	/* Search the nearby grids, which are always in bounds */
	for (y = (py - 1); y <= (py + 1); y++)
	{
		for (x = (px - 1); x <= (px + 1); x++)
		{
			/* Sometimes, notice things */
			if (randint0(100) < chance)
			{
				/* Invisible trap */
				if (cave->feat[y][x] == FEAT_INVIS)
				{
					found = TRUE;

					/* Pick a trap */
					pick_trap(y, x);

					/* Message */
					msg("You have found a trap.");

					/* Disturb */
					disturb(p_ptr, 0, 0);
				}

				/* Secret door */
				if (cave->feat[y][x] == FEAT_SECRET)
				{
					found = TRUE;

					/* Message */
					msg("You have found a secret door.");

					/* Pick a door */
					place_closed_door(cave, y, x);

					/* Disturb */
					disturb(p_ptr, 0, 0);
				}

				/* Scan all objects in the grid */
				for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr))
				{
					/* Skip non-chests */
					if (o_ptr->tval != TV_CHEST) continue;

					/* Skip disarmed chests */
					if (o_ptr->pval[DEFAULT_PVAL] <= 0) continue;

					/* Skip non-trapped chests */
					if (!chest_traps[o_ptr->pval[DEFAULT_PVAL]]) continue;

					/* Identify once */
					if (!object_is_known(o_ptr))
					{
						found = TRUE;

						/* Message */
						msg("You have discovered a trap on the chest!");

						/* Know the trap */
						object_notice_everything(o_ptr);

						/* Notice it */
						disturb(p_ptr, 0, 0);
					}
				}
			}
		}
	}

	if (verbose && !found)
	{
		if (chance >= 100)
			msg("There are no secrets here.");
		else
			msg("You found nothing.");
	}

	return TRUE;
}
Exemplo n.º 7
0
/*
 * Use an object the right way.
 *
 * There may be a BIG problem with any "effect" that can cause "changes"
 * to the inventory.  For example, a "scroll of recharging" can cause
 * a wand/staff to "disappear", moving the inventory up.  Luckily, the
 * scrolls all appear BEFORE the staffs/wands, so this is not a problem.
 * But, for example, a "staff of recharging" could cause MAJOR problems.
 * In such a case, it will be best to either (1) "postpone" the effect
 * until the end of the function, or (2) "change" the effect, say, into
 * giving a staff "negative" charges, or "turning a staff into a stick".
 * It seems as though a "rod of recharging" might in fact cause problems.
 * The basic problem is that the act of recharging (and destroying) an
 * item causes the inducer of that action to "move", causing "o_ptr" to
 * no longer point at the correct item, with horrifying results.
 */
void do_cmd_use(cmd_code code, cmd_arg args[])
{
    int item = args[0].item;
    object_type *o_ptr = object_from_item_idx(item);
    int effect;
    bool ident = FALSE, used = FALSE;
    bool was_aware = object_flavor_is_aware(o_ptr);
    int dir = 5;
    int px = p_ptr->px, py = p_ptr->py;
    int snd, boost, level;
    use_type use;
    int items_allowed = 0;

    /* Determine how this item is used. */
    if (obj_is_rod(o_ptr))
    {
        if (!obj_can_zap(o_ptr))
        {
            msg_print("That rod is still charging.");
            return;
        }

        use = USE_TIMEOUT;
        snd = MSG_ZAP_ROD;
        items_allowed = USE_INVEN | USE_FLOOR;
    }
    else if (obj_is_wand(o_ptr))
    {
        if (!obj_has_charges(o_ptr))
        {
            msg_print("That wand has no charges.");
            return;
        }

        use = USE_CHARGE;
        snd = MSG_ZAP_ROD;
        items_allowed = USE_INVEN | USE_FLOOR;
    }
    else if (obj_is_staff(o_ptr))
    {
        if (!obj_has_charges(o_ptr))
        {
            msg_print("That staff has no charges.");
            return;
        }

        use = USE_CHARGE;
        snd = MSG_USE_STAFF;
        items_allowed = USE_INVEN | USE_FLOOR;
    }
    else if (obj_is_food(o_ptr))
    {
        use = USE_SINGLE;
        snd = MSG_EAT;
        items_allowed = USE_INVEN | USE_FLOOR;
    }
    else if (obj_is_potion(o_ptr))
    {
        use = USE_SINGLE;
        snd = MSG_QUAFF;
        items_allowed = USE_INVEN | USE_FLOOR;
    }
    else if (obj_is_scroll(o_ptr))
    {
        /* Check player can use scroll */
        if (!player_can_read())
            return;

        use = USE_SINGLE;
        snd = MSG_GENERIC;
        items_allowed = USE_INVEN | USE_FLOOR;
    }
    else if (obj_is_activatable(o_ptr))
    {
        if (!obj_can_activate(o_ptr))
        {
            msg_print("That item is still charging.");
            return;
        }

        use = USE_TIMEOUT;
        snd = MSG_ACT_ARTIFACT;
        items_allowed = USE_EQUIP;
    }
    else
    {
        msg_print("The item cannot be used at the moment");
    }

    /* Check if item is within player's reach. */
    if (items_allowed == 0 || !item_is_available(item, NULL, items_allowed))
    {
        msg_print("You cannot use that item from its current location.");
        return;
    }

    /* track the object used */
    track_object(item);

    /* Figure out effect to use */
    effect = object_effect(o_ptr);

    /* If the item requires a direction, get one (allow cancelling) */
    if (obj_needs_aim(o_ptr))
        dir = args[1].direction;

    /* Check for use if necessary, and execute the effect */
    if ((use != USE_CHARGE && use != USE_TIMEOUT) ||
            check_devices(o_ptr))
    {
        /* Special message for artifacts */
        if (artifact_p(o_ptr))
        {
            message(snd, 0, "You activate it.");
            if (a_info[o_ptr->name1].effect_msg)
                activation_message(o_ptr, a_info[o_ptr->name1].effect_msg);
            level = a_info[o_ptr->name1].level;
        }
        else
        {
            /* Make a noise! */
            sound(snd);
            level = k_info[o_ptr->k_idx].level;
        }

        /* A bit of a hack to make ID work better.
        	-- Check for "obvious" effects beforehand. */
        if (effect_obvious(effect)) object_flavor_aware(o_ptr);

        /* Boost damage effects if skill > difficulty */
        boost = p_ptr->state.skills[SKILL_DEVICE] - level;
        if (boost < 0) boost = 0;

        /* Do effect */
        used = effect_do(effect, &ident, was_aware, dir,
                         beam_chance(o_ptr->tval), boost);

        /* Quit if the item wasn't used and no knowledge was gained */
        if (!used && (was_aware || !ident)) return;
    }

    /* If the item is a null pointer or has been wiped, be done now */
    if (!o_ptr || o_ptr->k_idx <= 1) return;

    if (ident) object_notice_effect(o_ptr);

    /* Food feeds the player */
    if (o_ptr->tval == TV_FOOD || o_ptr->tval == TV_POTION)
        (void)set_food(p_ptr->food + o_ptr->pval);

    /* Use the turn */
    p_ptr->energy_use = 100;

    /* Mark as tried and redisplay */
    p_ptr->notice |= (PN_COMBINE | PN_REORDER);
    p_ptr->redraw |= (PR_INVEN | PR_EQUIP | PR_OBJECT);

    /*
     * If the player becomes aware of the item's function, then mark it as
     * aware and reward the player with some experience.  Otherwise, mark
     * it as "tried".
     */
    if (ident && !was_aware)
    {
        /* Object level */
        int lev = k_info[o_ptr->k_idx].level;

        object_flavor_aware(o_ptr);
        if (o_ptr->tval == TV_ROD) object_notice_everything(o_ptr);
        gain_exp((lev + (p_ptr->lev / 2)) / p_ptr->lev);
        p_ptr->notice |= PN_SQUELCH;
    }
    else if (used)
    {
        object_flavor_tried(o_ptr);
    }

    /* If there are no more of the item left, then we're done. */
    if (!o_ptr->number) return;

    /* Chargeables act differently to single-used items when not used up */
    if (used && use == USE_CHARGE)
    {
        /* Use a single charge */
        o_ptr->pval--;

        /* Describe charges */
        if (item >= 0)
            inven_item_charges(item);
        else
            floor_item_charges(0 - item);
    }
    else if (used && use == USE_TIMEOUT)
    {
        /* Artifacts use their own special field */
        if (o_ptr->name1)
        {
            const artifact_type *a_ptr = &a_info[o_ptr->name1];
            o_ptr->timeout = randcalc(a_ptr->time, 0, RANDOMISE);
        }
        else
        {
            const object_kind *k_ptr = &k_info[o_ptr->k_idx];
            o_ptr->timeout += randcalc(k_ptr->time, 0, RANDOMISE);
        }
    }
    else if (used && use == USE_SINGLE)
    {
        /* Destroy a potion in the pack */
        if (item >= 0)
        {
            inven_item_increase(item, -1);
            inven_item_describe(item);
            inven_item_optimize(item);
        }

        /* Destroy a potion on the floor */
        else
        {
            floor_item_increase(0 - item, -1);
            floor_item_describe(0 - item);
            floor_item_optimize(0 - item);
        }
    }

    /* Hack to make Glyph of Warding work properly */
    if (cave_feat[py][px] == FEAT_GLYPH)
    {
        /* Shift any objects to further away */
        for (o_ptr = get_first_object(py, px); o_ptr; o_ptr =
                    get_next_object(o_ptr))
        {
            drop_near(o_ptr, 0, py, px, FALSE);
        }

        /* Delete the "moved" objects from their original position */
        delete_object(py, px);
    }


}
Exemplo n.º 8
0
/*
 * Update the current "run" path
 *
 * Return TRUE if the running should be stopped
 */
static bool run_test(void)
{
	int py = p_ptr->py;
	int px = p_ptr->px;

	int prev_dir;
	int new_dir;
	int check_dir = 0;

	int row, col;
	int i, max, inv;
	int option, option2;


	/* No options yet */
	option = 0;
	option2 = 0;

	/* Where we came from */
	prev_dir = p_ptr->run_old_dir;


	/* Range of newly adjacent grids */
	max = (prev_dir & 0x01) + 1;


	/* Look at every newly adjacent square. */
	for (i = -max; i <= max; i++)
	{
		object_type *o_ptr;


		/* New direction */
		new_dir = cycle[chome[prev_dir] + i];

		/* New location */
		row = py + ddy[new_dir];
		col = px + ddx[new_dir];


		/* Visible monsters abort running */
		if (cave_m_idx[row][col] > 0)
		{
			monster_type *m_ptr = &mon_list[cave_m_idx[row][col]];

			/* Visible monster */
			if (m_ptr->ml) return (TRUE);
		}

		/* Visible objects abort running */
		for (o_ptr = get_first_object(row, col); o_ptr; o_ptr = get_next_object(o_ptr))
		{
			/* Visible object */
			if (o_ptr->marked && !squelch_hide_item(o_ptr)) return (TRUE);
		}


		/* Assume unknown */
		inv = TRUE;

		/* Check memorized grids */
		if (cave_info[row][col] & (CAVE_MARK))
		{
			bool notice = TRUE;

			/* Examine the terrain */
			switch (cave_feat[row][col])
			{
				/* Floors */
				case FEAT_FLOOR:

				/* Invis traps */
				case FEAT_INVIS:

				/* Secret doors */
				case FEAT_SECRET:

				/* Normal veins */
				case FEAT_MAGMA:
				case FEAT_QUARTZ:

				/* Hidden treasure */
				case FEAT_MAGMA_H:
				case FEAT_QUARTZ_H:

				/* Walls */
				case FEAT_WALL_EXTRA:
				case FEAT_WALL_INNER:
				case FEAT_WALL_OUTER:
				case FEAT_WALL_SOLID:
				case FEAT_PERM_EXTRA:
				case FEAT_PERM_INNER:
				case FEAT_PERM_OUTER:
				case FEAT_PERM_SOLID:
				{
					/* Ignore */
					notice = FALSE;

					/* Done */
					break;
				}
			}

			/* Interesting feature */
			if (notice) return (TRUE);

			/* The grid is "visible" */
			inv = FALSE;
		}

		/* Analyze unknown grids and floors */
		if (inv || cave_floor_bold(row, col))
		{
			/* Looking for open area */
			if (p_ptr->run_open_area)
			{
				/* Nothing */
			}

			/* The first new direction. */
			else if (!option)
			{
				option = new_dir;
			}

			/* Three new directions. Stop running. */
			else if (option2)
			{
				return (TRUE);
			}

			/* Two non-adjacent new directions.  Stop running. */
			else if (option != cycle[chome[prev_dir] + i - 1])
			{
				return (TRUE);
			}

			/* Two new (adjacent) directions (case 1) */
			else if (new_dir & 0x01)
			{
				check_dir = cycle[chome[prev_dir] + i - 2];
				option2 = new_dir;
			}

			/* Two new (adjacent) directions (case 2) */
			else
			{
				check_dir = cycle[chome[prev_dir] + i + 1];
				option2 = option;
				option = new_dir;
			}
		}

		/* Obstacle, while looking for open area */
		else
		{
			if (p_ptr->run_open_area)
			{
				if (i < 0)
				{
					/* Break to the right */
					p_ptr->run_break_right = TRUE;
				}

				else if (i > 0)
				{
					/* Break to the left */
					p_ptr->run_break_left = TRUE;
				}
			}
		}
	}


	/* Look at every soon to be newly adjacent square. */
	for (i = -max; i <= max; i++)
	{		
		/* New direction */
		new_dir = cycle[chome[prev_dir] + i];
		
		/* New location */
		row = py + ddy[prev_dir] + ddy[new_dir];
		col = px + ddx[prev_dir] + ddx[new_dir];
		
		/* HACK: Ugh. Sometimes we come up with illegal bounds. This will
		 * treat the symptom but not the disease. */
		if (row >= DUNGEON_HGT || col >= DUNGEON_WID) continue;
		if (row < 0 || col < 0) continue;

		/* Visible monsters abort running */
		if (cave_m_idx[row][col] > 0)
		{
			monster_type *m_ptr = &mon_list[cave_m_idx[row][col]];
			
			/* Visible monster */
			if (m_ptr->ml) return (TRUE);			
		}
	}

	/* Looking for open area */
	if (p_ptr->run_open_area)
	{
		/* Hack -- look again */
		for (i = -max; i < 0; i++)
		{
			new_dir = cycle[chome[prev_dir] + i];

			row = py + ddy[new_dir];
			col = px + ddx[new_dir];

			/* Unknown grid or non-wall */
			/* Was: cave_floor_bold(row, col) */
			if (!(cave_info[row][col] & (CAVE_MARK)) ||
			    (cave_feat[row][col] < FEAT_SECRET))
			{
				/* Looking to break right */
				if (p_ptr->run_break_right)
				{
					return (TRUE);
				}
			}

			/* Obstacle */
			else
			{
				/* Looking to break left */
				if (p_ptr->run_break_left)
				{
					return (TRUE);
				}
			}
		}

		/* Hack -- look again */
		for (i = max; i > 0; i--)
		{
			new_dir = cycle[chome[prev_dir] + i];

			row = py + ddy[new_dir];
			col = px + ddx[new_dir];

			/* Unknown grid or non-wall */
			/* Was: cave_floor_bold(row, col) */
			if (!(cave_info[row][col] & (CAVE_MARK)) ||
			    (cave_feat[row][col] < FEAT_SECRET))
			{
				/* Looking to break left */
				if (p_ptr->run_break_left)
				{
					return (TRUE);
				}
			}

			/* Obstacle */
			else
			{
				/* Looking to break right */
				if (p_ptr->run_break_right)
				{
					return (TRUE);
				}
			}
		}
	}


	/* Not looking for open area */
	else
	{
		/* No options */
		if (!option)
		{
			return (TRUE);
		}

		/* One option */
		else if (!option2)
		{
			/* Primary option */
			p_ptr->run_cur_dir = option;

			/* No other options */
			p_ptr->run_old_dir = option;
		}

		/* Two options, examining corners */
		else
		{
			/* Primary option */
			p_ptr->run_cur_dir = option;

			/* Hack -- allow curving */
			p_ptr->run_old_dir = option2;
		}
	}


	/* About to hit a known wall, stop */
	if (see_wall(p_ptr->run_cur_dir, py, px))
	{
		return (TRUE);
	}


	/* Failure */
	return (FALSE);
}
Exemplo n.º 9
0
BOOL
pdhservice_translate(LPSTR object, LPSTR counter, LPSTR instance, 
                     BOOL is_english, LPSTR *new_object, LPSTR *new_counter, 
                     LPSTR *new_instance)
{
#if 0
#define DEBUG_SHOW_NAME
#endif
   BOOL instance_found = FALSE;
   BOOL counter_found = FALSE;
   BOOL object_found = FALSE;
   PPERF_DATA_BLOCK perf_data = NULL;
   DWORD buffer_size = TOTALBYTES;
   pdhservice_container *container1;
   pdhservice_container *container2;

   DENTER("pdhservice_translate");
   if (is_english) {
      container1 = &container_english;
      container2 = &container_system_lang;
   } else {
      container1 = &container_system_lang;
      container2 = &container_english;
   }

   // Allocate the buffer for the performance data.
   perf_data = (PPERF_DATA_BLOCK) malloc(buffer_size);
   if (perf_data != NULL) {
      PPERF_OBJECT_TYPE perf_object;
      DWORD i;

      while (RegQueryValueEx(HKEY_PERFORMANCE_DATA, "Global",
                             NULL, NULL, (LPBYTE) perf_data, 
                             &buffer_size) == ERROR_MORE_DATA) {
         /*
          * Increase buffer until it is big enough
          */
         buffer_size += BYTEINCREMENT;
         perf_data = (PPERF_DATA_BLOCK) realloc(perf_data, buffer_size);
      }

      /*
       * Process all objects
       */
      perf_object = get_first_object(perf_data);
      for(i = 0; !object_found && i < perf_data->NumObjectTypes; i++) {
         PPERF_COUNTER_DEFINITION perf_counter;

#ifdef DEBUG_SHOW_NAME
         printf("\nO %ld: %s\n", perf_object->ObjectNameTitleIndex,
                container1->names_array[perf_object->ObjectNameTitleIndex]);
         fflush(stdout);
#endif
         if (lstrcmp(container1->names_array[perf_object->ObjectNameTitleIndex], object) == 0) {
            *new_object = container2->names_array[perf_object->ObjectNameTitleIndex];
            object_found = TRUE;
         }

         perf_counter = get_first_counter(perf_object);
         if (perf_object->NumInstances > 0) {
            int k;

            /*
             * Process all instances
             */
            PPERF_INSTANCE_DEFINITION perf_instance = get_first_instance(perf_object);
            for (k = 0; !instance_found && k < perf_object->NumInstances; k++) {
               PPERF_COUNTER_DEFINITION perf_curinst;
               DWORD j;
               WCHAR wide_string[1024];


#ifdef DEBUG_SHOW_NAME
               printf( "\n\tI %S: \n", 
                      (char *)((PBYTE)perf_instance + perf_instance->NameOffset));
               fflush(stdout);
#endif
               /* The instance seems to be stored as multibyte string !? */
               mbstowcs(wide_string, instance, sizeof(wide_string)/sizeof(WCHAR));
               if (object_found && wcscmp((wchar_t *)((PBYTE)perf_instance + perf_instance->NameOffset), wide_string) == 0) {
                  *new_instance = instance;
                  instance_found = TRUE;
               } else if (object_found && lstrcmp("*", instance) == 0) {
                  *new_instance = "*";
                  instance_found = TRUE;
               }
               perf_curinst = perf_counter;
               // Retrieve all counters.

               for (j = 0; !counter_found && j < perf_object->NumCounters; j++) {
#ifdef DEBUG_SHOW_NAME
                    printf("\t\tC %ld: %s\n", 
                        perf_curinst->CounterNameTitleIndex,
                        container1->names_array[perf_curinst->CounterNameTitleIndex]);
                    fflush(stdout);
#endif

                  if (instance_found && lstrcmp(container1->names_array[perf_curinst->CounterNameTitleIndex], counter) == 0) {
                     *new_counter = container2->names_array[perf_curinst->CounterNameTitleIndex];
                     counter_found = TRUE;
                  }

                  perf_curinst = get_next_counter(perf_curinst);             
               }

               perf_instance = get_next_instance(perf_instance);
            }
         } else {
            WORD j;
            PPERF_COUNTER_BLOCK counter_block = (PPERF_COUNTER_BLOCK) ((PBYTE)perf_object +
                                                perf_object->DefinitionLength );

            for (j = 0; !counter_found && j < perf_object->NumCounters; j++) {
               // Display the counter by index and name.

#ifdef DEBUG_SHOW_NAME
               printf("\tC %ld: %s\n", perf_counter->CounterNameTitleIndex,
                      container1->names_array[perf_counter->CounterNameTitleIndex] != NULL ? 
                      container1->names_array[perf_counter->CounterNameTitleIndex] : "NULL");
               fflush(stdout);
#endif

               if (object_found && lstrcmp(container1->names_array[perf_counter->CounterNameTitleIndex], counter) == 0) {
                  *new_counter = container2->names_array[perf_counter->CounterNameTitleIndex];
                  counter_found = TRUE;
               }
                
               // Get the next counter.
               perf_counter = get_next_counter(perf_counter);
            }
         }
         
         // Get the next object type.

         perf_object = get_next_object(perf_object);
      }
      free(perf_data);
      perf_data = NULL;
   }
   DEXIT;
   return counter_found && object_found;
}
Exemplo n.º 10
0
/*
 * This is the entry point for generation statistics.
 */
static void stats_collect_level(void)
{
	static bool first = TRUE;
	size_t i, x, y;

	memset(o_count, 0, sizeof(o_count));
	memset(gold_count, 0, sizeof(gold_count));

	mon_gold = 0.0;
	mon_drop = 0.0;

	results_reset();
	result_add("level", format("%d", p_ptr->depth));


	for (i = 0; i < TRIES; i++)
	{
		generate_cave();

		/* Get stats on objects */
		for (y = 1; y < DUNGEON_HGT - 1; y++)
		{
			for (x = 1; x < DUNGEON_WID - 1; x++)
			{
				const object_type *obj = get_first_object(y, x);

				if (obj) do
				{
					if (obj->tval == TV_GOLD) gold_count[i] += obj->pval;
					else o_count[i]++;
				}
				while ((obj = get_next_object(obj)));
			}
		}

		/* Get stats on monsters */
		for (y = 1; y < DUNGEON_HGT - 1; y++)
		{
			for (x = 1; x < DUNGEON_WID - 1; x++)
			{
				if (cave_m_idx[y][x])
					stats_monster(&mon_list[cave_m_idx[y][x]]);
			}
		}
	}

	stats_print_o();
	stats_print_m();

	if (first)
	{
		/* printf("level,mon-drops"); */
		results_print_csv_titles();
		first = FALSE;
	}

	/* results_print_csv_pair("level", "mon-drops"); */
	results_print_csv();

	do_cmd_redraw();
}