annotate macros.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: macros.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 /* here's pretty much all the macro code. */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
4 /* This bears little resemblance to the */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
5 /* BRM code, i.e. it's somewhat organized :)*/
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
6 /* Bill Dyess 10/05/93 [BDyess]*/
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
7
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
8 #ifdef MACROS
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
9 #include"copyright.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
10 #include<stdio.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
11 #if !defined(SVR4) && !defined(sparc)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
12 #include<strings.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
13 #else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
14 #include<string.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
15 #endif /* !SVR4 && !sparc */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
16 #include<ctype.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
17 #include<fcntl.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
18 #include<sys/types.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
19 #include"Wlib.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
20 #include"data.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"gameconf.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
24 #include"proto.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
25
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
26 #define MAXMACRO 4096
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
27 #if defined(__STDC__) || defined(RS6K) || defined(sgi)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
28 typedef signed char s_char;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
29 #else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
30 typedef char s_char;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
31 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
32
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
33 /* prototypes */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
34 void doMacro2 P((struct macro * m, W_Event * data));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
35 void handle_dollar P((char **locpntr, char **destpntr, W_Event * data));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
36 void handle_special P((char **locpntr, char **destpntr, W_Event * data));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
37 char *strtoupper P((char *buf));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
38 char *strtolower P((char *buf));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
39 void handle_test P((char **locpntr, char **destpntr, W_Event * data));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
40 void handle_conditional P((char **locpntr, char **destpntr, W_Event * data));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
41 void getTestString P((char *buf, char **locpntr, char **destpntr, W_Event * data));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
42 void getConditionalString P((char **locpntr, char **destpntr, W_Event * data));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
43 void ignoreConditionalString P((char **locpntr));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
44
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
45 int abortflag = 0;
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 initMacros()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
49 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
50 struct stringlist *s;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
51 char *loc;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
52 unsigned char ch;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
53 struct macro *m;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
54 int i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
55 struct dmacro_list *dm;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
56 struct dmacro_list *dm_def;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
57 int notdone;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
58 unsigned char c;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
59 char *str;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
60
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
61 /* initialize macro lookup tables */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
62 bzero(macrotable, sizeof(struct macro *) * 256);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
63
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
64 #ifdef RC_DISTRESS
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
65 /* sizeof doesn't work if it isn't in the same source file, shoot me */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
66 MCOPY(dist_defaults, dist_prefered, sizedist);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
67 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
68
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
69 for (s = defaults; s; s = s->next) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
70 #ifdef RC_DISTRESS
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
71 if (strncmpi(s->string, "dist.", 5) == 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
72 str = (s->string) + 5;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
73 if (*str == '^') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
74 str++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
75 if (*str == '^')
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
76 c = '^';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
77 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
78 c = *str + 128;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
79 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
80 c = *str;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
81 str++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
82 if (*str != '.') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
83 str = (s->string) + 4;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
84 c = '\0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
85 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
86 str++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
87
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
88 notdone = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
89 for (dm = &dist_prefered[take], dm_def = &dist_defaults[take], i = take;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
90 dm->name && notdone; dm++, dm_def++, i++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
91 if (strcmpi(str, dm->name) == 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
92 dm->macro = strdup(s->value);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
93 if (c) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
94 if (!macrotable[c]) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
95 macrotable[c] = (struct macro *) malloc(sizeof(struct macro));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
96 bzero(macrotable[c], sizeof(struct macro));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
97 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
98 macrotable[c]->flags |= MACRCD;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
99 macrotable[c]->to = i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
100 /* printf("dist.%c.%s: %s\n",c,dm->name,dm->macro);*/
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
101 dm->c = c;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
102 dm_def->c = c;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
103 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
104 notdone = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
105 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
106 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
107 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
108 #endif /* RC_DISTRESS */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
109 #ifdef BEEPLITE
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
110
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
111 else if (strncmpi(s->string, "lite.", 5) == 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
112 int offset = 5;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
113 char **lt;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
114
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
115 if (s->string[6] == '.')
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
116 offset = 7;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
117
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
118 notdone = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
119
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
120 for (lt = &distlite[take], dm = &dist_prefered[take];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
121 dm->name && notdone; dm++, lt++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
122 if (strcmpi(s->string + offset, dm->name) == 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
123 *lt = strdup(s->value);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
124 /* printf("lite.%s: %s\n",dm->name,*lt);*/
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
125
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
126 notdone = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
127 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
128 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
129 if (notdone)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
130 fprintf(stderr, "Unknown lite %s\n", s->string + offset);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
131 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
132 #endif /* BEEPLITE */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
133 if (!strncmpi("mac", s->string, 3)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
134 if (s->string[3] == '.')
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
135 loc = s->string + 4;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
136 else if (strncmpi("ro.", s->string + 3, 3))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
137 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
138 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
139 loc = s->string + 6;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
140 if (*loc == '^') { /* possible control char */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
141 loc++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
142 if (*loc == '^' && *loc)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
143 ch = '^';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
144 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
145 ch = *loc + 128;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
146 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
147 ch = *loc;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
148 loc++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
149 if (!macrotable[ch]) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
150 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
151 make sure it doesn't already exist. I've allowed people
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
152 to have singlemacro: before the macro.*.* statements, so
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
153 it is possible
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
154 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
155 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
156 modified to allow multline macros by creating a linked
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
157 list of macro structures. -JR
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
158 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
159 if (ch == '?') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
160 printf("Can't use '?' as a macro. It is reserved for the macro window. Ignoring.\n");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
161 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
162 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
163 macrotable[ch] = m = (struct macro *) malloc(sizeof(struct macro));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
164 bzero(m, sizeof(struct macro));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
165 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
166 #ifdef RC_DISTRESS
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
167 if (macrotable[ch]->flags & MACRCD) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
168 m = macrotable[ch];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
169 m->flags &= ~(MACRCD); /* in case singleMacro was
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
170 set */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
171 m->next = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
172 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
173 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
174 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
175 m = (struct macro *) malloc(sizeof(struct macro));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
176 m->next = macrotable[ch];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
177 macrotable[ch] = m;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
178 m->next->flags |= MACMULTI;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
179 m->flags = m->next->flags;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
180 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
181 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
182 if (*(loc++) != '.')
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
183 m->to = -2; /* no destination given */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
184 else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
185 ch = *loc;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
186 if (ch == '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
187 m->specialto = toupper(*(loc + 1));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
188 m->to = -1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
189 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
190 m->to = ch;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
191 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
192 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
193 m->string = strdup(s->value);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
194 } else if (!strncmpi("singlemacro", s->string, 11)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
195 loc = s->value;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
196 while (*loc) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
197 ch = *(loc++);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
198 if (ch == '^') {/* for control chars */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
199 if (*loc != '^' && *loc)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
200 ch = *loc + 128;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
201 loc++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
202 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
203 if (!macrotable[ch]) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
204 m = macrotable[ch] = (struct macro *) malloc(sizeof(struct macro));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
205 bzero(m, sizeof(struct macro));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
206 m->flags = MACSINGLE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
207 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
208 for (m = macrotable[ch]; m; m = m->next)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
209 m->flags |= MACSINGLE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
210 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
211 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
212 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
213 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
214 for (i = 0; i < 256; i++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
215 /* eliminate any macros that have (null) macro strings */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
216 if (macrotable[i] && !(macrotable[i]->flags & MACRCD)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
217 struct macro *tmp, **scan;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
218
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
219 scan=&macrotable[i];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
220 while (*scan) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
221 if ( (*scan)->string ) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
222 scan = &(*scan)->next;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
223 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
224 tmp = (*scan);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
225 *scan = tmp->next;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
226 free(tmp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
227 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
228 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
229 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
230 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
231 #ifdef RC_DISTRESS
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
232 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
233 make macro entries for the default RCD keys, if those keys don't have
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
234 macros defined
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
235 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
236 for (dm = &dist_prefered[take], i = take; dm->name; dm++, i++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
237 if (!macrotable[dm->c]) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
238 macrotable[dm->c] = (struct macro *) malloc(sizeof(struct macro));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
239 bzero(macrotable[dm->c], sizeof(struct macro));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
240 macrotable[dm->c]->flags = MACRCD;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
241 macrotable[dm->c]->to = i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
242 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
243 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
244 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
245 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
246
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
247 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
248 doMacro(data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
249 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
250 /* takes a key as input and creates a string that is then sent to smessage*/
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
251 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
252 static struct macro *m;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
253 int key = data->key;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
254
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
255 if (key == '?') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
256 showMacroWin();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
257 macroState = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
258 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
259 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
260 if (macroState != 2)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
261 m = macrotable[key];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
262 if (!m) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
263 W_Beep();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
264 warning("No such macro");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
265 macroState = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
266 return; /* no macro */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
267 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
268 #ifdef RC_DISTRESS
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
269 if (m->flags & MACRCD) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
270 rcd(m->to, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
271 macroState = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
272 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
273 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
274 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
275 while (m) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
276 if (macroState == 2) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
277 m->to = key;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
278 doMacro2(m, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
279 m->to = -2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
280 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
281 doMacro2(m, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
282 if (macroState == 2)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
283 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
284 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
285 m = m->next;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
286 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
287 macroState = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
288 warning(" ");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
289 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
290
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
291 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
292 doMacro2(m, data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
293 struct macro *m;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
294 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
295 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
296 int group = -1, recip = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
297 char buf[MAXMACRO], sourcebuf[MAXMACRO];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
298 char *loc, *dest;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
299 struct obtype *target;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
300
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
301 /* first figure out who I'm going to send it to */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
302 if ((s_char)m->to == -1) { /* special recipient */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
303 switch (m->specialto) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
304 case 'I': /* send a message to myself */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
305 case 'C':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
306 group = MINDIV;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
307 recip = me->p_no;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
308 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
309 case 'U': /* send message to player nearest mouse */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
310 case 'P':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
311 group = MINDIV;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
312 target = gettarget(data->Window, data->x, data->y, TARG_PLAYER);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
313 recip = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
314 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
315 case 'T': /* send message to team of the player nearest
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
316 mouse */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
317 case 'Z':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
318 group = MTEAM;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
319 target = gettarget(data->Window, data->x, data->y, TARG_PLAYER);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
320 recip = idx_to_mask(players[target->o_num].p_teami);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
321 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
322 case 'G': /* send message to nearest friendly player to
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
323 my ship */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
324 group = MINDIV;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
325 target = gettarget((W_Window) 0, me->p_x, me->p_y,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
326 TARG_PLAYER | TARG_FRIENDLY);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
327 recip = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
328 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
329 case 'H': /* send message to nearest enemy player to my
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
330 ship */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
331 group = MINDIV;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
332 target = gettarget((W_Window) 0, me->p_x, me->p_y,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
333 TARG_PLAYER | TARG_ENEMY);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
334 recip = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
335 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
336 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
337 warning("Bad macro - incorrect 'to' field");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
338 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
339 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
340 } else if ((s_char)m->to == -2) { /* get recipient not provided, so change
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
341 state to get one */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
342 macroState = 2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
343 warning("Send macro to who?");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
344 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
345 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
346 recip = m->to;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
347 /* now parse the macro itself. */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
348 strcpy(sourcebuf, m->string);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
349 loc = sourcebuf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
350 dest = buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
351 while (*loc) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
352 if (*loc == '$') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
353 loc++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
354 handle_dollar(&loc, &dest, data); /* handle the special escape */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
355 } else if (*loc == '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
356 loc++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
357 if (*loc == '*')
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
358 return; /* %* means exit macro NOW */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
359 handle_special(&loc, &dest, data); /* handle the special escape */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
360 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
361 *(dest++) = *(loc++);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
362 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
363 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
364 *dest = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
365 if (buf[0] == 0 || abortflag) { /* abortflag means somewhere there
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
366 was a %* */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
367 abortflag = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
368 macroState = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
369 return; /* null message. If you *really* want to
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
370 print a null message, use <space> */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
371 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
372 if (group == -1)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
373 group = getgroup(recip, &recip);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
374 if (group <= 0)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
375 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
376 if ((m->flags & MACMULTI) && (F_multiline_enabled || paradise))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
377 group |= MMACRO;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
378 pmessage(buf, recip, group);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
379 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
380
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
381 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
382 handle_special(locpntr, destpntr, data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
383 char **locpntr, **destpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
384 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
385 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
386 char ch = **locpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
387 char *buf = *destpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
388 struct obtype *target;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
389 struct macro *m;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
390 int targettype = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
391 struct id *id;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
392 /* for pingstats */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
393 #if 0
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
394 extern int ping_iloss_sc; /* inc % loss 0--100, server to client */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
395 extern int ping_iloss_cs; /* inc % loss 0--100, client to server */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
396 #endif /* 0 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
397 extern int ping_tloss_sc; /* total % loss 0--100, server to client */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
398 extern int ping_tloss_cs; /* total % loss 0--100, client to server */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
399 #if 0
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
400 extern int ping_lag; /* delay in ms of last ping */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
401 #endif /* 0 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
402 extern int ping_av; /* average rt */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
403 extern int ping_sd; /* standard deviation */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
404
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
405 switch (ch) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
406 case 'a': /* armies carried by sender */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
407 sprintf(buf, "%d", me->p_armies);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
408 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
409 case 'd': /* sender damage percentage */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
410 sprintf(buf, "%d", 100 * me->p_damage / me->p_ship->s_maxdamage);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
411 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
412 case 's': /* sender shield percentage */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
413 sprintf(buf, "%d", 100 * me->p_shield / me->p_ship->s_maxshield);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
414 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
415 case 'f': /* sender fuel percentage */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
416 sprintf(buf, "%d", 100 * me->p_fuel / me->p_ship->s_maxfuel);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
417 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
418 case 'w': /* sender wtemp percentage */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
419 sprintf(buf, "%d", 100 * me->p_wtemp / me->p_ship->s_maxwpntemp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
420 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
421 case 'e': /* sender etemp percentage */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
422 sprintf(buf, "%d", 100 * me->p_etemp / me->p_ship->s_maxegntemp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
423 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
424 case 'r': /* team id character of target player */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
425 target = gettarget(data->Window, data->x, data->y, TARG_PLAYER);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
426 buf[0] = teaminfo[players[target->o_num].p_teami].letter;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
427 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
428 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
429 case 't': /* team id character of target planet */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
430 target = gettarget(data->Window, data->x, data->y, TARG_PLANET);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
431 buf[0] = teaminfo[mask_to_idx(planets[target->o_num].pl_owner)].letter;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
432 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
433 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
434 case 'p': /* id character of target player */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
435 targettype = TARG_PLAYER;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
436 case 'g': /* id character of target friendly player */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
437 if (!targettype)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
438 targettype = TARG_PLAYER | TARG_FRIENDLY;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
439 case 'h': /* id char of target enemy player */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
440 if (!targettype)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
441 targettype = TARG_PLAYER | TARG_ENEMY;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
442 id = getTargetID(data->Window, data->x, data->y, targettype);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
443 buf[0] = id->mapstring[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
444 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
445 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
446 case 'P': /* id character of player nearest sender */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
447 id = getTargetID((W_Window) 0, me->p_x, me->p_y, TARG_PLAYER);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
448 buf[0] = id->mapstring[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
449 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
450 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
451 case 'T': /* team id character of sender team */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
452 buf[0] = me->p_mapchars[0];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
453 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
454 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
455 case 'c': /* sender id character */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
456 buf[0] = me->p_mapchars[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
457 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
458 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
459 case 'C': /* 1 if cloaked, 0 if not [BDyess] */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
460 if (me->p_flags & PFCLOAK)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
461 buf[0] = '1';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
462 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
463 buf[0] = '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
464 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
465 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
466 case 'n': /* armies on target planet */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
467 target = gettarget(data->Window, data->x, data->y, TARG_PLANET);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
468 sprintf(buf, "%d", planets[target->o_num].pl_info ?
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
469 planets[target->o_num].pl_armies :
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
470 -1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
471 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
472 case 'E': /* 1 if etemped, 0 if not */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
473 if (me->p_flags & PFENG)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
474 buf[0] = '1';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
475 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
476 buf[0] = '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
477 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
478 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
479 case 'W': /* 1 if wtemped, 0 if not */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
480 if (me->p_flags & PFWEP)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
481 buf[0] = '1';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
482 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
483 buf[0] = '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
484 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
485 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
486 case 'S': /* sender two character ship type */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
487 strncpy(buf, me->p_ship->s_desig, 2);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
488 buf[2] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
489 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
490 case 'G': /* id char of friendly player nearest sender */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
491 targettype = TARG_FRIENDLY;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
492 case 'H': /* id char of enemy player nearest sender */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
493 if (!targettype)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
494 targettype = TARG_ENEMY;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
495 id = getTargetID((W_Window) 0, me->p_x, me->p_y,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
496 TARG_PLAYER | targettype);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
497 buf[0] = id->mapstring[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
498 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
499 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
500 case 'l': /* three character name of target planet */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
501 case 'L':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
502 id = getTargetID(data->Window, data->x, data->y, TARG_PLANET);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
503 strcpy(buf, id->mapstring);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
504 buf[0] = tolower(buf[0]);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
505 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
506 case 'i': /* sender full player name (16 character max) */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
507 case 'I':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
508 strncpy(buf, me->p_name, 16);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
509 buf[16] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
510 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
511 case 'u': /* full name of target player (16 character
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
512 max) */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
513 case 'U':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
514 id = getTargetID(data->Window, data->x, data->y, TARG_PLAYER);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
515 strncpy(buf, id->name, 16);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
516 buf[16] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
517 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
518 case 'z': /* 3 letter team id of target planet */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
519 case 'Z':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
520 id = getTargetID(data->Window, data->x, data->y, TARG_PLANET);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
521 strcpy(buf, teaminfo[id->team].shortname);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
522 strtolower(buf);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
523 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
524 case 'b': /* nearest planet to sender */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
525 case 'B':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
526 id = getTargetID((W_Window) 0, me->p_x, me->p_y, TARG_PLANET);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
527 strcpy(buf, id->mapstring);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
528 buf[0] = tolower(buf[0]);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
529 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
530 case 'v': /* average ping round trip time */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
531 sprintf(buf, "%d", ping_av);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
532 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
533 case 'V': /* ping stdev */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
534 sprintf(buf, "%d", ping_sd);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
535 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
536 case 'y': /* packet loss */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
537 sprintf(buf, "%d", (2 * ping_tloss_sc + ping_tloss_cs) / 3);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
538 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
539 case 'm': /* last message */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
540 case 'M':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
541 strcpy(buf, lastMessage);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
542 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
543 case 'o': /* insert three letter team name */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
544 case 'O':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
545 strcpy(buf, teaminfo[me->p_teami].shortname);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
546 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
547 case ' ': /* nothing. This is so you can start a macro
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
548 with spaces */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
549 buf[0] = ' ';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
550 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
551 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
552 case '%': /* insert % */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
553 buf[0] = '%';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
554 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
555 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
556 case '?': /* start test */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
557 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
558 handle_test(locpntr, destpntr, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
559 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
560 case '{': /* conditional */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
561 handle_conditional(locpntr, destpntr, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
562 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
563 case '*': /* abort! */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
564 abortflag = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
565 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
566 case '2': /* is paradise? sorry, ran out of good
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
567 letters. '2' means, 'is Netrek II?'. */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
568 buf[0] = paradise + '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
569 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
570 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
571 case '_': /* call another macro. Added 1/24/94 [BDyess] */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
572 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
573 if (**locpntr == '^') { /* control char */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
574 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
575 m = macrotable[**locpntr + (**locpntr == '^') ? 0 : 128];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
576 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
577 m = macrotable[(int) **locpntr];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
578 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
579 if (m) { /* does the macro exist? */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
580 char temp[MAXMACRO];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
581 strcpy(temp, m->string);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
582 strcat(temp, *locpntr + 1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
583 strcpy(*locpntr + 1, temp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
584 } else { /* somebody screwed up */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
585 printf("Error: called macro ");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
586 if (&m - macrotable >= 128)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
587 putchar('^');
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
588 printf("%c doesn't exist.\n", **locpntr);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
589 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
590 buf[0] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
591 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
592 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
593 sprintf(buf, "Unknown %% escape: %%%c", ch);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
594 warning(buf);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
595 buf[0] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
596 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
597 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
598 if (isupper(ch))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
599 strtoupper(buf);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
600 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
601 while (**destpntr)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
602 (*destpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
603 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
604 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
605
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
606 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
607 handle_test(locpntr, destpntr, data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
608 char **locpntr, **destpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
609 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
610 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
611 char l[MAXMACRO], r[MAXMACRO], condition = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
612 short trueflag = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
613
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
614 getTestString(l, locpntr, destpntr, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
615 if (**locpntr != '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
616 condition = *((*locpntr)++);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
617 getTestString(r, locpntr, destpntr, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
618 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
619 switch (condition) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
620 case '=':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
621 if (!strcmp(l, r))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
622 trueflag = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
623 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
624 case '>':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
625 if (atoi(l) > atoi(r))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
626 trueflag = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
627 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
628 case '<':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
629 if (atoi(l) < atoi(r))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
630 trueflag = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
631 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
632 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
633 if (atoi(l))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
634 trueflag = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
635 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
636 **destpntr = '0' + trueflag;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
637 *(*destpntr + 1) = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
638 (*destpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
639 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
640 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
641
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
642 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
643 handle_conditional(locpntr, destpntr, data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
644 char **locpntr, **destpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
645 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
646 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
647 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
648 **destpntr = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
649 (*destpntr)--;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
650 if (**destpntr == '0') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
651 ignoreConditionalString(locpntr);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
652 getConditionalString(locpntr, destpntr, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
653 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
654 getConditionalString(locpntr, destpntr, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
655 ignoreConditionalString(locpntr);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
656 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
657 (*locpntr) += 2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
658 while (**destpntr)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
659 (*destpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
660 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
661 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
662
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
663 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
664 ignoreConditionalString(locpntr)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
665 char **locpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
666 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
667 int depth = 0, breakflag = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
668
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
669 while (**locpntr) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
670 if (**locpntr == '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
671 switch (*(*locpntr + 1)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
672 case '!':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
673 if (!depth)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
674 breakflag = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
675 (*locpntr) += 2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
676 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
677 case '}':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
678 if (depth) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
679 depth--;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
680 (*locpntr) += 2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
681 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
682 breakflag = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
683 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
684 case '{':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
685 depth++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
686 (*locpntr) += 2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
687 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
688 case '*':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
689 abortflag = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
690 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
691 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
692 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
693 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
694 if (breakflag)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
695 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
696 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
697 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
698 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
699 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
700
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
701 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
702 getConditionalString(locpntr, destpntr, data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
703 char **locpntr, **destpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
704 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
705 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
706 char *dest = *destpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
707
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
708 while (**locpntr) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
709 if (**locpntr != '%' && **locpntr != '$' && **locpntr)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
710 *(dest++) = *((*locpntr)++);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
711 else if (*(*locpntr + 1) == '!') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
712 (*locpntr) += 2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
713 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
714 } else if (*(*locpntr + 1) == '}')
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
715 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
716 else if (**locpntr == '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
717 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
718 handle_special(locpntr, &dest, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
719 while (*(dest++));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
720 dest--;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
721 } else { /* **locpntr must equal '$' */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
722 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
723 handle_dollar(locpntr, &dest, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
724 while (*(dest++));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
725 dest--;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
726 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
727 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
728 *dest = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
729 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
730 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
731
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
732 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
733 getTestString(buf, locpntr, destpntr, data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
734 char *buf, **locpntr, **destpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
735 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
736 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
737 char *dest = buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
738
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
739 if (**locpntr == '%') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
740 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
741 handle_special(locpntr, &buf, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
742 } else if (**locpntr == '$') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
743 (*locpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
744 handle_dollar(locpntr, &buf, data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
745 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
746 while (**locpntr != '%' && **locpntr != '$' && **locpntr != '<' &&
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
747 **locpntr != '>' && **locpntr != '=' &&
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
748 **locpntr)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
749 *(dest++) = *((*locpntr)++);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
750 *dest = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
751 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
752 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
753 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
754
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
755 char *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
756 strtoupper(buf)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
757 char *buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
758 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
759 char *s;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
760 for (s = buf; *s; s++)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
761 *s = toupper(*s);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
762 return buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
763 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
764
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
765 char *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
766 strtolower(buf)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
767 char *buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
768 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
769 char *s;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
770 for (s = buf; *s; s++)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
771 *s = tolower(*s);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
772 return buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
773 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
774
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
775 /**********************************************************************/
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
776
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
777 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
778 start with a $
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
779
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
780 field 1:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
781 (n)earest
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
782 (t)arget
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
783 (s)elf (doesn't have fields 2 and 3)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
784 (_) ego (has no other fields)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
785
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
786 field 2:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
787 (a)ny
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
788 (t)eammate
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
789 (f)riendly
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
790 (h)ostile
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
791
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
792 field 3:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
793 (a)ny
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
794 (u)ser
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
795 (p)lanet (includes asteroids)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
796 (s)tar
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
797 (n)ebula
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
798 (b)lack hole
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
799 (^) non-planet
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
800 (*) any stellar object
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
801
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
802 field 4: (optional) NYI
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
803 (U)ppercase
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
804 (C)apitalize
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
805 (L)owercase
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
806
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
807 field 5:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
808 full (n)ame (Hammor, Thought)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
809 (i)dentifier (e.g. R5, Ka, Can, Sco)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
810 (#) number (0-9a-z for players, %d for planets)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
811 (t)eam name (Romulan)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
812 (s)hort team id (ROM)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
813 (l)etter of team (R)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
814 (a)rmies
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
815 (@) sector
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
816 (A)rable, 0=not arable, 1=arable but not AGRI, 2=AGRI
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
817 (M)etal, 0, 1, 2(repair), or 3(sy)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
818 (D)ilithium, 0, 1 or 2(fuel)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
819
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
820 Any implementation of the paradise $ codes (subset or superset)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
821 must implement and document the $_ code. -- Robert Forsman
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
822 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
823
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
824 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
825 handle_dollar(locpntr, destpntr, data)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
826 char **locpntr, **destpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
827 W_Event *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
828 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
829 char *buf = *destpntr;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
830 struct id *target;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
831 char ch = *((*locpntr)++);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
832 W_Window w;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
833 int x, y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
834 int flags;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
835 int capitalize = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
836
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
837 buf[0] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
838
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
839 if (ch == '_') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
840 strcpy(buf, "Paradise netrek $ codes are orthogonal and make sense.");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
841 while (**destpntr)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
842 (*destpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
843 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
844 } if (ch == 's') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
845 target = getTargetID((W_Window) 0, me->p_x, me->p_y, TARG_PLAYER | TARG_SELF);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
846 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
847 switch (tolower(ch)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
848 case 'n':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
849 w = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
850 x = me->p_x;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
851 y = me->p_y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
852 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
853 case 't':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
854 w = data->Window;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
855 x = data->x;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
856 y = data->y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
857 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
858 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
859 printf("Invalid $ code field 1 : `%c'\n", ch);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
860 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
861 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
862
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
863 ch = *((*locpntr)++);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
864 switch (tolower(ch)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
865 case 'a':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
866 flags = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
867 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
868 case 't':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
869 flags = TARG_TEAM;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
870 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
871 case 'f':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
872 flags = TARG_FRIENDLY;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
873 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
874 case 'h':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
875 flags = TARG_ENEMY;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
876 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
877 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
878 printf("Invalid $ code field 2 : `%c'\n", ch);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
879 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
880 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
881
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
882 ch = *((*locpntr)++);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
883 switch (tolower(ch)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
884 case 'a':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
885 flags |= TARG_PLAYER | TARG_ASTRAL;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
886 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
887 case 'u':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
888 flags |= TARG_PLAYER;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
889 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
890 case 'p':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
891 flags |= TARG_PLANET;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
892 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
893 case 's':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
894 flags |= TARG_STAR;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
895 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
896 case 'n':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
897 flags |= TARG_NEBULA;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
898 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
899 case 'b':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
900 flags |= TARG_BLACKHOLE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
901 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
902 case '^':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
903 flags |= (TARG_ASTRAL & ~TARG_PLANET);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
904 /* fall through */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
905 case '*':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
906 flags |= TARG_PLANET;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
907 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
908 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
909 printf("Invalid $ code field 3 : `%c'\n", ch);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
910 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
911 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
912
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
913 target = getTargetID(w, x, y, flags);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
914 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
915
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
916 ch = tolower(*((*locpntr)++));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
917 if (ch == 'l')
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
918 capitalize = -1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
919 else if (ch == 'c')
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
920 capitalize = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
921 else if (ch == 'u')
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
922 capitalize = 2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
923 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
924 (*locpntr)--; /* oops, back up and try again */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
925
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
926 ch = *((*locpntr)++);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
927
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
928 switch (ch) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
929 case 'n':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
930 strcpy(buf, target->name);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
931 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
932 case 'i':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
933 /* if (target->type == PLANETTYPE) {*/
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
934 strcpy(buf, target->mapstring);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
935 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
936 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
937 buf[0] = target->mapstring[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
938 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
939 }*/
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
940 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
941 case '#':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
942 if (target->type == PLANETTYPE) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
943 sprintf(buf, "%d", target->number);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
944 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
945 buf[0] = target->mapstring[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
946 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
947 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
948 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
949 case 't':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
950 strcpy(buf, teaminfo[target->team].name);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
951 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
952 case 's':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
953 strcpy(buf, teaminfo[target->team].shortname);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
954 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
955 case 'l':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
956 buf[0] = teaminfo[target->team].letter;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
957 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
958 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
959 case 'a':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
960 sprintf(buf, "%d", (target->type == PLANETTYPE) ?
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
961 planets[target->number].pl_armies :
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
962 players[target->number].p_armies);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
963 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
964 case '@':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
965 if (!paradise)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
966 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
967 if (target->type == PLANETTYPE) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
968 x = planets[target->number].pl_x;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
969 y = planets[target->number].pl_y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
970 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
971 x = players[target->number].p_x;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
972 y = players[target->number].p_y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
973 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
974 sprintf(buf, "%d-%d", x / GRIDSIZE + 1, y / GRIDSIZE + 1);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
975 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
976 case 'A': /* Arable or AGRI */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
977 buf[0] = '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
978 if (target->type == PLANETTYPE) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
979 if (planets[target->number].pl_flags & PLARABLE)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
980 buf[0] = '1';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
981 if (planets[target->number].pl_flags & PLAGRI)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
982 buf[0] = '2';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
983 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
984 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
985 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
986 case 'M': /* Metal, Repair, or SY */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
987 buf[0] = '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
988 if (target->type == PLANETTYPE) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
989 if (planets[target->number].pl_flags & PLMETAL)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
990 buf[0] = '1';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
991 if (planets[target->number].pl_flags & PLREPAIR)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
992 buf[0] = '2';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
993 if (planets[target->number].pl_flags & PLSHIPYARD)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
994 buf[0] = '3';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
995 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
996 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
997 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
998 case 'D': /* Dilythium or Fuel */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
999 buf[0] = '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1000 if (target->type == PLANETTYPE) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1001 if (planets[target->number].pl_flags & PLDILYTH)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1002 buf[0] = '1';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1003 if (planets[target->number].pl_flags & PLFUEL)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1004 buf[0] = '2';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1005 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1006 buf[1] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1007 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1008 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1009 printf("Invalid $ code field 4 : `%c'\n", ch);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1010 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1011 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1012
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1013 if (capitalize < 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1014 char *s;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1015 for (s = buf; *s; s++)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1016 *s = tolower(*s);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1017 } else if (capitalize > 1) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1018 char *s;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1019 for (s = buf; *s; s++)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1020 *s = toupper(*s);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1021 } else if (capitalize) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1022 char *s;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1023 s = buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1024 *s = toupper(*s);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1025 for (s++; *s; s++)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1026 *s = tolower(*s);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1027 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1028 while (**destpntr)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1029 (*destpntr)++;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1030 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1031 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1032 #endif /* MACROS */