Macro for picking random entry from array

This commit is contained in:
Pasi Kallinen
2023-12-05 10:06:27 +02:00
parent b98a70e3ec
commit 5dc94f3d83
24 changed files with 45 additions and 42 deletions
+3
View File
@@ -1404,6 +1404,9 @@ typedef uint32_t mmflags_nht; /* makemon MM_ flags */
/* monster shooting a wand; note: not -9 to -0 because -0 is ambiguous */ /* monster shooting a wand; note: not -9 to -0 because -0 is ambiguous */
#define BZ_M_WAND(bztyp) (-30 - (bztyp)) /* -39..-30 */ #define BZ_M_WAND(bztyp) (-30 - (bztyp)) /* -39..-30 */
/* pick a random entry from array */
#define ROLL_FROM(array) array[rn2(SIZE(array))]
#define FEATURE_NOTICE_VER(major, minor, patch) \ #define FEATURE_NOTICE_VER(major, minor, patch) \
(((unsigned long) major << 24) | ((unsigned long) minor << 16) \ (((unsigned long) major << 24) | ((unsigned long) minor << 16) \
| ((unsigned long) patch << 8) | ((unsigned long) 0)) | ((unsigned long) patch << 8) | ((unsigned long) 0))
+2 -2
View File
@@ -1505,7 +1505,7 @@ artifact_hit(
return TRUE; return TRUE;
} }
*dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER;
pline(behead_msg[rn2(SIZE(behead_msg))], wepdesc, pline(ROLL_FROM(behead_msg), wepdesc,
mon_nam(mdef)); mon_nam(mdef));
if (Hallucination && !flags.female) if (Hallucination && !flags.female)
pline("Good job Henry, but that wasn't Anne."); pline("Good job Henry, but that wasn't Anne.");
@@ -1525,7 +1525,7 @@ artifact_hit(
return TRUE; return TRUE;
} }
*dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER; *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER;
pline(behead_msg[rn2(SIZE(behead_msg))], wepdesc, "you"); pline(ROLL_FROM(behead_msg), wepdesc, "you");
otmp->dknown = TRUE; otmp->dknown = TRUE;
/* Should amulets fall off? */ /* Should amulets fall off? */
return TRUE; return TRUE;
+2 -2
View File
@@ -1899,7 +1899,7 @@ static const char *const ghostnames[] = {
const char * const char *
rndghostname(void) rndghostname(void)
{ {
return rn2(7) ? ghostnames[rn2(SIZE(ghostnames))] return rn2(7) ? ROLL_FROM(ghostnames)
: (const char *) gp.plname; : (const char *) gp.plname;
} }
@@ -2635,7 +2635,7 @@ rndorcname(char *s)
for (i = 0; i < iend; ++i) { for (i = 0; i < iend; ++i) {
vstart = 1 - vstart; /* 0 -> 1, 1 -> 0 */ vstart = 1 - vstart; /* 0 -> 1, 1 -> 0 */
Sprintf(eos(s), "%s%s", (i > 0 && !rn2(30)) ? "-" : "", Sprintf(eos(s), "%s%s", (i > 0 && !rn2(30)) ? "-" : "",
vstart ? v[rn2(SIZE(v))] : snd[rn2(SIZE(snd))]); vstart ? ROLL_FROM(v) : ROLL_FROM(snd));
} }
} }
return s; return s;
+1 -1
View File
@@ -689,7 +689,7 @@ really_kick_object(coordxy x, coordxy y)
if (!Deaf) if (!Deaf)
pline1("Thwwpingg!"); pline1("Thwwpingg!");
You("%s!", flyingcoinmsg[rn2(SIZE(flyingcoinmsg))]); You("%s!", ROLL_FROM(flyingcoinmsg));
(void) scatter(x, y, rnd(3), VIS_EFFECTS | MAY_HIT, (void) scatter(x, y, rnd(3), VIS_EFFECTS | MAY_HIT,
gk.kickedobj); gk.kickedobj);
newsym(x, y); newsym(x, y);
+1 -1
View File
@@ -1549,7 +1549,7 @@ static const char blind_writing[][21] = {
static const char * static const char *
blengr(void) blengr(void)
{ {
return blind_writing[rn2(SIZE(blind_writing))]; return ROLL_FROM(blind_writing);
} }
/*engrave.c*/ /*engrave.c*/
+1 -1
View File
@@ -1501,7 +1501,7 @@ currency(long amount)
{ {
const char *res; const char *res;
res = Hallucination ? currencies[rn2(SIZE(currencies))] : "zorkmid"; res = Hallucination ? ROLL_FROM(currencies) : "zorkmid";
if (amount != 1L) if (amount != 1L)
res = makeplural(res); res = makeplural(res);
return res; return res;
+2 -2
View File
@@ -2317,7 +2317,7 @@ set_mimic_sym(register struct monst *mtmp)
goto assign_sym; goto assign_sym;
} }
} else { } else {
s_sym = syms[rn2(SIZE(syms))]; s_sym = ROLL_FROM(syms);
assign_sym: assign_sym:
if (s_sym == MAXOCLASSES) { if (s_sym == MAXOCLASSES) {
static const int furnsyms[] = { static const int furnsyms[] = {
@@ -2326,7 +2326,7 @@ set_mimic_sym(register struct monst *mtmp)
}; };
ap_type = M_AP_FURNITURE; ap_type = M_AP_FURNITURE;
appear = furnsyms[rn2(SIZE(furnsyms))]; appear = ROLL_FROM(furnsyms);
} else { } else {
ap_type = M_AP_OBJECT; ap_type = M_AP_OBJECT;
if (s_sym == S_MIMIC_DEF) { if (s_sym == S_MIMIC_DEF) {
+2 -2
View File
@@ -109,7 +109,7 @@ msummon(struct monst *mon)
if (!rn2(6)) { if (!rn2(6)) {
switch (atyp) { /* see summon_minion */ switch (atyp) { /* see summon_minion */
case A_NEUTRAL: case A_NEUTRAL:
dtype = elementals[rn2(SIZE(elementals))]; dtype = ROLL_FROM(elementals);
break; break;
case A_CHAOTIC: case A_CHAOTIC:
case A_NONE: case A_NONE:
@@ -204,7 +204,7 @@ summon_minion(aligntyp alignment, boolean talk)
mnum = lminion(); mnum = lminion();
break; break;
case A_NEUTRAL: case A_NEUTRAL:
mnum = elementals[rn2(SIZE(elementals))]; mnum = ROLL_FROM(elementals);
break; break;
case A_CHAOTIC: case A_CHAOTIC:
case A_NONE: case A_NONE:
+2 -2
View File
@@ -956,7 +956,7 @@ fill_ordinary_room(struct mkroom *croom, boolean bonus_items)
WAN_DIGGING, WAN_DIGGING,
SPE_HEALING, SPE_HEALING,
}; };
otyp = supply_items[rn2(SIZE(supply_items))]; otyp = ROLL_FROM(supply_items);
} }
otmp = mksobj(otyp, TRUE, FALSE); otmp = mksobj(otyp, TRUE, FALSE);
if (otyp == POT_HEALING && rn2(2)) if (otyp == POT_HEALING && rn2(2))
@@ -991,7 +991,7 @@ fill_ordinary_room(struct mkroom *croom, boolean bonus_items)
SPBOOK_no_NOVEL, SPBOOK_no_NOVEL,
SPBOOK_no_NOVEL SPBOOK_no_NOVEL
}; };
int oclass = extra_classes[rn2(SIZE(extra_classes))]; int oclass = ROLL_FROM(extra_classes);
otmp = mkobj(oclass, FALSE); otmp = mkobj(oclass, FALSE);
if (oclass == SPBOOK_no_NOVEL) { if (oclass == SPBOOK_no_NOVEL) {
/* bias towards lower level by generating again /* bias towards lower level by generating again
+1 -1
View File
@@ -756,7 +756,7 @@ migr_booty_item(int otyp, const char* gang)
Strcpy(ONAME(otmp), gang); Strcpy(ONAME(otmp), gang);
if (objects[otyp].oc_class == FOOD_CLASS) { if (objects[otyp].oc_class == FOOD_CLASS) {
if (otyp == SLIME_MOLD) if (otyp == SLIME_MOLD)
otmp->spe = fruitadd((char *) orcfruit[rn2(SIZE(orcfruit))], otmp->spe = fruitadd((char *) ROLL_FROM(orcfruit),
(struct fruit *) 0); (struct fruit *) 0);
otmp->quan += (long) rn2(3); otmp->quan += (long) rn2(3);
otmp->owt = weight(otmp); otmp->owt = weight(otmp);
+1 -1
View File
@@ -1910,7 +1910,7 @@ static const int treefruits[] = {
struct obj * struct obj *
rnd_treefruit_at(coordxy x, coordxy y) rnd_treefruit_at(coordxy x, coordxy y)
{ {
return mksobj_at(treefruits[rn2(SIZE(treefruits))], x, y, TRUE, FALSE); return mksobj_at(ROLL_FROM(treefruits), x, y, TRUE, FALSE);
} }
/* create a stack of N gold pieces; never returns Null */ /* create a stack of N gold pieces; never returns Null */
+1 -1
View File
@@ -819,7 +819,7 @@ squadmon(void)
goto gotone; goto gotone;
} }
} }
mndx = squadprob[rn2(SIZE(squadprob))].pm; mndx = ROLL_FROM(squadprob).pm;
gotone: gotone:
if (!(gm.mvitals[mndx].mvflags & G_GONE)) if (!(gm.mvitals[mndx].mvflags & G_GONE))
return &mons[mndx]; return &mons[mndx];
+1 -1
View File
@@ -1546,7 +1546,7 @@ get_atkdam_type(int adtyp)
static const int rnd_breath_typ[] = { static const int rnd_breath_typ[] = {
AD_MAGM, AD_FIRE, AD_COLD, AD_SLEE, AD_MAGM, AD_FIRE, AD_COLD, AD_SLEE,
AD_DISN, AD_ELEC, AD_DRST, AD_ACID }; AD_DISN, AD_ELEC, AD_DRST, AD_ACID };
return rnd_breath_typ[rn2(SIZE(rnd_breath_typ))]; return ROLL_FROM(rnd_breath_typ);
} }
return adtyp; return adtyp;
} }
+1 -1
View File
@@ -48,7 +48,7 @@ const char *const hallublasts[] = {
const char * const char *
rnd_hallublast(void) rnd_hallublast(void)
{ {
return hallublasts[rn2(SIZE(hallublasts))]; return ROLL_FROM(hallublasts);
} }
boolean boolean
+1 -1
View File
@@ -695,7 +695,7 @@ do_improvisation(struct obj* instr)
/* TODO maybe: sound effects for these riffs */ /* TODO maybe: sound effects for these riffs */
You("%s %s.", You("%s %s.",
rn2(2) ? "butcher" : rn2(2) ? "manage" : "pull off", rn2(2) ? "butcher" : rn2(2) ? "manage" : "pull off",
an(beats[rn2(SIZE(beats))])); an(ROLL_FROM(beats)));
Hero_playnotes(obj_to_instr(&itmp), improvisation, 50); Hero_playnotes(obj_to_instr(&itmp), improvisation, 50);
} }
awaken_monsters(u.ulevel * (mundane ? 5 : 40)); awaken_monsters(u.ulevel * (mundane ? 5 : 40));
+2 -2
View File
@@ -1468,9 +1468,9 @@ const char *
bottlename(void) bottlename(void)
{ {
if (Hallucination) if (Hallucination)
return hbottlenames[rn2(SIZE(hbottlenames))]; return ROLL_FROM(hbottlenames);
else else
return bottlenames[rn2(SIZE(bottlenames))]; return ROLL_FROM(bottlenames);
} }
/* handle item dipped into water potion or steed saddle splashed by same */ /* handle item dipped into water potion or steed saddle splashed by same */
+1 -1
View File
@@ -1398,7 +1398,7 @@ godvoice(aligntyp g_align, const char *words)
words = ""; words = "";
pline_The("voice of %s %s: %s%s%s", align_gname(g_align), pline_The("voice of %s %s: %s%s%s", align_gname(g_align),
godvoices[rn2(SIZE(godvoices))], quot, words, quot); ROLL_FROM(godvoices), quot, words, quot);
} }
static void static void
+4 -4
View File
@@ -697,7 +697,7 @@ u_entered_shop(char *enterstring)
s_suffix(shkname(shkp)), shtypes[rt - SHOPBASE].name); s_suffix(shkname(shkp)), shtypes[rt - SHOPBASE].name);
} else { } else {
pline("%s seems %s over your return to %s %s!", pline("%s seems %s over your return to %s %s!",
Shknam(shkp), angrytexts[rn2(SIZE(angrytexts))], Shknam(shkp), ROLL_FROM(angrytexts),
noit_mhis(shkp), shtypes[rt - SHOPBASE].name); noit_mhis(shkp), shtypes[rt - SHOPBASE].name);
} }
} else if (eshkp->surcharge) { } else if (eshkp->surcharge) {
@@ -4613,7 +4613,7 @@ pay_for_damage(const char *dmgstr, boolean cant_mollify)
dugwall ? "shop" : "door"); dugwall ? "shop" : "door");
} else { } else {
pline("%s is %s that you decided to %s %s %s!", pline("%s is %s that you decided to %s %s %s!",
Shknam(shkp), angrytexts[rn2(SIZE(angrytexts))], Shknam(shkp), ROLL_FROM(angrytexts),
dmgstr, noit_mhis(shkp), dugwall ? "shop" : "door"); dmgstr, noit_mhis(shkp), dugwall ? "shop" : "door");
} }
} else { } else {
@@ -4624,7 +4624,7 @@ pay_for_damage(const char *dmgstr, boolean cant_mollify)
dugwall ? "shop" : "door"); dugwall ? "shop" : "door");
} else { } else {
pline("%s is %s that someone decided to %s %s %s!", pline("%s is %s that someone decided to %s %s %s!",
Shknam(shkp), angrytexts[rn2(SIZE(angrytexts))], Shknam(shkp), ROLL_FROM(angrytexts),
dmgstr, noit_mhis(shkp), dugwall ? "shop" : "door"); dmgstr, noit_mhis(shkp), dugwall ? "shop" : "door");
} }
} }
@@ -4926,7 +4926,7 @@ shk_chat(struct monst* shkp)
(!Deaf && !muteshk(shkp)) ? "says" : "indicates"); (!Deaf && !muteshk(shkp)) ? "says" : "indicates");
} else if (is_izchak(shkp, FALSE)) { } else if (is_izchak(shkp, FALSE)) {
if (!Deaf && !muteshk(shkp)) if (!Deaf && !muteshk(shkp))
pline(Izchak_speaks[rn2(SIZE(Izchak_speaks))], shkname(shkp)); pline(ROLL_FROM(Izchak_speaks), shkname(shkp));
} else { } else {
if (!Deaf && !muteshk(shkp)) if (!Deaf && !muteshk(shkp))
pline("%s talks about the problem of shoplifters.", Shknam(shkp)); pline("%s talks about the problem of shoplifters.", Shknam(shkp));
+4 -4
View File
@@ -406,7 +406,7 @@ growl(register struct monst* mtmp)
/* presumably nearness and soundok checks have already been made */ /* presumably nearness and soundok checks have already been made */
if (Hallucination) if (Hallucination)
growl_verb = h_sounds[rn2(SIZE(h_sounds))]; growl_verb = ROLL_FROM(h_sounds);
else else
growl_verb = growl_sound(mtmp); growl_verb = growl_sound(mtmp);
if (growl_verb) { if (growl_verb) {
@@ -432,7 +432,7 @@ yelp(register struct monst* mtmp)
/* presumably nearness and soundok checks have already been made */ /* presumably nearness and soundok checks have already been made */
if (Hallucination) if (Hallucination)
yelp_verb = h_sounds[rn2(SIZE(h_sounds))]; yelp_verb = ROLL_FROM(h_sounds);
else else
switch (mtmp->data->msound) { switch (mtmp->data->msound) {
case MS_MEW: case MS_MEW:
@@ -483,7 +483,7 @@ whimper(register struct monst* mtmp)
/* presumably nearness and soundok checks have already been made */ /* presumably nearness and soundok checks have already been made */
if (Hallucination) if (Hallucination)
whimper_verb = h_sounds[rn2(SIZE(h_sounds))]; whimper_verb = ROLL_FROM(h_sounds);
else else
switch (mtmp->data->msound) { switch (mtmp->data->msound) {
case MS_MEW: case MS_MEW:
@@ -602,7 +602,7 @@ maybe_gasp(struct monst* mon)
break; break;
} }
if (dogasp) { if (dogasp) {
return Exclam[rn2(SIZE(Exclam))]; /* [mon->m_id % SIZE(Exclam)]; */ return ROLL_FROM(Exclam); /* [mon->m_id % SIZE(Exclam)]; */
} }
return (const char *) 0; return (const char *) 0;
} }
+2 -2
View File
@@ -1125,7 +1125,7 @@ rnddoor(void)
{ {
static int state[] = { D_NODOOR, D_BROKEN, D_ISOPEN, D_CLOSED, D_LOCKED }; static int state[] = { D_NODOOR, D_BROKEN, D_ISOPEN, D_CLOSED, D_LOCKED };
return state[rn2(SIZE(state))]; return ROLL_FROM(state);
} }
/* /*
@@ -5789,7 +5789,7 @@ generate_way_out_method(
/* generate one of the escape items */ /* generate one of the escape items */
if (selection_rndcoord(ov2, &x, &y, FALSE)) { if (selection_rndcoord(ov2, &x, &y, FALSE)) {
mksobj_at(escapeitems[rn2(SIZE(escapeitems))], x, y, TRUE, FALSE); mksobj_at(ROLL_FROM(escapeitems), x, y, TRUE, FALSE);
goto gotitdone; goto gotitdone;
} }
+1 -1
View File
@@ -419,7 +419,7 @@ steal(struct monst* mtmp, char* objnambuf)
"take" }; "take" };
cant_take: cant_take:
pline("%s tries to %s %s%s but gives up.", Monnam(mtmp), pline("%s tries to %s %s%s but gives up.", Monnam(mtmp),
how[rn2(SIZE(how))], ROLL_FROM(how),
(otmp->owornmask & W_ARMOR) ? "your " : "", (otmp->owornmask & W_ARMOR) ? "your " : "",
(otmp->owornmask & W_ARMOR) ? equipname(otmp) (otmp->owornmask & W_ARMOR) ? equipname(otmp)
: yname(otmp)); : yname(otmp));
+1 -1
View File
@@ -6097,7 +6097,7 @@ chest_trap(
case 1: case 1:
case 0: case 0:
pline("A cloud of %s gas billows from %s.", pline("A cloud of %s gas billows from %s.",
Blind ? blindgas[rn2(SIZE(blindgas))] : rndcolor(), Blind ? ROLL_FROM(blindgas) : rndcolor(),
the(xname(obj))); the(xname(obj)));
if (!Stunned) { if (!Stunned) {
if (Hallucination) if (Hallucination)
+1 -1
View File
@@ -849,7 +849,7 @@ u_init(void)
if (Role_if(PM_CLERIC) || Role_if(PM_WIZARD)) { if (Role_if(PM_CLERIC) || Role_if(PM_WIZARD)) {
static int trotyp[] = { WOODEN_FLUTE, TOOLED_HORN, WOODEN_HARP, static int trotyp[] = { WOODEN_FLUTE, TOOLED_HORN, WOODEN_HARP,
BELL, BUGLE, LEATHER_DRUM }; BELL, BUGLE, LEATHER_DRUM };
Instrument[0].trotyp = trotyp[rn2(SIZE(trotyp))]; Instrument[0].trotyp = ROLL_FROM(trotyp);
ini_inv(Instrument); ini_inv(Instrument);
} }
+7 -7
View File
@@ -502,7 +502,7 @@ clonewiz(void)
} }
if (!Protection_from_shape_changers) { if (!Protection_from_shape_changers) {
mtmp2->m_ap_type = M_AP_MONSTER; mtmp2->m_ap_type = M_AP_MONSTER;
mtmp2->mappearance = wizapp[rn2(SIZE(wizapp))]; mtmp2->mappearance = ROLL_FROM(wizapp);
} }
newsym(mtmp2->mx, mtmp2->my); newsym(mtmp2->mx, mtmp2->my);
} }
@@ -513,7 +513,7 @@ int
pick_nasty( pick_nasty(
int difcap) /* if non-zero, try to make difficulty be lower than this */ int difcap) /* if non-zero, try to make difficulty be lower than this */
{ {
int alt, res = nasties[rn2(SIZE(nasties))]; int alt, res = ROLL_FROM(nasties);
/* To do? Possibly should filter for appropriate forms when /* To do? Possibly should filter for appropriate forms when
* in the elemental planes or surrounded by water or lava. * in the elemental planes or surrounded by water or lava.
@@ -523,7 +523,7 @@ pick_nasty(
*/ */
if (Is_rogue_level(&u.uz) if (Is_rogue_level(&u.uz)
&& !('A' <= mons[res].mlet && mons[res].mlet <= 'Z')) && !('A' <= mons[res].mlet && mons[res].mlet <= 'Z'))
res = nasties[rn2(SIZE(nasties))]; res = ROLL_FROM(nasties);
/* if genocided or too difficult or out of place, try a substitute /* if genocided or too difficult or out of place, try a substitute
when a suitable one exists when a suitable one exists
@@ -822,20 +822,20 @@ cuss(struct monst *mtmp)
} else if (u.uhave.amulet && !rn2(SIZE(random_insult))) { } else if (u.uhave.amulet && !rn2(SIZE(random_insult))) {
SetVoice(mtmp, 0, 80, 0); SetVoice(mtmp, 0, 80, 0);
verbalize("Relinquish the amulet, %s!", verbalize("Relinquish the amulet, %s!",
random_insult[rn2(SIZE(random_insult))]); ROLL_FROM(random_insult));
} else if (u.uhp < 5 && !rn2(2)) { /* Panic */ } else if (u.uhp < 5 && !rn2(2)) { /* Panic */
SetVoice(mtmp, 0, 80, 0); SetVoice(mtmp, 0, 80, 0);
verbalize(rn2(2) ? "Even now thy life force ebbs, %s!" verbalize(rn2(2) ? "Even now thy life force ebbs, %s!"
: "Savor thy breath, %s, it be thy last!", : "Savor thy breath, %s, it be thy last!",
random_insult[rn2(SIZE(random_insult))]); ROLL_FROM(random_insult));
} else if (mtmp->mhp < 5 && !rn2(2)) { /* Parthian shot */ } else if (mtmp->mhp < 5 && !rn2(2)) { /* Parthian shot */
SetVoice(mtmp, 0, 80, 0); SetVoice(mtmp, 0, 80, 0);
verbalize(rn2(2) ? "I shall return." : "I'll be back."); verbalize(rn2(2) ? "I shall return." : "I'll be back.");
} else { } else {
SetVoice(mtmp, 0, 80, 0); SetVoice(mtmp, 0, 80, 0);
verbalize("%s %s!", verbalize("%s %s!",
random_malediction[rn2(SIZE(random_malediction))], ROLL_FROM(random_malediction),
random_insult[rn2(SIZE(random_insult))]); ROLL_FROM(random_insult));
} }
} else if (is_lminion(mtmp) } else if (is_lminion(mtmp)
&& !(mtmp->isminion && EMIN(mtmp)->renegade)) { && !(mtmp->isminion && EMIN(mtmp)->renegade)) {