ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/spell_effect.C
(Generate patch)

Comparing deliantra/server/server/spell_effect.C (file contents):
Revision 1.35 by pippijn, Mon Jan 15 21:06:20 2007 UTC vs.
Revision 1.50 by root, Sat May 12 08:36:35 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 * 7 *
23 */ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <object.h> 26#include <object.h>
27#include <living.h> 27#include <living.h>
28#ifndef __CEXTRACT__
29# include <sproto.h> 28#include <sproto.h>
30#endif
31#include <spells.h> 29#include <spells.h>
32#include <sounds.h> 30#include <sounds.h>
33 31
34/* cast_magic_storm: This is really used mostly for spell 32/* cast_magic_storm: This is really used mostly for spell
35 * fumbles at the like. tmp is the object to propogate. 33 * fumbles at the like. tmp is the object to propogate.
156 /* If it starts with a letter, presume it is a description */ 154 /* If it starts with a letter, presume it is a description */
157 if (isalpha (*stringarg)) 155 if (isalpha (*stringarg))
158 { 156 {
159 artifact *al = find_artifactlist (missile->type)->items; 157 artifact *al = find_artifactlist (missile->type)->items;
160 158
161 for (; al != NULL; al = al->next) 159 for (; al; al = al->next)
162 if (!strcasecmp (al->item->name, stringarg)) 160 if (!strcasecmp (al->item->name, stringarg))
163 break; 161 break;
164 162
165 if (!al) 163 if (!al)
166 { 164 {
375 * normal applies. 373 * normal applies.
376 */ 374 */
377int 375int
378cast_invisible (object *op, object *caster, object *spell_ob) 376cast_invisible (object *op, object *caster, object *spell_ob)
379{ 377{
380 object *tmp;
381
382 if (op->invisible > 1000) 378 if (op->invisible > 1000)
383 { 379 {
384 new_draw_info (NDI_UNIQUE, 0, op, "You can not extend the duration of your invisibility any further"); 380 new_draw_info (NDI_UNIQUE, 0, op, "You can not extend the duration of your invisibility any further");
385 return 0; 381 return 0;
386 } 382 }
402 else 398 else
403 op->contr->tmp_invis = 1; 399 op->contr->tmp_invis = 1;
404 400
405 op->contr->hidden = 0; 401 op->contr->hidden = 0;
406 } 402 }
403
407 if (makes_invisible_to (op, op)) 404 if (makes_invisible_to (op, op))
408 new_draw_info (NDI_UNIQUE, 0, op, "You can't see your hands!"); 405 new_draw_info (NDI_UNIQUE, 0, op, "You can't see your hands!");
409 else 406 else
410 new_draw_info (NDI_UNIQUE, 0, op, "You feel more transparent!"); 407 new_draw_info (NDI_UNIQUE, 0, op, "You feel more transparent!");
411 408
412 update_object (op, UP_OBJ_FACE); 409 update_object (op, UP_OBJ_CHANGE);
413 410
414 /* Only search the active objects - only these should actually do 411 /* Only search the active objects - only these should actually do
415 * harm to the player. 412 * harm to the player.
416 */ 413 */
417 for_all_actives (tmp) 414 for_all_actives (tmp)
568} 565}
569 566
570int 567int
571perceive_self (object *op) 568perceive_self (object *op)
572{ 569{
570 char buf[MAX_BUF];
573 char *cp = describe_item (op, op), buf[MAX_BUF]; 571 const char *cp = describe_item (op, op);
574 archetype *at = archetype::find (ARCH_DEPLETION); 572 archetype *at = archetype::find (ARCH_DEPLETION);
575 object *tmp; 573 object *tmp;
576 int i; 574 int i;
577 575
578 tmp = find_god (determine_god (op)); 576 tmp = find_god (determine_god (op));
607 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 605 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
608 { 606 {
609 if (tmp->type == FORCE && !strcmp (tmp->arch->name, "dragon_ability_force")) 607 if (tmp->type == FORCE && !strcmp (tmp->arch->name, "dragon_ability_force"))
610 { 608 {
611 if (tmp->stats.exp == 0) 609 if (tmp->stats.exp == 0)
612 {
613 sprintf (buf, "Your metabolism isn't focused on anything."); 610 sprintf (buf, "Your metabolism isn't focused on anything.");
614 }
615 else 611 else
616 {
617 sprintf (buf, "Your metabolism is focused on %s.", change_resist_msg[tmp->stats.exp]); 612 sprintf (buf, "Your metabolism is focused on %s.", change_resist_msg[tmp->stats.exp]);
618 } 613
619 new_draw_info (NDI_UNIQUE, 0, op, buf); 614 new_draw_info (NDI_UNIQUE, 0, op, buf);
620 break; 615 break;
621 } 616 }
622 } 617 }
623 } 618 }
619
624 return 1; 620 return 1;
625} 621}
626 622
627/* int cast_create_town_portal (object *op, object *caster, int dir) 623/* int cast_create_town_portal (object *op, object *caster, int dir)
628 * 624 *
682 */ 678 */
683 dummy->name = op->map->path; 679 dummy->name = op->map->path;
684 EXIT_X (dummy) = op->x; 680 EXIT_X (dummy) = op->x;
685 EXIT_Y (dummy) = op->y; 681 EXIT_Y (dummy) = op->y;
686 insert_ob_in_ob (dummy, op); 682 insert_ob_in_ob (dummy, op);
687 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You fix this place in your mind.\nYou feel you are able to come here from anywhere."); 683 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You fix this place in your mind. You feel you are able to come here from anywhere.");
688 return 1; 684 return 1;
689 } 685 }
690 686
691 dummy->destroy (); 687 dummy->destroy ();
692 688
764 exitmap = maptile::find_sync (force->name); 760 exitmap = maptile::find_sync (force->name);
765 761
766 /* If we were unable to load (ex. random map deleted), warn player */ 762 /* If we were unable to load (ex. random map deleted), warn player */
767 if (!exitmap) 763 if (!exitmap)
768 { 764 {
769 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Something strange happens.\nYou can't remember where to go!?"); 765 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Something strange happens. You can't remember where to go!?");
770 force->destroy (); 766 force->destroy ();
771 return 1; 767 return 1;
772 } 768 }
773 769
774 exitmap->load_sync (); 770 exitmap->load_sync ();
775 771
776 op_level = caster_level (caster, spell); 772 op_level = caster_level (caster, spell);
777 if (op_level < 15) 773 if (op_level < 15)
778 snprintf (portal_message, 1024, 774 snprintf (portal_message, 1024,
779 "\nThe air moves around you and\na huge smell of ammonia\nsurounds you as you pass\nthrough %s's tiny portal\nPouah!\n", 775 "The air moves around you and a huge smell of ammonia surounds you as you pass through %s's tiny portal. Pouah!\n",
780 &op->name); 776 &op->name);
781 else if (op_level < 30) 777 else if (op_level < 30)
782 snprintf (portal_message, 1024, 778 snprintf (portal_message, 1024,
783 "\n%s's portal smells of ozone.\nYou do a lot of movements and finally pass\nthrough the small hole in the air\n", &op->name); 779 "%s's portal smells of ozone. You do a lot of movements and finally pass through the small hole in the air\n", &op->name);
784 else if (op_level < 60) 780 else if (op_level < 60)
785 snprintf (portal_message, 1024, "\nA shining door opens in the air in front of you,\nshowing you the path to another place.\n"); 781 snprintf (portal_message, 1024, "A shining door opens in the air in front of you, showing you the path to another place.\n");
786 else 782 else
787 snprintf (portal_message, 1024, "\nAs you walk through %s's portal, flowers come out\nfrom the ground around you.\nYou feel awed.\n", 783 snprintf (portal_message, 1024, "As you walk through %s's portal, flowers come out from the ground around you. You feel awed.\n",
788 &op->name); 784 &op->name);
789 785
790 /* Create a portal in front of player 786 /* Create a portal in front of player
791 * dummy contain the portal and 787 * dummy contain the portal and
792 * force contain the track to kill it later 788 * force contain the track to kill it later
1165 object *poison; 1161 object *poison;
1166 int heal = 0, success = 0; 1162 int heal = 0, success = 0;
1167 1163
1168 tmp = find_target_for_friendly_spell (op, dir); 1164 tmp = find_target_for_friendly_spell (op, dir);
1169 1165
1170 if (tmp == NULL) 1166 if (!tmp)
1171 return 0; 1167 return 0;
1172 1168
1173 /* Figure out how many hp this spell might cure. 1169 /* Figure out how many hp this spell might cure.
1174 * could be zero if this spell heals effects, not damage. 1170 * could be zero if this spell heals effects, not damage.
1175 */ 1171 */
1178 heal += random_roll (spell->stats.hp, 6, op, PREFER_HIGH) + spell->stats.hp; 1174 heal += random_roll (spell->stats.hp, 6, op, PREFER_HIGH) + spell->stats.hp;
1179 1175
1180 if (heal) 1176 if (heal)
1181 { 1177 {
1182 if (tmp->stats.hp >= tmp->stats.maxhp) 1178 if (tmp->stats.hp >= tmp->stats.maxhp)
1183 {
1184 new_draw_info (NDI_UNIQUE, 0, tmp, "You are already fully healed."); 1179 new_draw_info (NDI_UNIQUE, 0, tmp, "You are already fully healed.");
1185 }
1186 else 1180 else
1187 { 1181 {
1188 /* See how many points we actually heal. Instead of messages 1182 /* See how many points we actually heal. Instead of messages
1189 * based on type of spell, we instead do messages based 1183 * based on type of spell, we instead do messages based
1190 * on amount of damage healed. 1184 * on amount of damage healed.
1192 if (heal > (tmp->stats.maxhp - tmp->stats.hp)) 1186 if (heal > (tmp->stats.maxhp - tmp->stats.hp))
1193 heal = tmp->stats.maxhp - tmp->stats.hp; 1187 heal = tmp->stats.maxhp - tmp->stats.hp;
1194 tmp->stats.hp += heal; 1188 tmp->stats.hp += heal;
1195 1189
1196 if (tmp->stats.hp >= tmp->stats.maxhp) 1190 if (tmp->stats.hp >= tmp->stats.maxhp)
1197 {
1198 new_draw_info (NDI_UNIQUE, 0, tmp, "You feel just fine!"); 1191 new_draw_info (NDI_UNIQUE, 0, tmp, "You feel just fine!");
1199 }
1200 else if (heal > 50) 1192 else if (heal > 50)
1201 {
1202 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds close!"); 1193 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds close!");
1203 }
1204 else if (heal > 25) 1194 else if (heal > 25)
1205 {
1206 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds mostly close."); 1195 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds mostly close.");
1207 }
1208 else if (heal > 10) 1196 else if (heal > 10)
1209 {
1210 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds start to fade."); 1197 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds start to fade.");
1211 }
1212 else 1198 else
1213 {
1214 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds start to close."); 1199 new_draw_info (NDI_UNIQUE, 0, tmp, "Your wounds start to close.");
1215 } 1200
1216 success = 1; 1201 success = 1;
1217 } 1202 }
1218 } 1203 }
1204
1219 if (spell->attacktype & AT_DISEASE) 1205 if (spell->attacktype & AT_DISEASE)
1220 if (cure_disease (tmp, op)) 1206 if (cure_disease (tmp, op))
1221 success = 1; 1207 success = 1;
1222 1208
1223 if (spell->attacktype & AT_POISON) 1209 if (spell->attacktype & AT_POISON)
1229 success = 1; 1215 success = 1;
1230 new_draw_info (NDI_UNIQUE, 0, tmp, "Your body feels cleansed"); 1216 new_draw_info (NDI_UNIQUE, 0, tmp, "Your body feels cleansed");
1231 poison->stats.food = 1; 1217 poison->stats.food = 1;
1232 } 1218 }
1233 } 1219 }
1220
1234 if (spell->attacktype & AT_CONFUSION) 1221 if (spell->attacktype & AT_CONFUSION)
1235 { 1222 {
1236 poison = present_in_ob_by_name (FORCE, "confusion", tmp); 1223 poison = present_in_ob_by_name (FORCE, "confusion", tmp);
1237 if (poison) 1224 if (poison)
1238 { 1225 {
1239 success = 1; 1226 success = 1;
1240 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 1227 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
1241 poison->duration = 1; 1228 poison->duration = 1;
1242 } 1229 }
1243 } 1230 }
1231
1244 if (spell->attacktype & AT_BLIND) 1232 if (spell->attacktype & AT_BLIND)
1245 { 1233 {
1246 at = archetype::find ("blindness"); 1234 at = archetype::find ("blindness");
1247 poison = present_arch_in_ob (at, tmp); 1235 poison = present_arch_in_ob (at, tmp);
1248 if (poison) 1236 if (poison)
1250 success = 1; 1238 success = 1;
1251 new_draw_info (NDI_UNIQUE, 0, tmp, "Your vision begins to return."); 1239 new_draw_info (NDI_UNIQUE, 0, tmp, "Your vision begins to return.");
1252 poison->stats.food = 1; 1240 poison->stats.food = 1;
1253 } 1241 }
1254 } 1242 }
1243
1255 if (spell->last_sp && tmp->stats.sp < tmp->stats.maxsp) 1244 if (spell->last_sp && tmp->stats.sp < tmp->stats.maxsp)
1256 { 1245 {
1257 tmp->stats.sp += spell->last_sp; 1246 tmp->stats.sp += spell->last_sp;
1258 if (tmp->stats.sp > tmp->stats.maxsp) 1247 if (tmp->stats.sp > tmp->stats.maxsp)
1259 tmp->stats.sp = tmp->stats.maxsp; 1248 tmp->stats.sp = tmp->stats.maxsp;
1260 success = 1; 1249 success = 1;
1261 new_draw_info (NDI_UNIQUE, 0, tmp, "Magical energy surges through your body!"); 1250 new_draw_info (NDI_UNIQUE, 0, tmp, "Magical energy surges through your body!");
1262 } 1251 }
1252
1263 if (spell->last_grace && tmp->stats.grace < tmp->stats.maxgrace) 1253 if (spell->last_grace && tmp->stats.grace < tmp->stats.maxgrace)
1264 { 1254 {
1265 tmp->stats.grace += spell->last_grace; 1255 tmp->stats.grace += spell->last_grace;
1266 if (tmp->stats.grace > tmp->stats.maxgrace) 1256 if (tmp->stats.grace > tmp->stats.maxgrace)
1267 tmp->stats.grace = tmp->stats.maxgrace; 1257 tmp->stats.grace = tmp->stats.maxgrace;
1268 success = 1; 1258 success = 1;
1269 new_draw_info (NDI_UNIQUE, 0, tmp, "You feel redeemed with your god!"); 1259 new_draw_info (NDI_UNIQUE, 0, tmp, "You feel redeemed with your god!");
1270 } 1260 }
1261
1271 if (spell->stats.food && tmp->stats.food < 999) 1262 if (spell->stats.food && tmp->stats.food < 999)
1272 { 1263 {
1273 tmp->stats.food += spell->stats.food; 1264 tmp->stats.food += spell->stats.food;
1274 if (tmp->stats.food > 999) 1265 if (tmp->stats.food > 999)
1275 tmp->stats.food = 999; 1266 tmp->stats.food = 999;
1276 success = 1; 1267 success = 1;
1277 /* We could do something a bit better like the messages for healing above */ 1268 /* We could do something a bit better like the messages for healing above */
1278 new_draw_info (NDI_UNIQUE, 0, tmp, "You feel your belly fill with food"); 1269 new_draw_info (NDI_UNIQUE, 0, tmp, "You feel your belly fill with food");
1279 } 1270 }
1271
1280 return success; 1272 return success;
1281} 1273}
1282 1274
1283 1275
1284/* This is used for the spells that gain stats. There are no spells 1276/* This is used for the spells that gain stats. There are no spells
1532 change_abil (tmp, force); /* Mostly to display any messages */ 1524 change_abil (tmp, force); /* Mostly to display any messages */
1533 insert_ob_in_ob (force, tmp); 1525 insert_ob_in_ob (force, tmp);
1534 tmp->update_stats (); 1526 tmp->update_stats ();
1535 return 1; 1527 return 1;
1536} 1528}
1537
1538
1539 1529
1540/* Alchemy code by Mark Wedel 1530/* Alchemy code by Mark Wedel
1541 * 1531 *
1542 * This code adds a new spell, called alchemy. Alchemy will turn 1532 * This code adds a new spell, called alchemy. Alchemy will turn
1543 * objects to gold nuggets, the value of the gold nuggets being 1533 * objects to gold nuggets, the value of the gold nuggets being
1553 * For example, if an item is worth 110 gold, you will get 1543 * For example, if an item is worth 110 gold, you will get
1554 * 4 large nuggets, and from 0-10 small nuggets. 1544 * 4 large nuggets, and from 0-10 small nuggets.
1555 * 1545 *
1556 * There is also a chance (1:30) that you will get nothing at all 1546 * There is also a chance (1:30) that you will get nothing at all
1557 * for the object. There is also a maximum weight that will be 1547 * for the object. There is also a maximum weight that will be
1558 * alchemied. 1548 * alchemised.
1559 */ 1549 */
1560
1561/* I didn't feel like passing these as arguements to the
1562 * two functions that need them. Real values are put in them
1563 * when the spell is cast, and these are freed when the spell
1564 * is finished.
1565 */
1566static object *small, *large;
1567
1568static void 1550static void
1569alchemy_object (object *obj, int *small_nuggets, int *large_nuggets, int *weight) 1551alchemy_object (object *obj, uint64 &total_value, int &total_weight)
1570{ 1552{
1571 uint64 value = query_cost (obj, NULL, F_TRUE); 1553 uint64 value = query_cost (obj, NULL, F_TRUE);
1572 1554
1573 /* Give third price when we alchemy money (This should hopefully 1555 /* Give third price when we alchemy money (This should hopefully
1574 * make it so that it isn't worth it to alchemy money, sell 1556 * make it so that it isn't worth it to alchemy money, sell
1575 * the nuggets, alchemy the gold from that, etc. 1557 * the nuggets, alchemy the gold from that, etc.
1576 * Otherwise, give 9 silver on the gold for other objects, 1558 * Otherwise, give 9 silver on the gold for other objects,
1577 * so that it would still be more affordable to haul 1559 * so that it would still be more affordable to haul
1578 * the stuff back to town. 1560 * the stuff back to town.
1579 */ 1561 */
1580
1581 if (QUERY_FLAG (obj, FLAG_UNPAID)) 1562 if (QUERY_FLAG (obj, FLAG_UNPAID))
1582 value = 0; 1563 value = 0;
1583 else if (obj->type == MONEY || obj->type == GEM) 1564 else if (obj->type == MONEY || obj->type == GEM)
1584 value /= 3; 1565 value /= 3;
1585 else 1566 else
1586 value = (value * 9) / 10; 1567 value = value * 9 / 10;
1587 1568
1588 value /= 4; // fix by GHJ, don't understand, pcg
1589
1590 if ((obj->value > 0) && rndm (0, 29)) 1569 if (obj->value > 0 && rndm (0, 29))
1591 { 1570 total_value += value;
1592 int count;
1593 1571
1594 count = value / large->value;
1595 *large_nuggets += count;
1596 value -= (uint64) count *(uint64) large->value;
1597
1598 count = value / small->value;
1599 *small_nuggets += count;
1600 }
1601
1602 /* Turn 25 small nuggets into 1 large nugget. If the value
1603 * of large nuggets is not evenly divisable by the small nugget
1604 * value, take off an extra small_nugget (Assuming small_nuggets!=0)
1605 */
1606 if (*small_nuggets * small->value >= large->value)
1607 {
1608 (*large_nuggets)++;
1609 *small_nuggets -= large->value / small->value;
1610 if (*small_nuggets && large->value % small->value)
1611 (*small_nuggets)--;
1612 }
1613 weight += obj->weight; 1572 total_weight += obj->total_weight ();
1573
1614 obj->destroy (); 1574 obj->destroy ();
1615} 1575}
1616 1576
1617static void 1577static void
1618update_map (object *op, maptile *m, int small_nuggets, int large_nuggets, int x, int y) 1578update_map (object *op, maptile *m, int small_nuggets, object *small, int large_nuggets, object *large, int x, int y)
1619{ 1579{
1620 object *tmp;
1621 int flag = 0; 1580 int flag = 0;
1622 1581
1623 /* Put any nuggets below the player, but we can only pass this 1582 /* Put any nuggets below the player, but we can only pass this
1624 * flag if we are on the same space as the player 1583 * flag if we are on the same space as the player
1625 */ 1584 */
1626 if (x == op->x && y == op->y && op->map == m) 1585 if (x == op->x && y == op->y && op->map == m)
1627 flag = INS_BELOW_ORIGINATOR; 1586 flag = INS_BELOW_ORIGINATOR;
1628 1587
1629 if (small_nuggets) 1588 if (small_nuggets)
1630 { 1589 {
1631 tmp = small->clone (); 1590 object *tmp = small->clone ();
1632 tmp->nrof = small_nuggets; 1591 tmp->nrof = small_nuggets;
1633 m->insert (tmp, x, y, op, flag); 1592 m->insert (tmp, x, y, op, flag);
1634 } 1593 }
1635 1594
1636 if (large_nuggets) 1595 if (large_nuggets)
1637 { 1596 {
1638 tmp = large->clone (); 1597 object *tmp = large->clone ();
1639 tmp->nrof = large_nuggets; 1598 tmp->nrof = large_nuggets;
1640 m->insert (tmp, x, y, op, flag); 1599 m->insert (tmp, x, y, op, flag);
1641 } 1600 }
1601
1602 if (object *pl = m->at (x, y).player ())
1603 if (pl->contr->ns)
1604 pl->contr->ns->look_position = 0;
1642} 1605}
1643 1606
1644int 1607int
1645alchemy (object *op, object *caster, object *spell_ob) 1608alchemy (object *op, object *caster, object *spell_ob)
1646{ 1609{
1647 int x, y, weight = 0, weight_max, large_nuggets, small_nuggets, mflags;
1648 sint16 nx, ny;
1649 object *next, *tmp;
1650 maptile *mp;
1651
1652 if (op->type != PLAYER) 1610 if (op->type != PLAYER)
1653 return 0; 1611 return 0;
1654 1612
1613 object *large = get_archetype ("largenugget");
1614 object *small = get_archetype ("smallnugget");
1615
1655 /* Put a maximum weight of items that can be alchemied. Limits the power 1616 /* Put a maximum weight of items that can be alchemised. Limits the power
1656 * some, and also prevents people from alcheming every table/chair/clock 1617 * some, and also prevents people from alchemising every table/chair/clock
1657 * in sight 1618 * in sight
1658 */ 1619 */
1659 weight_max = spell_ob->duration + +SP_level_duration_adjust (caster, spell_ob); 1620 int duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob);
1660 weight_max *= 1000; 1621 int weight_max = duration * 1000;
1661 small = get_archetype ("smallnugget"), large = get_archetype ("largenugget"); 1622 uint64 value_max = duration * 1000;
1662 1623
1624 int weight = 0;
1625
1663 for (y = op->y - 1; y <= op->y + 1; y++) 1626 for (int y = op->y - 1; y <= op->y + 1; y++)
1664 { 1627 {
1665 for (x = op->x - 1; x <= op->x + 1; x++) 1628 for (int x = op->x - 1; x <= op->x + 1; x++)
1666 { 1629 {
1630 uint64 value = 0;
1631
1667 nx = x; 1632 sint16 nx = x;
1668 ny = y; 1633 sint16 ny = y;
1669 1634
1670 mp = op->map; 1635 maptile *mp = op->map;
1671 1636
1672 mflags = get_map_flags (mp, &mp, nx, ny, &nx, &ny); 1637 int mflags = get_map_flags (mp, &mp, nx, ny, &nx, &ny);
1673 1638
1674 if (mflags & (P_OUT_OF_MAP | P_NO_MAGIC)) 1639 if (mflags & (P_OUT_OF_MAP | P_NO_MAGIC))
1675 continue; 1640 continue;
1676 1641
1677 /* Treat alchemy a little differently - most spell effects 1642 /* Treat alchemy a little differently - most spell effects
1679 * ground level effect. 1644 * ground level effect.
1680 */ 1645 */
1681 if (GET_MAP_MOVE_BLOCK (mp, nx, ny) & MOVE_WALK) 1646 if (GET_MAP_MOVE_BLOCK (mp, nx, ny) & MOVE_WALK)
1682 continue; 1647 continue;
1683 1648
1684 small_nuggets = 0; 1649 for (object *next, *tmp = mp->at (nx, ny).bot; tmp; tmp = next)
1685 large_nuggets = 0;
1686
1687 for (tmp = GET_MAP_OB (mp, nx, ny); tmp != NULL; tmp = next)
1688 { 1650 {
1689 next = tmp->above; 1651 next = tmp->above;
1652
1690 if (tmp->weight > 0 && !QUERY_FLAG (tmp, FLAG_NO_PICK) && 1653 if (tmp->weight > 0 && !QUERY_FLAG (tmp, FLAG_NO_PICK) &&
1691 !QUERY_FLAG (tmp, FLAG_ALIVE) && !QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 1654 !QUERY_FLAG (tmp, FLAG_ALIVE) && !QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
1692 { 1655 {
1693
1694 if (tmp->inv) 1656 if (tmp->inv)
1695 { 1657 {
1696 object *next1, *tmp1; 1658 object *next1, *tmp1;
1697 1659
1698 for (tmp1 = tmp->inv; tmp1 != NULL; tmp1 = next1) 1660 for (tmp1 = tmp->inv; tmp1; tmp1 = next1)
1699 { 1661 {
1700 next1 = tmp1->below; 1662 next1 = tmp1->below;
1701 if (tmp1->weight > 0 && !QUERY_FLAG (tmp1, FLAG_NO_PICK) && 1663 if (tmp1->weight > 0 && !QUERY_FLAG (tmp1, FLAG_NO_PICK) &&
1702 !QUERY_FLAG (tmp1, FLAG_ALIVE) && !QUERY_FLAG (tmp1, FLAG_IS_CAULDRON)) 1664 !QUERY_FLAG (tmp1, FLAG_ALIVE) && !QUERY_FLAG (tmp1, FLAG_IS_CAULDRON))
1703 alchemy_object (tmp1, &small_nuggets, &large_nuggets, &weight); 1665 alchemy_object (tmp1, value, weight);
1704 } 1666 }
1705 } 1667 }
1668
1706 alchemy_object (tmp, &small_nuggets, &large_nuggets, &weight); 1669 alchemy_object (tmp, value, weight);
1707 1670
1708 if (weight > weight_max) 1671 if (weight > weight_max)
1709 { 1672 break;
1710 update_map (op, mp, small_nuggets, large_nuggets, nx, ny);
1711 large->destroy ();
1712 small->destroy ();
1713 return 1;
1714 } 1673 }
1715 } /* is alchemable object */ 1674 }
1716 } /* process all objects on this space */ 1675
1676 value = min (value, value_max);
1677
1678 uint64 count = value / large->value;
1679 int large_nuggets = count;
1680 value -= count * large->value;
1681
1682 count = value / small->value;
1683 int small_nuggets = count;
1717 1684
1718 /* Insert all the nuggets at one time. This probably saves time, but 1685 /* Insert all the nuggets at one time. This probably saves time, but
1719 * it also prevents us from alcheming nuggets that were just created 1686 * it also prevents us from alcheming nuggets that were just created
1720 * with this spell. 1687 * with this spell.
1721 */ 1688 */
1722 update_map (op, mp, small_nuggets, large_nuggets, nx, ny); 1689 update_map (op, mp, small_nuggets, small, large_nuggets, large, nx, ny);
1723 }
1724 }
1725 1690
1691 if (weight > weight_max)
1692 goto bailout;
1693 }
1694 }
1695
1696bailout:
1726 large->destroy (); 1697 large->destroy ();
1727 small->destroy (); 1698 small->destroy ();
1728 /* reset this so that if player standing on a big pile of stuff,
1729 * it is redrawn properly.
1730 */
1731 op->contr->ns->look_position = 0;
1732 return 1; 1699 return 1;
1733} 1700}
1734 1701
1735 1702
1736/* This function removes the cursed/damned status on equipped 1703/* This function removes the cursed/damned status on equipped
1763 } 1730 }
1764 1731
1765 if (op->type == PLAYER) 1732 if (op->type == PLAYER)
1766 { 1733 {
1767 if (success) 1734 if (success)
1768 {
1769 new_draw_info (NDI_UNIQUE, 0, op, "You feel like some of your items are looser now."); 1735 new_draw_info (NDI_UNIQUE, 0, op, "You feel like some of your items are looser now.");
1770 }
1771 else 1736 else
1772 { 1737 {
1773 if (was_one) 1738 if (was_one)
1774 new_draw_info (NDI_UNIQUE, 0, op, "You failed to remove the curse."); 1739 new_draw_info (NDI_UNIQUE, 0, op, "You failed to remove the curse.");
1775 else 1740 else
1799 { 1764 {
1800 identify (tmp); 1765 identify (tmp);
1801 1766
1802 if (op->type == PLAYER) 1767 if (op->type == PLAYER)
1803 { 1768 {
1804 new_draw_info_format (NDI_UNIQUE, 0, op, "You have %s.", long_desc (tmp, op)); 1769 new_draw_info_format (NDI_UNIQUE, 0, op, "You identified: %s.", long_desc (tmp, op));
1805 1770
1806 if (tmp->msg) 1771 if (tmp->msg)
1807 { 1772 {
1808 new_draw_info (NDI_UNIQUE, 0, op, "The item has a story:"); 1773 new_draw_info (NDI_UNIQUE, 0, op, "The item has a story:");
1809 new_draw_info (NDI_UNIQUE, 0, op, tmp->msg); 1774 new_draw_info (NDI_UNIQUE, 0, op, tmp->msg);
1821 * stuff on the floor. Only identify stuff on the floor if the spell 1786 * stuff on the floor. Only identify stuff on the floor if the spell
1822 * was not fully used. 1787 * was not fully used.
1823 */ 1788 */
1824 if (num_ident) 1789 if (num_ident)
1825 { 1790 {
1826 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 1791 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above)
1827 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED) && !tmp->invisible && need_identify (tmp)) 1792 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED) && !tmp->invisible && need_identify (tmp))
1828 { 1793 {
1829 identify (tmp); 1794 identify (tmp);
1830 1795
1831 if (op->type == PLAYER) 1796 if (op->type == PLAYER)
1832 { 1797 {
1833 new_draw_info_format (NDI_UNIQUE, 0, op, "On the ground is %s.", long_desc (tmp, op)); 1798 new_draw_info_format (NDI_UNIQUE, 0, op, "On the ground you identified: %s.", long_desc (tmp, op));
1834 1799
1835 if (tmp->msg) 1800 if (tmp->msg)
1836 { 1801 {
1837 new_draw_info (NDI_UNIQUE, 0, op, "The item has a story:"); 1802 new_draw_info (NDI_UNIQUE, 0, op, "The item has a story:");
1838 new_draw_info (NDI_UNIQUE, 0, op, tmp->msg); 1803 new_draw_info (NDI_UNIQUE, 0, op, tmp->msg);
2188 /* Basically, if the object is magical and not counterspell, 2153 /* Basically, if the object is magical and not counterspell,
2189 * we will more or less remove the object. Don't counterspell 2154 * we will more or less remove the object. Don't counterspell
2190 * monsters either. 2155 * monsters either.
2191 */ 2156 */
2192 2157
2193 if (head->attacktype & AT_MAGIC && 2158 if (head->attacktype & AT_MAGIC
2194 !(head->attacktype & AT_COUNTERSPELL) && !QUERY_FLAG (head, FLAG_MONSTER) && (op->level > head->level)) 2159 && !(head->attacktype & AT_COUNTERSPELL)
2160 && !QUERY_FLAG (head, FLAG_MONSTER)
2161 && (op->level > head->level))
2195 head->destroy (); 2162 head->destroy ();
2196 else 2163 else
2197 switch (head->type) 2164 switch (head->type)
2198 { 2165 {
2199 case SPELL_EFFECT: 2166 case SPELL_EFFECT:
2167 // XXX: Don't affect floor spelleffects. See also XXX comment
2168 // about sanctuary in spell_util.C
2169 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
2170 continue;
2171
2200 if (op->level > head->level) 2172 if (op->level > head->level)
2201 head->destroy (); 2173 head->destroy ();
2202 2174
2203 break; 2175 break;
2204 2176
2271 * This code was very odd - code early on would only let players use the spell, 2243 * This code was very odd - code early on would only let players use the spell,
2272 * yet the code wass full of player checks. I've presumed that the code 2244 * yet the code wass full of player checks. I've presumed that the code
2273 * that only let players use it was correct, and removed all the other 2245 * that only let players use it was correct, and removed all the other
2274 * player checks. MSW 2003-01-06 2246 * player checks. MSW 2003-01-06
2275 */ 2247 */
2276
2277int 2248int
2278animate_weapon (object *op, object *caster, object *spell, int dir) 2249animate_weapon (object *op, object *caster, object *spell, int dir)
2279{ 2250{
2280 object *weapon, *tmp; 2251 object *weapon, *tmp;
2281 char buf[MAX_BUF]; 2252 char buf[MAX_BUF];
2293 /* exit if it's not a player using this spell. */ 2264 /* exit if it's not a player using this spell. */
2294 if (op->type != PLAYER) 2265 if (op->type != PLAYER)
2295 return 0; 2266 return 0;
2296 2267
2297 /* if player already has a golem, abort */ 2268 /* if player already has a golem, abort */
2298 if (op->contr->ranges[range_golem]) 2269 if (object *golem = op->contr->golem)
2299 { 2270 {
2300 control_golem (op->contr->ranges[range_golem], dir); 2271 control_golem (golem, dir);
2301 return 0; 2272 return 0;
2302 } 2273 }
2303 2274
2304 /* if no direction specified, pick one */ 2275 /* if no direction specified, pick one */
2305 if (!dir) 2276 if (!dir)
2355 CLEAR_FLAG (tmp, FLAG_MONSTER); 2326 CLEAR_FLAG (tmp, FLAG_MONSTER);
2356 tmp->stats.exp = 0; 2327 tmp->stats.exp = 0;
2357 add_friendly_object (tmp); 2328 add_friendly_object (tmp);
2358 tmp->type = GOLEM; 2329 tmp->type = GOLEM;
2359 tmp->set_owner (op); 2330 tmp->set_owner (op);
2331 op->contr->golem = tmp;
2360 set_spell_skill (op, caster, spell, tmp); 2332 set_spell_skill (op, caster, spell, tmp);
2361 op->contr->ranges[range_golem] = tmp;
2362 op->contr->shoottype = range_golem;
2363 2333
2364 /* Give the weapon to the golem now. A bit of a hack to check the 2334 /* Give the weapon to the golem now. A bit of a hack to check the
2365 * removed flag - it should only be set if get_split_object was 2335 * removed flag - it should only be set if get_split_object was
2366 * used above. 2336 * used above.
2367 */ 2337 */
2368 if (!QUERY_FLAG (weapon, FLAG_REMOVED)) 2338 if (!QUERY_FLAG (weapon, FLAG_REMOVED))
2369 weapon->remove (); 2339 weapon->remove ();
2340
2370 insert_ob_in_ob (weapon, tmp); 2341 insert_ob_in_ob (weapon, tmp);
2371 esrv_send_item (op, weapon); 2342 esrv_send_item (op, weapon);
2372 /* To do everything necessary to let a golem use the weapon is a pain, 2343 /* To do everything necessary to let a golem use the weapon is a pain,
2373 * so instead, just set it as equipped (otherwise, we need to update 2344 * so instead, just set it as equipped (otherwise, we need to update
2374 * body_info, skills, etc) 2345 * body_info, skills, etc)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines