-
Notifications
You must be signed in to change notification settings - Fork 0
/
dg_scripts.cpp
5815 lines (5024 loc) · 177 KB
/
dg_scripts.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
/**************************************************************************
* File: scripts.c *
* Usage: contains general functions for using scripts. *
* *
* *
* $Author: w4dimenscor $
* $Date: 2007/11/18 06:50:38 $
* $Revision: 1.42 $
**************************************************************************/
/*
* $Log: dg_scripts.c,v $
* Revision 1.42 2007/11/18 06:50:38 w4dimenscor
* Fixed the bug where you could dig up any buried object in the mud. Removed all threadding from the code to stop the freezes.
*
* Revision 1.41 2007/11/14 03:30:12 w4dimenscor
* Changed the world and the index to classes. Fixed the room save bug where it would wipe descriptions
*
* Revision 1.40 2007/08/19 01:06:10 w4dimenscor
* - Changed the playerindex to be a c++ object with search functions.
* - changed the room descriptions to be searched from a MAP index, and
* added Get and Set methods for room descriptions.
* - changed the zone reset so that it doesnt search the entire object list
* to find the object to PUT things into.
* - rewrote other parts of the zone reset function, to make it give correct errors.
* - rewrote the parts of the code to do with loading and searching for directorys and files.
* - added a new dlib library.
*
* Revision 1.39 2007/07/01 14:34:03 w4dimenscor
* fixed a whitepace issue in globals
*
* Revision 1.38 2007/06/14 23:55:39 w4dimenscor
* Timers now work offline, keys can't be put in houses along with non-rent items. and the timers on items are run from the event system instead of 'ticks'
*
* Revision 1.37 2007/06/10 08:18:13 w4dimenscor
* added new body parts CHEST and BACK
*
* Revision 1.36 2007/04/12 13:08:18 w4dimenscor
* Forgot to remove a little pie comment.
* --Thotter
*
* Revision 1.35 2007/04/12 12:50:51 w4dimenscor
* fixed a crashbug in script log. The argument list was used twice.
* -- Thotter
*
* Revision 1.34 2006/09/15 08:01:12 w4dimenscor
* Changed a large amount of send_to_char's to ch->Send and d->Output. fixed namechange command
*
* Revision 1.33 2006/08/25 10:22:43 w4dimenscor
* added command to fix peoples skills back to the practiced amount they were at
*
* Revision 1.32 2006/08/23 09:01:26 w4dimenscor
* Changed some of the std::vectors to std::map, killlist, and the lookup tables for id nums
*
* Revision 1.31 2006/08/20 12:12:32 w4dimenscor
* Changed the lookup table buckets to use sorted vectors. exciting. Also changed ignore list to use vectors, and fixed the valgrind error with the sort algorithm. Also sped up top gold command
*
* Revision 1.30 2006/08/18 11:09:58 w4dimenscor
* updated some clan functions to use vectors instead of malloccing memory, and also sorted clan lists and updated their layout
*
* Revision 1.29 2006/08/17 12:28:31 w4dimenscor
* Fixed a little bug concerning brackets
*
* Revision 1.28 2006/08/13 06:26:51 w4dimenscor
* New branch created, most arrays in game converted to vectors, and the way new zones are created, many conversions of structs to classes
*
* Revision 1.27 2006/07/03 14:33:15 w4dimenscor
* Added |= and %text.abbrev(blah)%. now we can test wether a word starts
* with something. Great for command triggers.
*
* Revision 1.26 2006/06/21 05:22:35 w4dimenscor
* found an error where is find_room was passed too large a number, it would segfault. Fixed
*
* Revision 1.25 2006/05/30 09:14:19 w4dimenscor
* rewrote the color code, process_output, and vwrite_to_output so that they use strings and have better buffer checks
*
* Revision 1.24 2006/05/22 10:50:48 w4dimenscor
* Created 3 new files, mxp.cpp, mxp.h and descriptor.cpp
* struct descriptor_data has been converted to class Descriptor
*
* Revision 1.23 2006/05/21 11:02:26 w4dimenscor
* converted game from being C code to C++
* to use new_send_to_char(ch, 'blah') now, you use ch->Send('Blah')
*
* Revision 1.22 2006/05/13 01:31:29 w4dimenscor
* Added the changes to the fread_string function thotter. Also put the hash lookup table back in which speeds things up, but i have found that in the past it adds a little instability. I added code optimisations in to speed functions up, such as isname
*
* Revision 1.21 2006/05/01 11:29:26 w4dimenscor
* I wrote a typo checker that automaticly corrects typos in the comm channels. I have also been fixing shadowed variables. There may be residual issues with it.
*
* Revision 1.20 2006/04/06 14:00:57 w4dimenscor
* fixed a memory bug in dg scripts
*
* Revision 1.19 2006/02/17 22:19:54 w4dimenscor
* Fixed error for ubuntu that doesnt like empty array declarations, moved ice shield to a better place and fixed its messages, added auto auction fixes, allowed mounts to gain exp properly
*
* Revision 1.18 2005/11/30 19:08:47 w4dimenscor
* fixes an issue in function triggers
*
* Revision 1.17 2005/08/19 09:34:04 w4dimenscor
* fixed issue with FUNCTIONS not passing back vars, i mean, it does now.
*
* Revision 1.16 2005/08/19 09:32:57 w4dimenscor
* fixed issue with FUNCTIONS not passing back vars, didnt compile, this one does
*
* Revision 1.15 2005/08/19 09:31:43 w4dimenscor
* fixed issue with FUNCTIONS not passing back vars, maybe.
*
* Revision 1.14 2005/08/19 08:51:14 w4dimenscor
* fixed the variables not working
*
* Revision 1.13 2005/08/14 02:27:13 w4dimenscor
* added shiftable objects flag for the pull command, added to dg_variables ability to SET object values from variables, hopefully fixed issue where triggers would be removed from rooms after editing.
*
* Revision 1.12 2005/08/07 04:12:39 w4dimenscor
* Manu changes and command have been made, sorry for the lack of description. Main changes include command landscape, fixes to helpfile stuff, subskill fixes
*
* Revision 1.11 2005/04/23 12:18:12 w4dimenscor
* Fixed some buffer read errors in the fread_string function, also fixed (temp) an index search issue for real_trigger()
*
* Revision 1.10 2005/02/26 01:21:34 w4dimenscor
* Changed more of the code to be more buffer safe using strlcpy and strlcat
*
* Revision 1.9 2005/02/20 01:18:11 w4dimenscor
* added extra check to add to lookup table, and cleaned up freeing of characters and objects
*
* Revision 1.8 2005/02/16 07:36:25 w4dimenscor
* Added math.c and updated code
*
* Revision 1.7 2005/02/09 09:23:44 w4dimenscor
* added new code for using olc to create new mine shafts, and cleaned up the tsearch command, fixed a bug where there is no description in the log if the game crashes because a zone file is wanting to remove a item from a room using zedit, but the room doesnt exist, and fixed an exp bug in flee
*
* Revision 1.6 2005/02/05 05:26:17 w4dimenscor
* Added tsearch command to full text search triggers
*
* Revision 1.5 2005/02/04 20:46:11 w4dimenscor
* Many changes - i couldn't connect to this for a while
*
* Revision 1.4 2004/11/26 23:02:45 w4dimenscor
* Added more notes into fight code, and more debugging checks, made combat reuse the event
*
* Revision 1.3 2004/11/23 06:12:20 w4dimenscor
* fixed some mem leaks in lightsabers, discovered function is_num is fucked, reverted it
*
* Revision 1.2 2004/11/20 02:33:25 w4dimenscor
* updated and cleaned up the script system
*
* Revision 1.1.1.1 2004/11/12 02:15:49 w4dimenscor
* Initial clean submission of 4Dimensions src code
*
* Revision 1.42 2004/09/18 04:42:46 molly
* cleared up some memory leaks again, possibly fixed the QIC miscounts
*
* Revision 1.41 2004/08/15 01:12:26 molly
* aqdded logging to several files, fixed error in the setting of immtitles. fixed typo in busy
*
*/
#include "config.h"
#include "sysdep.h"
#include "structs.h"
#include "dg_scripts.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "dg_event.h"
#include "db.h"
#include "screen.h"
#include "constants.h"
#include "spells.h"
#include "oasis.h"
#include "descriptor.h"
#include "name.map.h"
#define PULSES_PER_MUD_HOUR (SECS_PER_MUD_HOUR*PASSES_PER_SEC)
#define NINE_MONTHS 6000 /* 6000 realtime minutes TO GO */
/* external vars */
extern unsigned long pulse;
/* other external vars */
extern struct time_info_data time_info;
/* external functions */
int edit_extra_desc ( obj_data *obj, const char *keyword, const char *description );
script_data* create_script();
void set_script_types ( script_data *sc );
void free_cmdlist ( trig_data *trig );
void copy_ex_descriptions ( struct extra_descr_data **to, struct extra_descr_data *from );
char *str_udup(const char *txt);
void view_room_by_rnum ( Character *ch, room_rnum is_in );
void free_varlist ( struct trig_var_data *vd );
int eval_lhs_op_rhs ( char *expr, char *result, size_t r_len,void *go,
struct script_data *sc, trig_data * trig, int type );
//int find_eq_pos_script(Character *ch, char *arg);
int find_skill_num ( char *name );
int find_sub_num ( char *name );
/*hm...mord*/
const char *simple_class_name ( Character *ch );
const char *race_name ( Character *ch );
int can_edit_zone ( Character *ch, zone_rnum zone );
zone_rnum real_zone_by_thing ( room_vnum vznum );
int genpreg ( void );
bool is_abbrev3 ( const string &s1, const string &s2 );
int zone_is_empty ( zone_rnum zone_nr );
room_rnum find_target_room ( Character *ch, char *rawroomstr );
/* function protos from this file */
void process_eval ( void *go, struct script_data *sc, trig_data *trig,
int type, char *cmd );
/* Local functions not used elsewhere */
void do_stat_trigger ( Character *ch, trig_data *trig );
void script_stat ( Character *ch, struct script_data *sc );
int remove_trigger ( void *thing, trig_data *trig, int type );
int is_num ( char *arg );
void eval_op ( char *op, char *lhs, char *rhs, char *result, size_t r_len, void *go,
struct script_data *sc, trig_data *trig );
char *matching_paren ( char *p );
void eval_expr ( char *line, char *result, size_t r_len, void *go, struct script_data *sc,
trig_data *trig, int type );
int eval_lhs_op_rhs ( char *expr, char *result, size_t r_len, void *go, struct script_data *sc,
trig_data *trig, int type );
int process_if ( char *cond, void *go, struct script_data *sc,
trig_data *trig, int type );
struct cmdlist_element *find_end ( trig_data *trig, struct cmdlist_element *cl );
struct cmdlist_element *find_else_end ( trig_data *trig,
struct cmdlist_element *cl, void *go,
struct script_data *sc, int type );
void process_wait ( void *go, trig_data *trig, int type, char *cmd,
struct cmdlist_element *cl );
void process_set ( struct script_data *sc, trig_data *trig, char *cmd );
void process_attach ( void *go, struct script_data *sc, trig_data *trig,
int type, char *cmd );
void process_detach ( void *go, struct script_data *sc, trig_data *trig,
int type, char *cmd );
void makeuid_var ( void *go, struct script_data *sc, trig_data *trig,
int type, char *cmd );
int process_return ( trig_data *trig, char *cmd );
void process_unset ( struct script_data *sc, trig_data *trig, char *cmd );
void process_remote ( struct script_data *sc, trig_data *trig, char *cmd );
void process_rdelete ( struct script_data *sc, trig_data *trig, char *cmd );
void process_restring ( script_data *sc, trig_data *trig, char *cmd );
void process_global ( struct script_data *sc, trig_data *trig, char *cmd, long id );
void process_context ( struct script_data *sc, trig_data *trig, char *cmd );
void dg_letter_value ( struct script_data *sc, trig_data *trig, char *cmd );
struct cmdlist_element *
find_case ( struct trig_data *trig, struct cmdlist_element *cl,
void *go, struct script_data *sc, int type, char *cond );
void extract_value ( struct script_data *sc, trig_data * trig, char *cmd );
struct cmdlist_element *find_done ( struct cmdlist_element *cl );
int fgetline ( FILE *file, char *p );
Character *find_char_by_uid_in_lookup_table ( long uid );
struct obj_data *find_obj_by_uid_in_lookup_table ( long uid );
EVENTFUNC ( trig_wait_event );
ACMD ( do_attach ) ;
ACMD ( do_detach );
ACMD ( do_vdelete );
ACMD ( do_tstat );
const char errorbuf[MAX_STRING_LENGTH] = "\0";
char *zero = ( char * ) "0";
map<trig_data*, TrigDebug> script_debug;
/* Return pointer to first occurrence of string ct in */
/* cs, or NULL if not present. Case insensitive */
char *str_str ( char *cs, char *ct )
{
char *s, *t;
if ( !cs || !ct || !*ct )
return NULL;
while ( *cs )
{
t = ct;
while ( *cs && ( LOWER ( *cs ) != LOWER ( *t ) ) )
cs++;
s = cs;
while ( *t && *cs && ( LOWER ( *cs ) == LOWER ( *t ) ) )
{
t++;
cs++;
}
if ( !*t )
return s;
}
return NULL;
}
char *str_str ( char *cs, const char *ct )
{
return str_str ( cs, ( char * ) ct );
}
int trgvar_in_room ( room_vnum vnum )
{
room_rnum rnum = real_room ( vnum );
int i = 0;
Character *ch;
if ( rnum == NULL )
{
script_log ( "people.vnum: world[rnum] does not exist" );
return ( -1 );
}
for ( ch = rnum->people; ch != NULL; ch = ch->next_in_room )
i++;
return i;
}
obj_data *get_obj_in_list ( char *name, obj_data * list )
{
obj_data *i;
long id;
if ( *name == UID_CHAR )
{
id = atoi ( name + 1 );
for ( i = list; i; i = i->next_content )
if ( id == GET_ID ( i ) )
return i;
}
else
{
for ( i = list; i; i = i->next_content )
if ( isname ( name, i->name ) )
return i;
}
return NULL;
}
obj_data *get_obj_in_list ( const char *name, obj_data * list )
{
obj_data *i;
long id;
if ( *name == UID_CHAR )
{
id = atoi ( name + 1 );
for ( i = list; i; i = i->next_content )
if ( id == GET_ID ( i ) )
return i;
}
else
{
for ( i = list; i; i = i->next_content )
if ( isname ( name, i->name ) )
return i;
}
return NULL;
}
/* Handles 'held', 'light' and 'wield' positions - Welcor
After idea from Byron Ellacott - bje@apnic.net */
int find_eq_pos_script ( char *arg )
{
int i;
if ( is_number ( arg ) && ( i = atoi ( arg ) ) >= 0 && i < NUM_WEARS )
return i;
for ( i = 0; eq_pos[i].where != -1; i++ )
{
if ( !strcasecmp ( eq_pos[i].pos, arg ) )
return eq_pos[i].where;
}
return ( -1 );
}
int can_wear_on_pos ( struct obj_data *obj, int pos )
{
switch ( pos )
{
case WEAR_HOLD:
case WEAR_LIGHT:
return CAN_WEAR ( obj, ITEM_WEAR_HOLD );
case WEAR_WIELD_2:
case WEAR_WIELD:
return CAN_WEAR ( obj, ITEM_WEAR_WIELD );
case WEAR_THUMB_R:
case WEAR_THUMB_L:
case WEAR_FINGER_R:
case WEAR_FINGER_L:
return CAN_WEAR ( obj, ITEM_WEAR_FINGER );
case WEAR_NECK_1:
case WEAR_NECK_2:
return CAN_WEAR ( obj, ITEM_WEAR_NECK );
case WEAR_BODY:
return CAN_WEAR ( obj, ITEM_WEAR_BODY );
case WEAR_HEAD:
return CAN_WEAR ( obj, ITEM_WEAR_HEAD );
case WEAR_LEGS_2:
case WEAR_LEGS:
return CAN_WEAR ( obj, ITEM_WEAR_LEGS );
case WEAR_FEET_2:
case WEAR_FEET:
return CAN_WEAR ( obj, ITEM_WEAR_FEET );
case WEAR_HANDS:
return CAN_WEAR ( obj, ITEM_WEAR_HANDS );
case WEAR_ARMS:
return CAN_WEAR ( obj, ITEM_WEAR_ARMS );
case WEAR_SHIELD:
return CAN_WEAR ( obj, ITEM_WEAR_SHIELD );
case WEAR_SADDLE:
case WEAR_ABOUT:
return CAN_WEAR ( obj, ITEM_WEAR_ABOUT );
case WEAR_WAIST:
return CAN_WEAR ( obj, ITEM_WEAR_WAIST );
case WEAR_WRIST_R:
case WEAR_WRIST_L:
return CAN_WEAR ( obj, ITEM_WEAR_WRIST );
case WEAR_FACE:
return CAN_WEAR ( obj, ITEM_WEAR_FACE );
case WEAR_EYES:
return CAN_WEAR ( obj, ITEM_WEAR_EYES );
case WEAR_HIPS:
return CAN_WEAR ( obj, ITEM_WEAR_HIPS );
case WEAR_EAR_TIP:
case WEAR_EAR_R:
case WEAR_EAR_L:
return CAN_WEAR ( obj, ITEM_WEAR_EAR );
case WEAR_ANKLE_R:
case WEAR_ANKLE_L:
return CAN_WEAR ( obj, ITEM_WEAR_ANKLE );
case WEAR_HORNS:
return CAN_WEAR ( obj, ITEM_WEAR_HORNS );
case WEAR_ANTENNA:
return CAN_WEAR ( obj, ITEM_WEAR_ANTENNA );
case WEAR_TAIL:
return CAN_WEAR ( obj, ITEM_WEAR_TAIL );
case WEAR_FOCUS:
return CAN_WEAR ( obj, ITEM_WEAR_FOCUS );
case WEAR_SHOULDER_L:
case WEAR_SHOULDER_R:
return CAN_WEAR ( obj, ITEM_WEAR_SHOULDER );
case WEAR_CREST:
return CAN_WEAR ( obj, ITEM_WEAR_CREST );
case WEAR_THIGH_L:
case WEAR_THIGH_R:
return CAN_WEAR ( obj, ITEM_WEAR_THIGH );
case WEAR_KNEE_L :
case WEAR_KNEE_R:
return CAN_WEAR ( obj, ITEM_WEAR_KNEE );
case WEAR_FLOATING:
return CAN_WEAR ( obj, ITEM_WEAR_FLOATING );
case WEAR_BACK:
return CAN_WEAR ( obj, ITEM_WEAR_BACK );
case WEAR_CHEST:
return CAN_WEAR ( obj, ITEM_WEAR_CHEST );
default:
return FALSE;
}
}
/*
#define WEAR_THUMB_R 32
#define WEAR_THUMB_L 33
#define WEAR_SADDLE 34
#define WEAR_EAR_TIP 35
#define WEAR_SHOULDER_L 36
#define WEAR_SHOULDER_R 37
#define WEAR_CREST 38
#define WEAR_THIGH_L 39
#define WEAR_THIGH_R 40
#define WEAR_KNEE_L 41
#define WEAR_KNEE_R 42
#define WEAR_FLOATING 43
*/
obj_data *get_object_in_equip ( Character * ch,const char *name )
{
int j;
obj_data *obj;
// char tmpname[MAX_INPUT_LENGTH];
// char *tmp = tmpname;
long id;
/*int n = 0, num;*/
if ( *name == UID_CHAR )
{
id = atoi ( name + 1 );
for ( j = 0; j < NUM_WEARS; j++ )
if ( ( obj = GET_EQ ( ch, j ) ) )
if ( id == GET_ID ( obj ) )
return ( obj );
}
else if ( is_number ( name ) )
{
obj_vnum ovnum = atoi ( name );
for ( j = 0; j < NUM_WEARS; j++ )
if ( ( obj = GET_EQ ( ch, j ) ) )
if ( GET_OBJ_VNUM ( obj ) == ovnum )
return ( obj );
}
else
{
/*snprintf ( tmpname, sizeof ( tmpname ), "%s", name );
if ( ! ( num = get_number ( &tmpname ) ) )
return NULL;*/
for ( j = 0; ( j < NUM_WEARS ) /* && ( n <= num )*/; j++ )
if ( ( obj = GET_EQ ( ch, j ) ) )
if ( isname ( /*tmp*/ name, obj->name ) )
/*if ( ++n == num )*/
return ( obj );
}
return NULL;
}
/************************************************************
* search by number routines
************************************************************/
/* return char with UID n */
/*TODO: this function uses alot of time, fix it */
Character *find_char ( long n )
{
if ( n>=ROOM_ID_BASE ) /* See note in dg_scripts.h */
return NULL;
return find_char_by_uid_in_lookup_table ( n );
}
/* return object with UID n */
struct obj_data *find_obj ( long n )
{
if ( n < OBJ_ID_BASE ) /* see note in dg_scripts.h */
return NULL;
return find_obj_by_uid_in_lookup_table ( n );
}
/* return room with UID n */
Room *find_room ( long n )
{
n -= ROOM_ID_BASE;
return real_room ( n );
}
/************************************************************
* generic searches based only on name
************************************************************/
/* search the entire world for a char, and return a pointer */
Character *get_char ( const char *name )
{
Character *i = NULL;
if ( *name == UID_CHAR )
{
i = find_char ( atoi ( name + 1 ) );
if ( i && valid_dg_target ( i, TRUE ) )
return i;
}
else
{
#if 1
long j = mobNames.nameLookup ( name );
if ( j != -1 )
i = find_char ( j );
if ( i && valid_dg_target ( i, TRUE ) )
return i;
for ( Descriptor *d = descriptor_list; d; d = d->next )
{
i = d->character;
if ( IS_PLAYING ( d ) && i && IN_ROOM ( i ) && isname_hard ( name, i->player.name ) && valid_dg_target ( i, TRUE ) )
return i;
}
#else
for ( i = character_list; i; i = i->next )
if ( isname_hard ( name, i->player.name ) && valid_dg_target ( i, TRUE ) )
return i;
#endif
}
return NULL;
}
/*
* Finds a char in the same room as the object with the name 'name'
*/
Character *get_char_near_obj ( obj_data * obj, char *name )
{
Character *ch;
if ( *name == UID_CHAR )
{
ch = find_char ( atoi ( name + 1 ) );
if ( ch && valid_dg_target ( ch, TRUE ) )
return ch;
}
else
{
room_rnum num;
if ( ( num = obj_room ( obj ) ) != NULL )
for ( ch = num->people; ch; ch = ch->next_in_room )
if ( isname ( name, ch->player.name ) &&
valid_dg_target ( ch, TRUE ) )
return ch;
}
return NULL;
}
/*
* returns a pointer to the first character in world by name name,
* or NULL if none found. Starts searching in room room first
*/
Character *get_char_in_room ( Room * room, char *name )
{
Character *ch;
if ( *name == UID_CHAR )
{
ch = find_char ( atoi ( name + 1 ) );
if ( ch && valid_dg_target ( ch, TRUE ) )
return ch;
}
else
{
for ( ch = room->people; ch; ch = ch->next_in_room )
if ( isname ( name, ch->player.name ) && valid_dg_target ( ch, TRUE ) )
return ch;
}
return NULL;
}
/* searches the room with the object for an object with name 'name'*/
obj_data *get_obj_near_obj ( obj_data * obj, char *name )
{
struct obj_data *i = NULL;
Character *ch;
room_rnum rm;
long id;
if ( !strcasecmp ( name, "self" ) || !strcasecmp ( name, "me" ) )
return obj;
/* is it inside ? */
if ( obj->contains && ( i = get_obj_in_list ( name, obj->contains ) ) )
return i;
/* or outside ? */
if ( obj->in_obj )
{
if ( *name == UID_CHAR )
{
id = atoi ( name + 1 );
if ( id == GET_ID ( obj->in_obj ) )
return obj->in_obj;
}
else if ( isname ( name, obj->in_obj->name ) )
return obj->in_obj;
}
/* or worn ? */
else if ( obj->worn_by && ( i = get_object_in_equip ( obj->worn_by, name ) ) )
return i;
/* or carried ? */
else if ( obj->carried_by &&
( i = get_obj_in_list ( name, obj->carried_by->carrying ) ) )
return i;
else if ( ( rm = obj_room ( obj ) ) != NULL )
{
/* check the floor */
if ( ( i = get_obj_in_list ( name, rm->contents ) ) )
return i;
/* check peoples' inventory */
for ( ch = rm->people; ch; ch = ch->next_in_room )
if ( ( i = get_object_in_equip ( ch, name ) ) )
return i;
}
return NULL;
}
/* returns the object in the world with name name, or NULL if not found */
struct obj_data *get_obj ( const char *name )
{
if ( !name || !*name )
return NULL;
else if ( *name == UID_CHAR )
return find_obj ( atoi ( name + 1 ) );
else
{
#if 1
long i = objNames.nameLookup ( name );
if ( i != -1 )
return find_obj ( i );
#else
for ( olt_it ob = object_list.begin(); ob != object_list.end(); ob++ )
if ( ob->second && isname_hard ( ( ob->second )->name, name ) )
return ob->second;
#endif
}
return NULL;
}
/**
switch (obj->Names.size()) {
case 0:
break;
case 1:
if (is_abbrev(name, obj->Names[0].c_str()))
return obj;
break;
default:
for (vector<string>::iterator i = obj->Names.begin();
i != obj->Names.end();
i++)
if (is_abbrev((*i).c_str(), name)
)
return obj;
//if (isname(name, obj->name))
// return obj;
}**/
/* finds room by id or vnum. returns NULL if not found */
room_rnum get_room ( const char *name )
{
if ( *name == UID_CHAR )
return find_room ( atoi ( name + 1 ) );
else if ( !is_number ( name ) )
return NULL;
else
return real_room ( atoi ( name ) );
}
/*
* returns a pointer to the first character in world by name name,
* or NULL if none found. Starts searching with the person owning the object
*/
Character *get_char_by_obj ( obj_data * obj,const char *name )
{
Character *ch;
room_rnum r = NULL;
if ( *name == UID_CHAR )
{
ch = find_char ( atoi ( name + 1 ) );
if ( ch && valid_dg_target ( ch, TRUE ) )
return ch;
}
else
{
if ( obj->carried_by &&
isname ( name, obj->carried_by->player.name ) &&
valid_dg_target ( obj->carried_by, TRUE ) )
return obj->carried_by;
if ( obj->worn_by &&
isname ( name, obj->worn_by->player.name ) &&
valid_dg_target ( obj->worn_by, TRUE ) )
return obj->worn_by;
if ( ( r = obj_room ( obj ) ) != NULL )
for ( ch = r->people; ch; ch = ch->next_in_room )
if ( isname ( name, ch->player.name ) && valid_dg_target ( ch, TRUE ) )
return ch;
for ( ch = character_list; ch; ch = ch->next )
if ( isname ( name, ch->player.name ) && valid_dg_target ( ch, TRUE ) )
return ch;
}
return NULL;
}
Character *get_char_by_obj ( obj_data * obj,char *name )
{
Character *ch;
room_rnum r = NULL;
if ( *name == UID_CHAR )
{
ch = find_char ( atoi ( name + 1 ) );
if ( ch && valid_dg_target ( ch, TRUE ) )
return ch;
}
else
{
if ( obj->carried_by &&
isname ( name, obj->carried_by->player.name ) &&
valid_dg_target ( obj->carried_by, TRUE ) )
return obj->carried_by;
if ( obj->worn_by &&
isname ( name, obj->worn_by->player.name ) &&
valid_dg_target ( obj->worn_by, TRUE ) )
return obj->worn_by;
if ( ( r = obj_room ( obj ) ) != NULL )
for ( ch = r->people; ch; ch = ch->next_in_room )
if ( isname ( name, ch->player.name ) && valid_dg_target ( ch, TRUE ) )
return ch;
for ( ch = character_list; ch; ch = ch->next )
if ( isname ( name, ch->player.name ) && valid_dg_target ( ch, TRUE ) )
return ch;
}
return NULL;
}
/*
* returns a pointer to the first character in world by name name,
* or NULL if none found. Starts searching in room room first
*/
Character *get_char_by_room ( Room * room,const char *name )
{
Character *ch;
if ( *name == UID_CHAR )
{
ch = find_char ( atoi ( name + 1 ) );
if ( ch && valid_dg_target ( ch, TRUE ) )
return ch;
}
else
{
for ( ch = room->people; ch; ch = ch->next_in_room )
if ( isname ( name, ch->player.name ) && valid_dg_target ( ch, TRUE ) )
return ch;
for ( ch = character_list; ch; ch = ch->next )
if ( isname ( name, ch->player.name ) && valid_dg_target ( ch, TRUE ) )
return ch;
}
return NULL;
}
/*
* returns the object in the world with name name, or NULL if not found
* search based on obj
*/
obj_data *get_obj_by_obj ( obj_data * obj,const char *name )
{
obj_data *i = NULL;
room_rnum rm;
if ( *name == UID_CHAR )
return find_obj ( atoi ( name + 1 ) );
if ( !strcasecmp ( name, "self" ) || !strcasecmp ( name, "me" ) )
return obj;
if ( obj->contains && ( i = get_obj_in_list ( name, obj->contains ) ) )
return i;
if ( obj->in_obj && isname ( name, obj->in_obj->name ) )
return obj->in_obj;
if ( obj->worn_by && ( i = get_object_in_equip ( obj->worn_by, name ) ) )
return i;
if ( obj->carried_by &&
( i = get_obj_in_list ( name, obj->carried_by->carrying ) ) )
return i;
if ( ( ( rm = obj_room ( obj ) ) != NULL ) &&
( i = get_obj_in_list ( name, rm->contents ) ) )
return i;
return NULL;
}
/* only searches the room */
obj_data *get_obj_in_room ( Room * room, char *name )
{
struct obj_data *obj;
if ( room )
{
for ( obj = room->contents; obj; obj = obj->next_content )
if ( isname ( name, obj->name ) )
return obj;
}
return NULL;
}
/* returns obj with name - searches room, then world */
obj_data *get_obj_by_room ( Room *room, const char *name )
{
obj_data *obj = NULL;
if ( *name == UID_CHAR )
return find_obj ( atoi ( name + 1 ) );
if ( room )
{
for ( obj = room->contents; obj; obj = obj->next_content )
if ( isname ( name, obj->name ) )
return obj;
}
return get_obj ( name );
}
void check_time_triggers ( void )
{
Character *ch;
obj_data *obj;
Room *room=NULL;
int nr;
struct script_data *sc;
for ( ch = character_list; ch; ch = ch->next )
{
if ( SCRIPT ( ch ) )
{
sc = SCRIPT ( ch );
if ( IS_SET ( SCRIPT_TYPES ( sc ), MTRIG_TIME ) )
time_mtrigger ( ch );
}
}
for ( olt_it i = object_list.begin(); i != object_list.end(); i++ )
{
obj = ( i->second );
if ( !obj->extracted && SCRIPT ( obj ) )
{
sc = SCRIPT ( obj );
if ( IS_SET ( SCRIPT_TYPES ( sc ), OTRIG_TIME ) )
time_otrigger ( obj );
}
}
for ( nr = 0; nr <= top_of_world; nr++ )
{
if ( world_vnum[nr] && SCRIPT ( world_vnum[nr] ) )
{
room = world_vnum[nr];
sc = SCRIPT ( room );
if ( IS_SET ( SCRIPT_TYPES ( sc ), WTRIG_TIME ) )
time_wtrigger ( room );
}
}
}
/* checks every PULSE_DG_SCRIPT for random triggers */
void script_trigger_check ( void )
{
Character *ch;
obj_data *obj;
Room *room=NULL;
int nr;
struct script_data *sc;
for ( ch = character_list; ch; ch = ch->next )
{
if ( SCRIPT ( ch ) )
{
sc = SCRIPT ( ch );
if ( IS_SET ( SCRIPT_TYPES ( sc ), MTRIG_RANDOM ) )
random_mtrigger ( ch );
}
}
for ( olt_it i = object_list.begin(); i != object_list.end(); i++ )
{
obj = ( i->second );
if ( !obj->extracted && SCRIPT ( obj ) )