-
Notifications
You must be signed in to change notification settings - Fork 9
/
minima.p8
1986 lines (1897 loc) · 108 KB
/
minima.p8
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
pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
-- minima
-- by feneric
-- a function for logging to an output log file.
-- function logit(entry)
-- printh(entry,'minima.out')
-- end
-- register json context here
_tok={
['true']=true,
['false']=false}
_g={}
-- json parser
-- from: https://gist.github.com/tylerneylon/59f4bcf316be525b30ab
table_delims={['{']="}",['[']="]"}
function match(s,tokens)
for i=1,#tokens do
if(s==sub(tokens,i,i)) return true
end
return false
end
function skip_delim(wrkstr, pos, delim, err_if_missing)
if sub(wrkstr,pos,pos)!=delim then
-- if(err_if_missing) assert'delimiter missing'
return pos,false
end
return pos+1,true
end
function parse_str_val(wrkstr, pos, val)
val=val or ''
-- if pos>#wrkstr then
-- assert'end of input found while parsing string.'
-- end
local c=sub(wrkstr,pos,pos)
if(c=='"') return _g[val] or val,pos+1
return parse_str_val(wrkstr,pos+1,val..c)
end
function parse_num_val(wrkstr,pos,val)
val=val or ''
-- if pos>#wrkstr then
-- assert'end of input found while parsing string.'
-- end
local c=sub(wrkstr,pos,pos)
-- support base 10, 16 and 2 numbers
if(not match(c,"-xb0123456789abcdef.")) return tonum(val),pos
return parse_num_val(wrkstr,pos+1,val..c)
end
-- public values and functions.
function json_parse(wrkstr, pos, end_delim)
pos=pos or 1
-- if(pos>#wrkstr) assert'reached unexpected end of input.'
local first=sub(wrkstr,pos,pos)
if match(first,"{[") then
local obj,key,delim_found={},true,true
pos+=1
while true do
key,pos=json_parse(wrkstr, pos, table_delims[first])
if(key==nil) return obj,pos
-- if not delim_found then assert'comma missing between table items.' end
if first=="{" then
pos=skip_delim(wrkstr,pos,':',true) -- true -> error if missing.
obj[key],pos=json_parse(wrkstr,pos)
else
add(obj,key)
end
pos,delim_found=skip_delim(wrkstr, pos, ',')
end
elseif first=='"' then
-- parse a string (or a reference to a global object)
return parse_str_val(wrkstr,pos+1)
elseif match(first,"-0123456789") then
-- parse a number.
return parse_num_val(wrkstr, pos)
elseif first==end_delim then -- end of an object or array.
return nil,pos+1
else -- parse true, false
for lit_str,lit_val in pairs(_tok) do
local lit_end=pos+#lit_str-1
if sub(wrkstr,pos,lit_end)==lit_str then return lit_val,lit_end+1 end
end
-- assert'invalid json token'
end
end
-- initialization data
fullheight,fullwidth,halfheight,halfwidth=11,13,5,6
-- set up the various messages
winmsg="\n\n\n\n\n\n congratulations, you've won!\n\n\n\n\n\n\n\n\n\n press p to get game menu,\n anything else to continue and\n explore a bit more."
losemsg="\n\n\n\n\n\n you've been killed!\n you lose!\n\n\n\n\n\n\n\n\n\n\n\n press p to get game menu"
helpmsg="minima commands:\n\na: attack\nc: cast spell\nd: dialog, talk, buy\ne: enter, board, mount, climb,\n descend\np: pause, save, load, help\nf: fountain drink; force chest;\n flame torch\ns: sit & wait\nw: wearing & wielding\nx: examine, look (repeat to\n search)\n\nfor commands with options (like\ncasting or buying) use the first\ncharacter from the list, or\nanything else to cancel."
msg=helpmsg
-- anyobj is our root object. all others inherit from it to
-- save space and reduce redundancy.
anyobj={f=1,mva=0,nm=0,mvp=0,hd=0,ch=0,z=0}
function makemetaobj(base,basetype)
return setmetatable(base,{__index=base.ot or basetype})
end
-- the types of terrain that exist in the game. each is
-- given a name and a list of allowed monster types.
terrains={"plains","bare ground","tundra","scrub","swamp","forest","foothills","mountains","tall mountain","volcano","volcano","water","water","deep water","deep water","brick","brick road","brick","mismatched brick","stone","stone","road","barred window","window","bridge","ladder down","ladder up","door","locked door","open door","sign","shrine","dungeon","castle","tower","town","village","ankh"}
--terrains=json_parse('["plains","bare ground","tundra","scrub","swamp","forest","foothills","mountains","tall mountain","volcano","volcano","water","water","deep water","deep water","brick","brick road","brick","mismatched brick","stone","stone","road","barred window","window","bridge","ladder down","ladder up","door","locked door","open door","sign","shrine","dungeon","castle","tower","town","village","ankh"]')
-- counter terrain types are special as they can be talked
-- over (essential for purchasing). there are a lot of them
-- as all the letters are represented.
for num=1,29 do
add(terrains,"counter")
end
terrainmonsters={}
for num=1,38 do
add(terrainmonsters,{})
end
-- basetypes are the objects we mean to use to make objects.
-- they inherit (often indirectly) from our root object.
basetypes=json_parse('[{"t":[1,2,3,4,5,6,7,8,17,18,22,25,26,27,30,31,33,35],"gp":10,"hp":10,"ch":1,"mva":1,"hos":1,"ar":1,"exp":2,"dex":8,"dmg":13},{"mxx":128,"mn":0,"fri":1,"mxy":64,"mnx":80,"mxm":0,"newm":0,"mny":0},{"sz":1,"sy":1,"sx":1,"mnx":1,"sf":1,"dg":1,"c":{},"mxm":27,"mn":0,"ss":17,"mxy":9,"fri":false,"newm":25,"mxx":9,"mny":1},{"i":38,"ia":38,"n":"ankh","d":["yes, ankhs can talk.","shrines make good landmarks."]},{"ia":70,"p":1,"i":70,"f":2,"n":"ship","fm":1},{"ia":92,"shm":-2,"i":92,"szm":11,"n":"chest","p":1},{"iseq":12,"n":"fountain","fi":1,"i":39,"szm":14,"shm":-2,"p":1},{"ia":27,"shm":12,"i":27,"szm":20,"n":"ladder up","p":1},{"ia":26,"shm":-3,"i":26,"szm":20,"n":"ladder down","p":1},{"hos":false,"i":80,"exp":1,"gp":5,"ar":0},{"n":"orc","ch":8,"d":["urg!","grar!"]},{"dmg":14,"gp":5,"ch":5,"dex":6},{"dex":10,"gp":0,"ch":3,"ar":0},{"dex":9,"n":"fighter","cs":[{},[[1,12],[14,2],[15,4]]],"d":["check out these pecs!","i\'m jacked!"],"i":82,"hp":12,"dmg":20,"ar":3},{"ar":12,"n":"guard","cs":[{},[[15,4]]],"d":["behave yourself.","i protect good citizens."],"i":90,"hp":85,"dmg":60,"mva":0},{"n":"merchant","fi":1,"d":["consume!","stuff makes you happy!"],"i":75,"cs":[{},[[1,4],[4,15],[6,1],[14,13]],[[1,4],[6,5],[14,10]],[[1,4],[4,15],[6,1],[14,3]]]},{"n":"lady","fi":1,"d":["pardon me.","well i never."],"i":81,"cs":[{},[[2,9],[4,15],[13,14]],[[2,10],[4,15],[13,9]],[[2,11],[13,3]]]},{"i":76,"n":"shepherd","cs":[{},[[6,5],[15,4]],[[6,5]],[[15,4]]],"d":["i like sheep.","the open air is nice."]},{"i":78,"n":"jester","dex":12,"d":["ho ho ho!","ha ha ha!"]},{"i":84,"n":"mage","ac":[[9,6],[8,13],[10,12]],"d":["a mage is always on time.","brain over brawn."]},{"cs":[{},[[9,11],[1,3],[15,4]],[[9,11],[1,3]],[[15,4]]],"n":"ranger","fi":1,"d":["i travel the land.","my home is the range."]},{"hos":1,"n":"villain","d":["stand and deliver!","you shall die!"],"ar":1,"exp":5,"gp":15},{"mch":"food","n":"grocer"},{"mch":"armor","n":"armorer"},{"mch":"weapons","n":"smith"},{"mch":"hospital","n":"medic"},{"mch":"guild","n":"guildkeeper"},{"mch":"bar","n":"barkeep"},{"i":96},{"n":"troll","exp":4,"i":102,"hp":15,"gp":10,"dmg":16},{"exp":3,"gp":8,"i":104,"hp":15,"dmg":14,"ns":["hobgoblin","bugbear"]},{"exp":1,"gp":5,"i":114,"hp":8,"dmg":10,"ns":["goblin","kobold"]},{"n":"ettin","fi":1,"exp":6,"i":118,"hp":20,"ch":1,"dmg":18},{"i":98,"n":"skeleton","gp":12},{"i":100,"hp":10,"ns":["zombie","wight","ghoul"]},{"d":["boooo!","feeear me!"],"fi":1,"t":[1,2,3,4,5,6,7,8,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,35],"i":123,"hp":15,"exp":7,"ns":["phantom","ghost","wraith"]},{"exp":10,"cs":[{},[[2,8],[15,4]]],"d":["i hex you!","a curse on you!"],"i":84,"dmg":18,"ac":[[9,6],[8,13],[10,12]],"ns":["warlock","necromancer","sorcerer"]},{"cs":[{},[[1,5],[8,2],[4,1],[2,12],[15,4]]],"dex":10,"i":88,"th":1,"ch":2,"ns":["rogue","bandit","cutpurse"]},{"exp":8,"cs":[{},[[1,5],[15,4]]],"d":["you shall die at my hands.","you are no match for me."],"i":86,"gp":10,"po":1,"ns":["ninja","assassin"]},{"n":"giant spider","exp":5,"i":106,"hp":18,"gp":8,"po":1},{"n":"giant rat","exp":2,"eat":1,"i":108,"hp":5,"po":1,"dmg":10},{"po":1,"exp":6,"t":[4,5,6,7],"i":112,"hp":20,"ch":1,"ns":["giant snake","serpent"]},{"n":"sea serpent","t":[5,12,13,14,15,25],"i":116,"hp":45,"exp":10},{"n":"megascorpion","fi":1,"exp":5,"i":125,"hp":12,"ch":1,"po":1},{"exp":2,"eat":1,"cs":[{},[[3,9],[11,10]],[[3,14],[11,15]]],"t":[17,22,23],"i":122,"gp":5,"fi":1,"ns":["slime","jelly","blob"]},{"exp":8,"t":[12,13,14,15],"i":94,"hp":50,"ch":2,"ns":["kraken","giant squid"]},{"n":"wisp","fi":1,"t":[4,5,6],"i":120,"exp":3},{"exp":8,"n":"pirate","cs":[[[6,5],[7,6]]],"t":[12,13,14,15],"i":70,"f":1,"fi":false,"fm":1},{"cs":[{},[[2,14],[1,4]]],"t":[17,22],"i":119,"exp":4,"fi":1,"ns":["gazer","beholder"]},{"fi":1,"ac":[[9,6],[8,13],[10,12]],"hp":50,"ns":["dragon","drake","wyvern"],"exp":17,"i":121,"gp":20,"dmg":28,"ar":7},{"t":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,22,25,26,27,30,31,33,35],"ac":[[9,10],[8,9],[10,7]],"hp":50,"ch":0.25,"ns":["daemon","devil"],"exp":15,"i":110,"gp":25,"dmg":23,"ar":3},{"th":1,"n":"mimic","exp":4,"t":[17,22],"i":92,"gp":12,"ch":0,"mva":0},{"fi":1,"t":[17,22],"gp":8,"hp":30,"ch":0,"mva":0,"n":"reaper","i":124,"exp":5,"ar":5}]')
-- give our base objects ns for convenience & efficiency.
shiptype=basetypes[5]
-- set our base objects base values. the latter portion is
-- our bestiary. it holds all the different monster types that can
-- be encountered in the game. it builds off of the basic types
-- already defined so most do not need many changes. actual
-- monsters in the game are instances of creatures found in the
-- bestiary.
for basetypenum=1,#basetypes do
local basetype
local objecttype=basetypes[basetypenum]
if basetypenum<10 then
basetype=anyobj
elseif basetypenum<14 then
basetype=basetypes[1]
elseif basetypenum<23 then
basetype=basetypes[10]
elseif basetypenum<28 then
basetype=basetypes[16]
elseif basetypenum<29 then
basetype=basetypes[17]
elseif basetypenum<35 then
basetype=basetypes[11]
elseif basetypenum<38 then
basetype=basetypes[12]
elseif basetypenum<41 then
basetype=basetypes[22]
elseif basetypenum<48 then
basetype=basetypes[13]
else
basetype=basetypes[1]
end
objecttype.id=basetypenum
makemetaobj(objecttype,basetype)
if basetypenum>28 then
for terrain in all(objecttype.t) do
add(terrainmonsters[terrain],objecttype)
end
end
end
-- check to see whether or not a desired purchase can
-- be made.
function checkpurchase(prompt,checkfunc,purchasefunc)
update_lines(prompt)
cmd=yield()
desireditem=checkfunc(cmd)
return desireditem and purchasefunc(desireditem) or desireditem==false and "you cannot afford that." or "no sale."
end
function purchasedetail(desireditem)
if desireditem and desireditem.p then
return hero.gp>=desireditem.p and desireditem
else
return nil
end
end
-- makes a purchase if all is in order.
function purchase(prompt,itemtype,attribute)
return checkpurchase(prompt,
function(cmd)
return purchasedetail(itemtype[cmd])
end,
function(desireditem)
if hero[attribute]>=desireditem.a then
return "that is not an upgrade."
else
hero.gp-=desireditem.p
hero[attribute]=desireditem.a
return "the "..desireditem.n.." is yours."
end
end
)
end
-- a table of functions to perform the different merchant
-- operations. while there is a lot in common between them,
-- there are a lot of differences, too.
shop={
food=function()
return checkpurchase({"$15 for 25 food; a\80\80\82\79\86\69? "},
function(cmd)
if cmd=='a' then
return hero.gp>=15
else
return nil
end
end,
function()
hero.gp-=15
hero.fd=not_over_32767(hero.fd+25)
return "you got more food."
end
)
end,
armor=function()
return purchase({"buy \131cloth $12, \139leather $99,","\145chain $300, or \148plate $950: "},armors,'ar')
end,
weapons=function()
return purchase({"buy d\65\71\71\69\82 $8, c\76\85\66 $40,","a\88\69 $75, or s\87\79\82\68 $150: "},weapons,'dmg')
end,
hospital=function()
return checkpurchase({"choose m\69\68\73\67 ($8), c\85\82\69 ($10),","or s\65\86\73\79\82 ($25): "},
function(cmd)
desiredspell=spells[cmd]
return purchasedetail(desiredspell)
end,
function(desiredspell)
sfx(3)
hero.gp-=desiredspell.p
if desiredspell.n=='cure' then
-- perform cure
hero.st=band(hero.st,14)
else
-- perform healing
increasehp(desiredspell.a)
end
return desiredspell.n.." is cast!"
end
)
end,
bar=function()
return checkpurchase({"$5 per drink; a\80\80\82\79\86\69? "},
function(cmd)
if cmd=='a' then
return hero.gp>=5
else
return nil
end
end,
function()
hero.gp-=5
rumors=json_parse('["faxon has many guards.","faxon is very powerful.","fountains respect injury.","dungeon fountains rule.","faxon fears a magic sword.","watch for secret doors.","fighters can bust doors.","good mages can zap doors."]')
update_lines{"while socializing, you hear:"}
return '"'..rumors[flr(rnd(8)+1)]..'"'
end
)
end,
guild=function()
return checkpurchase({"5 \139torches $12 or a \145key $23: "},
function(cmd)
local desiredtool=tools[cmd]
return purchasedetail(desiredtool)
end,
function(desireditem)
hero.gp-=desireditem.p
hero[desireditem.attr]+=desireditem.q
return "you purchase "..desireditem.n
end
)
end
}
-- add numerical references to names by amounts
function makenameforamount(itemtype)
nameforamount={}
for itemcmd,item in pairs(itemtype) do
nameforamount[item.a]=item.n
end
nameforamount[0]='none'
return nameforamount
end
-- armor definitions
armors=json_parse('{"south":{"n":"cloth","a":8,"p":12},"west":{"n":"leather","a":23,"p":99},"east":{"n":"chain","a":40,"p":300},"north":{"n":"plate","a":70,"p":950}}')
armornames=makenameforamount(armors)
-- weapon definitions
weapons=json_parse('{"d":{"n":"dagger","a":8,"p":8},"c":{"n":"club","a":12,"p":40},"a":{"n":"axe","a":18,"p":75},"s":{"n":"sword","a":30,"p":150},"t":{"n":"magic swd","a":40}}')
weaponnames=makenameforamount(weapons)
-- spell definitions
spells=json_parse('{"a":{"n":"attack","c":3,"a":1},"x":{"n":"medic","c":5,"a":1,"p":8},"c":{"n":"cure","c":7,"p":10},"w":{"n":"wound","c":11,"a":5},"e":{"n":"exit","c":13},"s":{"n":"savior","c":17,"a":6,"p":25}}')
-- tool definitions
tools=json_parse('{"west":{"n":"5 torches","attr":"ts","p":12,"q":5},"east":{"n":"a key","attr":"keys","p":23,"q":1}}')
function setmap()
local songstrt=curmap.ss
curmap=maps[mapnum]
contents=curmap.con
if(songstrt and curmap.ss)music(curmap.ss)
hero.hd=0
end
function initobjs()
-- the maps structure holds information about all of the regular
-- places in the game, dungeons as well as towns.
maps=json_parse('[{"sy":23,"mxx":105,"ex":13,"sx":92,"n":"saugus","signs":[{"x":92,"msg":"welcome to saugus!","y":19}],"mxy":24,"c":[{"x":89,"id":15,"y":21},{"x":84,"id":26,"y":9},{"x":95,"id":24,"y":3},{"x":97,"id":23,"y":13},{"x":82,"id":14,"y":21},{"x":101,"id":21,"y":5},{"x":84,"d":["the secret room is key.","the way must be clear."],"id":20,"y":5},{"x":103,"d":["faxon is in a tower.","volcanoes mark it."],"id":21,"y":18},{"x":85,"d":["poynter has a ship.","poynter is in lynn."],"id":17,"y":16},{"x":95,"id":15,"y":21}],"i":[{"x":84,"id":4,"y":4}],"ey":4},{"sy":23,"ex":17,"sx":116,"n":"lynn","signs":[{"x":125,"msg":"marina for members only.","y":9}],"mxy":24,"c":[{"x":118,"id":15,"y":22},{"x":106,"id":25,"y":1},{"x":118,"id":28,"y":2},{"x":107,"id":23,"y":9},{"x":106,"id":19,"y":16},{"x":122,"id":26,"y":12},{"x":105,"d":["i\'ve seen faxon\'s tower.","south of the eastern shrine."],"id":14,"y":4},{"x":106,"d":["griswold knows dungeons.","griswold is in salem."],"id":17,"y":7},{"x":119,"d":["i\'m rich! i have a yacht!","ho ho! i\'m the best!"],"id":16,"y":6},{"x":114,"id":15,"y":22}],"i":[{"x":125,"id":5,"y":5}],"mnx":104,"ey":4},{"sy":54,"mxx":112,"ex":45,"sx":96,"n":"boston","mxy":56,"c":[{"x":94,"id":15,"y":49},{"x":103,"id":25,"y":39},{"x":92,"id":24,"y":30},{"x":88,"id":23,"y":38},{"x":100,"id":26,"y":30},{"x":96,"id":19,"y":44},{"x":83,"d":["zanders has good tools.","be prepared!"],"id":14,"y":27},{"x":81,"id":16,"y":44},{"x":104,"d":["each shrine has a caretaker.","seek their wisdom."],"id":20,"y":26},{"x":110,"d":["i\'ve seen the magic sword.","search south of the shrine."],"id":16,"y":40},{"x":105,"mva":1,"id":15,"y":35},{"x":98,"id":15,"y":49}],"i":[{"x":96,"id":7,"y":40}],"mny":24,"ey":19},{"sy":62,"ex":7,"sx":119,"n":"salem","i":[{"x":116,"id":4,"y":53}],"c":[{"x":118,"id":15,"y":63},{"x":125,"id":27,"y":44},{"x":114,"id":28,"y":44},{"x":122,"id":23,"y":51},{"x":118,"id":17,"y":58},{"x":113,"d":["faxon is a blight.","daemons serve faxon."],"id":21,"y":50},{"x":123,"d":["increase stats in dungeons!","only severe injuries work."],"id":14,"y":57},{"x":120,"id":15,"y":63}],"mny":43,"mnx":112,"ey":36},{"c":[{"x":93,"id":23,"y":57},{"x":100,"id":28,"y":57},{"x":91,"d":["even faxon has fears.","lalla knows who to see."],"id":14,"y":60},{"x":82,"id":18,"y":57},{"x":102,"d":["gilly is in boston.","gilly knows of the sword."],"id":18,"y":63}],"sy":59,"mxx":103,"ex":27,"mny":56,"sx":82,"n":"great misery","ey":35},{"sy":62,"mxx":112,"ex":1,"sx":107,"n":"western shrine","c":[{"x":107,"d":["magic serves good or evil.","swords cut both ways."],"id":20,"y":59}],"mny":56,"mnx":103,"ey":28},{"sy":62,"mxx":112,"ex":49,"sx":107,"n":"eastern shrine","c":[{"x":107,"d":["some fountains have secrets.","know when to be humble."],"id":18,"y":59}],"mny":56,"mnx":103,"ey":6},{"sy":41,"newm":35,"ex":56,"sx":120,"n":"the dark tower","c":[{"x":119,"id":53,"y":41},{"x":126,"id":53,"y":40},{"x":123,"id":53,"y":38},{"x":113,"id":53,"y":40},{"x":121,"id":52,"y":37},{"x":119,"id":52,"y":38},{"x":120,"id":45,"y":34},{"x":118,"id":45,"y":35},{"ar":25,"dmg":50,"hp":255,"y":30,"x":118,"i":126,"id":50,"pn":"faxon"}],"i":[{"tm":12,"ty":8,"y":41,"x":117,"tz":3,"id":8,"tx":3},{"x":119,"id":6,"y":37},{"x":119,"id":6,"y":39},{"x":120,"id":6,"y":37},{"x":120,"id":6,"y":38},{"x":120,"id":6,"y":39},{"x":121,"id":6,"y":38},{"x":121,"id":6,"y":39}],"ss":17,"mxm":23,"mxy":43,"fri":false,"mny":24,"mnx":112,"ey":44},{"l":[[0,16382,768,12336,16380,13056,13308,192],[0,-13107,816,12336,15612,768,16332,704],[-32768,-3316,1020,12300,13116,13056,-3076,448],[29488,13116,0,-3073,0,-3124,780,13116]],"sy":8,"c":[{"x":8,"z":4,"id":50,"y":5},{"x":3,"z":4,"id":52,"y":1},{"x":1,"z":4,"id":52,"y":5},{"x":5,"z":4,"id":52,"y":1},{"x":3,"z":4,"id":53,"y":3}],"ex":4,"attr":"int","i":[{"x":1,"z":1,"id":8,"y":8},{"x":8,"z":2,"id":8,"y":2},{"x":4,"z":3,"id":8,"y":8},{"x":1,"z":4,"id":8,"y":1},{"x":1,"z":4,"id":6,"y":8},{"x":7,"z":4,"id":6,"y":1},{"x":3,"z":4,"id":6,"y":8},{"x":5,"z":4,"id":6,"y":8},{"x":8,"z":4,"id":6,"y":8},{"x":6,"z":3,"id":7,"y":8}],"n":"nibiru","ey":11},{"l":[[824,16188,768,13296,-4036,13056,13308,768],[13060,13116,12,16332,12540,15360,15311,768],[768,13116,-20432,-196,48,16140,14140,816],[0,-13108,19468,-13108,192,-13108,3084,-13108]],"c":[{"x":3,"z":4,"id":50,"y":5},{"x":1,"z":4,"id":52,"y":5},{"x":7,"z":4,"id":52,"y":5},{"x":5,"z":4,"id":53,"y":3},{"x":5,"z":4,"id":53,"y":7}],"ex":32,"attr":"str","i":[{"x":1,"z":1,"id":8,"y":1},{"x":7,"z":2,"id":8,"y":1},{"x":3,"z":3,"id":8,"y":7},{"x":1,"z":4,"id":8,"y":3},{"x":1,"z":4,"id":6,"y":1},{"x":1,"z":4,"id":6,"y":8},{"x":1,"z":4,"id":6,"y":7},{"x":2,"z":4,"id":6,"y":8},{"x":8,"z":4,"id":6,"y":8},{"x":7,"z":3,"id":7,"y":5}],"n":"purgatory","ey":5},{"l":[[768,16304,1020,13056,13299,12288,-4,0],[768,13180,12303,16382,252,15360,13263,12288],[768,13116,12348,13105,13119,13068,13116,512],[0,16188,12300,13260,12300,12300,16380,256]],"c":[{"x":3,"z":4,"id":50,"y":1},{"x":4,"z":4,"id":52,"y":5},{"x":5,"z":4,"id":52,"y":2},{"x":3,"z":4,"id":53,"y":4},{"x":6,"z":4,"id":53,"y":4}],"ex":33,"attr":"dex","i":[{"x":1,"z":1,"id":8,"y":1},{"x":5,"z":2,"id":8,"y":2},{"x":8,"z":3,"id":8,"y":4},{"x":4,"z":4,"id":8,"y":8},{"x":5,"z":4,"id":6,"y":5},{"x":3,"z":4,"id":6,"y":6},{"x":4,"z":4,"id":6,"y":6},{"x":5,"z":4,"id":6,"y":6},{"x":6,"z":4,"id":6,"y":6},{"x":6,"z":3,"id":7,"y":6}],"n":"sheol","ey":58},{"sz":3,"c":[{"x":4,"z":1,"id":51,"y":6},{"x":4,"z":2,"id":51,"y":7},{"x":1,"z":3,"id":51,"y":7},{"x":6,"z":3,"id":53,"y":8},{"x":8,"z":3,"id":53,"y":4},{"x":3,"z":3,"id":53,"y":1},{"x":6,"z":2,"id":53,"y":6},{"x":6,"z":1,"id":53,"y":8}],"ex":124,"sx":8,"n":"the upper levels","l":[[192,-17202,-817,204,16332,3276,204,3072],[192,31949,16323,14576,15555,3276,15566,192],[192,-13105,3264,13564,16320,207,13261,15104]],"mn":8,"i":[{"x":8,"z":3,"id":9,"y":1},{"tz":0,"tm":8,"z":3,"y":8,"x":3,"ty":41,"id":9,"tx":117},{"x":8,"z":3,"id":8,"y":7},{"x":3,"z":3,"id":8,"y":4},{"x":1,"z":2,"id":8,"y":2},{"x":8,"z":2,"id":8,"y":2}],"ey":26}]')
-- map 0 is special; it's the world map, the overview map.
maps[0]=json_parse('{"n":"world","mnx":0,"mny":0,"mxx":80,"mxy":64,"wrap":1,"newm":10,"mxm":12,"fri":false,"ss":0}')
-- the creatures structure holds the live copy saying which
-- creatures (both human and monster) are where in the world.
-- individually they are instances of bestiary objects or
-- occupation type objects.
creatures={}
-- perform the per-map data structure initializations.
for mapnum=0,#maps do
local maptype
curmap=maps[mapnum]
if mapnum>0 then
if curmap.l then
maptype=basetypes[3]
else
maptype=basetypes[2]
end
makemetaobj(curmap,maptype)
end
curmap.w,curmap.h=curmap.mxx-curmap.mnx,curmap.mxy-curmap.mny
creatures[mapnum],curmap.con={},{}
for num=curmap.mnx-1,curmap.mxx+1 do
curmap.con[num]={}
for inner=curmap.mny-1,curmap.mxy+1 do
curmap.con[num][inner]={}
end
end
for item in all(curmap.i) do
item.ot,xcoord,ycoord,zcoord=basetypes[item.id],item.x,item.y,item.z or 0
curmap.con[xcoord][ycoord][zcoord]=makemetaobj(item)
-- automatically make a corresponding ladder down for every ladder up
if item.ot.n=='ladder up' and curmap.dg then
zcoord-=1
curmap.con[xcoord][ycoord][zcoord]=makemetaobj{ot=basetypes[9]}
end
end
for creature in all(curmap.c) do
creature.mn=mapnum
creature.ot=basetypes[creature.id]
definemonster(creature)
end
end
-- the hero is the player character. although human, it has
-- enough differences that there is no advantage to inheriting
-- the human type.
hero=json_parse('{"i":0,"ar":0,"dmg":0,"x":7,"y":7,"z":0,"exp":0,"lvl":0,"str":8,"int":8,"dex":8,"st":0,"hd":0,"f":0,"gp":20,"fd":25,"mvp":0,"mp":8,"hp":24,"keys":0,"ts":5,"lit":0}')
hero.color=rnd(10)>6 and 4 or 15
-- make the map info global for efficiency
mapnum=0
setmap()
-- creature 0 is the maelstrom and not really a creature at all,
-- although it shares most creature behaviors.
creatures[0]={}
maelstrom=makemetaobj(json_parse('{"i":69,"iseq":23,"n":"maelstrom","t":[12,13,14,15],"mva":1,"x":13,"y":61}'),anyobj)
creatures[0][0]=maelstrom
contents[13][61][0]=maelstrom
turn=0
turnmade=false
cycle=0
_update=world_update
_draw=world_draw
draw_state=world_draw
end
-- the lines list holds the text output displayed on the screen.
lines={"","","","",">"}
numoflines=5
curline=numoflines
-- initialization routines
function _init()
initobjs()
menuitem(1,"list commands",listcommands)
menuitem(2,"save game",savegame)
menuitem(3,"load game",loadgame)
menuitem(4,"new game",run)
processinput=cocreate(inputprocessor)
cartdata("minima0")
end
function listcommands()
msg=helpmsg
if _draw~=msg_draw then
draw_state=_draw
_draw=msg_draw
end
end
attrlist={'ar','dmg','x','y','str','int','dex','st','i','color','f','keys','ts','exp','lvl','gp','fd','mp','hp'}
function combinevalues(highval,lowval)
return bor(shl(highval,8),lowval)
end
function savegame()
if mapnum~=0 then
update_lines{"sorry, only outside."}
else
local storagenum=0
for heroattr in all(attrlist) do
dset(storagenum,hero[heroattr])
storagenum+=1
end
for creaturenum=1,12 do
local creature=creatures[0][creaturenum]
if creature then
dset(storagenum,creature.id)
dset(storagenum+1,combinevalues(creature.x,creature.y))
else
dset(storagenum,0)
end
storagenum+=2
end
update_lines{"game saved."}
end
end
function separatevalues(comboval)
return lshr(band(comboval,0xff00),8),band(comboval,0xff)
end
function loadgame()
initobjs()
local storagenum=0
for heroattr in all(attrlist) do
hero[heroattr]=dget(storagenum)
storagenum+=1
end
for creaturenum=1,12 do
creatureid=dget(storagenum)
if creatureid~=0 then
creaturex,creaturey=separatevalues(dget(storagenum+1))
definemonster{ot=basetypes[creatureid],x=creaturex,y=creaturey,mn=0}
storagenum+=2
else
break
end
end
update_lines{"game loaded."}
end
buttons={
"west", "east", "north", "south",
"c", "x", "p", "?", "s", "f", "e", "d", "w", "a"
}
function getbutton(btnpress)
local bitcount=1
while btnpress>1 do
btnpress=lshr(btnpress,1)
bitcount+=1
end
return buttons[bitcount] or 'none'
end
function checkspell(cmd,extra)
local spell=spells[cmd]
if hero.mp>=spell.c then
hero.mp-=spell.c
update_lines{spell.n.." is cast! "..(extra or '')}
return true
else
update_lines{"not enough mp."}
return false
end
end
function exitdungeon(targx,targy,targmapnum)
hero.x,hero.y,hero.z,hero.f,hero.lit,mapnum=targx or curmap.ex,targy or curmap.ey,0,0,0,targmapnum or curmap.mn
setmap()
_draw=world_draw
end
function entermap(targmap,targmapnum,targx,targy,targz)
hero.x,hero.y=targx or targmap.sx,targy or targmap.sy
mapnum=targmapnum
setmap()
if targmap.dg then
_draw=dungeon_draw
hero.f,hero.z=targmap.sf,targmap.sz
end
return "entering "..targmap.n.."."
end
function inputprocessor(cmd)
while true do
local spots=calculatemoves(hero)
local xcoord,ycoord,zcoord=hero.x,hero.y,hero.z
local curobj=contents[xcoord][ycoord][zcoord]
local curobjname=curobj and curobj.n or nil
if _draw==msg_draw then
if cmd!='p' and hero.hp>0 then
_draw=draw_state
end
elseif cmd=='west' then
if curmap.dg then
hero.f-=1
if hero.f<1 then
hero.f=4
end
update_lines{"turn left"}
turnmade=true
else
hero.x,hero.y=checkmove(spots[2],ycoord,cmd)
end
elseif cmd=='east' then
if curmap.dg then
hero.f+=1
if hero.f>4 then
hero.f=1
end
update_lines{"turn right."}
turnmade=true
else
hero.x,hero.y=checkmove(spots[4],ycoord,cmd)
end
elseif cmd=='north' then
if curmap.dg then
hero.x,hero.y,hero.z=checkdungeonmove(1)
else
hero.x,hero.y=checkmove(xcoord,spots[1],cmd)
if hero.x==121 and hero.y==36 then
mset(116,41,22)
update_lines{"something clicks."}
end
end
elseif cmd=='south' then
if curmap.dg then
hero.x,hero.y,hero.z=checkdungeonmove(-1)
else
hero.x,hero.y=checkmove(xcoord,spots[3],cmd)
end
elseif cmd=='c' then
update_lines{"choose a\84\84\65\67\75, m\69\68\73\67, c\85\82\69,","w\79\85\78\68, e\88\73\84, s\65\86\73\79\82: "}
cmd=yield()
if cmd=='c' then
-- cast cure
if checkspell(cmd) then
sfx(3)
hero.st=band(hero.st,14)
end
elseif cmd=='x' or cmd=='s' then
-- cast healing
if checkspell(cmd) then
sfx(3)
increasehp(spells[cmd].a*hero.int)
end
elseif cmd=='e' then
-- cast exit dungeon
if not curmap.dg then
update_lines{'not in a dungeon.'}
elseif(checkspell(cmd)) then
sfx(4)
exitdungeon()
end
elseif cmd=='w' or cmd=='a' then
-- cast offensive spell
if checkspell(cmd,'dir:') then
local spelldamage=rnd(spells[cmd].a*hero.int)
if not getdirection(spots,attack_results,spelldamage) then
update_lines{'nothing to target.'}
end
end
else
update_lines{"cast: huh?"}
end
turnmade=true
elseif cmd=='x' then
update_lines{"examine dir:"}
if not getdirection(spots,look_results) then
if cmd=='x' then
local response={"search","you find nothing."}
signcontents=check_sign(xcoord,ycoord)
if signcontents then
response={"read sign",signcontents}
elseif xcoord==1 and ycoord==38 and hero.dmg<40 then
-- search response
response[2]="you find the magic sword!"
hero.dmg=40
end
update_lines(response)
else
update_lines{"examine: huh?"}
end
end
turnmade=true
elseif cmd=='p' then
update_lines{"pause / game menu"}
elseif cmd=='s' then
turnmade=true
update_lines{"sit and wait."}
elseif cmd=='f' then
turnmade=true
if curobjname=='fountain' then
sfx(3)
msg="healed!"
if curmap.dg and hero.hp<23 and hero[curmap.attr]<16 then
hero[curmap.attr]+=1
msg="you feel more capable!"
end
increasehp(100)
update_lines{msg}
elseif curobjname=='chest' then
local chestgold=ceil(rnd(100))
hero.gp+=chestgold
update_lines{"you find "..chestgold.." gp."}
contents[xcoord][ycoord][zcoord]=nil
elseif curmap.dg and hero.lit<1 then
if hero.ts>1 then
hero.lit=50
hero.ts-=1
update_lines{"the torch is now aflame."}
else
update_lines{"you have no torches."}
end
else
update_lines{"nothing here."}
end
elseif cmd=='e' then
turnmade=true
local msg="nothing to enter."
if curobjname=='ladder up' or curobjname=='ladder down' then
if curmap.dg then
if zcoord==curmap.sz and xcoord==curmap.sx and ycoord==curmap.sy then
msg="exiting "..curmap.n.."."
exitdungeon()
elseif curobjname=='ladder up' then
msg="ascending."
hero.z-=1
else
msg="descending."
hero.z+=1
end
end
if curobj.tm then
if curmap.dg and not maps[curobj.tm].dg then
exitdungeon(curobj.tx,curobj.ty,curobj.tm)
else
msg=entermap(maps[curobj.tm],curobj.tm,curobj.tx,curobj.ty,curobj.tz)
end
end
elseif hero.i>0 then
msg="exiting ship."
contents[xcoord][ycoord][zcoord]=makemetaobj{f=hero.f,ot=shiptype}
hero.i,hero.f=0,0
elseif curobjname=='ship' then
msg="boarding ship."
hero.i,hero.f=70,curobj.f
contents[xcoord][ycoord][zcoord]=nil
end
for loopmapnum=1,#maps do
local loopmap=maps[loopmapnum]
if mapnum==loopmap.mn and xcoord==loopmap.ex and ycoord==loopmap.ey then
msg=entermap(loopmap,loopmapnum)
end
end
update_lines{msg}
elseif cmd=='d' then
update_lines{"dialog dir:"}
if not getdirection(spots,dialog_results) then
update_lines{"dialog: huh?"}
end
turnmade=true
elseif cmd=='w' then
update_lines{
"worn: "..armornames[hero.ar].."; wield: "..weaponnames[hero.dmg],
hero.ts..' torches & '..hero.keys..' skeleton keys.'
}
elseif cmd=='a' then
if hero.i>0 then
update_lines{"fire dir:"}
else
update_lines{"attack dir:"}
end
if not getdirection(spots,attack_results) then
update_lines{"attack: huh?"}
end
turnmade=true
end
if hero.lit>1 then
hero.lit-=1
if hero.lit<1 then
update_lines{"the torch burnt out."}
end
end
if _draw==dungeon_draw and hero.lit<1 then
update_lines{"it's dark!"}
end
cmd=yield()
end
end
function getdirection(spots,resultfunc,magic,adir)
if curmap.dg then
adir=dngdirections[hero.f]
elseif not adir then
adir=yield()
end
if adir=='east' then
resultfunc(adir,spots[4],hero.y,magic)
elseif adir=='west' then
resultfunc(adir,spots[2],hero.y,magic)
elseif adir=='north' then
resultfunc(adir,hero.x,spots[1],magic)
elseif adir=='south' then
resultfunc(adir,hero.x,spots[3],magic)
else
return false
end
return true
end
function update_lines(msg)
local prompt="> "
for curmsg in all(msg) do
lines[curline]=prompt..curmsg
curline+=1
if(curline>numoflines)curline=1
prompt=""
end
lines[curline]=">"
end
function definemonster(monster)
local objtype,xcoord,ycoord,zcoord=monster.ot,monster.x,monster.y,monster.z or 0
monster.ot=objtype
makemetaobj(monster)
if monster.pn then
monster.n=monster.pn
elseif objtype.ns then
monster.n=objtype.ns[flr(rnd(#objtype.ns)+1)]
end
--if(objtype.is)monster.i=objtype.is[flr(rnd(#objtype.is)+1)]
if(objtype.cs)monster.co=objtype.cs[flr(rnd(#objtype.cs)+1)]
monster.iseq,monster.ia=flr(rnd(30)),false
add(creatures[monster.mn],monster)
maps[monster.mn].con[xcoord][ycoord][zcoord]=monster
return monster
end
function create_monster()
local monsterx,monstery,monsterz=flr(rnd(curmap.w))+curmap.mnx,flr(rnd(curmap.h))+curmap.mny,curmap.dg and flr(rnd(#curmap.l)+1) or 0
if contents[monsterx][monstery][monsterz] or monsterx==hero.x and monstery==hero.y and monsterz==hero.z then
-- don't create a monster where there already is one
monsterx=nil
end
if monsterx then
local monsterspot=mget(monsterx,monstery)
if curmap.dg then
monsterspot=getdungeonblk(monsterx,monstery,monsterz,1)
end
for objtype in all(terrainmonsters[monsterspot]) do
if rnd(200)<objtype.ch then
definemonster{ot=objtype,x=monsterx,y=monstery,z=monsterz,mn=mapnum}
break
end
end
end
end
function deducthp(damage)
hero.hp-=ceil(damage)
if hero.hp<=0 then
msg=losemsg
-- draw_state=_draw
_draw=msg_draw
end
end
function deductfood(amount)
hero.fd-=amount
if hero.fd<=0 then
sfx(1,3,8)
hero.fd=0
update_lines{"starving!"}
deducthp(1)
end
end
function not_over_32767(num)
return min(num,32767)
end
function increasexp(amount)
hero.exp=not_over_32767(hero.exp+amount)
if hero.exp>=hero.lvl^2*10 then
hero.lvl+=1
increasehp(12)
update_lines{"you went up a level!"}
end
end
function increasehp(amount)
hero.hp=not_over_32767(min(hero.hp+amount,hero.str*(hero.lvl+3)))
end
-- world updates
function checkdungeonmove(direction)
local newx,newy=hero.x,hero.y
local xcoord,ycoord,zcoord=hero.x,hero.y,hero.z
local cmd=direction>0 and 'advance' or 'retreat'
local item
local iscreature=false
if hero.f==1 then
newy-=direction
result=getdungeonblk(xcoord,newy,zcoord)
item=contents[xcoord][newy][zcoord]
elseif hero.f==2 then
newx+=direction
result=getdungeonblk(newx,ycoord,zcoord)
item=contents[newx][ycoord][zcoord]
elseif hero.f==3 then
newy+=direction
result=getdungeonblk(xcoord,newy,zcoord)
item=contents[xcoord][newy][zcoord]
else
newx-=direction
result=getdungeonblk(newx,ycoord,zcoord)
item=contents[newx][ycoord][zcoord]
end
if item and item.hp then
iscreature=true
end
if result==3 or iscreature then
blocked(cmd)
else
xcoord,ycoord=newx,newy
sfx(0)
update_lines{cmd}
end
turnmade=true
return xcoord,ycoord,zcoord
end
function checkexit(xcoord,ycoord)
if not curmap.wrap and(xcoord>=curmap.mxx or xcoord<curmap.mnx or ycoord>=curmap.mxy or ycoord<curmap.mny) then
update_lines{cmd,"exiting "..curmap.n.."."}
mapnum=0
return true
else
return false
end
end
function blocked(cmd)
sfx(5)
update_lines{cmd,"blocked!"}
return false
end
-- this is kind of weird; the ship icons ought to be rearranged
directions={north=1,west=2,south=3,east=4}
dngdirections={"north","east","south","west"}
function checkmove(xcoord,ycoord,cmd)
local movesuccess=true
local newloc=mget(xcoord,ycoord)
local movecost=band(fget(newloc),3)
local water=fget(newloc,2)
local impassable=fget(newloc,3)
local content=contents[xcoord][ycoord][hero.z]
--update_lines(""..xcoord..","..ycoord.." "..newloc.." "..movecost.." "..fget(newloc))
if hero.i>0 then
hero.f=directions[cmd]
local terraintype=mget(xcoord,ycoord)
if checkexit(xcoord,ycoord) then
xcoord,ycoord=curmap.ex,curmap.ey
setmap()
elseif content then
if content.n=='maelstrom' then
update_lines{cmd,"maelstrom! yikes!"}
deducthp(rnd(25))
else
movesuccess=blocked(cmd)
end
elseif terraintype<12 or terraintype>15 then
update_lines{cmd,"must exit ship first."}
movesuccess=false
else
update_lines{cmd}
end
else
if checkexit(xcoord,ycoord) then
xcoord,ycoord=curmap.ex,curmap.ey
setmap()
elseif content then
if not content.p then
movesuccess=blocked(cmd)
end
elseif newloc==28 then
update_lines{cmd,"open door."}
movesuccess=false
mset(xcoord,ycoord,30)
elseif newloc==29 then
if hero.keys>0 then
update_lines{cmd,"you jimmy the door."}
hero.keys-=1
mset(xcoord,ycoord,30)
else
update_lines{cmd,"the door is locked."}
end
movesuccess=false
elseif impassable then
movesuccess=blocked(cmd)
elseif water then
movesuccess=false
update_lines{cmd,"not without a boat."}
elseif movecost>hero.mvp then
hero.mvp+=1
movesuccess=false
update_lines{cmd,"slow progress."}
else
hero.mvp=0
update_lines{cmd}
end
end
if movesuccess then
if hero.i==0 then
sfx(0)
end
if newloc==5 and rnd(10)>6 then
update_lines{cmd,"poisoned!"}
hero.st=bor(hero.st,1)
end
else
xcoord,ycoord=hero.x,hero.y
end
turnmade=true
return xcoord,ycoord
end
function check_sign(xcoord,ycoord)
local response=nil
if mget(xcoord,ycoord)==31 then
-- read the sign
for sign in all(curmap.signs) do
if xcoord==sign.x and ycoord==sign.y then
response=sign.msg
break
end
end
end
return response
end
function look_results(ldir,xcoord,ycoord)
local cmd,signcontents,content="examine: "..ldir,check_sign(xcoord,ycoord),contents[xcoord][ycoord][hero.z] or nil
if signcontents then
update_lines{cmd.." (read sign)",signcontents}
elseif content then
update_lines{cmd,content.n}
elseif curmap.dg then
update_lines{cmd,getdungeonblk(xcoord,ycoord,hero.z)<1 and 'passage' or 'wall'}
else
update_lines{cmd,terrains[mget(xcoord,ycoord)]}
end
end
function dialog_results(ddir,xcoord,ycoord)
local cmd="dialog: "..ddir
if terrains[mget(xcoord,ycoord)]=='counter' then
return getdirection(calculatemoves({x=xcoord,y=ycoord}),dialog_results,nil,ddir)
end
local dialog_target=contents[xcoord][ycoord][hero.z]
if dialog_target then
if dialog_target.mch then
update_lines{shop[dialog_target.mch]()}
elseif dialog_target.d then
update_lines{cmd,'"'..dialog_target.d[flr(rnd(#dialog_target.d)+1)]..'"'}
else
update_lines{cmd,'no response!'}