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.27 by root, Sun Jul 1 05:00:19 2007 UTC vs.
Revision 1.31 by root, Tue Aug 7 22:57:57 2007 UTC

147 return 0; 147 return 0;
148 148
149 if (strstr (disease->race, "*") && !QUERY_FLAG (victim, FLAG_UNDEAD)) 149 if (strstr (disease->race, "*") && !QUERY_FLAG (victim, FLAG_UNDEAD))
150 return 1; 150 return 1;
151 151
152 if ((disease->race == undead_name) && QUERY_FLAG (victim, FLAG_UNDEAD)) 152 if ((disease->race == shstr_undead) && QUERY_FLAG (victim, FLAG_UNDEAD))
153 return 1; 153 return 1;
154 154
155 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))
156 return 1; 156 return 1;
157 157
163{ 163{
164 /* 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.
165 * If outside, we decrement 'value' until we're gone. 165 * If outside, we decrement 'value' until we're gone.
166 */ 166 */
167 167
168 if (disease->env == NULL) 168 if (!disease->env)
169 { /* we're outside of someone */ 169 { /* we're outside of someone */
170 if (disease->stats.maxhp > 0) 170 if (disease->stats.maxhp > 0)
171 disease->value--; 171 disease->value--;
172 172
173 if (disease->value == 0) 173 if (!disease->value)
174 { 174 {
175 disease->destroy (); 175 disease->destroy ();
176 return 1; 176 return 1;
177 } 177 }
178 } 178 }
179 else 179 else
180 { 180 {
181 /* 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 */
182 /* negative foods denote "perpetual" diseases. */ 182 /* negative/zero food denotes "perpetual" diseases. */
183 if (disease->stats.food > 0) 183 if (disease->stats.food > 0)
184 { 184 {
185 disease->stats.food--; 185 disease->stats.food--;
186 186
187 if (disease->stats.food == 0) 187 if (!disease->stats.food)
188 { 188 {
189 remove_symptoms (disease); /* remove the symptoms of this disease */ 189 remove_symptoms (disease); /* remove the symptoms of this disease */
190 grant_immunity (disease); 190 grant_immunity (disease);
191 disease->destroy (); 191 disease->destroy ();
192 return 1; 192 return 1;
224 symptom->destroy (); 224 symptom->destroy ();
225 } 225 }
226 226
227 if (victim) 227 if (victim)
228 victim->update_stats (); 228 victim->update_stats ();
229
229 return 0; 230 return 0;
230} 231}
231 232
232/* argument is a disease */ 233/* argument is a disease */
233object * 234object *
237 238
238 /* check the inventory for symptoms */ 239 /* check the inventory for symptoms */
239 for (walk = disease->env->inv; walk; walk = walk->below) 240 for (walk = disease->env->inv; walk; walk = walk->below)
240 if (walk->name == disease->name && walk->type == SYMPTOM) 241 if (walk->name == disease->name && walk->type == SYMPTOM)
241 return walk; 242 return walk;
243
242 return NULL; 244 return NULL;
243} 245}
244 246
245/* searches around for more victims to infect */ 247/* searches around for more victims to infect */
246int 248int
383 if (victim->type == PLAYER) 385 if (victim->type == PLAYER)
384 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);
385 else 387 else
386 new_draw_info (0, 4, new_disease->owner, buf); 388 new_draw_info (0, 4, new_disease->owner, buf);
387 } 389 }
390
388 if (victim->type == PLAYER) 391 if (victim->type == PLAYER)
389 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.");
390 393
391 return 1; 394 return 1;
392 395
393} 396}
394
395
396 397
397/* this function monitors the symptoms caused by the disease (if any), 398/* this function monitors the symptoms caused by the disease (if any),
398causes symptoms, and modifies existing symptoms in the case of 399causes symptoms, and modifies existing symptoms in the case of
399existing diseases. */ 400existing diseases. */
400
401int 401int
402do_symptoms (object *disease) 402do_symptoms (object *disease)
403{ 403{
404 object *symptom; 404 object *symptom;
405 object *victim; 405 object *victim;
406 object *tmp; 406 object *tmp;
407 407
408 victim = disease->env; 408 victim = disease->env;
409
410 if (!victim)
411 return 0; /* no-one to inflict symptoms on */
409 412
410 /* 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
411 * back to disease, causing endless loops. Why this happens really needs 414 * back to disease, causing endless loops. Why this happens really needs
412 * 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.
413 */ 416 */
414 417 //TODO: should no longer be the case, monitor, and remove
415 if (victim == NULL || victim == disease) 418 if (victim == disease)
416 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 }
417 423
418 symptom = find_symptom (disease); 424 symptom = find_symptom (disease);
419 if (symptom == NULL) 425 if (!symptom)
420 { 426 {
421 /* no symptom? need to generate one! */ 427 /* no symptom? need to generate one! */
422 object *new_symptom; 428 object *new_symptom;
423 429
424 /* 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! */
431 tmp = victim->head->inv; 437 tmp = victim->head->inv;
432 else 438 else
433 tmp = victim->inv; 439 tmp = victim->inv;
434 440
435 for ( /* tmp initialised in if, above */ ; tmp; tmp = tmp->below) 441 for ( /* tmp initialised in if, above */ ; tmp; tmp = tmp->below)
436 {
437 if (tmp->type == SIGN) /* possibly an immunity, or diseased */ 442 if (tmp->type == SIGN) /* possibly an immunity, or diseased */
438 if (tmp->name == disease->name && tmp->level >= disease->level) 443 if (tmp->name == disease->name && tmp->level >= disease->level)
439 return 0; /*Immune! */ 444 return 0; /*Immune! */
440 }
441 445
442 new_symptom = get_archetype ("symptom"); 446 new_symptom = get_archetype ("symptom");
443 447
444 /* Something special done with dam. We want diseases to be more 448 /* Something special done with dam. We want diseases to be more
445 * 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
452 /* reduce the damage, on average, 50%, and making things random. */ 456 /* reduce the damage, on average, 50%, and making things random. */
453 457
454 dam = random_roll (1, abs (dam), victim, PREFER_LOW); 458 dam = random_roll (1, abs (dam), victim, PREFER_LOW);
455 if (disease->stats.dam < 0) 459 if (disease->stats.dam < 0)
456 dam = -dam; 460 dam = -dam;
461
457 new_symptom->stats.dam = dam; 462 new_symptom->stats.dam = dam;
458 } 463 }
459 464
460
461 new_symptom->stats.maxsp = disease->stats.maxsp; 465 new_symptom->stats.maxsp = disease->stats.maxsp;
462 new_symptom->stats.food = new_symptom->stats.maxgrace; 466 new_symptom->stats.food = new_symptom->stats.maxgrace;
463 467
464 new_symptom->name = new_symptom->name_pl = disease->name; 468 new_symptom->name = new_symptom->name_pl = disease->name;
465 469
466 new_symptom->level = disease->level; 470 new_symptom->level = disease->level;
467 new_symptom->speed = disease->speed; 471 new_symptom->speed = disease->speed;
468 new_symptom->value = 0; 472 new_symptom->value = 0;
469 473
470 for (int i = 0; i < NUM_STATS; ++i) 474 for (int i = 0; i < NUM_STATS; ++i)
471 new_symptom->stats.stat (i) = disease->stats.stat (i); 475 new_symptom->stats.stat (i) = disease->stats.stat (i);
472 476
473 new_symptom->stats.sp = disease->stats.sp; 477 new_symptom->stats.sp = disease->stats.sp;
474 new_symptom->stats.food = disease->last_eat; 478 new_symptom->stats.food = disease->last_eat;
475 new_symptom->stats.maxsp = disease->stats.maxsp; 479 new_symptom->stats.maxsp = disease->stats.maxsp;
476 new_symptom->last_sp = disease->last_sp; 480 new_symptom->last_sp = disease->last_sp;
477 new_symptom->stats.exp = 0; 481 new_symptom->stats.exp = 0;
478 new_symptom->stats.hp = disease->stats.hp; 482 new_symptom->stats.hp = disease->stats.hp;
479 new_symptom->msg = disease->msg; 483 new_symptom->msg = disease->msg;
480 new_symptom->attacktype = disease->attacktype; 484 new_symptom->attacktype = disease->attacktype;
481 new_symptom->other_arch = disease->other_arch; 485 new_symptom->other_arch = disease->other_arch;
482 486
483 new_symptom->set_owner (disease->owner); 487 new_symptom->set_owner (disease->owner);
484 488
485 if (new_symptom->skill != disease->skill) 489 if (new_symptom->skill != disease->skill)
486 new_symptom->skill = disease->skill; 490 new_symptom->skill = disease->skill;
491 } 495 }
492 496
493 /* now deal with progressing diseases: we increase the debility 497 /* now deal with progressing diseases: we increase the debility
494 * caused by the symptoms. 498 * caused by the symptoms.
495 */ 499 */
496 if (disease->stats.ac != 0) 500 if (disease->stats.ac)
497 { 501 {
498 symptom->value += disease->stats.ac; 502 symptom->value = clamp (symptom->value + disease->stats.ac, 0, 100*100);
499 503
500 float scale = 1.f + symptom->value / 100.f; 504 float scale = 1.f + symptom->value / 100.f;
501 505
502 /* now rescale all the debilities */ 506 /* now rescale all the debilities */
503 for (int i = 0; i < NUM_STATS; ++i) 507 for (int i = 0; i < NUM_STATS; ++i)
504 symptom->stats.stat (i) = scale * disease->stats.stat (i); 508 symptom->stats.stat (i) = clamp (int (scale * disease->stats.stat (i)), -128, 127);
505 509
506 symptom->stats.dam = scale * disease->stats.dam; 510 symptom->stats.dam = clamp (scale * disease->stats.dam , -1024, 1024);
507 symptom->stats.sp = scale * disease->stats.sp;
508 symptom->stats.food = scale * disease->last_eat; 511 symptom->stats.food = clamp (scale * disease->last_eat , -1024, 1024);
509 symptom->stats.maxsp = scale * disease->stats.maxsp; 512 symptom->stats.maxsp = clamp (scale * disease->stats.maxsp, -1024, 1024);
510 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);
511 symptom->stats.exp = 0; 516 symptom->stats.exp = 0;
512 symptom->stats.hp = scale * disease->stats.hp;
513 517
514 symptom->msg = disease->msg; 518 symptom->msg = disease->msg;
515 symptom->attacktype = disease->attacktype; 519 symptom->attacktype = disease->attacktype;
516 symptom->other_arch = disease->other_arch; 520 symptom->other_arch = disease->other_arch;
517 } 521 }
518 522
519 SET_FLAG (symptom, FLAG_APPLIED); 523 SET_FLAG (symptom, FLAG_APPLIED);
520 victim->update_stats (); 524 victim->update_stats ();
521 525
679} 683}
680 684
681/* reduces disease progression: reduce_symptoms 685/* reduces disease progression: reduce_symptoms
682 * return true if we actually reduce a disease. 686 * return true if we actually reduce a disease.
683 */ 687 */
684
685int 688int
686reduce_symptoms (object *sufferer, int reduction) 689reduce_symptoms (object *sufferer, int reduction)
687{ 690{
688 object *walk; 691 object *walk;
689 int success = 0; 692 int success = 0;
693 if (walk->type == SYMPTOM) 696 if (walk->type == SYMPTOM)
694 { 697 {
695 if (walk->value > 0) 698 if (walk->value > 0)
696 { 699 {
697 success = 1; 700 success = 1;
698 walk->value = MAX (0, walk->value - 2 * reduction); 701 walk->value = max (0, walk->value - 2 * reduction);
699 /* give the disease time to modify this symptom, 702 /* give the disease time to modify this symptom,
700 * and reduce its severity. */ 703 * and reduce its severity. */
701 walk->speed_left = 0; 704 walk->speed_left = 0;
702 } 705 }
703 } 706 }
704 } 707 }
708
705 if (success) 709 if (success)
706 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
707 return success; 712 return success;
708} 713}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines