/
decks.cc
1740 lines (1492 loc) · 48.7 KB
/
decks.cc
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
/**
* @file
* @brief Functions with decks of cards.
**/
#include "AppHdr.h"
#include "decks.h"
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <unordered_set>
#include "ability.h"
#include "abyss.h"
#include "artefact.h"
#include "beam.h"
#include "cloud.h"
#include "coordit.h"
#include "dactions.h"
#include "database.h"
#include "describe.h"
#include "directn.h"
#include "dungeon.h"
#include "evoke.h"
#include "ghost.h"
#include "god-passive.h" // passive_t::no_haste
#include "god-wrath.h"
#include "invent.h"
#include "item-prop.h"
#include "item-status-flag-type.h"
#include "items.h"
#include "libutil.h"
#include "macro.h"
#include "message.h"
#include "mon-cast.h"
#include "mon-clone.h"
#include "mon-place.h"
#include "mon-poly.h"
#include "mon-project.h"
#include "mon-util.h"
#include "mutation.h"
#include "notes.h"
#include "output.h"
#include "prompt.h"
#include "random.h"
#include "religion.h"
#include "spl-clouds.h"
#include "spl-goditem.h"
#include "spl-miscast.h"
#include "spl-monench.h"
#include "state.h"
#include "stringutil.h"
#include "tag-version.h"
#include "teleport.h"
#include "terrain.h"
#include "transform.h"
#include "traps.h"
#include "uncancel.h"
#include "unicode.h"
#include "view.h"
#include "viewchar.h"
#include "xom.h"
using namespace ui;
typedef map<card_type, int> deck_archetype;
deck_archetype deck_of_escape =
{
{ CARD_TOMB, 5 },
{ CARD_EXILE, 3 },
{ CARD_ELIXIR, 5 },
{ CARD_CLOUD, 5 },
{ CARD_VELOCITY, 5 },
};
deck_archetype deck_of_destruction =
{
{ CARD_VITRIOL, 5 },
{ CARD_PAIN, 5 },
{ CARD_ORB, 5 },
{ CARD_DEGEN, 3 },
{ CARD_WILD_MAGIC, 5 },
{ CARD_STORM, 5 },
};
deck_archetype deck_of_summoning =
{
{ CARD_ELEMENTS, 5 },
{ CARD_SUMMON_DEMON, 5 },
{ CARD_SUMMON_WEAPON, 5 },
{ CARD_SUMMON_BEE, 5 },
{ CARD_RANGERS, 5 },
{ CARD_ILLUSION, 5 },
};
deck_archetype deck_of_punishment =
{
{ CARD_WRAITH, 5 },
{ CARD_WRATH, 5 },
{ CARD_SWINE, 5 },
{ CARD_TORMENT, 5 },
};
struct deck_type_data
{
string name;
string flavour;
/// The list of cards this deck contains.
deck_archetype cards;
int deck_max;
};
static map<deck_type, deck_type_data> all_decks =
{
{ DECK_OF_ESCAPE, {
"escape", "which may bring the user to safety or impede their foes.",
deck_of_escape,
13,
} },
{ DECK_OF_DESTRUCTION, {
"destruction", "which hurl death and destruction with wild abandon.",
deck_of_destruction,
26,
} },
{ DECK_OF_SUMMONING, {
"summoning", "depicting a range of weird and wonderful creatures.",
deck_of_summoning,
13,
} },
{ DECK_OF_PUNISHMENT, {
"punishment", "which wreak havoc on the user.", deck_of_punishment,
0, // Not a user deck
} },
};
vector<ability_type> deck_ability = {
ABIL_NEMELEX_DRAW_ESCAPE,
ABIL_NEMELEX_DRAW_DESTRUCTION,
ABIL_NEMELEX_DRAW_SUMMONING,
ABIL_NON_ABILITY,
ABIL_NEMELEX_DRAW_STACK
};
const char* card_name(card_type card)
{
switch (card)
{
case CARD_VELOCITY: return "Velocity";
case CARD_EXILE: return "Exile";
case CARD_ELIXIR: return "the Elixir";
case CARD_TOMB: return "the Tomb";
case CARD_WILD_MAGIC: return "Wild Magic";
case CARD_ELEMENTS: return "the Elements";
case CARD_SUMMON_DEMON: return "the Pentagram";
case CARD_SUMMON_WEAPON: return "the Dance";
case CARD_SUMMON_BEE: return "the Swarm";
case CARD_RANGERS: return "the Rangers";
case CARD_VITRIOL: return "Vitriol";
case CARD_CLOUD: return "the Cloud";
case CARD_STORM: return "the Storm";
case CARD_PAIN: return "Pain";
case CARD_TORMENT: return "Torment";
case CARD_WRATH: return "Wrath";
case CARD_WRAITH: return "the Wraith";
case CARD_SWINE: return "the Swine";
case CARD_ORB: return "the Orb";
case CARD_ILLUSION: return "the Illusion";
case CARD_DEGEN: return "Degeneration";
#if TAG_MAJOR_VERSION == 34
case CARD_FAMINE_REMOVED:
case CARD_SHAFT_REMOVED:
case CARD_STAIRS_REMOVED:
#endif
case NUM_CARDS: return "a buggy card";
}
return "a very buggy card";
}
bool card_is_removed(card_type card)
{
switch (card)
{
#if TAG_MAJOR_VERSION == 34
case CARD_FAMINE_REMOVED:
case CARD_SHAFT_REMOVED:
case CARD_STAIRS_REMOVED:
return true;
#endif
default:
return false;
}
}
card_type name_to_card(string name)
{
for (int i = 0; i < NUM_CARDS; i++)
{
if (card_name(static_cast<card_type>(i)) == name)
return static_cast<card_type>(i);
}
return NUM_CARDS;
}
static const deck_archetype _cards_in_deck(deck_type deck)
{
deck_type_data *deck_data = map_find(all_decks, deck);
if (deck_data)
return deck_data->cards;
#ifdef ASSERTS
die("No cards found for %u", unsigned(deck));
#endif
return {};
}
const string stack_contents()
{
const auto& stack = you.props[NEMELEX_STACK_KEY].get_vector();
string output = "";
output += comma_separated_fn(
reverse_iterator<CrawlVector::const_iterator>(stack.end()),
reverse_iterator<CrawlVector::const_iterator>(stack.begin()),
[](const CrawlStoreValue& card) { return card_name((card_type)card.get_int()); });
if (!stack.empty())
output += ".";
return output;
}
const string stack_top()
{
const auto& stack = you.props[NEMELEX_STACK_KEY].get_vector();
if (stack.empty())
return "none";
else
return card_name((card_type) stack[stack.size() - 1].get_int());
}
const string deck_contents(deck_type deck)
{
if (deck == DECK_STACK)
return "Remaining cards: " + stack_contents();
string output = "It may contain the following cards: ";
// This way of doing things is intended to prevent a card
// that appears in multiple subdecks from showing up twice in the
// output.
set<card_type> cards;
const deck_archetype &pdeck =_cards_in_deck(deck);
for (const auto& cww : pdeck)
cards.insert(cww.first);
output += comma_separated_fn(cards.begin(), cards.end(), card_name);
output += ".";
return output;
}
const string deck_flavour(deck_type deck)
{
if (deck == DECK_STACK)
return "set aside for later.";
deck_type_data* deck_data = map_find(all_decks, deck);
if (deck_data)
return deck_data->flavour;
return "";
}
static card_type _random_card(deck_type deck)
{
const deck_archetype &pdeck = _cards_in_deck(deck);
return *random_choose_weighted(pdeck);
}
int deck_cards(deck_type deck)
{
return deck == DECK_STACK ? you.props[NEMELEX_STACK_KEY].get_vector().size()
: you.props[deck_name(deck)].get_int();
}
bool gift_cards()
{
const int deal = random_range(MIN_GIFT_CARDS, MAX_GIFT_CARDS);
bool dealt_cards = false;
set<deck_type> sufficiency;
for (int i = 0; i < deal; i++)
{
deck_type choice = random_choose_weighted(
3, DECK_OF_DESTRUCTION,
1, DECK_OF_SUMMONING,
1, DECK_OF_ESCAPE);
if (deck_cards(choice) >= all_decks[choice].deck_max)
{
sufficiency.insert(choice);
continue;
}
you.props[deck_name(choice)]++;
dealt_cards = true;
}
if (!dealt_cards)
{
vector<string> deck_names;
for (deck_type deck : sufficiency)
{
const deck_type_data *deck_data = map_find(all_decks, deck);
deck_names.push_back(deck_data ? deck_data->name : "bugginess");
}
mprf(MSGCH_GOD, you.religion,
"%s goes to deal, but finds you have enough %s cards.",
god_name(you.religion).c_str(),
join_strings(deck_names.begin(), deck_names.end(), " and ").c_str());
}
return dealt_cards;
}
void reset_cards()
{
for (int i = FIRST_PLAYER_DECK; i <= LAST_PLAYER_DECK; i++)
you.props[deck_name((deck_type) i)] = 0;
you.props[NEMELEX_STACK_KEY].get_vector().clear();
}
string deck_summary()
{
vector<string> stats;
for (int i = FIRST_PLAYER_DECK; i <= LAST_PLAYER_DECK; i++)
{
int cards = deck_cards((deck_type) i);
const deck_type_data *deck_data = map_find(all_decks, (deck_type) i);
const string name = deck_data ? deck_data->name : "bugginess";
if (cards)
{
stats.push_back(make_stringf("%d %s card%s", cards,
name.c_str(), cards == 1 ? "" : "s"));
}
}
return comma_separated_line(stats.begin(), stats.end());
}
string which_decks(card_type card)
{
vector<string> decks;
string output = "\n";
bool punishment = false;
for (auto &deck_data : all_decks)
{
if (!deck_data.second.cards.count(card))
continue;
if (deck_data.first == DECK_OF_PUNISHMENT)
punishment = true;
else
decks.push_back(deck_data.second.name);
}
if (!decks.empty())
{
output += "It is found in decks of "
+ comma_separated_line(decks.begin(), decks.end());
if (punishment)
output += ", or in Nemelex Xobeh's deck of punishment";
output += ".";
}
else if (punishment)
{
output += "It is only found in Nemelex Xobeh's deck of "
"punishment.";
}
else
output += "It is normally not part of any deck.";
return output;
}
static void _describe_cards(CrawlVector& cards)
{
ASSERT(!cards.empty());
auto scroller = make_shared<Scroller>();
auto vbox = make_shared<Box>(Widget::VERT);
#ifdef USE_TILE_WEB
tiles.json_open_object();
tiles.json_open_array("cards");
#endif
bool seen[NUM_CARDS] = {0};
ostringstream data;
bool first = true;
for (auto& val : cards)
{
card_type card = (card_type) val.get_int();
if (seen[card])
continue;
seen[card] = true;
string name = card_name(card);
string desc = getLongDescription(name + " card");
if (desc.empty())
desc = "No description found.\n";
string decks = which_decks(card);
name = uppercase_first(name);
desc = desc + decks;
auto title_hbox = make_shared<Box>(Widget::HORZ);
#ifdef USE_TILE
auto icon = make_shared<Image>();
icon->set_tile(tile_def(TILEG_NEMELEX_CARD));
title_hbox->add_child(move(icon));
#endif
auto title = make_shared<Text>(formatted_string(name, WHITE));
title->set_margin_for_sdl(0, 0, 0, 10);
title_hbox->add_child(move(title));
title_hbox->set_cross_alignment(Widget::CENTER);
title_hbox->set_margin_for_crt(first ? 0 : 1, 0);
title_hbox->set_margin_for_sdl(first ? 0 : 20, 0);
vbox->add_child(move(title_hbox));
auto text = make_shared<Text>(desc);
text->set_wrap_text(true);
vbox->add_child(move(text));
#ifdef USE_TILE_WEB
tiles.json_open_object();
tiles.json_write_string("name", name);
tiles.json_write_string("desc", desc);
tiles.json_close_object();
#endif
first = false;
}
#ifdef USE_TILE_LOCAL
vbox->max_size().width = tiles.get_crt_font()->char_width()*80;
#endif
scroller->set_child(move(vbox));
auto popup = make_shared<ui::Popup>(scroller);
bool done = false;
popup->on_keydown_event([&done, &scroller](const KeyEvent& ev) {
done = !scroller->on_event(ev);
return true;
});
#ifdef USE_TILE_WEB
tiles.json_close_array();
tiles.push_ui_layout("describe-cards", 0);
popup->on_layout_pop([](){ tiles.pop_ui_layout(); });
#endif
ui::run_layout(move(popup), done);
}
string deck_status(deck_type deck)
{
const string name = deck_name(deck);
const int cards = deck_cards(deck);
ostringstream desc;
desc << chop_string(deck_name(deck), 24)
<< to_string(cards);
return trimmed_string(desc.str());
}
string deck_description(deck_type deck)
{
ostringstream desc;
desc << "A deck of magical cards, ";
desc << deck_flavour(deck) << "\n\n";
desc << deck_contents(deck) << "\n";
if (deck != DECK_STACK)
{
const int cards = deck_cards(deck);
desc << "\n";
if (cards > 1)
desc << make_stringf("It currently has %d cards ", cards);
else if (cards == 1)
desc << "It currently has 1 card ";
else
desc << "It is currently empty ";
desc << make_stringf("and can contain up to %d cards.",
all_decks[deck].deck_max);
desc << "\n";
}
return desc.str();
}
/**
* The deck a given ability uses. Asserts if called on an ability that does not
* use decks.
*
* @param abil the ability
*
* @return the deck
*/
deck_type ability_deck(ability_type abil)
{
auto deck = find(deck_ability.begin(), deck_ability.end(), abil);
ASSERT(deck != deck_ability.end());
return (deck_type) distance(deck_ability.begin(), deck);
}
// This will assert if the player doesn't have the ability to draw from the
// deck passed.
static char _deck_hotkey(deck_type deck)
{
return get_talent(deck_ability[deck], false).hotkey;
}
static deck_type _choose_deck(const string title = "Draw")
{
// TODO: refactor this into a subclass?
ToggleableMenu deck_menu(MF_SINGLESELECT
| MF_NO_WRAP_ROWS | MF_TOGGLE_ACTION
| MF_ARROWS_SELECT | MF_INIT_HOVER);
{
ToggleableMenuEntry* me =
new ToggleableMenuEntry(make_stringf("%s which deck? "
"Cards available", title.c_str()),
"Describe which deck? "
"Cards available",
MEL_TITLE);
deck_menu.set_title(me, true, true);
}
deck_menu.set_tag("deck");
deck_menu.add_toggle_from_command(CMD_MENU_CYCLE_MODE);
deck_menu.add_toggle_from_command(CMD_MENU_CYCLE_MODE_REVERSE);
// help here amounts to describing decks:
deck_menu.add_toggle_from_command(CMD_MENU_HELP);
deck_menu.menu_action = Menu::ACT_EXECUTE;
// XX proper keyhelp
deck_menu.set_more(formatted_string::parse_string(
menu_keyhelp_cmd(CMD_MENU_HELP) + " toggle "
"between deck selection and description."));
int numbers[NUM_DECKS];
for (int i = FIRST_PLAYER_DECK; i <= LAST_PLAYER_DECK; i++)
{
ToggleableMenuEntry* me =
new ToggleableMenuEntry(deck_status(static_cast<deck_type>(i)),
deck_status(static_cast<deck_type>(i)),
MEL_ITEM, 1, _deck_hotkey(static_cast<deck_type>(i)));
numbers[i] = i;
me->data = &numbers[i];
if (!deck_cards((deck_type)i))
me->colour = COL_USELESS;
me->add_tile(tile_def(TILEG_NEMELEX_DECK + i - FIRST_PLAYER_DECK + 1));
deck_menu.add_entry(me);
}
int ret = NUM_DECKS;
deck_menu.on_examine = [](const MenuEntry& sel)
{
int selected = *(static_cast<int*>(sel.data));
describe_deck((deck_type) selected);
return true;
};
deck_menu.on_single_selection = [&ret](const MenuEntry& sel)
{
ASSERT(sel.hotkeys.size() == 1);
ret = *(static_cast<int*>(sel.data));
return false;
};
deck_menu.show(false);
if (!crawl_state.doing_prev_cmd_again)
{
redraw_screen();
update_screen();
}
return (deck_type) ret;
}
/**
* Printed when a deck is exhausted
*
* @return A message to print;
* e.g. "the deck of cards disappears without a trace."
*/
static string _empty_deck_msg()
{
string message = random_choose("disappears without a trace.",
"glows slightly and disappears.",
"glows with a rainbow of weird colours and disappears.");
return "The deck of cards " + message;
}
static void _evoke_deck(deck_type deck, bool dealt = false)
{
ASSERT(deck_cards(deck) > 0);
mprf("You %s a card...", dealt ? "deal" : "draw");
if (deck == DECK_STACK)
{
auto& stack = you.props[NEMELEX_STACK_KEY].get_vector();
card_type card = (card_type) stack[stack.size() - 1].get_int();
stack.pop_back();
card_effect(card, dealt);
}
else
{
--you.props[deck_name(deck)];
card_effect(_random_card(deck), dealt);
}
if (!deck_cards(deck))
mpr(_empty_deck_msg());
}
// Draw one card from a deck, prompting the user for a choice
bool deck_draw(deck_type deck)
{
if (!deck_cards(deck))
{
mpr("That deck is empty!");
return false;
}
_evoke_deck(deck);
return true;
}
spret deck_stack(bool fail)
{
if (crawl_state.is_replaying_keys())
{
crawl_state.cancel_cmd_all("You can't repeat Stack Five.");
return spret::abort;
}
int total_cards = 0;
for (int i = FIRST_PLAYER_DECK; i <= LAST_PLAYER_DECK; ++i)
total_cards += deck_cards((deck_type) i);
if (deck_cards(DECK_STACK) && !yesno("Replace your current stack?",
false, 0))
{
canned_msg(MSG_OK);
return spret::abort;
}
if (!total_cards)
{
mpr("You are out of cards!");
return spret::abort;
}
if (total_cards < 5 && !yesno("You have fewer than five cards, "
"stack them anyway?", false, 0))
{
canned_msg(MSG_OK);
return spret::abort;
}
fail_check();
you.props[NEMELEX_STACK_KEY].get_vector().clear();
run_uncancel(UNC_STACK_FIVE, min(total_cards, 5));
return spret::success;
}
class StackFiveMenu : public Menu
{
virtual bool process_key(int keyin) override;
CrawlVector& draws;
public:
// TODO: is there a sensible way to implement hover / mouse support for
// this?
StackFiveMenu(CrawlVector& d)
: Menu(MF_NOSELECT | MF_UNCANCEL),
draws(d)
{};
};
bool StackFiveMenu::process_key(int keyin)
{
if (keyin == CK_ENTER)
{
formatted_string old_more = more;
set_more(formatted_string::parse_string(
"Are you done? (press y or Y to confirm)"));
if (yesno(nullptr, true, 'n', false, false, true))
return false;
set_more(old_more);
}
else if (keyin == '?')
_describe_cards(draws);
else if (keyin >= '1' && keyin <= '0' + static_cast<int>(draws.size()))
{
const unsigned int i = keyin - '1';
for (unsigned int j = 0; j < items.size(); j++)
if (items[j]->selected())
{
swap(draws[i], draws[j]);
swap(items[i]->text, items[j]->text);
items[j]->colour = LIGHTGREY;
select_item_index(i, 0); // this also updates the item
select_item_index(j, 0);
return true;
}
items[i]->colour = WHITE;
select_item_index(i, 1);
}
else
Menu::process_key(keyin); // intentionally do not return here
return true;
}
static void _draw_stack(int to_stack)
{
// TODO: refactor into its own subclass?
ToggleableMenu deck_menu(MF_SINGLESELECT | MF_UNCANCEL
| MF_NO_WRAP_ROWS | MF_TOGGLE_ACTION
| MF_ARROWS_SELECT | MF_INIT_HOVER);
{
ToggleableMenuEntry* me =
new ToggleableMenuEntry("Draw which deck? "
"Cards available",
"Describe which deck? "
"Cards available",
MEL_TITLE);
deck_menu.set_title(me, true, true);
}
deck_menu.set_tag("deck");
deck_menu.add_toggle_from_command(CMD_MENU_CYCLE_MODE);
deck_menu.add_toggle_from_command(CMD_MENU_CYCLE_MODE_REVERSE);
deck_menu.menu_action = Menu::ACT_EXECUTE;
auto& stack = you.props[NEMELEX_STACK_KEY].get_vector();
if (!stack.empty())
{
string status = "Drawn so far: " + stack_contents();
deck_menu.set_more(formatted_string::parse_string(
status + "\n" +
menu_keyhelp_cmd(CMD_MENU_HELP) + " toggle "
"between deck selection and description."));
}
else
{
deck_menu.set_more(formatted_string::parse_string(
menu_keyhelp_cmd(CMD_MENU_HELP) + " toggle "
"between deck selection and description."));
}
int numbers[NUM_DECKS];
for (int i = FIRST_PLAYER_DECK; i <= LAST_PLAYER_DECK; i++)
{
ToggleableMenuEntry* me =
new ToggleableMenuEntry(deck_status((deck_type)i),
deck_status((deck_type)i),
MEL_ITEM, 1, _deck_hotkey((deck_type)i));
numbers[i] = i;
me->data = &numbers[i];
// TODO: update this if a deck is emptied while in this menu
if (!deck_cards((deck_type)i))
me->colour = COL_USELESS;
me->add_tile(tile_def(TILEG_NEMELEX_DECK + i - FIRST_PLAYER_DECK + 1));
deck_menu.add_entry(me);
}
deck_menu.on_examine = [](const MenuEntry& sel)
{
// what's up with these casts
deck_type selected = (deck_type) *(static_cast<int*>(sel.data));
describe_deck(selected);
return true;
};
deck_menu.on_single_selection = [&deck_menu, &stack, to_stack](const MenuEntry& sel)
{
ASSERT(sel.hotkeys.size() == 1);
deck_type selected = (deck_type) *(static_cast<int*>(sel.data));
// Need non-const access to the selection.
ToggleableMenuEntry* me =
static_cast<ToggleableMenuEntry*>(deck_menu.selected_entries()[0]);
string status;
if (deck_cards(selected))
{
you.props[deck_name(selected)]--;
me->text = deck_status(selected);
me->alt_text = deck_status(selected);
card_type draw = _random_card(selected);
stack.push_back(draw);
}
else
status = "<lightred>That deck is empty!</lightred> ";
if (stack.size() > 0)
status += "Drawn so far: " + stack_contents();
deck_menu.set_more(formatted_string::parse_string(
status + "\n" +
"Press '<w>!</w>' or '<w>?</w>' to toggle "
"between deck selection and description."));
return stack.size() < to_stack;
};
deck_menu.show(false);
}
bool stack_five(int to_stack)
{
auto& stack = you.props[NEMELEX_STACK_KEY].get_vector();
// TODO: this loop makes me sad
while (stack.size() < to_stack)
{
if (crawl_state.seen_hups)
return false;
_draw_stack(to_stack);
}
StackFiveMenu menu(stack);
MenuEntry *const title = new MenuEntry("Select two cards to swap them:", MEL_TITLE);
menu.set_title(title);
for (unsigned int i = 0; i < stack.size(); i++)
{
MenuEntry * const entry =
new MenuEntry(card_name((card_type)stack[i].get_int()),
MEL_ITEM, 1, '1'+i);
entry->add_tile(tile_def(TILEG_NEMELEX_CARD));
menu.add_entry(entry);
}
menu.set_more(formatted_string::parse_string(
"<lightgrey>Press <w>?</w> for the card descriptions"
" or <w>Enter</w> to accept."));
menu.show();
if (crawl_state.seen_hups)
return false;
else
{
std::reverse(stack.begin(), stack.end());
return true;
}
}
// Draw the top four cards of an deck and play them all.
// Return spret::abort if the operation was failed/aborted along the way.
spret deck_deal(bool fail)
{
deck_type choice = _choose_deck("Deal");
if (choice == NUM_DECKS)
return spret::abort;
int num_cards = deck_cards(choice);
if (!num_cards)
{
mpr("That deck is empty!");
return spret::abort;
}
fail_check();
const int num_to_deal = min(num_cards, 4);
for (int i = 0; i < num_to_deal; ++i)
_evoke_deck(choice, true);
return spret::success;
}
// Draw the next three cards, discard two and pick one.
spret deck_triple_draw(bool fail)
{
if (crawl_state.is_replaying_keys())
{
crawl_state.cancel_cmd_all("You can't repeat Triple Draw.");
return spret::abort;
}
deck_type choice = _choose_deck();
if (choice == NUM_DECKS)
return spret::abort;
int num_cards = deck_cards(choice);
if (!num_cards)
{
mpr("That deck is empty!");
return spret::abort;
}
if (num_cards < 3 && !yesno("There's fewer than three cards, "
"still triple draw?", false, 0))
{
canned_msg(MSG_OK);
return spret::abort;
}
fail_check();
if (num_cards == 1)
{
// Only one card to draw, so just draw it.
mpr("There's only one card left!");
_evoke_deck(choice);
return spret::success;
}
const int num_to_draw = min(num_cards, 3);
you.props[deck_name(choice)] = deck_cards(choice) - num_to_draw;
auto& draw = you.props[NEMELEX_TRIPLE_DRAW_KEY].get_vector();
draw.clear();
for (int i = 0; i < num_to_draw; ++i)
draw.push_back(_random_card(choice));
run_uncancel(UNC_DRAW_THREE, 0);
return spret::success;
}
bool draw_three()
{
auto& draws = you.props[NEMELEX_TRIPLE_DRAW_KEY].get_vector();
int selected = -1;
bool need_prompt_redraw = true;
while (true)
{
if (need_prompt_redraw)
{
mpr("You draw... (choose one card, ? for their descriptions)");
for (int i = 0; i < draws.size(); ++i)
{
msg::streams(MSGCH_PROMPT)
<< msg::nocap << (static_cast<char>(i + 'a')) << " - "
<< card_name((card_type)draws[i].get_int()) << endl;
}
need_prompt_redraw = false;
}
const int keyin = toalower(get_ch());
if (crawl_state.seen_hups)
return false;
if (keyin == '?')
{
_describe_cards(draws);
redraw_screen();
update_screen();
need_prompt_redraw = true;
}
else if (keyin >= 'a' && keyin < 'a' + draws.size())
{
selected = keyin - 'a';
break;
}
else
canned_msg(MSG_HUH);
}
card_effect((card_type) draws[selected].get_int());
return true;
}
// This is Nemelex retribution. If deal is true, use the word "deal"
// rather than "draw" (for the Deal Four out-of-cards situation).
void draw_from_deck_of_punishment(bool deal)
{
card_type card = _random_card(DECK_OF_PUNISHMENT);
mprf("You %s a card...", deal ? "deal" : "draw");