1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_attack_c = |
|
|
4 | * "$Id: attack.C,v 1.10 2006/09/11 11:46:52 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The authors can be reached via e-mail to crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail to <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | #include <assert.h> |
23 | #include <assert.h> |
30 | #include <global.h> |
24 | #include <global.h> |
31 | #include <living.h> |
25 | #include <living.h> |
32 | #include <material.h> |
26 | #include <material.h> |
… | |
… | |
177 | if (type & (AT_FIRE | AT_ELECTRICITY) && op->other_arch && QUERY_FLAG (op, FLAG_IS_LIGHTABLE)) |
171 | if (type & (AT_FIRE | AT_ELECTRICITY) && op->other_arch && QUERY_FLAG (op, FLAG_IS_LIGHTABLE)) |
178 | { |
172 | { |
179 | const char *arch = op->other_arch->name; |
173 | const char *arch = op->other_arch->name; |
180 | |
174 | |
181 | op = decrease_ob_nr (op, 1); |
175 | op = decrease_ob_nr (op, 1); |
|
|
176 | |
182 | if (op) |
177 | if (op) |
183 | fix_stopped_item (op, m, originator); |
178 | fix_stopped_item (op, m, originator); |
|
|
179 | |
184 | if ((op = get_archetype (arch)) != NULL) |
180 | if ((op = get_archetype (arch)) != NULL) |
185 | { |
181 | { |
186 | if (env) |
182 | if (env) |
187 | { |
183 | { |
188 | op->x = env->x, op->y = env->y; |
184 | op->x = env->x, op->y = env->y; |
… | |
… | |
194 | { |
190 | { |
195 | op->x = x, op->y = y; |
191 | op->x = x, op->y = y; |
196 | insert_ob_in_map (op, m, originator, 0); |
192 | insert_ob_in_map (op, m, originator, 0); |
197 | } |
193 | } |
198 | } |
194 | } |
|
|
195 | |
199 | return; |
196 | return; |
200 | } |
197 | } |
|
|
198 | |
201 | if (type & AT_CANCELLATION) |
199 | if (type & AT_CANCELLATION) |
202 | { /* Cancellation. */ |
200 | { /* Cancellation. */ |
203 | cancellation (op); |
201 | cancellation (op); |
204 | fix_stopped_item (op, m, originator); |
202 | fix_stopped_item (op, m, originator); |
205 | return; |
203 | return; |
206 | } |
204 | } |
|
|
205 | |
207 | if (op->nrof > 1) |
206 | if (op->nrof > 1) |
208 | { |
207 | { |
209 | op = decrease_ob_nr (op, rndm (0, op->nrof - 1)); |
208 | op = decrease_ob_nr (op, rndm (0, op->nrof - 1)); |
|
|
209 | |
210 | if (op) |
210 | if (op) |
211 | fix_stopped_item (op, m, originator); |
211 | fix_stopped_item (op, m, originator); |
212 | } |
212 | } |
213 | else |
213 | else |
214 | { |
214 | { |
215 | if (op->env) |
215 | if (op->env) |
216 | { |
216 | { |
217 | object *tmp = is_player_inv (op->env); |
217 | object *tmp = is_player_inv (op->env); |
218 | |
218 | |
219 | if (tmp) |
219 | if (tmp) |
220 | { |
|
|
221 | esrv_del_item (tmp->contr, op->count); |
220 | esrv_del_item (tmp->contr, op->count); |
222 | } |
|
|
223 | } |
221 | } |
|
|
222 | |
224 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
223 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
225 | remove_ob (op); |
224 | remove_ob (op); |
|
|
225 | |
226 | free_object (op); |
226 | free_object (op); |
227 | } |
227 | } |
|
|
228 | |
228 | if (type & (AT_FIRE | AT_ELECTRICITY)) |
229 | if (type & (AT_FIRE | AT_ELECTRICITY)) |
229 | { |
|
|
230 | if (env) |
230 | if (env) |
231 | { |
231 | { |
232 | op = get_archetype ("burnout"); |
232 | op = get_archetype ("burnout"); |
233 | op->x = env->x, op->y = env->y; |
233 | op->x = env->x, op->y = env->y; |
234 | insert_ob_in_ob (op, env); |
234 | insert_ob_in_ob (op, env); |
235 | } |
235 | } |
236 | else |
236 | else |
237 | { |
|
|
238 | replace_insert_ob_in_map ("burnout", originator); |
237 | replace_insert_ob_in_map ("burnout", originator); |
239 | } |
238 | |
240 | } |
|
|
241 | return; |
239 | return; |
242 | } |
240 | } |
|
|
241 | |
243 | /* The value of 50 is arbitrary. */ |
242 | /* The value of 50 is arbitrary. */ |
244 | if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && (RANDOM () & 2)) |
243 | if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && (RANDOM () & 2)) |
245 | { |
244 | { |
246 | object *tmp; |
245 | object *tmp; |
247 | archetype *at = find_archetype ("icecube"); |
246 | archetype *at = archetype::find ("icecube"); |
248 | |
247 | |
249 | if (at == NULL) |
248 | if (at == NULL) |
250 | return; |
249 | return; |
|
|
250 | |
251 | op = stop_item (op); |
251 | op = stop_item (op); |
252 | if (op == NULL) |
252 | if (op == NULL) |
253 | return; |
253 | return; |
|
|
254 | |
254 | if ((tmp = present_arch (at, op->map, op->x, op->y)) == NULL) |
255 | if ((tmp = present_arch (at, op->map, op->x, op->y)) == NULL) |
255 | { |
256 | { |
256 | tmp = arch_to_object (at); |
257 | tmp = arch_to_object (at); |
257 | tmp->x = op->x, tmp->y = op->y; |
258 | tmp->x = op->x, tmp->y = op->y; |
258 | /* This was in the old (pre new movement code) - |
259 | /* This was in the old (pre new movement code) - |
… | |
… | |
261 | */ |
262 | */ |
262 | tmp->move_slow_penalty = 0; |
263 | tmp->move_slow_penalty = 0; |
263 | tmp->move_slow = 0; |
264 | tmp->move_slow = 0; |
264 | insert_ob_in_map (tmp, op->map, originator, 0); |
265 | insert_ob_in_map (tmp, op->map, originator, 0); |
265 | } |
266 | } |
|
|
267 | |
266 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
268 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
267 | remove_ob (op); |
269 | remove_ob (op); |
|
|
270 | |
268 | (void) insert_ob_in_ob (op, tmp); |
271 | insert_ob_in_ob (op, tmp); |
269 | return; |
272 | return; |
270 | } |
273 | } |
271 | } |
274 | } |
272 | |
275 | |
273 | /* Object op is hitting the map. |
276 | /* Object op is hitting the map. |
… | |
… | |
316 | |
319 | |
317 | int mflags = get_map_flags (map, &map, x, y, &x, &y); |
320 | int mflags = get_map_flags (map, &map, x, y, &x, &y); |
318 | |
321 | |
319 | // elmex: a safe map tile can't be hit! |
322 | // elmex: a safe map tile can't be hit! |
320 | // this should prevent most harmful effects on items and players there. |
323 | // this should prevent most harmful effects on items and players there. |
321 | if ((mflags & P_OUT_OF_MAP) || (mflags & P_SAFE)) |
324 | if (mflags & (P_OUT_OF_MAP | P_SAFE)) |
322 | return 0; |
325 | return 0; |
323 | |
326 | |
324 | /* peterm: a few special cases for special attacktypes --counterspell |
327 | /* peterm: a few special cases for special attacktypes --counterspell |
325 | * must be out here because it strikes things which are not alive |
328 | * must be out here because it strikes things which are not alive |
326 | */ |
329 | */ |
… | |
… | |
331 | |
334 | |
332 | /* If the only attacktype is counterspell or magic, don't need |
335 | /* If the only attacktype is counterspell or magic, don't need |
333 | * to do any further processing. |
336 | * to do any further processing. |
334 | */ |
337 | */ |
335 | if (!(type & ~(AT_COUNTERSPELL | AT_MAGIC))) |
338 | if (!(type & ~(AT_COUNTERSPELL | AT_MAGIC))) |
336 | { |
|
|
337 | return 0; |
339 | return 0; |
338 | } |
340 | |
339 | type &= ~AT_COUNTERSPELL; |
341 | type &= ~AT_COUNTERSPELL; |
340 | } |
342 | } |
341 | |
343 | |
342 | if (type & AT_CHAOS) |
344 | if (type & AT_CHAOS) |
343 | { |
345 | { |
… | |
… | |
364 | * below was spamming the logs for absolutely no reason. |
366 | * below was spamming the logs for absolutely no reason. |
365 | */ |
367 | */ |
366 | /* LOG (llevDebug, "hit_map(): next object destroyed\n"); */ |
368 | /* LOG (llevDebug, "hit_map(): next object destroyed\n"); */ |
367 | break; |
369 | break; |
368 | } |
370 | } |
|
|
371 | |
369 | tmp = next; |
372 | tmp = next; |
370 | next = tmp->above; |
373 | next = tmp->above; |
|
|
374 | |
371 | if (next) |
375 | if (next) |
372 | next_tag = next->count; |
376 | next_tag = next->count; |
373 | |
377 | |
374 | if (QUERY_FLAG (tmp, FLAG_FREED)) |
378 | if (QUERY_FLAG (tmp, FLAG_FREED)) |
375 | { |
379 | { |
… | |
… | |
389 | hit_player (tmp, op->stats.dam, op, type, full_hit); |
393 | hit_player (tmp, op->stats.dam, op, type, full_hit); |
390 | retflag |= 1; |
394 | retflag |= 1; |
391 | if (was_destroyed (op, op_tag)) |
395 | if (was_destroyed (op, op_tag)) |
392 | break; |
396 | break; |
393 | } |
397 | } |
|
|
398 | |
394 | /* Here we are potentially destroying an object. If the object has |
399 | /* Here we are potentially destroying an object. If the object has |
395 | * NO_PASS set, it is also immune - you can't destroy walls. Note |
400 | * NO_PASS set, it is also immune - you can't destroy walls. Note |
396 | * that weak walls have is_alive set, which prevent objects from |
401 | * that weak walls have is_alive set, which prevent objects from |
397 | * passing over/through them. We don't care what type of movement |
402 | * passing over/through them. We don't care what type of movement |
398 | * the wall blocks - if it blocks any type of movement, can't be |
403 | * the wall blocks - if it blocks any type of movement, can't be |
… | |
… | |
403 | save_throw_object (tmp, type, op); |
408 | save_throw_object (tmp, type, op); |
404 | if (was_destroyed (op, op_tag)) |
409 | if (was_destroyed (op, op_tag)) |
405 | break; |
410 | break; |
406 | } |
411 | } |
407 | } |
412 | } |
|
|
413 | |
408 | return 0; |
414 | return 0; |
409 | } |
415 | } |
410 | |
416 | |
411 | void |
417 | void |
412 | attack_message (int dam, int type, object *op, object *hitter) |
418 | attack_message (int dam, int type, object *op, object *hitter) |
… | |
… | |
1328 | break; |
1334 | break; |
1329 | case ATNR_TURN_UNDEAD: |
1335 | case ATNR_TURN_UNDEAD: |
1330 | { |
1336 | { |
1331 | if (QUERY_FLAG (op, FLAG_UNDEAD)) |
1337 | if (QUERY_FLAG (op, FLAG_UNDEAD)) |
1332 | { |
1338 | { |
1333 | object *owner = get_owner (hitter) == NULL ? hitter : get_owner (hitter); |
1339 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
1334 | object *god = find_god (determine_god (owner)); |
1340 | object *god = find_god (determine_god (owner)); |
1335 | int div = 1; |
1341 | int div = 1; |
1336 | |
1342 | |
1337 | /* if undead are not an enemy of your god, you turn them |
1343 | /* if undead are not an enemy of your god, you turn them |
1338 | * at half strength */ |
1344 | * at half strength */ |
… | |
… | |
1364 | break; |
1370 | break; |
1365 | case ATNR_HOLYWORD: |
1371 | case ATNR_HOLYWORD: |
1366 | { |
1372 | { |
1367 | /* This has already been handled by hit_player, |
1373 | /* This has already been handled by hit_player, |
1368 | * no need to check twice -- DAMN */ |
1374 | * no need to check twice -- DAMN */ |
1369 | |
1375 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
1370 | object *owner = get_owner (hitter) == NULL ? hitter : get_owner (hitter); |
|
|
1371 | |
1376 | |
1372 | /* As with turn undead above, give a bonus on the saving throw */ |
1377 | /* As with turn undead above, give a bonus on the saving throw */ |
1373 | if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis]) |
1378 | if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis]) |
1374 | scare_creature (op, owner); |
1379 | scare_creature (op, owner); |
1375 | } |
1380 | } |
… | |
… | |
1684 | { |
1689 | { |
1685 | play_sound_player_only (owner1->contr, SOUND_PET_IS_KILLED, 0, 0); |
1690 | play_sound_player_only (owner1->contr, SOUND_PET_IS_KILLED, 0, 0); |
1686 | /* Maybe we should include the owner that killed this, maybe not */ |
1691 | /* Maybe we should include the owner that killed this, maybe not */ |
1687 | new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, is killed by %s.", &op->name, &hitter->name); |
1692 | new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, is killed by %s.", &op->name, &hitter->name); |
1688 | } |
1693 | } |
|
|
1694 | |
1689 | remove_friendly_object (op); |
1695 | remove_friendly_object (op); |
1690 | } |
1696 | } |
|
|
1697 | |
1691 | remove_ob (op); |
1698 | remove_ob (op); |
1692 | free_object (op); |
1699 | free_object (op); |
1693 | } |
1700 | } |
1694 | /* Player has been killed! */ |
1701 | /* Player has been killed! */ |
1695 | else |
1702 | else |
… | |
… | |
1697 | if (owner->type == PLAYER) |
1704 | if (owner->type == PLAYER) |
1698 | { |
1705 | { |
1699 | snprintf (op->contr->killer, BIG_NAME, "%s the %s", &owner->name, owner->contr->title); |
1706 | snprintf (op->contr->killer, BIG_NAME, "%s the %s", &owner->name, owner->contr->title); |
1700 | } |
1707 | } |
1701 | else |
1708 | else |
1702 | { |
|
|
1703 | strncpy (op->contr->killer, hitter->name, BIG_NAME); |
1709 | assign (op->contr->killer, hitter->name); |
1704 | op->contr->killer[BIG_NAME - 1] = '\0'; |
|
|
1705 | } |
|
|
1706 | } |
1710 | } |
|
|
1711 | |
1707 | /* This was return -1 - that doesn't seem correct - if we return -1, process |
1712 | /* This was return -1 - that doesn't seem correct - if we return -1, process |
1708 | * continues in the calling function. |
1713 | * continues in the calling function. |
1709 | */ |
1714 | */ |
1710 | return maxdam; |
1715 | return maxdam; |
1711 | } |
1716 | } |
… | |
… | |
2055 | |
2060 | |
2056 | |
2061 | |
2057 | void |
2062 | void |
2058 | poison_player (object *op, object *hitter, int dam) |
2063 | poison_player (object *op, object *hitter, int dam) |
2059 | { |
2064 | { |
2060 | archetype *at = find_archetype ("poisoning"); |
2065 | archetype *at = archetype::find ("poisoning"); |
2061 | object *tmp = present_arch_in_ob (at, op); |
2066 | object *tmp = present_arch_in_ob (at, op); |
2062 | |
2067 | |
2063 | if (tmp == NULL) |
2068 | if (tmp == NULL) |
2064 | { |
2069 | { |
2065 | if ((tmp = arch_to_object (at)) == NULL) |
2070 | if ((tmp = arch_to_object (at)) == NULL) |
… | |
… | |
2111 | } |
2116 | } |
2112 | |
2117 | |
2113 | void |
2118 | void |
2114 | slow_player (object *op, object *hitter, int dam) |
2119 | slow_player (object *op, object *hitter, int dam) |
2115 | { |
2120 | { |
2116 | archetype *at = find_archetype ("slowness"); |
2121 | archetype *at = archetype::find ("slowness"); |
2117 | object *tmp; |
2122 | object *tmp; |
2118 | |
2123 | |
2119 | if (at == NULL) |
2124 | if (at == NULL) |
2120 | { |
2125 | { |
2121 | LOG (llevError, "Can't find slowness archetype.\n"); |
2126 | LOG (llevError, "Can't find slowness archetype.\n"); |