-
Notifications
You must be signed in to change notification settings - Fork 0
/
grub.cpp
executable file
·1487 lines (1360 loc) · 47.6 KB
/
grub.cpp
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
/****************************************************************************
* [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame | \\._.// *
* -----------------------------------------------------------| (0...0) *
* SMAUG 1.0 (C) 1994, 1995, 1996 by Derek Snider | ).:.( *
* -----------------------------------------------------------| {o o} *
* SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus, | / ' ' \ *
* Scryn, Rennard, Swordbearer, Gorog, Grishnakh and Tricops |~'~.VxvxV.~'~*
* ------------------------------------------------------------------------ *
* Gorog's Revenge on Unruly Bastards *
****************************************************************************/
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "mud.h"
#include "connection.h"
#include "World.h"
#define MAX_DISPLAY_LINES 14000 /* Size of Sort Array */
#define MAX_NAME_LENGTH 20
#define MAX_SITE_LENGTH 40
#define MAX_FIELD_LENGTH 40
#define MAX_NUM_OPS 32
#define GR_NUM_FIELDS 12
#define GO_NUM_FIELDS 24
#define UMIN(a, b) ((a) < (b) ? (a) : (b))
typedef struct gr_struct GR_STRUCT;
typedef struct go_struct GO_STRUCT;
int itemtype_name_to_number( const char *type ); /* fun prototype for fun in build.c */
struct field_struct /* field table - info re each field */
{
char nam [MAX_FIELD_LENGTH];
bool num; /* is field numeric or char string? */
} gr_fd [GR_NUM_FIELDS], go_fd [GO_NUM_FIELDS];
struct GR_OP /* operand table - info about each operand */
{
int field;
int op;
long nval; /* value for numeric operands */
char sval [MAX_FIELD_LENGTH];
bool num; /* is field numeric or char string? */
} gr_op [MAX_NUM_OPS]; /* the above field is stored here as */
/* well as in "fields" for readability */
struct GO_OP /* operand table - info about each op */
{
int field;
int op;
short nval; /* value for numeric operands */
char sval [MAX_FIELD_LENGTH];
bool num; /* is field numeric or char string? */
} go_op [MAX_NUM_OPS];
enum gr_field_type /* enumerates the fields in the input record */
{name, sex, Class, race, level, room, gold, clan, council,
site, last, pkill};
struct gr_struct /* input record containing pfile info */
{
char name [MAX_NAME_LENGTH];
char sex;
char Class;
char race;
char level;
short room;
long gold;
char clan;
char council;
char site [MAX_SITE_LENGTH];
long last;
char pkill;
};
struct go_struct /* input record containing object data */
{
short n[22];
const char *s[2];
};
short go_wear_ext (long arg) /* extract bit set in arg ignoring pos 1 */
{
short cou;
if ( arg <= 1 ) return arg;
for (cou=1; cou<=31; cou++)
if ( arg & ( (unsigned long) 1 << cou ) ) return cou + 1;
return -1;
}
int go_strcmp( const char *astr, const char *bstr )
{
int i;
for ( ; *astr || *bstr; astr++, bstr++ )
{
i=LOWER(*astr)-LOWER(*bstr);
if ( i ) return i;
}
return 0;
}
void go_init (void)
{
int cou;
for (cou=0; cou<GO_NUM_FIELDS; cou++)
go_fd[cou].num=TRUE;
go_fd[22].num=FALSE;
go_fd[23].num=FALSE;
strcpy(go_fd[ 0].nam, "count");
strcpy(go_fd[ 1].nam, "vnum" );
strcpy(go_fd[ 2].nam, "type" );
strcpy(go_fd[ 3].nam, "level");
strcpy(go_fd[ 4].nam, "wear" );
strcpy(go_fd[ 5].nam, "avg" );
strcpy(go_fd[ 6].nam, "hr" );
strcpy(go_fd[ 7].nam, "dr" );
strcpy(go_fd[ 8].nam, "hp" );
strcpy(go_fd[ 9].nam, "mp" );
strcpy(go_fd[10].nam, "ac" );
strcpy(go_fd[11].nam, "str" );
strcpy(go_fd[12].nam, "dex" );
strcpy(go_fd[13].nam, "con" );
strcpy(go_fd[14].nam, "wis" );
strcpy(go_fd[15].nam, "int" );
strcpy(go_fd[16].nam, "luck" );
strcpy(go_fd[17].nam, "sav0" );
strcpy(go_fd[18].nam, "sav1" );
strcpy(go_fd[19].nam, "sav2" );
strcpy(go_fd[20].nam, "sav3" );
strcpy(go_fd[21].nam, "sav4" );
strcpy(go_fd[22].nam, "cname" );
strcpy(go_fd[23].nam, "name" );
}
const char *go_otype_to_disp (int arg)
{
if ( arg==ITEM_LIGHT ) return "lt";
if ( arg==ITEM_SCROLL ) return "sc";
if ( arg==ITEM_WAND ) return "wa";
if ( arg==ITEM_STAFF ) return "st";
if ( arg==ITEM_WEAPON ) return "wp";
if ( arg==ITEM_ARMOR ) return "ar";
if ( arg==ITEM_POTION ) return "po";
if ( arg==ITEM_CONTAINER ) return "cn";
if ( arg==ITEM_POTION ) return "po";
if ( arg==ITEM_NOTE ) return "no";
if ( arg==ITEM_KEY ) return "ky";
if ( arg==ITEM_FOOD ) return "fo";
if ( arg==ITEM_CORPSE_PC ) return "pc";
if ( arg==ITEM_CORPSE_NPC) return "mc";
if ( arg==ITEM_PILL ) return "pi";
if ( arg==ITEM_BOOK ) return "bk";
return NULL;
}
char *owear_to_disp (short arg)
{
static char owear_disp[20][3] =
{ "??", "ta", "fi", "ne", "bo", "he", "le", "fe", "ha", "ar",
"sh", "ab", "wa", "wr", "wi", "ho", "du", "ea", "ey", "mi" };
arg = ( arg<0 || arg>20 ) ? 0 : arg;
return owear_disp[ arg ];
}
int owear_to_num (char *arg)
{
if ( !strcmp( arg, "take" ) ) return 1;
if ( !strcmp( arg, "finger" ) ) return 2;
if ( !strcmp( arg, "neck" ) ) return 3;
if ( !strcmp( arg, "body" ) ) return 4;
if ( !strcmp( arg, "head" ) ) return 5;
if ( !strcmp( arg, "legs" ) ) return 6;
if ( !strcmp( arg, "feet" ) ) return 7;
if ( !strcmp( arg, "hands" ) ) return 8;
if ( !strcmp( arg, "arms" ) ) return 9;
if ( !strcmp( arg, "shield" ) ) return 10;
if ( !strcmp( arg, "about" ) ) return 11;
if ( !strcmp( arg, "waist" ) ) return 12;
if ( !strcmp( arg, "wrist" ) ) return 13;
if ( !strcmp( arg, "wield" ) ) return 14;
if ( !strcmp( arg, "hold" ) ) return 15;
if ( !strcmp( arg, "dual" ) ) return 16;
if ( !strcmp( arg, "ears" ) ) return 17;
if ( !strcmp( arg, "eyes" ) ) return 18;
if ( !strcmp( arg, "missile" ) ) return 19;
return 0;
}
int go_fnam_to_num ( char *arg )
{
int cou;
for (cou=0; cou<GO_NUM_FIELDS; cou++)
if ( !strcmp(arg, go_fd[cou].nam) )
return cou;
return -1;
}
/*
* Generalized sort function.
* Sorts either ascending or descending.
* Sorts an array containing either numbers or strings.
* 1st parm is a pointer to an array of structures.
* 2nd parm indicates the starting position within the record
* 3rd parm indicates the first record in the sort range
* 4th parm indicates the last record in the sort range
* e.g. the array may contain 100 records but we may wish to sort
* only the first fifty.
* 5th parm is n_s - number/string - TRUE is number - FALSE is string
* 6th parm is direction - TRUE is ascending - FALSE is descending
*/
void go_sort( CHAR_DATA *ch, GO_STRUCT **p,
int ind, int left, int right, bool n_s, bool sor_dir )
{
GO_STRUCT *swap;
int i=left, j=right, testn;
static char tests[ MAX_STRING_LENGTH ];
if ( left < 0 || left >= right ) return;
right = UMIN(right, MAX_DISPLAY_LINES - 1);
if ( n_s )
testn = p[left]->n[ind];
else
strcpy( tests, p[left]->s[ind] );
do
{
if ( n_s )
{
if ( sor_dir )
while (p[i]->n[ind] < testn) i++;
else
while (p[i]->n[ind] > testn) i++;
if ( sor_dir )
while (testn < p[j]->n[ind]) j--;
else
while (testn > p[j]->n[ind]) j--;
}
else
{
if ( sor_dir )
while ( strcmp( p[i]->s[ind], tests) < 0 ) i++;
else
while ( strcmp( p[i]->s[ind], tests) > 0 ) i++;
if ( sor_dir )
while ( strcmp( tests, p[j]->s[ind]) < 0 ) j--;
else
while ( strcmp( tests, p[j]->s[ind]) > 0 ) j--;
}
if (i <= j) { swap=p[i]; p[i] = p[j]; p[j] = swap; i++; j--; }
} while (i <= j);
if (left < j) go_sort (ch, p, ind, left, j, n_s, sor_dir );
if (i < right) go_sort (ch, p, ind, i, right, n_s, sor_dir );
}
void go_accum_aff (GO_STRUCT *r, int loc, int mod)
{
enum {OCOUNT, OVNUM, OTYPE, OLEVEL, OWEAR, OAVG, OHR, ODR, OHP, OMP, OAC,
OSTR, ODEX, OCON, OWIS, OINT, OLUCK,
OSAV0, OSAV1, OSAV2, OSAV3, OSAV4};
switch (loc)
{
case APPLY_HITROLL : {r->n[OHR] += mod; break;}
case APPLY_DAMROLL : {r->n[ODR] += mod; break;}
case APPLY_HIT : {r->n[OHP] += mod; break;}
case APPLY_MANA : {r->n[OMP] += mod; break;}
case APPLY_AC : {r->n[OAC] += mod; break;}
case APPLY_STR : {r->n[OSTR] += mod; break;}
case APPLY_DEX : {r->n[ODEX] += mod; break;}
case APPLY_CON : {r->n[OCON] += mod; break;}
case APPLY_WIS : {r->n[OWIS] += mod; break;}
case APPLY_INT : {r->n[OINT] += mod; break;}
case APPLY_LCK : {r->n[OLUCK]+= mod; break;}
case APPLY_SAVING_POISON : {r->n[OSAV0]+= mod; break;}
case APPLY_SAVING_ROD : {r->n[OSAV1]+= mod; break;}
case APPLY_SAVING_PARA : {r->n[OSAV2]+= mod; break;}
case APPLY_SAVING_BREATH : {r->n[OSAV3]+= mod; break;}
case APPLY_SAVING_SPELL : {r->n[OSAV4]+= mod; break;}
}
}
void display_operand_table (CHAR_DATA *ch, int op_num)
{
int cou;
char opn[10][3] = {"eq", "ne", "su", "ge", "gt", "le", "lt", "[=", "]=", "|="};
pager_printf (ch, "OPERAND TABLE\n\r");
for(cou=0; cou < op_num; cou++)
if ( go_op[cou].num)
pager_printf (ch,
"%2d %-7s %2s %10ld\n\r", cou+1, go_fd[go_op[cou].field].nam,
opn[go_op[cou].op], go_op[cou].nval);
else
pager_printf (ch, "%2d %-7s %2s %s\n\r",
cou+1, go_fd[go_op[cou].field].nam,
opn[go_op[cou].op], go_op[cou].sval);
}
/*
* Store operand's operator and value in operand table.
*/
bool go_parse_operator (CHAR_DATA *ch, char *pch, int *op_num)
{
enum op_type {EQ, NE, SU, GE, GT, LE, LT, BO, EO, IN};
enum {OCOUNT, OVNUM, OTYPE, OLEVEL, OWEAR, OAVG, OHR, ODR, OHP, OMP, OAC,
OSTR, ODEX, OCON, OWIS, OINT, OLUCK,
OSAV0, OSAV1, OSAV2, OSAV3, OSAV4};
int cou;
char opstr [10][3] = { "=", "!=", "<>", ">=", ">", "<=", "<", "[", "]", "|" };
go_op[*op_num].op = -1;
for (cou=0; cou<10; cou++)
if ( !str_prefix(opstr[cou], pch) )
{
go_op[*op_num].op = cou;
break;
}
if ( go_op[*op_num].op < 0 )
{pager_printf(ch, "Invalid operator: %s\n\r", pch); return FALSE;}
if ( go_op[*op_num].op==EQ || go_op[*op_num].op==GT
|| go_op[*op_num].op==LT || go_op[*op_num].op==BO
|| go_op[*op_num].op==EO || go_op[*op_num].op==IN
)
pch++;
else pch+=2; /* advance to operand value */
if ( *pch=='\0' )
{pager_printf(ch, "Value is missing from operand.\n\r"); return FALSE;}
if ( go_fd[ go_op[ *op_num ].field ].num )
{
go_op[*op_num].num = TRUE;
if ( isdigit(*pch) ) /* user entered number */
go_op[*op_num].nval = atoi ( pch );
else
if ( go_op[*op_num].field == OTYPE )
go_op[*op_num].nval = itemtype_name_to_number( pch ); /* user entered token */
else
if ( go_op[*op_num].field == OWEAR )
go_op[*op_num].nval = owear_to_num( pch ); /* user entered token */
}
else
{
go_op[*op_num].num = FALSE;
if ( strlen(pch) > MAX_FIELD_LENGTH )
{
pager_printf(ch, "Char string is too long:%s\n\r", pch);
return FALSE;
}
strcpy ( go_op[*op_num].sval, pch ); /* store str value in table */
}
(*op_num)++; /* operand now stored in table */
return TRUE;
}
/*
* Store operand's field name in the operand table.
*/
bool go_parse_operand (CHAR_DATA *ch, char *arg, int *op_num, int *sor_ind,
bool *sor_dir, bool *or_sw, bool *np_sw, bool *nm_sw, bool *ng_sw,
bool *do_sw, bool *d2_sw)
{
int cou;
char *pch;
if ( !strcmp(arg, "or" ) ) return *or_sw = TRUE;
if ( !strcmp(arg, "np" ) ) return *np_sw = TRUE;
if ( !strcmp(arg, "nm" ) ) return *nm_sw = TRUE;
if ( !strcmp(arg, "ng" ) ) return *ng_sw = TRUE;
if ( !strcmp(arg, "do" ) ) return *do_sw = TRUE;
if ( !strcmp(arg, "d2" ) ) return *d2_sw = TRUE;
if ( arg[0]=='+' || arg[0]=='-')
{
*sor_dir = (arg[0]=='+') ? TRUE : FALSE;
pch = arg + 1;
if ( pch[0] == '\0')
{
pager_printf(ch, "Sorry. Missing sort field: %s\n\r", arg);
return FALSE;
}
if ( (*sor_ind = go_fnam_to_num(pch)) == -1 )
{
pager_printf(ch, "Sorry. Invalid sort field: %s\n\r", arg);
return FALSE;
}
return TRUE;
}
for (cou=0; cou<GO_NUM_FIELDS; cou++) /* check field name */
if ( !str_prefix( go_fd[cou].nam, arg ) )
{
arg += strlen( go_fd[cou].nam ); /* advance to operator */
go_op[ *op_num ].field = cou;
/* store field enum */
if ( !go_parse_operator (ch, arg, op_num) )
return FALSE;
return TRUE;
}
pager_printf(ch, "Sorry. Invalid field name: %s\n\r", arg);
return FALSE;
}
/*
* Evaluate one string criteria
*/
bool go_eval_str (const char *lval, int op, const char *rval)
{
enum op_type {EQ, NE, SU, GE, GT, LE, LT, BO, EO, IN};
switch (op)
{
case EQ: if ( !str_cmp(lval, rval) ) return TRUE;
else return FALSE;
case NE: if ( str_cmp(lval, rval) ) return TRUE;
else return FALSE;
case GT: if ( go_strcmp(lval, rval) > 0 ) return TRUE;
else return FALSE;
case GE: if ( go_strcmp(lval, rval) >= 0 ) return TRUE;
else return FALSE;
case LT: if ( go_strcmp(lval, rval) < 0 ) return TRUE;
else return FALSE;
case LE: if ( go_strcmp(lval, rval) <= 0 ) return TRUE;
else return FALSE;
case BO: if ( !str_prefix(rval, lval) ) return TRUE;
else return FALSE;
case EO: if ( !str_suffix(rval, lval) ) return TRUE;
else return FALSE;
case IN: if ( !str_infix(rval, lval) ) return TRUE;
else return FALSE;
case SU: if ( strstr(lval, rval) ) return TRUE;
else return FALSE;
}
return FALSE;
}
/*
* Evaluate one numeric criteria
*/
bool go_eval_num (long lval, int op, long rval)
{
enum op_type {EQ, NE, SU, GE, GT, LE, LT};
switch (op)
{
case EQ: return lval == rval;
case NE: return lval != rval;
case GE: return lval >= rval;
case GT: return lval > rval;
case LE: return lval <= rval;
case LT: return lval < rval;
default: return FALSE;
}
}
/*
* Evaluate one input record to see if it matches all search criteria
*/
bool go_eval_and (CHAR_DATA *ch, GO_STRUCT *r, int op_num)
{
enum {OCOUNT, OVNUM, OTYPE, OLEVEL, OWEAR, OAVG, OHR, ODR, OHP, OMP, OAC,
OSTR, ODEX, OCON, OWIS, OINT, OLUCK,
OSAV0, OSAV1, OSAV2, OSAV3, OSAV4};
int cou;
for (cou=0; cou<op_num; cou++)
{
if ( go_op[cou].field <= OSAV4 )
{
if ( !go_eval_num
(r->n[go_op[cou].field], go_op[cou].op, go_op[cou].nval) )
return FALSE;
else continue;
}
else
{
if ( !go_eval_str(
r->s[go_op[cou].field-OSAV4-1], go_op[cou].op,
go_op[cou].sval) )
return FALSE;
else continue;
}
}
return TRUE;
}
/*
* Evaluate one input record to see if it matches any search criteria
*/
bool go_eval_or (CHAR_DATA *ch, GO_STRUCT *r, int op_num)
{
enum {OCOUNT, OVNUM, OTYPE, OLEVEL, OWEAR, OAVG, OHR, ODR, OHP, OMP, OAC,
OSTR, ODEX, OCON, OWIS, OINT, OLUCK,
OSAV0, OSAV1, OSAV2, OSAV3, OSAV4};
int cou;
for (cou=0; cou<op_num; cou++)
{
if ( go_op[cou].field <= OSAV4 )
{
if ( go_eval_num( r->n[ go_op[cou].field ], go_op[cou].op,
go_op[cou].nval ) )
return TRUE;
else continue;
}
else
{
if ( go_eval_str( r->s[go_op[cou].field-OSAV4-1], go_op[cou].op,
go_op[cou].sval) )
return TRUE;
else continue;
}
}
return FALSE;
}
void go_display( CHAR_DATA *ch, int dis_num, int tot_match, bool d2_sw,
GO_STRUCT **p)
{
enum {OCOUNT, OVNUM, OTYPE, OLEVEL, OWEAR, OAVG, OHR, ODR, OHP, OMP, OAC,
OSTR, ODEX, OCON, OWIS, OINT, OLUCK,
OSAV0, OSAV1, OSAV2, OSAV3, OSAV4};
enum {CNAME, ONAME};
GO_STRUCT r;
int cou, lim;
char pri_cname[MAX_NAME_LENGTH];
char pri_oname[MAX_NAME_LENGTH];
if ( tot_match > 0 && dis_num > 0 ) /* print title if app */
{
if ( !d2_sw )
pager_printf(ch,
"\n\r%-12s%3s %5s %2s %-12s %2s %2s %2s %2s %2s %3s %3s %3s "
"%11s\n\r",
"Character", "Cou", "OVnum", "Lv", "OName", "Ty", "We",
"Av", "Hr", "Dr", "Hp", "Mp", "AC", "S D C W I L");
else
pager_printf(ch,
"\n\r%-12s%3s %5s %2s %-12s %2s %2s %2s %2s %2s %3s %3s %2s "
"%2s %2s %2s %2s\n\r",
"Character", "Cou", "OVnum", "Lv", "OName", "Ty", "We",
"Av", "Hr", "Dr", "Hp", "Mp", "S0", "S1", "S2", "S3", "S4");
}
lim = UMIN(tot_match, dis_num);
for ( cou=0; cou<lim; cou++)
{
r = *p[cou];
strncpy( pri_cname, r.s[CNAME], MAX_NAME_LENGTH - 1);
pri_cname[ MAX_NAME_LENGTH - 1] = '\0';
strncpy( pri_oname, r.s[ONAME], MAX_NAME_LENGTH - 1);
pri_oname[ MAX_NAME_LENGTH - 1] = '\0';
if ( !d2_sw )
pager_printf(ch,
"%-12s%3d %5d%3d %-12s %2s %2s%3d%3d%3d%4d%4d%4d"
"%2d%2d%2d%2d%2d%2d\n\r",
pri_cname, r.n[OCOUNT], r.n[OVNUM], r.n[OLEVEL],
pri_oname, go_otype_to_disp( r.n[OTYPE] ),
owear_to_disp( r.n[OWEAR] ),
r.n[OAVG], r.n[OHR], r.n[ODR],
r.n[OHP], r.n[OMP], r.n[OAC], r.n[OSTR], r.n[ODEX],
r.n[OCON], r.n[OWIS], r.n[OINT], r.n[OLUCK]);
else
pager_printf(ch,
"%-12s%3d %5d%3d %-12s %2s %2s%3d%3d%3d%4d%4d%3d"
"%3d%3d%3d%3d\n\r",
pri_cname, r.n[OCOUNT], r.n[OVNUM], r.n[OLEVEL],
pri_oname, go_otype_to_disp( r.n[OTYPE] ),
owear_to_disp( r.n[OWEAR] ),
r.n[OAVG], r.n[OHR], r.n[ODR],
r.n[OHP], r.n[OMP], r.n[OSAV0], r.n[OSAV1], r.n[OSAV2],
r.n[OSAV3], r.n[OSAV4]);
}
if (tot_match == 0 )
pager_printf(ch, "Zero matches were found.\n\r");
else pager_printf(ch,
"%5d matches in total.\n\r", tot_match);
}
/*
* Find the name of the character and object and place in record
* The name of the object is easy ... but the name of the character
* proved to be one of the most difficult and frustrating aspects ot
* this function. F.Y.I - if an object is not "carried_by" someone,
* it could be on the ground ... but ... growl ... it could also be
* in a container carried by someone - or in a container on the ground.
*/
bool go_read_names( CHAR_DATA *ch, OBJ_DATA *po, GO_STRUCT *r, bool np_sw,
bool nm_sw, bool ng_sw )
{
enum {CNAME, ONAME};
OBJ_DATA *pt;
const char *ground = "(none)";
const char *ack = "(error in data structure)";
r->s[ONAME] = ( po->name_.length() > 0 ) ? po->name_.c_str() : ack; /* set object name */
if ( po->GetCarriedBy() ) /* it's being carried by a char */
{
if ( get_trust(ch) < po->GetCarriedBy()->level ) return FALSE;
if ( nm_sw && IS_NPC(po->GetCarriedBy()) ) return FALSE;
if ( np_sw && !IS_NPC(po->GetCarriedBy()) ) return FALSE;
r->s[CNAME] = po->GetCarriedBy()->getName().c_str();
}
else if ( po->GetInObj() != 0 ) /* it's in a container */
{
pt = po;
while( pt->GetInObj() )
pt=pt->GetInObj();
if ( pt->GetCarriedBy() && get_trust(ch) < pt->GetCarriedBy()->level )
return FALSE;
if ( pt->GetCarriedBy() && nm_sw && IS_NPC(pt->GetCarriedBy()) )
return FALSE;
if ( pt->GetCarriedBy() && np_sw && !IS_NPC(pt->GetCarriedBy()) )
return FALSE;
if ( pt->GetCarriedBy() ) r->s[CNAME] = pt->GetCarriedBy()->getName().c_str();
else
{
if ( ng_sw ) return FALSE;
r->s[CNAME] = ground;
}
}
else if ( !po->GetInObj() ) /* it's on the ground */
{
if ( ng_sw ) return FALSE;
r->s[CNAME] = ground;
}
return TRUE;
}
bool go_read( CHAR_DATA *ch, int dis_num, int op_num, int sor_ind,
bool sor_dir, bool or_sw, bool np_sw, bool nm_sw, bool ng_sw,
bool d2_sw )
{
enum {OCOUNT, OVNUM, OTYPE, OLEVEL, OWEAR, OAVG, OHR, ODR, OHP, OMP, OAC,
OSTR, ODEX, OCON, OWIS, OINT, OLUCK,
OSAV0, OSAV1, OSAV2, OSAV3, OSAV4};
OBJ_INDEX_DATA *px;
OBJ_DATA *po;
AFFECT_DATA *pa;
GO_STRUCT r; /* input (physical record) */
GO_STRUCT a[MAX_DISPLAY_LINES]; /* array of records */
GO_STRUCT *p[MAX_DISPLAY_LINES]; /* array of pointers to records */
bool ok_otype [255]; /* we want to process these otypes */
int tot_match = 0; /* total records matched */
bool res; /* result of a boolean exp */
int ind; /* indicates the sort field */
memset(ok_otype, 0, sizeof ok_otype);
ok_otype[ITEM_LIGHT] = ok_otype[ITEM_WAND] = ok_otype[ITEM_KEY] =
ok_otype[ITEM_STAFF] = ok_otype[ITEM_WEAPON] = ok_otype[ITEM_ARMOR] =
ok_otype[ITEM_CONTAINER] = ok_otype[ITEM_DRINK_CON] = TRUE;
for (po=first_object; po; po=po->next) /* Loop through all objects */
{
if ( !ok_otype[po->item_type] ) /* don't process useless stuff*/
continue;
memset(&r, 0, sizeof r);
if ( !go_read_names( ch, po, &r, np_sw, nm_sw, ng_sw ) )
continue;
px = po->pIndexData;
r.n[OCOUNT] = po->count;
r.n[OVNUM] = px->vnum;
r.n[OTYPE] = po->item_type;
#ifdef USE_OBJECT_LEVELS
r.n[OLEVEL] = po->level;
#else
r.n[OLEVEL] = 0;
#endif
r.n[OWEAR] = go_wear_ext( po->wear_flags );
r.n[OAVG] = (po->item_type == ITEM_WEAPON) ?
(po->value[1] + po->value[2])/2 : 0;
for (pa=px->first_affect; pa; pa=pa->next)
go_accum_aff (&r, pa->location, pa->modifier);
for (pa=po->first_affect; pa; pa=pa->next)
go_accum_aff (&r, pa->location, pa->modifier);
res = or_sw ? go_eval_or(ch, &r, op_num) : go_eval_and(ch, &r, op_num);
if ( res ) /* record is a match */
{
if ( dis_num > 0 && tot_match < MAX_DISPLAY_LINES )
{
a[ tot_match ] = r;
p[ tot_match ] = &a[ tot_match ];
}
tot_match++;
}
}
ind = ( sor_ind<=OSAV4 ) ? sor_ind : sor_ind - OSAV4 - 1;
if ( tot_match > 1 && dis_num > 0 )
go_sort( ch, p, ind, 0, UMIN((tot_match - 1), MAX_DISPLAY_LINES - 1),
( sor_ind <= OSAV4 ), sor_dir );
go_display( ch, dis_num, tot_match, d2_sw, p );
return TRUE;
}
/*
The following code is intended to replace the static arrays "a" and "p"
with dynamically allocated ones. But I'm confused as to why. If the
user asks to display 10 lines, but selects 10,000 ... then the arrays
must be allocated to hold 10,000 so that they may be sorted. Once they
are sorted, we display only 10 - but - that don't change the fact that
we have to sort all 10,000 - sigh - arg! - Gorog
GO_STRUCT *a;
GO_STRUCT **p;
a = (GO_STRUCT *) calloc( UMIN(dis_num, MAX_DISPLAY_LINES), sizeof *a);
if (!a)
{
pager_printf(ch, "Sorry. There is currently insufficient memory avail"
" to service your request. Try later or speak to a coder.\n\r");
return FALSE;
}
p = (GO_STRUCT **) calloc( UMIN(dis_num, MAX_DISPLAY_LINES), sizeof *p);
if (!p)
{
pager_printf(ch, "Sorry. There is currently insufficient memory avail"
" to service your request. Try later or speak to a coder.\n\r");
return FALSE;
}
free(p); free(a);
*/
void do_ogrub(CHAR_DATA *ch, const char* argument)
{
enum {OCOUNT, OVNUM, OTYPE, OLEVEL, OWEAR, OAVG, OHR, ODR, OHP, OMP, OAC,
OSTR, ODEX, OCON, OWIS, OINT, OLUCK,
OSAV0, OSAV1, OSAV2, OSAV3, OSAV4};
char arg1[MAX_STRING_LENGTH];
int dis_num; /* display lines requested */
int op_num = 0; /* num of operands on cmd line */
int sor_ind = OVNUM; /* sort indicator */
bool or_sw = FALSE; /* or search criteria */
bool sor_dir = 1; /* sort indicator */
bool np_sw = FALSE; /* no players */
bool nm_sw = FALSE; /* no mobs */
bool ng_sw = FALSE; /* no ground objs */
bool do_sw = FALSE; /* display operand table */
bool d2_sw = FALSE; /* alternate display format */
go_init(); /* initialize data structures */
argument = one_argument (argument, arg1);
if ( !*arg1 )
{
pager_printf(ch, "Please type HELP OGRUB for info on OGRUB.\n\r");
return;
}
if ( isdigit(*arg1) ) /* first arg is number of display lines */
dis_num = atoi(arg1);
else
{
pager_printf(ch, "You did not specify the number of display lines.\n\r");
return;
}
if ( dis_num > MAX_DISPLAY_LINES )
{
pager_printf(ch, "Sorry. You have requested more than %d display "
"lines.\n\r", MAX_DISPLAY_LINES);
return;
}
argument = one_argument (argument, arg1);
while ( *arg1 ) /* build the operand table */
{
if ( op_num >= MAX_NUM_OPS )
{
pager_printf(ch, "Sorry. You have entered more than %d operands.\n\r",
MAX_NUM_OPS, MAX_NUM_OPS );
return;
}
if ( !go_parse_operand (ch, arg1, &op_num, &sor_ind, &sor_dir,
&or_sw, &np_sw, &nm_sw, &ng_sw, &do_sw, &d2_sw ) )
return;
argument = one_argument (argument, arg1);
}
if (op_num <= 0)
{
pager_printf(ch, "Sorry. You did not include any valid operands.\n\r");
return;
}
if ( do_sw )
display_operand_table (ch, op_num);
if ( !go_read(ch, dis_num, op_num, sor_ind, /* future expansion*/
sor_dir, or_sw, np_sw, nm_sw, ng_sw, d2_sw) )
return;
}
char *gr_strc (char c) /* convert a char to a str */
{
static char s[2] = "s";
s[0]=c;
return s;
}
/*
* Evaluate one input record to see if it matches all search criteria
*/
bool gr_eval_and (GR_STRUCT r, int op_num)
{
int cou;
for (cou=0; cou<op_num; cou++)
{
switch (gr_op[cou].field)
{
case name:
if ( !go_eval_str (r.name, gr_op[cou].op, gr_op[cou].sval) )
return FALSE;
else break;
case sex:
if ( !go_eval_num (r.sex, gr_op[cou].op, gr_op[cou].nval) )
return FALSE;
else break;
case Class:
if ( !go_eval_num (r.Class, gr_op[cou].op, gr_op[cou].nval) )
return FALSE;
else break;
case race:
if ( !go_eval_num (r.race, gr_op[cou].op, gr_op[cou].nval) )
return FALSE;
else break;
case level:
if ( !go_eval_num (r.level, gr_op[cou].op, gr_op[cou].nval) )
return FALSE;
else break;
case room:
if ( !go_eval_num (r.room, gr_op[cou].op, gr_op[cou].nval) )
return FALSE;
else break;
case gold:
if ( !go_eval_num (r.gold, gr_op[cou].op, gr_op[cou].nval) )
return FALSE;
else break;
case clan:
if ( !go_eval_num (r.clan, gr_op[cou].op, gr_op[cou].nval) )
return FALSE;
else break;
case council:
if ( !go_eval_num (r.council, gr_op[cou].op, gr_op[cou].nval) )
return FALSE;
else break;
case site:
if ( !go_eval_str (r.site, gr_op[cou].op, gr_op[cou].sval) )
return FALSE;
else break;
case last:
if ( !go_eval_num (r.last, gr_op[cou].op, gr_op[cou].nval) )
return FALSE;
else break;
case pkill:
if ( !go_eval_str (gr_strc(r.pkill), gr_op[cou].op, gr_op[cou].sval) )
return FALSE;
else break;
}
}
return TRUE;
}
/*
* Evaluate one input record to see if it matches any search criteria
*/
bool gr_eval_or (GR_STRUCT r, int op_num)
{
int cou;
for (cou=0; cou<op_num; cou++)
{
switch (gr_op[cou].field)
{
case name:
if ( go_eval_str (r.name, gr_op[cou].op, gr_op[cou].sval) )
return TRUE;
else break;
case sex:
if ( go_eval_num (r.sex, gr_op[cou].op, gr_op[cou].nval) )
return TRUE;
else break;
case Class:
if ( go_eval_num (r.Class, gr_op[cou].op, gr_op[cou].nval) )
return TRUE;
else break;
case race:
if ( go_eval_num (r.race, gr_op[cou].op, gr_op[cou].nval) )
return TRUE;
else break;
case level:
if ( go_eval_num (r.level, gr_op[cou].op, gr_op[cou].nval) )
return TRUE;
else break;
case room:
if ( go_eval_num (r.room, gr_op[cou].op, gr_op[cou].nval) )
return TRUE;
else break;
case gold:
if ( go_eval_num (r.gold, gr_op[cou].op, gr_op[cou].nval) )
return TRUE;
else break;
case clan:
if ( go_eval_num (r.clan, gr_op[cou].op, gr_op[cou].nval) )
return TRUE;
else break;
case council:
if ( go_eval_num (r.council, gr_op[cou].op, gr_op[cou].nval) )
return TRUE;
else break;
case site:
if ( go_eval_str (r.site, gr_op[cou].op, gr_op[cou].sval) )
return TRUE;
else break;
case last:
if ( go_eval_num (r.last, gr_op[cou].op, gr_op[cou].nval) )
return TRUE;
else break;
case pkill:
if ( go_eval_str (gr_strc(r.pkill), gr_op[cou].op, gr_op[cou].sval) )
return TRUE;
else break;
}
}
return FALSE;
}
void gr_init (void)
{
strcpy(gr_fd[ 0].nam, "name" ); gr_fd[0].num=FALSE;
strcpy(gr_fd[ 1].nam, "sex" ); gr_fd[ 1].num=TRUE;
strcpy(gr_fd[ 2].nam, "class" ); gr_fd[ 2].num=TRUE;
strcpy(gr_fd[ 3].nam, "race" ); gr_fd[ 3].num=TRUE;
strcpy(gr_fd[ 4].nam, "level" ); gr_fd[ 4].num=TRUE;
strcpy(gr_fd[ 5].nam, "room" ); gr_fd[ 5].num=TRUE;
strcpy(gr_fd[ 6].nam, "gold" ); gr_fd[ 6].num=TRUE;
strcpy(gr_fd[ 7].nam, "clan" ); gr_fd[ 7].num=TRUE;
strcpy(gr_fd[ 8].nam, "council"); gr_fd[ 8].num=TRUE;
strcpy(gr_fd[ 9].nam, "site" ); gr_fd[ 9].num=FALSE;
strcpy(gr_fd[10].nam, "last" ); gr_fd[10].num=TRUE;
strcpy(gr_fd[11].nam, "pkill" ); gr_fd[11].num=FALSE;
}
/*
* Store operand's operator and value in operand table.
*/
bool gr_parse_operator (CHAR_DATA *ch, char *pch, int *op_num)
{
enum op_type {EQ, NE, SU, GE, GT, LE, LT, BO, EO, IN};
int cou;
char opstr [10][3] = { "=", "!=", "<>", ">=", ">", "<=", "<", "[", "]", "|" };
gr_op[*op_num].op = -1;
for (cou=0; cou<10; cou++)
if ( !str_prefix(opstr[cou], pch) )
{
gr_op[*op_num].op = cou;
break;
}
if ( gr_op[*op_num].op < 0 )
{printf("Invalid operator: %s\n\r", pch); return FALSE;}
if ( gr_op[*op_num].op==EQ || gr_op[*op_num].op==LT
|| gr_op[*op_num].op==GT || gr_op[*op_num].op==BO
|| gr_op[*op_num].op==EO || gr_op[*op_num].op==IN)
pch++;
else pch+=2; /* advance to operand value */
if ( *pch=='\0' )
{ch_printf(ch, "Value is missing from operand.\n\r"); return FALSE;}
if ( gr_fd[gr_op[*op_num].field].num )
{
gr_op[*op_num].num = TRUE;
gr_op[*op_num].nval = atol (pch); /* store num operand value in table */
}
else
{
if ( strlen(pch) > MAX_FIELD_LENGTH )
{ch_printf(ch, "Char string is too long:%s\n\r", pch); return FALSE;}
gr_op[*op_num].num = FALSE;
strcpy (gr_op[*op_num].sval, pch); /* store str operand value in table */
}
(*op_num)++; /* operand now stored in table */
return TRUE;
}
/*
* Store operand's field name in the operand table.
*/
bool gr_parse_operand (CHAR_DATA *ch, char *arg, bool *or_sw, int *op_num)
{
int cou;