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,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 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. |
… | |
… | |
151 | if (disease->last_heal) |
151 | if (disease->last_heal) |
152 | return 0; |
152 | return 0; |
153 | |
153 | |
154 | /* first, search for an immunity of the same name */ |
154 | /* first, search for an immunity of the same name */ |
155 | for (walk = disease->env->inv; walk; walk = walk->below) |
155 | for (walk = disease->env->inv; walk; walk = walk->below) |
156 | if (walk->type == 98 && disease->name == walk->name) |
156 | if (disease->name == walk->name && walk->is_immunity ()) |
157 | { |
157 | { |
158 | walk->level = disease->level; |
158 | walk->level = disease->level; |
159 | return 1; /* just update the existing immunity. */ |
159 | return 1; /* just update the existing immunity. */ |
160 | } |
160 | } |
161 | |
161 | |
162 | immunity = get_archetype (shstr_immunity); |
162 | immunity = archetype::get (shstr_immunity); |
163 | |
163 | |
164 | immunity->name = disease->name; |
164 | immunity->name = disease->name; |
165 | immunity->level = disease->level; |
165 | immunity->level = disease->level; |
166 | immunity->move_block = 0; |
166 | immunity->move_block = 0; |
167 | |
167 | |
… | |
… | |
216 | object *op = disease->outer_env_or_self (); |
216 | object *op = disease->outer_env_or_self (); |
217 | |
217 | |
218 | if (!op->is_on_map ()) |
218 | if (!op->is_on_map ()) |
219 | return 0; |
219 | return 0; |
220 | |
220 | |
|
|
221 | dynbuf buf; |
221 | unordered_mapwalk (op, -range, -range, range, range) |
222 | unordered_mapwalk (buf, op, -range, -range, range, range) |
222 | { |
223 | { |
223 | mapspace &ms = m->at (nx, ny); |
224 | mapspace &ms = m->at (nx, ny); |
224 | |
225 | |
225 | if (ms.flags () & P_IS_ALIVE) |
226 | if (ms.flags () & P_IS_ALIVE) |
226 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
227 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
… | |
… | |
232 | |
233 | |
233 | /* check if victim is susceptible to disease. */ |
234 | /* check if victim is susceptible to disease. */ |
234 | static int |
235 | static int |
235 | is_susceptible_to_disease (object *victim, object *disease) |
236 | is_susceptible_to_disease (object *victim, object *disease) |
236 | { |
237 | { |
237 | if (!QUERY_FLAG (victim, FLAG_ALIVE)) |
238 | if (!victim->flag [FLAG_ALIVE]) |
238 | return 0; |
239 | return 0; |
239 | |
240 | |
240 | if (victim->flag [FLAG_WIZ]) |
241 | if (victim->flag [FLAG_WIZ]) |
241 | return 0; |
242 | return 0; |
242 | |
243 | |
243 | if (disease->race.contains ("*") && !QUERY_FLAG (victim, FLAG_UNDEAD)) |
244 | if (disease->race.contains ("*") && !victim->flag [FLAG_UNDEAD]) |
244 | return 1; |
245 | return 1; |
245 | |
246 | |
246 | if ((disease->race == shstr_undead) && QUERY_FLAG (victim, FLAG_UNDEAD)) |
247 | if ((disease->race == shstr_undead) && victim->flag [FLAG_UNDEAD]) |
247 | return 1; |
248 | return 1; |
248 | |
249 | |
249 | if ((victim->race && disease->race.contains (victim->race)) || disease->race.contains (victim->name)) |
250 | if ((victim->race && disease->race.contains (victim->race)) || disease->race.contains (victim->name)) |
250 | return 1; |
251 | return 1; |
251 | |
252 | |
… | |
… | |
288 | return 0; |
289 | return 0; |
289 | |
290 | |
290 | /* check for an actual immunity */ |
291 | /* check for an actual immunity */ |
291 | /* do an immunity check */ |
292 | /* do an immunity check */ |
292 | for (tmp = victim->head_ ()->inv; tmp; tmp = tmp->below) |
293 | for (tmp = victim->head_ ()->inv; tmp; tmp = tmp->below) |
293 | if (tmp->type == SIGN) /* possibly an immunity, or diseased */ |
294 | if (tmp->name == disease->name && tmp->is_immunity ()) /* possibly an immunity, or diseased */ |
294 | if (tmp->name == disease->name && tmp->level >= disease->level) |
295 | if (tmp->level >= disease->level) |
295 | return 0; /* Immune! */ |
296 | return 0; /* Immune! */ |
296 | |
297 | |
297 | object *new_symptom = get_archetype (shstr_symptom); |
298 | object *new_symptom = archetype::get (shstr_symptom); |
298 | |
299 | |
299 | /* Something special done with dam. We want diseases to be more |
300 | /* Something special done with dam. We want diseases to be more |
300 | * random in what they'll kill, so we'll make the damage they |
301 | * random in what they'll kill, so we'll make the damage they |
301 | * do random, note, this has a weird effect with progressive diseases. |
302 | * do random, note, this has a weird effect with progressive diseases. |
302 | */ |
303 | */ |
… | |
… | |
317 | new_symptom->stats.food = new_symptom->stats.maxgrace; |
318 | new_symptom->stats.food = new_symptom->stats.maxgrace; |
318 | |
319 | |
319 | new_symptom->name = new_symptom->name_pl = disease->name; |
320 | new_symptom->name = new_symptom->name_pl = disease->name; |
320 | |
321 | |
321 | new_symptom->level = disease->level; |
322 | new_symptom->level = disease->level; |
322 | new_symptom->speed = disease->speed; |
|
|
323 | new_symptom->value = 0; |
323 | new_symptom->value = 0; |
|
|
324 | |
|
|
325 | new_symptom->set_speed (disease->speed); |
324 | |
326 | |
325 | for (int i = 0; i < NUM_STATS; ++i) |
327 | for (int i = 0; i < NUM_STATS; ++i) |
326 | new_symptom->stats.stat (i) = disease->stats.stat (i); |
328 | new_symptom->stats.stat (i) = disease->stats.stat (i); |
327 | |
329 | |
328 | new_symptom->stats.sp = disease->stats.sp; |
330 | new_symptom->stats.sp = disease->stats.sp; |
… | |
… | |
369 | symptom->msg = disease->msg; |
371 | symptom->msg = disease->msg; |
370 | symptom->attacktype = disease->attacktype; |
372 | symptom->attacktype = disease->attacktype; |
371 | symptom->other_arch = disease->other_arch; |
373 | symptom->other_arch = disease->other_arch; |
372 | } |
374 | } |
373 | |
375 | |
374 | SET_FLAG (symptom, FLAG_APPLIED); |
376 | symptom->set_flag (FLAG_APPLIED); |
375 | victim->update_stats (); |
377 | victim->update_stats (); |
376 | |
378 | |
377 | return 1; |
379 | return 1; |
378 | } |
380 | } |
379 | |
381 | |
… | |
… | |
434 | { |
436 | { |
435 | object *tmp; |
437 | object *tmp; |
436 | object *new_disease; |
438 | object *new_disease; |
437 | |
439 | |
438 | /* don't infect inanimate objects */ |
440 | /* don't infect inanimate objects */ |
439 | if (!QUERY_FLAG (victim, FLAG_MONSTER) && !(victim->type == PLAYER)) |
441 | if (!victim->flag [FLAG_MONSTER] && !(victim->type == PLAYER)) |
440 | return 0; |
442 | return 0; |
441 | |
443 | |
442 | /* check and see if victim can catch disease: diseases |
444 | /* check and see if victim can catch disease: diseases |
443 | * are specific |
445 | * are specific |
444 | */ |
446 | */ |
… | |
… | |
458 | * they were cast in that same order. Instead, change it so that |
460 | * they were cast in that same order. Instead, change it so that |
459 | * if you diseased, you can't get diseased more. |
461 | * if you diseased, you can't get diseased more. |
460 | */ |
462 | */ |
461 | |
463 | |
462 | for (tmp = victim->head_ ()->inv; tmp; tmp = tmp->below) |
464 | for (tmp = victim->head_ ()->inv; tmp; tmp = tmp->below) |
463 | if (tmp->type == SIGN && tmp->name == disease->name && tmp->level >= disease->level) |
465 | if (tmp->name == disease->name && tmp->is_immunity () && tmp->level >= disease->level) |
464 | return 0; /* Immune! */ |
466 | return 0; /* Immune! */ |
465 | else if (tmp->type == DISEASE && tmp->name == disease->name) |
467 | else if (tmp->type == DISEASE && tmp->name == disease->name) |
466 | return 0; /* already diseased */ |
468 | return 0; /* already diseased */ |
467 | |
469 | |
468 | /* If we've gotten this far, go ahead and infect the victim. */ |
470 | /* If we've gotten this far, go ahead and infect the victim. */ |
… | |
… | |
514 | /* make the symptom do the nasty things it does */ |
516 | /* make the symptom do the nasty things it does */ |
515 | int |
517 | int |
516 | move_symptom (object *symptom) |
518 | move_symptom (object *symptom) |
517 | { |
519 | { |
518 | object *victim = symptom->env; |
520 | object *victim = symptom->env; |
519 | object *new_ob; |
|
|
520 | int sp_reduce; |
|
|
521 | |
521 | |
522 | if (!victim || !victim->map) |
522 | if (!victim || !victim->map) |
523 | { /* outside a monster/player, die immediately */ |
523 | { /* outside a monster/player, die immediately */ |
524 | symptom->destroy (); |
524 | symptom->destroy (); |
525 | return 0; |
525 | return 0; |
526 | } |
526 | } |
527 | |
|
|
528 | if (symptom->stats.dam > 0) |
|
|
529 | hit_player (victim, symptom->stats.dam, symptom, symptom->attacktype, 1); |
|
|
530 | else |
|
|
531 | hit_player (victim, max (1, -victim->stats.maxhp * symptom->stats.dam / 100), symptom, symptom->attacktype, 1); |
|
|
532 | |
|
|
533 | if (symptom->stats.maxsp > 0) |
|
|
534 | sp_reduce = symptom->stats.maxsp; |
|
|
535 | else |
|
|
536 | sp_reduce = max (1, victim->stats.maxsp * symptom->stats.maxsp / 100); |
|
|
537 | |
|
|
538 | victim->stats.sp = max (0, victim->stats.sp - sp_reduce); |
|
|
539 | |
527 | |
540 | /* create the symptom "other arch" object and drop it here |
528 | /* create the symptom "other arch" object and drop it here |
541 | * under every part of the monster |
529 | * under every part of the monster |
542 | * The victim may well have died. |
530 | * The victim may well have died. |
543 | */ |
531 | */ |
… | |
… | |
546 | victim->play_sound (symptom->sound); |
534 | victim->play_sound (symptom->sound); |
547 | |
535 | |
548 | if (symptom->other_arch) |
536 | if (symptom->other_arch) |
549 | for (object *tmp = victim->head_ (); tmp; tmp = tmp->more) |
537 | for (object *tmp = victim->head_ (); tmp; tmp = tmp->more) |
550 | { |
538 | { |
551 | new_ob = arch_to_object (symptom->other_arch); |
539 | object *new_ob = symptom->other_arch->instance (); |
552 | new_ob->x = tmp->x; |
540 | new_ob->x = tmp->x; |
553 | new_ob->y = tmp->y; |
541 | new_ob->y = tmp->y; |
554 | new_ob->map = victim->map; |
542 | new_ob->map = victim->map; |
555 | insert_ob_in_map (new_ob, victim->map, victim, 0); |
543 | insert_ob_in_map (new_ob, victim->map, victim, 0); |
556 | } |
544 | } |
557 | } |
545 | } |
|
|
546 | |
|
|
547 | int damage = |
|
|
548 | symptom->stats.dam > 0 |
|
|
549 | ? symptom->stats.dam |
|
|
550 | : max (1, victim->stats.maxhp * -symptom->stats.dam / 100); |
|
|
551 | |
|
|
552 | hit_player (victim, damage, symptom, symptom->attacktype, 1); |
|
|
553 | |
|
|
554 | int sp_reduce = |
|
|
555 | symptom->stats.maxsp > 0 |
|
|
556 | ? symptom->stats.maxsp |
|
|
557 | : max (1, victim->stats.maxsp * -symptom->stats.maxsp / 100); |
|
|
558 | |
|
|
559 | victim->stats.sp = max (0, victim->stats.sp - sp_reduce); |
558 | |
560 | |
559 | new_draw_info (NDI_UNIQUE | NDI_RED, 0, victim, symptom->msg); |
561 | new_draw_info (NDI_UNIQUE | NDI_RED, 0, victim, symptom->msg); |
560 | |
562 | |
561 | return 1; |
563 | return 1; |
562 | } |
564 | } |