forked from Atlantis-PBEM/Atlantis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spells.cpp
2145 lines (1871 loc) · 47.7 KB
/
spells.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
// START A3HEADER
//
// This source file is part of the Atlantis PBM game program.
// Copyright (C) 1995-1999 Geoff Dunbar
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program, in the file license.txt. If not, write
// to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
// See the Atlantis Project web page for details:
// http://www.prankster.com/project
//
// END A3HEADER
#include "game.h"
#include "gamedata.h"
static int RandomiseSummonAmount(int num)
{
int retval, i;
retval = 0;
for (i = 0; i < 2 * num; i++)
{
if (getrandom(2))
retval++;
}
if (retval < 1 && num > 0)
retval = 1;
return retval;
}
void Game::ProcessCastOrder(Unit * u,AString * o, OrdersCheck *pCheck )
{
AString * token = o->gettoken();
if (!token) {
ParseError( pCheck, u, 0, "CAST: No skill given.");
return;
}
int sk = ParseSkill(token);
delete token;
if (sk==-1) {
ParseError( pCheck, u, 0, "CAST: Invalid skill.");
return;
}
if ( !( SkillDefs[sk].flags & SkillType::MAGIC )) {
ParseError( pCheck, u, 0, "CAST: That is not a magic skill.");
return;
}
if ( !( SkillDefs[sk].flags & SkillType::CAST )) {
ParseError( pCheck, u, 0, "CAST: That skill cannot be CAST.");
return;
}
RangeType *rt = NULL;
if ( !pCheck ) {
//
// XXX -- should be error checking spells
//
switch(sk) {
case S_MIND_READING:
ProcessMindReading(u,o, pCheck );
break;
case S_CONSTRUCT_PORTAL:
case S_ENCHANT_SWORDS:
case S_ENCHANT_ARMOR:
case S_ENCHANT_SHIELDS:
case S_CONSTRUCT_GATE:
case S_ENGRAVE_RUNES_OF_WARDING:
case S_SUMMON_IMPS:
case S_SUMMON_DEMON:
case S_SUMMON_BALROG:
case S_SUMMON_SKELETONS:
case S_RAISE_UNDEAD:
case S_SUMMON_LICH:
case S_DRAGON_LORE:
case S_WOLF_LORE:
case S_EARTH_LORE:
case S_SUMMON_WIND:
case S_CREATE_RING_OF_INVISIBILITY:
case S_CREATE_CLOAK_OF_INVULNERABILITY:
case S_CREATE_STAFF_OF_FIRE:
case S_CREATE_STAFF_OF_LIGHTNING:
case S_CREATE_AMULET_OF_TRUE_SEEING:
case S_CREATE_AMULET_OF_PROTECTION:
case S_CREATE_RUNESWORD:
case S_CREATE_SHIELDSTONE:
case S_CREATE_MAGIC_CARPET:
case S_CREATE_FLAMING_SWORD:
case S_CREATE_FOOD:
case S_CREATE_AEGIS:
case S_CREATE_WINDCHIME:
case S_CREATE_GATE_CRYSTAL:
case S_CREATE_STAFF_OF_HEALING:
case S_CREATE_SCRYING_ORB:
case S_CREATE_CORNUCOPIA:
case S_CREATE_BOOK_OF_EXORCISM:
case S_CREATE_HOLY_SYMBOL:
case S_CREATE_CENSER:
case S_BLASPHEMOUS_RITUAL:
case S_PHANTASMAL_ENTERTAINMENT:
ProcessGenericSpell(u,sk, pCheck );
break;
case S_CLEAR_SKIES:
rt = FindRange(SkillDefs[sk].range);
if (rt == NULL)
ProcessGenericSpell(u, sk, pCheck);
else
ProcessRegionSpell(u, o, sk, pCheck);
break;
case S_FARSIGHT:
case S_TELEPORTATION:
case S_WEATHER_LORE:
ProcessRegionSpell(u, o, sk, pCheck);
break;
case S_BIRD_LORE:
ProcessBirdLore(u,o, pCheck );
break;
case S_INVISIBILITY:
ProcessInvisibility(u,o, pCheck );
break;
case S_GATE_LORE:
ProcessCastGateLore(u,o, pCheck );
break;
case S_PORTAL_LORE:
ProcessCastPortalLore(u,o, pCheck );
break;
case S_CREATE_PHANTASMAL_BEASTS:
ProcessPhanBeasts(u,o, pCheck );
break;
case S_CREATE_PHANTASMAL_UNDEAD:
ProcessPhanUndead(u,o, pCheck );
break;
case S_CREATE_PHANTASMAL_DEMONS:
ProcessPhanDemons(u,o, pCheck );
break;
case S_TRANSMUTATION:
ProcessTransmutation(u, o, pCheck);
break;
}
}
}
void Game::ProcessMindReading(Unit *u,AString *o, OrdersCheck *pCheck )
{
UnitId *id = ParseUnit(o);
if (!id) {
u->Error("CAST: No unit specified.");
return;
}
CastMindOrder *order = new CastMindOrder;
order->id = id;
order->spell = S_MIND_READING;
order->level = 1;
u->ClearCastOrders();
u->castorders = order;
}
void Game::ProcessBirdLore(Unit *u,AString *o, OrdersCheck *pCheck )
{
AString *token = o->gettoken();
if (!token) {
u->Error("CAST: Missing arguments.");
return;
}
if (*token == "eagle") {
CastIntOrder *order = new CastIntOrder;
order->spell = S_BIRD_LORE;
order->level = 3;
u->ClearCastOrders();
u->castorders = order;
return;
}
if (*token == "direction") {
delete token;
token = o->gettoken();
if (!token) {
u->Error("CAST: Missing arguments.");
return;
}
int dir = ParseDir(token);
delete token;
if (dir == -1 || dir > NDIRS) {
u->Error("CAST: Invalid direction.");
return;
}
CastIntOrder *order = new CastIntOrder;
order->spell = S_BIRD_LORE;
order->level = 1;
order->target = dir;
u->ClearCastOrders();
u->castorders = order;
return;
}
u->Error("CAST: Invalid arguments.");
delete token;
}
void Game::ProcessInvisibility(Unit *u,AString *o, OrdersCheck *pCheck )
{
AString *token = o->gettoken();
if (!token || !(*token == "units")) {
u->Error("CAST: Must specify units to render invisible.");
return;
}
delete token;
CastUnitsOrder *order;
if (u->castorders && u->castorders->type == O_CAST &&
((CastOrder *) u->castorders)->spell == S_INVISIBILITY &&
((CastOrder *) u->castorders)->level == 1) {
order = (CastUnitsOrder *) u->castorders;
} else {
order = new CastUnitsOrder;
order->spell = S_INVISIBILITY;
order->level = 1;
u->ClearCastOrders();
u->castorders = order;
}
UnitId *id = ParseUnit(o);
while (id) {
order->units.Add(id);
id = ParseUnit(o);
}
}
void Game::ProcessPhanDemons(Unit *u,AString *o, OrdersCheck *pCheck )
{
CastIntOrder *order = new CastIntOrder;
order->spell = S_CREATE_PHANTASMAL_DEMONS;
order->level = 0;
order->target = 1;
AString *token = o->gettoken();
if (!token) {
u->Error("CAST: Illusion to summon must be given.");
delete order;
return;
}
if (*token == "imp" || *token == "imps") {
order->level = 1;
}
if (*token == "demon" || *token == "demons") {
order->level = 2;
}
if (*token == "balrog" || *token == "balrogs") {
order->level = 3;
}
delete token;
if (!order->level) {
u->Error("CAST: Can't summon that illusion.");
delete order;
return;
}
token = o->gettoken();
if (!token) {
order->target = 1;
} else {
order->target = token->value();
delete token;
}
u->ClearCastOrders();
u->castorders = order;
}
void Game::ProcessPhanUndead(Unit *u,AString *o, OrdersCheck *pCheck)
{
CastIntOrder *order = new CastIntOrder;
order->spell = S_CREATE_PHANTASMAL_UNDEAD;
order->level = 0;
order->target = 1;
AString *token = o->gettoken();
if (!token) {
u->Error("CAST: Must specify which illusion to summon.");
delete order;
return;
}
if (*token == "skeleton" || *token == "skeletons") {
order->level = 1;
}
if (*token == "undead") {
order->level = 2;
}
if (*token == "lich" || *token == "liches") {
order->level = 3;
}
delete token;
if (!order->level) {
u->Error("CAST: Must specify which illusion to summon.");
delete order;
return;
}
token = o->gettoken();
if (token) {
order->target = token->value();
delete token;
} else {
order->target = 1;
}
u->ClearCastOrders();
u->castorders = order;
}
void Game::ProcessPhanBeasts(Unit *u,AString *o, OrdersCheck *pCheck )
{
CastIntOrder *order = new CastIntOrder;
order->spell = S_CREATE_PHANTASMAL_BEASTS;
order->level = 0;
order->target = 1;
AString *token = o->gettoken();
if (!token) {
u->Error("CAST: Must specify which illusion to summon.");
delete order;
return;
}
if (*token == "wolf" || *token == "wolves") {
order->level = 1;
}
if (*token == "eagle" || *token == "eagles") {
order->level = 2;
}
if (*token == "dragon" || *token == "dragon") {
order->level = 3;
}
delete token;
if (!order->level) {
delete order;
u->Error("CAST: Must specify which illusion to summon.");
return;
}
token = o->gettoken();
if (token) {
order->target = token->value();
delete token;
}
u->ClearCastOrders();
u->castorders = order;
}
void Game::ProcessGenericSpell(Unit *u,int spell, OrdersCheck *pCheck )
{
CastOrder *orders = new CastOrder;
orders->spell = spell;
orders->level = 1;
u->ClearCastOrders();
u->castorders = orders;
}
void Game::ProcessRegionSpell(Unit *u, AString *o, int spell,
OrdersCheck *pCheck)
{
AString *token = o->gettoken();
int x = -1;
int y = -1;
int z = -1;
RangeType *range = FindRange(SkillDefs[spell].range);
if (token) {
if (*token == "region") {
delete token;
token = o->gettoken();
if (!token) {
u->Error("CAST: Region X coordinate not specified.");
return;
}
x = token->value();
delete token;
token = o->gettoken();
if (!token) {
u->Error("CAST: Region Y coordinate not specified.");
return;
}
y = token->value();
delete token;
if (range && (range->flags & RangeType::RNG_CROSS_LEVELS)) {
token = o->gettoken();
if (token) {
z = token->value();
delete token;
if (z < 0 || (z >= Globals->UNDERWORLD_LEVELS +
Globals->UNDERDEEP_LEVELS +
Globals->ABYSS_LEVEL + 2)) {
u->Error("CAST: Invalid Z coordinate specified.");
return;
}
}
}
} else {
delete token;
}
}
if (x == -1) x = u->object->region->xloc;
if (y == -1) y = u->object->region->yloc;
if (z == -1) z = u->object->region->zloc;
CastRegionOrder *order;
if (spell == S_TELEPORTATION)
order = new TeleportOrder;
else
order = new CastRegionOrder;
order->spell = spell;
order->level = 1;
order->xloc = x;
order->yloc = y;
order->zloc = z;
u->ClearCastOrders();
/* Teleports happen late in the turn! */
if (spell == S_TELEPORTATION)
u->teleportorders = (TeleportOrder *) order;
else
u->castorders = order;
}
void Game::ProcessCastPortalLore(Unit *u,AString *o, OrdersCheck *pCheck )
{
AString *token = o->gettoken();
if (!token) {
u->Error("CAST: Requires a target mage.");
return;
}
int gate = token->value();
delete token;
token = o->gettoken();
if (!token) {
u->Error("CAST: No units to teleport.");
return;
}
if (!(*token == "units")) {
u->Error("CAST: No units to teleport.");
delete token;
return;
}
TeleportOrder *order;
if (u->teleportorders && u->teleportorders->spell == S_PORTAL_LORE) {
order = u->teleportorders;
} else {
order = new TeleportOrder;
u->ClearCastOrders();
u->teleportorders = order;
}
order->gate = gate;
order->spell = S_PORTAL_LORE;
order->level = 1;
UnitId *id = ParseUnit(o);
while(id) {
order->units.Add(id);
id = ParseUnit(o);
}
}
void Game::ProcessCastGateLore(Unit *u,AString *o, OrdersCheck *pCheck )
{
AString *token = o->gettoken();
if (!token) {
u->Error("CAST: Missing argument.");
return;
}
if ((*token) == "gate") {
delete token;
token = o->gettoken();
if (!token || token->value() < 1) {
u->Error("CAST: Requires a target gate.");
return;
}
TeleportOrder *order;
if (u->teleportorders && u->teleportorders->spell == S_GATE_LORE &&
u->teleportorders->gate == token->value()) {
order = u->teleportorders;
} else {
order = new TeleportOrder;
u->ClearCastOrders();
u->teleportorders = order;
}
order->gate = token->value();
order->spell = S_GATE_LORE;
order->level = 3;
delete token;
token = o->gettoken();
if (!token) return;
if (!(*token == "units")) {
delete token;
return;
}
UnitId *id = ParseUnit(o);
while(id) {
order->units.Add(id);
id = ParseUnit(o);
}
return;
}
if ((*token) == "random") {
TeleportOrder *order;
if (u->teleportorders &&
u->teleportorders->spell == S_GATE_LORE &&
u->teleportorders->gate == -1 ) {
order = u->teleportorders;
} else {
order = new TeleportOrder;
u->ClearCastOrders();
u->teleportorders = order;
}
order->gate = -1;
order->spell = S_GATE_LORE;
order->level = 1;
delete token;
token = o->gettoken();
if (!token) return;
if (*token == "level") {
order->gate = -2;
order->level = 2;
delete token;
token = o->gettoken();
}
if (!token) return;
if (!(*token == "units")) {
delete token;
return;
}
UnitId *id = ParseUnit(o);
while(id) {
order->units.Add(id);
id = ParseUnit(o);
}
return;
}
if ((*token) == "detect") {
delete token;
u->ClearCastOrders();
CastOrder *to = new CastOrder;
to->spell = S_GATE_LORE;
to->level = 2;
u->castorders = to;
return;
}
delete token;
u->Error("CAST: Invalid argument.");
}
void Game::ProcessTransmutation(Unit *u, AString *o, OrdersCheck *pCheck)
{
CastTransmuteOrder *order;
AString *token;
order = new CastTransmuteOrder;
order->spell = S_TRANSMUTATION;
order->level = 0;
order->item = -1;
order->number = -1;
token = o->gettoken();
if (!token) {
u->Error("CAST: You must specify what you wish to create.");
delete order;
return;
}
if (token->value() > 0) {
order->number = token->value();
delete token;
token = o->gettoken();
}
order->item = ParseEnabledItem(token);
delete token;
if (order->item == -1) {
u->Error("CAST: You must specify what you wish to create.");
delete order;
return;
}
switch(order->item) {
case I_MITHRIL:
case I_ROOTSTONE:
order->level = 1;
break;
case I_IRONWOOD:
order->level = 2;
break;
case I_FLOATER:
order->level = 3;
break;
case I_YEW:
order->level = 4;
break;
case I_WHORSE:
order->level = 5;
break;
case I_ADMANTIUM:
order->level = 5;
break;
default:
u->Error("CAST: Can't create that by transmutation.");
delete order;
return;
}
u->ClearCastOrders();
u->castorders = order;
return;
}
void Game::RunACastOrder(ARegion * r,Object *o,Unit * u)
{
int val;
if (u->type != U_MAGE && u->type != U_APPRENTICE) {
u->Error("CAST: Unit is not a mage.");
return;
}
if (u->castorders->level == 0) {
u->castorders->level = u->GetSkill(u->castorders->spell);
}
if (u->GetSkill(u->castorders->spell) < u->castorders->level ||
u->castorders->level == 0) {
u->Error("CAST: Skill level isn't that high.");
return;
}
int sk = u->castorders->spell;
switch (sk) {
case S_MIND_READING:
val = RunMindReading(r,u);
break;
case S_ENCHANT_ARMOR:
val = RunEnchant(r, u, sk, I_MPLATE);
break;
case S_ENCHANT_SWORDS:
val = RunEnchant(r, u, sk, I_MSWORD);
break;
case S_ENCHANT_SHIELDS:
val = RunEnchant(r, u, sk, I_MSHIELD);
break;
case S_CONSTRUCT_GATE:
val = RunConstructGate(r,u,sk);
break;
case S_ENGRAVE_RUNES_OF_WARDING:
val = RunEngraveRunes(r,o,u);
break;
case S_CONSTRUCT_PORTAL:
val = RunCreateArtifact(r,u,sk,I_PORTAL);
break;
case S_CREATE_RING_OF_INVISIBILITY:
val = RunCreateArtifact(r,u,sk,I_RINGOFI);
break;
case S_CREATE_CLOAK_OF_INVULNERABILITY:
val = RunCreateArtifact(r,u,sk,I_CLOAKOFI);
break;
case S_CREATE_STAFF_OF_FIRE:
val = RunCreateArtifact(r,u,sk,I_STAFFOFF);
break;
case S_CREATE_STAFF_OF_LIGHTNING:
val = RunCreateArtifact(r,u,sk,I_STAFFOFL);
break;
case S_CREATE_AMULET_OF_TRUE_SEEING:
val = RunCreateArtifact(r,u,sk,I_AMULETOFTS);
break;
case S_CREATE_AMULET_OF_PROTECTION:
val = RunCreateArtifact(r,u,sk,I_AMULETOFP);
break;
case S_CREATE_RUNESWORD:
val = RunCreateArtifact(r,u,sk,I_RUNESWORD);
break;
case S_CREATE_SHIELDSTONE:
val = RunCreateArtifact(r,u,sk,I_SHIELDSTONE);
break;
case S_CREATE_MAGIC_CARPET:
val = RunCreateArtifact(r,u,sk,I_MCARPET);
break;
case S_CREATE_FLAMING_SWORD:
val = RunCreateArtifact(r,u,sk,I_FSWORD);
break;
case S_SUMMON_IMPS:
val = RunSummonImps(r,u);
break;
case S_SUMMON_DEMON:
val = RunSummonDemon(r,u);
break;
case S_SUMMON_BALROG:
val = RunSummonBalrog(r,u);
break;
case S_SUMMON_LICH:
val = RunSummonLich(r,u);
break;
case S_RAISE_UNDEAD:
val = RunRaiseUndead(r,u);
break;
case S_SUMMON_SKELETONS:
val = RunSummonSkeletons(r,u);
break;
case S_DRAGON_LORE:
val = RunDragonLore(r,u);
break;
case S_BIRD_LORE:
val = RunBirdLore(r,u);
break;
case S_WOLF_LORE:
val = RunWolfLore(r,u);
break;
case S_INVISIBILITY:
val = RunInvisibility(r,u);
break;
case S_CREATE_PHANTASMAL_DEMONS:
val = RunPhanDemons(r,u);
break;
case S_CREATE_PHANTASMAL_UNDEAD:
val = RunPhanUndead(r,u);
break;
case S_CREATE_PHANTASMAL_BEASTS:
val = RunPhanBeasts(r,u);
break;
case S_GATE_LORE:
val = RunDetectGates(r,o,u);
break;
case S_FARSIGHT:
val = RunFarsight(r,u);
break;
case S_PHANTASMAL_ENTERTAINMENT:
val = RunPhantasmalEntertainment(r,u);
break;
case S_EARTH_LORE:
val = RunEarthLore(r,u);
break;
case S_WEATHER_LORE:
val = RunWeatherLore(r, u);
break;
case S_CLEAR_SKIES:
val = RunClearSkies(r,u);
break;
case S_SUMMON_WIND:
val = RunCreateArtifact(r, u, sk, I_CLOUDSHIP);
break;
case S_CREATE_FOOD:
val = RunCreateArtifact(r, u, sk, I_FOOD);
break;
case S_CREATE_AEGIS:
val = RunCreateArtifact(r,u,sk,I_AEGIS);
break;
case S_CREATE_WINDCHIME:
val = RunCreateArtifact(r,u,sk,I_WINDCHIME);
break;
case S_CREATE_GATE_CRYSTAL:
val = RunCreateArtifact(r,u,sk,I_GATE_CRYSTAL);
break;
case S_CREATE_STAFF_OF_HEALING:
val = RunCreateArtifact(r,u,sk,I_STAFFOFH);
break;
case S_CREATE_SCRYING_ORB:
val = RunCreateArtifact(r,u,sk,I_SCRYINGORB);
break;
case S_CREATE_CORNUCOPIA:
val = RunCreateArtifact(r,u,sk,I_CORNUCOPIA);
break;
case S_CREATE_BOOK_OF_EXORCISM:
val = RunCreateArtifact(r,u,sk,I_BOOKOFEXORCISM);
break;
case S_CREATE_HOLY_SYMBOL:
val = RunCreateArtifact(r,u,sk,I_HOLYSYMBOL);
break;
case S_CREATE_CENSER:
val = RunCreateArtifact(r,u,sk,I_CENSER);
break;
case S_TRANSMUTATION:
val = RunTransmutation(r, u);
break;
case S_BLASPHEMOUS_RITUAL:
val = RunBlasphemousRitual(r, u);
break;
}
if (val) {
u->Practice(sk);
r->NotifySpell(u, SkillDefs[sk].abbr, ®ions);
}
}
int Game::GetRegionInRange(ARegion *r, ARegion *tar, Unit *u, int spell)
{
int level = u->GetSkill(spell);
if (!level) {
u->Error("CAST: You don't know that spell.");
return 0;
}
RangeType *range = FindRange(SkillDefs[spell].range);
if (range == NULL) {
u->Error("CAST: Spell is not castable at range.");
return 0;
}
int rtype = regions.GetRegionArray(r->zloc)->levelType;
if ((rtype == ARegionArray::LEVEL_NEXUS) &&
!(range->flags & RangeType::RNG_NEXUS_SOURCE)) {
u->Error("CAST: Spell does not work from the Nexus.");
return 0;
}
if (!tar) {
u->Error("CAST: No such region.");
return 0;
}
rtype = regions.GetRegionArray(tar->zloc)->levelType;
if ((rtype == ARegionArray::LEVEL_NEXUS) &&
!(range->flags & RangeType::RNG_NEXUS_TARGET)) {
u->Error("CAST: Spell does not work to the Nexus.");
return 0;
}
if ((rtype != ARegionArray::LEVEL_SURFACE) &&
(range->flags & RangeType::RNG_SURFACE_ONLY)) {
u->Error("CAST: Spell can only target regions on the surface.");
return 0;
}
if (!(range->flags&RangeType::RNG_CROSS_LEVELS) && (r->zloc != tar->zloc)) {
u->Error("CAST: Spell is not able to work across levels.");
return 0;
}
int maxdist;
switch(range->rangeClass) {
default:
case RangeType::RNG_ABSOLUTE:
maxdist = 1;
break;
case RangeType::RNG_LEVEL:
maxdist = level;
break;
case RangeType::RNG_LEVEL2:
maxdist = level * level;
break;
case RangeType::RNG_LEVEL3:
maxdist = level * level * level;
break;
}
maxdist *= range->rangeMult;
int dist;
dist = regions.GetPlanarDistance(tar, r, range->crossLevelPenalty, maxdist);
if (dist > maxdist) {
u->Error("CAST: Target region out of range.");
return 0;
}
return 1;
}
int Game::RunMindReading(ARegion *r,Unit *u)
{
CastMindOrder *order = (CastMindOrder *) u->castorders;
int level = u->GetSkill(S_MIND_READING);
Unit *tar = r->GetUnitId(order->id,u->faction->num);
if (!tar) {
u->Error("No such unit.");
return 0;
}
AString temp = AString("Casts Mind Reading: ") + *(tar->name) + ", " +
*(tar->faction->name);
if (level < 4) {
u->Event(temp + ".");
return 1;
}
temp += tar->items.Report(2,5,0) + ". Skills: ";
temp += tar->skills.Report(tar->GetMen()) + ".";
u->Event(temp);
return 1;
}
int Game::RunEnchant(ARegion *r,Unit *u, int skill, int item)
{
int level, max, num, i, a;
unsigned int c;
level = u->GetSkill(skill);
max = ItemDefs[item].mOut * level / 100;
num = max;
// Figure out how many we can make based on available resources
for (c=0; c<sizeof(ItemDefs[item].mInput)/sizeof(Materials); c++) {
if (ItemDefs[item].mInput[c].item == -1)
continue;
i = ItemDefs[item].mInput[c].item;
a = ItemDefs[item].mInput[c].amt;
if (u->GetSharedNum(i) < num * a) {
num = u->GetSharedNum(i) / a;
}
}
// collect all the materials
for (c=0; c<sizeof(ItemDefs[item].mInput)/sizeof(Materials); c++) {
if (ItemDefs[item].mInput[c].item == -1)
continue;
i = ItemDefs[item].mInput[c].item;
a = ItemDefs[item].mInput[c].amt;
u->ConsumeShared(i, num * a);
}
// Add the created items
u->items.SetNum(item, u->items.GetNum(item) + num);
u->Event(AString("Enchants ") + num + " " + ItemDefs[item].names + ".");
if (num == 0) return 0;
return 1;
}
int Game::RunConstructGate(ARegion *r,Unit *u, int spell)
{
int ngates, log10, *used, i;
if (TerrainDefs[r->type].similar_type == R_OCEAN) {
u->Error("Gates may not be constructed at sea.");
return 0;
}
if (r->gate) {
u->Error("There is already a gate in that region.");
return 0;
}