Advertisement
Ra7eN

space

May 6th, 2025 (edited)
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 23.32 KB | Source Code | 0 0
  1. OPTION _Explicit
  2.  
  3. ' === MAIN VARIABLES ===
  4. CONST MAXPLANETS = 1000
  5. CONST MAXGOODS = 1000
  6. CONST MAXCARGO = 1000
  7. CONST MAX_NODES = 1000
  8.  
  9. DIM SHARED nodeLinks(1 TO MAX_NODES, 1 TO 3) AS INTEGER ' stores up to 3 links per node
  10. DIM SHARED isPlanet(1 TO MAX_NODES) AS INTEGER
  11. DIM SHARED planetName$(1 TO MAX_NODES)
  12. DIM SHARED planetExport1$(1 TO MAX_NODES), planetExport2$(1 TO MAX_NODES), planetuserInputort$(1 TO MAX_NODES)
  13.  
  14. DIM SHARED visited(1 TO MAX_NODES) AS INTEGER
  15. DIM SHARED currentNode AS INTEGER
  16.  
  17.  
  18. DIM SHARED AS INTEGER i, j
  19.  
  20. DIM SHARED x AS INTEGER, y AS INTEGER
  21. DIM SHARED fuel AS INTEGER, credits AS LONG
  22.  
  23. DIM SHARED cargoMax AS INTEGER
  24. DIM SHARED planet$(MAXPLANETS)
  25. DIM SHARED planetX(MAXPLANETS), planetY(MAXPLANETS)
  26. DIM SHARED goods$(MAXGOODS)
  27. DIM SHARED goodMin(MAXGOODS), goodMax(MAXGOODS)
  28. DIM SHARED cargo(1 TO MAXCARGO) AS INTEGER
  29. DIM SHARED numGoods AS INTEGER
  30.  
  31.  
  32. RANDOMIZE (-TIMER)
  33. InitGoods
  34. IF _FileExists("planets.txt") THEN
  35.     LoadPlanetsFromFile
  36. ELSE
  37.     GenerateStarterPlanets
  38.     LoadPlanetsFromFile
  39. END IF
  40. InitGame
  41.  
  42. ShipConsole
  43.  
  44.  
  45.  
  46. GoodsList:
  47. DATA Ore,80,150
  48. DATA Food,30,75
  49. DATA Tech,150,300
  50. DATA Medicine,100,250
  51. DATA Water,10,40
  52. DATA Crystals,200,400
  53. DATA Fuel,50,120
  54. DATA Alcohol,100,180
  55. DATA Tobacco,90,170
  56. DATA LuxuryGoods,300,500
  57. DATA Nanotubes,120,220
  58. DATA CircuitBoards,110,190
  59. DATA Jewelry,250,600
  60. DATA Perfume,180,350
  61. DATA SurgeryKits,400,700
  62. DATA FrozenMeals,60,130
  63. DATA QuantumChips,450,800
  64. DATA Coolant,85,160
  65. DATA AncientRelics,800,1500
  66. DATA AlienEggs,1000,1800
  67. DATA Titanium,140,250
  68. DATA Uranium,300,550
  69. DATA Carbon,90,160
  70. DATA Silicon,75,140
  71. DATA Iron,70,130
  72. DATA Copper,60,120
  73. DATA Zinc,55,110
  74. DATA Lithium,130,220
  75. DATA Quartz,50,100
  76. DATA Plastics,45,90
  77. DATA SyntheticFibers,80,150
  78. DATA Processors,200,320
  79. DATA WireSpools,70,140
  80. DATA AIcores,600,1000
  81. DATA Datadrives,300,600
  82. DATA NavigationModules,220,420
  83. DATA DefenseGrids,400,700
  84. DATA Holograms,150,290
  85. DATA Mechs,750,1100
  86. DATA Books,20,80
  87. DATA ReligiousIcons,60,140
  88. DATA Propaganda,30,100
  89. DATA IllicitSoftware,500,900
  90. DATA AncientTexts,600,1200
  91. DATA Sculptures,350,700
  92. DATA Instruments,180,350
  93. DATA DesignerClothes,220,400
  94. DATA FineWines,250,420
  95. DATA VintageTech,500,850
  96. DATA Antivirals,120,220
  97. DATA Painkillers,100,180
  98. DATA ProteinPaste,40,90
  99. DATA Gold,800,1200
  100. DATA Silver,300,500
  101. DATA Diamonds,1200,2000
  102. DATA Pearls,600,900
  103. DATA Spices,150,270
  104. DATA Tea,60,110
  105. DATA Coffee,70,130
  106. DATA ExoticFruits,90,160
  107. DATA ShipParts,300,600
  108. DATA PowerCells,150,300
  109. DATA GravityCores,500,900
  110. DATA LaserCrystals,400,800
  111. DATA BioGel,350,700
  112. DATA CloneTissues,700,1200
  113. DATA AndroidParts,600,1000
  114. DATA DroidCores,450,850
  115. DATA HackerTools,320,600
  116. DATA SurveillanceGear,300,580
  117. DATA Explosives,700,1100
  118. DATA Rockets,800,1400
  119. DATA Ballistics,400,700
  120. DATA PlasmaCores,1000,1600
  121. DATA EMPDevices,850,1500
  122. DATA FusionRods,600,1000
  123. DATA TerraformKits,1200,2000
  124. DATA IceSamples,90,170
  125. DATA GasSamples,70,150
  126. DATA AlienTech,1500,2200
  127. DATA SpaceArt,350,650
  128. DATA MartianDust,180,320
  129. DATA NeuralLinks,800,1400
  130. DATA CargoPods,90,160
  131. DATA AsteroidDebris,30,70
  132. DATA MoonRocks,100,200
  133. DATA XenoBones,600,1000
  134. DATA CreatureDNA,950,1500
  135. DATA ExoticLiquids,500,900
  136. DATA Stims,110,210
  137. DATA Vaccines,130,250
  138. DATA Fertilizer,60,100
  139. DATA IndustrialWaste,10,30
  140. DATA ScrapMetal,20,60
  141. DATA ShinyRocks,5,15
  142. DATA ProgrammablePets,400,700
  143. DATA Holobooks,90,180
  144. DATA CyberLimbs,700,1200
  145. DATA RealityChips,600,1000
  146. DATA TimeCapsules,1500,2500
  147. DATA 0,0,0
  148.  
  149.  
  150.  
  151.  
  152.  
  153. SUB ConsoleMenu
  154.     DIM choice$
  155.  
  156.     DO
  157.         CLS
  158.         PRINT "=== Ship Console ==="
  159.         PRINT "1. View Cargo"
  160.         PRINT "2. Planet Directory"
  161.         PRINT "3. Return to Main Menu"
  162.         INPUT "Choice: ", choice$
  163.  
  164.         SELECT CASE choice$
  165.             CASE "1": ShowCargo
  166.             CASE "2": ShowPlanetLinks
  167.             CASE "3": EXIT DO
  168.         END SELECT
  169.     LOOP
  170. END SUB
  171.  
  172. SUB ShowCargo
  173.     CLS
  174.     PRINT "=== Cargo Hold ==="
  175.     FOR i = 1 TO numGoods
  176.         IF cargo(i) > 0 THEN
  177.             PRINT goods$(i); " = "; cargo(i)
  178.         END IF
  179.     NEXT
  180.     PRINT: PRINT "Press any key...": SLEEP
  181. END SUB
  182.  
  183. SUB ShowPlanetLinks
  184.     DIM pname1$, pname2$, dx, dy
  185.  
  186.     CLS
  187.     PRINT "=== PLANET DIRECTORY ===": PRINT
  188.  
  189.     FOR i = 1 TO MAXPLANETS
  190.         IF planet$(i) <> "" THEN
  191.             pname1$ = SplitString$(planet$(i), "|", 1)
  192.             PRINT pname1$; " ("; planetX(i); ","; planetY(i); ")  ? ";
  193.  
  194.             DIM linkLine$
  195.             linkLine$ = ""
  196.  
  197.             FOR j = 1 TO MAXPLANETS
  198.                 IF planet$(j) <> "" THEN
  199.                     dx = ABS(planetX(j) - planetX(i))
  200.                     dy = ABS(planetY(j) - planetY(i))
  201.                     IF (dx = 1 AND dy = 0) OR (dx = 0 AND dy = 1) THEN
  202.                         pname2$ = SplitString$(planet$(j), "|", 1)
  203.                         IF linkLine$ <> "" THEN linkLine$ = linkLine$ + ", "
  204.                         linkLine$ = linkLine$ + pname2$
  205.                     END IF
  206.                 END IF
  207.             NEXT
  208.  
  209.             PRINT linkLine$
  210.         END IF
  211.     NEXT
  212.  
  213.     PRINT: PRINT "Press any key...": SLEEP
  214. END SUB
  215.  
  216.  
  217.  
  218. ' === INIT ===
  219. SUB InitGame ()
  220.     x = 0: y = 0
  221.     fuel = 100
  222.     credits = 5000
  223.     cargoMax = 20
  224. END SUB
  225.  
  226. SUB InitGoods
  227.     DIM g AS STRING, i AS INTEGER
  228.     RESTORE GoodsList
  229.     i = 1
  230.     DO
  231.         READ g, goodMin(i), goodMax(i)
  232.         IF g = "0" THEN EXIT DO
  233.         goods$(i) = g
  234.         i = i + 1
  235.     LOOP
  236.     numGoods = i - 1
  237. END SUB
  238.  
  239. ' === TRAVEL ===
  240.  
  241. ' === TRADE ===
  242. SUB Trade
  243.     DIM pname AS STRING
  244.     DIM ex1 AS STRING
  245.     DIM ex2 AS STRING
  246.     DIM userInput AS STRING
  247.     DIM g AS STRING
  248.     DIM buyPrice AS INTEGER, sellPrice AS INTEGER
  249.     DIM i AS INTEGER, choice AS INTEGER, found AS INTEGER
  250.  
  251.  
  252.  
  253.     found = 0
  254.     FOR i = 1 TO MAXPLANETS
  255.         IF x = planetX(i) AND y = planetY(i) THEN found = i: EXIT FOR
  256.     NEXT
  257.     IF found = 0 THEN PRINT "No market here.": SLEEP: EXIT SUB
  258.  
  259.     pname$ = SplitString$(planet$(found), "|", 1)
  260.     ex1$ = SplitString$(planet$(found), "|", 2)
  261.     ex2$ = SplitString$(planet$(found), "|", 3)
  262.     userInput$ = SplitString$(planet$(found), "|", 4)
  263.  
  264.     DO
  265.         CLS
  266.         PRINT "Welcome to "; pname$; " Trade Post"
  267.         PRINT "Cargo space: "; (cargoMax - (cargo(1) + cargo(2) + cargo(3)))
  268.         PRINT "Credits: "; credits: PRINT
  269.  
  270.         FOR i = 1 TO MAXGOODS
  271.             g$ = goods$(i)
  272.             buyPrice = (goodMin(i) + goodMax(i)) \ 2
  273.             sellPrice = buyPrice - 20
  274.             IF g$ = ex1$ OR g$ = ex2$ THEN buyPrice = goodMin(i): sellPrice = goodMin(i) - 10
  275.             IF g$ = userInput$ THEN buyPrice = goodMax(i): sellPrice = goodMax(i) - 10
  276.  
  277.             PRINT i; ". Buy "; g$; " - "; buyPrice; " cr"
  278.             PRINT "   Sell "; g$; " - "; sellPrice; " cr"
  279.         NEXT
  280.         PRINT numGoods + 1; ". Exit"
  281.         INPUT "Choice:", choice
  282.  
  283.         IF choice >= 1 AND choice <= numGoods THEN
  284.             g$ = goods$(choice)
  285.             buyPrice = (goodMin(choice) + goodMax(choice)) \ 2
  286.             sellPrice = buyPrice - 20
  287.             IF g$ = ex1$ OR g$ = ex2$ THEN buyPrice = goodMin(choice): sellPrice = goodMin(choice) - 10
  288.             IF g$ = userInput$ THEN buyPrice = goodMax(choice): sellPrice = goodMax(choice) - 10
  289.  
  290.             PRINT "[B]uy or [S]ell "; g$; "?";: userInput = UCASE$(LEFT$(_Trim$(userInput$), 1))
  291.             IF userInput$ = "B" THEN
  292.                 IF (cargo(1) + cargo(2) + cargo(3)) < cargoMax AND credits >= buyPrice THEN
  293.                     cargo(choice) = cargo(choice) + 1
  294.                     credits = credits - buyPrice
  295.                 ELSE
  296.                     PRINT "Not enough space or credits.": SLEEP
  297.                 END IF
  298.             ELSEIF userInput$ = "S" THEN
  299.                 IF cargo(choice) > 0 THEN
  300.                     cargo(choice) = cargo(choice) - 1
  301.                     credits = credits + sellPrice
  302.                 ELSE
  303.                     PRINT "You have none to sell.": SLEEP
  304.                 END IF
  305.             END IF
  306.         END IF
  307.     LOOP UNTIL choice = numGoods + 1
  308. END SUB
  309.  
  310. ' === MAP VIEW ===
  311. SUB ShowMap
  312.     DIM pname AS STRING
  313.     DIM n AS STRING
  314.  
  315.     PRINT "Known planets:"
  316.     FOR i = 1 TO MAXPLANETS
  317.         IF planet$(i) <> "" THEN
  318.             pname$ = SplitString$(planet$(i), "|", 1)
  319.             PRINT pname$; " at ("; planetX(i); ","; planetY(i); ")"
  320.         END IF
  321.     NEXT
  322.     PRINT "Press any key.": SLEEP
  323. END SUB
  324.  
  325. ' === NAME GENERATOR ===
  326. FUNCTION GenPlanetName$
  327.     DIM pre$(5), midd$(5), suf$(5)
  328.     DIM n AS STRING
  329.     pre$(1) = "Zor": pre$(2) = "Vel": pre$(3) = "Xan": pre$(4) = "Tor": pre$(5) = "Lum"
  330.     midd$(1) = "an": midd$(2) = "or": midd$(3) = "ul": midd$(4) = "ex": midd$(5) = ""
  331.     suf$(1) = "ia": suf$(2) = "on": suf$(3) = "ar": suf$(4) = "is": suf$(5) = "us"
  332.     n$ = pre$(INT(RND * 5) + 1) + midd$(INT(RND * 5) + 1) + suf$(INT(RND * 5) + 1)
  333.  
  334.     IF RND < 0.2 THEN n$ = n$ + "-" + CHR$(INT(RND * 10) + 48)
  335.     GenPlanetName$ = n$
  336. END FUNCTION
  337.  
  338. ' === SAVE PLANET ===
  339. SUB SavePlanetToFile (x AS INTEGER, y AS INTEGER, NAME$, ex1$, ex2$, userInput$)
  340.     PRINT "here"
  341.     OPEN "planets.txt" FOR APPEND AS #1
  342.     PRINT #1, x; ","; y; ","; NAME$; ","; ex1$; ","; ex2$; ","; userInput$
  343.     CLOSE #1
  344. END SUB
  345.  
  346. ' === LOAD PLANETS ===
  347. SUB LoadPlanetsFromFile ()
  348.     PRINT "here"
  349.     DIM LINE$, xPart$, yPart$, namePart$, ex1$, ex2$, userInput$
  350.     DIM i AS INTEGER
  351.     i = 1
  352.     IF _FileExists("planets.txt") THEN
  353.         OPEN "planets.txt" FOR INPUT AS #1
  354.         DO WHILE NOT EOF(1)
  355.             LINE INPUT #1, LINE$
  356.             xPart$ = SplitString$(LINE$, ",", 1)
  357.             yPart$ = SplitString$(LINE$, ",", 2)
  358.             namePart$ = SplitString$(LINE$, ",", 3)
  359.             ex1$ = SplitString$(LINE$, ",", 4)
  360.             ex2$ = SplitString$(LINE$, ",", 5)
  361.             userInput$ = SplitString$(LINE$, ",", 6)
  362.  
  363.             planetX(i) = VAL(xPart$)
  364.             planetY(i) = VAL(yPart$)
  365.             planet$(i) = namePart$ + "|" + ex1$ + "|" + ex2$ + "|" + userInput$
  366.             i = i + 1
  367.         LOOP
  368.         CLOSE #1
  369.     END IF
  370. END SUB
  371.  
  372. ' === SPLIT FUNCTION ===
  373. FUNCTION SplitString$ (userInput$, delim$, index)
  374.     DIM start AS INTEGER, count AS INTEGER, i AS INTEGER
  375.     start = 1: count = 1
  376.     FOR i = 1 TO LEN(userInput$)
  377.         IF MID$(userInput$, i, 1) = delim$ THEN
  378.             IF count = index THEN
  379.                 SplitString$ = MID$(userInput$, start, i - start)
  380.                 EXIT FUNCTION
  381.             END IF
  382.             count = count + 1
  383.             start = i + 1
  384.         END IF
  385.     NEXT
  386.     IF count = index THEN
  387.         SplitString$ = MID$(userInput$, start)
  388.     ELSE
  389.         SplitString$ = ""
  390.     END IF
  391. END FUNCTION
  392.  
  393. SUB GenerateStarterPlanets
  394.     DIM p$, ex1$, ex2$, userInput$
  395.     DIM i AS INTEGER
  396.  
  397.     FOR i = 1 TO 3
  398.         x = i: y = i * 2
  399.         p$ = GenPlanetName$
  400.         ex1$ = goods$(INT(RND * numGoods) + 1)
  401.         DO: ex2$ = goods$(INT(RND * numGoods) + 1): LOOP WHILE ex2$ = ex1$
  402.         DO: userInput$ = goods$(INT(RND * numGoods) + 1): LOOP WHILE userInput$ = ex1$ OR userInput$ = ex2$
  403.         planet$(i) = p$ + "|" + ex1$ + "|" + ex2$ + "|" + userInput$
  404.         planetX(i) = x: planetY(i) = y
  405.         SavePlanetToFile x, y, p$, ex1$, ex2$, userInput$
  406.     NEXT
  407. END SUB
  408.  
  409.  
  410. FUNCTION SelectPlanetByName$ ()
  411.     DIM typed$, pname$, matchList(1 TO MAXPLANETS), matchCount, i, KEY$
  412.  
  413.     CLS
  414.     PRINT "Travel - Type Planet Name:"
  415.     typed$ = ""
  416.  
  417.     DO
  418.         LOCATE 2, 1
  419.         PRINT SPACE$(40);
  420.         LOCATE 2, 1
  421.         PRINT "> "; typed$;
  422.  
  423.         ' find matches
  424.         matchCount = 0
  425.         FOR i = 1 TO MAXPLANETS
  426.             IF planet$(i) <> "" THEN
  427.                 pname$ = SplitString$(planet$(i), "|", 1)
  428.                 IF UCASE$(LEFT$(pname$, LEN(typed$))) = UCASE$(typed$) THEN
  429.                     matchCount = matchCount + 1
  430.                     matchList(matchCount) = i
  431.                 END IF
  432.             END IF
  433.         NEXT
  434.  
  435.         ' show up to 10 matches
  436.         FOR i = 1 TO 10
  437.             LOCATE 4 + i, 4: PRINT SPACE$(40);
  438.         NEXT
  439.         FOR i = 1 TO matchCount
  440.             IF i > 10 THEN EXIT FOR
  441.             pname$ = SplitString$(planet$(matchList(i)), "|", 1)
  442.             LOCATE 4 + i, 4
  443.             PRINT pname$; " ("; planetX(matchList(i)); ","; planetY(matchList(i)); ")"
  444.         NEXT
  445.  
  446.         KEY$ = INKEY$
  447.         IF KEY$ <> "" THEN
  448.             IF KEY$ = CHR$(13) THEN ' ENTER
  449.                 IF matchCount = 1 THEN
  450.                     SelectPlanetByName$ = SplitString$(planet$(matchList(1)), "|", 1)
  451.                     EXIT FUNCTION
  452.                 ELSE
  453.                     PRINT: PRINT "Ambiguous or not found.": SLEEP
  454.                     SelectPlanetByName$ = ""
  455.                     EXIT FUNCTION
  456.                 END IF
  457.             ELSEIF KEY$ = CHR$(8) AND LEN(typed$) > 0 THEN
  458.                 typed$ = LEFT$(typed$, LEN(typed$) - 1)
  459.             ELSEIF ASC(KEY$) >= 32 AND ASC(KEY$) <= 126 THEN
  460.                 typed$ = typed$ + KEY$
  461.             END IF
  462.         END IF
  463.  
  464.         _Limit 30
  465.     LOOP
  466.  
  467. END FUNCTION
  468.  
  469. SUB GenerateNearbyPlanets
  470.     DIM dx, dy, px, py, exists, p$, ex1$, ex2$, userInput$
  471.     DIM planetSlotFound AS INTEGER
  472.     DIM attempts AS INTEGER
  473.  
  474.     PRINT ">> Starting nearby planet generation..."
  475.  
  476.     FOR dx = -1 TO 1
  477.         FOR dy = -1 TO 1
  478.             IF dx <> 0 OR dy <> 0 THEN
  479.                 px = x + dx
  480.                 py = y + dy
  481.  
  482.                 exists = 0
  483.                 FOR i = 1 TO MAXPLANETS
  484.                     IF planet$(i) <> "" AND planetX(i) = px AND planetY(i) = py THEN exists = 1: EXIT FOR
  485.                 NEXT
  486.  
  487.                 IF exists = 0 THEN
  488.  
  489.                     planetSlotFound = 0
  490.                     FOR i = 1 TO MAXPLANETS
  491.                         IF planet$(i) = "" THEN
  492.                             p$ = GenPlanetName$
  493.                             ex1$ = goods$(INT(RND * numGoods) + 1)
  494.  
  495.                             '=== EXPORTS
  496.                             attempts = 0
  497.                             DO
  498.                                 ex2$ = goods$(INT(RND * numGoods) + 1)
  499.                                 attempts = attempts + 1
  500.                                 IF attempts > 100 THEN
  501.                                     PRINT "FAILED to get unique ex2$ after 100 tries."
  502.                                     EXIT SUB
  503.                                 END IF
  504.                             LOOP WHILE ex2$ = ex1$
  505.  
  506.                             '=== userInputORTS
  507.                             attempts = 0
  508.                             DO
  509.                                 userInput$ = goods$(INT(RND * numGoods) + 1)
  510.                                 attempts = attempts + 1
  511.                                 IF attempts > 100 THEN
  512.                                     PRINT "FAILED to get unique userInput$ after 100 tries."
  513.                                     EXIT SUB
  514.                                 END IF
  515.                             LOOP WHILE userInput$ = ex1$ OR userInput$ = ex2$
  516.  
  517.  
  518.                             planet$(i) = p$ + "|" + ex1$ + "|" + ex2$ + "|" + userInput$
  519.                             planetX(i) = px
  520.                             planetY(i) = py
  521.                             SavePlanetToFile px, py, p$, ex1$, ex2$, userInput$
  522.  
  523.                             planetSlotFound = 1
  524.                             EXIT FOR
  525.                         END IF
  526.                     NEXT
  527.  
  528.                     IF planetSlotFound = 0 THEN
  529.                         PRINT "No more space in planet list. Skipping generation."
  530.                         EXIT SUB
  531.                     END IF
  532.                 END IF
  533.             END IF
  534.         NEXT
  535.     NEXT
  536. END SUB
  537.  
  538. SUB ShipConsole
  539.     DIM choice$
  540.     DIM dockStatus$
  541.     DIM docked AS INTEGER
  542.     DIM dist AS INTEGER
  543.     DIM banked AS INTEGER
  544.     dist = ABS(x) + ABS(y)
  545.  
  546.     DO
  547.         CLS
  548.         PRINT "+================================================+"
  549.         PRINT "|         DELIVERANCE - SHIP CONSOLE INTERFACE   |"
  550.         PRINT "+================================================+"
  551.         PRINT USING "| LOCATION   : X: ###   Y: ###     SECTOR DIST : ###   |"; x; y; dist
  552.         PRINT USING "| FUEL       : ### / ###         CREDITS     : #####   |"; fuel; 100; credits
  553.         dockStatus$ = "IN ORBIT"
  554.         IF docked THEN dockStatus$ = "DOCKED"
  555.         PRINT "| SHIP MODEL : CARGO SCOUT MK I   STATUS      : \        |"; dockStatus$
  556.         PRINT USING "| CARGO BAY  : ### / ###         BANKED      : #####   |"; GetCargoCount; cargoMax; banked
  557.         PRINT "+------------------------------------------------+"
  558.         PRINT "| [1] Cargo Manifest        [2] Planet Directory |"
  559.         PRINT "| [3] Nav Range Monitor     [4] Exit Console     |"
  560.         PRINT "| [5] Travel to Another Planet                  |"
  561.         PRINT "+================================================+"
  562.         INPUT "SELECT OPTION: ", choice$
  563.  
  564.         SELECT CASE choice$
  565.             CASE "1": ShowCargo
  566.             CASE "2": ShowPlanetLinks
  567.             CASE "3": CheckTravelRange
  568.             CASE "4": EXIT DO
  569.             CASE "5": Travel
  570.         END SELECT
  571.     LOOP
  572. END SUB
  573.  
  574. SUB CheckTravelRange
  575.     CONST MAX_TRAVEL_DISTANCE = 50
  576.     DIM dist AS INTEGER
  577.  
  578.     CLS
  579.     PRINT "=== NAVIGATION RANGE ==="
  580.     dist = ABS(x) + ABS(y)
  581.     PRINT "Current Coordinates: ("; x; ","; y; ")"
  582.     PRINT "Distance from Core (0,0): "; dist; " sectors"
  583.  
  584.     IF dist >= MAX_TRAVEL_DISTANCE THEN
  585.         PRINT "!! WARNING: You are at or beyond safe navigation limits !!"
  586.     ELSEIF dist >= MAX_TRAVEL_DISTANCE - 10 THEN
  587.         PRINT ">> Caution: Approaching maximum safe range."
  588.     ELSE
  589.         PRINT "[OK] You are within operational range."
  590.     END IF
  591.  
  592.     PRINT: PRINT "Press any key to return...": SLEEP
  593. END SUB
  594.  
  595.  
  596. FUNCTION GetCargoCount
  597.     DIM total AS INTEGER
  598.     total = 0
  599.     FOR i = 1 TO numGoods
  600.         total = total + cargo(i)
  601.     NEXT
  602.     GetCargoCount = total
  603. END FUNCTION
  604.  
  605. SUB GenerateGalaxy (nodeCount AS INTEGER)
  606.     DIM i AS INTEGER, j AS INTEGER, k AS INTEGER, n1 AS INTEGER, n2 AS INTEGER
  607.  
  608.     ' Initialize all node links to 0
  609.     FOR i = 1 TO nodeCount
  610.         FOR j = 1 TO 3
  611.             nodeLinks(i, j) = 0
  612.         NEXT
  613.         visited(i) = 0
  614.     NEXT
  615.  
  616.     ' Build connections
  617.     RANDOMIZE TIMER
  618.     FOR i = 1 TO nodeCount
  619.         DO WHILE CountLinks(i) < 3
  620.             n2 = INT(RND * nodeCount) + 1
  621.             IF n2 <> i AND NotLinked(i, n2) AND CountLinks(n2) < 3 THEN
  622.                 AddLink i, n2
  623.             END IF
  624.         LOOP
  625.     NEXT
  626.  
  627.     ' Assign planet status ~70%
  628.     FOR i = 1 TO nodeCount
  629.         IF RND < 0.7 THEN
  630.             isPlanet(i) = -1
  631.             planetName$(i) = GenPlanetName$
  632.             planetExport1$(i) = goods$(INT(RND * numGoods) + 1)
  633.             DO: planetExport2$(i) = goods$(INT(RND * numGoods) + 1)
  634.             LOOP WHILE planetExport2$(i) = planetExport1$(i)
  635.             DO: planetuserInputort$(i) = goods$(INT(RND * numGoods) + 1)
  636.             LOOP WHILE planetuserInputort$(i) = planetExport1$(i) OR planetuserInputort$(i) = planetExport2$(i)
  637.         ELSE
  638.             isPlanet(i) = 0
  639.         END IF
  640.     NEXT
  641.  
  642.     ' Save data (optional)
  643.     OPEN "galaxy.txt" FOR OUTPUT AS #1
  644.     FOR i = 1 TO nodeCount
  645.         PRINT #1, i; ","; isPlanet(i); ","; nodeLinks(i, 1); ","; nodeLinks(i, 2); ","; nodeLinks(i, 3); ",";
  646.         IF isPlanet(i) THEN
  647.             PRINT #1, planetName$(i); ","; planetExport1$(i); ","; planetExport2$(i); ","; planetuserInputort$(i)
  648.         ELSE
  649.             PRINT #1, "EMPTY"
  650.         END IF
  651.     NEXT
  652.     CLOSE #1
  653.  
  654.     PRINT "Galaxy generated with "; nodeCount; " nodes."
  655. END SUB
  656.  
  657. FUNCTION CountLinks (n AS INTEGER)
  658.     DIM c AS INTEGER
  659.     c = 0
  660.     FOR i = 1 TO 3
  661.         IF nodeLinks(n, i) > 0 THEN c = c + 1
  662.     NEXT
  663.     CountLinks = c
  664. END FUNCTION
  665.  
  666. FUNCTION NotLinked (a AS INTEGER, b AS INTEGER)
  667.     FOR i = 1 TO 3
  668.         IF nodeLinks(a, i) = b THEN NotLinked = 0: EXIT FUNCTION
  669.     NEXT
  670.     NotLinked = -1
  671. END FUNCTION
  672.  
  673. SUB AddLink (a AS INTEGER, b AS INTEGER)
  674.     FOR i = 1 TO 3
  675.         IF nodeLinks(a, i) = 0 THEN nodeLinks(a, i) = b: EXIT FOR
  676.     NEXT
  677.     FOR i = 1 TO 3
  678.         IF nodeLinks(b, i) = 0 THEN nodeLinks(b, i) = a: EXIT FOR
  679.     NEXT
  680. END SUB
  681.  
  682. SUB Travel
  683.     DIM i AS INTEGER, dest AS INTEGER
  684.     DIM userInput$, pname$, exitCount AS INTEGER
  685.     DIM docked AS INTEGER
  686.  
  687.     CLS
  688.     PRINT "=== NAVIGATION CONSOLE ==="
  689.     PRINT "CURRENT LOCATION: ";
  690.     IF isPlanet(currentNode) THEN
  691.         PRINT planetName$(currentNode); " (Node "; currentNode; ")"
  692.     ELSE
  693.         PRINT "UNKNOWN SPACE (Node "; currentNode; ")"
  694.     END IF
  695.     PRINT: PRINT "CONNECTED EXITS:"
  696.  
  697.     FOR i = 1 TO 3
  698.         IF nodeLinks(currentNode, i) > 0 THEN
  699.             dest = nodeLinks(currentNode, i)
  700.             pname$ = "???"
  701.             IF visited(dest) THEN pname$ = planetName$(dest)
  702.             PRINT "  ["; i; "] "; pname$; " (Node "; dest; ")"
  703.         END IF
  704.     NEXT
  705.  
  706.     PRINT: INPUT "Enter exit number to travel: ", userInput$
  707.     dest = VAL(userInput$)
  708.     IF dest < 1 OR dest > 3 THEN PRINT "Invalid exit.": SLEEP: EXIT SUB
  709.  
  710.     dest = nodeLinks(currentNode, dest)
  711.     IF dest = 0 THEN PRINT "Link does not exist.": SLEEP: EXIT SUB
  712.  
  713.     ' Travel
  714.     PRINT "Engaging jump drive..."
  715.     _Delay 1.5
  716.     currentNode = dest
  717.     visited(currentNode) = -1
  718.  
  719.     IF isPlanet(currentNode) THEN
  720.         docked = -1
  721.         PRINT "Arrived at "; planetName$(currentNode); ". Docked."
  722.     ELSE
  723.         docked = 0
  724.         PRINT "Arrived in deep space."
  725.     END IF
  726.  
  727.     SLEEP
  728. END SUB
  729.  
  730. ' === SUB TO DISPLAY LOCAL RADIAL GALAXY MAP ===
  731. SUB ShowGalaxyMap
  732.     DIM queue(1 TO MAX_NODES) AS INTEGER
  733.     DIM depth(1 TO MAX_NODES) AS INTEGER
  734.     DIM seen(1 TO MAX_NODES) AS INTEGER
  735.     DIM head AS INTEGER, tail AS INTEGER, i AS INTEGER, n AS INTEGER, link AS INTEGER
  736.  
  737.     CONST MAX_DEPTH = 5
  738.  
  739.     CLS
  740.     PRINT "=== LOCAL GALACTIC MAP ("; MAX_DEPTH; " JUMPS) ==="
  741.     PRINT "You are at node "; currentNode; ".": PRINT
  742.  
  743.     ' BFS traversal from currentNode
  744.     FOR i = 1 TO MAX_NODES
  745.         depth(i) = -1
  746.         seen(i) = 0
  747.     NEXT
  748.  
  749.     head = 1: tail = 1
  750.     queue(1) = currentNode
  751.     depth(currentNode) = 0
  752.     seen(currentNode) = -1
  753.  
  754.     DO WHILE head <= tail
  755.         n = queue(head): head = head + 1
  756.  
  757.         FOR i = 1 TO 3
  758.             link = nodeLinks(n, i)
  759.             IF link > 0 AND seen(link) = 0 THEN
  760.                 depth(link) = depth(n) + 1
  761.                 IF depth(link) <= MAX_DEPTH THEN
  762.                     tail = tail + 1
  763.                     queue(tail) = link
  764.                     seen(link) = -1
  765.                 END IF
  766.             END IF
  767.         NEXT
  768.     LOOP
  769.  
  770.     ' Display map as list-style for now (grid later if needed)
  771.     FOR i = 1 TO MAX_NODES
  772.         IF depth(i) >= 0 AND depth(i) <= MAX_DEPTH THEN
  773.             SELECT CASE depth(i)
  774.                 CASE 0: PRINT "[ @ ] ";
  775.                 CASE ELSE
  776.                     PRINT "[ ";
  777.                     IF visited(i) = 0 THEN
  778.                         PRINT "?"
  779.                     ELSEIF isPlanet(i) THEN
  780.                         PRINT "*"
  781.                     ELSE
  782.                         PRINT "."
  783.                     END IF
  784.                     PRINT " ] Node "; i; "  Depth: "; depth(i)
  785.             END SELECT
  786.         END IF
  787.     NEXT
  788.  
  789.     PRINT: PRINT "LEGEND: @ = You, * = Planet, . = Empty, ? = Unknown"
  790.     PRINT "Press any key to return...": SLEEP
  791. END SUB
  792.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement