ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/disease.C
(Generate patch)

Comparing deliantra/server/server/disease.C (file contents):
Revision 1.7 by root, Thu Oct 5 16:50:07 2006 UTC vs.
Revision 1.20 by root, Sun Apr 29 18:11:21 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22*/ 23 */
23 24
24/* This file contains all the code implementing diseases, 25/* This file contains all the code implementing diseases,
25 except for odds and ends in attack.c and in 26 except for odds and ends in attack.c and in
26 living.c*/ 27 living.c*/
27 28
126 127
127 128
128#include <global.h> 129#include <global.h>
129#include <object.h> 130#include <object.h>
130#include <living.h> 131#include <living.h>
131#ifndef __CEXTRACT__
132# include <sproto.h> 132#include <sproto.h>
133#endif
134#include <spells.h> 133#include <spells.h>
135#include <sounds.h> 134#include <sounds.h>
136#include <skills.h> 135#include <skills.h>
137 136
138/* IMPLEMENTATION NOTES 137/* IMPLEMENTATION NOTES
170 169
171 if (disease->env == NULL) 170 if (disease->env == NULL)
172 { /* we're outside of someone */ 171 { /* we're outside of someone */
173 if (disease->stats.maxhp > 0) 172 if (disease->stats.maxhp > 0)
174 disease->value--; 173 disease->value--;
174
175 if (disease->value == 0) 175 if (disease->value == 0)
176 { 176 {
177 remove_ob (disease); 177 disease->destroy ();
178 free_object (disease);
179 return 1; 178 return 1;
180 } 179 }
181 } 180 }
182 else 181 else
183 { 182 {
184 /* if we're inside a person, have the disease run its course */ 183 /* if we're inside a person, have the disease run its course */
185 /* negative foods denote "perpetual" diseases. */ 184 /* negative foods denote "perpetual" diseases. */
186 if (disease->stats.food > 0) 185 if (disease->stats.food > 0)
187 { 186 {
188 disease->stats.food--; 187 disease->stats.food--;
188
189 if (disease->stats.food == 0) 189 if (disease->stats.food == 0)
190 { 190 {
191 remove_symptoms (disease); /* remove the symptoms of this disease */ 191 remove_symptoms (disease); /* remove the symptoms of this disease */
192 grant_immunity (disease); 192 grant_immunity (disease);
193 remove_ob (disease); 193 disease->destroy ();
194 free_object (disease);
195 return 1; 194 return 1;
196 } 195 }
197 } 196 }
198 } 197 }
198
199 /* check to see if we infect others */ 199 /* check to see if we infect others */
200 check_infection (disease); 200 check_infection (disease);
201 201
202 /* impose or modify the symptoms of the disease */ 202 /* impose or modify the symptoms of the disease */
203 if (disease->env && is_susceptible_to_disease (disease->env, disease)) 203 if (disease->env && is_susceptible_to_disease (disease->env, disease))
220 220
221 while ((symptom = find_symptom (disease)) != NULL) 221 while ((symptom = find_symptom (disease)) != NULL)
222 { 222 {
223 if (!victim) 223 if (!victim)
224 victim = symptom->env; 224 victim = symptom->env;
225 remove_ob (symptom); 225
226 free_object (symptom); 226 symptom->destroy ();
227 } 227 }
228
228 if (victim) 229 if (victim)
229 fix_player (victim); 230 victim->update_stats ();
230 return 0; 231 return 0;
231} 232}
232 233
233/* argument is a disease */ 234/* argument is a disease */
234object * 235object *
236{ 237{
237 object *walk; 238 object *walk;
238 239
239 /* check the inventory for symptoms */ 240 /* check the inventory for symptoms */
240 for (walk = disease->env->inv; walk; walk = walk->below) 241 for (walk = disease->env->inv; walk; walk = walk->below)
241 if (!strcmp (walk->name, disease->name) && walk->type == SYMPTOM) 242 if (walk->name == disease->name && walk->type == SYMPTOM)
242 return walk; 243 return walk;
243 return NULL; 244 return NULL;
244} 245}
245 246
246/* searches around for more victims to infect */ 247/* searches around for more victims to infect */
274 { 275 {
275 sint16 i2, j2; 276 sint16 i2, j2;
276 mflags = get_map_flags (map, &map2, i, j, &i2, &j2); 277 mflags = get_map_flags (map, &map2, i, j, &i2, &j2);
277 278
278 if (!(mflags & P_OUT_OF_MAP) && (mflags & P_IS_ALIVE)) 279 if (!(mflags & P_OUT_OF_MAP) && (mflags & P_IS_ALIVE))
279 for (tmp = get_map_ob (map2, i2, j2); tmp; tmp = tmp->above) 280 for (tmp = GET_MAP_OB (map2, i2, j2); tmp; tmp = tmp->above)
280 infect_object (tmp, disease, 0); 281 infect_object (tmp, disease, 0);
281 } 282 }
282 283
283 return 1; 284 return 1;
284} 285}
322 * (eg, level 1 cold, level 2 cold, level 3 cold, etc), as long as 323 * (eg, level 1 cold, level 2 cold, level 3 cold, etc), as long as
323 * they were cast in that same order. Instead, change it so that 324 * they were cast in that same order. Instead, change it so that
324 * if you diseased, you can't get diseased more. 325 * if you diseased, you can't get diseased more.
325 */ 326 */
326 327
327 for ( /* tmp initialized in if, above */ ; tmp; tmp = tmp->below) 328 for ( /* tmp initialised in if, above */ ; tmp; tmp = tmp->below)
328 { 329 {
329 if (tmp->type == SIGN && !strcmp (tmp->name, disease->name) && tmp->level >= disease->level) 330 if (tmp->type == SIGN && tmp->name == disease->name && tmp->level >= disease->level)
330 return 0; /*Immune! */ 331 return 0; /* Immune! */
331 else if (tmp->type == DISEASE && !strcmp (tmp->name, disease->name)) 332 else if (tmp->type == DISEASE && tmp->name == disease->name)
332 return 0; /* already diseased */ 333 return 0; /* already diseased */
333 } 334 }
334 335
335 /* If we've gotten this far, go ahead and infect the victim. */ 336 /* If we've gotten this far, go ahead and infect the victim. */
336 new_disease = get_object (); 337 new_disease = disease->clone ();
337 copy_object (disease, new_disease);
338 new_disease->stats.food = disease->stats.maxgrace; 338 new_disease->stats.food = disease->stats.maxgrace;
339 new_disease->value = disease->stats.maxhp; 339 new_disease->value = disease->stats.maxhp;
340 new_disease->stats.wc -= disease->last_grace; /* self-limiting factor */ 340 new_disease->stats.wc -= disease->last_grace; /* self-limiting factor */
341 341
342 /* Unfortunately, set_owner does the wrong thing to the skills pointers 342 /* Unfortunately, set_owner does the wrong thing to the skills pointers
343 * resulting in exp going into the owners *current* chosen skill. 343 * resulting in exp going into the owners *current* chosen skill.
344 */ 344 */
345 345
346 if (get_owner (disease)) 346 if (disease->owner)
347 { 347 {
348 set_owner (new_disease, disease->owner); 348 new_disease->set_owner (disease->owner);
349 349
350 /* Only need to update skill if different */ 350 /* Only need to update skill if different */
351 if (new_disease->skill != disease->skill) 351 if (new_disease->skill != disease->skill)
352 new_disease->skill = disease->skill; 352 new_disease->skill = disease->skill;
353 } 353 }
355 { /* for diseases which are passed by hitting, set owner and praying skill */ 355 { /* for diseases which are passed by hitting, set owner and praying skill */
356 if (disease->env && disease->env->type == PLAYER) 356 if (disease->env && disease->env->type == PLAYER)
357 { 357 {
358 object *player = disease->env; 358 object *player = disease->env;
359 359
360 set_owner (new_disease, player); 360 new_disease->set_owner (player);
361 361
362 /* the skill pointer for these diseases should already be set up - 362 /* the skill pointer for these diseases should already be set up -
363 * hardcoding in 'praying' is not the right approach. 363 * hardcoding in 'praying' is not the right approach.
364 */ 364 */
365 } 365 }
432 if (victim->head) 432 if (victim->head)
433 tmp = victim->head->inv; 433 tmp = victim->head->inv;
434 else 434 else
435 tmp = victim->inv; 435 tmp = victim->inv;
436 436
437 for ( /* tmp initialized in if, above */ ; tmp; tmp = tmp->below) 437 for ( /* tmp initialised in if, above */ ; tmp; tmp = tmp->below)
438 { 438 {
439 if (tmp->type == SIGN) /* possibly an immunity, or diseased */ 439 if (tmp->type == SIGN) /* possibly an immunity, or diseased */
440 if (!strcmp (tmp->name, disease->name) && tmp->level >= disease->level) 440 if (tmp->name == disease->name && tmp->level >= disease->level)
441 return 0; /*Immune! */ 441 return 0; /*Immune! */
442 } 442 }
443 443
444 new_symptom = get_archetype (ARCH_SYMPTOM); 444 new_symptom = get_archetype (ARCH_SYMPTOM);
445 445
451 { 451 {
452 int dam = disease->stats.dam; 452 int dam = disease->stats.dam;
453 453
454 /* reduce the damage, on average, 50%, and making things random. */ 454 /* reduce the damage, on average, 50%, and making things random. */
455 455
456 dam = random_roll (1, FABS (dam), victim, PREFER_LOW); 456 dam = random_roll (1, abs (dam), victim, PREFER_LOW);
457 if (disease->stats.dam < 0) 457 if (disease->stats.dam < 0)
458 dam = -dam; 458 dam = -dam;
459 new_symptom->stats.dam = dam; 459 new_symptom->stats.dam = dam;
460 } 460 }
461 461
483 new_symptom->stats.hp = disease->stats.hp; 483 new_symptom->stats.hp = disease->stats.hp;
484 new_symptom->msg = disease->msg; 484 new_symptom->msg = disease->msg;
485 new_symptom->attacktype = disease->attacktype; 485 new_symptom->attacktype = disease->attacktype;
486 new_symptom->other_arch = disease->other_arch; 486 new_symptom->other_arch = disease->other_arch;
487 487
488 set_owner (new_symptom, disease->owner); 488 new_symptom->set_owner (disease->owner);
489 489
490 if (new_symptom->skill != disease->skill) 490 if (new_symptom->skill != disease->skill)
491 new_symptom->skill = disease->skill; 491 new_symptom->skill = disease->skill;
492 492
493 new_symptom->move_block = 0; 493 new_symptom->move_block = 0;
523 symptom->msg = disease->msg; 523 symptom->msg = disease->msg;
524 symptom->attacktype = disease->attacktype; 524 symptom->attacktype = disease->attacktype;
525 symptom->other_arch = disease->other_arch; 525 symptom->other_arch = disease->other_arch;
526 } 526 }
527 SET_FLAG (symptom, FLAG_APPLIED); 527 SET_FLAG (symptom, FLAG_APPLIED);
528 fix_player (victim); 528 victim->update_stats ();
529 return 1; 529 return 1;
530} 530}
531 531
532 532
533/* grants immunity to plagues we've seen before. */ 533/* grants immunity to plagues we've seen before. */
541 if (disease->last_heal) 541 if (disease->last_heal)
542 return 0; 542 return 0;
543 /* first, search for an immunity of the same name */ 543 /* first, search for an immunity of the same name */
544 for (walk = disease->env->inv; walk; walk = walk->below) 544 for (walk = disease->env->inv; walk; walk = walk->below)
545 { 545 {
546 if (walk->type == 98 && !strcmp (disease->name, walk->name)) 546 if (walk->type == 98 && disease->name == walk->name)
547 { 547 {
548 walk->level = disease->level; 548 walk->level = disease->level;
549 return 1; /* just update the existing immunity. */ 549 return 1; /* just update the existing immunity. */
550 } 550 }
551 } 551 }
568 object *new_ob; 568 object *new_ob;
569 int sp_reduce; 569 int sp_reduce;
570 570
571 if (victim == NULL || victim->map == NULL) 571 if (victim == NULL || victim->map == NULL)
572 { /* outside a monster/player, die immediately */ 572 { /* outside a monster/player, die immediately */
573 remove_ob (symptom); 573 symptom->destroy ();
574 free_object (symptom);
575 return 0; 574 return 0;
576 } 575 }
577 576
578 if (symptom->stats.dam > 0) 577 if (symptom->stats.dam > 0)
579 hit_player (victim, symptom->stats.dam, symptom, symptom->attacktype, 1); 578 hit_player (victim, symptom->stats.dam, symptom, symptom->attacktype, 1);
598 object *tmp; 597 object *tmp;
599 598
600 tmp = victim; 599 tmp = victim;
601 if (tmp->head != NULL) 600 if (tmp->head != NULL)
602 tmp = tmp->head; 601 tmp = tmp->head;
603 for ( /*tmp initialized above */ ; tmp != NULL; tmp = tmp->more) 602 for ( /*tmp initialised above */ ; tmp != NULL; tmp = tmp->more)
604 { 603 {
605 new_ob = arch_to_object (symptom->other_arch); 604 new_ob = arch_to_object (symptom->other_arch);
606 new_ob->x = tmp->x; 605 new_ob->x = tmp->x;
607 new_ob->y = tmp->y; 606 new_ob->y = tmp->y;
608 new_ob->map = victim->map; 607 new_ob->map = victim->map;
612 new_draw_info (NDI_UNIQUE | NDI_RED, 0, victim, symptom->msg); 611 new_draw_info (NDI_UNIQUE | NDI_RED, 0, victim, symptom->msg);
613 612
614 return 1; 613 return 1;
615} 614}
616 615
617
618/* possibly infect due to direct physical contact 616/* possibly infect due to direct physical contact
619 i.e., AT_PHYSICAL-- called from "hit_player_attacktype" */ 617 * i.e., AT_PHYSICAL-- called from "hit_player_attacktype" */
620
621int 618int
622check_physically_infect (object *victim, object *hitter) 619check_physically_infect (object *victim, object *hitter)
623{ 620{
624 object *walk;
625
626 /* search for diseases, give every disease a chance to infect */ 621 /* search for diseases, give every disease a chance to infect */
627 for (walk = hitter->inv; walk != NULL; walk = walk->below) 622 for (object *disease = hitter->inv; disease; disease = disease->below)
628 if (walk->type == DISEASE) 623 if (disease->type == DISEASE)
629 infect_object (victim, walk, 0); 624 infect_object (victim, disease, 0);
625
630 return 1; 626 return 1;
631} 627}
632 628
633/* find a disease in someone*/ 629// find a disease in someone
634object * 630object *
635find_disease (object *victim) 631find_disease (object *victim)
636{ 632{
637 object *walk; 633 for (object *disease = victim->inv; disease; disease = disease->below)
638
639 for (walk = victim->inv; walk; walk = walk->below)
640 if (walk->type == DISEASE) 634 if (disease->type == DISEASE)
641 return walk; 635 return disease;
636
642 return NULL; 637 return 0;
643} 638}
644 639
645/* do the cure disease stuff, from the spell "cure disease" */ 640/* do the cure disease stuff, from the spell "cure disease" */
646 641
647int 642int
669 */ 664 */
670 if ((casting_level >= disease->level) || (!(random_roll (0, (disease->level - casting_level - 1), caster, PREFER_LOW)))) 665 if ((casting_level >= disease->level) || (!(random_roll (0, (disease->level - casting_level - 1), caster, PREFER_LOW))))
671 { 666 {
672 667
673 remove_symptoms (disease); 668 remove_symptoms (disease);
674 remove_ob (disease);
675 cure = 1; 669 cure = 1;
670
676 if (caster) 671 if (caster)
677 change_exp (caster, disease->stats.exp, caster->chosen_skill ? &caster->chosen_skill->skill : (const char *) 0, 0); 672 change_exp (caster, disease->stats.exp, caster->chosen_skill ? &caster->chosen_skill->skill : (const char *) 0, 0);
678 free_object (disease); 673
674 disease->destroy ();
679 } 675 }
680 } 676 }
681 } 677 }
682 if (cure) 678 if (cure)
683 { 679 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines