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.5 by root, Sat Aug 26 23:36:34 2006 UTC vs.
Revision 1.9 by root, Sun Sep 10 15:59:57 2006 UTC

1
1/* 2/*
2 * static char *rcsid_spell_attack_c = 3 * static char *rcsid_spell_attack_c =
3 * "$Id: spell_attack.C,v 1.5 2006/08/26 23:36:34 root Exp $"; 4 * "$Id: spell_attack.C,v 1.9 2006/09/10 15:59:57 root Exp $";
4 */ 5 */
5 6
6 7
7/* 8/*
8 CrossFire, A Multiplayer game for X-windows 9 CrossFire, A Multiplayer game for X-windows
34 35
35#include <global.h> 36#include <global.h>
36#include <object.h> 37#include <object.h>
37#include <living.h> 38#include <living.h>
38#ifndef __CEXTRACT__ 39#ifndef __CEXTRACT__
39#include <sproto.h> 40# include <sproto.h>
40#endif 41#endif
41#include <spells.h> 42#include <spells.h>
42#include <sounds.h> 43#include <sounds.h>
43 44
44/* this function checks to see if a spell pushes objects as well 45/* this function checks to see if a spell pushes objects as well
45 * as flies over and damages them (only used for cones for now) 46 * as flies over and damages them (only used for cones for now)
46 * but moved here so it could be applied to bolts too 47 * but moved here so it could be applied to bolts too
47 * op is the spell object. 48 * op is the spell object.
48 */ 49 */
49 50
51void
50void check_spell_knockback(object *op) { 52check_spell_knockback (object *op)
53{
51 object *tmp, *tmp2; /* object on the map */ 54 object *tmp, *tmp2; /* object on the map */
52 int weight_move; 55 int weight_move;
53 int frictionmod=2; /*poor man's physics - multipy targets weight by this amount */ 56 int frictionmod = 2; /*poor man's physics - multipy targets weight by this amount */
54 57
55 if(! op->weight) { /*shouldn't happen but if cone object has no weight drop out*/ 58 if (!op->weight)
59 { /*shouldn't happen but if cone object has no weight drop out */
56 /*LOG (llevDebug, "DEBUG: arch weighs nothing\n");*/ 60 /*LOG (llevDebug, "DEBUG: arch weighs nothing\n"); */
57 return; 61 return;
58 }else{ 62 }
63 else
64 {
59 weight_move = op->weight +(op->weight * op->level) / 3; 65 weight_move = op->weight + (op->weight * op->level) / 3;
60 /*LOG (llevDebug, "DEBUG: arch weighs %d and masses %d (%s,level %d)\n", op->weight,weight_move,op->name,op->level);*/ 66 /*LOG (llevDebug, "DEBUG: arch weighs %d and masses %d (%s,level %d)\n", op->weight,weight_move,op->name,op->level); */
61 } 67 }
62 68
63 for(tmp=get_map_ob(op->map,op->x,op->y);tmp!=NULL;tmp=tmp->above) 69 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above)
64 { 70 {
65 int num_sections = 1; 71 int num_sections = 1;
66 72
67 /* don't move DM */ 73 /* don't move DM */
68 if(QUERY_FLAG(tmp, FLAG_WIZ)) 74 if (QUERY_FLAG (tmp, FLAG_WIZ))
69 return; 75 return;
70 76
71 /* don't move parts of objects */ 77 /* don't move parts of objects */
72 if(tmp->head) continue; 78 if (tmp->head)
79 continue;
73 80
74 /* don't move floors or immobile objects */ 81 /* don't move floors or immobile objects */
75 if(QUERY_FLAG(tmp,FLAG_IS_FLOOR)||(!QUERY_FLAG(tmp,FLAG_ALIVE)&&QUERY_FLAG(tmp,FLAG_NO_PICK))) continue; 82 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) || (!QUERY_FLAG (tmp, FLAG_ALIVE) && QUERY_FLAG (tmp, FLAG_NO_PICK)))
83 continue;
76 84
77 /* count the object's sections */ 85 /* count the object's sections */
78 for(tmp2 = tmp; tmp2!=NULL;tmp2=tmp2->more) num_sections++; 86 for (tmp2 = tmp; tmp2 != NULL; tmp2 = tmp2->more)
87 num_sections++;
79 88
80 /* I'm not sure if it makes sense to divide by num_sections - bigger 89 /* I'm not sure if it makes sense to divide by num_sections - bigger
81 * objects should be harder to move, and we are moving the entire 90 * objects should be harder to move, and we are moving the entire
82 * object, not just the head, so the total weight should be relevant. 91 * object, not just the head, so the total weight should be relevant.
83 */ 92 */
84 93
85 /* surface area? -tm */ 94 /* surface area? -tm */
86 95
87 if (tmp->move_type & MOVE_FLYING) 96 if (tmp->move_type & MOVE_FLYING)
88 frictionmod = 1 ; /* flying objects loose the friction modifier */ 97 frictionmod = 1; /* flying objects loose the friction modifier */
89 98
90 if(rndm(0, weight_move-1) > ((tmp->weight / num_sections) * frictionmod)) { /* move it. */ 99 if (rndm (0, weight_move - 1) > ((tmp->weight / num_sections) * frictionmod))
100 { /* move it. */
91 /* move_object is really for monsters, but looking at 101 /* move_object is really for monsters, but looking at
92 * the move_object function, it appears that it should 102 * the move_object function, it appears that it should
93 * also be safe for objects. 103 * also be safe for objects.
94 * This does return if successful or not, but 104 * This does return if successful or not, but
95 * I don't see us doing anything useful with that information 105 * I don't see us doing anything useful with that information
96 * right now. 106 * right now.
97 */ 107 */
98 move_object(tmp, absdir(op->stats.sp)); 108 move_object (tmp, absdir (op->stats.sp));
99 } 109 }
100 110
101 } 111 }
102} 112}
103 113
104/*************************************************************************** 114/***************************************************************************
109 119
110/* Causes op to fork. op is the original bolt, tmp 120/* Causes op to fork. op is the original bolt, tmp
111 * is the first piece of the fork. 121 * is the first piece of the fork.
112 */ 122 */
113 123
124void
114void forklightning(object *op, object *tmp) { 125forklightning (object *op, object *tmp)
126{
115 int new_dir=1; /* direction or -1 for left, +1 for right 0 if no new bolt */ 127 int new_dir = 1; /* direction or -1 for left, +1 for right 0 if no new bolt */
116 int t_dir; /* stores temporary dir calculation */ 128 int t_dir; /* stores temporary dir calculation */
117 mapstruct *m; 129 mapstruct *m;
118 sint16 sx,sy; 130 sint16 sx, sy;
119 object *new_bolt; 131 object *new_bolt;
120 132
121 /* pick a fork direction. tmp->stats.Con is the left bias 133 /* pick a fork direction. tmp->stats.Con is the left bias
122 * i.e., the chance in 100 of forking LEFT 134 * i.e., the chance in 100 of forking LEFT
123 * Should start out at 50, down to 25 for one already going left 135 * Should start out at 50, down to 25 for one already going left
124 * down to 0 for one going 90 degrees left off original path 136 * down to 0 for one going 90 degrees left off original path
125 */ 137 */
126 138
127 if(rndm(0, 99) < tmp->stats.Con) /* fork left */ 139 if (rndm (0, 99) < tmp->stats.Con) /* fork left */
128 new_dir = -1; 140 new_dir = -1;
129 141
130 /* check the new dir for a wall and in the map*/ 142 /* check the new dir for a wall and in the map */
131 t_dir = absdir(tmp->direction + new_dir); 143 t_dir = absdir (tmp->direction + new_dir);
132 144
133 if(get_map_flags(tmp->map,&m, tmp->x + freearr_x[t_dir],tmp->y + freearr_y[t_dir], 145 if (get_map_flags (tmp->map, &m, tmp->x + freearr_x[t_dir], tmp->y + freearr_y[t_dir], &sx, &sy) & P_OUT_OF_MAP)
134 &sx, &sy) & P_OUT_OF_MAP) 146 return;
135 return;
136 147
137 if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(m, sx, sy))) 148 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, sx, sy)))
138 return; 149 return;
139 150
140 /* OK, we made a fork */ 151 /* OK, we made a fork */
141 new_bolt = get_object(); 152 new_bolt = get_object ();
142 copy_object(tmp,new_bolt); 153 copy_object (tmp, new_bolt);
143 154
144 /* reduce chances of subsequent forking */ 155 /* reduce chances of subsequent forking */
145 new_bolt->stats.Dex -= 10; 156 new_bolt->stats.Dex -= 10;
146 tmp->stats.Dex -= 10; /* less forks from main bolt too */ 157 tmp->stats.Dex -= 10; /* less forks from main bolt too */
147 new_bolt->stats.Con += 25 * new_dir; /* adjust the left bias */ 158 new_bolt->stats.Con += 25 * new_dir; /* adjust the left bias */
148 new_bolt->speed_left = -0.1; 159 new_bolt->speed_left = -0.1;
149 new_bolt->direction = t_dir; 160 new_bolt->direction = t_dir;
150 new_bolt->duration++; 161 new_bolt->duration++;
151 new_bolt->x=sx; 162 new_bolt->x = sx;
152 new_bolt->y=sy; 163 new_bolt->y = sy;
153 new_bolt->stats.dam /= 2; /* reduce daughter bolt damage */ 164 new_bolt->stats.dam /= 2; /* reduce daughter bolt damage */
154 new_bolt->stats.dam++; 165 new_bolt->stats.dam++;
155 tmp->stats.dam /= 2; /* reduce father bolt damage */ 166 tmp->stats.dam /= 2; /* reduce father bolt damage */
156 tmp->stats.dam++; 167 tmp->stats.dam++;
157 new_bolt = insert_ob_in_map(new_bolt,m,op,0); 168 new_bolt = insert_ob_in_map (new_bolt, m, op, 0);
158 update_turn_face(new_bolt); 169 update_turn_face (new_bolt);
159} 170}
160 171
161/* move_bolt: moves bolt 'op'. Basically, it just advances a space, 172/* move_bolt: moves bolt 'op'. Basically, it just advances a space,
162 * and checks for various things that may stop it. 173 * and checks for various things that may stop it.
163 */ 174 */
164 175
176void
165void move_bolt(object *op) { 177move_bolt (object *op)
178{
166 object *tmp; 179 object *tmp;
167 int mflags; 180 int mflags;
168 sint16 x, y; 181 sint16 x, y;
169 mapstruct *m; 182 mapstruct *m;
170 183
171 if(--(op->duration)<0) { 184 if (--(op->duration) < 0)
172 remove_ob(op);
173 free_object(op);
174 return;
175 } 185 {
186 remove_ob (op);
187 free_object (op);
188 return;
189 }
176 hit_map(op,0,op->attacktype,1); 190 hit_map (op, 0, op->attacktype, 1);
177 191
178 if(!op->direction) 192 if (!op->direction)
179 return;
180
181 if (--op->range<0) {
182 op->range=0;
183 } else {
184 x = op->x+DIRX(op);
185 y = op->y+DIRY(op);
186 m = op->map;
187 mflags = get_map_flags(m, &m, x, y, &x, &y);
188
189 if (mflags & P_OUT_OF_MAP) return;
190
191 /* We are about to run into something - we may bounce */
192 /* Calling reflwall is pretty costly, as it has to look at all the objects
193 * on the space. So only call reflwall if we think the data it returns
194 * will be useful.
195 */
196 if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y)) ||
197 ((mflags & P_IS_ALIVE) && reflwall(m, x, y, op))) {
198
199 if(!QUERY_FLAG(op, FLAG_REFLECTING))
200 return;
201
202 /* Since walls don't run diagonal, if the bolt is in
203 * one of 4 main directions, it just reflects back in the
204 * opposite direction. However, if the bolt is travelling
205 * on the diagonal, it is trickier - eg, a bolt travelling
206 * northwest bounces different if it hits a north/south
207 * wall (bounces to northeast) vs an east/west (bounces
208 * to the southwest.
209 */
210 if(op->direction&1)
211 op->direction=absdir(op->direction+4);
212 else {
213 int left, right;
214 int mflags;
215
216 /* Need to check for P_OUT_OF_MAP: if the bolt is tavelling
217 * over a corner in a tiled map, it is possible that
218 * op->direction is within an adjacent map but either
219 * op->direction-1 or op->direction+1 does not exist.
220 */
221 mflags = get_map_flags(op->map, &m, op->x+freearr_x[absdir(op->direction-1)],
222 op->y+freearr_y[absdir(op->direction-1)], &x, &y);
223
224 left = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y));
225
226 mflags = get_map_flags(op->map, &m, op->x+freearr_x[absdir(op->direction+1)],
227 op->y+freearr_y[absdir(op->direction+1)], &x, &y);
228 right = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y));
229
230 if(left==right)
231 op->direction=absdir(op->direction+4);
232 else if(left)
233 op->direction=absdir(op->direction+2);
234 else if(right)
235 op->direction=absdir(op->direction-2);
236 }
237 update_turn_face(op); /* A bolt *must* be IS_TURNABLE */
238 return; 193 return;
239 } 194
195 if (--op->range < 0)
196 {
197 op->range = 0;
198 }
199 else
200 {
201 x = op->x + DIRX (op);
202 y = op->y + DIRY (op);
203 m = op->map;
204 mflags = get_map_flags (m, &m, x, y, &x, &y);
205
206 if (mflags & P_OUT_OF_MAP)
207 return;
208
209 /* We are about to run into something - we may bounce */
210 /* Calling reflwall is pretty costly, as it has to look at all the objects
211 * on the space. So only call reflwall if we think the data it returns
212 * will be useful.
213 */
214 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, x, y)) || ((mflags & P_IS_ALIVE) && reflwall (m, x, y, op)))
215 {
216
217 if (!QUERY_FLAG (op, FLAG_REFLECTING))
218 return;
219
220 /* Since walls don't run diagonal, if the bolt is in
221 * one of 4 main directions, it just reflects back in the
222 * opposite direction. However, if the bolt is travelling
223 * on the diagonal, it is trickier - eg, a bolt travelling
224 * northwest bounces different if it hits a north/south
225 * wall (bounces to northeast) vs an east/west (bounces
226 * to the southwest.
227 */
228 if (op->direction & 1)
229 op->direction = absdir (op->direction + 4);
230 else
231 {
232 int left, right;
233 int mflags;
234
235 /* Need to check for P_OUT_OF_MAP: if the bolt is tavelling
236 * over a corner in a tiled map, it is possible that
237 * op->direction is within an adjacent map but either
238 * op->direction-1 or op->direction+1 does not exist.
239 */
240 mflags = get_map_flags (op->map, &m, op->x + freearr_x[absdir (op->direction - 1)],
241 op->y + freearr_y[absdir (op->direction - 1)], &x, &y);
242
243 left = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, x, y));
244
245 mflags = get_map_flags (op->map, &m, op->x + freearr_x[absdir (op->direction + 1)],
246 op->y + freearr_y[absdir (op->direction + 1)], &x, &y);
247 right = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, x, y));
248
249 if (left == right)
250 op->direction = absdir (op->direction + 4);
251 else if (left)
252 op->direction = absdir (op->direction + 2);
253 else if (right)
254 op->direction = absdir (op->direction - 2);
255 }
256 update_turn_face (op); /* A bolt *must* be IS_TURNABLE */
257 return;
258 }
259 else
240 else { /* Create a copy of this object and put it ahead */ 260 { /* Create a copy of this object and put it ahead */
241 tmp=get_object(); 261 tmp = get_object ();
242 copy_object(op,tmp); 262 copy_object (op, tmp);
243 tmp->speed_left= -0.1; 263 tmp->speed_left = -0.1;
244 tmp->x+=DIRX(tmp),tmp->y+=DIRY(tmp); 264 tmp->x += DIRX (tmp), tmp->y += DIRY (tmp);
245 tmp = insert_ob_in_map(tmp,op->map,op,0); 265 tmp = insert_ob_in_map (tmp, op->map, op, 0);
246 /* To make up for the decrease at the top of the function */ 266 /* To make up for the decrease at the top of the function */
247 tmp->duration++; 267 tmp->duration++;
248 268
249 /* New forking code. Possibly create forks of this object 269 /* New forking code. Possibly create forks of this object
250 * going off in other directions. 270 * going off in other directions.
251 */ 271 */
252 272
253 if(rndm(0, 99)< tmp->stats.Dex) { /* stats.Dex % of forking */ 273 if (rndm (0, 99) < tmp->stats.Dex)
254 forklightning(op,tmp); 274 { /* stats.Dex % of forking */
255 } 275 forklightning (op, tmp);
276 }
256 /* In this way, the object left behind sticks on the space, but 277 /* In this way, the object left behind sticks on the space, but
257 * doesn't create any bolts that continue to move onward. 278 * doesn't create any bolts that continue to move onward.
258 */ 279 */
259 op->range = 0; 280 op->range = 0;
260 } /* copy object and move it along */ 281 } /* copy object and move it along */
261 } /* if move bolt along */ 282 } /* if move bolt along */
262} 283}
263 284
264/* fire_bolt 285/* fire_bolt
265 * object op (cast from caster) files a bolt in dir. 286 * object op (cast from caster) files a bolt in dir.
266 * spob is the spell object for the bolt. 287 * spob is the spell object for the bolt.
268 * spob->attacktype. 289 * spob->attacktype.
269 * This function sets up the appropriate owner and skill 290 * This function sets up the appropriate owner and skill
270 * pointers. 291 * pointers.
271 */ 292 */
272 293
294int
273int fire_bolt(object *op,object *caster,int dir,object *spob, object *skill) { 295fire_bolt (object *op, object *caster, int dir, object *spob, object *skill)
296{
274 object *tmp=NULL; 297 object *tmp = NULL;
275 int mflags; 298 int mflags;
276 299
277 if (!spob->other_arch) 300 if (!spob->other_arch)
278 return 0; 301 return 0;
279 302
280 tmp=arch_to_object(spob->other_arch); 303 tmp = arch_to_object (spob->other_arch);
281 if(tmp==NULL) 304 if (tmp == NULL)
282 return 0; 305 return 0;
283 306
284 /* peterm: level dependency for bolts */ 307 /* peterm: level dependency for bolts */
285 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust(caster,spob); 308 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob);
286 tmp->attacktype = spob->attacktype; 309 tmp->attacktype = spob->attacktype;
287 if (spob->slaying) tmp->slaying = add_refcount(spob->slaying); 310 if (spob->slaying)
311 tmp->slaying = spob->slaying;
288 tmp->range = spob->range + SP_level_range_adjust(caster,spob); 312 tmp->range = spob->range + SP_level_range_adjust (caster, spob);
289 tmp->duration = spob->duration + SP_level_duration_adjust(caster,spob); 313 tmp->duration = spob->duration + SP_level_duration_adjust (caster, spob);
290 tmp->stats.Dex = spob->stats.Dex; 314 tmp->stats.Dex = spob->stats.Dex;
291 tmp->stats.Con = spob->stats.Con; 315 tmp->stats.Con = spob->stats.Con;
292 316
293 tmp->direction=dir; 317 tmp->direction = dir;
294 if(QUERY_FLAG(tmp, FLAG_IS_TURNABLE)) 318 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
295 SET_ANIMATION(tmp, dir); 319 SET_ANIMATION (tmp, dir);
296 320
297 set_owner(tmp,op); 321 set_owner (tmp, op);
298 set_spell_skill(op, caster, spob, tmp); 322 set_spell_skill (op, caster, spob, tmp);
299 323
300 tmp->x=op->x + DIRX(tmp); 324 tmp->x = op->x + DIRX (tmp);
301 tmp->y=op->y + DIRY(tmp); 325 tmp->y = op->y + DIRY (tmp);
302 tmp->map = op->map; 326 tmp->map = op->map;
303 327
304 mflags = get_map_flags(tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); 328 mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y);
305 if (mflags & P_OUT_OF_MAP) { 329 if (mflags & P_OUT_OF_MAP)
330 {
306 free_object(tmp); 331 free_object (tmp);
307 return 0; 332 return 0;
308 } 333 }
309 if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) { 334 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y)))
335 {
310 if(!QUERY_FLAG(tmp, FLAG_REFLECTING)) { 336 if (!QUERY_FLAG (tmp, FLAG_REFLECTING))
337 {
311 free_object(tmp); 338 free_object (tmp);
312 return 0; 339 return 0;
313 } 340 }
314 tmp->x=op->x; 341 tmp->x = op->x;
315 tmp->y=op->y; 342 tmp->y = op->y;
316 tmp->direction=absdir(tmp->direction+4); 343 tmp->direction = absdir (tmp->direction + 4);
317 tmp->map = op->map; 344 tmp->map = op->map;
318 } 345 }
319 if ((tmp = insert_ob_in_map(tmp,tmp->map,op,0)) != NULL) 346 if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL)
320 move_bolt (tmp); 347 move_bolt (tmp);
321 return 1; 348 return 1;
322} 349}
323 350
324 351
325 352
326/*************************************************************************** 353/***************************************************************************
331 358
332/* expands an explosion. op is a piece of the 359/* expands an explosion. op is a piece of the
333 * explosion - this expans it in the different directions. 360 * explosion - this expans it in the different directions.
334 * At least that is what I think this does. 361 * At least that is what I think this does.
335 */ 362 */
363void
336void explosion(object *op) { 364explosion (object *op)
365{
337 object *tmp; 366 object *tmp;
338 mapstruct *m=op->map; 367 mapstruct *m = op->map;
339 int i; 368 int i;
340 369
341 if(--(op->duration)<0) { 370 if (--(op->duration) < 0)
342 remove_ob(op);
343 free_object(op);
344 return;
345 } 371 {
372 remove_ob (op);
373 free_object (op);
374 return;
375 }
346 hit_map(op,0,op->attacktype,0); 376 hit_map (op, 0, op->attacktype, 0);
347 377
348 if(op->range>0) { 378 if (op->range > 0)
349 for(i=1;i<9;i++) { 379 {
380 for (i = 1; i < 9; i++)
381 {
350 sint16 dx,dy; 382 sint16 dx, dy;
351 383
352 dx=op->x+freearr_x[i]; 384 dx = op->x + freearr_x[i];
353 dy=op->y+freearr_y[i]; 385 dy = op->y + freearr_y[i];
354 /* ok_to_put_more already does things like checks for walls, 386 /* ok_to_put_more already does things like checks for walls,
355 * out of map, etc. 387 * out of map, etc.
356 */ 388 */
357 if(ok_to_put_more(op->map,dx,dy,op,op->attacktype)) { 389 if (ok_to_put_more (op->map, dx, dy, op, op->attacktype))
358 tmp=get_object(); 390 {
359 copy_object(op,tmp); 391 tmp = get_object ();
360 tmp->state=0; 392 copy_object (op, tmp);
361 tmp->speed_left= -0.21; 393 tmp->state = 0;
362 tmp->range--; 394 tmp->speed_left = -0.21;
363 tmp->value=0; 395 tmp->range--;
364 tmp->x=dx; 396 tmp->value = 0;
365 tmp->y=dy; 397 tmp->x = dx;
366 insert_ob_in_map(tmp,m,op,0); 398 tmp->y = dy;
367 } 399 insert_ob_in_map (tmp, m, op, 0);
368 } 400 }
401 }
369 } 402 }
370} 403}
371 404
372 405
373/* Causes an object to explode, eg, a firebullet, 406/* Causes an object to explode, eg, a firebullet,
374 * poison cloud ball, etc. op is the object to 407 * poison cloud ball, etc. op is the object to
375 * explode. 408 * explode.
376 */ 409 */
410void
377void explode_bullet(object *op) 411explode_bullet (object *op)
378{ 412{
379 tag_t op_tag = op->count; 413 tag_t op_tag = op->count;
380 object *tmp, *owner; 414 object *tmp, *owner;
381 415
382 if (op->other_arch == NULL) { 416 if (op->other_arch == NULL)
417 {
383 LOG (llevError, "BUG: explode_bullet(): op without other_arch\n"); 418 LOG (llevError, "BUG: explode_bullet(): op without other_arch\n");
384 remove_ob (op); 419 remove_ob (op);
385 free_object (op); 420 free_object (op);
386 return; 421 return;
387 } 422 }
388 423
389 if (op->env) { 424 if (op->env)
425 {
390 object *env; 426 object *env;
391 427
392 env = object_get_env_recursive(op); 428 env = object_get_env_recursive (op);
393 if (env->map == NULL || out_of_map (env->map, env->x, env->y)) { 429 if (env->map == NULL || out_of_map (env->map, env->x, env->y))
430 {
394 LOG (llevError, "BUG: explode_bullet(): env out of map\n"); 431 LOG (llevError, "BUG: explode_bullet(): env out of map\n");
432 remove_ob (op);
433 free_object (op);
434 return;
435 }
395 remove_ob (op); 436 remove_ob (op);
396 free_object (op);
397 return;
398 }
399 remove_ob (op);
400 op->x = env->x; 437 op->x = env->x;
401 op->y = env->y; 438 op->y = env->y;
402 insert_ob_in_map(op, env->map, op, INS_NO_MERGE | INS_NO_WALK_ON); 439 insert_ob_in_map (op, env->map, op, INS_NO_MERGE | INS_NO_WALK_ON);
440 }
403 } else if (out_of_map (op->map, op->x, op->y)) { 441 else if (out_of_map (op->map, op->x, op->y))
442 {
404 LOG (llevError, "BUG: explode_bullet(): op out of map\n"); 443 LOG (llevError, "BUG: explode_bullet(): op out of map\n");
405 remove_ob (op); 444 remove_ob (op);
406 free_object (op); 445 free_object (op);
407 return; 446 return;
408 } 447 }
409 448
410 // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent explosions of any kind on safe maps 449 // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent explosions of any kind on safe maps
411 // NOTE: If this breaks something important: remove this. I can't think of anything 450 // NOTE: If this breaks something important: remove this. I can't think of anything
412 // bad at the moment that might happen from this. 451 // bad at the moment that might happen from this.
413 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) 452 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE)
414 { 453 {
415 remove_ob (op); 454 remove_ob (op);
416 free_object (op); 455 free_object (op);
456 return;
457 }
458
459 if (op->attacktype)
460 {
461 hit_map (op, 0, op->attacktype, 1);
462 if (was_destroyed (op, op_tag))
417 return; 463 return;
418 } 464 }
419 465
420 if (op->attacktype) {
421 hit_map (op, 0, op->attacktype, 1);
422 if (was_destroyed (op, op_tag))
423 return;
424 }
425
426 /* other_arch contains what this explodes into */ 466 /* other_arch contains what this explodes into */
427 tmp = arch_to_object (op->other_arch); 467 tmp = arch_to_object (op->other_arch);
428 468
429 copy_owner (tmp, op); 469 copy_owner (tmp, op);
430 if (tmp->skill) FREE_AND_CLEAR_STR(tmp->skill); 470 tmp->skill = op->skill;
431 if (op->skill) tmp->skill = add_refcount(op->skill);
432 471
433 owner = get_owner(op); 472 owner = get_owner (op);
434 if ((tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) && owner && 473 if ((tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) && owner && !tailor_god_spell (tmp, owner))
435 !tailor_god_spell(tmp, owner)) { 474 {
436 remove_ob (op); 475 remove_ob (op);
437 free_object (op); 476 free_object (op);
438 return; 477 return;
439 } 478 }
440 tmp->x = op->x; 479 tmp->x = op->x;
441 tmp->y = op->y; 480 tmp->y = op->y;
442 481
443 /* special for bombs - it actually has sane values for these */ 482 /* special for bombs - it actually has sane values for these */
444 if (op->type == SPELL_EFFECT && op->subtype == SP_BOMB) { 483 if (op->type == SPELL_EFFECT && op->subtype == SP_BOMB)
484 {
445 tmp->attacktype = op->attacktype; 485 tmp->attacktype = op->attacktype;
446 tmp->range = op->range; 486 tmp->range = op->range;
447 tmp->stats.dam = op->stats.dam; 487 tmp->stats.dam = op->stats.dam;
448 tmp->duration = op->duration; 488 tmp->duration = op->duration;
449 } else { 489 }
450 if (op->attacktype & AT_MAGIC) tmp->attacktype|=AT_MAGIC; 490 else
491 {
492 if (op->attacktype & AT_MAGIC)
493 tmp->attacktype |= AT_MAGIC;
451 /* Spell doc describes what is going on here */ 494 /* Spell doc describes what is going on here */
452 tmp->stats.dam = op->dam_modifier; 495 tmp->stats.dam = op->dam_modifier;
453 tmp->range = op->stats.maxhp; 496 tmp->range = op->stats.maxhp;
454 tmp->duration = op->stats.hp; 497 tmp->duration = op->stats.hp;
455 /* Used for spell tracking - just need a unique val for this spell - 498 /* Used for spell tracking - just need a unique val for this spell -
456 * the count of the parent should work fine. 499 * the count of the parent should work fine.
457 */ 500 */
458 tmp->stats.maxhp = op->count; 501 tmp->stats.maxhp = op->count;
459 } 502 }
460 503
461 /* Set direction of cone explosion */ 504 /* Set direction of cone explosion */
462 if (tmp->type == SPELL_EFFECT && tmp->subtype == SP_CONE) 505 if (tmp->type == SPELL_EFFECT && tmp->subtype == SP_CONE)
463 tmp->stats.sp = op->direction; 506 tmp->stats.sp = op->direction;
464 507
465 /* Prevent recursion */ 508 /* Prevent recursion */
466 op->move_on = 0; 509 op->move_on = 0;
467 510
468 insert_ob_in_map(tmp, op->map, op, 0); 511 insert_ob_in_map (tmp, op->map, op, 0);
469 /* remove the firebullet */ 512 /* remove the firebullet */
470 if ( ! was_destroyed (op, op_tag)) { 513 if (!was_destroyed (op, op_tag))
514 {
471 remove_ob (op); 515 remove_ob (op);
472 free_object (op); 516 free_object (op);
473 } 517 }
474} 518}
475 519
476 520
477 521
478/* checks to see what op should do, given the space it is on 522/* checks to see what op should do, given the space it is on
479 * (eg, explode, damage player, etc) 523 * (eg, explode, damage player, etc)
480 */ 524 */
481 525
526void
482void check_bullet(object *op) 527check_bullet (object *op)
483{ 528{
484 tag_t op_tag = op->count, tmp_tag; 529 tag_t op_tag = op->count, tmp_tag;
485 object *tmp; 530 object *tmp;
486 int dam, mflags; 531 int dam, mflags;
487 mapstruct *m; 532 mapstruct *m;
488 sint16 sx, sy; 533 sint16 sx, sy;
489 534
490 mflags = get_map_flags(op->map,&m, op->x, op->y, &sx, &sy); 535 mflags = get_map_flags (op->map, &m, op->x, op->y, &sx, &sy);
491 536
492 if (!(mflags & P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy))) 537 if (!(mflags & P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))
493 return; 538 return;
494 539
495 if (op->other_arch) { 540 if (op->other_arch)
541 {
496 /* explode object will also remove op */ 542 /* explode object will also remove op */
497 explode_bullet (op); 543 explode_bullet (op);
498 return; 544 return;
499 } 545 }
500 546
501 /* If nothing alive on this space, no reason to do anything further */ 547 /* If nothing alive on this space, no reason to do anything further */
502 if (!(mflags & P_IS_ALIVE)) return; 548 if (!(mflags & P_IS_ALIVE))
549 return;
503 550
504 for (tmp = get_map_ob (op->map,op->x,op->y); tmp != NULL; tmp = tmp->above) 551 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above)
505 { 552 {
506 if (QUERY_FLAG (tmp, FLAG_ALIVE)) { 553 if (QUERY_FLAG (tmp, FLAG_ALIVE))
554 {
507 tmp_tag = tmp->count; 555 tmp_tag = tmp->count;
508 dam = hit_player (tmp, op->stats.dam, op, op->attacktype, 1); 556 dam = hit_player (tmp, op->stats.dam, op, op->attacktype, 1);
509 if (was_destroyed (op, op_tag) || ! was_destroyed (tmp, tmp_tag) 557 if (was_destroyed (op, op_tag) || !was_destroyed (tmp, tmp_tag) || (op->stats.dam -= dam) < 0)
510 || (op->stats.dam -= dam) < 0)
511 { 558 {
512 if(!QUERY_FLAG(op,FLAG_REMOVED)) { 559 if (!QUERY_FLAG (op, FLAG_REMOVED))
513 remove_ob (op); 560 {
514 free_object(op); 561 remove_ob (op);
515 return; 562 free_object (op);
516 } 563 return;
564 }
517 } 565 }
518 } 566 }
519 } 567 }
520} 568}
521 569
524 * call check_bullet. 572 * call check_bullet.
525 * This function is only applicable to bullets, but not to all 573 * This function is only applicable to bullets, but not to all
526 * fired arches (eg, bolts). 574 * fired arches (eg, bolts).
527 */ 575 */
528 576
577void
529void move_bullet(object *op) 578move_bullet (object *op)
530{ 579{
531 sint16 new_x, new_y; 580 sint16 new_x, new_y;
532 int mflags; 581 int mflags;
533 mapstruct *m; 582 mapstruct *m;
534 583
535#if 0 584#if 0
536 /* We need a better general purpose way to do this */ 585 /* We need a better general purpose way to do this */
537 586
538 /* peterm: added to make comet leave a trail of burnouts 587 /* peterm: added to make comet leave a trail of burnouts
539 it's an unadulterated hack, but the effect is cool. */ 588 it's an unadulterated hack, but the effect is cool. */
540 if(op->stats.sp == SP_METEOR) { 589 if (op->stats.sp == SP_METEOR)
590 {
541 replace_insert_ob_in_map("fire_trail",op); 591 replace_insert_ob_in_map ("fire_trail", op);
542 if (was_destroyed (op, op_tag)) 592 if (was_destroyed (op, op_tag))
543 return; 593 return;
544 } /* end addition. */ 594 } /* end addition. */
545#endif 595#endif
546 596
547 /* Reached the end of its life - remove it */ 597 /* Reached the end of its life - remove it */
548 if (--op->range <=0) { 598 if (--op->range <= 0)
599 {
549 if (op->other_arch) { 600 if (op->other_arch)
601 {
550 explode_bullet (op); 602 explode_bullet (op);
551 } else { 603 }
604 else
605 {
552 remove_ob (op); 606 remove_ob (op);
553 free_object (op); 607 free_object (op);
554 } 608 }
555 return; 609 return;
556 } 610 }
557 611
558 new_x = op->x + DIRX(op); 612 new_x = op->x + DIRX (op);
559 new_y = op->y + DIRY(op); 613 new_y = op->y + DIRY (op);
560 m = op->map; 614 m = op->map;
561 mflags = get_map_flags(m, &m, new_x, new_y, &new_x, &new_y); 615 mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y);
562 616
563 if (mflags & P_OUT_OF_MAP) { 617 if (mflags & P_OUT_OF_MAP)
618 {
564 remove_ob (op); 619 remove_ob (op);
565 free_object (op); 620 free_object (op);
566 return; 621 return;
567 } 622 }
568 623
569 if ( ! op->direction || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, new_x, new_y))) { 624 if (!op->direction || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y)))
625 {
570 if (op->other_arch) { 626 if (op->other_arch)
627 {
571 explode_bullet (op); 628 explode_bullet (op);
629 }
572 } else { 630 else
631 {
573 remove_ob (op); 632 remove_ob (op);
574 free_object (op); 633 free_object (op);
575 } 634 }
576 return; 635 return;
577 } 636 }
578 637
579 remove_ob (op); 638 remove_ob (op);
580 op->x = new_x; 639 op->x = new_x;
581 op->y = new_y; 640 op->y = new_y;
582 if ((op = insert_ob_in_map (op, m, op,0)) == NULL) 641 if ((op = insert_ob_in_map (op, m, op, 0)) == NULL)
583 return; 642 return;
584 643
585 if (reflwall (op->map, op->x, op->y, op)) { 644 if (reflwall (op->map, op->x, op->y, op))
645 {
586 op->direction = absdir (op->direction + 4); 646 op->direction = absdir (op->direction + 4);
587 update_turn_face (op); 647 update_turn_face (op);
588 } else { 648 }
649 else
650 {
589 check_bullet (op); 651 check_bullet (op);
590 } 652 }
591} 653}
592 654
593 655
594 656
600 * spob->attacktype. 662 * spob->attacktype.
601 * This function sets up the appropriate owner and skill 663 * This function sets up the appropriate owner and skill
602 * pointers. 664 * pointers.
603 */ 665 */
604 666
667int
605int fire_bullet(object *op,object *caster,int dir,object *spob) { 668fire_bullet (object *op, object *caster, int dir, object *spob)
669{
606 object *tmp=NULL; 670 object *tmp = NULL;
607 int mflags; 671 int mflags;
608 672
609 if (!spob->other_arch) 673 if (!spob->other_arch)
610 return 0; 674 return 0;
611 675
612 tmp=arch_to_object(spob->other_arch); 676 tmp = arch_to_object (spob->other_arch);
613 if(tmp==NULL) 677 if (tmp == NULL)
614 return 0; 678 return 0;
615 679
616 /* peterm: level dependency for bolts */ 680 /* peterm: level dependency for bolts */
617 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust(caster,spob); 681 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob);
618 tmp->attacktype = spob->attacktype; 682 tmp->attacktype = spob->attacktype;
619 if (spob->slaying) tmp->slaying = add_refcount(spob->slaying); 683 if (spob->slaying)
684 tmp->slaying = spob->slaying;
620 685
621 tmp->range = 50; 686 tmp->range = 50;
622 687
623 /* Need to store duration/range for the ball to use */ 688 /* Need to store duration/range for the ball to use */
624 tmp->stats.hp = spob->duration + SP_level_duration_adjust(caster,spob); 689 tmp->stats.hp = spob->duration + SP_level_duration_adjust (caster, spob);
625 tmp->stats.maxhp = spob->range + SP_level_range_adjust(caster,spob); 690 tmp->stats.maxhp = spob->range + SP_level_range_adjust (caster, spob);
626 tmp->dam_modifier = spob->stats.food + SP_level_dam_adjust(caster,spob); 691 tmp->dam_modifier = spob->stats.food + SP_level_dam_adjust (caster, spob);
627 692
628 tmp->direction=dir; 693 tmp->direction = dir;
629 if(QUERY_FLAG(tmp, FLAG_IS_TURNABLE)) 694 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
630 SET_ANIMATION(tmp, dir); 695 SET_ANIMATION (tmp, dir);
631 696
632 set_owner(tmp,op); 697 set_owner (tmp, op);
633 set_spell_skill(op, caster, spob, tmp); 698 set_spell_skill (op, caster, spob, tmp);
634 699
635 tmp->x=op->x + freearr_x[dir]; 700 tmp->x = op->x + freearr_x[dir];
636 tmp->y=op->y + freearr_y[dir]; 701 tmp->y = op->y + freearr_y[dir];
637 tmp->map = op->map; 702 tmp->map = op->map;
638 703
639 mflags = get_map_flags(tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); 704 mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y);
640 if (mflags & P_OUT_OF_MAP) { 705 if (mflags & P_OUT_OF_MAP)
706 {
641 free_object(tmp); 707 free_object (tmp);
642 return 0; 708 return 0;
643 } 709 }
644 if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) { 710 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y)))
711 {
645 if(!QUERY_FLAG(tmp, FLAG_REFLECTING)) { 712 if (!QUERY_FLAG (tmp, FLAG_REFLECTING))
713 {
646 free_object(tmp); 714 free_object (tmp);
647 return 0; 715 return 0;
648 } 716 }
649 tmp->x=op->x; 717 tmp->x = op->x;
650 tmp->y=op->y; 718 tmp->y = op->y;
651 tmp->direction=absdir(tmp->direction+4); 719 tmp->direction = absdir (tmp->direction + 4);
652 tmp->map = op->map; 720 tmp->map = op->map;
653 } 721 }
654 if ((tmp = insert_ob_in_map(tmp,tmp->map,op,0)) != NULL) { 722 if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL)
723 {
655 check_bullet (tmp); 724 check_bullet (tmp);
656 } 725 }
657 return 1; 726 return 1;
658} 727}
659 728
660 729
661 730
662 731
666 * 735 *
667 *****************************************************************************/ 736 *****************************************************************************/
668 737
669 738
670/* drops an object based on what is in the cone's "other_arch" */ 739/* drops an object based on what is in the cone's "other_arch" */
740void
671void cone_drop(object *op) { 741cone_drop (object *op)
742{
672 object *new_ob = arch_to_object(op->other_arch); 743 object *new_ob = arch_to_object (op->other_arch);
673 744
674 new_ob->x = op->x; 745 new_ob->x = op->x;
675 new_ob->y = op->y; 746 new_ob->y = op->y;
676 new_ob->level = op->level; 747 new_ob->level = op->level;
677 set_owner(new_ob,op->owner); 748 set_owner (new_ob, op->owner);
678 749
679 /* preserve skill ownership */ 750 /* preserve skill ownership */
680 if(op->skill && op->skill != new_ob->skill) { 751 if (op->skill && op->skill != new_ob->skill)
681 if (new_ob->skill) free_string(new_ob->skill);
682 new_ob->skill = add_refcount(op->skill);
683 } 752 {
753 new_ob->skill = op->skill;
754 }
684 insert_ob_in_map(new_ob,op->map,op,0); 755 insert_ob_in_map (new_ob, op->map, op, 0);
685 756
686} 757}
687 758
688/* move_cone: causes cone object 'op' to move a space/hit creatures */ 759/* move_cone: causes cone object 'op' to move a space/hit creatures */
689 760
761void
690void move_cone(object *op) { 762move_cone (object *op)
763{
691 int i; 764 int i;
692 tag_t tag; 765 tag_t tag;
693 766
694 /* if no map then hit_map will crash so just ignore object */ 767 /* if no map then hit_map will crash so just ignore object */
695 if (! op->map) { 768 if (!op->map)
696 LOG(llevError,"Tried to move_cone object %s without a map.\n", 769 {
697 op->name ? op->name : "unknown"); 770 LOG (llevError, "Tried to move_cone object %s without a map.\n", op->name ? &op->name : "unknown");
698 op->speed = 0; 771 op->speed = 0;
699 update_ob_speed (op); 772 update_ob_speed (op);
700 return; 773 return;
701 } 774 }
702 775
703 /* lava saves it's life, but not yours :) */ 776 /* lava saves it's life, but not yours :) */
704 if (QUERY_FLAG(op, FLAG_LIFESAVE)) { 777 if (QUERY_FLAG (op, FLAG_LIFESAVE))
778 {
705 hit_map(op,0,op->attacktype,0); 779 hit_map (op, 0, op->attacktype, 0);
706 return; 780 return;
707 } 781 }
708 782
709#if 0 783#if 0
710 /* Disable this - enabling it makes monsters easier, as 784 /* Disable this - enabling it makes monsters easier, as
711 * when their cone dies when they die. 785 * when their cone dies when they die.
712 */ 786 */
713 /* If no owner left, the spell dies out. */ 787 /* If no owner left, the spell dies out. */
714 if(get_owner(op)==NULL) { 788 if (get_owner (op) == NULL)
789 {
715 remove_ob(op); 790 remove_ob (op);
716 free_object(op); 791 free_object (op);
717 return; 792 return;
718 } 793 }
719#endif 794#endif
720 795
721 tag = op->count; 796 tag = op->count;
722 hit_map(op,0,op->attacktype,0); 797 hit_map (op, 0, op->attacktype, 0);
723 798
724 /* Check to see if we should push anything. 799 /* Check to see if we should push anything.
725 * Spell objects with weight push whatever they encounter to some 800 * Spell objects with weight push whatever they encounter to some
726 * degree. 801 * degree.
727 */ 802 */
803 if (op->weight)
728 if(op->weight) check_spell_knockback(op); 804 check_spell_knockback (op);
729 805
730 if (was_destroyed (op, tag)) 806 if (was_destroyed (op, tag))
807 return;
808
809 if ((op->duration--) < 0)
810 {
811 remove_ob (op);
812 free_object (op);
731 return; 813 return;
732
733 if((op->duration--)<0) {
734 remove_ob(op);
735 free_object(op);
736 return;
737 } 814 }
738 /* Object has hit maximum range, so don't have it move 815 /* Object has hit maximum range, so don't have it move
739 * any further. When the duration above expires, 816 * any further. When the duration above expires,
740 * then the object will get removed. 817 * then the object will get removed.
741 */ 818 */
742 if (--op->range < 0) { 819 if (--op->range < 0)
743 op->range=0; /* just so it doesn't wrap */
744 return;
745 } 820 {
821 op->range = 0; /* just so it doesn't wrap */
822 return;
823 }
746 824
747 for(i= -1;i<2;i++) { 825 for (i = -1; i < 2; i++)
748 sint16 x=op->x+freearr_x[absdir(op->stats.sp+i)], 826 {
749 y=op->y+freearr_y[absdir(op->stats.sp+i)]; 827 sint16 x = op->x + freearr_x[absdir (op->stats.sp + i)], y = op->y + freearr_y[absdir (op->stats.sp + i)];
750 828
751 if(ok_to_put_more(op->map,x,y,op,op->attacktype)) { 829 if (ok_to_put_more (op->map, x, y, op, op->attacktype))
830 {
752 object *tmp=get_object(); 831 object *tmp = get_object ();
832
753 copy_object(op, tmp); 833 copy_object (op, tmp);
754 tmp->x=x; 834 tmp->x = x;
755 tmp->y=y; 835 tmp->y = y;
756 836
757 tmp->duration = op->duration + 1; 837 tmp->duration = op->duration + 1;
758 838
759 /* Use for spell tracking - see ok_to_put_more() */ 839 /* Use for spell tracking - see ok_to_put_more() */
760 tmp->stats.maxhp = op->stats.maxhp; 840 tmp->stats.maxhp = op->stats.maxhp;
761 insert_ob_in_map(tmp,op->map,op,0); 841 insert_ob_in_map (tmp, op->map, op, 0);
762 if (tmp->other_arch) cone_drop(tmp); 842 if (tmp->other_arch)
763 } 843 cone_drop (tmp);
844 }
764 } 845 }
765} 846}
766 847
767/* cast_cone: casts a cone spell. 848/* cast_cone: casts a cone spell.
768 * op: person firing the object. 849 * op: person firing the object.
770 * dir: direction to fire in. 851 * dir: direction to fire in.
771 * spell: spell that is being fired. It uses other_arch for the archetype 852 * spell: spell that is being fired. It uses other_arch for the archetype
772 * to fire. 853 * to fire.
773 * returns 0 on failure, 1 on success. 854 * returns 0 on failure, 1 on success.
774 */ 855 */
856int
775int cast_cone(object *op, object *caster,int dir, object *spell) 857cast_cone (object *op, object *caster, int dir, object *spell)
776{ 858{
777 object *tmp; 859 object *tmp;
778 int i,success=0,range_min= -1,range_max=1; 860 int i, success = 0, range_min = -1, range_max = 1;
779 mapstruct *m; 861 mapstruct *m;
780 sint16 sx, sy; 862 sint16 sx, sy;
781 MoveType movetype; 863 MoveType movetype;
782 864
783 if (!spell->other_arch) return 0; 865 if (!spell->other_arch)
784
785 if (op->type == PLAYER && QUERY_FLAG(op, FLAG_UNDEAD) &&
786 op->attacktype & AT_TURN_UNDEAD) {
787 new_draw_info(NDI_UNIQUE, 0,op,
788 "Your undead nature prevents you from turning undead!");
789 return 0; 866 return 0;
867
868 if (op->type == PLAYER && QUERY_FLAG (op, FLAG_UNDEAD) && op->attacktype & AT_TURN_UNDEAD)
790 } 869 {
870 new_draw_info (NDI_UNIQUE, 0, op, "Your undead nature prevents you from turning undead!");
871 return 0;
872 }
791 873
792 if(!dir) { 874 if (!dir)
793 range_min= 0;
794 range_max=8;
795 } 875 {
876 range_min = 0;
877 range_max = 8;
878 }
796 879
797 /* Need to know what the movetype of the object we are about 880 /* Need to know what the movetype of the object we are about
798 * to create is, so we can know if the space we are about to 881 * to create is, so we can know if the space we are about to
799 * insert it into is blocked. 882 * insert it into is blocked.
800 */ 883 */
801 movetype = spell->other_arch->clone.move_type; 884 movetype = spell->other_arch->clone.move_type;
802 885
803 for(i=range_min;i<=range_max;i++) { 886 for (i = range_min; i <= range_max; i++)
887 {
804 sint16 x,y, d; 888 sint16 x, y, d;
805 889
806 /* We can't use absdir here, because it never returns 890 /* We can't use absdir here, because it never returns
807 * 0. If this is a rune, we want to hit the person on top 891 * 0. If this is a rune, we want to hit the person on top
808 * of the trap (d==0). If it is not a rune, then we don't want 892 * of the trap (d==0). If it is not a rune, then we don't want
809 * to hit that person. 893 * to hit that person.
810 */ 894 */
811 d = dir + i; 895 d = dir + i;
812 while (d < 0) d+=8; 896 while (d < 0)
813 while (d > 8) d-=8; 897 d += 8;
898 while (d > 8)
899 d -= 8;
814 900
815 /* If it's not a rune, we don't want to blast the caster. 901 /* If it's not a rune, we don't want to blast the caster.
816 * In that case, we have to see - if dir is specified, 902 * In that case, we have to see - if dir is specified,
817 * turn this into direction 8. If dir is not specified (all 903 * turn this into direction 8. If dir is not specified (all
818 * direction) skip - otherwise, one line would do more damage 904 * direction) skip - otherwise, one line would do more damage
819 * becase 0 direction will go through 9 directions - necessary 905 * becase 0 direction will go through 9 directions - necessary
820 * for the rune code. 906 * for the rune code.
821 */ 907 */
822 if (caster->type != RUNE && d==0) { 908 if (caster->type != RUNE && d == 0)
823 if (dir!=0) d=8; 909 {
824 else continue; 910 if (dir != 0)
825 } 911 d = 8;
912 else
913 continue;
914 }
826 915
827 x = op->x+freearr_x[d]; 916 x = op->x + freearr_x[d];
828 y = op->y+freearr_y[d]; 917 y = op->y + freearr_y[d];
829 918
830 if(get_map_flags(op->map, &m, x,y, &sx, &sy) & P_OUT_OF_MAP) 919 if (get_map_flags (op->map, &m, x, y, &sx, &sy) & P_OUT_OF_MAP)
831 continue; 920 continue;
832 921
833 if ((movetype & GET_MAP_MOVE_BLOCK(m, sx, sy)) == movetype) 922 if ((movetype & GET_MAP_MOVE_BLOCK (m, sx, sy)) == movetype)
834 continue; 923 continue;
835 924
836 success=1; 925 success = 1;
837 tmp=arch_to_object(spell->other_arch); 926 tmp = arch_to_object (spell->other_arch);
838 set_owner(tmp,op); 927 set_owner (tmp, op);
839 set_spell_skill(op, caster, spell, tmp); 928 set_spell_skill (op, caster, spell, tmp);
840 tmp->level = caster_level (caster, spell); 929 tmp->level = caster_level (caster, spell);
841 tmp->x = sx; 930 tmp->x = sx;
842 tmp->y = sy; 931 tmp->y = sy;
843 tmp->attacktype=spell->attacktype; 932 tmp->attacktype = spell->attacktype;
844 933
845 /* holy word stuff */ 934 /* holy word stuff */
846 if((tmp->attacktype & AT_HOLYWORD) || (tmp->attacktype & AT_GODPOWER)) { 935 if ((tmp->attacktype & AT_HOLYWORD) || (tmp->attacktype & AT_GODPOWER))
936 {
847 if(!tailor_god_spell(tmp,op)) return 0; 937 if (!tailor_god_spell (tmp, op))
848 } 938 return 0;
849 939 }
850 if(dir) 940
941 if (dir)
851 tmp->stats.sp=dir; 942 tmp->stats.sp = dir;
852 else 943 else
853 tmp->stats.sp=i; 944 tmp->stats.sp = i;
854 945
855 tmp->range=spell->range + SP_level_range_adjust(caster,spell); 946 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
856 947
857 /* If casting it in all directions, it doesn't go as far */ 948 /* If casting it in all directions, it doesn't go as far */
858 if (dir == 0) { 949 if (dir == 0)
950 {
859 tmp->range /= 4; 951 tmp->range /= 4;
860 if (tmp->range < 2 && spell->range >=2) tmp->range = 2; 952 if (tmp->range < 2 && spell->range >= 2)
861 } 953 tmp->range = 2;
954 }
862 tmp->stats.dam=spell->stats.dam + SP_level_dam_adjust(caster,spell); 955 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
863 tmp->duration=spell->duration + SP_level_duration_adjust(caster,spell); 956 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell);
864 957
865 /* Special bonus for fear attacks */ 958 /* Special bonus for fear attacks */
866 if (tmp->attacktype & AT_FEAR) { 959 if (tmp->attacktype & AT_FEAR)
867 if (caster->type == PLAYER) tmp->duration += fear_bonus[caster->stats.Cha]; 960 {
868 else 961 if (caster->type == PLAYER)
962 tmp->duration += fear_bonus[caster->stats.Cha];
963 else
869 tmp->duration += caster->level/3; 964 tmp->duration += caster->level / 3;
870 } 965 }
871 if (tmp->attacktype & (AT_HOLYWORD | AT_TURN_UNDEAD)) { 966 if (tmp->attacktype & (AT_HOLYWORD | AT_TURN_UNDEAD))
872 if (caster->type == PLAYER) tmp->duration += turn_bonus[caster->stats.Wis]/5; 967 {
873 else 968 if (caster->type == PLAYER)
969 tmp->duration += turn_bonus[caster->stats.Wis] / 5;
970 else
874 tmp->duration += caster->level/3; 971 tmp->duration += caster->level / 3;
875 } 972 }
876 973
877 974
878 if ( !(tmp->move_type & MOVE_FLY_LOW)) 975 if (!(tmp->move_type & MOVE_FLY_LOW))
879 LOG (llevDebug, "cast_cone(): arch %s doesn't have flying 1\n", 976 LOG (llevDebug, "cast_cone(): arch %s doesn't have flying 1\n", &spell->other_arch->name);
880 spell->other_arch->name);
881 977
882 if (!tmp->move_on && tmp->stats.dam) { 978 if (!tmp->move_on && tmp->stats.dam)
883 LOG (llevDebug, 979 {
884 "cast_cone(): arch %s doesn't have move_on set\n", 980 LOG (llevDebug, "cast_cone(): arch %s doesn't have move_on set\n", &spell->other_arch->name);
885 spell->other_arch->name); 981 }
886 }
887 insert_ob_in_map(tmp,m,op,0); 982 insert_ob_in_map (tmp, m, op, 0);
888 983
889 /* This is used for tracking spells so that one effect doesn't hit 984 /* This is used for tracking spells so that one effect doesn't hit
890 * a single space too many times. 985 * a single space too many times.
891 */ 986 */
892 tmp->stats.maxhp = tmp->count; 987 tmp->stats.maxhp = tmp->count;
893 988
894 if(tmp->other_arch) cone_drop(tmp); 989 if (tmp->other_arch)
990 cone_drop (tmp);
895 } 991 }
896 return success; 992 return success;
897} 993}
898 994
899/**************************************************************************** 995/****************************************************************************
900 * 996 *
901 * BOMB related code 997 * BOMB related code
904 1000
905 1001
906/* This handles an exploding bomb. 1002/* This handles an exploding bomb.
907 * op is the original bomb object. 1003 * op is the original bomb object.
908 */ 1004 */
1005void
909void animate_bomb(object *op) { 1006animate_bomb (object *op)
1007{
910 int i; 1008 int i;
911 object *env, *tmp; 1009 object *env, *tmp;
912 archetype *at; 1010 archetype *at;
913 1011
914 if(op->state!=NUM_ANIMATIONS(op)-1) 1012 if (op->state != NUM_ANIMATIONS (op) - 1)
915 return; 1013 return;
916 1014
917 1015
918 env = object_get_env_recursive(op); 1016 env = object_get_env_recursive (op);
919 1017
920 if (op->env) { 1018 if (op->env)
1019 {
921 if (env->map == NULL) 1020 if (env->map == NULL)
922 return;
923
924 if (env->type == PLAYER)
925 esrv_del_item(env->contr, op->count);
926
927 remove_ob(op);
928 op->x = env->x;
929 op->y = env->y;
930 if ((op = insert_ob_in_map (op, env->map, op,0)) == NULL)
931 return;
932 }
933
934 // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent bomb from exploding
935 // on a safe map. I don't like this special casing, but it seems to be neccessary
936 // as bombs can be carried.
937 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE)
938 {
939 remove_ob (op);
940 free_object (op);
941 return; 1021 return;
1022
1023 if (env->type == PLAYER)
1024 esrv_del_item (env->contr, op->count);
1025
1026 remove_ob (op);
1027 op->x = env->x;
1028 op->y = env->y;
1029 if ((op = insert_ob_in_map (op, env->map, op, 0)) == NULL)
1030 return;
942 } 1031 }
943 1032
1033 // elmex Tue Aug 15 17:46:51 CEST 2006: Prevent bomb from exploding
1034 // on a safe map. I don't like this special casing, but it seems to be neccessary
1035 // as bombs can be carried.
1036 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE)
1037 {
1038 remove_ob (op);
1039 free_object (op);
1040 return;
1041 }
1042
944 /* This copies a lot of the code from the fire bullet, 1043 /* This copies a lot of the code from the fire bullet,
945 * but using the cast_bullet isn't really feasible, 1044 * but using the cast_bullet isn't really feasible,
946 * so just set up the appropriate values. 1045 * so just set up the appropriate values.
947 */ 1046 */
948 at = find_archetype(SPLINT); 1047 at = find_archetype (SPLINT);
949 if (at) { 1048 if (at)
950 for(i=1;i<9;i++) { 1049 {
1050 for (i = 1; i < 9; i++)
1051 {
951 if (out_of_map(op->map, op->x + freearr_x[i], op->y + freearr_x[i])) 1052 if (out_of_map (op->map, op->x + freearr_x[i], op->y + freearr_x[i]))
952 continue; 1053 continue;
953 tmp = arch_to_object(at); 1054 tmp = arch_to_object (at);
954 tmp->direction = i; 1055 tmp->direction = i;
955 tmp->range = op->range; 1056 tmp->range = op->range;
956 tmp->stats.dam = op->stats.dam; 1057 tmp->stats.dam = op->stats.dam;
957 tmp->duration = op->duration; 1058 tmp->duration = op->duration;
958 tmp->attacktype = op->attacktype; 1059 tmp->attacktype = op->attacktype;
959 copy_owner (tmp, op); 1060 copy_owner (tmp, op);
960 if(op->skill && op->skill != tmp->skill) { 1061 if (op->skill && op->skill != tmp->skill)
961 if (tmp->skill) free_string(tmp->skill); 1062 {
962 tmp->skill = add_refcount(op->skill); 1063 tmp->skill = op->skill;
963 } 1064 }
964 if(QUERY_FLAG(tmp, FLAG_IS_TURNABLE)) 1065 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
965 SET_ANIMATION(tmp, i); 1066 SET_ANIMATION (tmp, i);
966 tmp->x = op->x + freearr_x[i]; 1067 tmp->x = op->x + freearr_x[i];
967 tmp->y = op->y + freearr_x[i]; 1068 tmp->y = op->y + freearr_x[i];
968 insert_ob_in_map(tmp, op->map, op, 0); 1069 insert_ob_in_map (tmp, op->map, op, 0);
969 move_bullet(tmp); 1070 move_bullet (tmp);
970 } 1071 }
971 } 1072 }
972 1073
973 explode_bullet(op); 1074 explode_bullet (op);
974} 1075}
975 1076
1077int
976int create_bomb(object *op,object *caster,int dir, object *spell) { 1078create_bomb (object *op, object *caster, int dir, object *spell)
1079{
977 1080
978 object *tmp; 1081 object *tmp;
979 int mflags; 1082 int mflags;
980 sint16 dx=op->x+freearr_x[dir], dy=op->y+freearr_y[dir]; 1083 sint16 dx = op->x + freearr_x[dir], dy = op->y + freearr_y[dir];
981 mapstruct *m; 1084 mapstruct *m;
982 1085
983 mflags = get_map_flags(op->map, &m, dx,dy, &dx,&dy); 1086 mflags = get_map_flags (op->map, &m, dx, dy, &dx, &dy);
984 if ((mflags & P_OUT_OF_MAP) || (GET_MAP_MOVE_BLOCK(m, dx, dy) & MOVE_WALK)) { 1087 if ((mflags & P_OUT_OF_MAP) || (GET_MAP_MOVE_BLOCK (m, dx, dy) & MOVE_WALK))
1088 {
985 new_draw_info(NDI_UNIQUE, 0,op,"There is something in the way."); 1089 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
986 return 0; 1090 return 0;
987 } 1091 }
988 tmp=arch_to_object(spell->other_arch); 1092 tmp = arch_to_object (spell->other_arch);
989 1093
990 /* level dependencies for bomb */ 1094 /* level dependencies for bomb */
991 tmp->range=spell->range + SP_level_range_adjust(caster,spell); 1095 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
992 tmp->stats.dam=spell->stats.dam + SP_level_dam_adjust(caster,spell); 1096 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
993 tmp->duration = spell->duration + SP_level_duration_adjust(caster,spell); 1097 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell);
994 tmp->attacktype = spell->attacktype; 1098 tmp->attacktype = spell->attacktype;
995 1099
996 set_owner(tmp,op); 1100 set_owner (tmp, op);
997 set_spell_skill(op, caster, spell, tmp); 1101 set_spell_skill (op, caster, spell, tmp);
998 tmp->x=dx; 1102 tmp->x = dx;
999 tmp->y=dy; 1103 tmp->y = dy;
1000 insert_ob_in_map(tmp,m,op,0); 1104 insert_ob_in_map (tmp, m, op, 0);
1001 return 1; 1105 return 1;
1002} 1106}
1003 1107
1004/**************************************************************************** 1108/****************************************************************************
1005 * 1109 *
1006 * smite related spell code. 1110 * smite related spell code.
1014 * dir is the direction to look in. 1118 * dir is the direction to look in.
1015 * range is how far out to look. 1119 * range is how far out to look.
1016 * type is the type of spell - either SPELL_MANA or SPELL_GRACE. 1120 * type is the type of spell - either SPELL_MANA or SPELL_GRACE.
1017 * this info is used for blocked magic/unholy spaces. 1121 * this info is used for blocked magic/unholy spaces.
1018 */ 1122 */
1019 1123
1124object *
1020object *get_pointed_target(object *op, int dir, int range, int type) { 1125get_pointed_target (object *op, int dir, int range, int type)
1126{
1021 object *target; 1127 object *target;
1022 sint16 x,y; 1128 sint16 x, y;
1023 int dist, mflags; 1129 int dist, mflags;
1024 mapstruct *mp; 1130 mapstruct *mp;
1025 1131
1026 if (dir==0) return NULL; 1132 if (dir == 0)
1027
1028 for (dist=1; dist<range; dist++) {
1029 x = op->x + freearr_x[dir] * dist;
1030 y = op->y + freearr_y[dir] * dist;
1031 mp = op->map;
1032 mflags = get_map_flags(op->map, &mp, x, y, &x, &y);
1033
1034 if (mflags & P_OUT_OF_MAP) return NULL;
1035 if ((type & SPELL_MANA) && (mflags & P_NO_MAGIC)) return NULL;
1036 if ((type & SPELL_GRACE) && (mflags & P_NO_CLERIC)) return NULL;
1037 if (GET_MAP_MOVE_BLOCK(mp, x, y) & MOVE_FLY_LOW) return NULL;
1038
1039 if (mflags & P_IS_ALIVE) {
1040 for(target=get_map_ob(mp,x,y); target; target=target->above) {
1041 if(QUERY_FLAG(target->head?target->head:target,FLAG_MONSTER)) {
1042 return target;
1043 }
1044 }
1045 }
1046 }
1047 return NULL; 1133 return NULL;
1134
1135 for (dist = 1; dist < range; dist++)
1136 {
1137 x = op->x + freearr_x[dir] * dist;
1138 y = op->y + freearr_y[dir] * dist;
1139 mp = op->map;
1140 mflags = get_map_flags (op->map, &mp, x, y, &x, &y);
1141
1142 if (mflags & P_OUT_OF_MAP)
1143 return NULL;
1144 if ((type & SPELL_MANA) && (mflags & P_NO_MAGIC))
1145 return NULL;
1146 if ((type & SPELL_GRACE) && (mflags & P_NO_CLERIC))
1147 return NULL;
1148 if (GET_MAP_MOVE_BLOCK (mp, x, y) & MOVE_FLY_LOW)
1149 return NULL;
1150
1151 if (mflags & P_IS_ALIVE)
1152 {
1153 for (target = get_map_ob (mp, x, y); target; target = target->above)
1154 {
1155 if (QUERY_FLAG (target->head ? target->head : target, FLAG_MONSTER))
1156 {
1157 return target;
1158 }
1159 }
1160 }
1161 }
1162 return NULL;
1048} 1163}
1049 1164
1050 1165
1051/* cast_smite_arch() - the priest points to a creature and causes 1166/* cast_smite_arch() - the priest points to a creature and causes
1052 * a 'godly curse' to decend. 1167 * a 'godly curse' to decend.
1055 * caster = object casting the spell. 1170 * caster = object casting the spell.
1056 * dir = direction being cast 1171 * dir = direction being cast
1057 * spell = spell object 1172 * spell = spell object
1058 */ 1173 */
1059 1174
1175int
1060int cast_smite_spell (object *op, object *caster,int dir, object *spell) { 1176cast_smite_spell (object *op, object *caster, int dir, object *spell)
1177{
1061 object *effect, *target; 1178 object *effect, *target;
1062 object *god = find_god(determine_god(op)); 1179 object *god = find_god (determine_god (op));
1063 int range; 1180 int range;
1064 1181
1065 range = spell->range + SP_level_range_adjust(caster,spell); 1182 range = spell->range + SP_level_range_adjust (caster, spell);
1066 target = get_pointed_target(op,dir, 50, spell->stats.grace?SPELL_GRACE:SPELL_MANA); 1183 target = get_pointed_target (op, dir, 50, spell->stats.grace ? SPELL_GRACE : SPELL_MANA);
1067 1184
1068 /* Bunch of conditions for casting this spell. Note that only 1185 /* Bunch of conditions for casting this spell. Note that only
1069 * require a god if this is a cleric spell (requires grace). 1186 * require a god if this is a cleric spell (requires grace).
1070 * This makes this spell much more general purpose - it can be used 1187 * This makes this spell much more general purpose - it can be used
1071 * by wizards also, which is good, because I think this is a very 1188 * by wizards also, which is good, because I think this is a very
1072 * interesting spell. 1189 * interesting spell.
1073 * if it is a cleric spell, you need a god, and the creature 1190 * if it is a cleric spell, you need a god, and the creature
1074 * can't be friendly to your god. 1191 * can't be friendly to your god.
1075 */ 1192 */
1076 1193
1077 if(!target || QUERY_FLAG(target,FLAG_REFL_SPELL) 1194 if (!target || QUERY_FLAG (target, FLAG_REFL_SPELL)
1078 ||(!god && spell->stats.grace) 1195 || (!god && spell->stats.grace)
1079 ||(target->title && god && !strcmp(target->title,god->name)) 1196 || (target->title && god && !strcmp (target->title, god->name)) || (target->race && god && strstr (target->race, god->race)))
1080 ||(target->race && god && strstr(target->race,god->race))) { 1197 {
1081 new_draw_info(NDI_UNIQUE,0,op,"Your request is unheeded."); 1198 new_draw_info (NDI_UNIQUE, 0, op, "Your request is unheeded.");
1082 return 0; 1199 return 0;
1083 } 1200 }
1084 1201
1085 if (spell->other_arch) 1202 if (spell->other_arch)
1086 effect = arch_to_object(spell->other_arch); 1203 effect = arch_to_object (spell->other_arch);
1087 else 1204 else
1088 return 0; 1205 return 0;
1089 1206
1090 /* tailor the effect by priest level and worshipped God */ 1207 /* tailor the effect by priest level and worshipped God */
1091 effect->level = caster_level (caster, spell); 1208 effect->level = caster_level (caster, spell);
1092 effect->attacktype = spell->attacktype; 1209 effect->attacktype = spell->attacktype;
1093 if (effect->attacktype & (AT_HOLYWORD | AT_GODPOWER)) { 1210 if (effect->attacktype & (AT_HOLYWORD | AT_GODPOWER))
1211 {
1094 if(tailor_god_spell(effect,op)) 1212 if (tailor_god_spell (effect, op))
1095 new_draw_info_format(NDI_UNIQUE,0,op, 1213 new_draw_info_format (NDI_UNIQUE, 0, op, "%s answers your call!", determine_god (op));
1096 "%s answers your call!",determine_god(op));
1097 else { 1214 else
1215 {
1098 new_draw_info(NDI_UNIQUE,0,op,"Your request is ignored."); 1216 new_draw_info (NDI_UNIQUE, 0, op, "Your request is ignored.");
1099 return 0; 1217 return 0;
1100 } 1218 }
1101 } 1219 }
1102 1220
1103 /* size of the area of destruction */ 1221 /* size of the area of destruction */
1104 effect->range=spell->range + 1222 effect->range = spell->range + SP_level_range_adjust (caster, spell);
1105 SP_level_range_adjust(caster,spell); 1223 effect->duration = spell->duration + SP_level_range_adjust (caster, spell);
1106 effect->duration=spell->duration +
1107 SP_level_range_adjust(caster,spell);
1108 1224
1109 if (effect->attacktype & AT_DEATH) { 1225 if (effect->attacktype & AT_DEATH)
1110 effect->level=spell->stats.dam + 1226 {
1111 SP_level_dam_adjust(caster,spell); 1227 effect->level = spell->stats.dam + SP_level_dam_adjust (caster, spell);
1112 1228
1113 /* casting death spells at undead isn't a good thing */ 1229 /* casting death spells at undead isn't a good thing */
1114 if QUERY_FLAG(target, FLAG_UNDEAD) { 1230 if QUERY_FLAG
1231 (target, FLAG_UNDEAD)
1232 {
1115 if(random_roll(0, 2, op, PREFER_LOW)) { 1233 if (random_roll (0, 2, op, PREFER_LOW))
1234 {
1116 new_draw_info(NDI_UNIQUE,0,op,"Idiot! Your spell boomerangs!"); 1235 new_draw_info (NDI_UNIQUE, 0, op, "Idiot! Your spell boomerangs!");
1117 effect->x=op->x; 1236 effect->x = op->x;
1118 effect->y=op->y; 1237 effect->y = op->y;
1119 } else { 1238 }
1120 new_draw_info_format(NDI_UNIQUE,0,op,"The %s looks stronger!", 1239 else
1121 query_name(target)); 1240 {
1241 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s looks stronger!", query_name (target));
1122 target->stats.hp = target->stats.maxhp*2; 1242 target->stats.hp = target->stats.maxhp * 2;
1123 free_object(effect); 1243 free_object (effect);
1124 return 0; 1244 return 0;
1245 }
1246 }
1125 } 1247 }
1126 } 1248 else
1127 } else { 1249 {
1128 /* how much woe to inflict :) */ 1250 /* how much woe to inflict :) */
1129 effect->stats.dam=spell->stats.dam + 1251 effect->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
1130 SP_level_dam_adjust(caster,spell);
1131 } 1252 }
1132 1253
1133 set_owner(effect,op); 1254 set_owner (effect, op);
1134 set_spell_skill(op, caster, spell, effect); 1255 set_spell_skill (op, caster, spell, effect);
1135 1256
1136 /* ok, tell it where to be, and insert! */ 1257 /* ok, tell it where to be, and insert! */
1137 effect->x=target->x; 1258 effect->x = target->x;
1138 effect->y=target->y; 1259 effect->y = target->y;
1139 insert_ob_in_map(effect,target->map,op,0); 1260 insert_ob_in_map (effect, target->map, op, 0);
1140 1261
1141 return 1; 1262 return 1;
1142} 1263}
1143 1264
1144 1265
1145/**************************************************************************** 1266/****************************************************************************
1146 * 1267 *
1148 * note that the fire_bullet is used to fire the missile. The 1269 * note that the fire_bullet is used to fire the missile. The
1149 * code here is just to move the missile. 1270 * code here is just to move the missile.
1150 ****************************************************************************/ 1271 ****************************************************************************/
1151 1272
1152/* op is a missile that needs to be moved */ 1273/* op is a missile that needs to be moved */
1274void
1153void move_missile(object *op) { 1275move_missile (object *op)
1276{
1154 int i, mflags; 1277 int i, mflags;
1155 object *owner; 1278 object *owner;
1156 sint16 new_x, new_y; 1279 sint16 new_x, new_y;
1157 mapstruct *m; 1280 mapstruct *m;
1158 1281
1159 if (op->range-- <=0) { 1282 if (op->range-- <= 0)
1160 remove_ob(op);
1161 free_object(op);
1162 return;
1163 } 1283 {
1284 remove_ob (op);
1285 free_object (op);
1286 return;
1287 }
1164 1288
1165 owner = get_owner(op); 1289 owner = get_owner (op);
1166#if 0 1290#if 0
1167 /* It'd make things nastier if this wasn't here - spells cast by 1291 /* It'd make things nastier if this wasn't here - spells cast by
1168 * monster that are then killed would continue to survive 1292 * monster that are then killed would continue to survive
1169 */ 1293 */
1170 if (owner == NULL) { 1294 if (owner == NULL)
1295 {
1171 remove_ob(op); 1296 remove_ob (op);
1172 free_object(op); 1297 free_object (op);
1173 return; 1298 return;
1174 } 1299 }
1175#endif 1300#endif
1176 1301
1177 new_x = op->x + DIRX(op); 1302 new_x = op->x + DIRX (op);
1178 new_y = op->y + DIRY(op); 1303 new_y = op->y + DIRY (op);
1179 1304
1180 mflags = get_map_flags(op->map, &m, new_x, new_y, &new_x, &new_y); 1305 mflags = get_map_flags (op->map, &m, new_x, new_y, &new_x, &new_y);
1181 1306
1182 if (!(mflags & P_OUT_OF_MAP) &&
1183 ((mflags & P_IS_ALIVE) || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, new_x, new_y)))) { 1307 if (!(mflags & P_OUT_OF_MAP) && ((mflags & P_IS_ALIVE) || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))))
1308 {
1184 tag_t tag = op->count; 1309 tag_t tag = op->count;
1310
1185 hit_map (op, op->direction, AT_MAGIC, 1); 1311 hit_map (op, op->direction, AT_MAGIC, 1);
1186 /* Basically, missile only hits one thing then goes away. 1312 /* Basically, missile only hits one thing then goes away.
1187 * we need to remove it if someone hasn't already done so. 1313 * we need to remove it if someone hasn't already done so.
1188 */ 1314 */
1189 if ( ! was_destroyed (op, tag)) { 1315 if (!was_destroyed (op, tag))
1316 {
1317 remove_ob (op);
1318 free_object (op);
1319 }
1320 return;
1321 }
1322
1190 remove_ob (op); 1323 remove_ob (op);
1191 free_object(op);
1192 }
1193 return;
1194 }
1195
1196 remove_ob(op);
1197 if ( ! op->direction || (mflags & P_OUT_OF_MAP)) { 1324 if (!op->direction || (mflags & P_OUT_OF_MAP))
1198 free_object(op);
1199 return;
1200 } 1325 {
1326 free_object (op);
1327 return;
1328 }
1201 op->x = new_x; 1329 op->x = new_x;
1202 op->y = new_y; 1330 op->y = new_y;
1203 op->map = m; 1331 op->map = m;
1204 i=spell_find_dir(op->map, op->x, op->y, get_owner(op)); 1332 i = spell_find_dir (op->map, op->x, op->y, get_owner (op));
1205 if(i > 0 && i != op->direction){ 1333 if (i > 0 && i != op->direction)
1334 {
1206 op->direction=i; 1335 op->direction = i;
1207 SET_ANIMATION(op, op->direction); 1336 SET_ANIMATION (op, op->direction);
1208 } 1337 }
1209 insert_ob_in_map(op,op->map,op,0); 1338 insert_ob_in_map (op, op->map, op, 0);
1210} 1339}
1211 1340
1212/**************************************************************************** 1341/****************************************************************************
1213 * Destruction 1342 * Destruction
1214 ****************************************************************************/ 1343 ****************************************************************************/
1344
1215/* make_object_glow() - currently only makes living objects glow. 1345/* make_object_glow() - currently only makes living objects glow.
1216 * we do this by creating a force and inserting it in the 1346 * we do this by creating a force and inserting it in the
1217 * object. if time is 0, the object glows permanently. To truely 1347 * object. if time is 0, the object glows permanently. To truely
1218 * make this work for non-living objects, we would have to 1348 * make this work for non-living objects, we would have to
1219 * give them the capability to have an inventory. b.t. 1349 * give them the capability to have an inventory. b.t.
1220 */ 1350 */
1221 1351
1352int
1222int make_object_glow(object *op, int radius, int time) { 1353make_object_glow (object *op, int radius, int time)
1354{
1223 object *tmp; 1355 object *tmp;
1224 1356
1225 /* some things are unaffected... */ 1357 /* some things are unaffected... */
1226 if(op->path_denied&PATH_LIGHT) 1358 if (op->path_denied & PATH_LIGHT)
1227 return 0; 1359 return 0;
1228 1360
1229 tmp=get_archetype(FORCE_NAME); 1361 tmp = get_archetype (FORCE_NAME);
1230 tmp->speed = 0.01; 1362 tmp->speed = 0.01;
1231 tmp->stats.food = time; 1363 tmp->stats.food = time;
1232 SET_FLAG(tmp, FLAG_IS_USED_UP); 1364 SET_FLAG (tmp, FLAG_IS_USED_UP);
1233 tmp->glow_radius=radius; 1365 tmp->glow_radius = radius;
1234 if (tmp->glow_radius > MAX_LIGHT_RADII) 1366 if (tmp->glow_radius > MAX_LIGHT_RADII)
1235 tmp->glow_radius = MAX_LIGHT_RADII; 1367 tmp->glow_radius = MAX_LIGHT_RADII;
1236 1368
1237 tmp->x=op->x; 1369 tmp->x = op->x;
1238 tmp->y=op->y; 1370 tmp->y = op->y;
1239 if(tmp->speed<MIN_ACTIVE_SPEED) tmp->speed = MIN_ACTIVE_SPEED; /* safety */ 1371 if (tmp->speed < MIN_ACTIVE_SPEED)
1372 tmp->speed = MIN_ACTIVE_SPEED; /* safety */
1240 tmp=insert_ob_in_ob(tmp,op); 1373 tmp = insert_ob_in_ob (tmp, op);
1241 if (tmp->glow_radius > op->glow_radius) 1374 if (tmp->glow_radius > op->glow_radius)
1242 op->glow_radius = tmp->glow_radius; 1375 op->glow_radius = tmp->glow_radius;
1243 1376
1244 if(!tmp->env||op!=tmp->env) { 1377 if (!tmp->env || op != tmp->env)
1378 {
1245 LOG(llevError,"make_object_glow() failed to insert glowing force in %s\n", 1379 LOG (llevError, "make_object_glow() failed to insert glowing force in %s\n", &op->name);
1246 op->name); 1380 return 0;
1247 return 0;
1248 } 1381 }
1249 return 1; 1382 return 1;
1250} 1383}
1251 1384
1252 1385
1253
1254 1386
1387
1388int
1255int cast_destruction(object *op, object *caster, object *spell_ob) { 1389cast_destruction (object *op, object *caster, object *spell_ob)
1390{
1256 int i,j, range, mflags, friendly=0, dam, dur; 1391 int i, j, range, mflags, friendly = 0, dam, dur;
1257 sint16 sx,sy; 1392 sint16 sx, sy;
1258 mapstruct *m; 1393 mapstruct *m;
1259 object *tmp; 1394 object *tmp;
1260 const char *skill; 1395 const char *skill;
1261 1396
1262 range = spell_ob->range + SP_level_range_adjust(caster, spell_ob); 1397 range = spell_ob->range + SP_level_range_adjust (caster, spell_ob);
1263 dam = spell_ob->stats.dam + SP_level_dam_adjust(caster, spell_ob); 1398 dam = spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob);
1264 dur = spell_ob->duration + SP_level_duration_adjust(caster, spell_ob); 1399 dur = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob);
1265 if (QUERY_FLAG(op, FLAG_FRIENDLY) || op->type == PLAYER) friendly=1; 1400 if (QUERY_FLAG (op, FLAG_FRIENDLY) || op->type == PLAYER)
1401 friendly = 1;
1266 1402
1267 /* destruction doesn't use another spell object, so we need 1403 /* destruction doesn't use another spell object, so we need
1268 * update op's skill pointer so that exp is properly awarded. 1404 * update op's skill pointer so that exp is properly awarded.
1269 * We do some shortcuts here - since this is just temporary 1405 * We do some shortcuts here - since this is just temporary
1270 * and we'll reset the values back, we don't need to go through 1406 * and we'll reset the values back, we don't need to go through
1271 * the full share string/free_string route. 1407 * the full share string/free_string route.
1272 */ 1408 */
1273 skill = op->skill; 1409 skill = op->skill;
1410 if (caster == op)
1274 if (caster == op) op->skill = spell_ob->skill; 1411 op->skill = spell_ob->skill;
1275 else if (caster->skill) op->skill = caster->skill; 1412 else if (caster->skill)
1413 op->skill = caster->skill;
1414 else
1276 else op->skill = NULL; 1415 op->skill = NULL;
1277 1416
1278 change_skill(op, find_skill_by_name(op, op->skill), 1); 1417 change_skill (op, find_skill_by_name (op, op->skill), 1);
1279 1418
1280 for(i= -range; i<range; i++) { 1419 for (i = -range; i < range; i++)
1420 {
1281 for(j=-range; j<range ; j++) { 1421 for (j = -range; j < range; j++)
1422 {
1282 m = op->map; 1423 m = op->map;
1283 sx = op->x + i; 1424 sx = op->x + i;
1284 sy = op->y + j; 1425 sy = op->y + j;
1285 mflags = get_map_flags(m, &m, sx, sy, &sx, &sy); 1426 mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
1286 if (mflags & P_OUT_OF_MAP) continue; 1427 if (mflags & P_OUT_OF_MAP)
1428 continue;
1287 if (mflags & P_IS_ALIVE) { 1429 if (mflags & P_IS_ALIVE)
1430 {
1288 for (tmp=get_map_ob(m, sx, sy); tmp; tmp=tmp->above) { 1431 for (tmp = get_map_ob (m, sx, sy); tmp; tmp = tmp->above)
1432 {
1289 if (QUERY_FLAG(tmp, FLAG_ALIVE) || tmp->type==PLAYER) break; 1433 if (QUERY_FLAG (tmp, FLAG_ALIVE) || tmp->type == PLAYER)
1290 } 1434 break;
1291 if (tmp) { 1435 }
1292 if (tmp->head) tmp=tmp->head; 1436 if (tmp)
1437 {
1438 if (tmp->head)
1439 tmp = tmp->head;
1293 1440
1294 if ((friendly && !QUERY_FLAG(tmp, FLAG_FRIENDLY) && tmp->type!=PLAYER) || 1441 if ((friendly && !QUERY_FLAG (tmp, FLAG_FRIENDLY) && tmp->type != PLAYER) ||
1295 (!friendly && (QUERY_FLAG(tmp, FLAG_FRIENDLY) || tmp->type==PLAYER))) { 1442 (!friendly && (QUERY_FLAG (tmp, FLAG_FRIENDLY) || tmp->type == PLAYER)))
1296 if (spell_ob->subtype == SP_DESTRUCTION) { 1443 {
1444 if (spell_ob->subtype == SP_DESTRUCTION)
1445 {
1297 hit_player(tmp,dam,op,spell_ob->attacktype,0); 1446 hit_player (tmp, dam, op, spell_ob->attacktype, 0);
1298 if (spell_ob->other_arch) { 1447 if (spell_ob->other_arch)
1299 tmp = arch_to_object(spell_ob->other_arch); 1448 {
1300 tmp->x = sx; 1449 tmp = arch_to_object (spell_ob->other_arch);
1301 tmp->y = sy; 1450 tmp->x = sx;
1302 insert_ob_in_map(tmp, m, op, 0); 1451 tmp->y = sy;
1303 } 1452 insert_ob_in_map (tmp, m, op, 0);
1304 } 1453 }
1305 else if (spell_ob->subtype == SP_FAERY_FIRE && 1454 }
1306 tmp->resist[ATNR_MAGIC]!=100) { 1455 else if (spell_ob->subtype == SP_FAERY_FIRE && tmp->resist[ATNR_MAGIC] != 100)
1456 {
1307 if (make_object_glow(tmp, 1, dur) && spell_ob->other_arch) { 1457 if (make_object_glow (tmp, 1, dur) && spell_ob->other_arch)
1458 {
1308 object *effect = arch_to_object(spell_ob->other_arch); 1459 object *effect = arch_to_object (spell_ob->other_arch);
1309 effect->x = sx; 1460
1310 effect->y = sy; 1461 effect->x = sx;
1311 insert_ob_in_map(effect, m, op, 0); 1462 effect->y = sy;
1312 } 1463 insert_ob_in_map (effect, m, op, 0);
1313 } 1464 }
1314 } 1465 }
1315 } 1466 }
1467 }
1468 }
1469 }
1316 } 1470 }
1317 }
1318 }
1319 op->skill = skill; 1471 op->skill = skill;
1320 return 1; 1472 return 1;
1321} 1473}
1322 1474
1323/*************************************************************************** 1475/***************************************************************************
1324 * 1476 *
1325 * CURSE 1477 * CURSE
1326 * 1478 *
1327 ***************************************************************************/ 1479 ***************************************************************************/
1328 1480
1481int
1329int cast_curse(object *op, object *caster, object *spell_ob, int dir) { 1482cast_curse (object *op, object *caster, object *spell_ob, int dir)
1483{
1330 object *god = find_god(determine_god(op)); 1484 object *god = find_god (determine_god (op));
1331 object *tmp, *force; 1485 object *tmp, *force;
1332 1486
1333 tmp = get_pointed_target(op, (dir==0)?op->direction:dir, 1487 tmp = get_pointed_target (op, (dir == 0) ? op->direction : dir, spell_ob->range, SPELL_GRACE);
1334 spell_ob->range, SPELL_GRACE);
1335 if (!tmp) { 1488 if (!tmp)
1336 new_draw_info(NDI_UNIQUE, 0, op,
1337 "There is no one in that direction to curse.");
1338 return 0;
1339 } 1489 {
1490 new_draw_info (NDI_UNIQUE, 0, op, "There is no one in that direction to curse.");
1491 return 0;
1492 }
1340 1493
1341 /* If we've already got a force of this type, don't add a new one. */ 1494 /* If we've already got a force of this type, don't add a new one. */
1342 for(force=tmp->inv; force!=NULL; force=force->below) { 1495 for (force = tmp->inv; force != NULL; force = force->below)
1496 {
1343 if (force->type==FORCE && force->subtype == FORCE_CHANGE_ABILITY) { 1497 if (force->type == FORCE && force->subtype == FORCE_CHANGE_ABILITY)
1498 {
1344 if (force->name == spell_ob->name) { 1499 if (force->name == spell_ob->name)
1345 break; 1500 {
1346 } 1501 break;
1502 }
1347 else if (spell_ob->race && spell_ob->race == force->name) { 1503 else if (spell_ob->race && spell_ob->race == force->name)
1348 new_draw_info_format(NDI_UNIQUE, 0, op, 1504 {
1349 "You can not cast %s while %s is in effect", 1505 new_draw_info_format (NDI_UNIQUE, 0, op, "You can not cast %s while %s is in effect", &spell_ob->name, &force->name_pl);
1350 spell_ob->name, force->name_pl); 1506 return 0;
1351 return 0; 1507 }
1508 }
1352 } 1509 }
1353 }
1354 }
1355 1510
1356 if(force==NULL) { 1511 if (force == NULL)
1512 {
1357 force=get_archetype(FORCE_NAME); 1513 force = get_archetype (FORCE_NAME);
1358 force->subtype = FORCE_CHANGE_ABILITY; 1514 force->subtype = FORCE_CHANGE_ABILITY;
1359 free_string(force->name);
1360 if (spell_ob->race) 1515 if (spell_ob->race)
1361 force->name = add_refcount(spell_ob->race); 1516 force->name = spell_ob->race;
1362 else
1363 force->name = add_refcount(spell_ob->name);
1364 free_string(force->name_pl);
1365 force->name_pl = add_refcount(spell_ob->name);
1366
1367 } else { 1517 else
1518 force->name = spell_ob->name;
1519
1520 force->name_pl = spell_ob->name;
1521
1522 }
1523 else
1524 {
1368 int duration; 1525 int duration;
1369 1526
1370 duration = spell_ob->duration + SP_level_duration_adjust(caster, spell_ob) * 50; 1527 duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob) * 50;
1371 if (duration > force->duration) { 1528 if (duration > force->duration)
1529 {
1372 force->duration = duration; 1530 force->duration = duration;
1373 new_draw_info(NDI_UNIQUE, 0, op, "You recast the spell while in effect."); 1531 new_draw_info (NDI_UNIQUE, 0, op, "You recast the spell while in effect.");
1374 } else { 1532 }
1533 else
1534 {
1375 new_draw_info(NDI_UNIQUE, 0, op, "Recasting the spell had no effect."); 1535 new_draw_info (NDI_UNIQUE, 0, op, "Recasting the spell had no effect.");
1376 } 1536 }
1377 return 1; 1537 return 1;
1378 } 1538 }
1379 force->duration = spell_ob->duration + SP_level_duration_adjust(caster, spell_ob) * 50; 1539 force->duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob) * 50;
1380 force->speed = 1.0; 1540 force->speed = 1.0;
1381 force->speed_left = -1.0; 1541 force->speed_left = -1.0;
1382 SET_FLAG(force, FLAG_APPLIED); 1542 SET_FLAG (force, FLAG_APPLIED);
1383 1543
1384 if(god) { 1544 if (god)
1545 {
1385 if (spell_ob->last_grace) 1546 if (spell_ob->last_grace)
1386 force->path_repelled=god->path_repelled; 1547 force->path_repelled = god->path_repelled;
1387 if (spell_ob->last_grace) 1548 if (spell_ob->last_grace)
1388 force->path_denied=god->path_denied; 1549 force->path_denied = god->path_denied;
1389 new_draw_info_format(NDI_UNIQUE, 0,tmp, 1550 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are a victim of %s's curse!", &god->name);
1390 "You are a victim of %s's curse!",god->name); 1551 }
1391 } else 1552 else
1392 new_draw_info(NDI_UNIQUE, 0,op,"Your curse seems empty."); 1553 new_draw_info (NDI_UNIQUE, 0, op, "Your curse seems empty.");
1393 1554
1394 1555
1395 if(tmp!=op && op->type==PLAYER) 1556 if (tmp != op && op->type == PLAYER)
1396 new_draw_info_format(NDI_UNIQUE, 0, op, "You curse %s!",tmp->name); 1557 new_draw_info_format (NDI_UNIQUE, 0, op, "You curse %s!", &tmp->name);
1397 1558
1398 force->stats.ac = spell_ob->stats.ac; 1559 force->stats.ac = spell_ob->stats.ac;
1399 force->stats.wc = spell_ob->stats.wc; 1560 force->stats.wc = spell_ob->stats.wc;
1400 1561
1401 change_abil(tmp,force); /* Mostly to display any messages */ 1562 change_abil (tmp, force); /* Mostly to display any messages */
1402 insert_ob_in_ob(force,tmp); 1563 insert_ob_in_ob (force, tmp);
1403 fix_player(tmp); 1564 fix_player (tmp);
1404 return 1; 1565 return 1;
1405 1566
1406} 1567}
1407 1568
1408 1569
1409/********************************************************************** 1570/**********************************************************************
1413 ***********************************************************************/ 1574 ***********************************************************************/
1414 1575
1415/* This covers the various spells that change the moods of monsters - 1576/* This covers the various spells that change the moods of monsters -
1416 * makes them angry, peacful, friendly, etc. 1577 * makes them angry, peacful, friendly, etc.
1417 */ 1578 */
1579int
1418int mood_change(object *op, object *caster, object *spell) { 1580mood_change (object *op, object *caster, object *spell)
1581{
1419 object *tmp, *god, *head; 1582 object *tmp, *god, *head;
1420 int done_one, range, mflags, level, at, best_at; 1583 int done_one, range, mflags, level, at, best_at;
1421 sint16 x, y, nx, ny; 1584 sint16 x, y, nx, ny;
1422 mapstruct *m; 1585 mapstruct *m;
1423 const char *race; 1586 const char *race;
1424 1587
1425 /* We precompute some values here so that we don't have to keep 1588 /* We precompute some values here so that we don't have to keep
1426 * doing it over and over again. 1589 * doing it over and over again.
1427 */ 1590 */
1428 god=find_god(determine_god(op)); 1591 god = find_god (determine_god (op));
1429 level=caster_level(caster, spell); 1592 level = caster_level (caster, spell);
1430 range = spell->range + SP_level_range_adjust(caster, spell); 1593 range = spell->range + SP_level_range_adjust (caster, spell);
1431 1594
1432 /* On the bright side, no monster should ever have a race of GOD_... 1595 /* On the bright side, no monster should ever have a race of GOD_...
1433 * so even if the player doesn't worship a god, if race=GOD_.., it 1596 * so even if the player doesn't worship a god, if race=GOD_.., it
1434 * won't ever match anything. 1597 * won't ever match anything.
1435 */ 1598 */
1436 if (!spell->race) race=NULL; 1599 if (!spell->race)
1600 race = NULL;
1437 else if (god && !strcmp(spell->race, "GOD_SLAYING")) race = god->slaying; 1601 else if (god && !strcmp (spell->race, "GOD_SLAYING"))
1602 race = god->slaying;
1438 else if (god && !strcmp(spell->race, "GOD_FRIEND")) race = god->race; 1603 else if (god && !strcmp (spell->race, "GOD_FRIEND"))
1604 race = god->race;
1605 else
1439 else race = spell->race; 1606 race = spell->race;
1440
1441 1607
1608
1442 for (x = op->x - range; x <= op->x + range; x++) 1609 for (x = op->x - range; x <= op->x + range; x++)
1443 for (y = op->y - range; y <= op->y + range; y++) { 1610 for (y = op->y - range; y <= op->y + range; y++)
1611 {
1444 1612
1445 done_one=0; 1613 done_one = 0;
1446 m = op->map; 1614 m = op->map;
1447 nx = x; 1615 nx = x;
1448 ny = y; 1616 ny = y;
1449 mflags = get_map_flags(m, &m, x, y, &nx, &ny); 1617 mflags = get_map_flags (m, &m, x, y, &nx, &ny);
1450 if (mflags & P_OUT_OF_MAP) continue; 1618 if (mflags & P_OUT_OF_MAP)
1619 continue;
1451 1620
1452 /* If there is nothing living on this space, no need to go further */ 1621 /* If there is nothing living on this space, no need to go further */
1453 if (!(mflags & P_IS_ALIVE)) continue; 1622 if (!(mflags & P_IS_ALIVE))
1623 continue;
1454 1624
1455 for (tmp = get_map_ob(m, nx, ny); tmp; tmp = tmp->above) 1625 for (tmp = get_map_ob (m, nx, ny); tmp; tmp = tmp->above)
1456 if (QUERY_FLAG(tmp, FLAG_MONSTER)) break; 1626 if (QUERY_FLAG (tmp, FLAG_MONSTER))
1627 break;
1457 1628
1458 /* There can be living objects that are not monsters */ 1629 /* There can be living objects that are not monsters */
1459 if (!tmp || tmp->type==PLAYER) continue; 1630 if (!tmp || tmp->type == PLAYER)
1631 continue;
1460 1632
1461 /* Only the head has meaningful data, so resolve to that */ 1633 /* Only the head has meaningful data, so resolve to that */
1462 if (tmp->head) head=tmp->head; 1634 if (tmp->head)
1463 else head=tmp; 1635 head = tmp->head;
1636 else
1637 head = tmp;
1464 1638
1465 /* Make sure the race is OK. Likewise, only effect undead if spell specifically allows it */ 1639 /* Make sure the race is OK. Likewise, only effect undead if spell specifically allows it */
1466 if (race && head->race && !strstr(race, head->race)) continue; 1640 if (race && head->race && !strstr (race, head->race))
1641 continue;
1467 if (QUERY_FLAG(head, FLAG_UNDEAD) && !QUERY_FLAG(spell, FLAG_UNDEAD)) continue; 1642 if (QUERY_FLAG (head, FLAG_UNDEAD) && !QUERY_FLAG (spell, FLAG_UNDEAD))
1643 continue;
1468 1644
1469 /* Now do a bunch of stuff related to saving throws */ 1645 /* Now do a bunch of stuff related to saving throws */
1470 best_at = -1; 1646 best_at = -1;
1471 if (spell->attacktype) { 1647 if (spell->attacktype)
1648 {
1472 for (at=0; at < NROFATTACKS; at++) 1649 for (at = 0; at < NROFATTACKS; at++)
1473 if (spell->attacktype & (1 << at)) 1650 if (spell->attacktype & (1 << at))
1474 if (best_at == -1 || head->resist[at] > head->resist[best_at]) best_at = at; 1651 if (best_at == -1 || head->resist[at] > head->resist[best_at])
1652 best_at = at;
1475 1653
1476 if (best_at == -1) at=0; 1654 if (best_at == -1)
1655 at = 0;
1477 else { 1656 else
1657 {
1478 if (head->resist[best_at] == 100) continue; 1658 if (head->resist[best_at] == 100)
1479 else at = head->resist[best_at] / 5; 1659 continue;
1480 } 1660 else
1661 at = head->resist[best_at] / 5;
1662 }
1481 at -= level / 5; 1663 at -= level / 5;
1482 if (did_make_save(head, head->level, at)) continue; 1664 if (did_make_save (head, head->level, at))
1483 } 1665 continue;
1666 }
1484 else /* spell->attacktype */ 1667 else /* spell->attacktype */
1485 /* 1668 /*
1486 Spell has no attacktype (charm & such), so we'll have a specific saving: 1669 Spell has no attacktype (charm & such), so we'll have a specific saving:
1487 * if spell level < monster level, no go 1670 * if spell level < monster level, no go
1488 * else, chance of effect = 20 + min( 50, 2 * ( spell level - monster level ) ) 1671 * else, chance of effect = 20 + min( 50, 2 * ( spell level - monster level ) )
1489 1672
1490 The chance will then be in the range [20-70] percent, not too bad. 1673 The chance will then be in the range [20-70] percent, not too bad.
1491 1674
1492 This is required to fix the 'charm monster' abuse, where a player level 1 can 1675 This is required to fix the 'charm monster' abuse, where a player level 1 can
1493 charm a level 125 monster... 1676 charm a level 125 monster...
1494 1677
1495 Ryo, august 14th 1678 Ryo, august 14th
1496 */ 1679 */
1497 { 1680 {
1498 if ( head->level > level ) continue; 1681 if (head->level > level)
1682 continue;
1499 if ( random_roll( 0, 100, caster, PREFER_LOW ) >= ( 20 + MIN( 50, 2 * ( level - head->level ) ) ) ) 1683 if (random_roll (0, 100, caster, PREFER_LOW) >= (20 + MIN (50, 2 * (level - head->level))))
1500 /* Failed, no effect */ 1684 /* Failed, no effect */
1501 continue; 1685 continue;
1502 } 1686 }
1503 1687
1504 /* Done with saving throw. Now start effecting the monster */ 1688 /* Done with saving throw. Now start effecting the monster */
1505 1689
1506 /* aggravation */ 1690 /* aggravation */
1507 if (QUERY_FLAG(spell, FLAG_MONSTER)) { 1691 if (QUERY_FLAG (spell, FLAG_MONSTER))
1692 {
1508 CLEAR_FLAG(head, FLAG_SLEEP); 1693 CLEAR_FLAG (head, FLAG_SLEEP);
1509 if (QUERY_FLAG(head, FLAG_FRIENDLY)) 1694 if (QUERY_FLAG (head, FLAG_FRIENDLY))
1510 remove_friendly_object(head); 1695 remove_friendly_object (head);
1511 1696
1512 done_one = 1; 1697 done_one = 1;
1513 head->enemy = op; 1698 head->enemy = op;
1514 } 1699 }
1515 1700
1516 /* calm monsters */ 1701 /* calm monsters */
1517 if (QUERY_FLAG(spell, FLAG_UNAGGRESSIVE) && !QUERY_FLAG(head, FLAG_UNAGGRESSIVE)) { 1702 if (QUERY_FLAG (spell, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (head, FLAG_UNAGGRESSIVE))
1703 {
1518 SET_FLAG(head, FLAG_UNAGGRESSIVE); 1704 SET_FLAG (head, FLAG_UNAGGRESSIVE);
1519 head->enemy = NULL; 1705 head->enemy = NULL;
1520 done_one = 1; 1706 done_one = 1;
1521 } 1707 }
1522 1708
1523 /* berserk monsters */ 1709 /* berserk monsters */
1524 if (QUERY_FLAG(spell, FLAG_BERSERK) && !QUERY_FLAG(head, FLAG_BERSERK)) { 1710 if (QUERY_FLAG (spell, FLAG_BERSERK) && !QUERY_FLAG (head, FLAG_BERSERK))
1711 {
1525 SET_FLAG(head, FLAG_BERSERK); 1712 SET_FLAG (head, FLAG_BERSERK);
1526 done_one = 1; 1713 done_one = 1;
1527 } 1714 }
1528 /* charm */ 1715 /* charm */
1529 if (QUERY_FLAG(spell, FLAG_NO_ATTACK) && !QUERY_FLAG(head, FLAG_FRIENDLY)) { 1716 if (QUERY_FLAG (spell, FLAG_NO_ATTACK) && !QUERY_FLAG (head, FLAG_FRIENDLY))
1717 {
1530 SET_FLAG(head, FLAG_FRIENDLY); 1718 SET_FLAG (head, FLAG_FRIENDLY);
1531 /* Prevent uncontolled outbreaks of self replicating monsters. 1719 /* Prevent uncontolled outbreaks of self replicating monsters.
1532 Typical use case is charm, go somwhere, use aggravation to make hostile. 1720 Typical use case is charm, go somwhere, use aggravation to make hostile.
1533 This could lead to fun stuff like mice outbreak in bigworld and server crawl. */ 1721 This could lead to fun stuff like mice outbreak in bigworld and server crawl. */
1534 CLEAR_FLAG(head, FLAG_GENERATOR); 1722 CLEAR_FLAG (head, FLAG_GENERATOR);
1535 set_owner(head, op); 1723 set_owner (head, op);
1536 set_spell_skill(op, caster, spell, head); 1724 set_spell_skill (op, caster, spell, head);
1537 add_friendly_object(head); 1725 add_friendly_object (head);
1538 head->attack_movement = PETMOVE; 1726 head->attack_movement = PETMOVE;
1539 done_one = 1; 1727 done_one = 1;
1540 change_exp(op, head->stats.exp / 2, head->skill, SK_EXP_ADD_SKILL); 1728 change_exp (op, head->stats.exp / 2, head->skill, SK_EXP_ADD_SKILL);
1541 head->stats.exp = 0; 1729 head->stats.exp = 0;
1542 } 1730 }
1543 1731
1544 /* If a monster was effected, put an effect in */ 1732 /* If a monster was effected, put an effect in */
1545 if (done_one && spell->other_arch) { 1733 if (done_one && spell->other_arch)
1734 {
1546 tmp = arch_to_object(spell->other_arch); 1735 tmp = arch_to_object (spell->other_arch);
1547 tmp->x = nx; 1736 tmp->x = nx;
1548 tmp->y = ny; 1737 tmp->y = ny;
1549 insert_ob_in_map(tmp, m, op, 0); 1738 insert_ob_in_map (tmp, m, op, 0);
1550 } 1739 }
1551 } /* for y */ 1740 } /* for y */
1552 1741
1553 return 1; 1742 return 1;
1554} 1743}
1555 1744
1556 1745
1557/* Move_ball_spell: This handles ball type spells that just sort of wander 1746/* Move_ball_spell: This handles ball type spells that just sort of wander
1558 * about. was called move_ball_lightning, but since more than the ball 1747 * about. was called move_ball_lightning, but since more than the ball
1559 * lightning spell used it, that seemed misnamed. 1748 * lightning spell used it, that seemed misnamed.
1560 * op is the spell effect. 1749 * op is the spell effect.
1561 * note that duration is handled by process_object() in time.c 1750 * note that duration is handled by process_object() in time.c
1562 */ 1751 */
1563 1752
1753void
1564void move_ball_spell(object *op) { 1754move_ball_spell (object *op)
1755{
1565 int i,j,dam_save,dir, mflags; 1756 int i, j, dam_save, dir, mflags;
1566 sint16 nx,ny, hx, hy; 1757 sint16 nx, ny, hx, hy;
1567 object *owner; 1758 object *owner;
1568 mapstruct *m; 1759 mapstruct *m;
1569 1760
1570 owner = get_owner(op); 1761 owner = get_owner (op);
1571 1762
1572 /* the following logic makes sure that the ball doesn't move into a wall, 1763 /* the following logic makes sure that the ball doesn't move into a wall,
1573 * and makes sure that it will move along a wall to try and get at it's 1764 * and makes sure that it will move along a wall to try and get at it's
1574 * victim. The block immediately below more or less chooses a random 1765 * victim. The block immediately below more or less chooses a random
1575 * offset to move the ball, eg, keep it mostly on course, with some 1766 * offset to move the ball, eg, keep it mostly on course, with some
1576 * deviations. 1767 * deviations.
1577 */ 1768 */
1578 1769
1579 dir = 0; 1770 dir = 0;
1580 if(!(rndm(0, 3))) 1771 if (!(rndm (0, 3)))
1581 j = rndm(0, 1); 1772 j = rndm (0, 1);
1582 else j=0; 1773 else
1774 j = 0;
1583 1775
1584 for(i = 1; i < 9; i++) { 1776 for (i = 1; i < 9; i++)
1777 {
1585 /* i bit 0: alters sign of offset 1778 /* i bit 0: alters sign of offset
1586 * other bits (i / 2): absolute value of offset 1779 * other bits (i / 2): absolute value of offset
1587 */ 1780 */
1588 1781
1589 int offset = ((i ^ j) & 1) ? (i / 2) : - (i / 2); 1782 int offset = ((i ^ j) & 1) ? (i / 2) : -(i / 2);
1590 int tmpdir = absdir (op->direction + offset); 1783 int tmpdir = absdir (op->direction + offset);
1591 1784
1592 nx = op->x + freearr_x[tmpdir]; 1785 nx = op->x + freearr_x[tmpdir];
1593 ny = op->y + freearr_y[tmpdir]; 1786 ny = op->y + freearr_y[tmpdir];
1594 if ( ! (get_map_flags(op->map, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) && 1787 if (!(get_map_flags (op->map, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) && !(OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, nx, ny))))
1595 !(OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, nx, ny)))) { 1788 {
1596 dir = tmpdir; 1789 dir = tmpdir;
1597 break; 1790 break;
1598 } 1791 }
1599 } 1792 }
1600 if (dir == 0) { 1793 if (dir == 0)
1601 nx = op->x;
1602 ny = op->y;
1603 m = op->map;
1604 } 1794 {
1795 nx = op->x;
1796 ny = op->y;
1797 m = op->map;
1798 }
1605 1799
1606 remove_ob(op); 1800 remove_ob (op);
1607 op->y=ny; 1801 op->y = ny;
1608 op->x=nx; 1802 op->x = nx;
1609 insert_ob_in_map(op,m,op,0); 1803 insert_ob_in_map (op, m, op, 0);
1610 1804
1611 dam_save = op->stats.dam; /* save the original dam: we do halfdam on 1805 dam_save = op->stats.dam; /* save the original dam: we do halfdam on
1612 surrounding squares */ 1806 surrounding squares */
1613 1807
1614 /* loop over current square and neighbors to hit. 1808 /* loop over current square and neighbors to hit.
1615 * if this has an other_arch field, we insert that in 1809 * if this has an other_arch field, we insert that in
1616 * the surround spaces. 1810 * the surround spaces.
1617 */ 1811 */
1618 for(j=0;j<9;j++) { 1812 for (j = 0; j < 9; j++)
1813 {
1619 object *new_ob; 1814 object *new_ob;
1620 1815
1621 hx = nx+freearr_x[j]; 1816 hx = nx + freearr_x[j];
1622 hy = ny+freearr_y[j]; 1817 hy = ny + freearr_y[j];
1623 1818
1624 m = op->map; 1819 m = op->map;
1625 mflags = get_map_flags(m, &m, hx, hy, &hx, &hy); 1820 mflags = get_map_flags (m, &m, hx, hy, &hx, &hy);
1626 1821
1627 if (mflags & P_OUT_OF_MAP) continue; 1822 if (mflags & P_OUT_OF_MAP)
1823 continue;
1628 1824
1629 /* first, don't ever, ever hit the owner. Don't hit out 1825 /* first, don't ever, ever hit the owner. Don't hit out
1630 * of the map either. 1826 * of the map either.
1631 */ 1827 */
1632 1828
1633 if((mflags & P_IS_ALIVE) && (!owner || owner->x!=hx || owner->y!=hy || !on_same_map(owner,op))) { 1829 if ((mflags & P_IS_ALIVE) && (!owner || owner->x != hx || owner->y != hy || !on_same_map (owner, op)))
1634 if(j) op->stats.dam = dam_save/2; 1830 {
1831 if (j)
1832 op->stats.dam = dam_save / 2;
1635 hit_map(op,j,op->attacktype,1); 1833 hit_map (op, j, op->attacktype, 1);
1636 1834
1637 } 1835 }
1638 1836
1639 /* insert the other arch */ 1837 /* insert the other arch */
1640 if(op->other_arch && !(OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, hx, hy)))) { 1838 if (op->other_arch && !(OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, hx, hy))))
1839 {
1641 new_ob = arch_to_object(op->other_arch); 1840 new_ob = arch_to_object (op->other_arch);
1642 new_ob->x = hx; 1841 new_ob->x = hx;
1643 new_ob->y = hy; 1842 new_ob->y = hy;
1644 insert_ob_in_map(new_ob,m,op,0); 1843 insert_ob_in_map (new_ob, m, op, 0);
1645 } 1844 }
1646 } 1845 }
1647 1846
1648 /* restore to the center location and damage*/ 1847 /* restore to the center location and damage */
1649 op->stats.dam = dam_save; 1848 op->stats.dam = dam_save;
1650 1849
1651 i=spell_find_dir(op->map,op->x,op->y,get_owner(op)); 1850 i = spell_find_dir (op->map, op->x, op->y, get_owner (op));
1652 1851
1653 if(i>=0) { /* we have a preferred direction! */ 1852 if (i >= 0)
1853 { /* we have a preferred direction! */
1654 /* pick another direction if the preferred dir is blocked. */ 1854 /* pick another direction if the preferred dir is blocked. */
1655 if (get_map_flags(op->map,&m, nx + freearr_x[i], ny + freearr_y[i],&hx,&hy) & P_OUT_OF_MAP || 1855 if (get_map_flags (op->map, &m, nx + freearr_x[i], ny + freearr_y[i], &hx, &hy) & P_OUT_OF_MAP ||
1656 OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, hx, hy))) { 1856 OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, hx, hy)))
1857 {
1657 i= absdir(i + rndm(0, 2) -1); /* -1, 0, +1 */ 1858 i = absdir (i + rndm (0, 2) - 1); /* -1, 0, +1 */
1658 } 1859 }
1659 op->direction=i; 1860 op->direction = i;
1660 } 1861 }
1661} 1862}
1662 1863
1663 1864
1664/* move_swarm_spell: peterm 1865/* move_swarm_spell: peterm
1667 * is a special type of object that casts swarms of other types 1868 * is a special type of object that casts swarms of other types
1668 * of spells. Which spell it casts is flexible. It fires the spells 1869 * of spells. Which spell it casts is flexible. It fires the spells
1669 * from a set of squares surrounding the caster, in a given direction. 1870 * from a set of squares surrounding the caster, in a given direction.
1670 */ 1871 */
1671 1872
1873void
1672void move_swarm_spell(object *op) 1874move_swarm_spell (object *op)
1673{ 1875{
1674 static int cardinal_adjust[9] = { -3, -2, -1, 0, 0, 0, 1, 2, 3 };
1675 static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 };
1676 sint16 target_x, target_y, origin_x, origin_y;
1677 int basedir, adjustdir;
1678 mapstruct *m;
1679 object *owner;
1680
1681 owner = get_owner(op);
1682 if(op->duration == 0 || owner == NULL) {
1683 remove_ob(op);
1684 free_object(op);
1685 return;
1686 }
1687 op->duration--;
1688
1689 basedir = op->direction;
1690 if(basedir == 0) {
1691 /* spray in all directions! 8) */
1692 basedir = rndm(1, 8);
1693 }
1694
1695#if 0 1876#if 0
1696 // this is bogus: it causes wrong places to be checked below 1877 static int cardinal_adjust[9] = { -3, -2, -1, 0, 0, 0, 1, 2, 3 };
1697 // (a wall 2 cells away will block the effect...) and 1878 static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 };
1698 // doesn't work for SP_BULLET anyhow, so again tests the wrong 1879 sint16 target_x, target_y, origin_x, origin_y;
1699 // space. 1880 int adjustdir;
1700 // should be fixed later, but correctness before featurs... 1881 mapstruct *m;
1701 // (schmorp)
1702
1703 /* new offset calculation to make swarm element distribution
1704 * more uniform
1705 */
1706 if(op->duration) {
1707 if(basedir & 1) {
1708 adjustdir = cardinal_adjust[rndm(0, 8)];
1709 } else {
1710 adjustdir = diagonal_adjust[rndm(0, 9)];
1711 }
1712 } else {
1713 adjustdir = 0; /* fire the last one from forward. */
1714 }
1715
1716 target_x = op->x + freearr_x[absdir(basedir + adjustdir)];
1717 target_y = op->y + freearr_y[absdir(basedir + adjustdir)];
1718
1719 /* back up one space so we can hit point-blank targets, but this
1720 * necessitates extra out_of_map check below
1721 */
1722 origin_x = target_x - freearr_x[basedir];
1723 origin_y = target_y - freearr_y[basedir];
1724
1725
1726 /* spell pointer is set up for the spell this casts. Since this
1727 * should just be a pointer to the spell in some inventory,
1728 * it is unlikely to disappear by the time we need it. However,
1729 * do some sanity checking anyways.
1730 */
1731
1732 if (op->spell && op->spell->type == SPELL &&
1733 !(get_map_flags(op->map, &m, target_x, target_y, &target_x, &target_y) & P_OUT_OF_MAP) &&
1734 !(OB_TYPE_MOVE_BLOCK(op->spell, GET_MAP_MOVE_BLOCK(m, target_x, target_y)))) {
1735
1736 /* Bullet spells have a bunch more customization that needs to be done */
1737 if (op->spell->subtype == SP_BULLET)
1738 fire_bullet(owner, op, basedir, op->spell);
1739 else if (op->spell->subtype == SP_MAGIC_MISSILE)
1740 fire_arch_from_position (owner, op, origin_x, origin_y, basedir, op->spell);
1741 }
1742#endif 1882#endif
1883 int basedir;
1884 object *owner;
1743 1885
1886 owner = get_owner (op);
1887 if (op->duration == 0 || owner == NULL)
1888 {
1889 remove_ob (op);
1890 free_object (op);
1891 return;
1892 }
1893 op->duration--;
1894
1895 basedir = op->direction;
1896 if (basedir == 0)
1897 {
1898 /* spray in all directions! 8) */
1899 basedir = rndm (1, 8);
1900 }
1901
1902#if 0
1903 // this is bogus: it causes wrong places to be checked below
1904 // (a wall 2 cells away will block the effect...) and
1905 // doesn't work for SP_BULLET anyhow, so again tests the wrong
1906 // space.
1907 // should be fixed later, but correctness before featurs...
1908 // (schmorp)
1909
1910 /* new offset calculation to make swarm element distribution
1911 * more uniform
1912 */
1913 if (op->duration)
1914 {
1915 if (basedir & 1)
1916 {
1917 adjustdir = cardinal_adjust[rndm (0, 8)];
1918 }
1919 else
1920 {
1921 adjustdir = diagonal_adjust[rndm (0, 9)];
1922 }
1923 }
1924 else
1925 {
1926 adjustdir = 0; /* fire the last one from forward. */
1927 }
1928
1929 target_x = op->x + freearr_x[absdir (basedir + adjustdir)];
1930 target_y = op->y + freearr_y[absdir (basedir + adjustdir)];
1931
1932 /* back up one space so we can hit point-blank targets, but this
1933 * necessitates extra out_of_map check below
1934 */
1935 origin_x = target_x - freearr_x[basedir];
1936 origin_y = target_y - freearr_y[basedir];
1937
1938
1744 /* spell pointer is set up for the spell this casts. Since this 1939 /* spell pointer is set up for the spell this casts. Since this
1745 * should just be a pointer to the spell in some inventory, 1940 * should just be a pointer to the spell in some inventory,
1746 * it is unlikely to disappear by the time we need it. However, 1941 * it is unlikely to disappear by the time we need it. However,
1747 * do some sanity checking anyways. 1942 * do some sanity checking anyways.
1748 */ 1943 */
1944
1945 if (op->spell && op->spell->type == SPELL &&
1946 !(get_map_flags (op->map, &m, target_x, target_y, &target_x, &target_y) & P_OUT_OF_MAP) &&
1947 !(OB_TYPE_MOVE_BLOCK (op->spell, GET_MAP_MOVE_BLOCK (m, target_x, target_y))))
1749 1948 {
1949
1950 /* Bullet spells have a bunch more customization that needs to be done */
1951 if (op->spell->subtype == SP_BULLET)
1952 fire_bullet (owner, op, basedir, op->spell);
1953 else if (op->spell->subtype == SP_MAGIC_MISSILE)
1954 fire_arch_from_position (owner, op, origin_x, origin_y, basedir, op->spell);
1955 }
1956#endif
1957
1958 /* spell pointer is set up for the spell this casts. Since this
1959 * should just be a pointer to the spell in some inventory,
1960 * it is unlikely to disappear by the time we need it. However,
1961 * do some sanity checking anyways.
1962 */
1963
1750 if (op->spell && op->spell->type == SPELL) 1964 if (op->spell && op->spell->type == SPELL)
1751 { 1965 {
1752 /* Bullet spells have a bunch more customization that needs to be done */ 1966 /* Bullet spells have a bunch more customization that needs to be done */
1753 if (op->spell->subtype == SP_BULLET) 1967 if (op->spell->subtype == SP_BULLET)
1754 fire_bullet(owner, op, basedir, op->spell); 1968 fire_bullet (owner, op, basedir, op->spell);
1755 else if (op->spell->subtype == SP_MAGIC_MISSILE) 1969 else if (op->spell->subtype == SP_MAGIC_MISSILE)
1756 fire_arch_from_position (owner, op, op->x, op->y, basedir, op->spell); 1970 fire_arch_from_position (owner, op, op->x, op->y, basedir, op->spell);
1757 } 1971 }
1758} 1972}
1759 1973
1760 1974
1761 1975
1762 1976
1770 * dir: the direction everything will be fired in 1984 * dir: the direction everything will be fired in
1771 * spell - the spell that is this spell. 1985 * spell - the spell that is this spell.
1772 * n: the number to be fired. 1986 * n: the number to be fired.
1773 */ 1987 */
1774 1988
1989int
1775int fire_swarm (object *op, object *caster, object *spell, int dir) 1990fire_swarm (object *op, object *caster, object *spell, int dir)
1776{ 1991{
1777 object *tmp; 1992 object *tmp;
1778 int i; 1993 int i;
1779 1994
1780 if (!spell->other_arch) return 0; 1995 if (!spell->other_arch)
1996 return 0;
1781 1997
1782 tmp=get_archetype(SWARM_SPELL); 1998 tmp = get_archetype (SWARM_SPELL);
1783 tmp->x=op->x; 1999 tmp->x = op->x;
1784 tmp->y=op->y; 2000 tmp->y = op->y;
1785 set_owner(tmp,op); /* needed so that if swarm elements kill, caster gets xp.*/ 2001 set_owner (tmp, op); /* needed so that if swarm elements kill, caster gets xp. */
1786 set_spell_skill(op, caster, spell, tmp); 2002 set_spell_skill (op, caster, spell, tmp);
1787 2003
1788 tmp->level=caster_level(caster, spell); /*needed later, to get level dep. right.*/ 2004 tmp->level = caster_level (caster, spell); /*needed later, to get level dep. right. */
1789 tmp->spell = arch_to_object(spell->other_arch); 2005 tmp->spell = arch_to_object (spell->other_arch);
1790 2006
1791 tmp->attacktype = tmp->spell->attacktype; 2007 tmp->attacktype = tmp->spell->attacktype;
1792 2008
1793 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) { 2009 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
2010 {
1794 if ( ! tailor_god_spell (tmp, op)) 2011 if (!tailor_god_spell (tmp, op))
1795 return 1; 2012 return 1;
1796 } 2013 }
1797 tmp->duration = SP_level_duration_adjust(caster, spell); 2014 tmp->duration = SP_level_duration_adjust (caster, spell);
1798 for (i=0; i< spell->duration; i++) 2015 for (i = 0; i < spell->duration; i++)
1799 tmp->duration += die_roll(1, 3, op, PREFER_HIGH); 2016 tmp->duration += die_roll (1, 3, op, PREFER_HIGH);
1800 2017
1801 tmp->direction=dir; 2018 tmp->direction = dir;
1802 tmp->invisible=1; 2019 tmp->invisible = 1;
1803 insert_ob_in_map(tmp,op->map,op,0); 2020 insert_ob_in_map (tmp, op->map, op, 0);
1804 return 1; 2021 return 1;
1805} 2022}
1806 2023
1807 2024
1808/* See the spells documentation file for why this is its own 2025/* See the spells documentation file for why this is its own
1809 * function. 2026 * function.
1810 */ 2027 */
2028int
1811int cast_light(object *op,object *caster,object *spell, int dir) { 2029cast_light (object *op, object *caster, object *spell, int dir)
2030{
1812 object *target=NULL,*tmp=NULL; 2031 object *target = NULL, *tmp = NULL;
1813 sint16 x,y; 2032 sint16 x, y;
1814 int dam, mflags; 2033 int dam, mflags;
1815 mapstruct *m; 2034 mapstruct *m;
1816 2035
1817 dam = spell->stats.dam + SP_level_dam_adjust(caster,spell); 2036 dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
1818 2037
1819 if(!dir) { 2038 if (!dir)
2039 {
1820 new_draw_info(NDI_UNIQUE, 0,op,"In what direction?"); 2040 new_draw_info (NDI_UNIQUE, 0, op, "In what direction?");
1821 return 0; 2041 return 0;
1822 } 2042 }
1823 2043
1824 x=op->x+freearr_x[dir]; 2044 x = op->x + freearr_x[dir];
1825 y=op->y+freearr_y[dir]; 2045 y = op->y + freearr_y[dir];
1826 m = op->map; 2046 m = op->map;
1827 2047
1828 mflags = get_map_flags(m, &m, x, y, &x, &y); 2048 mflags = get_map_flags (m, &m, x, y, &x, &y);
1829 2049
1830 if (mflags & P_OUT_OF_MAP) { 2050 if (mflags & P_OUT_OF_MAP)
2051 {
1831 new_draw_info(NDI_UNIQUE, 0,op,"Nothing is there."); 2052 new_draw_info (NDI_UNIQUE, 0, op, "Nothing is there.");
1832 return 0; 2053 return 0;
1833 } 2054 }
1834 2055
1835 if (mflags & P_IS_ALIVE && spell->attacktype) { 2056 if (mflags & P_IS_ALIVE && spell->attacktype)
2057 {
1836 for(target=get_map_ob(m,x,y);target;target=target->above) 2058 for (target = get_map_ob (m, x, y); target; target = target->above)
1837 if(QUERY_FLAG(target,FLAG_MONSTER)) { 2059 if (QUERY_FLAG (target, FLAG_MONSTER))
2060 {
1838 /* oky doky. got a target monster. Lets make a blinding attack */ 2061 /* oky doky. got a target monster. Lets make a blinding attack */
1839 if(target->head) target = target->head; 2062 if (target->head)
2063 target = target->head;
1840 (void) hit_player(target,dam,op,spell->attacktype,1); 2064 (void) hit_player (target, dam, op, spell->attacktype, 1);
1841 return 1; /* one success only! */ 2065 return 1; /* one success only! */
2066 }
1842 } 2067 }
1843 }
1844 2068
1845 /* no live target, perhaps a wall is in the way? */ 2069 /* no live target, perhaps a wall is in the way? */
1846 if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y))) { 2070 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, x, y)))
2071 {
1847 new_draw_info(NDI_UNIQUE, 0,op,"Something is in the way."); 2072 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way.");
1848 return 0; 2073 return 0;
1849 } 2074 }
1850 2075
1851 /* ok, looks groovy to just insert a new light on the map */ 2076 /* ok, looks groovy to just insert a new light on the map */
1852 tmp=arch_to_object(spell->other_arch); 2077 tmp = arch_to_object (spell->other_arch);
1853 if(!tmp) { 2078 if (!tmp)
2079 {
1854 LOG(llevError,"Error: spell arch for cast_light() missing.\n"); 2080 LOG (llevError, "Error: spell arch for cast_light() missing.\n");
1855 return 0; 2081 return 0;
1856 } 2082 }
1857 tmp->stats.food = spell->duration + SP_level_duration_adjust(caster,spell); 2083 tmp->stats.food = spell->duration + SP_level_duration_adjust (caster, spell);
1858 if (tmp->glow_radius) { 2084 if (tmp->glow_radius)
2085 {
1859 tmp->glow_radius= spell->range + SP_level_range_adjust(caster,spell); 2086 tmp->glow_radius = spell->range + SP_level_range_adjust (caster, spell);
1860 if (tmp->glow_radius > MAX_LIGHT_RADII) tmp->glow_radius = MAX_LIGHT_RADII; 2087 if (tmp->glow_radius > MAX_LIGHT_RADII)
2088 tmp->glow_radius = MAX_LIGHT_RADII;
1861 } 2089 }
1862 tmp->x=x; 2090 tmp->x = x;
1863 tmp->y=y; 2091 tmp->y = y;
1864 insert_ob_in_map(tmp,m,op,0); 2092 insert_ob_in_map (tmp, m, op, 0);
1865 return 1; 2093 return 1;
1866} 2094}
1867 2095
1868 2096
1869 2097
1870 2098
1873 * op is the player/monster, caster is the object, dir is the direction 2101 * op is the player/monster, caster is the object, dir is the direction
1874 * to cast, disease_arch is the specific disease, and type is the spell number 2102 * to cast, disease_arch is the specific disease, and type is the spell number
1875 * perhaps this should actually be in disease.c? 2103 * perhaps this should actually be in disease.c?
1876 */ 2104 */
1877 2105
2106int
1878int cast_cause_disease(object *op, object *caster, object *spell, int dir) { 2107cast_cause_disease (object *op, object *caster, object *spell, int dir)
2108{
1879 sint16 x,y; 2109 sint16 x, y;
1880 int i, mflags, range, dam_mod, dur_mod; 2110 int i, mflags, range, dam_mod, dur_mod;
1881 object *walk; 2111 object *walk;
1882 mapstruct *m; 2112 mapstruct *m;
1883 2113
1884 x = op->x; 2114 x = op->x;
1885 y = op->y; 2115 y = op->y;
1886 2116
1887 /* If casting from a scroll, no direction will be available, so refer to the 2117 /* If casting from a scroll, no direction will be available, so refer to the
1888 * direction the player is pointing. 2118 * direction the player is pointing.
1889 */ 2119 */
2120 if (!dir)
1890 if (!dir) dir=op->facing; 2121 dir = op->facing;
2122 if (!dir)
1891 if (!dir) return 0; /* won't find anything if casting on ourself, so just return */ 2123 return 0; /* won't find anything if casting on ourself, so just return */
1892 2124
1893 /* Calculate these once here */ 2125 /* Calculate these once here */
1894 range = spell->range + SP_level_range_adjust(caster, spell); 2126 range = spell->range + SP_level_range_adjust (caster, spell);
1895 dam_mod = SP_level_dam_adjust(caster, spell); 2127 dam_mod = SP_level_dam_adjust (caster, spell);
1896 dur_mod = SP_level_duration_adjust(caster, spell); 2128 dur_mod = SP_level_duration_adjust (caster, spell);
1897 2129
1898 /* search in a line for a victim */ 2130 /* search in a line for a victim */
1899 for(i=1; i<range; i++) { 2131 for (i = 1; i < range; i++)
2132 {
1900 x = op->x + i * freearr_x[dir]; 2133 x = op->x + i * freearr_x[dir];
1901 y = op->y + i * freearr_y[dir]; 2134 y = op->y + i * freearr_y[dir];
1902 m = op->map; 2135 m = op->map;
1903 2136
1904 mflags = get_map_flags(m, &m, x, y, &x, &y); 2137 mflags = get_map_flags (m, &m, x, y, &x, &y);
1905 2138
1906 if (mflags & P_OUT_OF_MAP) return 0; 2139 if (mflags & P_OUT_OF_MAP)
2140 return 0;
1907 2141
1908 /* don't go through walls - presume diseases are airborne */ 2142 /* don't go through walls - presume diseases are airborne */
1909 if (GET_MAP_MOVE_BLOCK(m, x, y) & MOVE_FLY_LOW) return 0; 2143 if (GET_MAP_MOVE_BLOCK (m, x, y) & MOVE_FLY_LOW)
2144 return 0;
1910 2145
1911 /* Only bother looking on this space if there is something living here */ 2146 /* Only bother looking on this space if there is something living here */
1912 if (mflags & P_IS_ALIVE) { 2147 if (mflags & P_IS_ALIVE)
2148 {
1913 /* search this square for a victim */ 2149 /* search this square for a victim */
1914 for(walk=get_map_ob(m,x,y);walk;walk=walk->above) 2150 for (walk = get_map_ob (m, x, y); walk; walk = walk->above)
1915 if (QUERY_FLAG(walk,FLAG_MONSTER) || (walk->type==PLAYER)) { /* found a victim */ 2151 if (QUERY_FLAG (walk, FLAG_MONSTER) || (walk->type == PLAYER))
2152 { /* found a victim */
1916 object *disease = arch_to_object(spell->other_arch); 2153 object *disease = arch_to_object (spell->other_arch);
1917 2154
1918 set_owner(disease,op); 2155 set_owner (disease, op);
1919 set_spell_skill(op, caster, spell, disease); 2156 set_spell_skill (op, caster, spell, disease);
1920 disease->stats.exp = 0; 2157 disease->stats.exp = 0;
1921 disease->level = caster_level(caster, spell); 2158 disease->level = caster_level (caster, spell);
1922 2159
1923 /* do level adjustments */ 2160 /* do level adjustments */
1924 if(disease->stats.wc) 2161 if (disease->stats.wc)
1925 disease->stats.wc += dur_mod/2; 2162 disease->stats.wc += dur_mod / 2;
1926 2163
1927 if(disease->magic> 0) 2164 if (disease->magic > 0)
1928 disease->magic += dur_mod/4; 2165 disease->magic += dur_mod / 4;
1929 2166
1930 if(disease->stats.maxhp>0) 2167 if (disease->stats.maxhp > 0)
1931 disease->stats.maxhp += dur_mod; 2168 disease->stats.maxhp += dur_mod;
1932 2169
1933 if(disease->stats.maxgrace>0) 2170 if (disease->stats.maxgrace > 0)
1934 disease->stats.maxgrace += dur_mod; 2171 disease->stats.maxgrace += dur_mod;
1935 2172
1936 if(disease->stats.dam) { 2173 if (disease->stats.dam)
1937 if(disease->stats.dam > 0) 2174 {
1938 disease->stats.dam += dam_mod; 2175 if (disease->stats.dam > 0)
1939 else disease->stats.dam -= dam_mod; 2176 disease->stats.dam += dam_mod;
1940 } 2177 else
2178 disease->stats.dam -= dam_mod;
2179 }
1941 2180
1942 if(disease->last_sp) { 2181 if (disease->last_sp)
1943 disease->last_sp -= 2*dam_mod; 2182 {
1944 if(disease->last_sp <1) disease->last_sp = 1; 2183 disease->last_sp -= 2 * dam_mod;
1945 } 2184 if (disease->last_sp < 1)
2185 disease->last_sp = 1;
2186 }
1946 2187
1947 if(disease->stats.maxsp) { 2188 if (disease->stats.maxsp)
1948 if(disease->stats.maxsp > 0) 2189 {
1949 disease->stats.maxsp += dam_mod; 2190 if (disease->stats.maxsp > 0)
1950 else disease->stats.maxsp -= dam_mod; 2191 disease->stats.maxsp += dam_mod;
1951 } 2192 else
1952 2193 disease->stats.maxsp -= dam_mod;
2194 }
2195
1953 if(disease->stats.ac) 2196 if (disease->stats.ac)
1954 disease->stats.ac += dam_mod; 2197 disease->stats.ac += dam_mod;
1955 2198
1956 if(disease->last_eat) 2199 if (disease->last_eat)
1957 disease->last_eat -= dam_mod; 2200 disease->last_eat -= dam_mod;
1958 2201
1959 if(disease->stats.hp) 2202 if (disease->stats.hp)
1960 disease->stats.hp -= dam_mod; 2203 disease->stats.hp -= dam_mod;
1961 2204
1962 if(disease->stats.sp) 2205 if (disease->stats.sp)
1963 disease->stats.sp -= dam_mod; 2206 disease->stats.sp -= dam_mod;
1964 2207
1965 if(infect_object(walk,disease,1)) { 2208 if (infect_object (walk, disease, 1))
2209 {
1966 object *flash; /* visual effect for inflicting disease */ 2210 object *flash; /* visual effect for inflicting disease */
1967 2211
1968 new_draw_info_format(NDI_UNIQUE, 0, op, "You inflict %s on %s!",disease->name,walk->name); 2212 new_draw_info_format (NDI_UNIQUE, 0, op, "You inflict %s on %s!", &disease->name, &walk->name);
1969 2213
1970 free_object(disease); /* don't need this one anymore */ 2214 free_object (disease); /* don't need this one anymore */
1971 flash=get_archetype(ARCH_DETECT_MAGIC); 2215 flash = get_archetype (ARCH_DETECT_MAGIC);
1972 flash->x = x; 2216 flash->x = x;
1973 flash->y = y; 2217 flash->y = y;
1974 flash->map = walk->map; 2218 flash->map = walk->map;
1975 insert_ob_in_map(flash,walk->map,op,0); 2219 insert_ob_in_map (flash, walk->map, op, 0);
1976 return 1; 2220 return 1;
1977 } 2221 }
1978 free_object(disease); 2222 free_object (disease);
1979 } 2223 }
1980 } /* if living creature */ 2224 } /* if living creature */
1981 } /* for range of spaces */ 2225 } /* for range of spaces */
1982 new_draw_info(NDI_UNIQUE,0,op,"No one caught anything!"); 2226 new_draw_info (NDI_UNIQUE, 0, op, "No one caught anything!");
1983 return 1; 2227 return 1;
1984} 2228}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines