-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagic.cpp
executable file
·6544 lines (5693 loc) · 173 KB
/
magic.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.~'~*
* ------------------------------------------------------------------------ *
* Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* ------------------------------------------------------------------------ *
* Spell handling module *
****************************************************************************/
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "mud.h"
#include "connection.h"
#include "ScentController.h"
#include "Scent.h"
/*
* Local functions.
*/
void say_spell ( CHAR_DATA *ch, int sn ) ;
CHAR_DATA *make_poly_mob (CHAR_DATA *ch, int vnum) ;
ch_ret spell_affect ( int sn, int level, CHAR_DATA *ch, void *vo ) ;
ch_ret spell_affectchar ( int sn, int level, CHAR_DATA *ch, void *vo ) ;
// Forward declarations
void do_look(Character * ch, const char* argument);
void do_recall(Character * ch, const char* argument);
ch_ret spell_null(int sn, int level, Character * ch, void * vo);
/*
* Is immune to a damage type
*/
bool is_immune( CHAR_DATA *ch, sh_int damtype )
{
switch( damtype )
{
case SD_FIRE: if (IS_SET(ch->immune, RIS_FIRE)) return TRUE;
case SD_COLD: if (IS_SET(ch->immune, RIS_COLD)) return TRUE;
case SD_ELECTRICITY: if (IS_SET(ch->immune, RIS_ELECTRICITY)) return TRUE;
case SD_ENERGY: if (IS_SET(ch->immune, RIS_ENERGY)) return TRUE;
case SD_ACID: if (IS_SET(ch->immune, RIS_ACID)) return TRUE;
case SD_POISON: if (IS_SET(ch->immune, RIS_POISON)) return TRUE;
case SD_DRAIN: if (IS_SET(ch->immune, RIS_DRAIN)) return TRUE;
}
return FALSE;
}
/*
* Lookup a skill by name, only stopping at skills the player has.
*/
int ch_slookup( CHAR_DATA *ch, const char *name )
{
int sn;
if ( IS_NPC(ch) )
return skill_lookup( name );
for ( sn = 0; sn < top_sn; sn++ )
{
if ( skill_table[sn]->name_.length() == 0 )
break;
if ( ch->pcdata->learned[sn] > 0
&& ch->level >= skill_table[sn]->skill_level[ch->Class]
&& LOWER(name[0]) == LOWER(skill_table[sn]->name_.str()[0])
&& !str_prefix( name, skill_table[sn]->name_.c_str() ) )
return sn;
}
return -1;
}
/*
* Lookup an herb by name.
*/
int herb_lookup( const char *name )
{
int sn;
for ( sn = 0; sn < top_herb; sn++ )
{
if ( !herb_table[sn] || herb_table[sn]->name_.length() == 0 )
return -1;
if ( LOWER(name[0]) == LOWER(herb_table[sn]->name_.str()[0])
&& !str_prefix( name, herb_table[sn]->name_.c_str() ) )
return sn;
}
return -1;
}
/*
* Lookup a personal skill
*/
int personal_lookup( CHAR_DATA *ch, const char *name )
{
return -1;
}
/*
* Lookup a skill by name.
*/
int skill_lookup( const char *name )
{
int sn;
/* Testaur - test for exact matches before prefixes */
if( (sn=bsearch_skill_exact(name, gsn_first_spell, gsn_first_skill-1)) != -1 )
return sn;
if( (sn=bsearch_skill_exact(name, gsn_first_skill, gsn_first_weapon-1)) != -1 )
return sn;
if( (sn=bsearch_skill_exact(name, gsn_first_weapon, gsn_first_tongue-1)) != -1 )
return sn;
if( (sn=bsearch_skill_exact(name, gsn_first_tongue, gsn_top_sn-1)) != -1 )
return sn;
if ( (sn=bsearch_skill(name, gsn_first_spell, gsn_first_skill-1)) != -1 )
return sn;
if ( (sn=bsearch_skill(name, gsn_first_skill, gsn_first_weapon-1)) != -1 )
return sn;
if ( (sn=bsearch_skill(name, gsn_first_weapon, gsn_first_tongue-1)) != -1 )
return sn;
if ( (sn=bsearch_skill(name, gsn_first_tongue, gsn_top_sn-1)) == -1
&& gsn_top_sn < top_sn )
{
for ( sn = gsn_top_sn; sn < top_sn; sn++ )
{
if ( !skill_table[sn] || skill_table[sn]->name_.length() == 0 )
return -1;
if ( LOWER(name[0]) == LOWER(skill_table[sn]->name_.str()[0])
&& !str_prefix( name, skill_table[sn]->name_.c_str() ) )
return sn;
}
return -1;
}
return sn;
}
/*
* Return a skilltype pointer based on sn -Thoric
* Returns NULL if bad, unused or personal sn.
*/
SkillType *get_skilltype( int sn )
{
if ( sn >= TYPE_PERSONAL )
return NULL;
if ( sn >= TYPE_HERB )
return IS_VALID_HERB(sn-TYPE_HERB) ? herb_table[sn-TYPE_HERB] : NULL;
if ( sn >= TYPE_HIT )
return NULL;
return IS_VALID_SN(sn) ? skill_table[sn] : NULL;
}
/*
* Perform a binary search on a section of the skill table -Thoric
* Each different section of the skill table is sorted alphabetically
*/
int bsearch_skill( const char *name, int first, int top )
{
int sn;
for (;;)
{
sn = (first + top) >> 1;
if ( LOWER(name[0]) == LOWER(skill_table[sn]->name_.str()[0])
&& !str_prefix(name, skill_table[sn]->name_.c_str()) )
return sn;
if (first >= top)
return -1;
if ( strcmp(name, skill_table[sn]->name_.c_str()) < 1)
top = sn - 1;
else
first = sn + 1;
}
return -1;
}
/*
* Perform a binary search on a section of the skill table -Thoric
* Each different section of the skill table is sorted alphabetically
* Check for exact matches only
*/
int bsearch_skill_exact( const char *name, int first, int top )
{
int sn;
for (;;)
{
sn = (first + top) >> 1;
if ( skill_table[sn]->name_.ciEqual(name) )
return sn;
if (first >= top)
return -1;
if (strcmp(name, skill_table[sn]->name_.c_str()) < 1)
top = sn - 1;
else
first = sn + 1;
}
return -1;
}
/*
* Perform a binary search on a section of the skill table
* Each different section of the skill table is sorted alphabetically
* Only match skills player knows -Thoric
*/
int ch_bsearch_skill( CHAR_DATA *ch, const char *name, int first, int top )
{
int sn;
/* Testaur - first test for exact matches */
for (;;)
{
sn = (first + top) >> 1;
if ( LOWER(name[0]) == LOWER(skill_table[sn]->name_.str()[0])
&& skill_table[sn]->name_.ciEqual(name)
&& ch->pcdata->learned[sn] > 0
&& ch->level >= skill_table[sn]->skill_level[ch->Class] )
return sn;
if (first >= top)
break;
if ( strcmp(name, skill_table[sn]->name_.c_str()) < 1 )
top = sn - 1;
else
first = sn + 1;
}
for (;;)
{
sn = (first + top) >> 1;
if ( LOWER(name[0]) == LOWER(skill_table[sn]->name_.str()[0])
&& !str_prefix(name, skill_table[sn]->name_.c_str())
&& ch->pcdata->learned[sn] > 0
&& ch->level >= skill_table[sn]->skill_level[ch->Class] )
return sn;
if (first >= top)
return -1;
if (strcmp( name, skill_table[sn]->name_.c_str()) < 1)
top = sn - 1;
else
first = sn + 1;
}
return -1;
}
/* KSILYAN
Small routine to search for a component.
*/
OBJ_DATA * find_vnum_component( CHAR_DATA * ch, int vnum )
{
OBJ_DATA *obj, *obj2;
for ( obj = ch->last_carrying; obj; obj = obj->prev_content )
{
if ( can_see_obj(ch, obj) )
{
if ( IS_SET(obj->extra_flags_2, ITEM_COMPONENT_CONTAINER) )
{
for ( obj2 = obj->last_content; obj2; obj2 = obj2->prev_content )
{
if ( obj2->pIndexData->vnum == vnum )
return obj2;
}
}
if ( obj->pIndexData->vnum == vnum )
return obj;
}
}
return NULL;
}
int find_spell( CHAR_DATA *ch, const char *name, bool know )
{
if ( IS_NPC(ch) || !know )
return bsearch_skill( name, gsn_first_spell, gsn_first_skill-1 );
else
return ch_bsearch_skill( ch, name, gsn_first_spell, gsn_first_skill-1 );
}
int find_skill( CHAR_DATA *ch, const char *name, bool know )
{
if ( IS_NPC(ch) || !know )
return bsearch_skill( name, gsn_first_skill, gsn_first_weapon-1 );
else
return ch_bsearch_skill( ch, name, gsn_first_skill, gsn_first_weapon-1 );
}
int find_weapon( CHAR_DATA *ch, const char *name, bool know )
{
if ( IS_NPC(ch) || !know )
return bsearch_skill( name, gsn_first_weapon, gsn_first_tongue-1 );
else
return ch_bsearch_skill( ch, name, gsn_first_weapon, gsn_first_tongue-1 );
}
int find_tongue( CHAR_DATA *ch, const char *name, bool know )
{
if ( IS_NPC(ch) || !know )
return bsearch_skill( name, gsn_first_tongue, gsn_top_sn-1 );
else
return ch_bsearch_skill( ch, name, gsn_first_tongue, gsn_top_sn-1 );
}
/*
* Lookup a skill by slot number.
* Used for object loading.
*/
int slot_lookup( int slot )
{
extern bool fBootDb;
int sn;
if ( slot <= 0 )
return -1;
for ( sn = 0; sn < top_sn; sn++ )
if ( slot == skill_table[sn]->slot )
return sn;
if ( fBootDb )
{
bug( "Slot_lookup: bad slot %d.", slot );
abort( );
}
return -1;
}
/*
* Fancy message handling for a successful casting -Thoric
*/
void successful_casting( SkillType *skill, CHAR_DATA *ch,
CHAR_DATA *victim, OBJ_DATA *obj )
{
sh_int chitroom = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_ACTION);
sh_int chit = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HIT);
sh_int chitme = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HITME);
if ( skill->target != TAR_CHAR_OFFENSIVE )
{
chit = chitroom;
chitme = chitroom;
}
if ( ch && ch != victim )
{
if ( skill->hit_char && skill->hit_char[0] != '\0' )
act( chit, skill->hit_char, ch, obj, victim, TO_CHAR );
else
if ( skill->type == SKILL_SPELL )
act( chit, "Ok.", ch, NULL, NULL, TO_CHAR );
}
if ( ch && skill->hit_room && skill->hit_room[0] != '\0' )
act( chitroom, skill->hit_room, ch, obj, victim, TO_NOTVICT );
if ( ch && victim && skill->hit_vict && skill->hit_vict[0] != '\0' )
{
if ( ch != victim )
act( chitme, skill->hit_vict, ch, obj, victim, TO_VICT );
else
act( chitme, skill->hit_vict, ch, obj, victim, TO_CHAR );
}
else
if ( ch && ch == victim && skill->type == SKILL_SPELL )
act( chitme, "Ok.", ch, NULL, NULL, TO_CHAR );
}
/*
* Fancy message handling for a failed casting -Thoric
*/
void failed_casting( SkillType *skill, CHAR_DATA *ch,
CHAR_DATA *victim, OBJ_DATA *obj )
{
sh_int chitroom = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_ACTION);
sh_int chit = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HIT);
sh_int chitme = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HITME);
if ( skill->target != TAR_CHAR_OFFENSIVE )
{
chit = chitroom;
chitme = chitroom;
}
if ( ch && ch != victim )
{
if ( skill->miss_char && skill->miss_char[0] != '\0' )
act( chit, skill->miss_char, ch, obj, victim, TO_CHAR );
else
if ( skill->type == SKILL_SPELL )
act( chit, "You failed.", ch, NULL, NULL, TO_CHAR );
}
if ( ch && skill->miss_room && skill->miss_room[0] != '\0' )
act( chitroom, skill->miss_room, ch, obj, victim, TO_NOTVICT );
if ( ch && victim && skill->miss_vict && skill->miss_vict[0] != '\0' )
{
if ( ch != victim )
act( chitme, skill->miss_vict, ch, obj, victim, TO_VICT );
else
act( chitme, skill->miss_vict, ch, obj, victim, TO_CHAR );
}
else
if ( ch && ch == victim )
{
if ( skill->miss_char && skill->miss_char[0] != '\0' )
act( chitme, skill->miss_char, ch, obj, victim, TO_CHAR );
else
if ( skill->type == SKILL_SPELL )
act( chitme, "You failed.", ch, NULL, NULL, TO_CHAR );
}
}
/*
* Fancy message handling for being immune to something -Thoric
*/
void immune_casting( SkillType *skill, CHAR_DATA *ch,
CHAR_DATA *victim, OBJ_DATA *obj )
{
sh_int chitroom = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_ACTION);
sh_int chit = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HIT);
sh_int chitme = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HITME);
if ( skill->target != TAR_CHAR_OFFENSIVE )
{
chit = chitroom;
chitme = chitroom;
}
if ( ch && ch != victim )
{
if ( skill->imm_char && skill->imm_char[0] != '\0' )
act( chit, skill->imm_char, ch, obj, victim, TO_CHAR );
else
if ( skill->miss_char && skill->miss_char[0] != '\0' )
act( chit, skill->hit_char, ch, obj, victim, TO_CHAR );
else
if ( skill->type == SKILL_SPELL || skill->type == SKILL_SKILL )
act( chit, "That appears to have no effect.", ch, NULL, NULL, TO_CHAR );
}
if ( ch && skill->imm_room && skill->imm_room[0] != '\0' )
act( chitroom, skill->imm_room, ch, obj, victim, TO_NOTVICT );
else
if ( ch && skill->miss_room && skill->miss_room[0] != '\0' )
act( chitroom, skill->miss_room, ch, obj, victim, TO_NOTVICT );
if ( ch && victim && skill->imm_vict && skill->imm_vict[0] != '\0' )
{
if ( ch != victim )
act( chitme, skill->imm_vict, ch, obj, victim, TO_VICT );
else
act( chitme, skill->imm_vict, ch, obj, victim, TO_CHAR );
}
else
if ( ch && victim && skill->miss_vict && skill->miss_vict[0] != '\0' )
{
if ( ch != victim )
act( chitme, skill->miss_vict, ch, obj, victim, TO_VICT );
else
act( chitme, skill->miss_vict, ch, obj, victim, TO_CHAR );
}
else
if ( ch && ch == victim )
{
if ( skill->imm_char && skill->imm_char[0] != '\0' )
act( chit, skill->imm_char, ch, obj, victim, TO_CHAR );
else
if ( skill->miss_char && skill->miss_char[0] != '\0' )
act( chit, skill->hit_char, ch, obj, victim, TO_CHAR );
else
if ( skill->type == SKILL_SPELL || skill->type == SKILL_SKILL )
act( chit, "That appears to have no affect.", ch, NULL, NULL, TO_CHAR );
}
}
/*
* Utter mystical words for an sn.
*/
void say_spell( CHAR_DATA *ch, int sn )
{
char buf [MAX_STRING_LENGTH];
char buf2 [MAX_STRING_LENGTH];
CHAR_DATA *rch;
const char *pName;
int iSyl;
int length;
SkillType *skill = get_skilltype( sn );
struct syl_type
{
const char * old;
const char * New;
};
static const struct syl_type syl_table[] =
{
{ " ", " " },
{ "ar", "abra" },
{ "au", "kada" },
{ "bless", "fido" },
{ "blind", "nose" },
{ "bur", "mosa" },
{ "cu", "judi" },
{ "de", "oculo" },
{ "en", "unso" },
{ "light", "dies" },
{ "lo", "hi" },
{ "mor", "zak" },
{ "move", "sido" },
{ "ness", "lacri" },
{ "ning", "illa" },
{ "per", "duda" },
{ "ra", "gru" },
{ "re", "candus" },
{ "son", "sabru" },
{ "tect", "infra" },
{ "tri", "cula" },
{ "ven", "nofo" },
{ "a", "a" }, { "b", "b" }, { "c", "q" }, { "d", "e" },
{ "e", "z" }, { "f", "y" }, { "g", "o" }, { "h", "p" },
{ "i", "u" }, { "j", "y" }, { "k", "t" }, { "l", "r" },
{ "m", "w" }, { "n", "i" }, { "o", "a" }, { "p", "s" },
{ "q", "d" }, { "r", "f" }, { "s", "g" }, { "t", "h" },
{ "u", "j" }, { "v", "z" }, { "w", "x" }, { "x", "n" },
{ "y", "l" }, { "z", "k" },
{ "", "" }
};
buf[0] = '\0';
for ( pName = skill->name_.c_str(); *pName != '\0'; pName += length )
{
for ( iSyl = 0; (length = strlen(syl_table[iSyl].old)) != 0; iSyl++ )
{
if ( !str_prefix( syl_table[iSyl].old, pName ) )
{
strcat( buf, syl_table[iSyl].New );
break;
}
}
if ( length == 0 )
length = 1;
}
sprintf( buf2, "$n utters the words, '%s'.", buf );
sprintf( buf, "$n utters the words, '%s'.", skill->name_.c_str() );
for ( rch = ch->GetInRoom()->first_person; rch; rch = rch->next_in_room )
{
if ( rch != ch )
act( AT_MAGIC, ch->Class==rch->Class ? buf : buf2,
ch, NULL, rch, TO_VICT );
}
return;
}
/*
* Make adjustments to saving throw based in RIS -Thoric
*/
int ris_save( CHAR_DATA *ch, int chance, int ris )
{
sh_int modifier;
modifier = 10;
if ( IS_SET(ch->immune, ris ) )
modifier -= 10;
if ( IS_SET(ch->resistant, ris ) )
modifier -= 2;
if ( IS_SET(ch->susceptible, ris ) )
modifier += 2;
if ( modifier <= 0 )
return 1000;
if ( modifier == 10 )
return chance;
return (chance * modifier) / 10;
}
/* -Thoric
* Fancy dice expression parsing complete with order of operations,
* simple exponent support, dice support as well as a few extra
* variables: L = level, H = hp, M = mana, V = move, S = str, X = dex
* I = int, W = wis, C = con, A = cha, U = luck, A = age
*
* Used for spell dice parsing, ie: 3d8+L-6
*
*/
int rd_parse(CHAR_DATA *ch, int level, char *exp)
{
unsigned int x;
int lop = 0, gop = 0, eop = 0;
char operation;
char *sexp[2];
int total = 0;
unsigned int len = 0;
// take care of nulls coming in
if (!exp || !strlen(exp))
return 0;
// get rid of brackets if they surround the entire expresion
if ((*exp == '(') && !index(exp+1,'(') && exp[strlen(exp)-1] == ')')
{
exp[strlen(exp)-1] = '\0';
exp++;
}
// check if the expresion is just a number
len = strlen(exp);
if ( len == 1 && isalpha(exp[0]) )
{
switch(exp[0])
{
case 'L': case 'l': return level;
case 'H': case 'h': return ch->hit;
case 'M': case 'm': return ch->mana;
case 'V': case 'v': return ch->move;
case 'S': case 's': return ch->getStr();
case 'I': case 'i': return ch->getInt();
case 'W': case 'w': return ch->getWis();
case 'X': case 'x': return ch->getDex();
case 'C': case 'c': return ch->getCon();
case 'A': case 'a': return ch->getCha();
case 'U': case 'u': return ch->getLck();
case 'Y': case 'y': return get_age(ch);
case 'F': case 'f': return IS_NPC(ch) ? 1 : ch->pcdata->favor;
}
}
for (x = 0; x < len; ++x)
{
if (!isdigit(exp[x]) && !isspace(exp[x]))
break;
}
if (x == len) return(atoi(exp));
/* break it into 2 parts */
for (x = 0; x < strlen(exp); ++x)
{
switch(exp[x])
{
case '^':
if (!total)
eop = x;
break;
case '-': case '+':
if (!total)
lop = x;
break;
case '*': case '/': case '%': case 'd': case 'D':
if (!total)
gop = x;
break;
case '(':
++total;
break;
case ')':
--total;
break;
}
}
if (lop)
x = lop;
else if (gop)
x = gop;
else
x = eop;
operation = exp[x];
exp[x] = '\0';
sexp[0] = exp;
sexp[1] = (char *)(exp+x+1);
/* work it out */
total = rd_parse(ch, level, sexp[0]);
switch(operation)
{
case '-': total -= rd_parse(ch, level, sexp[1]); break;
case '+': total += rd_parse(ch, level, sexp[1]); break;
case '*': total *= rd_parse(ch, level, sexp[1]); break;
case '/': total /= rd_parse(ch, level, sexp[1]); break;
case '%': total %= rd_parse(ch, level, sexp[1]); break;
case 'd': case 'D': total = dice( total, rd_parse(ch, level, sexp[1]) ); break;
case '^':
{
int y = rd_parse(ch, level, sexp[1]), z = total;
for (int x = 1; x < y; ++x)
z *= total;
total = z;
break;
}
}
return total;
}
/* wrapper function so as not to destroy exp */
int dice_parse(CHAR_DATA *ch, int level, char *exp)
{
char buf[MAX_INPUT_LENGTH];
strcpy( buf, exp );
return rd_parse(ch, level, buf);
}
/*
* Compute a saving throw.
* Negative apply's make saving throw better.
*/
bool saves_poison_death( int level, CHAR_DATA *victim )
{
int save;
save = 50 + ( victim->level - level - victim->saving_poison_death ) * 5;
save = URANGE( 5, save, 95 );
return victim->ChanceRoll( save );
}
bool saves_wands( int level, CHAR_DATA *victim )
{
int save;
if ( IS_SET( victim->immune, RIS_MAGIC ) )
return TRUE;
save = 50 + ( victim->level - level - victim->saving_wand ) * 5;
save = URANGE( 5, save, 95 );
return victim->ChanceRoll( save );
}
bool saves_para_petri( int level, CHAR_DATA *victim )
{
int save;
save = 50 + ( victim->level - level - victim->saving_para_petri ) * 5;
save = URANGE( 5, save, 95 );
return victim->ChanceRoll( save );
}
bool saves_breath( int level, CHAR_DATA *victim )
{
int save;
save = 50 + ( victim->level - level - victim->saving_breath ) * 5;
save = URANGE( 5, save, 95 );
return victim->ChanceRoll( save );
}
bool saves_spell_staff( int level, CHAR_DATA *victim )
{
int save;
if ( IS_SET( victim->immune, RIS_MAGIC ) )
return TRUE;
if ( IS_NPC( victim ) && level > 10 )
level -= 5;
save = 50 + ( victim->level - level - victim->saving_spell_staff ) * 5;
save = URANGE( 5, save, 95 );
return victim->ChanceRoll( save );
}
/*
* Process the spell's required components, if any -Thoric
* -----------------------------------------------
* T### check for item of type ###
* V##### check for item of vnum #####
* Kword check for item with keyword 'word'
* G##### check if player has ##### amount of gold
* H#### check if player has #### amount of hitpoints
*
* Special operators:
* ! spell fails if player has this
* + don't consume this component
* @ decrease component's value[0], and extract if it reaches 0
* # decrease component's value[1], and extract if it reaches 0
* $ decrease component's value[2], and extract if it reaches 0
* % decrease component's value[3], and extract if it reaches 0
* ^ decrease component's value[4], and extract if it reaches 0
* & decrease component's value[5], and extract if it reaches 0
*/
bool process_spell_components( CHAR_DATA *ch, int sn )
{
SkillType *skill = get_skilltype(sn);
char *comp = skill->components;
char *check;
char arg[MAX_INPUT_LENGTH];
bool consume, fail, found;
int val, value;
OBJ_DATA *obj;
/* if no components necessary, then everything is cool */
if ( !comp || comp[0] == '\0' )
return TRUE;
while ( comp[0] != '\0' )
{
comp = one_argument( comp, arg );
consume = TRUE;
fail = found = FALSE;
val = -1;
switch( arg[1] )
{
default: check = arg+1; break;
case '!': check = arg+2; fail = TRUE; break;
case '+': check = arg+2; consume = FALSE; break;
case '@': check = arg+2; val = 0; break;
case '#': check = arg+2; val = 1; break;
case '$': check = arg+2; val = 2; break;
case '%': check = arg+2; val = 3; break;
case '^': check = arg+2; val = 4; break;
case '&': check = arg+2; val = 5; break;
}
value = atoi(check);
obj = NULL;
switch( UPPER(arg[0]) )
{
case 'T':
for ( obj = ch->first_carrying; obj; obj = obj->next_content )
if ( obj->item_type == value )
{
if ( fail )
{
send_to_char( "Something disrupts the casting of this spell...\r\n", ch );
return FALSE;
}
found = TRUE;
break;
}
break;
case 'V':
obj = find_vnum_component(ch, value);
if (obj != NULL)
{
if (fail)
{
send_to_char( "Something disrupts the casting of this spell...\r\n", ch);
return FALSE;
}
found = TRUE;
break;
}
/* KSILYAN - reworked component searching
for ( obj = ch->first_carrying; obj; obj = obj->next_content )
if ( obj->pIndexData->vnum == value )
{
if ( fail )
{
send_to_char( "Something disrupts the casting of this spell...\r\n", ch );
return FALSE;
}
found = TRUE;
break;
}*/
break;
case 'K':
for ( obj = ch->first_carrying; obj; obj = obj->next_content )
if ( nifty_is_name( check, obj->name_.c_str() ) )
{
if ( fail )
{
send_to_char( "Something disrupts the casting of this spell...\r\n", ch );
return FALSE;
}
found = TRUE;
break;
}
break;
case 'G':
if ( ch->gold >= value ) {
if ( fail ) {
send_to_char( "Something disrupts the casting of this spell...\r\n", ch );
return FALSE;
} else {
if ( consume ) {
set_char_color( AT_GOLD, ch );
send_to_char( "You feel a little lighter...\r\n", ch );
ch->gold -= value;
}
continue;
}
}
break;
case 'H':
if ( ch->hit >= value ) {
if ( fail ) {
send_to_char( "Something disrupts the casting of this spell...\r\n", ch );
return FALSE;
} else {
if ( consume ) {
set_char_color( AT_BLOOD, ch );
send_to_char( "You feel a little weaker...\r\n", ch );
ch->hit -= value;
update_pos( ch );
}
continue;
}
}
break;
}
/* having this component would make the spell fail... if we get
here, then the caster didn't have that component */
if ( fail )
continue;
if ( !found )
{
send_to_char( "Something is missing...\r\n", ch );
return FALSE;
}
if ( obj )
{
if (obj->item_type == ITEM_COMPONENT)
{
obj->value[OBJECT_COMPONENT_QUANTITY]--;
if (obj->value[OBJECT_COMPONENT_QUANTITY] == 0)
{
extract_obj(obj, TRUE);
}
act( AT_MAGIC, "You take $p, which glows briefly, then disappears!", ch, obj, NULL, TO_CHAR );
act( AT_MAGIC, "$n holds $p, which glows briefly, then disappears!", ch, obj, NULL, TO_ROOM );
}
else
{
if ( val >=0 && val < 6 )
{
separate_obj(obj);
if ( obj->value[val] <= 0 )
return FALSE;
else if ( --obj->value[val] == 0 )
{
act( AT_MAGIC, "$p glows briefly, then disappears in a puff of smoke!", ch, obj, NULL, TO_CHAR );
act( AT_MAGIC, "$p glows briefly, then disappears in a puff of smoke!", ch, obj, NULL, TO_ROOM );
extract_obj( obj, TRUE );
}
else
act( AT_MAGIC, "$p glows briefly and a whisp of smoke rises from it.", ch, obj, NULL, TO_CHAR );
}
else if ( consume )
{
separate_obj(obj);
act( AT_MAGIC, "$p glows brightly, then disappears in a puff of smoke!", ch, obj, NULL, TO_CHAR );
act( AT_MAGIC, "$p glows brightly, then disappears in a puff of smoke!", ch, obj, NULL, TO_ROOM );
extract_obj( obj, TRUE );
}
else
{
int count = obj->count;
obj->count = 1;
act( AT_MAGIC, "$p glows briefly.", ch, obj, NULL, TO_CHAR );
obj->count = count;
}
}
}
}
return TRUE;
}
int pAbort;
/*
* Locate targets.
*/
void *locate_targets( CHAR_DATA *ch, char *arg, int sn,
CHAR_DATA **victim, OBJ_DATA **obj )
{
SkillType *skill = get_skilltype( sn );
void *vo = NULL;
*victim = NULL;
*obj = NULL;
switch ( skill->target )
{
default:
bug( "Do_cast: bad target for sn %d.", sn );
return &pAbort;
case TAR_IGNORE:
break;
case TAR_CHAR_OFFENSIVE:
if ( arg[0] == '\0' )
{
if ( ( *victim = ch->GetVictim() ) == NULL )