forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiexamine.cpp
602 lines (548 loc) · 18 KB
/
iexamine.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
//
// iexamine.cpp
// Cataclysm
//
// Livingstone
//
#include "iuse.h"
#include "game.h"
#include "mapdata.h"
#include "keypress.h"
#include "output.h"
#include "rng.h"
#include "line.h"
#include "player.h"
#include <sstream>
void iexamine::none (game *g, player *p, map *m, int examx, int examy) {
g->add_msg("That is a %s.", m->tername(examx, examy).c_str());
};
void iexamine::gaspump(game *g, player *p, map *m, int examx, int examy) {
if (!query_yn("Use the %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
item gas(g->itypes["gasoline"], g->turn);
if (one_in(10 + p->dex_cur)) {
g->add_msg("You accidentally spill the gasoline.");
m->add_item(p->posx, p->posy, gas);
} else {
p->moves -= 300;
g->handle_liquid(gas, false, true);
}
if (one_in(50)) {
g->add_msg("With a clang and a shudder, the gas pump goes silent.");
m->ter_set(examx, examy, t_gas_pump_empty);
}
}
void iexamine::elevator(game *g, player *p, map *m, int examx, int examy){
if (!query_yn("Use the %s?",m->tername(examx, examy).c_str())) return;
int movez = (g->levz < 0 ? 2 : -2);
g->levz += movez;
m->load(g, g->levx, g->levy, g->levz);
g->update_map(p->posx, p->posy);
for (int x = 0; x < SEEX * MAPSIZE; x++) {
for (int y = 0; y < SEEY * MAPSIZE; y++) {
if (m->ter(x, y) == t_elevator) {
p->posx = x;
p->posy = y;
}
}
}
g->refresh_all();
}
void iexamine::controls_gate(game *g, player *p, map *m, int examx, int examy) {
if (!query_yn("Use the %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
g->open_gate(g,examx,examy, m->ter(examx,examy));
}
void iexamine::cardreader(game *g, player *p, map *m, int examx, int examy) {
itype_id card_type = (m->ter(examx, examy) == t_card_science ? "id_science" :
"id_military");
if (p->has_amount(card_type, 1) && query_yn("Swipe your ID card?")) {
p->moves -= 100;
for (int i = -3; i <= 3; i++) {
for (int j = -3; j <= 3; j++) {
if (m->ter(examx + i, examy + j) == t_door_metal_locked)
m->ter_set(examx + i, examy + j, t_floor);
}
}
for (int i = 0; i < g->z.size(); i++) {
if (g->z[i].type->id == mon_turret) {
g->z.erase(g->z.begin() + i);
i--;
}
}
g->add_msg("You insert your ID card.");
g->add_msg("The nearby doors slide into the floor.");
p->use_amount(card_type, 1);
} else {
bool using_electrohack = (p->has_amount("electrohack", 1) &&
query_yn("Use electrohack on the reader?"));
bool using_fingerhack = (!using_electrohack && p->has_bionic("bio_fingerhack") &&
p->power_level > 0 &&
query_yn("Use fingerhack on the reader?"));
if (using_electrohack || using_fingerhack) {
p->moves -= 500;
p->practice("computer", 20);
int success = rng(p->skillLevel("computer") / 4 - 2, p->skillLevel("computer") * 2);
success += rng(-3, 3);
if (using_fingerhack)
success++;
if (p->int_cur < 8)
success -= rng(0, int((8 - p->int_cur) / 2));
else if (p->int_cur > 8)
success += rng(0, int((p->int_cur - 8) / 2));
if (success < 0) {
g->add_msg("You cause a short circuit!");
if (success <= -5) {
if (using_electrohack) {
g->add_msg("Your electrohack is ruined!");
p->use_amount("electrohack", 1);
} else {
g->add_msg("Your power is drained!");
p->charge_power(0 - rng(0, p->power_level));
}
}
m->ter_set(examx, examy, t_card_reader_broken);
} else if (success < 6)
g->add_msg("Nothing happens.");
else {
g->add_msg("You activate the panel!");
g->add_msg("The nearby doors slide into the floor.");
m->ter_set(examx, examy, t_card_reader_broken);
for (int i = -3; i <= 3; i++) {
for (int j = -3; j <= 3; j++) {
if (m->ter(examx + i, examy + j) == t_door_metal_locked)
m->ter_set(examx + i, examy + j, t_floor);
}
}
}
} else {
g->add_msg("Looks like you need a %s.",g->itypes[card_type]->name.c_str());
}
}
}
void iexamine::rubble(game *g, player *p, map *m, int examx, int examy) {
if (!(p->has_amount("shovel", 1) || p->has_amount("primitive_shovel", 1))) {
g->add_msg("If only you had a shovel...");
return;
}
const char *xname = m->tername(examx, examy).c_str();
if (query_yn("Clear up that %s?",xname)) {
// "Remove"
p->moves -= 200;
// "Replace"
if(m->ter(examx,examy) == t_rubble) {
item rock(g->itypes["rock"], g->turn);
m->add_item(p->posx, p->posy, rock);
m->add_item(p->posx, p->posy, rock);
}
// "Refloor"
if (g->levz < 0) {
m->ter_set(examx, examy, t_rock_floor);
} else {
m->ter_set(examx, examy, t_dirt);
}
// "Remind"
g->add_msg("You clear up that %s.", xname);
}
}
void iexamine::chainfence(game *g, player *p, map *m, int examx, int examy) {
if (!query_yn("Climb %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
p->moves -= 400;
if (one_in(p->dex_cur)) {
g->add_msg("You slip whilst climbing and fall down again");
} else {
p->moves += p->dex_cur * 10;
p->posx = examx;
p->posy = examy;
}
}
void iexamine::tent(game *g, player *p, map *m, int examx, int examy) {
if (!query_yn("Take down %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
p->moves -= 200;
for (int i = -1; i <= 1; i++)
for (int j = -1; j <= 1; j++)
m->ter_set(examx + i, examy + j, t_dirt);
g->add_msg("You take down the tent");
item tent(g->itypes["tent_kit"], g->turn);
m->add_item(examx, examy, tent);
}
void iexamine::shelter(game *g, player *p, map *m, int examx, int examy) {
if (!query_yn("Take down %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
p->moves -= 200;
for (int i = -1; i <= 1; i++)
for (int j = -1; j <= 1; j++)
m->ter_set(examx + i, examy + j, t_dirt);
g->add_msg("You take down the shelter");
item tent(g->itypes["shelter_kit"], g->turn);
m->add_item(examx, examy, tent);
}
void iexamine::wreckage(game *g, player *p, map *m, int examx, int examy) {
if (!(p->has_amount("shovel", 1) || p->has_amount("primitive_shovel", 1))) {
g->add_msg("If only you had a shovel..");
return;
}
if (query_yn("Clear up that wreckage?")) {
p->moves -= 200;
m->ter_set(examx, examy, t_dirt);
item chunk(g->itypes["steel_chunk"], g->turn);
item scrap(g->itypes["scrap"], g->turn);
item pipe(g->itypes["pipe"], g->turn);
item wire(g->itypes["wire"], g->turn);
m->add_item(examx, examy, chunk);
m->add_item(examx, examy, scrap);
if (one_in(5)) {
m->add_item(examx, examy, pipe);
m->add_item(examx, examy, wire); }
g->add_msg("You clear the wreckage up");
}
}
void iexamine::pit(game *g, player *p, map *m, int examx, int examy) {
if(!p->has_amount("2x4", 1)) {
none(g, p, m, examx, examy);
return;
}
if (query_yn("Place a plank over the pit?")) {
p->use_amount("2x4", 1);
m->ter_set(examx, examy, t_pit_covered);
g->add_msg("You place a plank of wood over the pit");
} else {
g->add_msg("You need a plank of wood to do that");
}
}
void iexamine::pit_spiked(game *g, player *p, map *m, int examx, int examy) {
if(!p->has_amount("2x4", 1)) {
none(g, p, m, examx, examy);
return;
}
if (query_yn("Place a plank over the pit?")) {
p->use_amount("2x4", 1);
m->ter_set(examx, examy, t_pit_spiked_covered);
g->add_msg("You place a plank of wood over the pit");
} else {
g->add_msg("You need a plank of wood to do that");
}
}
void iexamine::pit_covered(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Remove cover?")) {
none(g, p, m, examx, examy);
return;
}
item plank(g->itypes["2x4"], g->turn);
g->add_msg("You remove the plank.");
m->add_item(p->posx, p->posy, plank);
m->ter_set(examx, examy, t_pit);
}
void iexamine::pit_spiked_covered(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Remove cover?")) {
none(g, p, m, examx, examy);
return;
}
item plank(g->itypes["2x4"], g->turn);
g->add_msg("You remove the plank.");
m->add_item(p->posx, p->posy, plank);
m->ter_set(examx, examy, t_pit_spiked);
}
void iexamine::fence_post(game *g, player *p, map *m, int examx, int examy) {
int ch = menu("Fence Construction:", "Rope Fence", "Wire Fence",
"Barbed Wire Fence", "Cancel", NULL);
switch (ch){
case 1:{
if (p->has_amount("rope_6", 2)) {
p->use_amount("rope_6", 2);
m->ter_set(examx, examy, t_fence_rope);
p->moves -= 200;
} else
g->add_msg("You need 2 six-foot lengths of rope to do that");
} break;
case 2:{
if (p->has_amount("wire", 2)) {
p->use_amount("wire", 2);
m->ter_set(examx, examy, t_fence_wire);
p->moves -= 200;
} else
g->add_msg("You need 2 lengths of wire to do that!");
} break;
case 3:{
if (p->has_amount("wire_barbed", 2)) {
p->use_amount("wire_barbed", 2);
m->ter_set(examx, examy, t_fence_barbed);
p->moves -= 200;
} else
g->add_msg("You need 2 lengths of barbed wire to do that!");
} break;
case 4:
default:
break;
}
}
void iexamine::remove_fence_rope(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Remove %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
item rope(g->itypes["rope_6"], g->turn);
m->add_item(p->posx, p->posy, rope);
m->add_item(p->posx, p->posy, rope);
m->ter_set(examx, examy, t_fence_post);
p->moves -= 200;
}
void iexamine::remove_fence_wire(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Remove %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
item rope(g->itypes["wire"], g->turn);
m->add_item(p->posx, p->posy, rope);
m->add_item(p->posx, p->posy, rope);
m->ter_set(examx, examy, t_fence_post);
p->moves -= 200;
}
void iexamine::remove_fence_barbed(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Remove %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
item rope(g->itypes["wire_barbed"], g->turn);
m->add_item(p->posx, p->posy, rope);
m->add_item(p->posx, p->posy, rope);
m->ter_set(examx, examy, t_fence_post);
p->moves -= 200;
}
void iexamine::slot_machine(game *g, player *p, map *m, int examx, int examy) {
if (p->cash < 10)
g->add_msg("You need $10 to play.");
else if (query_yn("Insert $10?")) {
do {
if (one_in(5))
popup("Three cherries... you get your money back!");
else if (one_in(20)) {
popup("Three bells... you win $50!");
p->cash += 40; // Minus the $10 we wagered
} else if (one_in(50)) {
popup("Three stars... you win $200!");
p->cash += 190;
} else if (one_in(1000)) {
popup("JACKPOT! You win $5000!");
p->cash += 4990;
} else {
popup("No win.");
p->cash -= 10;
}
} while (p->cash >= 10 && query_yn("Play again?"));
}
}
void iexamine::bulletin_board(game *g, player *p, map *m, int examx, int examy) {
basecamp *camp = m->camp_at(examx, examy);
if (camp && camp->board_x() == examx && camp->board_y() == examy) {
std::vector<std::string> options;
options.push_back("Cancel");
int choice = menu_vec(camp->board_name().c_str(), options) - 1;
}
else {
bool create_camp = m->allow_camp(examx, examy);
std::vector<std::string> options;
if (create_camp)
options.push_back("Create camp");
options.push_back("Cancel");
// TODO: Other Bulletin Boards
int choice = menu_vec("Bulletin Board", options) - 1;
if (choice >= 0 && choice < options.size()) {
if (options[choice] == "Create camp") {
// TODO: Allow text entry for name
m->add_camp("Home", examx, examy);
}
}
}
}
void iexamine::fault(game *g, player *p, map *m, int examx, int examy) {
popup("\
This wall is perfectly vertical. Odd, twisted holes are set in it, leading\n\
as far back into the solid rock as you can see. The holes are humanoid in\n\
shape, but with long, twisted, distended limbs.");
}
void iexamine::pedestal_wyrm(game *g, player *p, map *m, int examx, int examy) {
if (!m->i_at(examx, examy).empty()) {
none(g, p, m, examx, examy);
return;
}
g->add_msg("The pedestal sinks into the ground...");
m->ter_set(examx, examy, t_rock_floor);
g->add_event(EVENT_SPAWN_WYRMS, int(g->turn) + rng(5, 10));
}
void iexamine::pedestal_temple(game *g, player *p, map *m, int examx, int examy) {
if (m->i_at(examx, examy).size() == 1 &&
m->i_at(examx, examy)[0].type->id == "petrified_eye") {
g->add_msg("The pedestal sinks into the ground...");
m->ter_set(examx, examy, t_dirt);
m->i_at(examx, examy).clear();
g->add_event(EVENT_TEMPLE_OPEN, int(g->turn) + 4);
} else if (p->has_amount("petrified_eye", 1) &&
query_yn("Place your petrified eye on the pedestal?")) {
p->use_amount("petrified_eye", 1);
g->add_msg("The pedestal sinks into the ground...");
m->ter_set(examx, examy, t_dirt);
g->add_event(EVENT_TEMPLE_OPEN, int(g->turn) + 4);
} else
g->add_msg("This pedestal is engraved in eye-shaped diagrams, and has a large\
semi-spherical indentation at the top.");
}
void iexamine::fswitch(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Flip the %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
p->moves -= 100;
for (int y = examy; y <= examy + 5; y++) {
for (int x = 0; x < SEEX * MAPSIZE; x++) {
switch (m->ter(examx, examy)) {
case t_switch_rg:
if (m->ter(x, y) == t_rock_red)
m->ter_set(x, y, t_floor_red);
else if (m->ter(x, y) == t_floor_red)
m->ter_set(x, y, t_rock_red);
else if (m->ter(x, y) == t_rock_green)
m->ter_set(x, y, t_floor_green);
else if (m->ter(x, y) == t_floor_green)
m->ter_set(x, y, t_rock_green);
break;
case t_switch_gb:
if (m->ter(x, y) == t_rock_blue)
m->ter_set(x, y, t_floor_blue);
else if (m->ter(x, y) == t_floor_blue)
m->ter_set(x, y, t_rock_blue);
else if (m->ter(x, y) == t_rock_green)
m->ter_set(x, y, t_floor_green);
else if (m->ter(x, y) == t_floor_green)
m->ter_set(x, y, t_rock_green);
break;
case t_switch_rb:
if (m->ter(x, y) == t_rock_blue)
m->ter_set(x, y, t_floor_blue);
else if (m->ter(x, y) == t_floor_blue)
m->ter_set(x, y, t_rock_blue);
else if (m->ter(x, y) == t_rock_red)
m->ter_set(x, y, t_floor_red);
else if (m->ter(x, y) == t_floor_red)
m->ter_set(x, y, t_rock_red);
break;
case t_switch_even:
if ((y - examy) % 2 == 1) {
if (m->ter(x, y) == t_rock_red)
m->ter_set(x, y, t_floor_red);
else if (m->ter(x, y) == t_floor_red)
m->ter_set(x, y, t_rock_red);
else if (m->ter(x, y) == t_rock_green)
m->ter_set(x, y, t_floor_green);
else if (m->ter(x, y) == t_floor_green)
m->ter_set(x, y, t_rock_green);
else if (m->ter(x, y) == t_rock_blue)
m->ter_set(x, y, t_floor_blue);
else if (m->ter(x, y) == t_floor_blue)
m->ter_set(x, y, t_rock_blue);
}
break;
}
}
}
g->add_msg("You hear the rumble of rock shifting.");
g->add_event(EVENT_TEMPLE_SPAWN, g->turn + 3);
}
void iexamine::flower_poppy(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Pick %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
g->add_msg("This flower has a heady aroma");
if (!(p->is_wearing("mask_filter")||p->is_wearing("mask_gas") ||
one_in(3))) {
g->add_msg("You fall asleep...");
p->add_disease(DI_SLEEP, 1200, g);
g->add_msg("Your legs are covered by flower's roots!");
p->hurt(g,bp_legs, 0, 4);
p->moves-=50;
}
m->ter_set(examx, examy, t_dirt);
m->spawn_item(examx, examy, g->itypes["poppy_flower"],0);
m->spawn_item(examx, examy, g->itypes["poppy_bud"],0);
}
void iexamine::tree_apple(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Pick %s?",m->tername(examx, examy).c_str())) return;
int num_apples = rng(1, p->skillLevel("survival"));
if (num_apples >= 12)
num_apples = 12;
for (int i = 0; i < num_apples; i++)
m->spawn_item(examx, examy, g->itypes["apple"], g->turn, 0);
m->ter_set(examx, examy, t_tree);
}
void iexamine::shrub_blueberry(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Pick %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
int num_blueberries = rng(1, p->skillLevel("survival"));
if (num_blueberries >= 12)
num_blueberries = 12;
for (int i = 0; i < num_blueberries; i++)
m->spawn_item(examx, examy, g->itypes["blueberries"], g->turn, 0);
m->ter_set(examx, examy, t_shrub);
}
void iexamine::shrub_wildveggies(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Pick %s?",m->tername(examx, examy).c_str())) return;
p->assign_activity(g, ACT_FORAGE, 500 / (p->skillLevel("survival") + 1), 0);
p->activity.placement = point(examx, examy);
p->moves = 0;
}
void iexamine::recycler(game *g, player *p, map *m, int examx, int examy) {
if(!query_yn("Use the %s?",m->tername(examx, examy).c_str())) {
none(g, p, m, examx, examy);
return;
}
if (m->i_at(examx, examy).size() > 0)
{
g->sound(examx, examy, 80, "Ka-klunk!");
int num_metal = 0;
for (int i = 0; i < m->i_at(examx, examy).size(); i++)
{
item *it = &(m->i_at(examx, examy)[i]);
if (it->made_of(STEEL))
num_metal++;
m->i_at(examx, examy).erase(m->i_at(examx, examy).begin() + i);
i--;
}
if (num_metal > 0)
{
while (num_metal > 9)
{
m->spawn_item(p->posx, p->posy, g->itypes["steel_lump"], 0);
num_metal -= 10;
}
do
{
m->spawn_item(p->posx, p->posy, g->itypes["steel_chunk"], 0);
num_metal -= 3;
} while (num_metal > 2);
}
}
else g->add_msg("The recycler is empty.");
}
void iexamine::trap(game *g, player *p, map *m, int examx, int examy) {
if (g->traps[m->tr_at(examx, examy)]->difficulty < 99 &&
p->per_cur-p->encumb(bp_eyes) >= g->traps[m->tr_at(examx, examy)]->visibility &&
query_yn("There is a %s there. Disarm?",
g->traps[m->tr_at(examx, examy)]->name.c_str())) {
m->disarm_trap(g, examx, examy);
}
}