* This function is called every turn. * It makes the regions age, if necessary and calls the appropriate * callbacks when needed. */
| 411 | * callbacks when needed. |
| 412 | */ |
| 413 | void |
| 414 | run_regions(void) |
| 415 | { |
| 416 | int i, j, k; |
| 417 | int f_indx; |
| 418 | |
| 419 | /* reset some messaging variables */ |
| 420 | gg.gas_cloud_diss_within = FALSE; |
| 421 | gg.gas_cloud_diss_seen = 0; |
| 422 | |
| 423 | /* End of life ? */ |
| 424 | /* Do it backward because the array will be modified */ |
| 425 | for (i = svn.n_regions - 1; i >= 0; i--) { |
| 426 | if (gr.regions[i]->ttl == 0L) { |
| 427 | if ((f_indx = gr.regions[i]->expire_f) == NO_CALLBACK |
| 428 | || (*callbacks[f_indx])(gr.regions[i], (genericptr_t) 0)) |
| 429 | remove_region(gr.regions[i]); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | /* Process remaining regions */ |
| 434 | for (i = 0; i < svn.n_regions; i++) { |
| 435 | /* Make the region age */ |
| 436 | if (gr.regions[i]->ttl > 0L) |
| 437 | gr.regions[i]->ttl--; |
| 438 | /* Check if player is inside region */ |
| 439 | f_indx = gr.regions[i]->inside_f; |
| 440 | if (f_indx != NO_CALLBACK && hero_inside(gr.regions[i])) |
| 441 | (void) (*callbacks[f_indx])(gr.regions[i], (genericptr_t) 0); |
| 442 | /* Check if any monster is inside region */ |
| 443 | if (f_indx != NO_CALLBACK) { |
| 444 | for (j = 0; j < gr.regions[i]->n_monst; j++) { |
| 445 | struct monst *mtmp = |
| 446 | find_mid(gr.regions[i]->monsters[j], FM_FMON); |
| 447 | |
| 448 | if (!mtmp || DEADMONSTER(mtmp) |
| 449 | || (*callbacks[f_indx])(gr.regions[i], mtmp)) { |
| 450 | /* The monster died, remove it from list */ |
| 451 | k = (gr.regions[i]->n_monst -= 1); |
| 452 | gr.regions[i]->monsters[j] = gr.regions[i]->monsters[k]; |
| 453 | gr.regions[i]->monsters[k] = 0; |
| 454 | --j; /* current slot has been reused; recheck it next */ |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | if (gg.gas_cloud_diss_within) { |
| 461 | pline_The("gas cloud around you dissipates."); |
| 462 | /* normally won't see additional dissipation when within */ |
| 463 | /* FIXME? this assumes that additional dissipation is close by */ |
| 464 | if (u.xray_range <= 1) |
| 465 | gg.gas_cloud_diss_seen = 0; |
| 466 | gg.gas_cloud_diss_within = FALSE; |
| 467 | } |
| 468 | if (gg.gas_cloud_diss_seen) { |
| 469 | You_see("%s gas cloud%s dissipate.", |
| 470 | (gg.gas_cloud_diss_seen == 1) ? "a" : "some", |
no test coverage detected