@@ -226,7 +226,8 @@ proc setAsHome(dialog: var GameDialog) {.raises: [], tags: [RootEffect],
226
226
dialog = setQuestion (question = " Are you sure want to change your home base (it cost " &
227
227
$ price & " " & moneyName & " )?" , qType = homeBase, data = $ price)
228
228
229
- proc askForEvents (dialog: var GameDialog ) {.raises : [], tags : [RootEffect ], contractual .} =
229
+ proc askForEvents (dialog: var GameDialog ) {.raises : [], tags : [RootEffect ],
230
+ contractual .} =
230
231
# # Ask for known events
231
232
# #
232
233
# # * dialog - the current in-game dialog displayed on the screen
@@ -239,7 +240,8 @@ proc askForEvents(dialog: var GameDialog) {.raises: [], tags: [RootEffect], cont
239
240
except :
240
241
dialog = setError (message = " Can't ask for events." )
241
242
242
- proc askForBases (dialog: var GameDialog ) {.raises : [], tags : [RootEffect ], contractual .} =
243
+ proc askForBases (dialog: var GameDialog ) {.raises : [], tags : [RootEffect ],
244
+ contractual .} =
243
245
# # Ask for known bases
244
246
# #
245
247
# # * dialog - the current in-game dialog displayed on the screen
@@ -252,7 +254,9 @@ proc askForBases(dialog: var GameDialog) {.raises: [], tags: [RootEffect], contr
252
254
except :
253
255
dialog = setError (message = " Can't ask for bases." )
254
256
255
- proc showDockedCommands (baseIndex: ExtendedBasesRange ; haveTrader: bool ; dialog: var GameDialog ; state: var GameState ) {.raises : [], tags : [RootEffect ], contractual .} =
257
+ proc showDockedCommands (baseIndex: ExtendedBasesRange ; haveTrader: bool ;
258
+ dialog: var GameDialog ; state: var GameState ) {.raises : [], tags : [
259
+ RootEffect ], contractual .} =
256
260
# # Show the available orders when the player's ship is docked to a base
257
261
# #
258
262
# # * baseIndex - the index of the base to which the player's ship is docked
@@ -397,13 +401,17 @@ proc showDockedCommands(baseIndex: ExtendedBasesRange; haveTrader: bool; dialog:
397
401
missionsLimit.dec
398
402
if missionsLimit > 0 :
399
403
labelButton (title = " Missions" ):
400
- discard
404
+ state = baseMissions
405
+ dialog = none
406
+ closePopup ()
401
407
if playerShip.homeBase != baseIndex:
402
408
labelButton (title = " Set as home" ):
403
409
setAsHome (dialog = dialog)
404
410
if skyBases[baseIndex].population == 0 :
405
411
labelButton (title = " Loot" ):
406
- discard
412
+ state = loot
413
+ dialog = none
414
+ closePopup ()
407
415
408
416
proc finishStory (): GameDialog {.raises : [], tags : [WriteIOEffect , TimeEffect ,
409
417
RootEffect ], contractual .} =
@@ -419,11 +427,12 @@ proc finishStory(): GameDialog {.raises: [], tags: [WriteIOEffect, TimeEffect,
419
427
except KeyError :
420
428
result = setError (message = " Can't get the end text of the current story. " )
421
429
422
- proc executeStory (dialog: var GameDialog ) {.raises : [], tags : [ RootEffect ],
423
- contractual .} =
430
+ proc executeStory (dialog: var GameDialog ; state: var GameState ) {.raises : [],
431
+ tags : [ RootEffect ], contractual .} =
424
432
# # Execute the current story step
425
433
# #
426
434
# # * dialog - the current in-game dialog displayed on the screen
435
+ # # * state - the current state of the game
427
436
# #
428
437
# # Returns the modified parameters dialog.
429
438
closePopup ()
@@ -448,12 +457,12 @@ proc executeStory(dialog: var GameDialog) {.raises: [], tags: [RootEffect],
448
457
try :
449
458
if progressStory ():
450
459
let tokens: seq [string ] = currentStory.data.split (sep = ';' )
451
- case step.finishCondition
452
- of destroyShip:
460
+ if step.finishCondition == destroyShip:
453
461
if startCombat (enemyIndex = tokens[2 ].parseInt, newCombat = false ):
462
+ state = combat
463
+ dialog = none
464
+ closePopup ()
454
465
return
455
- else :
456
- discard
457
466
if currentStory.currentStep > - 3 :
458
467
step = (if currentStory.currentStep > - 1 : storiesList[
459
468
currentStory.index].steps[currentStory.currentStep] else : storiesList[
@@ -471,8 +480,8 @@ proc executeStory(dialog: var GameDialog) {.raises: [], tags: [RootEffect],
471
480
dialog = setError (message = " Can't progress the current story." )
472
481
473
482
474
- proc startMission (dialog: var GameDialog ; state: var GameState ) {.raises : [], tags : [ RootEffect ],
475
- contractual .} =
483
+ proc startMission (dialog: var GameDialog ; state: var GameState ) {.raises : [],
484
+ tags : [ RootEffect ], contractual .} =
476
485
# # Start the mission in the current map cell
477
486
# #
478
487
# # * dialog - the current in-game dialog displayed on the screen
@@ -518,6 +527,8 @@ proc startMission(dialog: var GameDialog; state: var GameState) {.raises: [], ta
518
527
uMission = true
519
528
if startsCombat:
520
529
state = combat
530
+ dialog = none
531
+ closePopup ()
521
532
return
522
533
if uMission:
523
534
try :
@@ -586,8 +597,8 @@ proc deliverMedicines(dialog: var GameDialog; forFree: bool = true) {.raises: [
586
597
except :
587
598
dialog = setError (message = " Can't sell medicines to base." )
588
599
589
- proc showShipOrders * (dialog: var GameDialog ; state: var GameState ) {.raises : [], tags : [ RootEffect ],
590
- contractual .} =
600
+ proc showShipOrders * (dialog: var GameDialog ; state: var GameState ) {.raises : [],
601
+ tags : [ RootEffect ], contractual .} =
591
602
# # Show the player's ship's orders menu
592
603
# #
593
604
# # * dialog - the current in-game dialog displayed on the screen
@@ -629,7 +640,7 @@ proc showShipOrders*(dialog: var GameDialog; state: var GameState) {.raises: [],
629
640
labelButton (title = " Ask for " & itemsList[getStepData (
630
641
finishData = step.finishData,
631
642
name = " item" ).parseInt].name):
632
- executeStory (dialog = dialog)
643
+ executeStory (dialog = dialog, state = state )
633
644
except :
634
645
dialog = setError (message = " Can't add the story button." )
635
646
return
@@ -641,7 +652,7 @@ proc showShipOrders*(dialog: var GameDialog; state: var GameState) {.raises: [],
641
652
try :
642
653
labelButton (title = " Search for " & protoShipsList[parts[
643
654
3 ].parseInt].name):
644
- executeStory (dialog = dialog)
655
+ executeStory (dialog = dialog, state = state )
645
656
except :
646
657
dialog = setError (message = " Can't add the story button." )
647
658
return
@@ -654,7 +665,7 @@ proc showShipOrders*(dialog: var GameDialog; state: var GameState) {.raises: [],
654
665
if playerShip.skyX == parts[0 ].parseInt and playerShip.skyY ==
655
666
parts[1 ].parseInt:
656
667
labelButton (title = " Search area" ):
657
- executeStory (dialog = dialog)
668
+ executeStory (dialog = dialog, state = state )
658
669
except :
659
670
dialog = setError (message = " Can't get the story step location." )
660
671
return
@@ -671,15 +682,19 @@ proc showShipOrders*(dialog: var GameDialog; state: var GameState) {.raises: [],
671
682
case event
672
683
of enemyShip, enemyPatrol:
673
684
labelButton (title = " Attack" ):
674
- discard
685
+ state = combat
686
+ dialog = none
687
+ closePopup ()
675
688
of fullDocks:
676
689
labelButton (title = " Wait (full docks)" ):
677
690
closePopup ()
678
691
dialog = waitDialog
679
692
setDialog ()
680
693
of attackOnBase:
681
694
labelButton (title = " Defend" ):
682
- discard
695
+ state = combat
696
+ dialog = none
697
+ closePopup ()
683
698
of disease:
684
699
if haveTrader:
685
700
let itemIndex: int = try :
@@ -761,7 +776,9 @@ proc showShipOrders*(dialog: var GameDialog; state: var GameState) {.raises: [],
761
776
of trader:
762
777
if haveTrader:
763
778
labelButton (title = " Trade" ):
764
- discard
779
+ state = trade
780
+ dialog = none
781
+ closePopup ()
765
782
labelButton (title = " Ask for events" ):
766
783
askForEvents (dialog = dialog)
767
784
if dialog != none:
@@ -771,14 +788,18 @@ proc showShipOrders*(dialog: var GameDialog; state: var GameState) {.raises: [],
771
788
if dialog != none:
772
789
return
773
790
labelButton (title = " Attack" ):
774
- discard
791
+ state = combat
792
+ dialog = none
793
+ closePopup ()
775
794
of friendlyShip:
776
795
if haveTrader:
777
796
try :
778
797
if tradersName in protoShipsList[eventsList[skyMap[
779
798
playerShip.skyX][playerShip.skyY].eventIndex].shipIndex].name:
780
799
labelButton (title = " Trade" ):
781
- discard
800
+ state = trade
801
+ dialog = none
802
+ closePopup ()
782
803
labelButton (title = " Ask for bases" ):
783
804
askForBases (dialog = dialog)
784
805
if dialog != none:
@@ -791,7 +812,9 @@ proc showShipOrders*(dialog: var GameDialog; state: var GameState) {.raises: [],
791
812
if dialog != none:
792
813
return
793
814
labelButton (title = " Attack" ):
794
- discard
815
+ state = combat
816
+ dialog = none
817
+ closePopup ()
795
818
labelButton (title = " Close" ):
796
819
closePopup ()
797
820
dialog = none
0 commit comments