home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 63 / CDACTUAL63.iso / Aplicaciones / DarkBasic / DemoDarkBasic.exe / myproj / iced / iced.dba < prev    next >
Encoding:
Text File  |  2000-05-21  |  33.1 KB  |  1,387 lines

  1. Rem * Title  : ICED
  2. Rem * Author : DBS-LB
  3. Rem * Date   : 1st May 2000
  4. rem ********************************************
  5. rem *                   ICED                   *
  6. rem ********************************************
  7. rem * AUTHOR: Lee Bamber    DATE: 1st May 2000 *
  8. rem ********************************************
  9.  
  10. rem Setup environment
  11. sync rate 30
  12. autocam off
  13. hide mouse
  14. sync on
  15.  
  16. rem Decal limit (full version users can set this to 100)
  17. dim decalmax(1)
  18. decalmax(1)=10
  19.  
  20. rem Game arrays
  21. dim decal#(decalmax(1),20)
  22. dim goblin#(50,20)
  23. dim bullet#(10,10)
  24. dim gunrecoil#(2)
  25. dim fallstart(4)
  26. dim fallend(4)
  27. dim real(5)
  28. dim gpx#(2)
  29. dim gpy#(2)
  30. dim gpz#(2)
  31. enemymax=20
  32.  
  33. rem Load initial screen and sound effect
  34. load sound "rain.wav",1 : loop sound 1
  35. load bitmap "loading.bmp" : sync
  36.  
  37. rem Load sounds
  38. load sound "phaser.wav",2 : for s=3 to 12 : clone sound s,2 : next s
  39. for s=1 to enemymax
  40.     ss=100+(s*2)
  41.     load 3dsound "howl.wav",ss : set sound speed ss,5000+rnd(3000)
  42.     load 3dsound "die.wav",ss+1 : set sound speed ss+1,30000+rnd(5000)
  43. next s
  44. for s=1 to 5
  45.     ss=1000+(s*2)
  46.     load 3dsound "attack.wav",ss : set sound speed ss,15000+rnd(5000)
  47.     load 3dsound "thump.wav",ss+1 : set sound speed ss+1,3000
  48. next s
  49.  
  50. rem Load images
  51. load image "smoke.bmp",1001
  52.  
  53. rem Create Elements
  54. gosub _generate_goblins
  55. gosub _create_world
  56. gosub _create_enemies
  57. gosub _create_player
  58.  
  59. rem Place logo
  60. placelogo()
  61.  
  62. rem Main gameloop
  63. lowmode=0
  64. do
  65.  
  66. rem Activate low mode
  67. if lower$(inkey$())="l" and lowmode=0
  68.     lowmode=1
  69.     hide object 52
  70.     hide object 53
  71.     hide object 80
  72.     hide object 81
  73.     hide object 82
  74.     hide object 83
  75.     for e=1 to enemymax : delete object 100+(e*2)+1 : next e
  76.     for e=1 to 5 : delete object 1000+(e*2)+1 : next e
  77.     color backdrop rgb(255,255,255)
  78. endif
  79. if lower$(inkey$())="h" then hide object 65000
  80.  
  81. rem Control game elements
  82. gosub _control_player
  83. gosub _control_camera
  84. gosub _control_guns
  85. gosub _control_enemies
  86. gosub _control_weather
  87.  
  88. rem Controller functions
  89. controldecals(mx#,mz#)
  90.  
  91. rem Update screen
  92. sync
  93.  
  94. rem End of gameloop
  95. loop
  96.  
  97.  
  98. rem ** Subroutines **
  99.  
  100. _control_player:
  101.  
  102. rem Control Player
  103. olx#=x# : olz#=z#
  104. stage=0 : gunlag#=5.0
  105. if upkey()=1
  106.     x#=newxvalue(x#,cya#,8.0) : z#=newzvalue(z#,cya#,8.0)
  107.     gunlag#=1.1
  108.     stage=1
  109. endif
  110. if downkey()=1
  111.     x#=newxvalue(x#,cya#,-8.0) : z#=newzvalue(z#,cya#,-8.0)
  112.     gunlag#=1.1
  113.     stage=1
  114. endif
  115. if leftkey()=1
  116.     x#=newxvalue(x#,wrapvalue(cya#-90.0),6.0)
  117.     z#=newzvalue(z#,wrapvalue(cya#-90.0),6.0)
  118.     gunlag#=1.1
  119. endif 
  120. if rightkey()=1
  121.     x#=newxvalue(x#,wrapvalue(cya#+90.0),6.0)
  122.     z#=newzvalue(z#,wrapvalue(cya#+90.0),6.0)
  123.     gunlag#=1.1
  124. endif
  125.  
  126. rem Walk woddle height
  127. if stage=1
  128.     walkha#=wrapvalue(walkha#+16.0)
  129. else
  130.     walkha#=curveangle(0.0,walkha#,5.0)
  131. endif
  132. walkh#=(cos(walkha#)*4.5)
  133.  
  134. rem Ensure player stays on floor
  135. fx#=0 : fz#=0
  136. for r=0 to 35
  137.     ex#=newxvalue(x#,r*10,15)
  138.     ez#=newzvalue(z#,r*10,15)
  139.     eh#=get ground height(1,ex#+mx#,ez#+mz#)
  140.     if eh#<-50.0 then eh#=-50.0
  141.     force#=(eh#+50.0)/10.0
  142.     fx#=fx#+((ex#-x#)*force#)
  143.     fz#=fz#+((ez#-z#)*force#)
  144. next r
  145. x#=x#-(fx#/35.0)
  146. z#=z#-(fz#/35.0)
  147.  
  148. rem Aquire ground height of new position
  149. y#=get ground height(1,x#+mx#,z#+mz#)
  150. if y#<-50.0 then y#=-50.0
  151.  
  152. rem Place listener
  153. position listener x#,y#,z#
  154. rotate listener 0,wrapvalue(cya#),0
  155.  
  156. rem Control hurt fog
  157. if returnkey()=1 and hurt#=0.0 then hurt#=100.0
  158. if hurt#>0
  159.     dec hurt#,1.0+(100.0-hurt#)
  160.     fog on
  161.     fog color rgb((255.0/100.0)*hurt#,0,0)
  162.     fog distance 50000-((50000.0/100.0)*hurt#)
  163.     if hurt#<=0.0
  164.         hurt#=0.0
  165.         fog off
  166.     endif
  167. endif
  168.  
  169. rem Control compass needle
  170. if closestgoblin>0
  171.     g=closestgoblin
  172.     dx#=goblin#(g,2)-x#
  173.     dz#=goblin#(g,3)-z#
  174.     aa#=wrapvalue(cya#-atanfull(dx#,dz#))
  175.     compass#=aa#
  176.     if compassscale#<25.0 then inc compassscale#
  177. else
  178.     compass#=0
  179.     if compassscale#>0.0 then dec compassscale#
  180. endif
  181. zrotate object 80,compass#
  182. scale object 80,compassscale#,75,500
  183.  
  184. return
  185.  
  186. _control_camera:
  187.  
  188. rem Control Camera
  189. cya#=wrapvalue(cya#+(mousemovex()/3.0))
  190. cxa#=cxa#+(mousemovey()/3.0)
  191. if cxa#<-45.0 then cxa#=-45.0
  192. if cxa#>45.0 then cxa#=45.0
  193. cx#=newxvalue(x#,cya#,sin(cxa#)*10)
  194. cz#=newzvalue(z#,cya#,sin(cxa#)*10)
  195. position camera cx#,y#+30+walkh#,cz#
  196. rotate camera wrapvalue(cxa#),cya#,0
  197.  
  198. return
  199.  
  200. _control_guns:
  201.  
  202. rem Control gun recoil
  203. for g=0 to 1
  204.     if gunrecoil#(g)>0
  205.         gunrecoil#(g)=gunrecoil#(g)-1
  206.     endif
  207. next g
  208.  
  209. rem Control Guns
  210. for g=0 to 1
  211.     gga#=wrapvalue((cya#-20)+(g*40))
  212.     ggx#=newxvalue(x#,gga#,gunrecoil#(g)*-1)
  213.     ggz#=newzvalue(z#,gga#,gunrecoil#(g)*-1)
  214.     gpdx#=newxvalue(ggx#,wrapvalue((cya#-20)+(g*40)),10)
  215.     gpdy#=y#-(sin(cxa#)*10)
  216.     gpdz#=newzvalue(ggz#,gga#,10)
  217.     gpx#(g)=curvevalue(gpdx#,gpx#(g),gunlag#)
  218.     gpy#(g)=curvevalue(gpdy#,gpy#(g),gunlag#)
  219.     gpz#(g)=curvevalue(gpdz#,gpz#(g),gunlag#)
  220.     position object 2+g,gpx#(g),gpy#(g)+22+walkh#,gpz#(g)
  221.     xrotate object 2+g,wrapvalue(0-cxa#)
  222.     yrotate object 2+g,wrapvalue(cya#+180)
  223. next g
  224.  
  225. rem Control Firing
  226. if mouseclick()=1
  227.  
  228.     rem If gun ready
  229.     if gunpressed=0
  230.  
  231.         rem Start with prefered gun    
  232.         gunprefered=1-gunprefered
  233.         gunobj=2+gunprefered
  234.         gunrecoil#(gunobj-2)=10.0
  235.         gunpressed=1
  236.  
  237.         rem Find free bullet
  238.         bf=-1
  239.         for b=0 to 10
  240.             if bullet#(b,1)=0 then bf=b
  241.         next b
  242.     
  243.         rem Trigger bullet
  244.         if bf>0
  245.             objid=4+(bf*2)+0
  246.             bullet#(bf,1)=1
  247.             bullet#(bf,2)=0
  248.             play sound 2+bf
  249.             tx#=object position x(gunobj)
  250.             ty#=object position y(gunobj)
  251.             tz#=object position z(gunobj)
  252.             txa#=object angle x(gunobj)
  253.             tya#=object angle y(gunobj)
  254.             position object objid,tx#,ty#,tz#
  255.             rotate object objid,txa#,wrapvalue(tya#+90),0
  256.             if gunobj=2
  257.                 move object objid,2.0
  258.             else
  259.                 move object objid,-2.0
  260.             endif
  261.             rotate object objid,txa#,tya#,0
  262.             move object objid,5
  263.             show object objid+0
  264.             if object exist(objid+1)=1 then show object objid+1
  265.         endif    
  266.         for adv=1 to 10
  267.             objid=3+(adv*2)+0
  268.             if adv<>rp and bullet#(adv,1)=1 then move object objid,-25.0
  269.         next adv
  270.     
  271.     endif
  272.  
  273. else
  274.     gunpressed=0
  275. endif
  276.  
  277. rem Control bullet movement
  278. for b=0 to 10
  279.  
  280.     rem Bullet alive
  281.     if bullet#(b,1)=1
  282.  
  283.         rem Move bullet
  284.         objid=4+(b*2)+0
  285.         move object objid,-25.0
  286.         ex#=object position x(objid)
  287.         eh#=object position y(objid)
  288.         ez#=object position z(objid)
  289.         position object objid+1,ex#,-50-(eh#+50),ez#
  290.         rotate object objid+1,wrapvalue(0-object angle x(objid)),object angle y(objid),0
  291.  
  292.         rem If bullets meet at ice-level, switch
  293.         if eh#<-50.0
  294.             sx#=object position x(objid)
  295.             sy#=object position y(objid)
  296.             sz#=object position z(objid)
  297.             sxa#=object angle x(objid)
  298.             sya#=object angle y(objid)
  299.             position object objid,object position x(objid+1),object position y(objid+1),object position z(objid+1)
  300.             rotate object objid,object angle x(objid+1),object angle y(objid+1),0
  301.             position object objid+1,sx#,sy#,sz#
  302.             rotate object objid+1,sxa#,sya#,0
  303.         endif
  304.  
  305.         rem Out of Steam
  306.         killbullet=0
  307.         bullet#(b,2)=bullet#(b,2)+1
  308.         if bullet#(b,2)>40 then killbullet=1
  309.  
  310.         rem Collision with ground
  311.         if eh#<get ground height(1,ex#+mx#,ez#+mz#)
  312.             killbullet=1
  313.         endif
  314.  
  315.         rem Collision with goblin
  316.         triggerrevenge=-1
  317.         for g=1 to enemymax
  318.             if killbullet=0
  319.                 if goblin#(g,1)=1
  320.                     gobjid=100+(g*2)+0
  321.                     gx#=goblin#(g,2)-ex#
  322.                     gy#=get ground height(1,goblin#(g,2)+mx#,goblin#(g,3)+mz#)
  323.                     if gy#<-50.0 then gy#=-50.0
  324.                     gy#=gy#+15.0
  325.                     gz#=goblin#(g,3)-ez#
  326.                     if sqrt(abs(gx#*gx#)+abs(gz#*gz#))<20.0    
  327.                         if abs(eh#-gy#)<15.0
  328.                             ss=goblin#(g,12)
  329.                             if goblin#(g,12)<>2
  330.                                 goblin#(g,12)=2
  331.                                 activate_enemy(g,mx#,mz#)
  332.                                 rg=goblin#(g,11)
  333.                                 if rg>0
  334.                                     rgobj=1000+(rg*2)+0
  335.                                     position sound 100+(g*2)+0,object position x(rgobj),object position y(rgobj),object position z(rgobj)
  336.                                     play sound 100+(g*2)+1
  337.                                     stop sound 100+(g*2)+0
  338.                                     fn=goblin#(g,13)
  339.                                     play object rgobj,fallstart(fn),fallend(fn)
  340.                                     if object exist(rgobj+1)=1 then play object rgobj+1,fallstart(fn),fallend(fn)
  341.                                     killbullet=1
  342.                                     triggerrevenge=g
  343.                                 else
  344.                                     goblin#(g,12)=ss
  345.                                 endif
  346.                             endif
  347.                         endif
  348.                     endif
  349.                 endif
  350.             endif
  351.         next g
  352.  
  353.         rem If goblin struck, trigger neighbours to attack
  354.         if triggerrevenge>0
  355.             for g=1 to enemymax
  356.                 ex#=goblin#(g,2)-goblin#(triggerrevenge,2)
  357.                 ez#=goblin#(g,3)-goblin#(triggerrevenge,3)
  358.                 d#=sqrt(abs(ex#*ex#)+abs(ez#*ez#))
  359.                 if d#<200.0
  360.                     if goblin#(g,12)<=1 and goblin#(g,14)=0
  361.                         goblin#(g,12)=1
  362.                         goblin#(g,14)=2 : rem and trigger anger!
  363.                         activate_enemy(g,x#,z#)
  364.                     endif
  365.                 endif
  366.             next g
  367.         endif
  368.  
  369.         rem Kill bullet
  370.         if killbullet=1
  371.             move object objid,25.0
  372.             ex#=object position x(objid)
  373.             ez#=object position z(objid)
  374.             makesmoke(ex#,eh#,ez#,3.0)
  375.             hide object objid+0
  376.             hide object objid+1
  377.             bullet#(b,1)=0
  378.         endif
  379.  
  380.     endif
  381. next b
  382.  
  383. return
  384.  
  385. _control_enemies:
  386.  
  387. rem AI Control: Always Attack Anywhere
  388. for g=1 to enemymax
  389.     initialfind=0
  390.     if goblin#(g,12)=0
  391.         rem If player within view frustrum, activate
  392.         ex#=goblin#(g,2)-x#
  393.         ez#=goblin#(g,3)-z#
  394.         d#=sqrt(abs(ex#*ex#)+abs(ez#*ez#))
  395.         if d#<400.0
  396.             rem Goblin finds you
  397.             goblin#(g,12)=1
  398.             initialfind=1
  399.         endif
  400.     endif
  401.     if goblin#(g,12)>0
  402.         activate_enemy(g,x#,z#)
  403.         if initialfind=1
  404.             rg=goblin#(g,11)
  405.             if rg>0
  406.                 gobjid=1000+(rg*2)+0
  407.                 position sound 1000+(rg*2)+0,object position x(gobjid),object position y(gobjid),object position z(gobjid)
  408.                 play sound 1000+(rg*2)+0
  409.                 loop object gobjid+0,walkstart+5,walkend
  410.                 if object exist(gobjid+1)=1 then loop object gobjid+1,walkstart+5,walkend
  411.                 set object frame gobjid+0,walkstart
  412.                 if object exist(gobjid+1)=1 then set object frame gobjid+1,walkstart
  413.             endif
  414.         endif
  415.     endif
  416.     if goblin#(g,1)=0
  417.  
  418.         rem Hide RG
  419.         rg=goblin#(g,11)
  420.         if rg>0
  421.             gobjid=1000+(rg*2)+0
  422.             loop object gobjid+0,walkstart+5,walkend
  423.             if object exist(gobjid+1)=1 then loop object gobjid+1,walkstart+5,walkend            
  424.             set object frame gobjid+0,walkstart
  425.             if object exist(gobjid+1)=1 then set object frame gobjid+1,walkstart
  426.             realtodecal(g,rg)
  427.         endif
  428.  
  429.         rem If goblin dead, wait for chance to emerge from doorway
  430.         if rnd(1)=0
  431.             ex#=850 : eh#=-50 : ez#=300
  432.         else
  433.             ex#=-650 : eh#=-50 : ez#=850
  434.         endif
  435.         goblin#(g,1)=1
  436.         goblin#(g,2)=ex#
  437.         goblin#(g,3)=ez#
  438.         goblin#(g,4)=100+rnd(7)
  439.         goblin#(g,6)=45+(rnd(3)*90)
  440.         goblin#(g,7)=1
  441.         goblin#(g,8)=rnd(1000)-500
  442.         goblin#(g,9)=rnd(1000)-500
  443.         goblin#(g,12)=1
  444.         goblin#(g,13)=1+rnd(3)
  445.         goblin#(g,14)=0
  446.         goblin#(g,15)=0
  447.         objid=100+(g*2)
  448.         position object objid+0,ex#,eh#,ez#
  449.         if object exist(objid+1)=1 then position object objid+1,ex#,eh#,ez#
  450.         show object objid+0
  451.         if object exist(objid+1)=1 then show object objid+1
  452.  
  453.     endif
  454. next g
  455.  
  456. rem Reset detection of nearest goblin
  457. closestgoblin=-1
  458. closestgoblin#=9999.0
  459.  
  460. rem Control enemies
  461. for g=1 to enemymax
  462.  
  463.     rem Goblin Id
  464.     objid=100+(g*2)
  465.     if goblin#(g,1)=1
  466.     
  467.         if goblin#(g,7)=1
  468.  
  469.             rem Goblin follows Destination Coordinate
  470.             tx#=goblin#(g,8) : tz#=goblin#(g,9)
  471.             point object objid,tx#,-50,tz#
  472.             xrotate object objid,0 : zrotate object objid,0 
  473.  
  474.             rem End of Destination Move
  475.             cx=goblin#(g,2)/10.0 : cz=goblin#(g,3)/10.0
  476.             tx=goblin#(g,8)/10.0 : tz=goblin#(g,9)/10.0
  477.             if cx=tx and cz=tz
  478.                 goblin#(g,7)=0 : goblin#(g,12)=0
  479.                 rg=goblin#(g,11)
  480.                 if rg>0
  481.                     loop object 1000+(rg*2)+0,idlestart,idleend
  482.                     if object exist(1000+(rg*2)+1)=1 then loop object 1000+(rg*2)+1,idlestart,idleend
  483.                     set object frame 1000+(rg*2)+0,idlestart
  484.                     if object exist(1000+(rg*2)+1)=1 then set object frame 1000+(rg*2)+1,idlestart
  485.                 endif
  486.             endif
  487.  
  488.         else
  489.  
  490.             rem Goblin follows Player
  491.             point object objid,x#,y#,z#
  492.             xrotate object objid,0 : zrotate object objid,0 
  493.     
  494.             rem Ensure Goblin has free square
  495.             boverlap=0
  496.             bx=object position x(objid)/50.0
  497.             bz=object position z(objid)/50.0
  498.             for bg=1 to enemymax
  499.                 bgobjid=100+(bg*2)+0
  500.                 if goblin#(bg,1)=1
  501.                     tx=object position x(bgobjid)/50.0
  502.                     tz=object position z(bgobjid)/50.0
  503.                     if bg>g
  504.                         if bx=tx and bz=tz then boverlap=bg
  505.                     endif
  506.                 endif
  507.             next bg
  508.             if boverlap>0
  509.                 bgobjid=100+(boverlap*2)+0
  510.                 bb=(boverlap/2)
  511.                 bb=boverlap-(bb*2)
  512.                 yrotate object objid,wrapvalue((object angle y(objid)-70)+(140*bb))
  513.             endif
  514.  
  515.         endif    
  516.     
  517.         rem Goblin moves forward
  518.         if goblin#(g,12)=1
  519.  
  520.             rem Detect for charge opportunity
  521.             dx#=goblin#(g,2)-x#
  522.             dz#=goblin#(g,3)-z#
  523.             d#=sqrt(abs(dx#*dx#)+abs(dz#*dz#))
  524.             if d#<200.0 or goblin#(g,14)=2
  525.  
  526.                 rem If not charging, CHARGE!
  527.                 if goblin#(g,14)<>1
  528.                     goblin#(g,14)=1
  529.                     goblin#(g,7)=0
  530.                     rg=goblin#(g,11)
  531.                     if rg>0
  532.                         gobjid=1000+(rg*2)
  533.                         loop object gobjid+0,chargestart+5,chargeend
  534.                         if object exist(gobjid+1)=1 then loop object gobjid+1,chargestart+5,chargeend
  535.                         set object frame gobjid+0,chargestart
  536.                         if object exist(gobjid+1)=1 then set object frame gobjid+1,chargestart
  537.                         set object speed gobjid+0,75
  538.                         if object exist(gobjid+1)=1 then set object speed gobjid+1,75
  539.                         position sound 1000+(rg*2)+0,object position x(gobjid),object position y(gobjid),object position z(gobjid)
  540.                         play sound 1000+(rg*2)+0
  541.                     endif
  542.                 endif
  543.  
  544.             endif
  545.  
  546.             rem Record cloest goblin for later
  547.             if d#<closestgoblin#
  548.                 if goblin#(g,7)=0
  549.                     closestgoblin#=d# : closestgoblin=g
  550.                 endif
  551.             endif
  552.  
  553.             rem Special charge mode
  554.             if goblin#(g,14)=1
  555.                 rem Goblin makes a move
  556.                 move object objid,7.5
  557.             else
  558.                 rem Goblin makes a move
  559.                 move object objid,2.5
  560.     
  561.                 rem Make sound when tracking
  562.                 dx#=goblin#(g,2)-x#
  563.                 dz#=goblin#(g,3)-z#
  564.                 d#=sqrt(abs(dx#*dx#)+abs(dz#*dz#))
  565.                 if rnd(100)=0 or (rnd(20)=0 and d#<250.0)
  566.                     if sound playing(100+(g*2)+0)=0
  567.                         position sound 100+(g*2)+0,object position x(objid),object position y(objid),object position z(objid)
  568.                         play sound 100+(g*2)+0
  569.                     endif
  570.                 endif
  571.             endif
  572.     
  573.         endif
  574.     
  575.         rem Update goblin position
  576.         goblin#(g,2)=object position x(objid)
  577.         goblin#(g,3)=object position z(objid)
  578.     
  579.         rem Goblin falls on floor
  580.         if goblin#(g,12)=2
  581.     
  582.             rem Goblin waits for end of fall animation
  583.             rg=goblin#(g,11)
  584.             if rg>0
  585.                 gobjid=1000+(rg*2)
  586.                 fn=goblin#(g,13)
  587.                 if fn=1 then vanishvalue=45 : cutoff=0
  588.                 if fn=2 then vanishvalue=45 : cutoff=0
  589.                 if fn=3 then vanishvalue=45 : cutoff=0
  590.                 if fn=4 then vanishvalue=45 : cutoff=0
  591.                 if object frame(gobjid)>=fallstart(fn)+vanishvalue
  592.                     sc#=100-((object frame(gobjid)-(fallstart(fn)+vanishvalue))*4)
  593.                     scale object gobjid+0,sc#,sc#,100
  594.                     if object exist(gobjid+1)=1 then scale object gobjid+1,sc#,sc#*-1,100
  595.                     if sound playing(1000+(rg*2)+1)=0
  596.                         position sound 1000+(rg*2)+1,object position x(gobjid),object position y(gobjid),object position z(gobjid)
  597.                         play sound 1000+(rg*2)+1
  598.                     endif
  599.                 endif
  600.                 if object frame(gobjid)>=fallend(fn)-cutoff
  601.                     loop object gobjid+0,walkstart+5,walkend
  602.                     if object exist(gobjid+1)=1 then loop object gobjid+1,walkstart+5,walkend
  603.                     set object speed gobjid+0,50
  604.                     if object exist(gobjid+1)=1 then set object speed gobjid+1,50
  605.                     scale object gobjid,100,100,100
  606.                     if object exist(gobjid+1)=1 then scale object gobjid+1,100,-100,100
  607.                     realtodecal(g,rg)
  608.                     goblin#(g,1)=0
  609.                     goblin#(g,11)=0
  610.                     goblin#(g,12)=0
  611.                     hide object 100+(g*2)+0
  612.                     if object exist(100+(g*2)+1)=1 then hide object 100+(g*2)+1
  613.                 endif
  614.             endif
  615.             
  616.         endif
  617.     
  618.         rem Goblin is attacking
  619.         if goblin#(g,12)=3
  620.  
  621.             rem Goblin waits for end of fall animation
  622.             rg=goblin#(g,11)
  623.             if rg>0
  624.                 gobjid=1000+(rg*2)
  625.                 if object frame(gobjid)>=attackend-2
  626.                     goblin#(g,12)=1
  627.                     loop object gobjid+0,walkstart+5,walkend
  628.                     if object exist(gobjid+1)=1 then loop object gobjid+1,walkstart+5,walkend
  629.                 endif
  630.                 if object frame(gobjid)>=attackstart+10 and object frame(gobjid)<=attackstart+20
  631.                     rem Damage player when anim struck
  632.                     hurt#=100.0
  633.                 endif
  634.             endif
  635.  
  636.         endif
  637.  
  638.         rem Extra handling for RG goblins
  639.         rg=goblin#(g,11)
  640.         if rg>0
  641.  
  642.             rem Handle visual RG
  643.             gobjid=1000+(rg*2)
  644.             ey#=object position y(objid)
  645.             position object gobjid,goblin#(g,2),ey#,goblin#(g,3)
  646.             rotate object gobjid,object angle x(objid),object angle y(objid),object angle z(objid)
  647.             yrotate object gobjid+0,wrapvalue(object angle y(gobjid)+180)
  648.             if object exist(gobjid+1)=1 then yrotate object gobjid+1,object angle y(gobjid)
  649.  
  650.             rem Goblin attacks if close to player
  651.             dx#=goblin#(g,2)-x#
  652.             dz#=goblin#(g,3)-z#
  653.             d#=sqrt((dx#*dx#)+(dz#*dz#))
  654.             if d#<50.0 and goblin#(g,12)<=1
  655.                 goblin#(g,12)=3
  656.                 position sound 1000+(rg*2)+0,object position x(gobjid),object position y(gobjid),object position z(gobjid)
  657.                 play sound 1000+(rg*2)+0
  658.                 play object gobjid+0,attackstart,attackend
  659.                 if object exist(gobjid+1)=1 then play object gobjid+1,attackstart,attackend
  660.             endif
  661.  
  662.         endif
  663.  
  664.     endif
  665.  
  666. next g
  667.  
  668. rem Control enemies
  669. for g=1 to enemymax
  670.  
  671.     rem Affect goblin by gravity
  672.     fx#=0 : fz#=0
  673.     for r=0 to 35
  674.         ex#=newxvalue(goblin#(g,2),r*10,10)
  675.         ez#=newzvalue(goblin#(g,3),r*10,10)
  676.         eh#=get ground height(1,ex#+mx#,ez#+mz#)
  677.         if eh#<-50.0 then eh#=-50.0
  678.         force#=(eh#+50.0)/50.0
  679.         fx#=fx#+((ex#-goblin#(g,2))*force#)
  680.         fz#=fz#+((ez#-goblin#(g,3))*force#)
  681.     next r
  682.     ex#=goblin#(g,2)-(fx#/36.0)
  683.     ez#=goblin#(g,3)-(fz#/36.0)
  684.     goblin#(g,2)=ex# : goblin#(g,3)=ez#
  685.     objid=100+(g*2)+0
  686.  
  687.     rem Transfer position to real goblin
  688.     rg=goblin#(g,11)
  689.     if rg>0
  690.  
  691.         rem Determine whether goblin climbing up or down hill
  692.         gobjid=1000+(rg*2)
  693.         fa#=object angle y(gobjid)
  694.         fx#=newxvalue(goblin#(g,2),fa#,5.0)
  695.         fz#=newzvalue(goblin#(g,3),fa#,5.0)
  696.         fb#=get ground height(1,goblin#(g,2)+mx#,goblin#(g,2)+mz#)
  697.         fa#=get ground height(1,fx#+mx#,fz#+mz#)
  698.     
  699.         rem Position RG goblin
  700.         position object gobjid+0,ex#,eh#,ez#
  701.         if object exist(gobjid+1)=1 then position object gobjid+1,ex#,-50-(eh#+50),ez#
  702.  
  703.         rem Control RG walk or slide anim
  704.         if goblin#(g,12)=1
  705.             if force#>1.0 and fb#>fa#
  706.                 if goblin#(g,15)=0
  707.                     goblin#(g,15)=1
  708.                     loop object gobjid+0,slidestart+10,slideend-10
  709.                     if object exist(gobjid+1)=1 then loop object gobjid+1,slidestart+10,slideend-10
  710.                     set object frame gobjid+0,slidestart
  711.                     if object exist(gobjid+1)=1 then set object frame gobjid+1,slidestart
  712.                 endif
  713.                 makesmoke(ex#,eh#,ez#,5.0)
  714.             else
  715.                 if goblin#(g,15)=1
  716.                     goblin#(g,15)=0
  717.                     loop object gobjid+0,walkstart+5,walkend
  718.                     if object exist(gobjid+1)=1 then loop object gobjid+1,walkstart+5,walkend
  719.                     set object frame gobjid+0,walkstart+5
  720.                     if object exist(gobjid+1)=1 then set object frame gobjid+1,walkstart+5
  721.                 endif
  722.             endif
  723.         endif
  724.  
  725.     else
  726.         position object objid+0,ex#,eh#+18,ez#
  727.         if object exist(objid+1)=1 then position object objid+1,ex#,-68-(eh#+50),ez#
  728.     endif
  729.  
  730.     rem Maintain decal goblins
  731.     for b=0 to 1
  732.         objid=100+(g*2)+b
  733.         if object exist(objid)=1
  734.             point object objid,x#,y#,z#
  735.             xrotate object objid,0 : zrotate object objid,0 
  736.             goblin#(g,5)=goblin#(g,5)+1
  737.             if goblin#(g,5)>3
  738.                 goblin#(g,5)=0
  739.                 goblin#(g,4)=goblin#(g,4)+1
  740.                 if goblin#(g,4)>109 then goblin#(g,4)=100
  741.             endif
  742.             sighty#=atanfull(x#-goblin#(g,2),z#-goblin#(g,3))
  743.             if goblin#(g,12)=1
  744.                 dirface=4
  745.                 goblin#(g,5)=goblin#(g,5)+1
  746.             else
  747.                 dirface=wrapvalue(goblin#(g,6)+sighty#)/90.0
  748.             endif
  749.             image=goblin#(g,4)+(dirface*10)
  750.             texture object objid,image
  751.         endif
  752.     next b
  753.  
  754.     rem Scale decal based on mode
  755.     objid=100+(g*2)
  756.     if goblin#(g,12)=1
  757.         scale object objid,130,100,500
  758.         if object exist(objid+1)=1 then scale object objid+1,130,-100,500
  759.     else
  760.         scale object objid,100,100,500
  761.         if object exist(objid+1)=1 then scale object objid+1,100,-100,500
  762.     endif
  763.  
  764. next g
  765.  
  766. return
  767.  
  768. _control_weather:
  769.  
  770. rem Control skycover
  771. scroll object texture 52,0.001,0.0001
  772. scroll object texture 53,0.002,-0.002
  773.  
  774. if lowmode=0
  775.     rem Control rain
  776.     for t=1 to 20
  777.         makeraindrop(x#,y#,z#)
  778.     next t
  779. endif
  780.  
  781. return
  782.  
  783.  
  784. _create_world:
  785.  
  786. rem Generate random crator
  787. mx#=1000 : mz#=1000
  788. make matrix 1,2000,2000,25,25
  789. position matrix 1,mx#*-1,0,mz#*-1
  790.  
  791. rem Height map
  792. dim map(25,25)
  793. dim mh(25,25)
  794.  
  795. rem Load or generate
  796. if 1=1
  797.     rem load perimetor
  798.     load array "map.dat",map(0)
  799. else
  800.     rem Design perimetor
  801.     for t=0 to 25
  802.         r=50+rnd(50)
  803.         map(0,t)=r : map(t,0)=r
  804.         map(1,t)=r : map(t,1)=r
  805.         map(25,t)=r : map(t,25)=r
  806.     next t
  807.     for t=1 to 100 : map(rnd(25),rnd(25))=1+rnd(2) : next t
  808.     for t=1 to 75 : map(2+rnd(21),2+rnd(21))=100+rnd(50) : next t
  809.     for z=2 to 23 step 2 
  810.         for x=2 to 23 step 2
  811.             map(x,z)=0
  812.         next x
  813.     next z
  814.     save array "tempmap.dat",map(0)
  815. endif
  816.  
  817. rem Texture matrix
  818. load image "floor.bmp",1
  819. prepare matrix texture 1,1,4,4
  820.  
  821. rem Add hills
  822. for c=1 to 20
  823. for x=0 to 25
  824. for z=0 to 25
  825.     if map(x,z)>0
  826.         map(x,z)=map(x,z)-1
  827.         for tx=-1 to 1
  828.         for tz=-1 to 1
  829.             gx=x+tx : gz=z+tz
  830.             if gx>=0 and gx<=25 and gz>=0 and gz<=25
  831.                 mh(gx,gz)=mh(gx,gz)+(5-((abs(tx)+abs(tz))/2))
  832.                 set matrix height 1,gx,gz,mh(gx,gz)
  833.             endif
  834.         next tz
  835.         next tx
  836.     else
  837.         set matrix height 1,x,z,-100
  838.     endif
  839.     if x>=0 and x<=24 and z>=0 and z<=24
  840.         if x<=2 or x=23 or x=24 or z<=2 or z=23 or z=24
  841.             set matrix tile 1,x,z,9+rnd(7)
  842.         else
  843.             set matrix tile 1,x,z,1+rnd(7)
  844.         endif
  845.     endif
  846. next z
  847. next x
  848. next c
  849. update matrix 1
  850.  
  851. rem Create sky
  852. color backdrop 0
  853.  
  854. rem Create ice-floor
  855. load object "sky.x",51
  856. load image "clouds.bmp",3
  857. scale object 51,500000,500000,500000
  858. position object 51,0,-50,0
  859. texture object 51,3
  860. ghost object on 51
  861.  
  862. rem Create cloud-cover1
  863. load object "sky.x",52
  864. scale object 52,5000000,5000000,5000000
  865. position object 52,0,550,0
  866. texture object 52,3
  867. ghost object on 52
  868.  
  869. rem Create cloud-cover2
  870. load object "sky.x",53
  871. scale object 53,5000000,5000000,5000000
  872. position object 53,0,545,0
  873. texture object 53,3
  874. ghost object on 53
  875. scroll object texture 53,0.5,0.2
  876.  
  877. rem Find lowest point of map
  878. lowest=9999
  879. for x=2 to 24
  880. for z=2 to 24
  881. if mh(x,z)<lowest then lowest=mh(x,z) : lowestx=x : lowestz=z
  882. next z
  883. next x
  884. x#=lowestx*((mx#*2)/25.0)-mx#
  885. z#=lowestz*((mz#*2)/25.0)-mz#
  886.  
  887. rem Erode path from starting position to center
  888. for x=lowestx to 12
  889.     for z=lowestz to 12
  890.         set matrix height 1,x,z,-100
  891.     next z
  892. next x
  893. update matrix 1
  894.  
  895. rem Create goblin doorway1
  896. load object "cave.x",91
  897. position object 91,850,-50,300
  898. yrotate object 91,270
  899. fade object 91,200
  900.  
  901. rem Create goblin doorway2
  902. load object "cave.x",92
  903. position object 92,-650,-50,850
  904. yrotate object 92,180
  905. fade object 92,200
  906.  
  907. rem Free temp arrays
  908. undim map(0)
  909. undim mh(0)
  910.  
  911. rem Setup Scene
  912. set camera range 3,10000
  913. set ambient light 50
  914.  
  915. return
  916.  
  917. _create_enemies:
  918.  
  919. rem Create Enemies
  920. for g=1 to enemymax
  921.  
  922.     rem Goblin data
  923.     ex#=rnd(1000)-500
  924.     ez#=rnd(1000)-500
  925.     goblin#(g,1)=1
  926.     goblin#(g,2)=ex#
  927.     goblin#(g,3)=ez#
  928.     goblin#(g,4)=100+rnd(7)
  929.     goblin#(g,5)=0
  930.     goblin#(g,6)=45+(rnd(3)*90)
  931.     goblin#(g,11)=0
  932.     goblin#(g,12)=0
  933.     goblin#(g,13)=1+rnd(3)
  934.  
  935.     rem Goblin
  936.     objid=100+(g*2)+0
  937.     make object plain objid,30,40
  938.     texture object objid,100
  939.     set object objid,1,0,0
  940.     eh#=get ground height(1,ex#+mx#,ez#+mz#)
  941.     if eh#<-50.0 then eh#=-50.0
  942.     position object objid,ex#,eh#+18,ez#
  943.  
  944.     rem Goblin Reflection
  945.     objid=100+(g*2)+1
  946.     make object plain objid,30,40
  947.     texture object objid,100
  948.     set object objid,1,0,0
  949.     eh#=get ground height(1,ex#+mx#,ez#+mz#)
  950.     if eh#<-50.0 then eh#=-50.0
  951.     position object objid,ex#,-68-(eh#+50),ez#
  952.     scale object objid,100,-100,100
  953.  
  954. next g
  955.  
  956. rem Create Real Aliens
  957. for g=1 to 5
  958.  
  959.     rem Borrow goblin positions
  960.     ex#=goblin#(g,2)
  961.     ez#=goblin#(g,3)
  962.     ea#=goblin#(g,6)
  963.     ew#=5+rnd(15)
  964.  
  965.     rem Real Goblin
  966.     objid=1000+(g*2)+0 : idlestart=0
  967.     load object "idle.x",objid : idleend=total object frames(objid)
  968.     walkstart=total object frames(objid)+1
  969.     append object "walk.x",objid,walkstart : walkend=total object frames(objid)
  970.     fallstart(1)=total object frames(objid)+1
  971.     append object "die4.x",objid,fallstart(1) : fallend(1)=total object frames(objid)
  972.     fallstart(2)=total object frames(objid)+1
  973.     append object "die1.x",objid,fallstart(2) : fallend(2)=total object frames(objid)
  974.     fallstart(3)=total object frames(objid)+1
  975.     append object "die2.x",objid,fallstart(3) : fallend(3)=total object frames(objid)
  976.     fallstart(4)=total object frames(objid)+1
  977.     append object "die3.x",objid,fallstart(4) : fallend(4)=total object frames(objid)
  978.     attackstart=total object frames(objid)+1
  979.     append object "punch.x",objid,attackstart : attackend=total object frames(objid)
  980.     chargestart=total object frames(objid)+1
  981.     append object "charge.x",objid,chargestart : chargeend=total object frames(objid)
  982.     slidestart=total object frames(objid)+1
  983.     append object "slide.x",objid,slidestart : slideend=total object frames(objid)
  984.     `
  985.     eh#=get ground height(1,ex#+mx#,ez#+mz#)
  986.     if eh#<-50.0 then eh#=-50.0
  987.     position object objid,ex#,eh#,ez#
  988.     yrotate object objid,ea#
  989.     scale object objid,90,90,90
  990.     set object speed objid,10
  991.     set object rotation zyx objid
  992.     set object frame objid,ew#
  993.     fn=1 : loop object objid,walkstart+5,walkend
  994.     hide object objid
  995.     
  996.     rem Real Goblin Reflection
  997.     objid=1000+(g*2)+1
  998.     load object "idle.x",objid
  999.     append object "walk.x",objid,walkstart
  1000.     append object "die4.x",objid,fallstart(1)
  1001.     append object "die1.x",objid,fallstart(2)
  1002.     append object "die2.x",objid,fallstart(3)
  1003.     append object "die3.x",objid,fallstart(4)
  1004.     append object "punch.x",objid,attackstart
  1005.     append object "charge.x",objid,chargestart
  1006.     append object "slide.x",objid,slidestart
  1007.     eh#=get ground height(1,ex#+mx#,ez#+mz#)
  1008.     if eh#<-50.0 then eh#=-50.0
  1009.     position object objid,ex#,-50-(eh#+50),ez#
  1010.     yrotate object objid,ea#
  1011.     scale object objid,90,-90,90
  1012.     set object speed objid,10
  1013.     set object rotation zyx objid
  1014.     set object frame objid,ew#
  1015.     fn=1 : loop object objid,walkstart+5,walkend
  1016.     hide object objid
  1017.  
  1018. next rg
  1019.  
  1020. rem First five are active
  1021. for g=1 to 5
  1022.     goblin#(g,12)=1
  1023.     rg=g : decaltoreal(g,rg)
  1024. next g
  1025.  
  1026. return
  1027.  
  1028. _create_player:
  1029.  
  1030. rem Create Player
  1031. make object cube 1,10
  1032. hide object 1
  1033.  
  1034. rem Create Guns
  1035. for g=2 to 3
  1036.     if g=2
  1037.         load object "gunR.x",g
  1038.     else
  1039.         load object "gunL.x",g
  1040.     endif
  1041.     scale object g,200,200,200
  1042.     set object rotation zyx g
  1043.     gpx#(g-2)=x# : gpy#(g-2)=y#-100 : gpz#(g-2)=z#
  1044. next g
  1045.  
  1046. rem Create Laser Bolts
  1047. for l=0 to 10
  1048.     for b=0 to 1
  1049.         ll=4+(l*2)+b
  1050.         load object "pulse001.x",ll
  1051.         scale object ll,500,200,5000
  1052.         set object rotation zyx ll
  1053.         hide object ll
  1054.     next b
  1055. next l
  1056.  
  1057. rem Create needle for compass
  1058. make object plain 80,128,128
  1059. load image "needle.bmp",80
  1060. texture object 80,80
  1061. lock object on 80
  1062. set object 80,1,0,0
  1063. position object 80,240,165,400
  1064. scale object 80,25,75,500
  1065. fade object 80,200
  1066.  
  1067. rem Create compass
  1068. make object plain 81,128,128
  1069. load image "compass.bmp",81
  1070. texture object 81,81
  1071. lock object on 81
  1072. set object 81,1,0,0
  1073. position object 81,240,165,400
  1074. scale object 81,100,100,500
  1075. fade object 81,200
  1076.  
  1077. rem Create shade compass
  1078. make object plain 82,128,128
  1079. load image "shade.bmp",82
  1080. texture object 82,82
  1081. lock object on 82
  1082. set object 82,1,0,0
  1083. position object 82,240,165,400
  1084. scale object 82,100,100,500
  1085. fade object 82,200
  1086. ghost object on 82
  1087.  
  1088. rem Create status panels
  1089. make object plain 83,128,128
  1090. load image "stats.bmp",83
  1091. texture object 83,83
  1092. lock object on 83
  1093. set object 83,1,0,0
  1094. position object 83,-240,165,400
  1095. scale object 83,100,100,500
  1096. fade object 83,200
  1097.  
  1098. rem Set initial player angle
  1099. cya#=90.0
  1100.  
  1101. return
  1102.  
  1103. _generate_goblins:
  1104.  
  1105. rem Create decal images for alien
  1106. if 1=1
  1107.     load bitmap "goblin.bmp",5
  1108.     gobmax=0
  1109.     for d=0 to 4
  1110.         x=0
  1111.         for f=0 to 19 step 2
  1112.             rem Modified half-sized final bitmap
  1113.             get image 100+x+(d*10),(x*81),(d*128),(x*81)+81,(d*128)+128
  1114.             inc gobmax
  1115.             inc x
  1116.         next f
  1117.     next d
  1118.     delete bitmap 5
  1119. else
  1120.     autocam on
  1121.     sync off
  1122.     backdrop on
  1123.     set ambient light 50
  1124.     color backdrop 0
  1125.     load object "idle.x",100
  1126.     walkstart=total object frames(100)+1
  1127.     append object "walk.x",100,walkstart
  1128.     walkend=total object frames(100)
  1129.     fade object 100,200
  1130.     create bitmap 5,(192*10),256*5
  1131.     gobmax=0
  1132.     for d=0 to 4
  1133.         if d<4
  1134.             yrotate object 100,wrapvalue(45+(d*90))
  1135.             fstart=0
  1136.             fmax=20-1
  1137.         else
  1138.             yrotate object 100,0
  1139.             fstart=walkstart+5
  1140.             fmax=(walkend-walkstart)-6
  1141.             scale object 100,70,100,100
  1142.         endif
  1143.         x=0
  1144.         for f=0 to fmax step 2
  1145.             set object frame 100,fstart+f
  1146.             set current bitmap 0
  1147.             get image 100+x+(d*10),234,0,234+192,256
  1148.             set current bitmap 5
  1149.             paste image 100+x+(d*10),x*192,d*256
  1150.             inc gobmax
  1151.             inc x
  1152.         next f
  1153.     next d
  1154.     save bitmap "goblin.bmp",5
  1155.     delete object 100
  1156.     delete bitmap 5
  1157.     gobanim=100
  1158.     autocam off
  1159.     sync on
  1160. endif
  1161.  
  1162. return
  1163.  
  1164.  
  1165. rem ** Functions **
  1166.  
  1167. function makeraindrop(x#,y#,z#)
  1168.  
  1169.     rem Find spare decal
  1170.     fd=1 : for d=1 to decalmax(1) : if decal#(d,1)=0 : fd=d : endif : next d
  1171.     
  1172.     rem Create fire
  1173.     decal#(fd,1)=1
  1174.     decal#(fd,2)=(x#+100)-rnd(200)
  1175.     decal#(fd,3)=y#+150+rnd(50)
  1176.     decal#(fd,4)=(z#+100)-rnd(200)
  1177.  
  1178.     rem Object
  1179.     objid=10000+fd : dodecal(objid)
  1180.     
  1181. endfunction
  1182.  
  1183. function makesmoke(x#,y#,z#,size#)
  1184.  
  1185.     rem Find spare decal
  1186.     fd=1 : for d=1 to decalmax(1) : if decal#(d,1)=0 : fd=d : endif : next d
  1187.     
  1188.     rem Create fire
  1189.     decal#(fd,1)=2
  1190.     decal#(fd,2)=(x#+1)-rnd(2)
  1191.     decal#(fd,3)=(y#+1)-rnd(2)
  1192.     decal#(fd,4)=(z#+1)-rnd(2)
  1193.     decal#(fd,5)=rnd(350)
  1194.     decal#(fd,6)=(2+rnd(2))/10.0
  1195.     decal#(fd,7)=rnd(10)/10.0
  1196.     decal#(fd,8)=100-rnd(10)
  1197.     decal#(fd,9)=size#
  1198.  
  1199.     rem Object
  1200.     objid=10000+fd : dodecal(objid)
  1201.     texture object objid,1001
  1202.  
  1203. endfunction
  1204.  
  1205. function dodecal(objid)
  1206.     if object exist(objid)=0 then make object plain objid,10,10
  1207.     set object objid,1,0,0
  1208.     ghost object on objid
  1209. endfunction
  1210.  
  1211. function controldecals(mx#,mz#)
  1212.  
  1213.     rem All decals
  1214.     for d=1 to decalmax(1)
  1215.  
  1216.         rem Object id
  1217.         objid=10000+d
  1218.         if object exist(objid)=1
  1219.  
  1220.             rem Control rain decals
  1221.             if decal#(d,1)=1
  1222.                 position object objid,decal#(d,2),decal#(d,3),decal#(d,4)        
  1223.                 point object objid,camera position x(),camera position y(),camera position z()
  1224.                 xrotate object objid,0 : zrotate object objid,0
  1225.                 scale object objid,3,100,100
  1226.                 decal#(d,3)=decal#(d,3)-15.0
  1227.                 if decal#(d,3)<-50.0
  1228.                     decal#(d,1)=0
  1229.                 endif
  1230.                 show object objid
  1231.             endif        
  1232.  
  1233.             rem Control smoke decals
  1234.             if decal#(d,1)=2
  1235.                 position object objid,decal#(d,2),decal#(d,3),decal#(d,4)        
  1236.                 point object objid,camera position x(),camera position y(),camera position z()
  1237.                 xrotate object objid,0 : zrotate object objid,0
  1238.                 decal#(d,5)=wrapvalue(decal#(d,5)+2)
  1239.                 decal#(d,2)=decal#(d,2)+(cos(decal#(d,5))*decal#(d,7))
  1240.                 decal#(d,3)=decal#(d,3)+decal#(d,6)
  1241.                 scx#=(150-(decal#(d,8)*1.3))*decal#(d,9)
  1242.                 scz#=(250-decal#(d,8))*decal#(d,9)
  1243.                 scale object objid,scx#,decal#(d,8),scz#
  1244.                 decal#(d,8)=decal#(d,8)-2.0
  1245.                 if decal#(d,8)<=0
  1246.                     decal#(d,1)=0
  1247.                 endif
  1248.                 show object objid
  1249.             endif            
  1250.  
  1251.             rem Hide unused decals
  1252.             if decal#(d,1)=0 then hide object objid
  1253.  
  1254.         endif
  1255.     
  1256.     rem End of decal loop
  1257.     next d
  1258.  
  1259. endfunction
  1260.  
  1261. function activate_enemy(g,x#,z#)
  1262.  
  1263. rem If alive
  1264. if goblin#(g,1)>0
  1265.  
  1266.     rem Only if not RG-active
  1267.     if goblin#(g,11)=0
  1268.     
  1269.         rem Find spare real goblin
  1270.         rgfound=-1
  1271.         for rg=1 to 5
  1272.             if real(rg)=0 then rgfound=rg
  1273.         next rg
  1274.     
  1275.         rem If this enemy is closer than current RG goblins, switch
  1276.         if rgfound=-1
  1277.     
  1278.             rem Determine if closer
  1279.             nx#=goblin#(g,2)-x#
  1280.             nz#=goblin#(g,3)-z#
  1281.             nd#=sqrt(abs(nx#*nx#)+abs(nz#*nz#))
  1282.             for rg=1 to 5
  1283.                 tg=real(rg)
  1284.                 tx#=goblin#(tg,2)-x#
  1285.                 tz#=goblin#(tg,3)-z#
  1286.                 td#=sqrt(abs(tx#*tx#)+abs(tz#*tz#))
  1287.                 if nd#<td# and goblin#(tg,12)=1 then rgfound=rg
  1288.             next rg
  1289.     
  1290.             rem If closer, revert current RG holder
  1291.             if rgfound>0
  1292.                 tg=real(rgfound)
  1293.                 if tg>0 then realtodecal(tg,rgfound)
  1294.             endif
  1295.     
  1296.         endif
  1297.     
  1298.         rem If decal dying, must use real..
  1299.         if rgfound=-1
  1300.     
  1301.             if goblin#(g,12)=2 and goblin#(g,11)=0
  1302.                 for rg=1 to 5
  1303.                     tg=real(rg)
  1304.                     if goblin#(tg,12)<>2 then rgfound=rg
  1305.                 next rg
  1306.                 if rgfound>0
  1307.                     tg=real(rgfound)
  1308.                     if tg>0 then realtodecal(tg,rgfound)
  1309.                     decaltoreal(g,rgfound)
  1310.                     rgfound=-1
  1311.                 endif
  1312.             endif
  1313.     
  1314.         endif
  1315.     
  1316.         rem If RG available..
  1317.         if rgfound>0
  1318.             decaltoreal(g,rgfound)
  1319.         endif
  1320.  
  1321.     endif
  1322.     
  1323. endif
  1324.     
  1325. endfunction
  1326.  
  1327. function decaltoreal(g,rg)
  1328.  
  1329.     rem Prepare real goblin data
  1330.     ex#=goblin#(g,2)
  1331.     eh#=0.0
  1332.     ez#=goblin#(g,3)
  1333.     goblin#(g,11)=rg
  1334.     real(rg)=g
  1335.  
  1336.     rem Hide decal goblin
  1337.     hide object 100+(g*2)+0
  1338.     if object exist(100+(g*2)+1)=1 then hide object 100+(g*2)+1
  1339.     
  1340.     rem Show real goblin
  1341.     show object 1000+(rg*2)+0
  1342.     if object exist(1000+(rg*2)+1)=1 then show object 1000+(rg*2)+1
  1343.  
  1344.     rem Set speed
  1345.     set object speed 1000+(rg*2)+0,50
  1346.     if object exist(1000+(rg*2)+1)=1 then set object speed 1000+(rg*2)+1,50
  1347.  
  1348.     rem Position goblins
  1349.     position object 1000+(rg*2)+0,ex#,eh#,ez#
  1350.     if object exist(1000+(rg*2)+1)=1 then position object 1000+(rg*2)+1,ex#,-50-(eh#+50),ez#    
  1351.  
  1352. endfunction
  1353.  
  1354. function realtodecal(g,rg)
  1355.  
  1356.     rem Prepare real goblin data
  1357.     goblin#(g,11)=0
  1358.     real(rg)=0
  1359.  
  1360.     rem Show decal goblin
  1361.     show object 100+(g*2)+0
  1362.     if object exist(100+(g*2)+1)=1 then show object 100+(g*2)+1
  1363.     
  1364.     rem Hide real goblin
  1365.     hide object 1000+(rg*2)+0
  1366.     if object exist(1000+(rg*2)+1)=1 then hide object 1000+(rg*2)+1
  1367.  
  1368.     rem Set speed
  1369.     set object speed 1000+(rg*2)+0,10
  1370.     if object exist(1000+(rg*2)+1)=1 then set object speed 1000+(rg*2)+1,10
  1371.  
  1372. endfunction
  1373.  
  1374. function placelogo()
  1375.  
  1376. rem Create decal for logo
  1377. load image "logow.bmp",65000
  1378. make object plain 65000,128,144
  1379. position object 65000,25,-16.4,40
  1380. texture object 65000,65000
  1381. scale object 65000,10,10,50
  1382. set object 65000,1,0,0
  1383. fade object 65000,200
  1384. lock object on 65000
  1385.  
  1386. endfunction
  1387.