1 /* ---------------------------------------------------------------------- *
2  * port.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 <mps.h>
17 #include <port.h>
18 
19 
20 void
do_port(int x,int y)21 do_port (int x, int y)
22 {
23   /*
24      // int_1 is the money made so far this month
25      // int_2 is the money made last month
26      // int_3 holds the 'pence/pennies/bits' to add next time round.
27      // int_4 is the import costs so far this month
28      // int_5 is the import costs for last month
29      // Use int_3 to int_7 of (x+1,y) to hold the individual buy values
30      //                       (x,y+1) is last month's
31      // Use int_3 to int_7 of (x+2,y) to hold the individual sell values
32      //                       (x,y+2) is last month's
33    */
34   int i, et = 0, ic = 0, flags, *b1, *b2, *s1, *s2;
35   /* left connection first */
36   flags = MP_INFO(x,y).flags;
37   if (x > 0 && (MP_INFO(x - 1,y).flags
38 		& FLAG_IS_TRANSPORT) != 0)
39     {
40       if ((flags & FLAG_MB_FOOD) != 0)
41 	{
42 	  i = buy_food (x - 1, y);
43 	  ic += i;
44 	  MP_INFO(x + 1,y).int_3 += i;
45 	}
46       if ((flags & FLAG_MS_FOOD) != 0)
47 	{
48 	  i = sell_food (x - 1, y);
49 	  et += i;
50 	  MP_INFO(x + 2,y).int_3 += i;
51 	}
52       if ((flags & FLAG_MB_COAL) != 0)
53 	{
54 	  i = buy_coal (x - 1, y);
55 	  ic += i;
56 	  MP_INFO(x + 1,y).int_4 += i;
57 	}
58       if ((flags & FLAG_MS_COAL) != 0)
59 	{
60 	  i = sell_coal (x - 1, y);
61 	  et += i;
62 	  MP_INFO(x + 2,y).int_4 += i;
63 	}
64       if ((flags & FLAG_MB_ORE) != 0)
65 	{
66 	  i = buy_ore (x - 1, y);
67 	  ic += i;
68 	  MP_INFO(x + 1,y).int_5 += i;
69 	}
70       if ((flags & FLAG_MS_ORE) != 0)
71 	{
72 	  i = sell_ore (x - 1, y);
73 	  et += i;
74 	  MP_INFO(x + 2,y).int_5 += i;
75 	}
76       if ((flags & FLAG_MB_GOODS) != 0)
77 	{
78 	  i = buy_goods (x - 1, y);
79 	  ic += i;
80 	  MP_INFO(x + 1,y).int_6 += i;
81 	}
82       if ((flags & FLAG_MS_GOODS) != 0)
83 	{
84 	  i = sell_goods (x - 1, y);
85 	  et += i;
86 	  MP_INFO(x + 2,y).int_6 += i;
87 	}
88       if ((flags & FLAG_MB_STEEL) != 0)
89 	{
90 	  i = buy_steel (x - 1, y);
91 	  ic += i;
92 	  MP_INFO(x + 1,y).int_7 += i;
93 	}
94       if ((flags & FLAG_MS_STEEL) != 0)
95 	{
96 	  i = sell_steel (x - 1, y);
97 	  et += i;
98 	  MP_INFO(x + 2,y).int_7 += i;
99 	}
100     }
101   /* upper gate next */
102   if (y > 0 && (MP_INFO(x,y - 1).flags
103 		& FLAG_IS_TRANSPORT) != 0)
104     {
105       if ((flags & FLAG_MB_FOOD) != 0)
106 	{
107 	  i = buy_food (x, y - 1);
108 	  ic += i;
109 	  MP_INFO(x + 1,y).int_3 += i;
110 	}
111       if ((flags & FLAG_MS_FOOD) != 0)
112 	{
113 	  i = sell_food (x, y - 1);
114 	  et += i;
115 	  MP_INFO(x + 2,y).int_3 += i;
116 	}
117       if ((flags & FLAG_MB_COAL) != 0)
118 	{
119 	  i = buy_coal (x, y - 1);
120 	  ic += i;
121 	  MP_INFO(x + 1,y).int_4 += i;
122 	}
123       if ((flags & FLAG_MS_COAL) != 0)
124 	{
125 	  i = sell_coal (x, y - 1);
126 	  et += i;
127 	  MP_INFO(x + 2,y).int_4 += i;
128 	}
129       if ((flags & FLAG_MB_ORE) != 0)
130 	{
131 	  i = buy_ore (x, y - 1);
132 	  ic += i;
133 	  MP_INFO(x + 1,y).int_5 += i;
134 	}
135       if ((flags & FLAG_MS_ORE) != 0)
136 	{
137 	  i = sell_ore (x, y - 1);
138 	  et += i;
139 	  MP_INFO(x + 2,y).int_5 += i;
140 	}
141       if ((flags & FLAG_MB_GOODS) != 0)
142 	{
143 	  i = buy_goods (x, y - 1);
144 	  ic += i;
145 	  MP_INFO(x + 1,y).int_6 += i;
146 	}
147       if ((flags & FLAG_MS_GOODS) != 0)
148 	{
149 	  i = sell_goods (x, y - 1);
150 	  et += i;
151 	  MP_INFO(x + 2,y).int_6 += i;
152 	}
153       if ((flags & FLAG_MB_STEEL) != 0)
154 	{
155 	  i = buy_steel (x, y - 1);
156 	  ic += i;
157 	  MP_INFO(x + 1,y).int_7 += i;
158 	}
159       if ((flags & FLAG_MS_STEEL) != 0)
160 	{
161 	  i = sell_steel (x, y - 1);
162 	  et += i;
163 	  MP_INFO(x + 2,y).int_7 += i;
164 	}
165     }
166   MP_INFO(x,y).int_1 += et;
167   MP_INFO(x,y).int_4 += ic;
168   if (total_time % 100 == 0)
169     {
170       MP_INFO(x,y).int_2 = MP_INFO(x,y).int_1;
171       MP_INFO(x,y).int_1 = 0;
172       MP_INFO(x,y).int_5 = MP_INFO(x,y).int_4;
173       MP_INFO(x,y).int_4 = 0;
174       b1 = &(MP_INFO(x + 1,y).int_3);
175       s1 = &(MP_INFO(x + 2,y).int_3);
176       b2 = &(MP_INFO(x,y + 1).int_3);
177       s2 = &(MP_INFO(x,y + 2).int_3);
178       /* GCS FIX -- This obfuscation is unnecessary. */
179       for (i = 0; i < 5; i++)
180 	{
181 	  *(b2++) = *b1;
182 	  *(s2++) = *s1;
183 	  *(b1++) = 0;
184 	  *(s1++) = 0;
185 	}
186     }
187   if (et > 0)
188     {
189       sust_port_flag = 0;
190       tech_level++;
191     }
192   if (ic > 0)
193     {
194       sust_port_flag = 0;
195       tech_level++;
196     }
197   et += MP_INFO(x,y).int_3;	/* int_3 holds the 'pence' */
198 
199   export_tax += et / 100;
200   MP_INFO(x,y).int_3 = et % 100;
201   import_cost += ic;
202 }
203 
204 void
mps_port(int x,int y)205 mps_port (int x, int y)
206 {
207     int i = 0;
208     char buy[12], sell[12];
209 
210     mps_store_title(i++,_("Port"));
211     i++;
212 
213     num_to_ansi(buy, sizeof(buy), MP_INFO(x,y+1).int_3 / 100);
214     num_to_ansi(sell, sizeof(sell), MP_INFO(x,y+2).int_3 / 100);
215     mps_store_sss(i++,_("Food"),buy,sell);
216 
217     num_to_ansi(buy, sizeof(buy), MP_INFO(x,y+1).int_4 / 100);
218     num_to_ansi(sell, sizeof(sell), MP_INFO(x,y+2).int_4 / 100);
219     mps_store_sss(i++,_("Coal"),buy,sell);
220 
221     num_to_ansi(buy, sizeof(buy), MP_INFO(x,y+1).int_5 / 100);
222     num_to_ansi(sell, sizeof(sell), MP_INFO(x,y+2).int_5 / 100);
223     mps_store_sss(i++,_("Ore"),buy,sell);
224 
225     num_to_ansi(buy, sizeof(buy), MP_INFO(x,y+1).int_6 / 100);
226     num_to_ansi(sell, sizeof(sell), MP_INFO(x,y+2).int_6 / 100);
227     mps_store_sss(i++,_("Goods"),buy,sell);
228 
229     num_to_ansi(buy, sizeof(buy), MP_INFO(x,y+1).int_7 / 100);
230     num_to_ansi(sell, sizeof(sell), MP_INFO(x,y+2).int_7 / 100);
231     mps_store_sss(i++,_("Steel"),buy,sell);
232 
233     num_to_ansi(buy, sizeof(buy), MP_INFO(x,y).int_2 / 100);
234     num_to_ansi(sell, sizeof(sell), MP_INFO(x,y).int_5 / 100);
235     mps_store_sss(i++,_("Total"),buy,sell);
236 
237 }
238 
239 
240