/
helpwin.c
302 lines (277 loc) · 7.26 KB
/
helpwin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
* helpwin.c copyright 1991 ERic mehlhaff Free to use, hack, etc. Just keep
* these credits here. Use of this code may be dangerous to your health
* and/or system. Its use is at your own risk. I assume no responsibility for
* damages, real, potential, or imagined, resulting from the use of it.
*
* $Log: helpwin.c,v $
* Revision 1.2 2000/02/17 05:48:05 ahn
* BRMH 2.3 from David Pinkney <dpinkney@cs.uml.edu>
*
* Revision 1.6 1993/10/05 16:40:38 hadley
* checkin
*
* Revision 1.6 1993/10/05 16:38:08 hadley
* checkin
*
*/
#include <stdio.h>
#include <string.h>
#include "math.h"
#include <signal.h>
#include <sys/types.h>
#ifdef hpux
#include <time.h>
#else /* hpux */
#include <sys/time.h>
#endif /* hpux */
#include "netrek.h"
/*
* this is a set of routines that makes up a multi column help window, * and
* shows just what the keymaps current keymap representation of the * keys
* are. *
*
* fillhelp() handles the filling in if the strings for the help window *
* update_Help_to_Keymap() checks the keymap and sets it up in hte * help
* window. *
*
*
*
* Format for each entry is follows: * first character is the hard-coded
* character representation for the key * in the keymap. Useful for when you
* re-key things. This could confuse * people who do'nt know the keymap
* format. *
*
* the next few spaces are either spaces or keys that also do that *
* function. Note that if you have more than 3 keys set to do the same *
* thing, they will not be displayed. * So, you could, I suppose map
* everything to 'Q' and it would not * show, but that's a pretty bizarre
* situation. *
*
*
*
* Bugs & Comments: * You have to be sure that helpWin is defined to be big
* enough to handle * all the messages. That's pretty much a trial&error
* by-hand thing * at this point *
*
*/
/*
* fills in the help window to note all keys also mapped to the * listed
* functions
*/
void update_Help_to_Keymap();
#define HELPMESSAGES (sizeof(help_message)/ sizeof(char *))
/* this is the number of help messages there are */
char *help_message[] =
{
"0 Set speed",
"1 Set speed",
"2 Set speed",
"3 Set speed",
"4 Set speed",
"5 Set speed",
"6 Set speed",
"7 Set speed",
"8 Set speed",
"9 Set speed",
") speed = 10",
"! speed = 11",
"@ speed = 12",
"% speed = maximum",
"# speed = 1/2 maximum",
#ifdef EM
"< slow speed 1",
"> speed up 1",
#endif /* EM */
"k Set course",
"p Fire phaser",
"t Fire photon torpedo",
"f Fire plasma torpedo",
#ifdef SCAN
"a Use scanning beam",
#endif /* ATM */
"d detonate enemy torps",
"D detonate own torps",
"L List players",
"P List planets",
"S Status graph toggle",
"] Put up shields",
"[ Put down shields",
"u Shield toggle",
"s Shield toggle",
"i Info on player/planet",
"I Extended info on player",
"b Bomb planet",
"z Beam up armies",
"x Beam down armies",
#ifdef EM
"{ Cloak",
"} Uncloak",
#endif
"T Toggle tractor beam",
"y Toggle pressor beam",
"_ Tractor on",
"^ Pressor on",
"$ Tractor/Pressor off",
"R Enter repair mode",
"o Orbit planet or dock to outpost",
"e Docking permission toggle",
"r Refit (change ship type)",
"Q Quit",
"q fast quit (no entry window)",
"? Message window rotate",
"c Cloaking device toggle",
"C Coup a planet",
"l Lock on to player/planet",
"; Lock on starbase/planet",
"h Help window toggle",
"w War declarations window",
"N Planet names toggle",
"V Rotate local planet display",
"B Rotate galactic planet display",
"* Send in practice robot",
"E Send Distress signal",
#ifdef EM
"F Send armies carried report",
#endif /* EM */
"U Show rankings window",
"m Message Window Zoom",
"+ Show UDP options window",
"= Update all",
#ifdef NETSTAT
"/ Map LagMeter",
#endif
#ifdef PING
", Ping stats window",
#endif
#ifdef SHORT_PACKETS
"- Update small",
#endif /* SHORT_PACKETS */
" (space) Unmap special windows",
": Re-Read netrekrc defaults",
"& Re-Read all netrekrc defaults",
#ifdef LOGMESG
"M Toggle message logging",
#endif
#ifdef nodef
"; Toggle planet Bitmaps",
#endif
"| Toggle player list sorting",
"\\ Toggle player list",
#ifdef NBT
"X Enter Macro Mode",
#endif
#if !defined(CONTROL_KEY) && defined(FEATURE)
#ifdef NBT
"X-? Show FEATURES/MACROS/RCD window",
#endif
#endif
#if defined (CONTROL_KEY) && defined (FEATURE)
"^s Show FEATURES/MACROS/RCD window",
#endif
#ifdef RECORD
"` Toggle game recording",
#endif
0
};
#define MAXHELP 40
/* maximum length in characters of key explanation */
void
fillhelp()
{
register int i = 0, row, column;
char helpmessage[MAXHELP];
/* 4 column help window. THis may be changed depending on font size */
for (column = 0; column < 4; column++) {
for (row = 1; row < HELPMESSAGES / 4 + 2; row++) {
if (help_message[i] == 0)
break;
else {
strcpy(helpmessage, help_message[i]);
update_Help_to_Keymap(helpmessage);
W_WriteText(helpWin, MAXHELP * column, row, textColor,
helpmessage, strlen(helpmessage), W_RegularFont);
i++;
}
}
if (help_message[i] == 0)
break;
}
}
/*
* this takes the help messages and puts in the keymap, so the player can see
* just what does what!
*
* ordinary format: "U Show rankings window", translatedd here to
* "[ sE Computer options window",
*/
void
update_Help_to_Keymap(helpmessage)
char helpmessage[];
{
int i, num_mapped = 0;
unsigned char key;
#ifdef CONTROL_KEY
if (helpmessage[0] == '^' && helpmessage[1] != ' ')
key = helpmessage[1] + 96;
else
key = helpmessage[0];
#else
key = helpmessage[0];
#endif
#ifdef CONTROL_KEY
if (key < 32){
return;
}
#else
if (key < 32 || key > 126)
{
return;
}
#endif
if (strlen(helpmessage) < 6) {
return;
}
/*
* search the keymap to see if one of its entries matches the key * for
* this helpmessage
*/
for (i = 0; i < MAXKEY; i++) {
if (mykeymap[i] != key)
continue;
if (i + 32 == key)
continue; /* it's already there! don't add it! */
/* we've found a key mapped to key! */
/* the key is i+32 */
num_mapped++;
if (num_mapped > 3)
continue; /* we've found too many! */
/* put the key in the string */
#ifdef CONTROL_KEY
if (i > 127) {
helpmessage[1 + num_mapped++] = '^';
helpmessage[1 + num_mapped] = (char) i + 32 - 96;
}
else
helpmessage[1 + num_mapped] = i + 32;
#else
helpmessage[1 + num_mapped] = i + 32;
#endif
/* handle mappings for weird keys, i.e. space */
if (i + 32 == ' ')
helpmessage[1 + num_mapped] = '_';
}
/* clear spaces if any area available */
switch (num_mapped) {
case 0:
helpmessage[2] = ' ';
case 1:
helpmessage[3] = ' ';
case 2:
helpmessage[4] = ' ';
case 3:
default:
helpmessage[5] = ' ';
}
return;
}