1 /* ---------------------------------------------------------------------- *
2  * oremine.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 <engine.h>
16 #include <screen.h>
17 #include <mps.h>
18 #include <oremine.h>
19 
20 
21 
22 void
do_oremine(int x,int y)23 do_oremine (int x, int y)
24 {
25   /*
26      // int_1 is the ore at in stock
27      // int_2 is the ore reserve under the ground or at the surface really.
28    */
29   int xx, yy, xs, ys, xe, ye, cr;
30   if (MP_INFO(x,y).int_1 < DIG_MORE_ORE_TRIGGER - 5000)
31     {
32       xs = x;
33       ys = y;
34       xe = x + 4;
35       ye = y + 4;
36       cr = 0;
37       for (yy = ys; yy < ye; yy++)
38 	for (xx = xs; xx < xe; xx++)
39 	  cr += MP_INFO(xx,yy).ore_reserve;
40       MP_INFO(x,y).int_2 = cr;
41       if (cr > 0)
42 	if (get_jobs (x, y, JOBS_DIG_ORE) != 0)
43 	  for (yy = ys; yy < ye; yy++)
44 	    for (xx = xs; xx < xe; xx++)
45 	      if (MP_INFO(xx,yy).ore_reserve > 0)
46 		{
47 		  MP_INFO(xx,yy).ore_reserve--;
48 		  MP_INFO(x,y).int_1 += 5000;
49 		  ore_made += 5000;
50 		  sust_dig_ore_coal_tip_flag = 0;
51 		  /* maybe want an ore tax? */
52 		  yy = ye;
53 		  xx = xe;	/* break out */
54 		}
55     }
56 
57   if ((MP_INFO(x - 1,y).flags & FLAG_IS_TRANSPORT) != 0)
58     {
59       if (MP_GROUP(x-1,y) == GROUP_RAIL
60 	  && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_RAIL
61 	  && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL
62 				      - MP_INFO(x - 1,y).int_5))
63 	{
64 	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
65 	    {
66 	      MP_INFO(x,y).int_1
67 		-= (MAX_ORE_ON_RAIL - MP_INFO(x - 1,y).int_5);
68 	      MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_RAIL;
69 	    }
70 	}
71       else if (MP_GROUP(x-1,y) == GROUP_ROAD
72 	       && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_ROAD
73 	       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD
74 					   - MP_INFO(x - 1,y).int_5))
75 	{
76 	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
77 	    {
78 	      MP_INFO(x,y).int_1
79 		-= (MAX_ORE_ON_ROAD - MP_INFO(x - 1,y).int_5);
80 	      MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_ROAD;
81 	    }
82 	}
83       else if (MP_GROUP(x - 1,y) == GROUP_TRACK
84 	       && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_TRACK
85 	       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK
86 					   - MP_INFO(x - 1,y).int_5))
87 	{
88 	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
89 	    {
90 	      MP_INFO(x,y).int_1
91 		-= (MAX_ORE_ON_TRACK - MP_INFO(x - 1,y).int_5);
92 	      MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_TRACK;
93 	    }
94 	}
95     }
96 
97   if ((MP_INFO(x,y - 1).flags & FLAG_IS_TRANSPORT) != 0)
98     {
99       if (MP_GROUP(x,y-1) == GROUP_RAIL
100 	  && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_RAIL
101 	  && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL
102 				      - MP_INFO(x,y - 1).int_5))
103 	{
104 	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
105 	    {
106 	      MP_INFO(x,y).int_1
107 		-= (MAX_ORE_ON_RAIL - MP_INFO(x,y - 1).int_5);
108 	      MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_RAIL;
109 	    }
110 	}
111       else if (MP_GROUP(x,y-1) == GROUP_ROAD
112 	       && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_ROAD
113 	       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD
114 					   - MP_INFO(x,y - 1).int_5))
115 	{
116 	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
117 	    {
118 	      MP_INFO(x,y).int_1
119 		-= (MAX_ORE_ON_ROAD - MP_INFO(x,y - 1).int_5);
120 	      MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_ROAD;
121 	    }
122 	}
123       else if (MP_GROUP(x,y-1) == GROUP_TRACK
124 	       && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_TRACK
125 	       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK
126 					   - MP_INFO(x,y - 1).int_5))
127 	{
128 	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
129 	    {
130 	      MP_INFO(x,y).int_1
131 		-= (MAX_ORE_ON_TRACK - MP_INFO(x,y - 1).int_5);
132 	      MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_TRACK;
133 	    }
134 	}
135     }
136 
137 
138   /* choose a graphic */
139   if ((total_time & 0x7f) == 0)
140     {
141       xx = 7 * (MP_INFO(x,y).int_2 + (3 * ORE_RESERVE / 2))
142 	/ (16 * ORE_RESERVE);
143       switch (xx)
144 	{
145 	case (0):
146 	  MP_TYPE(x,y) = CST_OREMINE_8;
147 	  break;
148 	case (1):
149 	  MP_TYPE(x,y) = CST_OREMINE_7;
150 	  break;
151 	case (2):
152 	  MP_TYPE(x,y) = CST_OREMINE_6;
153 	  break;
154 	case (3):
155 	  MP_TYPE(x,y) = CST_OREMINE_5;
156 	  break;
157 	case (4):
158 	  MP_TYPE(x,y) = CST_OREMINE_4;
159 	  break;
160 	case (5):
161 	  MP_TYPE(x,y) = CST_OREMINE_3;
162 	  break;
163 	case (6):
164 	  MP_TYPE(x,y) = CST_OREMINE_2;
165 	  break;
166 	case (7):
167 	  MP_TYPE(x,y) = CST_OREMINE_1;
168 	  break;
169 	}
170 	if (MP_INFO(x,y).int_2 <= 0) {
171 #if defined (commentout)
172 	    do_bulldoze_area (CST_GREEN, x, y);
173 	    place_item(x,y,CST_TIP_0);
174 #endif
175 	    int i,j;
176 	    for (j = 0; j < 4; j++) {
177 		for (i = 0; i < 4; i++) {
178 		    do_bulldoze_area (CST_WATER, x+i, y+j);
179 		}
180 	    }
181 	    connect_rivers ();
182 	    refresh_main_screen ();
183 	}
184     }
185 }
186 
187 void
mps_oremine(int x,int y)188 mps_oremine (int x, int y)
189 {
190   int i = 0;
191 
192   mps_store_title(i++,_("Ore Mine"));
193   i++;
194 
195   mps_store_sfp(i++,_("Stock"),
196 		MP_INFO(x,y).int_1 * 100.0 / DIG_MORE_ORE_TRIGGER);
197   i++;
198 
199   mps_store_sfp(i++,_("Reserve"),
200 		MP_INFO(x,y).int_2 * 100.0 / (ORE_RESERVE * 16));
201 }
202 
203