Make the inventory-initialisation arrays constants

This is helpful for if we ever allow playing multiple games in the
same session: because the arrays are not modified, they can now be
used more than once.
This commit is contained in:
Alex Smith
2025-11-30 02:59:23 +00:00
parent 94e5f7b861
commit d41cea8286

View File

@@ -9,17 +9,19 @@ struct trobj {
short trotyp;
schar trspe;
char trclass;
Bitfield(trquan, 6);
Bitfield(trbless, 2);
char trquan_min;
char trquan_max;
char trbless;
};
staticfn long trquan(const struct trobj *);
staticfn struct obj *ini_inv_mkobj_filter(int, boolean);
staticfn short ini_inv_obj_substitution(struct trobj *,
struct obj *) NONNULLPTRS;
staticfn void ini_inv_adjust_obj(struct trobj *,
struct obj *) NONNULLPTRS;
staticfn short ini_inv_obj_substitution(const struct trobj *,
struct obj *) NONNULLPTRS;
staticfn boolean ini_inv_adjust_obj(const struct trobj *,
struct obj *) NONNULLPTRS;
staticfn void ini_inv_use_obj(struct obj *) NONNULLARG1;
staticfn void ini_inv(struct trobj *) NONNULLARG1;
staticfn void ini_inv(const struct trobj *) NONNULLARG1;
staticfn void knows_object(int, boolean);
staticfn void knows_class(char);
staticfn void u_init_role(void);
@@ -36,177 +38,188 @@ staticfn boolean restricted_spell_discipline(int);
* Initial inventory for the various roles.
*/
static struct trobj Archeologist[] = {
static const struct trobj Archeologist[] = {
/* if adventure has a name... idea from tan@uvm-gen */
{ BULLWHIP, 2, WEAPON_CLASS, 1, UNDEF_BLESS },
{ LEATHER_JACKET, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ FEDORA, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ FOOD_RATION, 0, FOOD_CLASS, 3, 0 },
{ PICK_AXE, UNDEF_SPE, TOOL_CLASS, 1, UNDEF_BLESS },
{ TINNING_KIT, UNDEF_SPE, TOOL_CLASS, 1, UNDEF_BLESS },
{ TOUCHSTONE, 0, GEM_CLASS, 1, 0 },
{ SACK, 0, TOOL_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 }
{ BULLWHIP, 2, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ LEATHER_JACKET, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ FEDORA, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ FOOD_RATION, 0, FOOD_CLASS, 3, 3, 0 },
{ PICK_AXE, UNDEF_SPE, TOOL_CLASS, 1, 1, UNDEF_BLESS },
{ TINNING_KIT, UNDEF_SPE, TOOL_CLASS, 1, 1, UNDEF_BLESS },
{ TOUCHSTONE, 0, GEM_CLASS, 1, 1, 0 },
{ SACK, 0, TOOL_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Barbarian[] = {
#define B_MAJOR 0 /* two-handed sword or battle-axe */
#define B_MINOR 1 /* matched with axe or short sword */
{ TWO_HANDED_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS },
{ AXE, 0, WEAPON_CLASS, 1, UNDEF_BLESS },
{ RING_MAIL, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ FOOD_RATION, 0, FOOD_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 }
static const struct trobj Barbarian_0[] = {
{ TWO_HANDED_SWORD, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ AXE, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ RING_MAIL, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ FOOD_RATION, 0, FOOD_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Cave_man[] = {
#define C_AMMO 2
{ CLUB, 1, WEAPON_CLASS, 1, UNDEF_BLESS },
{ SLING, 2, WEAPON_CLASS, 1, UNDEF_BLESS },
{ FLINT, 0, GEM_CLASS, 15, UNDEF_BLESS }, /* quan is variable */
{ ROCK, 0, GEM_CLASS, 3, 0 }, /* yields 18..33 */
{ LEATHER_ARMOR, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ 0, 0, 0, 0, 0 }
static const struct trobj Barbarian_1[] = {
{ BATTLE_AXE, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ SHORT_SWORD, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ RING_MAIL, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ FOOD_RATION, 0, FOOD_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Healer[] = {
{ SCALPEL, 0, WEAPON_CLASS, 1, UNDEF_BLESS },
{ LEATHER_GLOVES, 1, ARMOR_CLASS, 1, UNDEF_BLESS },
{ STETHOSCOPE, 0, TOOL_CLASS, 1, 0 },
{ POT_HEALING, 0, POTION_CLASS, 4, UNDEF_BLESS },
{ POT_EXTRA_HEALING, 0, POTION_CLASS, 4, UNDEF_BLESS },
{ WAN_SLEEP, UNDEF_SPE, WAND_CLASS, 1, UNDEF_BLESS },
static const struct trobj Cave_man[] = {
{ CLUB, 1, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ SLING, 2, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ FLINT, 0, GEM_CLASS, 10, 20, UNDEF_BLESS },
{ ROCK, 0, GEM_CLASS, 3, 3, 0 }, /* yields 18..33 */
{ LEATHER_ARMOR, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ 0, 0, 0, 0, 0, 0 }
};
static const struct trobj Healer[] = {
{ SCALPEL, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ LEATHER_GLOVES, 1, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ STETHOSCOPE, 0, TOOL_CLASS, 1, 1, 0 },
{ POT_HEALING, 0, POTION_CLASS, 4, 4, UNDEF_BLESS },
{ POT_EXTRA_HEALING, 0, POTION_CLASS, 4, 4, UNDEF_BLESS },
{ WAN_SLEEP, UNDEF_SPE, WAND_CLASS, 1, 1, UNDEF_BLESS },
/* always blessed, so it's guaranteed readable */
{ SPE_HEALING, 0, SPBOOK_CLASS, 1, 1 },
{ SPE_EXTRA_HEALING, 0, SPBOOK_CLASS, 1, 1 },
{ SPE_STONE_TO_FLESH, 0, SPBOOK_CLASS, 1, 1 },
{ APPLE, 0, FOOD_CLASS, 5, 0 },
{ 0, 0, 0, 0, 0 }
{ SPE_HEALING, 0, SPBOOK_CLASS, 1, 1, 1 },
{ SPE_EXTRA_HEALING, 0, SPBOOK_CLASS, 1, 1, 1 },
{ SPE_STONE_TO_FLESH, 0, SPBOOK_CLASS, 1, 1, 1 },
{ APPLE, 0, FOOD_CLASS, 5, 5, 0 },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Knight[] = {
{ LONG_SWORD, 1, WEAPON_CLASS, 1, UNDEF_BLESS },
{ LANCE, 1, WEAPON_CLASS, 1, UNDEF_BLESS },
{ RING_MAIL, 1, ARMOR_CLASS, 1, UNDEF_BLESS },
{ HELMET, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ SMALL_SHIELD, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ LEATHER_GLOVES, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ APPLE, 0, FOOD_CLASS, 10, 0 },
{ CARROT, 0, FOOD_CLASS, 10, 0 },
{ 0, 0, 0, 0, 0 }
static const struct trobj Knight[] = {
{ LONG_SWORD, 1, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ LANCE, 1, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ RING_MAIL, 1, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ HELMET, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ SMALL_SHIELD, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ LEATHER_GLOVES, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ APPLE, 0, FOOD_CLASS, 10, 10, 0 },
{ CARROT, 0, FOOD_CLASS, 10, 10, 0 },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Monk[] = {
#define M_BOOK 2
{ LEATHER_GLOVES, 2, ARMOR_CLASS, 1, UNDEF_BLESS },
{ ROBE, 1, ARMOR_CLASS, 1, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 1, 1 },
{ UNDEF_TYP, UNDEF_SPE, SCROLL_CLASS, 1, UNDEF_BLESS },
{ POT_HEALING, 0, POTION_CLASS, 3, UNDEF_BLESS },
{ FOOD_RATION, 0, FOOD_CLASS, 3, 0 },
{ APPLE, 0, FOOD_CLASS, 5, UNDEF_BLESS },
{ ORANGE, 0, FOOD_CLASS, 5, UNDEF_BLESS },
static const struct trobj Monk[] = {
{ LEATHER_GLOVES, 2, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ ROBE, 1, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, SCROLL_CLASS, 1, 1, UNDEF_BLESS },
{ POT_HEALING, 0, POTION_CLASS, 3, 3, UNDEF_BLESS },
{ FOOD_RATION, 0, FOOD_CLASS, 3, 3, 0 },
{ APPLE, 0, FOOD_CLASS, 5, 5, UNDEF_BLESS },
{ ORANGE, 0, FOOD_CLASS, 5, 5, UNDEF_BLESS },
/* Yes, we know fortune cookies aren't really from China. They were
* invented by George Jung in Los Angeles, California, USA in 1916.
*/
{ FORTUNE_COOKIE, 0, FOOD_CLASS, 3, UNDEF_BLESS },
{ 0, 0, 0, 0, 0 }
invented by George Jung in Los Angeles, California, USA in 1916. */
{ FORTUNE_COOKIE, 0, FOOD_CLASS, 3, 3, UNDEF_BLESS },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Priest[] = {
{ MACE, 1, WEAPON_CLASS, 1, 1 },
{ ROBE, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ SMALL_SHIELD, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ POT_WATER, 0, POTION_CLASS, 4, 1 }, /* holy water */
{ CLOVE_OF_GARLIC, 0, FOOD_CLASS, 1, 0 },
{ SPRIG_OF_WOLFSBANE, 0, FOOD_CLASS, 1, 0 },
{ UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 2, UNDEF_BLESS },
{ 0, 0, 0, 0, 0 }
static const struct trobj Priest[] = {
{ MACE, 1, WEAPON_CLASS, 1, 1, 1 },
{ ROBE, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ SMALL_SHIELD, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ POT_WATER, 0, POTION_CLASS, 4, 4, 1 }, /* holy water */
{ CLOVE_OF_GARLIC, 0, FOOD_CLASS, 1, 1, 0 },
{ SPRIG_OF_WOLFSBANE, 0, FOOD_CLASS, 1, 1, 0 },
{ UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 2, 2, UNDEF_BLESS },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Ranger[] = {
#define RAN_BOW 1
#define RAN_TWO_ARROWS 2
#define RAN_ZERO_ARROWS 3
{ DAGGER, 1, WEAPON_CLASS, 1, UNDEF_BLESS },
{ BOW, 1, WEAPON_CLASS, 1, UNDEF_BLESS },
{ ARROW, 2, WEAPON_CLASS, 50, UNDEF_BLESS },
{ ARROW, 0, WEAPON_CLASS, 30, UNDEF_BLESS },
{ CLOAK_OF_DISPLACEMENT, 2, ARMOR_CLASS, 1, UNDEF_BLESS },
{ CRAM_RATION, 0, FOOD_CLASS, 4, 0 },
{ 0, 0, 0, 0, 0 }
static const struct trobj Ranger[] = {
{ DAGGER, 1, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ BOW, 1, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ ARROW, 2, WEAPON_CLASS, 50, 59, UNDEF_BLESS },
{ ARROW, 0, WEAPON_CLASS, 30, 39, UNDEF_BLESS },
{ CLOAK_OF_DISPLACEMENT, 2, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ CRAM_RATION, 0, FOOD_CLASS, 4, 4, 0 },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Rogue[] = {
#define R_DAGGERS 1
{ SHORT_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS },
{ DAGGER, 0, WEAPON_CLASS, 10, 0 }, /* quan is variable */
{ LEATHER_ARMOR, 1, ARMOR_CLASS, 1, UNDEF_BLESS },
{ POT_SICKNESS, 0, POTION_CLASS, 1, 0 },
{ LOCK_PICK, 0, TOOL_CLASS, 1, 0 },
{ SACK, 0, TOOL_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 }
static const struct trobj Rogue[] = {
{ SHORT_SWORD, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ DAGGER, 0, WEAPON_CLASS, 6, 15, 0 },
{ LEATHER_ARMOR, 1, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ POT_SICKNESS, 0, POTION_CLASS, 1, 1, 0 },
{ LOCK_PICK, 0, TOOL_CLASS, 1, 1, 0 },
{ SACK, 0, TOOL_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Samurai[] = {
#define S_ARROWS 3
{ KATANA, 0, WEAPON_CLASS, 1, UNDEF_BLESS },
{ SHORT_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, /* wakizashi */
{ YUMI, 0, WEAPON_CLASS, 1, UNDEF_BLESS },
{ YA, 0, WEAPON_CLASS, 25, UNDEF_BLESS }, /* variable quan */
{ SPLINT_MAIL, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ 0, 0, 0, 0, 0 }
static const struct trobj Samurai[] = {
{ KATANA, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ SHORT_SWORD, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, /* wakizashi */
{ YUMI, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ YA, 0, WEAPON_CLASS, 26, 45, UNDEF_BLESS },
{ SPLINT_MAIL, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Tourist[] = {
#define T_DARTS 0
{ DART, 2, WEAPON_CLASS, 25, UNDEF_BLESS }, /* quan is variable */
{ UNDEF_TYP, UNDEF_SPE, FOOD_CLASS, 10, 0 },
{ POT_EXTRA_HEALING, 0, POTION_CLASS, 2, UNDEF_BLESS },
{ SCR_MAGIC_MAPPING, 0, SCROLL_CLASS, 4, UNDEF_BLESS },
{ HAWAIIAN_SHIRT, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ EXPENSIVE_CAMERA, UNDEF_SPE, TOOL_CLASS, 1, 0 },
{ CREDIT_CARD, 0, TOOL_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 }
static const struct trobj Tourist[] = {
{ DART, 2, WEAPON_CLASS, 21, 40, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, FOOD_CLASS, 10, 10, 0 },
{ POT_EXTRA_HEALING, 0, POTION_CLASS, 2, 2, UNDEF_BLESS },
{ SCR_MAGIC_MAPPING, 0, SCROLL_CLASS, 4, 4, UNDEF_BLESS },
{ HAWAIIAN_SHIRT, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ EXPENSIVE_CAMERA, UNDEF_SPE, TOOL_CLASS, 1, 1, 0 },
{ CREDIT_CARD, 0, TOOL_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Valkyrie[] = {
{ SPEAR, 1, WEAPON_CLASS, 1, UNDEF_BLESS },
{ DAGGER, 0, WEAPON_CLASS, 1, UNDEF_BLESS },
{ SMALL_SHIELD, 3, ARMOR_CLASS, 1, UNDEF_BLESS },
{ FOOD_RATION, 0, FOOD_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 }
static const struct trobj Valkyrie[] = {
{ SPEAR, 1, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ DAGGER, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS },
{ SMALL_SHIELD, 3, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ FOOD_RATION, 0, FOOD_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 }
};
static struct trobj Wizard[] = {
{ QUARTERSTAFF, 1, WEAPON_CLASS, 1, 1 },
{ CLOAK_OF_MAGIC_RESISTANCE, 0, ARMOR_CLASS, 1, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, WAND_CLASS, 1, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, RING_CLASS, 2, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, POTION_CLASS, 3, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, SCROLL_CLASS, 3, UNDEF_BLESS },
{ SPE_FORCE_BOLT, 0, SPBOOK_CLASS, 1, 1 },
{ UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 1, UNDEF_BLESS },
{ MAGIC_MARKER, 19, TOOL_CLASS, 1, 0 }, /* actually spe = 18 + d4 */
{ 0, 0, 0, 0, 0 }
static const struct trobj Wizard[] = {
{ QUARTERSTAFF, 1, WEAPON_CLASS, 1, 1, 1 },
{ CLOAK_OF_MAGIC_RESISTANCE, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, WAND_CLASS, 1, 1, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, RING_CLASS, 2, 2, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, POTION_CLASS, 3, 3, UNDEF_BLESS },
{ UNDEF_TYP, UNDEF_SPE, SCROLL_CLASS, 3, 3, UNDEF_BLESS },
{ SPE_FORCE_BOLT, 0, SPBOOK_CLASS, 1, 1, 1 },
{ UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 1, 1, UNDEF_BLESS },
{ MAGIC_MARKER, 19, TOOL_CLASS, 1, 1, 0 }, /* actually spe = 18 + d4 */
{ 0, 0, 0, 0, 0, 0 }
};
/*
* Optional extra inventory items.
*/
static struct trobj Tinopener[] = { { TIN_OPENER, 0, TOOL_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 } };
static struct trobj Magicmarker[] = { { MAGIC_MARKER, 19, TOOL_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 } };
static struct trobj Lamp[] = { { OIL_LAMP, 1, TOOL_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 } };
static struct trobj Blindfold[] = { { BLINDFOLD, 0, TOOL_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 } };
static struct trobj Instrument[] = { { WOODEN_FLUTE, 0, TOOL_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 } };
static struct trobj Xtra_food[] = { { UNDEF_TYP, UNDEF_SPE, FOOD_CLASS, 2, 0},
{ 0, 0, 0, 0, 0 } };
static struct trobj Leash[] = { { LEASH, 0, TOOL_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 } };
static struct trobj Towel[] = { { TOWEL, 0, TOOL_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 } };
static struct trobj Wishing[] = { { WAN_WISHING, 3, WAND_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 } };
static struct trobj Money[] = { { GOLD_PIECE, 0, COIN_CLASS, 1, 0 },
{ 0, 0, 0, 0, 0 } };
static const struct trobj Healing_book[] =
{ { SPE_HEALING, UNDEF_SPE, SPBOOK_CLASS, 1, 1, 1 },
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Protection_book[] =
{ { SPE_PROTECTION, UNDEF_SPE, SPBOOK_CLASS, 1, 1, 1 },
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Confuse_monster_book[] =
{ { SPE_CONFUSE_MONSTER, UNDEF_SPE, SPBOOK_CLASS, 1, 1, 1 },
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Tinopener[] =
{ { TIN_OPENER, 0, TOOL_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Magicmarker[] =
{ { MAGIC_MARKER, 19, TOOL_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Lamp[] =
{ { OIL_LAMP, 1, TOOL_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Blindfold[] =
{ { BLINDFOLD, 0, TOOL_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Xtra_food[] =
{ { UNDEF_TYP, UNDEF_SPE, FOOD_CLASS, 2, 2, 0},
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Leash[] =
{ { LEASH, 0, TOOL_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Towel[] =
{ { TOWEL, 0, TOOL_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Wishing[] =
{ { WAN_WISHING, 3, WAND_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 } };
static const struct trobj Money[] =
{ { GOLD_PIECE, 0, COIN_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 } };
/* race-based substitutions for initial inventory;
the weaker cloak for elven rangers is intentional--they shoot better */
static struct inv_sub {
static const struct inv_sub {
short race_pm, item_otyp, subs_otyp;
} inv_subs[] = {
{ PM_ELF, DAGGER, ELVEN_DAGGER },
@@ -645,10 +658,10 @@ u_init_role(void)
break;
case PM_BARBARIAN:
if (rn2(100) >= 50) { /* see above comment */
Barbarian[B_MAJOR].trotyp = BATTLE_AXE;
Barbarian[B_MINOR].trotyp = SHORT_SWORD;
ini_inv(Barbarian_0);
} else {
ini_inv(Barbarian_1);
}
ini_inv(Barbarian);
if (!rn2(6))
ini_inv(Lamp);
knows_class(WEAPON_CLASS); /* excluding polearms */
@@ -656,7 +669,6 @@ u_init_role(void)
skill_init(Skill_B);
break;
case PM_CAVE_DWELLER:
Cave_man[C_AMMO].trquan = rn1(11, 10); /* 10..20 */
ini_inv(Cave_man);
skill_init(Skill_C);
break;
@@ -677,12 +689,12 @@ u_init_role(void)
skill_init(Skill_K);
break;
case PM_MONK: {
static short M_spell[] = {
SPE_HEALING, SPE_PROTECTION, SPE_CONFUSE_MONSTER
static const struct trobj *M_spell[] = {
Healing_book, Protection_book, Confuse_monster_book
};
Monk[M_BOOK].trotyp = M_spell[rn2(90) / 30]; /* [0..2] */
ini_inv(Monk);
ini_inv(M_spell[rn2(90) / 30]); /* [0..2] */
if (!rn2(4))
ini_inv(Magicmarker);
else if (!rn2(10))
@@ -710,14 +722,11 @@ u_init_role(void)
*/
break;
case PM_RANGER:
Ranger[RAN_TWO_ARROWS].trquan = rn1(10, 50);
Ranger[RAN_ZERO_ARROWS].trquan = rn1(10, 30);
ini_inv(Ranger);
knows_class(WEAPON_CLASS); /* bows, arrows, spears only */
skill_init(Skill_Ran);
break;
case PM_ROGUE:
Rogue[R_DAGGERS].trquan = rn1(10, 6);
u.umoney0 = 0;
ini_inv(Rogue);
if (!rn2(5))
@@ -729,7 +738,6 @@ u_init_role(void)
skill_init(Skill_R);
break;
case PM_SAMURAI:
Samurai[S_ARROWS].trquan = rn1(20, 26);
ini_inv(Samurai);
if (!rn2(5))
ini_inv(Blindfold);
@@ -748,7 +756,6 @@ u_init_role(void)
skill_init(Skill_S);
break;
case PM_TOURIST:
Tourist[T_DARTS].trquan = rn1(20, 21);
u.umoney0 = rnd(1000);
ini_inv(Tourist);
if (!rn2(25))
@@ -797,9 +804,12 @@ u_init_race(void)
* get only non-magic instruments.
*/
if (Role_if(PM_CLERIC) || Role_if(PM_WIZARD)) {
static int trotyp[] = { WOODEN_FLUTE, TOOLED_HORN, WOODEN_HARP,
BELL, BUGLE, LEATHER_DRUM };
Instrument[0].trotyp = ROLL_FROM(trotyp);
static const int trotyp[] =
{ WOODEN_FLUTE, TOOLED_HORN, WOODEN_HARP,
BELL, BUGLE, LEATHER_DRUM };
const struct trobj Instrument[] =
{ { ROLL_FROM(trotyp), 0, TOOL_CLASS, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0 } };
ini_inv(Instrument);
}
@@ -1109,6 +1119,15 @@ restricted_spell_discipline(int otyp)
return TRUE;
}
/* randomizes the quantity given a trobj description */
staticfn long
trquan(const struct trobj *trop)
{
if (!trop->trquan_min)
return 1;
return trop->trquan_min + rn2(trop->trquan_max - trop->trquan_min + 1);
}
/* create random object of certain class, filtering out too powerful items */
staticfn struct obj *
ini_inv_mkobj_filter(int oclass, boolean got_level1_spellbook)
@@ -1175,7 +1194,7 @@ ini_inv_mkobj_filter(int oclass, boolean got_level1_spellbook)
/* substitute object with something else based on race.
only changes otyp, and returns it. */
staticfn short
ini_inv_obj_substitution(struct trobj *trop, struct obj *obj)
ini_inv_obj_substitution(const struct trobj *trop, struct obj *obj)
{
if (gu.urace.mnum != PM_HUMAN) {
int i;
@@ -1198,9 +1217,12 @@ ini_inv_obj_substitution(struct trobj *trop, struct obj *obj)
return obj->otyp;
}
staticfn void
ini_inv_adjust_obj(struct trobj *trop, struct obj *obj)
/* returns: TRUE to stop generating items from this trobj,
FALSE for normal behaviour */
staticfn boolean
ini_inv_adjust_obj(const struct trobj *trop, struct obj *obj)
{
boolean stop = FALSE;
if (trop->trclass == COIN_CLASS) {
/* no "blessed" or "identified" money */
obj->quan = u.umoney0;
@@ -1217,8 +1239,8 @@ ini_inv_adjust_obj(struct trobj *trop, struct obj *obj)
if (obj->opoisoned && u.ualign.type != A_CHAOTIC)
obj->opoisoned = 0;
if (obj->oclass == WEAPON_CLASS || obj->oclass == TOOL_CLASS) {
obj->quan = (long) trop->trquan;
trop->trquan = 1;
obj->quan = trquan(trop);
stop = TRUE;
} else if (obj->oclass == GEM_CLASS && is_graystone(obj)
&& obj->otyp != FLINT) {
obj->quan = 1L;
@@ -1239,6 +1261,7 @@ ini_inv_adjust_obj(struct trobj *trop, struct obj *obj)
}
/* defined after setting otyp+quan + blessedness */
obj->owt = weight(obj);
return stop;
}
/* initial inventory: wear, wield, learn the spell/obj */
@@ -1290,15 +1313,17 @@ ini_inv_use_obj(struct obj *obj)
}
staticfn void
ini_inv(struct trobj *trop)
ini_inv(const struct trobj *trop)
{
struct obj *obj;
int otyp;
boolean got_sp1 = FALSE; /* got a level 1 spellbook? */
long quan;
if (u.uroleplay.pauper) /* pauper gets no items */
return;
quan = trquan(trop);
while (trop->trclass) {
otyp = (int) trop->trotyp;
if (otyp != UNDEF_TYP) {
@@ -1340,7 +1365,8 @@ ini_inv(struct trobj *trop)
continue;
}
ini_inv_adjust_obj(trop, obj);
if (ini_inv_adjust_obj(trop, obj))
quan = 1;
obj = addinv(obj);
ini_inv_use_obj(obj);
@@ -1349,24 +1375,15 @@ ini_inv(struct trobj *trop)
if (obj->oclass == SPBOOK_CLASS && objects[obj->otyp].oc_level == 1)
got_sp1 = TRUE;
if (--trop->trquan)
if (--quan)
continue; /* make a similar object */
trop++;
quan = trquan(trop);
}
}
#undef UNDEF_TYP
#undef UNDEF_SPE
#undef UNDEF_BLESS
#undef B_MAJOR
#undef B_MINOR
#undef C_AMMO
#undef M_BOOK
#undef RAN_BOW
#undef RAN_TWO_ARROWS
#undef RAN_ZERO_ARROWS
#undef R_DAGGERS
#undef S_ARROWS
#undef T_DARTS
/*u_init.c*/