1 /* ---------------------------------------------------------------------- *
2 * coalmine.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 <coalmine.h>
17
18
19
20 void
do_coalmine(int x,int y)21 do_coalmine (int x, int y)
22 {
23 /*
24 // int_1 is the coal at the surface
25 // int_2 is the coal reserve under the ground. More than one mine can
26 // int_3 is the jobs collected.
27 */
28 /* claim the coal under ground! */
29 int xx, yy, xs, ys, xe, ye, cr;
30 if (MP_INFO(x,y).int_1 < (DIG_MORE_COAL_TRIGGER - 1000))
31 {
32 if (MP_INFO(x,y).int_2 < 0)
33 return; /* run out of reserves */
34
35 xs = x - COAL_RESERVE_SEARCH_LEN;
36 if (xs < 0)
37 xs = 0;
38 ys = y - COAL_RESERVE_SEARCH_LEN;
39 if (ys < 0)
40 ys = 0;
41 xe = x + COAL_RESERVE_SEARCH_LEN;
42 if (xe > WORLD_SIDE_LEN)
43 xe = WORLD_SIDE_LEN;
44 ye = y + COAL_RESERVE_SEARCH_LEN;
45 if (ye > WORLD_SIDE_LEN)
46 ye = WORLD_SIDE_LEN;
47 cr = 0;
48 for (yy = ys; yy < ye; yy++)
49 for (xx = xs; xx < xe; xx++)
50 cr += MP_INFO(xx,yy).coal_reserve;
51 MP_INFO(x,y).int_2 = cr;
52 if (cr > 0)
53 {
54 if (get_jobs (x, y, JOBS_DIG_COAL
55 - MP_INFO(x,y).int_3) != 0)
56 {
57 MP_INFO(x,y).int_3 = 0;
58 for (yy = ys; yy < ye; yy++)
59 for (xx = xs; xx < xe; xx++)
60 if (MP_INFO(xx,yy).coal_reserve > 0)
61 {
62 MP_INFO(xx,yy).coal_reserve--;
63 MP_INFO(x,y).int_1 += 1000;
64 coal_made += 1000;
65 coal_tax += 1000;
66 sust_dig_ore_coal_tip_flag = 0;
67 MP_POL(x,y) += COALMINE_POLLUTION;
68 yy = ye;
69 xx = xe; /* break out */
70
71 }
72 }
73 else if (get_jobs (x, y, JOBS_DIG_COAL / 10) != 0)
74 MP_INFO(x,y).int_3 += JOBS_DIG_COAL / 10;
75 else if (get_jobs (x, y, JOBS_DIG_COAL / 50) != 0)
76 MP_INFO(x,y).int_3 += JOBS_DIG_COAL / 50;
77 }
78 else
79 {
80 MP_INFO(x,y).int_1 = 0;
81 MP_INFO(x,y).int_2 = -1;
82 }
83 }
84 /* put it on the railway */
85 if (MP_GROUP(x - 1,y) == GROUP_RAIL
86 && MP_INFO(x - 1,y).int_3 < MAX_COAL_ON_RAIL
87 && MP_INFO(x,y).int_1 >= (MAX_COAL_ON_RAIL
88 - MP_INFO(x - 1,y).int_3))
89 {
90 if (get_jobs (x, y, JOBS_LOAD_COAL) != 0)
91 {
92 MP_INFO(x,y).int_1
93 -= (MAX_COAL_ON_RAIL - MP_INFO(x - 1,y).int_3);
94 MP_INFO(x - 1,y).int_3 = MAX_COAL_ON_RAIL;
95 }
96 }
97 if (MP_GROUP(x,y-1) == GROUP_RAIL
98 && MP_INFO(x,y - 1).int_3 < MAX_COAL_ON_RAIL
99 && MP_INFO(x,y).int_1 >= (MAX_COAL_ON_RAIL
100 - MP_INFO(x,y - 1).int_3))
101 {
102 if (get_jobs (x, y, JOBS_LOAD_COAL) != 0)
103 {
104 MP_INFO(x,y).int_1
105 -= (MAX_COAL_ON_RAIL - MP_INFO(x,y - 1).int_3);
106 MP_INFO(x,y - 1).int_3 = MAX_COAL_ON_RAIL;
107 }
108 }
109 /* put it on the road */
110 if (MP_GROUP(x-1,y) == GROUP_ROAD
111 && MP_INFO(x - 1,y).int_3 < MAX_COAL_ON_ROAD
112 && MP_INFO(x,y).int_1 >= (MAX_COAL_ON_ROAD
113 - MP_INFO(x - 1,y).int_3))
114 {
115 if (get_jobs (x, y, JOBS_LOAD_COAL) != 0)
116 {
117 MP_INFO(x,y).int_1
118 -= (MAX_COAL_ON_ROAD - MP_INFO(x - 1,y).int_3);
119 MP_INFO(x - 1,y).int_3 = MAX_COAL_ON_ROAD;
120 }
121 }
122 if (MP_GROUP(x,y-1) == GROUP_ROAD
123 && MP_INFO(x,y - 1).int_3 < MAX_COAL_ON_ROAD
124 && MP_INFO(x,y).int_1 >= (MAX_COAL_ON_ROAD
125 - MP_INFO(x,y - 1).int_3))
126 {
127 if (get_jobs (x, y, JOBS_LOAD_COAL) != 0)
128 {
129 MP_INFO(x,y).int_1
130 -= (MAX_COAL_ON_ROAD - MP_INFO(x,y - 1).int_3);
131 MP_INFO(x,y - 1).int_3 = MAX_COAL_ON_ROAD;
132 }
133 }
134 /* put it on the tracks */
135 if (MP_GROUP(x-1,y) == GROUP_TRACK
136 && MP_INFO(x - 1,y).int_3 < MAX_COAL_ON_TRACK
137 && MP_INFO(x,y).int_1 >= (MAX_COAL_ON_TRACK
138 - MP_INFO(x - 1,y).int_3))
139 {
140 if (get_jobs (x, y, JOBS_LOAD_COAL) != 0)
141 {
142 MP_INFO(x,y).int_1
143 -= (MAX_COAL_ON_TRACK - MP_INFO(x - 1,y).int_3);
144 MP_INFO(x - 1,y).int_3 = MAX_COAL_ON_TRACK;
145 }
146 }
147 if (MP_GROUP(x,y-1) == GROUP_TRACK
148 && MP_INFO(x,y - 1).int_3 < MAX_COAL_ON_TRACK
149 && MP_INFO(x,y).int_1 >= (MAX_COAL_ON_TRACK
150 - MP_INFO(x,y - 1).int_3))
151 {
152 if (get_jobs (x, y, JOBS_LOAD_COAL) != 0)
153 {
154 MP_INFO(x,y).int_1
155 -= (MAX_COAL_ON_TRACK - MP_INFO(x,y - 1).int_3);
156 MP_INFO(x,y - 1).int_3 = MAX_COAL_ON_TRACK;
157 }
158 }
159
160 /* choose a graphic */
161 if (MP_INFO(x,y).int_1 > (MAX_COAL_AT_MINE - (MAX_COAL_AT_MINE / 5)))
162 MP_TYPE(x,y) = CST_COALMINE_FULL;
163 else if (MP_INFO(x,y).int_1 > (MAX_COAL_AT_MINE / 2))
164 MP_TYPE(x,y) = CST_COALMINE_MED;
165 else if (MP_INFO(x,y).int_1 > 0)
166 MP_TYPE(x,y) = CST_COALMINE_LOW;
167 else
168 MP_TYPE(x,y) = CST_COALMINE_EMPTY;
169 }
170
171 void
mps_coalmine(int x,int y)172 mps_coalmine (int x, int y)
173 {
174 int i = 0;
175
176 mps_store_title(i++,_("Coal Mine"));
177 i++;
178
179 mps_store_sfp(i++,_("Stock"),
180 MP_INFO(x,y).int_1 * 100 / MAX_COAL_AT_MINE);
181
182 if (MP_INFO(x,y).int_2 > 0) {
183 mps_store_sd(i++, _("Reserve"), MP_INFO(x,y).int_2);
184 } else {
185 mps_store_ss(i++, _("Reserve"), _("EMPTY"));
186 }
187 }
188