1 /* ---------------------------------------------------------------------- *
2 * substation.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 "modules.h"
9 #include "../power.h"
10 #include "substation.h"
11
12 #include <stdlib.h>
13
14 /* Substations
15 *
16 * int_1 unused
17 * int_2 unused
18 * int_3 unused
19 * int_4 is the power demand at this substation
20 * int_5 forbidden for substations: it is power production from power sources
21 * and windmill is both a source power and a substation
22 * int_6 is the grid its connected to
23 * int_7 is a grid timestamp
24 */
25
do_power_substation(int x,int y)26 void do_power_substation(int x, int y)
27 {
28 switch (grid[MP_INFO(x, y).int_6]->powered) {
29 case -1:{
30 MP_TYPE(x, y) = CST_SUBSTATION_R;
31 }
32 break;
33 case 0:{
34 MP_TYPE(x, y) = CST_SUBSTATION_RG;
35 }
36 break;
37 case 1:{
38 MP_TYPE(x, y) = CST_SUBSTATION_G;
39 }
40 break;
41 default:{
42 printf("Default case in do_power_substation\n");
43 }
44 break;
45 }
46 }
47
add_a_substation(int x,int y)48 int add_a_substation(int x, int y)
49 { /* add to substationx substationy to list */
50 if (numof_substations >= MAX_NUMOF_SUBSTATIONS)
51 return (0);
52 substationx[numof_substations] = x;
53 substationy[numof_substations] = y;
54 numof_substations++;
55 return (1);
56 }
57
remove_a_substation(int x,int y)58 void remove_a_substation(int x, int y)
59 {
60 int q;
61 for (q = 0; q < numof_substations; q++)
62 if (substationx[q] == x && substationy[q] == y)
63 break;
64 for (; q < numof_substations; q++) {
65 substationx[q] = substationx[q + 1];
66 substationy[q] = substationy[q + 1];
67 }
68 numof_substations--;
69 }
70
shuffle_substations(void)71 void shuffle_substations(void)
72 {
73 int q, x, r, m;
74 m = (numof_substations / 2) + 1;
75 for (x = 0; x < m; x++) {
76 r = rand() % numof_substations;
77 if (r == x)
78 continue;
79 q = substationx[x];
80 substationx[x] = substationx[r];
81 substationx[r] = q;
82 q = substationy[x];
83 substationy[x] = substationy[r];
84 substationy[r] = q;
85 }
86 }
87
mps_substation(int x,int y)88 void mps_substation(int x, int y)
89 {
90 int i = 0;
91 char s[12];
92
93 mps_store_title(i++, _("Substation"));
94 i++;
95
96 format_power(s, sizeof(s), MP_INFO(x, y).int_4);
97 mps_store_title(i++, _("Local Demand"));
98 mps_store_title(i++, s);
99 i++;
100
101 mps_store_title(i++, _("Grid Status"));
102
103 format_power(s, sizeof(s), grid[MP_INFO(x, y).int_6]->max_power);
104 mps_store_ss(i++, _("T. Cap."), s);
105
106 format_power(s, sizeof(s), grid[MP_INFO(x, y).int_6]->avail_power);
107 mps_store_ss(i++, _("A. Cap."), s);
108
109 format_power(s, sizeof(s), grid[MP_INFO(x, y).int_6]->demand);
110 mps_store_ss(i++, _("Demand"), s);
111 i++;
112
113 mps_store_sd(i++, _("Grid ID"), MP_INFO(x, y).int_6);
114
115 }
116