1 /* ---------------------------------------------------------------------- *
2 * windmill.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 <lclib.h>
17 #include <power.h>
18 #include <windmill.h>
19
20
21 /*** Windmills ***/
22 /*
23 // int_1 is the rated capacity
24 // int_2 is the tech level when built
25 // int_3 is the sail count - to choose the right sail.
26 // int_4 is the last real time that a sail was turned
27 // int_5 is the power produced (basically _if_ power produced)
28 // int_6 is the grid it's on
29 // int_7 is a timestamp for mapping
30 */
31 void
do_windmill(int x,int y)32 do_windmill (int x, int y)
33 {
34 int anim_tile;
35
36 if (get_jobs (x, y, WINDMILL_JOBS) != 0) {
37 MP_INFO(x,y).int_5 = MP_INFO(x,y).int_1;
38 grid[MP_INFO(x,y).int_6]->avail_power += MP_INFO(x,y).int_1;
39 } else {
40 MP_INFO(x,y).int_4 = real_time + MODERN_WINDMILL_ANIM_SPEED;
41 return;
42 }
43
44 /* update animation */
45 if (real_time > MP_INFO(x,y).int_4) {
46 MP_INFO(x,y).int_3++;
47 if (MP_INFO(x,y).int_2 < MODERN_WINDMILL_TECH) {
48 MP_INFO(x,y).int_4 = real_time + ANTIQUE_WINDMILL_ANIM_SPEED;
49 } else {
50 MP_INFO(x,y).int_4 = real_time + MODERN_WINDMILL_ANIM_SPEED;
51 }
52 }
53
54 /* figure out which tile to use */
55 anim_tile = (MP_INFO(x,y).int_3 % 3);
56
57 if (MP_INFO(x,y).int_2 < MODERN_WINDMILL_TECH)
58 MP_TYPE(x,y) = CST_WINDMILL_1_W + anim_tile;
59 else
60 switch(grid[MP_INFO(x,y).int_6]->powered)
61 {
62 case -1:
63 MP_TYPE(x,y) = CST_WINDMILL_1_R + anim_tile;
64 break;
65 case 0 :
66 MP_TYPE(x,y) = CST_WINDMILL_1_RG + anim_tile;
67 break;
68 case 1 :
69 MP_TYPE(x,y) = CST_WINDMILL_1_G + anim_tile;
70 break;
71 default :
72 printf("Default case in do_power_substation\n");
73 break;
74 }
75 }
76
77 void
mps_windmill(int x,int y)78 mps_windmill (int x, int y)
79 {
80 int i = 0;
81 char s[12];
82
83 mps_store_title(i++,_("Windmill"));
84 i++;
85
86 if (MP_INFO(x,y).int_2 < MODERN_WINDMILL_TECH) {
87 mps_store_sfp(i++,_("Tech"),
88 MP_INFO(x,y).int_2 * 100.0 / MAX_TECH_LEVEL);
89 } else {
90 mps_store_title(i++,_("Local Status"));
91
92 format_power (s, sizeof(s), MP_INFO(x,y).int_1);
93 mps_store_ss(i++,_("Prod."),s);
94
95 format_power (s, sizeof(s), MP_INFO(x,y).int_5);
96 mps_store_ss(i++,_("Demand"),s);
97
98 mps_store_sfp(i++,_("Tech"),
99 MP_INFO(x,y).int_2 * 100.0 / MAX_TECH_LEVEL);
100 i++;
101
102 mps_store_title(i++,_("Grid Status"));
103
104 format_power (s, sizeof(s), grid[MP_INFO(x,y).int_6]->max_power);
105 mps_store_ss(i++,_("T. Cap."), s);
106
107 format_power (s, sizeof(s), grid[MP_INFO(x,y).int_6]->avail_power);
108 mps_store_ss(i++,_("A. Cap."), s);
109
110 format_power (s, sizeof(s), grid[MP_INFO(x,y).int_6]->demand);
111 mps_store_ss(i++,_("Demand"), s);
112 i++;
113
114 mps_store_sd(i++,_("Grid ID"), MP_INFO(x,y).int_6);
115 }
116 }
117
118