forked from hyperyoda/netrek-client-brmh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.c
240 lines (213 loc) · 4.16 KB
/
interface.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
* interface.c
*
* This file will include all the interfaces between the input routines and the
* daemon. They should be useful for writing robots and the like
*/
#include "copyright.h"
#include <stdio.h>
#include <math.h>
#include <sys/types.h>
#include <sys/time.h>
#ifndef sgi
#include <sys/timeb.h>
#endif
#include <signal.h>
#include "netrek.h"
void
set_speed(speed)
int speed;
{
sendSpeedReq(speed);
}
void
set_course(dir)
unsigned char dir;
{
sendDirReq(dir);
}
void
shield_up()
{
if (!(me->p_flags & PFSHIELD)) {
sendShieldReq(1);
}
}
void
shield_down()
{
if (me->p_flags & PFSHIELD) {
sendShieldReq(0);
}
}
void
shield_tog()
{
if (me->p_flags & PFSHIELD) {
sendShieldReq(0);
} else {
sendShieldReq(1);
}
}
void
bomb_planet()
{
if (!(me->p_flags & PFBOMB)) {
sendBombReq(1);
}
}
void
beam_up()
{
if (!(me->p_flags & PFBEAMUP)) {
sendBeamReq(1); /* 1 means up... */
}
}
void
beam_down()
{
if (!(me->p_flags & PFBEAMDOWN)) {
sendBeamReq(2); /* 2 means down... */
}
}
void
repair()
{
if (!(me->p_flags & PFREPAIR)) {
sendRepairReq(1);
}
}
void
repair_off()
{
if (me->p_flags & PFREPAIR) {
sendRepairReq(0);
}
}
void
repeat_message()
{
if (++lastm == MAXMESSAGE)
lastm = 0;
}
void
cloak()
{
if (me->p_flags & PFCLOAK) {
sendCloakReq(0);
} else {
sendCloakReq(1);
}
}
void
cloak_on()
{
if (!(me->p_flags & PFCLOAK)) {
sendCloakReq(1);
}
}
void
cloak_off()
{
if (me->p_flags & PFCLOAK) {
sendCloakReq(0);
}
}
int
mstime()
{
static
struct timeval tv_base;
struct timeval tv;
if (!tv_base.tv_sec) {
gettimeofday(&tv_base, NULL);
return 0;
}
gettimeofday(&tv, NULL);
return (tv.tv_sec - tv_base.tv_sec) * 1000 +
(tv.tv_usec - tv_base.tv_usec) / 1000;
}
int
msetime()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec - 732737182) * 1000 + tv.tv_usec / 1000;
}
#ifdef nodefGALAXY_BORG_FEATURES/* borg alert! */
/* robot features */
unsigned char
our_calc(x, y)
int x, y;
{
return (atan2((double) (x), (double) (y)) / 3.14159 * 128.);
}
void
plasma_phaser(pt)
register struct plasmatorp *pt;
{
int myphrange;
int x, y;
x = (pt->pt_x - me->p_x);
y = (me->p_y - pt->pt_y);
myphrange = PHASEDIST * me->p_ship.s_phaserdamage / 100;
if (pt->pt_status != PTMOVE)
return;
if (!(pt->pt_war & me->p_team) && !(me->p_hostile & pt->pt_team))
return;
if (abs(pt->pt_x - me->p_x) > myphrange)
return;
if (abs(pt->pt_y - me->p_y) > myphrange)
return;
if (hypot((float) pt->pt_x - me->p_x, (float) pt->pt_y - me->p_y) >
myphrange)
return;
if (!(me->p_flags & PFCLOAK) && !(me->p_flags & PFREPAIR)) {
warning(" --- Firing auto-plasma phaser --- ");
sendPhaserReq(our_calc(x, y));
}
}
void
get_enemy(data)
W_Event *data;
{
int myphrange;
register int i;
register struct player *j;
int g_x, g_y;
double dist, closedist;
unsigned char course;
closedist = GWIDTH;
myphrange = PHASEDIST * me->p_ship.s_phaserdamage / 100;
if (data->Window == mapw) {
g_x = data->x * (GWIDTH / WINSIDE);
g_y = data->y * (GWIDTH / WINSIDE);
} else {
g_x = me->p_x + ((data->x - WINSIDE / 2) * SCALE);
g_y = me->p_y + ((data->y - WINSIDE / 2) * SCALE);
}
for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
if ((j->p_status != PALIVE) || (j == me))
continue;
if (!(j->p_swar & me->p_team) && !(me->p_hostile & j->p_team))
continue;
if (abs(j->p_x - me->p_x) > myphrange)
continue;
if (abs(j->p_y - me->p_y) > myphrange)
continue;
dist = hypot((double) (g_x - j->p_x), (double) (g_y - j->p_y));
if (dist > myphrange)
continue;
if (dist < closedist) {
data->x = j->p_x;
data->y = j->p_y;
closedist = dist;
}
}
if (closedist == GWIDTH)
course = getcourse(data->Window, data->x, data->y);
else
course = our_calc((data->x - me->p_x), (me->p_y - data->y));
sendPhaserReq(course);
}
#endif