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.2 by root, Tue Aug 29 08:01:37 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.2 2006/08/29 08:01:37 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 if (new_disease->skill) free_string(new_disease->skill); 360 new_disease->skill = disease->skill;
324 if (disease->skill) new_disease->skill = add_refcount(disease->skill);
325 }
326 } 361 }
362 else
327 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 */
328 if(disease->env && disease->env->type==PLAYER) { 364 if (disease->env && disease->env->type == PLAYER)
365 {
329 object *player = disease->env; 366 object *player = disease->env;
330 367
331 set_owner(new_disease,player); 368 set_owner (new_disease, player);
369
332 /* the skill pointer for these diseases should already be set up - 370 /* the skill pointer for these diseases should already be set up -
333 * hardcoding in 'praying' is not the right approach. 371 * hardcoding in 'praying' is not the right approach.
334 */ 372 */
335 } 373 }
336 } 374 }
337 375
338 insert_ob_in_ob(new_disease,victim); 376 insert_ob_in_ob (new_disease, victim);
339 /* This appears to be a horrible case of overloading 'NO_PASS' 377 /* This appears to be a horrible case of overloading 'NO_PASS'
340 * for meaning in the diseases. 378 * for meaning in the diseases.
341 */ 379 */
342 new_disease->move_block = 0; 380 new_disease->move_block = 0;
343 if(new_disease->owner && new_disease->owner->type==PLAYER) { 381 if (new_disease->owner && new_disease->owner->type == PLAYER)
382 {
344 char buf[128]; 383 char buf[128];
384
345 /* 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
346 * This messages is printed in the form MESSAGE victim 386 * This messages is printed in the form MESSAGE victim
347 */ 387 */
348 if(new_disease->title) 388 if (new_disease->title)
349 sprintf(buf,"%s %s!!",disease->title,victim->name); 389 sprintf (buf, "%s %s!!", &disease->title, &victim->name);
350 else 390 else
351 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);
352 392
353 if(victim->type == PLAYER) 393 if (victim->type == PLAYER)
354 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);
355 else 395 else
356 new_draw_info(0, 4, new_disease->owner, buf); 396 new_draw_info (0, 4, new_disease->owner, buf);
357 } 397 }
358 if(victim->type==PLAYER) 398 if (victim->type == PLAYER)
359 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.");
360 400
361 return 1; 401 return 1;
362 402
363} 403}
364 404
365 405
366 406
367/* this function monitors the symptoms caused by the disease (if any), 407/* this function monitors the symptoms caused by the disease (if any),
368causes symptoms, and modifies existing symptoms in the case of 408causes symptoms, and modifies existing symptoms in the case of
369existing diseases. */ 409existing diseases. */
370 410
411int
371int do_symptoms(object *disease) { 412do_symptoms (object *disease)
413{
372 object *symptom; 414 object *symptom;
373 object *victim; 415 object *victim;
374 object *tmp; 416 object *tmp;
417
375 victim = disease->env; 418 victim = disease->env;
376 419
377 /* 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
378 * back to disease, causing endless loops. Why this happens really needs 421 * back to disease, causing endless loops. Why this happens really needs
379 * 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.
380 */ 423 */
381 424
382 if(victim == NULL || victim==disease) 425 if (victim == NULL || victim == disease)
383 return 0;/* no-one to inflict symptoms on */ 426 return 0; /* no-one to inflict symptoms on */
384 427
385 symptom = find_symptom(disease); 428 symptom = find_symptom (disease);
386 if(symptom==NULL) { 429 if (symptom == NULL)
430 {
387 /* no symptom? need to generate one! */ 431 /* no symptom? need to generate one! */
388 object *new_symptom; 432 object *new_symptom;
389 433
390 /* 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! */
391 if(!is_susceptible_to_disease(victim, disease)) return 0; 435 if (!is_susceptible_to_disease (victim, disease))
436 return 0;
392 437
393 /* check for an actual immunity */ 438 /* check for an actual immunity */
394 /* do an immunity check */ 439 /* do an immunity check */
440 if (victim->head)
395 if(victim->head) tmp = victim->head->inv; 441 tmp = victim->head->inv;
442 else
396 else tmp = victim->inv; 443 tmp = victim->inv;
397 444
398 for(/* tmp initialized in if, above */;tmp;tmp=tmp->below) { 445 for ( /* tmp initialized in if, above */ ; tmp; tmp = tmp->below)
446 {
399 if(tmp->type == SIGN) /* possibly an immunity, or diseased*/ 447 if (tmp->type == SIGN) /* possibly an immunity, or diseased */
400 if(!strcmp(tmp->name,disease->name) && tmp->level >= disease->level) 448 if (!strcmp (tmp->name, disease->name) && tmp->level >= disease->level)
401 return 0; /*Immune! */ 449 return 0; /*Immune! */
402 } 450 }
403 451
404 new_symptom = get_archetype(ARCH_SYMPTOM); 452 new_symptom = get_archetype (ARCH_SYMPTOM);
405 453
406 /* Something special done with dam. We want diseases to be more 454 /* Something special done with dam. We want diseases to be more
407 * 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
408 * do random, note, this has a weird effect with progressive diseases. 456 * do random, note, this has a weird effect with progressive diseases.
409 */ 457 */
410 if(disease->stats.dam != 0) { 458 if (disease->stats.dam != 0)
459 {
411 int dam = disease->stats.dam; 460 int dam = disease->stats.dam;
412 461
413 /* reduce the damage, on average, 50%, and making things random. */ 462 /* reduce the damage, on average, 50%, and making things random. */
414 463
415 dam = random_roll(1, FABS(dam), victim, PREFER_LOW); 464 dam = random_roll (1, FABS (dam), victim, PREFER_LOW);
416 if(disease->stats.dam < 0) dam = -dam; 465 if (disease->stats.dam < 0)
466 dam = -dam;
417 new_symptom->stats.dam = dam; 467 new_symptom->stats.dam = dam;
418 } 468 }
419 469
420 470
421 new_symptom->stats.maxsp = disease->stats.maxsp; 471 new_symptom->stats.maxsp = disease->stats.maxsp;
422 new_symptom->stats.food = new_symptom->stats.maxgrace; 472 new_symptom->stats.food = new_symptom->stats.maxgrace;
423 473
424 FREE_AND_COPY(new_symptom->name, disease->name); 474 new_symptom->name = new_symptom->name_pl = disease->name;
425 FREE_AND_COPY(new_symptom->name_pl, disease->name); 475
426 new_symptom->level = disease->level; 476 new_symptom->level = disease->level;
427 new_symptom->speed = disease->speed; 477 new_symptom->speed = disease->speed;
428 new_symptom->value = 0; 478 new_symptom->value = 0;
429 new_symptom->stats.Str =disease->stats.Str; 479 new_symptom->stats.Str = disease->stats.Str;
430 new_symptom->stats.Dex = disease->stats.Dex; 480 new_symptom->stats.Dex = disease->stats.Dex;
431 new_symptom->stats.Con = disease->stats.Con; 481 new_symptom->stats.Con = disease->stats.Con;
432 new_symptom->stats.Wis = disease->stats.Wis; 482 new_symptom->stats.Wis = disease->stats.Wis;
433 new_symptom->stats.Int = disease->stats.Int; 483 new_symptom->stats.Int = disease->stats.Int;
434 new_symptom->stats.Pow = disease->stats.Pow; 484 new_symptom->stats.Pow = disease->stats.Pow;
435 new_symptom->stats.Cha = disease->stats.Cha; 485 new_symptom->stats.Cha = disease->stats.Cha;
436 new_symptom->stats.sp = disease->stats.sp; 486 new_symptom->stats.sp = disease->stats.sp;
437 new_symptom->stats.food =disease->last_eat; 487 new_symptom->stats.food = disease->last_eat;
438 new_symptom->stats.maxsp = disease->stats.maxsp; 488 new_symptom->stats.maxsp = disease->stats.maxsp;
439 new_symptom->last_sp = disease->last_sp; 489 new_symptom->last_sp = disease->last_sp;
440 new_symptom->stats.exp = 0; 490 new_symptom->stats.exp = 0;
441 new_symptom->stats.hp = disease->stats.hp; 491 new_symptom->stats.hp = disease->stats.hp;
442 new_symptom->msg = add_string(disease->msg); 492 new_symptom->msg = disease->msg;
443 new_symptom->attacktype = disease->attacktype; 493 new_symptom->attacktype = disease->attacktype;
444 new_symptom->other_arch = disease->other_arch; 494 new_symptom->other_arch = disease->other_arch;
445 495
446 set_owner(new_symptom,disease->owner); 496 set_owner (new_symptom, disease->owner);
497
447 if (new_symptom->skill != disease->skill) { 498 if (new_symptom->skill != disease->skill)
448 if (new_symptom->skill) free_string(new_symptom->skill); 499 new_symptom->skill = disease->skill;
449 if (disease->skill) new_symptom->skill = add_refcount(disease->skill); 500
450 }
451 new_symptom->move_block=0; 501 new_symptom->move_block = 0;
452 insert_ob_in_ob(new_symptom,victim); 502 insert_ob_in_ob (new_symptom, victim);
453 return 1; 503 return 1;
454 } 504 }
455 505
456 /* now deal with progressing diseases: we increase the debility 506 /* now deal with progressing diseases: we increase the debility
457 * caused by the symptoms. 507 * caused by the symptoms.
458 */ 508 */
459 509
460 if(disease->stats.ac!=0) { 510 if (disease->stats.ac != 0)
511 {
461 float scale; 512 float scale;
462 513
463 symptom->value += disease->stats.ac; 514 symptom->value += disease->stats.ac;
464 scale = 1.0 + symptom->value/100.0; 515 scale = 1.0 + symptom->value / 100.0;
465 /* now rescale all the debilities */ 516 /* now rescale all the debilities */
466 symptom->stats.Str = (int) (scale*disease->stats.Str); 517 symptom->stats.Str = (int) (scale * disease->stats.Str);
467 symptom->stats.Dex = (int) (scale*disease->stats.Dex); 518 symptom->stats.Dex = (int) (scale * disease->stats.Dex);
468 symptom->stats.Con = (int) (scale*disease->stats.Con); 519 symptom->stats.Con = (int) (scale * disease->stats.Con);
469 symptom->stats.Wis = (int) (scale*disease->stats.Wis); 520 symptom->stats.Wis = (int) (scale * disease->stats.Wis);
470 symptom->stats.Int = (int) (scale*disease->stats.Int); 521 symptom->stats.Int = (int) (scale * disease->stats.Int);
471 symptom->stats.Pow = (int) (scale*disease->stats.Pow); 522 symptom->stats.Pow = (int) (scale * disease->stats.Pow);
472 symptom->stats.Cha = (int) (scale*disease->stats.Cha); 523 symptom->stats.Cha = (int) (scale * disease->stats.Cha);
473 symptom->stats.dam = (int) (scale*disease->stats.dam); 524 symptom->stats.dam = (int) (scale * disease->stats.dam);
474 symptom->stats.sp = (int) (scale*disease->stats.sp); 525 symptom->stats.sp = (int) (scale * disease->stats.sp);
475 symptom->stats.food = (int) (scale*disease->last_eat); 526 symptom->stats.food = (int) (scale * disease->last_eat);
476 symptom->stats.maxsp = (int) (scale*disease->stats.maxsp); 527 symptom->stats.maxsp = (int) (scale * disease->stats.maxsp);
477 symptom->last_sp = (int) (scale*disease->last_sp); 528 symptom->last_sp = (int) (scale * disease->last_sp);
478 symptom->stats.exp = 0; 529 symptom->stats.exp = 0;
479 symptom->stats.hp = (int) (scale*disease->stats.hp); 530 symptom->stats.hp = (int) (scale * disease->stats.hp);
480 symptom->msg = add_string(disease->msg); 531 symptom->msg = disease->msg;
481 symptom->attacktype = disease->attacktype; 532 symptom->attacktype = disease->attacktype;
482 symptom->other_arch = disease->other_arch; 533 symptom->other_arch = disease->other_arch;
483 } 534 }
484 SET_FLAG(symptom,FLAG_APPLIED); 535 SET_FLAG (symptom, FLAG_APPLIED);
485 fix_player(victim); 536 fix_player (victim);
486 return 1; 537 return 1;
487} 538}
488 539
489 540
490/* grants immunity to plagues we've seen before. */ 541/* grants immunity to plagues we've seen before. */
542int
491int grant_immunity(object *disease) { 543grant_immunity (object *disease)
544{
492 object * immunity; 545 object *immunity;
493 object *walk; 546 object *walk;
547
494 /* 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. */
495 if(disease->last_heal) return 0; 549 if (disease->last_heal)
550 return 0;
496 /* first, search for an immunity of the same name */ 551 /* first, search for an immunity of the same name */
497 for(walk=disease->env->inv;walk;walk=walk->below) { 552 for (walk = disease->env->inv; walk; walk = walk->below)
553 {
498 if(walk->type==98 && !strcmp(disease->name,walk->name)) { 554 if (walk->type == 98 && !strcmp (disease->name, walk->name))
555 {
499 walk->level = disease->level; 556 walk->level = disease->level;
500 return 1; /* just update the existing immunity. */ 557 return 1; /* just update the existing immunity. */
501 } 558 }
502 } 559 }
503 immunity = get_archetype("immunity"); 560 immunity = get_archetype ("immunity");
504 immunity->name = add_string(disease->name); 561 immunity->name = disease->name;
505 immunity->level = disease->level; 562 immunity->level = disease->level;
506 immunity->move_block = 0; 563 immunity->move_block = 0;
507 insert_ob_in_ob(immunity,disease->env); 564 insert_ob_in_ob (immunity, disease->env);
508 return 1; 565 return 1;
509 566
510} 567}
511 568
512 569
513/* make the symptom do the nasty things it does */ 570/* make the symptom do the nasty things it does */
514 571
572int
515int move_symptom(object *symptom) { 573move_symptom (object *symptom)
574{
516 object *victim = symptom->env; 575 object *victim = symptom->env;
517 object *new_ob; 576 object *new_ob;
518 int sp_reduce; 577 int sp_reduce;
519 578
520 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 */
521 remove_ob(symptom); 581 remove_ob (symptom);
522 free_object(symptom); 582 free_object (symptom);
523 return 0; 583 return 0;
524 } 584 }
525 585
586 if (symptom->stats.dam > 0)
526 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
527 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);
528 590
529 if(symptom->stats.maxsp>0) sp_reduce = symptom->stats.maxsp; 591 if (symptom->stats.maxsp > 0)
592 sp_reduce = symptom->stats.maxsp;
593 else
530 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);
531 victim->stats.sp = MAX(0,victim->stats.sp - sp_reduce); 595 victim->stats.sp = MAX (0, victim->stats.sp - sp_reduce);
532 596
533 /* create the symptom "other arch" object and drop it here 597 /* create the symptom "other arch" object and drop it here
534 * under every part of the monster 598 * under every part of the monster
535 * The victim may well have died. 599 * The victim may well have died.
536 */ 600 */
537 601
538 if(victim->map==NULL) return 0; 602 if (victim->map == NULL)
603 return 0;
539 if(symptom->other_arch) { 604 if (symptom->other_arch)
605 {
540 object *tmp; 606 object *tmp;
607
541 tmp=victim; 608 tmp = victim;
542 if(tmp->head!=NULL) tmp=tmp->head; 609 if (tmp->head != NULL)
610 tmp = tmp->head;
543 for(/*tmp initialized above */;tmp!=NULL;tmp=tmp->more) { 611 for ( /*tmp initialized above */ ; tmp != NULL; tmp = tmp->more)
612 {
544 new_ob = arch_to_object(symptom->other_arch); 613 new_ob = arch_to_object (symptom->other_arch);
545 new_ob->x = tmp->x; 614 new_ob->x = tmp->x;
546 new_ob->y = tmp->y; 615 new_ob->y = tmp->y;
547 new_ob->map = victim->map; 616 new_ob->map = victim->map;
548 insert_ob_in_map(new_ob,victim->map,victim,0); 617 insert_ob_in_map (new_ob, victim->map, victim, 0);
549 } 618 }
550 } 619 }
551 new_draw_info(NDI_UNIQUE | NDI_RED,0,victim,symptom->msg); 620 new_draw_info (NDI_UNIQUE | NDI_RED, 0, victim, symptom->msg);
552 621
553 return 1; 622 return 1;
554} 623}
555 624
556 625
557/* possibly infect due to direct physical contact 626/* possibly infect due to direct physical contact
558 i.e., AT_PHYSICAL-- called from "hit_player_attacktype" */ 627 i.e., AT_PHYSICAL-- called from "hit_player_attacktype" */
559 628
629int
560int check_physically_infect(object *victim, object *hitter) { 630check_physically_infect (object *victim, object *hitter)
631{
561 object *walk; 632 object *walk;
633
562 /* search for diseases, give every disease a chance to infect */ 634 /* search for diseases, give every disease a chance to infect */
563 for(walk=hitter->inv;walk!=NULL;walk=walk->below) 635 for (walk = hitter->inv; walk != NULL; walk = walk->below)
564 if(walk->type==DISEASE) infect_object(victim,walk,0); 636 if (walk->type == DISEASE)
637 infect_object (victim, walk, 0);
565 return 1; 638 return 1;
566} 639}
567 640
568/* find a disease in someone*/ 641/* find a disease in someone*/
642object *
569object *find_disease(object *victim) { 643find_disease (object *victim)
644{
570 object *walk; 645 object *walk;
646
571 for(walk=victim->inv;walk;walk=walk->below) 647 for (walk = victim->inv; walk; walk = walk->below)
572 if(walk->type==DISEASE) return walk; 648 if (walk->type == DISEASE)
649 return walk;
573 return NULL; 650 return NULL;
574} 651}
575 652
576/* do the cure disease stuff, from the spell "cure disease" */ 653/* do the cure disease stuff, from the spell "cure disease" */
577 654
655int
578int cure_disease(object *sufferer,object *caster) { 656cure_disease (object *sufferer, object *caster)
657{
579 object *disease, *next; 658 object *disease, *next;
580 int casting_level; 659 int casting_level;
581 int cure=0; 660 int cure = 0;
582 661
662 if (caster)
583 if(caster) casting_level = caster->level; 663 casting_level = caster->level;
664 else
584 else casting_level = 1000; /* if null caster, CURE all. */ 665 casting_level = 1000; /* if null caster, CURE all. */
585 666
586 for(disease=sufferer->inv;disease;disease=next) { 667 for (disease = sufferer->inv; disease; disease = next)
668 {
587 next=disease->below; 669 next = disease->below;
588 670
589 if(disease->type==DISEASE) { /* attempt to cure this disease */ 671 if (disease->type == DISEASE)
672 { /* attempt to cure this disease */
590 /* If caster lvel is higher than disease level, cure chance 673 /* If caster lvel is higher than disease level, cure chance
591 * is automatic. If lower, then the chance is basically 674 * is automatic. If lower, then the chance is basically
592 * 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
593 * is 1 in 5. 676 * is 1 in 5.
594 */ 677 */
595 if ((casting_level >= disease->level) || 678 if ((casting_level >= disease->level) || (!(random_roll (0, (disease->level - casting_level - 1), caster, PREFER_LOW))))
596 ( ! (random_roll(0, (disease->level - casting_level - 1), 679 {
597 caster, PREFER_LOW) ))) {
598 680
599 remove_symptoms(disease); 681 remove_symptoms (disease);
600 remove_ob(disease); 682 remove_ob (disease);
601 cure=1; 683 cure = 1;
602 if(caster) change_exp(caster,disease->stats.exp, 684 if (caster)
603 caster->chosen_skill?caster->chosen_skill->skill:NULL, 0); 685 change_exp (caster, disease->stats.exp, caster->chosen_skill ? &caster->chosen_skill->skill : (const char *) 0, 0);
604 free_object(disease); 686 free_object (disease);
605 } 687 }
606 } 688 }
607 } 689 }
608 if (cure) { 690 if (cure)
691 {
609 /* Only draw these messages once */ 692 /* Only draw these messages once */
610 if (caster) 693 if (caster)
611 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!");
612 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.");
613 } 696 }
614 return 1; 697 return 1;
615} 698}
616 699
617/* reduces disease progression: reduce_symptoms 700/* reduces disease progression: reduce_symptoms
618 * return true if we actually reduce a disease. 701 * return true if we actually reduce a disease.
619 */ 702 */
620 703
704int
621int reduce_symptoms(object *sufferer, int reduction) { 705reduce_symptoms (object *sufferer, int reduction)
706{
622 object *walk; 707 object *walk;
623 int success=0; 708 int success = 0;
624 709
625 for(walk=sufferer->inv;walk;walk=walk->below) { 710 for (walk = sufferer->inv; walk; walk = walk->below)
711 {
626 if(walk->type==SYMPTOM) { 712 if (walk->type == SYMPTOM)
713 {
627 if(walk->value > 0) { 714 if (walk->value > 0)
715 {
628 success=1; 716 success = 1;
629 walk->value = MAX(0,walk->value - 2*reduction); 717 walk->value = MAX (0, walk->value - 2 * reduction);
630 /* give the disease time to modify this symptom, 718 /* give the disease time to modify this symptom,
631 * and reduce its severity. */ 719 * and reduce its severity. */
632 walk->speed_left = 0; 720 walk->speed_left = 0;
633 } 721 }
634 } 722 }
635 } 723 }
636 if (success) 724 if (success)
637 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.");
638 return success; 726 return success;
639} 727}
640

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines