16
int c1, c2; /* computers connected */
17
int x1, y1, x2, y2; /* endpoints of line representing cable */
18
int x, y; /* current location of spark */
19
float fx, fy; /* needed for line drawing */
20
int delay; /* how much time until spark leaves */
21
int active; /* is spark moving and from which end */
25
#define SWAP(x, y) do {int _t; _t = x; x = y; y = _t;} while(0)
28
reverse(Cable *cable) {
29
SWAP(cable->c1, cable->c2);
30
SWAP(cable->x1, cable->x2);
31
SWAP(cable->y1, cable->y2);
35
Cable_setup(Cable **cablep) {
37
Computer *comp1, *comp2;
40
cable = xalloc(sizeof *cable);
42
cable->c1 = RAND(0, Network_num_computers() - 1);
44
cable->c2 = RAND(0, Network_num_computers() - 1);
45
} while (cable->c2 == cable->c1);
48
cable->delay = SPARK_DELAY(Game_level());
50
comp1 = Network_get_computer(cable->c1);
51
comp2 = Network_get_computer(cable->c2);
52
cwidth = Computer_width();
53
cheight = Computer_height();
54
cable->x1 = comp1->x + cwidth/3;
55
cable->x2 = comp2->x + cwidth/3;
56
cable->y1 = comp1->y + cheight/2;
57
cable->y2 = comp2->y + cheight/2;
64
Cable_draw(Cable *cable) {
65
UI_draw_line(cable->x1, cable->y1, cable->x2, cable->y2);
67
int rx = cable->x - Spark_width()/2;
68
int ry = cable->y - Spark_height()/2;
69
Spark_draw(rx, ry, cable->index);
74
Cable_update(Cable *cable) {
75
Computer *comp1, *comp2;
76
comp1 = Network_get_computer(cable->c1);
77
comp2 = Network_get_computer(cable->c2);
80
if ((comp1->os == OS_WINGDOWS) == (comp2->os == OS_WINGDOWS))
82
else if (comp1->os == OS_WINGDOWS || comp2->os == OS_WINGDOWS) {
86
if (comp2->os == OS_WINGDOWS)
89
xdist = cable->x2 - cable->x;
90
ydist = cable->y2 - cable->y;
92
sx = xdist >= 0 ? 1.0 : -1.0;
93
sy = ydist >= 0 ? 1.0 : -1.0;
96
if (xdist == 0 && ydist == 0) {
99
if (comp2->os == OS_OFF)
100
counter = NETWORK_COUNTER_OFF;
102
counter = NETWORK_COUNTER_BASE;
103
Network_inc_counter(counter, -1);
104
Network_inc_counter(NETWORK_COUNTER_WIN,
106
comp2->os = OS_WINGDOWS;
110
else if (MAX(xdist, ydist) < SPARK_SPEED) {
111
cable->x = cable->x2;
112
cable->y = cable->y2;
115
cable->fx+=(xdist*SPARK_SPEED*sx)/(xdist+ydist);
116
cable->fy+=(ydist*SPARK_SPEED*sy)/(xdist+ydist);
117
cable->x = (int)cable->fx;
118
cable->y = (int)cable->fy;
120
cable->index = 1 - cable->index;
124
if ((comp1->os == OS_WINGDOWS) == (comp2->os == OS_WINGDOWS))
126
else if (comp1->os == OS_WINGDOWS || comp2->os == OS_WINGDOWS) {
128
cable->delay = SPARK_DELAY(Game_level());
129
if (comp2->os == OS_WINGDOWS)
131
cable->x = cable->x1;
132
cable->fx = cable->x1;
133
cable->y = cable->y1;
134
cable->fy = cable->y1;
140
Cable_onspark(Cable *cable, int locx, int locy) {
143
return (abs(locx - cable->x) < Spark_width() &&
144
abs(locy - cable->y) < Spark_height());
148
Cable_reset(Cable *cable) {
150
cable->delay = SPARK_DELAY(Game_level());