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.1 by elmex, Sun Aug 13 17:16:03 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.1 2006/08/13 17:16:03 elmex 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 /* Lauwenmark: Handle for plugin attack event */
689 execute_event(op, EVENT_ATTACK,hitter,hitter,NULL,SCRIPT_FIX_ALL);
690
691 /* Lauwenmark: This is used to handle script_weapons with weapons.
692 * Only used for players.
693 */
694 if (hitter->type==PLAYER)
695 { 783 }
696 if (hitter->current_weapon != NULL) 784
697 { 785 op_name = op->name;
698 /* Lauwenmark: Handle for plugin attack event */ 786
699 execute_event(hitter, EVENT_ATTACK,hitter->current_weapon, 787 roll = random_roll (1, 20, hitter, PREFER_HIGH);
700 op,NULL,SCRIPT_FIX_ALL); 788
789 /* Adjust roll for various situations. */
790 if (!simple_attack)
791 roll += adj_attackroll (hitter, op);
792
793 /* See if we hit the creature */
794 if (roll == 20 || op->stats.ac >= base_wc - roll)
795 {
796 int hitdam = base_dam;
797
798 if (settings.casting_time == TRUE)
701 } 799 {
800 if ((hitter->type == PLAYER) && (hitter->casting_time > -1))
801 {
802 hitter->casting_time = -1;
803 new_draw_info (NDI_UNIQUE, 0, hitter, "You attacked and lost " "your spell!");
702 } 804 }
703 op_tag = op->count;
704 hitter_tag = hitter->count;
705
706 /*
707 * A little check to make it more difficult to dance forward and back
708 * to avoid ever being hit by monsters.
709 */
710 if ( ! simple_attack && QUERY_FLAG (op, FLAG_MONSTER)
711 && op->speed_left > -(FABS(op->speed))*0.3)
712 {
713 /* Decrease speed BEFORE calling process_object. Otherwise, an
714 * infinite loop occurs, with process_object calling move_monster,
715 * which then gets here again. By decreasing the speed before
716 * we call process_object, the 'if' statement above will fail.
717 */
718 op->speed_left--;
719 process_object(op);
720 if (was_destroyed (op, op_tag) || was_destroyed (hitter, hitter_tag)
721 || abort_attack (op, hitter, simple_attack))
722 goto error;
723 }
724
725 add_refcount(op_name = op->name);
726
727 roll=random_roll(1, 20, hitter, PREFER_HIGH);
728
729 /* Adjust roll for various situations. */
730 if ( ! simple_attack)
731 roll += adj_attackroll(hitter,op);
732
733 /* See if we hit the creature */
734 if(roll==20 || op->stats.ac>=base_wc-roll) {
735 int hitdam = base_dam;
736 if (settings.casting_time == TRUE) {
737 if ((hitter->type == PLAYER)&&(hitter->casting_time > -1)){
738 hitter->casting_time = -1;
739 new_draw_info(NDI_UNIQUE, 0,hitter,"You attacked and lost "
740 "your spell!");
741 }
742 if ((op->casting_time > -1)&&(hitdam > 0)){ 805 if ((op->casting_time > -1) && (hitdam > 0))
743 op->casting_time = -1;
744 if (op->type == PLAYER) {
745 new_draw_info(NDI_UNIQUE, 0,op,"You were hit and lost "
746 "your spell!");
747 new_draw_info_format(NDI_ALL|NDI_UNIQUE,5,NULL,
748 "%s was hit by %s and lost a spell.",
749 op_name,hitter->name);
750 }
751 }
752 }
753 if ( ! simple_attack)
754 { 806 {
755 /* If you hit something, the victim should *always* wake up. 807 op->casting_time = -1;
756 * Before, invisible hitters could avoid doing this.
757 * -b.t. */
758 if (QUERY_FLAG (op, FLAG_SLEEP))
759 CLEAR_FLAG(op,FLAG_SLEEP);
760
761 /* If the victim can't see the attacker, it may alert others
762 * for help. */
763 if (op->type != PLAYER && ! can_see_enemy (op, hitter)
764 && ! get_owner (op) && rndm(0, op->stats.Int))
765 npc_call_help (op);
766
767 /* if you were hidden and hit by a creature, you are discovered*/
768 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE)) {
769 make_visible (op);
770 if (op->type == PLAYER) 808 if (op->type == PLAYER)
771 new_draw_info (NDI_UNIQUE, 0, op, 809 {
772 "You were hit by a wild attack. " 810 new_draw_info (NDI_UNIQUE, 0, op, "You were hit and lost " "your spell!");
773 "You are no longer hidden!"); 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 }
774 } 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);
775 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
776 /* thrown items (hitter) will have various effects 836 /* thrown items (hitter) will have various effects
777 * when they hit the victim. For things like thrown daggers, 837 * when they hit the victim. For things like thrown daggers,
778 * this sets 'hitter' to the actual dagger, and not the 838 * this sets 'hitter' to the actual dagger, and not the
779 * wrapper object. 839 * wrapper object.
780 */ 840 */
781 thrown_item_effect (hitter, op); 841 thrown_item_effect (hitter, op);
782 if (was_destroyed (hitter, hitter_tag) 842 if (was_destroyed (hitter, hitter_tag) || was_destroyed (op, op_tag) || abort_attack (op, hitter, simple_attack))
783 || was_destroyed (op, op_tag)
784 || abort_attack (op, hitter, simple_attack))
785 goto leave; 843 goto leave;
786 } 844 }
787 845
788 /* 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
789 * to go further and it will cause FPE's below. 847 * to go further and it will cause FPE's below.
790 */ 848 */
791 if (hitdam<=0) hitdam=1; 849 if (hitdam <= 0)
850 hitdam = 1;
792 851
793 type=hitter->attacktype; 852 type = hitter->attacktype;
794 if(!type) type=AT_PHYSICAL; 853 if (!type)
854 type = AT_PHYSICAL;
795 /* Handle monsters that hit back */ 855 /* Handle monsters that hit back */
796 if ( ! simple_attack && QUERY_FLAG (op, FLAG_HITBACK) 856 if (!simple_attack && QUERY_FLAG (op, FLAG_HITBACK) && QUERY_FLAG (hitter, FLAG_ALIVE))
797 && QUERY_FLAG (hitter, FLAG_ALIVE)) 857 {
798 {
799 if (op->attacktype & AT_ACID && hitter->type==PLAYER) 858 if (op->attacktype & AT_ACID && hitter->type == PLAYER)
800 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");
801 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);
802 PREFER_LOW),op, op->attacktype, 1); 861 if (was_destroyed (op, op_tag) || was_destroyed (hitter, hitter_tag) || abort_attack (op, hitter, simple_attack))
803 if (was_destroyed (op, op_tag)
804 || was_destroyed (hitter, hitter_tag)
805 || abort_attack (op, hitter, simple_attack))
806 goto leave; 862 goto leave;
807 } 863 }
808 864
809 /* In the new attack code, it should handle multiple attack 865 /* In the new attack code, it should handle multiple attack
810 * types in its area, so remove it from here. 866 * types in its area, so remove it from here.
811 */ 867 */
812 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);
813 hitter, type, 1); 869 if (was_destroyed (op, op_tag) || was_destroyed (hitter, hitter_tag) || abort_attack (op, hitter, simple_attack))
814 if (was_destroyed (op, op_tag) || was_destroyed (hitter, hitter_tag)
815 || abort_attack (op, hitter, simple_attack))
816 goto leave; 870 goto leave;
817 } /* end of if hitter hit op */ 871 } /* end of if hitter hit op */
818 /* if we missed, dam=0 */ 872 /* if we missed, dam=0 */
819 873
820 /*attack_message(dam, type, op, hitter);*/ 874 /*attack_message(dam, type, op, hitter); */
821 875
822 goto leave; 876 goto leave;
823 877
824 error: 878error:
825 dam = 1; 879 dam = 1;
826 goto leave;
827 880
828 leave: 881leave:
829 if (op_name)
830 free_string (op_name);
831 882
832 return dam; 883 return dam;
833} 884}
834 885
886int
835int attack_ob (object *op, object *hitter) 887attack_ob (object *op, object *hitter)
836{ 888{
837 889
838 if (hitter->head) 890 if (hitter->head)
839 hitter = hitter->head; 891 hitter = hitter->head;
840 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);
841} 893}
842 894
843/* op is the arrow, tmp is what is stopping the arrow. 895/* op is the arrow, tmp is what is stopping the arrow.
844 * 896 *
845 * 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.
846 */ 898 */
899static int
847static int stick_arrow (object *op, object *tmp) 900stick_arrow (object *op, object *tmp)
848{ 901{
849 /* 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.
850 * 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
851 * 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
852 * 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
853 * stick around. 906 * stick around.
854 */ 907 */
855 if (op->weight <= 5000 && tmp->stats.hp >= 0) { 908 if (op->weight <= 5000 && tmp->stats.hp >= 0)
909 {
856 if(tmp->head != NULL) 910 if (tmp->head != NULL)
857 tmp = tmp->head; 911 tmp = tmp->head;
912
858 remove_ob (op); 913 remove_ob (op);
859 op = insert_ob_in_ob(op,tmp); 914 op = insert_ob_in_ob (op, tmp);
915
860 if (tmp->type== PLAYER) 916 if (tmp->type == PLAYER)
861 esrv_send_item (tmp, op); 917 esrv_send_item (tmp, op);
918
862 return 1; 919 return 1;
920 }
863 } else 921 else
864 return 0; 922 return 0;
865} 923}
866 924
867/* hit_with_arrow() disassembles the missile, attacks the victim and 925/* hit_with_arrow() disassembles the missile, attacks the victim and
868 * reassembles the missile. 926 * reassembles the missile.
869 * 927 *
870 * 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
871 * isn't available anymore. 929 * isn't available anymore.
872 */ 930 */
931object *
873object *hit_with_arrow (object *op, object *victim) 932hit_with_arrow (object *op, object *victim)
874{ 933{
875 object *container, *hitter; 934 object *container, *hitter;
876 int hit_something = 0; 935 int hit_something = 0;
877 tag_t victim_tag, hitter_tag; 936 tag_t victim_tag, hitter_tag;
878 sint16 victim_x, victim_y; 937 sint16 victim_x, victim_y;
879 938
880 /* Disassemble missile */ 939 /* Disassemble missile */
881 if (op->inv) { 940 if (op->inv)
941 {
882 container = op; 942 container = op;
883 hitter = op->inv; 943 hitter = op->inv;
884 remove_ob (hitter); 944 remove_ob (hitter);
885 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);
886 /* 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
887 * might be called until this THROWN_OBJ is either reassembled or 947 * might be called until this THROWN_OBJ is either reassembled or
888 * 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
889 * THROWN_OBJs. */ 949 * THROWN_OBJs. */
890 } else { 950 }
951 else
952 {
891 container = NULL; 953 container = NULL;
892 hitter = op; 954 hitter = op;
893 } 955 }
894 956
895 /* Try to hit victim */ 957 /* Try to hit victim */
896 victim_x = victim->x; 958 victim_x = victim->x;
897 victim_y = victim->y; 959 victim_y = victim->y;
898 victim_tag = victim->count; 960 victim_tag = victim->count;
899 hitter_tag = hitter->count; 961 hitter_tag = hitter->count;
900 /* Lauwenmark: Handling plugin attack event for thrown items */ 962
901 if (execute_event(op, EVENT_ATTACK,hitter,victim,NULL,SCRIPT_FIX_ALL) == 0)
902 hit_something = attack_ob_simple (victim, hitter, op->stats.dam, 963 hit_something = attack_ob_simple (victim, hitter, op->stats.dam, op->stats.wc);
903 op->stats.wc);
904 964
905 /* 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
906 * arrow, move_apply() calls this function, arrow sticks in demon, 966 * arrow, move_apply() calls this function, arrow sticks in demon,
907 * 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
908 * 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
909 * other places as well!) 969 * other places as well!)
910 */ 970 */
911 if (was_destroyed (hitter, hitter_tag) || hitter->env != NULL) { 971 if (was_destroyed (hitter, hitter_tag) || hitter->env != NULL)
972 {
912 if (container) { 973 if (container)
974 {
913 remove_ob (container); 975 remove_ob (container);
914 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)
915 } 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))
916 return NULL; 1002 return NULL;
917 }
918 1003
919 /* Missile hit victim */
920 /* if the speed is > 10, then this is a fast moving arrow, we go straight
921 * through the target
922 */
923 if (hit_something && op->speed <= 10.0)
924 {
925 /* Stop arrow */
926 if (container == NULL) {
927 hitter = fix_stopped_arrow (hitter);
928 if (hitter == NULL)
929 return NULL;
930 } else {
931 remove_ob (container);
932 free_object (container);
933 }
934
935 /* Try to stick arrow into victim */
936 if ( ! was_destroyed (victim, victim_tag)
937 && stick_arrow (hitter, victim))
938 return NULL;
939
940 /* Else try to put arrow on victim's map square 1004 /* Else try to put arrow on victim's map square
941 * 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
942 * space, that is good enough - with the new movement code, 1006 * space, that is good enough - with the new movement code,
943 * there is now the potential for lots of spaces where something 1007 * there is now the potential for lots of spaces where something
944 * 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
945 * way to handle those otherwise? 1009 * way to handle those otherwise?
946 */ 1010 */
947 if (victim_x != hitter->x || victim_y != hitter->y) { 1011 if (victim_x != hitter->x || victim_y != hitter->y)
1012 {
948 remove_ob (hitter); 1013 remove_ob (hitter);
949 hitter->x = victim_x; 1014 hitter->x = victim_x;
950 hitter->y = victim_y; 1015 hitter->y = victim_y;
951 insert_ob_in_map (hitter, victim->map, hitter,0); 1016 insert_ob_in_map (hitter, victim->map, hitter, 0);
1017 }
952 } else { 1018 else
1019 {
953 /* Else leave arrow where it is */ 1020 /* Else leave arrow where it is */
954 merge_ob (hitter, NULL); 1021 merge_ob (hitter, NULL);
955 } 1022 }
956 return NULL; 1023 return NULL;
957 } 1024 }
958 1025
959 if (hit_something && op->speed >= 10.0) 1026 if (hit_something && op->speed >= 10.0)
960 op->speed -= 1.0; 1027 op->speed -= 1.0;
961 1028
962 /* Missile missed victim - reassemble missile */ 1029 /* Missile missed victim - reassemble missile */
963 if (container) { 1030 if (container)
1031 {
964 remove_ob (hitter); 1032 remove_ob (hitter);
965 insert_ob_in_ob (hitter, container); 1033 insert_ob_in_ob (hitter, container);
966 } 1034 }
967 return op; 1035 return op;
968} 1036}
969 1037
970 1038
1039void
971void tear_down_wall(object *op) 1040tear_down_wall (object *op)
972{ 1041{
973 int perc=0; 1042 int perc = 0;
974 1043
975 if (!op->stats.maxhp) { 1044 if (!op->stats.maxhp)
1045 {
976 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);
977 perc = 1; 1047 perc = 1;
1048 }
978 } else if(!GET_ANIM_ID(op)) { 1049 else if (!GET_ANIM_ID (op))
1050 {
979 /* Object has been called - no animations, so remove it */ 1051 /* Object has been called - no animations, so remove it */
980 if(op->stats.hp<0) { 1052 if (op->stats.hp < 0)
1053 {
981 remove_ob(op); /* Should update LOS */ 1054 remove_ob (op); /* Should update LOS */
982 free_object(op); 1055 free_object (op);
983 /* 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 */
984 /*update_position(m, x, y);*/ 1057 /*update_position(m, x, y); */
985 } 1058 }
986 return; /* no animations, so nothing more to do */ 1059 return; /* no animations, so nothing more to do */
987 } 1060 }
988 perc = NUM_ANIMATIONS(op) 1061 perc = NUM_ANIMATIONS (op) - ((int) NUM_ANIMATIONS (op) * op->stats.hp) / op->stats.maxhp;
989 - ((int)NUM_ANIMATIONS(op)*op->stats.hp)/op->stats.maxhp;
990 if (perc >= (int) NUM_ANIMATIONS(op)) 1062 if (perc >= (int) NUM_ANIMATIONS (op))
991 perc = NUM_ANIMATIONS(op)-1; 1063 perc = NUM_ANIMATIONS (op) - 1;
992 else if (perc < 1) 1064 else if (perc < 1)
993 perc = 1; 1065 perc = 1;
994 SET_ANIMATION(op, perc); 1066 SET_ANIMATION (op, perc);
995 update_object(op,UP_OBJ_FACE); 1067 update_object (op, UP_OBJ_FACE);
996 if(perc==NUM_ANIMATIONS(op)-1) { /* Reached the last animation */ 1068 if (perc == NUM_ANIMATIONS (op) - 1)
1069 { /* Reached the last animation */
997 if(op->face==blank_face) { 1070 if (op->face == blank_face)
1071 {
998 /* If the last face is blank, remove the ob */ 1072 /* If the last face is blank, remove the ob */
999 remove_ob(op); /* Should update LOS */ 1073 remove_ob (op); /* Should update LOS */
1000 free_object(op); 1074 free_object (op);
1001 1075
1002 /* remove_ob should call update_position for us */ 1076 /* remove_ob should call update_position for us */
1003 /*update_position(m, x, y);*/ 1077 /*update_position(m, x, y); */
1004 1078
1005 } else { /* The last face was not blank, leave an image */ 1079 }
1080 else
1081 { /* The last face was not blank, leave an image */
1006 CLEAR_FLAG(op, FLAG_BLOCKSVIEW); 1082 CLEAR_FLAG (op, FLAG_BLOCKSVIEW);
1007 update_all_los(op->map, op->x, op->y); 1083 update_all_los (op->map, op->x, op->y);
1008 op->move_block = 0; 1084 op->move_block = 0;
1009 CLEAR_FLAG(op, FLAG_ALIVE); 1085 CLEAR_FLAG (op, FLAG_ALIVE);
1010 } 1086 }
1011 } 1087 }
1012} 1088}
1013 1089
1090void
1014void scare_creature(object *target, object *hitter) 1091scare_creature (object *target, object *hitter)
1015{ 1092{
1016 object *owner = get_owner(hitter); 1093 object *owner = get_owner (hitter);
1017 1094
1018 if (!owner) owner=hitter; 1095 if (!owner)
1096 owner = hitter;
1019 1097
1020 SET_FLAG(target, FLAG_SCARED); 1098 SET_FLAG (target, FLAG_SCARED);
1021 if (!target->enemy) target->enemy=owner; 1099 if (!target->enemy)
1100 target->enemy = owner;
1022} 1101}
1023 1102
1024 1103
1025/* 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
1026 * appropriate attacktype. Only 1 attacktype should be set at a time. 1105 * appropriate attacktype. Only 1 attacktype should be set at a time.
1027 * 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
1028 * take. However, it will do other effects (paralyzation, slow, etc.) 1107 * take. However, it will do other effects (paralyzation, slow, etc.)
1029 * 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
1030 * the attacktype. Makes it easier for the PR code. */ 1109 * the attacktype. Makes it easier for the PR code. */
1031 1110
1111int
1032int hit_player_attacktype(object *op, object *hitter, int dam, 1112hit_player_attacktype (object *op, object *hitter, int dam, uint32 attacknum, int magic)
1033 uint32 attacknum, int magic) { 1113{
1034 1114
1035 int doesnt_slay = 1; 1115 int doesnt_slay = 1;
1036 1116
1037 /* 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 */
1038 if (attacknum >= NROFATTACKS) { 1118 if (attacknum >= NROFATTACKS)
1119 {
1039 LOG(llevError, "hit_player_attacktype: Invalid attacknumber passed: %u\n", attacknum); 1120 LOG (llevError, "hit_player_attacktype: Invalid attacknumber passed: %u\n", attacknum);
1040 return 0; 1121 return 0;
1041 }
1042 1122 }
1123
1043 if (dam < 0) { 1124 if (dam < 0)
1125 {
1044 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);
1045 return 0; 1127 return 0;
1046 }
1047 1128 }
1129
1048 /* 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
1049 * people can't mess with that or it otherwise get confused. */ 1131 * people can't mess with that or it otherwise get confused. */
1050 if (attacknum == ATNR_INTERNAL) return dam; 1132 if (attacknum == ATNR_INTERNAL)
1051 1133 return dam;
1134
1052 if (hitter->slaying) { 1135 if (hitter->slaying)
1136 {
1053 if(((op->race != NULL) && strstr(hitter->slaying, op->race)) || 1137 if (((op->race != NULL) && strstr (hitter->slaying, op->race)) ||
1054 (op->arch && (op->arch->name != NULL) && 1138 (op->arch && (op->arch->name != NULL) && strstr (op->arch->name, hitter->slaying)))
1055 strstr(op->arch->name, hitter->slaying)) 1139 {
1056 ){ 1140 doesnt_slay = 0;
1057 doesnt_slay = 0; 1141 dam *= 3;
1058 dam *= 3;
1059 } 1142 }
1060 } 1143 }
1061 1144
1062 /* Adjust the damage for resistance. Note that neg. values increase damage. */ 1145 /* Adjust the damage for resistance. Note that neg. values increase damage. */
1063 if (op->resist[attacknum]) { 1146 if (op->resist[attacknum])
1147 {
1064 /* basically: dam = dam*(100-op->resist[attacknum])/100; 1148 /* basically: dam = dam*(100-op->resist[attacknum])/100;
1065 * 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 */
1066 dam *= (100-op->resist[attacknum]); 1150 dam *= (100 - op->resist[attacknum]);
1067 if (dam >= 100) dam /= 100; 1151 if (dam >= 100)
1152 dam /= 100;
1068 else 1153 else
1069 dam = (dam > (random_roll(0, 99, op, PREFER_LOW))) ? 1 : 0; 1154 dam = (dam > (random_roll (0, 99, op, PREFER_LOW))) ? 1 : 0;
1070 } 1155 }
1071 1156
1072 /* Special hack. By default, if immune to something, you 1157 /* Special hack. By default, if immune to something, you
1073 * shouldn't need to worry. However, acid is an exception, since 1158 * shouldn't need to worry. However, acid is an exception, since
1074 * it can still damage your items. Only include attacktypes if 1159 * it can still damage your items. Only include attacktypes if
1075 * special processing is needed */ 1160 * special processing is needed */
1076 1161
1077 if ((op->resist[attacknum] >= 100) && 1162 if ((op->resist[attacknum] >= 100) && doesnt_slay && (attacknum != ATNR_ACID))
1078 doesnt_slay && (attacknum != ATNR_ACID))
1079 return 0; 1163 return 0;
1080 1164
1081 /* Keep this in order - makes things easier to find */ 1165 /* Keep this in order - makes things easier to find */
1166
1167 switch (attacknum)
1082 1168 {
1083 switch(attacknum) {
1084 case ATNR_PHYSICAL: 1169 case ATNR_PHYSICAL:
1085 /* here also check for diseases */ 1170 /* here also check for diseases */
1086 check_physically_infect(op, hitter); 1171 check_physically_infect (op, hitter);
1087 break; 1172 break;
1088 1173
1089 /* Don't need to do anything for: 1174 /* Don't need to do anything for:
1090 magic, 1175 magic,
1091 fire, 1176 fire,
1092 electricity, 1177 electricity,
1093 cold */ 1178 cold */
1094 1179
1095 case ATNR_CONFUSION: 1180 case ATNR_CONFUSION:
1096 case ATNR_POISON: 1181 case ATNR_POISON:
1097 case ATNR_SLOW: 1182 case ATNR_SLOW:
1098 case ATNR_PARALYZE: 1183 case ATNR_PARALYZE:
1099 case ATNR_FEAR: 1184 case ATNR_FEAR:
1100 case ATNR_CANCELLATION: 1185 case ATNR_CANCELLATION:
1101 case ATNR_DEPLETE: 1186 case ATNR_DEPLETE:
1102 case ATNR_BLIND: 1187 case ATNR_BLIND:
1103 { 1188 {
1104 /* chance for inflicting a special attack depends on the 1189 /* chance for inflicting a special attack depends on the
1105 * difference between attacker's and defender's level 1190 * difference between attacker's and defender's level
1106 */ 1191 */
1107 int level_diff = MIN(110, MAX(0, op->level - hitter->level)); 1192 int level_diff = MIN (110, MAX (0, op->level - hitter->level));
1108 1193
1109 /* First, only creatures/players with speed can be affected. 1194 /* First, only creatures/players with speed can be affected.
1110 * Second, just getting hit doesn't mean it always affects 1195 * Second, just getting hit doesn't mean it always affects
1111 * you. Third, you still get a saving through against the 1196 * you. Third, you still get a saving through against the
1112 * effect. 1197 * effect.
1113 */ 1198 */
1114 if (op->speed && 1199 if (op->speed &&
1115 (QUERY_FLAG(op, FLAG_MONSTER) || op->type==PLAYER) && 1200 (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) &&
1116 !(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))
1117 !did_make_save(op, level_diff, op->resist[attacknum]/10)) { 1202 {
1118 1203
1119 /* Player has been hit by something */ 1204 /* Player has been hit by something */
1120 if (attacknum == ATNR_CONFUSION) confuse_player(op,hitter,dam); 1205 if (attacknum == ATNR_CONFUSION)
1121 else if (attacknum == ATNR_POISON) poison_player(op,hitter,dam); 1206 confuse_player (op, hitter, dam);
1122 else if (attacknum == ATNR_SLOW) slow_player(op,hitter,dam); 1207 else if (attacknum == ATNR_POISON)
1123 else if (attacknum == ATNR_PARALYZE) paralyze_player(op,hitter,dam); 1208 poison_player (op, hitter, dam);
1124 else if (attacknum == ATNR_FEAR) scare_creature(op, hitter); 1209 else if (attacknum == ATNR_SLOW)
1125 else if (attacknum == ATNR_CANCELLATION) cancellation(op); 1210 slow_player (op, hitter, dam);
1126 else if (attacknum == ATNR_DEPLETE) drain_stat(op); 1211 else if (attacknum == ATNR_PARALYZE)
1127 else if (attacknum == ATNR_BLIND && !QUERY_FLAG(op,FLAG_UNDEAD) && 1212 paralyze_player (op, hitter, dam);
1128 !QUERY_FLAG(op,FLAG_GENERATOR)) blind_player(op,hitter,dam); 1213 else if (attacknum == ATNR_FEAR)
1129 } 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 }
1130 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 */
1131 } 1223 }
1132 break; 1224 break;
1133 case ATNR_ACID: 1225 case ATNR_ACID:
1134 { 1226 {
1135 int flag=0; 1227 int flag = 0;
1136 1228
1137 /* 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
1138 * if your acid resistance is below 50%. */ 1230 * if your acid resistance is below 50%. */
1139 if (!op_on_battleground(op, NULL, NULL) && 1231 if (!op_on_battleground (op, NULL, NULL) && (op->resist[ATNR_ACID] < 50))
1140 (op->resist[ATNR_ACID] < 50)) 1232 {
1141 { 1233 object *tmp;
1142 object *tmp; 1234
1143 for(tmp=op->inv; tmp!=NULL; tmp=tmp->below) { 1235 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
1144 if(tmp->invisible) 1236 {
1145 continue; 1237 if (tmp->invisible)
1146 if(!QUERY_FLAG(tmp, FLAG_APPLIED) || 1238 continue;
1147 (tmp->resist[ATNR_ACID] >= 10)) 1239 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10))
1148 /* >= 10% acid res. on itmes will protect these */ 1240 /* >= 10% acid res. on itmes will protect these */
1149 continue; 1241 continue;
1150 if(!(tmp->material & M_IRON)) 1242 if (!(tmp->material & M_IRON))
1151 continue; 1243 continue;
1152 if(tmp->magic < -4) /* Let's stop at -5 */ 1244 if (tmp->magic < -4) /* Let's stop at -5 */
1153 continue; 1245 continue;
1154 if(tmp->type==RING || 1246 if (tmp->type == RING ||
1155 /* removed boots and gloves from exclusion list in 1247 /* removed boots and gloves from exclusion list in
1156 PR */ 1248 PR */
1157 tmp->type==GIRDLE || 1249 tmp->type == GIRDLE || tmp->type == AMULET || tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1158 tmp->type==AMULET ||
1159 tmp->type==WAND ||
1160 tmp->type==ROD ||
1161 tmp->type==HORN)
1162 continue; /* To avoid some strange effects */ 1250 continue; /* To avoid some strange effects */
1163 1251
1164 /* High damage acid has better chance of corroding 1252 /* High damage acid has better chance of corroding
1165 objects */ 1253 objects */
1166 if(rndm(0, dam+4) > 1254 if (rndm (0, dam + 4) > random_roll (0, 39, op, PREFER_HIGH) + 2 * tmp->magic)
1167 random_roll(0, 39, op, PREFER_HIGH)+2*tmp->magic) { 1255 {
1168 if(op->type == PLAYER) 1256 if (op->type == PLAYER)
1169 /* Make this more visible */ 1257 /* Make this more visible */
1170 new_draw_info_format(NDI_UNIQUE|NDI_RED,0, op, 1258 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op,
1171 "The %s's acid corrodes your %s!", 1259 "The %s's acid corrodes your %s!", query_name (hitter), query_name (tmp));
1172 query_name(hitter), query_name(tmp)); 1260 flag = 1;
1173 flag = 1; 1261 tmp->magic--;
1174 tmp->magic--; 1262 if (op->type == PLAYER)
1175 if(op->type == PLAYER) 1263 esrv_send_item (op, tmp);
1176 esrv_send_item(op, tmp); 1264 }
1177 } 1265 }
1178 } 1266 if (flag)
1179 if(flag)
1180 fix_player(op); /* Something was corroded */ 1267 fix_player (op); /* Something was corroded */
1181 } 1268 }
1182 } 1269 }
1183 break; 1270 break;
1184 case ATNR_DRAIN: 1271 case ATNR_DRAIN:
1185 { 1272 {
1186 /* rate is the proportion of exp drained. High rate means 1273 /* rate is the proportion of exp drained. High rate means
1187 * not much is drained, low rate means a lot is drained. 1274 * not much is drained, low rate means a lot is drained.
1188 */ 1275 */
1189 int rate; 1276 int rate;
1190 1277
1191 if(op->resist[ATNR_DRAIN] >= 0) 1278 if (op->resist[ATNR_DRAIN] >= 0)
1192 rate = 400 + op->resist[ATNR_DRAIN] * 3; 1279 rate = 400 + op->resist[ATNR_DRAIN] * 3;
1193 else 1280 else
1194 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); 1281 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]);
1195 1282
1196 if(op->stats.exp <= rate) { 1283 if (op->stats.exp <= rate)
1284 {
1197 if(op->type == GOLEM) 1285 if (op->type == GOLEM)
1198 dam = 999; /* Its force is "sucked" away. 8) */ 1286 dam = 999; /* Its force is "sucked" away. 8) */
1199 else 1287 else
1200 /* If we can't drain, lets try to do physical damage */ 1288 /* If we can't drain, lets try to do physical damage */
1201 dam = hit_player_attacktype(op, hitter, dam, ATNR_PHYSICAL, magic); 1289 dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic);
1202 } else { 1290 }
1291 else
1292 {
1203 /* Randomly give the hitter some hp */ 1293 /* Randomly give the hitter some hp */
1204 if(hitter->stats.hp<hitter->stats.maxhp && 1294 if (hitter->stats.hp < hitter->stats.maxhp &&
1205 (op->level > hitter->level) && 1295 (op->level > hitter->level) && random_roll (0, (op->level - hitter->level + 2), hitter, PREFER_HIGH) > 3)
1206 random_roll(0, (op->level-hitter->level+2), hitter, PREFER_HIGH)>3) 1296 hitter->stats.hp++;
1207 hitter->stats.hp++;
1208 1297
1209 /* Can't do drains on battleground spaces. 1298 /* Can't do drains on battleground spaces.
1210 * 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
1211 * 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,
1212 * nothing happens. 1301 * nothing happens.
1213 * 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
1214 * attacks, hence all the != PLAYER checks. 1303 * attacks, hence all the != PLAYER checks.
1215 */ 1304 */
1216 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))
1217 object *owner = get_owner(hitter); 1306 {
1307 object *owner = get_owner (hitter);
1218 1308
1219 if (owner && owner != hitter) { 1309 if (owner && owner != hitter)
1310 {
1220 if (op->type != PLAYER || owner->type != PLAYER) 1311 if (op->type != PLAYER || owner->type != PLAYER)
1221 change_exp(owner, op->stats.exp/(rate*2), 1312 change_exp (owner, op->stats.exp / (rate * 2),
1222 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 }
1223 } else if (op->type != PLAYER || hitter->type != PLAYER) { 1315 else if (op->type != PLAYER || hitter->type != PLAYER)
1316 {
1224 change_exp(hitter, op->stats.exp/(rate*2), 1317 change_exp (hitter, op->stats.exp / (rate * 2),
1225 hitter->chosen_skill?hitter->chosen_skill->skill:NULL, 0); 1318 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0);
1226 } 1319 }
1227 change_exp(op,-op->stats.exp/rate, NULL, 0); 1320 change_exp (op, -op->stats.exp / rate, NULL, 0);
1228 } 1321 }
1229 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
1230 * 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,
1231 * as the messages will say you missed 1324 * as the messages will say you missed
1232 */ 1325 */
1233 } 1326 }
1234 } 1327 }
1235 break; 1328 break;
1236 case ATNR_TURN_UNDEAD: 1329 case ATNR_TURN_UNDEAD:
1237 { 1330 {
1238 if (QUERY_FLAG(op,FLAG_UNDEAD)) { 1331 if (QUERY_FLAG (op, FLAG_UNDEAD))
1332 {
1239 object *owner = get_owner(hitter) == NULL ? hitter : get_owner(hitter); 1333 object *owner = get_owner (hitter) == NULL ? hitter : get_owner (hitter);
1240 object *god = find_god (determine_god (owner)); 1334 object *god = find_god (determine_god (owner));
1241 int div = 1; 1335 int div = 1;
1242 1336
1243 /* 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
1244 * at half strength */ 1338 * at half strength */
1245 if (! god || ! god->slaying || 1339 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL)
1246 strstr (god->slaying, undead_name) == NULL)
1247 div = 2; 1340 div = 2;
1248 /* Give a bonus if you resist turn undead */ 1341 /* Give a bonus if you resist turn undead */
1249 if (op->level * div < 1342 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100)))
1250 (turn_bonus[owner->stats.Wis]+owner->level + 1343 scare_creature (op, owner);
1251 (op->resist[ATNR_TURN_UNDEAD]/100))) 1344 }
1252 scare_creature(op, owner); 1345 else
1253 }
1254 else
1255 dam = 0; /* don't damage non undead - should we damage 1346 dam = 0; /* don't damage non undead - should we damage
1256 undead? */ 1347 undead? */
1348 }
1257 } break; 1349 break;
1258 case ATNR_DEATH: 1350 case ATNR_DEATH:
1259 deathstrike_player(op, hitter, &dam); 1351 deathstrike_player (op, hitter, &dam);
1260 break; 1352 break;
1261 case ATNR_CHAOS: 1353 case ATNR_CHAOS:
1262 LOG(llevError, 1354 LOG (llevError, "%s was hit by %s with non-specific chaos.\n", query_name (op), query_name (hitter));
1263 "%s was hit by %s with non-specific chaos.\n", 1355 dam = 0;
1264 query_name(op), 1356 break;
1265 query_name(hitter));
1266 dam = 0;
1267 break;
1268 case ATNR_COUNTERSPELL: 1357 case ATNR_COUNTERSPELL:
1269 LOG(llevError, 1358 LOG (llevError, "%s was hit by %s with counterspell attack.\n", query_name (op), query_name (hitter));
1270 "%s was hit by %s with counterspell attack.\n", 1359 dam = 0;
1271 query_name(op),
1272 query_name(hitter));
1273 dam = 0;
1274 /* This should never happen. Counterspell is handled 1360 /* This should never happen. Counterspell is handled
1275 * seperately and filtered out. If this does happen, 1361 * seperately and filtered out. If this does happen,
1276 * Counterspell has no effect on anything but spells, so it 1362 * Counterspell has no effect on anything but spells, so it
1277 * does no damage. */ 1363 * does no damage. */
1278 break; 1364 break;
1279 case ATNR_HOLYWORD: 1365 case ATNR_HOLYWORD:
1280 { 1366 {
1281 /* This has already been handled by hit_player, 1367 /* This has already been handled by hit_player,
1282 * no need to check twice -- DAMN */ 1368 * no need to check twice -- DAMN */
1283 1369
1284 object *owner = get_owner(hitter)==NULL?hitter:get_owner(hitter); 1370 object *owner = get_owner (hitter) == NULL ? hitter : get_owner (hitter);
1285 1371
1286 /* 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 */
1287 if((op->level+(op->resist[ATNR_HOLYWORD]/100)) < 1373 if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis])
1288 owner->level+turn_bonus[owner->stats.Wis])
1289 scare_creature(op, owner); 1374 scare_creature (op, owner);
1375 }
1290 } break; 1376 break;
1291 case ATNR_LIFE_STEALING: 1377 case ATNR_LIFE_STEALING:
1292 { 1378 {
1293 int new_hp; 1379 int new_hp;
1380
1294 /* this is replacement to drain for players, instead of taking 1381 /* this is replacement to drain for players, instead of taking
1295 * exp it takes hp. It is geared for players, probably not 1382 * exp it takes hp. It is geared for players, probably not
1296 * much use giving it to monsters 1383 * much use giving it to monsters
1297 * 1384 *
1298 * 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
1299 * damage it does do to the player. Given that, 1386 * damage it does do to the player. Given that,
1300 * 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
1301 * 1000). 1388 * 1000).
1302 */ 1389 */
1303 /* You can't steal life from something undead */ 1390 /* You can't steal life from something undead */
1304 if ((op->type == GOLEM) || (QUERY_FLAG(op, FLAG_UNDEAD))) return 0; 1391 if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD)))
1392 return 0;
1305 /* If drain protection is higher than life stealing, use that */ 1393 /* If drain protection is higher than life stealing, use that */
1306 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) 1394 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING])
1307 dam = (dam*(100 - op->resist[ATNR_DRAIN])) / 3000; 1395 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000;
1396 else
1308 else dam = (dam*(100 - op->resist[ATNR_LIFE_STEALING])) / 3000; 1397 dam = (dam * (100 - op->resist[ATNR_LIFE_STEALING])) / 3000;
1309 /* You die at -1 hp, not zero. */ 1398 /* You die at -1 hp, not zero. */
1310 if (dam > (op->stats.hp+1)) dam = op->stats.hp+1; 1399 if (dam > (op->stats.hp + 1))
1400 dam = op->stats.hp + 1;
1311 new_hp = hitter->stats.hp + dam; 1401 new_hp = hitter->stats.hp + dam;
1312 if (new_hp > hitter->stats.maxhp) new_hp = hitter->stats.maxhp; 1402 if (new_hp > hitter->stats.maxhp)
1313 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 }
1314 } 1407 }
1315 }
1316 return dam; 1408 return dam;
1317} 1409}
1318 1410
1319 1411
1320/* 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
1321 * allow script procedures to "kill" objects in a combat-like fashion. 1413 * allow script procedures to "kill" objects in a combat-like fashion.
1330 * 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,
1331 * 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
1332 * a bit - I think it should be functionally equivalant. 1424 * a bit - I think it should be functionally equivalant.
1333 * MSW 2002-07-17 1425 * MSW 2002-07-17
1334 */ 1426 */
1427int
1335int kill_object(object *op,int dam, object *hitter, int type) 1428kill_object (object *op, int dam, object *hitter, int type)
1336{ 1429{
1337 char buf[MAX_BUF]; 1430 char buf[MAX_BUF];
1338 const char *skill; 1431 const char *skill;
1339 int maxdam=0; 1432 int maxdam = 0;
1340 int battleg=0; /* true if op standing on battleground */ 1433 int battleg = 0; /* true if op standing on battleground */
1341 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 */
1342 object *owner=NULL; 1435 object *owner = NULL;
1343 object *skop=NULL; 1436 object *skop = NULL;
1344 1437
1345 if (op->stats.hp>=0) 1438 if (op->stats.hp >= 0)
1346 return -1; 1439 return -1;
1347 1440
1348 /* Lauwenmark: Handle for plugin death event */ 1441 if (INVOKE_OBJECT (KILL, op, ARG_OBJECT (hitter)))
1349 if (execute_event(op, EVENT_DEATH,hitter,NULL,NULL,SCRIPT_FIX_ALL)!=0) 1442 return 0;
1350 return 0;
1351 /* Lauwenmark: Handle for the global kill event */
1352 execute_global_event(EVENT_GKILL, op, hitter);
1353 1443
1354 /* 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
1355 * this creature. The function(s) that call us have already 1445 * this creature. The function(s) that call us have already
1356 * adjusted the creatures HP total, so that is negative. 1446 * adjusted the creatures HP total, so that is negative.
1357 */ 1447 */
1358 maxdam = dam + op->stats.hp + 1; 1448 maxdam = dam + op->stats.hp + 1;
1359 1449
1360 if(QUERY_FLAG(op,FLAG_BLOCKSVIEW)) 1450 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW))
1361 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 */
1362 1452
1363 if(op->type==DOOR) { 1453 if (op->type == DOOR)
1454 {
1364 op->speed = 0.1; 1455 op->speed = 0.1;
1365 update_ob_speed(op); 1456 update_ob_speed (op);
1366 op->speed_left= -0.05; 1457 op->speed_left = -0.05;
1367 return maxdam; 1458 return maxdam;
1368 } 1459 }
1369 if(QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) { 1460 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER)
1461 {
1370 remove_friendly_object(op); 1462 remove_friendly_object (op);
1371 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)
1372 op->owner->contr->ranges[range_golem] == op) { 1464 {
1373 op->owner->contr->ranges[range_golem]=NULL; 1465 op->owner->contr->ranges[range_golem] = NULL;
1374 op->owner->contr->golem_count=0; 1466 op->owner->contr->golem_count = 0;
1375 } 1467 }
1376 1468
1377 remove_ob(op); 1469 remove_ob (op);
1378 free_object(op); 1470 free_object (op);
1379 return maxdam; 1471 return maxdam;
1380 } 1472 }
1381 1473
1382 /* Now lets start dealing with experience we get for killing something */ 1474 /* Now lets start dealing with experience we get for killing something */
1383 1475
1384 owner=get_owner(hitter); 1476 owner = get_owner (hitter);
1385 if(owner==NULL) 1477 if (owner == NULL)
1386 owner=hitter; 1478 owner = hitter;
1387 1479
1388 /* is the victim (op) standing on battleground? */ 1480 /* is the victim (op) standing on battleground? */
1389 if (op_on_battleground(op, NULL, NULL)) battleg=1; 1481 if (op_on_battleground (op, NULL, NULL))
1390 1482 battleg = 1;
1483
1391 /* is this player killing?*/ 1484 /* is this player killing? */
1392 if (op->type == PLAYER && owner->type == PLAYER) pk=1; 1485 if (op->type == PLAYER && owner->type == PLAYER)
1486 pk = 1;
1393 1487
1394 /* Player killed something */ 1488 /* Player killed something */
1395 if(owner->type==PLAYER) { 1489 if (owner->type == PLAYER)
1490 {
1396 Log_Kill(owner->name, 1491 Log_Kill (owner->name,
1397 query_name(op),op->type, 1492 query_name (op), op->type, (owner != hitter) ? query_name (hitter) : NULL, (owner != hitter) ? hitter->type : 0);
1398 (owner!=hitter) ? query_name(hitter) : NULL,
1399 (owner!=hitter) ? hitter->type : 0);
1400 1493
1401 /* Log players killing other players - makes it easier to detect 1494 /* Log players killing other players - makes it easier to detect
1402 * and filter out malicious player killers - that is why the 1495 * and filter out malicious player killers - that is why the
1403 * ip address is included. 1496 * ip address is included.
1404 */ 1497 */
1405 if (op->type == PLAYER && !battleg) { 1498 if (op->type == PLAYER && !battleg)
1499 {
1406 time_t t=time(NULL); 1500 time_t t = time (NULL);
1407 struct tm *tmv; 1501 struct tm *tmv;
1408 char buf[256]; 1502 char buf[256];
1409 1503
1410 tmv = localtime(&t); 1504 tmv = localtime (&t);
1411 strftime(buf, 256,"%a %b %d %H:%M:%S %Y", tmv); 1505 strftime (buf, 256, "%a %b %d %H:%M:%S %Y", tmv);
1412 1506
1413 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));
1414 buf, owner->name, owner->contr->socket.host, query_name(op)); 1508 }
1415 }
1416 1509
1417 /* try to filter some things out - basically, if you are 1510 /* try to filter some things out - basically, if you are
1418 * killing a level 1 creature and your level 20, you 1511 * killing a level 1 creature and your level 20, you
1419 * probably don't want to see that. 1512 * probably don't want to see that.
1420 */ 1513 */
1421 if ( owner->level < op->level * 2|| op->stats.exp>1000) { 1514 if (owner->level < op->level * 2 || op->stats.exp > 1000)
1515 {
1422 if(owner!=hitter) { 1516 if (owner != hitter)
1423 new_draw_info_format(NDI_BLACK, 0, owner, 1517 {
1424 "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));
1425 query_name(hitter)); 1519 }
1426 } 1520 else
1427 else { 1521 {
1428 new_draw_info_format(NDI_BLACK, 0, owner, 1522 new_draw_info_format (NDI_BLACK, 0, owner, "You killed %s.", query_name (op));
1429 "You killed %s.",query_name(op)); 1523 }
1430 }
1431 /* Only play sounds for melee kills */ 1524 /* Only play sounds for melee kills */
1432 if (hitter->type == PLAYER) 1525 if (hitter->type == PLAYER)
1433 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);
1434 } 1527 }
1435 1528
1436 /* If a player kills another player, not on 1529 /* If a player kills another player, not on
1437 * battleground, the "killer" looses 1 luck. Since this is 1530 * battleground, the "killer" looses 1 luck. Since this is
1438 * not reversible, it's actually quite a pain IMHO. -AV 1531 * not reversible, it's actually quite a pain IMHO. -AV
1439 * 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
1440 * 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
1441 * with spells, pets, whatever, there was no penalty. 1534 * with spells, pets, whatever, there was no penalty.
1442 * Changed to make luck penalty configurable in settings. 1535 * Changed to make luck penalty configurable in settings.
1443 */ 1536 */
1444 if(op->type == PLAYER && owner != op && !battleg) 1537 if (op->type == PLAYER && owner != op && !battleg)
1445 change_luck(owner, -settings.pk_luck_penalty); 1538 change_luck (owner, -settings.pk_luck_penalty);
1446 1539
1447 /* This code below deals with finding the appropriate skill 1540 /* This code below deals with finding the appropriate skill
1448 * to credit exp to. This is a bit problematic - we should 1541 * to credit exp to. This is a bit problematic - we should
1449 * probably never really have to look at current_weapon->skill 1542 * probably never really have to look at current_weapon->skill
1450 */ 1543 */
1451 skill = NULL; 1544 skill = NULL;
1452 if (hitter->skill && hitter->type!=PLAYER) skill = hitter->skill; 1545 if (hitter->skill && hitter->type != PLAYER)
1546 skill = hitter->skill;
1453 else if (owner->chosen_skill) { 1547 else if (owner->chosen_skill)
1548 {
1454 skill = owner->chosen_skill->skill; 1549 skill = owner->chosen_skill->skill;
1455 skop = owner->chosen_skill; 1550 skop = owner->chosen_skill;
1456 } 1551 }
1457 else if (QUERY_FLAG(owner, FLAG_READY_WEAPON)) skill=owner->current_weapon->skill; 1552 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON))
1458 else 1553 skill = owner->current_weapon->skill;
1554 else
1459 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");
1460 1556
1461 /* 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
1462 * 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!
1463 */ 1559 */
1464 if ((!skop || skop->type != SKILL) && skill) { 1560 if ((!skop || skop->type != SKILL) && skill)
1465 int i; 1561 {
1562 int i;
1466 1563
1467 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 {
1468 if (owner->contr->last_skill_ob[i] && 1567 skop = owner->contr->last_skill_ob[i];
1469 !strcmp(owner->contr->last_skill_ob[i]->skill, skill)) { 1568 break;
1470 skop = owner->contr->last_skill_ob[i]; 1569 }
1471 break; 1570 }
1472 }
1473 }
1474 } /* Was it a player that hit somethign */ 1571 } /* Was it a player that hit somethign */
1475 else { 1572 else
1476 skill = NULL;
1477 } 1573 {
1574 skill = NULL;
1575 }
1478 1576
1479 /* Pet (or spell) killed something. */ 1577 /* Pet (or spell) killed something. */
1480 if(owner != hitter ) { 1578 if (owner != hitter)
1579 {
1481 (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,
1482 query_name(op),query_name(hitter), battleg? " (duel)":"", pk? " (pk)":""); 1581 query_name (op), query_name (hitter), battleg ? " (duel)" : "", pk ? " (pk)" : "");
1582 }
1583 else
1483 } 1584 {
1484 else {
1485 (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,
1486 (QUERY_FLAG(hitter, FLAG_MONSTER)) || hitter->type == PLAYER ? 1586 (QUERY_FLAG (hitter, FLAG_MONSTER)) || hitter->type == PLAYER ?
1487 " in hand to hand combat":"", battleg? " (duel)":"", pk? " (pk)":""); 1587 " in hand to hand combat" : "", battleg ? " (duel)" : "", pk ? " (pk)" : "");
1488 } 1588 }
1489 /* 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)
1490 if (!skop) skop = hitter->chosen_skill; 1591 skop = hitter->chosen_skill;
1491 if (!skill && skop) skill=skop->skill; 1592 if (!skill && skop)
1593 skill = skop->skill;
1492 1594
1493 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);
1494 1596
1495 1597
1496 /* If you didn't kill yourself, and your not the wizard */ 1598 /* If you didn't kill yourself, and your not the wizard */
1497 if(owner!=op && !QUERY_FLAG(op, FLAG_WAS_WIZ)) { 1599 if (owner != op && !QUERY_FLAG (op, FLAG_WAS_WIZ))
1498 int exp; 1600 {
1601 int exp;
1499 1602
1500 /* Really don't give much experience for killing other players */ 1603 /* Really don't give much experience for killing other players */
1501 // schmorp: temporary? reduce the amount of exp gained for pking enourmously 1604 // schmorp: temporary? reduce the amount of exp gained for pking enourmously
1502 if (op->type==PLAYER) { 1605 if (op->type == PLAYER)
1503 if (battleg) {
1504 new_draw_info(NDI_UNIQUE, 0,owner, "Your foe has fallen!");
1505 new_draw_info(NDI_UNIQUE, 0,owner, "VICTORY!!!");
1506 }
1507 else
1508 exp = op->stats.exp / 1000;
1509 } 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 }
1510 else 1612 else
1613 exp = op->stats.exp / 1000;
1614 }
1615 else
1511 exp = calc_skill_exp(owner, op, skop); 1616 exp = calc_skill_exp (owner, op, skop);
1512 1617
1513 /* if op is standing on "battleground" (arena), no way to gain 1618 /* if op is standing on "battleground" (arena), no way to gain
1514 * exp by killing him 1619 * exp by killing him
1515 */ 1620 */
1516 if (battleg) exp = 0; 1621 if (battleg)
1622 exp = 0;
1517 1623
1518 /* 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
1519 * sense to just divide everything by two for no reason. 1625 * sense to just divide everything by two for no reason.
1520 */ 1626 */
1521 1627
1522 if (!settings.simple_exp) 1628 if (!settings.simple_exp)
1523 exp=exp/2; 1629 exp = exp / 2;
1524 1630
1525 if(owner->type!=PLAYER || owner->contr->party==NULL) { 1631 if (owner->type != PLAYER || owner->contr->party == NULL)
1632 {
1526 change_exp(owner,exp, skill, 0); 1633 change_exp (owner, exp, skill, 0);
1527 } 1634 }
1528 else { 1635 else
1636 {
1529 int shares=0,count=0; 1637 int shares = 0, count = 0;
1530 1638
1531 player *pl; 1639 player *pl;
1532 1640
1533 partylist *party=owner->contr->party; 1641 partylist *party = owner->contr->party;
1642
1534#ifdef PARTY_KILL_LOG 1643#ifdef PARTY_KILL_LOG
1535 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);
1536#endif 1645#endif
1537 for(pl=first_player;pl!=NULL;pl=pl->next) { 1646 for (pl = first_player; pl != NULL; pl = pl->next)
1647 {
1538 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))
1539 count++; 1649 {
1650 count++;
1540 shares+=(pl->ob->level+4); 1651 shares += (pl->ob->level + 4);
1541 } 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);
1542 } 1693 }
1543 if(count==1 || shares>exp)
1544 change_exp(owner,exp, skill, SK_EXP_TOTAL);
1545 else {
1546 int share=exp/shares,given=0,nexp;
1547 for(pl=first_player;pl!=NULL;pl=pl->next) {
1548 if(party && pl->ob->contr->party==party && on_same_map(pl->ob, owner)) {
1549 nexp=(pl->ob->level+4)*share;
1550 change_exp(pl->ob,nexp, skill, SK_EXP_TOTAL);
1551 given+=nexp;
1552 }
1553 }
1554 exp-=given;
1555 /* give any remainder to the player */
1556 change_exp(owner,exp, skill, SK_EXP_ADD_SKILL);
1557 }
1558 } /* else part of a party */
1559
1560 } /* end if person didn't kill himself */
1561
1562 if(op->type!=PLAYER) {
1563 if(QUERY_FLAG(op,FLAG_FRIENDLY)) {
1564 object *owner1 = get_owner(op);
1565
1566 if(owner1!= NULL && owner1->type == PLAYER) {
1567 play_sound_player_only(owner1->contr, SOUND_PET_IS_KILLED,0,0);
1568 /* Maybe we should include the owner that killed this, maybe not */
1569 new_draw_info_format(NDI_UNIQUE, 0,owner1,"Your pet, the %s, is killed by %s.",
1570 op->name,hitter->name);
1571 }
1572 remove_friendly_object(op);
1573 }
1574 remove_ob(op);
1575 free_object(op);
1576 }
1577 /* Player has been killed! */ 1694 /* Player has been killed! */
1578 else { 1695 else
1696 {
1579 if(owner->type==PLAYER) { 1697 if (owner->type == PLAYER)
1698 {
1580 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);
1581 } 1700 }
1582 else { 1701 else
1702 {
1583 strncpy(op->contr->killer,hitter->name,BIG_NAME); 1703 strncpy (op->contr->killer, hitter->name, BIG_NAME);
1584 op->contr->killer[BIG_NAME-1]='\0'; 1704 op->contr->killer[BIG_NAME - 1] = '\0';
1585 } 1705 }
1586 } 1706 }
1587 /* 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
1588 * continues in the calling function. 1708 * continues in the calling function.
1589 */ 1709 */
1590 return maxdam; 1710 return maxdam;
1591} 1711}
1592 1712
1593/* 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
1594 * Returns 0 this is not friendly fire 1714 * Returns 0 this is not friendly fire
1595 */ 1715 */
1596 1716
1717int
1597int friendly_fire(object *op, object *hitter){ 1718friendly_fire (object *op, object *hitter)
1719{
1598 object *owner; 1720 object *owner;
1599 int friendlyfire; 1721 int friendlyfire;
1600
1601 if (hitter->head) hitter=hitter->head;
1602 1722
1723 if (hitter->head)
1724 hitter = hitter->head;
1725
1603 friendlyfire = 0; 1726 friendlyfire = 0;
1604 1727
1605 if(op->type == PLAYER) { 1728 if (op->type == PLAYER)
1729 {
1606 if (op_on_battleground (hitter, 0, 0)) 1730 if (op_on_battleground (hitter, 0, 0))
1607 return 0; 1731 return 0;
1608 1732
1609 if(hitter->type == PLAYER && hitter->contr->peaceful == 1) 1733 if (hitter->type == PLAYER && hitter->contr->peaceful == 1)
1610 return 1; 1734 return 1;
1611 1735
1612 if((owner = get_owner(hitter))!=NULL) { 1736 if ((owner = get_owner (hitter)) != NULL)
1737 {
1613 if(owner->type == PLAYER && owner->contr->peaceful == 1) 1738 if (owner->type == PLAYER && owner->contr->peaceful == 1)
1614 friendlyfire = 2; 1739 friendlyfire = 2;
1615 } 1740 }
1616 1741
1617 if (hitter->type == SPELL || hitter->type == POISONING || 1742 if (hitter->type == SPELL || hitter->type == POISONING || hitter->type == DISEASE || hitter->type == RUNE)
1618 hitter->type == DISEASE || hitter->type == RUNE)
1619 friendlyfire = 0; 1743 friendlyfire = 0;
1620 } 1744 }
1621 return friendlyfire; 1745 return friendlyfire;
1622} 1746}
1623 1747
1624 1748
1625/* 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.
1626 * 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
1631 */ 1755 */
1632 1756
1633 /* Oct 95 - altered the following slightly for MULTIPLE_GODS hack 1757 /* Oct 95 - altered the following slightly for MULTIPLE_GODS hack
1634 * which needs new attacktype AT_HOLYWORD to work . b.t. */ 1758 * which needs new attacktype AT_HOLYWORD to work . b.t. */
1635 1759
1760int
1636int 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{
1637 int maxdam=0, ndam=0, attacktype=1, magic=(type & AT_MAGIC); 1763 int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC);
1638 int maxattacktype, attacknum; 1764 int maxattacktype, attacknum;
1639 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? */
1640 int simple_attack; 1766 int simple_attack;
1641 tag_t op_tag, hitter_tag; 1767 tag_t op_tag, hitter_tag;
1642 int rtn_kill = 0; 1768 int rtn_kill = 0;
1643 int friendlyfire; 1769 int friendlyfire;
1644 1770
1645 if (get_attack_mode (&op, &hitter, &simple_attack)) 1771 if (get_attack_mode (&op, &hitter, &simple_attack))
1646 return 0; 1772 return 0;
1647 1773
1648 /* 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 */
1649 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))
1650 return 0; 1776 return 0;
1651 1777
1652#ifdef PROHIBIT_PLAYERKILL 1778#ifdef PROHIBIT_PLAYERKILL
1653 if (op->type == PLAYER) { 1779 if (op->type == PLAYER)
1780 {
1654 object *owner = get_owner (hitter); 1781 object *owner = get_owner (hitter);
1782
1783 if (!owner)
1655 if (!owner) owner = hitter; 1784 owner = hitter;
1656 if (owner->type == PLAYER
1657 && (!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)
1658 && 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))
1659 return 0; 1823 return 0;
1824 break;
1660 } 1825 }
1826 }
1827
1828 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0)
1661 } 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);
1662#endif 1839#endif
1663 1840
1664 op_tag = op->count;
1665 hitter_tag = hitter->count;
1666
1667 if (body_attack) {
1668 /* slow and paralyze must hit the head. But we don't want to just
1669 * return - we still need to process other attacks the spell still
1670 * might have. So just remove the paralyze and slow attacktypes,
1671 * and keep on processing if we have other attacktypes.
1672 * return if only magic or nothing is left - under normal code
1673 * we don't attack with pure magic if there is another attacktype.
1674 * Only do processing if the initial attacktype includes one of those
1675 * attack so we don't cancel out things like magic bullet.
1676 */
1677 if (type & (AT_PARALYZE | AT_SLOW)) {
1678 type &= ~(AT_PARALYZE | AT_SLOW);
1679 if (!type || type==AT_MAGIC) return 0;
1680 }
1681 }
1682
1683 if ( ! simple_attack && op->type == DOOR) {
1684 object *tmp;
1685 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
1686 if (tmp->type == RUNE || tmp->type == TRAP) {
1687 spring_trap (tmp, hitter);
1688 if (was_destroyed (hitter, hitter_tag)
1689 || was_destroyed (op, op_tag)
1690 || abort_attack (op, hitter, simple_attack))
1691 return 0;
1692 break;
1693 }
1694 }
1695
1696 if ( ! QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) {
1697 /* FIXME: If a player is killed by a rune in a door, the
1698 * was_destroyed() check above doesn't return, and might get here.
1699 */
1700 LOG (llevDebug, "victim (arch %s, name %s) already dead in "
1701 "hit_player()\n", op->arch->name, op->name);
1702 return 0;
1703 }
1704
1705#ifdef ATTACK_DEBUG
1706 LOG(llevDebug,"hit player: attacktype %d, dam %d\n", type, dam);
1707#endif
1708
1709 if (magic) { 1841 if (magic)
1842 {
1710 /* basically: dam = dam*(100-op->resist[attacknum])/100; 1843 /* basically: dam = dam*(100-op->resist[attacknum])/100;
1711 * 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 */
1712 dam = dam*(100-op->resist[ATNR_MAGIC]); 1845 dam = dam * (100 - op->resist[ATNR_MAGIC]);
1713 if (dam >= 100) 1846 if (dam >= 100)
1714 dam /= 100; 1847 dam /= 100;
1715 else 1848 else
1716 dam = (dam > (rndm(0, 99))) ? 1 : 0; 1849 dam = (dam > (rndm (0, 99))) ? 1 : 0;
1717 } 1850 }
1718 1851
1719 /* 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
1720 * 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
1721 */ 1854 */
1722 if(type & AT_CHAOS){ 1855 if (type & AT_CHAOS)
1856 {
1723 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 */
1724 update_object(op,UP_OBJ_FACE); 1858 update_object (op, UP_OBJ_FACE);
1725 type &= ~AT_CHAOS; 1859 type &= ~AT_CHAOS;
1726 } 1860 }
1727 1861
1728 /* Holyword is really an attacktype modifier (like magic is). If 1862 /* Holyword is really an attacktype modifier (like magic is). If
1729 * 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
1730 * a proper match, otherwise no damage. 1864 * a proper match, otherwise no damage.
1731 */ 1865 */
1732 if (type & AT_HOLYWORD) { 1866 if (type & AT_HOLYWORD)
1867 {
1733 object *god; 1868 object *god;
1869
1734 if ((!hitter->slaying || 1870 if ((!hitter->slaying ||
1735 (!(op->race && strstr(hitter->slaying,op->race)) && 1871 (!(op->race && strstr (hitter->slaying, op->race)) &&
1736 !(op->name && strstr(hitter->slaying,op->name)))) && 1872 !(op->name && strstr (hitter->slaying, op->name)))) &&
1737 (!QUERY_FLAG(op,FLAG_UNDEAD) || 1873 (!QUERY_FLAG (op, FLAG_UNDEAD) ||
1738 (hitter->title != NULL 1874 (hitter->title != NULL
1739 && (god = find_god(determine_god(hitter))) != NULL 1875 && (god = find_god (determine_god (hitter))) != NULL && god->race != NULL && strstr (god->race, undead_name) != NULL)))
1740 && god->race != NULL
1741 && strstr(god->race,undead_name) != NULL)))
1742 return 0; 1876 return 0;
1743 } 1877 }
1744 1878
1745 maxattacktype = type; /* initialize this to something */ 1879 maxattacktype = type; /* initialize this to something */
1746 for (attacknum=0; attacknum<NROFATTACKS; attacknum++, attacktype=1<<attacknum) { 1880 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum)
1881 {
1747 /* 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
1748 * attack types. As such, skip it over. However, if magic is 1883 * attack types. As such, skip it over. However, if magic is
1749 * the only attacktype in the group, then still attack with it 1884 * the only attacktype in the group, then still attack with it
1750 */ 1885 */
1751 if ((attacktype==AT_MAGIC) && (type & ~AT_MAGIC)) continue; 1886 if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC))
1887 continue;
1752 1888
1753 /* 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.
1754 * hit_player_attacktype only figures out the damage, doesn't inflict 1890 * hit_player_attacktype only figures out the damage, doesn't inflict
1755 * it. It will do the appropriate action for attacktypes with 1891 * it. It will do the appropriate action for attacktypes with
1756 * effects (slow, paralization, etc. 1892 * effects (slow, paralization, etc.
1757 */ 1893 */
1758 if (type & attacktype) { 1894 if (type & attacktype)
1895 {
1759 ndam=hit_player_attacktype(op,hitter,dam,attacknum,magic); 1896 ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic);
1760 /* the >= causes us to prefer messages from special attacks, if 1897 /* the >= causes us to prefer messages from special attacks, if
1761 * the damage is equal. 1898 * the damage is equal.
1762 */ 1899 */
1763 if (ndam >= maxdam) { 1900 if (ndam >= maxdam)
1901 {
1764 maxdam = ndam; 1902 maxdam = ndam;
1765 maxattacktype = 1<<attacknum; 1903 maxattacktype = 1 << attacknum;
1904 }
1905 }
1766 } 1906 }
1767 } 1907
1768 }
1769
1770 /* 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
1771 * 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
1772 * doing damage - otherwise, the +1 in the code below will make 1910 * doing damage - otherwise, the +1 in the code below will make
1773 * an attack do damage before when it otherwise didn't 1911 * an attack do damage before when it otherwise didn't
1774 */ 1912 */
1775 friendlyfire = friendly_fire(op, hitter); 1913 friendlyfire = friendly_fire (op, hitter);
1776 if (friendlyfire && maxdam){ 1914 if (friendlyfire && maxdam)
1915 {
1777 maxdam = ((dam * settings.set_friendly_fire) / 100); 1916 maxdam = ((dam * settings.set_friendly_fire) / 100);
1778#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)
1779 maxdam++; 1943 maxdam++;
1944 }
1945
1946#ifdef ATTACK_DEBUG
1947 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam);
1780#endif 1948#endif
1781
1782#ifdef ATTACK_DEBUG
1783 LOG(llevDebug,"Friendly fire (type:%d setting: %d%) did %d damage dropped to %d\n",
1784 friendlyfire, settings.set_friendly_fire, dam, maxdam);
1785#endif
1786 }
1787 1949
1788 if (!full_hit) {
1789 archetype *at;
1790 int area;
1791 int remainder;
1792
1793 area = 0;
1794 for(at = op->arch; at != NULL; at = at->more)
1795 area++;
1796 assert(area > 0);
1797
1798 /* basically: maxdam /= area; we try to "simulate" a float
1799 value-effect */
1800 remainder = 100*(maxdam%area)/area;
1801 maxdam /= area;
1802 if (RANDOM()%100 < remainder)
1803 maxdam++;
1804 }
1805
1806#ifdef ATTACK_DEBUG
1807 LOG(llevDebug,"Attacktype %d did %d damage\n", type, maxdam);
1808#endif
1809
1810 if(get_owner(hitter)) 1950 if (get_owner (hitter))
1811 op->enemy=hitter->owner; 1951 op->enemy = hitter->owner;
1812 else if (QUERY_FLAG(hitter,FLAG_ALIVE)) 1952 else if (QUERY_FLAG (hitter, FLAG_ALIVE))
1813 op->enemy=hitter; 1953 op->enemy = hitter;
1814 1954
1815 if(QUERY_FLAG(op,FLAG_UNAGGRESSIVE) && op->type != PLAYER) { 1955 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER)
1956 {
1816 /* The unaggressives look after themselves 8) */ 1957 /* The unaggressives look after themselves 8) */
1817 CLEAR_FLAG(op, FLAG_UNAGGRESSIVE); 1958 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE);
1818 npc_call_help(op); 1959 npc_call_help (op);
1819 } 1960 }
1820 1961
1821 if (magic && did_make_save(op, op->level, 0)) 1962 if (magic && did_make_save (op, op->level, 0))
1822 maxdam=maxdam/2; 1963 maxdam = maxdam / 2;
1823 1964
1824 attack_message(maxdam, maxattacktype, op, hitter); 1965 attack_message (maxdam, maxattacktype, op, hitter);
1825 1966
1826 op->stats.hp-=maxdam; 1967 op->stats.hp -= maxdam;
1827 1968
1828 /* Eneq(@csd.uu.se): Check to see if monster runs away. */ 1969 /* Eneq(@csd.uu.se): Check to see if monster runs away. */
1829 if ((op->stats.hp>=0) && 1970 if ((op->stats.hp >= 0) &&
1830 (QUERY_FLAG(op, FLAG_MONSTER) || op->type == PLAYER) && 1971 (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) &&
1831 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))
1832 (float)op->stats.maxhp)) { 1973 {
1833 1974
1834 if (QUERY_FLAG(op, FLAG_MONSTER)) 1975 if (QUERY_FLAG (op, FLAG_MONSTER))
1835 SET_FLAG(op, FLAG_RUN_AWAY); 1976 SET_FLAG (op, FLAG_RUN_AWAY);
1836 else 1977 else
1837 scare_creature(op, hitter); 1978 scare_creature (op, hitter);
1838 } 1979 }
1839 1980
1840 if(QUERY_FLAG(op,FLAG_TEAR_DOWN)) { 1981 if (QUERY_FLAG (op, FLAG_TEAR_DOWN))
1982 {
1841 if (maxdam) 1983 if (maxdam)
1842 tear_down_wall(op); 1984 tear_down_wall (op);
1843 return maxdam; /* nothing more to do for wall */ 1985 return maxdam; /* nothing more to do for wall */
1844 } 1986 }
1845 1987
1846 /* See if the creature has been killed */ 1988 /* See if the creature has been killed */
1847 rtn_kill = kill_object(op, maxdam, hitter, type); 1989 rtn_kill = kill_object (op, maxdam, hitter, type);
1848 if (rtn_kill != -1) 1990 if (rtn_kill != -1)
1849 return rtn_kill; 1991 return rtn_kill;
1850 1992
1851 1993
1852 /* 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
1853 * that before if the player was immune to ghosthit, the monster 1995 * that before if the player was immune to ghosthit, the monster
1854 * remained - that is no longer the case. 1996 * remained - that is no longer the case.
1855 */ 1997 */
1856 if(QUERY_FLAG(hitter, FLAG_ONE_HIT)) { 1998 if (QUERY_FLAG (hitter, FLAG_ONE_HIT))
1999 {
1857 if(QUERY_FLAG(hitter,FLAG_FRIENDLY)) 2000 if (QUERY_FLAG (hitter, FLAG_FRIENDLY))
1858 remove_friendly_object(hitter); 2001 remove_friendly_object (hitter);
1859 remove_ob(hitter); 2002 remove_ob (hitter);
1860 free_object(hitter); 2003 free_object (hitter);
1861 } 2004 }
1862 /* Lets handle creatures that are splitting now */ 2005 /* Lets handle creatures that are splitting now */
1863 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))
1864 int i; 2007 {
2008 int i;
1865 int friendly = QUERY_FLAG(op,FLAG_FRIENDLY); 2009 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY);
1866 int unaggressive = QUERY_FLAG(op, FLAG_UNAGGRESSIVE); 2010 int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE);
1867 object *owner = get_owner(op); 2011 object *owner = get_owner (op);
1868 2012
1869 if(!op->other_arch) { 2013 if (!op->other_arch)
2014 {
1870 LOG(llevError,"SPLITTING without other_arch error.\n"); 2015 LOG (llevError, "SPLITTING without other_arch error.\n");
1871 return maxdam; 2016 return maxdam;
1872 } 2017 }
1873 remove_ob(op); 2018 remove_ob (op);
1874 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 */
1875 object *tmp=arch_to_object(op->other_arch); 2021 object *tmp = arch_to_object (op->other_arch);
1876 int j; 2022 int j;
1877 2023
1878 tmp->stats.hp=op->stats.hp; 2024 tmp->stats.hp = op->stats.hp;
1879 if (friendly) { 2025 if (friendly)
2026 {
1880 SET_FLAG(tmp, FLAG_FRIENDLY); 2027 SET_FLAG (tmp, FLAG_FRIENDLY);
1881 add_friendly_object(tmp); 2028 add_friendly_object (tmp);
1882 tmp->attack_movement = PETMOVE; 2029 tmp->attack_movement = PETMOVE;
1883 if (owner!=NULL) 2030 if (owner != NULL)
1884 set_owner(tmp,owner); 2031 set_owner (tmp, owner);
1885 } 2032 }
1886 if (unaggressive) 2033 if (unaggressive)
1887 SET_FLAG(tmp, FLAG_UNAGGRESSIVE); 2034 SET_FLAG (tmp, FLAG_UNAGGRESSIVE);
1888 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);
1889 if (j==-1) /* No spot to put this monster */ 2036 if (j == -1) /* No spot to put this monster */
1890 free_object(tmp); 2037 free_object (tmp);
1891 else { 2038 else
2039 {
1892 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];
1893 insert_ob_in_map(tmp,op->map,NULL,0); 2041 insert_ob_in_map (tmp, op->map, NULL, 0);
1894 } 2042 }
1895 } 2043 }
1896 if(friendly) 2044 if (friendly)
1897 remove_friendly_object(op); 2045 remove_friendly_object (op);
1898 free_object(op); 2046 free_object (op);
1899 } 2047 }
1900 else if(type & AT_DRAIN && hitter->type==GRIMREAPER&&hitter->value++>10) { 2048 else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10)
2049 {
1901 remove_ob(hitter); 2050 remove_ob (hitter);
1902 free_object(hitter); 2051 free_object (hitter);
1903 } 2052 }
1904 return maxdam; 2053 return maxdam;
1905} 2054}
1906 2055
1907 2056
2057void
1908void poison_player(object *op, object *hitter, int dam) 2058poison_player (object *op, object *hitter, int dam)
1909{ 2059{
1910 archetype *at = find_archetype("poisoning"); 2060 archetype *at = find_archetype ("poisoning");
1911 object *tmp=present_arch_in_ob(at,op); 2061 object *tmp = present_arch_in_ob (at, op);
1912 2062
1913 if(tmp==NULL) { 2063 if (tmp == NULL)
2064 {
1914 if((tmp=arch_to_object(at))==NULL) 2065 if ((tmp = arch_to_object (at)) == NULL)
1915 LOG(llevError,"Failed to clone arch poisoning.\n"); 2066 LOG (llevError, "Failed to clone arch poisoning.\n");
1916 else { 2067 else
2068 {
1917 tmp = insert_ob_in_ob(tmp,op); 2069 tmp = insert_ob_in_ob (tmp, op);
1918 /* peterm: give poisoning some teeth. It should 2070 /* peterm: give poisoning some teeth. It should
1919 * be able to kill things better than it does: 2071 * be able to kill things better than it does:
1920 * damage should be dependent something--I choose to 2072 * damage should be dependent something--I choose to
1921 * do this: if it's a monster, the damage from the 2073 * do this: if it's a monster, the damage from the
1922 * poisoning goes as the level of the monster/2. 2074 * poisoning goes as the level of the monster/2.
1923 * If anything else, goes as damage. 2075 * If anything else, goes as damage.
1924 */ 2076 */
1925 2077
1926 if(QUERY_FLAG(hitter,FLAG_ALIVE)) 2078 if (QUERY_FLAG (hitter, FLAG_ALIVE))
1927 tmp->stats.dam += hitter->level/2; 2079 tmp->stats.dam += hitter->level / 2;
1928 else 2080 else
1929 tmp->stats.dam = dam; 2081 tmp->stats.dam = dam;
1930 2082
1931 copy_owner(tmp,hitter); /* so we get credit for poisoning kills */ 2083 copy_owner (tmp, hitter); /* so we get credit for poisoning kills */
1932 if(hitter->skill && hitter->skill != tmp->skill) { 2084 if (hitter->skill && hitter->skill != tmp->skill)
1933 if (tmp->skill) free_string(tmp->skill); 2085 {
1934 tmp->skill = add_refcount(hitter->skill); 2086 tmp->skill = hitter->skill;
1935 } 2087 }
1936 2088
1937 tmp->stats.food+=dam; /* more damage, longer poisoning */ 2089 tmp->stats.food += dam; /* more damage, longer poisoning */
1938 2090
1939 if(op->type==PLAYER) { 2091 if (op->type == PLAYER)
2092 {
1940 /* player looses stats, maximum is -10 of each */ 2093 /* player looses stats, maximum is -10 of each */
1941 tmp->stats.Con= MAX(-(dam/4+1), -10); 2094 tmp->stats.Con = MAX (-(dam / 4 + 1), -10);
1942 tmp->stats.Str= MAX(-(dam/3+2), -10); 2095 tmp->stats.Str = MAX (-(dam / 3 + 2), -10);
1943 tmp->stats.Dex= MAX(-(dam/6+1), -10); 2096 tmp->stats.Dex = MAX (-(dam / 6 + 1), -10);
1944 tmp->stats.Int= MAX(-dam/7, -10); 2097 tmp->stats.Int = MAX (-dam / 7, -10);
1945 SET_FLAG(tmp,FLAG_APPLIED); 2098 SET_FLAG (tmp, FLAG_APPLIED);
1946 fix_player(op); 2099 fix_player (op);
1947 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.");
1948 } 2101 }
1949 if (hitter->type == PLAYER) 2102 if (hitter->type == PLAYER)
1950 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);
1951 op->name);
1952 else if (get_owner(hitter) != NULL && hitter->owner->type == PLAYER) 2104 else if (get_owner (hitter) != NULL && hitter->owner->type == PLAYER)
1953 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);
1954 "Your %s poisons %s.", hitter->name, op->name); 2106 }
1955 }
1956 tmp->speed_left=0; 2107 tmp->speed_left = 0;
1957 } 2108 }
1958 else 2109 else
1959 tmp->stats.food++; 2110 tmp->stats.food++;
1960} 2111}
1961 2112
2113void
1962void slow_player(object *op,object *hitter,int dam) 2114slow_player (object *op, object *hitter, int dam)
2115{
1963{ archetype *at = find_archetype("slowness"); 2116 archetype *at = find_archetype ("slowness");
1964 object *tmp; 2117 object *tmp;
2118
1965 if(at == NULL) { 2119 if (at == NULL)
2120 {
1966 LOG(llevError,"Can't find slowness archetype.\n"); 2121 LOG (llevError, "Can't find slowness archetype.\n");
1967 } 2122 }
1968 if((tmp=present_arch_in_ob(at,op)) == NULL) { 2123 if ((tmp = present_arch_in_ob (at, op)) == NULL)
2124 {
1969 tmp = arch_to_object(at); 2125 tmp = arch_to_object (at);
1970 tmp = insert_ob_in_ob(tmp,op); 2126 tmp = insert_ob_in_ob (tmp, op);
1971 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 }
1972 } else 2129 else
1973 tmp->stats.food++; 2130 tmp->stats.food++;
1974 SET_FLAG(tmp, FLAG_APPLIED); 2131 SET_FLAG (tmp, FLAG_APPLIED);
1975 tmp->speed_left=0; 2132 tmp->speed_left = 0;
1976 fix_player(op); 2133 fix_player (op);
1977} 2134}
1978 2135
2136void
1979void confuse_player(object *op, object *hitter, int dam) 2137confuse_player (object *op, object *hitter, int dam)
1980{ 2138{
1981 object *tmp; 2139 object *tmp;
1982 int maxduration; 2140 int maxduration;
1983 2141
1984 tmp = present_in_ob_by_name(FORCE,"confusion", op); 2142 tmp = present_in_ob_by_name (FORCE, "confusion", op);
1985 if(!tmp) { 2143 if (!tmp)
1986 tmp = get_archetype(FORCE_NAME);
1987 tmp = insert_ob_in_ob(tmp,op);
1988 }
1989 2144 {
2145 tmp = get_archetype (FORCE_NAME);
2146 tmp = insert_ob_in_ob (tmp, op);
2147 }
2148
1990 /* Duration added per hit and max. duration of confusion both depend 2149 /* Duration added per hit and max. duration of confusion both depend
1991 * on the player's resistance 2150 * on the player's resistance
1992 */ 2151 */
1993 tmp->speed = 0.05; 2152 tmp->speed = 0.05;
1994 tmp->subtype = FORCE_CONFUSION; 2153 tmp->subtype = FORCE_CONFUSION;
1995 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);
1996 if (tmp->name) free_string(tmp->name);
1997 tmp->name = add_string("confusion"); 2155 tmp->name = "confusion";
1998 maxduration = MAX(2, 30*(100-op->resist[ATNR_CONFUSION])/100); 2156 maxduration = MAX (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100);
1999 if( tmp->duration > maxduration) 2157 if (tmp->duration > maxduration)
2000 tmp->duration = maxduration; 2158 tmp->duration = maxduration;
2001 2159
2002 if(op->type == PLAYER && !QUERY_FLAG(op,FLAG_CONFUSED)) 2160 if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED))
2003 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!");
2004 SET_FLAG(op, FLAG_CONFUSED); 2162 SET_FLAG (op, FLAG_CONFUSED);
2005} 2163}
2006 2164
2165void
2007void blind_player(object *op, object *hitter, int dam) 2166blind_player (object *op, object *hitter, int dam)
2008{ 2167{
2009 object *tmp,*owner; 2168 object *tmp, *owner;
2010 2169
2011 /* 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 */
2012 if (op->resist[ATNR_BLIND]==100) return; 2171 if (op->resist[ATNR_BLIND] == 100)
2172 return;
2013 2173
2014 tmp = present_in_ob(BLINDNESS,op); 2174 tmp = present_in_ob (BLINDNESS, op);
2015 if(!tmp) { 2175 if (!tmp)
2176 {
2016 tmp = get_archetype("blindness"); 2177 tmp = get_archetype ("blindness");
2017 SET_FLAG(tmp, FLAG_BLIND); 2178 SET_FLAG (tmp, FLAG_BLIND);
2018 SET_FLAG(tmp, FLAG_APPLIED); 2179 SET_FLAG (tmp, FLAG_APPLIED);
2019 /* 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.
2020 * speed is a float anyways. 2181 * speed is a float anyways.
2021 */ 2182 */
2022 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;
2023 2184
2024 tmp = insert_ob_in_ob(tmp,op); 2185 tmp = insert_ob_in_ob (tmp, op);
2025 change_abil(op,tmp); /* Mostly to display any messages */ 2186 change_abil (op, tmp); /* Mostly to display any messages */
2026 fix_player(op); /* This takes care of some other stuff */ 2187 fix_player (op); /* This takes care of some other stuff */
2027 2188
2189 if (hitter->owner)
2028 if(hitter->owner) owner = get_owner(hitter); 2190 owner = get_owner (hitter);
2191 else
2029 else owner = hitter; 2192 owner = hitter;
2030 2193
2031 new_draw_info_format(NDI_UNIQUE,0,owner, 2194 new_draw_info_format (NDI_UNIQUE, 0, owner, "Your attack blinds %s!", query_name (op));
2032 "Your attack blinds %s!",query_name(op));
2033 } 2195 }
2034 tmp->stats.food += dam; 2196 tmp->stats.food += dam;
2035 if(tmp->stats.food > 10) tmp->stats.food = 10; 2197 if (tmp->stats.food > 10)
2198 tmp->stats.food = 10;
2036} 2199}
2037 2200
2201void
2038void paralyze_player(object *op, object *hitter, int dam) 2202paralyze_player (object *op, object *hitter, int dam)
2039{ 2203{
2040 float effect,max; 2204 float effect, max;
2205
2041 /* object *tmp; */ 2206 /* object *tmp; */
2042 2207
2043 /* This is strange stuff... someone knows for what this is 2208 /* This is strange stuff... someone knows for what this is
2044 * written? Well, i think this can and should be removed 2209 * written? Well, i think this can and should be removed
2045 */ 2210 */
2046 2211
2047 /* 2212 /*
2048 if((tmp=present(PARAIMAGE,op->map,op->x,op->y))==NULL) { 2213 if((tmp=present(PARAIMAGE,op->map,op->x,op->y))==NULL) {
2049 tmp=clone_arch(PARAIMAGE); 2214 tmp=clone_arch(PARAIMAGE);
2050 tmp->x=op->x,tmp->y=op->y; 2215 tmp->x=op->x,tmp->y=op->y;
2051 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);
2052 } 2217 }
2053 */ 2218 */
2054 2219
2055 /* 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 */
2056 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;
2057 2222
2058 if (effect==0) return; 2223 if (effect == 0)
2224 return;
2059 2225
2060 op->speed_left-=FABS(op->speed)*effect; 2226 op->speed_left -= FABS (op->speed) * effect;
2061 /* tmp->stats.food+=(signed short) effect/op->speed; */ 2227 /* tmp->stats.food+=(signed short) effect/op->speed; */
2062 2228
2063 /* max number of ticks to be affected for. */ 2229 /* max number of ticks to be affected for. */
2064 max = (100 - op->resist[ATNR_PARALYZE])/ 2; 2230 max = (100 - op->resist[ATNR_PARALYZE]) / 2;
2065 if (op->speed_left< -(FABS(op->speed)*max)) 2231 if (op->speed_left < -(FABS (op->speed) * max))
2066 op->speed_left = (float) -(FABS(op->speed)*max); 2232 op->speed_left = (float) -(FABS (op->speed) * max);
2067 2233
2068/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */ 2234/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */
2069} 2235}
2070 2236
2071 2237
2072/* Attempts to kill 'op'. hitter is the attack object, dam is 2238/* Attempts to kill 'op'. hitter is the attack object, dam is
2073 * the computed damaged. 2239 * the computed damaged.
2074 */ 2240 */
2241void
2075void deathstrike_player(object *op, object *hitter, int *dam) 2242deathstrike_player (object *op, object *hitter, int *dam)
2076{ 2243{
2077 /* The intention of a death attack is to kill outright things 2244 /* The intention of a death attack is to kill outright things
2078 ** 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
2079 ** things somewhat weaker than the caster, and no chance of 2246 ** things somewhat weaker than the caster, and no chance of
2080 ** killing something equal or stronger than the attacker. 2247 ** killing something equal or stronger than the attacker.
2081 ** Also, if a deathstrike attack has a slaying, any monster 2248 ** Also, if a deathstrike attack has a slaying, any monster
2082 ** 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
2083 ** field of the deathstriking object */ 2250 ** field of the deathstriking object */
2084 2251
2085 int atk_lev, def_lev, kill_lev; 2252 int atk_lev, def_lev, kill_lev;
2086 2253
2087 if(hitter->slaying) 2254 if (hitter->slaying)
2088 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))))
2089 (op->race&&strstr(hitter->slaying,op->race)))) return; 2256 return;
2090 2257
2091 def_lev = op->level; 2258 def_lev = op->level;
2092 if (def_lev < 1) { 2259 if (def_lev < 1)
2260 {
2093 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);
2094 op->arch->name, op->name);
2095 def_lev = 1; 2262 def_lev = 1;
2096 } 2263 }
2097 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;
2098 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n", 2265 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n",
2099 atk_lev, def_lev); */ 2266 atk_lev, def_lev); */
2100 2267
2101 if(atk_lev >= def_lev ){ 2268 if (atk_lev >= def_lev)
2269 {
2102 kill_lev = random_roll(0, atk_lev-1, hitter, PREFER_HIGH); 2270 kill_lev = random_roll (0, atk_lev - 1, hitter, PREFER_HIGH);
2103 2271
2104 /* 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
2105 * defener level is important - if level 52 character has very little 2273 * defener level is important - if level 52 character has very little
2106 * chance of killing a level 50 monster. This should probably be 2274 * chance of killing a level 50 monster. This should probably be
2107 * redone. 2275 * redone.
2108 */ 2276 */
2109 if(kill_lev >= def_lev) { 2277 if (kill_lev >= def_lev)
2278 {
2110 *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 */
2111 /* I think this doesn't really do much. Because of 2280 /* I think this doesn't really do much. Because of
2112 * integer rounding, this only makes any difference if the 2281 * integer rounding, this only makes any difference if the
2113 * attack level is double the defender level. 2282 * attack level is double the defender level.
2114 */ 2283 */
2115 *dam *= kill_lev / def_lev; 2284 *dam *= kill_lev / def_lev;
2116 } 2285 }
2117 } else { 2286 }
2287 else
2288 {
2118 *dam = 0; /* no harm done */ 2289 *dam = 0; /* no harm done */
2119 } 2290 }
2120} 2291}
2121 2292
2122/* thrown_item_effect() - handles any special effects of thrown 2293/* thrown_item_effect() - handles any special effects of thrown
2123 * items (like attacking living creatures--a potion thrown at a 2294 * items (like attacking living creatures--a potion thrown at a
2124 * monster). 2295 * monster).
2125 */ 2296 */
2297static void
2126static void thrown_item_effect (object *hitter, object *victim) 2298thrown_item_effect (object *hitter, object *victim)
2127{ 2299{
2128 if(!QUERY_FLAG(hitter,FLAG_ALIVE)) { 2300 if (!QUERY_FLAG (hitter, FLAG_ALIVE))
2301 {
2129 /* 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
2130 * easier for expansion. 2303 * easier for expansion.
2131 */ 2304 */
2132 switch (hitter->type) { 2305 switch (hitter->type)
2306 {
2133 case POTION: 2307 case POTION:
2134 /* should player get a save throw instead of checking magic protection? */ 2308 /* should player get a save throw instead of checking magic protection? */
2135 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))
2136 &&(victim->resist[ATNR_MAGIC]<60)) (void) apply_potion(victim,hitter); 2310 (void) apply_potion (victim, hitter);
2137 break; 2311 break;
2138 2312
2139 case POISON: /* poison drinks */ 2313 case POISON: /* poison drinks */
2140 /* As with potions, should monster get a save? */ 2314 /* As with potions, should monster get a save? */
2141 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))
2142 &&(victim->resist[ATNR_POISON]<60)) apply_poison(victim,hitter); 2316 apply_poison (victim, hitter);
2143 break; 2317 break;
2144 2318
2145 /* Removed case statements that did nothing. 2319 /* Removed case statements that did nothing.
2146 * 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,
2147 * so we don't handle it here. 2321 * so we don't handle it here.
2148 * Containers should perhaps break open, but that code was disabled. 2322 * Containers should perhaps break open, but that code was disabled.
2149 */ 2323 */
2150 } 2324 }
2151 } 2325 }
2152} 2326}
2153 2327
2154/* adj_attackroll() - adjustments to attacks by various conditions */ 2328/* adj_attackroll() - adjustments to attacks by various conditions */
2155 2329
2330int
2156int adj_attackroll (object *hitter, object *target) { 2331adj_attackroll (object *hitter, object *target)
2332{
2157 object *attacker = hitter; 2333 object *attacker = hitter;
2158 int adjust=0; 2334 int adjust = 0;
2159 2335
2160 /* safety */ 2336 /* safety */
2161 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 {
2162 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");
2163 "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))
2164 return 0; 2355 return 0;
2165 }
2166 2356
2167 /* aimed missiles use the owning object's sight */
2168 if(is_aimed_missile(hitter)) {
2169 if ((attacker = get_owner(hitter))==NULL) attacker = hitter;
2170 /* A player who saves but hasn't quit still could have objects
2171 * owned by him - need to handle that case to avoid crashes.
2172 */
2173 if (QUERY_FLAG(attacker, FLAG_REMOVED)) attacker = hitter;
2174 }
2175 else if(!QUERY_FLAG(hitter,FLAG_ALIVE))
2176 return 0;
2177
2178 /* determine the condtions under which we make an attack. 2357 /* determine the condtions under which we make an attack.
2179 * Add more cases, as the need occurs. */ 2358 * Add more cases, as the need occurs. */
2180 2359
2181 if(!can_see_enemy(attacker,target)) { 2360 if (!can_see_enemy (attacker, target))
2361 {
2182 /* target is unseen */ 2362 /* target is unseen */
2183 if(target->invisible || QUERY_FLAG(attacker,FLAG_BLIND)) 2363 if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND))
2184 adjust -= 10; 2364 adjust -= 10;
2185 /* 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). */
2186 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))
2187 adjust -= target->map->darkness; 2367 adjust -= target->map->darkness;
2188 } 2368 }
2189 2369
2190 if(QUERY_FLAG(attacker,FLAG_SCARED)) 2370 if (QUERY_FLAG (attacker, FLAG_SCARED))
2191 adjust -= 3; 2371 adjust -= 3;
2192 2372
2193 if(QUERY_FLAG(target,FLAG_UNAGGRESSIVE)) 2373 if (QUERY_FLAG (target, FLAG_UNAGGRESSIVE))
2194 adjust += 1; 2374 adjust += 1;
2195 2375
2196 if(QUERY_FLAG(target,FLAG_SCARED)) 2376 if (QUERY_FLAG (target, FLAG_SCARED))
2197 adjust += 1; 2377 adjust += 1;
2198 2378
2199 if(QUERY_FLAG(attacker,FLAG_CONFUSED)) 2379 if (QUERY_FLAG (attacker, FLAG_CONFUSED))
2200 adjust -= 3; 2380 adjust -= 3;
2201 2381
2202 /* if we attack at a different 'altitude' its harder */ 2382 /* if we attack at a different 'altitude' its harder */
2203 if((attacker->move_type & target->move_type)==0) 2383 if ((attacker->move_type & target->move_type) == 0)
2204 adjust -= 2; 2384 adjust -= 2;
2205 2385
2206#if 0 2386#if 0
2207 /* slower attacks are less likely to succeed. We should use a 2387 /* slower attacks are less likely to succeed. We should use a
2208 * comparison between attacker/target speeds BUT, players have 2388 * comparison between attacker/target speeds BUT, players have
2209 * 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
2210 * disadantage for the monsters! Too bad, because missiles which 2390 * disadantage for the monsters! Too bad, because missiles which
2211 * 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.
2212 */ 2392 */
2213 if(hitter->speed<target->speed) 2393 if (hitter->speed < target->speed)
2214 adjust += ((float) hitter->speed-target->speed); 2394 adjust += ((float) hitter->speed - target->speed);
2215#endif 2395#endif
2216 2396
2217#if 0 2397#if 0
2218 LOG(llevDebug,"adj_attackroll() returns %d (%d)\n",adjust,attacker->count); 2398 LOG (llevDebug, "adj_attackroll() returns %d (%d)\n", adjust, attacker->count);
2219#endif 2399#endif
2220 2400
2221 return adjust; 2401 return adjust;
2222} 2402}
2223 2403
2224 2404
2225/* determine if the object is an 'aimed' missile */ 2405/* determine if the object is an 'aimed' missile */
2406int
2226int is_aimed_missile ( object *op) { 2407is_aimed_missile (object *op)
2408{
2227 2409
2228 /* 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
2229 * ones so that figuring out the logic is at least possible. 2411 * ones so that figuring out the logic is at least possible.
2230 */ 2412 */
2231 if (op && (op->move_type & MOVE_FLYING)) { 2413 if (op && (op->move_type & MOVE_FLYING))
2414 {
2232 if (op->type==ARROW || op->type==THROWN_OBJ) 2415 if (op->type == ARROW || op->type == THROWN_OBJ)
2233 return 1; 2416 return 1;
2234 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))
2235 op->subtype == SP_EXPLOSION))
2236 return 1; 2418 return 1;
2237 } 2419 }
2238 return 0; 2420 return 0;
2239} 2421}
2240

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines