1 /* ---------------------------------------------------------------------- *
2  * cricket.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 <cricket.h>
17 
18 
19 void
do_cricket(int x,int y)20 do_cricket (int x, int y)
21 {
22   /*
23      // int_1 is the jobs stored at the pavillion
24      // int_2 is the goods stored at the pavillion
25      // int_3 is the animation flag
26      // int_4 is the time of the next frame
27    */
28   if (MP_INFO(x,y).int_1
29       < (MAX_JOBS_AT_CRICKET - CRICKET_GET_JOBS))
30     if (get_jobs (x, y, CRICKET_GET_JOBS) != 0)
31       MP_INFO(x,y).int_1 += CRICKET_GET_JOBS;
32   if (MP_INFO(x,y).int_2
33       < (MAX_GOODS_AT_CRICKET - CRICKET_GET_GOODS))
34     if (get_goods (x, y, CRICKET_GET_GOODS) != 0)
35       MP_INFO(x,y).int_2 += CRICKET_GET_GOODS;
36   /* animate */
37   if (MP_INFO(x,y).int_3 && real_time > MP_INFO(x,y).int_4)
38     {
39       MP_INFO(x,y).int_4 = real_time + CRICKET_ANIMATION_SPEED;
40       switch (MP_TYPE(x,y))
41 	{
42 	case (CST_CRICKET_1):
43 	  MP_TYPE(x,y) = CST_CRICKET_2;
44 	  break;
45 	case (CST_CRICKET_2):
46 	  MP_TYPE(x,y) = CST_CRICKET_3;
47 	  break;
48 	case (CST_CRICKET_3):
49 	  MP_TYPE(x,y) = CST_CRICKET_4;
50 	  break;
51 	case (CST_CRICKET_4):
52 	  MP_TYPE(x,y) = CST_CRICKET_5;
53 	  break;
54 	case (CST_CRICKET_5):
55 	  MP_TYPE(x,y) = CST_CRICKET_6;
56 	  break;
57 	case (CST_CRICKET_6):
58 	  MP_TYPE(x,y) = CST_CRICKET_7;
59 	  break;
60 	case (CST_CRICKET_7):
61 	  MP_TYPE(x,y) = CST_CRICKET_1;
62 	  MP_INFO(x,y).int_3 = 0;	/* disable anim */
63 
64 	  break;
65 	}
66     }
67 
68   /* That's all. Cover is done by different functions every 3 months or so. */
69 
70   cricket_cost += CRICKET_RUNNING_COST;
71 }
72 
73 
74 void
do_cricket_cover(int x,int y)75 do_cricket_cover (int x, int y)
76 {
77   int xx, x1, x2, y1, y2;
78   if (MP_INFO(x,y).int_1 < (CRICKET_JOBS * DAYS_BETWEEN_COVER) ||
79       MP_INFO(x,y).int_2 < (CRICKET_GOODS * DAYS_BETWEEN_COVER))
80     return;
81   MP_INFO(x,y).int_1 -= (CRICKET_JOBS * DAYS_BETWEEN_COVER);
82   MP_INFO(x,y).int_2 -= (CRICKET_GOODS * DAYS_BETWEEN_COVER);
83   MP_INFO(x,y).int_3 = 1;	/* turn on animation */
84 
85   x1 = x - CRICKET_RANGE;
86   if (x1 < 0)
87     x1 = 0;
88   x2 = x + CRICKET_RANGE;
89   if (x2 > WORLD_SIDE_LEN)
90     x2 = WORLD_SIDE_LEN;
91   y1 = y - CRICKET_RANGE;
92   if (y1 < 0)
93     y1 = 0;
94   y2 = y + CRICKET_RANGE;
95   if (y2 > WORLD_SIDE_LEN)
96     y2 = WORLD_SIDE_LEN;
97   for (; y1 < y2; y1++)
98     for (xx = x1; xx < x2; xx++)
99       MP_INFO(xx,y1).flags |= FLAG_CRICKET_COVER;
100 }
101 
102 void
mps_cricket(int x,int y)103 mps_cricket (int x, int y)
104 {
105     int i = 0;
106 
107     mps_store_title(i++,_("Cricket Pitch"));
108     i++;
109     mps_store_title(i++,_("Inventory"));
110     mps_store_sfp(i++,_("Jobs"),
111 		  MP_INFO(x,y).int_1 * 100.0 / MAX_JOBS_AT_CRICKET);
112     mps_store_sfp(i++,_("Goods"),
113 		  MP_INFO(x,y).int_2 * 100.0 / MAX_GOODS_AT_CRICKET);
114 
115 }
116