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,2013,2014,2015,2016 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 = op->material; |
43 | materialtype_t *mt = op->material; |
50 | |
44 | |
|
|
45 | // destroying objects without material has many bad effects |
|
|
46 | if (mt == MATERIAL_NULL) |
|
|
47 | return 1; |
|
|
48 | |
51 | roll = rndm (1, 20); |
49 | int roll = rndm (1, 20); |
52 | |
50 | |
53 | /* the attacktypes have no meaning for object saves |
51 | /* the attacktypes have no meaning for object saves |
54 | * 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 |
55 | * 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 |
56 | * is magic teamed with something else, then strip out the |
54 | * is magic teamed with something else, then strip out the |
57 | * magic type, and instead let the fire, cold, or whatever component |
55 | * magic type, and instead let the fire, cold, or whatever component |
58 | * destroy the item. Otherwise, you get the case of poisoncloud |
56 | * destroy the item. Otherwise, you get the case of poisoncloud |
59 | * destroying objects because it has magic attacktype. |
57 | * destroying objects because it has magic attacktype. |
60 | */ |
58 | */ |
61 | if (type != AT_MAGIC) |
59 | if (type != AT_MAGIC) |
62 | type &= ~(AT_CONFUSION | AT_DRAIN | AT_GHOSTHIT | AT_POISON | AT_SLOW | |
60 | type &= ~(AT_CONFUSION | AT_DRAIN | AT_GHOSTHIT | AT_POISON | AT_SLOW | |
63 | AT_PARALYZE | AT_TURN_UNDEAD | AT_FEAR | AT_DEPLETE | AT_DEATH | |
61 | AT_PARALYZE | AT_TURN_UNDEAD | AT_FEAR | AT_DEPLETE | AT_DEATH | |
64 | AT_COUNTERSPELL | AT_HOLYWORD | AT_BLIND | AT_LIFE_STEALING | AT_MAGIC); |
62 | AT_COUNTERSPELL | AT_HOLYWORD | AT_BLIND | AT_LIFE_STEALING | AT_MAGIC); |
65 | |
63 | |
|
|
64 | |
66 | if (type == 0) return TRUE; |
65 | if (type == 0) return TRUE; |
67 | |
66 | |
68 | if (roll == 20) return TRUE; |
67 | if (roll == 20) return TRUE; |
69 | if (roll == 1) return FALSE; |
68 | if (roll == 1) return FALSE; |
70 | |
69 | |
71 | for (number = 0; number < NROFATTACKS; number++) |
70 | for_all_bits_sparse_32 (type, number) |
72 | { |
71 | { |
73 | i = 1 << number; |
|
|
74 | |
|
|
75 | if (!(i & type)) |
|
|
76 | continue; |
|
|
77 | |
|
|
78 | attacks++; |
72 | attacks++; |
|
|
73 | |
79 | if (op->resist[number] == 100) |
74 | if (op->resist[number] == 100) |
80 | saves++; |
75 | saves++; |
81 | 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) |
82 | saves++; |
77 | saves++; |
83 | else if ((20 - mt->save[number]) / 3 > originator->stats.dam) |
78 | else if ((20 - mt->save[number]) / 3 > originator->stats.dam) |
… | |
… | |
100 | cancellation (object *op) |
95 | cancellation (object *op) |
101 | { |
96 | { |
102 | if (op->invisible) |
97 | if (op->invisible) |
103 | return; |
98 | return; |
104 | |
99 | |
105 | 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) |
106 | { |
101 | { |
107 | /* Recurse through the inventory */ |
102 | /* Recurse through the inventory */ |
108 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
103 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
109 | if (!did_make_save_item (tmp, AT_CANCELLATION, op)) |
104 | if (!did_make_save_item (tmp, AT_CANCELLATION, op)) |
110 | cancellation (tmp); |
105 | cancellation (tmp); |
… | |
… | |
113 | { |
108 | { |
114 | /* Nullify this object. This code could probably be more complete */ |
109 | /* Nullify this object. This code could probably be more complete */ |
115 | /* in what abilities it should cancel */ |
110 | /* in what abilities it should cancel */ |
116 | op->magic = 0; |
111 | op->magic = 0; |
117 | |
112 | |
118 | CLEAR_FLAG (op, FLAG_DAMNED); |
113 | op->clr_flag (FLAG_DAMNED); |
119 | CLEAR_FLAG (op, FLAG_CURSED); |
114 | op->clr_flag (FLAG_CURSED); |
120 | CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); |
115 | op->clr_flag (FLAG_KNOWN_MAGICAL); |
121 | CLEAR_FLAG (op, FLAG_KNOWN_CURSED); |
116 | op->clr_flag (FLAG_KNOWN_CURSED); |
122 | |
117 | |
123 | if (object *pl = op->visible_to ()) |
118 | if (object *pl = op->visible_to ()) |
124 | esrv_update_item (UPD_FLAGS, pl, op); |
119 | esrv_update_item (UPD_FLAGS, pl, op); |
125 | } |
120 | } |
126 | } |
121 | } |
… | |
… | |
130 | * calling cancellation, etc.) |
125 | * calling cancellation, etc.) |
131 | */ |
126 | */ |
132 | void |
127 | void |
133 | save_throw_object (object *op, int type, object *originator) |
128 | save_throw_object (object *op, int type, object *originator) |
134 | { |
129 | { |
|
|
130 | op = op->head_ (); |
|
|
131 | |
135 | if (!did_make_save_item (op, type, originator)) |
132 | if (!did_make_save_item (op, type, originator)) |
136 | { |
133 | { |
137 | object *env = op->env; |
134 | object *env = op->env; |
138 | int x = op->x, y = op->y; |
135 | int x = op->x, y = op->y; |
139 | maptile *m = op->map; |
136 | maptile *m = op->map; |
140 | |
137 | |
141 | op = stop_item (op); |
138 | op = stop_item (op); |
142 | if (!op) |
139 | if (!op) |
143 | return; |
140 | return; |
144 | |
141 | |
145 | /* Hacked the following so that type LIGHTER will work. |
142 | /* Hacked the following so that type LIGHTER will work. |
146 | * Also, objects which are potential "lights" that are hit by |
143 | * Also, objects which are potential "lights" that are hit by |
147 | * flame/elect attacks will be set to glow. "lights" are any |
144 | * flame/elect attacks will be set to glow. "lights" are any |
148 | * object with +/- glow_radius and an "other_arch" to change to. |
145 | * object with +/- glow_radius and an "other_arch" to change to. |
149 | * (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 |
150 | * function if the object doesnt contain a material that can burn. |
147 | * function if the object doesnt contain a material that can burn. |
151 | * So forget lighting magical swords on fire with this!) -b.t. |
148 | * So forget lighting magical swords on fire with this!) -b.t. |
152 | */ |
149 | */ |
153 | if (type & (AT_FIRE | AT_ELECTRICITY) |
150 | if (type & (AT_FIRE | AT_ELECTRICITY)) |
154 | && (QUERY_FLAG (op, FLAG_IS_LIGHTABLE) |
|
|
155 | || op->type == LAMP |
|
|
156 | || op->type == TORCH |
|
|
157 | )) |
151 | { |
158 | { |
152 | // seems LAMPs and TORCHes are always IS_LIGHTABLE? |
159 | switch (op->type) |
153 | if (op->type == LAMP || op->type == TORCH) |
160 | { |
154 | { |
161 | case LAMP: |
|
|
162 | case TORCH: |
|
|
163 | // turn on a lamp |
|
|
164 | apply_lamp (op, true); |
155 | apply_lamp (op, true); // turn on a lamp |
165 | break; |
156 | return; |
166 | |
|
|
167 | default: |
|
|
168 | // for instance icecubes: |
|
|
169 | if (op->other_arch) |
|
|
170 | { |
|
|
171 | const char *arch = op->other_arch->archname; |
|
|
172 | |
|
|
173 | if (op->decrease ()) |
|
|
174 | fix_stopped_item (op, m, originator); |
|
|
175 | |
|
|
176 | if ((op = archetype::get (arch))) |
|
|
177 | { |
|
|
178 | if (env) |
|
|
179 | env->insert (op); |
|
|
180 | else |
|
|
181 | m->insert (op, x, y, originator); |
|
|
182 | } |
|
|
183 | } |
|
|
184 | } |
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 | |
185 | return; |
176 | return; |
|
|
177 | } |
186 | } |
178 | } |
187 | |
179 | |
188 | if (type & AT_CANCELLATION) |
180 | if (type & AT_CANCELLATION) |
189 | { /* Cancellation. */ |
181 | { /* Cancellation. */ |
190 | cancellation (op); |
182 | cancellation (op); |
191 | fix_stopped_item (op, m, originator); |
183 | fix_stopped_item (op, m, originator); |
|
|
184 | |
192 | return; |
185 | return; |
193 | } |
|
|
194 | |
|
|
195 | if (op->nrof > 1) |
|
|
196 | { |
|
|
197 | if (op->decrease (rndm (0, op->nrof - 1))) |
|
|
198 | fix_stopped_item (op, m, originator); |
|
|
199 | } |
|
|
200 | else |
|
|
201 | { |
|
|
202 | // drop everything to the ground, if possible |
|
|
203 | op->insert_at (originator); |
|
|
204 | op->drop_and_destroy (); |
|
|
205 | } |
186 | } |
206 | |
187 | |
207 | if (type & (AT_FIRE | AT_ELECTRICITY)) |
188 | if (type & (AT_FIRE | AT_ELECTRICITY)) |
208 | if (env) |
189 | if (env) |
209 | { |
190 | { |
210 | op = archetype::get (shstr_burnout); |
191 | object *op = archetype::get (shstr_burnout); |
211 | op->x = env->x, op->y = env->y; |
192 | op->x = env->x, op->y = env->y; |
212 | env->insert (op); |
193 | env->insert (op); |
213 | } |
194 | } |
214 | else |
195 | else |
215 | replace_insert_ob_in_map (shstr_burnout, originator); |
196 | replace_insert_ob_in_map (shstr_burnout, originator); |
216 | |
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 | |
217 | return; |
210 | return; |
218 | } |
211 | } |
219 | |
212 | |
220 | /* The value of 50 is arbitrary. */ |
213 | /* The value of 50 is arbitrary. */ |
221 | 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)) |
222 | { |
215 | { |
223 | archetype *at = archetype::find (shstr_icecube); |
216 | archetype *at = archetype::find (shstr_icecube); |
224 | |
217 | |
225 | if (at == NULL) |
218 | if (at == NULL) |
226 | return; |
219 | return; |
… | |
… | |
230 | return; |
223 | return; |
231 | |
224 | |
232 | object *tmp = present_arch (at, op->map, op->x, op->y); |
225 | object *tmp = present_arch (at, op->map, op->x, op->y); |
233 | if (!tmp) |
226 | if (!tmp) |
234 | { |
227 | { |
235 | tmp = arch_to_object (at); |
228 | tmp = at->instance (); |
236 | tmp->x = op->x, tmp->y = op->y; |
229 | tmp->x = op->x, tmp->y = op->y; |
237 | /* This was in the old (pre new movement code) - |
230 | /* This was in the old (pre new movement code) - |
238 | * icecubes have slow_move set to 1 - don't want |
231 | * icecubes have slow_move set to 1 - don't want |
239 | * that for ones we create. |
232 | * that for ones we create. |
240 | */ |
233 | */ |
… | |
… | |
253 | * type is the attacktype of the object. |
246 | * type is the attacktype of the object. |
254 | * full_hit is set if monster area does not matter. |
247 | * full_hit is set if monster area does not matter. |
255 | * returns 1 if it hits something, 0 otherwise. |
248 | * returns 1 if it hits something, 0 otherwise. |
256 | */ |
249 | */ |
257 | int |
250 | int |
258 | hit_map (object *op, int dir, int type, int full_hit) |
251 | hit_map (object *op, int dir, uint32_t type, int full_hit) |
259 | { |
252 | { |
260 | maptile *map; |
|
|
261 | sint16 x, y; |
253 | sint16 x, y; |
262 | 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 */ |
263 | |
255 | |
264 | if (QUERY_FLAG (op, FLAG_FREED)) |
256 | if (op->flag [FLAG_FREED]) |
265 | { |
257 | { |
266 | LOG (llevError, "BUG: hit_map(): free object\n"); |
258 | LOG (llevError, "BUG: hit_map(): free object\n"); |
267 | return 0; |
259 | return 0; |
268 | } |
260 | } |
269 | |
261 | |
270 | if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL) |
262 | if (op->flag [FLAG_REMOVED] || op->env != NULL) |
271 | { |
263 | { |
272 | 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); |
273 | return 0; |
265 | return 0; |
274 | } |
266 | } |
275 | |
267 | |
… | |
… | |
339 | * 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. |
340 | */ |
332 | */ |
341 | 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) |
342 | continue; |
334 | continue; |
343 | |
335 | |
344 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
336 | if (tmp->flag [FLAG_ALIVE]) |
345 | { |
337 | { |
346 | hit_player (tmp, op->stats.dam, op, type, full_hit); |
338 | hit_player (tmp, op->stats.dam, op, type, full_hit); |
347 | retflag |= 1; |
339 | retflag |= 1; |
348 | |
340 | |
349 | if (op->destroyed ()) |
341 | if (op->destroyed ()) |
350 | break; |
342 | break; |
351 | } |
343 | } |
352 | /* Here we are potentially destroying an object. If the object has |
344 | /* Here we are potentially destroying an object. If the object has |
353 | * 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 |
354 | * that weak walls have is_alive set, which prevent objects from |
346 | * that weak walls have is_alive set, which prevent objects from |
355 | * 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 |
356 | * 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 |
357 | * 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. |
358 | */ |
352 | */ |
359 | else if (op->stats.dam > 0 && !tmp->move_block) |
353 | else if (op->stats.dam > 0 && !tmp->move_block && tmp->material != MATERIAL_NULL) |
360 | { |
354 | { |
361 | save_throw_object (tmp, type, op); |
355 | save_throw_object (tmp, type, op); |
362 | |
356 | |
363 | if (op->destroyed ()) |
357 | if (op->destroyed ()) |
364 | break; |
358 | break; |
365 | } |
359 | } |
366 | } |
360 | } |
367 | |
361 | |
368 | return 0; |
362 | return retflag; |
369 | } |
363 | } |
370 | |
364 | |
371 | static void |
365 | static void |
372 | attack_message (int dam, int type, object *op, object *hitter) |
366 | attack_message (int dam, int type, object *op, object *hitter) |
373 | { |
367 | { |
… | |
… | |
522 | { |
516 | { |
523 | int mtype; |
517 | int mtype; |
524 | |
518 | |
525 | switch (hitter->current_weapon->weapontype) |
519 | switch (hitter->current_weapon->weapontype) |
526 | { |
520 | { |
527 | case WEAP_HIT: |
521 | case WEAP_HIT: mtype = ATM_BASIC; break; |
528 | mtype = ATM_BASIC; |
522 | case WEAP_SLASH: mtype = ATM_SLASH; break; |
529 | break; |
523 | case WEAP_PIERCE: mtype = ATM_PIERCE; break; |
530 | case WEAP_SLASH: |
524 | case WEAP_CLEAVE: mtype = ATM_CLEAVE; break; |
531 | mtype = ATM_SLASH; |
525 | case WEAP_SLICE: mtype = ATM_SLICE; break; |
532 | break; |
526 | case WEAP_STAB: mtype = ATM_STAB; break; |
533 | case WEAP_PIERCE: |
527 | case WEAP_WHIP: mtype = ATM_WHIP; break; |
534 | mtype = ATM_PIERCE; |
528 | case WEAP_CRUSH: mtype = ATM_CRUSH; break; |
535 | break; |
529 | case WEAP_BLUD: mtype = ATM_BLUD; break; |
536 | case WEAP_CLEAVE: |
530 | default: mtype = ATM_BASIC; break; |
537 | mtype = ATM_CLEAVE; |
|
|
538 | break; |
|
|
539 | case WEAP_SLICE: |
|
|
540 | mtype = ATM_SLICE; |
|
|
541 | break; |
|
|
542 | case WEAP_STAB: |
|
|
543 | mtype = ATM_STAB; |
|
|
544 | break; |
|
|
545 | case WEAP_WHIP: |
|
|
546 | mtype = ATM_WHIP; |
|
|
547 | break; |
|
|
548 | case WEAP_CRUSH: |
|
|
549 | mtype = ATM_CRUSH; |
|
|
550 | break; |
|
|
551 | case WEAP_BLUD: |
|
|
552 | mtype = ATM_BLUD; |
|
|
553 | break; |
|
|
554 | default: |
|
|
555 | mtype = ATM_BASIC; |
|
|
556 | break; |
|
|
557 | } |
531 | } |
558 | |
532 | |
559 | 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++) |
560 | 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) |
561 | { |
535 | { |
… | |
… | |
667 | } |
641 | } |
668 | |
642 | |
669 | static int |
643 | static int |
670 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
644 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
671 | { |
645 | { |
672 | if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) |
646 | if ((*target)->flag [FLAG_FREED] || (*hitter)->flag [FLAG_FREED]) |
673 | { |
647 | { |
674 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
648 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
675 | return 1; |
649 | return 1; |
676 | } |
650 | } |
677 | |
651 | |
… | |
… | |
685 | { |
659 | { |
686 | *simple_attack = 1; |
660 | *simple_attack = 1; |
687 | return 0; |
661 | return 0; |
688 | } |
662 | } |
689 | |
663 | |
690 | if (QUERY_FLAG (*target, FLAG_REMOVED) |
664 | if ((*target)->flag [FLAG_REMOVED] |
691 | || QUERY_FLAG (*hitter, FLAG_REMOVED) |
665 | || (*hitter)->flag [FLAG_REMOVED] |
692 | || !(*hitter)->map |
666 | || !(*hitter)->map |
693 | || !on_same_map (*hitter, *target)) |
667 | || !on_same_map (*hitter, *target)) |
694 | { |
668 | { |
695 | 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", |
696 | (*hitter)->debug_desc (), (*target)->debug_desc ()); |
670 | (*hitter)->debug_desc (), (*target)->debug_desc ()); |
… | |
… | |
709 | */ |
683 | */ |
710 | int new_mode; |
684 | int new_mode; |
711 | |
685 | |
712 | if (hitter->env == target || target->env == hitter) |
686 | if (hitter->env == target || target->env == hitter) |
713 | new_mode = 1; |
687 | new_mode = 1; |
714 | else if (QUERY_FLAG (hitter, FLAG_REMOVED) || QUERY_FLAG (target, FLAG_REMOVED) |
688 | else if (hitter->flag [FLAG_REMOVED] || target->flag [FLAG_REMOVED] |
715 | || hitter->map == NULL || !on_same_map (hitter, target)) |
689 | || hitter->map == NULL || !on_same_map (hitter, target)) |
716 | return 1; |
690 | return 1; |
717 | else |
691 | else |
718 | new_mode = 0; |
692 | new_mode = 0; |
719 | |
693 | |
… | |
… | |
725 | * monster). |
699 | * monster). |
726 | */ |
700 | */ |
727 | static void |
701 | static void |
728 | thrown_item_effect (object *hitter, object *victim) |
702 | thrown_item_effect (object *hitter, object *victim) |
729 | { |
703 | { |
730 | if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
704 | if (!hitter->flag [FLAG_ALIVE]) |
731 | { |
705 | { |
732 | /* 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 |
733 | * easier for expansion. |
707 | * easier for expansion. |
734 | */ |
708 | */ |
735 | switch (hitter->type) |
709 | switch (hitter->type) |
736 | { |
710 | { |
737 | case POTION: |
711 | case POTION: |
738 | /* should player get a save throw instead of checking magic protection? */ |
712 | /* should player get a save throw instead of checking magic protection? */ |
739 | 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)) |
740 | (void) apply_potion (victim, hitter); |
714 | apply_potion (victim, hitter); |
741 | break; |
715 | break; |
742 | |
716 | |
743 | case POISON: /* poison drinks */ |
717 | case POISON: /* poison drinks */ |
744 | /* As with potions, should monster get a save? */ |
718 | /* As with potions, should monster get a save? */ |
745 | 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)) |
746 | apply_poison (victim, hitter); |
720 | apply_poison (victim, hitter); |
747 | break; |
721 | break; |
748 | |
722 | |
749 | /* Removed case statements that did nothing. |
723 | /* Removed case statements that did nothing. |
750 | * 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, |
… | |
… | |
757 | |
731 | |
758 | /* determine if the object is an 'aimed' missile */ |
732 | /* determine if the object is an 'aimed' missile */ |
759 | static int |
733 | static int |
760 | is_aimed_missile (object *op) |
734 | is_aimed_missile (object *op) |
761 | { |
735 | { |
762 | |
|
|
763 | /* 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 |
764 | * ones so that figuring out the logic is at least possible. |
737 | * ones so that figuring out the logic is at least possible. |
765 | */ |
738 | */ |
766 | if (op && (op->move_type & MOVE_FLYING)) |
739 | if (op && (op->move_type & MOVE_FLYING)) |
767 | if (op->type == ARROW || op->type == THROWN_OBJ) |
740 | if (op->type == ARROW || op->type == THROWN_OBJ) |
… | |
… | |
791 | if ((attacker = hitter->owner) == NULL) |
764 | if ((attacker = hitter->owner) == NULL) |
792 | attacker = hitter; |
765 | attacker = hitter; |
793 | /* 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 |
794 | * owned by him - need to handle that case to avoid crashes. |
767 | * owned by him - need to handle that case to avoid crashes. |
795 | */ |
768 | */ |
796 | if (QUERY_FLAG (attacker, FLAG_REMOVED)) |
769 | if (attacker->flag [FLAG_REMOVED]) |
797 | attacker = hitter; |
770 | attacker = hitter; |
798 | } |
771 | } |
799 | else if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
772 | else if (!hitter->flag [FLAG_ALIVE]) |
800 | return 0; |
773 | return 0; |
801 | |
774 | |
802 | /* determine the condtions under which we make an attack. |
775 | /* determine the condtions under which we make an attack. |
803 | * Add more cases, as the need occurs. */ |
776 | * Add more cases, as the need occurs. */ |
804 | |
777 | |
805 | if (!can_see_enemy (attacker, target)) |
778 | if (!can_see_enemy (attacker, target)) |
806 | { |
779 | { |
807 | /* target is unseen */ |
780 | /* target is unseen */ |
808 | if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) |
781 | if (target->invisible || attacker->flag [FLAG_BLIND]) |
809 | adjust -= 10; |
782 | adjust -= 10; |
810 | /* 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). */ |
811 | else if (!stand_in_light (target)) |
784 | else if (!stand_in_light (target)) |
812 | adjust -= target->map->darklevel (); |
785 | adjust -= target->map->darklevel (); |
813 | } |
786 | } |
814 | |
787 | |
815 | if (QUERY_FLAG (attacker, FLAG_SCARED)) |
788 | if (attacker->flag [FLAG_SCARED]) |
816 | adjust -= 3; |
789 | adjust -= 3; |
817 | |
790 | |
818 | if (QUERY_FLAG (target, FLAG_UNAGGRESSIVE)) |
791 | if (target->flag [FLAG_UNAGGRESSIVE]) |
819 | adjust += 1; |
792 | adjust += 1; |
820 | |
793 | |
821 | if (QUERY_FLAG (target, FLAG_SCARED)) |
794 | if (target->flag [FLAG_SCARED]) |
822 | adjust += 1; |
795 | adjust += 1; |
823 | |
796 | |
824 | if (QUERY_FLAG (attacker, FLAG_CONFUSED)) |
797 | if (attacker->flag [FLAG_CONFUSED]) |
825 | adjust -= 3; |
798 | adjust -= 3; |
826 | |
799 | |
827 | /* if we attack at a different 'altitude' its harder */ |
800 | /* if we attack at a different 'altitude' its harder */ |
828 | if ((attacker->move_type & target->move_type) == 0) |
801 | if ((attacker->move_type & target->move_type) == 0) |
829 | adjust -= 2; |
802 | adjust -= 2; |
… | |
… | |
865 | |
838 | |
866 | /* |
839 | /* |
867 | * 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 |
868 | * to avoid ever being hit by monsters. |
841 | * to avoid ever being hit by monsters. |
869 | */ |
842 | */ |
870 | 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) |
871 | { |
844 | { |
872 | /* Decrease speed BEFORE calling process_object. Otherwise, an |
845 | /* Decrease speed BEFORE calling process_object. Otherwise, an |
873 | * infinite loop occurs, with process_object calling move_monster, |
846 | * infinite loop occurs, with process_object calling move_monster, |
874 | * which then gets here again. By decreasing the speed before |
847 | * which then gets here again. By decreasing the speed before |
875 | * we call process_object, the 'if' statement above will fail. |
848 | * we call process_object, the 'if' statement above will fail. |
… | |
… | |
895 | int hitdam = base_dam; |
868 | int hitdam = base_dam; |
896 | |
869 | |
897 | if (!simple_attack) |
870 | if (!simple_attack) |
898 | { |
871 | { |
899 | /* If you hit something, the victim should *always* wake up. |
872 | /* If you hit something, the victim should *always* wake up. |
900 | * Before, invisible hitters could avoid doing this. |
873 | * Before, invisible hitters could avoid doing this. |
901 | * -b.t. */ |
874 | * -b.t. */ |
902 | if (QUERY_FLAG (op, FLAG_SLEEP)) |
875 | if (op->flag [FLAG_SLEEP]) |
903 | CLEAR_FLAG (op, FLAG_SLEEP); |
876 | op->clr_flag (FLAG_SLEEP); |
904 | |
877 | |
905 | /* 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 |
906 | * for help. */ |
879 | * for help. */ |
907 | 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)) |
908 | npc_call_help (op); |
881 | npc_call_help (op); |
… | |
… | |
928 | } |
901 | } |
929 | |
902 | |
930 | /* 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 |
931 | * to go further and it will cause FPE's below. |
904 | * to go further and it will cause FPE's below. |
932 | */ |
905 | */ |
933 | if (hitdam <= 0) |
906 | max_it (hitdam, 1); |
934 | hitdam = 1; |
|
|
935 | |
907 | |
936 | type = hitter->attacktype; |
908 | type = hitter->attacktype; |
937 | |
909 | |
938 | /* 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* |
939 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
911 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
940 | * This check is important for the most simple monsters out there in the |
912 | * This check is important for the most simple monsters out there in the |
941 | * game content (maps, archs). For example orcs: They would have |
913 | * game content (maps, archs). For example orcs: They would have |
942 | * no attacktype at all. |
914 | * no attacktype at all. |
943 | * |
915 | * |
944 | * Some time in the future someone should just go into the game data |
916 | * Some time in the future someone should just go into the game data |
945 | * and fix every monster out there ;-/ Until then we will kill some |
917 | * and fix every monster out there ;-/ Until then we will kill some |
946 | * more trees in the african rain forests with this check. |
918 | * more trees in the african rain forests with this check. |
947 | */ |
919 | */ |
948 | if (!type) |
920 | if (!type) |
949 | type = AT_PHYSICAL; |
921 | type = AT_PHYSICAL; |
950 | |
922 | |
951 | /* Handle monsters that hit back */ |
923 | /* Handle monsters that hit back */ |
952 | 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]) |
953 | { |
925 | { |
954 | if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
926 | if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
955 | 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"); |
956 | |
928 | |
957 | 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); |
… | |
… | |
983 | } |
955 | } |
984 | |
956 | |
985 | int |
957 | int |
986 | attack_ob (object *op, object *hitter) |
958 | attack_ob (object *op, object *hitter) |
987 | { |
959 | { |
988 | hitter = hitter->head_ (); |
|
|
989 | |
|
|
990 | 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); |
991 | } |
961 | } |
992 | |
962 | |
993 | /* op is the arrow, tmp is what is stopping the arrow. |
963 | /* op is the arrow, tmp is what is stopping the arrow. |
994 | * |
964 | * |
995 | * 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. |
… | |
… | |
1048 | * arrow, move_apply() calls this function, arrow sticks in demon, |
1018 | * arrow, move_apply() calls this function, arrow sticks in demon, |
1049 | * attack_ob_simple() returns, and we've got an arrow that still exists |
1019 | * attack_ob_simple() returns, and we've got an arrow that still exists |
1050 | * but is no longer on the map. Ugh. (Beware: Such things can happen at |
1020 | * but is no longer on the map. Ugh. (Beware: Such things can happen at |
1051 | * other places as well!) |
1021 | * other places as well!) |
1052 | */ |
1022 | */ |
1053 | if (hitter->destroyed () || hitter->env != NULL) |
1023 | if (hitter->destroyed () || hitter->env) |
1054 | { |
1024 | { |
1055 | if (container) |
1025 | if (container) |
1056 | container->destroy (); |
1026 | container->destroy (); |
1057 | |
1027 | |
1058 | return 0; |
1028 | return 0; |
1059 | } |
1029 | } |
1060 | |
1030 | |
1061 | /* Missile hit victim */ |
1031 | /* Missile hit victim */ |
1062 | /* if the speed is > 10, then this is a fast moving arrow, we go straight |
1032 | /* if the speed is >= 10, then this is a fast moving arrow, we go straight |
1063 | * through the target |
1033 | * through the target |
1064 | */ |
1034 | */ |
1065 | if (hit_something && op->speed <= 10.0) |
1035 | if (hit_something) |
|
|
1036 | if (op->speed < 10.0) |
1066 | { |
1037 | { |
1067 | /* Stop arrow */ |
1038 | /* Stop arrow */ |
1068 | if (!container) |
1039 | if (container) |
|
|
1040 | container->destroy (); |
|
|
1041 | else |
1069 | { |
1042 | { |
1070 | hitter = fix_stopped_arrow (hitter); |
1043 | hitter = fix_stopped_arrow (hitter); |
1071 | if (!hitter) |
1044 | if (!hitter) |
1072 | return 0; |
1045 | return 0; |
1073 | } |
1046 | } |
1074 | else |
|
|
1075 | container->destroy (); |
|
|
1076 | |
1047 | |
1077 | /* Try to stick arrow into victim */ |
1048 | /* Try to stick arrow into victim */ |
1078 | if (!victim->destroyed () && stick_arrow (hitter, victim)) |
1049 | if (!victim->destroyed () && stick_arrow (hitter, victim)) |
|
|
1050 | return 0; |
|
|
1051 | |
|
|
1052 | /* Else try to put arrow on victim's map square |
|
|
1053 | * remove check for P_WALL here. If the arrow got to this |
|
|
1054 | * space, that is good enough - with the new movement code, |
|
|
1055 | * there is now the potential for lots of spaces where something |
|
|
1056 | * can fly over but not otherwise move over. What is the correct |
|
|
1057 | * way to handle those otherwise? |
|
|
1058 | */ |
|
|
1059 | if (victim->x != hitter->x || victim->y != hitter->y) |
|
|
1060 | { |
|
|
1061 | if (victim->destroyed ()) |
|
|
1062 | hitter->destroy (); |
|
|
1063 | else |
|
|
1064 | { |
|
|
1065 | hitter->remove (); |
|
|
1066 | hitter->x = victim->x; |
|
|
1067 | hitter->y = victim->y; |
|
|
1068 | insert_ob_in_map (hitter, victim->map, hitter, 0); |
|
|
1069 | } |
|
|
1070 | } |
|
|
1071 | else |
|
|
1072 | /* Else leave arrow where it is */ |
|
|
1073 | merge_ob (hitter, NULL); |
|
|
1074 | |
1079 | return 0; |
1075 | return 0; |
1080 | |
|
|
1081 | /* Else try to put arrow on victim's map square |
|
|
1082 | * remove check for P_WALL here. If the arrow got to this |
|
|
1083 | * space, that is good enough - with the new movement code, |
|
|
1084 | * there is now the potential for lots of spaces where something |
|
|
1085 | * can fly over but not otherwise move over. What is the correct |
|
|
1086 | * way to handle those otherwise? |
|
|
1087 | */ |
|
|
1088 | if (victim->x != hitter->x || victim->y != hitter->y) |
|
|
1089 | { |
|
|
1090 | if (victim->destroyed ()) |
|
|
1091 | hitter->destroy (); |
|
|
1092 | else |
|
|
1093 | { |
|
|
1094 | hitter->remove (); |
|
|
1095 | hitter->x = victim->x; |
|
|
1096 | hitter->y = victim->y; |
|
|
1097 | insert_ob_in_map (hitter, victim->map, hitter, 0); |
|
|
1098 | } |
|
|
1099 | } |
1076 | } |
1100 | else |
1077 | else |
1101 | /* Else leave arrow where it is */ |
1078 | op->set_speed (op->speed - 1.f); |
1102 | merge_ob (hitter, NULL); |
|
|
1103 | |
|
|
1104 | return 0; |
|
|
1105 | } |
|
|
1106 | |
|
|
1107 | if (hit_something && op->speed >= 10.0) |
|
|
1108 | op->speed -= 1.0; |
|
|
1109 | |
1079 | |
1110 | /* Missile missed victim - reassemble missile */ |
1080 | /* Missile missed victim - reassemble missile */ |
1111 | if (container) |
1081 | if (container) |
1112 | { |
1082 | { |
1113 | hitter->remove (); |
1083 | hitter->remove (); |
… | |
… | |
1181 | * MSW 2002-07-17 |
1151 | * MSW 2002-07-17 |
1182 | */ |
1152 | */ |
1183 | int |
1153 | int |
1184 | kill_object (object *op, int dam, object *hitter, int type) |
1154 | kill_object (object *op, int dam, object *hitter, int type) |
1185 | { |
1155 | { |
1186 | char buf[MAX_BUF]; |
|
|
1187 | shstr skill; |
1156 | shstr skill; |
1188 | int maxdam = 0; |
1157 | int maxdam = 0; |
1189 | int battleg = 0; /* true if op standing on battleground */ |
1158 | int battleg = 0; /* true if op standing on battleground */ |
1190 | 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 */ |
1191 | object *owner = 0; |
1160 | object *owner = 0; |
… | |
… | |
1201 | * this creature. The function(s) that call us have already |
1170 | * this creature. The function(s) that call us have already |
1202 | * adjusted the creatures HP total, so that is negative. |
1171 | * adjusted the creatures HP total, so that is negative. |
1203 | */ |
1172 | */ |
1204 | maxdam = dam + op->stats.hp + 1; |
1173 | maxdam = dam + op->stats.hp + 1; |
1205 | |
1174 | |
1206 | if (QUERY_FLAG (op, FLAG_BLOCKSVIEW)) |
1175 | if (op->flag [FLAG_BLOCKSVIEW]) |
1207 | 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 */ |
1208 | |
1177 | |
1209 | if (op->type == DOOR) |
1178 | if (op->type == DOOR) |
1210 | { |
1179 | { |
1211 | op->set_speed (0.1f); |
1180 | op->set_speed (0.1f); |
1212 | op->speed_left = -0.05f; |
1181 | op->speed_left = -0.05f; |
1213 | return maxdam; |
1182 | return maxdam; |
1214 | } |
1183 | } |
1215 | |
1184 | |
1216 | if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) |
1185 | if (op->flag [FLAG_FRIENDLY] && op->type != PLAYER) |
1217 | { |
1186 | { |
1218 | op->drop_and_destroy (); |
1187 | op->drop_and_destroy (); |
1219 | return maxdam; |
1188 | return maxdam; |
1220 | } |
1189 | } |
1221 | |
1190 | |
… | |
… | |
1268 | owner->play_sound (sound_find ("player_kills")); |
1237 | owner->play_sound (sound_find ("player_kills")); |
1269 | } |
1238 | } |
1270 | |
1239 | |
1271 | /* If a player kills another player, not on |
1240 | /* If a player kills another player, not on |
1272 | * battleground, the "killer" looses 1 luck. Since this is |
1241 | * battleground, the "killer" looses 1 luck. Since this is |
1273 | * not reversible, it's actually quite a pain IMHO. -AV |
1242 | * not reversible, it's actually quite a pain IMHO. -AV |
1274 | * Fix bug in that we were changing the luck of the hitter, not |
1243 | * Fix bug in that we were changing the luck of the hitter, not |
1275 | * player that the object belonged to - so if you killed another player |
1244 | * player that the object belonged to - so if you killed another player |
1276 | * with spells, pets, whatever, there was no penalty. |
1245 | * with spells, pets, whatever, there was no penalty. |
1277 | * Changed to make luck penalty configurable in settings. |
1246 | * Changed to make luck penalty configurable in settings. |
1278 | */ |
1247 | */ |
… | |
… | |
1288 | else if (owner->chosen_skill) |
1257 | else if (owner->chosen_skill) |
1289 | { |
1258 | { |
1290 | skop = owner->chosen_skill; |
1259 | skop = owner->chosen_skill; |
1291 | skill = skop->skill; |
1260 | skill = skop->skill; |
1292 | } |
1261 | } |
1293 | else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon) |
1262 | else if (owner->flag [FLAG_READY_WEAPON] && owner->current_weapon) |
1294 | skill = owner->current_weapon->skill; |
1263 | skill = owner->current_weapon->skill; |
1295 | else |
1264 | else |
1296 | { |
1265 | { |
|
|
1266 | LOG (llevError | logBacktrace, |
1297 | 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" |
1298 | "op: %s\n" "hitter: %s\n" "owner: %s\n", |
1268 | "op: %s\n" "hitter: %s\n" "op: %s\n", |
1299 | owner->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
1269 | op->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
1300 | skill = 0; |
1270 | skill = 0; |
1301 | } |
1271 | } |
1302 | |
1272 | |
1303 | /* 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 |
1304 | * 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! |
… | |
… | |
1314 | |
1284 | |
1315 | if (!skill && skop) |
1285 | if (!skill && skop) |
1316 | skill = skop->skill; |
1286 | skill = skop->skill; |
1317 | |
1287 | |
1318 | /* If you didn't kill yourself, and your not the wizard */ |
1288 | /* If you didn't kill yourself, and your not the wizard */ |
1319 | if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) |
1289 | if (owner != op && !op->flag [FLAG_WIZ]) |
1320 | { |
1290 | { |
1321 | int exp; |
1291 | int exp; |
1322 | |
1292 | |
1323 | /* Really don't give much experience for killing other players */ |
1293 | /* Really don't give much experience for killing other players */ |
1324 | // schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
1294 | // schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
… | |
… | |
1381 | } /* else part of a party */ |
1351 | } /* else part of a party */ |
1382 | } /* end if person didn't kill himself */ |
1352 | } /* end if person didn't kill himself */ |
1383 | |
1353 | |
1384 | if (op->type != PLAYER) |
1354 | if (op->type != PLAYER) |
1385 | { |
1355 | { |
1386 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
1356 | if (op->flag [FLAG_FRIENDLY]) |
1387 | { |
1357 | { |
1388 | object *owner1 = op->owner; |
1358 | object *owner1 = op->owner; |
1389 | |
1359 | |
1390 | if (owner1 && owner1->type == PLAYER) |
1360 | if (owner1 && owner1->type == PLAYER) |
1391 | { |
1361 | { |
… | |
… | |
1407 | * continues in the calling function. |
1377 | * continues in the calling function. |
1408 | */ |
1378 | */ |
1409 | return maxdam; |
1379 | return maxdam; |
1410 | } |
1380 | } |
1411 | |
1381 | |
1412 | /* Find out if this is friendly fire (PVP and attacker is peaceful) or not |
1382 | /* Find out if this is friendly fire (PVP and attacker is peaceful) or not |
1413 | * Returns 0 this is not friendly fire |
1383 | * Returns 0 this is not friendly fire |
1414 | */ |
1384 | */ |
1415 | int |
1385 | int |
1416 | friendly_fire (object *op, object *hitter) |
1386 | friendly_fire (object *op, object *hitter) |
1417 | { |
1387 | { |
… | |
… | |
1452 | * modify it. |
1422 | * modify it. |
1453 | */ |
1423 | */ |
1454 | /* Oct 95 - altered the following slightly for MULTIPLE_GODS hack |
1424 | /* Oct 95 - altered the following slightly for MULTIPLE_GODS hack |
1455 | * which needs new attacktype AT_HOLYWORD to work . b.t. */ |
1425 | * which needs new attacktype AT_HOLYWORD to work . b.t. */ |
1456 | int |
1426 | int |
1457 | 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) |
1458 | { |
1428 | { |
1459 | int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC); |
1429 | int magic = type & AT_MAGIC; |
1460 | int maxattacktype, attacknum; |
|
|
1461 | 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; |
1462 | int simple_attack; |
1433 | int simple_attack; |
1463 | int rtn_kill = 0; |
1434 | int rtn_kill = 0; |
1464 | int friendlyfire; |
1435 | int friendlyfire; |
1465 | |
1436 | |
1466 | if (get_attack_mode (&op, &hitter, &simple_attack)) |
1437 | if (get_attack_mode (&op, &hitter, &simple_attack)) |
1467 | return 0; |
1438 | return 0; |
1468 | |
1439 | |
1469 | /* 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 */ |
1470 | if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE)) |
1441 | if (op->flag [FLAG_WIZ] || op->flag [FLAG_NO_DAMAGE]) |
1471 | return 0; |
1442 | return 0; |
1472 | |
1443 | |
1473 | // only allow pk for hostile players |
1444 | // only allow pk for hostile players |
1474 | if (op->type == PLAYER) |
1445 | if (op->type == PLAYER) |
1475 | { |
1446 | { |
… | |
… | |
1517 | |
1488 | |
1518 | break; |
1489 | break; |
1519 | } |
1490 | } |
1520 | } |
1491 | } |
1521 | |
1492 | |
1522 | if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) |
1493 | if (!op->flag [FLAG_ALIVE] || op->stats.hp < 0) |
1523 | { |
1494 | { |
1524 | /* 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 |
1525 | * destroyed() check above doesn't return, and might get here. |
1496 | * destroyed() check above doesn't return, and might get here. |
1526 | */ |
1497 | */ |
1527 | |
1498 | |
… | |
… | |
1568 | object *god; |
1539 | object *god; |
1569 | |
1540 | |
1570 | if ((!hitter->slaying |
1541 | if ((!hitter->slaying |
1571 | || (!(op->race && hitter->slaying.contains (op->race)) |
1542 | || (!(op->race && hitter->slaying.contains (op->race)) |
1572 | && !(op->name && hitter->slaying.contains (op->name)))) |
1543 | && !(op->name && hitter->slaying.contains (op->name)))) |
1573 | && (!QUERY_FLAG (op, FLAG_UNDEAD) |
1544 | && (!op->flag [FLAG_UNDEAD] |
1574 | || (hitter->title |
1545 | || (hitter->title |
1575 | && (god = find_god (determine_god (hitter))) != NULL |
1546 | && (god = find_god (determine_god (hitter))) != NULL |
1576 | && god->race.contains (shstr_undead)))) |
1547 | && god->race.contains (shstr_undead)))) |
1577 | return 0; |
1548 | return 0; |
1578 | } |
1549 | } |
1579 | |
1550 | |
1580 | maxattacktype = type; /* initialise this to something */ |
1551 | maxattacktype = type; /* initialise this to something */ |
1581 | for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) |
1552 | for_all_bits_sparse_32 (type, attacknum) |
1582 | { |
1553 | { |
|
|
1554 | uint32_t attacktype = 1 << attacknum; |
|
|
1555 | |
1583 | /* 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 |
1584 | * attack types. As such, skip it over. However, if magic is |
1557 | * attack types. As such, skip it over. However, if magic is |
1585 | * the only attacktype in the group, then still attack with it |
1558 | * the only attacktype in the group, then still attack with it |
1586 | */ |
1559 | */ |
1587 | if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC)) |
1560 | if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC)) |
… | |
… | |
1590 | /* 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. |
1591 | * hit_player_attacktype only figures out the damage, doesn't inflict |
1564 | * hit_player_attacktype only figures out the damage, doesn't inflict |
1592 | * it. It will do the appropriate action for attacktypes with |
1565 | * it. It will do the appropriate action for attacktypes with |
1593 | * effects (slow, paralization, etc. |
1566 | * effects (slow, paralization, etc. |
1594 | */ |
1567 | */ |
1595 | if (type & attacktype) |
|
|
1596 | { |
|
|
1597 | ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic); |
1568 | ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic); |
|
|
1569 | |
1598 | /* the >= causes us to prefer messages from special attacks, if |
1570 | /* the >= causes us to prefer messages from special attacks, if |
1599 | * the damage is equal. |
1571 | * the damage is equal. |
1600 | */ |
1572 | */ |
1601 | if (ndam >= maxdam) |
1573 | if (ndam >= maxdam) |
1602 | { |
1574 | { |
1603 | maxdam = ndam; |
1575 | maxdam = ndam; |
1604 | maxattacktype = 1 << attacknum; |
1576 | maxattacktype = 1 << attacknum; |
1605 | } |
|
|
1606 | } |
1577 | } |
1607 | } |
1578 | } |
1608 | |
1579 | |
1609 | /* 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 |
1610 | * 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 |
… | |
… | |
1650 | // 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 |
1651 | // for an non-active objetc to know its enemy. |
1622 | // for an non-active objetc to know its enemy. |
1652 | if (op->active) |
1623 | if (op->active) |
1653 | if (hitter->owner) |
1624 | if (hitter->owner) |
1654 | op->enemy = hitter->owner; |
1625 | op->enemy = hitter->owner; |
1655 | else if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
1626 | else if (hitter->flag [FLAG_ALIVE]) |
1656 | op->enemy = hitter; |
1627 | op->enemy = hitter; |
1657 | |
1628 | |
1658 | if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) |
1629 | if (op->flag [FLAG_UNAGGRESSIVE] && op->type != PLAYER) |
1659 | { |
1630 | { |
1660 | /* The unaggressives look after themselves 8) */ |
1631 | /* The unaggressives look after themselves 8) */ |
1661 | CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); |
1632 | op->clr_flag (FLAG_UNAGGRESSIVE); |
1662 | npc_call_help (op); |
1633 | npc_call_help (op); |
1663 | } |
1634 | } |
1664 | |
1635 | |
1665 | if (magic && did_make_save (op, op->level, 0)) |
1636 | if (magic && did_make_save (op, op->level, 0)) |
1666 | maxdam = maxdam / 2; |
1637 | maxdam = maxdam / 2; |
… | |
… | |
1668 | attack_message (maxdam, maxattacktype, op, hitter); |
1639 | attack_message (maxdam, maxattacktype, op, hitter); |
1669 | |
1640 | |
1670 | op->stats.hp -= maxdam; |
1641 | op->stats.hp -= maxdam; |
1671 | |
1642 | |
1672 | /* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
1643 | /* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
1673 | if ((op->stats.hp >= 0) && |
1644 | if (op->stats.hp >= 0 |
1674 | (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) && |
1645 | && (op->flag [FLAG_MONSTER] || op->type == PLAYER) |
1675 | 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) |
1676 | { |
1647 | { |
1677 | |
1648 | |
1678 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1649 | if (op->flag [FLAG_MONSTER]) |
1679 | SET_FLAG (op, FLAG_RUN_AWAY); |
1650 | op->set_flag (FLAG_RUN_AWAY); |
1680 | else |
1651 | else |
1681 | scare_creature (op, hitter); |
1652 | scare_creature (op, hitter); |
1682 | } |
1653 | } |
1683 | |
1654 | |
1684 | if (QUERY_FLAG (op, FLAG_TEAR_DOWN)) |
1655 | if (op->flag [FLAG_TEAR_DOWN]) |
1685 | { |
1656 | { |
1686 | if (maxdam) |
1657 | if (maxdam) |
1687 | tear_down_wall (op); |
1658 | tear_down_wall (op); |
1688 | |
1659 | |
1689 | return maxdam; /* nothing more to do for wall */ |
1660 | return maxdam; /* nothing more to do for wall */ |
… | |
… | |
1696 | |
1667 | |
1697 | /* 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 |
1698 | * that before if the player was immune to ghosthit, the monster |
1669 | * that before if the player was immune to ghosthit, the monster |
1699 | * remained - that is no longer the case. |
1670 | * remained - that is no longer the case. |
1700 | */ |
1671 | */ |
1701 | if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) |
1672 | if (hitter->flag [FLAG_ONE_HIT]) |
1702 | hitter->drop_and_destroy (); |
1673 | hitter->drop_and_destroy (); |
1703 | /* Lets handle creatures that are splitting now */ |
1674 | /* Lets handle creatures that are splitting now */ |
1704 | 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]) |
1705 | { |
1676 | { |
1706 | int i; |
|
|
1707 | int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); |
1677 | int friendly = op->flag [FLAG_FRIENDLY]; |
1708 | int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE); |
1678 | int unaggressive = op->flag [FLAG_UNAGGRESSIVE]; |
1709 | object *owner = op->owner; |
1679 | object *owner = op->owner; |
1710 | |
1680 | |
1711 | if (!op->other_arch) |
1681 | if (!op->other_arch) |
1712 | { |
1682 | { |
1713 | LOG (llevError, "SPLITTING without other_arch error.\n"); |
1683 | LOG (llevError, "SPLITTING without other_arch error.\n"); |
1714 | return maxdam; |
1684 | return maxdam; |
1715 | } |
1685 | } |
1716 | |
1686 | |
1717 | op->remove (); |
1687 | op->remove (); |
1718 | |
1688 | |
1719 | for (i = 0; i < op->stats.food; i++) |
1689 | for (int i = 0; i < op->stats.food; i++) |
1720 | { /* This doesn't handle op->more yet */ |
1690 | { /* This doesn't handle op->more yet */ |
1721 | object *tmp = arch_to_object (op->other_arch); |
1691 | object *tmp = op->other_arch->instance (); |
1722 | int j; |
|
|
1723 | |
1692 | |
1724 | tmp->stats.hp = op->stats.hp; |
1693 | tmp->stats.hp = op->stats.hp; |
1725 | |
1694 | |
1726 | if (friendly) |
1695 | if (friendly) |
1727 | { |
1696 | { |
… | |
… | |
1731 | if (owner) |
1700 | if (owner) |
1732 | tmp->set_owner (owner); |
1701 | tmp->set_owner (owner); |
1733 | } |
1702 | } |
1734 | |
1703 | |
1735 | if (unaggressive) |
1704 | if (unaggressive) |
1736 | SET_FLAG (tmp, FLAG_UNAGGRESSIVE); |
1705 | tmp->set_flag (FLAG_UNAGGRESSIVE); |
1737 | |
1706 | |
1738 | 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); |
1739 | |
1708 | |
1740 | if (j == -1) /* No spot to put this monster */ |
1709 | if (j == -1) /* No spot to put this monster */ |
1741 | tmp->destroy (); |
1710 | tmp->destroy (); |
1742 | else |
1711 | else |
1743 | { |
1712 | { |
1744 | tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; |
1713 | tmp->x = op->x + DIRX (j), tmp->y = op->y + DIRY (j); |
1745 | insert_ob_in_map (tmp, op->map, NULL, 0); |
1714 | insert_ob_in_map (tmp, op->map, NULL, 0); |
1746 | } |
1715 | } |
1747 | } |
1716 | } |
1748 | |
1717 | |
1749 | op->destroy (); |
1718 | op->destroy (); |
… | |
… | |
1758 | poison_player (object *op, object *hitter, int dam) |
1727 | poison_player (object *op, object *hitter, int dam) |
1759 | { |
1728 | { |
1760 | archetype *at = archetype::find (shstr_poisoning); |
1729 | archetype *at = archetype::find (shstr_poisoning); |
1761 | object *tmp = present_arch_in_ob (at, op); |
1730 | object *tmp = present_arch_in_ob (at, op); |
1762 | |
1731 | |
1763 | if (tmp == NULL) |
1732 | if (!tmp) |
1764 | { |
1733 | { |
1765 | if ((tmp = arch_to_object (at)) == NULL) |
1734 | tmp = insert_ob_in_ob (at->instance (), op); |
1766 | 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; |
1767 | else |
1745 | else |
1768 | { |
|
|
1769 | tmp = insert_ob_in_ob (tmp, op); |
|
|
1770 | /* peterm: give poisoning some teeth. It should |
|
|
1771 | * be able to kill things better than it does: |
|
|
1772 | * damage should be dependent something--I choose to |
|
|
1773 | * do this: if it's a monster, the damage from the |
|
|
1774 | * poisoning goes as the level of the monster/2. |
|
|
1775 | * If anything else, goes as damage. |
|
|
1776 | */ |
|
|
1777 | |
|
|
1778 | if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
|
|
1779 | tmp->stats.dam += hitter->level / 2; |
|
|
1780 | else |
|
|
1781 | tmp->stats.dam = dam; |
1746 | tmp->stats.dam = dam; |
1782 | |
1747 | |
1783 | tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
1748 | tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
1784 | if (hitter->skill && hitter->skill != tmp->skill) |
1749 | if (hitter->skill && hitter->skill != tmp->skill) |
1785 | { |
|
|
1786 | tmp->skill = hitter->skill; |
1750 | tmp->skill = hitter->skill; |
1787 | } |
|
|
1788 | |
1751 | |
1789 | tmp->stats.food += dam; /* more damage, longer poisoning */ |
1752 | tmp->stats.food += dam; /* more damage, longer poisoning */ |
1790 | |
1753 | |
1791 | if (op->type == PLAYER) |
1754 | if (op->type == PLAYER) |
1792 | { |
1755 | { |
1793 | /* player looses stats, maximum is -10 of each */ |
1756 | /* player looses stats, maximum is -10 of each */ |
1794 | tmp->stats.Con = max (-(dam / 4 + 1), -10); |
1757 | tmp->stats.Con = max (-(dam / 4 + 1), -10); |
1795 | tmp->stats.Str = max (-(dam / 3 + 2), -10); |
1758 | tmp->stats.Str = max (-(dam / 3 + 2), -10); |
1796 | tmp->stats.Dex = max (-(dam / 6 + 1), -10); |
1759 | tmp->stats.Dex = max (-(dam / 6 + 1), -10); |
1797 | tmp->stats.Int = max (-(dam / 7 ), -10); |
1760 | tmp->stats.Int = max (-(dam / 7 ), -10); |
1798 | SET_FLAG (tmp, FLAG_APPLIED); |
1761 | tmp->set_flag (FLAG_APPLIED); |
1799 | op->update_stats (); |
1762 | op->update_stats (); |
1800 | 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."); |
1801 | op->play_sound (tmp->sound); |
1764 | op->play_sound (tmp->sound); |
1802 | } |
1765 | } |
1803 | |
1766 | |
1804 | if (hitter->type == PLAYER) |
1767 | if (hitter->type == PLAYER) |
1805 | 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); |
1806 | else if (hitter->owner != NULL && hitter->owner->type == PLAYER) |
1769 | else if (hitter->owner != NULL && hitter->owner->type == PLAYER) |
1807 | 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); |
1808 | } |
|
|
1809 | |
1771 | |
1810 | tmp->speed_left = 0; |
1772 | tmp->speed_left = 0; |
1811 | } |
1773 | } |
1812 | else |
1774 | else |
1813 | tmp->stats.food++; |
1775 | tmp->stats.food++; |
… | |
… | |
1817 | slow_player (object *op, object *hitter, int dam) |
1779 | slow_player (object *op, object *hitter, int dam) |
1818 | { |
1780 | { |
1819 | archetype *at = archetype::find (shstr_slowness); |
1781 | archetype *at = archetype::find (shstr_slowness); |
1820 | object *tmp; |
1782 | object *tmp; |
1821 | |
1783 | |
1822 | if (at == NULL) |
1784 | if (!at) |
1823 | LOG (llevError, "Can't find slowness archetype.\n"); |
1785 | LOG (llevError, "Can't find slowness archetype.\n"); |
1824 | |
1786 | |
1825 | if ((tmp = present_arch_in_ob (at, op)) == NULL) |
1787 | if ((tmp = present_arch_in_ob (at, op)) == NULL) |
1826 | { |
1788 | { |
1827 | tmp = arch_to_object (at); |
1789 | tmp = at->instance (); |
1828 | tmp = insert_ob_in_ob (tmp, op); |
1790 | tmp = insert_ob_in_ob (tmp, op); |
1829 | 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!"); |
1830 | } |
1792 | } |
1831 | else |
1793 | else |
1832 | tmp->stats.food++; |
1794 | tmp->stats.food++; |
1833 | |
1795 | |
1834 | SET_FLAG (tmp, FLAG_APPLIED); |
1796 | tmp->set_flag (FLAG_APPLIED); |
1835 | tmp->speed_left = 0; |
1797 | tmp->speed_left = 0; |
1836 | op->update_stats (); |
1798 | op->update_stats (); |
1837 | } |
1799 | } |
1838 | |
1800 | |
1839 | void |
1801 | void |
… | |
… | |
1843 | int maxduration; |
1805 | int maxduration; |
1844 | |
1806 | |
1845 | tmp = present_in_ob_by_name (FORCE, shstr_confusion, op); |
1807 | tmp = present_in_ob_by_name (FORCE, shstr_confusion, op); |
1846 | if (!tmp) |
1808 | if (!tmp) |
1847 | { |
1809 | { |
1848 | tmp = get_archetype (FORCE_NAME); |
1810 | tmp = archetype::get (FORCE_NAME); |
1849 | tmp = insert_ob_in_ob (tmp, op); |
1811 | tmp = insert_ob_in_ob (tmp, op); |
1850 | } |
1812 | } |
1851 | |
1813 | |
1852 | /* Duration added per hit and max. duration of confusion both depend |
1814 | /* Duration added per hit and max. duration of confusion both depend |
1853 | * on the player's resistance |
1815 | * on the player's resistance |
1854 | */ |
1816 | */ |
1855 | tmp->speed = 0.05; |
1817 | tmp->set_speed (0.05); |
1856 | tmp->subtype = FORCE_CONFUSION; |
1818 | tmp->subtype = FORCE_CONFUSION; |
1857 | 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); |
1858 | tmp->name = shstr_confusion; |
1820 | tmp->name = shstr_confusion; |
1859 | maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1821 | maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1860 | |
1822 | |
1861 | if (tmp->duration > maxduration) |
1823 | if (tmp->duration > maxduration) |
1862 | tmp->duration = maxduration; |
1824 | tmp->duration = maxduration; |
1863 | |
1825 | |
1864 | if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED)) |
1826 | if (op->type == PLAYER && !op->flag [FLAG_CONFUSED]) |
1865 | 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!"); |
1866 | |
1828 | |
1867 | SET_FLAG (op, FLAG_CONFUSED); |
1829 | op->set_flag (FLAG_CONFUSED); |
1868 | } |
1830 | } |
1869 | |
1831 | |
1870 | void |
1832 | void |
1871 | blind_player (object *op, object *hitter, int dam) |
1833 | blind_player (object *op, object *hitter, int dam) |
1872 | { |
1834 | { |
1873 | object *tmp, *owner; |
|
|
1874 | |
|
|
1875 | /* 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 */ |
1876 | if (op->resist[ATNR_BLIND] == 100) |
1836 | if (op->resist[ATNR_BLIND] == 100) |
1877 | return; |
1837 | return; |
1878 | |
1838 | |
1879 | tmp = present_in_ob (BLINDNESS, op); |
1839 | object *tmp = present_in_ob (BLINDNESS, op); |
1880 | if (!tmp) |
1840 | if (!tmp) |
1881 | { |
1841 | { |
1882 | tmp = get_archetype (shstr_blindness); |
1842 | tmp = archetype::get (shstr_blindness); |
1883 | SET_FLAG (tmp, FLAG_BLIND); |
1843 | tmp->set_flag (FLAG_BLIND); |
1884 | SET_FLAG (tmp, FLAG_APPLIED); |
1844 | tmp->set_flag (FLAG_APPLIED); |
1885 | /* 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. |
1886 | * speed is a float anyways. |
1846 | tmp->set_speed (lerp<float> (op->resist [ATNR_BLIND], 0, 100, tmp->speed, MIN_ACTIVE_SPEED)); |
1887 | */ |
|
|
1888 | tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100; |
|
|
1889 | |
1847 | |
1890 | tmp = insert_ob_in_ob (tmp, op); |
1848 | tmp = insert_ob_in_ob (tmp, op); |
1891 | change_abil (op, tmp); /* Mostly to display any messages */ |
1849 | change_abil (op, tmp); /* Mostly to display any messages */ |
1892 | op->update_stats (); /* This takes care of some other stuff */ |
1850 | op->update_stats (); /* This takes care of some other stuff */ |
1893 | |
1851 | |
1894 | if (hitter->owner) |
|
|
1895 | owner = hitter->owner; |
|
|
1896 | else |
|
|
1897 | owner = hitter; |
|
|
1898 | |
|
|
1899 | 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)); |
1900 | } |
1853 | } |
|
|
1854 | |
1901 | tmp->stats.food += dam; |
1855 | tmp->stats.food += dam; |
1902 | if (tmp->stats.food > 10) |
1856 | min_it (tmp->stats.food, 10); |
1903 | tmp->stats.food = 10; |
|
|
1904 | } |
1857 | } |
1905 | |
1858 | |
1906 | void |
1859 | void |
1907 | paralyze_player (object *op, object *hitter, int dam) |
1860 | paralyze_player (object *op, object *hitter, int dam) |
1908 | { |
1861 | { |
1909 | /* This is strange stuff... someone knows for what this is |
1862 | /* This is strange stuff... someone knows for what this is |
1910 | * written? Well, i think this can and should be removed |
1863 | * written? Well, i think this can and should be removed |
1911 | */ |
1864 | */ |
1912 | |
1865 | |
1913 | /* |
1866 | /* |
1914 | if((tmp=present(PARAIMAGE,op->map,op->x,op->y))==NULL) { |
1867 | if((tmp=present(PARAIMAGE,op->map,op->x,op->y))==NULL) { |
1915 | tmp=clone_arch(PARAIMAGE); |
1868 | tmp=clone_arch(PARAIMAGE); |
… | |
… | |
1919 | */ |
1872 | */ |
1920 | |
1873 | |
1921 | /* 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 */ |
1922 | float effect = dam * 3.f * (100.f - op->resist[ATNR_PARALYZE]) / 100.f; |
1875 | float effect = dam * 3.f * (100.f - op->resist[ATNR_PARALYZE]) / 100.f; |
1923 | |
1876 | |
1924 | op->speed_left -= fabs (op->speed) * effect; |
1877 | op->speed_left -= op->speed * effect; |
1925 | /* tmp->stats.food+=(signed short) effect/op->speed; */ |
1878 | /* tmp->stats.food+=(signed short) effect/op->speed; */ |
1926 | |
1879 | |
1927 | /* max number of ticks to be affected for. */ |
1880 | /* max number of ticks to be affected for. */ |
1928 | float max = (100 - op->resist[ATNR_PARALYZE]) / 2; |
1881 | float max = (100 - op->resist[ATNR_PARALYZE]) / 2; |
1929 | |
1882 | |
1930 | if (op->speed_left < -(fabs (op->speed) * max)) |
1883 | max_it (op->speed_left, -op->speed * max); |
1931 | op->speed_left = -(fabs (op->speed) * max); |
|
|
1932 | |
1884 | |
1933 | /* tmp->stats.food = (signed short) (max / fabs (op->speed)); */ |
1885 | /* tmp->stats.food = (signed short) (max / op->speed); */ |
1934 | } |
1886 | } |
1935 | |
1887 | |
1936 | /* Attempts to kill 'op'. hitter is the attack object, dam is |
1888 | /* Attempts to kill 'op'. hitter is the attack object, dam is |
1937 | * the computed damaged. |
1889 | * the computed damaged. |
1938 | */ |
1890 | */ |
… | |
… | |
1948 | ** field of the deathstriking object */ |
1900 | ** field of the deathstriking object */ |
1949 | |
1901 | |
1950 | int atk_lev, def_lev, kill_lev; |
1902 | int atk_lev, def_lev, kill_lev; |
1951 | |
1903 | |
1952 | if (hitter->slaying) |
1904 | if (hitter->slaying) |
1953 | if (!((QUERY_FLAG (op, FLAG_UNDEAD) && hitter->slaying.contains (shstr_undead)) |
1905 | if (!((op->flag [FLAG_UNDEAD] && hitter->slaying.contains (shstr_undead)) |
1954 | || (op->race && hitter->slaying.contains (op->race)))) |
1906 | || (op->race && hitter->slaying.contains (op->race)))) |
1955 | return; |
1907 | return; |
1956 | |
1908 | |
1957 | def_lev = op->level; |
1909 | def_lev = op->level; |
1958 | if (def_lev < 1) |
1910 | if (def_lev < 1) |
… | |
… | |
1975 | * redone. |
1927 | * redone. |
1976 | */ |
1928 | */ |
1977 | if (kill_lev >= def_lev) |
1929 | if (kill_lev >= def_lev) |
1978 | { |
1930 | { |
1979 | *dam = op->stats.hp + 10; /* take all hp. they can still save for 1/2 */ |
1931 | *dam = op->stats.hp + 10; /* take all hp. they can still save for 1/2 */ |
1980 | /* I think this doesn't really do much. Because of |
1932 | /* I think this doesn't really do much. Because of |
1981 | * integer rounding, this only makes any difference if the |
1933 | * integer rounding, this only makes any difference if the |
1982 | * attack level is double the defender level. |
1934 | * attack level is double the defender level. |
1983 | */ |
1935 | */ |
1984 | *dam *= kill_lev / def_lev; |
1936 | *dam *= kill_lev / def_lev; |
1985 | } |
1937 | } |
1986 | } |
1938 | } |
… | |
… | |
2058 | /* here also check for diseases */ |
2010 | /* here also check for diseases */ |
2059 | check_physically_infect (op, hitter); |
2011 | check_physically_infect (op, hitter); |
2060 | break; |
2012 | break; |
2061 | |
2013 | |
2062 | /* Don't need to do anything for: |
2014 | /* Don't need to do anything for: |
2063 | magic, |
2015 | magic, |
2064 | fire, |
2016 | fire, |
2065 | electricity, |
2017 | electricity, |
2066 | cold */ |
2018 | cold */ |
2067 | |
2019 | |
2068 | case ATNR_CONFUSION: |
2020 | case ATNR_CONFUSION: |
2069 | case ATNR_POISON: |
2021 | case ATNR_POISON: |
… | |
… | |
2073 | case ATNR_CANCELLATION: |
2025 | case ATNR_CANCELLATION: |
2074 | case ATNR_DEPLETE: |
2026 | case ATNR_DEPLETE: |
2075 | case ATNR_BLIND: |
2027 | case ATNR_BLIND: |
2076 | { |
2028 | { |
2077 | /* chance for inflicting a special attack depends on the |
2029 | /* chance for inflicting a special attack depends on the |
2078 | * difference between attacker's and defender's level |
2030 | * difference between attacker's and defender's level |
2079 | */ |
2031 | */ |
2080 | int level_diff = min (110, max (0, op->level - hitter->level)); |
2032 | int level_diff = min (110, max (0, op->level - hitter->level)); |
2081 | |
2033 | |
2082 | /* First, only creatures/players with speed can be affected. |
2034 | /* First, only creatures/players with speed can be affected. |
2083 | * Second, just getting hit doesn't mean it always affects |
2035 | * Second, just getting hit doesn't mean it always affects |
2084 | * you. Third, you still get a saving through against the |
2036 | * you. Third, you still get a saving through against the |
2085 | * effect. |
2037 | * effect. |
2086 | */ |
2038 | */ |
2087 | if (op->has_active_speed () |
2039 | if (op->has_active_speed () |
2088 | && (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) |
2040 | && (op->flag [FLAG_MONSTER] || op->type == PLAYER) |
2089 | && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) |
2041 | && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) |
2090 | && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
2042 | && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
2091 | { |
2043 | { |
2092 | |
2044 | |
2093 | /* Player has been hit by something */ |
2045 | /* Player has been hit by something */ |
… | |
… | |
2103 | scare_creature (op, hitter); |
2055 | scare_creature (op, hitter); |
2104 | else if (attacknum == ATNR_CANCELLATION) |
2056 | else if (attacknum == ATNR_CANCELLATION) |
2105 | cancellation (op); |
2057 | cancellation (op); |
2106 | else if (attacknum == ATNR_DEPLETE) |
2058 | else if (attacknum == ATNR_DEPLETE) |
2107 | op->drain_stat (); |
2059 | op->drain_stat (); |
2108 | 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]) |
2109 | blind_player (op, hitter, dam); |
2061 | blind_player (op, hitter, dam); |
2110 | } |
2062 | } |
2111 | |
2063 | |
2112 | 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 */ |
2113 | } |
2065 | } |
… | |
… | |
2123 | { |
2075 | { |
2124 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2076 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2125 | { |
2077 | { |
2126 | if (tmp->invisible) |
2078 | if (tmp->invisible) |
2127 | continue; |
2079 | continue; |
2128 | if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) |
2080 | if (!tmp->flag [FLAG_APPLIED] || (tmp->resist[ATNR_ACID] >= 10)) |
2129 | /* >= 10% acid res. on items will protect these */ |
2081 | /* >= 10% acid res. on items will protect these */ |
2130 | continue; |
2082 | continue; |
2131 | if (!(tmp->materials & M_IRON)) |
2083 | if (!(tmp->materials & M_IRON)) |
2132 | continue; |
2084 | continue; |
2133 | if (tmp->magic < -4) /* Let's stop at -5 */ |
2085 | if (tmp->magic < -4) /* Let's stop at -5 */ |
… | |
… | |
2178 | rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); |
2130 | rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); |
2179 | |
2131 | |
2180 | if (op->stats.exp <= rate) |
2132 | if (op->stats.exp <= rate) |
2181 | { |
2133 | { |
2182 | if (op->type == GOLEM) |
2134 | if (op->type == GOLEM) |
2183 | dam = 999; /* Its force is "sucked" away. 8) */ |
2135 | dam = 9998; /* Its force is "sucked" away. 8) */ |
2184 | else |
2136 | else |
2185 | /* If we can't drain, lets try to do physical damage */ |
2137 | /* If we can't drain, lets try to do physical damage */ |
2186 | dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); |
2138 | dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); |
2187 | } |
2139 | } |
2188 | else |
2140 | else |
… | |
… | |
2197 | * 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, |
2198 | * nothing happens. |
2150 | * nothing happens. |
2199 | * 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 |
2200 | * attacks, hence all the != PLAYER checks. |
2152 | * attacks, hence all the != PLAYER checks. |
2201 | */ |
2153 | */ |
2202 | if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WIZ)) |
2154 | if (!op_on_battleground (hitter, NULL, NULL) && !op->flag [FLAG_WIZ]) |
2203 | { |
2155 | { |
2204 | object *owner = hitter->owner; |
2156 | object *owner = hitter->owner; |
2205 | |
2157 | |
2206 | if (owner && owner != hitter) |
2158 | if (owner && owner != hitter) |
2207 | { |
2159 | { |
2208 | if (op->type != PLAYER || owner->type != PLAYER) |
2160 | if (op->type != PLAYER || owner->type != PLAYER) |
2209 | change_exp (owner, op->stats.exp / (rate * 2), |
2161 | change_exp (owner, op->stats.exp / (rate * 2), |
2210 | 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); |
2211 | } |
2163 | } |
2212 | else if (op->type != PLAYER || hitter->type != PLAYER) |
2164 | else if (op->type != PLAYER || hitter->type != PLAYER) |
2213 | change_exp (hitter, op->stats.exp / (rate * 2), |
2165 | change_exp (hitter, op->stats.exp / (rate * 2), |
2214 | hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); |
2166 | hitter->chosen_skill ? hitter->chosen_skill->skill : shstr (), 0); |
2215 | |
2167 | |
2216 | change_exp (op, -op->stats.exp / rate, NULL, 0); |
2168 | change_exp (op, -op->stats.exp / rate, shstr (), 0); |
2217 | } |
2169 | } |
2218 | |
2170 | |
2219 | 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 |
2220 | * 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, |
2221 | * as the messages will say you missed |
2173 | * as the messages will say you missed |
… | |
… | |
2224 | } |
2176 | } |
2225 | break; |
2177 | break; |
2226 | |
2178 | |
2227 | case ATNR_TURN_UNDEAD: |
2179 | case ATNR_TURN_UNDEAD: |
2228 | { |
2180 | { |
2229 | if (QUERY_FLAG (op, FLAG_UNDEAD)) |
2181 | if (op->flag [FLAG_UNDEAD]) |
2230 | { |
2182 | { |
2231 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2183 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2232 | object *god = find_god (determine_god (owner)); |
2184 | object *god = find_god (determine_god (owner)); |
2233 | int div = 1; |
2185 | int div = 1; |
2234 | |
2186 | |
… | |
… | |
2265 | * does no damage. */ |
2217 | * does no damage. */ |
2266 | break; |
2218 | break; |
2267 | |
2219 | |
2268 | case ATNR_HOLYWORD: |
2220 | case ATNR_HOLYWORD: |
2269 | { |
2221 | { |
2270 | /* This has already been handled by hit_player, |
2222 | /* This has already been handled by hit_player, |
2271 | * no need to check twice -- DAMN */ |
2223 | * no need to check twice -- DAMN */ |
2272 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2224 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2273 | |
2225 | |
2274 | /* As with turn undead above, give a bonus on the saving throw */ |
2226 | /* As with turn undead above, give a bonus on the saving throw */ |
2275 | if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis]) |
2227 | if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis]) |
… | |
… | |
2289 | * damage it does do to the player. Given that, |
2241 | * damage it does do to the player. Given that, |
2290 | * 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 |
2291 | * 1000). |
2243 | * 1000). |
2292 | */ |
2244 | */ |
2293 | /* You can't steal life from something undead */ |
2245 | /* You can't steal life from something undead */ |
2294 | if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) |
2246 | if ((op->type == GOLEM) || (op->flag [FLAG_UNDEAD])) |
2295 | return 0; |
2247 | return 0; |
2296 | |
2248 | |
2297 | /* If drain protection is higher than life stealing, use that */ |
2249 | /* If drain protection is higher than life stealing, use that */ |
2298 | if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
2250 | if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
2299 | dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |
2251 | dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |