1 /* ---------------------------------------------------------------------- *
2 * coal_power.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 <lclib.h>
13 #include <engglobs.h>
14 #include <cliglobs.h>
15 #include <stats.h>
16 #include <power.h>
17 #include <coal_power.h>
18 #include <mps.h>
19 #include <transport.h> /* XXX: This seems to be an anomaly; no other modules
20 use XY_IS_TRANSPORT */
21
22 /*** Coal Power ***/
23 /*
24 // int_1 is the maximum possible power
25 // int_2 is the coal at the power station
26 // int_3 is the stored jobs... Must be an interesting warehouse
27 // int_4 is the tech level when built
28 // int_5 is the projected output.
29 */
30
31
32 void
do_power_source_coal(int x,int y)33 do_power_source_coal (int x, int y)
34 {
35
36 /* Need coal? Try transport. */
37 if (MP_INFO(x,y).int_2 < MAX_COAL_AT_POWER_STATION) {
38
39 /* left side */
40 if (XY_IS_TRANSPORT(x-1, y+1) && MP_INFO(x-1, y+1).int_3 > 0) {
41 if (get_jobs (x, y, JOBS_LOAD_COAL) != 0)
42 {
43 MP_INFO(x,y).int_2 += (MP_INFO(x-1, y+1).int_3 / 2
44 + ((MP_INFO(x-1, y+1).int_3) % 2));
45 MP_INFO(x-1, y+1).int_3 /= 2;
46 MP_POL(x,y)++;
47 }
48 }
49 /* top side */
50 else if (XY_IS_TRANSPORT(x+1, y-1) && MP_INFO(x+1, y-1).int_3 > 0) {
51 if (get_jobs (x, y, JOBS_LOAD_COAL) != 0)
52 MP_INFO(x,y).int_2 += (MP_INFO(x+1, y-1).int_3 / 2
53 + ((MP_INFO(x+1, y-1).int_3) % 2));
54 MP_INFO(x + 1,y - 1).int_3 /= 2;
55 MP_POL(x,y)++;
56 }
57 }
58
59 /* Need jobs? get_jobs. */
60 if ((MP_INFO(x,y).int_3 + JOBS_COALPS_GENERATE + 10)
61 < MAX_JOBS_AT_COALPS)
62 if (get_jobs (x, y, JOBS_COALPS_GENERATE + 10) != 0)
63 MP_INFO(x,y).int_3 += JOBS_COALPS_GENERATE + 10;
64
65 /* Generate Power */
66 if (MP_INFO(x,y).int_2 > POWERS_COAL_OUTPUT / 500 &&
67 MP_INFO(x,y).int_3 > JOBS_COALPS_GENERATE)
68 {
69 MP_INFO(x,y).int_5 = MP_INFO(x,y).int_1;
70 MP_INFO(x,y).int_3 -= JOBS_COALPS_GENERATE;
71 MP_INFO(x,y).int_2 -= POWERS_COAL_OUTPUT / 500;
72 coal_used += POWERS_COAL_OUTPUT / 500;
73 MP_POL(x,y) += POWERS_COAL_POLLUTION;
74 grid[MP_INFO(x,y).int_6]->avail_power += MP_INFO(x,y).int_1;
75 }
76
77 /* Animation */
78 /* choose a graphic */
79 if (MP_INFO(x,y).int_2 > (MAX_COAL_AT_POWER_STATION
80 - (MAX_COAL_AT_POWER_STATION / 5)))
81 MP_TYPE(x,y) = CST_POWERS_COAL_FULL;
82 else if (MP_INFO(x,y).int_2 > (MAX_COAL_AT_POWER_STATION / 2))
83 MP_TYPE(x,y) = CST_POWERS_COAL_MED;
84 else if (MP_INFO(x,y).int_2 > (MAX_COAL_AT_POWER_STATION / 10))
85 MP_TYPE(x,y) = CST_POWERS_COAL_LOW;
86 else
87 MP_TYPE(x,y) = CST_POWERS_COAL_EMPTY;
88 }
89
90 void
mps_coal_power(int x,int y)91 mps_coal_power (int x, int y)
92 {
93 int i = 0;
94
95 char s[12];
96
97 mps_store_title(i++,_("Coal"));
98 mps_store_title(i++,_("Power Station"));
99 i++;
100
101 format_power (s, sizeof(s), MP_INFO(x,y).int_1);
102 mps_store_title(i++,_("Max Output"));
103 mps_store_title(i++,s);
104 i++;
105
106 format_power (s, sizeof(s), MP_INFO(x,y).int_5);
107 mps_store_title(i++,_("Current Output"));
108 mps_store_title(i++,s);
109 i++;
110
111 mps_store_sfp(i++,_("Coal"),
112 MP_INFO(x,y).int_2 * 100.0 / MAX_COAL_AT_POWER_STATION);
113 mps_store_sfp(i++,_("Jobs"),
114 MP_INFO(x,y).int_3 * 100.0 / MAX_JOBS_AT_COALPS);
115 mps_store_sfp(i++,_("Tech"),
116 MP_INFO(x,y).int_4 * 100.0 / MAX_TECH_LEVEL);
117 mps_store_sd(i++,_("Grid ID"), MP_INFO(x,y).int_6);
118 }
119