-
Notifications
You must be signed in to change notification settings - Fork 0
/
assedit.c
461 lines (385 loc) · 13.7 KB
/
assedit.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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/* ******************************************************************** *
* FILE : assedit.c Copyright (C) 1999 Del Minturn *
* USAGE: Olc for assembly engine by Geoff Davis. *
* Oasis OLC by George Greer.
* -------------------------------------------------------------------- *
* 1999 July 25 [email protected] *
* ******************************************************************** */
#include "conf.h"
#include "sysdep.h"
SVNHEADER("$Id: assedit.c 55 2009-03-20 17:58:56Z pladow $");
#include "structs.h"
#include "utils.h"
#include "db.h"
#include "comm.h"
#include "handler.h"
#include "interpreter.h"
#include "oasis.h"
#include "assemblies.h"
#include "constants.h"
/*-------------------------------------------------------------------*
* External data structures.
*-------------------------------------------------------------------*/
extern struct descriptor_data *descriptor_list;
extern struct obj_data *obj_proto;
/*-------------------------------------------------------------------*
* Function prototypes.
*-------------------------------------------------------------------*/
void assedit_setup(struct descriptor_data *d, int number);
void assedit_disp_menu(struct descriptor_data *d);
void assedit_delete(struct descriptor_data *d);
void assedit_edit_extract(struct descriptor_data *d);
void assedit_edit_inroom(struct descriptor_data *d);
void nodigit(struct descriptor_data *d);
/*-------------------------------------------------------------------*
* Nasty internal macros to clean up the code.
*-------------------------------------------------------------------*/
long lRnum = 0;
/*-------------------------------------------------------------------*
* Assedit command
*-------------------------------------------------------------------*/
ACMD (do_assedit)
{
struct descriptor_data *d = ch->desc;
char buf[MAX_STRING_LENGTH];
char buf2[MAX_STRING_LENGTH];
*buf = '\0'; /* If I run into problems then take this sucker out */
*buf2 = '\0';
if (IS_NPC(ch))
return;
for (d = descriptor_list; d; d = d->next) {
if (d->connected == CON_ASSEDIT) {
send_to_char(ch, "Assemblies are already being editted by someone.\r\n");
return;
}
}
two_arguments(argument, buf, buf2);
d= ch->desc;
if(!*buf) {
nodigit(d);
return;
}
if (!isdigit(*buf)) {
if (strn_cmp("new", buf, 3) == 0) {
if (!isdigit(*buf2)) {
nodigit(d);
} else if (real_object(atoi(buf2)) == NOTHING) {
send_to_char(d->character, "You need to create the assembly object before you can create the new assembly.\r\n");
return;
} else {
assemblyCreate(atoi(buf2), 0);
send_to_char(d->character, "Assembly Created.\r\n");
assemblySaveAssemblies();
return;
}
}
else
if (strn_cmp("delete", buf, 6) == 0) {
if (!isdigit(*buf2))
nodigit(d);
else {
assemblyDestroy(atoi(buf2));
send_to_char(d->character, "Assembly Deleted.\r\n");
assemblySaveAssemblies();
return;
}
}
else {
nodigit(d);
return;
}
} else
if (isdigit(*buf)) {
d = ch->desc;
CREATE (d->olc, struct oasis_olc_data, 1);
assedit_setup(d, atoi(buf));
}
return;
}
/*-------------------------------------------------------------------*
* Assedit Functions
*-------------------------------------------------------------------*/
void assedit_setup(struct descriptor_data *d, int number)
{
ASSEMBLY *pOldAssembly = NULL;
CREATE(OLC_ASSEDIT(d), ASSEMBLY, 1 );
if( (pOldAssembly = assemblyGetAssemblyPtr( number )) == NULL ) {
send_to_char(d->character, "That assembly does not exist\r\n");
cleanup_olc(d, CLEANUP_ALL);
return;
} else {
/* Copy the old assembly. */
OLC_ASSEDIT(d)->lVnum = pOldAssembly->lVnum;
OLC_ASSEDIT(d)->uchAssemblyType = pOldAssembly->uchAssemblyType;
OLC_ASSEDIT(d)->lNumComponents = pOldAssembly->lNumComponents;
if( OLC_ASSEDIT(d)->lNumComponents > 0 ) {
CREATE(OLC_ASSEDIT(d)->pComponents, COMPONENT, OLC_ASSEDIT(d)->lNumComponents);
memmove(OLC_ASSEDIT(d)->pComponents, pOldAssembly->pComponents,
OLC_ASSEDIT(d)->lNumComponents * sizeof( COMPONENT ) );
}
}
/*
* At this point, pNewAssembly is now the address of a freshly allocated copy of all
* the data contained in the original assembly structure.
*/
if ( (lRnum = real_object( OLC_ASSEDIT(d)->lVnum ) ) < 0)
{
send_to_char(d->character, "Assembled item may not exist, check the vnum and assembles (show assemblies). \r\n");
cleanup_olc(d, CLEANUP_ALL); /* for right now we just get out! */
return;
}
STATE(d) = CON_ASSEDIT;
act("$n starts using OLC.", TRUE, d->character, 0, 0, TO_ROOM);
SET_BIT_AR(PLR_FLAGS(d->character), PLR_WRITING);
assedit_disp_menu(d);
}
void assedit_disp_menu(struct descriptor_data *d)
{
int i = 0;
char szAssmType[MAX_INPUT_LENGTH] = { '\0' };
sprinttype(OLC_ASSEDIT(d)->uchAssemblyType, AssemblyTypes, szAssmType, sizeof(szAssmType));
#if defined(CLEAR_SCREEN)
send_to_char(d->character, "%c[H%c[J", 27, 27);
#endif
send_to_char(d->character,
"Assembly Number: @c%ld@n\r\n"
"Assembly Name : @y%s@n\r\n"
"Assembly Type : @y%s@n\r\n"
"Components:\r\n",
OLC_ASSEDIT(d)->lVnum,
obj_proto[real_object(OLC_ASSEDIT(d)->lVnum)].short_description,
szAssmType
);
if (OLC_ASSEDIT(d)->lNumComponents <= 0)
send_to_char(d->character, " < NONE > \r\n");
else {
for (i = 0; i < OLC_ASSEDIT(d)->lNumComponents; i++ ) {
if ((lRnum = real_object(OLC_ASSEDIT(d)->pComponents[i].lVnum)) < 0) {
send_to_char(d->character, "@g%2d@n) @y ERROR --- Contact an Implementor @n\r\n ", i+1);
} else {
send_to_char(d->character,
"@g%2d@n) [@c%5ld@n] %-20.20s In room: @c%-3.3s@n Extract: @y%-3.3s@n\r\n",
i+1, OLC_ASSEDIT(d)->pComponents[i].lVnum,
obj_proto[lRnum].short_description,
(OLC_ASSEDIT(d)->pComponents[i].bInRoom ? "Yes" : "No"),
(OLC_ASSEDIT(d)->pComponents[i].bExtract ? "Yes" : "No"));
}
}
}
send_to_char(d->character,
"@gA@n) Add a new component.\r\n"
"@gE@n) Edit a component.\r\n"
"@gD@n) Delete a component.\r\n"
"@gT@n) Change Assembly Type.\r\n"
"@gQ@n) Quit.\r\n"
"\r\nEnter your choice : ");
OLC_MODE(d) = ASSEDIT_MAIN_MENU;
return;
}
/***************************************************
Command Parse
***************************************************/
void assedit_parse(struct descriptor_data *d, char *arg)
{
int pos = 0, i = 0, counter, columns = 0;
COMPONENT *pTComponents = NULL;
switch (OLC_MODE(d)) {
case ASSEDIT_MAIN_MENU:
switch (*arg) {
case 'q':
case 'Q': /* do the quit stuff */
/* Ok, Time to save it back to the original stuff and get out */
/* due to the infrequent use of this code and restricted use */
/* I decided to copy over changes regarless. */
assemblyDestroy(OLC_ASSEDIT(d)->lVnum);
assemblyCreate(OLC_ASSEDIT(d)->lVnum, OLC_ASSEDIT(d)->uchAssemblyType);
for( i = 0; i < OLC_ASSEDIT(d)->lNumComponents; i++) {
assemblyAddComponent(OLC_ASSEDIT(d)->lVnum,
OLC_ASSEDIT(d)->pComponents[i].lVnum,
OLC_ASSEDIT(d)->pComponents[i].bExtract,
OLC_ASSEDIT(d)->pComponents[i].bInRoom
);
}
send_to_char(d->character, "\r\nSaving all assemblies\r\n");
assemblySaveAssemblies();
/* free(pTComponents);
free(OLC_ASSEDIT(d));
*/
cleanup_olc(d, CLEANUP_ALL); /* for right now we just get out! */
break;
case 't':
case 'T':
#if defined(CLEAR_SCREEN)
send_to_char(d->character, "%c[H%c[J", 27, 27);
#endif
for (counter = 0; counter < MAX_ASSM; counter++) {
send_to_char(d->character, "@g%2d@n) %-20.20s %s", counter + 1,
AssemblyTypes[counter], !(++columns % 2) ? "\r\n" : "");
}
send_to_char(d->character, "Enter the assembly type : ");
OLC_MODE(d) = ASSEDIT_EDIT_TYPES;
break;
case 'a':
case 'A': /* add a new component */
send_to_char(d->character, "\r\nWhat is the vnum of the new component?");
OLC_MODE(d) = ASSEDIT_ADD_COMPONENT;
break;
case 'e':
case 'E': /* edit a component */
send_to_char(d->character, "\r\nEdit which component? ");
OLC_MODE(d) = ASSEDIT_EDIT_COMPONENT;
break;
case 'd':
case 'D': /* delete a component */
if ((pos < 0) || pos > OLC_ASSEDIT(d)->lNumComponents) {
send_to_char(d->character, "\r\nWhich component do you wish to remove?");
assedit_disp_menu(d);
} else {
send_to_char(d->character, "\r\nWhich component do you wish to remove?");
OLC_MODE(d) = ASSEDIT_DELETE_COMPONENT;
}
break;
default:
assedit_disp_menu(d);
}
break;
case ASSEDIT_EDIT_TYPES:
if (isdigit(*arg)){
pos = atoi(arg) - 1;
if( (pos >= 0) || (pos < MAX_ASSM)) {
OLC_ASSEDIT(d)->uchAssemblyType = pos;
assedit_disp_menu(d);
break;
}
}
else
assedit_disp_menu(d);
break;
case ASSEDIT_ADD_COMPONENT: /* add a new component */
if (isdigit(*arg)){
pos = atoi(arg);
#if CIRCLE_UNSIGNED_INDEX
if ((real_object(pos)) == NOTHING) /* does the object exist? */
break;
#else
if ((real_object(pos)) <= NOTHING) /* does the object exist? */
break;
#endif
for ( i = 0; i < OLC_ASSEDIT(d)->lNumComponents; i++) {
if(OLC_ASSEDIT(d)->pComponents[i].lVnum == pos)
break;
}
CREATE( pTComponents, COMPONENT, OLC_ASSEDIT(d)->lNumComponents + 1);
if(OLC_ASSEDIT(d)->pComponents != NULL) { /* Copy from olc to temp */
memmove(pTComponents, OLC_ASSEDIT(d)->pComponents,
OLC_ASSEDIT(d)->lNumComponents * sizeof(COMPONENT) );
/* free(OLC_ASSEDIT(d)->pComponents); */
}
OLC_ASSEDIT(d)->pComponents = pTComponents;
OLC_ASSEDIT(d)->pComponents[ OLC_ASSEDIT(d)->lNumComponents ].lVnum = pos;
OLC_ASSEDIT(d)->pComponents[ OLC_ASSEDIT(d)->lNumComponents ].bExtract = YES;
OLC_ASSEDIT(d)->pComponents[ OLC_ASSEDIT(d)->lNumComponents ].bInRoom = NO;
OLC_ASSEDIT(d)->lNumComponents += 1;
assedit_disp_menu(d);
} else {
send_to_char(d->character, "That object does not exist. Please try again\r\n");
assedit_disp_menu(d);
}
break;
case ASSEDIT_EDIT_COMPONENT:
pos = atoi(arg);
if (isdigit(*arg)) {
pos--;
OLC_VAL(d) = pos;
assedit_edit_extract(d);
break;
}
else
assedit_disp_menu(d);
break;
case ASSEDIT_DELETE_COMPONENT:
if (isdigit(*arg)) {
pos = atoi(arg);
pos -= 1;
CREATE( pTComponents, COMPONENT, OLC_ASSEDIT(d)->lNumComponents -1);
if( pos > 0 )
memmove( pTComponents, OLC_ASSEDIT(d)->pComponents, pos * sizeof( COMPONENT ) );
if( pos < OLC_ASSEDIT(d)->lNumComponents - 1 )
memmove( pTComponents + pos, OLC_ASSEDIT(d)->pComponents + pos + 1,
(OLC_ASSEDIT(d)->lNumComponents - pos - 1) * sizeof(COMPONENT) );
free(OLC_ASSEDIT(d)->pComponents );
OLC_ASSEDIT(d)->pComponents = pTComponents;
OLC_ASSEDIT(d)->lNumComponents -= 1;
assedit_disp_menu(d);
break;
} else
assedit_disp_menu(d);
break;
case ASSEDIT_EDIT_EXTRACT:
switch (*arg) {
case 'y':
case 'Y':
OLC_ASSEDIT(d)->pComponents[ OLC_VAL(d) ].bExtract = TRUE;
assedit_edit_inroom(d);
break;
case 'n':
case 'N':
OLC_ASSEDIT(d)->pComponents[ OLC_VAL(d) ].bExtract = FALSE;
assedit_edit_inroom(d);
break;
default:
send_to_char(d->character, "Is the item to be extracted when the assembly is created? (Y/N)");
break;
}
break;
case ASSEDIT_EDIT_INROOM:
switch (*arg) {
case 'y':
case 'Y':
OLC_ASSEDIT(d)->pComponents[ OLC_VAL(d) ].bInRoom = TRUE;
assedit_disp_menu(d);
break;
case 'n':
case 'N':
OLC_ASSEDIT(d)->pComponents[ OLC_VAL(d) ].bInRoom = FALSE;
assedit_disp_menu(d);
break;
default:
send_to_char(d->character, "Object in the room when assembly is created? (n = in inventory):");
break;
}
break;
default: /* default for whole assedit parse function */
/* we should never get here */
mudlog(BRF, ADMLVL_GOD, TRUE, "SYSERR: OLC assedit_parse(): Reached default case!");
send_to_char(d->character, "Opps...\r\n");
STATE(d) = CON_PLAYING;
break;
}
}
/* End of Assedit Parse */
void assedit_delete(struct descriptor_data *d)
{
send_to_char(d->character, "Which item number do you wish to delete from this assembly?");
OLC_MODE(d) = ASSEDIT_DELETE_COMPONENT;
return;
}
void assedit_edit_extract(struct descriptor_data *d)
{
send_to_char(d->character, "Is the item to be extracted when the assembly is created? (Y/N):");
OLC_MODE(d) = ASSEDIT_EDIT_EXTRACT;
return;
}
void assedit_edit_inroom(struct descriptor_data *d)
{
send_to_char(d->character, "Should the object be in the room when assembly is created (n = in inventory)?");
OLC_MODE(d) = ASSEDIT_EDIT_INROOM;
return;
}
void nodigit(struct descriptor_data *d)
{
send_to_char(d->character, "Usage: assedit <vnum>\r\n");
send_to_char(d->character, " : assedit new <vnum>\r\n");
send_to_char(d->character, " : assedit delete <vnum>\r\n");
return;
}