annotate interface.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1 /* $Id: interface.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
2
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
3 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
4 * interface.c
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
5 *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
6 * This file will include all the interfaces between the input routines
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
7 * and the daemon. They should be useful for writing robots and the
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
8 * like
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
9 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
10 #include "copyright.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
11
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
12 #include <stdio.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
13 #include <math.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
14 #include <sys/types.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
15 #include <sys/time.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
16 #ifndef sgi
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
17 #include <sys/timeb.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
18 #endif /* sgi */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
19 #include <signal.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
20 #include "Wlib.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
21 #include "defs.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
22 #include "struct.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
23 #include "data.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
24 #include "packets.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
25 #include "proto.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
26
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
27 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
28 set_speed(speed)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
29 int speed;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
30 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
31 /* don't repeat useless commands [BDyess] */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
32 if (me->p_desspeed != speed || me->p_speed != speed)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
33 sendSpeedReq(speed);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
34 me->p_desspeed = speed;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
35 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
36
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
37 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
38 set_course(dir)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
39 unsigned int dir;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
40 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
41 /* don't repeat commands [BDyess] */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
42 if (me->p_desdir != dir || me->p_dir != dir)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
43 sendDirReq(dir);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
44 me->p_desdir = dir;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
45 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
46
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
47 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
48 shield_up()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
49 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
50 if (!(me->p_flags & PFSHIELD)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
51 sendShieldReq(1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
52 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
53 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
54
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
55 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
56 shield_down()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
57 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
58 if (me->p_flags & PFSHIELD) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
59 sendShieldReq(0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
60 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
61 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
62
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
63 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
64 shield_tog()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
65 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
66 if (me->p_flags & PFSHIELD) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
67 sendShieldReq(0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
68 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
69 sendShieldReq(1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
70 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
71 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
72
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
73 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
74 bomb_planet()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
75 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
76 if (!(me->p_flags & PFBOMB)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
77 sendBombReq(1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
78 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
79 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
80
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
81 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
82 beam_up()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
83 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
84 if (!(me->p_flags & PFBEAMUP)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
85 sendBeamReq(1); /* 1 means up... */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
86 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
87 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
88
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
89 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
90 beam_down()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
91 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
92 if (!(me->p_flags & PFBEAMDOWN)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
93 sendBeamReq(2); /* 2 means down... */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
94 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
95 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
96
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
97 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
98 cloak()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
99 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
100 if (me->p_flags & PFCLOAK) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
101 sendCloakReq(0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
102 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
103 sendCloakReq(1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
104 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
105 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
106
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
107 int
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
108 mtime()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
109 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
110 #if 0
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
111 struct timeb tm;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
112
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
113 ftime(&tm);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
114 /* mask off 16 high bits and add in milliseconds */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
115 return (tm.time & 0x0000ffff) * 1000 + tm.millitm;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
116 #else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
117 struct timeval tv;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
118
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
119 gettimeofday(&tv, (struct timezone *) 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
120 return (tv.tv_sec & 0x0ffff) * 1000 + tv.tv_usec / 1000;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
121 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
122 }