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 <stdlib.h>
9 #include <lin-city.h>
10 #include <lctypes.h>
11 #include <engglobs.h>
12 #include <cliglobs.h>
13 #include <stats.h>
14 #include <engine.h>
15 #include <mps.h>
16 #include <fire.h>
17
18 void
do_fire(int x,int y)19 do_fire (int x, int y)
20 {
21 /*
22 // int_1 is the next animation frame time
23 // int_2 is the fire length
24 // int_3 is the real_time before the fire can spread or -1 if triggered
25 // int_4 is the idle land length
26 */
27 int i;
28 /* this so we don't get whole blocks changing in one go. */
29 if (MP_INFO(x,y).int_2 == 0)
30
31 MP_INFO(x,y).int_2 = rand () % (FIRE_LENGTH / 5);
32 if (MP_INFO(x,y).int_2 > FIRE_LENGTH)
33 {
34 if (MP_INFO(x,y).int_4 == 0) /* rand length here also */
35 MP_INFO(x,y).int_4 = rand () % (AFTER_FIRE_LENGTH / 6);
36 MP_INFO(x,y).int_4++;
37 if (MP_INFO(x,y).int_4 > AFTER_FIRE_LENGTH)
38 do_bulldoze_area (CST_GREEN, x, y);
39 else if (MP_INFO(x,y).int_4 > (3 * AFTER_FIRE_LENGTH) / 4)
40 MP_TYPE(x,y) = CST_FIRE_DONE4;
41 else if (MP_INFO(x,y).int_4 > (2 * AFTER_FIRE_LENGTH) / 4)
42 MP_TYPE(x,y) = CST_FIRE_DONE3;
43 else if (MP_INFO(x,y).int_4 > (AFTER_FIRE_LENGTH) / 4)
44 MP_TYPE(x,y) = CST_FIRE_DONE2;
45 else
46 MP_TYPE(x,y) = CST_FIRE_DONE1;
47 return;
48 }
49 MP_INFO(x,y).int_2++;
50 if (real_time > MP_INFO(x,y).int_1)
51 {
52 MP_INFO(x,y).int_1 = real_time + FIRE_ANIMATION_SPEED;
53 if (MP_TYPE(x,y) == CST_FIRE_1)
54 MP_TYPE(x,y) = CST_FIRE_2;
55 else if (MP_TYPE(x,y) == CST_FIRE_2)
56 MP_TYPE(x,y) = CST_FIRE_3;
57 else if (MP_TYPE(x,y) == CST_FIRE_3)
58 MP_TYPE(x,y) = CST_FIRE_4;
59 else if (MP_TYPE(x,y) == CST_FIRE_4)
60 MP_TYPE(x,y) = CST_FIRE_5;
61 else if (MP_TYPE(x,y) == CST_FIRE_5)
62 MP_TYPE(x,y) = CST_FIRE_1;
63 }
64 if (MP_INFO(x,y).int_3 == -1)
65 {
66 if ((rand () % FIRE_DAYS_PER_SPREAD) == 1)
67 {
68 i = rand () % 4;
69 switch (i)
70 {
71 case (0):
72 do_random_fire (x - 1, y, 0);
73 break;
74 case (1):
75 do_random_fire (x, y - 1, 0);
76 break;
77 case (2):
78 do_random_fire (x + 1, y, 0);
79 break;
80 case (3):
81 do_random_fire (x, y + 1, 0);
82 break;
83 }
84 }
85 }
86 /* check here 'cos we can wait in the ok box for ever. */
87 else if (MP_INFO(x,y).int_3 == 0)
88 MP_INFO(x,y).int_3 = real_time + 15000; /* 15 secs seem fair */
89 else if (real_time >= MP_INFO(x,y).int_3)
90 MP_INFO(x,y).int_3 = -1;
91 }
92