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