-
Notifications
You must be signed in to change notification settings - Fork 41
/
boe.dlgutil.cpp
1571 lines (1445 loc) · 50.8 KB
/
boe.dlgutil.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
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
#include <cstring>
#include "boe.global.hpp"
#include "universe/universe.hpp"
#include "boe.dlgutil.hpp"
#include "boe.text.hpp"
#include "boe.town.hpp"
#include "boe.locutils.hpp"
#include "boe.party.hpp"
#include "boe.specials.hpp"
#include "boe.fileio.hpp"
#include "boe.graphics.hpp"
#include "boe.townspec.hpp"
#include "boe.main.hpp"
#include "boe.items.hpp"
#include "boe.consts.hpp"
#include "sounds.hpp"
#include <cstdio>
#include "boe.newgraph.hpp"
#include "boe.infodlg.hpp"
#include "utility.hpp"
#include "mathutil.hpp"
#include "dialogxml/dialogs/strdlog.hpp"
#include "dialogxml/dialogs/choicedlog.hpp"
#include "gfx/render_shapes.hpp"
#include "tools/winutil.hpp"
#include "fileio/fileio.hpp"
#include "fileio/resmgr/res_dialog.hpp"
#include "fileio/resmgr/res_strings.hpp"
#include "dialogxml/widgets/scrollbar.hpp"
#include "dialogxml/widgets/button.hpp"
#include "dialogxml/widgets/ledgroup.hpp"
#include "dialogxml/widgets/pict.hpp"
#include "dialogxml/widgets/stack.hpp"
#include <boost/lexical_cast.hpp>
#include "tools/prefs.hpp"
#include "scenario/shop.hpp"
#include "tools/cursors.hpp"
#include "tools/enum_map.hpp"
extern eItemWinMode stat_window;
extern eGameMode overall_mode;
extern bool changed_display_mode;
extern sf::RenderWindow mainPtr;
extern rectangle d_rects[80];
extern short d_rect_index[80];
extern eStatMode stat_screen_mode;
extern long register_flag;
extern long ed_flag,ed_key;
extern location center;
extern std::shared_ptr<cScrollbar> text_sbar,item_sbar,shop_sbar;
extern std::shared_ptr<cButton> done_btn, help_btn;
extern bool map_visible;
extern sf::RenderWindow mini_map;
extern cUniverse univ;
extern sf::Texture pc_gworld;
extern std::map<eSkill,short> skill_max;
short sign_mode,person_graphic,store_person_graphic,store_sign_mode;
long num_talk_entries;
char null_string[256] = "";
extern bool party_in_memory;
// Talking vars
eGameMode store_pre_talk_mode;
short store_personality,store_personality_graphic,shop_identify_cost;
std::string save_talk_str1, save_talk_str2;
sf::RenderTexture talk_gworld;
bool talk_end_forced;
rectangle talk_area_rect = {7,19,422,298}, word_place_rect = {44,7,372,257},talk_help_rect = {7,268,23,286};
std::string title_string;
mon_num_t store_monst_type;
short store_m_num;
rectangle dummy_rect = {0,0,0,0};
bool can_save_talk;
short store_talk_face_pic;
int current_talk_node;
extern std::vector<word_rect_t> talk_words;
// Shopping vars
// 1 - 499 ... regular items
// 500 alchemy
// 600-620 ... food not used!!!
// 700+ i - that healing
// 800 + - mage spells
// 900 + - priest spells
// n000 + i - magic store n item i
// talk_area_rect and talk_help_rect used for this too
eGameMode store_pre_shop_mode;
extern enum_map(eShopArea, rectangle) shopping_rects[8];
rectangle bottom_help_rects[4] = {{356,6,368,250},{374,6,386,270},{386,6,398,250},{398,6,410,250}};
rectangle shop_name_str = {44,6,56,200};
rectangle shop_frame = {62,10,352,269};
rectangle shop_done_rect = {388,212,411,275};
std::vector<int> shop_array;
cShop active_shop;
short active_shop_num;
void start_shop_mode(short which,short cost_adj,std::string store_name) {
rectangle area_rect;
if(which < 0 || which >= univ.scenario.shops.size()) {
showError("The scenario tried to place you in a nonexistent shop!");
return;
}
// This would be a place to hide the text box, if I add it.
active_shop_num = which;
active_shop = univ.scenario.shops[which];
active_shop.setCostAdjust(cost_adj);
active_shop.setName(store_name);
area_rect = talk_area_rect;
talk_gworld.create(area_rect.width(), area_rect.height());
store_pre_shop_mode = overall_mode;
overall_mode = MODE_SHOPPING;
stat_screen_mode = MODE_SHOP;
shop_sbar->setPosition(0);
// Check if the shop's stock has been reduced yet
if(univ.party.store_limited_stock.find(active_shop_num) != univ.party.store_limited_stock.end()) {
for(auto p : univ.party.store_limited_stock[active_shop_num]) {
int which_item, quant_left;
std::tie(which_item, quant_left) = p;
if(which_item < 0 || which_item >= active_shop.size()) continue;
cShopItem entry = active_shop.getItem(which_item);
if(entry.quantity == 0) continue; // Just in case a stray entry accidentally gets put in for an infinite stock item (or an item was changed from finite to infinite)
if(quant_left == 0)
entry.type = eShopItemType::EMPTY;
else if(entry.type == eShopItemType::OPT_ITEM)
entry.quantity = quant_left + (entry.quantity / 1000) * 1000;
else entry.quantity = quant_left;
active_shop.replaceItem(which_item, entry);
}
}
set_up_shop_array();
put_background();
draw_shop_graphics(0,area_rect);
put_item_screen(stat_window);
give_help(26,27);
}
static void update_last_talk(int new_node) {
// Store last node in the Go Back button
for(word_rect_t& word : talk_words) {
if(word.word != "Go Back") continue;
word.node = current_talk_node;
current_talk_node = new_node;
break;
}
}
void end_shop_mode() {
rectangle dummy_rect = {0,0,0,0};
// This would be a place to show the text box, if I add it (and if this is not an outdoor shop).
shop_sbar->hide();
done_btn->hide();
help_btn->hide();
if(store_pre_shop_mode == MODE_TALKING) {
place_talk_str("You conclude your business.", "", 0, dummy_rect);
update_last_talk(TALK_BUSINESS);
}
overall_mode = store_pre_shop_mode;
if(overall_mode == MODE_TALK_TOWN)
overall_mode = MODE_TOWN;
if(overall_mode == MODE_TOWN) {
center = univ.party.town_loc;
update_explored(center);
}
stat_screen_mode = MODE_INVEN;
put_item_screen(stat_window);
put_pc_screen();
// TODO: I suspect REFRESH_NONE will suffice here
redraw_screen(REFRESH_TERRAIN | REFRESH_BAR);
// If it was a random shop, we need to update the stored list of items so that bought items don't reappear
if(active_shop.getType() == eShopType::RANDOM) {
auto& this_shop = univ.party.magic_store_items[active_shop_num];
this_shop.clear();
for(int i = 0; i < active_shop.size(); i++) {
cShopItem item = active_shop.getItem(i);
if(item.type == eShopItemType::TREASURE || item.type == eShopItemType::CLASS || item.type == eShopItemType::OPT_ITEM)
this_shop[i] = item.item;
}
}
// We also need to save any limited stock
for(int i = 0; i < active_shop.size(); i++) {
cShopItem item = active_shop.getItem(i);
if(item.quantity > 0) {
// This means the stock is limited.
int left = item.type == eShopItemType::EMPTY ? 0 : item.quantity;
univ.party.store_limited_stock[active_shop_num][i] = left;
}
}
}
void handle_shop_event(location p) {
if(p.in(talk_help_rect)) {
if(!help_btn->handleClick(p))
return;
give_help(226,27);
return;
}
if(p.in(shop_done_rect)) {
if(done_btn->handleClick(p))
end_shop_mode();
return;
}
for(short i = 0; i < 8; i++) {
auto shop_i = i + shop_sbar->getPosition();
if(shop_i >= shop_array.size()) break;
unsigned long what_picked = shop_array[shop_i];
if(what_picked >= active_shop.size()) break;
if(active_shop.getItem(what_picked).type == eShopItemType::EMPTY)
break;
// Since shop UI was drawn into the game window with offsets, we need to apply
// the same offsets to event catching areas.
rectangle active_rect { shopping_rects[i][SHOPRECT_ACTIVE_AREA] };
active_rect.offset(talk_gword_offset_x, talk_gword_offset_y);
rectangle item_help_rect { shopping_rects[i][SHOPRECT_ITEM_HELP] };
item_help_rect.offset(talk_gword_offset_x, talk_gword_offset_y);
if(p.in(active_rect)) {
click_shop_rect(active_rect);
handle_sale(active_shop.getItem(what_picked), what_picked);
set_up_shop_array();
draw_shop_graphics(false, {});
} else if(p.in(item_help_rect)){
click_shop_rect(item_help_rect);
handle_info_request(active_shop.getItem(what_picked));
}
}
}
void handle_sale(cShopItem item, int i) {
cItem base_item = item.item;
short cost = item.getCost(active_shop.getCostAdjust());
rectangle dummy_rect = {0,0,0,0};
switch(item.type) {
case eShopItemType::EMPTY: break; // Invalid
case eShopItemType::TREASURE: break; // Also invalid
case eShopItemType::CLASS: break; // Also invalid
case eShopItemType::OPT_ITEM: break; // Also invalid
case eShopItemType::ITEM:
switch(univ.current_pc().ok_to_buy(cost,base_item)) {
case eBuyStatus::OK:
play_sound(-38);
take_gold(cost,true);
univ.current_pc().give_item(base_item,true);
// Magic shops have limited stock
active_shop.takeOne(i);
break;
case eBuyStatus::NO_SPACE: ASB("Can't carry any more items."); break;
case eBuyStatus::NEED_GOLD: ASB("Not enough cash."); break;
case eBuyStatus::TOO_HEAVY: ASB("Item is too heavy."); break;
case eBuyStatus::HAVE_LOTS:
if(base_item.variety == eItemType::SPECIAL) ASB("You already own this.");
else if(base_item.variety == eItemType::QUEST) ASB("You already completed this.");
else ASB("You own too many of this.");
break;
}
break;
case eShopItemType::ALCHEMY:
if(univ.party.alchemy[base_item.item_level])
ASB("You already know that recipe.");
else if(!take_gold(cost,false))
ASB("Not enough gold.");
else {
// TODO: This seems like the wrong sound
play_sound(62);
ASB("You buy an alchemical recipe.");
univ.party.alchemy[base_item.item_level] = true;
}
break;
case eShopItemType::HEAL_WOUNDS: case eShopItemType::REMOVE_CURSE: case eShopItemType::CURE_DUMBFOUNDING:
case eShopItemType::CURE_POISON: case eShopItemType::CURE_DISEASE: case eShopItemType::CURE_PARALYSIS:
case eShopItemType::DESTONE: case eShopItemType::RAISE_DEAD: case eShopItemType::RESURRECT:
case eShopItemType::CURE_ACID:
if(!take_gold(cost,false))
ASB("Not enough gold.");
else {
ASB("You pay the healer.");
play_sound(68);
switch(item.type) {
case eShopItemType::HEAL_WOUNDS:
univ.current_pc().cur_health = univ.current_pc().max_health;
break;
case eShopItemType::CURE_POISON:
univ.current_pc().status[eStatus::POISON] = 0;
break;
case eShopItemType::CURE_DISEASE:
univ.current_pc().status[eStatus::DISEASE] = 0;
break;
case eShopItemType::CURE_ACID:
univ.current_pc().status[eStatus::ACID] = 0;
break;
case eShopItemType::CURE_PARALYSIS:
univ.current_pc().status[eStatus::PARALYZED] = 0;
break;
case eShopItemType::REMOVE_CURSE:
for(int i = 0; i < univ.current_pc().items.size(); i++)
if((univ.current_pc().equip[i]) &&
(univ.current_pc().items[i].cursed))
univ.current_pc().items[i].cursed = univ.current_pc().items[i].unsellable = false;
break;
case eShopItemType::DESTONE: case eShopItemType::RAISE_DEAD: case eShopItemType::RESURRECT:
univ.current_pc().main_status = eMainStatus::ALIVE;
break;
case eShopItemType::CURE_DUMBFOUNDING:
// TODO: Don't cure anti-dumbfounding!
univ.current_pc().status[eStatus::DUMB] = 0;
break;
default: break; // Silence compiler warning
}
}
break;
case eShopItemType::MAGE_SPELL:
if((base_item.item_level < 0) || (base_item.item_level > 61)) {
beep();
showError("The scenario tried to sell you an invalid mage spell!");
break;
}
if(univ.current_pc().mage_spells[base_item.item_level])
ASB("You already have this spell.");
else if(!take_gold(cost,false))
ASB("Not enough gold.");
else {
// TODO: This seems like the wrong sound
play_sound(62);
ASB("You buy a spell.");
univ.current_pc().mage_spells[base_item.item_level] = true;
give_help(41,0);
}
break;
case eShopItemType::PRIEST_SPELL:
if((base_item.item_level < 0) || (base_item.item_level > 61)) {
beep();
showError("The scenario tried to sell you an invalid priest spell!");
break;
}
if(univ.current_pc().priest_spells[base_item.item_level])
ASB("You already have this spell.");
else if(!take_gold(cost,false))
ASB("Not enough gold.");
else {
// TODO: This seems like the wrong sound
play_sound(62);
ASB("You buy a spell.");
univ.current_pc().priest_spells[base_item.item_level] = true;
give_help(41,0);
}
break;
case eShopItemType::CALL_SPECIAL:
if(univ.party.gold < cost)
ASB("Not enough gold.");
else {
short s1;
run_special(eSpecCtx::SHOPPING, eSpecCtxType::SCEN, base_item.item_level, {0,0}, &s1);
if(s1 <= 0) {
take_gold(cost,false);
active_shop.takeOne(i);
}
}
break;
case eShopItemType::SKILL:
if(base_item.item_level < 0 || base_item.item_level > 18) {
beep();
showError("The scenario tried to sell you an invalid skill!");
break;
}
eSkill skill = eSkill(base_item.item_level);
if(univ.current_pc().skills[skill] >= skill_max[skill])
ASB("You're already an expert in this skill.");
else if(!take_gold(cost, false))
ASB("Not enough gold.");
else {
// TODO: No idea what's a good sound here.
play_sound(62);
ASB("You learn a little...");
active_shop.takeOne(i);
univ.current_pc().skills[skill]++;
}
break;
}
if(overall_mode != MODE_SHOPPING) {
beep();
ASB("Shop error 1. Report This!");
}
// Maybe that was the last of that item, so re-init the shop array just in case.
set_up_shop_array();
draw_shop_graphics(0,dummy_rect);
print_buf();
put_pc_screen();
put_item_screen(stat_window);
}
void handle_info_request(cShopItem item) {
cItem base_item = item.item;
switch(item.type) {
case eShopItemType::EMPTY: break;
case eShopItemType::TREASURE: break;
case eShopItemType::CLASS: break;
case eShopItemType::OPT_ITEM: break;
case eShopItemType::ITEM:
display_pc_item(6,0, base_item,0);
break;
case eShopItemType::ALCHEMY:
// TODO: Create a dedicated dialog for alchemy info
display_alchemy();
break;
case eShopItemType::MAGE_SPELL:
display_spells(eSkill::MAGE_SPELLS,base_item.item_level,0);
break;
case eShopItemType::PRIEST_SPELL:
display_spells(eSkill::PRIEST_SPELLS,base_item.item_level,0);
break;
case eShopItemType::SKILL:
display_skills(eSkill(base_item.item_level), nullptr);
break;
case eShopItemType::HEAL_WOUNDS:
cStrDlog("Select this option to restore the current PC to full health.", "", "Heal Wounds", 15, PIC_DLOG).show();
break;
case eShopItemType::REMOVE_CURSE:
cStrDlog("Select this option to remove any curses on any items the PC is wearing.", "", "Remove Curse", 15, PIC_DLOG).show();
break;
case eShopItemType::CURE_DUMBFOUNDING:
cStrDlog("Select this option to restore the PC's mind from dumbfounding.", "", "Cure Dumbfounding", 15, PIC_DLOG).show();
break;
case eShopItemType::CURE_POISON:
cStrDlog("Select this option purge all poison from the current PC.", "", "Cure Poison", 15, PIC_DLOG).show();
break;
case eShopItemType::CURE_DISEASE:
cStrDlog("Select this option purge all disease from the current PC.", "", "Cure Disease", 15, PIC_DLOG).show();
break;
case eShopItemType::CURE_ACID:
cStrDlog("Select this option purge all acid from the current PC.", "", "Cure Acid", 15, PIC_DLOG).show();
break;
case eShopItemType::CURE_PARALYSIS:
cStrDlog("Select this option to cure the current PC's paralysis.", "", "Cure Paralysis", 15, PIC_DLOG).show();
break;
case eShopItemType::DESTONE:
cStrDlog("Select this option to restore a PC that has been turned to stone.", "", "Destone", 15, PIC_DLOG).show();
break;
case eShopItemType::RAISE_DEAD:
cStrDlog("Select this option to resurrect a PC.", "", "Raise Dead", 15, PIC_DLOG).show();
break;
case eShopItemType::RESURRECT:
cStrDlog("Select this option to resurrect a PC that has been turned to dust.", "", "Resurrect", 15, PIC_DLOG).show();
break;
case eShopItemType::CALL_SPECIAL:
cStrDlog(base_item.desc, "", base_item.full_name, base_item.graphic_num, PIC_ITEM).show();
break;
}
}
void set_up_shop_array() {
shop_array.clear();
for(int j = 0; j < active_shop.size(); j++) {
cShopItem entry = active_shop.getItem(j);
switch(entry.type) {
case eShopItemType::ITEM:
case eShopItemType::MAGE_SPELL:
case eShopItemType::PRIEST_SPELL:
case eShopItemType::ALCHEMY:
case eShopItemType::SKILL:
shop_array.push_back(j);
break;
case eShopItemType::HEAL_WOUNDS:
if(univ.current_pc().cur_health < univ.current_pc().max_health)
shop_array.push_back(j);
break;
case eShopItemType::CURE_POISON:
if(univ.current_pc().status[eStatus::POISON] > 0)
shop_array.push_back(j);
break;
case eShopItemType::CURE_DISEASE:
if(univ.current_pc().status[eStatus::DISEASE] > 0)
shop_array.push_back(j);
break;
case eShopItemType::CURE_ACID:
if(univ.current_pc().status[eStatus::ACID] > 0)
shop_array.push_back(j);
break;
case eShopItemType::CURE_PARALYSIS:
if(univ.current_pc().status[eStatus::PARALYZED] > 0)
shop_array.push_back(j);
break;
case eShopItemType::CURE_DUMBFOUNDING:
if(univ.current_pc().status[eStatus::DUMB] > 0)
shop_array.push_back(j);
break;
case eShopItemType::DESTONE:
if(univ.current_pc().main_status == eMainStatus::STONE)
shop_array.push_back(j);
break;
case eShopItemType::RAISE_DEAD:
if(univ.current_pc().main_status == eMainStatus::DEAD)
shop_array.push_back(j);
break;
case eShopItemType::RESURRECT:
if(univ.current_pc().main_status == eMainStatus::DUST)
shop_array.push_back(j);
break;
case eShopItemType::REMOVE_CURSE:
for(int i = 0; i < univ.current_pc().items.size(); i++) {
if((univ.current_pc().equip[i]) && (univ.current_pc().items[i].cursed)) {
shop_array.push_back(j);
break;
}
}
break;
case eShopItemType::CALL_SPECIAL:
if(PSD[entry.item.abil_strength][entry.item.abil_data.value])
shop_array.push_back(j);
break;
case eShopItemType::OPT_ITEM:
entry.quantity %= 1000;
BOOST_FALLTHROUGH;
case eShopItemType::TREASURE:
case eShopItemType::CLASS:
entry.type = eShopItemType::ITEM;
entry.item = univ.party.magic_store_items[active_shop_num][j];
if(entry.item.variety == eItemType::NO_ITEM)
entry.type = eShopItemType::EMPTY;
else shop_array.push_back(j);
entry.quantity = 1;
active_shop.replaceItem(j, entry);
break;
case eShopItemType::EMPTY:
break;
}
}
if(shop_array.size() < 8) {
shop_sbar->setMaximum(0);
} else {
shop_sbar->setMaximum(shop_array.size() - 8);
}
}
void start_talk_mode(short m_num,short personality,mon_num_t monst_type,short store_face_pic) {
rectangle area_rect;
store_personality = personality;
store_monst_type = monst_type;
store_m_num = m_num;
store_talk_face_pic = store_face_pic; ////
area_rect = talk_area_rect;
talk_gworld.create(area_rect.width(), area_rect.height());
help_btn->show();
// This would be the place to show the text box, if I add it.
// Set the current town for talk strings
univ.town.prep_talk(personality / 10);
// Dredge up critter's name
title_string = std::string(univ.town.cur_talk().people[personality % 10].title) + ":";
store_pre_talk_mode = overall_mode;
overall_mode = MODE_TALKING;
talk_end_forced = false;
// first initialise talk_words here
talk_words.clear();
static const rectangle preset_rects[9] = {
rectangle{366,4,386,54}, rectangle{366,70,386,130}, rectangle{366,136,386,186},
rectangle{389,4,409,54}, rectangle{389,70,409,120}, rectangle{389,121,409,186},
rectangle{389,210,409,270}, rectangle{366,190,386,270},
rectangle{343,4,363,134},
};
static const char*const preset_words[9] = {
"Look", "Name", "Job",
"Buy", "Sell", "Record",
"Done", "Go Back",
"Ask About...",
};
// Place buttons at bottom.
for(short i = 0; i < 9; i++) {
word_rect_t preset_word(preset_words[i], preset_rects[i]);
preset_word.on = Colours::DARK_GREEN;
preset_word.off = Colours::LIGHT_GREEN;
switch(i) {
case 0: preset_word.node = TALK_LOOK; break;
case 1: preset_word.node = TALK_NAME; break;
case 2: preset_word.node = TALK_JOB; break;
case 3: preset_word.node = TALK_BUY; break;
case 4: preset_word.node = TALK_SELL; break;
case 5: preset_word.node = TALK_RECORD; break;
case 6: preset_word.node = TALK_DONE; break;
case 7: preset_word.node = TALK_BACK; break;
case 8: preset_word.node = TALK_ASK; break;
}
talk_words.push_back(preset_word);
}
stat_screen_mode = MODE_SHOP;
current_talk_node = TALK_LOOK;
// Bring up and place first strings.
save_talk_str1 = univ.town.cur_talk().people[personality % 10].look;
save_talk_str2 = "";
can_save_talk = true;
place_talk_str(save_talk_str1, "", 0, dummy_rect);
put_item_screen(stat_window);
give_help(5,6);
}
void end_talk_mode() {
// This would be where to hide the text box, if I add it.
overall_mode = store_pre_talk_mode;
if(overall_mode == MODE_TALK_TOWN)
overall_mode = MODE_TOWN;
if(overall_mode == MODE_TOWN) {
center = univ.party.town_loc;
update_explored(center);
}
help_btn->hide();
stat_screen_mode = MODE_INVEN;
put_item_screen(stat_window);
put_pc_screen();
// TODO: I suspect REFRESH_NONE will suffice here
redraw_screen(REFRESH_TERRAIN | REFRESH_BAR);
}
static void fill_job_bank(cDialog& me, job_bank_t& bank, std::string) {
// TODO: Maybe customize the icon?
// TODO: Allow custom title?
me["day"].setTextToNum(univ.party.calc_day());
for(int i = 0; i < 4; i++) {
std::string id = std::to_string(i + 1);
if(bank.jobs[i] >= 0 && bank.jobs[i] < univ.scenario.quests.size()) {
cQuest& quest = univ.scenario.quests[bank.jobs[i]];
std::string description = quest.descr;
if(quest.deadline > 0) {
if(quest.deadline_is_relative)
description += " Must be completed in " + std::to_string(quest.deadline) + " days.";
else description += " Must be completed by day " + std::to_string(quest.deadline) + ".";
}
description += " Pay is " + std::to_string(quest.gold) + " gold.";
me["take" + id].show();
me["job" + id].setText(description);
} else {
me["take" + id].hide();
me["job" + id].setText("");
}
}
}
static void show_job_bank(int which_bank, std::string title) {
cDialog job_dlg(*ResMgr::dialogs.get("job-bank"));
job_dlg.attachClickHandlers([&](cDialog& me, std::string hit, eKeyMod) -> bool {
int which = hit[4] - '1';
me["prompt"].setText("Job accepted.");
job_bank_t& bank = univ.party.job_banks[which_bank];
univ.party.active_quests[bank.jobs[which]] = cJob(univ.party.calc_day(), store_personality);
// Now, if there are spare jobs available, fill in. Otherwise, clear space.
if(bank.jobs[4] >= 0)
std::swap(bank.jobs[which], bank.jobs[4]);
else if(bank.jobs[5] >= 0)
std::swap(bank.jobs[which], bank.jobs[5]);
fill_job_bank(me, bank, title);
return true;
}, {"take1", "take2", "take3", "take4"});
job_dlg["done"].attachClickHandler(std::bind(&cDialog::toast, &job_dlg, false));
if(which_bank >= univ.party.job_banks.size())
univ.party.job_banks.resize(which_bank + 1);
if(!univ.party.job_banks[which_bank].inited)
univ.generate_job_bank(which_bank, univ.party.job_banks[which_bank]);
fill_job_bank(job_dlg, univ.party.job_banks[which_bank], title);
int anger = univ.party.job_banks[which_bank].anger;
if(anger >= 0 && anger < 10) {
job_dlg["prompt"].setText("Dispatcher is neutral towards you.");
} else if(anger >= 10 && anger < 20) {
job_dlg["prompt"].setText("Dispatcher is a little annoyed at you.");
} else if(anger >= 20 && anger < 35) {
job_dlg["prompt"].setText("Dispatcher is annoyed at you.");
} else job_dlg["prompt"].setText("Dispatcher is rather angry at you.");
job_dlg.run();
}
void handle_talk_event(location p) {
short get_pc,s1 = -1,s2 = -1;
char asked[4];
short a,b,c,d;
eTalkNode ttype;
if(p.in(talk_help_rect)) {
if(!help_btn->handleClick(p))
return;
give_help(205,6);
return;
}
p.x -= 5;
p.y -= 5;
int which_talk_entry = TALK_DUNNO;
for(word_rect_t& word : talk_words) {
if(word.node == -1) continue;
rectangle wordRect(word.rect);
wordRect.offset(talk_area_rect.topLeft());
wordRect.offset(-1, -10); // TODO: This corrects for the byzantine offsets that win_draw_string applies for some reason...
if(!p.in(wordRect)) continue;
click_talk_rect(word);
which_talk_entry = word.node;
break;
}
if(which_talk_entry == TALK_DUNNO)
return;
switch(which_talk_entry) {
case TALK_DUNNO:
SPECIAL_DUNNO:
save_talk_str1 = univ.town.cur_talk().people[store_personality % 10].dunno;
if(save_talk_str1.length() < 2) save_talk_str1 = "You get no response.";
place_talk_str(save_talk_str1, "", 0, dummy_rect);
update_last_talk(TALK_DUNNO);
return;
case TALK_BUSINESS: // This one only reachable via "go back".
place_talk_str("You conclude your business.", "", 0, dummy_rect);
update_last_talk(TALK_BUSINESS);
return;
case TALK_LOOK:
SPECIAL_LOOK:
save_talk_str1 = univ.town.cur_talk().people[store_personality % 10].look;
place_talk_str(save_talk_str1, "", 0, dummy_rect);
update_last_talk(TALK_LOOK);
return;
case TALK_NAME:
SPECIAL_NAME:
save_talk_str1 = univ.town.cur_talk().people[store_personality % 10].name;
place_talk_str(save_talk_str1, "", 0, dummy_rect);
update_last_talk(TALK_NAME);
return;
case TALK_JOB:
SPECIAL_JOB:
save_talk_str1 = univ.town.cur_talk().people[store_personality % 10].job;
place_talk_str(save_talk_str1, "", 0, dummy_rect);
update_last_talk(TALK_JOB);
return;
case TALK_BUY:
SPECIAL_BUY:
which_talk_entry = scan_for_response("purc");
if(which_talk_entry < 0) which_talk_entry = scan_for_response("sale");
if(which_talk_entry < 0) which_talk_entry = scan_for_response("heal");
if(which_talk_entry < 0) which_talk_entry = scan_for_response("iden");
if(which_talk_entry < 0) which_talk_entry = scan_for_response("trai");
if(which_talk_entry < 0) which_talk_entry = scan_for_response("ench");
if(which_talk_entry == -1) goto SPECIAL_DUNNO;
break;
case TALK_SELL:
SPECIAL_SELL:
which_talk_entry = scan_for_response("sell");
if(which_talk_entry == -1) goto SPECIAL_DUNNO;
break;
case TALK_RECORD:
if(!can_save_talk) {
beep();
return;
}
if(univ.party.save_talk(univ.town->talking.people[store_personality%10].title, univ.town->name, save_talk_str1, save_talk_str2)) {
give_help(57,0);
play_sound(0);
ASB("Noted in journal.");
} else ASB("This is already saved.");
print_buf();
return;
case TALK_DONE:
SPECIAL_DONE:
end_talk_mode();
return;
case TALK_BACK: // only if there's nothing to go back to
return; // so, there's nothing to do here
case TALK_ASK: // ask about
save_talk_str1 = get_text_response("Ask about what?", 8);
strncpy(asked, save_talk_str1.c_str(), 4);
if(strnicmp(asked, "name", 4) == 0) goto SPECIAL_NAME;
if(strnicmp(asked, "look", 4) == 0) goto SPECIAL_LOOK;
if(strnicmp(asked, "job", 3) == 0) goto SPECIAL_JOB;
if(strnicmp(asked, "work", 4) == 0) goto SPECIAL_JOB;
if(strnicmp(asked, "bye", 3) == 0) goto SPECIAL_DONE;
if(strnicmp(asked, "buy", 3) == 0) goto SPECIAL_BUY;
if(strnicmp(asked, "sell", 4) == 0) goto SPECIAL_SELL;
which_talk_entry = scan_for_response(asked);
if(which_talk_entry == -1) goto SPECIAL_DUNNO;
break;
}
update_last_talk(which_talk_entry);
ttype = univ.town.cur_talk().talk_nodes[which_talk_entry].type;
a = univ.town.cur_talk().talk_nodes[which_talk_entry].extras[0];
b = univ.town.cur_talk().talk_nodes[which_talk_entry].extras[1];
c = univ.town.cur_talk().talk_nodes[which_talk_entry].extras[2];
d = univ.town.cur_talk().talk_nodes[which_talk_entry].extras[3];
save_talk_str1 = univ.town.cur_talk().talk_nodes[which_talk_entry].str1;
save_talk_str2 = univ.town.cur_talk().talk_nodes[which_talk_entry].str2;
can_save_talk = true;
switch(ttype) {
case eTalkNode::REGULAR:
break;
case eTalkNode::DEP_ON_SDF:
if(PSD[a][b] > c) {
save_talk_str1 = save_talk_str2;
}
save_talk_str2 = "";
break;
case eTalkNode::SET_SDF:
PSD[a][b] = c;
break;
case eTalkNode::INN:
if(univ.party.gold < a) {
save_talk_str1 = save_talk_str2;
}
else {
talk_end_forced = true;
univ.party.gold -= a;
put_pc_screen();
do_rest(700, 30 * b, 25 * b);
univ.party.town_loc.x = c;
univ.party.town_loc.y = d;
center = univ.party.town_loc;
}
save_talk_str2 = "";
break;
case eTalkNode::DEP_ON_TIME:
if(day_reached((unsigned char) a,0)) {
save_talk_str1 = save_talk_str2;
}
save_talk_str2 = "";
break;
case eTalkNode::DEP_ON_TIME_AND_EVENT:
if(day_reached((unsigned char) a,(unsigned char) b)) {
save_talk_str1 = save_talk_str2;
}
save_talk_str2 = "";
break;
case eTalkNode::DEP_ON_TOWN:
if(univ.party.town_num != a) {
save_talk_str1 = save_talk_str2;
}
save_talk_str2 = "";
break;
case eTalkNode::TRAINING:
if((get_pc = char_select_pc(0,"Train who?")) < 6) {
can_save_talk = false;
spend_xp(get_pc,1, nullptr);
}
save_talk_str1 = "You conclude your training.";
return;
case eTalkNode::SHOP:
if(d < 0 || d > 11) {
showError("Invalid shop type!");
return;
}
start_shop_mode(b,a,save_talk_str1);
can_save_talk = false;
return;
case eTalkNode::JOB_BANK:
if(a < univ.party.job_banks.size() && univ.party.job_banks[a].anger >= 50) {
save_talk_str1 = save_talk_str2;
save_talk_str2 = "";
break;
} else {
show_job_bank(a, save_talk_str1.c_str());
return;
}
case eTalkNode::SELL_WEAPONS:
can_save_talk = false;
stat_screen_mode = MODE_SELL_WEAP;
put_item_screen(stat_window);
give_help(42,43);
break;
case eTalkNode::SELL_ARMOR:
can_save_talk = false;
stat_screen_mode = MODE_SELL_ARMOR;
put_item_screen(stat_window);
give_help(42,43);
break;
case eTalkNode::SELL_ITEMS:
can_save_talk = false;
stat_screen_mode = MODE_SELL_ANY;
put_item_screen(stat_window);
give_help(42,43);
break;
case eTalkNode::IDENTIFY: case eTalkNode::ENCHANT:
can_save_talk = false;
stat_screen_mode = (ttype == eTalkNode::IDENTIFY) ? MODE_IDENTIFY : MODE_ENCHANT;
shop_identify_cost = a;
put_item_screen(stat_window);
give_help(ttype == eTalkNode::IDENTIFY ? 44 : 45,0);
break;
case eTalkNode::BUY_INFO:
if(univ.party.gold < a) {
save_talk_str1 = save_talk_str2;
}
else {
univ.party.gold -= a;
put_pc_screen();
}
save_talk_str2 = "";
break;
case eTalkNode::BUY_SDF:
if((univ.party.sd_legit(b,c)) && (PSD[b][c] == d)) {
save_talk_str1 = "You've already learned that.";
can_save_talk = false;
}
else if(univ.party.gold < a) {
save_talk_str1 + save_talk_str2;
}
else {
univ.party.gold -= a;
put_pc_screen();
if(univ.party.sd_legit(b,c))
PSD[b][c] = d;
else showError("Invalid Stuff Done flag called in conversation.");
}
save_talk_str2 = "";
break;
case eTalkNode::BUY_SHIP:
if(univ.party.gold < a) {
save_talk_str1 = save_talk_str2;
save_talk_str2 = "";
break;
} else {
using namespace std::placeholders;
auto& boats = univ.party.boats;
b = minmax(0, boats.size() - 1, b);
c = minmax(0, boats.size() - b, c);
auto iter = std::find_if(boats.begin() + b, boats.begin() + b + c, std::bind(&cVehicle::property, _1));
if(iter != boats.end()) {
univ.party.gold -= a;
put_pc_screen();
iter->property = false;
save_talk_str2 = "";
} else {
save_talk_str1 = "There are no boats left.";
save_talk_str2 = "";
can_save_talk = false;
}
}
break;
case eTalkNode::BUY_HORSE:
if(univ.party.gold < a) {
save_talk_str1 = save_talk_str2;
save_talk_str2 = "";
break;
} else {
using namespace std::placeholders;
auto& horses = univ.party.horses;
b = minmax(0, horses.size() - 1, b);
c = minmax(0, horses.size() - b, c);
auto iter = std::find_if(horses.begin() + b, horses.begin() + b + c, std::bind(&cVehicle::property, _1));
if(iter != horses.end()) {
univ.party.gold -= a;
put_pc_screen();
iter->property = false;
save_talk_str2 = "";
} else {
save_talk_str1 = "There are no horses left.";
save_talk_str2 = "";
can_save_talk = false;
}
}
break;
case eTalkNode::BUY_SPEC_ITEM:
if(univ.party.spec_items.count(a)) {