-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_help.c
executable file
·258 lines (235 loc) · 11.2 KB
/
context_help.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
/*
* The functions below this point is handling the context sensitive help system
* If you add more olc options, be sure to add a case for it here. - Welcor
*/
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "db.h"
#include "oasis.h"
#include "dg_olc.h"
/* local global */
char *context_help_list[NUM_CONTEXTS];
int find_context(struct descriptor_data *d)
{
switch STATE(d) {
case CON_TRIGEDIT: return find_context_trigedit(d);
case CON_REDIT: return find_context_redit(d);
case CON_MEDIT: return find_context_medit(d);
case CON_OEDIT: return find_context_oedit(d);
case CON_ZEDIT: return find_context_zedit(d);
case CON_SEDIT: return find_context_sedit(d);
default: return NOTHING;
}
}
int find_context_oedit(struct descriptor_data *d)
{
switch (OLC_MODE(d)) {
case OEDIT_MAIN_MENU: return CONTEXT_OEDIT_MAIN_MENU;
case OEDIT_EDIT_NAMELIST: return CONTEXT_OEDIT_EDIT_NAMELIST;
case OEDIT_SHORTDESC: return CONTEXT_OEDIT_SHORTDESC;
case OEDIT_LONGDESC: return CONTEXT_OEDIT_LONGDESC;
case OEDIT_ACTDESC: return CONTEXT_OEDIT_ACTDESC;
case OEDIT_TYPE: return CONTEXT_OEDIT_TYPE;
case OEDIT_EXTRAS: return CONTEXT_OEDIT_EXTRAS;
case OEDIT_WEAR: return CONTEXT_OEDIT_WEAR;
case OEDIT_WEIGHT: return CONTEXT_OEDIT_WEIGHT;
case OEDIT_COST: return CONTEXT_OEDIT_COST;
case OEDIT_COSTPERDAY: return CONTEXT_OEDIT_COSTPERDAY;
case OEDIT_TIMER: return CONTEXT_OEDIT_TIMER;
case OEDIT_VALUE_1: return CONTEXT_OEDIT_VALUE_1;
case OEDIT_VALUE_2: return CONTEXT_OEDIT_VALUE_2;
case OEDIT_VALUE_3: return CONTEXT_OEDIT_VALUE_3;
case OEDIT_VALUE_4: return CONTEXT_OEDIT_VALUE_4;
case OEDIT_APPLY: return CONTEXT_OEDIT_APPLY;
case OEDIT_APPLYMOD: return CONTEXT_OEDIT_APPLYMOD;
case OEDIT_EXTRADESC_KEY: return CONTEXT_OEDIT_EXTRADESC_KEY;
case OEDIT_CONFIRM_SAVEDB: return CONTEXT_OEDIT_CONFIRM_SAVEDB;
case OEDIT_CONFIRM_SAVESTRING: return CONTEXT_OEDIT_CONFIRM_SAVESTRING;
case OEDIT_PROMPT_APPLY: return CONTEXT_OEDIT_PROMPT_APPLY;
case OEDIT_EXTRADESC_DESCRIPTION: return CONTEXT_OEDIT_EXTRADESC_DESCRIPTION;
case OEDIT_EXTRADESC_MENU: return CONTEXT_OEDIT_EXTRADESC_MENU;
case OEDIT_LEVEL: return CONTEXT_OEDIT_LEVEL;
case OEDIT_PERM: return CONTEXT_OEDIT_PERM;
case OLC_SCRIPT_EDIT: return find_context_script_edit(d);
default: return NOTHING;
}
}
int find_context_redit(struct descriptor_data *d)
{
switch (OLC_MODE(d)) {
case REDIT_MAIN_MENU: return CONTEXT_REDIT_MAIN_MENU;
case REDIT_NAME: return CONTEXT_REDIT_NAME;
case REDIT_DESC: return CONTEXT_REDIT_DESC;
case REDIT_FLAGS: return CONTEXT_REDIT_FLAGS;
case REDIT_SECTOR: return CONTEXT_REDIT_SECTOR;
case REDIT_EXIT_MENU: return CONTEXT_REDIT_EXIT_MENU;
case REDIT_CONFIRM_SAVEDB: return CONTEXT_REDIT_CONFIRM_SAVEDB;
case REDIT_CONFIRM_SAVESTRING: return CONTEXT_REDIT_CONFIRM_SAVESTRING;
case REDIT_EXIT_NUMBER: return CONTEXT_REDIT_EXIT_NUMBER;
case REDIT_EXIT_DESCRIPTION: return CONTEXT_REDIT_EXIT_DESCRIPTION;
case REDIT_EXIT_KEYWORD: return CONTEXT_REDIT_EXIT_KEYWORD;
case REDIT_EXIT_KEY: return CONTEXT_REDIT_EXIT_KEY;
case REDIT_EXIT_DOORFLAGS: return CONTEXT_REDIT_EXIT_DOORFLAGS;
case REDIT_EXTRADESC_MENU: return CONTEXT_REDIT_EXTRADESC_MENU;
case REDIT_EXTRADESC_KEY: return CONTEXT_REDIT_EXTRADESC_KEY;
case REDIT_EXTRADESC_DESCRIPTION:return CONTEXT_REDIT_EXTRADESC_DESCRIPTION;
case OLC_SCRIPT_EDIT: return find_context_script_edit(d);
default: return NOTHING;
}
}
int find_context_zedit(struct descriptor_data *d)
{
switch (OLC_MODE(d)) {
case ZEDIT_MAIN_MENU: return CONTEXT_ZEDIT_MAIN_MENU;
case ZEDIT_DELETE_ENTRY: return CONTEXT_ZEDIT_DELETE_ENTRY;
case ZEDIT_NEW_ENTRY: return CONTEXT_ZEDIT_NEW_ENTRY;
case ZEDIT_CHANGE_ENTRY: return CONTEXT_ZEDIT_CHANGE_ENTRY;
case ZEDIT_COMMAND_TYPE: return CONTEXT_ZEDIT_COMMAND_TYPE;
case ZEDIT_IF_FLAG: return CONTEXT_ZEDIT_IF_FLAG;
case ZEDIT_ARG1: return CONTEXT_ZEDIT_ARG1;
case ZEDIT_ARG2: return CONTEXT_ZEDIT_ARG2;
case ZEDIT_ARG3: return CONTEXT_ZEDIT_ARG3;
case ZEDIT_ZONE_NAME: return CONTEXT_ZEDIT_ZONE_NAME;
case ZEDIT_ZONE_LIFE: return CONTEXT_ZEDIT_ZONE_LIFE;
case ZEDIT_ZONE_BOT: return CONTEXT_ZEDIT_ZONE_BOT;
case ZEDIT_ZONE_TOP: return CONTEXT_ZEDIT_ZONE_TOP;
case ZEDIT_ZONE_RESET: return CONTEXT_ZEDIT_ZONE_RESET;
case ZEDIT_CONFIRM_SAVESTRING:return CONTEXT_ZEDIT_CONFIRM_SAVESTRING;
case ZEDIT_SARG1: return CONTEXT_ZEDIT_SARG1;
case ZEDIT_SARG2: return CONTEXT_ZEDIT_SARG2;
case ZEDIT_FLAG_MENU: return CONTEXT_ZEDIT_FLAG_MENU;
default: return NOTHING;
}
}
int find_context_medit(struct descriptor_data *d)
{
switch (OLC_MODE(d)) {
case MEDIT_MAIN_MENU: return CONTEXT_MEDIT_MAIN_MENU;
case MEDIT_ALIAS: return CONTEXT_MEDIT_ALIAS;
case MEDIT_S_DESC: return CONTEXT_MEDIT_S_DESC;
case MEDIT_L_DESC: return CONTEXT_MEDIT_L_DESC;
case MEDIT_D_DESC: return CONTEXT_MEDIT_D_DESC;
case MEDIT_NPC_FLAGS: return CONTEXT_MEDIT_NPC_FLAGS;
case MEDIT_AFF_FLAGS: return CONTEXT_MEDIT_AFF_FLAGS;
case MEDIT_CONFIRM_SAVESTRING:return CONTEXT_MEDIT_CONFIRM_SAVESTRING;
case MEDIT_SEX: return CONTEXT_MEDIT_SEX;
case MEDIT_HITROLL: return CONTEXT_MEDIT_HITROLL;
case MEDIT_DAMROLL: return CONTEXT_MEDIT_DAMROLL;
case MEDIT_NDD: return CONTEXT_MEDIT_NDD;
case MEDIT_SDD: return CONTEXT_MEDIT_SDD;
case MEDIT_NUM_HP_DICE: return CONTEXT_MEDIT_NUM_HP_DICE;
case MEDIT_SIZE_HP_DICE: return CONTEXT_MEDIT_SIZE_HP_DICE;
case MEDIT_ADD_HP: return CONTEXT_MEDIT_ADD_HP;
case MEDIT_AC: return CONTEXT_MEDIT_AC;
case MEDIT_EXP: return CONTEXT_MEDIT_EXP;
case MEDIT_GOLD: return CONTEXT_MEDIT_GOLD;
case MEDIT_POS: return CONTEXT_MEDIT_POS;
case MEDIT_DEFAULT_POS: return CONTEXT_MEDIT_DEFAULT_POS;
case MEDIT_ATTACK: return CONTEXT_MEDIT_ATTACK;
case MEDIT_LEVEL: return CONTEXT_MEDIT_LEVEL;
case MEDIT_ALIGNMENT: return CONTEXT_MEDIT_ALIGNMENT;
case OLC_SCRIPT_EDIT: return find_context_script_edit(d);
default: return NOTHING;
}
}
int find_context_sedit(struct descriptor_data *d)
{
switch (OLC_MODE(d)) {
case SEDIT_MAIN_MENU: return CONTEXT_SEDIT_MAIN_MENU;
case SEDIT_CONFIRM_SAVESTRING:return CONTEXT_SEDIT_CONFIRM_SAVESTRING;
case SEDIT_NOITEM1: return CONTEXT_SEDIT_NOITEM1;
case SEDIT_NOITEM2: return CONTEXT_SEDIT_NOITEM2;
case SEDIT_NOCASH1: return CONTEXT_SEDIT_NOCASH1;
case SEDIT_NOCASH2: return CONTEXT_SEDIT_NOCASH2;
case SEDIT_NOBUY: return CONTEXT_SEDIT_NOBUY;
case SEDIT_BUY: return CONTEXT_SEDIT_BUY;
case SEDIT_SELL: return CONTEXT_SEDIT_SELL;
case SEDIT_PRODUCTS_MENU: return CONTEXT_SEDIT_PRODUCTS_MENU;
case SEDIT_ROOMS_MENU: return CONTEXT_SEDIT_ROOMS_MENU;
case SEDIT_NAMELIST_MENU: return CONTEXT_SEDIT_NAMELIST_MENU;
case SEDIT_NAMELIST: return CONTEXT_SEDIT_NAMELIST;
case SEDIT_OPEN1: return CONTEXT_SEDIT_OPEN1;
case SEDIT_OPEN2: return CONTEXT_SEDIT_OPEN2;
case SEDIT_CLOSE1: return CONTEXT_SEDIT_CLOSE1;
case SEDIT_CLOSE2: return CONTEXT_SEDIT_CLOSE2;
case SEDIT_KEEPER: return CONTEXT_SEDIT_KEEPER;
case SEDIT_BUY_PROFIT: return CONTEXT_SEDIT_BUY_PROFIT;
case SEDIT_SELL_PROFIT: return CONTEXT_SEDIT_SELL_PROFIT;
case SEDIT_TYPE_MENU: return CONTEXT_SEDIT_TYPE_MENU;
case SEDIT_DELETE_TYPE: return CONTEXT_SEDIT_DELETE_TYPE;
case SEDIT_DELETE_PRODUCT: return CONTEXT_SEDIT_DELETE_PRODUCT;
case SEDIT_NEW_PRODUCT: return CONTEXT_SEDIT_NEW_PRODUCT;
case SEDIT_DELETE_ROOM: return CONTEXT_SEDIT_DELETE_ROOM;
case SEDIT_NEW_ROOM: return CONTEXT_SEDIT_NEW_ROOM;
case SEDIT_SHOP_FLAGS: return CONTEXT_SEDIT_SHOP_FLAGS;
case SEDIT_NOTRADE: return CONTEXT_SEDIT_NOTRADE;
default: return NOTHING;
}
}
int find_context_trigedit(struct descriptor_data *d)
{
switch (OLC_MODE(d)) {
case TRIGEDIT_MAIN_MENU: return CONTEXT_TRIGEDIT_MAIN_MENU;
case TRIGEDIT_TRIGTYPE: return CONTEXT_TRIGEDIT_TRIGTYPE;
case TRIGEDIT_CONFIRM_SAVESTRING:return CONTEXT_TRIGEDIT_CONFIRM_SAVESTRING;
case TRIGEDIT_NAME: return CONTEXT_TRIGEDIT_NAME;
case TRIGEDIT_INTENDED: return CONTEXT_TRIGEDIT_INTENDED;
case TRIGEDIT_TYPES: return CONTEXT_TRIGEDIT_TYPES;
case TRIGEDIT_COMMANDS: return CONTEXT_TRIGEDIT_COMMANDS;
case TRIGEDIT_NARG: return CONTEXT_TRIGEDIT_NARG;
case TRIGEDIT_ARGUMENT: return CONTEXT_TRIGEDIT_ARGUMENT;
default: return NOTHING;
}
}
int find_context_script_edit(struct descriptor_data *d)
{
switch (OLC_SCRIPT_EDIT_MODE(d)) {
case SCRIPT_MAIN_MENU: return CONTEXT_SCRIPT_MAIN_MENU;
case SCRIPT_NEW_TRIGGER:return CONTEXT_SCRIPT_NEW_TRIGGER;
case SCRIPT_DEL_TRIGGER:return CONTEXT_SCRIPT_DEL_TRIGGER;
default: return NOTHING;
}
}
char *NO_HELP = "No help available (yet)!\r\n";
int context_help(struct descriptor_data *d, char *arg)
{
int context;
/* skip if context help isn't wanted */
if (strcmp(arg, CONTEXT_HELP_STRING))
return 0;
context = find_context(d);
if (context != NOTHING && context < NUM_CONTEXTS && *context_help_list[context]) {
write_to_output(d, "\r\n%s\r\n", context_help_list[context]);
} else {
write_to_output(d, "\r\n%s\r\n", NO_HELP);
}
write_to_output(d, "> "); /* a sort-of prompt*/
return 1;
}
void boot_context_help(void) {
int i, num;
FILE *fl;
char line[READ_SIZE];
fl = fopen(CONTEXT_HELP_FILE, "r");
/* init to 'no help' string */
for (i=0;i < NUM_CONTEXTS;i++)
context_help_list[i] = NO_HELP;
if (!fl) {
log("No context help found : %s", strerror(errno));
return;
}
while (get_line(fl, line)) {
if (sscanf(line, "#%d *", &num) == 1) /* got a number, now get the text */
context_help_list[num] = fread_string(fl, "Context sensitive help");
}
fclose(fl);
}
void free_context_help(void) {
int i;
for (i = 0; i < NUM_CONTEXTS; i++)
if (context_help_list[i] && context_help_list[i] != NO_HELP)
free(context_help_list[i]);
}