1 /* ---------------------------------------------------------------------- *
2 * light_industry.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 <light_industry.h>
17
18
19 void
do_industry_l(int x,int y)20 do_industry_l (int x, int y)
21 {
22 int goods = 0;
23 /*
24 // int_1 is the goods produced this month so far
25 // int_2 is the amount of goods in store.
26 // int_3 is the amount of ore in store.
27 // int_4 is the amount of steel in store.
28 // int_5 is the jobs stored.
29 // int_6 is the percent of capacity last month.
30 // int 7 is the next animation frame time.
31 */
32 /* first get some jobs */
33 if (MP_INFO(x,y).int_5 < MAX_JOBS_AT_INDUSTRY_L - INDUSTRY_L_GET_JOBS)
34 {
35 if (get_jobs (x, y, INDUSTRY_L_GET_JOBS) != 0)
36 MP_INFO(x,y).int_5 += INDUSTRY_L_GET_JOBS;
37 else if (get_jobs (x, y, INDUSTRY_L_GET_JOBS / 10) != 0)
38 MP_INFO(x,y).int_5 += INDUSTRY_L_GET_JOBS / 10;
39 }
40 /* if we don't have enough jobs we can't do anything */
41 if (MP_INFO(x,y).int_5 < MIN_JOBS_AT_INDUSTRY_L)
42 return;
43 /* get some ore */
44 if (MP_INFO(x,y).int_3 < (MAX_ORE_AT_INDUSTRY_L
45 - INDUSTRY_L_GET_ORE))
46 {
47 if ((MP_INFO(x - 1,y).flags & FLAG_IS_TRANSPORT) != 0
48 && MP_INFO(x - 1,y).int_5 > 0)
49 {
50 if (MP_INFO(x - 1,y).int_5 >= INDUSTRY_L_GET_ORE)
51 {
52 MP_INFO(x,y).int_3 += INDUSTRY_L_GET_ORE;
53 MP_INFO(x - 1,y).int_5 -= INDUSTRY_L_GET_ORE;
54 }
55 else
56 {
57 MP_INFO(x,y).int_3 += MP_INFO(x - 1,y).int_5;
58 MP_INFO(x - 1,y).int_5 = 0;
59 }
60 MP_INFO(x,y).int_5 -= INDUSTRY_L_JOBS_LOAD_ORE;
61 }
62 }
63 /* do we still need some ore? */
64 if (MP_INFO(x,y).int_3 < (MAX_ORE_AT_INDUSTRY_L
65 - INDUSTRY_L_GET_ORE))
66 {
67 if ((MP_INFO(x,y - 1).flags & FLAG_IS_TRANSPORT) != 0
68 && MP_INFO(x,y - 1).int_5 > 0)
69 {
70 if (MP_INFO(x,y - 1).int_5 >= INDUSTRY_L_GET_ORE)
71 {
72 MP_INFO(x,y).int_3 += INDUSTRY_L_GET_ORE;
73 MP_INFO(x,y - 1).int_5 -= INDUSTRY_L_GET_ORE;
74 }
75 else
76 {
77 MP_INFO(x,y).int_3 += MP_INFO(x,y - 1).int_5;
78 MP_INFO(x,y - 1).int_5 = 0;
79 }
80 MP_INFO(x,y).int_5 -= INDUSTRY_L_JOBS_LOAD_ORE;
81 }
82 }
83 /* then get some steel */
84 if (MP_INFO(x,y).int_4 < (MAX_STEEL_AT_INDUSTRY_L
85 - INDUSTRY_L_GET_STEEL))
86 {
87 if ((MP_INFO(x - 1,y).flags & FLAG_IS_TRANSPORT) != 0
88 && MP_INFO(x - 1,y).int_6 > 0)
89 {
90 if (MP_INFO(x - 1,y).int_6 >= INDUSTRY_L_GET_STEEL)
91 {
92 MP_INFO(x,y).int_4 += INDUSTRY_L_GET_STEEL;
93 MP_INFO(x - 1,y).int_6 -= INDUSTRY_L_GET_STEEL;
94 }
95 else
96 {
97 MP_INFO(x,y).int_4
98 += MP_INFO(x - 1,y).int_6;
99 MP_INFO(x - 1,y).int_6 = 0;
100 }
101 MP_INFO(x,y).int_5 -= INDUSTRY_L_JOBS_LOAD_STEEL;
102 }
103 }
104 /* do we still need some steel? */
105 if (MP_INFO(x,y).int_4 < (MAX_STEEL_AT_INDUSTRY_L
106 - INDUSTRY_L_GET_STEEL))
107 {
108 if ((MP_INFO(x,y - 1).flags & FLAG_IS_TRANSPORT) != 0
109 && MP_INFO(x,y - 1).int_6 > 0)
110 {
111 if (MP_INFO(x,y - 1).int_6 >= INDUSTRY_L_GET_STEEL)
112 {
113 MP_INFO(x,y).int_4 += INDUSTRY_L_GET_STEEL;
114 MP_INFO(x,y - 1).int_6 -= INDUSTRY_L_GET_STEEL;
115 }
116 else
117 {
118 MP_INFO(x,y).int_4
119 += MP_INFO(x,y - 1).int_6;
120 MP_INFO(x,y - 1).int_6 = 0;
121 }
122 MP_INFO(x,y).int_5 -= INDUSTRY_L_JOBS_LOAD_STEEL;
123 }
124 }
125 /* now make some goods */
126 if (MP_INFO(x,y).int_2 < (MAX_GOODS_AT_INDUSTRY_L
127 - (INDUSTRY_L_MAKE_GOODS * 8)) && MP_INFO(x,y).int_3
128 >= INDUSTRY_L_ORE_USED)
129 {
130 goods += INDUSTRY_L_MAKE_GOODS;
131 MP_INFO(x,y).int_3 -= INDUSTRY_L_ORE_USED;
132 ore_used += INDUSTRY_L_ORE_USED;
133 MP_INFO(x,y).int_5 -= INDUSTRY_L_JOBS_USED;
134 MP_POL(x,y) += INDUSTRY_L_POLLUTION;
135
136 /* multiply by 2 if we have steel. */
137 if (MP_INFO(x,y).int_4 >= INDUSTRY_L_STEEL_USED)
138 {
139 MP_INFO(x,y).int_4 -= INDUSTRY_L_STEEL_USED;
140 goods += goods;
141 }
142 /* multipy by 4 if we can get power. */
143
144 if (MP_INFO(x,y).int_3 >= INDUSTRY_L_ORE_USED
145 && get_power (x, y, goods * 10, 1) != 0)
146 {
147 goods *= 4;
148 MP_INFO(x,y).flags |= FLAG_POWERED;
149 /* and use more ore */
150 MP_INFO(x,y).int_3 -= INDUSTRY_L_ORE_USED;
151 ore_used += INDUSTRY_L_ORE_USED;
152 }
153 else
154 MP_INFO(x,y).flags &= (0xffffffff - FLAG_POWERED);
155 }
156
157 MP_INFO(x,y).int_1 += goods;
158 MP_INFO(x,y).int_2 += goods;
159 goods_made += goods;
160
161 /* now sell the goods to the road/rail/track */
162 if (MP_GROUP(x,y - 1) == GROUP_ROAD
163 && (MAX_GOODS_ON_ROAD - MP_INFO(x,y - 1).int_4) <= MP_INFO(x,y).int_2)
164 {
165 MP_INFO(x,y).int_2 -= (MAX_GOODS_ON_ROAD - MP_INFO(x,y - 1).int_4);
166 MP_INFO(x,y - 1).int_4 = MAX_GOODS_ON_ROAD;
167 }
168 else if (MP_GROUP(x,y - 1) == GROUP_RAIL
169 && (MAX_GOODS_ON_RAIL - MP_INFO(x,y - 1).int_4)
170 <= MP_INFO(x,y).int_2)
171 {
172 MP_INFO(x,y).int_2 -= (MAX_GOODS_ON_RAIL
173 - MP_INFO(x,y - 1).int_4);
174 MP_INFO(x,y - 1).int_4 = MAX_GOODS_ON_RAIL;
175 }
176 else if (MP_GROUP(x,y - 1) == GROUP_TRACK
177 && (MAX_GOODS_ON_TRACK - MP_INFO(x,y - 1).int_4)
178 <= MP_INFO(x,y).int_2)
179 {
180 MP_INFO(x,y).int_2 -= (MAX_GOODS_ON_TRACK
181 - MP_INFO(x,y - 1).int_4);
182 MP_INFO(x,y - 1).int_4 = MAX_GOODS_ON_TRACK;
183 }
184
185
186 if (MP_GROUP(x - 1,y) == GROUP_ROAD
187 && (MAX_GOODS_ON_ROAD - MP_INFO(x - 1,y).int_4)
188 <= MP_INFO(x,y).int_2)
189 {
190 MP_INFO(x,y).int_2 -= (MAX_GOODS_ON_ROAD
191 - MP_INFO(x - 1,y).int_4);
192 MP_INFO(x - 1,y).int_4 = MAX_GOODS_ON_ROAD;
193 }
194 else if (MP_GROUP(x - 1,y) == GROUP_RAIL
195 && (MAX_GOODS_ON_RAIL - MP_INFO(x - 1,y).int_4)
196 <= MP_INFO(x,y).int_2)
197 {
198 MP_INFO(x,y).int_2 -= (MAX_GOODS_ON_RAIL
199 - MP_INFO(x - 1,y).int_4);
200 MP_INFO(x - 1,y).int_4 = MAX_GOODS_ON_RAIL;
201 }
202 else if (MP_GROUP(x-1,y) == GROUP_TRACK
203 && (MAX_GOODS_ON_TRACK - MP_INFO(x - 1,y).int_4)
204 <= MP_INFO(x,y).int_2)
205 {
206 MP_INFO(x,y).int_2 -= (MAX_GOODS_ON_TRACK
207 - MP_INFO(x - 1,y).int_4);
208 MP_INFO(x - 1,y).int_4 = MAX_GOODS_ON_TRACK;
209 }
210
211 /* now choose a graphic every month */
212 if ((total_time % NUMOF_DAYS_IN_MONTH) == NUMOF_DAYS_IN_MONTH - 1)
213 {
214 MP_INFO(x,y).int_6 = (MP_INFO(x,y).int_1)
215 / (INDUSTRY_L_MAKE_GOODS * 8);
216 MP_INFO(x,y).int_1 = 0;
217 if (MP_INFO(x,y).int_6 > 80)
218 {
219 switch (MP_TYPE(x,y))
220 {
221 case (CST_INDUSTRY_L_H1):
222 case (CST_INDUSTRY_L_H2):
223 case (CST_INDUSTRY_L_H3):
224 case (CST_INDUSTRY_L_H4):
225 break;
226 default:
227 MP_TYPE(x,y) = CST_INDUSTRY_L_H1;
228 }
229 }
230 else if (MP_INFO(x,y).int_6 > 55)
231 {
232 switch (MP_TYPE(x,y))
233 {
234 case (CST_INDUSTRY_L_M1):
235 case (CST_INDUSTRY_L_M2):
236 case (CST_INDUSTRY_L_M3):
237 case (CST_INDUSTRY_L_M4):
238 break;
239 default:
240 MP_TYPE(x,y) = CST_INDUSTRY_L_M1;
241 }
242 }
243 else if (MP_INFO(x,y).int_6 > 25)
244 {
245 switch (MP_TYPE(x,y))
246 {
247 case (CST_INDUSTRY_L_L1):
248 case (CST_INDUSTRY_L_L2):
249 case (CST_INDUSTRY_L_L3):
250 case (CST_INDUSTRY_L_L4):
251 break;
252 default:
253 MP_TYPE(x,y) = CST_INDUSTRY_L_L1;
254 }
255 }
256 else if (MP_INFO(x,y).int_6 > 0)
257 {
258 switch (MP_TYPE(x,y))
259 {
260 case (CST_INDUSTRY_L_Q1):
261 case (CST_INDUSTRY_L_Q2):
262 case (CST_INDUSTRY_L_Q3):
263 case (CST_INDUSTRY_L_Q4):
264 break;
265 default:
266 MP_TYPE(x,y) = CST_INDUSTRY_L_Q1;
267 }
268 }
269 else
270 MP_TYPE(x,y) = CST_INDUSTRY_L_C;
271 }
272 /* now animate */
273 if (real_time >= MP_INFO(x,y).int_7)
274 {
275 MP_INFO(x,y).int_7 = real_time + INDUSTRY_L_ANIM_SPEED;
276 switch (MP_TYPE(x,y))
277 {
278 case (CST_INDUSTRY_L_Q1):
279 MP_TYPE(x,y) = CST_INDUSTRY_L_Q2;
280 break;
281 case (CST_INDUSTRY_L_Q2):
282 MP_TYPE(x,y) = CST_INDUSTRY_L_Q3;
283 break;
284 case (CST_INDUSTRY_L_Q3):
285 MP_TYPE(x,y) = CST_INDUSTRY_L_Q4;
286 break;
287 case (CST_INDUSTRY_L_Q4):
288 MP_TYPE(x,y) = CST_INDUSTRY_L_Q1;
289 break;
290 case (CST_INDUSTRY_L_L1):
291 MP_TYPE(x,y) = CST_INDUSTRY_L_L2;
292 break;
293 case (CST_INDUSTRY_L_L2):
294 MP_TYPE(x,y) = CST_INDUSTRY_L_L3;
295 break;
296 case (CST_INDUSTRY_L_L3):
297 MP_TYPE(x,y) = CST_INDUSTRY_L_L4;
298 break;
299 case (CST_INDUSTRY_L_L4):
300 MP_TYPE(x,y) = CST_INDUSTRY_L_L1;
301 break;
302 case (CST_INDUSTRY_L_M1):
303 MP_TYPE(x,y) = CST_INDUSTRY_L_M2;
304 break;
305 case (CST_INDUSTRY_L_M2):
306 MP_TYPE(x,y) = CST_INDUSTRY_L_M3;
307 break;
308 case (CST_INDUSTRY_L_M3):
309 MP_TYPE(x,y) = CST_INDUSTRY_L_M4;
310 break;
311 case (CST_INDUSTRY_L_M4):
312 MP_TYPE(x,y) = CST_INDUSTRY_L_M1;
313 break;
314 case (CST_INDUSTRY_L_H1):
315 MP_TYPE(x,y) = CST_INDUSTRY_L_H2;
316 break;
317 case (CST_INDUSTRY_L_H2):
318 MP_TYPE(x,y) = CST_INDUSTRY_L_H3;
319 break;
320 case (CST_INDUSTRY_L_H3):
321 MP_TYPE(x,y) = CST_INDUSTRY_L_H4;
322 break;
323 case (CST_INDUSTRY_L_H4):
324 MP_TYPE(x,y) = CST_INDUSTRY_L_H1;
325 break;
326 }
327 }
328 }
329
330
331 void
mps_light_industry(int x,int y)332 mps_light_industry (int x, int y)
333 {
334 int i = 0;
335 char * p;
336
337 mps_store_title(i++,_("Light"));
338 mps_store_title(i++,_("Industry"));
339
340 i++;
341
342 p = ((MP_INFO(x,y).flags & FLAG_POWERED) != 0) ? _("YES") : _("NO");
343 mps_store_ss(i++,_("Power"),p);
344
345 mps_store_sd(i++,_("Output"),MP_INFO(x,y).int_1);
346
347 mps_store_sfp(i++,_("Store"),
348 MP_INFO(x,y).int_2 * 100.0 / MAX_GOODS_AT_INDUSTRY_L);
349 mps_store_sfp(i++,_("Ore"),
350 MP_INFO(x,y).int_3 * 100.0 / MAX_ORE_AT_INDUSTRY_L);
351 mps_store_sfp(i++,_("Steel"),
352 MP_INFO(x,y).int_4 * 100.0 / MAX_STEEL_AT_INDUSTRY_L);
353 mps_store_sfp(i++,_("Capacity"),
354 MP_INFO(x,y).int_6);
355 }
356