1 /* ---------------------------------------------------------------------- *
2  * recycle.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 <recycle.h>
17 
18 void
do_recycle(int x,int y)19 do_recycle (int x, int y)
20 {
21   int i;
22   /*
23      // int_1 is the ore made and waiting to go out
24      // int_2 is the used goods in store
25      // int_3 is the used steel in store       NOT USED at this time
26      // int_4 is the tech level when built
27      // int_5 is the recycling done so far this month
28      // int_6 is the percent of max recycling last month
29      // int_7 is the waste in store
30      // cost
31    */
32   recycle_cost += RECYCLE_RUNNING_COST;
33 
34   /*
35      // let these go through, even if we're full of waste. It's a waste of time
36      // checking.
37    */
38   if (x > 0 && (MP_INFO(x - 1,y).flags & FLAG_IS_TRANSPORT) != 0)
39     {
40       i = MP_INFO(x - 1,y).int_7;
41       if (i > MAX_WASTE_AT_RECYCLE - MP_INFO(x,y).int_2)
42 	i = MAX_WASTE_AT_RECYCLE - MP_INFO(x,y).int_2;
43       MP_INFO(x,y).int_2 += i;
44       MP_INFO(x - 1,y).int_7 -= i;
45     }
46   if (y > 0 && (MP_INFO(x,y - 1).flags & FLAG_IS_TRANSPORT) != 0)
47     {
48       i = MP_INFO(x,y - 1).int_7;
49       if (i > MAX_WASTE_AT_RECYCLE - MP_INFO(x,y).int_2)
50 	i = MAX_WASTE_AT_RECYCLE - MP_INFO(x,y).int_2;
51       MP_INFO(x,y).int_2 += i;
52       MP_INFO(x,y - 1).int_7 -= i;
53     }
54 
55   /* get some startup power if not powered yet */
56   if ((MP_INFO(x,y).flags & FLAG_POWERED) == 0)
57     if (get_power (x, y, GOODS_RECYCLED, 1) != 0)
58       MP_INFO(x,y).flags |= FLAG_POWERED;
59 
60   /* no steel recycling yet - no point, it's only used to make goods.
61      // recycle to ore.
62    */
63   if (MP_INFO(x,y).int_1 < MAX_ORE_AT_RECYCLE
64       && MP_INFO(x,y).int_2 > GOODS_RECYCLED
65       && (MP_INFO(x,y).flags & FLAG_POWERED) != 0)
66     if (get_jobs (x, y, RECYCLE_GOODS_JOBS) != 0)
67       {
68 	if (get_power (x, y, GOODS_RECYCLED / 2, 1) == 0)
69 	  MP_INFO(x,y).flags
70 	    &= (0xffffffff - FLAG_POWERED);
71 	else
72 	  MP_INFO(x,y).flags |= FLAG_POWERED;
73 	MP_INFO(x,y).int_2 -= GOODS_RECYCLED;
74 	i = (GOODS_RECYCLED * (10 + ((50 * MP_INFO(x,y).int_4)
75 				     / MAX_TECH_LEVEL))) / 100;
76 	if (i > (GOODS_RECYCLED * 8) / 10)
77 	  i = (GOODS_RECYCLED * 8) / 10;
78 	MP_INFO(x,y).int_1 += i;
79 	ore_made += i;
80 	MP_INFO(x,y).int_5++;
81       }
82   if (total_time % 100 == 0)
83     {
84       MP_INFO(x,y).int_6 = MP_INFO(x,y).int_5;
85       MP_INFO(x,y).int_5 = 0;
86     }
87   /* now bung the ore out */
88   /* put it on the railway */
89   if (x > 0 && MP_GROUP(x-1,y) == GROUP_RAIL
90       && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_RAIL
91       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL
92 				  - MP_INFO(x - 1,y).int_5))
93     {
94       if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
95 	{
96 	  MP_INFO(x,y).int_1
97 	    -= (MAX_ORE_ON_RAIL - MP_INFO(x - 1,y).int_5);
98 	  MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_RAIL;
99 	}
100     }
101   if (y > 0 && MP_GROUP(x,y-1) == GROUP_RAIL
102       && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_RAIL
103       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL
104 				  - MP_INFO(x,y - 1).int_5))
105     {
106       if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
107 	{
108 	  MP_INFO(x,y).int_1
109 	    -= (MAX_ORE_ON_RAIL - MP_INFO(x,y - 1).int_5);
110 	  MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_RAIL;
111 	}
112     }
113   /* put it on the road */
114   if (x > 0 && MP_GROUP(x-1,y) == GROUP_ROAD
115       && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_ROAD
116       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD
117 				  - MP_INFO(x - 1,y).int_5))
118     {
119       if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
120 	{
121 	  MP_INFO(x,y).int_1
122 	    -= (MAX_ORE_ON_ROAD - MP_INFO(x - 1,y).int_5);
123 	  MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_ROAD;
124 	}
125     }
126   if (y > 0 && MP_GROUP(x,y-1) == GROUP_ROAD
127       && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_ROAD
128       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD
129 				  - MP_INFO(x,y - 1).int_5))
130     {
131       if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
132 	{
133 	  MP_INFO(x,y).int_1
134 	    -= (MAX_ORE_ON_ROAD - MP_INFO(x,y - 1).int_5);
135 	  MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_ROAD;
136 	}
137     }
138   /* put it on the tracks */
139   if (x > 0 && MP_GROUP(x-1,y) == GROUP_TRACK
140       && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_TRACK
141       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK
142 				  - MP_INFO(x - 1,y).int_5))
143     {
144       if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
145 	{
146 	  MP_INFO(x,y).int_1
147 	    -= (MAX_ORE_ON_TRACK - MP_INFO(x - 1,y).int_5);
148 	  MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_TRACK;
149 	}
150     }
151   if (y > 0 && MP_GROUP(x,y-1) == GROUP_TRACK
152       && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_TRACK
153       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK
154 				  - MP_INFO(x,y - 1).int_5))
155     {
156       if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
157 	{
158 	  MP_INFO(x,y).int_1
159 	    -= (MAX_ORE_ON_TRACK - MP_INFO(x,y - 1).int_5);
160 	  MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_TRACK;
161 	}
162     }
163   /* if we've still got >90% ore and waste in stock, burn some waste cleanly.
164    */
165   if (MP_INFO(x,y).int_1 > (MAX_ORE_AT_RECYCLE * 9 / 10)
166       && MP_INFO(x,y).int_2 > (MAX_WASTE_AT_RECYCLE * 9 / 10))
167     MP_INFO(x,y).int_2 -= BURN_WASTE_AT_RECYCLE;
168 }
169 
170 void
mps_recycle(int x,int y)171 mps_recycle (int x, int y)
172 {
173   int i = 0;
174   char * p;
175 
176   mps_store_title(i++,_("Recycling"));
177   mps_store_title(i++,_("Center"));
178   i++;
179 
180   mps_store_sfp(i++,_("Capacity"), MP_INFO(x,y).int_6);
181 
182   p = ((MP_INFO(x,y).flags & FLAG_POWERED) != 0) ? _("YES") : _("NO");
183   mps_store_ss(i++,_("Power"),p);
184 
185   mps_store_sfp(i++,_("Tech"),
186 		MP_INFO(x,y).int_4 * 100.0 / MAX_TECH_LEVEL);
187   i++;
188   mps_store_title(i++,_("Inventory"));
189   mps_store_sfp(i++,_("Ore"),
190 		MP_INFO(x,y).int_1 * 100.0 / MAX_ORE_AT_RECYCLE);
191   mps_store_sfp(i++,_("Waste"),
192 		MP_INFO(x,y).int_2 * 100.0 / MAX_WASTE_AT_RECYCLE);
193 
194 }
195