home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / 476-500 / apd496 / commented-yachting.amos / commented-yachting.amosSourceCode
AMOS Source Code  |  1986-08-03  |  14KB  |  501 lines

  1. '  
  2. '           *******************************************            
  3. '           *                                         *            
  4. '           *               Yachting             1993 *                  
  5. '           *               --------                  *          
  6. '           *       THIS IS THE OLD VERSION           *    
  7. '           *      written by Stephan Scholz          *  
  8. '           *                                         *
  9. '           *   A yachting simulator on a lake with   *  
  10. '           *   three buoys, one competitor yacht     *        
  11. '           *   and a Vista generated background.     *        
  12. '           *                                         *
  13. '           *   12 Knot Wind.  -  Beaufort Force 3    *  
  14. '           *                                         *                    
  15. '           *   Click mouse on   < > ^ v symbols      *
  16. '           *   round the dashboard instruments.      *
  17. '           *   to turn rudder left or right, to      *
  18. '           *   bring in or let out sailboom, and     *                        
  19. '           *   on the little box for spinnaker.      *
  20. '           *                                         *
  21. '           *******************************************      
  22. '
  23. Set Buffer 40
  24. Dim H(360,15)
  25. Dim H#(360,2)
  26. Dim BUOY(3,3)
  27. Proc COMMENCE
  28. Proc SAILDATA
  29. Proc SCRNOBJLDR
  30. Proc SETTINGS
  31. Do 
  32. For HO=1 To 10
  33. 'horizon oscillation 
  34.    Add HOR,OSCI
  35.    Add A,OSCI*PITCH
  36. 'get your heading
  37.    HR#= Extension_4_01D0(0)
  38. 'background view or orientation angle  
  39.    BACKX=HR#/68.2
  40. 'heading 
  41.    HH=HR#/182
  42. 'relative wind 
  43.    WW=ANGW-HH
  44.    If WW<1 Then WW=WW+360
  45. 'windward side right(+) or left(-)   
  46.    TK=Sgn(WW-180)
  47. 'boom angle  
  48.    SIL=180-(SAIL*TK)
  49. 'boom angle when loose in the wind   
  50.    TI=180*TK
  51.    QWW=180-WW
  52.    VES=VE#*VE#
  53. 'force of apparent wind (FAPWIND is square of windspeed) 
  54.    FAPWIND=(SWIND)+(VES)-2*(WIND*VE#*Cos(QWW))
  55. 'APWIND# is apparent windspeed or force    
  56.    APWIND#=Sqr(FAPWIND)
  57. 'AWA is apparent wind direction  
  58.    AWA=WW-(90-Acos((VE#*Sin(QWW))/APWIND#))
  59. 'boom angle when loose in wind (180 degrees less)    
  60.    AWT=AWA-TI
  61. 'sail angle of incidence 
  62.    INS=(AWT-SIL)*-TK
  63.    If INS<1
  64.       SIL=AWT
  65.       INS=1
  66.    End If 
  67. 'boom colours  
  68.    FAR=H(INS,15)
  69. 'sail efficiency as per angle tables 
  70.    FSAIL=H(INS,14)*Abs(Sin(SIL))
  71. 'total propulsion * square of windspeed and working
  72. 'coefficient which accounts for water resistence and 
  73. 'wave factor when reaching or running free, and spinnaker if up. 
  74.    PROP#=FSAIL*FAPWIND*H#(WW,SPA)
  75. 'speed increase or decrease as per propulsion difference 
  76.    VE#=VE#-(Sgn(VE#-PROP#)*0.025)
  77. 'the following line should be VE=VE#*20 if using a 68030 and in the  
  78. 'SAILDATA procedure a change is also indicated before the AUTOS data.  
  79.    VE=VE#*40
  80.    If Mouse Key<>0
  81.    CONTROL
  82.    Else 
  83. 'self correcting rudder
  84.      Add F,-Sgn(F)
  85.    End If 
  86.      G=F*VE/4
  87.      F1=F*2
  88.      RUD=180
  89.      Add G,F1
  90.      Add RUD,-F1
  91. 'alter heading as per rudder 
  92.      Add B,G
  93.    Extension_4_01A6 0,A,B,C
  94.    Extension_4_0100 0,VE
  95. 'movement of competitor as per its wind angle table established
  96. 'every finished for next loop, depending on its orientation. 
  97.       Add VE1,Sgn(H(WW1,13)-VE1)
  98.        Extension_4_01A6 1,A,B1,C
  99.        Extension_4_0100 1,VE1
  100.    Cls 0
  101.     Extension_4_0318 
  102. 'background scroll 
  103.     Extension_4_049E 1,BACKX,0,960,85 To 0,HOR
  104. 'draw dashboard  
  105.    Screen Copy 2,0,0,320,66 To 0,0,139
  106. '
  107. 'instrument pointers and numbers 
  108. '    
  109.      Locate 27,19
  110. 'your speed:   
  111.      Print VE#
  112. 'print spinnaker indicator:  
  113.      Locate 14,21
  114.      Print SPIN$
  115. 'compass bearing:  
  116.      Locate 12,19
  117.      COMPAS=H(HH,1)
  118.      Print Mid$(COMPAS$,COMPAS,5)
  119. 'apparent wind:    
  120.    Plot H(AWA,3),H(AWA,4),7
  121.    Draw To H(AWA,5),H(AWA,6)
  122. 'use the following line to see the real wind:  
  123.    'Draw H(WW,3),H(WW,4) To H(WW,5),H(WW,6) 
  124. 'sail boom:
  125.    Plot PX,PY,FAR
  126.    Draw To H(SIL,7),H(SIL,8)
  127. 'rudder: 
  128.    Plot PX,RY,13
  129.    Draw To H(RUD,11),H(RUD,12)
  130. 'competitor's position on scanner: 
  131.    Plot 59+LX1/3125,170-LZ1/3125,7
  132. 'your position on scanner:   
  133.    Plot 59+LX/3125,170-LZ/3125,13
  134.    Screen Swap 
  135.    Wait Vbl 
  136. Next HO
  137.    If VE#<0 Then VE#=0
  138. 'update your position
  139.    LX= Extension_4_0114(0)
  140.    LZ= Extension_4_013C(0)
  141. 'keep your ship on map 
  142.    If Abs(LZ)>90000 Then LZ=90000*Sgn(LZ)
  143.    If Abs(LX)>90000 Then LX=90000*Sgn(LX)
  144. 'a minor correction for totally rear wind
  145.    If AWA=180 Then Add F,5
  146. 'a minor correction to avoid boat taking off (ly=0)
  147.     Extension_4_00EC 0,LX,LY,LZ
  148. 'collision detection 
  149.    If Extension_4_0344(0)>0 Then CRASH
  150. 'invert horizon oscillation
  151.    OSCI=-OSCI
  152.    SHIPS
  153.    ROBWIND
  154. Loop 
  155. Procedure CRASH
  156. Shared LX,LY,LZ,LX1,LY1,LZ1,CHOCA,F,HR#,VE#,CRA,HH,HH1,CRA
  157. Boom 
  158. 'bumps counter 
  159. Inc CHOCA
  160. N= Extension_4_0344(0)
  161. 'checks which side of your ship collision has occured on 
  162. CRA= Extension_4_0258(0,N)-HR#
  163. 'brusque rudder movement away from other ship  
  164. F=40*-Sgn(CRA)
  165. End Proc
  166. Procedure SHIPS
  167. Shared LX1,LX,LZ1,LZ,LY,LY1,B,B1,WW1,HH1,TK1,ANGW
  168. Shared X5,Y5,Z5,X6,Y6,Z6,BO1,BO0,BUOY(),BCOUNT,B1COUNT,CHOCA,SPAU
  169.    LX1= Extension_4_0114(1)
  170.    LZ1= Extension_4_013C(1)
  171. 'keep ship on map
  172.    If Abs(LZ1)>90000 Then LZ1=90000*Sgn(LZ1)
  173.    If Abs(LX1)>90000 Then LX1=90000*Sgn(LX1)
  174.    B1= Extension_4_0262(1,X5,Y5,Z5)
  175.   MIRA:
  176.     Extension_4_01A6 1,A,B1,C
  177.    HH1= Extension_4_01D0(1)/182
  178.    WW1=ANGW-HH1
  179.    If WW1<1 Then WW1=WW1+360
  180.    If WW1>180 Then WW1=360-WW1
  181.    TK1=182*Sgn(WW1-180)
  182. 'if against wind try again 
  183.    If WW1<40
  184.      B1=B1+((Rnd(15)+40)-WW1*TK1)
  185.      Goto MIRA
  186.    End If 
  187. 'if near enough buoy head for next one (competitor)
  188.      If Extension_4_028E(1,X5,Y5,Z5)<2000
  189.       Inc B1COUNT
  190.       If BO1<3
  191.           Inc BO1
  192.           X5=BUOY(BO1,1)
  193.           Y5=BUOY(BO1,2)
  194.           Z5=BUOY(BO1,3)
  195.       End If 
  196.     End If 
  197.      Extension_4_00EC 1,LX1,LY1,LZ1
  198. 'if near enough, record this buoy and set next one (your ship) 
  199.     If Extension_4_028E(0,X6,Y6,Z6)<3000
  200.      Bell 
  201.      Inc BCOUNT
  202.      If BO0<3
  203.       Inc BO0
  204.       X6=BUOY(BO0,1)
  205.       Y6=BUOY(BO0,2)
  206.       Z6=BUOY(BO0,3)
  207.      End If 
  208.     End If 
  209. 'if you've arrived at last buoy... 
  210.    If BCOUNT=3
  211.     Locate 27,19
  212.     Print "Bumps:";CHOCA
  213.     Locate 27,20
  214.      If B1COUNT<3
  215.       Print "You've won"
  216.      End If 
  217.       Screen Swap 
  218.       Wait 200
  219.       Bell 
  220.       Locate 27,19
  221.       Print "Turn north,"
  222.       Locate 27,20
  223.       Print "race again."
  224.       Screen Swap 
  225.       Wait 200
  226.       Bell 
  227.       BCOUNT=0
  228.       B1COUNT=0
  229.       CHOCA=0
  230.       SETTINGS
  231.     End If 
  232. End Proc
  233. Procedure ROBWIND
  234. Shared ANGW,VE#,VE1,SV0,SV1,DSE
  235.    DSE= Extension_4_007E(0,1)
  236.    SV0= Extension_4_0258(0,1)/182
  237.    SV1= Extension_4_0258(1,0)/182
  238.    If SV0<0 Then Add SV0,360
  239.    If SV1<0 Then Add SV1,360
  240.   If DSE<10000
  241.    Add SV0,-ANGW
  242.    If Abs(SV0)<20
  243.     Shoot 
  244.      If VE#>0.5
  245.       VE#=VE#-0.5
  246.       Pop Proc
  247.      End If 
  248.    End If 
  249.     Add SV1,-ANGW
  250.    If Abs(SV1)<20
  251.     Bell 
  252.      If VE1>20
  253.       Add VE1,-20
  254.       Pop Proc
  255.      End If 
  256.     End If 
  257.   End If 
  258. End Proc
  259. Procedure CONTROL
  260. Shared FOCK,SAIL,F,FM,SPA,SPIN$
  261.  X=X Mouse/8 : Y=Y Mouse/8
  262. If Y>28
  263.  If X>37
  264.    If F<FM : Inc F : Pop Proc : End If 
  265.    Else 
  266.    If F>-FM : Dec F : Pop Proc : End If 
  267.  End If 
  268. End If 
  269. If X>40
  270.   If Y<26
  271.    If SAIL<90 : Inc SAIL : Pop Proc : End If 
  272.   Else 
  273.    If SAIL>0 : Dec SAIL : Pop Proc : End If 
  274.   End If 
  275. End If 
  276. If X<32
  277. Bell 
  278.  If SPIN$="v" : SPA=2 : SPIN$="^" : Wait 2 : Pop Proc
  279.  Else 
  280.  SPIN$="v" : SPA=1 : Wait 2 : Pop Proc : End If 
  281.  End If 
  282. End Proc
  283. Procedure COMMENCE
  284.    Shared WIND,SWIND,SAIL,ANGW,OSCI,HOR,PITCH
  285.     Extension_4_0548 : Degree : Curs Off 
  286.    Paper 0 : Ink 0,9 : Cls 0 : Pen 4
  287.    Locate 0,6
  288.    Print "        La Oroya presents:"
  289.    Print 
  290.    Print "      * * *   REGATTA   * * *"
  291.    Print 
  292.    Print " Greetings to Mad Max and Kid Blast"
  293.    Print : Print : Print : Print 
  294. Randomize Timer
  295.    WIND=12
  296.    SWIND=WIND*WIND
  297. AGAIN:
  298.    ANGW=Rnd(359)
  299. 'this avoids head-wind at start
  300. If Abs(ANGW)<45 Then Goto AGAIN
  301.    If ANGW=180 or ANGW=0 Then ANGW=ANGW+1
  302.    Print "  Wind direction:";ANGW;" deg. N"
  303.    Print 
  304.    Print "  Wind speed    :";WIND;" Kts."
  305. 'Horizon oscillation 
  306.    OSCI=1
  307.    HOR=-12
  308. 'and its relationship to ship�s pitching 
  309.    PITCH=72
  310. End Proc
  311. Procedure SETTINGS
  312. Shared LX,LX1,LY,LY1,LZ,LZ1,BUOY(),BO0,BO1
  313. Shared X5,Y5,Z5,X6,Z6,Y6,SAIL,FOCK,FM,SPA,SPIN$
  314.    LX=62000
  315.    LY=200
  316.    LX1=64000
  317.    LY1=500
  318.    LZ=-70000
  319.    LZ1=-65000
  320.     Extension_4_00EC 0,LX,LY,LZ
  321.     Extension_4_01A6 0,0,0,0
  322.     Extension_4_00EC 1,LX1,LY1,LZ1
  323.     Extension_4_01A6 1,0,0,0
  324.    H=-100
  325.    BUOY(1,1)=0 : BUOY(1,2)=H : BUOY(1,3)=53000
  326.    BUOY(2,1)=-53000 : BUOY(2,2)=H : BUOY(2,3)=-53000
  327.    BUOY(3,1)=53000 : BUOY(3,2)=H : BUOY(3,3)=-53000
  328. 'which buoy are they going for at start: 
  329.    BO0=1
  330.    BO1=1
  331. 'buoy homing indicators for each ship: 
  332.    X5=BUOY(BO1,1)
  333.    Y5=BUOY(BO1,2)
  334.    Z5=BUOY(BO1,3)
  335.    X6=X5
  336.    Y6=Y5
  337.    Z6=Z5
  338. 'initial boom angles 
  339.    SAIL=30
  340.    FOCK=30
  341. 'maximum rudder angle
  342.    FM=12
  343. 'spinnaker stowed at start 
  344.    SPIN$="v"
  345.    SPA=1
  346.    Pen 3
  347. End Proc
  348. Procedure SCRNOBJLDR
  349. 'background landscape loading and preparation of extra long strip. 
  350. Screen Open 0,320,256,16,Lowres : Flash Off : Curs Off 
  351. Load Iff "Yachting:Iffs/Back.Iff",0
  352. Screen Open 1,960,86,16,Lowres : Flash Off : Curs Off 
  353. Get Palette 0
  354. Screen Copy 0,0,0,320,85 To 1,0,0
  355. Screen Copy 0,0,86,320,170 To 1,320,0
  356. Screen Copy 0,0,171,320,256 To 1,640,0
  357. Screen Hide 1 : Screen 0
  358. Get Palette 0
  359. Screen Display 0,,,320,205
  360. 'dashboard loading and copying to a storage screen 
  361. Load Iff "Yachting:IFFs/Dashboard.IFF"
  362. Screen Open 2,320,66,16,Lowres : Flash Off : Curs Off 
  363. Screen Copy 0,0,139,320,256 To 2,0,0
  364. Get Palette 0
  365. Screen Hide 2 : Screen 0
  366.    Extension_4_0054 140 : Double Buffer : Autoback 0
  367.    Extension_4_04D6 "Yachting:objects"
  368.    Extension_4_0016 "buoy1"
  369.    Extension_4_0016 "buoy2"
  370.    Extension_4_0016 "buoy3"
  371.    Extension_4_0016 "yacht"
  372.    Extension_4_0036 1,"yacht",65000,0,-55000,0,0,0
  373.    Extension_4_0036 2,"buoy1",0,H,50000,0,0,0
  374.    Extension_4_0036 3,"buoy2",-50000,0,-50000,0,0,0
  375.    Extension_4_0036 4,"buoy3",50000,0,-50000,0,0,0
  376.   For N=2 To 4
  377.    Extension_4_0328 N,0,0,0,0,700
  378.   Next N
  379.    Extension_4_0328 0,0,0,0,500,500
  380.    Extension_4_0328 1,0,0,0,1400,700
  381.    Extension_4_0328 1,1,0,0,-1400,700
  382.    Extension_4_0328 1,2,0,0,0,700
  383. End Proc
  384. Procedure SAILDATA
  385. Shared PX,PY,BX,BY,RY,NAN#,NIN#,NON#,H(),H#(),COMPAS$,WIND,SWIND
  386. COMPAS$="  -N-  n.e  -E-  s.e  -S-  s.w  -W-  n.w  -N- "
  387. 'points on screen for navigation instruments:  
  388.    PX=176
  389.    PY=171
  390.    BY=155
  391.    RY=189
  392.    NAN#=15
  393.    NIN#=17
  394.    NON#=19
  395.    For N=0 To 360
  396.        SN#=Sin(N)
  397.        CN#=-Cos(N)
  398. 'compass instrument data:      
  399.        H(N,1)=2+N/9
  400.        H(N,2)=0
  401. 'main navigation instrument: 
  402. 'apparent wind indicator data: 
  403.        H(N,3)=PX+NON#*SN#
  404.        H(N,4)=PY+NON#*CN#
  405.        H(N,5)=H(N,3)+NIN#/3*SN#
  406.        H(N,6)=H(N,4)+NIN#/3*CN#
  407. 'boom position indicator data:   
  408.        H(N,7)=PX+16*SN#
  409.        H(N,8)=PY+16*CN#
  410. 'jib position indicator data (unused in this version):     
  411.        H(N,9)=PX+12*SN#
  412.        H(N,10)=BY+12*CN#
  413. 'rudder indicator data data:   
  414.        H(N,11)=PX+7*SN#
  415.        H(N,12)=RY+7*CN#
  416. 'working factor accounting for resistances multiplied by 
  417. 'wave and wind resistance close hauled, or their help if 
  418. 'running free. This is called if spinnaker is not up.
  419.        H#(N,1)=0.0007+(0.00014*CN#)
  420.    Next N
  421. 'data for automatic ships' speed depending on real wind direction  
  422. 'based on modern yachtspeed graph (with spinnaker for aft winds):          
  423.  Restore AUTOS
  424.    For N=30 To 180
  425.        Read A#
  426. 'the following should be h(n,13)=a#*1.4 if using a 68030 
  427.        H(N,13)=A#*2.8
  428.    Next N
  429.  AUTOS:
  430.   Data 0,0,0,0,5,10,15,20,25,30
  431.   Data 32,36,40,44,46,50,53,55,58,60
  432.   Data 62,64,66,68,70,71,72,73,74,75
  433.   Data 76,77,78,79,80,80,81,81,82,82
  434.   Data 83,83,84,84,85,85,86,87,88,89
  435.   Data 90,91,92,93,94,95,96,97,98,99
  436.   Data 100,100,101,101,102,102,103,103,104,104
  437.   Data 105,105,106,106,107,107,108,108,109,109
  438.   Data 110,111,112,113,114,115,116,117,117,118
  439.   Data 118,119,119,120,120,121,121,122,122,123
  440.   Data 123,124,124,125,125,125,124,124,123,123
  441.   Data 122,122,121,121,120,120,119,118,117,116
  442.   Data 115,114,113,112,111,110,109,108,106,104
  443.   Data 102,100,98,96,94,92,90,88,86,84
  444.   Data 82,81,80,79,78,77,76,76,75,75,75
  445.   Restore SAILS
  446.    For N=0 To 180
  447.      Read A
  448.      H(N,14)=A
  449.      If N<10 Then H(N,15)=15 : Goto RAUS
  450.      If N<26 Then H(N,15)=7 : Goto RAUS
  451.      H(N,15)=6
  452.      RAUS:
  453.    Next N
  454. 'your sail efficiency data, depending on the angle of incidence
  455. 'of the wind. Between 10 and 25 deg. there is laminar flow, and  
  456. 'sail efficiency lies between 89 and 100% for 15 to 22 degrees.
  457.  SAILS:
  458.    Data 0,0,0,0,0,0,0,0,0,0
  459.    Data 80,81,83,85,87,89,91,93,95,97
  460.    Data 98,99,100,99,98,97,70,70,70,70
  461.    Data 70,70,70,70,70,70,70,70,70,70
  462.    Data 70,70,70,70,70,70,71,71,72,72
  463.    Data 73,73,74,74,75,75,75,75,75,75
  464.    Data 75,75,75,75,75,75,75,75,75,75
  465.    Data 75,75,75,75,75,75,75,75,75,75
  466.    Data 75,76,77,78,79,80,80,80,80,80
  467.    Data 79,78,77,76,75,74,73,72,71,70
  468.    Data 69,68,67,66,65,64,63,62,61,60
  469.    Data 59,58,57,56,55,54,53,52,51,50
  470.    Data 49,48,47,46,45,44,43,42,41,40
  471.    Data 39,38,37,36,35,34,33,32,31,30
  472.    Data 29,28,27,26,25,24,23,22,21,20
  473.    Data 19,18,17,16,15,14,13,12,11,10
  474.    Data 9,8,7,6,5,4,3,2,1,0
  475.    Data 0,0,0,0,0,0,0,0,0,0,0
  476. 'The following factor is a percentage increase on h#(n,1)  
  477. 'which controls resistance and wind+wave effect times a constant.    
  478. 'The table gives the percentage increase and the multiplier is 
  479. 'the change in the constant, as speed also changes resistance. The 
  480. 'result h#(n,2) is called by SPA if spinnaker is up, instead of h#(n,1).       
  481.    For N=0 To 89
  482.      H#(N,2)=-1
  483.      H#(360-N,2)=-1
  484.    Next N
  485. Restore SPINNAKER
  486.    For N=90 To 180
  487.      Read A#
  488.      H#(N,2)=H#(N,1)+H#(N,1)*A#*0.024
  489.      H#(360-N,2)=H#(N,2)
  490.    Next N
  491. SPINNAKER:
  492.  Data 1,1,2,2,3,3,4,4,5,5
  493.  Data 6,6,7,7,8,8,9,9,10,10
  494.  Data 11,12,13,14,15,16,17,18,19,20
  495.  Data 22,24,26,28,30,32,34,36,38,40
  496.  Data 42,44,46,48,50,51,52,53,54,55
  497.  Data 56,58,60,62,64,66,68,70,72,75
  498.  Data 78,79,80,81,82,83,84,85,86,87
  499.  Data 88,87,86,85,84,83,82,81,80,79
  500.  Data 78,76,74,72,70,69,68,67,66,66,66
  501. End Proc