-
Notifications
You must be signed in to change notification settings - Fork 0
/
Services.cpp
845 lines (781 loc) · 27.5 KB
/
Services.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
#include "Global.h"
#include "Util.h"
#include "Hero.h"
#include "Interface.h"
#include "Services.h"
#include <ctype.h>
/******************************************************
Code for docbot and Melnorme.
******************************************************/
shServiceDescData MedicalProcedureData[kMedMaxService] =
{
{ "SNU-???", 0 },
{ "THERAC-25", 0 },
{ "JARVIK 7", 0 },
{ "PFAZER", 0 },
{ "PNLS DTH", 0 }, // 5
{ "NACSTAC", 0 },
{ "X-14-39-ZS", 0 },
{ "89 50 4E 47 0D 0A 1A 0A", 0 }, /* PNG file header. */
{ "BBQ--BBQ", 0 }
};
shServiceDescData MelnormeServiceData[6 /* kMelnMaxService */] =
{
{ "Puun-Taffy", 0 },
{ "Juffo-Wup", 0 },
{ "Ta Puun", 0 },
{ "Huffi-Muffi-Guffi", 0 },
{ "Wezzy-Wezzah", 0 }, // 5
{ "Tuffa-Yuf", 0 }
};
/* Could not decide on one to leave off so hardcoded array size. */
void
randomizeServiceNames ()
{
shuffle (MedicalProcedureData, kMedMaxService, sizeof (shServiceDescData));
shuffle (MelnormeServiceData, 6, sizeof (shServiceDescData));
}
/* called when the hero enters a shop room */
void
shHero::enterHospital ()
{
shMonster *doctor = mLevel->getDoctor (mX, mY);
if (doctor) {
if (doctor->isHostile ()) {
return;
}
if (tryToTranslate (doctor)) {
I->p ("\"Welcome to Ol' Sawbot's Precision Surgery Center!\"");
} else {
I->p ("%s beeps and bloops pleasantly.", doctor->the ());
}
I->p ("Press 'p' to see a menu of available services.");
} else {
I->p ("Hmm... This store appears to be deserted.");
}
}
void
shHero::leaveHospital ()
{
shMonster *doc = mLevel->getDoctor (mX, mY);
shObjectVector v;
if (!doc) {
return;
}
if (doc->isHostile ()) {
return;
} else if (tryToTranslate (doc)) {
I->p ("\"Come again soon!\"");
} else {
I->p ("%s twitters cheerfully.", doc->the ());
}
}
static void
amputationDiscount (shCreature *doctor, shCreature *hero, bool *flag, int price)
{
if (!*flag) {
*flag = true;
} else {
if (Hero.tryToTranslate (doctor)) {
I->p ("\"As advertised every second amputation is half off.\"");
} else {
I->p ("%s gives you back half what you paid.", THE (doctor));
}
hero->gainMoney (price / 2);
doctor->loseMoney (price / 2);
*flag = false;
}
}
void
shHero::payDoctor (shMonster *doctor)
{
static const char *MedicalProcedureNames[] =
{ "Wound Treatment",
"Restoration Treatment",
"Intestinal Examination",
"Systems Diagnostics",
"Radiation Purge",
"Caesarean Section",
"Canister Amputation",
"Teef Extraction",
"Tail Amputation"
};
static bool hadamputation = false;
char buf[200];
shMenu *menu = I->newMenu ("Medical Services Menu", 0);
int serv;
const int TREATMENT_COST = 200;
if (tryToTranslate (doctor)) {
/* make all services known */
for (int i = 0; i < kMedMaxService; ++i) {
MedicalProcedureData[i].mNameKnown = 1;
}
}
char letter = 'a';
for (int i = 0; i < kMedMaxService; ++i) {
serv = doctor->mDoctor.mPermute[i];
/* try not to offer unneeded services */
switch (serv) {
case kMedHealing:
if (Hero.mHP != Hero.mMaxHP or
Hero.is (kViolated) or
Hero.is (kConfused) or
Hero.is (kStunned))
{
break;
}
continue;
case kMedRestoration: {
int add = 0;
FOR_ALL_ABILITIES (j) {
int abil = Hero.mAbil.getByIndex (j);
if (kPsi == j) {
abil += Hero.mPsiDrain;
}
if (abil < Hero.mMaxAbil.getByIndex (j)) {
add = 1;
break;
}
}
if (add) break;
continue;
}
case kMedRectalExam:
case kMedDiagnostics:
case kMedRadPurification:
/* these services are always available: */
break;
case kMedCaesareanSection:
if (Hero.getStoryFlag ("impregnation"))
break;
continue;
case kMedCanisterAmputation:
if (Hero.getStoryFlag ("superglued tongue"))
break;
continue;
case kMedTeefExtraction:
if (!Hero.getStoryFlag ("lost teef") and Hero.isOrc ())
break;
continue;
case kMedTailAmputation:
if (Hero.mIlkId == kMonXelNaga and !Hero.getStoryFlag ("lost tail"))
break;
continue;
default:
continue;
}
snprintf (buf, sizeof(buf), "%s ($%d)",
MedicalProcedureData[serv].mNameKnown
? MedicalProcedureNames[serv]
: MedicalProcedureData[serv].mDesc,
TREATMENT_COST);
menu->addIntItem (letter++, buf, serv);
}
int res;
if (!menu->getIntResult (&res))
return; /* nothing picked */
delete menu;
MedicalProcedures choice = MedicalProcedures (res);
int price = TREATMENT_COST;
if (countMoney () < price) {
I->p ("You don't have enough money for that.");
return;
}
if (Hero.is (kFrightened) and choice == kMedTeefExtraction and
MedicalProcedureData[choice].mNameKnown)
{
I->p ("No way! You are too afraid of the dentist at the moment!");
return;
}
loseMoney (price);
doctor->gainMoney (price);
const char *who = doctor->the ();
shObjectIlk *ilk;
switch (choice) {
case kMedHealing:
ilk = &AllIlks[kObjHealingRayGun];
I->p ("%s injects you with a %s serum!", who,
!Hero.isBlind () ? ilk->getRayGunColor () : "kind of");
if (Hero.healing (NDX (10, 5), 0) and !Hero.isBlind ()) {
ilk->mFlags |= kIdentified;
MedicalProcedureData[choice].mNameKnown = 1;
}
break;
case kMedRestoration:
ilk = &AllIlks[kObjRestorationRayGun];
I->p ("%s injects you with a %s serum!", who,
!Hero.isBlind () ? ilk->getRayGunColor () : "kind of");
if (Hero.restoration (NDX (3, 2))) {
MedicalProcedureData[choice].mNameKnown = 1;
if (!Hero.isBlind ()) ilk->mFlags |= kIdentified;
}
break;
case kMedRectalExam:
{
int probed = 0;
/* Was loser option pre PRIME 1.7 but why not make it useful
in a border case? */
MedicalProcedureData[choice].mNameKnown = 1;
I->p ("%s probes you!", who);
/* Any resistance is treated like obstacle. */
if (!Hero.mResistances[kViolating]) {
Hero.sufferDamage (kAttProbe);
probed = 1;
} else { /* If hero wears loser anorak he is immune. */
I->p ("You seem unaffected.");
Hero.mCloak->setKnown ();
if (Hero.tryToTranslate (doctor)) {
I->p ("\"I cannot perform the service while you wear %s.\"",
THE (Hero.mCloak));
Hero.mCloak->setKnown ();
/* Get rid of buggy loser anorak for 200 BZ. */
if (I->yn ("\"May I remove it?\"")) {
I->p ("%s removes %s.", who, YOUR (Hero.mCloak));
Hero.doff (Hero.mCloak);
I->p ("%s probes you again!", who);
Hero.sufferDamage (kAttProbe);
probed = 1;
} else {
I->p ("Money-back guarantee requires me to refuse payment.");
gainMoney (price);
doctor->loseMoney (price);
}
} else {
I->p ("%s chirps something and gives back your money.", who);
gainMoney (price);
doctor->loseMoney (price);
}
if (probed and Hero.getStoryFlag ("impregnation")) {
I->p ("\"You have a parasite.\"");
} /* Thank you, Captain Obvious! */
}
break;
}
case kMedDiagnostics:
MedicalProcedureData[choice].mNameKnown = 1;
I->p ("%s probes you!", who);
Hero.doDiagnostics (0);
break;
case kMedRadPurification:
MedicalProcedureData[choice].mNameKnown = 1;
I->p ("%s injects you with a %s serum!", who,
!Hero.isBlind () ? "bubbly" : "kind of");
Hero.mRad = maxi (0, Hero.mRad - RNG (50, 200));
if (!Hero.mRad)
I->p ("You feel purified.");
else
I->p ("You feel less contaminated.");
break;
case kMedCaesareanSection:
{
if (!Hero.getStoryFlag ("impregnation"))
break;
MedicalProcedureData[choice].mNameKnown = 1;
Hero.setStoryFlag ("impregnation", 0);
int x = Hero.mX;
int y = Hero.mY;
int queen = !RNG (0, 17);
int colicky = !RNG (0, 5);
shMonster *baby = new shMonster (queen ? kMonAlienPrincess : kMonChestburster);
if (!colicky) {
baby->mDisposition = shMonster::kIndifferent;
}
Level->findNearbyUnoccupiedSquare (&x, &y);
if (!baby) {
I->p ("Unfortunately, your baby was stillborn.");
} else {
I->p ("It's a %s!", queen ? "girl" : "boy");
if (Level->putCreature (baby, x, y)) {
/* FIXME: something went wrong */
} else {
I->drawScreen ();
}
}
I->p ("You lose a lot of blood during the operation.");
if (Hero.sufferDamage (kAttCaesareanSection)) {
Hero.shCreature::die (kKilled, "complications in childbirth");
}
break;
}
case kMedCanisterAmputation:
{
if (!Hero.getStoryFlag ("superglued tongue"))
break;
MedicalProcedureData[choice].mNameKnown = 1;
I->p ("%s cuts away the glued canister.", who);
Hero.resetStoryFlag ("superglued tongue");
amputationDiscount (doctor, this, &hadamputation, price);
}
case kMedTeefExtraction:
{
if (Hero.getStoryFlag ("lost teef"))
break;
int sum = NDX (11, 100);
Hero.setStoryFlag ("lost teef", sum);
MedicalProcedureData[choice].mNameKnown = 1; /* Kind of pointless. */
if (Hero.is (kFrightened)) {
char *buf = GetBuf ();
strcpy (buf, who);
buf[0] = toupper (buf[0]);
I->p ("Oh no!! %s gets at your teef!", buf);
I->p ("You panic and try to flee but %s has immobilized you already.", who);
} else
I->p ("%s extracts your teef.", who);
I->p ("Your magnificent teef are worth $%d buckazoids.", sum);
gainMoney (sum);
break;
}
case kMedTailAmputation:
{
if (Hero.getStoryFlag ("lost tail"))
break;
Hero.setStoryFlag ("lost tail", 1);
MedicalProcedureData[choice].mNameKnown = 1;
I->p ("%s amputates your tail!", who);
Hero.amputateTail ();
amputationDiscount (doctor, this, &hadamputation, price);
}
case kMedMaxService:
break;
}
I->drawSideWin ();
}
/* doctor strategy:
wait around for hero to request services;
occasionally advertise
returns ms elapsed, -2 if the monster dies
*/
int
shMonster::doDoctor ()
{
int elapsed;
int res = -1;
int retry = 3;
while (-1 == res) {
if (!retry--) {
return 200;
}
switch (mTactic) {
case kNewEnemy:
mStrategy = kWander;
mTactic = kNewEnemy;
return doWander ();
case kMoveTo:
res = doMoveTo ();
continue;
case kReady:
if (Level->getRoomID (mX, mY) != mDoctor.mRoomID) {
/* somehow, we're not in our hospital! */
mDestX = mDoctor.mHomeX;
mDestY = mDoctor.mHomeY;
if (setupPath ()) {
mTactic = kMoveTo;
continue;
} else {
return 2000;
}
}
if (canSee (&Hero) and
mDoctor.mRoomID == Level->getRoomID (Hero.mX, Hero.mY))
{
if (0 == RNG (12)) {
/* move to an empty square near the home square */
mDestX = mDoctor.mHomeX;
mDestY = mDoctor.mHomeY;
if (!mLevel ->
findAdjacentUnoccupiedSquare (&mDestX, &mDestY))
{
elapsed = doQuickMoveTo ();
if (-1 == elapsed) elapsed = 800;
return elapsed;
}
return RNG (300, 1000); /* nowhere to go, let's wait... */
} else if (0 == RNG (50)) {
const char *quips[] = {
"\"Dammit, %s! I'm a docbot, not %s!\"",
"\"Your second amputation is half off!\"",
"\"Galaxy-class health care services!\"",
"\"I've been through much experience, you're dealing with an expert!\""
};
const unsigned int NUMQUIPS = sizeof (quips) / sizeof (char *);
const char *nouns[] = {
"a magician",
"a psychiatrist",
"a bartender",
"a bricklayer",
"a mechanic",
"a priest",
"a lawyer",
"a prostitute",
"a toaster oven",
"a warbot"
};
const unsigned int NUMNOUNS = sizeof (nouns) / sizeof (char *);
if (Hero.tryToTranslate (this)) {
I->p (quips[RNG (NUMQUIPS)],
Hero.mName, nouns[RNG (NUMNOUNS)]);
Hero.interrupt ();
}
return RNG (500, 1000);
}
return RNG (500, 1000);
} else {
return RNG (800, 1600);
}
case kFight:
case kShoot:
mTactic = kReady;
debug.log ("Unexpected doctor tactic!");
}
}
return RNG (300, 1000); /* keep on lurking */
}
void
pacifyMelnorme (shMonster *trader)
{
trader->mStrategy = shMonster::kMelnorme;
trader->mTactic = shMonster::kReady;
trader->mDisposition = shMonster::kIndifferent;
if (Level->getRoomID (Hero.mX, Hero.mY) ==
Level->getRoomID (trader->mX, trader->mY))
{
trader->mGlyph.mColor = kMagenta;
trader->mGlyph.mTileX = 3;
} else {
trader->mGlyph.mColor = kGreen;
trader->mGlyph.mTileX = 2;
}
I->drawScreen ();
}
const char *MelnormeServiceNames[] =
{ "Reveal object bugginess",
"Reveal object charges",
"Reveal object enhancement",
"Describe object appearance",
"Buy knowledge"
};
void
shHero::payMelnorme (shMonster *trader)
{
if (trader->isHostile ()) {
int result;
shMenu *amends = I->newMenu ("Make amends:", 0);
amends->addIntItem ('a', "Apologize", 1, 1);
amends->addIntItem ('p', "Pay reparations", 2, 1);
amends->getIntResult (&result);
delete amends;
switch (result) {
case -1:
return;
case 1:
if (trader->mHP == trader->mMaxHP) {
if (tryToTranslate (trader)) {
I->p ("\"We believe you.\"");
} else {
I->p ("%s mumbles soothingly.", THE (trader));
}
pacifyMelnorme (trader);
} else {
if (tryToTranslate (trader)) {
I->p ("\"It is not enough.\"");
} else {
I->p ("%s mumbles stalwartly.", THE (trader));
}
}
return;
case 2:
{
int demand = (trader->mMaxHP - trader->mHP) * 10;
demand = maxi (50, demand);
if (demand <= countMoney ()) {
if (I->yn ("Pay %s %d buckazoids?", THE (trader), demand)) {
I->p ("%s accepts the money.", THE (trader));
pacifyMelnorme (trader);
loseMoney (demand);
trader->gainMoney (demand);
}
} else {
I->p ("%s demands %d buckazoids but you don't"
" have that much.", THE (trader), demand);
}
}
}
return;
}
static int (shObject::*tests[])(void) =
{
&shObject::isBugginessKnown,
&shObject::isChargeKnown,
&shObject::isEnhancementKnown,
&shObject::isAppearanceKnown
};
static void (shObject::*actions[])(void) =
{
&shObject::setBugginessKnown,
&shObject::setChargeKnown,
&shObject::setEnhancementKnown,
&shObject::setAppearanceKnown
};
int (shObject::*test) (void);
void (shObject::*action) (void);
reorganizeInventory ();
shMenu *menu = I->newMenu ("Melnorme Services Menu", 0);
char buf[200];
shObjectVector v;
int price = 1000, services = 0;
int price1 = 40 - Hero.mAbil.mPsi; /* Bugginess. */
int price2 = 225 - 5 * Hero.mAbil.mPsi; /* Knowledge. */
int price3 = price1 / 2; /* Remaining. */
if (!trader->is (kGenerous)) {
/* Ward against drinking a lot of nano cola. */
price1 = maxi (10, price1);
price2 = maxi (100, price2);
price3 = maxi (10, price3);
} else {
price1 = 10;
price2 = 100;
price3 = 10;
}
if (tryToTranslate (trader)) {
/* Make all services known. */
for (int i = 0; i < kMelnMaxService; ++i) {
MelnormeServiceData[i].mNameKnown = 1;
}
}
char letter = 'a';
for (int i = 0; i < kMelnMaxService; ++i) {
int serv = trader->mMelnorme.mPermute[i];
/* Offer only eligible services. */
if (serv == kMelnRandomIdentify) {
if (trader->mMelnorme.mKnowledgeExhausted or
!hasTranslation ())
continue;
price = price2;
++services;
} else if (serv >= kMelnRevealBugginess and
serv <= kMelnRevealAppearance)
{
test = tests[serv - kMelnRevealBugginess];
v.reset ();
unselectObjectsByFunction (&v, Hero.mInventory, test);
if (!v.count ()) continue;
if (serv == kMelnRevealBugginess) {
price = price1;
} else {
price = price3;
}
++services;
}
snprintf (buf, sizeof (buf), "%s ($%d)",
MelnormeServiceData[serv].mNameKnown
? MelnormeServiceNames[serv]
: MelnormeServiceData[serv].mDesc,
price);
menu->addIntItem (letter++, buf, serv);
}
if (!services) {
if (tryToTranslate (trader)) {
I->p ("Unfortunately I cannot help you at the moment.");
} else {
I->p ("%s mumbles something in sad voice.", THE (trader));
}
return;
}
int choice;
if (!menu->getIntResult (&choice))
return;
delete menu;
price = choice == kMelnRandomIdentify ? price2 :
choice == kMelnRevealBugginess ? price1 : price3;
if (countMoney () < price) {
I->p ("You don't have enough money for that.");
return;
}
loseMoney (price);
trader->gainMoney (price);
shObject *obj = NULL;
if (choice == kMelnRandomIdentify) {
int n = kObjNumIlks;
int tries = 10;
int success = 0;
while (tries--) {
int i = RNG (n);
shObjectIlk *ilk = &AllIlks[i];
if (!(ilk->mFlags & kIdentified) and ilk->mProbability != ABSTRACT) {
char *buf = GetBuf ();
strncpy (buf, ilk->mReal.mName, SHBUFLEN);
makePlural (buf, SHBUFLEN);
ilk->mFlags |= kIdentified;
I->p ("%s tells you how to recognize %s.", THE (trader), buf);
success = 1;
break;
}
}
if (!success) {
I->p ("%s offers you several facts but you know all of them.", THE (trader));
I->p ("\"It seems you know all I do.\"");
trader->mMelnorme.mKnowledgeExhausted = 1;
I->p ("%s returns your money.");
trader->loseMoney (price);
gainMoney (price);
}
MelnormeServiceData[choice].mNameKnown = 1;
} else if (choice >= kMelnRevealBugginess and
choice <= kMelnRevealAppearance)
{
v.reset ();
test = tests[choice - kMelnRevealBugginess];
unselectObjectsByFunction (&v, Hero.mInventory, test);
obj = quickPickItem (&v, "perform service on", 0);
if (obj) {
if (hasTranslation () or RNG (4)) { /* 75% - lets be generous. */
action = actions[choice - kMelnRevealBugginess];
(obj->*action) ();
if (!hasTranslation ()) {
I->p ("You manage to understand %s.", THE (trader));
}
MelnormeServiceData[choice].mNameKnown = 1;
I->p ("%c - %s", obj->mLetter, obj->inv ());
} else {
I->p ("This time you fail to understand %s.", THE (trader));
}
}
}
I->drawSideWin ();
}
/* Melnorme strategy:
- Wander around continuously until hero comes near
- When hero is in room stop and turn purple
- When hero left the room start to wander and turn green
Returns ms elapsed, -2 if the monster dies.
*/
int
shMonster::doMelnorme ()
{
int elapsed;
int result = -1;
int retries = 3;
int myRoom = Level->getRoomID (mX, mY);
while (-1 == result) {
if (!retries--) {
return 200;
}
/* Melnorme have no designated shop. They are willing to trade
if you enter their room. This also allows them to relocate. */
if (Level->getRoomID (Hero.mX, Hero.mY) == myRoom and
Level->getRoomID (mX, mY) != 0)
{
if (mGlyph.mColor == kGreen and !isHostile ()) {
/* Greet hero who just entered the room. */
if (Hero.tryToTranslate (this)) {
char *buf = GetBuf ();
int rnd;
switch (RNG (3)) {
case 0: /* hello, heroname/title/racename */
rnd = RNG (4);
strncpy (buf, rnd == 0 ? Hero.mName :
rnd == 1 ? Hero.mProfession->mName :
rnd == 2 ? Hero.getTitle () :
Hero.myIlk ()->mName, SHBUFLEN);
if (rnd == 0) buf[0] = toupper (buf[0]);
break;
case 1: /* hello, heroname the Janitor */
snprintf (buf, SHBUFLEN, "%s the %s", Hero.mName,
!RNG (3) ? Hero.mProfession->mName :
!RNG (2) ? Hero.getTitle () :
Hero.myIlk ()->mName);
buf[0] = toupper (buf[0]);
break;
case 2: /* hello, earthling Detective */
snprintf (buf, SHBUFLEN, "%s %s", Hero.myIlk ()->mName,
!RNG (2) ? Hero.mProfession->mName :
Hero.getTitle ());
break;
}
switch (RNG (4)) {
case 0:
I->p ("I bid you a formal welcome, %s.", buf); break;
case 1:
I->p ("Hello, %s.", buf); break;
case 2:
I->p ("How nice to see you, %s.", buf); break;
case 3: /* Use just the capitalized name because
greetings could be too long otherwise. */
strncpy (buf, Hero.mName, SHBUFLEN);
buf[0] = toupper (buf[0]);
I->p ("I had itchy pods recently, %s"
", and here you are!", buf);
break;
}
} else {
I->p ("%s mumbles something in coarse voice.", THE (this));
}
}
mGlyph.mColor = kMagenta;
mGlyph.mTileX = 3;
/* Hero was greeted properly. Is this first encounter? */
if (!Hero.getStoryFlag ("Met Melnorme")) {
Hero.setStoryFlag ("Met Melnorme", 1);
I->p ("Press '%s' to request services.",
I->getKeyForCommand (shInterface::kPay));
}
} else {
mGlyph.mColor = kGreen;
mGlyph.mTileX = 2;
}
switch (mTactic) {
case kNewEnemy:
mStrategy = kWander;
mTactic = kNewEnemy;
mGlyph.mColor = kNavy;
mGlyph.mTileX = 4;
return doWander ();
case kMoveTo:
result = doMoveTo ();
continue;
case kReady:
/* Usually stay where you are but occassionally
move to new square inside this room. */
if (myRoom and !RNG (6)) {
mDestX = RNG (mMelnorme.mSX, mMelnorme.mEX);
mDestY = RNG (mMelnorme.mSY, mMelnorme.mEY);
if (!mLevel->isOccupied (mDestX, mDestY)) {
elapsed = doQuickMoveTo ();
if (-1 == elapsed) elapsed = 800;
return elapsed;
}
return RNG (600, 1000); /* Path blocked. Wait. */
/* !myRoom == Warp out of corridors eagerly. */
} else if ((!myRoom or !RNG (40)) and
mGlyph.mColor == kGreen)
{
int newx = mX, newy = mY, tries = 3;
while (tries--) {
mLevel->findUnoccupiedSquare (&newx, &newy);
if (!mLevel->isOccupied (newx, newy) and
!mLevel->isInShop (newx, newy) and
/* Do not accept corridors. */
(myRoom = Level->getRoomID (newx, newy)))
{
transport (newx, newy, 100, 1);
/* Update location data. */
Level->getRoomDimensions (myRoom,
&mMelnorme.mSX, &mMelnorme.mSY,
&mMelnorme.mEX, &mMelnorme.mEY);
/* Exclude walls from room coordinates. */
++mMelnorme.mSX; ++mMelnorme.mSY;
--mMelnorme.mEX; --mMelnorme.mEY;
return FULLTURN;
}
}
return FULLTURN;
} else {
return FULLTURN;
}
default:
mTactic = kReady;
debug.log ("Unexpected Melnorme tactic!");
}
}
return FULLTURN;
}