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.3 by root, Sun Sep 3 00:18:42 2006 UTC vs.
Revision 1.4 by root, Sun Sep 10 15:59:57 2006 UTC

1
1/* 2/*
2 * static char *rcsid_disease_c = 3 * static char *rcsid_disease_c =
3 * "$Id: disease.C,v 1.3 2006/09/03 00:18:42 root Exp $"; 4 * "$Id: disease.C,v 1.4 2006/09/10 15:59:57 root Exp $";
4 */ 5 */
6
5/* 7/*
6 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
7 9
8 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
9 Copyright (C) 1992 Frank Tore Johansen 11 Copyright (C) 1992 Frank Tore Johansen
131 133
132#include <global.h> 134#include <global.h>
133#include <object.h> 135#include <object.h>
134#include <living.h> 136#include <living.h>
135#ifndef __CEXTRACT__ 137#ifndef __CEXTRACT__
136#include <sproto.h> 138# include <sproto.h>
137#endif 139#endif
138#include <spells.h> 140#include <spells.h>
139#include <sounds.h> 141#include <sounds.h>
140#include <skills.h> 142#include <skills.h>
141 143
145inventory. They themselves do nothing, except modify Symptoms, or 147inventory. They themselves do nothing, except modify Symptoms, or
146spread to other live objects. Symptoms are what actually damage the player: 148spread to other live objects. Symptoms are what actually damage the player:
147these are their own object. */ 149these are their own object. */
148 150
149/* check if victim is susceptible to disease. */ 151/* check if victim is susceptible to disease. */
152static int
150static int is_susceptible_to_disease(object *victim, object *disease) 153is_susceptible_to_disease (object *victim, object *disease)
151{ 154{
152 if(!QUERY_FLAG(victim,FLAG_ALIVE)) return 0; 155 if (!QUERY_FLAG (victim, FLAG_ALIVE))
153
154 if(strstr(disease->race, "*") && !QUERY_FLAG(victim, FLAG_UNDEAD))
155 return 1;
156
157 if((disease->race == undead_name) && QUERY_FLAG(victim, FLAG_UNDEAD))
158 return 1;
159
160 if((victim->race && strstr(disease->race, victim->race)) ||
161 strstr(disease->race, victim->name))
162 return 1;
163
164 return 0; 156 return 0;
165}
166 157
158 if (strstr (disease->race, "*") && !QUERY_FLAG (victim, FLAG_UNDEAD))
159 return 1;
160
161 if ((disease->race == undead_name) && QUERY_FLAG (victim, FLAG_UNDEAD))
162 return 1;
163
164 if ((victim->race && strstr (disease->race, victim->race)) || strstr (disease->race, victim->name))
165 return 1;
166
167 return 0;
168}
169
170int
167int move_disease(object *disease) { 171move_disease (object *disease)
172{
168 /* first task is to determine if the disease is inside or outside of someone. 173 /* first task is to determine if the disease is inside or outside of someone.
169 * If outside, we decrement 'value' until we're gone. 174 * If outside, we decrement 'value' until we're gone.
170 */ 175 */
171 176
172 if(disease->env==NULL) { /* we're outside of someone */ 177 if (disease->env == NULL)
178 { /* we're outside of someone */
173 if ( disease->stats.maxhp > 0 ) disease->value--; 179 if (disease->stats.maxhp > 0)
180 disease->value--;
174 if(disease->value==0) { 181 if (disease->value == 0)
182 {
175 remove_ob(disease); 183 remove_ob (disease);
176 free_object(disease); 184 free_object (disease);
177 return 1; 185 return 1;
178 } 186 }
179 } else { 187 }
188 else
189 {
180 /* if we're inside a person, have the disease run its course */ 190 /* if we're inside a person, have the disease run its course */
181 /* negative foods denote "perpetual" diseases. */ 191 /* negative foods denote "perpetual" diseases. */
182 if(disease->stats.food>0) { 192 if (disease->stats.food > 0)
193 {
183 disease->stats.food--; 194 disease->stats.food--;
184 if (disease->stats.food==0) { 195 if (disease->stats.food == 0)
196 {
185 remove_symptoms(disease); /* remove the symptoms of this disease */ 197 remove_symptoms (disease); /* remove the symptoms of this disease */
186 grant_immunity(disease); 198 grant_immunity (disease);
187 remove_ob(disease); 199 remove_ob (disease);
188 free_object(disease); 200 free_object (disease);
189 return 1; 201 return 1;
190 } 202 }
191 } 203 }
192 } 204 }
193 /* check to see if we infect others */ 205 /* check to see if we infect others */
194 check_infection(disease); 206 check_infection (disease);
195 207
196 /* impose or modify the symptoms of the disease */ 208 /* impose or modify the symptoms of the disease */
197 if(disease->env && is_susceptible_to_disease(disease->env, disease)) 209 if (disease->env && is_susceptible_to_disease (disease->env, disease))
198 do_symptoms(disease); 210 do_symptoms (disease);
199 211
200 return 0; 212 return 0;
201} 213}
202 214
203/* remove any symptoms of disease 215/* remove any symptoms of disease
204 * Modified by MSW 2003-03-28 do try to find all the symptom the 216 * Modified by MSW 2003-03-28 do try to find all the symptom the
205 * player may have - I think through some odd interactoins with 217 * player may have - I think through some odd interactoins with
206 * disease level and player level and whatnot, a player could get 218 * disease level and player level and whatnot, a player could get
207 * more than one symtpom to a disease. 219 * more than one symtpom to a disease.
208 */ 220 */
209 221
222int
210int remove_symptoms(object *disease) { 223remove_symptoms (object *disease)
224{
211 object *symptom, *victim=NULL; 225 object *symptom, *victim = NULL;
212 226
213 while ((symptom = find_symptom(disease)) != NULL) { 227 while ((symptom = find_symptom (disease)) != NULL)
228 {
229 if (!victim)
214 if (!victim) victim=symptom->env; 230 victim = symptom->env;
215 remove_ob(symptom); 231 remove_ob (symptom);
216 free_object(symptom); 232 free_object (symptom);
233 }
234 if (victim)
235 fix_player (victim);
236 return 0;
237}
238
239/* argument is a disease */
240object *
241find_symptom (object *disease)
242{
243 object *walk;
244
245 /* check the inventory for symptoms */
246 for (walk = disease->env->inv; walk; walk = walk->below)
247 if (!strcmp (walk->name, disease->name) && walk->type == SYMPTOM)
248 return walk;
249 return NULL;
250}
251
252/* searches around for more victims to infect */
253int
254check_infection (object *disease)
255{
256 int x, y, range, mflags;
257 mapstruct *map, *map2;
258 object *tmp;
259 sint16 i, j, i2, j2;
260
261 range = abs (disease->magic);
262 if (disease->env)
217 } 263 {
218 if(victim) fix_player(victim); 264 x = disease->env->x;
265 y = disease->env->y;
266 map = disease->env->map;
267 }
268 else
269 {
270 x = disease->x;
271 y = disease->y;
272 map = disease->map;
273 }
274
275 if (map == NULL)
219 return 0; 276 return 0;
220}
221
222/* argument is a disease */
223object * find_symptom(object *disease) {
224 object *walk;
225
226 /* check the inventory for symptoms */
227 for(walk=disease->env->inv;walk;walk = walk->below)
228 if(!strcmp(walk->name,disease->name)&&walk->type==SYMPTOM) return walk;
229 return NULL;
230}
231
232/* searches around for more victims to infect */
233int check_infection(object *disease) {
234 int x,y,range, mflags;
235 mapstruct *map, *map2;
236 object *tmp;
237 sint16 i, j, i2, j2;
238
239 range = abs(disease->magic);
240 if(disease->env) {
241 x = disease->env->x;
242 y = disease->env->y;
243 map=disease->env->map;
244 }
245 else {
246 x = disease->x;
247 y = disease->y;
248 map = disease->map;
249 }
250
251 if(map == NULL) return 0;
252 for(i=x-range;i<=x+range;i++) { 277 for (i = x - range; i <= x + range; i++)
278 {
253 for(j=y-range;j<=y+range;j++) { 279 for (j = y - range; j <= y + range; j++)
280 {
254 mflags = get_map_flags(map,&map2, i,j, &i2, &j2); 281 mflags = get_map_flags (map, &map2, i, j, &i2, &j2);
255 if (!(mflags & P_OUT_OF_MAP) && (mflags & P_IS_ALIVE)) { 282 if (!(mflags & P_OUT_OF_MAP) && (mflags & P_IS_ALIVE))
283 {
256 for(tmp=get_map_ob(map2,i2,j2);tmp;tmp=tmp->above) { 284 for (tmp = get_map_ob (map2, i2, j2); tmp; tmp = tmp->above)
285 {
257 infect_object(tmp,disease,0); 286 infect_object (tmp, disease, 0);
258 } 287 }
259 } 288 }
260 } 289 }
261 } 290 }
262 return 1; 291 return 1;
263} 292}
264 293
265 294
266/* check to see if an object is infectable: 295/* check to see if an object is infectable:
267 * objects with immunity aren't infectable. 296 * objects with immunity aren't infectable.
268 * objects already infected aren't infectable. 297 * objects already infected aren't infectable.
269 * dead objects aren't infectable. 298 * dead objects aren't infectable.
270 * undead objects are infectible only if specifically named. 299 * undead objects are infectible only if specifically named.
271*/ 300*/
301int
272int infect_object(object *victim, object *disease, int force) { 302infect_object (object *victim, object *disease, int force)
303{
273 object *tmp; 304 object *tmp;
274 object *new_disease; 305 object *new_disease;
275 306
276 /* don't infect inanimate objects */ 307 /* don't infect inanimate objects */
277 if(!QUERY_FLAG(victim,FLAG_MONSTER) && !(victim->type==PLAYER)) return 0; 308 if (!QUERY_FLAG (victim, FLAG_MONSTER) && !(victim->type == PLAYER))
309 return 0;
278 310
279 /* check and see if victim can catch disease: diseases 311 /* check and see if victim can catch disease: diseases
280 * are specific 312 * are specific
281 */ 313 */
282 if(!is_susceptible_to_disease(victim, disease)) return 0; 314 if (!is_susceptible_to_disease (victim, disease))
315 return 0;
283 316
284 /* roll the dice on infection before doing the inventory check! */ 317 /* roll the dice on infection before doing the inventory check! */
285 if(!force && (random_roll(0, 126, victim, PREFER_HIGH) >= disease->stats.wc)) 318 if (!force && (random_roll (0, 126, victim, PREFER_HIGH) >= disease->stats.wc))
286 return 0; 319 return 0;
287 320
288 /* do an immunity check */ 321 /* do an immunity check */
322 if (victim->head)
289 if(victim->head) tmp = victim->head->inv; 323 tmp = victim->head->inv;
324 else
290 else tmp = victim->inv; 325 tmp = victim->inv;
291 326
292 /* There used to (IMO) be a flaw in the below - it used to be the case 327 /* There used to (IMO) be a flaw in the below - it used to be the case
293 * that if level check was done for both immunity and disease. This could 328 * that if level check was done for both immunity and disease. This could
294 * result in a person with multiple afflictions of the same disease 329 * result in a person with multiple afflictions of the same disease
295 * (eg, level 1 cold, level 2 cold, level 3 cold, etc), as long as 330 * (eg, level 1 cold, level 2 cold, level 3 cold, etc), as long as
296 * they were cast in that same order. Instead, change it so that 331 * they were cast in that same order. Instead, change it so that
297 * if you diseased, you can't get diseased more. 332 * if you diseased, you can't get diseased more.
298 */ 333 */
299 334
300 for(/* tmp initialized in if, above */;tmp;tmp=tmp->below) { 335 for ( /* tmp initialized in if, above */ ; tmp; tmp = tmp->below)
336 {
301 if(tmp->type == SIGN && !strcmp(tmp->name,disease->name) && tmp->level >= disease->level) 337 if (tmp->type == SIGN && !strcmp (tmp->name, disease->name) && tmp->level >= disease->level)
302 return 0; /*Immune! */ 338 return 0; /*Immune! */
303 else if (tmp->type==DISEASE && !strcmp(tmp->name,disease->name)) 339 else if (tmp->type == DISEASE && !strcmp (tmp->name, disease->name))
304 return 0; /* already diseased */ 340 return 0; /* already diseased */
305 } 341 }
306 342
307 /* If we've gotten this far, go ahead and infect the victim. */ 343 /* If we've gotten this far, go ahead and infect the victim. */
308 new_disease = get_object(); 344 new_disease = get_object ();
309 copy_object(disease,new_disease); 345 copy_object (disease, new_disease);
310 new_disease->stats.food=disease->stats.maxgrace; 346 new_disease->stats.food = disease->stats.maxgrace;
311 new_disease->value=disease->stats.maxhp; 347 new_disease->value = disease->stats.maxhp;
312 new_disease->stats.wc -= disease->last_grace; /* self-limiting factor */ 348 new_disease->stats.wc -= disease->last_grace; /* self-limiting factor */
313 349
314 /* Unfortunately, set_owner does the wrong thing to the skills pointers 350 /* Unfortunately, set_owner does the wrong thing to the skills pointers
315 * resulting in exp going into the owners *current* chosen skill. 351 * resulting in exp going into the owners *current* chosen skill.
316 */ 352 */
317 353
318 if(get_owner(disease)) { 354 if (get_owner (disease))
355 {
319 set_owner(new_disease,disease->owner); 356 set_owner (new_disease, disease->owner);
320 357
321 /* Only need to update skill if different */ 358 /* Only need to update skill if different */
322 if (new_disease->skill != disease->skill) 359 if (new_disease->skill != disease->skill)
323 new_disease->skill = disease->skill; 360 new_disease->skill = disease->skill;
324 } 361 }
362 else
325 else { /* for diseases which are passed by hitting, set owner and praying skill*/ 363 { /* for diseases which are passed by hitting, set owner and praying skill */
326 if(disease->env && disease->env->type==PLAYER) { 364 if (disease->env && disease->env->type == PLAYER)
365 {
327 object *player = disease->env; 366 object *player = disease->env;
328 367
329 set_owner(new_disease,player); 368 set_owner (new_disease, player);
369
330 /* the skill pointer for these diseases should already be set up - 370 /* the skill pointer for these diseases should already be set up -
331 * hardcoding in 'praying' is not the right approach. 371 * hardcoding in 'praying' is not the right approach.
332 */ 372 */
333 } 373 }
334 } 374 }
335 375
336 insert_ob_in_ob(new_disease,victim); 376 insert_ob_in_ob (new_disease, victim);
337 /* This appears to be a horrible case of overloading 'NO_PASS' 377 /* This appears to be a horrible case of overloading 'NO_PASS'
338 * for meaning in the diseases. 378 * for meaning in the diseases.
339 */ 379 */
340 new_disease->move_block = 0; 380 new_disease->move_block = 0;
341 if(new_disease->owner && new_disease->owner->type==PLAYER) { 381 if (new_disease->owner && new_disease->owner->type == PLAYER)
382 {
342 char buf[128]; 383 char buf[128];
384
343 /* if the disease has a title, it has a special infection message 385 /* if the disease has a title, it has a special infection message
344 * This messages is printed in the form MESSAGE victim 386 * This messages is printed in the form MESSAGE victim
345 */ 387 */
346 if(new_disease->title) 388 if (new_disease->title)
347 sprintf(buf,"%s %s!!",&disease->title,&victim->name); 389 sprintf (buf, "%s %s!!", &disease->title, &victim->name);
348 else 390 else
349 sprintf(buf,"You infect %s with your disease, %s!",&victim->name,&new_disease->name); 391 sprintf (buf, "You infect %s with your disease, %s!", &victim->name, &new_disease->name);
350 392
351 if(victim->type == PLAYER) 393 if (victim->type == PLAYER)
352 new_draw_info(NDI_UNIQUE | NDI_RED, 0, new_disease->owner, buf); 394 new_draw_info (NDI_UNIQUE | NDI_RED, 0, new_disease->owner, buf);
353 else 395 else
354 new_draw_info(0, 4, new_disease->owner, buf); 396 new_draw_info (0, 4, new_disease->owner, buf);
355 } 397 }
356 if(victim->type==PLAYER) 398 if (victim->type == PLAYER)
357 new_draw_info(NDI_UNIQUE | NDI_RED,0,victim,"You suddenly feel ill."); 399 new_draw_info (NDI_UNIQUE | NDI_RED, 0, victim, "You suddenly feel ill.");
358 400
359 return 1; 401 return 1;
360 402
361} 403}
362 404
363 405
364 406
365/* this function monitors the symptoms caused by the disease (if any), 407/* this function monitors the symptoms caused by the disease (if any),
366causes symptoms, and modifies existing symptoms in the case of 408causes symptoms, and modifies existing symptoms in the case of
367existing diseases. */ 409existing diseases. */
368 410
411int
369int do_symptoms(object *disease) { 412do_symptoms (object *disease)
413{
370 object *symptom; 414 object *symptom;
371 object *victim; 415 object *victim;
372 object *tmp; 416 object *tmp;
417
373 victim = disease->env; 418 victim = disease->env;
374 419
375 /* This is a quick hack - for whatever reason, disease->env will point 420 /* This is a quick hack - for whatever reason, disease->env will point
376 * back to disease, causing endless loops. Why this happens really needs 421 * back to disease, causing endless loops. Why this happens really needs
377 * to be found, but this should at least prevent the infinite loops. 422 * to be found, but this should at least prevent the infinite loops.
378 */ 423 */
379 424
380 if(victim == NULL || victim==disease) 425 if (victim == NULL || victim == disease)
381 return 0;/* no-one to inflict symptoms on */ 426 return 0; /* no-one to inflict symptoms on */
382 427
383 symptom = find_symptom(disease); 428 symptom = find_symptom (disease);
384 if(symptom==NULL) { 429 if (symptom == NULL)
430 {
385 /* no symptom? need to generate one! */ 431 /* no symptom? need to generate one! */
386 object *new_symptom; 432 object *new_symptom;
387 433
388 /* first check and see if the carrier of the disease is immune. If so, no symptoms! */ 434 /* first check and see if the carrier of the disease is immune. If so, no symptoms! */
389 if(!is_susceptible_to_disease(victim, disease)) return 0; 435 if (!is_susceptible_to_disease (victim, disease))
436 return 0;
390 437
391 /* check for an actual immunity */ 438 /* check for an actual immunity */
392 /* do an immunity check */ 439 /* do an immunity check */
440 if (victim->head)
393 if(victim->head) tmp = victim->head->inv; 441 tmp = victim->head->inv;
442 else
394 else tmp = victim->inv; 443 tmp = victim->inv;
395 444
396 for(/* tmp initialized in if, above */;tmp;tmp=tmp->below) { 445 for ( /* tmp initialized in if, above */ ; tmp; tmp = tmp->below)
446 {
397 if(tmp->type == SIGN) /* possibly an immunity, or diseased*/ 447 if (tmp->type == SIGN) /* possibly an immunity, or diseased */
398 if(!strcmp(tmp->name,disease->name) && tmp->level >= disease->level) 448 if (!strcmp (tmp->name, disease->name) && tmp->level >= disease->level)
399 return 0; /*Immune! */ 449 return 0; /*Immune! */
400 } 450 }
401 451
402 new_symptom = get_archetype(ARCH_SYMPTOM); 452 new_symptom = get_archetype (ARCH_SYMPTOM);
403 453
404 /* Something special done with dam. We want diseases to be more 454 /* Something special done with dam. We want diseases to be more
405 * random in what they'll kill, so we'll make the damage they 455 * random in what they'll kill, so we'll make the damage they
406 * do random, note, this has a weird effect with progressive diseases. 456 * do random, note, this has a weird effect with progressive diseases.
407 */ 457 */
408 if(disease->stats.dam != 0) { 458 if (disease->stats.dam != 0)
459 {
409 int dam = disease->stats.dam; 460 int dam = disease->stats.dam;
410 461
411 /* reduce the damage, on average, 50%, and making things random. */ 462 /* reduce the damage, on average, 50%, and making things random. */
412 463
413 dam = random_roll(1, FABS(dam), victim, PREFER_LOW); 464 dam = random_roll (1, FABS (dam), victim, PREFER_LOW);
414 if(disease->stats.dam < 0) dam = -dam; 465 if (disease->stats.dam < 0)
466 dam = -dam;
415 new_symptom->stats.dam = dam; 467 new_symptom->stats.dam = dam;
416 } 468 }
417 469
418 470
419 new_symptom->stats.maxsp = disease->stats.maxsp; 471 new_symptom->stats.maxsp = disease->stats.maxsp;
420 new_symptom->stats.food = new_symptom->stats.maxgrace; 472 new_symptom->stats.food = new_symptom->stats.maxgrace;
421 473
422 new_symptom->name =
423 new_symptom->name_pl = disease->name; 474 new_symptom->name = new_symptom->name_pl = disease->name;
424 475
425 new_symptom->level = disease->level; 476 new_symptom->level = disease->level;
426 new_symptom->speed = disease->speed; 477 new_symptom->speed = disease->speed;
427 new_symptom->value = 0; 478 new_symptom->value = 0;
428 new_symptom->stats.Str =disease->stats.Str; 479 new_symptom->stats.Str = disease->stats.Str;
429 new_symptom->stats.Dex = disease->stats.Dex; 480 new_symptom->stats.Dex = disease->stats.Dex;
430 new_symptom->stats.Con = disease->stats.Con; 481 new_symptom->stats.Con = disease->stats.Con;
431 new_symptom->stats.Wis = disease->stats.Wis; 482 new_symptom->stats.Wis = disease->stats.Wis;
432 new_symptom->stats.Int = disease->stats.Int; 483 new_symptom->stats.Int = disease->stats.Int;
433 new_symptom->stats.Pow = disease->stats.Pow; 484 new_symptom->stats.Pow = disease->stats.Pow;
434 new_symptom->stats.Cha = disease->stats.Cha; 485 new_symptom->stats.Cha = disease->stats.Cha;
435 new_symptom->stats.sp = disease->stats.sp; 486 new_symptom->stats.sp = disease->stats.sp;
436 new_symptom->stats.food =disease->last_eat; 487 new_symptom->stats.food = disease->last_eat;
437 new_symptom->stats.maxsp = disease->stats.maxsp; 488 new_symptom->stats.maxsp = disease->stats.maxsp;
438 new_symptom->last_sp = disease->last_sp; 489 new_symptom->last_sp = disease->last_sp;
439 new_symptom->stats.exp = 0; 490 new_symptom->stats.exp = 0;
440 new_symptom->stats.hp = disease->stats.hp; 491 new_symptom->stats.hp = disease->stats.hp;
441 new_symptom->msg = disease->msg; 492 new_symptom->msg = disease->msg;
442 new_symptom->attacktype = disease->attacktype; 493 new_symptom->attacktype = disease->attacktype;
443 new_symptom->other_arch = disease->other_arch; 494 new_symptom->other_arch = disease->other_arch;
444 495
445 set_owner(new_symptom,disease->owner); 496 set_owner (new_symptom, disease->owner);
446 497
447 if (new_symptom->skill != disease->skill) 498 if (new_symptom->skill != disease->skill)
448 new_symptom->skill = disease->skill; 499 new_symptom->skill = disease->skill;
449 500
450 new_symptom->move_block=0; 501 new_symptom->move_block = 0;
451 insert_ob_in_ob(new_symptom,victim); 502 insert_ob_in_ob (new_symptom, victim);
452 return 1; 503 return 1;
453 } 504 }
454 505
455 /* now deal with progressing diseases: we increase the debility 506 /* now deal with progressing diseases: we increase the debility
456 * caused by the symptoms. 507 * caused by the symptoms.
457 */ 508 */
458 509
459 if(disease->stats.ac!=0) { 510 if (disease->stats.ac != 0)
511 {
460 float scale; 512 float scale;
461 513
462 symptom->value += disease->stats.ac; 514 symptom->value += disease->stats.ac;
463 scale = 1.0 + symptom->value/100.0; 515 scale = 1.0 + symptom->value / 100.0;
464 /* now rescale all the debilities */ 516 /* now rescale all the debilities */
465 symptom->stats.Str = (int) (scale*disease->stats.Str); 517 symptom->stats.Str = (int) (scale * disease->stats.Str);
466 symptom->stats.Dex = (int) (scale*disease->stats.Dex); 518 symptom->stats.Dex = (int) (scale * disease->stats.Dex);
467 symptom->stats.Con = (int) (scale*disease->stats.Con); 519 symptom->stats.Con = (int) (scale * disease->stats.Con);
468 symptom->stats.Wis = (int) (scale*disease->stats.Wis); 520 symptom->stats.Wis = (int) (scale * disease->stats.Wis);
469 symptom->stats.Int = (int) (scale*disease->stats.Int); 521 symptom->stats.Int = (int) (scale * disease->stats.Int);
470 symptom->stats.Pow = (int) (scale*disease->stats.Pow); 522 symptom->stats.Pow = (int) (scale * disease->stats.Pow);
471 symptom->stats.Cha = (int) (scale*disease->stats.Cha); 523 symptom->stats.Cha = (int) (scale * disease->stats.Cha);
472 symptom->stats.dam = (int) (scale*disease->stats.dam); 524 symptom->stats.dam = (int) (scale * disease->stats.dam);
473 symptom->stats.sp = (int) (scale*disease->stats.sp); 525 symptom->stats.sp = (int) (scale * disease->stats.sp);
474 symptom->stats.food = (int) (scale*disease->last_eat); 526 symptom->stats.food = (int) (scale * disease->last_eat);
475 symptom->stats.maxsp = (int) (scale*disease->stats.maxsp); 527 symptom->stats.maxsp = (int) (scale * disease->stats.maxsp);
476 symptom->last_sp = (int) (scale*disease->last_sp); 528 symptom->last_sp = (int) (scale * disease->last_sp);
477 symptom->stats.exp = 0; 529 symptom->stats.exp = 0;
478 symptom->stats.hp = (int) (scale*disease->stats.hp); 530 symptom->stats.hp = (int) (scale * disease->stats.hp);
479 symptom->msg = disease->msg; 531 symptom->msg = disease->msg;
480 symptom->attacktype = disease->attacktype; 532 symptom->attacktype = disease->attacktype;
481 symptom->other_arch = disease->other_arch; 533 symptom->other_arch = disease->other_arch;
482 } 534 }
483 SET_FLAG(symptom,FLAG_APPLIED); 535 SET_FLAG (symptom, FLAG_APPLIED);
484 fix_player(victim); 536 fix_player (victim);
485 return 1; 537 return 1;
486} 538}
487 539
488 540
489/* grants immunity to plagues we've seen before. */ 541/* grants immunity to plagues we've seen before. */
542int
490int grant_immunity(object *disease) { 543grant_immunity (object *disease)
544{
491 object * immunity; 545 object *immunity;
492 object *walk; 546 object *walk;
547
493 /* Don't give immunity to this disease if last_heal is set. */ 548 /* Don't give immunity to this disease if last_heal is set. */
494 if(disease->last_heal) return 0; 549 if (disease->last_heal)
550 return 0;
495 /* first, search for an immunity of the same name */ 551 /* first, search for an immunity of the same name */
496 for(walk=disease->env->inv;walk;walk=walk->below) { 552 for (walk = disease->env->inv; walk; walk = walk->below)
553 {
497 if(walk->type==98 && !strcmp(disease->name,walk->name)) { 554 if (walk->type == 98 && !strcmp (disease->name, walk->name))
555 {
498 walk->level = disease->level; 556 walk->level = disease->level;
499 return 1; /* just update the existing immunity. */ 557 return 1; /* just update the existing immunity. */
500 } 558 }
501 } 559 }
502 immunity = get_archetype("immunity"); 560 immunity = get_archetype ("immunity");
503 immunity->name = disease->name; 561 immunity->name = disease->name;
504 immunity->level = disease->level; 562 immunity->level = disease->level;
505 immunity->move_block = 0; 563 immunity->move_block = 0;
506 insert_ob_in_ob(immunity,disease->env); 564 insert_ob_in_ob (immunity, disease->env);
507 return 1; 565 return 1;
508 566
509} 567}
510 568
511 569
512/* make the symptom do the nasty things it does */ 570/* make the symptom do the nasty things it does */
513 571
572int
514int move_symptom(object *symptom) { 573move_symptom (object *symptom)
574{
515 object *victim = symptom->env; 575 object *victim = symptom->env;
516 object *new_ob; 576 object *new_ob;
517 int sp_reduce; 577 int sp_reduce;
518 578
519 if(victim == NULL || victim->map==NULL) { /* outside a monster/player, die immediately */ 579 if (victim == NULL || victim->map == NULL)
580 { /* outside a monster/player, die immediately */
520 remove_ob(symptom); 581 remove_ob (symptom);
521 free_object(symptom); 582 free_object (symptom);
522 return 0; 583 return 0;
523 } 584 }
524 585
586 if (symptom->stats.dam > 0)
525 if(symptom->stats.dam > 0) hit_player(victim,symptom->stats.dam,symptom,symptom->attacktype,1); 587 hit_player (victim, symptom->stats.dam, symptom, symptom->attacktype, 1);
588 else
526 else hit_player(victim,(int) MAX(1,-victim->stats.maxhp * symptom->stats.dam / 100.0),symptom,symptom->attacktype,1); 589 hit_player (victim, (int) MAX (1, -victim->stats.maxhp * symptom->stats.dam / 100.0), symptom, symptom->attacktype, 1);
527 590
528 if(symptom->stats.maxsp>0) sp_reduce = symptom->stats.maxsp; 591 if (symptom->stats.maxsp > 0)
592 sp_reduce = symptom->stats.maxsp;
593 else
529 else sp_reduce = (int) MAX(1,victim->stats.maxsp * symptom->stats.maxsp/100.0); 594 sp_reduce = (int) MAX (1, victim->stats.maxsp * symptom->stats.maxsp / 100.0);
530 victim->stats.sp = MAX(0,victim->stats.sp - sp_reduce); 595 victim->stats.sp = MAX (0, victim->stats.sp - sp_reduce);
531 596
532 /* create the symptom "other arch" object and drop it here 597 /* create the symptom "other arch" object and drop it here
533 * under every part of the monster 598 * under every part of the monster
534 * The victim may well have died. 599 * The victim may well have died.
535 */ 600 */
536 601
537 if(victim->map==NULL) return 0; 602 if (victim->map == NULL)
603 return 0;
538 if(symptom->other_arch) { 604 if (symptom->other_arch)
605 {
539 object *tmp; 606 object *tmp;
607
540 tmp=victim; 608 tmp = victim;
541 if(tmp->head!=NULL) tmp=tmp->head; 609 if (tmp->head != NULL)
610 tmp = tmp->head;
542 for(/*tmp initialized above */;tmp!=NULL;tmp=tmp->more) { 611 for ( /*tmp initialized above */ ; tmp != NULL; tmp = tmp->more)
612 {
543 new_ob = arch_to_object(symptom->other_arch); 613 new_ob = arch_to_object (symptom->other_arch);
544 new_ob->x = tmp->x; 614 new_ob->x = tmp->x;
545 new_ob->y = tmp->y; 615 new_ob->y = tmp->y;
546 new_ob->map = victim->map; 616 new_ob->map = victim->map;
547 insert_ob_in_map(new_ob,victim->map,victim,0); 617 insert_ob_in_map (new_ob, victim->map, victim, 0);
548 } 618 }
549 } 619 }
550 new_draw_info(NDI_UNIQUE | NDI_RED,0,victim,symptom->msg); 620 new_draw_info (NDI_UNIQUE | NDI_RED, 0, victim, symptom->msg);
551 621
552 return 1; 622 return 1;
553} 623}
554 624
555 625
556/* possibly infect due to direct physical contact 626/* possibly infect due to direct physical contact
557 i.e., AT_PHYSICAL-- called from "hit_player_attacktype" */ 627 i.e., AT_PHYSICAL-- called from "hit_player_attacktype" */
558 628
629int
559int check_physically_infect(object *victim, object *hitter) { 630check_physically_infect (object *victim, object *hitter)
631{
560 object *walk; 632 object *walk;
633
561 /* search for diseases, give every disease a chance to infect */ 634 /* search for diseases, give every disease a chance to infect */
562 for(walk=hitter->inv;walk!=NULL;walk=walk->below) 635 for (walk = hitter->inv; walk != NULL; walk = walk->below)
563 if(walk->type==DISEASE) infect_object(victim,walk,0); 636 if (walk->type == DISEASE)
637 infect_object (victim, walk, 0);
564 return 1; 638 return 1;
565} 639}
566 640
567/* find a disease in someone*/ 641/* find a disease in someone*/
642object *
568object *find_disease(object *victim) { 643find_disease (object *victim)
644{
569 object *walk; 645 object *walk;
646
570 for(walk=victim->inv;walk;walk=walk->below) 647 for (walk = victim->inv; walk; walk = walk->below)
571 if(walk->type==DISEASE) return walk; 648 if (walk->type == DISEASE)
649 return walk;
572 return NULL; 650 return NULL;
573} 651}
574 652
575/* do the cure disease stuff, from the spell "cure disease" */ 653/* do the cure disease stuff, from the spell "cure disease" */
576 654
655int
577int cure_disease(object *sufferer,object *caster) { 656cure_disease (object *sufferer, object *caster)
657{
578 object *disease, *next; 658 object *disease, *next;
579 int casting_level; 659 int casting_level;
580 int cure=0; 660 int cure = 0;
581 661
662 if (caster)
582 if(caster) casting_level = caster->level; 663 casting_level = caster->level;
664 else
583 else casting_level = 1000; /* if null caster, CURE all. */ 665 casting_level = 1000; /* if null caster, CURE all. */
584 666
585 for(disease=sufferer->inv;disease;disease=next) { 667 for (disease = sufferer->inv; disease; disease = next)
668 {
586 next=disease->below; 669 next = disease->below;
587 670
588 if(disease->type==DISEASE) { /* attempt to cure this disease */ 671 if (disease->type == DISEASE)
672 { /* attempt to cure this disease */
589 /* If caster lvel is higher than disease level, cure chance 673 /* If caster lvel is higher than disease level, cure chance
590 * is automatic. If lower, then the chance is basically 674 * is automatic. If lower, then the chance is basically
591 * 1 in level_diff - if there is a 5 level difference, chance 675 * 1 in level_diff - if there is a 5 level difference, chance
592 * is 1 in 5. 676 * is 1 in 5.
593 */ 677 */
594 if ((casting_level >= disease->level) || 678 if ((casting_level >= disease->level) || (!(random_roll (0, (disease->level - casting_level - 1), caster, PREFER_LOW))))
595 ( ! (random_roll(0, (disease->level - casting_level - 1), 679 {
596 caster, PREFER_LOW) ))) {
597 680
598 remove_symptoms(disease); 681 remove_symptoms (disease);
599 remove_ob(disease); 682 remove_ob (disease);
600 cure=1; 683 cure = 1;
601 if(caster) change_exp(caster,disease->stats.exp, 684 if (caster)
602 caster->chosen_skill ? &caster->chosen_skill->skill : (const char *)0, 0); 685 change_exp (caster, disease->stats.exp, caster->chosen_skill ? &caster->chosen_skill->skill : (const char *) 0, 0);
603 free_object(disease); 686 free_object (disease);
604 } 687 }
605 } 688 }
606 } 689 }
607 if (cure) { 690 if (cure)
691 {
608 /* Only draw these messages once */ 692 /* Only draw these messages once */
609 if (caster) 693 if (caster)
610 new_draw_info_format(NDI_UNIQUE,0,caster,"You cure a disease!"); 694 new_draw_info_format (NDI_UNIQUE, 0, caster, "You cure a disease!");
611 new_draw_info(NDI_UNIQUE,0,sufferer,"You no longer feel diseased."); 695 new_draw_info (NDI_UNIQUE, 0, sufferer, "You no longer feel diseased.");
612 } 696 }
613 return 1; 697 return 1;
614} 698}
615 699
616/* reduces disease progression: reduce_symptoms 700/* reduces disease progression: reduce_symptoms
617 * return true if we actually reduce a disease. 701 * return true if we actually reduce a disease.
618 */ 702 */
619 703
704int
620int reduce_symptoms(object *sufferer, int reduction) { 705reduce_symptoms (object *sufferer, int reduction)
706{
621 object *walk; 707 object *walk;
622 int success=0; 708 int success = 0;
623 709
624 for(walk=sufferer->inv;walk;walk=walk->below) { 710 for (walk = sufferer->inv; walk; walk = walk->below)
711 {
625 if(walk->type==SYMPTOM) { 712 if (walk->type == SYMPTOM)
713 {
626 if(walk->value > 0) { 714 if (walk->value > 0)
715 {
627 success=1; 716 success = 1;
628 walk->value = MAX(0,walk->value - 2*reduction); 717 walk->value = MAX (0, walk->value - 2 * reduction);
629 /* give the disease time to modify this symptom, 718 /* give the disease time to modify this symptom,
630 * and reduce its severity. */ 719 * and reduce its severity. */
631 walk->speed_left = 0; 720 walk->speed_left = 0;
632 } 721 }
633 } 722 }
634 } 723 }
635 if (success) 724 if (success)
636 new_draw_info(NDI_UNIQUE,0,sufferer,"Your illness seems less severe."); 725 new_draw_info (NDI_UNIQUE, 0, sufferer, "Your illness seems less severe.");
637 return success; 726 return success;
638} 727}
639

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines