/* * Sat Oct 3 18:33:15 1998 -- Scott Turner * * Select a random beast. This should be inversely weighted by the * combat prowess of the beast. * */ int random_beast(int sk) { int i, choice = 0; int sum = 0, val; loop_item(i) { if (item_attack(i) && item_defense(i) && item_wild(i) && (!sk || subkind(i) == sk) && !rp_item(i)->maintenance) { val = MAX_MM - MM(i) + 1; if (val < 0) val = 1; sum += val; if (rnd(1, sum) <= val) { choice = i; }; }; } next_item; assert(choice); return choice; };
/* * Sat Oct 3 18:22:54 1998 -- Scott Turner * * Select a random soldier-type unit. * */ static int random_soldier() { int i, choice = 0; int sum = 0; loop_item(i) { if (item_attack(i) && item_defense(i) && man_item(i) && rp_item(i)->maintenance) { sum++; if (rnd(1, sum) == 1) { choice = i; }; }; } next_item; return choice; };
int d_capture_beasts(struct command *c) { int type, piety, from = 0; int target = c->a; if (!has_holy_symbol(c->who)) { wout(c->who, "You must have a holy symbol to capture wild beasts."); return FALSE; }; if (!has_holy_plant(c->who)) { wout(c->who, "Capturing wild beasts requires a holy plant."); return FALSE; }; /* * Target should be a character (oddly enough) * */ if (kind(target) != T_char) { wout(c->who, "You cannot capture beasts from %s.",box_name(target)); return FALSE; }; /* * In same location. * */ if (!check_char_here(c->who, target)) { wout(c->who, "%s is not here.",box_name(c->a)); return FALSE; }; if (is_prisoner(target)) { wout(c->who, "Cannot capture beasts from prisoners."); return FALSE; }; if (c->who == target) { wout(c->who, "Can't capture beasts from oneself."); return FALSE; }; if (stack_leader(c->who) == stack_leader(target)) { wout(c->who, "Can't capture beasts from a member of the same stack."); return FALSE; }; /* * Now select a random beast from the target. That can be either the * target itself, or one of the beasts in the target's inventory. In * any case, the beast's statistics determine the piety cost of the * spell. * * Note that who the beast is "from" is also returned. * */ type = get_random_beast(target, &from); if (!type || !item_animal(type)) { wout(c->who, "%s has no beasts that you can capture.", box_name(target)); return FALSE; }; piety = ((item_attack(type) + item_defense(type)) / 50.0) + 1.5; /* * Perhaps he hasn't the piety. * */ if (!has_piety(c->who, piety)) { wout(c->who, "You lack the piety to lure a beast from %s.", box_name(target)); return FALSE; }; /* * Lure the beast away. * */ if (!move_item(from, c->who, type, 1)) { /* * Possibly it is "from" himself who we are capturing. * */ if (subkind(from) == sub_ni && item_animal(noble_item(from))) { wout(c->who, "You capture %s!",box_name(target)); use_piety(c->who, piety); take_prisoner(c->who, from); /* * Fri Mar 24 06:56:46 2000 -- Scott Turner * * Take prisoner doesn't actually transfer the animal into your * inventory, so we'll have to "create" one. * */ gen_item(c->who, type, 1); return TRUE; }; wout(c->who,"For some reason, you capture no beast."); return FALSE; }; wout(c->who, "You capture a %s from %s!",box_name(type), box_name(target)); use_piety(c->who, piety); return TRUE; };