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.23 by root, Mon May 14 21:32:27 2007 UTC vs.
Revision 1.31 by root, Tue Aug 7 22:57:57 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * 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
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25/* This file contains all the code implementing diseases, 24/* This file contains all the code implementing diseases,
26 * except for odds and ends in attack.c and in 25 * except for odds and ends in attack.c and in
148 return 0; 147 return 0;
149 148
150 if (strstr (disease->race, "*") && !QUERY_FLAG (victim, FLAG_UNDEAD)) 149 if (strstr (disease->race, "*") && !QUERY_FLAG (victim, FLAG_UNDEAD))
151 return 1; 150 return 1;
152 151
153 if ((disease->race == undead_name) && QUERY_FLAG (victim, FLAG_UNDEAD)) 152 if ((disease->race == shstr_undead) && QUERY_FLAG (victim, FLAG_UNDEAD))
154 return 1; 153 return 1;
155 154
156 if ((victim->race && strstr (disease->race, victim->race)) || strstr (disease->race, victim->name)) 155 if ((victim->race && strstr (disease->race, victim->race)) || strstr (disease->race, victim->name))
157 return 1; 156 return 1;
158 157
164{ 163{
165 /* first task is to determine if the disease is inside or outside of someone. 164 /* first task is to determine if the disease is inside or outside of someone.
166 * If outside, we decrement 'value' until we're gone. 165 * If outside, we decrement 'value' until we're gone.
167 */ 166 */
168 167
169 if (disease->env == NULL) 168 if (!disease->env)
170 { /* we're outside of someone */ 169 { /* we're outside of someone */
171 if (disease->stats.maxhp > 0) 170 if (disease->stats.maxhp > 0)
172 disease->value--; 171 disease->value--;
173 172
174 if (disease->value == 0) 173 if (!disease->value)
175 { 174 {
176 disease->destroy (); 175 disease->destroy ();
177 return 1; 176 return 1;
178 } 177 }
179 } 178 }
180 else 179 else
181 { 180 {
182 /* if we're inside a person, have the disease run its course */ 181 /* if we're inside a person, have the disease run its course */
183 /* negative foods denote "perpetual" diseases. */ 182 /* negative/zero food denotes "perpetual" diseases. */
184 if (disease->stats.food > 0) 183 if (disease->stats.food > 0)
185 { 184 {
186 disease->stats.food--; 185 disease->stats.food--;
187 186
188 if (disease->stats.food == 0) 187 if (!disease->stats.food)
189 { 188 {
190 remove_symptoms (disease); /* remove the symptoms of this disease */ 189 remove_symptoms (disease); /* remove the symptoms of this disease */
191 grant_immunity (disease); 190 grant_immunity (disease);
192 disease->destroy (); 191 disease->destroy ();
193 return 1; 192 return 1;
225 symptom->destroy (); 224 symptom->destroy ();
226 } 225 }
227 226
228 if (victim) 227 if (victim)
229 victim->update_stats (); 228 victim->update_stats ();
229
230 return 0; 230 return 0;
231} 231}
232 232
233/* argument is a disease */ 233/* argument is a disease */
234object * 234object *
238 238
239 /* check the inventory for symptoms */ 239 /* check the inventory for symptoms */
240 for (walk = disease->env->inv; walk; walk = walk->below) 240 for (walk = disease->env->inv; walk; walk = walk->below)
241 if (walk->name == disease->name && walk->type == SYMPTOM) 241 if (walk->name == disease->name && walk->type == SYMPTOM)
242 return walk; 242 return walk;
243
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 */
247int 248int
362 * hardcoding in 'praying' is not the right approach. 363 * hardcoding in 'praying' is not the right approach.
363 */ 364 */
364 } 365 }
365 } 366 }
366 367
367 insert_ob_in_ob (new_disease, victim); 368 insert_ob_in_ob (new_disease, victim->head_ ());
368 /* This appears to be a horrible case of overloading 'NO_PASS' 369 /* This appears to be a horrible case of overloading 'NO_PASS'
369 * for meaning in the diseases. 370 * for meaning in the diseases.
370 */ 371 */
371 new_disease->move_block = 0; 372 new_disease->move_block = 0;
372 if (new_disease->owner && new_disease->owner->type == PLAYER) 373 if (new_disease->owner && new_disease->owner->type == PLAYER)
384 if (victim->type == PLAYER) 385 if (victim->type == PLAYER)
385 new_draw_info (NDI_UNIQUE | NDI_RED, 0, new_disease->owner, buf); 386 new_draw_info (NDI_UNIQUE | NDI_RED, 0, new_disease->owner, buf);
386 else 387 else
387 new_draw_info (0, 4, new_disease->owner, buf); 388 new_draw_info (0, 4, new_disease->owner, buf);
388 } 389 }
390
389 if (victim->type == PLAYER) 391 if (victim->type == PLAYER)
390 new_draw_info (NDI_UNIQUE | NDI_RED, 0, victim, "You suddenly feel ill."); 392 new_draw_info (NDI_UNIQUE | NDI_RED, 0, victim, "You suddenly feel ill.");
391 393
392 return 1; 394 return 1;
393 395
394} 396}
395
396
397 397
398/* this function monitors the symptoms caused by the disease (if any), 398/* this function monitors the symptoms caused by the disease (if any),
399causes symptoms, and modifies existing symptoms in the case of 399causes symptoms, and modifies existing symptoms in the case of
400existing diseases. */ 400existing diseases. */
401
402int 401int
403do_symptoms (object *disease) 402do_symptoms (object *disease)
404{ 403{
405 object *symptom; 404 object *symptom;
406 object *victim; 405 object *victim;
407 object *tmp; 406 object *tmp;
408 407
409 victim = disease->env; 408 victim = disease->env;
409
410 if (!victim)
411 return 0; /* no-one to inflict symptoms on */
410 412
411 /* This is a quick hack - for whatever reason, disease->env will point 413 /* This is a quick hack - for whatever reason, disease->env will point
412 * back to disease, causing endless loops. Why this happens really needs 414 * back to disease, causing endless loops. Why this happens really needs
413 * to be found, but this should at least prevent the infinite loops. 415 * to be found, but this should at least prevent the infinite loops.
414 */ 416 */
415 417 //TODO: should no longer be the case, monitor, and remove
416 if (victim == NULL || victim == disease) 418 if (victim == disease)
417 return 0; /* no-one to inflict symptoms on */ 419 {
420 LOG (llevError | logBacktrace, "%s: disease->env points to itself", disease->debug_desc ());
421 return 0;
422 }
418 423
419 symptom = find_symptom (disease); 424 symptom = find_symptom (disease);
420 if (symptom == NULL) 425 if (!symptom)
421 { 426 {
422 /* no symptom? need to generate one! */ 427 /* no symptom? need to generate one! */
423 object *new_symptom; 428 object *new_symptom;
424 429
425 /* first check and see if the carrier of the disease is immune. If so, no symptoms! */ 430 /* first check and see if the carrier of the disease is immune. If so, no symptoms! */
432 tmp = victim->head->inv; 437 tmp = victim->head->inv;
433 else 438 else
434 tmp = victim->inv; 439 tmp = victim->inv;
435 440
436 for ( /* tmp initialised in if, above */ ; tmp; tmp = tmp->below) 441 for ( /* tmp initialised in if, above */ ; tmp; tmp = tmp->below)
437 {
438 if (tmp->type == SIGN) /* possibly an immunity, or diseased */ 442 if (tmp->type == SIGN) /* possibly an immunity, or diseased */
439 if (tmp->name == disease->name && tmp->level >= disease->level) 443 if (tmp->name == disease->name && tmp->level >= disease->level)
440 return 0; /*Immune! */ 444 return 0; /*Immune! */
441 }
442 445
443 new_symptom = get_archetype (ARCH_SYMPTOM); 446 new_symptom = get_archetype ("symptom");
444 447
445 /* Something special done with dam. We want diseases to be more 448 /* Something special done with dam. We want diseases to be more
446 * random in what they'll kill, so we'll make the damage they 449 * random in what they'll kill, so we'll make the damage they
447 * do random, note, this has a weird effect with progressive diseases. 450 * do random, note, this has a weird effect with progressive diseases.
448 */ 451 */
453 /* reduce the damage, on average, 50%, and making things random. */ 456 /* reduce the damage, on average, 50%, and making things random. */
454 457
455 dam = random_roll (1, abs (dam), victim, PREFER_LOW); 458 dam = random_roll (1, abs (dam), victim, PREFER_LOW);
456 if (disease->stats.dam < 0) 459 if (disease->stats.dam < 0)
457 dam = -dam; 460 dam = -dam;
461
458 new_symptom->stats.dam = dam; 462 new_symptom->stats.dam = dam;
459 } 463 }
460 464
461
462 new_symptom->stats.maxsp = disease->stats.maxsp; 465 new_symptom->stats.maxsp = disease->stats.maxsp;
463 new_symptom->stats.food = new_symptom->stats.maxgrace; 466 new_symptom->stats.food = new_symptom->stats.maxgrace;
464 467
465 new_symptom->name = new_symptom->name_pl = disease->name; 468 new_symptom->name = new_symptom->name_pl = disease->name;
466 469
467 new_symptom->level = disease->level; 470 new_symptom->level = disease->level;
468 new_symptom->speed = disease->speed; 471 new_symptom->speed = disease->speed;
469 new_symptom->value = 0; 472 new_symptom->value = 0;
470 473
471 for (int i = 0; i < NUM_STATS; ++i) 474 for (int i = 0; i < NUM_STATS; ++i)
472 new_symptom->stats.stat (i) = disease->stats.stat (i); 475 new_symptom->stats.stat (i) = disease->stats.stat (i);
473 476
474 new_symptom->stats.sp = disease->stats.sp; 477 new_symptom->stats.sp = disease->stats.sp;
475 new_symptom->stats.food = disease->last_eat; 478 new_symptom->stats.food = disease->last_eat;
476 new_symptom->stats.maxsp = disease->stats.maxsp; 479 new_symptom->stats.maxsp = disease->stats.maxsp;
477 new_symptom->last_sp = disease->last_sp; 480 new_symptom->last_sp = disease->last_sp;
478 new_symptom->stats.exp = 0; 481 new_symptom->stats.exp = 0;
479 new_symptom->stats.hp = disease->stats.hp; 482 new_symptom->stats.hp = disease->stats.hp;
480 new_symptom->msg = disease->msg; 483 new_symptom->msg = disease->msg;
481 new_symptom->attacktype = disease->attacktype; 484 new_symptom->attacktype = disease->attacktype;
482 new_symptom->other_arch = disease->other_arch; 485 new_symptom->other_arch = disease->other_arch;
483 486
484 new_symptom->set_owner (disease->owner); 487 new_symptom->set_owner (disease->owner);
485 488
486 if (new_symptom->skill != disease->skill) 489 if (new_symptom->skill != disease->skill)
487 new_symptom->skill = disease->skill; 490 new_symptom->skill = disease->skill;
492 } 495 }
493 496
494 /* now deal with progressing diseases: we increase the debility 497 /* now deal with progressing diseases: we increase the debility
495 * caused by the symptoms. 498 * caused by the symptoms.
496 */ 499 */
497 if (disease->stats.ac != 0) 500 if (disease->stats.ac)
498 { 501 {
499 symptom->value += disease->stats.ac; 502 symptom->value = clamp (symptom->value + disease->stats.ac, 0, 100*100);
500 503
501 float scale = 1.f + symptom->value / 100.f; 504 float scale = 1.f + symptom->value / 100.f;
502 505
503 /* now rescale all the debilities */ 506 /* now rescale all the debilities */
504 for (int i = 0; i < NUM_STATS; ++i) 507 for (int i = 0; i < NUM_STATS; ++i)
505 symptom->stats.stat (i) = scale * disease->stats.stat (i); 508 symptom->stats.stat (i) = clamp (int (scale * disease->stats.stat (i)), -128, 127);
506 509
507 symptom->stats.dam = scale * disease->stats.dam; 510 symptom->stats.dam = clamp (scale * disease->stats.dam , -1024, 1024);
508 symptom->stats.sp = scale * disease->stats.sp;
509 symptom->stats.food = scale * disease->last_eat; 511 symptom->stats.food = clamp (scale * disease->last_eat , -1024, 1024);
510 symptom->stats.maxsp = scale * disease->stats.maxsp; 512 symptom->stats.maxsp = clamp (scale * disease->stats.maxsp, -1024, 1024);
511 symptom->last_sp = scale * disease->last_sp; 513 symptom->last_sp = clamp (scale * disease->last_sp , -1024, 1024);
514 symptom->stats.sp = clamp (scale * disease->stats.sp , -1024, 1024);
515 symptom->stats.hp = clamp (scale * disease->stats.hp , -1024, 1024);
512 symptom->stats.exp = 0; 516 symptom->stats.exp = 0;
513 symptom->stats.hp = scale * disease->stats.hp;
514 517
515 symptom->msg = disease->msg; 518 symptom->msg = disease->msg;
516 symptom->attacktype = disease->attacktype; 519 symptom->attacktype = disease->attacktype;
517 symptom->other_arch = disease->other_arch; 520 symptom->other_arch = disease->other_arch;
518 } 521 }
519 522
520 SET_FLAG (symptom, FLAG_APPLIED); 523 SET_FLAG (symptom, FLAG_APPLIED);
521 victim->update_stats (); 524 victim->update_stats ();
522 525
680} 683}
681 684
682/* reduces disease progression: reduce_symptoms 685/* reduces disease progression: reduce_symptoms
683 * return true if we actually reduce a disease. 686 * return true if we actually reduce a disease.
684 */ 687 */
685
686int 688int
687reduce_symptoms (object *sufferer, int reduction) 689reduce_symptoms (object *sufferer, int reduction)
688{ 690{
689 object *walk; 691 object *walk;
690 int success = 0; 692 int success = 0;
694 if (walk->type == SYMPTOM) 696 if (walk->type == SYMPTOM)
695 { 697 {
696 if (walk->value > 0) 698 if (walk->value > 0)
697 { 699 {
698 success = 1; 700 success = 1;
699 walk->value = MAX (0, walk->value - 2 * reduction); 701 walk->value = max (0, walk->value - 2 * reduction);
700 /* give the disease time to modify this symptom, 702 /* give the disease time to modify this symptom,
701 * and reduce its severity. */ 703 * and reduce its severity. */
702 walk->speed_left = 0; 704 walk->speed_left = 0;
703 } 705 }
704 } 706 }
705 } 707 }
708
706 if (success) 709 if (success)
707 new_draw_info (NDI_UNIQUE, 0, sufferer, "Your illness seems less severe."); 710 new_draw_info (NDI_UNIQUE, 0, sufferer, "Your illness seems less severe.");
711
708 return success; 712 return success;
709} 713}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines