示例#1
0
文件: mod.c 项目: ErisBlastar/osfree
struct o32_obj *
get_data_stack(struct LX_module * lx_mod) {
        if((lx_mod->lx_head_e32_exe->e32_stackobj == 0) ||
                (lx_mod->lx_head_e32_exe->e32_stackobj > get_obj_num(lx_mod))) {
                if (options.debugixfmgr) 
                {
                  io_log("Invalid data/stack object ==%lu, max=%lu\n",
                                  lx_mod->lx_head_e32_exe->e32_stackobj,
                                  get_obj_num(lx_mod));
                }
                return (struct o32_obj *)0;
        }
        return get_obj(lx_mod, lx_mod->lx_head_e32_exe->e32_stackobj);
}
示例#2
0
/**
 * Attempt to make an object
 *
 * \param c is the current dungeon level.
 * \param j_ptr is the object struct to be populated.
 * \param lev is the creation level of the object (not necessarily == depth).
 * \param good is whether the object is to be good
 * \param great is whether the object is to be great
 * \param value is the value to be returned to the calling function
 *
 * Returns the whether or not creation worked.
 */
bool make_object(struct cave *c, object_type *j_ptr, int lev, bool good,
	bool great, s32b *value)
{
	int base, art, div;
	object_kind *kind;

	/* Base level and artifact chance for the object */
	if (great) {
		art = ART_GREAT;
		base = lev + 10 + m_bonus(5, lev);
	} else if (good) {
		art = ART_GOOD;
		base = lev + 5 + m_bonus(5, lev);
	} else {
		art = ART_NORMAL;
		base = lev;
	}

	/* Small hack to bring artifact frequencies at low depths in line with V */
	div = 9 - p_ptr->depth;
	if (div < 1)
		div = 1;

	/* Try to make an artifact */
	if (one_in_(art * div)) {
		if (make_artifact(j_ptr, lev)) {
			if (value)
				*value = object_value_real(j_ptr, 1, FALSE, TRUE);
			return TRUE;
		}
	}

	/* Get the object, prep it and apply magic */
	kind = get_obj_num(base, good || great);
	if (!kind) return FALSE;
	object_prep(j_ptr, kind, base, RANDOMISE);
	apply_magic(j_ptr, base, FALSE, good, great);

	/* Generate multiple items */
	if (kind->gen_mult_prob >= randint1(100))
		j_ptr->number = randcalc(kind->stack_size, lev, RANDOMISE);

	if (j_ptr->number >= MAX_STACK_SIZE)
		j_ptr->number = MAX_STACK_SIZE - 1;

	/* Return value, increased for uncursed out-of-depth objects */
	if (value)
		*value = object_value_real(j_ptr, j_ptr->number, FALSE, TRUE);

	if (!cursed_p(j_ptr->flags) && (kind->alloc_min > c->depth)) {
		if (value) *value = (kind->alloc_min - c->depth) * (*value / 5);
	}

	return TRUE;
}
示例#3
0
文件: obj-make.c 项目: fizzix/angband
/**
 * Attempt to make an object
 *
 * \param c is the current dungeon level.
 * \param lev is the creation level of the object (not necessarily == depth).
 * \param good is whether the object is to be good
 * \param great is whether the object is to be great
 * \param extra_roll is whether we get an extra roll in apply_magic()
 * \param value is the value to be returned to the calling function
 * \param tval is the desired tval, or 0 if we allow any tval
 *
 * \return a pointer to the newly allocated object, or NULL on failure.
 */
struct object *make_object(struct chunk *c, int lev, bool good, bool great,
						   bool extra_roll, s32b *value, int tval)
{
	int base;
	struct object_kind *kind;
	struct object *new_obj;

	/* Try to make a special artifact */
	if (one_in_(good ? 10 : 1000)) {
		new_obj = make_artifact_special(lev);
		if (new_obj) {
			if (value) *value = object_value_real(new_obj, 1, false);
			return new_obj;
		}

		/* If we failed to make an artifact, the player gets a good item */
		good = true;
	}

	/* Base level for the object */
	base = (good ? (lev + 10) : lev);

	/* Try to choose an object kind */
	kind = get_obj_num(base, good || great, tval);
	if (!kind)
		return NULL;

	/* Make the object, prep it and apply magic */
	new_obj = object_new();
	object_prep(new_obj, kind, lev, RANDOMISE);
	if (one_in_(20) && tval_is_wearable(new_obj)) {
		apply_curse(new_obj, &lev);
	}
	apply_magic(new_obj, lev, true, good, great, extra_roll);
	apply_curse_knowledge(new_obj);

	/* Generate multiple items */
	if (kind->gen_mult_prob >= randint1(100))
		new_obj->number = randcalc(kind->stack_size, lev, RANDOMISE);

	if (new_obj->number > z_info->stack_size)
		new_obj->number = z_info->stack_size;

	/* Get the value */
	if (value)
		*value = object_value_real(new_obj, new_obj->number, false);

	/* Boost of 20% per level OOD for uncursed objects */
	if ((!new_obj->curses) && (kind->alloc_min > c->depth)) {
		if (value) *value += (kind->alloc_min - c->depth) * (*value / 5);
	}

	return new_obj;
}
示例#4
0
/**
 * Attempt to make an object
 *
 * \param c is the current dungeon level.
 * \param lev is the creation level of the object (not necessarily == depth).
 * \param good is whether the object is to be good
 * \param great is whether the object is to be great
 * \param extra_roll is whether we get an extra roll in apply_magic()
 * \param value is the value to be returned to the calling function
 * \param tval is the desired tval, or 0 if we allow any tval
 *
 * \return a pointer to the newly allocated object, or NULL on failure.
 */
struct object *make_object(struct chunk *c, int lev, bool good, bool great,
						   bool extra_roll, s32b *value, int tval)
{
	int base;
	object_kind *kind;
	struct object *new_obj;

	/* Try to make a special artifact */
	if (one_in_(good ? 10 : 1000)) {
		new_obj = make_artifact_special(lev);
		if (new_obj) {
			if (value) *value = object_value_real(new_obj, 1, FALSE, TRUE);
			return new_obj;
		}

		/* If we failed to make an artifact, the player gets a good item */
		good = TRUE;
	}

	/* Base level for the object */
	base = (good ? (lev + 10) : lev);

	/* Try to choose an object kind */
	kind = get_obj_num(base, good || great, tval);
	if (!kind)
		return NULL;

	/* Make the object, prep it and apply magic */
	new_obj = object_new();
	object_prep(new_obj, kind, lev, RANDOMISE);
	apply_magic(new_obj, lev, TRUE, good, great, extra_roll);

	/* Generate multiple items */
	if (kind->gen_mult_prob >= randint1(100))
		new_obj->number = randcalc(kind->stack_size, lev, RANDOMISE);

	if (new_obj->number > z_info->stack_size)
		new_obj->number = z_info->stack_size;

	/* Return value, increased for uncursed out-of-depth objects */
	if (value)
		*value = object_value_real(new_obj, new_obj->number, FALSE, TRUE);

	/* This seems to imply objects get less value from being > 1 but < 5
	 * levels out of depth - should it be *value +=... - NRM */
	if (!cursed_p(new_obj->flags) && (kind->alloc_min > c->depth)) {
		if (value) *value = (kind->alloc_min - c->depth) * (*value / 5);
	}

	return new_obj;
}
示例#5
0
/*
 * Attempt to make an object (normal or good/great)
 *
 * This routine plays nasty games to generate the "special artifacts".
 *
 * We assume that the given object has been "wiped".
 */
bool make_object(object_type *j_ptr, int lev, bool good, bool great)
{
	int k_idx, base;
	object_kind *k_ptr;

	/* Try to make a special artifact */
	if (one_in_(good ? 10 : 1000))
	{
		if (make_artifact_special(j_ptr, lev)) return TRUE;
		/* If we failed to make an artifact, the player gets a great item */
		good = great = TRUE;
	}

	/* Base level for the object */
	base = (good ? (lev + 10) : lev);

	/* Get the object */
	k_idx = get_obj_num(base, good || great);
	if (!k_idx) return FALSE;

	/* Prepare the object */
	object_prep(j_ptr, &k_info[k_idx], lev, RANDOMISE);

	/* Apply magic (allow artifacts) */
	apply_magic(j_ptr, lev, TRUE, good, great);


	/* Generate multiple items */
	k_ptr = &k_info[j_ptr->k_idx];

	if (k_ptr->gen_mult_prob >= 100 ||
	    k_ptr->gen_mult_prob >= randint1(100))
	{
		j_ptr->number = randcalc(k_ptr->stack_size, lev, RANDOMISE);
	}


	/* Notice "okay" out-of-depth objects */
	if (!cursed_p(j_ptr) && (k_info[j_ptr->k_idx].level > p_ptr->depth))
	{
		/* Rating increase */
		rating += (k_info[j_ptr->k_idx].alloc_min - p_ptr->depth);

		/* Cheat -- peek at items */
		if (OPT(cheat_peek)) object_mention(j_ptr);
	}

	return TRUE;
}
示例#6
0
文件: obj-make.c 项目: Dasaan/angband
/**
 * Attempt to make an object
 *
 * \param c is the current dungeon level.
 * \param j_ptr is the object struct to be populated.
 * \param lev is the creation level of the object (not necessarily == depth).
 * \param good is whether the object is to be good
 * \param great is whether the object is to be great
 * \param value is the value to be returned to the calling function
 * \param tval is the desired tval, or 0 if we allow any tval
 *
 * Returns the whether or not creation worked.
 */
bool make_object(struct cave *c, object_type *j_ptr, int lev, bool good,
	bool great, bool extra_roll, s32b *value, int tval)
{
	int base;
	object_kind *kind;

	/* Try to make a special artifact */
	if (one_in_(good ? 10 : 1000)) {
		if (make_artifact_special(j_ptr, lev)) {
			if (value) *value = object_value_real(j_ptr, 1, FALSE, TRUE);
			return TRUE;
		}

		/* If we failed to make an artifact, the player gets a good item */
		good = TRUE;
	}

	/* Base level for the object */
	base = (good ? (lev + 10) : lev);

	/* Get the object, prep it and apply magic */
	kind = get_obj_num(base, good || great, tval);
	if (!kind) return FALSE;
	object_prep(j_ptr, kind, lev, RANDOMISE);
	apply_magic(j_ptr, lev, TRUE, good, great, extra_roll);

	/* Generate multiple items */
	if (kind->gen_mult_prob >= randint1(100))
		j_ptr->number = randcalc(kind->stack_size, lev, RANDOMISE);

	if (j_ptr->number >= MAX_STACK_SIZE)
		j_ptr->number = MAX_STACK_SIZE - 1;

	/* Return value, increased for uncursed out-of-depth objects */
	if (value)
		*value = object_value_real(j_ptr, j_ptr->number, FALSE, TRUE);

	if (!cursed_p(j_ptr->flags) && (kind->alloc_min > c->depth)) {
		if (value) *value = (kind->alloc_min - c->depth) * (*value / 5);
	}

	return TRUE;
}
示例#7
0
文件: load.c 项目: ErisBlastar/osfree
/* @brief Loads all the objects in a dll and exe. */
int LXLoadObjects(IXFModule * ixfModule)
{
  struct LX_module * lx_exe_mod=(struct LX_module *)(ixfModule->FormatStruct);
  void * vm_code_obj;
  unsigned int obj_cnt;
  struct o32_obj * kod_obj;
  unsigned long int number_of_objects = get_obj_num(lx_exe_mod);
  
  for(obj_cnt=1; obj_cnt<=number_of_objects; obj_cnt++)
  {
    kod_obj = get_obj(lx_exe_mod, obj_cnt);
    vm_code_obj = 0;
#if 0 /*!defined(__OS2__) && !defined(__LINUX__)*/
                if( !is_mem_used(&root_area/*proc->root_mem_area*/,
                                    (void *) kod_obj->o32_reserved, kod_obj->o32_size) ) {
                                    //(void *) kod_obj->o32_base, kod_obj->o32_size) ) {
                        vm_code_obj = (void*) vm_alloc_obj_lx(lx_exe_mod, kod_obj);
                } else {
                        unsigned long int new_base = (unsigned long int) seek_free_mem(
                                                            &root_area/*proc->root_mem_area*/,
                                                            kod_obj->o32_size);
                        /*  What kind of requirements is there on allocated memory
                            for DLLs is OS/2? Allocated in "Shared Area"? Where is that,
                            from 128 MiB and downwards to 64 MiB???
                            This would be the place to make that kind of call.
                            But, for now, just allocate the space somewhere.
                            Which just goes through the memory registry from beginning,
                            position 1 and upward and grabs first free space. */
                        if( is_mem_used(&root_area/*proc->root_mem_area*/,
                                        (void *) new_base,
                                        kod_obj->vm_size) )
                                        //kod_obj->o32_size) )
                                io_printf("Error allocating used memory!!! 0x%lx \n", new_base);
                        //kod_obj->o32_base = new_base;
                        kod_obj->o32_reserved = new_base;
			//io_printf(" new_base: 0x%lx, %lu \n", new_base, new_base);
                        vm_code_obj = (void*) vm_alloc_obj_lx(lx_exe_mod, kod_obj);
                        //io_printf(" new_base == %p ?\n", vm_code_obj);
                }

#else
// In OS/2 no normal mmap() support, so we always relocate objects
    vm_code_obj = (void*) vm_alloc_obj_lx(ixfModule, kod_obj);
    // use 'reserved' field for VM address of an object
    kod_obj->o32_reserved = (unsigned long)vm_code_obj;
    if (ixfModule->PIC)
      kod_obj->o32_base = kod_obj->o32_reserved;
    //io_printf("o32_base=%x\n", kod_obj->o32_base);
    //io_printf("o32_reserved=%x\n", kod_obj->o32_reserved);
#endif
    // Register allocated area
    //alloc_mem_area(&root_area, (void *) kod_obj->o32_base, kod_obj->o32_size);
    alloc_mem_area(&root_area, (void *) kod_obj->o32_reserved, kod_obj->o32_size);

    if(vm_code_obj == MAP_FAILED) {
                        io_printf("Error mapping memory for (code)\n");
                        print_o32_obj_info(*kod_obj, "object code");
                        return 0;
                }

                load_obj_lx(lx_exe_mod, kod_obj, vm_code_obj);

                if (options.debugixfmgr)
                  print_o32_obj_info(*kod_obj, "object 1");
        }

        return 1;
}
示例#8
0
/*
 * Output a rarity graph for a type of object.
 *
 * Use a monte-carlo method to calculate the probabilities.
 */
static void prt_alloc(const object_type *o_ptr, int row, int col, u32b monte)
{
	u32b i, j;
	u32b maxd = 1, maxr = 1, maxt = 1;
	u32b rarity[MAX_DEPTH];
	u32b total[MAX_DEPTH];
	u32b display[20];
	byte c = TERM_WHITE;
	cptr r = "+--common--+";
	u16b kind = o_ptr->k_idx;
	u16b home = k_info[kind].level;

	/* Wipe the tables */
	(void)C_WIPE(rarity, MAX_DEPTH, u32b);
	(void)C_WIPE(total, MAX_DEPTH, u32b);
	(void)C_WIPE(display, 20, u32b);

	msg_print(NULL);
	prt("Calculating probability distribution - please wait.", 0, 0);

	/* Refresh */
	Term_fresh();

	/* Scan all entries */
	for (i = 0; i < MAX_DEPTH; i++)
	{
		for (j = 0; j < monte; j++)
		{
			if (get_obj_num(i, 0) == kind) rarity[i]++;
		}

		total[i] = monte;
	}

	/* Find maxima */
	for (i = 0; i < MAX_DEPTH; i++)
	{
		if (rarity[i] > maxr) maxr = rarity[i];
		if (total[i] > maxt) maxt = total[i];
	}

	/* Simulate a log graph */
	if (maxt / maxr > 32)
	{
		c = TERM_L_WHITE;
		r = "+-uncommon-+";
	}
	if (maxt / maxr > 1024)
	{
		c = TERM_SLATE;
		r = "+---rare---+";
	}
	if (maxt / maxr > 32768L)
	{
		c = TERM_L_DARK;
		r = "+--unique--+";
	}

	/* Calculate probabilities for each range */
	for (i = 0; i < 20; i++)
	{
		/* Shift the values into view */
		for (j = i * MAX_DEPTH / 20; j < (i + 1) * MAX_DEPTH / 20; j++)
		{
			display[i] += rarity[j] * maxt * 10 / total[j];
		}

		/* Correct proportions */
		display[i] /= maxr;

		/* Track maximum */
		if (display[i] > maxd) maxd = display[i];
	}

	/* Normalize */
	for (i = 0; i < 20; i++)
	{
		display[i] = display[i] * 10 / maxd;
	}

	/* Graph the rarities */
	for (i = 0; i < 20; i++)
	{
		Term_putch(col, row + i + 1, TERM_WHITE,  '|');

		/* Note the level */
		if ((i * MAX_DEPTH / 20 <= home) && (home < (i + 1) * MAX_DEPTH / 20))
		{
			c_prt(TERM_RED, format("%.*s", display[i], "**********"), row + i + 1, col + 1);
		}
		else
		{
			c_prt(c, format("%.*s", display[i], "**********"), row + i + 1, col + 1);
		}
	}

	/* Make it look nice */
	prt(r, row, col);

	Term_putch(col, row + 2, TERM_WHITE,  '6');

	Term_putch(col, row + 8, TERM_WHITE,  'A');
	Term_putch(col, row + 9, TERM_WHITE,  'L');
	Term_putch(col, row + 10, TERM_WHITE, 'L');
	Term_putch(col, row + 11, TERM_WHITE, 'O');
	Term_putch(col, row + 12, TERM_WHITE, 'C');

	prt("+", row + 21, col);
}