1 /* ---------------------------------------------------------------------- *
2  * blacksmith.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 <blacksmith.h>
17 
18 
19 void
do_blacksmith(int x,int y)20 do_blacksmith (int x, int y)
21 {
22   /*
23     // int_1 contains the goods at the blacksmith
24     // int_2 contains the goods made - for the animation
25     // int_3 contains the coal store
26     // int_4 is the animation trigger time
27     // int_5 is the % made so far this month
28     // int_6 is the % capacity last month
29   */
30   if (MP_INFO(x,y).int_3 < MAX_COAL_AT_BLACKSMITH)
31     if (get_coal (x, y, BLACKSMITH_GET_COAL) != 0)
32       MP_INFO(x,y).int_3 += BLACKSMITH_GET_COAL;
33   if (MP_INFO(x,y).int_1 < MAX_GOODS_AT_BLACKSMITH
34       && MP_INFO(x,y).int_3 >= BLACKSMITH_COAL_USED)
35     {
36       if (get_steel (x, y, BLACKSMITH_STEEL_USED) != 0)
37 	{
38 	  MP_INFO(x,y).int_1 += GOODS_MADE_BY_BLACKSMITH;
39 	  MP_INFO(x,y).int_3 -= BLACKSMITH_COAL_USED;
40 	}
41     }
42   if (get_jobs (x, y, BLACKSMITH_JOBS) != 0)
43     {
44       if (MP_INFO(x,y).int_1 > GOODS_MADE_BY_BLACKSMITH)
45 	{
46 	  if (put_goods (x, y, GOODS_MADE_BY_BLACKSMITH - 1) != 0)
47 	    {
48 	      MP_INFO(x,y).int_1 -= (GOODS_MADE_BY_BLACKSMITH - 1);
49 	      MP_INFO(x,y).int_2 += (GOODS_MADE_BY_BLACKSMITH - 1);
50 	      MP_INFO(x,y).int_5++;
51 	    }
52 	  else
53 	    put_jobs (x, y, BLACKSMITH_JOBS);
54 	}
55       else
56 	put_jobs (x, y, BLACKSMITH_JOBS);
57     }
58   else
59     MP_TYPE(x,y) = CST_BLACKSMITH_0;
60   if (MP_INFO(x,y).int_2 > BLACKSMITH_BATCH
61       && real_time >= MP_INFO(x,y).int_4)
62     {
63       MP_INFO(x,y).int_4 = real_time + BLACKSMITH_ANIM_SPEED;
64       switch (MP_TYPE(x,y))
65 	{
66 	case (CST_BLACKSMITH_0):
67 	  MP_TYPE(x,y) = CST_BLACKSMITH_1;
68 	  break;
69 	case (CST_BLACKSMITH_1):
70 	  MP_TYPE(x,y) = CST_BLACKSMITH_2;
71 	  break;
72 	case (CST_BLACKSMITH_2):
73 	  MP_TYPE(x,y) = CST_BLACKSMITH_3;
74 	  break;
75 	case (CST_BLACKSMITH_3):
76 	  MP_TYPE(x,y) = CST_BLACKSMITH_4;
77 	  break;
78 	case (CST_BLACKSMITH_4):
79 	  MP_TYPE(x,y) = CST_BLACKSMITH_5;
80 	  break;
81 	case (CST_BLACKSMITH_5):
82 	  MP_TYPE(x,y) = CST_BLACKSMITH_6;
83 	  break;
84 	case (CST_BLACKSMITH_6):
85 	  MP_TYPE(x,y) = CST_BLACKSMITH_1;
86 	  MP_INFO(x,y).int_2 = 0;
87 	  MP_POL(x,y)++;
88 	  break;
89 	}
90     }
91   if (total_time % 100 == 0)
92     {
93       MP_INFO(x,y).int_6 = MP_INFO(x,y).int_5;
94       MP_INFO(x,y).int_5 = 0;
95     }
96 }
97 
98 void
mps_blacksmith(int x,int y)99 mps_blacksmith (int x, int y)
100 {
101   int i = 0;
102 
103   mps_store_title(i++,_("Blacksmith"));
104   i++;
105 
106   mps_store_sfp(i++,_("Capacity"), MP_INFO(x,y).int_6);
107   i++;
108   mps_store_title(i++,_("Inventory"));
109   mps_store_sfp(i++,_("Goods"),
110 		MP_INFO(x,y).int_1 * 100.0 / MAX_GOODS_AT_BLACKSMITH);
111   mps_store_sfp(i++,_("Coal"),
112 		MP_INFO(x,y).int_3 * 100.0 / MAX_COAL_AT_BLACKSMITH);
113 }
114