1 /* ---------------------------------------------------------------------- *
2  * fire.c
3  * This file is part of lincity.
4  * Lincity is copyright (c) I J Peters 1995-1997, (c) Greg Sharp 1997-2001.
5  * (c) Corey Keasling, 2004
6  * ---------------------------------------------------------------------- */
7 
8 #include "modules.h"
9 #include "fire.h"
10 #include <stdlib.h>
11 
do_fire(int x,int y)12 void do_fire(int x, int y)
13 {
14     /*
15        // int_1 unused
16        // int_2 is the fire length
17        // int_3 is the real_time before the fire can spread or -1 if triggered
18        // int_4 is the idle land length
19        // MP_ANIM is the next animation frame time, since 1.91
20      */
21     int i;
22     /* this so we don't get whole blocks changing in one go. */
23     if (MP_INFO(x, y).int_2 == 0)
24 
25         MP_INFO(x, y).int_2 = rand() % (FIRE_LENGTH / 5);
26     if (MP_INFO(x, y).int_2 > FIRE_LENGTH) {
27         if (MP_INFO(x, y).int_4 == 0)   /* rand length here also */
28             MP_INFO(x, y).int_4 = rand() % (AFTER_FIRE_LENGTH / 6);
29         MP_INFO(x, y).int_4++;
30         if (MP_INFO(x, y).int_4 > AFTER_FIRE_LENGTH)
31             if (use_waterwell) {
32                 do_bulldoze_area(CST_DESERT, x, y);
33             } else {
34                 do_bulldoze_area(CST_GREEN, x, y);
35         } else if (MP_INFO(x, y).int_4 > (3 * AFTER_FIRE_LENGTH) / 4)
36             MP_TYPE(x, y) = CST_FIRE_DONE4;
37         else if (MP_INFO(x, y).int_4 > (2 * AFTER_FIRE_LENGTH) / 4)
38             MP_TYPE(x, y) = CST_FIRE_DONE3;
39         else if (MP_INFO(x, y).int_4 > (AFTER_FIRE_LENGTH) / 4)
40             MP_TYPE(x, y) = CST_FIRE_DONE2;
41         else
42             MP_TYPE(x, y) = CST_FIRE_DONE1;
43         return;
44     }
45     MP_INFO(x, y).int_2++;
46     if (real_time > MP_ANIM(x, y)) {
47         MP_ANIM(x, y) = real_time + FIRE_ANIMATION_SPEED;
48         if (MP_TYPE(x, y) == CST_FIRE_1)
49             MP_TYPE(x, y) = CST_FIRE_2;
50         else if (MP_TYPE(x, y) == CST_FIRE_2)
51             MP_TYPE(x, y) = CST_FIRE_3;
52         else if (MP_TYPE(x, y) == CST_FIRE_3)
53             MP_TYPE(x, y) = CST_FIRE_4;
54         else if (MP_TYPE(x, y) == CST_FIRE_4)
55             MP_TYPE(x, y) = CST_FIRE_5;
56         else if (MP_TYPE(x, y) == CST_FIRE_5)
57             MP_TYPE(x, y) = CST_FIRE_1;
58     }
59     if (MP_INFO(x, y).int_3 == -1) {
60         if ((rand() % FIRE_DAYS_PER_SPREAD) == 1) {
61             i = rand() % 4;
62             switch (i) {
63             case (0):
64                 do_random_fire(x - 1, y, 0);
65                 break;
66             case (1):
67                 do_random_fire(x, y - 1, 0);
68                 break;
69             case (2):
70                 do_random_fire(x + 1, y, 0);
71                 break;
72             case (3):
73                 do_random_fire(x, y + 1, 0);
74                 break;
75             }
76         }
77     } else if (MP_INFO(x, y).int_3 == 0) {
78         /* check here 'cos we can wait in the ok box for ever. */
79         MP_INFO(x, y).int_3 = real_time + 15000;        /* 15 secs seem fair */
80     } else if (real_time >= MP_INFO(x, y).int_3)
81         MP_INFO(x, y).int_3 = -1;
82 }
83