1 /* ---------------------------------------------------------------------- *
2 * firestation.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 <lin-city.h>
9 #include <lctypes.h>
10 #include <lcintl.h>
11 #include <lcconfig.h>
12 #include <engglobs.h>
13 #include <cliglobs.h>
14 #include <stats.h>
15 #include <mps.h>
16 #include <firestation.h>
17
18
19 void
do_firestation(int x,int y)20 do_firestation (int x, int y)
21 {
22 /*
23 // int_1 is the jobs stored at the fire station
24 // int_2 is the goods stored at the fire station
25 // int_3 is the animation flag
26 // int_4 is the time of the next frame
27 // int_5 is the pause counter
28 */
29 /* XXX: should note whether we actually _produced_ fire cover in int_6 */
30 if (MP_INFO(x,y).int_1
31 < (MAX_JOBS_AT_FIRESTATION - FIRESTATION_GET_JOBS))
32 if (get_jobs (x, y, FIRESTATION_GET_JOBS) != 0)
33 MP_INFO(x,y).int_1 += FIRESTATION_GET_JOBS;
34 if (MP_INFO(x,y).int_2
35 < (MAX_GOODS_AT_FIRESTATION - FIRESTATION_GET_GOODS))
36 if (get_goods (x, y, FIRESTATION_GET_GOODS) != 0)
37 MP_INFO(x,y).int_2 += FIRESTATION_GET_GOODS;
38 /* animate */
39 if (MP_INFO(x,y).int_3 && real_time > MP_INFO(x,y).int_4)
40 {
41 MP_INFO(x,y).int_4 = real_time + FIRESTATION_ANIMATION_SPEED;
42 if (MP_INFO(x,y).int_5 > 0)
43 MP_INFO(x,y).int_5--;
44 else
45 {
46 switch (MP_TYPE(x,y))
47 {
48 case (CST_FIRESTATION_1):
49 MP_TYPE(x,y) = CST_FIRESTATION_2;
50 break;
51 case (CST_FIRESTATION_2):
52 MP_TYPE(x,y) = CST_FIRESTATION_3;
53 break;
54 case (CST_FIRESTATION_3):
55 MP_TYPE(x,y) = CST_FIRESTATION_4;
56 break;
57 case (CST_FIRESTATION_4):
58 MP_TYPE(x,y) = CST_FIRESTATION_5;
59 break;
60 case (CST_FIRESTATION_5):
61 MP_TYPE(x,y) = CST_FIRESTATION_6;
62 break;
63 case (CST_FIRESTATION_6):
64 MP_TYPE(x,y) = CST_FIRESTATION_7;
65 MP_INFO(x,y).int_5 = 10; /* pause */
66
67 break;
68 case (CST_FIRESTATION_7):
69 MP_TYPE(x,y) = CST_FIRESTATION_8;
70 break;
71 case (CST_FIRESTATION_8):
72 MP_TYPE(x,y) = CST_FIRESTATION_9;
73 break;
74 case (CST_FIRESTATION_9):
75 MP_TYPE(x,y) = CST_FIRESTATION_10;
76 break;
77 case (CST_FIRESTATION_10):
78 MP_TYPE(x,y) = CST_FIRESTATION_1;
79 MP_INFO(x,y).int_3 = 0; /* stop */
80
81 break;
82
83
84 }
85 }
86 }
87 /* That's all. Cover is done by different functions every 3 months or so. */
88
89 fire_cost += FIRESTATION_RUNNING_COST;
90 }
91
92
93 void
do_fire_cover(int x,int y)94 do_fire_cover (int x, int y)
95 {
96 int xx, x1, x2, y1, y2;
97 if (MP_INFO(x,y).int_1 < (FIRESTATION_JOBS * DAYS_BETWEEN_COVER) ||
98 MP_INFO(x,y).int_2 < (FIRESTATION_GOODS * DAYS_BETWEEN_COVER))
99 return;
100 MP_INFO(x,y).int_1 -= (FIRESTATION_JOBS * DAYS_BETWEEN_COVER);
101 MP_INFO(x,y).int_2 -= (FIRESTATION_GOODS * DAYS_BETWEEN_COVER);
102 MP_INFO(x,y).int_3 = 1; /* turn on animation */
103
104 x1 = x - FIRESTATION_RANGE;
105 if (x1 < 0)
106 x1 = 0;
107 x2 = x + FIRESTATION_RANGE;
108 if (x2 > WORLD_SIDE_LEN)
109 x2 = WORLD_SIDE_LEN;
110 y1 = y - FIRESTATION_RANGE;
111 if (y1 < 0)
112 y1 = 0;
113 y2 = y + FIRESTATION_RANGE;
114 if (y2 > WORLD_SIDE_LEN)
115 y2 = WORLD_SIDE_LEN;
116 for (; y1 < y2; y1++)
117 for (xx = x1; xx < x2; xx++)
118 MP_INFO(xx,y1).flags |= FLAG_FIRE_COVER;
119 }
120
121 void
mps_firestation(int x,int y)122 mps_firestation (int x, int y)
123 {
124 int i = 0;
125
126 mps_store_title(i++,_("Fire Station"));
127 i++;
128 mps_store_title(i++,_("Inventory"));
129 mps_store_sfp(i++,_("Jobs"),
130 MP_INFO(x,y).int_1 * 100.0 / MAX_JOBS_AT_FIRESTATION);
131 mps_store_sfp(i++,_("Goods"),
132 MP_INFO(x,y).int_2 * 100.0 / MAX_GOODS_AT_FIRESTATION);
133
134 }
135