particular types of monsters. Accordingly, make it global, and move it from decks.cc to monstuff.cc.
In xom.cc, remove get_random_nearby_monster(), as it's duplicate code, and replace it with a call to choose_random_nearby_monster(), filtering out those monsters that shouldn't be mutated.
All this should eventually allow choosing a random friendly monster near you, for the proposed TSO/Beogh blessings.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3714 c06c8d41-db1a-0410-9941-cceddc491573
GXXYPBFEWKRZQ6OBGYNS2EXZN52NGNV3UU3WM6S5R74CMJBAKGTAC C6LQVIY4ZBCWW4OWH7YS6SIHAUCAIS2EB7SJHSTNT3OLTLCEG3CQC TE3EKXUMZMN5IF3IZAAQY6OEGBE3C6QZ4L5YKXT3PAIJSUOCQXOQC 6KJRTSXHM3MQVU5CLIMN5XDMCWXAHCYR4A5QKS6MGWWEI3TCXLAQC KFULGQQOHWUTXOM3BXCCYPGGVGGY4Z6265XUFRCBPNLTZAEHJZSQC 22YVHM74WBJNJE4PA5CBEUTDWM6FAGGGILI26A4LXAURX55TNRKAC PHQHFM4FPVCJFW4BJRFC23IXIZOVN35O36YBDYW7ZF37IYWOMSDQC IOMAHHDYJ6P65ZZK4Q44YX2PEBZWBPB7ZOA3OKXPUBI5BRLRQ5JAC K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC 2E4RV454MTTCKYLKMSHEEAFPNAFVUXXPBZV3XP6V7QMF4BBWE7TAC NUYXKJP5YXHRDUQW5QW7UC3D5U3VPANIOZAOHFCPWMSRYGMA3GCAC 3KAINFIXO7WNWGUGZB43EUNFRS2ZPBLQZDTY456QACMRHYIJ7WDAC JP7SVXCIKEPVDD4Q5CDYDATPK7X5XOYW3T6QK2Y6EWHFH52LBK3QC monsters *monster = NULL;/* not particularly efficient, but oh well */for (int it = 0, num = 0; it < MAX_MONSTERS; it++){monsters *mons = &menv[it];if (mons->alive() && mons_near(mons)&& !mons_is_submerged(mons)&& one_chance_in(++num)){monster = mons;}}return (monster);
return (mons_holiness(mon) == MH_NATURAL && !mons_is_submerged(mon));
monsters* mon = get_random_nearby_monster();if (mon && mon->holiness() == MH_NATURAL)
int monster = choose_random_nearby_monster(0,choose_mutatable_monster);monsters* mon = (monster != NON_MONSTER) ? &menv[monster] : NULL;if (mon)
monsters* mon = get_random_nearby_monster();if (mon && mon->holiness() == MH_NATURAL)
int monster = choose_random_nearby_monster(0,choose_mutatable_monster);monsters* mon = (monster != NON_MONSTER) ? &menv[monster] : NULL;if (mon)
}// The default suitable() function for choose_random_nearby_monster().bool choose_any_monster(const monsters* mon){return true;}// Find a nearby monster and return its index, including you as a// possibility with probability weight. suitable() should return true// for the type of monster wanted.int choose_random_nearby_monster(int weight,bool (*suitable)(const monsters* mon)){int mons_count = weight;int result = NON_MONSTER;int ystart = you.y_pos - 9, xstart = you.x_pos - 9;int yend = you.y_pos + 9, xend = you.x_pos + 9;if ( xstart < 0 ) xstart = 0;if ( ystart < 0 ) ystart = 0;if ( xend >= GXM ) xend = GXM;if ( yend >= GYM ) yend = GYM;// monster checkfor ( int y = ystart; y < yend; ++y )for ( int x = xstart; x < xend; ++x )if ( see_grid(x,y) && mgrd[x][y] != NON_MONSTER ){result = mgrd[x][y];if ( suitable(&menv[result]) && one_chance_in(++mons_count) )break;result = NON_MONSTER;}return result;
}// Find a nearby monster to banish and return its index,// including you as a possibility with probability weight.static int choose_random_nearby_monster(int weight){int mons_count = weight;int result = NON_MONSTER;int ystart = you.y_pos - 9, xstart = you.x_pos - 9;int yend = you.y_pos + 9, xend = you.x_pos + 9;if ( xstart < 0 ) xstart = 0;if ( ystart < 0 ) ystart = 0;if ( xend >= GXM ) xend = GXM;if ( yend >= GYM ) yend = GYM;/* monster check */for ( int y = ystart; y < yend; ++y )for ( int x = xstart; x < xend; ++x )if ( see_grid(x,y) && mgrd[x][y] != NON_MONSTER )if ( one_chance_in(++mons_count) )result = mgrd[x][y];return result;