1 /* ---------------------------------------------------------------------- *
2  * commune.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 <mps.h>
17 #include <commune.h>
18 
19 
20 void
do_commune(int x,int y)21 do_commune (int x, int y)
22 {
23   /*
24     // int_1 is the animation trigger time
25     // int_2 is the steelflag/trackflag
26     // int_3 is the coal sold in the last 100 days 200 units is 100%
27     // steel adds more.
28     // int_4 is the months without selling much coal,steel,ore
29     // int_5 is the coal, ore, steel waste flags for last month
30     // int_6 is the coal, ore, steel waste flags so far this month
31   */
32   /* GCS -- I folded the trackflag into int_2, changing the logic slightly.
33      This change only affects the animation. */
34   int trackflag = 0;
35   /* stick coal and ore on tracks, in SMALL doses. */
36   if (put_coal (x, y, 2) != 0)
37     {
38       trackflag = 1;
39       MP_INFO(x,y).int_3++;
40       MP_INFO(x,y).int_6 |= 1;
41     }
42   if (put_ore (x, y, 6) != 0)
43     {
44       trackflag = 1;
45       MP_INFO(x,y).int_3++;
46       MP_INFO(x,y).int_6 |= 2;
47     }
48   /* recycle a bit of waste */
49   if (get_waste (x, y, 20) != 0)
50     {
51       trackflag = 1;
52       MP_INFO(x,y).int_3++;
53       MP_INFO(x,y).int_6 |= 8;
54     }
55   if (total_time % 10 == 0)
56     {
57       MP_INFO(x,y).int_2 = 1;
58       if (put_steel (x, y, 2) != 0) {
59 	  MP_INFO(x,y).int_3++;
60 	  MP_INFO(x,y).int_6 |= 4;
61       } else {
62 	MP_INFO(x,y).int_2 = 0;
63       }
64       if (trackflag) {
65 	MP_INFO(x,y).int_2 = 0;
66       }
67     }
68   if (total_time % 100 == 48)
69     {
70       MP_INFO(x,y).int_5 = MP_INFO(x,y).int_6;
71       MP_INFO(x,y).int_6 = 0;
72       if (MP_INFO(x,y).int_2 == 0 || trackflag == 0)
73 	{
74 	  if (MP_TYPE(x,y) > CST_COMMUNE_7)
75 	    MP_TYPE(x,y) -= 7;
76 	}
77       else if (MP_TYPE(x,y) <= CST_COMMUNE_7)
78 	MP_TYPE(x,y) += 7;
79       if (MP_INFO(x,y).int_3 > 0)	/*  >0% */
80 	{
81 	  MP_INFO(x,y).int_3 = 0;
82 	  if (--MP_INFO(x,y).int_4 < 0)
83 	    MP_INFO(x,y).int_4 = 0;
84 	}
85       else
86 	{
87 	  MP_INFO(x,y).int_3 = 0;
88 	  MP_INFO(x,y).int_4++;
89 	  /* XXX: Why do communes only last 10 years? */
90 	  if (MP_INFO(x,y).int_4 > 120)	/* 10 years */
91 	    {
92 	      do_bulldoze_area (CST_PARKLAND_PLANE, x, y);
93 	      return;
94 	    }
95 	}
96     }
97   /* animate */
98   if (real_time >= MP_INFO(x,y).int_1)
99     {
100       MP_INFO(x,y).int_1 = real_time + COMMUNE_ANIM_SPEED;
101       switch (MP_TYPE(x,y))
102 	{
103 	case (CST_COMMUNE_1):
104 	  MP_TYPE(x,y) = CST_COMMUNE_2;
105 	  break;
106 	case (CST_COMMUNE_2):
107 	  MP_TYPE(x,y) = CST_COMMUNE_3;
108 	  break;
109 	case (CST_COMMUNE_3):
110 	  MP_TYPE(x,y) = CST_COMMUNE_4;
111 	  break;
112 	case (CST_COMMUNE_4):
113 	  MP_TYPE(x,y) = CST_COMMUNE_5;
114 	  break;
115 	case (CST_COMMUNE_5):
116 	  MP_TYPE(x,y) = CST_COMMUNE_6;
117 	  break;
118 	case (CST_COMMUNE_6):
119 	  MP_TYPE(x,y) = CST_COMMUNE_1;
120 	  break;
121 	case (CST_COMMUNE_8):
122 	  MP_TYPE(x,y) = CST_COMMUNE_9;
123 	  break;
124 	case (CST_COMMUNE_9):
125 	  MP_TYPE(x,y) = CST_COMMUNE_10;
126 	  break;
127 	case (CST_COMMUNE_10):
128 	  MP_TYPE(x,y) = CST_COMMUNE_11;
129 	  break;
130 	case (CST_COMMUNE_11):
131 	  MP_TYPE(x,y) = CST_COMMUNE_12;
132 	  break;
133 	case (CST_COMMUNE_12):
134 	  MP_TYPE(x,y) = CST_COMMUNE_13;
135 	  break;
136 	case (CST_COMMUNE_13):
137 	  MP_TYPE(x,y) = CST_COMMUNE_8;
138 	  break;
139 
140 	}
141     }
142 
143 }
144 
145 void
mps_commune(int x,int y)146 mps_commune (int x, int y)
147 {
148     int i = 0;
149     char * p;
150 
151     mps_store_title(i++,_("Commune"));
152     i++;
153     i++;
154     mps_store_title(i++,_("Activity"));
155     i++;
156     p = (MP_INFO(x,y).int_5 & 1) ? _("Yes") : _("No");
157     mps_store_ss(i++,_("Coal"),p);
158     p = (MP_INFO(x,y).int_5 & 2) ? _("Yes") : _("No");
159     mps_store_ss(i++,_("Ore"),p);
160     p = (MP_INFO(x,y).int_5 & 4) ? _("Yes") : _("No");
161     mps_store_ss(i++,_("Steel"),p);
162     p = (MP_INFO(x,y).int_5 & 8) ? _("Yes") : _("No");
163     mps_store_ss(i++,_("Waste"),p);
164 }
165