Beispiel #1
0
int main()
{
	object_t *o;
	char *s;
	const char *string_type = "STRING";
	type_t *type;

	plan(9);
	
	type = type_get(string_type);
	type_set_callback(type, "free", free);

	s = calloc(20, sizeof(char));
	strcpy(s, "Hello, object world");

	o = object_new(string_type, s);
	ok(o != NULL, "object is not NULL");
	ok(object_isset(o), "object is set");
	ok(object_isa(o, string_type), "object isa '%s'", string_type);
	str_eq(object_type(o), string_type);
	ok(object_type(o) == string_type, "object_type() returns direct pointer to type string");
	str_eq(object_value(o), s);
	ok(object_value(o) == s, "object_value() returns direct pointer to value");

	object_set(o, "Goodbye");
	str_eq(object_value(o), "Goodbye");
	object_set(o, s);

	object_free(o);
	ok(object_isset(NULL) == 0, "NULL is considered as an unset object");

	types_finalize();

	return 0;
}
Beispiel #2
0
/**
 * Determine if the current store will purchase the given object
 *
 * Note that a shop-keeper must refuse to buy "worthless" objects
 */
static bool store_will_buy(struct store *store, const struct object *obj)
{
	struct object_buy *buy;

	/* Home accepts anything */
	if (store->sidx == STORE_HOME) return TRUE;

	/* Ignore "worthless" items */
	if (object_value(obj, 1, FALSE) <= 0) return FALSE;

	/* No buy list means we buy anything */
	if (!store->buy) return TRUE;

	/* Run through the buy list */
	for (buy = store->buy; buy; buy = buy->next) {
		/* Wrong tval */
		if (buy->tval != obj->tval) continue;

		/* No flag means we're good */
		if (!buy->flag) return TRUE;

		/* OK if the object is known to have the flag */
		if (of_has(obj->flags, buy->flag) &&
			object_flag_is_known(obj, buy->flag))
			return TRUE;
	}

	/* Not on the list */
	return FALSE;
}
Beispiel #3
0
cwaf_cb cwaf_callback_get(cwaf_callback_t *callback)
{
	cwaf_cb cb = NULL;

	if (object_isa(callback, cwaf_callback_type)) {
		cb = object_value(callback);
	}

	return cb;
}
Beispiel #4
0
/**
 * Display an item's properties
 */
static void wiz_display_item(object_type * o_ptr)
{
	int j = 0;

	char buf[256];


	/* Clear screen */
	Term_clear();

	/* Describe fully */
	object_desc(buf, sizeof(buf), o_ptr,
				ODESC_PREFIX | ODESC_FULL | ODESC_SPOIL);
	prt(buf, 2, j);

	prt(format
		("kind = %-5d  level = %-4d  tval = %-5d  sval = %-5d",
		 o_ptr->k_idx, k_info[o_ptr->k_idx].level, o_ptr->tval,
		 o_ptr->sval), 4, j);

	prt(format
		("number = %-3d  wgt = %-6d  ac = %-5d    damage = %dd%d",
		 o_ptr->number, o_ptr->weight, o_ptr->ac, o_ptr->dd, o_ptr->ds), 5,
		j);

	prt(format
		("pval = %-5d  toac = %-5d  tohit = %-4d  todam = %-4d",
		 o_ptr->pval, o_ptr->to_a, o_ptr->to_h, o_ptr->to_d), 6, j);

	prt(format
		("name1 = %-4d  name2 = %-4d  cost = %ld", o_ptr->name1,
		 o_ptr->name2, (long) object_value(o_ptr)), 7, j);

	prt(format
		("ident = %04x  timeout = %-d", o_ptr->ident, o_ptr->timeout), 8,
		j);

	prt("+------------FLAGS_------------+", 10, j);
	prt("..SUST..POWERS....OTHER.........", 11, j);
	prt("                                ", 12, j);
	prt("tbsiwdcc  re   s  ttbiaefc   f..", 13, j);
	prt("hatnieohsfessfhefphhlmcliosspr..", 14, j);
	prt("rlrtsxnadfgpialerlrdspppppmcca..", 15, j);
	prt_binary(o_ptr->flags_obj, 0, 16, j, '*', 32);

	prt("+------------CURSES------------+", 17, j);
	prt("	n r    b b       b             ", 18, j);
	prt("ttaasahppcuhdaassppdddd.........", 19, j);
	prt("eeggrfuooutawduttaaxssc.........", 20, j);
	prt("llggerniitrlemncwrrppth.........", 21, j);
	prt_binary(o_ptr->flags_curse, 0, 22, j, '*', 32);
	prt("Resists, bonuses and slays coming soon...", 23, j);
}
Token *Token_create(String *value, int line, int column) {
  Token *token = calloc(1, sizeof(Token));
  check_mem(token);

  object_value(token) = value;
  token_line(token) = line;
  token_column(token) = column;

  return token;
error:
  return NULL;
}
Beispiel #6
0
/**
 * Describe the kind
 */
static void kind_info(char *buf, size_t buf_len, char *dam, size_t dam_len,
					  char *wgt, size_t wgt_len, int *lev, s32b *val, int k)
{
	struct object_kind *kind = &k_info[k];
	struct object *obj = object_new(), *known_obj = object_new();
	int i;

	/* Prepare a fake item */
	object_prep(obj, kind, 0, MAXIMISE);

	/* Cancel bonuses */
	for (i = 0; i < OBJ_MOD_MAX; i++)
		obj->modifiers[i] = 0;
	obj->to_a = 0;
	obj->to_h = 0;
	obj->to_d = 0;

	/* Level */
	(*lev) = kind->level;

	/* Make known */
	object_copy(known_obj, obj);
	obj->known = known_obj;

	/* Value */
	(*val) = object_value(obj, 1, false);

	/* Description (too brief) */
	if (buf)
		object_desc(buf, buf_len, obj, ODESC_BASE | ODESC_SPOIL);

	/* Weight */
	if (wgt)
		strnfmt(wgt, wgt_len, "%3d.%d", obj->weight / 10, obj->weight % 10);

	/* Hack */
	if (!dam)
		return;

	/* Misc info */
	dam[0] = '\0';

	/* Damage */
	if (tval_is_ammo(obj) || tval_is_melee_weapon(obj))
		strnfmt(dam, dam_len, "%dd%d", obj->dd, obj->ds);
	else if (tval_is_armor(obj))
		strnfmt(dam, dam_len, "%d", obj->ac);

	object_delete(&known_obj);
	object_delete(&obj);
}
Beispiel #7
0
/**
 * Some cheap objects should be created in piles.
 */
static void mass_produce(struct object *obj)
{
	int size = 1;
	s32b cost = object_value(obj, 1, FALSE);

	/* Analyze the type */
	switch (obj->tval)
	{
		/* Food, Flasks, and Lights */
		case TV_FOOD:
		case TV_MUSHROOM:
		case TV_FLASK:
		case TV_LIGHT:
		{
			if (cost <= 5L) size += mass_roll(3, 5);
			if (cost <= 20L) size += mass_roll(3, 5);
			break;
		}

		case TV_POTION:
		case TV_SCROLL:
		{
			if (cost <= 60L) size += mass_roll(3, 5);
			if (cost <= 240L) size += mass_roll(1, 5);
			break;
		}

		case TV_MAGIC_BOOK:
		case TV_PRAYER_BOOK:
		{
			if (cost <= 50L) size += mass_roll(2, 3);
			if (cost <= 500L) size += mass_roll(1, 3);
			break;
		}

		case TV_SOFT_ARMOR:
		case TV_HARD_ARMOR:
		case TV_SHIELD:
		case TV_GLOVES:
		case TV_BOOTS:
		case TV_CLOAK:
		case TV_HELM:
		case TV_CROWN:
		case TV_SWORD:
		case TV_POLEARM:
		case TV_HAFTED:
		case TV_DIGGING:
		case TV_BOW:
		{
			if (obj->ego) break;
			if (cost <= 10L) size += mass_roll(3, 5);
			if (cost <= 100L) size += mass_roll(3, 5);
			break;
		}

		case TV_SHOT:
		case TV_ARROW:
		case TV_BOLT:
		{
			if (cost <= 5L)
				size = randint1(2) * 20;         /* 20-40 in 20s */
			else if (cost > 5L && cost <= 50L)
				size = randint1(4) * 10;         /* 10-40 in 10s */
			else if (cost > 50 && cost <= 500L)
				size = randint1(4) * 5;          /* 5-20 in 5s */
			else
				size = 1;

			break;
		}
	}

	/* Save the total pile size */
	obj->number = size;
}
Beispiel #8
0
/**
 * Determine the price of an object (qty one) in a store.
 *
 *  store_buying == TRUE  means the shop is buying, player selling
 *               == FALSE means the shop is selling, player buying
 *
 * This function never lets a shop-keeper lose money in a transaction.
 *
 * The "greed" value should exceed 100 when the player is "buying" the
 * object, and should be less than 100 when the player is "selling" it.
 *
 * Hack -- the black market always charges twice as much as it should.
 */
int price_item(struct store *store, const struct object *obj,
			   bool store_buying, int qty)
{
	int adjust = 100;
	int price;
	struct owner *proprietor;

	if (!store) return 0L;

	proprietor = store->owner;

	/* Get the value of the stack of wands, or a single item */
	if (tval_can_have_charges(obj))
		price = object_value(obj, qty, FALSE);
	else
		price = object_value(obj, 1, FALSE);

	/* Worthless items */
	if (price <= 0) return (0L);

	/* The black market is always a worse deal */
	if (store->sidx == STORE_B_MARKET)
		adjust = 150;

	/* Shop is buying */
	if (store_buying) {
		/* Set the factor */
		adjust = 100 + (100 - adjust);
		if (adjust > 100) adjust = 100;

		/* Shops now pay 2/3 of true value */
		price = price * 2 / 3;

		/* Black market sucks */
		if (store->sidx == STORE_B_MARKET)
			price = price / 2;

		/* Check for no_selling option */
		if (OPT(birth_no_selling)) return (0L);
	} else {
		/* Recalculate if the player doesn't know the flavour */
		if (!obj->kind->aware) {
			obj->kind->aware = TRUE;
			if (tval_can_have_charges(obj))
				price = object_value(obj, qty, FALSE);
			else
				price = object_value(obj, 1, FALSE);
			obj->kind->aware = FALSE;
		}

		/* Black market sucks */
		if (store->sidx == STORE_B_MARKET)
			price = price * 2;
	}

	/* Compute the final price (with rounding) */
	price = (price * adjust + 50L) / 100L;

	/* Now convert price to total price for non-wands */
	if (!tval_can_have_charges(obj))
		price *= qty;

	/* Now limit the price to the purse limit */
	if (store_buying && (price > proprietor->max_cost * qty))
		price = proprietor->max_cost * qty;

	/* Note -- Never become "free" */
	if (price <= 0L) return (qty);

	/* Return the price */
	return (price);
}
Beispiel #9
0
/*
 * Destroy an item
 */
void do_cmd_destroy(void)
{
    int          item, amt = 1;
    int          old_number;
    bool         force = FALSE;
    object_type *o_ptr;
    object_type  forge;
    object_type *q_ptr = &forge;
    bool         is_equipped = FALSE;
    char         o_name[MAX_NLEN];
    char         out_val[MAX_NLEN+40];

    cptr q, s;
    int mode = USE_INVEN | USE_FLOOR;

    if (p_ptr->pclass == CLASS_RUNE_KNIGHT)
        mode |= USE_EQUIP;

    if (p_ptr->special_defense & KATA_MUSOU)
    {
        set_action(ACTION_NONE);
    }

    /* Hack -- force destruction */
    if (command_arg > 0) force = TRUE;


    /* Get an item */
    q = "Destroy which item? ";
    s = "You have nothing to destroy.";

    if (!get_item(&item, q, s, mode)) return;

    /* Get the item (in the pack) */
    if (item >= 0)
    {
        o_ptr = &inventory[item];
        is_equipped = equip_is_valid_slot(item);
    }

    /* Get the item (on the floor) */
    else
    {
        o_ptr = &o_list[0 - item];
    }

    /* Hack for Rune Knight: They can destroy worn equipment, but only
       if it has the Sacrifice rune.  get_item() is not smart enough
       to handle this restriction ... */
    if (is_equipped && o_ptr->rune != RUNE_SACRIFICE)
    {
        msg_print("You must first remove that item before destroying it.");
        return;
    }

    /* Verify unless quantity given beforehand */
    if (!force && (confirm_destroy || (object_value(o_ptr) > 0)))
    {
        object_desc(o_name, o_ptr, OD_OMIT_PREFIX);

        /* Make a verification */
        sprintf(out_val, 
            "Really destroy %s? [y/n/Auto]",
            o_name);

        msg_print(NULL);

        /* HACK : Add the line to message buffer */
        message_add(out_val);
        p_ptr->window |= (PW_MESSAGE);
        window_stuff();

        /* Get an acceptable answer */
        while (TRUE)
        {
            char i;

            /* Prompt */
            prt(out_val, 0, 0);

            i = inkey();

            /* Erase the prompt */
            prt("", 0, 0);


            if (i == 'y' || i == 'Y')
            {
                break;
            }
            if (i == ESCAPE || i == 'n' || i == 'N')
            {
                /* Cancel */
                return;
            }
            if (i == 'A')
            {
                /* Add an auto-destroy preference line */
                if (autopick_autoregister(o_ptr))
                {
                    /* Auto-destroy it */
                    autopick_alter_item(item, TRUE);
                }

                /* The object is already destroyed. */
                return;
            }
        } /* while (TRUE) */
    }

    /* See how many items */
    if (o_ptr->number > 1)
    {
        /* Get a quantity */
        amt = get_quantity(NULL, o_ptr->number);

        /* Allow user abort */
        if (amt <= 0) return;
    }


    /* Describe the object */
    old_number = o_ptr->number;
    o_ptr->number = amt;
    object_desc(o_name, o_ptr, 0);
    o_ptr->number = old_number;

    /* Take a turn */
    energy_use = 100;

    /* Artifacts cannot be destroyed */
    if (!can_player_destroy_object(o_ptr))
    {
        energy_use = 0;

        /* Message */
        msg_format("You cannot destroy %s.", o_name);

        /* Done */
        return;
    }

    object_copy(q_ptr, o_ptr);

    stats_on_p_destroy(o_ptr, amt);

    if (prace_is_(RACE_MON_JELLY))
        jelly_eat_object(o_ptr);
    else if (prace_is_(RACE_MON_SWORD) && object_is_melee_weapon(o_ptr))
        sword_absorb_object(o_ptr);
    else if (prace_is_(RACE_MON_RING) && object_is_jewelry(o_ptr))
        ring_absorb_object(o_ptr);
    else
        msg_format("You destroy %s.", o_name);

    if (o_ptr->rune == RUNE_SACRIFICE)
    {
        int add_hp = is_equipped ? p_ptr->mhp : p_ptr->mhp/3;
        int add_sp = is_equipped ? p_ptr->msp : p_ptr->msp/3;

        msg_print("You feel a surge of wondrous power enter your body.");
        
        p_ptr->chp = MIN(p_ptr->mhp, p_ptr->chp + add_hp);
        p_ptr->chp_frac = 0;
        p_ptr->csp = MIN(p_ptr->msp, p_ptr->csp + add_sp);
        p_ptr->csp_frac = 0;

        p_ptr->redraw |= (PR_MANA);
        p_ptr->window |= (PW_PLAYER);
        p_ptr->window |= (PW_SPELL);
        p_ptr->redraw |= (PR_HP);

        if (is_equipped)
        {
            blast_object(o_ptr);
            o_ptr->curse_flags = TRC_HEAVY_CURSE;
        }
    }
    else if (is_equipped)
        blast_object(o_ptr);

    sound(SOUND_DESTITEM);

    /* Reduce the charges of rods/wands */
    reduce_charges(o_ptr, amt);

    /* Eliminate the item (from the pack) */
    if (item >= 0)
    {
        if (!is_equipped)
        {
            inven_item_increase(item, -amt);
            inven_item_describe(item);
            inven_item_optimize(item);
        }
    }

    /* Eliminate the item (from the floor) */
    else
    {
        floor_item_increase(0 - item, -amt);
        floor_item_describe(0 - item);
        floor_item_optimize(0 - item);
    }

    if ( p_ptr->pclass == CLASS_NECROMANCER
      && (q_ptr->tval == TV_LIFE_BOOK || q_ptr->tval == TV_CRUSADE_BOOK) )
    {
        int sp = 0;
        int osp = p_ptr->csp;
        switch (q_ptr->sval)
        {
        case 0: sp = 10; break;
        case 1: sp = 25; break;
        case 2: sp = 100; break;
        case 3: sp = 666; break;
        }

        p_ptr->csp += sp;
        if (p_ptr->csp >= p_ptr->msp)
        {
            p_ptr->csp = p_ptr->msp;
            p_ptr->csp_frac = 0;
        }

        if (p_ptr->csp > osp)
            msg_print("You feel your head clear.");

        p_ptr->redraw |= (PR_MANA);
    }

    if (high_level_book(q_ptr))
    {
        bool gain_expr = FALSE;

        if (p_ptr->prace == RACE_ANDROID)
        {
        }
        else if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_BERSERKER))
        {
            gain_expr = TRUE;
        }
        else if (p_ptr->pclass == CLASS_PALADIN)
        {
            if (is_good_realm(p_ptr->realm1))
            {
                if (!is_good_realm(tval2realm(q_ptr->tval))) gain_expr = TRUE;
            }
            else
            {
                if (is_good_realm(tval2realm(q_ptr->tval))) gain_expr = TRUE;
            }
        }

        if (gain_expr && (p_ptr->exp < PY_MAX_EXP))
        {
            s32b tester_exp = p_ptr->max_exp / 20;
            if (tester_exp > 10000) tester_exp = 10000;
            if (q_ptr->sval < 3) tester_exp /= 4;
            if (tester_exp<1) tester_exp = 1;

            msg_print("You feel more experienced.");
            gain_exp(tester_exp * amt);
        }
    }

    if (high_level_book(q_ptr) && q_ptr->tval == TV_LIFE_BOOK)
    {
        virtue_add(VIRTUE_UNLIFE, 1);
        virtue_add(VIRTUE_VITALITY, -1);
    }
    else if ( high_level_book(q_ptr) 
           && (q_ptr->tval == TV_DEATH_BOOK || q_ptr->tval == TV_NECROMANCY_BOOK) )
    {
        virtue_add(VIRTUE_UNLIFE, -1);
        virtue_add(VIRTUE_VITALITY, 1);
    }    

    if (q_ptr->to_a || q_ptr->to_h || q_ptr->to_d)
        virtue_add(VIRTUE_ENCHANTMENT, -1);
    
    if (object_value_real(q_ptr) > 30000)
        virtue_add(VIRTUE_SACRIFICE, 2);
    
    else if (object_value_real(q_ptr) > 10000)
        virtue_add(VIRTUE_SACRIFICE, 1);

    if (q_ptr->to_a != 0 || q_ptr->to_d != 0 || q_ptr->to_h != 0)
        virtue_add(VIRTUE_HARMONY, 1);

    if (equip_is_valid_slot(item)) 
        calc_android_exp();
}
Beispiel #10
0
/*
 * Describe the kind
 */
static void kind_info(char *buf, size_t buf_len,
                      char *dam, size_t dam_len,
                      char *wgt, size_t wgt_len,
                      int *lev, s32b *val, int k)
{
	object_kind *k_ptr;

	object_type *i_ptr;
	object_type object_type_body;
	int i;

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

	/* Prepare a fake item */
	object_prep(i_ptr, &k_info[k], 0, MAXIMISE);

	/* Obtain the "kind" info */
	k_ptr = i_ptr->kind;

	/* Cancel bonuses */
	for (i = 0; i < MAX_PVALS; i++)
		i_ptr->pval[i] = 0;
	i_ptr->to_a = 0;
	i_ptr->to_h = 0;
	i_ptr->to_d = 0;


	/* Level */
	(*lev) = k_ptr->level;

	/* Make known */
	object_notice_everything(i_ptr);

	/* Value */
	(*val) = object_value(i_ptr, 1, FALSE);

	/* Description (too brief) */
	if (buf)
		object_desc(buf, buf_len, i_ptr, ODESC_BASE | ODESC_SPOIL);

	/* Weight */
	if (wgt)
		strnfmt(wgt, wgt_len, "%3d.%d",
				i_ptr->weight / 10, i_ptr->weight % 10);

	/* Hack */
	if (!dam)
		return;

	/* Misc info */
	dam[0] = '\0';

	/* Damage */
	switch (i_ptr->tval)
	{
		/* Bows */
		case TV_BOW:
		{
			break;
		}

		/* Ammo */
		case TV_SHOT:
		case TV_BOLT:
		case TV_ARROW:
		{
			strnfmt(dam, dam_len, "%dd%d", i_ptr->dd, i_ptr->ds);
			break;
		}

		/* Weapons */
		case TV_HAFTED:
		case TV_POLEARM:
		case TV_SWORD:
		case TV_DIGGING:
		{
			strnfmt(dam, dam_len, "%dd%d", i_ptr->dd, i_ptr->ds);
			break;
		}

		/* Armour */
		case TV_BOOTS:
		case TV_GLOVES:
		case TV_CLOAK:
		case TV_CROWN:
		case TV_HELM:
		case TV_SHIELD:
		case TV_SOFT_ARMOR:
		case TV_HARD_ARMOR:
		case TV_DRAG_ARMOR:
		{
			strnfmt(dam, dam_len, "%d", i_ptr->ac);
			break;
		}
	}
}
Beispiel #11
0
/*
 * Display an item's properties
 */
static void wiz_display_item(const object_type *o_ptr, bool all)
{
	int j = 0;

	bitflag f[OF_SIZE];

	char buf[256];


	/* Extract the flags */
	if (all)
		object_flags(o_ptr, f);
	else
		object_flags_known(o_ptr, f);

	/* Clear screen */
	Term_clear();

	/* Describe fully */
	object_desc(buf, sizeof(buf), o_ptr,
				ODESC_PREFIX | ODESC_FULL | ODESC_SPOIL);

	prt(buf, 2, j);

	prt(format("combat = (%dd%d) (%+d,%+d) [%d,%+d]",
	           o_ptr->dd, o_ptr->ds, o_ptr->to_h, o_ptr->to_d, o_ptr->ac, o_ptr->to_a), 4, j);

	prt(format("kind = %-5d  tval = %-5d  sval = %-5d  wgt = %-3d     timeout = %-d",
	           o_ptr->kind->kidx, o_ptr->tval, o_ptr->sval, o_ptr->weight, o_ptr->timeout), 5, j);

	/* CC: multiple pvals not shown, pending #1290 */
	prt(format("number = %-3d  pval = %-5d  name1 = %-4d  egoidx = %-4d  cost = %ld",
			o_ptr->number, o_ptr->pval[DEFAULT_PVAL],
			o_ptr->artifact ? o_ptr->artifact->aidx : 0,
			o_ptr->ego ? o_ptr->ego->eidx : 0,
			(long)object_value(o_ptr, 1, FALSE)), 6, j);

	prt("+------------FLAGS0------------+", 8, j);
	prt("AFFECT..........SLAY.......BRAND", 9, j);
	prt("                ae      xxxpaefc", 10, j);
	prt("siwdcc  ssidsasmnvudotgddduoclio", 11, j);
	prt("tnieoh  trnipthgiinmrrnrrmniierl", 12, j);
	prt("rtsxna..lcfgdkttmldncltggndsdced", 13, j);
	prt_binary(f, 0, 14, j, '*', 32);
	prt_binary(o_ptr->known_flags, 0, 15, j, '+', 32);

	prt("+------------FLAGS1------------+", 16, j);
	prt("SUST........IMM.RESIST.........", 17, j);
	prt("            afecaefcpfldbc s n  ", 18, j);
	prt("siwdcc      cilocliooeialoshnecd", 19, j);
	prt("tnieoh      irelierliatrnnnrethi", 20, j);
	prt("rtsxna......decddcedsrekdfddxhss", 21, j);
	prt_binary(f, 32, 22, j, '*', 32);
	prt_binary(o_ptr->known_flags, 32, 23, j, '+', 32);

	prt("+------------FLAGS2------------+", 8, j+34);
	prt("s   ts hn    tadiiii   aiehs  hp", 9, j+34);
	prt("lf  eefoo    egrgggg  bcnaih  vr", 10, j+34);
	prt("we  lerlf   ilgannnn  ltssdo  ym", 11, j+34);	prt("da reiedu   merirrrr  eityew ccc", 12, j+34);
	prt("itlepnele   ppanaefc  svaktm uuu", 13, j+34);
	prt("ghigavail   aoveclio  saanyo rrr", 14, j+34);
	prt("seteticf    craxierl  etropd sss", 15, j+34);
	prt("trenhste    tttpdced  detwes eee", 16, j+34);
	prt_binary(f, 64, 17, j + 34, '*', 32);
	prt_binary(o_ptr->known_flags, 64, 18, j + 34, '+', 32);

	prt("o_ptr->ident:", 20, j+34);
	prt(format("sense  %c  worn   %c  empty   %c  known   %c",
		(o_ptr->ident & IDENT_SENSE) ? '+' : ' ',
		(o_ptr->ident & IDENT_WORN) ? '+' : ' ',
		(o_ptr->ident & IDENT_EMPTY) ? '+' : ' ',
		(o_ptr->ident & IDENT_KNOWN) ? '+' : ' '), 21, j+34);
	prt(format("store  %c  attack %c  defence %c  effect  %c",
		(o_ptr->ident & IDENT_STORE) ? '+' : ' ',
		(o_ptr->ident & IDENT_ATTACK) ? '+' : ' ',
		(o_ptr->ident & IDENT_DEFENCE) ? '+' : ' ',
		(o_ptr->ident & IDENT_EFFECT) ? '+' : ' '), 22, j+34);
	prt(format("indest %c  ego    %c",
		(o_ptr->ident & IDENT_INDESTRUCT) ? '+' : ' ',
		(o_ptr->ident & IDENT_NAME) ? '+' : ' '), 23, j+34);
}
/*
 * Display an item's properties
 */
static void wiz_display_item(const object_type *o_ptr)
{
	int j = 0;

	u32b f1, f2, f3;

	char buf[256];


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

	/* Clear screen */
	Term_clear();

	/* Describe fully */
	object_desc_store(buf, o_ptr, TRUE, 3);
	prt(buf, 2, j);

	prt(format("kind = %-5d  level = %-4d  tval = %-5d  sval = %-5d",
	           o_ptr->k_idx, k_info[o_ptr->k_idx].level,
	           o_ptr->tval, o_ptr->sval), 4, j);

	prt(format("number = %-3d  wgt = %-6d  ac = %-5d    damage = %dd%d",
	           o_ptr->number, o_ptr->weight,
	           o_ptr->ac, o_ptr->dd, o_ptr->ds), 5, j);

	prt(format("pval = %-5d  toac = %-5d  tohit = %-4d  todam = %-4d",
	           o_ptr->pval, o_ptr->to_a, o_ptr->to_h, o_ptr->to_d), 6, j);

	prt(format("name1 = %-4d  name2 = %-4d  cost = %ld",
	           o_ptr->name1, o_ptr->name2, (long)object_value(o_ptr)), 7, j);

	prt(format("ident = %04x  timeout = %-d",
	           o_ptr->ident, o_ptr->timeout), 8, j);

	prt("+------------FLAGS1------------+", 10, j);
	prt("AFFECT..........SLAY.......BRAND", 11, j);
	prt("                ae      x  paefc", 12, j);
	prt("siwdcc  ssidsasmnvudotgdd  oclio", 13, j);
	prt("tnieoh  trnipthgiinmrrnrr  iierl", 14, j);
	prt("rtsxna..lcfgdkttmldncltgg..sdced", 15, j);
	prt_binary(f1, 16, j);

	prt("+------------FLAGS2------------+", 17, j);
	prt("SUST........IMM.RESIST.........", 18, j);
	prt("            afecaefcpfldbc s n  ", 19, j);
	prt("siwdcc      cilocliooeialoshnecd", 20, j);
	prt("tnieoh      irelierliatrnnnrethi", 21, j);
	prt("rtsxna......decddcedsrekdfddxhss", 22, j);
	prt_binary(f2, 23, j);

	prt("+------------FLAGS3------------+", 10, j+32);
	prt("s   ts h     tadiiii   aiehs  hp", 11, j+32);
	prt("lf  eefo     egrgggg  bcnaih  vr", 12, j+32);
	prt("we  lerl    ilgannnn  ltssdo  ym", 13, j+32);
	prt("da reied    merirrrr  eityew ccc", 14, j+32);
	prt("itlepnel    ppanaefc  svaktm uuu", 15, j+32);
	prt("ghigavai    aoveclio  saanyo rrr", 16, j+32);
	prt("seteticf    craxierl  etropd sss", 17, j+32);
	prt("trenhste    tttpdced  detwes eee", 18, j+32);
	prt_binary(f3, 19, j+32);
}
Beispiel #13
0
/*
 * Describe the kind
 */
static void kind_info(char *buf, char *dam, char *wgt, int *lev, s32b *val,
	int k)
{
	object_type forge;
	object_type *q_ptr;

	object_kind *k_ptr;


	/* Get local object */
	q_ptr = &forge;

	/* Prepare a fake item */
	object_prep(q_ptr, k);

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

	/* It is known */
	q_ptr->ident |= (IDENT_KNOWN);

	/* Cancel bonuses */
	q_ptr->pval = 0;
	q_ptr->to_a = 0;
	q_ptr->to_h = 0;
	q_ptr->to_d = 0;


	/* Level (is this appropriate?) */
	(*lev) = object_k_level(k_ptr);

	/* Value */
	(*val) = object_value(q_ptr, FALSE);


	/* Hack */
	if (!buf || !dam || !wgt) return;


	/* Description (too brief) */
	strnfmt(buf, ONAME_MAX, "%v", object_desc_f3, q_ptr, OD_SHOP, 0);


	/* Misc info */
	strcpy(dam, "");

	/* Damage */
	switch (q_ptr->tval)
	{
		/* Bows */
		case TV_BOW:
		{
			break;
		}

		/* Ammo */
		case TV_SHOT:
		case TV_BOLT:
		case TV_ARROW:
		{
			sprintf(dam, "%dd%d", q_ptr->dd, q_ptr->ds);
			break;
		}

		/* Weapons */
		case TV_HAFTED:
		case TV_POLEARM:
		case TV_SWORD:
		case TV_DIGGING:
		{
			sprintf(dam, "%dd%d", q_ptr->dd, q_ptr->ds);
			break;
		}

		/* Armour */
		case TV_BOOTS:
		case TV_GLOVES:
		case TV_CLOAK:
		case TV_CROWN:
		case TV_HELM:
		case TV_SHIELD:
		case TV_SOFT_ARMOR:
		case TV_HARD_ARMOR:
		case TV_DRAG_ARMOR:
		{
			sprintf(dam, "%d", q_ptr->ac);
			break;
		}
	}


	/* Weight */
	sprintf(wgt, "%3d.%d", q_ptr->weight / 10, q_ptr->weight % 10);
}
Beispiel #14
0
/*
 * Destroy an item
 */
void do_cmd_destroy(void)
{
	int			item, amt = 1;
	int			old_number;

	bool		force = FALSE;

	object_type		*o_ptr;

	char		o_name[MAX_NLEN];

	char		out_val[160];

	cptr q, s;

	/* Hack -- force destruction */
	if (command_arg > 0) force = TRUE;


	/* Get an item */
#ifdef JP
	q = "どのアイテムを壊しますか? ";
	s = "壊せるアイテムを持っていない。";
#else
	q = "Destroy which item? ";
	s = "You have nothing to destroy.";
#endif

	if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;

	/* Get the item (in the pack) */
	if (item >= 0)
	{
		o_ptr = &inventory[item];
	}

	/* Get the item (on the floor) */
	else
	{
		o_ptr = &o_list[0 - item];
	}


	/* Verify unless quantity given */
	if (!force && (!(auto_destroy && (object_value(o_ptr) < 1))))
	{
		object_desc(o_name, o_ptr, OD_OMIT_PREFIX);

		/* Make a verification */
		sprintf(out_val, 
#ifdef JP
			"本当に%sを壊しますか? [y/n/Auto]",
#else
			"Really destroy %s? [y/n/Auto]",
#endif
			o_name);

		msg_print(NULL);

		/* HACK : Add the line to message buffer */
		message_add(out_val);
		p_ptr->window |= (PW_MESSAGE);
		window_stuff();

		/* Get an acceptable answer */
		while (TRUE)
		{
			char i;

			/* Prompt */
			prt(out_val, 0, 0);

			i = inkey();

			/* Erase the prompt */
			prt("", 0, 0);

			if (i == 'y' || i == 'Y')
			{
				break;
			}
			if (i == ESCAPE || i == 'n' || i == 'N')
			{
				/* Cancel */
				return;
			}
			if (i == 'A')
			{
				/* Add an auto-destroy preference line */
				if (autopick_autoregister(o_ptr))
				{
					/* Auto-destroy it */
					autopick_alter_item(item, TRUE);
				}

				/* The object is already destroyed. */
				return;
			}
		} /* while (TRUE) */
	}

	/* See how many items */
	if (o_ptr->number > 1)
	{
		/* Get a quantity */
		amt = get_quantity(NULL, o_ptr->number);

		/* Allow user abort */
		if (amt <= 0) return;
	}

	/* Describe the object */
	old_number = o_ptr->number;
	o_ptr->number = amt;
	object_desc(o_name, o_ptr, 0);
	o_ptr->number = old_number;

	/* Take a turn */
	energy_use = 100;

	/* Can the player destroy the object? */
	if (!can_player_destroy_object(o_ptr))
	{
		/* Don't take a turn */
		energy_use = 0;

		/* Message */
#ifdef JP
		msg_format("%sは破壊不可能だ。", o_name);
#else
		msg_format("You cannot destroy %s.", o_name);
#endif

		/* Done */
		return;
	}

	/* Message */
#ifdef JP
	msg_format("%sを壊した。", o_name);
#else
	msg_format("You destroy %s.", o_name);
#endif

	sound(SOUND_DESTROY);

	if (high_level_book(o_ptr))
	{
		bool gain_expr = FALSE;

		if (p_ptr->pclass == CLASS_WARRIOR)
		{
			gain_expr = TRUE;
		}
		else if (p_ptr->pclass == CLASS_PALADIN)
		{
			if (p_ptr->realm1 == REALM_LIFE)
			{
				if (o_ptr->tval != TV_LIFE_BOOK) gain_expr = TRUE;
			}
			else
			{
				if (o_ptr->tval == TV_LIFE_BOOK) gain_expr = TRUE;
			}
		}

		if (gain_expr && (p_ptr->exp < PY_MAX_EXP))
		{
			s32b tester_exp = p_ptr->max_exp / 20;
			if (tester_exp > 10000) tester_exp = 10000;
			if (o_ptr->sval < 3) tester_exp /= 4;
			if (tester_exp < 1) tester_exp = 1;

#ifdef JP
msg_print("更に経験を積んだような気がする。");
#else
			msg_print("You feel more experienced.");
#endif

			gain_exp(tester_exp * amt);
		}
	}

	/* Reduce the charges of rods/wands */
	reduce_charges(o_ptr, amt);

	/* Eliminate the item (from the pack) */
	if (item >= 0)
	{
		inven_item_increase(item, -amt);
		inven_item_describe(item);
		inven_item_optimize(item);
	}

	/* Eliminate the item (from the floor) */
	else
	{
		floor_item_increase(0 - item, -amt);
		floor_item_describe(0 - item);
		floor_item_optimize(0 - item);
	}
}