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

Comparing deliantra/server/server/attack.C (file contents):
Revision 1.3 by root, Sat Aug 26 23:36:33 2006 UTC vs.
Revision 1.10 by root, Mon Sep 11 11:46:52 2006 UTC

1
1/* 2/*
2 * static char *rcsid_attack_c = 3 * static char *rcsid_attack_c =
3 * "$Id: attack.C,v 1.3 2006/08/26 23:36:33 root Exp $"; 4 * "$Id: attack.C,v 1.10 2006/09/11 11:46:52 root Exp $";
4 */ 5 */
6
5/* 7/*
6 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
7 9
8 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
9 Copyright (C) 1992 Frank Tore Johansen 11 Copyright (C) 1992 Frank Tore Johansen
29#include <living.h> 31#include <living.h>
30#include <material.h> 32#include <material.h>
31#include <skills.h> 33#include <skills.h>
32 34
33#ifndef __CEXTRACT__ 35#ifndef __CEXTRACT__
34#include <sproto.h> 36# include <sproto.h>
35#endif 37#endif
36 38
37#include <sounds.h> 39#include <sounds.h>
38 40
39typedef struct att_msg_str { 41typedef struct att_msg_str
42{
40 char *msg1; 43 char *msg1;
41 char *msg2; 44 char *msg2;
42} att_msg; 45} att_msg;
43 46
44/*#define ATTACK_DEBUG*/ 47/*#define ATTACK_DEBUG*/
45 48
46/* cancels object *op. Cancellation basically means an object loses 49/* cancels object *op. Cancellation basically means an object loses
47 * its magical benefits. 50 * its magical benefits.
48 */ 51 */
52void
49void cancellation(object *op) 53cancellation (object *op)
50{ 54{
51 object *tmp; 55 object *tmp;
52 56
53 if (op->invisible) 57 if (op->invisible)
54 return; 58 return;
55 59
56 if (QUERY_FLAG (op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ) { 60 if (QUERY_FLAG (op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ)
61 {
57 /* Recur through the inventory */ 62 /* Recur through the inventory */
58 for(tmp=op->inv;tmp!=NULL;tmp=tmp->below) 63 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
59 if (!did_make_save_item(tmp, AT_CANCELLATION,op)) 64 if (!did_make_save_item (tmp, AT_CANCELLATION, op))
60 cancellation(tmp); 65 cancellation (tmp);
61 } 66 }
62 else if(FABS(op->magic)<=(rndm(0, 5))) { 67 else if (FABS (op->magic) <= (rndm (0, 5)))
68 {
63 /* Nullify this object. This code could probably be more complete */ 69 /* Nullify this object. This code could probably be more complete */
64 /* in what abilities it should cancel */ 70 /* in what abilities it should cancel */
65 op->magic=0; 71 op->magic = 0;
66 CLEAR_FLAG(op, FLAG_DAMNED); 72 CLEAR_FLAG (op, FLAG_DAMNED);
67 CLEAR_FLAG(op, FLAG_CURSED); 73 CLEAR_FLAG (op, FLAG_CURSED);
68 CLEAR_FLAG(op, FLAG_KNOWN_MAGICAL); 74 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL);
69 CLEAR_FLAG(op, FLAG_KNOWN_CURSED); 75 CLEAR_FLAG (op, FLAG_KNOWN_CURSED);
70 if (op->env && op->env->type == PLAYER) { 76 if (op->env && op->env->type == PLAYER)
77 {
71 esrv_send_item (op->env, op); 78 esrv_send_item (op->env, op);
72 } 79 }
73 } 80 }
74} 81}
75 82
76 83
77 84
78/* did_make_save_item just checks to make sure the item actually 85/* did_make_save_item just checks to make sure the item actually
79 * made its saving throw based on the tables. It does not take 86 * made its saving throw based on the tables. It does not take
80 * any further action (like destroying the item). 87 * any further action (like destroying the item).
81 */ 88 */
82 89
90int
83int did_make_save_item(object *op, int type, object *originator) { 91did_make_save_item (object *op, int type, object *originator)
92{
84 int i, roll, saves=0, attacks=0, number; 93 int i, roll, saves = 0, attacks = 0, number;
85 materialtype_t *mt; 94 materialtype_t *mt;
86 95
87 if (op->materialname == NULL) { 96 if (op->materialname == NULL)
97 {
88 for (mt = materialt; mt != NULL && mt->next != NULL; mt=mt->next) { 98 for (mt = materialt; mt != NULL && mt->next != NULL; mt = mt->next)
99 {
89 if (op->material & mt->material) 100 if (op->material & mt->material)
90 break; 101 break;
91 } 102 }
103 }
92 } else 104 else
93 mt = name_to_material(op->materialname); 105 mt = name_to_material (op->materialname);
94 if (mt == NULL) 106 if (mt == NULL)
95 return TRUE;
96 roll = rndm(1, 20);
97
98 /* the attacktypes have no meaning for object saves
99 * If the type is only magic, don't adjust type - basically, if
100 * pure magic is hitting an object, it should save. However, if it
101 * is magic teamed with something else, then strip out the
102 * magic type, and instead let the fire, cold, or whatever component
103 * destroy the item. Otherwise, you get the case of poisoncloud
104 * destroying objects because it has magic attacktype.
105 */
106 if (type != AT_MAGIC)
107 type &= ~(AT_CONFUSION|AT_DRAIN|AT_GHOSTHIT|AT_POISON|AT_SLOW|
108 AT_PARALYZE|AT_TURN_UNDEAD|AT_FEAR|AT_DEPLETE|AT_DEATH|
109 AT_COUNTERSPELL|AT_HOLYWORD|AT_BLIND|AT_LIFE_STEALING|
110 AT_MAGIC);
111
112 if (type == 0)
113 return TRUE;
114 if (roll == 20)
115 return TRUE;
116 if (roll == 1)
117 return FALSE;
118
119 for (number=0; number < NROFATTACKS; number++) {
120 i = 1<<number;
121 if (!(i&type))
122 continue;
123 attacks++;
124 if (op->resist[number] == 100)
125 saves++;
126 else if (roll >= mt->save[number] - op->magic - op->resist[number]/100)
127 saves++;
128 else if ((20-mt->save[number])/3 > originator->stats.dam)
129 saves++;
130 }
131
132 if (saves==attacks || attacks==0)
133 return TRUE;
134 if ((saves==0) || (rndm(1, attacks) > saves))
135 return FALSE;
136 return TRUE; 107 return TRUE;
108 roll = rndm (1, 20);
109
110 /* the attacktypes have no meaning for object saves
111 * If the type is only magic, don't adjust type - basically, if
112 * pure magic is hitting an object, it should save. However, if it
113 * is magic teamed with something else, then strip out the
114 * magic type, and instead let the fire, cold, or whatever component
115 * destroy the item. Otherwise, you get the case of poisoncloud
116 * destroying objects because it has magic attacktype.
117 */
118 if (type != AT_MAGIC)
119 type &= ~(AT_CONFUSION | AT_DRAIN | AT_GHOSTHIT | AT_POISON | AT_SLOW |
120 AT_PARALYZE | AT_TURN_UNDEAD | AT_FEAR | AT_DEPLETE | AT_DEATH |
121 AT_COUNTERSPELL | AT_HOLYWORD | AT_BLIND | AT_LIFE_STEALING | AT_MAGIC);
122
123 if (type == 0)
124 return TRUE;
125 if (roll == 20)
126 return TRUE;
127 if (roll == 1)
128 return FALSE;
129
130 for (number = 0; number < NROFATTACKS; number++)
131 {
132 i = 1 << number;
133 if (!(i & type))
134 continue;
135 attacks++;
136 if (op->resist[number] == 100)
137 saves++;
138 else if (roll >= mt->save[number] - op->magic - op->resist[number] / 100)
139 saves++;
140 else if ((20 - mt->save[number]) / 3 > originator->stats.dam)
141 saves++;
142 }
143
144 if (saves == attacks || attacks == 0)
145 return TRUE;
146 if ((saves == 0) || (rndm (1, attacks) > saves))
147 return FALSE;
148 return TRUE;
137} 149}
138 150
139/* This function calls did_make_save_item. It then performs the 151/* This function calls did_make_save_item. It then performs the
140 * appropriate actions to the item (such as burning the item up, 152 * appropriate actions to the item (such as burning the item up,
141 * calling cancellation, etc.) 153 * calling cancellation, etc.)
142 */ 154 */
143 155
156void
144void save_throw_object (object *op, int type, object *originator) 157save_throw_object (object *op, int type, object *originator)
145{ 158{
146 if ( ! did_make_save_item (op, type,originator)) 159 if (!did_make_save_item (op, type, originator))
147 { 160 {
148 object *env=op->env; 161 object *env = op->env;
149 int x=op->x,y=op->y; 162 int x = op->x, y = op->y;
150 mapstruct *m=op->map; 163 mapstruct *m = op->map;
151 164
152 op = stop_item (op); 165 op = stop_item (op);
153 if (op == NULL) 166 if (op == NULL)
154 return; 167 return;
155 168
156 /* Hacked the following so that type LIGHTER will work. 169 /* Hacked the following so that type LIGHTER will work.
157 * Also, objects which are potenital "lights" that are hit by 170 * Also, objects which are potenital "lights" that are hit by
158 * flame/elect attacks will be set to glow. "lights" are any 171 * flame/elect attacks will be set to glow. "lights" are any
159 * object with +/- glow_radius and an "other_arch" to change to. 172 * object with +/- glow_radius and an "other_arch" to change to.
160 * (and please note that we cant fail our save and reach this 173 * (and please note that we cant fail our save and reach this
161 * function if the object doesnt contain a material that can burn. 174 * function if the object doesnt contain a material that can burn.
162 * So forget lighting magical swords on fire with this!) -b.t. 175 * So forget lighting magical swords on fire with this!) -b.t.
163 */ 176 */
164 if(type&(AT_FIRE|AT_ELECTRICITY) 177 if (type & (AT_FIRE | AT_ELECTRICITY) && op->other_arch && QUERY_FLAG (op, FLAG_IS_LIGHTABLE))
165 &&op->other_arch&&QUERY_FLAG(op, FLAG_IS_LIGHTABLE)) {
166 const char *arch=op->other_arch->name;
167
168 op = decrease_ob_nr (op, 1);
169 if (op)
170 fix_stopped_item (op, m, originator);
171 if((op = get_archetype(arch))!=NULL) {
172 if(env) {
173 op->x=env->x,op->y=env->y;
174 insert_ob_in_ob(op,env);
175 if (env->contr)
176 esrv_send_item(env, op);
177 } else {
178 op->x=x,op->y=y;
179 insert_ob_in_map(op,m,originator,0);
180 }
181 }
182 return;
183 } 178 {
184 if(type&AT_CANCELLATION) { /* Cancellation. */ 179 const char *arch = op->other_arch->name;
185 cancellation(op); 180
181 op = decrease_ob_nr (op, 1);
182 if (op)
186 fix_stopped_item (op, m, originator); 183 fix_stopped_item (op, m, originator);
187 return; 184 if ((op = get_archetype (arch)) != NULL)
188 } 185 {
189 if(op->nrof>1) {
190 op = decrease_ob_nr(op,rndm(0, op->nrof-1));
191 if (op) 186 if (env)
192 fix_stopped_item (op, m, originator); 187 {
193 } else { 188 op->x = env->x, op->y = env->y;
194 if (op->env) {
195 object *tmp= is_player_inv(op->env);
196
197 if (tmp) {
198 esrv_del_item(tmp->contr, op->count);
199 }
200 }
201 if ( ! QUERY_FLAG (op, FLAG_REMOVED))
202 remove_ob(op);
203 free_object(op);
204 }
205 if(type&(AT_FIRE|AT_ELECTRICITY)) {
206 if(env) {
207 op=get_archetype("burnout");
208 op->x=env->x,op->y=env->y;
209 insert_ob_in_ob(op,env); 189 insert_ob_in_ob (op, env);
210 } else { 190 if (env->contr)
191 esrv_send_item (env, op);
192 }
193 else
194 {
195 op->x = x, op->y = y;
211 replace_insert_ob_in_map("burnout",originator); 196 insert_ob_in_map (op, m, originator, 0);
212 } 197 }
213 } 198 }
214 return;
215 }
216 /* The value of 50 is arbitrary. */
217 if(type&AT_COLD &&(op->resist[ATNR_COLD]<50) &&
218 !QUERY_FLAG(op,FLAG_NO_PICK)&&(RANDOM()&2)) {
219 object *tmp;
220 archetype *at = find_archetype("icecube");
221 if (at == NULL)
222 return; 199 return;
223 op = stop_item (op); 200 }
224 if (op == NULL) 201 if (type & AT_CANCELLATION)
202 { /* Cancellation. */
203 cancellation (op);
204 fix_stopped_item (op, m, originator);
225 return; 205 return;
226 if ((tmp = present_arch(at,op->map,op->x,op->y)) == NULL) { 206 }
227 tmp = arch_to_object(at); 207 if (op->nrof > 1)
228 tmp->x=op->x,tmp->y=op->y;
229 /* This was in the old (pre new movement code) -
230 * icecubes have slow_move set to 1 - don't want
231 * that for ones we create.
232 */
233 tmp->move_slow_penalty=0;
234 tmp->move_slow=0;
235 insert_ob_in_map(tmp,op->map,originator,0);
236 } 208 {
209 op = decrease_ob_nr (op, rndm (0, op->nrof - 1));
210 if (op)
211 fix_stopped_item (op, m, originator);
212 }
213 else
214 {
215 if (op->env)
216 {
217 object *tmp = is_player_inv (op->env);
218
219 if (tmp)
220 {
221 esrv_del_item (tmp->contr, op->count);
222 }
223 }
237 if ( ! QUERY_FLAG (op, FLAG_REMOVED)) 224 if (!QUERY_FLAG (op, FLAG_REMOVED))
238 remove_ob(op); 225 remove_ob (op);
226 free_object (op);
227 }
228 if (type & (AT_FIRE | AT_ELECTRICITY))
229 {
230 if (env)
231 {
232 op = get_archetype ("burnout");
233 op->x = env->x, op->y = env->y;
239 (void) insert_ob_in_ob(op,tmp); 234 insert_ob_in_ob (op, env);
235 }
236 else
237 {
238 replace_insert_ob_in_map ("burnout", originator);
239 }
240 }
241 return;
242 }
243 /* The value of 50 is arbitrary. */
244 if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && (RANDOM () & 2))
245 {
246 object *tmp;
247 archetype *at = find_archetype ("icecube");
248
249 if (at == NULL)
240 return; 250 return;
251 op = stop_item (op);
252 if (op == NULL)
253 return;
254 if ((tmp = present_arch (at, op->map, op->x, op->y)) == NULL)
255 {
256 tmp = arch_to_object (at);
257 tmp->x = op->x, tmp->y = op->y;
258 /* This was in the old (pre new movement code) -
259 * icecubes have slow_move set to 1 - don't want
260 * that for ones we create.
261 */
262 tmp->move_slow_penalty = 0;
263 tmp->move_slow = 0;
264 insert_ob_in_map (tmp, op->map, originator, 0);
265 }
266 if (!QUERY_FLAG (op, FLAG_REMOVED))
267 remove_ob (op);
268 (void) insert_ob_in_ob (op, tmp);
269 return;
241 } 270 }
242} 271}
243 272
244/* Object op is hitting the map. 273/* Object op is hitting the map.
245 * op is going in direction 'dir' 274 * op is going in direction 'dir'
246 * type is the attacktype of the object. 275 * type is the attacktype of the object.
247 * full_hit is set if monster area does not matter. 276 * full_hit is set if monster area does not matter.
248 * returns 1 if it hits something, 0 otherwise. 277 * returns 1 if it hits something, 0 otherwise.
249 */ 278 */
250 279
280int
251int hit_map(object *op, int dir, int type, int full_hit) { 281hit_map (object *op, int dir, int type, int full_hit)
282{
252 object *tmp, *next; 283 object *tmp, *next;
253 mapstruct *map; 284 mapstruct *map;
254 sint16 x, y; 285 sint16 x, y;
255 int retflag=0; /* added this flag.. will return 1 if it hits a monster */ 286 int retflag = 0; /* added this flag.. will return 1 if it hits a monster */
256 287
257 tag_t op_tag, next_tag=0; 288 tag_t op_tag, next_tag = 0;
258 289
259 if (QUERY_FLAG (op, FLAG_FREED)) { 290 if (QUERY_FLAG (op, FLAG_FREED))
291 {
260 LOG (llevError, "BUG: hit_map(): free object\n"); 292 LOG (llevError, "BUG: hit_map(): free object\n");
261 return 0; 293 return 0;
262 } 294 }
263 295
264 if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL) { 296 if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL)
297 {
265 LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", 298 LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->name, &op->name);
266 op->arch->name, op->name); 299 return 0;
267 return 0;
268 } 300 }
269 301
270 if ( ! op->map) { 302 if (!op->map)
303 {
271 LOG (llevError,"BUG: hit_map(): %s has no map\n", op->name); 304 LOG (llevError, "BUG: hit_map(): %s has no map\n", &op->name);
272 return 0; 305 return 0;
273 } 306 }
274 307
275 if (op->head) op=op->head; 308 if (op->head)
309 op = op->head;
276 310
277 op_tag = op->count; 311 op_tag = op->count;
278 312
279 map = op->map; 313 map = op->map;
280 x = op->x + freearr_x[dir]; 314 x = op->x + freearr_x[dir];
281 y = op->y + freearr_y[dir]; 315 y = op->y + freearr_y[dir];
282 if (get_map_flags(map, &map, x, y, &x, &y) & P_OUT_OF_MAP)
283 return 0;
284 316
285 /* peterm: a few special cases for special attacktypes --counterspell 317 int mflags = get_map_flags (map, &map, x, y, &x, &y);
286 * must be out here because it strikes things which are not alive
287 */
288 318
289 if (type & AT_COUNTERSPELL) { 319 // elmex: a safe map tile can't be hit!
290 counterspell(op,dir); /* see spell_effect.c */ 320 // this should prevent most harmful effects on items and players there.
291 321 if ((mflags & P_OUT_OF_MAP) || (mflags & P_SAFE))
292 /* If the only attacktype is counterspell or magic, don't need
293 * to do any further processing.
294 */
295 if(!(type & ~(AT_COUNTERSPELL|AT_MAGIC))){
296 return 0;
297 }
298 type &= ~AT_COUNTERSPELL;
299 }
300
301 if(type & AT_CHAOS){
302 shuffle_attack(op,1); /*1 flag tells it to change the face */
303 update_object(op,UP_OBJ_FACE);
304 type &= ~AT_CHAOS;
305 }
306
307 next = get_map_ob (map, x, y);
308 if (next)
309 next_tag = next->count;
310
311 while (next) {
312 if (was_destroyed (next, next_tag)) {
313 /* There may still be objects that were above 'next', but there is no
314 * simple way to find out short of copying all object references and
315 * tags into a temporary array before we start processing the first
316 * object. That's why we just abort.
317 *
318 * This happens whenever attack spells (like fire) hit a pile
319 * of objects. This is not a bug - nor an error. The errormessage
320 * below was spamming the logs for absolutely no reason.
321 */
322 /* LOG (llevDebug, "hit_map(): next object destroyed\n"); */
323 break;
324 }
325 tmp = next;
326 next = tmp->above;
327 if (next)
328 next_tag = next->count;
329
330 if (QUERY_FLAG (tmp, FLAG_FREED)) {
331 LOG (llevError, "BUG: hit_map(): found freed object\n");
332 break;
333 }
334
335 /* Something could have happened to 'tmp' while 'tmp->below' was processed.
336 * For example, 'tmp' was put in an icecube.
337 * This is one of the few cases where on_same_map should not be used.
338 */
339 if (tmp->map != map || tmp->x != x || tmp->y != y)
340 continue;
341
342 /* Need to hit everyone in the transport with this spell */
343 if (tmp->type == TRANSPORT) {
344 object *pl;
345
346 for (pl=tmp->inv; pl; pl=pl->below) {
347 if (pl->type == PLAYER)
348 hit_player(pl,op->stats.dam,op,type,full_hit);
349 }
350 }
351
352 if (QUERY_FLAG (tmp, FLAG_ALIVE)) {
353 hit_player(tmp,op->stats.dam,op,type,full_hit);
354 retflag |=1;
355 if (was_destroyed (op, op_tag))
356 break;
357 }
358 /* Here we are potentially destroying an object. If the object has
359 * NO_PASS set, it is also immune - you can't destroy walls. Note
360 * that weak walls have is_alive set, which prevent objects from
361 * passing over/through them. We don't care what type of movement
362 * the wall blocks - if it blocks any type of movement, can't be
363 * destroyed right now.
364 */
365 else if ((tmp->material || tmp->materialname) && op->stats.dam > 0 &&
366 !tmp->move_block) {
367 save_throw_object(tmp,type,op);
368 if (was_destroyed (op, op_tag))
369 break;
370 }
371 }
372 return 0; 322 return 0;
373}
374 323
324 /* peterm: a few special cases for special attacktypes --counterspell
325 * must be out here because it strikes things which are not alive
326 */
327
328 if (type & AT_COUNTERSPELL)
329 {
330 counterspell (op, dir); /* see spell_effect.c */
331
332 /* If the only attacktype is counterspell or magic, don't need
333 * to do any further processing.
334 */
335 if (!(type & ~(AT_COUNTERSPELL | AT_MAGIC)))
336 {
337 return 0;
338 }
339 type &= ~AT_COUNTERSPELL;
340 }
341
342 if (type & AT_CHAOS)
343 {
344 shuffle_attack (op, 1); /*1 flag tells it to change the face */
345 update_object (op, UP_OBJ_FACE);
346 type &= ~AT_CHAOS;
347 }
348
349 next = get_map_ob (map, x, y);
350 if (next)
351 next_tag = next->count;
352
353 while (next)
354 {
355 if (was_destroyed (next, next_tag))
356 {
357 /* There may still be objects that were above 'next', but there is no
358 * simple way to find out short of copying all object references and
359 * tags into a temporary array before we start processing the first
360 * object. That's why we just abort.
361 *
362 * This happens whenever attack spells (like fire) hit a pile
363 * of objects. This is not a bug - nor an error. The errormessage
364 * below was spamming the logs for absolutely no reason.
365 */
366 /* LOG (llevDebug, "hit_map(): next object destroyed\n"); */
367 break;
368 }
369 tmp = next;
370 next = tmp->above;
371 if (next)
372 next_tag = next->count;
373
374 if (QUERY_FLAG (tmp, FLAG_FREED))
375 {
376 LOG (llevError, "BUG: hit_map(): found freed object\n");
377 break;
378 }
379
380 /* Something could have happened to 'tmp' while 'tmp->below' was processed.
381 * For example, 'tmp' was put in an icecube.
382 * This is one of the few cases where on_same_map should not be used.
383 */
384 if (tmp->map != map || tmp->x != x || tmp->y != y)
385 continue;
386
387 if (QUERY_FLAG (tmp, FLAG_ALIVE))
388 {
389 hit_player (tmp, op->stats.dam, op, type, full_hit);
390 retflag |= 1;
391 if (was_destroyed (op, op_tag))
392 break;
393 }
394 /* Here we are potentially destroying an object. If the object has
395 * NO_PASS set, it is also immune - you can't destroy walls. Note
396 * that weak walls have is_alive set, which prevent objects from
397 * passing over/through them. We don't care what type of movement
398 * the wall blocks - if it blocks any type of movement, can't be
399 * destroyed right now.
400 */
401 else if ((tmp->material || tmp->materialname) && op->stats.dam > 0 && !tmp->move_block)
402 {
403 save_throw_object (tmp, type, op);
404 if (was_destroyed (op, op_tag))
405 break;
406 }
407 }
408 return 0;
409}
410
411void
375void attack_message(int dam, int type, object *op, object *hitter) { 412attack_message (int dam, int type, object *op, object *hitter)
413{
376 char buf[MAX_BUF], buf1[MAX_BUF], buf2[MAX_BUF]; 414 char buf[MAX_BUF], buf1[MAX_BUF], buf2[MAX_BUF];
377 int i, found=0; 415 int i, found = 0;
378 mapstruct *map; 416 mapstruct *map;
379 object *next, *tmp; 417 object *next, *tmp;
380 418
381 /* put in a few special messages for some of the common attacktypes 419 /* put in a few special messages for some of the common attacktypes
382 * a player might have. For example, fire, electric, cold, etc 420 * a player might have. For example, fire, electric, cold, etc
383 * [garbled 20010919] 421 * [garbled 20010919]
384 */ 422 */
385 423
386 if (dam == 9998 && op->type == DOOR) { 424 if (dam == 9998 && op->type == DOOR)
425 {
387 sprintf(buf1, "unlock %s", op->name); 426 sprintf (buf1, "unlock %s", &op->name);
388 sprintf(buf2, " unlocks"); 427 sprintf (buf2, " unlocks");
389 found++; 428 found++;
429 }
430 if (dam < 0)
390 } 431 {
391 if(dam<0) {
392 sprintf(buf1, "hit %s", op->name); 432 sprintf (buf1, "hit %s", &op->name);
393 sprintf(buf2, " hits"); 433 sprintf (buf2, " hits");
394 found++; 434 found++;
435 }
395 } else if(dam==0) { 436 else if (dam == 0)
437 {
396 sprintf(buf1, "missed %s", op->name); 438 sprintf (buf1, "missed %s", &op->name);
397 sprintf(buf2, " misses"); 439 sprintf (buf2, " misses");
398 found++; 440 found++;
441 }
399 } else if ((hitter->type == DISEASE || hitter->type == SYMPTOM || 442 else if ((hitter->type == DISEASE || hitter->type == SYMPTOM ||
400 hitter->type == POISONING || 443 hitter->type == POISONING || (type & AT_POISON && IS_LIVE (op))) && !found)
401 (type & AT_POISON && IS_LIVE(op))) && !found) { 444 {
402 for (i=0; i < MAXATTACKMESS && attack_mess[ATM_SUFFER][i].level != -1; 445 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_SUFFER][i].level != -1; i++)
403 i++) 446 if (dam < attack_mess[ATM_SUFFER][i].level || attack_mess[ATM_SUFFER][i + 1].level == -1)
404 if (dam < attack_mess[ATM_SUFFER][i].level 447 {
405 || attack_mess[ATM_SUFFER][i+1].level == -1) { 448 sprintf (buf1, "%s %s%s", attack_mess[ATM_SUFFER][i].buf1, &op->name, attack_mess[ATM_SUFFER][i].buf2);
406 sprintf(buf1, "%s %s%s", attack_mess[ATM_SUFFER][i].buf1,
407 op->name, attack_mess[ATM_SUFFER][i].buf2);
408 strcpy (buf2, attack_mess[ATM_SUFFER][i].buf3); 449 strcpy (buf2, attack_mess[ATM_SUFFER][i].buf3);
409 found++; 450 found++;
410 break; 451 break;
452 }
411 } 453 }
412 } else if (op->type == DOOR && !found) { 454 else if (op->type == DOOR && !found)
455 {
413 for (i=0; i < MAXATTACKMESS && attack_mess[ATM_DOOR][i].level != -1; 456 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_DOOR][i].level != -1; i++)
414 i++) 457 if (dam < attack_mess[ATM_DOOR][i].level || attack_mess[ATM_DOOR][i + 1].level == -1)
415 if (dam < attack_mess[ATM_DOOR][i].level 458 {
416 || attack_mess[ATM_DOOR][i+1].level == -1) { 459 sprintf (buf1, "%s %s%s", attack_mess[ATM_DOOR][i].buf1, &op->name, attack_mess[ATM_DOOR][i].buf2);
417 sprintf(buf1, "%s %s%s", attack_mess[ATM_DOOR][i].buf1,
418 op->name, attack_mess[ATM_DOOR][i].buf2);
419 strcpy (buf2, attack_mess[ATM_DOOR][i].buf3); 460 strcpy (buf2, attack_mess[ATM_DOOR][i].buf3);
420 found++; 461 found++;
421 break; 462 break;
463 }
422 } 464 }
423 } else if (hitter->type == PLAYER && IS_LIVE(op)) { 465 else if (hitter->type == PLAYER && IS_LIVE (op))
466 {
424 if (USING_SKILL(hitter, SK_KARATE)) { 467 if (USING_SKILL (hitter, SK_KARATE))
468 {
425 for (i=0; i < MAXATTACKMESS && attack_mess[ATM_KARATE][i].level != -1; 469 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_KARATE][i].level != -1; i++)
426 i++) 470 if (dam < attack_mess[ATM_KARATE][i].level || attack_mess[ATM_KARATE][i + 1].level == -1)
427 if (dam < attack_mess[ATM_KARATE][i].level 471 {
428 || attack_mess[ATM_KARATE][i+1].level == -1) { 472 sprintf (buf1, "%s %s%s", attack_mess[ATM_KARATE][i].buf1, &op->name, attack_mess[ATM_KARATE][i].buf2);
429 sprintf(buf1, "%s %s%s", attack_mess[ATM_KARATE][i].buf1,
430 op->name, attack_mess[ATM_KARATE][i].buf2);
431 strcpy (buf2, attack_mess[ATM_KARATE][i].buf3); 473 strcpy (buf2, attack_mess[ATM_KARATE][i].buf3);
432 found++; 474 found++;
433 break; 475 break;
476 }
434 } 477 }
435 } else if (USING_SKILL(hitter, SK_CLAWING)) { 478 else if (USING_SKILL (hitter, SK_CLAWING))
479 {
436 for (i=0; i < MAXATTACKMESS && attack_mess[ATM_CLAW][i].level != -1; 480 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_CLAW][i].level != -1; i++)
437 i++) 481 if (dam < attack_mess[ATM_CLAW][i].level || attack_mess[ATM_CLAW][i + 1].level == -1)
438 if (dam < attack_mess[ATM_CLAW][i].level 482 {
439 || attack_mess[ATM_CLAW][i+1].level == -1) { 483 sprintf (buf1, "%s %s%s", attack_mess[ATM_CLAW][i].buf1, &op->name, attack_mess[ATM_CLAW][i].buf2);
440 sprintf(buf1, "%s %s%s", attack_mess[ATM_CLAW][i].buf1,
441 op->name, attack_mess[ATM_CLAW][i].buf2);
442 strcpy (buf2, attack_mess[ATM_CLAW][i].buf3); 484 strcpy (buf2, attack_mess[ATM_CLAW][i].buf3);
443 found++; 485 found++;
444 break; 486 break;
487 }
445 } 488 }
446 } else if (USING_SKILL(hitter, SK_PUNCHING)) { 489 else if (USING_SKILL (hitter, SK_PUNCHING))
490 {
447 for (i=0; i < MAXATTACKMESS && attack_mess[ATM_PUNCH][i].level != -1; 491 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_PUNCH][i].level != -1; i++)
448 i++) 492 if (dam < attack_mess[ATM_PUNCH][i].level || attack_mess[ATM_PUNCH][i + 1].level == -1)
449 if (dam < attack_mess[ATM_PUNCH][i].level 493 {
450 || attack_mess[ATM_PUNCH][i+1].level == -1) { 494 sprintf (buf1, "%s %s%s", attack_mess[ATM_PUNCH][i].buf1, &op->name, attack_mess[ATM_PUNCH][i].buf2);
451 sprintf(buf1, "%s %s%s", attack_mess[ATM_PUNCH][i].buf1,
452 op->name, attack_mess[ATM_PUNCH][i].buf2);
453 strcpy (buf2, attack_mess[ATM_PUNCH][i].buf3); 495 strcpy (buf2, attack_mess[ATM_PUNCH][i].buf3);
454 found++; 496 found++;
455 break; 497 break;
498 }
456 } 499 }
457 }
458 } 500 }
459 if (found) { 501 if (found)
460 /* done */ 502 {
503 /* done */
504 }
461 } else if (IS_ARROW(hitter) && (type == AT_PHYSICAL || type == AT_MAGIC)) { 505 else if (IS_ARROW (hitter) && (type == AT_PHYSICAL || type == AT_MAGIC))
506 {
462 sprintf(buf1, "hit"); /* just in case */ 507 sprintf (buf1, "hit"); /* just in case */
463 for (i=0; i < MAXATTACKMESS; i++) 508 for (i = 0; i < MAXATTACKMESS; i++)
464 if (dam < attack_mess[ATM_ARROW][i].level 509 if (dam < attack_mess[ATM_ARROW][i].level || attack_mess[ATM_ARROW][i + 1].level == -1)
465 || attack_mess[ATM_ARROW][i+1].level == -1) { 510 {
466 strcpy (buf2, attack_mess[ATM_ARROW][i].buf3); 511 strcpy (buf2, attack_mess[ATM_ARROW][i].buf3);
467 found++; 512 found++;
468 break; 513 break;
514 }
469 } 515 }
470 } else if (type & AT_DRAIN && IS_LIVE(op)) { 516 else if (type & AT_DRAIN && IS_LIVE (op))
517 {
471 /* drain is first, because some items have multiple attypes */ 518 /* drain is first, because some items have multiple attypes */
472 for (i=0; i < MAXATTACKMESS && attack_mess[ATM_DRAIN][i].level != -1; 519 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_DRAIN][i].level != -1; i++)
473 i++) 520 if (dam < attack_mess[ATM_DRAIN][i].level || attack_mess[ATM_DRAIN][i + 1].level == -1)
474 if (dam < attack_mess[ATM_DRAIN][i].level 521 {
475 || attack_mess[ATM_DRAIN][i+1].level == -1) { 522 sprintf (buf1, "%s %s%s", attack_mess[ATM_DRAIN][i].buf1, &op->name, attack_mess[ATM_DRAIN][i].buf2);
476 sprintf(buf1, "%s %s%s", attack_mess[ATM_DRAIN][i].buf1,
477 op->name, attack_mess[ATM_DRAIN][i].buf2);
478 strcpy (buf2, attack_mess[ATM_DRAIN][i].buf3); 523 strcpy (buf2, attack_mess[ATM_DRAIN][i].buf3);
479 found++; 524 found++;
480 break; 525 break;
526 }
481 } 527 }
482 } else if (type & AT_ELECTRICITY && IS_LIVE(op)) { 528 else if (type & AT_ELECTRICITY && IS_LIVE (op))
529 {
483 for (i=0; i < MAXATTACKMESS && attack_mess[ATM_ELEC][i].level != -1; 530 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_ELEC][i].level != -1; i++)
484 i++) 531 if (dam < attack_mess[ATM_ELEC][i].level || attack_mess[ATM_ELEC][i + 1].level == -1)
485 if (dam < attack_mess[ATM_ELEC][i].level 532 {
486 || attack_mess[ATM_ELEC][i+1].level == -1) { 533 sprintf (buf1, "%s %s%s", attack_mess[ATM_ELEC][i].buf1, &op->name, attack_mess[ATM_ELEC][i].buf2);
487 sprintf(buf1, "%s %s%s", attack_mess[ATM_ELEC][i].buf1,
488 op->name, attack_mess[ATM_ELEC][i].buf2);
489 strcpy (buf2, attack_mess[ATM_ELEC][i].buf3); 534 strcpy (buf2, attack_mess[ATM_ELEC][i].buf3);
490 found++; 535 found++;
491 break; 536 break;
537 }
492 } 538 }
493 } else if (type & AT_COLD && IS_LIVE(op)) { 539 else if (type & AT_COLD && IS_LIVE (op))
540 {
494 for (i=0; i < MAXATTACKMESS && attack_mess[ATM_COLD][i].level != -1; 541 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_COLD][i].level != -1; i++)
495 i++) 542 if (dam < attack_mess[ATM_COLD][i].level || attack_mess[ATM_COLD][i + 1].level == -1)
496 if (dam < attack_mess[ATM_COLD][i].level 543 {
497 || attack_mess[ATM_COLD][i+1].level == -1) { 544 sprintf (buf1, "%s %s%s", attack_mess[ATM_COLD][i].buf1, &op->name, attack_mess[ATM_COLD][i].buf2);
498 sprintf(buf1, "%s %s%s", attack_mess[ATM_COLD][i].buf1,
499 op->name, attack_mess[ATM_COLD][i].buf2);
500 strcpy (buf2, attack_mess[ATM_COLD][i].buf3); 545 strcpy (buf2, attack_mess[ATM_COLD][i].buf3);
501 found++; 546 found++;
502 break; 547 break;
548 }
503 } 549 }
504 } else if (type & AT_FIRE) { 550 else if (type & AT_FIRE)
551 {
505 for (i=0; i < MAXATTACKMESS && attack_mess[ATM_FIRE][i].level != -1; 552 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_FIRE][i].level != -1; i++)
506 i++) 553 if (dam < attack_mess[ATM_FIRE][i].level || attack_mess[ATM_FIRE][i + 1].level == -1)
507 if (dam < attack_mess[ATM_FIRE][i].level 554 {
508 || attack_mess[ATM_FIRE][i+1].level == -1) { 555 sprintf (buf1, "%s %s%s", attack_mess[ATM_FIRE][i].buf1, &op->name, attack_mess[ATM_FIRE][i].buf2);
509 sprintf(buf1, "%s %s%s", attack_mess[ATM_FIRE][i].buf1,
510 op->name, attack_mess[ATM_FIRE][i].buf2);
511 strcpy (buf2, attack_mess[ATM_FIRE][i].buf3); 556 strcpy (buf2, attack_mess[ATM_FIRE][i].buf3);
512 found++; 557 found++;
513 break; 558 break;
559 }
514 } 560 }
515 } else if (hitter->current_weapon != NULL) { 561 else if (hitter->current_weapon != NULL)
516 int mtype; 562 {
563 int mtype;
564
517 switch (hitter->current_weapon->weapontype) { 565 switch (hitter->current_weapon->weapontype)
518 case WEAP_HIT: mtype = ATM_BASIC; break; 566 {
519 case WEAP_SLASH: mtype = ATM_SLASH; break; 567 case WEAP_HIT:
520 case WEAP_PIERCE: mtype = ATM_PIERCE; break; 568 mtype = ATM_BASIC;
521 case WEAP_CLEAVE: mtype = ATM_CLEAVE; break; 569 break;
522 case WEAP_SLICE: mtype = ATM_SLICE; break; 570 case WEAP_SLASH:
523 case WEAP_STAB: mtype = ATM_STAB; break; 571 mtype = ATM_SLASH;
524 case WEAP_WHIP: mtype = ATM_WHIP; break; 572 break;
525 case WEAP_CRUSH: mtype = ATM_CRUSH; break; 573 case WEAP_PIERCE:
526 case WEAP_BLUD: mtype = ATM_BLUD; break; 574 mtype = ATM_PIERCE;
527 default: mtype = ATM_BASIC; break; 575 break;
528 } 576 case WEAP_CLEAVE:
577 mtype = ATM_CLEAVE;
578 break;
579 case WEAP_SLICE:
580 mtype = ATM_SLICE;
581 break;
582 case WEAP_STAB:
583 mtype = ATM_STAB;
584 break;
585 case WEAP_WHIP:
586 mtype = ATM_WHIP;
587 break;
588 case WEAP_CRUSH:
589 mtype = ATM_CRUSH;
590 break;
591 case WEAP_BLUD:
592 mtype = ATM_BLUD;
593 break;
594 default:
595 mtype = ATM_BASIC;
596 break;
597 }
529 for (i=0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; 598 for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++)
530 i++) 599 if (dam < attack_mess[mtype][i].level || attack_mess[mtype][i + 1].level == -1)
531 if (dam < attack_mess[mtype][i].level 600 {
532 || attack_mess[mtype][i+1].level == -1) { 601 sprintf (buf1, "%s %s%s", attack_mess[mtype][i].buf1, &op->name, attack_mess[mtype][i].buf2);
533 sprintf(buf1, "%s %s%s", attack_mess[mtype][i].buf1,
534 op->name, attack_mess[mtype][i].buf2);
535 strcpy (buf2, attack_mess[mtype][i].buf3); 602 strcpy (buf2, attack_mess[mtype][i].buf3);
536 found++; 603 found++;
537 break; 604 break;
605 }
538 } 606 }
539 } else { 607 else
608 {
540 for (i=0; i < MAXATTACKMESS && attack_mess[ATM_BASIC][i].level != -1; 609 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_BASIC][i].level != -1; i++)
541 i++) 610 if (dam < attack_mess[ATM_BASIC][i].level || attack_mess[ATM_BASIC][i + 1].level == -1)
542 if (dam < attack_mess[ATM_BASIC][i].level 611 {
543 || attack_mess[ATM_BASIC][i+1].level == -1) { 612 sprintf (buf1, "%s %s%s", attack_mess[ATM_BASIC][i].buf1, &op->name, attack_mess[ATM_BASIC][i].buf2);
544 sprintf(buf1, "%s %s%s", attack_mess[ATM_BASIC][i].buf1,
545 op->name, attack_mess[ATM_BASIC][i].buf2);
546 strcpy (buf2, attack_mess[ATM_BASIC][i].buf3); 613 strcpy (buf2, attack_mess[ATM_BASIC][i].buf3);
547 found++; 614 found++;
548 break; 615 break;
616 }
549 } 617 }
550 }
551 618
552 if (!found) { 619 if (!found)
620 {
553 strcpy (buf1, "hit"); 621 strcpy (buf1, "hit");
554 strcpy (buf2, " hits"); 622 strcpy (buf2, " hits");
555 } 623 }
556 624
557 /* bail out if a monster is casting spells */ 625 /* bail out if a monster is casting spells */
558 if (!(hitter->type == PLAYER ||
559 (get_owner(hitter) != NULL && hitter->owner->type == PLAYER))) 626 if (!(hitter->type == PLAYER || (get_owner (hitter) != NULL && hitter->owner->type == PLAYER)))
560 return; 627 return;
561 628
562 /* scale down magic considerably. */ 629 /* scale down magic considerably. */
563 if (type & AT_MAGIC && rndm(0, 5)) 630 if (type & AT_MAGIC && rndm (0, 5))
564 return; 631 return;
565 632
566 /* Did a player hurt another player? Inform both! */ 633 /* Did a player hurt another player? Inform both! */
567 if(op->type==PLAYER &&
568 (get_owner(hitter)==NULL?hitter->type:hitter->owner->type)==PLAYER) { 634 if (op->type == PLAYER && (get_owner (hitter) == NULL ? hitter->type : hitter->owner->type) == PLAYER)
635 {
569 if(get_owner(hitter)!=NULL) 636 if (get_owner (hitter) != NULL)
570 sprintf(buf,"%s's %s%s you.", 637 sprintf (buf, "%s's %s%s you.", &hitter->owner->name, &hitter->name, buf2);
571 hitter->owner->name, hitter->name, buf2); 638 else
572 else { 639 {
573 sprintf(buf,"%s%s you.",hitter->name, buf2); 640 sprintf (buf, "%s%s you.", &hitter->name, buf2);
574 if (dam != 0) { 641 if (dam != 0)
575 if (dam < 10) 642 {
643 if (dam < 10)
576 play_sound_player_only(op->contr, SOUND_PLAYER_IS_HIT1,0,0); 644 play_sound_player_only (op->contr, SOUND_PLAYER_IS_HIT1, 0, 0);
577 else if (dam < 20) 645 else if (dam < 20)
578 play_sound_player_only(op->contr, SOUND_PLAYER_IS_HIT2,0,0); 646 play_sound_player_only (op->contr, SOUND_PLAYER_IS_HIT2, 0, 0);
579 else 647 else
580 play_sound_player_only(op->contr, SOUND_PLAYER_IS_HIT3,0,0); 648 play_sound_player_only (op->contr, SOUND_PLAYER_IS_HIT3, 0, 0);
581 } 649 }
582 } 650 }
583 new_draw_info(NDI_BLACK, 0,op,buf); 651 new_draw_info (NDI_BLACK, 0, op, buf);
584 } /* end of player hitting player */ 652 } /* end of player hitting player */
585 653
586 if(hitter->type==PLAYER) { 654 if (hitter->type == PLAYER)
655 {
587 sprintf(buf,"You %s.",buf1); 656 sprintf (buf, "You %s.", buf1);
588 if (dam != 0) { 657 if (dam != 0)
658 {
589 if (dam < 10) 659 if (dam < 10)
590 play_sound_player_only(hitter->contr, SOUND_PLAYER_HITS1,0,0); 660 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS1, 0, 0);
591 else if (dam < 20) 661 else if (dam < 20)
592 play_sound_player_only(hitter->contr, SOUND_PLAYER_HITS2,0,0); 662 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS2, 0, 0);
593 else 663 else
594 play_sound_player_only(hitter->contr, SOUND_PLAYER_HITS3,0,0); 664 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS3, 0, 0);
595 } 665 }
596 new_draw_info(NDI_BLACK, 0, hitter, buf); 666 new_draw_info (NDI_BLACK, 0, hitter, buf);
667 }
597 } else if(get_owner(hitter)!=NULL&&hitter->owner->type==PLAYER) { 668 else if (get_owner (hitter) != NULL && hitter->owner->type == PLAYER)
669 {
598 /* look for stacked spells and start reducing the message chances */ 670 /* look for stacked spells and start reducing the message chances */
599 if (hitter->type == SPELL_EFFECT && 671 if (hitter->type == SPELL_EFFECT && (hitter->subtype == SP_EXPLOSION || hitter->subtype == SP_BULLET || hitter->subtype == SP_CONE))
600 (hitter->subtype == SP_EXPLOSION || 672 {
601 hitter->subtype == SP_BULLET || 673 i = 4;
602 hitter->subtype == SP_CONE)) {
603 i=4;
604 map = hitter->map; 674 map = hitter->map;
605 if (out_of_map(map, hitter->x, hitter->y)) 675 if (out_of_map (map, hitter->x, hitter->y))
676 return;
677 next = get_map_ob (map, hitter->x, hitter->y);
678 if (next)
679 while (next)
680 {
681 if (next->type == SPELL_EFFECT && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE))
682 i *= 3;
683 tmp = next;
684 next = tmp->above;
685 }
686 if (i < 0)
687 return;
688 if (rndm (0, i) != 0)
689 return;
690 }
691 else if (rndm (0, 5) != 0)
606 return; 692 return;
607 next = get_map_ob(map, hitter->x, hitter->y);
608 if (next)
609 while(next) {
610 if (next->type == SPELL_EFFECT &&
611 (next->subtype == SP_EXPLOSION || next->subtype==SP_BULLET ||
612 next->subtype == SP_CONE))
613 i*=3;
614 tmp = next;
615 next = tmp->above;
616 }
617 if (i < 0)
618 return;
619 if (rndm(0, i) != 0)
620 return;
621 } else if (rndm(0, 5) != 0)
622 return;
623 sprintf(buf,"Your %s%s %s.", hitter->name, buf2, op->name); 693 sprintf (buf, "Your %s%s %s.", &hitter->name, buf2, &op->name);
624 play_sound_map(op->map, op->x, op->y, SOUND_PLAYER_HITS4); 694 play_sound_map (op->map, op->x, op->y, SOUND_PLAYER_HITS4);
625 new_draw_info(NDI_BLACK, 0, hitter->owner, buf); 695 new_draw_info (NDI_BLACK, 0, hitter->owner, buf);
626 } 696 }
627} 697}
628 698
629 699
700static int
630static int get_attack_mode (object **target, object **hitter, 701get_attack_mode (object **target, object **hitter, int *simple_attack)
631 int *simple_attack)
632{ 702{
633 if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) { 703 if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED))
704 {
634 LOG (llevError, "BUG: get_attack_mode(): freed object\n"); 705 LOG (llevError, "BUG: get_attack_mode(): freed object\n");
635 return 1; 706 return 1;
636 } 707 }
637 if ((*target)->head) 708 if ((*target)->head)
638 *target = (*target)->head; 709 *target = (*target)->head;
639 if ((*hitter)->head) 710 if ((*hitter)->head)
640 *hitter = (*hitter)->head; 711 *hitter = (*hitter)->head;
641 if ((*hitter)->env != NULL || (*target)->env != NULL) { 712 if ((*hitter)->env != NULL || (*target)->env != NULL)
713 {
642 *simple_attack = 1; 714 *simple_attack = 1;
643 return 0; 715 return 0;
644 } 716 }
645 if (QUERY_FLAG (*target, FLAG_REMOVED) 717 if (QUERY_FLAG (*target, FLAG_REMOVED)
646 || QUERY_FLAG (*hitter, FLAG_REMOVED)
647 || (*hitter)->map == NULL || !on_same_map((*hitter), (*target))) 718 || QUERY_FLAG (*hitter, FLAG_REMOVED) || (*hitter)->map == NULL || !on_same_map ((*hitter), (*target)))
648 { 719 {
649 LOG (llevError, "BUG: hitter (arch %s, name %s) with no relation to " 720 LOG (llevError, "BUG: hitter (arch %s, name %s) with no relation to " "target\n", &(*hitter)->arch->name, &(*hitter)->name);
650 "target\n", (*hitter)->arch->name, (*hitter)->name);
651 return 1; 721 return 1;
652 } 722 }
653 *simple_attack = 0; 723 *simple_attack = 0;
654 return 0; 724 return 0;
655} 725}
656 726
727static int
657static int abort_attack (object *target, object *hitter, int simple_attack) 728abort_attack (object *target, object *hitter, int simple_attack)
658{ 729{
730
659/* Check if target and hitter are still in a relation similar to the one 731/* Check if target and hitter are still in a relation similar to the one
660 * determined by get_attack_mode(). Returns true if the relation has changed. 732 * determined by get_attack_mode(). Returns true if the relation has changed.
661 */ 733 */
662 int new_mode; 734 int new_mode;
663 735
664 if (hitter->env == target || target->env == hitter) 736 if (hitter->env == target || target->env == hitter)
665 new_mode = 1; 737 new_mode = 1;
666 else if (QUERY_FLAG (hitter, FLAG_REMOVED) 738 else if (QUERY_FLAG (hitter, FLAG_REMOVED) || QUERY_FLAG (target, FLAG_REMOVED) || hitter->map == NULL || !on_same_map (hitter, target))
667 || QUERY_FLAG (target, FLAG_REMOVED)
668 || hitter->map == NULL || !on_same_map(hitter, target))
669 return 1; 739 return 1;
670 else 740 else
671 new_mode = 0; 741 new_mode = 0;
672 return new_mode != simple_attack; 742 return new_mode != simple_attack;
673} 743}
674 744
675static void thrown_item_effect (object *, object *); 745static void thrown_item_effect (object *, object *);
676 746
747static int
677static int attack_ob_simple (object *op, object *hitter, int base_dam, 748attack_ob_simple (object *op, object *hitter, int base_dam, int base_wc)
678 int base_wc)
679{ 749{
680 int simple_attack, roll, dam=0; 750 int simple_attack, roll, dam = 0;
681 uint32 type; 751 uint32 type;
682 const char *op_name = NULL; 752 shstr op_name;
683 tag_t op_tag, hitter_tag; 753 tag_t op_tag, hitter_tag;
684 754
685 if (get_attack_mode (&op, &hitter, &simple_attack)) 755 if (get_attack_mode (&op, &hitter, &simple_attack))
756 goto error;
757
758 if (hitter->current_weapon)
759 if (INVOKE_OBJECT (WEAPON_ATTACK, hitter->current_weapon, ARG_OBJECT (hitter), ARG_OBJECT (op)))
760 return RESULT_INT (0);
761
762 if (INVOKE_OBJECT (ATTACK, op, ARG_OBJECT (hitter)))
763 return RESULT_INT (0);
764
765 op_tag = op->count;
766 hitter_tag = hitter->count;
767
768 /*
769 * A little check to make it more difficult to dance forward and back
770 * to avoid ever being hit by monsters.
771 */
772 if (!simple_attack && QUERY_FLAG (op, FLAG_MONSTER) && op->speed_left > -(FABS (op->speed)) * 0.3)
773 {
774 /* Decrease speed BEFORE calling process_object. Otherwise, an
775 * infinite loop occurs, with process_object calling move_monster,
776 * which then gets here again. By decreasing the speed before
777 * we call process_object, the 'if' statement above will fail.
778 */
779 op->speed_left--;
780 process_object (op);
781 if (was_destroyed (op, op_tag) || was_destroyed (hitter, hitter_tag) || abort_attack (op, hitter, simple_attack))
686 goto error; 782 goto error;
687
688 if (hitter->current_weapon)
689 if (INVOKE_OBJECT (ATTACKS, hitter->current_weapon, ARG_OBJECT (hitter), ARG_OBJECT (op)))
690 return RESULT_INT (0);
691
692 if (INVOKE_OBJECT (ATTACK, op, ARG_OBJECT (hitter)))
693 return RESULT_INT (0);
694
695 op_tag = op->count;
696 hitter_tag = hitter->count;
697
698 /*
699 * A little check to make it more difficult to dance forward and back
700 * to avoid ever being hit by monsters.
701 */
702 if ( ! simple_attack && QUERY_FLAG (op, FLAG_MONSTER)
703 && op->speed_left > -(FABS(op->speed))*0.3)
704 { 783 }
705 /* Decrease speed BEFORE calling process_object. Otherwise, an
706 * infinite loop occurs, with process_object calling move_monster,
707 * which then gets here again. By decreasing the speed before
708 * we call process_object, the 'if' statement above will fail.
709 */
710 op->speed_left--;
711 process_object(op);
712 if (was_destroyed (op, op_tag) || was_destroyed (hitter, hitter_tag)
713 || abort_attack (op, hitter, simple_attack))
714 goto error;
715 }
716 784
717 add_refcount(op_name = op->name); 785 op_name = op->name;
718 786
719 roll=random_roll(1, 20, hitter, PREFER_HIGH); 787 roll = random_roll (1, 20, hitter, PREFER_HIGH);
720 788
721 /* Adjust roll for various situations. */ 789 /* Adjust roll for various situations. */
722 if ( ! simple_attack) 790 if (!simple_attack)
723 roll += adj_attackroll(hitter,op); 791 roll += adj_attackroll (hitter, op);
724 792
725 /* See if we hit the creature */ 793 /* See if we hit the creature */
726 if(roll==20 || op->stats.ac>=base_wc-roll) { 794 if (roll == 20 || op->stats.ac >= base_wc - roll)
795 {
727 int hitdam = base_dam; 796 int hitdam = base_dam;
797
728 if (settings.casting_time == TRUE) { 798 if (settings.casting_time == TRUE)
799 {
729 if ((hitter->type == PLAYER)&&(hitter->casting_time > -1)){ 800 if ((hitter->type == PLAYER) && (hitter->casting_time > -1))
730 hitter->casting_time = -1;
731 new_draw_info(NDI_UNIQUE, 0,hitter,"You attacked and lost "
732 "your spell!");
733 }
734 if ((op->casting_time > -1)&&(hitdam > 0)){
735 op->casting_time = -1;
736 if (op->type == PLAYER) {
737 new_draw_info(NDI_UNIQUE, 0,op,"You were hit and lost "
738 "your spell!");
739 new_draw_info_format(NDI_ALL|NDI_UNIQUE,5,NULL,
740 "%s was hit by %s and lost a spell.",
741 op_name,hitter->name);
742 }
743 }
744 }
745 if ( ! simple_attack)
746 { 801 {
747 /* If you hit something, the victim should *always* wake up. 802 hitter->casting_time = -1;
748 * Before, invisible hitters could avoid doing this. 803 new_draw_info (NDI_UNIQUE, 0, hitter, "You attacked and lost " "your spell!");
749 * -b.t. */
750 if (QUERY_FLAG (op, FLAG_SLEEP))
751 CLEAR_FLAG(op,FLAG_SLEEP);
752
753 /* If the victim can't see the attacker, it may alert others
754 * for help. */
755 if (op->type != PLAYER && ! can_see_enemy (op, hitter)
756 && ! get_owner (op) && rndm(0, op->stats.Int))
757 npc_call_help (op);
758
759 /* if you were hidden and hit by a creature, you are discovered*/
760 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE)) {
761 make_visible (op);
762 if (op->type == PLAYER)
763 new_draw_info (NDI_UNIQUE, 0, op,
764 "You were hit by a wild attack. "
765 "You are no longer hidden!");
766 } 804 }
805 if ((op->casting_time > -1) && (hitdam > 0))
806 {
807 op->casting_time = -1;
808 if (op->type == PLAYER)
809 {
810 new_draw_info (NDI_UNIQUE, 0, op, "You were hit and lost " "your spell!");
811 new_draw_info_format (NDI_ALL | NDI_UNIQUE, 5, NULL, "%s was hit by %s and lost a spell.", &op_name, &hitter->name);
812 }
813 }
814 }
815 if (!simple_attack)
816 {
817 /* If you hit something, the victim should *always* wake up.
818 * Before, invisible hitters could avoid doing this.
819 * -b.t. */
820 if (QUERY_FLAG (op, FLAG_SLEEP))
821 CLEAR_FLAG (op, FLAG_SLEEP);
767 822
823 /* If the victim can't see the attacker, it may alert others
824 * for help. */
825 if (op->type != PLAYER && !can_see_enemy (op, hitter) && !get_owner (op) && rndm (0, op->stats.Int))
826 npc_call_help (op);
827
828 /* if you were hidden and hit by a creature, you are discovered */
829 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE))
830 {
831 make_visible (op);
832 if (op->type == PLAYER)
833 new_draw_info (NDI_UNIQUE, 0, op, "You were hit by a wild attack. " "You are no longer hidden!");
834 }
835
768 /* thrown items (hitter) will have various effects 836 /* thrown items (hitter) will have various effects
769 * when they hit the victim. For things like thrown daggers, 837 * when they hit the victim. For things like thrown daggers,
770 * this sets 'hitter' to the actual dagger, and not the 838 * this sets 'hitter' to the actual dagger, and not the
771 * wrapper object. 839 * wrapper object.
772 */ 840 */
773 thrown_item_effect (hitter, op); 841 thrown_item_effect (hitter, op);
774 if (was_destroyed (hitter, hitter_tag) 842 if (was_destroyed (hitter, hitter_tag) || was_destroyed (op, op_tag) || abort_attack (op, hitter, simple_attack))
775 || was_destroyed (op, op_tag)
776 || abort_attack (op, hitter, simple_attack))
777 goto leave; 843 goto leave;
778 } 844 }
779 845
780 /* Need to do at least 1 damage, otherwise there is no point 846 /* Need to do at least 1 damage, otherwise there is no point
781 * to go further and it will cause FPE's below. 847 * to go further and it will cause FPE's below.
782 */ 848 */
783 if (hitdam<=0) hitdam=1; 849 if (hitdam <= 0)
850 hitdam = 1;
784 851
785 type=hitter->attacktype; 852 type = hitter->attacktype;
786 if(!type) type=AT_PHYSICAL; 853 if (!type)
854 type = AT_PHYSICAL;
787 /* Handle monsters that hit back */ 855 /* Handle monsters that hit back */
788 if ( ! simple_attack && QUERY_FLAG (op, FLAG_HITBACK) 856 if (!simple_attack && QUERY_FLAG (op, FLAG_HITBACK) && QUERY_FLAG (hitter, FLAG_ALIVE))
789 && QUERY_FLAG (hitter, FLAG_ALIVE)) 857 {
790 {
791 if (op->attacktype & AT_ACID && hitter->type==PLAYER) 858 if (op->attacktype & AT_ACID && hitter->type == PLAYER)
792 new_draw_info(NDI_UNIQUE, 0,hitter,"You are splashed by acid!\n"); 859 new_draw_info (NDI_UNIQUE, 0, hitter, "You are splashed by acid!\n");
793 hit_player(hitter, random_roll(0, (op->stats.dam), hitter, 860 hit_player (hitter, random_roll (0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1);
794 PREFER_LOW),op, op->attacktype, 1); 861 if (was_destroyed (op, op_tag) || was_destroyed (hitter, hitter_tag) || abort_attack (op, hitter, simple_attack))
795 if (was_destroyed (op, op_tag)
796 || was_destroyed (hitter, hitter_tag)
797 || abort_attack (op, hitter, simple_attack))
798 goto leave; 862 goto leave;
799 } 863 }
800 864
801 /* In the new attack code, it should handle multiple attack 865 /* In the new attack code, it should handle multiple attack
802 * types in its area, so remove it from here. 866 * types in its area, so remove it from here.
803 */ 867 */
804 dam=hit_player(op, random_roll(1, hitdam, hitter, PREFER_HIGH), 868 dam = hit_player (op, random_roll (1, hitdam, hitter, PREFER_HIGH), hitter, type, 1);
805 hitter, type, 1); 869 if (was_destroyed (op, op_tag) || was_destroyed (hitter, hitter_tag) || abort_attack (op, hitter, simple_attack))
806 if (was_destroyed (op, op_tag) || was_destroyed (hitter, hitter_tag)
807 || abort_attack (op, hitter, simple_attack))
808 goto leave; 870 goto leave;
809 } /* end of if hitter hit op */ 871 } /* end of if hitter hit op */
810 /* if we missed, dam=0 */ 872 /* if we missed, dam=0 */
811 873
812 /*attack_message(dam, type, op, hitter);*/ 874 /*attack_message(dam, type, op, hitter); */
813 875
814 goto leave; 876 goto leave;
815 877
816 error: 878error:
817 dam = 1; 879 dam = 1;
818 880
819 leave: 881leave:
820 if (op_name)
821 free_string (op_name);
822 882
823 return dam; 883 return dam;
824} 884}
825 885
886int
826int attack_ob (object *op, object *hitter) 887attack_ob (object *op, object *hitter)
827{ 888{
828 889
829 if (hitter->head) 890 if (hitter->head)
830 hitter = hitter->head; 891 hitter = hitter->head;
831 return attack_ob_simple (op, hitter, hitter->stats.dam, hitter->stats.wc); 892 return attack_ob_simple (op, hitter, hitter->stats.dam, hitter->stats.wc);
832} 893}
833 894
834/* op is the arrow, tmp is what is stopping the arrow. 895/* op is the arrow, tmp is what is stopping the arrow.
835 * 896 *
836 * Returns 1 if op was inserted into tmp's inventory, 0 otherwise. 897 * Returns 1 if op was inserted into tmp's inventory, 0 otherwise.
837 */ 898 */
899static int
838static int stick_arrow (object *op, object *tmp) 900stick_arrow (object *op, object *tmp)
839{ 901{
840 /* If the missile hit a player, we insert it in their inventory. 902 /* If the missile hit a player, we insert it in their inventory.
841 * However, if the missile is heavy, we don't do so (assume it falls 903 * However, if the missile is heavy, we don't do so (assume it falls
842 * to the ground after a hit). What a good value for this is up to 904 * to the ground after a hit). What a good value for this is up to
843 * debate - 5000 is 5 kg, so arrows, knives, and other light weapons 905 * debate - 5000 is 5 kg, so arrows, knives, and other light weapons
844 * stick around. 906 * stick around.
845 */ 907 */
846 if (op->weight <= 5000 && tmp->stats.hp >= 0) { 908 if (op->weight <= 5000 && tmp->stats.hp >= 0)
909 {
847 if(tmp->head != NULL) 910 if (tmp->head != NULL)
848 tmp = tmp->head; 911 tmp = tmp->head;
912
849 remove_ob (op); 913 remove_ob (op);
850 op = insert_ob_in_ob(op,tmp); 914 op = insert_ob_in_ob (op, tmp);
915
851 if (tmp->type== PLAYER) 916 if (tmp->type == PLAYER)
852 esrv_send_item (tmp, op); 917 esrv_send_item (tmp, op);
918
853 return 1; 919 return 1;
920 }
854 } else 921 else
855 return 0; 922 return 0;
856} 923}
857 924
858/* hit_with_arrow() disassembles the missile, attacks the victim and 925/* hit_with_arrow() disassembles the missile, attacks the victim and
859 * reassembles the missile. 926 * reassembles the missile.
860 * 927 *
861 * It returns a pointer to the reassembled missile, or NULL if the missile 928 * It returns a pointer to the reassembled missile, or NULL if the missile
862 * isn't available anymore. 929 * isn't available anymore.
863 */ 930 */
931object *
864object *hit_with_arrow (object *op, object *victim) 932hit_with_arrow (object *op, object *victim)
865{ 933{
866 object *container, *hitter; 934 object *container, *hitter;
867 int hit_something = 0; 935 int hit_something = 0;
868 tag_t victim_tag, hitter_tag; 936 tag_t victim_tag, hitter_tag;
869 sint16 victim_x, victim_y; 937 sint16 victim_x, victim_y;
870 938
871 /* Disassemble missile */ 939 /* Disassemble missile */
872 if (op->inv) { 940 if (op->inv)
941 {
873 container = op; 942 container = op;
874 hitter = op->inv; 943 hitter = op->inv;
875 remove_ob (hitter); 944 remove_ob (hitter);
876 insert_ob_in_map(hitter, container->map,hitter,INS_NO_MERGE | INS_NO_WALK_ON); 945 insert_ob_in_map (hitter, container->map, hitter, INS_NO_MERGE | INS_NO_WALK_ON);
877 /* Note that we now have an empty THROWN_OBJ on the map. Code that 946 /* Note that we now have an empty THROWN_OBJ on the map. Code that
878 * might be called until this THROWN_OBJ is either reassembled or 947 * might be called until this THROWN_OBJ is either reassembled or
879 * removed at the end of this function must be able to deal with empty 948 * removed at the end of this function must be able to deal with empty
880 * THROWN_OBJs. */ 949 * THROWN_OBJs. */
881 } else { 950 }
951 else
952 {
882 container = NULL; 953 container = NULL;
883 hitter = op; 954 hitter = op;
884 } 955 }
885 956
886 /* Try to hit victim */ 957 /* Try to hit victim */
887 victim_x = victim->x; 958 victim_x = victim->x;
888 victim_y = victim->y; 959 victim_y = victim->y;
889 victim_tag = victim->count; 960 victim_tag = victim->count;
890 hitter_tag = hitter->count; 961 hitter_tag = hitter->count;
891 962
892 hit_something = attack_ob_simple (victim, hitter, op->stats.dam, op->stats.wc); 963 hit_something = attack_ob_simple (victim, hitter, op->stats.dam, op->stats.wc);
893 964
894 /* Arrow attacks door, rune of summoning is triggered, demon is put on 965 /* Arrow attacks door, rune of summoning is triggered, demon is put on
895 * arrow, move_apply() calls this function, arrow sticks in demon, 966 * arrow, move_apply() calls this function, arrow sticks in demon,
896 * attack_ob_simple() returns, and we've got an arrow that still exists 967 * attack_ob_simple() returns, and we've got an arrow that still exists
897 * but is no longer on the map. Ugh. (Beware: Such things can happen at 968 * but is no longer on the map. Ugh. (Beware: Such things can happen at
898 * other places as well!) 969 * other places as well!)
899 */ 970 */
900 if (was_destroyed (hitter, hitter_tag) || hitter->env != NULL) { 971 if (was_destroyed (hitter, hitter_tag) || hitter->env != NULL)
972 {
901 if (container) { 973 if (container)
974 {
902 remove_ob (container); 975 remove_ob (container);
903 free_object (container); 976 free_object (container);
977 }
978 return NULL;
979 }
980
981 /* Missile hit victim */
982 /* if the speed is > 10, then this is a fast moving arrow, we go straight
983 * through the target
984 */
985 if (hit_something && op->speed <= 10.0)
986 {
987 /* Stop arrow */
988 if (container == NULL)
904 } 989 {
990 hitter = fix_stopped_arrow (hitter);
991 if (hitter == NULL)
992 return NULL;
993 }
994 else
995 {
996 remove_ob (container);
997 free_object (container);
998 }
999
1000 /* Try to stick arrow into victim */
1001 if (!was_destroyed (victim, victim_tag) && stick_arrow (hitter, victim))
905 return NULL; 1002 return NULL;
906 }
907 1003
908 /* Missile hit victim */
909 /* if the speed is > 10, then this is a fast moving arrow, we go straight
910 * through the target
911 */
912 if (hit_something && op->speed <= 10.0)
913 {
914 /* Stop arrow */
915 if (container == NULL) {
916 hitter = fix_stopped_arrow (hitter);
917 if (hitter == NULL)
918 return NULL;
919 } else {
920 remove_ob (container);
921 free_object (container);
922 }
923
924 /* Try to stick arrow into victim */
925 if ( ! was_destroyed (victim, victim_tag)
926 && stick_arrow (hitter, victim))
927 return NULL;
928
929 /* Else try to put arrow on victim's map square 1004 /* Else try to put arrow on victim's map square
930 * remove check for P_WALL here. If the arrow got to this 1005 * remove check for P_WALL here. If the arrow got to this
931 * space, that is good enough - with the new movement code, 1006 * space, that is good enough - with the new movement code,
932 * there is now the potential for lots of spaces where something 1007 * there is now the potential for lots of spaces where something
933 * can fly over but not otherwise move over. What is the correct 1008 * can fly over but not otherwise move over. What is the correct
934 * way to handle those otherwise? 1009 * way to handle those otherwise?
935 */ 1010 */
936 if (victim_x != hitter->x || victim_y != hitter->y) { 1011 if (victim_x != hitter->x || victim_y != hitter->y)
1012 {
937 remove_ob (hitter); 1013 remove_ob (hitter);
938 hitter->x = victim_x; 1014 hitter->x = victim_x;
939 hitter->y = victim_y; 1015 hitter->y = victim_y;
940 insert_ob_in_map (hitter, victim->map, hitter,0); 1016 insert_ob_in_map (hitter, victim->map, hitter, 0);
1017 }
941 } else { 1018 else
1019 {
942 /* Else leave arrow where it is */ 1020 /* Else leave arrow where it is */
943 merge_ob (hitter, NULL); 1021 merge_ob (hitter, NULL);
944 } 1022 }
945 return NULL; 1023 return NULL;
946 } 1024 }
947 1025
948 if (hit_something && op->speed >= 10.0) 1026 if (hit_something && op->speed >= 10.0)
949 op->speed -= 1.0; 1027 op->speed -= 1.0;
950 1028
951 /* Missile missed victim - reassemble missile */ 1029 /* Missile missed victim - reassemble missile */
952 if (container) { 1030 if (container)
1031 {
953 remove_ob (hitter); 1032 remove_ob (hitter);
954 insert_ob_in_ob (hitter, container); 1033 insert_ob_in_ob (hitter, container);
955 } 1034 }
956 return op; 1035 return op;
957} 1036}
958 1037
959 1038
1039void
960void tear_down_wall(object *op) 1040tear_down_wall (object *op)
961{ 1041{
962 int perc=0; 1042 int perc = 0;
963 1043
964 if (!op->stats.maxhp) { 1044 if (!op->stats.maxhp)
1045 {
965 LOG(llevError, "TEAR_DOWN wall %s had no maxhp.\n", op->name); 1046 LOG (llevError, "TEAR_DOWN wall %s had no maxhp.\n", &op->name);
966 perc = 1; 1047 perc = 1;
1048 }
967 } else if(!GET_ANIM_ID(op)) { 1049 else if (!GET_ANIM_ID (op))
1050 {
968 /* Object has been called - no animations, so remove it */ 1051 /* Object has been called - no animations, so remove it */
969 if(op->stats.hp<0) { 1052 if (op->stats.hp < 0)
1053 {
970 remove_ob(op); /* Should update LOS */ 1054 remove_ob (op); /* Should update LOS */
971 free_object(op); 1055 free_object (op);
972 /* Don't know why this is here - remove_ob should do it for us */ 1056 /* Don't know why this is here - remove_ob should do it for us */
973 /*update_position(m, x, y);*/ 1057 /*update_position(m, x, y); */
974 } 1058 }
975 return; /* no animations, so nothing more to do */ 1059 return; /* no animations, so nothing more to do */
976 } 1060 }
977 perc = NUM_ANIMATIONS(op) 1061 perc = NUM_ANIMATIONS (op) - ((int) NUM_ANIMATIONS (op) * op->stats.hp) / op->stats.maxhp;
978 - ((int)NUM_ANIMATIONS(op)*op->stats.hp)/op->stats.maxhp;
979 if (perc >= (int) NUM_ANIMATIONS(op)) 1062 if (perc >= (int) NUM_ANIMATIONS (op))
980 perc = NUM_ANIMATIONS(op)-1; 1063 perc = NUM_ANIMATIONS (op) - 1;
981 else if (perc < 1) 1064 else if (perc < 1)
982 perc = 1; 1065 perc = 1;
983 SET_ANIMATION(op, perc); 1066 SET_ANIMATION (op, perc);
984 update_object(op,UP_OBJ_FACE); 1067 update_object (op, UP_OBJ_FACE);
985 if(perc==NUM_ANIMATIONS(op)-1) { /* Reached the last animation */ 1068 if (perc == NUM_ANIMATIONS (op) - 1)
1069 { /* Reached the last animation */
986 if(op->face==blank_face) { 1070 if (op->face == blank_face)
1071 {
987 /* If the last face is blank, remove the ob */ 1072 /* If the last face is blank, remove the ob */
988 remove_ob(op); /* Should update LOS */ 1073 remove_ob (op); /* Should update LOS */
989 free_object(op); 1074 free_object (op);
990 1075
991 /* remove_ob should call update_position for us */ 1076 /* remove_ob should call update_position for us */
992 /*update_position(m, x, y);*/ 1077 /*update_position(m, x, y); */
993 1078
994 } else { /* The last face was not blank, leave an image */ 1079 }
1080 else
1081 { /* The last face was not blank, leave an image */
995 CLEAR_FLAG(op, FLAG_BLOCKSVIEW); 1082 CLEAR_FLAG (op, FLAG_BLOCKSVIEW);
996 update_all_los(op->map, op->x, op->y); 1083 update_all_los (op->map, op->x, op->y);
997 op->move_block = 0; 1084 op->move_block = 0;
998 CLEAR_FLAG(op, FLAG_ALIVE); 1085 CLEAR_FLAG (op, FLAG_ALIVE);
999 } 1086 }
1000 } 1087 }
1001} 1088}
1002 1089
1090void
1003void scare_creature(object *target, object *hitter) 1091scare_creature (object *target, object *hitter)
1004{ 1092{
1005 object *owner = get_owner(hitter); 1093 object *owner = get_owner (hitter);
1006 1094
1007 if (!owner) owner=hitter; 1095 if (!owner)
1096 owner = hitter;
1008 1097
1009 SET_FLAG(target, FLAG_SCARED); 1098 SET_FLAG (target, FLAG_SCARED);
1010 if (!target->enemy) target->enemy=owner; 1099 if (!target->enemy)
1100 target->enemy = owner;
1011} 1101}
1012 1102
1013 1103
1014/* This returns the amount of damage hitter does to op with the 1104/* This returns the amount of damage hitter does to op with the
1015 * appropriate attacktype. Only 1 attacktype should be set at a time. 1105 * appropriate attacktype. Only 1 attacktype should be set at a time.
1016 * This doesn't damage the player, but returns how much it should 1106 * This doesn't damage the player, but returns how much it should
1017 * take. However, it will do other effects (paralyzation, slow, etc.) 1107 * take. However, it will do other effects (paralyzation, slow, etc.)
1018 * Note - changed for PR code - we now pass the attack number and not 1108 * Note - changed for PR code - we now pass the attack number and not
1019 * the attacktype. Makes it easier for the PR code. */ 1109 * the attacktype. Makes it easier for the PR code. */
1020 1110
1111int
1021int hit_player_attacktype(object *op, object *hitter, int dam, 1112hit_player_attacktype (object *op, object *hitter, int dam, uint32 attacknum, int magic)
1022 uint32 attacknum, int magic) { 1113{
1023 1114
1024 int doesnt_slay = 1; 1115 int doesnt_slay = 1;
1025 1116
1026 /* Catch anyone that may be trying to send us a bitmask instead of the number */ 1117 /* Catch anyone that may be trying to send us a bitmask instead of the number */
1027 if (attacknum >= NROFATTACKS) { 1118 if (attacknum >= NROFATTACKS)
1119 {
1028 LOG(llevError, "hit_player_attacktype: Invalid attacknumber passed: %u\n", attacknum); 1120 LOG (llevError, "hit_player_attacktype: Invalid attacknumber passed: %u\n", attacknum);
1029 return 0; 1121 return 0;
1030 }
1031 1122 }
1123
1032 if (dam < 0) { 1124 if (dam < 0)
1125 {
1033 LOG(llevError,"hit_player_attacktype called with negative damage: %d\n", dam); 1126 LOG (llevError, "hit_player_attacktype called with negative damage: %d\n", dam);
1034 return 0; 1127 return 0;
1035 }
1036 1128 }
1129
1037 /* AT_INTERNAL is supposed to do exactly dam. Put a case here so 1130 /* AT_INTERNAL is supposed to do exactly dam. Put a case here so
1038 * people can't mess with that or it otherwise get confused. */ 1131 * people can't mess with that or it otherwise get confused. */
1039 if (attacknum == ATNR_INTERNAL) return dam; 1132 if (attacknum == ATNR_INTERNAL)
1040 1133 return dam;
1134
1041 if (hitter->slaying) { 1135 if (hitter->slaying)
1136 {
1042 if(((op->race != NULL) && strstr(hitter->slaying, op->race)) || 1137 if (((op->race != NULL) && strstr (hitter->slaying, op->race)) ||
1043 (op->arch && (op->arch->name != NULL) && 1138 (op->arch && (op->arch->name != NULL) && strstr (op->arch->name, hitter->slaying)))
1044 strstr(op->arch->name, hitter->slaying)) 1139 {
1045 ){ 1140 doesnt_slay = 0;
1046 doesnt_slay = 0; 1141 dam *= 3;
1047 dam *= 3;
1048 } 1142 }
1049 } 1143 }
1050 1144
1051 /* Adjust the damage for resistance. Note that neg. values increase damage. */ 1145 /* Adjust the damage for resistance. Note that neg. values increase damage. */
1052 if (op->resist[attacknum]) { 1146 if (op->resist[attacknum])
1147 {
1053 /* basically: dam = dam*(100-op->resist[attacknum])/100; 1148 /* basically: dam = dam*(100-op->resist[attacknum])/100;
1054 * in case 0>dam>1, we try to "simulate" a float value-effect */ 1149 * in case 0>dam>1, we try to "simulate" a float value-effect */
1055 dam *= (100-op->resist[attacknum]); 1150 dam *= (100 - op->resist[attacknum]);
1056 if (dam >= 100) dam /= 100; 1151 if (dam >= 100)
1152 dam /= 100;
1057 else 1153 else
1058 dam = (dam > (random_roll(0, 99, op, PREFER_LOW))) ? 1 : 0; 1154 dam = (dam > (random_roll (0, 99, op, PREFER_LOW))) ? 1 : 0;
1059 } 1155 }
1060 1156
1061 /* Special hack. By default, if immune to something, you 1157 /* Special hack. By default, if immune to something, you
1062 * shouldn't need to worry. However, acid is an exception, since 1158 * shouldn't need to worry. However, acid is an exception, since
1063 * it can still damage your items. Only include attacktypes if 1159 * it can still damage your items. Only include attacktypes if
1064 * special processing is needed */ 1160 * special processing is needed */
1065 1161
1066 if ((op->resist[attacknum] >= 100) && 1162 if ((op->resist[attacknum] >= 100) && doesnt_slay && (attacknum != ATNR_ACID))
1067 doesnt_slay && (attacknum != ATNR_ACID))
1068 return 0; 1163 return 0;
1069 1164
1070 /* Keep this in order - makes things easier to find */ 1165 /* Keep this in order - makes things easier to find */
1166
1167 switch (attacknum)
1071 1168 {
1072 switch(attacknum) {
1073 case ATNR_PHYSICAL: 1169 case ATNR_PHYSICAL:
1074 /* here also check for diseases */ 1170 /* here also check for diseases */
1075 check_physically_infect(op, hitter); 1171 check_physically_infect (op, hitter);
1076 break; 1172 break;
1077 1173
1078 /* Don't need to do anything for: 1174 /* Don't need to do anything for:
1079 magic, 1175 magic,
1080 fire, 1176 fire,
1081 electricity, 1177 electricity,
1082 cold */ 1178 cold */
1083 1179
1084 case ATNR_CONFUSION: 1180 case ATNR_CONFUSION:
1085 case ATNR_POISON: 1181 case ATNR_POISON:
1086 case ATNR_SLOW: 1182 case ATNR_SLOW:
1087 case ATNR_PARALYZE: 1183 case ATNR_PARALYZE:
1088 case ATNR_FEAR: 1184 case ATNR_FEAR:
1089 case ATNR_CANCELLATION: 1185 case ATNR_CANCELLATION:
1090 case ATNR_DEPLETE: 1186 case ATNR_DEPLETE:
1091 case ATNR_BLIND: 1187 case ATNR_BLIND:
1092 { 1188 {
1093 /* chance for inflicting a special attack depends on the 1189 /* chance for inflicting a special attack depends on the
1094 * difference between attacker's and defender's level 1190 * difference between attacker's and defender's level
1095 */ 1191 */
1096 int level_diff = MIN(110, MAX(0, op->level - hitter->level)); 1192 int level_diff = MIN (110, MAX (0, op->level - hitter->level));
1097 1193
1098 /* First, only creatures/players with speed can be affected. 1194 /* First, only creatures/players with speed can be affected.
1099 * Second, just getting hit doesn't mean it always affects 1195 * Second, just getting hit doesn't mean it always affects
1100 * you. Third, you still get a saving through against the 1196 * you. Third, you still get a saving through against the
1101 * effect. 1197 * effect.
1102 */ 1198 */
1103 if (op->speed && 1199 if (op->speed &&
1104 (QUERY_FLAG(op, FLAG_MONSTER) || op->type==PLAYER) && 1200 (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) &&
1105 !(rndm(0, (attacknum == ATNR_SLOW?6:3)-1)) && 1201 !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) && !did_make_save (op, level_diff, op->resist[attacknum] / 10))
1106 !did_make_save(op, level_diff, op->resist[attacknum]/10)) { 1202 {
1107 1203
1108 /* Player has been hit by something */ 1204 /* Player has been hit by something */
1109 if (attacknum == ATNR_CONFUSION) confuse_player(op,hitter,dam); 1205 if (attacknum == ATNR_CONFUSION)
1110 else if (attacknum == ATNR_POISON) poison_player(op,hitter,dam); 1206 confuse_player (op, hitter, dam);
1111 else if (attacknum == ATNR_SLOW) slow_player(op,hitter,dam); 1207 else if (attacknum == ATNR_POISON)
1112 else if (attacknum == ATNR_PARALYZE) paralyze_player(op,hitter,dam); 1208 poison_player (op, hitter, dam);
1113 else if (attacknum == ATNR_FEAR) scare_creature(op, hitter); 1209 else if (attacknum == ATNR_SLOW)
1114 else if (attacknum == ATNR_CANCELLATION) cancellation(op); 1210 slow_player (op, hitter, dam);
1115 else if (attacknum == ATNR_DEPLETE) drain_stat(op); 1211 else if (attacknum == ATNR_PARALYZE)
1116 else if (attacknum == ATNR_BLIND && !QUERY_FLAG(op,FLAG_UNDEAD) && 1212 paralyze_player (op, hitter, dam);
1117 !QUERY_FLAG(op,FLAG_GENERATOR)) blind_player(op,hitter,dam); 1213 else if (attacknum == ATNR_FEAR)
1118 } 1214 scare_creature (op, hitter);
1215 else if (attacknum == ATNR_CANCELLATION)
1216 cancellation (op);
1217 else if (attacknum == ATNR_DEPLETE)
1218 drain_stat (op);
1219 else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR))
1220 blind_player (op, hitter, dam);
1221 }
1119 dam = 0; /* These are all effects and don't do real damage */ 1222 dam = 0; /* These are all effects and don't do real damage */
1120 } 1223 }
1121 break; 1224 break;
1122 case ATNR_ACID: 1225 case ATNR_ACID:
1123 { 1226 {
1124 int flag=0; 1227 int flag = 0;
1125 1228
1126 /* Items only get corroded if you're not on a battleground and 1229 /* Items only get corroded if you're not on a battleground and
1127 * if your acid resistance is below 50%. */ 1230 * if your acid resistance is below 50%. */
1128 if (!op_on_battleground(op, NULL, NULL) && 1231 if (!op_on_battleground (op, NULL, NULL) && (op->resist[ATNR_ACID] < 50))
1129 (op->resist[ATNR_ACID] < 50)) 1232 {
1130 { 1233 object *tmp;
1131 object *tmp; 1234
1132 for(tmp=op->inv; tmp!=NULL; tmp=tmp->below) { 1235 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
1133 if(tmp->invisible) 1236 {
1134 continue; 1237 if (tmp->invisible)
1135 if(!QUERY_FLAG(tmp, FLAG_APPLIED) || 1238 continue;
1136 (tmp->resist[ATNR_ACID] >= 10)) 1239 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10))
1137 /* >= 10% acid res. on itmes will protect these */ 1240 /* >= 10% acid res. on itmes will protect these */
1138 continue; 1241 continue;
1139 if(!(tmp->material & M_IRON)) 1242 if (!(tmp->material & M_IRON))
1140 continue; 1243 continue;
1141 if(tmp->magic < -4) /* Let's stop at -5 */ 1244 if (tmp->magic < -4) /* Let's stop at -5 */
1142 continue; 1245 continue;
1143 if(tmp->type==RING || 1246 if (tmp->type == RING ||
1144 /* removed boots and gloves from exclusion list in 1247 /* removed boots and gloves from exclusion list in
1145 PR */ 1248 PR */
1146 tmp->type==GIRDLE || 1249 tmp->type == GIRDLE || tmp->type == AMULET || tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1147 tmp->type==AMULET ||
1148 tmp->type==WAND ||
1149 tmp->type==ROD ||
1150 tmp->type==HORN)
1151 continue; /* To avoid some strange effects */ 1250 continue; /* To avoid some strange effects */
1152 1251
1153 /* High damage acid has better chance of corroding 1252 /* High damage acid has better chance of corroding
1154 objects */ 1253 objects */
1155 if(rndm(0, dam+4) > 1254 if (rndm (0, dam + 4) > random_roll (0, 39, op, PREFER_HIGH) + 2 * tmp->magic)
1156 random_roll(0, 39, op, PREFER_HIGH)+2*tmp->magic) { 1255 {
1157 if(op->type == PLAYER) 1256 if (op->type == PLAYER)
1158 /* Make this more visible */ 1257 /* Make this more visible */
1159 new_draw_info_format(NDI_UNIQUE|NDI_RED,0, op, 1258 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op,
1160 "The %s's acid corrodes your %s!", 1259 "The %s's acid corrodes your %s!", query_name (hitter), query_name (tmp));
1161 query_name(hitter), query_name(tmp)); 1260 flag = 1;
1162 flag = 1; 1261 tmp->magic--;
1163 tmp->magic--; 1262 if (op->type == PLAYER)
1164 if(op->type == PLAYER) 1263 esrv_send_item (op, tmp);
1165 esrv_send_item(op, tmp); 1264 }
1166 } 1265 }
1167 } 1266 if (flag)
1168 if(flag)
1169 fix_player(op); /* Something was corroded */ 1267 fix_player (op); /* Something was corroded */
1170 } 1268 }
1171 } 1269 }
1172 break; 1270 break;
1173 case ATNR_DRAIN: 1271 case ATNR_DRAIN:
1174 { 1272 {
1175 /* rate is the proportion of exp drained. High rate means 1273 /* rate is the proportion of exp drained. High rate means
1176 * not much is drained, low rate means a lot is drained. 1274 * not much is drained, low rate means a lot is drained.
1177 */ 1275 */
1178 int rate; 1276 int rate;
1179 1277
1180 if(op->resist[ATNR_DRAIN] >= 0) 1278 if (op->resist[ATNR_DRAIN] >= 0)
1181 rate = 400 + op->resist[ATNR_DRAIN] * 3; 1279 rate = 400 + op->resist[ATNR_DRAIN] * 3;
1182 else 1280 else
1183 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); 1281 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]);
1184 1282
1185 if(op->stats.exp <= rate) { 1283 if (op->stats.exp <= rate)
1284 {
1186 if(op->type == GOLEM) 1285 if (op->type == GOLEM)
1187 dam = 999; /* Its force is "sucked" away. 8) */ 1286 dam = 999; /* Its force is "sucked" away. 8) */
1188 else 1287 else
1189 /* If we can't drain, lets try to do physical damage */ 1288 /* If we can't drain, lets try to do physical damage */
1190 dam = hit_player_attacktype(op, hitter, dam, ATNR_PHYSICAL, magic); 1289 dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic);
1191 } else { 1290 }
1291 else
1292 {
1192 /* Randomly give the hitter some hp */ 1293 /* Randomly give the hitter some hp */
1193 if(hitter->stats.hp<hitter->stats.maxhp && 1294 if (hitter->stats.hp < hitter->stats.maxhp &&
1194 (op->level > hitter->level) && 1295 (op->level > hitter->level) && random_roll (0, (op->level - hitter->level + 2), hitter, PREFER_HIGH) > 3)
1195 random_roll(0, (op->level-hitter->level+2), hitter, PREFER_HIGH)>3) 1296 hitter->stats.hp++;
1196 hitter->stats.hp++;
1197 1297
1198 /* Can't do drains on battleground spaces. 1298 /* Can't do drains on battleground spaces.
1199 * Move the wiz check up here - before, the hitter wouldn't gain exp 1299 * Move the wiz check up here - before, the hitter wouldn't gain exp
1200 * exp, but the wiz would still lose exp! If drainee is a wiz, 1300 * exp, but the wiz would still lose exp! If drainee is a wiz,
1201 * nothing happens. 1301 * nothing happens.
1202 * Try to credit the owner. We try to display player -> player drain 1302 * Try to credit the owner. We try to display player -> player drain
1203 * attacks, hence all the != PLAYER checks. 1303 * attacks, hence all the != PLAYER checks.
1204 */ 1304 */
1205 if (!op_on_battleground(hitter, NULL, NULL) && !QUERY_FLAG(op,FLAG_WAS_WIZ)) { 1305 if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WAS_WIZ))
1206 object *owner = get_owner(hitter); 1306 {
1307 object *owner = get_owner (hitter);
1207 1308
1208 if (owner && owner != hitter) { 1309 if (owner && owner != hitter)
1310 {
1209 if (op->type != PLAYER || owner->type != PLAYER) 1311 if (op->type != PLAYER || owner->type != PLAYER)
1210 change_exp(owner, op->stats.exp/(rate*2), 1312 change_exp (owner, op->stats.exp / (rate * 2),
1211 hitter->chosen_skill? hitter->chosen_skill->skill:NULL, SK_EXP_TOTAL); 1313 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL);
1314 }
1212 } else if (op->type != PLAYER || hitter->type != PLAYER) { 1315 else if (op->type != PLAYER || hitter->type != PLAYER)
1316 {
1213 change_exp(hitter, op->stats.exp/(rate*2), 1317 change_exp (hitter, op->stats.exp / (rate * 2),
1214 hitter->chosen_skill?hitter->chosen_skill->skill:NULL, 0); 1318 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0);
1215 } 1319 }
1216 change_exp(op,-op->stats.exp/rate, NULL, 0); 1320 change_exp (op, -op->stats.exp / rate, NULL, 0);
1217 } 1321 }
1218 dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure 1322 dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure
1219 * drain attack, you won't know that you are actually sucking out EXP, 1323 * drain attack, you won't know that you are actually sucking out EXP,
1220 * as the messages will say you missed 1324 * as the messages will say you missed
1221 */ 1325 */
1222 } 1326 }
1223 } 1327 }
1224 break; 1328 break;
1225 case ATNR_TURN_UNDEAD: 1329 case ATNR_TURN_UNDEAD:
1226 { 1330 {
1227 if (QUERY_FLAG(op,FLAG_UNDEAD)) { 1331 if (QUERY_FLAG (op, FLAG_UNDEAD))
1332 {
1228 object *owner = get_owner(hitter) == NULL ? hitter : get_owner(hitter); 1333 object *owner = get_owner (hitter) == NULL ? hitter : get_owner (hitter);
1229 object *god = find_god (determine_god (owner)); 1334 object *god = find_god (determine_god (owner));
1230 int div = 1; 1335 int div = 1;
1231 1336
1232 /* if undead are not an enemy of your god, you turn them 1337 /* if undead are not an enemy of your god, you turn them
1233 * at half strength */ 1338 * at half strength */
1234 if (! god || ! god->slaying || 1339 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL)
1235 strstr (god->slaying, undead_name) == NULL)
1236 div = 2; 1340 div = 2;
1237 /* Give a bonus if you resist turn undead */ 1341 /* Give a bonus if you resist turn undead */
1238 if (op->level * div < 1342 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100)))
1239 (turn_bonus[owner->stats.Wis]+owner->level + 1343 scare_creature (op, owner);
1240 (op->resist[ATNR_TURN_UNDEAD]/100))) 1344 }
1241 scare_creature(op, owner); 1345 else
1242 }
1243 else
1244 dam = 0; /* don't damage non undead - should we damage 1346 dam = 0; /* don't damage non undead - should we damage
1245 undead? */ 1347 undead? */
1348 }
1246 } break; 1349 break;
1247 case ATNR_DEATH: 1350 case ATNR_DEATH:
1248 deathstrike_player(op, hitter, &dam); 1351 deathstrike_player (op, hitter, &dam);
1249 break; 1352 break;
1250 case ATNR_CHAOS: 1353 case ATNR_CHAOS:
1251 LOG(llevError, 1354 LOG (llevError, "%s was hit by %s with non-specific chaos.\n", query_name (op), query_name (hitter));
1252 "%s was hit by %s with non-specific chaos.\n", 1355 dam = 0;
1253 query_name(op), 1356 break;
1254 query_name(hitter));
1255 dam = 0;
1256 break;
1257 case ATNR_COUNTERSPELL: 1357 case ATNR_COUNTERSPELL:
1258 LOG(llevError, 1358 LOG (llevError, "%s was hit by %s with counterspell attack.\n", query_name (op), query_name (hitter));
1259 "%s was hit by %s with counterspell attack.\n", 1359 dam = 0;
1260 query_name(op),
1261 query_name(hitter));
1262 dam = 0;
1263 /* This should never happen. Counterspell is handled 1360 /* This should never happen. Counterspell is handled
1264 * seperately and filtered out. If this does happen, 1361 * seperately and filtered out. If this does happen,
1265 * Counterspell has no effect on anything but spells, so it 1362 * Counterspell has no effect on anything but spells, so it
1266 * does no damage. */ 1363 * does no damage. */
1267 break; 1364 break;
1268 case ATNR_HOLYWORD: 1365 case ATNR_HOLYWORD:
1269 { 1366 {
1270 /* This has already been handled by hit_player, 1367 /* This has already been handled by hit_player,
1271 * no need to check twice -- DAMN */ 1368 * no need to check twice -- DAMN */
1272 1369
1273 object *owner = get_owner(hitter)==NULL?hitter:get_owner(hitter); 1370 object *owner = get_owner (hitter) == NULL ? hitter : get_owner (hitter);
1274 1371
1275 /* As with turn undead above, give a bonus on the saving throw */ 1372 /* As with turn undead above, give a bonus on the saving throw */
1276 if((op->level+(op->resist[ATNR_HOLYWORD]/100)) < 1373 if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis])
1277 owner->level+turn_bonus[owner->stats.Wis])
1278 scare_creature(op, owner); 1374 scare_creature (op, owner);
1375 }
1279 } break; 1376 break;
1280 case ATNR_LIFE_STEALING: 1377 case ATNR_LIFE_STEALING:
1281 { 1378 {
1282 int new_hp; 1379 int new_hp;
1380
1283 /* this is replacement to drain for players, instead of taking 1381 /* this is replacement to drain for players, instead of taking
1284 * exp it takes hp. It is geared for players, probably not 1382 * exp it takes hp. It is geared for players, probably not
1285 * much use giving it to monsters 1383 * much use giving it to monsters
1286 * 1384 *
1287 * life stealing doesn't do a lot of damage, but it gives the 1385 * life stealing doesn't do a lot of damage, but it gives the
1288 * damage it does do to the player. Given that, 1386 * damage it does do to the player. Given that,
1289 * it only does 1/10'th normal damage (hence the divide by 1387 * it only does 1/10'th normal damage (hence the divide by
1290 * 1000). 1388 * 1000).
1291 */ 1389 */
1292 /* You can't steal life from something undead */ 1390 /* You can't steal life from something undead */
1293 if ((op->type == GOLEM) || (QUERY_FLAG(op, FLAG_UNDEAD))) return 0; 1391 if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD)))
1392 return 0;
1294 /* If drain protection is higher than life stealing, use that */ 1393 /* If drain protection is higher than life stealing, use that */
1295 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) 1394 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING])
1296 dam = (dam*(100 - op->resist[ATNR_DRAIN])) / 3000; 1395 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000;
1396 else
1297 else dam = (dam*(100 - op->resist[ATNR_LIFE_STEALING])) / 3000; 1397 dam = (dam * (100 - op->resist[ATNR_LIFE_STEALING])) / 3000;
1298 /* You die at -1 hp, not zero. */ 1398 /* You die at -1 hp, not zero. */
1299 if (dam > (op->stats.hp+1)) dam = op->stats.hp+1; 1399 if (dam > (op->stats.hp + 1))
1400 dam = op->stats.hp + 1;
1300 new_hp = hitter->stats.hp + dam; 1401 new_hp = hitter->stats.hp + dam;
1301 if (new_hp > hitter->stats.maxhp) new_hp = hitter->stats.maxhp; 1402 if (new_hp > hitter->stats.maxhp)
1302 if (new_hp > hitter->stats.hp) hitter->stats.hp = new_hp; 1403 new_hp = hitter->stats.maxhp;
1404 if (new_hp > hitter->stats.hp)
1405 hitter->stats.hp = new_hp;
1406 }
1303 } 1407 }
1304 }
1305 return dam; 1408 return dam;
1306} 1409}
1307 1410
1308 1411
1309/* GROS: This code comes from hit_player. It has been made external to 1412/* GROS: This code comes from hit_player. It has been made external to
1310 * allow script procedures to "kill" objects in a combat-like fashion. 1413 * allow script procedures to "kill" objects in a combat-like fashion.
1319 * This function was a bit of a mess with hitter getting changed, 1422 * This function was a bit of a mess with hitter getting changed,
1320 * values being stored away but not used, etc. I've cleaned it up 1423 * values being stored away but not used, etc. I've cleaned it up
1321 * a bit - I think it should be functionally equivalant. 1424 * a bit - I think it should be functionally equivalant.
1322 * MSW 2002-07-17 1425 * MSW 2002-07-17
1323 */ 1426 */
1427int
1324int kill_object(object *op,int dam, object *hitter, int type) 1428kill_object (object *op, int dam, object *hitter, int type)
1325{ 1429{
1326 char buf[MAX_BUF]; 1430 char buf[MAX_BUF];
1327 const char *skill; 1431 const char *skill;
1328 int maxdam=0; 1432 int maxdam = 0;
1329 int battleg=0; /* true if op standing on battleground */ 1433 int battleg = 0; /* true if op standing on battleground */
1330 int pk=0; /* true if op and what controls hitter are both players*/ 1434 int pk = 0; /* true if op and what controls hitter are both players */
1331 object *owner=NULL; 1435 object *owner = NULL;
1332 object *skop=NULL; 1436 object *skop = NULL;
1333 1437
1334 if (op->stats.hp>=0) 1438 if (op->stats.hp >= 0)
1335 return -1; 1439 return -1;
1336 1440
1337 if (INVOKE_OBJECT (KILL, op, ARG_OBJECT (hitter))) 1441 if (INVOKE_OBJECT (KILL, op, ARG_OBJECT (hitter)))
1338 return 0; 1442 return 0;
1339 1443
1340 /* maxdam needs to be the amount of damage it took to kill 1444 /* maxdam needs to be the amount of damage it took to kill
1341 * this creature. The function(s) that call us have already 1445 * this creature. The function(s) that call us have already
1342 * adjusted the creatures HP total, so that is negative. 1446 * adjusted the creatures HP total, so that is negative.
1343 */ 1447 */
1344 maxdam = dam + op->stats.hp + 1; 1448 maxdam = dam + op->stats.hp + 1;
1345 1449
1346 if(QUERY_FLAG(op,FLAG_BLOCKSVIEW)) 1450 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW))
1347 update_all_los(op->map,op->x, op->y); /* makes sure los will be recalculated */ 1451 update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */
1348 1452
1349 if(op->type==DOOR) { 1453 if (op->type == DOOR)
1454 {
1350 op->speed = 0.1; 1455 op->speed = 0.1;
1351 update_ob_speed(op); 1456 update_ob_speed (op);
1352 op->speed_left= -0.05; 1457 op->speed_left = -0.05;
1353 return maxdam; 1458 return maxdam;
1354 } 1459 }
1355 if(QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) { 1460 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER)
1461 {
1356 remove_friendly_object(op); 1462 remove_friendly_object (op);
1357 if (get_owner (op) != NULL && op->owner->type == PLAYER && 1463 if (get_owner (op) != NULL && op->owner->type == PLAYER && op->owner->contr->ranges[range_golem] == op)
1358 op->owner->contr->ranges[range_golem] == op) { 1464 {
1359 op->owner->contr->ranges[range_golem]=NULL; 1465 op->owner->contr->ranges[range_golem] = NULL;
1360 op->owner->contr->golem_count=0; 1466 op->owner->contr->golem_count = 0;
1361 } 1467 }
1362 1468
1363 remove_ob(op); 1469 remove_ob (op);
1364 free_object(op); 1470 free_object (op);
1365 return maxdam; 1471 return maxdam;
1366 } 1472 }
1367 1473
1368 /* Now lets start dealing with experience we get for killing something */ 1474 /* Now lets start dealing with experience we get for killing something */
1369 1475
1370 owner=get_owner(hitter); 1476 owner = get_owner (hitter);
1371 if(owner==NULL) 1477 if (owner == NULL)
1372 owner=hitter; 1478 owner = hitter;
1373 1479
1374 /* is the victim (op) standing on battleground? */ 1480 /* is the victim (op) standing on battleground? */
1375 if (op_on_battleground(op, NULL, NULL)) battleg=1; 1481 if (op_on_battleground (op, NULL, NULL))
1376 1482 battleg = 1;
1483
1377 /* is this player killing?*/ 1484 /* is this player killing? */
1378 if (op->type == PLAYER && owner->type == PLAYER) pk=1; 1485 if (op->type == PLAYER && owner->type == PLAYER)
1486 pk = 1;
1379 1487
1380 /* Player killed something */ 1488 /* Player killed something */
1381 if(owner->type==PLAYER) { 1489 if (owner->type == PLAYER)
1490 {
1382 Log_Kill(owner->name, 1491 Log_Kill (owner->name,
1383 query_name(op),op->type, 1492 query_name (op), op->type, (owner != hitter) ? query_name (hitter) : NULL, (owner != hitter) ? hitter->type : 0);
1384 (owner!=hitter) ? query_name(hitter) : NULL,
1385 (owner!=hitter) ? hitter->type : 0);
1386 1493
1387 /* Log players killing other players - makes it easier to detect 1494 /* Log players killing other players - makes it easier to detect
1388 * and filter out malicious player killers - that is why the 1495 * and filter out malicious player killers - that is why the
1389 * ip address is included. 1496 * ip address is included.
1390 */ 1497 */
1391 if (op->type == PLAYER && !battleg) { 1498 if (op->type == PLAYER && !battleg)
1499 {
1392 time_t t=time(NULL); 1500 time_t t = time (NULL);
1393 struct tm *tmv; 1501 struct tm *tmv;
1394 char buf[256]; 1502 char buf[256];
1395 1503
1396 tmv = localtime(&t); 1504 tmv = localtime (&t);
1397 strftime(buf, 256,"%a %b %d %H:%M:%S %Y", tmv); 1505 strftime (buf, 256, "%a %b %d %H:%M:%S %Y", tmv);
1398 1506
1399 LOG(llevInfo,"%s PLAYER_KILL_PLAYER: %s (%s) killed %s\n", 1507 LOG (llevInfo, "%s PLAYER_KILL_PLAYER: %s (%s) killed %s\n", buf, &owner->name, owner->contr->socket.host, query_name (op));
1400 buf, owner->name, owner->contr->socket.host, query_name(op)); 1508 }
1401 }
1402 1509
1403 /* try to filter some things out - basically, if you are 1510 /* try to filter some things out - basically, if you are
1404 * killing a level 1 creature and your level 20, you 1511 * killing a level 1 creature and your level 20, you
1405 * probably don't want to see that. 1512 * probably don't want to see that.
1406 */ 1513 */
1407 if ( owner->level < op->level * 2|| op->stats.exp>1000) { 1514 if (owner->level < op->level * 2 || op->stats.exp > 1000)
1515 {
1408 if(owner!=hitter) { 1516 if (owner != hitter)
1409 new_draw_info_format(NDI_BLACK, 0, owner, 1517 {
1410 "You killed %s with %s.",query_name(op), 1518 new_draw_info_format (NDI_BLACK, 0, owner, "You killed %s with %s.", query_name (op), query_name (hitter));
1411 query_name(hitter)); 1519 }
1412 } 1520 else
1413 else { 1521 {
1414 new_draw_info_format(NDI_BLACK, 0, owner, 1522 new_draw_info_format (NDI_BLACK, 0, owner, "You killed %s.", query_name (op));
1415 "You killed %s.",query_name(op)); 1523 }
1416 }
1417 /* Only play sounds for melee kills */ 1524 /* Only play sounds for melee kills */
1418 if (hitter->type == PLAYER) 1525 if (hitter->type == PLAYER)
1419 play_sound_map(owner->map, owner->x, owner->y, SOUND_PLAYER_KILLS); 1526 play_sound_map (owner->map, owner->x, owner->y, SOUND_PLAYER_KILLS);
1420 } 1527 }
1421 1528
1422 /* If a player kills another player, not on 1529 /* If a player kills another player, not on
1423 * battleground, the "killer" looses 1 luck. Since this is 1530 * battleground, the "killer" looses 1 luck. Since this is
1424 * not reversible, it's actually quite a pain IMHO. -AV 1531 * not reversible, it's actually quite a pain IMHO. -AV
1425 * Fix bug in that we were changing the luck of the hitter, not 1532 * Fix bug in that we were changing the luck of the hitter, not
1426 * player that the object belonged to - so if you killed another player 1533 * player that the object belonged to - so if you killed another player
1427 * with spells, pets, whatever, there was no penalty. 1534 * with spells, pets, whatever, there was no penalty.
1428 * Changed to make luck penalty configurable in settings. 1535 * Changed to make luck penalty configurable in settings.
1429 */ 1536 */
1430 if(op->type == PLAYER && owner != op && !battleg) 1537 if (op->type == PLAYER && owner != op && !battleg)
1431 change_luck(owner, -settings.pk_luck_penalty); 1538 change_luck (owner, -settings.pk_luck_penalty);
1432 1539
1433 /* This code below deals with finding the appropriate skill 1540 /* This code below deals with finding the appropriate skill
1434 * to credit exp to. This is a bit problematic - we should 1541 * to credit exp to. This is a bit problematic - we should
1435 * probably never really have to look at current_weapon->skill 1542 * probably never really have to look at current_weapon->skill
1436 */ 1543 */
1437 skill = NULL; 1544 skill = NULL;
1438 if (hitter->skill && hitter->type!=PLAYER) skill = hitter->skill; 1545 if (hitter->skill && hitter->type != PLAYER)
1546 skill = hitter->skill;
1439 else if (owner->chosen_skill) { 1547 else if (owner->chosen_skill)
1548 {
1440 skill = owner->chosen_skill->skill; 1549 skill = owner->chosen_skill->skill;
1441 skop = owner->chosen_skill; 1550 skop = owner->chosen_skill;
1442 } 1551 }
1443 else if (QUERY_FLAG(owner, FLAG_READY_WEAPON)) skill=owner->current_weapon->skill; 1552 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON))
1444 else 1553 skill = owner->current_weapon->skill;
1554 else
1445 LOG(llevError,"kill_object - unable to find skill that killed monster\n"); 1555 LOG (llevError, "kill_object - unable to find skill that killed monster\n");
1446 1556
1447 /* We have the skill we want to credit to - now find the object this goes 1557 /* We have the skill we want to credit to - now find the object this goes
1448 * to. Make sure skop is an actual skill, and not a skill tool! 1558 * to. Make sure skop is an actual skill, and not a skill tool!
1449 */ 1559 */
1450 if ((!skop || skop->type != SKILL) && skill) { 1560 if ((!skop || skop->type != SKILL) && skill)
1451 int i; 1561 {
1562 int i;
1452 1563
1453 for (i=0; i<NUM_SKILLS; i++) 1564 for (i = 0; i < NUM_SKILLS; i++)
1565 if (owner->contr->last_skill_ob[i] && !strcmp (owner->contr->last_skill_ob[i]->skill, skill))
1566 {
1454 if (owner->contr->last_skill_ob[i] && 1567 skop = owner->contr->last_skill_ob[i];
1455 !strcmp(owner->contr->last_skill_ob[i]->skill, skill)) { 1568 break;
1456 skop = owner->contr->last_skill_ob[i]; 1569 }
1457 break; 1570 }
1458 }
1459 }
1460 } /* Was it a player that hit somethign */ 1571 } /* Was it a player that hit somethign */
1461 else { 1572 else
1462 skill = NULL;
1463 } 1573 {
1574 skill = NULL;
1575 }
1464 1576
1465 /* Pet (or spell) killed something. */ 1577 /* Pet (or spell) killed something. */
1466 if(owner != hitter ) { 1578 if (owner != hitter)
1579 {
1467 (void) sprintf(buf,"%s killed %s with %s%s%s.",owner->name, 1580 (void) sprintf (buf, "%s killed %s with %s%s%s.", &owner->name,
1468 query_name(op),query_name(hitter), battleg? " (duel)":"", pk? " (pk)":""); 1581 query_name (op), query_name (hitter), battleg ? " (duel)" : "", pk ? " (pk)" : "");
1582 }
1583 else
1469 } 1584 {
1470 else {
1471 (void) sprintf(buf,"%s killed %s%s%s%s.",hitter->name,op->name, 1585 (void) sprintf (buf, "%s killed %s%s%s%s.", &hitter->name, &op->name,
1472 (QUERY_FLAG(hitter, FLAG_MONSTER)) || hitter->type == PLAYER ? 1586 (QUERY_FLAG (hitter, FLAG_MONSTER)) || hitter->type == PLAYER ?
1473 " in hand to hand combat":"", battleg? " (duel)":"", pk? " (pk)":""); 1587 " in hand to hand combat" : "", battleg ? " (duel)" : "", pk ? " (pk)" : "");
1474 } 1588 }
1475 /* These may have been set in the player code section above */ 1589 /* These may have been set in the player code section above */
1590 if (!skop)
1476 if (!skop) skop = hitter->chosen_skill; 1591 skop = hitter->chosen_skill;
1477 if (!skill && skop) skill=skop->skill; 1592 if (!skill && skop)
1593 skill = skop->skill;
1478 1594
1479 new_draw_info(NDI_ALL, op->type==PLAYER?1:10, NULL, buf); 1595 new_draw_info (NDI_ALL, op->type == PLAYER ? 1 : 10, NULL, buf);
1480 1596
1481 1597
1482 /* If you didn't kill yourself, and your not the wizard */ 1598 /* If you didn't kill yourself, and your not the wizard */
1483 if(owner!=op && !QUERY_FLAG(op, FLAG_WAS_WIZ)) { 1599 if (owner != op && !QUERY_FLAG (op, FLAG_WAS_WIZ))
1484 int exp; 1600 {
1601 int exp;
1485 1602
1486 /* Really don't give much experience for killing other players */ 1603 /* Really don't give much experience for killing other players */
1487 // schmorp: temporary? reduce the amount of exp gained for pking enourmously 1604 // schmorp: temporary? reduce the amount of exp gained for pking enourmously
1488 if (op->type==PLAYER) { 1605 if (op->type == PLAYER)
1489 if (battleg) {
1490 new_draw_info(NDI_UNIQUE, 0,owner, "Your foe has fallen!");
1491 new_draw_info(NDI_UNIQUE, 0,owner, "VICTORY!!!");
1492 }
1493 else
1494 exp = op->stats.exp / 1000;
1495 } 1606 {
1607 if (battleg)
1608 {
1609 new_draw_info (NDI_UNIQUE, 0, owner, "Your foe has fallen!");
1610 new_draw_info (NDI_UNIQUE, 0, owner, "VICTORY!!!");
1611 }
1496 else 1612 else
1613 exp = op->stats.exp / 1000;
1614 }
1615 else
1497 exp = calc_skill_exp(owner, op, skop); 1616 exp = calc_skill_exp (owner, op, skop);
1498 1617
1499 /* if op is standing on "battleground" (arena), no way to gain 1618 /* if op is standing on "battleground" (arena), no way to gain
1500 * exp by killing him 1619 * exp by killing him
1501 */ 1620 */
1502 if (battleg) exp = 0; 1621 if (battleg)
1622 exp = 0;
1503 1623
1504 /* Don't know why this is set this way - doesn't make 1624 /* Don't know why this is set this way - doesn't make
1505 * sense to just divide everything by two for no reason. 1625 * sense to just divide everything by two for no reason.
1506 */ 1626 */
1507 1627
1508 if (!settings.simple_exp) 1628 if (!settings.simple_exp)
1509 exp=exp/2; 1629 exp = exp / 2;
1510 1630
1511 if(owner->type!=PLAYER || owner->contr->party==NULL) { 1631 if (owner->type != PLAYER || owner->contr->party == NULL)
1632 {
1512 change_exp(owner,exp, skill, 0); 1633 change_exp (owner, exp, skill, 0);
1513 } 1634 }
1514 else { 1635 else
1636 {
1515 int shares=0,count=0; 1637 int shares = 0, count = 0;
1516 1638
1517 player *pl; 1639 player *pl;
1518 1640
1519 partylist *party=owner->contr->party; 1641 partylist *party = owner->contr->party;
1642
1520#ifdef PARTY_KILL_LOG 1643#ifdef PARTY_KILL_LOG
1521 add_kill_to_party(party, query_name(owner), query_name(op), exp); 1644 add_kill_to_party (party, query_name (owner), query_name (op), exp);
1522#endif 1645#endif
1523 for(pl=first_player;pl!=NULL;pl=pl->next) { 1646 for (pl = first_player; pl != NULL; pl = pl->next)
1647 {
1524 if(party && pl->ob->contr->party==party && on_same_map(pl->ob, owner)) { 1648 if (party && pl->ob->contr->party == party && on_same_map (pl->ob, owner))
1525 count++; 1649 {
1650 count++;
1526 shares+=(pl->ob->level+4); 1651 shares += (pl->ob->level + 4);
1527 } 1652 }
1653 }
1654 if (count == 1 || shares > exp)
1655 change_exp (owner, exp, skill, SK_EXP_TOTAL);
1656 else
1657 {
1658 int share = exp / shares, given = 0, nexp;
1659
1660 for (pl = first_player; pl != NULL; pl = pl->next)
1661 {
1662 if (party && pl->ob->contr->party == party && on_same_map (pl->ob, owner))
1663 {
1664 nexp = (pl->ob->level + 4) * share;
1665 change_exp (pl->ob, nexp, skill, SK_EXP_TOTAL);
1666 given += nexp;
1667 }
1668 }
1669 exp -= given;
1670 /* give any remainder to the player */
1671 change_exp (owner, exp, skill, SK_EXP_ADD_SKILL);
1672 }
1673 } /* else part of a party */
1674
1675 } /* end if person didn't kill himself */
1676
1677 if (op->type != PLAYER)
1678 {
1679 if (QUERY_FLAG (op, FLAG_FRIENDLY))
1680 {
1681 object *owner1 = get_owner (op);
1682
1683 if (owner1 != NULL && owner1->type == PLAYER)
1684 {
1685 play_sound_player_only (owner1->contr, SOUND_PET_IS_KILLED, 0, 0);
1686 /* Maybe we should include the owner that killed this, maybe not */
1687 new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, is killed by %s.", &op->name, &hitter->name);
1688 }
1689 remove_friendly_object (op);
1690 }
1691 remove_ob (op);
1692 free_object (op);
1528 } 1693 }
1529 if(count==1 || shares>exp)
1530 change_exp(owner,exp, skill, SK_EXP_TOTAL);
1531 else {
1532 int share=exp/shares,given=0,nexp;
1533 for(pl=first_player;pl!=NULL;pl=pl->next) {
1534 if(party && pl->ob->contr->party==party && on_same_map(pl->ob, owner)) {
1535 nexp=(pl->ob->level+4)*share;
1536 change_exp(pl->ob,nexp, skill, SK_EXP_TOTAL);
1537 given+=nexp;
1538 }
1539 }
1540 exp-=given;
1541 /* give any remainder to the player */
1542 change_exp(owner,exp, skill, SK_EXP_ADD_SKILL);
1543 }
1544 } /* else part of a party */
1545
1546 } /* end if person didn't kill himself */
1547
1548 if(op->type!=PLAYER) {
1549 if(QUERY_FLAG(op,FLAG_FRIENDLY)) {
1550 object *owner1 = get_owner(op);
1551
1552 if(owner1!= NULL && owner1->type == PLAYER) {
1553 play_sound_player_only(owner1->contr, SOUND_PET_IS_KILLED,0,0);
1554 /* Maybe we should include the owner that killed this, maybe not */
1555 new_draw_info_format(NDI_UNIQUE, 0,owner1,"Your pet, the %s, is killed by %s.",
1556 op->name,hitter->name);
1557 }
1558 remove_friendly_object(op);
1559 }
1560 remove_ob(op);
1561 free_object(op);
1562 }
1563 /* Player has been killed! */ 1694 /* Player has been killed! */
1564 else { 1695 else
1696 {
1565 if(owner->type==PLAYER) { 1697 if (owner->type == PLAYER)
1698 {
1566 snprintf(op->contr->killer, BIG_NAME, "%s the %s",owner->name,owner->contr->title); 1699 snprintf (op->contr->killer, BIG_NAME, "%s the %s", &owner->name, owner->contr->title);
1567 } 1700 }
1568 else { 1701 else
1702 {
1569 strncpy(op->contr->killer,hitter->name,BIG_NAME); 1703 strncpy (op->contr->killer, hitter->name, BIG_NAME);
1570 op->contr->killer[BIG_NAME-1]='\0'; 1704 op->contr->killer[BIG_NAME - 1] = '\0';
1571 } 1705 }
1572 } 1706 }
1573 /* This was return -1 - that doesn't seem correct - if we return -1, process 1707 /* This was return -1 - that doesn't seem correct - if we return -1, process
1574 * continues in the calling function. 1708 * continues in the calling function.
1575 */ 1709 */
1576 return maxdam; 1710 return maxdam;
1577} 1711}
1578 1712
1579/* Find out if this is friendly fire (PVP and attacker is peaceful) or not 1713/* Find out if this is friendly fire (PVP and attacker is peaceful) or not
1580 * Returns 0 this is not friendly fire 1714 * Returns 0 this is not friendly fire
1581 */ 1715 */
1582 1716
1717int
1583int friendly_fire(object *op, object *hitter){ 1718friendly_fire (object *op, object *hitter)
1719{
1584 object *owner; 1720 object *owner;
1585 int friendlyfire; 1721 int friendlyfire;
1586
1587 if (hitter->head) hitter=hitter->head;
1588 1722
1723 if (hitter->head)
1724 hitter = hitter->head;
1725
1589 friendlyfire = 0; 1726 friendlyfire = 0;
1590 1727
1591 if(op->type == PLAYER) { 1728 if (op->type == PLAYER)
1729 {
1592 if (op_on_battleground (hitter, 0, 0)) 1730 if (op_on_battleground (hitter, 0, 0))
1593 return 0; 1731 return 0;
1594 1732
1595 if(hitter->type == PLAYER && hitter->contr->peaceful == 1) 1733 if (hitter->type == PLAYER && hitter->contr->peaceful == 1)
1596 return 1; 1734 return 1;
1597 1735
1598 if((owner = get_owner(hitter))!=NULL) { 1736 if ((owner = get_owner (hitter)) != NULL)
1737 {
1599 if(owner->type == PLAYER && owner->contr->peaceful == 1) 1738 if (owner->type == PLAYER && owner->contr->peaceful == 1)
1600 friendlyfire = 2; 1739 friendlyfire = 2;
1601 } 1740 }
1602 1741
1603 if (hitter->type == SPELL || hitter->type == POISONING || 1742 if (hitter->type == SPELL || hitter->type == POISONING || hitter->type == DISEASE || hitter->type == RUNE)
1604 hitter->type == DISEASE || hitter->type == RUNE)
1605 friendlyfire = 0; 1743 friendlyfire = 0;
1606 } 1744 }
1607 return friendlyfire; 1745 return friendlyfire;
1608} 1746}
1609 1747
1610 1748
1611/* This isn't used just for players, but in fact most objects. 1749/* This isn't used just for players, but in fact most objects.
1612 * op is the object to be hit, dam is the amount of damage, hitter 1750 * op is the object to be hit, dam is the amount of damage, hitter
1617 */ 1755 */
1618 1756
1619 /* Oct 95 - altered the following slightly for MULTIPLE_GODS hack 1757 /* Oct 95 - altered the following slightly for MULTIPLE_GODS hack
1620 * which needs new attacktype AT_HOLYWORD to work . b.t. */ 1758 * which needs new attacktype AT_HOLYWORD to work . b.t. */
1621 1759
1760int
1622int hit_player(object *op,int dam, object *hitter, int type, int full_hit) { 1761hit_player (object *op, int dam, object *hitter, int type, int full_hit)
1762{
1623 int maxdam=0, ndam=0, attacktype=1, magic=(type & AT_MAGIC); 1763 int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC);
1624 int maxattacktype, attacknum; 1764 int maxattacktype, attacknum;
1625 int body_attack = op && op->head; /* Did we hit op's head? */ 1765 int body_attack = op && op->head; /* Did we hit op's head? */
1626 int simple_attack; 1766 int simple_attack;
1627 tag_t op_tag, hitter_tag; 1767 tag_t op_tag, hitter_tag;
1628 int rtn_kill = 0; 1768 int rtn_kill = 0;
1629 int friendlyfire; 1769 int friendlyfire;
1630 1770
1631 if (get_attack_mode (&op, &hitter, &simple_attack)) 1771 if (get_attack_mode (&op, &hitter, &simple_attack))
1632 return 0; 1772 return 0;
1633 1773
1634 /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */ 1774 /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */
1635 if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE)) 1775 if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE))
1636 return 0; 1776 return 0;
1637 1777
1638#ifdef PROHIBIT_PLAYERKILL 1778#ifdef PROHIBIT_PLAYERKILL
1639 if (op->type == PLAYER) { 1779 if (op->type == PLAYER)
1780 {
1640 object *owner = get_owner (hitter); 1781 object *owner = get_owner (hitter);
1782
1783 if (!owner)
1641 if (!owner) owner = hitter; 1784 owner = hitter;
1642 if (owner->type == PLAYER
1643 && (!op_on_battleground (op, 0, 0) && (op->contr->peaceful || owner->contr->peaceful)) 1785 if (owner->type == PLAYER && (!op_on_battleground (op, 0, 0) && (op->contr->peaceful || owner->contr->peaceful)) && op != owner)
1644 && op != owner) { 1786 {
1787 return 0;
1788 }
1789 }
1790#endif
1791
1792 op_tag = op->count;
1793 hitter_tag = hitter->count;
1794
1795 if (body_attack)
1796 {
1797 /* slow and paralyze must hit the head. But we don't want to just
1798 * return - we still need to process other attacks the spell still
1799 * might have. So just remove the paralyze and slow attacktypes,
1800 * and keep on processing if we have other attacktypes.
1801 * return if only magic or nothing is left - under normal code
1802 * we don't attack with pure magic if there is another attacktype.
1803 * Only do processing if the initial attacktype includes one of those
1804 * attack so we don't cancel out things like magic bullet.
1805 */
1806 if (type & (AT_PARALYZE | AT_SLOW))
1807 {
1808 type &= ~(AT_PARALYZE | AT_SLOW);
1809 if (!type || type == AT_MAGIC)
1810 return 0;
1811 }
1812 }
1813
1814 if (!simple_attack && op->type == DOOR)
1815 {
1816 object *tmp;
1817
1818 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
1819 if (tmp->type == RUNE || tmp->type == TRAP)
1820 {
1821 spring_trap (tmp, hitter);
1822 if (was_destroyed (hitter, hitter_tag) || was_destroyed (op, op_tag) || abort_attack (op, hitter, simple_attack))
1645 return 0; 1823 return 0;
1824 break;
1646 } 1825 }
1826 }
1827
1828 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0)
1647 } 1829 {
1830 /* FIXME: If a player is killed by a rune in a door, the
1831 * was_destroyed() check above doesn't return, and might get here.
1832 */
1833 LOG (llevDebug, "victim (arch %s, name %s) already dead in " "hit_player()\n", &op->arch->name, &op->name);
1834 return 0;
1835 }
1836
1837#ifdef ATTACK_DEBUG
1838 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam);
1648#endif 1839#endif
1649 1840
1650 op_tag = op->count;
1651 hitter_tag = hitter->count;
1652
1653 if (body_attack) {
1654 /* slow and paralyze must hit the head. But we don't want to just
1655 * return - we still need to process other attacks the spell still
1656 * might have. So just remove the paralyze and slow attacktypes,
1657 * and keep on processing if we have other attacktypes.
1658 * return if only magic or nothing is left - under normal code
1659 * we don't attack with pure magic if there is another attacktype.
1660 * Only do processing if the initial attacktype includes one of those
1661 * attack so we don't cancel out things like magic bullet.
1662 */
1663 if (type & (AT_PARALYZE | AT_SLOW)) {
1664 type &= ~(AT_PARALYZE | AT_SLOW);
1665 if (!type || type==AT_MAGIC) return 0;
1666 }
1667 }
1668
1669 if ( ! simple_attack && op->type == DOOR) {
1670 object *tmp;
1671 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
1672 if (tmp->type == RUNE || tmp->type == TRAP) {
1673 spring_trap (tmp, hitter);
1674 if (was_destroyed (hitter, hitter_tag)
1675 || was_destroyed (op, op_tag)
1676 || abort_attack (op, hitter, simple_attack))
1677 return 0;
1678 break;
1679 }
1680 }
1681
1682 if ( ! QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) {
1683 /* FIXME: If a player is killed by a rune in a door, the
1684 * was_destroyed() check above doesn't return, and might get here.
1685 */
1686 LOG (llevDebug, "victim (arch %s, name %s) already dead in "
1687 "hit_player()\n", op->arch->name, op->name);
1688 return 0;
1689 }
1690
1691#ifdef ATTACK_DEBUG
1692 LOG(llevDebug,"hit player: attacktype %d, dam %d\n", type, dam);
1693#endif
1694
1695 if (magic) { 1841 if (magic)
1842 {
1696 /* basically: dam = dam*(100-op->resist[attacknum])/100; 1843 /* basically: dam = dam*(100-op->resist[attacknum])/100;
1697 * in case 0>dam>1, we try to "simulate" a float value-effect */ 1844 * in case 0>dam>1, we try to "simulate" a float value-effect */
1698 dam = dam*(100-op->resist[ATNR_MAGIC]); 1845 dam = dam * (100 - op->resist[ATNR_MAGIC]);
1699 if (dam >= 100) 1846 if (dam >= 100)
1700 dam /= 100; 1847 dam /= 100;
1701 else 1848 else
1702 dam = (dam > (rndm(0, 99))) ? 1 : 0; 1849 dam = (dam > (rndm (0, 99))) ? 1 : 0;
1703 } 1850 }
1704 1851
1705 /* AT_CHAOS here is a weapon or monster. Spells are handled by hit_map 1852 /* AT_CHAOS here is a weapon or monster. Spells are handled by hit_map
1706 * If the attacktype still has chaos, shuffle it, then clear the Chaos bit 1853 * If the attacktype still has chaos, shuffle it, then clear the Chaos bit
1707 */ 1854 */
1708 if(type & AT_CHAOS){ 1855 if (type & AT_CHAOS)
1856 {
1709 shuffle_attack(op,0); /*0 flag tells it to not change the face */ 1857 shuffle_attack (op, 0); /*0 flag tells it to not change the face */
1710 update_object(op,UP_OBJ_FACE); 1858 update_object (op, UP_OBJ_FACE);
1711 type &= ~AT_CHAOS; 1859 type &= ~AT_CHAOS;
1712 } 1860 }
1713 1861
1714 /* Holyword is really an attacktype modifier (like magic is). If 1862 /* Holyword is really an attacktype modifier (like magic is). If
1715 * holyword is part of an attacktype, then make sure the creature is 1863 * holyword is part of an attacktype, then make sure the creature is
1716 * a proper match, otherwise no damage. 1864 * a proper match, otherwise no damage.
1717 */ 1865 */
1718 if (type & AT_HOLYWORD) { 1866 if (type & AT_HOLYWORD)
1867 {
1719 object *god; 1868 object *god;
1869
1720 if ((!hitter->slaying || 1870 if ((!hitter->slaying ||
1721 (!(op->race && strstr(hitter->slaying,op->race)) && 1871 (!(op->race && strstr (hitter->slaying, op->race)) &&
1722 !(op->name && strstr(hitter->slaying,op->name)))) && 1872 !(op->name && strstr (hitter->slaying, op->name)))) &&
1723 (!QUERY_FLAG(op,FLAG_UNDEAD) || 1873 (!QUERY_FLAG (op, FLAG_UNDEAD) ||
1724 (hitter->title != NULL 1874 (hitter->title != NULL
1725 && (god = find_god(determine_god(hitter))) != NULL 1875 && (god = find_god (determine_god (hitter))) != NULL && god->race != NULL && strstr (god->race, undead_name) != NULL)))
1726 && god->race != NULL
1727 && strstr(god->race,undead_name) != NULL)))
1728 return 0; 1876 return 0;
1729 } 1877 }
1730 1878
1731 maxattacktype = type; /* initialize this to something */ 1879 maxattacktype = type; /* initialize this to something */
1732 for (attacknum=0; attacknum<NROFATTACKS; attacknum++, attacktype=1<<attacknum) { 1880 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum)
1881 {
1733 /* Magic isn't really a true attack type - it gets combined with other 1882 /* Magic isn't really a true attack type - it gets combined with other
1734 * attack types. As such, skip it over. However, if magic is 1883 * attack types. As such, skip it over. However, if magic is
1735 * the only attacktype in the group, then still attack with it 1884 * the only attacktype in the group, then still attack with it
1736 */ 1885 */
1737 if ((attacktype==AT_MAGIC) && (type & ~AT_MAGIC)) continue; 1886 if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC))
1887 continue;
1738 1888
1739 /* Go through and hit the player with each attacktype, one by one. 1889 /* Go through and hit the player with each attacktype, one by one.
1740 * hit_player_attacktype only figures out the damage, doesn't inflict 1890 * hit_player_attacktype only figures out the damage, doesn't inflict
1741 * it. It will do the appropriate action for attacktypes with 1891 * it. It will do the appropriate action for attacktypes with
1742 * effects (slow, paralization, etc. 1892 * effects (slow, paralization, etc.
1743 */ 1893 */
1744 if (type & attacktype) { 1894 if (type & attacktype)
1895 {
1745 ndam=hit_player_attacktype(op,hitter,dam,attacknum,magic); 1896 ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic);
1746 /* the >= causes us to prefer messages from special attacks, if 1897 /* the >= causes us to prefer messages from special attacks, if
1747 * the damage is equal. 1898 * the damage is equal.
1748 */ 1899 */
1749 if (ndam >= maxdam) { 1900 if (ndam >= maxdam)
1901 {
1750 maxdam = ndam; 1902 maxdam = ndam;
1751 maxattacktype = 1<<attacknum; 1903 maxattacktype = 1 << attacknum;
1904 }
1905 }
1752 } 1906 }
1753 } 1907
1754 }
1755
1756 /* if this is friendly fire then do a set % of damage only 1908 /* if this is friendly fire then do a set % of damage only
1757 * Note - put a check in to make sure this attack is actually 1909 * Note - put a check in to make sure this attack is actually
1758 * doing damage - otherwise, the +1 in the code below will make 1910 * doing damage - otherwise, the +1 in the code below will make
1759 * an attack do damage before when it otherwise didn't 1911 * an attack do damage before when it otherwise didn't
1760 */ 1912 */
1761 friendlyfire = friendly_fire(op, hitter); 1913 friendlyfire = friendly_fire (op, hitter);
1762 if (friendlyfire && maxdam){ 1914 if (friendlyfire && maxdam)
1915 {
1763 maxdam = ((dam * settings.set_friendly_fire) / 100); 1916 maxdam = ((dam * settings.set_friendly_fire) / 100);
1764#ifndef COZY_SERVER 1917#ifndef COZY_SERVER
1918 maxdam++;
1919#endif
1920
1921#ifdef ATTACK_DEBUG
1922 LOG (llevDebug, "Friendly fire (type:%d setting: %d%) did %d damage dropped to %d\n",
1923 friendlyfire, settings.set_friendly_fire, dam, maxdam);
1924#endif
1925 }
1926
1927 if (!full_hit)
1928 {
1929 archetype *at;
1930 int area;
1931 int remainder;
1932
1933 area = 0;
1934 for (at = op->arch; at != NULL; at = at->more)
1935 area++;
1936 assert (area > 0);
1937
1938 /* basically: maxdam /= area; we try to "simulate" a float
1939 value-effect */
1940 remainder = 100 * (maxdam % area) / area;
1941 maxdam /= area;
1942 if (RANDOM () % 100 < remainder)
1765 maxdam++; 1943 maxdam++;
1944 }
1945
1946#ifdef ATTACK_DEBUG
1947 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam);
1766#endif 1948#endif
1767
1768#ifdef ATTACK_DEBUG
1769 LOG(llevDebug,"Friendly fire (type:%d setting: %d%) did %d damage dropped to %d\n",
1770 friendlyfire, settings.set_friendly_fire, dam, maxdam);
1771#endif
1772 }
1773 1949
1774 if (!full_hit) {
1775 archetype *at;
1776 int area;
1777 int remainder;
1778
1779 area = 0;
1780 for(at = op->arch; at != NULL; at = at->more)
1781 area++;
1782 assert(area > 0);
1783
1784 /* basically: maxdam /= area; we try to "simulate" a float
1785 value-effect */
1786 remainder = 100*(maxdam%area)/area;
1787 maxdam /= area;
1788 if (RANDOM()%100 < remainder)
1789 maxdam++;
1790 }
1791
1792#ifdef ATTACK_DEBUG
1793 LOG(llevDebug,"Attacktype %d did %d damage\n", type, maxdam);
1794#endif
1795
1796 if(get_owner(hitter)) 1950 if (get_owner (hitter))
1797 op->enemy=hitter->owner; 1951 op->enemy = hitter->owner;
1798 else if (QUERY_FLAG(hitter,FLAG_ALIVE)) 1952 else if (QUERY_FLAG (hitter, FLAG_ALIVE))
1799 op->enemy=hitter; 1953 op->enemy = hitter;
1800 1954
1801 if(QUERY_FLAG(op,FLAG_UNAGGRESSIVE) && op->type != PLAYER) { 1955 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER)
1956 {
1802 /* The unaggressives look after themselves 8) */ 1957 /* The unaggressives look after themselves 8) */
1803 CLEAR_FLAG(op, FLAG_UNAGGRESSIVE); 1958 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE);
1804 npc_call_help(op); 1959 npc_call_help (op);
1805 } 1960 }
1806 1961
1807 if (magic && did_make_save(op, op->level, 0)) 1962 if (magic && did_make_save (op, op->level, 0))
1808 maxdam=maxdam/2; 1963 maxdam = maxdam / 2;
1809 1964
1810 attack_message(maxdam, maxattacktype, op, hitter); 1965 attack_message (maxdam, maxattacktype, op, hitter);
1811 1966
1812 op->stats.hp-=maxdam; 1967 op->stats.hp -= maxdam;
1813 1968
1814 /* Eneq(@csd.uu.se): Check to see if monster runs away. */ 1969 /* Eneq(@csd.uu.se): Check to see if monster runs away. */
1815 if ((op->stats.hp>=0) && 1970 if ((op->stats.hp >= 0) &&
1816 (QUERY_FLAG(op, FLAG_MONSTER) || op->type == PLAYER) && 1971 (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) &&
1817 op->stats.hp<(signed short)(((float)op->run_away/(float)100)* 1972 op->stats.hp < (signed short) (((float) op->run_away / (float) 100) * (float) op->stats.maxhp))
1818 (float)op->stats.maxhp)) { 1973 {
1819 1974
1820 if (QUERY_FLAG(op, FLAG_MONSTER)) 1975 if (QUERY_FLAG (op, FLAG_MONSTER))
1821 SET_FLAG(op, FLAG_RUN_AWAY); 1976 SET_FLAG (op, FLAG_RUN_AWAY);
1822 else 1977 else
1823 scare_creature(op, hitter); 1978 scare_creature (op, hitter);
1824 } 1979 }
1825 1980
1826 if(QUERY_FLAG(op,FLAG_TEAR_DOWN)) { 1981 if (QUERY_FLAG (op, FLAG_TEAR_DOWN))
1982 {
1827 if (maxdam) 1983 if (maxdam)
1828 tear_down_wall(op); 1984 tear_down_wall (op);
1829 return maxdam; /* nothing more to do for wall */ 1985 return maxdam; /* nothing more to do for wall */
1830 } 1986 }
1831 1987
1832 /* See if the creature has been killed */ 1988 /* See if the creature has been killed */
1833 rtn_kill = kill_object(op, maxdam, hitter, type); 1989 rtn_kill = kill_object (op, maxdam, hitter, type);
1834 if (rtn_kill != -1) 1990 if (rtn_kill != -1)
1835 return rtn_kill; 1991 return rtn_kill;
1836 1992
1837 1993
1838 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note 1994 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note
1839 * that before if the player was immune to ghosthit, the monster 1995 * that before if the player was immune to ghosthit, the monster
1840 * remained - that is no longer the case. 1996 * remained - that is no longer the case.
1841 */ 1997 */
1842 if(QUERY_FLAG(hitter, FLAG_ONE_HIT)) { 1998 if (QUERY_FLAG (hitter, FLAG_ONE_HIT))
1999 {
1843 if(QUERY_FLAG(hitter,FLAG_FRIENDLY)) 2000 if (QUERY_FLAG (hitter, FLAG_FRIENDLY))
1844 remove_friendly_object(hitter); 2001 remove_friendly_object (hitter);
1845 remove_ob(hitter); 2002 remove_ob (hitter);
1846 free_object(hitter); 2003 free_object (hitter);
1847 } 2004 }
1848 /* Lets handle creatures that are splitting now */ 2005 /* Lets handle creatures that are splitting now */
1849 else if(type&AT_PHYSICAL&&!QUERY_FLAG(op, FLAG_FREED)&&QUERY_FLAG(op,FLAG_SPLITTING)) { 2006 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING))
1850 int i; 2007 {
2008 int i;
1851 int friendly = QUERY_FLAG(op,FLAG_FRIENDLY); 2009 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY);
1852 int unaggressive = QUERY_FLAG(op, FLAG_UNAGGRESSIVE); 2010 int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE);
1853 object *owner = get_owner(op); 2011 object *owner = get_owner (op);
1854 2012
1855 if(!op->other_arch) { 2013 if (!op->other_arch)
2014 {
1856 LOG(llevError,"SPLITTING without other_arch error.\n"); 2015 LOG (llevError, "SPLITTING without other_arch error.\n");
1857 return maxdam; 2016 return maxdam;
1858 } 2017 }
1859 remove_ob(op); 2018 remove_ob (op);
1860 for(i=0;i<NROFNEWOBJS(op);i++) { /* This doesn't handle op->more yet */ 2019 for (i = 0; i < NROFNEWOBJS (op); i++)
2020 { /* This doesn't handle op->more yet */
1861 object *tmp=arch_to_object(op->other_arch); 2021 object *tmp = arch_to_object (op->other_arch);
1862 int j; 2022 int j;
1863 2023
1864 tmp->stats.hp=op->stats.hp; 2024 tmp->stats.hp = op->stats.hp;
1865 if (friendly) { 2025 if (friendly)
2026 {
1866 SET_FLAG(tmp, FLAG_FRIENDLY); 2027 SET_FLAG (tmp, FLAG_FRIENDLY);
1867 add_friendly_object(tmp); 2028 add_friendly_object (tmp);
1868 tmp->attack_movement = PETMOVE; 2029 tmp->attack_movement = PETMOVE;
1869 if (owner!=NULL) 2030 if (owner != NULL)
1870 set_owner(tmp,owner); 2031 set_owner (tmp, owner);
1871 } 2032 }
1872 if (unaggressive) 2033 if (unaggressive)
1873 SET_FLAG(tmp, FLAG_UNAGGRESSIVE); 2034 SET_FLAG (tmp, FLAG_UNAGGRESSIVE);
1874 j=find_first_free_spot(tmp,op->map,op->x,op->y); 2035 j = find_first_free_spot (tmp, op->map, op->x, op->y);
1875 if (j==-1) /* No spot to put this monster */ 2036 if (j == -1) /* No spot to put this monster */
1876 free_object(tmp); 2037 free_object (tmp);
1877 else { 2038 else
2039 {
1878 tmp->x=op->x+freearr_x[j],tmp->y=op->y+freearr_y[j]; 2040 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j];
1879 insert_ob_in_map(tmp,op->map,NULL,0); 2041 insert_ob_in_map (tmp, op->map, NULL, 0);
1880 } 2042 }
1881 } 2043 }
1882 if(friendly) 2044 if (friendly)
1883 remove_friendly_object(op); 2045 remove_friendly_object (op);
1884 free_object(op); 2046 free_object (op);
1885 } 2047 }
1886 else if(type & AT_DRAIN && hitter->type==GRIMREAPER&&hitter->value++>10) { 2048 else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10)
2049 {
1887 remove_ob(hitter); 2050 remove_ob (hitter);
1888 free_object(hitter); 2051 free_object (hitter);
1889 } 2052 }
1890 return maxdam; 2053 return maxdam;
1891} 2054}
1892 2055
1893 2056
2057void
1894void poison_player(object *op, object *hitter, int dam) 2058poison_player (object *op, object *hitter, int dam)
1895{ 2059{
1896 archetype *at = find_archetype("poisoning"); 2060 archetype *at = find_archetype ("poisoning");
1897 object *tmp=present_arch_in_ob(at,op); 2061 object *tmp = present_arch_in_ob (at, op);
1898 2062
1899 if(tmp==NULL) { 2063 if (tmp == NULL)
2064 {
1900 if((tmp=arch_to_object(at))==NULL) 2065 if ((tmp = arch_to_object (at)) == NULL)
1901 LOG(llevError,"Failed to clone arch poisoning.\n"); 2066 LOG (llevError, "Failed to clone arch poisoning.\n");
1902 else { 2067 else
2068 {
1903 tmp = insert_ob_in_ob(tmp,op); 2069 tmp = insert_ob_in_ob (tmp, op);
1904 /* peterm: give poisoning some teeth. It should 2070 /* peterm: give poisoning some teeth. It should
1905 * be able to kill things better than it does: 2071 * be able to kill things better than it does:
1906 * damage should be dependent something--I choose to 2072 * damage should be dependent something--I choose to
1907 * do this: if it's a monster, the damage from the 2073 * do this: if it's a monster, the damage from the
1908 * poisoning goes as the level of the monster/2. 2074 * poisoning goes as the level of the monster/2.
1909 * If anything else, goes as damage. 2075 * If anything else, goes as damage.
1910 */ 2076 */
1911 2077
1912 if(QUERY_FLAG(hitter,FLAG_ALIVE)) 2078 if (QUERY_FLAG (hitter, FLAG_ALIVE))
1913 tmp->stats.dam += hitter->level/2; 2079 tmp->stats.dam += hitter->level / 2;
1914 else 2080 else
1915 tmp->stats.dam = dam; 2081 tmp->stats.dam = dam;
1916 2082
1917 copy_owner(tmp,hitter); /* so we get credit for poisoning kills */ 2083 copy_owner (tmp, hitter); /* so we get credit for poisoning kills */
1918 if(hitter->skill && hitter->skill != tmp->skill) { 2084 if (hitter->skill && hitter->skill != tmp->skill)
1919 if (tmp->skill) free_string(tmp->skill); 2085 {
1920 tmp->skill = add_refcount(hitter->skill); 2086 tmp->skill = hitter->skill;
1921 } 2087 }
1922 2088
1923 tmp->stats.food+=dam; /* more damage, longer poisoning */ 2089 tmp->stats.food += dam; /* more damage, longer poisoning */
1924 2090
1925 if(op->type==PLAYER) { 2091 if (op->type == PLAYER)
2092 {
1926 /* player looses stats, maximum is -10 of each */ 2093 /* player looses stats, maximum is -10 of each */
1927 tmp->stats.Con= MAX(-(dam/4+1), -10); 2094 tmp->stats.Con = MAX (-(dam / 4 + 1), -10);
1928 tmp->stats.Str= MAX(-(dam/3+2), -10); 2095 tmp->stats.Str = MAX (-(dam / 3 + 2), -10);
1929 tmp->stats.Dex= MAX(-(dam/6+1), -10); 2096 tmp->stats.Dex = MAX (-(dam / 6 + 1), -10);
1930 tmp->stats.Int= MAX(-dam/7, -10); 2097 tmp->stats.Int = MAX (-dam / 7, -10);
1931 SET_FLAG(tmp,FLAG_APPLIED); 2098 SET_FLAG (tmp, FLAG_APPLIED);
1932 fix_player(op); 2099 fix_player (op);
1933 new_draw_info(NDI_UNIQUE, 0,op,"You suddenly feel very ill."); 2100 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill.");
1934 } 2101 }
1935 if (hitter->type == PLAYER) 2102 if (hitter->type == PLAYER)
1936 new_draw_info_format(NDI_UNIQUE, 0, hitter, "You poison %s.", 2103 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name);
1937 op->name);
1938 else if (get_owner(hitter) != NULL && hitter->owner->type == PLAYER) 2104 else if (get_owner (hitter) != NULL && hitter->owner->type == PLAYER)
1939 new_draw_info_format(NDI_UNIQUE, 0, hitter->owner, 2105 new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name);
1940 "Your %s poisons %s.", hitter->name, op->name); 2106 }
1941 }
1942 tmp->speed_left=0; 2107 tmp->speed_left = 0;
1943 } 2108 }
1944 else 2109 else
1945 tmp->stats.food++; 2110 tmp->stats.food++;
1946} 2111}
1947 2112
2113void
1948void slow_player(object *op,object *hitter,int dam) 2114slow_player (object *op, object *hitter, int dam)
2115{
1949{ archetype *at = find_archetype("slowness"); 2116 archetype *at = find_archetype ("slowness");
1950 object *tmp; 2117 object *tmp;
2118
1951 if(at == NULL) { 2119 if (at == NULL)
2120 {
1952 LOG(llevError,"Can't find slowness archetype.\n"); 2121 LOG (llevError, "Can't find slowness archetype.\n");
1953 } 2122 }
1954 if((tmp=present_arch_in_ob(at,op)) == NULL) { 2123 if ((tmp = present_arch_in_ob (at, op)) == NULL)
2124 {
1955 tmp = arch_to_object(at); 2125 tmp = arch_to_object (at);
1956 tmp = insert_ob_in_ob(tmp,op); 2126 tmp = insert_ob_in_ob (tmp, op);
1957 new_draw_info(NDI_UNIQUE, 0,op,"The world suddenly moves very fast!"); 2127 new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!");
2128 }
1958 } else 2129 else
1959 tmp->stats.food++; 2130 tmp->stats.food++;
1960 SET_FLAG(tmp, FLAG_APPLIED); 2131 SET_FLAG (tmp, FLAG_APPLIED);
1961 tmp->speed_left=0; 2132 tmp->speed_left = 0;
1962 fix_player(op); 2133 fix_player (op);
1963} 2134}
1964 2135
2136void
1965void confuse_player(object *op, object *hitter, int dam) 2137confuse_player (object *op, object *hitter, int dam)
1966{ 2138{
1967 object *tmp; 2139 object *tmp;
1968 int maxduration; 2140 int maxduration;
1969 2141
1970 tmp = present_in_ob_by_name(FORCE,"confusion", op); 2142 tmp = present_in_ob_by_name (FORCE, "confusion", op);
1971 if(!tmp) { 2143 if (!tmp)
1972 tmp = get_archetype(FORCE_NAME);
1973 tmp = insert_ob_in_ob(tmp,op);
1974 }
1975 2144 {
2145 tmp = get_archetype (FORCE_NAME);
2146 tmp = insert_ob_in_ob (tmp, op);
2147 }
2148
1976 /* Duration added per hit and max. duration of confusion both depend 2149 /* Duration added per hit and max. duration of confusion both depend
1977 * on the player's resistance 2150 * on the player's resistance
1978 */ 2151 */
1979 tmp->speed = 0.05; 2152 tmp->speed = 0.05;
1980 tmp->subtype = FORCE_CONFUSION; 2153 tmp->subtype = FORCE_CONFUSION;
1981 tmp->duration = 8 + MAX(1, 5*(100-op->resist[ATNR_CONFUSION])/100); 2154 tmp->duration = 8 + MAX (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100);
1982 if (tmp->name) free_string(tmp->name);
1983 tmp->name = add_string("confusion"); 2155 tmp->name = "confusion";
1984 maxduration = MAX(2, 30*(100-op->resist[ATNR_CONFUSION])/100); 2156 maxduration = MAX (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100);
1985 if( tmp->duration > maxduration) 2157 if (tmp->duration > maxduration)
1986 tmp->duration = maxduration; 2158 tmp->duration = maxduration;
1987 2159
1988 if(op->type == PLAYER && !QUERY_FLAG(op,FLAG_CONFUSED)) 2160 if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED))
1989 new_draw_info(NDI_UNIQUE, 0,op,"You suddenly feel very confused!"); 2161 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!");
1990 SET_FLAG(op, FLAG_CONFUSED); 2162 SET_FLAG (op, FLAG_CONFUSED);
1991} 2163}
1992 2164
2165void
1993void blind_player(object *op, object *hitter, int dam) 2166blind_player (object *op, object *hitter, int dam)
1994{ 2167{
1995 object *tmp,*owner; 2168 object *tmp, *owner;
1996 2169
1997 /* Save some work if we know it isn't going to affect the player */ 2170 /* Save some work if we know it isn't going to affect the player */
1998 if (op->resist[ATNR_BLIND]==100) return; 2171 if (op->resist[ATNR_BLIND] == 100)
2172 return;
1999 2173
2000 tmp = present_in_ob(BLINDNESS,op); 2174 tmp = present_in_ob (BLINDNESS, op);
2001 if(!tmp) { 2175 if (!tmp)
2176 {
2002 tmp = get_archetype("blindness"); 2177 tmp = get_archetype ("blindness");
2003 SET_FLAG(tmp, FLAG_BLIND); 2178 SET_FLAG (tmp, FLAG_BLIND);
2004 SET_FLAG(tmp, FLAG_APPLIED); 2179 SET_FLAG (tmp, FLAG_APPLIED);
2005 /* use floats so we don't lose too much precision due to rounding errors. 2180 /* use floats so we don't lose too much precision due to rounding errors.
2006 * speed is a float anyways. 2181 * speed is a float anyways.
2007 */ 2182 */
2008 tmp->speed = tmp->speed * (100.0 - (float)op->resist[ATNR_BLIND]) / 100; 2183 tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100;
2009 2184
2010 tmp = insert_ob_in_ob(tmp,op); 2185 tmp = insert_ob_in_ob (tmp, op);
2011 change_abil(op,tmp); /* Mostly to display any messages */ 2186 change_abil (op, tmp); /* Mostly to display any messages */
2012 fix_player(op); /* This takes care of some other stuff */ 2187 fix_player (op); /* This takes care of some other stuff */
2013 2188
2189 if (hitter->owner)
2014 if(hitter->owner) owner = get_owner(hitter); 2190 owner = get_owner (hitter);
2191 else
2015 else owner = hitter; 2192 owner = hitter;
2016 2193
2017 new_draw_info_format(NDI_UNIQUE,0,owner, 2194 new_draw_info_format (NDI_UNIQUE, 0, owner, "Your attack blinds %s!", query_name (op));
2018 "Your attack blinds %s!",query_name(op));
2019 } 2195 }
2020 tmp->stats.food += dam; 2196 tmp->stats.food += dam;
2021 if(tmp->stats.food > 10) tmp->stats.food = 10; 2197 if (tmp->stats.food > 10)
2198 tmp->stats.food = 10;
2022} 2199}
2023 2200
2201void
2024void paralyze_player(object *op, object *hitter, int dam) 2202paralyze_player (object *op, object *hitter, int dam)
2025{ 2203{
2026 float effect,max; 2204 float effect, max;
2205
2027 /* object *tmp; */ 2206 /* object *tmp; */
2028 2207
2029 /* This is strange stuff... someone knows for what this is 2208 /* This is strange stuff... someone knows for what this is
2030 * written? Well, i think this can and should be removed 2209 * written? Well, i think this can and should be removed
2031 */ 2210 */
2032 2211
2033 /* 2212 /*
2034 if((tmp=present(PARAIMAGE,op->map,op->x,op->y))==NULL) { 2213 if((tmp=present(PARAIMAGE,op->map,op->x,op->y))==NULL) {
2035 tmp=clone_arch(PARAIMAGE); 2214 tmp=clone_arch(PARAIMAGE);
2036 tmp->x=op->x,tmp->y=op->y; 2215 tmp->x=op->x,tmp->y=op->y;
2037 insert_ob_in_map(tmp,op->map,tmp,INS_NO_MERGE | INS_NO_WALK_ON); 2216 insert_ob_in_map(tmp,op->map,tmp,INS_NO_MERGE | INS_NO_WALK_ON);
2038 } 2217 }
2039 */ 2218 */
2040 2219
2041 /* Do this as a float - otherwise, rounding might very well reduce this to 0 */ 2220 /* Do this as a float - otherwise, rounding might very well reduce this to 0 */
2042 effect = (float)dam * 3.0 * (100.0 - op->resist[ATNR_PARALYZE]) / 100; 2221 effect = (float) dam *3.0 * (100.0 - op->resist[ATNR_PARALYZE]) / 100;
2043 2222
2044 if (effect==0) return; 2223 if (effect == 0)
2224 return;
2045 2225
2046 op->speed_left-=FABS(op->speed)*effect; 2226 op->speed_left -= FABS (op->speed) * effect;
2047 /* tmp->stats.food+=(signed short) effect/op->speed; */ 2227 /* tmp->stats.food+=(signed short) effect/op->speed; */
2048 2228
2049 /* max number of ticks to be affected for. */ 2229 /* max number of ticks to be affected for. */
2050 max = (100 - op->resist[ATNR_PARALYZE])/ 2; 2230 max = (100 - op->resist[ATNR_PARALYZE]) / 2;
2051 if (op->speed_left< -(FABS(op->speed)*max)) 2231 if (op->speed_left < -(FABS (op->speed) * max))
2052 op->speed_left = (float) -(FABS(op->speed)*max); 2232 op->speed_left = (float) -(FABS (op->speed) * max);
2053 2233
2054/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */ 2234/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */
2055} 2235}
2056 2236
2057 2237
2058/* Attempts to kill 'op'. hitter is the attack object, dam is 2238/* Attempts to kill 'op'. hitter is the attack object, dam is
2059 * the computed damaged. 2239 * the computed damaged.
2060 */ 2240 */
2241void
2061void deathstrike_player(object *op, object *hitter, int *dam) 2242deathstrike_player (object *op, object *hitter, int *dam)
2062{ 2243{
2063 /* The intention of a death attack is to kill outright things 2244 /* The intention of a death attack is to kill outright things
2064 ** that are a lot weaker than the attacker, have a chance of killing 2245 ** that are a lot weaker than the attacker, have a chance of killing
2065 ** things somewhat weaker than the caster, and no chance of 2246 ** things somewhat weaker than the caster, and no chance of
2066 ** killing something equal or stronger than the attacker. 2247 ** killing something equal or stronger than the attacker.
2067 ** Also, if a deathstrike attack has a slaying, any monster 2248 ** Also, if a deathstrike attack has a slaying, any monster
2068 ** whose name or race matches a comma-delimited list in the slaying 2249 ** whose name or race matches a comma-delimited list in the slaying
2069 ** field of the deathstriking object */ 2250 ** field of the deathstriking object */
2070 2251
2071 int atk_lev, def_lev, kill_lev; 2252 int atk_lev, def_lev, kill_lev;
2072 2253
2073 if(hitter->slaying) 2254 if (hitter->slaying)
2074 if(!( (QUERY_FLAG(op,FLAG_UNDEAD)&&strstr(hitter->slaying,undead_name)) || 2255 if (!((QUERY_FLAG (op, FLAG_UNDEAD) && strstr (hitter->slaying, undead_name)) || (op->race && strstr (hitter->slaying, op->race))))
2075 (op->race&&strstr(hitter->slaying,op->race)))) return; 2256 return;
2076 2257
2077 def_lev = op->level; 2258 def_lev = op->level;
2078 if (def_lev < 1) { 2259 if (def_lev < 1)
2260 {
2079 LOG (llevError, "BUG: arch %s, name %s with level < 1\n", 2261 LOG (llevError, "BUG: arch %s, name %s with level < 1\n", &op->arch->name, &op->name);
2080 op->arch->name, op->name);
2081 def_lev = 1; 2262 def_lev = 1;
2082 } 2263 }
2083 atk_lev = (hitter->chosen_skill?hitter->chosen_skill->level:hitter->level) / 2; 2264 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2;
2084 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n", 2265 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n",
2085 atk_lev, def_lev); */ 2266 atk_lev, def_lev); */
2086 2267
2087 if(atk_lev >= def_lev ){ 2268 if (atk_lev >= def_lev)
2269 {
2088 kill_lev = random_roll(0, atk_lev-1, hitter, PREFER_HIGH); 2270 kill_lev = random_roll (0, atk_lev - 1, hitter, PREFER_HIGH);
2089 2271
2090 /* Note that the below effectively means the ratio of the atk vs 2272 /* Note that the below effectively means the ratio of the atk vs
2091 * defener level is important - if level 52 character has very little 2273 * defener level is important - if level 52 character has very little
2092 * chance of killing a level 50 monster. This should probably be 2274 * chance of killing a level 50 monster. This should probably be
2093 * redone. 2275 * redone.
2094 */ 2276 */
2095 if(kill_lev >= def_lev) { 2277 if (kill_lev >= def_lev)
2278 {
2096 *dam = op->stats.hp+10; /* take all hp. they can still save for 1/2 */ 2279 *dam = op->stats.hp + 10; /* take all hp. they can still save for 1/2 */
2097 /* I think this doesn't really do much. Because of 2280 /* I think this doesn't really do much. Because of
2098 * integer rounding, this only makes any difference if the 2281 * integer rounding, this only makes any difference if the
2099 * attack level is double the defender level. 2282 * attack level is double the defender level.
2100 */ 2283 */
2101 *dam *= kill_lev / def_lev; 2284 *dam *= kill_lev / def_lev;
2102 } 2285 }
2103 } else { 2286 }
2287 else
2288 {
2104 *dam = 0; /* no harm done */ 2289 *dam = 0; /* no harm done */
2105 } 2290 }
2106} 2291}
2107 2292
2108/* thrown_item_effect() - handles any special effects of thrown 2293/* thrown_item_effect() - handles any special effects of thrown
2109 * items (like attacking living creatures--a potion thrown at a 2294 * items (like attacking living creatures--a potion thrown at a
2110 * monster). 2295 * monster).
2111 */ 2296 */
2297static void
2112static void thrown_item_effect (object *hitter, object *victim) 2298thrown_item_effect (object *hitter, object *victim)
2113{ 2299{
2114 if(!QUERY_FLAG(hitter,FLAG_ALIVE)) { 2300 if (!QUERY_FLAG (hitter, FLAG_ALIVE))
2301 {
2115 /* May not need a switch for just 2 types, but this makes it 2302 /* May not need a switch for just 2 types, but this makes it
2116 * easier for expansion. 2303 * easier for expansion.
2117 */ 2304 */
2118 switch (hitter->type) { 2305 switch (hitter->type)
2306 {
2119 case POTION: 2307 case POTION:
2120 /* should player get a save throw instead of checking magic protection? */ 2308 /* should player get a save throw instead of checking magic protection? */
2121 if(QUERY_FLAG(victim,FLAG_ALIVE)&&!QUERY_FLAG(victim,FLAG_UNDEAD) 2309 if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_UNDEAD) && (victim->resist[ATNR_MAGIC] < 60))
2122 &&(victim->resist[ATNR_MAGIC]<60)) (void) apply_potion(victim,hitter); 2310 (void) apply_potion (victim, hitter);
2123 break; 2311 break;
2124 2312
2125 case POISON: /* poison drinks */ 2313 case POISON: /* poison drinks */
2126 /* As with potions, should monster get a save? */ 2314 /* As with potions, should monster get a save? */
2127 if(QUERY_FLAG(victim,FLAG_ALIVE)&&!QUERY_FLAG(victim,FLAG_UNDEAD) 2315 if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_UNDEAD) && (victim->resist[ATNR_POISON] < 60))
2128 &&(victim->resist[ATNR_POISON]<60)) apply_poison(victim,hitter); 2316 apply_poison (victim, hitter);
2129 break; 2317 break;
2130 2318
2131 /* Removed case statements that did nothing. 2319 /* Removed case statements that did nothing.
2132 * food may be poisonous, but monster must be willing to eat it, 2320 * food may be poisonous, but monster must be willing to eat it,
2133 * so we don't handle it here. 2321 * so we don't handle it here.
2134 * Containers should perhaps break open, but that code was disabled. 2322 * Containers should perhaps break open, but that code was disabled.
2135 */ 2323 */
2136 } 2324 }
2137 } 2325 }
2138} 2326}
2139 2327
2140/* adj_attackroll() - adjustments to attacks by various conditions */ 2328/* adj_attackroll() - adjustments to attacks by various conditions */
2141 2329
2330int
2142int adj_attackroll (object *hitter, object *target) { 2331adj_attackroll (object *hitter, object *target)
2332{
2143 object *attacker = hitter; 2333 object *attacker = hitter;
2144 int adjust=0; 2334 int adjust = 0;
2145 2335
2146 /* safety */ 2336 /* safety */
2147 if(!target||!hitter||!hitter->map||!target->map||!on_same_map(hitter,target)) { 2337 if (!target || !hitter || !hitter->map || !target->map || !on_same_map (hitter, target))
2338 {
2148 LOG (llevError, "BUG: adj_attackroll(): hitter and target not on same " 2339 LOG (llevError, "BUG: adj_attackroll(): hitter and target not on same " "map\n");
2149 "map\n"); 2340 return 0;
2341 }
2342
2343 /* aimed missiles use the owning object's sight */
2344 if (is_aimed_missile (hitter))
2345 {
2346 if ((attacker = get_owner (hitter)) == NULL)
2347 attacker = hitter;
2348 /* A player who saves but hasn't quit still could have objects
2349 * owned by him - need to handle that case to avoid crashes.
2350 */
2351 if (QUERY_FLAG (attacker, FLAG_REMOVED))
2352 attacker = hitter;
2353 }
2354 else if (!QUERY_FLAG (hitter, FLAG_ALIVE))
2150 return 0; 2355 return 0;
2151 }
2152 2356
2153 /* aimed missiles use the owning object's sight */
2154 if(is_aimed_missile(hitter)) {
2155 if ((attacker = get_owner(hitter))==NULL) attacker = hitter;
2156 /* A player who saves but hasn't quit still could have objects
2157 * owned by him - need to handle that case to avoid crashes.
2158 */
2159 if (QUERY_FLAG(attacker, FLAG_REMOVED)) attacker = hitter;
2160 }
2161 else if(!QUERY_FLAG(hitter,FLAG_ALIVE))
2162 return 0;
2163
2164 /* determine the condtions under which we make an attack. 2357 /* determine the condtions under which we make an attack.
2165 * Add more cases, as the need occurs. */ 2358 * Add more cases, as the need occurs. */
2166 2359
2167 if(!can_see_enemy(attacker,target)) { 2360 if (!can_see_enemy (attacker, target))
2361 {
2168 /* target is unseen */ 2362 /* target is unseen */
2169 if(target->invisible || QUERY_FLAG(attacker,FLAG_BLIND)) 2363 if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND))
2170 adjust -= 10; 2364 adjust -= 10;
2171 /* dark map penalty for the hitter (lacks infravision if we got here). */ 2365 /* dark map penalty for the hitter (lacks infravision if we got here). */
2172 else if(target->map&&target->map->darkness>0&&!stand_in_light(target)) 2366 else if (target->map && target->map->darkness > 0 && !stand_in_light (target))
2173 adjust -= target->map->darkness; 2367 adjust -= target->map->darkness;
2174 } 2368 }
2175 2369
2176 if(QUERY_FLAG(attacker,FLAG_SCARED)) 2370 if (QUERY_FLAG (attacker, FLAG_SCARED))
2177 adjust -= 3; 2371 adjust -= 3;
2178 2372
2179 if(QUERY_FLAG(target,FLAG_UNAGGRESSIVE)) 2373 if (QUERY_FLAG (target, FLAG_UNAGGRESSIVE))
2180 adjust += 1; 2374 adjust += 1;
2181 2375
2182 if(QUERY_FLAG(target,FLAG_SCARED)) 2376 if (QUERY_FLAG (target, FLAG_SCARED))
2183 adjust += 1; 2377 adjust += 1;
2184 2378
2185 if(QUERY_FLAG(attacker,FLAG_CONFUSED)) 2379 if (QUERY_FLAG (attacker, FLAG_CONFUSED))
2186 adjust -= 3; 2380 adjust -= 3;
2187 2381
2188 /* if we attack at a different 'altitude' its harder */ 2382 /* if we attack at a different 'altitude' its harder */
2189 if((attacker->move_type & target->move_type)==0) 2383 if ((attacker->move_type & target->move_type) == 0)
2190 adjust -= 2; 2384 adjust -= 2;
2191 2385
2192#if 0 2386#if 0
2193 /* slower attacks are less likely to succeed. We should use a 2387 /* slower attacks are less likely to succeed. We should use a
2194 * comparison between attacker/target speeds BUT, players have 2388 * comparison between attacker/target speeds BUT, players have
2195 * a generally faster speed, so this will wind up being a HUGE 2389 * a generally faster speed, so this will wind up being a HUGE
2196 * disadantage for the monsters! Too bad, because missiles which 2390 * disadantage for the monsters! Too bad, because missiles which
2197 * fly fast should have a better chance of hitting a slower target. 2391 * fly fast should have a better chance of hitting a slower target.
2198 */ 2392 */
2199 if(hitter->speed<target->speed) 2393 if (hitter->speed < target->speed)
2200 adjust += ((float) hitter->speed-target->speed); 2394 adjust += ((float) hitter->speed - target->speed);
2201#endif 2395#endif
2202 2396
2203#if 0 2397#if 0
2204 LOG(llevDebug,"adj_attackroll() returns %d (%d)\n",adjust,attacker->count); 2398 LOG (llevDebug, "adj_attackroll() returns %d (%d)\n", adjust, attacker->count);
2205#endif 2399#endif
2206 2400
2207 return adjust; 2401 return adjust;
2208} 2402}
2209 2403
2210 2404
2211/* determine if the object is an 'aimed' missile */ 2405/* determine if the object is an 'aimed' missile */
2406int
2212int is_aimed_missile ( object *op) { 2407is_aimed_missile (object *op)
2408{
2213 2409
2214 /* I broke what used to be one big if into a few nested 2410 /* I broke what used to be one big if into a few nested
2215 * ones so that figuring out the logic is at least possible. 2411 * ones so that figuring out the logic is at least possible.
2216 */ 2412 */
2217 if (op && (op->move_type & MOVE_FLYING)) { 2413 if (op && (op->move_type & MOVE_FLYING))
2414 {
2218 if (op->type==ARROW || op->type==THROWN_OBJ) 2415 if (op->type == ARROW || op->type == THROWN_OBJ)
2219 return 1; 2416 return 1;
2220 else if (op->type==SPELL_EFFECT && (op->subtype == SP_BULLET || 2417 else if (op->type == SPELL_EFFECT && (op->subtype == SP_BULLET || op->subtype == SP_EXPLOSION))
2221 op->subtype == SP_EXPLOSION))
2222 return 1; 2418 return 1;
2223 } 2419 }
2224 return 0; 2420 return 0;
2225} 2421}
2226

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines