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