-
Notifications
You must be signed in to change notification settings - Fork 23
/
crafts.c
executable file
·1275 lines (1103 loc) · 34.3 KB
/
crafts.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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
\
/ Luminari Crafts System
/ Created By: Created by Vatiken, (Joseph Arnusch)
\ installed by Ornir
/ Header file: crafts.h
\ Created: June 21st, 2012
/
\ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ /*/
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "db.h"
#include "comm.h"
#include "act.h"
#include "handler.h"
#include "interpreter.h"
#include "screen.h"
#include "constants.h"
#include "oasis.h"
#include "genolc.h"
#include "spells.h"
#include "mud_event.h"
#include "crafts.h"
#include "item.h"
/* Statics */
static void craftedit_disp_menu(struct descriptor_data *d);
static void save_crafts_to_disk(void);
static void remove_components(struct char_data *ch, struct craft_data *craft, bool success);
int num_crafts = 0;
struct list_data *global_craft_list = NULL;
struct craft_data *create_craft(void)
{
struct craft_data *new_craft;
CREATE(new_craft, struct craft_data, 1);
new_craft->craft_name = NULL;
new_craft->craft_flags = 0;
new_craft->craft_object_vnum = NOTHING;
new_craft->craft_timer = 0;
new_craft->craft_id = 0;
new_craft->craft_skill = -1;
new_craft->craft_skill_level = 0;
new_craft->craft_msg_room = NULL;
new_craft->craft_msg_self = NULL;
new_craft->requirements = create_list();
return (new_craft);
}
struct requirement_data *create_requirement(void)
{
struct requirement_data *new_requirement;
CREATE(new_requirement, struct requirement_data, 1);
new_requirement->req_vnum = NOTHING;
new_requirement->req_amount = 0;
new_requirement->req_flags = 0;
return (new_requirement);
}
void free_craft(struct craft_data *craft)
{
struct requirement_data *r;
struct iterator_data Iterator;
if (craft->craft_name)
free(craft->craft_name);
if (craft->craft_msg_self)
free(craft->craft_msg_self);
if (craft->craft_msg_room)
free(craft->craft_msg_room);
if (craft->requirements->iSize)
{
for (r = (struct requirement_data *)merge_iterator(&Iterator, craft->requirements);
r;
r = next_in_list(&Iterator))
{
remove_from_list(r, craft->requirements);
free(r);
}
remove_iterator(&Iterator);
free_list(craft->requirements);
}
free(craft);
}
void load_crafts(void)
{
FILE *fp;
char *line;
char tag[6];
struct craft_data *craft = NULL;
struct requirement_data *requirement;
bool in_craft = FALSE;
bool done = FALSE;
if ((fp = fopen(CRAFT_FILE, "r")) == NULL)
{
log("No Craft file found!");
return;
}
else
{
while ((line = fread_line(fp)) != NULL && line[0] != '\0' && !done)
{
if (!in_craft && !strcmp(line, "NEW"))
{
craft = create_craft();
in_craft = TRUE;
}
else if (line[0] == '$')
{
done = TRUE;
break;
}
else if (in_craft)
{
tag_argument(line, tag);
switch (*tag)
{
case 'I':
if (!strcmp(tag, "Id "))
craft->craft_id = atoi(line);
break;
case 'E':
if (!strcmp(tag, "End "))
{
in_craft = FALSE;
add_to_list(craft, global_craft_list);
}
break;
case 'F':
if (!strcmp(tag, "Flag"))
craft->craft_flags = atoi(line);
break;
case 'M':
if (!strcmp(tag, "Mroo"))
craft->craft_msg_room = strdup(line);
else if (!strcmp(tag, "Mslf"))
craft->craft_msg_self = strdup(line);
break;
case 'N':
if (!strcmp(tag, "Name"))
craft->craft_name = strdup(line);
break;
case 'R':
if (!strcmp(tag, "Req "))
{
requirement = create_requirement();
if (sscanf(line, "%d %d %d\n", (int *)&requirement->req_vnum, &requirement->req_amount, &requirement->req_flags) != 3)
log("SYSERR: Format error in Requirement");
else
add_to_list(requirement, craft->requirements);
}
break;
case 'S':
if (!strcmp(tag, "Skil"))
{
if (sscanf(line, "%d %d\n", &craft->craft_skill, &craft->craft_skill_level) != 2)
log("SYSERR: Format error in Skill Level");
}
break;
case 'T':
if (!strcmp(tag, "Time"))
craft->craft_timer = atoi(line);
break;
case 'V':
if (!strcmp(tag, "Vnum"))
craft->craft_object_vnum = atoi(line);
break;
default:
log("SYSERR: Craft File: Unexpected '%s' in file.", tag);
break;
}
}
else
log("SYSERR: Error in the crafts file.");
}
}
fclose(fp);
}
/* write_crafts() */
static void save_crafts_to_disk(void)
{
FILE *fp;
struct craft_data *c;
struct requirement_data *r;
struct iterator_data Iterator;
if ((fp = fopen(CRAFT_FILE, "w")) == NULL)
{
log("Cannot open craft file for writing!");
return;
}
for (c = (struct craft_data *)merge_iterator(&Iterator, global_craft_list);
c;
c = next_in_list(&Iterator))
{
fprintf(fp, "NEW\n");
fprintf(fp, "Name: %s\n", CRAFT_NAME(c));
fprintf(fp, "Id : %d\n", CRAFT_ID(c));
fprintf(fp, "Flag: %d\n", CRAFT_FLAGS(c));
fprintf(fp, "Vnum: %d\n", CRAFT_OBJVNUM(c));
fprintf(fp, "Time: %d\n", CRAFT_TIMER(c));
fprintf(fp, "Skil: %d %d\n", CRAFT_SKILL(c), CRAFT_SKILL_LEVEL(c));
fprintf(fp, "Mslf: %s\n", CRAFT_MSG_SELF(c));
fprintf(fp, "Mroo: %s\n", CRAFT_MSG_ROOM(c));
while ((r = (struct requirement_data *)simple_list(c->requirements)) != NULL)
fprintf(fp, "Req : %d %d %d\n",
r->req_vnum, r->req_amount, r->req_flags);
fprintf(fp, "End :\n");
}
remove_iterator(&Iterator);
fprintf(fp, "$\n");
fclose(fp);
}
/* Craft Handlers */
void sort_craft_list(void)
{
struct list_data *sorted;
struct craft_data *craft, *rem_craft;
sorted = create_list();
while (global_craft_list->iSize)
{
simple_list(NULL);
rem_craft = NULL;
while ((craft = (struct craft_data *)simple_list(global_craft_list)) != NULL)
{
if (rem_craft == NULL)
rem_craft = craft;
else if (CRAFT_ID(craft) <= CRAFT_ID(rem_craft))
rem_craft = craft;
}
if (rem_craft != NULL)
{
add_to_list(rem_craft, sorted);
remove_from_list(rem_craft, global_craft_list);
}
else
break;
}
free_list(global_craft_list);
global_craft_list = sorted;
}
struct craft_data *get_craft_from_arg(char *arg)
{
struct iterator_data iterator;
struct craft_data *craft = NULL;
if (!global_craft_list->iSize)
return NULL;
for (craft = (struct craft_data *)merge_iterator(&iterator, global_craft_list);
craft != NULL;
craft = (struct craft_data *)next_in_list(&iterator))
{
if (is_abbrev(arg, CRAFT_NAME(craft)))
break;
}
remove_iterator(&iterator);
return (craft);
}
struct craft_data *get_craft_from_id(int id)
{
struct iterator_data iterator;
struct craft_data *craft = NULL;
if (!global_craft_list->iSize)
return NULL;
for (craft = (struct craft_data *)merge_iterator(&iterator, global_craft_list);
craft != NULL;
craft = (struct craft_data *)next_in_list(&iterator))
{
if (CRAFT_ID(craft) == id)
break;
}
remove_iterator(&iterator);
return (craft);
}
struct requirement_data *find_requirement_in_craft(struct craft_data *craft, obj_vnum vnum)
{
struct requirement_data *r = NULL;
struct iterator_data Iterator;
bool found = FALSE;
if (craft->requirements->iSize == 0)
return NULL;
for (r = (struct requirement_data *)merge_iterator(&Iterator, craft->requirements);
r;
r = next_in_list(&Iterator))
if (r->req_vnum == vnum)
{
found = TRUE;
break;
}
remove_iterator(&Iterator);
if (found)
return r;
return NULL;
}
struct obj_data *get_object_from_requirement(struct char_data *ch, struct requirement_data *req)
{
struct obj_data *obj;
if (IS_SET(req->req_flags, REQ_FLAG_NO_REMOVE))
return (NULL);
if (IS_SET(req->req_flags, REQ_FLAG_IN_ROOM))
{
for (obj = world[IN_ROOM(ch)].contents; obj; obj = obj->next_content)
{
if (GET_OBJ_VNUM(obj) == req->req_vnum)
return (obj);
}
}
else
{
for (obj = ch->carrying; obj; obj = obj->next_content)
{
if (GET_OBJ_VNUM(obj) == req->req_vnum)
return (obj);
}
}
return (NULL);
}
bool find_requirement(struct char_data *ch, struct requirement_data *req)
{
bool in_room = IS_SET(req->req_flags, REQ_FLAG_IN_ROOM);
obj_vnum vnum = req->req_vnum;
int amount = req->req_amount;
struct obj_data *obj;
if (in_room)
{
for (obj = world[IN_ROOM(ch)].contents; obj; obj = obj->next_content)
{
if (GET_OBJ_VNUM(obj) == vnum)
if (--amount <= 0)
return (TRUE);
}
}
else
{
for (obj = ch->carrying; obj; obj = obj->next_content)
{
if (GET_OBJ_VNUM(obj) == vnum)
if (--amount <= 0)
return (TRUE);
}
}
return (FALSE);
}
int missing_craft_requirements(struct char_data *ch, struct craft_data *craft)
{
int missing = 0;
struct iterator_data iterator;
struct requirement_data *requirement;
obj_rnum rnum;
if (!craft->requirements->iSize)
return (-1);
for (requirement = (struct requirement_data *)merge_iterator(&iterator, craft->requirements);
requirement != NULL;
requirement = (struct requirement_data *)next_in_list(&iterator))
{
if ((rnum = real_object(requirement->req_vnum)) == NOTHING)
continue;
if (find_requirement(ch, requirement) == FALSE)
missing++;
}
remove_iterator(&iterator);
return (missing);
}
static void remove_components(struct char_data *ch, struct craft_data *craft, bool success)
{
struct iterator_data iterator;
struct requirement_data *req;
struct obj_data *obj;
int count;
for (req = (struct requirement_data *)merge_iterator(&iterator, craft->requirements);
req;
req = next_in_list(&iterator))
{
if (IS_SET(req->req_flags, REQ_FLAG_NO_REMOVE))
continue;
if (!success && IS_SET(req->req_flags, REQ_SAVE_ON_FAIL))
continue;
count = req->req_amount;
while (count)
{
if ((obj = get_object_from_requirement(ch, req)) == NULL)
break;
if (obj->in_room != NOWHERE)
{
obj_from_room(obj);
extract_obj(obj);
}
else if (obj->carried_by != NULL)
{
obj_from_char(obj);
extract_obj(obj);
}
count--;
}
}
remove_iterator(&iterator);
}
void list_all_crafts(struct char_data *ch)
{
struct craft_data *craft;
obj_vnum vnum;
if (global_craft_list->iSize > 0)
{
send_to_char(ch, "\t1Crafts:\r\n"
"\t2ID ) Name VNUM Item Name\tn\r\n");
while ((craft = (struct craft_data *)simple_list(global_craft_list)) != NULL)
{
send_to_char(ch, "\t2%-4d)\t3 %-22s -> \t1[\t2%-4d\t1] [\t2%s\t1]\tn\r\n", CRAFT_ID(craft), CRAFT_NAME(craft), CRAFT_OBJVNUM(craft),
(vnum = real_object(CRAFT_OBJVNUM(craft))) != NOWHERE ? obj_proto[vnum].short_description : "MISSING OBJECT");
}
}
else
send_to_char(ch, "There are no crafts available... use 'craftedit #' to create one.\r\n");
}
void list_available_crafts(struct char_data *ch)
{
struct craft_data *craft;
int missing, count = 0;
send_to_char(ch, "Crafts:\r\n");
if (global_craft_list->iSize > 0)
{
while ((craft = (struct craft_data *)simple_list(global_craft_list)) != NULL)
{
if (IS_SET(CRAFT_FLAGS(craft), CRAFT_RECIPE))
continue;
if (GET_SKILL(ch, CRAFT_SKILL(craft)) < CRAFT_SKILL_LEVEL(craft))
continue;
missing = missing_craft_requirements(ch, craft);
send_to_char(ch, " %d) %s%s%s\r\n", ++count, missing ? CCRED(ch, C_NRM) : CCGRN(ch, C_NRM), CRAFT_NAME(craft), CCNRM(ch, C_NRM));
}
}
if (!count)
send_to_char(ch, " You do not currently know of any crafts.\r\n");
else
send_to_char(ch, "\r\n%sAll Requirement Met %sMissing Requirements%s\r\n", CCGRN(ch, C_NRM), CCRED(ch, C_NRM), CCNRM(ch, C_NRM));
}
void show_craft(struct char_data *ch, struct craft_data *craft, int mode)
{
struct requirement_data *req;
obj_rnum rnum;
if (craft == NULL)
return;
if (!IS_SET(CRAFT_FLAGS(craft), CRAFT_RECIPE))
{
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "Craft: %s, (%d)\r\n", CRAFT_NAME(craft), CRAFT_ID(craft));
else
send_to_char(ch, "Craft: %s, (%d)\r\n", CRAFT_NAME(craft), CRAFT_ID(craft));
rnum = real_object(CRAFT_OBJVNUM(craft));
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "Makes: %s!\r\n", rnum == NOTHING ? "Nothing" : obj_proto[rnum].short_description);
else
send_to_char(ch, "Makes: %s!\r\n", rnum == NOTHING ? "Nothing" : obj_proto[rnum].short_description);
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "Time: %d\r\n", CRAFT_TIMER(craft));
else
send_to_char(ch, "Time: %d\r\n", CRAFT_TIMER(craft));
while ((req = (struct requirement_data *)simple_list(craft->requirements)) != NULL)
{
if ((rnum = real_object(req->req_vnum)) == NOWHERE)
{
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "Req: NO OBJECT! ");
else
send_to_char(ch, "Req: NO OBJECT! ");
}
else
{
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "Req: %-14s (%-2d) %s ", obj_proto[rnum].short_description, req->req_amount, IS_SET(req->req_flags, REQ_FLAG_IN_ROOM) ? "In Room" : "In Inventory");
else
send_to_char(ch, "Req: %-14s (%-2d) %s ", obj_proto[rnum].short_description, req->req_amount, IS_SET(req->req_flags, REQ_FLAG_IN_ROOM) ? "In Room" : "In Inventory");
}
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "%s\r\n", IS_SET(req->req_flags, REQ_FLAG_NO_REMOVE) ? "No Remove" : "Remove");
else
send_to_char(ch, "%s\r\n", IS_SET(req->req_flags, REQ_FLAG_NO_REMOVE) ? "No Remove" : "Remove");
}
}
else
{
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "Item: %-14s Print Id: %d\r\n", CRAFT_NAME(craft), CRAFT_ID(craft));
else
send_to_char(ch, "Item: %-14s Print Id: %d\r\n", CRAFT_NAME(craft), CRAFT_ID(craft));
rnum = real_object(CRAFT_OBJVNUM(craft));
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "These prints display in detail the how-to of creating %s.\r\n", rnum == NOTHING ? "Nothing" : obj_proto[rnum].short_description);
else
send_to_char(ch, "These prints display in detail the how-to of creating %s.\r\n", rnum == NOTHING ? "Nothing" : obj_proto[rnum].short_description);
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "Judging by the difficulty, you estimate that will take about %d seconds.\r\n", CRAFT_TIMER(craft));
else
send_to_char(ch, "Judging by the difficulty, you estimate that will take about %d seconds.\r\n", CRAFT_TIMER(craft));
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "Gazing at the requirements list, you envision what you need:\r\n");
else
send_to_char(ch, "Gazing at the requirements list, you envision what you need:\r\n");
while ((req = (struct requirement_data *)simple_list(craft->requirements)) != NULL)
{
if ((rnum = real_object(req->req_vnum)) == NOWHERE)
{
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), "Req: NO OBJECT! ");
else
send_to_char(ch, "Req: NO OBJECT! ");
}
else
{
if (mode == ITEM_STAT_MODE_G_LORE)
send_to_group(NULL, GROUP(ch), " %d, %s %s.\r\n", req->req_amount, obj_proto[rnum].short_description, IS_SET(req->req_flags, REQ_FLAG_IN_ROOM) ? "in the room" : "in your possession");
else
send_to_char(ch, " %d, %s %s.\r\n", req->req_amount, obj_proto[rnum].short_description, IS_SET(req->req_flags, REQ_FLAG_IN_ROOM) ? "in the room" : "in your possession");
}
}
}
}
EVENTFUNC(event_craft)
{
struct mud_event_data *pMudEvent;
struct craft_data *craft;
struct char_data *ch = NULL;
struct obj_data *obj;
int missing, skill, rand;
pMudEvent = (struct mud_event_data *)event_obj;
ch = (struct char_data *)pMudEvent->pStruct;
if (FIGHTING(ch))
{
send_to_char(ch, "You abort your attempt at crafting.\r\n");
return (0);
}
if (GET_POS(ch) != POS_STANDING)
{
send_to_char(ch, "You must be standing to craft.\r\n");
return (0);
}
if ((craft = get_craft_from_arg(pMudEvent->sVariables)) == NULL)
{
mudlog(CMP, LVL_STAFF, TRUE, "SYSERR: Event Craft called without craft.");
return (0);
}
if ((missing = missing_craft_requirements(ch, craft)) > 0)
{
send_to_char(ch, "You are still missing %d components.\r\n", missing);
return (0);
}
skill = GET_SKILL(ch, CRAFT_SKILL(craft));
rand = rand_number(0, (CRAFT_SKILL_LEVEL(craft) * 2));
rand = MIN(151, rand);
if (skill > rand)
{
if ((obj = read_object(CRAFT_OBJVNUM(craft), VIRTUAL)) == NULL)
{
send_to_char(ch, "You seem to have an issue with your crafting.\r\n");
mudlog(CMP, LVL_STAFF, TRUE, "SYSERR: Event Craft called without created object.");
return (0);
}
remove_components(ch, craft, TRUE);
obj_to_char(obj, ch);
if (!CRAFT_MSG_SELF(craft))
send_to_char(ch, "You have created %s.\r\n", obj->short_description);
else
act(CRAFT_MSG_SELF(craft), TRUE, ch, obj, 0, TO_CHAR);
if (CRAFT_MSG_ROOM(craft))
act(CRAFT_MSG_ROOM(craft), TRUE, ch, obj, 0, TO_NOTVICT);
}
else if (skill > (rand / 2))
{
act("You struggle in your attempt to craft, but you continue on.", TRUE, ch, 0, 0, TO_CHAR);
act("$n struggles in $s attempt to craft.", TRUE, ch, 0, 0, TO_NOTVICT);
return (CRAFT_TIMER(craft) * PASSES_PER_SEC);
}
else
{
remove_components(ch, craft, FALSE);
act("You mess up your attempt to craft.", TRUE, ch, 0, 0, TO_CHAR);
act("$n messes up $s attempt to craft.", TRUE, ch, 0, 0, TO_NOTVICT);
}
return (0);
}
ACMDU(do_craft)
{
struct craft_data *craft;
struct obj_data *obj;
int missing;
if (IS_NPC(ch))
return;
if (!*argument)
{
list_available_crafts(ch);
return;
}
if (char_has_mud_event(ch, eCRAFT))
{
send_to_char(ch, "You are already attempting to craft something.\r\n");
return;
}
skip_spaces(&argument);
if ((obj = get_obj_in_list_vis(ch, argument, NULL, ch->carrying)) == NULL ||
GET_OBJ_TYPE(obj) != ITEM_BLUEPRINT ||
(craft = get_craft_from_id(GET_OBJ_VAL(obj, 0))) == NULL)
{
if ((craft = get_craft_from_arg(argument)) == NULL || IS_SET(CRAFT_FLAGS(craft), CRAFT_RECIPE))
{
send_to_char(ch, "What are you trying to craft?\r\n");
return;
}
}
if ((missing = missing_craft_requirements(ch, craft)) > 0)
{
send_to_char(ch, "You are still missing %d components.\r\n", missing);
return;
}
/* Other Checks */
if (GET_SKILL(ch, CRAFT_SKILL(craft)) < CRAFT_SKILL_LEVEL(craft))
{
send_to_char(ch, "You aren't skilled enough in %s to craft that, you need at least %d.\r\n",
spell_info[CRAFT_SKILL(craft)].name, CRAFT_SKILL_LEVEL(craft));
return;
}
/* Activate the Event */
NEW_EVENT(eCRAFT, ch, strdup(CRAFT_NAME(craft)), CRAFT_TIMER(craft) * PASSES_PER_SEC);
act("You begin attempting to craft.", TRUE, ch, 0, 0, TO_CHAR);
act("$n is attempting to craft.", TRUE, ch, 0, 0, TO_NOTVICT);
}
/***********************************************************************
CRAFT EDITOR
**********************************************************************/
static void copy_requirement(struct requirement_data *to, struct requirement_data *from)
{
*to = *from;
}
static void copy_craft(struct craft_data *to, struct craft_data *from)
{
struct requirement_data *from_req, *to_req;
struct list_data *tmp_list;
struct iterator_data Iterator;
if (from == NULL)
return;
tmp_list = to->requirements;
*to = *from;
if (to->requirements != tmp_list)
to->requirements = tmp_list;
if (CRAFT_NAME(from))
to->craft_name = strdup(CRAFT_NAME(from));
if (CRAFT_MSG_SELF(from))
to->craft_msg_self = strdup(CRAFT_MSG_SELF(from));
if (CRAFT_MSG_ROOM(from))
to->craft_msg_room = strdup(CRAFT_MSG_ROOM(from));
if (from->requirements->iSize)
{
for (from_req = (struct requirement_data *)merge_iterator(&Iterator, from->requirements);
from_req;
from_req = next_in_list(&Iterator))
{
to_req = create_requirement();
copy_requirement(to_req, from_req);
add_to_list(to_req, to->requirements);
}
remove_iterator(&Iterator);
}
}
static void craftedit_setup_new(struct descriptor_data *d)
{
OLC_CRAFT(d) = create_craft();
CRAFT_ID(OLC_CRAFT(d)) = OLC_NUM(d);
OLC_CRAFT(d)->craft_msg_self = strdup("You craft $p.");
OLC_CRAFT(d)->craft_msg_room = strdup("$n crafts $p.");
OLC_VAL(d) = 0;
}
void craftedit_setup_existing(struct descriptor_data *d, int craft_id)
{
struct craft_data *craft;
craft = get_craft_from_id(craft_id);
/* Allocate craft in memory. */
OLC_CRAFT(d) = create_craft();
copy_craft(OLC_CRAFT(d), craft);
/* Attach new craft to player's descriptor. */
OLC_VAL(d) = 0;
}
void craftedit_save_internal(struct craft_data *craft)
{
struct craft_data *temp_craft;
if ((temp_craft = get_craft_from_id(CRAFT_ID(craft))) != NULL)
{
remove_from_list(temp_craft, global_craft_list);
free_craft(temp_craft);
}
temp_craft = create_craft();
copy_craft(temp_craft, craft);
add_to_list(temp_craft, global_craft_list);
sort_craft_list();
}
ACMD(do_oasis_craftedit)
{
struct descriptor_data *d;
int idnum;
if (!*argument)
{
send_to_char(ch, "Which craft would you like to edit?\r\n");
return;
}
if ((idnum = atoi(argument)) <= 0)
{
send_to_char(ch, "Please select a craft to edit.\r\n");
return;
}
for (d = descriptor_list; d; d = d->next)
if (STATE(d) == CON_CRAFTEDIT && d->olc && OLC_NUM(d) == idnum)
{
send_to_char(ch, "Someone is currently editing that craft.\r\n");
return;
}
/* Point d to the builder's descriptor (for easier typing later). */
d = ch->desc;
/* Give the descriptor an OLC structure. */
if (d->olc)
{
mudlog(BRF, LVL_IMMORT, TRUE,
"SYSERR: do_oasis: Player already had olc structure.");
free(d->olc);
}
CREATE(d->olc, struct oasis_olc_data, 1);
OLC_CRAFT_REQ(d) = NULL;
OLC_NUM(d) = idnum;
if (get_craft_from_id(idnum))
craftedit_setup_existing(d, idnum);
else
craftedit_setup_new(d);
craftedit_disp_menu(d);
STATE(d) = CON_CRAFTEDIT;
/* Send the OLC message to the players in the same room as the builder. */
act("$n starts using OLC.", TRUE, d->character, 0, 0, TO_ROOM);
SET_BIT_AR(PLR_FLAGS(ch), PLR_WRITING);
/* Log the OLC message. */
mudlog(CMP, LVL_IMMORT, TRUE, "OLC: %s starts editing the craft file",
GET_NAME(ch));
}
/* Display craft skill menu. */
static void craftedit_disp_skill_menu(struct descriptor_data *d)
{
int counter, columns = 0;
get_char_colors(d->character);
clear_screen(d);
for (counter = TOP_CRAFT_SKILL; counter < BOTTOM_CRAFT_SKILL; counter++)
{
if (spell_info[counter].min_level[0] == LVL_IMPL + 1) /* UNUSED */
continue;
write_to_output(d, "\t2%3d\t3) \t1%-20.20s\tn %s", counter,
spell_info[counter].name, !(++columns % 3) ? "\r\n" : "");
}
write_to_output(d, "\r\n%sEnter skill choice (-1 for none) : ", nrm);
}
/* Display craft requirement flags menu. */
static void craftedit_disp_req_flags(struct descriptor_data *d)
{
int i, count = 0, columns = 0;
char flags[MAX_STRING_LENGTH] = {'\0'};
get_char_colors(d->character);
clear_screen(d);
for (i = 0; i < NUM_REQ_FLAGS; i++)
{
write_to_output(d, "\t2%2d\t3) \t1%-20.20s\tn %s", ++count, requirement_flags[i],
!(++columns % 2) ? "\r\n" : "");
}
sprintbit(OLC_CRAFT_REQ(d)->req_flags, requirement_flags, flags, sizeof(flags));
write_to_output(d, "\r\nCurrent flags : %s\r\nEnter craft req flags (0 to quit) : ", flags);
}
/* Display craft flags menu. */
static void craftedit_disp_craft_flags(struct descriptor_data *d)
{
int i, count = 0, columns = 0;
char flags[MAX_STRING_LENGTH] = {'\0'};
get_char_colors(d->character);
clear_screen(d);
/* Mob flags has special handling to remove illegal flags from the list */
for (i = 0; i < NUM_CRAFT_FLAGS; i++)
{
write_to_output(d, "\t2%2d\t3) \t1%-20.20s\tn %s", ++count, craft_flags[i],
!(++columns % 2) ? "\r\n" : "");
}
sprintbit(CRAFT_FLAGS(OLC_CRAFT(d)), craft_flags, flags, sizeof(flags));
write_to_output(d, "\r\nCurrent flags : %s\r\nEnter craft flags (0 to quit) : ", flags);
}
static void craftedit_requirement_menu(struct descriptor_data *d)
{
struct craft_data *c = OLC_CRAFT(d);
struct requirement_data *r;
char buf[MAX_STRING_LENGTH] = {'\0'};
obj_vnum vnum;
write_to_output(d, "\t1Craft Requirements:\tn\r\n");
if (c->requirements->iSize)
{
while ((r = (struct requirement_data *)simple_list(c->requirements)) != NULL)
{
sprintbit(r->req_flags, requirement_flags, buf, sizeof(buf));
write_to_output(d, " \t2[\t3%-5d\t2]\t1)\t3 %d, %s \t2[\t3%s\t2]\tn\r\n",
r->req_vnum, r->req_amount,
((vnum = real_object(r->req_vnum)) != NOTHING) ? obj_proto[vnum].short_description : "None", buf);
}
}
else
write_to_output(d, " \t1NONE\tn\r\n");
write_to_output(d, "N) New/Edit Craft\r\nX) Delete Craft\r\nQ) Quit\r\nSelect Option: ");
OLC_MODE(d) = CRAFTEDIT_REQUIREMENTS;
}
static void craftedit_disp_menu(struct descriptor_data *d)
{
struct craft_data *c = OLC_CRAFT(d);
struct requirement_data *r;
obj_vnum vnum;
char buf[MAX_STRING_LENGTH] = {'\0'};
write_to_output(d, "\t1-- Craftedit Menu\t1 : \t2[\t3%d\t2]\tn\r\n"
"\t21\t3) Craft Name : \t1%s\tn\r\n"
"\t22\t3) Craft Timer : \t1%d seconds\tn\r\n"
"\t23\t3) Craft Item : \t1\"\tn%s\t1\"\tn\r\n"
"\t24\t3) Craft Self Msg : \t1\"\tn%s\t1\"\tn\r\n"
"\t25\t3) Craft Room Msg : \t1\"\tn%s\t1\"\tn\r\n",
CRAFT_ID(c),
CRAFT_NAME(c),
CRAFT_TIMER(c),
((vnum = real_object(CRAFT_OBJVNUM(c))) != NOTHING) ? obj_proto[vnum].short_description : "None",
CRAFT_MSG_SELF(c),
CRAFT_MSG_ROOM(c));
write_to_output(d, "\t2S\t3) Craft Skill : \t1%s \t2(\t3%d\t2)\tn\r\n", CRAFT_SKILL(c) == -1 ? "No Skill" : spell_info[CRAFT_SKILL(c)].name, CRAFT_SKILL_LEVEL(c));
sprintbit(CRAFT_FLAGS(c), craft_flags, buf, sizeof(buf));
write_to_output(d, "\t2F\t3) Flags : \t1%s\tn\r\n", buf);
write_to_output(d, "\t2R\t3) Requirements :\tn\r\n");
if (c->requirements->iSize)
{
while ((r = (struct requirement_data *)simple_list(c->requirements)) != NULL)
{
sprintbit(r->req_flags, requirement_flags, buf, sizeof(buf));
write_to_output(d, " \t2[\t3%-4d\t2] \t1%-2d, \t1\"\tn%s\t1\"\tn \t2[\t3%s\t2]\tn\r\n",
r->req_vnum, r->req_amount,
((vnum = real_object(r->req_vnum)) != NOTHING) ? obj_proto[vnum].short_description : "None", buf);
}
}
else
write_to_output(d, " \t1None\tn\r\n");
write_to_output(d, "\t2X\t3) Delete\tn\r\n"
"\t2Q\t3) Quit\tn\r\n"
"Enter choice: ");
OLC_MODE(d) = CRAFTEDIT_MENU;
}
void craftedit_parse(struct descriptor_data *d, char *arg)
{
int var;
struct requirement_data *r = NULL;
struct craft_data *craft;