1 /* ---------------------------------------------------------------------- *
2  * organic_farm.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 <lcintl.h>
9 #include <lcconfig.h>
10 #include <lctypes.h>
11 #include <stdlib.h>
12 #include <engglobs.h>
13 #include <mps.h>
14 #include <organic_farm.h>
15 
16 
17 void
do_organic_farm(int x,int y)18 do_organic_farm (int x, int y)
19 {
20   /*
21      // int_1 is the tech level of the farm when built
22      // int_2 is a flag so we don't create a farm with nearly ripe crops.
23      // int_3 is the food sold count so far this year.
24      // int_4 is the food made last year.
25      // int_5 is the random crop rotation key.
26      // int_6 is the random month stagger, so they don't all flash at once
27      // int_7 is the tech-level dependent output of a powered farm with a full
28      // workforce.
29   */
30   int i;
31   if (MP_INFO(x,y).int_5 == 0)	/* this should be done when we create */
32 
33     {				/* the area! */
34 
35       MP_INFO(x,y).int_5 = (rand () % 4) + 1;
36       MP_INFO(x,y).int_6 = rand () % 300;
37     }
38   MP_INFO(x,y).flags &= (0xffffffff - FLAG_POWERED);
39   if (get_jobs (x, y, 1) == 0)
40     put_food (x, y, 30);
41   else if (get_jobs (x, y, FARM_JOBS_USED) != 0)
42     {
43       if (get_power (x, y, ORG_FARM_POWER_REC, 0) != 0)
44 	{
45 	  if (put_food (x, y, (ORGANIC_FARM_FOOD_OUTPUT
46 			       + MP_INFO(x,y).int_7)) == 0)
47 	    put_jobs (x, y, FARM_JOBS_USED);
48 	  else
49 	    MP_INFO(x,y).int_3++;
50 	  MP_INFO(x,y).flags |= FLAG_POWERED;
51 	}
52       else
53 	{
54 	  if (put_food (x, y, (ORGANIC_FARM_FOOD_OUTPUT / 4)) == 0)
55 	    put_jobs (x, y, FARM_JOBS_USED);
56 	  else
57 	    MP_INFO(x,y).int_3++;
58 	}
59     }
60   else if (get_jobs (x, y, FARM_JOBS_USED / 4) != 0)
61     {
62       if (get_power (x, y, ORG_FARM_POWER_REC, 0) != 0)
63 	{
64 	  if (put_food (x, y, (ORGANIC_FARM_FOOD_OUTPUT
65 			       + (MP_INFO(x,y).int_7 / 4))) == 0)
66 	    put_jobs (x, y, FARM_JOBS_USED / 4);
67 	  else
68 	    MP_INFO(x,y).int_3++;
69 	  MP_INFO(x,y).flags |= FLAG_POWERED;
70 	}
71       else
72 	{
73 	  if (put_food (x, y, (ORGANIC_FARM_FOOD_OUTPUT / (4 * 4))) == 0)
74 	    put_jobs (x, y, FARM_JOBS_USED / 4);
75 	  else
76 	    MP_INFO(x,y).int_3++;
77 	}
78     }
79   else
80     {
81       if (get_power (x, y, ORG_FARM_POWER_REC, 0) != 0)
82 	{
83 	  if (put_food (x, y, (ORGANIC_FARM_FOOD_OUTPUT
84 			       + (MP_INFO(x,y).int_7 / 8))) != 0)
85 	    MP_INFO(x,y).int_3++;
86 	  MP_INFO(x,y).flags |= FLAG_POWERED;
87 	}
88       else if (put_food (x, y, 30
89 			 + (ORGANIC_FARM_FOOD_OUTPUT / (4 * 8))) != 0)
90 	MP_INFO(x,y).int_3++;
91     }
92   if ((total_time & 0x7f) == 0)
93     if ((MP_INFO(x,y).flags & FLAG_POWERED) != 0)
94       get_waste (x, y, 0x80 * ORG_FARM_WASTE_GET);
95   if ((total_time % 1200) == 0)
96     {
97       MP_INFO(x,y).int_4 = MP_INFO(x,y).int_3;
98       MP_INFO(x,y).int_3 = 0;
99     }
100   i = ((total_time + (MP_INFO(x,y).int_5 * 1200)
101 	+ MP_INFO(x,y).int_6) % 4800);
102   if (i % 300 == 0)
103     {
104       i /= 300;
105       if ( /* MP_INFO(x,y).int_2!=0 &&  */ MP_INFO(x,y).int_4
106 	  > MIN_FOOD_SOLD_FOR_ANIM)
107 	{
108 	  if (i % 4 == 0)
109 	    {
110 	      MP_INFO(x,y).int_6 = rand () % 100;
111 	    }
112 	  switch (i)
113 	    {
114 	    case (0):
115 	      MP_TYPE(x,y) = CST_FARM_O3;
116 	      break;
117 	    case (1):
118 	      MP_TYPE(x,y) = CST_FARM_O3;
119 	      break;
120 	    case (2):
121 	      MP_TYPE(x,y) = CST_FARM_O3;
122 	      break;
123 	    case (3):
124 	      MP_TYPE(x,y) = CST_FARM_O3;
125 	      break;
126 	    case (4):
127 	      MP_TYPE(x,y) = CST_FARM_O7;
128 	      break;
129 	    case (5):
130 	      MP_TYPE(x,y) = CST_FARM_O7;
131 	      break;
132 	    case (6):
133 	      MP_TYPE(x,y) = CST_FARM_O7;
134 	      break;
135 	    case (7):
136 	      MP_TYPE(x,y) = CST_FARM_O7;
137 	      break;
138 	    case (8):
139 	      MP_TYPE(x,y) = CST_FARM_O11;
140 	      break;
141 	    case (9):
142 	      MP_TYPE(x,y) = CST_FARM_O11;
143 	      break;
144 	    case (10):
145 	      MP_TYPE(x,y) = CST_FARM_O11;
146 	      break;
147 	    case (11):
148 	      MP_TYPE(x,y) = CST_FARM_O11;
149 	      break;
150 	    case (12):
151 	      MP_TYPE(x,y) = CST_FARM_O15;
152 	      break;
153 	    case (13):
154 	      MP_TYPE(x,y) = CST_FARM_O15;
155 	      break;
156 	    case (14):
157 	      MP_TYPE(x,y) = CST_FARM_O15;
158 	      break;
159 	    case (15):
160 	      MP_TYPE(x,y) = CST_FARM_O15;
161 	      break;
162 
163 	    }
164 	}
165       else
166 	{
167 	  MP_TYPE(x,y) = CST_FARM_O0;
168 	}
169     }
170 }
171 
172 void
mps_organic_farm(int x,int y)173 mps_organic_farm (int x, int y)
174 {
175   int i = 0;
176   char * p;
177 
178   snprintf(mps_info[i++], MPS_INFO_CHARS, _("Organic Farm"));
179   i++;
180 
181   if ((MP_INFO(x,y).flags & FLAG_POWERED) != 0)
182     p = _("YES");
183   else
184     p = _("NO ");
185 
186   snprintf(mps_info[i++], MPS_INFO_CHARS, "%s %s", _("Power"), p);
187 
188   snprintf(mps_info[i++], MPS_INFO_CHARS, "%s  %5.1f%%", _("Tech"),
189 	   MP_INFO(x,y).int_1 * 100.0 / MAX_TECH_LEVEL);
190 
191   snprintf(mps_info[i++], MPS_INFO_CHARS, "%s  %5.1f%%", _("Prod"),
192 	   MP_INFO(x,y).int_4 * 100.0 / 1200.0);
193 }
194 
195 
196