This repository has been archived by the owner on Nov 28, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDoctor.cpp
323 lines (279 loc) · 9.07 KB
/
Doctor.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
#include "Global.h"
#include "Util.h"
#include "Hero.h"
#include "Creature.h"
#include "Interface.h"
/******************************************************
shopping code
******************************************************/
/* 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 ());
}
}
const char * MedicalProcedureNames[] =
{ "Wound Treatment",
"Restoration Treatment",
"Intestinal Examination",
"Systems Diagnostics",
"Radiation Purge",
"Caesarean Section"
};
shAttack CaesareanDamage =
shAttack (NULL, shAttack::kNoAttack, shAttack::kOther, 0,
kSlashing, 6, 6);
void
shHero::payDoctor (shMonster *doctor)
{
char buf[200];
shMenu menu ("Medical Services Menu", shMenu::kNothingAllowed);
int i, j, serv;
const int TREATMENT_COST = 200;
if (tryToTranslate (doctor)) {
/* make all services known */
for (i = 0; i < kMedMaxService; i++) {
MedicalProcedureData[i].mNameKnown = 1;
}
}
char letter = 'a';
for (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 ||
Hero.isViolated () ||
Hero.isConfused () ||
Hero.isStunned ())
{
goto addservice;
}
continue;
case kMedRestoration:
for (j = 1; j <= 7; j++) {
int abil = Hero.mAbil.getByIndex (j);
if (kCha == j) {
abil += Hero.mChaDrain;
}
if (abil < Hero.mMaxAbil.getByIndex (j))
goto addservice;
}
continue;
case kMedRectalExam:
case kMedDiagnostics:
case kMedRadPurification:
/* these services are always available: */
goto addservice;
case kMedCaesareanSection:
if (Hero.getStoryFlag ("impregnation"))
goto addservice;
default:
continue;
}
addservice:
snprintf (buf, sizeof(buf), "%s ($%d)",
MedicalProcedureData[serv].mNameKnown
? MedicalProcedureNames[serv]
: MedicalProcedureData[serv].mDesc,
TREATMENT_COST);
menu.addItem (letter++, buf, (void *) serv);
}
int choice;
if (!menu.getResult ((const void **) &choice))
return; /* nothing picked */
int price = TREATMENT_COST;
if (countMoney () < price) {
I->p ("You don't have enough money for that.");
return;
}
loseMoney (price);
doctor->gainMoney (price);
const char *who = doctor->the ();
switch (choice) {
case kMedHealing:
I->p ("%s injects you with a %s serum!", who,
findAnIlk (&RayGunIlks, "healing ray gun") ->getRayGunColor ());
if (Hero.healing (0))
MedicalProcedureData[choice].mNameKnown = 1;
break;
case kMedRestoration:
I->p ("%s injects you with a %s serum!", who,
findAnIlk (&RayGunIlks, "restoration ray gun") ->getRayGunColor ());
if (Hero.restoration ())
MedicalProcedureData[choice].mNameKnown = 1;
break;
case kMedRectalExam:
MedicalProcedureData[choice].mNameKnown = 1;
I->p ("%s probes you!", who);
Hero.makeViolated (1000 * NDX (20, 20));
break;
case kMedDiagnostics:
MedicalProcedureData[choice].mNameKnown = 1;
I->p ("%s probes you!", who);
Hero.doDiagnostics ();
break;
case kMedRadPurification:
MedicalProcedureData[choice].mNameKnown = 1;
I->p ("%s injects you with a bubbly serum!", who);
Hero.mRad -= RNG (1, 200);
Hero.mRad = maxi (0, Hero.mRad);
if (!Hero.mRad)
I->p ("You feel purified.");
else
I->p ("You feel less contaminated.");
break;
case kMedCaesareanSection:
{
if (!Hero.getStoryFlag ("impregnation"))
break;
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 (findAMonsterIlk (queen ? "alien princess"
: "chestburster"));
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 (&CaesareanDamage)) {
Hero.die (kKilled, "complications in childbirth");
}
break;
}
default:
break;
}
}
/* doctor strategy:
wait around for hero to request services;
occasionally advertise
returns ms elapsed, -2 if the monster dies
*/
int
shMonster::doDoctor ()
{
I->debug (" doctor strategy");
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) &&
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 unsigned int NUMQUIPS = 3;
const char *quips[NUMQUIPS] = {
"\"Dammit, %s! I'm a docbot, not %s!\"",
"\"Your second amputation is half off!\"",
"\"Galaxy-class health care services!\"",
};
const unsigned int NUMNOUNS = 10;
const char *nouns[NUMNOUNS] = {
"a magician",
"a psychiatrist",
"a bartender",
"a bricklayer",
"a mechanic",
"a priest",
"a lawyer",
"a prostitute",
"a toaster oven",
"a warbot"
};
if (Hero.tryToTranslate (this)) {
I->p (quips[RNG(NUMQUIPS)],
Hero.mName, nouns[RNG(NUMNOUNS)]);
Hero.interrupt ();
}
return RNG (500, 1000);
}
} else {
return RNG (800, 1600);
}
case kFight:
case kShoot:
mTactic = kReady;
I->debug ("Unexped doctor tactic!");
}
}
return RNG (300, 1000); /* keep on lurking */
}