-
Notifications
You must be signed in to change notification settings - Fork 0
/
DarkTower.cpp
2240 lines (1919 loc) · 71.3 KB
/
DarkTower.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
/*
* Dark Tower
* Copyright (C) 2018 Marcus Hutchings
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <SPI.h>
#include <Gamebuino.h>
#define EVENT_MEMORY 2
#define DESCRIPTION_SIZE 250
#define MAX_OBJECTS_PER_EVENT 10
#define MAX_OBJECTS_ON_PLAYER MAX_OBJECTS_PER_EVENT
#define OBJECT_MENU_LENGTH (MAX_OBJECTS_ON_PLAYER)
#define OBJECT_MENU_ITEM_LENGTH 13
typedef unsigned char action_id;
#define ACTION_ID_NONE 0
#define ACTION_ID_LOOK 0
#define ACTION_ID_TAKE 1
#define ACTION_ID_USE 2
#define ACTION_ID_ITEM 3
#define ACTION_ID_CONTINUE 0xff
typedef unsigned char event_tag_id;
#define EVENT_TAG_ID_CRYPT_MONSTER_DEAD (1 << 0)
#define EVENT_TAG_ID_SECRET_PASSAGE_OPENED (1 << 1)
#define EVENT_TAG_ID_RELEASED_SWORD (1 << 2)
#define EVENT_TAG_ID_UNCOVERED_KEY_MACHINE (1 << 3)
#define EVENT_TAG_ID_ROPE_TIED_AROUND_WELL (1 << 4)
#define EVENT_TAG_ID_MASTER_ROOM_DOOR_OPENED (1 << 6)
#define EVENT_TAG_ID_ALL (0xff)
typedef unsigned char game_state_id;
#define GAME_STATE_ID_TITLE 0
#define GAME_STATE_ID_INIT 1
#define GAME_STATE_ID_PLAY 2
#define GAME_STATE_ID_FINISH_PLAY 3
#define GAME_STATE_ID_PLAYER_DIED 4
typedef unsigned char game_presenter_state_id;
#define GAME_PRESENTER_STATE_ID_AWAIT_ACTION 1
#define GAME_PRESENTER_STATE_ID_AWAIT_OBJECT 2
Gamebuino gb;
extern const byte font5x7[];
extern const byte font3x5[];
#define CALL_REF(the_class, the_function) (the_class.*the_class.the_function)
typedef void (*basic_function)();
typedef void (*load_string_function)(char *string_to_init);
typedef unsigned int player_item_id;
#define PLAYER_ITEM_ID_MASTER_KEY (1 << 0)
#define PLAYER_ITEM_ID_OIL_LAMP (1 << 1)
#define PLAYER_ITEM_ID_SWORD (1 << 2)
#define PLAYER_ITEM_ID_BROKEN_KEY (1 << 3)
#define PLAYER_ITEM_ID_BLANK_KEY (1 << 4)
#define PLAYER_ITEM_ID_MOD_CHEST_KEY (1 << 5)
#define PLAYER_ITEM_ID_SHEET (1 << 6)
#define PLAYER_ITEM_ID_COPIED_KEY (1 << 7)
#define PLAYER_ITEM_ID_CHEST_KEY (1 << 8)
#define PLAYER_ITEM_ID_ROPE (1 << 9)
#define PLAYER_ITEM_ID_ALL (0xffff)
const char player_item_name_master_key[] PROGMEM = "Crystal";
const char player_item_name_lamp[] PROGMEM = "Lamp";
const char player_item_name_broad_sword[] PROGMEM = "Silver Sword";
const char player_item_name_broken_key[] PROGMEM = "Broken Key";
const char player_item_name_blank_key[] PROGMEM = "Blank Key";
const char player_item_name_modified_chest_key[] PROGMEM = "Modified Key";
const char player_item_name_sheet[] PROGMEM = "Curtain";
const char player_item_name_copied_key[] PROGMEM = "Copied Key";
const char player_item_name_chest_key[] PROGMEM = "Copper Key";
const char player_item_name_rope[] PROGMEM = "Rope";
const char* const player_item_name_full_list[] PROGMEM =
{ player_item_name_master_key
, player_item_name_lamp
, player_item_name_broad_sword
, player_item_name_broken_key
, player_item_name_blank_key
, player_item_name_modified_chest_key
, player_item_name_sheet
, player_item_name_copied_key
, player_item_name_chest_key
, player_item_name_rope
};
class player_type
{
public:
player_type()
: items_carried( 0 )
, achievements( 0 )
{ }
void add_achievement(event_tag_id new_achievement){
achievements |= new_achievement;
}
void remove_achievement(event_tag_id lost_achievement){
achievements &= ~lost_achievement;
}
boolean has_achievement(event_tag_id check_achievement){
return (achievements & check_achievement);
}
void add_item(player_item_id item){
items_carried |= item;
}
void remove_item(player_item_id item){
items_carried &= ~item;
}
boolean has_item(player_item_id item){
return (items_carried & item) == item;
}
player_item_id get_item_by_index(uint8_t item_index){
player_item_id result = 0;
uint8_t count = 0;
for (player_item_id id = 1; id < PLAYER_ITEM_ID_ALL; id <<= 1){
if (has_item(id)){
if (count == item_index){
result = id;
break;
}
count++;
}
}
return result;
}
uint8_t load_item_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
const char* available_item_list[MAX_OBJECTS_ON_PLAYER];
char *cur_buf_pos = menu_buffer;
uint8_t count = 0;
for (uint8_t i = 0; i < MAX_OBJECTS_ON_PLAYER; i++){
if ( has_item( 1 << ((uint16_t)i) ) ){
count++;
if (count > menu_length)
break;
strncpy_P(cur_buf_pos, (char*)pgm_read_word(&(player_item_name_full_list[i])), menu_item_length);
cur_buf_pos[menu_item_length-1] = '\0';
cur_buf_pos += menu_item_length;
}
}
return count;
}
private:
player_item_id items_carried;
event_tag_id achievements;
} player;
void load_progmem_string_to_var (const char* progmem_string, char *output_string, uint8_t limit) {
strncpy_P(output_string, progmem_string, limit);
output_string[limit-1] = '\0';
}
void copy_string_array_from_src_to_buf(const char** src, uint8_t array_length, char* buf, uint8_t buf_size, uint8_t str_len){
char *cur_buf_pos = buf;
char *end_of_buf = buf + buf_size*str_len;
uint8_t cur_str_len = str_len;
for (uint8_t i=0; i<array_length; i++){
if (cur_buf_pos + strlen_P(src[i]) >= end_of_buf)
cur_str_len = end_of_buf - cur_buf_pos;
load_progmem_string_to_var(src[i], cur_buf_pos, cur_str_len);
cur_buf_pos += str_len;
if (cur_buf_pos >= end_of_buf)
break;
}
}
void copy_string_array_from_src_to_buf(const __FlashStringHelper** src, uint8_t array_length, char* buf, uint8_t buf_size, uint8_t str_len){
copy_string_array_from_src_to_buf((const char **)src, array_length, buf, buf_size, str_len);
}
void append_progmem_string_to_string(const __FlashStringHelper* src, char *dest, uint8_t max_string_length){
uint16_t used_length = strlen(dest);
uint16_t remaining_length = max_string_length - used_length;
strncat_P(dest, (const char*)src, remaining_length);
}
// ------------------------------------------------
// Game Events
// ------------------------------------------------
class event;
typedef void (event::*load_description_type)(char *string_to_init, uint8_t max_string_length);
typedef void (event::*load_object_menu_type)(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length);
typedef event (event::*process_action_on_object_type)(uint8_t selected_action, uint8_t object_selected);
typedef event (event::*process_item_on_object_type)(player_item_id selected_item, uint8_t object_selected);
typedef event (event::*get_prelude_event_type)();
typedef bool (event::*simple_bool_question_type)();
// Do not use virtual methods because the vtable resides in both progmem, and sram.
// Do not add properties to sub-classes otherwise object shearing will result.
class event
{
public:
event()
: internal_load_description( &default_load_description )
, internal_load_object_menu( &default_load_object_menu )
, internal_process_action_on_object( &default_process_action_on_object )
, internal_process_item_on_object( &default_process_item_on_object )
, internal_get_continue_event( &default_get_continue_event )
, internal_actions_are_allowed( &default_actions_are_allowed )
, internal_return_to_previous_event( &default_should_return_to_previous_event )
, description( (const char*)F("Nothing happens.") )
, allow_actions( false )
, return_to_previous_event( true )
, local_event_tags( 0 )
{ }
event(const __FlashStringHelper* progmem_description)
: event()
{
description = (const char*)progmem_description;
}
void load_description(char *string_to_init, uint8_t max_string_length){
CALL_REF((*this),internal_load_description)(string_to_init, max_string_length);
}
void load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
CALL_REF((*this),internal_load_object_menu)(menu_buffer, menu_length, menu_item_length);
}
event process_action_on_object(uint8_t selected_action, uint8_t object_selected){
return CALL_REF((*this),internal_process_action_on_object)(selected_action, object_selected);
}
event process_item_on_object(player_item_id selected_item, uint8_t object_selected){
return CALL_REF((*this),internal_process_item_on_object)(selected_item, object_selected);
}
event get_continue_event(){
return CALL_REF((*this),internal_get_continue_event)();
}
bool actions_are_allowed(){
return CALL_REF((*this),internal_actions_are_allowed)();
}
bool should_return_to_previous_event(){
return CALL_REF((*this),internal_return_to_previous_event)();
}
protected:
const char *description;
bool allow_actions;
bool return_to_previous_event;
uint8_t local_event_tags;
load_description_type internal_load_description;
load_object_menu_type internal_load_object_menu;
process_action_on_object_type internal_process_action_on_object;
process_item_on_object_type internal_process_item_on_object;
get_prelude_event_type internal_get_continue_event;
simple_bool_question_type internal_actions_are_allowed;
simple_bool_question_type internal_return_to_previous_event;
void default_load_description(char *string_to_init, uint8_t max_string_length);
void default_load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length) {};
event default_process_action_on_object(uint8_t selected_action, uint8_t object_selected){ return event(); }
event default_process_item_on_object(player_item_id selected_item, uint8_t object_selected){ return event(); }
event default_get_continue_event() { return event(); }
bool default_actions_are_allowed() { return allow_actions; }
bool default_should_return_to_previous_event() { return return_to_previous_event; }
};
void event::default_load_description(char *string_to_init, uint8_t max_string_length)
{
load_progmem_string_to_var(description, string_to_init, max_string_length);
}
struct
{
game_state_id state = GAME_STATE_ID_TITLE;
} game_state;
const char drink_pink_vial[] PROGMEM = "You take the pink vial and drink it. It tastes foul. A few moments later, you start coughing blood violently and collapse. Everything goes dark.";
const char open_chest_description[] PROGMEM = "The key slots in and turns. The chest unlocks and you open it. The door slams shut behind you. Inside you see ";
const char f0_hall_description[] PROGMEM = "The light from your lamp shows this is a store room with many barrels. There is a well in the middle of the room.";
event create_f0_main_hall_event();
event create_f1_main_hall_event();
event create_f2_main_hall_event();
event create_f3_main_hall_event();
class intro_event : public event {
public:
intro_event(){
description = (const char*)F("Stairs lead up to the first floor of the abandoned tower. A tower flowing with what Angels fear; the dark. You ascend hoping to find a way to break the curse of undeath that has come upon you. The tower's doors close behind you. You are trapped!");
internal_get_continue_event = static_cast<get_prelude_event_type>(&real_get_continue_event);
return_to_previous_event = false;
player.remove_achievement(EVENT_TAG_ID_ALL);
player.remove_item(PLAYER_ITEM_ID_ALL);
// temp for testing - 6 bytes needed
//player.add_item(PLAYER_ITEM_ID_SHEET);
}
private:
event real_get_continue_event(){
return create_f1_main_hall_event();
}
};
class resurrect_event : public event {
public:
resurrect_event(){
description = (const char*)F("You wake up in the entrance hall of the tower. Not sure of what has happened, you find you have lost your items!");
internal_get_continue_event = static_cast<get_prelude_event_type>(&real_get_continue_event);
return_to_previous_event = false;
player.remove_achievement(EVENT_TAG_ID_ALL);
player.remove_item(PLAYER_ITEM_ID_ALL);
}
private:
event real_get_continue_event(){
return create_f1_main_hall_event();
}
};
class return_to_game : public event {
public:
return_to_game(){
description = (const char *)F("Well Done! You have won! If you would like to play again, then please continue.");
internal_get_continue_event = static_cast<get_prelude_event_type>(&real_get_continue_event);
return_to_previous_event = false;
}
protected:
event real_get_continue_event(){
return intro_event();
}
};
class win_event : public event {
public:
win_event(){
description = (const char *)F("You leave the tower feeling reborn. The ordeal of the tower may well live with you forever, but now no longer bearing the curse of undeath you can explore and enjoy everything the world has to offer.");
internal_get_continue_event = static_cast<get_prelude_event_type>(&real_get_continue_event);
return_to_previous_event = false;
}
protected:
event real_get_continue_event(){
return return_to_game();
}
};
class player_dies_event : public event {
public:
player_dies_event(){
description = (const char *)F("");
internal_get_continue_event = static_cast<get_prelude_event_type>(&real_get_continue_event);
return_to_previous_event = false;
}
player_dies_event(const __FlashStringHelper* progmem_description)
: player_dies_event()
{
description = (const char*)progmem_description;
}
protected:
event real_get_continue_event(){
return resurrect_event();
}
};
struct drinks_yellow_vial_event : public event
{
drinks_yellow_vial_event(){
description = (const char *)F("You take the yellow vial and drink it. It tastes foul. A few moments later, you feel warmth return to your body. You starting breathing again. The potion has cured you of the curse of undeath!");
internal_get_continue_event = static_cast<get_prelude_event_type>(&real_get_continue_event);
return_to_previous_event = false;
}
protected:
event real_get_continue_event(){
return win_event();
}
};
class f0_in_the_well_event : public event {
public:
f0_in_the_well_event(){
description = (const char *)F("The water comes up to your waist, it feels cold.");
allow_actions = true;
internal_load_object_menu = static_cast<load_object_menu_type>(&real_load_object_menu);
internal_process_action_on_object = static_cast<process_action_on_object_type>(&real_process_action_on_object);
internal_load_description = static_cast<load_description_type>(&real_load_description);
}
private:
static const uint8_t EVENT_NOTICE_KEY = (1<<0);
void real_load_description(char *string_to_init, uint8_t max_string_length)
{
default_load_description(string_to_init, max_string_length);
if (should_show_crystal())
append_progmem_string_to_string(F(" You can see what looks like a crystal in the water."), string_to_init, max_string_length);
}
bool should_show_crystal(){
bool crystal_is_available = !player.has_item(PLAYER_ITEM_ID_MASTER_KEY);
bool crystal_has_not_been_used = !player.has_achievement(EVENT_TAG_ID_MASTER_ROOM_DOOR_OPENED);
return (crystal_is_available && crystal_has_not_been_used);
}
bool should_show_key(){
bool key_has_been_noticed = local_event_tags & EVENT_NOTICE_KEY;
bool key_is_available = !player.has_item(PLAYER_ITEM_ID_BLANK_KEY);
bool key_is_not_cut = !player.has_item(PLAYER_ITEM_ID_COPIED_KEY);
bool crystal_is_shown = should_show_crystal();
return (key_has_been_noticed && key_is_available && crystal_is_shown && key_is_not_cut);
}
void real_load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
const __FlashStringHelper* object_list[] =
{ F("Water")
, F("Rope")
, F("Crystal")
, F("Key")
};
uint8_t object_list_length = sizeof(object_list) / sizeof(typeof(object_list[0]));
object_list_length -= 2;
if (should_show_crystal()){
object_list_length++;
if (should_show_key())
object_list_length++;
}
copy_string_array_from_src_to_buf(object_list, object_list_length, menu_buffer, menu_length, menu_item_length);
}
event real_process_action_on_object(uint8_t selected_action, uint8_t object_selected){
const __FlashStringHelper* look_descriptions[] =
{ F("The water is clear and stagnant.")
, F("The rope hangs down from above.")
, F("The diamond-shaped crystal seems to glow with magical energy.")
, F("The key is has a no cuttings on its head. It is like a blank key.")
, F("You notice in the light of the crystal there is a key in water.")
};
switch (selected_action){
case ACTION_ID_LOOK:
if (object_selected == 0 && should_show_crystal()){
local_event_tags |= EVENT_NOTICE_KEY;
object_selected = 4;
}
return event(look_descriptions[object_selected]);
case ACTION_ID_USE:
if (object_selected == 1)
return create_f0_main_hall_event();
break;
case ACTION_ID_TAKE:
if (object_selected == 2){
bool key_disapears = should_show_key();
player.add_item(PLAYER_ITEM_ID_MASTER_KEY);
if ( key_disapears )
return event(F("You take the diamond-shaped crystal. The key in the water fades into nothingness."));
else
return event(F("You take the diamond-shaped crystal."));
}
if (object_selected == 3){
player.add_item(PLAYER_ITEM_ID_BLANK_KEY);
return event(F("You take the blank key."));
}
break;
}
return event();
}
};
class f0_light_room_event : public event {
public:
f0_light_room_event(){
description = f0_hall_description;
allow_actions = true;
internal_load_object_menu = static_cast<load_object_menu_type>(&real_load_object_menu);
internal_process_action_on_object = static_cast<process_action_on_object_type>(&real_process_action_on_object);
internal_process_item_on_object = static_cast<process_item_on_object_type>(&real_process_item_on_object);
}
private:
static const uint8_t EVENT_NOTICE_ROPE = (1<<0);
bool should_show_rope(){
bool rope_has_been_noticed = local_event_tags & EVENT_NOTICE_ROPE;
bool rope_is_available = !player.has_item(PLAYER_ITEM_ID_ROPE);
return ( rope_has_been_noticed && rope_is_available );
}
bool should_show_crystal(){
bool crystal_is_available = !player.has_item(PLAYER_ITEM_ID_MASTER_KEY);
bool crystal_has_not_been_used = !player.has_achievement(EVENT_TAG_ID_MASTER_ROOM_DOOR_OPENED);
return (crystal_is_available && crystal_has_not_been_used);
}
void real_load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
const __FlashStringHelper* object_list[] =
{ F("Stairs up")
, F("Barrels")
, F("Well")
, F("Rope")
};
uint8_t object_list_length = sizeof(object_list) / sizeof(typeof(object_list[0]));
object_list_length --;
if (should_show_rope())
object_list_length++;
copy_string_array_from_src_to_buf(object_list, object_list_length, menu_buffer, menu_length, menu_item_length);
}
const __FlashStringHelper* shimmer_in_water(){
return F("There seems to be water in the well. Something glitters in the light under the shallow water.");
}
event real_process_action_on_object(uint8_t selected_action, uint8_t object_selected){
const __FlashStringHelper* look_descriptions[] =
{ F("The stairs lead up to the light of the entrance room.")
, F("The barrels contain grain.")
, F("There seems to be water in the well.")
, F("The long length of rope is made of hemp and looks strong.")
, F("One of the barrels contains some rope.")
};
switch (selected_action){
case ACTION_ID_LOOK:
if (object_selected == 1){
if ( !player.has_item(PLAYER_ITEM_ID_ROPE) && !player.has_achievement(EVENT_TAG_ID_ROPE_TIED_AROUND_WELL)){
local_event_tags |= EVENT_NOTICE_ROPE;
object_selected = 4;
}
}
else if (object_selected == 2){
if ( should_show_crystal() )
return event(shimmer_in_water());
}
return event(look_descriptions[object_selected]);
case ACTION_ID_USE:
if (object_selected == 0)
return create_f1_main_hall_event();
else if (object_selected == 3 && player.has_achievement(EVENT_TAG_ID_ROPE_TIED_AROUND_WELL))
return f0_in_the_well_event();
break;
case ACTION_ID_TAKE:
if (object_selected == 3){
player.add_item(PLAYER_ITEM_ID_ROPE);
player.remove_achievement(EVENT_TAG_ID_ROPE_TIED_AROUND_WELL);
return event(F("You gather the rope."));
}
break;
}
return event();
}
event real_process_item_on_object(player_item_id selected_item, uint8_t object_selected){
if (selected_item == PLAYER_ITEM_ID_ROPE){
if (object_selected == 2){
player.add_achievement(EVENT_TAG_ID_ROPE_TIED_AROUND_WELL);
player.remove_item(PLAYER_ITEM_ID_ROPE);
return event(F("You tie the rope around the well."));
}
}
else if (selected_item == PLAYER_ITEM_ID_OIL_LAMP){
if (object_selected == 2){
if ( should_show_crystal() )
return event(shimmer_in_water());
else
return event(F("The water is still."));
}
}
return event();
}
};
class f0_monster_dies_event : public event {
public:
f0_monster_dies_event(){
description = (const char *)F("The bat flies towards you, fangs ready to bite you. You quickly draw your sword and swing at the creature. The sword cuts the creature and the fell beast screeches and bursts into flames before evaporating into mist.");
internal_get_continue_event = static_cast<get_prelude_event_type>(&real_get_continue_event);
return_to_previous_event = false;
}
private:
event real_get_continue_event(){
return f0_light_room_event();
}
};
class f0_monster_attacks_event : public event {
public:
f0_monster_attacks_event(){
description = f0_hall_description;
allow_actions = true;
internal_load_object_menu = static_cast<load_object_menu_type>(&real_load_object_menu);
internal_process_action_on_object = static_cast<process_action_on_object_type>(&real_process_action_on_object);
internal_process_item_on_object = static_cast<process_item_on_object_type>(&real_process_item_on_object);
internal_load_description = static_cast<load_description_type>(&real_load_description);
}
private:
void real_load_description(char *string_to_init, uint8_t max_string_length)
{
default_load_description(string_to_init, max_string_length);
append_progmem_string_to_string(F(" Your light disturbs a large black creature, hanging from the ceiling. The large bat unfolds its wings and attacks you!"), string_to_init, max_string_length);
}
void real_load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
const __FlashStringHelper* object_list[] =
{ F("Stairs up")
, F("Barrels")
, F("Well")
, F("Large Bat")
};
uint8_t object_list_length = sizeof(object_list) / sizeof(typeof(object_list[0]));
copy_string_array_from_src_to_buf(object_list, object_list_length, menu_buffer, menu_length, menu_item_length);
}
event real_process_action_on_object(uint8_t selected_action, uint8_t object_selected){
switch (selected_action){
case ACTION_ID_LOOK:
if (object_selected == 3)
return event(F("The bat has a five foot wing span and very sharp fangs."));
break;
}
return killed_by_bat_while_distracted();
}
event real_process_item_on_object(player_item_id selected_item, uint8_t object_selected){
if (object_selected == 3){
if (selected_item == PLAYER_ITEM_ID_SWORD){
player.add_achievement(EVENT_TAG_ID_CRYPT_MONSTER_DEAD);
return f0_monster_dies_event();
}
return event();
}
return killed_by_bat_while_distracted();
}
event killed_by_bat_while_distracted(){
return player_dies_event(F("While distracted the bat grabs you and sinks its fangs deep into your neck. Everything goes dark."));
}
};
class f0_dark_room_event : public event {
public:
f0_dark_room_event(){
description = (const char *)F("You descend several steps, but it quickly gets too dark to proceed further.");
allow_actions = true;
internal_load_object_menu = static_cast<load_object_menu_type>(&real_load_object_menu);
internal_process_action_on_object = static_cast<process_action_on_object_type>(&real_process_action_on_object);
internal_process_item_on_object = static_cast<process_item_on_object_type>(&real_process_item_on_object);
}
private:
void real_load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
const __FlashStringHelper* object_list[] =
{ F("Stairs up")
, F("Darkness")
};
uint8_t object_list_length = sizeof(object_list) / sizeof(typeof(object_list[0]));
copy_string_array_from_src_to_buf(object_list, object_list_length, menu_buffer, menu_length, menu_item_length);
}
event real_process_action_on_object(uint8_t selected_action, uint8_t object_selected){
const __FlashStringHelper* look_descriptions[] =
{ F("The stairs lead up to the light of the entrance room.")
, F("This area is too dark to see anything.")
};
switch (selected_action){
case ACTION_ID_LOOK:
return event(look_descriptions[object_selected]);
case ACTION_ID_USE:
if (object_selected == 0)
return create_f1_main_hall_event();
}
return event();
}
event real_process_item_on_object(player_item_id selected_item, uint8_t object_selected){
switch (selected_item){
case PLAYER_ITEM_ID_OIL_LAMP:
if (object_selected == 1){
if (player.has_achievement(EVENT_TAG_ID_CRYPT_MONSTER_DEAD))
return f0_light_room_event();
else
return f0_monster_attacks_event();
}
}
return event();
}
};
class f4_open_chest_with_copied_key : public event {
public:
f4_open_chest_with_copied_key(){
description = open_chest_description;
internal_load_object_menu = static_cast<load_object_menu_type>(&real_load_object_menu);
internal_process_action_on_object = static_cast<process_action_on_object_type>(&real_process_action_on_object);
internal_load_description = static_cast<load_description_type>(&real_load_description);
allow_actions = true;
}
private:
void real_load_description(char *string_to_init, uint8_t max_string_length)
{
default_load_description(string_to_init, max_string_length);
append_progmem_string_to_string(F("two vials, each containing a different coloured liquid."), string_to_init, max_string_length);
}
void real_load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
const __FlashStringHelper* object_list[] =
{ F("Pink Vial")
, F("Yellow Vial")
, F("Door")
};
uint8_t object_list_length = sizeof(object_list) / sizeof(typeof(object_list[0]));
copy_string_array_from_src_to_buf(object_list, object_list_length, menu_buffer, menu_length, menu_item_length);
}
event real_process_action_on_object(uint8_t selected_action, uint8_t object_selected){
const __FlashStringHelper* look_descriptions[] =
{ F("The small vial contains a pink liquid.")
, F("The small vial contains a yellow liquid.")
, F("The door is shut tight. You cannot open it.")
};
switch (selected_action){
case ACTION_ID_LOOK:
return event(look_descriptions[object_selected]);
case ACTION_ID_USE:
case ACTION_ID_TAKE:
switch (object_selected){
case 0:
return player_dies_event((const __FlashStringHelper*)drink_pink_vial);
case 1:
return drinks_yellow_vial_event();
}
return event(look_descriptions[object_selected]);
break;
}
return event();
}
};
class f4_open_chest_with_modified_key : public event {
public:
f4_open_chest_with_modified_key(){
description = open_chest_description;
internal_load_object_menu = static_cast<load_object_menu_type>(&real_load_object_menu);
internal_process_action_on_object = static_cast<process_action_on_object_type>(&real_process_action_on_object);
internal_load_description = static_cast<load_description_type>(&real_load_description);
allow_actions = true;
}
private:
void real_load_description(char *string_to_init, uint8_t max_string_length)
{
default_load_description(string_to_init, max_string_length);
append_progmem_string_to_string(F("a vial containing a pink liquid."), string_to_init, max_string_length);
}
void real_load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
const __FlashStringHelper* object_list[] =
{ F("Pink Vial")
, F("Door")
};
uint8_t object_list_length = sizeof(object_list) / sizeof(typeof(object_list[0]));
copy_string_array_from_src_to_buf(object_list, object_list_length, menu_buffer, menu_length, menu_item_length);
}
event real_process_action_on_object(uint8_t selected_action, uint8_t object_selected){
const __FlashStringHelper* look_descriptions[] =
{ F("The small vial contains a pink liquid.")
, F("The door is shut tight. You cannot open it.")
};
switch (selected_action){
case ACTION_ID_LOOK:
return event(look_descriptions[object_selected]);
case ACTION_ID_USE:
case ACTION_ID_TAKE:
switch (object_selected){
case 0:
return player_dies_event((const __FlashStringHelper*)drink_pink_vial);
}
return event(look_descriptions[object_selected]);
break;
}
return event();
}
};
class f4_open_chest_with_chest_key : public event {
public:
f4_open_chest_with_chest_key(){
description = open_chest_description;
internal_load_object_menu = static_cast<load_object_menu_type>(&real_load_object_menu);
internal_process_action_on_object = static_cast<process_action_on_object_type>(&real_process_action_on_object);
internal_load_description = static_cast<load_description_type>(&real_load_description);
allow_actions = true;
}
private:
void real_load_description(char *string_to_init, uint8_t max_string_length)
{
default_load_description(string_to_init, max_string_length);
append_progmem_string_to_string(F("a vial containing a pink liquid."), string_to_init, max_string_length);
}
void real_load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
const __FlashStringHelper* object_list[] =
{ F("Vial")
, F("Door")
};
uint8_t object_list_length = sizeof(object_list) / sizeof(typeof(object_list[0]));
copy_string_array_from_src_to_buf(object_list, object_list_length, menu_buffer, menu_length, menu_item_length);
}
event real_process_action_on_object(uint8_t selected_action, uint8_t object_selected){
const __FlashStringHelper* look_descriptions[] =
{ F("The small vial contains a pink liquid.")
, F("The door is shut tight. You cannot open it.")
};
switch (selected_action){
case ACTION_ID_LOOK:
return event(look_descriptions[object_selected]);
case ACTION_ID_USE:
case ACTION_ID_TAKE:
switch (object_selected){
case 0:
return player_dies_event((const __FlashStringHelper*)drink_pink_vial);
}
return event(look_descriptions[object_selected]);
break;
}
return event();
}
};
class f4_main_hall_event : public event {
public:
f4_main_hall_event(){
description = (const char *)F("Four arrow-slit windows cast a dim light in this room. A chest stands in the middle of the room.");
internal_load_object_menu = static_cast<load_object_menu_type>(&real_load_object_menu);
internal_process_action_on_object = static_cast<process_action_on_object_type>(&real_process_action_on_object);
internal_process_item_on_object = static_cast<process_item_on_object_type>(&real_process_item_on_object);
allow_actions = true;
}
private:
void real_load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
const __FlashStringHelper* object_list[] =
{ F("Chest")
, F("Stairs down")
};
uint8_t object_list_length = sizeof(object_list) / sizeof(typeof(object_list[0]));
copy_string_array_from_src_to_buf(object_list, object_list_length, menu_buffer, menu_length, menu_item_length);
}
event real_process_action_on_object(uint8_t selected_action, uint8_t object_selected){
const __FlashStringHelper* look_descriptions[] =
{ F("The chest is sturdy with iron bands and a lock built in. Could this have the cure you are looking for?")
, F("The stairs lead down to the floor below.")
};
switch (selected_action){
case ACTION_ID_LOOK:
return event(look_descriptions[object_selected]);
case ACTION_ID_USE:
switch (object_selected){
case 1:
return create_f3_main_hall_event();
}
break;
case ACTION_ID_TAKE:
switch (object_selected){
case 0:
return event(F("You try to move the chest, but it won't budge. It is like it is held in place by some force."));
}
break;
}
return event();
}
event real_process_item_on_object(player_item_id selected_item, uint8_t object_selected){
if (object_selected == 0){
if (selected_item == PLAYER_ITEM_ID_CHEST_KEY)
return f4_open_chest_with_chest_key();
if (selected_item == PLAYER_ITEM_ID_MOD_CHEST_KEY)
return f4_open_chest_with_modified_key();
if (selected_item == PLAYER_ITEM_ID_COPIED_KEY)
return f4_open_chest_with_copied_key();
}
return event();
}
};
class f4_door_unlocked_event : public event {
public:
f4_door_unlocked_event(){
description = (const char *)F("You place the crystal in the door. The magic circle and the symbols glow faintly and hum with energy. With a loud grinding sound, the door swings open to reveal the room beyond.");
internal_get_continue_event = static_cast<get_prelude_event_type>(&real_get_continue_event);
return_to_previous_event = false;
}
private:
event real_get_continue_event(){
return f4_main_hall_event();
}
};
class f4_main_hall_locked_event : public event {
public:
f4_main_hall_locked_event(){
description = (const char *)F("You ascend the stairs to the next floor. A solid oak door awaits you at the top of the stairs.");
allow_actions = true;
internal_load_object_menu = static_cast<load_object_menu_type>(&real_load_object_menu);
internal_process_action_on_object = static_cast<process_action_on_object_type>(&real_process_action_on_object);
internal_process_item_on_object = static_cast<process_item_on_object_type>(&real_process_item_on_object);
}
private:
void real_load_object_menu(char *menu_buffer, uint8_t menu_length, uint8_t menu_item_length){
const __FlashStringHelper* object_list[] =
{ F("Stairs Down")
, F("Door")
};
uint8_t object_list_length = sizeof(object_list) / sizeof(typeof(object_list[0]));
copy_string_array_from_src_to_buf(object_list, object_list_length, menu_buffer, menu_length, menu_item_length);
}
event real_process_action_on_object(uint8_t selected_action, uint8_t object_selected){
const __FlashStringHelper* look_descriptions[] =
{ F("The stairs lead down to the hall below.")
, F("The solid oak door is sturdy and is locked. A magic circle with strange symbols mark the door. In the centre is a diamond shaped hole.")
};
switch (selected_action){
case ACTION_ID_LOOK:
return event(look_descriptions[object_selected]);
case ACTION_ID_USE:
if (object_selected == 0)
return create_f3_main_hall_event();
}
return event();
}
event real_process_item_on_object(player_item_id selected_item, uint8_t object_selected){
if (selected_item == PLAYER_ITEM_ID_MASTER_KEY)
if (object_selected == 1){
player.add_achievement(EVENT_TAG_ID_MASTER_ROOM_DOOR_OPENED);
return f4_door_unlocked_event();
}