-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
6761 lines (5826 loc) · 140 KB
/
main.cpp
File metadata and controls
6761 lines (5826 loc) · 140 KB
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
/*
* PROPRIETARY INFORMATION. This software is proprietary to POWDER
* Development, and is not to be reproduced, transmitted, or disclosed
* in any way without written permission.
*
* Produced by: Jeff Lait
*
* POWDER Development
*
* NAME: main.cpp ( POWDER Library, C++ )
*
* COMMENTS:
* Good old main.
*
* This is where the main game loop resides. It is also where
* a lot of the UI interaction has ended up. Code here, almost
* by definition, should be refactored somewhere else.
*/
#include "mygba.h"
#include <stdio.h>
#include <ctype.h>
#include "gfxengine.h"
#include "gfx/all_bitmaps.h"
#include "artifact.h"
#include "encyc_support.h"
#include "control.h"
#include "glbdef.h"
#include "creature.h"
#include "map.h"
#include "assert.h"
#include "msg.h"
#include "item.h"
#include "itemstack.h"
#include "input.h"
#include "sramstream.h"
#include "victory.h"
#include "mobref.h"
#include "speed.h"
#include "piety.h"
#include "hiscore.h"
#include "stylus.h"
#include "rooms/allrooms.h"
#ifdef iPOWDER
#include "thread.h"
#endif
#if defined(USING_SDL) || defined(USING_DS) || defined(_3DS)
#include <time.h>
#endif
// Defines whether we are in map testing mode.
//#define MAPTEST
// MULTIBOOT
// The following comment is preserved to provide sufficinet irony
// to avoid the danger of code anemia.
/*
----------------------------------
This is a simple mapping application...
----------------------------------
*/
#ifdef USING_SDL
#define TILEWIDTH (gfx_gettilewidth())
#define TILEHEIGHT (gfx_gettileheight())
#else
#define TILEWIDTH 8
#define TILEHEIGHT 8
#endif
//
// No one likes autoprompt. Boohoo!
// But I have used it for a year now, so screw the user!
// In the end, it turned out to be a keyboard centric issue. Those
// lacking keyboards love autoprompt, those with hate. Thankfully
// this is a compile time issue.
//
#ifdef HAS_KEYBOARD
bool glbAutoPrompt = false;
#else
bool glbAutoPrompt = true;
#endif
bool glbSuppressAutoClimb = false;
// Do we allow the user to tap on the screen to move?
bool glbScreenTap = true;
#ifdef iPOWDER
bool glbActionBar = false;
#else
bool glbActionBar = true;
#endif
bool glbColouredFont = true;
bool glbFinishedASave = false;
bool glbSafeWalk = false;
bool glbToggleSafeWalk = false;
bool glbSwap = false;
bool glbToggleSwap = false;
bool glbJump = false;
bool glbToggleJump = false;
int glbAutoRunDX = 0;
int glbAutoRunDY = 0;
bool glbAutoRunEnabled = false;
bool glbAutoRunOpenSpace = false;
bool glbHasJustSearched = false;
int glbSearchCount = 0;
extern int glbMapCount;
extern int glbMobCount;
extern int glbItemCount;
#ifdef _3DS
int glbScreenMode = 0;
#endif
ACTION_NAMES glb_actionbuttons[NUM_BUTTONS];
#ifdef iPOWDER
// Note the default of 0 actually is rather sensible here
int glb_spellgreylist[NUM_SPELLS];
#endif
#define STRIPLENGTH 50
// Specifies the default.
const ACTION_NAMES glb_globaldefaultactionstrip[STRIPLENGTH] =
{
ACTION_HELP,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_OPTIONS,
// Bottom row.
ACTION_LOOK,
ACTION_PICKUP,
ACTION_CLIMB,
ACTION_ZAP,
ACTION_FIRE,
ACTION_EAT,
ACTION_CLOSE,
ACTION_PRAY,
ACTION_SWAP,
ACTION_NAME,
ACTION_MINIMAP,
ACTION_JUMP,
ACTION_COMMAND,
ACTION_INVENTORY,
ACTION_VERBLIST,
// Left
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
// Right
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
};
u8 glb_globalactionstrip[STRIPLENGTH];
u8 *
getGlobalActionStrip()
{
return glb_globalactionstrip;
}
// This is not remappable so is fixed.
const ACTION_NAMES glb_inventoryactionstrip[STRIPLENGTH] =
{
// Top
ACTION_FAVORITE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
// Bottom
ACTION_EQUIP,
ACTION_DEQUIP,
ACTION_DIP,
ACTION_QUAFF,
ACTION_READ,
ACTION_ZAP,
ACTION_EAT,
ACTION_DROP,
ACTION_EXAMINE,
ACTION_QUIVER,
ACTION_THROW,
ACTION_SPLITSTACK,
ACTION_NAME,
ACTION_INVENTORY,
ACTION_SORT,
// Left
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
// Right
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
ACTION_NONE,
};
void
attemptunlock()
{
#ifdef iPOWDER
gfx_pager_addtext(
"POWDER is not like many similar looking games. It "
"is entirely reasonable for you to spend the next "
"year actively playing it and still not reach "
"dungeon level 15."
);
gfx_pager_newline(); gfx_pager_newline();
gfx_pager_addtext(
"This is not because of an arduous grind! You could win a game "
"of POWDER in three hours of play time. It is because "
"POWDER is hard, unforgiving, and a heck of a lot of fun."
);
gfx_pager_newline(); gfx_pager_newline();
gfx_pager_addtext(
"To explore deeper than dungeon level 15, however, you "
"must unlock POWDER. To help you reach those levels, as an "
"added bonus, when unlocked, you gain access to the "
"powerful Wish command that allows you to summon any item or "
"creature. Finally, unlocking will enable the stress "
"test."
);
gfx_pager_newline();
gfx_pager_display();
if (!hamfake_allowunlocks())
{
gfx_pager_addtext(
"You have disabled in-app purchases. Please re-enable "
"and try again."
);
gfx_pager_newline();
gfx_pager_display();
return;
}
if (!gfx_yesnomenu("Unlock POWDER now?"))
{
return;
}
hamfake_buttonreq(6);
// This may take a while, let the user know it is asynchronous.
gfx_pager_addtext(
"Accessing the store..."
);
gfx_pager_newline(); gfx_pager_newline();
gfx_pager_addtext(
"This may take a while. System pop-ups will take you through "
"the rest of the process. In the meantime, we return you to "
"your regularly scheduled game."
);
gfx_pager_newline();
gfx_pager_display();
#endif
}
ACTION_NAMES
getInventoryActionStrip(int button)
{
return glb_inventoryactionstrip[button];
}
void
resetDefaultActionStrip()
{
int i;
// Initialize the button strip.
for (i = 0; i < STRIPLENGTH; i++)
{
glb_globalactionstrip[i] = action_packStripButton(glb_globaldefaultactionstrip[i]);
}
}
const BUTTONS glb_mapbuttons[] =
{
BUTTON_A,
BUTTON_B,
BUTTON_R,
BUTTON_L,
#ifdef HAS_XYBUTTON
BUTTON_X,
BUTTON_Y,
#endif
NUM_BUTTONS
};
char
getActionChar(ACTION_NAMES action)
{
return glb_actiondefs[action].hint[0];
}
void
hideSideActionBar()
{
#ifdef HAS_STYLUS
int x, sx, sy;
if (glbActionBar)
{
for (x = 0; x < STRIPLENGTH; x++)
{
action_indexToOverlayPos(x, sx, sy);
if (sx == -1 || sx == 29)
{
hamfake_enablesprite(x+1, false);
}
}
}
#endif
}
bool
getMask(u8 val, int mask)
{
if (val & mask)
return true;
return false;
}
u8
setMask(bool state, int mask)
{
if (state)
return mask;
return 0;
}
void
loadOptions(SRAMSTREAM &is)
{
u8 val;
int i;
// Load our action key mappings.
for (i = 0; glb_mapbuttons[i] != NUM_BUTTONS; i++)
{
is.readRaw((char *) &val, 1);
glb_actionbuttons[glb_mapbuttons[i]] =
(ACTION_NAMES) val;
}
is.readRaw((char *) &val, 1);
glbAutoPrompt = getMask(val, 1);
glbActionBar = getMask(val, 2);
glbOpaqueTiles = getMask(val, 4);
glbColouredFont = getMask(val, 8);
glbGender = getMask(val, 16);
glbSafeWalk = getMask(val, 32);
// We save the opposite sense so people get the expected for
// versions that didn't save it.
glbScreenTap = !getMask(val, 64);
is.readRaw((char *) &val, 1);
int pset, sset;
pset = val & 0xf;
sset = val >> 4;
// Verify the tileset is legal.
if (pset >= NUM_TILESETS - !hamfake_extratileset())
pset = 0;
if (sset >= NUM_TILESETS - !hamfake_extratileset())
sset = 0;
gfx_settilesetmode(0, pset);
gfx_settilesetmode(1, sset);
// Load our current font
is.readRaw((char *) &val, 1);
#ifdef _3DS
glbScreenMode = (val>>6)&1;
val = val& 0b00111111;
#endif
if (val >= NUM_FONTS)
val = 0;
gfx_switchfonts(val);
is.readRaw(glbAvatarName, 23);
glbAvatarName[23] = 0;
}
void
saveOptions(SRAMSTREAM &os)
{
u8 val;
int i;
// Save our current action key mappings.
for (i = 0; glb_mapbuttons[i] != NUM_BUTTONS; i++)
{
val = glb_actionbuttons[glb_mapbuttons[i]];
os.writeRaw((const char *) &val, 1);
}
val = 0;
val |= setMask(glbAutoPrompt, 1);
val |= setMask(glbActionBar, 2);
val |= setMask(glbOpaqueTiles, 4);
val |= setMask(glbColouredFont, 8);
val |= setMask(glbGender, 16);
val |= setMask(glbSafeWalk, 32);
val |= setMask(!glbScreenTap, 64);
glbSuppressAutoClimb = false;
os.writeRaw((const char *) &val, 1);
// Save our current tileset
val = gfx_gettilesetmode(0) | (gfx_gettilesetmode(1) << 4);
os.writeRaw((const char *) &val, 1);
val = gfx_getfont();
#ifdef _3DS
val |= glbScreenMode << 6;
#endif
os.writeRaw((const char *) &val, 1);
// Not necessarily null terminated!
os.writeRaw(glbAvatarName, 23);
}
bool
makeAWish(MOB *avatar)
{
bool didsomething = false;
const char *topmenu[] =
{
"Item by Type",
"Magic Item",
"Monster",
"Spell",
"Skill",
"Experience",
"Befriend Gods",
"Level Teleport",
"Create Room",
"Shape Shift",
0
};
static int topchoice = 0;
int select, aorb;
select = gfx_selectmenu(5, 3, topmenu, aorb, topchoice);
if (select < 0 || aorb)
{
for (int y = 3; y < 19; y++)
gfx_cleartextline(y);
return false;
}
topchoice = select;
switch (topchoice)
{
case 0: // Item by type...
{
const char *typelist[NUM_ITEMTYPES+1];
ITEMTYPE_NAMES itype;
static int lasttype = 0;
FOREACH_ITEMTYPE(itype)
{
typelist[itype] = glb_itemtypedefs[itype].name;
}
typelist[NUM_ITEMTYPES] = 0;
select = gfx_selectmenu(5, 3, typelist, aorb, lasttype);
if (select < 0 || aorb)
break;
itype = (ITEMTYPE_NAMES) select;
lasttype = select;
// Build our list of matching items.
const char *itemlist[NUM_ITEMS+1];
ITEM_NAMES itemname[NUM_ITEMS+1], item;
int i = 0;
FOREACH_ITEM(item)
{
if (itype == ITEMTYPE_ANY
|| itype == ITEMTYPE_ARTIFACT
|| glb_itemdefs[item].itemtype == itype)
{
itemlist[i] = glb_itemdefs[item].name;
itemname[i] = item;
i++;
}
}
itemlist[i] = 0;
// Empty list means no selection possible
if (!i)
break;
static int lastitemchoice = 0;
select = gfx_selectmenu(5, 3, itemlist, aorb, lastitemchoice);
if (select < 0 || aorb)
break;
lastitemchoice = select;
{
// Acquire the item...
ITEM *wish;
wish = ITEM::create((ITEM_NAMES) itemname[select]);
if (itype == ITEMTYPE_ARTIFACT)
{
wish->makeArtifact();
}
// Some items need built in charges
if (itemname[select] == ITEM_BONES ||
itemname[select] == ITEM_CORPSE)
{
wish->addCharges(20);
}
avatar->formatAndReport("%U <wish> for %IU.", wish);
if (!avatar->acquireItem(wish))
{
avatar->formatAndReport("%IU <I:fall> at %r feet.", wish);
glbCurLevel->acquireItem(wish, avatar->getX(), avatar->getY(), avatar);
}
}
didsomething = true;
break;
}
case 1: // Magic Item
{
const char *typelist[NUM_MAGICTYPES+1];
MAGICTYPE_NAMES mtype;
static int lasttype = 0;
FOREACH_MAGICTYPE(mtype)
{
typelist[mtype] = glb_magictypedefs[mtype].name;
}
typelist[NUM_MAGICTYPES] = 0;
select = gfx_selectmenu(5, 3, typelist, aorb, lasttype);
if (select < 0 || aorb)
break;
mtype = (MAGICTYPE_NAMES) select;
lasttype = select;
int numtype[NUM_MAGICTYPES] =
{
0,
NUM_POTIONS,
NUM_SCROLLS,
NUM_RINGS,
NUM_HELMS,
NUM_WANDS,
NUM_AMULETS,
NUM_SPELLBOOKS,
NUM_BOOTSS,
NUM_STAFFS
};
const char *itemlist[NUM_ITEMS+1];
int i = 0;
for (i = 0; i < numtype[mtype]; i++)
{
switch (mtype)
{
case MAGICTYPE_NONE:
case NUM_MAGICTYPES:
UT_ASSERT(!"Illegal magic type");
itemlist[i] = "illegal";
break;
case MAGICTYPE_POTION:
itemlist[i] = glb_potiondefs[i].name;
break;
case MAGICTYPE_SCROLL:
itemlist[i] = glb_scrolldefs[i].name;
break;
case MAGICTYPE_RING:
itemlist[i] = glb_ringdefs[i].name;
break;
case MAGICTYPE_HELM:
itemlist[i] = glb_helmdefs[i].name;
break;
case MAGICTYPE_WAND:
itemlist[i] = glb_wanddefs[i].name;
break;
case MAGICTYPE_AMULET:
itemlist[i] = glb_amuletdefs[i].name;
break;
case MAGICTYPE_SPELLBOOK:
itemlist[i] = glb_spellbookdefs[i].name;
break;
case MAGICTYPE_BOOTS:
itemlist[i] = glb_bootsdefs[i].name;
break;
case MAGICTYPE_STAFF:
itemlist[i] = glb_staffdefs[i].name;
break;
}
}
itemlist[i] = 0;
// Nothing in the list, nothing to do.
if (!i)
break;
static int lastitemchoice = 0;
select = gfx_selectmenu(5, 3, itemlist, aorb, lastitemchoice);
if (select < 0 || aorb)
break;
lastitemchoice = select;
{
// Acquire the item...
ITEM *wish;
wish = ITEM::createMagicItem(mtype, select);
avatar->formatAndReport("%U <wish> for %IU.", wish);
if (!avatar->acquireItem(wish))
{
avatar->formatAndReport("%IU <I:fall> at %r feet.", wish);
glbCurLevel->acquireItem(wish, avatar->getX(), avatar->getY(), avatar);
}
}
didsomething = true;
break;
}
case 2: // Monster...
{
const char *moblist[NUM_MOBS+1];
MOB_NAMES mobname;
static int lastmob = 0;
int tx, ty;
FOREACH_MOB(mobname)
{
moblist[mobname] = glb_mobdefs[mobname].name;
}
moblist[NUM_MOBS] = 0;
select = gfx_selectmenu(5, 3, moblist, aorb, lastmob);
if (select < 0 || aorb)
break;
mobname = (MOB_NAMES) select;
lastmob = select;
for (int y = 3; y < 19; y++)
gfx_cleartextline(y);
// Ask for creation location.
avatar->formatAndReport("Create where?");
tx = avatar->getX();
ty = avatar->getY();
if (!gfx_selecttile(tx, ty))
break;
MOB *mob = MOB::create(mobname);
mob->move(tx, ty);
glbCurLevel->registerMob(mob);
avatar->formatAndReport("%U <wish> for %MU.", mob);
didsomething = true;
break;
}
case 3: // Spell...
{
const char *spelllist[NUM_SPELLS+1];
SPELL_NAMES spellname;
static int lastspell = 0;
FOREACH_SPELL(spellname)
{
spelllist[spellname] = glb_spelldefs[spellname].name;
}
spelllist[NUM_SPELLS] = 0;
select = gfx_selectmenu(5, 3, spelllist, aorb, lastspell);
if (select < 0 || aorb)
break;
spellname = (SPELL_NAMES) select;
lastspell = select;
for (int y = 3; y < 19; y++)
gfx_cleartextline(y);
avatar->formatAndReport("%U <wish> for %B1.", spelllist[spellname]);
if (!avatar->canCastSpell(spellname))
{
// Make sure this is a "free" spell and we don't run
// out of spell points..
avatar->incrementMagicDie(1);
// Likewise, verify we have sufficient mana for it.
avatar->incrementMaxMP(glb_spelldefs[spellname].mpcost);
avatar->learnSpell(spellname);
didsomething = true;
}
else
{
avatar->formatAndReport("%U already know %B1.", spelllist[spellname]);
}
break;
}
case 4: // Skill...
{
const char *skilllist[NUM_SKILLS+1];
SKILL_NAMES skillname;
static int lastskill = 0;
FOREACH_SKILL(skillname)
{
skilllist[skillname] = glb_skilldefs[skillname].name;
}
skilllist[NUM_SKILLS] = 0;
select = gfx_selectmenu(5, 3, skilllist, aorb, lastskill);
if (select < 0 || aorb)
break;
skillname = (SKILL_NAMES) select;
lastskill = select;
for (int y = 3; y < 19; y++)
gfx_cleartextline(y);
avatar->formatAndReport("%U <wish> for %B1.", skilllist[skillname]);
if (!avatar->hasSkill(skillname))
{
avatar->incrementHitDie(1);
avatar->learnSkill(skillname);
didsomething = true;
}
else
{
avatar->formatAndReport("%U already know %B1.", skilllist[skillname]);
}
break;
}
case 5: // Experience
{
const char *xpmenu[] =
{
"250 XP",
"1 Level",
"10 Levels",
"Ascension Kit",
0
};
int xpval[] =
{
250,
1000,
10000,
-1
};
select = gfx_selectmenu(5, 3, xpmenu, aorb);
if (select < 0 || aorb)
break;
// GAining exp triggers level up warnings
for (int y = 3; y < 19; y++)
gfx_cleartextline(y);
avatar->formatAndReport("You gain experience...");
if (xpval[select] < 0)
avatar->buildAscensionKit();
else
avatar->receiveExp(xpval[select]);
didsomething = true;
break;
}
case 6: // Befriend gods
{
const char *godlist[NUM_GODS+1];
GOD_NAMES godname;
FOREACH_GOD(godname)
{
godlist[godname] = glb_goddefs[godname].name;
}
godlist[NUM_GODS] = 0;
select = gfx_selectmenu(5, 3, godlist, aorb);
if (select < 0 || aorb)
break;
godname = (GOD_NAMES) select;
avatar->formatAndReport("%U <win> the favour of %B1.", godlist[godname]);
avatar->pietyGrant(godname, 100);
didsomething = true;
break;
}
case 7: // Level teleport
{
char buf[50];
int lvl;
{
for (int y = 3; y < 19; y++)
gfx_cleartextline(y);
}
gfx_printtext(0, 4, "Level? ");
input_getline(buf, 3, 7, 4, 23, 8);
{
int y;
for (y = 0; y < 20; y++)
gfx_cleartextline(y);
}
if (!isdigit(buf[0]))
break;
// It is suspected that there exist platforms where
// atoi does not work. Sigh.
// What is more depressing that this has taken me
// three tries to get right.
lvl = 0;
int off = 0;
while (isdigit(buf[off]))
{
lvl *= 10;
lvl += buf[off] - '0';
off++;
}
// Our depth is a s8 so can't support greater than 127,
// we just cap at 100 (anyways, the game proper stops at 25
// so not much point for the higher options)
// This avoids infinite loops if someone asks for a really deep
// level.
if (lvl > 100)
lvl = 100;
// Move to level lvl!
MAP *newlevel;
glbCurLevel->unregisterMob(avatar);
newlevel = glbCurLevel;
while (newlevel && newlevel->getDepth() != lvl)
{
if (lvl < newlevel->getDepth())
newlevel = newlevel->getMapUp();
else
newlevel = newlevel->getMapDown();
}
if (newlevel)
{
MAP::changeCurrentLevel(newlevel);
}
int x, y;
if (!glbCurLevel->findTile(SQUARE_LADDERUP, x, y))
{
if (!glbCurLevel->findTile(SQUARE_LADDERDOWN, x, y))
{
if (!glbCurLevel->findTile(SQUARE_DIMDOOR, x, y))
{
// Default paranoid position.
x = y = 15;
}
}
}
// Find a tile where we don't sit on an existing mob.
// If walk/swim fail, just go on top of existing mob.
if (!glbCurLevel->findCloseTile(x, y, MOVE_WALK))
glbCurLevel->findCloseTile(x, y, MOVE_WALK);
avatar->move(x, y, true);
glbCurLevel->registerMob(avatar);
didsomething = true;
break;
}
case 8: // Create a room
{
const char *roomlist[NUM_ALLROOMDEFS+1];
int rnum;
int tx, ty;
static int lastroom = 0;
for (rnum = 0; rnum < NUM_ALLROOMDEFS; rnum++)
{
roomlist[rnum] = glb_allroomdefs[rnum]->name;
}
roomlist[rnum] = 0;
select = gfx_selectmenu(5, 3, roomlist, aorb, lastroom);
if (select < 0 || aorb)
break;
lastroom = select;
rnum = select;
for (int y = 3; y < 19; y++)
gfx_cleartextline(y);
avatar->formatAndReport("Create where?");
tx = avatar->getX();
ty = avatar->getY();
if (!gfx_selecttile(tx, ty))
break;
avatar->formatAndReport("%U <wish> for %B1.", roomlist[rnum]);
ROOM room;
glbCurLevel->buildRandomRoomFromDefinition(room, glb_allroomdefs[rnum]);
// Center on desired tx/ty
int dx, dy;
dx = tx - (room.l.x + room.h.x)/2;
if (room.l.x + dx < 1)
dx = 1 - room.l.x;
if (room.h.x + dx > MAP_WIDTH - 2)
dx = MAP_WIDTH-2 - room.h.x;
dy = ty - (room.l.y + room.h.y)/2;
if (room.l.y + dy < 1)
dy = 1 - room.l.y;
if (room.h.y + dy > MAP_HEIGHT - 2)
dy = MAP_HEIGHT-2 - room.h.y;
room.l.x += dx;
room.h.x += dx;
room.l.y += dy;
room.h.y += dy;
glbCurLevel->drawRoom(room, false, false, false);
glbCurLevel->populateRoom(room);
didsomething = true;
break;
}