1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <assert.h> |
25 | #include <assert.h> |
26 | #include <global.h> |
26 | #include <global.h> |
… | |
… | |
28 | #include <material.h> |
28 | #include <material.h> |
29 | #include <skills.h> |
29 | #include <skills.h> |
30 | #include <sounds.h> |
30 | #include <sounds.h> |
31 | #include <sproto.h> |
31 | #include <sproto.h> |
32 | |
32 | |
33 | typedef struct att_msg_str |
|
|
34 | { |
|
|
35 | char *msg1; |
|
|
36 | char *msg2; |
|
|
37 | } att_msg; |
|
|
38 | |
|
|
39 | /*#define ATTACK_DEBUG*/ |
33 | /*#define ATTACK_DEBUG*/ |
40 | |
34 | |
41 | /* did_make_save_item just checks to make sure the item actually |
35 | /* did_make_save_item just checks to make sure the item actually |
42 | * made its saving throw based on the tables. It does not take |
36 | * made its saving throw based on the tables. It does not take |
43 | * any further action (like destroying the item). |
37 | * any further action (like destroying the item). |
44 | */ |
38 | */ |
45 | static int |
39 | static int |
46 | did_make_save_item (object *op, int type, object *originator) |
40 | did_make_save_item (object *op, uint32_t type, object *originator) |
47 | { |
41 | { |
48 | int i, roll, saves = 0, attacks = 0, number; |
42 | int saves = 0, attacks = 0; |
49 | materialtype_t *mt; |
43 | materialtype_t *mt = op->material; |
50 | |
44 | |
51 | if (!op->materialname) |
45 | // destroying objects without material has many bad effects |
52 | { |
46 | if (mt == MATERIAL_NULL) |
53 | for (mt = materialt; mt; mt = mt->next) |
|
|
54 | if (op->materials & mt->material) |
|
|
55 | break; |
|
|
56 | } |
|
|
57 | else |
|
|
58 | mt = name_to_material (op->materialname); |
|
|
59 | |
|
|
60 | if (!mt) |
|
|
61 | return TRUE; |
47 | return 1; |
62 | |
48 | |
63 | roll = rndm (1, 20); |
49 | int roll = rndm (1, 20); |
64 | |
50 | |
65 | /* the attacktypes have no meaning for object saves |
51 | /* the attacktypes have no meaning for object saves |
66 | * If the type is only magic, don't adjust type - basically, if |
52 | * If the type is only magic, don't adjust type - basically, if |
67 | * pure magic is hitting an object, it should save. However, if it |
53 | * pure magic is hitting an object, it should save. However, if it |
68 | * is magic teamed with something else, then strip out the |
54 | * is magic teamed with something else, then strip out the |
69 | * magic type, and instead let the fire, cold, or whatever component |
55 | * magic type, and instead let the fire, cold, or whatever component |
70 | * destroy the item. Otherwise, you get the case of poisoncloud |
56 | * destroy the item. Otherwise, you get the case of poisoncloud |
71 | * destroying objects because it has magic attacktype. |
57 | * destroying objects because it has magic attacktype. |
72 | */ |
58 | */ |
73 | if (type != AT_MAGIC) |
59 | if (type != AT_MAGIC) |
74 | type &= ~(AT_CONFUSION | AT_DRAIN | AT_GHOSTHIT | AT_POISON | AT_SLOW | |
60 | type &= ~(AT_CONFUSION | AT_DRAIN | AT_GHOSTHIT | AT_POISON | AT_SLOW | |
75 | AT_PARALYZE | AT_TURN_UNDEAD | AT_FEAR | AT_DEPLETE | AT_DEATH | |
61 | AT_PARALYZE | AT_TURN_UNDEAD | AT_FEAR | AT_DEPLETE | AT_DEATH | |
76 | AT_COUNTERSPELL | AT_HOLYWORD | AT_BLIND | AT_LIFE_STEALING | AT_MAGIC); |
62 | AT_COUNTERSPELL | AT_HOLYWORD | AT_BLIND | AT_LIFE_STEALING | AT_MAGIC); |
77 | |
63 | |
|
|
64 | |
78 | if (type == 0) return TRUE; |
65 | if (type == 0) return TRUE; |
79 | |
66 | |
80 | if (roll == 20) return TRUE; |
67 | if (roll == 20) return TRUE; |
81 | if (roll == 1) return FALSE; |
68 | if (roll == 1) return FALSE; |
82 | |
69 | |
83 | for (number = 0; number < NROFATTACKS; number++) |
70 | for_all_bits_sparse_32 (type, number) |
84 | { |
71 | { |
85 | i = 1 << number; |
|
|
86 | |
|
|
87 | if (!(i & type)) |
|
|
88 | continue; |
|
|
89 | |
|
|
90 | attacks++; |
72 | attacks++; |
|
|
73 | |
91 | if (op->resist[number] == 100) |
74 | if (op->resist[number] == 100) |
92 | saves++; |
75 | saves++; |
93 | else if (roll >= mt->save[number] - op->magic - op->resist[number] / 100) |
76 | else if (roll >= mt->save[number] - op->magic - op->resist[number] / 100) |
94 | saves++; |
77 | saves++; |
95 | else if ((20 - mt->save[number]) / 3 > originator->stats.dam) |
78 | else if ((20 - mt->save[number]) / 3 > originator->stats.dam) |
… | |
… | |
112 | cancellation (object *op) |
95 | cancellation (object *op) |
113 | { |
96 | { |
114 | if (op->invisible) |
97 | if (op->invisible) |
115 | return; |
98 | return; |
116 | |
99 | |
117 | if (QUERY_FLAG (op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ) |
100 | if (op->flag [FLAG_ALIVE] || op->type == CONTAINER || op->type == THROWN_OBJ) |
118 | { |
101 | { |
119 | /* Recurse through the inventory */ |
102 | /* Recurse through the inventory */ |
120 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
103 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
121 | if (!did_make_save_item (tmp, AT_CANCELLATION, op)) |
104 | if (!did_make_save_item (tmp, AT_CANCELLATION, op)) |
122 | cancellation (tmp); |
105 | cancellation (tmp); |
123 | } |
106 | } |
124 | else if (FABS (op->magic) <= rndm (0, 5)) |
107 | else if (fabs (op->magic) <= rndm (0, 5)) |
125 | { |
108 | { |
126 | /* Nullify this object. This code could probably be more complete */ |
109 | /* Nullify this object. This code could probably be more complete */ |
127 | /* in what abilities it should cancel */ |
110 | /* in what abilities it should cancel */ |
128 | op->magic = 0; |
111 | op->magic = 0; |
129 | |
112 | |
130 | CLEAR_FLAG (op, FLAG_DAMNED); |
113 | op->clr_flag (FLAG_DAMNED); |
131 | CLEAR_FLAG (op, FLAG_CURSED); |
114 | op->clr_flag (FLAG_CURSED); |
132 | CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); |
115 | op->clr_flag (FLAG_KNOWN_MAGICAL); |
133 | CLEAR_FLAG (op, FLAG_KNOWN_CURSED); |
116 | op->clr_flag (FLAG_KNOWN_CURSED); |
134 | |
117 | |
135 | if (object *pl = op->visible_to ()) |
118 | if (object *pl = op->visible_to ()) |
136 | esrv_update_item (UPD_FLAGS, pl, op); |
119 | esrv_update_item (UPD_FLAGS, pl, op); |
137 | } |
120 | } |
138 | } |
121 | } |
… | |
… | |
142 | * calling cancellation, etc.) |
125 | * calling cancellation, etc.) |
143 | */ |
126 | */ |
144 | void |
127 | void |
145 | save_throw_object (object *op, int type, object *originator) |
128 | save_throw_object (object *op, int type, object *originator) |
146 | { |
129 | { |
|
|
130 | op = op->head_ (); |
|
|
131 | |
147 | if (!did_make_save_item (op, type, originator)) |
132 | if (!did_make_save_item (op, type, originator)) |
148 | { |
133 | { |
149 | object *env = op->env; |
134 | object *env = op->env; |
150 | int x = op->x, y = op->y; |
135 | int x = op->x, y = op->y; |
151 | maptile *m = op->map; |
136 | maptile *m = op->map; |
… | |
… | |
160 | * object with +/- glow_radius and an "other_arch" to change to. |
145 | * object with +/- glow_radius and an "other_arch" to change to. |
161 | * (and please note that we cant fail our save and reach this |
146 | * (and please note that we cant fail our save and reach this |
162 | * function if the object doesnt contain a material that can burn. |
147 | * function if the object doesnt contain a material that can burn. |
163 | * So forget lighting magical swords on fire with this!) -b.t. |
148 | * So forget lighting magical swords on fire with this!) -b.t. |
164 | */ |
149 | */ |
165 | if (type & (AT_FIRE | AT_ELECTRICITY) |
150 | if (type & (AT_FIRE | AT_ELECTRICITY)) |
166 | && (QUERY_FLAG (op, FLAG_IS_LIGHTABLE) |
|
|
167 | || op->type == LAMP |
|
|
168 | || op->type == TORCH |
|
|
169 | )) |
151 | { |
170 | { |
152 | // seems LAMPs and TORCHes are always IS_LIGHTABLE? |
171 | switch (op->type) |
153 | if (op->type == LAMP || op->type == TORCH) |
172 | { |
154 | { |
173 | case LAMP: |
|
|
174 | case TORCH: |
|
|
175 | // turn on a lamp |
|
|
176 | apply_lamp (op, true); |
155 | apply_lamp (op, true); // turn on a lamp |
177 | break; |
156 | return; |
178 | |
|
|
179 | default: |
|
|
180 | // for instance icecubes: |
|
|
181 | if (op->other_arch) |
|
|
182 | { |
|
|
183 | const char *arch = op->other_arch->archname; |
|
|
184 | |
|
|
185 | if (op->decrease ()) |
|
|
186 | fix_stopped_item (op, m, originator); |
|
|
187 | |
|
|
188 | if ((op = archetype::get (arch))) |
|
|
189 | { |
|
|
190 | if (env) |
|
|
191 | env->insert (op); |
|
|
192 | else |
|
|
193 | m->insert (op, x, y, originator); |
|
|
194 | } |
|
|
195 | } |
|
|
196 | } |
157 | } |
|
|
158 | else if (op->flag [FLAG_IS_LIGHTABLE]) |
|
|
159 | { |
|
|
160 | if (op->other_arch) |
|
|
161 | { |
|
|
162 | const char *arch = op->other_arch->archname; |
|
|
163 | |
|
|
164 | if (op->decrease ()) |
|
|
165 | fix_stopped_item (op, m, originator); |
|
|
166 | |
|
|
167 | if ((op = archetype::get (arch))) |
|
|
168 | { |
|
|
169 | if (env) |
|
|
170 | env->insert (op); |
|
|
171 | else |
|
|
172 | m->insert (op, x, y, originator); |
|
|
173 | } |
|
|
174 | } |
|
|
175 | |
197 | return; |
176 | return; |
|
|
177 | } |
198 | } |
178 | } |
199 | |
179 | |
200 | if (type & AT_CANCELLATION) |
180 | if (type & AT_CANCELLATION) |
201 | { /* Cancellation. */ |
181 | { /* Cancellation. */ |
202 | cancellation (op); |
182 | cancellation (op); |
203 | fix_stopped_item (op, m, originator); |
183 | fix_stopped_item (op, m, originator); |
|
|
184 | |
204 | return; |
185 | return; |
205 | } |
|
|
206 | |
|
|
207 | if (op->nrof > 1) |
|
|
208 | { |
|
|
209 | if (op->decrease (rndm (0, op->nrof - 1))) |
|
|
210 | fix_stopped_item (op, m, originator); |
|
|
211 | } |
|
|
212 | else |
|
|
213 | { |
|
|
214 | // drop everything to the ground, if possible |
|
|
215 | op->insert_at (originator); |
|
|
216 | op->drop_and_destroy (); |
|
|
217 | } |
186 | } |
218 | |
187 | |
219 | if (type & (AT_FIRE | AT_ELECTRICITY)) |
188 | if (type & (AT_FIRE | AT_ELECTRICITY)) |
220 | if (env) |
189 | if (env) |
221 | { |
190 | { |
222 | op = archetype::get (shstr_burnout); |
191 | object *op = archetype::get (shstr_burnout); |
223 | op->x = env->x, op->y = env->y; |
192 | op->x = env->x, op->y = env->y; |
224 | env->insert (op); |
193 | env->insert (op); |
225 | } |
194 | } |
226 | else |
195 | else |
227 | replace_insert_ob_in_map (shstr_burnout, originator); |
196 | replace_insert_ob_in_map (shstr_burnout, originator); |
228 | |
197 | |
|
|
198 | if (op->nrof > 1) |
|
|
199 | { |
|
|
200 | if (op->decrease (rndm (0, op->nrof - 1))) |
|
|
201 | fix_stopped_item (op, m, originator); |
|
|
202 | } |
|
|
203 | else |
|
|
204 | { |
|
|
205 | // drop everything to the ground, if possible |
|
|
206 | op->insert_at (originator); |
|
|
207 | op->drop_and_destroy (); |
|
|
208 | } |
|
|
209 | |
229 | return; |
210 | return; |
230 | } |
211 | } |
231 | |
212 | |
232 | /* The value of 50 is arbitrary. */ |
213 | /* The value of 50 is arbitrary. */ |
233 | if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && rndm (2)) |
214 | if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !op->flag [FLAG_NO_PICK] && rndm (2)) |
234 | { |
215 | { |
235 | archetype *at = archetype::find (shstr_icecube); |
216 | archetype *at = archetype::find (shstr_icecube); |
236 | |
217 | |
237 | if (at == NULL) |
218 | if (at == NULL) |
238 | return; |
219 | return; |
… | |
… | |
242 | return; |
223 | return; |
243 | |
224 | |
244 | object *tmp = present_arch (at, op->map, op->x, op->y); |
225 | object *tmp = present_arch (at, op->map, op->x, op->y); |
245 | if (!tmp) |
226 | if (!tmp) |
246 | { |
227 | { |
247 | tmp = arch_to_object (at); |
228 | tmp = at->instance (); |
248 | tmp->x = op->x, tmp->y = op->y; |
229 | tmp->x = op->x, tmp->y = op->y; |
249 | /* This was in the old (pre new movement code) - |
230 | /* This was in the old (pre new movement code) - |
250 | * icecubes have slow_move set to 1 - don't want |
231 | * icecubes have slow_move set to 1 - don't want |
251 | * that for ones we create. |
232 | * that for ones we create. |
252 | */ |
233 | */ |
… | |
… | |
265 | * type is the attacktype of the object. |
246 | * type is the attacktype of the object. |
266 | * full_hit is set if monster area does not matter. |
247 | * full_hit is set if monster area does not matter. |
267 | * returns 1 if it hits something, 0 otherwise. |
248 | * returns 1 if it hits something, 0 otherwise. |
268 | */ |
249 | */ |
269 | int |
250 | int |
270 | hit_map (object *op, int dir, int type, int full_hit) |
251 | hit_map (object *op, int dir, uint32_t type, int full_hit) |
271 | { |
252 | { |
272 | maptile *map; |
|
|
273 | sint16 x, y; |
253 | sint16 x, y; |
274 | int retflag = 0; /* added this flag.. will return 1 if it hits a monster */ |
254 | int retflag = 0; /* added this flag.. will return 1 if it hits a monster */ |
275 | |
255 | |
276 | if (QUERY_FLAG (op, FLAG_FREED)) |
256 | if (op->flag [FLAG_FREED]) |
277 | { |
257 | { |
278 | LOG (llevError, "BUG: hit_map(): free object\n"); |
258 | LOG (llevError, "BUG: hit_map(): free object\n"); |
279 | return 0; |
259 | return 0; |
280 | } |
260 | } |
281 | |
261 | |
282 | if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL) |
262 | if (op->flag [FLAG_REMOVED] || op->env != NULL) |
283 | { |
263 | { |
284 | LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->archname, &op->name); |
264 | LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->archname, &op->name); |
285 | return 0; |
265 | return 0; |
286 | } |
266 | } |
287 | |
267 | |
… | |
… | |
351 | * This is one of the few cases where on_same_map should not be used. |
331 | * This is one of the few cases where on_same_map should not be used. |
352 | */ |
332 | */ |
353 | if (tmp->map != pos.m || tmp->x != pos.x || tmp->y != pos.y) |
333 | if (tmp->map != pos.m || tmp->x != pos.x || tmp->y != pos.y) |
354 | continue; |
334 | continue; |
355 | |
335 | |
356 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
336 | if (tmp->flag [FLAG_ALIVE]) |
357 | { |
337 | { |
358 | hit_player (tmp, op->stats.dam, op, type, full_hit); |
338 | hit_player (tmp, op->stats.dam, op, type, full_hit); |
359 | retflag |= 1; |
339 | retflag |= 1; |
360 | |
340 | |
361 | if (op->destroyed ()) |
341 | if (op->destroyed ()) |
… | |
… | |
365 | * NO_PASS set, it is also immune - you can't destroy walls. Note |
345 | * NO_PASS set, it is also immune - you can't destroy walls. Note |
366 | * that weak walls have is_alive set, which prevent objects from |
346 | * that weak walls have is_alive set, which prevent objects from |
367 | * passing over/through them. We don't care what type of movement |
347 | * passing over/through them. We don't care what type of movement |
368 | * the wall blocks - if it blocks any type of movement, can't be |
348 | * the wall blocks - if it blocks any type of movement, can't be |
369 | * destroyed right now. |
349 | * destroyed right now. |
|
|
350 | * Without the material check the server completely fails to work, |
|
|
351 | * objects detsroy themselves, floors get destroyed etc. etc. |
370 | */ |
352 | */ |
371 | else if (tmp->materialname && op->stats.dam > 0 && !tmp->move_block) |
353 | else if (op->stats.dam > 0 && !tmp->move_block && tmp->material != MATERIAL_NULL) |
372 | { |
354 | { |
373 | save_throw_object (tmp, type, op); |
355 | save_throw_object (tmp, type, op); |
374 | |
356 | |
375 | if (op->destroyed ()) |
357 | if (op->destroyed ()) |
376 | break; |
358 | break; |
377 | } |
359 | } |
378 | } |
360 | } |
379 | |
361 | |
380 | return 0; |
362 | return retflag; |
381 | } |
363 | } |
382 | |
364 | |
383 | void |
365 | static void |
384 | attack_message (int dam, int type, object *op, object *hitter) |
366 | attack_message (int dam, int type, object *op, object *hitter) |
385 | { |
367 | { |
386 | char buf[MAX_BUF], buf1[MAX_BUF], buf2[MAX_BUF]; |
368 | char buf[MAX_BUF], buf1[MAX_BUF], buf2[MAX_BUF]; |
387 | int i, found = 0; |
369 | int i, found = 0; |
388 | maptile *map; |
370 | maptile *map; |
… | |
… | |
534 | { |
516 | { |
535 | int mtype; |
517 | int mtype; |
536 | |
518 | |
537 | switch (hitter->current_weapon->weapontype) |
519 | switch (hitter->current_weapon->weapontype) |
538 | { |
520 | { |
539 | case WEAP_HIT: |
521 | case WEAP_HIT: mtype = ATM_BASIC; break; |
540 | mtype = ATM_BASIC; |
522 | case WEAP_SLASH: mtype = ATM_SLASH; break; |
541 | break; |
523 | case WEAP_PIERCE: mtype = ATM_PIERCE; break; |
542 | case WEAP_SLASH: |
524 | case WEAP_CLEAVE: mtype = ATM_CLEAVE; break; |
543 | mtype = ATM_SLASH; |
525 | case WEAP_SLICE: mtype = ATM_SLICE; break; |
544 | break; |
526 | case WEAP_STAB: mtype = ATM_STAB; break; |
545 | case WEAP_PIERCE: |
527 | case WEAP_WHIP: mtype = ATM_WHIP; break; |
546 | mtype = ATM_PIERCE; |
528 | case WEAP_CRUSH: mtype = ATM_CRUSH; break; |
547 | break; |
529 | case WEAP_BLUD: mtype = ATM_BLUD; break; |
548 | case WEAP_CLEAVE: |
530 | default: mtype = ATM_BASIC; break; |
549 | mtype = ATM_CLEAVE; |
|
|
550 | break; |
|
|
551 | case WEAP_SLICE: |
|
|
552 | mtype = ATM_SLICE; |
|
|
553 | break; |
|
|
554 | case WEAP_STAB: |
|
|
555 | mtype = ATM_STAB; |
|
|
556 | break; |
|
|
557 | case WEAP_WHIP: |
|
|
558 | mtype = ATM_WHIP; |
|
|
559 | break; |
|
|
560 | case WEAP_CRUSH: |
|
|
561 | mtype = ATM_CRUSH; |
|
|
562 | break; |
|
|
563 | case WEAP_BLUD: |
|
|
564 | mtype = ATM_BLUD; |
|
|
565 | break; |
|
|
566 | default: |
|
|
567 | mtype = ATM_BASIC; |
|
|
568 | break; |
|
|
569 | } |
531 | } |
570 | |
532 | |
571 | for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++) |
533 | for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++) |
572 | if (dam < attack_mess[mtype][i].level || attack_mess[mtype][i + 1].level == -1) |
534 | if (dam < attack_mess[mtype][i].level || attack_mess[mtype][i + 1].level == -1) |
573 | { |
535 | { |
… | |
… | |
679 | } |
641 | } |
680 | |
642 | |
681 | static int |
643 | static int |
682 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
644 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
683 | { |
645 | { |
684 | if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) |
646 | if ((*target)->flag [FLAG_FREED] || (*hitter)->flag [FLAG_FREED]) |
685 | { |
647 | { |
686 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
648 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
687 | return 1; |
649 | return 1; |
688 | } |
650 | } |
689 | |
651 | |
… | |
… | |
697 | { |
659 | { |
698 | *simple_attack = 1; |
660 | *simple_attack = 1; |
699 | return 0; |
661 | return 0; |
700 | } |
662 | } |
701 | |
663 | |
702 | if (QUERY_FLAG (*target, FLAG_REMOVED) |
664 | if ((*target)->flag [FLAG_REMOVED] |
703 | || QUERY_FLAG (*hitter, FLAG_REMOVED) |
665 | || (*hitter)->flag [FLAG_REMOVED] |
704 | || !(*hitter)->map |
666 | || !(*hitter)->map |
705 | || !on_same_map (*hitter, *target)) |
667 | || !on_same_map (*hitter, *target)) |
706 | { |
668 | { |
707 | LOG (llevError | logBacktrace, "BUG: hitter (%s) with no relation to target (%s)\n", |
669 | LOG (llevError | logBacktrace, "BUG: hitter (%s) with no relation to target (%s)\n", |
708 | (*hitter)->debug_desc (), (*target)->debug_desc ()); |
670 | (*hitter)->debug_desc (), (*target)->debug_desc ()); |
… | |
… | |
721 | */ |
683 | */ |
722 | int new_mode; |
684 | int new_mode; |
723 | |
685 | |
724 | if (hitter->env == target || target->env == hitter) |
686 | if (hitter->env == target || target->env == hitter) |
725 | new_mode = 1; |
687 | new_mode = 1; |
726 | else if (QUERY_FLAG (hitter, FLAG_REMOVED) || QUERY_FLAG (target, FLAG_REMOVED) |
688 | else if (hitter->flag [FLAG_REMOVED] || target->flag [FLAG_REMOVED] |
727 | || hitter->map == NULL || !on_same_map (hitter, target)) |
689 | || hitter->map == NULL || !on_same_map (hitter, target)) |
728 | return 1; |
690 | return 1; |
729 | else |
691 | else |
730 | new_mode = 0; |
692 | new_mode = 0; |
731 | |
693 | |
… | |
… | |
737 | * monster). |
699 | * monster). |
738 | */ |
700 | */ |
739 | static void |
701 | static void |
740 | thrown_item_effect (object *hitter, object *victim) |
702 | thrown_item_effect (object *hitter, object *victim) |
741 | { |
703 | { |
742 | if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
704 | if (!hitter->flag [FLAG_ALIVE]) |
743 | { |
705 | { |
744 | /* May not need a switch for just 2 types, but this makes it |
706 | /* May not need a switch for just 2 types, but this makes it |
745 | * easier for expansion. |
707 | * easier for expansion. |
746 | */ |
708 | */ |
747 | switch (hitter->type) |
709 | switch (hitter->type) |
748 | { |
710 | { |
749 | case POTION: |
711 | case POTION: |
750 | /* should player get a save throw instead of checking magic protection? */ |
712 | /* should player get a save throw instead of checking magic protection? */ |
751 | if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_UNDEAD) && (victim->resist[ATNR_MAGIC] < 60)) |
713 | if (victim->flag [FLAG_ALIVE] && !victim->flag [FLAG_UNDEAD] && (victim->resist[ATNR_MAGIC] < 60)) |
752 | (void) apply_potion (victim, hitter); |
714 | apply_potion (victim, hitter); |
753 | break; |
715 | break; |
754 | |
716 | |
755 | case POISON: /* poison drinks */ |
717 | case POISON: /* poison drinks */ |
756 | /* As with potions, should monster get a save? */ |
718 | /* As with potions, should monster get a save? */ |
757 | if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_UNDEAD) && (victim->resist[ATNR_POISON] < 60)) |
719 | if (victim->flag [FLAG_ALIVE] && !victim->flag [FLAG_UNDEAD] && (victim->resist[ATNR_POISON] < 60)) |
758 | apply_poison (victim, hitter); |
720 | apply_poison (victim, hitter); |
759 | break; |
721 | break; |
760 | |
722 | |
761 | /* Removed case statements that did nothing. |
723 | /* Removed case statements that did nothing. |
762 | * food may be poisonous, but monster must be willing to eat it, |
724 | * food may be poisonous, but monster must be willing to eat it, |
… | |
… | |
769 | |
731 | |
770 | /* determine if the object is an 'aimed' missile */ |
732 | /* determine if the object is an 'aimed' missile */ |
771 | static int |
733 | static int |
772 | is_aimed_missile (object *op) |
734 | is_aimed_missile (object *op) |
773 | { |
735 | { |
774 | |
|
|
775 | /* I broke what used to be one big if into a few nested |
736 | /* I broke what used to be one big if into a few nested |
776 | * ones so that figuring out the logic is at least possible. |
737 | * ones so that figuring out the logic is at least possible. |
777 | */ |
738 | */ |
778 | if (op && (op->move_type & MOVE_FLYING)) |
739 | if (op && (op->move_type & MOVE_FLYING)) |
779 | if (op->type == ARROW || op->type == THROWN_OBJ) |
740 | if (op->type == ARROW || op->type == THROWN_OBJ) |
… | |
… | |
803 | if ((attacker = hitter->owner) == NULL) |
764 | if ((attacker = hitter->owner) == NULL) |
804 | attacker = hitter; |
765 | attacker = hitter; |
805 | /* A player who saves but hasn't quit still could have objects |
766 | /* A player who saves but hasn't quit still could have objects |
806 | * owned by him - need to handle that case to avoid crashes. |
767 | * owned by him - need to handle that case to avoid crashes. |
807 | */ |
768 | */ |
808 | if (QUERY_FLAG (attacker, FLAG_REMOVED)) |
769 | if (attacker->flag [FLAG_REMOVED]) |
809 | attacker = hitter; |
770 | attacker = hitter; |
810 | } |
771 | } |
811 | else if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
772 | else if (!hitter->flag [FLAG_ALIVE]) |
812 | return 0; |
773 | return 0; |
813 | |
774 | |
814 | /* determine the condtions under which we make an attack. |
775 | /* determine the condtions under which we make an attack. |
815 | * Add more cases, as the need occurs. */ |
776 | * Add more cases, as the need occurs. */ |
816 | |
777 | |
817 | if (!can_see_enemy (attacker, target)) |
778 | if (!can_see_enemy (attacker, target)) |
818 | { |
779 | { |
819 | /* target is unseen */ |
780 | /* target is unseen */ |
820 | if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) |
781 | if (target->invisible || attacker->flag [FLAG_BLIND]) |
821 | adjust -= 10; |
782 | adjust -= 10; |
822 | /* dark map penalty for the hitter (lacks infravision if we got here). */ |
783 | /* dark map penalty for the hitter (lacks infravision if we got here). */ |
823 | else if (!stand_in_light (target)) |
784 | else if (!stand_in_light (target)) |
824 | adjust -= target->map->darklevel (); |
785 | adjust -= target->map->darklevel (); |
825 | } |
786 | } |
826 | |
787 | |
827 | if (QUERY_FLAG (attacker, FLAG_SCARED)) |
788 | if (attacker->flag [FLAG_SCARED]) |
828 | adjust -= 3; |
789 | adjust -= 3; |
829 | |
790 | |
830 | if (QUERY_FLAG (target, FLAG_UNAGGRESSIVE)) |
791 | if (target->flag [FLAG_UNAGGRESSIVE]) |
831 | adjust += 1; |
792 | adjust += 1; |
832 | |
793 | |
833 | if (QUERY_FLAG (target, FLAG_SCARED)) |
794 | if (target->flag [FLAG_SCARED]) |
834 | adjust += 1; |
795 | adjust += 1; |
835 | |
796 | |
836 | if (QUERY_FLAG (attacker, FLAG_CONFUSED)) |
797 | if (attacker->flag [FLAG_CONFUSED]) |
837 | adjust -= 3; |
798 | adjust -= 3; |
838 | |
799 | |
839 | /* if we attack at a different 'altitude' its harder */ |
800 | /* if we attack at a different 'altitude' its harder */ |
840 | if ((attacker->move_type & target->move_type) == 0) |
801 | if ((attacker->move_type & target->move_type) == 0) |
841 | adjust -= 2; |
802 | adjust -= 2; |
… | |
… | |
877 | |
838 | |
878 | /* |
839 | /* |
879 | * A little check to make it more difficult to dance forward and back |
840 | * A little check to make it more difficult to dance forward and back |
880 | * to avoid ever being hit by monsters. |
841 | * to avoid ever being hit by monsters. |
881 | */ |
842 | */ |
882 | if (!simple_attack && QUERY_FLAG (op, FLAG_MONSTER) && op->speed_left > abs (op->speed) * -0.3f) |
843 | if (!simple_attack && op->flag [FLAG_MONSTER] && op->speed_left > op->speed * -0.3f) |
883 | { |
844 | { |
884 | /* Decrease speed BEFORE calling process_object. Otherwise, an |
845 | /* Decrease speed BEFORE calling process_object. Otherwise, an |
885 | * infinite loop occurs, with process_object calling move_monster, |
846 | * infinite loop occurs, with process_object calling move_monster, |
886 | * which then gets here again. By decreasing the speed before |
847 | * which then gets here again. By decreasing the speed before |
887 | * we call process_object, the 'if' statement above will fail. |
848 | * we call process_object, the 'if' statement above will fail. |
… | |
… | |
909 | if (!simple_attack) |
870 | if (!simple_attack) |
910 | { |
871 | { |
911 | /* If you hit something, the victim should *always* wake up. |
872 | /* If you hit something, the victim should *always* wake up. |
912 | * Before, invisible hitters could avoid doing this. |
873 | * Before, invisible hitters could avoid doing this. |
913 | * -b.t. */ |
874 | * -b.t. */ |
914 | if (QUERY_FLAG (op, FLAG_SLEEP)) |
875 | if (op->flag [FLAG_SLEEP]) |
915 | CLEAR_FLAG (op, FLAG_SLEEP); |
876 | op->clr_flag (FLAG_SLEEP); |
916 | |
877 | |
917 | /* If the victim can't see the attacker, it may alert others |
878 | /* If the victim can't see the attacker, it may alert others |
918 | * for help. */ |
879 | * for help. */ |
919 | if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int)) |
880 | if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int)) |
920 | npc_call_help (op); |
881 | npc_call_help (op); |
… | |
… | |
940 | } |
901 | } |
941 | |
902 | |
942 | /* Need to do at least 1 damage, otherwise there is no point |
903 | /* Need to do at least 1 damage, otherwise there is no point |
943 | * to go further and it will cause FPE's below. |
904 | * to go further and it will cause FPE's below. |
944 | */ |
905 | */ |
945 | if (hitdam <= 0) |
906 | max_it (hitdam, 1); |
946 | hitdam = 1; |
|
|
947 | |
907 | |
948 | type = hitter->attacktype; |
908 | type = hitter->attacktype; |
949 | |
909 | |
950 | /* Ok, because some of the brainfucks of the good *sigh* old *sigh* |
910 | /* Ok, because some of the brainfucks of the good *sigh* old *sigh* |
951 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
911 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
… | |
… | |
959 | */ |
919 | */ |
960 | if (!type) |
920 | if (!type) |
961 | type = AT_PHYSICAL; |
921 | type = AT_PHYSICAL; |
962 | |
922 | |
963 | /* Handle monsters that hit back */ |
923 | /* Handle monsters that hit back */ |
964 | if (!simple_attack && QUERY_FLAG (op, FLAG_HITBACK) && QUERY_FLAG (hitter, FLAG_ALIVE)) |
924 | if (!simple_attack && op->flag [FLAG_HITBACK] && hitter->flag [FLAG_ALIVE]) |
965 | { |
925 | { |
966 | if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
926 | if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
967 | new_draw_info (NDI_UNIQUE, 0, hitter, "You are splashed by acid!\n"); |
927 | new_draw_info (NDI_UNIQUE, 0, hitter, "You are splashed by acid!\n"); |
968 | |
928 | |
969 | hit_player (hitter, random_roll (0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1); |
929 | hit_player (hitter, random_roll (0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1); |
… | |
… | |
995 | } |
955 | } |
996 | |
956 | |
997 | int |
957 | int |
998 | attack_ob (object *op, object *hitter) |
958 | attack_ob (object *op, object *hitter) |
999 | { |
959 | { |
1000 | hitter = hitter->head_ (); |
|
|
1001 | |
|
|
1002 | return attack_ob_simple (op, hitter, hitter->stats.dam, hitter->stats.wc); |
960 | return attack_ob_simple (op, hitter->head_ (), hitter->stats.dam, hitter->stats.wc); |
1003 | } |
961 | } |
1004 | |
962 | |
1005 | /* op is the arrow, tmp is what is stopping the arrow. |
963 | /* op is the arrow, tmp is what is stopping the arrow. |
1006 | * |
964 | * |
1007 | * Returns 1 if op was inserted into tmp's inventory, 0 otherwise. |
965 | * Returns 1 if op was inserted into tmp's inventory, 0 otherwise. |
… | |
… | |
1115 | |
1073 | |
1116 | return 0; |
1074 | return 0; |
1117 | } |
1075 | } |
1118 | |
1076 | |
1119 | if (hit_something && op->speed >= 10.0) |
1077 | if (hit_something && op->speed >= 10.0) |
1120 | op->speed -= 1.0; |
1078 | op->set_speed (op->speed - 1.f); |
1121 | |
1079 | |
1122 | /* Missile missed victim - reassemble missile */ |
1080 | /* Missile missed victim - reassemble missile */ |
1123 | if (container) |
1081 | if (container) |
1124 | { |
1082 | { |
1125 | hitter->remove (); |
1083 | hitter->remove (); |
… | |
… | |
1127 | } |
1085 | } |
1128 | |
1086 | |
1129 | return op; |
1087 | return op; |
1130 | } |
1088 | } |
1131 | |
1089 | |
1132 | void |
1090 | static void |
1133 | tear_down_wall (object *op) |
1091 | tear_down_wall (object *op) |
1134 | { |
1092 | { |
1135 | if (!op->stats.maxhp) |
1093 | if (!op->stats.maxhp) |
1136 | LOG (llevError, "TEAR_DOWN wall %s had no maxhp.\n", &op->name); |
1094 | LOG (llevError, "TEAR_DOWN wall %s had no maxhp.\n", &op->name); |
1137 | else if (!op->has_anim ()) |
1095 | else if (!op->has_anim ()) |
… | |
… | |
1166 | op->flag [FLAG_ALIVE] = false; |
1124 | op->flag [FLAG_ALIVE] = false; |
1167 | } |
1125 | } |
1168 | } |
1126 | } |
1169 | } |
1127 | } |
1170 | |
1128 | |
1171 | void |
1129 | static void |
1172 | scare_creature (object *target, object *hitter) |
1130 | scare_creature (object *target, object *hitter) |
1173 | { |
1131 | { |
1174 | target->flag [FLAG_SCARED] = true; |
1132 | target->flag [FLAG_SCARED] = true; |
1175 | |
1133 | |
1176 | if (!target->enemy) |
1134 | if (!target->enemy) |
… | |
… | |
1193 | * MSW 2002-07-17 |
1151 | * MSW 2002-07-17 |
1194 | */ |
1152 | */ |
1195 | int |
1153 | int |
1196 | kill_object (object *op, int dam, object *hitter, int type) |
1154 | kill_object (object *op, int dam, object *hitter, int type) |
1197 | { |
1155 | { |
1198 | char buf[MAX_BUF]; |
|
|
1199 | shstr skill; |
1156 | shstr skill; |
1200 | int maxdam = 0; |
1157 | int maxdam = 0; |
1201 | int battleg = 0; /* true if op standing on battleground */ |
1158 | int battleg = 0; /* true if op standing on battleground */ |
1202 | int pk = 0; /* true if op and what controls hitter are both players */ |
1159 | int pk = 0; /* true if op and what controls hitter are both players */ |
1203 | object *owner = 0; |
1160 | object *owner = 0; |
… | |
… | |
1213 | * this creature. The function(s) that call us have already |
1170 | * this creature. The function(s) that call us have already |
1214 | * adjusted the creatures HP total, so that is negative. |
1171 | * adjusted the creatures HP total, so that is negative. |
1215 | */ |
1172 | */ |
1216 | maxdam = dam + op->stats.hp + 1; |
1173 | maxdam = dam + op->stats.hp + 1; |
1217 | |
1174 | |
1218 | if (QUERY_FLAG (op, FLAG_BLOCKSVIEW)) |
1175 | if (op->flag [FLAG_BLOCKSVIEW]) |
1219 | update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */ |
1176 | update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */ |
1220 | |
1177 | |
1221 | if (op->type == DOOR) |
1178 | if (op->type == DOOR) |
1222 | { |
1179 | { |
1223 | op->set_speed (0.1f); |
1180 | op->set_speed (0.1f); |
1224 | op->speed_left = -0.05f; |
1181 | op->speed_left = -0.05f; |
1225 | return maxdam; |
1182 | return maxdam; |
1226 | } |
1183 | } |
1227 | |
1184 | |
1228 | if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) |
1185 | if (op->flag [FLAG_FRIENDLY] && op->type != PLAYER) |
1229 | { |
1186 | { |
1230 | op->drop_and_destroy (); |
1187 | op->drop_and_destroy (); |
1231 | return maxdam; |
1188 | return maxdam; |
1232 | } |
1189 | } |
1233 | |
1190 | |
… | |
… | |
1300 | else if (owner->chosen_skill) |
1257 | else if (owner->chosen_skill) |
1301 | { |
1258 | { |
1302 | skop = owner->chosen_skill; |
1259 | skop = owner->chosen_skill; |
1303 | skill = skop->skill; |
1260 | skill = skop->skill; |
1304 | } |
1261 | } |
1305 | else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon) |
1262 | else if (owner->flag [FLAG_READY_WEAPON] && owner->current_weapon) |
1306 | skill = owner->current_weapon->skill; |
1263 | skill = owner->current_weapon->skill; |
1307 | else |
1264 | else |
1308 | { |
1265 | { |
|
|
1266 | LOG (llevError | logBacktrace, |
1309 | LOG (llevError, "BUG: kill_object - unable to find skill that killed monster\n" |
1267 | "BUG: kill_object - unable to find skill that killed monster\n" |
1310 | "op: %s\n" "hitter: %s\n" "owner: %s\n", |
1268 | "op: %s\n" "hitter: %s\n" "op: %s\n", |
1311 | owner->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
1269 | op->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
1312 | skill = 0; |
1270 | skill = 0; |
1313 | } |
1271 | } |
1314 | |
1272 | |
1315 | /* We have the skill we want to credit to - now find the object this goes |
1273 | /* We have the skill we want to credit to - now find the object this goes |
1316 | * to. Make sure skop is an actual skill, and not a skill tool! |
1274 | * to. Make sure skop is an actual skill, and not a skill tool! |
… | |
… | |
1326 | |
1284 | |
1327 | if (!skill && skop) |
1285 | if (!skill && skop) |
1328 | skill = skop->skill; |
1286 | skill = skop->skill; |
1329 | |
1287 | |
1330 | /* If you didn't kill yourself, and your not the wizard */ |
1288 | /* If you didn't kill yourself, and your not the wizard */ |
1331 | if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) |
1289 | if (owner != op && !op->flag [FLAG_WIZ]) |
1332 | { |
1290 | { |
1333 | int exp; |
1291 | int exp; |
1334 | |
1292 | |
1335 | /* Really don't give much experience for killing other players */ |
1293 | /* Really don't give much experience for killing other players */ |
1336 | // schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
1294 | // schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
1337 | if (op->type == PLAYER) |
|
|
1338 | { |
|
|
1339 | if (battleg) |
1295 | if (battleg) |
|
|
1296 | { |
|
|
1297 | if (op->is_player ()) |
1340 | { |
1298 | { |
1341 | new_draw_info (NDI_UNIQUE, 0, owner, "Your foe has fallen!"); |
1299 | new_draw_info (NDI_UNIQUE, 0, owner, "Your foe has fallen!"); |
1342 | new_draw_info (NDI_UNIQUE, 0, owner, "VICTORY!!!"); |
1300 | new_draw_info (NDI_UNIQUE, 0, owner, "VICTORY!!!"); |
1343 | } |
1301 | } |
1344 | else |
1302 | |
|
|
1303 | exp = 0; |
|
|
1304 | } |
|
|
1305 | else if (op->is_player ()) |
1345 | exp = op->stats.exp / 1000; |
1306 | exp = op->stats.exp / 1000; |
1346 | } |
|
|
1347 | else |
1307 | else |
1348 | exp = calc_skill_exp (owner, op, skop); |
1308 | exp = calc_skill_exp (owner, op, skop); |
1349 | |
|
|
1350 | /* if op is standing on "battleground" (arena), no way to gain |
|
|
1351 | * exp by killing him |
|
|
1352 | */ |
|
|
1353 | if (battleg) |
|
|
1354 | exp = 0; |
|
|
1355 | |
1309 | |
1356 | /* Don't know why this is set this way - doesn't make |
1310 | /* Don't know why this is set this way - doesn't make |
1357 | * sense to just divide everything by two for no reason. |
1311 | * sense to just divide everything by two for no reason. |
1358 | */ |
1312 | */ |
1359 | |
1313 | |
… | |
… | |
1397 | } /* else part of a party */ |
1351 | } /* else part of a party */ |
1398 | } /* end if person didn't kill himself */ |
1352 | } /* end if person didn't kill himself */ |
1399 | |
1353 | |
1400 | if (op->type != PLAYER) |
1354 | if (op->type != PLAYER) |
1401 | { |
1355 | { |
1402 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
1356 | if (op->flag [FLAG_FRIENDLY]) |
1403 | { |
1357 | { |
1404 | object *owner1 = op->owner; |
1358 | object *owner1 = op->owner; |
1405 | |
1359 | |
1406 | if (owner1 && owner1->type == PLAYER) |
1360 | if (owner1 && owner1->type == PLAYER) |
1407 | { |
1361 | { |
… | |
… | |
1468 | * modify it. |
1422 | * modify it. |
1469 | */ |
1423 | */ |
1470 | /* Oct 95 - altered the following slightly for MULTIPLE_GODS hack |
1424 | /* Oct 95 - altered the following slightly for MULTIPLE_GODS hack |
1471 | * which needs new attacktype AT_HOLYWORD to work . b.t. */ |
1425 | * which needs new attacktype AT_HOLYWORD to work . b.t. */ |
1472 | int |
1426 | int |
1473 | hit_player (object *op, int dam, object *hitter, int type, int full_hit) |
1427 | hit_player (object *op, int dam, object *hitter, uint32_t type, int full_hit) |
1474 | { |
1428 | { |
1475 | int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC); |
1429 | int magic = type & AT_MAGIC; |
1476 | int maxattacktype, attacknum; |
|
|
1477 | int body_attack = op && op->head; /* Did we hit op's head? */ |
1430 | int body_attack = op && op->head; /* Did we hit op's head? */ |
|
|
1431 | int maxdam = 0, ndam = 0; |
|
|
1432 | int maxattacktype; |
1478 | int simple_attack; |
1433 | int simple_attack; |
1479 | int rtn_kill = 0; |
1434 | int rtn_kill = 0; |
1480 | int friendlyfire; |
1435 | int friendlyfire; |
1481 | |
1436 | |
1482 | if (get_attack_mode (&op, &hitter, &simple_attack)) |
1437 | if (get_attack_mode (&op, &hitter, &simple_attack)) |
1483 | return 0; |
1438 | return 0; |
1484 | |
1439 | |
1485 | /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */ |
1440 | /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */ |
1486 | if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE)) |
1441 | if (op->flag [FLAG_WIZ] || op->flag [FLAG_NO_DAMAGE]) |
1487 | return 0; |
1442 | return 0; |
1488 | |
1443 | |
1489 | // only allow pk for hostile players |
1444 | // only allow pk for hostile players |
1490 | if (op->type == PLAYER) |
1445 | if (op->type == PLAYER) |
1491 | { |
1446 | { |
… | |
… | |
1533 | |
1488 | |
1534 | break; |
1489 | break; |
1535 | } |
1490 | } |
1536 | } |
1491 | } |
1537 | |
1492 | |
1538 | if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) |
1493 | if (!op->flag [FLAG_ALIVE] || op->stats.hp < 0) |
1539 | { |
1494 | { |
1540 | /* FIXME: If a player is killed by a rune in a door, the |
1495 | /* FIXME: If a player is killed by a rune in a door, the |
1541 | * destroyed() check above doesn't return, and might get here. |
1496 | * destroyed() check above doesn't return, and might get here. |
1542 | */ |
1497 | */ |
1543 | |
1498 | |
… | |
… | |
1584 | object *god; |
1539 | object *god; |
1585 | |
1540 | |
1586 | if ((!hitter->slaying |
1541 | if ((!hitter->slaying |
1587 | || (!(op->race && hitter->slaying.contains (op->race)) |
1542 | || (!(op->race && hitter->slaying.contains (op->race)) |
1588 | && !(op->name && hitter->slaying.contains (op->name)))) |
1543 | && !(op->name && hitter->slaying.contains (op->name)))) |
1589 | && (!QUERY_FLAG (op, FLAG_UNDEAD) |
1544 | && (!op->flag [FLAG_UNDEAD] |
1590 | || (hitter->title |
1545 | || (hitter->title |
1591 | && (god = find_god (determine_god (hitter))) != NULL |
1546 | && (god = find_god (determine_god (hitter))) != NULL |
1592 | && god->race.contains (shstr_undead)))) |
1547 | && god->race.contains (shstr_undead)))) |
1593 | return 0; |
1548 | return 0; |
1594 | } |
1549 | } |
1595 | |
1550 | |
1596 | maxattacktype = type; /* initialise this to something */ |
1551 | maxattacktype = type; /* initialise this to something */ |
1597 | for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) |
1552 | for_all_bits_sparse_32 (type, attacknum) |
1598 | { |
1553 | { |
|
|
1554 | uint32_t attacktype = 1 << attacknum; |
|
|
1555 | |
1599 | /* Magic isn't really a true attack type - it gets combined with other |
1556 | /* Magic isn't really a true attack type - it gets combined with other |
1600 | * attack types. As such, skip it over. However, if magic is |
1557 | * attack types. As such, skip it over. However, if magic is |
1601 | * the only attacktype in the group, then still attack with it |
1558 | * the only attacktype in the group, then still attack with it |
1602 | */ |
1559 | */ |
1603 | if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC)) |
1560 | if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC)) |
… | |
… | |
1606 | /* Go through and hit the player with each attacktype, one by one. |
1563 | /* Go through and hit the player with each attacktype, one by one. |
1607 | * hit_player_attacktype only figures out the damage, doesn't inflict |
1564 | * hit_player_attacktype only figures out the damage, doesn't inflict |
1608 | * it. It will do the appropriate action for attacktypes with |
1565 | * it. It will do the appropriate action for attacktypes with |
1609 | * effects (slow, paralization, etc. |
1566 | * effects (slow, paralization, etc. |
1610 | */ |
1567 | */ |
1611 | if (type & attacktype) |
|
|
1612 | { |
|
|
1613 | ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic); |
1568 | ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic); |
|
|
1569 | |
1614 | /* the >= causes us to prefer messages from special attacks, if |
1570 | /* the >= causes us to prefer messages from special attacks, if |
1615 | * the damage is equal. |
1571 | * the damage is equal. |
1616 | */ |
1572 | */ |
1617 | if (ndam >= maxdam) |
1573 | if (ndam >= maxdam) |
1618 | { |
1574 | { |
1619 | maxdam = ndam; |
1575 | maxdam = ndam; |
1620 | maxattacktype = 1 << attacknum; |
1576 | maxattacktype = 1 << attacknum; |
1621 | } |
|
|
1622 | } |
1577 | } |
1623 | } |
1578 | } |
1624 | |
1579 | |
1625 | /* if this is friendly fire then do a set % of damage only |
1580 | /* if this is friendly fire then do a set % of damage only |
1626 | * Note - put a check in to make sure this attack is actually |
1581 | * Note - put a check in to make sure this attack is actually |
… | |
… | |
1666 | // keep a refcount for a long time and I see no usefulness |
1621 | // keep a refcount for a long time and I see no usefulness |
1667 | // for an non-active objetc to know its enemy. |
1622 | // for an non-active objetc to know its enemy. |
1668 | if (op->active) |
1623 | if (op->active) |
1669 | if (hitter->owner) |
1624 | if (hitter->owner) |
1670 | op->enemy = hitter->owner; |
1625 | op->enemy = hitter->owner; |
1671 | else if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
1626 | else if (hitter->flag [FLAG_ALIVE]) |
1672 | op->enemy = hitter; |
1627 | op->enemy = hitter; |
1673 | |
1628 | |
1674 | if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) |
1629 | if (op->flag [FLAG_UNAGGRESSIVE] && op->type != PLAYER) |
1675 | { |
1630 | { |
1676 | /* The unaggressives look after themselves 8) */ |
1631 | /* The unaggressives look after themselves 8) */ |
1677 | CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); |
1632 | op->clr_flag (FLAG_UNAGGRESSIVE); |
1678 | npc_call_help (op); |
1633 | npc_call_help (op); |
1679 | } |
1634 | } |
1680 | |
1635 | |
1681 | if (magic && did_make_save (op, op->level, 0)) |
1636 | if (magic && did_make_save (op, op->level, 0)) |
1682 | maxdam = maxdam / 2; |
1637 | maxdam = maxdam / 2; |
… | |
… | |
1684 | attack_message (maxdam, maxattacktype, op, hitter); |
1639 | attack_message (maxdam, maxattacktype, op, hitter); |
1685 | |
1640 | |
1686 | op->stats.hp -= maxdam; |
1641 | op->stats.hp -= maxdam; |
1687 | |
1642 | |
1688 | /* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
1643 | /* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
1689 | if ((op->stats.hp >= 0) && |
1644 | if (op->stats.hp >= 0 |
1690 | (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) && |
1645 | && (op->flag [FLAG_MONSTER] || op->type == PLAYER) |
1691 | op->stats.hp < (signed short) (((float) op->run_away / (float) 100) * (float) op->stats.maxhp)) |
1646 | && op->stats.hp * 100 < op->stats.maxhp * op->run_away) |
1692 | { |
1647 | { |
1693 | |
1648 | |
1694 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1649 | if (op->flag [FLAG_MONSTER]) |
1695 | SET_FLAG (op, FLAG_RUN_AWAY); |
1650 | op->set_flag (FLAG_RUN_AWAY); |
1696 | else |
1651 | else |
1697 | scare_creature (op, hitter); |
1652 | scare_creature (op, hitter); |
1698 | } |
1653 | } |
1699 | |
1654 | |
1700 | if (QUERY_FLAG (op, FLAG_TEAR_DOWN)) |
1655 | if (op->flag [FLAG_TEAR_DOWN]) |
1701 | { |
1656 | { |
1702 | if (maxdam) |
1657 | if (maxdam) |
1703 | tear_down_wall (op); |
1658 | tear_down_wall (op); |
1704 | |
1659 | |
1705 | return maxdam; /* nothing more to do for wall */ |
1660 | return maxdam; /* nothing more to do for wall */ |
… | |
… | |
1712 | |
1667 | |
1713 | /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note |
1668 | /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note |
1714 | * that before if the player was immune to ghosthit, the monster |
1669 | * that before if the player was immune to ghosthit, the monster |
1715 | * remained - that is no longer the case. |
1670 | * remained - that is no longer the case. |
1716 | */ |
1671 | */ |
1717 | if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) |
1672 | if (hitter->flag [FLAG_ONE_HIT]) |
1718 | hitter->drop_and_destroy (); |
1673 | hitter->drop_and_destroy (); |
1719 | /* Lets handle creatures that are splitting now */ |
1674 | /* Lets handle creatures that are splitting now */ |
1720 | else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) |
1675 | else if (type & AT_PHYSICAL && !op->flag [FLAG_FREED] && op->flag [FLAG_SPLITTING]) |
1721 | { |
1676 | { |
1722 | int i; |
|
|
1723 | int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); |
1677 | int friendly = op->flag [FLAG_FRIENDLY]; |
1724 | int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE); |
1678 | int unaggressive = op->flag [FLAG_UNAGGRESSIVE]; |
1725 | object *owner = op->owner; |
1679 | object *owner = op->owner; |
1726 | |
1680 | |
1727 | if (!op->other_arch) |
1681 | if (!op->other_arch) |
1728 | { |
1682 | { |
1729 | LOG (llevError, "SPLITTING without other_arch error.\n"); |
1683 | LOG (llevError, "SPLITTING without other_arch error.\n"); |
1730 | return maxdam; |
1684 | return maxdam; |
1731 | } |
1685 | } |
1732 | |
1686 | |
1733 | op->remove (); |
1687 | op->remove (); |
1734 | |
1688 | |
1735 | for (i = 0; i < op->stats.food; i++) |
1689 | for (int i = 0; i < op->stats.food; i++) |
1736 | { /* This doesn't handle op->more yet */ |
1690 | { /* This doesn't handle op->more yet */ |
1737 | object *tmp = arch_to_object (op->other_arch); |
1691 | object *tmp = op->other_arch->instance (); |
1738 | int j; |
|
|
1739 | |
1692 | |
1740 | tmp->stats.hp = op->stats.hp; |
1693 | tmp->stats.hp = op->stats.hp; |
1741 | |
1694 | |
1742 | if (friendly) |
1695 | if (friendly) |
1743 | { |
1696 | { |
… | |
… | |
1747 | if (owner) |
1700 | if (owner) |
1748 | tmp->set_owner (owner); |
1701 | tmp->set_owner (owner); |
1749 | } |
1702 | } |
1750 | |
1703 | |
1751 | if (unaggressive) |
1704 | if (unaggressive) |
1752 | SET_FLAG (tmp, FLAG_UNAGGRESSIVE); |
1705 | tmp->set_flag (FLAG_UNAGGRESSIVE); |
1753 | |
1706 | |
1754 | j = find_first_free_spot (tmp, op->map, op->x, op->y); |
1707 | int j = find_first_free_spot (tmp, op->map, op->x, op->y); |
1755 | |
1708 | |
1756 | if (j == -1) /* No spot to put this monster */ |
1709 | if (j == -1) /* No spot to put this monster */ |
1757 | tmp->destroy (); |
1710 | tmp->destroy (); |
1758 | else |
1711 | else |
1759 | { |
1712 | { |
… | |
… | |
1768 | hitter->drop_and_destroy (); |
1721 | hitter->drop_and_destroy (); |
1769 | |
1722 | |
1770 | return maxdam; |
1723 | return maxdam; |
1771 | } |
1724 | } |
1772 | |
1725 | |
1773 | void |
1726 | static void |
1774 | poison_player (object *op, object *hitter, int dam) |
1727 | poison_player (object *op, object *hitter, int dam) |
1775 | { |
1728 | { |
1776 | archetype *at = archetype::find ("poisoning"); |
1729 | archetype *at = archetype::find (shstr_poisoning); |
1777 | object *tmp = present_arch_in_ob (at, op); |
1730 | object *tmp = present_arch_in_ob (at, op); |
1778 | |
1731 | |
1779 | if (tmp == NULL) |
1732 | if (!tmp) |
1780 | { |
1733 | { |
1781 | if ((tmp = arch_to_object (at)) == NULL) |
1734 | tmp = insert_ob_in_ob (at->instance (), op); |
1782 | LOG (llevError, "Failed to clone arch poisoning.\n"); |
1735 | /* peterm: give poisoning some teeth. It should |
|
|
1736 | * be able to kill things better than it does: |
|
|
1737 | * damage should be dependent something--I choose to |
|
|
1738 | * do this: if it's a monster, the damage from the |
|
|
1739 | * poisoning goes as the level of the monster/2. |
|
|
1740 | * If anything else, goes as damage. |
|
|
1741 | */ |
|
|
1742 | |
|
|
1743 | if (hitter->flag [FLAG_ALIVE]) |
|
|
1744 | tmp->stats.dam += hitter->level / 2; |
1783 | else |
1745 | else |
1784 | { |
|
|
1785 | tmp = insert_ob_in_ob (tmp, op); |
|
|
1786 | /* peterm: give poisoning some teeth. It should |
|
|
1787 | * be able to kill things better than it does: |
|
|
1788 | * damage should be dependent something--I choose to |
|
|
1789 | * do this: if it's a monster, the damage from the |
|
|
1790 | * poisoning goes as the level of the monster/2. |
|
|
1791 | * If anything else, goes as damage. |
|
|
1792 | */ |
|
|
1793 | |
|
|
1794 | if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
|
|
1795 | tmp->stats.dam += hitter->level / 2; |
|
|
1796 | else |
|
|
1797 | tmp->stats.dam = dam; |
1746 | tmp->stats.dam = dam; |
1798 | |
1747 | |
1799 | tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
1748 | tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
1800 | if (hitter->skill && hitter->skill != tmp->skill) |
1749 | if (hitter->skill && hitter->skill != tmp->skill) |
1801 | { |
|
|
1802 | tmp->skill = hitter->skill; |
1750 | tmp->skill = hitter->skill; |
1803 | } |
|
|
1804 | |
1751 | |
1805 | tmp->stats.food += dam; /* more damage, longer poisoning */ |
1752 | tmp->stats.food += dam; /* more damage, longer poisoning */ |
1806 | |
1753 | |
1807 | if (op->type == PLAYER) |
1754 | if (op->type == PLAYER) |
1808 | { |
1755 | { |
1809 | /* player looses stats, maximum is -10 of each */ |
1756 | /* player looses stats, maximum is -10 of each */ |
1810 | tmp->stats.Con = MAX (-(dam / 4 + 1), -10); |
1757 | tmp->stats.Con = max (-(dam / 4 + 1), -10); |
1811 | tmp->stats.Str = MAX (-(dam / 3 + 2), -10); |
1758 | tmp->stats.Str = max (-(dam / 3 + 2), -10); |
1812 | tmp->stats.Dex = MAX (-(dam / 6 + 1), -10); |
1759 | tmp->stats.Dex = max (-(dam / 6 + 1), -10); |
1813 | tmp->stats.Int = MAX (-dam / 7, -10); |
1760 | tmp->stats.Int = max (-(dam / 7 ), -10); |
1814 | SET_FLAG (tmp, FLAG_APPLIED); |
1761 | tmp->set_flag (FLAG_APPLIED); |
1815 | op->update_stats (); |
1762 | op->update_stats (); |
1816 | new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill."); |
1763 | new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill."); |
1817 | op->play_sound (tmp->sound); |
1764 | op->play_sound (tmp->sound); |
1818 | } |
1765 | } |
1819 | |
1766 | |
1820 | if (hitter->type == PLAYER) |
1767 | if (hitter->type == PLAYER) |
1821 | new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name); |
1768 | new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name); |
1822 | else if (hitter->owner != NULL && hitter->owner->type == PLAYER) |
1769 | else if (hitter->owner != NULL && hitter->owner->type == PLAYER) |
1823 | new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name); |
1770 | new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name); |
1824 | } |
|
|
1825 | |
1771 | |
1826 | tmp->speed_left = 0; |
1772 | tmp->speed_left = 0; |
1827 | } |
1773 | } |
1828 | else |
1774 | else |
1829 | tmp->stats.food++; |
1775 | tmp->stats.food++; |
1830 | } |
1776 | } |
1831 | |
1777 | |
1832 | void |
1778 | static void |
1833 | slow_player (object *op, object *hitter, int dam) |
1779 | slow_player (object *op, object *hitter, int dam) |
1834 | { |
1780 | { |
1835 | archetype *at = archetype::find ("slowness"); |
1781 | archetype *at = archetype::find (shstr_slowness); |
1836 | object *tmp; |
1782 | object *tmp; |
1837 | |
1783 | |
1838 | if (at == NULL) |
1784 | if (!at) |
1839 | LOG (llevError, "Can't find slowness archetype.\n"); |
1785 | LOG (llevError, "Can't find slowness archetype.\n"); |
1840 | |
1786 | |
1841 | if ((tmp = present_arch_in_ob (at, op)) == NULL) |
1787 | if ((tmp = present_arch_in_ob (at, op)) == NULL) |
1842 | { |
1788 | { |
1843 | tmp = arch_to_object (at); |
1789 | tmp = at->instance (); |
1844 | tmp = insert_ob_in_ob (tmp, op); |
1790 | tmp = insert_ob_in_ob (tmp, op); |
1845 | new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!"); |
1791 | new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!"); |
1846 | } |
1792 | } |
1847 | else |
1793 | else |
1848 | tmp->stats.food++; |
1794 | tmp->stats.food++; |
1849 | |
1795 | |
1850 | SET_FLAG (tmp, FLAG_APPLIED); |
1796 | tmp->set_flag (FLAG_APPLIED); |
1851 | tmp->speed_left = 0; |
1797 | tmp->speed_left = 0; |
1852 | op->update_stats (); |
1798 | op->update_stats (); |
1853 | } |
1799 | } |
1854 | |
1800 | |
1855 | void |
1801 | void |
1856 | confuse_player (object *op, object *hitter, int dam) |
1802 | confuse_player (object *op, object *hitter, int dam) |
1857 | { |
1803 | { |
1858 | object *tmp; |
1804 | object *tmp; |
1859 | int maxduration; |
1805 | int maxduration; |
1860 | |
1806 | |
1861 | tmp = present_in_ob_by_name (FORCE, "confusion", op); |
1807 | tmp = present_in_ob_by_name (FORCE, shstr_confusion, op); |
1862 | if (!tmp) |
1808 | if (!tmp) |
1863 | { |
1809 | { |
1864 | tmp = get_archetype (FORCE_NAME); |
1810 | tmp = archetype::get (FORCE_NAME); |
1865 | tmp = insert_ob_in_ob (tmp, op); |
1811 | tmp = insert_ob_in_ob (tmp, op); |
1866 | } |
1812 | } |
1867 | |
1813 | |
1868 | /* Duration added per hit and max. duration of confusion both depend |
1814 | /* Duration added per hit and max. duration of confusion both depend |
1869 | * on the player's resistance |
1815 | * on the player's resistance |
1870 | */ |
1816 | */ |
1871 | tmp->speed = 0.05; |
1817 | tmp->set_speed (0.05); |
1872 | tmp->subtype = FORCE_CONFUSION; |
1818 | tmp->subtype = FORCE_CONFUSION; |
1873 | tmp->duration = 8 + MAX (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1819 | tmp->duration = 8 + max (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1874 | tmp->name = "confusion"; |
1820 | tmp->name = shstr_confusion; |
1875 | maxduration = MAX (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1821 | maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1876 | |
1822 | |
1877 | if (tmp->duration > maxduration) |
1823 | if (tmp->duration > maxduration) |
1878 | tmp->duration = maxduration; |
1824 | tmp->duration = maxduration; |
1879 | |
1825 | |
1880 | if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED)) |
1826 | if (op->type == PLAYER && !op->flag [FLAG_CONFUSED]) |
1881 | new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!"); |
1827 | new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!"); |
1882 | |
1828 | |
1883 | SET_FLAG (op, FLAG_CONFUSED); |
1829 | op->set_flag (FLAG_CONFUSED); |
1884 | } |
1830 | } |
1885 | |
1831 | |
1886 | void |
1832 | void |
1887 | blind_player (object *op, object *hitter, int dam) |
1833 | blind_player (object *op, object *hitter, int dam) |
1888 | { |
1834 | { |
1889 | object *tmp, *owner; |
|
|
1890 | |
|
|
1891 | /* Save some work if we know it isn't going to affect the player */ |
1835 | /* Save some work if we know it isn't going to affect the player */ |
1892 | if (op->resist[ATNR_BLIND] == 100) |
1836 | if (op->resist[ATNR_BLIND] == 100) |
1893 | return; |
1837 | return; |
1894 | |
1838 | |
1895 | tmp = present_in_ob (BLINDNESS, op); |
1839 | object *tmp = present_in_ob (BLINDNESS, op); |
1896 | if (!tmp) |
1840 | if (!tmp) |
1897 | { |
1841 | { |
1898 | tmp = get_archetype ("blindness"); |
1842 | tmp = archetype::get (shstr_blindness); |
1899 | SET_FLAG (tmp, FLAG_BLIND); |
1843 | tmp->set_flag (FLAG_BLIND); |
1900 | SET_FLAG (tmp, FLAG_APPLIED); |
1844 | tmp->set_flag (FLAG_APPLIED); |
1901 | /* use floats so we don't lose too much precision due to rounding errors. |
1845 | // use floats so we don't lose too much precision due to rounding errors. |
1902 | * speed is a float anyways. |
1846 | tmp->set_speed (lerp<float> (op->resist [ATNR_BLIND], 0, 100, tmp->speed, MIN_ACTIVE_SPEED)); |
1903 | */ |
|
|
1904 | tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100; |
|
|
1905 | |
1847 | |
1906 | tmp = insert_ob_in_ob (tmp, op); |
1848 | tmp = insert_ob_in_ob (tmp, op); |
1907 | change_abil (op, tmp); /* Mostly to display any messages */ |
1849 | change_abil (op, tmp); /* Mostly to display any messages */ |
1908 | op->update_stats (); /* This takes care of some other stuff */ |
1850 | op->update_stats (); /* This takes care of some other stuff */ |
1909 | |
1851 | |
1910 | if (hitter->owner) |
|
|
1911 | owner = hitter->owner; |
|
|
1912 | else |
|
|
1913 | owner = hitter; |
|
|
1914 | |
|
|
1915 | new_draw_info_format (NDI_UNIQUE, 0, owner, "Your attack blinds %s!", query_name (op)); |
1852 | new_draw_info_format (NDI_UNIQUE, 0, hitter->outer_owner (), "Your attack blinds %s!", query_name (op)); |
1916 | } |
1853 | } |
|
|
1854 | |
1917 | tmp->stats.food += dam; |
1855 | tmp->stats.food += dam; |
1918 | if (tmp->stats.food > 10) |
1856 | min_it (tmp->stats.food, 10); |
1919 | tmp->stats.food = 10; |
|
|
1920 | } |
1857 | } |
1921 | |
1858 | |
1922 | void |
1859 | void |
1923 | paralyze_player (object *op, object *hitter, int dam) |
1860 | paralyze_player (object *op, object *hitter, int dam) |
1924 | { |
1861 | { |
1925 | float effect, max; |
|
|
1926 | |
|
|
1927 | /* object *tmp; */ |
|
|
1928 | |
|
|
1929 | /* This is strange stuff... someone knows for what this is |
1862 | /* This is strange stuff... someone knows for what this is |
1930 | * written? Well, i think this can and should be removed |
1863 | * written? Well, i think this can and should be removed |
1931 | */ |
1864 | */ |
1932 | |
1865 | |
1933 | /* |
1866 | /* |
… | |
… | |
1937 | insert_ob_in_map(tmp,op->map,tmp,INS_NO_MERGE | INS_NO_WALK_ON); |
1870 | insert_ob_in_map(tmp,op->map,tmp,INS_NO_MERGE | INS_NO_WALK_ON); |
1938 | } |
1871 | } |
1939 | */ |
1872 | */ |
1940 | |
1873 | |
1941 | /* Do this as a float - otherwise, rounding might very well reduce this to 0 */ |
1874 | /* Do this as a float - otherwise, rounding might very well reduce this to 0 */ |
1942 | effect = (float) dam *3.0 * (100.0 - op->resist[ATNR_PARALYZE]) / 100; |
1875 | float effect = dam * 3.f * (100.f - op->resist[ATNR_PARALYZE]) / 100.f; |
1943 | |
1876 | |
1944 | if (effect == 0) |
|
|
1945 | return; |
|
|
1946 | |
|
|
1947 | op->speed_left -= FABS (op->speed) * effect; |
1877 | op->speed_left -= op->speed * effect; |
1948 | /* tmp->stats.food+=(signed short) effect/op->speed; */ |
1878 | /* tmp->stats.food+=(signed short) effect/op->speed; */ |
1949 | |
1879 | |
1950 | /* max number of ticks to be affected for. */ |
1880 | /* max number of ticks to be affected for. */ |
1951 | max = (100 - op->resist[ATNR_PARALYZE]) / 2; |
1881 | float max = (100 - op->resist[ATNR_PARALYZE]) / 2; |
|
|
1882 | |
1952 | if (op->speed_left < -(FABS (op->speed) * max)) |
1883 | max_it (op->speed_left, -op->speed * max); |
1953 | op->speed_left = (float) -(FABS (op->speed) * max); |
|
|
1954 | |
1884 | |
1955 | /* tmp->stats.food = (signed short) (max/FABS(op->speed)); */ |
1885 | /* tmp->stats.food = (signed short) (max / op->speed); */ |
1956 | } |
1886 | } |
1957 | |
1887 | |
1958 | /* Attempts to kill 'op'. hitter is the attack object, dam is |
1888 | /* Attempts to kill 'op'. hitter is the attack object, dam is |
1959 | * the computed damaged. |
1889 | * the computed damaged. |
1960 | */ |
1890 | */ |
1961 | void |
1891 | static void |
1962 | deathstrike_player (object *op, object *hitter, int *dam) |
1892 | deathstrike_player (object *op, object *hitter, int *dam) |
1963 | { |
1893 | { |
1964 | /* The intention of a death attack is to kill outright things |
1894 | /* The intention of a death attack is to kill outright things |
1965 | ** that are a lot weaker than the attacker, have a chance of killing |
1895 | ** that are a lot weaker than the attacker, have a chance of killing |
1966 | ** things somewhat weaker than the caster, and no chance of |
1896 | ** things somewhat weaker than the caster, and no chance of |
… | |
… | |
1970 | ** field of the deathstriking object */ |
1900 | ** field of the deathstriking object */ |
1971 | |
1901 | |
1972 | int atk_lev, def_lev, kill_lev; |
1902 | int atk_lev, def_lev, kill_lev; |
1973 | |
1903 | |
1974 | if (hitter->slaying) |
1904 | if (hitter->slaying) |
1975 | if (!((QUERY_FLAG (op, FLAG_UNDEAD) && hitter->slaying.contains (shstr_undead)) |
1905 | if (!((op->flag [FLAG_UNDEAD] && hitter->slaying.contains (shstr_undead)) |
1976 | || (op->race && hitter->slaying.contains (op->race)))) |
1906 | || (op->race && hitter->slaying.contains (op->race)))) |
1977 | return; |
1907 | return; |
1978 | |
1908 | |
1979 | def_lev = op->level; |
1909 | def_lev = op->level; |
1980 | if (def_lev < 1) |
1910 | if (def_lev < 1) |
… | |
… | |
2097 | case ATNR_BLIND: |
2027 | case ATNR_BLIND: |
2098 | { |
2028 | { |
2099 | /* chance for inflicting a special attack depends on the |
2029 | /* chance for inflicting a special attack depends on the |
2100 | * difference between attacker's and defender's level |
2030 | * difference between attacker's and defender's level |
2101 | */ |
2031 | */ |
2102 | int level_diff = MIN (110, MAX (0, op->level - hitter->level)); |
2032 | int level_diff = min (110, max (0, op->level - hitter->level)); |
2103 | |
2033 | |
2104 | /* First, only creatures/players with speed can be affected. |
2034 | /* First, only creatures/players with speed can be affected. |
2105 | * Second, just getting hit doesn't mean it always affects |
2035 | * Second, just getting hit doesn't mean it always affects |
2106 | * you. Third, you still get a saving through against the |
2036 | * you. Third, you still get a saving through against the |
2107 | * effect. |
2037 | * effect. |
2108 | */ |
2038 | */ |
2109 | if (op->speed && |
2039 | if (op->has_active_speed () |
2110 | (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) && |
2040 | && (op->flag [FLAG_MONSTER] || op->type == PLAYER) |
|
|
2041 | && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) |
2111 | !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
2042 | && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
2112 | { |
2043 | { |
2113 | |
2044 | |
2114 | /* Player has been hit by something */ |
2045 | /* Player has been hit by something */ |
2115 | if (attacknum == ATNR_CONFUSION) |
2046 | if (attacknum == ATNR_CONFUSION) |
2116 | confuse_player (op, hitter, dam); |
2047 | confuse_player (op, hitter, dam); |
… | |
… | |
2124 | scare_creature (op, hitter); |
2055 | scare_creature (op, hitter); |
2125 | else if (attacknum == ATNR_CANCELLATION) |
2056 | else if (attacknum == ATNR_CANCELLATION) |
2126 | cancellation (op); |
2057 | cancellation (op); |
2127 | else if (attacknum == ATNR_DEPLETE) |
2058 | else if (attacknum == ATNR_DEPLETE) |
2128 | op->drain_stat (); |
2059 | op->drain_stat (); |
2129 | else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR)) |
2060 | else if (attacknum == ATNR_BLIND && !op->flag [FLAG_UNDEAD] && !op->flag [FLAG_GENERATOR]) |
2130 | blind_player (op, hitter, dam); |
2061 | blind_player (op, hitter, dam); |
2131 | } |
2062 | } |
2132 | |
2063 | |
2133 | dam = 0; /* These are all effects and don't do real damage */ |
2064 | dam = 0; /* These are all effects and don't do real damage */ |
2134 | } |
2065 | } |
… | |
… | |
2144 | { |
2075 | { |
2145 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2076 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2146 | { |
2077 | { |
2147 | if (tmp->invisible) |
2078 | if (tmp->invisible) |
2148 | continue; |
2079 | continue; |
2149 | if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) |
2080 | if (!tmp->flag [FLAG_APPLIED] || (tmp->resist[ATNR_ACID] >= 10)) |
2150 | /* >= 10% acid res. on items will protect these */ |
2081 | /* >= 10% acid res. on items will protect these */ |
2151 | continue; |
2082 | continue; |
2152 | if (!(tmp->materials & M_IRON)) |
2083 | if (!(tmp->materials & M_IRON)) |
2153 | continue; |
2084 | continue; |
2154 | if (tmp->magic < -4) /* Let's stop at -5 */ |
2085 | if (tmp->magic < -4) /* Let's stop at -5 */ |
… | |
… | |
2199 | rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); |
2130 | rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); |
2200 | |
2131 | |
2201 | if (op->stats.exp <= rate) |
2132 | if (op->stats.exp <= rate) |
2202 | { |
2133 | { |
2203 | if (op->type == GOLEM) |
2134 | if (op->type == GOLEM) |
2204 | dam = 999; /* Its force is "sucked" away. 8) */ |
2135 | dam = 9998; /* Its force is "sucked" away. 8) */ |
2205 | else |
2136 | else |
2206 | /* If we can't drain, lets try to do physical damage */ |
2137 | /* If we can't drain, lets try to do physical damage */ |
2207 | dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); |
2138 | dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); |
2208 | } |
2139 | } |
2209 | else |
2140 | else |
… | |
… | |
2218 | * exp, but the wiz would still lose exp! If drainee is a wiz, |
2149 | * exp, but the wiz would still lose exp! If drainee is a wiz, |
2219 | * nothing happens. |
2150 | * nothing happens. |
2220 | * Try to credit the owner. We try to display player -> player drain |
2151 | * Try to credit the owner. We try to display player -> player drain |
2221 | * attacks, hence all the != PLAYER checks. |
2152 | * attacks, hence all the != PLAYER checks. |
2222 | */ |
2153 | */ |
2223 | if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WIZ)) |
2154 | if (!op_on_battleground (hitter, NULL, NULL) && !op->flag [FLAG_WIZ]) |
2224 | { |
2155 | { |
2225 | object *owner = hitter->owner; |
2156 | object *owner = hitter->owner; |
2226 | |
2157 | |
2227 | if (owner && owner != hitter) |
2158 | if (owner && owner != hitter) |
2228 | { |
2159 | { |
2229 | if (op->type != PLAYER || owner->type != PLAYER) |
2160 | if (op->type != PLAYER || owner->type != PLAYER) |
2230 | change_exp (owner, op->stats.exp / (rate * 2), |
2161 | change_exp (owner, op->stats.exp / (rate * 2), |
2231 | hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL); |
2162 | hitter->chosen_skill ? hitter->chosen_skill->skill : shstr (), SK_EXP_TOTAL); |
2232 | } |
2163 | } |
2233 | else if (op->type != PLAYER || hitter->type != PLAYER) |
2164 | else if (op->type != PLAYER || hitter->type != PLAYER) |
2234 | change_exp (hitter, op->stats.exp / (rate * 2), |
2165 | change_exp (hitter, op->stats.exp / (rate * 2), |
2235 | hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); |
2166 | hitter->chosen_skill ? hitter->chosen_skill->skill : shstr (), 0); |
2236 | |
2167 | |
2237 | change_exp (op, -op->stats.exp / rate, NULL, 0); |
2168 | change_exp (op, -op->stats.exp / rate, shstr (), 0); |
2238 | } |
2169 | } |
2239 | |
2170 | |
2240 | dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure |
2171 | dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure |
2241 | * drain attack, you won't know that you are actually sucking out EXP, |
2172 | * drain attack, you won't know that you are actually sucking out EXP, |
2242 | * as the messages will say you missed |
2173 | * as the messages will say you missed |
… | |
… | |
2245 | } |
2176 | } |
2246 | break; |
2177 | break; |
2247 | |
2178 | |
2248 | case ATNR_TURN_UNDEAD: |
2179 | case ATNR_TURN_UNDEAD: |
2249 | { |
2180 | { |
2250 | if (QUERY_FLAG (op, FLAG_UNDEAD)) |
2181 | if (op->flag [FLAG_UNDEAD]) |
2251 | { |
2182 | { |
2252 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2183 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2253 | object *god = find_god (determine_god (owner)); |
2184 | object *god = find_god (determine_god (owner)); |
2254 | int div = 1; |
2185 | int div = 1; |
2255 | |
2186 | |
… | |
… | |
2310 | * damage it does do to the player. Given that, |
2241 | * damage it does do to the player. Given that, |
2311 | * it only does 1/10'th normal damage (hence the divide by |
2242 | * it only does 1/10'th normal damage (hence the divide by |
2312 | * 1000). |
2243 | * 1000). |
2313 | */ |
2244 | */ |
2314 | /* You can't steal life from something undead */ |
2245 | /* You can't steal life from something undead */ |
2315 | if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) |
2246 | if ((op->type == GOLEM) || (op->flag [FLAG_UNDEAD])) |
2316 | return 0; |
2247 | return 0; |
2317 | |
2248 | |
2318 | /* If drain protection is higher than life stealing, use that */ |
2249 | /* If drain protection is higher than life stealing, use that */ |
2319 | if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
2250 | if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
2320 | dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |
2251 | dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |