-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreature.cpp
More file actions
9917 lines (8626 loc) · 225 KB
/
creature.cpp
File metadata and controls
9917 lines (8626 loc) · 225 KB
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
/*
* PROPRIETARY INFORMATION. This software is proprietary to POWDER
* Development, and is not to be reproduced, transmitted, or disclosed
* in any way without written permission.
*
* Produced by: Jeff Lait
*
* POWDER Development
*
* NAME: creature.cpp ( POWDER Library, C++ )
*
* COMMENTS:
* This would be better named mob.cpp or mob.h, but the change
* to MOB from CREATURE occured a bit late.
*
* This handles all the generic MOB manipulation routines.
* Note that action and ai functions can be found in action.cpp
* or ai.cpp.
*/
#include "creature.h"
#include "mygba.h"
#include <stdio.h>
#include <ctype.h>
#include "assert.h"
#include "gfxengine.h"
#include "glbdef.h"
#include "map.h"
#include "creature.h"
#include "rand.h"
#include "msg.h"
#include "grammar.h"
#include "item.h"
#include "itemstack.h"
#include "intrinsic.h"
#include "sramstream.h"
#include "victory.h"
#include "control.h"
#include "piety.h"
#include "encyc_support.h"
#include "hiscore.h"
MOBREF glbAvatar;
int MOB::ourFireBallCount = 0;
SPELL_NAMES MOB::ourZapSpell;
ATTACK_NAMES MOB::ourEffectAttack;
bool MOB::ourAvatarOnFreshSquare = false;
bool MOB::ourAvatarMoveOld = true;
u16 glbKillCount[NUM_MOBS];
s8 MOB::ourAvatarDx = 0;
s8 MOB::ourAvatarDy = 0;
int glbMobCount = 0;
// Defined in main.cpp
extern bool glbAutoRunEnabled;
void
mob_init()
{
// Nothing to do here... yet.
}
//
// MOB::Methods...
//
MOB::MOB()
{
myNext = 0;
myInventory = 0;
myCounters = 0;
myWornIntrinsic = 0;
glbMobCount++;
}
MOB::~MOB()
{
INTRINSIC_COUNTER *counter, *next;
// We don't want people pointing to our mob value any more:
if (!myOwnRef.transferMOB(0))
{
UT_ASSERT(!"Failed transfer in destructor");
}
// We obviously don't need these anymore.
for (counter = myCounters; counter; counter = next)
{
next = counter->myNext;
delete counter;
}
myCounters = 0;
delete myWornIntrinsic;
MOB *mob;
mob = myBaseType.getMob();
if (mob)
{
// This is safe as we own it.
delete mob;
}
// Delete all of our inventory.
// Normal in game mob deletions will not have inventory as we'll
// drop it first, but when cleaning up after a game we just
// delete the mob straight
{
ITEM *cur, *next;
// TODO: This is very dangerous! We may have a quest
// item or similar?
// Ideally we'll assert false if inventory is present
// except when doing map destruction.
for (cur = myInventory; cur; cur = next)
{
next = cur->getNext();
cur->setNext(0);
delete cur;
}
myInventory = 0;
}
// Mobs should only be destructed after they have been removed
// from the relevant lists.
UT_ASSERT(!myNext);
glbMobCount--;
}
void
MOB::init()
{
memset(glbKillCount, 0, sizeof(u16) * NUM_MOBS);
ourAvatarDx = 0;
ourAvatarDy = 0;
ourAvatarMoveOld = true;
}
MOB *
MOB::getAvatar()
{
return glbAvatar.getMob();
}
void
MOB::setAvatar(MOB *mob)
{
glbAvatar.setMob(mob);
}
void
MOB::saveAvatar(SRAMSTREAM &os)
{
glbAvatar.save(os);
}
void
MOB::loadAvatar(SRAMSTREAM &os)
{
glbAvatar.load(os);
}
void
MOB::buildAscensionKit()
{
ITEM *item;
// This is a recreation of a winning character.
item = ITEM::createMagicItem(MAGICTYPE_HELM, HELM_WARNING);
acquireItem(item);
item = ITEM::createMagicItem(MAGICTYPE_AMULET, AMULET_LIFESAVING);
acquireItem(item);
item = ITEM::create(ITEM_FLAMESWORD);
acquireItem(item);
item = ITEM::create(ITEM_REFLECTSHIELD);
acquireItem(item);
item = ITEM::create(ITEM_PLATEMAIL);
acquireItem(item);
item = ITEM::createMagicItem(MAGICTYPE_RING, RING_REGENERATE);
acquireItem(item);
item = ITEM::createMagicItem(MAGICTYPE_BOOTS, BOOTS_SPEED);
acquireItem(item);
setIntrinsic(INTRINSIC_SKILL_ARMOUR_HELMET);
setIntrinsic(INTRINSIC_SKILL_ARMOUR_SHIELD);
setIntrinsic(INTRINSIC_SKILL_ARMOUR_BODY);
setIntrinsic(INTRINSIC_SKILL_ARMOUR_BOOTS);
setIntrinsic(INTRINSIC_SKILL_WEAPON_RANGED);
setIntrinsic(INTRINSIC_SKILL_WEAPON_EDGED);
setIntrinsic(INTRINSIC_SKILL_WEAPON_MEDIUM);
setIntrinsic(INTRINSIC_SKILL_WEAPON_PARRY);
setIntrinsic(INTRINSIC_SPELL_MAGICMISSILE);
setIntrinsic(INTRINSIC_SPELL_SPARK);
setIntrinsic(INTRINSIC_SPELL_LIGHTNINGBOLT);
setIntrinsic(INTRINSIC_SPELL_REGENERATE);
setIntrinsic(INTRINSIC_SPELL_SLOWPOISON);
setIntrinsic(INTRINSIC_SPELL_HEAL);
setIntrinsic(INTRINSIC_SPELL_CUREPOISON);
setIntrinsic(INTRINSIC_SPELL_MAJORHEAL);
setIntrinsic(INTRINSIC_SPELL_RESURRECT);
setIntrinsic(INTRINSIC_SPELL_FORCEBOLT);
setIntrinsic(INTRINSIC_SPELL_ACIDSPLASH);
setIntrinsic(INTRINSIC_SPELL_DISINTEGRATE);
setIntrinsic(INTRINSIC_SPELL_DIG);
setIntrinsic(INTRINSIC_SPELL_TELEPORT);
setIntrinsic(INTRINSIC_SPELL_BLINK);
setIntrinsic(INTRINSIC_SPELL_IDENTIFY);
setIntrinsic(INTRINSIC_SPELL_DETECTCURSE);
setIntrinsic(INTRINSIC_SPELL_PETRIFY);
myMP = 147;
myMaxMP = 147;
myMagicDie = 38;
myHitDie = 26;
myHP = 103;
myMaxHP = 103;
}
MOB *
MOB::create(MOB_NAMES definition)
{
MOB *mob;
mob = new MOB();
mob->myOwnRef.createAndSetMOB(mob);
mob->myDefinition = definition;
mob->myOrigDefinition = definition;
mob->myExpLevel = glb_mobdefs[definition].explevel;
mob->myExp = 0;
mob->myHitDie = glb_mobdefs[definition].hitdie * 2;
mob->myHP = rand_dice(glb_mobdefs[definition].hp);
mob->myMaxHP = mob->myHP;
mob->myMagicDie = glb_mobdefs[definition].mpdie * 2;
mob->myMP = rand_dice(glb_mobdefs[definition].mp);
mob->myMaxMP = mob->myMP;
mob->myNoiseLevel = 0;
{
GENDERCHANCE_NAMES genderchance;
int male, female, neuter, percent;
genderchance = (GENDERCHANCE_NAMES) glb_mobdefs[definition].gender;
male = glb_genderchancedefs[genderchance].male;
female = glb_genderchancedefs[genderchance].female;
neuter = glb_genderchancedefs[genderchance].neuter;
UT_ASSERT(male + female + neuter == 100);
percent = rand_choice(100);
if (percent < male)
mob->myGender = VERB_HE;
else if (percent < male + female)
mob->myGender = VERB_SHE;
else
mob->myGender = VERB_IT;
// After all this, the avatar uses the global glbGender value
// to seed their gender.
if (definition == MOB_AVATAR)
{
if (glbGender)
mob->myGender = VERB_SHE;
else
mob->myGender = VERB_HE;
}
}
// Everyone starts of relatively well off.
mob->myFoodLevel = 1500;
mob->myIntrinsic.loadFromString(glb_mobdefs[definition].intrinsic);
{
// Determine handedness.
ITEMSLOTSET_NAMES slotset;
slotset = (ITEMSLOTSET_NAMES) defn(definition).slotset;
if (glb_itemslotsetdefs[slotset].lhand_name &&
glb_itemslotsetdefs[slotset].rhand_name)
{
// 10% chance of a left handed creature.
if (rand_chance(10))
mob->setIntrinsic(INTRINSIC_LEFTHANDED);
}
}
// Set this out of range so we don't munge any old data.
mob->myX = (u8) -1;
mob->myY = (u8) -1;
mob->setDLevel(-1);
mob->myAIFSM = AI_FSM_JUSTBORN;
mob->myAIState = 0;
// Create some treasure...
ITEM *item;
if (glbTutorial && definition == MOB_AVATAR)
{
// Special case for the tutorial. You start with a chainmail.
item = ITEM::create(ITEM_CHAINMAIL, false, true);
if (item) mob->acquireItem(item);
// Because it is a tutorial, we take pity and give the player
// some bonus strength.
mob->myMP = 30;
mob->myMaxMP = 30;
mob->myMagicDie = 4;
mob->myHitDie = 4;
mob->myHP = 30;
mob->myMaxHP = 30;
}
else if (definition == MOB_AVATAR)
{
// You are lucky! You always start with a weapon, an armour,
// a book, and a random item.
// Rethink... You start with a balanced set that
// is always balanced.
//
// You always wear some clothing as it is otherwise
// ugly to see your naked self. (Some may say the charm
// of POWDER is starting naked, though :>)
// Your weapon strength is the inverse of the body armour
//
// DSR: Don't update the comments much do you? :)
//
// JML: I believe comments form a place to engage in a dialog
// to better understand not just what the code is, but what it
// was, so people can gain the sense of history without
// resorting to svn blame. Which is a rationalization for
// my not updating them much.
// The *really* long dialog is in the createNPC function, IIRC.
//
ITEM_NAMES armour, weapon;
armour = ITEM_PLATEMAIL;
weapon = ITEM_WARHAMMER;
// Did the user pick something specific? Give him ...
// ...well, more or less what he asked for ;)
//
// The user's pick is judged by the currently worshiped god.
//
// The adventurer and cultist can have the standard random
// selection -- the first is true to original POWDER,
// and the second, well, Xom is the god of "random"...
/////////////////////////////////////////////////////////////////////
//
// The Fighter
//
// Always gets an edged/blunt large or medium weapon.
// Always gets metal 'fabricated' armor.
//
// Never gets the "guile" skill book as his guaranteed skillbook.
// Never gets the "divination" spell book as his guaranteed spellbook.
if (piety_chosengod() == GOD_FIGHTER)
{
ITEM_NAMES weplist[] =
{
ITEM_LONGSWORD,
ITEM_SILVERSWORD,
ITEM_WARHAMMER,
ITEM_MACE
};
ITEM_NAMES armlist[] =
{
ITEM_PLATEMAIL,
ITEM_SPLINTMAIL,
ITEM_BANDEDMAIL,
ITEM_CHAINMAIL
};
weapon = weplist[rand_choice(sizeof(weplist)/sizeof(ITEM_NAMES))];
armour = armlist[rand_choice(sizeof(armlist)/sizeof(ITEM_NAMES))];
}
// The Wizard
//
// Always gets a 'small' weapon.
// Always gets a robe.
//
// Gets two spell books (note he still starts with
// one skill and one spell slot, he just gets better choice
// in his starting spells).
else if (piety_chosengod() == GOD_WIZARD)
{
ITEM_NAMES weplist[] =
{
ITEM_KNIFE,
ITEM_DAGGER,
ITEM_SILVERDAGGER,
ITEM_CLUB,
ITEM_SHORTSWORD
};
weapon = weplist[rand_choice(sizeof(weplist)/sizeof(ITEM_NAMES))];
armour = ITEM_ROBE;
}
//
// The Ranger
//
// Always gets a bow and some arrows, OR a 'pointed' weapon.
// Always gets cloth or leather armor.
//
// Never receives the book of H'ruth as his guaranteed skillbook.
// Never receives the book of healing as his guaranteed spellbook.
else if (piety_chosengod() == GOD_ROGUE)
{
ITEM_NAMES weplist[] =
{
ITEM_BOW,
ITEM_DAGGER,
ITEM_SILVERDAGGER,
ITEM_SPEAR,
ITEM_SILVERSPEAR,
ITEM_RAPIER
};
ITEM_NAMES armlist[] =
{
ITEM_ROBE,
ITEM_LEATHERTUNIC,
ITEM_STUDDEDLEATHER
};
weapon = weplist[rand_choice(sizeof(weplist)/sizeof(ITEM_NAMES))];
armour = armlist[rand_choice(sizeof(armlist)/sizeof(ITEM_NAMES))];
}
// The Cleric
//
// Always gets a blunt weapon.
// Only one who can start with the 'special' armors;
// will never start with leather.
//
// Never receives the book of Necromancy or Death as his guaranteed
// spellbook.
else if (piety_chosengod() == GOD_CLERIC)
{
ITEM_NAMES weplist[] =
{
ITEM_CLUB,
ITEM_MACE,
ITEM_WARHAMMER
};
ITEM_NAMES armlist[] =
{
ITEM_ROBE,
ITEM_CHAINMAIL,
ITEM_MITHRILMAIL,
ITEM_BANDEDMAIL,
ITEM_SPLINTMAIL,
ITEM_PLATEMAIL,
ITEM_CRYSTALPLATE
};
weapon = weplist[rand_choice(sizeof(weplist)/sizeof(ITEM_NAMES))];
armour = armlist[rand_choice(sizeof(armlist)/sizeof(ITEM_NAMES))];
}
// The Necromancer
//
// Always starts with a knife and wearing a robe.
//
// Always starts with either the book of Death or Necromancy
// as his guaranteed spellbook, to compensate.
else if (piety_chosengod() == GOD_NECRO)
{
weapon = ITEM_KNIFE;
armour = ITEM_ROBE;
}
// The Barbarian
//
// Always starts with a bashing weapon or spear.
// Always starts with leather armor of some form.
//
// Begins with two skill books; note that he still receives
// a single spell and a single skill slot, however.
else if (piety_chosengod() == GOD_BARB)
{
ITEM_NAMES weplist[] =
{
ITEM_CLUB,
ITEM_MACE,
ITEM_WARHAMMER,
ITEM_SPEAR,
ITEM_SILVERSPEAR
};
ITEM_NAMES armlist[] =
{
ITEM_LEATHERTUNIC,
ITEM_STUDDEDLEATHER
};
weapon = weplist[rand_choice(sizeof(weplist)/sizeof(ITEM_NAMES))];
armour = armlist[rand_choice(sizeof(armlist)/sizeof(ITEM_NAMES))];
}
// The Cultist
//
// Befitting the random nature, you get a random weapon and
// random armour with no attempt at balance. Your special
// books are likewise entirely random.
else if (piety_chosengod() == GOD_CULTIST)
{
ITEM *temp;
temp = ITEM::createRandomType(ITEMTYPE_WEAPON);
weapon = temp->getDefinition();
delete temp;
temp = ITEM::createRandomType(ITEMTYPE_ARMOUR);
armour = temp->getDefinition();
delete temp;
}
// The Agnostic
//
// The classic weapon set that is good for any problem. This
// is also the default for new players.
else if (piety_chosengod() == GOD_AGNOSTIC)
{
switch (rand_choice(3))
{
case 0: // Robe
{
ITEM_NAMES list[] =
{
ITEM_LONGSWORD,
ITEM_SPEAR,
ITEM_MACE,
ITEM_RAPIER
};
armour = ITEM_ROBE;
weapon = list[rand_choice(sizeof(list)/sizeof(ITEM_NAMES))];
break;
}
case 1: // Leather
{
ITEM_NAMES list[] =
{
ITEM_SHORTSWORD,
ITEM_CLUB
};
armour = ITEM_LEATHERTUNIC;
weapon = list[rand_choice(sizeof(list)/sizeof(ITEM_NAMES))];
break;
}
case 2: // Studded Leather
{
ITEM_NAMES list[] =
{
ITEM_DAGGER,
ITEM_KNIFE,
ITEM_BOW
};
armour = ITEM_STUDDEDLEATHER;
weapon = list[rand_choice(sizeof(list)/sizeof(ITEM_NAMES))];
break;
}
}
}
item = ITEM::create(armour);
if (item)
{
item->makeVanilla();
mob->acquireItem(item);
mob->actionEquip(item->getX(), item->getY(),
ITEMSLOT_BODY, true);
}
item = ITEM::create(weapon);
if (item)
{
item->makeVanilla();
mob->acquireItem(item);
mob->actionEquip(item->getX(), item->getY(),
(item->getDefinition() == ITEM_BOW) ?
ITEMSLOT_LHAND :
ITEMSLOT_RHAND, true);
}
// If the item is a bow, add arrows. If it is arrows,
// add a bow.
if (item && item->getDefinition() == ITEM_BOW)
{
item = ITEM::create(ITEM_ARROW, false);
if (item)
{
item->makeVanilla();
item->setStackCount(7);
item->markQuivered();
mob->acquireItem(item);
}
}
// We want to create on spellbook and one skill book.
{
SPELLBOOK_NAMES spelllist[NUM_SPELLBOOKS];
SPELLBOOK_NAMES skilllist[NUM_SPELLBOOKS];
int numspell, numskill;
SPELLBOOK_NAMES book;
numspell = 0;
numskill = 0;
FOREACH_SPELLBOOK(book)
{
if (*glb_spellbookdefs[book].spells)
{
// Note the funny use of continue
// inside swtich to abort adding spells/skills
switch (piety_chosengod())
{
case GOD_BARB:
continue;
case GOD_NECRO:
if (book != SPELLBOOK_DEATH &&
book != SPELLBOOK_NECRO)
continue;
break;
case GOD_CLERIC:
if (book == SPELLBOOK_DEATH ||
book == SPELLBOOK_NECRO)
continue;
break;
case GOD_FIGHTER:
if (book == SPELLBOOK_DIVINATION)
continue;
break;
case GOD_ROGUE:
if (book == SPELLBOOK_HEAL)
continue;
break;
case GOD_CULTIST:
// Both books are of any type.
skilllist[numskill++] = book;
break;
case NUM_GODS:
case GOD_AGNOSTIC:
// Nothing special
break;
case GOD_WIZARD:
// Get only spell books so add to skill list.
skilllist[numskill++] = book;
break;
}
// It has spells
spelllist[numspell++] = book;
}
else
{
// Note the funny use of continue
// inside swtich to abort adding spells/skills
switch (piety_chosengod())
{
case GOD_BARB:
// Barbarians get two skill books
spelllist[numspell++] = book;
break;
case GOD_NECRO:
case GOD_CLERIC:
break;
case GOD_FIGHTER:
// The fighter never gets guile
if (book == SPELLBOOK_ROGUE)
continue;
break;
case GOD_ROGUE:
// The ranger never gets H'ruth
if (book == SPELLBOOK_BARB)
continue;
break;
case GOD_CULTIST:
// Both books are of any type.
spelllist[numspell++] = book;
break;
case NUM_GODS:
case GOD_AGNOSTIC:
// Nothing special
break;
case GOD_WIZARD:
// No skill books for wizards
continue;
}
skilllist[numskill++] = book;
}
}
// Pick one random of each...
book = spelllist[rand_choice(numspell)];
item = ITEM::createMagicItem(MAGICTYPE_SPELLBOOK, book, false);
if (item) mob->acquireItem(item);
book = skilllist[rand_choice(numskill)];
item = ITEM::createMagicItem(MAGICTYPE_SPELLBOOK, book, false);
if (item) mob->acquireItem(item);
}
// The bonus item!
item = ITEM::createRandom();
if (item) mob->acquireItem(item);
}
else
{
// Standard treasure is a random item...
// We, however, don't give it to every creature all the time.
if (rand_chance(10))
{
item = ITEM::createRandom();
mob->acquireItem(item);
}
}
// Add all the standard loot the critter has.
const char *loot;
loot = glb_mobdefs[definition].loot;
while (*loot)
{
item = ITEM::create((ITEM_NAMES) *loot);
mob->acquireItem(item);
loot++;
}
// Likewise, any loot types...
loot = glb_mobdefs[definition].loottype;
while (*loot)
{
item = ITEM::createRandomType((ITEMTYPE_NAMES) *loot);
mob->acquireItem(item);
loot++;
}
// if (definition == MOB_AVATAR)
// mob->setIntrinsic(INTRINSIC_SPELL_SUMMON_IMP);
// Debug insta assign for item testing...
#if 0
for (int i = 0; i < 15; i++)
{
item = ITEM::create(ITEM_WATER);
mob->acquireItem(item);
}
#endif
#if 0
if (definition == MOB_AVATAR)
{
mob->setIntrinsic(INTRINSIC_LICHFORM);
item = ITEM::create(ITEM_BLACKHEART);
mob->acquireItem(item);
item = ITEM::create(ITEM_YRUNE);
mob->acquireItem(item);
item = ITEM::create(ITEM_ARROW);
mob->acquireItem(item);
item = ITEM::create(ITEM_BOW);
mob->acquireItem(item);
// Test cleric dress.
item = ITEM::create(ITEM_SANDALS);
mob->acquireItem(item);
item = ITEM::create(ITEM_RUBYNECKLACE);
mob->acquireItem(item);
item = ITEM::create(ITEM_CHAINMAIL);
mob->acquireItem(item);
// Verify mini icons.
item = ITEM::create(ITEM_SCROLL_FOOBAR);
mob->acquireItem(item);
item = ITEM::create(ITEM_PURPLEWAND);
mob->acquireItem(item);
}
#endif
// Simple hash.
if (definition == MOB_AVATAR)
{
#ifndef iPOWDER
if (rand_hashstring(glbAvatarName) == 3939879139u)
{
glbWizard = true;
}
else
{
glbWizard = false;
}
#endif
}
#if 0
// Report the hash to make it easy to change the passwords.
if (definition == MOB_AVATAR)
{
BUF buf;
buf.sprintf("%x ", rand_hashstring(glbAvatarName));
msg_report(buf);
}
#endif
#if 0
// You can now wish for all this.
if (definition == MOB_AVATAR && glbWizard)
{
mob->setIntrinsic(INTRINSIC_SPELL_RESURRECT);
mob->setIntrinsic(INTRINSIC_SPELL_WIZARDSEYE);
mob->setIntrinsic(INTRINSIC_SPELL_POSSESS);
mob->setIntrinsic(INTRINSIC_SPELL_BLINK);
mob->setIntrinsic(INTRINSIC_SPELL_FETCH);
mob->setIntrinsic(INTRINSIC_SPELL_BINDSOUL);
mob->setIntrinsic(INTRINSIC_SPELL_ENTOMB);
mob->setIntrinsic(INTRINSIC_SPELL_PETRIFY);
mob->setIntrinsic(INTRINSIC_SPELL_DETECTCURSE);
mob->setIntrinsic(INTRINSIC_SPELL_IDENTIFY);
mob->setIntrinsic(INTRINSIC_SPELL_MAJORHEAL);
mob->setIntrinsic(INTRINSIC_SPELL_FORCEBOLT);
mob->setIntrinsic(INTRINSIC_SPELL_ACIDSPLASH);
mob->setIntrinsic(INTRINSIC_SPELL_CORROSIVEEXPLOSION);
mob->setIntrinsic(INTRINSIC_SPELL_CREATEPIT);
mob->setIntrinsic(INTRINSIC_SPELL_TRACK);
mob->setIntrinsic(INTRINSIC_SPELL_DIAGNOSE);
mob->setIntrinsic(INTRINSIC_SPELL_ROLLINGBOULDER);
mob->setIntrinsic(INTRINSIC_SPELL_SUMMON_DEMON);
mob->setIntrinsic(INTRINSIC_SPELL_LIVINGFROST);
mob->setIntrinsic(INTRINSIC_SPELL_BLIZZARD);
mob->setIntrinsic(INTRINSIC_SPELL_PRESERVE);
mob->setIntrinsic(INTRINSIC_SPELL_DIRECTWIND);
mob->setIntrinsic(INTRINSIC_SPELL_STICKYFLAMES);
mob->setIntrinsic(INTRINSIC_SKILL_WEAPON_RIPOSTE);
mob->setIntrinsic(INTRINSIC_SKILL_WEAPON_TRUEAIM);
mob->setIntrinsic(INTRINSIC_SKILL_CHARGE);
mob->setIntrinsic(INTRINSIC_SKILL_LEAPATTACK);
mob->setIntrinsic(INTRINSIC_SKILL_TWOWEAPON);
mob->setIntrinsic(INTRINSIC_SKILL_WEAPON_DISARM);
mob->setIntrinsic(INTRINSIC_SPELL_DISINTEGRATE);
mob->setIntrinsic(INTRINSIC_SPELL_RAISE_UNDEAD);
mob->setIntrinsic(INTRINSIC_SPELL_RECLAIM_SOUL);
mob->setIntrinsic(INTRINSIC_SPELL_DARK_RITUAL);
mob->setIntrinsic(INTRINSIC_SPELL_FORCEWALL);
mob->setIntrinsic(INTRINSIC_SPELL_SUMMON_FAMILIAR);
mob->setIntrinsic(INTRINSIC_SPELL_TRANSFER_KNOWLEDGE);
mob->setIntrinsic(INTRINSIC_REFLECTION);
mob->setIntrinsic(INTRINSIC_JUMP);
mob->myMP = 200;
// mob->myMagicDie = 100;
mob->myHitDie = 8;
mob->myMaxMP = 200;
mob->myHP = 100;
mob->myMaxHP = 100;
}
#endif
#if 0
for (int i = 0; definition == MOB_AVATAR && i < 90; i++)
//for (int i = 0; i < 90; i++)
{
// item = ITEM::createRandom();
// We can also create a bunch of items of a given type, useful
// for testing...
item = ITEM::createRandomType(ITEMTYPE_WAND);
mob->acquireItem(item);
item = ITEM::createRandomType(ITEMTYPE_WEAPON);
mob->acquireItem(item);
}
// mob->myMagicDie = 38;
// mob->myHitDie = 38;
#endif
if (glbStressTest && !glbMapStats && definition == MOB_AVATAR)
{
if (rand_chance(80))
{
mob->buildAscensionKit();
}
else
{
int i, n;
SPELL_NAMES spell;
SKILL_NAMES skill;
// A much more random character...
n = 20;
for (i = 0; i < 20; i++)
{
item = ITEM::createRandomType(ITEMTYPE_ANY);
mob->acquireItem(item);
}
n = rand_range(1, 20);
for (i = 0; i < n; i++)
{
spell = (SPELL_NAMES) rand_range(1, NUM_SPELLS-1);
mob->setIntrinsic((INTRINSIC_NAMES)glb_spelldefs[spell].intrinsic);
}
n = rand_range(1, 20);
for (i = 0; i < n; i++)
{
skill = (SKILL_NAMES) rand_range(1, NUM_SKILLS-1);
mob->setIntrinsic((INTRINSIC_NAMES)glb_skilldefs[skill].intrinsic);
}
mob->myMP = rand_range(30, 150);
mob->myMaxMP = mob->myMP;
mob->myMagicDie = mob->myMP / 7;
mob->myHP = rand_range(30, 150);
mob->myMaxHP = mob->myHP;
mob->myHitDie = mob->myHP / 7 + 1;
}
}
// Make everyone do a poly dance.
// mob->setIntrinsic(INTRINSIC_POLYMORPH);
return mob;
}
void
MOB::changeDefinition(MOB_NAMES definition, bool reset)
{
myDefinition = definition;
myOrigDefinition = definition;
if (reset)
{
myExpLevel = glb_mobdefs[definition].explevel;
myExp = 0;
myHitDie = glb_mobdefs[definition].hitdie * 2;
myHP = rand_dice(glb_mobdefs[definition].hp);
myMaxHP = myHP;
myMagicDie = glb_mobdefs[definition].mpdie * 2;
myMP = rand_dice(glb_mobdefs[definition].mp);
myMaxMP = myMP;
myNoiseLevel = 0;
myIntrinsic.clearAll();
myIntrinsic.loadFromString(glb_mobdefs[definition].intrinsic);
}
}
MOB_NAMES
MOB::chooseNPC(int threatlevel)
{
int percentages[NUM_MOBS];
int total = 0;
int explevel, guess;
bool fuck_the_player = false;
MOB_NAMES def;
if (piety_chosengod() == GOD_CULTIST)
{
if (rand_choice(100) == 66)
{
msg_report("><0|V| laughs.");
fuck_the_player = true;
}
}
else
{
if (rand_choice(5000) == 666)
fuck_the_player = true;
}
if (threatlevel < 0)
threatlevel = 0;
threatlevel = threatlevel / 2;
FOREACH_MOB(def)
{
if (def == MOB_NONE)
percentages[def] = 0;
else if (def == MOB_AVATAR)
percentages[def] = 0;
else
{
// The "ExpLevel" is the rough guess of the strength of the mob.
explevel = glb_mobdefs[def].explevel;
// We want to create mobs matching our adjusted threatlevel.
// We do this by biassing the creation. Anything within two
// levels gets a value of 65536. For every level outside
// that, it is dropped in half, to a minimum of 1. So
// you could get all powerful creatures in level 1.
// This gives a level difference of 18 to mean there isn't
// a chance in one direction of successful combat.
// I don't like the above schema very much, a level 1 character
// has a 1/32 bias against a dragon of any type. As there
// is a peak of dragons currnetly, (32 possible monsters, 3
// are non-green dragons, chance of non-green dragon is
// one in 341 chance of a dragon.
// I'd like something 8 levels away to be 1/1000 chance.
// New system:
// Things your level have chance 1024.
// Every level above your level halves chance, for 1 chance
// at 10 over (7 over on dragons is 1/128, or 8)
// Below you falls off slower, and halves every two levels.
// Creatures an odd number below are 75%.