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

Comparing deliantra/server/server/spell_attack.C (file contents):
Revision 1.27 by root, Mon Jan 8 01:19:04 2007 UTC vs.
Revision 1.57 by root, Sat May 17 14:11:13 2008 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 Copyright (C) 2002-2003 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002-2003,2007 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 17 *
18 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
21 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 The authors can be reached via e-mail at <crossfire@schmorp.de>
23*/ 22 */
24 23
25/* This file contains all the spell attack code. Grouping this code 24/* This file contains all the spell attack code. Grouping this code
26 * together should hopefully make it easier to find the relevent bits 25 * together should hopefully make it easier to find the relevent bits
27 * of code 26 * of code
28 */ 27 */
37/* this function checks to see if a spell pushes objects as well 36/* this function checks to see if a spell pushes objects as well
38 * as flies over and damages them (only used for cones for now) 37 * as flies over and damages them (only used for cones for now)
39 * but moved here so it could be applied to bolts too 38 * but moved here so it could be applied to bolts too
40 * op is the spell object. 39 * op is the spell object.
41 */ 40 */
42
43void 41void
44check_spell_knockback (object *op) 42check_spell_knockback (object *op)
45{ 43{
46 object *tmp, *tmp2; /* object on the map */ 44 object *tmp, *tmp2; /* object on the map */
47 int weight_move; 45 int weight_move;
107 * 105 *
108 * BOLT CODE 106 * BOLT CODE
109 * 107 *
110 ***************************************************************************/ 108 ***************************************************************************/
111 109
112/* Causes op to fork. op is the original bolt, tmp 110/* Causes op to fork. op is the original bolt, tmp
113 * is the first piece of the fork. 111 * is the first piece of the fork.
114 */ 112 */
115
116void 113void
117forklightning (object *op, object *tmp) 114forklightning (object *op, object *tmp)
118{ 115{
119 int new_dir = 1; /* direction or -1 for left, +1 for right 0 if no new bolt */ 116 int new_dir = 1; /* direction or -1 for left, +1 for right 0 if no new bolt */
120 int t_dir; /* stores temporary dir calculation */ 117 int t_dir; /* stores temporary dir calculation */
145 142
146 /* reduce chances of subsequent forking */ 143 /* reduce chances of subsequent forking */
147 new_bolt->stats.Dex -= 10; 144 new_bolt->stats.Dex -= 10;
148 tmp->stats.Dex -= 10; /* less forks from main bolt too */ 145 tmp->stats.Dex -= 10; /* less forks from main bolt too */
149 new_bolt->stats.Con += 25 * new_dir; /* adjust the left bias */ 146 new_bolt->stats.Con += 25 * new_dir; /* adjust the left bias */
150 new_bolt->speed_left = -0.1; 147 new_bolt->speed_left = -0.1f;
151 new_bolt->direction = t_dir; 148 new_bolt->direction = t_dir;
152 new_bolt->duration++; 149 new_bolt->duration++;
153 new_bolt->stats.dam /= 2; /* reduce daughter bolt damage */ 150 new_bolt->stats.dam /= 2; /* reduce daughter bolt damage */
154 new_bolt->stats.dam++; 151 new_bolt->stats.dam++;
155 tmp->stats.dam /= 2; /* reduce father bolt damage */ 152 tmp->stats.dam /= 2; /* reduce father bolt damage */
163 */ 160 */
164 161
165void 162void
166move_bolt (object *op) 163move_bolt (object *op)
167{ 164{
168 object *tmp;
169 int mflags; 165 int mflags;
170 sint16 x, y; 166 sint16 x, y;
171 maptile *m; 167 maptile *m;
172 168
173 if (--op->duration < 0) 169 if (--op->duration < 0)
246 else 242 else
247 { /* Create a copy of this object and put it ahead */ 243 { /* Create a copy of this object and put it ahead */
248 object *tmp = op->clone (); 244 object *tmp = op->clone ();
249 245
250 m->insert (tmp, x, y, op); 246 m->insert (tmp, x, y, op);
251 tmp->speed_left = -0.1; 247 tmp->speed_left = -0.1f;
252 /* To make up for the decrease at the top of the function */ 248 /* To make up for the decrease at the top of the function */
253 tmp->duration++; 249 tmp->duration++;
254 250
255 /* New forking code. Possibly create forks of this object 251 /* New forking code. Possibly create forks of this object
256 * going off in other directions. 252 * going off in other directions.
338 move_bolt (tmp); 334 move_bolt (tmp);
339 335
340 return 1; 336 return 1;
341} 337}
342 338
343
344
345/*************************************************************************** 339/***************************************************************************
346 * 340 *
347 * BULLET/BALL CODE 341 * BULLET/BALL CODE
348 * 342 *
349 ***************************************************************************/ 343 ***************************************************************************/
350 344
351/* expands an explosion. op is a piece of the 345/* expands an explosion. op is a piece of the
352 * explosion - this expans it in the different directions. 346 * explosion - this expands it in the different directions.
353 * At least that is what I think this does. 347 * At least that is what I think this does.
354 */ 348 */
355void 349void
356explosion (object *op) 350explosion (object *op)
357{ 351{
381 if (ok_to_put_more (op->map, dx, dy, op, op->attacktype)) 375 if (ok_to_put_more (op->map, dx, dy, op, op->attacktype))
382 { 376 {
383 object *tmp = op->clone (); 377 object *tmp = op->clone ();
384 378
385 tmp->state = 0; 379 tmp->state = 0;
386 tmp->speed_left = -0.21; 380 tmp->speed_left = -0.21f;
387 tmp->range--; 381 tmp->range--;
388 tmp->value = 0; 382 tmp->value = 0;
389 383
390 m->insert (tmp, dx, dy, op); 384 m->insert (tmp, dx, dy, op);
391 } 385 }
392 } 386 }
393 } 387 }
394} 388}
395
396 389
397/* Causes an object to explode, eg, a firebullet, 390/* Causes an object to explode, eg, a firebullet,
398 * poison cloud ball, etc. op is the object to 391 * poison cloud ball, etc. op is the object to
399 * explode. 392 * explode.
400 */ 393 */
410 return; 403 return;
411 } 404 }
412 405
413 if (op->env) 406 if (op->env)
414 { 407 {
415 object *env = object_get_env_recursive (op); 408 object *env = op->outer_env ();
409
416 if (env->map == NULL || out_of_map (env->map, env->x, env->y)) 410 if (!env->map || out_of_map (env->map, env->x, env->y))
417 { 411 {
418 LOG (llevError, "BUG: explode_bullet(): env out of map\n"); 412 LOG (llevError, "BUG: explode_bullet(): env out of map\n");
419 op->destroy (); 413 op->destroy ();
420 return; 414 return;
421 } 415 }
488 482
489 /* Prevent recursion */ 483 /* Prevent recursion */
490 op->move_on = 0; 484 op->move_on = 0;
491 485
492 tmp->insert_at (op, op); 486 tmp->insert_at (op, op);
487 tmp->play_sound (tmp->sound);
488
493 /* remove the firebullet */ 489 /* remove the firebullet */
494 op->destroy (); 490 op->destroy ();
495} 491}
496 492
497/* checks to see what op should do, given the space it is on 493/* checks to see what op should do, given the space it is on
519 515
520 /* If nothing alive on this space, no reason to do anything further */ 516 /* If nothing alive on this space, no reason to do anything further */
521 if (!(mflags & P_IS_ALIVE)) 517 if (!(mflags & P_IS_ALIVE))
522 return; 518 return;
523 519
524 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 520 for (tmp = op->ms ().bot; tmp; tmp = tmp->above)
525 { 521 {
526 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 522 if (QUERY_FLAG (tmp, FLAG_ALIVE))
527 { 523 {
528 dam = hit_player (tmp, op->stats.dam, op, op->attacktype, 1); 524 dam = hit_player (tmp, op->stats.dam, op, op->attacktype, 1);
529 if (op->destroyed () || !tmp->destroyed () || (op->stats.dam -= dam) < 0) 525 if (op->destroyed () || !tmp->destroyed () || (op->stats.dam -= dam) < 0)
605 } 601 }
606 else 602 else
607 check_bullet (op); 603 check_bullet (op);
608} 604}
609 605
610
611
612
613/* fire_bullet 606/* fire_bullet
614 * object op (cast from caster) files a bolt in dir. 607 * object op (cast from caster) files a bolt in dir.
615 * spob is the spell object for the bolt. 608 * spob is the spell object for the bolt.
616 * we remove the magic flag - that can be derived from 609 * we remove the magic flag - that can be derived from
617 * spob->attacktype. 610 * spob->attacktype.
618 * This function sets up the appropriate owner and skill 611 * This function sets up the appropriate owner and skill
619 * pointers. 612 * pointers.
620 */ 613 */
621
622int 614int
623fire_bullet (object *op, object *caster, int dir, object *spob) 615fire_bullet (object *op, object *caster, int dir, object *spob)
624{ 616{
625 object *tmp = NULL; 617 object *tmp = NULL;
626 int mflags; 618 int mflags;
627 619
628 if (!spob->other_arch) 620 if (!spob->other_arch)
629 return 0; 621 return 0;
630 622
631 tmp = arch_to_object (spob->other_arch); 623 tmp = spob->other_arch->instance ();
632 if (tmp == NULL) 624 if (!tmp)
633 return 0; 625 return 0;
634 626
635 /* peterm: level dependency for bolts */ 627 /* peterm: level dependency for bolts */
636 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); 628 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob);
637 tmp->attacktype = spob->attacktype; 629 tmp->attacktype = spob->attacktype;
638 if (spob->slaying) 630 if (spob->slaying)
639 tmp->slaying = spob->slaying; 631 tmp->slaying = spob->slaying;
640 632
650 SET_ANIMATION (tmp, dir); 642 SET_ANIMATION (tmp, dir);
651 643
652 tmp->set_owner (op); 644 tmp->set_owner (op);
653 set_spell_skill (op, caster, spob, tmp); 645 set_spell_skill (op, caster, spob, tmp);
654 646
655 tmp->x = op->x + freearr_x[dir]; 647 tmp->x = op->x + freearr_x[dir];
656 tmp->y = op->y + freearr_y[dir]; 648 tmp->y = op->y + freearr_y[dir];
657 tmp->map = op->map; 649 tmp->map = op->map;
658 650
659 maptile *newmap; 651 maptile *newmap;
660 mflags = get_map_flags (tmp->map, &newmap, tmp->x, tmp->y, &tmp->x, &tmp->y); 652 mflags = get_map_flags (tmp->map, &newmap, tmp->x, tmp->y, &tmp->x, &tmp->y);
661 if (mflags & P_OUT_OF_MAP) 653 if (mflags & P_OUT_OF_MAP)
683 if ((tmp = tmp->insert_at (tmp, op))) 675 if ((tmp = tmp->insert_at (tmp, op)))
684 check_bullet (tmp); 676 check_bullet (tmp);
685 677
686 return 1; 678 return 1;
687} 679}
688
689
690
691 680
692/***************************************************************************** 681/*****************************************************************************
693 * 682 *
694 * CONE RELATED FUNCTIONS 683 * CONE RELATED FUNCTIONS
695 * 684 *
696 *****************************************************************************/ 685 *****************************************************************************/
697
698 686
699/* drops an object based on what is in the cone's "other_arch" */ 687/* drops an object based on what is in the cone's "other_arch" */
700void 688void
701cone_drop (object *op) 689cone_drop (object *op)
702{ 690{
828 816
829 /* Need to know what the movetype of the object we are about 817 /* Need to know what the movetype of the object we are about
830 * to create is, so we can know if the space we are about to 818 * to create is, so we can know if the space we are about to
831 * insert it into is blocked. 819 * insert it into is blocked.
832 */ 820 */
833 movetype = spell->other_arch->clone.move_type; 821 movetype = spell->other_arch->move_type;
834 822
835 for (i = range_min; i <= range_max; i++) 823 for (i = range_min; i <= range_max; i++)
836 { 824 {
837 sint16 x, y, d; 825 sint16 x, y, d;
838 826
917 else 905 else
918 tmp->duration += caster->level / 3; 906 tmp->duration += caster->level / 3;
919 } 907 }
920 908
921 if (!(tmp->move_type & MOVE_FLY_LOW)) 909 if (!(tmp->move_type & MOVE_FLY_LOW))
922 LOG (llevDebug, "cast_cone(): arch %s doesn't have flying 1\n", &spell->other_arch->name); 910 LOG (llevDebug, "cast_cone(): arch %s doesn't have flying 1\n", &spell->other_arch->archname);
923 911
924 if (!tmp->move_on && tmp->stats.dam) 912 if (!tmp->move_on && tmp->stats.dam)
925 LOG (llevDebug, "cast_cone(): arch %s doesn't have move_on set\n", &spell->other_arch->name); 913 LOG (llevDebug, "cast_cone(): arch %s doesn't have move_on set\n", &spell->other_arch->archname);
926 914
927 m->insert (tmp, sx, sy, op); 915 m->insert (tmp, sx, sy, op);
928 916
929 /* This is used for tracking spells so that one effect doesn't hit 917 /* This is used for tracking spells so that one effect doesn't hit
930 * a single space too many times. 918 * a single space too many times.
942 * 930 *
943 * BOMB related code 931 * BOMB related code
944 * 932 *
945 ****************************************************************************/ 933 ****************************************************************************/
946 934
947
948/* This handles an exploding bomb. 935/* This handles an exploding bomb.
949 * op is the original bomb object. 936 * op is the original bomb object.
950 */ 937 */
951void 938void
952animate_bomb (object *op) 939animate_bomb (object *op)
953{ 940{
954 int i;
955 object *env, *tmp;
956
957 if (op->state != NUM_ANIMATIONS (op) - 1) 941 if (op->state != NUM_ANIMATIONS (op) - 1)
958 return; 942 return;
959 943
960 env = object_get_env_recursive (op); 944 object *env = op->outer_env ();
961 945
962 if (op->env) 946 if (op->env)
963 { 947 {
964 if (env->map == NULL) 948 if (env->map == NULL)
965 return; 949 return;
966
967 if (env->type == PLAYER)
968 esrv_del_item (env->contr, op->count);
969 950
970 if (!(op = op->insert_at (env, op))) 951 if (!(op = op->insert_at (env, op)))
971 return; 952 return;
972 } 953 }
973 954
984 * but using the cast_bullet isn't really feasible, 965 * but using the cast_bullet isn't really feasible,
985 * so just set up the appropriate values. 966 * so just set up the appropriate values.
986 */ 967 */
987 if (archetype *at = archetype::find (SPLINT)) 968 if (archetype *at = archetype::find (SPLINT))
988 { 969 {
989 for (i = 1; i < 9; i++) 970 for (int i = 1; i < 9; i++)
990 { 971 {
991 if (out_of_map (op->map, op->x + freearr_x[i], op->y + freearr_x[i])) 972 if (out_of_map (op->map, op->x + freearr_x[i], op->y + freearr_x[i]))
992 continue; 973 continue;
993 974
994 tmp = arch_to_object (at); 975 object *tmp = arch_to_object (at);
995 tmp->direction = i; 976 tmp->direction = i;
996 tmp->range = op->range; 977 tmp->range = op->range;
997 tmp->stats.dam = op->stats.dam; 978 tmp->stats.dam = op->stats.dam;
998 tmp->duration = op->duration; 979 tmp->duration = op->duration;
999 tmp->attacktype = op->attacktype; 980 tmp->attacktype = op->attacktype;
1013} 994}
1014 995
1015int 996int
1016create_bomb (object *op, object *caster, int dir, object *spell) 997create_bomb (object *op, object *caster, int dir, object *spell)
1017{ 998{
1018
1019 object *tmp; 999 object *tmp;
1020 int mflags; 1000 int mflags;
1021 sint16 dx = op->x + freearr_x[dir], dy = op->y + freearr_y[dir]; 1001 sint16 dx = op->x + freearr_x[dir], dy = op->y + freearr_y[dir];
1022 maptile *m; 1002 maptile *m;
1023 1003
1025 if ((mflags & P_OUT_OF_MAP) || (GET_MAP_MOVE_BLOCK (m, dx, dy) & MOVE_WALK)) 1005 if ((mflags & P_OUT_OF_MAP) || (GET_MAP_MOVE_BLOCK (m, dx, dy) & MOVE_WALK))
1026 { 1006 {
1027 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 1007 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1028 return 0; 1008 return 0;
1029 } 1009 }
1010
1030 tmp = arch_to_object (spell->other_arch); 1011 tmp = arch_to_object (spell->other_arch);
1031 1012
1032 /* level dependencies for bomb */ 1013 /* level dependencies for bomb */
1033 tmp->range = spell->range + SP_level_range_adjust (caster, spell); 1014 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
1034 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); 1015 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
1055 * dir is the direction to look in. 1036 * dir is the direction to look in.
1056 * range is how far out to look. 1037 * range is how far out to look.
1057 * type is the type of spell - either SPELL_MANA or SPELL_GRACE. 1038 * type is the type of spell - either SPELL_MANA or SPELL_GRACE.
1058 * this info is used for blocked magic/unholy spaces. 1039 * this info is used for blocked magic/unholy spaces.
1059 */ 1040 */
1060
1061object * 1041object *
1062get_pointed_target (object *op, int dir, int range, int type) 1042get_pointed_target (object *op, int dir, int range, int type)
1063{ 1043{
1064 object *target; 1044 object *target;
1065 sint16 x, y; 1045 sint16 x, y;
1084 return NULL; 1064 return NULL;
1085 if (GET_MAP_MOVE_BLOCK (mp, x, y) & MOVE_FLY_LOW) 1065 if (GET_MAP_MOVE_BLOCK (mp, x, y) & MOVE_FLY_LOW)
1086 return NULL; 1066 return NULL;
1087 1067
1088 if (mflags & P_IS_ALIVE) 1068 if (mflags & P_IS_ALIVE)
1089 {
1090 for (target = GET_MAP_OB (mp, x, y); target; target = target->above) 1069 for (target = GET_MAP_OB (mp, x, y); target; target = target->above)
1091 { 1070 if (QUERY_FLAG (target, FLAG_MONSTER))
1092 if (QUERY_FLAG (target->head ? target->head : target, FLAG_MONSTER))
1093 {
1094 return target; 1071 return target;
1095 }
1096 }
1097 }
1098 } 1072 }
1073
1099 return NULL; 1074 return NULL;
1100} 1075}
1101
1102 1076
1103/* cast_smite_arch() - the priest points to a creature and causes 1077/* cast_smite_arch() - the priest points to a creature and causes
1104 * a 'godly curse' to decend. 1078 * a 'godly curse' to decend.
1105 * usual params - 1079 * usual params -
1106 * op = player 1080 * op = player
1107 * caster = object casting the spell. 1081 * caster = object casting the spell.
1108 * dir = direction being cast 1082 * dir = direction being cast
1109 * spell = spell object 1083 * spell = spell object
1110 */ 1084 */
1111
1112int 1085int
1113cast_smite_spell (object *op, object *caster, int dir, object *spell) 1086cast_smite_spell (object *op, object *caster, int dir, object *spell)
1114{ 1087{
1115 object *effect, *target; 1088 object *effect, *target;
1116 object *god = find_god (determine_god (op)); 1089 object *god = find_god (determine_god (op));
1194 effect->insert_at (target, op); 1167 effect->insert_at (target, op);
1195 1168
1196 return 1; 1169 return 1;
1197} 1170}
1198 1171
1199
1200/**************************************************************************** 1172/****************************************************************************
1201 * 1173 *
1202 * MAGIC MISSILE code. 1174 * MAGIC MISSILE code.
1203 * note that the fire_bullet is used to fire the missile. The 1175 * note that the fire_bullet is used to fire the missile. The
1204 * code here is just to move the missile. 1176 * code here is just to move the missile.
1274 * we do this by creating a force and inserting it in the 1246 * we do this by creating a force and inserting it in the
1275 * object. if time is 0, the object glows permanently. To truely 1247 * object. if time is 0, the object glows permanently. To truely
1276 * make this work for non-living objects, we would have to 1248 * make this work for non-living objects, we would have to
1277 * give them the capability to have an inventory. b.t. 1249 * give them the capability to have an inventory. b.t.
1278 */ 1250 */
1279
1280int 1251int
1281make_object_glow (object *op, int radius, int time) 1252make_object_glow (object *op, int radius, int time)
1282{ 1253{
1283 object *tmp;
1284
1285 /* some things are unaffected... */ 1254 /* some things are unaffected... */
1286 if (op->path_denied & PATH_LIGHT) 1255 if (op->path_denied & PATH_LIGHT)
1287 return 0; 1256 return 0;
1288 1257
1289 tmp = get_archetype (FORCE_NAME); 1258 object *tmp = get_archetype (FORCE_NAME);
1290 tmp->speed = 0.01; 1259 tmp->speed = 0.01;
1291 tmp->stats.food = time; 1260 tmp->stats.food = time;
1292 SET_FLAG (tmp, FLAG_IS_USED_UP); 1261 SET_FLAG (tmp, FLAG_IS_USED_UP);
1293 tmp->glow_radius = radius; 1262 tmp->glow_radius = radius;
1294 if (tmp->glow_radius > MAX_LIGHT_RADII) 1263 if (tmp->glow_radius > MAX_LIGHT_RADII)
1295 tmp->glow_radius = MAX_LIGHT_RADII; 1264 tmp->glow_radius = MAX_LIGHT_RADII;
1296 1265
1297 tmp->x = op->x;
1298 tmp->y = op->y;
1299 if (tmp->speed < MIN_ACTIVE_SPEED)
1300 tmp->speed = MIN_ACTIVE_SPEED; /* safety */
1301 tmp = insert_ob_in_ob (tmp, op); 1266 tmp = insert_ob_in_ob (tmp, op);
1267
1302 if (tmp->glow_radius > op->glow_radius) 1268 if (tmp->glow_radius > op->glow_radius)
1303 op->glow_radius = tmp->glow_radius; 1269 op->glow_radius = tmp->glow_radius;
1304 1270
1305 if (!tmp->env || op != tmp->env)
1306 {
1307 LOG (llevError, "make_object_glow() failed to insert glowing force in %s\n", &op->name);
1308 return 0;
1309 }
1310 return 1; 1271 return 1;
1311} 1272}
1312
1313
1314
1315 1273
1316int 1274int
1317cast_destruction (object *op, object *caster, object *spell_ob) 1275cast_destruction (object *op, object *caster, object *spell_ob)
1318{ 1276{
1319 int i, j, range, mflags, friendly = 0, dam, dur; 1277 int i, j, range, mflags, friendly = 0, dam, dur;
1340 else if (caster->skill) 1298 else if (caster->skill)
1341 op->skill = caster->skill; 1299 op->skill = caster->skill;
1342 else 1300 else
1343 op->skill = NULL; 1301 op->skill = NULL;
1344 1302
1345 change_skill (op, find_skill_by_name (op, op->skill), 1); 1303 op->change_skill (find_skill_by_name (op, op->skill));
1346 1304
1347 for (i = -range; i < range; i++) 1305 for (i = -range; i < range; i++)
1348 { 1306 {
1349 for (j = -range; j < range; j++) 1307 for (j = -range; j < range; j++)
1350 { 1308 {
1408 { 1366 {
1409 new_draw_info (NDI_UNIQUE, 0, op, "There is no one in that direction to curse."); 1367 new_draw_info (NDI_UNIQUE, 0, op, "There is no one in that direction to curse.");
1410 return 0; 1368 return 0;
1411 } 1369 }
1412 1370
1371 tmp = tmp->head_ ();
1372
1413 /* If we've already got a force of this type, don't add a new one. */ 1373 /* If we've already got a force of this type, don't add a new one. */
1414 for (force = tmp->inv; force != NULL; force = force->below) 1374 for (force = tmp->inv; force; force = force->below)
1415 { 1375 {
1416 if (force->type == FORCE && force->subtype == FORCE_CHANGE_ABILITY) 1376 if (force->type == FORCE && force->subtype == FORCE_CHANGE_ABILITY)
1417 { 1377 {
1418 if (force->name == spell_ob->name) 1378 if (force->name == spell_ob->name)
1419 { 1379 {
1425 return 0; 1385 return 0;
1426 } 1386 }
1427 } 1387 }
1428 } 1388 }
1429 1389
1430 if (force == NULL) 1390 if (!force)
1431 { 1391 {
1432 force = get_archetype (FORCE_NAME); 1392 force = get_archetype (FORCE_NAME);
1433 force->subtype = FORCE_CHANGE_ABILITY; 1393 force->subtype = FORCE_CHANGE_ABILITY;
1394
1434 if (spell_ob->race) 1395 if (spell_ob->race)
1435 force->name = spell_ob->race; 1396 force->name = spell_ob->race;
1436 else 1397 else
1437 force->name = spell_ob->name; 1398 force->name = spell_ob->name;
1438 1399
1448 { 1409 {
1449 force->duration = duration; 1410 force->duration = duration;
1450 new_draw_info (NDI_UNIQUE, 0, op, "You recast the spell while in effect."); 1411 new_draw_info (NDI_UNIQUE, 0, op, "You recast the spell while in effect.");
1451 } 1412 }
1452 else 1413 else
1453 {
1454 new_draw_info (NDI_UNIQUE, 0, op, "Recasting the spell had no effect."); 1414 new_draw_info (NDI_UNIQUE, 0, op, "Recasting the spell had no effect.");
1455 } 1415
1456 return 1; 1416 return 1;
1457 } 1417 }
1418
1458 force->duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob) * 50; 1419 force->duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob) * 50;
1459 force->speed = 1.0; 1420 force->speed = 1.f;
1460 force->speed_left = -1.0; 1421 force->speed_left = -1.f;
1461 SET_FLAG (force, FLAG_APPLIED); 1422 SET_FLAG (force, FLAG_APPLIED);
1462 1423
1463 if (god) 1424 if (god)
1464 { 1425 {
1465 if (spell_ob->last_grace) 1426 if (spell_ob->last_grace)
1482 insert_ob_in_ob (force, tmp); 1443 insert_ob_in_ob (force, tmp);
1483 tmp->update_stats (); 1444 tmp->update_stats ();
1484 return 1; 1445 return 1;
1485 1446
1486} 1447}
1487
1488 1448
1489/********************************************************************** 1449/**********************************************************************
1490 * mood change 1450 * mood change
1491 * Arguably, this may or may not be an attack spell. But since it 1451 * Arguably, this may or may not be an attack spell. But since it
1492 * effects monsters, it seems best to put it into this file 1452 * effects monsters, it seems best to put it into this file
1522 else if (god && !strcmp (spell->race, "GOD_FRIEND")) 1482 else if (god && !strcmp (spell->race, "GOD_FRIEND"))
1523 race = god->race; 1483 race = god->race;
1524 else 1484 else
1525 race = spell->race; 1485 race = spell->race;
1526 1486
1527
1528 for (x = op->x - range; x <= op->x + range; x++) 1487 for (x = op->x - range; x <= op->x + range; x++)
1529 for (y = op->y - range; y <= op->y + range; y++) 1488 for (y = op->y - range; y <= op->y + range; y++)
1530 { 1489 {
1531
1532 done_one = 0; 1490 done_one = 0;
1533 m = op->map; 1491 m = op->map;
1534 nx = x; 1492 nx = x;
1535 ny = y; 1493 ny = y;
1536 mflags = get_map_flags (m, &m, x, y, &nx, &ny); 1494 mflags = get_map_flags (m, &m, x, y, &nx, &ny);
1539 1497
1540 /* If there is nothing living on this space, no need to go further */ 1498 /* If there is nothing living on this space, no need to go further */
1541 if (!(mflags & P_IS_ALIVE)) 1499 if (!(mflags & P_IS_ALIVE))
1542 continue; 1500 continue;
1543 1501
1502 // players can only affect spaces that they can actually see
1503 if (caster && caster->contr
1504 && caster->contr->visibility_at (m, nx, ny) < 70)
1505 continue;
1506
1544 for (tmp = GET_MAP_OB (m, nx, ny); tmp; tmp = tmp->above) 1507 for (tmp = GET_MAP_TOP (m, nx, ny); tmp; tmp = tmp->below)
1545 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 1508 if (QUERY_FLAG (tmp, FLAG_MONSTER))
1546 break; 1509 break;
1547 1510
1548 /* There can be living objects that are not monsters */ 1511 /* There can be living objects that are not monsters */
1549 if (!tmp || tmp->type == PLAYER) 1512 if (!tmp || tmp->type == PLAYER)
1556 head = tmp; 1519 head = tmp;
1557 1520
1558 /* Make sure the race is OK. Likewise, only effect undead if spell specifically allows it */ 1521 /* Make sure the race is OK. Likewise, only effect undead if spell specifically allows it */
1559 if (race && head->race && !strstr (race, head->race)) 1522 if (race && head->race && !strstr (race, head->race))
1560 continue; 1523 continue;
1524
1561 if (QUERY_FLAG (head, FLAG_UNDEAD) && !QUERY_FLAG (spell, FLAG_UNDEAD)) 1525 if (QUERY_FLAG (head, FLAG_UNDEAD) && !QUERY_FLAG (spell, FLAG_UNDEAD))
1562 continue; 1526 continue;
1563 1527
1564 /* Now do a bunch of stuff related to saving throws */ 1528 /* Now do a bunch of stuff related to saving throws */
1565 best_at = -1; 1529 best_at = -1;
1582 at -= level / 5; 1546 at -= level / 5;
1583 if (did_make_save (head, head->level, at)) 1547 if (did_make_save (head, head->level, at))
1584 continue; 1548 continue;
1585 } 1549 }
1586 else /* spell->attacktype */ 1550 else /* spell->attacktype */
1587 /*
1588 Spell has no attacktype (charm & such), so we'll have a specific saving:
1589 * if spell level < monster level, no go
1590 * else, chance of effect = 20 + min( 50, 2 * ( spell level - monster level ) )
1591
1592 The chance will then be in the range [20-70] percent, not too bad.
1593
1594 This is required to fix the 'charm monster' abuse, where a player level 1 can
1595 charm a level 125 monster...
1596
1597 Ryo, august 14th
1598 */
1599 { 1551 {
1552 /*
1553 Spell has no attacktype (charm & such), so we'll have a specific saving:
1554 * if spell level < monster level, no go
1555 * else, chance of effect = 20 + min( 50, 2 * ( spell level - monster level ) )
1556
1557 The chance will then be in the range [20-70] percent, not too bad.
1558
1559 This is required to fix the 'charm monster' abuse, where a player level 1 can
1560 charm a level 125 monster...
1561
1562 Ryo, august 14th
1563 */
1600 if (head->level > level) 1564 if (head->level > level)
1601 continue; 1565 continue;
1566
1602 if (random_roll (0, 100, caster, PREFER_LOW) >= (20 + MIN (50, 2 * (level - head->level)))) 1567 if (random_roll (0, 100, caster, PREFER_LOW) >= (20 + MIN (50, 2 * (level - head->level))))
1603 /* Failed, no effect */ 1568 /* Failed, no effect */
1604 continue; 1569 continue;
1605 } 1570 }
1606 1571
1607 /* Done with saving throw. Now start effecting the monster */ 1572 /* Done with saving throw. Now start affecting the monster */
1608 1573
1609 /* aggravation */ 1574 /* aggravation */
1610 if (QUERY_FLAG (spell, FLAG_MONSTER)) 1575 if (QUERY_FLAG (spell, FLAG_MONSTER))
1611 { 1576 {
1612 CLEAR_FLAG (head, FLAG_SLEEP); 1577 CLEAR_FLAG (head, FLAG_SLEEP);
1613 if (QUERY_FLAG (head, FLAG_FRIENDLY))
1614 remove_friendly_object (head); 1578 remove_friendly_object (head);
1615
1616 done_one = 1; 1579 done_one = 1;
1617 head->enemy = op; 1580 head->enemy = op;
1618 } 1581 }
1619 1582
1620 /* calm monsters */ 1583 /* calm monsters */
1633 } 1596 }
1634 1597
1635 /* charm */ 1598 /* charm */
1636 if (QUERY_FLAG (spell, FLAG_NO_ATTACK) && !QUERY_FLAG (head, FLAG_FRIENDLY)) 1599 if (QUERY_FLAG (spell, FLAG_NO_ATTACK) && !QUERY_FLAG (head, FLAG_FRIENDLY))
1637 { 1600 {
1601 INVOKE_OBJECT (KILL, head, ARG_OBJECT (caster));
1602
1638 /* Prevent uncontolled outbreaks of self replicating monsters. 1603 /* Prevent uncontrolled outbreaks of self replicating monsters.
1639 Typical use case is charm, go somwhere, use aggravation to make hostile. 1604 Typical use case is charm, go somwhere, use aggravation to make hostile.
1640 This could lead to fun stuff like mice outbreak in bigworld and server crawl. */ 1605 This could lead to fun stuff like mice outbreak in bigworld and server crawl. */
1641 CLEAR_FLAG (head, FLAG_GENERATOR); 1606 CLEAR_FLAG (head, FLAG_GENERATOR);
1642 head->set_owner (op); 1607 head->set_owner (op);
1643 set_spell_skill (op, caster, spell, head); 1608 set_spell_skill (op, caster, spell, head);
1720 * if this has an other_arch field, we insert that in 1685 * if this has an other_arch field, we insert that in
1721 * the surround spaces. 1686 * the surround spaces.
1722 */ 1687 */
1723 for (j = 0; j < 9; j++) 1688 for (j = 0; j < 9; j++)
1724 { 1689 {
1725 object *new_ob;
1726
1727 hx = nx + freearr_x[j]; 1690 hx = nx + freearr_x[j];
1728 hy = ny + freearr_y[j]; 1691 hy = ny + freearr_y[j];
1729 1692
1730 m = op->map; 1693 m = op->map;
1731 mflags = get_map_flags (m, &m, hx, hy, &hx, &hy); 1694 mflags = get_map_flags (m, &m, hx, hy, &hx, &hy);
1764 1727
1765 op->direction = i; 1728 op->direction = i;
1766 } 1729 }
1767} 1730}
1768 1731
1769
1770/* move_swarm_spell: peterm 1732/* move_swarm_spell: peterm
1771 * This is an implementation of the swarm spell. It was written for 1733 * This is an implementation of the swarm spell. It was written for
1772 * meteor swarm, but it could be used for any swarm. A swarm spell 1734 * meteor swarm, but it could be used for any swarm. A swarm spell
1773 * is a special type of object that casts swarms of other types 1735 * is a special type of object that casts swarms of other types
1774 * of spells. Which spell it casts is flexible. It fires the spells 1736 * of spells. Which spell it casts is flexible. It fires the spells
1775 * from a set of squares surrounding the caster, in a given direction. 1737 * from a set of squares surrounding the caster, in a given direction.
1776 */ 1738 */
1777
1778void 1739void
1779move_swarm_spell (object *op) 1740move_swarm_spell (object *op)
1780{ 1741{
1781#if 0 1742#if 0
1782 static int cardinal_adjust[9] = { -3, -2, -1, 0, 0, 0, 1, 2, 3 }; 1743 static int cardinal_adjust[9] = { -3, -2, -1, 0, 0, 0, 1, 2, 3 };
1783 static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 }; 1744 static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 };
1784 sint16 target_x, target_y, origin_x, origin_y; 1745 sint16 target_x, target_y, origin_x, origin_y;
1785 int adjustdir; 1746 int adjustdir;
1786 maptile *m; 1747 maptile *m;
1787#endif 1748#endif
1788 int basedir;
1789 object *owner; 1749 object *owner = op->env;
1790 1750
1791 owner = op->owner; 1751 if (!op->duration || !owner->is_on_map ())
1792 if (op->duration == 0 || owner == NULL)
1793 { 1752 {
1794 op->destroy (); 1753 op->destroy ();
1795 return; 1754 return;
1796 } 1755 }
1797 1756
1798 op->duration--; 1757 op->duration--;
1799 1758
1800 basedir = op->direction; 1759 int basedir = op->direction;
1801 if (basedir == 0) 1760 if (!basedir)
1802 {
1803 /* spray in all directions! 8) */ 1761 /* spray in all directions! 8) */
1804 basedir = rndm (1, 8); 1762 basedir = (op->facing += op->state) % 8 + 1;
1805 }
1806 1763
1807#if 0 1764#if 0
1808 // this is bogus: it causes wrong places to be checked below 1765 // this is bogus: it causes wrong places to be checked below
1809 // (a wall 2 cells away will block the effect...) and 1766 // (a wall 2 cells away will block the effect...) and
1810 // doesn't work for SP_BULLET anyhow, so again tests the wrong 1767 // doesn't work for SP_BULLET anyhow, so again tests the wrong
1811 // space. 1768 // space.
1812 // should be fixed later, but correctness before featurs... 1769 // should be fixed later, but correctness before features...
1813 // (schmorp) 1770 // (schmorp)
1814 1771
1815 /* new offset calculation to make swarm element distribution 1772 /* new offset calculation to make swarm element distribution
1816 * more uniform 1773 * more uniform
1817 */ 1774 */
1870 { 1827 {
1871 /* Bullet spells have a bunch more customization that needs to be done */ 1828 /* Bullet spells have a bunch more customization that needs to be done */
1872 if (op->spell->subtype == SP_BULLET) 1829 if (op->spell->subtype == SP_BULLET)
1873 fire_bullet (owner, op, basedir, op->spell); 1830 fire_bullet (owner, op, basedir, op->spell);
1874 else if (op->spell->subtype == SP_MAGIC_MISSILE) 1831 else if (op->spell->subtype == SP_MAGIC_MISSILE)
1875 fire_arch_from_position (owner, op, op->x, op->y, basedir, op->spell); 1832 fire_arch_from_position (owner, op, owner->x, owner->y, basedir, op->spell);
1876 } 1833 }
1877} 1834}
1878
1879
1880
1881 1835
1882/* fire_swarm: 1836/* fire_swarm:
1883 * The following routine creates a swarm of objects. It actually 1837 * The following routine creates a swarm of objects. It actually
1884 * sets up a specific swarm object, which then fires off all 1838 * sets up a specific swarm object, which then fires off all
1885 * the parts of the swarm. 1839 * the parts of the swarm.
1888 * caster: the caster (owner, wand, rod, scroll) 1842 * caster: the caster (owner, wand, rod, scroll)
1889 * dir: the direction everything will be fired in 1843 * dir: the direction everything will be fired in
1890 * spell - the spell that is this spell. 1844 * spell - the spell that is this spell.
1891 * n: the number to be fired. 1845 * n: the number to be fired.
1892 */ 1846 */
1893
1894int 1847int
1895fire_swarm (object *op, object *caster, object *spell, int dir) 1848fire_swarm (object *op, object *caster, object *spell, int dir)
1896{ 1849{
1897 object *tmp;
1898 int i;
1899
1900 if (!spell->other_arch) 1850 if (!spell->other_arch)
1901 return 0; 1851 return 0;
1902 1852
1903 tmp = get_archetype (SWARM_SPELL); 1853 object *tmp = archetype::get (SWARM_SPELL);
1904 tmp->set_owner (op); /* needed so that if swarm elements kill, caster gets xp. */
1905 set_spell_skill (op, caster, spell, tmp); 1854 set_spell_skill (op, caster, spell, tmp);
1906
1907 tmp->level = caster_level (caster, spell); /*needed later, to get level dep. right. */ 1855 tmp->level = caster_level (caster, spell); /* needed later, to get level dep. right. */
1908 tmp->spell = arch_to_object (spell->other_arch); 1856 tmp->spell = spell->other_arch->instance ();
1909
1910 tmp->attacktype = tmp->spell->attacktype; 1857 tmp->attacktype = tmp->spell->attacktype;
1911 1858
1912 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) 1859 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
1913 if (!tailor_god_spell (tmp, op)) 1860 if (!tailor_god_spell (tmp, op))
1914 return 1; 1861 return 1;
1915 1862
1916 tmp->duration = SP_level_duration_adjust (caster, spell); 1863 tmp->duration = SP_level_duration_adjust (caster, spell);
1917 for (i = 0; i < spell->duration; i++) 1864 for (int i = 0; i < spell->duration; i++)
1918 tmp->duration += die_roll (1, 3, op, PREFER_HIGH); 1865 tmp->duration += die_roll (1, 3, op, PREFER_HIGH);
1919 1866
1920 tmp->direction = dir; 1867 tmp->direction = dir;
1921 tmp->invisible = 1; 1868 tmp->invisible = 1;
1869 tmp->facing = rndm (1, 8); // initial firing direction
1870 tmp->state = rndm (4) * 2 + 1; // direction increment
1922 1871
1923 tmp->insert_at (op, op); 1872 op->insert (tmp);
1873
1924 return 1; 1874 return 1;
1925} 1875}
1926
1927 1876
1928/* See the spells documentation file for why this is its own 1877/* See the spells documentation file for why this is its own
1929 * function. 1878 * function.
1930 */ 1879 */
1931int 1880int
1993 1942
1994 m->insert (tmp, x, y, op); 1943 m->insert (tmp, x, y, op);
1995 return 1; 1944 return 1;
1996} 1945}
1997 1946
1998
1999
2000
2001/* cast_cause_disease: this spell looks along <dir> from the 1947/* cast_cause_disease: this spell looks along <dir> from the
2002 * player and infects someone. 1948 * player and infects someone.
2003 * op is the player/monster, caster is the object, dir is the direction 1949 * op is the player/monster, caster is the object, dir is the direction
2004 * to cast, disease_arch is the specific disease, and type is the spell number 1950 * to cast, disease_arch is the specific disease, and type is the spell number
2005 * perhaps this should actually be in disease.c? 1951 * perhaps this should actually be in disease.c?
2006 */ 1952 */
2007
2008int 1953int
2009cast_cause_disease (object *op, object *caster, object *spell, int dir) 1954cast_cause_disease (object *op, object *caster, object *spell, int dir)
2010{ 1955{
2011 sint16 x, y; 1956 sint16 x, y;
2012 int i, mflags, range, dam_mod, dur_mod; 1957 int i, mflags, range, dam_mod, dur_mod;
2019 /* If casting from a scroll, no direction will be available, so refer to the 1964 /* If casting from a scroll, no direction will be available, so refer to the
2020 * direction the player is pointing. 1965 * direction the player is pointing.
2021 */ 1966 */
2022 if (!dir) 1967 if (!dir)
2023 dir = op->facing; 1968 dir = op->facing;
1969
2024 if (!dir) 1970 if (!dir)
2025 return 0; /* won't find anything if casting on ourself, so just return */ 1971 return 0; /* won't find anything if casting on ourself, so just return */
2026 1972
2027 /* Calculate these once here */ 1973 /* Calculate these once here */
2028 range = spell->range + SP_level_range_adjust (caster, spell); 1974 range = spell->range + SP_level_range_adjust (caster, spell);
2062 /* do level adjustments */ 2008 /* do level adjustments */
2063 if (disease->stats.wc) 2009 if (disease->stats.wc)
2064 disease->stats.wc += dur_mod / 2; 2010 disease->stats.wc += dur_mod / 2;
2065 2011
2066 if (disease->magic > 0) 2012 if (disease->magic > 0)
2067 disease->magic += dur_mod / 4; 2013 disease->magic += dur_mod / 8;
2068 2014
2069 if (disease->stats.maxhp > 0) 2015 if (disease->stats.maxhp > 0)
2070 disease->stats.maxhp += dur_mod; 2016 disease->stats.maxhp += dur_mod;
2071 2017
2072 if (disease->stats.maxgrace > 0) 2018 if (disease->stats.maxgrace > 0)
2107 if (disease->stats.sp) 2053 if (disease->stats.sp)
2108 disease->stats.sp -= dam_mod; 2054 disease->stats.sp -= dam_mod;
2109 2055
2110 if (infect_object (walk, disease, 1)) 2056 if (infect_object (walk, disease, 1))
2111 { 2057 {
2112 object *flash; /* visual effect for inflicting disease */
2113
2114 new_draw_info_format (NDI_UNIQUE, 0, op, "You inflict %s on %s!", &disease->name, &walk->name); 2058 new_draw_info_format (NDI_UNIQUE, 0, op, "You inflict %s on %s!", &disease->name, &walk->name);
2115 2059
2116 disease->destroy (); /* don't need this one anymore */ 2060 disease->destroy (); /* don't need this one anymore */
2117 walk->map->insert (get_archetype (ARCH_DETECT_MAGIC), x, y, op); 2061 walk->map->insert (get_archetype ("detect_magic"), x, y, op);
2118 return 1; 2062 return 1;
2119 } 2063 }
2120 2064
2121 disease->destroy (); 2065 disease->destroy ();
2122 } 2066 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines