--- deliantra/server/server/apply.C 2009/11/05 16:09:51 1.207 +++ deliantra/server/server/apply.C 2009/11/06 12:27:06 1.208 @@ -1604,6 +1604,59 @@ } /** + * op made some mistake with a scroll, this takes care of punishment. + * scroll_failure()- hacked directly from spell_failure + */ +static void +scroll_failure (object *op, int failure, int power) +{ + if (abs (failure / 4) > power) + power = abs (failure / 4); /* set minimum effect */ + + if (failure <= -1 && failure > -15) + { /* wonder */ + object *tmp; + + op->failmsg ("Your spell warps!"); + tmp = get_archetype (SPELL_WONDER); + cast_wonder (op, op, 0, tmp); + tmp->destroy (); + } + else if (failure <= -15 && failure > -35) + { /* drain mana */ + op->failmsg ("Your mana is drained!"); + op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW); + if (op->stats.sp < 0) + op->stats.sp = 0; + } + else if (settings.spell_failure_effects == TRUE) + { + if (failure <= -35 && failure > -60) + { /* confusion */ + op->failmsg ("The magic recoils on you!"); + confuse_player (op, op, power); + } + else if (failure <= -60 && failure > -70) + { /* paralysis */ + op->failmsg ("The magic recoils and paralyzes you!"); + paralyze_player (op, op, power); + } + else if (failure <= -70 && failure > -80) + { /* blind */ + op->failmsg ("The magic recoils on you!"); + blind_player (op, op, power); + } + else if (failure <= -80) + { /* blast the immediate area */ + object *tmp = get_archetype (LOOSE_MANA); + cast_magic_storm (op, tmp, power); + op->failmsg ("You unleash uncontrolled mana!"); + tmp->destroy (); + } + } +} + +/** * Handles the applying of a skill scroll, calling learn_skill straight. * op is the person learning the skill, tmp is the skill scroll object */ @@ -1921,82 +1974,6 @@ } /** - * op eats food. - * If player, takes care of messages and dragon special food. - */ -static void -apply_food (object *op, object *tmp) -{ - int capacity_remaining; - - if (op->type != PLAYER) - op->stats.hp = op->stats.maxhp; - else - { - /* check if this is a dragon (player), eating some flesh */ - if (tmp->type == FLESH && is_dragon_pl (op) && dragon_eat_flesh (op, tmp)) - ; - else - { - /* usual case - no dragon meal: */ - if (op->stats.food + tmp->stats.food > 999) - { - if (tmp->type == FOOD || tmp->type == FLESH) - op->failmsg ("You feel full, but what a waste of food!"); - else - op->statusmsg ("Most of the drink goes down your face not your throat!"); - } - - tmp->play_sound ( - tmp->sound - ? tmp->sound - : tmp->type == DRINK - ? sound_find ("eat_drink") - : sound_find ("eat_food") - ); - - if (!QUERY_FLAG (tmp, FLAG_CURSED)) - { - const char *buf; - - if (!is_dragon_pl (op)) - { - /* eating message for normal players */ - if (tmp->type == DRINK) - buf = format ("Ahhh...that %s tasted good.", &tmp->name); - else - buf = format ("The %s tasted %s", &tmp->name, tmp->type == FLESH ? "terrible!" : "good."); - } - else - /* eating message for dragon players */ - buf = format ("The %s tasted terrible!", &tmp->name); - - op->statusmsg (buf); - - capacity_remaining = 999 - op->stats.food; - op->stats.food += tmp->stats.food; - if (capacity_remaining < tmp->stats.food) - op->stats.hp += capacity_remaining / 50; - else - op->stats.hp += tmp->stats.food / 50; - - if (op->stats.hp > op->stats.maxhp) - op->stats.hp = op->stats.maxhp; - if (op->stats.food > 999) - op->stats.food = 999; - } - - /* special food hack -b.t. */ - if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED)) - eat_special_food (op, tmp); - } - } - - handle_apply_yield (tmp); - tmp->decrease (); -} - -/** * A dragon is eating some flesh. If the flesh contains resistances, * there is a chance for the dragon's skin to get improved. * @@ -2006,7 +1983,7 @@ * return: * int 1 if eating successful, 0 if it doesn't work */ -int +static int dragon_eat_flesh (object *op, object *meal) { object *skin = NULL; /* pointer to dragon skin force */ @@ -2157,6 +2134,82 @@ } /** + * op eats food. + * If player, takes care of messages and dragon special food. + */ +static void +apply_food (object *op, object *tmp) +{ + int capacity_remaining; + + if (op->type != PLAYER) + op->stats.hp = op->stats.maxhp; + else + { + /* check if this is a dragon (player), eating some flesh */ + if (tmp->type == FLESH && is_dragon_pl (op) && dragon_eat_flesh (op, tmp)) + ; + else + { + /* usual case - no dragon meal: */ + if (op->stats.food + tmp->stats.food > 999) + { + if (tmp->type == FOOD || tmp->type == FLESH) + op->failmsg ("You feel full, but what a waste of food!"); + else + op->statusmsg ("Most of the drink goes down your face not your throat!"); + } + + tmp->play_sound ( + tmp->sound + ? tmp->sound + : tmp->type == DRINK + ? sound_find ("eat_drink") + : sound_find ("eat_food") + ); + + if (!QUERY_FLAG (tmp, FLAG_CURSED)) + { + const char *buf; + + if (!is_dragon_pl (op)) + { + /* eating message for normal players */ + if (tmp->type == DRINK) + buf = format ("Ahhh...that %s tasted good.", &tmp->name); + else + buf = format ("The %s tasted %s", &tmp->name, tmp->type == FLESH ? "terrible!" : "good."); + } + else + /* eating message for dragon players */ + buf = format ("The %s tasted terrible!", &tmp->name); + + op->statusmsg (buf); + + capacity_remaining = 999 - op->stats.food; + op->stats.food += tmp->stats.food; + if (capacity_remaining < tmp->stats.food) + op->stats.hp += capacity_remaining / 50; + else + op->stats.hp += tmp->stats.food / 50; + + if (op->stats.hp > op->stats.maxhp) + op->stats.hp = op->stats.maxhp; + if (op->stats.food > 999) + op->stats.food = 999; + } + + /* special food hack -b.t. */ + if (tmp->title || QUERY_FLAG (tmp, FLAG_CURSED)) + eat_special_food (op, tmp); + } + } + + handle_apply_yield (tmp); + tmp->decrease (); +} + +/** * Handles applying an improve armor scroll. * Does some sanity checks, then calls improve_armour. */ @@ -2552,6 +2605,107 @@ } /** + * This handles items of type 'transformer'. + * Basically those items, used with a marked item, transform both items into something + * else. + * "Transformer" item has food decreased by 1, removed if 0 (0 at start means illimited).. + * Change information is contained in the 'slaying' field of the marked item. + * The format is as follow: transformer:[number ]yield[;transformer:...]. + * This way an item can be transformed in many things, and/or many objects. + * The 'slaying' field for transformer is used as verb for the action. + */ +static void +apply_item_transformer (object *pl, object *transformer) +{ + object *marked; + object *new_item; + char *find; + char *separator; + int yield; + char got[MAX_BUF]; + int len; + + if (!pl || !transformer) + return; + + marked = find_marked_object (pl); + + if (!marked) + { + pl->failmsg (format ("Use the %s with what item?", query_name (transformer))); + return; + } + + if (!marked->slaying) + { + pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); + return; + } + + /* check whether they are compatible or not */ + find = strstr (&marked->slaying, transformer->arch->archname); + if (!find || (*(find + strlen (transformer->arch->archname)) != ':')) + { + pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); + return; + } + + find += strlen (transformer->arch->archname) + 1; + /* Item can be used, now find how many and what it yields */ + if (isdigit (*(find))) + { + yield = atoi (find); + if (yield < 1) + { + LOG (llevDebug, "apply_item_transformer: item %s has slaying-yield %d.", query_base_name (marked, 0), yield); + yield = 1; + } + } + else + yield = 1; + + while (isdigit (*find)) + find++; + + while (*find == ' ') + find++; + + memset (got, 0, MAX_BUF); + + if ((separator = strchr (find, ';')) != NULL) + len = separator - find; + else + len = strlen (find); + + if (len > MAX_BUF - 1) + len = MAX_BUF - 1; + + strcpy (got, find); + got[len] = '\0'; + + /* Now create new item, remove used ones when required. */ + new_item = get_archetype (got); + if (!new_item) + { + pl->failmsg (format ("This %s is strange, better to not use it.", query_base_name (marked, 0))); + return; + } + + new_item->nrof = yield; + + pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0))); + + pl->insert (new_item); + /* Eat up one item */ + marked->decrease (); + + /* Eat one transformer if needed */ + if (transformer->stats.food) + if (--transformer->stats.food == 0) + transformer->decrease (); +} + +/** * Main apply handler. * * Checks for unpaid items before applying. @@ -3898,59 +4052,6 @@ who->update_stats (); } -/** - * op made some mistake with a scroll, this takes care of punishment. - * scroll_failure()- hacked directly from spell_failure - */ -void -scroll_failure (object *op, int failure, int power) -{ - if (abs (failure / 4) > power) - power = abs (failure / 4); /* set minimum effect */ - - if (failure <= -1 && failure > -15) - { /* wonder */ - object *tmp; - - op->failmsg ("Your spell warps!"); - tmp = get_archetype (SPELL_WONDER); - cast_wonder (op, op, 0, tmp); - tmp->destroy (); - } - else if (failure <= -15 && failure > -35) - { /* drain mana */ - op->failmsg ("Your mana is drained!"); - op->stats.sp -= random_roll (0, power - 1, op, PREFER_LOW); - if (op->stats.sp < 0) - op->stats.sp = 0; - } - else if (settings.spell_failure_effects == TRUE) - { - if (failure <= -35 && failure > -60) - { /* confusion */ - op->failmsg ("The magic recoils on you!"); - confuse_player (op, op, power); - } - else if (failure <= -60 && failure > -70) - { /* paralysis */ - op->failmsg ("The magic recoils and paralyzes you!"); - paralyze_player (op, op, power); - } - else if (failure <= -70 && failure > -80) - { /* blind */ - op->failmsg ("The magic recoils on you!"); - blind_player (op, op, power); - } - else if (failure <= -80) - { /* blast the immediate area */ - object *tmp = get_archetype (LOOSE_MANA); - cast_magic_storm (op, tmp, power); - op->failmsg ("You unleash uncontrolled mana!"); - tmp->destroy (); - } - } -} - void apply_changes_to_player (object *pl, object *change) { @@ -4035,104 +4136,3 @@ } } -/** - * This handles items of type 'transformer'. - * Basically those items, used with a marked item, transform both items into something - * else. - * "Transformer" item has food decreased by 1, removed if 0 (0 at start means illimited).. - * Change information is contained in the 'slaying' field of the marked item. - * The format is as follow: transformer:[number ]yield[;transformer:...]. - * This way an item can be transformed in many things, and/or many objects. - * The 'slaying' field for transformer is used as verb for the action. - */ -void -apply_item_transformer (object *pl, object *transformer) -{ - object *marked; - object *new_item; - char *find; - char *separator; - int yield; - char got[MAX_BUF]; - int len; - - if (!pl || !transformer) - return; - - marked = find_marked_object (pl); - - if (!marked) - { - pl->failmsg (format ("Use the %s with what item?", query_name (transformer))); - return; - } - - if (!marked->slaying) - { - pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); - return; - } - - /* check whether they are compatible or not */ - find = strstr (&marked->slaying, transformer->arch->archname); - if (!find || (*(find + strlen (transformer->arch->archname)) != ':')) - { - pl->failmsg (format ("You can't use the %s with your %s!", query_name (transformer), query_name (marked))); - return; - } - - find += strlen (transformer->arch->archname) + 1; - /* Item can be used, now find how many and what it yields */ - if (isdigit (*(find))) - { - yield = atoi (find); - if (yield < 1) - { - LOG (llevDebug, "apply_item_transformer: item %s has slaying-yield %d.", query_base_name (marked, 0), yield); - yield = 1; - } - } - else - yield = 1; - - while (isdigit (*find)) - find++; - - while (*find == ' ') - find++; - - memset (got, 0, MAX_BUF); - - if ((separator = strchr (find, ';')) != NULL) - len = separator - find; - else - len = strlen (find); - - if (len > MAX_BUF - 1) - len = MAX_BUF - 1; - - strcpy (got, find); - got[len] = '\0'; - - /* Now create new item, remove used ones when required. */ - new_item = get_archetype (got); - if (!new_item) - { - pl->failmsg (format ("This %s is strange, better to not use it.", query_base_name (marked, 0))); - return; - } - - new_item->nrof = yield; - - pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0))); - - pl->insert (new_item); - /* Eat up one item */ - marked->decrease (); - - /* Eat one transformer if needed */ - if (transformer->stats.food) - if (--transformer->stats.food == 0) - transformer->decrease (); -} -