home *** CD-ROM | disk | FTP | other *** search
/ ftp.uni-stuttgart.de/pub/systems/acorn/ / Acorn.tar / Acorn / acornet / fun / games / trynth.spk / !Trynth / !RunImage (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1993-05-07  |  136KB  |  3,936 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.20b (07 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.  "Wimp_OpenTemplate",, "TrynthRes:Templates"
  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.  "Wimp_OpenTemplate",, "TrynthRes:Templates"
  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. wimpLoadCreateWindow(windowName$, 
  1610.  indirect%)
  1611.  window%
  1612. wimpLoadTemplate(windowName$, indirect%)
  1613.  "Wimp_CreateWindow",, WimpBlock% 
  1614.  window%
  1615. =window%
  1616. wimpLoadTemplate(windowName$, 
  1617.  indirect%)
  1618.  "Wimp_LoadTemplate",, WimpBlock%, indirect%, IndirectBlock%+&1000, FontReferenceBlock%, windowName$, 0 
  1619.  ,,indirect%
  1620. ------------------------------------------------------------------------------ Screen
  1621. screenSize(
  1622.  screenX%, 
  1623.  screenY%)
  1624.  F%, P%
  1625.  &35,-1,4 
  1626.  ,,F%
  1627.  &35,-1,11 
  1628.  ,,P%
  1629. screenX%=P%<<F%
  1630.  &35,-1,5 
  1631.  ,,F%
  1632.  &35,-1,12 
  1633.  ,,P%
  1634. screenY%=P%<<F%
  1635. ----------------------------------------------------------------------------- Windows
  1636. openWindow(window%)
  1637.  Opens a windw to the Front of the screen
  1638. !WimpBlock% = window%
  1639.  "Wimp_GetWindowState",, WimpBlock%
  1640. WimpBlock%!28 = -1
  1641.  "Wimp_OpenWindow",, WimpBlock%
  1642. openWindowCentred(window%)
  1643.  Opens a window to the Front of the screen, in centre
  1644.  screenX%, screenY%, width%, height%
  1645. !WimpBlock% = window%
  1646.  "Wimp_GetWindowInfo",, WimpBlock%
  1647. WimpBlock%!28 = -1
  1648. screenSize(screenX%, screenY%)
  1649. X+width%  = WimpBlock%!52 - WimpBlock%!44
  1650. Y+height% = WimpBlock%!56 - WimpBlock%!48
  1651. ZRWimpBlock%!4 = (screenX% -  width%) 
  1652.  2: WimpBlock%!12 = WimpBlock%!4 + width%
  1653. [SWimpBlock%!8 = (screenY% - height%) 
  1654.  2: WimpBlock%!16 = WimpBlock%!8 + height%
  1655.  "Wimp_OpenWindow",, WimpBlock%
  1656. reopenWindow(window%)
  1657. !WimpBlock% = window%
  1658.  "Wimp_GetWindowState",, WimpBlock%
  1659.  "Wimp_OpenWindow",, WimpBlock%
  1660. closeWindow(window%)
  1661. !WimpBlock% = window%
  1662.  "Wimp_CloseWindow",, WimpBlock%
  1663. getWindowState(window%)
  1664. !WimpBlock% = window%
  1665.  "Wimp_GetWindowState",, WimpBlock%
  1666. redrawWindowArea(window%, x0%, y0%, x1%, y1%)
  1667.  "Wimp_ForceRedraw", window%, x0%, y0%, x1%, y1%
  1668. redrawWindow(window%)
  1669.  "Wimp_ForceRedraw", window%, 0, -&7FFFFF, &7FFFFF, 0
  1670. redrawWindowTitle(window%)
  1671. WimpBlock%!0 = window%
  1672.  "Wimp_GetWindowState",, WimpBlock%
  1673.  WimpBlock%!32 
  1674.  (1 << 16) 
  1675.  "Wimp_ForceRedraw", -1, WimpBlock%!4, (WimpBlock%!16) + 4, WimpBlock%!12, (WimpBlock%!16) + 36
  1676. ------------------------------------------------------------------------------- Icons
  1677. indirectedBuffer(iconNumber%)
  1678.  Used a CreateWindow block
  1679. indirectedLookup(iconNumber%, 20)
  1680. indirectedValidation(iconNumber%)
  1681. indirectedLookup(iconNumber%, 24)
  1682. indirectedLength(iconNumber%)
  1683. indirectedLookup(iconNumber%, 28)
  1684. indirectedLookup(iconNumber%, offset%)
  1685. 3=WimpBlock%!((iconNumber% * 32) + 88 + offset%)
  1686. newBasicIcon(iconType%, size%, window%, icon%)
  1687.  block%
  1688. !block% = 
  1689. getHeapBlock(size%)
  1690. block%!0 = iconType%
  1691. *block%!4 = window%  : block%!8 = icon%
  1692. =block%
  1693. newIndirectedIcon(window%, icon%)
  1694.  Creates an 'Indircted' icon representation.
  1695.  block%
  1696. Gblock% = 
  1697. newBasicIcon(StandardIndirectedIcon%, 24, window%, icon%)
  1698. Rblock%!12 = 
  1699. indirectedBuffer(icon%): block%!16 = 
  1700. indirectedValidation(icon%)
  1701. (block%!20 = 
  1702. indirectedLength(icon%)
  1703. =block%
  1704. readIndirectedBuffer(iconBlock%)
  1705. readSysString(iconBlock%!12)
  1706. writeIndirectedBuffer(iconBlock%, text$)
  1707.  This stoes the next text$ and redraws it within the window
  1708.  shortText$, length%
  1709. length% = iconBlock%!20 - 1
  1710. !shortText$ = 
  1711. text$, length%)
  1712. !$(iconBlock%!12) = shortText$
  1713. "?(iconBlock%!12 + length%) = 0
  1714. redrawIcon(iconBlock%!4, iconBlock%!8)
  1715. shadeIndirectedIcon(iconBlock%, flag%)
  1716. shadeIcon(iconBlock%!4, iconBlock%!8, flag%)
  1717. redrawIcon(window%, icon%)
  1718. 1!WimpBlock%  = window%: WimpBlock%!4  = icon%
  1719. -WimpBlock%!8 = 0      : WimpBlock%!12 = 0
  1720.  "Wimp_SetIconState",, WimpBlock%
  1721. redrawIconList(window%, iconList%())
  1722.  This redraws every icon listed in the iconList%() array, for
  1723.  window%. SMOOTHY procedure
  1724.  loop%, length%
  1725. length% = 
  1726. (iconList%(), 1)
  1727. WimpBlock%!0 = window%
  1728. -WimpBlock%!8 = 0      : WimpBlock%!12 = 0
  1729.  loop% = 1 
  1730.  length%
  1731. %  WimpBlock%!4 = iconList%(loop%)
  1732.  "Wimp_SetIconState",, WimpBlock%
  1733.  loop%
  1734. getIconState(window%, icon%)
  1735. WimpBlock%!0 = window%
  1736. WimpBlock%!4 = icon%
  1737.  "Wimp_GetIconState",, WimpBlock%
  1738. setIconState(window%, icon%, eor%, mask%)
  1739. 1WimpBlock%!0 = window%: WimpBlock%!4  = icon%
  1740. 1WimpBlock%!8 = eor%   : WimpBlock%!12 = mask%
  1741.  "Wimp_SetIconState",, WimpBlock%
  1742. shadeIcon(window%, icon%, flag%)
  1743.  flag% 
  1744. setIconState(window%, icon%, 1 << 22, 1 << 22)
  1745. setIconState(window%, icon%,       0, 1 << 22)
  1746. setIconForegroundColour(window%, icon%, colour%)
  1747. setIconState(window%, icon%, colour% << 24, 15 << 24)
  1748. setIconBackgroundColour(window%, icon%, colour%)
  1749. setIconState(window%, icon%, colour% << 28, 15 << 28)
  1750. ------------------------------------------------------------------------------ Errors
  1751. wimpError
  1752.  response%
  1753.  0, 0
  1754. !WimpBlock% = 
  1755. @$(WimpBlock% + 4) = 
  1756. $ + " (Error code " + 
  1757. ) + ")" + 
  1758.  "Wimp_ReportError", WimpBlock%, 3, TaskName$ 
  1759.  ,response%
  1760.  response% = 2 
  1761.  Quit% = 
  1762. wimpCloseDown: 
  1763. wimpComplain(complainToken$, arg1$, arg2$)
  1764.  complain$
  1765. Fcomplain$ = 
  1766. messageLookupStringArgs(complainToken$, arg1$, arg2$)
  1767. !WimpBlock% = 0
  1768. messageLookup(complainToken$, WimpBlock% + 4, 250)
  1769.  "Wimp_ReportError", WimpBlock%, 17, TaskName$
  1770. ------------------------------------------------------------------------------- Menus
  1771. openMenu(menu%, x%, y%)
  1772.  Open a menu, remembering details in case it is to be kept open
  1773. x% -= 60
  1774. CurrentMenu% = menu%
  1775. *CurrentMenuX% = x%: CurrentMenuY% = y%
  1776.  "Wimp_CreateMenu",, menu%, x%, y%
  1777. closeMenu
  1778.  "Wimp_CreateMenu",, -1
  1779. openIconBarMenu(menu%, x%)
  1780.  This opens a menu with correct y position relative to the icon bar
  1781.  menuItemHeight%, menuItemGap%, menuHeight%, tempMenu%
  1782. 7menuItemHeight% = menu%!20: menuItemGap% = menu%!24
  1783.  menu%!0 = 0 
  1784.  menuHeight% = menuItemGap% 
  1785.  menuHeight% = menuItemHeight% + menuItemGap%
  1786. tempMenu% = menu% + 4
  1787.   tempMenu% += 24
  1788. $  menuHeight% += menuItemHeight%
  1789.  (tempMenu%!0 
  1790.  menuHeight% += 24
  1791.  (tempMenu%!0 
  1792.  &80) <> 0
  1793. openMenu(menu%, x%, menuHeight% + 56)
  1794. reopenCurrentMenu
  1795.  Tests to see if the current menu should stay open.
  1796.  (Adjust has been used to select option)
  1797.  "Wimp_GetPointerInfo",, WimpBlock%
  1798.  WimpBlock%!8 = AdjustClick 
  1799.  "Wimp_CreateMenu",, CurrentMenu%, CurrentMenuX%, CurrentMenuY%
  1800. startMenu(titleToken$, start%, 
  1801.  block%)
  1802.  length%
  1803. block% = start%
  1804. messageLookupLength(titleToken$, block%, 12, length%)
  1805. #0block%!12 = &70207: block%!16 = length% * 16
  1806. $%block%!20 =     40: block%!24 = 0
  1807. block%   += 28
  1808. addMenuItem(itemToken$, subMenu%, menuFlags%, start%, 
  1809.  current%)
  1810.  itemWidth%, length%, address%, item$
  1811. messageRead(itemToken$, address%, length%)
  1812.  current% > start% + 28 
  1813.  current%!-24 = current%!-24 
  1814. ."current%!0  = menuFlags% 
  1815. /5current%!4  = subMenu%: current%!8  =  IconFlags%
  1816. 0,current%!12 = address%: current%!16 = -1
  1817. current%!20 = length%
  1818. current%  += 24
  1819. addMenuItemWidth(address%, length%, start%)
  1820. addMenuItemWidth(address%, charLength%, start%)
  1821.  This ensures that the menu is wide enough for all entries
  1822.  itemWidth%
  1823.  MenuFonts% 
  1824.  "Font_StringWidth",, address%, 1E8, 1E8, -1, 1E8 
  1825.  ,, itemWidth%
  1826.  "Font_ConverttoOS",, itemWidth%, 0 
  1827.  , itemWidth%
  1828. @#  itemWidth% = charLength% * 16
  1829. itemWidth% += 16
  1830.  itemWidth% > start%!16 
  1831.  start%!16 = itemWidth%
  1832. toggleTick(menuItem%, start%)
  1833.  current%
  1834. J1current%   = (start% + 28) + (menuItem% * 24)
  1835. current%!0 = current%!0 
  1836. shadeMenuItem(menuItem%, start%, flag%)
  1837.  current%
  1838. Q/current% = (start% + 28) + (menuItem% * 24)
  1839.  flag% 
  1840. S)  current%!8 = current%!8 
  1841.  (1 << 22)
  1842. U-  current%!8 = current%!8 
  1843.  (1 << 22))
  1844. ------------------------------------------------------------------------------ Caret
  1845. removeCaret
  1846.  "Wimp_SetCaretPosition", -1
  1847. --------------------------------------------------------------------------- Drag Box
  1848. dragBox(window%, icon%)
  1849.  x0%, y0%
  1850. getWindowState(window%)
  1851. getOrigin(x0%, y0%)
  1852. getIconState(window%, icon%)
  1853. f:!WimpBlock%   = window%            : WimpBlock%!4  = 5
  1854. gLWimpBlock%!8  = x0% + WimpBlock%!8 : WimpBlock%!12 = y0% + WimpBlock%!12
  1855. hLWimpBlock%!16 = x0% + WimpBlock%!16: WimpBlock%!20 = y0% + WimpBlock%!20
  1856. i:WimpBlock%!24 = 0                  : WimpBlock%!28 = 0
  1857. jBWimpBlock%!32 = &7FFFFFFF          : WimpBlock%!36 = &7FFFFFFF
  1858. dragASprite 
  1859.  (window% = SaveWindow%) 
  1860.  "DragASprite_Start", 197, 1, "file_099", WimpBlock% + 8, WimpBlock% + 24
  1861.  "Wimp_DragBox",, WimpBlock%
  1862. ----------------------------------------------------------------------------- Pointer
  1863. getPointerInfo
  1864.  "Wimp_GetPointerInfo",, WimpBlock%
  1865. ------------------------------------------------------------------------- DragASprite
  1866. dragASprite
  1867.  Answer true if you use solid sprite dragging
  1868.  flags%, temp%
  1869.  "XOS_SWINumberFromString",, "DragASprite_Start" 
  1870.  temp% ;flags%
  1871.  "OS_Byte", 161, 28 
  1872.  ,,temp%
  1873.  ((temp% 
  1874.  2) = 2) 
  1875.  (flags% 
  1876. *************************************************************************************
  1877. *********************************************************************** Memory system
  1878. *************************************************************************************
  1879. initializeHeap
  1880.  Use Heap Manager to provide useful memory management system
  1881.  Ensure that there is 1 page of free space within the heap to use
  1882.  Assumes that App loads at &8000
  1883. HeapBlock% = 
  1884.  "OS_ReadMemMapInfo" 
  1885.  SystemPageSize%
  1886.  "Wimp_SlotSize", HeapBlock% - &8000 + SystemPageSize%, -1 
  1887.  HeapEnd%
  1888. HeapEnd% += &8000
  1889.  HeapEnd% <= HeapBlock% 
  1890.  255, "Not enough memory for Heap block"
  1891.  "OS_Heap", 0, HeapBlock%,, HeapEnd% - HeapBlock%
  1892. getHeapBlock(blockSize%)
  1893.  This attempt to get a block of memory from the HeapManager of
  1894.  size blockSize%. If it fails it attempts to increase the tasks
  1895.  SlotSize
  1896.  freeBlockSize%, slotIncrease%, oldHeapEnd%, blockPointer%
  1897.  blockSize% = 0 
  1898.  blockSize%=1: 
  1899.  Get around heap specification problem
  1900.  "OS_Heap", 1, HeapBlock% 
  1901.  ,, freeBlockSize%
  1902.  freeBlockSize% < blockSize% 
  1903.   oldHeapEnd%   = HeapEnd%
  1904. L  HeapEnd% = 
  1905. extendSlotSize((blockSize% 
  1906.  SystemPageSize%) + 1) + &8000
  1907.  "OS_Heap", 5, HeapBlock%,, HeapEnd% - oldHeapEnd%
  1908.  "OS_Heap", 1, HeapBlock% 
  1909.  ,, freeBlockSize%, t%
  1910.  freeBlockSize% < blockSize% 
  1911.  255, 
  1912. messageLookupString("HeapFree")
  1913.  "OS_Heap", 2, HeapBlock%,, blockSize% 
  1914.  ,,blockPointer%
  1915. =blockPointer%
  1916. freeHeapBlock(blockPointer%)
  1917.  freeBlockSize%, numberFreePages%, flags%
  1918.  "OS_Heap", 3, HeapBlock%, blockPointer%
  1919.  "OS_Heap", 1, HeapBlock% 
  1920.  ,, freeBlockSize%
  1921.  This isn't finished...
  1922.  freeBlockSize% > SystemPageSize% 
  1923. A    
  1924.  "XOS_Heap", 5, HeapBlock%,, -SystemPageSize% 
  1925.  ;flags%
  1926.  (flags% 
  1927.  1) = 0 
  1928.       numberFreePages% += 1
  1929. %      HeapEnd% -= SystemPageSize%
  1930.         
  1931.  flags% 
  1932.  numberFreePages% > 0 
  1933. 4    flags% = 
  1934. extendSlotSize(- numberFreePages%)
  1935. extendHeapBlock(
  1936.  blockPointer%, change%)
  1937.  Note may change blockPointer%, so have to return
  1938.  Doesn't extend the Wimp_SlotSize yet
  1939.  flags%, temp%
  1940.  "XOS_Heap", 4, HeapBlock%, blockPointer%, change% 
  1941.  ,, blockPointer% ;flags%
  1942.  flags% 
  1943.    temp% = 
  1944. extendSlotSize(1)
  1945.  "OS_Heap",  5, HeapBlock%,, SystemPageSize%
  1946.  "XOS_Heap", 4, HeapBlock%, blockPointer%, change% 
  1947.  ,, blockPointer% ;flags%
  1948. --------------------------------------------------------------------------- Slot Size
  1949. extendSlotSize(changePages%)
  1950.  This attempts to increase the Task SlotSize by the number of pages
  1951.  defined in the parameter. Error if not possible
  1952.  oldTaskSize%, newTaskSize%, actualTaskSize%
  1953.  "Wimp_SlotSize", -1, -1 
  1954.  oldTaskSize%
  1955. BnewTaskSize% = oldTaskSize% + (SystemPageSize% * changePages%)
  1956.  "Wimp_SlotSize", newTaskSize%, -1 
  1957.  actualTaskSize%
  1958.  actualTaskSize% <> newTaskSize% 
  1959.  255, "Could not extend tasks slot size"
  1960. =newTaskSize%
  1961. *************************************************************************************
  1962. ******************************************************************* Initializing Game
  1963. *************************************************************************************
  1964. initializeGame
  1965. PROCinitializeGameVariables
  1966. PROCinitializeSides
  1967. initializeSidesTotal
  1968. initializeComputerBlock
  1969. initializePlanetVariables
  1970. initializePlanets
  1971. initializeJourneyTimes
  1972. initializeStatistics
  1973. initializeGraphs
  1974. initializeSortedOnShips
  1975. initializeComputerSides
  1976. initializeMovementOrders
  1977. "StartSide%   = 
  1978. (NumberSides%)
  1979. initializeGameVariables
  1980.  dummy
  1981. -dummy = 
  1982.  Randomize the randomizer
  1983. $CurrentTurn% = 1: EndOfTurn% = 
  1984. MaximumResources% = 250
  1985. CurrentWorld% = 1
  1986. loadGameVariables(file%)
  1987. #file%, CurrentTurn%, EndOfTurn%, CurrentWorld%, NumberPlanets%, StartSide%
  1988. saveGameVariables(file%)
  1989. #file%, CurrentTurn%, EndOfTurn%, CurrentWorld%, NumberPlanets%, StartSide%
  1990. initializeSides
  1991.  Note that: Side = 0, is Neutral always
  1992.  The SidePlayer%() determines
  1993.     0  Human player
  1994.     1  Computer Player -
  1995.  loop%
  1996. (NumberSides% = 6: MaximumSides% = 10
  1997.  SideNames$(MaximumSides%), SideFlags$(MaximumSides%), SidePlayer%(MaximumSides%)
  1998.  loop% = 0 
  1999.  MaximumSides%
  2000. B  SideNames$(loop%) = 
  2001. messageLookupString("Side"  + 
  2002. (loop%))
  2003. B  SideFlags$(loop%) = 
  2004. messageLookupString("SideS" + 
  2005. (loop%))
  2006.  loop%
  2007. )SidePlayer%(0) = 99: 
  2008.  Set up Neutral
  2009. >SidePlayer%(1) = 0: SidePlayer%(2) = 2: SidePlayer%(3) = 0
  2010.     >SidePlayer%(4) = 4: SidePlayer%(5) = 5: SidePlayer%(6) = 5
  2011. >SidePlayer%(7) = 4: SidePlayer%(8) = 4: SidePlayer%(9) = 2
  2012. SidePlayer%(10)= 2
  2013. NumberComputerPlayers% = 6
  2014. loadSides(file%)
  2015.  side%
  2016. #file%, CurrentSide%, EndOfTurn%
  2017. #file%, NumberSides%
  2018.  side% = 1 
  2019.  NumberSides%
  2020. #file%, SidePlayer%(side%)
  2021.  side%
  2022. saveSides(file%)
  2023.  side%
  2024. #file%, CurrentSide%, EndOfTurn%
  2025. #file%, NumberSides%
  2026.  side% = 1 
  2027.  NumberSides%
  2028. #file%, SidePlayer%(side%)
  2029.  side%
  2030. initializeSidesTotal
  2031.  SideTotalPlanets%(NumberSides%), SideTotalShips%(NumberSides%)
  2032.  SideTotalResources%(NumberSides%)
  2033. initializeComputerBlock
  2034.  Some computer players require their own block of memory to store
  2035.  bits and pieces in. This defines the appropriate areas.
  2036.  Care has to be taken in this system not to write or read outside
  2037.  the appropriate block of memory
  2038.  loop%, totalRequiredMemory%, currentComputerBlock%
  2039.  loop% = 1 
  2040.  NumberSides%
  2041. 1I  totalRequiredMemory% += 
  2042. computerRequiredMemory(SidePlayer%(loop%))
  2043.  loop%
  2044. 4<ComputerBlock%     = 
  2045. getHeapBlock(totalRequiredMemory%)
  2046. 5-ComputerBlockSize% = totalRequiredMemory%
  2047.  ComputerBlockPtr%(NumberSides%)
  2048. 8*currentComputerBlock% = ComputerBlock%
  2049.  loop% = 1 
  2050.  NumberSides%
  2051. :6  ComputerBlockPtr%(loop%) = currentComputerBlock%
  2052. ;L  currentComputerBlock%   += 
  2053. computerRequiredMemory(SidePlayer%(loop%))
  2054.  loop%
  2055. loadComputerBlock(file%)
  2056.  loop%, data%, total%
  2057. #file%, total%
  2058.  total% <> ComputerBlockSize% 
  2059.  1, "ComputerBlock sizes do not match!"
  2060.  loop% = ComputerBlock% 
  2061.  (ComputerBlock% + ComputerBlockSize%) - 1 
  2062. #file%, data%
  2063.   !loop% = data%
  2064.  loop%
  2065.  loop% = 1 
  2066.  NumberSides%
  2067. #file%, data%
  2068. J7  ComputerBlockPtr%(loop%) = data% + ComputerBlock%
  2069.  loop%
  2070. saveComputerBlock(file%)
  2071.  loop%
  2072. #file%, ComputerBlockSize%
  2073.  loop% = ComputerBlock% 
  2074.  (ComputerBlock% + ComputerBlockSize%) - 1 
  2075. #file%, !loop%
  2076.  loop%
  2077.  loop% = 1 
  2078.  NumberSides%
  2079. #file%, ComputerBlockPtr%(loop%) - ComputerBlock%
  2080.  loop%
  2081. initializePlanetVariables
  2082. NumberPlanets% = 22
  2083. MaximumPlanetOffset% = 100
  2084. ]!MaximumPlanetResources% = 100
  2085.  PlanetPosition(NumberPlanets%, 1)
  2086.  PlanetName$(NumberPlanets%)
  2087.  PlanetResources(NumberPlanets%)
  2088.  PlanetSide(NumberPlanets%)
  2089.  PlanetShips%(NumberPlanets%)
  2090. initializePlanets
  2091.  Temporary fiddle with NumberPlanets% to improve efficiency
  2092.  of FNuniquePlanetPosition()
  2093.  loop%, tempNumberPlanets%, defaultPlanetName$
  2094. k:defaultPlanetName$ = 
  2095. messageLookupString("DefPlanet")
  2096. l'tempNumberPlanets% = NumberPlanets%
  2097.  loop% = 1 
  2098.  tempNumberPlanets%
  2099.   NumberPlanets% = loop%
  2100. findUniquePlanetPosition(PlanetPosition(loop%, 0), PlanetPosition(loop%, 1))
  2101. p<  PlanetName$(loop%)     = defaultPlanetName$ + 
  2102. (loop%)
  2103. q9  PlanetResources(loop%) = 
  2104. (MaximumPlanetResources%)
  2105. r   PlanetSide(loop%)      = 0
  2106. s5  PlanetShips%(loop%)    = PlanetResources(loop%)
  2107.  loop%
  2108.  Set up initial planets for teams
  2109.  loop% = 1 
  2110.  NumberSides%
  2111. x$  PlanetSide(loop%)      = loop%
  2112. y:  PlanetResources(loop%) = MaximumPlanetResources% / 2
  2113. z:  PlanetShips%(loop%)    = MaximumPlanetResources% / 2
  2114.  loop%
  2115. updateTotalPlanetShipsAverage
  2116. loadPlanets(file%)
  2117.  loop%
  2118.  loop% = 1 
  2119.  NumberPlanets%
  2120. #file%, PlanetPosition(loop%, 0), PlanetPosition(loop%, 1)
  2121. #file%, PlanetName$(loop%), PlanetResources(loop%), PlanetSide(loop%)
  2122. #file%, PlanetShips%(loop%)
  2123.  loop%
  2124. updateTotalPlanetShipsAverage
  2125. savePlanets(file%)
  2126.  loop%
  2127.  loop% = 1 
  2128.  NumberPlanets%
  2129. #file%, PlanetPosition(loop%, 0), PlanetPosition(loop%, 1)
  2130. #file%, PlanetName$(loop%), PlanetResources(loop%), PlanetSide(loop%)
  2131. #file%, PlanetShips%(loop%)
  2132.  loop%
  2133. findUniquePlanetPosition(
  2134.  x%, 
  2135. "  x% = 
  2136. (MaximumPlanetOffset%)
  2137. "  y% = 
  2138. (MaximumPlanetOffset%)
  2139. uniquePlanetPosition(x%, y%)
  2140. uniquePlanetPosition(x%, y%)
  2141.  loop%
  2142.  Make sure that we don't overlap planets on main window
  2143.  loop% = 1 
  2144.  NumberPlanets% - 1
  2145.  PlanetPosition(loop%, 0) = x% 
  2146.  PlanetPosition(loop%, 1) = y% 
  2147.  loop%
  2148.  Leave space at top left of Main window for PointerOverPlanet details
  2149.  (x% < 60) 
  2150.  (y% <= 8) 
  2151. initializeJourneyTimes
  2152. JourneySpeed%   = 20
  2153. GMaxJourneyTime% = 
  2154. ((MaximumPlanetOffset% ^ 2) * 2) / JourneySpeed%
  2155. initializeStatistics
  2156.  loop%, side%
  2157.  Set up totals for Statistics Window
  2158.  loop% = 1 
  2159.  NumberPlanets%
  2160.   side% = PlanetSide(loop%)
  2161. 7  SideTotalShips%(side%)     += PlanetShips%(loop%)
  2162. %  SideTotalPlanets%(side%)   += 1
  2163. :  SideTotalResources%(side%) += PlanetResources(loop%)
  2164.  loop%
  2165. loadStatistics(file%)
  2166.  loop%
  2167.  loop% = 0 
  2168.  NumberSides%
  2169. #file%, SideTotalShips%(loop%), SideTotalPlanets%(loop%), SideTotalResources%(loop%)
  2170.  loop%
  2171. saveStatistics(file%)
  2172.  loop%
  2173.  loop% = 0 
  2174.  NumberSides%
  2175. #file%, SideTotalShips%(loop%), SideTotalPlanets%(loop%), SideTotalResources%(loop%)
  2176.  loop%
  2177. initializeGraphs
  2178.  GraphData is stored for each turn, based on totals at the
  2179.  end of that turn for each side
  2180.    0  Total sides ships
  2181.    1  Total sides resources
  2182.    2  Total sides planets
  2183.  Data is stored in blocks, each holding 20 turns worth of information.
  2184.  Up to 20 of blocks, 4000 turns...
  2185. CurrentGraphChoice% = 1
  2186.  GraphDataMaximum%(2)
  2187. 2GraphBlockEntrySize% = (NumberSides% + 1) * 12
  2188. 4GraphSubBlockSize%   = GraphBlockEntrySize% * 20
  2189. 3GraphBlock% = 
  2190. getHeapBlock(GraphSubBlockSize%)
  2191. updateGraph
  2192. loadGraphs(file%)
  2193.  loop%, side%, start%, A%, B%, C%
  2194.  GraphDataMaximum%(2)
  2195. #file%, CurrentGraphChoice%
  2196. #file%, GraphDataMaximum%(0), GraphDataMaximum%(1), GraphDataMaximum%(2)
  2197. #file%, GraphBlockEntrySize%, GraphSubBlockSize%
  2198. PGraphBlock% = 
  2199. getHeapBlock( ((CurrentTurn% 
  2200.  20) + 1) * GraphSubBlockSize%)
  2201. /start% = GraphBlock% + GraphBlockEntrySize%
  2202.  loop% = 1 
  2203.  CurrentTurn%
  2204.  side% = 0 
  2205.  NumberSides%
  2206. #file%, A%, B%, C%
  2207.         :
  2208. 3    start%!0 = A%: start%!4 = B%: start%!8 = C%
  2209.     start% += 12
  2210.  side%
  2211.  loop%
  2212. saveGraphs(file%)
  2213.  loop%, side%, start%
  2214. #file%, CurrentGraphChoice%
  2215. #file%, GraphDataMaximum%(0), GraphDataMaximum%(1), GraphDataMaximum%(2)
  2216. #file%, GraphBlockEntrySize%, GraphSubBlockSize%
  2217. /start% = GraphBlock% + GraphBlockEntrySize%
  2218.  loop% = 1 
  2219.  CurrentTurn%
  2220.  side% = 0 
  2221.  NumberSides%
  2222. -    
  2223. #file%, start%!0, start%!4, start%!8
  2224.     start% += 12
  2225.  side%
  2226.  loop%
  2227. initializeSortedOnShips
  2228.  loop%
  2229.  PlanetSortedOnShips%(NumberPlanets%)
  2230.  loop% = 1 
  2231.  NumberPlanets%
  2232. )  PlanetSortedOnShips%(loop%) = loop%
  2233.  loop%
  2234. updatePlanetSortedOnShips
  2235. loadSortedOnShips(file%)
  2236.  loop%
  2237.  PlanetSortedOnShips%(NumberPlanets%)
  2238.  loop% = 1 
  2239.  NumberPlanets%
  2240. #file%, PlanetSortedOnShips%(loop%)
  2241.  loop%
  2242. saveSortedOnShips(file%)
  2243.  loop%
  2244.  loop% = 1 
  2245.  NumberPlanets%
  2246. #file%, PlanetSortedOnShips%(loop%)
  2247.  loop%
  2248. initializeComputerSides
  2249.  loop%
  2250.  loop% = 1 
  2251.  NumberSides%
  2252.  SidePlayer%(loop%) 
  2253.     %0    
  2254.  3: !(ComputerBlockPtr%(loop%)) = loop%
  2255.     &0    
  2256.  4: !(ComputerBlockPtr%(loop%)) = loop%
  2257.     '0    
  2258.  5: !(ComputerBlockPtr%(loop%)) = loop%
  2259.     ()    
  2260. spClearAttackDetails(loop%)
  2261.  loop%
  2262. initializeMovementOrders
  2263.  A movement order has the form:
  2264.  -0--   -----1-------   ------2-----  ---------3--------
  2265.  Side   Turn arriving   Number ships  Destination planet
  2266.  Note to show that a particular MovementOrder slot is free, the side
  2267.  is set to 0. Note: Neutral planets NEVER move ships, etc.
  2268.     6;MaximumMovementOrders% = 100: NumberMovementOrders% = 1
  2269.  MovementOrders%(MaximumMovementOrders%, 3)
  2270. MovementOrders%() = 0
  2271.     :%OrderSide  = 0: OrderArriving = 1
  2272.     ;%OrderShips = 2: OrderPlanet   = 3
  2273. loadMovementOrders(file%)
  2274.  loop%
  2275. #file%, NumberMovementOrders%
  2276.  NumberMovementOrders% > MaximumMovementOrders% 
  2277.  255, "Saved game needs more than MaximumMovementOrders%"
  2278.  loop% = 1 
  2279.  NumberMovementOrders%
  2280.     EC  
  2281. #file%, MovementOrders%(loop%, 0), MovementOrders%(loop%, 1)
  2282.     FC  
  2283. #file%, MovementOrders%(loop%, 2), MovementOrders%(loop%, 3)
  2284.  loop%
  2285. saveMovementOrders(file%)
  2286.  loop%
  2287. #file%, NumberMovementOrders%
  2288.  loop% = 1 
  2289.  NumberMovementOrders%
  2290.     PC  
  2291. #file%, MovementOrders%(loop%, 0), MovementOrders%(loop%, 1)
  2292.     QC  
  2293. #file%, MovementOrders%(loop%, 2), MovementOrders%(loop%, 3)
  2294.  loop%
  2295. *************************************************************************************
  2296. ********************************************************************** Game Mechanics
  2297. *************************************************************************************
  2298. --------------------------------------------------------------------- Movement Orders
  2299. moveShipsFromTo(numberShips%, startPlanet%, destinationPlanet%)
  2300.  This is the top level PROC for setting movement orders.
  2301.  This procedure should be called from outside the MovementOrders module
  2302.  journeyTime%
  2303.     ^AjourneyTime% = 
  2304. journeyTime(startPlanet%, destinationPlanet%)
  2305. newMovementOrder(CurrentSide%, CurrentTurn% + journeyTime%, numberShips%, destinationPlanet%)
  2306.     `.PlanetShips%(startPlanet%) -= numberShips%
  2307. redrawWindowArea(OrdersWindow%, 0, -9000, 9000, -124)
  2308. journeyTime(startPlanet%, destinationPlanet%)
  2309.  Calculates the number of turns to travel between the two planets
  2310. max( 
  2311. distanceBetweenPlanets(startPlanet%, destinationPlanet%) / JourneySpeed%), 1)
  2312. newMovementOrder(side%, arrivalTurn%, numberShips%, destinationPlanet%)
  2313.  Stores the details for a movementOrder. If there is a similar order already in
  2314.  place then the two orders are merged, so the ships arrive in one large group
  2315.  slot%, loop%, success%
  2316. success% = 
  2317.  loop% = 1 
  2318.  NumberMovementOrders%
  2319.  (MovementOrders%(loop%, 0) = side%) 
  2320.  (MovementOrders%(loop%, 1) = arrivalTurn%) 
  2321.  (MovementOrders%(loop%, 3) = destinationPlanet%) 
  2322.     q1    MovementOrders%(loop%, 2) += numberShips%
  2323.     success% = 
  2324.  loop%
  2325.  success% 
  2326.     w$  slot% = 
  2327. nextFreeMovementOrder
  2328.     x'  MovementOrders%(slot%, 0) = side%
  2329.     y.  MovementOrders%(slot%, 1) = arrivalTurn%
  2330.     z.  MovementOrders%(slot%, 2) = numberShips%
  2331.     {4  MovementOrders%(slot%, 3) = destinationPlanet%
  2332. nextFreeMovementOrder
  2333.  loop%
  2334.  loop% = 1 
  2335.  NumberMovementOrders%
  2336.  MovementOrders%(loop%, 0) = 0 
  2337.  =loop%
  2338.  loop%
  2339.  Have to 'add' another slot onto the end
  2340. NumberMovementOrders% += 1
  2341.  NumberMovementOrders% > MaximumMovementOrders% 
  2342.  255, 
  2343. messageLookupString("ErrFreeMov")
  2344. =NumberMovementOrders%
  2345. freeMovementOrder(slot%)
  2346.  This blanks slot%, and if it is the last slot it travels
  2347.  back through the slots trying to reduce NumberMovementOrders%
  2348. blankMovementOrder(slot%)
  2349.  (slot% = NumberMovementOrders%) 
  2350.  slot% >= 2
  2351.    NumberMovementOrders% -= 1
  2352.  MovementOrders%(NumberMovementOrders%, 0) = 0 
  2353.  slot% -= 1
  2354. blankMovementOrder(slot%)
  2355. !MovementOrders%(slot%, 0) = 0
  2356. !MovementOrders%(slot%, 1) = 0
  2357. !MovementOrders%(slot%, 2) = 0
  2358. !MovementOrders%(slot%, 3) = 0
  2359. *************************************************************************** Next Turn
  2360. nextTurn
  2361. CurrentTurn% += 1
  2362.  CurrentTurn% 
  2363.  20 = 0 
  2364.  Need to extend GraphBlock, by space for 20 more turns
  2365. extendHeapBlock(GraphBlock%, GraphSubBlockSize%)
  2366. diagnosis("Turn: "+
  2367. (CurrentTurn%)+"---------------------------------------------------")
  2368. shadeMenuItem(1, MainMenu%, 
  2369. completeMovementOrders
  2370.  Recalculate totals for use in StatisticsWindow
  2371.  "Hourglass_On"
  2372. updatePlanetResources
  2373. updatePlanetShips
  2374. updateTotalPlanetShipsAverage
  2375. updateMovedShips
  2376. updatePlanetSides
  2377. updatePlanetSortedOnShips
  2378. updateGraph
  2379.  WinnerContinue% 
  2380. findWinner
  2381. EndOfTurn% = 
  2382. shadeMenuItem(0, MainMenu%, 
  2383. shadeMenuItem(1, MainMenu%,  
  2384. updateWorldWindow(CurrentWorld%)
  2385. updateSideWindow(SideWindowSide%)
  2386. redrawWindow(OrdersWindow%)
  2387. redrawWindow(GraphWindow%)
  2388. redrawWindowArea(SortedPlanetsWindow%, 0, -9000, 1000, -64)
  2389. redrawWindowArea(StatisticsWindow%, 294, -1000, 1000, -68)
  2390.  "Hourglass_Off"
  2391. !StartSide% = 
  2392. (NumberSides%):
  2393. changeSides(StartSide%)
  2394. findWinner
  2395.  Attempts to find if there is a winner this turn.
  2396.  side%, winnerSide%, winnerTotal%, sideTotal%, totalToWin%
  2397.  side% = 0 
  2398.  NumberSides%
  2399. +  totalToWin% += SideTotalShips%(side%)
  2400. /  totalToWin% += SideTotalResources%(side%)
  2401.  side%
  2402.  Winner needs more than 60% of total ships and resources
  2403. #totalToWin% = totalToWin% * 0.6
  2404.  side% = 1 
  2405.  NumberSides%
  2406. F  sideTotal% = SideTotalShips%(side%) + SideTotalResources%(side%)
  2407.  (sideTotal% > totalToWin%) 
  2408.  (sideTotal% > winnerTotal%) 
  2409.     winnerSide%  = side%
  2410. !    winnerTotal% = sideTotal%
  2411.  side%
  2412.  winnerSide% <> 0 
  2413.  We have a winner
  2414.  "Hourglass_Off"
  2415. startWinnerWindow(winnerSide%)
  2416. wimpPoll
  2417.  WinnerContinue%
  2418.  "Hourglass_On"
  2419. updatePlanetResources
  2420.  loop%, newResources%, side%
  2421. SideTotalResources%() = 0
  2422.  loop% = 1 
  2423.  NumberPlanets%
  2424.   side% = PlanetSide(loop%)
  2425.  side% > 0 
  2426. D    newResources% = 
  2427. resourcesIncreaseTo(PlanetResources(loop%))
  2428. .    PlanetResources(loop%) = newResources%
  2429. .    newResources% = PlanetResources(loop%)
  2430. 1  SideTotalResources%(side%) += newResources%
  2431.  loop%
  2432. resourcesIncreaseTo(currentResources%)
  2433.  Increases currentResources% by one turn
  2434. min(MaximumResources%, 
  2435. max(currentResources% + 1, currentResources% * 1.05)) )
  2436. shipsIncreaseFromResourcesOver(currentResources%, turns%)
  2437.  Predicts the extra ships gained due to resources over a number of turns%
  2438.  loop%, shipsIncrease%
  2439.  loop% = 1 
  2440.  turns%
  2441. B  currentResources% += 
  2442. resourcesIncreaseTo(currentResources%)
  2443. 1  shipsIncrease%    += currentResources% 
  2444.  loop%
  2445. =shipsIncrease%
  2446. updatePlanetShips
  2447.  loop%, newShips%, side%
  2448. SideTotalShips%() = 0
  2449.  loop% = 1 
  2450.  NumberPlanets%
  2451.   side% = PlanetSide(loop%)
  2452.  side% > 0 
  2453. G    newShips% = (PlanetResources(loop%) 
  2454.  10) + PlanetShips%(loop%)
  2455. '    PlanetShips%(loop%) = newShips%
  2456. '    newShips% = PlanetShips%(loop%)
  2457. )  SideTotalShips%(side%) += newShips%
  2458.  loop%
  2459. updateTotalPlanetShipsAverage
  2460.  planet%
  2461. TotalPlanetShipsAverage = 0
  2462.  planet% = 1 
  2463.  NumberPlanets%
  2464. 6  TotalPlanetShipsAverage += PlanetShips%(planet%)
  2465.  planet%
  2466. FTotalPlanetShipsAverage = TotalPlanetShipsAverage / NumberPlanets%
  2467. updatePlanetSides
  2468.  loop%, side%
  2469. SideTotalPlanets%() = 0
  2470.  loop% = 1 
  2471.  NumberPlanets%
  2472.   side% = PlanetSide(loop%)
  2473. $#  SideTotalPlanets%(side%) += 1
  2474.  loop%
  2475. updateMovedShips
  2476.  This just adds details for ships that are being moved to the
  2477.  SideTotalShips%()
  2478.  loop%, side%
  2479.  loop% = 1 
  2480.  NumberMovementOrders%
  2481. .'  side% = MovementOrders%(loop%, 0)
  2482.  side% > 0 
  2483.  SideTotalShips%(side%) += MovementOrders%(loop%, 2)
  2484.  loop%
  2485. updateGraph
  2486.  loop%, totalShips%, totalResources%, totalPlanets%, graphPointer%
  2487. 6GgraphPointer% = GraphBlock% + (GraphBlockEntrySize% * CurrentTurn%)
  2488.  loop% = 0 
  2489.  NumberSides%
  2490. 8.  totalShips%     = SideTotalShips%(loop%)
  2491. 92  totalResources% = SideTotalResources%(loop%)
  2492. :0  totalPlanets%   = SideTotalPlanets%(loop%)
  2493. <H  GraphDataMaximum%(0) = 
  2494. max(totalShips%,     GraphDataMaximum%(0))
  2495. =H  GraphDataMaximum%(1) = 
  2496. max(totalResources%, GraphDataMaximum%(1))
  2497. >H  GraphDataMaximum%(2) = 
  2498. max(totalPlanets%,   GraphDataMaximum%(2))
  2499. @#  graphPointer%!0 = totalShips%
  2500. A'  graphPointer%!4 = totalResources%
  2501. B%  graphPointer%!8 = totalPlanets%
  2502.   graphPointer% += 12
  2503.  loop%
  2504. updatePlanetSortedOnShips
  2505.  Sort planets into increasing PlanetShips%()
  2506.  loop%, minimum%, loop2%, nextPlanet%
  2507.  loop%= 1 
  2508.  NumberPlanets% - 1
  2509. M:  minimum% = PlanetShips%(PlanetSortedOnShips%(loop%))
  2510.  loop2% = loop% + 1 
  2511.  NumberPlanets%
  2512. P2    nextPlanet% = PlanetSortedOnShips%(loop2%)
  2513. Q0    
  2514.  PlanetShips%(nextPlanet%) < minimum% 
  2515. RF      
  2516.  PlanetSortedOnShips%(loop%), PlanetSortedOnShips%(loop2%)
  2517. S.      minimum% = PlanetShips%(nextPlanet%)
  2518. T        
  2519.  loop2%
  2520.  loop%
  2521. completeMovementOrders
  2522.  Goes through all MovementOrders%(). Any that complete this turn are
  2523.  processed then removed from the MovementOrders() list
  2524.  loop%
  2525.  Firstly all ships arriving at a planet they own, are added to that
  2526.  planets ships stockpile before any battles are computed
  2527.  loop% = 1 
  2528.  NumberMovementOrders%
  2529.  (MovementOrders%(loop%, 0) > 0) 
  2530.  (MovementOrders%(loop%, 1) = CurrentTurn%) 
  2531. bM    
  2532.  PlanetSide(MovementOrders%(loop%, 3)) = MovementOrders%(loop%, 0) 
  2533. c!      
  2534. movementArrival(loop%)
  2535. d        
  2536.  loop%
  2537.  Now compute any battles
  2538.  loop% = 1 
  2539.  NumberMovementOrders%
  2540.  (MovementOrders%(loop%, 0) > 0) 
  2541.  (MovementOrders%(loop%, 1) = CurrentTurn%) 
  2542. movementArrival(loop%)
  2543.  loop%
  2544.  Close BattleWindow% if it ever opened
  2545. closeWindow(BattleWindow%)
  2546. movementArrival(slot%)
  2547.  A group of ships have arrived at their destination. They either add
  2548.  themselves to the existing ships if the planet is theirs, or attack
  2549.  it if not
  2550.  planet%, arrivalSide%, planetSide%, arrivalNumber%, planetNumber%
  2551. y.planet%        = MovementOrders%(slot%, 3)
  2552. z.arrivalSide%   = MovementOrders%(slot%, 0)
  2553. {(planetSide%    = PlanetSide(planet%)
  2554. |.arrivalNumber% = MovementOrders%(slot%, 2)
  2555. }*planetNumber%  = PlanetShips%(planet%)
  2556.  arrivalSide% = planetSide% 
  2557. -  PlanetShips%(planet%) += arrivalNumber%
  2558. openWindow(BattleWindow%)
  2559. computeBattle(planet%, planetSide%, planetNumber%, arrivalSide%, arrivalNumber%)
  2560. freeMovementOrder(loop%)
  2561. computeBattle(planet%, planetSide%, planetShips%, arrivalSide%, arrivalShips%)
  2562.  This calculates result of one battle, with Multitasking display of progress
  2563.  wimpMask%, reason%, quit%, finishedBattle%, startTotalShips%
  2564. BattleWorld% = planet%
  2565. startBattleWindow(PlanetName$(planet%), planetSide%, planetShips%, arrivalSide%, arrivalShips%)
  2566. 3startTotalShips% = planetShips% + arrivalShips%
  2567. "quit% = 
  2568. : finishedBattle% = 
  2569. %wimpMask% = %10011111110000110000
  2570.  "Wimp_Poll", wimpMask%, WimpBlock% 
  2571.  reason%
  2572.  reason% 
  2573. 7      
  2574. nextBattleRound(planetShips%, arrivalShips%)
  2575. 8      
  2576.  (planetShips% <= 0) 
  2577.  (arrivalShips% <= 0) 
  2578. %        wimpMask% = wimpMask% 
  2579.         finishedBattle% = 
  2580.         :
  2581. !        
  2582.  arrivalShips% > 0 
  2583. E          
  2584. successfulAttack(planet%, arrivalSide%, arrivalShips%)
  2585.         
  2586. 8          
  2587. unsuccessfulAttack(planet%, planetShips%)
  2588.         
  2589. 8        
  2590. shadeIndirectedIcon(BattleWindowOk%,     
  2591. 8        
  2592. shadeIndirectedIcon(BattleWindowFinish%, 
  2593. R        
  2594. planetDamage(planet%, startTotalShips% - arrivalSide% - planetShips%)
  2595.       
  2596. !    
  2597. redrawWindowRequest
  2598. /    
  2599.  "Wimp_OpenWindow",,  WimpBlock%
  2600. /    
  2601.  "Wimp_CloseWindow",, WimpBlock%
  2602. .    
  2603.  WimpBlock%!12 = BattleWindow% 
  2604. D        
  2605.   WimpBlock%!16 = 12  
  2606.      finishedBattle% 
  2607.  quit% = 
  2608. c        
  2609.  (WimpBlock%!16 = 13) 
  2610.  finishedBattle% 
  2611. finishBattle(planetShips%, arrivalShips%)
  2612.       
  2613.         
  2614. mouseButtonChange
  2615.       
  2616. keyPressed
  2617. menuSelect
  2618.  17, 18: 
  2619. userMessage
  2620.  quit% 
  2621.  Quit%
  2622. PROCcloseWindow(BattleWindow%)
  2623. nextBattleRound(
  2624.  planetShips%, 
  2625.  arrivalShips%)
  2626.  This does the actual calculations of the combat. It works one shot
  2627.  at the time, updating BattleWindow on the way for efficiency
  2628.  total%
  2629.  (planetShips% <= 0) 
  2630.  (arrivalShips% <= 0) 
  2631. )total% = planetShips% + arrivalShips%
  2632. (total%) > planetShips% 
  2633.   planetShips% -= 1
  2634. writeIndirectedBuffer(BattleWindowCurrent1%, 
  2635. (planetShips%))
  2636.   arrivalShips% -= 1
  2637. writeIndirectedBuffer(BattleWindowCurrent2%, 
  2638. (arrivalShips%))
  2639. finishBattle(
  2640.  planetShips%, 
  2641.  arrivalShips%)
  2642.  total%
  2643.  (planetShips% > 1) 
  2644.  (arrivalShips% > 1)
  2645. +  total% = planetShips% + arrivalShips%
  2646. (total%) > planetShips% 
  2647.  planetShips% -=1 
  2648.  arrivalShips% -= 1
  2649. writeIndirectedBuffer(BattleWindowCurrent1%, 
  2650. (planetShips%))
  2651. writeIndirectedBuffer(BattleWindowCurrent2%, 
  2652. (arrivalShips%))
  2653. ------------------------------------------------------------------ Outcome of attacks
  2654. successfulAttack(planet%, arrivalSide%, arrivalShips%)
  2655. &PlanetSide(planet%) = arrivalSide%
  2656. )PlanetShips%(planet%) = arrivalShips%
  2657. writeIndirectedBuffer(BattleWindowComment%, 
  2658. messageLookupString("AWon"))
  2659. redrawPlanet(planet%)
  2660. unsuccessfulAttack(planet%, planetSide%)
  2661. 'PlanetShips%(planet%) = planetSide%
  2662. writeIndirectedBuffer(BattleWindowComment%, 
  2663. messageLookupString("DWon"))
  2664. redrawPlanet(planet%)
  2665. planetDamage(planet%, shipsDestroyed%)
  2666.  If there has been a lot of damage, then it is possible to reduce
  2667.  the resources of a planet becuase of the battle
  2668.  planetDamage, resourcesLost%
  2669. XplanetDamage% = 
  2670. min(shipsDestroyed% / 25, 25) / 100) * PlanetResources(planet%))
  2671. -PlanetResources(planet%) -= planetDamage%
  2672. -------------------------------------------------------------------------------- Bits
  2673. nextSide
  2674.  This is called when the CurrentSide% has finished, and the next side
  2675.  takes over control.
  2676.  If all sides have had a go this turn then, the next turn will begin
  2677.  newSide%
  2678. newSide% = CurrentSide% + 1
  2679.  newSide% > NumberSides% 
  2680.  newSide% = 1
  2681.  newSide% = StartSide% 
  2682. PROCnextTurn
  2683.  Need a Next Turn. Let user select it from MainMenu
  2684.  Also redraw everything to update windows
  2685. shadeMenuItem(0, MainMenu%, 
  2686. shadeMenuItem(1, MainMenu%, 
  2687.   EndOfTurn% = 
  2688. messageLookup("EndTurn", MainWindowTitle%, 20)
  2689. redrawWindowTitle(MainWindow%)
  2690. wimpPoll
  2691. updateWorldWindow(CurrentWorld%)
  2692. changeSides(newSide%)
  2693. changeSides(newSide%)
  2694.  CurrentSide%      = newSide%
  2695. ,$MainWindowTitle% = SideNames$(newSide%)
  2696. redrawWindowTitle(MainWindow%)
  2697. wimpPoll
  2698. computerMove(newSide%)
  2699. updatePlanetSortedOnShips
  2700.  SidePlayer%(newSide%) = 0 
  2701.  Update displays if this player is a human.
  2702.  Computers don't read the windows...
  2703. updateSideWindow(SideWindowSide%)
  2704. updateWorldWindow(CurrentWorld%)
  2705. redrawWindowArea(OrdersWindow%, 0, -9000, 9000, -124)
  2706. redrawWindow(GraphWindow%)
  2707. redrawWindowArea(SortedPlanetsWindow%, 0, -9000, 9000, -64)
  2708. updateSideWindow(SideWindowSide%)
  2709. *************************************************************************************
  2710. ********************************************************************* Computer player
  2711. *************************************************************************************
  2712. computerMove(side%)
  2713.  SidePlayer%(side%) <> 0 
  2714.  "Hourglass_On"
  2715.  SideTotalPlanets%(side%) > 0 
  2716.  SidePlayer%(side%) 
  2717. (%    
  2718. cmoveMadAttacker(side%)
  2719. )/    
  2720. cmoveRestrainedMadAttacker(side%)
  2721. *!    
  2722. cmoveBuildUp(side%)
  2723. +"    
  2724. cmoveBuildUp2(side%)
  2725. ,     
  2726. cmoveExpert(side%)
  2727. cmoveSp(side%)
  2728.  "Hourglass_Off"
  2729. nextSide
  2730.  Skip human if they are dead
  2731.  (SideTotalShips%(side%) = 0) 
  2732.  (SideTotalPlanets%(side%) = 0) 
  2733. nextSide
  2734. computerRequiredMemory(player%)
  2735.  memory%
  2736.  player% 
  2737.  3: memory% = 4
  2738.  4: memory% = 4
  2739.  5: memory% = 4
  2740.  6: memory% = 12
  2741. =memory%
  2742. *************************************************************************************
  2743. ************************************************************************ Mad Attacker
  2744. *************************************************************************************
  2745. cmoveMadAttacker(computerSide%)
  2746.  This is a quick stab at a computer player.
  2747.  Adds a bit of complexity to the game
  2748.  loop%, loop2%, myShips%, transferShips%, tooStrong%, theirPlanet%
  2749.  loop% = 1 
  2750.  NumberPlanets%
  2751.  PlanetSide(loop%) = computerSide% 
  2752. O'    myShips%  = PlanetShips%(loop%)
  2753. P        :
  2754. Q"    loop2% = 0: tooStrong% = 
  2755. R        
  2756.       loop2% += 1
  2757. T5      theirPlanet% = PlanetSortedOnShips%(loop2%)
  2758. U7      
  2759.  PlanetSide(theirPlanet%) <> computerSide% 
  2760. VI        transferShips% = 
  2761. calculateTransferShips(theirPlanet%, loop%)
  2762. W$        
  2763.  transferShips% <> -1 
  2764. X+          
  2765.  transferShips% < myShips% 
  2766. YE            
  2767. moveShipsFromTo(transferShips%, loop%, theirPlanet%)
  2768. Z.            myShips% = PlanetShips%(loop%)
  2769.           
  2770.             tooStrong% = 
  2771.           
  2772.         
  2773.       
  2774.  tooStrong%
  2775.  loop%
  2776. *************************************************************************************
  2777. ************************************************************* Restrained Mad Attacker
  2778. *************************************************************************************
  2779. cmoveRestrainedMadAttacker(computerSide%)
  2780.  This is a quick stab at a computer player.
  2781.  Adds a bit of complexity to the game
  2782.  loop%, loop2%, myShips%, transferShips%, tooStrong%, theirPlanet%
  2783.  loop% = 1 
  2784.  NumberPlanets%
  2785.  PlanetSide(loop%) = computerSide% 
  2786. p'    myShips%  = PlanetShips%(loop%)
  2787. q        :
  2788. r"    loop2% = 0: tooStrong% = 
  2789. s        
  2790.       loop2% +=1
  2791. u5      theirPlanet% = PlanetSortedOnShips%(loop2%)
  2792. v7      
  2793.  PlanetSide(theirPlanet%) <> computerSide% 
  2794. wI        transferShips% = 
  2795. calculateTransferShips(theirPlanet%, loop%)
  2796. x$        
  2797.  transferShips% <> -1 
  2798. yk          
  2799.  (myShips% - transferShips% >= (PlanetResources(loop%) 
  2800.  2)) 
  2801.  (transferShips% < myShips%) 
  2802. zE            
  2803. moveShipsFromTo(transferShips%, loop%, theirPlanet%)
  2804. {.            myShips% = PlanetShips%(loop%)
  2805.           
  2806.             tooStrong% = 
  2807.           
  2808.         
  2809.       
  2810.  tooStrong%
  2811.  loop%
  2812. calculateTransferShips(planet%, fromPlanet%)
  2813.  This attempts to calculate the number of ships that
  2814.  are required to send to a planet to take it over.
  2815.  Returns +inf if sufficient ships on their way
  2816.  requiredShips%, loop%, inf%, currentShips%
  2817. 5requiredShips% = PlanetShips%(planet%) * 1.25 + 2
  2818.  loop% = 1 
  2819.  NumberMovementOrders%
  2820.  (MovementOrders%(loop%, 0) = CurrentSide%) 
  2821.  (MovementOrders%(loop%, 3) = planet%) 
  2822. (    
  2823.  Ships are going, but how many?
  2824. 1    currentShips% = MovementOrders%(loop%, 2)
  2825. +    
  2826.  currentShips% >= requiredShips% 
  2827.       =-1
  2828.         
  2829. L      
  2830.  Boost quantity of ships if arrive at time date and are necessary
  2831. }      
  2832. journeyTime(fromPlanet%, planet%) = (MovementOrders%(loop%, 1) - CurrentTurn%) 
  2833.  =requiredShips% - currentShips%
  2834.         
  2835.  loop%
  2836. =requiredShips%
  2837. *************************************************************************************
  2838. **************************************************************************** Build Up
  2839. *************************************************************************************
  2840. cmoveBuildUp(computerSide%)
  2841.  The idea of this computer player is that it tries to keep hold of its
  2842.  planets by leaving a fair number on there. The excess ships it moves
  2843.  to a central planet. From here it decides what to attack.
  2844.  centralPlanet%, planet%, loop%, freeShips%, requiredShips%, resourceShips%
  2845. 8centralPlanet% = !(ComputerBlockPtr%(computerSide%))
  2846.  Ensure the centralPlanet is still ours, if not, find our planet with
  2847.  the highest number of ships on it. Making it our new central planet
  2848.  PlanetSide(centralPlanet%) <> computerSide% 
  2849.    loop% = NumberPlanets% + 1
  2850.     loop% -= 1
  2851. -    planet% = PlanetSortedOnShips%(loop%)
  2852.  PlanetSide(planet%) = computerSide%
  2853. 3  !(ComputerBlockPtr%(computerSide%)) = planet%
  2854.    centralPlanet% = planet%
  2855.  Send any excess ships to central planet. Make sure that the number
  2856.  of ships left is at least 1/6 of PlanetResources() or 2/3 TotalPlanetShipsAverage
  2857.  planet% = 1 
  2858.  NumberPlanets%
  2859.  (PlanetSide(planet%) = computerSide%) 
  2860.  (planet% <> centralPlanet%) 
  2861.     freeShips% = 
  2862. min(PlanetShips%(planet%) - ((2 / 3) * TotalPlanetShipsAverage), PlanetShips%(planet%) - (PlanetResources(planet%) * 0.6))
  2863.  freeShips% > 0 
  2864. ?      
  2865. moveShipsFromTo(freeShips%, planet%, centralPlanet%)
  2866.         
  2867.  planet%
  2868.  Now possibly move any excess held at central planet.
  2869.  Keep more ships at home base because of its importance
  2870. WfreeShips% = PlanetShips%(centralPlanet%) - (PlanetResources(centralPlanet%) * 0.7)
  2871. loop% = 0
  2872.   loop% += 1
  2873. !  planet% = 
  2874. (NumberPlanets%)
  2875. N  requiredShips% = 
  2876. calculateTransferShipsBuildUp(planet%, centralPlanet%)
  2877.  (loop% = 4) 
  2878.  ((requiredShips% <= freeShips%) 
  2879.  (requiredShips% <> -1))
  2880.  If we can, send the ships off. Good luck!!
  2881.  But we may also send off more ships than is required because of
  2882.  the planets large resources.
  2883.  (requiredShips% <= freeShips%) 
  2884.  (freeShips% > 0) 
  2885. 5  resourceShips% = PlanetResources(planet%) * 0.6
  2886.  resourceShips% >= freeShips% 
  2887. #    requiredShips% = freeShips%
  2888. K    
  2889.  resourceShips% > requiredShips% 
  2890.  requiredShips% = resourceShips%
  2891. moveShipsFromTo(requiredShips%, centralPlanet%, planet%)
  2892. calculateTransferShipsBuildUp(planet%, centralPlanet%)
  2893.  This calculates how many ships will have to be sent to planet% to take
  2894.  it over from centralPlanet%
  2895.  loop%, side%
  2896. &side% = PlanetSide(centralPlanet%)
  2897.  PlanetSide(planet%) <> side% 
  2898.  loop% = 1 
  2899.  NumberMovementOrders%
  2900. W    
  2901.  (MovementOrders%(loop%, 0) = side%) 
  2902.  (MovementOrders%(loop%, 3) = planet%) 
  2903. E      
  2904.  We have already sent ships there. Forget it at this stage
  2905.       = -1
  2906.         
  2907.  loop%
  2908.  There are no troops on the way, therefore calculate a value
  2909. ( (PlanetShips%(planet%) + 
  2910. shipsIncreaseFromResourcesOver(PlanetResources(planet%), 
  2911. journeyTime(centralPlanet%, planet%))) * 1.3 )
  2912.   = -1
  2913. *************************************************************************************
  2914. ************************************************************************** Build Up 2
  2915. *************************************************************************************
  2916. cmoveBuildUp2(computerSide%)
  2917.  The idea of this computer player is that it tries to keep hold of its
  2918.  planets by leaving a fair number on there. The excess ships it moves
  2919.  to a central planet. From here it decides what to attack.
  2920.  This includes a number of 'improvements' over BuildUp
  2921.  centralPlanet%, planet%, loop%, freeShips%, requiredShips%, resourceShips%, planetShips%
  2922.  repeatTimes%
  2923. 8centralPlanet% = !(ComputerBlockPtr%(computerSide%))
  2924.  Ensure the centralPlanet is still ours, if not, find our planet with
  2925.  the highest number of ships on it. Making it our new central planet
  2926.  PlanetSide(centralPlanet%) <> computerSide% 
  2927.    loop% = NumberPlanets% + 1
  2928.     loop% -= 1
  2929. -    planet% = PlanetSortedOnShips%(loop%)
  2930.  PlanetSide(planet%) = computerSide%
  2931. 3  !(ComputerBlockPtr%(computerSide%)) = planet%
  2932.    centralPlanet% = planet%
  2933.  Send any excess ships to central planet. Make sure that the number
  2934.  of ships left is at least 1/6 of PlanetResources() or 2/3 TotalPlanetShipsAverage
  2935.  If ships are coming this way may have to retreat to centralPlanet, or build up
  2936.  ships on the planet
  2937.  planet% = 1 
  2938.  NumberPlanets%
  2939.  (PlanetSide(planet%) = computerSide%) 
  2940.  (planet% <> centralPlanet%) 
  2941. ,    planetShips% = PlanetShips%(planet%)
  2942. ~    freeShips% = 
  2943. min(planetShips% - ((2 / 3) * TotalPlanetShipsAverage), planetShips% - (PlanetResources(planet%) * 0.6))
  2944.         :
  2945.     requiredShips% = 0
  2946. +    
  2947.  loop% = 1 
  2948.  NumberMovementOrders%
  2949. b      
  2950.  (MovementOrders%(loop%, 0) <> computerSide%) 
  2951.  (MovementOrders%(loop%, 3) = planet%) 
  2952. S        requiredShips% = 
  2953. max(MovementOrders%(loop%, 2), requiredShips% * 1.10)
  2954.        
  2955.  loop%
  2956.         :
  2957. +    
  2958.  (planetShips% < requiredShips%) 
  2959. 2      
  2960.  planetShips% * 1.10 < requiredShips% 
  2961. C        
  2962. moveShipsFromTo(planetShips%, planet%, centralPlanet%)
  2963.       
  2964.         
  2965. O      freeShips% = 
  2966. min(planetShips% - (requiredShips% * 1.10), freeShips%)
  2967. R      
  2968.  freeShips% > 0 
  2969. moveShipsFromTo(freeShips%, planet%, centralPlanet%)
  2970.         
  2971.  planet%
  2972.  Now possibly move any excess held at central planet.
  2973.  Keep more ships at home base because of its importance
  2974. $0loop% = 0: repeatTimes% = NumberPlanets% / 4
  2975.   loop% += 1
  2976. 'Y  freeShips% = PlanetShips%(centralPlanet%) - (PlanetResources(centralPlanet%) * 0.7)
  2977. (!  planet% = 
  2978. (NumberPlanets%)
  2979. )O  requiredShips% = 
  2980. calculateTransferShipsBuildUp2(planet%, centralPlanet%)
  2981.  requiredShips% >= 0 
  2982. ,4    
  2983.  If we can, send the ships off. Good luck!!
  2984. -I    
  2985.  But we may also send off more ships than is required because of
  2986. .&    
  2987.  the planets large resources.
  2988. /I    
  2989.  Try to get at least 2/3 of TotalPlanetShipsAverage after battle
  2990. 0=    
  2991.  (requiredShips% <= freeShips%) 
  2992.  (freeShips% > 0) 
  2993. 1b      resourceShips% = 
  2994. max(PlanetResources(planet%) * 0.6, (2 / 3) * TotalPlanetShipsAverage)
  2995. 2*      
  2996.  resourceShips% >= freeShips% 
  2997. 3'        requiredShips% = freeShips%
  2998.       
  2999. 5O        
  3000.  resourceShips% > requiredShips% 
  3001.  requiredShips% = resourceShips%
  3002.       
  3003.       :
  3004. 8C      
  3005. moveShipsFromTo(requiredShips%, centralPlanet%, planet%)
  3006. 9        
  3007.  (loop% = repeatTimes%)
  3008. calculateTransferShipsBuildUp2(planet%, centralPlanet%)
  3009.  This calculates how many ships will have to be sent to planet% to take
  3010.  it over from centralPlanet%
  3011.  This also takes into account the number of ships from other sides
  3012.  heading for the planet
  3013.  loop%, side%, transitShips%
  3014. E&side% = PlanetSide(centralPlanet%)
  3015.  PlanetSide(planet%) <> side% 
  3016.  loop% = 1 
  3017.  NumberMovementOrders%
  3018. H1    
  3019.  (MovementOrders%(loop%, 3) = planet%) 
  3020. I/      
  3021.  MovementOrders%(loop%, 0) = side% 
  3022. JG        
  3023.  We have already sent ships there. Forget it at this stage
  3024.         = -1
  3025.       
  3026. MI        
  3027.  another side is sending ships. Have to send more than them!
  3028. NJ        transitShips% = 
  3029. max(MovementOrders%(loop%, 2), transitShips%)
  3030.       
  3031. P        
  3032.  loop%
  3033.  There are no troops on the way, therefore calculate a value
  3034. max( PlanetShips%(planet%) + 
  3035. shipsIncreaseFromResourcesOver(PlanetResources(planet%), 
  3036. journeyTime(centralPlanet%, planet%)), transitShips%) * 1.3 )
  3037.   = -1
  3038. *************************************************************************************
  3039. ****************************************************************************** Expert
  3040. *************************************************************************************
  3041. cmoveExpert(computerSide%)
  3042.  This is another computer player, set out on a depth first, backtracking (???)
  3043.  Expet System style.
  3044.  Hopefully is the best computer player
  3045.  ourPlanets%()
  3046.  planets%, totalPlanets%, central%
  3047. c4totalPlanets% = SideTotalPlanets%(computerSide%)
  3048. e>ExpPlanet = 0: ExpShipsRequired = 1: ExpShipsAvailable = 2
  3049.  ourPlanets%(totalPlanets%, 2)
  3050. expGetPlanetData(computerSide%, ourPlanets%())
  3051. expDefensiveMoves(ourPlanets%(), central%)
  3052. expAttackingMoves(ourPlanets%(), central%)
  3053. expGetPlanetData(side%, 
  3054.  ourPlanets%())
  3055.  This fills ourPlanets%() with the necessary information for later
  3056.  stages of the 'Experts' turn
  3057. expGetOurPlanets(side%, ourPlanets%())
  3058. expAvailableShips(ourPlanets%())
  3059. expRequiredShips(ourPlanets%())
  3060. expGetOurPlanets(side%, 
  3061.  ourPlanets%())
  3062.  This stores all the planets owned by the Expert in ourPlanets%()
  3063.  planet%, ourPlanet%
  3064.  planet% = 1 
  3065.  NumberPlanets%
  3066.  PlanetSide(planet%) = side% 
  3067.     ourPlanet% += 1
  3068. ~4    ourPlanets%(ourPlanet%, ExpPlanet) = planet%
  3069.  planet%
  3070. expAvailableShips(
  3071.  ourPlanets%())
  3072.  This records for each of our planets, the difference between the
  3073.  number of ships there and the number of ships that we would like
  3074.  to be there, to help prevent against new attacks
  3075.  loop%, planet%, requiredShips%
  3076.  loop% = 1 
  3077. (ourPlanets%(), 1)
  3078. -  planet% = ourPlanets%(loop%, ExpPlanet)
  3079. :  requiredShips% = 
  3080. expRequiredDefensiveShips(planet%)
  3081. T  ourPlanets%(loop%, ExpShipsAvailable) = PlanetShips%(planet%) - requiredShips%
  3082.  loop%
  3083. expRequiredShips(
  3084.  ourPlanets%())
  3085.  This records for each of our planets, the number of extra ships
  3086.  that are required to defend successfully against known attacks
  3087.  arriving next turn
  3088.  loop%, planet%, order%, requiredShips%, fiddleAvailable%
  3089.  loop% = 1 
  3090. (ourPlanets%(), 1)
  3091. -  planet% = ourPlanets%(loop%, ExpPlanet)
  3092.   requiredShips% = 0
  3093.  order% = 1 
  3094.  NumberMovementOrders%
  3095. W    requiredShips% = 
  3096. expRequiredShipsOrders(order%, planet%), requiredShips%)
  3097.  order%
  3098.  requiredShips% > 0 
  3099. j    requiredShips% = (requiredShips% * 1.2) - PlanetShips%(planet%) - 
  3100. expOurShipsArrivingNow(planet%)
  3101.  requiredShips% >= 0 
  3102. @      ourPlanets%(loop%, ExpShipsRequired)  = requiredShips%
  3103. 3      ourPlanets%(loop%, ExpShipsAvailable) = 0
  3104.         
  3105. S      fiddleAvailable% = requiredShips% + ourPlanets%(loop%, ExpShipsAvailable)
  3106. `      
  3107.  fiddleAvailable% > 0 
  3108.  ourPlanets%(loop%, ExpShipsAvailable) -= fiddleAvailable% 
  3109.         
  3110.  loop%
  3111. expOurShipsArrivingNow(planet%)
  3112.  This is the amount of ships that are arriving this coming
  3113.  turn at ourPlanet%, that are on our side
  3114.  order%, ships%
  3115.  order% = 1 
  3116.  NumberMovementOrders%
  3117.  MovementOrders%(order%, OrderPlanet) = planet% 
  3118. D    
  3119.  MovementOrders%(order%, OrderSide) = PlanetSide(planet%) 
  3120. G      
  3121.  MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1 
  3122. 9        ships% += MovementOrders%(order%, OrderShips)
  3123.       
  3124.         
  3125.  order%
  3126. =ships%
  3127. expRequiredShipsOrders(order%, planet%)
  3128.  IF the ships of this order are to attack this planet, next turn, then
  3129.  the number of ships necessary to defend the planet well is returned
  3130.  MovementOrders%(order%, OrderPlanet) = planet% 
  3131.  MovementOrders%(order%, OrderSide) <> PlanetSide(planet%) 
  3132. E    
  3133.  MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1 
  3134. /      = MovementOrders%(order%, OrderShips)
  3135.         
  3136. expRequiredDefensiveShips(planet%)
  3137.  Result is the number of ships required to deter an average
  3138.  attack against the planet
  3139. max((2 / 3) * TotalPlanetShipsAverage, PlanetResources(planet%) * 0.6)
  3140. expDefensiveMoves(
  3141.  ourPlanets%(), 
  3142.  central%)
  3143.  This attempts to ensure that any planets under attack can be either
  3144.  sent enough ships to withstand the attack, or retreat if need be
  3145.  loop%, numberOurPlanets%
  3146. +numberOurPlanets% = 
  3147. (ourPlanets%(), 1)
  3148.  loop% = 1 
  3149.  numberOurPlanets%
  3150.  ourPlanets%(loop%, ExpShipsRequired) > 0 
  3151. expGetReinforcements(loop%, ourPlanets%())
  3152.  loop%
  3153.  loop% = 1 
  3154.  numberOurPlanets%
  3155.  ourPlanets%(loop%, ExpShipsAvailable) < -
  3156. shipsIncreaseFromResourcesOver(PlanetResources(ourPlanets%(loop%, ExpPlanet)), 1) 
  3157. expGetBackup(loop%, ourPlanets%())
  3158.  loop%
  3159. /central% = 
  3160. expCentralPlanet(ourPlanets%())
  3161.  loop% = 1 
  3162.  numberOurPlanets%
  3163.  (ourPlanets%(loop%, ExpShipsAvailable) > 0) 
  3164.  (central% <> loop%) 
  3165. moveShipsFromTo(ourPlanets%(loop%, ExpShipsAvailable), ourPlanets%(loop%, ExpPlanet), ourPlanets%(central%, ExpPlanet))
  3166.  loop%
  3167. expGetReinforcements(attacked%, 
  3168.  ourPlanets%())
  3169.  This attempts to get reinforcements from our surrounding planets,
  3170.  that will ensure we have enough ships to defeat an attack. If
  3171.  possible to ensure the defending force has up to 120% the sorce
  3172.  of the attacker
  3173.  loop%, planet%, attackedPlanet%, takeShips%(), takeShipsFraction, takenShips%, totalShips%, requiredShips%, maxRequiredShips%
  3174. 7attackedPlanet% = ourPlanets%(attacked%, ExpPlanet)
  3175.  takeShips%( 
  3176. (ourPlanets%(), 1) )
  3177.  loop% = 1 
  3178. (ourPlanets%(), 1)
  3179. -  planet% = ourPlanets%(loop%, ExpPlanet)
  3180.  planet% <> attackedPlanet% 
  3181. f    
  3182. journeyTime(attackedPlanet%, planet%) = 1) 
  3183.  (ourPlanets%(loop%, ExpShipsAvailable) > 0) 
  3184. C      takeShips%(loop%) = ourPlanets%(loop%, ExpShipsAvailable)
  3185.         
  3186.  loop%
  3187. 'totalShips%       = 
  3188.  takeShips%()
  3189. @requiredShips%    = ourPlanets%(attacked%, ExpShipsRequired)
  3190.  totalShips% >= requiredShips% 
  3191. 6  takeShipsFraction = requiredShips% / totalShips%
  3192.  loop% = 1 
  3193. (ourPlanets%(), 1)
  3194. ;    takenShips% = takeShips%(loop%) * takeShipsFraction
  3195.  takenShips% > 0 
  3196. >      ourPlanets%(loop%, ExpShipsAvailable) -= takenShips%
  3197. W      
  3198. moveShipsFromTo(takenShips%, ourPlanets%(loop%, ExpPlanet), attackedPlanet%)
  3199.         
  3200.  loop%
  3201. 3  ourPlanets%(attacked%, ExpShipsRequired)  = 0
  3202.  Planet can't be saved. Escape
  3203. 4  ourPlanets%(attacked%, ExpShipsRequired)  = -1
  3204. O  ourPlanets%(attacked%, ExpShipsAvailable) = PlanetShips%(attackedPlanet%)
  3205.  Attempt to attack a planet with the ShipsAvailable
  3206. expAttackingMoves(ourPlanets%(), attacked%)
  3207. expGetBackup(defend%, 
  3208.  ourPlanets%())
  3209.  defendPlanet%, requiredShips%, loop%, takeShipsFraction, takenShips%, planet%
  3210.  takeShips%()
  3211. 4defendPlanet%  = ourPlanets%(defend%, ExpPlanet)
  3212. requiredShips% = -(ourPlanets%(defend%, ExpShipsAvailable) + 
  3213. shipsIncreaseFromResourcesOver(PlanetResources(defendPlanet%), 1))
  3214.  takeShips%( 
  3215. (ourPlanets%(), 1) )
  3216.  loop% = 1 
  3217. (ourPlanets%(), 1)
  3218. -  planet% = ourPlanets%(loop%, ExpPlanet)
  3219.  planet% <> defendPlanet% 
  3220. d    
  3221. journeyTime(defendPlanet%, planet%) = 1) 
  3222.  (ourPlanets%(loop%, ExpShipsAvailable) > 0) 
  3223. C      takeShips%(loop%) = ourPlanets%(loop%, ExpShipsAvailable)
  3224.         
  3225.  loop%
  3226. CtakeShipsFraction = 
  3227. min( 
  3228.  takeShips%() / requiredShips%, 1 )
  3229.  loop% = 1 
  3230. (ourPlanets%(), 1)
  3231. !-  planet% = ourPlanets%(loop%, ExpPlanet)
  3232.  planet% <> defendPlanet% 
  3233. #;    takenShips% = takeShips%(loop%) * takeShipsFraction
  3234.  takenShips% > 0 
  3235. %>      ourPlanets%(loop%, ExpShipsAvailable) -= takenShips%
  3236. &?      
  3237. moveShipsFromTo(takenShips%, planet%, defendPlanet%)
  3238. '        
  3239.  loop%
  3240. expAttackingMoves(
  3241.  ourPlanets%(), central%)
  3242.  loop%, theirPlanet%
  3243.  theirPlanets%()
  3244.  theirPlanets%( NumberPlanets% - 
  3245. (ourPlanets%(), 1), 1 )
  3246.  loop% = 1 
  3247.  NumberPlanets%
  3248.  PlanetSide(loop%) <> CurrentSide% 
  3249.     theirPlanet% += 1
  3250. 5.    theirPlanets%(theirPlanet%, 0) = loop%
  3251. 6h    theirPlanets%(theirPlanet%, 1) = 
  3252. expAttackValue(theirPlanet%, ourPlanets%(central%, ExpPlanet))
  3253.  loop%
  3254. expSortAttackValues(theirPlanets%())
  3255. expDecideAttacks(ourPlanets%(), theirPlanets%(), central%)
  3256. expSortAttackValues(
  3257.  theirPlanets%())
  3258.  loop%, loop2%, max%, number%
  3259. A#number% = 
  3260. (theirPlanets%(), 1)
  3261.  number% > 1 
  3262.  loop% = 1 
  3263.  number% - 1
  3264. D$  max% = theirPlanets%(loop%, 1)
  3265.  loop2% = loop% + 1 
  3266.  number%
  3267. G+    
  3268.  theirPlanets%(loop2%, 1) > max% 
  3269. H>      
  3270.  theirPlanets%(loop2%, 0), theirPlanets%(loop%, 0)
  3271. I>      
  3272.  theirPlanets%(loop2%, 1), theirPlanets%(loop%, 1)
  3273. J(      max% = theirPlanets%(loop%, 1)
  3274. K        
  3275.  loop2%
  3276.  loop%
  3277. expDecideAttacks(
  3278.  ourPlanets%(), theirPlanets%(), our%)
  3279.  freeShips%, loop%, requiredShips%, ourPlanet%, planet%
  3280. T-ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3281. U5freeShips% = ourPlanets%(our%, ExpShipsAvailable)
  3282. loop% = 1
  3283.  (freeShips% > 0) 
  3284.  (loop% <= 
  3285. (theirPlanets%(), 1)) 
  3286.  (theirPlanets%(loop%, 1) <> -1)
  3287. Y'  planet% = theirPlanets%(loop%, 0)
  3288. Z\  requiredShips% = 
  3289. calculateTransferShipsBuildUp2(planet%, ourPlanet%): 
  3290.  changed our%)
  3291.  (freeShips% >= requiredShips%) 
  3292.  (requiredShips% <> -1) 
  3293. \=    
  3294. moveShipsFromTo(requiredShips%, ourPlanet%, planet%)
  3295. ]$    freeShips% -= requiredShips%
  3296.   loop% += 1
  3297. b5ourPlanets%(our%, ExpShipsAvailable) = freeShips%
  3298. expAttackValue(planet%, centralPlanet%)
  3299.  This returns a value that signifies its take over value.
  3300.  This is based on the number of ships relative to number of resources
  3301.  Should also take into account distance, but not yet
  3302.  ships%, timeMultiplier
  3303. kMships%         = 
  3304. calculateTransferShipsBuildUp2(planet%, centralPlanet%)
  3305. lLtimeMultiplier = MaxJourneyTime% / 
  3306. journeyTime(planet%, centralPlanet%)
  3307.  ships% = -1 
  3308.  = -1
  3309.  ships% = 0 
  3310. p6  =(PlanetResources(planet%) ^ 2) * timeMultiplier
  3311. rB  =((PlanetResources(planet%) ^ 2 ) / ships%) * timeMultiplier
  3312. expCentralPlanet(ourPlanets%())
  3313.  This returns the central for this side. If it has been
  3314.  taken over, or will be taken over this turn, then it is changed
  3315.  to the planet with the highest availableShips
  3316.  side%, central%, loop%, maxPlanet%, maxShips%
  3317. z@central% = 
  3318. expGetCentralPlanet(CurrentSide%, ourPlanets%())
  3319.  central% = -1 
  3320.  We have to find a new planet
  3321. }(  maxPlanet% = -1: maxShips% = -9999
  3322.  loop% = 1 
  3323. (ourPlanets%(), 1)
  3324. =    
  3325.  ourPlanets%(loop%, ExpShipsAvailable) > maxShips% 
  3326. O      maxPlanet% = loop%: maxShips% = ourPlanets%(loop%, ExpShipsAvailable)
  3327.         
  3328.  loop%
  3329. M  !(ComputerBlockPtr%(CurrentSide%)) = ourPlanets%(maxPlanet%, ExpPlanet)
  3330.   = maxPlanet%
  3331.   = central%
  3332. expGetCentralPlanet(side%, ourPlanets%())
  3333.  Returns the ourPlanets%() index of centralPlanet.
  3334.  Returns -1 if it is not our planet anymore, or it will
  3335.  be taken over most probably this turn
  3336.  centralPlanet%, loop%
  3337. 0centralPlanet% = !(ComputerBlockPtr%(side%))
  3338.  loop% = 1 
  3339. (ourPlanets%(), 1)
  3340.  ourPlanets%(loop%, ExpPlanet) = centralPlanet% 
  3341. B    
  3342.  ourPlanets%(loop%, ExpShipsRequired) <> 0 
  3343.  =-1 
  3344.  =loop%
  3345.  loop%
  3346. *************************************************************************************
  3347. ************************************************************************ Super Player
  3348. *************************************************************************************
  3349. cmoveSp(computerSide%)
  3350.  This is another computer player
  3351.  Hopefully better than the previous "Expert Player"
  3352.  ourPlanets%(), totalPlanets%
  3353.  attackFrom%, attackPlanet%
  3354. 4totalPlanets% = SideTotalPlanets%(computerSide%)
  3355. >ExpPlanet = 0: ExpShipsRequired = 1: ExpShipsAvailable = 2
  3356.  ourPlanets%(totalPlanets%, 2)
  3357. spGetPlanetsData(computerSide%, ourPlanets%())
  3358. spGetAttackPlanet(computerSide%, ourPlanets%(), attackFrom%, attackPlanet%)
  3359. spDefensiveMoves(ourPlanets%(), attackFrom%, attackPlanet%)
  3360. spAttackMove(computerSide%, ourPlanets%(), attackFrom%, attackPlanet%)
  3361. ------------------------------------------------------------------- Get Attack Planet
  3362. spWriteAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
  3363.  This stores the information so it can be used in future turns.
  3364.  Only used by THIS computer "super player"
  3365. 7!(ComputerBlockPtr%(side%))     = attackFromPlanet%
  3366. 3!(ComputerBlockPtr%(side%) + 4) = attackPlanet%
  3367. 0!(ComputerBlockPtr%(side%) + 8) = startTurn%
  3368. spClearAttackDetails(side%)
  3369.  This changes,and storesm the stored variables to "undefined" values
  3370. spWriteAttackDetails(side%, -1, -1, -1)
  3371. spReadAttackDetails(side%, 
  3372.  attackFromPlanet%, 
  3373.  attackPlanet%, 
  3374.  startTurn%)
  3375.  This reads the stored information
  3376. 3attackFromPlanet% = !(ComputerBlockPtr%(side%))
  3377. 7attackPlanet%     = !(ComputerBlockPtr%(side%) + 4)
  3378. 7startTurn%        = !(ComputerBlockPtr%(side%) + 8)
  3379. spGiveUpAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
  3380.  This checks to see whether it is worth continuing against this target
  3381.  changeAttack%
  3382. changeAttack% = 
  3383. spTimeOutAttack(startTurn%) 
  3384. spAttackFromChangeOwnership(side%, attackFromPlanet%) 
  3385.  (attackFromPlanet% = -1)
  3386. = changeAttack%
  3387. spTimeOutAttack(startTurn%)
  3388.  Gives up an attackPlanet if we have spent too long building up for it
  3389.  (CurrentTurn% - startTurn%) > 3 
  3390. spAttackFromChangeOwnership(side%, attackFromPlanet%)
  3391.  If the starting planet is not ours any more, then we
  3392.  can't build up from there
  3393.  attackFromPlanet% <> -1 
  3394.  PlanetSide(attackFromPlanet%) <> side% 
  3395. spGetAttackPlanet(side%, ourPlanets%(), 
  3396.  attackFrom%, 
  3397.  attackPlanet%)
  3398.  This aims to find a planet to attack, and a planet to
  3399.  build up the attack force from.
  3400.  attackFromPlanet%, startTurn%    :
  3401.  Integer
  3402.  changeAttack%                    :
  3403.  Boolean
  3404. spReadAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
  3405. _changeAttack% = 
  3406. spGiveUpAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
  3407.  changeAttack% 
  3408. spGetNewAttackPlanet(side%, ourPlanets%(), attackFromPlanet%, attackPlanet%)
  3409. 6attackFrom% = 
  3410. spAllToMyPlanets(attackFromPlanet%)
  3411. diagnosis("Attack Planet:      " + PlanetName$(attackPlanet%))
  3412. diagnosis("Attack from Planet: " + PlanetName$(attackFromPlanet%))
  3413. spGetNewAttackPlanet(side%, ourPlanets%(), 
  3414.  attackFromPlanet%, 
  3415.  attackPlanet%)
  3416.  This finds a new set of attackFromPlanet, attackPlanet.
  3417.  Updates stored details
  3418.  checkPlanets%(), planets%
  3419.  checkPlanets%(NumberPlanets%, 1)
  3420. spGetAttackPlanetsList(side%, checkPlanets%(), planets%)
  3421. spChooseAttackPlanet(checkPlanets%(), planets%, attackFromPlanet%, attackPlanet%)
  3422. spWriteAttackDetails(side%, attackFromPlanet%, attackPlanet%, CurrentTurn%)
  3423. spGetAttackPlanetsList(side%, 
  3424.  checkPlanets%(), 
  3425.  planets%)
  3426.  This creates a list of possible pairs = (attackFrom%, attackPlanet%)
  3427.  Unordered at present
  3428.  attackDistance%, attackFrom%, attackFromPlanet%, attackPlanet%
  3429.  loop%, found%
  3430.  planets% = 0
  3431.   attackDistance% += 1
  3432.  attackFrom% = 1 
  3433. (ourPlanets%(), 1)
  3434. ?    attackFromPlanet% = ourPlanets%(attackFrom%, ExpPlanet)
  3435. ,    
  3436.  attackPlanet% = 1 
  3437.  NumberPlanets%
  3438. w      
  3439.  (PlanetSide(attackPlanet%) <> side%) 
  3440. journeyTime(attackFromPlanet%, attackPlanet%) = attackDistance%) 
  3441.         :
  3442. !        loop% = 1: found% = 
  3443. -        
  3444.  (loop% <= planets%) 
  3445.  found%
  3446. 9          
  3447.  checkPlanets%(loop%, 1) = attackPlanet% 
  3448. y            
  3449.  ourPlanets%(attackFrom%, ExpShipsAvailable) > ourPlanets%(checkPlanets%(loop%, 0), ExpShipsAvailable) 
  3450. 7              checkPlanets%(loop%, 0) = attackFrom%
  3451.             
  3452.             found% = 
  3453.           
  3454.             loop% += 1
  3455.           
  3456.         
  3457.         
  3458.  found% 
  3459.           planets% += 1
  3460. 6          checkPlanets%(planets%, 0) = attackFrom%
  3461. 8          checkPlanets%(planets%, 1) = attackPlanet%
  3462.         
  3463.       
  3464.  attackPlanet%
  3465.  attackFrom%
  3466. spChooseAttackPlanet(checkPlanets%(), planets%, 
  3467.  attackFromPlanet%, 
  3468.  attackPlanet%)
  3469.  This chooses one pair of (attackFrom%, attackPlanet%) from the list
  3470.  of possible ones
  3471.  availShips%, newAvailShips%, loop%
  3472.  planets% > 1 
  3473.  Find planet with largest ships which we can take with AvailableShips
  3474. -k  availShips% = ourPlanets%(checkPlanets%(1, 0), ExpShipsAvailable) - PlanetShips%(checkPlanets%(1, 1))
  3475.  loop% = 2 
  3476.  planets%
  3477. /x    newAvailShips% = ourPlanets%(checkPlanets%(loop%, 0), ExpShipsAvailable) - PlanetShips%(checkPlanets%(loop%, 1))
  3478. 0(    
  3479.  newAvailShips% > availShips% 
  3480. 19      
  3481.  checkPlanets%(1, 0), checkPlanets%(loop%, 0)
  3482. 29      
  3483.  checkPlanets%(1, 1), checkPlanets%(loop%, 1)
  3484. 3&      availShips% = newAvailShips%
  3485. 4        
  3486.  loop%
  3487. 8CattackFromPlanet% = ourPlanets%(checkPlanets%(1, 0), ExpPlanet)
  3488. 97attackPlanet%     =             checkPlanets%(1, 1)
  3489. spAllToMyPlanets(planet%)
  3490.  This converts a plant id from Planets(planet%) to ourPlanets%()
  3491.  loop%
  3492.   loop% += 1
  3493.  ourPlanets%(loop%, ExpPlanet) = planet% 
  3494.  =loop%
  3495. ------------------------------------------------------------------ Get Planet Details
  3496. spGetPlanetsData(side%, 
  3497.  ourPlanets%())
  3498.  This fills ourPlanets%() with the necessary information for later
  3499.  stages of the 'Experts' turn
  3500. spGetOurPlanets(side%, ourPlanets%())
  3501. spAvailableShips(ourPlanets%())
  3502. spRequiredShips(ourPlanets%())
  3503. spGetOurPlanets(side%, 
  3504.  ourPlanets%())
  3505.  This stores all the planets owned by the Super Player in ourPlanets%()
  3506.  planet%, ourPlanet%
  3507.  planet% = 1 
  3508.  NumberPlanets%
  3509.  PlanetSide(planet%) = side% 
  3510.     ourPlanet% += 1
  3511. Y4    ourPlanets%(ourPlanet%, ExpPlanet) = planet%
  3512.  planet%
  3513. spAvailableShips(
  3514.  ourPlanets%())
  3515.  This records for each of our planets, the difference between the
  3516.  number of ships there and the number of ships that we would like
  3517.  to be there, to help prevent against new attacks.
  3518.  our%, ourPlanet%, requiredShips%
  3519.  our% = 1 
  3520. (ourPlanets%(), 1)
  3521. f/  ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3522. g<  requiredShips% = 
  3523. spRequiredDeterrentShips(ourPlanet%)
  3524. hV  ourPlanets%(our%, ExpShipsAvailable) = PlanetShips%(ourPlanet%) - requiredShips%
  3525.  our%
  3526. spRequiredDeterrentShips(planet%)
  3527.  Result is the number of ships required to deter an average
  3528.  attack against the planet
  3529. max(PlanetShips%(PlanetSortedOnShips%(NumberPlanets% / 4)) + 1, PlanetResources(planet%) * 0.6)
  3530. spRequiredTotalDefensiveShips(planet%)
  3531.  Answer is the number of ships that are needed to adequately defend
  3532.  against an actual attack on planet%
  3533.  order%, ships%
  3534.  order% = 1 
  3535.  NumberMovementOrders%
  3536. z7  ships% += 
  3537. spRequiredShipsOrders(order%, planet%)
  3538.  order%
  3539. = ships% * 1.3
  3540. spRequiredDefensiveShips(our%, requiredShips%, 
  3541.  ourPlanets%())
  3542.  This sets the number of extra ships a planet needs to successfully
  3543.  defend an attack.
  3544.  ourPlanet%, fiddleAvailable%
  3545. -ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3546.  requiredShips% >= 0 
  3547. .  ourPlanets%(our%, ExpShipsAvailable) = 0
  3548. T  fiddleAvailable% = 
  3549. min(-requiredShips%, ourPlanets%(our%, ExpShipsAvailable))
  3550. m  ourPlanets%(our%, ExpShipsAvailable) = 
  3551. max(0, ourPlanets%(our%, ExpShipsAvailable) - fiddleAvailable%)
  3552.   requiredShips% = 0
  3553. =requiredShips%
  3554. spRequiredShips(
  3555.  ourPlanets%())
  3556.  This records for each of our planets, the number of extra ships
  3557.  that are required to defend successfully against known attacks
  3558.  arriving next turn
  3559.  our%, ourPlanet%, requiredShips%
  3560.  our% = 1 
  3561. (ourPlanets%(), 1)
  3562. /  ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3563. A  requiredShips% = 
  3564. spRequiredTotalDefensiveShips(ourPlanet%)
  3565.  requiredShips% > 0 
  3566. g    requiredShips% = requiredShips% - PlanetShips%(ourPlanet%) - 
  3567. spOurShipsArrivingNow(ourPlanet%)
  3568. W    requiredShips% = 
  3569. spRequiredDefensiveShips(our%, requiredShips%, ourPlanets%())
  3570. ;  ourPlanets%(our%, ExpShipsRequired)  = requiredShips%
  3571.  our%
  3572. spOurShipsArrivingNow(planet%)
  3573.  This is the amount of ships that are arriving this coming
  3574.  turn at ourPlanet%, that are on our side
  3575.  order%, ships%
  3576.  order% = 1 
  3577.  NumberMovementOrders%
  3578.  MovementOrders%(order%, OrderPlanet) = planet% 
  3579. D    
  3580.  MovementOrders%(order%, OrderSide) = PlanetSide(planet%) 
  3581. G      
  3582.  MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1 
  3583. 9        ships% += MovementOrders%(order%, OrderShips)
  3584.       
  3585.         
  3586.  order%
  3587. =ships%
  3588. spRequiredShipsOrders(order%, planet%)
  3589.  IF the ships of this order are to attack this planet, next turn, then
  3590.  the number of ships necessary to defend the planet well is returned
  3591.  MovementOrders%(order%, OrderPlanet) = planet% 
  3592.  MovementOrders%(order%, OrderSide) <> PlanetSide(planet%) 
  3593. E    
  3594.  MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1 
  3595. /      = MovementOrders%(order%, OrderShips)
  3596.         
  3597. --------------------------------------------------------------------- Defensive Moves
  3598. spDefensiveMoves(
  3599.  ourPlanets%(), attackFrom%, attackPlanet%)
  3600.  This attempts to ensure that any planets under attack can be either
  3601.  sent enough ships to withstand the attack, or retreat if need be
  3602. spFindOppositionAttacks(ourPlanets%())
  3603. spFindOurWeakPlanets(ourPlanets%())
  3604. spMoveExcessShips(ourPlanets%(), attackFrom%)
  3605. spFindOppositionAttacks(
  3606.  ourPlanets%())
  3607.  Examines all our planets looking for ones that are being attacked
  3608.  and need assistance. Attempt to send assistance
  3609.  our%, numberOurPlanets%
  3610. +numberOurPlanets% = 
  3611. (ourPlanets%(), 1)
  3612.  our% = 1 
  3613.  numberOurPlanets%
  3614.  ourPlanets%(our%, ExpShipsRequired) > 0 
  3615. diagnosis(PlanetName$(ourPlanets%(our%, ExpPlanet))+ " needs "+
  3616. (ourPlanets%(our%, ExpShipsRequired))+" reinforcements to withstand attack")
  3617. 1    
  3618. spGetReinforcements(our%, ourPlanets%())
  3619.  our%
  3620. spFindOurWeakPlanets(
  3621.  ourPlanets%())
  3622.  This finds all our planets that could be targets because of their
  3623.  low number of ships in defence and boost it to appropriate levels
  3624.  our%, ourPlanet%, numberOurPlanets%
  3625. +numberOurPlanets% = 
  3626. (ourPlanets%(), 1)
  3627.  our% = 1 
  3628.  numberOurPlanets%
  3629.  ourPlanets%(our%, ExpShipsAvailable) < 0 
  3630. 1    ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3631. diagnosis(PlanetName$(ourPlanet%)+" needs "+
  3632. (-ourPlanets%(our%, ExpShipsAvailable))+" extra ships to dissuade future attacks")
  3633. )    
  3634. spGetBackup(our%, ourPlanets%())
  3635.  our%
  3636. spMoveExcessShips(
  3637.  ourPlanets%(), attackFrom%)
  3638.  This moves any available ships to attackFromPlanet% so they can be
  3639.  used in the next offensive
  3640.  our%, ourPlanet%, numberOurPlanets%, attackFromPlanet%
  3641. +numberOurPlanets% = 
  3642. (ourPlanets%(), 1)
  3643. ;attackFromPlanet% = ourPlanets%(attackFrom%, ExpPlanet)
  3644.  our% = 1 
  3645.  numberOurPlanets%
  3646.  (ourPlanets%(our%, ExpShipsAvailable) > 0) 
  3647.  (attackFrom% <> our%) 
  3648. 1    ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3649. ]    
  3650. moveShipsFromTo(ourPlanets%(our%, ExpShipsAvailable), ourPlanet%, attackFromPlanet%)
  3651. k    
  3652. PROCdiagnosis("Excess troops from "+PlanetName$(ourPlanet%)+" to "+PlanetName$(attackFromPlanet%))
  3653.  our%
  3654. spGetReinforcements(attacked%, 
  3655.  ourPlanets%())
  3656.  This attempts to get reinforcements from our surrounding planets,
  3657.  that will ensure we have enough ships to defeat an attack.
  3658.  attackedPlanet%, numberOurPlanets%, our%
  3659.  takeShips%()
  3660.  totalShips%, requiredShips%, takeShipsFraction, takenShips%, totalTakenShips%
  3661. 9attackedPlanet%   = ourPlanets%(attacked%, ExpPlanet)
  3662. +numberOurPlanets% = 
  3663. (ourPlanets%(), 1)
  3664.  takeShips%(numberOurPlanets%)
  3665. spSupplyAvailableShips(attackedPlanet%, ourPlanets%(), takeShips%())
  3666. @requiredShips%    = ourPlanets%(attacked%, ExpShipsRequired)
  3667. 'totalShips%       = 
  3668.  takeShips%()
  3669.  totalShips% >= requiredShips% 
  3670. 6  takeShipsFraction = requiredShips% / totalShips%
  3671.  our% = 1 
  3672.  numberOurPlanets%
  3673. B    takenShips% = 
  3674. round(takeShips%(our%) * takeShipsFraction)
  3675. '    totalTakenShips% += takenShips%
  3676.  takenShips% > 0 
  3677. =      ourPlanets%(our%, ExpShipsAvailable) -= takenShips%
  3678. V      
  3679. moveShipsFromTo(takenShips%, ourPlanets%(our%, ExpPlanet), attackedPlanet%)
  3680.         
  3681.  our%
  3682. diagnosis("Here comes the cavalry with "+
  3683. (totalTakenShips%))
  3684.  Planet can't be saved. Escape
  3685. diagnosis(PlanetName$(attackedPlanet%)+" can't be saved. Escape, Escape!!")
  3686. O  ourPlanets%(attacked%, ExpShipsAvailable) = PlanetShips%(attackedPlanet%)
  3687. !1ourPlanets%(attacked%, ExpShipsRequired)  = 0
  3688. spSupplyAvailableShips(destinationPlanet%, ourPlanets%(), 
  3689.  takeShips%())
  3690.  This sees how many available ships are within 1 distance of the
  3691.  planet
  3692.  our%, ourPlanet%, numberOurPlanets%
  3693. *+numberOurPlanets% = 
  3694. (ourPlanets%(), 1)
  3695.  our% = 1 
  3696.  numberOurPlanets%
  3697. ,/  ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3698.  ourPlanet% <> destinationPlanet% 
  3699. .k    
  3700. journeyTime(destinationPlanet%, ourPlanet%) = 1) 
  3701.  (ourPlanets%(our%, ExpShipsAvailable) > 0) 
  3702. /A      takeShips%(our%) = ourPlanets%(our%, ExpShipsAvailable)
  3703. 0        
  3704.  our%
  3705. spGetBackup(defend%, 
  3706.  ourPlanets%())
  3707.  this attempts to get available ships from nearby planets to
  3708.  stop the planet looking such an easy target
  3709.  defendPlanet%, requiredShips%, numberOurPlanets%, takeShips%()
  3710.  totalShips%, takeShipsFraction, our%, ourPlanet%, takenShips%, totalTakenShips%
  3711. <5defendPlanet%  =  ourPlanets%(defend%, ExpPlanet)
  3712. ==requiredShips% = -ourPlanets%(defend%, ExpShipsAvailable)
  3713. >+numberOurPlanets% = 
  3714. (ourPlanets%(), 1)
  3715.  takeShips%(numberOurPlanets%)
  3716. spSupplyAvailableShips(defendPlanet%, ourPlanets%(), takeShips%())
  3717. C!totalShips% = 
  3718.  takeShips%()
  3719.  totalShips% = 0 
  3720. diagnosis("No ships available to backup "+PlanetName$(defendPlanet%))
  3721. G?  takeShipsFraction = 
  3722. min(requiredShips% / totalShips%, 1)
  3723.  our% = 1 
  3724.  numberOurPlanets%
  3725. I1    ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3726. JB    
  3727.  (ourPlanet% <> defendPlanet%) 
  3728.  (takeShips%(our%) > 0) 
  3729. KM      takenShips% = 
  3730. round(takeShips%(our%) * takeShipsFraction), 1)
  3731. L)      totalTakenShips% += takenShips%
  3732.       :
  3733. N=      ourPlanets%(our%, ExpShipsAvailable) -= takenShips%
  3734. OB      
  3735. moveShipsFromTo(takenShips%, ourPlanet%, defendPlanet%)
  3736. P        
  3737.  our%
  3738. diagnosis(
  3739. min(totalShips%, requiredShips%))+" ships can help backup "+PlanetName$(defendPlanet%))
  3740. V9ourPlanets%(defend%, ExpShipsRequired) += totalShips%
  3741. --------------------------------------------------------------------- Attacking Moves
  3742. spAttackMove(side%, 
  3743.  ourPlanets%(), attackFrom%, attackPlanet%)
  3744.  requiredShips%, freeShips%, attackFromPlanet%
  3745. ^;attackFromPlanet% = ourPlanets%(attackFrom%, ExpPlanet)
  3746. _SrequiredShips%    = 
  3747. calculateTransferShipsSp(attackPlanet%, attackFromPlanet%)
  3748. `CfreeShips%        = ourPlanets%(attackFrom%, ExpShipsAvailable)
  3749.  (freeShips% >= requiredShips%) 
  3750.  (requiredShips% <> -1) 
  3751. moveShipsFromTo(freeShips%, attackFromPlanet%, attackPlanet%)
  3752. diagnosis("Sent ships to battle: "+ 
  3753. (freeShips%))
  3754. spClearAttackDetails(side%)
  3755. diagnosis("Not enough troops yet... Have: "+
  3756. (freeShips%)+", need "+
  3757. (requiredShips%))
  3758. spAttackingMoves(
  3759.  ourPlanets%(), attackFromPlanet%, attackPlanet%)
  3760.  loop%, theirPlanet%
  3761.  theirPlanets%()
  3762.  theirPlanets%( NumberPlanets% - 
  3763. (ourPlanets%(), 1), 1 )
  3764.  loop% = 1 
  3765.  NumberPlanets%
  3766.  PlanetSide(loop%) <> CurrentSide% 
  3767.     theirPlanet% += 1
  3768. u.    theirPlanets%(theirPlanet%, 0) = loop%
  3769. vg    theirPlanets%(theirPlanet%, 1) = 
  3770. spAttackValue(theirPlanet%, ourPlanets%(central%, ExpPlanet))
  3771.  loop%
  3772. spSortAttackValues(theirPlanets%())
  3773. spDecideAttacks(ourPlanets%(), theirPlanets%(), central%)
  3774. spSortAttackValues(
  3775.  theirPlanets%())
  3776.  loop%, loop2%, max%, number%
  3777. #number% = 
  3778. (theirPlanets%(), 1)
  3779.  number% > 1 
  3780.  loop% = 1 
  3781.  number% - 1
  3782. $  max% = theirPlanets%(loop%, 1)
  3783.  loop2% = loop% + 1 
  3784.  number%
  3785. +    
  3786.  theirPlanets%(loop2%, 1) > max% 
  3787. >      
  3788.  theirPlanets%(loop2%, 0), theirPlanets%(loop%, 0)
  3789. >      
  3790.  theirPlanets%(loop2%, 1), theirPlanets%(loop%, 1)
  3791. (      max% = theirPlanets%(loop%, 1)
  3792.         
  3793.  loop2%
  3794.  loop%
  3795. spDecideAttacks(
  3796.  ourPlanets%(), theirPlanets%(), our%)
  3797.  freeShips%, loop%, requiredShips%, ourPlanet%, planet%
  3798. -ourPlanet% = ourPlanets%(our%, ExpPlanet)
  3799. 5freeShips% = ourPlanets%(our%, ExpShipsAvailable)
  3800. loop% = 1
  3801.  (freeShips% > 0) 
  3802.  (loop% <= 
  3803. (theirPlanets%(), 1)) 
  3804.  (theirPlanets%(loop%, 1) <> -1)
  3805. '  planet% = theirPlanets%(loop%, 0)
  3806. X  requiredShips% = 
  3807. calculateTransferShipsBuildUp2(planet%, ourPlanet%) :
  3808.  was our%)
  3809.  (freeShips% >= requiredShips%) 
  3810.  (requiredShips% <> -1) 
  3811. =    
  3812. moveShipsFromTo(requiredShips%, ourPlanet%, planet%)
  3813. $    freeShips% -= requiredShips%
  3814.   loop% += 1
  3815. 5ourPlanets%(our%, ExpShipsAvailable) = freeShips%
  3816. spAttackValue(planet%, centralPlanet%)
  3817.  This returns a value that signifies its take over value.
  3818.  This is based on the number of ships relative to number of resources
  3819.  Should also take into account distance, but not yet
  3820.  ships%, timeMultiplier
  3821. Mships%         = 
  3822. calculateTransferShipsBuildUp2(planet%, centralPlanet%)
  3823. LtimeMultiplier = MaxJourneyTime% / 
  3824. journeyTime(planet%, centralPlanet%)
  3825.  ships% = -1 
  3826.  = -1
  3827.  ships% = 0 
  3828. 6  =(PlanetResources(planet%) ^ 2) * timeMultiplier
  3829. B  =((PlanetResources(planet%) ^ 2 ) / ships%) * timeMultiplier
  3830. spCentralPlanet(ourPlanets%())
  3831.  This returns the central for this side. If it has been
  3832.  taken over, or will be taken over this turn, then it is changed
  3833.  to the planet with the highest availableShips
  3834.  side%, central%, loop%, maxPlanet%, maxShips%
  3835. ?central% = 
  3836. spGetCentralPlanet(CurrentSide%, ourPlanets%())
  3837.  central% = -1 
  3838.  We have to find a new planet
  3839. (  maxPlanet% = -1: maxShips% = -9999
  3840.  loop% = 1 
  3841. (ourPlanets%(), 1)
  3842. =    
  3843.  ourPlanets%(loop%, ExpShipsAvailable) > maxShips% 
  3844. O      maxPlanet% = loop%: maxShips% = ourPlanets%(loop%, ExpShipsAvailable)
  3845.         
  3846.  loop%
  3847. M  !(ComputerBlockPtr%(CurrentSide%)) = ourPlanets%(maxPlanet%, ExpPlanet)
  3848.   = maxPlanet%
  3849.   = central%
  3850. spGetCentralPlanet(side%, ourPlanets%())
  3851.  Returns the ourPlanets%() index of centralPlanet.
  3852.  Returns -1 if it is not our planet anymore, or it will
  3853.  be taken over most probably this turn
  3854.  centralPlanet%, loop%
  3855. 0centralPlanet% = !(ComputerBlockPtr%(side%))
  3856.  loop% = 1 
  3857. (ourPlanets%(), 1)
  3858.  ourPlanets%(loop%, ExpPlanet) = centralPlanet% 
  3859. B    
  3860.  ourPlanets%(loop%, ExpShipsRequired) <> 0 
  3861.  =-1 
  3862.  =loop%
  3863.  loop%
  3864. calculateTransferShipsSp(attackPlanet%, attackFromPlanet%)
  3865.  This calculates how many ships will have to be sent to planet% to take
  3866.  it over from centralPlanet%
  3867.  This also takes into account the number of ships from other sides
  3868.  heading for the planet
  3869.  order%, side%, transitShips%
  3870. )side% = PlanetSide(attackFromPlanet%)
  3871.  PlanetSide(attackPlanet%) <> side% 
  3872.  order% = 1 
  3873.  NumberMovementOrders%
  3874. 8    
  3875.  (MovementOrders%(order%, 3) = attackPlanet%) 
  3876. 0      
  3877.  MovementOrders%(order%, 0) = side% 
  3878. G        
  3879.  We have already sent ships there. Forget it at this stage
  3880.         = -1
  3881.       
  3882. I        
  3883.  another side is sending ships. Have to send more than them!
  3884. K        transitShips% = 
  3885. max(MovementOrders%(order%, 2), transitShips%)
  3886.       
  3887.         
  3888.  order%
  3889.  There are no troops on the way, therefore calculate a value
  3890. max( PlanetShips%(attackPlanet%) + 
  3891. shipsIncreaseFromResourcesOver(PlanetResources(attackPlanet%), 
  3892. journeyTime(attackFromPlanet%, attackPlanet%)), transitShips%) * 1.3 )
  3893.   = -1
  3894.  > GeneralLib
  3895. ----------------------------------------------------------------------------- String
  3896. stringToLowerCase(upper$)
  3897.  loop%, lower$
  3898. lower$ = ""
  3899.  loop% = 1 
  3900. (upper$)
  3901. ;   lower$ += 
  3902. charToLowerCase(
  3903. upper$, loop%, 1))))
  3904.  loop%
  3905. =lower$
  3906. charToLowerCase(upper%)
  3907.  upper% >= 
  3908. ("A") 
  3909.  upper% <= 
  3910. ("Z") 
  3911. "  = upper% + (
  3912. ("a") - 
  3913. ("A"))
  3914.   = upper%
  3915. read0String(ptr%)
  3916.  string$
  3917.  ?ptr% <> 0
  3918.   string$ += 
  3919. (?ptr%)
  3920.   ptr% += 1
  3921. =string$
  3922. readSysString(ptr%)
  3923.  string$
  3924.  ?ptr% >= 32
  3925.   string$ += 
  3926. (?ptr%)
  3927.   ptr% += 1
  3928. =string$
  3929. -------------------------------------------------------------------------- Numerical
  3930. min(A, B)
  3931.  A <= B 
  3932. max(A, B)
  3933.  A > B 
  3934. round(n)
  3935. (n + 0.5)
  3936.