home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / games / _trynth / !Trynth / !RunImage (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1993-05-17  |  132.8 KB  |  3,943 lines

  1.  > <Trynth$Dir>.!RunImage
  2.  Trynth, a Space Strategy Game for the Archimedes
  3.  (C) David Jones, 1993
  4.          160 Hazelwood Drive
  5.          St.Albans
  6.          HERTS
  7.          AL4 0UZ
  8. %TaskDate$ = "0.20c (18 May 1993)"
  9. TaskCopy$ = "Shareware"
  10. diagnosisPipe% = 
  11. MenuFonts% = 
  12. TRACE TO "pipe::trace"
  13. TRACE PROC
  14. $; " (Error code "; 
  15. ); ")": 
  16. LIBRARY "<Trynth$Dir>.GeneralLib"
  17. initializeStart
  18.  LoadedGame% 
  19. initializeGame
  20. initializeMoreWimp
  21.  LoadedGame% 
  22. changeSides(StartSide%)
  23.     LoadedGame% 
  24.  $MainWindowTitle% = SideNames$(CurrentSide%)
  25. wimpError
  26.  Quit%
  27. wimpPoll
  28. wimpCloseDown
  29. *************************************************************************************
  30. wimpPoll
  31.  reason%
  32.  "Wimp_Poll", %10011111110000000000, WimpBlock% 
  33.  reason%
  34.  reason% 
  35. nullReasonCode
  36. redrawWindowRequest
  37.  "Wimp_OpenWindow",, WimpBlock%
  38.  "Wimp_CloseWindow",, WimpBlock%
  39. pointerLeavingWindow
  40. pointerEnteringWindow
  41. mouseButtonChange
  42. userDragBox
  43. keyPressed
  44. menuSelect
  45.  17, 18: 
  46. userMessage
  47. nullReasonCode
  48.  newPointerOverPlanet%
  49.  (PointerOverPlanet% <> -1) 
  50.  (DragFromWindow% <> -1) 
  51.  "Wimp_GetPointerInfo",, WimpBlock%
  52. ;H  newPointerOverPlanet% = 
  53. worldAtWindow(WimpBlock%!0, WimpBlock%!4)
  54.  PointerOverPlanet% <> newPointerOverPlanet% 
  55. =2    PointerOverPlanet% = newPointerOverPlanet%
  56. >6    
  57. redrawWindowArea(MainWindow%, 0, -64, 560, 0)
  58. redrawWindowRequest
  59.  window%, more%, x0%, y0%
  60. window% = !WimpBlock%
  61.  "Wimp_RedrawWindow",, WimpBlock% 
  62.  more%
  63. getOrigin(x0%, y0%)
  64.  more%
  65.  x0%, y0%
  66.  window% 
  67. L9    
  68.  MainWindow%         : 
  69. drawMainWindow(x0%, y0%)
  70. M;    
  71.  OrdersWindow%       : 
  72. drawOrdersWindow(x0%, y0%)
  73. N?    
  74.  StatisticsWindow%   : 
  75. drawStatisticsWindow(x0%, y0%)
  76. O:    
  77.  GraphWindow%        : 
  78. drawGraphWindow(x0%, y0%)
  79. PB    
  80.  SortedPlanetsWindow%: 
  81. drawSortedPlanetsWindow(x0%, y0%)
  82. Q:    
  83.  WorldWindow%        : 
  84. drawWorldWindow(x0%, y0%)
  85. R<    
  86.  NewGameWindow%      : 
  87. drawNewGameWindow(x0%, y0%)
  88.  0, 0
  89.  "Wimp_GetRectangle",, WimpBlock% 
  90.  more%
  91. pointerLeavingWindow
  92.  window%
  93. window% = WimpBlock%!0
  94.  window% = MainWindow% 
  95.  PointerOverPlanet% = -1
  96. pointerEnteringWindow
  97.  window%
  98. window% = WimpBlock%!0
  99.  window% = MainWindow% 
  100.  "Wimp_GetPointerInfo",, WimpBlock%
  101. kE  PointerOverPlanet% = 
  102. worldAtWindow(WimpBlock%!0, WimpBlock%!4)
  103. redrawWindowArea(MainWindow%, 0, -64, 560, 0)
  104. mouseButtonChange
  105.  x%, y%, buttonState%, icon%
  106. t5x%           = WimpBlock%!0: y%    = WimpBlock%!4
  107. u6buttonState% = WimpBlock%!8: icon% = WimpBlock%!16
  108.  WimpBlock%!12 
  109.  IconBarWindow%
  110.  buttonState% 
  111. z8      
  112.  MenuClick  : 
  113. openIconBarMenu(IconMenu%, x%)
  114. {1      
  115.  SelectClick: 
  116. openWindow(MainWindow%)
  117. |        
  118.  SaveWindow%
  119.  icon% 
  120. C      
  121. dataSaveAck(
  122. readIndirectedBuffer(SaveWindowText%))
  123. '      
  124. dragBox(SaveWindow%, 3)
  125. /              DragFromWindow% = SaveWindow%
  126.         
  127.  MainWindow%
  128.  buttonState% 
  129. 3      
  130.  MenuClick: 
  131. openMenu(MainMenu%, x%, y%)
  132.       
  133.  SelectClick
  134. 6        
  135. updateWorldWindow(
  136. worldAtWindow(x%, y%))
  137. %        
  138. openWindow(WorldWindow%)
  139. "        PointerOverPlanet% = 0
  140.         
  141.  WorldWindow%
  142. K    
  143.  Shading the appropriate icons in updateWorldWindow() stops people
  144. %    
  145.  changing other sides values
  146.  icon% 
  147. !      
  148.  14: 
  149.  Left ship arrow
  150. F        
  151.  buttonState% = SelectClick 
  152. updateWorldWindowShips( 1)
  153. F        
  154.  buttonState% = AdjustClick 
  155. updateWorldWindowShips(-1)
  156. "      
  157.  15: 
  158.  Right ship arrow
  159. F        
  160.  buttonState% = SelectClick 
  161. updateWorldWindowShips(-1)
  162. F        
  163.  buttonState% = AdjustClick 
  164. updateWorldWindowShips( 1)
  165. -      
  166.  16: 
  167.  buttonState% = SelectDrag 
  168. /                 
  169. dragBox(WorldWindow%, 16)
  170. 3                 DragFromWindow% = WorldWindow%
  171.                
  172.       
  173.  12: 
  174.  All left
  175. )        
  176. updateWorldWindowShips( 1E8)
  177.       
  178.  17: 
  179.  All right
  180. )        
  181. updateWorldWindowShips(-1E8)
  182.         
  183.  GraphWindow%
  184.  buttonState% 
  185. 6      
  186.  MenuClick  : 
  187. openMenu(GraphMenu%, x%, y%)
  188.         
  189.  StatisticsWindow%
  190.  buttonState% 
  191. ;      
  192.  MenuClick  : 
  193. openMenu(StatisticsMenu%, x%, y%)
  194.         
  195.  SortedPlanetsWindow%
  196.  buttonState% 
  197. :      
  198.  SelectClick: 
  199. clickSortedPlanetsWindow(x%, y%)
  200.         
  201.  OrdersWindow%
  202.  buttonState% 
  203. 3      
  204.  SelectClick: 
  205. clickOrdersWindow(x%, y%)
  206.         
  207.  SideWindow%
  208.  buttonState% 
  209. ;      
  210.  MenuClick  : 
  211. openMenu(SideWindowMenu%, x%, y%)
  212.         
  213.  WinnerWindow%
  214.  icon% 
  215.       
  216.  Ok, finish
  217.                
  218. wimpCloseDown
  219.               
  220.       
  221.  Continue
  222. %              WinnerContinue% = 
  223. -              
  224. closeWindow(WinnerWindow%)
  225.       
  226. userDragBox
  227.  destinationWorld%, orderShips%
  228.  DragFromWindow% 
  229.  WorldWindow%: 
  230.  move ships
  231. getPointerInfo
  232. '    
  233.  WimpBlock%!12 = MainWindow% 
  234. H      destinationWorld% = 
  235. worldAtWindow(WimpBlock%!0, WimpBlock%!4)
  236. 0      
  237.  destinationWorld% <> CurrentWorld% 
  238. J        orderShips%  = 
  239. readIndirectedBuffer(WorldWindowShipsDrag%))
  240.         
  241.  orderShips% > 0 
  242. M          
  243. moveShipsFromTo(orderShips%, CurrentWorld%, destinationWorld%)
  244. /          
  245. updateWorldWindow(CurrentWorld%)
  246.         
  247.           
  248.         
  249.       
  250.         
  251.       
  252.         
  253.  SaveWindow%
  254. dataSave
  255. DragFromWindow% = -1
  256. keyPressed
  257.  acceptKey%, character%, icon%
  258. 4icon% = WimpBlock%!4: character% = WimpBlock%!24
  259. acceptKey% = 
  260.  WimpBlock%!0 
  261.  WorldWindow%
  262.  icon% 
  263.       
  264.  Planet name
  265.         
  266.  character% = 13 
  267. R          PlanetName$(CurrentWorld%) = 
  268. readIndirectedBuffer(WorldWindowName%)
  269.           
  270. removeCaret
  271. D          
  272. redrawWindowArea(OrdersWindow%, 0, -9000, 1000, -124)
  273. J          
  274. redrawWindowArea(SortedPlanetsWindow%, 0, -9000, 1000, -64)
  275.         
  276.           acceptKey% = 
  277.         
  278. #      
  279.  13: 
  280.  character% = 13 
  281.           
  282. removeCaret
  283. X          
  284. updateWorldWindowPlanetShips(
  285. readIndirectedBuffer(WorldWindowShips%)))
  286.         
  287.  acceptKey% = 
  288.         
  289.       
  290. : acceptKey% = 
  291.         
  292.  BattleWindow%
  293. +    
  294.  (icon% = 1) 
  295.  (character% = 13) 
  296. P      PlanetName$(BattleWorld%) = 
  297. readIndirectedBuffer(BattleWindowPlanet%)
  298.       
  299. removeCaret
  300. @      
  301. redrawWindowArea(OrdersWindow%, 0, -9000, 1000, -124)
  302. F      
  303. redrawWindowArea(SortedPlanetsWindow%, 0, -9000, 1000, -64)
  304.      
  305.       acceptKey% = 
  306.      
  307.  SaveWindow%
  308.  character% = 13 
  309. >      
  310. dataSaveAck(
  311. readIndirectedBuffer(SaveWindowText%))
  312.             
  313.       acceptKey% = 
  314.         
  315. : acceptKey% = 
  316.  acceptKey% 
  317.  "Wimp_ProcessKey", character%
  318. menuSelect
  319.  menu1%
  320. menu1% = WimpBlock%!0
  321.  CurrentMenu% 
  322.  IconMenu%
  323.  menu1% 
  324.       
  325.  2: Quit% = 
  326.         
  327.  MainMenu%
  328.  menu1% 
  329.       
  330. nextSide
  331.       
  332. nextTurn
  333. !-      
  334. openWindow(StatisticsWindow%)
  335. ")      
  336. openWindow(OrdersWindow%)
  337. #        
  338.  GraphMenu%
  339.  menu1% 
  340. 'A      
  341.  0, 1, 2: 
  342. toggleTick(CurrentGraphChoice%, GraphMenu%)
  343. (+        
  344. toggleTick(menu1%, GraphMenu%)
  345. )(        CurrentGraphChoice% = menu1%
  346. *'        
  347. redrawWindow(GraphWindow%)
  348. +        
  349.  StatisticsMenu%
  350.  menu1% 
  351. /(      
  352. openWindow(GraphWindow%)
  353. 00      
  354. openWindow(SortedPlanetsWindow%)
  355. 1'      
  356. openWindow(SideWindow%)
  357. 2        
  358.  SideWindowMenu%
  359.      
  360.  menu1% >= 0 
  361. 6(       
  362. updateSideWindow(menu1% - 1)
  363. 7#       
  364. openWindow(SideWindow%)
  365.      
  366. reopenCurrentMenu
  367. userMessage
  368.  WimpBlock%!16 
  369.  0   : Quit% = 
  370.  2   : 
  371. dataSaveAck(
  372. read0String(WimpBlock% + 44))
  373.  3   : 
  374. dataLoad
  375.  10  : 
  376. bootOptions
  377.  &502: 
  378. helpMessage
  379. bootOptions
  380.  Save details to load this app in this set
  381.  file%, dir$, length%
  382. file% = WimpBlock%!20
  383.  "OS_GSTrans", "<Trynth$Dir>", WimpBlock% + 200, 256 
  384.  ,, length%
  385. O&?(WimpBlock% + length% + 200) = 13
  386. dir$ = $(WimpBlock% + 200)
  387. #file%, "Run " + dir$
  388. *************************************************************************************
  389. ************************************************************************ User Windows
  390. *************************************************************************************
  391. ------------------------------------------------------------------------- Main Window
  392. drawMainWindow(x0%, y0%)
  393.  loop%, x%, y%
  394.  (WimpBlock%!40 - y0% >= -64) 
  395.  (PointerOverPlanet% > 0) 
  396.   10,  -4: 
  397. sideColours( PlanetSide(PointerOverPlanet%))
  398. ^A                 
  399.  SideNames$(PlanetSide(PointerOverPlanet%))
  400. colourBlack
  401.   10, -36: 
  402. (PlanetShips%(PointerOverPlanet%))
  403.  106, -36
  404.  PointerOverPlanet% = CurrentWorld% 
  405.                  
  406.  "--"
  407. eI                 
  408. journeyTime(CurrentWorld%, PointerOverPlanet%))
  409.  170, -36: 
  410.  PlanetName$(PointerOverPlanet%)
  411.  ((WimpBlock%!32 - y0% >= -64) 
  412.  (WimpBlock%!36 - x0% < 600)) 
  413.  loop% = 1 
  414.  NumberPlanets%
  415. l)    
  416. sideColours( PlanetSide(loop%) )
  417. m&    
  418. planetPosition(loop%, x%, y%)
  419. n$    
  420. planetToWindowTrans(x%, y%)
  421.  x%, y%, 20
  422.  loop%
  423. planetToWindowTrans(
  424.  x%, 
  425. x% = x% * 10: y% = y% * -10
  426. windowToPlanetTrans(
  427.  x%, 
  428. x% = x% / 10: y% = y% / 10
  429. sideColoursNumber(side%)
  430.  Returns the relevant Wimp colour number
  431.  side% = 0 
  432.  side% <= 8 
  433.     =side% + 7
  434.     =side% - 7
  435. sideColours(side%)
  436.  "Wimp_SetColour", 
  437. sideColoursNumber(side%)
  438. colourBlack
  439.  "Wimp_SetColour", 7
  440. colourBackground
  441.  "Wimp_SetColour", 1
  442. planetPosition(planet%, 
  443.  x%, 
  444. Dx% = PlanetPosition(planet%, 0): y% = PlanetPosition(planet%, 1)
  445. worldAtWindow(x%, y%)
  446.  Returns the value of the planet at (x%, y%) on the MainWindow%
  447.  loop%, x0%, y0%, closestPlanet%, closestDistance%
  448. getWindowState(MainWindow%)
  449. getOrigin(x0%, y0%)
  450.  x% = x% - x0%: y% = y0% - y%
  451. windowToPlanetTrans(x%, y%)
  452. closestDistance% = 10000
  453.  loop% = 1 
  454.  NumberPlanets%
  455. closestPlanetFromPosition(x%, y%, loop%, closestPlanet%, closestDistance%)
  456.  loop%
  457. = closestPlanet%
  458. closestPlanetFromPosition(x%, y%, currentPlanet%, 
  459.  closestPlanet%, 
  460.  closestDistance%)
  461.  distance%
  462. ndistance% = 
  463. distanceBetween(PlanetPosition(currentPlanet%, 0), x%, PlanetPosition(currentPlanet%, 1), y%)
  464.  distance% < closestDistance% 
  465. %  closestPlanet% = currentPlanet%
  466. "  closestDistance% = distance%
  467. distanceBetweenPlanets(planet1%, planet2%)
  468. distanceBetween( PlanetPosition(planet1%, 0), PlanetPosition(planet2%, 0), PlanetPosition(planet1%, 1), PlanetPosition(planet2%, 1) )
  469. distanceBetween(x0%, x1%, y0%, y1%)
  470. ( ((x0% - x1%) ^2) + ((y0% - y1%) ^2) )
  471. redrawPlanet(planet%)
  472.  x%, y%
  473. planetPosition(planet%, x%, y%)
  474. planetToWindowTrans(x%, y%)
  475. redrawWindowArea(MainWindow%, x% - 25, y% - 25, x% + 25, y% + 25)
  476. ----------------------------------------------------------------------- Orders Window
  477. drawOrdersWindow(x0%, y0%)
  478.  loop%, y%, redrawStartY%, redrawEndY%
  479.  WimpBlock%!40 - y0% > -120 
  480.   10,  -8: 
  481. messageLookupString("CTurn");"  "; CurrentTurn%
  482.   10, -64: 
  483. messageLookupString("Side")
  484.  298, -64: 
  485. messageLookupString("ArrTurn")
  486.  474, -64: 
  487. messageLookupString("Ships")
  488.  650, -64: 
  489. messageLookupString("Planet")
  490.   10, -96: 
  491.  "----------------  ---------  ---------  ----------------"
  492. =redrawStartY% = 
  493. max((WimpBlock%!40 + 96 - y0%) / -32, 1)
  494. QredrawEndY%   = 
  495. min((WimpBlock%!32 + 96 - y0%) / -32, NumberMovementOrders%)
  496.  redrawStartY% <= redrawEndY% 
  497.  loop% = redrawStartY% 
  498.  redrawEndY%
  499.     y% = (-32 * loop%) - 96
  500. *    
  501.  MovementOrders%(loop%, 0) <> 0 
  502. 1      
  503. sideColours(MovementOrders%(loop%, 0))
  504. <      
  505.   10, y%: 
  506.  SideNames$(MovementOrders%(loop%, 0))
  507.       
  508. colourBlack
  509. 0      
  510.  282, y%: 
  511.  MovementOrders%(loop%, 1)
  512. 0      
  513.  458, y%: 
  514.  MovementOrders%(loop%, 2)
  515. =      
  516.  650, y%: 
  517.  PlanetName$(MovementOrders%(loop%, 3))
  518.         
  519. N      
  520.  10,y%:
  521.  "................  .........  .........  ................"
  522.         
  523.  loop%
  524. clickOrdersWindow(x%, y%)
  525.  If the user clicks over a planet name, then that planet is shown
  526.  in the World Window
  527.  x0%, y0%, selectedLine%
  528. getWindowState(OrdersWindow%)
  529. getOrigin(x0%, y0%)
  530.  x% = x% - x0%: y% = y0% - y%
  531. "selectedLine% = (y% - 96) / 32
  532.  selectedLine% >= 1 
  533.  MovementOrders%(selectedLine%, 0) > 0 
  534. ?    
  535. updateWorldWindow( MovementOrders%(selectedLine%, 3) )
  536. !    
  537. openWindow(WorldWindow%)
  538. --------------------------------------------------------------- Sorted Planets Window
  539. drawSortedPlanetsWindow(x0%, y0%)
  540.  loop%, y%, sortedPlanet%, redrawStartY%, redrawEndY%
  541.  WimpBlock%!40 - y0% > -64 
  542.   10,  -8: 
  543. messageLookupString("Side")
  544.  298,  -8: 
  545. messageLookupString("Ships")
  546.  474,  -8: 
  547. messageLookupString("Planet")
  548.   10, -40: 
  549.  "----------------  ---------  ----------------"
  550. =redrawStartY% = 
  551. max((WimpBlock%!40 + 40 - y0%) / -32, 1)
  552. JredrawEndY%   = 
  553. min((WimpBlock%!32 + 40 - y0%) / -32, NumberPlanets%)
  554.  loop% = redrawStartY% 
  555.  redrawEndY%
  556.   y% = (-32 * loop%) - 40
  557. 1  sortedPlanet% = PlanetSortedOnShips%(loop%)
  558. sideColours(PlanetSide(sortedPlanet%))
  559.   10, y%: 
  560.  SideNames$(PlanetSide(sortedPlanet%))
  561. colourBlack
  562.  282, y%: 
  563.  PlanetShips%(sortedPlanet%)
  564.  472, y%: 
  565.  PlanetName$(sortedPlanet%)
  566.  loop%
  567. clickSortedPlanetsWindow(x%, y%)
  568.  If the user clicks over a planet name, then that planet is shown
  569.  in the World Window
  570.  x0%, y0%, selectedLine%
  571. getWindowState(SortedPlanetsWindow%)
  572. getOrigin(x0%, y0%)
  573.  x% = x% - x0%: y% = y0% - y%
  574. "selectedLine% = (y% - 40) / 32
  575.  selectedLine% >= 1 
  576. updateWorldWindow( PlanetSortedOnShips%(selectedLine%) )
  577. openWindow(WorldWindow%)
  578. ------------------------------------------------------------------------ Graph Window
  579. drawGraphWindow(x0%, y0%)
  580.  This is prime for ARM'ing
  581.  loop%, loop2%, maximum%, xUnit, yUnit, graphPointer%, redrawStartX%, redrawEndX%, graphBlockStart%
  582.  CurrentTurn% <= 1 
  583. 5maximum% = GraphDataMaximum%(CurrentGraphChoice%)
  584. ;xUnit =  GraphWindowMaximumX%      / (CurrentTurn% - 1)
  585.  ;yUnit = (GraphWindowMinimumY% - 8) / (maximum%     + 1)
  586. !:redrawStartX% = 
  587. max((WimpBlock%!28 - x0%) / xUnit, 1)
  588. "KredrawEndX%   = 
  589. min(((WimpBlock%!36 - x0%) / xUnit) + 2, CurrentTurn%)
  590. $ggraphBlockStart% = GraphBlock% + (GraphBlockEntrySize% * redrawStartX%) + (CurrentGraphChoice% * 4)
  591.  loop% = 0 
  592.  NumberSides%
  593. sideColours(loop%)
  594. '5  graphPointer% = graphBlockStart% + (loop% * 12)
  595.  (redrawStartX% - 2) * xUnit, (maximum% - !graphPointer%) * yUnit
  596.  loop2% = redrawStartX% 
  597.  redrawEndX%
  598. +C    
  599.  (loop2% - 1) * xUnit, (maximum% - !graphPointer%) * yUnit
  600. ,-    graphPointer% += GraphBlockEntrySize%
  601.  loop2%
  602.  loop%
  603. ------------------------------------------------------------------- Statistics Window
  604. drawStatisticsWindow(x0%, y0%)
  605.  loop%, y%, redrawStartY%, redrawEndY%
  606.  WimpBlock%!40 - y0% > -64 
  607.   10,  -8: 
  608. messageLookupString("Side")
  609.  298,  -8: 
  610. messageLookupString("Ships")
  611.  474,  -8: 
  612. messageLookupString("Reses")
  613.  650,  -8: 
  614. messageLookupString("Planets")
  615.   10, -40: 
  616.  "----------------  ---------  ---------  ---------"
  617. =RredrawStartY% = 
  618. min( 
  619. max((WimpBlock%!40 + 72 - y0%) / -32, 0), NumberSides%)
  620. >HredrawEndY%   = 
  621. min((WimpBlock%!32 + 72 - y0%) / -32, NumberSides%)
  622.  loop% = redrawStartY% 
  623.  redrawEndY%
  624.   y% = (-32 * loop%) - 72
  625. sideColours(loop%)
  626.   10, y%: 
  627.  SideNames$(loop%)
  628. colourBlack
  629.  282, y%: 
  630.  SideTotalShips%(loop%)
  631.  458, y%: 
  632.  SideTotalResources%(loop%)
  633.  632, y%: 
  634.  SideTotalPlanets%(loop%)
  635.  loop%
  636. drawStatisticsWindowGraphs(WimpBlock%!28 - x0%, WimpBlock%!36 - x0%)
  637. drawStatisticsWindowGraphs(minX%, maxX%)
  638.  loop%, top%, totalShips%, totalResources%
  639. N@totalShips% = 
  640. totalShips: totalResources% = 
  641. totalResources
  642.  (minX% <= 328) 
  643.  (maxX% >= 298) 
  644.   top% = -72: 
  645.  Ships bar
  646.  loop% = 0 
  647.  NumberSides%
  648. S\    
  649. drawStatisticsWindowPartBar(loop%, 298, top%, SideTotalShips%(loop%) / totalShips%)
  650.  loop%
  651.  (minX% <= 504) 
  652.  (maxX% >= 474) 
  653. X!  top% = -72: 
  654.  Resources bar
  655.  loop% = 0 
  656.  NumberSides%
  657. Zd    
  658. drawStatisticsWindowPartBar(loop%, 474, top%, SideTotalResources%(loop%) / totalResources%)
  659.  loop%
  660.  (minX% <= 682) 
  661.  (maxX% >= 652) 
  662.   top% = -72: 
  663.  Planets bar
  664.  loop% = 0 
  665.  NumberSides%
  666. aa    
  667. drawStatisticsWindowPartBar(loop%, 652, top%, SideTotalPlanets%(loop%) / NumberPlanets%)
  668.  loop%
  669. drawStatisticsWindowPartBar(side%, x%, 
  670.  top%, fraction)
  671.  height%
  672. sideColours(side%)
  673. j3height% = fraction * ((NumberSides% + 1) * -32)
  674.  x%, top%, 30, height%
  675. top% += height%
  676. totalShips
  677.  loop%, total%
  678.  loop% = 0 
  679.  NumberSides%
  680. s&  total% += SideTotalShips%(loop%)
  681.  loop%
  682. =total%
  683. totalResources
  684.  loop%, total%
  685.  loop% = 0 
  686.  NumberSides%
  687. {*  total% += SideTotalResources%(loop%)
  688.  loop%
  689. =total%
  690. getOrigin(
  691.  x0%, 
  692.  y0%)
  693. 'x0% = WimpBlock%!4  - WimpBlock%!20
  694. 'y0% = WimpBlock%!16 - WimpBlock%!24
  695. ------------------------------------------------------------------------- Side Window
  696. updateSideWindow(side%)
  697.  SideWindowSide% <> side% 
  698. toggleTick(SideWindowSide% + 1, SideWindowMenu%)
  699.   SideWindowSide% = side%
  700. toggleTick(side% + 1, SideWindowMenu%)
  701.  side% = -1 
  702.  side% = CurrentSide%
  703. writeIndirectedBuffer(SideWindowName%,           SideNames$(side%))
  704. writeIndirectedBuffer(SideWindowFlag%,           SideFlags$(side%))
  705. writeIndirectedBuffer(SideWindowShips%,     
  706. (SideTotalShips%(side%)))
  707. writeIndirectedBuffer(SideWindowResources%, 
  708. (SideTotalResources%(side%)))
  709. writeIndirectedBuffer(SideWindowPlanets%,   
  710. (SideTotalPlanets%(side%)))
  711. writeIndirectedBuffer(SideWindowPlayer%,    
  712. messageLookupString("Player" + 
  713. (SidePlayer%(side%))))
  714. writeIndirectedBuffer(SideWindowPlace%,     
  715. sidePlace(side%)))
  716. sidePlace(side%)
  717.  loop%, ourScore%, ourPosition%
  718. !ourScore% = 
  719. sideScore(side%)
  720. ourPosition% = 1
  721.  loop% <= NumberSides%
  722.  loop% <> side% 
  723. ;    
  724. sideScore(loop%) > ourScore% 
  725.  ourPosition% += 1
  726.   loop% += 1
  727. =ourPosition%
  728. sideScore(side%)
  729. 9= SideTotalShips%(side%) + SideTotalResources%(side%)
  730. ------------------------------------------------------------------------ World Window
  731. drawWorldWindow(x0%, y0%)
  732.  arrivalTimes%(), numberArrivalTimes%()
  733.  minusTurn%, side%, numberArriving%, currentSide%
  734.  centreX%, xentreY%, radius%
  735.  WimpBlock%!36 - x0% <= 668 
  736. #centreX% = 789: centreY% = -234
  737.  arrivalTimes%(5, NumberSides%), numberArrivalTimes%(5)
  738. getArrivalTimes(CurrentWorld%, arrivalTimes%(), numberArrivalTimes%())
  739.  minusTurn% = 5 
  740. 7  numberArriving% = numberArrivalTimes%(minusTurn%)
  741. &  radius% = 90 + (minusTurn% * 24)
  742.  numberArriving% > 0 
  743.     currentSide% = 1
  744. %    
  745.  side% = 1 
  746.  numberArriving%
  747. 6      
  748.  arrivalTimes%(minusTurn%, currentSide%)
  749.         currentSide% += 1
  750.       
  751.       :
  752. $      
  753. sideColours(currentSide%)
  754. Q      
  755. drawArrivalSector(centreX%, centreY%, radius%, side%, numberArriving%)
  756.       currentSide% += 1
  757.  side%
  758. colourBackground
  759. )    
  760.  centreX%, centreY%, radius%
  761.  minusTurn%
  762.  Draw planet
  763. colourBackground
  764.  centreX%, centreY%, 90
  765. sideColours(PlanetSide(CurrentWorld%))
  766.  centreX%, centreY%, 80
  767. drawArrivalSector(centreX%, centreY%, radius%, side%, totalSides%)
  768.  degree, degree2
  769. side% -= 1
  770.  (side% = 0) 
  771.  (totalSides% = 1) 
  772.  centreX%, centreY%, radius%
  773. :  degree  = 
  774. (       ( side%     / totalSides%) * 360)
  775. ?  degree2 = 
  776. min(((side% + 1) / totalSides%) * 360, 360))
  777.  centreX%, centreY%
  778.       centreX% + 
  779. (degree)  * radius%, centreY% + 
  780. (degree)  * radius%
  781.  &b5, centreX% + 
  782. (degree2) * radius%, centreY% + 
  783. (degree2) * radius%
  784. getArrivalTimes(planet%, 
  785.  arrivalTimes%(), 
  786.  numberArrivalTimes%())
  787.  order%, ourArrival%, maximumOurArrival%, side%
  788. .maximumOurArrival% = 
  789. (arrivalTimes%(), 1)
  790.  order% = 1 
  791.  NumberMovementOrders%
  792. 0  side% = MovementOrders%(order%, OrderSide)
  793.  side% <> 0 
  794. :    
  795.  MovementOrders%(order%, OrderPlanet) = planet% 
  796. M      ourArrival% = MovementOrders%(order%, OrderArriving) - CurrentTurn%
  797. /      
  798.  ourArrival% <= maximumOurArrival% 
  799. 1        arrivalTimes%(ourArrival%, side%) = 
  800. 1        numberArrivalTimes%(ourArrival%) += 1
  801.       
  802.         
  803.  order%
  804. updateWorldWindow(world%)
  805.  This updates the values of the WorldWindow% for name, position, etc.
  806.  shadeFlag%, loop%
  807. CurrentWorld% = world%
  808. writeIndirectedBuffer(WorldWindowName%,           PlanetName$(world%))
  809. writeIndirectedBuffer(WorldWindowX%,         
  810. (PlanetPosition(world%, 0)))
  811. writeIndirectedBuffer(WorldWindowY%,         
  812. (PlanetPosition(world%, 1)))
  813. writeIndirectedBuffer(WorldWindowFlag%,           SideFlags$(PlanetSide(world%)))
  814. writeIndirectedBuffer(WorldWindowResources%, 
  815. (PlanetResources(world%)))
  816. writeIndirectedBuffer(WorldWindowShips%,     
  817. (PlanetShips%(world%)))
  818. writeIndirectedBuffer(WorldWindowShipsDrag%,      "0")
  819.  (PlanetSide(world%) <> CurrentSide%) 
  820.  EndOfTurn% 
  821.  shadeFlag%=
  822.  shadeFlag%=
  823.  loop% = 12 
  824. shadeIcon(WorldWindow%, loop%, shadeFlag%)
  825.  loop%
  826. redrawWindowArea(WorldWindow%, 586, -432, 992, -20)
  827. updateWorldWindowShips(transferShips%)
  828.  This moves ships between the planet and available for orders, just
  829.  on the window display. Sign of transferShips%:
  830.    +ve  Increase planet store
  831.    -ve  Increase ship order stores
  832.  planetShips%, orderShips%, oldPlanetShips%
  833. aplanetShips% = 
  834. readIndirectedBuffer(WorldWindowShips%))   : oldPlanetShips% = planetShips%
  835. BorderShips%  = 
  836. readIndirectedBuffer(WorldWindowShipsDrag%))
  837.  transferShips% > 0 
  838. :  transferShips% = 
  839. min( orderShips%,  transferShips%)
  840. :  transferShips% = 
  841. max(-planetShips%, transferShips%)
  842. "planetShips% += transferShips%
  843. "orderShips%  -= transferShips%
  844.  oldPlanetShips% <> planetShips% 
  845. writeIndirectedBuffer(WorldWindowShips%,     
  846. (planetShips%))
  847. writeIndirectedBuffer(WorldWindowShipsDrag%, 
  848. (orderShips%))
  849. updateWorldWindowPlanetShips(ships%)
  850.  planetShips%, orderShips%, oldPlanetShips%
  851. &1oldPlanetShips% = PlanetShips%(CurrentWorld%)
  852. ':planetShips% = 
  853. min( 
  854. max(ships%, 0), oldPlanetShips%)
  855. )0orderShips% = oldPlanetShips% - planetShips%
  856. writeIndirectedBuffer(WorldWindowShips%,     
  857. (planetShips%))
  858. writeIndirectedBuffer(WorldWindowShipsDrag%, 
  859. (orderShips%))
  860. ---------------------------------------------------------------------- NewGame Window
  861. drawNewGameWindow(x0%, y0%)
  862.  loop%, y%, redrawStartY%, redrawEndY%
  863. 3SredrawStartY% = 
  864. min( 
  865. max((WimpBlock%!40 + 168 - y0%) / -32, 1), NumberSides%)
  866. 4TredrawEndY%   = 
  867. min(       (WimpBlock%!32 + 168 - y0%) / -32,     NumberSides%)
  868.  loop% = redrawStartY% 
  869.  redrawEndY%
  870.   y% = (-32 * loop%) - 168
  871. sideColours(loop%)
  872.   28, y%: 
  873.  SideNames$(loop%)
  874. colourBlack
  875.  296, y%: 
  876. messageLookupString("Player" + 
  877. (SidePlayer%(loop%)))
  878.  loop%
  879. updateNewGameWindowPlanets(change%)
  880.  oldNumberPlanets%
  881. B&oldNumberPlanets% = NumberPlanets%
  882. NumberPlanets% += change%
  883. D;NumberPlanets% = 
  884. max(NumberPlanets%, NumberSides% + 1)
  885.  oldNumberPlanets% <> NumberPlanets% 
  886. writeIndirectedBuffer(NewGameWindowPlanets%, 
  887. (NumberPlanets%))
  888. updateNewGameWindowSides(change%)
  889.  oldNumberSides%
  890. N"oldNumberSides% = NumberSides%
  891. NumberSides% += change%
  892. PVNumberSides% = 
  893. max(NumberSides%, 2): 
  894.  Has to be 2 or we run into RND(1) problems
  895. Q4NumberSides% = 
  896. min(NumberSides%, MaximumSides%)
  897.  oldNumberSides% <> NumberSides% 
  898. writeIndirectedBuffer(NewGameWindowSides%, 
  899. (NumberSides%))
  900.  NumberSides% >= NumberPlanets% 
  901. updateNewGameWindowPlanets(NumberPlanets% - NumberSides% + 1)
  902. redrawWindowArea(NewGameWindow%, 24, -9000, 810, -196 - (
  903. min(oldNumberSides%, NumberSides%) * 32))
  904. updateNewGameWindowRandom
  905.  This sets each side to a random non-human player.
  906.  Leave Human controlled players as they are.
  907.  loop%
  908.  loop% = 1 
  909.  NumberSides%
  910.  SidePlayer%(loop%) <> 0 
  911.  SidePlayer%(loop%) = 
  912. (NumberComputerPlayers%)
  913.  loop%
  914. redrawWindowArea(NewGameWindow%, 24, -9000, 810, -190)
  915. clickNewGameWindow(x%, y%, buttonState%)
  916.  x0%, y0%, selectedSide%, oldPlayer%
  917. getWindowState(NewGameWindow%)
  918. getOrigin(x0%, y0%)
  919. l x% = x% - x0%: y% = y0% - y%
  920. n#selectedSide% = (y% - 168) / 32
  921.  (selectedSide% >= 1) 
  922.  (selectedSide% <= NumberSides%) 
  923. p-  oldPlayer% = SidePlayer%(selectedSide%)
  924.  buttonState% = SelectClick 
  925.  oldPlayer% +=  1
  926.  buttonState% = AdjustClick 
  927.  oldPlayer% += -1
  928.  oldPlayer% < 0                      
  929.  oldPlayer% = NumberComputerPlayers%
  930.  oldPlayer% > NumberComputerPlayers% 
  931.  oldPlayer% = 0
  932. v-  SidePlayer%(selectedSide%) = oldPlayer%
  933. redrawWindowArea(NewGameWindow%, 292, -(196 + selectedSide% * 32), 810, -(162 + selectedSide% * 32))
  934. ----------------------------------------------------------------------- Battle Window
  935. startBattleWindow(planetName$, side1%, start1%, side2%, start2%)
  936. writeIndirectedBuffer(BattleWindowPlanet%,        planetName$)
  937. writeIndirectedBuffer(BattleWindowSide1%,    SideNames$(side1%))
  938. setIconForegroundColour(BattleWindow%, 5, 
  939. sideColoursNumber(side1%))
  940. writeIndirectedBuffer(BattleWindowSide2%,    SideNames$(side2%))
  941. setIconForegroundColour(BattleWindow%, 8, 
  942. sideColoursNumber(side2%))
  943. writeIndirectedBuffer(BattleWindowStart1%,   
  944. (start1%)   )
  945. writeIndirectedBuffer(BattleWindowStart2%,   
  946. (start2%)   )
  947. writeIndirectedBuffer(BattleWindowCurrent1%, 
  948. (start1%)   )
  949. writeIndirectedBuffer(BattleWindowCurrent2%, 
  950. (start2%)   )
  951. writeIndirectedBuffer(BattleWindowComment%,  
  952. messageLookupString("BInProg"))
  953. shadeIndirectedIcon(BattleWindowOk%,     
  954. shadeIndirectedIcon(BattleWindowFinish%, 
  955. ----------------------------------------------------------------------- Winner Window
  956. startWinnerWindow(winningSide%)
  957.  RiscOS2.00 doesn't seem to like the Win window, so don't bother
  958.  with it.
  959.  WimpVersion% >= 300 
  960. openWindowCentred(WinnerWindow%)
  961. writeIndirectedBuffer(WinnerWindowName%, SideNames$(winningSide%))
  962. writeIndirectedBuffer(WinnerWindowTurn%, 
  963. (CurrentTurn%))
  964. writeIndirectedBuffer(WinnerWindowFlag%, SideFlags$(winningSide%))
  965. wimpComplain("win2", SideNames$(winningSide%), 
  966. (CurrentTurn%))
  967.  Ok, finish
  968. wimpCloseDown
  969. *************************************************************************************
  970. ******************************************************************* Initializing Wimp
  971. *************************************************************************************
  972. initializeStart
  973. initializeHeap
  974. initializeMessages
  975. initializeIcons
  976. initializeWimpVariables
  977. initializeWimpSystem
  978. initializeSpriteArea("TrynthRes:Sprites")
  979. initializeFonts
  980. initializeLicence
  981. initializeNewGame
  982. ----------------------------------------------------------------------------- Licence
  983. initializeLicence
  984.  This reminds the user of the SHARWARE aspect of this software.
  985.  Reminders comes up when Trynth$Dir is changed, or every 10 load times
  986.  file%, oldPath$, newPath$, loadTimes%, remind%
  987. %file% = 
  988. ("<Trynth$Dir>.Options")
  989. #file%, oldPath$, loadTimes%
  990. #file%
  991.  "OS_ReadVarVal", "Trynth$Dir", WimpBlock%, 250, 0, 0
  992. )newPath$ = 
  993. readSysString(WimpBlock%)
  994.  oldPath$ <> newPath$  
  995.  remind% = 
  996. loadTimes% += 1
  997.  loadTimes% 
  998.  5 = 0  
  999.  remind% = 
  1000. %file% = 
  1001. ("<Trynth$Dir>.Options")
  1002. #file%, newPath$, loadTimes%
  1003. #file%
  1004.  remind% 
  1005. wimpComplain("Licence", "", "")
  1006. --------------------------------------------------------------------------- Diagnosis
  1007. initializeDiagnosis
  1008.  diagnosisPipe% 
  1009. -  diagnosisFile% = 
  1010. ("pipe::diagnosis.9")
  1011. diagnosis("")
  1012. diagnosis("               Welcome to Trynth Diagnosis window")
  1013. diagnosis("               ----------------------------------")
  1014. diagnosis("")
  1015. startTask(command$)
  1016.  "Wimp_StartTask", command$ + 
  1017. diagnosis(line$)
  1018.  diagnosisPipe% 
  1019. #diagnosisFile%, line$
  1020. ---------------------------------------------------------------------------- New Game
  1021. initializeNewGame
  1022.  reason%, finished%, buttonState%, icon%
  1023. initializeGameVariables
  1024. initializeSides
  1025. %NumberPlanets% = NumberSides% * 2
  1026. openTemplate
  1027. initializeNewGameWindow
  1028. initializeInfoWindow
  1029. initializeSaveWindow
  1030.  "Wimp_CloseTemplate"
  1031. openWindowCentred(NewGameWindow%)
  1032. initializeIconMenu
  1033. 0MainWindow%   = -99: WorldWindow%      = -99
  1034. LBattleWindow% = -99: OrdersWindow%     = -99: SortedPlanetsWindow% = -99
  1035. LGraphWindow%  = -99: StatisticsWindow% = -99: SideWindow%          = -99
  1036. LoadedGame% = 
  1037. wimpError
  1038.  (Quit% 
  1039.  finished% 
  1040.  LoadedGame%)
  1041.  "Wimp_Poll", %10011111110110110001, WimpBlock% 
  1042.  reason%
  1043.  reason% 
  1044. !    
  1045. redrawWindowRequest
  1046. .    
  1047.  "Wimp_OpenWindow",, WimpBlock%
  1048.  3: Quit% = 
  1049.  WimpBlock%!12 
  1050. <      buttonState% = WimpBlock%!8: icon% = WimpBlock%!16
  1051.       :
  1052.       
  1053.  icon% 
  1054.         
  1055.  10: finished% = 
  1056. %        
  1057.  Left planets arrow
  1058. L          
  1059.  buttonState% = SelectClick 
  1060. updateNewGameWindowPlanets(-1)
  1061. L          
  1062.  buttonState% = AdjustClick 
  1063. updateNewGameWindowPlanets( 1)
  1064. &        
  1065.  Right planets arrow
  1066. L          
  1067.  buttonState% = SelectClick 
  1068. updateNewGameWindowPlanets( 1)
  1069. L          
  1070.  buttonState% = AdjustClick 
  1071. updateNewGameWindowPlanets(-1)
  1072. %        
  1073.  Left players arrow
  1074. J          
  1075.  buttonState% = SelectClick 
  1076. updateNewGameWindowSides(-1)
  1077. J          
  1078.  buttonState% = AdjustClick 
  1079. updateNewGameWindowSides( 1)
  1080. &        
  1081.  Right players arrow
  1082. J          
  1083.  buttonState% = SelectClick 
  1084. updateNewGameWindowSides( 1)
  1085. J          
  1086.  buttonState% = AdjustClick 
  1087. updateNewGameWindowSides(-1)
  1088.     +        
  1089. updateNewGameWindowRandom
  1090.         
  1091. *          
  1092.  buttonState% = MenuClick 
  1093. @            
  1094. openMenu(IconMenu%, WimpBlock%!0, WimpBlock%!4)
  1095.           
  1096. M            
  1097. clickNewGameWindow(WimpBlock%!0, WimpBlock%!4, buttonState%)
  1098.           
  1099.       
  1100. menuSelect
  1101.  17, 18: 
  1102. userMessage
  1103.  Quit% 
  1104. wimpCloseDown: 
  1105. closeWindow(NewGameWindow%)
  1106. shadeMenuItem(1, IconMenu%, 
  1107. initializeMoreWimp
  1108. initializeWindows
  1109. initializeMenus
  1110. initializeIconBar
  1111. initializeDiagnosis
  1112. ---------------------------------------------------------------------------- Messages
  1113. initializeMessages
  1114.  length%, messages$
  1115. '$messages$ = "TrynthRes:Messages"
  1116.  "MessageTrans_FileInfo",, messages$  
  1117.  ,, length%
  1118.  MessageBlock% 16
  1119. *0MessageBlockBuffer% = 
  1120. getHeapBlock(length%)
  1121.  "MessageTrans_OpenFile", MessageBlock%, messages$, MessageBlockBuffer%
  1122. ---------------------------------------------------------------------- Wimp Variables
  1123. initializeWimpVariables
  1124.  These are Wimp related Global Variables
  1125.  Capital First Letter means global
  1126.  WimpBlock% &1000
  1127.  IndirectBlock% &1000
  1128. 5%IndirectCurrent% = IndirectBlock%
  1129. 7/TaskName$ = 
  1130. messageLookupString("TskName")
  1131. IconBarWindow% = -2
  1132. Quit% = 
  1133. diagnosisFile% =- 1
  1134. IconFlags% = &7000111
  1135. DragFromWindow% = -1
  1136.  Mouse button clicks
  1137. ?&AdjustClick =  1: MenuClick   =  2
  1138. @&SelectClick =  4: AdjustDrag  = 16
  1139. SelectDrag  = 64
  1140. ------------------------------------------------------------------------- Wimp System
  1141. initializeWimpSystem
  1142.  Should work for 2.00 and 3.00+
  1143.  messageList%
  1144. $WimpBlock% = "TASK"
  1145. JBmessageList% = WimpBlock% + 4: 
  1146.  List of WimpMessages received
  1147. KCmessageList%!0  = 2   : messageList%!4 = 3: messageList%!8 = 10
  1148. messageList%!12 = &502
  1149. messageList%!16 = 0
  1150.  Try for RiscOS 2.00, noting real RiscOS version
  1151.  "Wimp_Initialise", 200, !WimpBlock%, TaskName$ 
  1152.  WimpVersion%, TaskHandle%
  1153.  WimpVersion% >= 300 
  1154.  "Wimp_CloseDown", TaskHandle%, !WimpBlock%
  1155.  "Wimp_Initialise", 300, !WimpBlock%, TaskName$, messageList% 
  1156.  WimpVersion%, TaskHandle%
  1157. ------------------------------------------------------------------------- Sprite Area
  1158. initializeSpriteArea(fileName$)
  1159.  Loads standard Sprite file into memory
  1160.  fileType%, fileSize%
  1161.  "OS_File", 5, fileName$ 
  1162.  fileType%,,,, fileSize%
  1163.  fileType% <> 1 
  1164.  255, "Could not find sprite file: '"+fileName$+"'"
  1165. fileSize% += 16
  1166. a/SpriteAreaBlock% = 
  1167. getHeapBlock(fileSize%)
  1168. c#SpriteAreaBlock%!0  = fileSize%
  1169. SpriteAreaBlock%!4  = 0
  1170. SpriteAreaBlock%!8  = 16
  1171. SpriteAreaBlock%!12 = 0
  1172.  "OS_SpriteOp", 256 + 10, SpriteAreaBlock%, fileName$
  1173. ------------------------------------------------------------------------------ Fonts
  1174. initializeFonts
  1175.  menuFont$, menuY%, menuX%, font%, flags%
  1176.  FontReferenceBlock% 256
  1177.  font% = 0 
  1178.  251 
  1179. p#  FontReferenceBlock%!font% = 0
  1180.  font%
  1181.  MenuFonts% = 
  1182. t6  menuFont$ =     
  1183. messageLookupString("MenuFont")
  1184. u2  menuX%    = 
  1185. messageLookupString("MenuX"))
  1186. v2  menuY%    = 
  1187. messageLookupString("MenuY"))
  1188.  menuFont$ <> "System" 
  1189. yW    
  1190.  "XFont_FindFont",, menuFont$, menuX% * 16, menuY% * 16, 0, 0 
  1191.  font% ;flags%
  1192.  flags% 
  1193. {4      
  1194. wimpComplain("NoMenuFont", menuFont$, "")
  1195.       MenuFonts% = 
  1196. }        
  1197. ~'      FontReferenceBlock%?font% = 1
  1198.       :
  1199. ,      IconFlags% = IconFlags% 
  1200.  (1 << 6)
  1201. 1      IconFlags% = IconFlags% 
  1202.  ((1 <<24) -1)
  1203. 1      IconFlags% = IconFlags% 
  1204.  (font% << 24)
  1205.         
  1206.     MenuFonts% = 
  1207. loseAllFonts
  1208.  font%, loop%, uses%
  1209.  font% = 0 
  1210. '  uses% = FontReferenceBlock%?font%
  1211.  uses% > 0 
  1212.  loop% = 1 
  1213.  uses%
  1214. #      
  1215.  "Font_LoseFont", font%
  1216.  loop%
  1217.  font%
  1218. ------------------------------------------------------------------------------- Icons
  1219. initializeIcons
  1220. StandardIndirectedIcon% = 0
  1221. ----------------------------------------------------------------------------- Windows
  1222. initializeWindows
  1223. openTemplate
  1224. initializeMainWindow
  1225. initializeWorldWindow
  1226. initializeBattleWindow
  1227. initializeOrdersWindow
  1228. initializeSortedPlanetsWindow
  1229. initializeGraphWindow
  1230. initializeStatisticsWindow
  1231. initializeSideWindow
  1232. WinnerContinue% = 
  1233.  WimpVersion% >= 300 
  1234. initializeWinnerWindow
  1235.  "Wimp_CloseTemplate"
  1236. initializeNewGameWindow
  1237. wimpLoadTemplate("newgame", IndirectCurrent%)
  1238. :!(WimpBlock% + 88 + (32 * 13) + 24) = SpriteAreaBlock%
  1239. EWimpBlock%!44 = WimpBlock%!52 - ((MaximumSides% * 32) + 200 + 32)
  1240. <!(WimpBlock% + 88 + (32 * 11) +  4) = WimpBlock%!44 + 12
  1241.  "Wimp_CreateWindow",, WimpBlock% 
  1242.  NewGameWindow%
  1243. BNewGameWindowPlanets%  = 
  1244. newIndirectedIcon(NewGameWindow%, 6)
  1245. BNewGameWindowSides%    = 
  1246. newIndirectedIcon(NewGameWindow%, 2)
  1247. writeIndirectedBuffer(NewGameWindowPlanets%, 
  1248. (NumberPlanets%))
  1249. writeIndirectedBuffer(NewGameWindowSides%,   
  1250. (NumberSides%))
  1251. initializeInfoWindow
  1252. wimpLoadTemplate("info", IndirectCurrent%)
  1253. 9!(WimpBlock% + 88 + (32 * 9) + 24) = SpriteAreaBlock%
  1254.  "Wimp_CreateWindow",, WimpBlock% 
  1255.  InfoWindow%
  1256. messageLookup("TskName", 
  1257. indirectedBuffer(1), 40)
  1258. messageLookup("TskPurp", 
  1259. indirectedBuffer(2), 40)
  1260. messageLookup("TskAuth", 
  1261. indirectedBuffer(3), 40)
  1262. indirectedBuffer(4)  = TaskDate$ + 
  1263. indirectedBuffer(10) = TaskCopy$ + 
  1264. initializeSaveWindow
  1265. ASaveWindow% = 
  1266. wimpLoadCreateWindow("save", IndirectCurrent%)
  1267. *SaveWindowIcon% = 
  1268. indirectedBuffer(3)
  1269. 8SaveWindowText% = 
  1270. newIndirectedIcon(SaveWindow%, 2)
  1271. $SaveWindowIcon% = "file_099"
  1272. writeIndirectedBuffer(SaveWindowText%, "SavedGame")
  1273. initializeMainWindow
  1274. wimpLoadTemplate("main", IndirectCurrent%)
  1275. [WimpBlock%!40 = 0                        : WimpBlock%!44 = -(MaximumPlanetOffset% * 10)
  1276. @WimpBlock%!48 = MaximumPlanetOffset% * 10: WimpBlock%!52 = 0
  1277. MainWindowTitle% = WimpBlock%!72 + INSTR(FNread0String(WimpBlock%!72), "- ") + 1
  1278. )MainWindowTitle% = WimpBlock%!72 + 10
  1279.  "Wimp_CreateWindow",, WimpBlock% 
  1280.  MainWindow%
  1281. PointerOverPlanet% = -1
  1282. initializeWorldWindow
  1283. wimpLoadTemplate("world", IndirectCurrent%)
  1284. 9!(WimpBlock% + 88 + (32 * 9) + 24) = SpriteAreaBlock%
  1285.  "Wimp_CreateWindow",, WimpBlock% 
  1286.  WorldWindow%
  1287. @WorldWindowName%      = 
  1288. newIndirectedIcon(WorldWindow%,  1)
  1289. @WorldWindowX%         = 
  1290. newIndirectedIcon(WorldWindow%,  4)
  1291. @WorldWindowY%         = 
  1292. newIndirectedIcon(WorldWindow%,  6)
  1293. @WorldWindowFlag%      = 
  1294. newIndirectedIcon(WorldWindow%,  9)
  1295. @WorldWindowResources% = 
  1296. newIndirectedIcon(WorldWindow%,  8)
  1297. @WorldWindowShips%     = 
  1298. newIndirectedIcon(WorldWindow%, 13)
  1299. @WorldWindowShipsDrag% = 
  1300. newIndirectedIcon(WorldWindow%, 16)
  1301. initializeBattleWindow
  1302. IBattleWindow%     = 
  1303. wimpLoadCreateWindow("battle", IndirectCurrent%)
  1304. ABattleWindowSide1%    = 
  1305. newIndirectedIcon(BattleWindow%,  5)
  1306. ABattleWindowSide2%    = 
  1307. newIndirectedIcon(BattleWindow%,  8)
  1308. ABattleWindowStart1%   = 
  1309. newIndirectedIcon(BattleWindow%,  6)
  1310. ABattleWindowStart2%   = 
  1311. newIndirectedIcon(BattleWindow%,  9)
  1312. ABattleWindowCurrent1% = 
  1313. newIndirectedIcon(BattleWindow%,  7)
  1314. ABattleWindowCurrent2% = 
  1315. newIndirectedIcon(BattleWindow%, 10)
  1316. ABattleWindowComment%  = 
  1317. newIndirectedIcon(BattleWindow%, 11)
  1318. ABattleWindowPlanet%   = 
  1319. newIndirectedIcon(BattleWindow%,  1)
  1320. ABattleWindowOk%       = 
  1321. newIndirectedIcon(BattleWindow%, 12)
  1322. ABattleWindowFinish%   = 
  1323. newIndirectedIcon(BattleWindow%, 13)
  1324. initializeOrdersWindow
  1325. wimpLoadTemplate("orders", IndirectCurrent%)
  1326. HWimpBlock%!44 = WimpBlock%!52 - (96 + (MaximumMovementOrders% * 32))
  1327.  "Wimp_CreateWindow",, WimpBlock% 
  1328.  OrdersWindow%
  1329. initializeSortedPlanetsWindow
  1330. wimpLoadTemplate("sortplanet", IndirectCurrent%)
  1331. @WimpBlock%!44 = WimpBlock%!52 - ((NumberPlanets% * 32) + 72)
  1332.  "Wimp_CreateWindow",, WimpBlock% 
  1333.  SortedPlanetsWindow%
  1334. initializeGraphWindow
  1335. wimpLoadTemplate("graph", IndirectCurrent%)
  1336.     (GraphWindowMaximumX% = WimpBlock%!48
  1337. (GraphWindowMinimumY% = WimpBlock%!44
  1338.  "Wimp_CreateWindow",, WimpBlock% 
  1339.  GraphWindow%
  1340. initializeStatisticsWindow
  1341. wimpLoadTemplate("statistics", IndirectCurrent%)
  1342. DWimpBlock%!4 = WimpBlock%!12 - (80 + ((NumberSides% + 1) * 32) )
  1343.  "Wimp_CreateWindow",, WimpBlock% 
  1344.  StatisticsWindow%
  1345. initializeSideWindow
  1346. wimpLoadTemplate("side", IndirectCurrent%)
  1347. 9!(WimpBlock% + 88 + (32 * 9) + 24) = SpriteAreaBlock%
  1348.  "Wimp_CreateWindow",, WimpBlock% 
  1349.  SideWindow%
  1350. SideWindowSide% = -1
  1351. ?SideWindowName%       = 
  1352. newIndirectedIcon(SideWindow%,  1)
  1353. ?SideWindowShips%      = 
  1354. newIndirectedIcon(SideWindow%,  6)
  1355. ?SideWindowResources%  = 
  1356. newIndirectedIcon(SideWindow%,  7)
  1357. ?SideWindowPlanets%    = 
  1358. newIndirectedIcon(SideWindow%,  8)
  1359.  ?SideWindowFlag%       = 
  1360. newIndirectedIcon(SideWindow%,  9)
  1361. !?SideWindowPlayer%     = 
  1362. newIndirectedIcon(SideWindow%, 11)
  1363. "?SideWindowPlace%      = 
  1364. newIndirectedIcon(SideWindow%, 13)
  1365. initializeWinnerWindow
  1366. WinnerContinue% = 
  1367. (BWinnerWindow% = 
  1368. wimpLoadCreateWindow("win", IndirectCurrent%)
  1369. *@WinnerWindowName%     = 
  1370. newIndirectedIcon(WinnerWindow%, 1)
  1371. +@WinnerWindowTurn%     = 
  1372. newIndirectedIcon(WinnerWindow%, 3)
  1373. ,@WinnerWindowOk%       = 
  1374. newIndirectedIcon(WinnerWindow%, 4)
  1375. -@WinnerWindowContinue% = 
  1376. newIndirectedIcon(WinnerWindow%, 5)
  1377. .@WinnerWindowFlag%     = 
  1378. newIndirectedIcon(WinnerWindow%, 7)
  1379. ------------------------------------------------------------------------------- Menus
  1380. initializeIconMenu
  1381.  current%
  1382.  IconMenu% 200
  1383. startMenu("Trynth", IconMenu%, current%)
  1384. addMenuItem("Info", InfoWindow%,  2,  IconMenu%, current%)
  1385. addMenuItem("Save", SaveWindow%,  2,  IconMenu%, current%)
  1386. addMenuItem("Quit",          -1,  0,  IconMenu%, current%)
  1387. shadeMenuItem(1, IconMenu%, 
  1388. initializeMenus
  1389.  current%, loop%
  1390.  MainMenu% 200
  1391. startMenu("Trynth", MainMenu%, current%)
  1392. addMenuItem("NSide",         -1,  0,  MainMenu%, current%)
  1393. addMenuItem("NTurn",         -1,  2,  MainMenu%, current%)
  1394. addMenuItem("Stats",         -1,  0,  MainMenu%, current%)
  1395. addMenuItem("Orders",        -1,  0,  MainMenu%, current%)
  1396. shadeMenuItem(1, MainMenu%, 
  1397.  StatisticsMenu% 200 + (NumberSides% * 24)
  1398. startMenu("Stats", StatisticsMenu%, current%)
  1399. addMenuItem("Graphs",        -1,  0, StatisticsMenu%, current%)
  1400. addMenuItem("SortPl",        -1,  0, StatisticsMenu%, current%)
  1401. addMenuItem("SideInf",       -1,  0, StatisticsMenu%, current%)
  1402.  SideWindowMenu% 100 + (NumberSides% * 24)
  1403. startMenu("Side", SideWindowMenu%, current%)
  1404. addMenuItem("Auto",          -1,  2, SideWindowMenu%, current%)
  1405.  loop% = 0 
  1406.  NumberSides%
  1407. addMenuItem("Side" + 
  1408. (loop%), -1, 0, SideWindowMenu%, current%)
  1409.  loop%
  1410. toggleTick(SideWindowSide% + 1, SideWindowMenu%)
  1411.  GraphMenu% 200
  1412. startMenu("Graph",  GraphMenu%, current%)
  1413. addMenuItem("Ships",         -1,  0, GraphMenu%, current%)
  1414. addMenuItem("Reses",         -1,  0, GraphMenu%, current%)
  1415. addMenuItem("Planets",       -1,  0, GraphMenu%, current%)
  1416. toggleTick(CurrentGraphChoice%, GraphMenu%)
  1417. initializeIconBar
  1418. _*!WimpBlock%   = -1: WimpBlock%!4  =  0
  1419. `*WimpBlock%!8  =  0: WimpBlock%!12 = 70
  1420. a-WimpBlock%!16 = 70: WimpBlock%!20 = &303A
  1421. b:$(WimpBlock% + 24) = "!"+
  1422. stringToLowerCase(TaskName$)
  1423.  "Wimp_CreateIcon",, WimpBlock%
  1424. ----------------------------------------------------------------------- Help Messages
  1425. helpMessage
  1426.  This attempts to find a help message associated with:
  1427.    A window, and possibly the icon
  1428.    A menu item
  1429.  window%, icon%, startToken$, arg1$, arg2$
  1430. m2window% = WimpBlock%!32: icon% = WimpBlock%!36
  1431.  window% 
  1432.  IconBarWindow%      : startToken$ = "IBarWH"
  1433.  InfoWindow%         : startToken$ = "InfoWH"
  1434. qA                             
  1435.  icon% = 10 
  1436.  arg1$ = TaskCopy$
  1437.  SaveWindow%         : startToken$ = "SaveWH"
  1438.  MainWindow%         : startToken$ = "MainWH"
  1439.  StatisticsWindow%   : startToken$ = "StatWH"
  1440.  OrdersWindow%       : startToken$ = "OrdWH"
  1441.  WorldWindow%        : startToken$ = "WorWH"
  1442. xC                             arg1$ = PlanetName$(CurrentWorld%)
  1443. yN                             arg2$ = SideNames$(PlanetSide(CurrentWorld%))
  1444.  BattleWindow%       : startToken$ = "BatWH"
  1445.  GraphWindow%        : startToken$ = "GraphWH"
  1446.  SortedPlanetsWindow%: startToken$ = "SortWH"
  1447.  SideWindow%         : startToken$ = "SideWH"
  1448. ~A                             arg1$ = SideNames$(CurrentSide%)
  1449.  NewGameWindow%      : startToken$ = "NGameWH"
  1450.  WinnerWindow%       : startToken$ = "WinWH"
  1451.  Could be a Menu option that needs help. Only for post-3.00
  1452.  WimpVersion% >= 300 
  1453. D      
  1454.  "Wimp_GetMenuState", 1, WimpBlock% + 40, window%, icon%
  1455.        
  1456.  WimpBlock%!40 >= 0 
  1457. !        icon% = WimpBlock%!40
  1458.         
  1459.  CurrentMenu% 
  1460. 7          
  1461.  IconMenu%      : startToken$ = "IBarMH"
  1462. 8          
  1463.  GraphMenu%     : startToken$ = "GraphMH"
  1464. 8          
  1465.  StatisticsMenu%: startToken$ = "StatsMH"
  1466. 7          
  1467.  SideWindowMenu%: startToken$ = "SideMH"
  1468. O                                
  1469.  icon% > 0 
  1470.  arg1$ = SideNames$(icon% - 1)
  1471. 7          
  1472.  MainMenu%      : startToken$ = "MainMH"
  1473.         
  1474.       
  1475.         
  1476.  startToken$ <> "" 
  1477. sendHelpMessage(startToken$, icon%, arg1$, arg2$)
  1478. *************************************************************************************
  1479. ************************************************************************ WIMP Library
  1480. *************************************************************************************
  1481. ------------------------------------------------------------------------- Saving data
  1482. dataSave
  1483.  x0%, y0%, leafName$
  1484. IleafName$ = 
  1485. getLeafName(
  1486. readIndirectedBuffer(SaveWindowText%)) + 
  1487.  "Wimp_GetPointerInfo",, WimpBlock%
  1488. @WimpBlock%!20 = WimpBlock%!12: WimpBlock%!24 = WimpBlock%!16
  1489. ?WimpBlock%!28 = WimpBlock%!0 : WimpBlock%!32 = WimpBlock%!4
  1490. -WimpBlock%!0  = (
  1491. (leafName$) + 49) 
  1492. )WimpBlock%!12 =  0: WimpBlock%!16 = 1
  1493. +WimpBlock%!36 = -1: WimpBlock%!40 = 099
  1494. "$(WimpBlock% + 44) = leafName$
  1495.  "Wimp_SendMessage", 17, WimpBlock%, WimpBlock%!20, WimpBlock%!24
  1496. dataSaveAck(fileName$)
  1497.  Actually save data to a file
  1498. fileName$, ".")=0 
  1499. closeMenu
  1500. wimpComplain("ErrSDrag", "", "")
  1501. saveTrynthGame(fileName$)
  1502. closeMenu
  1503. writeIndirectedBuffer(SaveWindowText%, fileName$)
  1504. dataLoad
  1505.  fileName$
  1506.  (WimpBlock%!20 = NewGameWindow%) 
  1507.  (WimpBlock%!40 = &99) 
  1508. /  fileName$ = 
  1509. read0String(WimpBlock% + 44)
  1510.  "Hourglass_On"
  1511. loadTrynthGame(fileName$)
  1512.  "Hourglass_Off"
  1513.   LoadedGame% = 
  1514. getLeafName(fileName$)
  1515. fileName$, ".")
  1516. 3  fileName$ = 
  1517. fileName$, 
  1518. fileName$, ".") + 1)
  1519. =fileName$
  1520. saveTrynthGame(fileName$)
  1521.  file%
  1522.  "Hourglass_On"
  1523. file% = 
  1524. (fileName$)
  1525. saveGameVariables(file%)
  1526. saveSides(file%)
  1527. saveComputerBlock(file%)
  1528. savePlanets(file%)
  1529. saveStatistics(file%)
  1530. saveGraphs(file%)
  1531. saveSortedOnShips(file%)
  1532. saveMovementOrders(file%)
  1533. #file%
  1534. ("SetType "+fileName$+" 099")
  1535.  "Hourglass_Off"
  1536. loadTrynthGame(fileName$)
  1537.  file%
  1538. file% = 
  1539. (fileName$)
  1540. loadGameVariables(file%)
  1541. loadSides(file%)
  1542. initializeSidesTotal
  1543. initializeComputerBlock
  1544. loadComputerBlock(file%)
  1545. initializePlanetVariables
  1546. loadPlanets(file%)
  1547. loadStatistics(file%)
  1548. loadGraphs(file%)
  1549. initializeJourneyTimes
  1550. loadSortedOnShips(file%)
  1551. initializeMovementOrders
  1552. loadMovementOrders(file%)
  1553. #file%
  1554.  Message_DataLoadAck
  1555.  WimpBlock%!12 = WimpBlock%!8
  1556. WimpBlock%!16 = 4
  1557.  "Wimp_SendMessage", 17, WimpBlock%, WimpBlock%!4
  1558. ----------------------------------------------------------------------- Help Messages
  1559. sendHelpMessage(startToken$, addition%, arg1$, arg2$)
  1560.  length%, flags%
  1561.  "XMessageTrans_Lookup", MessageBlock%, startToken$ + 
  1562. (addition%), WimpBlock% + 20, 232, arg1$, arg2$ 
  1563.  ,,,length%; flags%
  1564.  flags% 
  1565.  "MessageTrans_Lookup", MessageBlock%, startToken$, WimpBlock% + 20, 232, arg1$, arg2$ 
  1566.  ,,,length%
  1567. FWimpBlock%!0  = (length% + 25) 
  1568.  3: WimpBlock%!12 = WimpBlock%!8
  1569. WimpBlock%!16 = &503
  1570.  "Wimp_SendMessage", 17, WimpBlock%, WimpBlock%!4
  1571. --------------------------------------------------------------------------- Messages
  1572. messageLookupStringArgs(token$, arg1$, arg2$)
  1573.  pointer%, length%, text$, loop%
  1574.  "MessageTrans_Lookup", MessageBlock%, token$, 0, 255, arg1$, arg2$ 
  1575.  ,, pointer%, length%
  1576.  loop% = 0 
  1577.  length% - 1
  1578.    text$ += 
  1579. (pointer%?loop%)
  1580. =text$
  1581. messageLookupString(token$)
  1582. messageLookupStringArgs(token$, "", "")
  1583. messageLookup(token$, destinationPtr%, maximumLength%)
  1584.  "MessageTrans_Lookup", MessageBlock%, token$, destinationPtr%, maximumLength%
  1585. messageLookupArgs(token$, destinationPtr%, maximumLength%, arg1$, arg2$)
  1586.  "MessageTrans_Lookup", MessageBlock%, token$, destinationPtr%, maximumLength%, arg1$, arg2$
  1587. messageLookupLength(token$, destinationPtr%, maximumLength%,
  1588.  actualLength%)
  1589.  "MessageTrans_Lookup", MessageBlock%, token$, destinationPtr%, maximumLength% 
  1590.  ,,,actualLength%
  1591. messageRead(token$, 
  1592.  address%, 
  1593.  length%)
  1594.  "MessageTrans_Lookup", MessageBlock%, token$, 0 
  1595.  ,,address%, length%
  1596. -------------------------------------------------------------------------- Close Down
  1597. wimpCloseDown
  1598.  diagnosisPipe% 
  1599.  diagnosisFile% <> -1 
  1600. #diagnosisFile%
  1601. loseAllFonts
  1602. TRACE CLOSE
  1603.  "XMessageTrans_CloseFile", WimpBlock%
  1604.  "XWimp_DragBox",, -1
  1605.  "XHourglass_Smash"
  1606. $WimpBlock% = "TASK"
  1607.  "XWimp_CloseDown", TaskHandle%, !WimpBlock%
  1608. ---------------------------------------------------------------------------- Template
  1609. openTemplate
  1610.  file$
  1611.  WimpVersion% >= 310 
  1612.  file$ = "Templ3d" 
  1613.  file$ = "Templ2d"
  1614.  "Wimp_OpenTemplate",, "TrynthRes:"+file$
  1615. wimpLoadCreateWindow(windowName$, 
  1616.  indirect%)
  1617.  window%
  1618. wimpLoadTemplate(windowName$, indirect%)
  1619.  "Wimp_CreateWindow",, WimpBlock% 
  1620.  window%
  1621. =window%
  1622. wimpLoadTemplate(windowName$, 
  1623.  indirect%)
  1624.  "Wimp_LoadTemplate",, WimpBlock%, indirect%, IndirectBlock%+&1000, FontReferenceBlock%, windowName$, 0 
  1625.  ,,indirect%
  1626. ------------------------------------------------------------------------------ Screen
  1627. screenSize(
  1628.  screenX%, 
  1629.  screenY%)
  1630.  F%, P%
  1631.  &35,-1,4 
  1632.  ,,F%
  1633.  &35,-1,11 
  1634.  ,,P%
  1635. screenX%=P%<<F%
  1636.  &35,-1,5 
  1637.  ,,F%
  1638.  &35,-1,12 
  1639.  ,,P%
  1640. screenY%=P%<<F%
  1641. ----------------------------------------------------------------------------- Windows
  1642. openWindow(window%)
  1643.  Opens a windw to the Front of the screen
  1644. !WimpBlock% = window%
  1645.  "Wimp_GetWindowState",, WimpBlock%
  1646. WimpBlock%!28 = -1
  1647.  "Wimp_OpenWindow",, WimpBlock%
  1648. openWindowCentred(window%)
  1649.  Opens a window to the Front of the screen, in centre
  1650.  screenX%, screenY%, width%, height%
  1651. !WimpBlock% = window%
  1652.  "Wimp_GetWindowInfo",, WimpBlock%
  1653. WimpBlock%!28 = -1
  1654. screenSize(screenX%, screenY%)
  1655. _+width%  = WimpBlock%!52 - WimpBlock%!44
  1656. `+height% = WimpBlock%!56 - WimpBlock%!48
  1657. aRWimpBlock%!4 = (screenX% -  width%) 
  1658.  2: WimpBlock%!12 = WimpBlock%!4 + width%
  1659. bSWimpBlock%!8 = (screenY% - height%) 
  1660.  2: WimpBlock%!16 = WimpBlock%!8 + height%
  1661.  "Wimp_OpenWindow",, WimpBlock%
  1662. reopenWindow(window%)
  1663. !WimpBlock% = window%
  1664.  "Wimp_GetWindowState",, WimpBlock%
  1665.  "Wimp_OpenWindow",, WimpBlock%
  1666. closeWindow(window%)
  1667. !WimpBlock% = window%
  1668.  "Wimp_CloseWindow",, WimpBlock%
  1669. getWindowState(window%)
  1670. !WimpBlock% = window%
  1671.  "Wimp_GetWindowState",, WimpBlock%
  1672. redrawWindowArea(window%, x0%, y0%, x1%, y1%)
  1673.  "Wimp_ForceRedraw", window%, x0%, y0%, x1%, y1%
  1674. redrawWindow(window%)
  1675.  "Wimp_ForceRedraw", window%, 0, -&7FFFFF, &7FFFFF, 0
  1676. redrawWindowTitle(window%)
  1677. WimpBlock%!0 = window%
  1678.  "Wimp_GetWindowState",, WimpBlock%
  1679.  WimpBlock%!32 
  1680.  (1 << 16) 
  1681.  "Wimp_ForceRedraw", -1, WimpBlock%!4, (WimpBlock%!16) + 4, WimpBlock%!12, (WimpBlock%!16) + 36
  1682. ------------------------------------------------------------------------------- Icons
  1683. indirectedBuffer(iconNumber%)
  1684.  Used a CreateWindow block
  1685. indirectedLookup(iconNumber%, 20)
  1686. indirectedValidation(iconNumber%)
  1687. indirectedLookup(iconNumber%, 24)
  1688. indirectedLength(iconNumber%)
  1689. indirectedLookup(iconNumber%, 28)
  1690. indirectedLookup(iconNumber%, offset%)
  1691. 3=WimpBlock%!((iconNumber% * 32) + 88 + offset%)
  1692. newBasicIcon(iconType%, size%, window%, icon%)
  1693.  block%
  1694. !block% = 
  1695. getHeapBlock(size%)
  1696. block%!0 = iconType%
  1697. *block%!4 = window%  : block%!8 = icon%
  1698. =block%
  1699. newIndirectedIcon(window%, icon%)
  1700.  Creates an 'Indircted' icon representation.
  1701.  block%
  1702. Gblock% = 
  1703. newBasicIcon(StandardIndirectedIcon%, 24, window%, icon%)
  1704. Rblock%!12 = 
  1705. indirectedBuffer(icon%): block%!16 = 
  1706. indirectedValidation(icon%)
  1707. (block%!20 = 
  1708. indirectedLength(icon%)
  1709. =block%
  1710. readIndirectedBuffer(iconBlock%)
  1711. readSysString(iconBlock%!12)
  1712. writeIndirectedBuffer(iconBlock%, text$)
  1713.  This stoes the next text$ and redraws it within the window
  1714.  shortText$, length%
  1715. length% = iconBlock%!20 - 1
  1716. !shortText$ = 
  1717. text$, length%)
  1718. !$(iconBlock%!12) = shortText$
  1719. "?(iconBlock%!12 + length%) = 0
  1720. redrawIcon(iconBlock%!4, iconBlock%!8)
  1721. shadeIndirectedIcon(iconBlock%, flag%)
  1722. shadeIcon(iconBlock%!4, iconBlock%!8, flag%)
  1723. redrawIcon(window%, icon%)
  1724. 1!WimpBlock%  = window%: WimpBlock%!4  = icon%
  1725. -WimpBlock%!8 = 0      : WimpBlock%!12 = 0
  1726.  "Wimp_SetIconState",, WimpBlock%
  1727. redrawIconList(window%, iconList%())
  1728.  This redraws every icon listed in the iconList%() array, for
  1729.  window%. SMOOTHY procedure
  1730.  loop%, length%
  1731. length% = 
  1732. (iconList%(), 1)
  1733. WimpBlock%!0 = window%
  1734. -WimpBlock%!8 = 0      : WimpBlock%!12 = 0
  1735.  loop% = 1 
  1736.  length%
  1737. %  WimpBlock%!4 = iconList%(loop%)
  1738.  "Wimp_SetIconState",, WimpBlock%
  1739.  loop%
  1740. getIconState(window%, icon%)
  1741. WimpBlock%!0 = window%
  1742. WimpBlock%!4 = icon%
  1743.  "Wimp_GetIconState",, WimpBlock%
  1744. setIconState(window%, icon%, eor%, mask%)
  1745. 1WimpBlock%!0 = window%: WimpBlock%!4  = icon%
  1746. 1WimpBlock%!8 = eor%   : WimpBlock%!12 = mask%
  1747.  "Wimp_SetIconState",, WimpBlock%
  1748. shadeIcon(window%, icon%, flag%)
  1749.  flag% 
  1750. setIconState(window%, icon%, 1 << 22, 1 << 22)
  1751. setIconState(window%, icon%,       0, 1 << 22)
  1752. setIconForegroundColour(window%, icon%, colour%)
  1753. setIconState(window%, icon%, colour% << 24, 15 << 24)
  1754. setIconBackgroundColour(window%, icon%, colour%)
  1755. setIconState(window%, icon%, colour% << 28, 15 << 28)
  1756. ------------------------------------------------------------------------------ Errors
  1757. wimpError
  1758.  response%
  1759.  0, 0
  1760. !WimpBlock% = 
  1761. @$(WimpBlock% + 4) = 
  1762. $ + " (Error code " + 
  1763. ) + ")" + 
  1764.  "Wimp_ReportError", WimpBlock%, 3, TaskName$ 
  1765.  ,response%
  1766.  response% = 2 
  1767.  Quit% = 
  1768. wimpCloseDown: 
  1769. wimpComplain(complainToken$, arg1$, arg2$)
  1770.  complain$
  1771. Fcomplain$ = 
  1772. messageLookupStringArgs(complainToken$, arg1$, arg2$)
  1773. !WimpBlock% = 0
  1774. messageLookup(complainToken$, WimpBlock% + 4, 250)
  1775.  "Wimp_ReportError", WimpBlock%, 17, TaskName$
  1776. ------------------------------------------------------------------------------- Menus
  1777. openMenu(menu%, x%, y%)
  1778.  Open a menu, remembering details in case it is to be kept open
  1779. x% -= 60
  1780. CurrentMenu% = menu%
  1781. *CurrentMenuX% = x%: CurrentMenuY% = y%
  1782.  "Wimp_CreateMenu",, menu%, x%, y%
  1783. closeMenu
  1784.  "Wimp_CreateMenu",, -1
  1785. openIconBarMenu(menu%, x%)
  1786.  This opens a menu with correct y position relative to the icon bar
  1787.  menuItemHeight%, menuItemGap%, menuHeight%, tempMenu%
  1788. 7menuItemHeight% = menu%!20: menuItemGap% = menu%!24
  1789.  menu%!0 = 0 
  1790.  menuHeight% = menuItemGap% 
  1791.  menuHeight% = menuItemHeight% + menuItemGap%
  1792. tempMenu% = menu% + 4
  1793.   tempMenu% += 24
  1794. $  menuHeight% += menuItemHeight%
  1795.  (tempMenu%!0 
  1796.  menuHeight% += 24
  1797.  (tempMenu%!0 
  1798.  &80) <> 0
  1799. openMenu(menu%, x%, menuHeight% + 56)
  1800. reopenCurrentMenu
  1801.  Tests to see if the current menu should stay open.
  1802.  (Adjust has been used to select option)
  1803.  "Wimp_GetPointerInfo",, WimpBlock%
  1804.  WimpBlock%!8 = AdjustClick 
  1805.  "Wimp_CreateMenu",, CurrentMenu%, CurrentMenuX%, CurrentMenuY%
  1806. startMenu(titleToken$, start%, 
  1807.  block%)
  1808.  length%
  1809. block% = start%
  1810. messageLookupLength(titleToken$, block%, 12, length%)
  1811. *0block%!12 = &70207: block%!16 = length% * 16
  1812. +%block%!20 =     40: block%!24 = 0
  1813. block%   += 28
  1814. addMenuItem(itemToken$, subMenu%, menuFlags%, start%, 
  1815.  current%)
  1816.  itemWidth%, length%, address%, item$
  1817. messageRead(itemToken$, address%, length%)
  1818.  current% > start% + 28 
  1819.  current%!-24 = current%!-24 
  1820. 5"current%!0  = menuFlags% 
  1821. 65current%!4  = subMenu%: current%!8  =  IconFlags%
  1822. 7,current%!12 = address%: current%!16 = -1
  1823. current%!20 = length%
  1824. current%  += 24
  1825. addMenuItemWidth(address%, length%, start%)
  1826. addMenuItemWidth(address%, charLength%, start%)
  1827.  This ensures that the menu is wide enough for all entries
  1828.  itemWidth%
  1829.  MenuFonts% 
  1830.  "Font_StringWidth",, address%, 1E8, 1E8, -1, 1E8 
  1831.  ,, itemWidth%
  1832.  "Font_ConverttoOS",, itemWidth%, 0 
  1833.  , itemWidth%
  1834. G#  itemWidth% = charLength% * 16
  1835. itemWidth% += 16
  1836.  itemWidth% > start%!16 
  1837.  start%!16 = itemWidth%
  1838. toggleTick(menuItem%, start%)
  1839.  current%
  1840. Q1current%   = (start% + 28) + (menuItem% * 24)
  1841. current%!0 = current%!0 
  1842. shadeMenuItem(menuItem%, start%, flag%)
  1843.  current%
  1844. X/current% = (start% + 28) + (menuItem% * 24)
  1845.  flag% 
  1846. Z)  current%!8 = current%!8 
  1847.  (1 << 22)
  1848. \-  current%!8 = current%!8 
  1849.  (1 << 22))
  1850. ------------------------------------------------------------------------------ Caret
  1851. removeCaret
  1852.  "Wimp_SetCaretPosition", -1
  1853. --------------------------------------------------------------------------- Drag Box
  1854. dragBox(window%, icon%)
  1855.  x0%, y0%
  1856. getWindowState(window%)
  1857. getOrigin(x0%, y0%)
  1858. getIconState(window%, icon%)
  1859. m:!WimpBlock%   = window%            : WimpBlock%!4  = 5
  1860. nLWimpBlock%!8  = x0% + WimpBlock%!8 : WimpBlock%!12 = y0% + WimpBlock%!12
  1861. oLWimpBlock%!16 = x0% + WimpBlock%!16: WimpBlock%!20 = y0% + WimpBlock%!20
  1862. p:WimpBlock%!24 = 0                  : WimpBlock%!28 = 0
  1863. qBWimpBlock%!32 = &7FFFFFFF          : WimpBlock%!36 = &7FFFFFFF
  1864. dragASprite 
  1865.  (window% = SaveWindow%) 
  1866.  "DragASprite_Start", 197, 1, "file_099", WimpBlock% + 8, WimpBlock% + 24
  1867.  "Wimp_DragBox",, WimpBlock%
  1868. ----------------------------------------------------------------------------- Pointer
  1869. getPointerInfo
  1870.  "Wimp_GetPointerInfo",, WimpBlock%
  1871. ------------------------------------------------------------------------- DragASprite
  1872. dragASprite
  1873.  Answer true if you use solid sprite dragging
  1874.  flags%, temp%
  1875.  "XOS_SWINumberFromString",, "DragASprite_Start" 
  1876.  temp% ;flags%
  1877.  "OS_Byte", 161, 28 
  1878.  ,,temp%
  1879.  ((temp% 
  1880.  2) = 2) 
  1881.  (flags% 
  1882. *************************************************************************************
  1883. *********************************************************************** Memory system
  1884. *************************************************************************************
  1885. initializeHeap
  1886.  Use Heap Manager to provide useful memory management system
  1887.  Ensure that there is 1 page of free space within the heap to use
  1888.  Assumes that App loads at &8000
  1889. HeapBlock% = 
  1890.  "OS_ReadMemMapInfo" 
  1891.  SystemPageSize%
  1892.  "Wimp_SlotSize", HeapBlock% - &8000 + SystemPageSize%, -1 
  1893.  HeapEnd%
  1894. HeapEnd% += &8000
  1895.  HeapEnd% <= HeapBlock% 
  1896.  255, "Not enough memory for Heap block"
  1897.  "OS_Heap", 0, HeapBlock%,, HeapEnd% - HeapBlock%
  1898. getHeapBlock(blockSize%)
  1899.  This attempt to get a block of memory from the HeapManager of
  1900.  size blockSize%. If it fails it attempts to increase the tasks
  1901.  SlotSize
  1902.  freeBlockSize%, slotIncrease%, oldHeapEnd%, blockPointer%
  1903.  blockSize% = 0 
  1904.  blockSize%=1: 
  1905.  Get around heap specification problem
  1906.  "OS_Heap", 1, HeapBlock% 
  1907.  ,, freeBlockSize%
  1908.  freeBlockSize% < blockSize% 
  1909.   oldHeapEnd%   = HeapEnd%
  1910. L  HeapEnd% = 
  1911. extendSlotSize((blockSize% 
  1912.  SystemPageSize%) + 1) + &8000
  1913.  "OS_Heap", 5, HeapBlock%,, HeapEnd% - oldHeapEnd%
  1914.  "OS_Heap", 1, HeapBlock% 
  1915.  ,, freeBlockSize%, t%
  1916.  freeBlockSize% < blockSize% 
  1917.  255, 
  1918. messageLookupString("HeapFree")
  1919.  "OS_Heap", 2, HeapBlock%,, blockSize% 
  1920.  ,,blockPointer%
  1921. =blockPointer%
  1922. freeHeapBlock(blockPointer%)
  1923.  freeBlockSize%, numberFreePages%, flags%
  1924.  "OS_Heap", 3, HeapBlock%, blockPointer%
  1925.  "OS_Heap", 1, HeapBlock% 
  1926.  ,, freeBlockSize%
  1927.  This isn't finished...
  1928.  freeBlockSize% > SystemPageSize% 
  1929. A    
  1930.  "XOS_Heap", 5, HeapBlock%,, -SystemPageSize% 
  1931.  ;flags%
  1932.  (flags% 
  1933.  1) = 0 
  1934.       numberFreePages% += 1
  1935. %      HeapEnd% -= SystemPageSize%
  1936.         
  1937.  flags% 
  1938.  numberFreePages% > 0 
  1939. 4    flags% = 
  1940. extendSlotSize(- numberFreePages%)
  1941. extendHeapBlock(
  1942.  blockPointer%, change%)
  1943.  Note may change blockPointer%, so have to return
  1944.  Doesn't extend the Wimp_SlotSize yet
  1945.  flags%, temp%
  1946.  "XOS_Heap", 4, HeapBlock%, blockPointer%, change% 
  1947.  ,, blockPointer% ;flags%
  1948.  flags% 
  1949.    temp% = 
  1950. extendSlotSize(1)
  1951.  "OS_Heap",  5, HeapBlock%,, SystemPageSize%
  1952.  "XOS_Heap", 4, HeapBlock%, blockPointer%, change% 
  1953.  ,, blockPointer% ;flags%
  1954. --------------------------------------------------------------------------- Slot Size
  1955. extendSlotSize(changePages%)
  1956.  This attempts to increase the Task SlotSize by the number of pages
  1957.  defined in the parameter. Error if not possible
  1958.  oldTaskSize%, newTaskSize%, actualTaskSize%
  1959.  "Wimp_SlotSize", -1, -1 
  1960.  oldTaskSize%
  1961. BnewTaskSize% = oldTaskSize% + (SystemPageSize% * changePages%)
  1962.  "Wimp_SlotSize", newTaskSize%, -1 
  1963.  actualTaskSize%
  1964.  actualTaskSize% <> newTaskSize% 
  1965.  255, "Could not extend tasks slot size"
  1966. =newTaskSize%
  1967. *************************************************************************************
  1968. ******************************************************************* Initializing Game
  1969. *************************************************************************************
  1970. initializeGame
  1971. PROCinitializeGameVariables
  1972. PROCinitializeSides
  1973. initializeSidesTotal
  1974. initializeComputerBlock
  1975. initializePlanetVariables
  1976. initializePlanets
  1977. initializeJourneyTimes
  1978. initializeStatistics
  1979. initializeGraphs
  1980. initializeSortedOnShips
  1981. initializeComputerSides
  1982. initializeMovementOrders
  1983. "StartSide%   = 
  1984. (NumberSides%)
  1985. initializeGameVariables
  1986.  dummy
  1987. -dummy = 
  1988.  Randomize the randomizer
  1989. $CurrentTurn% = 1: EndOfTurn% = 
  1990. MaximumResources% = 250
  1991. CurrentWorld% = 1
  1992. loadGameVariables(file%)
  1993. #file%, CurrentTurn%, EndOfTurn%, CurrentWorld%, NumberPlanets%, StartSide%
  1994. saveGameVariables(file%)
  1995. #file%, CurrentTurn%, EndOfTurn%, CurrentWorld%, NumberPlanets%, StartSide%
  1996. initializeSides
  1997.  Note that: Side = 0, is Neutral always
  1998.  The SidePlayer%() determines
  1999.     0  Human player
  2000.     1  Computer Player -
  2001.  loop%
  2002. (NumberSides% = 6: MaximumSides% = 10
  2003.  SideNames$(MaximumSides%), SideFlags$(MaximumSides%), SidePlayer%(MaximumSides%)
  2004.  loop% = 0 
  2005.  MaximumSides%
  2006. B  SideNames$(loop%) = 
  2007. messageLookupString("Side"  + 
  2008. (loop%))
  2009. B  SideFlags$(loop%) = 
  2010. messageLookupString("SideS" + 
  2011. (loop%))
  2012.  loop%
  2013. )SidePlayer%(0) = 99: 
  2014.  Set up Neutral
  2015. >SidePlayer%(1) = 0: SidePlayer%(2) = 2: SidePlayer%(3) = 0
  2016. >SidePlayer%(4) = 4: SidePlayer%(5) = 5: SidePlayer%(6) = 5
  2017. >SidePlayer%(7) = 4: SidePlayer%(8) = 4: SidePlayer%(9) = 2
  2018. SidePlayer%(10)= 2
  2019. NumberComputerPlayers% = 6
  2020. loadSides(file%)
  2021.  side%
  2022. #file%, CurrentSide%, EndOfTurn%
  2023. #file%, NumberSides%
  2024.  side% = 1 
  2025.  NumberSides%
  2026. #file%, SidePlayer%(side%)
  2027.  side%
  2028. saveSides(file%)
  2029.  side%
  2030. #file%, CurrentSide%, EndOfTurn%
  2031. #file%, NumberSides%
  2032.  side% = 1 
  2033.  NumberSides%
  2034. #file%, SidePlayer%(side%)
  2035.  side%
  2036. initializeSidesTotal
  2037.  SideTotalPlanets%(NumberSides%), SideTotalShips%(NumberSides%)
  2038.  SideTotalResources%(NumberSides%)
  2039. initializeComputerBlock
  2040.  Some computer players require their own block of memory to store
  2041.  bits and pieces in. This defines the appropriate areas.
  2042.  Care has to be taken in this system not to write or read outside
  2043.  the appropriate block of memory
  2044.  loop%, totalRequiredMemory%, currentComputerBlock%
  2045.  loop% = 1 
  2046.  NumberSides%
  2047. 8I  totalRequiredMemory% += 
  2048. computerRequiredMemory(SidePlayer%(loop%))
  2049.  loop%
  2050. ;<ComputerBlock%     = 
  2051. getHeapBlock(totalRequiredMemory%)
  2052. <-ComputerBlockSize% = totalRequiredMemory%
  2053.  ComputerBlockPtr%(NumberSides%)
  2054. ?*currentComputerBlock% = ComputerBlock%
  2055.  loop% = 1 
  2056.  NumberSides%
  2057. A6  ComputerBlockPtr%(loop%) = currentComputerBlock%
  2058. BL  currentComputerBlock%   += 
  2059. computerRequiredMemory(SidePlayer%(loop%))
  2060.  loop%
  2061. loadComputerBlock(file%)
  2062.  loop%, data%, total%
  2063. #file%, total%
  2064.  total% <> ComputerBlockSize% 
  2065.  1, "ComputerBlock sizes do not match!"
  2066.  loop% = ComputerBlock% 
  2067.  (ComputerBlock% + ComputerBlockSize%) - 1 
  2068. #file%, data%
  2069.   !loop% = data%
  2070.  loop%
  2071.  loop% = 1 
  2072.  NumberSides%
  2073. #file%, data%
  2074. Q7  ComputerBlockPtr%(loop%) = data% + ComputerBlock%
  2075.  loop%
  2076. saveComputerBlock(file%)
  2077.  loop%
  2078. #file%, ComputerBlockSize%
  2079.  loop% = ComputerBlock% 
  2080.  (ComputerBlock% + ComputerBlockSize%) - 1 
  2081. #file%, !loop%
  2082.  loop%
  2083.  loop% = 1 
  2084.  NumberSides%
  2085. #file%, ComputerBlockPtr%(loop%) - ComputerBlock%
  2086.  loop%
  2087. initializePlanetVariables
  2088. NumberPlanets% = 22
  2089. MaximumPlanetOffset% = 100
  2090. d!MaximumPlanetResources% = 100
  2091.  PlanetPosition(NumberPlanets%, 1)
  2092.  PlanetName$(NumberPlanets%)
  2093.  PlanetResources(NumberPlanets%)
  2094.  PlanetSide(NumberPlanets%)
  2095.  PlanetShips%(NumberPlanets%)
  2096. initializePlanets
  2097.  Temporary fiddle with NumberPlanets% to improve efficiency
  2098.  of FNuniquePlanetPosition()
  2099.  loop%, tempNumberPlanets%, defaultPlanetName$
  2100. r:defaultPlanetName$ = 
  2101. messageLookupString("DefPlanet")
  2102. s'tempNumberPlanets% = NumberPlanets%
  2103.  loop% = 1 
  2104.  tempNumberPlanets%
  2105.   NumberPlanets% = loop%
  2106. findUniquePlanetPosition(PlanetPosition(loop%, 0), PlanetPosition(loop%, 1))
  2107. w<  PlanetName$(loop%)     = defaultPlanetName$ + 
  2108. (loop%)
  2109. x9  PlanetResources(loop%) = 
  2110. (MaximumPlanetResources%)
  2111. y   PlanetSide(loop%)      = 0
  2112. z5  PlanetShips%(loop%)    = PlanetResources(loop%)
  2113.  loop%
  2114.  Set up initial planets for teams
  2115.  loop% = 1 
  2116.  NumberSides%
  2117. $  PlanetSide(loop%)      = loop%
  2118. :  PlanetResources(loop%) = MaximumPlanetResources% / 2
  2119. :  PlanetShips%(loop%)    = MaximumPlanetResources% / 2
  2120.  loop%
  2121. updateTotalPlanetShipsAverage
  2122. loadPlanets(file%)
  2123.  loop%
  2124.  loop% = 1 
  2125.  NumberPlanets%
  2126. #file%, PlanetPosition(loop%, 0), PlanetPosition(loop%, 1)
  2127. #file%, PlanetName$(loop%), PlanetResources(loop%), PlanetSide(loop%)
  2128. #file%, PlanetShips%(loop%)
  2129.  loop%
  2130. updateTotalPlanetShipsAverage
  2131. savePlanets(file%)
  2132.  loop%
  2133.  loop% = 1 
  2134.  NumberPlanets%
  2135. #file%, PlanetPosition(loop%, 0), PlanetPosition(loop%, 1)
  2136. #file%, PlanetName$(loop%), PlanetResources(loop%), PlanetSide(loop%)
  2137. #file%, PlanetShips%(loop%)
  2138.  loop%
  2139. findUniquePlanetPosition(
  2140.  x%, 
  2141. "  x% = 
  2142. (MaximumPlanetOffset%)
  2143. "  y% = 
  2144. (MaximumPlanetOffset%)
  2145. uniquePlanetPosition(x%, y%)
  2146. uniquePlanetPosition(x%, y%)
  2147.  loop%
  2148.  Make sure that we don't overlap planets on main window
  2149.  loop% = 1 
  2150.  NumberPlanets% - 1
  2151.  PlanetPosition(loop%, 0) = x% 
  2152.  PlanetPosition(loop%, 1) = y% 
  2153.  loop%
  2154.  Leave space at top left of Main window for PointerOverPlanet details
  2155.  (x% < 60) 
  2156.  (y% <= 8) 
  2157. initializeJourneyTimes
  2158. JourneySpeed%   = 20
  2159. GMaxJourneyTime% = 
  2160. ((MaximumPlanetOffset% ^ 2) * 2) / JourneySpeed%
  2161. initializeStatistics
  2162.  loop%, side%
  2163.  Set up totals for Statistics Window
  2164.  loop% = 1 
  2165.  NumberPlanets%
  2166.   side% = PlanetSide(loop%)
  2167. 7  SideTotalShips%(side%)     += PlanetShips%(loop%)
  2168. %  SideTotalPlanets%(side%)   += 1
  2169. :  SideTotalResources%(side%) += PlanetResources(loop%)
  2170.  loop%
  2171. loadStatistics(file%)
  2172.  loop%
  2173.  loop% = 0 
  2174.  NumberSides%
  2175. #file%, SideTotalShips%(loop%), SideTotalPlanets%(loop%), SideTotalResources%(loop%)
  2176.  loop%
  2177. saveStatistics(file%)
  2178.  loop%
  2179.  loop% = 0 
  2180.  NumberSides%
  2181. #file%, SideTotalShips%(loop%), SideTotalPlanets%(loop%), SideTotalResources%(loop%)
  2182.  loop%
  2183. initializeGraphs
  2184.  GraphData is stored for each turn, based on totals at the
  2185.  end of that turn for each side
  2186.    0  Total sides ships
  2187.    1  Total sides resources
  2188.    2  Total sides planets
  2189.  Data is stored in blocks, each holding 20 turns worth of information.
  2190.  Up to 20 of blocks, 4000 turns...
  2191. CurrentGraphChoice% = 1
  2192.  GraphDataMaximum%(2)
  2193. 2GraphBlockEntrySize% = (NumberSides% + 1) * 12
  2194. 4GraphSubBlockSize%   = GraphBlockEntrySize% * 20
  2195. 3GraphBlock% = 
  2196. getHeapBlock(GraphSubBlockSize%)
  2197. updateGraph
  2198. loadGraphs(file%)
  2199.  loop%, side%, start%, A%, B%, C%
  2200.  GraphDataMaximum%(2)
  2201. #file%, CurrentGraphChoice%
  2202. #file%, GraphDataMaximum%(0), GraphDataMaximum%(1), GraphDataMaximum%(2)
  2203. #file%, GraphBlockEntrySize%, GraphSubBlockSize%
  2204. PGraphBlock% = 
  2205. getHeapBlock( ((CurrentTurn% 
  2206.  20) + 1) * GraphSubBlockSize%)
  2207. /start% = GraphBlock% + GraphBlockEntrySize%
  2208.  loop% = 1 
  2209.  CurrentTurn%
  2210.  side% = 0 
  2211.  NumberSides%
  2212. #file%, A%, B%, C%
  2213.         :
  2214. 3    start%!0 = A%: start%!4 = B%: start%!8 = C%
  2215.     start% += 12
  2216.  side%
  2217.  loop%
  2218. saveGraphs(file%)
  2219.  loop%, side%, start%
  2220. #file%, CurrentGraphChoice%
  2221. #file%, GraphDataMaximum%(0), GraphDataMaximum%(1), GraphDataMaximum%(2)
  2222. #file%, GraphBlockEntrySize%, GraphSubBlockSize%
  2223. /start% = GraphBlock% + GraphBlockEntrySize%
  2224.  loop% = 1 
  2225.  CurrentTurn%
  2226.  side% = 0 
  2227.  NumberSides%
  2228. -    
  2229. #file%, start%!0, start%!4, start%!8
  2230.     start% += 12
  2231.  side%
  2232.  loop%
  2233. initializeSortedOnShips
  2234.  loop%
  2235.  PlanetSortedOnShips%(NumberPlanets%)
  2236.  loop% = 1 
  2237.  NumberPlanets%
  2238. )  PlanetSortedOnShips%(loop%) = loop%
  2239.  loop%
  2240. updatePlanetSortedOnShips
  2241. loadSortedOnShips(file%)
  2242.  loop%
  2243.  PlanetSortedOnShips%(NumberPlanets%)
  2244.  loop% = 1 
  2245.  NumberPlanets%
  2246. #file%, PlanetSortedOnShips%(loop%)
  2247.  loop%
  2248. saveSortedOnShips(file%)
  2249.  loop%
  2250.  loop% = 1 
  2251.  NumberPlanets%
  2252.     "*  
  2253. #file%, PlanetSortedOnShips%(loop%)
  2254.  loop%
  2255. initializeComputerSides
  2256.  loop%
  2257.  loop% = 1 
  2258.  NumberSides%
  2259.  SidePlayer%(loop%) 
  2260.     ,0    
  2261.  3: !(ComputerBlockPtr%(loop%)) = loop%
  2262.     -0    
  2263.  4: !(ComputerBlockPtr%(loop%)) = loop%
  2264.     .0    
  2265.  5: !(ComputerBlockPtr%(loop%)) = loop%
  2266.     /)    
  2267. spClearAttackDetails(loop%)
  2268.  loop%
  2269. initializeMovementOrders
  2270.  A movement order has the form:
  2271.  -0--   -----1-------   ------2-----  ---------3--------
  2272.  Side   Turn arriving   Number ships  Destination planet
  2273.  Note to show that a particular MovementOrder slot is free, the side
  2274.  is set to 0. Note: Neutral planets NEVER move ships, etc.
  2275.     =;MaximumMovementOrders% = 100: NumberMovementOrders% = 1
  2276.  MovementOrders%(MaximumMovementOrders%, 3)
  2277. MovementOrders%() = 0
  2278.     A%OrderSide  = 0: OrderArriving = 1
  2279.     B%OrderShips = 2: OrderPlanet   = 3
  2280. loadMovementOrders(file%)
  2281.  loop%
  2282. #file%, NumberMovementOrders%
  2283.  NumberMovementOrders% > MaximumMovementOrders% 
  2284.  255, "Saved game needs more than MaximumMovementOrders%"
  2285.  loop% = 1 
  2286.  NumberMovementOrders%
  2287.     LC  
  2288. #file%, MovementOrders%(loop%, 0), MovementOrders%(loop%, 1)
  2289.     MC  
  2290. #file%, MovementOrders%(loop%, 2), MovementOrders%(loop%, 3)
  2291.  loop%
  2292. saveMovementOrders(file%)
  2293.  loop%
  2294. #file%, NumberMovementOrders%
  2295.  loop% = 1 
  2296.  NumberMovementOrders%
  2297.     WC  
  2298. #file%, MovementOrders%(loop%, 0), MovementOrders%(loop%, 1)
  2299.     XC  
  2300. #file%, MovementOrders%(loop%, 2), MovementOrders%(loop%, 3)
  2301.  loop%
  2302. *************************************************************************************
  2303. ********************************************************************** Game Mechanics
  2304. *************************************************************************************
  2305. --------------------------------------------------------------------- Movement Orders
  2306. moveShipsFromTo(numberShips%, startPlanet%, destinationPlanet%)
  2307.  This is the top level PROC for setting movement orders.
  2308.  This procedure should be called from outside the MovementOrders module
  2309.  journeyTime%
  2310.     eAjourneyTime% = 
  2311. journeyTime(startPlanet%, destinationPlanet%)
  2312. newMovementOrder(CurrentSide%, CurrentTurn% + journeyTime%, numberShips%, destinationPlanet%)
  2313.     g.PlanetShips%(startPlanet%) -= numberShips%
  2314. redrawWindowArea(OrdersWindow%, 0, -9000, 9000, -124)
  2315. journeyTime(startPlanet%, destinationPlanet%)
  2316.  Calculates the number of turns to travel between the two planets
  2317. max( 
  2318. distanceBetweenPlanets(startPlanet%, destinationPlanet%) / JourneySpeed%), 1)
  2319. newMovementOrder(side%, arrivalTurn%, numberShips%, destinationPlanet%)
  2320.  Stores the details for a movementOrder. If there is a similar order already in
  2321.  place then the two orders are merged, so the ships arrive in one large group
  2322.  slot%, loop%, success%
  2323. success% = 
  2324.  loop% = 1 
  2325.  NumberMovementOrders%
  2326.  (MovementOrders%(loop%, 0) = side%) 
  2327.  (MovementOrders%(loop%, 1) = arrivalTurn%) 
  2328.  (MovementOrders%(loop%, 3) = destinationPlanet%) 
  2329.     x1    MovementOrders%(loop%, 2) += numberShips%
  2330.     success% = 
  2331.  loop%
  2332.  success% 
  2333.     ~$  slot% = 
  2334. nextFreeMovementOrder
  2335. '  MovementOrders%(slot%, 0) = side%
  2336. .  MovementOrders%(slot%, 1) = arrivalTurn%
  2337. .  MovementOrders%(slot%, 2) = numberShips%
  2338. 4  MovementOrders%(slot%, 3) = destinationPlanet%
  2339. nextFreeMovementOrder
  2340.  loop%
  2341.  loop% = 1 
  2342.  NumberMovementOrders%
  2343.  MovementOrders%(loop%, 0) = 0 
  2344.  =loop%
  2345.  loop%
  2346.  Have to 'add' another slot onto the end
  2347. NumberMovementOrders% += 1
  2348.  NumberMovementOrders% > MaximumMovementOrders% 
  2349.  255, 
  2350. messageLookupString("ErrFreeMov")
  2351. =NumberMovementOrders%
  2352. freeMovementOrder(slot%)
  2353.  This blanks slot%, and if it is the last slot it travels
  2354.  back through the slots trying to reduce NumberMovementOrders%
  2355. blankMovementOrder(slot%)
  2356.  (slot% = NumberMovementOrders%) 
  2357.  slot% >= 2
  2358.    NumberMovementOrders% -= 1
  2359.  MovementOrders%(NumberMovementOrders%, 0) = 0 
  2360.  slot% -= 1
  2361. blankMovementOrder(slot%)
  2362. !MovementOrders%(slot%, 0) = 0
  2363. !MovementOrders%(slot%, 1) = 0
  2364. !MovementOrders%(slot%, 2) = 0
  2365. !MovementOrders%(slot%, 3) = 0
  2366. *************************************************************************** Next Turn
  2367. nextTurn
  2368. CurrentTurn% += 1
  2369.  CurrentTurn% 
  2370.  20 = 0 
  2371.  Need to extend GraphBlock, by space for 20 more turns
  2372. extendHeapBlock(GraphBlock%, GraphSubBlockSize%)
  2373. diagnosis("Turn: "+
  2374. (CurrentTurn%)+"---------------------------------------------------")
  2375. shadeMenuItem(1, MainMenu%, 
  2376. completeMovementOrders
  2377.  Recalculate totals for use in StatisticsWindow
  2378.  "Hourglass_On"
  2379. updatePlanetResources
  2380. updatePlanetShips
  2381. updateTotalPlanetShipsAverage
  2382. updateMovedShips
  2383. updatePlanetSides
  2384. updatePlanetSortedOnShips
  2385. updateGraph
  2386.  WinnerContinue% 
  2387. findWinner
  2388. EndOfTurn% = 
  2389. shadeMenuItem(0, MainMenu%, 
  2390. shadeMenuItem(1, MainMenu%,  
  2391. updateWorldWindow(CurrentWorld%)
  2392. updateSideWindow(SideWindowSide%)
  2393. redrawWindow(OrdersWindow%)
  2394. redrawWindow(GraphWindow%)
  2395. redrawWindowArea(SortedPlanetsWindow%, 0, -9000, 1000, -64)
  2396. redrawWindowArea(StatisticsWindow%, 294, -1000, 1000, -68)
  2397.  "Hourglass_Off"
  2398. !StartSide% = 
  2399. (NumberSides%):
  2400. changeSides(StartSide%)
  2401. findWinner
  2402.  Attempts to find if there is a winner this turn.
  2403.  side%, winnerSide%, winnerTotal%, sideTotal%, totalToWin%
  2404.  side% = 0 
  2405.  NumberSides%
  2406. +  totalToWin% += SideTotalShips%(side%)
  2407. /  totalToWin% += SideTotalResources%(side%)
  2408.  side%
  2409.  Winner needs more than 60% of total ships and resources
  2410. #totalToWin% = totalToWin% * 0.6
  2411.  side% = 1 
  2412.  NumberSides%
  2413. F  sideTotal% = SideTotalShips%(side%) + SideTotalResources%(side%)
  2414.  (sideTotal% > totalToWin%) 
  2415.  (sideTotal% > winnerTotal%) 
  2416.     winnerSide%  = side%
  2417. !    winnerTotal% = sideTotal%
  2418.  side%
  2419.  winnerSide% <> 0 
  2420.  We have a winner
  2421.  "Hourglass_Off"
  2422. startWinnerWindow(winnerSide%)
  2423. wimpPoll
  2424.  WinnerContinue%
  2425.  "Hourglass_On"
  2426. updatePlanetResources
  2427.  loop%, newResources%, side%
  2428. SideTotalResources%() = 0
  2429.  loop% = 1 
  2430.  NumberPlanets%
  2431.   side% = PlanetSide(loop%)
  2432.  side% > 0 
  2433. D    newResources% = 
  2434. resourcesIncreaseTo(PlanetResources(loop%))
  2435. .    PlanetResources(loop%) = newResources%
  2436. .    newResources% = PlanetResources(loop%)
  2437. 1  SideTotalResources%(side%) += newResources%
  2438.  loop%
  2439. resourcesIncreaseTo(currentResources%)
  2440.  Increases currentResources% by one turn
  2441. min(MaximumResources%, 
  2442. max(currentResources% + 1, currentResources% * 1.05)) )
  2443. shipsIncreaseFromResourcesOver(currentResources%, turns%)
  2444.  Predicts the extra ships gained due to resources over a number of turns%
  2445.  loop%, shipsIncrease%
  2446.  loop% = 1 
  2447.  turns%
  2448. B  currentResources% += 
  2449. resourcesIncreaseTo(currentResources%)
  2450. 1  shipsIncrease%    += currentResources% 
  2451.  loop%
  2452. =shipsIncrease%
  2453. updatePlanetShips
  2454.  loop%, newShips%, side%
  2455. SideTotalShips%() = 0
  2456.  loop% = 1 
  2457.  NumberPlanets%
  2458.   side% = PlanetSide(loop%)
  2459.  side% > 0 
  2460. G    newShips% = (PlanetResources(loop%) 
  2461.  10) + PlanetShips%(loop%)
  2462. '    PlanetShips%(loop%) = newShips%
  2463. '    newShips% = PlanetShips%(loop%)
  2464. )  SideTotalShips%(side%) += newShips%
  2465.  loop%
  2466. updateTotalPlanetShipsAverage
  2467.  planet%
  2468. TotalPlanetShipsAverage = 0
  2469.  planet% = 1 
  2470.  NumberPlanets%
  2471.  6  TotalPlanetShipsAverage += PlanetShips%(planet%)
  2472.  planet%
  2473. "FTotalPlanetShipsAverage = TotalPlanetShipsAverage / NumberPlanets%
  2474. updatePlanetSides
  2475.  loop%, side%
  2476. SideTotalPlanets%() = 0
  2477.  loop% = 1 
  2478.  NumberPlanets%
  2479.   side% = PlanetSide(loop%)
  2480. +#  SideTotalPlanets%(side%) += 1
  2481.  loop%
  2482. updateMovedShips
  2483.  This just adds details for ships that are being moved to the
  2484.  SideTotalShips%()
  2485.  loop%, side%
  2486.  loop% = 1 
  2487.  NumberMovementOrders%
  2488. 5'  side% = MovementOrders%(loop%, 0)
  2489.  side% > 0 
  2490.  SideTotalShips%(side%) += MovementOrders%(loop%, 2)
  2491.  loop%
  2492. updateGraph
  2493.  loop%, totalShips%, totalResources%, totalPlanets%, graphPointer%
  2494. =GgraphPointer% = GraphBlock% + (GraphBlockEntrySize% * CurrentTurn%)
  2495.  loop% = 0 
  2496.  NumberSides%
  2497. ?.  totalShips%     = SideTotalShips%(loop%)
  2498. @2  totalResources% = SideTotalResources%(loop%)
  2499. A0  totalPlanets%   = SideTotalPlanets%(loop%)
  2500. CH  GraphDataMaximum%(0) = 
  2501. max(totalShips%,     GraphDataMaximum%(0))
  2502. DH  GraphDataMaximum%(1) = 
  2503. max(totalResources%, GraphDataMaximum%(1))
  2504. EH  GraphDataMaximum%(2) = 
  2505. max(totalPlanets%,   GraphDataMaximum%(2))
  2506. G#  graphPointer%!0 = totalShips%
  2507. H'  graphPointer%!4 = totalResources%
  2508. I%  graphPointer%!8 = totalPlanets%
  2509.   graphPointer% += 12
  2510.  loop%
  2511. updatePlanetSortedOnShips
  2512.  Sort planets into increasing PlanetShips%()
  2513.  loop%, minimum%, loop2%, nextPlanet%
  2514.  loop%= 1 
  2515.  NumberPlanets% - 1
  2516. T:  minimum% = PlanetShips%(PlanetSortedOnShips%(loop%))
  2517.  loop2% = loop% + 1 
  2518.  NumberPlanets%
  2519. W2    nextPlanet% = PlanetSortedOnShips%(loop2%)
  2520. X0    
  2521.  PlanetShips%(nextPlanet%) < minimum% 
  2522. YF      
  2523.  PlanetSortedOnShips%(loop%), PlanetSortedOnShips%(loop2%)
  2524. Z.      minimum% = PlanetShips%(nextPlanet%)
  2525. [        
  2526.  loop2%
  2527.  loop%
  2528. completeMovementOrders
  2529.  Goes through all MovementOrders%(). Any that complete this turn are
  2530.  processed then removed from the MovementOrders() list
  2531.  loop%
  2532.  Firstly all ships arriving at a planet they own, are added to that
  2533.  planets ships stockpile before any battles are computed
  2534.  loop% = 1 
  2535.  NumberMovementOrders%
  2536.  (MovementOrders%(loop%, 0) > 0) 
  2537.  (MovementOrders%(loop%, 1) = CurrentTurn%) 
  2538. iM    
  2539.  PlanetSide(MovementOrders%(loop%, 3)) = MovementOrders%(loop%, 0) 
  2540. j!      
  2541. movementArrival(loop%)
  2542. k        
  2543.  loop%
  2544.  Now compute any battles
  2545.  loop% = 1 
  2546.  NumberMovementOrders%
  2547.  (MovementOrders%(loop%, 0) > 0) 
  2548.  (MovementOrders%(loop%, 1) = CurrentTurn%) 
  2549. movementArrival(loop%)
  2550.  loop%
  2551.  Close BattleWindow% if it ever opened
  2552. closeWindow(BattleWindow%)
  2553. movementArrival(slot%)
  2554.  A group of ships have arrived at their destination. They either add
  2555.  themselves to the existing ships if the planet is theirs, or attack
  2556.  it if not
  2557.  planet%, arrivalSide%, planetSide%, arrivalNumber%, planetNumber%
  2558. .planet%        = MovementOrders%(slot%, 3)
  2559. .arrivalSide%   = MovementOrders%(slot%, 0)
  2560. (planetSide%    = PlanetSide(planet%)
  2561. .arrivalNumber% = MovementOrders%(slot%, 2)
  2562. *planetNumber%  = PlanetShips%(planet%)
  2563.  arrivalSide% = planetSide% 
  2564. -  PlanetShips%(planet%) += arrivalNumber%
  2565. openWindow(BattleWindow%)
  2566. computeBattle(planet%, planetSide%, planetNumber%, arrivalSide%, arrivalNumber%)
  2567. freeMovementOrder(loop%)
  2568. computeBattle(planet%, planetSide%, planetShips%, arrivalSide%, arrivalShips%)
  2569.  This calculates result of one battle, with Multitasking display of progress
  2570.  wimpMask%, reason%, quit%, finishedBattle%, startTotalShips%
  2571. BattleWorld% = planet%
  2572. startBattleWindow(PlanetName$(planet%), planetSide%, planetShips%, arrivalSide%, arrivalShips%)
  2573. 3startTotalShips% = planetShips% + arrivalShips%
  2574. "quit% = 
  2575. : finishedBattle% = 
  2576. %wimpMask% = %10011111110000110000
  2577.  "Wimp_Poll", wimpMask%, WimpBlock% 
  2578.  reason%
  2579.  reason% 
  2580. 7      
  2581. nextBattleRound(planetShips%, arrivalShips%)
  2582. 8      
  2583.  (planetShips% <= 0) 
  2584.  (arrivalShips% <= 0) 
  2585. %        wimpMask% = wimpMask% 
  2586.         finishedBattle% = 
  2587.         :
  2588. !        
  2589.  arrivalShips% > 0 
  2590. E          
  2591. successfulAttack(planet%, arrivalSide%, arrivalShips%)
  2592.         
  2593. 8          
  2594. unsuccessfulAttack(planet%, planetShips%)
  2595.         
  2596. 8        
  2597. shadeIndirectedIcon(BattleWindowOk%,     
  2598. 8        
  2599. shadeIndirectedIcon(BattleWindowFinish%, 
  2600. R        
  2601. planetDamage(planet%, startTotalShips% - arrivalSide% - planetShips%)
  2602.       
  2603. !    
  2604. redrawWindowRequest
  2605. /    
  2606.  "Wimp_OpenWindow",,  WimpBlock%
  2607. /    
  2608.  "Wimp_CloseWindow",, WimpBlock%
  2609. .    
  2610.  WimpBlock%!12 = BattleWindow% 
  2611. D        
  2612.   WimpBlock%!16 = 12  
  2613.      finishedBattle% 
  2614.  quit% = 
  2615. c        
  2616.  (WimpBlock%!16 = 13) 
  2617.  finishedBattle% 
  2618. finishBattle(planetShips%, arrivalShips%)
  2619.       
  2620.         
  2621. mouseButtonChange
  2622.       
  2623. keyPressed
  2624. menuSelect
  2625.  17, 18: 
  2626. userMessage
  2627.  quit% 
  2628.  Quit%
  2629. PROCcloseWindow(BattleWindow%)
  2630. nextBattleRound(
  2631.  planetShips%, 
  2632.  arrivalShips%)
  2633.  This does the actual calculations of the combat. It works one shot
  2634.  at the time, updating BattleWindow on the way for efficiency
  2635.  total%
  2636.  (planetShips% <= 0) 
  2637.  (arrivalShips% <= 0) 
  2638. )total% = planetShips% + arrivalShips%
  2639. (total%) > planetShips% 
  2640.   planetShips% -= 1
  2641. writeIndirectedBuffer(BattleWindowCurrent1%, 
  2642. (planetShips%))
  2643.   arrivalShips% -= 1
  2644. writeIndirectedBuffer(BattleWindowCurrent2%, 
  2645. (arrivalShips%))
  2646. finishBattle(
  2647.  planetShips%, 
  2648.  arrivalShips%)
  2649.  total%
  2650.  (planetShips% > 1) 
  2651.  (arrivalShips% > 1)
  2652. +  total% = planetShips% + arrivalShips%
  2653. (total%) > planetShips% 
  2654.  planetShips% -=1 
  2655.  arrivalShips% -= 1
  2656. writeIndirectedBuffer(BattleWindowCurrent1%, 
  2657. (planetShips%))
  2658. writeIndirectedBuffer(BattleWindowCurrent2%, 
  2659. (arrivalShips%))
  2660. ------------------------------------------------------------------ Outcome of attacks
  2661. successfulAttack(planet%, arrivalSide%, arrivalShips%)
  2662. &PlanetSide(planet%) = arrivalSide%
  2663. )PlanetShips%(planet%) = arrivalShips%
  2664. writeIndirectedBuffer(BattleWindowComment%, 
  2665. messageLookupString("AWon"))
  2666. redrawPlanet(planet%)
  2667. unsuccessfulAttack(planet%, planetSide%)
  2668. 'PlanetShips%(planet%) = planetSide%
  2669. writeIndirectedBuffer(BattleWindowComment%, 
  2670. messageLookupString("DWon"))
  2671. redrawPlanet(planet%)
  2672. planetDamage(planet%, shipsDestroyed%)
  2673.  If there has been a lot of damage, then it is possible to reduce
  2674.  the resources of a planet becuase of the battle
  2675.  planetDamage, resourcesLost%
  2676. XplanetDamage% = 
  2677. min(shipsDestroyed% / 25, 25) / 100) * PlanetResources(planet%))
  2678. -PlanetResources(planet%) -= planetDamage%
  2679. -------------------------------------------------------------------------------- Bits
  2680. nextSide
  2681.  This is called when the CurrentSide% has finished, and the next side
  2682.  takes over control.
  2683.  If all sides have had a go this turn then, the next turn will begin
  2684.  newSide%
  2685. newSide% = CurrentSide% + 1
  2686.  newSide% > NumberSides% 
  2687.  newSide% = 1
  2688.  newSide% = StartSide% 
  2689. PROCnextTurn
  2690.  Need a Next Turn. Let user select it from MainMenu
  2691.  Also redraw everything to update windows
  2692. shadeMenuItem(0, MainMenu%, 
  2693. shadeMenuItem(1, MainMenu%, 
  2694.   EndOfTurn% = 
  2695. messageLookup("EndTurn", MainWindowTitle%, 20)
  2696. redrawWindowTitle(MainWindow%)
  2697. wimpPoll
  2698. updateWorldWindow(CurrentWorld%)
  2699. changeSides(newSide%)
  2700. changeSides(newSide%)
  2701.  CurrentSide%      = newSide%
  2702. ,$MainWindowTitle% = SideNames$(newSide%)
  2703. redrawWindowTitle(MainWindow%)
  2704. wimpPoll
  2705. computerMove(newSide%)
  2706. updatePlanetSortedOnShips
  2707.  SidePlayer%(newSide%) = 0 
  2708.  Update displays if this player is a human.
  2709.  Computers don't read the windows...
  2710. updateSideWindow(SideWindowSide%)
  2711. updateWorldWindow(CurrentWorld%)
  2712. redrawWindowArea(OrdersWindow%, 0, -9000, 9000, -124)
  2713. redrawWindow(GraphWindow%)
  2714. redrawWindowArea(SortedPlanetsWindow%, 0, -9000, 9000, -64)
  2715. updateSideWindow(SideWindowSide%)
  2716. *************************************************************************************
  2717. ********************************************************************* Computer player
  2718. *************************************************************************************
  2719. computerMove(side%)
  2720.  SidePlayer%(side%) <> 0 
  2721.  "Hourglass_On"
  2722.  SideTotalPlanets%(side%) > 0 
  2723.  SidePlayer%(side%) 
  2724. /%    
  2725. cmoveMadAttacker(side%)
  2726. 0/    
  2727. cmoveRestrainedMadAttacker(side%)
  2728. 1!    
  2729. cmoveBuildUp(side%)
  2730. 2"    
  2731. cmoveBuildUp2(side%)
  2732. 3     
  2733. cmoveExpert(side%)
  2734. cmoveSp(side%)
  2735.  "Hourglass_Off"
  2736. nextSide
  2737.  Skip human if they are dead
  2738.  (SideTotalShips%(side%) = 0) 
  2739.  (SideTotalPlanets%(side%) = 0) 
  2740. nextSide
  2741. computerRequiredMemory(player%)
  2742.  memory%
  2743.  player% 
  2744.  3: memory% = 4
  2745.  4: memory% = 4
  2746.  5: memory% = 4
  2747.  6: memory% = 12
  2748. =memory%
  2749. *************************************************************************************
  2750. ************************************************************************ Mad Attacker
  2751. *************************************************************************************
  2752. cmoveMadAttacker(computerSide%)
  2753.  This is a quick stab at a computer player.
  2754.  Adds a bit of complexity to the game
  2755.  loop%, loop2%, myShips%, transferShips%, tooStrong%, theirPlanet%
  2756.  loop% = 1 
  2757.  NumberPlanets%
  2758.  PlanetSide(loop%) = computerSide% 
  2759. V'    myShips%  = PlanetShips%(loop%)
  2760. W        :
  2761. X"    loop2% = 0: tooStrong% = 
  2762. Y        
  2763.       loop2% += 1
  2764. [5      theirPlanet% = PlanetSortedOnShips%(loop2%)
  2765. \7      
  2766.  PlanetSide(theirPlanet%) <> computerSide% 
  2767. ]I        transferShips% = 
  2768. calculateTransferShips(theirPlanet%, loop%)
  2769. ^$        
  2770.  transferShips% <> -1 
  2771. _+          
  2772.  transferShips% < myShips% 
  2773. `E            
  2774. moveShipsFromTo(transferShips%, loop%, theirPlanet%)
  2775. a.            myShips% = PlanetShips%(loop%)
  2776.           
  2777.             tooStrong% = 
  2778.           
  2779.         
  2780.       
  2781.  tooStrong%
  2782.  loop%
  2783. *************************************************************************************
  2784. ************************************************************* Restrained Mad Attacker
  2785. *************************************************************************************
  2786. cmoveRestrainedMadAttacker(computerSide%)
  2787.  This is a quick stab at a computer player.
  2788.  Adds a bit of complexity to the game
  2789.  loop%, loop2%, myShips%, transferShips%, tooStrong%, theirPlanet%
  2790.  loop% = 1 
  2791.  NumberPlanets%
  2792.  PlanetSide(loop%) = computerSide% 
  2793. w'    myShips%  = PlanetShips%(loop%)
  2794. x        :
  2795. y"    loop2% = 0: tooStrong% = 
  2796. z        
  2797.       loop2% +=1
  2798. |5      theirPlanet% = PlanetSortedOnShips%(loop2%)
  2799. }7      
  2800.  PlanetSide(theirPlanet%) <> computerSide% 
  2801. ~I        transferShips% = 
  2802. calculateTransferShips(theirPlanet%, loop%)
  2803. $        
  2804.  transferShips% <> -1 
  2805. k          
  2806.  (myShips% - transferShips% >= (PlanetResources(loop%) 
  2807.  2)) 
  2808.  (transferShips% < myShips%) 
  2809. E            
  2810. moveShipsFromTo(transferShips%, loop%, theirPlanet%)
  2811. .            myShips% = PlanetShips%(loop%)
  2812.           
  2813.             tooStrong% = 
  2814.           
  2815.         
  2816.       
  2817.  tooStrong%
  2818.  loop%
  2819. calculateTransferShips(planet%, fromPlanet%)
  2820.  This attempts to calculate the number of ships that
  2821.  are required to send to a planet to take it over.
  2822.  Returns +inf if sufficient ships on their way
  2823.  requiredShips%, loop%, inf%, currentShips%
  2824. 5requiredShips% = PlanetShips%(planet%) * 1.25 + 2
  2825.  loop% = 1 
  2826.  NumberMovementOrders%
  2827.  (MovementOrders%(loop%, 0) = CurrentSide%) 
  2828.  (MovementOrders%(loop%, 3) = planet%) 
  2829. (    
  2830.  Ships are going, but how many?
  2831. 1    currentShips% = MovementOrders%(loop%, 2)
  2832. +    
  2833.  currentShips% >= requiredShips% 
  2834.       =-1
  2835.         
  2836. L      
  2837.  Boost quantity of ships if arrive at time date and are necessary
  2838. }      
  2839. journeyTime(fromPlanet%, planet%) = (MovementOrders%(loop%, 1) - CurrentTurn%) 
  2840.  =requiredShips% - currentShips%
  2841.         
  2842.  loop%
  2843. =requiredShips%
  2844. *************************************************************************************
  2845. **************************************************************************** Build Up
  2846. *************************************************************************************
  2847. cmoveBuildUp(computerSide%)
  2848.  The idea of this computer player is that it tries to keep hold of its
  2849.  planets by leaving a fair number on there. The excess ships it moves
  2850.  to a central planet. From here it decides what to attack.
  2851.  centralPlanet%, planet%, loop%, freeShips%, requiredShips%, resourceShips%
  2852. 8centralPlanet% = !(ComputerBlockPtr%(computerSide%))
  2853.  Ensure the centralPlanet is still ours, if not, find our planet with
  2854.  the highest number of ships on it. Making it our new central planet
  2855.  PlanetSide(centralPlanet%) <> computerSide% 
  2856.    loop% = NumberPlanets% + 1
  2857.     loop% -= 1
  2858. -    planet% = PlanetSortedOnShips%(loop%)
  2859.  PlanetSide(planet%) = computerSide%
  2860. 3  !(ComputerBlockPtr%(computerSide%)) = planet%
  2861.    centralPlanet% = planet%
  2862.  Send any excess ships to central planet. Make sure that the number
  2863.  of ships left is at least 1/6 of PlanetResources() or 2/3 TotalPlanetShipsAverage
  2864.  planet% = 1 
  2865.  NumberPlanets%
  2866.  (PlanetSide(planet%) = computerSide%) 
  2867.  (planet% <> centralPlanet%) 
  2868.     freeShips% = 
  2869. min(PlanetShips%(planet%) - ((2 / 3) * TotalPlanetShipsAverage), PlanetShips%(planet%) - (PlanetResources(planet%) * 0.6))
  2870.  freeShips% > 0 
  2871. ?      
  2872. moveShipsFromTo(freeShips%, planet%, centralPlanet%)
  2873.         
  2874.  planet%
  2875.  Now possibly move any excess held at central planet.
  2876.  Keep more ships at home base because of its importance
  2877. WfreeShips% = PlanetShips%(centralPlanet%) - (PlanetResources(centralPlanet%) * 0.7)
  2878. loop% = 0
  2879.   loop% += 1
  2880. !  planet% = 
  2881. (NumberPlanets%)
  2882. N  requiredShips% = 
  2883. calculateTransferShipsBuildUp(planet%, centralPlanet%)
  2884.  (loop% = 4) 
  2885.  ((requiredShips% <= freeShips%) 
  2886.  (requiredShips% <> -1))
  2887.  If we can, send the ships off. Good luck!!
  2888.  But we may also send off more ships than is required because of
  2889.  the planets large resources.
  2890.  (requiredShips% <= freeShips%) 
  2891.  (freeShips% > 0) 
  2892. 5  resourceShips% = PlanetResources(planet%) * 0.6
  2893.  resourceShips% >= freeShips% 
  2894. #    requiredShips% = freeShips%
  2895. K    
  2896.  resourceShips% > requiredShips% 
  2897.  requiredShips% = resourceShips%
  2898. moveShipsFromTo(requiredShips%, centralPlanet%, planet%)
  2899. calculateTransferShipsBuildUp(planet%, centralPlanet%)
  2900.  This calculates how many ships will have to be sent to planet% to take
  2901.  it over from centralPlanet%
  2902.  loop%, side%
  2903. &side% = PlanetSide(centralPlanet%)
  2904.  PlanetSide(planet%) <> side% 
  2905.  loop% = 1 
  2906.  NumberMovementOrders%
  2907. W    
  2908.  (MovementOrders%(loop%, 0) = side%) 
  2909.  (MovementOrders%(loop%, 3) = planet%) 
  2910. E      
  2911.  We have already sent ships there. Forget it at this stage
  2912.       = -1
  2913.         
  2914.  loop%
  2915.  There are no troops on the way, therefore calculate a value
  2916. ( (PlanetShips%(planet%) + 
  2917. shipsIncreaseFromResourcesOver(PlanetResources(planet%), 
  2918. journeyTime(centralPlanet%, planet%))) * 1.3 )
  2919.   = -1
  2920. *************************************************************************************
  2921. ************************************************************************** Build Up 2
  2922. *************************************************************************************
  2923. cmoveBuildUp2(computerSide%)
  2924.  The idea of this computer player is that it tries to keep hold of its
  2925.  planets by leaving a fair number on there. The excess ships it moves
  2926.  to a central planet. From here it decides what to attack.
  2927.  This includes a number of 'improvements' over BuildUp
  2928.  centralPlanet%, planet%, loop%, freeShips%, requiredShips%, resourceShips%, planetShips%
  2929.  repeatTimes%
  2930. 8centralPlanet% = !(ComputerBlockPtr%(computerSide%))
  2931.  Ensure the centralPlanet is still ours, if not, find our planet with
  2932.  the highest number of ships on it. Making it our new central planet
  2933.  PlanetSide(centralPlanet%) <> computerSide% 
  2934.    loop% = NumberPlanets% + 1
  2935.     loop% -= 1
  2936. -    planet% = PlanetSortedOnShips%(loop%)
  2937.  PlanetSide(planet%) = computerSide%
  2938. 3  !(ComputerBlockPtr%(computerSide%)) = planet%
  2939.    centralPlanet% = planet%
  2940.  Send any excess ships to central planet. Make sure that the number
  2941.  of ships left is at least 1/6 of PlanetResources() or 2/3 TotalPlanetShipsAverage
  2942.  If ships are coming this way may have to retreat to centralPlanet, or build up
  2943.  ships on the planet
  2944.  planet% = 1 
  2945.  NumberPlanets%
  2946.  (PlanetSide(planet%) = computerSide%) 
  2947.  (planet% <> centralPlanet%) 
  2948. ,    planetShips% = PlanetShips%(planet%)
  2949. ~    freeShips% = 
  2950. min(planetShips% - ((2 / 3) * TotalPlanetShipsAverage), planetShips% - (PlanetResources(planet%) * 0.6))
  2951.         :
  2952.     requiredShips% = 0
  2953. +    
  2954.  loop% = 1 
  2955.  NumberMovementOrders%
  2956. b      
  2957.  (MovementOrders%(loop%, 0) <> computerSide%) 
  2958.  (MovementOrders%(loop%, 3) = planet%) 
  2959. S        requiredShips% = 
  2960. max(MovementOrders%(loop%, 2), requiredShips% * 1.10)
  2961.        
  2962.  loop%
  2963.         :
  2964. +    
  2965.  (planetShips% < requiredShips%) 
  2966. 2      
  2967.  planetShips% * 1.10 < requiredShips% 
  2968.  C        
  2969. moveShipsFromTo(planetShips%, planet%, centralPlanet%)
  2970.       
  2971. "        
  2972. #O      freeShips% = 
  2973. min(planetShips% - (requiredShips% * 1.10), freeShips%)
  2974. $R      
  2975.  freeShips% > 0 
  2976. moveShipsFromTo(freeShips%, planet%, centralPlanet%)
  2977. %        
  2978.  planet%
  2979.  Now possibly move any excess held at central planet.
  2980.  Keep more ships at home base because of its importance
  2981. +0loop% = 0: repeatTimes% = NumberPlanets% / 4
  2982.   loop% += 1
  2983. .Y  freeShips% = PlanetShips%(centralPlanet%) - (PlanetResources(centralPlanet%) * 0.7)
  2984. /!  planet% = 
  2985. (NumberPlanets%)
  2986. 0O  requiredShips% = 
  2987. calculateTransferShipsBuildUp2(planet%, centralPlanet%)
  2988.  requiredShips% >= 0 
  2989. 34    
  2990.  If we can, send the ships off. Good luck!!
  2991. 4I    
  2992.  But we may also send off more ships than is required because of
  2993. 5&    
  2994.  the planets large resources.
  2995. 6I    
  2996.  Try to get at least 2/3 of TotalPlanetShipsAverage after battle
  2997. 7=    
  2998.  (requiredShips% <= freeShips%) 
  2999.  (freeShips% > 0) 
  3000. 8b      resourceShips% = 
  3001. max(PlanetResources(planet%) * 0.6, (2 / 3) * TotalPlanetShipsAverage)
  3002. 9*      
  3003.  resourceShips% >= freeShips% 
  3004. :'        requiredShips% = freeShips%
  3005.       
  3006. <O        
  3007.  resourceShips% > requiredShips% 
  3008.  requiredShips% = resourceShips%
  3009.       
  3010.       :
  3011. ?C      
  3012. moveShipsFromTo(requiredShips%, centralPlanet%, planet%)
  3013. @        
  3014.  (loop% = repeatTimes%)
  3015. calculateTransferShipsBuildUp2(planet%, centralPlanet%)
  3016.  This calculates how many ships will have to be sent to planet% to take
  3017.  it over from centralPlanet%
  3018.  This also takes into account the number of ships from other sides
  3019.  heading for the planet
  3020.  loop%, side%, transitShips%
  3021. L&side% = PlanetSide(centralPlanet%)
  3022.  PlanetSide(planet%) <> side% 
  3023.  loop% = 1 
  3024.  NumberMovementOrders%
  3025. O1    
  3026.  (MovementOrders%(loop%, 3) = planet%) 
  3027. P/      
  3028.  MovementOrders%(loop%, 0) = side% 
  3029. QG        
  3030.  We have already sent ships there. Forget it at this stage
  3031.         = -1
  3032.       
  3033. TI        
  3034.  another side is sending ships. Have to send more than them!
  3035. UJ        transitShips% = 
  3036. max(MovementOrders%(loop%, 2), transitShips%)
  3037.       
  3038. W        
  3039.  loop%
  3040.  There are no troops on the way, therefore calculate a value
  3041. max( PlanetShips%(planet%) + 
  3042. shipsIncreaseFromResourcesOver(PlanetResources(planet%), 
  3043. journeyTime(centralPlanet%, planet%)), transitShips%) * 1.3 )
  3044.   = -1
  3045. *************************************************************************************
  3046. ****************************************************************************** Expert
  3047. *************************************************************************************
  3048. cmoveExpert(computerSide%)
  3049.  This is another computer player, set out on a depth first, backtracking (???)
  3050.  Expet System style.
  3051.  Hopefully is the best computer player
  3052.  ourPlanets%()
  3053.  planets%, totalPlanets%, central%
  3054. j4totalPlanets% = SideTotalPlanets%(computerSide%)
  3055. l>ExpPlanet = 0: ExpShipsRequired = 1: ExpShipsAvailable = 2
  3056.  ourPlanets%(totalPlanets%, 2)
  3057. expGetPlanetData(computerSide%, ourPlanets%())
  3058. expDefensiveMoves(ourPlanets%(), central%)
  3059. expAttackingMoves(ourPlanets%(), central%)
  3060. expGetPlanetData(side%, 
  3061.  ourPlanets%())
  3062.  This fills ourPlanets%() with the necessary information for later
  3063.  stages of the 'Experts' turn
  3064. expGetOurPlanets(side%, ourPlanets%())
  3065. expAvailableShips(ourPlanets%())
  3066. expRequiredShips(ourPlanets%())
  3067. expGetOurPlanets(side%, 
  3068.  ourPlanets%())
  3069.  This stores all the planets owned by the Expert in ourPlanets%()
  3070.  planet%, ourPlanet%
  3071.  planet% = 1 
  3072.  NumberPlanets%
  3073.  PlanetSide(planet%) = side% 
  3074.     ourPlanet% += 1
  3075. 4    ourPlanets%(ourPlanet%, ExpPlanet) = planet%
  3076.  planet%
  3077. expAvailableShips(
  3078.  ourPlanets%())
  3079.  This records for each of our planets, the difference between the
  3080.  number of ships there and the number of ships that we would like
  3081.  to be there, to help prevent against new attacks
  3082.  loop%, planet%, requiredShips%
  3083.  loop% = 1 
  3084. (ourPlanets%(), 1)
  3085. -  planet% = ourPlanets%(loop%, ExpPlanet)
  3086. :  requiredShips% = 
  3087. expRequiredDefensiveShips(planet%)
  3088. T  ourPlanets%(loop%, ExpShipsAvailable) = PlanetShips%(planet%) - requiredShips%
  3089.  loop%
  3090. expRequiredShips(
  3091.  ourPlanets%())
  3092.  This records for each of our planets, the number of extra ships
  3093.  that are required to defend successfully against known attacks
  3094.  arriving next turn
  3095.  loop%, planet%, order%, requiredShips%, fiddleAvailable%
  3096.  loop% = 1 
  3097. (ourPlanets%(), 1)
  3098. -  planet% = ourPlanets%(loop%, ExpPlanet)
  3099.   requiredShips% = 0
  3100.  order% = 1 
  3101.  NumberMovementOrders%
  3102. W    requiredShips% = 
  3103. expRequiredShipsOrders(order%, planet%), requiredShips%)
  3104.  order%
  3105.  requiredShips% > 0 
  3106. j    requiredShips% = (requiredShips% * 1.2) - PlanetShips%(planet%) - 
  3107. expOurShipsArrivingNow(planet%)
  3108.  requiredShips% >= 0 
  3109. @      ourPlanets%(loop%, ExpShipsRequired)  = requiredShips%
  3110. 3      ourPlanets%(loop%, ExpShipsAvailable) = 0
  3111.         
  3112. S      fiddleAvailable% = requiredShips% + ourPlanets%(loop%, ExpShipsAvailable)
  3113. `      
  3114.  fiddleAvailable% > 0 
  3115.  ourPlanets%(loop%, ExpShipsAvailable) -= fiddleAvailable% 
  3116.         
  3117.  loop%
  3118. expOurShipsArrivingNow(planet%)
  3119.  This is the amount of ships that are arriving this coming
  3120.  turn at ourPlanet%, that are on our side
  3121.  order%, ships%
  3122.  order% = 1 
  3123.  NumberMovementOrders%
  3124.  MovementOrders%(order%, OrderPlanet) = planet% 
  3125. D    
  3126.  MovementOrders%(order%, OrderSide) = PlanetSide(planet%) 
  3127. G      
  3128.  MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1 
  3129. 9        ships% += MovementOrders%(order%, OrderShips)
  3130.       
  3131.         
  3132.  order%
  3133. =ships%
  3134. expRequiredShipsOrders(order%, planet%)
  3135.  IF the ships of this order are to attack this planet, next turn, then
  3136.  the number of ships necessary to defend the planet well is returned
  3137.  MovementOrders%(order%, OrderPlanet) = planet% 
  3138.  MovementOrders%(order%, OrderSide) <> PlanetSide(planet%) 
  3139. E    
  3140.  MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1 
  3141. /      = MovementOrders%(order%, OrderShips)
  3142.         
  3143. expRequiredDefensiveShips(planet%)
  3144.  Result is the number of ships required to deter an average
  3145.  attack against the planet
  3146. max((2 / 3) * TotalPlanetShipsAverage, PlanetResources(planet%) * 0.6)
  3147. expDefensiveMoves(
  3148.  ourPlanets%(), 
  3149.  central%)
  3150.  This attempts to ensure that any planets under attack can be either
  3151.  sent enough ships to withstand the attack, or retreat if need be
  3152.  loop%, numberOurPlanets%
  3153. +numberOurPlanets% = 
  3154. (ourPlanets%(), 1)
  3155.  loop% = 1 
  3156.  numberOurPlanets%
  3157.  ourPlanets%(loop%, ExpShipsRequired) > 0 
  3158. expGetReinforcements(loop%, ourPlanets%())
  3159.  loop%
  3160.  loop% = 1 
  3161.  numberOurPlanets%
  3162.  ourPlanets%(loop%, ExpShipsAvailable) < -
  3163. shipsIncreaseFromResourcesOver(PlanetResources(ourPlanets%(loop%, ExpPlanet)), 1) 
  3164. expGetBackup(loop%, ourPlanets%())
  3165.  loop%
  3166. /central% = 
  3167. expCentralPlanet(ourPlanets%())
  3168.  loop% = 1 
  3169.  numberOurPlanets%
  3170.  (ourPlanets%(loop%, ExpShipsAvailable) > 0) 
  3171.  (central% <> loop%) 
  3172. moveShipsFromTo(ourPlanets%(loop%, ExpShipsAvailable), ourPlanets%(loop%, ExpPlanet), ourPlanets%(central%, ExpPlanet))
  3173.  loop%
  3174. expGetReinforcements(attacked%, 
  3175.  ourPlanets%())
  3176.  This attempts to get reinforcements from our surrounding planets,
  3177.  that will ensure we have enough ships to defeat an attack. If
  3178.  possible to ensure the defending force has up to 120% the sorce
  3179.  of the attacker
  3180.  loop%, planet%, attackedPlanet%, takeShips%(), takeShipsFraction, takenShips%, totalShips%, requiredShips%, maxRequiredShips%
  3181. 7attackedPlanet% = ourPlanets%(attacked%, ExpPlanet)
  3182.  takeShips%( 
  3183. (ourPlanets%(), 1) )
  3184.  loop% = 1 
  3185. (ourPlanets%(), 1)
  3186. -  planet% = ourPlanets%(loop%, ExpPlanet)
  3187.  planet% <> attackedPlanet% 
  3188. f    
  3189. journeyTime(attackedPlanet%, planet%) = 1) 
  3190.  (ourPlanets%(loop%, ExpShipsAvailable) > 0) 
  3191. C      takeShips%(loop%) = ourPlanets%(loop%, ExpShipsAvailable)
  3192.         
  3193.  loop%
  3194. 'totalShips%       = 
  3195.  takeShips%()
  3196. @requiredShips%    = ourPlanets%(attacked%, ExpShipsRequired)
  3197.  totalShips% >= requiredShips% 
  3198. 6  takeShipsFraction = requiredShips% / totalShips%
  3199.  loop% = 1 
  3200. (ourPlanets%(), 1)
  3201. ;    takenShips% = takeShips%(loop%) * takeShipsFraction
  3202.  takenShips% > 0 
  3203. >      ourPlanets%(loop%, ExpShipsAvailable) -= takenShips%
  3204. W      
  3205. moveShipsFromTo(takenShips%, ourPlanets%(loop%, ExpPlanet), attackedPlanet%)
  3206.         
  3207.  loop%
  3208. 3  ourPlanets%(attacked%, ExpShipsRequired)  = 0
  3209.  Planet can't be saved. Escape
  3210. 4  ourPlanets%(attacked%, ExpShipsRequired)  = -1
  3211. O  ourPlanets%(attacked%, ExpShipsAvailable) = PlanetShips%(attackedPlanet%)
  3212.  Attempt to attack a planet with the ShipsAvailable
  3213. expAttackingMoves(ourPlanets%(), attacked%)
  3214. expGetBackup(defend%, 
  3215.  ourPlanets%())
  3216.  defendPlanet%, requiredShips%, loop%, takeShipsFraction, takenShips%, planet%
  3217.  takeShips%()
  3218. 4defendPlanet%  = ourPlanets%(defend%, ExpPlanet)
  3219. requiredShips% = -(ourPlanets%(defend%, ExpShipsAvailable) + 
  3220. shipsIncreaseFromResourcesOver(PlanetResources(defendPlanet%), 1))
  3221.  takeShips%( 
  3222. (ourPlanets%(), 1) )
  3223.  loop% = 1 
  3224. (ourPlanets%(), 1)
  3225. -  planet% = ourPlanets%(loop%, ExpPlanet)
  3226.  planet% <> defendPlanet% 
  3227.  d    
  3228. journeyTime(defendPlanet%, planet%) = 1) 
  3229.  (ourPlanets%(loop%, ExpShipsAvailable) > 0) 
  3230. !C      takeShips%(loop%) = ourPlanets%(loop%, ExpShipsAvailable)
  3231. "        
  3232.  loop%
  3233. &CtakeShipsFraction = 
  3234. min( 
  3235.  takeShips%() / requiredShips%, 1 )
  3236.  loop% = 1 
  3237. (ourPlanets%(), 1)
  3238. (-  planet% = ourPlanets%(loop%, ExpPlanet)
  3239.  planet% <> defendPlanet% 
  3240. *;    takenShips% = takeShips%(loop%) * takeShipsFraction
  3241.  takenShips% > 0 
  3242. ,>      ourPlanets%(loop%, ExpShipsAvailable) -= takenShips%
  3243. -?      
  3244. moveShipsFromTo(takenShips%, planet%, defendPlanet%)
  3245. .        
  3246.  loop%
  3247. expAttackingMoves(
  3248.  ourPlanets%(), central%)
  3249.  loop%, theirPlanet%
  3250.  theirPlanets%()
  3251.  theirPlanets%( NumberPlanets% - 
  3252. (ourPlanets%(), 1), 1 )
  3253.  loop% = 1 
  3254.  NumberPlanets%
  3255.  PlanetSide(loop%) <> CurrentSide% 
  3256.     theirPlanet% += 1
  3257. <.    theirPlanets%(theirPlanet%, 0) = loop%
  3258. =h    theirPlanets%(theirPlanet%, 1) = 
  3259. expAttackValue(theirPlanet%, ourPlanets%(central%, ExpPlanet))
  3260.  loop%
  3261. expSortAttackValues(theirPlanets%())
  3262. expDecideAttacks(ourPlanets%(), theirPlanets%(), central%)
  3263. expSortAttackValues(
  3264.  theirPlanets%())
  3265.  loop%, loop2%, max%, number%
  3266. H#number% = 
  3267. (theirPlanets%(), 1)
  3268.  number% > 1 
  3269.  loop% = 1 
  3270.  number% - 1
  3271. K$  max% = theirPlanets%(loop%, 1)
  3272.  loop2% = loop% + 1 
  3273.  number%
  3274. N+    
  3275.  theirPlanets%(loop2%, 1) > max% 
  3276. O>      
  3277.  theirPlanets%(loop2%, 0), theirPlanets%(loop%, 0)
  3278. P>      
  3279.  theirPlanets%(loop2%, 1), theirPlanets%(loop%, 1)
  3280. Q(      max% = theirPlanets%(loop%, 1)
  3281. R        
  3282.  loop2%
  3283.  loop%
  3284. expDecideAttacks(
  3285.  ourPlanets%(), theirPlanets%(), our%)
  3286.  freeShips%, loop%, requiredShips%, ourPlanet%, planet%
  3287. [-ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3288. \5freeShips% = ourPlanets%(our%, ExpShipsAvailable)
  3289. loop% = 1
  3290.  (freeShips% > 0) 
  3291.  (loop% <= 
  3292. (theirPlanets%(), 1)) 
  3293.  (theirPlanets%(loop%, 1) <> -1)
  3294. `'  planet% = theirPlanets%(loop%, 0)
  3295. a\  requiredShips% = 
  3296. calculateTransferShipsBuildUp2(planet%, ourPlanet%): 
  3297.  changed our%)
  3298.  (freeShips% >= requiredShips%) 
  3299.  (requiredShips% <> -1) 
  3300. c=    
  3301. moveShipsFromTo(requiredShips%, ourPlanet%, planet%)
  3302. d$    freeShips% -= requiredShips%
  3303.   loop% += 1
  3304. i5ourPlanets%(our%, ExpShipsAvailable) = freeShips%
  3305. expAttackValue(planet%, centralPlanet%)
  3306.  This returns a value that signifies its take over value.
  3307.  This is based on the number of ships relative to number of resources
  3308.  Should also take into account distance, but not yet
  3309.  ships%, timeMultiplier
  3310. rMships%         = 
  3311. calculateTransferShipsBuildUp2(planet%, centralPlanet%)
  3312. sLtimeMultiplier = MaxJourneyTime% / 
  3313. journeyTime(planet%, centralPlanet%)
  3314.  ships% = -1 
  3315.  = -1
  3316.  ships% = 0 
  3317. w6  =(PlanetResources(planet%) ^ 2) * timeMultiplier
  3318. yB  =((PlanetResources(planet%) ^ 2 ) / ships%) * timeMultiplier
  3319. expCentralPlanet(ourPlanets%())
  3320.  This returns the central for this side. If it has been
  3321.  taken over, or will be taken over this turn, then it is changed
  3322.  to the planet with the highest availableShips
  3323.  side%, central%, loop%, maxPlanet%, maxShips%
  3324. @central% = 
  3325. expGetCentralPlanet(CurrentSide%, ourPlanets%())
  3326.  central% = -1 
  3327.  We have to find a new planet
  3328. (  maxPlanet% = -1: maxShips% = -9999
  3329.  loop% = 1 
  3330. (ourPlanets%(), 1)
  3331. =    
  3332.  ourPlanets%(loop%, ExpShipsAvailable) > maxShips% 
  3333. O      maxPlanet% = loop%: maxShips% = ourPlanets%(loop%, ExpShipsAvailable)
  3334.         
  3335.  loop%
  3336. M  !(ComputerBlockPtr%(CurrentSide%)) = ourPlanets%(maxPlanet%, ExpPlanet)
  3337.   = maxPlanet%
  3338.   = central%
  3339. expGetCentralPlanet(side%, ourPlanets%())
  3340.  Returns the ourPlanets%() index of centralPlanet.
  3341.  Returns -1 if it is not our planet anymore, or it will
  3342.  be taken over most probably this turn
  3343.  centralPlanet%, loop%
  3344. 0centralPlanet% = !(ComputerBlockPtr%(side%))
  3345.  loop% = 1 
  3346. (ourPlanets%(), 1)
  3347.  ourPlanets%(loop%, ExpPlanet) = centralPlanet% 
  3348. B    
  3349.  ourPlanets%(loop%, ExpShipsRequired) <> 0 
  3350.  =-1 
  3351.  =loop%
  3352.  loop%
  3353. *************************************************************************************
  3354. ************************************************************************ Super Player
  3355. *************************************************************************************
  3356. cmoveSp(computerSide%)
  3357.  This is another computer player
  3358.  Hopefully better than the previous "Expert Player"
  3359.  ourPlanets%(), totalPlanets%
  3360.  attackFrom%, attackPlanet%
  3361. 4totalPlanets% = SideTotalPlanets%(computerSide%)
  3362. >ExpPlanet = 0: ExpShipsRequired = 1: ExpShipsAvailable = 2
  3363.  ourPlanets%(totalPlanets%, 2)
  3364. spGetPlanetsData(computerSide%, ourPlanets%())
  3365. spGetAttackPlanet(computerSide%, ourPlanets%(), attackFrom%, attackPlanet%)
  3366. spDefensiveMoves(ourPlanets%(), attackFrom%, attackPlanet%)
  3367. spAttackMove(computerSide%, ourPlanets%(), attackFrom%, attackPlanet%)
  3368. ------------------------------------------------------------------- Get Attack Planet
  3369. spWriteAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
  3370.  This stores the information so it can be used in future turns.
  3371.  Only used by THIS computer "super player"
  3372. 7!(ComputerBlockPtr%(side%))     = attackFromPlanet%
  3373. 3!(ComputerBlockPtr%(side%) + 4) = attackPlanet%
  3374. 0!(ComputerBlockPtr%(side%) + 8) = startTurn%
  3375. spClearAttackDetails(side%)
  3376.  This changes,and storesm the stored variables to "undefined" values
  3377. spWriteAttackDetails(side%, -1, -1, -1)
  3378. spReadAttackDetails(side%, 
  3379.  attackFromPlanet%, 
  3380.  attackPlanet%, 
  3381.  startTurn%)
  3382.  This reads the stored information
  3383. 3attackFromPlanet% = !(ComputerBlockPtr%(side%))
  3384. 7attackPlanet%     = !(ComputerBlockPtr%(side%) + 4)
  3385. 7startTurn%        = !(ComputerBlockPtr%(side%) + 8)
  3386. spGiveUpAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
  3387.  This checks to see whether it is worth continuing against this target
  3388.  changeAttack%
  3389. changeAttack% = 
  3390. spTimeOutAttack(startTurn%) 
  3391. spAttackFromChangeOwnership(side%, attackFromPlanet%) 
  3392.  (attackFromPlanet% = -1)
  3393. = changeAttack%
  3394. spTimeOutAttack(startTurn%)
  3395.  Gives up an attackPlanet if we have spent too long building up for it
  3396.  (CurrentTurn% - startTurn%) > 3 
  3397. spAttackFromChangeOwnership(side%, attackFromPlanet%)
  3398.  If the starting planet is not ours any more, then we
  3399.  can't build up from there
  3400.  attackFromPlanet% <> -1 
  3401.  PlanetSide(attackFromPlanet%) <> side% 
  3402. spGetAttackPlanet(side%, ourPlanets%(), 
  3403.  attackFrom%, 
  3404.  attackPlanet%)
  3405.  This aims to find a planet to attack, and a planet to
  3406.  build up the attack force from.
  3407.  attackFromPlanet%, startTurn%    :
  3408.  Integer
  3409.  changeAttack%                    :
  3410.  Boolean
  3411. spReadAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
  3412. _changeAttack% = 
  3413. spGiveUpAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
  3414.  changeAttack% 
  3415. spGetNewAttackPlanet(side%, ourPlanets%(), attackFromPlanet%, attackPlanet%)
  3416. 6attackFrom% = 
  3417. spAllToMyPlanets(attackFromPlanet%)
  3418. diagnosis("Attack Planet:      " + PlanetName$(attackPlanet%))
  3419. diagnosis("Attack from Planet: " + PlanetName$(attackFromPlanet%))
  3420. spGetNewAttackPlanet(side%, ourPlanets%(), 
  3421.  attackFromPlanet%, 
  3422.  attackPlanet%)
  3423.  This finds a new set of attackFromPlanet, attackPlanet.
  3424.  Updates stored details
  3425.  checkPlanets%(), planets%
  3426.  checkPlanets%(NumberPlanets%, 1)
  3427. spGetAttackPlanetsList(side%, checkPlanets%(), planets%)
  3428. spChooseAttackPlanet(checkPlanets%(), planets%, attackFromPlanet%, attackPlanet%)
  3429. spWriteAttackDetails(side%, attackFromPlanet%, attackPlanet%, CurrentTurn%)
  3430. spGetAttackPlanetsList(side%, 
  3431.  checkPlanets%(), 
  3432.  planets%)
  3433.  This creates a list of possible pairs = (attackFrom%, attackPlanet%)
  3434.  Unordered at present
  3435.  attackDistance%, attackFrom%, attackFromPlanet%, attackPlanet%
  3436.  loop%, found%
  3437.  planets% = 0
  3438.   attackDistance% += 1
  3439.  attackFrom% = 1 
  3440. (ourPlanets%(), 1)
  3441. ?    attackFromPlanet% = ourPlanets%(attackFrom%, ExpPlanet)
  3442. ,    
  3443.  attackPlanet% = 1 
  3444.  NumberPlanets%
  3445. w      
  3446.  (PlanetSide(attackPlanet%) <> side%) 
  3447. journeyTime(attackFromPlanet%, attackPlanet%) = attackDistance%) 
  3448.         :
  3449. !        loop% = 1: found% = 
  3450. -        
  3451.  (loop% <= planets%) 
  3452.  found%
  3453. 9          
  3454.  checkPlanets%(loop%, 1) = attackPlanet% 
  3455. y            
  3456.  ourPlanets%(attackFrom%, ExpShipsAvailable) > ourPlanets%(checkPlanets%(loop%, 0), ExpShipsAvailable) 
  3457. 7              checkPlanets%(loop%, 0) = attackFrom%
  3458.             
  3459.             found% = 
  3460.           
  3461.             loop% += 1
  3462.           
  3463.         
  3464.         
  3465.  found% 
  3466.           planets% += 1
  3467. #6          checkPlanets%(planets%, 0) = attackFrom%
  3468. $8          checkPlanets%(planets%, 1) = attackPlanet%
  3469.         
  3470.       
  3471.  attackPlanet%
  3472.  attackFrom%
  3473. spChooseAttackPlanet(checkPlanets%(), planets%, 
  3474.  attackFromPlanet%, 
  3475.  attackPlanet%)
  3476.  This chooses one pair of (attackFrom%, attackPlanet%) from the list
  3477.  of possible ones
  3478.  availShips%, newAvailShips%, loop%
  3479.  planets% > 1 
  3480.  Find planet with largest ships which we can take with AvailableShips
  3481. 4k  availShips% = ourPlanets%(checkPlanets%(1, 0), ExpShipsAvailable) - PlanetShips%(checkPlanets%(1, 1))
  3482.  loop% = 2 
  3483.  planets%
  3484. 6x    newAvailShips% = ourPlanets%(checkPlanets%(loop%, 0), ExpShipsAvailable) - PlanetShips%(checkPlanets%(loop%, 1))
  3485. 7(    
  3486.  newAvailShips% > availShips% 
  3487. 89      
  3488.  checkPlanets%(1, 0), checkPlanets%(loop%, 0)
  3489. 99      
  3490.  checkPlanets%(1, 1), checkPlanets%(loop%, 1)
  3491. :&      availShips% = newAvailShips%
  3492. ;        
  3493.  loop%
  3494. ?CattackFromPlanet% = ourPlanets%(checkPlanets%(1, 0), ExpPlanet)
  3495. @7attackPlanet%     =             checkPlanets%(1, 1)
  3496. spAllToMyPlanets(planet%)
  3497.  This converts a plant id from Planets(planet%) to ourPlanets%()
  3498.  loop%
  3499.   loop% += 1
  3500.  ourPlanets%(loop%, ExpPlanet) = planet% 
  3501.  =loop%
  3502. ------------------------------------------------------------------ Get Planet Details
  3503. spGetPlanetsData(side%, 
  3504.  ourPlanets%())
  3505.  This fills ourPlanets%() with the necessary information for later
  3506.  stages of the 'Experts' turn
  3507. spGetOurPlanets(side%, ourPlanets%())
  3508. spAvailableShips(ourPlanets%())
  3509. spRequiredShips(ourPlanets%())
  3510. spGetOurPlanets(side%, 
  3511.  ourPlanets%())
  3512.  This stores all the planets owned by the Super Player in ourPlanets%()
  3513.  planet%, ourPlanet%
  3514.  planet% = 1 
  3515.  NumberPlanets%
  3516.  PlanetSide(planet%) = side% 
  3517.     ourPlanet% += 1
  3518. `4    ourPlanets%(ourPlanet%, ExpPlanet) = planet%
  3519.  planet%
  3520. spAvailableShips(
  3521.  ourPlanets%())
  3522.  This records for each of our planets, the difference between the
  3523.  number of ships there and the number of ships that we would like
  3524.  to be there, to help prevent against new attacks.
  3525.  our%, ourPlanet%, requiredShips%
  3526.  our% = 1 
  3527. (ourPlanets%(), 1)
  3528. m/  ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3529. n<  requiredShips% = 
  3530. spRequiredDeterrentShips(ourPlanet%)
  3531. oV  ourPlanets%(our%, ExpShipsAvailable) = PlanetShips%(ourPlanet%) - requiredShips%
  3532.  our%
  3533. spRequiredDeterrentShips(planet%)
  3534.  Result is the number of ships required to deter an average
  3535.  attack against the planet
  3536. max(PlanetShips%(PlanetSortedOnShips%(NumberPlanets% / 4)) + 1, PlanetResources(planet%) * 0.6)
  3537. spRequiredTotalDefensiveShips(planet%)
  3538.  Answer is the number of ships that are needed to adequately defend
  3539.  against an actual attack on planet%
  3540.  order%, ships%
  3541.  order% = 1 
  3542.  NumberMovementOrders%
  3543. 7  ships% += 
  3544. spRequiredShipsOrders(order%, planet%)
  3545.  order%
  3546. = ships% * 1.3
  3547. spRequiredDefensiveShips(our%, requiredShips%, 
  3548.  ourPlanets%())
  3549.  This sets the number of extra ships a planet needs to successfully
  3550.  defend an attack.
  3551.  ourPlanet%, fiddleAvailable%
  3552. -ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3553.  requiredShips% >= 0 
  3554. .  ourPlanets%(our%, ExpShipsAvailable) = 0
  3555. T  fiddleAvailable% = 
  3556. min(-requiredShips%, ourPlanets%(our%, ExpShipsAvailable))
  3557. m  ourPlanets%(our%, ExpShipsAvailable) = 
  3558. max(0, ourPlanets%(our%, ExpShipsAvailable) - fiddleAvailable%)
  3559.   requiredShips% = 0
  3560. =requiredShips%
  3561. spRequiredShips(
  3562.  ourPlanets%())
  3563.  This records for each of our planets, the number of extra ships
  3564.  that are required to defend successfully against known attacks
  3565.  arriving next turn
  3566.  our%, ourPlanet%, requiredShips%
  3567.  our% = 1 
  3568. (ourPlanets%(), 1)
  3569. /  ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3570. A  requiredShips% = 
  3571. spRequiredTotalDefensiveShips(ourPlanet%)
  3572.  requiredShips% > 0 
  3573. g    requiredShips% = requiredShips% - PlanetShips%(ourPlanet%) - 
  3574. spOurShipsArrivingNow(ourPlanet%)
  3575. W    requiredShips% = 
  3576. spRequiredDefensiveShips(our%, requiredShips%, ourPlanets%())
  3577. ;  ourPlanets%(our%, ExpShipsRequired)  = requiredShips%
  3578.  our%
  3579. spOurShipsArrivingNow(planet%)
  3580.  This is the amount of ships that are arriving this coming
  3581.  turn at ourPlanet%, that are on our side
  3582.  order%, ships%
  3583.  order% = 1 
  3584.  NumberMovementOrders%
  3585.  MovementOrders%(order%, OrderPlanet) = planet% 
  3586. D    
  3587.  MovementOrders%(order%, OrderSide) = PlanetSide(planet%) 
  3588. G      
  3589.  MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1 
  3590. 9        ships% += MovementOrders%(order%, OrderShips)
  3591.       
  3592.         
  3593.  order%
  3594. =ships%
  3595. spRequiredShipsOrders(order%, planet%)
  3596.  IF the ships of this order are to attack this planet, next turn, then
  3597.  the number of ships necessary to defend the planet well is returned
  3598.  MovementOrders%(order%, OrderPlanet) = planet% 
  3599.  MovementOrders%(order%, OrderSide) <> PlanetSide(planet%) 
  3600. E    
  3601.  MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1 
  3602. /      = MovementOrders%(order%, OrderShips)
  3603.         
  3604. --------------------------------------------------------------------- Defensive Moves
  3605. spDefensiveMoves(
  3606.  ourPlanets%(), attackFrom%, attackPlanet%)
  3607.  This attempts to ensure that any planets under attack can be either
  3608.  sent enough ships to withstand the attack, or retreat if need be
  3609. spFindOppositionAttacks(ourPlanets%())
  3610. spFindOurWeakPlanets(ourPlanets%())
  3611. spMoveExcessShips(ourPlanets%(), attackFrom%)
  3612. spFindOppositionAttacks(
  3613.  ourPlanets%())
  3614.  Examines all our planets looking for ones that are being attacked
  3615.  and need assistance. Attempt to send assistance
  3616.  our%, numberOurPlanets%
  3617. +numberOurPlanets% = 
  3618. (ourPlanets%(), 1)
  3619.  our% = 1 
  3620.  numberOurPlanets%
  3621.  ourPlanets%(our%, ExpShipsRequired) > 0 
  3622. diagnosis(PlanetName$(ourPlanets%(our%, ExpPlanet))+ " needs "+
  3623. (ourPlanets%(our%, ExpShipsRequired))+" reinforcements to withstand attack")
  3624. 1    
  3625. spGetReinforcements(our%, ourPlanets%())
  3626.  our%
  3627. spFindOurWeakPlanets(
  3628.  ourPlanets%())
  3629.  This finds all our planets that could be targets because of their
  3630.  low number of ships in defence and boost it to appropriate levels
  3631.  our%, ourPlanet%, numberOurPlanets%
  3632. +numberOurPlanets% = 
  3633. (ourPlanets%(), 1)
  3634.  our% = 1 
  3635.  numberOurPlanets%
  3636.  ourPlanets%(our%, ExpShipsAvailable) < 0 
  3637. 1    ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3638. diagnosis(PlanetName$(ourPlanet%)+" needs "+
  3639. (-ourPlanets%(our%, ExpShipsAvailable))+" extra ships to dissuade future attacks")
  3640. )    
  3641. spGetBackup(our%, ourPlanets%())
  3642.  our%
  3643. spMoveExcessShips(
  3644.  ourPlanets%(), attackFrom%)
  3645.  This moves any available ships to attackFromPlanet% so they can be
  3646.  used in the next offensive
  3647.  our%, ourPlanet%, numberOurPlanets%, attackFromPlanet%
  3648. +numberOurPlanets% = 
  3649. (ourPlanets%(), 1)
  3650. ;attackFromPlanet% = ourPlanets%(attackFrom%, ExpPlanet)
  3651.  our% = 1 
  3652.  numberOurPlanets%
  3653.  (ourPlanets%(our%, ExpShipsAvailable) > 0) 
  3654.  (attackFrom% <> our%) 
  3655. 1    ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3656. ]    
  3657. moveShipsFromTo(ourPlanets%(our%, ExpShipsAvailable), ourPlanet%, attackFromPlanet%)
  3658. k    
  3659. PROCdiagnosis("Excess troops from "+PlanetName$(ourPlanet%)+" to "+PlanetName$(attackFromPlanet%))
  3660.  our%
  3661. spGetReinforcements(attacked%, 
  3662.  ourPlanets%())
  3663.  This attempts to get reinforcements from our surrounding planets,
  3664.  that will ensure we have enough ships to defeat an attack.
  3665.  attackedPlanet%, numberOurPlanets%, our%
  3666.  takeShips%()
  3667.  totalShips%, requiredShips%, takeShipsFraction, takenShips%, totalTakenShips%
  3668. 9attackedPlanet%   = ourPlanets%(attacked%, ExpPlanet)
  3669. +numberOurPlanets% = 
  3670. (ourPlanets%(), 1)
  3671.  takeShips%(numberOurPlanets%)
  3672. spSupplyAvailableShips(attackedPlanet%, ourPlanets%(), takeShips%())
  3673. @requiredShips%    = ourPlanets%(attacked%, ExpShipsRequired)
  3674. 'totalShips%       = 
  3675.  takeShips%()
  3676.  totalShips% >= requiredShips% 
  3677. 6  takeShipsFraction = requiredShips% / totalShips%
  3678.  our% = 1 
  3679.  numberOurPlanets%
  3680. B    takenShips% = 
  3681. round(takeShips%(our%) * takeShipsFraction)
  3682. '    totalTakenShips% += takenShips%
  3683.  takenShips% > 0 
  3684. =      ourPlanets%(our%, ExpShipsAvailable) -= takenShips%
  3685. V      
  3686. moveShipsFromTo(takenShips%, ourPlanets%(our%, ExpPlanet), attackedPlanet%)
  3687.         
  3688.  our%
  3689. diagnosis("Here comes the cavalry with "+
  3690. (totalTakenShips%))
  3691.  Planet can't be saved. Escape
  3692. diagnosis(PlanetName$(attackedPlanet%)+" can't be saved. Escape, Escape!!")
  3693. %O  ourPlanets%(attacked%, ExpShipsAvailable) = PlanetShips%(attackedPlanet%)
  3694. (1ourPlanets%(attacked%, ExpShipsRequired)  = 0
  3695. spSupplyAvailableShips(destinationPlanet%, ourPlanets%(), 
  3696.  takeShips%())
  3697.  This sees how many available ships are within 1 distance of the
  3698.  planet
  3699.  our%, ourPlanet%, numberOurPlanets%
  3700. 1+numberOurPlanets% = 
  3701. (ourPlanets%(), 1)
  3702.  our% = 1 
  3703.  numberOurPlanets%
  3704. 3/  ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3705.  ourPlanet% <> destinationPlanet% 
  3706. 5k    
  3707. journeyTime(destinationPlanet%, ourPlanet%) = 1) 
  3708.  (ourPlanets%(our%, ExpShipsAvailable) > 0) 
  3709. 6A      takeShips%(our%) = ourPlanets%(our%, ExpShipsAvailable)
  3710. 7        
  3711.  our%
  3712. spGetBackup(defend%, 
  3713.  ourPlanets%())
  3714.  this attempts to get available ships from nearby planets to
  3715.  stop the planet looking such an easy target
  3716.  defendPlanet%, requiredShips%, numberOurPlanets%, takeShips%()
  3717.  totalShips%, takeShipsFraction, our%, ourPlanet%, takenShips%, totalTakenShips%
  3718. C5defendPlanet%  =  ourPlanets%(defend%, ExpPlanet)
  3719. D=requiredShips% = -ourPlanets%(defend%, ExpShipsAvailable)
  3720. E+numberOurPlanets% = 
  3721. (ourPlanets%(), 1)
  3722.  takeShips%(numberOurPlanets%)
  3723. spSupplyAvailableShips(defendPlanet%, ourPlanets%(), takeShips%())
  3724. J!totalShips% = 
  3725.  takeShips%()
  3726.  totalShips% = 0 
  3727. diagnosis("No ships available to backup "+PlanetName$(defendPlanet%))
  3728. N?  takeShipsFraction = 
  3729. min(requiredShips% / totalShips%, 1)
  3730.  our% = 1 
  3731.  numberOurPlanets%
  3732. P1    ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3733. QB    
  3734.  (ourPlanet% <> defendPlanet%) 
  3735.  (takeShips%(our%) > 0) 
  3736. RM      takenShips% = 
  3737. round(takeShips%(our%) * takeShipsFraction), 1)
  3738. S)      totalTakenShips% += takenShips%
  3739.       :
  3740. U=      ourPlanets%(our%, ExpShipsAvailable) -= takenShips%
  3741. VB      
  3742. moveShipsFromTo(takenShips%, ourPlanet%, defendPlanet%)
  3743. W        
  3744.  our%
  3745. diagnosis(
  3746. min(totalShips%, requiredShips%))+" ships can help backup "+PlanetName$(defendPlanet%))
  3747. ]9ourPlanets%(defend%, ExpShipsRequired) += totalShips%
  3748. --------------------------------------------------------------------- Attacking Moves
  3749. spAttackMove(side%, 
  3750.  ourPlanets%(), attackFrom%, attackPlanet%)
  3751.  requiredShips%, freeShips%, attackFromPlanet%
  3752. e;attackFromPlanet% = ourPlanets%(attackFrom%, ExpPlanet)
  3753. fSrequiredShips%    = 
  3754. calculateTransferShipsSp(attackPlanet%, attackFromPlanet%)
  3755. gCfreeShips%        = ourPlanets%(attackFrom%, ExpShipsAvailable)
  3756.  (freeShips% >= requiredShips%) 
  3757.  (requiredShips% <> -1) 
  3758. moveShipsFromTo(freeShips%, attackFromPlanet%, attackPlanet%)
  3759. diagnosis("Sent ships to battle: "+ 
  3760. (freeShips%))
  3761. spClearAttackDetails(side%)
  3762. diagnosis("Not enough troops yet... Have: "+
  3763. (freeShips%)+", need "+
  3764. (requiredShips%))
  3765. spAttackingMoves(
  3766.  ourPlanets%(), attackFromPlanet%, attackPlanet%)
  3767.  loop%, theirPlanet%
  3768.  theirPlanets%()
  3769.  theirPlanets%( NumberPlanets% - 
  3770. (ourPlanets%(), 1), 1 )
  3771.  loop% = 1 
  3772.  NumberPlanets%
  3773.  PlanetSide(loop%) <> CurrentSide% 
  3774.     theirPlanet% += 1
  3775. |.    theirPlanets%(theirPlanet%, 0) = loop%
  3776. }g    theirPlanets%(theirPlanet%, 1) = 
  3777. spAttackValue(theirPlanet%, ourPlanets%(central%, ExpPlanet))
  3778.  loop%
  3779. spSortAttackValues(theirPlanets%())
  3780. spDecideAttacks(ourPlanets%(), theirPlanets%(), central%)
  3781. spSortAttackValues(
  3782.  theirPlanets%())
  3783.  loop%, loop2%, max%, number%
  3784. #number% = 
  3785. (theirPlanets%(), 1)
  3786.  number% > 1 
  3787.  loop% = 1 
  3788.  number% - 1
  3789. $  max% = theirPlanets%(loop%, 1)
  3790.  loop2% = loop% + 1 
  3791.  number%
  3792. +    
  3793.  theirPlanets%(loop2%, 1) > max% 
  3794. >      
  3795.  theirPlanets%(loop2%, 0), theirPlanets%(loop%, 0)
  3796. >      
  3797.  theirPlanets%(loop2%, 1), theirPlanets%(loop%, 1)
  3798. (      max% = theirPlanets%(loop%, 1)
  3799.         
  3800.  loop2%
  3801.  loop%
  3802. spDecideAttacks(
  3803.  ourPlanets%(), theirPlanets%(), our%)
  3804.  freeShips%, loop%, requiredShips%, ourPlanet%, planet%
  3805. -ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3806. 5freeShips% = ourPlanets%(our%, ExpShipsAvailable)
  3807. loop% = 1
  3808.  (freeShips% > 0) 
  3809.  (loop% <= 
  3810. (theirPlanets%(), 1)) 
  3811.  (theirPlanets%(loop%, 1) <> -1)
  3812. '  planet% = theirPlanets%(loop%, 0)
  3813. X  requiredShips% = 
  3814. calculateTransferShipsBuildUp2(planet%, ourPlanet%) :
  3815.  was our%)
  3816.  (freeShips% >= requiredShips%) 
  3817.  (requiredShips% <> -1) 
  3818. =    
  3819. moveShipsFromTo(requiredShips%, ourPlanet%, planet%)
  3820. $    freeShips% -= requiredShips%
  3821.   loop% += 1
  3822. 5ourPlanets%(our%, ExpShipsAvailable) = freeShips%
  3823. spAttackValue(planet%, centralPlanet%)
  3824.  This returns a value that signifies its take over value.
  3825.  This is based on the number of ships relative to number of resources
  3826.  Should also take into account distance, but not yet
  3827.  ships%, timeMultiplier
  3828. Mships%         = 
  3829. calculateTransferShipsBuildUp2(planet%, centralPlanet%)
  3830. LtimeMultiplier = MaxJourneyTime% / 
  3831. journeyTime(planet%, centralPlanet%)
  3832.  ships% = -1 
  3833.  = -1
  3834.  ships% = 0 
  3835. 6  =(PlanetResources(planet%) ^ 2) * timeMultiplier
  3836. B  =((PlanetResources(planet%) ^ 2 ) / ships%) * timeMultiplier
  3837. spCentralPlanet(ourPlanets%())
  3838.  This returns the central for this side. If it has been
  3839.  taken over, or will be taken over this turn, then it is changed
  3840.  to the planet with the highest availableShips
  3841.  side%, central%, loop%, maxPlanet%, maxShips%
  3842. ?central% = 
  3843. spGetCentralPlanet(CurrentSide%, ourPlanets%())
  3844.  central% = -1 
  3845.  We have to find a new planet
  3846. (  maxPlanet% = -1: maxShips% = -9999
  3847.  loop% = 1 
  3848. (ourPlanets%(), 1)
  3849. =    
  3850.  ourPlanets%(loop%, ExpShipsAvailable) > maxShips% 
  3851. O      maxPlanet% = loop%: maxShips% = ourPlanets%(loop%, ExpShipsAvailable)
  3852.         
  3853.  loop%
  3854. M  !(ComputerBlockPtr%(CurrentSide%)) = ourPlanets%(maxPlanet%, ExpPlanet)
  3855.   = maxPlanet%
  3856.   = central%
  3857. spGetCentralPlanet(side%, ourPlanets%())
  3858.  Returns the ourPlanets%() index of centralPlanet.
  3859.  Returns -1 if it is not our planet anymore, or it will
  3860.  be taken over most probably this turn
  3861.  centralPlanet%, loop%
  3862. 0centralPlanet% = !(ComputerBlockPtr%(side%))
  3863.  loop% = 1 
  3864. (ourPlanets%(), 1)
  3865.  ourPlanets%(loop%, ExpPlanet) = centralPlanet% 
  3866. B    
  3867.  ourPlanets%(loop%, ExpShipsRequired) <> 0 
  3868.  =-1 
  3869.  =loop%
  3870.  loop%
  3871. calculateTransferShipsSp(attackPlanet%, attackFromPlanet%)
  3872.  This calculates how many ships will have to be sent to planet% to take
  3873.  it over from centralPlanet%
  3874.  This also takes into account the number of ships from other sides
  3875.  heading for the planet
  3876.  order%, side%, transitShips%
  3877. )side% = PlanetSide(attackFromPlanet%)
  3878.  PlanetSide(attackPlanet%) <> side% 
  3879.  order% = 1 
  3880.  NumberMovementOrders%
  3881. 8    
  3882.  (MovementOrders%(order%, 3) = attackPlanet%) 
  3883. 0      
  3884.  MovementOrders%(order%, 0) = side% 
  3885. G        
  3886.  We have already sent ships there. Forget it at this stage
  3887.         = -1
  3888.       
  3889. I        
  3890.  another side is sending ships. Have to send more than them!
  3891. K        transitShips% = 
  3892. max(MovementOrders%(order%, 2), transitShips%)
  3893.       
  3894.         
  3895.  order%
  3896.  There are no troops on the way, therefore calculate a value
  3897. max( PlanetShips%(attackPlanet%) + 
  3898. shipsIncreaseFromResourcesOver(PlanetResources(attackPlanet%), 
  3899. journeyTime(attackFromPlanet%, attackPlanet%)), transitShips%) * 1.3 )
  3900.   = -1
  3901.  > GeneralLib
  3902. ----------------------------------------------------------------------------- String
  3903. stringToLowerCase(upper$)
  3904.  loop%, lower$
  3905. lower$ = ""
  3906.  loop% = 1 
  3907. (upper$)
  3908. ;   lower$ += 
  3909. charToLowerCase(
  3910. upper$, loop%, 1))))
  3911.  loop%
  3912. =lower$
  3913. charToLowerCase(upper%)
  3914.  upper% >= 
  3915. ("A") 
  3916.  upper% <= 
  3917. ("Z") 
  3918. "  = upper% + (
  3919. ("a") - 
  3920. ("A"))
  3921.   = upper%
  3922. read0String(ptr%)
  3923.  string$
  3924.  ?ptr% <> 0
  3925.   string$ += 
  3926. (?ptr%)
  3927.   ptr% += 1
  3928. =string$
  3929. readSysString(ptr%)
  3930.  string$
  3931.  ?ptr% >= 32
  3932.   string$ += 
  3933. (?ptr%)
  3934.   ptr% += 1
  3935. =string$
  3936. -------------------------------------------------------------------------- Numerical
  3937. min(A, B)
  3938.  A <= B 
  3939. max(A, B)
  3940.  A > B 
  3941. round(n)
  3942. (n + 0.5)
  3943.