home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 2
/
DATAFILE_PDCD2.iso
/
games
/
_trynth
/
!Trynth
/
!RunImage
(
.txt
)
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
RISC OS BBC BASIC V Source
|
1993-05-17
|
132.8 KB
|
3,943 lines
> <Trynth$Dir>.!RunImage
Trynth, a Space Strategy Game for the Archimedes
(C) David Jones, 1993
160 Hazelwood Drive
St.Albans
HERTS
AL4 0UZ
%TaskDate$ = "0.20c (18 May 1993)"
TaskCopy$ = "Shareware"
diagnosisPipe% =
MenuFonts% =
TRACE TO "pipe::trace"
TRACE PROC
$; " (Error code ";
); ")":
LIBRARY "<Trynth$Dir>.GeneralLib"
initializeStart
LoadedGame%
initializeGame
initializeMoreWimp
LoadedGame%
changeSides(StartSide%)
LoadedGame%
$MainWindowTitle% = SideNames$(CurrentSide%)
wimpError
Quit%
wimpPoll
wimpCloseDown
*************************************************************************************
wimpPoll
reason%
"Wimp_Poll", %10011111110000000000, WimpBlock%
reason%
reason%
nullReasonCode
redrawWindowRequest
"Wimp_OpenWindow",, WimpBlock%
"Wimp_CloseWindow",, WimpBlock%
pointerLeavingWindow
pointerEnteringWindow
mouseButtonChange
userDragBox
keyPressed
menuSelect
17, 18:
userMessage
nullReasonCode
newPointerOverPlanet%
(PointerOverPlanet% <> -1)
(DragFromWindow% <> -1)
"Wimp_GetPointerInfo",, WimpBlock%
;H newPointerOverPlanet% =
worldAtWindow(WimpBlock%!0, WimpBlock%!4)
PointerOverPlanet% <> newPointerOverPlanet%
=2 PointerOverPlanet% = newPointerOverPlanet%
>6
redrawWindowArea(MainWindow%, 0, -64, 560, 0)
redrawWindowRequest
window%, more%, x0%, y0%
window% = !WimpBlock%
"Wimp_RedrawWindow",, WimpBlock%
more%
getOrigin(x0%, y0%)
more%
x0%, y0%
window%
L9
MainWindow% :
drawMainWindow(x0%, y0%)
M;
OrdersWindow% :
drawOrdersWindow(x0%, y0%)
N?
StatisticsWindow% :
drawStatisticsWindow(x0%, y0%)
O:
GraphWindow% :
drawGraphWindow(x0%, y0%)
PB
SortedPlanetsWindow%:
drawSortedPlanetsWindow(x0%, y0%)
Q:
WorldWindow% :
drawWorldWindow(x0%, y0%)
R<
NewGameWindow% :
drawNewGameWindow(x0%, y0%)
0, 0
"Wimp_GetRectangle",, WimpBlock%
more%
pointerLeavingWindow
window%
window% = WimpBlock%!0
window% = MainWindow%
PointerOverPlanet% = -1
pointerEnteringWindow
window%
window% = WimpBlock%!0
window% = MainWindow%
"Wimp_GetPointerInfo",, WimpBlock%
kE PointerOverPlanet% =
worldAtWindow(WimpBlock%!0, WimpBlock%!4)
redrawWindowArea(MainWindow%, 0, -64, 560, 0)
mouseButtonChange
x%, y%, buttonState%, icon%
t5x% = WimpBlock%!0: y% = WimpBlock%!4
u6buttonState% = WimpBlock%!8: icon% = WimpBlock%!16
WimpBlock%!12
IconBarWindow%
buttonState%
z8
MenuClick :
openIconBarMenu(IconMenu%, x%)
{1
SelectClick:
openWindow(MainWindow%)
|
SaveWindow%
icon%
C
dataSaveAck(
readIndirectedBuffer(SaveWindowText%))
'
dragBox(SaveWindow%, 3)
/ DragFromWindow% = SaveWindow%
MainWindow%
buttonState%
3
MenuClick:
openMenu(MainMenu%, x%, y%)
SelectClick
6
updateWorldWindow(
worldAtWindow(x%, y%))
%
openWindow(WorldWindow%)
" PointerOverPlanet% = 0
WorldWindow%
K
Shading the appropriate icons in updateWorldWindow() stops people
%
changing other sides values
icon%
!
14:
Left ship arrow
F
buttonState% = SelectClick
updateWorldWindowShips( 1)
F
buttonState% = AdjustClick
updateWorldWindowShips(-1)
"
15:
Right ship arrow
F
buttonState% = SelectClick
updateWorldWindowShips(-1)
F
buttonState% = AdjustClick
updateWorldWindowShips( 1)
-
16:
buttonState% = SelectDrag
/
dragBox(WorldWindow%, 16)
3 DragFromWindow% = WorldWindow%
12:
All left
)
updateWorldWindowShips( 1E8)
17:
All right
)
updateWorldWindowShips(-1E8)
GraphWindow%
buttonState%
6
MenuClick :
openMenu(GraphMenu%, x%, y%)
StatisticsWindow%
buttonState%
;
MenuClick :
openMenu(StatisticsMenu%, x%, y%)
SortedPlanetsWindow%
buttonState%
:
SelectClick:
clickSortedPlanetsWindow(x%, y%)
OrdersWindow%
buttonState%
3
SelectClick:
clickOrdersWindow(x%, y%)
SideWindow%
buttonState%
;
MenuClick :
openMenu(SideWindowMenu%, x%, y%)
WinnerWindow%
icon%
Ok, finish
wimpCloseDown
Continue
% WinnerContinue% =
-
closeWindow(WinnerWindow%)
userDragBox
destinationWorld%, orderShips%
DragFromWindow%
WorldWindow%:
move ships
getPointerInfo
'
WimpBlock%!12 = MainWindow%
H destinationWorld% =
worldAtWindow(WimpBlock%!0, WimpBlock%!4)
0
destinationWorld% <> CurrentWorld%
J orderShips% =
readIndirectedBuffer(WorldWindowShipsDrag%))
orderShips% > 0
M
moveShipsFromTo(orderShips%, CurrentWorld%, destinationWorld%)
/
updateWorldWindow(CurrentWorld%)
SaveWindow%
dataSave
DragFromWindow% = -1
keyPressed
acceptKey%, character%, icon%
4icon% = WimpBlock%!4: character% = WimpBlock%!24
acceptKey% =
WimpBlock%!0
WorldWindow%
icon%
Planet name
character% = 13
R PlanetName$(CurrentWorld%) =
readIndirectedBuffer(WorldWindowName%)
removeCaret
D
redrawWindowArea(OrdersWindow%, 0, -9000, 1000, -124)
J
redrawWindowArea(SortedPlanetsWindow%, 0, -9000, 1000, -64)
acceptKey% =
#
13:
character% = 13
removeCaret
X
updateWorldWindowPlanetShips(
readIndirectedBuffer(WorldWindowShips%)))
acceptKey% =
: acceptKey% =
BattleWindow%
+
(icon% = 1)
(character% = 13)
P PlanetName$(BattleWorld%) =
readIndirectedBuffer(BattleWindowPlanet%)
removeCaret
@
redrawWindowArea(OrdersWindow%, 0, -9000, 1000, -124)
F
redrawWindowArea(SortedPlanetsWindow%, 0, -9000, 1000, -64)
acceptKey% =
SaveWindow%
character% = 13
>
dataSaveAck(
readIndirectedBuffer(SaveWindowText%))
acceptKey% =
: acceptKey% =
acceptKey%
"Wimp_ProcessKey", character%
menuSelect
menu1%
menu1% = WimpBlock%!0
CurrentMenu%
IconMenu%
menu1%
2: Quit% =
MainMenu%
menu1%
nextSide
nextTurn
!-
openWindow(StatisticsWindow%)
")
openWindow(OrdersWindow%)
#
GraphMenu%
menu1%
'A
0, 1, 2:
toggleTick(CurrentGraphChoice%, GraphMenu%)
(+
toggleTick(menu1%, GraphMenu%)
)( CurrentGraphChoice% = menu1%
*'
redrawWindow(GraphWindow%)
+
StatisticsMenu%
menu1%
/(
openWindow(GraphWindow%)
00
openWindow(SortedPlanetsWindow%)
1'
openWindow(SideWindow%)
2
SideWindowMenu%
menu1% >= 0
6(
updateSideWindow(menu1% - 1)
7#
openWindow(SideWindow%)
reopenCurrentMenu
userMessage
WimpBlock%!16
0 : Quit% =
2 :
dataSaveAck(
read0String(WimpBlock% + 44))
3 :
dataLoad
10 :
bootOptions
&502:
helpMessage
bootOptions
Save details to load this app in this set
file%, dir$, length%
file% = WimpBlock%!20
"OS_GSTrans", "<Trynth$Dir>", WimpBlock% + 200, 256
,, length%
O&?(WimpBlock% + length% + 200) = 13
dir$ = $(WimpBlock% + 200)
#file%, "Run " + dir$
*************************************************************************************
************************************************************************ User Windows
*************************************************************************************
------------------------------------------------------------------------- Main Window
drawMainWindow(x0%, y0%)
loop%, x%, y%
(WimpBlock%!40 - y0% >= -64)
(PointerOverPlanet% > 0)
10, -4:
sideColours( PlanetSide(PointerOverPlanet%))
^A
SideNames$(PlanetSide(PointerOverPlanet%))
colourBlack
10, -36:
(PlanetShips%(PointerOverPlanet%))
106, -36
PointerOverPlanet% = CurrentWorld%
"--"
eI
journeyTime(CurrentWorld%, PointerOverPlanet%))
170, -36:
PlanetName$(PointerOverPlanet%)
((WimpBlock%!32 - y0% >= -64)
(WimpBlock%!36 - x0% < 600))
loop% = 1
NumberPlanets%
l)
sideColours( PlanetSide(loop%) )
m&
planetPosition(loop%, x%, y%)
n$
planetToWindowTrans(x%, y%)
x%, y%, 20
loop%
planetToWindowTrans(
x%,
x% = x% * 10: y% = y% * -10
windowToPlanetTrans(
x%,
x% = x% / 10: y% = y% / 10
sideColoursNumber(side%)
Returns the relevant Wimp colour number
side% = 0
side% <= 8
=side% + 7
=side% - 7
sideColours(side%)
"Wimp_SetColour",
sideColoursNumber(side%)
colourBlack
"Wimp_SetColour", 7
colourBackground
"Wimp_SetColour", 1
planetPosition(planet%,
x%,
Dx% = PlanetPosition(planet%, 0): y% = PlanetPosition(planet%, 1)
worldAtWindow(x%, y%)
Returns the value of the planet at (x%, y%) on the MainWindow%
loop%, x0%, y0%, closestPlanet%, closestDistance%
getWindowState(MainWindow%)
getOrigin(x0%, y0%)
x% = x% - x0%: y% = y0% - y%
windowToPlanetTrans(x%, y%)
closestDistance% = 10000
loop% = 1
NumberPlanets%
closestPlanetFromPosition(x%, y%, loop%, closestPlanet%, closestDistance%)
loop%
= closestPlanet%
closestPlanetFromPosition(x%, y%, currentPlanet%,
closestPlanet%,
closestDistance%)
distance%
ndistance% =
distanceBetween(PlanetPosition(currentPlanet%, 0), x%, PlanetPosition(currentPlanet%, 1), y%)
distance% < closestDistance%
% closestPlanet% = currentPlanet%
" closestDistance% = distance%
distanceBetweenPlanets(planet1%, planet2%)
distanceBetween( PlanetPosition(planet1%, 0), PlanetPosition(planet2%, 0), PlanetPosition(planet1%, 1), PlanetPosition(planet2%, 1) )
distanceBetween(x0%, x1%, y0%, y1%)
( ((x0% - x1%) ^2) + ((y0% - y1%) ^2) )
redrawPlanet(planet%)
x%, y%
planetPosition(planet%, x%, y%)
planetToWindowTrans(x%, y%)
redrawWindowArea(MainWindow%, x% - 25, y% - 25, x% + 25, y% + 25)
----------------------------------------------------------------------- Orders Window
drawOrdersWindow(x0%, y0%)
loop%, y%, redrawStartY%, redrawEndY%
WimpBlock%!40 - y0% > -120
10, -8:
messageLookupString("CTurn");" "; CurrentTurn%
10, -64:
messageLookupString("Side")
298, -64:
messageLookupString("ArrTurn")
474, -64:
messageLookupString("Ships")
650, -64:
messageLookupString("Planet")
10, -96:
"---------------- --------- --------- ----------------"
=redrawStartY% =
max((WimpBlock%!40 + 96 - y0%) / -32, 1)
QredrawEndY% =
min((WimpBlock%!32 + 96 - y0%) / -32, NumberMovementOrders%)
redrawStartY% <= redrawEndY%
loop% = redrawStartY%
redrawEndY%
y% = (-32 * loop%) - 96
*
MovementOrders%(loop%, 0) <> 0
1
sideColours(MovementOrders%(loop%, 0))
<
10, y%:
SideNames$(MovementOrders%(loop%, 0))
colourBlack
0
282, y%:
MovementOrders%(loop%, 1)
0
458, y%:
MovementOrders%(loop%, 2)
=
650, y%:
PlanetName$(MovementOrders%(loop%, 3))
N
10,y%:
"................ ......... ......... ................"
loop%
clickOrdersWindow(x%, y%)
If the user clicks over a planet name, then that planet is shown
in the World Window
x0%, y0%, selectedLine%
getWindowState(OrdersWindow%)
getOrigin(x0%, y0%)
x% = x% - x0%: y% = y0% - y%
"selectedLine% = (y% - 96) / 32
selectedLine% >= 1
MovementOrders%(selectedLine%, 0) > 0
?
updateWorldWindow( MovementOrders%(selectedLine%, 3) )
!
openWindow(WorldWindow%)
--------------------------------------------------------------- Sorted Planets Window
drawSortedPlanetsWindow(x0%, y0%)
loop%, y%, sortedPlanet%, redrawStartY%, redrawEndY%
WimpBlock%!40 - y0% > -64
10, -8:
messageLookupString("Side")
298, -8:
messageLookupString("Ships")
474, -8:
messageLookupString("Planet")
10, -40:
"---------------- --------- ----------------"
=redrawStartY% =
max((WimpBlock%!40 + 40 - y0%) / -32, 1)
JredrawEndY% =
min((WimpBlock%!32 + 40 - y0%) / -32, NumberPlanets%)
loop% = redrawStartY%
redrawEndY%
y% = (-32 * loop%) - 40
1 sortedPlanet% = PlanetSortedOnShips%(loop%)
sideColours(PlanetSide(sortedPlanet%))
10, y%:
SideNames$(PlanetSide(sortedPlanet%))
colourBlack
282, y%:
PlanetShips%(sortedPlanet%)
472, y%:
PlanetName$(sortedPlanet%)
loop%
clickSortedPlanetsWindow(x%, y%)
If the user clicks over a planet name, then that planet is shown
in the World Window
x0%, y0%, selectedLine%
getWindowState(SortedPlanetsWindow%)
getOrigin(x0%, y0%)
x% = x% - x0%: y% = y0% - y%
"selectedLine% = (y% - 40) / 32
selectedLine% >= 1
updateWorldWindow( PlanetSortedOnShips%(selectedLine%) )
openWindow(WorldWindow%)
------------------------------------------------------------------------ Graph Window
drawGraphWindow(x0%, y0%)
This is prime for ARM'ing
loop%, loop2%, maximum%, xUnit, yUnit, graphPointer%, redrawStartX%, redrawEndX%, graphBlockStart%
CurrentTurn% <= 1
5maximum% = GraphDataMaximum%(CurrentGraphChoice%)
;xUnit = GraphWindowMaximumX% / (CurrentTurn% - 1)
;yUnit = (GraphWindowMinimumY% - 8) / (maximum% + 1)
!:redrawStartX% =
max((WimpBlock%!28 - x0%) / xUnit, 1)
"KredrawEndX% =
min(((WimpBlock%!36 - x0%) / xUnit) + 2, CurrentTurn%)
$ggraphBlockStart% = GraphBlock% + (GraphBlockEntrySize% * redrawStartX%) + (CurrentGraphChoice% * 4)
loop% = 0
NumberSides%
sideColours(loop%)
'5 graphPointer% = graphBlockStart% + (loop% * 12)
(redrawStartX% - 2) * xUnit, (maximum% - !graphPointer%) * yUnit
loop2% = redrawStartX%
redrawEndX%
+C
(loop2% - 1) * xUnit, (maximum% - !graphPointer%) * yUnit
,- graphPointer% += GraphBlockEntrySize%
loop2%
loop%
------------------------------------------------------------------- Statistics Window
drawStatisticsWindow(x0%, y0%)
loop%, y%, redrawStartY%, redrawEndY%
WimpBlock%!40 - y0% > -64
10, -8:
messageLookupString("Side")
298, -8:
messageLookupString("Ships")
474, -8:
messageLookupString("Reses")
650, -8:
messageLookupString("Planets")
10, -40:
"---------------- --------- --------- ---------"
=RredrawStartY% =
min(
max((WimpBlock%!40 + 72 - y0%) / -32, 0), NumberSides%)
>HredrawEndY% =
min((WimpBlock%!32 + 72 - y0%) / -32, NumberSides%)
loop% = redrawStartY%
redrawEndY%
y% = (-32 * loop%) - 72
sideColours(loop%)
10, y%:
SideNames$(loop%)
colourBlack
282, y%:
SideTotalShips%(loop%)
458, y%:
SideTotalResources%(loop%)
632, y%:
SideTotalPlanets%(loop%)
loop%
drawStatisticsWindowGraphs(WimpBlock%!28 - x0%, WimpBlock%!36 - x0%)
drawStatisticsWindowGraphs(minX%, maxX%)
loop%, top%, totalShips%, totalResources%
N@totalShips% =
totalShips: totalResources% =
totalResources
(minX% <= 328)
(maxX% >= 298)
top% = -72:
Ships bar
loop% = 0
NumberSides%
S\
drawStatisticsWindowPartBar(loop%, 298, top%, SideTotalShips%(loop%) / totalShips%)
loop%
(minX% <= 504)
(maxX% >= 474)
X! top% = -72:
Resources bar
loop% = 0
NumberSides%
Zd
drawStatisticsWindowPartBar(loop%, 474, top%, SideTotalResources%(loop%) / totalResources%)
loop%
(minX% <= 682)
(maxX% >= 652)
top% = -72:
Planets bar
loop% = 0
NumberSides%
aa
drawStatisticsWindowPartBar(loop%, 652, top%, SideTotalPlanets%(loop%) / NumberPlanets%)
loop%
drawStatisticsWindowPartBar(side%, x%,
top%, fraction)
height%
sideColours(side%)
j3height% = fraction * ((NumberSides% + 1) * -32)
x%, top%, 30, height%
top% += height%
totalShips
loop%, total%
loop% = 0
NumberSides%
s& total% += SideTotalShips%(loop%)
loop%
=total%
totalResources
loop%, total%
loop% = 0
NumberSides%
{* total% += SideTotalResources%(loop%)
loop%
=total%
getOrigin(
x0%,
y0%)
'x0% = WimpBlock%!4 - WimpBlock%!20
'y0% = WimpBlock%!16 - WimpBlock%!24
------------------------------------------------------------------------- Side Window
updateSideWindow(side%)
SideWindowSide% <> side%
toggleTick(SideWindowSide% + 1, SideWindowMenu%)
SideWindowSide% = side%
toggleTick(side% + 1, SideWindowMenu%)
side% = -1
side% = CurrentSide%
writeIndirectedBuffer(SideWindowName%, SideNames$(side%))
writeIndirectedBuffer(SideWindowFlag%, SideFlags$(side%))
writeIndirectedBuffer(SideWindowShips%,
(SideTotalShips%(side%)))
writeIndirectedBuffer(SideWindowResources%,
(SideTotalResources%(side%)))
writeIndirectedBuffer(SideWindowPlanets%,
(SideTotalPlanets%(side%)))
writeIndirectedBuffer(SideWindowPlayer%,
messageLookupString("Player" +
(SidePlayer%(side%))))
writeIndirectedBuffer(SideWindowPlace%,
sidePlace(side%)))
sidePlace(side%)
loop%, ourScore%, ourPosition%
!ourScore% =
sideScore(side%)
ourPosition% = 1
loop% <= NumberSides%
loop% <> side%
;
sideScore(loop%) > ourScore%
ourPosition% += 1
loop% += 1
=ourPosition%
sideScore(side%)
9= SideTotalShips%(side%) + SideTotalResources%(side%)
------------------------------------------------------------------------ World Window
drawWorldWindow(x0%, y0%)
arrivalTimes%(), numberArrivalTimes%()
minusTurn%, side%, numberArriving%, currentSide%
centreX%, xentreY%, radius%
WimpBlock%!36 - x0% <= 668
#centreX% = 789: centreY% = -234
arrivalTimes%(5, NumberSides%), numberArrivalTimes%(5)
getArrivalTimes(CurrentWorld%, arrivalTimes%(), numberArrivalTimes%())
minusTurn% = 5
7 numberArriving% = numberArrivalTimes%(minusTurn%)
& radius% = 90 + (minusTurn% * 24)
numberArriving% > 0
currentSide% = 1
%
side% = 1
numberArriving%
6
arrivalTimes%(minusTurn%, currentSide%)
currentSide% += 1
:
$
sideColours(currentSide%)
Q
drawArrivalSector(centreX%, centreY%, radius%, side%, numberArriving%)
currentSide% += 1
side%
colourBackground
)
centreX%, centreY%, radius%
minusTurn%
Draw planet
colourBackground
centreX%, centreY%, 90
sideColours(PlanetSide(CurrentWorld%))
centreX%, centreY%, 80
drawArrivalSector(centreX%, centreY%, radius%, side%, totalSides%)
degree, degree2
side% -= 1
(side% = 0)
(totalSides% = 1)
centreX%, centreY%, radius%
: degree =
( ( side% / totalSides%) * 360)
? degree2 =
min(((side% + 1) / totalSides%) * 360, 360))
centreX%, centreY%
centreX% +
(degree) * radius%, centreY% +
(degree) * radius%
&b5, centreX% +
(degree2) * radius%, centreY% +
(degree2) * radius%
getArrivalTimes(planet%,
arrivalTimes%(),
numberArrivalTimes%())
order%, ourArrival%, maximumOurArrival%, side%
.maximumOurArrival% =
(arrivalTimes%(), 1)
order% = 1
NumberMovementOrders%
0 side% = MovementOrders%(order%, OrderSide)
side% <> 0
:
MovementOrders%(order%, OrderPlanet) = planet%
M ourArrival% = MovementOrders%(order%, OrderArriving) - CurrentTurn%
/
ourArrival% <= maximumOurArrival%
1 arrivalTimes%(ourArrival%, side%) =
1 numberArrivalTimes%(ourArrival%) += 1
order%
updateWorldWindow(world%)
This updates the values of the WorldWindow% for name, position, etc.
shadeFlag%, loop%
CurrentWorld% = world%
writeIndirectedBuffer(WorldWindowName%, PlanetName$(world%))
writeIndirectedBuffer(WorldWindowX%,
(PlanetPosition(world%, 0)))
writeIndirectedBuffer(WorldWindowY%,
(PlanetPosition(world%, 1)))
writeIndirectedBuffer(WorldWindowFlag%, SideFlags$(PlanetSide(world%)))
writeIndirectedBuffer(WorldWindowResources%,
(PlanetResources(world%)))
writeIndirectedBuffer(WorldWindowShips%,
(PlanetShips%(world%)))
writeIndirectedBuffer(WorldWindowShipsDrag%, "0")
(PlanetSide(world%) <> CurrentSide%)
EndOfTurn%
shadeFlag%=
shadeFlag%=
loop% = 12
shadeIcon(WorldWindow%, loop%, shadeFlag%)
loop%
redrawWindowArea(WorldWindow%, 586, -432, 992, -20)
updateWorldWindowShips(transferShips%)
This moves ships between the planet and available for orders, just
on the window display. Sign of transferShips%:
+ve Increase planet store
-ve Increase ship order stores
planetShips%, orderShips%, oldPlanetShips%
aplanetShips% =
readIndirectedBuffer(WorldWindowShips%)) : oldPlanetShips% = planetShips%
BorderShips% =
readIndirectedBuffer(WorldWindowShipsDrag%))
transferShips% > 0
: transferShips% =
min( orderShips%, transferShips%)
: transferShips% =
max(-planetShips%, transferShips%)
"planetShips% += transferShips%
"orderShips% -= transferShips%
oldPlanetShips% <> planetShips%
writeIndirectedBuffer(WorldWindowShips%,
(planetShips%))
writeIndirectedBuffer(WorldWindowShipsDrag%,
(orderShips%))
updateWorldWindowPlanetShips(ships%)
planetShips%, orderShips%, oldPlanetShips%
&1oldPlanetShips% = PlanetShips%(CurrentWorld%)
':planetShips% =
min(
max(ships%, 0), oldPlanetShips%)
)0orderShips% = oldPlanetShips% - planetShips%
writeIndirectedBuffer(WorldWindowShips%,
(planetShips%))
writeIndirectedBuffer(WorldWindowShipsDrag%,
(orderShips%))
---------------------------------------------------------------------- NewGame Window
drawNewGameWindow(x0%, y0%)
loop%, y%, redrawStartY%, redrawEndY%
3SredrawStartY% =
min(
max((WimpBlock%!40 + 168 - y0%) / -32, 1), NumberSides%)
4TredrawEndY% =
min( (WimpBlock%!32 + 168 - y0%) / -32, NumberSides%)
loop% = redrawStartY%
redrawEndY%
y% = (-32 * loop%) - 168
sideColours(loop%)
28, y%:
SideNames$(loop%)
colourBlack
296, y%:
messageLookupString("Player" +
(SidePlayer%(loop%)))
loop%
updateNewGameWindowPlanets(change%)
oldNumberPlanets%
B&oldNumberPlanets% = NumberPlanets%
NumberPlanets% += change%
D;NumberPlanets% =
max(NumberPlanets%, NumberSides% + 1)
oldNumberPlanets% <> NumberPlanets%
writeIndirectedBuffer(NewGameWindowPlanets%,
(NumberPlanets%))
updateNewGameWindowSides(change%)
oldNumberSides%
N"oldNumberSides% = NumberSides%
NumberSides% += change%
PVNumberSides% =
max(NumberSides%, 2):
Has to be 2 or we run into RND(1) problems
Q4NumberSides% =
min(NumberSides%, MaximumSides%)
oldNumberSides% <> NumberSides%
writeIndirectedBuffer(NewGameWindowSides%,
(NumberSides%))
NumberSides% >= NumberPlanets%
updateNewGameWindowPlanets(NumberPlanets% - NumberSides% + 1)
redrawWindowArea(NewGameWindow%, 24, -9000, 810, -196 - (
min(oldNumberSides%, NumberSides%) * 32))
updateNewGameWindowRandom
This sets each side to a random non-human player.
Leave Human controlled players as they are.
loop%
loop% = 1
NumberSides%
SidePlayer%(loop%) <> 0
SidePlayer%(loop%) =
(NumberComputerPlayers%)
loop%
redrawWindowArea(NewGameWindow%, 24, -9000, 810, -190)
clickNewGameWindow(x%, y%, buttonState%)
x0%, y0%, selectedSide%, oldPlayer%
getWindowState(NewGameWindow%)
getOrigin(x0%, y0%)
l x% = x% - x0%: y% = y0% - y%
n#selectedSide% = (y% - 168) / 32
(selectedSide% >= 1)
(selectedSide% <= NumberSides%)
p- oldPlayer% = SidePlayer%(selectedSide%)
buttonState% = SelectClick
oldPlayer% += 1
buttonState% = AdjustClick
oldPlayer% += -1
oldPlayer% < 0
oldPlayer% = NumberComputerPlayers%
oldPlayer% > NumberComputerPlayers%
oldPlayer% = 0
v- SidePlayer%(selectedSide%) = oldPlayer%
redrawWindowArea(NewGameWindow%, 292, -(196 + selectedSide% * 32), 810, -(162 + selectedSide% * 32))
----------------------------------------------------------------------- Battle Window
startBattleWindow(planetName$, side1%, start1%, side2%, start2%)
writeIndirectedBuffer(BattleWindowPlanet%, planetName$)
writeIndirectedBuffer(BattleWindowSide1%, SideNames$(side1%))
setIconForegroundColour(BattleWindow%, 5,
sideColoursNumber(side1%))
writeIndirectedBuffer(BattleWindowSide2%, SideNames$(side2%))
setIconForegroundColour(BattleWindow%, 8,
sideColoursNumber(side2%))
writeIndirectedBuffer(BattleWindowStart1%,
(start1%) )
writeIndirectedBuffer(BattleWindowStart2%,
(start2%) )
writeIndirectedBuffer(BattleWindowCurrent1%,
(start1%) )
writeIndirectedBuffer(BattleWindowCurrent2%,
(start2%) )
writeIndirectedBuffer(BattleWindowComment%,
messageLookupString("BInProg"))
shadeIndirectedIcon(BattleWindowOk%,
shadeIndirectedIcon(BattleWindowFinish%,
----------------------------------------------------------------------- Winner Window
startWinnerWindow(winningSide%)
RiscOS2.00 doesn't seem to like the Win window, so don't bother
with it.
WimpVersion% >= 300
openWindowCentred(WinnerWindow%)
writeIndirectedBuffer(WinnerWindowName%, SideNames$(winningSide%))
writeIndirectedBuffer(WinnerWindowTurn%,
(CurrentTurn%))
writeIndirectedBuffer(WinnerWindowFlag%, SideFlags$(winningSide%))
wimpComplain("win2", SideNames$(winningSide%),
(CurrentTurn%))
Ok, finish
wimpCloseDown
*************************************************************************************
******************************************************************* Initializing Wimp
*************************************************************************************
initializeStart
initializeHeap
initializeMessages
initializeIcons
initializeWimpVariables
initializeWimpSystem
initializeSpriteArea("TrynthRes:Sprites")
initializeFonts
initializeLicence
initializeNewGame
----------------------------------------------------------------------------- Licence
initializeLicence
This reminds the user of the SHARWARE aspect of this software.
Reminders comes up when Trynth$Dir is changed, or every 10 load times
file%, oldPath$, newPath$, loadTimes%, remind%
%file% =
("<Trynth$Dir>.Options")
#file%, oldPath$, loadTimes%
#file%
"OS_ReadVarVal", "Trynth$Dir", WimpBlock%, 250, 0, 0
)newPath$ =
readSysString(WimpBlock%)
oldPath$ <> newPath$
remind% =
loadTimes% += 1
loadTimes%
5 = 0
remind% =
%file% =
("<Trynth$Dir>.Options")
#file%, newPath$, loadTimes%
#file%
remind%
wimpComplain("Licence", "", "")
--------------------------------------------------------------------------- Diagnosis
initializeDiagnosis
diagnosisPipe%
- diagnosisFile% =
("pipe::diagnosis.9")
diagnosis("")
diagnosis(" Welcome to Trynth Diagnosis window")
diagnosis(" ----------------------------------")
diagnosis("")
startTask(command$)
"Wimp_StartTask", command$ +
diagnosis(line$)
diagnosisPipe%
#diagnosisFile%, line$
---------------------------------------------------------------------------- New Game
initializeNewGame
reason%, finished%, buttonState%, icon%
initializeGameVariables
initializeSides
%NumberPlanets% = NumberSides% * 2
openTemplate
initializeNewGameWindow
initializeInfoWindow
initializeSaveWindow
"Wimp_CloseTemplate"
openWindowCentred(NewGameWindow%)
initializeIconMenu
0MainWindow% = -99: WorldWindow% = -99
LBattleWindow% = -99: OrdersWindow% = -99: SortedPlanetsWindow% = -99
LGraphWindow% = -99: StatisticsWindow% = -99: SideWindow% = -99
LoadedGame% =
wimpError
(Quit%
finished%
LoadedGame%)
"Wimp_Poll", %10011111110110110001, WimpBlock%
reason%
reason%
!
redrawWindowRequest
.
"Wimp_OpenWindow",, WimpBlock%
3: Quit% =
WimpBlock%!12
< buttonState% = WimpBlock%!8: icon% = WimpBlock%!16
:
icon%
10: finished% =
%
Left planets arrow
L
buttonState% = SelectClick
updateNewGameWindowPlanets(-1)
L
buttonState% = AdjustClick
updateNewGameWindowPlanets( 1)
&
Right planets arrow
L
buttonState% = SelectClick
updateNewGameWindowPlanets( 1)
L
buttonState% = AdjustClick
updateNewGameWindowPlanets(-1)
%
Left players arrow
J
buttonState% = SelectClick
updateNewGameWindowSides(-1)
J
buttonState% = AdjustClick
updateNewGameWindowSides( 1)
&
Right players arrow
J
buttonState% = SelectClick
updateNewGameWindowSides( 1)
J
buttonState% = AdjustClick
updateNewGameWindowSides(-1)
+
updateNewGameWindowRandom
*
buttonState% = MenuClick
@
openMenu(IconMenu%, WimpBlock%!0, WimpBlock%!4)
M
clickNewGameWindow(WimpBlock%!0, WimpBlock%!4, buttonState%)
menuSelect
17, 18:
userMessage
Quit%
wimpCloseDown:
closeWindow(NewGameWindow%)
shadeMenuItem(1, IconMenu%,
initializeMoreWimp
initializeWindows
initializeMenus
initializeIconBar
initializeDiagnosis
---------------------------------------------------------------------------- Messages
initializeMessages
length%, messages$
'$messages$ = "TrynthRes:Messages"
"MessageTrans_FileInfo",, messages$
,, length%
MessageBlock% 16
*0MessageBlockBuffer% =
getHeapBlock(length%)
"MessageTrans_OpenFile", MessageBlock%, messages$, MessageBlockBuffer%
---------------------------------------------------------------------- Wimp Variables
initializeWimpVariables
These are Wimp related Global Variables
Capital First Letter means global
WimpBlock% &1000
IndirectBlock% &1000
5%IndirectCurrent% = IndirectBlock%
7/TaskName$ =
messageLookupString("TskName")
IconBarWindow% = -2
Quit% =
diagnosisFile% =- 1
IconFlags% = &7000111
DragFromWindow% = -1
Mouse button clicks
?&AdjustClick = 1: MenuClick = 2
@&SelectClick = 4: AdjustDrag = 16
SelectDrag = 64
------------------------------------------------------------------------- Wimp System
initializeWimpSystem
Should work for 2.00 and 3.00+
messageList%
$WimpBlock% = "TASK"
JBmessageList% = WimpBlock% + 4:
List of WimpMessages received
KCmessageList%!0 = 2 : messageList%!4 = 3: messageList%!8 = 10
messageList%!12 = &502
messageList%!16 = 0
Try for RiscOS 2.00, noting real RiscOS version
"Wimp_Initialise", 200, !WimpBlock%, TaskName$
WimpVersion%, TaskHandle%
WimpVersion% >= 300
"Wimp_CloseDown", TaskHandle%, !WimpBlock%
"Wimp_Initialise", 300, !WimpBlock%, TaskName$, messageList%
WimpVersion%, TaskHandle%
------------------------------------------------------------------------- Sprite Area
initializeSpriteArea(fileName$)
Loads standard Sprite file into memory
fileType%, fileSize%
"OS_File", 5, fileName$
fileType%,,,, fileSize%
fileType% <> 1
255, "Could not find sprite file: '"+fileName$+"'"
fileSize% += 16
a/SpriteAreaBlock% =
getHeapBlock(fileSize%)
c#SpriteAreaBlock%!0 = fileSize%
SpriteAreaBlock%!4 = 0
SpriteAreaBlock%!8 = 16
SpriteAreaBlock%!12 = 0
"OS_SpriteOp", 256 + 10, SpriteAreaBlock%, fileName$
------------------------------------------------------------------------------ Fonts
initializeFonts
menuFont$, menuY%, menuX%, font%, flags%
FontReferenceBlock% 256
font% = 0
251
p# FontReferenceBlock%!font% = 0
font%
MenuFonts% =
t6 menuFont$ =
messageLookupString("MenuFont")
u2 menuX% =
messageLookupString("MenuX"))
v2 menuY% =
messageLookupString("MenuY"))
menuFont$ <> "System"
yW
"XFont_FindFont",, menuFont$, menuX% * 16, menuY% * 16, 0, 0
font% ;flags%
flags%
{4
wimpComplain("NoMenuFont", menuFont$, "")
MenuFonts% =
}
~' FontReferenceBlock%?font% = 1
:
, IconFlags% = IconFlags%
(1 << 6)
1 IconFlags% = IconFlags%
((1 <<24) -1)
1 IconFlags% = IconFlags%
(font% << 24)
MenuFonts% =
loseAllFonts
font%, loop%, uses%
font% = 0
' uses% = FontReferenceBlock%?font%
uses% > 0
loop% = 1
uses%
#
"Font_LoseFont", font%
loop%
font%
------------------------------------------------------------------------------- Icons
initializeIcons
StandardIndirectedIcon% = 0
----------------------------------------------------------------------------- Windows
initializeWindows
openTemplate
initializeMainWindow
initializeWorldWindow
initializeBattleWindow
initializeOrdersWindow
initializeSortedPlanetsWindow
initializeGraphWindow
initializeStatisticsWindow
initializeSideWindow
WinnerContinue% =
WimpVersion% >= 300
initializeWinnerWindow
"Wimp_CloseTemplate"
initializeNewGameWindow
wimpLoadTemplate("newgame", IndirectCurrent%)
:!(WimpBlock% + 88 + (32 * 13) + 24) = SpriteAreaBlock%
EWimpBlock%!44 = WimpBlock%!52 - ((MaximumSides% * 32) + 200 + 32)
<!(WimpBlock% + 88 + (32 * 11) + 4) = WimpBlock%!44 + 12
"Wimp_CreateWindow",, WimpBlock%
NewGameWindow%
BNewGameWindowPlanets% =
newIndirectedIcon(NewGameWindow%, 6)
BNewGameWindowSides% =
newIndirectedIcon(NewGameWindow%, 2)
writeIndirectedBuffer(NewGameWindowPlanets%,
(NumberPlanets%))
writeIndirectedBuffer(NewGameWindowSides%,
(NumberSides%))
initializeInfoWindow
wimpLoadTemplate("info", IndirectCurrent%)
9!(WimpBlock% + 88 + (32 * 9) + 24) = SpriteAreaBlock%
"Wimp_CreateWindow",, WimpBlock%
InfoWindow%
messageLookup("TskName",
indirectedBuffer(1), 40)
messageLookup("TskPurp",
indirectedBuffer(2), 40)
messageLookup("TskAuth",
indirectedBuffer(3), 40)
indirectedBuffer(4) = TaskDate$ +
indirectedBuffer(10) = TaskCopy$ +
initializeSaveWindow
ASaveWindow% =
wimpLoadCreateWindow("save", IndirectCurrent%)
*SaveWindowIcon% =
indirectedBuffer(3)
8SaveWindowText% =
newIndirectedIcon(SaveWindow%, 2)
$SaveWindowIcon% = "file_099"
writeIndirectedBuffer(SaveWindowText%, "SavedGame")
initializeMainWindow
wimpLoadTemplate("main", IndirectCurrent%)
[WimpBlock%!40 = 0 : WimpBlock%!44 = -(MaximumPlanetOffset% * 10)
@WimpBlock%!48 = MaximumPlanetOffset% * 10: WimpBlock%!52 = 0
MainWindowTitle% = WimpBlock%!72 + INSTR(FNread0String(WimpBlock%!72), "- ") + 1
)MainWindowTitle% = WimpBlock%!72 + 10
"Wimp_CreateWindow",, WimpBlock%
MainWindow%
PointerOverPlanet% = -1
initializeWorldWindow
wimpLoadTemplate("world", IndirectCurrent%)
9!(WimpBlock% + 88 + (32 * 9) + 24) = SpriteAreaBlock%
"Wimp_CreateWindow",, WimpBlock%
WorldWindow%
@WorldWindowName% =
newIndirectedIcon(WorldWindow%, 1)
@WorldWindowX% =
newIndirectedIcon(WorldWindow%, 4)
@WorldWindowY% =
newIndirectedIcon(WorldWindow%, 6)
@WorldWindowFlag% =
newIndirectedIcon(WorldWindow%, 9)
@WorldWindowResources% =
newIndirectedIcon(WorldWindow%, 8)
@WorldWindowShips% =
newIndirectedIcon(WorldWindow%, 13)
@WorldWindowShipsDrag% =
newIndirectedIcon(WorldWindow%, 16)
initializeBattleWindow
IBattleWindow% =
wimpLoadCreateWindow("battle", IndirectCurrent%)
ABattleWindowSide1% =
newIndirectedIcon(BattleWindow%, 5)
ABattleWindowSide2% =
newIndirectedIcon(BattleWindow%, 8)
ABattleWindowStart1% =
newIndirectedIcon(BattleWindow%, 6)
ABattleWindowStart2% =
newIndirectedIcon(BattleWindow%, 9)
ABattleWindowCurrent1% =
newIndirectedIcon(BattleWindow%, 7)
ABattleWindowCurrent2% =
newIndirectedIcon(BattleWindow%, 10)
ABattleWindowComment% =
newIndirectedIcon(BattleWindow%, 11)
ABattleWindowPlanet% =
newIndirectedIcon(BattleWindow%, 1)
ABattleWindowOk% =
newIndirectedIcon(BattleWindow%, 12)
ABattleWindowFinish% =
newIndirectedIcon(BattleWindow%, 13)
initializeOrdersWindow
wimpLoadTemplate("orders", IndirectCurrent%)
HWimpBlock%!44 = WimpBlock%!52 - (96 + (MaximumMovementOrders% * 32))
"Wimp_CreateWindow",, WimpBlock%
OrdersWindow%
initializeSortedPlanetsWindow
wimpLoadTemplate("sortplanet", IndirectCurrent%)
@WimpBlock%!44 = WimpBlock%!52 - ((NumberPlanets% * 32) + 72)
"Wimp_CreateWindow",, WimpBlock%
SortedPlanetsWindow%
initializeGraphWindow
wimpLoadTemplate("graph", IndirectCurrent%)
(GraphWindowMaximumX% = WimpBlock%!48
(GraphWindowMinimumY% = WimpBlock%!44
"Wimp_CreateWindow",, WimpBlock%
GraphWindow%
initializeStatisticsWindow
wimpLoadTemplate("statistics", IndirectCurrent%)
DWimpBlock%!4 = WimpBlock%!12 - (80 + ((NumberSides% + 1) * 32) )
"Wimp_CreateWindow",, WimpBlock%
StatisticsWindow%
initializeSideWindow
wimpLoadTemplate("side", IndirectCurrent%)
9!(WimpBlock% + 88 + (32 * 9) + 24) = SpriteAreaBlock%
"Wimp_CreateWindow",, WimpBlock%
SideWindow%
SideWindowSide% = -1
?SideWindowName% =
newIndirectedIcon(SideWindow%, 1)
?SideWindowShips% =
newIndirectedIcon(SideWindow%, 6)
?SideWindowResources% =
newIndirectedIcon(SideWindow%, 7)
?SideWindowPlanets% =
newIndirectedIcon(SideWindow%, 8)
?SideWindowFlag% =
newIndirectedIcon(SideWindow%, 9)
!?SideWindowPlayer% =
newIndirectedIcon(SideWindow%, 11)
"?SideWindowPlace% =
newIndirectedIcon(SideWindow%, 13)
initializeWinnerWindow
WinnerContinue% =
(BWinnerWindow% =
wimpLoadCreateWindow("win", IndirectCurrent%)
*@WinnerWindowName% =
newIndirectedIcon(WinnerWindow%, 1)
+@WinnerWindowTurn% =
newIndirectedIcon(WinnerWindow%, 3)
,@WinnerWindowOk% =
newIndirectedIcon(WinnerWindow%, 4)
-@WinnerWindowContinue% =
newIndirectedIcon(WinnerWindow%, 5)
.@WinnerWindowFlag% =
newIndirectedIcon(WinnerWindow%, 7)
------------------------------------------------------------------------------- Menus
initializeIconMenu
current%
IconMenu% 200
startMenu("Trynth", IconMenu%, current%)
addMenuItem("Info", InfoWindow%, 2, IconMenu%, current%)
addMenuItem("Save", SaveWindow%, 2, IconMenu%, current%)
addMenuItem("Quit", -1, 0, IconMenu%, current%)
shadeMenuItem(1, IconMenu%,
initializeMenus
current%, loop%
MainMenu% 200
startMenu("Trynth", MainMenu%, current%)
addMenuItem("NSide", -1, 0, MainMenu%, current%)
addMenuItem("NTurn", -1, 2, MainMenu%, current%)
addMenuItem("Stats", -1, 0, MainMenu%, current%)
addMenuItem("Orders", -1, 0, MainMenu%, current%)
shadeMenuItem(1, MainMenu%,
StatisticsMenu% 200 + (NumberSides% * 24)
startMenu("Stats", StatisticsMenu%, current%)
addMenuItem("Graphs", -1, 0, StatisticsMenu%, current%)
addMenuItem("SortPl", -1, 0, StatisticsMenu%, current%)
addMenuItem("SideInf", -1, 0, StatisticsMenu%, current%)
SideWindowMenu% 100 + (NumberSides% * 24)
startMenu("Side", SideWindowMenu%, current%)
addMenuItem("Auto", -1, 2, SideWindowMenu%, current%)
loop% = 0
NumberSides%
addMenuItem("Side" +
(loop%), -1, 0, SideWindowMenu%, current%)
loop%
toggleTick(SideWindowSide% + 1, SideWindowMenu%)
GraphMenu% 200
startMenu("Graph", GraphMenu%, current%)
addMenuItem("Ships", -1, 0, GraphMenu%, current%)
addMenuItem("Reses", -1, 0, GraphMenu%, current%)
addMenuItem("Planets", -1, 0, GraphMenu%, current%)
toggleTick(CurrentGraphChoice%, GraphMenu%)
initializeIconBar
_*!WimpBlock% = -1: WimpBlock%!4 = 0
`*WimpBlock%!8 = 0: WimpBlock%!12 = 70
a-WimpBlock%!16 = 70: WimpBlock%!20 = &303A
b:$(WimpBlock% + 24) = "!"+
stringToLowerCase(TaskName$)
"Wimp_CreateIcon",, WimpBlock%
----------------------------------------------------------------------- Help Messages
helpMessage
This attempts to find a help message associated with:
A window, and possibly the icon
A menu item
window%, icon%, startToken$, arg1$, arg2$
m2window% = WimpBlock%!32: icon% = WimpBlock%!36
window%
IconBarWindow% : startToken$ = "IBarWH"
InfoWindow% : startToken$ = "InfoWH"
qA
icon% = 10
arg1$ = TaskCopy$
SaveWindow% : startToken$ = "SaveWH"
MainWindow% : startToken$ = "MainWH"
StatisticsWindow% : startToken$ = "StatWH"
OrdersWindow% : startToken$ = "OrdWH"
WorldWindow% : startToken$ = "WorWH"
xC arg1$ = PlanetName$(CurrentWorld%)
yN arg2$ = SideNames$(PlanetSide(CurrentWorld%))
BattleWindow% : startToken$ = "BatWH"
GraphWindow% : startToken$ = "GraphWH"
SortedPlanetsWindow%: startToken$ = "SortWH"
SideWindow% : startToken$ = "SideWH"
~A arg1$ = SideNames$(CurrentSide%)
NewGameWindow% : startToken$ = "NGameWH"
WinnerWindow% : startToken$ = "WinWH"
Could be a Menu option that needs help. Only for post-3.00
WimpVersion% >= 300
D
"Wimp_GetMenuState", 1, WimpBlock% + 40, window%, icon%
WimpBlock%!40 >= 0
! icon% = WimpBlock%!40
CurrentMenu%
7
IconMenu% : startToken$ = "IBarMH"
8
GraphMenu% : startToken$ = "GraphMH"
8
StatisticsMenu%: startToken$ = "StatsMH"
7
SideWindowMenu%: startToken$ = "SideMH"
O
icon% > 0
arg1$ = SideNames$(icon% - 1)
7
MainMenu% : startToken$ = "MainMH"
startToken$ <> ""
sendHelpMessage(startToken$, icon%, arg1$, arg2$)
*************************************************************************************
************************************************************************ WIMP Library
*************************************************************************************
------------------------------------------------------------------------- Saving data
dataSave
x0%, y0%, leafName$
IleafName$ =
getLeafName(
readIndirectedBuffer(SaveWindowText%)) +
"Wimp_GetPointerInfo",, WimpBlock%
@WimpBlock%!20 = WimpBlock%!12: WimpBlock%!24 = WimpBlock%!16
?WimpBlock%!28 = WimpBlock%!0 : WimpBlock%!32 = WimpBlock%!4
-WimpBlock%!0 = (
(leafName$) + 49)
)WimpBlock%!12 = 0: WimpBlock%!16 = 1
+WimpBlock%!36 = -1: WimpBlock%!40 = 099
"$(WimpBlock% + 44) = leafName$
"Wimp_SendMessage", 17, WimpBlock%, WimpBlock%!20, WimpBlock%!24
dataSaveAck(fileName$)
Actually save data to a file
fileName$, ".")=0
closeMenu
wimpComplain("ErrSDrag", "", "")
saveTrynthGame(fileName$)
closeMenu
writeIndirectedBuffer(SaveWindowText%, fileName$)
dataLoad
fileName$
(WimpBlock%!20 = NewGameWindow%)
(WimpBlock%!40 = &99)
/ fileName$ =
read0String(WimpBlock% + 44)
"Hourglass_On"
loadTrynthGame(fileName$)
"Hourglass_Off"
LoadedGame% =
getLeafName(fileName$)
fileName$, ".")
3 fileName$ =
fileName$,
fileName$, ".") + 1)
=fileName$
saveTrynthGame(fileName$)
file%
"Hourglass_On"
file% =
(fileName$)
saveGameVariables(file%)
saveSides(file%)
saveComputerBlock(file%)
savePlanets(file%)
saveStatistics(file%)
saveGraphs(file%)
saveSortedOnShips(file%)
saveMovementOrders(file%)
#file%
("SetType "+fileName$+" 099")
"Hourglass_Off"
loadTrynthGame(fileName$)
file%
file% =
(fileName$)
loadGameVariables(file%)
loadSides(file%)
initializeSidesTotal
initializeComputerBlock
loadComputerBlock(file%)
initializePlanetVariables
loadPlanets(file%)
loadStatistics(file%)
loadGraphs(file%)
initializeJourneyTimes
loadSortedOnShips(file%)
initializeMovementOrders
loadMovementOrders(file%)
#file%
Message_DataLoadAck
WimpBlock%!12 = WimpBlock%!8
WimpBlock%!16 = 4
"Wimp_SendMessage", 17, WimpBlock%, WimpBlock%!4
----------------------------------------------------------------------- Help Messages
sendHelpMessage(startToken$, addition%, arg1$, arg2$)
length%, flags%
"XMessageTrans_Lookup", MessageBlock%, startToken$ +
(addition%), WimpBlock% + 20, 232, arg1$, arg2$
,,,length%; flags%
flags%
"MessageTrans_Lookup", MessageBlock%, startToken$, WimpBlock% + 20, 232, arg1$, arg2$
,,,length%
FWimpBlock%!0 = (length% + 25)
3: WimpBlock%!12 = WimpBlock%!8
WimpBlock%!16 = &503
"Wimp_SendMessage", 17, WimpBlock%, WimpBlock%!4
--------------------------------------------------------------------------- Messages
messageLookupStringArgs(token$, arg1$, arg2$)
pointer%, length%, text$, loop%
"MessageTrans_Lookup", MessageBlock%, token$, 0, 255, arg1$, arg2$
,, pointer%, length%
loop% = 0
length% - 1
text$ +=
(pointer%?loop%)
=text$
messageLookupString(token$)
messageLookupStringArgs(token$, "", "")
messageLookup(token$, destinationPtr%, maximumLength%)
"MessageTrans_Lookup", MessageBlock%, token$, destinationPtr%, maximumLength%
messageLookupArgs(token$, destinationPtr%, maximumLength%, arg1$, arg2$)
"MessageTrans_Lookup", MessageBlock%, token$, destinationPtr%, maximumLength%, arg1$, arg2$
messageLookupLength(token$, destinationPtr%, maximumLength%,
actualLength%)
"MessageTrans_Lookup", MessageBlock%, token$, destinationPtr%, maximumLength%
,,,actualLength%
messageRead(token$,
address%,
length%)
"MessageTrans_Lookup", MessageBlock%, token$, 0
,,address%, length%
-------------------------------------------------------------------------- Close Down
wimpCloseDown
diagnosisPipe%
diagnosisFile% <> -1
#diagnosisFile%
loseAllFonts
TRACE CLOSE
"XMessageTrans_CloseFile", WimpBlock%
"XWimp_DragBox",, -1
"XHourglass_Smash"
$WimpBlock% = "TASK"
"XWimp_CloseDown", TaskHandle%, !WimpBlock%
---------------------------------------------------------------------------- Template
openTemplate
file$
WimpVersion% >= 310
file$ = "Templ3d"
file$ = "Templ2d"
"Wimp_OpenTemplate",, "TrynthRes:"+file$
wimpLoadCreateWindow(windowName$,
indirect%)
window%
wimpLoadTemplate(windowName$, indirect%)
"Wimp_CreateWindow",, WimpBlock%
window%
=window%
wimpLoadTemplate(windowName$,
indirect%)
"Wimp_LoadTemplate",, WimpBlock%, indirect%, IndirectBlock%+&1000, FontReferenceBlock%, windowName$, 0
,,indirect%
------------------------------------------------------------------------------ Screen
screenSize(
screenX%,
screenY%)
F%, P%
&35,-1,4
,,F%
&35,-1,11
,,P%
screenX%=P%<<F%
&35,-1,5
,,F%
&35,-1,12
,,P%
screenY%=P%<<F%
----------------------------------------------------------------------------- Windows
openWindow(window%)
Opens a windw to the Front of the screen
!WimpBlock% = window%
"Wimp_GetWindowState",, WimpBlock%
WimpBlock%!28 = -1
"Wimp_OpenWindow",, WimpBlock%
openWindowCentred(window%)
Opens a window to the Front of the screen, in centre
screenX%, screenY%, width%, height%
!WimpBlock% = window%
"Wimp_GetWindowInfo",, WimpBlock%
WimpBlock%!28 = -1
screenSize(screenX%, screenY%)
_+width% = WimpBlock%!52 - WimpBlock%!44
`+height% = WimpBlock%!56 - WimpBlock%!48
aRWimpBlock%!4 = (screenX% - width%)
2: WimpBlock%!12 = WimpBlock%!4 + width%
bSWimpBlock%!8 = (screenY% - height%)
2: WimpBlock%!16 = WimpBlock%!8 + height%
"Wimp_OpenWindow",, WimpBlock%
reopenWindow(window%)
!WimpBlock% = window%
"Wimp_GetWindowState",, WimpBlock%
"Wimp_OpenWindow",, WimpBlock%
closeWindow(window%)
!WimpBlock% = window%
"Wimp_CloseWindow",, WimpBlock%
getWindowState(window%)
!WimpBlock% = window%
"Wimp_GetWindowState",, WimpBlock%
redrawWindowArea(window%, x0%, y0%, x1%, y1%)
"Wimp_ForceRedraw", window%, x0%, y0%, x1%, y1%
redrawWindow(window%)
"Wimp_ForceRedraw", window%, 0, -&7FFFFF, &7FFFFF, 0
redrawWindowTitle(window%)
WimpBlock%!0 = window%
"Wimp_GetWindowState",, WimpBlock%
WimpBlock%!32
(1 << 16)
"Wimp_ForceRedraw", -1, WimpBlock%!4, (WimpBlock%!16) + 4, WimpBlock%!12, (WimpBlock%!16) + 36
------------------------------------------------------------------------------- Icons
indirectedBuffer(iconNumber%)
Used a CreateWindow block
indirectedLookup(iconNumber%, 20)
indirectedValidation(iconNumber%)
indirectedLookup(iconNumber%, 24)
indirectedLength(iconNumber%)
indirectedLookup(iconNumber%, 28)
indirectedLookup(iconNumber%, offset%)
3=WimpBlock%!((iconNumber% * 32) + 88 + offset%)
newBasicIcon(iconType%, size%, window%, icon%)
block%
!block% =
getHeapBlock(size%)
block%!0 = iconType%
*block%!4 = window% : block%!8 = icon%
=block%
newIndirectedIcon(window%, icon%)
Creates an 'Indircted' icon representation.
block%
Gblock% =
newBasicIcon(StandardIndirectedIcon%, 24, window%, icon%)
Rblock%!12 =
indirectedBuffer(icon%): block%!16 =
indirectedValidation(icon%)
(block%!20 =
indirectedLength(icon%)
=block%
readIndirectedBuffer(iconBlock%)
readSysString(iconBlock%!12)
writeIndirectedBuffer(iconBlock%, text$)
This stoes the next text$ and redraws it within the window
shortText$, length%
length% = iconBlock%!20 - 1
!shortText$ =
text$, length%)
!$(iconBlock%!12) = shortText$
"?(iconBlock%!12 + length%) = 0
redrawIcon(iconBlock%!4, iconBlock%!8)
shadeIndirectedIcon(iconBlock%, flag%)
shadeIcon(iconBlock%!4, iconBlock%!8, flag%)
redrawIcon(window%, icon%)
1!WimpBlock% = window%: WimpBlock%!4 = icon%
-WimpBlock%!8 = 0 : WimpBlock%!12 = 0
"Wimp_SetIconState",, WimpBlock%
redrawIconList(window%, iconList%())
This redraws every icon listed in the iconList%() array, for
window%. SMOOTHY procedure
loop%, length%
length% =
(iconList%(), 1)
WimpBlock%!0 = window%
-WimpBlock%!8 = 0 : WimpBlock%!12 = 0
loop% = 1
length%
% WimpBlock%!4 = iconList%(loop%)
"Wimp_SetIconState",, WimpBlock%
loop%
getIconState(window%, icon%)
WimpBlock%!0 = window%
WimpBlock%!4 = icon%
"Wimp_GetIconState",, WimpBlock%
setIconState(window%, icon%, eor%, mask%)
1WimpBlock%!0 = window%: WimpBlock%!4 = icon%
1WimpBlock%!8 = eor% : WimpBlock%!12 = mask%
"Wimp_SetIconState",, WimpBlock%
shadeIcon(window%, icon%, flag%)
flag%
setIconState(window%, icon%, 1 << 22, 1 << 22)
setIconState(window%, icon%, 0, 1 << 22)
setIconForegroundColour(window%, icon%, colour%)
setIconState(window%, icon%, colour% << 24, 15 << 24)
setIconBackgroundColour(window%, icon%, colour%)
setIconState(window%, icon%, colour% << 28, 15 << 28)
------------------------------------------------------------------------------ Errors
wimpError
response%
0, 0
!WimpBlock% =
@$(WimpBlock% + 4) =
$ + " (Error code " +
) + ")" +
"Wimp_ReportError", WimpBlock%, 3, TaskName$
,response%
response% = 2
Quit% =
wimpCloseDown:
wimpComplain(complainToken$, arg1$, arg2$)
complain$
Fcomplain$ =
messageLookupStringArgs(complainToken$, arg1$, arg2$)
!WimpBlock% = 0
messageLookup(complainToken$, WimpBlock% + 4, 250)
"Wimp_ReportError", WimpBlock%, 17, TaskName$
------------------------------------------------------------------------------- Menus
openMenu(menu%, x%, y%)
Open a menu, remembering details in case it is to be kept open
x% -= 60
CurrentMenu% = menu%
*CurrentMenuX% = x%: CurrentMenuY% = y%
"Wimp_CreateMenu",, menu%, x%, y%
closeMenu
"Wimp_CreateMenu",, -1
openIconBarMenu(menu%, x%)
This opens a menu with correct y position relative to the icon bar
menuItemHeight%, menuItemGap%, menuHeight%, tempMenu%
7menuItemHeight% = menu%!20: menuItemGap% = menu%!24
menu%!0 = 0
menuHeight% = menuItemGap%
menuHeight% = menuItemHeight% + menuItemGap%
tempMenu% = menu% + 4
tempMenu% += 24
$ menuHeight% += menuItemHeight%
(tempMenu%!0
menuHeight% += 24
(tempMenu%!0
&80) <> 0
openMenu(menu%, x%, menuHeight% + 56)
reopenCurrentMenu
Tests to see if the current menu should stay open.
(Adjust has been used to select option)
"Wimp_GetPointerInfo",, WimpBlock%
WimpBlock%!8 = AdjustClick
"Wimp_CreateMenu",, CurrentMenu%, CurrentMenuX%, CurrentMenuY%
startMenu(titleToken$, start%,
block%)
length%
block% = start%
messageLookupLength(titleToken$, block%, 12, length%)
*0block%!12 = &70207: block%!16 = length% * 16
+%block%!20 = 40: block%!24 = 0
block% += 28
addMenuItem(itemToken$, subMenu%, menuFlags%, start%,
current%)
itemWidth%, length%, address%, item$
messageRead(itemToken$, address%, length%)
current% > start% + 28
current%!-24 = current%!-24
5"current%!0 = menuFlags%
65current%!4 = subMenu%: current%!8 = IconFlags%
7,current%!12 = address%: current%!16 = -1
current%!20 = length%
current% += 24
addMenuItemWidth(address%, length%, start%)
addMenuItemWidth(address%, charLength%, start%)
This ensures that the menu is wide enough for all entries
itemWidth%
MenuFonts%
"Font_StringWidth",, address%, 1E8, 1E8, -1, 1E8
,, itemWidth%
"Font_ConverttoOS",, itemWidth%, 0
, itemWidth%
G# itemWidth% = charLength% * 16
itemWidth% += 16
itemWidth% > start%!16
start%!16 = itemWidth%
toggleTick(menuItem%, start%)
current%
Q1current% = (start% + 28) + (menuItem% * 24)
current%!0 = current%!0
shadeMenuItem(menuItem%, start%, flag%)
current%
X/current% = (start% + 28) + (menuItem% * 24)
flag%
Z) current%!8 = current%!8
(1 << 22)
\- current%!8 = current%!8
(1 << 22))
------------------------------------------------------------------------------ Caret
removeCaret
"Wimp_SetCaretPosition", -1
--------------------------------------------------------------------------- Drag Box
dragBox(window%, icon%)
x0%, y0%
getWindowState(window%)
getOrigin(x0%, y0%)
getIconState(window%, icon%)
m:!WimpBlock% = window% : WimpBlock%!4 = 5
nLWimpBlock%!8 = x0% + WimpBlock%!8 : WimpBlock%!12 = y0% + WimpBlock%!12
oLWimpBlock%!16 = x0% + WimpBlock%!16: WimpBlock%!20 = y0% + WimpBlock%!20
p:WimpBlock%!24 = 0 : WimpBlock%!28 = 0
qBWimpBlock%!32 = &7FFFFFFF : WimpBlock%!36 = &7FFFFFFF
dragASprite
(window% = SaveWindow%)
"DragASprite_Start", 197, 1, "file_099", WimpBlock% + 8, WimpBlock% + 24
"Wimp_DragBox",, WimpBlock%
----------------------------------------------------------------------------- Pointer
getPointerInfo
"Wimp_GetPointerInfo",, WimpBlock%
------------------------------------------------------------------------- DragASprite
dragASprite
Answer true if you use solid sprite dragging
flags%, temp%
"XOS_SWINumberFromString",, "DragASprite_Start"
temp% ;flags%
"OS_Byte", 161, 28
,,temp%
((temp%
2) = 2)
(flags%
*************************************************************************************
*********************************************************************** Memory system
*************************************************************************************
initializeHeap
Use Heap Manager to provide useful memory management system
Ensure that there is 1 page of free space within the heap to use
Assumes that App loads at &8000
HeapBlock% =
"OS_ReadMemMapInfo"
SystemPageSize%
"Wimp_SlotSize", HeapBlock% - &8000 + SystemPageSize%, -1
HeapEnd%
HeapEnd% += &8000
HeapEnd% <= HeapBlock%
255, "Not enough memory for Heap block"
"OS_Heap", 0, HeapBlock%,, HeapEnd% - HeapBlock%
getHeapBlock(blockSize%)
This attempt to get a block of memory from the HeapManager of
size blockSize%. If it fails it attempts to increase the tasks
SlotSize
freeBlockSize%, slotIncrease%, oldHeapEnd%, blockPointer%
blockSize% = 0
blockSize%=1:
Get around heap specification problem
"OS_Heap", 1, HeapBlock%
,, freeBlockSize%
freeBlockSize% < blockSize%
oldHeapEnd% = HeapEnd%
L HeapEnd% =
extendSlotSize((blockSize%
SystemPageSize%) + 1) + &8000
"OS_Heap", 5, HeapBlock%,, HeapEnd% - oldHeapEnd%
"OS_Heap", 1, HeapBlock%
,, freeBlockSize%, t%
freeBlockSize% < blockSize%
255,
messageLookupString("HeapFree")
"OS_Heap", 2, HeapBlock%,, blockSize%
,,blockPointer%
=blockPointer%
freeHeapBlock(blockPointer%)
freeBlockSize%, numberFreePages%, flags%
"OS_Heap", 3, HeapBlock%, blockPointer%
"OS_Heap", 1, HeapBlock%
,, freeBlockSize%
This isn't finished...
freeBlockSize% > SystemPageSize%
A
"XOS_Heap", 5, HeapBlock%,, -SystemPageSize%
;flags%
(flags%
1) = 0
numberFreePages% += 1
% HeapEnd% -= SystemPageSize%
flags%
numberFreePages% > 0
4 flags% =
extendSlotSize(- numberFreePages%)
extendHeapBlock(
blockPointer%, change%)
Note may change blockPointer%, so have to return
Doesn't extend the Wimp_SlotSize yet
flags%, temp%
"XOS_Heap", 4, HeapBlock%, blockPointer%, change%
,, blockPointer% ;flags%
flags%
temp% =
extendSlotSize(1)
"OS_Heap", 5, HeapBlock%,, SystemPageSize%
"XOS_Heap", 4, HeapBlock%, blockPointer%, change%
,, blockPointer% ;flags%
--------------------------------------------------------------------------- Slot Size
extendSlotSize(changePages%)
This attempts to increase the Task SlotSize by the number of pages
defined in the parameter. Error if not possible
oldTaskSize%, newTaskSize%, actualTaskSize%
"Wimp_SlotSize", -1, -1
oldTaskSize%
BnewTaskSize% = oldTaskSize% + (SystemPageSize% * changePages%)
"Wimp_SlotSize", newTaskSize%, -1
actualTaskSize%
actualTaskSize% <> newTaskSize%
255, "Could not extend tasks slot size"
=newTaskSize%
*************************************************************************************
******************************************************************* Initializing Game
*************************************************************************************
initializeGame
PROCinitializeGameVariables
PROCinitializeSides
initializeSidesTotal
initializeComputerBlock
initializePlanetVariables
initializePlanets
initializeJourneyTimes
initializeStatistics
initializeGraphs
initializeSortedOnShips
initializeComputerSides
initializeMovementOrders
"StartSide% =
(NumberSides%)
initializeGameVariables
dummy
-dummy =
Randomize the randomizer
$CurrentTurn% = 1: EndOfTurn% =
MaximumResources% = 250
CurrentWorld% = 1
loadGameVariables(file%)
#file%, CurrentTurn%, EndOfTurn%, CurrentWorld%, NumberPlanets%, StartSide%
saveGameVariables(file%)
#file%, CurrentTurn%, EndOfTurn%, CurrentWorld%, NumberPlanets%, StartSide%
initializeSides
Note that: Side = 0, is Neutral always
The SidePlayer%() determines
0 Human player
1 Computer Player -
loop%
(NumberSides% = 6: MaximumSides% = 10
SideNames$(MaximumSides%), SideFlags$(MaximumSides%), SidePlayer%(MaximumSides%)
loop% = 0
MaximumSides%
B SideNames$(loop%) =
messageLookupString("Side" +
(loop%))
B SideFlags$(loop%) =
messageLookupString("SideS" +
(loop%))
loop%
)SidePlayer%(0) = 99:
Set up Neutral
>SidePlayer%(1) = 0: SidePlayer%(2) = 2: SidePlayer%(3) = 0
>SidePlayer%(4) = 4: SidePlayer%(5) = 5: SidePlayer%(6) = 5
>SidePlayer%(7) = 4: SidePlayer%(8) = 4: SidePlayer%(9) = 2
SidePlayer%(10)= 2
NumberComputerPlayers% = 6
loadSides(file%)
side%
#file%, CurrentSide%, EndOfTurn%
#file%, NumberSides%
side% = 1
NumberSides%
#file%, SidePlayer%(side%)
side%
saveSides(file%)
side%
#file%, CurrentSide%, EndOfTurn%
#file%, NumberSides%
side% = 1
NumberSides%
#file%, SidePlayer%(side%)
side%
initializeSidesTotal
SideTotalPlanets%(NumberSides%), SideTotalShips%(NumberSides%)
SideTotalResources%(NumberSides%)
initializeComputerBlock
Some computer players require their own block of memory to store
bits and pieces in. This defines the appropriate areas.
Care has to be taken in this system not to write or read outside
the appropriate block of memory
loop%, totalRequiredMemory%, currentComputerBlock%
loop% = 1
NumberSides%
8I totalRequiredMemory% +=
computerRequiredMemory(SidePlayer%(loop%))
loop%
;<ComputerBlock% =
getHeapBlock(totalRequiredMemory%)
<-ComputerBlockSize% = totalRequiredMemory%
ComputerBlockPtr%(NumberSides%)
?*currentComputerBlock% = ComputerBlock%
loop% = 1
NumberSides%
A6 ComputerBlockPtr%(loop%) = currentComputerBlock%
BL currentComputerBlock% +=
computerRequiredMemory(SidePlayer%(loop%))
loop%
loadComputerBlock(file%)
loop%, data%, total%
#file%, total%
total% <> ComputerBlockSize%
1, "ComputerBlock sizes do not match!"
loop% = ComputerBlock%
(ComputerBlock% + ComputerBlockSize%) - 1
#file%, data%
!loop% = data%
loop%
loop% = 1
NumberSides%
#file%, data%
Q7 ComputerBlockPtr%(loop%) = data% + ComputerBlock%
loop%
saveComputerBlock(file%)
loop%
#file%, ComputerBlockSize%
loop% = ComputerBlock%
(ComputerBlock% + ComputerBlockSize%) - 1
#file%, !loop%
loop%
loop% = 1
NumberSides%
#file%, ComputerBlockPtr%(loop%) - ComputerBlock%
loop%
initializePlanetVariables
NumberPlanets% = 22
MaximumPlanetOffset% = 100
d!MaximumPlanetResources% = 100
PlanetPosition(NumberPlanets%, 1)
PlanetName$(NumberPlanets%)
PlanetResources(NumberPlanets%)
PlanetSide(NumberPlanets%)
PlanetShips%(NumberPlanets%)
initializePlanets
Temporary fiddle with NumberPlanets% to improve efficiency
of FNuniquePlanetPosition()
loop%, tempNumberPlanets%, defaultPlanetName$
r:defaultPlanetName$ =
messageLookupString("DefPlanet")
s'tempNumberPlanets% = NumberPlanets%
loop% = 1
tempNumberPlanets%
NumberPlanets% = loop%
findUniquePlanetPosition(PlanetPosition(loop%, 0), PlanetPosition(loop%, 1))
w< PlanetName$(loop%) = defaultPlanetName$ +
(loop%)
x9 PlanetResources(loop%) =
(MaximumPlanetResources%)
y PlanetSide(loop%) = 0
z5 PlanetShips%(loop%) = PlanetResources(loop%)
loop%
Set up initial planets for teams
loop% = 1
NumberSides%
$ PlanetSide(loop%) = loop%
: PlanetResources(loop%) = MaximumPlanetResources% / 2
: PlanetShips%(loop%) = MaximumPlanetResources% / 2
loop%
updateTotalPlanetShipsAverage
loadPlanets(file%)
loop%
loop% = 1
NumberPlanets%
#file%, PlanetPosition(loop%, 0), PlanetPosition(loop%, 1)
#file%, PlanetName$(loop%), PlanetResources(loop%), PlanetSide(loop%)
#file%, PlanetShips%(loop%)
loop%
updateTotalPlanetShipsAverage
savePlanets(file%)
loop%
loop% = 1
NumberPlanets%
#file%, PlanetPosition(loop%, 0), PlanetPosition(loop%, 1)
#file%, PlanetName$(loop%), PlanetResources(loop%), PlanetSide(loop%)
#file%, PlanetShips%(loop%)
loop%
findUniquePlanetPosition(
x%,
" x% =
(MaximumPlanetOffset%)
" y% =
(MaximumPlanetOffset%)
uniquePlanetPosition(x%, y%)
uniquePlanetPosition(x%, y%)
loop%
Make sure that we don't overlap planets on main window
loop% = 1
NumberPlanets% - 1
PlanetPosition(loop%, 0) = x%
PlanetPosition(loop%, 1) = y%
loop%
Leave space at top left of Main window for PointerOverPlanet details
(x% < 60)
(y% <= 8)
initializeJourneyTimes
JourneySpeed% = 20
GMaxJourneyTime% =
((MaximumPlanetOffset% ^ 2) * 2) / JourneySpeed%
initializeStatistics
loop%, side%
Set up totals for Statistics Window
loop% = 1
NumberPlanets%
side% = PlanetSide(loop%)
7 SideTotalShips%(side%) += PlanetShips%(loop%)
% SideTotalPlanets%(side%) += 1
: SideTotalResources%(side%) += PlanetResources(loop%)
loop%
loadStatistics(file%)
loop%
loop% = 0
NumberSides%
#file%, SideTotalShips%(loop%), SideTotalPlanets%(loop%), SideTotalResources%(loop%)
loop%
saveStatistics(file%)
loop%
loop% = 0
NumberSides%
#file%, SideTotalShips%(loop%), SideTotalPlanets%(loop%), SideTotalResources%(loop%)
loop%
initializeGraphs
GraphData is stored for each turn, based on totals at the
end of that turn for each side
0 Total sides ships
1 Total sides resources
2 Total sides planets
Data is stored in blocks, each holding 20 turns worth of information.
Up to 20 of blocks, 4000 turns...
CurrentGraphChoice% = 1
GraphDataMaximum%(2)
2GraphBlockEntrySize% = (NumberSides% + 1) * 12
4GraphSubBlockSize% = GraphBlockEntrySize% * 20
3GraphBlock% =
getHeapBlock(GraphSubBlockSize%)
updateGraph
loadGraphs(file%)
loop%, side%, start%, A%, B%, C%
GraphDataMaximum%(2)
#file%, CurrentGraphChoice%
#file%, GraphDataMaximum%(0), GraphDataMaximum%(1), GraphDataMaximum%(2)
#file%, GraphBlockEntrySize%, GraphSubBlockSize%
PGraphBlock% =
getHeapBlock( ((CurrentTurn%
20) + 1) * GraphSubBlockSize%)
/start% = GraphBlock% + GraphBlockEntrySize%
loop% = 1
CurrentTurn%
side% = 0
NumberSides%
#file%, A%, B%, C%
:
3 start%!0 = A%: start%!4 = B%: start%!8 = C%
start% += 12
side%
loop%
saveGraphs(file%)
loop%, side%, start%
#file%, CurrentGraphChoice%
#file%, GraphDataMaximum%(0), GraphDataMaximum%(1), GraphDataMaximum%(2)
#file%, GraphBlockEntrySize%, GraphSubBlockSize%
/start% = GraphBlock% + GraphBlockEntrySize%
loop% = 1
CurrentTurn%
side% = 0
NumberSides%
-
#file%, start%!0, start%!4, start%!8
start% += 12
side%
loop%
initializeSortedOnShips
loop%
PlanetSortedOnShips%(NumberPlanets%)
loop% = 1
NumberPlanets%
) PlanetSortedOnShips%(loop%) = loop%
loop%
updatePlanetSortedOnShips
loadSortedOnShips(file%)
loop%
PlanetSortedOnShips%(NumberPlanets%)
loop% = 1
NumberPlanets%
#file%, PlanetSortedOnShips%(loop%)
loop%
saveSortedOnShips(file%)
loop%
loop% = 1
NumberPlanets%
"*
#file%, PlanetSortedOnShips%(loop%)
loop%
initializeComputerSides
loop%
loop% = 1
NumberSides%
SidePlayer%(loop%)
,0
3: !(ComputerBlockPtr%(loop%)) = loop%
-0
4: !(ComputerBlockPtr%(loop%)) = loop%
.0
5: !(ComputerBlockPtr%(loop%)) = loop%
/)
spClearAttackDetails(loop%)
loop%
initializeMovementOrders
A movement order has the form:
-0-- -----1------- ------2----- ---------3--------
Side Turn arriving Number ships Destination planet
Note to show that a particular MovementOrder slot is free, the side
is set to 0. Note: Neutral planets NEVER move ships, etc.
=;MaximumMovementOrders% = 100: NumberMovementOrders% = 1
MovementOrders%(MaximumMovementOrders%, 3)
MovementOrders%() = 0
A%OrderSide = 0: OrderArriving = 1
B%OrderShips = 2: OrderPlanet = 3
loadMovementOrders(file%)
loop%
#file%, NumberMovementOrders%
NumberMovementOrders% > MaximumMovementOrders%
255, "Saved game needs more than MaximumMovementOrders%"
loop% = 1
NumberMovementOrders%
LC
#file%, MovementOrders%(loop%, 0), MovementOrders%(loop%, 1)
MC
#file%, MovementOrders%(loop%, 2), MovementOrders%(loop%, 3)
loop%
saveMovementOrders(file%)
loop%
#file%, NumberMovementOrders%
loop% = 1
NumberMovementOrders%
WC
#file%, MovementOrders%(loop%, 0), MovementOrders%(loop%, 1)
XC
#file%, MovementOrders%(loop%, 2), MovementOrders%(loop%, 3)
loop%
*************************************************************************************
********************************************************************** Game Mechanics
*************************************************************************************
--------------------------------------------------------------------- Movement Orders
moveShipsFromTo(numberShips%, startPlanet%, destinationPlanet%)
This is the top level PROC for setting movement orders.
This procedure should be called from outside the MovementOrders module
journeyTime%
eAjourneyTime% =
journeyTime(startPlanet%, destinationPlanet%)
newMovementOrder(CurrentSide%, CurrentTurn% + journeyTime%, numberShips%, destinationPlanet%)
g.PlanetShips%(startPlanet%) -= numberShips%
redrawWindowArea(OrdersWindow%, 0, -9000, 9000, -124)
journeyTime(startPlanet%, destinationPlanet%)
Calculates the number of turns to travel between the two planets
max(
distanceBetweenPlanets(startPlanet%, destinationPlanet%) / JourneySpeed%), 1)
newMovementOrder(side%, arrivalTurn%, numberShips%, destinationPlanet%)
Stores the details for a movementOrder. If there is a similar order already in
place then the two orders are merged, so the ships arrive in one large group
slot%, loop%, success%
success% =
loop% = 1
NumberMovementOrders%
(MovementOrders%(loop%, 0) = side%)
(MovementOrders%(loop%, 1) = arrivalTurn%)
(MovementOrders%(loop%, 3) = destinationPlanet%)
x1 MovementOrders%(loop%, 2) += numberShips%
success% =
loop%
success%
~$ slot% =
nextFreeMovementOrder
' MovementOrders%(slot%, 0) = side%
. MovementOrders%(slot%, 1) = arrivalTurn%
. MovementOrders%(slot%, 2) = numberShips%
4 MovementOrders%(slot%, 3) = destinationPlanet%
nextFreeMovementOrder
loop%
loop% = 1
NumberMovementOrders%
MovementOrders%(loop%, 0) = 0
=loop%
loop%
Have to 'add' another slot onto the end
NumberMovementOrders% += 1
NumberMovementOrders% > MaximumMovementOrders%
255,
messageLookupString("ErrFreeMov")
=NumberMovementOrders%
freeMovementOrder(slot%)
This blanks slot%, and if it is the last slot it travels
back through the slots trying to reduce NumberMovementOrders%
blankMovementOrder(slot%)
(slot% = NumberMovementOrders%)
slot% >= 2
NumberMovementOrders% -= 1
MovementOrders%(NumberMovementOrders%, 0) = 0
slot% -= 1
blankMovementOrder(slot%)
!MovementOrders%(slot%, 0) = 0
!MovementOrders%(slot%, 1) = 0
!MovementOrders%(slot%, 2) = 0
!MovementOrders%(slot%, 3) = 0
*************************************************************************** Next Turn
nextTurn
CurrentTurn% += 1
CurrentTurn%
20 = 0
Need to extend GraphBlock, by space for 20 more turns
extendHeapBlock(GraphBlock%, GraphSubBlockSize%)
diagnosis("Turn: "+
(CurrentTurn%)+"---------------------------------------------------")
shadeMenuItem(1, MainMenu%,
completeMovementOrders
Recalculate totals for use in StatisticsWindow
"Hourglass_On"
updatePlanetResources
updatePlanetShips
updateTotalPlanetShipsAverage
updateMovedShips
updatePlanetSides
updatePlanetSortedOnShips
updateGraph
WinnerContinue%
findWinner
EndOfTurn% =
shadeMenuItem(0, MainMenu%,
shadeMenuItem(1, MainMenu%,
updateWorldWindow(CurrentWorld%)
updateSideWindow(SideWindowSide%)
redrawWindow(OrdersWindow%)
redrawWindow(GraphWindow%)
redrawWindowArea(SortedPlanetsWindow%, 0, -9000, 1000, -64)
redrawWindowArea(StatisticsWindow%, 294, -1000, 1000, -68)
"Hourglass_Off"
!StartSide% =
(NumberSides%):
changeSides(StartSide%)
findWinner
Attempts to find if there is a winner this turn.
side%, winnerSide%, winnerTotal%, sideTotal%, totalToWin%
side% = 0
NumberSides%
+ totalToWin% += SideTotalShips%(side%)
/ totalToWin% += SideTotalResources%(side%)
side%
Winner needs more than 60% of total ships and resources
#totalToWin% = totalToWin% * 0.6
side% = 1
NumberSides%
F sideTotal% = SideTotalShips%(side%) + SideTotalResources%(side%)
(sideTotal% > totalToWin%)
(sideTotal% > winnerTotal%)
winnerSide% = side%
! winnerTotal% = sideTotal%
side%
winnerSide% <> 0
We have a winner
"Hourglass_Off"
startWinnerWindow(winnerSide%)
wimpPoll
WinnerContinue%
"Hourglass_On"
updatePlanetResources
loop%, newResources%, side%
SideTotalResources%() = 0
loop% = 1
NumberPlanets%
side% = PlanetSide(loop%)
side% > 0
D newResources% =
resourcesIncreaseTo(PlanetResources(loop%))
. PlanetResources(loop%) = newResources%
. newResources% = PlanetResources(loop%)
1 SideTotalResources%(side%) += newResources%
loop%
resourcesIncreaseTo(currentResources%)
Increases currentResources% by one turn
min(MaximumResources%,
max(currentResources% + 1, currentResources% * 1.05)) )
shipsIncreaseFromResourcesOver(currentResources%, turns%)
Predicts the extra ships gained due to resources over a number of turns%
loop%, shipsIncrease%
loop% = 1
turns%
B currentResources% +=
resourcesIncreaseTo(currentResources%)
1 shipsIncrease% += currentResources%
loop%
=shipsIncrease%
updatePlanetShips
loop%, newShips%, side%
SideTotalShips%() = 0
loop% = 1
NumberPlanets%
side% = PlanetSide(loop%)
side% > 0
G newShips% = (PlanetResources(loop%)
10) + PlanetShips%(loop%)
' PlanetShips%(loop%) = newShips%
' newShips% = PlanetShips%(loop%)
) SideTotalShips%(side%) += newShips%
loop%
updateTotalPlanetShipsAverage
planet%
TotalPlanetShipsAverage = 0
planet% = 1
NumberPlanets%
6 TotalPlanetShipsAverage += PlanetShips%(planet%)
planet%
"FTotalPlanetShipsAverage = TotalPlanetShipsAverage / NumberPlanets%
updatePlanetSides
loop%, side%
SideTotalPlanets%() = 0
loop% = 1
NumberPlanets%
side% = PlanetSide(loop%)
+# SideTotalPlanets%(side%) += 1
loop%
updateMovedShips
This just adds details for ships that are being moved to the
SideTotalShips%()
loop%, side%
loop% = 1
NumberMovementOrders%
5' side% = MovementOrders%(loop%, 0)
side% > 0
SideTotalShips%(side%) += MovementOrders%(loop%, 2)
loop%
updateGraph
loop%, totalShips%, totalResources%, totalPlanets%, graphPointer%
=GgraphPointer% = GraphBlock% + (GraphBlockEntrySize% * CurrentTurn%)
loop% = 0
NumberSides%
?. totalShips% = SideTotalShips%(loop%)
@2 totalResources% = SideTotalResources%(loop%)
A0 totalPlanets% = SideTotalPlanets%(loop%)
CH GraphDataMaximum%(0) =
max(totalShips%, GraphDataMaximum%(0))
DH GraphDataMaximum%(1) =
max(totalResources%, GraphDataMaximum%(1))
EH GraphDataMaximum%(2) =
max(totalPlanets%, GraphDataMaximum%(2))
G# graphPointer%!0 = totalShips%
H' graphPointer%!4 = totalResources%
I% graphPointer%!8 = totalPlanets%
graphPointer% += 12
loop%
updatePlanetSortedOnShips
Sort planets into increasing PlanetShips%()
loop%, minimum%, loop2%, nextPlanet%
loop%= 1
NumberPlanets% - 1
T: minimum% = PlanetShips%(PlanetSortedOnShips%(loop%))
loop2% = loop% + 1
NumberPlanets%
W2 nextPlanet% = PlanetSortedOnShips%(loop2%)
X0
PlanetShips%(nextPlanet%) < minimum%
YF
PlanetSortedOnShips%(loop%), PlanetSortedOnShips%(loop2%)
Z. minimum% = PlanetShips%(nextPlanet%)
[
loop2%
loop%
completeMovementOrders
Goes through all MovementOrders%(). Any that complete this turn are
processed then removed from the MovementOrders() list
loop%
Firstly all ships arriving at a planet they own, are added to that
planets ships stockpile before any battles are computed
loop% = 1
NumberMovementOrders%
(MovementOrders%(loop%, 0) > 0)
(MovementOrders%(loop%, 1) = CurrentTurn%)
iM
PlanetSide(MovementOrders%(loop%, 3)) = MovementOrders%(loop%, 0)
j!
movementArrival(loop%)
k
loop%
Now compute any battles
loop% = 1
NumberMovementOrders%
(MovementOrders%(loop%, 0) > 0)
(MovementOrders%(loop%, 1) = CurrentTurn%)
movementArrival(loop%)
loop%
Close BattleWindow% if it ever opened
closeWindow(BattleWindow%)
movementArrival(slot%)
A group of ships have arrived at their destination. They either add
themselves to the existing ships if the planet is theirs, or attack
it if not
planet%, arrivalSide%, planetSide%, arrivalNumber%, planetNumber%
.planet% = MovementOrders%(slot%, 3)
.arrivalSide% = MovementOrders%(slot%, 0)
(planetSide% = PlanetSide(planet%)
.arrivalNumber% = MovementOrders%(slot%, 2)
*planetNumber% = PlanetShips%(planet%)
arrivalSide% = planetSide%
- PlanetShips%(planet%) += arrivalNumber%
openWindow(BattleWindow%)
computeBattle(planet%, planetSide%, planetNumber%, arrivalSide%, arrivalNumber%)
freeMovementOrder(loop%)
computeBattle(planet%, planetSide%, planetShips%, arrivalSide%, arrivalShips%)
This calculates result of one battle, with Multitasking display of progress
wimpMask%, reason%, quit%, finishedBattle%, startTotalShips%
BattleWorld% = planet%
startBattleWindow(PlanetName$(planet%), planetSide%, planetShips%, arrivalSide%, arrivalShips%)
3startTotalShips% = planetShips% + arrivalShips%
"quit% =
: finishedBattle% =
%wimpMask% = %10011111110000110000
"Wimp_Poll", wimpMask%, WimpBlock%
reason%
reason%
7
nextBattleRound(planetShips%, arrivalShips%)
8
(planetShips% <= 0)
(arrivalShips% <= 0)
% wimpMask% = wimpMask%
finishedBattle% =
:
!
arrivalShips% > 0
E
successfulAttack(planet%, arrivalSide%, arrivalShips%)
8
unsuccessfulAttack(planet%, planetShips%)
8
shadeIndirectedIcon(BattleWindowOk%,
8
shadeIndirectedIcon(BattleWindowFinish%,
R
planetDamage(planet%, startTotalShips% - arrivalSide% - planetShips%)
!
redrawWindowRequest
/
"Wimp_OpenWindow",, WimpBlock%
/
"Wimp_CloseWindow",, WimpBlock%
.
WimpBlock%!12 = BattleWindow%
D
WimpBlock%!16 = 12
finishedBattle%
quit% =
c
(WimpBlock%!16 = 13)
finishedBattle%
finishBattle(planetShips%, arrivalShips%)
mouseButtonChange
keyPressed
menuSelect
17, 18:
userMessage
quit%
Quit%
PROCcloseWindow(BattleWindow%)
nextBattleRound(
planetShips%,
arrivalShips%)
This does the actual calculations of the combat. It works one shot
at the time, updating BattleWindow on the way for efficiency
total%
(planetShips% <= 0)
(arrivalShips% <= 0)
)total% = planetShips% + arrivalShips%
(total%) > planetShips%
planetShips% -= 1
writeIndirectedBuffer(BattleWindowCurrent1%,
(planetShips%))
arrivalShips% -= 1
writeIndirectedBuffer(BattleWindowCurrent2%,
(arrivalShips%))
finishBattle(
planetShips%,
arrivalShips%)
total%
(planetShips% > 1)
(arrivalShips% > 1)
+ total% = planetShips% + arrivalShips%
(total%) > planetShips%
planetShips% -=1
arrivalShips% -= 1
writeIndirectedBuffer(BattleWindowCurrent1%,
(planetShips%))
writeIndirectedBuffer(BattleWindowCurrent2%,
(arrivalShips%))
------------------------------------------------------------------ Outcome of attacks
successfulAttack(planet%, arrivalSide%, arrivalShips%)
&PlanetSide(planet%) = arrivalSide%
)PlanetShips%(planet%) = arrivalShips%
writeIndirectedBuffer(BattleWindowComment%,
messageLookupString("AWon"))
redrawPlanet(planet%)
unsuccessfulAttack(planet%, planetSide%)
'PlanetShips%(planet%) = planetSide%
writeIndirectedBuffer(BattleWindowComment%,
messageLookupString("DWon"))
redrawPlanet(planet%)
planetDamage(planet%, shipsDestroyed%)
If there has been a lot of damage, then it is possible to reduce
the resources of a planet becuase of the battle
planetDamage, resourcesLost%
XplanetDamage% =
min(shipsDestroyed% / 25, 25) / 100) * PlanetResources(planet%))
-PlanetResources(planet%) -= planetDamage%
-------------------------------------------------------------------------------- Bits
nextSide
This is called when the CurrentSide% has finished, and the next side
takes over control.
If all sides have had a go this turn then, the next turn will begin
newSide%
newSide% = CurrentSide% + 1
newSide% > NumberSides%
newSide% = 1
newSide% = StartSide%
PROCnextTurn
Need a Next Turn. Let user select it from MainMenu
Also redraw everything to update windows
shadeMenuItem(0, MainMenu%,
shadeMenuItem(1, MainMenu%,
EndOfTurn% =
messageLookup("EndTurn", MainWindowTitle%, 20)
redrawWindowTitle(MainWindow%)
wimpPoll
updateWorldWindow(CurrentWorld%)
changeSides(newSide%)
changeSides(newSide%)
CurrentSide% = newSide%
,$MainWindowTitle% = SideNames$(newSide%)
redrawWindowTitle(MainWindow%)
wimpPoll
computerMove(newSide%)
updatePlanetSortedOnShips
SidePlayer%(newSide%) = 0
Update displays if this player is a human.
Computers don't read the windows...
updateSideWindow(SideWindowSide%)
updateWorldWindow(CurrentWorld%)
redrawWindowArea(OrdersWindow%, 0, -9000, 9000, -124)
redrawWindow(GraphWindow%)
redrawWindowArea(SortedPlanetsWindow%, 0, -9000, 9000, -64)
updateSideWindow(SideWindowSide%)
*************************************************************************************
********************************************************************* Computer player
*************************************************************************************
computerMove(side%)
SidePlayer%(side%) <> 0
"Hourglass_On"
SideTotalPlanets%(side%) > 0
SidePlayer%(side%)
/%
cmoveMadAttacker(side%)
0/
cmoveRestrainedMadAttacker(side%)
1!
cmoveBuildUp(side%)
2"
cmoveBuildUp2(side%)
3
cmoveExpert(side%)
cmoveSp(side%)
"Hourglass_Off"
nextSide
Skip human if they are dead
(SideTotalShips%(side%) = 0)
(SideTotalPlanets%(side%) = 0)
nextSide
computerRequiredMemory(player%)
memory%
player%
3: memory% = 4
4: memory% = 4
5: memory% = 4
6: memory% = 12
=memory%
*************************************************************************************
************************************************************************ Mad Attacker
*************************************************************************************
cmoveMadAttacker(computerSide%)
This is a quick stab at a computer player.
Adds a bit of complexity to the game
loop%, loop2%, myShips%, transferShips%, tooStrong%, theirPlanet%
loop% = 1
NumberPlanets%
PlanetSide(loop%) = computerSide%
V' myShips% = PlanetShips%(loop%)
W :
X" loop2% = 0: tooStrong% =
Y
loop2% += 1
[5 theirPlanet% = PlanetSortedOnShips%(loop2%)
\7
PlanetSide(theirPlanet%) <> computerSide%
]I transferShips% =
calculateTransferShips(theirPlanet%, loop%)
^$
transferShips% <> -1
_+
transferShips% < myShips%
`E
moveShipsFromTo(transferShips%, loop%, theirPlanet%)
a. myShips% = PlanetShips%(loop%)
tooStrong% =
tooStrong%
loop%
*************************************************************************************
************************************************************* Restrained Mad Attacker
*************************************************************************************
cmoveRestrainedMadAttacker(computerSide%)
This is a quick stab at a computer player.
Adds a bit of complexity to the game
loop%, loop2%, myShips%, transferShips%, tooStrong%, theirPlanet%
loop% = 1
NumberPlanets%
PlanetSide(loop%) = computerSide%
w' myShips% = PlanetShips%(loop%)
x :
y" loop2% = 0: tooStrong% =
z
loop2% +=1
|5 theirPlanet% = PlanetSortedOnShips%(loop2%)
}7
PlanetSide(theirPlanet%) <> computerSide%
~I transferShips% =
calculateTransferShips(theirPlanet%, loop%)
$
transferShips% <> -1
k
(myShips% - transferShips% >= (PlanetResources(loop%)
2))
(transferShips% < myShips%)
E
moveShipsFromTo(transferShips%, loop%, theirPlanet%)
. myShips% = PlanetShips%(loop%)
tooStrong% =
tooStrong%
loop%
calculateTransferShips(planet%, fromPlanet%)
This attempts to calculate the number of ships that
are required to send to a planet to take it over.
Returns +inf if sufficient ships on their way
requiredShips%, loop%, inf%, currentShips%
5requiredShips% = PlanetShips%(planet%) * 1.25 + 2
loop% = 1
NumberMovementOrders%
(MovementOrders%(loop%, 0) = CurrentSide%)
(MovementOrders%(loop%, 3) = planet%)
(
Ships are going, but how many?
1 currentShips% = MovementOrders%(loop%, 2)
+
currentShips% >= requiredShips%
=-1
L
Boost quantity of ships if arrive at time date and are necessary
}
journeyTime(fromPlanet%, planet%) = (MovementOrders%(loop%, 1) - CurrentTurn%)
=requiredShips% - currentShips%
loop%
=requiredShips%
*************************************************************************************
**************************************************************************** Build Up
*************************************************************************************
cmoveBuildUp(computerSide%)
The idea of this computer player is that it tries to keep hold of its
planets by leaving a fair number on there. The excess ships it moves
to a central planet. From here it decides what to attack.
centralPlanet%, planet%, loop%, freeShips%, requiredShips%, resourceShips%
8centralPlanet% = !(ComputerBlockPtr%(computerSide%))
Ensure the centralPlanet is still ours, if not, find our planet with
the highest number of ships on it. Making it our new central planet
PlanetSide(centralPlanet%) <> computerSide%
loop% = NumberPlanets% + 1
loop% -= 1
- planet% = PlanetSortedOnShips%(loop%)
PlanetSide(planet%) = computerSide%
3 !(ComputerBlockPtr%(computerSide%)) = planet%
centralPlanet% = planet%
Send any excess ships to central planet. Make sure that the number
of ships left is at least 1/6 of PlanetResources() or 2/3 TotalPlanetShipsAverage
planet% = 1
NumberPlanets%
(PlanetSide(planet%) = computerSide%)
(planet% <> centralPlanet%)
freeShips% =
min(PlanetShips%(planet%) - ((2 / 3) * TotalPlanetShipsAverage), PlanetShips%(planet%) - (PlanetResources(planet%) * 0.6))
freeShips% > 0
?
moveShipsFromTo(freeShips%, planet%, centralPlanet%)
planet%
Now possibly move any excess held at central planet.
Keep more ships at home base because of its importance
WfreeShips% = PlanetShips%(centralPlanet%) - (PlanetResources(centralPlanet%) * 0.7)
loop% = 0
loop% += 1
! planet% =
(NumberPlanets%)
N requiredShips% =
calculateTransferShipsBuildUp(planet%, centralPlanet%)
(loop% = 4)
((requiredShips% <= freeShips%)
(requiredShips% <> -1))
If we can, send the ships off. Good luck!!
But we may also send off more ships than is required because of
the planets large resources.
(requiredShips% <= freeShips%)
(freeShips% > 0)
5 resourceShips% = PlanetResources(planet%) * 0.6
resourceShips% >= freeShips%
# requiredShips% = freeShips%
K
resourceShips% > requiredShips%
requiredShips% = resourceShips%
moveShipsFromTo(requiredShips%, centralPlanet%, planet%)
calculateTransferShipsBuildUp(planet%, centralPlanet%)
This calculates how many ships will have to be sent to planet% to take
it over from centralPlanet%
loop%, side%
&side% = PlanetSide(centralPlanet%)
PlanetSide(planet%) <> side%
loop% = 1
NumberMovementOrders%
W
(MovementOrders%(loop%, 0) = side%)
(MovementOrders%(loop%, 3) = planet%)
E
We have already sent ships there. Forget it at this stage
= -1
loop%
There are no troops on the way, therefore calculate a value
( (PlanetShips%(planet%) +
shipsIncreaseFromResourcesOver(PlanetResources(planet%),
journeyTime(centralPlanet%, planet%))) * 1.3 )
= -1
*************************************************************************************
************************************************************************** Build Up 2
*************************************************************************************
cmoveBuildUp2(computerSide%)
The idea of this computer player is that it tries to keep hold of its
planets by leaving a fair number on there. The excess ships it moves
to a central planet. From here it decides what to attack.
This includes a number of 'improvements' over BuildUp
centralPlanet%, planet%, loop%, freeShips%, requiredShips%, resourceShips%, planetShips%
repeatTimes%
8centralPlanet% = !(ComputerBlockPtr%(computerSide%))
Ensure the centralPlanet is still ours, if not, find our planet with
the highest number of ships on it. Making it our new central planet
PlanetSide(centralPlanet%) <> computerSide%
loop% = NumberPlanets% + 1
loop% -= 1
- planet% = PlanetSortedOnShips%(loop%)
PlanetSide(planet%) = computerSide%
3 !(ComputerBlockPtr%(computerSide%)) = planet%
centralPlanet% = planet%
Send any excess ships to central planet. Make sure that the number
of ships left is at least 1/6 of PlanetResources() or 2/3 TotalPlanetShipsAverage
If ships are coming this way may have to retreat to centralPlanet, or build up
ships on the planet
planet% = 1
NumberPlanets%
(PlanetSide(planet%) = computerSide%)
(planet% <> centralPlanet%)
, planetShips% = PlanetShips%(planet%)
~ freeShips% =
min(planetShips% - ((2 / 3) * TotalPlanetShipsAverage), planetShips% - (PlanetResources(planet%) * 0.6))
:
requiredShips% = 0
+
loop% = 1
NumberMovementOrders%
b
(MovementOrders%(loop%, 0) <> computerSide%)
(MovementOrders%(loop%, 3) = planet%)
S requiredShips% =
max(MovementOrders%(loop%, 2), requiredShips% * 1.10)
loop%
:
+
(planetShips% < requiredShips%)
2
planetShips% * 1.10 < requiredShips%
C
moveShipsFromTo(planetShips%, planet%, centralPlanet%)
"
#O freeShips% =
min(planetShips% - (requiredShips% * 1.10), freeShips%)
$R
freeShips% > 0
moveShipsFromTo(freeShips%, planet%, centralPlanet%)
%
planet%
Now possibly move any excess held at central planet.
Keep more ships at home base because of its importance
+0loop% = 0: repeatTimes% = NumberPlanets% / 4
loop% += 1
.Y freeShips% = PlanetShips%(centralPlanet%) - (PlanetResources(centralPlanet%) * 0.7)
/! planet% =
(NumberPlanets%)
0O requiredShips% =
calculateTransferShipsBuildUp2(planet%, centralPlanet%)
requiredShips% >= 0
34
If we can, send the ships off. Good luck!!
4I
But we may also send off more ships than is required because of
5&
the planets large resources.
6I
Try to get at least 2/3 of TotalPlanetShipsAverage after battle
7=
(requiredShips% <= freeShips%)
(freeShips% > 0)
8b resourceShips% =
max(PlanetResources(planet%) * 0.6, (2 / 3) * TotalPlanetShipsAverage)
9*
resourceShips% >= freeShips%
:' requiredShips% = freeShips%
<O
resourceShips% > requiredShips%
requiredShips% = resourceShips%
:
?C
moveShipsFromTo(requiredShips%, centralPlanet%, planet%)
@
(loop% = repeatTimes%)
calculateTransferShipsBuildUp2(planet%, centralPlanet%)
This calculates how many ships will have to be sent to planet% to take
it over from centralPlanet%
This also takes into account the number of ships from other sides
heading for the planet
loop%, side%, transitShips%
L&side% = PlanetSide(centralPlanet%)
PlanetSide(planet%) <> side%
loop% = 1
NumberMovementOrders%
O1
(MovementOrders%(loop%, 3) = planet%)
P/
MovementOrders%(loop%, 0) = side%
QG
We have already sent ships there. Forget it at this stage
= -1
TI
another side is sending ships. Have to send more than them!
UJ transitShips% =
max(MovementOrders%(loop%, 2), transitShips%)
W
loop%
There are no troops on the way, therefore calculate a value
max( PlanetShips%(planet%) +
shipsIncreaseFromResourcesOver(PlanetResources(planet%),
journeyTime(centralPlanet%, planet%)), transitShips%) * 1.3 )
= -1
*************************************************************************************
****************************************************************************** Expert
*************************************************************************************
cmoveExpert(computerSide%)
This is another computer player, set out on a depth first, backtracking (???)
Expet System style.
Hopefully is the best computer player
ourPlanets%()
planets%, totalPlanets%, central%
j4totalPlanets% = SideTotalPlanets%(computerSide%)
l>ExpPlanet = 0: ExpShipsRequired = 1: ExpShipsAvailable = 2
ourPlanets%(totalPlanets%, 2)
expGetPlanetData(computerSide%, ourPlanets%())
expDefensiveMoves(ourPlanets%(), central%)
expAttackingMoves(ourPlanets%(), central%)
expGetPlanetData(side%,
ourPlanets%())
This fills ourPlanets%() with the necessary information for later
stages of the 'Experts' turn
expGetOurPlanets(side%, ourPlanets%())
expAvailableShips(ourPlanets%())
expRequiredShips(ourPlanets%())
expGetOurPlanets(side%,
ourPlanets%())
This stores all the planets owned by the Expert in ourPlanets%()
planet%, ourPlanet%
planet% = 1
NumberPlanets%
PlanetSide(planet%) = side%
ourPlanet% += 1
4 ourPlanets%(ourPlanet%, ExpPlanet) = planet%
planet%
expAvailableShips(
ourPlanets%())
This records for each of our planets, the difference between the
number of ships there and the number of ships that we would like
to be there, to help prevent against new attacks
loop%, planet%, requiredShips%
loop% = 1
(ourPlanets%(), 1)
- planet% = ourPlanets%(loop%, ExpPlanet)
: requiredShips% =
expRequiredDefensiveShips(planet%)
T ourPlanets%(loop%, ExpShipsAvailable) = PlanetShips%(planet%) - requiredShips%
loop%
expRequiredShips(
ourPlanets%())
This records for each of our planets, the number of extra ships
that are required to defend successfully against known attacks
arriving next turn
loop%, planet%, order%, requiredShips%, fiddleAvailable%
loop% = 1
(ourPlanets%(), 1)
- planet% = ourPlanets%(loop%, ExpPlanet)
requiredShips% = 0
order% = 1
NumberMovementOrders%
W requiredShips% =
expRequiredShipsOrders(order%, planet%), requiredShips%)
order%
requiredShips% > 0
j requiredShips% = (requiredShips% * 1.2) - PlanetShips%(planet%) -
expOurShipsArrivingNow(planet%)
requiredShips% >= 0
@ ourPlanets%(loop%, ExpShipsRequired) = requiredShips%
3 ourPlanets%(loop%, ExpShipsAvailable) = 0
S fiddleAvailable% = requiredShips% + ourPlanets%(loop%, ExpShipsAvailable)
`
fiddleAvailable% > 0
ourPlanets%(loop%, ExpShipsAvailable) -= fiddleAvailable%
loop%
expOurShipsArrivingNow(planet%)
This is the amount of ships that are arriving this coming
turn at ourPlanet%, that are on our side
order%, ships%
order% = 1
NumberMovementOrders%
MovementOrders%(order%, OrderPlanet) = planet%
D
MovementOrders%(order%, OrderSide) = PlanetSide(planet%)
G
MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1
9 ships% += MovementOrders%(order%, OrderShips)
order%
=ships%
expRequiredShipsOrders(order%, planet%)
IF the ships of this order are to attack this planet, next turn, then
the number of ships necessary to defend the planet well is returned
MovementOrders%(order%, OrderPlanet) = planet%
MovementOrders%(order%, OrderSide) <> PlanetSide(planet%)
E
MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1
/ = MovementOrders%(order%, OrderShips)
expRequiredDefensiveShips(planet%)
Result is the number of ships required to deter an average
attack against the planet
max((2 / 3) * TotalPlanetShipsAverage, PlanetResources(planet%) * 0.6)
expDefensiveMoves(
ourPlanets%(),
central%)
This attempts to ensure that any planets under attack can be either
sent enough ships to withstand the attack, or retreat if need be
loop%, numberOurPlanets%
+numberOurPlanets% =
(ourPlanets%(), 1)
loop% = 1
numberOurPlanets%
ourPlanets%(loop%, ExpShipsRequired) > 0
expGetReinforcements(loop%, ourPlanets%())
loop%
loop% = 1
numberOurPlanets%
ourPlanets%(loop%, ExpShipsAvailable) < -
shipsIncreaseFromResourcesOver(PlanetResources(ourPlanets%(loop%, ExpPlanet)), 1)
expGetBackup(loop%, ourPlanets%())
loop%
/central% =
expCentralPlanet(ourPlanets%())
loop% = 1
numberOurPlanets%
(ourPlanets%(loop%, ExpShipsAvailable) > 0)
(central% <> loop%)
moveShipsFromTo(ourPlanets%(loop%, ExpShipsAvailable), ourPlanets%(loop%, ExpPlanet), ourPlanets%(central%, ExpPlanet))
loop%
expGetReinforcements(attacked%,
ourPlanets%())
This attempts to get reinforcements from our surrounding planets,
that will ensure we have enough ships to defeat an attack. If
possible to ensure the defending force has up to 120% the sorce
of the attacker
loop%, planet%, attackedPlanet%, takeShips%(), takeShipsFraction, takenShips%, totalShips%, requiredShips%, maxRequiredShips%
7attackedPlanet% = ourPlanets%(attacked%, ExpPlanet)
takeShips%(
(ourPlanets%(), 1) )
loop% = 1
(ourPlanets%(), 1)
- planet% = ourPlanets%(loop%, ExpPlanet)
planet% <> attackedPlanet%
f
journeyTime(attackedPlanet%, planet%) = 1)
(ourPlanets%(loop%, ExpShipsAvailable) > 0)
C takeShips%(loop%) = ourPlanets%(loop%, ExpShipsAvailable)
loop%
'totalShips% =
takeShips%()
@requiredShips% = ourPlanets%(attacked%, ExpShipsRequired)
totalShips% >= requiredShips%
6 takeShipsFraction = requiredShips% / totalShips%
loop% = 1
(ourPlanets%(), 1)
; takenShips% = takeShips%(loop%) * takeShipsFraction
takenShips% > 0
> ourPlanets%(loop%, ExpShipsAvailable) -= takenShips%
W
moveShipsFromTo(takenShips%, ourPlanets%(loop%, ExpPlanet), attackedPlanet%)
loop%
3 ourPlanets%(attacked%, ExpShipsRequired) = 0
Planet can't be saved. Escape
4 ourPlanets%(attacked%, ExpShipsRequired) = -1
O ourPlanets%(attacked%, ExpShipsAvailable) = PlanetShips%(attackedPlanet%)
Attempt to attack a planet with the ShipsAvailable
expAttackingMoves(ourPlanets%(), attacked%)
expGetBackup(defend%,
ourPlanets%())
defendPlanet%, requiredShips%, loop%, takeShipsFraction, takenShips%, planet%
takeShips%()
4defendPlanet% = ourPlanets%(defend%, ExpPlanet)
requiredShips% = -(ourPlanets%(defend%, ExpShipsAvailable) +
shipsIncreaseFromResourcesOver(PlanetResources(defendPlanet%), 1))
takeShips%(
(ourPlanets%(), 1) )
loop% = 1
(ourPlanets%(), 1)
- planet% = ourPlanets%(loop%, ExpPlanet)
planet% <> defendPlanet%
d
journeyTime(defendPlanet%, planet%) = 1)
(ourPlanets%(loop%, ExpShipsAvailable) > 0)
!C takeShips%(loop%) = ourPlanets%(loop%, ExpShipsAvailable)
"
loop%
&CtakeShipsFraction =
min(
takeShips%() / requiredShips%, 1 )
loop% = 1
(ourPlanets%(), 1)
(- planet% = ourPlanets%(loop%, ExpPlanet)
planet% <> defendPlanet%
*; takenShips% = takeShips%(loop%) * takeShipsFraction
takenShips% > 0
,> ourPlanets%(loop%, ExpShipsAvailable) -= takenShips%
-?
moveShipsFromTo(takenShips%, planet%, defendPlanet%)
.
loop%
expAttackingMoves(
ourPlanets%(), central%)
loop%, theirPlanet%
theirPlanets%()
theirPlanets%( NumberPlanets% -
(ourPlanets%(), 1), 1 )
loop% = 1
NumberPlanets%
PlanetSide(loop%) <> CurrentSide%
theirPlanet% += 1
<. theirPlanets%(theirPlanet%, 0) = loop%
=h theirPlanets%(theirPlanet%, 1) =
expAttackValue(theirPlanet%, ourPlanets%(central%, ExpPlanet))
loop%
expSortAttackValues(theirPlanets%())
expDecideAttacks(ourPlanets%(), theirPlanets%(), central%)
expSortAttackValues(
theirPlanets%())
loop%, loop2%, max%, number%
H#number% =
(theirPlanets%(), 1)
number% > 1
loop% = 1
number% - 1
K$ max% = theirPlanets%(loop%, 1)
loop2% = loop% + 1
number%
N+
theirPlanets%(loop2%, 1) > max%
O>
theirPlanets%(loop2%, 0), theirPlanets%(loop%, 0)
P>
theirPlanets%(loop2%, 1), theirPlanets%(loop%, 1)
Q( max% = theirPlanets%(loop%, 1)
R
loop2%
loop%
expDecideAttacks(
ourPlanets%(), theirPlanets%(), our%)
freeShips%, loop%, requiredShips%, ourPlanet%, planet%
[-ourPlanet% = ourPlanets%(our%, ExpPlanet)
\5freeShips% = ourPlanets%(our%, ExpShipsAvailable)
loop% = 1
(freeShips% > 0)
(loop% <=
(theirPlanets%(), 1))
(theirPlanets%(loop%, 1) <> -1)
`' planet% = theirPlanets%(loop%, 0)
a\ requiredShips% =
calculateTransferShipsBuildUp2(planet%, ourPlanet%):
changed our%)
(freeShips% >= requiredShips%)
(requiredShips% <> -1)
c=
moveShipsFromTo(requiredShips%, ourPlanet%, planet%)
d$ freeShips% -= requiredShips%
loop% += 1
i5ourPlanets%(our%, ExpShipsAvailable) = freeShips%
expAttackValue(planet%, centralPlanet%)
This returns a value that signifies its take over value.
This is based on the number of ships relative to number of resources
Should also take into account distance, but not yet
ships%, timeMultiplier
rMships% =
calculateTransferShipsBuildUp2(planet%, centralPlanet%)
sLtimeMultiplier = MaxJourneyTime% /
journeyTime(planet%, centralPlanet%)
ships% = -1
= -1
ships% = 0
w6 =(PlanetResources(planet%) ^ 2) * timeMultiplier
yB =((PlanetResources(planet%) ^ 2 ) / ships%) * timeMultiplier
expCentralPlanet(ourPlanets%())
This returns the central for this side. If it has been
taken over, or will be taken over this turn, then it is changed
to the planet with the highest availableShips
side%, central%, loop%, maxPlanet%, maxShips%
@central% =
expGetCentralPlanet(CurrentSide%, ourPlanets%())
central% = -1
We have to find a new planet
( maxPlanet% = -1: maxShips% = -9999
loop% = 1
(ourPlanets%(), 1)
=
ourPlanets%(loop%, ExpShipsAvailable) > maxShips%
O maxPlanet% = loop%: maxShips% = ourPlanets%(loop%, ExpShipsAvailable)
loop%
M !(ComputerBlockPtr%(CurrentSide%)) = ourPlanets%(maxPlanet%, ExpPlanet)
= maxPlanet%
= central%
expGetCentralPlanet(side%, ourPlanets%())
Returns the ourPlanets%() index of centralPlanet.
Returns -1 if it is not our planet anymore, or it will
be taken over most probably this turn
centralPlanet%, loop%
0centralPlanet% = !(ComputerBlockPtr%(side%))
loop% = 1
(ourPlanets%(), 1)
ourPlanets%(loop%, ExpPlanet) = centralPlanet%
B
ourPlanets%(loop%, ExpShipsRequired) <> 0
=-1
=loop%
loop%
*************************************************************************************
************************************************************************ Super Player
*************************************************************************************
cmoveSp(computerSide%)
This is another computer player
Hopefully better than the previous "Expert Player"
ourPlanets%(), totalPlanets%
attackFrom%, attackPlanet%
4totalPlanets% = SideTotalPlanets%(computerSide%)
>ExpPlanet = 0: ExpShipsRequired = 1: ExpShipsAvailable = 2
ourPlanets%(totalPlanets%, 2)
spGetPlanetsData(computerSide%, ourPlanets%())
spGetAttackPlanet(computerSide%, ourPlanets%(), attackFrom%, attackPlanet%)
spDefensiveMoves(ourPlanets%(), attackFrom%, attackPlanet%)
spAttackMove(computerSide%, ourPlanets%(), attackFrom%, attackPlanet%)
------------------------------------------------------------------- Get Attack Planet
spWriteAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
This stores the information so it can be used in future turns.
Only used by THIS computer "super player"
7!(ComputerBlockPtr%(side%)) = attackFromPlanet%
3!(ComputerBlockPtr%(side%) + 4) = attackPlanet%
0!(ComputerBlockPtr%(side%) + 8) = startTurn%
spClearAttackDetails(side%)
This changes,and storesm the stored variables to "undefined" values
spWriteAttackDetails(side%, -1, -1, -1)
spReadAttackDetails(side%,
attackFromPlanet%,
attackPlanet%,
startTurn%)
This reads the stored information
3attackFromPlanet% = !(ComputerBlockPtr%(side%))
7attackPlanet% = !(ComputerBlockPtr%(side%) + 4)
7startTurn% = !(ComputerBlockPtr%(side%) + 8)
spGiveUpAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
This checks to see whether it is worth continuing against this target
changeAttack%
changeAttack% =
spTimeOutAttack(startTurn%)
spAttackFromChangeOwnership(side%, attackFromPlanet%)
(attackFromPlanet% = -1)
= changeAttack%
spTimeOutAttack(startTurn%)
Gives up an attackPlanet if we have spent too long building up for it
(CurrentTurn% - startTurn%) > 3
spAttackFromChangeOwnership(side%, attackFromPlanet%)
If the starting planet is not ours any more, then we
can't build up from there
attackFromPlanet% <> -1
PlanetSide(attackFromPlanet%) <> side%
spGetAttackPlanet(side%, ourPlanets%(),
attackFrom%,
attackPlanet%)
This aims to find a planet to attack, and a planet to
build up the attack force from.
attackFromPlanet%, startTurn% :
Integer
changeAttack% :
Boolean
spReadAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
_changeAttack% =
spGiveUpAttackDetails(side%, attackFromPlanet%, attackPlanet%, startTurn%)
changeAttack%
spGetNewAttackPlanet(side%, ourPlanets%(), attackFromPlanet%, attackPlanet%)
6attackFrom% =
spAllToMyPlanets(attackFromPlanet%)
diagnosis("Attack Planet: " + PlanetName$(attackPlanet%))
diagnosis("Attack from Planet: " + PlanetName$(attackFromPlanet%))
spGetNewAttackPlanet(side%, ourPlanets%(),
attackFromPlanet%,
attackPlanet%)
This finds a new set of attackFromPlanet, attackPlanet.
Updates stored details
checkPlanets%(), planets%
checkPlanets%(NumberPlanets%, 1)
spGetAttackPlanetsList(side%, checkPlanets%(), planets%)
spChooseAttackPlanet(checkPlanets%(), planets%, attackFromPlanet%, attackPlanet%)
spWriteAttackDetails(side%, attackFromPlanet%, attackPlanet%, CurrentTurn%)
spGetAttackPlanetsList(side%,
checkPlanets%(),
planets%)
This creates a list of possible pairs = (attackFrom%, attackPlanet%)
Unordered at present
attackDistance%, attackFrom%, attackFromPlanet%, attackPlanet%
loop%, found%
planets% = 0
attackDistance% += 1
attackFrom% = 1
(ourPlanets%(), 1)
? attackFromPlanet% = ourPlanets%(attackFrom%, ExpPlanet)
,
attackPlanet% = 1
NumberPlanets%
w
(PlanetSide(attackPlanet%) <> side%)
journeyTime(attackFromPlanet%, attackPlanet%) = attackDistance%)
:
! loop% = 1: found% =
-
(loop% <= planets%)
found%
9
checkPlanets%(loop%, 1) = attackPlanet%
y
ourPlanets%(attackFrom%, ExpShipsAvailable) > ourPlanets%(checkPlanets%(loop%, 0), ExpShipsAvailable)
7 checkPlanets%(loop%, 0) = attackFrom%
found% =
loop% += 1
found%
planets% += 1
#6 checkPlanets%(planets%, 0) = attackFrom%
$8 checkPlanets%(planets%, 1) = attackPlanet%
attackPlanet%
attackFrom%
spChooseAttackPlanet(checkPlanets%(), planets%,
attackFromPlanet%,
attackPlanet%)
This chooses one pair of (attackFrom%, attackPlanet%) from the list
of possible ones
availShips%, newAvailShips%, loop%
planets% > 1
Find planet with largest ships which we can take with AvailableShips
4k availShips% = ourPlanets%(checkPlanets%(1, 0), ExpShipsAvailable) - PlanetShips%(checkPlanets%(1, 1))
loop% = 2
planets%
6x newAvailShips% = ourPlanets%(checkPlanets%(loop%, 0), ExpShipsAvailable) - PlanetShips%(checkPlanets%(loop%, 1))
7(
newAvailShips% > availShips%
89
checkPlanets%(1, 0), checkPlanets%(loop%, 0)
99
checkPlanets%(1, 1), checkPlanets%(loop%, 1)
:& availShips% = newAvailShips%
;
loop%
?CattackFromPlanet% = ourPlanets%(checkPlanets%(1, 0), ExpPlanet)
@7attackPlanet% = checkPlanets%(1, 1)
spAllToMyPlanets(planet%)
This converts a plant id from Planets(planet%) to ourPlanets%()
loop%
loop% += 1
ourPlanets%(loop%, ExpPlanet) = planet%
=loop%
------------------------------------------------------------------ Get Planet Details
spGetPlanetsData(side%,
ourPlanets%())
This fills ourPlanets%() with the necessary information for later
stages of the 'Experts' turn
spGetOurPlanets(side%, ourPlanets%())
spAvailableShips(ourPlanets%())
spRequiredShips(ourPlanets%())
spGetOurPlanets(side%,
ourPlanets%())
This stores all the planets owned by the Super Player in ourPlanets%()
planet%, ourPlanet%
planet% = 1
NumberPlanets%
PlanetSide(planet%) = side%
ourPlanet% += 1
`4 ourPlanets%(ourPlanet%, ExpPlanet) = planet%
planet%
spAvailableShips(
ourPlanets%())
This records for each of our planets, the difference between the
number of ships there and the number of ships that we would like
to be there, to help prevent against new attacks.
our%, ourPlanet%, requiredShips%
our% = 1
(ourPlanets%(), 1)
m/ ourPlanet% = ourPlanets%(our%, ExpPlanet)
n< requiredShips% =
spRequiredDeterrentShips(ourPlanet%)
oV ourPlanets%(our%, ExpShipsAvailable) = PlanetShips%(ourPlanet%) - requiredShips%
our%
spRequiredDeterrentShips(planet%)
Result is the number of ships required to deter an average
attack against the planet
max(PlanetShips%(PlanetSortedOnShips%(NumberPlanets% / 4)) + 1, PlanetResources(planet%) * 0.6)
spRequiredTotalDefensiveShips(planet%)
Answer is the number of ships that are needed to adequately defend
against an actual attack on planet%
order%, ships%
order% = 1
NumberMovementOrders%
7 ships% +=
spRequiredShipsOrders(order%, planet%)
order%
= ships% * 1.3
spRequiredDefensiveShips(our%, requiredShips%,
ourPlanets%())
This sets the number of extra ships a planet needs to successfully
defend an attack.
ourPlanet%, fiddleAvailable%
-ourPlanet% = ourPlanets%(our%, ExpPlanet)
requiredShips% >= 0
. ourPlanets%(our%, ExpShipsAvailable) = 0
T fiddleAvailable% =
min(-requiredShips%, ourPlanets%(our%, ExpShipsAvailable))
m ourPlanets%(our%, ExpShipsAvailable) =
max(0, ourPlanets%(our%, ExpShipsAvailable) - fiddleAvailable%)
requiredShips% = 0
=requiredShips%
spRequiredShips(
ourPlanets%())
This records for each of our planets, the number of extra ships
that are required to defend successfully against known attacks
arriving next turn
our%, ourPlanet%, requiredShips%
our% = 1
(ourPlanets%(), 1)
/ ourPlanet% = ourPlanets%(our%, ExpPlanet)
A requiredShips% =
spRequiredTotalDefensiveShips(ourPlanet%)
requiredShips% > 0
g requiredShips% = requiredShips% - PlanetShips%(ourPlanet%) -
spOurShipsArrivingNow(ourPlanet%)
W requiredShips% =
spRequiredDefensiveShips(our%, requiredShips%, ourPlanets%())
; ourPlanets%(our%, ExpShipsRequired) = requiredShips%
our%
spOurShipsArrivingNow(planet%)
This is the amount of ships that are arriving this coming
turn at ourPlanet%, that are on our side
order%, ships%
order% = 1
NumberMovementOrders%
MovementOrders%(order%, OrderPlanet) = planet%
D
MovementOrders%(order%, OrderSide) = PlanetSide(planet%)
G
MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1
9 ships% += MovementOrders%(order%, OrderShips)
order%
=ships%
spRequiredShipsOrders(order%, planet%)
IF the ships of this order are to attack this planet, next turn, then
the number of ships necessary to defend the planet well is returned
MovementOrders%(order%, OrderPlanet) = planet%
MovementOrders%(order%, OrderSide) <> PlanetSide(planet%)
E
MovementOrders%(order%, OrderArriving) = CurrentTurn% + 1
/ = MovementOrders%(order%, OrderShips)
--------------------------------------------------------------------- Defensive Moves
spDefensiveMoves(
ourPlanets%(), attackFrom%, attackPlanet%)
This attempts to ensure that any planets under attack can be either
sent enough ships to withstand the attack, or retreat if need be
spFindOppositionAttacks(ourPlanets%())
spFindOurWeakPlanets(ourPlanets%())
spMoveExcessShips(ourPlanets%(), attackFrom%)
spFindOppositionAttacks(
ourPlanets%())
Examines all our planets looking for ones that are being attacked
and need assistance. Attempt to send assistance
our%, numberOurPlanets%
+numberOurPlanets% =
(ourPlanets%(), 1)
our% = 1
numberOurPlanets%
ourPlanets%(our%, ExpShipsRequired) > 0
diagnosis(PlanetName$(ourPlanets%(our%, ExpPlanet))+ " needs "+
(ourPlanets%(our%, ExpShipsRequired))+" reinforcements to withstand attack")
1
spGetReinforcements(our%, ourPlanets%())
our%
spFindOurWeakPlanets(
ourPlanets%())
This finds all our planets that could be targets because of their
low number of ships in defence and boost it to appropriate levels
our%, ourPlanet%, numberOurPlanets%
+numberOurPlanets% =
(ourPlanets%(), 1)
our% = 1
numberOurPlanets%
ourPlanets%(our%, ExpShipsAvailable) < 0
1 ourPlanet% = ourPlanets%(our%, ExpPlanet)
diagnosis(PlanetName$(ourPlanet%)+" needs "+
(-ourPlanets%(our%, ExpShipsAvailable))+" extra ships to dissuade future attacks")
)
spGetBackup(our%, ourPlanets%())
our%
spMoveExcessShips(
ourPlanets%(), attackFrom%)
This moves any available ships to attackFromPlanet% so they can be
used in the next offensive
our%, ourPlanet%, numberOurPlanets%, attackFromPlanet%
+numberOurPlanets% =
(ourPlanets%(), 1)
;attackFromPlanet% = ourPlanets%(attackFrom%, ExpPlanet)
our% = 1
numberOurPlanets%
(ourPlanets%(our%, ExpShipsAvailable) > 0)
(attackFrom% <> our%)
1 ourPlanet% = ourPlanets%(our%, ExpPlanet)
]
moveShipsFromTo(ourPlanets%(our%, ExpShipsAvailable), ourPlanet%, attackFromPlanet%)
k
PROCdiagnosis("Excess troops from "+PlanetName$(ourPlanet%)+" to "+PlanetName$(attackFromPlanet%))
our%
spGetReinforcements(attacked%,
ourPlanets%())
This attempts to get reinforcements from our surrounding planets,
that will ensure we have enough ships to defeat an attack.
attackedPlanet%, numberOurPlanets%, our%
takeShips%()
totalShips%, requiredShips%, takeShipsFraction, takenShips%, totalTakenShips%
9attackedPlanet% = ourPlanets%(attacked%, ExpPlanet)
+numberOurPlanets% =
(ourPlanets%(), 1)
takeShips%(numberOurPlanets%)
spSupplyAvailableShips(attackedPlanet%, ourPlanets%(), takeShips%())
@requiredShips% = ourPlanets%(attacked%, ExpShipsRequired)
'totalShips% =
takeShips%()
totalShips% >= requiredShips%
6 takeShipsFraction = requiredShips% / totalShips%
our% = 1
numberOurPlanets%
B takenShips% =
round(takeShips%(our%) * takeShipsFraction)
' totalTakenShips% += takenShips%
takenShips% > 0
= ourPlanets%(our%, ExpShipsAvailable) -= takenShips%
V
moveShipsFromTo(takenShips%, ourPlanets%(our%, ExpPlanet), attackedPlanet%)
our%
diagnosis("Here comes the cavalry with "+
(totalTakenShips%))
Planet can't be saved. Escape
diagnosis(PlanetName$(attackedPlanet%)+" can't be saved. Escape, Escape!!")
%O ourPlanets%(attacked%, ExpShipsAvailable) = PlanetShips%(attackedPlanet%)
(1ourPlanets%(attacked%, ExpShipsRequired) = 0
spSupplyAvailableShips(destinationPlanet%, ourPlanets%(),
takeShips%())
This sees how many available ships are within 1 distance of the
planet
our%, ourPlanet%, numberOurPlanets%
1+numberOurPlanets% =
(ourPlanets%(), 1)
our% = 1
numberOurPlanets%
3/ ourPlanet% = ourPlanets%(our%, ExpPlanet)
ourPlanet% <> destinationPlanet%
5k
journeyTime(destinationPlanet%, ourPlanet%) = 1)
(ourPlanets%(our%, ExpShipsAvailable) > 0)
6A takeShips%(our%) = ourPlanets%(our%, ExpShipsAvailable)
7
our%
spGetBackup(defend%,
ourPlanets%())
this attempts to get available ships from nearby planets to
stop the planet looking such an easy target
defendPlanet%, requiredShips%, numberOurPlanets%, takeShips%()
totalShips%, takeShipsFraction, our%, ourPlanet%, takenShips%, totalTakenShips%
C5defendPlanet% = ourPlanets%(defend%, ExpPlanet)
D=requiredShips% = -ourPlanets%(defend%, ExpShipsAvailable)
E+numberOurPlanets% =
(ourPlanets%(), 1)
takeShips%(numberOurPlanets%)
spSupplyAvailableShips(defendPlanet%, ourPlanets%(), takeShips%())
J!totalShips% =
takeShips%()
totalShips% = 0
diagnosis("No ships available to backup "+PlanetName$(defendPlanet%))
N? takeShipsFraction =
min(requiredShips% / totalShips%, 1)
our% = 1
numberOurPlanets%
P1 ourPlanet% = ourPlanets%(our%, ExpPlanet)
QB
(ourPlanet% <> defendPlanet%)
(takeShips%(our%) > 0)
RM takenShips% =
round(takeShips%(our%) * takeShipsFraction), 1)
S) totalTakenShips% += takenShips%
:
U= ourPlanets%(our%, ExpShipsAvailable) -= takenShips%
VB
moveShipsFromTo(takenShips%, ourPlanet%, defendPlanet%)
W
our%
diagnosis(
min(totalShips%, requiredShips%))+" ships can help backup "+PlanetName$(defendPlanet%))
]9ourPlanets%(defend%, ExpShipsRequired) += totalShips%
--------------------------------------------------------------------- Attacking Moves
spAttackMove(side%,
ourPlanets%(), attackFrom%, attackPlanet%)
requiredShips%, freeShips%, attackFromPlanet%
e;attackFromPlanet% = ourPlanets%(attackFrom%, ExpPlanet)
fSrequiredShips% =
calculateTransferShipsSp(attackPlanet%, attackFromPlanet%)
gCfreeShips% = ourPlanets%(attackFrom%, ExpShipsAvailable)
(freeShips% >= requiredShips%)
(requiredShips% <> -1)
moveShipsFromTo(freeShips%, attackFromPlanet%, attackPlanet%)
diagnosis("Sent ships to battle: "+
(freeShips%))
spClearAttackDetails(side%)
diagnosis("Not enough troops yet... Have: "+
(freeShips%)+", need "+
(requiredShips%))
spAttackingMoves(
ourPlanets%(), attackFromPlanet%, attackPlanet%)
loop%, theirPlanet%
theirPlanets%()
theirPlanets%( NumberPlanets% -
(ourPlanets%(), 1), 1 )
loop% = 1
NumberPlanets%
PlanetSide(loop%) <> CurrentSide%
theirPlanet% += 1
|. theirPlanets%(theirPlanet%, 0) = loop%
}g theirPlanets%(theirPlanet%, 1) =
spAttackValue(theirPlanet%, ourPlanets%(central%, ExpPlanet))
loop%
spSortAttackValues(theirPlanets%())
spDecideAttacks(ourPlanets%(), theirPlanets%(), central%)
spSortAttackValues(
theirPlanets%())
loop%, loop2%, max%, number%
#number% =
(theirPlanets%(), 1)
number% > 1
loop% = 1
number% - 1
$ max% = theirPlanets%(loop%, 1)
loop2% = loop% + 1
number%
+
theirPlanets%(loop2%, 1) > max%
>
theirPlanets%(loop2%, 0), theirPlanets%(loop%, 0)
>
theirPlanets%(loop2%, 1), theirPlanets%(loop%, 1)
( max% = theirPlanets%(loop%, 1)
loop2%
loop%
spDecideAttacks(
ourPlanets%(), theirPlanets%(), our%)
freeShips%, loop%, requiredShips%, ourPlanet%, planet%
-ourPlanet% = ourPlanets%(our%, ExpPlanet)
5freeShips% = ourPlanets%(our%, ExpShipsAvailable)
loop% = 1
(freeShips% > 0)
(loop% <=
(theirPlanets%(), 1))
(theirPlanets%(loop%, 1) <> -1)
' planet% = theirPlanets%(loop%, 0)
X requiredShips% =
calculateTransferShipsBuildUp2(planet%, ourPlanet%) :
was our%)
(freeShips% >= requiredShips%)
(requiredShips% <> -1)
=
moveShipsFromTo(requiredShips%, ourPlanet%, planet%)
$ freeShips% -= requiredShips%
loop% += 1
5ourPlanets%(our%, ExpShipsAvailable) = freeShips%
spAttackValue(planet%, centralPlanet%)
This returns a value that signifies its take over value.
This is based on the number of ships relative to number of resources
Should also take into account distance, but not yet
ships%, timeMultiplier
Mships% =
calculateTransferShipsBuildUp2(planet%, centralPlanet%)
LtimeMultiplier = MaxJourneyTime% /
journeyTime(planet%, centralPlanet%)
ships% = -1
= -1
ships% = 0
6 =(PlanetResources(planet%) ^ 2) * timeMultiplier
B =((PlanetResources(planet%) ^ 2 ) / ships%) * timeMultiplier
spCentralPlanet(ourPlanets%())
This returns the central for this side. If it has been
taken over, or will be taken over this turn, then it is changed
to the planet with the highest availableShips
side%, central%, loop%, maxPlanet%, maxShips%
?central% =
spGetCentralPlanet(CurrentSide%, ourPlanets%())
central% = -1
We have to find a new planet
( maxPlanet% = -1: maxShips% = -9999
loop% = 1
(ourPlanets%(), 1)
=
ourPlanets%(loop%, ExpShipsAvailable) > maxShips%
O maxPlanet% = loop%: maxShips% = ourPlanets%(loop%, ExpShipsAvailable)
loop%
M !(ComputerBlockPtr%(CurrentSide%)) = ourPlanets%(maxPlanet%, ExpPlanet)
= maxPlanet%
= central%
spGetCentralPlanet(side%, ourPlanets%())
Returns the ourPlanets%() index of centralPlanet.
Returns -1 if it is not our planet anymore, or it will
be taken over most probably this turn
centralPlanet%, loop%
0centralPlanet% = !(ComputerBlockPtr%(side%))
loop% = 1
(ourPlanets%(), 1)
ourPlanets%(loop%, ExpPlanet) = centralPlanet%
B
ourPlanets%(loop%, ExpShipsRequired) <> 0
=-1
=loop%
loop%
calculateTransferShipsSp(attackPlanet%, attackFromPlanet%)
This calculates how many ships will have to be sent to planet% to take
it over from centralPlanet%
This also takes into account the number of ships from other sides
heading for the planet
order%, side%, transitShips%
)side% = PlanetSide(attackFromPlanet%)
PlanetSide(attackPlanet%) <> side%
order% = 1
NumberMovementOrders%
8
(MovementOrders%(order%, 3) = attackPlanet%)
0
MovementOrders%(order%, 0) = side%
G
We have already sent ships there. Forget it at this stage
= -1
I
another side is sending ships. Have to send more than them!
K transitShips% =
max(MovementOrders%(order%, 2), transitShips%)
order%
There are no troops on the way, therefore calculate a value
max( PlanetShips%(attackPlanet%) +
shipsIncreaseFromResourcesOver(PlanetResources(attackPlanet%),
journeyTime(attackFromPlanet%, attackPlanet%)), transitShips%) * 1.3 )
= -1
> GeneralLib
----------------------------------------------------------------------------- String
stringToLowerCase(upper$)
loop%, lower$
lower$ = ""
loop% = 1
(upper$)
; lower$ +=
charToLowerCase(
upper$, loop%, 1))))
loop%
=lower$
charToLowerCase(upper%)
upper% >=
("A")
upper% <=
("Z")
" = upper% + (
("a") -
("A"))
= upper%
read0String(ptr%)
string$
?ptr% <> 0
string$ +=
(?ptr%)
ptr% += 1
=string$
readSysString(ptr%)
string$
?ptr% >= 32
string$ +=
(?ptr%)
ptr% += 1
=string$
-------------------------------------------------------------------------- Numerical
min(A, B)
A <= B
max(A, B)
A > B
round(n)
(n + 0.5)