-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmud_prog.cpp
executable file
·4185 lines (3663 loc) · 98.1 KB
/
mud_prog.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.~'~*
****************************************************************************
* The MUDprograms are heavily based on the original MOBprogram code that *
* was written by N'Atas-ha. *
* Much has been added, including the capability to put a "program" on *
* rooms and objects, not to mention many more triggers and ifchecks, as *
* well as "script" support. *
* *
* Error reporting has been changed to specify whether the offending *
* program is on a mob, a room or and object, along with the vnum. *
* *
* Mudprog parsing has been rewritten (in mprog_driver). Mprog_process_if *
* and mprog_process_cmnd have been removed, mprog_do_command is new. *
* Full support for nested ifs is in. *
****************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "globals.h"
#include "mud.h"
#include "commands.h"
#include "World.h"
int fcontinue_after_command; /* for command triggers */
bool bMpwalkSuccess;
bool MOBtrigger; // moved here from mud.h by Ksilyan
/* Defines by Narn for new mudprog parsing, used as
return values from mprog_do_command. */
#define COMMANDOK 1
#define IFTRUE 2
#define IFFALSE 3
#define ORTRUE 4
#define ORFALSE 5
#define FOUNDELSE 6
#define FOUNDENDIF 7
#define IFIGNORED 8
#define ORIGNORED 9
#define ANDTRUE 10
#define ANDFALSE 11
/* Ifstate defines, used to create and access ifstate array
in mprog_driver. */
#define MAX_IFS 20 /* should always be generous */
#define IN_IF 0
#define IN_ELSE 1
#define DO_IF 2
#define DO_ELSE 3
#define MAX_PROG_NEST 20
int mprog_do_command( char *cmnd, CHAR_DATA *mob, CHAR_DATA *actor,
OBJ_DATA *obj, void *vo, CHAR_DATA *rndm,
bool ignore, bool ignore_ors );
/*
* Mudprogram additions
*/
CHAR_DATA *supermob;
struct act_prog_data *room_act_list;
struct act_prog_data *obj_act_list;
struct act_prog_data *mob_act_list;
/*
* Local function prototypes
*/
char * mprog_next_command ( char* clist ) ;
bool mprog_seval ( const char* lhs, char* opr, char* rhs,
CHAR_DATA *mob );
bool mprog_veval ( int lhs, char* opr, int rhs,
CHAR_DATA *mob );
int mprog_do_ifcheck ( char* ifcheck, CHAR_DATA* mob,
CHAR_DATA* actor, OBJ_DATA* obj,
void* vo, CHAR_DATA* rndm );
void mprog_translate ( char ch, char* t, CHAR_DATA* mob,
CHAR_DATA* actor, OBJ_DATA* obj,
void* vo, CHAR_DATA* rndm );
void mprog_driver ( char* com_list, CHAR_DATA* mob,
CHAR_DATA* actor, OBJ_DATA* obj,
void* vo, bool single_step );
bool mprog_keyword_check ( const char *argu, const char *argl ) ;
void oprog_wordlist_check( const char *arg, CHAR_DATA *mob, CHAR_DATA *actor, OBJ_DATA *obj, void *vo, int64 type, OBJ_DATA *iobj );
void set_supermob(OBJ_DATA *obj);
bool oprog_percent_check( CHAR_DATA *mob, CHAR_DATA *actor, OBJ_DATA *obj, void *vo, int64 type);
void rprog_percent_check( CHAR_DATA *mob, CHAR_DATA *actor, OBJ_DATA *obj, void *vo, int64 type);
void rprog_wordlist_check( const char *arg, CHAR_DATA *mob, CHAR_DATA *actor,
OBJ_DATA *obj, void *vo, int64 type, ROOM_INDEX_DATA *room );
/***************************************************************************
* Local function code and brief comments.
*/
/* if you dont have these functions, you damn well should... */
#ifdef DUNNO_STRSTR
char * strstr(s1,s2) const char *s1; const char *s2;
{
char *cp;
int i,j=strlen(s1)-strlen(s2),k=strlen(s2);
if(j<0)
return NULL;
for(i=0; i<=j && strncmp(s1++,s2, k)!=0; i++);
return (i>j) ? NULL : (s1-1);
}
#endif
#define RID ROOM_INDEX_DATA
void init_supermob()
{
RID *office;
supermob = create_mobile(get_mob_index( 3 ));
office = get_room_index ( 3 );
char_to_room( supermob, office );
}
#undef RID
/* Used to get sequential lines of a multi line string (separated by "\n\r")
* Thus its like one_argument(), but a trifle different. It is destructive
* to the multi line string argument, and thus clist must not be shared.
*/
char *mprog_next_command( char *clist )
{
char *pointer = clist;
while ( *pointer != '\n' && *pointer != '\0' )
pointer++;
if ( *pointer == '\n' || *pointer == '\r' )
*pointer++ = '\0';
if ( *pointer == '\r' || *pointer == '\n' )
*pointer++ = '\0';
return ( pointer );
}
/* These two functions do the basic evaluation of ifcheck operators.
* It is important to note that the string operations are not what
* you probably expect. Equality is exact and division is substring.
* remember that lhs has been stripped of leading space, but can
* still have trailing spaces so be careful when editing since:
* "guard" and "guard " are not equal.
*/
bool mprog_seval( const char *lhs, char *opr, char *rhs, CHAR_DATA *mob )
{
if ( !str_cmp( opr, "==" ) )
return ( bool )( !str_cmp( lhs, rhs ) );
if ( !str_cmp( opr, "!=" ) )
return ( bool )( str_cmp( lhs, rhs ) );
if ( !str_cmp( opr, "/" ) )
return ( bool )( !str_infix( rhs, lhs ) );
if ( !str_cmp( opr, "!/" ) )
return ( bool )( str_infix( rhs, lhs ) );
sprintf( log_buf, "Improper MOBprog operator '%s'", opr );
progbug( log_buf, mob );
return 0;
}
bool mprog_veval( int lhs, char *opr, int rhs, CHAR_DATA *mob )
{
if ( !str_cmp( opr, "==" ) )
return ( lhs == rhs );
if ( !str_cmp( opr, "!=" ) )
return ( lhs != rhs );
if ( !str_cmp( opr, ">" ) )
return ( lhs > rhs );
if ( !str_cmp( opr, "<" ) )
return ( lhs < rhs );
if ( !str_cmp( opr, "<=" ) )
return ( lhs <= rhs );
if ( !str_cmp( opr, ">=" ) )
return ( lhs >= rhs );
if ( !str_cmp( opr, "&" ) )
return ( lhs & rhs );
if ( !str_cmp( opr, "|" ) )
return ( lhs | rhs );
sprintf( log_buf, "Improper MOBprog operator '%s'", opr );
progbug( log_buf, mob );
return false;
}
/*
* Customizable Flag/Quest Code modified from GenmaC's code - Zoie
* (This is probably the only thing simple enough to work with Darkstone's code)
*/
#define DT_FLAG_DIR "../flags/"
void AddFlag( const char *flag, CHAR_DATA *player );
bool CheckForFlag( const char *flag, CHAR_DATA *player );
/*
AddFlag
Appends the line passed to it to the player's flag file.
Note that it could duplicate flags if marked more than once,
so use if hasflag before calling this.
*/
void AddFlag( const char *flag, CHAR_DATA *player )
{
char flag_file[100];
FILE * fw;
strcpy(flag_file, DT_FLAG_DIR);
strcat(flag_file, player->getName().c_str());
strcat(flag_file, ".flg");
fw = NULL;
fw = fopen(flag_file,"a");
fprintf(fw, "%s\n",flag);
printf("stuck %s in %s - correct?\n",flag,flag_file);
fclose(fw);
}
/*
CheckForFlag
finds the flag entry in /flags/player_name.flg, and returns 1 if
found.
*/
bool CheckForFlag( const char *flag, CHAR_DATA *player )
{
char flag_file[100];
char read_string[100];
bool bFound;
FILE * read;
strcpy(flag_file, DT_FLAG_DIR);
strcat(flag_file, player->getName().c_str());
strcat(flag_file, ".flg");
read = fopen(flag_file, "r");
bFound = 0;
if(read==NULL)
{
return FALSE;
}
while(fgets(read_string,99,read) != NULL)
{
if(read_string[strlen(read_string)-1] == '\n')
{
read_string[strlen(read_string)-1]='\0';
}
if( !str_cmp(flag,read_string) )
{
bFound = 1;
break;
}
}
return bFound;
}
/* This function performs the evaluation of the if checks. It is
* here that you can add any ifchecks which you so desire. Hopefully
* it is clear from what follows how one would go about adding your
* own. The syntax for an if check is: ifcheck ( arg ) [opr val]
* where the parenthesis are required and the opr and val fields are
* optional but if one is there then both must be. The spaces are all
* optional. The evaluation of the opr expressions is farmed out
* to reduce the redundancy of the mammoth if statement list.
* If there are errors, then return BERR otherwise return boolean 1,0
* Redone by Altrag.. kill all that big copy-code that performs the
* same action on each variable..
*/
int mprog_do_ifcheck( char *ifcheck, CHAR_DATA *mob, CHAR_DATA *actor,
OBJ_DATA *obj, void *vo, CHAR_DATA *rndm )
{
char cvar[MAX_INPUT_LENGTH] = "\0";
char chck[MAX_INPUT_LENGTH] = "\0";
char opr[MAX_INPUT_LENGTH] = "\0";
char rval[MAX_INPUT_LENGTH] = "\0";
char *point = ifcheck;
char *pchck = chck;
CHAR_DATA *chkchar = NULL;
OBJ_DATA *chkobj = NULL;
int lhsvl, rhsvl;
if ( !*point )
{
progbug( "Null ifcheck", mob );
return BERR;
}
while ( *point == ' ' )
point++;
while ( *point != '(' )
{
if ( *point == '\0' )
{
progbug( "Ifcheck syntax error", mob );
return BERR;
}
else if ( *point == ' ' )
point++;
else
*pchck++ = *point++;
}
*pchck = '\0';
point++;
pchck = cvar;
while ( *point != ')' )
{
if ( *point == '\0' )
{
progbug( "Ifcheck syntax error", mob );
return BERR;
}
else if ( *point == ' ' )
point++;
else
*pchck++ = *point++;
}
point++;
while ( *point == ' ' )
point++;
if ( !*point )
{
opr[0] = '\0';
rval[0] = '\0';
}
else
{
pchck = opr;
while ( *point != ' ' && !isalnum(*point) )
if ( *point == '\0' )
{
progbug( "Ifcheck operator without value", mob );
return BERR;
}
else
*pchck++ = *point++;
*pchck = '\0';
while ( *point == ' ' )
point++;
pchck = rval;
while ( *point != '\0' && *point != '\0' )
*pchck++ = *point++;
*pchck = '\0';
}
/* chck contains check, cvar is the variable in the (), opr is the
* operator if there is one, and rval is the value if there was an
* operator.
*/
if ( cvar[0] == '$' )
{
switch(cvar[1])
{
case 'i': chkchar = mob; break;
case 'n': chkchar = actor; break;
case 't': chkchar = (CHAR_DATA *)vo; break;
case 'r': chkchar = rndm; break;
case 'o': chkobj = obj; break;
case 'p': chkobj = (OBJ_DATA *)vo; break;
default:
sprintf(rval, "Bad argument '%c' to '%s'", cvar[0], chck);
progbug(rval, mob);
return BERR;
}
if ( !chkchar && !chkobj )
return BERR;
}
/* KSILYAN
* this is to allow certain ifchecks to work
* when called from objects.
*/
if ( mob == supermob)
{
if (supermob->tempnum == TEMPNUM_OBJ)
{
/* This means that we're working from an object.
* So, the mob is whoever is holding the object.
*/
OBJ_DATA * in_obj;
OBJ_DATA * obj;
obj = (OBJ_DATA *) supermob->spare_ptr;
for (in_obj = obj; in_obj->GetInObj(); in_obj = in_obj->GetInObj())
;
mob = obj->GetCarriedBy();
if (!mob)
mob = supermob; // just in case
}
}
if ( !str_cmp(chck, "rand") )
{
return (number_percent() <= atoi(cvar));
}
/*
Aiyan, 20/03/05 - roll a dice and check it's value, it was designed for the 0.8%(1/125)
drop rate. Some extensibility can't hurt though
*/
if ( !str_cmp(chck, "dice") )
{
if ( atoi(cvar) < 1 || atoi(cvar) > 65536 )
{
progbug("Dice ifcheck, number is less than 1 or greater than 65536", mob);
return BERR;
}
if ( atoi(rval) > atoi(cvar) )
{
progbug("Dice ifcheck, searching for a value greater than the dice sides", mob);
return BERR;
}
if ( atoi(rval) < 1 )
{
progbug("Dice ifcheck, searcing for 0 or negative value", mob);
return BERR;
}
return mprog_veval(number_range(0, atoi(cvar)), opr, atoi(rval), mob);
}
if( !str_cmp(chck, "hasflag" ) ) /* Ifcheck for new flag/quest system */
{ /* usage: if hasflag($n) == QuestName */
return(CheckForFlag(rval,chkchar));
}
if ( !str_cmp(chck, "mpwalkok" ) )
{
return bMpwalkSuccess;
}
if ( !str_cmp(chck, "ismpwalking" ) )
{
return chkchar ? chkchar->vnum_destination>0 :
mob->vnum_destination>0;
}
if ( !str_cmp(chck, "cansee") )
{
if ( !chkchar ) {
progbug("Cansee: no victim!", mob);
return BERR;
}
return can_see(mob, chkchar);
}
if ( !str_cmp(chck, "rarelimit" ) )
{
int vnum = dotted_to_vnum(mob->GetInRoom()->vnum, cvar);
OBJ_INDEX_DATA* pObj;
pObj = get_obj_index(vnum);
if ( !pObj ) {
sprintf(rval, "rarelimit: vnum %s is invalid!", cvar);
progbug(rval, mob);
return BERR;
}
if ( pObj->total_count >= pObj->rare && pObj->rare > 0 )
return 1;
else
return 0;
}
// Added by Ksilyan, nov-12-2004
if ( !str_cmp(chck, "isinvfull" ) )
{
if ( !chkchar ) {
progbug("isinvfull: no character!", mob);
return BERR;
}
int ok = 1;
if ( chkchar->carry_number + (get_obj_number(obj)/obj->count) > can_carry_n( chkchar ) )
ok = 0;
if ( chkchar->carry_weight + (get_obj_weight(obj)/obj->count) > can_carry_w( chkchar ) )
ok = 0;
return ok;
}
if ( !str_cmp(chck, "isexit" ) )
{
int vdir = atoi(cvar);
ROOM_INDEX_DATA* room;
ExitData* exit;
room = mob->GetInRoom();
for ( exit = room->first_exit; exit; exit = exit->next ) {
if ( exit->vdir == vdir ) {
return 1;
}
}
return 0;
}
if ( !str_cmp(chck, "issmell" ) )
{
int scent;
if ( !chkchar )
{
progbug("issmell ifcheck: no mob!", mob);
return BERR;
}
scent = atoi(rval);
if ( scent == chkchar->getScentId() )
{
return 1;
}
return 0;
}
if( !str_cmp(chck, "iscarryingobj") ) {
int vnum;
OBJ_DATA *pObj;
if ( !chkchar ) {
progbug("iscarryingobj ifcheck: no mob!", mob);
return BERR;
}
vnum = dotted_to_vnum(mob->GetInRoom()->vnum, rval);
if ( vnum == -1 ) {
progbug("iscarryingobj ifcheck: rval must be a number!", mob);
return BERR;
}
for ( pObj = chkchar->first_carrying; pObj; pObj = pObj->next_content ) {
if ( pObj->pIndexData->vnum == vnum ) {
return 1;
}
}
return 0;
}
if ( !str_cmp(chck, "iswearingobj") ) {
int vnum;
OBJ_DATA * pObj;
if ( !chkchar ) {
progbug("iswearingobj ifcheck: no mob!", mob);
return BERR;
}
vnum = dotted_to_vnum(mob->GetInRoom()->vnum, rval);
if ( vnum == -1 ) {
progbug("iswearingobj ifcheck: rval must be a number!", mob);
return BERR;
}
for ( pObj = chkchar->first_carrying; pObj; pObj = pObj->next_content ) {
if ( pObj->pIndexData->vnum == vnum) {
if (pObj->wear_loc != -1)
return 1;
}
}
return 0;
}
if ( !str_cmp(chck, "iscarried")) {
if ( !obj ) {
progbug("iscarried ifcheck: no object!", mob);
return BERR;
}
if ( obj->GetCarriedBy() ) {
return 1;
}
return 0;
}
if ( !str_cmp(chck, "economy") )
{
int idx = dotted_to_vnum(mob->GetInRoom()->vnum, cvar);
ROOM_INDEX_DATA *room;
if ( !idx )
{
if ( !mob->GetInRoom() )
{
progbug( "'economy' ifcheck: mob in NULL room with no room vnum "
"argument", mob );
return BERR;
}
room = mob->GetInRoom();
}
else
room = get_room_index(idx);
if ( !room )
{
progbug( "Bad room vnum passed to 'economy'", mob );
return BERR;
}
return mprog_veval( ((room->area->high_economy > 0) ? 1000000000 : 0)
+ room->area->low_economy, opr, atoi(rval), mob );
}
if ( !str_cmp(chck, "sectormob") )
{
if ( !chkchar ) {
progbug("sectormob ifcheck: no mob!", mob);
return BERR;
}
return mprog_veval( chkchar->GetInRoom()->sector_type, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "sector") )
{
ROOM_INDEX_DATA * iRoom;
iRoom = get_room_index(dotted_to_vnum(mob->GetInRoom()->vnum, cvar));
if ( !iRoom)
{
progbug("Invalid room vnum passed to sector", mob);
return BERR;
}
return mprog_veval( iRoom->sector_type, opr, atoi(rval),
mob );
}
if ( !str_cmp(chck, "numinroom") )
{
ROOM_INDEX_DATA* iRoom;
CHAR_DATA * vch;
int count = 0;
iRoom = get_room_index(dotted_to_vnum(mob->GetInRoom()->vnum, cvar));
if ( !iRoom ) {
progbug("Invalid room vnum passed to numinroom", mob);
return BERR;
}
for ( vch = iRoom->first_person; vch; vch = vch->next_in_room )
{
if ( IS_NPC(vch) && vch->pIndexData->vnum == 3 ) {
continue;
}
++count;
}
return mprog_veval(count, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "num_pc_inarea") )
{
int count = 0;
count = mob->GetInRoom()->area->nplayer;
return mprog_veval(count, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "num_pc_inroom") )
{
ROOM_INDEX_DATA* iRoom;
CHAR_DATA * vch;
int count = 0;
iRoom = get_room_index(dotted_to_vnum(mob->GetInRoom()->vnum, cvar));
if ( !iRoom ) {
progbug("Invalid room vnum passed to num_pc_inroom", mob);
return BERR;
}
for ( vch = iRoom->first_person; vch; vch = vch->next_in_room )
{
if ( !IS_NPC(vch) ){
++count;
}
}
return mprog_veval(count, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "num_npc_inroom") )
{
ROOM_INDEX_DATA* iRoom;
CHAR_DATA * vch;
int count = 0;
iRoom = get_room_index(dotted_to_vnum(mob->GetInRoom()->vnum, cvar));
if ( !iRoom ) {
progbug("Invalid room vnum passed to num_npc_inroom", mob);
return BERR;
}
for ( vch = iRoom->first_person; vch; vch = vch->next_in_room )
{
if ( IS_NPC(vch) && vch->pIndexData->vnum != 3) {
++count;
}
}
return mprog_veval(count, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "mobinroom") )
{
int vnum = dotted_to_vnum(mob->GetInRoom()->vnum, cvar);
int lhsvl;
CHAR_DATA *oMob;
if ( vnum < 1 || vnum > 1048576000 )
{
char buf[255];
sprintf(buf, "Bad vnum (%s) to 'mobinroom'", cvar);
progbug( buf, mob );
return BERR;
}
lhsvl = 0;
for ( oMob = mob->GetInRoom()->first_person; oMob;
oMob = oMob->next_in_room )
{
if ( IS_NPC(oMob) && oMob->pIndexData->vnum == vnum )
{
lhsvl++;
}
}
rhsvl = atoi(rval);
if ( rhsvl < 1 ) rhsvl = 1;
if ( !*opr )
strcpy( opr, "==" );
return mprog_veval(lhsvl, opr, rhsvl, mob);
}
if ( !str_cmp(chck, "isworn" ) )
{
OBJ_DATA* pObj;
int count = 0;
int vnum = dotted_to_vnum(mob->GetInRoom()->vnum, cvar);
for ( pObj = mob->first_carrying; pObj; pObj = pObj->next ) {
if ( pObj->pIndexData->vnum == vnum || !is_name_prefix(cvar, pObj->name_.c_str()) ) {
if ( pObj->wear_loc == WEAR_NONE )
++count;
}
}
return mprog_veval(count, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "time_hour" ) )
{
return mprog_veval(time_info.hour, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "date_day" ) )
{
return mprog_veval(time_info.day, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "date_month" ) )
{
return mprog_veval(time_info.month, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "date_year" ) )
{
return mprog_veval(time_info.year, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "ininvent" ) )
{
OBJ_DATA* pObj;
int count = 0;
int vnum = dotted_to_vnum(mob->GetInRoom()->vnum, cvar);
for ( pObj = mob->first_carrying; pObj; pObj = pObj->next ) {
if ( pObj->pIndexData->vnum == vnum || !is_name_prefix(cvar, pObj->name_.c_str()) ) {
++count;
}
}
return mprog_veval(count, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "timeskilled") )
{
MOB_INDEX_DATA *pMob;
if ( chkchar )
pMob = chkchar->pIndexData;
else if ( !(pMob = get_mob_index(dotted_to_vnum(mob->GetInRoom()->vnum, cvar))))
{
progbug("TimesKilled ifcheck: bad vnum", mob);
return BERR;
}
return mprog_veval(pMob->killed, opr, atoi(rval), mob);
}
if ( !str_cmp(chck, "ovnumhere") )
{
OBJ_DATA *pObj;
int vnum = dotted_to_vnum(mob->GetInRoom()->vnum, cvar);
if ( vnum < 1 || vnum > 1048576000 )
{
progbug("OvnumHere: bad vnum", mob);
return BERR;
}
lhsvl = 0;
for ( pObj = mob->first_carrying; pObj; pObj = pObj->next_content )
if ( can_see_obj(mob, pObj) && pObj->pIndexData->vnum == vnum )
lhsvl++;
for ( pObj = mob->GetInRoom()->first_content; pObj;
pObj = pObj->next_content )
if ( can_see_obj(mob, pObj) && pObj->pIndexData->vnum == vnum )
lhsvl++;
rhsvl = is_number(rval) ? atoi(rval) : -1;
if ( rhsvl < 1 )
rhsvl = 1;
if ( !*opr )
strcpy(opr, "==");
return mprog_veval(lhsvl, opr, rhsvl, mob);
}
if ( !str_cmp(chck, "otypehere") )
{
OBJ_DATA *pObj;
int64 type;
if ( is_number(cvar) )
type = atoi(cvar);
else
type = itemtype_name_to_number(cvar);
if ( type < 0 || type > MAX_ITEM_TYPE )
{
progbug("OtypeHere: bad type", mob);
return BERR;
}
lhsvl = 0;
for ( pObj = mob->first_carrying; pObj; pObj = pObj->next_content )
if ( can_see_obj(mob, pObj) && pObj->item_type == type )
lhsvl++;
for ( pObj = mob->GetInRoom()->first_content; pObj;
pObj = pObj->next_content )
if ( can_see_obj(mob, pObj) && pObj->item_type == type )
lhsvl++;
rhsvl = is_number(rval) ? atoi(rval) : -1;
if ( rhsvl < 1 )
rhsvl = 1;
if ( !*opr )
strcpy(opr, "==");
return mprog_veval(lhsvl, opr, rhsvl, mob);
}
if ( !str_cmp(chck, "ovnumroom") )
{
OBJ_DATA *pObj;
int vnum = dotted_to_vnum(mob->GetInRoom()->vnum, cvar);
if ( vnum < 1 || vnum > 1048576000 )
{
progbug("OvnumRoom: bad vnum", mob);
return BERR;
}
lhsvl = 0;
for ( pObj = mob->GetInRoom()->first_content; pObj;
pObj = pObj->next_content )
if ( can_see_obj(mob, pObj) && pObj->pIndexData->vnum == vnum )
lhsvl++;
rhsvl = is_number(rval) ? atoi(rval) : -1;
if ( rhsvl < 1 )
rhsvl = 1;
if ( !*opr )
strcpy(opr, "==");
return mprog_veval(lhsvl, opr, rhsvl, mob);
}
if ( !str_cmp(chck, "otyperoom") )
{
OBJ_DATA *pObj;
int64 type;
if ( is_number(cvar) )
type = atoi(cvar);
else
type = itemtype_name_to_number(cvar);
if ( type < 0 || type > MAX_ITEM_TYPE )
{
progbug("OtypeRoom: bad type", mob);
return BERR;
}
lhsvl = 0;
for ( pObj = mob->GetInRoom()->first_content; pObj;
pObj = pObj->next_content )
if ( can_see_obj(mob, pObj) && pObj->item_type == type )
lhsvl++;
rhsvl = is_number(rval) ? atoi(rval) : -1;
if ( rhsvl < 1 )
rhsvl = 1;
if ( !*opr )
strcpy(opr, "==");
return mprog_veval(lhsvl, opr, rhsvl, mob);
}
if ( !str_cmp(chck, "ovnumcarry") )
{
OBJ_DATA *pObj;
int vnum = dotted_to_vnum(mob->GetInRoom()->vnum, cvar);
if ( vnum < 1 || vnum > 1048576000 )
{
progbug("OvnumCarry: bad vnum", mob);
return BERR;
}
lhsvl = 0;
for ( pObj = mob->first_carrying; pObj; pObj = pObj->next_content )
{
if ( can_see_obj(mob, pObj) && pObj->pIndexData->vnum == vnum )
lhsvl++;
}
rhsvl = is_number(rval) ? atoi(rval) : -1;
if ( rhsvl < 0 )
{
progbug("OvnumCarry: bad right-hand side value. Using 0 instead.", mob);
rhsvl = 0;
}
if ( !*opr )
{
progbug("OvnumCarry: bad operator. Using == instead.", mob);
strcpy(opr, "==");
}
return mprog_veval(lhsvl, opr, rhsvl, mob);
}
if ( !str_cmp(chck, "otypecarry") )
{
OBJ_DATA *pObj;
int64 type;
if ( is_number(cvar) )
type = atoi(cvar);
else
type = itemtype_name_to_number(cvar);
if ( type < 0 || type > MAX_ITEM_TYPE )
{
progbug("OtypeCarry: bad type", mob);
return BERR;
}
lhsvl = 0;
for ( pObj = mob->first_carrying; pObj; pObj = pObj->next_content )
if ( can_see_obj(mob, pObj) && pObj->item_type == type )
lhsvl++;
rhsvl = is_number(rval) ? atoi(rval) : -1;
if ( rhsvl < 1 )
rhsvl = 1;
if ( !*opr )
strcpy(opr, "==");
return mprog_veval(lhsvl, opr, rhsvl, mob);
}
if ( !str_cmp(chck, "ovnumwear") )
{
OBJ_DATA *pObj;
int vnum = dotted_to_vnum(mob->GetInRoom()->vnum, cvar);
if ( vnum < 1 || vnum > 1048576000 )
{
progbug("OvnumWear: bad vnum", mob);
return BERR;
}
lhsvl = 0;
for ( pObj = mob->first_carrying; pObj; pObj = pObj->next_content )
if ( pObj->wear_loc != WEAR_NONE && can_see_obj(mob, pObj) &&
pObj->pIndexData->vnum == vnum )
lhsvl++;
rhsvl = is_number(rval) ? atoi(rval) : -1;
if ( rhsvl < 1 )
rhsvl = 1;
if ( !*opr )
strcpy(opr, "==");